Index: src/gpu/batches/GrTessellatingPathRenderer.cpp |
diff --git a/src/gpu/batches/GrTessellatingPathRenderer.cpp b/src/gpu/batches/GrTessellatingPathRenderer.cpp |
index 27e287e9c6bceb6b48c7e500ef338fcc7b259775..d5fe886c0773e58c4f7ffcfe9e93db4779a2912f 100644 |
--- a/src/gpu/batches/GrTessellatingPathRenderer.cpp |
+++ b/src/gpu/batches/GrTessellatingPathRenderer.cpp |
@@ -14,7 +14,6 @@ |
#include "GrVertices.h" |
#include "GrResourceCache.h" |
#include "GrResourceProvider.h" |
-#include "SkChunkAlloc.h" |
#include "SkGeometry.h" |
#include "batches/GrVertexBatch.h" |
@@ -80,10 +79,9 @@ |
* increasing in Y; edges to the right are decreasing in Y). That is, the setting rotates 90 |
* degrees counterclockwise, rather that transposing. |
*/ |
-#define LOGGING_ENABLED 0 |
#define WIREFRAME 0 |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
#define LOG printf |
#else |
#define LOG(...) |
@@ -91,9 +89,6 @@ |
#define ALLOC_NEW(Type, args, alloc) new (alloc.allocThrow(sizeof(Type))) Type args |
-namespace { |
- |
-struct Vertex; |
struct Edge; |
struct Poly; |
@@ -128,40 +123,6 @@ void remove(T* t, T** head, T** tail) { |
t->*Prev = t->*Next = nullptr; |
} |
-/** |
- * Vertices are used in three ways: first, the path contours are converted into a |
- * circularly-linked list of Vertices for each contour. After edge construction, the same Vertices |
- * are re-ordered by the merge sort according to the sweep_lt comparator (usually, increasing |
- * in Y) using the same fPrev/fNext pointers that were used for the contours, to avoid |
- * reallocation. Finally, MonotonePolys are built containing a circularly-linked list of |
- * Vertices. (Currently, those Vertices are newly-allocated for the MonotonePolys, since |
- * an individual Vertex from the path mesh may belong to multiple |
- * MonotonePolys, so the original Vertices cannot be re-used. |
- */ |
- |
-struct Vertex { |
- Vertex(const SkPoint& point) |
- : fPoint(point), fPrev(nullptr), fNext(nullptr) |
- , fFirstEdgeAbove(nullptr), fLastEdgeAbove(nullptr) |
- , fFirstEdgeBelow(nullptr), fLastEdgeBelow(nullptr) |
- , fProcessed(false) |
-#if LOGGING_ENABLED |
- , fID (-1.0f) |
-#endif |
- {} |
- SkPoint fPoint; // Vertex position |
- Vertex* fPrev; // Linked list of contours, then Y-sorted vertices. |
- Vertex* fNext; // " |
- Edge* fFirstEdgeAbove; // Linked list of edges above this vertex. |
- Edge* fLastEdgeAbove; // " |
- Edge* fFirstEdgeBelow; // Linked list of edges below this vertex. |
- Edge* fLastEdgeBelow; // " |
- bool fProcessed; // Has this vertex been seen in simplify()? |
-#if LOGGING_ENABLED |
- float fID; // Identifier used for logging. |
-#endif |
-}; |
- |
/***************************************************************************************/ |
typedef bool (*CompareFunc)(const SkPoint& a, const SkPoint& b); |
@@ -187,12 +148,13 @@ bool sweep_gt_vert(const SkPoint& a, const SkPoint& b) { |
return a.fY == b.fY ? a.fX > b.fX : a.fY > b.fY; |
} |
-inline SkPoint* emit_vertex(Vertex* v, SkPoint* data) { |
+inline SkPoint* emit_vertex(TessellatingVertex* v, SkPoint* data) { |
*data++ = v->fPoint; |
return data; |
} |
-SkPoint* emit_triangle(Vertex* v0, Vertex* v1, Vertex* v2, SkPoint* data) { |
+SkPoint* emit_triangle(TessellatingVertex* v0, TessellatingVertex* v1, TessellatingVertex* v2, |
+ SkPoint* data) { |
#if WIREFRAME |
data = emit_vertex(v0, data); |
data = emit_vertex(v1, data); |
@@ -233,7 +195,7 @@ struct EdgeList { |
*/ |
struct Edge { |
- Edge(Vertex* top, Vertex* bottom, int winding) |
+ Edge(TessellatingVertex* top, TessellatingVertex* bottom, int winding) |
: fWinding(winding) |
, fTop(top) |
, fBottom(bottom) |
@@ -247,27 +209,27 @@ struct Edge { |
, fRightPoly(nullptr) { |
recompute(); |
} |
- int fWinding; // 1 == edge goes downward; -1 = edge goes upward. |
- Vertex* fTop; // The top vertex in vertex-sort-order (sweep_lt). |
- Vertex* fBottom; // The bottom vertex in vertex-sort-order. |
- Edge* fLeft; // The linked list of edges in the active edge list. |
- Edge* fRight; // " |
- Edge* fPrevEdgeAbove; // The linked list of edges in the bottom Vertex's "edges above". |
- Edge* fNextEdgeAbove; // " |
- Edge* fPrevEdgeBelow; // The linked list of edges in the top Vertex's "edges below". |
- Edge* fNextEdgeBelow; // " |
- Poly* fLeftPoly; // The Poly to the left of this edge, if any. |
- Poly* fRightPoly; // The Poly to the right of this edge, if any. |
- double fDX; // The line equation for this edge, in implicit form. |
- double fDY; // fDY * x + fDX * y + fC = 0, for point (x, y) on the line. |
+ int fWinding; // 1 == edge goes downward; -1 = edge goes upward. |
+ TessellatingVertex* fTop; // The top vertex in vertex-sort-order (sweep_lt). |
+ TessellatingVertex* fBottom; // The bottom vertex in vertex-sort-order. |
+ Edge* fLeft; // The linked list of edges in the active edge list. |
+ Edge* fRight; // " |
+ Edge* fPrevEdgeAbove; // The linked list of edges in the bottom Vertex's "edges above". |
+ Edge* fNextEdgeAbove; // " |
+ Edge* fPrevEdgeBelow; // The linked list of edges in the top Vertex's "edges below". |
+ Edge* fNextEdgeBelow; // " |
+ Poly* fLeftPoly; // The Poly to the left of this edge, if any. |
+ Poly* fRightPoly; // The Poly to the right of this edge, if any. |
+ double fDX; // The line equation for this edge, in implicit form. |
+ double fDY; // fDY * x + fDX * y + fC = 0, for point (x, y) on the line. |
double fC; |
double dist(const SkPoint& p) const { |
return fDY * p.fX - fDX * p.fY + fC; |
} |
- bool isRightOf(Vertex* v) const { |
+ bool isRightOf(TessellatingVertex* v) const { |
return dist(v->fPoint) < 0.0; |
} |
- bool isLeftOf(Vertex* v) const { |
+ bool isLeftOf(TessellatingVertex* v) const { |
return dist(v->fPoint) > 0.0; |
} |
void recompute() { |
@@ -320,7 +282,7 @@ struct Poly { |
, fPartner(nullptr) |
, fCount(0) |
{ |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
static int gID = 0; |
fID = gID++; |
LOG("*** created Poly %d\n", fID); |
@@ -335,12 +297,12 @@ struct Poly { |
, fPrev(nullptr) |
, fNext(nullptr) {} |
Side fSide; |
- Vertex* fHead; |
- Vertex* fTail; |
+ TessellatingVertex* fHead; |
+ TessellatingVertex* fTail; |
MonotonePoly* fPrev; |
MonotonePoly* fNext; |
- bool addVertex(Vertex* v, Side side, SkChunkAlloc& alloc) { |
- Vertex* newV = ALLOC_NEW(Vertex, (v->fPoint), alloc); |
+ bool addVertex(TessellatingVertex* v, Side side, SkChunkAlloc& alloc) { |
+ TessellatingVertex* newV = ALLOC_NEW(TessellatingVertex, (v->fPoint), alloc); |
bool done = false; |
if (fSide == kNeither_Side) { |
fSide = side; |
@@ -361,14 +323,14 @@ struct Poly { |
return done; |
} |
- SkPoint* emit(SkPoint* data) { |
- Vertex* first = fHead; |
- Vertex* v = first->fNext; |
+ SkPoint* emit(int winding, SkPoint* data) { |
+ TessellatingVertex* first = fHead; |
+ TessellatingVertex* v = first->fNext; |
while (v != fTail) { |
SkASSERT(v && v->fPrev && v->fNext); |
- Vertex* prev = v->fPrev; |
- Vertex* curr = v; |
- Vertex* next = v->fNext; |
+ TessellatingVertex* prev = v->fPrev; |
+ TessellatingVertex* curr = v; |
+ TessellatingVertex* next = v->fNext; |
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; |
@@ -389,7 +351,7 @@ struct Poly { |
return data; |
} |
}; |
- Poly* addVertex(Vertex* v, Side side, SkChunkAlloc& alloc) { |
+ Poly* addVertex(TessellatingVertex* v, Side side, SkChunkAlloc& alloc) { |
LOG("addVertex() to %d at %g (%g, %g), %s side\n", fID, v->fID, v->fPoint.fX, v->fPoint.fY, |
side == kLeft_Side ? "left" : side == kRight_Side ? "right" : "neither"); |
Poly* partner = fPartner; |
@@ -412,7 +374,7 @@ struct Poly { |
partner->addVertex(v, side, alloc); |
poly = partner; |
} else { |
- Vertex* prev = fActive->fSide == Poly::kLeft_Side ? |
+ TessellatingVertex* prev = fActive->fSide == Poly::kLeft_Side ? |
fActive->fHead->fNext : fActive->fTail->fPrev; |
fActive = ALLOC_NEW(MonotonePoly, , alloc); |
fActive->addVertex(prev, Poly::kNeither_Side, alloc); |
@@ -422,7 +384,7 @@ struct Poly { |
fCount++; |
return poly; |
} |
- void end(Vertex* v, SkChunkAlloc& alloc) { |
+ void end(TessellatingVertex* v, SkChunkAlloc& alloc) { |
LOG("end() %d at %g, %g\n", fID, v->fPoint.fX, v->fPoint.fY); |
if (fPartner) { |
fPartner = fPartner->fPartner = nullptr; |
@@ -435,7 +397,7 @@ struct Poly { |
} |
LOG("emit() %d, size %d\n", fID, fCount); |
for (MonotonePoly* m = fHead; m != nullptr; m = m->fNext) { |
- data = m->emit(data); |
+ data = m->emit(fWinding, data); |
} |
return data; |
} |
@@ -446,7 +408,7 @@ struct Poly { |
Poly* fNext; |
Poly* fPartner; |
int fCount; |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
int fID; |
#endif |
}; |
@@ -457,7 +419,7 @@ bool coincident(const SkPoint& a, const SkPoint& b) { |
return a == b; |
} |
-Poly* new_poly(Poly** head, Vertex* v, int winding, SkChunkAlloc& alloc) { |
+Poly* new_poly(Poly** head, TessellatingVertex* v, int winding, SkChunkAlloc& alloc) { |
Poly* poly = ALLOC_NEW(Poly, (winding), alloc); |
poly->addVertex(v, Poly::kNeither_Side, alloc); |
poly->fNext = *head; |
@@ -465,10 +427,10 @@ Poly* new_poly(Poly** head, Vertex* v, int winding, SkChunkAlloc& alloc) { |
return poly; |
} |
-Vertex* append_point_to_contour(const SkPoint& p, Vertex* prev, Vertex** head, |
- SkChunkAlloc& alloc) { |
- Vertex* v = ALLOC_NEW(Vertex, (p), alloc); |
-#if LOGGING_ENABLED |
+TessellatingVertex* append_point_to_contour(const SkPoint& p, TessellatingVertex* prev, |
+ TessellatingVertex** head, SkChunkAlloc& alloc) { |
+ TessellatingVertex* v = ALLOC_NEW(TessellatingVertex, (p), alloc); |
+#if TESSELLATION_LOGGING_ENABLED |
static float gID = 0.0f; |
v->fID = gID++; |
#endif |
@@ -481,12 +443,12 @@ Vertex* append_point_to_contour(const SkPoint& p, Vertex* prev, Vertex** head, |
return v; |
} |
-Vertex* generate_quadratic_points(const SkPoint& p0, |
+TessellatingVertex* generate_quadratic_points(const SkPoint& p0, |
const SkPoint& p1, |
const SkPoint& p2, |
SkScalar tolSqd, |
- Vertex* prev, |
- Vertex** head, |
+ TessellatingVertex* prev, |
+ TessellatingVertex** head, |
int pointsLeft, |
SkChunkAlloc& alloc) { |
SkScalar d = p1.distanceToLineSegmentBetweenSqd(p0, p2); |
@@ -506,13 +468,13 @@ Vertex* generate_quadratic_points(const SkPoint& p0, |
return prev; |
} |
-Vertex* generate_cubic_points(const SkPoint& p0, |
+TessellatingVertex* generate_cubic_points(const SkPoint& p0, |
const SkPoint& p1, |
const SkPoint& p2, |
const SkPoint& p3, |
SkScalar tolSqd, |
- Vertex* prev, |
- Vertex** head, |
+ TessellatingVertex* prev, |
+ TessellatingVertex** head, |
int pointsLeft, |
SkChunkAlloc& alloc) { |
SkScalar d1 = p1.distanceToLineSegmentBetweenSqd(p0, p3); |
@@ -540,7 +502,7 @@ Vertex* generate_cubic_points(const SkPoint& p0, |
// Stage 1: convert the input path to a set of linear contours (linked list of Vertices). |
void path_to_contours(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds, |
- Vertex** contours, SkChunkAlloc& alloc, bool *isLinear) { |
+ TessellatingVertex** contours, SkChunkAlloc& alloc, bool *isLinear) { |
SkScalar toleranceSqd = tolerance * tolerance; |
@@ -548,8 +510,8 @@ void path_to_contours(const SkPath& path, SkScalar tolerance, const SkRect& clip |
bool done = false; |
*isLinear = true; |
SkPath::Iter iter(path, false); |
- Vertex* prev = nullptr; |
- Vertex* head = nullptr; |
+ TessellatingVertex* prev = nullptr; |
+ TessellatingVertex* head = nullptr; |
if (path.isInverseFillType()) { |
SkPoint quad[4]; |
clipBounds.toQuad(quad); |
@@ -640,10 +602,11 @@ inline bool apply_fill_type(SkPath::FillType fillType, int winding) { |
} |
} |
-Edge* new_edge(Vertex* prev, Vertex* next, SkChunkAlloc& alloc, Comparator& c) { |
+Edge* new_edge(TessellatingVertex* prev, TessellatingVertex* next, SkChunkAlloc& alloc, |
+ Comparator& c) { |
int winding = c.sweep_lt(prev->fPoint, next->fPoint) ? 1 : -1; |
- Vertex* top = winding < 0 ? next : prev; |
- Vertex* bottom = winding < 0 ? prev : next; |
+ TessellatingVertex* top = winding < 0 ? next : prev; |
+ TessellatingVertex* bottom = winding < 0 ? prev : next; |
return ALLOC_NEW(Edge, (top, bottom, winding), alloc); |
} |
@@ -660,7 +623,7 @@ void insert_edge(Edge* edge, Edge* prev, EdgeList* edges) { |
insert<Edge, &Edge::fLeft, &Edge::fRight>(edge, prev, next, &edges->fHead, &edges->fTail); |
} |
-void find_enclosing_edges(Vertex* v, EdgeList* edges, Edge** left, Edge** right) { |
+void find_enclosing_edges(TessellatingVertex* v, EdgeList* edges, Edge** left, Edge** right) { |
if (v->fFirstEdgeAbove) { |
*left = v->fFirstEdgeAbove->fLeft; |
*right = v->fLastEdgeAbove->fRight; |
@@ -711,7 +674,7 @@ void fix_active_state(Edge* edge, EdgeList* activeEdges, Comparator& c) { |
} |
} |
-void insert_edge_above(Edge* edge, Vertex* v, Comparator& c) { |
+void insert_edge_above(Edge* edge, TessellatingVertex* v, Comparator& c) { |
if (edge->fTop->fPoint == edge->fBottom->fPoint || |
c.sweep_gt(edge->fTop->fPoint, edge->fBottom->fPoint)) { |
return; |
@@ -729,7 +692,7 @@ void insert_edge_above(Edge* edge, Vertex* v, Comparator& c) { |
edge, prev, next, &v->fFirstEdgeAbove, &v->fLastEdgeAbove); |
} |
-void insert_edge_below(Edge* edge, Vertex* v, Comparator& c) { |
+void insert_edge_below(Edge* edge, TessellatingVertex* v, Comparator& c) { |
if (edge->fTop->fPoint == edge->fBottom->fPoint || |
c.sweep_gt(edge->fTop->fPoint, edge->fBottom->fPoint)) { |
return; |
@@ -775,7 +738,7 @@ void erase_edge_if_zero_winding(Edge* edge, EdgeList* edges) { |
void merge_collinear_edges(Edge* edge, EdgeList* activeEdges, Comparator& c); |
-void set_top(Edge* edge, Vertex* v, EdgeList* activeEdges, Comparator& c) { |
+void set_top(Edge* edge, TessellatingVertex* v, EdgeList* activeEdges, Comparator& c) { |
remove_edge_below(edge); |
edge->fTop = v; |
edge->recompute(); |
@@ -784,7 +747,7 @@ void set_top(Edge* edge, Vertex* v, EdgeList* activeEdges, Comparator& c) { |
merge_collinear_edges(edge, activeEdges, c); |
} |
-void set_bottom(Edge* edge, Vertex* v, EdgeList* activeEdges, Comparator& c) { |
+void set_bottom(Edge* edge, TessellatingVertex* v, EdgeList* activeEdges, Comparator& c) { |
remove_edge_above(edge); |
edge->fBottom = v; |
edge->recompute(); |
@@ -850,14 +813,15 @@ void merge_collinear_edges(Edge* edge, EdgeList* activeEdges, Comparator& c) { |
} |
} |
-void split_edge(Edge* edge, Vertex* v, EdgeList* activeEdges, Comparator& c, SkChunkAlloc& alloc); |
+void split_edge(Edge* edge, TessellatingVertex* v, EdgeList* activeEdges, Comparator& c, |
+ SkChunkAlloc& alloc); |
void cleanup_active_edges(Edge* edge, EdgeList* activeEdges, Comparator& c, SkChunkAlloc& alloc) { |
- Vertex* top = edge->fTop; |
- Vertex* bottom = edge->fBottom; |
+ TessellatingVertex* top = edge->fTop; |
+ TessellatingVertex* bottom = edge->fBottom; |
if (edge->fLeft) { |
- Vertex* leftTop = edge->fLeft->fTop; |
- Vertex* leftBottom = edge->fLeft->fBottom; |
+ TessellatingVertex* leftTop = edge->fLeft->fTop; |
+ TessellatingVertex* leftBottom = edge->fLeft->fBottom; |
if (c.sweep_gt(top->fPoint, leftTop->fPoint) && !edge->fLeft->isLeftOf(top)) { |
split_edge(edge->fLeft, edge->fTop, activeEdges, c, alloc); |
} else if (c.sweep_gt(leftTop->fPoint, top->fPoint) && !edge->isRightOf(leftTop)) { |
@@ -870,8 +834,8 @@ void cleanup_active_edges(Edge* edge, EdgeList* activeEdges, Comparator& c, SkCh |
} |
} |
if (edge->fRight) { |
- Vertex* rightTop = edge->fRight->fTop; |
- Vertex* rightBottom = edge->fRight->fBottom; |
+ TessellatingVertex* rightTop = edge->fRight->fTop; |
+ TessellatingVertex* rightBottom = edge->fRight->fBottom; |
if (c.sweep_gt(top->fPoint, rightTop->fPoint) && !edge->fRight->isRightOf(top)) { |
split_edge(edge->fRight, top, activeEdges, c, alloc); |
} else if (c.sweep_gt(rightTop->fPoint, top->fPoint) && !edge->isLeftOf(rightTop)) { |
@@ -886,7 +850,8 @@ void cleanup_active_edges(Edge* edge, EdgeList* activeEdges, Comparator& c, SkCh |
} |
} |
-void split_edge(Edge* edge, Vertex* v, EdgeList* activeEdges, Comparator& c, SkChunkAlloc& alloc) { |
+void split_edge(Edge* edge, TessellatingVertex* v, EdgeList* activeEdges, Comparator& c, |
+ SkChunkAlloc& alloc) { |
LOG("splitting edge (%g -> %g) at vertex %g (%g, %g)\n", |
edge->fTop->fID, edge->fBottom->fID, |
v->fID, v->fPoint.fX, v->fPoint.fY); |
@@ -905,7 +870,8 @@ void split_edge(Edge* edge, Vertex* v, EdgeList* activeEdges, Comparator& c, SkC |
} |
} |
-void merge_vertices(Vertex* src, Vertex* dst, Vertex** head, Comparator& c, SkChunkAlloc& alloc) { |
+void merge_vertices(TessellatingVertex* src, TessellatingVertex* dst, TessellatingVertex** head, |
+ Comparator& c, SkChunkAlloc& alloc) { |
LOG("found coincident verts at %g, %g; merging %g into %g\n", src->fPoint.fX, src->fPoint.fY, |
src->fID, dst->fID); |
for (Edge* edge = src->fFirstEdgeAbove; edge;) { |
@@ -918,17 +884,18 @@ void merge_vertices(Vertex* src, Vertex* dst, Vertex** head, Comparator& c, SkCh |
set_top(edge, dst, nullptr, c); |
edge = next; |
} |
- remove<Vertex, &Vertex::fPrev, &Vertex::fNext>(src, head, nullptr); |
+ remove<TessellatingVertex, &TessellatingVertex::fPrev, &TessellatingVertex::fNext>(src, head, |
+ nullptr); |
} |
-Vertex* check_for_intersection(Edge* edge, Edge* other, EdgeList* activeEdges, Comparator& c, |
- SkChunkAlloc& alloc) { |
+TessellatingVertex* check_for_intersection(Edge* edge, Edge* other, EdgeList* activeEdges, |
+ Comparator& c, SkChunkAlloc& alloc) { |
SkPoint p; |
if (!edge || !other) { |
return nullptr; |
} |
if (edge->intersect(*other, &p)) { |
- Vertex* v; |
+ TessellatingVertex* v; |
LOG("found intersection, pt is %g, %g\n", p.fX, p.fY); |
if (p == edge->fTop->fPoint || c.sweep_lt(p, edge->fTop->fPoint)) { |
split_edge(other, edge->fTop, activeEdges, c, alloc); |
@@ -943,24 +910,24 @@ Vertex* check_for_intersection(Edge* edge, Edge* other, EdgeList* activeEdges, C |
split_edge(edge, other->fBottom, activeEdges, c, alloc); |
v = other->fBottom; |
} else { |
- Vertex* nextV = edge->fTop; |
+ TessellatingVertex* nextV = edge->fTop; |
while (c.sweep_lt(p, nextV->fPoint)) { |
nextV = nextV->fPrev; |
} |
while (c.sweep_lt(nextV->fPoint, p)) { |
nextV = nextV->fNext; |
} |
- Vertex* prevV = nextV->fPrev; |
+ TessellatingVertex* prevV = nextV->fPrev; |
if (coincident(prevV->fPoint, p)) { |
v = prevV; |
} else if (coincident(nextV->fPoint, p)) { |
v = nextV; |
} else { |
- v = ALLOC_NEW(Vertex, (p), alloc); |
+ v = ALLOC_NEW(TessellatingVertex, (p), alloc); |
LOG("inserting between %g (%g, %g) and %g (%g, %g)\n", |
prevV->fID, prevV->fPoint.fX, prevV->fPoint.fY, |
nextV->fID, nextV->fPoint.fX, nextV->fPoint.fY); |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
v->fID = (nextV->fID + prevV->fID) * 0.5f; |
#endif |
v->fPrev = prevV; |
@@ -976,10 +943,10 @@ Vertex* check_for_intersection(Edge* edge, Edge* other, EdgeList* activeEdges, C |
return nullptr; |
} |
-void sanitize_contours(Vertex** contours, int contourCnt) { |
+void sanitize_contours(TessellatingVertex** contours, int contourCnt) { |
for (int i = 0; i < contourCnt; ++i) { |
SkASSERT(contours[i]); |
- for (Vertex* v = contours[i];;) { |
+ for (TessellatingVertex* v = contours[i];;) { |
if (coincident(v->fPrev->fPoint, v->fPoint)) { |
LOG("vertex %g,%g coincident; removing\n", v->fPoint.fX, v->fPoint.fY); |
if (v->fPrev == v) { |
@@ -1000,8 +967,8 @@ void sanitize_contours(Vertex** contours, int contourCnt) { |
} |
} |
-void merge_coincident_vertices(Vertex** vertices, Comparator& c, SkChunkAlloc& alloc) { |
- for (Vertex* v = (*vertices)->fNext; v != nullptr; v = v->fNext) { |
+void merge_coincident_vertices(TessellatingVertex** vertices, Comparator& c, SkChunkAlloc& alloc) { |
+ for (TessellatingVertex* v = (*vertices)->fNext; v != nullptr; v = v->fNext) { |
if (c.sweep_lt(v->fPoint, v->fPrev->fPoint)) { |
v->fPoint = v->fPrev->fPoint; |
} |
@@ -1013,12 +980,13 @@ void merge_coincident_vertices(Vertex** vertices, Comparator& c, SkChunkAlloc& a |
// Stage 2: convert the contours to a mesh of edges connecting the vertices. |
-Vertex* build_edges(Vertex** contours, int contourCnt, Comparator& c, SkChunkAlloc& alloc) { |
- Vertex* vertices = nullptr; |
- Vertex* prev = nullptr; |
+TessellatingVertex* build_edges(TessellatingVertex** contours, int contourCnt, Comparator& c, |
+ SkChunkAlloc& alloc) { |
+ TessellatingVertex* vertices = nullptr; |
+ TessellatingVertex* prev = nullptr; |
for (int i = 0; i < contourCnt; ++i) { |
- for (Vertex* v = contours[i]; v != nullptr;) { |
- Vertex* vNext = v->fNext; |
+ for (TessellatingVertex* v = contours[i]; v != nullptr;) { |
+ TessellatingVertex* vNext = v->fNext; |
Edge* edge = new_edge(v->fPrev, v, alloc, c); |
if (edge->fWinding > 0) { |
insert_edge_below(edge, v->fPrev, c); |
@@ -1047,11 +1015,12 @@ Vertex* build_edges(Vertex** contours, int contourCnt, Comparator& c, SkChunkAll |
// Stage 3: sort the vertices by increasing sweep direction. |
-Vertex* sorted_merge(Vertex* a, Vertex* b, Comparator& c); |
+TessellatingVertex* sorted_merge(TessellatingVertex* a, TessellatingVertex* b, Comparator& c); |
-void front_back_split(Vertex* v, Vertex** pFront, Vertex** pBack) { |
- Vertex* fast; |
- Vertex* slow; |
+void front_back_split(TessellatingVertex* v, TessellatingVertex** pFront, |
+ TessellatingVertex** pBack) { |
+ TessellatingVertex* fast; |
+ TessellatingVertex* slow; |
if (!v || !v->fNext) { |
*pFront = v; |
*pBack = nullptr; |
@@ -1074,13 +1043,13 @@ void front_back_split(Vertex* v, Vertex** pFront, Vertex** pBack) { |
} |
} |
-void merge_sort(Vertex** head, Comparator& c) { |
+void merge_sort(TessellatingVertex** head, Comparator& c) { |
if (!*head || !(*head)->fNext) { |
return; |
} |
- Vertex* a; |
- Vertex* b; |
+ TessellatingVertex* a; |
+ TessellatingVertex* b; |
front_back_split(*head, &a, &b); |
merge_sort(&a, c); |
@@ -1089,25 +1058,31 @@ void merge_sort(Vertex** head, Comparator& c) { |
*head = sorted_merge(a, b, c); |
} |
-inline void append_vertex(Vertex* v, Vertex** head, Vertex** tail) { |
- insert<Vertex, &Vertex::fPrev, &Vertex::fNext>(v, *tail, nullptr, head, tail); |
+inline void append_vertex(TessellatingVertex* v, TessellatingVertex** head, |
+ TessellatingVertex** tail) { |
+ insert<TessellatingVertex, &TessellatingVertex::fPrev, &TessellatingVertex::fNext>(v, *tail, |
+ nullptr, |
+ head, tail); |
} |
-inline void append_vertex_list(Vertex* v, Vertex** head, Vertex** tail) { |
- insert<Vertex, &Vertex::fPrev, &Vertex::fNext>(v, *tail, v->fNext, head, tail); |
+inline void append_vertex_list(TessellatingVertex* v, TessellatingVertex** head, |
+ TessellatingVertex** tail) { |
+ insert<TessellatingVertex, &TessellatingVertex::fPrev, &TessellatingVertex::fNext>(v, *tail, |
+ v->fNext, |
+ head, tail); |
} |
-Vertex* sorted_merge(Vertex* a, Vertex* b, Comparator& c) { |
- Vertex* head = nullptr; |
- Vertex* tail = nullptr; |
+TessellatingVertex* sorted_merge(TessellatingVertex* a, TessellatingVertex* b, Comparator& c) { |
+ TessellatingVertex* head = nullptr; |
+ TessellatingVertex* tail = nullptr; |
while (a && b) { |
if (c.sweep_lt(a->fPoint, b->fPoint)) { |
- Vertex* next = a->fNext; |
+ TessellatingVertex* next = a->fNext; |
append_vertex(a, &head, &tail); |
a = next; |
} else { |
- Vertex* next = b->fNext; |
+ TessellatingVertex* next = b->fNext; |
append_vertex(b, &head, &tail); |
b = next; |
} |
@@ -1123,14 +1098,14 @@ Vertex* sorted_merge(Vertex* a, Vertex* b, Comparator& c) { |
// Stage 4: Simplify the mesh by inserting new vertices at intersecting edges. |
-void simplify(Vertex* vertices, Comparator& c, SkChunkAlloc& alloc) { |
+void simplify(TessellatingVertex* vertices, Comparator& c, SkChunkAlloc& alloc) { |
LOG("simplifying complex polygons\n"); |
EdgeList activeEdges; |
- for (Vertex* v = vertices; v != nullptr; v = v->fNext) { |
+ for (TessellatingVertex* v = vertices; v != nullptr; v = v->fNext) { |
if (!v->fFirstEdgeAbove && !v->fFirstEdgeBelow) { |
continue; |
} |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
LOG("\nvertex %g: (%g,%g)\n", v->fID, v->fPoint.fX, v->fPoint.fY); |
#endif |
Edge* leftEnclosingEdge = nullptr; |
@@ -1151,8 +1126,9 @@ void simplify(Vertex* vertices, Comparator& c, SkChunkAlloc& alloc) { |
} |
} |
} else { |
- if (Vertex* pv = check_for_intersection(leftEnclosingEdge, rightEnclosingEdge, |
- &activeEdges, c, alloc)) { |
+ if (TessellatingVertex* pv = check_for_intersection(leftEnclosingEdge, |
+ rightEnclosingEdge, |
+ &activeEdges, c, alloc)) { |
if (c.sweep_lt(pv->fPoint, v->fPoint)) { |
v = pv; |
} |
@@ -1175,15 +1151,15 @@ void simplify(Vertex* vertices, Comparator& c, SkChunkAlloc& alloc) { |
// Stage 5: Tessellate the simplified mesh into monotone polygons. |
-Poly* tessellate(Vertex* vertices, SkChunkAlloc& alloc) { |
+Poly* tessellate(TessellatingVertex* vertices, SkChunkAlloc& alloc) { |
LOG("tessellating simple polygons\n"); |
EdgeList activeEdges; |
Poly* polys = nullptr; |
- for (Vertex* v = vertices; v != nullptr; v = v->fNext) { |
+ for (TessellatingVertex* v = vertices; v != nullptr; v = v->fNext) { |
if (!v->fFirstEdgeAbove && !v->fFirstEdgeBelow) { |
continue; |
} |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
LOG("\nvertex %g: (%g,%g)\n", v->fID, v->fPoint.fX, v->fPoint.fY); |
#endif |
Edge* leftEnclosingEdge = nullptr; |
@@ -1198,7 +1174,7 @@ Poly* tessellate(Vertex* vertices, SkChunkAlloc& alloc) { |
leftPoly = leftEnclosingEdge ? leftEnclosingEdge->fRightPoly : nullptr; |
rightPoly = rightEnclosingEdge ? rightEnclosingEdge->fLeftPoly : nullptr; |
} |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
LOG("edges above:\n"); |
for (Edge* e = v->fFirstEdgeAbove; e; e = e->fNextEdgeAbove) { |
LOG("%g -> %g, lpoly %d, rpoly %d\n", e->fTop->fID, e->fBottom->fID, |
@@ -1280,7 +1256,7 @@ Poly* tessellate(Vertex* vertices, SkChunkAlloc& alloc) { |
} |
v->fLastEdgeBelow->fRightPoly = rightPoly; |
} |
-#if LOGGING_ENABLED |
+#if TESSELLATION_LOGGING_ENABLED |
LOG("\nactive edges:\n"); |
for (Edge* e = activeEdges.fHead; e != nullptr; e = e->fRight) { |
LOG("%g -> %g, lpoly %d, rpoly %d\n", e->fTop->fID, e->fBottom->fID, |
@@ -1293,10 +1269,19 @@ Poly* tessellate(Vertex* vertices, SkChunkAlloc& alloc) { |
// This is a driver function which calls stages 2-5 in turn. |
-Poly* contours_to_polys(Vertex** contours, int contourCnt, Comparator& c, SkChunkAlloc& alloc) { |
-#if LOGGING_ENABLED |
+Poly* contours_to_polys(TessellatingVertex** contours, int contourCnt, SkRect pathBounds, |
+ SkChunkAlloc& alloc) { |
+ Comparator c; |
+ if (pathBounds.width() > pathBounds.height()) { |
+ c.sweep_lt = sweep_lt_horiz; |
+ c.sweep_gt = sweep_gt_horiz; |
+ } else { |
+ c.sweep_lt = sweep_lt_vert; |
+ c.sweep_gt = sweep_gt_vert; |
+ } |
+#if TESSELLATION_LOGGING_ENABLED |
for (int i = 0; i < contourCnt; ++i) { |
- Vertex* v = contours[i]; |
+ TessellatingVertex* v = contours[i]; |
SkASSERT(v); |
LOG("path.moveTo(%20.20g, %20.20g);\n", v->fPoint.fX, v->fPoint.fY); |
for (v = v->fNext; v != contours[i]; v = v->fNext) { |
@@ -1305,7 +1290,7 @@ Poly* contours_to_polys(Vertex** contours, int contourCnt, Comparator& c, SkChun |
} |
#endif |
sanitize_contours(contours, contourCnt); |
- Vertex* vertices = build_edges(contours, contourCnt, c, alloc); |
+ TessellatingVertex* vertices = build_edges(contours, contourCnt, c, alloc); |
if (!vertices) { |
return nullptr; |
} |
@@ -1313,8 +1298,8 @@ Poly* contours_to_polys(Vertex** contours, int contourCnt, Comparator& c, SkChun |
// Sort vertices in Y (secondarily in X). |
merge_sort(&vertices, c); |
merge_coincident_vertices(&vertices, c, alloc); |
-#if LOGGING_ENABLED |
- for (Vertex* v = vertices; v != nullptr; v = v->fNext) { |
+#if TESSELLATION_LOGGING_ENABLED |
+ for (TessellatingVertex* v = vertices; v != nullptr; v = v->fNext) { |
static float gID = 0.0f; |
v->fID = gID++; |
} |
@@ -1323,22 +1308,99 @@ Poly* contours_to_polys(Vertex** contours, int contourCnt, Comparator& c, SkChun |
return tessellate(vertices, alloc); |
} |
+ |
+struct TessInfo { |
+ SkScalar fTolerance; |
+ int fCount; |
+}; |
+ |
// Stage 6: Triangulate the monotone polygons into a vertex buffer. |
-SkPoint* polys_to_triangles(Poly* polys, SkPath::FillType fillType, SkPoint* data) { |
- SkPoint* d = data; |
+int polys_to_triangles(Poly* polys, SkPath::FillType fillType, bool isLinear, |
+ GrResourceProvider* resourceProvider, SkAutoTUnref<GrVertexBuffer>& vertexBuffer, |
+ bool canMapVB) { |
+ int count = 0; |
+ for (Poly* poly = polys; poly; poly = poly->fNext) { |
+ if (apply_fill_type(fillType, poly->fWinding) && poly->fCount >= 3) { |
+ count += (poly->fCount - 2) * (WIREFRAME ? 6 : 3); |
+ } |
+ } |
+ if (0 == count) { |
+ return 0; |
+ } |
+ |
+ size_t size = count * sizeof(SkPoint); |
+ if (!vertexBuffer.get() || vertexBuffer->gpuMemorySize() < size) { |
+ vertexBuffer.reset(resourceProvider->createVertexBuffer( |
+ size, GrResourceProvider::kStatic_BufferUsage, 0)); |
+ } |
+ if (!vertexBuffer.get()) { |
+ SkDebugf("Could not allocate vertices\n"); |
+ return 0; |
+ } |
+ SkPoint* verts; |
+ if (canMapVB) { |
+ verts = static_cast<SkPoint*>(vertexBuffer->map()); |
+ } else { |
+ verts = new SkPoint[count]; |
+ } |
+ SkPoint* end = verts; |
for (Poly* poly = polys; poly; poly = poly->fNext) { |
if (apply_fill_type(fillType, poly->fWinding)) { |
- d = poly->emit(d); |
+ end = poly->emit(end); |
} |
} |
- return d; |
+ int actualCount = static_cast<int>(end - verts); |
+ LOG("actual count: %d\n", actualCount); |
+ SkASSERT(actualCount <= count); |
+ if (canMapVB) { |
+ vertexBuffer->unmap(); |
+ } else { |
+ vertexBuffer->updateData(verts, actualCount * sizeof(SkPoint)); |
+ delete[] verts; |
+ } |
+ |
+ return actualCount; |
} |
-struct TessInfo { |
- SkScalar fTolerance; |
- int fCount; |
-}; |
+// creates an array of (point, winding) vertices and sets the 'verts' out |
+// parameter to point to it. CALLER IS RESPONSIBLE for deleting this buffer to |
+// avoid a memory leak! |
+int polys_to_vertices(Poly* polys, SkPath::FillType fillType, bool isLinear, |
+ WindingVertex** verts) { |
+ int count = 0; |
+ for (Poly* poly = polys; poly; poly = poly->fNext) { |
+ if (apply_fill_type(fillType, poly->fWinding) && poly->fCount >= 3) { |
+ count += (poly->fCount - 2) * (WIREFRAME ? 6 : 3); |
+ } |
+ } |
+ if (0 == count) { |
+ *verts = nullptr; |
+ return 0; |
+ } |
+ |
+ *verts = new WindingVertex[count]; |
+ WindingVertex* vertsEnd = *verts; |
+ SkPoint* points = new SkPoint[count]; |
+ SkPoint* pointsEnd = points; |
+ for (Poly* poly = polys; poly; poly = poly->fNext) { |
+ if (apply_fill_type(fillType, poly->fWinding)) { |
+ SkPoint* start = pointsEnd; |
+ pointsEnd = poly->emit(pointsEnd); |
+ while (start != pointsEnd) { |
+ vertsEnd->fPos = *start; |
+ vertsEnd->fWinding = poly->fWinding; |
+ ++start; |
+ ++vertsEnd; |
+ } |
+ } |
+ } |
+ int actualCount = static_cast<int>(vertsEnd - *verts); |
+ SkASSERT(actualCount <= count); |
+ SkASSERT(pointsEnd - points == actualCount); |
+ delete[] points; |
+ return actualCount; |
+} |
bool cache_match(GrVertexBuffer* vertexBuffer, SkScalar tol, int* actualCount) { |
if (!vertexBuffer) { |
@@ -1354,8 +1416,6 @@ bool cache_match(GrVertexBuffer* vertexBuffer, SkScalar tol, int* actualCount) { |
return false; |
} |
-}; |
- |
GrTessellatingPathRenderer::GrTessellatingPathRenderer() { |
} |
@@ -1435,16 +1495,8 @@ private: |
} |
stroke.setFillStyle(); |
} |
- SkRect pathBounds = path.getBounds(); |
- Comparator c; |
- if (pathBounds.width() > pathBounds.height()) { |
- c.sweep_lt = sweep_lt_horiz; |
- c.sweep_gt = sweep_gt_horiz; |
- } else { |
- c.sweep_lt = sweep_lt_vert; |
- c.sweep_gt = sweep_gt_vert; |
- } |
SkScalar screenSpaceTol = GrPathUtils::kDefaultTolerance; |
+ SkRect pathBounds = path.getBounds(); |
SkScalar tol = GrPathUtils::scaleToleranceToSrc(screenSpaceTol, fViewMatrix, pathBounds); |
int contourCnt; |
int maxPts = GrPathUtils::worstCasePointCount(path, &contourCnt, tol); |
@@ -1460,65 +1512,29 @@ private: |
contourCnt++; |
} |
- LOG("got %d pts, %d contours\n", maxPts, contourCnt); |
- SkAutoTDeleteArray<Vertex*> contours(new Vertex* [contourCnt]); |
+ SkAutoTDeleteArray<TessellatingVertex*> contours(new TessellatingVertex* [contourCnt]); |
// For the initial size of the chunk allocator, estimate based on the point count: |
// one vertex per point for the initial passes, plus two for the vertices in the |
// resulting Polys, since the same point may end up in two Polys. Assume minimal |
- // connectivity of one Edge per Vertex (will grow for intersections). |
- SkChunkAlloc alloc(maxPts * (3 * sizeof(Vertex) + sizeof(Edge))); |
+ // connectivity of one Edge per TessellatingVertex (will grow for intersections). |
+ SkChunkAlloc alloc(maxPts * (3 * sizeof(TessellatingVertex) + sizeof(Edge))); |
bool isLinear; |
path_to_contours(path, tol, fClipBounds, contours.get(), alloc, &isLinear); |
Poly* polys; |
- polys = contours_to_polys(contours.get(), contourCnt, c, alloc); |
- int count = 0; |
- for (Poly* poly = polys; poly; poly = poly->fNext) { |
- if (apply_fill_type(fillType, poly->fWinding) && poly->fCount >= 3) { |
- count += (poly->fCount - 2) * (WIREFRAME ? 6 : 3); |
- } |
- } |
- if (0 == count) { |
- return 0; |
- } |
- |
- size_t size = count * sizeof(SkPoint); |
- if (!vertexBuffer.get() || vertexBuffer->gpuMemorySize() < size) { |
- vertexBuffer.reset(resourceProvider->createVertexBuffer( |
- size, GrResourceProvider::kStatic_BufferUsage, 0)); |
- } |
- if (!vertexBuffer.get()) { |
- SkDebugf("Could not allocate vertices\n"); |
- return 0; |
- } |
- SkPoint* verts; |
- if (canMapVB) { |
- verts = static_cast<SkPoint*>(vertexBuffer->map()); |
- } else { |
- verts = new SkPoint[count]; |
- } |
- SkPoint* end = polys_to_triangles(polys, fillType, verts); |
- int actualCount = static_cast<int>(end - verts); |
- LOG("actual count: %d\n", actualCount); |
- SkASSERT(actualCount <= count); |
- if (canMapVB) { |
- vertexBuffer->unmap(); |
- } else { |
- vertexBuffer->updateData(verts, actualCount * sizeof(SkPoint)); |
- delete[] verts; |
- } |
- |
- |
+ polys = contours_to_polys(contours.get(), contourCnt, path.getBounds(), alloc); |
+ int count = polys_to_triangles(polys, fillType, isLinear, resourceProvider, vertexBuffer, |
+ canMapVB); |
if (!fPath.isVolatile()) { |
TessInfo info; |
info.fTolerance = isLinear ? 0 : tol; |
- info.fCount = actualCount; |
+ info.fCount = count; |
SkAutoTUnref<SkData> data(SkData::NewWithCopy(&info, sizeof(info))); |
key->setCustomData(data.get()); |
resourceProvider->assignUniqueKeyToResource(*key, vertexBuffer.get()); |
SkPathPriv::AddGenIDChangeListener(fPath, new PathInvalidator(*key)); |
} |
- return actualCount; |
+ return count; |
} |
void onPrepareDraws(Target* target) const override { |