Rename GrStrokeGeometry -> GrStrokePatchBuilder

Bug: skia:10419
Change-Id: Iffd139c2d489deb9d57fa860c20158ee398b7c11
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305561
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
Chris Dalton 2020-07-23 16:20:47 -06:00
parent 9eea916c05
commit f617b4d9c2
5 changed files with 41 additions and 38 deletions

View File

@ -458,8 +458,8 @@ skia_gpu_sources = [
"$_src/gpu/tessellate/GrResolveLevelCounter.h",
"$_src/gpu/tessellate/GrStencilPathShader.cpp",
"$_src/gpu/tessellate/GrStencilPathShader.h",
"$_src/gpu/tessellate/GrStrokeGeometry.cpp",
"$_src/gpu/tessellate/GrStrokeGeometry.h",
"$_src/gpu/tessellate/GrStrokePatchBuilder.cpp",
"$_src/gpu/tessellate/GrStrokePatchBuilder.h",
"$_src/gpu/tessellate/GrTessellatePathOp.cpp",
"$_src/gpu/tessellate/GrTessellatePathOp.h",
"$_src/gpu/tessellate/GrTessellateStrokeOp.cpp",

View File

@ -5,13 +5,14 @@
* found in the LICENSE file.
*/
#include "src/gpu/tessellate/GrStrokeGeometry.h"
#include "src/gpu/tessellate/GrStrokePatchBuilder.h"
#include "include/core/SkStrokeRec.h"
#include "include/private/SkNx.h"
#include "src/core/SkGeometry.h"
#include "src/core/SkMathPriv.h"
#include "src/core/SkPathPriv.h"
#include "src/gpu/tessellate/GrTessellateStrokeShader.h"
// This is the maximum distance in pixels that we can stray from the edge of a stroke when
// converting it to flat line segments.
@ -44,7 +45,7 @@ static inline float calc_curvature_costheta(const Sk2f& leftTan, const Sk2f& rig
return (dotprod[0] + dotprod[1]) * invlength[0] * invlength[1];
}
void GrStrokeGeometry::allocVertexChunk(int minVertexAllocCount) {
void GrStrokePatchBuilder::allocVertexChunk(int minVertexAllocCount) {
VertexChunk* chunk = &fVertexChunkArray->push_back();
fCurrChunkVertexData = (SkPoint*)fTarget->makeVertexSpaceAtLeast(
sizeof(SkPoint), minVertexAllocCount, minVertexAllocCount, &chunk->fVertexBuffer,
@ -52,7 +53,7 @@ void GrStrokeGeometry::allocVertexChunk(int minVertexAllocCount) {
fCurrChunkMinVertexAllocCount = minVertexAllocCount;
}
SkPoint* GrStrokeGeometry::reservePatch() {
SkPoint* GrStrokePatchBuilder::reservePatch() {
constexpr static int kNumVerticesPerPatch = GrTessellateStrokeShader::kNumVerticesPerPatch;
if (fVertexChunkArray->back().fVertexCount + kNumVerticesPerPatch > fCurrChunkVertexCapacity) {
// No need to put back vertices; the buffer is full.
@ -69,8 +70,8 @@ SkPoint* GrStrokeGeometry::reservePatch() {
return patch;
}
void GrStrokeGeometry::writeCubicSegment(float leftJoinType, const SkPoint pts[4],
float overrideNumSegments) {
void GrStrokePatchBuilder::writeCubicSegment(float leftJoinType, const SkPoint pts[4],
float overrideNumSegments) {
SkPoint c1 = (pts[1] == pts[0]) ? pts[2] : pts[1];
SkPoint c2 = (pts[2] == pts[3]) ? pts[1] : pts[2];
@ -90,8 +91,9 @@ void GrStrokeGeometry::writeCubicSegment(float leftJoinType, const SkPoint pts[4
fCurrentPoint = pts[3];
}
void GrStrokeGeometry::writeJoin(float joinType, const SkPoint& anchorPoint,
const SkPoint& prevControlPoint, const SkPoint& nextControlPoint) {
void GrStrokePatchBuilder::writeJoin(float joinType, const SkPoint& anchorPoint,
const SkPoint& prevControlPoint,
const SkPoint& nextControlPoint) {
if (SkPoint* joinPatch = this->reservePatch()) {
joinPatch[0] = anchorPoint;
joinPatch[1] = prevControlPoint;
@ -101,7 +103,7 @@ void GrStrokeGeometry::writeJoin(float joinType, const SkPoint& anchorPoint,
}
}
void GrStrokeGeometry::writeSquareCap(const SkPoint& endPoint, const SkPoint& controlPoint) {
void GrStrokePatchBuilder::writeSquareCap(const SkPoint& endPoint, const SkPoint& controlPoint) {
SkVector v = (endPoint - controlPoint);
v.normalize();
SkPoint capPoint = endPoint + v*fCurrStrokeRadius;
@ -119,7 +121,7 @@ void GrStrokeGeometry::writeSquareCap(const SkPoint& endPoint, const SkPoint& co
}
}
void GrStrokeGeometry::writeCaps() {
void GrStrokePatchBuilder::writeCaps() {
if (!fHasPreviousSegment) {
// We don't have any control points to orient the caps. In this case, square and round caps
// are specified to be drawn as an axis-aligned square or circle respectively. Assign
@ -145,7 +147,7 @@ void GrStrokeGeometry::writeCaps() {
}
}
void GrStrokeGeometry::addPath(const SkPath& path, const SkStrokeRec& stroke) {
void GrStrokePatchBuilder::addPath(const SkPath& path, const SkStrokeRec& stroke) {
this->beginPath(stroke, stroke.getWidth());
SkPathVerb previousVerb = SkPathVerb::kClose;
for (auto [verb, pts, w] : SkPathPriv::Iterate(path)) {
@ -196,7 +198,7 @@ static float join_type_from_join(SkPaint::Join join) {
SkUNREACHABLE;
}
void GrStrokeGeometry::beginPath(const SkStrokeRec& stroke, float strokeDevWidth) {
void GrStrokePatchBuilder::beginPath(const SkStrokeRec& stroke, float strokeDevWidth) {
// Client should have already converted the stroke to device space (i.e. width=1 for hairline).
SkASSERT(strokeDevWidth > 0);
@ -212,16 +214,16 @@ void GrStrokeGeometry::beginPath(const SkStrokeRec& stroke, float strokeDevWidth
fHasPreviousSegment = false;
}
void GrStrokeGeometry::moveTo(const SkPoint& pt) {
void GrStrokePatchBuilder::moveTo(const SkPoint& pt) {
fHasPreviousSegment = false;
fCurrContourStartPoint = pt;
}
void GrStrokeGeometry::lineTo(const SkPoint& p0, const SkPoint& p1) {
void GrStrokePatchBuilder::lineTo(const SkPoint& p0, const SkPoint& p1) {
this->lineTo(fCurrStrokeJoinType, p0, p1);
}
void GrStrokeGeometry::lineTo(float leftJoinType, const SkPoint& pt0, const SkPoint& pt1) {
void GrStrokePatchBuilder::lineTo(float leftJoinType, const SkPoint& pt0, const SkPoint& pt1) {
Sk2f p0 = Sk2f::Load(&pt0);
Sk2f p1 = Sk2f::Load(&pt1);
if ((p0 == p1).allTrue()) {
@ -230,7 +232,7 @@ void GrStrokeGeometry::lineTo(float leftJoinType, const SkPoint& pt0, const SkPo
this->writeCubicSegment(leftJoinType, p0, lerp(p0, p1, 1/3.f), lerp(p0, p1, 2/3.f), p1, 1);
}
void GrStrokeGeometry::quadraticTo(const SkPoint P[3]) {
void GrStrokePatchBuilder::quadraticTo(const SkPoint P[3]) {
this->quadraticTo(fCurrStrokeJoinType, P, SkFindQuadMaxCurvature(P));
}
@ -243,7 +245,8 @@ static inline float wangs_formula_quadratic(const Sk2f& p0, const Sk2f& p1, cons
return SkScalarCeilToInt(f);
}
void GrStrokeGeometry::quadraticTo(float leftJoinType, const SkPoint P[3], float maxCurvatureT) {
void GrStrokePatchBuilder::quadraticTo(float leftJoinType, const SkPoint P[3],
float maxCurvatureT) {
Sk2f p0 = Sk2f::Load(P);
Sk2f p1 = Sk2f::Load(P+1);
Sk2f p2 = Sk2f::Load(P+2);
@ -330,7 +333,7 @@ void GrStrokeGeometry::quadraticTo(float leftJoinType, const SkPoint P[3], float
this->writeCubicSegment(leftJoinType, p0, lerp(p0, p1, 2/3.f), lerp(p1, p2, 1/3.f), p2);
}
void GrStrokeGeometry::cubicTo(const SkPoint P[4]) {
void GrStrokePatchBuilder::cubicTo(const SkPoint P[4]) {
float roots[3];
int numRoots = SkFindCubicMaxCurvature(P, roots);
this->cubicTo(fCurrStrokeJoinType, P,
@ -350,8 +353,8 @@ static inline float wangs_formula_cubic(const Sk2f& p0, const Sk2f& p1, const Sk
return SkScalarCeilToInt(f);
}
void GrStrokeGeometry::cubicTo(float leftJoinType, const SkPoint P[4], float maxCurvatureT,
float leftMaxCurvatureT, float rightMaxCurvatureT) {
void GrStrokePatchBuilder::cubicTo(float leftJoinType, const SkPoint P[4], float maxCurvatureT,
float leftMaxCurvatureT, float rightMaxCurvatureT) {
Sk2f p0 = Sk2f::Load(P);
Sk2f p1 = Sk2f::Load(P+1);
Sk2f p2 = Sk2f::Load(P+2);
@ -479,8 +482,8 @@ void GrStrokeGeometry::cubicTo(float leftJoinType, const SkPoint P[4], float max
this->writeCubicSegment(leftJoinType, p0, p1, p2, p3);
}
void GrStrokeGeometry::rotateTo(float leftJoinType, const SkPoint& anchorPoint,
const SkPoint& controlPoint) {
void GrStrokePatchBuilder::rotateTo(float leftJoinType, const SkPoint& anchorPoint,
const SkPoint& controlPoint) {
// Effectively rotate the current normal by drawing a zero length, 1-segment cubic.
// writeCubicSegment automatically adds the necessary join and the zero length cubic serves as
// 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,
this->writeCubicSegment(leftJoinType, pts, 1);
}
void GrStrokeGeometry::close() {
void GrStrokePatchBuilder::close() {
if (!fHasPreviousSegment) {
// Draw caps instead of closing if the subpath is zero length:
//

View File

@ -5,8 +5,8 @@
* found in the LICENSE file.
*/
#ifndef GrGrStrokeGeometry_DEFINED
#define GrGrStrokeGeometry_DEFINED
#ifndef GrGrStrokePatchBuilder_DEFINED
#define GrGrStrokePatchBuilder_DEFINED
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
@ -21,14 +21,14 @@ class SkStrokeRec;
// entire lifetime of this class. e.g.:
//
// void onPrepare(GrOpFlushState* target) {
// GrStrokeGeometry g(target, &fMyVertexChunks, count); // Locks target.
// GrStrokePatchBuilder builder(target, &fMyVertexChunks, count); // Locks target.
// for (...) {
// g.addPath(path, stroke);
// builder.addPath(path, stroke);
// }
// }
// ... target can now be used normally again.
// ... fMyVertexChunks now contains chunks that can be drawn during onExecute.
class GrStrokeGeometry {
class GrStrokePatchBuilder {
public:
// We generate vertex buffers in chunks. Normally there will only be one chunk, but in rare
// cases the first can run out of space if too many cubics needed to be subdivided.
@ -41,8 +41,8 @@ public:
// Stores raw pointers to the provided target and vertexChunkArray, which this class will use
// and push to as addPath is called. The caller is responsible to bind and draw each chunk that
// gets pushed to the array. (See GrTessellateStrokeShader.)
GrStrokeGeometry(GrMeshDrawOp::Target* target, SkTArray<VertexChunk>* vertexChunkArray,
int totalCombinedVerbCnt)
GrStrokePatchBuilder(GrMeshDrawOp::Target* target, SkTArray<VertexChunk>* vertexChunkArray,
int totalCombinedVerbCnt)
: fMaxTessellationSegments(target->caps().shaderCaps()->maxTessellationSegments())
, fTarget(target)
, fVertexChunkArray(vertexChunkArray) {
@ -52,7 +52,7 @@ public:
// "Releases" the target to be used externally again by putting back any unused pre-allocated
// vertices.
~GrStrokeGeometry() {
~GrStrokePatchBuilder() {
fTarget->putBackVertices(fCurrChunkVertexCapacity - fVertexChunkArray->back().fVertexCount,
sizeof(SkPoint));
}

View File

@ -8,13 +8,13 @@
#include "src/gpu/tessellate/GrTessellateStrokeOp.h"
#include "src/core/SkPathPriv.h"
#include "src/gpu/tessellate/GrStrokeGeometry.h"
#include "src/gpu/tessellate/GrStrokePatchBuilder.h"
#include "src/gpu/tessellate/GrTessellateStrokeShader.h"
static SkPath transform_path(const SkMatrix& viewMatrix, const SkPath& path) {
SkPath devPath;
// The provided matrix must be a similarity matrix for the time being. This is so we can
// bootstrap this Op on top of GrStrokeGeometry with minimal modifications.
// bootstrap this Op on top of GrStrokePatchBuilder with minimal modifications.
SkASSERT(viewMatrix.isSimilarity());
path.transform(viewMatrix, &devPath);
return devPath;
@ -109,9 +109,9 @@ void GrTessellateStrokeOp::onPrePrepare(GrRecordingContext*, const GrSurfaceProx
}
void GrTessellateStrokeOp::onPrepare(GrOpFlushState* flushState) {
GrStrokeGeometry strokeGeometry(flushState, &fVertexChunks, fTotalCombinedVerbCnt);
GrStrokePatchBuilder builder(flushState, &fVertexChunks, fTotalCombinedVerbCnt);
for (auto& [path, stroke] : fPathStrokes) {
strokeGeometry.addPath(path, stroke);
builder.addPath(path, stroke);
}
}

View File

@ -11,7 +11,7 @@
#include "include/core/SkStrokeRec.h"
#include "src/gpu/GrSTArenaList.h"
#include "src/gpu/ops/GrDrawOp.h"
#include "src/gpu/tessellate/GrStrokeGeometry.h"
#include "src/gpu/tessellate/GrStrokePatchBuilder.h"
// Renders opaque, constant-color strokes by decomposing them into standalone tessellation patches.
// Each patch is either a "cubic" (single stroked bezier curve with butt caps) or a "join". Requires
@ -55,7 +55,7 @@ private:
GrProcessorSet fProcessors;
// S=1 because we will almost always fit everything into one single chunk.
SkSTArray<1, GrStrokeGeometry::VertexChunk> fVertexChunks;
SkSTArray<1, GrStrokePatchBuilder::VertexChunk> fVertexChunks;
friend class GrOpMemoryPool; // For ctor.
};