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