Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Do not convert an open path to a closed rect. #45903

Merged
merged 2 commits into from
Sep 15, 2023
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
26 changes: 26 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,32 @@ TEST_P(AiksTest, CanRenderDifferencePaths) {
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}

// Regression test for https://github.com/flutter/flutter/issues/134816.
//
// It should be possible to draw 3 lines, and not have an implicit close path.
TEST_P(AiksTest, CanDrawAnOpenPath) {
Canvas canvas;

// Starting at (50, 50), draw lines from:
// 1. (50, height)
// 2. (width, height)
// 3. (width, 50)
PathBuilder builder;
builder.MoveTo({50, 50});
builder.LineTo({50, 100});
builder.LineTo({100, 100});
builder.LineTo({100, 50});

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
24 changes: 17 additions & 7 deletions impeller/display_list/dl_dispatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -848,19 +848,29 @@ void DlDispatcher::drawDRRect(const SkRRect& outer, const SkRRect& inner) {
// |flutter::DlOpReceiver|
void DlDispatcher::drawPath(const SkPath& path) {
SkRect rect;
SkRRect rrect;
SkRect oval;
if (path.isRect(&rect)) {

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

SkRRect rrect;
if (path.isRRect(&rrect) && rrect.isSimple()) {
canvas_.DrawRRect(skia_conversions::ToRect(rrect.rect()),
rrect.getSimpleRadii().fX, paint_);
} else if (path.isOval(&oval) && oval.width() == oval.height()) {
return;
}

SkRect oval;
if (path.isOval(&oval) && oval.width() == oval.height()) {
canvas_.DrawCircle(skia_conversions::ToPoint(oval.center()),
oval.width() * 0.5, paint_);
} else {
canvas_.DrawPath(skia_conversions::ToPath(path), paint_);
return;
}

canvas_.DrawPath(skia_conversions::ToPath(path), paint_);
}

// |flutter::DlOpReceiver|
Expand Down
27 changes: 27 additions & 0 deletions impeller/display_list/dl_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,33 @@ TEST_P(DisplayListTest, CanDrawWithOddPathWinding) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

// Regression test for https://github.com/flutter/flutter/issues/134816.
//
// It should be possible to draw 3 lines, and not have an implicit close path.
TEST_P(DisplayListTest, CanDrawAnOpenPath) {
flutter::DisplayListBuilder builder;
flutter::DlPaint paint;

paint.setColor(flutter::DlColor::kRed());
paint.setDrawStyle(flutter::DlDrawStyle::kStroke);
paint.setStrokeWidth(10);

builder.Translate(300, 300);

// Move to (50, 50) and draw lines from:
// 1. (50, height)
// 2. (width, height)
// 3. (width, 50)
SkPath path;
path.moveTo(50, 50);
path.lineTo(50, 100);
path.lineTo(100, 100);
path.lineTo(100, 50);
builder.DrawPath(path, paint);

ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(DisplayListTest, CanDrawWithMaskBlur) {
auto texture = CreateTextureForFixture("embarcadero.jpg");
flutter::DisplayListBuilder builder;
Expand Down