5
5
* found in the LICENSE file.
6
6
*/
7
7
8
- #include " src/gpu/tessellate/GrStrokeGeometry .h"
8
+ #include " src/gpu/tessellate/GrStrokePatchBuilder .h"
9
9
10
10
#include " include/core/SkStrokeRec.h"
11
11
#include " include/private/SkNx.h"
12
12
#include " src/core/SkGeometry.h"
13
13
#include " src/core/SkMathPriv.h"
14
14
#include " src/core/SkPathPriv.h"
15
+ #include " src/gpu/tessellate/GrTessellateStrokeShader.h"
15
16
16
17
// This is the maximum distance in pixels that we can stray from the edge of a stroke when
17
18
// converting it to flat line segments.
@@ -44,15 +45,15 @@ static inline float calc_curvature_costheta(const Sk2f& leftTan, const Sk2f& rig
44
45
return (dotprod[0 ] + dotprod[1 ]) * invlength[0 ] * invlength[1 ];
45
46
}
46
47
47
- void GrStrokeGeometry ::allocVertexChunk (int minVertexAllocCount) {
48
+ void GrStrokePatchBuilder ::allocVertexChunk (int minVertexAllocCount) {
48
49
VertexChunk* chunk = &fVertexChunkArray ->push_back ();
49
50
fCurrChunkVertexData = (SkPoint*)fTarget ->makeVertexSpaceAtLeast (
50
51
sizeof (SkPoint), minVertexAllocCount, minVertexAllocCount, &chunk->fVertexBuffer ,
51
52
&chunk->fBaseVertex , &fCurrChunkVertexCapacity );
52
53
fCurrChunkMinVertexAllocCount = minVertexAllocCount;
53
54
}
54
55
55
- SkPoint* GrStrokeGeometry ::reservePatch () {
56
+ SkPoint* GrStrokePatchBuilder ::reservePatch () {
56
57
constexpr static int kNumVerticesPerPatch = GrTessellateStrokeShader::kNumVerticesPerPatch ;
57
58
if (fVertexChunkArray ->back ().fVertexCount + kNumVerticesPerPatch > fCurrChunkVertexCapacity ) {
58
59
// No need to put back vertices; the buffer is full.
@@ -69,8 +70,8 @@ SkPoint* GrStrokeGeometry::reservePatch() {
69
70
return patch;
70
71
}
71
72
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) {
74
75
SkPoint c1 = (pts[1 ] == pts[0 ]) ? pts[2 ] : pts[1 ];
75
76
SkPoint c2 = (pts[2 ] == pts[3 ]) ? pts[1 ] : pts[2 ];
76
77
@@ -90,8 +91,9 @@ void GrStrokeGeometry::writeCubicSegment(float leftJoinType, const SkPoint pts[4
90
91
fCurrentPoint = pts[3 ];
91
92
}
92
93
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) {
95
97
if (SkPoint* joinPatch = this ->reservePatch ()) {
96
98
joinPatch[0 ] = anchorPoint;
97
99
joinPatch[1 ] = prevControlPoint;
@@ -101,7 +103,7 @@ void GrStrokeGeometry::writeJoin(float joinType, const SkPoint& anchorPoint,
101
103
}
102
104
}
103
105
104
- void GrStrokeGeometry ::writeSquareCap (const SkPoint& endPoint, const SkPoint& controlPoint) {
106
+ void GrStrokePatchBuilder ::writeSquareCap (const SkPoint& endPoint, const SkPoint& controlPoint) {
105
107
SkVector v = (endPoint - controlPoint);
106
108
v.normalize ();
107
109
SkPoint capPoint = endPoint + v*fCurrStrokeRadius ;
@@ -119,7 +121,7 @@ void GrStrokeGeometry::writeSquareCap(const SkPoint& endPoint, const SkPoint& co
119
121
}
120
122
}
121
123
122
- void GrStrokeGeometry ::writeCaps () {
124
+ void GrStrokePatchBuilder ::writeCaps () {
123
125
if (!fHasPreviousSegment ) {
124
126
// We don't have any control points to orient the caps. In this case, square and round caps
125
127
// are specified to be drawn as an axis-aligned square or circle respectively. Assign
@@ -145,7 +147,7 @@ void GrStrokeGeometry::writeCaps() {
145
147
}
146
148
}
147
149
148
- void GrStrokeGeometry ::addPath (const SkPath& path, const SkStrokeRec& stroke) {
150
+ void GrStrokePatchBuilder ::addPath (const SkPath& path, const SkStrokeRec& stroke) {
149
151
this ->beginPath (stroke, stroke.getWidth ());
150
152
SkPathVerb previousVerb = SkPathVerb::kClose ;
151
153
for (auto [verb, pts, w] : SkPathPriv::Iterate (path)) {
@@ -196,7 +198,7 @@ static float join_type_from_join(SkPaint::Join join) {
196
198
SkUNREACHABLE;
197
199
}
198
200
199
- void GrStrokeGeometry ::beginPath (const SkStrokeRec& stroke, float strokeDevWidth) {
201
+ void GrStrokePatchBuilder ::beginPath (const SkStrokeRec& stroke, float strokeDevWidth) {
200
202
// Client should have already converted the stroke to device space (i.e. width=1 for hairline).
201
203
SkASSERT (strokeDevWidth > 0 );
202
204
@@ -212,16 +214,16 @@ void GrStrokeGeometry::beginPath(const SkStrokeRec& stroke, float strokeDevWidth
212
214
fHasPreviousSegment = false ;
213
215
}
214
216
215
- void GrStrokeGeometry ::moveTo (const SkPoint& pt) {
217
+ void GrStrokePatchBuilder ::moveTo (const SkPoint& pt) {
216
218
fHasPreviousSegment = false ;
217
219
fCurrContourStartPoint = pt;
218
220
}
219
221
220
- void GrStrokeGeometry ::lineTo (const SkPoint& p0, const SkPoint& p1) {
222
+ void GrStrokePatchBuilder ::lineTo (const SkPoint& p0, const SkPoint& p1) {
221
223
this ->lineTo (fCurrStrokeJoinType , p0, p1);
222
224
}
223
225
224
- void GrStrokeGeometry ::lineTo (float leftJoinType, const SkPoint& pt0, const SkPoint& pt1) {
226
+ void GrStrokePatchBuilder ::lineTo (float leftJoinType, const SkPoint& pt0, const SkPoint& pt1) {
225
227
Sk2f p0 = Sk2f::Load (&pt0);
226
228
Sk2f p1 = Sk2f::Load (&pt1);
227
229
if ((p0 == p1).allTrue ()) {
@@ -230,7 +232,7 @@ void GrStrokeGeometry::lineTo(float leftJoinType, const SkPoint& pt0, const SkPo
230
232
this ->writeCubicSegment (leftJoinType, p0, lerp (p0, p1, 1 /3 .f ), lerp (p0, p1, 2 /3 .f ), p1, 1 );
231
233
}
232
234
233
- void GrStrokeGeometry ::quadraticTo (const SkPoint P[3 ]) {
235
+ void GrStrokePatchBuilder ::quadraticTo (const SkPoint P[3 ]) {
234
236
this ->quadraticTo (fCurrStrokeJoinType , P, SkFindQuadMaxCurvature (P));
235
237
}
236
238
@@ -243,7 +245,8 @@ static inline float wangs_formula_quadratic(const Sk2f& p0, const Sk2f& p1, cons
243
245
return SkScalarCeilToInt (f);
244
246
}
245
247
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) {
247
250
Sk2f p0 = Sk2f::Load (P);
248
251
Sk2f p1 = Sk2f::Load (P+1 );
249
252
Sk2f p2 = Sk2f::Load (P+2 );
@@ -330,7 +333,7 @@ void GrStrokeGeometry::quadraticTo(float leftJoinType, const SkPoint P[3], float
330
333
this ->writeCubicSegment (leftJoinType, p0, lerp (p0, p1, 2 /3 .f ), lerp (p1, p2, 1 /3 .f ), p2);
331
334
}
332
335
333
- void GrStrokeGeometry ::cubicTo (const SkPoint P[4 ]) {
336
+ void GrStrokePatchBuilder ::cubicTo (const SkPoint P[4 ]) {
334
337
float roots[3 ];
335
338
int numRoots = SkFindCubicMaxCurvature (P, roots);
336
339
this ->cubicTo (fCurrStrokeJoinType , P,
@@ -350,8 +353,8 @@ static inline float wangs_formula_cubic(const Sk2f& p0, const Sk2f& p1, const Sk
350
353
return SkScalarCeilToInt (f);
351
354
}
352
355
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) {
355
358
Sk2f p0 = Sk2f::Load (P);
356
359
Sk2f p1 = Sk2f::Load (P+1 );
357
360
Sk2f p2 = Sk2f::Load (P+2 );
@@ -479,8 +482,8 @@ void GrStrokeGeometry::cubicTo(float leftJoinType, const SkPoint P[4], float max
479
482
this ->writeCubicSegment (leftJoinType, p0, p1, p2, p3);
480
483
}
481
484
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) {
484
487
// Effectively rotate the current normal by drawing a zero length, 1-segment cubic.
485
488
// writeCubicSegment automatically adds the necessary join and the zero length cubic serves as
486
489
// 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,
489
492
this ->writeCubicSegment (leftJoinType, pts, 1 );
490
493
}
491
494
492
- void GrStrokeGeometry ::close () {
495
+ void GrStrokePatchBuilder ::close () {
493
496
if (!fHasPreviousSegment ) {
494
497
// Draw caps instead of closing if the subpath is zero length:
495
498
//
0 commit comments