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

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

Issue 261663003: First pass at pre-rendering saveLayers for GPU (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Reduce size of PlaybackReplacements in SkPicturePlayback.h Created 6 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 | Annotate | Revision Log
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPicturePlayback.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 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
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
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 {
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() { this->freeAll(); }
282
283 // Add a new replacement range. The replacement ranges should be
284 // sorted in increasing order and non-overlapping (esp. no nested
285 // saveLayers).
286 ReplacementInfo* push();
287
288 private:
289 friend class SkPicturePlayback; // for access to lookupByStart
290
291 // look up a replacement range by its start offset
292 ReplacementInfo* lookupByStart(size_t start);
293
294 void freeAll();
295
296 #ifdef SK_DEBUG
297 void validate() const;
298 #endif
299
300 SkTDArray<ReplacementInfo> fReplacements;
301 };
302
303
304 // Replace all the draw ops in the replacement ranges in 'replacements' with
305 // the associated drawBitmap call
306 // Draw replacing cannot be enabled at the same time as draw limiting
307 void setReplacements(PlaybackReplacements* replacements) {
308 SkASSERT(fStart == 0 && fStop == 0);
309 fReplacements = replacements;
310 }
311
312 bool fUseBBH;
313 size_t fStart;
314 size_t fStop;
315 PlaybackReplacements* fReplacements;
316
251 class CachedOperationList : public SkPicture::OperationList { 317 class CachedOperationList : public SkPicture::OperationList {
252 public: 318 public:
253 CachedOperationList() { 319 CachedOperationList() {
254 fCacheQueryRect.setEmpty(); 320 fCacheQueryRect.setEmpty();
255 } 321 }
256 322
257 virtual bool valid() const { return true; } 323 virtual bool valid() const { return true; }
258 virtual int numOps() const SK_OVERRIDE { return fOps.count(); } 324 virtual int numOps() const SK_OVERRIDE { return fOps.count(); }
259 virtual uint32_t offset(int index) const SK_OVERRIDE; 325 virtual uint32_t offset(int index) const SK_OVERRIDE;
260 virtual const SkMatrix& matrix(int index) const SK_OVERRIDE; 326 virtual const SkMatrix& matrix(int index) const SK_OVERRIDE;
(...skipping 21 matching lines...) Expand all
282 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec); 348 static void WriteFactories(SkWStream* stream, const SkFactorySet& rec);
283 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec); 349 static void WriteTypefaces(SkWStream* stream, const SkRefCntSet& rec);
284 350
285 #ifdef SK_BUILD_FOR_ANDROID 351 #ifdef SK_BUILD_FOR_ANDROID
286 SkMutex fDrawMutex; 352 SkMutex fDrawMutex;
287 bool fAbortCurrentPlayback; 353 bool fAbortCurrentPlayback;
288 #endif 354 #endif
289 }; 355 };
290 356
291 #endif 357 #endif
OLDNEW
« no previous file with comments | « include/core/SkPicture.h ('k') | src/core/SkPicturePlayback.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698