• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
~GrVertexChunkBuilder()12 GrVertexChunkBuilder::~GrVertexChunkBuilder() {
13     if (!fChunks->empty()) {
14         fTarget->putBackVertices(fCurrChunkVertexCapacity - fCurrChunkVertexCount, fStride);
15         fChunks->back().fCount = fCurrChunkVertexCount;
16     }
17 }
18 
allocChunk(int minCount)19 bool 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 }
41