| 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 "SkLayerInfo.h" |
| 9 #include "SkRecordDraw.h" | 9 #include "SkRecordDraw.h" |
| 10 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
| (...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 601 } |
| 602 | 602 |
| 603 template <typename T> void operator()(const T& op) { | 603 template <typename T> void operator()(const T& op) { |
| 604 fFillBounds(op); | 604 fFillBounds(op); |
| 605 this->trackSaveLayers(op); | 605 this->trackSaveLayers(op); |
| 606 } | 606 } |
| 607 | 607 |
| 608 private: | 608 private: |
| 609 struct SaveLayerInfo { | 609 struct SaveLayerInfo { |
| 610 SaveLayerInfo() { } | 610 SaveLayerInfo() { } |
| 611 SaveLayerInfo(int opIndex, bool isSaveLayer, const SkRect* bounds, const
SkPaint* paint) | 611 SaveLayerInfo(int opIndex, bool isSaveLayer, const SkPaint* paint) |
| 612 : fStartIndex(opIndex) | 612 : fStartIndex(opIndex) |
| 613 , fIsSaveLayer(isSaveLayer) | 613 , fIsSaveLayer(isSaveLayer) |
| 614 , fHasNestedSaveLayer(false) | 614 , fHasNestedSaveLayer(false) |
| 615 , fBounds(bounds ? *bounds : SkRect::MakeEmpty()) | |
| 616 , fPaint(paint) { | 615 , fPaint(paint) { |
| 617 } | 616 } |
| 618 | 617 |
| 619 int fStartIndex; | 618 int fStartIndex; |
| 620 bool fIsSaveLayer; | 619 bool fIsSaveLayer; |
| 621 bool fHasNestedSaveLayer; | 620 bool fHasNestedSaveLayer; |
| 622 SkRect fBounds; | |
| 623 const SkPaint* fPaint; | 621 const SkPaint* fPaint; |
| 624 }; | 622 }; |
| 625 | 623 |
| 626 template <typename T> void trackSaveLayers(const T& op) { | 624 template <typename T> void trackSaveLayers(const T& op) { |
| 627 /* most ops aren't involved in saveLayers */ | 625 /* most ops aren't involved in saveLayers */ |
| 628 } | 626 } |
| 629 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL, N
ULL); } | 627 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL);
} |
| 630 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl
.bounds, sl.paint); } | 628 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl
.paint); } |
| 631 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } | 629 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } |
| 632 | 630 |
| 633 void trackSaveLayersForPicture(const SkPicture* picture, const SkPaint* pain
t) { | 631 void trackSaveLayersForPicture(const SkPicture* picture, const SkPaint* pain
t) { |
| 634 // For sub-pictures, we wrap their layer information within the parent | 632 // For sub-pictures, we wrap their layer information within the parent |
| 635 // picture's rendering hierarchy | 633 // picture's rendering hierarchy |
| 636 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); | 634 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
| 637 | 635 |
| 638 const SkLayerInfo* childData = | 636 const SkLayerInfo* childData = |
| 639 static_cast<const SkLayerInfo*>(picture->EXPERIMENTAL_getAccelData(k
ey)); | 637 static_cast<const SkLayerInfo*>(picture->EXPERIMENTAL_getAccelData(k
ey)); |
| 640 if (!childData) { | 638 if (!childData) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 657 | 655 |
| 658 this->updateStackForSaveLayer(); | 656 this->updateStackForSaveLayer(); |
| 659 | 657 |
| 660 SkLayerInfo::BlockInfo& dst = fAccelData->addBlock(); | 658 SkLayerInfo::BlockInfo& dst = fAccelData->addBlock(); |
| 661 | 659 |
| 662 // If src.fPicture is NULL the layer is in dp.picture; otherwise | 660 // If src.fPicture is NULL the layer is in dp.picture; otherwise |
| 663 // it belongs to a sub-picture. | 661 // it belongs to a sub-picture. |
| 664 dst.fPicture = src.fPicture ? src.fPicture : picture; | 662 dst.fPicture = src.fPicture ? src.fPicture : picture; |
| 665 dst.fPicture->ref(); | 663 dst.fPicture->ref(); |
| 666 dst.fBounds = newBound; | 664 dst.fBounds = newBound; |
| 667 dst.fSrcBounds = src.fSrcBounds; | |
| 668 dst.fLocalMat = src.fLocalMat; | 665 dst.fLocalMat = src.fLocalMat; |
| 669 dst.fPreMat = src.fPreMat; | 666 dst.fPreMat = src.fPreMat; |
| 670 dst.fPreMat.postConcat(fFillBounds.ctm()); | 667 dst.fPreMat.postConcat(fFillBounds.ctm()); |
| 671 if (src.fPaint) { | 668 if (src.fPaint) { |
| 672 dst.fPaint = SkNEW_ARGS(SkPaint, (*src.fPaint)); | 669 dst.fPaint = SkNEW_ARGS(SkPaint, (*src.fPaint)); |
| 673 } | 670 } |
| 674 dst.fSaveLayerOpID = src.fSaveLayerOpID; | 671 dst.fSaveLayerOpID = src.fSaveLayerOpID; |
| 675 dst.fRestoreOpID = src.fRestoreOpID; | 672 dst.fRestoreOpID = src.fRestoreOpID; |
| 676 dst.fHasNestedLayers = src.fHasNestedLayers; | 673 dst.fHasNestedLayers = src.fHasNestedLayers; |
| 677 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested; | 674 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 703 if (fSaveLayerStack[index].fHasNestedSaveLayer) { | 700 if (fSaveLayerStack[index].fHasNestedSaveLayer) { |
| 704 break; | 701 break; |
| 705 } | 702 } |
| 706 fSaveLayerStack[index].fHasNestedSaveLayer = true; | 703 fSaveLayerStack[index].fHasNestedSaveLayer = true; |
| 707 if (fSaveLayerStack[index].fIsSaveLayer) { | 704 if (fSaveLayerStack[index].fIsSaveLayer) { |
| 708 break; | 705 break; |
| 709 } | 706 } |
| 710 } | 707 } |
| 711 } | 708 } |
| 712 | 709 |
| 713 void pushSaveLayerInfo(bool isSaveLayer, const SkRect* bounds, const SkPaint
* paint) { | 710 void pushSaveLayerInfo(bool isSaveLayer, const SkPaint* paint) { |
| 714 if (isSaveLayer) { | 711 if (isSaveLayer) { |
| 715 this->updateStackForSaveLayer(); | 712 this->updateStackForSaveLayer(); |
| 716 ++fSaveLayersInStack; | 713 ++fSaveLayersInStack; |
| 717 fSaveLayerOpStack.push(fFillBounds.currentOp()); | 714 fSaveLayerOpStack.push(fFillBounds.currentOp()); |
| 718 } | 715 } |
| 719 | 716 |
| 720 fSaveLayerStack.push(SaveLayerInfo(fFillBounds.currentOp(), isSaveLayer,
bounds, paint)); | 717 fSaveLayerStack.push(SaveLayerInfo(fFillBounds.currentOp(), isSaveLayer,
paint)); |
| 721 } | 718 } |
| 722 | 719 |
| 723 void popSaveLayerInfo() { | 720 void popSaveLayerInfo() { |
| 724 if (fSaveLayerStack.count() <= 0) { | 721 if (fSaveLayerStack.count() <= 0) { |
| 725 SkASSERT(false); | 722 SkASSERT(false); |
| 726 return; | 723 return; |
| 727 } | 724 } |
| 728 | 725 |
| 729 SkASSERT(fSaveLayersInStack == fSaveLayerOpStack.count()); | 726 SkASSERT(fSaveLayersInStack == fSaveLayerOpStack.count()); |
| 730 | 727 |
| 731 SaveLayerInfo sli; | 728 SaveLayerInfo sli; |
| 732 fSaveLayerStack.pop(&sli); | 729 fSaveLayerStack.pop(&sli); |
| 733 | 730 |
| 734 if (!sli.fIsSaveLayer) { | 731 if (!sli.fIsSaveLayer) { |
| 735 return; | 732 return; |
| 736 } | 733 } |
| 737 | 734 |
| 738 --fSaveLayersInStack; | 735 --fSaveLayersInStack; |
| 739 | 736 |
| 740 SkLayerInfo::BlockInfo& block = fAccelData->addBlock(); | 737 SkLayerInfo::BlockInfo& block = fAccelData->addBlock(); |
| 741 | 738 |
| 742 SkASSERT(NULL == block.fPicture); // This layer is in the top-most pict
ure | 739 SkASSERT(NULL == block.fPicture); // This layer is in the top-most pict
ure |
| 743 | 740 |
| 744 block.fBounds = fFillBounds.getBounds(sli.fStartIndex); | 741 block.fBounds = fFillBounds.getBounds(sli.fStartIndex); |
| 745 block.fLocalMat = fFillBounds.ctm(); | 742 block.fLocalMat = fFillBounds.ctm(); |
| 746 block.fPreMat = SkMatrix::I(); | 743 block.fPreMat = SkMatrix::I(); |
| 747 if (sli.fPaint) { | 744 if (sli.fPaint) { |
| 748 block.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint)); | 745 block.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint)); |
| 749 } | 746 } |
| 750 | |
| 751 block.fSrcBounds = sli.fBounds; | |
| 752 block.fSaveLayerOpID = sli.fStartIndex; | 747 block.fSaveLayerOpID = sli.fStartIndex; |
| 753 block.fRestoreOpID = fFillBounds.currentOp(); | 748 block.fRestoreOpID = fFillBounds.currentOp(); |
| 754 block.fHasNestedLayers = sli.fHasNestedSaveLayer; | 749 block.fHasNestedLayers = sli.fHasNestedSaveLayer; |
| 755 block.fIsNested = fSaveLayersInStack > 0; | 750 block.fIsNested = fSaveLayersInStack > 0; |
| 756 | 751 |
| 757 block.fKeySize = fSaveLayerOpStack.count(); | 752 block.fKeySize = fSaveLayerOpStack.count(); |
| 758 block.fKey = SkNEW_ARRAY(unsigned, block.fKeySize); | 753 block.fKey = SkNEW_ARRAY(unsigned, block.fKeySize); |
| 759 memcpy(block.fKey, fSaveLayerOpStack.begin(), block.fKeySize * sizeof(un
signed)); | 754 memcpy(block.fKey, fSaveLayerOpStack.begin(), block.fKeySize * sizeof(un
signed)); |
| 760 | 755 |
| 761 fSaveLayerOpStack.pop(); | 756 fSaveLayerOpStack.pop(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 791 SkRecords::CollectLayers visitor(cullRect, record, pictList, data); | 786 SkRecords::CollectLayers visitor(cullRect, record, pictList, data); |
| 792 | 787 |
| 793 for (unsigned curOp = 0; curOp < record.count(); curOp++) { | 788 for (unsigned curOp = 0; curOp < record.count(); curOp++) { |
| 794 visitor.setCurrentOp(curOp); | 789 visitor.setCurrentOp(curOp); |
| 795 record.visit<void>(curOp, visitor); | 790 record.visit<void>(curOp, visitor); |
| 796 } | 791 } |
| 797 | 792 |
| 798 visitor.cleanUp(bbh); | 793 visitor.cleanUp(bbh); |
| 799 } | 794 } |
| 800 | 795 |
| OLD | NEW |