[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:

<img width="685" alt="image" src="https://github.com/flutter/engine/assets/919017/cef666c1-c188-4c83-ae93-fca117b0bc7f">

After:

<img width="685" alt="image" src="https://github.com/flutter/engine/assets/919017/0cf5e994-5366-4e73-8f9c-4fec1128b303">
This commit is contained in:
Brandon DeRosier
2024-03-05 13:21:03 -08:00
committed by GitHub
parent d706543640
commit 0fc45b3c73
4 changed files with 38 additions and 2 deletions

View File

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

View File

@@ -205,6 +205,7 @@ std::vector<Point> 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);
}

View File

@@ -126,8 +126,8 @@ TEST(TessellatorTest, TessellateConvex) {
1.0);
std::vector<Point> 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);
}
}

View File

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