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

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

Issue 1130283004: Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « gyp/utils.gypi ('k') | include/core/SkPictureRecorder.h » ('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 * Copyright 2007 The Android Open Source Project 2 * Copyright 2007 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8
8 #ifndef SkPicture_DEFINED 9 #ifndef SkPicture_DEFINED
9 #define SkPicture_DEFINED 10 #define SkPicture_DEFINED
10 11
11 #include "SkImageDecoder.h" 12 #include "SkImageDecoder.h"
12 #include "SkLazyPtr.h" 13 #include "SkLazyPtr.h"
13 #include "SkRefCnt.h" 14 #include "SkRefCnt.h"
14 #include "SkTypes.h" 15 #include "SkTDArray.h"
15 16
17 #if SK_SUPPORT_GPU
16 class GrContext; 18 class GrContext;
17 class SkBigPicture; 19 #endif
20
18 class SkBitmap; 21 class SkBitmap;
22 class SkBBoxHierarchy;
19 class SkCanvas; 23 class SkCanvas;
24 class SkData;
20 class SkPictureData; 25 class SkPictureData;
21 class SkPixelSerializer; 26 class SkPixelSerializer;
22 class SkStream; 27 class SkStream;
23 class SkWStream; 28 class SkWStream;
29
24 struct SkPictInfo; 30 struct SkPictInfo;
25 31
32 class SkRecord;
33
34 namespace SkRecords {
35 class CollectLayers;
36 };
37
26 /** \class SkPicture 38 /** \class SkPicture
27 39
28 An SkPicture records drawing commands made to a canvas to be played back at a later time. 40 The SkPicture class records the drawing commands made to a canvas, to
29 This base class handles serialization and a few other miscellany. 41 be played back at a later time.
30 */ 42 */
31 class SK_API SkPicture : public SkRefCnt { 43 class SK_API SkPicture : public SkNVRefCnt<SkPicture> {
32 public: 44 public:
33 virtual ~SkPicture(); 45 // AccelData provides a base class for device-specific acceleration data.
46 class AccelData : public SkRefCnt {
47 public:
48 typedef uint8_t Domain;
49 typedef uint32_t Key;
50
51 AccelData(Key key) : fKey(key) { }
52
53 const Key& getKey() const { return fKey; }
54
55 // This entry point allows user's to get a unique domain prefix
56 // for their keys
57 static Domain GenerateDomain();
58 private:
59 Key fKey;
60 };
61
62 /** PRIVATE / EXPERIMENTAL -- do not call */
63 const AccelData* EXPERIMENTAL_getAccelData(AccelData::Key) const;
34 64
35 /** 65 /**
36 * Function signature defining a function that sets up an SkBitmap from enc oded data. On 66 * Function signature defining a function that sets up an SkBitmap from enc oded data. On
37 * success, the SkBitmap should have its Config, width, height, rowBytes an d pixelref set. 67 * success, the SkBitmap should have its Config, width, height, rowBytes an d pixelref set.
38 * If the installed pixelref has decoded the data into pixels, then the src buffer need not be 68 * If the installed pixelref has decoded the data into pixels, then the src buffer need not be
39 * copied. If the pixelref defers the actual decode until its lockPixels() is called, then it 69 * copied. If the pixelref defers the actual decode until its lockPixels() is called, then it
40 * must make a copy of the src buffer. 70 * must make a copy of the src buffer.
41 * @param src Encoded data. 71 * @param src Encoded data.
42 * @param length Size of the encoded data, in bytes. 72 * @param length Size of the encoded data, in bytes.
43 * @param dst SkBitmap to install the pixel ref on. 73 * @param dst SkBitmap to install the pixel ref on.
(...skipping 15 matching lines...) Expand all
59 /** 89 /**
60 * Recreate a picture that was serialized into a buffer. If the creation re quires bitmap 90 * Recreate a picture that was serialized into a buffer. If the creation re quires bitmap
61 * decoding, the decoder must be set on the SkReadBuffer parameter by calli ng 91 * decoding, the decoder must be set on the SkReadBuffer parameter by calli ng
62 * SkReadBuffer::setBitmapDecoder() before calling SkPicture::CreateFromBuf fer(). 92 * SkReadBuffer::setBitmapDecoder() before calling SkPicture::CreateFromBuf fer().
63 * @param SkReadBuffer Serialized picture data. 93 * @param SkReadBuffer Serialized picture data.
64 * @return A new SkPicture representing the serialized data, or NULL if the buffer is 94 * @return A new SkPicture representing the serialized data, or NULL if the buffer is
65 * invalid. 95 * invalid.
66 */ 96 */
67 static SkPicture* CreateFromBuffer(SkReadBuffer&); 97 static SkPicture* CreateFromBuffer(SkReadBuffer&);
68 98
99 ~SkPicture();
100
69 /** 101 /**
70 * Subclasses of this can be passed to playback(). During the playback 102 * Subclasses of this can be passed to playback(). During the playback
71 * of the picture, this callback will periodically be invoked. If its 103 * of the picture, this callback will periodically be invoked. If its
72 * abort() returns true, then picture playback will be interrupted. 104 * abort() returns true, then picture playback will be interrupted.
73 * 105 *
74 * The resulting drawing is undefined, as there is no guarantee how often th e 106 * The resulting drawing is undefined, as there is no guarantee how often th e
75 * callback will be invoked. If the abort happens inside some level of neste d 107 * callback will be invoked. If the abort happens inside some level of neste d
76 * calls to save(), restore will automatically be called to return the state 108 * calls to save(), restore will automatically be called to return the state
77 * to the same level it was before the playback call was made. 109 * to the same level it was before the playback call was made.
78 */ 110 */
79 class SK_API AbortCallback { 111 class SK_API AbortCallback {
80 public: 112 public:
81 AbortCallback() {} 113 AbortCallback() {}
82 virtual ~AbortCallback() {} 114 virtual ~AbortCallback() {}
115
83 virtual bool abort() = 0; 116 virtual bool abort() = 0;
84 }; 117 };
85 118
86 /** Replays the drawing commands on the specified canvas. Note that 119 /** Replays the drawing commands on the specified canvas. Note that
87 this has the effect of unfurling this picture into the destination 120 this has the effect of unfurling this picture into the destination
88 canvas. Using the SkCanvas::drawPicture entry point gives the destinatio n 121 canvas. Using the SkCanvas::drawPicture entry point gives the destinatio n
89 canvas the option of just taking a ref. 122 canvas the option of just taking a ref.
90 @param canvas the canvas receiving the drawing commands. 123 @param canvas the canvas receiving the drawing commands.
91 @param callback a callback that allows interruption of playback 124 @param callback a callback that allows interruption of playback
92 */ 125 */
93 virtual void playback(SkCanvas*, AbortCallback* = NULL) const = 0; 126 void playback(SkCanvas* canvas, AbortCallback* = NULL) const;
94 127
95 /** Return a cull rect for this picture. 128 /** Return the cull rect used when creating this picture: { 0, 0, cullWidth, cullHeight }.
96 Ops recorded into this picture that attempt to draw outside the cull mig ht not be drawn. 129 It does not necessarily reflect the bounds of what has been recorded int o the picture.
130 @return the cull rect used to create this picture
131 */
132 SkRect cullRect() const { return fCullRect; }
133
134 /** Return a non-zero, unique value representing the picture.
97 */ 135 */
98 virtual SkRect cullRect() const = 0;
99
100 /** Returns a non-zero value unique among all pictures. */
101 uint32_t uniqueID() const; 136 uint32_t uniqueID() const;
102 137
103 /** 138 /**
104 * Serialize to a stream. If non NULL, serializer will be used to serialize 139 * Serialize to a stream. If non NULL, serializer will be used to serialize
105 * any bitmaps in the picture. 140 * any bitmaps in the picture.
106 * 141 *
107 * TODO: Use serializer to serialize SkImages as well. 142 * TODO: Use serializer to serialize SkImages as well.
108 */ 143 */
109 void serialize(SkWStream*, SkPixelSerializer* = NULL) const; 144 void serialize(SkWStream*, SkPixelSerializer* serializer = NULL) const;
110 145
111 /** 146 /**
112 * Serialize to a buffer. 147 * Serialize to a buffer.
113 */ 148 */
114 void flatten(SkWriteBuffer&) const; 149 void flatten(SkWriteBuffer&) const;
115 150
116 /** 151 /**
117 * Returns true if any bitmaps may be produced when this SkPicture 152 * Returns true if any bitmaps may be produced when this SkPicture
118 * is replayed. 153 * is replayed.
119 */ 154 */
120 virtual bool willPlayBackBitmaps() const = 0; 155 bool willPlayBackBitmaps() const;
121
122 /** Return the approximate number of operations in this picture. This
123 * number may be greater or less than the number of SkCanvas calls
124 * recorded: some calls may be recorded as more than one operation, or some
125 * calls may be optimized away.
126 */
127 virtual int approximateOpCount() const = 0;
128
129 /** Return true if this picture contains text.
130 */
131 virtual bool hasText() const = 0;
132
133 /** Returns the approximate byte size of this picture, not including large r ef'd objects. */
134 virtual size_t approximateBytesUsed() const = 0;
135 156
136 /** Return true if the SkStream/Buffer represents a serialized picture, and 157 /** Return true if the SkStream/Buffer represents a serialized picture, and
137 fills out SkPictInfo. After this function returns, the data source is no t 158 fills out SkPictInfo. After this function returns, the data source is no t
138 rewound so it will have to be manually reset before passing to 159 rewound so it will have to be manually reset before passing to
139 CreateFromStream or CreateFromBuffer. Note, CreateFromStream and 160 CreateFromStream or CreateFromBuffer. Note, CreateFromStream and
140 CreateFromBuffer perform this check internally so these entry points are 161 CreateFromBuffer perform this check internally so these entry points are
141 intended for stand alone tools. 162 intended for stand alone tools.
142 If false is returned, SkPictInfo is unmodified. 163 If false is returned, SkPictInfo is unmodified.
143 */ 164 */
144 static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*); 165 static bool InternalOnly_StreamIsSKP(SkStream*, SkPictInfo*);
145 static bool InternalOnly_BufferIsSKP(SkReadBuffer*, SkPictInfo*); 166 static bool InternalOnly_BufferIsSKP(SkReadBuffer*, SkPictInfo*);
146 167
147 /** Return true if the picture is suitable for rendering on the GPU. */ 168 /** Return true if the picture is suitable for rendering on the GPU.
148 bool suitableForGpuRasterization(GrContext*, const char** whyNot = NULL) con st; 169 */
170
171 #if SK_SUPPORT_GPU
172 bool suitableForGpuRasterization(GrContext*, const char ** = NULL) const;
173 #endif
174
175 /** Return the approximate number of operations in this picture. This
176 * number may be greater or less than the number of SkCanvas calls
177 * recorded: some calls may be recorded as more than one operation, or some
178 * calls may be optimized away.
179 */
180 int approximateOpCount() const;
181
182 /** Return true if this picture contains text.
183 */
184 bool hasText() const;
185
186 // An array of refcounted const SkPicture pointers.
187 class SnapshotArray : ::SkNoncopyable {
188 public:
189 SnapshotArray(const SkPicture* pics[], int count) : fPics(pics), fCount( count) {}
190 ~SnapshotArray() { for (int i = 0; i < fCount; i++) { fPics[i]->unref(); } }
191
192 const SkPicture* const* begin() const { return fPics; }
193 int count() const { return fCount; }
194 private:
195 SkAutoTMalloc<const SkPicture*> fPics;
196 int fCount;
197 };
149 198
150 // Sent via SkMessageBus from destructor. 199 // Sent via SkMessageBus from destructor.
151 struct DeletionMessage { int32_t fUniqueID; }; // TODO: -> uint32_t? 200 struct DeletionMessage { int32_t fUniqueID; };
152
153 // Returns NULL if this is not an SkBigPicture.
154 virtual const SkBigPicture* asSkBigPicture() const { return NULL; }
155 201
156 private: 202 private:
157 // Subclass whitelist. 203 // V2 : adds SkPixelRef's generation ID.
158 SkPicture(); 204 // V3 : PictInfo tag at beginning, and EOF tag at the end
159 friend class SkBigPicture; 205 // V4 : move SkPictInfo to be the header
160 friend class SkEmptyPicture; 206 // V5 : don't read/write FunctionPtr on cross-process (we can detect that)
161 template <typename> friend class SkMiniPicture; 207 // V6 : added serialization of SkPath's bounds (and packed its flags tighter )
162 208 // V7 : changed drawBitmapRect(IRect) to drawBitmapRectToRect(Rect)
163 virtual int numSlowPaths() const = 0; 209 // V8 : Add an option for encoding bitmaps
164 friend struct SkPathCounter; 210 // V9 : Allow the reader and writer of an SKP disagree on whether to support
165 211 // SK_SUPPORT_HINTING_SCALE_FACTOR
212 // V10: add drawRRect, drawOval, clipRRect
213 // V11: modify how readBitmap and writeBitmap store their info.
214 // V12: add conics to SkPath, use new SkPathRef flattening
215 // V13: add flag to drawBitmapRectToRect
216 // parameterize blurs by sigma rather than radius
217 // V14: Add flags word to PathRef serialization
218 // V15: Remove A1 bitmap config (and renumber remaining configs)
219 // V16: Move SkPath's isOval flag to SkPathRef
220 // V17: SkPixelRef now writes SkImageInfo
221 // V18: SkBitmap now records x,y for its pixelref origin, instead of offset.
222 // V19: encode matrices and regions into the ops stream
223 // V20: added bool to SkPictureImageFilter's serialization (to allow SkPictu re serialization)
224 // V21: add pushCull, popCull
225 // V22: SK_PICT_FACTORY_TAG's size is now the chunk size in bytes
226 // V23: SkPaint::FilterLevel became a real enum
227 // V24: SkTwoPointConicalGradient now has fFlipped flag for gradient flippin g
228 // V25: SkDashPathEffect now only writes phase and interval array when flatt ening
229 // V26: Removed boolean from SkColorShader for inheriting color from SkPaint .
230 // V27: Remove SkUnitMapper from gradients (and skia).
231 // V28: No longer call bitmap::flatten inside SkWriteBuffer::writeBitmap.
232 // V29: Removed SaveFlags parameter from save().
233 // V30: Remove redundant SkMatrix from SkLocalMatrixShader.
234 // V31: Add a serialized UniqueID to SkImageFilter.
235 // V32: Removed SkPaintOptionsAndroid from SkPaint
236 // V33: Serialize only public API of effects.
237 // V34: Add SkTextBlob serialization.
166 // V35: Store SkRect (rather then width & height) in header 238 // V35: Store SkRect (rather then width & height) in header
167 // V36: Remove (obsolete) alphatype from SkColorTable 239 // V36: Remove (obsolete) alphatype from SkColorTable
168 // V37: Added shadow only option to SkDropShadowImageFilter (last version to record CLEAR) 240 // V37: Added shadow only option to SkDropShadowImageFilter (last version to record CLEAR)
169 // V38: Added PictureResolution option to SkPictureImageFilter 241 // V38: Added PictureResolution option to SkPictureImageFilter
170 // V39: Added FilterLevel option to SkPictureImageFilter 242 // V39: Added FilterLevel option to SkPictureImageFilter
171 // V40: Remove UniqueID serialization from SkImageFilter. 243 // V40: Remove UniqueID serialization from SkImageFilter.
172 // V41: Added serialization of SkBitmapSource's filterQuality parameter 244 // V41: Added serialization of SkBitmapSource's filterQuality parameter
173 245
246 // Note: If the picture version needs to be increased then please follow the
247 // steps to generate new SKPs in (only accessible to Googlers): http://goo.g l/qATVcw
248
174 // Only SKPs within the min/current picture version range (inclusive) can be read. 249 // Only SKPs within the min/current picture version range (inclusive) can be read.
175 static const uint32_t MIN_PICTURE_VERSION = 35, // Produced by Chrome M3 9. 250 static const uint32_t MIN_PICTURE_VERSION = 35; // Produced by Chrome M3 9.
176 CURRENT_PICTURE_VERSION = 41; 251 static const uint32_t CURRENT_PICTURE_VERSION = 41;
177 252
178 static_assert(MIN_PICTURE_VERSION <= 41, 253 static_assert(MIN_PICTURE_VERSION <= 41,
179 "Remove kFontFileName and related code from SkFontDescriptor.c pp."); 254 "Remove kFontFileName and related code from SkFontDescriptor.c pp.");
180 255
256 void createHeader(SkPictInfo* info) const;
181 static bool IsValidPictInfo(const SkPictInfo& info); 257 static bool IsValidPictInfo(const SkPictInfo& info);
258
259 // Takes ownership of the (optional) SnapshotArray.
260 // For performance, we take ownership of the caller's refs on the SkRecord, BBH, and AccelData.
261 SkPicture(const SkRect& cullRect,
262 SkRecord*,
263 SnapshotArray*,
264 SkBBoxHierarchy*,
265 AccelData*,
266 size_t approxBytesUsedBySubPictures);
267
182 static SkPicture* Forwardport(const SkPictInfo&, const SkPictureData*); 268 static SkPicture* Forwardport(const SkPictInfo&, const SkPictureData*);
269 static SkPictureData* Backport(const SkRecord&, const SkPictInfo&,
270 SkPicture const* const drawablePics[], int dr awableCount);
183 271
184 SkPictInfo createHeader() const; 272 // uint32_t fRefCnt; from SkNVRefCnt<SkPicture>
185 SkPictureData* backport() const; 273 mutable uint32_t fUniqueID;
274 const SkRect fCullRect;
275 SkAutoTUnref<const SkRecord> fRecord;
276 SkAutoTDelete<const SnapshotArray> fDrawablePicts;
277 SkAutoTUnref<const SkBBoxHierarchy> fBBH;
278 SkAutoTUnref<const AccelData> fAccelData;
279 const size_t fApproxBytesUsedBySubPictures;
186 280
187 mutable uint32_t fUniqueID; 281 // helpers for fDrawablePicts
282 int drawableCount() const;
283 // will return NULL if drawableCount() returns 0
284 SkPicture const* const* drawablePicts() const;
285
286 struct PathCounter;
287
288 struct Analysis {
289 Analysis() {} // Only used by SkPictureData codepath.
290 explicit Analysis(const SkRecord&);
291
292 bool suitableForGpuRasterization(const char** reason, int sampleCount) c onst;
293
294 uint8_t fNumSlowPathsAndDashEffects;
295 bool fWillPlaybackBitmaps : 1;
296 bool fHasText : 1;
297 };
298 SkLazyPtr<Analysis> fAnalysis;
299 const Analysis& analysis() const;
300
301 friend class SkPictureRecorder; // SkRecord-based constructor.
302 friend class GrLayerHoister; // access to fRecord
303 friend class ReplaceDraw;
304 friend class SkPictureUtils;
305 friend class SkRecordedDrawable;
188 }; 306 };
307 SK_COMPILE_ASSERT(sizeof(SkPicture) <= 88, SkPictureSize);
189 308
190 #endif 309 #endif
OLDNEW
« no previous file with comments | « gyp/utils.gypi ('k') | include/core/SkPictureRecorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698