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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkClipStack.h" | 9 #include "SkClipStack.h" |
10 #include "SkPath.h" | 10 #include "SkPath.h" |
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 break; | 590 break; |
591 } | 591 } |
592 element->~Element(); | 592 element->~Element(); |
593 fDeque.pop_back(); | 593 fDeque.pop_back(); |
594 } | 594 } |
595 } | 595 } |
596 | 596 |
597 void SkClipStack::getBounds(SkRect* canvFiniteBound, | 597 void SkClipStack::getBounds(SkRect* canvFiniteBound, |
598 BoundsType* boundType, | 598 BoundsType* boundType, |
599 bool* isIntersectionOfRects) const { | 599 bool* isIntersectionOfRects) const { |
600 SkASSERT(NULL != canvFiniteBound && NULL != boundType); | 600 SkASSERT(canvFiniteBound && boundType); |
601 | 601 |
602 Element* element = (Element*)fDeque.back(); | 602 Element* element = (Element*)fDeque.back(); |
603 | 603 |
604 if (NULL == element) { | 604 if (NULL == element) { |
605 // the clip is wide open - the infinite plane w/ no pixels un-writeable | 605 // the clip is wide open - the infinite plane w/ no pixels un-writeable |
606 canvFiniteBound->setEmpty(); | 606 canvFiniteBound->setEmpty(); |
607 *boundType = kInsideOut_BoundsType; | 607 *boundType = kInsideOut_BoundsType; |
608 if (NULL != isIntersectionOfRects) { | 608 if (isIntersectionOfRects) { |
609 *isIntersectionOfRects = false; | 609 *isIntersectionOfRects = false; |
610 } | 610 } |
611 return; | 611 return; |
612 } | 612 } |
613 | 613 |
614 *canvFiniteBound = element->fFiniteBound; | 614 *canvFiniteBound = element->fFiniteBound; |
615 *boundType = element->fFiniteBoundType; | 615 *boundType = element->fFiniteBoundType; |
616 if (NULL != isIntersectionOfRects) { | 616 if (isIntersectionOfRects) { |
617 *isIntersectionOfRects = element->fIsIntersectionOfRects; | 617 *isIntersectionOfRects = element->fIsIntersectionOfRects; |
618 } | 618 } |
619 } | 619 } |
620 | 620 |
621 bool SkClipStack::intersectRectWithClip(SkRect* rect) const { | 621 bool SkClipStack::intersectRectWithClip(SkRect* rect) const { |
622 SkASSERT(NULL != rect); | 622 SkASSERT(rect); |
623 | 623 |
624 SkRect bounds; | 624 SkRect bounds; |
625 SkClipStack::BoundsType bt; | 625 SkClipStack::BoundsType bt; |
626 this->getBounds(&bounds, &bt); | 626 this->getBounds(&bounds, &bt); |
627 if (bt == SkClipStack::kInsideOut_BoundsType) { | 627 if (bt == SkClipStack::kInsideOut_BoundsType) { |
628 if (bounds.contains(*rect)) { | 628 if (bounds.contains(*rect)) { |
629 return false; | 629 return false; |
630 } else { | 630 } else { |
631 // If rect's x values are both within bound's x range we | 631 // If rect's x values are both within bound's x range we |
632 // could clip here. Same for y. But we don't bother to check. | 632 // could clip here. Same for y. But we don't bother to check. |
(...skipping 27 matching lines...) Expand all Loading... |
660 element = iter.prev(); | 660 element = iter.prev(); |
661 } | 661 } |
662 return true; | 662 return true; |
663 } | 663 } |
664 | 664 |
665 void SkClipStack::pushElement(const Element& element) { | 665 void SkClipStack::pushElement(const Element& element) { |
666 // Use reverse iterator instead of back because Rect path may need previous | 666 // Use reverse iterator instead of back because Rect path may need previous |
667 SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart); | 667 SkDeque::Iter iter(fDeque, SkDeque::Iter::kBack_IterStart); |
668 Element* prior = (Element*) iter.prev(); | 668 Element* prior = (Element*) iter.prev(); |
669 | 669 |
670 if (NULL != prior) { | 670 if (prior) { |
671 if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) { | 671 if (prior->canBeIntersectedInPlace(fSaveCount, element.getOp())) { |
672 switch (prior->fType) { | 672 switch (prior->fType) { |
673 case Element::kEmpty_Type: | 673 case Element::kEmpty_Type: |
674 SkDEBUGCODE(prior->checkEmpty();) | 674 SkDEBUGCODE(prior->checkEmpty();) |
675 return; | 675 return; |
676 case Element::kRect_Type: | 676 case Element::kRect_Type: |
677 if (Element::kRect_Type == element.getType()) { | 677 if (Element::kRect_Type == element.getType()) { |
678 if (prior->rectRectIntersectAllowed(element.getRect(), e
lement.isAA())) { | 678 if (prior->rectRectIntersectAllowed(element.getRect(), e
lement.isAA())) { |
679 SkRect isectRect; | 679 SkRect isectRect; |
680 if (!isectRect.intersect(prior->getRect(), element.g
etRect())) { | 680 if (!isectRect.intersect(prior->getRect(), element.g
etRect())) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 | 759 |
760 if (NULL == fStack) { | 760 if (NULL == fStack) { |
761 return NULL; | 761 return NULL; |
762 } | 762 } |
763 | 763 |
764 fIter.reset(fStack->fDeque, SkDeque::Iter::kBack_IterStart); | 764 fIter.reset(fStack->fDeque, SkDeque::Iter::kBack_IterStart); |
765 | 765 |
766 const SkClipStack::Element* element = NULL; | 766 const SkClipStack::Element* element = NULL; |
767 | 767 |
768 for (element = (const SkClipStack::Element*) fIter.prev(); | 768 for (element = (const SkClipStack::Element*) fIter.prev(); |
769 NULL != element; | 769 element; |
770 element = (const SkClipStack::Element*) fIter.prev()) { | 770 element = (const SkClipStack::Element*) fIter.prev()) { |
771 | 771 |
772 if (op == element->fOp) { | 772 if (op == element->fOp) { |
773 // The Deque's iterator is actually one pace ahead of the | 773 // The Deque's iterator is actually one pace ahead of the |
774 // returned value. So while "element" is the element we want to | 774 // returned value. So while "element" is the element we want to |
775 // return, the iterator is actually pointing at (and will | 775 // return, the iterator is actually pointing at (and will |
776 // return on the next "next" or "prev" call) the element | 776 // return on the next "next" or "prev" call) the element |
777 // in front of it in the deque. Bump the iterator forward a | 777 // in front of it in the deque. Bump the iterator forward a |
778 // step so we get the expected result. | 778 // step so we get the expected result. |
779 if (NULL == fIter.next()) { | 779 if (NULL == fIter.next()) { |
(...skipping 19 matching lines...) Expand all Loading... |
799 fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc)); | 799 fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc)); |
800 } | 800 } |
801 | 801 |
802 // helper method | 802 // helper method |
803 void SkClipStack::getConservativeBounds(int offsetX, | 803 void SkClipStack::getConservativeBounds(int offsetX, |
804 int offsetY, | 804 int offsetY, |
805 int maxWidth, | 805 int maxWidth, |
806 int maxHeight, | 806 int maxHeight, |
807 SkRect* devBounds, | 807 SkRect* devBounds, |
808 bool* isIntersectionOfRects) const { | 808 bool* isIntersectionOfRects) const { |
809 SkASSERT(NULL != devBounds); | 809 SkASSERT(devBounds); |
810 | 810 |
811 devBounds->setLTRB(0, 0, | 811 devBounds->setLTRB(0, 0, |
812 SkIntToScalar(maxWidth), SkIntToScalar(maxHeight)); | 812 SkIntToScalar(maxWidth), SkIntToScalar(maxHeight)); |
813 | 813 |
814 SkRect temp; | 814 SkRect temp; |
815 SkClipStack::BoundsType boundType; | 815 SkClipStack::BoundsType boundType; |
816 | 816 |
817 // temp starts off in canvas space here | 817 // temp starts off in canvas space here |
818 this->getBounds(&temp, &boundType, isIntersectionOfRects); | 818 this->getBounds(&temp, &boundType, isIntersectionOfRects); |
819 if (SkClipStack::kInsideOut_BoundsType == boundType) { | 819 if (SkClipStack::kInsideOut_BoundsType == boundType) { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 | 898 |
899 void SkClipStack::dump() const { | 899 void SkClipStack::dump() const { |
900 B2TIter iter(*this); | 900 B2TIter iter(*this); |
901 const Element* e; | 901 const Element* e; |
902 while ((e = iter.next())) { | 902 while ((e = iter.next())) { |
903 e->dump(); | 903 e->dump(); |
904 SkDebugf("\n"); | 904 SkDebugf("\n"); |
905 } | 905 } |
906 } | 906 } |
907 #endif | 907 #endif |
OLD | NEW |