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

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

@ -32,7 +32,7 @@ bool SkClipStack::Element::operator== (const Element& element) const {
case kRRect_Type:
return fRRect == element.fRRect;
case kRect_Type:
return fRect == element.fRect;
return this->getRect() == element.getRect();
case kEmpty_Type:
return true;
default:
@ -45,7 +45,7 @@ void SkClipStack::Element::invertShapeFillType() {
switch (fType) {
case kRect_Type:
fPath.reset();
fPath.addRect(fRect);
fPath.addRect(this->getRect());
fPath.setFillType(SkPath::kInverseEvenOdd_FillType);
fType = kPath_Type;
break;
@ -91,7 +91,7 @@ void SkClipStack::Element::asPath(SkPath* path) const {
break;
case kRect_Type:
path->reset();
path->addRect(fRect);
path->addRect(this->getRect());
break;
case kRRect_Type:
path->reset();
@ -108,7 +108,6 @@ void SkClipStack::Element::setEmpty() {
fFiniteBound.setEmpty();
fFiniteBoundType = kNormal_BoundsType;
fIsIntersectionOfRects = false;
fRect.setEmpty();
fRRect.setEmpty();
fPath.reset();
fGenID = kEmptyGenID;
@ -143,12 +142,12 @@ bool SkClipStack::Element::rectRectIntersectAllowed(const SkRect& newR, bool new
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
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
// issue
return true;
@ -343,13 +342,13 @@ void SkClipStack::Element::updateBoundAndGenID(const Element* prior) {
fIsIntersectionOfRects = false;
switch (fType) {
case kRect_Type:
fFiniteBound = fRect;
fFiniteBound = this->getRect();
fFiniteBoundType = kNormal_BoundsType;
if (SkRegion::kReplace_Op == fOp ||
(SkRegion::kIntersect_Op == fOp && NULL == prior) ||
(SkRegion::kIntersect_Op == fOp && prior->fIsIntersectionOfRects &&
prior->rectRectIntersectAllowed(fRect, fDoAA))) {
prior->rectRectIntersectAllowed(this->getRect(), fDoAA))) {
fIsIntersectionOfRects = true;
}
break;
@ -632,11 +631,13 @@ void SkClipStack::pushElement(const Element& element) {
case Element::kRect_Type:
if (Element::kRect_Type == element.getType()) {
if (prior->rectRectIntersectAllowed(element.getRect(), element.isAA())) {
if (!prior->fRect.intersect(element.getRect())) {
SkRect isectRect;
if (!isectRect.intersect(prior->getRect(), element.getRect())) {
prior->setEmpty();
return;
}
prior->fRRect.setRect(isectRect);
prior->fDoAA = element.isAA();
Element* priorPrior = (Element*) iter.prev();
prior->updateBoundAndGenID(priorPrior);