Use SkRRect to store rects in SkClipStack::Element

BUG=skia:2181
R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/163483003

git-svn-id: http://skia.googlecode.com/svn/trunk@13544 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-02-21 20:09:13 +00:00
Родитель 374ea4ee26
Коммит 032a52fd4c
2 изменённых файлов: 20 добавлений и 18 удалений

Просмотреть файл

@ -78,7 +78,10 @@ public:
const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; } const SkRRect& getRRect() const { SkASSERT(kRRect_Type == fType); return fRRect; }
//!< Call if getType() is kRect to get the rect. //!< Call if getType() is kRect to get the rect.
const SkRect& getRect() const { SkASSERT(kRect_Type == fType); return fRect; } const SkRect& getRect() const {
SkASSERT(kRect_Type == fType && (fRRect.isRect() || fRRect.isEmpty()));
return fRRect.getBounds();
}
//!< Call if getType() is not kEmpty to get the set operation used to combine this element. //!< Call if getType() is not kEmpty to get the set operation used to combine this element.
SkRegion::Op getOp() const { return fOp; } SkRegion::Op getOp() const { return fOp; }
@ -110,8 +113,7 @@ public:
const SkRect& getBounds() const { const SkRect& getBounds() const {
static const SkRect kEmpty = { 0, 0, 0, 0 }; static const SkRect kEmpty = { 0, 0, 0, 0 };
switch (fType) { switch (fType) {
case kRect_Type: case kRect_Type: // fallthrough
return fRect;
case kRRect_Type: case kRRect_Type:
return fRRect.getBounds(); return fRRect.getBounds();
case kPath_Type: case kPath_Type:
@ -131,7 +133,7 @@ public:
bool contains(const SkRect& rect) const { bool contains(const SkRect& rect) const {
switch (fType) { switch (fType) {
case kRect_Type: case kRect_Type:
return fRect.contains(rect); return this->getRect().contains(rect);
case kRRect_Type: case kRRect_Type:
return fRRect.contains(rect); return fRRect.contains(rect);
case kPath_Type: case kPath_Type:
@ -155,7 +157,6 @@ public:
friend class SkClipStack; friend class SkClipStack;
SkPath fPath; SkPath fPath;
SkRect fRect;
SkRRect fRRect; SkRRect fRRect;
int fSaveCount; // save count of stack when this element was added. int fSaveCount; // save count of stack when this element was added.
SkRegion::Op fOp; SkRegion::Op fOp;
@ -211,17 +212,17 @@ public:
} }
void initRect(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) { void initRect(int saveCount, const SkRect& rect, SkRegion::Op op, bool doAA) {
fRect = rect; fRRect.setRect(rect);
fType = kRect_Type; fType = kRect_Type;
this->initCommon(saveCount, op, doAA); this->initCommon(saveCount, op, doAA);
} }
void initRRect(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) { void initRRect(int saveCount, const SkRRect& rrect, SkRegion::Op op, bool doAA) {
if (rrect.isRect()) { SkRRect::Type type = rrect.getType();
fRect = rrect.getBounds(); fRRect = rrect;
if (SkRRect::kRect_Type == type || SkRRect::kEmpty_Type == type) {
fType = kRect_Type; fType = kRect_Type;
} else { } else {
fRRect = rrect;
fType = kRRect_Type; fType = kRRect_Type;
} }
this->initCommon(saveCount, op, doAA); this->initCommon(saveCount, op, doAA);

Просмотреть файл

@ -32,7 +32,7 @@ bool SkClipStack::Element::operator== (const Element& element) const {
case kRRect_Type: case kRRect_Type:
return fRRect == element.fRRect; return fRRect == element.fRRect;
case kRect_Type: case kRect_Type:
return fRect == element.fRect; return this->getRect() == element.getRect();
case kEmpty_Type: case kEmpty_Type:
return true; return true;
default: default:
@ -45,7 +45,7 @@ void SkClipStack::Element::invertShapeFillType() {
switch (fType) { switch (fType) {
case kRect_Type: case kRect_Type:
fPath.reset(); fPath.reset();
fPath.addRect(fRect); fPath.addRect(this->getRect());
fPath.setFillType(SkPath::kInverseEvenOdd_FillType); fPath.setFillType(SkPath::kInverseEvenOdd_FillType);
fType = kPath_Type; fType = kPath_Type;
break; break;
@ -91,7 +91,7 @@ void SkClipStack::Element::asPath(SkPath* path) const {
break; break;
case kRect_Type: case kRect_Type:
path->reset(); path->reset();
path->addRect(fRect); path->addRect(this->getRect());
break; break;
case kRRect_Type: case kRRect_Type:
path->reset(); path->reset();
@ -108,7 +108,6 @@ void SkClipStack::Element::setEmpty() {
fFiniteBound.setEmpty(); fFiniteBound.setEmpty();
fFiniteBoundType = kNormal_BoundsType; fFiniteBoundType = kNormal_BoundsType;
fIsIntersectionOfRects = false; fIsIntersectionOfRects = false;
fRect.setEmpty();
fRRect.setEmpty(); fRRect.setEmpty();
fPath.reset(); fPath.reset();
fGenID = kEmptyGenID; fGenID = kEmptyGenID;
@ -143,12 +142,12 @@ bool SkClipStack::Element::rectRectIntersectAllowed(const SkRect& newR, bool new
return true; return true;
} }
if (!SkRect::Intersects(fRect, newR)) { if (!SkRect::Intersects(this->getRect(), newR)) {
// The calling code will correctly set the result to the empty clip // The calling code will correctly set the result to the empty clip
return true; return true;
} }
if (fRect.contains(newR)) { if (this->getRect().contains(newR)) {
// if the new rect carves out a portion of the old one there is no // if the new rect carves out a portion of the old one there is no
// issue // issue
return true; return true;
@ -343,13 +342,13 @@ void SkClipStack::Element::updateBoundAndGenID(const Element* prior) {
fIsIntersectionOfRects = false; fIsIntersectionOfRects = false;
switch (fType) { switch (fType) {
case kRect_Type: case kRect_Type:
fFiniteBound = fRect; fFiniteBound = this->getRect();
fFiniteBoundType = kNormal_BoundsType; fFiniteBoundType = kNormal_BoundsType;
if (SkRegion::kReplace_Op == fOp || if (SkRegion::kReplace_Op == fOp ||
(SkRegion::kIntersect_Op == fOp && NULL == prior) || (SkRegion::kIntersect_Op == fOp && NULL == prior) ||
(SkRegion::kIntersect_Op == fOp && prior->fIsIntersectionOfRects && (SkRegion::kIntersect_Op == fOp && prior->fIsIntersectionOfRects &&
prior->rectRectIntersectAllowed(fRect, fDoAA))) { prior->rectRectIntersectAllowed(this->getRect(), fDoAA))) {
fIsIntersectionOfRects = true; fIsIntersectionOfRects = true;
} }
break; break;
@ -632,11 +631,13 @@ void SkClipStack::pushElement(const Element& element) {
case Element::kRect_Type: case Element::kRect_Type:
if (Element::kRect_Type == element.getType()) { if (Element::kRect_Type == element.getType()) {
if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) { if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) {
if (!prior->fRect.intersect(element.getRect())) { SkRect isectRect;
if (!isectRect.intersect(prior->getRect(), element.getRect())) {
prior->setEmpty(); prior->setEmpty();
return; return;
} }
prior->fRRect.setRect(isectRect);
prior->fDoAA = element.isAA(); prior->fDoAA = element.isAA();
Element* priorPrior = (Element*) iter.prev(); Element* priorPrior = (Element*) iter.prev();
prior->updateBoundAndGenID(priorPrior); prior->updateBoundAndGenID(priorPrior);