diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-11 14:36:57 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-05-11 14:36:57 +0000 |
commit | a1c6ff4922251065c45e3323e17e985a62931fc7 (patch) | |
tree | d3b4961a7c7d095e843c4a30a386a65620c2615f /src | |
parent | 7324415759fe0c5a0902877b664aa942a89bd940 (diff) |
inline isEmpty and isRect (faster)
git-svn-id: http://skia.googlecode.com/svn/trunk@3907 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkRasterClip.cpp | 54 | ||||
-rw-r--r-- | src/core/SkRasterClip.h | 29 |
2 files changed, 62 insertions, 21 deletions
diff --git a/src/core/SkRasterClip.cpp b/src/core/SkRasterClip.cpp index 5a2447dae9..09da0f7bab 100644 --- a/src/core/SkRasterClip.cpp +++ b/src/core/SkRasterClip.cpp @@ -10,6 +10,9 @@ SkRasterClip::SkRasterClip() { fIsBW = true; + fIsEmpty = true; + fIsRect = false; + SkDEBUGCODE(this->validate();) } SkRasterClip::SkRasterClip(const SkRasterClip& src) { @@ -21,22 +24,21 @@ SkRasterClip::SkRasterClip(const SkRasterClip& src) { } else { fAA = src.fAA; } + + fIsEmpty = src.isEmpty(); + fIsRect = src.isRect(); + SkDEBUGCODE(this->validate();) } SkRasterClip::SkRasterClip(const SkIRect& bounds) : fBW(bounds) { fIsBW = true; + fIsEmpty = this->computeIsEmpty(); // bounds might be empty, so compute + fIsRect = !fIsEmpty; + SkDEBUGCODE(this->validate();) } SkRasterClip::~SkRasterClip() { - AUTO_RASTERCLIP_VALIDATE(*this); -} - -bool SkRasterClip::isEmpty() const { - return fIsBW ? fBW.isEmpty() : fAA.isEmpty(); -} - -bool SkRasterClip::isRect() const { - return fIsBW ? fBW.isRect() : false; + SkDEBUGCODE(this->validate();) } bool SkRasterClip::isComplex() const { @@ -53,6 +55,8 @@ bool SkRasterClip::setEmpty() { fIsBW = true; fBW.setEmpty(); fAA.setEmpty(); + fIsEmpty = true; + fIsRect = false; return false; } @@ -61,22 +65,25 @@ bool SkRasterClip::setRect(const SkIRect& rect) { fIsBW = true; fAA.setEmpty(); - return fBW.setRect(rect); + fIsRect = fBW.setRect(rect); + fIsEmpty = !fIsRect; + return fIsRect; } bool SkRasterClip::setPath(const SkPath& path, const SkRegion& clip, bool doAA) { AUTO_RASTERCLIP_VALIDATE(*this); if (this->isBW() && !doAA) { - return fBW.setPath(path, clip); + (void)fBW.setPath(path, clip); } else { // TODO: since we are going to over-write fAA completely (aren't we?) // we should just clear our BW data (if any) and set fIsAA=true if (this->isBW()) { this->convertToAA(); } - return fAA.setPath(path, &clip, doAA); + (void)fAA.setPath(path, &clip, doAA); } + return this->updateCacheAndReturnNonEmpty(); } bool SkRasterClip::setPath(const SkPath& path, const SkIRect& clip, bool doAA) { @@ -102,19 +109,21 @@ bool SkRasterClip::setPath(const SkPath& path, const SkRasterClip& clip, bool SkRasterClip::op(const SkIRect& rect, SkRegion::Op op) { AUTO_RASTERCLIP_VALIDATE(*this); - return fIsBW ? fBW.op(rect, op) : fAA.op(rect, op); + fIsBW ? fBW.op(rect, op) : fAA.op(rect, op); + return this->updateCacheAndReturnNonEmpty(); } bool SkRasterClip::op(const SkRegion& rgn, SkRegion::Op op) { AUTO_RASTERCLIP_VALIDATE(*this); if (fIsBW) { - return fBW.op(rgn, op); + (void)fBW.op(rgn, op); } else { SkAAClip tmp; tmp.setRegion(rgn); - return fAA.op(tmp, op); + (void)fAA.op(tmp, op); } + return this->updateCacheAndReturnNonEmpty(); } bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) { @@ -122,7 +131,7 @@ bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) { clip.validate(); if (this->isBW() && clip.isBW()) { - return fBW.op(clip.fBW, op); + (void)fBW.op(clip.fBW, op); } else { SkAAClip tmp; const SkAAClip* other; @@ -136,8 +145,9 @@ bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) { } else { other = &clip.aaRgn(); } - return fAA.op(*other, op); + (void)fAA.op(*other, op); } + return this->updateCacheAndReturnNonEmpty(); } // return true if x is nearly integral (within 1/16) since that is the highest @@ -162,13 +172,14 @@ bool SkRasterClip::op(const SkRect& r, SkRegion::Op op, bool doAA) { if (fIsBW && !doAA) { SkIRect ir; r.round(&ir); - return fBW.op(ir, op); + (void)fBW.op(ir, op); } else { if (fIsBW) { this->convertToAA(); } - return fAA.op(r, op, doAA); + (void)fAA.op(r, op, doAA); } + return this->updateCacheAndReturnNonEmpty(); } void SkRasterClip::translate(int dx, int dy, SkRasterClip* dst) const { @@ -195,6 +206,7 @@ void SkRasterClip::translate(int dx, int dy, SkRasterClip* dst) const { fAA.translate(dx, dy, &dst->fAA); dst->fBW.setEmpty(); } + dst->updateCacheAndReturnNonEmpty(); } bool SkRasterClip::quickContains(const SkIRect& ir) const { @@ -218,6 +230,7 @@ void SkRasterClip::convertToAA() { SkASSERT(fIsBW); fAA.setRegion(fBW); fIsBW = false; + (void)this->updateCacheAndReturnNonEmpty(); } #ifdef SK_DEBUG @@ -229,6 +242,9 @@ void SkRasterClip::validate() const { fBW.validate(); fAA.validate(); + + SkASSERT(this->computeIsEmpty() == fIsEmpty); + SkASSERT(this->computeIsRect() == fIsRect); } #endif diff --git a/src/core/SkRasterClip.h b/src/core/SkRasterClip.h index 8f182701b8..0ac7ff4d8a 100644 --- a/src/core/SkRasterClip.h +++ b/src/core/SkRasterClip.h @@ -23,8 +23,16 @@ public: const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; } const SkAAClip& aaRgn() const { SkASSERT(!fIsBW); return fAA; } - bool isEmpty() const; - bool isRect() const; + bool isEmpty() const { + SkASSERT(this->computeIsEmpty() == fIsEmpty); + return fIsEmpty; + } + + bool isRect() const { + SkASSERT(this->computeIsRect() == fIsRect); + return fIsRect; + } + bool isComplex() const; const SkIRect& getBounds() const; @@ -73,6 +81,23 @@ private: SkRegion fBW; SkAAClip fAA; bool fIsBW; + // these 2 are caches based on querying the right obj based on fIsBW + bool fIsEmpty; + bool fIsRect; + + bool computeIsEmpty() const { + return fIsBW ? fBW.isEmpty() : fAA.isEmpty(); + } + + bool computeIsRect() const { + return fIsBW ? fBW.isRect() : false; + } + + bool updateCacheAndReturnNonEmpty() { + fIsEmpty = this->computeIsEmpty(); + fIsRect = this->computeIsRect(); + return !fIsEmpty; + } void convertToAA(); }; |