| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrAAConvexTessellator_DEFINED | 8 #ifndef GrAAConvexTessellator_DEFINED |
| 9 #define GrAAConvexTessellator_DEFINED | 9 #define GrAAConvexTessellator_DEFINED |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 static const SkScalar kAntialiasingRadius = 0.5f; | 24 static const SkScalar kAntialiasingRadius = 0.5f; |
| 25 | 25 |
| 26 class GrAAConvexTessellator; | 26 class GrAAConvexTessellator; |
| 27 | 27 |
| 28 // The AAConvexTessellator holds the global pool of points and the triangulation | 28 // The AAConvexTessellator holds the global pool of points and the triangulation |
| 29 // that connects them. It also drives the tessellation process. | 29 // that connects them. It also drives the tessellation process. |
| 30 // The outward facing normals of the original polygon are stored (in 'fNorms') t
o service | 30 // The outward facing normals of the original polygon are stored (in 'fNorms') t
o service |
| 31 // computeDepthFromEdge requests. | 31 // computeDepthFromEdge requests. |
| 32 class GrAAConvexTessellator { | 32 class GrAAConvexTessellator { |
| 33 public: | 33 public: |
| 34 GrAAConvexTessellator(SkScalar strokeWidth = -1.0f, | 34 GrAAConvexTessellator(SkScalar strokeWidth = -1.0f, |
| 35 SkPaint::Join join = SkPaint::Join::kBevel_Join, | 35 SkPaint::Join join = SkPaint::Join::kBevel_Join, |
| 36 SkScalar miterLimit = 0.0f) | 36 SkScalar miterLimit = 0.0f) |
| 37 : fSide(SkPoint::kOn_Side) | 37 : fSide(SkPoint::kOn_Side) |
| 38 , fStrokeWidth(strokeWidth) | 38 , fStrokeWidth(strokeWidth) |
| 39 , fJoin(join) | 39 , fJoin(join) |
| 40 , fMiterLimit(miterLimit) { | 40 , fMiterLimit(miterLimit) { |
| 41 } | 41 } |
| 42 | 42 |
| 43 SkPoint::Side side() const { return fSide; } | 43 SkPoint::Side side() const { return fSide; } |
| 44 | 44 |
| 45 bool tessellate(const SkMatrix& m, const SkPath& path); | 45 bool tessellate(const SkMatrix& m, const SkPath& path); |
| 46 | 46 |
| 47 // The next five should only be called after tessellate to extract the resul
t | 47 // The next five should only be called after tessellate to extract the resul
t |
| 48 int numPts() const { return fPts.count(); } | 48 int numPts() const { return fPts.count(); } |
| 49 int numIndices() const { return fIndices.count(); } | 49 int numIndices() const { return fIndices.count(); } |
| 50 | 50 |
| 51 const SkPoint& lastPoint() const { return fPts.top(); } | 51 const SkPoint& lastPoint() const { return fPts.top(); } |
| 52 const SkPoint& point(int index) const { return fPts[index]; } | 52 const SkPoint& point(int index) const { return fPts[index]; } |
| 53 int index(int index) const { return fIndices[index]; } | 53 int index(int index) const { return fIndices[index]; } |
| 54 SkScalar coverage(int index) const { return fCoverages[index]; } | 54 SkScalar coverage(int index) const { return fCoverages[index]; } |
| 55 | 55 |
| 56 #if GR_AA_CONVEX_TESSELLATOR_VIZ | 56 #if GR_AA_CONVEX_TESSELLATOR_VIZ |
| 57 void draw(SkCanvas* canvas) const; | 57 void draw(SkCanvas* canvas) const; |
| 58 #endif | 58 #endif |
| 59 | 59 |
| 60 // The tessellator can be reused for multiple paths by rewinding in between | 60 // The tessellator can be reused for multiple paths by rewinding in between |
| 61 void rewind(); | 61 void rewind(); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 // CandidateVerts holds the vertices for the next ring while they are | 64 // CandidateVerts holds the vertices for the next ring while they are |
| 65 // being generated. Its main function is to de-dup the points. | 65 // being generated. Its main function is to de-dup the points. |
| 66 class CandidateVerts { | 66 class CandidateVerts { |
| 67 public: | 67 public: |
| 68 void setReserve(int numPts) { fPts.setReserve(numPts); } | 68 void setReserve(int numPts) { fPts.setReserve(numPts); } |
| 69 void rewind() { fPts.rewind(); } | 69 void rewind() { fPts.rewind(); } |
| 70 | 70 |
| 71 int numPts() const { return fPts.count(); } | 71 int numPts() const { return fPts.count(); } |
| 72 | 72 |
| 73 const SkPoint& lastPoint() const { return fPts.top().fPt; } | 73 const SkPoint& lastPoint() const { return fPts.top().fPt; } |
| 74 const SkPoint& firstPoint() const { return fPts[0].fPt; } | 74 const SkPoint& firstPoint() const { return fPts[0].fPt; } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 void terminate(const Ring& lastRing); | 206 void terminate(const Ring& lastRing); |
| 207 | 207 |
| 208 // return false on failure/degenerate path | 208 // return false on failure/degenerate path |
| 209 bool extractFromPath(const SkMatrix& m, const SkPath& path); | 209 bool extractFromPath(const SkMatrix& m, const SkPath& path); |
| 210 void computeBisectors(); | 210 void computeBisectors(); |
| 211 | 211 |
| 212 void fanRing(const Ring& ring); | 212 void fanRing(const Ring& ring); |
| 213 | 213 |
| 214 Ring* getNextRing(Ring* lastRing); | 214 Ring* getNextRing(Ring* lastRing); |
| 215 | 215 |
| 216 void createOuterRing(const Ring& previousRing, SkScalar outset, SkScalar cov
erage, | 216 void createOuterRing(const Ring& previousRing, SkScalar outset, SkScalar cov
erage, |
| 217 Ring* nextRing); | 217 Ring* nextRing); |
| 218 | 218 |
| 219 bool createInsetRings(Ring& previousRing, SkScalar initialDepth, SkScalar in
itialCoverage, | 219 bool createInsetRings(Ring& previousRing, SkScalar initialDepth, SkScalar in
itialCoverage, |
| 220 SkScalar targetDepth, SkScalar targetCoverage, Ring**
finalRing); | 220 SkScalar targetDepth, SkScalar targetCoverage, Ring**
finalRing); |
| 221 | 221 |
| 222 bool createInsetRing(const Ring& lastRing, Ring* nextRing, | 222 bool createInsetRing(const Ring& lastRing, Ring* nextRing, |
| 223 SkScalar initialDepth, SkScalar initialCoverage, SkScal
ar targetDepth, | 223 SkScalar initialDepth, SkScalar initialCoverage, SkScal
ar targetDepth, |
| 224 SkScalar targetCoverage, bool forceNew); | 224 SkScalar targetCoverage, bool forceNew); |
| 225 | 225 |
| 226 void validate() const; | 226 void validate() const; |
| 227 | 227 |
| 228 // fPts, fCoverages & fMovable should always have the same # of elements | 228 // fPts, fCoverages & fMovable should always have the same # of elements |
| 229 SkTDArray<SkPoint> fPts; | 229 SkTDArray<SkPoint> fPts; |
| 230 SkTDArray<SkScalar> fCoverages; | 230 SkTDArray<SkScalar> fCoverages; |
| 231 // movable points are those that can be slid further along their bisector | 231 // movable points are those that can be slid further along their bisector |
| 232 SkTDArray<bool> fMovable; | 232 SkTDArray<bool> fMovable; |
| 233 | 233 |
| 234 // The outward facing normals for the original polygon | 234 // The outward facing normals for the original polygon |
| 235 SkTDArray<SkVector> fNorms; | 235 SkTDArray<SkVector> fNorms; |
| 236 // The inward facing bisector at each point in the original polygon. Only | 236 // The inward facing bisector at each point in the original polygon. Only |
| 237 // needed for exterior ring creation and then handed off to the initial ring
. | 237 // needed for exterior ring creation and then handed off to the initial ring
. |
| 238 SkTDArray<SkVector> fBisectors; | 238 SkTDArray<SkVector> fBisectors; |
| 239 | 239 |
| 240 // Tracks whether a given point is interior to a curve. Such points are | 240 // Tracks whether a given point is interior to a curve. Such points are |
| 241 // assumed to have shallow curvature. | 241 // assumed to have shallow curvature. |
| 242 SkTDArray<bool> fIsCurve; | 242 SkTDArray<bool> fIsCurve; |
| 243 | 243 |
| 244 SkPoint::Side fSide; // winding of the original polygon | 244 SkPoint::Side fSide; // winding of the original polygon |
| 245 | 245 |
| 246 // The triangulation of the points | 246 // The triangulation of the points |
| 247 SkTDArray<int> fIndices; | 247 SkTDArray<int> fIndices; |
| 248 | 248 |
| 249 Ring fInitialRing; | 249 Ring fInitialRing; |
| 250 #if GR_AA_CONVEX_TESSELLATOR_VIZ | 250 #if GR_AA_CONVEX_TESSELLATOR_VIZ |
| 251 // When visualizing save all the rings | 251 // When visualizing save all the rings |
| 252 SkTDArray<Ring*> fRings; | 252 SkTDArray<Ring*> fRings; |
| 253 #else | 253 #else |
| 254 Ring fRings[2]; | 254 Ring fRings[2]; |
| 255 #endif | 255 #endif |
| 256 CandidateVerts fCandidateVerts; | 256 CandidateVerts fCandidateVerts; |
| 257 | 257 |
| 258 // < 0 means filling rather than stroking | 258 // < 0 means filling rather than stroking |
| 259 SkScalar fStrokeWidth; | 259 SkScalar fStrokeWidth; |
| 260 | 260 |
| 261 SkPaint::Join fJoin; | 261 SkPaint::Join fJoin; |
| 262 | 262 |
| 263 SkScalar fMiterLimit; | 263 SkScalar fMiterLimit; |
| 264 | 264 |
| 265 SkTDArray<SkPoint> fPointBuffer; | 265 SkTDArray<SkPoint> fPointBuffer; |
| 266 }; | 266 }; |
| 267 | 267 |
| 268 | 268 |
| 269 #endif | 269 #endif |
| 270 | |
| OLD | NEW |