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 <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp
index 7e492b0..77f86c5 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<GrGeometryProcessor> 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<GrGeometryProcessor> 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<GrLegacyMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp,
-                                                    const SkRect& rect, GrColor color) {
-        return std::unique_ptr<GrLegacyMeshDrawOp>(new BezierCubicTestOp(gp, rect, color));
+    static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect,
+                                          GrColor color) {
+        return std::unique_ptr<GrDrawOp>(new BezierCubicTestOp(std::move(gp), rect, color));
     }
 
 private:
     BezierCubicTestOp(sk_sp<GrGeometryProcessor> 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<SkPoint*>(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<GrGeometryProcessor> fGeometryProcessor;
-
     static constexpr int kVertsPerCubic = 4;
     static constexpr int kIndicesPerCubic = 6;
 
-    typedef GrTestMeshDrawOp INHERITED;
+    typedef BezierTestOp INHERITED;
 };
 
 /**
@@ -169,8 +203,6 @@
                     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<GrGeometryProcessor> gp = GrCubicEffect::Make(color, SkMatrix::I(), klm,
@@ -180,11 +212,9 @@
                         break;
                     }
 
-                    std::unique_ptr<GrLegacyMeshDrawOp> op =
+                    std::unique_ptr<GrDrawOp> 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 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-class BezierConicTestOp : public GrTestMeshDrawOp {
+class BezierConicTestOp : public BezierTestOp {
 public:
     DEFINE_OP_CLASS_ID
 
     const char* name() const override { return "BezierConicTestOp"; }
 
-    static std::unique_ptr<GrLegacyMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp,
-                                                    const SkRect& rect, GrColor color,
-                                                    const SkMatrix& klm) {
-        return std::unique_ptr<GrLegacyMeshDrawOp>(new BezierConicTestOp(gp, rect, color, klm));
+    static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect,
+                                          GrColor color, const SkMatrix& klm) {
+        return std::unique_ptr<GrMeshDrawOp>(
+                new BezierConicTestOp(std::move(gp), rect, color, klm));
     }
 
 private:
     BezierConicTestOp(sk_sp<GrGeometryProcessor> 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 @@
 
     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<Vertex*>(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<GrGeometryProcessor> fGeometryProcessor;
 
     static constexpr int kVertsPerCubic = 4;
     static constexpr int kIndicesPerCubic = 6;
 
-    typedef GrTestMeshDrawOp INHERITED;
+    typedef BezierTestOp INHERITED;
 };
 
 
@@ -363,14 +389,8 @@
                     boundsPaint.setStyle(SkPaint::kStroke_Style);
                     canvas->drawRect(bounds, boundsPaint);
 
-                    GrPaint grPaint;
-                    grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));
-
-                    std::unique_ptr<GrLegacyMeshDrawOp> op =
-                            BezierConicTestOp::Make(gp, bounds, color, klm);
-
-                    renderTargetContext->priv().testingOnly_addLegacyMeshDrawOp(
-                            std::move(grPaint), GrAAType::kNone, std::move(op));
+                    std::unique_ptr<GrDrawOp> op = BezierConicTestOp::Make(gp, bounds, color, klm);
+                    renderTargetContext->priv().testingOnly_addDrawOp(std::move(op));
                 }
                 ++col;
                 if (numCols == col) {
@@ -427,24 +447,20 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-class BezierQuadTestOp : public GrTestMeshDrawOp {
+class BezierQuadTestOp : public BezierTestOp {
 public:
     DEFINE_OP_CLASS_ID
     const char* name() const override { return "BezierQuadTestOp"; }
 
-    static std::unique_ptr<GrLegacyMeshDrawOp> Make(sk_sp<GrGeometryProcessor> gp,
-                                                    const SkRect& rect, GrColor color,
-                                                    const GrPathUtils::QuadUVMatrix& devToUV) {
-        return std::unique_ptr<GrLegacyMeshDrawOp>(new BezierQuadTestOp(gp, rect, color, devToUV));
+    static std::unique_ptr<GrDrawOp> Make(sk_sp<GrGeometryProcessor> gp, const SkRect& rect,
+                                          GrColor color, const GrPathUtils::QuadUVMatrix& devToUV) {
+        return std::unique_ptr<GrDrawOp>(new BezierQuadTestOp(std::move(gp), rect, color, devToUV));
     }
 
 private:
     BezierQuadTestOp(sk_sp<GrGeometryProcessor> 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 @@
 
     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<Vertex*>(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<GrGeometryProcessor> fGeometryProcessor;
 
     static constexpr int kVertsPerCubic = 4;
     static constexpr int kIndicesPerCubic = 6;
 
-    typedef GrTestMeshDrawOp INHERITED;
+    typedef BezierTestOp INHERITED;
 };
 
 /**
@@ -584,11 +599,9 @@
 
                     GrPathUtils::QuadUVMatrix DevToUV(pts);
 
-                    std::unique_ptr<GrLegacyMeshDrawOp> op =
+                    std::unique_ptr<GrDrawOp> 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) {
diff --git a/src/gpu/GrProcessorSet.cpp b/src/gpu/GrProcessorSet.cpp
index 6c9e55d..152b97d 100644
--- a/src/gpu/GrProcessorSet.cpp
+++ b/src/gpu/GrProcessorSet.cpp
@@ -9,6 +9,7 @@
 #include "GrAppliedClip.h"
 #include "GrCaps.h"
 #include "GrXferProcessor.h"
+#include "SkBlendModePriv.h"
 #include "effects/GrPorterDuffXferProcessor.h"
 
 const GrProcessorSet& GrProcessorSet::EmptySet() {
@@ -36,6 +37,12 @@
     }
 }
 
+GrProcessorSet::GrProcessorSet(SkBlendMode mode)
+        : fXP(SkBlendMode_AsXPFactory(mode))
+        , fColorFragmentProcessorCnt(0)
+        , fFragmentProcessorOffset(0)
+        , fFlags(0) {}
+
 GrProcessorSet::~GrProcessorSet() {
     for (int i = fFragmentProcessorOffset; i < fFragmentProcessors.count(); ++i) {
         if (this->isFinalized()) {
diff --git a/src/gpu/GrProcessorSet.h b/src/gpu/GrProcessorSet.h
index 407d71e..a12a2ce 100644
--- a/src/gpu/GrProcessorSet.h
+++ b/src/gpu/GrProcessorSet.h
@@ -24,6 +24,7 @@
 
 public:
     GrProcessorSet(GrPaint&& paint);
+    GrProcessorSet(SkBlendMode mode);
 
     ~GrProcessorSet();