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 "GrFlushToGpuDrawTarget.h" |
12 #include "GrGpu.h" | |
13 #include "GrIndexBuffer.h" | |
14 #include "GrOptDrawState.h" | 12 #include "GrOptDrawState.h" |
15 #include "GrPath.h" | 13 #include "GrPath.h" |
16 #include "GrPathRange.h" | |
17 #include "GrRenderTarget.h" | |
18 #include "GrSurface.h" | |
19 #include "GrTRecorder.h" | 14 #include "GrTRecorder.h" |
20 #include "GrVertexBuffer.h" | |
21 | |
22 #include "SkClipStack.h" | |
23 #include "SkTemplates.h" | |
24 #include "SkTypes.h" | |
25 | |
26 class GrIndexBufferAllocPool; | |
27 class GrVertexBufferAllocPool; | |
28 | 15 |
29 /** | 16 /** |
30 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual | 17 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual |
31 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or | 18 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or |
32 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds | 19 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds |
33 * references to the buffers. It is the callers responsibility to ensure that th
e data is still | 20 * references to the buffers. It is the callers responsibility to ensure that th
e data is still |
34 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's | 21 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's |
35 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated | 22 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated |
36 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to | 23 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to |
37 * store geometry. | 24 * store geometry. |
38 */ | 25 */ |
39 class GrInOrderDrawBuffer : public GrClipTarget { | 26 class GrInOrderDrawBuffer : public GrFlushToGpuDrawTarget { |
40 public: | 27 public: |
41 | 28 |
42 /** | 29 /** |
43 * Creates a GrInOrderDrawBuffer | 30 * Creates a GrInOrderDrawBuffer |
44 * | 31 * |
45 * @param gpu the gpu object that this draw buffer flushes to. | 32 * @param gpu the gpu object that this draw buffer flushes to. |
46 * @param vertexPool pool where vertices for queued draws will be saved when | 33 * @param vertexPool pool where vertices for queued draws will be saved when |
47 * the vertex source is either reserved or array. | 34 * the vertex source is either reserved or array. |
48 * @param indexPool pool where indices for queued draws will be saved when | 35 * @param indexPool pool where indices for queued draws will be saved when |
49 * the index source is either reserved or array. | 36 * the index source is either reserved or array. |
50 */ | 37 */ |
51 GrInOrderDrawBuffer(GrGpu* gpu, | 38 GrInOrderDrawBuffer(GrGpu* gpu, |
52 GrVertexBufferAllocPool* vertexPool, | 39 GrVertexBufferAllocPool* vertexPool, |
53 GrIndexBufferAllocPool* indexPool); | 40 GrIndexBufferAllocPool* indexPool); |
54 | 41 |
55 ~GrInOrderDrawBuffer() SK_OVERRIDE; | 42 ~GrInOrderDrawBuffer() SK_OVERRIDE; |
56 | 43 |
57 /** | |
58 * Empties the draw buffer of any queued up draws. This must not be called w
hile inside an | |
59 * unbalanced pushGeometrySource(). The current draw state and clip are pres
erved. | |
60 */ | |
61 void reset(); | |
62 | |
63 /** | |
64 * This plays the queued up draws to its GrGpu target. It also resets this o
bject (i.e. flushing | |
65 * is destructive). This buffer must not have an active reserved vertex or i
ndex source. Any | |
66 * reserved geometry on the target will be finalized because it's geometry s
ource will be pushed | |
67 * before flushing and popped afterwards. | |
68 */ | |
69 void flush(); | |
70 | |
71 // tracking for draws | 44 // tracking for draws |
72 DrawToken getCurrentDrawToken() { return DrawToken(this, fDrawID); } | 45 DrawToken getCurrentDrawToken() { return DrawToken(this, fDrawID); } |
73 | 46 |
74 // overrides from GrDrawTarget | |
75 bool geometryHints(size_t vertexStride, | |
76 int* vertexCount, | |
77 int* indexCount) const SK_OVERRIDE; | |
78 | |
79 void clearStencilClip(const SkIRect& rect, | 47 void clearStencilClip(const SkIRect& rect, |
80 bool insideClip, | 48 bool insideClip, |
81 GrRenderTarget* renderTarget) SK_OVERRIDE; | 49 GrRenderTarget* renderTarget) SK_OVERRIDE; |
82 | 50 |
83 void discard(GrRenderTarget*) SK_OVERRIDE; | 51 void discard(GrRenderTarget*) SK_OVERRIDE; |
84 | 52 |
85 private: | 53 private: |
86 typedef GrClipMaskManager::ScissorState ScissorState; | 54 typedef GrClipMaskManager::ScissorState ScissorState; |
87 enum { | 55 enum { |
88 kDraw_Cmd = 1, | 56 kDraw_Cmd = 1, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 178 |
211 void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; | 179 void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; |
212 | 180 |
213 const GrOptDrawState fState; | 181 const GrOptDrawState fState; |
214 GrGpu::DrawType fDrawType; | 182 GrGpu::DrawType fDrawType; |
215 }; | 183 }; |
216 | 184 |
217 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | 185 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
218 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 186 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
219 | 187 |
| 188 void onReset() SK_OVERRIDE; |
| 189 void onFlush() SK_OVERRIDE; |
| 190 |
220 // overrides from GrDrawTarget | 191 // overrides from GrDrawTarget |
221 void onDraw(const GrDrawState&, | 192 void onDraw(const GrDrawState&, |
222 const DrawInfo&, | 193 const DrawInfo&, |
223 const ScissorState&, | 194 const ScissorState&, |
224 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; | 195 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
225 void onDrawRect(GrDrawState*, | 196 void onDrawRect(GrDrawState*, |
226 const SkRect& rect, | 197 const SkRect& rect, |
227 const SkRect* localRect, | 198 const SkRect* localRect, |
228 const SkMatrix* localMatrix) SK_OVERRIDE; | 199 const SkMatrix* localMatrix) SK_OVERRIDE; |
229 | 200 |
(...skipping 13 matching lines...) Expand all Loading... |
243 const float transformValues[], | 214 const float transformValues[], |
244 PathTransformType, | 215 PathTransformType, |
245 int count, | 216 int count, |
246 const ScissorState&, | 217 const ScissorState&, |
247 const GrStencilSettings&, | 218 const GrStencilSettings&, |
248 const GrDeviceCoordTexture*) SK_OVERRIDE; | 219 const GrDeviceCoordTexture*) SK_OVERRIDE; |
249 void onClear(const SkIRect* rect, | 220 void onClear(const SkIRect* rect, |
250 GrColor color, | 221 GrColor color, |
251 bool canIgnoreRect, | 222 bool canIgnoreRect, |
252 GrRenderTarget* renderTarget) SK_OVERRIDE; | 223 GrRenderTarget* renderTarget) SK_OVERRIDE; |
253 void setDrawBuffers(DrawInfo*) SK_OVERRIDE; | |
254 | |
255 bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertice
s) SK_OVERRIDE; | |
256 bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE; | |
257 void releaseReservedVertexSpace() SK_OVERRIDE; | |
258 void releaseReservedIndexSpace() SK_OVERRIDE; | |
259 void geometrySourceWillPush() SK_OVERRIDE; | |
260 void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRID
E; | |
261 void willReserveVertexAndIndexSpace(int vertexCount, | |
262 size_t vertexStride, | |
263 int indexCount) SK_OVERRIDE; | |
264 bool onCopySurface(GrSurface* dst, | 224 bool onCopySurface(GrSurface* dst, |
265 GrSurface* src, | 225 GrSurface* src, |
266 const SkIRect& srcRect, | 226 const SkIRect& srcRect, |
267 const SkIPoint& dstPoint) SK_OVERRIDE; | 227 const SkIPoint& dstPoint) SK_OVERRIDE; |
268 bool onCanCopySurface(const GrSurface* dst, | 228 bool onCanCopySurface(const GrSurface* dst, |
269 const GrSurface* src, | 229 const GrSurface* src, |
270 const SkIRect& srcRect, | 230 const SkIRect& srcRect, |
271 const SkIPoint& dstPoint) SK_OVERRIDE; | 231 const SkIPoint& dstPoint) SK_OVERRIDE; |
272 bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_
OVERRIDE; | 232 bool onInitCopySurfaceDstDesc(const GrSurface* src, GrSurfaceDesc* desc) SK_
OVERRIDE; |
273 | 233 |
(...skipping 13 matching lines...) Expand all Loading... |
287 // Records any trace markers for a command after adding it to the buffer. | 247 // Records any trace markers for a command after adding it to the buffer. |
288 void recordTraceMarkersIfNecessary(); | 248 void recordTraceMarkersIfNecessary(); |
289 | 249 |
290 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 250 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
291 | 251 |
292 // TODO: Use a single allocator for commands and records | 252 // TODO: Use a single allocator for commands and records |
293 enum { | 253 enum { |
294 kCmdBufferInitialSizeInBytes = 8 * 1024, | 254 kCmdBufferInitialSizeInBytes = 8 * 1024, |
295 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's | 255 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's |
296 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms | 256 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms |
297 kGeoPoolStatePreAllocCnt = 4, | |
298 }; | 257 }; |
299 | 258 |
300 struct GeometryPoolState { | |
301 const GrVertexBuffer* fPoolVertexBuffer; | |
302 int fPoolStartVertex; | |
303 const GrIndexBuffer* fPoolIndexBuffer; | |
304 int fPoolStartIndex; | |
305 // caller may conservatively over reserve vertices / indices. | |
306 // we release unused space back to allocator if possible | |
307 // can only do this if there isn't an intervening pushGeometrySource() | |
308 size_t fUsedPoolVertexBytes; | |
309 size_t fUsedPoolIndexBytes; | |
310 }; | |
311 | |
312 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; | |
313 | |
314 CmdBuffer fCmdBuffer; | 259 CmdBuffer fCmdBuffer; |
315 const GrOptDrawState* fPrevState; | 260 const GrOptDrawState* fPrevState; |
316 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | 261 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
317 GrGpu* fDstGpu; | |
318 GrVertexBufferAllocPool& fVertexPool; | |
319 GrIndexBufferAllocPool& fIndexPool; | |
320 SkTDArray<char> fPathIndexBuffer; | 262 SkTDArray<char> fPathIndexBuffer; |
321 SkTDArray<float> fPathTransformBuffer; | 263 SkTDArray<float> fPathTransformBuffer; |
322 GeoPoolStateStack fGeoPoolStateStack; | |
323 bool fFlushing; | |
324 uint32_t fDrawID; | 264 uint32_t fDrawID; |
325 | 265 |
326 typedef GrClipTarget INHERITED; | 266 typedef GrFlushToGpuDrawTarget INHERITED; |
327 }; | 267 }; |
328 | 268 |
329 #endif | 269 #endif |
OLD | NEW |