Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrMeshDrawTarget.h
Go to the documentation of this file.
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#ifndef GrMeshDrawTarget_DEFINED
9#define GrMeshDrawTarget_DEFINED
10
11#include "include/core/SkRefCnt.h" // IWYU pragma: keep
17
18#include <cstddef>
19#include <cstdint>
20
21class GrAtlasManager;
22class GrBuffer;
23class GrCaps;
25class GrDstProxyView;
29class GrSurfaceProxy;
32enum class GrLoadOp;
33enum class GrPrimitiveType : uint8_t;
34enum class GrXferBarrierFlags;
35
36namespace skgpu::ganesh {
37class SmallPathAtlasMgr;
38}
39
40namespace skgpu {
41struct IndexWriter;
42struct VertexWriter;
43} // namespace skgpu
44
45namespace sktext::gpu {
46class StrikeCache;
47}
48
49/*
50 * Abstract interface that supports creating vertices, indices, and meshes, as well as
51 * invoking GPU draw operations.
52 */
54public:
55 virtual ~GrMeshDrawTarget() {}
56
57 /** Adds a draw of a mesh. 'primProcProxies' must have
58 * GrGeometryProcessor::numTextureSamplers() entries. Can be null if no samplers.
59 */
60 virtual void recordDraw(const GrGeometryProcessor*,
61 const GrSimpleMesh[],
62 int meshCnt,
63 const GrSurfaceProxy* const primProcProxies[],
64 GrPrimitiveType) = 0;
65
66 /**
67 * Helper for drawing GrSimpleMesh(es) with zero primProc textures.
68 */
70 const GrSimpleMesh meshes[],
71 int meshCnt,
72 GrPrimitiveType primitiveType) {
73 this->recordDraw(gp, meshes, meshCnt, nullptr, primitiveType);
74 }
75
76 /**
77 * Makes space for vertex data. The returned pointer is the location where vertex data
78 * should be written. On return the buffer that will hold the data as well as an offset into
79 * the buffer (in 'vertexSize' units) where the data will be placed.
80 */
81 virtual void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
82 int* startVertex) = 0;
83
84 /**
85 * Makes space for index data. The returned pointer is the location where index data
86 * should be written. On return the buffer that will hold the data as well as an offset into
87 * the buffer (in uint16_t units) where the data will be placed.
88 */
89 virtual uint16_t* makeIndexSpace(int indexCount, sk_sp<const GrBuffer>*, int* startIndex) = 0;
90
91 /**
92 * This is similar to makeVertexSpace. It allows the caller to use up to 'actualVertexCount'
93 * vertices in the returned pointer, which may exceed 'minVertexCount'.
94 * 'fallbackVertexCount' is the maximum number of vertices that should be allocated if a new
95 * buffer is allocated on behalf of this request.
96 */
97 virtual void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount,
98 int fallbackVertexCount, sk_sp<const GrBuffer>*,
99 int* startVertex, int* actualVertexCount) = 0;
100
101 /**
102 * This is similar to makeIndexSpace. It allows the caller to use up to 'actualIndexCount'
103 * indices in the returned pointer, which may exceed 'minIndexCount'.
104 * 'fallbackIndexCount' is the maximum number of indices that should be allocated if a new
105 * buffer is allocated on behalf of this request.
106 */
107 virtual uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
108 sk_sp<const GrBuffer>*, int* startIndex,
109 int* actualIndexCount) = 0;
110
111 /**
112 * Makes space for elements in a draw-indirect buffer. Upon success, the returned pointer is a
113 * CPU mapping where the data should be written.
114 */
116 size_t* offsetInBytes) = 0;
117
118 /**
119 * Makes space for elements in a draw-indexed-indirect buffer. Upon success, the returned
120 * pointer is a CPU mapping where the data should be written.
121 */
124 size_t* offsetInBytes) = 0;
125
126 /** Helpers for ops that only need to use the VertexWriter to fill the data directly. */
127 skgpu::VertexWriter makeVertexWriter(size_t vertexSize, int vertexCount,
128 sk_sp<const GrBuffer>*, int* startVertex);
129 skgpu::IndexWriter makeIndexWriter(int indexCount, sk_sp<const GrBuffer>*, int* startIndex);
130 skgpu::VertexWriter makeVertexWriterAtLeast(size_t vertexSize, int minVertexCount,
131 int fallbackVertexCount, sk_sp<const GrBuffer>*,
132 int* startVertex, int* actualVertexCount);
133 skgpu::IndexWriter makeIndexWriterAtLeast(int minIndexCount, int fallbackIndexCount,
134 sk_sp<const GrBuffer>*, int* startIndex,
135 int* actualIndexCount);
136
137 /** Helpers for ops which over-allocate and then return excess data to the pool. */
138 virtual void putBackIndices(int indices) = 0;
139 virtual void putBackVertices(int vertices, size_t vertexStride) = 0;
140 virtual void putBackIndirectDraws(int count) = 0;
141 virtual void putBackIndexedIndirectDraws(int count) = 0;
142
144 GrSimpleMesh* allocMeshes(int n) { return this->allocator()->makeArray<GrSimpleMesh>(n); }
146 return this->allocator()->makeArray<const GrSurfaceProxy*>(n);
147 }
148
149 virtual GrRenderTargetProxy* rtProxy() const = 0;
150 virtual const GrSurfaceProxyView& writeView() const = 0;
151
152 virtual const GrAppliedClip* appliedClip() const = 0;
154
155 virtual const GrDstProxyView& dstProxyView() const = 0;
156 virtual bool usesMSAASurface() const = 0;
157
159
160 virtual GrLoadOp colorLoadOp() const = 0;
161
162 virtual GrThreadSafeCache* threadSafeCache() const = 0;
164 uint32_t contextUniqueID() const;
165
167 virtual GrAtlasManager* atlasManager() const = 0;
168#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
170#endif
171
172 // This should be called during onPrepare of a GrOp. The caller should add any proxies to the
173 // array it will use that it did not access during a call to visitProxies. This is usually the
174 // case for atlases.
176
177 virtual const GrCaps& caps() const = 0;
178
180
181 virtual SkArenaAlloc* allocator() = 0;
182};
183
184#endif
int count
GrPrimitiveType
Definition GrTypesPriv.h:42
GrLoadOp
GrXferBarrierFlags
virtual const GrAppliedClip * appliedClip() const =0
uint32_t contextUniqueID() const
virtual const GrCaps & caps() const =0
virtual GrLoadOp colorLoadOp() const =0
skgpu::IndexWriter makeIndexWriterAtLeast(int minIndexCount, int fallbackIndexCount, sk_sp< const GrBuffer > *, int *startIndex, int *actualIndexCount)
virtual void putBackIndexedIndirectDraws(int count)=0
virtual void putBackIndirectDraws(int count)=0
virtual bool usesMSAASurface() const =0
virtual void recordDraw(const GrGeometryProcessor *, const GrSimpleMesh[], int meshCnt, const GrSurfaceProxy *const primProcProxies[], GrPrimitiveType)=0
virtual GrAtlasManager * atlasManager() const =0
skgpu::VertexWriter makeVertexWriter(size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *, int *startVertex)
virtual uint16_t * makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, sk_sp< const GrBuffer > *, int *startIndex, int *actualIndexCount)=0
virtual const GrSurfaceProxyView & writeView() const =0
virtual void * makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, sk_sp< const GrBuffer > *, int *startVertex, int *actualVertexCount)=0
virtual GrResourceProvider * resourceProvider() const =0
virtual SkArenaAlloc * allocator()=0
virtual void * makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *, int *startVertex)=0
virtual GrDrawIndexedIndirectWriter makeDrawIndexedIndirectSpace(int drawCount, sk_sp< const GrBuffer > *, size_t *offsetInBytes)=0
void recordDraw(const GrGeometryProcessor *gp, const GrSimpleMesh meshes[], int meshCnt, GrPrimitiveType primitiveType)
virtual skia_private::TArray< GrSurfaceProxy *, true > * sampledProxyArray()=0
skgpu::IndexWriter makeIndexWriter(int indexCount, sk_sp< const GrBuffer > *, int *startIndex)
const GrSurfaceProxy ** allocPrimProcProxyPtrs(int n)
virtual GrDeferredUploadTarget * deferredUploadTarget()=0
virtual GrRenderTargetProxy * rtProxy() const =0
virtual const GrDstProxyView & dstProxyView() const =0
virtual ~GrMeshDrawTarget()
virtual GrThreadSafeCache * threadSafeCache() const =0
virtual GrXferBarrierFlags renderPassBarriers() const =0
GrSimpleMesh * allocMesh()
skgpu::VertexWriter makeVertexWriterAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, sk_sp< const GrBuffer > *, int *startVertex, int *actualVertexCount)
virtual void putBackIndices(int indices)=0
virtual sktext::gpu::StrikeCache * strikeCache() const =0
GrSimpleMesh * allocMeshes(int n)
virtual GrAppliedClip detachAppliedClip()=0
virtual GrDrawIndirectWriter makeDrawIndirectSpace(int drawCount, sk_sp< const GrBuffer > *buffer, size_t *offsetInBytes)=0
virtual skgpu::ganesh::SmallPathAtlasMgr * smallPathAtlasManager() const =0
virtual uint16_t * makeIndexSpace(int indexCount, sk_sp< const GrBuffer > *, int *startIndex)=0
virtual void putBackVertices(int vertices, size_t vertexStride)=0
T * makeArray(size_t count)
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
static const uint8_t buffer[]