From 0fc45b3c733bd762c7d02802751f3493df0c4ba1 Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Tue, 5 Mar 2024 13:21:03 -0800 Subject: [PATCH] [Impeller] Fix convex triangulation winding bug for multi-contour paths. (flutter/engine#51198) An extra triangle needs to be inserted after bridging the triangle strip to a new contour, otherwise the triangle winding ends up getting inverted for each consecutive contour. Before: image After: image --- .../impeller/aiks/aiks_path_unittests.cc | 32 +++++++++++++++++++ .../impeller/tessellator/tessellator.cc | 1 + .../tessellator/tessellator_unittests.cc | 4 +-- .../testing/impeller_golden_tests_output.txt | 3 ++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/impeller/aiks/aiks_path_unittests.cc b/engine/src/flutter/impeller/aiks/aiks_path_unittests.cc index 9d5cc3936e..a1f85dee47 100644 --- a/engine/src/flutter/impeller/aiks/aiks_path_unittests.cc +++ b/engine/src/flutter/impeller/aiks/aiks_path_unittests.cc @@ -398,5 +398,37 @@ TEST_P(AiksTest, CanRenderClips) { ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); } +TEST_P(AiksTest, CanRenderOverlappingMultiContourPath) { + Canvas canvas; + + Paint paint; + paint.color = Color::Red(); + + PathBuilder::RoundingRadii radii; + radii.top_left = {50, 50}; + radii.top_right = {50, 50}; + radii.bottom_right = {50, 50}; + radii.bottom_left = {50, 50}; + + const Scalar kTriangleHeight = 100; + canvas.Translate(Vector2(200, 200)); + // Form a path similar to the Material drop slider value indicator. + auto path = + PathBuilder{} + .MoveTo({0, kTriangleHeight}) + .LineTo({-kTriangleHeight / 2.0f, 0}) + .LineTo({kTriangleHeight / 2.0f, 0}) + .Close() + .AddRoundedRect( + Rect::MakeXYWH(-kTriangleHeight / 2.0f, -kTriangleHeight / 2.0f, + kTriangleHeight, kTriangleHeight), + radii) + .TakePath(); + + canvas.DrawPath(path, paint); + + ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); +} + } // namespace testing } // namespace impeller diff --git a/engine/src/flutter/impeller/tessellator/tessellator.cc b/engine/src/flutter/impeller/tessellator/tessellator.cc index 8ef6986a35..e771c6dff9 100644 --- a/engine/src/flutter/impeller/tessellator/tessellator.cc +++ b/engine/src/flutter/impeller/tessellator/tessellator.cc @@ -205,6 +205,7 @@ std::vector Tessellator::TessellateConvex(const Path& path, output.emplace_back(output.back()); output.emplace_back(first_point); output.emplace_back(first_point); + output.emplace_back(first_point); } else { output.emplace_back(first_point); } diff --git a/engine/src/flutter/impeller/tessellator/tessellator_unittests.cc b/engine/src/flutter/impeller/tessellator/tessellator_unittests.cc index 2892a0ded8..7bbe1e3146 100644 --- a/engine/src/flutter/impeller/tessellator/tessellator_unittests.cc +++ b/engine/src/flutter/impeller/tessellator/tessellator_unittests.cc @@ -126,8 +126,8 @@ TEST(TessellatorTest, TessellateConvex) { 1.0); std::vector expected = {{0, 0}, {10, 0}, {0, 10}, {10, 10}, - {10, 10}, {20, 20}, {20, 20}, {30, 20}, - {20, 30}, {30, 30}}; + {10, 10}, {20, 20}, {20, 20}, {20, 20}, + {30, 20}, {20, 30}, {30, 30}}; EXPECT_EQ(pts, expected); } } diff --git a/engine/src/flutter/testing/impeller_golden_tests_output.txt b/engine/src/flutter/testing/impeller_golden_tests_output.txt index aeb18abee2..b7453ed0ee 100644 --- a/engine/src/flutter/testing/impeller_golden_tests_output.txt +++ b/engine/src/flutter/testing/impeller_golden_tests_output.txt @@ -284,6 +284,9 @@ impeller_Play_AiksTest_CanRenderNestedClips_Vulkan.png impeller_Play_AiksTest_CanRenderOffscreenCheckerboard_Metal.png impeller_Play_AiksTest_CanRenderOffscreenCheckerboard_OpenGLES.png impeller_Play_AiksTest_CanRenderOffscreenCheckerboard_Vulkan.png +impeller_Play_AiksTest_CanRenderOverlappingMultiContourPath_Metal.png +impeller_Play_AiksTest_CanRenderOverlappingMultiContourPath_OpenGLES.png +impeller_Play_AiksTest_CanRenderOverlappingMultiContourPath_Vulkan.png impeller_Play_AiksTest_CanRenderRadialGradientManyColors_Metal.png impeller_Play_AiksTest_CanRenderRadialGradientManyColors_OpenGLES.png impeller_Play_AiksTest_CanRenderRadialGradientManyColors_Vulkan.png