| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2015 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 GrTargetCommands_DEFINED |
| 9 #define GrInOrderDrawBuffer_DEFINED | 9 #define GrTargetCommands_DEFINED |
| 10 | 10 |
| 11 #include "GrFlushToGpuDrawTarget.h" | |
| 12 | |
| 13 #include "GrBatch.h" | |
| 14 #include "GrBatchTarget.h" | 11 #include "GrBatchTarget.h" |
| 15 #include "SkChunkAlloc.h" | 12 #include "GrDrawTarget.h" |
| 16 #include "GrPipeline.h" | 13 #include "GrGpu.h" |
| 17 #include "GrPath.h" | 14 #include "GrPath.h" |
| 15 #include "GrPendingProgramElement.h" |
| 16 #include "GrRenderTarget.h" |
| 18 #include "GrTRecorder.h" | 17 #include "GrTRecorder.h" |
| 18 #include "SkRect.h" |
| 19 #include "SkTypes.h" |
| 19 | 20 |
| 20 class GrInOrderDrawBuffer; | 21 class GrInOrderDrawBuffer; |
| 22 class GrVertexBufferAllocPool; |
| 23 class GrIndexBufferAllocPool; |
| 21 | 24 |
| 22 class GrTargetCommands : ::SkNoncopyable { | 25 class GrTargetCommands : ::SkNoncopyable { |
| 23 struct SetState; | 26 struct SetState; |
| 24 | 27 |
| 25 public: | 28 public: |
| 26 GrTargetCommands(GrGpu* gpu, | 29 GrTargetCommands(GrGpu* gpu, |
| 27 GrVertexBufferAllocPool* vertexPool, | 30 GrVertexBufferAllocPool* vertexPool, |
| 28 GrIndexBufferAllocPool* indexPool) | 31 GrIndexBufferAllocPool* indexPool) |
| 29 : fCmdBuffer(kCmdBufferInitialSizeInBytes) | 32 : fCmdBuffer(kCmdBufferInitialSizeInBytes) |
| 30 , fPrevState(NULL) | 33 , fPrevState(NULL) |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 SetState* fPrevState; | 298 SetState* fPrevState; |
| 296 GrBatchTarget fBatchTarget; | 299 GrBatchTarget fBatchTarget; |
| 297 // TODO hack until batch is everywhere | 300 // TODO hack until batch is everywhere |
| 298 GrTargetCommands::DrawBatch* fDrawBatch; | 301 GrTargetCommands::DrawBatch* fDrawBatch; |
| 299 | 302 |
| 300 // This will go away when everything uses batch. However, in the short ter
m anything which | 303 // This will go away when everything uses batch. However, in the short ter
m anything which |
| 301 // might be put into the GrInOrderDrawBuffer needs to make sure it closes t
he last batch | 304 // might be put into the GrInOrderDrawBuffer needs to make sure it closes t
he last batch |
| 302 void closeBatch(); | 305 void closeBatch(); |
| 303 }; | 306 }; |
| 304 | 307 |
| 305 /** | 308 #endif |
| 306 * GrInOrderDrawBuffer is an implementation of GrDrawTarget that queues up draws
for eventual | |
| 307 * playback into a GrGpu. In theory one draw buffer could playback into another.
When index or | |
| 308 * vertex buffers are used as geometry sources it is the callers the draw buffer
only holds | |
| 309 * references to the buffers. It is the callers responsibility to ensure that th
e data is still | |
| 310 * valid when the draw buffer is played back into a GrGpu. Similarly, it is the
caller's | |
| 311 * responsibility to ensure that all referenced textures, buffers, and render-ta
rgets are associated | |
| 312 * in the GrGpu object that the buffer is played back into. The buffer requires
VB and IB pools to | |
| 313 * store geometry. | |
| 314 */ | |
| 315 class GrInOrderDrawBuffer : public GrFlushToGpuDrawTarget { | |
| 316 public: | |
| 317 | 309 |
| 318 /** | |
| 319 * Creates a GrInOrderDrawBuffer | |
| 320 * | |
| 321 * @param gpu the gpu object that this draw buffer flushes to. | |
| 322 * @param vertexPool pool where vertices for queued draws will be saved when | |
| 323 * the vertex source is either reserved or array. | |
| 324 * @param indexPool pool where indices for queued draws will be saved when | |
| 325 * the index source is either reserved or array. | |
| 326 */ | |
| 327 GrInOrderDrawBuffer(GrGpu* gpu, | |
| 328 GrVertexBufferAllocPool* vertexPool, | |
| 329 GrIndexBufferAllocPool* indexPool); | |
| 330 | |
| 331 ~GrInOrderDrawBuffer() SK_OVERRIDE; | |
| 332 | |
| 333 // tracking for draws | |
| 334 DrawToken getCurrentDrawToken() SK_OVERRIDE { return DrawToken(this, fDrawID
); } | |
| 335 | |
| 336 void clearStencilClip(const SkIRect& rect, | |
| 337 bool insideClip, | |
| 338 GrRenderTarget* renderTarget) SK_OVERRIDE; | |
| 339 | |
| 340 void discard(GrRenderTarget*) SK_OVERRIDE; | |
| 341 | |
| 342 protected: | |
| 343 void willReserveVertexAndIndexSpace(int vertexCount, | |
| 344 size_t vertexStride, | |
| 345 int indexCount) SK_OVERRIDE; | |
| 346 | |
| 347 void appendIndicesAndTransforms(const void* indexValues, PathIndexType index
Type, | |
| 348 const float* transformValues, PathTransformT
ype transformType, | |
| 349 int count, char** indicesLocation, float** x
formsLocation) { | |
| 350 int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); | |
| 351 *indicesLocation = (char*) fPathIndexBuffer.alloc(count * indexBytes, | |
| 352 SkChunkAlloc::kThrow_A
llocFailType); | |
| 353 SkASSERT(SkIsAlign4((uintptr_t)*indicesLocation)); | |
| 354 memcpy(*indicesLocation, reinterpret_cast<const char*>(indexValues), cou
nt * indexBytes); | |
| 355 | |
| 356 const int xformBytes = GrPathRendering::PathTransformSize(transformType)
* sizeof(float); | |
| 357 *xformsLocation = NULL; | |
| 358 | |
| 359 if (0 != xformBytes) { | |
| 360 *xformsLocation = (float*) fPathTransformBuffer.alloc(count * xformB
ytes, | |
| 361 SkChunkAlloc::kTh
row_AllocFailType); | |
| 362 SkASSERT(SkIsAlign4((uintptr_t)*xformsLocation)); | |
| 363 memcpy(*xformsLocation, transformValues, count * xformBytes); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 bool canConcatToIndexBuffer(const GrIndexBuffer** ib) { | |
| 368 const GrDrawTarget::GeometrySrcState& geomSrc = this->getGeomSrc(); | |
| 369 | |
| 370 // we only attempt to concat when reserved verts are used with a client-
specified | |
| 371 // index buffer. To make this work with client-specified VBs we'd need t
o know if the VB | |
| 372 // was updated between draws. | |
| 373 if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || | |
| 374 kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { | |
| 375 return false; | |
| 376 } | |
| 377 | |
| 378 *ib = geomSrc.fIndexBuffer; | |
| 379 return true; | |
| 380 } | |
| 381 | |
| 382 private: | |
| 383 friend class GrTargetCommands; | |
| 384 | |
| 385 typedef GrGpu::DrawArgs DrawArgs; | |
| 386 | |
| 387 void onReset() SK_OVERRIDE; | |
| 388 void onFlush() SK_OVERRIDE; | |
| 389 | |
| 390 // overrides from GrDrawTarget | |
| 391 void onDraw(const GrGeometryProcessor*, const DrawInfo&, const PipelineInfo&
) SK_OVERRIDE; | |
| 392 void onDrawBatch(GrBatch*, const PipelineInfo&) SK_OVERRIDE; | |
| 393 void onDrawRect(GrPipelineBuilder*, | |
| 394 GrColor, | |
| 395 const SkMatrix& viewMatrix, | |
| 396 const SkRect& rect, | |
| 397 const SkRect* localRect, | |
| 398 const SkMatrix* localMatrix) SK_OVERRIDE; | |
| 399 | |
| 400 void onStencilPath(const GrPipelineBuilder&, | |
| 401 const GrPathProcessor*, | |
| 402 const GrPath*, | |
| 403 const GrScissorState&, | |
| 404 const GrStencilSettings&) SK_OVERRIDE; | |
| 405 void onDrawPath(const GrPathProcessor*, | |
| 406 const GrPath*, | |
| 407 const GrStencilSettings&, | |
| 408 const PipelineInfo&) SK_OVERRIDE; | |
| 409 void onDrawPaths(const GrPathProcessor*, | |
| 410 const GrPathRange*, | |
| 411 const void* indices, | |
| 412 PathIndexType, | |
| 413 const float transformValues[], | |
| 414 PathTransformType, | |
| 415 int count, | |
| 416 const GrStencilSettings&, | |
| 417 const PipelineInfo&) SK_OVERRIDE; | |
| 418 void onClear(const SkIRect* rect, | |
| 419 GrColor color, | |
| 420 bool canIgnoreRect, | |
| 421 GrRenderTarget* renderTarget) SK_OVERRIDE; | |
| 422 bool onCopySurface(GrSurface* dst, | |
| 423 GrSurface* src, | |
| 424 const SkIRect& srcRect, | |
| 425 const SkIPoint& dstPoint) SK_OVERRIDE; | |
| 426 | |
| 427 // Attempts to concat instances from info onto the previous draw. info must
represent an | |
| 428 // instanced draw. The caller must have already recorded a new draw state an
d clip if necessary. | |
| 429 int concatInstancedDraw(const DrawInfo&); | |
| 430 | |
| 431 // We lazily record clip changes in order to skip clips that have no effect. | |
| 432 void recordClipIfNecessary(); | |
| 433 // Records any trace markers for a command | |
| 434 void recordTraceMarkersIfNecessary(GrTargetCommands::Cmd*); | |
| 435 SkString getCmdString(int index) const { | |
| 436 SkASSERT(index < fGpuCmdMarkers.count()); | |
| 437 return fGpuCmdMarkers[index].toString(); | |
| 438 } | |
| 439 bool isIssued(uint32_t drawID) SK_OVERRIDE { return drawID != fDrawID; } | |
| 440 | |
| 441 // TODO: Use a single allocator for commands and records | |
| 442 enum { | |
| 443 kPathIdxBufferMinReserve = 2 * 64, // 64 uint16_t's | |
| 444 kPathXformBufferMinReserve = 2 * 64, // 64 two-float transforms | |
| 445 }; | |
| 446 | |
| 447 GrTargetCommands fCommands; | |
| 448 SkTArray<GrTraceMarkerSet, false> fGpuCmdMarkers; | |
| 449 SkChunkAlloc fPathIndexBuffer; | |
| 450 SkChunkAlloc fPathTransformBuffer; | |
| 451 uint32_t fDrawID; | |
| 452 | |
| 453 typedef GrFlushToGpuDrawTarget INHERITED; | |
| 454 }; | |
| 455 | |
| 456 #endif | |
| OLD | NEW |