Switch GrMeshDrawOp::Target to be the stand alone GrMeshDrawTarget class
The Tessellator classes will survive in the NGA and they use
GrMeshDrawOp::Target - but GrMeshDrawOp will not survive.
This is a prelude to making all the remaining GrOp-derived classes OGA-only.
Bug: skia:11837
Change-Id: I62dc92e5f42d672342113f12dcedf3435fab993f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/419198
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrVertexChunkArray.cpp b/src/gpu/GrVertexChunkArray.cpp
new file mode 100644
index 0000000..27490f6
--- /dev/null
+++ b/src/gpu/GrVertexChunkArray.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2021 Google LLC.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "src/gpu/GrVertexChunkArray.h"
+
+#include "src/gpu/GrMeshDrawTarget.h"
+
+GrVertexChunkBuilder::~GrVertexChunkBuilder() {
+ if (!fChunks->empty()) {
+ fTarget->putBackVertices(fCurrChunkVertexCapacity - fCurrChunkVertexCount, fStride);
+ fChunks->back().fCount = fCurrChunkVertexCount;
+ }
+}
+
+bool GrVertexChunkBuilder::allocChunk(int minCount) {
+ if (!fChunks->empty()) {
+ // No need to put back vertices; the buffer is full.
+ fChunks->back().fCount = fCurrChunkVertexCount;
+ }
+ fCurrChunkVertexCount = 0;
+ GrVertexChunk* chunk = &fChunks->push_back();
+ int minAllocCount = std::max(minCount, fMinVerticesPerChunk);
+ fCurrChunkVertexWriter = {fTarget->makeVertexSpaceAtLeast(fStride, minAllocCount,
+ minAllocCount, &chunk->fBuffer,
+ &chunk->fBase,
+ &fCurrChunkVertexCapacity)};
+ if (!fCurrChunkVertexWriter || !chunk->fBuffer || fCurrChunkVertexCapacity < minCount) {
+ SkDebugf("WARNING: Failed to allocate vertex buffer for GrVertexChunk.\n");
+ fChunks->pop_back();
+ SkASSERT(fCurrChunkVertexCount == 0);
+ fCurrChunkVertexCapacity = 0;
+ return false;
+ }
+ fMinVerticesPerChunk *= 2;
+ return true;
+}