OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrInOrderDrawBuffer_DEFINED | 8 #ifndef GrInOrderDrawBuffer_DEFINED |
9 #define GrInOrderDrawBuffer_DEFINED | 9 #define GrInOrderDrawBuffer_DEFINED |
10 | 10 |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
12 #include "GrAllocPool.h" | 12 #include "GrAllocPool.h" |
13 #include "GrAllocator.h" | 13 #include "GrAllocator.h" |
14 #include "GrGpu.h" | |
14 #include "GrIndexBuffer.h" | 15 #include "GrIndexBuffer.h" |
16 #include "GrOptDrawState.h" | |
15 #include "GrRenderTarget.h" | 17 #include "GrRenderTarget.h" |
16 #include "GrPath.h" | 18 #include "GrPath.h" |
17 #include "GrPathRange.h" | 19 #include "GrPathRange.h" |
18 #include "GrSurface.h" | 20 #include "GrSurface.h" |
19 #include "GrTRecorder.h" | 21 #include "GrTRecorder.h" |
20 #include "GrVertexBuffer.h" | 22 #include "GrVertexBuffer.h" |
21 | 23 |
22 #include "SkClipStack.h" | 24 #include "SkClipStack.h" |
23 #include "SkTemplates.h" | 25 #include "SkTemplates.h" |
24 #include "SkTypes.h" | 26 #include "SkTypes.h" |
25 | 27 |
26 class GrGpu; | |
27 class GrIndexBufferAllocPool; | 28 class GrIndexBufferAllocPool; |
28 class GrVertexBufferAllocPool; | 29 class GrVertexBufferAllocPool; |
29 | 30 |
30 /** | 31 /** |
31 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual | 32 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws for eventual |
32 * playback into a GrGpu. In theory one draw buffer could playback into another. When index or | 33 * playback into a GrGpu. In theory one draw buffer could playback into another. When index or |
33 * vertex buffers are used as geometry sources it is the callers the draw buffer only holds | 34 * vertex buffers are used as geometry sources it is the callers the draw buffer only holds |
34 * references to the buffers. It is the callers responsibility to ensure that th e data is still | 35 * references to the buffers. It is the callers responsibility to ensure that th e data is still |
35 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's | 36 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the caller's |
36 * responsibility to ensure that all referenced textures, buffers, and render-ta rgets are associated | 37 * responsibility to ensure that all referenced textures, buffers, and render-ta rgets are associated |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 kClear_Cmd = 4, | 104 kClear_Cmd = 4, |
104 kCopySurface_Cmd = 5, | 105 kCopySurface_Cmd = 5, |
105 kDrawPath_Cmd = 6, | 106 kDrawPath_Cmd = 6, |
106 kDrawPaths_Cmd = 7, | 107 kDrawPaths_Cmd = 7, |
107 }; | 108 }; |
108 | 109 |
109 struct Cmd : ::SkNoncopyable { | 110 struct Cmd : ::SkNoncopyable { |
110 Cmd(uint8_t type) : fType(type) {} | 111 Cmd(uint8_t type) : fType(type) {} |
111 virtual ~Cmd() {} | 112 virtual ~Cmd() {} |
112 | 113 |
113 virtual void execute(GrGpu*) = 0; | 114 virtual void execute(GrGpu*, const GrOptDrawState*) = 0; |
114 | 115 |
115 uint8_t fType; | 116 uint8_t fType; |
116 }; | 117 }; |
117 | 118 |
118 struct Draw : public Cmd { | 119 struct Draw : public Cmd { |
119 Draw(const DrawInfo& info, | 120 Draw(const DrawInfo& info, |
120 const ScissorState& scissorState, | 121 const ScissorState& scissorState, |
121 const GrVertexBuffer* vb, | 122 const GrVertexBuffer* vb, |
122 const GrIndexBuffer* ib) | 123 const GrIndexBuffer* ib) |
123 : Cmd(kDraw_Cmd) | 124 : Cmd(kDraw_Cmd) |
124 , fInfo(info) | 125 , fInfo(info) |
125 , fScissorState(scissorState) | 126 , fScissorState(scissorState) |
126 , fVertexBuffer(vb) | 127 , fVertexBuffer(vb) |
127 , fIndexBuffer(ib) {} | 128 , fIndexBuffer(ib) {} |
128 | 129 |
129 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } | 130 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } |
130 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } | 131 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } |
131 | 132 |
132 virtual void execute(GrGpu*); | 133 virtual void execute(GrGpu*, const GrOptDrawState*); |
133 | 134 |
134 DrawInfo fInfo; | 135 DrawInfo fInfo; |
135 ScissorState fScissorState; | 136 ScissorState fScissorState; |
136 | 137 |
137 private: | 138 private: |
138 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff er; | 139 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuff er; |
139 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe r; | 140 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffe r; |
140 }; | 141 }; |
141 | 142 |
142 struct StencilPath : public Cmd { | 143 struct StencilPath : public Cmd { |
143 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} | 144 StencilPath(const GrPath* path) : Cmd(kStencilPath_Cmd), fPath(path) {} |
144 | 145 |
145 const GrPath* path() const { return fPath.get(); } | 146 const GrPath* path() const { return fPath.get(); } |
146 | 147 |
147 virtual void execute(GrGpu*); | 148 virtual void execute(GrGpu*, const GrOptDrawState*); |
148 | 149 |
149 ScissorState fScissorState; | 150 ScissorState fScissorState; |
150 GrStencilSettings fStencilSettings; | 151 GrStencilSettings fStencilSettings; |
151 | 152 |
152 private: | 153 private: |
153 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 154 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
154 }; | 155 }; |
155 | 156 |
156 struct DrawPath : public Cmd { | 157 struct DrawPath : public Cmd { |
157 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} | 158 DrawPath(const GrPath* path) : Cmd(kDrawPath_Cmd), fPath(path) {} |
158 | 159 |
159 const GrPath* path() const { return fPath.get(); } | 160 const GrPath* path() const { return fPath.get(); } |
160 | 161 |
161 virtual void execute(GrGpu*); | 162 virtual void execute(GrGpu*, const GrOptDrawState*); |
162 | 163 |
163 GrDeviceCoordTexture fDstCopy; | 164 GrDeviceCoordTexture fDstCopy; |
164 ScissorState fScissorState; | 165 ScissorState fScissorState; |
165 GrStencilSettings fStencilSettings; | 166 GrStencilSettings fStencilSettings; |
166 | 167 |
167 private: | 168 private: |
168 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; | 169 GrPendingIOResource<const GrPath, kRead_GrIOType> fPath; |
169 }; | 170 }; |
170 | 171 |
171 struct DrawPaths : public Cmd { | 172 struct DrawPaths : public Cmd { |
172 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang e(pathRange) {} | 173 DrawPaths(const GrPathRange* pathRange) : Cmd(kDrawPaths_Cmd), fPathRang e(pathRange) {} |
173 | 174 |
174 const GrPathRange* pathRange() const { return fPathRange.get(); } | 175 const GrPathRange* pathRange() const { return fPathRange.get(); } |
175 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD ataForItem(this)); } | 176 uint32_t* indices() { return reinterpret_cast<uint32_t*>(CmdBuffer::GetD ataForItem(this)); } |
176 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f Count]); } | 177 float* transforms() { return reinterpret_cast<float*>(&this->indices()[f Count]); } |
177 | 178 |
178 virtual void execute(GrGpu*); | 179 virtual void execute(GrGpu*, const GrOptDrawState*); |
179 | 180 |
180 size_t fCount; | 181 size_t fCount; |
181 PathTransformType fTransformsType; | 182 PathTransformType fTransformsType; |
182 GrDeviceCoordTexture fDstCopy; | 183 GrDeviceCoordTexture fDstCopy; |
183 ScissorState fScissorState; | 184 ScissorState fScissorState; |
184 GrStencilSettings fStencilSettings; | 185 GrStencilSettings fStencilSettings; |
185 | 186 |
186 private: | 187 private: |
187 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; | 188 GrPendingIOResource<const GrPathRange, kRead_GrIOType> fPathRange; |
188 }; | 189 }; |
189 | 190 |
190 // This is also used to record a discard by setting the color to GrColor_ILL EGAL | 191 // This is also used to record a discard by setting the color to GrColor_ILL EGAL |
191 struct Clear : public Cmd { | 192 struct Clear : public Cmd { |
192 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} | 193 Clear(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt) {} |
193 | 194 |
194 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 195 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
195 | 196 |
196 virtual void execute(GrGpu*); | 197 virtual void execute(GrGpu*, const GrOptDrawState*); |
197 | 198 |
198 SkIRect fRect; | 199 SkIRect fRect; |
199 GrColor fColor; | 200 GrColor fColor; |
200 bool fCanIgnoreRect; | 201 bool fCanIgnoreRect; |
201 | 202 |
202 private: | 203 private: |
203 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 204 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
204 }; | 205 }; |
205 | 206 |
206 // This command is ONLY used by the clip mask manager to clear the stencil c lip bits | 207 // This command is ONLY used by the clip mask manager to clear the stencil c lip bits |
207 struct ClearStencilClip : public Cmd { | 208 struct ClearStencilClip : public Cmd { |
208 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt ) {} | 209 ClearStencilClip(GrRenderTarget* rt) : Cmd(kClear_Cmd), fRenderTarget(rt ) {} |
209 | 210 |
210 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } | 211 GrRenderTarget* renderTarget() const { return fRenderTarget.get(); } |
211 | 212 |
212 virtual void execute(GrGpu*); | 213 virtual void execute(GrGpu*, const GrOptDrawState*); |
213 | 214 |
214 SkIRect fRect; | 215 SkIRect fRect; |
215 bool fInsideClip; | 216 bool fInsideClip; |
216 | 217 |
217 private: | 218 private: |
218 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; | 219 GrPendingIOResource<GrRenderTarget, kWrite_GrIOType> fRenderTarget; |
219 }; | 220 }; |
220 | 221 |
221 struct CopySurface : public Cmd { | 222 struct CopySurface : public Cmd { |
222 CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDs t(dst), fSrc(src) {} | 223 CopySurface(GrSurface* dst, GrSurface* src) : Cmd(kCopySurface_Cmd), fDs t(dst), fSrc(src) {} |
223 | 224 |
224 GrSurface* dst() const { return fDst.get(); } | 225 GrSurface* dst() const { return fDst.get(); } |
225 GrSurface* src() const { return fSrc.get(); } | 226 GrSurface* src() const { return fSrc.get(); } |
226 | 227 |
227 virtual void execute(GrGpu*); | 228 virtual void execute(GrGpu*, const GrOptDrawState*); |
228 | 229 |
229 SkIPoint fDstPoint; | 230 SkIPoint fDstPoint; |
230 SkIRect fSrcRect; | 231 SkIRect fSrcRect; |
231 | 232 |
232 private: | 233 private: |
233 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; | 234 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
234 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; | 235 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
235 }; | 236 }; |
236 | 237 |
237 struct SetState : public Cmd { | 238 struct SetState : public Cmd { |
238 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) { } | 239 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) { } |
239 | 240 |
240 virtual void execute(GrGpu*); | 241 virtual void execute(GrGpu*, const GrOptDrawState*); |
241 | 242 |
242 GrDrawState fState; | 243 GrDrawState fState; |
244 GrGpu::DrawType fDrawType; | |
245 GrDeviceCoordTexture fDstCopy; | |
243 }; | 246 }; |
244 | 247 |
245 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. | 248 typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. |
246 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 249 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
247 | 250 |
248 // overrides from GrDrawTarget | 251 // overrides from GrDrawTarget |
249 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&) SK_OVERRIDE; | 252 virtual void onDraw(const DrawInfo&, const GrClipMaskManager::ScissorState&) SK_OVERRIDE; |
250 virtual void onDrawRect(const SkRect& rect, | 253 virtual void onDrawRect(const SkRect& rect, |
251 const SkRect* localRect, | 254 const SkRect* localRect, |
252 const SkMatrix* localMatrix) SK_OVERRIDE; | 255 const SkMatrix* localMatrix) SK_OVERRIDE; |
(...skipping 28 matching lines...) Expand all Loading... | |
281 virtual void geometrySourceWillPush() SK_OVERRIDE; | 284 virtual void geometrySourceWillPush() SK_OVERRIDE; |
282 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK _OVERRIDE; | 285 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK _OVERRIDE; |
283 virtual void willReserveVertexAndIndexSpace(int vertexCount, | 286 virtual void willReserveVertexAndIndexSpace(int vertexCount, |
284 int indexCount) SK_OVERRIDE; | 287 int indexCount) SK_OVERRIDE; |
285 | 288 |
286 // Attempts to concat instances from info onto the previous draw. info must represent an | 289 // Attempts to concat instances from info onto the previous draw. info must represent an |
287 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary. | 290 // instanced draw. The caller must have already recorded a new draw state an d clip if necessary. |
288 int concatInstancedDraw(const DrawInfo& info, const GrClipMaskManager::Sciss orState&); | 291 int concatInstancedDraw(const DrawInfo& info, const GrClipMaskManager::Sciss orState&); |
289 | 292 |
290 // Determines whether the current draw operation requieres a new drawstate a nd if so records it. | 293 // Determines whether the current draw operation requieres a new drawstate a nd if so records it. |
291 void recordStateIfNecessary(); | 294 void recordStateIfNecessary(GrGpu::DrawType, const GrDeviceCoordTexture*); |
292 // We lazily record clip changes in order to skip clips that have no effect. | 295 // We lazily record clip changes in order to skip clips that have no effect. |
293 void recordClipIfNecessary(); | 296 void recordClipIfNecessary(); |
294 // Records any trace markers for a command after adding it to the buffer. | 297 // Records any trace markers for a command after adding it to the buffer. |
295 void recordTraceMarkersIfNecessary(); | 298 void recordTraceMarkersIfNecessary(); |
296 | 299 |
297 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 300 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
298 | 301 |
299 // TODO: Use a single allocator for commands and records | 302 // TODO: Use a single allocator for commands and records |
300 enum { | 303 enum { |
301 kCmdBufferInitialSizeInBytes = 8 * 1024, | 304 kCmdBufferInitialSizeInBytes = 8 * 1024, |
302 kGeoPoolStatePreAllocCnt = 4, | 305 kGeoPoolStatePreAllocCnt = 4, |
303 }; | 306 }; |
304 | 307 |
305 CmdBuffer fCmdBuffer; | 308 CmdBuffer fCmdBuffer; |
306 GrDrawState* fLastState; | 309 GrDrawState* fLastState; |
307 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | 310 SkAutoTUnref<const GrOptDrawState> fCurrentOptDrawState; |
bsalomon
2014/11/10 16:06:15
Looks like this guy doesn't need to be a member. I
joshualitt
2014/11/10 16:27:18
But is it possible for some state setting to cross
bsalomon
2014/11/10 16:36:02
flush is destructive of the recorded data. Newly r
| |
308 GrGpu* fDstGpu; | 311 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
309 GrVertexBufferAllocPool& fVertexPool; | 312 GrGpu* fDstGpu; |
310 GrIndexBufferAllocPool& fIndexPool; | 313 GrVertexBufferAllocPool& fVertexPool; |
314 GrIndexBufferAllocPool& fIndexPool; | |
311 | 315 |
312 struct GeometryPoolState { | 316 struct GeometryPoolState { |
313 const GrVertexBuffer* fPoolVertexBuffer; | 317 const GrVertexBuffer* fPoolVertexBuffer; |
314 int fPoolStartVertex; | 318 int fPoolStartVertex; |
315 const GrIndexBuffer* fPoolIndexBuffer; | 319 const GrIndexBuffer* fPoolIndexBuffer; |
316 int fPoolStartIndex; | 320 int fPoolStartIndex; |
317 // caller may conservatively over reserve vertices / indices. | 321 // caller may conservatively over reserve vertices / indices. |
318 // we release unused space back to allocator if possible | 322 // we release unused space back to allocator if possible |
319 // can only do this if there isn't an intervening pushGeometrySource() | 323 // can only do this if there isn't an intervening pushGeometrySource() |
320 size_t fUsedPoolVertexBytes; | 324 size_t fUsedPoolVertexBytes; |
321 size_t fUsedPoolIndexBytes; | 325 size_t fUsedPoolIndexBytes; |
322 }; | 326 }; |
323 | 327 |
324 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS tack; | 328 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS tack; |
325 | 329 |
326 GeoPoolStateStack fGeoPoolStateStack; | 330 GeoPoolStateStack fGeoPoolStateStack; |
327 bool fFlushing; | 331 bool fFlushing; |
328 uint32_t fDrawID; | 332 uint32_t fDrawID; |
329 | 333 |
330 typedef GrClipTarget INHERITED; | 334 typedef GrClipTarget INHERITED; |
331 }; | 335 }; |
332 | 336 |
333 #endif | 337 #endif |
OLD | NEW |