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