aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-23 18:56:55 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-02-23 18:56:55 +0000
commit819c921b0445fa9f45f18d4a560603cd9fde6ba4 (patch)
tree7ef834990dcbe2bec2810542139321bf591589d2 /src
parent7b19d6d12c36fed79c7d8ddafa2895de9e0cd641 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/core/SkCanvas.cpp86
1 files changed, 47 insertions, 39 deletions
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 94db24cfe5..1ca31df93b 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -919,30 +919,6 @@ void SkCanvas::resetMatrix() {
//////////////////////////////////////////////////////////////////////////////
-#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 @@ bool SkCanvas::clipRect(const SkRect& rect, SkRegion::Op op) {
}
}
+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 @@ bool SkCanvas::clipPath(const SkPath& path, SkRegion::Op op) {
// 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 @@ bool SkCanvas::clipRegion(const SkRegion& rgn, SkRegion::Op op) {
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 {