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