Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPictureRecorder.h
Go to the documentation of this file.
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 "include/core/SkRect.h"
15
16#include <memory>
17
18#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
19namespace android {
20 class Picture;
21};
22#endif
23
24class SkBBHFactory;
25class SkBBoxHierarchy;
26class SkCanvas;
27class SkDrawable;
28class SkPicture;
29class SkRecord;
30class SkRecorder;
31
33public:
36
37 /** Returns the canvas that records the drawing commands.
38 @param bounds the cull rect used when recording this picture. Any drawing the falls outside
39 of this rect is undefined, and may be drawn or it may not.
40 @param bbh optional acceleration structure
41 @param recordFlags optional flags that control recording.
42 @return the canvas.
43 */
44 SkCanvas* beginRecording(const SkRect& bounds, sk_sp<SkBBoxHierarchy> bbh);
45
46 SkCanvas* beginRecording(const SkRect& bounds, SkBBHFactory* bbhFactory = nullptr);
47
49 SkBBHFactory* bbhFactory = nullptr) {
50 return this->beginRecording(SkRect::MakeWH(width, height), bbhFactory);
51 }
52
53 /** Returns the recording canvas if one is active, or NULL if recording is
54 not active. This does not alter the refcnt on the canvas (if present).
55 */
56 SkCanvas* getRecordingCanvas();
57
58 /**
59 * Signal that the caller is done recording. This invalidates the canvas returned by
60 * beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who
61 * must call unref() when they are done using it.
62 *
63 * The returned picture is immutable. If during recording drawables were added to the canvas,
64 * these will have been "drawn" into a recording canvas, so that this resulting picture will
65 * reflect their current state, but will not contain a live reference to the drawables
66 * themselves.
67 */
68 sk_sp<SkPicture> finishRecordingAsPicture();
69
70 /**
71 * Signal that the caller is done recording, and update the cull rect to use for bounding
72 * box hierarchy (BBH) generation. The behavior is the same as calling
73 * finishRecordingAsPicture(), except that this method updates the cull rect initially passed
74 * into beginRecording.
75 * @param cullRect the new culling rectangle to use as the overall bound for BBH generation
76 * and subsequent culling operations.
77 * @return the picture containing the recorded content.
78 */
79 sk_sp<SkPicture> finishRecordingAsPictureWithCull(const SkRect& cullRect);
80
81 /**
82 * Signal that the caller is done recording. This invalidates the canvas returned by
83 * beginRecording/getRecordingCanvas. Ownership of the object is passed to the caller, who
84 * must call unref() when they are done using it.
85 *
86 * Unlike finishRecordingAsPicture(), which returns an immutable picture, the returned drawable
87 * may contain live references to other drawables (if they were added to the recording canvas)
88 * and therefore this drawable will reflect the current state of those nested drawables anytime
89 * it is drawn or a new picture is snapped from it (by calling drawable->makePictureSnapshot()).
90 */
91 sk_sp<SkDrawable> finishRecordingAsDrawable();
92
93private:
94 void reset();
95
96 /** Replay the current (partially recorded) operation stream into
97 canvas. This call doesn't close the current recording.
98 */
99#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
100 friend class android::Picture;
101#endif
102 friend class SkPictureRecorderReplayTester; // for unit testing
103 void partialReplay(SkCanvas* canvas) const;
104
105 bool fActivelyRecording;
106 SkRect fCullRect;
108 std::unique_ptr<SkRecorder> fRecorder;
109 sk_sp<SkRecord> fRecord;
110
112 SkPictureRecorder& operator=(SkPictureRecorder&&) = delete;
113};
114
115#endif
m reset()
#define SK_API
Definition SkAPI.h:35
SkCanvas * beginRecording(SkScalar width, SkScalar height, SkBBHFactory *bbhFactory=nullptr)
float SkScalar
Definition extension.cpp:12
SkRTreeFactory bbhFactory
Definition picture.cpp:14
SK_API sk_sp< PrecompileShader > Picture()
int32_t height
int32_t width
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609