refactor to use a shared function (clipPathHelper) between
SkCanvas::clipPath() and SkCanvas::validateClip().



git-svn-id: http://skia.googlecode.com/svn/trunk@840 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 94db24c..1ca31df 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -919,30 +919,6 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-#ifdef SK_DEBUG
-void SkCanvas::validateClip() const {
-    const SkRegion& rgn = this->getTotalClip();
-    const SkDevice* device = this->getDevice();
-    SkIRect ir;
-    ir.set(0, 0, device->width(), device->height());
-    SkRegion clipRgn(ir);
-
-    SkClipStack::B2FIter                iter(fClipStack);
-    const SkClipStack::B2FIter::Clip*   clip;
-    while ((clip = iter.next()) != NULL) {
-        if (clip->fPath) {
-            clipRgn.setPath(*clip->fPath, clipRgn);
-        } else if (clip->fRect) {
-            clip->fRect->round(&ir);
-            clipRgn.op(ir, clip->fOp);
-        } else {
-            break;
-        }
-    }
-    SkASSERT(rgn == clipRgn);
-}
-#endif
-
 bool SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op) {
     AutoValidateClip avc(this);
 
@@ -974,6 +950,25 @@
     }
 }
 
+static bool clipPathHelper(const SkCanvas* canvas, SkRegion* currRgn,
+                           const SkPath& devPath, SkRegion::Op op) {
+    if (SkRegion::kIntersect_Op == op) {
+        return currRgn->setPath(devPath, *currRgn);
+    } else {
+        SkRegion base;
+        const SkBitmap& bm = canvas->getDevice()->accessBitmap(false);
+        base.setRect(0, 0, bm.width(), bm.height());
+
+        if (SkRegion::kReplace_Op == op) {
+            return currRgn->setPath(devPath, base);
+        } else {
+            SkRegion rgn;
+            rgn.setPath(devPath, base);
+            return currRgn->op(rgn, op);
+        }
+    }
+}
+
 bool SkCanvas::clipPath(const SkPath& path, SkRegion::Op op) {
     AutoValidateClip avc(this);
 
@@ -987,21 +982,7 @@
     // if we called path.swap() we could avoid a deep copy of this path
     fClipStack.clipDevPath(devPath, op);
 
-    if (SkRegion::kIntersect_Op == op) {
-        return fMCRec->fRegion->setPath(devPath, *fMCRec->fRegion);
-    } else {
-        SkRegion base;
-        const SkBitmap& bm = this->getDevice()->accessBitmap(false);
-        base.setRect(0, 0, bm.width(), bm.height());
-
-        if (SkRegion::kReplace_Op == op) {
-            return fMCRec->fRegion->setPath(devPath, base);
-        } else {
-            SkRegion rgn;
-            rgn.setPath(devPath, base);
-            return fMCRec->fRegion->op(rgn, op);
-        }
-    }
+    return clipPathHelper(this, fMCRec->fRegion, devPath, op);
 }
 
 bool SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) {
@@ -1018,6 +999,33 @@
     return fMCRec->fRegion->op(rgn, op);
 }
 
+#ifdef SK_DEBUG
+void SkCanvas::validateClip() const {
+    // construct clipRgn from the clipstack
+    const SkDevice* device = this->getDevice();
+    SkIRect ir;
+    ir.set(0, 0, device->width(), device->height());
+    SkRegion clipRgn(ir);
+
+    SkClipStack::B2FIter                iter(fClipStack);
+    const SkClipStack::B2FIter::Clip*   clip;
+    while ((clip = iter.next()) != NULL) {
+        if (clip->fPath) {
+            clipPathHelper(this, &clipRgn, *clip->fPath, clip->fOp);
+        } else if (clip->fRect) {
+            clip->fRect->round(&ir);
+            clipRgn.op(ir, clip->fOp);
+        } else {
+            break;
+        }
+    }
+
+    // now compare against the current rgn
+    const SkRegion& rgn = this->getTotalClip();
+    SkASSERT(rgn == clipRgn);
+}
+#endif
+
 ///////////////////////////////////////////////////////////////////////////////
 
 void SkCanvas::computeLocalClipBoundsCompareType(EdgeType et) const {