Flutter Engine
 
Loading...
Searching...
No Matches
stopwatch_dl_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
7#include "gtest/gtest.h"
8
9namespace flutter {
10namespace testing {
11
12static DlRect MakeRectFromVertices(DlPoint vertices[6]) {
13 // "Combine" the vertices to form a rectangle.
14 auto const left = std::min(vertices[0].x, vertices[5].x);
15 auto const top = std::min(vertices[0].y, vertices[1].y);
16 auto const right = std::max(vertices[1].x, vertices[2].x);
17 auto const bottom = std::max(vertices[2].y, vertices[3].y);
18
19 return DlRect::MakeLTRB(left, top, right, bottom);
20}
21
22TEST(DlVertexPainter, DrawRectIntoVertices) {
23 std::vector<DlPoint> point_storage(12);
24 std::vector<DlColor> color_storage(12);
25 auto painter = DlVertexPainter(point_storage, color_storage);
26
27 // Paint a red rectangle.
28 painter.DrawRect(DlRect::MakeLTRB(0, 0, 10, 10), DlColor::kRed());
29
30 // Paint a blue rectangle.
31 painter.DrawRect(DlRect::MakeLTRB(10, 10, 20, 20), DlColor::kBlue());
32
33 // Convert the buffered vertices into a |DlVertices| object.
34 auto vertices = painter.IntoVertices(DlRect::MakeLTRB(0, 0, 20, 20));
35
36 // Verify the vertices.
37 EXPECT_EQ(vertices->mode(), DlVertexMode::kTriangles);
38 EXPECT_EQ(vertices->vertex_count(), 3 * 2 * 2);
39
40 auto const points = vertices->vertex_data();
41
42 {
43 // Extract the first 6 vertices (first rectangle).
44 DlPoint first_rect_vertices[6];
45 std::copy(points, points + 6, first_rect_vertices);
46 EXPECT_EQ(MakeRectFromVertices(first_rect_vertices),
47 DlRect::MakeLTRB(0, 0, 10, 10));
48 }
49
50 {
51 // Extract the next 6 vertices (second rectangle).
52 DlPoint second_rect_vertices[6];
53 std::copy(points + 6, points + 12, second_rect_vertices);
54 EXPECT_EQ(MakeRectFromVertices(second_rect_vertices),
55 DlRect::MakeLTRB(10, 10, 20, 20));
56 }
57
58 // Verify the colors (first 6 vertices are red, next 6 are blue).
59 auto const colors = vertices->colors();
60 EXPECT_EQ(colors[0], DlColor::kRed());
61 EXPECT_EQ(colors[1], DlColor::kRed());
62 EXPECT_EQ(colors[2], DlColor::kRed());
63 EXPECT_EQ(colors[3], DlColor::kRed());
64 EXPECT_EQ(colors[4], DlColor::kRed());
65 EXPECT_EQ(colors[5], DlColor::kRed());
66
67 EXPECT_EQ(colors[6], DlColor::kBlue());
68 EXPECT_EQ(colors[7], DlColor::kBlue());
69 EXPECT_EQ(colors[8], DlColor::kBlue());
70 EXPECT_EQ(colors[9], DlColor::kBlue());
71 EXPECT_EQ(colors[10], DlColor::kBlue());
72 EXPECT_EQ(colors[11], DlColor::kBlue());
73}
74
75} // namespace testing
76} // namespace flutter
Provides canvas-like painting methods that actually build vertices.
int32_t x
double y
static DlRect MakeRectFromVertices(DlPoint vertices[6])
TEST(NativeAssetsManagerTest, NoAvailableAssets)
@ kTriangles
The vertices are taken 3 at a time to form a triangle.
static constexpr DlColor kBlue()
Definition dl_color.h:73
static constexpr DlColor kRed()
Definition dl_color.h:71
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
Definition rect.h:129
std::vector< Point > points