From b6e9d3c788ab2cf22df7e7d7e7b6aa212a8a3217 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Mon, 11 Feb 2019 14:29:34 -0500 Subject: [PATCH] Outline GrDrawAtlasOp and GrDrawVerticesOp This makes it easier to switch all the ops over to using a GrRecordingContext (and better matches what we do with all the other ops) Change-Id: Ie690975c31b8c9f4c7acebdc0185a145a0a263a5 Reviewed-on: https://skia-review.googlesource.com/c/191280 Commit-Queue: Robert Phillips Reviewed-by: Brian Salomon --- src/gpu/GrRenderTargetContext.cpp | 1 + src/gpu/ops/GrDrawAtlasOp.cpp | 94 +++++++++++-- src/gpu/ops/GrDrawAtlasOp.h | 78 +++-------- src/gpu/ops/GrDrawVerticesOp.cpp | 211 +++++++++++++++++++++++------- src/gpu/ops/GrDrawVerticesOp.h | 149 +++------------------ tools/gpu/GrTest.cpp | 8 +- 6 files changed, 287 insertions(+), 254 deletions(-) diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index e6975abd43..21bfebd94a 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -16,6 +16,7 @@ #include "GrDrawingManager.h" #include "GrFixedClip.h" #include "GrGpuResourcePriv.h" +#include "GrMemoryPool.h" #include "GrOpList.h" #include "GrPathRenderer.h" #include "GrQuad.h" diff --git a/src/gpu/ops/GrDrawAtlasOp.cpp b/src/gpu/ops/GrDrawAtlasOp.cpp index fdabd6456d..e1ee90cbbc 100644 --- a/src/gpu/ops/GrDrawAtlasOp.cpp +++ b/src/gpu/ops/GrDrawAtlasOp.cpp @@ -6,13 +6,71 @@ */ #include "GrDrawAtlasOp.h" + +#include "GrCaps.h" +#include "GrDefaultGeoProcFactory.h" #include "GrDrawOpTest.h" #include "GrOpFlushState.h" +#include "GrRecordingContext.h" +#include "GrRecordingContextPriv.h" +#include "GrSimpleMeshDrawOpHelper.h" #include "SkGr.h" #include "SkRSXform.h" #include "SkRandom.h" #include "SkRectPriv.h" +namespace { + +class DrawAtlasOp final : public GrMeshDrawOp { +private: + using Helper = GrSimpleMeshDrawOpHelper; + +public: + DEFINE_OP_CLASS_ID + + DrawAtlasOp(const Helper::MakeArgs&, const SkPMColor4f& color, + const SkMatrix& viewMatrix, GrAAType, int spriteCount, const SkRSXform* xforms, + const SkRect* rects, const SkColor* colors); + + const char* name() const override { return "DrawAtlasOp"; } + + void visitProxies(const VisitProxyFunc& func, VisitorType) const override { + fHelper.visitProxies(func); + } + +#ifdef SK_DEBUG + SkString dumpInfo() const override; +#endif + + FixedFunctionFlags fixedFunctionFlags() const override; + + GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override; + +private: + void onPrepareDraws(Target*) override; + + const SkPMColor4f& color() const { return fColor; } + const SkMatrix& viewMatrix() const { return fViewMatrix; } + bool hasColors() const { return fHasColors; } + int quadCount() const { return fQuadCount; } + + CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override; + + struct Geometry { + SkPMColor4f fColor; + SkTArray fVerts; + }; + + SkSTArray<1, Geometry, true> fGeoData; + Helper fHelper; + SkMatrix fViewMatrix; + SkPMColor4f fColor; + int fQuadCount; + bool fHasColors; + + typedef GrMeshDrawOp INHERITED; +}; + static sk_sp make_gp(const GrShaderCaps* shaderCaps, bool hasColors, const SkPMColor4f& color, @@ -27,9 +85,9 @@ static sk_sp make_gp(const GrShaderCaps* shaderCaps, LocalCoords::kHasExplicit_Type, viewMatrix); } -GrDrawAtlasOp::GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, - const SkMatrix& viewMatrix, GrAAType aaType, int spriteCount, - const SkRSXform* xforms, const SkRect* rects, const SkColor* colors) +DrawAtlasOp::DrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, + const SkMatrix& viewMatrix, GrAAType aaType, int spriteCount, + const SkRSXform* xforms, const SkRect* rects, const SkColor* colors) : INHERITED(ClassID()), fHelper(helperArgs, aaType), fColor(color) { SkASSERT(xforms); SkASSERT(rects); @@ -110,7 +168,7 @@ GrDrawAtlasOp::GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor } #ifdef SK_DEBUG -SkString GrDrawAtlasOp::dumpInfo() const { +SkString DrawAtlasOp::dumpInfo() const { SkString string; for (const auto& geo : fGeoData) { string.appendf("Color: 0x%08x, Quads: %d\n", geo.fColor.toBytes_RGBA(), @@ -122,7 +180,7 @@ SkString GrDrawAtlasOp::dumpInfo() const { } #endif -void GrDrawAtlasOp::onPrepareDraws(Target* target) { +void DrawAtlasOp::onPrepareDraws(Target* target) { // Setup geometry processor sk_sp gp(make_gp(target->caps().shaderCaps(), this->hasColors(), @@ -152,8 +210,8 @@ void GrDrawAtlasOp::onPrepareDraws(Target* target) { helper.recordDraw(target, std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState); } -GrOp::CombineResult GrDrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { - GrDrawAtlasOp* that = t->cast(); +GrOp::CombineResult DrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { + DrawAtlasOp* that = t->cast(); if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { return CombineResult::kCannotCombine; @@ -178,11 +236,11 @@ GrOp::CombineResult GrDrawAtlasOp::onCombineIfPossible(GrOp* t, const GrCaps& ca return CombineResult::kMerged; } -GrDrawOp::FixedFunctionFlags GrDrawAtlasOp::fixedFunctionFlags() const { +GrDrawOp::FixedFunctionFlags DrawAtlasOp::fixedFunctionFlags() const { return fHelper.fixedFunctionFlags(); } -GrProcessorSet::Analysis GrDrawAtlasOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) { +GrProcessorSet::Analysis DrawAtlasOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) { GrProcessorAnalysisColor gpColor; if (this->hasColors()) { gpColor.setToUnknown(); @@ -197,6 +255,22 @@ GrProcessorSet::Analysis GrDrawAtlasOp::finalize(const GrCaps& caps, const GrApp return result; } +} // anonymous namespace + +std::unique_ptr GrDrawAtlasOp::Make(GrContext* context, + GrPaint&& paint, + const SkMatrix& viewMatrix, + GrAAType aaType, + int spriteCount, + const SkRSXform* xforms, + const SkRect* rects, + const SkColor* colors) { + return GrSimpleMeshDrawOpHelper::FactoryHelper(context, std::move(paint), + viewMatrix, aaType, + spriteCount, xforms, + rects, colors); +} + #if GR_TEST_UTILS static SkRSXform random_xform(SkRandom* random) { @@ -240,7 +314,7 @@ static void randomize_params(uint32_t count, SkRandom* random, SkTArraynextRangeU(1, 100); SkTArray xforms(spriteCount); diff --git a/src/gpu/ops/GrDrawAtlasOp.h b/src/gpu/ops/GrDrawAtlasOp.h index 92820e9d6f..b3e654413e 100644 --- a/src/gpu/ops/GrDrawAtlasOp.h +++ b/src/gpu/ops/GrDrawAtlasOp.h @@ -8,71 +8,23 @@ #ifndef GrDrawAtlasOp_DEFINED #define GrDrawAtlasOp_DEFINED -#include "GrColor.h" -#include "GrDefaultGeoProcFactory.h" -#include "GrMeshDrawOp.h" -#include "GrSimpleMeshDrawOpHelper.h" +#include "GrTypesPriv.h" +#include "SkRefCnt.h" -class GrDrawAtlasOp final : public GrMeshDrawOp { -private: - using Helper = GrSimpleMeshDrawOpHelper; +class GrContext; +class GrDrawOp; +class GrPaint; +class SkMatrix; -public: - DEFINE_OP_CLASS_ID - - static std::unique_ptr Make(GrContext* context, - GrPaint&& paint, - const SkMatrix& viewMatrix, - GrAAType aaType, - int spriteCount, - const SkRSXform* xforms, - const SkRect* rects, - const SkColor* colors) { - return Helper::FactoryHelper(context, std::move(paint), viewMatrix, aaType, - spriteCount, xforms, rects, colors); - } - - GrDrawAtlasOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, - const SkMatrix& viewMatrix, GrAAType, int spriteCount, const SkRSXform* xforms, - const SkRect* rects, const SkColor* colors); - - const char* name() const override { return "DrawAtlasOp"; } - - void visitProxies(const VisitProxyFunc& func, VisitorType) const override { - fHelper.visitProxies(func); - } - -#ifdef SK_DEBUG - SkString dumpInfo() const override; -#endif - - FixedFunctionFlags fixedFunctionFlags() const override; - - GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override; - -private: - void onPrepareDraws(Target*) override; - - const SkPMColor4f& color() const { return fColor; } - const SkMatrix& viewMatrix() const { return fViewMatrix; } - bool hasColors() const { return fHasColors; } - int quadCount() const { return fQuadCount; } - - CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override; - - struct Geometry { - SkPMColor4f fColor; - SkTArray fVerts; - }; - - SkSTArray<1, Geometry, true> fGeoData; - Helper fHelper; - SkMatrix fViewMatrix; - SkPMColor4f fColor; - int fQuadCount; - bool fHasColors; - - typedef GrMeshDrawOp INHERITED; +namespace GrDrawAtlasOp { + std::unique_ptr Make(GrContext*, + GrPaint&&, + const SkMatrix& viewMatrix, + GrAAType, + int spriteCount, + const SkRSXform* xforms, + const SkRect* rects, + const SkColor* colors); }; #endif diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp index 1e46fc9e69..315a1ecd35 100644 --- a/src/gpu/ops/GrDrawVerticesOp.cpp +++ b/src/gpu/ops/GrDrawVerticesOp.cpp @@ -9,31 +9,132 @@ #include "GrCaps.h" #include "GrDefaultGeoProcFactory.h" #include "GrOpFlushState.h" +#include "GrSimpleMeshDrawOpHelper.h" #include "SkGr.h" #include "SkRectPriv.h" -std::unique_ptr GrDrawVerticesOp::Make(GrContext* context, - GrPaint&& paint, - sk_sp vertices, - const SkVertices::Bone bones[], - int boneCount, - const SkMatrix& viewMatrix, - GrAAType aaType, - sk_sp colorSpaceXform, - GrPrimitiveType* overridePrimType) { - SkASSERT(vertices); - GrPrimitiveType primType = overridePrimType ? *overridePrimType - : SkVertexModeToGrPrimitiveType(vertices->mode()); - return Helper::FactoryHelper(context, std::move(paint), std::move(vertices), - bones, boneCount, primType, aaType, - std::move(colorSpaceXform), viewMatrix); -} +namespace { -GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, - sk_sp vertices, const SkVertices::Bone bones[], - int boneCount, GrPrimitiveType primitiveType, GrAAType aaType, - sk_sp colorSpaceXform, - const SkMatrix& viewMatrix) +class DrawVerticesOp final : public GrMeshDrawOp { +private: + using Helper = GrSimpleMeshDrawOpHelper; + +public: + DEFINE_OP_CLASS_ID + + DrawVerticesOp(const Helper::MakeArgs&, const SkPMColor4f&, sk_sp, + const SkVertices::Bone bones[], int boneCount, GrPrimitiveType, GrAAType, + sk_sp, const SkMatrix& viewMatrix); + + const char* name() const override { return "DrawVerticesOp"; } + + void visitProxies(const VisitProxyFunc& func, VisitorType) const override { + fHelper.visitProxies(func); + } + +#ifdef SK_DEBUG + SkString dumpInfo() const override; +#endif + + FixedFunctionFlags fixedFunctionFlags() const override; + + GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override; + +private: + enum class ColorArrayType { + kPremulGrColor, + kSkColor, + }; + + void onPrepareDraws(Target*) override; + + void drawVolatile(Target*); + void drawNonVolatile(Target*); + + void fillBuffers(bool hasColorAttribute, + bool hasLocalCoordsAttribute, + size_t vertexStride, + void* verts, + uint16_t* indices) const; + + void drawVertices(Target*, + sk_sp, + sk_sp vertexBuffer, + int firstVertex, + sk_sp indexBuffer, + int firstIndex); + + sk_sp makeGP(const GrShaderCaps* shaderCaps, + bool* hasColorAttribute, + bool* hasLocalCoordAttribute) const; + + GrPrimitiveType primitiveType() const { return fPrimitiveType; } + bool combinablePrimitive() const { + return GrPrimitiveType::kTriangles == fPrimitiveType || + GrPrimitiveType::kLines == fPrimitiveType || + GrPrimitiveType::kPoints == fPrimitiveType; + } + + CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override; + + struct Mesh { + SkPMColor4f fColor; // Used if this->hasPerVertexColors() is false. + sk_sp fVertices; + SkMatrix fViewMatrix; + bool fIgnoreTexCoords; + bool fIgnoreColors; + + bool hasExplicitLocalCoords() const { + return fVertices->hasTexCoords() && !fIgnoreTexCoords; + } + + bool hasPerVertexColors() const { + return fVertices->hasColors() && !fIgnoreColors; + } + }; + + bool isIndexed() const { + // Consistency enforced in onCombineIfPossible. + return fMeshes[0].fVertices->hasIndices(); + } + + bool requiresPerVertexColors() const { + return SkToBool(kRequiresPerVertexColors_Flag & fFlags); + } + + bool anyMeshHasExplicitLocalCoords() const { + return SkToBool(kAnyMeshHasExplicitLocalCoords_Flag & fFlags); + } + + bool hasMultipleViewMatrices() const { + return SkToBool(kHasMultipleViewMatrices_Flag & fFlags); + } + + enum Flags { + kRequiresPerVertexColors_Flag = 0x1, + kAnyMeshHasExplicitLocalCoords_Flag = 0x2, + kHasMultipleViewMatrices_Flag = 0x4, + }; + + Helper fHelper; + SkSTArray<1, Mesh, true> fMeshes; + // GrPrimitiveType is more expressive than fVertices.mode() so it is used instead and we ignore + // the SkVertices mode (though fPrimitiveType may have been inferred from it). + GrPrimitiveType fPrimitiveType; + uint32_t fFlags; + int fVertexCount; + int fIndexCount; + ColorArrayType fColorArrayType; + sk_sp fColorSpaceXform; + + typedef GrMeshDrawOp INHERITED; +}; + +DrawVerticesOp::DrawVerticesOp(const Helper::MakeArgs& helperArgs, const SkPMColor4f& color, + sk_sp vertices, const SkVertices::Bone bones[], + int boneCount, GrPrimitiveType primitiveType, GrAAType aaType, + sk_sp colorSpaceXform, + const SkMatrix& viewMatrix) : INHERITED(ClassID()) , fHelper(helperArgs, aaType) , fPrimitiveType(primitiveType) @@ -89,7 +190,7 @@ GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, const SkP } #ifdef SK_DEBUG -SkString GrDrawVerticesOp::dumpInfo() const { +SkString DrawVerticesOp::dumpInfo() const { SkString string; string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n", (int)fPrimitiveType, fMeshes.count(), fVertexCount, fIndexCount); @@ -99,11 +200,11 @@ SkString GrDrawVerticesOp::dumpInfo() const { } #endif -GrDrawOp::FixedFunctionFlags GrDrawVerticesOp::fixedFunctionFlags() const { +GrDrawOp::FixedFunctionFlags DrawVerticesOp::fixedFunctionFlags() const { return fHelper.fixedFunctionFlags(); } -GrProcessorSet::Analysis GrDrawVerticesOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) { +GrProcessorSet::Analysis DrawVerticesOp::finalize(const GrCaps& caps, const GrAppliedClip* clip) { GrProcessorAnalysisColor gpColor; if (this->requiresPerVertexColors()) { gpColor.setToUnknown(); @@ -124,9 +225,9 @@ GrProcessorSet::Analysis GrDrawVerticesOp::finalize(const GrCaps& caps, const Gr return result; } -sk_sp GrDrawVerticesOp::makeGP(const GrShaderCaps* shaderCaps, - bool* hasColorAttribute, - bool* hasLocalCoordAttribute) const { +sk_sp DrawVerticesOp::makeGP(const GrShaderCaps* shaderCaps, + bool* hasColorAttribute, + bool* hasLocalCoordAttribute) const { using namespace GrDefaultGeoProcFactory; LocalCoords::Type localCoordsType; if (fHelper.usesLocalCoords()) { @@ -166,7 +267,7 @@ sk_sp GrDrawVerticesOp::makeGP(const GrShaderCaps* shaderCa vm); } -void GrDrawVerticesOp::onPrepareDraws(Target* target) { +void DrawVerticesOp::onPrepareDraws(Target* target) { bool hasMapBufferSupport = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags(); if (fMeshes[0].fVertices->isVolatile() || !hasMapBufferSupport) { this->drawVolatile(target); @@ -175,7 +276,7 @@ void GrDrawVerticesOp::onPrepareDraws(Target* target) { } } -void GrDrawVerticesOp::drawVolatile(Target* target) { +void DrawVerticesOp::drawVolatile(Target* target) { bool hasColorAttribute; bool hasLocalCoordsAttribute; sk_sp gp = this->makeGP(target->caps().shaderCaps(), @@ -215,7 +316,7 @@ void GrDrawVerticesOp::drawVolatile(Target* target) { firstIndex); } -void GrDrawVerticesOp::drawNonVolatile(Target* target) { +void DrawVerticesOp::drawNonVolatile(Target* target) { static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); bool hasColorAttribute; @@ -295,11 +396,11 @@ void GrDrawVerticesOp::drawNonVolatile(Target* target) { 0); } -void GrDrawVerticesOp::fillBuffers(bool hasColorAttribute, - bool hasLocalCoordsAttribute, - size_t vertexStride, - void* verts, - uint16_t* indices) const { +void DrawVerticesOp::fillBuffers(bool hasColorAttribute, + bool hasLocalCoordsAttribute, + size_t vertexStride, + void* verts, + uint16_t* indices) const { int instanceCount = fMeshes.count(); // Copy data into the buffers. @@ -387,12 +488,12 @@ void GrDrawVerticesOp::fillBuffers(bool hasColorAttribute, } } -void GrDrawVerticesOp::drawVertices(Target* target, - sk_sp gp, - sk_sp vertexBuffer, - int firstVertex, - sk_sp indexBuffer, - int firstIndex) { +void DrawVerticesOp::drawVertices(Target* target, + sk_sp gp, + sk_sp vertexBuffer, + int firstVertex, + sk_sp indexBuffer, + int firstIndex) { GrMesh* mesh = target->allocMesh(this->primitiveType()); if (this->isIndexed()) { mesh->setIndexed(std::move(indexBuffer), fIndexCount, firstIndex, 0, fVertexCount - 1, @@ -405,8 +506,8 @@ void GrDrawVerticesOp::drawVertices(Target* target, target->draw(std::move(gp), pipe.fPipeline, pipe.fFixedDynamicState, mesh); } -GrOp::CombineResult GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { - GrDrawVerticesOp* that = t->cast(); +GrOp::CombineResult DrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { + DrawVerticesOp* that = t->cast(); if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { return CombineResult::kCannotCombine; @@ -459,6 +560,28 @@ GrOp::CombineResult GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& return CombineResult::kMerged; } +} // anonymous namespace + +std::unique_ptr GrDrawVerticesOp::Make(GrContext* context, + GrPaint&& paint, + sk_sp vertices, + const SkVertices::Bone bones[], + int boneCount, + const SkMatrix& viewMatrix, + GrAAType aaType, + sk_sp colorSpaceXform, + GrPrimitiveType* overridePrimType) { + SkASSERT(vertices); + GrPrimitiveType primType = overridePrimType ? *overridePrimType + : SkVertexModeToGrPrimitiveType(vertices->mode()); + return GrSimpleMeshDrawOpHelper::FactoryHelper(context, std::move(paint), + std::move(vertices), + bones, boneCount, + primType, aaType, + std::move(colorSpaceXform), + viewMatrix); +} + /////////////////////////////////////////////////////////////////////////////////////////////////// #if GR_TEST_UTILS @@ -526,7 +649,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca } } -GR_DRAW_OP_TEST_DEFINE(GrDrawVerticesOp) { +GR_DRAW_OP_TEST_DEFINE(DrawVerticesOp) { GrPrimitiveType type; do { type = GrPrimitiveType(random->nextULessThan(kNumGrPrimitiveTypes)); diff --git a/src/gpu/ops/GrDrawVerticesOp.h b/src/gpu/ops/GrDrawVerticesOp.h index a42e52bf73..491b303d80 100644 --- a/src/gpu/ops/GrDrawVerticesOp.h +++ b/src/gpu/ops/GrDrawVerticesOp.h @@ -8,26 +8,16 @@ #ifndef GrDrawVerticesOp_DEFINED #define GrDrawVerticesOp_DEFINED -#include "GrColor.h" -#include "GrMeshDrawOp.h" -#include "GrRenderTargetContext.h" -#include "GrSimpleMeshDrawOpHelper.h" -#include "GrTypes.h" -#include "SkMatrix.h" -#include "SkRect.h" -#include "SkTDArray.h" +#include "GrTypesPriv.h" +#include "SkRefCnt.h" #include "SkVertices.h" -class GrOpFlushState; -class SkVertices; -struct GrInitInvariantOutput; +class GrColorSpaceXform; +class GrContext; +class GrDrawOp; +class GrPaint; -class GrDrawVerticesOp final : public GrMeshDrawOp { -private: - using Helper = GrSimpleMeshDrawOpHelper; - -public: - DEFINE_OP_CLASS_ID +namespace GrDrawVerticesOp { /** * Draw a SkVertices. The GrPaint param's color is used if the vertices lack per-vertex color. @@ -35,122 +25,15 @@ public: * primitive type drawn is derived from the SkVertices object, unless overridePrimType is * specified. */ - static std::unique_ptr Make(GrContext* context, - GrPaint&&, - sk_sp, - const SkVertices::Bone bones[], - int boneCount, - const SkMatrix& viewMatrix, - GrAAType, - sk_sp, - GrPrimitiveType* overridePrimType = nullptr); - - GrDrawVerticesOp(const Helper::MakeArgs&, const SkPMColor4f&, sk_sp, - const SkVertices::Bone bones[], int boneCount, GrPrimitiveType, GrAAType, - sk_sp, const SkMatrix& viewMatrix); - - const char* name() const override { return "DrawVerticesOp"; } - - void visitProxies(const VisitProxyFunc& func, VisitorType) const override { - fHelper.visitProxies(func); - } - -#ifdef SK_DEBUG - SkString dumpInfo() const override; -#endif - - FixedFunctionFlags fixedFunctionFlags() const override; - - GrProcessorSet::Analysis finalize(const GrCaps& caps, const GrAppliedClip* clip) override; - -private: - enum class ColorArrayType { - kPremulGrColor, - kSkColor, - }; - - void onPrepareDraws(Target*) override; - - void drawVolatile(Target*); - void drawNonVolatile(Target*); - - void fillBuffers(bool hasColorAttribute, - bool hasLocalCoordsAttribute, - size_t vertexStride, - void* verts, - uint16_t* indices) const; - - void drawVertices(Target*, - sk_sp, - sk_sp vertexBuffer, - int firstVertex, - sk_sp indexBuffer, - int firstIndex); - - sk_sp makeGP(const GrShaderCaps* shaderCaps, - bool* hasColorAttribute, - bool* hasLocalCoordAttribute) const; - - GrPrimitiveType primitiveType() const { return fPrimitiveType; } - bool combinablePrimitive() const { - return GrPrimitiveType::kTriangles == fPrimitiveType || - GrPrimitiveType::kLines == fPrimitiveType || - GrPrimitiveType::kPoints == fPrimitiveType; - } - - CombineResult onCombineIfPossible(GrOp* t, const GrCaps&) override; - - struct Mesh { - SkPMColor4f fColor; // Used if this->hasPerVertexColors() is false. - sk_sp fVertices; - SkMatrix fViewMatrix; - bool fIgnoreTexCoords; - bool fIgnoreColors; - - bool hasExplicitLocalCoords() const { - return fVertices->hasTexCoords() && !fIgnoreTexCoords; - } - - bool hasPerVertexColors() const { - return fVertices->hasColors() && !fIgnoreColors; - } - }; - - bool isIndexed() const { - // Consistency enforced in onCombineIfPossible. - return fMeshes[0].fVertices->hasIndices(); - } - - bool requiresPerVertexColors() const { - return SkToBool(kRequiresPerVertexColors_Flag & fFlags); - } - - bool anyMeshHasExplicitLocalCoords() const { - return SkToBool(kAnyMeshHasExplicitLocalCoords_Flag & fFlags); - } - - bool hasMultipleViewMatrices() const { - return SkToBool(kHasMultipleViewMatrices_Flag & fFlags); - } - - enum Flags { - kRequiresPerVertexColors_Flag = 0x1, - kAnyMeshHasExplicitLocalCoords_Flag = 0x2, - kHasMultipleViewMatrices_Flag = 0x4, - }; - - Helper fHelper; - SkSTArray<1, Mesh, true> fMeshes; - // GrPrimitiveType is more expressive than fVertices.mode() so it is used instead and we ignore - // the SkVertices mode (though fPrimitiveType may have been inferred from it). - GrPrimitiveType fPrimitiveType; - uint32_t fFlags; - int fVertexCount; - int fIndexCount; - ColorArrayType fColorArrayType; - sk_sp fColorSpaceXform; - - typedef GrMeshDrawOp INHERITED; + std::unique_ptr Make(GrContext*, + GrPaint&&, + sk_sp, + const SkVertices::Bone bones[], + int boneCount, + const SkMatrix& viewMatrix, + GrAAType, + sk_sp, + GrPrimitiveType* overridePrimType = nullptr); }; #endif diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index f697d95f95..6ce73a90ed 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -175,8 +175,8 @@ DRAW_OP_TEST_EXTERN(DIEllipseOp); DRAW_OP_TEST_EXTERN(EllipseOp); DRAW_OP_TEST_EXTERN(FillRectOp); DRAW_OP_TEST_EXTERN(GrAtlasTextOp); -DRAW_OP_TEST_EXTERN(GrDrawAtlasOp); -DRAW_OP_TEST_EXTERN(GrDrawVerticesOp); +DRAW_OP_TEST_EXTERN(DrawAtlasOp); +DRAW_OP_TEST_EXTERN(DrawVerticesOp); DRAW_OP_TEST_EXTERN(NonAALatticeOp); DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); DRAW_OP_TEST_EXTERN(ShadowRRectOp); @@ -201,8 +201,8 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext DRAW_OP_TEST_ENTRY(EllipseOp), DRAW_OP_TEST_ENTRY(FillRectOp), DRAW_OP_TEST_ENTRY(GrAtlasTextOp), - DRAW_OP_TEST_ENTRY(GrDrawAtlasOp), - DRAW_OP_TEST_ENTRY(GrDrawVerticesOp), + DRAW_OP_TEST_ENTRY(DrawAtlasOp), + DRAW_OP_TEST_ENTRY(DrawVerticesOp), DRAW_OP_TEST_ENTRY(NonAALatticeOp), DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp), DRAW_OP_TEST_ENTRY(ShadowRRectOp),