Skip to content

Commit

Permalink
[Impeller] dont treat non-rects as rects. (#46218)
Browse files Browse the repository at this point in the history
We were going down this branch for all closed paths, but we should only be taking it for closed paths that are also rectangles.
  • Loading branch information
jonahwilliams authored and harryterkelsen committed Oct 23, 2023
1 parent 932f1e2 commit a534ce8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,28 @@ TEST_P(AiksTest, CanDrawAnOpenPath) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

TEST_P(AiksTest, CanDrawAnOpenPathThatIsntARect) {
Canvas canvas;

// Draw a stroked path that is explicitly closed to verify
// It doesn't become a rectangle.
PathBuilder builder;
builder.MoveTo({50, 50});
builder.LineTo({520, 120});
builder.LineTo({300, 310});
builder.LineTo({100, 50});
builder.Close();

Paint paint;
paint.color = Color::Red();
paint.style = Paint::Style::kStroke;
paint.stroke_width = 10;

canvas.DrawPath(builder.TakePath(), paint);

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

static sk_sp<SkData> OpenFixtureAsSkData(const char* fixture_name) {
auto mapping = flutter::testing::OpenFixtureAsMapping(fixture_name);
if (!mapping) {
Expand Down
2 changes: 1 addition & 1 deletion impeller/display_list/dl_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ void DlDispatcher::drawPath(const SkPath& path) {

// We can't "optimize" a path into a rectangle if it's open.
bool closed;
if (path.isRect(&rect, &closed); closed) {
if (path.isRect(&rect, &closed) && closed) {
canvas_.DrawRect(skia_conversions::ToRect(rect), paint_);
return;
}
Expand Down

0 comments on commit a534ce8

Please sign in to comment.