Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: src/core/SkRecordDraw.cpp

Issue 1950523002: Remove GrLayerHoister (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Forgot to remove some files Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPictureRecorder.cpp ('k') | src/core/SkRecordedDrawable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
9 #include "SkRecordDraw.h" 8 #include "SkRecordDraw.h"
10 #include "SkPatchUtils.h" 9 #include "SkPatchUtils.h"
11 10
12 void SkRecordDraw(const SkRecord& record, 11 void SkRecordDraw(const SkRecord& record,
13 SkCanvas* canvas, 12 SkCanvas* canvas,
14 SkPicture const* const drawablePicts[], 13 SkPicture const* const drawablePicts[],
15 SkDrawable* const drawables[], 14 SkDrawable* const drawables[],
16 int drawableCount, 15 int drawableCount,
17 const SkBBoxHierarchy* bbh, 16 const SkBBoxHierarchy* bbh,
18 SkPicture::AbortCallback* callback) { 17 SkPicture::AbortCallback* callback) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 // identity-space bounds of the current clip (fCurrentClipBounds). 597 // identity-space bounds of the current clip (fCurrentClipBounds).
599 int fCurrentOp; 598 int fCurrentOp;
600 SkMatrix fCTM; 599 SkMatrix fCTM;
601 Bounds fCurrentClipBounds; 600 Bounds fCurrentClipBounds;
602 601
603 // Used to track the bounds of Save/Restore blocks and the control ops insid e them. 602 // Used to track the bounds of Save/Restore blocks and the control ops insid e them.
604 SkTDArray<SaveBounds> fSaveStack; 603 SkTDArray<SaveBounds> fSaveStack;
605 SkTDArray<int> fControlIndices; 604 SkTDArray<int> fControlIndices;
606 }; 605 };
607 606
608 // SkRecord visitor to gather saveLayer/restore information.
609 class CollectLayers : SkNoncopyable {
610 public:
611 CollectLayers(const SkRect& cullRect, const SkRecord& record, SkRect bounds[ ],
612 const SkBigPicture::SnapshotArray* pictList, SkLayerInfo* acce lData)
613 : fSaveLayersInStack(0)
614 , fAccelData(accelData)
615 , fPictList(pictList)
616 , fFillBounds(cullRect, record, bounds)
617 {}
618
619 void cleanUp() {
620 // fFillBounds must perform its cleanUp first so that all the bounding
621 // boxes associated with unbalanced restores are updated (prior to
622 // fetching their bound in popSaveLayerInfo).
623 fFillBounds.cleanUp();
624 while (!fSaveLayerStack.isEmpty()) {
625 this->popSaveLayerInfo();
626 }
627 }
628
629 void setCurrentOp(int currentOp) { fFillBounds.setCurrentOp(currentOp); }
630
631
632 template <typename T> void operator()(const T& op) {
633 fFillBounds(op);
634 this->trackSaveLayers(op);
635 }
636
637 private:
638 struct SaveLayerInfo {
639 SaveLayerInfo() { }
640 SaveLayerInfo(int opIndex, bool isSaveLayer, const SkRect* bounds, const SkPaint* paint)
641 : fStartIndex(opIndex)
642 , fIsSaveLayer(isSaveLayer)
643 , fHasNestedSaveLayer(false)
644 , fBounds(bounds ? *bounds : SkRect::MakeEmpty())
645 , fPaint(paint) {
646 }
647
648 int fStartIndex;
649 bool fIsSaveLayer;
650 bool fHasNestedSaveLayer;
651 SkRect fBounds;
652 const SkPaint* fPaint;
653 };
654
655 template <typename T> void trackSaveLayers(const T& op) {
656 /* most ops aren't involved in saveLayers */
657 }
658 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, nullptr , nullptr); }
659 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl .bounds, sl.paint); }
660 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); }
661
662 void trackSaveLayersForPicture(const SkPicture* picture, const SkPaint* pain t) {
663 // For sub-pictures, we wrap their layer information within the parent
664 // picture's rendering hierarchy
665 const SkLayerInfo* childData = nullptr;
666 if (const SkBigPicture* bp = picture->asSkBigPicture()) {
667 childData = static_cast<const SkLayerInfo*>(bp->accelData());
668 }
669 if (!childData) {
670 // If the child layer hasn't been generated with saveLayer data we
671 // assume the worst (i.e., that it does contain layers which nest
672 // inside existing layers). Layers within sub-pictures that don't
673 // have saveLayer data cannot be hoisted.
674 // TODO: could the analysis data be use to fine tune this?
675 this->updateStackForSaveLayer();
676 return;
677 }
678
679 for (int i = 0; i < childData->numBlocks(); ++i) {
680 const SkLayerInfo::BlockInfo& src = childData->block(i);
681
682 FillBounds::Bounds newBound = fFillBounds.adjustAndMap(src.fBounds, paint);
683 if (newBound.isEmpty()) {
684 continue;
685 }
686
687 this->updateStackForSaveLayer();
688
689 SkLayerInfo::BlockInfo& dst = fAccelData->addBlock();
690
691 // If src.fPicture is nullptr the layer is in dp.picture; otherwise
692 // it belongs to a sub-picture.
693 dst.fPicture = src.fPicture ? src.fPicture : picture;
694 dst.fPicture->ref();
695 dst.fBounds = newBound;
696 dst.fSrcBounds = src.fSrcBounds;
697 dst.fLocalMat = src.fLocalMat;
698 dst.fPreMat = src.fPreMat;
699 dst.fPreMat.postConcat(fFillBounds.ctm());
700 if (src.fPaint) {
701 dst.fPaint = new SkPaint(*src.fPaint);
702 }
703 dst.fSaveLayerOpID = src.fSaveLayerOpID;
704 dst.fRestoreOpID = src.fRestoreOpID;
705 dst.fHasNestedLayers = src.fHasNestedLayers;
706 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested;
707
708 // Store 'saveLayer ops from enclosing picture' + drawPict op + 'ops from sub-picture'
709 dst.fKeySize = fSaveLayerOpStack.count() + src.fKeySize + 1;
710 dst.fKey = new int[dst.fKeySize];
711 sk_careful_memcpy(dst.fKey, fSaveLayerOpStack.begin(),
712 fSaveLayerOpStack.count() * sizeof(int));
713 dst.fKey[fSaveLayerOpStack.count()] = fFillBounds.currentOp();
714 memcpy(&dst.fKey[fSaveLayerOpStack.count()+1], src.fKey, src.fKeySiz e * sizeof(int));
715 }
716 }
717
718 void trackSaveLayers(const DrawPicture& dp) {
719 this->trackSaveLayersForPicture(dp.picture, dp.paint);
720 }
721
722 void trackSaveLayers(const DrawDrawable& dp) {
723 SkASSERT(fPictList);
724 SkASSERT(dp.index >= 0 && dp.index < fPictList->count());
725 const SkPaint* paint = nullptr; // drawables don't get a side-car pai nt
726 this->trackSaveLayersForPicture(fPictList->begin()[dp.index], paint);
727 }
728
729 // Inform all the saveLayers already on the stack that they now have a
730 // nested saveLayer inside them
731 void updateStackForSaveLayer() {
732 for (int index = fSaveLayerStack.count() - 1; index >= 0; --index) {
733 if (fSaveLayerStack[index].fHasNestedSaveLayer) {
734 break;
735 }
736 fSaveLayerStack[index].fHasNestedSaveLayer = true;
737 if (fSaveLayerStack[index].fIsSaveLayer) {
738 break;
739 }
740 }
741 }
742
743 void pushSaveLayerInfo(bool isSaveLayer, const SkRect* bounds, const SkPaint * paint) {
744 if (isSaveLayer) {
745 this->updateStackForSaveLayer();
746 ++fSaveLayersInStack;
747 fSaveLayerOpStack.push(fFillBounds.currentOp());
748 }
749
750 fSaveLayerStack.push(SaveLayerInfo(fFillBounds.currentOp(), isSaveLayer, bounds, paint));
751 }
752
753 void popSaveLayerInfo() {
754 if (fSaveLayerStack.count() <= 0) {
755 SkASSERT(false);
756 return;
757 }
758
759 SkASSERT(fSaveLayersInStack == fSaveLayerOpStack.count());
760
761 SaveLayerInfo sli;
762 fSaveLayerStack.pop(&sli);
763
764 if (!sli.fIsSaveLayer) {
765 return;
766 }
767
768 --fSaveLayersInStack;
769
770 SkLayerInfo::BlockInfo& block = fAccelData->addBlock();
771
772 SkASSERT(nullptr == block.fPicture); // This layer is in the top-most p icture
773
774 block.fBounds = fFillBounds.getBounds(sli.fStartIndex);
775 block.fLocalMat = fFillBounds.ctm();
776 block.fPreMat = SkMatrix::I();
777 if (sli.fPaint) {
778 block.fPaint = new SkPaint(*sli.fPaint);
779 }
780
781 block.fSrcBounds = sli.fBounds;
782 block.fSaveLayerOpID = sli.fStartIndex;
783 block.fRestoreOpID = fFillBounds.currentOp();
784 block.fHasNestedLayers = sli.fHasNestedSaveLayer;
785 block.fIsNested = fSaveLayersInStack > 0;
786
787 block.fKeySize = fSaveLayerOpStack.count();
788 block.fKey = new int[block.fKeySize];
789 memcpy(block.fKey, fSaveLayerOpStack.begin(), block.fKeySize * sizeof(in t));
790
791 fSaveLayerOpStack.pop();
792 }
793
794 // Used to collect saveLayer information for layer hoisting
795 int fSaveLayersInStack;
796 SkTDArray<SaveLayerInfo> fSaveLayerStack;
797 // The op code indices of all the currently active saveLayers
798 SkTDArray<int> fSaveLayerOpStack;
799 SkLayerInfo* fAccelData;
800 const SkBigPicture::SnapshotArray* fPictList;
801
802 SkRecords::FillBounds fFillBounds;
803 };
804
805 } // namespace SkRecords 607 } // namespace SkRecords
806 608
807 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkRect b ounds[]) { 609 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord& record, SkRect b ounds[]) {
808 SkRecords::FillBounds visitor(cullRect, record, bounds); 610 SkRecords::FillBounds visitor(cullRect, record, bounds);
809 for (int curOp = 0; curOp < record.count(); curOp++) { 611 for (int curOp = 0; curOp < record.count(); curOp++) {
810 visitor.setCurrentOp(curOp); 612 visitor.setCurrentOp(curOp);
811 record.visit(curOp, visitor); 613 record.visit(curOp, visitor);
812 } 614 }
813 visitor.cleanUp(); 615 visitor.cleanUp();
814 } 616 }
815 617
816 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord& record, SkRec t bounds[],
817 const SkBigPicture::SnapshotArray* pictList, SkLayerI nfo* data) {
818 SkRecords::CollectLayers visitor(cullRect, record, bounds, pictList, data);
819 for (int curOp = 0; curOp < record.count(); curOp++) {
820 visitor.setCurrentOp(curOp);
821 record.visit(curOp, visitor);
822 }
823 visitor.cleanUp();
824 }
OLDNEW
« no previous file with comments | « src/core/SkPictureRecorder.cpp ('k') | src/core/SkRecordedDrawable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698