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