blob: a3065f706af6ad6f9403e7928541136996e482d2 [file] [log] [blame]
Robert Phillips71143952021-06-17 14:55:07 -04001/*
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 "src/gpu/GrDrawIndirectCommand.h"
12#include "src/gpu/GrSimpleMesh.h"
13
Robert Phillips1a82a4e2021-07-01 10:27:44 -040014class GrAtlasManager;
15class GrSmallPathAtlasMgr;
16class GrStrikeCache;
17
Robert Phillips71143952021-06-17 14:55:07 -040018/*
19 * Abstract interface that supports creating vertices, indices, and meshes, as well as
20 * invoking GPU draw operations.
21 */
22class GrMeshDrawTarget {
23public:
24 virtual ~GrMeshDrawTarget() {}
25
26 /** Adds a draw of a mesh. 'primProcProxies' must have
27 * GrGeometryProcessor::numTextureSamplers() entries. Can be null if no samplers.
28 */
29 virtual void recordDraw(const GrGeometryProcessor*,
30 const GrSimpleMesh[],
31 int meshCnt,
32 const GrSurfaceProxy* const primProcProxies[],
33 GrPrimitiveType) = 0;
34
35 /**
36 * Helper for drawing GrSimpleMesh(es) with zero primProc textures.
37 */
38 void recordDraw(const GrGeometryProcessor* gp,
39 const GrSimpleMesh meshes[],
40 int meshCnt,
41 GrPrimitiveType primitiveType) {
42 this->recordDraw(gp, meshes, meshCnt, nullptr, primitiveType);
43 }
44
45 /**
46 * Makes space for vertex data. The returned pointer is the location where vertex data
47 * should be written. On return the buffer that will hold the data as well as an offset into
48 * the buffer (in 'vertexSize' units) where the data will be placed.
49 */
50 virtual void* makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp<const GrBuffer>*,
51 int* startVertex) = 0;
52
53 /**
54 * Makes space for index data. The returned pointer is the location where index data
55 * should be written. On return the buffer that will hold the data as well as an offset into
56 * the buffer (in uint16_t units) where the data will be placed.
57 */
58 virtual uint16_t* makeIndexSpace(int indexCount, sk_sp<const GrBuffer>*, int* startIndex) = 0;
59
60 /**
61 * This is similar to makeVertexSpace. It allows the caller to use up to 'actualVertexCount'
62 * vertices in the returned pointer, which may exceed 'minVertexCount'.
63 * 'fallbackVertexCount' is the maximum number of vertices that should be allocated if a new
64 * buffer is allocated on behalf of this request.
65 */
66 virtual void* makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount,
67 int fallbackVertexCount, sk_sp<const GrBuffer>*,
68 int* startVertex, int* actualVertexCount) = 0;
69
70 /**
71 * This is similar to makeIndexSpace. It allows the caller to use up to 'actualIndexCount'
72 * indices in the returned pointer, which may exceed 'minIndexCount'.
73 * 'fallbackIndexCount' is the maximum number of indices that should be allocated if a new
74 * buffer is allocated on behalf of this request.
75 */
76 virtual uint16_t* makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
77 sk_sp<const GrBuffer>*, int* startIndex,
78 int* actualIndexCount) = 0;
79
80 /**
81 * Makes space for elements in a draw-indirect buffer. Upon success, the returned pointer is a
82 * CPU mapping where the data should be written.
83 */
84 virtual GrDrawIndirectWriter makeDrawIndirectSpace(int drawCount, sk_sp<const GrBuffer>* buffer,
85 size_t* offsetInBytes) = 0;
86
87 /**
88 * Makes space for elements in a draw-indexed-indirect buffer. Upon success, the returned
89 * pointer is a CPU mapping where the data should be written.
90 */
91 virtual GrDrawIndexedIndirectWriter makeDrawIndexedIndirectSpace(int drawCount,
92 sk_sp<const GrBuffer>*,
93 size_t* offsetInBytes) = 0;
94
95 /** Helpers for ops which over-allocate and then return excess data to the pool. */
96 virtual void putBackIndices(int indices) = 0;
97 virtual void putBackVertices(int vertices, size_t vertexStride) = 0;
98 virtual void putBackIndirectDraws(int count) = 0;
99 virtual void putBackIndexedIndirectDraws(int count) = 0;
100
101 GrSimpleMesh* allocMesh() { return this->allocator()->make<GrSimpleMesh>(); }
102 GrSimpleMesh* allocMeshes(int n) { return this->allocator()->makeArray<GrSimpleMesh>(n); }
103 const GrSurfaceProxy** allocPrimProcProxyPtrs(int n) {
104 return this->allocator()->makeArray<const GrSurfaceProxy*>(n);
105 }
106
107 virtual GrRenderTargetProxy* rtProxy() const = 0;
108 virtual const GrSurfaceProxyView& writeView() const = 0;
109
110 virtual const GrAppliedClip* appliedClip() const = 0;
111 virtual GrAppliedClip detachAppliedClip() = 0;
112
113 virtual const GrDstProxyView& dstProxyView() const = 0;
114 virtual bool usesMSAASurface() const = 0;
115
116 virtual GrXferBarrierFlags renderPassBarriers() const = 0;
117
118 virtual GrLoadOp colorLoadOp() const = 0;
119
120 virtual GrThreadSafeCache* threadSafeCache() const = 0;
121 virtual GrResourceProvider* resourceProvider() const = 0;
Robert Phillips1a82a4e2021-07-01 10:27:44 -0400122 uint32_t contextUniqueID() const;
Robert Phillips71143952021-06-17 14:55:07 -0400123
124 virtual GrStrikeCache* strikeCache() const = 0;
125 virtual GrAtlasManager* atlasManager() const = 0;
126 virtual GrSmallPathAtlasMgr* smallPathAtlasManager() const = 0;
127
128 // This should be called during onPrepare of a GrOp. The caller should add any proxies to the
129 // array it will use that it did not access during a call to visitProxies. This is usually the
130 // case for atlases.
131 virtual SkTArray<GrSurfaceProxy*, true>* sampledProxyArray() = 0;
132
133 virtual const GrCaps& caps() const = 0;
134
135 virtual GrDeferredUploadTarget* deferredUploadTarget() = 0;
136
137 virtual SkArenaAlloc* allocator() = 0;
138};
139
140#endif