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" | |
13 #include "GrAllocator.h" | |
14 #include "GrGpu.h" | 12 #include "GrGpu.h" |
15 #include "GrIndexBuffer.h" | 13 #include "GrIndexBuffer.h" |
16 #include "GrRenderTarget.h" | 14 #include "GrOptDrawState.h" |
17 #include "GrPath.h" | 15 #include "GrPath.h" |
18 #include "GrPathRange.h" | 16 #include "GrPathRange.h" |
| 17 #include "GrRenderTarget.h" |
19 #include "GrSurface.h" | 18 #include "GrSurface.h" |
20 #include "GrTRecorder.h" | 19 #include "GrTRecorder.h" |
21 #include "GrVertexBuffer.h" | 20 #include "GrVertexBuffer.h" |
22 | 21 |
23 #include "SkClipStack.h" | 22 #include "SkClipStack.h" |
24 #include "SkTemplates.h" | 23 #include "SkTemplates.h" |
25 #include "SkTypes.h" | 24 #include "SkTypes.h" |
26 | 25 |
27 class GrIndexBufferAllocPool; | 26 class GrIndexBufferAllocPool; |
28 class GrVertexBufferAllocPool; | 27 class GrVertexBufferAllocPool; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 | 216 |
218 SkIPoint fDstPoint; | 217 SkIPoint fDstPoint; |
219 SkIRect fSrcRect; | 218 SkIRect fSrcRect; |
220 | 219 |
221 private: | 220 private: |
222 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; | 221 GrPendingIOResource<GrSurface, kWrite_GrIOType> fDst; |
223 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; | 222 GrPendingIOResource<GrSurface, kRead_GrIOType> fSrc; |
224 }; | 223 }; |
225 | 224 |
226 struct SetState : public Cmd { | 225 struct SetState : public Cmd { |
227 SetState(const GrDrawState& state) : Cmd(kSetState_Cmd), fState(state) {
} | 226 SetState(const GrOptDrawState* state) : Cmd(kSetState_Cmd), fState(SkRef
(state)) {} |
228 | 227 |
229 virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*); | 228 virtual void execute(GrInOrderDrawBuffer*, const GrOptDrawState*); |
230 | 229 |
231 GrDrawState fState; | 230 SkAutoTUnref<const GrOptDrawState> fState; |
232 GrGpu::DrawType fDrawType; | 231 GrGpu::DrawType fDrawType; |
233 GrDeviceCoordTexture fDstCopy; | 232 GrDeviceCoordTexture fDstCopy; |
234 }; | 233 }; |
235 | 234 |
236 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. | 235 typedef void* TCmdAlign; // This wouldn't be enough align if a command used
long double. |
237 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; | 236 typedef GrTRecorder<Cmd, TCmdAlign> CmdBuffer; |
238 | 237 |
239 // overrides from GrDrawTarget | 238 // overrides from GrDrawTarget |
240 virtual void onDraw(const GrDrawState&, | 239 void onDraw(const GrDrawState&, |
241 const DrawInfo&, | 240 const DrawInfo&, |
242 const GrClipMaskManager::ScissorState&) SK_OVERRIDE; | 241 const GrClipMaskManager::ScissorState&) SK_OVERRIDE; |
243 virtual void onDrawRect(GrDrawState*, | 242 void onDrawRect(GrDrawState*, |
244 const SkRect& rect, | 243 const SkRect& rect, |
245 const SkRect* localRect, | 244 const SkRect* localRect, |
246 const SkMatrix* localMatrix) SK_OVERRIDE; | 245 const SkMatrix* localMatrix) SK_OVERRIDE; |
247 | 246 |
248 virtual void onStencilPath(const GrDrawState&, | 247 void onStencilPath(const GrDrawState&, |
249 const GrPath*, | 248 const GrPath*, |
250 const GrClipMaskManager::ScissorState&, | 249 const GrClipMaskManager::ScissorState&, |
251 const GrStencilSettings&) SK_OVERRIDE; | 250 const GrStencilSettings&) SK_OVERRIDE; |
252 virtual void onDrawPath(const GrDrawState&, | 251 void onDrawPath(const GrDrawState&, |
253 const GrPath*, | 252 const GrPath*, |
254 const GrClipMaskManager::ScissorState&, | 253 const GrClipMaskManager::ScissorState&, |
255 const GrStencilSettings&, | 254 const GrStencilSettings&, |
256 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; | 255 const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE; |
257 virtual void onDrawPaths(const GrDrawState&, | 256 void onDrawPaths(const GrDrawState&, |
258 const GrPathRange*, | 257 const GrPathRange*, |
259 const uint32_t indices[], | 258 const uint32_t indices[], |
260 int count, | 259 int count, |
261 const float transforms[], | 260 const float transforms[], |
262 PathTransformType, | 261 PathTransformType, |
263 const GrClipMaskManager::ScissorState&, | 262 const GrClipMaskManager::ScissorState&, |
264 const GrStencilSettings&, | 263 const GrStencilSettings&, |
265 const GrDeviceCoordTexture*) SK_OVERRIDE; | 264 const GrDeviceCoordTexture*) SK_OVERRIDE; |
266 virtual void onClear(const SkIRect* rect, | 265 void onClear(const SkIRect* rect, |
267 GrColor color, | 266 GrColor color, |
268 bool canIgnoreRect, | 267 bool canIgnoreRect, |
269 GrRenderTarget* renderTarget) SK_OVERRIDE; | 268 GrRenderTarget* renderTarget) SK_OVERRIDE; |
270 virtual void setDrawBuffers(DrawInfo*) SK_OVERRIDE; | 269 void setDrawBuffers(DrawInfo*) SK_OVERRIDE; |
271 | 270 |
272 virtual bool onReserveVertexSpace(size_t vertexSize, | 271 bool onReserveVertexSpace(size_t vertexSize, int vertexCount, void** vertice
s) SK_OVERRIDE; |
273 int vertexCount, | 272 bool onReserveIndexSpace(int indexCount, void** indices) SK_OVERRIDE; |
274 void** vertices) SK_OVERRIDE; | 273 void releaseReservedVertexSpace() SK_OVERRIDE; |
275 virtual bool onReserveIndexSpace(int indexCount, | 274 void releaseReservedIndexSpace() SK_OVERRIDE; |
276 void** indices) SK_OVERRIDE; | 275 void geometrySourceWillPush() SK_OVERRIDE; |
277 virtual void releaseReservedVertexSpace() SK_OVERRIDE; | 276 void geometrySourceWillPop(const GeometrySrcState& restoredState) SK_OVERRID
E; |
278 virtual void releaseReservedIndexSpace() SK_OVERRIDE; | 277 void willReserveVertexAndIndexSpace(int vertexCount, |
279 virtual void geometrySourceWillPush() SK_OVERRIDE; | 278 size_t vertexStride, |
280 virtual void geometrySourceWillPop(const GeometrySrcState& restoredState) SK
_OVERRIDE; | 279 int indexCount) SK_OVERRIDE; |
281 virtual void willReserveVertexAndIndexSpace(int vertexCount, | |
282 size_t vertexStride, | |
283 int indexCount) SK_OVERRIDE; | |
284 | 280 |
285 // Attempts to concat instances from info onto the previous draw. info must
represent an | 281 // Attempts to concat instances from info onto the previous draw. info must
represent an |
286 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. | 282 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. |
287 int concatInstancedDraw(const GrDrawState&, | 283 int concatInstancedDraw(const GrDrawState&, |
288 const DrawInfo&, | 284 const DrawInfo&, |
289 const GrClipMaskManager::ScissorState&); | 285 const GrClipMaskManager::ScissorState&); |
290 | 286 |
291 // Determines whether the current draw operation requieres a new drawstate a
nd if so records it. | 287 // Determines whether the current draw operation requires a new GrOptDrawSta
te and if so |
292 void recordStateIfNecessary(const GrDrawState&, GrGpu::DrawType, const GrDev
iceCoordTexture*); | 288 // records it. If the draw can be skipped false is returned and no new GrOpt
DrawState is |
| 289 // recorded. |
| 290 bool SK_WARN_UNUSED_RESULT recordStateAndShouldDraw(const GrDrawState&, |
| 291 GrGpu::DrawType, |
| 292 const GrDeviceCoordTextu
re*); |
293 // We lazily record clip changes in order to skip clips that have no effect. | 293 // We lazily record clip changes in order to skip clips that have no effect. |
294 void recordClipIfNecessary(); | 294 void recordClipIfNecessary(); |
295 // Records any trace markers for a command after adding it to the buffer. | 295 // Records any trace markers for a command after adding it to the buffer. |
296 void recordTraceMarkersIfNecessary(); | 296 void recordTraceMarkersIfNecessary(); |
297 | 297 |
298 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } | 298 virtual bool isIssued(uint32_t drawID) { return drawID != fDrawID; } |
299 | 299 |
300 // TODO: Use a single allocator for commands and records | 300 // TODO: Use a single allocator for commands and records |
301 enum { | 301 enum { |
302 kCmdBufferInitialSizeInBytes = 8 * 1024, | 302 kCmdBufferInitialSizeInBytes = 8 * 1024, |
303 kPathIdxBufferMinReserve = 64, | 303 kPathIdxBufferMinReserve = 64, |
304 kPathXformBufferMinReserve = 2 * kPathIdxBufferMinReserve, | 304 kPathXformBufferMinReserve = 2 * kPathIdxBufferMinReserve, |
305 kGeoPoolStatePreAllocCnt = 4, | 305 kGeoPoolStatePreAllocCnt = 4, |
306 }; | 306 }; |
307 | 307 |
308 CmdBuffer fCmdBuffer; | |
309 GrDrawState* fLastState; | |
310 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | |
311 GrGpu* fDstGpu; | |
312 GrVertexBufferAllocPool& fVertexPool; | |
313 GrIndexBufferAllocPool& fIndexPool; | |
314 SkTDArray<uint32_t> fPathIndexBuffer; | |
315 SkTDArray<float> fPathTransformBuffer; | |
316 | |
317 struct GeometryPoolState { | 308 struct GeometryPoolState { |
318 const GrVertexBuffer* fPoolVertexBuffer; | 309 const GrVertexBuffer* fPoolVertexBuffer; |
319 int fPoolStartVertex; | 310 int fPoolStartVertex; |
320 const GrIndexBuffer* fPoolIndexBuffer; | 311 const GrIndexBuffer* fPoolIndexBuffer; |
321 int fPoolStartIndex; | 312 int fPoolStartIndex; |
322 // caller may conservatively over reserve vertices / indices. | 313 // caller may conservatively over reserve vertices / indices. |
323 // we release unused space back to allocator if possible | 314 // we release unused space back to allocator if possible |
324 // can only do this if there isn't an intervening pushGeometrySource() | 315 // can only do this if there isn't an intervening pushGeometrySource() |
325 size_t fUsedPoolVertexBytes; | 316 size_t fUsedPoolVertexBytes; |
326 size_t fUsedPoolIndexBytes; | 317 size_t fUsedPoolIndexBytes; |
327 }; | 318 }; |
328 | 319 |
329 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; | 320 typedef SkSTArray<kGeoPoolStatePreAllocCnt, GeometryPoolState> GeoPoolStateS
tack; |
330 | 321 |
331 GeoPoolStateStack fGeoPoolStateStack; | 322 CmdBuffer fCmdBuffer; |
332 bool fFlushing; | 323 SkAutoTUnref<const GrOptDrawState> fLastState; |
333 uint32_t fDrawID; | 324 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; |
| 325 GrGpu* fDstGpu; |
| 326 GrVertexBufferAllocPool& fVertexPool; |
| 327 GrIndexBufferAllocPool& fIndexPool; |
| 328 SkTDArray<uint32_t> fPathIndexBuffer; |
| 329 SkTDArray<float> fPathTransformBuffer; |
| 330 GeoPoolStateStack fGeoPoolStateStack; |
| 331 bool fFlushing; |
| 332 uint32_t fDrawID; |
334 | 333 |
335 typedef GrClipTarget INHERITED; | 334 typedef GrClipTarget INHERITED; |
336 }; | 335 }; |
337 | 336 |
338 #endif | 337 #endif |
OLD | NEW |