blob: 27490f6469fa0e6b39842ad2f641efef3761134e [file] [log] [blame]
Robert Phillips71143952021-06-17 14:55:07 -04001/*
2 * Copyright 2021 Google LLC.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "src/gpu/GrVertexChunkArray.h"
9
10#include "src/gpu/GrMeshDrawTarget.h"
11
12GrVertexChunkBuilder::~GrVertexChunkBuilder() {
13 if (!fChunks->empty()) {
14 fTarget->putBackVertices(fCurrChunkVertexCapacity - fCurrChunkVertexCount, fStride);
15 fChunks->back().fCount = fCurrChunkVertexCount;
16 }
17}
18
19bool GrVertexChunkBuilder::allocChunk(int minCount) {
20 if (!fChunks->empty()) {
21 // No need to put back vertices; the buffer is full.
22 fChunks->back().fCount = fCurrChunkVertexCount;
23 }
24 fCurrChunkVertexCount = 0;
25 GrVertexChunk* chunk = &fChunks->push_back();
26 int minAllocCount = std::max(minCount, fMinVerticesPerChunk);
27 fCurrChunkVertexWriter = {fTarget->makeVertexSpaceAtLeast(fStride, minAllocCount,
28 minAllocCount, &chunk->fBuffer,
29 &chunk->fBase,
30 &fCurrChunkVertexCapacity)};
31 if (!fCurrChunkVertexWriter || !chunk->fBuffer || fCurrChunkVertexCapacity < minCount) {
32 SkDebugf("WARNING: Failed to allocate vertex buffer for GrVertexChunk.\n");
33 fChunks->pop_back();
34 SkASSERT(fCurrChunkVertexCount == 0);
35 fCurrChunkVertexCapacity = 0;
36 return false;
37 }
38 fMinVerticesPerChunk *= 2;
39 return true;
40}