Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: src/gpu/GrAAConvexTessellator.h

Issue 1120023003: Refugee from Dead Machine 13: New version of the convex AA tessellator Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrAAConvexTessellator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 GrAAConvexTessellator_DEFINED
9 #define GrAAConvexTessellator_DEFINED
10
11 #include "SkColor.h"
12 #include "SkPoint.h"
13 #include "SkScalar.h"
14 #include "SkTDArray.h"
15 #include "SkTDPQueue.h"
16
17 class SkCanvas;
18 class SkMatrix;
19 class SkPath;
20
21 #define GR_AA_CONVEX_TESSELLATOR_VIZ 1
22
23 class GrAAConvexTessellator;
24 class GrVertInfo;
25
26 class GrCandidateVert {
27 public:
28 void setPt(const SkPoint& pt) { fPt = pt; }
29 const SkPoint& pt() { return fPt; }
30
31 void setBisector(const SkVector& bisector) { fBisector = bisector; }
32 const SkVector& bisector() const { return fBisector; }
33
34 void setDepth(SkScalar depth) { fDepth = depth; }
35 SkScalar depth() const { return fDepth; }
36
37 void setOriginatingPt(int idx) { fOriginatingPt = idx; }
38 int originatingPt() const { return fOriginatingPt;}
39
40 void setPrevSubsumed(GrVertInfo* prevSubsumed) { fPrevSubsumed = prevSubsume d; }
41 GrVertInfo* prevSubsumed() { return fPrevSubsumed; }
42
43 void setNextSubsumed(GrVertInfo* nextSubsumed) { fNextSubsumed = nextSubsume d; }
44 GrVertInfo* nextSubsumed() { return fNextSubsumed; }
45
46 void setPrev(GrCandidateVert* prev) { fPrev = prev; }
47 GrCandidateVert* prev() { return fPrev; }
48
49 void setNext(GrCandidateVert* next) { fNext = next; }
50 GrCandidateVert* next() { return fNext; }
51
52 static bool Less(GrCandidateVert*const& a, GrCandidateVert*const& b) {
53 return a->fDepth < b->fDepth;
54 }
55 static int* AccessIndex(GrCandidateVert* const& a) {
56 return &a->fQueueIndex;
57 }
58
59 void computeIntersection();
60
61 void recomputeBi();
62
63 protected:
64
65 private:
66 SkPoint fPt;
67 SkVector fBisector;
68 SkScalar fDepth;
69 int fOriginatingPt;
70 int fEdgeId;
71
72 // segment subsumed
73 GrVertInfo* fPrevSubsumed;
74 GrVertInfo* fNextSubsumed;
75
76 // DLL
77 GrCandidateVert* fPrev;
78 GrCandidateVert* fNext;
79
80 int fQueueIndex;
81 };
82
83 class GrVertInfo {
84 public:
85 void setOriginatingPt(int index) { fIndex1 = index; }
86 int originatingPt() const { return fIndex1; }
87
88 void setBisector(const SkVector& bisector) { fBisector = bisector; }
89 const SkVector& bisector() const { return fBisector; }
90
91 void setEdgeId(int edgeId) { fEdgeId = edgeId; }
92 int edgeId() const { return fEdgeId; }
93
94 void setPrev(GrVertInfo* prev) { fPrev = prev; }
95 void setNext(GrVertInfo* next) { fNext = next; }
96
97
98 GrVertInfo* prev() { return fPrev; }
99 GrVertInfo* next() { return fNext; }
100
101 void updateGeometry(const GrAAConvexTessellator& tess);
102 // void computeIntersection(const GrAAConvexTessellator& tess);
103
104 private:
105 int fIndex1;
106 SkVector fBisector;
107 int fEdgeId;
108
109 GrVertInfo* fPrev;
110 GrVertInfo* fNext;
111
112 };
113
114 // The GrAAConvexTessellator holds:
115 // the global pool of vertices
116 // the triangle indices
117 class GrAAConvexTessellator {
118 public:
119 GrAAConvexTessellator(SkScalar targetDepth = 0.5f) : fTargetDepth(targetDept h), fFree(NULL) { }
120
121 void setTargetDepth(SkScalar targetDepth) { fTargetDepth = targetDepth; }
122 SkScalar targetDepth() const { return fTargetDepth; }
123
124 bool tessellate(const SkMatrix& m, const SkPath& path);
125
126 // The next seven should only be called after tessellate
127 int numPts() const { return fPts.count(); }
128 int numIndices() const { return fIndices.count(); }
129
130 const SkPoint& point(int index) const { return fPts[index]; }
131 int index(int index) const { return fIndices[index]; }
132 SkScalar depth(int index) const {return fDepths[index]; }
133
134 SkScalar computeDepthFromEdge(int edgeIdx, const SkPoint& p) const;
135
136 #if GR_AA_CONVEX_TESSELLATOR_VIZ
137 void draw(SkCanvas* canvas) const;
138 #endif
139
140 void rewind();
141
142 private:
143 int addPt(const SkPoint& pt, SkScalar depth);
144 void popLastPt();
145 void popFirstPtShuffle();
146
147 void addTri(int i0, int i1, int i2);
148
149 void reservePts(int count) {
150 fPts.setReserve(count);
151 fDepths.setReserve(count);
152 }
153
154
155 SkPoint computePtAlongBisector(int startIdx, const SkPoint& bisector,
156 int edgeIdx, SkScalar desiredDepth) const;
157
158 // return false on failure/degenerate path
159 bool extractFromPath(const SkMatrix& m, const SkPath& path);
160 void computeNormals();
161 void computeBisectors();
162 void initPQueue();
163 void createOuterRing();
164 void stepAllIn();
165 void removeDups(GrVertInfo* start, int* trailingIdx);
166 void removeDups2(GrVertInfo* start, int* trailingIdx);
167 void createInsetRing();
168
169 void createCandidate(GrVertInfo* v, GrCandidateVert** prev,
170 GrCandidateVert* next, bool checkNext);
171 void recompute(GrCandidateVert* v);
172
173 void validate() const;
174
175 #if GR_AA_CONVEX_TESSELLATOR_VIZ
176 void drawInitialPoly(SkCanvas* canvas) const;
177 #endif
178
179 #ifdef SK_DEBUG
180 SkScalar computeRealDepth(const SkPoint& p) const;
181 void checkAllDepths() const;
182 #endif
183
184 // fPts, fWeights & fMovable should always have the same # of elements
185 SkTDArray<SkPoint> fPts;
186 SkTDArray<SkScalar> fDepths;
187
188 // The triangle indices
189 SkTDArray<int> fIndices;
190
191 // The outward facing normals for the original polygon
192 SkTDArray<SkVector> fNorms;
193 // The inward facing bisector at each point in the original polygon
194 SkTDArray<SkVector> fBisectors;
195 SkPoint::Side fSide; // winding of the original polygon
196
197 typedef SkTDPQueue<GrCandidateVert*, GrCandidateVert::Less, GrCandidateVert: :AccessIndex> VertPQueue;
198
199 VertPQueue fPQueue; // pointers to GrVertInfos
200 SkTDArray<GrCandidateVert> fCandidates1;
201 GrCandidateVert* fFree;
202
203 GrCandidateVert* get() {
204 SkASSERT(fFree);
205 GrCandidateVert* tmp = fFree;
206 fFree = fFree->next();
207 return tmp;
208 }
209
210 void release(GrCandidateVert* v) {
211 v->setNext(fFree);
212 fFree = v;
213 }
214
215 SkTDArray<GrVertInfo> fVerts1; // the actual verts
216
217 SkScalar fTargetDepth;
218 };
219
220
221 #endif
222
OLDNEW
« no previous file with comments | « src/gpu/GrAAConvexPathRenderer.cpp ('k') | src/gpu/GrAAConvexTessellator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698