1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
cc / paint / clear_for_opaque_raster_unittest.cc [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/paint/clear_for_opaque_raster.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size_f.h"
#include "ui/gfx/geometry/vector2d_f.h"
namespace cc {
TEST(ClearForOpaqueRasterTest, NoTransform) {
const gfx::Vector2dF translation;
const gfx::Vector2dF scale(1, 1);
const gfx::Size content_size(100, 100);
const gfx::Rect bitmap_rect(content_size);
gfx::Rect inner_rect;
gfx::Rect outer_rect;
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, bitmap_rect, outer_rect,
inner_rect));
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(25, 25, 50, 50),
outer_rect, inner_rect));
}
TEST(ClearForOpaqueRasterTest, WithTranslation) {
const gfx::Vector2dF translation(0.3f, 0.7f);
const gfx::Vector2dF scale(1, 1);
const gfx::Size content_size(100, 100);
const gfx::Rect bitmap_rect(content_size);
gfx::Rect inner_rect;
gfx::Rect outer_rect;
// Full playback (touching all edges).
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, bitmap_rect, outer_rect,
inner_rect));
EXPECT_EQ(gfx::Rect(0, 0, 100, 100), outer_rect);
EXPECT_EQ(gfx::Rect(1, 1, 99, 99), inner_rect);
// Touches the left edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(0, 25, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(0, 25, 50, 50), outer_rect);
EXPECT_EQ(gfx::Rect(1, 25, 49, 50), inner_rect);
// Touches the top edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(25, 0, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(25, 0, 50, 50), outer_rect);
EXPECT_EQ(gfx::Rect(25, 1, 50, 49), inner_rect);
// Touches the right edge only.
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(50, 25, 50, 50),
outer_rect, inner_rect));
// Touches the bottom edge only.
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(25, 50, 50, 50),
outer_rect, inner_rect));
// Touches no edges.
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(1, 1, 98, 98),
outer_rect, inner_rect));
}
TEST(ClearForOpaqueRasterTest, WithScale) {
const gfx::Vector2dF translation;
const gfx::Vector2dF scale(1.5f, 1.5f);
const gfx::Size content_size(100, 100);
const gfx::Rect bitmap_rect(content_size);
gfx::Rect inner_rect;
gfx::Rect outer_rect;
// Full playback (touching all edges).
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, bitmap_rect, outer_rect,
inner_rect));
EXPECT_EQ(gfx::Rect(0, 0, 101, 101), outer_rect);
EXPECT_EQ(gfx::Rect(0, 0, 99, 99), inner_rect);
// Touches the left edge only.
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(0, 25, 50, 50),
outer_rect, inner_rect));
// Touches the top edge only.
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(25, 0, 50, 50),
outer_rect, inner_rect));
// Touches the right edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(50, 25, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(50, 25, 51, 50), outer_rect);
EXPECT_EQ(gfx::Rect(50, 25, 49, 50), inner_rect);
// Touches the bottom edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(25, 50, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(25, 50, 50, 51), outer_rect);
EXPECT_EQ(gfx::Rect(25, 50, 50, 49), inner_rect);
// Touches no edges.
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(1, 1, 98, 98),
outer_rect, inner_rect));
}
TEST(ClearForOpaqueRasterTest, WithTranslationAndScale) {
const gfx::Vector2dF translation(0.3f, 0.7f);
const gfx::Vector2dF scale(1.5f, 1.5f);
const gfx::Size content_size(100, 100);
const gfx::Rect bitmap_rect(content_size);
gfx::Rect inner_rect;
gfx::Rect outer_rect;
// Full playback (touching all edges).
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, bitmap_rect, outer_rect,
inner_rect));
EXPECT_EQ(gfx::Rect(0, 0, 101, 101), outer_rect);
EXPECT_EQ(gfx::Rect(1, 1, 98, 98), inner_rect);
// Touches the left edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(0, 25, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(0, 25, 50, 50), outer_rect);
EXPECT_EQ(gfx::Rect(1, 25, 49, 50), inner_rect);
// Touches the top edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(25, 0, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(25, 0, 50, 50), outer_rect);
EXPECT_EQ(gfx::Rect(25, 1, 50, 49), inner_rect);
// Touches the right edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(50, 25, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(50, 25, 51, 50), outer_rect);
EXPECT_EQ(gfx::Rect(50, 25, 49, 50), inner_rect);
// Touches the bottom edge only.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(25, 50, 50, 50),
outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(25, 50, 50, 51), outer_rect);
EXPECT_EQ(gfx::Rect(25, 50, 50, 49), inner_rect);
// Touches no edges.
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, gfx::Rect(1, 1, 98, 98),
outer_rect, inner_rect));
// With bitmap_rect non-zero offset.
EXPECT_TRUE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, gfx::Rect(25, 25, 75, 75),
gfx::Rect(50, 50, 50, 50), outer_rect, inner_rect));
EXPECT_EQ(gfx::Rect(25, 25, 51, 51), outer_rect);
EXPECT_EQ(gfx::Rect(25, 25, 49, 49), inner_rect);
}
TEST(ClearForOpaqueRasterTest, PlaybackRectBelowContentRect) {
const gfx::Vector2dF translation(0.0f, 0.1f);
const gfx::Vector2dF scale(1.0f, 1.0f);
const gfx::Size content_size(100, 100);
const gfx::Rect bitmap_rect(50, 50, 100, 100);
const gfx::Rect playback_rect(50, 100, 100, 3);
gfx::Rect inner_rect;
gfx::Rect outer_rect;
EXPECT_FALSE(CalculateClearForOpaqueRasterRects(
translation, scale, content_size, bitmap_rect, playback_rect, outer_rect,
inner_rect));
}
} // namespace cc