Extract a GrVertexChunkArray class with a builder

This will be used by the new stroke tessellator. All the other
tessellators should start chopping and chunking too. That will allow us
to quit cropping paths if we are afraid they might need more segments
than are supported.

Bug: chromium:1172543
Change-Id: I30f0ebb581f56cac099d8c05e0e181c4657c3db8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/390096
Commit-Queue: Chris Dalton <csmartdalton@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/mock/GrMockOpTarget.h b/src/gpu/mock/GrMockOpTarget.h
index 9564cf3..e3cb2f1 100644
--- a/src/gpu/mock/GrMockOpTarget.h
+++ b/src/gpu/mock/GrMockOpTarget.h
@@ -10,13 +10,20 @@
 
 #include "include/gpu/GrDirectContext.h"
 #include "src/gpu/GrDirectContextPriv.h"
+#include "src/gpu/GrGpu.h"
 #include "src/gpu/ops/GrMeshDrawOp.h"
 
 // This is a mock GrMeshDrawOp::Target implementation that just gives back pointers into
 // pre-allocated CPU buffers, rather than allocating and mapping GPU buffers.
 class GrMockOpTarget : public GrMeshDrawOp::Target {
 public:
-    GrMockOpTarget(sk_sp<GrDirectContext> mockContext) : fMockContext(std::move(mockContext)) {}
+    GrMockOpTarget(sk_sp<GrDirectContext> mockContext) : fMockContext(std::move(mockContext)) {
+        fStaticVertexBuffer = fMockContext->priv().getGpu()->createBuffer(
+                sizeof(fStaticVertexData), GrGpuBufferType::kVertex, kDynamic_GrAccessPattern);
+        fStaticIndirectBuffer = fMockContext->priv().getGpu()->createBuffer(
+                sizeof(fStaticIndirectData), GrGpuBufferType::kDrawIndirect,
+                kDynamic_GrAccessPattern);
+    }
     const GrDirectContext* mockContext() const { return fMockContext.get(); }
     const GrCaps& caps() const override { return *fMockContext->priv().caps(); }
     GrThreadSafeCache* threadSafeCache() const override {
@@ -34,23 +41,25 @@
     GrXferBarrierFlags renderPassBarriers() const override { return GrXferBarrierFlags::kNone; }
     GrLoadOp colorLoadOp() const override { return GrLoadOp::kLoad; }
 
-    void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
+    void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>* buffer,
                           int* startVertex) override {
         if (vertexSize * vertexCount > sizeof(fStaticVertexData)) {
             SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
                      vertexSize * vertexCount, sizeof(fStaticVertexData));
         }
+        *buffer = fStaticVertexBuffer;
         *startVertex = 0;
         return fStaticVertexData;
     }
 
     void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount,
-                                 sk_sp<const GrBuffer>*, int* startVertex,
+                                 sk_sp<const GrBuffer>* buffer, int* startVertex,
                                  int* actualVertexCount) override {
         if (vertexSize * minVertexCount > sizeof(fStaticVertexData)) {
             SK_ABORT("FATAL: wanted %zu bytes of static vertex data; only have %zu.\n",
                      vertexSize * minVertexCount, sizeof(fStaticVertexData));
         }
+        *buffer = fStaticVertexBuffer;
         *startVertex = 0;
         *actualVertexCount = sizeof(fStaticVertexData) / vertexSize;
         return fStaticVertexData;
@@ -62,6 +71,7 @@
             SK_ABORT("FATAL: wanted %zu bytes of static indirect data; only have %zu.\n",
                      sizeof(GrDrawIndirectCommand) * drawCount, sizeof(fStaticIndirectData));
         }
+        *buffer = fStaticIndirectBuffer;
         *offsetInBytes = 0;
         return fStaticIndirectData;
     }
@@ -75,6 +85,7 @@
             SK_ABORT("FATAL: wanted %zu bytes of static indirect data; only have %zu.\n",
                      sizeof(GrDrawIndexedIndirectCommand) * drawCount, sizeof(fStaticIndirectData));
         }
+        *buffer = fStaticIndirectBuffer;
         *offsetInBytes = 0;
         return fStaticIndirectData;
     }
@@ -103,7 +114,9 @@
 private:
     sk_sp<GrDirectContext> fMockContext;
     char fStaticVertexData[6 * 1024 * 1024];
+    sk_sp<GrGpuBuffer> fStaticVertexBuffer;
     char fStaticIndirectData[sizeof(GrDrawIndexedIndirectCommand) * 32];
+    sk_sp<GrGpuBuffer> fStaticIndirectBuffer;
     SkSTArenaAllocWithReset<1024 * 1024> fAllocator;
     GrXferProcessor::DstProxyView fDstProxyView;
 };