| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
| 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 | 9 |
| 10 #ifndef SkPicture_DEFINED | 10 #ifndef SkPicture_DEFINED |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 * Recreate a picture that was serialized into a stream. | 61 * Recreate a picture that was serialized into a stream. |
| 62 * @param SkStream Serialized picture data. | 62 * @param SkStream Serialized picture data. |
| 63 * @param proc Function pointer for installing pixelrefs on SkBitmaps repre
senting the | 63 * @param proc Function pointer for installing pixelrefs on SkBitmaps repre
senting the |
| 64 * encoded bitmap data from the stream. | 64 * encoded bitmap data from the stream. |
| 65 * @return A new SkPicture representing the serialized data, or NULL if the
stream is | 65 * @return A new SkPicture representing the serialized data, or NULL if the
stream is |
| 66 * invalid. | 66 * invalid. |
| 67 */ | 67 */ |
| 68 static SkPicture* CreateFromStream(SkStream*, | 68 static SkPicture* CreateFromStream(SkStream*, |
| 69 InstallPixelRefProc proc = &SkImageDecode
r::DecodeMemory); | 69 InstallPixelRefProc proc = &SkImageDecode
r::DecodeMemory); |
| 70 | 70 |
| 71 /** | |
| 72 * Recreate a picture that was serialized into a buffer. If the creation re
quires bitmap | |
| 73 * decoding, the decoder must be set on the SkReadBuffer parameter by calli
ng | |
| 74 * SkReadBuffer::setBitmapDecoder() before calling SkPicture::CreateFromBuf
fer(). | |
| 75 * @param SkReadBuffer Serialized picture data. | |
| 76 * @return A new SkPicture representing the serialized data, or NULL if the
buffer is | |
| 77 * invalid. | |
| 78 */ | |
| 79 static SkPicture* CreateFromBuffer(SkReadBuffer&); | |
| 80 | |
| 81 virtual ~SkPicture(); | 71 virtual ~SkPicture(); |
| 82 | 72 |
| 83 /** | 73 /** |
| 84 * Swap the contents of the two pictures. Guaranteed to succeed. | 74 * Swap the contents of the two pictures. Guaranteed to succeed. |
| 85 */ | 75 */ |
| 86 void swap(SkPicture& other); | 76 void swap(SkPicture& other); |
| 87 | 77 |
| 88 /** | 78 /** |
| 89 * Creates a thread-safe clone of the picture that is ready for playback. | 79 * Creates a thread-safe clone of the picture that is ready for playback. |
| 90 */ | 80 */ |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm); | 180 typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm); |
| 191 | 181 |
| 192 /** | 182 /** |
| 193 * Serialize to a stream. If non NULL, encoder will be used to encode | 183 * Serialize to a stream. If non NULL, encoder will be used to encode |
| 194 * any bitmaps in the picture. | 184 * any bitmaps in the picture. |
| 195 * encoder will never be called with a NULL pixelRefOffset. | 185 * encoder will never be called with a NULL pixelRefOffset. |
| 196 */ | 186 */ |
| 197 void serialize(SkWStream*, EncodeBitmap encoder = NULL) const; | 187 void serialize(SkWStream*, EncodeBitmap encoder = NULL) const; |
| 198 | 188 |
| 199 /** | 189 /** |
| 200 * Serialize to a buffer. | |
| 201 */ | |
| 202 void flatten(SkWriteBuffer&) const; | |
| 203 | |
| 204 /** | |
| 205 * Returns true if any bitmaps may be produced when this SkPicture | 190 * Returns true if any bitmaps may be produced when this SkPicture |
| 206 * is replayed. | 191 * is replayed. |
| 207 * Returns false if called while still recording. | 192 * Returns false if called while still recording. |
| 208 */ | 193 */ |
| 209 bool willPlayBackBitmaps() const; | 194 bool willPlayBackBitmaps() const; |
| 210 | 195 |
| 211 #ifdef SK_BUILD_FOR_ANDROID | 196 #ifdef SK_BUILD_FOR_ANDROID |
| 212 /** Signals that the caller is prematurely done replaying the drawing | 197 /** Signals that the caller is prematurely done replaying the drawing |
| 213 commands. This can be called from a canvas virtual while the picture | 198 commands. This can be called from a canvas virtual while the picture |
| 214 is drawing. Has no effect if the picture is not drawing. | 199 is drawing. Has no effect if the picture is not drawing. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 231 // V11: modify how readBitmap and writeBitmap store their info. | 216 // V11: modify how readBitmap and writeBitmap store their info. |
| 232 // V12: add conics to SkPath, use new SkPathRef flattening | 217 // V12: add conics to SkPath, use new SkPathRef flattening |
| 233 // V13: add flag to drawBitmapRectToRect | 218 // V13: add flag to drawBitmapRectToRect |
| 234 // parameterize blurs by sigma rather than radius | 219 // parameterize blurs by sigma rather than radius |
| 235 // V14: Add flags word to PathRef serialization | 220 // V14: Add flags word to PathRef serialization |
| 236 // V15: Remove A1 bitmpa config (and renumber remaining configs) | 221 // V15: Remove A1 bitmpa config (and renumber remaining configs) |
| 237 // V16: Move SkPath's isOval flag to SkPathRef | 222 // V16: Move SkPath's isOval flag to SkPathRef |
| 238 // V17: SkPixelRef now writes SkImageInfo | 223 // V17: SkPixelRef now writes SkImageInfo |
| 239 // V18: SkBitmap now records x,y for its pixelref origin, instead of offset. | 224 // V18: SkBitmap now records x,y for its pixelref origin, instead of offset. |
| 240 // V19: encode matrices and regions into the ops stream | 225 // V19: encode matrices and regions into the ops stream |
| 241 // V20: added bool to SkPictureImageFilter's serialization (to allow SkPictu
re serialization) | 226 static const uint32_t PICTURE_VERSION = 19; |
| 242 static const uint32_t PICTURE_VERSION = 20; | |
| 243 | 227 |
| 244 // fPlayback, fRecord, fWidth & fHeight are protected to allow derived class
es to | 228 // fPlayback, fRecord, fWidth & fHeight are protected to allow derived class
es to |
| 245 // install their own SkPicturePlayback-derived players,SkPictureRecord-deriv
ed | 229 // install their own SkPicturePlayback-derived players,SkPictureRecord-deriv
ed |
| 246 // recorders and set the picture size | 230 // recorders and set the picture size |
| 247 SkPicturePlayback* fPlayback; | 231 SkPicturePlayback* fPlayback; |
| 248 SkPictureRecord* fRecord; | 232 SkPictureRecord* fRecord; |
| 249 int fWidth, fHeight; | 233 int fWidth, fHeight; |
| 250 | 234 |
| 251 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of | 235 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of |
| 252 // playback is unchanged. | 236 // playback is unchanged. |
| 253 SkPicture(SkPicturePlayback*, int width, int height); | 237 SkPicture(SkPicturePlayback*, int width, int height); |
| 254 | 238 |
| 255 // For testing. Derived classes may instantiate an alternate | 239 // For testing. Derived classes may instantiate an alternate |
| 256 // SkBBoxHierarchy implementation | 240 // SkBBoxHierarchy implementation |
| 257 virtual SkBBoxHierarchy* createBBoxHierarchy() const; | 241 virtual SkBBoxHierarchy* createBBoxHierarchy() const; |
| 258 | 242 |
| 259 // Return true if the SkStream represents a serialized picture, and fills ou
t | 243 // Return true if the SkStream represents a serialized picture, and fills ou
t |
| 260 // SkPictInfo. After this function returns, the SkStream is not rewound; it | 244 // SkPictInfo. After this function returns, the SkStream is not rewound; it |
| 261 // will be ready to be parsed to create an SkPicturePlayback. | 245 // will be ready to be parsed to create an SkPicturePlayback. |
| 262 // If false is returned, SkPictInfo is unmodified. | 246 // If false is returned, SkPictInfo is unmodified. |
| 263 static bool StreamIsSKP(SkStream*, SkPictInfo*); | 247 static bool StreamIsSKP(SkStream*, SkPictInfo*); |
| 264 static bool BufferIsSKP(SkReadBuffer&, SkPictInfo*); | |
| 265 private: | 248 private: |
| 266 void createHeader(void* header) const; | |
| 267 | |
| 268 friend class SkFlatPicture; | 249 friend class SkFlatPicture; |
| 269 friend class SkPicturePlayback; | 250 friend class SkPicturePlayback; |
| 270 | 251 |
| 271 typedef SkRefCnt INHERITED; | 252 typedef SkRefCnt INHERITED; |
| 272 }; | 253 }; |
| 273 | 254 |
| 274 /** | 255 /** |
| 275 * Subclasses of this can be passed to canvas.drawPicture. During the drawing | 256 * Subclasses of this can be passed to canvas.drawPicture. During the drawing |
| 276 * of the picture, this callback will periodically be invoked. If its | 257 * of the picture, this callback will periodically be invoked. If its |
| 277 * abortDrawing() returns true, then picture playback will be interrupted. | 258 * abortDrawing() returns true, then picture playback will be interrupted. |
| 278 * | 259 * |
| 279 * The resulting drawing is undefined, as there is no guarantee how often the | 260 * The resulting drawing is undefined, as there is no guarantee how often the |
| 280 * callback will be invoked. If the abort happens inside some level of nested | 261 * callback will be invoked. If the abort happens inside some level of nested |
| 281 * calls to save(), restore will automatically be called to return the state | 262 * calls to save(), restore will automatically be called to return the state |
| 282 * to the same level it was before the drawPicture call was made. | 263 * to the same level it was before the drawPicture call was made. |
| 283 */ | 264 */ |
| 284 class SK_API SkDrawPictureCallback { | 265 class SK_API SkDrawPictureCallback { |
| 285 public: | 266 public: |
| 286 SkDrawPictureCallback() {} | 267 SkDrawPictureCallback() {} |
| 287 virtual ~SkDrawPictureCallback() {} | 268 virtual ~SkDrawPictureCallback() {} |
| 288 | 269 |
| 289 virtual bool abortDrawing() = 0; | 270 virtual bool abortDrawing() = 0; |
| 290 }; | 271 }; |
| 291 | 272 |
| 292 #endif | 273 #endif |
| OLD | NEW |