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 #include "GrInOrderDrawBuffer.h" | 8 #include "GrInOrderDrawBuffer.h" |
9 | 9 |
10 #include "GrBufferAllocPool.h" | 10 #include "GrBufferAllocPool.h" |
11 #include "GrDefaultGeoProcFactory.h" | 11 #include "GrDefaultGeoProcFactory.h" |
12 #include "GrDrawTargetCaps.h" | 12 #include "GrDrawTargetCaps.h" |
13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
14 #include "GrTemplates.h" | 14 #include "GrTemplates.h" |
15 #include "GrTextStrike.h" | 15 #include "GrTextStrike.h" |
16 #include "GrTexture.h" | 16 #include "GrTexture.h" |
17 | 17 |
18 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, | 18 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, |
19 GrVertexBufferAllocPool* vertexPool, | 19 GrVertexBufferAllocPool* vertexPool, |
20 GrIndexBufferAllocPool* indexPool) | 20 GrIndexBufferAllocPool* indexPool) |
21 : INHERITED(gpu->getContext()) | 21 : INHERITED(gpu->getContext()) |
22 , fCmdBuffer(kCmdBufferInitialSizeInBytes) | 22 , fCmdBuffer(kCmdBufferInitialSizeInBytes) |
23 , fLastState(NULL) | 23 , fPrevState(NULL) |
24 , fDstGpu(gpu) | 24 , fDstGpu(gpu) |
25 , fVertexPool(*vertexPool) | 25 , fVertexPool(*vertexPool) |
26 , fIndexPool(*indexPool) | 26 , fIndexPool(*indexPool) |
27 , fFlushing(false) | 27 , fFlushing(false) |
28 , fDrawID(0) { | 28 , fDrawID(0) { |
29 | 29 |
30 fDstGpu->ref(); | 30 fDstGpu->ref(); |
31 fCaps.reset(SkRef(fDstGpu->caps())); | 31 fCaps.reset(SkRef(fDstGpu->caps())); |
32 | 32 |
33 SkASSERT(vertexPool); | 33 SkASSERT(vertexPool); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 428 } |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 void GrInOrderDrawBuffer::reset() { | 432 void GrInOrderDrawBuffer::reset() { |
433 SkASSERT(1 == fGeoPoolStateStack.count()); | 433 SkASSERT(1 == fGeoPoolStateStack.count()); |
434 this->resetVertexSource(); | 434 this->resetVertexSource(); |
435 this->resetIndexSource(); | 435 this->resetIndexSource(); |
436 | 436 |
437 fCmdBuffer.reset(); | 437 fCmdBuffer.reset(); |
438 fLastState.reset(NULL); | 438 fPrevState = NULL; |
439 fVertexPool.reset(); | 439 fVertexPool.reset(); |
440 fIndexPool.reset(); | 440 fIndexPool.reset(); |
441 reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve); | 441 reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve); |
442 reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve); | 442 reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve); |
443 fGpuCmdMarkers.reset(); | 443 fGpuCmdMarkers.reset(); |
444 } | 444 } |
445 | 445 |
446 void GrInOrderDrawBuffer::flush() { | 446 void GrInOrderDrawBuffer::flush() { |
447 if (fFlushing) { | 447 if (fFlushing) { |
448 return; | 448 return; |
(...skipping 14 matching lines...) Expand all Loading... |
463 fVertexPool.unmap(); | 463 fVertexPool.unmap(); |
464 fIndexPool.unmap(); | 464 fIndexPool.unmap(); |
465 | 465 |
466 CmdBuffer::Iter iter(fCmdBuffer); | 466 CmdBuffer::Iter iter(fCmdBuffer); |
467 | 467 |
468 int currCmdMarker = 0; | 468 int currCmdMarker = 0; |
469 fDstGpu->saveActiveTraceMarkers(); | 469 fDstGpu->saveActiveTraceMarkers(); |
470 | 470 |
471 // Updated every time we find a set state cmd to reflect the current state i
n the playback | 471 // Updated every time we find a set state cmd to reflect the current state i
n the playback |
472 // stream. | 472 // stream. |
473 SkAutoTUnref<const GrOptDrawState> currentOptState; | 473 const GrOptDrawState* currentOptState = NULL; |
474 | 474 |
475 while (iter.next()) { | 475 while (iter.next()) { |
476 GrGpuTraceMarker newMarker("", -1); | 476 GrGpuTraceMarker newMarker("", -1); |
477 SkString traceString; | 477 SkString traceString; |
478 if (cmd_has_trace_marker(iter->fType)) { | 478 if (cmd_has_trace_marker(iter->fType)) { |
479 traceString = fGpuCmdMarkers[currCmdMarker].toString(); | 479 traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
480 newMarker.fMarker = traceString.c_str(); | 480 newMarker.fMarker = traceString.c_str(); |
481 fDstGpu->addGpuTraceMarker(&newMarker); | 481 fDstGpu->addGpuTraceMarker(&newMarker); |
482 ++currCmdMarker; | 482 ++currCmdMarker; |
483 } | 483 } |
484 | 484 |
485 if (kSetState_Cmd == strip_trace_bit(iter->fType)) { | 485 if (kSetState_Cmd == strip_trace_bit(iter->fType)) { |
486 SetState* ss = reinterpret_cast<SetState*>(iter.get()); | 486 SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
487 currentOptState.reset(SkRef(ss->fState.get())); | 487 currentOptState = &ss->fState; |
488 } else { | 488 } else { |
489 iter->execute(this, currentOptState.get()); | 489 iter->execute(this, currentOptState); |
490 } | 490 } |
491 | 491 |
492 if (cmd_has_trace_marker(iter->fType)) { | 492 if (cmd_has_trace_marker(iter->fType)) { |
493 fDstGpu->removeGpuTraceMarker(&newMarker); | 493 fDstGpu->removeGpuTraceMarker(&newMarker); |
494 } | 494 } |
495 } | 495 } |
496 | 496 |
497 fDstGpu->restoreActiveTraceMarkers(); | 497 fDstGpu->restoreActiveTraceMarkers(); |
498 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); | 498 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
499 | 499 |
500 this->reset(); | 500 this->reset(); |
501 ++fDrawID; | 501 ++fDrawID; |
502 } | 502 } |
503 | 503 |
504 void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const GrOptDra
wState* optState) { | 504 void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const GrOptDra
wState* optState) { |
| 505 SkASSERT(optState); |
505 buf->fDstGpu->draw(*optState, fInfo); | 506 buf->fDstGpu->draw(*optState, fInfo); |
506 } | 507 } |
507 | 508 |
508 void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, | 509 void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, |
509 const GrOptDrawState* optState) { | 510 const GrOptDrawState* optState) { |
| 511 SkASSERT(optState); |
510 buf->fDstGpu->stencilPath(*optState, this->path(), fStencilSettings); | 512 buf->fDstGpu->stencilPath(*optState, this->path(), fStencilSettings); |
511 } | 513 } |
512 | 514 |
513 void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, | 515 void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, |
514 const GrOptDrawState* optState) { | 516 const GrOptDrawState* optState) { |
| 517 SkASSERT(optState); |
515 buf->fDstGpu->drawPath(*optState, this->path(), fStencilSettings); | 518 buf->fDstGpu->drawPath(*optState, this->path(), fStencilSettings); |
516 } | 519 } |
517 | 520 |
518 void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, | 521 void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, |
519 const GrOptDrawState* optState) { | 522 const GrOptDrawState* optState) { |
| 523 SkASSERT(optState); |
520 buf->fDstGpu->drawPaths(*optState, this->pathRange(), | 524 buf->fDstGpu->drawPaths(*optState, this->pathRange(), |
521 &buf->fPathIndexBuffer[fIndicesLocation], fCount, | 525 &buf->fPathIndexBuffer[fIndicesLocation], fCount, |
522 &buf->fPathTransformBuffer[fTransformsLocation], fTr
ansformsType, | 526 &buf->fPathTransformBuffer[fTransformsLocation], fTr
ansformsType, |
523 fStencilSettings); | 527 fStencilSettings); |
524 } | 528 } |
525 | 529 |
526 void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDra
wState*) { | 530 void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const GrOptDra
wState*) {} |
527 } | |
528 | 531 |
529 void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const GrOptDr
awState*) { | 532 void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const GrOptDr
awState*) { |
530 if (GrColor_ILLEGAL == fColor) { | 533 if (GrColor_ILLEGAL == fColor) { |
531 buf->fDstGpu->discard(this->renderTarget()); | 534 buf->fDstGpu->discard(this->renderTarget()); |
532 } else { | 535 } else { |
533 buf->fDstGpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()
); | 536 buf->fDstGpu->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()
); |
534 } | 537 } |
535 } | 538 } |
536 | 539 |
537 void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf, | 540 void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 } | 723 } |
721 if (kReserved_GeometrySrcType == restoredState.fIndexSrc) { | 724 if (kReserved_GeometrySrcType == restoredState.fIndexSrc) { |
722 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * restoredState.fIndexC
ount; | 725 poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * restoredState.fIndexC
ount; |
723 } | 726 } |
724 } | 727 } |
725 | 728 |
726 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, | 729 bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, |
727 GrGpu::DrawType drawType, | 730 GrGpu::DrawType drawType, |
728 const GrClipMaskManager::Scis
sorState& scissor, | 731 const GrClipMaskManager::Scis
sorState& scissor, |
729 const GrDeviceCoordTexture* d
stCopy) { | 732 const GrDeviceCoordTexture* d
stCopy) { |
730 SkAutoTUnref<GrOptDrawState> optState( | 733 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
731 SkNEW_ARGS(GrOptDrawState, (ds, fDstGpu, scissor, dstCopy, drawType))); | 734 (ds, fDstGpu, scissor, dstCopy, draw
Type)); |
732 if (optState->mustSkip()) { | 735 if (ss->fState.mustSkip()) { |
| 736 fCmdBuffer.pop_back(); |
733 return false; | 737 return false; |
734 } | 738 } |
735 if (!fLastState || *optState != *fLastState) { | 739 if (fPrevState && *fPrevState == ss->fState) { |
736 SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (optState)
); | 740 fCmdBuffer.pop_back(); |
737 fLastState.reset(SkRef(optState.get())); | 741 } else { |
738 ss->fDrawType = drawType; | 742 fPrevState = &ss->fState; |
739 this->recordTraceMarkersIfNecessary(); | 743 this->recordTraceMarkersIfNecessary(); |
740 } | 744 } |
741 return true; | 745 return true; |
742 } | 746 } |
743 | 747 |
744 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { | 748 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
745 SkASSERT(!fCmdBuffer.empty()); | 749 SkASSERT(!fCmdBuffer.empty()); |
746 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); | 750 SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |
747 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 751 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
748 if (activeTraceMarkers.count() > 0) { | 752 if (activeTraceMarkers.count() > 0) { |
749 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); | 753 fCmdBuffer.back().fType = add_trace_bit(fCmdBuffer.back().fType); |
750 fGpuCmdMarkers.push_back(activeTraceMarkers); | 754 fGpuCmdMarkers.push_back(activeTraceMarkers); |
751 } | 755 } |
752 } | 756 } |
OLD | NEW |