Chromium Code Reviews| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 */ | 125 */ |
| 126 SkPicture* clone() const; | 126 SkPicture* clone() const; |
| 127 | 127 |
| 128 /** | 128 /** |
| 129 * Creates multiple thread-safe clones of this picture that are ready for | 129 * Creates multiple thread-safe clones of this picture that are ready for |
| 130 * playback. The resulting clones are stored in the provided array of | 130 * playback. The resulting clones are stored in the provided array of |
| 131 * SkPictures. | 131 * SkPictures. |
| 132 */ | 132 */ |
| 133 void clone(SkPicture* pictures, int count) const; | 133 void clone(SkPicture* pictures, int count) const; |
| 134 | 134 |
| 135 // TODO: kUsePathBoundsForClip_RecordingFlag no longer belongs in | |
| 136 // SkPicture. It should be moved to SkPictureRecorder (or just made | |
|
mtklein
2014/06/03 15:27:44
+1 to default.
| |
| 137 // the default behavior). | |
| 135 enum RecordingFlags { | 138 enum RecordingFlags { |
| 136 /* This flag specifies that when clipPath() is called, the path will | 139 /* This flag specifies that when clipPath() is called, the path will |
| 137 be faithfully recorded, but the recording canvas' current clip will | 140 be faithfully recorded, but the recording canvas' current clip will |
| 138 only see the path's bounds. This speeds up the recording process | 141 only see the path's bounds. This speeds up the recording process |
| 139 without compromising the fidelity of the playback. The only side- | 142 without compromising the fidelity of the playback. The only side- |
| 140 effect for recording is that calling getTotalClip() or related | 143 effect for recording is that calling getTotalClip() or related |
| 141 clip-query calls will reflect the path's bounds, not the actual | 144 clip-query calls will reflect the path's bounds, not the actual |
| 142 path. | 145 path. |
| 143 */ | 146 */ |
| 144 kUsePathBoundsForClip_RecordingFlag = 0x01 | 147 kUsePathBoundsForClip_RecordingFlag = 0x01 |
| 145 }; | 148 }; |
| 146 | 149 |
| 147 #ifndef SK_SUPPORT_DEPRECATED_RECORD_FLAGS | |
| 148 // TODO: once kOptimizeForClippedPlayback_RecordingFlag is hidden from | |
| 149 // all external consumers, SkPicture::createBBoxHierarchy can also be | |
| 150 // cleaned up. | |
| 151 private: | |
| 152 #endif | |
| 153 enum Deprecated_RecordingFlags { | |
| 154 /* This flag causes the picture to compute bounding boxes and build | |
| 155 up a spatial hierarchy (currently an R-Tree), plus a tree of Canvas' | |
| 156 usually stack-based clip/etc state. This requires an increase in | |
| 157 recording time (often ~2x; likely more for very complex pictures), | |
| 158 but allows us to perform much faster culling at playback time, and | |
| 159 completely avoid some unnecessary clips and other operations. This | |
| 160 is ideal for tiled rendering, or any other situation where you're | |
| 161 drawing a fraction of a large scene into a smaller viewport. | |
| 162 | |
| 163 In most cases the record cost is offset by the playback improvement | |
| 164 after a frame or two of tiled rendering (and complex pictures that | |
| 165 induce the worst record times will generally get the largest | |
| 166 speedups at playback time). | |
| 167 | |
| 168 Note: Currently this is not serializable, the bounding data will be | |
| 169 discarded if you serialize into a stream and then deserialize. | |
| 170 */ | |
| 171 kOptimizeForClippedPlayback_RecordingFlag = 0x02, | |
| 172 }; | |
| 173 #ifndef SK_SUPPORT_DEPRECATED_RECORD_FLAGS | |
| 174 public: | |
| 175 #endif | |
| 176 | |
| 177 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD | |
| 178 private: | |
| 179 #endif | |
| 180 | |
| 181 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES | |
| 182 | |
| 183 /** Returns the canvas that records the drawing commands. | |
| 184 @param width the base width for the picture, as if the recording | |
| 185 canvas' bitmap had this width. | |
| 186 @param height the base width for the picture, as if the recording | |
| 187 canvas' bitmap had this height. | |
| 188 @param recordFlags optional flags that control recording. | |
| 189 @return the picture canvas. | |
| 190 */ | |
| 191 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0); | |
| 192 #endif | |
| 193 | |
| 194 /** Returns the recording canvas if one is active, or NULL if recording is | |
| 195 not active. This does not alter the refcnt on the canvas (if present). | |
| 196 */ | |
| 197 SkCanvas* getRecordingCanvas() const; | |
| 198 /** Signal that the caller is done recording. This invalidates the canvas | |
| 199 returned by beginRecording/getRecordingCanvas, and prepares the picture | |
| 200 for drawing. Note: this happens implicitly the first time the picture | |
| 201 is drawn. | |
| 202 */ | |
| 203 void endRecording(); | |
| 204 | |
| 205 #ifndef SK_SUPPORT_LEGACY_PICTURE_CAN_RECORD | |
| 206 public: | |
| 207 #endif | |
| 208 | |
| 209 /** Replays the drawing commands on the specified canvas. This internally | 150 /** Replays the drawing commands on the specified canvas. This internally |
| 210 calls endRecording() if that has not already been called. | 151 calls endRecording() if that has not already been called. |
| 211 @param canvas the canvas receiving the drawing commands. | 152 @param canvas the canvas receiving the drawing commands. |
| 212 */ | 153 */ |
| 213 void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL); | 154 void draw(SkCanvas* canvas, SkDrawPictureCallback* = NULL); |
| 214 | 155 |
| 215 /** Return the width of the picture's recording canvas. This | 156 /** Return the width of the picture's recording canvas. This |
| 216 value reflects what was passed to setSize(), and does not necessarily | 157 value reflects what was passed to setSize(), and does not necessarily |
| 217 reflect the bounds of what has been recorded into the picture. | 158 reflect the bounds of what has been recorded into the picture. |
| 218 @return the width of the picture's recording canvas | 159 @return the width of the picture's recording canvas |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 SkPictureRecord* fRecord; | 287 SkPictureRecord* fRecord; |
| 347 int fWidth, fHeight; | 288 int fWidth, fHeight; |
| 348 const AccelData* fAccelData; | 289 const AccelData* fAccelData; |
| 349 | 290 |
| 350 void needsNewGenID() { fUniqueID = SK_InvalidGenID; } | 291 void needsNewGenID() { fUniqueID = SK_InvalidGenID; } |
| 351 | 292 |
| 352 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of | 293 // Create a new SkPicture from an existing SkPicturePlayback. Ref count of |
| 353 // playback is unchanged. | 294 // playback is unchanged. |
| 354 SkPicture(SkPicturePlayback*, int width, int height); | 295 SkPicture(SkPicturePlayback*, int width, int height); |
| 355 | 296 |
| 356 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES | |
| 357 // For testing. Derived classes may instantiate an alternate | |
| 358 // SkBBoxHierarchy implementation | |
| 359 virtual SkBBoxHierarchy* createBBoxHierarchy() const; | |
| 360 #endif | |
| 361 | |
| 362 SkCanvas* beginRecording(int width, int height, SkBBHFactory* factory, uint3 2_t recordFlags); | |
| 363 | |
| 364 private: | 297 private: |
| 365 friend class SkPictureRecord; | 298 friend class SkPictureRecord; |
| 366 friend class SkPictureTester; // for unit testing | 299 friend class SkPictureTester; // for unit testing |
| 367 | 300 |
| 368 SkAutoTUnref<SkPathHeap> fPathHeap; // reference counted | 301 SkAutoTUnref<SkPathHeap> fPathHeap; // reference counted |
| 369 | 302 |
| 370 // ContentInfo is not serialized! It is intended solely for use | 303 // ContentInfo is not serialized! It is intended solely for use |
| 371 // with suitableForGpuRasterization. | 304 // with suitableForGpuRasterization. |
| 372 class ContentInfo { | 305 class ContentInfo { |
| 373 public: | 306 public: |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 bool deepCopy); | 412 bool deepCopy); |
| 480 | 413 |
| 481 friend class SkFlatPicture; | 414 friend class SkFlatPicture; |
| 482 friend class SkPicturePlayback; | 415 friend class SkPicturePlayback; |
| 483 friend class SkPictureRecorder; | 416 friend class SkPictureRecorder; |
| 484 friend class SkGpuDevice; | 417 friend class SkGpuDevice; |
| 485 friend class GrGatherCanvas; | 418 friend class GrGatherCanvas; |
| 486 friend class GrGatherDevice; | 419 friend class GrGatherDevice; |
| 487 friend class SkDebugCanvas; | 420 friend class SkDebugCanvas; |
| 488 | 421 |
| 422 // TODO: beginRecording, getRecordingCanvas & endRecording can now be | |
| 423 // be moved out of SkPicture (and, presumably, be directly implemented | |
| 424 // in SkPictureRecorder) | |
| 425 | |
| 426 /** Returns the canvas that records the drawing commands. | |
| 427 @param width the base width for the picture, as if the recording | |
| 428 canvas' bitmap had this width. | |
| 429 @param height the base width for the picture, as if the recording | |
| 430 canvas' bitmap had this height. | |
| 431 @param factory if non-NULL, the factory used to the BBH for the recorded picture | |
| 432 @param recordFlags optional flags that control recording. | |
| 433 @return the picture canvas. | |
| 434 */ | |
| 435 SkCanvas* beginRecording(int width, int height, SkBBHFactory* factory, uint3 2_t recordFlags); | |
| 436 /** Returns the recording canvas if one is active, or NULL if recording is | |
| 437 not active. This does not alter the refcnt on the canvas (if present). | |
| 438 */ | |
| 439 SkCanvas* getRecordingCanvas() const; | |
| 440 /** Signal that the caller is done recording. This invalidates the canvas | |
| 441 returned by beginRecording/getRecordingCanvas, and prepares the picture | |
| 442 for drawing. Note: this happens implicitly the first time the picture | |
| 443 is drawn. | |
| 444 */ | |
| 445 void endRecording(); | |
| 446 | |
| 489 typedef SkRefCnt INHERITED; | 447 typedef SkRefCnt INHERITED; |
| 490 }; | 448 }; |
| 491 | 449 |
| 492 /** | 450 /** |
| 493 * Subclasses of this can be passed to canvas.drawPicture. During the drawing | 451 * Subclasses of this can be passed to canvas.drawPicture. During the drawing |
| 494 * of the picture, this callback will periodically be invoked. If its | 452 * of the picture, this callback will periodically be invoked. If its |
| 495 * abortDrawing() returns true, then picture playback will be interrupted. | 453 * abortDrawing() returns true, then picture playback will be interrupted. |
| 496 * | 454 * |
| 497 * The resulting drawing is undefined, as there is no guarantee how often the | 455 * The resulting drawing is undefined, as there is no guarantee how often the |
| 498 * callback will be invoked. If the abort happens inside some level of nested | 456 * callback will be invoked. If the abort happens inside some level of nested |
| 499 * calls to save(), restore will automatically be called to return the state | 457 * calls to save(), restore will automatically be called to return the state |
| 500 * to the same level it was before the drawPicture call was made. | 458 * to the same level it was before the drawPicture call was made. |
| 501 */ | 459 */ |
| 502 class SK_API SkDrawPictureCallback { | 460 class SK_API SkDrawPictureCallback { |
| 503 public: | 461 public: |
| 504 SkDrawPictureCallback() {} | 462 SkDrawPictureCallback() {} |
| 505 virtual ~SkDrawPictureCallback() {} | 463 virtual ~SkDrawPictureCallback() {} |
| 506 | 464 |
| 507 virtual bool abortDrawing() = 0; | 465 virtual bool abortDrawing() = 0; |
| 508 }; | 466 }; |
| 509 | 467 |
| 510 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES | |
| 511 | |
| 512 class SkPictureFactory : public SkRefCnt { | |
| 513 public: | |
| 514 /** | |
| 515 * Allocate a new SkPicture. Return NULL on failure. | |
| 516 */ | |
| 517 virtual SkPicture* create(int width, int height) = 0; | |
| 518 | |
| 519 private: | |
| 520 typedef SkRefCnt INHERITED; | |
| 521 }; | |
| 522 | |
| 523 #endif | 468 #endif |
| 524 | |
| 525 #ifdef SK_SUPPORT_LEGACY_PICTURE_HEADERS | |
| 526 #include "SkPictureRecorder.h" | |
| 527 #endif | |
| 528 | |
| 529 #endif | |
| OLD | NEW |