blob: e1516b43b6200f0c25702792f5a17515cfc07249 [file] [log] [blame]
ethannicholase9709e82016-01-07 13:34:16 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Chris Dalton17dc4182020-03-25 16:18:16 -06008#ifndef GrTriangulator_DEFINED
9#define GrTriangulator_DEFINED
ethannicholase9709e82016-01-07 13:34:16 -080010
Chris Dalton57ea1fc2021-01-05 13:37:44 -070011#include "include/core/SkPath.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkPoint.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/private/SkColorData.h"
Chris Dalton57ea1fc2021-01-05 13:37:44 -070014#include "src/core/SkArenaAlloc.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040015#include "src/gpu/GrColor.h"
senorblanco6599eff2016-03-10 08:38:45 -080016
Chris Daltond081dce2020-01-23 12:09:04 -070017class GrEagerVertexAllocator;
senorblanco6599eff2016-03-10 08:38:45 -080018struct SkRect;
ethannicholase9709e82016-01-07 13:34:16 -080019
Chris Dalton5045de32021-01-07 19:09:01 -070020#define TRIANGULATOR_LOGGING 0
Chris Dalton57ea1fc2021-01-05 13:37:44 -070021#define TRIANGULATOR_WIREFRAME 0
22
ethannicholase9709e82016-01-07 13:34:16 -080023/**
24 * Provides utility functions for converting paths to a collection of triangles.
25 */
Chris Dalton57ea1fc2021-01-05 13:37:44 -070026class GrTriangulator {
27public:
Chris Dalton854ee852021-01-05 15:12:59 -070028 static int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
29 GrEagerVertexAllocator* vertexAllocator, bool* isLinear) {
30 GrTriangulator triangulator(path);
Chris Dalton93c2d812021-01-11 19:51:59 -070031 int count = triangulator.pathToTriangles(tolerance, clipBounds, vertexAllocator);
Chris Dalton854ee852021-01-05 15:12:59 -070032 *isLinear = triangulator.fIsLinear;
33 return count;
Chris Dalton57ea1fc2021-01-05 13:37:44 -070034 }
ethannicholase9709e82016-01-07 13:34:16 -080035
Chris Dalton854ee852021-01-05 15:12:59 -070036 static int TriangulateSimpleInnerPolygons(const SkPath& path,
37 GrEagerVertexAllocator* vertexAllocator,
38 bool *isLinear) {
39 GrTriangulator triangulator(path);
40 triangulator.fCullCollinearVertices = false;
Chris Dalton57115c02021-01-12 18:12:18 -070041 triangulator.fDisallowSelfIntersection = true;
Chris Dalton93c2d812021-01-11 19:51:59 -070042 int count = triangulator.pathToTriangles(0, SkRect::MakeEmpty(), vertexAllocator);
Chris Dalton854ee852021-01-05 15:12:59 -070043 *isLinear = triangulator.fIsLinear;
44 return count;
45 }
ethannicholase9709e82016-01-07 13:34:16 -080046
Chris Dalton57ea1fc2021-01-05 13:37:44 -070047 struct WindingVertex {
48 SkPoint fPos;
49 int fWinding;
50 };
Chris Dalton6ccc0322020-01-29 11:38:16 -070051
Chris Dalton57ea1fc2021-01-05 13:37:44 -070052 // *DEPRECATED*: Once CCPR is removed this method will go away.
Chris Dalton6ccc0322020-01-29 11:38:16 -070053 //
Chris Dalton57ea1fc2021-01-05 13:37:44 -070054 // Triangulates a path to an array of vertices. Each triangle is represented as a set of three
55 // WindingVertex entries, each of which contains the position and winding count (which is the
56 // same for all three vertices of a triangle). The 'verts' out parameter is set to point to the
57 // resultant vertex array. CALLER IS RESPONSIBLE for deleting this buffer to avoid a memory
58 // leak!
59 static int PathToVertices(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
60 WindingVertex** verts);
61
Chris Dalton17ce8c52021-01-07 18:08:46 -070062 // Enums used by GrTriangulator internals.
63 typedef enum { kLeft_Side, kRight_Side } Side;
64 enum class EdgeType { kInner, kOuter, kConnector };
65
Chris Dalton57ea1fc2021-01-05 13:37:44 -070066 // Structs used by GrTriangulator internals.
67 struct Vertex;
68 struct VertexList;
Chris Dalton17ce8c52021-01-07 18:08:46 -070069 struct Line;
Chris Dalton57ea1fc2021-01-05 13:37:44 -070070 struct Edge;
71 struct EdgeList;
Chris Dalton17ce8c52021-01-07 18:08:46 -070072 struct MonotonePoly;
Chris Dalton57ea1fc2021-01-05 13:37:44 -070073 struct Poly;
74 struct Comparator;
75
Chris Dalton7cf3add2021-01-11 18:33:28 -070076protected:
Chris Dalton854ee852021-01-05 15:12:59 -070077 GrTriangulator(const SkPath& path) : fPath(path) {}
Chris Dalton7cf3add2021-01-11 18:33:28 -070078 virtual ~GrTriangulator() {}
Chris Dalton57ea1fc2021-01-05 13:37:44 -070079
80 // There are six stages to the basic algorithm:
81 //
82 // 1) Linearize the path contours into piecewise linear segments:
83 void pathToContours(float tolerance, const SkRect& clipBounds, VertexList* contours);
84
85 // 2) Build a mesh of edges connecting the vertices:
Chris Dalton811dc6a2021-01-07 16:40:32 -070086 void contoursToMesh(VertexList* contours, int contourCnt, VertexList* mesh, const Comparator&);
Chris Dalton57ea1fc2021-01-05 13:37:44 -070087
88 // 3) Sort the vertices in Y (and secondarily in X) (merge_sort()).
Chris Dalton47114db2021-01-06 00:35:20 -070089 static void SortedMerge(VertexList* front, VertexList* back, VertexList* result,
90 const Comparator&);
Chris Dalton57ea1fc2021-01-05 13:37:44 -070091 static void SortMesh(VertexList* vertices, const Comparator&);
92
93 // 4) Simplify the mesh by inserting new vertices at intersecting edges:
94 enum class SimplifyResult {
95 kAlreadySimple,
96 kFoundSelfIntersection,
97 kAbort
98 };
99
Chris Dalton811dc6a2021-01-07 16:40:32 -0700100 SimplifyResult simplify(VertexList* mesh, const Comparator&);
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700101
102 // 5) Tessellate the simplified mesh into monotone polygons:
Chris Dalton93c2d812021-01-11 19:51:59 -0700103 virtual Poly* tessellate(const VertexList& vertices, const Comparator&);
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700104
105 // 6) Triangulate the monotone polygons directly into a vertex buffer:
Chris Dalton93c2d812021-01-11 19:51:59 -0700106 virtual int64_t countPoints(Poly* polys) const {
107 return this->countPointsImpl(polys, fPath.getFillType());
108 }
109 virtual void* polysToTriangles(Poly* polys, void* data) {
110 return this->polysToTrianglesImpl(polys, data, fPath.getFillType());
111 }
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700112
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700113 // The vertex sorting in step (3) is a merge sort, since it plays well with the linked list
114 // of vertices (and the necessity of inserting new vertices on intersection).
115 //
116 // Stages (4) and (5) use an active edge list -- a list of all edges for which the
117 // sweep line has crossed the top vertex, but not the bottom vertex. It's sorted
118 // left-to-right based on the point where both edges are active (when both top vertices
119 // have been seen, so the "lower" top vertex of the two). If the top vertices are equal
120 // (shared), it's sorted based on the last point where both edges are active, so the
121 // "upper" bottom vertex.
122 //
123 // The most complex step is the simplification (4). It's based on the Bentley-Ottman
124 // line-sweep algorithm, but due to floating point inaccuracy, the intersection points are
125 // not exact and may violate the mesh topology or active edge list ordering. We
126 // accommodate this by adjusting the topology of the mesh and AEL to match the intersection
127 // points. This occurs in two ways:
128 //
129 // A) Intersections may cause a shortened edge to no longer be ordered with respect to its
130 // neighbouring edges at the top or bottom vertex. This is handled by merging the
131 // edges (merge_collinear_edges()).
132 // B) Intersections may cause an edge to violate the left-to-right ordering of the
133 // active edge list. This is handled by detecting potential violations and rewinding
134 // the active edge list to the vertex before they occur (rewind() during merging,
135 // rewind_if_necessary() during splitting).
136 //
137 // The tessellation steps (5) and (6) are based on "Triangulating Simple Polygons and
138 // Equivalent Problems" (Fournier and Montuno); also a line-sweep algorithm. Note that it
139 // currently uses a linked list for the active edge list, rather than a 2-3 tree as the
140 // paper describes. The 2-3 tree gives O(lg N) lookups, but insertion and removal also
141 // become O(lg N). In all the test cases, it was found that the cost of frequent O(lg N)
142 // insertions and removals was greater than the cost of infrequent O(N) lookups with the
143 // linked list implementation. With the latter, all removals are O(1), and most insertions
144 // are O(1), since we know the adjacent edge in the active edge list based on the topology.
145 // Only type 2 vertices (see paper) require the O(N) lookups, and these are much less
146 // frequent. There may be other data structures worth investigating, however.
147 //
148 // Note that the orientation of the line sweep algorithms is determined by the aspect ratio of
149 // the path bounds. When the path is taller than it is wide, we sort vertices based on
150 // increasing Y coordinate, and secondarily by increasing X coordinate. When the path is wider
151 // than it is tall, we sort by increasing X coordinate, but secondarily by *decreasing* Y
152 // coordinate. This is so that the "left" and "right" orientation in the code remains correct
153 // (edges to the left are increasing in Y; edges to the right are decreasing in Y). That is, the
154 // setting rotates 90 degrees counterclockwise, rather that transposing.
155
156 // Additional helpers and driver functions.
Chris Dalton9a4904f2021-01-07 19:10:14 -0700157 void* emitMonotonePoly(const MonotonePoly*, void* data);
158 void* emitTriangle(Vertex* prev, Vertex* curr, Vertex* next, int winding, void* data) const;
159 void* emitPoly(const Poly*, void *data);
Chris Dalton7cf3add2021-01-11 18:33:28 -0700160 Poly* makePoly(Poly** head, Vertex* v, int winding);
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700161 void appendPointToContour(const SkPoint& p, VertexList* contour);
162 void appendQuadraticToContour(const SkPoint[3], SkScalar toleranceSqd, VertexList* contour);
163 void generateCubicPoints(const SkPoint&, const SkPoint&, const SkPoint&, const SkPoint&,
164 SkScalar tolSqd, VertexList* contour, int pointsLeft);
Chris Dalton47114db2021-01-06 00:35:20 -0700165 bool applyFillType(int winding);
Chris Dalton7cf3add2021-01-11 18:33:28 -0700166 Edge* makeEdge(Vertex* prev, Vertex* next, EdgeType type, const Comparator&);
167 Edge* makeConnectingEdge(Vertex* prev, Vertex* next, EdgeType, const Comparator&,
168 int windingScale = 1);
Chris Dalton47114db2021-01-06 00:35:20 -0700169 static void FindEnclosingEdges(Vertex* v, EdgeList* edges, Edge** left, Edge** right);
Chris Dalton811dc6a2021-01-07 16:40:32 -0700170 bool splitEdge(Edge* edge, Vertex* v, EdgeList* activeEdges, Vertex** current,
171 const Comparator&);
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700172 bool intersectEdgePair(Edge* left, Edge* right, EdgeList* activeEdges, Vertex** current,
Chris Dalton811dc6a2021-01-07 16:40:32 -0700173 const Comparator&);
Chris Dalton7cf3add2021-01-11 18:33:28 -0700174 Vertex* makeSortedVertex(const SkPoint&, uint8_t alpha, VertexList* mesh, Vertex* reference,
175 const Comparator&);
176 void computeBisector(Edge* edge1, Edge* edge2, Vertex*);
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700177 bool checkForIntersection(Edge* left, Edge* right, EdgeList* activeEdges, Vertex** current,
Chris Dalton811dc6a2021-01-07 16:40:32 -0700178 VertexList* mesh, const Comparator&);
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700179 void sanitizeContours(VertexList* contours, int contourCnt);
Chris Dalton811dc6a2021-01-07 16:40:32 -0700180 bool mergeCoincidentVertices(VertexList* mesh, const Comparator&);
181 void buildEdges(VertexList* contours, int contourCnt, VertexList* mesh, const Comparator&);
Chris Dalton93c2d812021-01-11 19:51:59 -0700182 Poly* contoursToPolys(VertexList* contours, int contourCnt);
183 Poly* pathToPolys(float tolerance, const SkRect& clipBounds, int contourCnt);
184 int64_t countPointsImpl(Poly* polys, SkPathFillType overrideFillType) const;
185 void* polysToTrianglesImpl(Poly* polys, void* data, SkPathFillType overrideFillType);
186 int pathToTriangles(float tolerance, const SkRect& clipBounds, GrEagerVertexAllocator*);
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700187
188 constexpr static int kArenaChunkSize = 16 * 1024;
189 SkArenaAlloc fAlloc{kArenaChunkSize};
190 const SkPath fPath;
Chris Dalton57ea1fc2021-01-05 13:37:44 -0700191 bool fIsLinear = false;
Chris Dalton854ee852021-01-05 15:12:59 -0700192
193 // Flags.
194 bool fRoundVerticesToQuarterPixel = false;
195 bool fEmitCoverage = false;
196 bool fCullCollinearVertices = true;
Chris Dalton57115c02021-01-12 18:12:18 -0700197 bool fDisallowSelfIntersection = false;
Chris Daltondcc8c542020-01-28 17:55:56 -0700198};
199
Chris Dalton5045de32021-01-07 19:09:01 -0700200/**
201 * Vertices are used in three ways: first, the path contours are converted into a
202 * circularly-linked list of Vertices for each contour. After edge construction, the same Vertices
203 * are re-ordered by the merge sort according to the sweep_lt comparator (usually, increasing
204 * in Y) using the same fPrev/fNext pointers that were used for the contours, to avoid
205 * reallocation. Finally, MonotonePolys are built containing a circularly-linked list of
206 * Vertices. (Currently, those Vertices are newly-allocated for the MonotonePolys, since
207 * an individual Vertex from the path mesh may belong to multiple
208 * MonotonePolys, so the original Vertices cannot be re-used.
209 */
210
211struct GrTriangulator::Vertex {
212 Vertex(const SkPoint& point, uint8_t alpha)
213 : fPoint(point), fPrev(nullptr), fNext(nullptr)
214 , fFirstEdgeAbove(nullptr), fLastEdgeAbove(nullptr)
215 , fFirstEdgeBelow(nullptr), fLastEdgeBelow(nullptr)
216 , fLeftEnclosingEdge(nullptr), fRightEnclosingEdge(nullptr)
217 , fPartner(nullptr)
218 , fAlpha(alpha)
219 , fSynthetic(false)
220#if TRIANGULATOR_LOGGING
221 , fID (-1.0f)
222#endif
223 {}
224 SkPoint fPoint; // Vertex position
225 Vertex* fPrev; // Linked list of contours, then Y-sorted vertices.
226 Vertex* fNext; // "
227 Edge* fFirstEdgeAbove; // Linked list of edges above this vertex.
228 Edge* fLastEdgeAbove; // "
229 Edge* fFirstEdgeBelow; // Linked list of edges below this vertex.
230 Edge* fLastEdgeBelow; // "
231 Edge* fLeftEnclosingEdge; // Nearest edge in the AEL left of this vertex.
232 Edge* fRightEnclosingEdge; // Nearest edge in the AEL right of this vertex.
233 Vertex* fPartner; // Corresponding inner or outer vertex (for AA).
234 uint8_t fAlpha;
235 bool fSynthetic; // Is this a synthetic vertex?
236#if TRIANGULATOR_LOGGING
237 float fID; // Identifier used for logging.
238#endif
Chris Dalton24472af2021-01-11 20:05:00 -0700239 bool isConnected() const { return this->fFirstEdgeAbove || this->fFirstEdgeBelow; }
Chris Dalton5045de32021-01-07 19:09:01 -0700240};
241
242struct GrTriangulator::VertexList {
243 VertexList() : fHead(nullptr), fTail(nullptr) {}
244 VertexList(Vertex* head, Vertex* tail) : fHead(head), fTail(tail) {}
245 Vertex* fHead;
246 Vertex* fTail;
247 void insert(Vertex* v, Vertex* prev, Vertex* next);
248 void append(Vertex* v) { insert(v, fTail, nullptr); }
249 void append(const VertexList& list) {
250 if (!list.fHead) {
251 return;
252 }
253 if (fTail) {
254 fTail->fNext = list.fHead;
255 list.fHead->fPrev = fTail;
256 } else {
257 fHead = list.fHead;
258 }
259 fTail = list.fTail;
260 }
261 void prepend(Vertex* v) { insert(v, nullptr, fHead); }
262 void remove(Vertex* v);
263 void close() {
264 if (fHead && fTail) {
265 fTail->fNext = fHead;
266 fHead->fPrev = fTail;
267 }
268 }
Chris Dalton24472af2021-01-11 20:05:00 -0700269#if TRIANGULATOR_LOGGING
270 void dump();
271#endif
Chris Dalton5045de32021-01-07 19:09:01 -0700272};
273
274// A line equation in implicit form. fA * x + fB * y + fC = 0, for all points (x, y) on the line.
275struct GrTriangulator::Line {
276 Line(double a, double b, double c) : fA(a), fB(b), fC(c) {}
277 Line(Vertex* p, Vertex* q) : Line(p->fPoint, q->fPoint) {}
278 Line(const SkPoint& p, const SkPoint& q)
279 : fA(static_cast<double>(q.fY) - p.fY) // a = dY
280 , fB(static_cast<double>(p.fX) - q.fX) // b = -dX
281 , fC(static_cast<double>(p.fY) * q.fX - // c = cross(q, p)
282 static_cast<double>(p.fX) * q.fY) {}
283 double dist(const SkPoint& p) const { return fA * p.fX + fB * p.fY + fC; }
284 Line operator*(double v) const { return Line(fA * v, fB * v, fC * v); }
285 double magSq() const { return fA * fA + fB * fB; }
286 void normalize() {
287 double len = sqrt(this->magSq());
288 if (len == 0.0) {
289 return;
290 }
291 double scale = 1.0f / len;
292 fA *= scale;
293 fB *= scale;
294 fC *= scale;
295 }
296 bool nearParallel(const Line& o) const {
297 return fabs(o.fA - fA) < 0.00001 && fabs(o.fB - fB) < 0.00001;
298 }
299
300 // Compute the intersection of two (infinite) Lines.
301 bool intersect(const Line& other, SkPoint* point) const;
302 double fA, fB, fC;
303};
304
305/**
306 * An Edge joins a top Vertex to a bottom Vertex. Edge ordering for the list of "edges above" and
307 * "edge below" a vertex as well as for the active edge list is handled by isLeftOf()/isRightOf().
308 * Note that an Edge will give occasionally dist() != 0 for its own endpoints (because floating
309 * point). For speed, that case is only tested by the callers that require it (e.g.,
310 * rewind_if_necessary()). Edges also handle checking for intersection with other edges.
311 * Currently, this converts the edges to the parametric form, in order to avoid doing a division
312 * until an intersection has been confirmed. This is slightly slower in the "found" case, but
313 * a lot faster in the "not found" case.
314 *
315 * The coefficients of the line equation stored in double precision to avoid catastrophic
316 * cancellation in the isLeftOf() and isRightOf() checks. Using doubles ensures that the result is
317 * correct in float, since it's a polynomial of degree 2. The intersect() function, being
318 * degree 5, is still subject to catastrophic cancellation. We deal with that by assuming its
319 * output may be incorrect, and adjusting the mesh topology to match (see comment at the top of
320 * this file).
321 */
322
323struct GrTriangulator::Edge {
324 Edge(Vertex* top, Vertex* bottom, int winding, EdgeType type)
325 : fWinding(winding)
326 , fTop(top)
327 , fBottom(bottom)
328 , fType(type)
329 , fLeft(nullptr)
330 , fRight(nullptr)
331 , fPrevEdgeAbove(nullptr)
332 , fNextEdgeAbove(nullptr)
333 , fPrevEdgeBelow(nullptr)
334 , fNextEdgeBelow(nullptr)
335 , fLeftPoly(nullptr)
336 , fRightPoly(nullptr)
337 , fLeftPolyPrev(nullptr)
338 , fLeftPolyNext(nullptr)
339 , fRightPolyPrev(nullptr)
340 , fRightPolyNext(nullptr)
341 , fUsedInLeftPoly(false)
342 , fUsedInRightPoly(false)
343 , fLine(top, bottom) {
344 }
345 int fWinding; // 1 == edge goes downward; -1 = edge goes upward.
346 Vertex* fTop; // The top vertex in vertex-sort-order (sweep_lt).
347 Vertex* fBottom; // The bottom vertex in vertex-sort-order.
348 EdgeType fType;
349 Edge* fLeft; // The linked list of edges in the active edge list.
350 Edge* fRight; // "
351 Edge* fPrevEdgeAbove; // The linked list of edges in the bottom Vertex's "edges above".
352 Edge* fNextEdgeAbove; // "
353 Edge* fPrevEdgeBelow; // The linked list of edges in the top Vertex's "edges below".
354 Edge* fNextEdgeBelow; // "
355 Poly* fLeftPoly; // The Poly to the left of this edge, if any.
356 Poly* fRightPoly; // The Poly to the right of this edge, if any.
357 Edge* fLeftPolyPrev;
358 Edge* fLeftPolyNext;
359 Edge* fRightPolyPrev;
360 Edge* fRightPolyNext;
361 bool fUsedInLeftPoly;
362 bool fUsedInRightPoly;
363 Line fLine;
364 double dist(const SkPoint& p) const { return fLine.dist(p); }
365 bool isRightOf(Vertex* v) const { return fLine.dist(v->fPoint) < 0.0; }
366 bool isLeftOf(Vertex* v) const { return fLine.dist(v->fPoint) > 0.0; }
367 void recompute() { fLine = Line(fTop, fBottom); }
Chris Dalton24472af2021-01-11 20:05:00 -0700368 void insertAbove(Vertex*, const Comparator&);
369 void insertBelow(Vertex*, const Comparator&);
370 void disconnect();
Chris Dalton5045de32021-01-07 19:09:01 -0700371 bool intersect(const Edge& other, SkPoint* p, uint8_t* alpha = nullptr) const;
372};
373
374struct GrTriangulator::EdgeList {
375 EdgeList() : fHead(nullptr), fTail(nullptr) {}
376 Edge* fHead;
377 Edge* fTail;
378 void insert(Edge* edge, Edge* prev, Edge* next);
Chris Dalton24472af2021-01-11 20:05:00 -0700379 void insert(Edge* edge, Edge* prev);
Chris Dalton5045de32021-01-07 19:09:01 -0700380 void append(Edge* e) { insert(e, fTail, nullptr); }
381 void remove(Edge* edge);
382 void removeAll() {
383 while (fHead) {
384 this->remove(fHead);
385 }
386 }
387 void close() {
388 if (fHead && fTail) {
389 fTail->fRight = fHead;
390 fHead->fLeft = fTail;
391 }
392 }
393 bool contains(Edge* edge) const { return edge->fLeft || edge->fRight || fHead == edge; }
394};
395
396struct GrTriangulator::MonotonePoly {
397 MonotonePoly(Edge* edge, Side side, int winding)
398 : fSide(side)
399 , fFirstEdge(nullptr)
400 , fLastEdge(nullptr)
401 , fPrev(nullptr)
402 , fNext(nullptr)
403 , fWinding(winding) {
404 this->addEdge(edge);
405 }
406 Side fSide;
407 Edge* fFirstEdge;
408 Edge* fLastEdge;
409 MonotonePoly* fPrev;
410 MonotonePoly* fNext;
411 int fWinding;
412 void addEdge(Edge*);
413 void* emit(bool emitCoverage, void* data);
414 void* emitTriangle(Vertex* prev, Vertex* curr, Vertex* next, bool emitCoverage,
415 void* data) const;
416};
417
418struct GrTriangulator::Poly {
419 Poly(Vertex* v, int winding)
420 : fFirstVertex(v)
421 , fWinding(winding)
422 , fHead(nullptr)
423 , fTail(nullptr)
424 , fNext(nullptr)
425 , fPartner(nullptr)
426 , fCount(0)
427 {
428#if TRIANGULATOR_LOGGING
429 static int gID = 0;
430 fID = gID++;
431 TESS_LOG("*** created Poly %d\n", fID);
432#endif
433 }
434 Poly* addEdge(Edge* e, Side side, SkArenaAlloc& alloc);
435 void* emit(bool emitCoverage, void *data);
436 Vertex* lastVertex() const { return fTail ? fTail->fLastEdge->fBottom : fFirstVertex; }
437 Vertex* fFirstVertex;
438 int fWinding;
439 MonotonePoly* fHead;
440 MonotonePoly* fTail;
441 Poly* fNext;
442 Poly* fPartner;
443 int fCount;
444#if TRIANGULATOR_LOGGING
445 int fID;
446#endif
447};
448
449struct GrTriangulator::Comparator {
450 enum class Direction { kVertical, kHorizontal };
451 Comparator(Direction direction) : fDirection(direction) {}
452 bool sweep_lt(const SkPoint& a, const SkPoint& b) const;
453 Direction fDirection;
454};
455
ethannicholase9709e82016-01-07 13:34:16 -0800456#endif