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