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

[Impeller] Use DrawPath instead of Rect geometry when the paint style is stroke #38146

Merged
merged 2 commits into from
Dec 8, 2022
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
5 changes: 5 additions & 0 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
}

void Canvas::DrawRect(Rect rect, const Paint& paint) {
if (paint.style == Paint::Style::kStroke) {
DrawPath(PathBuilder{}.AddRect(rect).TakePath(), paint);
return;
}

if (AttemptDrawBlurredRRect(rect, 0, paint)) {
return;
}
Expand Down
38 changes: 38 additions & 0 deletions impeller/display_list/display_list_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1120,5 +1120,43 @@ TEST_P(DisplayListTest, DrawVerticesSolidColorTrianglesWithIndices) {
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

TEST_P(DisplayListTest, DrawShapes) {
flutter::DisplayListBuilder builder;
std::vector<flutter::DlStrokeJoin> joins = {
flutter::DlStrokeJoin::kBevel,
flutter::DlStrokeJoin::kRound,
flutter::DlStrokeJoin::kMiter,
};
flutter::DlPaint paint = //
flutter::DlPaint() //
.setColor(flutter::DlColor::kWhite()) //
.setDrawStyle(flutter::DlDrawStyle::kFill) //
.setStrokeWidth(10);
flutter::DlPaint stroke_paint = //
flutter::DlPaint() //
.setColor(flutter::DlColor::kWhite()) //
.setDrawStyle(flutter::DlDrawStyle::kStroke) //
.setStrokeWidth(10);
SkPath path = SkPath().addPoly({{150, 50}, {160, 50}}, false);

builder.translate(300, 50);
builder.scale(0.8, 0.8);
for (auto join : joins) {
paint.setStrokeJoin(join);
stroke_paint.setStrokeJoin(join);
builder.drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
builder.drawRect(SkRect::MakeXYWH(0, 150, 100, 100), stroke_paint);
builder.drawRRect(
SkRRect::MakeRectXY(SkRect::MakeXYWH(150, 0, 100, 100), 30, 30), paint);
builder.drawRRect(
SkRRect::MakeRectXY(SkRect::MakeXYWH(150, 150, 100, 100), 30, 30),
stroke_paint);
builder.drawCircle({350, 50}, 50, paint);
builder.drawCircle({350, 200}, 50, stroke_paint);
builder.translate(0, 300);
}
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
}

} // namespace testing
} // namespace impeller