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>
2 files changed