Skip to content

Commit e17287d

Browse files
[Impeller] Move to the new location before rendering a stroke path contour containing only one point (#165940)
Fixes flutter/flutter#165190
1 parent 31ed3b7 commit e17287d

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

engine/src/flutter/impeller/display_list/aiks_dl_path_unittests.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,5 +641,25 @@ TEST_P(AiksTest, CanRenderOverlappingMultiContourPath) {
641641
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
642642
}
643643

644+
TEST_P(AiksTest, TwoContourPathWithSinglePointContour) {
645+
DisplayListBuilder builder;
646+
647+
DlPaint paint;
648+
paint.setColor(DlColor::kRed());
649+
paint.setDrawStyle(DlDrawStyle::kStroke);
650+
paint.setStrokeWidth(15.0);
651+
paint.setStrokeCap(DlStrokeCap::kRound);
652+
653+
DlPathBuilder path_builder;
654+
path_builder.MoveTo(DlPoint(100, 100));
655+
path_builder.LineTo(DlPoint(150, 150));
656+
path_builder.MoveTo(DlPoint(200, 200));
657+
path_builder.LineTo(DlPoint(200, 200));
658+
659+
builder.DrawPath(DlPath(path_builder), paint);
660+
661+
ASSERT_TRUE(OpenPlaygroundHere(builder.Build()));
662+
}
663+
644664
} // namespace testing
645665
} // namespace impeller

engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,10 @@ class StrokeGenerator {
8787
polyline.GetContourPointBounds(contour_i);
8888

8989
size_t contour_delta = contour_end_point_i - contour_start_point_i;
90-
if (contour_delta == 1) {
91-
Point p = polyline.GetPoint(contour_start_point_i);
92-
cap_proc(vtx_builder, p, {-stroke_width * 0.5f, 0}, scale,
93-
/*reverse=*/false);
94-
cap_proc(vtx_builder, p, {stroke_width * 0.5f, 0}, scale,
95-
/*reverse=*/false);
96-
continue;
97-
} else if (contour_delta == 0) {
90+
if (contour_delta == 0) {
9891
continue; // This contour has no renderable content.
9992
}
10093

101-
previous_offset = offset;
102-
offset = ComputeOffset(contour_start_point_i, contour_start_point_i,
103-
contour_end_point_i, contour);
104-
const Point contour_first_offset = offset.GetVector();
105-
10694
if (contour_i > 0) {
10795
// This branch only executes when we've just finished drawing a contour
10896
// and are switching to a new one.
@@ -125,6 +113,20 @@ class StrokeGenerator {
125113
vtx_builder.AppendVertex(vtx.position);
126114
}
127115

116+
if (contour_delta == 1) {
117+
Point p = polyline.GetPoint(contour_start_point_i);
118+
cap_proc(vtx_builder, p, {-stroke_width * 0.5f, 0}, scale,
119+
/*reverse=*/false);
120+
cap_proc(vtx_builder, p, {stroke_width * 0.5f, 0}, scale,
121+
/*reverse=*/false);
122+
continue;
123+
}
124+
125+
previous_offset = offset;
126+
offset = ComputeOffset(contour_start_point_i, contour_start_point_i,
127+
contour_end_point_i, contour);
128+
const Point contour_first_offset = offset.GetVector();
129+
128130
// Generate start cap.
129131
if (!polyline.contours[contour_i].is_closed) {
130132
Point cap_offset =

engine/src/flutter/testing/impeller_golden_tests_output.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,9 @@ impeller_Play_AiksTest_TranslucentSaveLayerWithColorMatrixImageFilterDrawsCorrec
963963
impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_Metal.png
964964
impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_OpenGLES.png
965965
impeller_Play_AiksTest_TransparentShadowProducesCorrectColor_Vulkan.png
966+
impeller_Play_AiksTest_TwoContourPathWithSinglePointContour_Metal.png
967+
impeller_Play_AiksTest_TwoContourPathWithSinglePointContour_OpenGLES.png
968+
impeller_Play_AiksTest_TwoContourPathWithSinglePointContour_Vulkan.png
966969
impeller_Play_AiksTest_VerifyNonOptimizedGradient_Metal.png
967970
impeller_Play_AiksTest_VerifyNonOptimizedGradient_OpenGLES.png
968971
impeller_Play_AiksTest_VerifyNonOptimizedGradient_Vulkan.png

0 commit comments

Comments
 (0)