From 5045e501d2aec23e5f1e4b46346033ac3202c6b0 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Tue, 19 Jun 2018 01:40:57 +0000 Subject: Revert "Change how vertex/instance attributes are handled in geometry processors." This reverts commit 19c1233c447f625c2522e7ecd0a0adecc629bb2f. Reason for revert: want to make sure Google3 can roll Original change's description: > Change how vertex/instance attributes are handled in geometry processors. > > * No longer register vertex/instance attributes on base class, just counts > > * Separate instance and vertex attributes and remove InputRate and offset > > * Make attributes constexpr where possible > > Change-Id: I1f1d5e772fa177a96d2aeb805aab7b69f35bfae6 > Reviewed-on: https://skia-review.googlesource.com/132405 > Commit-Queue: Brian Salomon > Reviewed-by: Chris Dalton TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com Change-Id: I4800632515e14fbf54af52826928ac915657b59f No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/135661 Reviewed-by: Mike Klein Commit-Queue: Mike Klein --- src/gpu/ops/GrAAConvexPathRenderer.cpp | 42 ++-- src/gpu/ops/GrAAFillRectOp.cpp | 19 +- src/gpu/ops/GrAAHairLinePathRenderer.cpp | 15 +- src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp | 10 +- src/gpu/ops/GrAAStrokeRectOp.cpp | 8 +- src/gpu/ops/GrAtlasTextOp.cpp | 4 +- src/gpu/ops/GrDashOp.cpp | 115 +++++------ src/gpu/ops/GrDefaultPathRenderer.cpp | 2 +- src/gpu/ops/GrDrawAtlasOp.cpp | 6 +- src/gpu/ops/GrDrawVerticesOp.cpp | 6 +- src/gpu/ops/GrLatticeOp.cpp | 48 ++--- src/gpu/ops/GrNonAAFillRectOp.cpp | 23 ++- src/gpu/ops/GrNonAAStrokeRectOp.cpp | 6 +- src/gpu/ops/GrOvalOpFactory.cpp | 236 ++++++++++------------ src/gpu/ops/GrRegionOp.cpp | 13 +- src/gpu/ops/GrShadowRRectOp.cpp | 7 +- src/gpu/ops/GrSmallPathRenderer.cpp | 17 +- src/gpu/ops/GrTessellatingPathRenderer.cpp | 18 +- src/gpu/ops/GrTextureOp.cpp | 112 +++++----- 19 files changed, 324 insertions(+), 383 deletions(-) (limited to 'src/gpu/ops') diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp index 566eebd827..3237afeaed 100644 --- a/src/gpu/ops/GrAAConvexPathRenderer.cpp +++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp @@ -576,21 +576,21 @@ public: GrGLSLVarying v(kHalf4_GrSLType); varyingHandler->addVarying("QuadEdge", &v); - vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.kInQuadEdge.name()); + vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.fInQuadEdge->name()); // Setup pass through color - varyingHandler->addPassThroughAttribute(qe.kInColor, args.fOutputColor); + varyingHandler->addPassThroughAttribute(qe.fInColor, args.fOutputColor); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; // Setup position - this->writeOutputPosition(vertBuilder, gpArgs, qe.kInPosition.name()); + this->writeOutputPosition(vertBuilder, gpArgs, qe.fInPosition->name()); // emit transforms this->emitTransforms(vertBuilder, varyingHandler, uniformHandler, - qe.kInPosition.asShaderVar(), + qe.fInPosition->asShaderVar(), qe.fLocalMatrix, args.fFPCoordTransformHandler); @@ -646,25 +646,21 @@ private: : INHERITED(kQuadEdgeEffect_ClassID) , fLocalMatrix(localMatrix) , fUsesLocalCoords(usesLocalCoords) { - this->setVertexAttributeCnt(3); + fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); + fInColor = &this->addVertexAttrib("inColor", kUByte4_norm_GrVertexAttribType); + fInQuadEdge = &this->addVertexAttrib("inQuadEdge", kHalf4_GrVertexAttribType); } - const Attribute& onVertexAttribute(int i) const override { - return IthAttribute(i, kInPosition, kInColor, kInQuadEdge); - } - static constexpr Attribute kInPosition = {"inPosition", kFloat2_GrVertexAttribType}; - static constexpr Attribute kInColor = {"inColor", kUByte4_norm_GrVertexAttribType}; - static constexpr Attribute kInQuadEdge = {"inQuadEdge", kHalf4_GrVertexAttribType}; - SkMatrix fLocalMatrix; - bool fUsesLocalCoords; + const Attribute* fInPosition; + const Attribute* fInQuadEdge; + const Attribute* fInColor; + SkMatrix fLocalMatrix; + bool fUsesLocalCoords; GR_DECLARE_GEOMETRY_PROCESSOR_TEST typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInPosition; -constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInColor; -constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInQuadEdge; GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect); @@ -799,10 +795,12 @@ private: return; } - size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage() - ? sizeof(GrDefaultGeoProcFactory::PositionColorAttr) - : sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr); - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + + SkASSERT(fHelper.compatibleWithAlphaAsCoverage() + ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) + : vertexStride == + sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); GrAAConvexTessellator tess; @@ -903,9 +901,9 @@ private: const GrBuffer* vertexBuffer; int firstVertex; - SkASSERT(sizeof(QuadVertex) == quadProcessor->debugOnly_vertexStride()); + size_t vertexStride = quadProcessor->getVertexStride(); QuadVertex* verts = reinterpret_cast(target->makeVertexSpace( - sizeof(QuadVertex), vertexCount, &vertexBuffer, &firstVertex)); + vertexStride, vertexCount, &vertexBuffer, &firstVertex)); if (!verts) { SkDebugf("Could not allocate vertices\n"); diff --git a/src/gpu/ops/GrAAFillRectOp.cpp b/src/gpu/ops/GrAAFillRectOp.cpp index 76bc8128cf..5472f11f71 100644 --- a/src/gpu/ops/GrAAFillRectOp.cpp +++ b/src/gpu/ops/GrAAFillRectOp.cpp @@ -242,19 +242,12 @@ private: void onPrepareDraws(Target* target) override { using namespace GrDefaultGeoProcFactory; - size_t vertexStride = sizeof(SkPoint) + sizeof(GrColor); Color color(Color::kPremulGrColorAttribute_Type); - Coverage::Type coverageType = Coverage::kSolid_Type; - if (!fHelper.compatibleWithAlphaAsCoverage()) { - coverageType = Coverage::kAttribute_Type; - vertexStride += sizeof(float); - } - LocalCoords lc = LocalCoords::kUnused_Type; - if (fHelper.usesLocalCoords()) { - lc = LocalCoords::kHasExplicit_Type; - vertexStride += sizeof(SkPoint); - } - + Coverage::Type coverageType = fHelper.compatibleWithAlphaAsCoverage() + ? Coverage::kSolid_Type + : Coverage::kAttribute_Type; + LocalCoords lc = fHelper.usesLocalCoords() ? LocalCoords::kHasExplicit_Type + : LocalCoords::kUnused_Type; sk_sp gp = GrDefaultGeoProcFactory::Make(color, coverageType, lc, SkMatrix::I()); if (!gp) { @@ -262,7 +255,7 @@ private: return; } - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); sk_sp indexBuffer = get_index_buffer(target->resourceProvider()); PatternHelper helper(GrPrimitiveType::kTriangles); diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp index 89dedc48a4..b62c14b197 100644 --- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp +++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp @@ -959,16 +959,18 @@ void AAHairlineOp::onPrepareDraws(Target* target) { const GrBuffer* vertexBuffer; int firstVertex; - SkASSERT(sizeof(LineVertex) == lineGP->debugOnly_vertexStride()); + size_t vertexStride = lineGP->getVertexStride(); int vertexCount = kLineSegNumVertices * lineCount; - LineVertex* verts = reinterpret_cast(target->makeVertexSpace( - sizeof(LineVertex), vertexCount, &vertexBuffer, &firstVertex)); + LineVertex* verts = reinterpret_cast( + target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex)); if (!verts|| !linesIndexBuffer) { SkDebugf("Could not allocate vertices\n"); return; } + SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex)); + for (int i = 0; i < lineCount; ++i) { add_line(&lines[2*i], toSrc, this->coverage(), &verts); } @@ -1002,11 +1004,10 @@ void AAHairlineOp::onPrepareDraws(Target* target) { sk_sp quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider()); - SkASSERT(sizeof(BezierVertex) == quadGP->debugOnly_vertexStride()); - SkASSERT(sizeof(BezierVertex) == conicGP->debugOnly_vertexStride()); + size_t vertexStride = sizeof(BezierVertex); int vertexCount = kQuadNumVertices * quadAndConicCount; - void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer, - &firstVertex); + void *vertices = target->makeVertexSpace(vertexStride, vertexCount, + &vertexBuffer, &firstVertex); if (!vertices || !quadsIndexBuffer) { SkDebugf("Could not allocate vertices\n"); diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp index b6b70779ff..5659099c84 100644 --- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp +++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp @@ -249,10 +249,12 @@ private: return; } - size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage() - ? sizeof(GrDefaultGeoProcFactory::PositionColorAttr) - : sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr); - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + + SkASSERT(fHelper.compatibleWithAlphaAsCoverage() + ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) + : vertexStride == + sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); int instanceCount = fPaths.count(); diff --git a/src/gpu/ops/GrAAStrokeRectOp.cpp b/src/gpu/ops/GrAAStrokeRectOp.cpp index 3347227f04..b9a6d88021 100644 --- a/src/gpu/ops/GrAAStrokeRectOp.cpp +++ b/src/gpu/ops/GrAAStrokeRectOp.cpp @@ -268,11 +268,11 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) { return; } - size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage() - ? sizeof(GrDefaultGeoProcFactory::PositionColorAttr) - : sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr); + size_t vertexStride = gp->getVertexStride(); - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + SkASSERT(fHelper.compatibleWithAlphaAsCoverage() + ? vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorAttr) + : vertexStride == sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr)); int innerVertexNum = 4; int outerVertexNum = this->miterStroke() ? 4 : 8; int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2; diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp index 2d98d2dd2b..eb39079423 100644 --- a/src/gpu/ops/GrAtlasTextOp.cpp +++ b/src/gpu/ops/GrAtlasTextOp.cpp @@ -307,8 +307,8 @@ void GrAtlasTextOp::onPrepareDraws(Target* target) { } flushInfo.fGlyphsToFlush = 0; - size_t vertexStride = GrTextBlob::GetVertexStride(maskFormat, vmPerspective); - SkASSERT(vertexStride == flushInfo.fGeometryProcessor->debugOnly_vertexStride()); + size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride(); + SkASSERT(vertexStride == GrTextBlob::GetVertexStride(maskFormat, vmPerspective)); int glyphCount = this->numGlyphs(); const GrBuffer* vertexBuffer; diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp index 5023f38cd1..b784b0590e 100644 --- a/src/gpu/ops/GrDashOp.cpp +++ b/src/gpu/ops/GrDashOp.cpp @@ -624,15 +624,7 @@ private: } QuadHelper helper; - size_t vertexStride; - if (fullDash) { - vertexStride = - SkPaint::kRound_Cap == fCap ? sizeof(DashCircleVertex) : sizeof(DashLineVertex); - } else { - vertexStride = sizeof(SkPoint); - } - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); - void* vertices = helper.init(target, vertexStride, totalRectCount); + void* vertices = helper.init(target, gp->getVertexStride(), totalRectCount); if (!vertices) { return; } @@ -644,13 +636,15 @@ private: if (!draws[i].fLineDone) { if (fullDash) { - setup_dashed_rect( - rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv, - draws[i].fStartOffset, draws[i].fDevBloatX, draws[i].fDevBloatY, - draws[i].fLineLength, draws[i].fHalfDevStroke, draws[i].fIntervals[0], - draws[i].fIntervals[1], draws[i].fStrokeWidth, capType, vertexStride); + setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv, + draws[i].fStartOffset, draws[i].fDevBloatX, + draws[i].fDevBloatY, draws[i].fLineLength, + draws[i].fHalfDevStroke, draws[i].fIntervals[0], + draws[i].fIntervals[1], draws[i].fStrokeWidth, + capType, gp->getVertexStride()); } else { SkPoint* verts = reinterpret_cast(vertices); + SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRotInv, verts); } curVIdx += 4; @@ -659,13 +653,15 @@ private: if (draws[i].fHasStartRect) { if (fullDash) { - setup_dashed_rect( - rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv, - draws[i].fStartOffset, draws[i].fDevBloatX, draws[i].fDevBloatY, - draws[i].fIntervals[0], draws[i].fHalfDevStroke, draws[i].fIntervals[0], - draws[i].fIntervals[1], draws[i].fStrokeWidth, capType, vertexStride); + setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv, + draws[i].fStartOffset, draws[i].fDevBloatX, + draws[i].fDevBloatY, draws[i].fIntervals[0], + draws[i].fHalfDevStroke, draws[i].fIntervals[0], + draws[i].fIntervals[1], draws[i].fStrokeWidth, capType, + gp->getVertexStride()); } else { SkPoint* verts = reinterpret_cast(vertices); + SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRotInv, verts); } curVIdx += 4; @@ -674,13 +670,15 @@ private: if (draws[i].fHasEndRect) { if (fullDash) { - setup_dashed_rect( - rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv, - draws[i].fStartOffset, draws[i].fDevBloatX, draws[i].fDevBloatY, - draws[i].fIntervals[0], draws[i].fHalfDevStroke, draws[i].fIntervals[0], - draws[i].fIntervals[1], draws[i].fStrokeWidth, capType, vertexStride); + setup_dashed_rect(rects[rectIndex], vertices, curVIdx, geom.fSrcRotInv, + draws[i].fStartOffset, draws[i].fDevBloatX, + draws[i].fDevBloatY, draws[i].fIntervals[0], + draws[i].fHalfDevStroke, draws[i].fIntervals[0], + draws[i].fIntervals[1], draws[i].fStrokeWidth, capType, + gp->getVertexStride()); } else { SkPoint* verts = reinterpret_cast(vertices); + SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); setup_dashed_rect_pos(rects[rectIndex], curVIdx, geom.fSrcRotInv, verts); } curVIdx += 4; @@ -840,6 +838,12 @@ public: const char* name() const override { return "DashingCircleEffect"; } + const Attribute* inPosition() const { return fInPosition; } + + const Attribute* inDashParams() const { return fInDashParams; } + + const Attribute* inCircleParams() const { return fInCircleParams; } + AAMode aaMode() const { return fAAMode; } GrColor color() const { return fColor; } @@ -856,27 +860,18 @@ private: DashingCircleEffect(GrColor, AAMode aaMode, const SkMatrix& localMatrix, bool usesLocalCoords); - const Attribute& onVertexAttribute(int i) const override { - return IthAttribute(i, kInPosition, kInDashParams, kInCircleParams); - } - GrColor fColor; SkMatrix fLocalMatrix; bool fUsesLocalCoords; AAMode fAAMode; - - static constexpr Attribute kInPosition = {"inPosition", kFloat2_GrVertexAttribType}; - static constexpr Attribute kInDashParams = {"inDashParams", kHalf3_GrVertexAttribType}; - static constexpr Attribute kInCircleParams = {"inCircleParams", kHalf2_GrVertexAttribType}; + const Attribute* fInPosition; + const Attribute* fInDashParams; + const Attribute* fInCircleParams; GR_DECLARE_GEOMETRY_PROCESSOR_TEST - friend class GLDashingCircleEffect; typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInPosition; -constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInDashParams; -constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInCircleParams; ////////////////////////////////////////////////////////////////////////////// @@ -921,25 +916,25 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { // XY are dashPos, Z is dashInterval GrGLSLVarying dashParams(kHalf3_GrSLType); varyingHandler->addVarying("DashParam", &dashParams); - vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.kInDashParams.name()); + vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.inDashParams()->name()); // x refers to circle radius - 0.5, y refers to cicle's center x coord GrGLSLVarying circleParams(kHalf2_GrSLType); varyingHandler->addVarying("CircleParams", &circleParams); - vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.kInCircleParams.name()); + vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.inCircleParams()->name()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; // Setup pass through color this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform); // Setup position - this->writeOutputPosition(vertBuilder, gpArgs, dce.kInPosition.name()); + this->writeOutputPosition(vertBuilder, gpArgs, dce.inPosition()->name()); // emit transforms this->emitTransforms(vertBuilder, varyingHandler, uniformHandler, - dce.kInPosition.asShaderVar(), + dce.inPosition()->asShaderVar(), dce.localMatrix(), args.fFPCoordTransformHandler); @@ -1012,7 +1007,9 @@ DashingCircleEffect::DashingCircleEffect(GrColor color, , fLocalMatrix(localMatrix) , fUsesLocalCoords(usesLocalCoords) , fAAMode(aaMode) { - this->setVertexAttributeCnt(3); + fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); + fInDashParams = &this->addVertexAttrib("inDashParams", kHalf3_GrVertexAttribType); + fInCircleParams = &this->addVertexAttrib("inCircleParams", kHalf2_GrVertexAttribType); } GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect); @@ -1050,6 +1047,12 @@ public: const char* name() const override { return "DashingEffect"; } + const Attribute* inPosition() const { return fInPosition; } + + const Attribute* inDashParams() const { return fInDashParams; } + + const Attribute* inRectParams() const { return fInRectParams; } + AAMode aaMode() const { return fAAMode; } GrColor color() const { return fColor; } @@ -1066,28 +1069,18 @@ private: DashingLineEffect(GrColor, AAMode aaMode, const SkMatrix& localMatrix, bool usesLocalCoords); - const Attribute& onVertexAttribute(int i) const override { - return IthAttribute(i, kInPosition, kInDashParams, kInRectParams); - } - GrColor fColor; SkMatrix fLocalMatrix; bool fUsesLocalCoords; AAMode fAAMode; - - static constexpr Attribute kInPosition = {"inPosition", kFloat2_GrVertexAttribType}; - static constexpr Attribute kInDashParams = {"inDashParams", kHalf3_GrVertexAttribType}; - static constexpr Attribute kInRectParams = {"inRect", kHalf4_GrVertexAttribType}; + const Attribute* fInPosition; + const Attribute* fInDashParams; + const Attribute* fInRectParams; GR_DECLARE_GEOMETRY_PROCESSOR_TEST - friend class GLDashingLineEffect; - typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInPosition; -constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInDashParams; -constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInRectParams; ////////////////////////////////////////////////////////////////////////////// @@ -1125,26 +1118,26 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { // XY refers to dashPos, Z is the dash interval length GrGLSLVarying inDashParams(kFloat3_GrSLType); varyingHandler->addVarying("DashParams", &inDashParams); - vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.kInDashParams.name()); + vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.inDashParams()->name()); // The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bottom - 0.5), // respectively. GrGLSLVarying inRectParams(kFloat4_GrSLType); varyingHandler->addVarying("RectParams", &inRectParams); - vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.kInRectParams.name()); + vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.inRectParams()->name()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; // Setup pass through color this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform); // Setup position - this->writeOutputPosition(vertBuilder, gpArgs, de.kInPosition.name()); + this->writeOutputPosition(vertBuilder, gpArgs, de.inPosition()->name()); // emit transforms this->emitTransforms(vertBuilder, varyingHandler, uniformHandler, - de.kInPosition.asShaderVar(), + de.inPosition()->asShaderVar(), de.localMatrix(), args.fFPCoordTransformHandler); @@ -1235,7 +1228,9 @@ DashingLineEffect::DashingLineEffect(GrColor color, , fLocalMatrix(localMatrix) , fUsesLocalCoords(usesLocalCoords) , fAAMode(aaMode) { - this->setVertexAttributeCnt(3); + fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); + fInDashParams = &this->addVertexAttrib("inDashParams", kHalf3_GrVertexAttribType); + fInRectParams = &this->addVertexAttrib("inRect", kHalf4_GrVertexAttribType); } GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect); @@ -1247,8 +1242,8 @@ sk_sp DashingLineEffect::TestCreate(GrProcessorTestData* d) aaMode, GrTest::TestMatrix(d->fRandom), d->fRandom->nextBool()); } - #endif + ////////////////////////////////////////////////////////////////////////////// static sk_sp make_dash_gp(GrColor color, diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp index aa0963b02a..df6f81f552 100644 --- a/src/gpu/ops/GrDefaultPathRenderer.cpp +++ b/src/gpu/ops/GrDefaultPathRenderer.cpp @@ -404,7 +404,7 @@ private: gp = GrDefaultGeoProcFactory::Make(color, coverage, localCoords, this->viewMatrix()); } - SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint)); + SkASSERT(gp->getVertexStride() == sizeof(SkPoint)); int instanceCount = fPaths.count(); diff --git a/src/gpu/ops/GrDrawAtlasOp.cpp b/src/gpu/ops/GrDrawAtlasOp.cpp index 47bad8b2a4..fa08e558f3 100644 --- a/src/gpu/ops/GrDrawAtlasOp.cpp +++ b/src/gpu/ops/GrDrawAtlasOp.cpp @@ -122,9 +122,9 @@ void GrDrawAtlasOp::onPrepareDraws(Target* target) { sk_sp gp(make_gp(this->hasColors(), this->color(), this->viewMatrix())); int instanceCount = fGeoData.count(); - size_t vertexStride = - sizeof(SkPoint) + sizeof(SkPoint) + (this->hasColors() ? sizeof(GrColor) : 0); - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(vertexStride == + sizeof(SkPoint) + sizeof(SkPoint) + (this->hasColors() ? sizeof(GrColor) : 0)); QuadHelper helper; int numQuads = this->quadCount(); diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp index 8f6ad9745d..c968611152 100644 --- a/src/gpu/ops/GrDrawVerticesOp.cpp +++ b/src/gpu/ops/GrDrawVerticesOp.cpp @@ -140,10 +140,10 @@ void GrDrawVerticesOp::onPrepareDraws(Target* target) { bool hasColorAttribute; bool hasLocalCoordsAttribute; sk_sp gp = this->makeGP(&hasColorAttribute, &hasLocalCoordsAttribute); + size_t vertexStride = gp->getVertexStride(); - size_t vertexStride = sizeof(SkPoint) + (hasColorAttribute ? sizeof(uint32_t) : 0) + - (hasLocalCoordsAttribute ? sizeof(SkPoint) : 0); - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + SkASSERT(vertexStride == sizeof(SkPoint) + (hasColorAttribute ? sizeof(uint32_t) : 0) + + (hasLocalCoordsAttribute ? sizeof(SkPoint) : 0)); int instanceCount = fMeshes.count(); diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp index 7bfa72ec94..5903231cb2 100644 --- a/src/gpu/ops/GrLatticeOp.cpp +++ b/src/gpu/ops/GrLatticeOp.cpp @@ -62,19 +62,19 @@ public: latticeGP.fColorSpaceXform.get()); args.fVaryingHandler->emitAttributes(latticeGP); - this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.kPositions.name()); + this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.fPositions.name()); this->emitTransforms(args.fVertBuilder, args.fVaryingHandler, args.fUniformHandler, - latticeGP.kTextureCoords.asShaderVar(), + latticeGP.fTextureCoords.asShaderVar(), args.fFPCoordTransformHandler); args.fFragBuilder->codeAppend("float2 textureCoords;"); - args.fVaryingHandler->addPassThroughAttribute(latticeGP.kTextureCoords, + args.fVaryingHandler->addPassThroughAttribute(&latticeGP.fTextureCoords, "textureCoords"); args.fFragBuilder->codeAppend("float4 textureDomain;"); args.fVaryingHandler->addPassThroughAttribute( - latticeGP.kTextureDomain, "textureDomain", Interpolation::kCanBeFlat); - args.fVaryingHandler->addPassThroughAttribute(latticeGP.kColors, args.fOutputColor, + &latticeGP.fTextureDomain, "textureDomain", Interpolation::kCanBeFlat); + args.fVaryingHandler->addPassThroughAttribute(&latticeGP.fColors, args.fOutputColor, Interpolation::kCanBeFlat); args.fFragBuilder->codeAppendf("%s = ", args.fOutputColor); args.fFragBuilder->appendTextureLookupAndModulate( @@ -95,31 +95,24 @@ private: LatticeGP(sk_sp proxy, sk_sp csxf, GrSamplerState::Filter filter) : INHERITED(kLatticeGP_ClassID), fColorSpaceXform(std::move(csxf)) { + fPositions = this->addVertexAttrib("position", kFloat2_GrVertexAttribType); fSampler.reset(std::move(proxy), filter); this->addTextureSampler(&fSampler); - this->setVertexAttributeCnt(4); + fTextureCoords = this->addVertexAttrib("textureCoords", kFloat2_GrVertexAttribType); + fTextureDomain = this->addVertexAttrib("textureDomain", kFloat4_GrVertexAttribType); + fColors = this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType); } - const Attribute& onVertexAttribute(int i) const override { - return IthAttribute(i, kPositions, kTextureCoords, kTextureDomain, kColors); - } - - static constexpr Attribute kPositions = {"position", kFloat2_GrVertexAttribType}; - static constexpr Attribute kTextureCoords = {"textureCoords", kFloat2_GrVertexAttribType}; - static constexpr Attribute kTextureDomain = {"textureDomain", kFloat4_GrVertexAttribType}; - static constexpr Attribute kColors = {"color", kUByte4_norm_GrVertexAttribType}; - + Attribute fPositions; + Attribute fTextureCoords; + Attribute fTextureDomain; + Attribute fColors; sk_sp fColorSpaceXform; TextureSampler fSampler; typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute LatticeGP::kPositions; -constexpr GrPrimitiveProcessor::Attribute LatticeGP::kTextureCoords; -constexpr GrPrimitiveProcessor::Attribute LatticeGP::kTextureDomain; -constexpr GrPrimitiveProcessor::Attribute LatticeGP::kColors; - class NonAALatticeOp final : public GrMeshDrawOp { private: using Helper = GrSimpleMeshDrawOpHelper; @@ -207,10 +200,7 @@ private: return; } - static constexpr size_t kVertexStide = - sizeof(SkPoint) + sizeof(SkPoint) + sizeof(SkRect) + sizeof(uint32_t); - SkASSERT(kVertexStide == gp->debugOnly_vertexStride()); - + size_t vertexStride = gp->getVertexStride(); int patchCnt = fPatches.count(); int numRects = 0; for (int i = 0; i < patchCnt; i++) { @@ -223,7 +213,7 @@ private: sk_sp indexBuffer = target->resourceProvider()->refQuadIndexBuffer(); PatternHelper helper(GrPrimitiveType::kTriangles); - void* vertices = helper.init(target, kVertexStide, indexBuffer.get(), kVertsPerRect, + void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect, kIndicesPerRect, numRects); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); @@ -251,7 +241,7 @@ private: static const Sk4f kFlipMuls(1.f, -1.f, 1.f, -1.f); while (patch.fIter->next(&srcR, &dstR)) { auto vertices = reinterpret_cast(verts); - SkPointPriv::SetRectTriStrip(&vertices->fPosition, dstR, kVertexStide); + SkPointPriv::SetRectTriStrip(&vertices->fPosition, dstR, vertexStride); Sk4f coords(SkIntToScalar(srcR.fLeft), SkIntToScalar(srcR.fTop), SkIntToScalar(srcR.fRight), SkIntToScalar(srcR.fBottom)); Sk4f domain = coords + kDomainOffsets; @@ -262,7 +252,7 @@ private: domain = SkNx_shuffle<0, 3, 2, 1>(kFlipMuls * domain + kFlipOffsets); } SkPointPriv::SetRectTriStrip(&vertices->fTextureCoords, coords[0], coords[1], - coords[2], coords[3], kVertexStide); + coords[2], coords[3], vertexStride); for (int j = 0; j < kVertsPerRect; ++j) { vertices[j].fTextureDomain = {domain[0], domain[1], domain[2], domain[3]}; } @@ -270,13 +260,13 @@ private: for (int j = 0; j < kVertsPerRect; ++j) { vertices[j].fColor = patch.fColor; } - verts += kVertsPerRect * kVertexStide; + verts += kVertsPerRect * vertexStride; } // If we didn't handle it above, apply the matrix here. if (!isScaleTranslate) { SkPoint* positions = reinterpret_cast(patchVerts); - SkMatrixPriv::MapPointsWithStride(patch.fViewMatrix, positions, kVertexStide, + SkMatrixPriv::MapPointsWithStride(patch.fViewMatrix, positions, vertexStride, kVertsPerRect * patch.fIter->numRectsToDraw()); } } diff --git a/src/gpu/ops/GrNonAAFillRectOp.cpp b/src/gpu/ops/GrNonAAFillRectOp.cpp index d4ebedc6e1..20bd599133 100644 --- a/src/gpu/ops/GrNonAAFillRectOp.cpp +++ b/src/gpu/ops/GrNonAAFillRectOp.cpp @@ -181,16 +181,15 @@ private: SkDebugf("Couldn't create GrGeometryProcessor\n"); return; } + SkASSERT(gp->getVertexStride() == + sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)); - static constexpr size_t kVertexStride = - sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr); - SkASSERT(kVertexStride == gp->debugOnly_vertexStride()); - + size_t vertexStride = gp->getVertexStride(); int rectCount = fRects.count(); sk_sp indexBuffer = target->resourceProvider()->refQuadIndexBuffer(); PatternHelper helper(GrPrimitiveType::kTriangles); - void* vertices = helper.init(target, kVertexStride, indexBuffer.get(), kVertsPerRect, + void* vertices = helper.init(target, vertexStride, indexBuffer.get(), kVertsPerRect, kIndicesPerRect, rectCount); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); @@ -199,8 +198,8 @@ private: for (int i = 0; i < rectCount; i++) { intptr_t verts = - reinterpret_cast(vertices) + i * kVertsPerRect * kVertexStride; - tesselate(verts, kVertexStride, fRects[i].fColor, &fRects[i].fViewMatrix, + reinterpret_cast(vertices) + i * kVertsPerRect * vertexStride; + tesselate(verts, vertexStride, fRects[i].fColor, &fRects[i].fViewMatrix, fRects[i].fRect, &fRects[i].fLocalQuad); } helper.recordDraw(target, gp.get(), fHelper.makePipeline(target)); @@ -312,11 +311,13 @@ private: SkDebugf("Couldn't create GrGeometryProcessor\n"); return; } - size_t vertexStride = fHasLocalRect - ? sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr) - : sizeof(GrDefaultGeoProcFactory::PositionColorAttr); - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + SkASSERT(fHasLocalRect + ? gp->getVertexStride() == + sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr) + : gp->getVertexStride() == + sizeof(GrDefaultGeoProcFactory::PositionColorAttr)); + size_t vertexStride = gp->getVertexStride(); int rectCount = fRects.count(); sk_sp indexBuffer = target->resourceProvider()->refQuadIndexBuffer(); diff --git a/src/gpu/ops/GrNonAAStrokeRectOp.cpp b/src/gpu/ops/GrNonAAStrokeRectOp.cpp index 11c2f8cda5..5e00e559e7 100644 --- a/src/gpu/ops/GrNonAAStrokeRectOp.cpp +++ b/src/gpu/ops/GrNonAAStrokeRectOp.cpp @@ -152,9 +152,9 @@ private: fViewMatrix); } - static constexpr size_t kVertexStride = sizeof(GrDefaultGeoProcFactory::PositionAttr); + size_t vertexStride = gp->getVertexStride(); - SkASSERT(kVertexStride == gp->debugOnly_vertexStride()); + SkASSERT(vertexStride == sizeof(GrDefaultGeoProcFactory::PositionAttr)); int vertexCount = kVertsPerHairlineRect; if (fStrokeWidth > 0) { @@ -165,7 +165,7 @@ private: int firstVertex; void* verts = - target->makeVertexSpace(kVertexStride, vertexCount, &vertexBuffer, &firstVertex); + target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex); if (!verts) { SkDebugf("Could not allocate vertices\n"); diff --git a/src/gpu/ops/GrOvalOpFactory.cpp b/src/gpu/ops/GrOvalOpFactory.cpp index 75ffb17370..747fa5f119 100644 --- a/src/gpu/ops/GrOvalOpFactory.cpp +++ b/src/gpu/ops/GrOvalOpFactory.cpp @@ -73,26 +73,32 @@ public: : INHERITED(kCircleGeometryProcessor_ClassID) , fLocalMatrix(localMatrix) , fStroke(stroke) { - int cnt = 3; + fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); + fInColor = &this->addVertexAttrib("inColor", kUByte4_norm_GrVertexAttribType); + fInCircleEdge = &this->addVertexAttrib("inCircleEdge", kFloat4_GrVertexAttribType); if (clipPlane) { - fInClipPlane = {"inClipPlane", kHalf3_GrVertexAttribType}; - ++cnt; + fInClipPlane = &this->addVertexAttrib("inClipPlane", kHalf3_GrVertexAttribType); + } else { + fInClipPlane = nullptr; } if (isectPlane) { - fInIsectPlane = {"inIsectPlane", kHalf3_GrVertexAttribType}; - ++cnt; + fInIsectPlane = &this->addVertexAttrib("inIsectPlane", kHalf3_GrVertexAttribType); + } else { + fInIsectPlane = nullptr; } if (unionPlane) { - fInUnionPlane = {"inUnionPlane", kHalf3_GrVertexAttribType}; - ++cnt; + fInUnionPlane = &this->addVertexAttrib("inUnionPlane", kHalf3_GrVertexAttribType); + } else { + fInUnionPlane = nullptr; } if (roundCaps) { SkASSERT(stroke); SkASSERT(clipPlane); - fInRoundCapCenters = {"inRoundCapCenters", kFloat4_GrVertexAttribType}; - ++cnt; + fInRoundCapCenters = + &this->addVertexAttrib("inRoundCapCenters", kFloat4_GrVertexAttribType); + } else { + fInRoundCapCenters = nullptr; } - this->setVertexAttributeCnt(cnt); } ~CircleGeometryProcessor() override {} @@ -122,22 +128,23 @@ private: // emit attributes varyingHandler->emitAttributes(cgp); fragBuilder->codeAppend("float4 circleEdge;"); - varyingHandler->addPassThroughAttribute(cgp.kInCircleEdge, "circleEdge"); - if (cgp.fInClipPlane.isInitialized()) { + varyingHandler->addPassThroughAttribute(cgp.fInCircleEdge, "circleEdge"); + if (cgp.fInClipPlane) { fragBuilder->codeAppend("half3 clipPlane;"); varyingHandler->addPassThroughAttribute(cgp.fInClipPlane, "clipPlane"); } - if (cgp.fInIsectPlane.isInitialized()) { + if (cgp.fInIsectPlane) { + SkASSERT(cgp.fInClipPlane); fragBuilder->codeAppend("half3 isectPlane;"); varyingHandler->addPassThroughAttribute(cgp.fInIsectPlane, "isectPlane"); } - if (cgp.fInUnionPlane.isInitialized()) { - SkASSERT(cgp.fInClipPlane.isInitialized()); + if (cgp.fInUnionPlane) { + SkASSERT(cgp.fInClipPlane); fragBuilder->codeAppend("half3 unionPlane;"); varyingHandler->addPassThroughAttribute(cgp.fInUnionPlane, "unionPlane"); } GrGLSLVarying capRadius(kFloat_GrSLType); - if (cgp.fInRoundCapCenters.isInitialized()) { + if (cgp.fInRoundCapCenters) { fragBuilder->codeAppend("float4 roundCapCenters;"); varyingHandler->addPassThroughAttribute(cgp.fInRoundCapCenters, "roundCapCenters"); varyingHandler->addVarying("capRadius", &capRadius, @@ -145,20 +152,20 @@ private: // This is the cap radius in normalized space where the outer radius is 1 and // circledEdge.w is the normalized inner radius. vertBuilder->codeAppendf("%s = (1.0 - %s.w) / 2.0;", capRadius.vsOut(), - cgp.kInCircleEdge.name()); + cgp.fInCircleEdge->name()); } // setup pass through color - varyingHandler->addPassThroughAttribute(cgp.kInColor, args.fOutputColor); + varyingHandler->addPassThroughAttribute(cgp.fInColor, args.fOutputColor); // Setup position - this->writeOutputPosition(vertBuilder, gpArgs, cgp.kInPosition.name()); + this->writeOutputPosition(vertBuilder, gpArgs, cgp.fInPosition->name()); // emit transforms this->emitTransforms(vertBuilder, varyingHandler, uniformHandler, - cgp.kInPosition.asShaderVar(), + cgp.fInPosition->asShaderVar(), cgp.fLocalMatrix, args.fFPCoordTransformHandler); @@ -172,22 +179,22 @@ private: fragBuilder->codeAppend("edgeAlpha *= innerAlpha;"); } - if (cgp.fInClipPlane.isInitialized()) { + if (cgp.fInClipPlane) { fragBuilder->codeAppend( "half clip = clamp(circleEdge.z * dot(circleEdge.xy, clipPlane.xy) + " "clipPlane.z, 0.0, 1.0);"); - if (cgp.fInIsectPlane.isInitialized()) { + if (cgp.fInIsectPlane) { fragBuilder->codeAppend( "clip *= clamp(circleEdge.z * dot(circleEdge.xy, isectPlane.xy) + " "isectPlane.z, 0.0, 1.0);"); } - if (cgp.fInUnionPlane.isInitialized()) { + if (cgp.fInUnionPlane) { fragBuilder->codeAppend( "clip += (1.0 - clip)*clamp(circleEdge.z * dot(circleEdge.xy, " "unionPlane.xy) + unionPlane.z, 0.0, 1.0);"); } fragBuilder->codeAppend("edgeAlpha *= clip;"); - if (cgp.fInRoundCapCenters.isInitialized()) { + if (cgp.fInRoundCapCenters) { // We compute coverage of the round caps as circles at the butt caps produced // by the clip planes. The inverse of the clip planes is applied so that there // is no double counting. @@ -211,10 +218,10 @@ private: uint16_t key; key = cgp.fStroke ? 0x01 : 0x0; key |= cgp.fLocalMatrix.hasPerspective() ? 0x02 : 0x0; - key |= cgp.fInClipPlane.isInitialized() ? 0x04 : 0x0; - key |= cgp.fInIsectPlane.isInitialized() ? 0x08 : 0x0; - key |= cgp.fInUnionPlane.isInitialized() ? 0x10 : 0x0; - key |= cgp.fInRoundCapCenters.isInitialized() ? 0x20 : 0x0; + key |= cgp.fInClipPlane ? 0x04 : 0x0; + key |= cgp.fInIsectPlane ? 0x08 : 0x0; + key |= cgp.fInUnionPlane ? 0x10 : 0x0; + key |= cgp.fInRoundCapCenters ? 0x20 : 0x0; b->add32(key); } @@ -228,31 +235,19 @@ private: typedef GrGLSLGeometryProcessor INHERITED; }; - const Attribute& onVertexAttribute(int i) const override { - return IthInitializedAttribute(i, kInPosition, kInColor, kInCircleEdge, fInClipPlane, - fInIsectPlane, fInUnionPlane, fInRoundCapCenters); - } - SkMatrix fLocalMatrix; - - static constexpr Attribute kInPosition = {"inPosition", kFloat2_GrVertexAttribType}; - static constexpr Attribute kInColor = {"inColor", kUByte4_norm_GrVertexAttribType}; - static constexpr Attribute kInCircleEdge = {"inCircleEdge", kFloat4_GrVertexAttribType}; - - // Optional attributes. - Attribute fInClipPlane; - Attribute fInIsectPlane; - Attribute fInUnionPlane; - Attribute fInRoundCapCenters; - + const Attribute* fInPosition; + const Attribute* fInColor; + const Attribute* fInCircleEdge; + const Attribute* fInClipPlane; + const Attribute* fInIsectPlane; + const Attribute* fInUnionPlane; + const Attribute* fInRoundCapCenters; bool fStroke; GR_DECLARE_GEOMETRY_PROCESSOR_TEST typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInPosition; -constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInColor; -constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInCircleEdge; GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleGeometryProcessor); @@ -273,7 +268,10 @@ class ButtCapDashedCircleGeometryProcessor : public GrGeometryProcessor { public: ButtCapDashedCircleGeometryProcessor(const SkMatrix& localMatrix) : INHERITED(kButtCapStrokedCircleGeometryProcessor_ClassID), fLocalMatrix(localMatrix) { - this->setVertexAttributeCnt(4); + fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); + fInColor = &this->addVertexAttrib("inColor", kUByte4_norm_GrVertexAttribType); + fInCircleEdge = &this->addVertexAttrib("inCircleEdge", kFloat4_GrVertexAttribType); + fInDashParams = &this->addVertexAttrib("inDashParams", kFloat4_GrVertexAttribType); } ~ButtCapDashedCircleGeometryProcessor() override {} @@ -304,11 +302,11 @@ private: // emit attributes varyingHandler->emitAttributes(bcscgp); fragBuilder->codeAppend("float4 circleEdge;"); - varyingHandler->addPassThroughAttribute(bcscgp.kInCircleEdge, "circleEdge"); + varyingHandler->addPassThroughAttribute(bcscgp.fInCircleEdge, "circleEdge"); fragBuilder->codeAppend("float4 dashParams;"); varyingHandler->addPassThroughAttribute( - bcscgp.kInDashParams, "dashParams", + bcscgp.fInDashParams, "dashParams", GrGLSLVaryingHandler::Interpolation::kCanBeFlat); GrGLSLVarying wrapDashes(kHalf4_GrSLType); varyingHandler->addVarying("wrapDashes", &wrapDashes, @@ -316,7 +314,7 @@ private: GrGLSLVarying lastIntervalLength(kHalf_GrSLType); varyingHandler->addVarying("lastIntervalLength", &lastIntervalLength, GrGLSLVaryingHandler::Interpolation::kCanBeFlat); - vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.kInDashParams.name()); + vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.fInDashParams->name()); // Our fragment shader works in on/off intervals as specified by dashParams.xy: // x = length of on interval, y = length of on + off. // There are two other parameters in dashParams.zw: @@ -378,17 +376,17 @@ private: // setup pass through color varyingHandler->addPassThroughAttribute( - bcscgp.kInColor, args.fOutputColor, + bcscgp.fInColor, args.fOutputColor, GrGLSLVaryingHandler::Interpolation::kCanBeFlat); // Setup position - this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.kInPosition.name()); + this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.fInPosition->name()); // emit transforms this->emitTransforms(vertBuilder, varyingHandler, uniformHandler, - bcscgp.kInPosition.asShaderVar(), + bcscgp.fInPosition->asShaderVar(), bcscgp.fLocalMatrix, args.fFPCoordTransformHandler); GrShaderVar fnArgs[] = { @@ -482,24 +480,16 @@ private: typedef GrGLSLGeometryProcessor INHERITED; }; - const Attribute& onVertexAttribute(int i) const override { - return IthAttribute(i, kInPosition, kInColor, kInCircleEdge, kInDashParams); - } - SkMatrix fLocalMatrix; - static constexpr Attribute kInPosition = {"inPosition", kFloat2_GrVertexAttribType}; - static constexpr Attribute kInColor = {"inColor", kUByte4_norm_GrVertexAttribType}; - static constexpr Attribute kInCircleEdge = {"inCircleEdge", kFloat4_GrVertexAttribType}; - static constexpr Attribute kInDashParams = {"inDashParams", kFloat4_GrVertexAttribType}; + const Attribute* fInPosition; + const Attribute* fInColor; + const Attribute* fInCircleEdge; + const Attribute* fInDashParams; GR_DECLARE_GEOMETRY_PROCESSOR_TEST typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInPosition; -constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInColor; -constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInCircleEdge; -constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInDashParams; #if GR_TEST_UTILS sk_sp ButtCapDashedCircleGeometryProcessor::TestCreate(GrProcessorTestData* d) { @@ -523,7 +513,10 @@ public: EllipseGeometryProcessor(bool stroke, const SkMatrix& localMatrix) : INHERITED(kEllipseGeometryProcessor_ClassID) , fLocalMatrix(localMatrix) { - this->setVertexAttributeCnt(4); + fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); + fInColor = &this->addVertexAttrib("inColor", kUByte4_norm_GrVertexAttribType); + fInEllipseOffset = &this->addVertexAttrib("inEllipseOffset", kHalf2_GrVertexAttribType); + fInEllipseRadii = &this->addVertexAttrib("inEllipseRadii", kHalf4_GrVertexAttribType); fStroke = stroke; } @@ -556,24 +549,24 @@ private: GrGLSLVarying ellipseOffsets(kHalf2_GrSLType); varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets); vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(), - egp.kInEllipseOffset.name()); + egp.fInEllipseOffset->name()); GrGLSLVarying ellipseRadii(kHalf4_GrSLType); varyingHandler->addVarying("EllipseRadii", &ellipseRadii); - vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.kInEllipseRadii.name()); + vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.fInEllipseRadii->name()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; // setup pass through color - varyingHandler->addPassThroughAttribute(egp.kInColor, args.fOutputColor); + varyingHandler->addPassThroughAttribute(egp.fInColor, args.fOutputColor); // Setup position - this->writeOutputPosition(vertBuilder, gpArgs, egp.kInPosition.name()); + this->writeOutputPosition(vertBuilder, gpArgs, egp.fInPosition->name()); // emit transforms this->emitTransforms(vertBuilder, varyingHandler, uniformHandler, - egp.kInPosition.asShaderVar(), + egp.fInPosition->asShaderVar(), egp.fLocalMatrix, args.fFPCoordTransformHandler); @@ -621,15 +614,10 @@ private: typedef GrGLSLGeometryProcessor INHERITED; }; - const Attribute& onVertexAttribute(int i) const override { - return IthAttribute(i, kInPosition, kInColor, kInEllipseOffset, kInEllipseRadii); - } - - static constexpr Attribute kInPosition = {"inPosition", kFloat2_GrVertexAttribType}; - static constexpr Attribute kInColor = {"inColor", kUByte4_norm_GrVertexAttribType}; - static constexpr Attribute kInEllipseOffset = {"inEllipseOffset", kHalf2_GrVertexAttribType}; - static constexpr Attribute kInEllipseRadii = {"inEllipseRadii", kHalf4_GrVertexAttribType}; - + const Attribute* fInPosition; + const Attribute* fInColor; + const Attribute* fInEllipseOffset; + const Attribute* fInEllipseRadii; SkMatrix fLocalMatrix; bool fStroke; @@ -637,10 +625,6 @@ private: typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInPosition; -constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInColor; -constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInEllipseOffset; -constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInEllipseRadii; GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseGeometryProcessor); @@ -669,8 +653,11 @@ public: DIEllipseGeometryProcessor(const SkMatrix& viewMatrix, DIEllipseStyle style) : INHERITED(kDIEllipseGeometryProcessor_ClassID) , fViewMatrix(viewMatrix) { + fInPosition = &this->addVertexAttrib("inPosition", kFloat2_GrVertexAttribType); + fInColor = &this->addVertexAttrib("inColor", kUByte4_norm_GrVertexAttribType); + fInEllipseOffsets0 = &this->addVertexAttrib("inEllipseOffsets0", kHalf2_GrVertexAttribType); + fInEllipseOffsets1 = &this->addVertexAttrib("inEllipseOffsets1", kHalf2_GrVertexAttribType); fStyle = style; - this->setVertexAttributeCnt(4); } ~DIEllipseGeometryProcessor() override {} @@ -701,20 +688,22 @@ private: GrGLSLVarying offsets0(kHalf2_GrSLType); varyingHandler->addVarying("EllipseOffsets0", &offsets0); - vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), diegp.kInEllipseOffsets0.name()); + vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), + diegp.fInEllipseOffsets0->name()); GrGLSLVarying offsets1(kHalf2_GrSLType); varyingHandler->addVarying("EllipseOffsets1", &offsets1); - vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), diegp.kInEllipseOffsets1.name()); + vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), + diegp.fInEllipseOffsets1->name()); GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; - varyingHandler->addPassThroughAttribute(diegp.kInColor, args.fOutputColor); + varyingHandler->addPassThroughAttribute(diegp.fInColor, args.fOutputColor); // Setup position this->writeOutputPosition(vertBuilder, uniformHandler, gpArgs, - diegp.kInPosition.name(), + diegp.fInPosition->name(), diegp.fViewMatrix, &fViewMatrixUniform); @@ -722,7 +711,7 @@ private: this->emitTransforms(vertBuilder, varyingHandler, uniformHandler, - diegp.kInPosition.asShaderVar(), + diegp.fInPosition->asShaderVar(), args.fFPCoordTransformHandler); // for outer curve @@ -793,17 +782,10 @@ private: typedef GrGLSLGeometryProcessor INHERITED; }; - const Attribute& onVertexAttribute(int i) const override { - return IthAttribute(i, kInPosition, kInColor, kInEllipseOffsets0, kInEllipseOffsets1); - } - - static constexpr Attribute kInPosition = {"inPosition", kFloat2_GrVertexAttribType}; - static constexpr Attribute kInColor = {"inColor", kUByte4_norm_GrVertexAttribType}; - static constexpr Attribute kInEllipseOffsets0 = {"inEllipseOffsets0", - kHalf2_GrVertexAttribType}; - static constexpr Attribute kInEllipseOffsets1 = {"inEllipseOffsets1", - kHalf2_GrVertexAttribType}; - + const Attribute* fInPosition; + const Attribute* fInColor; + const Attribute* fInEllipseOffsets0; + const Attribute* fInEllipseOffsets1; SkMatrix fViewMatrix; DIEllipseStyle fStyle; @@ -811,10 +793,6 @@ private: typedef GrGeometryProcessor INHERITED; }; -constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInPosition; -constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInColor; -constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInEllipseOffsets0; -constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInEllipseOffsets1; GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseGeometryProcessor); @@ -1163,11 +1141,11 @@ private: auto vertexCapCenters = [numPlanes](CircleVertex* v) { return (void*)(v->fHalfPlanes + numPlanes); }; - size_t vertexStride = sizeof(CircleVertex) - (fClipPlane ? 0 : 3 * sizeof(SkScalar)) - - (fClipPlaneIsect ? 0 : 3 * sizeof(SkScalar)) - - (fClipPlaneUnion ? 0 : 3 * sizeof(SkScalar)) + - (fRoundCaps ? 2 * sizeof(SkPoint) : 0); - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(vertexStride == sizeof(CircleVertex) - (fClipPlane ? 0 : 3 * sizeof(SkScalar)) - + (fClipPlaneIsect ? 0 : 3 * sizeof(SkScalar)) - + (fClipPlaneUnion ? 0 : 3 * sizeof(SkScalar)) + + (fRoundCaps ? 2 * sizeof(SkPoint) : 0)); const GrBuffer* vertexBuffer; int firstVertex; @@ -1651,12 +1629,12 @@ private: SkScalar fPhaseAngle; }; - static constexpr size_t kVertexStride = sizeof(CircleVertex); - SkASSERT(kVertexStride == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(vertexStride == sizeof(CircleVertex)); const GrBuffer* vertexBuffer; int firstVertex; - char* vertices = (char*)target->makeVertexSpace(kVertexStride, fVertCount, &vertexBuffer, + char* vertices = (char*)target->makeVertexSpace(vertexStride, fVertCount, &vertexBuffer, &firstVertex); if (!vertices) { SkDebugf("Could not allocate vertices\n"); @@ -1707,7 +1685,7 @@ private: SkPoint center = SkPoint::Make(bounds.centerX(), bounds.centerY()); SkScalar halfWidth = 0.5f * bounds.width(); auto init_outer_vertex = [&](int idx, SkScalar x, SkScalar y) { - CircleVertex* v = reinterpret_cast(vertices + idx * kVertexStride); + CircleVertex* v = reinterpret_cast(vertices + idx * vertexStride); v->fPos = center + SkPoint{x * halfWidth, y * halfWidth}; v->fOffset = {x, y}; init_const_attrs_and_reflect(v); @@ -1725,7 +1703,7 @@ private: // Compute the vertices of the inner octagon. auto init_inner_vertex = [&](int idx, SkScalar x, SkScalar y) { CircleVertex* v = - reinterpret_cast(vertices + (idx + 8) * kVertexStride); + reinterpret_cast(vertices + (idx + 8) * vertexStride); v->fPos = center + SkPoint{x * circle.fInnerRadius, y * circle.fInnerRadius}; v->fOffset = {x * normInnerRadius, y * normInnerRadius}; init_const_attrs_and_reflect(v); @@ -1751,7 +1729,7 @@ private: } currStartVertex += circle_type_to_vert_count(true); - vertices += circle_type_to_vert_count(true) * kVertexStride; + vertices += circle_type_to_vert_count(true) * vertexStride; } GrMesh mesh(GrPrimitiveType::kTriangles); @@ -1953,9 +1931,10 @@ private: sk_sp gp(new EllipseGeometryProcessor(fStroked, localMatrix)); QuadHelper helper; - SkASSERT(sizeof(EllipseVertex) == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(vertexStride == sizeof(EllipseVertex)); EllipseVertex* verts = reinterpret_cast( - helper.init(target, sizeof(EllipseVertex), fEllipses.count())); + helper.init(target, vertexStride, fEllipses.count())); if (!verts) { return; } @@ -2181,10 +2160,11 @@ private: sk_sp gp( new DIEllipseGeometryProcessor(this->viewMatrix(), this->style())); - SkASSERT(sizeof(DIEllipseVertex) == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(vertexStride == sizeof(DIEllipseVertex)); QuadHelper helper; DIEllipseVertex* verts = reinterpret_cast( - helper.init(target, sizeof(DIEllipseVertex), fEllipses.count())); + helper.init(target, vertexStride, fEllipses.count())); if (!verts) { return; } @@ -2595,13 +2575,14 @@ private: sk_sp gp( new CircleGeometryProcessor(!fAllFill, false, false, false, false, localMatrix)); - SkASSERT(sizeof(CircleVertex) == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(sizeof(CircleVertex) == vertexStride); const GrBuffer* vertexBuffer; int firstVertex; - CircleVertex* verts = (CircleVertex*)target->makeVertexSpace( - sizeof(CircleVertex), fVertCount, &vertexBuffer, &firstVertex); + CircleVertex* verts = (CircleVertex*)target->makeVertexSpace(vertexStride, fVertCount, + &vertexBuffer, &firstVertex); if (!verts) { SkDebugf("Could not allocate vertices\n"); return; @@ -2883,7 +2864,8 @@ private: // Setup geometry processor sk_sp gp(new EllipseGeometryProcessor(fStroked, localMatrix)); - SkASSERT(sizeof(EllipseVertex) == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(vertexStride == sizeof(EllipseVertex)); // drop out the middle quad if we're stroked int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerFillRRect; @@ -2892,8 +2874,8 @@ private: PatternHelper helper(GrPrimitiveType::kTriangles); EllipseVertex* verts = reinterpret_cast( - helper.init(target, sizeof(EllipseVertex), indexBuffer.get(), - kVertsPerStandardRRect, indicesPerInstance, fRRects.count())); + helper.init(target, vertexStride, indexBuffer.get(), kVertsPerStandardRRect, + indicesPerInstance, fRRects.count())); if (!verts || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); return; diff --git a/src/gpu/ops/GrRegionOp.cpp b/src/gpu/ops/GrRegionOp.cpp index 9a9814e0be..9e81d66730 100644 --- a/src/gpu/ops/GrRegionOp.cpp +++ b/src/gpu/ops/GrRegionOp.cpp @@ -115,8 +115,7 @@ private: SkDebugf("Couldn't create GrGeometryProcessor\n"); return; } - static constexpr size_t kVertexStride = sizeof(GrDefaultGeoProcFactory::PositionColorAttr); - SkASSERT(kVertexStride == gp->debugOnly_vertexStride()); + SkASSERT(gp->getVertexStride() == sizeof(GrDefaultGeoProcFactory::PositionColorAttr)); int numRegions = fRegions.count(); int numRects = 0; @@ -127,10 +126,12 @@ private: if (!numRects) { return; } + size_t vertexStride = gp->getVertexStride(); sk_sp indexBuffer = target->resourceProvider()->refQuadIndexBuffer(); PatternHelper helper(GrPrimitiveType::kTriangles); - void* vertices = helper.init(target, kVertexStride, indexBuffer.get(), kVertsPerInstance, - kIndicesPerInstance, numRects); + void* vertices = + helper.init(target, vertexStride, indexBuffer.get(), kVertsPerInstance, + kIndicesPerInstance, numRects); if (!vertices || !indexBuffer) { SkDebugf("Could not allocate vertices\n"); return; @@ -138,9 +139,9 @@ private: intptr_t verts = reinterpret_cast(vertices); for (int i = 0; i < numRegions; i++) { - tesselate_region(verts, kVertexStride, fRegions[i].fColor, fRegions[i].fRegion); + tesselate_region(verts, vertexStride, fRegions[i].fColor, fRegions[i].fRegion); int numRectsInRegion = fRegions[i].fRegion.computeRegionComplexity(); - verts += numRectsInRegion * kVertsPerInstance * kVertexStride; + verts += numRectsInRegion * kVertsPerInstance * vertexStride; } helper.recordDraw(target, gp.get(), fHelper.makePipeline(target)); } diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp index f6b2003710..a2ec23000d 100644 --- a/src/gpu/ops/GrShadowRRectOp.cpp +++ b/src/gpu/ops/GrShadowRRectOp.cpp @@ -576,12 +576,13 @@ private: sk_sp gp = GrRRectShadowGeoProc::Make(); int instanceCount = fGeoData.count(); - SkASSERT(sizeof(CircleVertex) == gp->debugOnly_vertexStride()); + size_t vertexStride = gp->getVertexStride(); + SkASSERT(sizeof(CircleVertex) == vertexStride); const GrBuffer* vertexBuffer; int firstVertex; - CircleVertex* verts = (CircleVertex*)target->makeVertexSpace( - sizeof(CircleVertex), fVertCount, &vertexBuffer, &firstVertex); + CircleVertex* verts = (CircleVertex*)target->makeVertexSpace(vertexStride, fVertCount, + &vertexBuffer, &firstVertex); if (!verts) { SkDebugf("Could not allocate vertices\n"); return; diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp index a0c9f9cf2b..4ffe47855e 100644 --- a/src/gpu/ops/GrSmallPathRenderer.cpp +++ b/src/gpu/ops/GrSmallPathRenderer.cpp @@ -351,9 +351,8 @@ private: } // allocate vertices - static constexpr size_t kVertexStride = - sizeof(SkPoint) + sizeof(GrColor) + 2 * sizeof(uint16_t); - SkASSERT(kVertexStride == flushInfo.fGeometryProcessor->debugOnly_vertexStride()); + size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride(); + SkASSERT(vertexStride == sizeof(SkPoint) + sizeof(GrColor) + 2*sizeof(uint16_t)); const GrBuffer* vertexBuffer; @@ -362,7 +361,7 @@ private: if (instanceCount > SK_MaxS32 / kVerticesPerQuad) { return; } - void* vertices = target->makeVertexSpace(kVertexStride, + void* vertices = target->makeVertexSpace(vertexStride, kVerticesPerQuad * instanceCount, &vertexBuffer, &flushInfo.fVertexOffset); @@ -477,9 +476,13 @@ private: auto uploadTarget = target->deferredUploadTarget(); fAtlas->setLastUseToken(shapeData->fID, uploadTarget->tokenTracker()->nextDrawToken()); - this->writePathVertices( - fAtlas, offset, args.fColor, kVertexStride, args.fViewMatrix, shapeData); - offset += kVerticesPerQuad * kVertexStride; + this->writePathVertices(fAtlas, + offset, + args.fColor, + vertexStride, + args.fViewMatrix, + shapeData); + offset += kVerticesPerQuad * vertexStride; flushInfo.fInstancesToFlush++; } diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp index 4c436c291d..51dac5adff 100644 --- a/src/gpu/ops/GrTessellatingPathRenderer.cpp +++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp @@ -237,7 +237,7 @@ private: return path; } - void draw(Target* target, const GrGeometryProcessor* gp, size_t vertexStride) { + void draw(Target* target, const GrGeometryProcessor* gp) { SkASSERT(!fAntiAlias); GrResourceProvider* rp = target->resourceProvider(); bool inverseFill = fShape.inverseFilled(); @@ -274,7 +274,7 @@ private: vmi.mapRect(&clipBounds); bool isLinear; bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags(); - StaticVertexAllocator allocator(vertexStride, rp, canMapVB); + StaticVertexAllocator allocator(gp->getVertexStride(), rp, canMapVB); int count = GrTessellator::PathToTriangles(getPath(), tol, clipBounds, &allocator, false, GrColor(), false, &isLinear); if (count == 0) { @@ -289,7 +289,7 @@ private: fShape.addGenIDChangeListener(sk_make_sp(key)); } - void drawAA(Target* target, const GrGeometryProcessor* gp, size_t vertexStride) { + void drawAA(Target* target, const GrGeometryProcessor* gp) { SkASSERT(fAntiAlias); SkPath path = getPath(); if (path.isEmpty()) { @@ -299,7 +299,7 @@ private: path.transform(fViewMatrix); SkScalar tol = GrPathUtils::kDefaultTolerance; bool isLinear; - DynamicVertexAllocator allocator(vertexStride, target); + DynamicVertexAllocator allocator(gp->getVertexStride(), target); int count = GrTessellator::PathToTriangles(path, tol, clipBounds, &allocator, true, fColor, fHelper.compatibleWithAlphaAsCoverage(), &isLinear); @@ -311,12 +311,9 @@ private: void onPrepareDraws(Target* target) override { sk_sp gp; - size_t vertexStride; { using namespace GrDefaultGeoProcFactory; - vertexStride = sizeof(SkPoint); // position - Color color(fColor); LocalCoords::Type localCoordsType = fHelper.usesLocalCoords() ? LocalCoords::kUsePosition_Type @@ -324,12 +321,10 @@ private: Coverage::Type coverageType; if (fAntiAlias) { color = Color(Color::kPremulGrColorAttribute_Type); - vertexStride += sizeof(uint32_t); if (fHelper.compatibleWithAlphaAsCoverage()) { coverageType = Coverage::kSolid_Type; } else { coverageType = Coverage::kAttribute_Type; - vertexStride += 4; } } else { coverageType = Coverage::kSolid_Type; @@ -345,11 +340,10 @@ private: if (!gp.get()) { return; } - SkASSERT(vertexStride == gp->debugOnly_vertexStride()); if (fAntiAlias) { - this->drawAA(target, gp.get(), vertexStride); + this->drawAA(target, gp.get()); } else { - this->draw(target, gp.get(), vertexStride); + this->draw(target, gp.get()); } } diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp index 95378ac969..80174bcb7d 100644 --- a/src/gpu/ops/GrTextureOp.cpp +++ b/src/gpu/ops/GrTextureOp.cpp @@ -163,14 +163,16 @@ public: args.fUniformHandler, textureGP.fTextureCoords.asShaderVar(), args.fFPCoordTransformHandler); - args.fVaryingHandler->addPassThroughAttribute( - textureGP.fColors, args.fOutputColor, Interpolation::kCanBeFlat); + args.fVaryingHandler->addPassThroughAttribute(&textureGP.fColors, + args.fOutputColor, + Interpolation::kCanBeFlat); args.fFragBuilder->codeAppend("float2 texCoord;"); - args.fVaryingHandler->addPassThroughAttribute(textureGP.fTextureCoords, "texCoord"); + args.fVaryingHandler->addPassThroughAttribute(&textureGP.fTextureCoords, + "texCoord"); if (textureGP.fDomain.isInitialized()) { args.fFragBuilder->codeAppend("float4 domain;"); args.fVaryingHandler->addPassThroughAttribute( - textureGP.fDomain, "domain", + &textureGP.fDomain, "domain", GrGLSLVaryingHandler::Interpolation::kCanBeFlat); args.fFragBuilder->codeAppend( "texCoord = clamp(texCoord, domain.xy, domain.zw);"); @@ -180,7 +182,7 @@ public: SkASSERT(kInt_GrVertexAttribType == textureGP.fTextureIdx.type()); SkASSERT(args.fShaderCaps->integerSupport()); args.fFragBuilder->codeAppend("int texIdx;"); - args.fVaryingHandler->addPassThroughAttribute(textureGP.fTextureIdx, "texIdx", + args.fVaryingHandler->addPassThroughAttribute(&textureGP.fTextureIdx, "texIdx", Interpolation::kMustBeFlat); args.fFragBuilder->codeAppend("switch (texIdx) {"); for (int i = 0; i < textureGP.numTextureSamplers(); ++i) { @@ -314,13 +316,12 @@ private: } if (perspective) { - fPositions = {"position", kFloat3_GrVertexAttribType}; + fPositions = this->addVertexAttrib("position", kFloat3_GrVertexAttribType); } else { - fPositions = {"position", kFloat2_GrVertexAttribType}; + fPositions = this->addVertexAttrib("position", kFloat2_GrVertexAttribType); } - fColors = {"color", kUByte4_norm_GrVertexAttribType}; - fTextureCoords = {"textureCoords", kFloat2_GrVertexAttribType}; - int vertexAttributeCnt = 3; + fColors = this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType); + fTextureCoords = this->addVertexAttrib("textureCoords", kFloat2_GrVertexAttribType); if (samplerCnt > 1) { // Here we initialize any extra samplers by repeating the last one samplerCnt - proxyCnt @@ -331,26 +332,17 @@ private: this->addTextureSampler(&fSamplers[i]); } SkASSERT(caps.integerSupport()); - fTextureIdx = {"textureIdx", kInt_GrVertexAttribType}; - ++vertexAttributeCnt; + fTextureIdx = this->addVertexAttrib("textureIdx", kInt_GrVertexAttribType); } if (domain == Domain::kYes) { - fDomain = {"domain", kFloat4_GrVertexAttribType}; - ++vertexAttributeCnt; + fDomain = this->addVertexAttrib("domain", kFloat4_GrVertexAttribType); } if (coverageAA) { - fAAEdges[0] = {"aaEdge0", kFloat3_GrVertexAttribType}; - fAAEdges[1] = {"aaEdge1", kFloat3_GrVertexAttribType}; - fAAEdges[2] = {"aaEdge2", kFloat3_GrVertexAttribType}; - fAAEdges[3] = {"aaEdge3", kFloat3_GrVertexAttribType}; - vertexAttributeCnt += 4; + fAAEdges[0] = this->addVertexAttrib("aaEdge0", kFloat3_GrVertexAttribType); + fAAEdges[1] = this->addVertexAttrib("aaEdge1", kFloat3_GrVertexAttribType); + fAAEdges[2] = this->addVertexAttrib("aaEdge2", kFloat3_GrVertexAttribType); + fAAEdges[3] = this->addVertexAttrib("aaEdge3", kFloat3_GrVertexAttribType); } - this->setVertexAttributeCnt(vertexAttributeCnt); - } - - const Attribute& onVertexAttribute(int i) const override { - return IthInitializedAttribute(i, fPositions, fColors, fTextureCoords, fTextureIdx, fDomain, - fAAEdges[0], fAAEdges[1], fAAEdges[2], fAAEdges[3]); } Attribute fPositions; @@ -752,7 +744,7 @@ __attribute__((no_sanitize("float-cast-overflow"))) template void tess(void* v, const float iw[], const float ih[], const GrGeometryProcessor* gp) { using Vertex = TextureGeometryProcessor::Vertex; - SkASSERT(gp->debugOnly_vertexStride() == sizeof(Vertex)); + SkASSERT(gp->getVertexStride() == sizeof(Vertex)); auto vertices = static_cast(v); auto proxies = this->proxies(); auto filters = this->filters(); @@ -793,47 +785,10 @@ __attribute__((no_sanitize("float-cast-overflow"))) const GrPipeline* pipeline = target->allocPipeline(args, GrProcessorSet::MakeEmptySet(), target->detachAppliedClip()); - using TessFn = - decltype(&TextureOp::tess); -#define TESS_FN_AND_VERTEX_SIZE(Point, MT, Domain, AA) \ - { \ - &TextureOp::tess, \ - sizeof(TextureGeometryProcessor::Vertex) \ - } - static constexpr struct { - TessFn fTessFn; - size_t fVertexSize; - } kTessFnsAndVertexSizes[] = { - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kYes), - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kYes), - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kYes), - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kYes), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kYes), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kYes), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kYes), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kNo), - TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kYes), - }; -#undef TESS_FN_AND_VERTEX_SIZE - int tessFnIdx = 0; - tessFnIdx |= coverageAA ? 0x1 : 0x0; - tessFnIdx |= fDomain ? 0x2 : 0x0; - tessFnIdx |= (fProxyCnt > 1) ? 0x4 : 0x0; - tessFnIdx |= fPerspective ? 0x8 : 0x0; - - SkASSERT(kTessFnsAndVertexSizes[tessFnIdx].fVertexSize == gp->debugOnly_vertexStride()); - int vstart; const GrBuffer* vbuffer; - void* vdata = target->makeVertexSpace(kTessFnsAndVertexSizes[tessFnIdx].fVertexSize, - 4 * fDraws.count(), &vbuffer, &vstart); + void* vdata = target->makeVertexSpace(gp->getVertexStride(), 4 * fDraws.count(), &vbuffer, + &vstart); if (!vdata) { SkDebugf("Could not allocate vertices\n"); return; @@ -847,7 +802,32 @@ __attribute__((no_sanitize("float-cast-overflow"))) ih[t] = 1.f / texture->height(); } - (this->*(kTessFnsAndVertexSizes[tessFnIdx].fTessFn))(vdata, iw, ih, gp.get()); + using TessFn = + decltype(&TextureOp::tess); + static constexpr TessFn kTessFns[] = { + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + &TextureOp::tess, + }; + int tessFnIdx = 0; + tessFnIdx |= coverageAA ? 0x1 : 0x0; + tessFnIdx |= fDomain ? 0x2 : 0x0; + tessFnIdx |= (fProxyCnt > 1) ? 0x4 : 0x0; + tessFnIdx |= fPerspective ? 0x8 : 0x0; + (this->*(kTessFns[tessFnIdx]))(vdata, iw, ih, gp.get()); GrPrimitiveType primitiveType = fDraws.count() > 1 ? GrPrimitiveType::kTriangles : GrPrimitiveType::kTriangleStrip; -- cgit v1.2.3