From c2f425440aca5b29b94e5921dbc02e56650ce651 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Wed, 12 Jul 2017 14:11:22 -0400 Subject: [PATCH] Make GrDrawVerticesOp a non-legacy GrMeshDrawOp Change-Id: I0e1e6815ed41764115bc84a5967b3da3be4ce147 Reviewed-on: https://skia-review.googlesource.com/22722 Commit-Queue: Brian Salomon Reviewed-by: Greg Daniel --- src/gpu/GrRenderTargetContext.cpp | 15 ++---- src/gpu/ops/GrDrawVerticesOp.cpp | 87 +++++++++++++++++-------------- src/gpu/ops/GrDrawVerticesOp.h | 66 +++++++++-------------- tools/gpu/GrTest.cpp | 4 +- 4 files changed, 82 insertions(+), 90 deletions(-) diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index c5fd414a48..842666810a 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -847,16 +847,11 @@ void GrRenderTargetContext::drawVertices(const GrClip& clip, AutoCheckFlush acf(this->drawingManager()); SkASSERT(vertices); - std::unique_ptr op = GrDrawVerticesOp::Make(paint.getColor(), - std::move(vertices), viewMatrix, - this->isGammaCorrect(), - fColorXformFromSRGB, - overridePrimType); - if (!op) { - return; - } - GrPipelineBuilder pipelineBuilder(std::move(paint), GrAAType::kNone); - this->addLegacyMeshDrawOp(std::move(pipelineBuilder), clip, std::move(op)); + GrAAType aaType = this->chooseAAType(GrAA::kNo, GrAllowMixedSamples::kNo); + std::unique_ptr op = + GrDrawVerticesOp::Make(std::move(paint), std::move(vertices), viewMatrix, aaType, + this->isGammaCorrect(), fColorXformFromSRGB, overridePrimType); + this->addDrawOp(clip, std::move(op)); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp index e872830797..771bd4ffb0 100644 --- a/src/gpu/ops/GrDrawVerticesOp.cpp +++ b/src/gpu/ops/GrDrawVerticesOp.cpp @@ -10,26 +10,28 @@ #include "GrOpFlushState.h" #include "SkGr.h" -std::unique_ptr GrDrawVerticesOp::Make(GrColor color, - sk_sp vertices, - const SkMatrix& viewMatrix, - bool gammaCorrect, - sk_sp colorSpaceXform, - GrPrimitiveType* overridePrimType) { +std::unique_ptr GrDrawVerticesOp::Make(GrPaint&& paint, + sk_sp vertices, + const SkMatrix& viewMatrix, + GrAAType aaType, + bool gammaCorrect, + sk_sp colorSpaceXform, + GrPrimitiveType* overridePrimType) { SkASSERT(vertices); GrPrimitiveType primType = overridePrimType ? *overridePrimType : SkVertexModeToGrPrimitiveType(vertices->mode()); - return std::unique_ptr(new GrDrawVerticesOp(std::move(vertices), primType, - color, gammaCorrect, - std::move(colorSpaceXform), - viewMatrix)); + return Helper::FactoryHelper(std::move(paint), std::move(vertices), primType, + aaType, gammaCorrect, std::move(colorSpaceXform), + viewMatrix); } -GrDrawVerticesOp::GrDrawVerticesOp(sk_sp vertices, GrPrimitiveType primitiveType, - GrColor color, bool gammaCorrect, +GrDrawVerticesOp::GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor color, + sk_sp vertices, GrPrimitiveType primitiveType, + GrAAType aaType, bool gammaCorrect, sk_sp colorSpaceXform, const SkMatrix& viewMatrix) : INHERITED(ClassID()) + , fHelper(helperArgs, aaType) , fPrimitiveType(primitiveType) , fColorSpaceXform(std::move(colorSpaceXform)) { SkASSERT(vertices); @@ -66,39 +68,47 @@ GrDrawVerticesOp::GrDrawVerticesOp(sk_sp vertices, GrPrimitiveType p this->setTransformedBounds(mesh.fVertices->bounds(), viewMatrix, HasAABloat::kNo, zeroArea); } -void GrDrawVerticesOp::getProcessorAnalysisInputs(GrProcessorAnalysisColor* color, - GrProcessorAnalysisCoverage* coverage) const { - if (this->requiresPerVertexColors()) { - color->setToUnknown(); - } else { - color->setToConstant(fMeshes[0].fColor); - } - *coverage = GrProcessorAnalysisCoverage::kNone; +SkString GrDrawVerticesOp::dumpInfo() const { + SkString string; + string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n", (int)fPrimitiveType, + fMeshes.count(), fVertexCount, fIndexCount); + string += fHelper.dumpInfo(); + string += INHERITED::dumpInfo(); + return string; } -void GrDrawVerticesOp::applyPipelineOptimizations(const PipelineOptimizations& optimizations) { - SkASSERT(fMeshes.count() == 1); - GrColor overrideColor; - if (optimizations.getOverrideColorIfSet(&overrideColor)) { - fMeshes[0].fColor = overrideColor; - fMeshes[0].fIgnoreColors = true; +GrDrawOp::FixedFunctionFlags GrDrawVerticesOp::fixedFunctionFlags() const { + return fHelper.fixedFunctionFlags(); +} + +GrDrawOp::RequiresDstTexture GrDrawVerticesOp::finalize(const GrCaps& caps, + const GrAppliedClip* clip) { + GrProcessorAnalysisColor gpColor; + if (this->requiresPerVertexColors()) { + gpColor.setToUnknown(); + } else { + gpColor.setToConstant(fMeshes.front().fColor); + } + auto result = + fHelper.xpRequiresDstTexture(caps, clip, GrProcessorAnalysisCoverage::kNone, &gpColor); + if (gpColor.isConstant(&fMeshes.front().fColor)) { + fMeshes.front().fIgnoreColors = true; fFlags &= ~kRequiresPerVertexColors_Flag; fColorArrayType = ColorArrayType::kPremulGrColor; fLinearizeColors = false; } - if (optimizations.readsLocalCoords()) { - fFlags |= kPipelineRequiresLocalCoords_Flag; - } else { + if (!fHelper.usesLocalCoords()) { fMeshes[0].fIgnoreTexCoords = true; fFlags &= ~kAnyMeshHasExplicitLocalCoords; } + return result; } sk_sp GrDrawVerticesOp::makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const { using namespace GrDefaultGeoProcFactory; LocalCoords::Type localCoordsType; - if (this->pipelineRequiresLocalCoords()) { + if (fHelper.usesLocalCoords()) { // If we have multiple view matrices we will transform the positions into device space. We // must then also provide untransformed positions as local coords. if (this->anyMeshHasExplicitLocalCoords() || this->hasMultipleViewMatrices()) { @@ -236,14 +246,13 @@ void GrDrawVerticesOp::onPrepareDraws(Target* target) const { mesh.setIndexed(indexBuffer, fIndexCount, firstIndex, 0, fVertexCount - 1); } mesh.setVertexData(vertexBuffer, firstVertex); - target->draw(gp.get(), this->pipeline(), mesh); + target->draw(gp.get(), fHelper.makePipeline(target), mesh); } bool GrDrawVerticesOp::onCombineIfPossible(GrOp* t, const GrCaps& caps) { GrDrawVerticesOp* that = t->cast(); - if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pipeline(), - that->bounds(), caps)) { + if (!fHelper.isCompatible(that->fHelper, caps, this->bounds(), that->bounds())) { return false; } @@ -361,7 +370,7 @@ static void randomize_params(size_t count, size_t maxVertex, SkScalar min, SkSca } } -GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(VerticesOp) { +GR_DRAW_OP_TEST_DEFINE(GrDrawVerticesOp) { GrPrimitiveType type; do { type = GrPrimitiveType(random->nextULessThan(kNumGrPrimitiveTypes)); @@ -397,7 +406,6 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(VerticesOp) { SkMatrix viewMatrix = GrTest::TestMatrix(random); - GrColor color = GrRandomColor(random); sk_sp colorSpaceXform = GrTest::TestColorXform(random); static constexpr SkVertices::VertexMode kIgnoredMode = SkVertices::kTriangles_VertexMode; @@ -405,9 +413,12 @@ GR_LEGACY_MESH_DRAW_OP_TEST_DEFINE(VerticesOp) { texCoords.begin(), colors.begin(), hasIndices ? indices.count() : 0, indices.begin()); - return std::unique_ptr( - new GrDrawVerticesOp(std::move(vertices), type, color, linearizeColors, - std::move(colorSpaceXform), viewMatrix)); + GrAAType aaType = GrAAType::kNone; + if (GrFSAAType::kUnifiedMSAA == fsaaType && random->nextBool()) { + aaType = GrAAType::kMSAA; + } + return GrDrawVerticesOp::Make(std::move(paint), std::move(vertices), viewMatrix, aaType, + linearizeColors, std::move(colorSpaceXform), &type); } #endif diff --git a/src/gpu/ops/GrDrawVerticesOp.h b/src/gpu/ops/GrDrawVerticesOp.h index 4ff19cc4c2..1242ffe4d0 100644 --- a/src/gpu/ops/GrDrawVerticesOp.h +++ b/src/gpu/ops/GrDrawVerticesOp.h @@ -11,46 +11,46 @@ #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 "SkVertices.h" -#if GR_TEST_UTILS -#include "GrDrawOpTest.h" -#endif - class GrOpFlushState; class SkVertices; struct GrInitInvariantOutput; -class GrDrawVerticesOp final : public GrLegacyMeshDrawOp { +class GrDrawVerticesOp final : public GrMeshDrawOp { +private: + using Helper = GrSimpleMeshDrawOpHelper; + public: DEFINE_OP_CLASS_ID /** - * Draw a SkVertices. The GrColor param is used if the vertices lack per-vertex color. If the - * vertices lack local coords then the vertex positions are used as local coords. The primitive - * type drawn is derived from the SkVertices object, unless overridePrimType is specified. - * If gammaCorrect is true, the vertex colors will be linearized in the shader to get correct - * rendering. + * Draw a SkVertices. The GrPaint param's color is used if the vertices lack per-vertex color. + * If the vertices lack local coords then the vertex positions are used as local coords. The + * primitive type drawn is derived from the SkVertices object, unless overridePrimType is + * specified. If gammaCorrect is true, the vertex colors will be linearized in the shader to get + * correct rendering. */ - static std::unique_ptr Make(GrColor color, sk_sp, - const SkMatrix& viewMatrix, bool gammaCorrect, - sk_sp colorSpaceXform, - GrPrimitiveType* overridePrimType = nullptr); + static std::unique_ptr Make(GrPaint&&, sk_sp, const SkMatrix& viewMatrix, + GrAAType, bool gammaCorrect, sk_sp, + GrPrimitiveType* overridePrimType = nullptr); + + GrDrawVerticesOp(const Helper::MakeArgs& helperArgs, GrColor, sk_sp, + GrPrimitiveType, GrAAType, bool gammaCorrect, sk_sp, + const SkMatrix& viewMatrix); const char* name() const override { return "DrawVerticesOp"; } - SkString dumpInfo() const override { - SkString string; - string.appendf("PrimType: %d, MeshCount %d, VCount: %d, ICount: %d\n", - (int) fPrimitiveType, fMeshes.count(), fVertexCount, fIndexCount); - string.append(DumpPipelineInfo(*this->pipeline())); - string.append(INHERITED::dumpInfo()); - return string; - } + SkString dumpInfo() const override; + + FixedFunctionFlags fixedFunctionFlags() const override; + + RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override; private: enum class ColorArrayType { @@ -58,12 +58,6 @@ private: kSkColor, }; - GrDrawVerticesOp(sk_sp, GrPrimitiveType, GrColor, bool gammaCorrect, - sk_sp, const SkMatrix& viewMatrix); - - void getProcessorAnalysisInputs(GrProcessorAnalysisColor* color, - GrProcessorAnalysisCoverage* coverage) const override; - void applyPipelineOptimizations(const PipelineOptimizations&) override; void onPrepareDraws(Target*) const override; sk_sp makeGP(bool* hasColorAttribute, bool* hasLocalCoordAttribute) const; @@ -106,10 +100,6 @@ private: return SkToBool(kAnyMeshHasExplicitLocalCoords & fFlags); } - bool pipelineRequiresLocalCoords() const { - return SkToBool(kPipelineRequiresLocalCoords_Flag & fFlags); - } - bool hasMultipleViewMatrices() const { return SkToBool(kHasMultipleViewMatrices_Flag & fFlags); } @@ -117,11 +107,12 @@ private: enum Flags { kRequiresPerVertexColors_Flag = 0x1, kAnyMeshHasExplicitLocalCoords = 0x2, - kPipelineRequiresLocalCoords_Flag = 0x4, - kHasMultipleViewMatrices_Flag = 0x8 + 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; @@ -131,13 +122,8 @@ private: ColorArrayType fColorArrayType; bool fLinearizeColors; sk_sp fColorSpaceXform; - SkSTArray<1, Mesh, true> fMeshes; - typedef GrLegacyMeshDrawOp INHERITED; - -#if GR_TEST_UTILS - GR_LEGACY_MESH_DRAW_OP_TEST_FRIEND(VerticesOp); -#endif + typedef GrMeshDrawOp INHERITED; }; #endif diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp index b28420bbb8..a5aeec41b7 100644 --- a/tools/gpu/GrTest.cpp +++ b/tools/gpu/GrTest.cpp @@ -317,7 +317,6 @@ LEGACY_MESH_DRAW_OP_TEST_EXTERN(AAFlatteningConvexPathOp); LEGACY_MESH_DRAW_OP_TEST_EXTERN(AnalyticRectOp); LEGACY_MESH_DRAW_OP_TEST_EXTERN(DefaultPathOp); LEGACY_MESH_DRAW_OP_TEST_EXTERN(TextBlobOp); -LEGACY_MESH_DRAW_OP_TEST_EXTERN(VerticesOp); DRAW_OP_TEST_EXTERN(AAConvexPathOp); DRAW_OP_TEST_EXTERN(AAFillRectOp); @@ -328,6 +327,7 @@ DRAW_OP_TEST_EXTERN(DashOp); DRAW_OP_TEST_EXTERN(DIEllipseOp); DRAW_OP_TEST_EXTERN(EllipseOp); DRAW_OP_TEST_EXTERN(GrDrawAtlasOp); +DRAW_OP_TEST_EXTERN(GrDrawVerticesOp); DRAW_OP_TEST_EXTERN(NonAAFillRectOp); DRAW_OP_TEST_EXTERN(NonAALatticeOp); DRAW_OP_TEST_EXTERN(NonAAStrokeRectOp); @@ -345,7 +345,6 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext DRAW_OP_TEST_ENTRY(AnalyticRectOp), DRAW_OP_TEST_ENTRY(DefaultPathOp), DRAW_OP_TEST_ENTRY(TextBlobOp), - DRAW_OP_TEST_ENTRY(VerticesOp) }; using MakeDrawOpFn = std::unique_ptr(GrPaint&&, SkRandom*, GrContext*, GrFSAAType); @@ -359,6 +358,7 @@ void GrDrawRandomOp(SkRandom* random, GrRenderTargetContext* renderTargetContext DRAW_OP_TEST_ENTRY(DIEllipseOp), DRAW_OP_TEST_ENTRY(EllipseOp), DRAW_OP_TEST_ENTRY(GrDrawAtlasOp), + DRAW_OP_TEST_ENTRY(GrDrawVerticesOp), DRAW_OP_TEST_ENTRY(NonAAFillRectOp), DRAW_OP_TEST_ENTRY(NonAALatticeOp), DRAW_OP_TEST_ENTRY(NonAAStrokeRectOp),