OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkLayerInfo.h" |
8 #include "SkRecordDraw.h" | 9 #include "SkRecordDraw.h" |
9 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
10 | 11 |
11 #if SK_SUPPORT_GPU | |
12 #include "GrPictureUtils.h" | |
13 #endif | |
14 | |
15 void SkRecordDraw(const SkRecord& record, | 12 void SkRecordDraw(const SkRecord& record, |
16 SkCanvas* canvas, | 13 SkCanvas* canvas, |
17 const SkBBoxHierarchy* bbh, | 14 const SkBBoxHierarchy* bbh, |
18 SkDrawPictureCallback* callback) { | 15 SkDrawPictureCallback* callback) { |
19 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 16 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
20 | 17 |
21 if (bbh) { | 18 if (bbh) { |
22 // Draw only ops that affect pixels in the canvas's current clip. | 19 // Draw only ops that affect pixels in the canvas's current clip. |
23 // The SkRecord and BBH were recorded in identity space. This canvas | 20 // The SkRecord and BBH were recorded in identity space. This canvas |
24 // is not necessarily in that same space. getClipBounds() returns us | 21 // is not necessarily in that same space. getClipBounds() returns us |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 // identity-space bounds of the current clip (fCurrentClipBounds). | 560 // identity-space bounds of the current clip (fCurrentClipBounds). |
564 unsigned fCurrentOp; | 561 unsigned fCurrentOp; |
565 const SkMatrix* fCTM; | 562 const SkMatrix* fCTM; |
566 Bounds fCurrentClipBounds; | 563 Bounds fCurrentClipBounds; |
567 | 564 |
568 // Used to track the bounds of Save/Restore blocks and the control ops insid
e them. | 565 // Used to track the bounds of Save/Restore blocks and the control ops insid
e them. |
569 SkTDArray<SaveBounds> fSaveStack; | 566 SkTDArray<SaveBounds> fSaveStack; |
570 SkTDArray<unsigned> fControlIndices; | 567 SkTDArray<unsigned> fControlIndices; |
571 }; | 568 }; |
572 | 569 |
573 #if SK_SUPPORT_GPU | |
574 // SkRecord visitor to gather saveLayer/restore information. | 570 // SkRecord visitor to gather saveLayer/restore information. |
575 class CollectLayers : SkNoncopyable { | 571 class CollectLayers : SkNoncopyable { |
576 public: | 572 public: |
577 CollectLayers(const SkRect& cullRect, const SkRecord& record, GrAccelData* a
ccelData) | 573 CollectLayers(const SkRect& cullRect, const SkRecord& record, SkLayerInfo* a
ccelData) |
578 : fSaveLayersInStack(0) | 574 : fSaveLayersInStack(0) |
579 , fAccelData(accelData) | 575 , fAccelData(accelData) |
580 , fFillBounds(cullRect, record) { | 576 , fFillBounds(cullRect, record) { |
581 } | 577 } |
582 | 578 |
583 void setCurrentOp(unsigned currentOp) { fFillBounds.setCurrentOp(currentOp);
} | 579 void setCurrentOp(unsigned currentOp) { fFillBounds.setCurrentOp(currentOp);
} |
584 | 580 |
585 void cleanUp(SkBBoxHierarchy* bbh) { | 581 void cleanUp(SkBBoxHierarchy* bbh) { |
586 // fFillBounds must perform its cleanUp first so that all the bounding | 582 // fFillBounds must perform its cleanUp first so that all the bounding |
587 // boxes associated with unbalanced restores are updated (prior to | 583 // boxes associated with unbalanced restores are updated (prior to |
(...skipping 29 matching lines...) Expand all Loading... |
617 template <typename T> void trackSaveLayers(const T& op) { | 613 template <typename T> void trackSaveLayers(const T& op) { |
618 /* most ops aren't involved in saveLayers */ | 614 /* most ops aren't involved in saveLayers */ |
619 } | 615 } |
620 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL);
} | 616 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL);
} |
621 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl
.paint); } | 617 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl
.paint); } |
622 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } | 618 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } |
623 | 619 |
624 void trackSaveLayers(const DrawPicture& dp) { | 620 void trackSaveLayers(const DrawPicture& dp) { |
625 // For sub-pictures, we wrap their layer information within the parent | 621 // For sub-pictures, we wrap their layer information within the parent |
626 // picture's rendering hierarchy | 622 // picture's rendering hierarchy |
627 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); | 623 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
628 | 624 |
629 const GrAccelData* childData = | 625 const SkLayerInfo* childData = |
630 static_cast<const GrAccelData*>(dp.picture->EXPERIMENTAL_getAccelDat
a(key)); | 626 static_cast<const SkLayerInfo*>(dp.picture->EXPERIMENTAL_getAccelDat
a(key)); |
631 if (!childData) { | 627 if (!childData) { |
632 // If the child layer hasn't been generated with saveLayer data we | 628 // If the child layer hasn't been generated with saveLayer data we |
633 // assume the worst (i.e., that it does contain layers which nest | 629 // assume the worst (i.e., that it does contain layers which nest |
634 // inside existing layers). Layers within sub-pictures that don't | 630 // inside existing layers). Layers within sub-pictures that don't |
635 // have saveLayer data cannot be hoisted. | 631 // have saveLayer data cannot be hoisted. |
636 // TODO: could the analysis data be use to fine tune this? | 632 // TODO: could the analysis data be use to fine tune this? |
637 this->updateStackForSaveLayer(); | 633 this->updateStackForSaveLayer(); |
638 return; | 634 return; |
639 } | 635 } |
640 | 636 |
641 for (int i = 0; i < childData->numSaveLayers(); ++i) { | 637 for (int i = 0; i < childData->numBlocks(); ++i) { |
642 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); | 638 const SkLayerInfo::BlockInfo& src = childData->block(i); |
643 | 639 |
644 FillBounds::Bounds newBound = fFillBounds.adjustAndMap(src.fBounds,
dp.paint); | 640 FillBounds::Bounds newBound = fFillBounds.adjustAndMap(src.fBounds,
dp.paint); |
645 if (newBound.isEmpty()) { | 641 if (newBound.isEmpty()) { |
646 continue; | 642 continue; |
647 } | 643 } |
648 | 644 |
649 this->updateStackForSaveLayer(); | 645 this->updateStackForSaveLayer(); |
650 | 646 |
651 GrAccelData::SaveLayerInfo& dst = fAccelData->addSaveLayerInfo(); | 647 SkLayerInfo::BlockInfo& dst = fAccelData->addBlock(); |
652 | 648 |
653 // If src.fPicture is NULL the layer is in dp.picture; otherwise | 649 // If src.fPicture is NULL the layer is in dp.picture; otherwise |
654 // it belongs to a sub-picture. | 650 // it belongs to a sub-picture. |
655 dst.fPicture = src.fPicture ? src.fPicture : static_cast<const SkPic
ture*>(dp.picture); | 651 dst.fPicture = src.fPicture ? src.fPicture : static_cast<const SkPic
ture*>(dp.picture); |
656 dst.fPicture->ref(); | 652 dst.fPicture->ref(); |
657 dst.fBounds = newBound; | 653 dst.fBounds = newBound; |
658 dst.fLocalMat = src.fLocalMat; | 654 dst.fLocalMat = src.fLocalMat; |
659 dst.fPreMat = src.fPreMat; | 655 dst.fPreMat = src.fPreMat; |
660 dst.fPreMat.postConcat(fFillBounds.ctm()); | 656 dst.fPreMat.postConcat(fFillBounds.ctm()); |
661 if (src.fPaint) { | 657 if (src.fPaint) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 | 695 |
700 SaveLayerInfo sli; | 696 SaveLayerInfo sli; |
701 fSaveLayerStack.pop(&sli); | 697 fSaveLayerStack.pop(&sli); |
702 | 698 |
703 if (!sli.fIsSaveLayer) { | 699 if (!sli.fIsSaveLayer) { |
704 return; | 700 return; |
705 } | 701 } |
706 | 702 |
707 --fSaveLayersInStack; | 703 --fSaveLayersInStack; |
708 | 704 |
709 GrAccelData::SaveLayerInfo& slInfo = fAccelData->addSaveLayerInfo(); | 705 SkLayerInfo::BlockInfo& block = fAccelData->addBlock(); |
710 | 706 |
711 SkASSERT(NULL == slInfo.fPicture); // This layer is in the top-most pic
ture | 707 SkASSERT(NULL == block.fPicture); // This layer is in the top-most pict
ure |
712 | 708 |
713 slInfo.fBounds = fFillBounds.getBounds(sli.fStartIndex); | 709 block.fBounds = fFillBounds.getBounds(sli.fStartIndex); |
714 slInfo.fLocalMat = fFillBounds.ctm(); | 710 block.fLocalMat = fFillBounds.ctm(); |
715 slInfo.fPreMat = SkMatrix::I(); | 711 block.fPreMat = SkMatrix::I(); |
716 if (sli.fPaint) { | 712 if (sli.fPaint) { |
717 slInfo.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint)); | 713 block.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint)); |
718 } | 714 } |
719 slInfo.fSaveLayerOpID = sli.fStartIndex; | 715 block.fSaveLayerOpID = sli.fStartIndex; |
720 slInfo.fRestoreOpID = fFillBounds.currentOp(); | 716 block.fRestoreOpID = fFillBounds.currentOp(); |
721 slInfo.fHasNestedLayers = sli.fHasNestedSaveLayer; | 717 block.fHasNestedLayers = sli.fHasNestedSaveLayer; |
722 slInfo.fIsNested = fSaveLayersInStack > 0; | 718 block.fIsNested = fSaveLayersInStack > 0; |
723 } | 719 } |
724 | 720 |
725 // Used to collect saveLayer information for layer hoisting | 721 // Used to collect saveLayer information for layer hoisting |
726 int fSaveLayersInStack; | 722 int fSaveLayersInStack; |
727 SkTDArray<SaveLayerInfo> fSaveLayerStack; | 723 SkTDArray<SaveLayerInfo> fSaveLayerStack; |
728 GrAccelData* fAccelData; | 724 SkLayerInfo* fAccelData; |
729 | 725 |
730 SkRecords::FillBounds fFillBounds; | 726 SkRecords::FillBounds fFillBounds; |
731 }; | 727 }; |
732 #endif | |
733 | 728 |
734 } // namespace SkRecords | 729 } // namespace SkRecords |
735 | 730 |
736 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkBBoxHi
erarchy* bbh) { | 731 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkBBoxHi
erarchy* bbh) { |
737 SkRecords::FillBounds visitor(cullRect, record); | 732 SkRecords::FillBounds visitor(cullRect, record); |
738 | 733 |
739 for (unsigned curOp = 0; curOp < record.count(); curOp++) { | 734 for (unsigned curOp = 0; curOp < record.count(); curOp++) { |
740 visitor.setCurrentOp(curOp); | 735 visitor.setCurrentOp(curOp); |
741 record.visit<void>(curOp, visitor); | 736 record.visit<void>(curOp, visitor); |
742 } | 737 } |
743 | 738 |
744 visitor.cleanUp(bbh); | 739 visitor.cleanUp(bbh); |
745 } | 740 } |
746 | 741 |
747 #if SK_SUPPORT_GPU | |
748 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, | 742 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, |
749 SkBBoxHierarchy* bbh, GrAccelData* data) { | 743 SkBBoxHierarchy* bbh, SkLayerInfo* data) { |
750 SkRecords::CollectLayers visitor(cullRect, record, data); | 744 SkRecords::CollectLayers visitor(cullRect, record, data); |
751 | 745 |
752 for (unsigned curOp = 0; curOp < record.count(); curOp++) { | 746 for (unsigned curOp = 0; curOp < record.count(); curOp++) { |
753 visitor.setCurrentOp(curOp); | 747 visitor.setCurrentOp(curOp); |
754 record.visit<void>(curOp, visitor); | 748 record.visit<void>(curOp, visitor); |
755 } | 749 } |
756 | 750 |
757 visitor.cleanUp(bbh); | 751 visitor.cleanUp(bbh); |
758 } | 752 } |
759 #endif | |
760 | 753 |
OLD | NEW |