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"
14TEST(DisplayListVertices, MakeWithZeroAndNegativeVerticesAndIndices) {
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);
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);
38TEST(DisplayListVertices, MakeWithTexAndColorAndIndices) {
54 uint16_t indices[6] = {
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);
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]);
76 ASSERT_EQ(vertices->index_count(), 6);
77 for (
int i = 0;
i < 6;
i++) {
78 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
82TEST(DisplayListVertices, MakeWithTexAndColor) {
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);
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]);
116 ASSERT_EQ(vertices->index_count(), 0);
119TEST(DisplayListVertices, MakeWithTexAndIndices) {
130 uint16_t indices[6] = {
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);
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]);
151 ASSERT_EQ(vertices->index_count(), 6);
152 for (
int i = 0;
i < 6;
i++) {
153 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
157TEST(DisplayListVertices, MakeWithColorAndIndices) {
168 uint16_t indices[6] = {
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);
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]);
189 ASSERT_EQ(vertices->index_count(), 6);
190 for (
int i = 0;
i < 6;
i++) {
191 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
195TEST(DisplayListVertices, MakeWithTex) {
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);
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]);
223 ASSERT_EQ(vertices->index_count(), 0);
226TEST(DisplayListVertices, MakeWithColor) {
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);
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]);
254 ASSERT_EQ(vertices->index_count(), 0);
257TEST(DisplayListVertices, MakeWithIndices) {
263 uint16_t indices[6] = {
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);
279 ASSERT_EQ(vertices->vertex_count(), 3);
280 for (
int i = 0;
i < 3;
i++) {
281 ASSERT_EQ(vertices->vertices()[
i], coords[
i]);
283 ASSERT_EQ(vertices->index_count(), 6);
284 for (
int i = 0;
i < 6;
i++) {
285 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
289TEST(DisplayListVertices, MakeWithNoOptionalData) {
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);
307 ASSERT_EQ(vertices->vertex_count(), 3);
308 for (
int i = 0;
i < 3;
i++) {
309 ASSERT_EQ(vertices->vertices()[
i], coords[
i]);
311 ASSERT_EQ(vertices->index_count(), 0);
314TEST(DisplayListVertices, MakeWithIndicesButZeroIndexCount) {
320 uint16_t indices[6] = {
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);
336 ASSERT_EQ(vertices->vertex_count(), 3);
337 for (
int i = 0;
i < 3;
i++) {
338 ASSERT_EQ(vertices->vertices()[
i], coords[
i]);
340 ASSERT_EQ(vertices->index_count(), 0);
343TEST(DisplayListVertices, MakeWithIndicesButNegativeIndexCount) {
349 uint16_t indices[6] = {
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);
365 ASSERT_EQ(vertices->vertex_count(), 3);
366 for (
int i = 0;
i < 3;
i++) {
367 ASSERT_EQ(vertices->vertices()[
i], coords[
i]);
369 ASSERT_EQ(vertices->index_count(), 0);
374TEST(DisplayListVertices, BuilderFlags) {
376 EXPECT_FALSE(
flags.has_texture_coordinates);
377 EXPECT_FALSE(
flags.has_colors);
381 EXPECT_FALSE(
flags.has_colors);
388 EXPECT_FALSE(
flags.has_texture_coordinates);
389 EXPECT_FALSE(
flags.has_colors);
392 EXPECT_FALSE(
flags.has_texture_coordinates);
409 .has_texture_coordinates);
414TEST(DisplayListVertices, BuildWithZeroAndNegativeVerticesAndIndices) {
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);
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);
440TEST(DisplayListVertices, BuildWithTexAndColorAndIndices) {
456 uint16_t indices[6] = {
463 builder.store_vertices(coords);
464 builder.store_texture_coordinates(texture_coords);
466 builder.store_indices(indices);
467 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
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]);
483 ASSERT_EQ(vertices->index_count(), 6);
484 for (
int i = 0;
i < 6;
i++) {
485 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
494 std::shared_ptr<const DlVertices> vertices2 = builder2.
build();
504TEST(DisplayListVertices, BuildWithTexAndColor) {
523 builder.store_vertices(coords);
524 builder.store_texture_coordinates(texture_coords);
526 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
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]);
542 ASSERT_EQ(vertices->index_count(), 0);
545TEST(DisplayListVertices, BuildWithTexAndIndices) {
556 uint16_t indices[6] = {
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();
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);
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]);
581 ASSERT_EQ(vertices->index_count(), 6);
582 for (
int i = 0;
i < 6;
i++) {
583 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
587TEST(DisplayListVertices, BuildWithColorAndIndices) {
598 uint16_t indices[6] = {
605 builder.store_vertices(coords);
607 builder.store_indices(indices);
608 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
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]);
623 ASSERT_EQ(vertices->index_count(), 6);
624 for (
int i = 0;
i < 6;
i++) {
625 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
629TEST(DisplayListVertices, BuildWithTexUsingPoints) {
643 builder.store_vertices(coords);
644 builder.store_texture_coordinates(texture_coords);
645 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
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]);
660 ASSERT_EQ(vertices->index_count(), 0);
663TEST(DisplayListVertices, BuildWithTexUsingFloats) {
669 float texture_coords[6] = {
677 builder.store_vertices(coords);
678 builder.store_texture_coordinates(texture_coords);
679 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
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]);
696 ASSERT_EQ(vertices->index_count(), 0);
699TEST(DisplayListVertices, BuildUsingFloatsSameAsPoints) {
705 SkPoint texture_coord_points[3] = {
711 float coord_floats[6] = {
716 float texture_coord_floats[6] = {
726 std::shared_ptr<const DlVertices> vertices_points = builder_points.
build();
732 std::shared_ptr<const DlVertices> vertices_floats = builder_floats.
build();
734 TestEquals(*vertices_points, *vertices_floats);
737TEST(DisplayListVertices, BuildWithColor) {
751 builder.store_vertices(coords);
753 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
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]);
768 ASSERT_EQ(vertices->index_count(), 0);
771TEST(DisplayListVertices, BuildWithIndices) {
777 uint16_t indices[6] = {
783 builder.store_vertices(coords);
784 builder.store_indices(indices);
785 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
795 ASSERT_EQ(vertices->vertex_count(), 3);
796 for (
int i = 0;
i < 3;
i++) {
797 ASSERT_EQ(vertices->vertices()[
i], coords[
i]);
799 ASSERT_EQ(vertices->index_count(), 6);
800 for (
int i = 0;
i < 6;
i++) {
801 ASSERT_EQ(vertices->indices()[
i], indices[
i]);
805TEST(DisplayListVertices, BuildWithNoOptionalData) {
813 builder.store_vertices(coords);
814 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
824 ASSERT_EQ(vertices->vertex_count(), 3);
825 for (
int i = 0;
i < 3;
i++) {
826 ASSERT_EQ(vertices->vertices()[
i], coords[
i]);
828 ASSERT_EQ(vertices->index_count(), 0);
831TEST(DisplayListVertices, BuildWithNegativeIndexCount) {
839 builder.store_vertices(coords);
840 std::shared_ptr<const DlVertices> vertices =
builder.build();
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);
850 ASSERT_EQ(vertices->vertex_count(), 3);
851 for (
int i = 0;
i < 3;
i++) {
852 ASSERT_EQ(vertices->vertices()[
i], coords[
i]);
854 ASSERT_EQ(vertices->index_count(), 0);
873 uint16_t indices[6] = {
904 SkPoint wrong_texture_coords[4] = {
922 uint16_t indices[9] = {
927 uint16_t wrong_indices[9] = {
937 std::shared_ptr<const DlVertices> vertices2 =
939 texture_coords,
colors, 9, indices);
940 TestNotEquals(*vertices1, *vertices2,
"vertex mode differs");
943 std::shared_ptr<const DlVertices> vertices2 =
945 texture_coords,
colors, 9, indices);
946 TestNotEquals(*vertices1, *vertices2,
"vertex count differs");
949 std::shared_ptr<const DlVertices> vertices2 =
951 texture_coords,
colors, 9, indices);
952 TestNotEquals(*vertices1, *vertices2,
"vertex coordinates differ");
955 std::shared_ptr<const DlVertices> vertices2 =
957 wrong_texture_coords,
colors, 9, indices);
958 TestNotEquals(*vertices1, *vertices2,
"texture coordinates differ");
961 std::shared_ptr<const DlVertices> vertices2 =
963 texture_coords, wrong_colors, 9, indices);
967 std::shared_ptr<const DlVertices> vertices2 =
969 texture_coords,
colors, 6, indices);
970 TestNotEquals(*vertices1, *vertices2,
"index count differs");
973 std::shared_ptr<const DlVertices> vertices2 =
975 texture_coords,
colors, 9, wrong_indices);
constexpr SkColor SK_ColorCYAN
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorGREEN
A utility class to build up a |DlVertices| object one set of data at a time.
void store_texture_coordinates(const SkPoint points[])
Copies the indicated list of points as texture coordinates.
void store_vertices(const SkPoint points[])
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
std::shared_ptr< DlVertices > build()
Finalizes and the constructed DlVertices object.
bool is_valid()
Returns true iff the underlying object was successfully allocated.
static constexpr Flags kHasColors
void store_colors(const DlColor colors[])
Copies the indicated list of colors as vertex colors.
static constexpr Flags kHasTextureCoordinates
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.
FlutterSemanticsFlag flags
PODArray< SkColor > colors
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)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
static constexpr DlColor kMagenta()
static constexpr DlColor kBlue()
static constexpr DlColor kRed()
static constexpr DlColor kGreen()
static constexpr DlColor kCyan()
flags to indicate/promise which of the optional texture coordinates or colors will be supplied during...
#define EXPECT_TRUE(handle)