Flutter Engine
The Flutter Engine
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
5#include "flutter/flow/stopwatch_dl.h"
6#include "gtest/gtest.h"
7
8namespace flutter {
9namespace testing {
10
11static SkRect MakeRectFromVertices(SkPoint vertices[6]) {
12 // "Combine" the vertices to form a rectangle.
13 auto const left = std::min(vertices[0].x(), vertices[5].x());
14 auto const top = std::min(vertices[0].y(), vertices[1].y());
15 auto const right = std::max(vertices[1].x(), vertices[2].x());
16 auto const bottom = std::max(vertices[2].y(), vertices[3].y());
17
18 return SkRect::MakeLTRB(left, top, right, bottom);
19}
20
21TEST(DlVertexPainter, DrawRectIntoVertices) {
22 auto painter = DlVertexPainter();
23
24 // Paint a red rectangle.
25 painter.DrawRect(SkRect::MakeLTRB(0, 0, 10, 10), DlColor::kRed());
26
27 // Paint a blue rectangle.
28 painter.DrawRect(SkRect::MakeLTRB(10, 10, 20, 20), DlColor::kBlue());
29
30 // Convert the buffered vertices into a |DlVertices| object.
31 auto vertices = painter.IntoVertices();
32
33 // Verify the vertices.
34 EXPECT_EQ(vertices->mode(), DlVertexMode::kTriangles);
35 EXPECT_EQ(vertices->vertex_count(), 3 * 2 * 2);
36
37 auto const points = vertices->vertices();
38
39 {
40 // Extract the first 6 vertices (first rectangle).
41 SkPoint first_rect_vertices[6];
42 std::copy(points, points + 6, first_rect_vertices);
43 EXPECT_EQ(MakeRectFromVertices(first_rect_vertices),
44 SkRect::MakeLTRB(0, 0, 10, 10));
45 }
46
47 {
48 // Extract the next 6 vertices (second rectangle).
49 SkPoint second_rect_vertices[6];
50 std::copy(points + 6, points + 12, second_rect_vertices);
51 EXPECT_EQ(MakeRectFromVertices(second_rect_vertices),
52 SkRect::MakeLTRB(10, 10, 20, 20));
53 }
54
55 // Verify the colors (first 6 vertices are red, next 6 are blue).
56 auto const colors = vertices->colors();
57 EXPECT_EQ(colors[0], DlColor::kRed());
58 EXPECT_EQ(colors[1], DlColor::kRed());
59 EXPECT_EQ(colors[2], DlColor::kRed());
60 EXPECT_EQ(colors[3], DlColor::kRed());
61 EXPECT_EQ(colors[4], DlColor::kRed());
62 EXPECT_EQ(colors[5], DlColor::kRed());
63
64 EXPECT_EQ(colors[6], DlColor::kBlue());
65 EXPECT_EQ(colors[7], DlColor::kBlue());
66 EXPECT_EQ(colors[8], DlColor::kBlue());
67 EXPECT_EQ(colors[9], DlColor::kBlue());
68 EXPECT_EQ(colors[10], DlColor::kBlue());
69 EXPECT_EQ(colors[11], DlColor::kBlue());
70}
71
72} // namespace testing
73} // namespace flutter
static const int points[]
static void copy(void *dst, const uint8_t *src, int width, int bpp, int deltaSrc, int offset, const SkPMColor ctable[])
Definition: SkSwizzler.cpp:31
Provides canvas-like painting methods that actually build vertices.
Definition: stopwatch_dl.h:39
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
static SkRect MakeRectFromVertices(SkPoint vertices[6])
TEST(DisplayListComplexity, EmptyDisplayList)
@ kTriangles
The vertices are taken 3 at a time to form a triangle.
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
static constexpr DlColor kBlue()
Definition: dl_color.h:26
static constexpr DlColor kRed()
Definition: dl_color.h:24