OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #ifndef SkPicturePlayback_DEFINED | 9 #ifndef SkPicturePlayback_DEFINED |
10 #define SkPicturePlayback_DEFINED | 10 #define SkPicturePlayback_DEFINED |
11 | 11 |
| 12 #include "SkBitmap.h" |
| 13 #include "SkPathHeap.h" |
12 #include "SkPicture.h" | 14 #include "SkPicture.h" |
13 #include "SkReader32.h" | |
14 | |
15 #include "SkBitmap.h" | |
16 #include "SkData.h" | |
17 #include "SkMatrix.h" | |
18 #include "SkReadBuffer.h" | |
19 #include "SkPaint.h" | |
20 #include "SkPath.h" | |
21 #include "SkPathHeap.h" | |
22 #include "SkRegion.h" | |
23 #include "SkRRect.h" | |
24 #include "SkPictureFlat.h" | 15 #include "SkPictureFlat.h" |
25 | 16 |
26 #ifdef SK_BUILD_FOR_ANDROID | 17 #ifdef SK_BUILD_FOR_ANDROID |
27 #include "SkThread.h" | 18 #include "SkThread.h" |
28 #endif | 19 #endif |
29 | 20 |
| 21 class SkData; |
30 class SkPictureRecord; | 22 class SkPictureRecord; |
| 23 class SkReader32; |
31 class SkStream; | 24 class SkStream; |
32 class SkWStream; | 25 class SkWStream; |
33 class SkBBoxHierarchy; | 26 class SkBBoxHierarchy; |
| 27 class SkMatrix; |
| 28 class SkPaint; |
| 29 class SkPath; |
34 class SkPictureStateTree; | 30 class SkPictureStateTree; |
| 31 class SkReadBuffer; |
| 32 class SkRegion; |
35 | 33 |
36 struct SkPictInfo { | 34 struct SkPictInfo { |
37 enum Flags { | 35 enum Flags { |
38 kCrossProcess_Flag = 1 << 0, | 36 kCrossProcess_Flag = 1 << 0, |
39 kScalarIsFloat_Flag = 1 << 1, | 37 kScalarIsFloat_Flag = 1 << 1, |
40 kPtrIs64Bit_Flag = 1 << 2, | 38 kPtrIs64Bit_Flag = 1 << 2, |
41 }; | 39 }; |
42 | 40 |
43 char fMagic[8]; | 41 char fMagic[8]; |
44 uint32_t fVersion; | 42 uint32_t fVersion; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 struct SkPictCopyInfo { | 117 struct SkPictCopyInfo { |
120 SkPictCopyInfo() : initialized(false), controller(1024) {} | 118 SkPictCopyInfo() : initialized(false), controller(1024) {} |
121 | 119 |
122 bool initialized; | 120 bool initialized; |
123 SkChunkFlatController controller; | 121 SkChunkFlatController controller; |
124 SkTDArray<SkFlatData*> paintData; | 122 SkTDArray<SkFlatData*> paintData; |
125 }; | 123 }; |
126 | 124 |
127 class SkPicturePlayback { | 125 class SkPicturePlayback { |
128 public: | 126 public: |
129 SkPicturePlayback(const SkPicture* picture, const SkPicturePlayback& src, | 127 SkPicturePlayback(const SkPicturePlayback& src, |
130 SkPictCopyInfo* deepCopyInfo = NULL); | 128 SkPictCopyInfo* deepCopyInfo = NULL); |
131 SkPicturePlayback(const SkPicture* picture, const SkPictureRecord& record, | 129 SkPicturePlayback(const SkPictureRecord& record, const SkPictInfo&, bool dee
pCopyOps); |
132 const SkPictInfo&, bool deepCopyOps); | 130 static SkPicturePlayback* CreateFromStream(SkStream*, |
133 static SkPicturePlayback* CreateFromStream(SkPicture* picture, | |
134 SkStream*, | |
135 const SkPictInfo&, | 131 const SkPictInfo&, |
136 SkPicture::InstallPixelRefProc); | 132 SkPicture::InstallPixelRefProc); |
137 static SkPicturePlayback* CreateFromBuffer(SkPicture* picture, | 133 static SkPicturePlayback* CreateFromBuffer(SkReadBuffer&, |
138 SkReadBuffer&, | |
139 const SkPictInfo&); | 134 const SkPictInfo&); |
140 | 135 |
141 virtual ~SkPicturePlayback(); | 136 virtual ~SkPicturePlayback(); |
142 | 137 |
143 const SkPicture::OperationList& getActiveOps(const SkIRect& queryRect); | 138 const SkPicture::OperationList& getActiveOps(const SkIRect& queryRect); |
144 | 139 |
145 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } | 140 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } |
146 | 141 |
147 void draw(SkCanvas& canvas, SkDrawPictureCallback*); | 142 void draw(SkCanvas& canvas, SkDrawPictureCallback*); |
148 | 143 |
149 void serialize(SkWStream*, SkPicture::EncodeBitmap) const; | 144 void serialize(SkWStream*, SkPicture::EncodeBitmap) const; |
150 void flatten(SkWriteBuffer&) const; | 145 void flatten(SkWriteBuffer&) const; |
151 | 146 |
152 void dumpSize() const; | 147 void dumpSize() const; |
153 | 148 |
154 bool containsBitmaps() const; | 149 bool containsBitmaps() const; |
155 | 150 |
156 #ifdef SK_BUILD_FOR_ANDROID | 151 #ifdef SK_BUILD_FOR_ANDROID |
157 // Can be called in the middle of playback (the draw() call). WIll abort the | 152 // Can be called in the middle of playback (the draw() call). WIll abort the |
158 // drawing and return from draw() after the "current" op code is done | 153 // drawing and return from draw() after the "current" op code is done |
159 void abort() { fAbortCurrentPlayback = true; } | 154 void abort() { fAbortCurrentPlayback = true; } |
160 #endif | 155 #endif |
161 | 156 |
162 size_t curOpID() const { return fCurOffset; } | 157 size_t curOpID() const { return fCurOffset; } |
163 void resetOpID() { fCurOffset = 0; } | 158 void resetOpID() { fCurOffset = 0; } |
164 | 159 |
165 protected: | 160 protected: |
166 explicit SkPicturePlayback(const SkPicture* picture, const SkPictInfo& info)
; | 161 explicit SkPicturePlayback(const SkPictInfo& info); |
167 | 162 |
168 bool parseStream(SkPicture* picture, SkStream*, SkPicture::InstallPixelRefPr
oc); | 163 bool parseStream(SkStream*, SkPicture::InstallPixelRefProc); |
169 bool parseBuffer(SkPicture* picture, SkReadBuffer& buffer); | 164 bool parseBuffer(SkReadBuffer& buffer); |
170 #ifdef SK_DEVELOPER | 165 #ifdef SK_DEVELOPER |
171 virtual bool preDraw(int opIndex, int type); | 166 virtual bool preDraw(int opIndex, int type); |
172 virtual void postDraw(int opIndex); | 167 virtual void postDraw(int opIndex); |
173 #endif | 168 #endif |
174 | 169 |
175 private: | 170 private: |
176 class TextContainer { | 171 class TextContainer { |
177 public: | 172 public: |
178 size_t length() { return fByteLength; } | 173 size_t length() { return fByteLength; } |
179 const void* text() { return (const void*) fText; } | 174 const void* text() { return (const void*) fText; } |
(...skipping 10 matching lines...) Expand all Loading... |
190 return fBadBitmap; | 185 return fBadBitmap; |
191 } | 186 } |
192 return (*fBitmaps)[index]; | 187 return (*fBitmaps)[index]; |
193 } | 188 } |
194 | 189 |
195 void getMatrix(SkReader32& reader, SkMatrix* matrix) { | 190 void getMatrix(SkReader32& reader, SkMatrix* matrix) { |
196 reader.readMatrix(matrix); | 191 reader.readMatrix(matrix); |
197 } | 192 } |
198 | 193 |
199 const SkPath& getPath(SkReader32& reader) { | 194 const SkPath& getPath(SkReader32& reader) { |
200 return fPicture->getPath(reader.readInt() - 1); | 195 int index = reader.readInt() - 1; |
| 196 return (*fPathHeap.get())[index]; |
201 } | 197 } |
202 | 198 |
203 const SkPicture* getPicture(SkReader32& reader) { | 199 const SkPicture* getPicture(SkReader32& reader) { |
204 int index = reader.readInt(); | 200 int index = reader.readInt(); |
205 SkASSERT(index > 0 && index <= fPictureCount); | 201 SkASSERT(index > 0 && index <= fPictureCount); |
206 return fPictureRefs[index - 1]; | 202 return fPictureRefs[index - 1]; |
207 } | 203 } |
208 | 204 |
209 const SkPaint* getPaint(SkReader32& reader) { | 205 const SkPaint* getPaint(SkReader32& reader) { |
210 int index = reader.readInt(); | 206 int index = reader.readInt(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 266 |
271 public: | 267 public: |
272 void dump() const; | 268 void dump() const; |
273 #endif | 269 #endif |
274 | 270 |
275 #if SK_SUPPORT_GPU | 271 #if SK_SUPPORT_GPU |
276 bool suitableForGpuRasterization(GrContext* context, const char **reason) co
nst; | 272 bool suitableForGpuRasterization(GrContext* context, const char **reason) co
nst; |
277 #endif | 273 #endif |
278 | 274 |
279 private: // these help us with reading/writing | 275 private: // these help us with reading/writing |
280 bool parseStreamTag(SkPicture* picture, SkStream*, uint32_t tag, uint32_t si
ze, | 276 bool parseStreamTag(SkStream*, uint32_t tag, uint32_t size, SkPicture::Insta
llPixelRefProc); |
281 SkPicture::InstallPixelRefProc); | 277 bool parseBufferTag(SkReadBuffer&, uint32_t tag, uint32_t size); |
282 bool parseBufferTag(SkPicture* picture, SkReadBuffer&, uint32_t tag, uint32_
t size); | |
283 void flattenToBuffer(SkWriteBuffer&) const; | 278 void flattenToBuffer(SkWriteBuffer&) const; |
284 | 279 |
285 private: | 280 private: |
286 friend class SkPicture; | 281 friend class SkPicture; |
287 friend class SkGpuDevice; // for access to setDrawLimits & setReplacements | 282 friend class SkGpuDevice; // for access to setDrawLimits & setReplacements |
288 | 283 |
289 // The picture that owns this SkPicturePlayback object | |
290 const SkPicture* fPicture; | |
291 | |
292 // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_
SLOT. This empty | 284 // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_
SLOT. This empty |
293 // bitmap allows playback to draw nothing and move on. | 285 // bitmap allows playback to draw nothing and move on. |
294 SkBitmap fBadBitmap; | 286 SkBitmap fBadBitmap; |
295 | 287 |
296 SkAutoTUnref<SkBitmapHeap> fBitmapHeap; | 288 SkAutoTUnref<SkBitmapHeap> fBitmapHeap; |
297 | 289 |
298 SkTRefArray<SkBitmap>* fBitmaps; | 290 SkTRefArray<SkBitmap>* fBitmaps; |
299 SkTRefArray<SkPaint>* fPaints; | 291 SkTRefArray<SkPaint>* fPaints; |
300 | 292 |
301 SkData* fOpData; // opcodes and parameters | 293 SkData* fOpData; // opcodes and parameters |
302 | 294 |
| 295 SkAutoTUnref<const SkPathHeap> fPathHeap; // reference counted |
| 296 |
303 const SkPicture** fPictureRefs; | 297 const SkPicture** fPictureRefs; |
304 int fPictureCount; | 298 int fPictureCount; |
305 | 299 |
306 SkBBoxHierarchy* fBoundingHierarchy; | 300 SkBBoxHierarchy* fBoundingHierarchy; |
307 SkPictureStateTree* fStateTree; | 301 SkPictureStateTree* fStateTree; |
308 | 302 |
309 SkPictureContentInfo fContentInfo; | 303 SkPictureContentInfo fContentInfo; |
310 | 304 |
311 // Limit the opcode playback to be between the offsets 'start' and 'stop'. | 305 // Limit the opcode playback to be between the offsets 'start' and 'stop'. |
312 // The opcode at 'start' should be a saveLayer while the opcode at | 306 // The opcode at 'start' should be a saveLayer while the opcode at |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 SkFactoryPlayback* fFactoryPlayback; | 390 SkFactoryPlayback* fFactoryPlayback; |
397 | 391 |
398 // The offset of the current operation when within the draw method | 392 // The offset of the current operation when within the draw method |
399 size_t fCurOffset; | 393 size_t fCurOffset; |
400 | 394 |
401 const SkPictInfo fInfo; | 395 const SkPictInfo fInfo; |
402 | 396 |
403 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); | 397 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); |
404 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); | 398 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); |
405 | 399 |
| 400 void initForPlayback() const; |
| 401 |
406 #ifdef SK_BUILD_FOR_ANDROID | 402 #ifdef SK_BUILD_FOR_ANDROID |
407 SkMutex fDrawMutex; | 403 SkMutex fDrawMutex; |
408 bool fAbortCurrentPlayback; | 404 bool fAbortCurrentPlayback; |
409 #endif | 405 #endif |
410 }; | 406 }; |
411 | 407 |
412 #endif | 408 #endif |
OLD | NEW |