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

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 a change in behavior Created 7 years, 5 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
« no previous file with comments | « gyp/utils.gyp ('k') | samplecode/SampleApp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 // V12: add conics to SkPath, use new SkPathRef flattening 210 // V12: add conics to SkPath, use new SkPathRef flattening
214 static const uint32_t PICTURE_VERSION = 12; 211 static const uint32_t PICTURE_VERSION = 12;
215 212
216 // fPlayback, fRecord, fWidth & fHeight are protected to allow derived class es to 213 // fPlayback, fRecord, fWidth & fHeight are protected to allow derived class es to
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
220 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of
221 // playback is unchanged.
222 SkPicture(SkPicturePlayback*, int width, int height);
223
223 // For testing. Derived classes may instantiate an alternate 224 // For testing. Derived classes may instantiate an alternate
224 // SkBBoxHierarchy implementation 225 // SkBBoxHierarchy implementation
225 virtual SkBBoxHierarchy* createBBoxHierarchy() const; 226 virtual SkBBoxHierarchy* createBBoxHierarchy() const;
226 227
228 // Return true if the SkStream represents a serialized picture, and fills ou t
229 // SkPictInfo. After this function returns, the SkStream is not rewound; it
230 // will be ready to be parsed to create an SkPicturePlayback.
231 // If false is returned, SkPictInfo is unmodified.
232 static bool StreamIsSKP(SkStream*, SkPictInfo*);
227 private: 233 private:
228 void initFromStream(SkStream*, bool* success, InstallPixelRefProc);
229
230 friend class SkFlatPicture; 234 friend class SkFlatPicture;
231 friend class SkPicturePlayback; 235 friend class SkPicturePlayback;
232 236
233 typedef SkRefCnt INHERITED; 237 typedef SkRefCnt INHERITED;
234 }; 238 };
235 239
236 class SkAutoPictureRecord : SkNoncopyable { 240 class SkAutoPictureRecord : SkNoncopyable {
237 public: 241 public:
238 SkAutoPictureRecord(SkPicture* pict, int width, int height, 242 SkAutoPictureRecord(SkPicture* pict, int width, int height,
239 uint32_t recordingFlags = 0) { 243 uint32_t recordingFlags = 0) {
(...skipping 25 matching lines...) Expand all
265 */ 269 */
266 class SK_API SkDrawPictureCallback { 270 class SK_API SkDrawPictureCallback {
267 public: 271 public:
268 SkDrawPictureCallback() {} 272 SkDrawPictureCallback() {}
269 virtual ~SkDrawPictureCallback() {} 273 virtual ~SkDrawPictureCallback() {}
270 274
271 virtual bool abortDrawing() = 0; 275 virtual bool abortDrawing() = 0;
272 }; 276 };
273 277
274 #endif 278 #endif
OLDNEW
« no previous file with comments | « gyp/utils.gyp ('k') | samplecode/SampleApp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698