[Impeller] Use DrawPath instead of Rect geometry when the paint style is stroke (flutter/engine#38146)

* [Impeller] Use DrawPath instead of Rect geometry when the paint state is set to stroke

* Add playground
This commit is contained in:
Brandon DeRosier
2022-12-08 15:33:05 -08:00
committed by GitHub
parent dd92718f62
commit f9aba7d6b1
2 changed files with 43 additions and 0 deletions

View File

@@ -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;
}

View File

@@ -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