1 /* 2 * Copyright 2022 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 #ifndef VertexChunkPatchAllocator_DEFINED 9 #define VertexChunkPatchAllocator_DEFINED 10 11 #include "src/gpu/BufferWriter.h" 12 #include "src/gpu/ganesh/GrVertexChunkArray.h" 13 #include "src/gpu/tessellate/LinearTolerances.h" 14 15 #include <cstddef> 16 17 class GrMeshDrawTarget; 18 19 namespace skgpu::ganesh { 20 21 // An adapter around GrVertexChunkBuilder that fits the API requirements of 22 // skgpu::tess::PatchWriter's PatchAllocator template parameter. 23 class VertexChunkPatchAllocator { 24 public: 25 // 'stride' is provided by PatchWriter. 26 // 'worstCaseTolerances' is used to accumulate the LinearTolerances from each append(). 27 // 'target', 'chunks', and 'minVerticesPerChunk' are forwarded from the PatchWriter's ctor and 28 // are used to construct a GrVertexChunkBuilder matching the PatchWriter's stride. VertexChunkPatchAllocator(size_t stride,tess::LinearTolerances * worstCaseTolerances,GrMeshDrawTarget * target,GrVertexChunkArray * chunks,int minVerticesPerChunk)29 VertexChunkPatchAllocator(size_t stride, 30 tess::LinearTolerances* worstCaseTolerances, 31 GrMeshDrawTarget* target, 32 GrVertexChunkArray* chunks, 33 int minVerticesPerChunk) 34 : fWorstCaseTolerances(worstCaseTolerances) 35 , fBuilder(target, chunks, stride, minVerticesPerChunk) {} 36 append(const tess::LinearTolerances & tolerances)37 VertexWriter append(const tess::LinearTolerances& tolerances) { 38 fWorstCaseTolerances->accumulate(tolerances); 39 return fBuilder.appendVertices(1); 40 } 41 42 private: 43 tess::LinearTolerances* fWorstCaseTolerances; 44 GrVertexChunkBuilder fBuilder; 45 }; 46 47 } // namespace skgpu::ganesh 48 49 #endif // VertexChunkPatchAllocator_DEFINED 50