| Flutter Impeller |

trace_serializer.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/aiks/trace_serializer.h"
6 #include "flutter/fml/logging.h"
7
8 namespace impeller {
9
10 namespace {
11
12 class ImageFilterTraceVisitor : public ImageFilterVisitor {
13 public:
14 explicit ImageFilterTraceVisitor(std::ostream& os) : os_(os) {}
15 void Visit(const BlurImageFilter& filter) override {
16 os_ << "BlurImageFilter";
17 }
18 void Visit(const LocalMatrixImageFilter& filter) override {
19 os_ << "LocalMatrixImageFilter";
20 }
21 void Visit(const DilateImageFilter& filter) override {
22 os_ << "DilateImageFilter";
23 }
24 void Visit(const ErodeImageFilter& filter) override {
25 os_ << "ErodeImageFilter";
26 }
27 void Visit(const MatrixImageFilter& filter) override {
28 os_ << "{MatrixImageFilter matrix: " << filter.GetMatrix() << "}";
29 }
30 void Visit(const ComposeImageFilter& filter) override {
31 os_ << "ComposeImageFilter";
32 }
33 void Visit(const ColorImageFilter& filter) override {
34 os_ << "ColorImageFilter";
35 }
36
37 private:
38 std::ostream& os_;
39 };
40
41 std::ostream& operator<<(std::ostream& os,
42 const std::shared_ptr<ImageFilter>& image_filter) {
43 if (image_filter) {
44 os << "[";
45 ImageFilterTraceVisitor visitor(os);
46 image_filter->Visit(visitor);
47 os << "]";
48 } else {
49 os << "[None]";
50 }
51 return os;
52 }
53
54 std::ostream& operator<<(std::ostream& os, const ColorSource& color_source) {
55 os << "{ type: ";
56 switch (color_source.GetType()) {
57 case ColorSource::Type::kColor:
58 os << "kColor";
59 break;
60 case ColorSource::Type::kImage:
61 os << "kImage";
62 break;
63 case ColorSource::Type::kLinearGradient:
64 os << "kLinearGradient";
65 break;
66 case ColorSource::Type::kRadialGradient:
67 os << "kRadialGradient";
68 break;
69 case ColorSource::Type::kConicalGradient:
70 os << "kConicalGradient";
71 break;
72 case ColorSource::Type::kSweepGradient:
73 os << "kSweepGradient";
74 break;
75 case ColorSource::Type::kRuntimeEffect:
76 os << "kRuntimeEffect";
77 break;
78 case ColorSource::Type::kScene:
79 os << "kScene";
80 break;
81 }
82 os << " }";
83 return os;
84 }
85
86 std::ostream& operator<<(std::ostream& os, const Paint& paint) {
87 os << "{" << std::endl;
88 os << " color: [" << paint.color << "]" << std::endl;
89 os << " color_source:" << "[" << paint.color_source << "]" << std::endl;
90 os << " dither: [" << paint.dither << "]" << std::endl;
91 os << " stroke_width: [" << paint.stroke_width << "]" << std::endl;
92 os << " stroke_cap: " << "[Paint::Cap]" << std::endl;
93 os << " stroke_join: " << "[Paint::Join]" << std::endl;
94 os << " stroke_miter: [" << paint.stroke_miter << "]" << std::endl;
95 os << " style:" << "[Paint::Style]" << std::endl;
96 os << " blend_mode: [" << BlendModeToString(paint.blend_mode) << "]"
97 << std::endl;
98 os << " invert_colors: [" << paint.invert_colors << "]" << std::endl;
99 os << " image_filter: " << paint.image_filter << std::endl;
100 os << " color_filter: " << paint.color_filter << std::endl;
101 os << " mask_blur_descriptor: " << "[std::optional<MaskBlurDescriptor>]"
102 << std::endl;
103 os << "}";
104 return os;
105 }
106 } // namespace
107
108 #define FLT_CANVAS_RECORDER_OP_TO_STRING(name) \
109 case CanvasRecorderOp::name: \
110 return #name
111
112 namespace {
113 std::string_view CanvasRecorderOpToString(CanvasRecorderOp op) {
114 switch (op) {
115 FLT_CANVAS_RECORDER_OP_TO_STRING(kNew);
116 FLT_CANVAS_RECORDER_OP_TO_STRING(kSave);
117 FLT_CANVAS_RECORDER_OP_TO_STRING(kSaveLayer);
118 FLT_CANVAS_RECORDER_OP_TO_STRING(kRestore);
119 FLT_CANVAS_RECORDER_OP_TO_STRING(kRestoreToCount);
120 FLT_CANVAS_RECORDER_OP_TO_STRING(kResetTransform);
121 FLT_CANVAS_RECORDER_OP_TO_STRING(kTransform);
122 FLT_CANVAS_RECORDER_OP_TO_STRING(kConcat);
123 FLT_CANVAS_RECORDER_OP_TO_STRING(kPreConcat);
124 FLT_CANVAS_RECORDER_OP_TO_STRING(kTranslate);
125 FLT_CANVAS_RECORDER_OP_TO_STRING(kScale2);
126 FLT_CANVAS_RECORDER_OP_TO_STRING(kScale3);
127 FLT_CANVAS_RECORDER_OP_TO_STRING(kSkew);
128 FLT_CANVAS_RECORDER_OP_TO_STRING(kRotate);
129 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPath);
130 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPaint);
131 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawLine);
132 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawRect);
133 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawOval);
134 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawRRect);
135 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawCircle);
136 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPoints);
137 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawImage);
138 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawImageRect);
139 FLT_CANVAS_RECORDER_OP_TO_STRING(kClipPath);
140 FLT_CANVAS_RECORDER_OP_TO_STRING(kClipRect);
141 FLT_CANVAS_RECORDER_OP_TO_STRING(kClipOval);
142 FLT_CANVAS_RECORDER_OP_TO_STRING(kClipRRect);
143 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawTextFrame);
144 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawVertices);
145 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawAtlas);
146 }
147 }
148 } // namespace
149
150 TraceSerializer::TraceSerializer() {}
151
152 void TraceSerializer::Write(CanvasRecorderOp op) {
153 if (op == CanvasRecorderOp::kNew) {
154 FML_LOG(ERROR) << "######################################################";
155 } else {
156 FML_LOG(ERROR) << CanvasRecorderOpToString(op) << ":" << buffer_.str();
157 buffer_.str("");
158 buffer_.clear();
159 }
160 }
161
162 void TraceSerializer::Write(const Paint& paint) {
163 buffer_ << "[" << paint << "] ";
164 }
165
166 void TraceSerializer::Write(const std::optional<Rect> optional_rect) {
167 if (optional_rect.has_value()) {
168 buffer_ << "[" << optional_rect.value() << "] ";
169 } else {
170 buffer_ << "[None] ";
171 }
172 }
173
174 void TraceSerializer::Write(const std::shared_ptr<ImageFilter>& image_filter) {
175 buffer_ << image_filter << " ";
176 }
177
178 void TraceSerializer::Write(size_t size) {
179 buffer_ << "[" << size << "] ";
180 }
181
182 void TraceSerializer::Write(const Matrix& matrix) {
183 buffer_ << "[" << matrix << "] ";
184 }
185
186 void TraceSerializer::Write(const Vector3& vec3) {
187 buffer_ << "[" << vec3 << "] ";
188 }
189
190 void TraceSerializer::Write(const Vector2& vec2) {
191 buffer_ << "[" << vec2 << "] ";
192 }
193
194 void TraceSerializer::Write(const Radians& radians) {
195 buffer_ << "[" << radians.radians << "] ";
196 }
197
198 void TraceSerializer::Write(const Path& path) {
199 buffer_ << "[Path] ";
200 }
201
202 void TraceSerializer::Write(const std::vector<Point>& points) {
203 buffer_ << "[std::vector<Point>] ";
204 }
205
206 void TraceSerializer::Write(const PointStyle& point_style) {
207 buffer_ << "[PointStyle] ";
208 }
209
210 void TraceSerializer::Write(const std::shared_ptr<Image>& image) {
211 buffer_ << "[std::shared_ptr<Image>] ";
212 }
213
214 void TraceSerializer::Write(const SamplerDescriptor& sampler) {
215 buffer_ << "[SamplerDescriptor] ";
216 }
217
218 void TraceSerializer::Write(const Entity::ClipOperation& clip_op) {
219 switch (clip_op) {
220 case Entity::ClipOperation::kDifference:
221 buffer_ << "[kDifference] ";
222 break;
223 case Entity::ClipOperation::kIntersect:
224 buffer_ << "[kIntersect] ";
225 break;
226 }
227 }
228
229 void TraceSerializer::Write(const Picture& clip_op) {
230 buffer_ << "[Picture] ";
231 }
232
233 void TraceSerializer::Write(const std::shared_ptr<TextFrame>& text_frame) {
234 buffer_ << "[std::shared_ptr<TextFrame>] ";
235 }
236
237 void TraceSerializer::Write(const std::shared_ptr<VerticesGeometry>& vertices) {
238 buffer_ << "[std::shared_ptr<VerticesGeometry>] ";
239 }
240
241 void TraceSerializer::Write(const BlendMode& blend_mode) {
242 buffer_ << "[" << BlendModeToString(blend_mode) << "] ";
243 }
244
245 void TraceSerializer::Write(const std::vector<Matrix>& matrices) {
246 buffer_ << "[std::vector<Matrix>] ";
247 }
248
249 void TraceSerializer::Write(const std::vector<Rect>& matrices) {
250 buffer_ << "[std::vector<Rect>] ";
251 }
252
253 void TraceSerializer::Write(const std::vector<Color>& matrices) {
254 buffer_ << "[std::vector<Color>] ";
255 }
256
257 void TraceSerializer::Write(const SourceRectConstraint& src_rect_constraint) {
258 buffer_ << "[SourceRectConstraint] ";
259 }
260
261 void TraceSerializer::Write(const ContentBoundsPromise& promise) {
262 buffer_ << "[SaveLayerBoundsPromise]";
263 }
264
265 } // namespace impeller
impeller::Entity::ClipOperation::kIntersect
@ kIntersect
impeller::kResetTransform
@ kResetTransform
Definition: canvas_recorder.h:25
impeller::ColorSource::Type::kScene
@ kScene
impeller::ColorSource::Type::kLinearGradient
@ kLinearGradient
impeller::kPreConcat
@ kPreConcat
Definition: canvas_recorder.h:28
impeller::kDrawImage
@ kDrawImage
Definition: canvas_recorder.h:42
impeller::BlendModeToString
const char * BlendModeToString(BlendMode blend_mode)
Definition: color.cc:47
impeller::kClipPath
@ kClipPath
Definition: canvas_recorder.h:44
impeller::kClipOval
@ kClipOval
Definition: canvas_recorder.h:46
impeller::Entity::ClipOperation::kDifference
@ kDifference
trace_serializer.h
impeller::kConcat
@ kConcat
Definition: canvas_recorder.h:27
impeller::ColorSource::Type::kRadialGradient
@ kRadialGradient
impeller::Paint
Definition: paint.h:23
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::PointStyle
PointStyle
Definition: canvas.h:41
impeller::kRotate
@ kRotate
Definition: canvas_recorder.h:33
std::operator<<
std::ostream & operator<<(std::ostream &out, const impeller::Color &c)
Definition: color.h:951
impeller::ContentBoundsPromise
ContentBoundsPromise
Definition: entity_pass.h:28
impeller::Radians::radians
Scalar radians
Definition: scalar.h:39
impeller::kSave
@ kSave
Definition: canvas_recorder.h:21
impeller::kDrawCircle
@ kDrawCircle
Definition: canvas_recorder.h:40
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
impeller::Picture
Definition: picture.h:20
impeller::kDrawTextFrame
@ kDrawTextFrame
Definition: canvas_recorder.h:48
impeller::kScale2
@ kScale2
Definition: canvas_recorder.h:30
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:51
impeller::ColorSource::Type::kRuntimeEffect
@ kRuntimeEffect
impeller::kDrawRect
@ kDrawRect
Definition: canvas_recorder.h:37
impeller::kSkew
@ kSkew
Definition: canvas_recorder.h:32
impeller::kClipRRect
@ kClipRRect
Definition: canvas_recorder.h:47
impeller::SourceRectConstraint
SourceRectConstraint
Controls the behavior of the source rectangle given to DrawImageRect.
Definition: canvas.h:50
impeller::Radians
Definition: scalar.h:38
impeller::kDrawImageRect
@ kDrawImageRect
Definition: canvas_recorder.h:43
FLT_CANVAS_RECORDER_OP_TO_STRING
#define FLT_CANVAS_RECORDER_OP_TO_STRING(name)
Definition: trace_serializer.cc:108
impeller::kTransform
@ kTransform
Definition: canvas_recorder.h:26
impeller::kDrawAtlas
@ kDrawAtlas
Definition: canvas_recorder.h:50
impeller::kDrawPaint
@ kDrawPaint
Definition: canvas_recorder.h:35
impeller::kNew
@ kNew
Definition: canvas_recorder.h:20
impeller::kSaveLayer
@ kSaveLayer
Definition: canvas_recorder.h:22
impeller::ColorSource::Type::kImage
@ kImage
impeller::ColorSource::Type::kConicalGradient
@ kConicalGradient
impeller::kDrawPoints
@ kDrawPoints
Definition: canvas_recorder.h:41
impeller::TPoint< Scalar >
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:61
impeller::kDrawOval
@ kDrawOval
Definition: canvas_recorder.h:38
impeller::kScale3
@ kScale3
Definition: canvas_recorder.h:31
impeller::kDrawVertices
@ kDrawVertices
Definition: canvas_recorder.h:49
impeller::ColorSource::Type::kSweepGradient
@ kSweepGradient
impeller::kDrawLine
@ kDrawLine
Definition: canvas_recorder.h:36
impeller::kDrawPath
@ kDrawPath
Definition: canvas_recorder.h:34
impeller::kDrawRRect
@ kDrawRRect
Definition: canvas_recorder.h:39
impeller::TraceSerializer::TraceSerializer
TraceSerializer()
Definition: trace_serializer.cc:150
impeller
Definition: aiks_blur_unittests.cc:20
impeller::kRestore
@ kRestore
Definition: canvas_recorder.h:23
impeller::ColorSource::Type::kColor
@ kColor
impeller::kTranslate
@ kTranslate
Definition: canvas_recorder.h:29
impeller::CanvasRecorderOp
CanvasRecorderOp
Definition: canvas_recorder.h:19
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:37
impeller::Vector3
Definition: vector.h:20
impeller::kClipRect
@ kClipRect
Definition: canvas_recorder.h:45
impeller::TraceSerializer::Write
void Write(CanvasRecorderOp op)
Definition: trace_serializer.cc:152
impeller::kRestoreToCount
@ kRestoreToCount
Definition: canvas_recorder.h:24