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 "SkCanvas.h" |
12 #include "SkPicture.h" | 13 #include "SkPicture.h" |
13 #include "SkRefCnt.h" | 14 #include "SkRefCnt.h" |
14 | 15 |
15 class SkCanvas; | 16 class SkCanvas; |
16 | 17 |
17 class SK_API SkPictureRecorder : SkNoncopyable { | 18 class SK_API SkPictureRecorder : SkNoncopyable { |
18 public: | 19 public: |
| 20 SkPictureRecorder() { } |
| 21 |
19 /** Returns the canvas that records the drawing commands. | 22 /** Returns the canvas that records the drawing commands. |
20 @param width the base width for the picture, as if the recording | 23 @param width the base width for the picture, as if the recording |
21 canvas' bitmap had this width. | 24 canvas' bitmap had this width. |
22 @param height the base width for the picture, as if the recording | 25 @param height the base width for the picture, as if the recording |
23 canvas' bitmap had this height. | 26 canvas' bitmap had this height. |
24 @param bbhFactory factory to create desired acceleration structure | 27 @param bbhFactory factory to create desired acceleration structure |
25 @param recordFlags optional flags that control recording. | 28 @param recordFlags optional flags that control recording. |
26 @return the canvas. | 29 @return the canvas. |
27 */ | 30 */ |
28 // TODO: allow default parameters once the other beginRecoding entry point i
s gone | 31 // TODO: allow default parameters once the other beginRecoding entry point i
s gone |
29 SkCanvas* beginRecording(int width, int height, | 32 SkCanvas* beginRecording(int width, int height, |
30 SkBBHFactory* bbhFactory /* = NULL */, | 33 SkBBHFactory* bbhFactory /* = NULL */, |
31 uint32_t recordFlags /* = 0 */); | 34 uint32_t recordFlags /* = 0 */); |
32 | 35 |
33 /** Returns the recording canvas if one is active, or NULL if recording is | 36 /** Returns the recording canvas if one is active, or NULL if recording is |
34 not active. This does not alter the refcnt on the canvas (if present). | 37 not active. This does not alter the refcnt on the canvas (if present). |
35 */ | 38 */ |
36 SkCanvas* getRecordingCanvas() { | 39 SkCanvas* getRecordingCanvas() { |
37 if (NULL != fPicture.get()) { | 40 return fCanvas.get(); |
38 return fPicture->getRecordingCanvas(); | |
39 } | |
40 return NULL; | |
41 } | 41 } |
42 | 42 |
43 /** Signal that the caller is done recording. This invalidates the canvas | 43 /** Signal that the caller is done recording. This invalidates the canvas |
44 returned by beginRecording/getRecordingCanvas, and returns the | 44 returned by beginRecording/getRecordingCanvas, and returns the |
45 created SkPicture. Note that the returned picture has its creation | 45 created SkPicture. Note that the returned picture has its creation |
46 ref which the caller must take ownership of. | 46 ref which the caller must take ownership of. |
47 */ | 47 */ |
48 SkPicture* endRecording() { | 48 SkPicture* endRecording(); |
49 if (NULL != fPicture.get()) { | |
50 fPicture->endRecording(); | |
51 return fPicture.detach(); | |
52 } | |
53 return NULL; | |
54 } | |
55 | 49 |
56 /** Enable/disable all the picture recording optimizations (i.e., | 50 /** Enable/disable all the picture recording optimizations (i.e., |
57 those in SkPictureRecord). It is mainly intended for testing the | 51 those in SkPictureRecord). It is mainly intended for testing the |
58 existing optimizations (i.e., to actually have the pattern | 52 existing optimizations (i.e., to actually have the pattern |
59 appear in an .skp we have to disable the optimization). Call right | 53 appear in an .skp we have to disable the optimization). Call right |
60 after 'beginRecording'. | 54 after 'beginRecording'. |
61 */ | 55 */ |
62 void internalOnly_EnableOpts(bool enableOpts) { | 56 void internalOnly_EnableOpts(bool enableOpts); |
63 if (NULL != fPicture.get()) { | |
64 fPicture->internalOnly_EnableOpts(enableOpts); | |
65 } | |
66 } | |
67 | 57 |
68 private: | 58 private: |
69 #ifdef SK_BUILD_FOR_ANDROID | 59 #ifdef SK_BUILD_FOR_ANDROID |
70 /** Replay the current (partially recorded) operation stream into | 60 /** Replay the current (partially recorded) operation stream into |
71 canvas. This call doesn't close the current recording. | 61 canvas. This call doesn't close the current recording. |
72 */ | 62 */ |
73 friend class AndroidPicture; | 63 friend class AndroidPicture; |
74 friend class SkPictureRecorderReplayTester; // for unit testing | 64 friend class SkPictureRecorderReplayTester; // for unit testing |
75 void partialReplay(SkCanvas* canvas) const; | 65 void partialReplay(SkCanvas* canvas) const; |
76 #endif | 66 #endif |
77 | 67 |
78 SkAutoTUnref<SkPicture> fPicture; | 68 SkAutoTUnref<SkPicture> fPicture; |
| 69 SkAutoTUnref<SkCanvas> fCanvas; |
79 | 70 |
80 typedef SkNoncopyable INHERITED; | 71 typedef SkNoncopyable INHERITED; |
81 }; | 72 }; |
82 | 73 |
83 #endif | 74 #endif |
OLD | NEW |