GrTessellator: Implement a fast path in poly emission.
authorStephen White <senorblanco@chromium.org>
Fri, 3 Mar 2017 17:24:16 +0000 (12:24 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 3 Mar 2017 21:18:05 +0000 (21:18 +0000)
When there's a single triangle remaining in the monotone,
emit early and skip a convexity check.

BUG=skia:

Change-Id: I591acf4b7f567dbbf7681ba72181e578ca4623ec
Reviewed-on: https://skia-review.googlesource.com/8797
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Brian Salomon <bsalomon@google.com>
src/gpu/GrTessellator.cpp

index 80a813f..10f6edf 100644 (file)
@@ -481,6 +481,7 @@ struct Poly {
             Edge* e = fFirstEdge;
             VertexList vertices;
             vertices.append(e->fTop);
+            int count = 1;
             while (e != nullptr) {
                 if (kRight_Side == fSide) {
                     vertices.append(e->fBottom);
@@ -489,6 +490,7 @@ struct Poly {
                     vertices.prepend(e->fBottom);
                     e = e->fLeftPolyNext;
                 }
+                count++;
             }
             Vertex* first = vertices.fHead;
             Vertex* v = first->fNext;
@@ -497,6 +499,9 @@ struct Poly {
                 Vertex* prev = v->fPrev;
                 Vertex* curr = v;
                 Vertex* next = v->fNext;
+                if (count == 3) {
+                    return emit_triangle(prev, curr, next, aaParams, data);
+                }
                 double ax = static_cast<double>(curr->fPoint.fX) - prev->fPoint.fX;
                 double ay = static_cast<double>(curr->fPoint.fY) - prev->fPoint.fY;
                 double bx = static_cast<double>(next->fPoint.fX) - curr->fPoint.fX;
@@ -505,6 +510,7 @@ struct Poly {
                     data = emit_triangle(prev, curr, next, aaParams, data);
                     v->fPrev->fNext = v->fNext;
                     v->fNext->fPrev = v->fPrev;
+                    count--;
                     if (v->fPrev == first) {
                         v = v->fNext;
                     } else {