55 * found in the LICENSE file.
66 */
77
8- #include " src/gpu/tessellate/GrStrokeGeometry .h"
8+ #include " src/gpu/tessellate/GrStrokePatchBuilder .h"
99
1010#include " include/core/SkStrokeRec.h"
1111#include " include/private/SkNx.h"
1212#include " src/core/SkGeometry.h"
1313#include " src/core/SkMathPriv.h"
1414#include " src/core/SkPathPriv.h"
15+ #include " src/gpu/tessellate/GrTessellateStrokeShader.h"
1516
1617// This is the maximum distance in pixels that we can stray from the edge of a stroke when
1718// converting it to flat line segments.
@@ -44,15 +45,15 @@ static inline float calc_curvature_costheta(const Sk2f& leftTan, const Sk2f& rig
4445 return (dotprod[0 ] + dotprod[1 ]) * invlength[0 ] * invlength[1 ];
4546}
4647
47- void GrStrokeGeometry ::allocVertexChunk (int minVertexAllocCount) {
48+ void GrStrokePatchBuilder ::allocVertexChunk (int minVertexAllocCount) {
4849 VertexChunk* chunk = &fVertexChunkArray ->push_back ();
4950 fCurrChunkVertexData = (SkPoint*)fTarget ->makeVertexSpaceAtLeast (
5051 sizeof (SkPoint), minVertexAllocCount, minVertexAllocCount, &chunk->fVertexBuffer ,
5152 &chunk->fBaseVertex , &fCurrChunkVertexCapacity );
5253 fCurrChunkMinVertexAllocCount = minVertexAllocCount;
5354}
5455
55- SkPoint* GrStrokeGeometry ::reservePatch () {
56+ SkPoint* GrStrokePatchBuilder ::reservePatch () {
5657 constexpr static int kNumVerticesPerPatch = GrTessellateStrokeShader::kNumVerticesPerPatch ;
5758 if (fVertexChunkArray ->back ().fVertexCount + kNumVerticesPerPatch > fCurrChunkVertexCapacity ) {
5859 // No need to put back vertices; the buffer is full.
@@ -69,8 +70,8 @@ SkPoint* GrStrokeGeometry::reservePatch() {
6970 return patch;
7071}
7172
72- void GrStrokeGeometry ::writeCubicSegment (float leftJoinType, const SkPoint pts[4 ],
73- float overrideNumSegments) {
73+ void GrStrokePatchBuilder ::writeCubicSegment (float leftJoinType, const SkPoint pts[4 ],
74+ float overrideNumSegments) {
7475 SkPoint c1 = (pts[1 ] == pts[0 ]) ? pts[2 ] : pts[1 ];
7576 SkPoint c2 = (pts[2 ] == pts[3 ]) ? pts[1 ] : pts[2 ];
7677
@@ -90,8 +91,9 @@ void GrStrokeGeometry::writeCubicSegment(float leftJoinType, const SkPoint pts[4
9091 fCurrentPoint = pts[3 ];
9192}
9293
93- void GrStrokeGeometry::writeJoin (float joinType, const SkPoint& anchorPoint,
94- const SkPoint& prevControlPoint, const SkPoint& nextControlPoint) {
94+ void GrStrokePatchBuilder::writeJoin (float joinType, const SkPoint& anchorPoint,
95+ const SkPoint& prevControlPoint,
96+ const SkPoint& nextControlPoint) {
9597 if (SkPoint* joinPatch = this ->reservePatch ()) {
9698 joinPatch[0 ] = anchorPoint;
9799 joinPatch[1 ] = prevControlPoint;
@@ -101,7 +103,7 @@ void GrStrokeGeometry::writeJoin(float joinType, const SkPoint& anchorPoint,
101103 }
102104}
103105
104- void GrStrokeGeometry ::writeSquareCap (const SkPoint& endPoint, const SkPoint& controlPoint) {
106+ void GrStrokePatchBuilder ::writeSquareCap (const SkPoint& endPoint, const SkPoint& controlPoint) {
105107 SkVector v = (endPoint - controlPoint);
106108 v.normalize ();
107109 SkPoint capPoint = endPoint + v*fCurrStrokeRadius ;
@@ -119,7 +121,7 @@ void GrStrokeGeometry::writeSquareCap(const SkPoint& endPoint, const SkPoint& co
119121 }
120122}
121123
122- void GrStrokeGeometry ::writeCaps () {
124+ void GrStrokePatchBuilder ::writeCaps () {
123125 if (!fHasPreviousSegment ) {
124126 // We don't have any control points to orient the caps. In this case, square and round caps
125127 // are specified to be drawn as an axis-aligned square or circle respectively. Assign
@@ -145,7 +147,7 @@ void GrStrokeGeometry::writeCaps() {
145147 }
146148}
147149
148- void GrStrokeGeometry ::addPath (const SkPath& path, const SkStrokeRec& stroke) {
150+ void GrStrokePatchBuilder ::addPath (const SkPath& path, const SkStrokeRec& stroke) {
149151 this ->beginPath (stroke, stroke.getWidth ());
150152 SkPathVerb previousVerb = SkPathVerb::kClose ;
151153 for (auto [verb, pts, w] : SkPathPriv::Iterate (path)) {
@@ -196,7 +198,7 @@ static float join_type_from_join(SkPaint::Join join) {
196198 SkUNREACHABLE;
197199}
198200
199- void GrStrokeGeometry ::beginPath (const SkStrokeRec& stroke, float strokeDevWidth) {
201+ void GrStrokePatchBuilder ::beginPath (const SkStrokeRec& stroke, float strokeDevWidth) {
200202 // Client should have already converted the stroke to device space (i.e. width=1 for hairline).
201203 SkASSERT (strokeDevWidth > 0 );
202204
@@ -212,16 +214,16 @@ void GrStrokeGeometry::beginPath(const SkStrokeRec& stroke, float strokeDevWidth
212214 fHasPreviousSegment = false ;
213215}
214216
215- void GrStrokeGeometry ::moveTo (const SkPoint& pt) {
217+ void GrStrokePatchBuilder ::moveTo (const SkPoint& pt) {
216218 fHasPreviousSegment = false ;
217219 fCurrContourStartPoint = pt;
218220}
219221
220- void GrStrokeGeometry ::lineTo (const SkPoint& p0, const SkPoint& p1) {
222+ void GrStrokePatchBuilder ::lineTo (const SkPoint& p0, const SkPoint& p1) {
221223 this ->lineTo (fCurrStrokeJoinType , p0, p1);
222224}
223225
224- void GrStrokeGeometry ::lineTo (float leftJoinType, const SkPoint& pt0, const SkPoint& pt1) {
226+ void GrStrokePatchBuilder ::lineTo (float leftJoinType, const SkPoint& pt0, const SkPoint& pt1) {
225227 Sk2f p0 = Sk2f::Load (&pt0);
226228 Sk2f p1 = Sk2f::Load (&pt1);
227229 if ((p0 == p1).allTrue ()) {
@@ -230,7 +232,7 @@ void GrStrokeGeometry::lineTo(float leftJoinType, const SkPoint& pt0, const SkPo
230232 this ->writeCubicSegment (leftJoinType, p0, lerp (p0, p1, 1 /3 .f ), lerp (p0, p1, 2 /3 .f ), p1, 1 );
231233}
232234
233- void GrStrokeGeometry ::quadraticTo (const SkPoint P[3 ]) {
235+ void GrStrokePatchBuilder ::quadraticTo (const SkPoint P[3 ]) {
234236 this ->quadraticTo (fCurrStrokeJoinType , P, SkFindQuadMaxCurvature (P));
235237}
236238
@@ -243,7 +245,8 @@ static inline float wangs_formula_quadratic(const Sk2f& p0, const Sk2f& p1, cons
243245 return SkScalarCeilToInt (f);
244246}
245247
246- void GrStrokeGeometry::quadraticTo (float leftJoinType, const SkPoint P[3 ], float maxCurvatureT) {
248+ void GrStrokePatchBuilder::quadraticTo (float leftJoinType, const SkPoint P[3 ],
249+ float maxCurvatureT) {
247250 Sk2f p0 = Sk2f::Load (P);
248251 Sk2f p1 = Sk2f::Load (P+1 );
249252 Sk2f p2 = Sk2f::Load (P+2 );
@@ -330,7 +333,7 @@ void GrStrokeGeometry::quadraticTo(float leftJoinType, const SkPoint P[3], float
330333 this ->writeCubicSegment (leftJoinType, p0, lerp (p0, p1, 2 /3 .f ), lerp (p1, p2, 1 /3 .f ), p2);
331334}
332335
333- void GrStrokeGeometry ::cubicTo (const SkPoint P[4 ]) {
336+ void GrStrokePatchBuilder ::cubicTo (const SkPoint P[4 ]) {
334337 float roots[3 ];
335338 int numRoots = SkFindCubicMaxCurvature (P, roots);
336339 this ->cubicTo (fCurrStrokeJoinType , P,
@@ -350,8 +353,8 @@ static inline float wangs_formula_cubic(const Sk2f& p0, const Sk2f& p1, const Sk
350353 return SkScalarCeilToInt (f);
351354}
352355
353- void GrStrokeGeometry ::cubicTo (float leftJoinType, const SkPoint P[4 ], float maxCurvatureT,
354- float leftMaxCurvatureT, float rightMaxCurvatureT) {
356+ void GrStrokePatchBuilder ::cubicTo (float leftJoinType, const SkPoint P[4 ], float maxCurvatureT,
357+ float leftMaxCurvatureT, float rightMaxCurvatureT) {
355358 Sk2f p0 = Sk2f::Load (P);
356359 Sk2f p1 = Sk2f::Load (P+1 );
357360 Sk2f p2 = Sk2f::Load (P+2 );
@@ -479,8 +482,8 @@ void GrStrokeGeometry::cubicTo(float leftJoinType, const SkPoint P[4], float max
479482 this ->writeCubicSegment (leftJoinType, p0, p1, p2, p3);
480483}
481484
482- void GrStrokeGeometry ::rotateTo (float leftJoinType, const SkPoint& anchorPoint,
483- const SkPoint& controlPoint) {
485+ void GrStrokePatchBuilder ::rotateTo (float leftJoinType, const SkPoint& anchorPoint,
486+ const SkPoint& controlPoint) {
484487 // Effectively rotate the current normal by drawing a zero length, 1-segment cubic.
485488 // writeCubicSegment automatically adds the necessary join and the zero length cubic serves as
486489 // a glue that guarantees a water tight rasterized edge between the new join and the segment
@@ -489,7 +492,7 @@ void GrStrokeGeometry::rotateTo(float leftJoinType, const SkPoint& anchorPoint,
489492 this ->writeCubicSegment (leftJoinType, pts, 1 );
490493}
491494
492- void GrStrokeGeometry ::close () {
495+ void GrStrokePatchBuilder ::close () {
493496 if (!fHasPreviousSegment ) {
494497 // Draw caps instead of closing if the subpath is zero length:
495498 //
0 commit comments