Move SkTDStackNester into its own private file.

Also remove depth(), which is unused.

Otherwise the class is unchanged.

R=mtklein@google.com

Review URL: https://codereview.chromium.org/64093009

git-svn-id: http://skia.googlecode.com/svn/trunk@12324 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/PdfViewer/SkPdfGraphicsState.h b/experimental/PdfViewer/SkPdfGraphicsState.h
index 6bb51b5..00bfeef 100644
--- a/experimental/PdfViewer/SkPdfGraphicsState.h
+++ b/experimental/PdfViewer/SkPdfGraphicsState.h
@@ -12,6 +12,7 @@
 #include "SkPaint.h"
 #include "SkPdfConfig.h"
 #include "SkPdfUtils.h"
+#include "SkTDStackNester.h"
 
 class SkPdfAllocator;
 class SkPdfFont;
@@ -20,149 +21,8 @@
 class SkPdfNativeObject;
 class SkPdfResourceDictionary;
 class SkPdfSoftMaskDictionary;
-#include "SkTypes.h"
 
-
-// TODO(edisonn): move SkTDStackNester class in its own private file
-
-// Adobe limits it to 28, so 256 should be more than enough
-#define MAX_NESTING 256
-
-/** \class SkTDStackNester
- *
- * The difference between SkTDStackNester and SkTDStack is that:
- *   - SkTDStackNester uses new/delete to manage initializations
- *   - Supports nest/unnest which simulates a stack of stack. unnest will pop all the
- *     objects pushed since the last nest
- */
-
-template <typename T> class SkTDStackNester : SkNoncopyable {
-public:
-    SkTDStackNester() : fCount(0), fTotalCount(0), fLocalCount(0) {
-        fInitialRec.fNext = NULL;
-        fRec = &fInitialRec;
-
-    //  fCount = kSlotCount;
-    }
-
-    ~SkTDStackNester() {
-        Rec* rec = fRec;
-        while (rec != &fInitialRec) {
-            Rec* next = rec->fNext;
-            delete rec;
-            rec = next;
-        }
-    }
-
-    int count() const { return fLocalCount; }
-    int depth() const { return fLocalCount; }
-    bool empty() const { return fLocalCount == 0; }
-
-    int nests() {
-        return fNestingLevel;
-    }
-
-    void nest() {
-        // We are are past max nesting levels, we will still continue to work, but we might fail
-        // to properly ignore errors. Ideally it should only mean poor rendering in exceptional
-        // cases
-        if (fNestingLevel >= 0 && fNestingLevel < MAX_NESTING) {
-            fNestings[fNestingLevel] = fLocalCount;
-            fLocalCount = 0;
-        }
-        fNestingLevel++;
-    }
-
-    void unnest() {
-        SkASSERT(fNestingLevel > 0);
-        fNestingLevel--;
-        if (fNestingLevel >= 0 && fNestingLevel < MAX_NESTING) {
-            // TODO(edisonn): warn if fLocal > 0
-            while (fLocalCount > 0) {
-                pop();
-            }
-            fLocalCount = fNestings[fNestingLevel];
-        }
-    }
-
-    T* push() {
-        SkASSERT(fCount <= kSlotCount);
-        if (fCount == kSlotCount) {
-            Rec* rec = new Rec();
-            rec->fNext = fRec;
-            fRec = rec;
-            fCount = 0;
-        }
-        ++fTotalCount;
-        ++fLocalCount;
-        return &fRec->fSlots[fCount++];
-    }
-
-    void push(const T& elem) { *this->push() = elem; }
-
-    const T& index(int idx) const {
-        SkASSERT(fRec && fCount > idx);
-        return fRec->fSlots[fCount - idx - 1];
-    }
-
-    T& index(int idx) {
-        SkASSERT(fRec && fCount > idx);
-        return fRec->fSlots[fCount - idx - 1];
-    }
-
-    const T& top() const {
-        SkASSERT(fRec && fCount > 0);
-        return fRec->fSlots[fCount - 1];
-    }
-
-    T& top() {
-        SkASSERT(fRec && fCount > 0);
-        return fRec->fSlots[fCount - 1];
-    }
-
-    void pop(T* elem) {
-        if (elem) {
-            *elem = fRec->fSlots[fCount - 1];
-        }
-        this->pop();
-    }
-
-    void pop() {
-        SkASSERT(fCount > 0 && fRec);
-        --fLocalCount;
-        --fTotalCount;
-        if (--fCount == 0) {
-            if (fRec != &fInitialRec) {
-                Rec* rec = fRec->fNext;
-                delete fRec;
-                fCount = kSlotCount;
-                fRec = rec;
-            } else {
-                SkASSERT(fTotalCount == 0);
-            }
-        }
-    }
-
-private:
-    enum {
-        kSlotCount  = 64
-    };
-
-    struct Rec;
-    friend struct Rec;
-
-    struct Rec {
-        Rec* fNext;
-        T    fSlots[kSlotCount];
-    };
-    Rec     fInitialRec;
-    Rec*    fRec;
-    int     fCount, fTotalCount, fLocalCount;
-    int     fNestings[MAX_NESTING];
-    int     fNestingLevel;
-};
-
-/** \class SkTDStackNester
+/** \class SkPdfColorOperator
  *   Operates on stroking or non-stroking properties.
  */
 class SkPdfColorOperator {
diff --git a/experimental/PdfViewer/src/SkTDStackNester.h b/experimental/PdfViewer/src/SkTDStackNester.h
new file mode 100644
index 0000000..4910ad1
--- /dev/null
+++ b/experimental/PdfViewer/src/SkTDStackNester.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkTDStackNester_DEFINED
+#define SkTDStackNester_DEFINED
+
+#include "SkTypes.h"
+
+// Adobe limits it to 28, so 256 should be more than enough
+#define MAX_NESTING 256
+
+/** \class SkTDStackNester
+ *
+ * The difference between SkTDStackNester and SkTDStack is that:
+ *   - SkTDStackNester uses new/delete to manage initializations
+ *   - Supports nest/unnest which simulates a stack of stack. unnest will pop all the
+ *     objects pushed since the last nest
+ */
+
+template <typename T> class SkTDStackNester : SkNoncopyable {
+public:
+    SkTDStackNester() : fCount(0), fTotalCount(0), fLocalCount(0) {
+        fInitialRec.fNext = NULL;
+        fRec = &fInitialRec;
+
+    //  fCount = kSlotCount;
+    }
+
+    ~SkTDStackNester() {
+        Rec* rec = fRec;
+        while (rec != &fInitialRec) {
+            Rec* next = rec->fNext;
+            delete rec;
+            rec = next;
+        }
+    }
+
+    int count() const { return fLocalCount; }
+    bool empty() const { return fLocalCount == 0; }
+
+    int nests() {
+        return fNestingLevel;
+    }
+
+    void nest() {
+        // We are are past max nesting levels, we will still continue to work, but we might fail
+        // to properly ignore errors. Ideally it should only mean poor rendering in exceptional
+        // cases
+        if (fNestingLevel >= 0 && fNestingLevel < MAX_NESTING) {
+            fNestings[fNestingLevel] = fLocalCount;
+            fLocalCount = 0;
+        }
+        fNestingLevel++;
+    }
+
+    void unnest() {
+        SkASSERT(fNestingLevel > 0);
+        fNestingLevel--;
+        if (fNestingLevel >= 0 && fNestingLevel < MAX_NESTING) {
+            // TODO(edisonn): warn if fLocal > 0
+            while (fLocalCount > 0) {
+                pop();
+            }
+            fLocalCount = fNestings[fNestingLevel];
+        }
+    }
+
+    T* push() {
+        SkASSERT(fCount <= kSlotCount);
+        if (fCount == kSlotCount) {
+            Rec* rec = new Rec();
+            rec->fNext = fRec;
+            fRec = rec;
+            fCount = 0;
+        }
+        ++fTotalCount;
+        ++fLocalCount;
+        return &fRec->fSlots[fCount++];
+    }
+
+    void push(const T& elem) { *this->push() = elem; }
+
+    const T& index(int idx) const {
+        SkASSERT(fRec && fCount > idx);
+        return fRec->fSlots[fCount - idx - 1];
+    }
+
+    T& index(int idx) {
+        SkASSERT(fRec && fCount > idx);
+        return fRec->fSlots[fCount - idx - 1];
+    }
+
+    const T& top() const {
+        SkASSERT(fRec && fCount > 0);
+        return fRec->fSlots[fCount - 1];
+    }
+
+    T& top() {
+        SkASSERT(fRec && fCount > 0);
+        return fRec->fSlots[fCount - 1];
+    }
+
+    void pop(T* elem) {
+        if (elem) {
+            *elem = fRec->fSlots[fCount - 1];
+        }
+        this->pop();
+    }
+
+    void pop() {
+        SkASSERT(fCount > 0 && fRec);
+        --fLocalCount;
+        --fTotalCount;
+        if (--fCount == 0) {
+            if (fRec != &fInitialRec) {
+                Rec* rec = fRec->fNext;
+                delete fRec;
+                fCount = kSlotCount;
+                fRec = rec;
+            } else {
+                SkASSERT(fTotalCount == 0);
+            }
+        }
+    }
+
+private:
+    enum {
+        kSlotCount  = 64
+    };
+
+    struct Rec;
+    friend struct Rec;
+
+    struct Rec {
+        Rec* fNext;
+        T    fSlots[kSlotCount];
+    };
+    Rec     fInitialRec;
+    Rec*    fRec;
+    int     fCount, fTotalCount, fLocalCount;
+    int     fNestings[MAX_NESTING];
+    int     fNestingLevel;
+};
+#endif // SkTDStackNester_DEFINED
diff --git a/gyp/pdfviewer_lib.gyp b/gyp/pdfviewer_lib.gyp
index e25e024..fd6d0fc 100644
--- a/gyp/pdfviewer_lib.gyp
+++ b/gyp/pdfviewer_lib.gyp
@@ -12,7 +12,9 @@
         # FIXME: Include directory is named "inc" (instead of "include") in
         # order to not be considered the public API.
         '../experimental/PdfViewer/inc/SkPdfRenderer.h',
+
         '../experimental/PdfViewer/src/SkPdfRenderer.cpp',
+        '../experimental/PdfViewer/src/SkTDStackNester.h',
 
         '../experimental/PdfViewer/SkPdfGraphicsState.cpp',
         '../experimental/PdfViewer/SkPdfFont.cpp',
@@ -30,6 +32,7 @@
       'include_dirs': [
         '../experimental/PdfViewer',
         '../experimental/PdfViewer/inc',
+        '../experimental/PdfViewer/src',
         '../experimental/PdfViewer/pdfparser',
         '../experimental/PdfViewer/pdfparser/native',
         '../experimental/PdfViewer/pdfparser/native/pdfapi',