Move SkTDStackNester into its own private file.
authorscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 20 Nov 2013 20:47:21 +0000 (20:47 +0000)
committerscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 20 Nov 2013 20:47:21 +0000 (20:47 +0000)
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

experimental/PdfViewer/SkPdfGraphicsState.h
experimental/PdfViewer/src/SkTDStackNester.h [new file with mode: 0644]
gyp/pdfviewer_lib.gyp

index 6bb51b5294a0552d6b6e52a8b8dfee60558f4c2e..00bfeef109161376e788edc0c5c38e8e14ff8543 100644 (file)
@@ -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 SkPdfNativeDoc;
 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 (file)
index 0000000..4910ad1
--- /dev/null
@@ -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
index e25e02416693a3ad2f3f3f76335d54a8c32a7049..fd6d0fceb2f53b1c927190ae0a328c463ef2fa4c 100644 (file)
@@ -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',