aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-10 19:36:25 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-10-10 19:36:25 +0000
commitd1e3c5fde3f2ed309273cb08dbba2309b13e527f (patch)
tree8e82ec31219aa28ff3c35a4aef438eb120f874a7
parentf3c1da1e977a0e02535af71749fe9e92665ed51e (diff)
add experimental wrapper for region+aaclip
git-svn-id: http://skia.googlecode.com/svn/trunk@2451 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--src/core/SkRasterClip.cpp104
-rw-r--r--src/core/SkRasterClip.h49
2 files changed, 153 insertions, 0 deletions
diff --git a/src/core/SkRasterClip.cpp b/src/core/SkRasterClip.cpp
new file mode 100644
index 0000000000..0f9d3f9d1b
--- /dev/null
+++ b/src/core/SkRasterClip.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkRasterClip.h"
+
+
+SkRasterClip::SkRasterClip() {
+ fIsBW = true;
+}
+
+bool SkRasterClip::isEmpty() const {
+ return fIsBW ? fBW.isEmpty() : fAA.isEmpty();
+}
+
+bool SkRasterClip::isRect() const {
+ return fIsBW ? fBW.isRect() : false;
+}
+
+bool SkRasterClip::isComplex() const {
+ return fIsBW ? fBW.isComplex() : !fAA.isEmpty();
+}
+
+const SkIRect& SkRasterClip::getBounds() const {
+ return fIsBW ? fBW.getBounds() : fAA.getBounds();
+}
+
+bool SkRasterClip::setEmpty() {
+ fIsBW = true;
+ fBW.setEmpty();
+ fAA.setEmpty();
+ return false;
+}
+
+bool SkRasterClip::setIRect(const SkIRect& rect) {
+ fIsBW = true;
+ fAA.setEmpty();
+ return fBW.setRect(rect);
+}
+
+bool SkRasterClip::setPath(const SkPath& path, const SkRegion& clip, bool doAA) {
+ if (this->isBW() && !doAA) {
+ return fBW.setPath(path, clip);
+ } else {
+ if (this->isBW()) {
+ this->convertToAA();
+ }
+ return fAA.setPath(path, &clip, doAA);
+ }
+}
+
+bool SkRasterClip::setPath(const SkPath& path, const SkIRect& clip, bool doAA) {
+ SkRegion tmp;
+ tmp.setRect(clip);
+ return this->setPath(path, tmp, doAA);
+}
+
+bool SkRasterClip::setPath(const SkPath& path, const SkRasterClip& clip,
+ bool doAA) {
+ if (clip.isBW()) {
+ return this->setPath(path, clip.bwRgn(), doAA);
+ } else {
+ SkRegion tmp;
+ tmp.setRect(clip.getBounds());
+ if (!this->setPath(path, clip, doAA)) {
+ return false;
+ }
+ return this->op(clip, SkRegion::kIntersect_Op);
+ }
+}
+
+bool SkRasterClip::op(const SkIRect& rect, SkRegion::Op op) {
+ return fIsBW ? fBW.op(rect, op) : fAA.op(rect, op);
+}
+
+bool SkRasterClip::op(const SkRasterClip& clip, SkRegion::Op op) {
+ if (this->isBW() && clip.isBW()) {
+ return fBW.op(clip.fBW, op);
+ } else {
+ SkAAClip tmp;
+ const SkAAClip* other;
+
+ if (this->isBW()) {
+ this->convertToAA();
+ }
+ if (clip.isBW()) {
+ tmp.setRegion(clip.bwRgn());
+ other = &tmp;
+ } else {
+ other = &clip.aaRgn();
+ }
+ return fAA.op(*other, op);
+ }
+}
+
+void SkRasterClip::convertToAA() {
+ SkASSERT(fIsBW);
+ fAA.setRegion(fBW);
+ fIsBW = false;
+}
+
diff --git a/src/core/SkRasterClip.h b/src/core/SkRasterClip.h
new file mode 100644
index 0000000000..77e6baa975
--- /dev/null
+++ b/src/core/SkRasterClip.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2010 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkRasterClip_DEFINED
+#define SkRasterClip_DEFINED
+
+#include "SkRegion.h"
+#include "SkAAClip.h"
+
+class SkRasterClip {
+public:
+ SkRasterClip();
+ SkRasterClip(const SkRasterClip&);
+ ~SkRasterClip();
+
+ bool isBW() const { return fIsBW; }
+ bool isAA() const { return !fIsBW; }
+
+ bool isEmpty() const;
+ bool isRect() const;
+ bool isComplex() const;
+ const SkIRect& getBounds() const;
+
+ bool setEmpty();
+ bool setIRect(const SkIRect&);
+
+ bool setPath(const SkPath& path, const SkRegion& clip, bool doAA);
+ bool setPath(const SkPath& path, const SkIRect& clip, bool doAA);
+ bool setPath(const SkPath& path, const SkRasterClip&, bool doAA);
+
+ bool op(const SkIRect&, SkRegion::Op);
+ bool op(const SkRasterClip&, SkRegion::Op);
+
+ const SkRegion& bwRgn() const { SkASSERT(fIsBW); return fBW; }
+ const SkAAClip& aaRgn() const { SkASSERT(!fIsBW); return fAA; }
+
+private:
+ SkRegion fBW;
+ SkAAClip fAA;
+ bool fIsBW;
+
+ void convertToAA();
+};
+
+#endif