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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/resources/tile.h"
#include "cc/resources/tile_priority.h"
#include "cc/test/fake_tile_manager.h"
#include "cc/test/fake_tile_manager_client.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace cc {
namespace {
class FakePicturePileImpl : public PicturePileImpl {
public:
FakePicturePileImpl() : PicturePileImpl(false) {
gfx::Size size(std::numeric_limits<int>::max(),
std::numeric_limits<int>::max());
Resize(size);
recorded_region_ = Region(gfx::Rect(size));
}
protected:
virtual ~FakePicturePileImpl() {}
};
class TilePriorityForSoonBin : public TilePriority {
public:
TilePriorityForSoonBin() : TilePriority(
HIGH_RESOLUTION,
0.5,
300.0) {}
};
class TilePriorityForEventualBin : public TilePriority {
public:
TilePriorityForEventualBin() : TilePriority(
NON_IDEAL_RESOLUTION,
1.0,
315.0) {}
};
class TilePriorityForNowBin : public TilePriority {
public:
TilePriorityForNowBin() : TilePriority(
HIGH_RESOLUTION,
0,
0) {}
};
class TileManagerTest : public testing::Test {
public:
typedef std::vector<scoped_refptr<Tile> > TileVector;
void Initialize(int max_memory_tiles,
TileMemoryLimitPolicy memory_limit_policy,
TreePriority tree_priority) {
tile_manager_ = make_scoped_ptr(new FakeTileManager(&tile_manager_client_));
GlobalStateThatImpactsTilePriority state;
gfx::Size tile_size = settings_.default_tile_size;
state.memory_limit_in_bytes =
max_memory_tiles * 4 * tile_size.width() * tile_size.height();
state.memory_limit_policy = memory_limit_policy;
state.tree_priority = tree_priority;
tile_manager_->SetGlobalState(state);
picture_pile_ = make_scoped_refptr(new FakePicturePileImpl());
}
virtual void TearDown() OVERRIDE {
tile_manager_.reset(NULL);
picture_pile_ = NULL;
testing::Test::TearDown();
}
TileVector CreateTiles(int count,
TilePriority active_priority,
TilePriority pending_priority) {
TileVector tiles;
for (int i = 0; i < count; ++i) {
scoped_refptr<Tile> tile =
make_scoped_refptr(new Tile(tile_manager_.get(),
picture_pile_.get(),
settings_.default_tile_size,
gfx::Rect(),
gfx::Rect(),
1.0,
0,
0));
tile->SetPriority(ACTIVE_TREE, active_priority);
tile->SetPriority(PENDING_TREE, pending_priority);
tiles.push_back(tile);
}
return tiles;
}
FakeTileManager* tile_manager() {
return tile_manager_.get();
}
int AssignedMemoryCounts(const TileVector& tiles) {
int has_memory_count = 0;
for (TileVector::const_iterator it = tiles.begin();
it != tiles.end();
++it) {
if ((*it)->IsAssignedGpuMemory())
++has_memory_count;
}
return has_memory_count;
}
private:
FakeTileManagerClient tile_manager_client_;
LayerTreeSettings settings_;
scoped_ptr<FakeTileManager> tile_manager_;
scoped_refptr<FakePicturePileImpl> picture_pile_;
};
TEST_F(TileManagerTest, EnoughMemoryAllowAnything) {
// A few tiles of each type of priority, with enough memory for all tiles.
Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_now =
CreateTiles(3, TilePriorityForNowBin(), TilePriority());
TileVector pending_now =
CreateTiles(3, TilePriority(), TilePriorityForNowBin());
TileVector active_pending_soon = CreateTiles(
3, TilePriorityForSoonBin(), TilePriorityForSoonBin());
TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority());
tile_manager()->ManageTiles();
EXPECT_EQ(3, AssignedMemoryCounts(active_now));
EXPECT_EQ(3, AssignedMemoryCounts(pending_now));
EXPECT_EQ(3, AssignedMemoryCounts(active_pending_soon));
EXPECT_EQ(1, AssignedMemoryCounts(never_bin));
active_now.clear();
pending_now.clear();
active_pending_soon.clear();
never_bin.clear();
TearDown();
}
TEST_F(TileManagerTest, EnoughMemoryAllowPrepaintOnly) {
// A few tiles of each type of priority, with enough memory for all tiles,
// with the exception of never bin.
Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_now =
CreateTiles(3, TilePriorityForNowBin(), TilePriority());
TileVector pending_now =
CreateTiles(3, TilePriority(), TilePriorityForNowBin());
TileVector active_pending_soon = CreateTiles(
3, TilePriorityForSoonBin(), TilePriorityForSoonBin());
TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority());
tile_manager()->ManageTiles();
EXPECT_EQ(3, AssignedMemoryCounts(active_now));
EXPECT_EQ(3, AssignedMemoryCounts(pending_now));
EXPECT_EQ(3, AssignedMemoryCounts(active_pending_soon));
EXPECT_EQ(0, AssignedMemoryCounts(never_bin));
active_now.clear();
pending_now.clear();
active_pending_soon.clear();
never_bin.clear();
TearDown();
}
TEST_F(TileManagerTest, EnoughMemoryAllowAbsoluteMinimum) {
// A few tiles of each type of priority, with enough memory for all tiles,
// with the exception of never and soon bins.
Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_now =
CreateTiles(3, TilePriorityForNowBin(), TilePriority());
TileVector pending_now =
CreateTiles(3, TilePriority(), TilePriorityForNowBin());
TileVector active_pending_soon = CreateTiles(
3, TilePriorityForSoonBin(), TilePriorityForSoonBin());
TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority());
tile_manager()->ManageTiles();
EXPECT_EQ(3, AssignedMemoryCounts(active_now));
EXPECT_EQ(3, AssignedMemoryCounts(pending_now));
EXPECT_EQ(0, AssignedMemoryCounts(active_pending_soon));
EXPECT_EQ(0, AssignedMemoryCounts(never_bin));
active_now.clear();
pending_now.clear();
active_pending_soon.clear();
never_bin.clear();
TearDown();
}
TEST_F(TileManagerTest, EnoughMemoryAllowNothing) {
// A few tiles of each type of priority, with enough memory for all tiles,
// but allow nothing should not assign any memory.
Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_now =
CreateTiles(3, TilePriorityForNowBin(), TilePriority());
TileVector pending_now =
CreateTiles(3, TilePriority(), TilePriorityForNowBin());
TileVector active_pending_soon = CreateTiles(
3, TilePriorityForSoonBin(), TilePriorityForSoonBin());
TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority());
tile_manager()->ManageTiles();
EXPECT_EQ(0, AssignedMemoryCounts(active_now));
EXPECT_EQ(0, AssignedMemoryCounts(pending_now));
EXPECT_EQ(0, AssignedMemoryCounts(active_pending_soon));
EXPECT_EQ(0, AssignedMemoryCounts(never_bin));
active_now.clear();
pending_now.clear();
active_pending_soon.clear();
never_bin.clear();
TearDown();
}
TEST_F(TileManagerTest, PartialOOMMemoryToPending) {
// 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin,
// but only enough memory for 8 tiles. The result is all pending tree tiles
// get memory, and 3 of the active tree tiles get memory.
Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_tree_tiles =
CreateTiles(5, TilePriorityForEventualBin(), TilePriority());
TileVector pending_tree_tiles =
CreateTiles(5, TilePriority(), TilePriorityForNowBin());
tile_manager()->ManageTiles();
EXPECT_EQ(3, AssignedMemoryCounts(active_tree_tiles));
EXPECT_EQ(5, AssignedMemoryCounts(pending_tree_tiles));
pending_tree_tiles.clear();
active_tree_tiles.clear();
TearDown();
}
TEST_F(TileManagerTest, PartialOOMMemoryToActive) {
// 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin,
// but only enough memory for 8 tiles. The result is all active tree tiles
// get memory, and 3 of the pending tree tiles get memory.
Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_tree_tiles =
CreateTiles(5, TilePriorityForNowBin(), TilePriority());
TileVector pending_tree_tiles =
CreateTiles(5, TilePriority(), TilePriorityForNowBin());
tile_manager()->ManageTiles();
EXPECT_EQ(5, AssignedMemoryCounts(active_tree_tiles));
EXPECT_EQ(3, AssignedMemoryCounts(pending_tree_tiles));
pending_tree_tiles.clear();
active_tree_tiles.clear();
TearDown();
}
TEST_F(TileManagerTest, TotalOOMMemoryToPending) {
// 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin,
// but only enough memory for 4 tiles. The result is 4 pending tree tiles
// get memory, and none of the active tree tiles get memory.
Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_tree_tiles =
CreateTiles(5, TilePriorityForEventualBin(), TilePriority());
TileVector pending_tree_tiles =
CreateTiles(5, TilePriority(), TilePriorityForNowBin());
tile_manager()->ManageTiles();
EXPECT_EQ(0, AssignedMemoryCounts(active_tree_tiles));
EXPECT_EQ(4, AssignedMemoryCounts(pending_tree_tiles));
pending_tree_tiles.clear();
active_tree_tiles.clear();
TearDown();
}
TEST_F(TileManagerTest, TotalOOMMemoryToActive) {
// 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin,
// but only enough memory for 4 tiles. The result is 5 active tree tiles
// get memory, and none of the pending tree tiles get memory.
Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY);
TileVector active_tree_tiles =
CreateTiles(5, TilePriorityForNowBin(), TilePriority());
TileVector pending_tree_tiles =
CreateTiles(5, TilePriority(), TilePriorityForNowBin());
tile_manager()->ManageTiles();
EXPECT_EQ(4, AssignedMemoryCounts(active_tree_tiles));
EXPECT_EQ(0, AssignedMemoryCounts(pending_tree_tiles));
pending_tree_tiles.clear();
active_tree_tiles.clear();
TearDown();
}
} // namespace
} // namespace cc
|