Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Unified Diff: experimental/PdfViewer/SkPdfGraphicsState.h

Issue 23258004: pdfviewer: code cleanup - remove STL usage (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.cpp ('k') | experimental/PdfViewer/SkPdfRenderer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: experimental/PdfViewer/SkPdfGraphicsState.h
===================================================================
--- experimental/PdfViewer/SkPdfGraphicsState.h (revision 10721)
+++ experimental/PdfViewer/SkPdfGraphicsState.h (working copy)
@@ -6,7 +6,7 @@
#include "SkPdfConfig.h"
#include "SkPdfUtils.h"
-#include <stack>
+//#include "SkTDStack.h"
class SkPdfFont;
class SkPdfDoc;
@@ -17,6 +17,106 @@
class SkPdfNativeDoc;
class SkPdfAllocator;
+// TODO(edisonn): move this class in iclude/core?
+// Ref objects can't be dealt unless we use a specific class initialization
+// The difference between SkTDStackNew and SkTDStack is that SkTDStackNew uses new/delete
+// to be a manage c++ stuff (like initializations)
+#include "SkTypes.h"
+template <typename T> class SkTDStackNew : SkNoncopyable {
+public:
+ SkTDStackNew() : fCount(0), fTotalCount(0) {
+ fInitialRec.fNext = NULL;
+ fRec = &fInitialRec;
+
+ // fCount = kSlotCount;
+ }
+
+ ~SkTDStackNew() {
+ Rec* rec = fRec;
+ while (rec != &fInitialRec) {
+ Rec* next = rec->fNext;
+ delete rec;
+ rec = next;
+ }
+ }
+
+ int count() const { return fTotalCount; }
+ int depth() const { return fTotalCount; }
+ bool empty() const { return fTotalCount == 0; }
+
+ T* push() {
+ SkASSERT(fCount <= kSlotCount);
+ if (fCount == kSlotCount) {
+ Rec* rec = new Rec();
+ rec->fNext = fRec;
+ fRec = rec;
+ fCount = 0;
+ }
+ ++fTotalCount;
+ 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);
+ --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;
+};
+
// TODO(edisonn): better class design.
class SkPdfColorOperator {
@@ -88,8 +188,6 @@
SkPath fPath;
bool fPathClosed;
-
-
double fTextLeading;
double fWordSpace;
double fCharSpace;
@@ -361,8 +459,8 @@
// TODO(edisonn): rename to SkPdfContext
class SkPdfContext {
public:
- std::stack<SkPdfNativeObject*> fObjectStack;
- std::stack<SkPdfGraphicsState> fStateStack;
+ SkTDStackNew<SkPdfNativeObject*> fObjectStack;
+ SkTDStackNew<SkPdfGraphicsState> fStateStack;
SkPdfGraphicsState fGraphicsState;
SkPdfNativeDoc* fPdfDoc;
// TODO(edisonn): the allocator, could be freed after the page is done drawing.
« no previous file with comments | « experimental/PdfViewer/SkPdfFont.cpp ('k') | experimental/PdfViewer/SkPdfRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698