Move pipeline handling out of GrMeshDrawOp.

The monolithic GrPipeline is moved to a subclass GrLegacyDrawMeshOp.

The pipeline used to record a GrMesh draw in a GrMeshDrawOp must now be passed rather than implicitly using the op's pipeline.

Change-Id: I50d77e4dcc8d91a523fa7566ce43a9a291174706
Reviewed-on: https://skia-review.googlesource.com/11002
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/ops/GrMeshDrawOp.h b/src/gpu/ops/GrMeshDrawOp.h
index a8da29a..8daa62b 100644
--- a/src/gpu/ops/GrMeshDrawOp.h
+++ b/src/gpu/ops/GrMeshDrawOp.h
@@ -25,6 +25,77 @@
 public:
     class Target;
 
+protected:
+    GrMeshDrawOp(uint32_t classID);
+
+    /** Helper for rendering instances using an instanced index buffer. This class creates the space
+        for the vertices and flushes the draws to the GrMeshDrawOp::Target. */
+    class InstancedHelper {
+    public:
+        InstancedHelper() {}
+        /** Returns the allocated storage for the vertices. The caller should populate the vertices
+            before calling recordDraws(). */
+        void* init(Target*, GrPrimitiveType, size_t vertexStride, const GrBuffer*,
+                   int verticesPerInstance, int indicesPerInstance, int instancesToDraw);
+
+        /** Call after init() to issue draws to the GrMeshDrawOp::Target.*/
+        void recordDraw(Target*, const GrGeometryProcessor*, const GrPipeline*);
+
+    private:
+        GrMesh fMesh;
+    };
+
+    static const int kVerticesPerQuad = 4;
+    static const int kIndicesPerQuad = 6;
+
+    /** A specialization of InstanceHelper for quad rendering. */
+    class QuadHelper : private InstancedHelper {
+    public:
+        QuadHelper() : INHERITED() {}
+        /** Finds the cached quad index buffer and reserves vertex space. Returns nullptr on failure
+            and on success a pointer to the vertex data that the caller should populate before
+            calling recordDraws(). */
+        void* init(Target*, size_t vertexStride, int quadsToDraw);
+
+        using InstancedHelper::recordDraw;
+
+    private:
+        typedef InstancedHelper INHERITED;
+    };
+
+private:
+    void onPrepare(GrOpFlushState* state) final;
+    void onExecute(GrOpFlushState* state) final;
+
+    virtual void onPrepareDraws(Target*) const = 0;
+
+    // A set of contiguous draws that share a draw token and primitive processor. The draws all use
+    // the op's pipeline. The meshes for the draw are stored in the fMeshes array and each
+    // Queued draw uses fMeshCnt meshes from the fMeshes array. The reason for coallescing meshes
+    // that share a primitive processor into a QueuedDraw is that it allows the Gpu object to setup
+    // the shared state once and then issue draws for each mesh.
+    struct QueuedDraw {
+        int fMeshCnt = 0;
+        GrPendingProgramElement<const GrGeometryProcessor> fGeometryProcessor;
+        const GrPipeline* fPipeline;
+    };
+
+    // All draws in all the GrMeshDrawOps have implicit tokens based on the order they are enqueued
+    // globally across all ops. This is the offset of the first entry in fQueuedDraws.
+    // fQueuedDraws[i]'s token is fBaseDrawToken + i.
+    GrDrawOpUploadToken fBaseDrawToken;
+    SkSTArray<4, GrMesh> fMeshes;
+    SkSTArray<4, QueuedDraw, true> fQueuedDraws;
+
+    typedef GrDrawOp INHERITED;
+};
+
+/**
+ * Many of our ops derive from this class which initializes a GrPipeline just before being recorded.
+ * We are migrating away from use of this class.
+ */
+class GrLegacyMeshDrawOp : public GrMeshDrawOp {
+public:
     /**
      * Performs analysis of the fragment processors in GrProcessorSet and GrAppliedClip using the
      * initial color and coverage from this op's geometry processor.
@@ -49,19 +120,19 @@
      * the op is recorded. These methods are unnecessary as this information is in the pipeline.
      */
     FixedFunctionFlags fixedFunctionFlags() const override {
-        SkFAIL("This should never be called for mesh draw ops.");
+        SkFAIL("This should never be called for legacy mesh draw ops.");
         return FixedFunctionFlags::kNone;
     }
     bool xpRequiresDstTexture(const GrCaps&, const GrAppliedClip*) override {
-        SkFAIL("Should never be called for mesh draw ops.");
+        SkFAIL("Should never be called for legacy mesh draw ops.");
         return false;
     }
 
 protected:
-    GrMeshDrawOp(uint32_t classID);
+    GrLegacyMeshDrawOp(uint32_t classID) : INHERITED(classID) {}
     /**
-     * This is a legacy class only used by GrMeshDrawOp and will be removed. It presents some
-     * aspects of GrProcessorSet::Analysis to GrMeshDrawOp subclasses.
+     * This is a legacy class only used by GrLegacyMeshDrawOp and will be removed. It presents some
+     * aspects of GrProcessorSet::Analysis to GrLegacyMeshDrawOp subclasses.
      */
     class PipelineOptimizations {
     public:
@@ -116,41 +187,6 @@
         GrColor fOverrideColor;
     };
 
-    /** Helper for rendering instances using an instanced index index buffer. This class creates the
-        space for the vertices and flushes the draws to the GrMeshDrawOp::Target. */
-    class InstancedHelper {
-    public:
-        InstancedHelper() {}
-        /** Returns the allocated storage for the vertices. The caller should populate the vertices
-            before calling recordDraws(). */
-        void* init(Target*, GrPrimitiveType, size_t vertexStride, const GrBuffer*,
-                   int verticesPerInstance, int indicesPerInstance, int instancesToDraw);
-
-        /** Call after init() to issue draws to the GrMeshDrawOp::Target.*/
-        void recordDraw(Target*, const GrGeometryProcessor*);
-
-    private:
-        GrMesh fMesh;
-    };
-
-    static const int kVerticesPerQuad = 4;
-    static const int kIndicesPerQuad = 6;
-
-    /** A specialization of InstanceHelper for quad rendering. */
-    class QuadHelper : private InstancedHelper {
-    public:
-        QuadHelper() : INHERITED() {}
-        /** Finds the cached quad index buffer and reserves vertex space. Returns nullptr on failure
-            and on success a pointer to the vertex data that the caller should populate before
-            calling recordDraws(). */
-        void* init(Target*, size_t vertexStride, int quadsToDraw);
-
-        using InstancedHelper::recordDraw;
-
-    private:
-        typedef InstancedHelper INHERITED;
-    };
-
     const GrPipeline* pipeline() const {
         SkASSERT(fPipeline.isInitialized());
         return &fPipeline;
@@ -170,30 +206,9 @@
      */
     virtual void applyPipelineOptimizations(const PipelineOptimizations&) = 0;
 
-    void onPrepare(GrOpFlushState* state) final;
-    void onExecute(GrOpFlushState* state) final;
-
-    virtual void onPrepareDraws(Target*) const = 0;
-
-    // A set of contiguous draws that share a draw token and primitive processor. The draws all use
-    // the op's pipeline. The meshes for the draw are stored in the fMeshes array and each
-    // Queued draw uses fMeshCnt meshes from the fMeshes array. The reason for coallescing meshes
-    // that share a primitive processor into a QueuedDraw is that it allows the Gpu object to setup
-    // the shared state once and then issue draws for each mesh.
-    struct QueuedDraw {
-        int fMeshCnt = 0;
-        GrPendingProgramElement<const GrGeometryProcessor> fGeometryProcessor;
-    };
-
-    // All draws in all the GrMeshDrawOps have implicit tokens based on the order they are enqueued
-    // globally across all ops. This is the offset of the first entry in fQueuedDraws.
-    // fQueuedDraws[i]'s token is fBaseDrawToken + i.
-    GrDrawOpUploadToken fBaseDrawToken;
     GrPipeline fPipeline;
-    SkSTArray<4, GrMesh> fMeshes;
-    SkSTArray<4, QueuedDraw, true> fQueuedDraws;
 
-    typedef GrDrawOp INHERITED;
+    typedef GrMeshDrawOp INHERITED;
 };
 
 #endif