Flutter Engine
The Flutter Engine
DynamicInstancesPatchAllocator.h
Go to the documentation of this file.
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 skgpu_graphite_render_DynamicInstancesPatchAllocator_DEFINED
9#define skgpu_graphite_render_DynamicInstancesPatchAllocator_DEFINED
10
14
15namespace skgpu::graphite {
16
17// An adapter around DrawWriter::DynamicInstances that fits the API requirements of
18// skgpu::tess::PatchWriter's PatchAllocator template parameter.
19//
20// FixedCountVariant should be one of FixedCountCurves, FixedCountWedges, or FixedCountStrokes
21// (technically any class with a static VertexCount(const LinearTolerances&) function).
22template <typename FixedCountVariant>
24public:
25 // 'stride' is provided by PatchWriter.
26 // 'writer' is the DrawWriter that the RenderStep can append instance data to,
27 // 'fixedVertexBuffer' and 'fixedIndexBuffer' are the bindings for the instance template that
28 // is passed to DrawWriter::DynamicInstances.
30 DrawWriter& writer,
31 BindBufferInfo fixedVertexBuffer,
32 BindBufferInfo fixedIndexBuffer,
33 unsigned int reserveCount)
34 : fInstances(writer, fixedVertexBuffer, fixedIndexBuffer) {
35 SkASSERT(stride == writer.instanceStride());
36 // TODO: Is it worth re-reserving large chunks after this preallocation is used up? Or will
37 // appending 1 at a time be fine since it's coming from a large vertex buffer alloc anyway?
38 fInstances.reserve(reserveCount);
39 }
40
42 return fInstances.append(tolerances, 1);
43 }
44
45private:
46 struct LinearToleranceProxy {
47 operator unsigned int() const { return FixedCountVariant::VertexCount(fTolerances); }
48 void operator <<(const tess::LinearTolerances& t) { fTolerances.accumulate(t); }
49
50 tess::LinearTolerances fTolerances;
51 };
52
53 DrawWriter::DynamicInstances<LinearToleranceProxy> fInstances;
54};
55
56} // namespace skgpu::graphite
57
58#endif // skgpu_graphite_render_DynamicInstancesPatchAllocator_DEFINED
#define SkASSERT(cond)
Definition: SkAssert.h:116
VertexWriter append(const V &vertexCount, unsigned int instanceCount)
Definition: DrawWriter.h:365
VertexWriter append(const tess::LinearTolerances &tolerances)
DynamicInstancesPatchAllocator(size_t stride, DrawWriter &writer, BindBufferInfo fixedVertexBuffer, BindBufferInfo fixedIndexBuffer, unsigned int reserveCount)
VertexWriter & operator<<(VertexWriter &w, const T &val)
Definition: BufferWriter.h:277