Flutter Engine
The Flutter Engine
Public Member Functions | Friends | List of all members
SkPictureRecorder Class Reference

#include <SkPictureRecorder.h>

Public Member Functions

 SkPictureRecorder ()
 
 ~SkPictureRecorder ()
 
SkCanvasbeginRecording (const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
 
SkCanvasbeginRecording (const SkRect &bounds, SkBBHFactory *bbhFactory=nullptr)
 
SkCanvasbeginRecording (SkScalar width, SkScalar height, SkBBHFactory *bbhFactory=nullptr)
 
SkCanvasgetRecordingCanvas ()
 
sk_sp< SkPicturefinishRecordingAsPicture ()
 
sk_sp< SkPicturefinishRecordingAsPictureWithCull (const SkRect &cullRect)
 
sk_sp< SkDrawablefinishRecordingAsDrawable ()
 

Friends

class SkPictureRecorderReplayTester
 

Detailed Description

Definition at line 32 of file SkPictureRecorder.h.

Constructor & Destructor Documentation

◆ SkPictureRecorder()

SkPictureRecorder::SkPictureRecorder ( )

Definition at line 28 of file SkPictureRecorder.cpp.

28 {
29 fActivelyRecording = false;
30 fRecorder = std::make_unique<SkRecorder>(nullptr, SkRect::MakeEmpty());
31}
static constexpr SkRect MakeEmpty()
Definition: SkRect.h:595

◆ ~SkPictureRecorder()

SkPictureRecorder::~SkPictureRecorder ( )

Definition at line 33 of file SkPictureRecorder.cpp.

33{}

Member Function Documentation

◆ beginRecording() [1/3]

SkCanvas * SkPictureRecorder::beginRecording ( const SkRect bounds,
sk_sp< SkBBoxHierarchy bbh 
)

Returns the canvas that records the drawing commands.

Parameters
boundsthe cull rect used when recording this picture. Any drawing the falls outside of this rect is undefined, and may be drawn or it may not.
bbhoptional acceleration structure
recordFlagsoptional flags that control recording.
Returns
the canvas.

Definition at line 35 of file SkPictureRecorder.cpp.

36 {
37 const SkRect cullRect = userCullRect.isEmpty() ? SkRect::MakeEmpty() : userCullRect;
38
39 fCullRect = cullRect;
40 fBBH = std::move(bbh);
41
42 if (!fRecord) {
43 fRecord.reset(new SkRecord);
44 }
45 fRecorder->reset(fRecord.get(), cullRect);
46 fActivelyRecording = true;
47 return this->getRecordingCanvas();
48}
SkCanvas * getRecordingCanvas()
T * get() const
Definition: SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
bool isEmpty() const
Definition: SkRect.h:693

◆ beginRecording() [2/3]

SkCanvas * SkPictureRecorder::beginRecording ( const SkRect bounds,
SkBBHFactory bbhFactory = nullptr 
)

Definition at line 50 of file SkPictureRecorder.cpp.

50 {
51 return this->beginRecording(bounds, factory ? (*factory)() : nullptr);
52}
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)

◆ beginRecording() [3/3]

SkCanvas * SkPictureRecorder::beginRecording ( SkScalar  width,
SkScalar  height,
SkBBHFactory bbhFactory = nullptr 
)
inline

Definition at line 48 of file SkPictureRecorder.h.

49 {
50 return this->beginRecording(SkRect::MakeWH(width, height), bbhFactory);
51 }
int32_t height
int32_t width
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ finishRecordingAsDrawable()

sk_sp< SkDrawable > SkPictureRecorder::finishRecordingAsDrawable ( )

Signal that the caller is done recording. This invalidates the canvas returned by beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who must call unref() when they are done using it.

Unlike finishRecordingAsPicture(), which returns an immutable picture, the returned drawable may contain live references to other drawables (if they were added to the recording canvas) and therefore this drawable will reflect the current state of those nested drawables anytime it is drawn or a new picture is snapped from it (by calling drawable->makePictureSnapshot()).

Definition at line 132 of file SkPictureRecorder.cpp.

132 {
133 fActivelyRecording = false;
134 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
135
136 SkRecordOptimize(fRecord.get());
137
138 if (fBBH) {
139 AutoTArray<SkRect> bounds(fRecord->count());
141 SkRecordFillBounds(fCullRect, *fRecord, bounds.data(), meta);
142 fBBH->insert(bounds.data(), meta, fRecord->count());
143 }
144
145 sk_sp<SkDrawable> drawable =
146 sk_make_sp<SkRecordedDrawable>(std::move(fRecord), std::move(fBBH),
147 fRecorder->detachDrawableList(), fCullRect);
148
149 return drawable;
150}
void SkRecordFillBounds(const SkRect &cullRect, const SkRecord &record, SkRect bounds[], SkBBoxHierarchy::Metadata meta[])
void SkRecordOptimize(SkRecord *record)
virtual void insert(const SkRect[], int N)=0
int count() const
Definition: SkRecord.h:38
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ finishRecordingAsPicture()

sk_sp< SkPicture > SkPictureRecorder::finishRecordingAsPicture ( )

Signal that the caller is done recording. This invalidates the canvas returned by beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who must call unref() when they are done using it.

The returned picture is immutable. If during recording drawables were added to the canvas, these will have been "drawn" into a recording canvas, so that this resulting picture will reflect their current state, but will not contain a live reference to the drawables themselves.

Definition at line 67 of file SkPictureRecorder.cpp.

67 {
68 fActivelyRecording = false;
69 fRecorder->restoreToCount(1); // If we were missing any restores, add them now.
70
71 if (fRecord->count() == 0) {
72 return sk_make_sp<SkEmptyPicture>();
73 }
74
75 // TODO: delay as much of this work until just before first playback?
76 SkRecordOptimize(fRecord.get());
77
78 SkDrawableList* drawableList = fRecorder->getDrawableList();
79 std::unique_ptr<SkBigPicture::SnapshotArray> pictList{
80 drawableList ? drawableList->newDrawableSnapshot() : nullptr
81 };
82
83 if (fBBH) {
86 SkRecordFillBounds(fCullRect, *fRecord, bounds.data(), meta);
87
88 fBBH->insert(bounds.data(), meta, fRecord->count());
89
90 // Now that we've calculated content bounds, we can update fCullRect, often trimming it.
91 SkRect bbhBound = SkRect::MakeEmpty();
92 for (int i = 0; i < fRecord->count(); i++) {
93 bbhBound.join(bounds[i]);
94 }
95 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound))
96 || (bbhBound.isEmpty() && fCullRect.isEmpty()));
97 fCullRect = bbhBound;
98 }
99
100 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures();
101 for (int i = 0; pictList && i < pictList->count(); i++) {
102 subPictureBytes += pictList->begin()[i]->approximateBytesUsed();
103 }
104 return sk_make_sp<SkBigPicture>(fCullRect,
105 std::move(fRecord),
106 std::move(pictList),
107 std::move(fBBH),
108 subPictureBytes);
109}
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBigPicture::SnapshotArray * newDrawableSnapshot()
Definition: SkRecorder.cpp:62
bool contains(SkScalar x, SkScalar y) const
Definition: extension.cpp:19
void join(const SkRect &r)
Definition: SkRect.cpp:126

◆ finishRecordingAsPictureWithCull()

sk_sp< SkPicture > SkPictureRecorder::finishRecordingAsPictureWithCull ( const SkRect cullRect)

Signal that the caller is done recording, and update the cull rect to use for bounding box hierarchy (BBH) generation. The behavior is the same as calling finishRecordingAsPicture(), except that this method updates the cull rect initially passed into beginRecording.

Parameters
cullRectthe new culling rectangle to use as the overall bound for BBH generation and subsequent culling operations.
Returns
the picture containing the recorded content.

Definition at line 111 of file SkPictureRecorder.cpp.

111 {
112 fCullRect = cullRect;
113 return this->finishRecordingAsPicture();
114}
sk_sp< SkPicture > finishRecordingAsPicture()

◆ getRecordingCanvas()

SkCanvas * SkPictureRecorder::getRecordingCanvas ( )

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).

Definition at line 54 of file SkPictureRecorder.cpp.

54 {
55 return fActivelyRecording ? fRecorder.get() : nullptr;
56}

Friends And Related Function Documentation

◆ SkPictureRecorderReplayTester

friend class SkPictureRecorderReplayTester
friend

Replay the current (partially recorded) operation stream into canvas. This call doesn't close the current recording.

Definition at line 102 of file SkPictureRecorder.h.


The documentation for this class was generated from the following files: