Flutter Engine
 
Loading...
Searching...
No Matches
dl_vertices_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
9#include "gtest/gtest.h"
10
11namespace flutter {
12namespace testing {
13
14TEST(DisplayListVertices, MakeWithZeroAndNegativeVerticesAndIndices) {
15 std::shared_ptr<DlVertices> vertices1 = DlVertices::Make(
16 DlVertexMode::kTriangles, 0, nullptr, nullptr, nullptr, 0, nullptr);
17 EXPECT_NE(vertices1, nullptr);
18 EXPECT_EQ(vertices1->vertex_count(), 0);
19 EXPECT_EQ(vertices1->vertex_data(), nullptr);
20 EXPECT_EQ(vertices1->texture_coordinate_data(), nullptr);
21 EXPECT_EQ(vertices1->colors(), nullptr);
22 EXPECT_EQ(vertices1->index_count(), 0);
23 EXPECT_EQ(vertices1->indices(), nullptr);
24
25 std::shared_ptr<DlVertices> vertices2 = DlVertices::Make(
26 DlVertexMode::kTriangles, -1, nullptr, nullptr, nullptr, -1, nullptr);
27 EXPECT_NE(vertices2, nullptr);
28 EXPECT_EQ(vertices2->vertex_count(), 0);
29 EXPECT_EQ(vertices2->vertex_data(), nullptr);
30 EXPECT_EQ(vertices2->texture_coordinate_data(), nullptr);
31 EXPECT_EQ(vertices2->colors(), nullptr);
32 EXPECT_EQ(vertices2->index_count(), 0);
33 EXPECT_EQ(vertices2->indices(), nullptr);
34
35 TestEquals(*vertices1, *vertices2);
36}
37
38TEST(DisplayListVertices, MakeWithTexAndColorAndIndices) {
39 DlPoint coords[3] = {
40 DlPoint(2, 3),
41 DlPoint(5, 6),
42 DlPoint(15, 20),
43 };
44 DlPoint texture_coords[3] = {
45 DlPoint(102, 103),
46 DlPoint(105, 106),
47 DlPoint(115, 120),
48 };
49 DlColor colors[3] = {
53 };
54 uint16_t indices[6] = {
55 2, 1, 0, //
56 1, 2, 0,
57 };
58
59 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
60 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices);
61
62 ASSERT_NE(vertices, nullptr);
63 ASSERT_NE(vertices->vertex_data(), nullptr);
64 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
65 ASSERT_NE(vertices->colors(), nullptr);
66 ASSERT_NE(vertices->indices(), nullptr);
67
68 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
69 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
70 ASSERT_EQ(vertices->vertex_count(), 3);
71 for (int i = 0; i < 3; i++) {
72 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
73 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
74 ASSERT_EQ(vertices->colors()[i], colors[i]);
75 }
76 ASSERT_EQ(vertices->index_count(), 6);
77 for (int i = 0; i < 6; i++) {
78 ASSERT_EQ(vertices->indices()[i], indices[i]);
79 }
80}
81
82TEST(DisplayListVertices, MakeWithTexAndColor) {
83 DlPoint coords[3] = {
84 DlPoint(2, 3),
85 DlPoint(5, 6),
86 DlPoint(15, 20),
87 };
88 DlPoint texture_coords[3] = {
89 DlPoint(102, 103),
90 DlPoint(105, 106),
91 DlPoint(115, 120),
92 };
93 DlColor colors[3] = {
97 };
98
99 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
100 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, nullptr);
101
102 ASSERT_NE(vertices, nullptr);
103 ASSERT_NE(vertices->vertex_data(), nullptr);
104 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
105 ASSERT_NE(vertices->colors(), nullptr);
106 ASSERT_EQ(vertices->indices(), nullptr);
107
108 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
109 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
110 ASSERT_EQ(vertices->vertex_count(), 3);
111 for (int i = 0; i < 3; i++) {
112 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
113 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
114 ASSERT_EQ(vertices->colors()[i], colors[i]);
115 }
116 ASSERT_EQ(vertices->index_count(), 0);
117}
118
119TEST(DisplayListVertices, MakeWithTexAndIndices) {
120 DlPoint coords[3] = {
121 DlPoint(2, 3),
122 DlPoint(5, 6),
123 DlPoint(15, 20),
124 };
125 DlPoint texture_coords[3] = {
126 DlPoint(102, 103),
127 DlPoint(105, 106),
128 DlPoint(115, 120),
129 };
130 uint16_t indices[6] = {
131 2, 1, 0, //
132 1, 2, 0,
133 };
134
135 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
136 DlVertexMode::kTriangles, 3, coords, texture_coords, nullptr, 6, indices);
137
138 ASSERT_NE(vertices, nullptr);
139 ASSERT_NE(vertices->vertex_data(), nullptr);
140 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
141 ASSERT_EQ(vertices->colors(), nullptr);
142 ASSERT_NE(vertices->indices(), nullptr);
143
144 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
145 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
146 ASSERT_EQ(vertices->vertex_count(), 3);
147 for (int i = 0; i < 3; i++) {
148 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
149 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
150 }
151 ASSERT_EQ(vertices->index_count(), 6);
152 for (int i = 0; i < 6; i++) {
153 ASSERT_EQ(vertices->indices()[i], indices[i]);
154 }
155}
156
157TEST(DisplayListVertices, MakeWithColorAndIndices) {
158 DlPoint coords[3] = {
159 DlPoint(2, 3),
160 DlPoint(5, 6),
161 DlPoint(15, 20),
162 };
163 DlColor colors[3] = {
167 };
168 uint16_t indices[6] = {
169 2, 1, 0, //
170 1, 2, 0,
171 };
172
173 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
174 DlVertexMode::kTriangles, 3, coords, nullptr, colors, 6, indices);
175
176 ASSERT_NE(vertices, nullptr);
177 ASSERT_NE(vertices->vertex_data(), nullptr);
178 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
179 ASSERT_NE(vertices->colors(), nullptr);
180 ASSERT_NE(vertices->indices(), nullptr);
181
182 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
183 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
184 ASSERT_EQ(vertices->vertex_count(), 3);
185 for (int i = 0; i < 3; i++) {
186 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
187 ASSERT_EQ(vertices->colors()[i], colors[i]);
188 }
189 ASSERT_EQ(vertices->index_count(), 6);
190 for (int i = 0; i < 6; i++) {
191 ASSERT_EQ(vertices->indices()[i], indices[i]);
192 }
193}
194
195TEST(DisplayListVertices, MakeWithTex) {
196 DlPoint coords[3] = {
197 DlPoint(2, 3),
198 DlPoint(5, 6),
199 DlPoint(15, 20),
200 };
201 DlPoint texture_coords[3] = {
202 DlPoint(102, 103),
203 DlPoint(105, 106),
204 DlPoint(115, 120),
205 };
206
207 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
208 DlVertexMode::kTriangles, 3, coords, texture_coords, nullptr, 6, nullptr);
209
210 ASSERT_NE(vertices, nullptr);
211 ASSERT_NE(vertices->vertex_data(), nullptr);
212 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
213 ASSERT_EQ(vertices->colors(), nullptr);
214 ASSERT_EQ(vertices->indices(), nullptr);
215
216 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
217 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
218 ASSERT_EQ(vertices->vertex_count(), 3);
219 for (int i = 0; i < 3; i++) {
220 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
221 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
222 }
223 ASSERT_EQ(vertices->index_count(), 0);
224}
225
226TEST(DisplayListVertices, MakeWithColor) {
227 DlPoint coords[3] = {
228 DlPoint(2, 3),
229 DlPoint(5, 6),
230 DlPoint(15, 20),
231 };
232 DlColor colors[3] = {
236 };
237
238 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
239 DlVertexMode::kTriangles, 3, coords, nullptr, colors, 6, nullptr);
240
241 ASSERT_NE(vertices, nullptr);
242 ASSERT_NE(vertices->vertex_data(), nullptr);
243 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
244 ASSERT_NE(vertices->colors(), nullptr);
245 ASSERT_EQ(vertices->indices(), nullptr);
246
247 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
248 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
249 ASSERT_EQ(vertices->vertex_count(), 3);
250 for (int i = 0; i < 3; i++) {
251 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
252 ASSERT_EQ(vertices->colors()[i], colors[i]);
253 }
254 ASSERT_EQ(vertices->index_count(), 0);
255}
256
257TEST(DisplayListVertices, MakeWithIndices) {
258 DlPoint coords[3] = {
259 DlPoint(2, 3),
260 DlPoint(5, 6),
261 DlPoint(15, 20),
262 };
263 uint16_t indices[6] = {
264 2, 1, 0, //
265 1, 2, 0,
266 };
267
268 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
269 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 6, indices);
270
271 ASSERT_NE(vertices, nullptr);
272 ASSERT_NE(vertices->vertex_data(), nullptr);
273 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
274 ASSERT_EQ(vertices->colors(), nullptr);
275 ASSERT_NE(vertices->indices(), nullptr);
276
277 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
278 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
279 ASSERT_EQ(vertices->vertex_count(), 3);
280 for (int i = 0; i < 3; i++) {
281 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
282 }
283 ASSERT_EQ(vertices->index_count(), 6);
284 for (int i = 0; i < 6; i++) {
285 ASSERT_EQ(vertices->indices()[i], indices[i]);
286 }
287}
288
289TEST(DisplayListVertices, MakeWithNoOptionalData) {
290 DlPoint coords[3] = {
291 DlPoint(2, 3),
292 DlPoint(5, 6),
293 DlPoint(15, 20),
294 };
295
296 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
297 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 6, nullptr);
298
299 ASSERT_NE(vertices, nullptr);
300 ASSERT_NE(vertices->vertex_data(), nullptr);
301 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
302 ASSERT_EQ(vertices->colors(), nullptr);
303 ASSERT_EQ(vertices->indices(), nullptr);
304
305 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
306 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
307 ASSERT_EQ(vertices->vertex_count(), 3);
308 for (int i = 0; i < 3; i++) {
309 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
310 }
311 ASSERT_EQ(vertices->index_count(), 0);
312}
313
314TEST(DisplayListVertices, MakeWithIndicesButZeroIndexCount) {
315 DlPoint coords[3] = {
316 DlPoint(2, 3),
317 DlPoint(5, 6),
318 DlPoint(15, 20),
319 };
320 uint16_t indices[6] = {
321 2, 1, 0, //
322 1, 2, 0,
323 };
324
325 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
326 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 0, indices);
327
328 ASSERT_NE(vertices, nullptr);
329 ASSERT_NE(vertices->vertex_data(), nullptr);
330 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
331 ASSERT_EQ(vertices->colors(), nullptr);
332 ASSERT_EQ(vertices->indices(), nullptr);
333
334 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
335 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
336 ASSERT_EQ(vertices->vertex_count(), 3);
337 for (int i = 0; i < 3; i++) {
338 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
339 }
340 ASSERT_EQ(vertices->index_count(), 0);
341}
342
343TEST(DisplayListVertices, MakeWithIndicesButNegativeIndexCount) {
344 DlPoint coords[3] = {
345 DlPoint(2, 3),
346 DlPoint(5, 6),
347 DlPoint(15, 20),
348 };
349 uint16_t indices[6] = {
350 2, 1, 0, //
351 1, 2, 0,
352 };
353
354 std::shared_ptr<DlVertices> vertices = DlVertices::Make(
355 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, -5, indices);
356
357 ASSERT_NE(vertices, nullptr);
358 ASSERT_NE(vertices->vertex_data(), nullptr);
359 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
360 ASSERT_EQ(vertices->colors(), nullptr);
361 ASSERT_EQ(vertices->indices(), nullptr);
362
363 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
364 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
365 ASSERT_EQ(vertices->vertex_count(), 3);
366 for (int i = 0; i < 3; i++) {
367 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
368 }
369 ASSERT_EQ(vertices->index_count(), 0);
370}
371
373
374TEST(DisplayListVertices, BuilderFlags) {
375 Builder::Flags flags;
376 EXPECT_FALSE(flags.has_texture_coordinates);
377 EXPECT_FALSE(flags.has_colors);
378
380 EXPECT_TRUE(flags.has_texture_coordinates);
381 EXPECT_FALSE(flags.has_colors);
382
383 flags |= Builder::kHasColors;
384 EXPECT_TRUE(flags.has_texture_coordinates);
385 EXPECT_TRUE(flags.has_colors);
386
387 flags = Builder::Flags();
388 EXPECT_FALSE(flags.has_texture_coordinates);
389 EXPECT_FALSE(flags.has_colors);
390
391 flags |= Builder::kHasColors;
392 EXPECT_FALSE(flags.has_texture_coordinates);
393 EXPECT_TRUE(flags.has_colors);
394
396 EXPECT_TRUE(flags.has_texture_coordinates);
397 EXPECT_TRUE(flags.has_colors);
398
399 EXPECT_FALSE(Builder::kNone.has_texture_coordinates);
400 EXPECT_FALSE(Builder::kNone.has_colors);
401
402 EXPECT_TRUE(Builder::kHasTextureCoordinates.has_texture_coordinates);
403 EXPECT_FALSE(Builder::kHasTextureCoordinates.has_colors);
404
405 EXPECT_FALSE(Builder::kHasColors.has_texture_coordinates);
406 EXPECT_TRUE(Builder::kHasColors.has_colors);
407
409 .has_texture_coordinates);
411 .has_colors);
412}
413
414TEST(DisplayListVertices, BuildWithZeroAndNegativeVerticesAndIndices) {
416 EXPECT_TRUE(builder1.is_valid());
417 std::shared_ptr<DlVertices> vertices1 = builder1.build();
418 EXPECT_NE(vertices1, nullptr);
419 EXPECT_EQ(vertices1->vertex_count(), 0);
420 EXPECT_EQ(vertices1->vertex_data(), nullptr);
421 EXPECT_EQ(vertices1->texture_coordinate_data(), nullptr);
422 EXPECT_EQ(vertices1->colors(), nullptr);
423 EXPECT_EQ(vertices1->index_count(), 0);
424 EXPECT_EQ(vertices1->indices(), nullptr);
425
427 EXPECT_TRUE(builder2.is_valid());
428 std::shared_ptr<DlVertices> vertices2 = builder2.build();
429 EXPECT_NE(vertices2, nullptr);
430 EXPECT_EQ(vertices2->vertex_count(), 0);
431 EXPECT_EQ(vertices2->vertex_data(), nullptr);
432 EXPECT_EQ(vertices2->texture_coordinate_data(), nullptr);
433 EXPECT_EQ(vertices2->colors(), nullptr);
434 EXPECT_EQ(vertices2->index_count(), 0);
435 EXPECT_EQ(vertices2->indices(), nullptr);
436
437 TestEquals(*vertices1, *vertices2);
438}
439
440TEST(DisplayListVertices, BuildWithTexAndColorAndIndices) {
441 DlPoint coords[3] = {
442 DlPoint(2, 3),
443 DlPoint(5, 6),
444 DlPoint(15, 20),
445 };
446 DlPoint texture_coords[3] = {
447 DlPoint(102, 103),
448 DlPoint(105, 106),
449 DlPoint(115, 120),
450 };
451 DlColor colors[3] = {
455 };
456 uint16_t indices[6] = {
457 2, 1, 0, //
458 1, 2, 0,
459 };
460
461 Builder builder(DlVertexMode::kTriangles, 3, //
463 builder.store_vertices(coords);
464 builder.store_texture_coordinates(texture_coords);
465 builder.store_colors(colors);
466 builder.store_indices(indices);
467 std::shared_ptr<DlVertices> vertices = builder.build();
468
469 ASSERT_NE(vertices, nullptr);
470 ASSERT_NE(vertices->vertex_data(), nullptr);
471 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
472 ASSERT_NE(vertices->colors(), nullptr);
473 ASSERT_NE(vertices->indices(), nullptr);
474
475 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
476 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
477 ASSERT_EQ(vertices->vertex_count(), 3);
478 for (int i = 0; i < 3; i++) {
479 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
480 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
481 ASSERT_EQ(vertices->colors()[i], colors[i]);
482 }
483 ASSERT_EQ(vertices->index_count(), 6);
484 for (int i = 0; i < 6; i++) {
485 ASSERT_EQ(vertices->indices()[i], indices[i]);
486 }
487
488 Builder builder2(DlVertexMode::kTriangles, 3, //
490 builder2.store_vertices(coords);
491 builder2.store_texture_coordinates(texture_coords);
492 builder2.store_colors(colors);
493 builder2.store_indices(indices);
494 std::shared_ptr<DlVertices> vertices2 = builder2.build();
495
496 TestEquals(*vertices, *vertices2);
497
498 std::shared_ptr<DlVertices> vertices3 = DlVertices::Make(
499 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices);
500
501 TestEquals(*vertices, *vertices3);
502}
503
504TEST(DisplayListVertices, BuildWithTexAndColor) {
505 DlPoint coords[3] = {
506 DlPoint(2, 3),
507 DlPoint(5, 6),
508 DlPoint(15, 20),
509 };
510 DlPoint texture_coords[3] = {
511 DlPoint(102, 103),
512 DlPoint(105, 106),
513 DlPoint(115, 120),
514 };
515 DlColor colors[3] = {
519 };
520
521 Builder builder(DlVertexMode::kTriangles, 3, //
523 builder.store_vertices(coords);
524 builder.store_texture_coordinates(texture_coords);
525 builder.store_colors(colors);
526 std::shared_ptr<DlVertices> vertices = builder.build();
527
528 ASSERT_NE(vertices, nullptr);
529 ASSERT_NE(vertices->vertex_data(), nullptr);
530 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
531 ASSERT_NE(vertices->colors(), nullptr);
532 ASSERT_EQ(vertices->indices(), nullptr);
533
534 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
535 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
536 ASSERT_EQ(vertices->vertex_count(), 3);
537 for (int i = 0; i < 3; i++) {
538 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
539 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
540 ASSERT_EQ(vertices->colors()[i], colors[i]);
541 }
542 ASSERT_EQ(vertices->index_count(), 0);
543}
544
545TEST(DisplayListVertices, BuildWithTexAndIndices) {
546 DlPoint coords[3] = {
547 DlPoint(2, 3),
548 DlPoint(5, 6),
549 DlPoint(15, 20),
550 };
551 DlPoint texture_coords[3] = {
552 DlPoint(102, 103),
553 DlPoint(105, 106),
554 DlPoint(115, 120),
555 };
556 uint16_t indices[6] = {
557 2, 1, 0, //
558 1, 2, 0,
559 };
560
561 Builder builder(DlVertexMode::kTriangles, 3, //
563 builder.store_vertices(coords);
564 builder.store_texture_coordinates(texture_coords);
565 builder.store_indices(indices);
566 std::shared_ptr<DlVertices> vertices = builder.build();
567
568 ASSERT_NE(vertices, nullptr);
569 ASSERT_NE(vertices->vertex_data(), nullptr);
570 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
571 ASSERT_EQ(vertices->colors(), nullptr);
572 ASSERT_NE(vertices->indices(), nullptr);
573
574 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
575 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
576 ASSERT_EQ(vertices->vertex_count(), 3);
577 for (int i = 0; i < 3; i++) {
578 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
579 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
580 }
581 ASSERT_EQ(vertices->index_count(), 6);
582 for (int i = 0; i < 6; i++) {
583 ASSERT_EQ(vertices->indices()[i], indices[i]);
584 }
585}
586
587TEST(DisplayListVertices, BuildWithColorAndIndices) {
588 DlPoint coords[3] = {
589 DlPoint(2, 3),
590 DlPoint(5, 6),
591 DlPoint(15, 20),
592 };
593 uint32_t colors[3] = {
594 0xffff0000,
595 0xff00ffff,
596 0xff00ff00,
597 };
598 uint16_t indices[6] = {
599 2, 1, 0, //
600 1, 2, 0,
601 };
602
603 Builder builder(DlVertexMode::kTriangles, 3, //
605 builder.store_vertices(coords);
606 builder.store_colors(colors);
607 builder.store_indices(indices);
608 std::shared_ptr<DlVertices> vertices = builder.build();
609
610 ASSERT_NE(vertices, nullptr);
611 ASSERT_NE(vertices->vertex_data(), nullptr);
612 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
613 ASSERT_NE(vertices->colors(), nullptr);
614 ASSERT_NE(vertices->indices(), nullptr);
615
616 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
617 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
618 ASSERT_EQ(vertices->vertex_count(), 3);
619 for (int i = 0; i < 3; i++) {
620 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
621 ASSERT_EQ(vertices->colors()[i].argb(), colors[i]);
622 }
623 ASSERT_EQ(vertices->index_count(), 6);
624 for (int i = 0; i < 6; i++) {
625 ASSERT_EQ(vertices->indices()[i], indices[i]);
626 }
627}
628
629TEST(DisplayListVertices, BuildWithTexUsingPoints) {
630 DlPoint coords[3] = {
631 DlPoint(2, 3),
632 DlPoint(5, 6),
633 DlPoint(15, 20),
634 };
635 DlPoint texture_coords[3] = {
636 DlPoint(102, 103),
637 DlPoint(105, 106),
638 DlPoint(115, 120),
639 };
640
641 Builder builder(DlVertexMode::kTriangles, 3, //
643 builder.store_vertices(coords);
644 builder.store_texture_coordinates(texture_coords);
645 std::shared_ptr<DlVertices> vertices = builder.build();
646
647 ASSERT_NE(vertices, nullptr);
648 ASSERT_NE(vertices->vertex_data(), nullptr);
649 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
650 ASSERT_EQ(vertices->colors(), nullptr);
651 ASSERT_EQ(vertices->indices(), nullptr);
652
653 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
654 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
655 ASSERT_EQ(vertices->vertex_count(), 3);
656 for (int i = 0; i < 3; i++) {
657 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
658 ASSERT_EQ(vertices->texture_coordinate_data()[i], texture_coords[i]);
659 }
660 ASSERT_EQ(vertices->index_count(), 0);
661}
662
663TEST(DisplayListVertices, BuildWithTexUsingFloats) {
664 float coords[6] = {
665 2, 3, //
666 5, 6, //
667 15, 20,
668 };
669 float texture_coords[6] = {
670 102, 103, //
671 105, 106, //
672 115, 120,
673 };
674
675 Builder builder(DlVertexMode::kTriangles, 3, //
677 builder.store_vertices(coords);
678 builder.store_texture_coordinates(texture_coords);
679 std::shared_ptr<DlVertices> vertices = builder.build();
680
681 ASSERT_NE(vertices, nullptr);
682 ASSERT_NE(vertices->vertex_data(), nullptr);
683 ASSERT_NE(vertices->texture_coordinate_data(), nullptr);
684 ASSERT_EQ(vertices->colors(), nullptr);
685 ASSERT_EQ(vertices->indices(), nullptr);
686
687 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
688 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
689 ASSERT_EQ(vertices->vertex_count(), 3);
690 for (int i = 0; i < 3; i++) {
691 ASSERT_EQ(vertices->vertex_data()[i].x, coords[i * 2 + 0]);
692 ASSERT_EQ(vertices->vertex_data()[i].y, coords[i * 2 + 1]);
693 ASSERT_EQ(vertices->texture_coordinate_data()[i].x,
694 texture_coords[i * 2 + 0]);
695 ASSERT_EQ(vertices->texture_coordinate_data()[i].y,
696 texture_coords[i * 2 + 1]);
697 }
698 ASSERT_EQ(vertices->index_count(), 0);
699}
700
701TEST(DisplayListVertices, BuildUsingFloatsSameAsPoints) {
702 DlPoint coord_points[3] = {
703 DlPoint(2, 3),
704 DlPoint(5, 6),
705 DlPoint(15, 20),
706 };
707 DlPoint texture_coord_points[3] = {
708 DlPoint(102, 103),
709 DlPoint(105, 106),
710 DlPoint(115, 120),
711 };
712
713 float coord_floats[6] = {
714 2, 3, //
715 5, 6, //
716 15, 20,
717 };
718 float texture_coord_floats[6] = {
719 102, 103, //
720 105, 106, //
721 115, 120,
722 };
723
724 Builder builder_points(DlVertexMode::kTriangles, 3, //
726 builder_points.store_vertices(coord_points);
727 builder_points.store_texture_coordinates(texture_coord_points);
728 std::shared_ptr<DlVertices> vertices_points = builder_points.build();
729
730 Builder builder_floats(DlVertexMode::kTriangles, 3, //
732 builder_floats.store_vertices(coord_floats);
733 builder_floats.store_texture_coordinates(texture_coord_floats);
734 std::shared_ptr<DlVertices> vertices_floats = builder_floats.build();
735
736 TestEquals(*vertices_points, *vertices_floats);
737}
738
739TEST(DisplayListVertices, BuildWithColor) {
740 DlPoint coords[3] = {
741 DlPoint(2, 3),
742 DlPoint(5, 6),
743 DlPoint(15, 20),
744 };
745 uint32_t colors[3] = {
746 0xffff0000,
747 0xff00ffff,
748 0xff00ff00,
749 };
750
751 Builder builder(DlVertexMode::kTriangles, 3, //
753 builder.store_vertices(coords);
754 builder.store_colors(colors);
755 std::shared_ptr<DlVertices> vertices = builder.build();
756
757 ASSERT_NE(vertices, nullptr);
758 ASSERT_NE(vertices->vertex_data(), nullptr);
759 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
760 ASSERT_NE(vertices->colors(), nullptr);
761 ASSERT_EQ(vertices->indices(), nullptr);
762
763 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
764 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
765 ASSERT_EQ(vertices->vertex_count(), 3);
766 for (int i = 0; i < 3; i++) {
767 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
768 ASSERT_EQ(vertices->colors()[i].argb(), colors[i]);
769 }
770 ASSERT_EQ(vertices->index_count(), 0);
771}
772
773TEST(DisplayListVertices, BuildWithIndices) {
774 DlPoint coords[3] = {
775 DlPoint(2, 3),
776 DlPoint(5, 6),
777 DlPoint(15, 20),
778 };
779 uint16_t indices[6] = {
780 2, 1, 0, //
781 1, 2, 0,
782 };
783
785 builder.store_vertices(coords);
786 builder.store_indices(indices);
787 std::shared_ptr<DlVertices> vertices = builder.build();
788
789 ASSERT_NE(vertices, nullptr);
790 ASSERT_NE(vertices->vertex_data(), nullptr);
791 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
792 ASSERT_EQ(vertices->colors(), nullptr);
793 ASSERT_NE(vertices->indices(), nullptr);
794
795 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
796 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
797 ASSERT_EQ(vertices->vertex_count(), 3);
798 for (int i = 0; i < 3; i++) {
799 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
800 }
801 ASSERT_EQ(vertices->index_count(), 6);
802 for (int i = 0; i < 6; i++) {
803 ASSERT_EQ(vertices->indices()[i], indices[i]);
804 }
805}
806
807TEST(DisplayListVertices, BuildWithNoOptionalData) {
808 DlPoint coords[3] = {
809 DlPoint(2, 3),
810 DlPoint(5, 6),
811 DlPoint(15, 20),
812 };
813
815 builder.store_vertices(coords);
816 std::shared_ptr<DlVertices> vertices = builder.build();
817
818 ASSERT_NE(vertices, nullptr);
819 ASSERT_NE(vertices->vertex_data(), nullptr);
820 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
821 ASSERT_EQ(vertices->colors(), nullptr);
822 ASSERT_EQ(vertices->indices(), nullptr);
823
824 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
825 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
826 ASSERT_EQ(vertices->vertex_count(), 3);
827 for (int i = 0; i < 3; i++) {
828 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
829 }
830 ASSERT_EQ(vertices->index_count(), 0);
831}
832
833TEST(DisplayListVertices, BuildWithNegativeIndexCount) {
834 DlPoint coords[3] = {
835 DlPoint(2, 3),
836 DlPoint(5, 6),
837 DlPoint(15, 20),
838 };
839
841 builder.store_vertices(coords);
842 std::shared_ptr<DlVertices> vertices = builder.build();
843
844 ASSERT_NE(vertices, nullptr);
845 ASSERT_NE(vertices->vertex_data(), nullptr);
846 ASSERT_EQ(vertices->texture_coordinate_data(), nullptr);
847 ASSERT_EQ(vertices->colors(), nullptr);
848 ASSERT_EQ(vertices->indices(), nullptr);
849
850 ASSERT_EQ(vertices->GetBounds(), DlRect::MakeLTRB(2, 3, 15, 20));
851 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
852 ASSERT_EQ(vertices->vertex_count(), 3);
853 for (int i = 0; i < 3; i++) {
854 ASSERT_EQ(vertices->vertex_data()[i], coords[i]);
855 }
856 ASSERT_EQ(vertices->index_count(), 0);
857}
858
859TEST(DisplayListVertices, TestEquals) {
860 DlPoint coords[3] = {
861 DlPoint(2, 3),
862 DlPoint(5, 6),
863 DlPoint(15, 20),
864 };
865 DlPoint texture_coords[3] = {
866 DlPoint(102, 103),
867 DlPoint(105, 106),
868 DlPoint(115, 120),
869 };
870 DlColor colors[3] = {
874 };
875 uint16_t indices[6] = {
876 2, 1, 0, //
877 1, 2, 0,
878 };
879
880 std::shared_ptr<DlVertices> vertices1 = DlVertices::Make(
881 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices);
882 std::shared_ptr<DlVertices> vertices2 = DlVertices::Make(
883 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices);
884 TestEquals(*vertices1, *vertices2);
885}
886
887TEST(DisplayListVertices, TestNotEquals) {
888 DlPoint coords[4] = {
889 DlPoint(2, 3),
890 DlPoint(5, 6),
891 DlPoint(15, 20),
892 DlPoint(53, 62),
893 };
894 DlPoint wrong_coords[4] = {
895 DlPoint(2, 3),
896 DlPoint(5, 6),
897 DlPoint(15, 20),
898 DlPoint(57, 62),
899 };
900 DlPoint texture_coords[4] = {
901 DlPoint(102, 103),
902 DlPoint(105, 106),
903 DlPoint(115, 120),
904 DlPoint(153, 162),
905 };
906 DlPoint wrong_texture_coords[4] = {
907 DlPoint(102, 103),
908 DlPoint(105, 106),
909 DlPoint(115, 121),
910 DlPoint(153, 162),
911 };
912 DlColor colors[4] = {
917 };
918 DlColor wrong_colors[4] = {
923 };
924 uint16_t indices[9] = {
925 2, 1, 0, //
926 1, 2, 0, //
927 1, 2, 3,
928 };
929 uint16_t wrong_indices[9] = {
930 2, 1, 0, //
931 1, 2, 0, //
932 2, 3, 1,
933 };
934
935 std::shared_ptr<DlVertices> vertices1 = DlVertices::Make(
936 DlVertexMode::kTriangles, 4, coords, texture_coords, colors, 9, indices);
937
938 {
939 std::shared_ptr<DlVertices> vertices2 =
941 texture_coords, colors, 9, indices);
942 TestNotEquals(*vertices1, *vertices2, "vertex mode differs");
943 }
944 {
945 std::shared_ptr<DlVertices> vertices2 =
947 texture_coords, colors, 9, indices);
948 TestNotEquals(*vertices1, *vertices2, "vertex count differs");
949 }
950 {
951 std::shared_ptr<DlVertices> vertices2 =
952 DlVertices::Make(DlVertexMode::kTriangles, 4, wrong_coords, //
953 texture_coords, colors, 9, indices);
954 TestNotEquals(*vertices1, *vertices2, "vertex coordinates differ");
955 }
956 {
957 std::shared_ptr<DlVertices> vertices2 =
959 wrong_texture_coords, colors, 9, indices);
960 TestNotEquals(*vertices1, *vertices2, "texture coordinates differ");
961 }
962 {
963 std::shared_ptr<DlVertices> vertices2 =
965 texture_coords, wrong_colors, 9, indices);
966 TestNotEquals(*vertices1, *vertices2, "colors differ");
967 }
968 {
969 std::shared_ptr<DlVertices> vertices2 =
971 texture_coords, colors, 6, indices);
972 TestNotEquals(*vertices1, *vertices2, "index count differs");
973 }
974 {
975 std::shared_ptr<DlVertices> vertices2 =
977 texture_coords, colors, 9, wrong_indices);
978 TestNotEquals(*vertices1, *vertices2, "indices differ");
979 }
980}
981
982} // namespace testing
983} // namespace flutter
A utility class to build up a |DlVertices| object one set of data at a time.
Definition dl_vertices.h:73
void store_vertices(const DlPoint vertices[])
Copies the indicated list of points as vertices.
void store_indices(const uint16_t indices[])
Copies the indicated list of 16-bit indices as vertex indices.
static constexpr Flags kNone
Definition dl_vertices.h:94
bool is_valid() const
Returns true iff the underlying object was successfully allocated.
void store_texture_coordinates(const DlPoint points[])
Copies the indicated list of points as texture coordinates.
std::shared_ptr< DlVertices > build()
Finalizes and the constructed DlVertices object.
static constexpr Flags kHasColors
Definition dl_vertices.h:96
void store_colors(const DlColor colors[])
Copies the indicated list of colors as vertex colors.
static constexpr Flags kHasTextureCoordinates
Definition dl_vertices.h:95
static std::shared_ptr< DlVertices > Make(DlVertexMode mode, int vertex_count, const DlPoint vertices[], const DlPoint texture_coordinates[], const DlColor colors[], int index_count=0, const uint16_t indices[]=nullptr, const DlRect *bounds=nullptr)
Constructs a DlVector with compact inline storage for all of its required and optional lists of data.
static void TestEquals(const T &source1, const U &source2)
static void TestNotEquals(T &source1, U &source2, const std::string &label)
TEST(NativeAssetsManagerTest, NoAvailableAssets)
@ kTriangles
The vertices are taken 3 at a time to form a triangle.
impeller::Point DlPoint
static constexpr DlColor kMagenta()
Definition dl_color.h:75
static constexpr DlColor kBlue()
Definition dl_color.h:73
static constexpr DlColor kRed()
Definition dl_color.h:71
static constexpr DlColor kGreen()
Definition dl_color.h:72
static constexpr DlColor kCyan()
Definition dl_color.h:74
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129
flags to indicate/promise which of the optional texture coordinates or colors will be supplied during...
Definition dl_vertices.h:78