OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkPictureRecorder_DEFINED |
| 9 #define SkPictureRecorder_DEFINED |
| 10 |
| 11 #include "SkBBHFactory.h" |
| 12 #include "SkPicture.h" |
| 13 #include "SkRefCnt.h" |
| 14 |
| 15 class SkCanvas; |
| 16 |
| 17 class SK_API SkPictureRecorder : SkNoncopyable { |
| 18 public: |
| 19 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES |
| 20 |
| 21 SkPictureRecorder(SkPictureFactory* factory = NULL) { |
| 22 fFactory.reset(factory); |
| 23 if (NULL != fFactory.get()) { |
| 24 fFactory.get()->ref(); |
| 25 } |
| 26 } |
| 27 |
| 28 /** Returns the canvas that records the drawing commands. |
| 29 @param width the base width for the picture, as if the recording |
| 30 canvas' bitmap had this width. |
| 31 @param height the base width for the picture, as if the recording |
| 32 canvas' bitmap had this height. |
| 33 @param recordFlags optional flags that control recording. |
| 34 @return the canvas. |
| 35 */ |
| 36 SkCanvas* beginRecording(int width, int height, uint32_t recordFlags = 0) { |
| 37 if (NULL != fFactory) { |
| 38 fPicture.reset(fFactory->create(width, height)); |
| 39 recordFlags |= SkPicture::kOptimizeForClippedPlayback_RecordingFlag; |
| 40 } else { |
| 41 fPicture.reset(SkNEW(SkPicture)); |
| 42 } |
| 43 |
| 44 return fPicture->beginRecording(width, height, recordFlags); |
| 45 } |
| 46 #endif |
| 47 |
| 48 /** Returns the canvas that records the drawing commands. |
| 49 @param width the base width for the picture, as if the recording |
| 50 canvas' bitmap had this width. |
| 51 @param height the base width for the picture, as if the recording |
| 52 canvas' bitmap had this height. |
| 53 @param bbhFactory factory to create desired acceleration structure |
| 54 @param recordFlags optional flags that control recording. |
| 55 @return the canvas. |
| 56 */ |
| 57 // TODO: allow default parameters once the other beginRecoding entry point i
s gone |
| 58 SkCanvas* beginRecording(int width, int height, |
| 59 SkBBHFactory* bbhFactory /* = NULL */, |
| 60 uint32_t recordFlags /* = 0 */); |
| 61 |
| 62 /** Returns the recording canvas if one is active, or NULL if recording is |
| 63 not active. This does not alter the refcnt on the canvas (if present). |
| 64 */ |
| 65 SkCanvas* getRecordingCanvas() { |
| 66 if (NULL != fPicture.get()) { |
| 67 return fPicture->getRecordingCanvas(); |
| 68 } |
| 69 return NULL; |
| 70 } |
| 71 |
| 72 /** Signal that the caller is done recording. This invalidates the canvas |
| 73 returned by beginRecording/getRecordingCanvas, and returns the |
| 74 created SkPicture. Note that the returned picture has its creation |
| 75 ref which the caller must take ownership of. |
| 76 */ |
| 77 SkPicture* endRecording() { |
| 78 if (NULL != fPicture.get()) { |
| 79 fPicture->endRecording(); |
| 80 return fPicture.detach(); |
| 81 } |
| 82 return NULL; |
| 83 } |
| 84 |
| 85 /** Enable/disable all the picture recording optimizations (i.e., |
| 86 those in SkPictureRecord). It is mainly intended for testing the |
| 87 existing optimizations (i.e., to actually have the pattern |
| 88 appear in an .skp we have to disable the optimization). Call right |
| 89 after 'beginRecording'. |
| 90 */ |
| 91 void internalOnly_EnableOpts(bool enableOpts) { |
| 92 if (NULL != fPicture.get()) { |
| 93 fPicture->internalOnly_EnableOpts(enableOpts); |
| 94 } |
| 95 } |
| 96 |
| 97 private: |
| 98 #ifdef SK_SUPPORT_LEGACY_DERIVED_PICTURE_CLASSES |
| 99 SkAutoTUnref<SkPictureFactory> fFactory; |
| 100 #endif |
| 101 |
| 102 SkAutoTUnref<SkPicture> fPicture; |
| 103 |
| 104 typedef SkNoncopyable INHERITED; |
| 105 }; |
| 106 |
| 107 #endif |
OLD | NEW |