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

Commit 0bc57e0

Browse files
authored
Started filtering out close line segments in rrect polylines. (#55929)
fixes flutter/flutter#156422 tests: AiksTest.GradientOvalStrokeMaskBlurSigmaZero This filtering needs to happen somewheres. I opted for putting it inside of the AddLinearComponent instead of where it was affected me in the test: https://github.com/flutter/engine/blob/31aaaaad868743b38ac3b7165f0d58eca94e521b/impeller/geometry/path_builder.cc#L180 This seems preferable. A tiny line segment should never matter. The rub is that its only happening here. We might want to do this in other places as well. It's equally unimportant to have a tiny curve. [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent bde72d8 commit 0bc57e0

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

impeller/display_list/aiks_dl_basic_unittests.cc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,5 +1534,50 @@ TEST_P(AiksTest, MassiveScalingMatrixImageFilter) {
15341534
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
15351535
}
15361536

1537+
TEST_P(AiksTest, NoDimplesInRRectPath) {
1538+
Scalar width = 200.f;
1539+
Scalar height = 60.f;
1540+
Scalar corner = 1.f;
1541+
auto callback = [&]() -> sk_sp<DisplayList> {
1542+
if (AiksTest::ImGuiBegin("Controls", nullptr,
1543+
ImGuiWindowFlags_AlwaysAutoResize)) {
1544+
ImGui::SliderFloat("width", &width, 0, 200);
1545+
ImGui::SliderFloat("height", &height, 0, 200);
1546+
ImGui::SliderFloat("corner", &corner, 0, 1);
1547+
ImGui::End();
1548+
}
1549+
1550+
DisplayListBuilder builder;
1551+
builder.Scale(GetContentScale().x, GetContentScale().y);
1552+
1553+
DlPaint background_paint;
1554+
background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB));
1555+
builder.DrawPaint(background_paint);
1556+
1557+
std::vector<DlColor> colors = {DlColor::kRed(), DlColor::kBlue()};
1558+
std::vector<Scalar> stops = {0.0, 1.0};
1559+
1560+
DlPaint paint;
1561+
auto gradient = DlColorSource::MakeLinear(
1562+
{0, 0}, {200, 200}, 2, colors.data(), stops.data(), DlTileMode::kClamp);
1563+
paint.setColorSource(gradient);
1564+
paint.setColor(DlColor::kWhite());
1565+
paint.setDrawStyle(DlDrawStyle::kStroke);
1566+
paint.setStrokeWidth(20);
1567+
1568+
builder.Save();
1569+
builder.Translate(100, 100);
1570+
1571+
Scalar corner_x = ((1 - corner) * 50) + 50;
1572+
Scalar corner_y = corner * 50 + 50;
1573+
SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(0, 0, width, height),
1574+
corner_x, corner_y);
1575+
builder.DrawRRect(rrect, paint);
1576+
builder.Restore();
1577+
return builder.Build();
1578+
};
1579+
ASSERT_TRUE(OpenPlaygroundHere(callback));
1580+
}
1581+
15371582
} // namespace testing
15381583
} // namespace impeller

impeller/geometry/path_builder.cc

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
165165
//----------------------------------------------------------------------------
166166
// Top line.
167167
//
168-
AddLinearComponent(
168+
AddLinearComponentIfNeeded(
169169
{rect_origin.x + radii.top_left.x, rect_origin.y},
170170
{rect_origin.x + rect_size.width - radii.top_right.x, rect_origin.y});
171171

@@ -177,7 +177,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
177177
//----------------------------------------------------------------------------
178178
// Right line.
179179
//
180-
AddLinearComponent(
180+
AddLinearComponentIfNeeded(
181181
{rect_origin.x + rect_size.width, rect_origin.y + radii.top_right.y},
182182
{rect_origin.x + rect_size.width,
183183
rect_origin.y + rect_size.height - radii.bottom_right.y});
@@ -190,7 +190,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
190190
//----------------------------------------------------------------------------
191191
// Bottom line.
192192
//
193-
AddLinearComponent(
193+
AddLinearComponentIfNeeded(
194194
{rect_origin.x + rect_size.width - radii.bottom_right.x,
195195
rect_origin.y + rect_size.height},
196196
{rect_origin.x + radii.bottom_left.x, rect_origin.y + rect_size.height});
@@ -203,7 +203,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) {
203203
//----------------------------------------------------------------------------
204204
// Left line.
205205
//
206-
AddLinearComponent(
206+
AddLinearComponentIfNeeded(
207207
{rect_origin.x, rect_origin.y + rect_size.height - radii.bottom_left.y},
208208
{rect_origin.x, rect_origin.y + radii.top_left.y});
209209

@@ -283,6 +283,14 @@ void PathBuilder::AddContourComponent(const Point& destination,
283283
prototype_.bounds.reset();
284284
}
285285

286+
void PathBuilder::AddLinearComponentIfNeeded(const Point& p1, const Point& p2) {
287+
if (ScalarNearlyEqual(p1.x, p2.x, 1e-4f) &&
288+
ScalarNearlyEqual(p1.y, p2.y, 1e-4f)) {
289+
return;
290+
}
291+
AddLinearComponent(p1, p2);
292+
}
293+
286294
void PathBuilder::AddLinearComponent(const Point& p1, const Point& p2) {
287295
auto& points = prototype_.points;
288296
points.push_back(p1);

impeller/geometry/path_builder.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class PathBuilder {
173173

174174
void AddLinearComponent(const Point& p1, const Point& p2);
175175

176+
void AddLinearComponentIfNeeded(const Point& p1, const Point& p2);
177+
176178
void AddQuadraticComponent(const Point& p1, const Point& cp, const Point& p2);
177179

178180
void AddCubicComponent(const Point& p1,

testing/impeller_golden_tests_output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,9 @@ impeller_Play_AiksTest_MatrixSaveLayerFilter_Vulkan.png
819819
impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Metal.png
820820
impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_OpenGLES.png
821821
impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Vulkan.png
822+
impeller_Play_AiksTest_NoDimplesInRRectPath_Metal.png
823+
impeller_Play_AiksTest_NoDimplesInRRectPath_OpenGLES.png
824+
impeller_Play_AiksTest_NoDimplesInRRectPath_Vulkan.png
822825
impeller_Play_AiksTest_PaintBlendModeIsRespected_Metal.png
823826
impeller_Play_AiksTest_PaintBlendModeIsRespected_OpenGLES.png
824827
impeller_Play_AiksTest_PaintBlendModeIsRespected_Vulkan.png

0 commit comments

Comments
 (0)