Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 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 | |
| 8 #ifndef GrTessellator_DEFINED | |
| 9 #define GrTessellator_DEFINED | |
| 10 | |
| 11 #include "SkChunkAlloc.h" | |
| 12 #include "GrPathRenderer.h" | |
| 13 | |
| 14 /** | |
| 15 * Provides utility functions for converting paths to a collection of triangles. | |
| 16 */ | |
| 17 | |
| 18 #define TESSELLATOR_LOGGING_ENABLED 0 | |
| 19 #define TESSELLATOR_WIREFRAME 0 | |
| 20 | |
|
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
| |
| 21 struct Poly; | |
| 22 struct Edge; | |
| 23 | |
| 24 /** | |
| 25 * Vertices are used in three ways: first, the path contours are converted into a circularly-linked | |
| 26 * list of vertices for each contour. After edge construction, the same vertices are re-ordered by | |
| 27 * the merge sort according to the sweep_lt comparator (usually, increasing in Y ) using the same | |
| 28 * fPrev/fNext pointers that were used for the contours, to avoid reallocation. Finally, | |
| 29 * MonotonePolys are built containing a circularly-linked list of vertices. Curr ently, those | |
| 30 * Vertices are newly-allocated for the MonotonePolys, since an individual Tesse llatorVertex from | |
| 31 * the path mesh may belong to multiple MonotonePolys, so the original vertices cannot be re-used. | |
| 32 */ | |
| 33 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
| |
| 34 TessellatorVertex(const SkPoint& point) | |
| 35 : fPoint(point), fPrev(nullptr), fNext(nullptr) | |
| 36 , fFirstEdgeAbove(nullptr), fLastEdgeAbove(nullptr) | |
| 37 , fFirstEdgeBelow(nullptr), fLastEdgeBelow(nullptr) | |
| 38 , fProcessed(false) | |
| 39 #if TESSELLATOR_LOGGING_ENABLED | |
| 40 , fID (-1.0f) | |
| 41 #endif | |
| 42 {} | |
| 43 SkPoint fPoint; // Vertex position | |
| 44 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.
| |
| 45 TessellatorVertex* fNext; // " | |
| 46 Edge* fFirstEdgeAbove; // Linked list of edges above this vertex. | |
| 47 Edge* fLastEdgeAbove; // " | |
| 48 Edge* fFirstEdgeBelow; // Linked list of edges below this vertex. | |
| 49 Edge* fLastEdgeBelow; // " | |
| 50 bool fProcessed; // Has this vertex been seen in simplify()? | |
| 51 #if TESSELLATOR_LOGGING_ENABLED | |
| 52 float fID; // Identifier used for logging. | |
| 53 #endif | |
| 54 }; | |
| 55 | |
| 56 struct EdgeList { | |
| 57 EdgeList() : fHead(nullptr), fTail(nullptr) {} | |
| 58 Edge* fHead; | |
| 59 Edge* fTail; | |
| 60 }; | |
| 61 | |
| 62 struct Edge { | |
| 63 Edge(TessellatorVertex* top, TessellatorVertex* bottom, int winding) | |
| 64 : fTop(top) | |
| 65 , fBottom(bottom) | |
| 66 , fWinding(winding) | |
| 67 , fLeft(nullptr) | |
| 68 , fRight(nullptr) | |
| 69 , fPrevEdgeAbove(nullptr) | |
| 70 , fNextEdgeAbove(nullptr) | |
| 71 , fPrevEdgeBelow(nullptr) | |
| 72 , fNextEdgeBelow(nullptr) | |
| 73 , fLeftPoly(nullptr) | |
| 74 , fRightPoly(nullptr) { | |
| 75 recompute(); | |
| 76 } | |
| 77 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.
| |
| 78 TessellatorVertex* fBottom; // The bottom vertex in vertex-sort-order. | |
| 79 int fWinding; // 1 == edge goes downward; -1 = edge goes upwar d. | |
| 80 Edge* fLeft; // The linked list of edges in the active edge l ist. | |
| 81 Edge* fRight; // " | |
| 82 Edge* fPrevEdgeAbove; // The linked list of edges in the bottom Vertex 's "edges above". | |
| 83 Edge* fNextEdgeAbove; // " | |
| 84 Edge* fPrevEdgeBelow; // The linked list of edges in the top Vertex's "edges below". | |
| 85 Edge* fNextEdgeBelow; // " | |
| 86 Poly* fLeftPoly; // The Poly to the left of this edge, if any. | |
| 87 Poly* fRightPoly; // The Poly to the right of this edge, if any. | |
| 88 double fDX; // The line equation for this edge, in implicit form. | |
| 89 double fDY; // fDY * x + fDX * y + fC = 0, for point (x, y) on the line. | |
| 90 double fC; | |
| 91 double dist(const SkPoint& p) const; | |
| 92 bool isRightOf(TessellatorVertex* v) const; | |
| 93 bool isLeftOf(TessellatorVertex* v) const; | |
| 94 void recompute(); | |
| 95 bool intersect(const Edge& other, SkPoint* p); | |
| 96 bool isActive(EdgeList* activeEdges) const; | |
| 97 }; | |
| 98 | |
| 99 struct WindingVertex { | |
| 100 SkPoint fPos; | |
| 101 int fWinding; | |
| 102 }; | |
| 103 | |
| 104 Poly* path_to_polys(const SkPath& path, SkScalar tolerance, const SkRect& clipBo unds, | |
|
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
| |
| 105 bool* isLinear); | |
| 106 | |
| 107 // creates an array of (point, winding) vertices and sets the 'verts' out parame ter to point to it. | |
| 108 // CALLER IS RESPONSIBLE for deleting this buffer to avoid a memory leak! | |
| 109 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
| |
| 110 WindingVertex** verts); | |
| 111 | |
| 112 int polys_to_triangles(Poly* polys, SkPath::FillType fillType, bool isLinear, | |
| 113 GrResourceProvider* resourceProvider, SkAutoTUnref<GrVertexBuffer>& vert exBuffer, | |
| 114 bool canMapVB); | |
| 115 | |
| 116 #endif | |
| OLD | NEW |