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