-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Render axis-aligned Caps for zero length lines in Impeller #35298
Conversation
|
I wanted to add a rotation test to the zero-length line unit test but I ran into an interesting problem with the tesselation. The following patch fails to render the "rotated" versions of the line/path, but if you change the rotation to any value except for 45, then it renders just fine. Why does a 45 degree angle freak out the tesselator? @bdero ? Rotation unit test patch |
|
Tried this patch locally and the frame fails to render for me. Stepped through with the debugger and it's hitting the polyline point size check. One approach that can work is to embrace the deduplication and handle the single point contour case internally like this: diff --git a/impeller/entity/contents/solid_stroke_contents.cc b/impeller/entity/contents/solid_stroke_contents.cc
index c332b966c5..fecb17798c 100644
--- a/impeller/entity/contents/solid_stroke_contents.cc
+++ b/impeller/entity/contents/solid_stroke_contents.cc
@@ -72,7 +72,7 @@ static VertexBuffer CreateSolidStrokeVertices(
VertexBufferBuilder<VS::PerVertexData> vtx_builder;
auto polyline = path.CreatePolyline();
- if (polyline.points.size() < 2) {
+ if (polyline.points.empty()) {
return {}; // Nothing to render.
}
@@ -95,6 +95,12 @@ static VertexBuffer CreateSolidStrokeVertices(
std::tie(contour_start_point_i, contour_end_point_i) =
polyline.GetContourPointBounds(contour_i);
+ if (contour_end_point_i - contour_start_point_i == 1) {
+ cap_proc(vtx_builder, polyline.points[0], {0, 1}, smoothing);
+ cap_proc(vtx_builder, polyline.points[0], {0, -1}, smoothing);
+ continue;
+ }
+
if (contour_end_point_i - contour_start_point_i < 2) {
continue; // This contour has no renderable content.
}These normals aren't respecting the transform, but that's a separate issue. |
AFAICT this method works entirely in path-space? The normals aren't necessarily normal in a transformed space. (Which means everywhere it does a {-y, x} or something similar to the normals would not work in device space under a skew transform.) |
|
Sorry, disregard the comment about the normals -- I think I misread the test. I suspected we weren't handling normals right in the vertex shader, but it lgtm. |
bdero
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍 I think the funky 45 degree problem is a preexisting issue rising to the surface. Maybe drop your useful repro in a new bug?
| continue; // This contour has no renderable content. | ||
| switch (contour_end_point_i - contour_start_point_i) { | ||
| case 1: { | ||
| Point p = polyline.points[contour_start_point_i]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch that this index should be contour_start_point_i.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, haha, I didn't cut/paste your code, I just went "aha" and wrote it manually. So I didn't even really catch anything...
fixes flutter/flutter#109077