OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
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 |
9 | 9 |
10 #ifndef SkPicture_DEFINED | 10 #ifndef SkPicture_DEFINED |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 enum RecordingFlags { | 133 enum RecordingFlags { |
134 /* This flag specifies that when clipPath() is called, the path will | 134 /* This flag specifies that when clipPath() is called, the path will |
135 be faithfully recorded, but the recording canvas' current clip will | 135 be faithfully recorded, but the recording canvas' current clip will |
136 only see the path's bounds. This speeds up the recording process | 136 only see the path's bounds. This speeds up the recording process |
137 without compromising the fidelity of the playback. The only side- | 137 without compromising the fidelity of the playback. The only side- |
138 effect for recording is that calling getTotalClip() or related | 138 effect for recording is that calling getTotalClip() or related |
139 clip-query calls will reflect the path's bounds, not the actual | 139 clip-query calls will reflect the path's bounds, not the actual |
140 path. | 140 path. |
141 */ | 141 */ |
142 kUsePathBoundsForClip_RecordingFlag = 0x01, | 142 kUsePathBoundsForClip_RecordingFlag = 0x01 |
| 143 }; |
| 144 |
| 145 #ifndef SK_SUPPORT_DEPRECATED_RECORD_FLAGS |
| 146 // TODO: once kOptimizeForClippedPlayback_RecordingFlag is hidden from |
| 147 // all external consumers, SkPicture::createBBoxHierarchy can also be |
| 148 // cleaned up. |
| 149 private: |
| 150 #endif |
| 151 enum Deprecated_RecordingFlags { |
143 /* This flag causes the picture to compute bounding boxes and build | 152 /* This flag causes the picture to compute bounding boxes and build |
144 up a spatial hierarchy (currently an R-Tree), plus a tree of Canvas' | 153 up a spatial hierarchy (currently an R-Tree), plus a tree of Canvas' |
145 usually stack-based clip/etc state. This requires an increase in | 154 usually stack-based clip/etc state. This requires an increase in |
146 recording time (often ~2x; likely more for very complex pictures), | 155 recording time (often ~2x; likely more for very complex pictures), |
147 but allows us to perform much faster culling at playback time, and | 156 but allows us to perform much faster culling at playback time, and |
148 completely avoid some unnecessary clips and other operations. This | 157 completely avoid some unnecessary clips and other operations. This |
149 is ideal for tiled rendering, or any other situation where you're | 158 is ideal for tiled rendering, or any other situation where you're |
150 drawing a fraction of a large scene into a smaller viewport. | 159 drawing a fraction of a large scene into a smaller viewport. |
151 | 160 |
152 In most cases the record cost is offset by the playback improvement | 161 In most cases the record cost is offset by the playback improvement |
153 after a frame or two of tiled rendering (and complex pictures that | 162 after a frame or two of tiled rendering (and complex pictures that |
154 induce the worst record times will generally get the largest | 163 induce the worst record times will generally get the largest |
155 speedups at playback time). | 164 speedups at playback time). |
156 | 165 |
157 Note: Currently this is not serializable, the bounding data will be | 166 Note: Currently this is not serializable, the bounding data will be |
158 discarded if you serialize into a stream and then deserialize. | 167 discarded if you serialize into a stream and then deserialize. |
159 */ | 168 */ |
160 kOptimizeForClippedPlayback_RecordingFlag = 0x02, | 169 kOptimizeForClippedPlayback_RecordingFlag = 0x02, |
161 }; | 170 }; |
| 171 #ifndef SK_SUPPORT_DEPRECATED_RECORD_FLAGS |
| 172 public: |
| 173 #endif |
162 | 174 |
163 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD | 175 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD |
164 private: | 176 private: |
165 friend class SkPictureRecorder; | 177 friend class SkPictureRecorder; |
166 friend class SkImage_Picture; | 178 friend class SkImage_Picture; |
167 friend class SkSurface_Picture; | 179 friend class SkSurface_Picture; |
168 #endif | 180 #endif |
169 | 181 |
170 /** Returns the canvas that records the drawing commands. | 182 /** Returns the canvas that records the drawing commands. |
171 @param width the base width for the picture, as if the recording | 183 @param width the base width for the picture, as if the recording |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 341 |
330 void needsNewGenID() { fUniqueID = SK_InvalidGenID; } | 342 void needsNewGenID() { fUniqueID = SK_InvalidGenID; } |
331 | 343 |
332 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of | 344 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of |
333 // playback is unchanged. | 345 // playback is unchanged. |
334 SkPicture(SkPicturePlayback*, int width, int height); | 346 SkPicture(SkPicturePlayback*, int width, int height); |
335 | 347 |
336 // For testing. Derived classes may instantiate an alternate | 348 // For testing. Derived classes may instantiate an alternate |
337 // SkBBoxHierarchy implementation | 349 // SkBBoxHierarchy implementation |
338 virtual SkBBoxHierarchy* createBBoxHierarchy() const; | 350 virtual SkBBoxHierarchy* createBBoxHierarchy() const; |
| 351 |
339 private: | 352 private: |
340 // An OperationList encapsulates a set of operation offsets into the picture
byte | 353 // An OperationList encapsulates a set of operation offsets into the picture
byte |
341 // stream along with the CTMs needed for those operation. | 354 // stream along with the CTMs needed for those operation. |
342 class OperationList : ::SkNoncopyable { | 355 class OperationList : ::SkNoncopyable { |
343 public: | 356 public: |
344 virtual ~OperationList() {} | 357 virtual ~OperationList() {} |
345 | 358 |
346 // If valid returns false then there is no optimization data | 359 // If valid returns false then there is no optimization data |
347 // present. All the draw operations need to be issued. | 360 // present. All the draw operations need to be issued. |
348 virtual bool valid() const { return false; } | 361 virtual bool valid() const { return false; } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 411 |
399 virtual bool abortDrawing() = 0; | 412 virtual bool abortDrawing() = 0; |
400 }; | 413 }; |
401 | 414 |
402 class SkPictureFactory : public SkRefCnt { | 415 class SkPictureFactory : public SkRefCnt { |
403 public: | 416 public: |
404 /** | 417 /** |
405 * Allocate a new SkPicture. Return NULL on failure. | 418 * Allocate a new SkPicture. Return NULL on failure. |
406 */ | 419 */ |
407 virtual SkPicture* create(int width, int height) = 0; | 420 virtual SkPicture* create(int width, int height) = 0; |
| 421 |
| 422 private: |
| 423 typedef SkRefCnt INHERITED; |
408 }; | 424 }; |
409 | 425 |
410 class SK_API SkPictureRecorder : SkNoncopyable { | 426 class SK_API SkPictureRecorder : SkNoncopyable { |
411 public: | 427 public: |
412 SkPictureRecorder(SkPictureFactory* factory = NULL) { | 428 SkPictureRecorder(SkPictureFactory* factory = NULL) { |
413 fFactory.reset(factory); | 429 fFactory.reset(factory); |
414 if (NULL != fFactory.get()) { | 430 if (NULL != fFactory.get()) { |
415 fFactory.get()->ref(); | 431 fFactory.get()->ref(); |
416 } | 432 } |
417 } | 433 } |
418 | 434 |
419 /** Returns the canvas that records the drawing commands. | 435 /** Returns the canvas that records the drawing commands. |
420 @param width the base width for the picture, as if the recording | 436 @param width the base width for the picture, as if the recording |
421 canvas' bitmap had this width. | 437 canvas' bitmap had this width. |
422 @param height the base width for the picture, as if the recording | 438 @param height the base width for the picture, as if the recording |
423 canvas' bitmap had this height. | 439 canvas' bitmap had this height. |
424 @param recordFlags optional flags that control recording. | 440 @param recordFlags optional flags that control recording. |
425 @return the canvas. | 441 @return the canvas. |
426 */ | 442 */ |
427 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) { | 443 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) { |
428 if (NULL != fFactory) { | 444 if (NULL != fFactory) { |
429 fPicture.reset(fFactory->create(width, height)); | 445 fPicture.reset(fFactory->create(width, height)); |
| 446 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
430 } else { | 447 } else { |
431 fPicture.reset(SkNEW(SkPicture)); | 448 fPicture.reset(SkNEW(SkPicture)); |
432 } | 449 } |
433 | 450 |
434 return fPicture->beginRecording(width, height, recordFlags); | 451 return fPicture->beginRecording(width, height, recordFlags); |
435 } | 452 } |
436 | 453 |
437 /** Returns the recording canvas if one is active, or NULL if recording is | 454 /** Returns the recording canvas if one is active, or NULL if recording is |
438 not active. This does not alter the refcnt on the canvas (if present). | 455 not active. This does not alter the refcnt on the canvas (if present). |
439 */ | 456 */ |
(...skipping 30 matching lines...) Expand all Loading... |
470 } | 487 } |
471 | 488 |
472 private: | 489 private: |
473 SkAutoTUnref<SkPictureFactory> fFactory; | 490 SkAutoTUnref<SkPictureFactory> fFactory; |
474 SkAutoTUnref<SkPicture> fPicture; | 491 SkAutoTUnref<SkPicture> fPicture; |
475 | 492 |
476 typedef SkNoncopyable INHERITED; | 493 typedef SkNoncopyable INHERITED; |
477 }; | 494 }; |
478 | 495 |
479 #endif | 496 #endif |
OLD | NEW |