Index: src/gpu/GrTessellator.h |
diff --git a/src/gpu/GrTessellator.h b/src/gpu/GrTessellator.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..05bb5faaa930e1d505f847a1733a8b759a8c801d |
--- /dev/null |
+++ b/src/gpu/GrTessellator.h |
@@ -0,0 +1,116 @@ |
+/* |
+ * Copyright 2015 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#ifndef GrTessellator_DEFINED |
+#define GrTessellator_DEFINED |
+ |
+#include "SkChunkAlloc.h" |
+#include "GrPathRenderer.h" |
+ |
+/** |
+ * Provides utility functions for converting paths to a collection of triangles. |
+ */ |
+ |
+#define TESSELLATOR_LOGGING_ENABLED 0 |
+#define TESSELLATOR_WIREFRAME 0 |
+ |
bsalomon
2016/01/04 21:45:21
Maybe we should put all these structs and function
Stephen White
2016/01/04 22:51:19
Maybe GrTessellator, to match the .h?
Agreed that
|
+struct Poly; |
+struct Edge; |
+ |
+/** |
+ * 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 TessellatorVertex from |
+ * the path mesh may belong to multiple MonotonePolys, so the original vertices cannot be re-used. |
+ */ |
+struct TessellatorVertex { |
bsalomon
2016/01/04 21:45:21
Does this get used by any client of tessellator? I
Stephen White
2016/01/04 22:51:19
+1. IWBN to keep this in the .cpp if not necessary
|
+ TessellatorVertex(const SkPoint& point) |
+ : fPoint(point), fPrev(nullptr), fNext(nullptr) |
+ , fFirstEdgeAbove(nullptr), fLastEdgeAbove(nullptr) |
+ , fFirstEdgeBelow(nullptr), fLastEdgeBelow(nullptr) |
+ , fProcessed(false) |
+#if TESSELLATOR_LOGGING_ENABLED |
+ , fID (-1.0f) |
+#endif |
+ {} |
+ SkPoint fPoint; // Vertex position |
+ TessellatorVertex* fPrev; // Linked list of contours, then Y-sorted vertices. |
Stephen White
2016/01/04 22:51:19
Nit: spacing of these is weird now.
|
+ TessellatorVertex* 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 TESSELLATOR_LOGGING_ENABLED |
+ float fID; // Identifier used for logging. |
+#endif |
+}; |
+ |
+struct EdgeList { |
+ EdgeList() : fHead(nullptr), fTail(nullptr) {} |
+ Edge* fHead; |
+ Edge* fTail; |
+}; |
+ |
+struct Edge { |
+ Edge(TessellatorVertex* top, TessellatorVertex* bottom, int winding) |
+ : fTop(top) |
+ , fBottom(bottom) |
+ , fWinding(winding) |
+ , fLeft(nullptr) |
+ , fRight(nullptr) |
+ , fPrevEdgeAbove(nullptr) |
+ , fNextEdgeAbove(nullptr) |
+ , fPrevEdgeBelow(nullptr) |
+ , fNextEdgeBelow(nullptr) |
+ , fLeftPoly(nullptr) |
+ , fRightPoly(nullptr) { |
+ recompute(); |
+ } |
+ TessellatorVertex* fTop; // The top vertex in vertex-sort-order (sweep_lt). |
Stephen White
2016/01/04 22:51:19
Nit: spacing of these is weird now.
|
+ TessellatorVertex* fBottom; // The bottom vertex in vertex-sort-order. |
+ int fWinding; // 1 == edge goes downward; -1 = edge goes upward. |
+ 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; |
+ bool isRightOf(TessellatorVertex* v) const; |
+ bool isLeftOf(TessellatorVertex* v) const; |
+ void recompute(); |
+ bool intersect(const Edge& other, SkPoint* p); |
+ bool isActive(EdgeList* activeEdges) const; |
+}; |
+ |
+struct WindingVertex { |
+ SkPoint fPos; |
+ int fWinding; |
+}; |
+ |
+Poly* path_to_polys(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds, |
bsalomon
2016/01/04 21:45:21
Does this need to be exposed? It looks like Poly i
Stephen White
2016/01/04 22:51:19
Maybe they should be in the GrTessellator namespac
|
+ bool* isLinear); |
+ |
+// 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, |
bsalomon
2016/01/04 21:45:21
Is this (and polys_to_triangles) destructive to po
|
+ WindingVertex** verts); |
+ |
+int polys_to_triangles(Poly* polys, SkPath::FillType fillType, bool isLinear, |
+ GrResourceProvider* resourceProvider, SkAutoTUnref<GrVertexBuffer>& vertexBuffer, |
+ bool canMapVB); |
+ |
+#endif |