From 71b6d12f090149c51cf43233e25b079341145605 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Thu, 17 Oct 2024 11:03:10 -0700 Subject: [PATCH 1/4] Started filtering out close line segments in polylines. --- impeller/geometry/path_builder.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/impeller/geometry/path_builder.cc b/impeller/geometry/path_builder.cc index e6b8228f148d7..392e2f6d518c0 100644 --- a/impeller/geometry/path_builder.cc +++ b/impeller/geometry/path_builder.cc @@ -284,6 +284,9 @@ void PathBuilder::AddContourComponent(const Point& destination, } void PathBuilder::AddLinearComponent(const Point& p1, const Point& p2) { + if (ScalarNearlyEqual(p1.x, p2.x) && ScalarNearlyEqual(p1.y, p2.y)) { + return; + } auto& points = prototype_.points; points.push_back(p1); points.push_back(p2); From 1703a64bc49eabc383dc7b0a7bf82702ed4f7c82 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 18 Oct 2024 09:55:35 -0700 Subject: [PATCH 2/4] made this only apply to rrect path and added an interactive test --- .../display_list/aiks_dl_basic_unittests.cc | 45 +++++++++++++++++++ impeller/geometry/path_builder.cc | 16 +++++-- impeller/geometry/path_builder.h | 2 + 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/impeller/display_list/aiks_dl_basic_unittests.cc b/impeller/display_list/aiks_dl_basic_unittests.cc index 39e5d057eb92c..cf9fcf0183ce9 100644 --- a/impeller/display_list/aiks_dl_basic_unittests.cc +++ b/impeller/display_list/aiks_dl_basic_unittests.cc @@ -1534,5 +1534,50 @@ TEST_P(AiksTest, MassiveScalingMatrixImageFilter) { ASSERT_TRUE(OpenPlaygroundHere(builder.Build())); } +TEST_P(AiksTest, NoDimplesInRRectPath) { + Scalar width = 200.f; + Scalar height = 60.f; + Scalar corner = 1.f; + auto callback = [&]() -> sk_sp { + if (AiksTest::ImGuiBegin("Controls", nullptr, + ImGuiWindowFlags_AlwaysAutoResize)) { + ImGui::SliderFloat("width", &width, 0, 200); + ImGui::SliderFloat("height", &height, 0, 200); + ImGui::SliderFloat("corner", &corner, 0, 1); + ImGui::End(); + } + + DisplayListBuilder builder; + builder.Scale(GetContentScale().x, GetContentScale().y); + + DlPaint background_paint; + background_paint.setColor(DlColor(1, 0.1, 0.1, 0.1, DlColorSpace::kSRGB)); + builder.DrawPaint(background_paint); + + std::vector colors = {DlColor::kRed(), DlColor::kBlue()}; + std::vector stops = {0.0, 1.0}; + + DlPaint paint; + auto gradient = DlColorSource::MakeLinear( + {0, 0}, {200, 200}, 2, colors.data(), stops.data(), DlTileMode::kClamp); + paint.setColorSource(gradient); + paint.setColor(DlColor::kWhite()); + paint.setDrawStyle(DlDrawStyle::kStroke); + paint.setStrokeWidth(20); + + builder.Save(); + builder.Translate(100, 100); + + Scalar corner_x = ((1 - corner) * 50) + 50; + Scalar corner_y = corner * 50 + 50; + SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(0, 0, width, height), + corner_x, corner_y); + builder.DrawRRect(rrect, paint); + builder.Restore(); + return builder.Build(); + }; + ASSERT_TRUE(OpenPlaygroundHere(callback)); +} + } // namespace testing } // namespace impeller diff --git a/impeller/geometry/path_builder.cc b/impeller/geometry/path_builder.cc index 392e2f6d518c0..82de97fb829d6 100644 --- a/impeller/geometry/path_builder.cc +++ b/impeller/geometry/path_builder.cc @@ -165,7 +165,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { //---------------------------------------------------------------------------- // Top line. // - AddLinearComponent( + AddLinearComponentIfNeeded( {rect_origin.x + radii.top_left.x, rect_origin.y}, {rect_origin.x + rect_size.width - radii.top_right.x, rect_origin.y}); @@ -177,7 +177,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { //---------------------------------------------------------------------------- // Right line. // - AddLinearComponent( + AddLinearComponentIfNeeded( {rect_origin.x + rect_size.width, rect_origin.y + radii.top_right.y}, {rect_origin.x + rect_size.width, rect_origin.y + rect_size.height - radii.bottom_right.y}); @@ -190,7 +190,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { //---------------------------------------------------------------------------- // Bottom line. // - AddLinearComponent( + AddLinearComponentIfNeeded( {rect_origin.x + rect_size.width - radii.bottom_right.x, rect_origin.y + rect_size.height}, {rect_origin.x + radii.bottom_left.x, rect_origin.y + rect_size.height}); @@ -203,7 +203,7 @@ PathBuilder& PathBuilder::AddRoundedRect(Rect rect, RoundingRadii radii) { //---------------------------------------------------------------------------- // Left line. // - AddLinearComponent( + AddLinearComponentIfNeeded( {rect_origin.x, rect_origin.y + rect_size.height - radii.bottom_left.y}, {rect_origin.x, rect_origin.y + radii.top_left.y}); @@ -283,6 +283,14 @@ void PathBuilder::AddContourComponent(const Point& destination, prototype_.bounds.reset(); } +void PathBuilder::AddLinearComponentIfNeeded(const Point& p1, const Point& p2) { + if (ScalarNearlyEqual(p1.x, p2.x, 1e-4f) && + ScalarNearlyEqual(p1.y, p2.y, 1e-4f)) { + return; + } + AddLinearComponent(p1, p2); +} + void PathBuilder::AddLinearComponent(const Point& p1, const Point& p2) { if (ScalarNearlyEqual(p1.x, p2.x) && ScalarNearlyEqual(p1.y, p2.y)) { return; diff --git a/impeller/geometry/path_builder.h b/impeller/geometry/path_builder.h index f4de96d18b704..4e57e1d7d8700 100644 --- a/impeller/geometry/path_builder.h +++ b/impeller/geometry/path_builder.h @@ -173,6 +173,8 @@ class PathBuilder { void AddLinearComponent(const Point& p1, const Point& p2); + void AddLinearComponentIfNeeded(const Point& p1, const Point& p2); + void AddQuadraticComponent(const Point& p1, const Point& cp, const Point& p2); void AddCubicComponent(const Point& p1, From 94d16365474c7947160e159adc63fa0f74420761 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 18 Oct 2024 09:59:52 -0700 Subject: [PATCH 3/4] golden golden --- testing/impeller_golden_tests_output.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/impeller_golden_tests_output.txt b/testing/impeller_golden_tests_output.txt index ef3b466533e9d..349de6047a1c4 100644 --- a/testing/impeller_golden_tests_output.txt +++ b/testing/impeller_golden_tests_output.txt @@ -807,6 +807,9 @@ impeller_Play_AiksTest_MatrixSaveLayerFilter_Vulkan.png impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Metal.png impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_OpenGLES.png impeller_Play_AiksTest_MipmapGenerationWorksCorrectly_Vulkan.png +impeller_Play_AiksTest_NoDimplesInRRectPath_Metal.png +impeller_Play_AiksTest_NoDimplesInRRectPath_OpenGLES.png +impeller_Play_AiksTest_NoDimplesInRRectPath_Vulkan.png impeller_Play_AiksTest_PaintBlendModeIsRespected_Metal.png impeller_Play_AiksTest_PaintBlendModeIsRespected_OpenGLES.png impeller_Play_AiksTest_PaintBlendModeIsRespected_Vulkan.png From dd7be937bea8ba51af90e152db8eea4a3dde09fc Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 18 Oct 2024 10:53:19 -0700 Subject: [PATCH 4/4] oops --- impeller/geometry/path_builder.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/impeller/geometry/path_builder.cc b/impeller/geometry/path_builder.cc index 82de97fb829d6..91303550511d7 100644 --- a/impeller/geometry/path_builder.cc +++ b/impeller/geometry/path_builder.cc @@ -292,9 +292,6 @@ void PathBuilder::AddLinearComponentIfNeeded(const Point& p1, const Point& p2) { } void PathBuilder::AddLinearComponent(const Point& p1, const Point& p2) { - if (ScalarNearlyEqual(p1.x, p2.x) && ScalarNearlyEqual(p1.y, p2.y)) { - return; - } auto& points = prototype_.points; points.push_back(p1); points.push_back(p2);