OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
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 #ifndef SkPicturePlayback_DEFINED | 9 #ifndef SkPicturePlayback_DEFINED |
9 #define SkPicturePlayback_DEFINED | 10 #define SkPicturePlayback_DEFINED |
10 | 11 |
11 #include "SkPicture.h" | 12 #include "SkPicture.h" |
12 #include "SkReader32.h" | 13 #include "SkReader32.h" |
13 | 14 |
14 #include "SkBitmap.h" | 15 #include "SkBitmap.h" |
15 #include "SkData.h" | 16 #include "SkData.h" |
16 #include "SkMatrix.h" | 17 #include "SkMatrix.h" |
17 #include "SkReadBuffer.h" | 18 #include "SkReadBuffer.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 const SkPictInfo&, | 85 const SkPictInfo&, |
85 SkPicture::InstallPixelRefProc); | 86 SkPicture::InstallPixelRefProc); |
86 static SkPicturePlayback* CreateFromBuffer(SkPicture* picture, | 87 static SkPicturePlayback* CreateFromBuffer(SkPicture* picture, |
87 SkReadBuffer&, | 88 SkReadBuffer&, |
88 const SkPictInfo&); | 89 const SkPictInfo&); |
89 | 90 |
90 virtual ~SkPicturePlayback(); | 91 virtual ~SkPicturePlayback(); |
91 | 92 |
92 const SkPicture::OperationList& getActiveOps(const SkIRect& queryRect); | 93 const SkPicture::OperationList& getActiveOps(const SkIRect& queryRect); |
93 | 94 |
95 void setUseBBH(bool useBBH) { fUseBBH = useBBH; } | |
96 | |
94 void draw(SkCanvas& canvas, SkDrawPictureCallback*); | 97 void draw(SkCanvas& canvas, SkDrawPictureCallback*); |
95 | 98 |
96 void serialize(SkWStream*, SkPicture::EncodeBitmap) const; | 99 void serialize(SkWStream*, SkPicture::EncodeBitmap) const; |
97 void flatten(SkWriteBuffer&) const; | 100 void flatten(SkWriteBuffer&) const; |
98 | 101 |
99 void dumpSize() const; | 102 void dumpSize() const; |
100 | 103 |
101 bool containsBitmaps() const; | 104 bool containsBitmaps() const; |
102 | 105 |
103 #ifdef SK_BUILD_FOR_ANDROID | 106 #ifdef SK_BUILD_FOR_ANDROID |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 #endif | 223 #endif |
221 | 224 |
222 private: // these help us with reading/writing | 225 private: // these help us with reading/writing |
223 bool parseStreamTag(SkPicture* picture, SkStream*, uint32_t tag, uint32_t si ze, | 226 bool parseStreamTag(SkPicture* picture, SkStream*, uint32_t tag, uint32_t si ze, |
224 SkPicture::InstallPixelRefProc); | 227 SkPicture::InstallPixelRefProc); |
225 bool parseBufferTag(SkPicture* picture, SkReadBuffer&, uint32_t tag, uint32_ t size); | 228 bool parseBufferTag(SkPicture* picture, SkReadBuffer&, uint32_t tag, uint32_ t size); |
226 void flattenToBuffer(SkWriteBuffer&) const; | 229 void flattenToBuffer(SkWriteBuffer&) const; |
227 | 230 |
228 private: | 231 private: |
229 friend class SkPicture; | 232 friend class SkPicture; |
233 friend class SkGpuDevice; // for access to setDrawLimits & setReplacements | |
230 | 234 |
231 // The picture that owns this SkPicturePlayback object | 235 // The picture that owns this SkPicturePlayback object |
232 const SkPicture* fPicture; | 236 const SkPicture* fPicture; |
233 | 237 |
234 // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_ SLOT. This empty | 238 // Only used by getBitmap() if the passed in index is SkBitmapHeap::INVALID_ SLOT. This empty |
235 // bitmap allows playback to draw nothing and move on. | 239 // bitmap allows playback to draw nothing and move on. |
236 SkBitmap fBadBitmap; | 240 SkBitmap fBadBitmap; |
237 | 241 |
238 SkAutoTUnref<SkBitmapHeap> fBitmapHeap; | 242 SkAutoTUnref<SkBitmapHeap> fBitmapHeap; |
239 | 243 |
240 SkTRefArray<SkBitmap>* fBitmaps; | 244 SkTRefArray<SkBitmap>* fBitmaps; |
241 SkTRefArray<SkPaint>* fPaints; | 245 SkTRefArray<SkPaint>* fPaints; |
242 | 246 |
243 SkData* fOpData; // opcodes and parameters | 247 SkData* fOpData; // opcodes and parameters |
244 | 248 |
245 SkPicture** fPictureRefs; | 249 SkPicture** fPictureRefs; |
246 int fPictureCount; | 250 int fPictureCount; |
247 | 251 |
248 SkBBoxHierarchy* fBoundingHierarchy; | 252 SkBBoxHierarchy* fBoundingHierarchy; |
249 SkPictureStateTree* fStateTree; | 253 SkPictureStateTree* fStateTree; |
250 | 254 |
255 // Limit the opcode playback to be between the offsets 'start' and 'stop'. | |
256 // The opcode at 'start' should be a saveLayer while the opcode at | |
257 // 'stop' should be a restore. Neither of those commands will be issued. | |
258 // Set both start & stop to 0 to disable draw limiting | |
259 // Draw limiting cannot be enabled at the same time as draw replacing | |
260 void setDrawLimits(size_t start, size_t stop) { | |
261 SkASSERT(NULL == fReplacements); | |
262 fStart = start; | |
263 fStop = stop; | |
264 } | |
265 | |
266 // PlaybackReplacements collects op ranges that can be replaced with | |
267 // a single drawBitmap call (using a precomputed bitmap). | |
268 class PlaybackReplacements { | |
reed1
2014/05/07 16:13:28
nit: can this guy live in the .cpp, and just forwa
robertphillips
2014/05/07 16:52:03
SkGpuDevice needs access to it. I have, however, m
| |
269 public: | |
270 // All the operations between fStart and fStop (inclusive) will be repla ced with | |
271 // a single drawBitmap call using fPos, fBM and fPaint. | |
272 // fPaint will be NULL if the picture's paint wasn't copyable | |
273 struct ReplacementInfo { | |
274 size_t fStart; | |
275 size_t fStop; | |
276 SkPoint fPos; | |
277 SkBitmap* fBM; | |
278 const SkPaint* fPaint; // Note: this object doesn't own the paint | |
279 }; | |
280 | |
281 ~PlaybackReplacements() { | |
282 this->freeAll(); | |
283 } | |
284 | |
285 // Add a new replacement range. The replacement ranges should be | |
286 // sorted in increasing order and non-overlapping (esp. no nested | |
287 // saveLayers). | |
288 ReplacementInfo* push() { | |
289 SkDEBUGCODE(this->validate()); | |
290 return fReplacements.push(); | |
291 } | |
292 | |
293 private: | |
294 friend class SkPicturePlayback; // for access to lookupByStart | |
295 | |
296 // look up a replacement range by its start offset | |
297 ReplacementInfo* lookupByStart(size_t start); | |
298 | |
299 void freeAll() { | |
300 for (int i = 0; i < fReplacements.count(); ++i) { | |
301 SkDELETE(fReplacements[i].fBM); | |
302 } | |
303 fReplacements.reset(); | |
304 } | |
305 | |
306 #ifdef SK_DEBUG | |
307 void validate() const { | |
308 // Check that the ranges are monotonically increasing and non-overla pping | |
309 if (fReplacements.count() > 0) { | |
310 SkASSERT(fReplacements[0].fStart < fReplacements[0].fStop); | |
311 | |
312 for (int i = 1; i < fReplacements.count(); ++i) { | |
313 SkASSERT(fReplacements[i].fStart < fReplacements[i].fStop); | |
314 SkASSERT(fReplacements[i-1].fStop < fReplacements[i].fStart) ; | |
315 } | |
316 } | |
317 } | |
318 #endif | |
319 | |
320 SkTDArray<ReplacementInfo> fReplacements; | |
321 }; | |
322 | |
323 // Replace all the draw ops in the replacement ranges in 'replacements' with | |
324 // the associated drawBitmap call | |
325 // Draw replacing cannot be enabled at the same time as draw limiting | |
326 void setReplacements(PlaybackReplacements* replacements) { | |
327 SkASSERT(fStart == 0 && fStop == 0); | |
328 fReplacements = replacements; | |
329 } | |
330 | |
331 bool fUseBBH; | |
332 size_t fStart; | |
333 size_t fStop; | |
334 PlaybackReplacements* fReplacements; | |
335 | |
251 class CachedOperationList : public SkPicture::OperationList { | 336 class CachedOperationList : public SkPicture::OperationList { |
252 public: | 337 public: |
253 CachedOperationList() { | 338 CachedOperationList() { |
254 fCacheQueryRect.setEmpty(); | 339 fCacheQueryRect.setEmpty(); |
255 } | 340 } |
256 | 341 |
257 virtual bool valid() const { return true; } | 342 virtual bool valid() const { return true; } |
258 virtual int numOps() const SK_OVERRIDE { return fOps.count(); } | 343 virtual int numOps() const SK_OVERRIDE { return fOps.count(); } |
259 virtual uint32_t offset(int index) const SK_OVERRIDE; | 344 virtual uint32_t offset(int index) const SK_OVERRIDE; |
260 virtual const SkMatrix& matrix(int index) const SK_OVERRIDE; | 345 virtual const SkMatrix& matrix(int index) const SK_OVERRIDE; |
(...skipping 21 matching lines...) Expand all Loading... | |
282 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); | 367 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); |
283 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); | 368 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); |
284 | 369 |
285 #ifdef SK_BUILD_FOR_ANDROID | 370 #ifdef SK_BUILD_FOR_ANDROID |
286 SkMutex fDrawMutex; | 371 SkMutex fDrawMutex; |
287 bool fAbortCurrentPlayback; | 372 bool fAbortCurrentPlayback; |
288 #endif | 373 #endif |
289 }; | 374 }; |
290 | 375 |
291 #endif | 376 #endif |
OLD | NEW |