| 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 |
| 11 #include "SkColor.h" | 11 #include "SkColor.h" |
| 12 #include "SkPaint.h" | 12 #include "SkPaint.h" |
| 13 #include "SkPoint.h" | 13 #include "SkPoint.h" |
| 14 #include "SkScalar.h" | 14 #include "SkScalar.h" |
| 15 #include "SkStrokeRec.h" | |
| 16 #include "SkTDArray.h" | 15 #include "SkTDArray.h" |
| 17 | 16 |
| 18 class SkCanvas; | 17 class SkCanvas; |
| 19 class SkMatrix; | 18 class SkMatrix; |
| 20 class SkPath; | 19 class SkPath; |
| 21 | 20 |
| 22 //#define GR_AA_CONVEX_TESSELLATOR_VIZ 1 | 21 //#define GR_AA_CONVEX_TESSELLATOR_VIZ 1 |
| 23 | 22 |
| 24 // device space distance which we inset / outset points in order to create the s
oft antialiased edge | 23 // device space distance which we inset / outset points in order to create the s
oft antialiased edge |
| 25 static const SkScalar kAntialiasingRadius = 0.5f; | 24 static const SkScalar kAntialiasingRadius = 0.5f; |
| 26 | 25 |
| 27 class GrAAConvexTessellator; | 26 class GrAAConvexTessellator; |
| 28 | 27 |
| 29 // The AAConvexTessellator holds the global pool of points and the triangulation | 28 // The AAConvexTessellator holds the global pool of points and the triangulation |
| 30 // that connects them. It also drives the tessellation process. | 29 // that connects them. It also drives the tessellation process. |
| 31 // 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 |
| 32 // computeDepthFromEdge requests. | 31 // computeDepthFromEdge requests. |
| 33 class GrAAConvexTessellator { | 32 class GrAAConvexTessellator { |
| 34 public: | 33 public: |
| 35 GrAAConvexTessellator(SkStrokeRec::Style style = SkStrokeRec::kFill_Style, | 34 GrAAConvexTessellator(SkScalar strokeWidth = -1.0f, |
| 36 SkScalar strokeWidth = -1.0f, | |
| 37 SkPaint::Join join = SkPaint::Join::kBevel_Join, | 35 SkPaint::Join join = SkPaint::Join::kBevel_Join, |
| 38 SkScalar miterLimit = 0.0f) | 36 SkScalar miterLimit = 0.0f) |
| 39 : fSide(SkPoint::kOn_Side) | 37 : fSide(SkPoint::kOn_Side) |
| 40 , fStrokeWidth(strokeWidth) | 38 , fStrokeWidth(strokeWidth) |
| 41 , fStyle(style) | |
| 42 , fJoin(join) | 39 , fJoin(join) |
| 43 , fMiterLimit(miterLimit) { | 40 , fMiterLimit(miterLimit) { |
| 44 } | 41 } |
| 45 | 42 |
| 46 SkPoint::Side side() const { return fSide; } | 43 SkPoint::Side side() const { return fSide; } |
| 47 | 44 |
| 48 bool tessellate(const SkMatrix& m, const SkPath& path); | 45 bool tessellate(const SkMatrix& m, const SkPath& path); |
| 49 | 46 |
| 50 // 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 |
| 51 int numPts() const { return fPts.count(); } | 48 int numPts() const { return fPts.count(); } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 void rewind() { fPts.rewind(); } | 129 void rewind() { fPts.rewind(); } |
| 133 | 130 |
| 134 int numPts() const { return fPts.count(); } | 131 int numPts() const { return fPts.count(); } |
| 135 | 132 |
| 136 void addIdx(int index, int origEdgeId) { | 133 void addIdx(int index, int origEdgeId) { |
| 137 struct PointData* pt = fPts.push(); | 134 struct PointData* pt = fPts.push(); |
| 138 pt->fIndex = index; | 135 pt->fIndex = index; |
| 139 pt->fOrigEdgeId = origEdgeId; | 136 pt->fOrigEdgeId = origEdgeId; |
| 140 } | 137 } |
| 141 | 138 |
| 142 // Upgrade this ring so that it can behave like an originating ring | |
| 143 void makeOriginalRing() { | |
| 144 for (int i = 0; i < fPts.count(); ++i) { | |
| 145 fPts[i].fOrigEdgeId = fPts[i].fIndex; | |
| 146 } | |
| 147 } | |
| 148 | |
| 149 // init should be called after all the indices have been added (via addI
dx) | 139 // init should be called after all the indices have been added (via addI
dx) |
| 150 void init(const GrAAConvexTessellator& tess); | 140 void init(const GrAAConvexTessellator& tess); |
| 151 void init(const SkTDArray<SkVector>& norms, const SkTDArray<SkVector>& b
isectors); | 141 void init(const SkTDArray<SkVector>& norms, const SkTDArray<SkVector>& b
isectors); |
| 152 | 142 |
| 153 const SkPoint& norm(int index) const { return fPts[index].fNorm; } | 143 const SkPoint& norm(int index) const { return fPts[index].fNorm; } |
| 154 const SkPoint& bisector(int index) const { return fPts[index].fBisector;
} | 144 const SkPoint& bisector(int index) const { return fPts[index].fBisector;
} |
| 155 int index(int index) const { return fPts[index].fIndex; } | 145 int index(int index) const { return fPts[index].fIndex; } |
| 156 int origEdgeID(int index) const { return fPts[index].fOrigEdgeId; } | 146 int origEdgeID(int index) const { return fPts[index].fOrigEdgeId; } |
| 157 void setOrigEdgeId(int index, int id) { fPts[index].fOrigEdgeId = id; } | 147 void setOrigEdgeId(int index, int id) { fPts[index].fOrigEdgeId = id; } |
| 158 | 148 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 260 |
| 271 Ring fInitialRing; | 261 Ring fInitialRing; |
| 272 #if GR_AA_CONVEX_TESSELLATOR_VIZ | 262 #if GR_AA_CONVEX_TESSELLATOR_VIZ |
| 273 // When visualizing save all the rings | 263 // When visualizing save all the rings |
| 274 SkTDArray<Ring*> fRings; | 264 SkTDArray<Ring*> fRings; |
| 275 #else | 265 #else |
| 276 Ring fRings[2]; | 266 Ring fRings[2]; |
| 277 #endif | 267 #endif |
| 278 CandidateVerts fCandidateVerts; | 268 CandidateVerts fCandidateVerts; |
| 279 | 269 |
| 280 // the stroke width is only used for stroke or stroke-and-fill styles | 270 // < 0 means filling rather than stroking |
| 281 SkScalar fStrokeWidth; | 271 SkScalar fStrokeWidth; |
| 282 SkStrokeRec::Style fStyle; | |
| 283 | 272 |
| 284 SkPaint::Join fJoin; | 273 SkPaint::Join fJoin; |
| 285 | 274 |
| 286 SkScalar fMiterLimit; | 275 SkScalar fMiterLimit; |
| 287 | 276 |
| 288 SkTDArray<SkPoint> fPointBuffer; | 277 SkTDArray<SkPoint> fPointBuffer; |
| 289 }; | 278 }; |
| 290 | 279 |
| 291 | 280 |
| 292 #endif | 281 #endif |
| OLD | NEW |