Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1d15b35

Browse files
authored
Revert "[Impeller] Fixes stroke path geometry that can draw outside o… (#46334)
�f path if the path ends at sharp turn. (#45252)" This reverts commit 343dfe8. introduced a regression flutter/flutter#135225 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent 49fe851 commit 1d15b35

File tree

6 files changed

+13
-151
lines changed

6 files changed

+13
-151
lines changed

impeller/aiks/aiks_unittests.cc

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,37 +1205,6 @@ TEST_P(AiksTest, CanRenderRoundedRectWithNonUniformRadii) {
12051205
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
12061206
}
12071207

1208-
TEST_P(AiksTest, CanRenderStrokePathThatEndsAtSharpTurn) {
1209-
Canvas canvas;
1210-
1211-
Paint paint;
1212-
paint.color = Color::Red();
1213-
paint.style = Paint::Style::kStroke;
1214-
paint.stroke_width = 200;
1215-
1216-
Rect rect = {100, 100, 200, 200};
1217-
PathBuilder builder;
1218-
builder.AddArc(rect, Degrees(0), Degrees(90), false);
1219-
1220-
canvas.DrawPath(builder.TakePath(), paint);
1221-
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
1222-
}
1223-
1224-
TEST_P(AiksTest, CanRenderStrokePathWithCubicLine) {
1225-
Canvas canvas;
1226-
1227-
Paint paint;
1228-
paint.color = Color::Red();
1229-
paint.style = Paint::Style::kStroke;
1230-
paint.stroke_width = 20;
1231-
1232-
PathBuilder builder;
1233-
builder.AddCubicCurve({0, 200}, {50, 400}, {350, 0}, {400, 200});
1234-
1235-
canvas.DrawPath(builder.TakePath(), paint);
1236-
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
1237-
}
1238-
12391208
TEST_P(AiksTest, CanRenderDifferencePaths) {
12401209
Canvas canvas;
12411210

@@ -2047,22 +2016,6 @@ TEST_P(AiksTest, DrawRectStrokesRenderCorrectly) {
20472016
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
20482017
}
20492018

2050-
TEST_P(AiksTest, DrawRectStrokesWithBevelJoinRenderCorrectly) {
2051-
Canvas canvas;
2052-
Paint paint;
2053-
paint.color = Color::Red();
2054-
paint.style = Paint::Style::kStroke;
2055-
paint.stroke_width = 10;
2056-
paint.stroke_join = Join::kBevel;
2057-
2058-
canvas.Translate({100, 100});
2059-
canvas.DrawPath(
2060-
PathBuilder{}.AddRect(Rect::MakeSize(Size{100, 100})).TakePath(),
2061-
{paint});
2062-
2063-
ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
2064-
}
2065-
20662019
TEST_P(AiksTest, SaveLayerDrawsBehindSubsequentEntities) {
20672020
// Compare with https://fiddle.skia.org/c/9e03de8567ffb49e7e83f53b64bcf636
20682021
Canvas canvas;

impeller/core/formats.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -325,33 +325,11 @@ enum class IndexType {
325325
kNone,
326326
};
327327

328-
/// Decides how backend draws pixels based on input vertices.
329328
enum class PrimitiveType {
330-
/// Draws a triage for each separate set of three vertices.
331-
///
332-
/// Vertices [A, B, C, D, E, F] will produce triages
333-
/// [ABC, DEF].
334329
kTriangle,
335-
336-
/// Draws a triage for every adjacent three vertices.
337-
///
338-
/// Vertices [A, B, C, D, E, F] will produce triages
339-
/// [ABC, BCD, CDE, DEF].
340330
kTriangleStrip,
341-
342-
/// Draws a line for each separate set of two vertices.
343-
///
344-
/// Vertices [A, B, C] will produce discontinued line
345-
/// [AB, BC].
346331
kLine,
347-
348-
/// Draws a continuous line that connect every input vertices
349-
///
350-
/// Vertices [A, B, C] will produce one continuous line
351-
/// [ABC].
352332
kLineStrip,
353-
354-
/// Draws a point at each input vertex.
355333
kPoint,
356334
// Triangle fans are implementation dependent and need extra extensions
357335
// checks. Hence, they are not supported here.

impeller/entity/geometry/stroke_path_geometry.cc

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ StrokePathGeometry::CreateSolidStrokeVertices(
253253
for (size_t contour_i = 0; contour_i < polyline.contours.size();
254254
contour_i++) {
255255
auto contour = polyline.contours[contour_i];
256-
size_t contour_component_i = 0;
257256
size_t contour_start_point_i, contour_end_point_i;
258257
std::tie(contour_start_point_i, contour_end_point_i) =
259258
polyline.GetContourPointBounds(contour_i);
@@ -309,55 +308,27 @@ StrokePathGeometry::CreateSolidStrokeVertices(
309308
// Generate contour geometry.
310309
for (size_t point_i = contour_start_point_i + 1;
311310
point_i < contour_end_point_i; point_i++) {
312-
if ((contour_component_i + 1 >= contour.components.size()) &&
313-
contour.components[contour_component_i + 1].component_start_index <=
314-
point_i) {
315-
// The point_i has entered the next component in this contour.
316-
contour_component_i += 1;
317-
}
318311
// Generate line rect.
319312
vtx.position = polyline.points[point_i - 1] + offset;
320313
vtx_builder.AppendVertex(vtx);
321314
vtx.position = polyline.points[point_i - 1] - offset;
322315
vtx_builder.AppendVertex(vtx);
316+
vtx.position = polyline.points[point_i] + offset;
317+
vtx_builder.AppendVertex(vtx);
318+
vtx.position = polyline.points[point_i] - offset;
319+
vtx_builder.AppendVertex(vtx);
323320

324-
auto is_end_of_contour = point_i == contour_end_point_i - 1;
325-
326-
if (!contour.components[contour_component_i].is_curve) {
327-
// For line components, two additional points need to be appended prior
328-
// to appending a join connecting the next component.
329-
vtx.position = polyline.points[point_i] + offset;
330-
vtx_builder.AppendVertex(vtx);
331-
vtx.position = polyline.points[point_i] - offset;
332-
vtx_builder.AppendVertex(vtx);
321+
if (point_i < contour_end_point_i - 1) {
322+
compute_offset(point_i + 1);
333323

334-
if (!is_end_of_contour) {
335-
compute_offset(point_i + 1);
336-
// Generate join from the current line to the next line.
337-
join_proc(vtx_builder, polyline.points[point_i], previous_offset,
338-
offset, scaled_miter_limit, scale);
339-
}
340-
} else {
341-
// For curve components, the polyline is detailed enough such that
342-
// it can avoid worrying about joins altogether.
343-
if (!is_end_of_contour) {
344-
compute_offset(point_i + 1);
345-
} else {
346-
// If this is a curve and is the end of the contour, two end points
347-
// need to be drawn with the contour end_direction.
348-
auto end_offset =
349-
Vector2(-contour.end_direction.y, contour.end_direction.x) *
350-
stroke_width * 0.5;
351-
vtx.position = polyline.points[contour_end_point_i - 1] + end_offset;
352-
vtx_builder.AppendVertex(vtx);
353-
vtx.position = polyline.points[contour_end_point_i - 1] - end_offset;
354-
vtx_builder.AppendVertex(vtx);
355-
}
324+
// Generate join from the current line to the next line.
325+
join_proc(vtx_builder, polyline.points[point_i], previous_offset,
326+
offset, scaled_miter_limit, scale);
356327
}
357328
}
358329

359330
// Generate end cap or join.
360-
if (!contour.is_closed) {
331+
if (!polyline.contours[contour_i].is_closed) {
361332
auto cap_offset =
362333
Vector2(-contour.end_direction.y, contour.end_direction.x) *
363334
stroke_width * 0.5; // Clockwise normal

impeller/geometry/path.cc

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,9 @@ Path::Polyline Path::CreatePolyline(Scalar scale) const {
324324
return Vector2(0, -1);
325325
};
326326

327-
std::vector<PolylineContour::Component> components;
328327
std::optional<size_t> previous_path_component_index;
329328
auto end_contour = [&polyline, &previous_path_component_index,
330-
&get_path_component, &components]() {
329+
&get_path_component]() {
331330
// Whenever a contour has ended, extract the exact end direction from the
332331
// last component.
333332
if (polyline.contours.empty()) {
@@ -340,8 +339,6 @@ Path::Polyline Path::CreatePolyline(Scalar scale) const {
340339

341340
auto& contour = polyline.contours.back();
342341
contour.end_direction = Vector2(0, 1);
343-
contour.components = components;
344-
components.clear();
345342

346343
size_t previous_index = previous_path_component_index.value();
347344
while (!std::holds_alternative<std::monostate>(
@@ -366,26 +363,14 @@ Path::Polyline Path::CreatePolyline(Scalar scale) const {
366363
const auto& component = components_[component_i];
367364
switch (component.type) {
368365
case ComponentType::kLinear:
369-
components.push_back({
370-
.component_start_index = polyline.points.size(),
371-
.is_curve = false,
372-
});
373366
collect_points(linears_[component.index].CreatePolyline());
374367
previous_path_component_index = component_i;
375368
break;
376369
case ComponentType::kQuadratic:
377-
components.push_back({
378-
.component_start_index = polyline.points.size(),
379-
.is_curve = true,
380-
});
381370
collect_points(quads_[component.index].CreatePolyline(scale));
382371
previous_path_component_index = component_i;
383372
break;
384373
case ComponentType::kCubic:
385-
components.push_back({
386-
.component_start_index = polyline.points.size(),
387-
.is_curve = true,
388-
});
389374
collect_points(cubics_[component.index].CreatePolyline(scale));
390375
previous_path_component_index = component_i;
391376
break;
@@ -401,14 +386,13 @@ Path::Polyline Path::CreatePolyline(Scalar scale) const {
401386
const auto& contour = contours_[component.index];
402387
polyline.contours.push_back({.start_index = polyline.points.size(),
403388
.is_closed = contour.is_closed,
404-
.start_direction = start_direction,
405-
.components = components});
389+
.start_direction = start_direction});
406390
previous_contour_point = std::nullopt;
407391
collect_points({contour.destination});
408392
break;
409393
}
394+
end_contour();
410395
}
411-
end_contour();
412396
return polyline;
413397
}
414398

impeller/geometry/path.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,8 @@ class Path {
6161
};
6262

6363
struct PolylineContour {
64-
struct Component {
65-
size_t component_start_index;
66-
/// Denotes whether this component is a curve.
67-
///
68-
/// This is set to true when this component is generated from
69-
/// QuadraticComponent or CubicPathComponent.
70-
bool is_curve;
71-
};
7264
/// Index that denotes the first point of this contour.
7365
size_t start_index;
74-
7566
/// Denotes whether the last point of this contour is connected to the first
7667
/// point of this contour or not.
7768
bool is_closed;
@@ -80,12 +71,6 @@ class Path {
8071
Vector2 start_direction;
8172
/// The direction of the contour's end cap.
8273
Vector2 end_direction;
83-
84-
/// Distinct components in this contour.
85-
///
86-
/// If this contour is generated from multiple path components, each
87-
/// path component forms a component in this vector.
88-
std::vector<Component> components;
8974
};
9075

9176
/// One or more contours represented as a series of points and indices in

impeller/geometry/path_component.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ struct LinearPathComponent {
4747
std::optional<Vector2> GetEndDirection() const;
4848
};
4949

50-
// A component that represets a Quadratic Bézier curve.
5150
struct QuadraticPathComponent {
52-
// Start point.
5351
Point p1;
54-
// Control point.
5552
Point cp;
56-
// End point.
5753
Point p2;
5854

5955
QuadraticPathComponent() {}
@@ -91,15 +87,10 @@ struct QuadraticPathComponent {
9187
std::optional<Vector2> GetEndDirection() const;
9288
};
9389

94-
// A component that represets a Cubic Bézier curve.
9590
struct CubicPathComponent {
96-
// Start point.
9791
Point p1;
98-
// The first control point.
9992
Point cp1;
100-
// The second control point.
10193
Point cp2;
102-
// End point.
10394
Point p2;
10495

10596
CubicPathComponent() {}

0 commit comments

Comments
 (0)