1 #ifndef SkPictureFlat_DEFINED 2 #define SkPictureFlat_DEFINED 3 4 #include "SkChunkAlloc.h" 5 #include "SkBitmap.h" 6 #include "SkPicture.h" 7 #include "SkMatrix.h" 8 #include "SkPaint.h" 9 #include "SkPath.h" 10 #include "SkRegion.h" 11 12 enum DrawType { 13 UNUSED, 14 CLIP_PATH, 15 CLIP_REGION, 16 CLIP_RECT, 17 CONCAT, 18 DRAW_BITMAP, 19 DRAW_BITMAP_MATRIX, 20 DRAW_BITMAP_RECT, 21 DRAW_CLEAR, 22 DRAW_DATA, 23 DRAW_PAINT, 24 DRAW_PATH, 25 DRAW_PICTURE, 26 DRAW_POINTS, 27 DRAW_POS_TEXT, 28 DRAW_POS_TEXT_H, 29 DRAW_POS_TEXT_H_TOP_BOTTOM, // fast variant of DRAW_POS_TEXT_H 30 DRAW_RECT, 31 DRAW_SHAPE, 32 DRAW_SPRITE, 33 DRAW_TEXT, 34 DRAW_TEXT_ON_PATH, 35 DRAW_TEXT_TOP_BOTTOM, // fast variant of DRAW_TEXT 36 DRAW_VERTICES, 37 RESTORE, 38 ROTATE, 39 SAVE, 40 SAVE_LAYER, 41 SCALE, 42 SET_MATRIX, 43 SKEW, 44 TRANSLATE 45 }; 46 47 enum DrawVertexFlags { 48 DRAW_VERTICES_HAS_TEXS = 0x01, 49 DRAW_VERTICES_HAS_COLORS = 0x02, 50 DRAW_VERTICES_HAS_INDICES = 0x04 51 }; 52 53 class SkRefCntPlayback { 54 public: 55 SkRefCntPlayback(); 56 virtual ~SkRefCntPlayback(); 57 58 int count() const { return fCount; } 59 60 void reset(const SkRefCntSet*); 61 62 void setCount(int count); 63 SkRefCnt* set(int index, SkRefCnt*); 64 65 virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const { 66 buffer.setRefCntArray(fArray, fCount); 67 } 68 69 protected: 70 int fCount; 71 SkRefCnt** fArray; 72 }; 73 74 class SkTypefacePlayback : public SkRefCntPlayback { 75 public: 76 virtual void setupBuffer(SkFlattenableReadBuffer& buffer) const { 77 buffer.setTypefaceArray((SkTypeface**)fArray, fCount); 78 } 79 }; 80 81 class SkFactoryPlayback { 82 public: 83 SkFactoryPlayback(int count) : fCount(count) { 84 fArray = SkNEW_ARRAY(SkFlattenable::Factory, count); 85 } 86 87 ~SkFactoryPlayback() { 88 SkDELETE_ARRAY(fArray); 89 } 90 91 SkFlattenable::Factory* base() const { return fArray; } 92 93 void setupBuffer(SkFlattenableReadBuffer& buffer) const { 94 buffer.setFactoryPlayback(fArray, fCount); 95 } 96 97 private: 98 int fCount; 99 SkFlattenable::Factory* fArray; 100 }; 101 102 class SkFlatData { 103 public: 104 static int Compare(const SkFlatData* a, const SkFlatData* b) { 105 return memcmp(&a->fAllocSize, &b->fAllocSize, a->fAllocSize); 106 } 107 108 int index() const { return fIndex; } 109 110 #ifdef SK_DEBUG_SIZE 111 size_t size() const { return sizeof(fIndex) + fAllocSize; } 112 #endif 113 114 protected: 115 static SkFlatData* Alloc(SkChunkAlloc* heap, int32_t size, int index); 116 117 int fIndex; 118 int32_t fAllocSize; 119 }; 120 121 class SkFlatBitmap : public SkFlatData { 122 public: 123 static SkFlatBitmap* Flatten(SkChunkAlloc*, const SkBitmap&, int index, 124 SkRefCntSet*); 125 126 void unflatten(SkBitmap* bitmap, SkRefCntPlayback* rcp) const { 127 SkFlattenableReadBuffer buffer(fBitmapData); 128 if (rcp) { 129 rcp->setupBuffer(buffer); 130 } 131 bitmap->unflatten(buffer); 132 } 133 134 #ifdef SK_DEBUG_VALIDATE 135 void validate() const { 136 // to be written 137 } 138 #endif 139 140 private: 141 char fBitmapData[1]; 142 typedef SkFlatData INHERITED; 143 }; 144 145 class SkFlatMatrix : public SkFlatData { 146 public: 147 static SkFlatMatrix* Flatten(SkChunkAlloc* heap, const SkMatrix& matrix, int index); 148 149 void unflatten(SkMatrix* result) const { 150 result->unflatten(fMatrixData); 151 } 152 153 #ifdef SK_DEBUG_DUMP 154 void dump() const; 155 #endif 156 157 #ifdef SK_DEBUG_VALIDATE 158 void validate() const { 159 // to be written 160 } 161 #endif 162 163 private: 164 char fMatrixData[1]; 165 typedef SkFlatData INHERITED; 166 }; 167 168 class SkFlatPaint : public SkFlatData { 169 public: 170 static SkFlatPaint* Flatten(SkChunkAlloc* heap, const SkPaint& paint, 171 int index, SkRefCntSet*, 172 SkRefCntSet* faceRecorder); 173 174 void unflatten(SkPaint* result, SkRefCntPlayback* rcp, 175 SkTypefacePlayback* facePlayback) const { 176 Read(fPaintData, result, rcp, facePlayback); 177 } 178 179 static void Read(const void* storage, SkPaint* paint, SkRefCntPlayback*, 180 SkTypefacePlayback* facePlayback); 181 182 #ifdef SK_DEBUG_DUMP 183 void dump() const; 184 #endif 185 186 private: 187 char fPaintData[1]; 188 typedef SkFlatData INHERITED; 189 }; 190 191 class SkFlatRegion : public SkFlatData { 192 public: 193 static SkFlatRegion* Flatten(SkChunkAlloc* heap, const SkRegion& region, int index); 194 195 void unflatten(SkRegion* result) const { 196 result->unflatten(fRegionData); 197 } 198 199 #ifdef SK_DEBUG_VALIDATE 200 void validate() const { 201 // to be written 202 } 203 #endif 204 205 private: 206 char fRegionData[1]; 207 typedef SkFlatData INHERITED; 208 }; 209 210 #endif 211