Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: include/core/SkPicture.h

Issue 17113004: Replace SkPicture(SkStream) constructors with a factory. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Remove dead function declaration. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #define SkPicture_DEFINED 11 #define SkPicture_DEFINED
12 12
13 #include "SkBitmap.h" 13 #include "SkBitmap.h"
14 #include "SkImageDecoder.h"
14 #include "SkRefCnt.h" 15 #include "SkRefCnt.h"
15 16
16 class SkBBoxHierarchy; 17 class SkBBoxHierarchy;
17 class SkCanvas; 18 class SkCanvas;
18 class SkDrawPictureCallback; 19 class SkDrawPictureCallback;
19 class SkData; 20 class SkData;
20 class SkPicturePlayback; 21 class SkPicturePlayback;
21 class SkPictureRecord; 22 class SkPictureRecord;
22 class SkStream; 23 class SkStream;
23 class SkWStream; 24 class SkWStream;
24 25
26 struct SkPictInfo;
27
25 /** \class SkPicture 28 /** \class SkPicture
26 29
27 The SkPicture class records the drawing commands made to a canvas, to 30 The SkPicture class records the drawing commands made to a canvas, to
28 be played back at a later time. 31 be played back at a later time.
29 */ 32 */
30 class SK_API SkPicture : public SkRefCnt { 33 class SK_API SkPicture : public SkRefCnt {
31 public: 34 public:
32 SK_DECLARE_INST_COUNT(SkPicture) 35 SK_DECLARE_INST_COUNT(SkPicture)
33 36
34 /** The constructor prepares the picture to record. 37 /** The constructor prepares the picture to record.
35 @param width the width of the virtual device the picture records. 38 @param width the width of the virtual device the picture records.
36 @param height the height of the virtual device the picture records. 39 @param height the height of the virtual device the picture records.
37 */ 40 */
38 SkPicture(); 41 SkPicture();
39 /** Make a copy of the contents of src. If src records more drawing after 42 /** Make a copy of the contents of src. If src records more drawing after
40 this call, those elements will not appear in this picture. 43 this call, those elements will not appear in this picture.
41 */ 44 */
42 SkPicture(const SkPicture& src); 45 SkPicture(const SkPicture& src);
43 46
44 /** 47 /**
45 * Recreate a picture that was serialized into a stream.
46 * On failure, silently creates an empty picture.
47 * @param SkStream Serialized picture data.
48 */
49 explicit SkPicture(SkStream*);
50
51 /**
52 * Function signature defining a function that sets up an SkBitmap from enc oded data. On 48 * Function signature defining a function that sets up an SkBitmap from enc oded data. On
53 * success, the SkBitmap should have its Config, width, height, rowBytes an d pixelref set. 49 * success, the SkBitmap should have its Config, width, height, rowBytes an d pixelref set.
54 * If the installed pixelref has decoded the data into pixels, then the src buffer need not be 50 * If the installed pixelref has decoded the data into pixels, then the src buffer need not be
55 * copied. If the pixelref defers the actual decode until its lockPixels() is called, then it 51 * copied. If the pixelref defers the actual decode until its lockPixels() is called, then it
56 * must make a copy of the src buffer. 52 * must make a copy of the src buffer.
57 * @param src Encoded data. 53 * @param src Encoded data.
58 * @param length Size of the encoded data, in bytes. 54 * @param length Size of the encoded data, in bytes.
59 * @param dst SkBitmap to install the pixel ref on. 55 * @param dst SkBitmap to install the pixel ref on.
60 * @param bool Whether or not a pixel ref was successfully installed. 56 * @param bool Whether or not a pixel ref was successfully installed.
61 */ 57 */
62 typedef bool (*InstallPixelRefProc)(const void* src, size_t length, SkBitmap * dst); 58 typedef bool (*InstallPixelRefProc)(const void* src, size_t length, SkBitmap * dst);
63 59
64 /** 60 /**
65 * Recreate a picture that was serialized into a stream. 61 * Recreate a picture that was serialized into a stream.
66 * @param SkStream Serialized picture data. 62 * @param SkStream Serialized picture data.
67 * @param success Output parameter. If non-NULL, will be set to true if the picture was
68 * deserialized successfully and false otherwise.
69 * @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
70 * 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
66 * invalid.
71 */ 67 */
72 SkPicture(SkStream*, bool* success, InstallPixelRefProc proc); 68 static SkPicture* CreateFromStream(SkStream*,
69 InstallPixelRefProc proc = &SkImageDecode r::DecodeMemory);
73 70
74 virtual ~SkPicture(); 71 virtual ~SkPicture();
75 72
76 /** 73 /**
77 * Swap the contents of the two pictures. Guaranteed to succeed. 74 * Swap the contents of the two pictures. Guaranteed to succeed.
78 */ 75 */
79 void swap(SkPicture& other); 76 void swap(SkPicture& other);
80 77
81 /** 78 /**
82 * 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.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // install their own SkPicturePlayback-derived players,SkPictureRecord-deriv ed 214 // install their own SkPicturePlayback-derived players,SkPictureRecord-deriv ed
218 // recorders and set the picture size 215 // recorders and set the picture size
219 SkPicturePlayback* fPlayback; 216 SkPicturePlayback* fPlayback;
220 SkPictureRecord* fRecord; 217 SkPictureRecord* fRecord;
221 int fWidth, fHeight; 218 int fWidth, fHeight;
222 219
223 // For testing. Derived classes may instantiate an alternate 220 // For testing. Derived classes may instantiate an alternate
224 // SkBBoxHierarchy implementation 221 // SkBBoxHierarchy implementation
225 virtual SkBBoxHierarchy* createBBoxHierarchy() const; 222 virtual SkBBoxHierarchy* createBBoxHierarchy() const;
226 223
224 // Return true if the SkStream represents a serialized picture, and fills ou t
225 // SkPictInfo. After this function returns, the SkStream is not rewound; it
226 // will be ready to be parsed to create an SkPicturePlayback.
227 // If false is returned, SkPictInfo is still modified.
228 static bool StreamIsSKP(SkStream*, SkPictInfo*);
227 private: 229 private:
228 void initFromStream(SkStream*, bool* success, InstallPixelRefProc);
229
230 friend class SkFlatPicture; 230 friend class SkFlatPicture;
231 friend class SkPicturePlayback; 231 friend class SkPicturePlayback;
232 232
233 typedef SkRefCnt INHERITED; 233 typedef SkRefCnt INHERITED;
234 }; 234 };
235 235
236 class SkAutoPictureRecord : SkNoncopyable { 236 class SkAutoPictureRecord : SkNoncopyable {
237 public: 237 public:
238 SkAutoPictureRecord(SkPicture* pict, int width, int height, 238 SkAutoPictureRecord(SkPicture* pict, int width, int height,
239 uint32_t recordingFlags = 0) { 239 uint32_t recordingFlags = 0) {
(...skipping 25 matching lines...) Expand all
265 */ 265 */
266 class SK_API SkDrawPictureCallback { 266 class SK_API SkDrawPictureCallback {
267 public: 267 public:
268 SkDrawPictureCallback() {} 268 SkDrawPictureCallback() {}
269 virtual ~SkDrawPictureCallback() {} 269 virtual ~SkDrawPictureCallback() {}
270 270
271 virtual bool abortDrawing() = 0; 271 virtual bool abortDrawing() = 0;
272 }; 272 };
273 273
274 #endif 274 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698