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

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

Issue 719793002: Clean up CollectLayers code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month 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 | « no previous file | no next file » | 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 "SkRecordDraw.h" 8 #include "SkRecordDraw.h"
9 #include "SkPatchUtils.h" 9 #include "SkPatchUtils.h"
10 10
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 this->updateCTM(op); 179 this->updateCTM(op);
180 this->updateClipBounds(op); 180 this->updateClipBounds(op);
181 this->trackBounds(op); 181 this->trackBounds(op);
182 } 182 }
183 183
184 // In this file, SkRect are in local coordinates, Bounds are translated back to identity space. 184 // In this file, SkRect are in local coordinates, Bounds are translated back to identity space.
185 typedef SkRect Bounds; 185 typedef SkRect Bounds;
186 186
187 unsigned currentOp() const { return fCurrentOp; } 187 unsigned currentOp() const { return fCurrentOp; }
188 const SkMatrix& ctm() const { return *fCTM; } 188 const SkMatrix& ctm() const { return *fCTM; }
189 const Bounds& currentClipBounds() const { return fCurrentClipBounds; }
190 const Bounds& getBounds(unsigned index) const { return fBounds[index]; } 189 const Bounds& getBounds(unsigned index) const { return fBounds[index]; }
191 190
192 // Adjust rect for all paints that may affect its geometry, then map it to i dentity space. 191 // Adjust rect for all paints that may affect its geometry, then map it to i dentity space.
193 Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const { 192 Bounds adjustAndMap(SkRect rect, const SkPaint* paint) const {
194 // Inverted rectangles really confuse our BBHs. 193 // Inverted rectangles really confuse our BBHs.
195 rect.sort(); 194 rect.sort();
196 195
197 // Adjust the rect for its own paint. 196 // Adjust the rect for its own paint.
198 if (!AdjustForPaint(paint, &rect)) { 197 if (!AdjustForPaint(paint, &rect)) {
199 // The paint could do anything to our bounds. The only safe answer is the current clip. 198 // The paint could do anything to our bounds. The only safe answer is the current clip.
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 } 594 }
596 595
597 template <typename T> void operator()(const T& op) { 596 template <typename T> void operator()(const T& op) {
598 fFillBounds(op); 597 fFillBounds(op);
599 this->trackSaveLayers(op); 598 this->trackSaveLayers(op);
600 } 599 }
601 600
602 private: 601 private:
603 struct SaveLayerInfo { 602 struct SaveLayerInfo {
604 SaveLayerInfo() { } 603 SaveLayerInfo() { }
605 SaveLayerInfo(int opIndex, bool isSaveLayer, const SkPaint* paint, 604 SaveLayerInfo(int opIndex, bool isSaveLayer, const SkPaint* paint)
606 const FillBounds::Bounds& clipBound)
607 : fStartIndex(opIndex) 605 : fStartIndex(opIndex)
608 , fIsSaveLayer(isSaveLayer) 606 , fIsSaveLayer(isSaveLayer)
609 , fHasNestedSaveLayer(false) 607 , fHasNestedSaveLayer(false)
610 , fPaint(paint) 608 , fPaint(paint) {
611 , fClipBound(clipBound) {
612 } 609 }
613 610
614 int fStartIndex; 611 int fStartIndex;
615 bool fIsSaveLayer; 612 bool fIsSaveLayer;
616 bool fHasNestedSaveLayer; 613 bool fHasNestedSaveLayer;
617 const SkPaint* fPaint; 614 const SkPaint* fPaint;
618 FillBounds::Bounds fClipBound;
619 }; 615 };
620 616
621 template <typename T> void trackSaveLayers(const T& op) { 617 template <typename T> void trackSaveLayers(const T& op) {
622 /* most ops aren't involved in saveLayers */ 618 /* most ops aren't involved in saveLayers */
623 } 619 }
624 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL); } 620 void trackSaveLayers(const Save& s) { this->pushSaveLayerInfo(false, NULL); }
625 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl .paint); } 621 void trackSaveLayers(const SaveLayer& sl) { this->pushSaveLayerInfo(true, sl .paint); }
626 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); } 622 void trackSaveLayers(const Restore& r) { this->popSaveLayerInfo(); }
627 623
628 void trackSaveLayers(const DrawPicture& dp) { 624 void trackSaveLayers(const DrawPicture& dp) {
629 // For sub-pictures, we wrap their layer information within the parent 625 // For sub-pictures, we wrap their layer information within the parent
630 // picture's rendering hierarchy 626 // picture's rendering hierarchy
631 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey(); 627 SkPicture::AccelData::Key key = GrAccelData::ComputeAccelDataKey();
632 628
633 const GrAccelData* childData = 629 const GrAccelData* childData =
634 static_cast<const GrAccelData*>(dp.picture->EXPERIMENTAL_getAccelDat a(key)); 630 static_cast<const GrAccelData*>(dp.picture->EXPERIMENTAL_getAccelDat a(key));
635 if (!childData) { 631 if (!childData) {
636 // If the child layer hasn't been generated with saveLayer data we 632 // If the child layer hasn't been generated with saveLayer data we
637 // assume the worst (i.e., that it does contain layers which nest 633 // assume the worst (i.e., that it does contain layers which nest
638 // inside existing layers). Layers within sub-pictures that don't 634 // inside existing layers). Layers within sub-pictures that don't
639 // have saveLayer data cannot be hoisted. 635 // have saveLayer data cannot be hoisted.
640 // TODO: could the analysis data be use to fine tune this? 636 // TODO: could the analysis data be use to fine tune this?
641 this->updateStackForSaveLayer(); 637 this->updateStackForSaveLayer();
642 return; 638 return;
643 } 639 }
644 640
645 for (int i = 0; i < childData->numSaveLayers(); ++i) { 641 for (int i = 0; i < childData->numSaveLayers(); ++i) {
646 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i); 642 const GrAccelData::SaveLayerInfo& src = childData->saveLayerInfo(i);
647 643
648 FillBounds::Bounds newClip(fFillBounds.currentClipBounds()); 644 FillBounds::Bounds newBound = fFillBounds.adjustAndMap(src.fBounds, dp.paint);
649 645 if (newBound.isEmpty()) {
650 if (!newClip.intersect(fFillBounds.adjustAndMap(src.fBounds, dp.pain t))) {
651 continue; 646 continue;
652 } 647 }
653 648
654 this->updateStackForSaveLayer(); 649 this->updateStackForSaveLayer();
655 650
656 GrAccelData::SaveLayerInfo& dst = fAccelData->addSaveLayerInfo(); 651 GrAccelData::SaveLayerInfo& dst = fAccelData->addSaveLayerInfo();
657 652
658 // If src.fPicture is NULL the layer is in dp.picture; otherwise 653 // If src.fPicture is NULL the layer is in dp.picture; otherwise
659 // it belongs to a sub-picture. 654 // it belongs to a sub-picture.
660 dst.fPicture = src.fPicture ? src.fPicture : static_cast<const SkPic ture*>(dp.picture); 655 dst.fPicture = src.fPicture ? src.fPicture : static_cast<const SkPic ture*>(dp.picture);
661 dst.fPicture->ref(); 656 dst.fPicture->ref();
662 dst.fBounds = newClip; 657 dst.fBounds = newBound;
663 dst.fLocalMat = src.fLocalMat; 658 dst.fLocalMat = src.fLocalMat;
664 dst.fPreMat = src.fPreMat; 659 dst.fPreMat = src.fPreMat;
665 dst.fPreMat.postConcat(fFillBounds.ctm()); 660 dst.fPreMat.postConcat(fFillBounds.ctm());
666 if (src.fPaint) { 661 if (src.fPaint) {
667 dst.fPaint = SkNEW_ARGS(SkPaint, (*src.fPaint)); 662 dst.fPaint = SkNEW_ARGS(SkPaint, (*src.fPaint));
668 } 663 }
669 dst.fSaveLayerOpID = src.fSaveLayerOpID; 664 dst.fSaveLayerOpID = src.fSaveLayerOpID;
670 dst.fRestoreOpID = src.fRestoreOpID; 665 dst.fRestoreOpID = src.fRestoreOpID;
671 dst.fHasNestedLayers = src.fHasNestedLayers; 666 dst.fHasNestedLayers = src.fHasNestedLayers;
672 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested; 667 dst.fIsNested = fSaveLayersInStack > 0 || src.fIsNested;
(...skipping 13 matching lines...) Expand all
686 } 681 }
687 } 682 }
688 } 683 }
689 684
690 void pushSaveLayerInfo(bool isSaveLayer, const SkPaint* paint) { 685 void pushSaveLayerInfo(bool isSaveLayer, const SkPaint* paint) {
691 if (isSaveLayer) { 686 if (isSaveLayer) {
692 this->updateStackForSaveLayer(); 687 this->updateStackForSaveLayer();
693 ++fSaveLayersInStack; 688 ++fSaveLayersInStack;
694 } 689 }
695 690
696 fSaveLayerStack.push(SaveLayerInfo(fFillBounds.currentOp(), isSaveLayer, paint, 691 fSaveLayerStack.push(SaveLayerInfo(fFillBounds.currentOp(), isSaveLayer, paint));
697 fFillBounds.currentClipBounds()));
698 } 692 }
699 693
700 void popSaveLayerInfo() { 694 void popSaveLayerInfo() {
701 if (fSaveLayerStack.count() <= 0) { 695 if (fSaveLayerStack.count() <= 0) {
702 SkASSERT(false); 696 SkASSERT(false);
703 return; 697 return;
704 } 698 }
705 699
706 SaveLayerInfo sli; 700 SaveLayerInfo sli;
707 fSaveLayerStack.pop(&sli); 701 fSaveLayerStack.pop(&sli);
708 702
709 if (!sli.fIsSaveLayer) { 703 if (!sli.fIsSaveLayer) {
710 return; 704 return;
711 } 705 }
712 706
713 --fSaveLayersInStack; 707 --fSaveLayersInStack;
714 708
715 GrAccelData::SaveLayerInfo& slInfo = fAccelData->addSaveLayerInfo(); 709 GrAccelData::SaveLayerInfo& slInfo = fAccelData->addSaveLayerInfo();
716 710
717 SkASSERT(NULL == slInfo.fPicture); // This layer is in the top-most pic ture 711 SkASSERT(NULL == slInfo.fPicture); // This layer is in the top-most pic ture
718 712
719 slInfo.fBounds = fFillBounds.getBounds(sli.fStartIndex); 713 slInfo.fBounds = fFillBounds.getBounds(sli.fStartIndex);
720 slInfo.fBounds.intersect(sli.fClipBound);
721 slInfo.fLocalMat = fFillBounds.ctm(); 714 slInfo.fLocalMat = fFillBounds.ctm();
722 slInfo.fPreMat = SkMatrix::I(); 715 slInfo.fPreMat = SkMatrix::I();
723 if (sli.fPaint) { 716 if (sli.fPaint) {
724 slInfo.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint)); 717 slInfo.fPaint = SkNEW_ARGS(SkPaint, (*sli.fPaint));
725 } 718 }
726 slInfo.fSaveLayerOpID = sli.fStartIndex; 719 slInfo.fSaveLayerOpID = sli.fStartIndex;
727 slInfo.fRestoreOpID = fFillBounds.currentOp(); 720 slInfo.fRestoreOpID = fFillBounds.currentOp();
728 slInfo.fHasNestedLayers = sli.fHasNestedSaveLayer; 721 slInfo.fHasNestedLayers = sli.fHasNestedSaveLayer;
729 slInfo.fIsNested = fSaveLayersInStack > 0; 722 slInfo.fIsNested = fSaveLayersInStack > 0;
730 } 723 }
(...skipping 27 matching lines...) Expand all
758 751
759 for (unsigned curOp = 0; curOp < record.count(); curOp++) { 752 for (unsigned curOp = 0; curOp < record.count(); curOp++) {
760 visitor.setCurrentOp(curOp); 753 visitor.setCurrentOp(curOp);
761 record.visit<void>(curOp, visitor); 754 record.visit<void>(curOp, visitor);
762 } 755 }
763 756
764 visitor.cleanUp(bbh); 757 visitor.cleanUp(bbh);
765 } 758 }
766 #endif 759 #endif
767 760
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698