Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
mutators_stack_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/flow/embedded_views.h"
6#include "gtest/gtest.h"
7
8namespace flutter {
9namespace testing {
10
11TEST(MutatorsStack, Initialization) {
12 MutatorsStack stack;
13 ASSERT_TRUE(true);
14}
15
16TEST(MutatorsStack, CopyConstructor) {
17 MutatorsStack stack;
18 auto rrect = SkRRect::MakeEmpty();
19 auto rect = SkRect::MakeEmpty();
20 stack.PushClipRect(rect);
21 stack.PushClipRRect(rrect);
23 ASSERT_TRUE(copy == stack);
24}
25
26TEST(MutatorsStack, CopyAndUpdateTheCopy) {
27 MutatorsStack stack;
28 auto rrect = SkRRect::MakeEmpty();
29 auto rect = SkRect::MakeEmpty();
30 stack.PushClipRect(rect);
31 stack.PushClipRRect(rrect);
33 copy.Pop();
34 copy.Pop();
35 ASSERT_TRUE(copy != stack);
36 ASSERT_TRUE(copy.is_empty());
37 ASSERT_TRUE(!stack.is_empty());
38 auto iter = stack.Bottom();
39 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
40 ASSERT_TRUE(iter->get()->GetRRect() == rrect);
41 ++iter;
42 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
43 ASSERT_TRUE(iter->get()->GetRect() == rect);
44}
45
46TEST(MutatorsStack, PushClipRect) {
47 MutatorsStack stack;
48 auto rect = SkRect::MakeEmpty();
49 stack.PushClipRect(rect);
50 auto iter = stack.Bottom();
51 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
52 ASSERT_TRUE(iter->get()->GetRect() == rect);
53}
54
55TEST(MutatorsStack, PushClipRRect) {
56 MutatorsStack stack;
57 auto rrect = SkRRect::MakeEmpty();
58 stack.PushClipRRect(rrect);
59 auto iter = stack.Bottom();
60 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
61 ASSERT_TRUE(iter->get()->GetRRect() == rrect);
62}
63
64TEST(MutatorsStack, PushClipPath) {
65 MutatorsStack stack;
67 stack.PushClipPath(path);
68 auto iter = stack.Bottom();
69 ASSERT_TRUE(iter->get()->GetType() == flutter::MutatorType::kClipPath);
70 ASSERT_TRUE(iter->get()->GetPath() == path);
71}
72
73TEST(MutatorsStack, PushTransform) {
74 MutatorsStack stack;
75 SkMatrix matrix;
76 matrix.setIdentity();
77 stack.PushTransform(matrix);
78 auto iter = stack.Bottom();
79 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kTransform);
80 ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
81}
82
83TEST(MutatorsStack, PushOpacity) {
84 MutatorsStack stack;
85 int alpha = 240;
86 stack.PushOpacity(alpha);
87 auto iter = stack.Bottom();
88 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kOpacity);
89 ASSERT_TRUE(iter->get()->GetAlpha() == 240);
90}
91
92TEST(MutatorsStack, PushBackdropFilter) {
93 MutatorsStack stack;
94 const int num_of_mutators = 10;
95 for (int i = 0; i < num_of_mutators; i++) {
96 auto filter = std::make_shared<DlBlurImageFilter>(i, 5, DlTileMode::kClamp);
97 stack.PushBackdropFilter(filter, SkRect::MakeXYWH(i, i, i, i));
98 }
99
100 auto iter = stack.Begin();
101 int i = 0;
102 while (iter != stack.End()) {
103 ASSERT_EQ(iter->get()->GetType(), MutatorType::kBackdropFilter);
104 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilter().asBlur()->sigma_x(),
105 i);
106 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().x(), i);
107 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().x(), i);
108 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().width(), i);
109 ASSERT_EQ(iter->get()->GetFilterMutation().GetFilterRect().height(), i);
110 ++iter;
111 ++i;
112 }
113 ASSERT_EQ(i, num_of_mutators);
114}
115
117 MutatorsStack stack;
118 SkMatrix matrix;
119 matrix.setIdentity();
120 stack.PushTransform(matrix);
121 stack.Pop();
122 auto iter = stack.Bottom();
123 ASSERT_TRUE(iter == stack.Top());
124}
125
126TEST(MutatorsStack, Traversal) {
127 MutatorsStack stack;
128 SkMatrix matrix;
129 matrix.setIdentity();
130 stack.PushTransform(matrix);
131 auto rect = SkRect::MakeEmpty();
132 stack.PushClipRect(rect);
133 auto rrect = SkRRect::MakeEmpty();
134 stack.PushClipRRect(rrect);
135 auto iter = stack.Bottom();
136 int index = 0;
137 while (iter != stack.Top()) {
138 switch (index) {
139 case 0:
140 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRRect);
141 ASSERT_TRUE(iter->get()->GetRRect() == rrect);
142 break;
143 case 1:
144 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kClipRect);
145 ASSERT_TRUE(iter->get()->GetRect() == rect);
146 break;
147 case 2:
148 ASSERT_TRUE(iter->get()->GetType() == MutatorType::kTransform);
149 ASSERT_TRUE(iter->get()->GetMatrix() == matrix);
150 break;
151 default:
152 break;
153 }
154 ++iter;
155 ++index;
156 }
157}
158
159TEST(MutatorsStack, Equality) {
160 MutatorsStack stack;
161 SkMatrix matrix = SkMatrix::Scale(1, 1);
162 stack.PushTransform(matrix);
163 SkRect rect = SkRect::MakeEmpty();
164 stack.PushClipRect(rect);
165 SkRRect rrect = SkRRect::MakeEmpty();
166 stack.PushClipRRect(rrect);
167 SkPath path;
168 stack.PushClipPath(path);
169 int alpha = 240;
170 stack.PushOpacity(alpha);
171 auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
172 stack.PushBackdropFilter(filter, SkRect::MakeEmpty());
173
174 MutatorsStack stack_other;
175 SkMatrix matrix_other = SkMatrix::Scale(1, 1);
176 stack_other.PushTransform(matrix_other);
177 SkRect rect_other = SkRect::MakeEmpty();
178 stack_other.PushClipRect(rect_other);
179 SkRRect rrect_other = SkRRect::MakeEmpty();
180 stack_other.PushClipRRect(rrect_other);
181 SkPath other_path;
182 stack_other.PushClipPath(other_path);
183 int other_alpha = 240;
184 stack_other.PushOpacity(other_alpha);
185 auto other_filter =
186 std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
187 stack_other.PushBackdropFilter(other_filter, SkRect::MakeEmpty());
188
189 ASSERT_TRUE(stack == stack_other);
190}
191
192TEST(Mutator, Initialization) {
193 SkRect rect = SkRect::MakeEmpty();
194 Mutator mutator = Mutator(rect);
195 ASSERT_TRUE(mutator.GetType() == MutatorType::kClipRect);
196 ASSERT_TRUE(mutator.GetRect() == rect);
197
198 SkRRect rrect = SkRRect::MakeEmpty();
199 Mutator mutator2 = Mutator(rrect);
200 ASSERT_TRUE(mutator2.GetType() == MutatorType::kClipRRect);
201 ASSERT_TRUE(mutator2.GetRRect() == rrect);
202
203 SkPath path;
204 Mutator mutator3 = Mutator(path);
205 ASSERT_TRUE(mutator3.GetType() == MutatorType::kClipPath);
206 ASSERT_TRUE(mutator3.GetPath() == path);
207
208 SkMatrix matrix;
209 matrix.setIdentity();
210 Mutator mutator4 = Mutator(matrix);
211 ASSERT_TRUE(mutator4.GetType() == MutatorType::kTransform);
212 ASSERT_TRUE(mutator4.GetMatrix() == matrix);
213
214 int alpha = 240;
215 Mutator mutator5 = Mutator(alpha);
216 ASSERT_TRUE(mutator5.GetType() == MutatorType::kOpacity);
217
218 auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
219 Mutator mutator6 = Mutator(filter, SkRect::MakeEmpty());
220 ASSERT_TRUE(mutator6.GetType() == MutatorType::kBackdropFilter);
221 ASSERT_TRUE(mutator6.GetFilterMutation().GetFilter() == *filter);
222}
223
224TEST(Mutator, CopyConstructor) {
225 SkRect rect = SkRect::MakeEmpty();
226 Mutator mutator = Mutator(rect);
227 Mutator copy = Mutator(mutator);
228 ASSERT_TRUE(mutator == copy);
229
230 SkRRect rrect = SkRRect::MakeEmpty();
231 Mutator mutator2 = Mutator(rrect);
232 Mutator copy2 = Mutator(mutator2);
233 ASSERT_TRUE(mutator2 == copy2);
234
235 SkPath path;
236 Mutator mutator3 = Mutator(path);
237 Mutator copy3 = Mutator(mutator3);
238 ASSERT_TRUE(mutator3 == copy3);
239
240 SkMatrix matrix;
241 matrix.setIdentity();
242 Mutator mutator4 = Mutator(matrix);
243 Mutator copy4 = Mutator(mutator4);
244 ASSERT_TRUE(mutator4 == copy4);
245
246 int alpha = 240;
247 Mutator mutator5 = Mutator(alpha);
248 Mutator copy5 = Mutator(mutator5);
249 ASSERT_TRUE(mutator5 == copy5);
250
251 auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
252 Mutator mutator6 = Mutator(filter, SkRect::MakeEmpty());
253 Mutator copy6 = Mutator(mutator6);
254 ASSERT_TRUE(mutator6 == copy6);
255}
256
257TEST(Mutator, Equality) {
258 SkMatrix matrix;
259 matrix.setIdentity();
260 Mutator mutator = Mutator(matrix);
261 Mutator other_mutator = Mutator(matrix);
262 ASSERT_TRUE(mutator == other_mutator);
263
264 SkRect rect = SkRect::MakeEmpty();
265 Mutator mutator2 = Mutator(rect);
266 Mutator other_mutator2 = Mutator(rect);
267 ASSERT_TRUE(mutator2 == other_mutator2);
268
269 SkRRect rrect = SkRRect::MakeEmpty();
270 Mutator mutator3 = Mutator(rrect);
271 Mutator other_mutator3 = Mutator(rrect);
272 ASSERT_TRUE(mutator3 == other_mutator3);
273
274 SkPath path;
276 flutter::Mutator other_mutator4 = flutter::Mutator(path);
277 ASSERT_TRUE(mutator4 == other_mutator4);
278 ASSERT_FALSE(mutator2 == mutator);
279 int alpha = 240;
280 Mutator mutator5 = Mutator(alpha);
281 Mutator other_mutator5 = Mutator(alpha);
282 ASSERT_TRUE(mutator5 == other_mutator5);
283
284 auto filter1 = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
285 auto filter2 = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
286 Mutator mutator6 = Mutator(filter1, SkRect::MakeEmpty());
287 Mutator other_mutator6 = Mutator(filter2, SkRect::MakeEmpty());
288 ASSERT_TRUE(mutator6 == other_mutator6);
289}
290
291TEST(Mutator, UnEquality) {
292 SkRect rect = SkRect::MakeEmpty();
293 Mutator mutator = Mutator(rect);
294 SkMatrix matrix;
295 matrix.setIdentity();
296 Mutator not_equal_mutator = Mutator(matrix);
297 ASSERT_TRUE(not_equal_mutator != mutator);
298
299 int alpha = 240;
300 int alpha2 = 241;
301 Mutator mutator2 = Mutator(alpha);
302 Mutator other_mutator2 = Mutator(alpha2);
303 ASSERT_TRUE(mutator2 != other_mutator2);
304
305 auto filter = std::make_shared<DlBlurImageFilter>(5, 5, DlTileMode::kClamp);
306 auto filter2 =
307 std::make_shared<DlBlurImageFilter>(10, 10, DlTileMode::kClamp);
308 Mutator mutator3 = Mutator(filter, SkRect::MakeEmpty());
309 Mutator other_mutator3 = Mutator(filter2, SkRect::MakeEmpty());
310 ASSERT_TRUE(mutator3 != other_mutator3);
311}
312
313} // namespace testing
314} // namespace flutter
#define TEST(S, s, D, expected)
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition SkMatrix.h:75
static SkRRect MakeEmpty()
Definition SkRRect.h:142
const DlImageFilter & GetFilter() const
const SkMatrix & GetMatrix() const
const ImageFilterMutation & GetFilterMutation() const
const MutatorType & GetType() const
const SkPath & GetPath() const
const SkRRect & GetRRect() const
const SkRect & GetRect() const
void PushClipPath(const SkPath &path)
void PushOpacity(const int &alpha)
const std::vector< std::shared_ptr< Mutator > >::const_reverse_iterator Top() const
const std::vector< std::shared_ptr< Mutator > >::const_reverse_iterator Bottom() const
void PushBackdropFilter(const std::shared_ptr< const DlImageFilter > &filter, const SkRect &filter_rect)
const std::vector< std::shared_ptr< Mutator > >::const_iterator End() const
void PushClipRect(const SkRect &rect)
void PushTransform(const SkMatrix &matrix)
const std::vector< std::shared_ptr< Mutator > >::const_iterator Begin() const
void PushClipRRect(const SkRRect &rrect)
Definition copy.py:1
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659