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