aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/concavepaths.cpp
diff options
context:
space:
mode:
authorGravatar Stephen White <senorblanco@chromium.org>2017-06-06 14:51:19 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-06-07 00:09:15 +0000
commit3b5a3fa8b1c11d4bd4499b040311f4c3553ebf8c (patch)
treee11a87cbeab2f235c8f408a2a7ec6a758e544f2a /gm/concavepaths.cpp
parent31550dbc9804dafb18a71c968deb513cc8857cf3 (diff)
GrTessellator: implement out-of-range splitting and AEL rewinding.
Due to floating point inaccuracy, when intersecting edges, the intersection point may fall above one of the edges' top vertices or below one of the bottom vertices. In these cases, we were simply splitting one edge on the relevant endpoint of the other edge. This is incorrect if the intersection is far from the endpoint (e.g., the test case in the linked bug, where one of the intersected edges is near-horizontal but the intersection falls below both of its endpoints, in the middle of the edge.) The correct solution is to split both edges as normal, and take care to produce edges with the correct ordering where the intersection is above or below an edge. However, since the new vertex may be above the current vertex, simply restarting intersection checks at the current vertex won't work. We need to process the intersection vertex before the current one. This introduces another problem: unlike all other splitting modes (which always shorten edges), splitting an edge above the top or below the bottom can lengthen it, causing it to violate the AEL with an adjacent edge which then shortens it back to the original point (in cleanup_active_edges()). Since the splitting and merging code can't agree, we loop forever. Instead of simply fusing neighboring edges in cleanup_active_edges(), the proper fix to this problem is to detect the AEL violation and rewind all processing to the vertex above it. For performance, we only rewind when we detect that a split edge is no longer ordered within the mesh (merge_enclosing_edges()) or within the the AEL (rewind_if_necessary()). We also store the enclosing edges of each vertex, which allows us to rewind quickly, since we know exactly which edges need to be added/removed from the AEL. cleanup_active_edges(), fix_active_state() and Vertex::fProcessed have been removed. In their place are rewind_active_edges() and rewind_if_necessary(), which uses the same logic as cleanup_active_edges() but uses it to know when to rewind. Bug: skia:5026 Change-Id: I3638a429f5428498d6df6bb7b98c67374dc291aa Reviewed-on: https://skia-review.googlesource.com/18900 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Stephen White <senorblanco@chromium.org>
Diffstat (limited to 'gm/concavepaths.cpp')
-rw-r--r--gm/concavepaths.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/gm/concavepaths.cpp b/gm/concavepaths.cpp
index 890f6c0855..fe8a1418ab 100644
--- a/gm/concavepaths.cpp
+++ b/gm/concavepaths.cpp
@@ -159,6 +159,20 @@ void test_star(SkCanvas* canvas, const SkPaint& paint) {
canvas->restore();
}
+// Exercise a case where the intersection is below a bottom edge.
+void test_twist(SkCanvas* canvas, const SkPaint& paint) {
+ SkPath path;
+ canvas->save();
+ path.moveTo( 0.5, 6);
+ path.lineTo(5.8070392608642578125, 6.4612660408020019531);
+ path.lineTo(-2.9186885356903076172, 2.811046600341796875);
+ path.lineTo(0.49999994039535522461, -1.4124038219451904297);
+ canvas->translate(420, 220);
+ canvas->scale(10, 10);
+ canvas->drawPath(path, paint);
+ canvas->restore();
+}
+
// Stairstep with repeated vert (intersection)
void test_stairstep(SkCanvas* canvas, const SkPaint& paint) {
SkPath path;
@@ -409,6 +423,7 @@ DEF_SIMPLE_GM(concavepaths, canvas, 500, 600) {
test_fast_forward(canvas, paint);
test_hole(canvas, paint);
test_star(canvas, paint);
+ test_twist(canvas, paint);
test_inversion_repeat_vertex(canvas, paint);
test_stairstep(canvas, paint);
test_stairstep2(canvas, paint);