Extended SkDeque's reverse iteration capability to SkClipStack

http://codereview.appspot.com/6409046/



git-svn-id: http://skia.googlecode.com/svn/trunk@4631 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/core/SkClipStack.cpp b/src/core/SkClipStack.cpp
index 567fd7e..71b988d 100644
--- a/src/core/SkClipStack.cpp
+++ b/src/core/SkClipStack.cpp
@@ -202,11 +202,11 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-SkClipStack::B2FIter::B2FIter() {
+SkClipStack::Iter::Iter() {
 }
 
-bool operator==(const SkClipStack::B2FIter::Clip& a,
-               const SkClipStack::B2FIter::Clip& b) {
+bool operator==(const SkClipStack::Iter::Clip& a,
+                const SkClipStack::Iter::Clip& b) {
     return a.fOp == b.fOp && a.fDoAA == b.fDoAA &&
            ((a.fRect == NULL && b.fRect == NULL) ||
                (a.fRect != NULL && b.fRect != NULL && *a.fRect == *b.fRect)) &&
@@ -214,21 +214,17 @@
                (a.fPath != NULL && b.fPath != NULL && *a.fPath == *b.fPath));
 }
 
-bool operator!=(const SkClipStack::B2FIter::Clip& a,
-               const SkClipStack::B2FIter::Clip& b) {
+bool operator!=(const SkClipStack::Iter::Clip& a,
+                const SkClipStack::Iter::Clip& b) {
     return !(a == b);
 }
 
-SkClipStack::B2FIter::B2FIter(const SkClipStack& stack) {
-    this->reset(stack);
+SkClipStack::Iter::Iter(const SkClipStack& stack, IterStart startLoc) {
+    this->reset(stack, startLoc);
 }
 
-const SkClipStack::B2FIter::Clip* SkClipStack::B2FIter::next() {
-    const SkClipStack::Rec* rec = (const SkClipStack::Rec*)fIter.next();
-    if (NULL == rec) {
-        return NULL;
-    }
-
+const SkClipStack::Iter::Clip* SkClipStack::Iter::updateClip(
+                        const SkClipStack::Rec* rec) {
     switch (rec->fState) {
         case SkClipStack::Rec::kEmpty_State:
             fClip.fRect = NULL;
@@ -248,6 +244,24 @@
     return &fClip;
 }
 
-void SkClipStack::B2FIter::reset(const SkClipStack& stack) {
-    fIter.reset(stack.fDeque);
+const SkClipStack::Iter::Clip* SkClipStack::Iter::next() {
+    const SkClipStack::Rec* rec = (const SkClipStack::Rec*)fIter.next();
+    if (NULL == rec) {
+        return NULL;
+    }
+
+    return this->updateClip(rec);
+}
+
+const SkClipStack::Iter::Clip* SkClipStack::Iter::prev() {
+    const SkClipStack::Rec* rec = (const SkClipStack::Rec*)fIter.prev();
+    if (NULL == rec) {
+        return NULL;
+    }
+
+    return this->updateClip(rec);
+}
+
+void SkClipStack::Iter::reset(const SkClipStack& stack, IterStart startLoc) {
+    fIter.reset(stack.fDeque, static_cast<SkDeque::Iter::IterStart>(startLoc));
 }