SkPicturePlayback.h revision 5667afc5cb4a8cd15a27667f222b6d9c94d61c38
1#ifndef SkPicturePlayback_DEFINED 2#define SkPicturePlayback_DEFINED 3 4#include "SkPicture.h" 5#include "SkReader32.h" 6 7#include "SkBitmap.h" 8#include "SkMatrix.h" 9#include "SkPaint.h" 10#include "SkPath.h" 11#include "SkPathHeap.h" 12#include "SkRegion.h" 13#include "SkPictureFlat.h" 14 15#ifdef ANDROID 16#include "SkThread.h" 17#endif 18 19class SkPictureRecord; 20class SkStream; 21class SkWStream; 22 23class SkPicturePlayback { 24public: 25 SkPicturePlayback(); 26 SkPicturePlayback(const SkPicturePlayback& src); 27 explicit SkPicturePlayback(const SkPictureRecord& record); 28 explicit SkPicturePlayback(SkStream*); 29 30 virtual ~SkPicturePlayback(); 31 32 void draw(SkCanvas& canvas); 33 34 void serialize(SkWStream*) const; 35 36 void dumpSize() const; 37 38 // Can be called in the middle of playback (the draw() call). WIll abort the 39 // drawing and return from draw() after the "current" op code is done 40 void abort(); 41 42private: 43 44 class TextContainer { 45 public: 46 size_t length() { return fByteLength; } 47 const void* text() { return (const void*) fText; } 48 size_t fByteLength; 49 const char* fText; 50 }; 51 52 const SkBitmap& getBitmap() { 53 int index = getInt(); 54 SkASSERT(index > 0); 55 return fBitmaps[index - 1]; 56 } 57 58 int getIndex() { return fReader.readInt(); } 59 int getInt() { return fReader.readInt(); } 60 61 const SkMatrix* getMatrix() { 62 int index = getInt(); 63 if (index == 0) { 64 return NULL; 65 } 66 SkASSERT(index > 0 && index <= fMatrixCount); 67 return &fMatrices[index - 1]; 68 } 69 70 const SkPath& getPath() { 71 return (*fPathHeap)[getInt() - 1]; 72 } 73 74 SkPicture& getPicture() { 75 int index = getInt(); 76 SkASSERT(index > 0 && index <= fPictureCount); 77 return *fPictureRefs[index - 1]; 78 } 79 80 const SkPaint* getPaint() { 81 int index = getInt(); 82 if (index == 0) { 83 return NULL; 84 } 85 SkASSERT(index > 0 && index <= fPaintCount); 86 return &fPaints[index - 1]; 87 } 88 89 const SkRect* getRectPtr() { 90 if (fReader.readBool()) { 91 return fReader.skipRect(); 92 } else { 93 return NULL; 94 } 95 } 96 97 const SkIRect* getIRectPtr() { 98 if (fReader.readBool()) { 99 return (const SkIRect*)fReader.skip(sizeof(SkIRect)); 100 } else { 101 return NULL; 102 } 103 } 104 105 const SkRegion& getRegion() { 106 int index = getInt(); 107 SkASSERT(index > 0); 108 return fRegions[index - 1]; 109 } 110 111 SkScalar getScalar() { return fReader.readScalar(); } 112 113 void getText(TextContainer* text) { 114 size_t length = text->fByteLength = getInt(); 115 text->fText = (const char*)fReader.skip(length); 116 } 117 118 void init(); 119 120#ifdef SK_DEBUG_SIZE 121public: 122 int size(size_t* sizePtr); 123 int bitmaps(size_t* size); 124 int paints(size_t* size); 125 int paths(size_t* size); 126 int regions(size_t* size); 127#endif 128 129#ifdef SK_DEBUG_DUMP 130private: 131 void dumpBitmap(const SkBitmap& bitmap) const; 132 void dumpMatrix(const SkMatrix& matrix) const; 133 void dumpPaint(const SkPaint& paint) const; 134 void dumpPath(const SkPath& path) const; 135 void dumpPicture(const SkPicture& picture) const; 136 void dumpRegion(const SkRegion& region) const; 137 int dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType); 138 int dumpInt(char* bufferPtr, char* buffer, char* name); 139 int dumpRect(char* bufferPtr, char* buffer, char* name); 140 int dumpPoint(char* bufferPtr, char* buffer, char* name); 141 void dumpPointArray(char** bufferPtrPtr, char* buffer, int count); 142 int dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr); 143 int dumpRectPtr(char* bufferPtr, char* buffer, char* name); 144 int dumpScalar(char* bufferPtr, char* buffer, char* name); 145 void dumpText(char** bufferPtrPtr, char* buffer); 146 void dumpStream(); 147 148public: 149 void dump() const; 150#endif 151 152private: 153 SkPathHeap* fPathHeap; // reference counted 154 SkBitmap* fBitmaps; 155 int fBitmapCount; 156 SkMatrix* fMatrices; 157 int fMatrixCount; 158 SkPaint* fPaints; 159 int fPaintCount; 160 SkRegion* fRegions; 161 int fRegionCount; 162 mutable SkFlattenableReadBuffer fReader; 163 164 SkPicture** fPictureRefs; 165 int fPictureCount; 166 167 SkRefCntPlayback fRCPlayback; 168 SkTypefacePlayback fTFPlayback; 169 SkFactoryPlayback* fFactoryPlayback; 170#ifdef ANDROID 171 SkMutex fDrawMutex; 172#endif 173}; 174 175#endif 176