Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix npe during skia dispatch of drawAtlas #55497

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions display_list/skia/dl_sk_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,15 @@ void DlSkCanvasDispatcher::drawAtlas(const sk_sp<DlImage> atlas,
return;
}
std::vector<SkColor> sk_colors;
sk_colors.reserve(count);
for (int i = 0; i < count; ++i) {
sk_colors.push_back(colors[i].argb());
if (colors != nullptr) {
sk_colors.reserve(count);
for (int i = 0; i < count; ++i) {
sk_colors.push_back(colors[i].argb());
}
}
canvas_->drawAtlas(skia_atlas.get(), xform, ToSkRects(tex), sk_colors.data(),
count, ToSk(mode), ToSk(sampling), ToSkRect(cullRect),
canvas_->drawAtlas(skia_atlas.get(), xform, ToSkRects(tex),
sk_colors.empty() ? nullptr : sk_colors.data(), count,
ToSk(mode), ToSk(sampling), ToSkRect(cullRect),
safe_paint(render_with_attributes));
}
void DlSkCanvasDispatcher::drawDisplayList(
Expand Down
30 changes: 30 additions & 0 deletions testing/dart/canvas_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,36 @@ void main() async {
final int rgba = data.buffer.asUint32List()[0];
expect(rgba, 0xFF0000FF);
});

test('DrawAtlas with no colors does not crash',
() async {
final Image testImage = await createTestImage();
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
// Make a drawAtlas call that should be solid red.
canvas.drawAtlas(
testImage,
[
RSTransform.fromComponents(
rotation: 0,
scale: 10,
anchorX: 0,
anchorY: 0,
translateX: 0,
translateY: 0,
),
],
[const Rect.fromLTWH(0, 0, 1, 1)],
[],
BlendMode.dst,
null,
Paint(),
);

final Image resultImage = await recorder.endRecording().toImage(1, 1);
final ByteData? data = await resultImage.toByteData();
expect(data, isNotNull);
});
}

Future<Image> createTestImage() async {
Expand Down