inline isEmpty and isRect (faster)



git-svn-id: http://skia.googlecode.com/svn/trunk@3907 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkRasterClip.cpp b/src/core/SkRasterClip.cpp
index 5a2447d..09da0f7 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 @@
     } 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 @@
     fIsBW = true;
     fBW.setEmpty();
     fAA.setEmpty();
+    fIsEmpty = true;
+    fIsRect = false;
     return false;
 }
 
@@ -61,22 +65,25 @@
     
     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::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 @@
     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 @@
         } 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 @@
     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 @@
         fAA.translate(dx, dy, &dst->fAA);
         dst->fBW.setEmpty();
     }
+    dst->updateCacheAndReturnNonEmpty();
 }
 
 bool SkRasterClip::quickContains(const SkIRect& ir) const {
@@ -218,6 +230,7 @@
     SkASSERT(fIsBW);
     fAA.setRegion(fBW);
     fIsBW = false;
+    (void)this->updateCacheAndReturnNonEmpty();
 }
 
 #ifdef SK_DEBUG
@@ -229,6 +242,9 @@
 
     fBW.validate();
     fAA.validate();
+
+    SkASSERT(this->computeIsEmpty() == fIsEmpty);
+    SkASSERT(this->computeIsRect() == fIsRect);
 }
 #endif