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

Commit 743ce67

Browse files
bderozanderso
authored andcommitted
[Impeller] Use DrawPath instead of Rect geometry when the paint style is stroke (#38146)
* [Impeller] Use DrawPath instead of Rect geometry when the paint state is set to stroke * Add playground
1 parent 4971c5b commit 743ce67

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

impeller/aiks/canvas.cc

+5
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ bool Canvas::AttemptDrawBlurredRRect(const Rect& rect,
194194
}
195195

196196
void Canvas::DrawRect(Rect rect, const Paint& paint) {
197+
if (paint.style == Paint::Style::kStroke) {
198+
DrawPath(PathBuilder{}.AddRect(rect).TakePath(), paint);
199+
return;
200+
}
201+
197202
if (AttemptDrawBlurredRRect(rect, 0, paint)) {
198203
return;
199204
}

impeller/display_list/display_list_unittests.cc

+38
Original file line numberDiff line numberDiff line change
@@ -1120,5 +1120,43 @@ TEST_P(DisplayListTest, DrawVerticesSolidColorTrianglesWithIndices) {
11201120
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
11211121
}
11221122

1123+
TEST_P(DisplayListTest, DrawShapes) {
1124+
flutter::DisplayListBuilder builder;
1125+
std::vector<flutter::DlStrokeJoin> joins = {
1126+
flutter::DlStrokeJoin::kBevel,
1127+
flutter::DlStrokeJoin::kRound,
1128+
flutter::DlStrokeJoin::kMiter,
1129+
};
1130+
flutter::DlPaint paint = //
1131+
flutter::DlPaint() //
1132+
.setColor(flutter::DlColor::kWhite()) //
1133+
.setDrawStyle(flutter::DlDrawStyle::kFill) //
1134+
.setStrokeWidth(10);
1135+
flutter::DlPaint stroke_paint = //
1136+
flutter::DlPaint() //
1137+
.setColor(flutter::DlColor::kWhite()) //
1138+
.setDrawStyle(flutter::DlDrawStyle::kStroke) //
1139+
.setStrokeWidth(10);
1140+
SkPath path = SkPath().addPoly({{150, 50}, {160, 50}}, false);
1141+
1142+
builder.translate(300, 50);
1143+
builder.scale(0.8, 0.8);
1144+
for (auto join : joins) {
1145+
paint.setStrokeJoin(join);
1146+
stroke_paint.setStrokeJoin(join);
1147+
builder.drawRect(SkRect::MakeXYWH(0, 0, 100, 100), paint);
1148+
builder.drawRect(SkRect::MakeXYWH(0, 150, 100, 100), stroke_paint);
1149+
builder.drawRRect(
1150+
SkRRect::MakeRectXY(SkRect::MakeXYWH(150, 0, 100, 100), 30, 30), paint);
1151+
builder.drawRRect(
1152+
SkRRect::MakeRectXY(SkRect::MakeXYWH(150, 150, 100, 100), 30, 30),
1153+
stroke_paint);
1154+
builder.drawCircle({350, 50}, 50, paint);
1155+
builder.drawCircle({350, 200}, 50, stroke_paint);
1156+
builder.translate(0, 300);
1157+
}
1158+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
1159+
}
1160+
11231161
} // namespace testing
11241162
} // namespace impeller

0 commit comments

Comments
 (0)