From 477d0efcf2d90c70a87c5a126349e76ac57d9649 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Fri, 14 Jul 2017 10:12:26 -0400 Subject: Make ops in bezier_effects GMs be non-Legacy GrMeshDrawOps Change-Id: I1d56536820a61af293a7bce290f35b724c3a8257 Reviewed-on: https://skia-review.googlesource.com/23480 Reviewed-by: Greg Daniel Commit-Queue: Brian Salomon --- gm/beziereffects.cpp | 149 ++++++++++++++++++++++++++++----------------------- 1 file changed, 81 insertions(+), 68 deletions(-) (limited to 'gm/beziereffects.cpp') diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp index 7e492b0ca2..77f86c5ea4 100644 --- a/gm/beziereffects.cpp +++ b/gm/beziereffects.cpp @@ -11,56 +11,90 @@ #if SK_SUPPORT_GPU -#include "GrRenderTargetContextPriv.h" #include "GrContext.h" +#include "GrOpFlushState.h" #include "GrPathUtils.h" +#include "GrRenderTargetContextPriv.h" #include "GrTest.h" #include "SkColorPriv.h" #include "SkGeometry.h" - -#include "ops/GrTestMeshDrawOp.h" - #include "effects/GrBezierEffect.h" +#include "ops/GrMeshDrawOp.h" namespace skiagm { -class BezierCubicTestOp : public GrTestMeshDrawOp { +class BezierTestOp : public GrMeshDrawOp { +public: + FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; } + + RequiresDstTexture finalize(const GrCaps& caps, const GrAppliedClip* clip) override { + auto analysis = fProcessorSet.finalize(fColor, GrProcessorAnalysisCoverage::kSingleChannel, + clip, false, caps, &fColor); + return analysis.requiresDstTexture() ? RequiresDstTexture::kYes : RequiresDstTexture::kNo; + } + +protected: + BezierTestOp(sk_sp gp, const SkRect& rect, GrColor color, int32_t classID) + : INHERITED(classID) + , fRect(rect) + , fColor(color) + , fGeometryProcessor(std::move(gp)) + , fProcessorSet(SkBlendMode::kSrc) { + this->setBounds(rect, HasAABloat::kYes, IsZeroArea::kNo); + } + + const GrPipeline* makePipeline(Target* target) const { + return target->makePipeline(0, &fProcessorSet); + } + + const GrGeometryProcessor* gp() const { return fGeometryProcessor.get(); } + + const SkRect& rect() const { return fRect; } + GrColor color() const { return fColor; } + +private: + bool onCombineIfPossible(GrOp* op, const GrCaps& caps) override { return false; } + + SkRect fRect; + GrColor fColor; + sk_sp fGeometryProcessor; + GrProcessorSet fProcessorSet; + + typedef GrMeshDrawOp INHERITED; +}; + +class BezierCubicTestOp : public BezierTestOp { public: DEFINE_OP_CLASS_ID const char* name() const override { return "BezierCubicTestOp"; } - static std::unique_ptr Make(sk_sp gp, - const SkRect& rect, GrColor color) { - return std::unique_ptr(new BezierCubicTestOp(gp, rect, color)); + static std::unique_ptr Make(sk_sp gp, const SkRect& rect, + GrColor color) { + return std::unique_ptr(new BezierCubicTestOp(std::move(gp), rect, color)); } private: BezierCubicTestOp(sk_sp gp, const SkRect& rect, GrColor color) - : INHERITED(ClassID(), rect, color) - , fRect(rect) - , fGeometryProcessor(std::move(gp)) { - } + : INHERITED(std::move(gp), rect, color, ClassID()) {} void onPrepareDraws(Target* target) const override { QuadHelper helper; - size_t vertexStride = fGeometryProcessor->getVertexStride(); + size_t vertexStride = this->gp()->getVertexStride(); SkASSERT(vertexStride == sizeof(SkPoint)); SkPoint* pts = reinterpret_cast(helper.init(target, vertexStride, 1)); if (!pts) { return; } - pts[0].setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, vertexStride); - helper.recordDraw(target, fGeometryProcessor.get(), this->pipeline()); + SkRect rect = this->rect(); + pts[0].setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vertexStride); + helper.recordDraw(target, this->gp(), this->makePipeline(target)); } - SkRect fRect; - sk_sp fGeometryProcessor; - static constexpr int kVertsPerCubic = 4; static constexpr int kIndicesPerCubic = 6; - typedef GrTestMeshDrawOp INHERITED; + typedef BezierTestOp INHERITED; }; /** @@ -169,8 +203,6 @@ protected: boundsPaint.setStyle(SkPaint::kStroke_Style); canvas->drawRect(bounds, boundsPaint); - GrPaint grPaint; - grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); bool flipKL = (c == loopIndex && cnt != 3); sk_sp gp = GrCubicEffect::Make(color, SkMatrix::I(), klm, @@ -180,11 +212,9 @@ protected: break; } - std::unique_ptr op = + std::unique_ptr op = BezierCubicTestOp::Make(std::move(gp), bounds, color); - - renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp( - std::move(grPaint), GrAAType::kNone, std::move(op)); + renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); } ++col; if (numCols == col) { @@ -201,26 +231,23 @@ private: ////////////////////////////////////////////////////////////////////////////// -class BezierConicTestOp : public GrTestMeshDrawOp { +class BezierConicTestOp : public BezierTestOp { public: DEFINE_OP_CLASS_ID const char* name() const override { return "BezierConicTestOp"; } - static std::unique_ptr Make(sk_sp gp, - const SkRect& rect, GrColor color, - const SkMatrix& klm) { - return std::unique_ptr(new BezierConicTestOp(gp, rect, color, klm)); + static std::unique_ptr Make(sk_sp gp, const SkRect& rect, + GrColor color, const SkMatrix& klm) { + return std::unique_ptr( + new BezierConicTestOp(std::move(gp), rect, color, klm)); } private: BezierConicTestOp(sk_sp gp, const SkRect& rect, GrColor color, const SkMatrix& klm) - : INHERITED(ClassID(), rect, color) - , fKLM(klm) - , fRect(rect) - , fGeometryProcessor(std::move(gp)) { - } + : INHERITED(std::move(gp), rect, color, ClassID()), fKLM(klm) {} + struct Vertex { SkPoint fPosition; float fKLM[4]; // The last value is ignored. The effect expects a vec4f. @@ -228,29 +255,28 @@ private: void onPrepareDraws(Target* target) const override { QuadHelper helper; - size_t vertexStride = fGeometryProcessor->getVertexStride(); + size_t vertexStride = this->gp()->getVertexStride(); SkASSERT(vertexStride == sizeof(Vertex)); Vertex* verts = reinterpret_cast(helper.init(target, vertexStride, 1)); if (!verts) { return; } - verts[0].fPosition.setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, + SkRect rect = this->rect(); + verts[0].fPosition.setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, sizeof(Vertex)); for (int v = 0; v < 4; ++v) { SkScalar pt3[3] = {verts[v].fPosition.x(), verts[v].fPosition.y(), 1.f}; fKLM.mapHomogeneousPoints(verts[v].fKLM, pt3, 1); } - helper.recordDraw(target, fGeometryProcessor.get(), this->pipeline()); + helper.recordDraw(target, this->gp(), this->makePipeline(target)); } SkMatrix fKLM; - SkRect fRect; - sk_sp fGeometryProcessor; static constexpr int kVertsPerCubic = 4; static constexpr int kIndicesPerCubic = 6; - typedef GrTestMeshDrawOp INHERITED; + typedef BezierTestOp INHERITED; }; @@ -363,14 +389,8 @@ protected: boundsPaint.setStyle(SkPaint::kStroke_Style); canvas->drawRect(bounds, boundsPaint); - GrPaint grPaint; - grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); - - std::unique_ptr op = - BezierConicTestOp::Make(gp, bounds, color, klm); - - renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp( - std::move(grPaint), GrAAType::kNone, std::move(op)); + std::unique_ptr op = BezierConicTestOp::Make(gp, bounds, color, klm); + renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); } ++col; if (numCols == col) { @@ -427,24 +447,20 @@ private: ////////////////////////////////////////////////////////////////////////////// -class BezierQuadTestOp : public GrTestMeshDrawOp { +class BezierQuadTestOp : public BezierTestOp { public: DEFINE_OP_CLASS_ID const char* name() const override { return "BezierQuadTestOp"; } - static std::unique_ptr Make(sk_sp gp, - const SkRect& rect, GrColor color, - const GrPathUtils::QuadUVMatrix& devToUV) { - return std::unique_ptr(new BezierQuadTestOp(gp, rect, color, devToUV)); + static std::unique_ptr Make(sk_sp gp, const SkRect& rect, + GrColor color, const GrPathUtils::QuadUVMatrix& devToUV) { + return std::unique_ptr(new BezierQuadTestOp(std::move(gp), rect, color, devToUV)); } private: BezierQuadTestOp(sk_sp gp, const SkRect& rect, GrColor color, const GrPathUtils::QuadUVMatrix& devToUV) - : INHERITED(ClassID(), rect, color) - , fDevToUV(devToUV) - , fRect(rect) - , fGeometryProcessor(std::move(gp)) {} + : INHERITED(std::move(gp), rect, color, ClassID()), fDevToUV(devToUV) {} struct Vertex { SkPoint fPosition; @@ -453,26 +469,25 @@ private: void onPrepareDraws(Target* target) const override { QuadHelper helper; - size_t vertexStride = fGeometryProcessor->getVertexStride(); + size_t vertexStride = this->gp()->getVertexStride(); SkASSERT(vertexStride == sizeof(Vertex)); Vertex* verts = reinterpret_cast(helper.init(target, vertexStride, 1)); if (!verts) { return; } - verts[0].fPosition.setRectFan(fRect.fLeft, fRect.fTop, fRect.fRight, fRect.fBottom, + SkRect rect = this->rect(); + verts[0].fPosition.setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, sizeof(Vertex)); fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts); - helper.recordDraw(target, fGeometryProcessor.get(), this->pipeline()); + helper.recordDraw(target, this->gp(), this->makePipeline(target)); } GrPathUtils::QuadUVMatrix fDevToUV; - SkRect fRect; - sk_sp fGeometryProcessor; static constexpr int kVertsPerCubic = 4; static constexpr int kIndicesPerCubic = 6; - typedef GrTestMeshDrawOp INHERITED; + typedef BezierTestOp INHERITED; }; /** @@ -584,11 +599,9 @@ protected: GrPathUtils::QuadUVMatrix DevToUV(pts); - std::unique_ptr op = + std::unique_ptr op = BezierQuadTestOp::Make(gp, bounds, color, DevToUV); - - renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp( - std::move(grPaint), GrAAType::kNone, std::move(op)); + renderTargetContext->priv().testingOnly_addDrawOp(std::move(op)); } ++col; if (numCols == col) { -- cgit v1.2.3