| Flutter Impeller |

canvas_recorder_unittests.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 "flutter/testing/testing.h"
6 #include "impeller/aiks/canvas_recorder.h"
7 namespace impeller {
8 namespace testing {
9
10 namespace {
11 class Serializer {
12 public:
13 void Write(CanvasRecorderOp op) { last_op_ = op; }
14
15 void Write(const Paint& paint) {}
16
17 void Write(const std::optional<Rect> optional_rect) {}
18
19 void Write(const std::shared_ptr<ImageFilter>& image_filter) {}
20
21 void Write(size_t size) {}
22
23 void Write(const Matrix& matrix) {}
24
25 void Write(const Vector3& vec3) {}
26
27 void Write(const Vector2& vec2) {}
28
29 void Write(const Radians& vec2) {}
30
31 void Write(const Path& path) {}
32
33 void Write(const std::vector<Point>& points) {}
34
35 void Write(const PointStyle& point_style) {}
36
37 void Write(const std::shared_ptr<Image>& image) {}
38
39 void Write(const SamplerDescriptor& sampler) {}
40
41 void Write(const Entity::ClipOperation& clip_op) {}
42
43 void Write(const Picture& clip_op) {}
44
45 void Write(const std::shared_ptr<TextFrame>& text_frame) {}
46
47 void Write(const std::shared_ptr<VerticesGeometry>& vertices) {}
48
49 void Write(const BlendMode& blend_mode) {}
50
51 void Write(const std::vector<Matrix>& matrices) {}
52
53 void Write(const std::vector<Rect>& matrices) {}
54
55 void Write(const std::vector<Color>& matrices) {}
56
57 void Write(const SourceRectConstraint& src_rect_constraint) {}
58
59 void Write(const ContentBoundsPromise& promise) {}
60
61 CanvasRecorderOp last_op_;
62 };
63 } // namespace
64
65 TEST(CanvasRecorder, Save) {
66 CanvasRecorder<Serializer> recorder;
67 recorder.Save();
68 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kSave);
69 }
70
71 TEST(CanvasRecorder, SaveLayer) {
72 CanvasRecorder<Serializer> recorder;
73 Paint paint;
74 recorder.SaveLayer(paint);
75 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kSaveLayer);
76 }
77
78 TEST(CanvasRecorder, Restore) {
79 CanvasRecorder<Serializer> recorder;
80 recorder.Restore();
81 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kRestore);
82 }
83
84 TEST(CanvasRecorder, RestoreToCount) {
85 CanvasRecorder<Serializer> recorder;
86 recorder.Save();
87 recorder.RestoreToCount(0);
88 ASSERT_EQ(recorder.GetSerializer().last_op_,
89 CanvasRecorderOp::kRestoreToCount);
90 }
91
92 TEST(CanvasRecorder, ResetTransform) {
93 CanvasRecorder<Serializer> recorder;
94 recorder.ResetTransform();
95 ASSERT_EQ(recorder.GetSerializer().last_op_,
96 CanvasRecorderOp::kResetTransform);
97 }
98
99 TEST(CanvasRecorder, Transform) {
100 CanvasRecorder<Serializer> recorder;
101 recorder.Transform(Matrix());
102 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kTransform);
103 }
104
105 TEST(CanvasRecorder, Concat) {
106 CanvasRecorder<Serializer> recorder;
107 recorder.Concat(Matrix());
108 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kConcat);
109 }
110
111 TEST(CanvasRecorder, PreConcat) {
112 CanvasRecorder<Serializer> recorder;
113 recorder.PreConcat(Matrix());
114 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kPreConcat);
115 }
116
117 TEST(CanvasRecorder, Translate) {
118 CanvasRecorder<Serializer> recorder;
119 recorder.Translate(Vector3());
120 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kTranslate);
121 }
122
123 TEST(CanvasRecorder, Scale2) {
124 CanvasRecorder<Serializer> recorder;
125 recorder.Scale(Vector2());
126 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kScale2);
127 }
128
129 TEST(CanvasRecorder, Scale3) {
130 CanvasRecorder<Serializer> recorder;
131 recorder.Scale(Vector3());
132 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kScale3);
133 }
134
135 TEST(CanvasRecorder, Skew) {
136 CanvasRecorder<Serializer> recorder;
137 recorder.Skew(0, 0);
138 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kSkew);
139 }
140
141 TEST(CanvasRecorder, Rotate) {
142 CanvasRecorder<Serializer> recorder;
143 recorder.Rotate(Radians(0));
144 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kRotate);
145 }
146
147 TEST(CanvasRecorder, DrawPath) {
148 CanvasRecorder<Serializer> recorder;
149 recorder.DrawPath(Path(), Paint());
150 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPath);
151 }
152
153 TEST(CanvasRecorder, DrawPaint) {
154 CanvasRecorder<Serializer> recorder;
155 recorder.DrawPaint(Paint());
156 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPaint);
157 }
158
159 TEST(CanvasRecorder, DrawLine) {
160 CanvasRecorder<Serializer> recorder;
161 recorder.DrawLine(Point(), Point(), Paint());
162 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawLine);
163 }
164
165 TEST(CanvasRecorder, DrawRect) {
166 CanvasRecorder<Serializer> recorder;
167 recorder.DrawRect(Rect(), Paint());
168 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawRect);
169 }
170
171 TEST(CanvasRecorder, DrawOval) {
172 CanvasRecorder<Serializer> recorder;
173 recorder.DrawOval(Rect(), Paint());
174 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawOval);
175 }
176
177 TEST(CanvasRecorder, DrawRRect) {
178 CanvasRecorder<Serializer> recorder;
179 recorder.DrawRRect(Rect(), {}, Paint());
180 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawRRect);
181 }
182
183 TEST(CanvasRecorder, DrawCircle) {
184 CanvasRecorder<Serializer> recorder;
185 recorder.DrawCircle(Point(), 0, Paint());
186 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawCircle);
187 }
188
189 TEST(CanvasRecorder, DrawPoints) {
190 CanvasRecorder<Serializer> recorder;
191 recorder.DrawPoints(std::vector<Point>{}, 0, Paint(), PointStyle::kRound);
192 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPoints);
193 }
194
195 TEST(CanvasRecorder, DrawImage) {
196 CanvasRecorder<Serializer> recorder;
197 recorder.DrawImage({}, {}, {}, {});
198 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawImage);
199 }
200
201 TEST(CanvasRecorder, DrawImageRect) {
202 CanvasRecorder<Serializer> recorder;
203 recorder.DrawImageRect({}, {}, {}, {}, {}, SourceRectConstraint::kFast);
204 ASSERT_EQ(recorder.GetSerializer().last_op_,
205 CanvasRecorderOp::kDrawImageRect);
206 }
207
208 TEST(CanvasRecorder, ClipPath) {
209 CanvasRecorder<Serializer> recorder;
210 recorder.ClipPath({});
211 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipPath);
212 }
213
214 TEST(CanvasRecorder, ClipRect) {
215 CanvasRecorder<Serializer> recorder;
216 recorder.ClipRect({});
217 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipRect);
218 }
219
220 TEST(CanvasRecorder, ClipOval) {
221 CanvasRecorder<Serializer> recorder;
222 recorder.ClipOval({});
223 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipOval);
224 }
225
226 TEST(CanvasRecorder, ClipRRect) {
227 CanvasRecorder<Serializer> recorder;
228 recorder.ClipRRect({}, {});
229 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipRRect);
230 }
231
232 TEST(CanvasRecorder, DrawTextFrame) {
233 CanvasRecorder<Serializer> recorder;
234 recorder.DrawTextFrame({}, {}, {});
235 ASSERT_EQ(recorder.GetSerializer().last_op_,
236 CanvasRecorderOp::kDrawTextFrame);
237 }
238
239 TEST(CanvasRecorder, DrawVertices) {
240 CanvasRecorder<Serializer> recorder;
241 auto geometry = std::shared_ptr<VerticesGeometry>(
242 new VerticesGeometry({}, {}, {}, {}, {}, {}));
243 recorder.DrawVertices(geometry, {}, {});
244 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawVertices);
245 }
246
247 TEST(CanvasRecorder, DrawAtlas) {
248 CanvasRecorder<Serializer> recorder;
249 recorder.DrawAtlas({}, {}, {}, {}, {}, {}, {}, {});
250 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawAtlas);
251 }
252
253 } // namespace testing
254 } // namespace impeller
impeller::kResetTransform
@ kResetTransform
Definition: canvas_recorder.h:25
impeller::VerticesGeometry
A geometry that is created from a vertices object.
Definition: vertices_geometry.h:13
impeller::kPreConcat
@ kPreConcat
Definition: canvas_recorder.h:28
impeller::kDrawImage
@ kDrawImage
Definition: canvas_recorder.h:42
impeller::kClipPath
@ kClipPath
Definition: canvas_recorder.h:44
impeller::kClipOval
@ kClipOval
Definition: canvas_recorder.h:46
impeller::SourceRectConstraint::kFast
@ kFast
Faster, but may sample outside the bounds of the source rectangle.
impeller::kConcat
@ kConcat
Definition: canvas_recorder.h:27
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
impeller::PointStyle::kRound
@ kRound
Points are drawn as squares.
impeller::Vector2
Point Vector2
Definition: point.h:320
impeller::ContentBoundsPromise
ContentBoundsPromise
Definition: entity_pass.h:28
impeller::kSave
@ kSave
Definition: canvas_recorder.h:21
impeller::kDrawCircle
@ kDrawCircle
Definition: canvas_recorder.h:40
canvas_recorder.h
impeller::kDrawTextFrame
@ kDrawTextFrame
Definition: canvas_recorder.h:48
impeller::kScale2
@ kScale2
Definition: canvas_recorder.h:30
impeller::Point
TPoint< Scalar > Point
Definition: point.h:316
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:51
impeller::kDrawRect
@ kDrawRect
Definition: canvas_recorder.h:37
last_op_
CanvasRecorderOp last_op_
Definition: canvas_recorder_unittests.cc:61
impeller::testing::TEST
TEST(CanvasRecorder, Save)
Definition: canvas_recorder_unittests.cc:65
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
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:661
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::kSaveLayer
@ kSaveLayer
Definition: canvas_recorder.h:22
impeller::kDrawPoints
@ kDrawPoints
Definition: canvas_recorder.h:41
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::kDrawLine
@ kDrawLine
Definition: canvas_recorder.h:36
impeller::kDrawPath
@ kDrawPath
Definition: canvas_recorder.h:34
impeller::kDrawRRect
@ kDrawRRect
Definition: canvas_recorder.h:39
impeller
Definition: aiks_blur_unittests.cc:20
impeller::kRestore
@ kRestore
Definition: canvas_recorder.h:23
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::kRestoreToCount
@ kRestoreToCount
Definition: canvas_recorder.h:24