Flutter Engine
The Flutter Engine
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
5#include "flutter/display_list/dl_builder.h"
6#include "flutter/display_list/dl_vertices.h"
7#include "flutter/display_list/testing/dl_test_equality.h"
8#include "flutter/display_list/utils/dl_comparable.h"
9#include "gtest/gtest.h"
10
11namespace flutter {
12namespace testing {
13
14TEST(DisplayListVertices, MakeWithZeroAndNegativeVerticesAndIndices) {
15 std::shared_ptr<const 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->vertices(), nullptr);
20 EXPECT_EQ(vertices1->texture_coordinates(), 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<const 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->vertices(), nullptr);
30 EXPECT_EQ(vertices2->texture_coordinates(), 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 SkPoint coords[3] = {
40 SkPoint::Make(2, 3),
41 SkPoint::Make(5, 6),
42 SkPoint::Make(15, 20),
43 };
44 SkPoint texture_coords[3] = {
45 SkPoint::Make(102, 103),
46 SkPoint::Make(105, 106),
47 SkPoint::Make(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<const DlVertices> vertices = DlVertices::Make(
60 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices);
61
62 ASSERT_NE(vertices, nullptr);
63 ASSERT_NE(vertices->vertices(), nullptr);
64 ASSERT_NE(vertices->texture_coordinates(), nullptr);
65 ASSERT_NE(vertices->colors(), nullptr);
66 ASSERT_NE(vertices->indices(), nullptr);
67
68 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
73 ASSERT_EQ(vertices->texture_coordinates()[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 SkPoint coords[3] = {
84 SkPoint::Make(2, 3),
85 SkPoint::Make(5, 6),
86 SkPoint::Make(15, 20),
87 };
88 SkPoint texture_coords[3] = {
89 SkPoint::Make(102, 103),
90 SkPoint::Make(105, 106),
91 SkPoint::Make(115, 120),
92 };
93 DlColor colors[3] = {
97 };
98
99 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
100 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, nullptr);
101
102 ASSERT_NE(vertices, nullptr);
103 ASSERT_NE(vertices->vertices(), nullptr);
104 ASSERT_NE(vertices->texture_coordinates(), nullptr);
105 ASSERT_NE(vertices->colors(), nullptr);
106 ASSERT_EQ(vertices->indices(), nullptr);
107
108 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
113 ASSERT_EQ(vertices->texture_coordinates()[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 SkPoint coords[3] = {
121 SkPoint::Make(2, 3),
122 SkPoint::Make(5, 6),
123 SkPoint::Make(15, 20),
124 };
125 SkPoint texture_coords[3] = {
126 SkPoint::Make(102, 103),
127 SkPoint::Make(105, 106),
128 SkPoint::Make(115, 120),
129 };
130 uint16_t indices[6] = {
131 2, 1, 0, //
132 1, 2, 0,
133 };
134
135 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
136 DlVertexMode::kTriangles, 3, coords, texture_coords, nullptr, 6, indices);
137
138 ASSERT_NE(vertices, nullptr);
139 ASSERT_NE(vertices->vertices(), nullptr);
140 ASSERT_NE(vertices->texture_coordinates(), nullptr);
141 ASSERT_EQ(vertices->colors(), nullptr);
142 ASSERT_NE(vertices->indices(), nullptr);
143
144 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
149 ASSERT_EQ(vertices->texture_coordinates()[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 SkPoint coords[3] = {
159 SkPoint::Make(2, 3),
160 SkPoint::Make(5, 6),
161 SkPoint::Make(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<const DlVertices> vertices = DlVertices::Make(
174 DlVertexMode::kTriangles, 3, coords, nullptr, colors, 6, indices);
175
176 ASSERT_NE(vertices, nullptr);
177 ASSERT_NE(vertices->vertices(), nullptr);
178 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
179 ASSERT_NE(vertices->colors(), nullptr);
180 ASSERT_NE(vertices->indices(), nullptr);
181
182 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[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 SkPoint coords[3] = {
197 SkPoint::Make(2, 3),
198 SkPoint::Make(5, 6),
199 SkPoint::Make(15, 20),
200 };
201 SkPoint texture_coords[3] = {
202 SkPoint::Make(102, 103),
203 SkPoint::Make(105, 106),
204 SkPoint::Make(115, 120),
205 };
206
207 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
208 DlVertexMode::kTriangles, 3, coords, texture_coords, nullptr, 6, nullptr);
209
210 ASSERT_NE(vertices, nullptr);
211 ASSERT_NE(vertices->vertices(), nullptr);
212 ASSERT_NE(vertices->texture_coordinates(), nullptr);
213 ASSERT_EQ(vertices->colors(), nullptr);
214 ASSERT_EQ(vertices->indices(), nullptr);
215
216 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
221 ASSERT_EQ(vertices->texture_coordinates()[i], texture_coords[i]);
222 }
223 ASSERT_EQ(vertices->index_count(), 0);
224}
225
226TEST(DisplayListVertices, MakeWithColor) {
227 SkPoint coords[3] = {
228 SkPoint::Make(2, 3),
229 SkPoint::Make(5, 6),
230 SkPoint::Make(15, 20),
231 };
232 DlColor colors[3] = {
236 };
237
238 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
239 DlVertexMode::kTriangles, 3, coords, nullptr, colors, 6, nullptr);
240
241 ASSERT_NE(vertices, nullptr);
242 ASSERT_NE(vertices->vertices(), nullptr);
243 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
244 ASSERT_NE(vertices->colors(), nullptr);
245 ASSERT_EQ(vertices->indices(), nullptr);
246
247 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[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 SkPoint coords[3] = {
259 SkPoint::Make(2, 3),
260 SkPoint::Make(5, 6),
261 SkPoint::Make(15, 20),
262 };
263 uint16_t indices[6] = {
264 2, 1, 0, //
265 1, 2, 0,
266 };
267
268 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
269 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 6, indices);
270
271 ASSERT_NE(vertices, nullptr);
272 ASSERT_NE(vertices->vertices(), nullptr);
273 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
274 ASSERT_EQ(vertices->colors(), nullptr);
275 ASSERT_NE(vertices->indices(), nullptr);
276
277 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[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 SkPoint coords[3] = {
291 SkPoint::Make(2, 3),
292 SkPoint::Make(5, 6),
293 SkPoint::Make(15, 20),
294 };
295
296 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
297 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 6, nullptr);
298
299 ASSERT_NE(vertices, nullptr);
300 ASSERT_NE(vertices->vertices(), nullptr);
301 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
302 ASSERT_EQ(vertices->colors(), nullptr);
303 ASSERT_EQ(vertices->indices(), nullptr);
304
305 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
310 }
311 ASSERT_EQ(vertices->index_count(), 0);
312}
313
314TEST(DisplayListVertices, MakeWithIndicesButZeroIndexCount) {
315 SkPoint coords[3] = {
316 SkPoint::Make(2, 3),
317 SkPoint::Make(5, 6),
318 SkPoint::Make(15, 20),
319 };
320 uint16_t indices[6] = {
321 2, 1, 0, //
322 1, 2, 0,
323 };
324
325 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
326 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, 0, indices);
327
328 ASSERT_NE(vertices, nullptr);
329 ASSERT_NE(vertices->vertices(), nullptr);
330 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
331 ASSERT_EQ(vertices->colors(), nullptr);
332 ASSERT_EQ(vertices->indices(), nullptr);
333
334 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
339 }
340 ASSERT_EQ(vertices->index_count(), 0);
341}
342
343TEST(DisplayListVertices, MakeWithIndicesButNegativeIndexCount) {
344 SkPoint coords[3] = {
345 SkPoint::Make(2, 3),
346 SkPoint::Make(5, 6),
347 SkPoint::Make(15, 20),
348 };
349 uint16_t indices[6] = {
350 2, 1, 0, //
351 1, 2, 0,
352 };
353
354 std::shared_ptr<const DlVertices> vertices = DlVertices::Make(
355 DlVertexMode::kTriangles, 3, coords, nullptr, nullptr, -5, indices);
356
357 ASSERT_NE(vertices, nullptr);
358 ASSERT_NE(vertices->vertices(), nullptr);
359 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
360 ASSERT_EQ(vertices->colors(), nullptr);
361 ASSERT_EQ(vertices->indices(), nullptr);
362
363 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
368 }
369 ASSERT_EQ(vertices->index_count(), 0);
370}
371
373
374TEST(DisplayListVertices, BuilderFlags) {
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
384 EXPECT_TRUE(flags.has_texture_coordinates);
385 EXPECT_TRUE(flags.has_colors);
386
388 EXPECT_FALSE(flags.has_texture_coordinates);
389 EXPECT_FALSE(flags.has_colors);
390
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);
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->vertices(), nullptr);
421 EXPECT_EQ(vertices1->texture_coordinates(), 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->vertices(), nullptr);
432 EXPECT_EQ(vertices2->texture_coordinates(), 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 SkPoint coords[3] = {
442 SkPoint::Make(2, 3),
443 SkPoint::Make(5, 6),
444 SkPoint::Make(15, 20),
445 };
446 SkPoint texture_coords[3] = {
447 SkPoint::Make(102, 103),
448 SkPoint::Make(105, 106),
449 SkPoint::Make(115, 120),
450 };
451 DlColor colors[3] = {
455 };
456 uint16_t indices[6] = {
457 2, 1, 0, //
458 1, 2, 0,
459 };
460
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<const DlVertices> vertices = builder.build();
468
469 ASSERT_NE(vertices, nullptr);
470 ASSERT_NE(vertices->vertices(), nullptr);
471 ASSERT_NE(vertices->texture_coordinates(), nullptr);
472 ASSERT_NE(vertices->colors(), nullptr);
473 ASSERT_NE(vertices->indices(), nullptr);
474
475 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
480 ASSERT_EQ(vertices->texture_coordinates()[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<const DlVertices> vertices2 = builder2.build();
495
496 TestEquals(*vertices, *vertices2);
497
498 std::shared_ptr<const 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 SkPoint coords[3] = {
506 SkPoint::Make(2, 3),
507 SkPoint::Make(5, 6),
508 SkPoint::Make(15, 20),
509 };
510 SkPoint texture_coords[3] = {
511 SkPoint::Make(102, 103),
512 SkPoint::Make(105, 106),
513 SkPoint::Make(115, 120),
514 };
515 DlColor colors[3] = {
519 };
520
523 builder.store_vertices(coords);
524 builder.store_texture_coordinates(texture_coords);
525 builder.store_colors(colors);
526 std::shared_ptr<const DlVertices> vertices = builder.build();
527
528 ASSERT_NE(vertices, nullptr);
529 ASSERT_NE(vertices->vertices(), nullptr);
530 ASSERT_NE(vertices->texture_coordinates(), nullptr);
531 ASSERT_NE(vertices->colors(), nullptr);
532 ASSERT_EQ(vertices->indices(), nullptr);
533
534 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
539 ASSERT_EQ(vertices->texture_coordinates()[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 SkPoint coords[3] = {
547 SkPoint::Make(2, 3),
548 SkPoint::Make(5, 6),
549 SkPoint::Make(15, 20),
550 };
551 SkPoint texture_coords[3] = {
552 SkPoint::Make(102, 103),
553 SkPoint::Make(105, 106),
554 SkPoint::Make(115, 120),
555 };
556 uint16_t indices[6] = {
557 2, 1, 0, //
558 1, 2, 0,
559 };
560
563 builder.store_vertices(coords);
564 builder.store_texture_coordinates(texture_coords);
565 builder.store_indices(indices);
566 std::shared_ptr<const DlVertices> vertices = builder.build();
567
568 ASSERT_NE(vertices, nullptr);
569 ASSERT_NE(vertices->vertices(), nullptr);
570 ASSERT_NE(vertices->texture_coordinates(), nullptr);
571 ASSERT_EQ(vertices->colors(), nullptr);
572 ASSERT_NE(vertices->indices(), nullptr);
573
574 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
579 ASSERT_EQ(vertices->texture_coordinates()[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 SkPoint coords[3] = {
589 SkPoint::Make(2, 3),
590 SkPoint::Make(5, 6),
591 SkPoint::Make(15, 20),
592 };
593 SkColor colors[3] = {
597 };
598 uint16_t indices[6] = {
599 2, 1, 0, //
600 1, 2, 0,
601 };
602
605 builder.store_vertices(coords);
606 builder.store_colors(colors);
607 builder.store_indices(indices);
608 std::shared_ptr<const DlVertices> vertices = builder.build();
609
610 ASSERT_NE(vertices, nullptr);
611 ASSERT_NE(vertices->vertices(), nullptr);
612 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
613 ASSERT_NE(vertices->colors(), nullptr);
614 ASSERT_NE(vertices->indices(), nullptr);
615
616 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
621 ASSERT_EQ(vertices->colors()[i], 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 SkPoint coords[3] = {
631 SkPoint::Make(2, 3),
632 SkPoint::Make(5, 6),
633 SkPoint::Make(15, 20),
634 };
635 SkPoint texture_coords[3] = {
636 SkPoint::Make(102, 103),
637 SkPoint::Make(105, 106),
638 SkPoint::Make(115, 120),
639 };
640
643 builder.store_vertices(coords);
644 builder.store_texture_coordinates(texture_coords);
645 std::shared_ptr<const DlVertices> vertices = builder.build();
646
647 ASSERT_NE(vertices, nullptr);
648 ASSERT_NE(vertices->vertices(), nullptr);
649 ASSERT_NE(vertices->texture_coordinates(), nullptr);
650 ASSERT_EQ(vertices->colors(), nullptr);
651 ASSERT_EQ(vertices->indices(), nullptr);
652
653 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i], coords[i]);
658 ASSERT_EQ(vertices->texture_coordinates()[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
677 builder.store_vertices(coords);
678 builder.store_texture_coordinates(texture_coords);
679 std::shared_ptr<const DlVertices> vertices = builder.build();
680
681 ASSERT_NE(vertices, nullptr);
682 ASSERT_NE(vertices->vertices(), nullptr);
683 ASSERT_NE(vertices->texture_coordinates(), nullptr);
684 ASSERT_EQ(vertices->colors(), nullptr);
685 ASSERT_EQ(vertices->indices(), nullptr);
686
687 ASSERT_EQ(vertices->bounds(), SkRect::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->vertices()[i].fX, coords[i * 2 + 0]);
692 ASSERT_EQ(vertices->vertices()[i].fY, coords[i * 2 + 1]);
693 ASSERT_EQ(vertices->texture_coordinates()[i].fX, texture_coords[i * 2 + 0]);
694 ASSERT_EQ(vertices->texture_coordinates()[i].fY, texture_coords[i * 2 + 1]);
695 }
696 ASSERT_EQ(vertices->index_count(), 0);
697}
698
699TEST(DisplayListVertices, BuildUsingFloatsSameAsPoints) {
700 SkPoint coord_points[3] = {
701 SkPoint::Make(2, 3),
702 SkPoint::Make(5, 6),
703 SkPoint::Make(15, 20),
704 };
705 SkPoint texture_coord_points[3] = {
706 SkPoint::Make(102, 103),
707 SkPoint::Make(105, 106),
708 SkPoint::Make(115, 120),
709 };
710
711 float coord_floats[6] = {
712 2, 3, //
713 5, 6, //
714 15, 20,
715 };
716 float texture_coord_floats[6] = {
717 102, 103, //
718 105, 106, //
719 115, 120,
720 };
721
722 Builder builder_points(DlVertexMode::kTriangles, 3, //
724 builder_points.store_vertices(coord_points);
725 builder_points.store_texture_coordinates(texture_coord_points);
726 std::shared_ptr<const DlVertices> vertices_points = builder_points.build();
727
728 Builder builder_floats(DlVertexMode::kTriangles, 3, //
730 builder_floats.store_vertices(coord_floats);
731 builder_floats.store_texture_coordinates(texture_coord_floats);
732 std::shared_ptr<const DlVertices> vertices_floats = builder_floats.build();
733
734 TestEquals(*vertices_points, *vertices_floats);
735}
736
737TEST(DisplayListVertices, BuildWithColor) {
738 SkPoint coords[3] = {
739 SkPoint::Make(2, 3),
740 SkPoint::Make(5, 6),
741 SkPoint::Make(15, 20),
742 };
743 SkColor colors[3] = {
747 };
748
751 builder.store_vertices(coords);
752 builder.store_colors(colors);
753 std::shared_ptr<const DlVertices> vertices = builder.build();
754
755 ASSERT_NE(vertices, nullptr);
756 ASSERT_NE(vertices->vertices(), nullptr);
757 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
758 ASSERT_NE(vertices->colors(), nullptr);
759 ASSERT_EQ(vertices->indices(), nullptr);
760
761 ASSERT_EQ(vertices->bounds(), SkRect::MakeLTRB(2, 3, 15, 20));
762 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
763 ASSERT_EQ(vertices->vertex_count(), 3);
764 for (int i = 0; i < 3; i++) {
765 ASSERT_EQ(vertices->vertices()[i], coords[i]);
766 ASSERT_EQ(vertices->colors()[i], colors[i]);
767 }
768 ASSERT_EQ(vertices->index_count(), 0);
769}
770
771TEST(DisplayListVertices, BuildWithIndices) {
772 SkPoint coords[3] = {
773 SkPoint::Make(2, 3),
774 SkPoint::Make(5, 6),
775 SkPoint::Make(15, 20),
776 };
777 uint16_t indices[6] = {
778 2, 1, 0, //
779 1, 2, 0,
780 };
781
783 builder.store_vertices(coords);
784 builder.store_indices(indices);
785 std::shared_ptr<const DlVertices> vertices = builder.build();
786
787 ASSERT_NE(vertices, nullptr);
788 ASSERT_NE(vertices->vertices(), nullptr);
789 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
790 ASSERT_EQ(vertices->colors(), nullptr);
791 ASSERT_NE(vertices->indices(), nullptr);
792
793 ASSERT_EQ(vertices->bounds(), SkRect::MakeLTRB(2, 3, 15, 20));
794 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
795 ASSERT_EQ(vertices->vertex_count(), 3);
796 for (int i = 0; i < 3; i++) {
797 ASSERT_EQ(vertices->vertices()[i], coords[i]);
798 }
799 ASSERT_EQ(vertices->index_count(), 6);
800 for (int i = 0; i < 6; i++) {
801 ASSERT_EQ(vertices->indices()[i], indices[i]);
802 }
803}
804
805TEST(DisplayListVertices, BuildWithNoOptionalData) {
806 SkPoint coords[3] = {
807 SkPoint::Make(2, 3),
808 SkPoint::Make(5, 6),
809 SkPoint::Make(15, 20),
810 };
811
813 builder.store_vertices(coords);
814 std::shared_ptr<const DlVertices> vertices = builder.build();
815
816 ASSERT_NE(vertices, nullptr);
817 ASSERT_NE(vertices->vertices(), nullptr);
818 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
819 ASSERT_EQ(vertices->colors(), nullptr);
820 ASSERT_EQ(vertices->indices(), nullptr);
821
822 ASSERT_EQ(vertices->bounds(), SkRect::MakeLTRB(2, 3, 15, 20));
823 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
824 ASSERT_EQ(vertices->vertex_count(), 3);
825 for (int i = 0; i < 3; i++) {
826 ASSERT_EQ(vertices->vertices()[i], coords[i]);
827 }
828 ASSERT_EQ(vertices->index_count(), 0);
829}
830
831TEST(DisplayListVertices, BuildWithNegativeIndexCount) {
832 SkPoint coords[3] = {
833 SkPoint::Make(2, 3),
834 SkPoint::Make(5, 6),
835 SkPoint::Make(15, 20),
836 };
837
839 builder.store_vertices(coords);
840 std::shared_ptr<const DlVertices> vertices = builder.build();
841
842 ASSERT_NE(vertices, nullptr);
843 ASSERT_NE(vertices->vertices(), nullptr);
844 ASSERT_EQ(vertices->texture_coordinates(), nullptr);
845 ASSERT_EQ(vertices->colors(), nullptr);
846 ASSERT_EQ(vertices->indices(), nullptr);
847
848 ASSERT_EQ(vertices->bounds(), SkRect::MakeLTRB(2, 3, 15, 20));
849 ASSERT_EQ(vertices->mode(), DlVertexMode::kTriangles);
850 ASSERT_EQ(vertices->vertex_count(), 3);
851 for (int i = 0; i < 3; i++) {
852 ASSERT_EQ(vertices->vertices()[i], coords[i]);
853 }
854 ASSERT_EQ(vertices->index_count(), 0);
855}
856
857TEST(DisplayListVertices, TestEquals) {
858 SkPoint coords[3] = {
859 SkPoint::Make(2, 3),
860 SkPoint::Make(5, 6),
861 SkPoint::Make(15, 20),
862 };
863 SkPoint texture_coords[3] = {
864 SkPoint::Make(102, 103),
865 SkPoint::Make(105, 106),
866 SkPoint::Make(115, 120),
867 };
868 DlColor colors[3] = {
872 };
873 uint16_t indices[6] = {
874 2, 1, 0, //
875 1, 2, 0,
876 };
877
878 std::shared_ptr<const DlVertices> vertices1 = DlVertices::Make(
879 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices);
880 std::shared_ptr<const DlVertices> vertices2 = DlVertices::Make(
881 DlVertexMode::kTriangles, 3, coords, texture_coords, colors, 6, indices);
882 TestEquals(*vertices1, *vertices2);
883}
884
885TEST(DisplayListVertices, TestNotEquals) {
886 SkPoint coords[4] = {
887 SkPoint::Make(2, 3),
888 SkPoint::Make(5, 6),
889 SkPoint::Make(15, 20),
890 SkPoint::Make(53, 62),
891 };
892 SkPoint wrong_coords[4] = {
893 SkPoint::Make(2, 3),
894 SkPoint::Make(5, 6),
895 SkPoint::Make(15, 20),
896 SkPoint::Make(57, 62),
897 };
898 SkPoint texture_coords[4] = {
899 SkPoint::Make(102, 103),
900 SkPoint::Make(105, 106),
901 SkPoint::Make(115, 120),
902 SkPoint::Make(153, 162),
903 };
904 SkPoint wrong_texture_coords[4] = {
905 SkPoint::Make(102, 103),
906 SkPoint::Make(105, 106),
907 SkPoint::Make(115, 121),
908 SkPoint::Make(153, 162),
909 };
910 DlColor colors[4] = {
915 };
916 DlColor wrong_colors[4] = {
921 };
922 uint16_t indices[9] = {
923 2, 1, 0, //
924 1, 2, 0, //
925 1, 2, 3,
926 };
927 uint16_t wrong_indices[9] = {
928 2, 1, 0, //
929 1, 2, 0, //
930 2, 3, 1,
931 };
932
933 std::shared_ptr<const DlVertices> vertices1 = DlVertices::Make(
934 DlVertexMode::kTriangles, 4, coords, texture_coords, colors, 9, indices);
935
936 {
937 std::shared_ptr<const DlVertices> vertices2 =
939 texture_coords, colors, 9, indices);
940 TestNotEquals(*vertices1, *vertices2, "vertex mode differs");
941 }
942 {
943 std::shared_ptr<const DlVertices> vertices2 =
945 texture_coords, colors, 9, indices);
946 TestNotEquals(*vertices1, *vertices2, "vertex count differs");
947 }
948 {
949 std::shared_ptr<const DlVertices> vertices2 =
950 DlVertices::Make(DlVertexMode::kTriangles, 4, wrong_coords, //
951 texture_coords, colors, 9, indices);
952 TestNotEquals(*vertices1, *vertices2, "vertex coordinates differ");
953 }
954 {
955 std::shared_ptr<const DlVertices> vertices2 =
957 wrong_texture_coords, colors, 9, indices);
958 TestNotEquals(*vertices1, *vertices2, "texture coordinates differ");
959 }
960 {
961 std::shared_ptr<const DlVertices> vertices2 =
963 texture_coords, wrong_colors, 9, indices);
964 TestNotEquals(*vertices1, *vertices2, "colors differ");
965 }
966 {
967 std::shared_ptr<const DlVertices> vertices2 =
969 texture_coords, colors, 6, indices);
970 TestNotEquals(*vertices1, *vertices2, "index count differs");
971 }
972 {
973 std::shared_ptr<const DlVertices> vertices2 =
975 texture_coords, colors, 9, wrong_indices);
976 TestNotEquals(*vertices1, *vertices2, "indices differ");
977 }
978}
979
980} // namespace testing
981} // namespace flutter
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
A utility class to build up a |DlVertices| object one set of data at a time.
Definition: dl_vertices.h:75
void store_texture_coordinates(const SkPoint points[])
Copies the indicated list of points as texture coordinates.
Definition: dl_vertices.cc:243
void store_vertices(const SkPoint points[])
Copies the indicated list of points as vertices.
Definition: dl_vertices.cc:225
void store_indices(const uint16_t indices[])
Copies the indicated list of 16-bit indices as vertex indices.
Definition: dl_vertices.cc:270
static constexpr Flags kNone
Definition: dl_vertices.h:96
std::shared_ptr< DlVertices > build()
Finalizes and the constructed DlVertices object.
Definition: dl_vertices.cc:279
bool is_valid()
Returns true iff the underlying object was successfully allocated.
Definition: dl_vertices.h:115
static constexpr Flags kHasColors
Definition: dl_vertices.h:98
void store_colors(const DlColor colors[])
Copies the indicated list of colors as vertex colors.
Definition: dl_vertices.cc:261
static constexpr Flags kHasTextureCoordinates
Definition: dl_vertices.h:97
static std::shared_ptr< DlVertices > Make(DlVertexMode mode, int vertex_count, const SkPoint vertices[], const SkPoint texture_coordinates[], const DlColor colors[], int index_count=0, const uint16_t indices[]=nullptr)
Constructs a DlVector with compact inline storage for all of its required and optional lists of data.
Definition: dl_vertices.cc:39
FlutterSemanticsFlag flags
PODArray< SkColor > colors
Definition: SkRecords.h:276
DlVertices::Builder Builder
static void TestNotEquals(T &source1, T &source2, const std::string &label)
static void TestEquals(T &source1, T &source2)
TEST(DisplayListComplexity, EmptyDisplayList)
@ kTriangles
The vertices are taken 3 at a time to form a triangle.
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
static constexpr DlColor kMagenta()
Definition: dl_color.h:28
static constexpr DlColor kBlue()
Definition: dl_color.h:26
static constexpr DlColor kRed()
Definition: dl_color.h:24
static constexpr DlColor kGreen()
Definition: dl_color.h:25
static constexpr DlColor kCyan()
Definition: dl_color.h:27
flags to indicate/promise which of the optional texture coordinates or colors will be supplied during...
Definition: dl_vertices.h:80
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678