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