Add a drawPaths method to GrCCPathProcessor

Bug: skia:
Change-Id: I5d3762203cbe1d823ea3f3967240bcab76651f2c
Reviewed-on: https://skia-review.googlesource.com/126662
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/ccpr/GrCCPathProcessor.cpp b/src/gpu/ccpr/GrCCPathProcessor.cpp
index 55cbcab..5dacc6a 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.cpp
+++ b/src/gpu/ccpr/GrCCPathProcessor.cpp
@@ -7,6 +7,7 @@
 
 #include "GrCCPathProcessor.h"
 
+#include "GrGpuCommandBuffer.h"
 #include "GrOnFlushResourceProvider.h"
 #include "GrTexture.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
@@ -74,11 +75,6 @@
     }
 }
 
-int GrCCPathProcessor::NumIndicesPerInstance(const GrCaps& caps) {
-    return caps.usePrimitiveRestart() ? SK_ARRAY_COUNT(kOctoIndicesAsStrips)
-                                      : SK_ARRAY_COUNT(kOctoIndicesAsTris);
-}
-
 GrCCPathProcessor::GrCCPathProcessor(GrResourceProvider* resourceProvider,
                                      sk_sp<GrTextureProxy> atlas, SkPath::FillType fillType)
         : INHERITED(kGrCCPathProcessor_ClassID)
@@ -144,6 +140,25 @@
     return new GLSLPathProcessor();
 }
 
+void GrCCPathProcessor::drawPaths(GrOpFlushState* flushState, const GrPipeline& pipeline,
+                                  const GrBuffer* indexBuffer, const GrBuffer* vertexBuffer,
+                                  GrBuffer* instanceBuffer, int baseInstance, int endInstance,
+                                  const SkRect& bounds) const {
+    const GrCaps& caps = flushState->caps();
+    GrPrimitiveType primitiveType = caps.usePrimitiveRestart()
+                                            ? GrPrimitiveType::kTriangleStrip
+                                            : GrPrimitiveType::kTriangles;
+    int numIndicesPerInstance = caps.usePrimitiveRestart()
+                                        ? SK_ARRAY_COUNT(kOctoIndicesAsStrips)
+                                        : SK_ARRAY_COUNT(kOctoIndicesAsTris);
+    GrMesh mesh(primitiveType);
+    mesh.setIndexedInstanced(indexBuffer, numIndicesPerInstance, instanceBuffer,
+                             endInstance - baseInstance, baseInstance);
+    mesh.setVertexData(vertexBuffer);
+
+    flushState->rtCommandBuffer()->draw(pipeline, *this, &mesh, nullptr, 1, bounds);
+}
+
 void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
     using InstanceAttribs = GrCCPathProcessor::InstanceAttribs;
     using Interpolation = GrGLSLVaryingHandler::Interpolation;
diff --git a/src/gpu/ccpr/GrCCPathProcessor.h b/src/gpu/ccpr/GrCCPathProcessor.h
index 644fbba..40b16a4 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.h
+++ b/src/gpu/ccpr/GrCCPathProcessor.h
@@ -14,6 +14,8 @@
 #include <array>
 
 class GrOnFlushResourceProvider;
+class GrOpFlushState;
+class GrPipeline;
 
 /**
  * This class draws AA paths using the coverage count masks produced by GrCCCoverageProcessor.
@@ -21,8 +23,9 @@
  * Paths are drawn as bloated octagons, and coverage is derived from the coverage count mask and
  * fill rule.
  *
- * The caller must set up an instance buffer as detailed below, then draw indexed-instanced
- * meshes using the buffers and parameters provided by this class.
+ * To draw paths, the caller must set up an instance buffer as detailed below, then call drawPaths()
+ * providing its own instance buffer alongside the buffers found by calling FindIndexBuffer/
+ * FindVertexBuffer.
  */
 class GrCCPathProcessor : public GrGeometryProcessor {
 public:
@@ -50,13 +53,8 @@
 
     GR_STATIC_ASSERT(4 * 16 == sizeof(Instance));
 
-    static GrPrimitiveType MeshPrimitiveType(const GrCaps& caps) {
-        return caps.usePrimitiveRestart() ? GrPrimitiveType::kTriangleStrip
-                                          : GrPrimitiveType::kTriangles;
-    }
     static sk_sp<const GrBuffer> FindVertexBuffer(GrOnFlushResourceProvider*);
     static sk_sp<const GrBuffer> FindIndexBuffer(GrOnFlushResourceProvider*);
-    static int NumIndicesPerInstance(const GrCaps&);
 
     GrCCPathProcessor(GrResourceProvider*, sk_sp<GrTextureProxy> atlas, SkPath::FillType);
 
@@ -79,6 +77,10 @@
     void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
     GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
 
+    void drawPaths(GrOpFlushState*, const GrPipeline&, const GrBuffer* indexBuffer,
+                   const GrBuffer* vertexBuffer, GrBuffer* instanceBuffer, int baseInstance,
+                   int endInstance, const SkRect& bounds) const;
+
 private:
     const SkPath::FillType fFillType;
     const TextureSampler fAtlasAccess;
diff --git a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
index fa08af5..2634896 100644
--- a/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
+++ b/src/gpu/ccpr/GrCoverageCountingPathRenderer.cpp
@@ -511,15 +511,9 @@
 
         GrCCPathProcessor pathProc(flushState->resourceProvider(),
                                    sk_ref_sp(batch.fAtlas->textureProxy()), this->getFillType());
-
-        GrMesh mesh(GrCCPathProcessor::MeshPrimitiveType(flushState->caps()));
-        mesh.setIndexedInstanced(fCCPR->fPerFlushIndexBuffer.get(),
-                                 GrCCPathProcessor::NumIndicesPerInstance(flushState->caps()),
-                                 fCCPR->fPerFlushInstanceBuffer.get(),
-                                 batch.fEndInstanceIdx - baseInstance, baseInstance);
-        mesh.setVertexData(fCCPR->fPerFlushVertexBuffer.get());
-
-        flushState->rtCommandBuffer()->draw(pipeline, pathProc, &mesh, nullptr, 1, this->bounds());
+        pathProc.drawPaths(flushState, pipeline, fCCPR->fPerFlushIndexBuffer.get(),
+                           fCCPR->fPerFlushVertexBuffer.get(), fCCPR->fPerFlushInstanceBuffer.get(),
+                           baseInstance, batch.fEndInstanceIdx, this->bounds());
     }
 
     SkASSERT(baseInstance == fBaseInstance + fInstanceCount - fNumSkippedInstances);