| 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.
|
|
|