 |
Flutter Impeller
|
|
Go to the documentation of this file.
8 #include <initializer_list>
11 #include <type_traits>
12 #include <unordered_map>
13 #include <unordered_set>
16 #include "flutter/fml/logging.h"
17 #include "flutter/fml/macros.h"
27 struct CaptureProcTable;
29 #define _FOR_EACH_CAPTURE_PROPERTY(PROPERTY_V) \
30 PROPERTY_V(bool, Boolean, boolean) \
31 PROPERTY_V(int, Integer, integer) \
32 PROPERTY_V(Scalar, Scalar, scalar) \
33 PROPERTY_V(Point, Point, point) \
34 PROPERTY_V(Vector3, Vector3, vector3) \
35 PROPERTY_V(Rect, Rect, rect) \
36 PROPERTY_V(Color, Color, color) \
37 PROPERTY_V(Matrix, Matrix, matrix) \
38 PROPERTY_V(std::string, String, string)
40 template <
typename Type>
61 #define _CAPTURE_TYPE(type_name, pascal_name, lower_name) k##pascal_name,
63 #define _CAPTURE_PROPERTY_CAST_DECLARATION(type_name, pascal_name, lower_name) \
64 std::optional<type_name> As##pascal_name() const;
101 #define _CAPTURE_PROPERTY_DECLARATION(type_name, pascal_name, lower_name) \
102 struct Capture##pascal_name##Property final : public CaptureProperty { \
105 static std::shared_ptr<Capture##pascal_name##Property> \
106 Make(const std::string& label, type_name value, Options options); \
109 Type GetType() const override; \
112 void Invoke(const CaptureProcTable& proc_table) override; \
115 Capture##pascal_name##Property(const std::string& label, \
119 FML_DISALLOW_COPY_AND_ASSIGN(Capture##pascal_name##Property); \
124 #define _CAPTURE_PROC(type_name, pascal_name, lower_name) \
125 std::function<void(Capture##pascal_name##Property&)> lower_name = \
126 [](Capture##pascal_name##Property& value) {};
132 template <
typename Type>
147 size_t Count() {
return values_.size(); }
149 std::shared_ptr<Type>
GetNext(std::shared_ptr<Type> captured,
150 bool force_overwrite) {
151 if (cursor_ < values_.size()) {
152 std::shared_ptr<Type>& result = values_[cursor_];
154 if (result->MatchesCloselyEnough(*captured)) {
155 if (force_overwrite) {
156 values_[cursor_] = captured;
164 values_.resize(cursor_);
168 values_.push_back(captured);
173 for (std::shared_ptr<Type>& value : values_) {
174 if (value->label == label) {
181 void Iterate(std::function<
void(Type&)> iterator)
const {
182 for (
auto& value : values_) {
189 std::vector<std::shared_ptr<Type>> values_;
200 static std::shared_ptr<CaptureElement>
Make(
const std::string&
label);
212 #ifdef IMPELLER_ENABLE_CAPTURE
213 #define _CAPTURE_PROPERTY_RECORDER_DECLARATION(type_name, pascal_name, \
215 type_name Add##pascal_name(const std::string& label, type_name value, \
216 CaptureProperty::Options options = {});
218 #define _CAPTURE_PROPERTY_RECORDER_DECLARATION(type_name, pascal_name, \
220 inline type_name Add##pascal_name(const std::string& label, type_name value, \
221 CaptureProperty::Options options = {}) { \
228 explicit Capture(
const std::string& label);
235 #ifdef IMPELLER_ENABLE_CAPTURE
240 auto new_capture =
Capture(label);
241 new_capture.element_ =
242 element_->children.GetNext(new_capture.element_,
false);
243 new_capture.element_->Rewind();
250 std::shared_ptr<CaptureElement>
GetElement()
const;
257 #ifdef IMPELLER_ENABLE_CAPTURE
258 std::shared_ptr<CaptureElement> element_;
259 bool active_ =
false;
270 std::initializer_list<std::string> allowlist);
281 struct InactiveFlag {};
285 #ifdef IMPELLER_ENABLE_CAPTURE
286 bool active_ =
false;
287 std::optional<std::unordered_set<std::string>> allowlist_;
288 std::unordered_map<std::string, Capture> documents_;
std::shared_ptr< Type > GetNext(std::shared_ptr< Type > captured, bool force_overwrite)
virtual bool MatchesCloselyEnough(const Type &other) const =0
Determines if previously captured data matches closely enough with newly recorded data to safely emit...
Capture CreateChild(const std::string &label)
#define _CAPTURE_PROC(type_name, pascal_name, lower_name)
void Iterate(std::function< void(Type &)> iterator) const
static Capture MakeInactive()
std::shared_ptr< Type > FindFirstByLabel(const std::string &label)
std::shared_ptr< CaptureElement > GetElement() const
CaptureCursorListElement(const std::string &label)
static CaptureContext MakeAllowlist(std::initializer_list< std::string > allowlist)
bool MatchesCloselyEnough(const CaptureElement &other) const override
Determines if previously captured data matches closely enough with newly recorded data to safely emit...
std::optional< Range > range
virtual void Invoke(const CaptureProcTable &proc_table)=0
virtual ~CaptureCursorListElement()=default
bool DoesDocumentExist(const std::string &label) const
_FOR_EACH_CAPTURE_PROPERTY(_CAPTURE_PROPERTY_CAST_DEFINITION)
static std::shared_ptr< CaptureElement > Make(const std::string &label)
#define _CAPTURE_TYPE(type_name, pascal_name, lower_name)
CapturePlaybackList()=default
CapturePlaybackList< CaptureElement > children
static CaptureContext MakeInactive()
bool MatchesCloselyEnough(const CaptureProperty &other) const override
Determines if previously captured data matches closely enough with newly recorded data to safely emit...
CaptureProperty(const std::string &label, Options options)
#define _FOR_EACH_CAPTURE_PROPERTY(PROPERTY_V)
A capturable property type.
#define _CAPTURE_PROPERTY_DECLARATION(type_name, pascal_name, lower_name)
virtual ~CaptureProperty()
@ _FOR_EACH_CAPTURE_PROPERTY
Capture GetDocument(const std::string &label)
#define _CAPTURE_PROPERTY_CAST_DECLARATION(type_name, pascal_name, lower_name)
#define _CAPTURE_PROPERTY_RECORDER_DECLARATION(type_name, pascal_name, lower_name)
CapturePlaybackList< CaptureProperty > properties
virtual Type GetType() const =0