Add a writer class for indirect draw commands

This enforces write-only access to the mapped buffers, will enable
chaining of indirect strokes, and gives us the ability to reorder the
fields for Metal.

Bug: chromium:1172543
Bug: skia:11291
Bug: skia:10419
Change-Id: I4449ff85dd0019f6d6d6781ede52bcf26dee8b02
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367416
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Chris Dalton <csmartdalton@google.com>
diff --git a/src/gpu/GrBufferAllocPool.h b/src/gpu/GrBufferAllocPool.h
index ce4b02c..ad57668 100644
--- a/src/gpu/GrBufferAllocPool.h
+++ b/src/gpu/GrBufferAllocPool.h
@@ -14,6 +14,7 @@
 #include "include/private/SkTArray.h"
 #include "include/private/SkTDArray.h"
 #include "src/gpu/GrCpuBuffer.h"
+#include "src/gpu/GrDrawIndirectCommand.h"
 #include "src/gpu/GrNonAtomicRef.h"
 
 class GrGpu;
@@ -319,23 +320,23 @@
     GrDrawIndirectBufferAllocPool(GrGpu* gpu, sk_sp<CpuBufferCache> cpuBufferCache)
             : GrBufferAllocPool(gpu, GrGpuBufferType::kDrawIndirect, std::move(cpuBufferCache)) {}
 
-    GrDrawIndirectCommand* makeSpace(int drawCount, sk_sp<const GrBuffer>* buffer, size_t* offset) {
-        return static_cast<GrDrawIndirectCommand*>(this->GrBufferAllocPool::makeSpace(
-                (size_t)drawCount * sizeof(GrDrawIndirectCommand), 4, buffer, offset));
+    GrDrawIndirectWriter makeSpace(int drawCount, sk_sp<const GrBuffer>* buffer, size_t* offset) {
+        return this->GrBufferAllocPool::makeSpace(drawCount * sizeof(GrDrawIndirectCommand), 4,
+                                                  buffer, offset);
     }
 
     void putBack(int drawCount) {
-        this->GrBufferAllocPool::putBack((size_t)drawCount * sizeof(GrDrawIndirectCommand));
+        this->GrBufferAllocPool::putBack(drawCount * sizeof(GrDrawIndirectCommand));
     }
 
-    GrDrawIndexedIndirectCommand* makeIndexedSpace(int drawCount, sk_sp<const GrBuffer>* buffer,
-                                                   size_t* offset) {
-        return static_cast<GrDrawIndexedIndirectCommand*>(this->GrBufferAllocPool::makeSpace(
-                (size_t)drawCount * sizeof(GrDrawIndexedIndirectCommand), 4, buffer, offset));
+    GrDrawIndexedIndirectWriter makeIndexedSpace(int drawCount, sk_sp<const GrBuffer>* buffer,
+                                                 size_t* offset) {
+        return this->GrBufferAllocPool::makeSpace(
+                drawCount * sizeof(GrDrawIndexedIndirectCommand), 4, buffer, offset);
     }
 
     void putBackIndexed(int drawCount) {
-        this->GrBufferAllocPool::putBack((size_t)drawCount * sizeof(GrDrawIndexedIndirectCommand));
+        this->GrBufferAllocPool::putBack(drawCount * sizeof(GrDrawIndexedIndirectCommand));
     }
 
     using GrBufferAllocPool::unmap;