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 e6b8228f148d7..91303550511d7 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) { auto& points = prototype_.points; points.push_back(p1); 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, 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