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

Side by Side Diff: src/core/SkPictureData.h

Issue 377623002: Split SkPicturePlayback out of SkPictureData (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add virtual dtor for SkPicturePlayback Created 6 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
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkPictureData.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
2 /* 1 /*
3 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 #ifndef SkPictureData_DEFINED 8 #ifndef SkPictureData_DEFINED
10 #define SkPictureData_DEFINED 9 #define SkPictureData_DEFINED
11 10
12 #include "SkBitmap.h" 11 #include "SkBitmap.h"
13 #include "SkPathHeap.h" 12 #include "SkPathHeap.h"
14 #include "SkPicture.h" 13 #include "SkPicture.h"
15 #include "SkPictureFlat.h" 14 #include "SkPictureFlat.h"
16 15
17 #ifdef SK_BUILD_FOR_ANDROID
18 #include "SkThread.h"
19 #endif
20
21 class SkData; 16 class SkData;
22 class SkPictureRecord; 17 class SkPictureRecord;
23 class SkReader32; 18 class SkReader32;
24 class SkStream; 19 class SkStream;
25 class SkWStream; 20 class SkWStream;
26 class SkBBoxHierarchy; 21 class SkBBoxHierarchy;
27 class SkMatrix; 22 class SkMatrix;
28 class SkPaint; 23 class SkPaint;
29 class SkPath; 24 class SkPath;
30 class SkPictureStateTree; 25 class SkPictureStateTree;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 124
130 bool initialized; 125 bool initialized;
131 SkChunkFlatController controller; 126 SkChunkFlatController controller;
132 SkTDArray<SkFlatData*> paintData; 127 SkTDArray<SkFlatData*> paintData;
133 }; 128 };
134 #endif 129 #endif
135 130
136 class SkPictureData { 131 class SkPictureData {
137 public: 132 public:
138 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE 133 #ifdef SK_SUPPORT_LEGACY_PICTURE_CLONE
139 SkPictureData(const SkPictureData& src, 134 SkPictureData(const SkPictureData& src, SkPictCopyInfo* deepCopyInfo = NULL) ;
140 SkPictCopyInfo* deepCopyInfo = NULL);
141 #else 135 #else
142 SkPictureData(const SkPictureData& src); 136 SkPictureData(const SkPictureData& src);
143 #endif 137 #endif
144 SkPictureData(const SkPictureRecord& record, const SkPictInfo&, bool deepCop yOps); 138 SkPictureData(const SkPictureRecord& record, const SkPictInfo&, bool deepCop yOps);
145 static SkPictureData* CreateFromStream(SkStream*, 139 static SkPictureData* CreateFromStream(SkStream*,
146 const SkPictInfo&, 140 const SkPictInfo&,
147 SkPicture::InstallPixelRefProc); 141 SkPicture::InstallPixelRefProc);
148 static SkPictureData* CreateFromBuffer(SkReadBuffer&, 142 static SkPictureData* CreateFromBuffer(SkReadBuffer&, const SkPictInfo&);
149 const SkPictInfo&);
150 143
151 virtual ~SkPictureData(); 144 virtual ~SkPictureData();
152 145
153 const SkPicture::OperationList& getActiveOps(const SkIRect& queryRect); 146 const SkPicture::OperationList* getActiveOps(const SkIRect& queryRect) const ;
154
155 void setUseBBH(bool useBBH) { fUseBBH = useBBH; }
156
157 void draw(SkCanvas& canvas, SkDrawPictureCallback*);
158 147
159 void serialize(SkWStream*, SkPicture::EncodeBitmap) const; 148 void serialize(SkWStream*, SkPicture::EncodeBitmap) const;
160 void flatten(SkWriteBuffer&) const; 149 void flatten(SkWriteBuffer&) const;
161 150
162 void dumpSize() const; 151 void dumpSize() const;
163 152
164 bool containsBitmaps() const; 153 bool containsBitmaps() const;
165 154
166 #ifdef SK_BUILD_FOR_ANDROID
167 // Can be called in the middle of playback (the draw() call). WIll abort the
168 // drawing and return from draw() after the "current" op code is done
169 void abort() { fAbortCurrentPlayback = true; }
170 #endif
171
172 size_t curOpID() const { return fCurOffset; }
173 void resetOpID() { fCurOffset = 0; }
174
175 protected: 155 protected:
176 explicit SkPictureData(const SkPictInfo& info); 156 explicit SkPictureData(const SkPictInfo& info);
177 157
178 bool parseStream(SkStream*, SkPicture::InstallPixelRefProc); 158 bool parseStream(SkStream*, SkPicture::InstallPixelRefProc);
179 bool parseBuffer(SkReadBuffer& buffer); 159 bool parseBuffer(SkReadBuffer& buffer);
180 #ifdef SK_DEVELOPER
181 virtual bool preDraw(int opIndex, int type);
182 virtual void postDraw(int opIndex);
183 #endif
184 160
185 private: 161 private:
186 class TextContainer {
187 public:
188 size_t length() { return fByteLength; }
189 const void* text() { return (const void*) fText; }
190 size_t fByteLength;
191 const char* fText;
192 };
193 162
194 const SkBitmap& getBitmap(SkReader32& reader) { 163 const SkBitmap& getBitmap(SkReader32& reader) const {
195 const int index = reader.readInt(); 164 const int index = reader.readInt();
196 if (SkBitmapHeap::INVALID_SLOT == index) { 165 if (SkBitmapHeap::INVALID_SLOT == index) {
197 #ifdef SK_DEBUG 166 #ifdef SK_DEBUG
198 SkDebugf("An invalid bitmap was recorded!\n"); 167 SkDebugf("An invalid bitmap was recorded!\n");
199 #endif 168 #endif
200 return fBadBitmap; 169 return fBadBitmap;
201 } 170 }
202 return (*fBitmaps)[index]; 171 return (*fBitmaps)[index];
203 } 172 }
204 173
205 void getMatrix(SkReader32& reader, SkMatrix* matrix) { 174 const SkPath& getPath(SkReader32& reader) const {
206 reader.readMatrix(matrix);
207 }
208
209 const SkPath& getPath(SkReader32& reader) {
210 int index = reader.readInt() - 1; 175 int index = reader.readInt() - 1;
211 return (*fPathHeap.get())[index]; 176 return (*fPathHeap.get())[index];
212 } 177 }
213 178
214 const SkPicture* getPicture(SkReader32& reader) { 179 const SkPicture* getPicture(SkReader32& reader) const {
215 int index = reader.readInt(); 180 int index = reader.readInt();
216 SkASSERT(index > 0 && index <= fPictureCount); 181 SkASSERT(index > 0 && index <= fPictureCount);
217 return fPictureRefs[index - 1]; 182 return fPictureRefs[index - 1];
218 } 183 }
219 184
220 const SkPaint* getPaint(SkReader32& reader) { 185 const SkPaint* getPaint(SkReader32& reader) const {
221 int index = reader.readInt(); 186 int index = reader.readInt();
222 if (index == 0) { 187 if (index == 0) {
223 return NULL; 188 return NULL;
224 } 189 }
225 return &(*fPaints)[index - 1]; 190 return &(*fPaints)[index - 1];
226 } 191 }
227 192
228 const SkRect* getRectPtr(SkReader32& reader) {
229 if (reader.readBool()) {
230 return &reader.skipT<SkRect>();
231 } else {
232 return NULL;
233 }
234 }
235
236 const SkIRect* getIRectPtr(SkReader32& reader) {
237 if (reader.readBool()) {
238 return &reader.skipT<SkIRect>();
239 } else {
240 return NULL;
241 }
242 }
243
244 void getRegion(SkReader32& reader, SkRegion* region) {
245 reader.readRegion(region);
246 }
247
248 void getText(SkReader32& reader, TextContainer* text) {
249 size_t length = text->fByteLength = reader.readInt();
250 text->fText = (const char*)reader.skip(length);
251 }
252
253 void init(); 193 void init();
254 194
255 #ifdef SK_DEBUG_SIZE 195 #ifdef SK_DEBUG_SIZE
256 public: 196 public:
257 int size(size_t* sizePtr); 197 int size(size_t* sizePtr);
258 int bitmaps(size_t* size); 198 int bitmaps(size_t* size);
259 int paints(size_t* size); 199 int paints(size_t* size);
260 int paths(size_t* size); 200 int paths(size_t* size);
261 #endif 201 #endif
262 202
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 GrPixelConfig config, SkScalar dpi) const; 239 GrPixelConfig config, SkScalar dpi) const;
300 #endif 240 #endif
301 241
302 private: // these help us with reading/writing 242 private: // these help us with reading/writing
303 bool parseStreamTag(SkStream*, uint32_t tag, uint32_t size, SkPicture::Insta llPixelRefProc); 243 bool parseStreamTag(SkStream*, uint32_t tag, uint32_t size, SkPicture::Insta llPixelRefProc);
304 bool parseBufferTag(SkReadBuffer&, uint32_t tag, uint32_t size); 244 bool parseBufferTag(SkReadBuffer&, uint32_t tag, uint32_t size);
305 void flattenToBuffer(SkWriteBuffer&) const; 245 void flattenToBuffer(SkWriteBuffer&) const;
306 246
307 private: 247 private:
308 friend class SkPicture; 248 friend class SkPicture;
309 friend class SkGpuDevice; // for access to setDrawLimits & setReplacements 249 friend class SkPicturePlayback;
310 250
311 // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_ SLOT. This empty 251 // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_ SLOT. This empty
312 // bitmap allows playback to draw nothing and move on. 252 // bitmap allows playback to draw nothing and move on.
313 SkBitmap fBadBitmap; 253 SkBitmap fBadBitmap;
314 254
315 SkAutoTUnref<SkBitmapHeap> fBitmapHeap; 255 SkAutoTUnref<SkBitmapHeap> fBitmapHeap;
316 256
317 SkTRefArray<SkBitmap>* fBitmaps; 257 SkTRefArray<SkBitmap>* fBitmaps;
318 SkTRefArray<SkPaint>* fPaints; 258 SkTRefArray<SkPaint>* fPaints;
319 259
320 SkData* fOpData; // opcodes and parameters 260 SkData* fOpData; // opcodes and parameters
321 261
322 SkAutoTUnref<const SkPathHeap> fPathHeap; // reference counted 262 SkAutoTUnref<const SkPathHeap> fPathHeap; // reference counted
323 263
324 const SkPicture** fPictureRefs; 264 const SkPicture** fPictureRefs;
325 int fPictureCount; 265 int fPictureCount;
326 266
327 SkBBoxHierarchy* fBoundingHierarchy; 267 SkBBoxHierarchy* fBoundingHierarchy;
328 SkPictureStateTree* fStateTree; 268 SkPictureStateTree* fStateTree;
329 269
330 SkPictureContentInfo fContentInfo; 270 SkPictureContentInfo fContentInfo;
331 271
332 // Limit the opcode playback to be between the offsets 'start' and 'stop'. 272 class OperationList : public SkPicture::OperationList {
333 // The opcode at 'start' should be a saveLayer while the opcode at
334 // 'stop' should be a restore. Neither of those commands will be issued.
335 // Set both start & stop to 0 to disable draw limiting
336 // Draw limiting cannot be enabled at the same time as draw replacing
337 void setDrawLimits(size_t start, size_t stop) {
338 SkASSERT(NULL == fReplacements);
339 fStart = start;
340 fStop = stop;
341 }
342
343 // PlaybackReplacements collects op ranges that can be replaced with
344 // a single drawBitmap call (using a precomputed bitmap).
345 class PlaybackReplacements {
346 public: 273 public:
347 // All the operations between fStart and fStop (inclusive) will be repla ced with 274 OperationList() { }
348 // a single drawBitmap call using fPos, fBM and fPaint.
349 // fPaint will be NULL if the picture's paint wasn't copyable
350 struct ReplacementInfo {
351 size_t fStart;
352 size_t fStop;
353 SkIPoint fPos;
354 SkBitmap* fBM; // fBM is allocated so ReplacementInfo can remain POD
355 const SkPaint* fPaint; // Note: this object doesn't own the paint
356
357 SkIRect fSrcRect;
358 };
359
360 ~PlaybackReplacements() { this->freeAll(); }
361
362 // Add a new replacement range. The replacement ranges should be
363 // sorted in increasing order and non-overlapping (esp. no nested
364 // saveLayers).
365 ReplacementInfo* push();
366
367 private:
368 friend class SkPictureData; // for access to lookupByStart
369
370 // look up a replacement range by its start offset
371 ReplacementInfo* lookupByStart(size_t start);
372
373 void freeAll();
374
375 #ifdef SK_DEBUG
376 void validate() const;
377 #endif
378
379 SkTDArray<ReplacementInfo> fReplacements;
380 };
381
382 // Replace all the draw ops in the replacement ranges in 'replacements' with
383 // the associated drawBitmap call
384 // Draw replacing cannot be enabled at the same time as draw limiting
385 void setReplacements(PlaybackReplacements* replacements) {
386 SkASSERT(fStart == 0 && fStop == 0);
387 fReplacements = replacements;
388 }
389
390 bool fUseBBH;
391 size_t fStart;
392 size_t fStop;
393 PlaybackReplacements* fReplacements;
394
395 class CachedOperationList : public SkPicture::OperationList {
396 public:
397 CachedOperationList() {
398 fCacheQueryRect.setEmpty();
399 }
400
401 virtual bool valid() const { return true; }
402 virtual int numOps() const SK_OVERRIDE { return fOps.count(); } 275 virtual int numOps() const SK_OVERRIDE { return fOps.count(); }
403 virtual uint32_t offset(int index) const SK_OVERRIDE; 276 virtual uint32_t offset(int index) const SK_OVERRIDE;
404 virtual const SkMatrix& matrix(int index) const SK_OVERRIDE; 277 virtual const SkMatrix& matrix(int index) const SK_OVERRIDE;
405 278
406 // The query rect for which the cached active ops are valid
407 SkIRect fCacheQueryRect;
408
409 // The operations which are active within 'fCachedQueryRect' 279 // The operations which are active within 'fCachedQueryRect'
410 SkTDArray<void*> fOps; 280 SkTDArray<void*> fOps;
411 281
412 private: 282 private:
413 typedef SkPicture::OperationList INHERITED; 283 typedef SkPicture::OperationList INHERITED;
414 }; 284 };
415 285
416 CachedOperationList* fCachedActiveOps;
417
418 SkTypefacePlayback fTFPlayback; 286 SkTypefacePlayback fTFPlayback;
419 SkFactoryPlayback* fFactoryPlayback; 287 SkFactoryPlayback* fFactoryPlayback;
420 288
421 // The offset of the current operation when within the draw method
422 size_t fCurOffset;
423
424 const SkPictInfo fInfo; 289 const SkPictInfo fInfo;
425 290
426 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); 291 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec);
427 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); 292 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec);
428 293
429 void initForPlayback() const; 294 void initForPlayback() const;
430
431 #ifdef SK_BUILD_FOR_ANDROID
432 SkMutex fDrawMutex;
433 bool fAbortCurrentPlayback;
434 #endif
435 }; 295 };
436 296
437 #endif 297 #endif
OLDNEW
« no previous file with comments | « src/core/SkPicture.cpp ('k') | src/core/SkPictureData.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698