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

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

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