| 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 CanvasRecorderOp last_op_;
58 };
59 } // namespace
60
61 TEST(CanvasRecorder, Save) {
62 CanvasRecorder<Serializer> recorder;
63 recorder.Save();
64 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kSave);
65 }
66
67 TEST(CanvasRecorder, SaveLayer) {
68 CanvasRecorder<Serializer> recorder;
69 Paint paint;
70 recorder.SaveLayer(paint);
71 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kSaveLayer);
72 }
73
74 TEST(CanvasRecorder, Restore) {
75 CanvasRecorder<Serializer> recorder;
76 recorder.Restore();
77 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kRestore);
78 }
79
80 TEST(CanvasRecorder, RestoreToCount) {
81 CanvasRecorder<Serializer> recorder;
82 recorder.Save();
83 recorder.RestoreToCount(0);
84 ASSERT_EQ(recorder.GetSerializer().last_op_,
85 CanvasRecorderOp::kRestoreToCount);
86 }
87
88 TEST(CanvasRecorder, ResetTransform) {
89 CanvasRecorder<Serializer> recorder;
90 recorder.ResetTransform();
91 ASSERT_EQ(recorder.GetSerializer().last_op_,
92 CanvasRecorderOp::kResetTransform);
93 }
94
95 TEST(CanvasRecorder, Transform) {
96 CanvasRecorder<Serializer> recorder;
97 recorder.Transform(Matrix());
98 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kTransform);
99 }
100
101 TEST(CanvasRecorder, Concat) {
102 CanvasRecorder<Serializer> recorder;
103 recorder.Concat(Matrix());
104 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kConcat);
105 }
106
107 TEST(CanvasRecorder, PreConcat) {
108 CanvasRecorder<Serializer> recorder;
109 recorder.PreConcat(Matrix());
110 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kPreConcat);
111 }
112
113 TEST(CanvasRecorder, Translate) {
114 CanvasRecorder<Serializer> recorder;
115 recorder.Translate(Vector3());
116 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kTranslate);
117 }
118
119 TEST(CanvasRecorder, Scale2) {
120 CanvasRecorder<Serializer> recorder;
121 recorder.Scale(Vector2());
122 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kScale2);
123 }
124
125 TEST(CanvasRecorder, Scale3) {
126 CanvasRecorder<Serializer> recorder;
127 recorder.Scale(Vector3());
128 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kScale3);
129 }
130
131 TEST(CanvasRecorder, Skew) {
132 CanvasRecorder<Serializer> recorder;
133 recorder.Skew(0, 0);
134 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kSkew);
135 }
136
137 TEST(CanvasRecorder, Rotate) {
138 CanvasRecorder<Serializer> recorder;
139 recorder.Rotate(Radians(0));
140 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kRotate);
141 }
142
143 TEST(CanvasRecorder, DrawPath) {
144 CanvasRecorder<Serializer> recorder;
145 recorder.DrawPath(Path(), Paint());
146 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPath);
147 }
148
149 TEST(CanvasRecorder, DrawPaint) {
150 CanvasRecorder<Serializer> recorder;
151 recorder.DrawPaint(Paint());
152 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPaint);
153 }
154
155 TEST(CanvasRecorder, DrawRect) {
156 CanvasRecorder<Serializer> recorder;
157 recorder.DrawRect(Rect(), Paint());
158 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawRect);
159 }
160
161 TEST(CanvasRecorder, DrawRRect) {
162 CanvasRecorder<Serializer> recorder;
163 recorder.DrawRRect(Rect(), {}, Paint());
164 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawRRect);
165 }
166
167 TEST(CanvasRecorder, DrawCircle) {
168 CanvasRecorder<Serializer> recorder;
169 recorder.DrawCircle(Point(), 0, Paint());
170 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawCircle);
171 }
172
173 TEST(CanvasRecorder, DrawPoints) {
174 CanvasRecorder<Serializer> recorder;
175 recorder.DrawPoints(std::vector<Point>{}, 0, Paint(), PointStyle::kRound);
176 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPoints);
177 }
178
179 TEST(CanvasRecorder, DrawImage) {
180 CanvasRecorder<Serializer> recorder;
181 recorder.DrawImage({}, {}, {}, {});
182 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawImage);
183 }
184
185 TEST(CanvasRecorder, DrawImageRect) {
186 CanvasRecorder<Serializer> recorder;
187 recorder.DrawImageRect({}, {}, {}, {}, {});
188 ASSERT_EQ(recorder.GetSerializer().last_op_,
189 CanvasRecorderOp::kDrawImageRect);
190 }
191
192 TEST(CanvasRecorder, ClipPath) {
193 CanvasRecorder<Serializer> recorder;
194 recorder.ClipPath({});
195 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipPath);
196 }
197
198 TEST(CanvasRecorder, ClipRect) {
199 CanvasRecorder<Serializer> recorder;
200 recorder.ClipRect({});
201 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipRect);
202 }
203
204 TEST(CanvasRecorder, ClipRRect) {
205 CanvasRecorder<Serializer> recorder;
206 recorder.ClipRRect({}, {});
207 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kClipRRect);
208 }
209
210 TEST(CanvasRecorder, DrawPicture) {
211 CanvasRecorder<Serializer> recorder;
212 recorder.DrawPicture({});
213 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawPicture);
214 }
215
216 TEST(CanvasRecorder, DrawTextFrame) {
217 CanvasRecorder<Serializer> recorder;
218 recorder.DrawTextFrame({}, {}, {});
219 ASSERT_EQ(recorder.GetSerializer().last_op_,
220 CanvasRecorderOp::kDrawTextFrame);
221 }
222
223 TEST(CanvasRecorder, DrawVertices) {
224 CanvasRecorder<Serializer> recorder;
225 auto geometry = std::shared_ptr<VerticesGeometry>(
226 new VerticesGeometry({}, {}, {}, {}, {}, {}));
227 recorder.DrawVertices(geometry, {}, {});
228 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawVertices);
229 }
230
231 TEST(CanvasRecorder, DrawAtlas) {
232 CanvasRecorder<Serializer> recorder;
233 recorder.DrawAtlas({}, {}, {}, {}, {}, {}, {}, {});
234 ASSERT_EQ(recorder.GetSerializer().last_op_, CanvasRecorderOp::kDrawAtlas);
235 }
236
237 } // namespace testing
238 } // 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:40
impeller::kClipPath
@ kClipPath
Definition: canvas_recorder.h:42
impeller::kConcat
@ kConcat
Definition: canvas_recorder.h:27
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
impeller::PointStyle::kRound
@ kRound
Points are drawn as squares.
impeller::Vector2
Point Vector2
Definition: point.h:312
impeller::kSave
@ kSave
Definition: canvas_recorder.h:21
impeller::kDrawCircle
@ kDrawCircle
Definition: canvas_recorder.h:38
canvas_recorder.h
impeller::kDrawTextFrame
@ kDrawTextFrame
Definition: canvas_recorder.h:46
impeller::kScale2
@ kScale2
Definition: canvas_recorder.h:30
impeller::Point
TPoint< Scalar > Point
Definition: point.h:308
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:55
impeller::kDrawRect
@ kDrawRect
Definition: canvas_recorder.h:36
last_op_
CanvasRecorderOp last_op_
Definition: canvas_recorder_unittests.cc:57
impeller::testing::TEST
TEST(CanvasRecorder, Save)
Definition: canvas_recorder_unittests.cc:61
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
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:488
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::kSaveLayer
@ kSaveLayer
Definition: canvas_recorder.h:22
impeller::kDrawPoints
@ kDrawPoints
Definition: canvas_recorder.h:39
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::kDrawPath
@ kDrawPath
Definition: canvas_recorder.h:34
impeller::kDrawRRect
@ kDrawRRect
Definition: canvas_recorder.h:37
impeller
Definition: aiks_context.cc:10
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:43
impeller::kRestoreToCount
@ kRestoreToCount
Definition: canvas_recorder.h:24