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" |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 Clear* clr = this->recordClear(); | 523 Clear* clr = this->recordClear(); |
524 clr->fColor = GrColor_ILLEGAL; | 524 clr->fColor = GrColor_ILLEGAL; |
525 clr->fRenderTarget = renderTarget; | 525 clr->fRenderTarget = renderTarget; |
526 renderTarget->ref(); | 526 renderTarget->ref(); |
527 } | 527 } |
528 | 528 |
529 void GrInOrderDrawBuffer::reset() { | 529 void GrInOrderDrawBuffer::reset() { |
530 SkASSERT(1 == fGeoPoolStateStack.count()); | 530 SkASSERT(1 == fGeoPoolStateStack.count()); |
531 this->resetVertexSource(); | 531 this->resetVertexSource(); |
532 this->resetIndexSource(); | 532 this->resetIndexSource(); |
533 int numDraws = fDraws.count(); | 533 |
534 for (int d = 0; d < numDraws; ++d) { | 534 DrawAllocator::Iter drawIter(&fDraws); |
| 535 while (drawIter.next()) { |
535 // we always have a VB, but not always an IB | 536 // we always have a VB, but not always an IB |
536 SkASSERT(NULL != fDraws[d].fVertexBuffer); | 537 SkASSERT(NULL != drawIter->fVertexBuffer); |
537 fDraws[d].fVertexBuffer->unref(); | 538 drawIter->fVertexBuffer->unref(); |
538 SkSafeUnref(fDraws[d].fIndexBuffer); | 539 SkSafeUnref(drawIter->fIndexBuffer); |
539 } | 540 } |
540 fCmds.reset(); | 541 fCmds.reset(); |
541 fDraws.reset(); | 542 fDraws.reset(); |
542 fStencilPaths.reset(); | 543 fStencilPaths.reset(); |
543 fDrawPath.reset(); | 544 fDrawPath.reset(); |
544 fDrawPaths.reset(); | 545 fDrawPaths.reset(); |
545 fStates.reset(); | 546 fStates.reset(); |
546 fClears.reset(); | 547 fClears.reset(); |
547 fVertexPool.reset(); | 548 fVertexPool.reset(); |
548 fIndexPool.reset(); | 549 fIndexPool.reset(); |
(...skipping 28 matching lines...) Expand all Loading... |
577 GrDrawTarget::AutoClipRestore acr(fDstGpu); | 578 GrDrawTarget::AutoClipRestore acr(fDstGpu); |
578 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit); | 579 AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit); |
579 | 580 |
580 GrDrawState playbackState; | 581 GrDrawState playbackState; |
581 GrDrawState* prevDrawState = fDstGpu->drawState(); | 582 GrDrawState* prevDrawState = fDstGpu->drawState(); |
582 prevDrawState->ref(); | 583 prevDrawState->ref(); |
583 fDstGpu->setDrawState(&playbackState); | 584 fDstGpu->setDrawState(&playbackState); |
584 | 585 |
585 GrClipData clipData; | 586 GrClipData clipData; |
586 | 587 |
587 int currState = 0; | 588 StateAllocator::Iter stateIter(&fStates); |
588 int currClip = 0; | 589 ClipAllocator::Iter clipIter(&fClips); |
589 int currClear = 0; | 590 ClipOriginAllocator::Iter clipOriginIter(&fClipOrigins); |
590 int currDraw = 0; | 591 ClearAllocator::Iter clearIter(&fClears); |
591 int currStencilPath = 0; | 592 DrawAllocator::Iter drawIter(&fDraws); |
592 int currDrawPath = 0; | 593 StencilPathAllocator::Iter stencilPathIter(&fStencilPaths); |
593 int currDrawPaths = 0; | 594 DrawPathAllocator::Iter drawPathIter(&fDrawPath); |
594 int currCopySurface = 0; | 595 DrawPathsAllocator::Iter drawPathsIter(&fDrawPaths); |
| 596 CopySurfaceAllocator::Iter copySurfaceIter(&fCopySurfaces); |
| 597 |
595 int currCmdMarker = 0; | 598 int currCmdMarker = 0; |
596 | 599 |
597 fDstGpu->saveActiveTraceMarkers(); | 600 fDstGpu->saveActiveTraceMarkers(); |
598 for (int c = 0; c < numCmds; ++c) { | 601 for (int c = 0; c < numCmds; ++c) { |
599 GrGpuTraceMarker newMarker("", -1); | 602 GrGpuTraceMarker newMarker("", -1); |
600 if (cmd_has_trace_marker(fCmds[c])) { | 603 if (cmd_has_trace_marker(fCmds[c])) { |
601 SkString traceString = fGpuCmdMarkers[currCmdMarker].toString(); | 604 SkString traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
602 newMarker.fMarker = traceString.c_str(); | 605 newMarker.fMarker = traceString.c_str(); |
603 fDstGpu->addGpuTraceMarker(&newMarker); | 606 fDstGpu->addGpuTraceMarker(&newMarker); |
604 ++currCmdMarker; | 607 ++currCmdMarker; |
605 } | 608 } |
606 switch (strip_trace_bit(fCmds[c])) { | 609 switch (strip_trace_bit(fCmds[c])) { |
607 case kDraw_Cmd: { | 610 case kDraw_Cmd: { |
608 const DrawRecord& draw = fDraws[currDraw]; | 611 SkAssertResult(drawIter.next()); |
609 fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); | 612 fDstGpu->setVertexSourceToBuffer(drawIter->fVertexBuffer); |
610 if (draw.isIndexed()) { | 613 if (drawIter->isIndexed()) { |
611 fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); | 614 fDstGpu->setIndexSourceToBuffer(drawIter->fIndexBuffer); |
612 } | 615 } |
613 fDstGpu->executeDraw(draw); | 616 fDstGpu->executeDraw(*drawIter); |
614 ++currDraw; | |
615 break; | 617 break; |
616 } | 618 } |
617 case kStencilPath_Cmd: { | 619 case kStencilPath_Cmd: { |
618 const StencilPath& sp = fStencilPaths[currStencilPath]; | 620 SkAssertResult(stencilPathIter.next()); |
619 fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); | 621 fDstGpu->stencilPath(stencilPathIter->fPath.get(), stencilPathIt
er->fFill); |
620 ++currStencilPath; | |
621 break; | 622 break; |
622 } | 623 } |
623 case kDrawPath_Cmd: { | 624 case kDrawPath_Cmd: { |
624 const DrawPath& cp = fDrawPath[currDrawPath]; | 625 SkAssertResult(drawPathIter.next()); |
625 fDstGpu->executeDrawPath(cp.fPath.get(), cp.fFill, | 626 fDstGpu->executeDrawPath(drawPathIter->fPath.get(), drawPathIter
->fFill, |
626 NULL != cp.fDstCopy.texture() ? &cp.fDs
tCopy : NULL); | 627 NULL != drawPathIter->fDstCopy.texture(
) ? |
627 ++currDrawPath; | 628 &drawPathIter->fDstCopy : |
| 629 NULL); |
628 break; | 630 break; |
629 } | 631 } |
630 case kDrawPaths_Cmd: { | 632 case kDrawPaths_Cmd: { |
631 DrawPaths& dp = fDrawPaths[currDrawPaths]; | 633 SkAssertResult(drawPathsIter.next()); |
632 const GrDeviceCoordTexture* dstCopy = | 634 const GrDeviceCoordTexture* dstCopy = |
633 NULL != dp.fDstCopy.texture() ? &dp.fDstCopy : NULL; | 635 NULL !=drawPathsIter->fDstCopy.texture() ? &drawPathsIter->f
DstCopy : NULL; |
634 fDstGpu->executeDrawPaths(dp.fPathCount, dp.fPaths, | 636 fDstGpu->executeDrawPaths(drawPathsIter->fPathCount, drawPathsIt
er->fPaths, |
635 dp.fTransforms, dp.fFill, dp.fStroke, | 637 drawPathsIter->fTransforms, drawPathsI
ter->fFill, |
636 dstCopy); | 638 drawPathsIter->fStroke, dstCopy); |
637 ++currDrawPaths; | |
638 break; | 639 break; |
639 } | 640 } |
640 case kSetState_Cmd: | 641 case kSetState_Cmd: |
641 fStates[currState].restoreTo(&playbackState); | 642 SkAssertResult(stateIter.next()); |
642 ++currState; | 643 stateIter->restoreTo(&playbackState); |
643 break; | 644 break; |
644 case kSetClip_Cmd: | 645 case kSetClip_Cmd: |
645 clipData.fClipStack = &fClips[currClip]; | 646 SkAssertResult(clipIter.next()); |
646 clipData.fOrigin = fClipOrigins[currClip]; | 647 SkAssertResult(clipOriginIter.next()); |
| 648 clipData.fClipStack = clipIter.get(); |
| 649 clipData.fOrigin = *clipOriginIter; |
647 fDstGpu->setClip(&clipData); | 650 fDstGpu->setClip(&clipData); |
648 ++currClip; | |
649 break; | 651 break; |
650 case kClear_Cmd: | 652 case kClear_Cmd: |
651 if (GrColor_ILLEGAL == fClears[currClear].fColor) { | 653 SkAssertResult(clearIter.next()); |
652 fDstGpu->discard(fClears[currClear].fRenderTarget); | 654 if (GrColor_ILLEGAL == clearIter->fColor) { |
| 655 fDstGpu->discard(clearIter->fRenderTarget); |
653 } else { | 656 } else { |
654 fDstGpu->clear(&fClears[currClear].fRect, | 657 fDstGpu->clear(&clearIter->fRect, |
655 fClears[currClear].fColor, | 658 clearIter->fColor, |
656 fClears[currClear].fCanIgnoreRect, | 659 clearIter->fCanIgnoreRect, |
657 fClears[currClear].fRenderTarget); | 660 clearIter->fRenderTarget); |
658 } | 661 } |
659 ++currClear; | |
660 break; | 662 break; |
661 case kCopySurface_Cmd: | 663 case kCopySurface_Cmd: |
662 fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), | 664 SkAssertResult(copySurfaceIter.next()); |
663 fCopySurfaces[currCopySurface].fSrc.get(), | 665 fDstGpu->copySurface(copySurfaceIter->fDst.get(), |
664 fCopySurfaces[currCopySurface].fSrcRect, | 666 copySurfaceIter->fSrc.get(), |
665 fCopySurfaces[currCopySurface].fDstPoint); | 667 copySurfaceIter->fSrcRect, |
666 ++currCopySurface; | 668 copySurfaceIter->fDstPoint); |
667 break; | 669 break; |
668 } | 670 } |
669 if (cmd_has_trace_marker(fCmds[c])) { | 671 if (cmd_has_trace_marker(fCmds[c])) { |
670 fDstGpu->removeGpuTraceMarker(&newMarker); | 672 fDstGpu->removeGpuTraceMarker(&newMarker); |
671 } | 673 } |
672 } | 674 } |
673 fDstGpu->restoreActiveTraceMarkers(); | 675 fDstGpu->restoreActiveTraceMarkers(); |
674 // we should have consumed all the states, clips, etc. | 676 // we should have consumed all the states, clips, etc. |
675 SkASSERT(fStates.count() == currState); | 677 SkASSERT(!stateIter.next()); |
676 SkASSERT(fClips.count() == currClip); | 678 SkASSERT(!clipIter.next()); |
677 SkASSERT(fClipOrigins.count() == currClip); | 679 SkASSERT(!clipOriginIter.next()); |
678 SkASSERT(fClears.count() == currClear); | 680 SkASSERT(!clearIter.next()); |
679 SkASSERT(fDraws.count() == currDraw); | 681 SkASSERT(!drawIter.next()); |
680 SkASSERT(fCopySurfaces.count() == currCopySurface); | 682 SkASSERT(!copySurfaceIter.next()); |
| 683 SkASSERT(!stencilPathIter.next()); |
| 684 SkASSERT(!drawPathIter.next()); |
| 685 SkASSERT(!drawPathsIter.next()); |
| 686 |
681 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); | 687 SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
682 | 688 |
683 fDstGpu->setDrawState(prevDrawState); | 689 fDstGpu->setDrawState(prevDrawState); |
684 prevDrawState->unref(); | 690 prevDrawState->unref(); |
685 this->reset(); | 691 this->reset(); |
686 ++fDrawID; | 692 ++fDrawID; |
687 } | 693 } |
688 | 694 |
689 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, | 695 bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
690 GrSurface* src, | 696 GrSurface* src, |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 this->addToCmdBuffer(kCopySurface_Cmd); | 992 this->addToCmdBuffer(kCopySurface_Cmd); |
987 return &fCopySurfaces.push_back(); | 993 return &fCopySurfaces.push_back(); |
988 } | 994 } |
989 | 995 |
990 | 996 |
991 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { | 997 void GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { |
992 INHERITED::clipWillBeSet(newClipData); | 998 INHERITED::clipWillBeSet(newClipData); |
993 fClipSet = true; | 999 fClipSet = true; |
994 fClipProxyState = kUnknown_ClipProxyState; | 1000 fClipProxyState = kUnknown_ClipProxyState; |
995 } | 1001 } |
OLD | NEW |