Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f617b4d

Browse files
Rename GrStrokeGeometry -> GrStrokePatchBuilder
Bug: skia:10419 Change-Id: Iffd139c2d489deb9d57fa860c20158ee398b7c11 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305561 Commit-Queue: Chris Dalton <[email protected]> Reviewed-by: Michael Ludwig <[email protected]>
1 parent 9eea916 commit f617b4d

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

gn/gpu.gni

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,8 @@ skia_gpu_sources = [
458458
"$_src/gpu/tessellate/GrResolveLevelCounter.h",
459459
"$_src/gpu/tessellate/GrStencilPathShader.cpp",
460460
"$_src/gpu/tessellate/GrStencilPathShader.h",
461-
"$_src/gpu/tessellate/GrStrokeGeometry.cpp",
462-
"$_src/gpu/tessellate/GrStrokeGeometry.h",
461+
"$_src/gpu/tessellate/GrStrokePatchBuilder.cpp",
462+
"$_src/gpu/tessellate/GrStrokePatchBuilder.h",
463463
"$_src/gpu/tessellate/GrTessellatePathOp.cpp",
464464
"$_src/gpu/tessellate/GrTessellatePathOp.h",
465465
"$_src/gpu/tessellate/GrTessellateStrokeOp.cpp",

src/gpu/tessellate/GrStrokeGeometry.cpp renamed to src/gpu/tessellate/GrStrokePatchBuilder.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
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
//

src/gpu/tessellate/GrStrokeGeometry.h renamed to src/gpu/tessellate/GrStrokePatchBuilder.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* found in the LICENSE file.
66
*/
77

8-
#ifndef GrGrStrokeGeometry_DEFINED
9-
#define GrGrStrokeGeometry_DEFINED
8+
#ifndef GrGrStrokePatchBuilder_DEFINED
9+
#define GrGrStrokePatchBuilder_DEFINED
1010

1111
#include "include/core/SkPaint.h"
1212
#include "include/core/SkPoint.h"
@@ -21,14 +21,14 @@ class SkStrokeRec;
2121
// entire lifetime of this class. e.g.:
2222
//
2323
// void onPrepare(GrOpFlushState* target) {
24-
// GrStrokeGeometry g(target, &fMyVertexChunks, count); // Locks target.
24+
// GrStrokePatchBuilder builder(target, &fMyVertexChunks, count); // Locks target.
2525
// for (...) {
26-
// g.addPath(path, stroke);
26+
// builder.addPath(path, stroke);
2727
// }
2828
// }
2929
// ... target can now be used normally again.
3030
// ... fMyVertexChunks now contains chunks that can be drawn during onExecute.
31-
class GrStrokeGeometry {
31+
class GrStrokePatchBuilder {
3232
public:
3333
// We generate vertex buffers in chunks. Normally there will only be one chunk, but in rare
3434
// cases the first can run out of space if too many cubics needed to be subdivided.
@@ -41,8 +41,8 @@ class GrStrokeGeometry {
4141
// Stores raw pointers to the provided target and vertexChunkArray, which this class will use
4242
// and push to as addPath is called. The caller is responsible to bind and draw each chunk that
4343
// gets pushed to the array. (See GrTessellateStrokeShader.)
44-
GrStrokeGeometry(GrMeshDrawOp::Target* target, SkTArray<VertexChunk>* vertexChunkArray,
45-
int totalCombinedVerbCnt)
44+
GrStrokePatchBuilder(GrMeshDrawOp::Target* target, SkTArray<VertexChunk>* vertexChunkArray,
45+
int totalCombinedVerbCnt)
4646
: fMaxTessellationSegments(target->caps().shaderCaps()->maxTessellationSegments())
4747
, fTarget(target)
4848
, fVertexChunkArray(vertexChunkArray) {
@@ -52,7 +52,7 @@ class GrStrokeGeometry {
5252

5353
// "Releases" the target to be used externally again by putting back any unused pre-allocated
5454
// vertices.
55-
~GrStrokeGeometry() {
55+
~GrStrokePatchBuilder() {
5656
fTarget->putBackVertices(fCurrChunkVertexCapacity - fVertexChunkArray->back().fVertexCount,
5757
sizeof(SkPoint));
5858
}

src/gpu/tessellate/GrTessellateStrokeOp.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
#include "src/gpu/tessellate/GrTessellateStrokeOp.h"
99

1010
#include "src/core/SkPathPriv.h"
11-
#include "src/gpu/tessellate/GrStrokeGeometry.h"
11+
#include "src/gpu/tessellate/GrStrokePatchBuilder.h"
1212
#include "src/gpu/tessellate/GrTessellateStrokeShader.h"
1313

1414
static SkPath transform_path(const SkMatrix& viewMatrix, const SkPath& path) {
1515
SkPath devPath;
1616
// The provided matrix must be a similarity matrix for the time being. This is so we can
17-
// bootstrap this Op on top of GrStrokeGeometry with minimal modifications.
17+
// bootstrap this Op on top of GrStrokePatchBuilder with minimal modifications.
1818
SkASSERT(viewMatrix.isSimilarity());
1919
path.transform(viewMatrix, &devPath);
2020
return devPath;
@@ -109,9 +109,9 @@ void GrTessellateStrokeOp::onPrePrepare(GrRecordingContext*, const GrSurfaceProx
109109
}
110110

111111
void GrTessellateStrokeOp::onPrepare(GrOpFlushState* flushState) {
112-
GrStrokeGeometry strokeGeometry(flushState, &fVertexChunks, fTotalCombinedVerbCnt);
112+
GrStrokePatchBuilder builder(flushState, &fVertexChunks, fTotalCombinedVerbCnt);
113113
for (auto& [path, stroke] : fPathStrokes) {
114-
strokeGeometry.addPath(path, stroke);
114+
builder.addPath(path, stroke);
115115
}
116116
}
117117

src/gpu/tessellate/GrTessellateStrokeOp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "include/core/SkStrokeRec.h"
1212
#include "src/gpu/GrSTArenaList.h"
1313
#include "src/gpu/ops/GrDrawOp.h"
14-
#include "src/gpu/tessellate/GrStrokeGeometry.h"
14+
#include "src/gpu/tessellate/GrStrokePatchBuilder.h"
1515

1616
// Renders opaque, constant-color strokes by decomposing them into standalone tessellation patches.
1717
// Each patch is either a "cubic" (single stroked bezier curve with butt caps) or a "join". Requires
@@ -55,7 +55,7 @@ class GrTessellateStrokeOp : public GrDrawOp {
5555
GrProcessorSet fProcessors;
5656

5757
// S=1 because we will almost always fit everything into one single chunk.
58-
SkSTArray<1, GrStrokeGeometry::VertexChunk> fVertexChunks;
58+
SkSTArray<1, GrStrokePatchBuilder::VertexChunk> fVertexChunks;
5959

6060
friend class GrOpMemoryPool; // For ctor.
6161
};

0 commit comments

Comments
 (0)