| 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:"
90 << "[" << paint.color_source << "]" << std::endl;
91 os << " dither: [" << paint.dither << "]" << std::endl;
92 os << " stroke_width: [" << paint.stroke_width << "]" << std::endl;
93 os << " stroke_cap: "
94 << "[Paint::Cap]" << std::endl;
95 os << " stroke_join: "
96 << "[Paint::Join]" << std::endl;
97 os << " stroke_miter: [" << paint.stroke_miter << "]" << std::endl;
98 os << " style:"
99 << "[Paint::Style]" << std::endl;
100 os << " blend_mode: [" << BlendModeToString(paint.blend_mode) << "]"
101 << std::endl;
102 os << " invert_colors: [" << paint.invert_colors << "]" << std::endl;
103 os << " image_filter: " << paint.image_filter << std::endl;
104 os << " color_filter: " << paint.color_filter << std::endl;
105 os << " mask_blur_descriptor: "
106 << "[std::optional<MaskBlurDescriptor>]" << std::endl;
107 os << "}";
108 return os;
109 }
110 } // namespace
111
112 #define FLT_CANVAS_RECORDER_OP_TO_STRING(name) \
113 case CanvasRecorderOp::name: \
114 return #name
115
116 namespace {
117 std::string_view CanvasRecorderOpToString(CanvasRecorderOp op) {
118 switch (op) {
119 FLT_CANVAS_RECORDER_OP_TO_STRING(kNew);
120 FLT_CANVAS_RECORDER_OP_TO_STRING(kSave);
121 FLT_CANVAS_RECORDER_OP_TO_STRING(kSaveLayer);
122 FLT_CANVAS_RECORDER_OP_TO_STRING(kRestore);
123 FLT_CANVAS_RECORDER_OP_TO_STRING(kRestoreToCount);
124 FLT_CANVAS_RECORDER_OP_TO_STRING(kResetTransform);
125 FLT_CANVAS_RECORDER_OP_TO_STRING(kTransform);
126 FLT_CANVAS_RECORDER_OP_TO_STRING(kConcat);
127 FLT_CANVAS_RECORDER_OP_TO_STRING(kPreConcat);
128 FLT_CANVAS_RECORDER_OP_TO_STRING(kTranslate);
129 FLT_CANVAS_RECORDER_OP_TO_STRING(kScale2);
130 FLT_CANVAS_RECORDER_OP_TO_STRING(kScale3);
131 FLT_CANVAS_RECORDER_OP_TO_STRING(kSkew);
132 FLT_CANVAS_RECORDER_OP_TO_STRING(kRotate);
133 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPath);
134 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPaint);
135 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawRect);
136 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawRRect);
137 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawCircle);
138 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPoints);
139 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawImage);
140 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawImageRect);
141 FLT_CANVAS_RECORDER_OP_TO_STRING(kClipPath);
142 FLT_CANVAS_RECORDER_OP_TO_STRING(kClipRect);
143 FLT_CANVAS_RECORDER_OP_TO_STRING(kClipRRect);
144 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawPicture);
145 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawTextFrame);
146 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawVertices);
147 FLT_CANVAS_RECORDER_OP_TO_STRING(kDrawAtlas);
148 }
149 }
150 } // namespace
151
152 TraceSerializer::TraceSerializer() {}
153
154 void TraceSerializer::Write(CanvasRecorderOp op) {
155 if (op == CanvasRecorderOp::kNew) {
156 FML_LOG(ERROR) << "######################################################";
157 } else {
158 FML_LOG(ERROR) << CanvasRecorderOpToString(op) << ":" << buffer_.str();
159 buffer_.str("");
160 buffer_.clear();
161 }
162 }
163
164 void TraceSerializer::Write(const Paint& paint) {
165 buffer_ << "[" << paint << "] ";
166 }
167
168 void TraceSerializer::Write(const std::optional<Rect> optional_rect) {
169 if (optional_rect.has_value()) {
170 buffer_ << "[" << optional_rect.value() << "] ";
171 } else {
172 buffer_ << "[None] ";
173 }
174 }
175
176 void TraceSerializer::Write(const std::shared_ptr<ImageFilter>& image_filter) {
177 buffer_ << image_filter << " ";
178 }
179
180 void TraceSerializer::Write(size_t size) {
181 buffer_ << "[" << size << "] ";
182 }
183
184 void TraceSerializer::Write(const Matrix& matrix) {
185 buffer_ << "[" << matrix << "] ";
186 }
187
188 void TraceSerializer::Write(const Vector3& vec3) {
189 buffer_ << "[" << vec3 << "] ";
190 }
191
192 void TraceSerializer::Write(const Vector2& vec2) {
193 buffer_ << "[" << vec2 << "] ";
194 }
195
196 void TraceSerializer::Write(const Radians& radians) {
197 buffer_ << "[" << radians.radians << "] ";
198 }
199
200 void TraceSerializer::Write(const Path& path) {
201 buffer_ << "[Path] ";
202 }
203
204 void TraceSerializer::Write(const std::vector<Point>& points) {
205 buffer_ << "[std::vector<Point>] ";
206 }
207
208 void TraceSerializer::Write(const PointStyle& point_style) {
209 buffer_ << "[PointStyle] ";
210 }
211
212 void TraceSerializer::Write(const std::shared_ptr<Image>& image) {
213 buffer_ << "[std::shared_ptr<Image>] ";
214 }
215
216 void TraceSerializer::Write(const SamplerDescriptor& sampler) {
217 buffer_ << "[SamplerDescriptor] ";
218 }
219
220 void TraceSerializer::Write(const Entity::ClipOperation& clip_op) {
221 switch (clip_op) {
222 case Entity::ClipOperation::kDifference:
223 buffer_ << "[kDifference] ";
224 break;
225 case Entity::ClipOperation::kIntersect:
226 buffer_ << "[kIntersect] ";
227 break;
228 }
229 }
230
231 void TraceSerializer::Write(const Picture& clip_op) {
232 buffer_ << "[Picture] ";
233 }
234
235 void TraceSerializer::Write(const std::shared_ptr<TextFrame>& text_frame) {
236 buffer_ << "[std::shared_ptr<TextFrame>] ";
237 }
238
239 void TraceSerializer::Write(const std::shared_ptr<VerticesGeometry>& vertices) {
240 buffer_ << "[std::shared_ptr<VerticesGeometry>] ";
241 }
242
243 void TraceSerializer::Write(const BlendMode& blend_mode) {
244 buffer_ << "[" << BlendModeToString(blend_mode) << "] ";
245 }
246
247 void TraceSerializer::Write(const std::vector<Matrix>& matrices) {
248 buffer_ << "[std::vector<Matrix>] ";
249 }
250
251 void TraceSerializer::Write(const std::vector<Rect>& matrices) {
252 buffer_ << "[std::vector<Rect>] ";
253 }
254
255 void TraceSerializer::Write(const std::vector<Color>& matrices) {
256 buffer_ << "[std::vector<Color>] ";
257 }
258 } // 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:40
impeller::BlendModeToString
const char * BlendModeToString(BlendMode blend_mode)
Definition: color.cc:47
impeller::kClipPath
@ kClipPath
Definition: canvas_recorder.h:42
impeller::Entity::ClipOperation::kDifference
@ kDifference
trace_serializer.h
impeller::kConcat
@ kConcat
Definition: canvas_recorder.h:27
impeller::ColorSource::Type::kRadialGradient
@ kRadialGradient
impeller::kDrawPicture
@ kDrawPicture
Definition: canvas_recorder.h:45
impeller::Paint
Definition: paint.h:22
impeller::BlendMode
BlendMode
Definition: color.h:59
impeller::PointStyle
PointStyle
Definition: canvas.h:40
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::Radians::radians
Scalar radians
Definition: scalar.h:39
impeller::kSave
@ kSave
Definition: canvas_recorder.h:21
impeller::kDrawCircle
@ kDrawCircle
Definition: canvas_recorder.h:38
impeller::SamplerDescriptor
Definition: sampler_descriptor.h:15
impeller::Picture
Definition: picture.h:20
impeller::kDrawTextFrame
@ kDrawTextFrame
Definition: canvas_recorder.h:46
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:55
impeller::ColorSource::Type::kRuntimeEffect
@ kRuntimeEffect
impeller::kDrawRect
@ kDrawRect
Definition: canvas_recorder.h:36
impeller::kSkew
@ kSkew
Definition: canvas_recorder.h:32
impeller::kClipRRect
@ kClipRRect
Definition: canvas_recorder.h:44
impeller::Radians
Definition: scalar.h:38
impeller::kDrawImageRect
@ kDrawImageRect
Definition: canvas_recorder.h:41
FLT_CANVAS_RECORDER_OP_TO_STRING
#define FLT_CANVAS_RECORDER_OP_TO_STRING(name)
Definition: trace_serializer.cc:112
impeller::kTransform
@ kTransform
Definition: canvas_recorder.h:26
impeller::kDrawAtlas
@ kDrawAtlas
Definition: canvas_recorder.h:48
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:39
impeller::TPoint< Scalar >
impeller::Entity::ClipOperation
ClipOperation
Definition: entity.h:59
impeller::kScale3
@ kScale3
Definition: canvas_recorder.h:31
impeller::kDrawVertices
@ kDrawVertices
Definition: canvas_recorder.h:47
impeller::ColorSource::Type::kSweepGradient
@ kSweepGradient
impeller::kDrawPath
@ kDrawPath
Definition: canvas_recorder.h:34
impeller::kDrawRRect
@ kDrawRRect
Definition: canvas_recorder.h:37
impeller::TraceSerializer::TraceSerializer
TraceSerializer()
Definition: trace_serializer.cc:152
impeller
Definition: aiks_context.cc:10
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:43
impeller::TraceSerializer::Write
void Write(CanvasRecorderOp op)
Definition: trace_serializer.cc:154
impeller::kRestoreToCount
@ kRestoreToCount
Definition: canvas_recorder.h:24