Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
dl_path_builder_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
6
7#include "gtest/gtest.h"
8
10
11namespace {
12using ::testing::Return;
13
14MATCHER_P(ScalarEq, a, "") {
15 *result_listener << "isn't equal to " << a;
16 return abs(arg - a) <= impeller::kEhCloseEnough;
17}
18} // namespace
19
20namespace flutter {
21namespace testing {
22
23TEST(DisplayListPathBuilder, DefaultConstructor) {
24 DlPathBuilder builder;
25 DlPath path = builder.TakePath();
26
27 EXPECT_TRUE(path.IsEmpty());
28 EXPECT_TRUE(path.GetBounds().IsEmpty());
29 EXPECT_EQ(path, DlPath());
30 EXPECT_EQ(path.GetFillType(), DlPathFillType::kNonZero);
31}
32
33TEST(DisplayListPathBuilder, SetFillType) {
34 DlPathBuilder builder;
35 builder.SetFillType(DlPathFillType::kOdd);
36 DlPath path = builder.TakePath();
37
38 EXPECT_EQ(path.GetFillType(), DlPathFillType::kOdd);
39}
40
41TEST(DisplayListPathBuilder, CopyPathDoesNotResetPath) {
42 DlPathBuilder builder;
43 builder.SetFillType(DlPathFillType::kOdd);
44 builder.MoveTo(DlPoint(10, 10));
45 builder.LineTo(DlPoint(20, 10));
46 builder.QuadraticCurveTo(DlPoint(20, 20), DlPoint(10, 20));
47 DlPath before_path = builder.CopyPath();
48
49 EXPECT_FALSE(before_path.IsEmpty());
50 EXPECT_EQ(before_path.GetBounds(), DlRect::MakeLTRB(10, 10, 20, 20));
51 EXPECT_NE(before_path, DlPath());
52 EXPECT_EQ(before_path.GetFillType(), DlPathFillType::kOdd);
53
54 DlPath after_path = builder.TakePath();
55
56 EXPECT_FALSE(after_path.IsEmpty());
57 EXPECT_EQ(after_path.GetBounds(), DlRect::MakeLTRB(10, 10, 20, 20));
58 EXPECT_NE(after_path, DlPath());
59 EXPECT_EQ(after_path, before_path);
60 EXPECT_EQ(after_path.GetFillType(), DlPathFillType::kOdd);
61}
62
63TEST(DisplayListPathBuilder, TakePathResetsPath) {
64 DlPathBuilder builder;
65 builder.SetFillType(DlPathFillType::kOdd);
66 builder.MoveTo(DlPoint(10, 10));
67 builder.LineTo(DlPoint(20, 10));
68 builder.QuadraticCurveTo(DlPoint(20, 20), DlPoint(10, 20));
69 DlPath before_path = builder.TakePath();
70
71 EXPECT_FALSE(before_path.IsEmpty());
72 EXPECT_EQ(before_path.GetBounds(), DlRect::MakeLTRB(10, 10, 20, 20));
73 EXPECT_NE(before_path, DlPath());
74 EXPECT_EQ(before_path.GetFillType(), DlPathFillType::kOdd);
75
76 DlPath after_path = builder.TakePath();
77
78 EXPECT_TRUE(after_path.IsEmpty());
79 EXPECT_TRUE(after_path.GetBounds().IsEmpty());
80 EXPECT_EQ(after_path, DlPath());
81 EXPECT_EQ(after_path.GetFillType(), DlPathFillType::kNonZero);
82}
83
84TEST(DisplayListPathBuilder, LineToInsertsMoveTo) {
85 DlPathBuilder builder;
86 builder.LineTo(DlPoint(10, 10));
87 DlPath path = builder.TakePath();
88
89 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
90
91 {
92 ::testing::InSequence sequence;
93
94 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(0, 0), false));
95 EXPECT_CALL(mock_receiver, LineTo(DlPoint(10, 10)));
96 }
97
98 path.Dispatch(mock_receiver);
99}
100
101TEST(DisplayListPathBuilder, QuadToInsertsMoveTo) {
102 DlPathBuilder builder;
103 builder.QuadraticCurveTo(DlPoint(10, 10), DlPoint(10, 0));
104 DlPath path = builder.TakePath();
105
106 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
107
108 {
109 ::testing::InSequence sequence;
110
111 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(0, 0), false));
112 EXPECT_CALL(mock_receiver, QuadTo(DlPoint(10, 10), DlPoint(10, 0)));
113 }
114
115 path.Dispatch(mock_receiver);
116}
117
118TEST(DisplayListPathBuilder, ConicToInsertsMoveTo) {
119 DlPathBuilder builder;
120 builder.ConicCurveTo(DlPoint(10, 10), DlPoint(10, 0), 0.5f);
121 DlPath path = builder.TakePath();
122
123 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
124
125 {
126 ::testing::InSequence sequence;
127
128 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(0, 0), false));
129 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 10), DlPoint(10, 0), 0.5f))
130 .WillOnce(Return(true));
131 }
132
133 path.Dispatch(mock_receiver);
134}
135
136TEST(DisplayListPathBuilder, CubicToInsertsMoveTo) {
137 DlPathBuilder builder;
138 builder.CubicCurveTo(DlPoint(10, 10), DlPoint(10, 0), DlPoint(0, 10));
139 DlPath path = builder.TakePath();
140
141 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
142
143 {
144 ::testing::InSequence sequence;
145
146 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(0, 0), false));
147 EXPECT_CALL(mock_receiver,
148 CubicTo(DlPoint(10, 10), DlPoint(10, 0), DlPoint(0, 10)));
149 }
150
151 path.Dispatch(mock_receiver);
152}
153
154TEST(DisplayListPathBuilder, ConicWithNonPositiveWeightsInsertLineTo) {
155 DlPathBuilder builder;
156 builder.MoveTo(DlPoint(10, 10));
157 builder.ConicCurveTo(DlPoint(20, 10), DlPoint(10, 20), -1.0f);
158 builder.ConicCurveTo(DlPoint(20, 20), DlPoint(10, 30), 0.0f);
159 builder.ConicCurveTo(DlPoint(20, 30), DlPoint(10, 40),
160 std::numeric_limits<DlScalar>::quiet_NaN());
161 DlPath path = builder.TakePath();
162
163 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
164
165 {
166 ::testing::InSequence sequence;
167
168 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(10, 10), false));
169 EXPECT_CALL(mock_receiver, LineTo(DlPoint(10, 20)));
170 EXPECT_CALL(mock_receiver, LineTo(DlPoint(10, 30)));
171 EXPECT_CALL(mock_receiver, LineTo(DlPoint(10, 40)));
172 }
173
174 path.Dispatch(mock_receiver);
175}
176
177TEST(DisplayListPathBuilder, ConicWithWeight1InsertsQuadTo) {
178 DlPathBuilder builder;
179 builder.MoveTo(DlPoint(10, 10));
180 builder.ConicCurveTo(DlPoint(20, 10), DlPoint(10, 20), 1.0f);
181 DlPath path = builder.TakePath();
182
183 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
184
185 {
186 ::testing::InSequence sequence;
187
188 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(10, 10), false));
189 EXPECT_CALL(mock_receiver, QuadTo(DlPoint(20, 10), DlPoint(10, 20)));
190 }
191
192 path.Dispatch(mock_receiver);
193}
194
195TEST(DisplayListPathBuilder, AddRect) {
196 auto path = DlPathBuilder{} //
197 .AddRect(DlRect::MakeLTRB(10, 10, 20, 20))
198 .TakePath();
199
200 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
201
202 {
203 ::testing::InSequence sequence;
204
205 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(10, 10), true));
206 EXPECT_CALL(mock_receiver, LineTo(DlPoint(20, 10)));
207 EXPECT_CALL(mock_receiver, LineTo(DlPoint(20, 20)));
208 EXPECT_CALL(mock_receiver, LineTo(DlPoint(10, 20)));
209 EXPECT_CALL(mock_receiver, LineTo(DlPoint(10, 10)));
210 EXPECT_CALL(mock_receiver, Close());
211 }
212
213 path.Dispatch(mock_receiver);
214}
215
216TEST(DisplayListPathBuilder, AddOval) {
217 auto path = DlPathBuilder{} //
218 .AddOval(DlRect::MakeLTRB(10, 10, 30, 20))
219 .TakePath();
220
221 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
222
223 {
224 ::testing::InSequence sequence;
225
226 auto wt = impeller::kSqrt2Over2;
227 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(30, 15), true));
228 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(30, 20), DlPoint(20, 20), wt))
229 .WillOnce(Return(true));
230 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 20), DlPoint(10, 15), wt))
231 .WillOnce(Return(true));
232 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 10), DlPoint(20, 10), wt))
233 .WillOnce(Return(true));
234 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(30, 10), DlPoint(30, 15), wt))
235 .WillOnce(Return(true));
236 EXPECT_CALL(mock_receiver, Close());
237 }
238
239 path.Dispatch(mock_receiver);
240}
241
242TEST(DisplayListPathBuilder, AddCircle) {
243 auto path = DlPathBuilder{} //
244 .AddCircle(DlPoint(15, 15), 5)
245 .TakePath();
246
247 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
248
249 {
250 ::testing::InSequence sequence;
251
252 auto wt = impeller::kSqrt2Over2;
253 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(20, 15), true));
254 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(20, 20), DlPoint(15, 20), wt))
255 .WillOnce(Return(true));
256 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 20), DlPoint(10, 15), wt))
257 .WillOnce(Return(true));
258 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 10), DlPoint(15, 10), wt))
259 .WillOnce(Return(true));
260 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(20, 10), DlPoint(20, 15), wt))
261 .WillOnce(Return(true));
262 EXPECT_CALL(mock_receiver, Close());
263 }
264
265 path.Dispatch(mock_receiver);
266}
267
268TEST(DisplayListPathBuilder, AddRoundRect) {
269 auto bounds = DlRect::MakeLTRB(10, 10, 100, 100);
270 auto radii = DlRoundingRadii{
271 .top_left = DlSize(2, 12),
272 .top_right = DlSize(3, 13),
273 .bottom_left = DlSize(4, 14),
274 .bottom_right = DlSize(5, 15),
275 };
276 auto path = DlPathBuilder{} //
278 .TakePath();
279
280 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
281
282 {
283 ::testing::InSequence sequence;
284
285 auto wt = impeller::kSqrt2Over2;
286 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(10, 86), true));
287 EXPECT_CALL(mock_receiver, LineTo(DlPoint(10, 22)));
288 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 10), DlPoint(12, 10), wt))
289 .WillOnce(Return(true));
290 EXPECT_CALL(mock_receiver, LineTo(DlPoint(97, 10)));
291 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(100, 10), DlPoint(100, 23), wt))
292 .WillOnce(Return(true));
293 EXPECT_CALL(mock_receiver, LineTo(DlPoint(100, 85)));
294 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(100, 100), DlPoint(95, 100), wt))
295 .WillOnce(Return(true));
296 EXPECT_CALL(mock_receiver, LineTo(DlPoint(14, 100)));
297 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 100), DlPoint(10, 86), wt))
298 .WillOnce(Return(true));
299 EXPECT_CALL(mock_receiver, Close());
300 }
301
302 path.Dispatch(mock_receiver);
303}
304
305TEST(DisplayListPathBuilder, AddRoundSuperellipse) {
306 auto bounds = DlRect::MakeLTRB(10, 10, 100, 100);
307 auto radii = DlRoundingRadii{
308 .top_left = DlSize(2, 12),
309 .top_right = DlSize(3, 13),
310 .bottom_left = DlSize(4, 14),
311 .bottom_right = DlSize(5, 15),
312 };
313 auto path = DlPathBuilder{} //
316 .TakePath();
317
318 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
319
320 {
321 ::testing::InSequence sequence;
322
323 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(46, 10), true));
324
325 // 1
326 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(94.8672, 9.99998)),
327 PointEq(DlPoint(95.7708, 10.0493)),
328 ScalarEq(3.63127851)))
329 .WillOnce(Return(true));
330 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(96.6558, 10.0976)),
331 PointEq(DlPoint(97.1856, 10.2338)),
332 ScalarEq(1.22087204)))
333 .WillOnce(Return(true));
334 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(97.9096f, 10.367f)),
335 PointEq(DlPoint(98.5976, 11.6373)),
336 PointEq(DlPoint(99.1213, 13.8076))));
337
338 // 2
339 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(99.5784, 15.7987)),
340 PointEq(DlPoint(99.8618, 18.4156)),
341 PointEq(DlPoint(99.9232, 21.2114))));
342 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(99.9636, 23.0102)),
343 PointEq(DlPoint(99.9805, 25.6229)),
344 ScalarEq(1.17059147)))
345 .WillOnce(Return(true));
346 EXPECT_CALL(mock_receiver,
347 ConicTo(PointEq(DlPoint(100, 28.6213)),
348 PointEq(DlPoint(100, 51.7857)), ScalarEq(2.12785244)))
349 .WillOnce(Return(true));
350
351 // 3
352 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(100, 78.514)),
353 PointEq(DlPoint(99.9675, 81.9736)),
354 ScalarEq(2.12785244)))
355 .WillOnce(Return(true));
356 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(99.9393, 84.9882)),
357 PointEq(DlPoint(99.872, 87.0638)),
358 ScalarEq(1.17059147)))
359 .WillOnce(Return(true));
360 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(99.7697, 90.2897)),
361 PointEq(DlPoint(99.2973, 93.3092)),
362 PointEq(DlPoint(98.5355, 95.6066))));
363
364 // 4
365 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(97.6834, 98.0734)),
366 PointEq(DlPoint(96.5625, 99.532)),
367 PointEq(DlPoint(95.3799, 99.7131))));
368 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(94.5196, 99.8799)),
369 PointEq(DlPoint(93.1037, 99.9395)),
370 ScalarEq(1.16898668)))
371 .WillOnce(Return(true));
372 EXPECT_CALL(mock_receiver,
373 ConicTo(PointEq(DlPoint(91.6668, 100)),
374 PointEq(DlPoint(50, 100)), ScalarEq(3.63127851)))
375 .WillOnce(Return(true));
376
377 // 5
378 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(16.6667, 100)),
379 PointEq(DlPoint(15.5171, 99.9435)),
380 ScalarEq(3.63127851)))
381 .WillOnce(Return(true));
382 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(14.3843, 99.8879)),
383 PointEq(DlPoint(13.6961, 99.7323)),
384 ScalarEq(1.16898668)))
385 .WillOnce(Return(true));
386 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(12.75, 99.5632)),
387 PointEq(DlPoint(11.8533, 98.2018)),
388 PointEq(DlPoint(11.1716, 95.8995))));
389
390 // 6
391 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(10.5569, 93.7323)),
392 PointEq(DlPoint(10.1777, 90.8822)),
393 PointEq(DlPoint(10.0993, 87.8409))));
394 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(10.0462, 85.8435)),
395 PointEq(DlPoint(10.0244, 82.8947)),
396 ScalarEq(1.2416352)))
397 .WillOnce(Return(true));
398 EXPECT_CALL(mock_receiver,
399 ConicTo(PointEq(DlPoint(10, 79.594)),
400 PointEq(DlPoint(10, 51.5385)), ScalarEq(1.77972043)))
401 .WillOnce(Return(true));
402
403 // 7
404 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(10, 27.4909)),
405 PointEq(DlPoint(10.0122, 24.6616)),
406 ScalarEq(1.77972043)))
407 .WillOnce(Return(true));
408 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(10.0231, 22.1342)),
409 PointEq(DlPoint(10.0496, 20.4221)),
410 ScalarEq(1.2416352)))
411 .WillOnce(Return(true));
412 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(10.0888, 17.8153)),
413 PointEq(DlPoint(10.2785, 15.3723)),
414 PointEq(DlPoint(10.5858, 13.5147))));
415
416 // 8
417 EXPECT_CALL(mock_receiver, CubicTo(PointEq(DlPoint(10.9349, 11.5114)),
418 PointEq(DlPoint(11.3936, 10.3388)),
419 PointEq(DlPoint(11.8762, 10.2158))));
420 EXPECT_CALL(mock_receiver, ConicTo(PointEq(DlPoint(12.2295, 10.0901)),
421 PointEq(DlPoint(12.8195, 10.0455)),
422 ScalarEq(1.22087204)))
423 .WillOnce(Return(true));
424 EXPECT_CALL(mock_receiver,
425 ConicTo(PointEq(DlPoint(13.4216, 10)), PointEq(DlPoint(46, 10)),
426 ScalarEq(3.63127851)))
427 .WillOnce(Return(true));
428
429 EXPECT_CALL(mock_receiver, LineTo(PointEq(DlPoint(46, 10))));
430 EXPECT_CALL(mock_receiver, Close());
431 }
432
433 path.Dispatch(mock_receiver);
434}
435
436TEST(DisplayListPathBuilder, AddArcNoCenter) {
437 auto path = DlPathBuilder{}
438 .AddArc(DlRect::MakeLTRB(10, 10, 30, 20), //
439 DlDegrees(90), DlDegrees(90), false)
440 .TakePath();
441
442 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
443
444 {
445 ::testing::InSequence sequence;
446
447 auto wt = impeller::kSqrt2Over2;
448 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(20, 20), false));
449 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 20), DlPoint(10, 15), wt))
450 .WillOnce(Return(true));
451 }
452
453 path.Dispatch(mock_receiver);
454}
455
456TEST(DisplayListPathBuilder, AddArcWithCenter) {
457 auto path = DlPathBuilder{}
458 .AddArc(DlRect::MakeLTRB(10, 10, 30, 20), //
459 DlDegrees(90), DlDegrees(90), true)
460 .TakePath();
461
462 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
463
464 {
465 ::testing::InSequence sequence;
466
467 auto wt = impeller::kSqrt2Over2;
468 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(20, 15), true));
469 EXPECT_CALL(mock_receiver, LineTo(DlPoint(20, 20)));
470 EXPECT_CALL(mock_receiver, ConicTo(DlPoint(10, 20), DlPoint(10, 15), wt))
471 .WillOnce(Return(true));
472 EXPECT_CALL(mock_receiver, LineTo(DlPoint(20, 15)));
473 EXPECT_CALL(mock_receiver, Close());
474 }
475
476 path.Dispatch(mock_receiver);
477}
478
479TEST(DisplayListPathBuilder, SimpleUnclosedPath) {
480 auto path = DlPathBuilder{}
481 .MoveTo({0, 0})
482 .LineTo({100, 100})
483 .QuadraticCurveTo({200, 200}, {300, 300})
484 .ConicCurveTo({200, 200}, {100, 100}, 0.75f)
485 .CubicCurveTo({300, 300}, {400, 400}, {500, 500})
486 .TakePath();
487
488 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
489
490 {
491 ::testing::InSequence sequence;
492
493 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(0, 0), false));
494 EXPECT_CALL(mock_receiver, LineTo(DlPoint(100, 100)));
495 EXPECT_CALL(mock_receiver, QuadTo(DlPoint(200, 200), DlPoint(300, 300)));
496 EXPECT_CALL(mock_receiver,
497 ConicTo(DlPoint(200, 200), DlPoint(100, 100), 0.75f))
498 .WillOnce(Return(true));
499 EXPECT_CALL(mock_receiver, CubicTo(DlPoint(300, 300), DlPoint(400, 400),
500 DlPoint(500, 500)));
501 }
502
503 path.Dispatch(mock_receiver);
504}
505
506TEST(DisplayListPathBuilder, SimpleClosedPath) {
507 auto path = DlPathBuilder{}
508 .MoveTo({0, 0})
509 .LineTo({100, 100})
510 .QuadraticCurveTo({200, 200}, {300, 300})
511 .ConicCurveTo({200, 200}, {100, 100}, 0.75f)
512 .CubicCurveTo({300, 300}, {400, 400}, {500, 500})
513 .Close()
514 .TakePath();
515
516 ::testing::StrictMock<DlPathReceiverMock> mock_receiver;
517
518 {
519 ::testing::InSequence sequence;
520
521 EXPECT_CALL(mock_receiver, MoveTo(DlPoint(0, 0), true));
522 EXPECT_CALL(mock_receiver, LineTo(DlPoint(100, 100)));
523 EXPECT_CALL(mock_receiver, QuadTo(DlPoint(200, 200), DlPoint(300, 300)));
524 EXPECT_CALL(mock_receiver,
525 ConicTo(DlPoint(200, 200), DlPoint(100, 100), 0.75f))
526 .WillOnce(Return(true));
527 EXPECT_CALL(mock_receiver, CubicTo(DlPoint(300, 300), DlPoint(400, 400),
528 DlPoint(500, 500)));
529 EXPECT_CALL(mock_receiver, LineTo(DlPoint(0, 0)));
530 EXPECT_CALL(mock_receiver, Close());
531 }
532
533 path.Dispatch(mock_receiver);
534}
535
536TEST(DisplayListPathBuilder, EvenOddAppendNonZeroStaysEvenOdd) {
537 auto even_odd_path_builder = DlPathBuilder{}
538 .SetFillType(DlPathFillType::kOdd)
539 .MoveTo({0, 0})
540 .LineTo({100, 0})
541 .LineTo({0, 100})
542 .Close();
543 auto non_zero_path_builder = DlPathBuilder{}
544 .SetFillType(DlPathFillType::kNonZero)
545 .MoveTo({200, 200})
546 .LineTo({300, 200})
547 .LineTo({200, 300})
548 .Close();
549
550 even_odd_path_builder.AddPath(non_zero_path_builder.TakePath());
551 auto path = even_odd_path_builder.TakePath();
552
553 EXPECT_EQ(path.GetFillType(), DlPathFillType::kOdd);
554}
555
556TEST(DisplayListPathBuilder, NonZeroAppendEvenOddAppendStaysNonZero) {
557 auto even_odd_path_builder = DlPathBuilder{}
558 .SetFillType(DlPathFillType::kOdd)
559 .MoveTo({0, 0})
560 .LineTo({100, 0})
561 .LineTo({0, 100})
562 .Close();
563 auto non_zero_path_builder = DlPathBuilder{}
564 .SetFillType(DlPathFillType::kNonZero)
565 .MoveTo({200, 200})
566 .LineTo({300, 200})
567 .LineTo({200, 300})
568 .Close();
569
570 non_zero_path_builder.AddPath(even_odd_path_builder.TakePath());
571 auto path = non_zero_path_builder.TakePath();
572
573 EXPECT_EQ(path.GetFillType(), DlPathFillType::kNonZero);
574}
575
576} // namespace testing
577} // namespace flutter
DlPathBuilder & AddRoundSuperellipse(const DlRoundSuperellipse &rse)
Append a closed rounded super-ellipse contour to the path.
DlPathBuilder & LineTo(DlPoint p2)
Draw a line from the current point to the indicated point p2.
DlPathBuilder & AddPath(const DlPath &path)
Append the provided path to this path as if the commands used to construct it were repeated on this p...
DlPathBuilder & MoveTo(DlPoint p2)
Start a new contour that will originate at the indicated point p2.
const DlPath CopyPath()
Returns the path constructed by this path builder so far and retains all current geometry to continue...
DlPathBuilder & SetFillType(DlPathFillType fill_type)
Set the fill type that should be used to determine the interior of this path to the indicated |fill_t...
const DlPath TakePath()
Returns the path constructed by this path builder and resets its internal state to the default state ...
DlPathBuilder & ConicCurveTo(DlPoint cp, DlPoint p2, DlScalar weight)
Draw a conic curve (a rational quadratic bezier curve) from the current point to the indicated point ...
DlPathBuilder & AddCircle(DlPoint center, DlScalar radius)
Append a closed circular contour to the path centered on the provided point at the provided radius.
DlPathBuilder & AddRect(const DlRect &rect)
Append a closed rectangular contour to the path.
DlPathBuilder & AddRoundRect(const DlRoundRect &round_rect)
Append a closed rounded rect contour to the path.
DlPathBuilder & QuadraticCurveTo(DlPoint cp, DlPoint p2)
Draw a quadratic bezier curve from the current point to the indicated point p2, using the indicated p...
DlPathBuilder & AddArc(const DlRect &bounds, DlDegrees start, DlDegrees sweep, bool use_center=false)
Append an arc contour to the path which:
DlPathBuilder & AddOval(const DlRect &bounds)
Append a closed elliptical contour to the path inscribed in the provided bounds.
DlPathBuilder & CubicCurveTo(DlPoint cp1, DlPoint cp2, DlPoint p2)
Draw a cubic bezier curve from the current point to the indicated point p2, using the indicated point...
bool IsEmpty() const
Definition dl_path.cc:204
DlRect GetBounds() const override
Definition dl_path.cc:243
DlPathFillType GetFillType() const override
Definition dl_path.cc:239
TEST(NativeAssetsManagerTest, NoAvailableAssets)
impeller::Degrees DlDegrees
impeller::Size DlSize
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 switch_defs.h:52
impeller::Point DlPoint
constexpr float kSqrt2Over2
Definition constants.h:51
constexpr float kEhCloseEnough
Definition constants.h:57
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
void LineTo(PathBuilder *builder, Scalar x, Scalar y)
void CubicTo(PathBuilder *builder, Scalar x1, Scalar y1, Scalar x2, Scalar y2, Scalar x3, Scalar y3)
void Close(PathBuilder *builder)
static RoundRect MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
Definition round_rect.cc:9
static RoundSuperellipse MakeRectRadii(const Rect &rect, const RoundingRadii &radii)
constexpr bool IsEmpty() const
Returns true if either of the width or height are 0, negative, or NaN.
Definition rect.h:297
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129