OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/eviction_tile_priority_queue.h" | 5 #include "cc/resources/eviction_tile_priority_queue.h" |
6 #include "cc/resources/raster_tile_priority_queue.h" | 6 #include "cc/resources/raster_tile_priority_queue.h" |
7 #include "cc/resources/tile.h" | 7 #include "cc/resources/tile.h" |
8 #include "cc/resources/tile_priority.h" | 8 #include "cc/resources/tile_priority.h" |
9 #include "cc/test/fake_impl_proxy.h" | 9 #include "cc/test/fake_impl_proxy.h" |
10 #include "cc/test/fake_layer_tree_host_impl.h" | 10 #include "cc/test/fake_layer_tree_host_impl.h" |
11 #include "cc/test/fake_output_surface.h" | 11 #include "cc/test/fake_output_surface.h" |
12 #include "cc/test/fake_output_surface_client.h" | 12 #include "cc/test/fake_output_surface_client.h" |
13 #include "cc/test/fake_picture_layer_impl.h" | 13 #include "cc/test/fake_picture_layer_impl.h" |
14 #include "cc/test/fake_picture_pile_impl.h" | 14 #include "cc/test/fake_picture_pile_impl.h" |
15 #include "cc/test/fake_tile_manager.h" | 15 #include "cc/test/fake_tile_manager.h" |
16 #include "cc/test/impl_side_painting_settings.h" | 16 #include "cc/test/impl_side_painting_settings.h" |
17 #include "cc/test/test_shared_bitmap_manager.h" | 17 #include "cc/test/test_shared_bitmap_manager.h" |
18 #include "cc/test/test_tile_priorities.h" | 18 #include "cc/test/test_tile_priorities.h" |
19 #include "cc/trees/layer_tree_impl.h" | 19 #include "cc/trees/layer_tree_impl.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 namespace cc { | 22 namespace cc { |
23 namespace { | 23 namespace { |
24 | 24 |
25 class TileManagerTest : public testing::TestWithParam<bool>, | |
26 public TileManagerClient { | |
27 public: | |
28 typedef std::vector<scoped_refptr<Tile> > TileVector; | |
29 | |
30 TileManagerTest() | |
31 : memory_limit_policy_(ALLOW_ANYTHING), | |
32 max_tiles_(0), | |
33 ready_to_activate_(false) {} | |
34 | |
35 void Initialize(int max_tiles, | |
36 TileMemoryLimitPolicy memory_limit_policy, | |
37 TreePriority tree_priority) { | |
38 output_surface_ = FakeOutputSurface::Create3d(); | |
39 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
40 | |
41 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | |
42 resource_provider_ = ResourceProvider::Create( | |
43 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, | |
44 false); | |
45 resource_pool_ = ResourcePool::Create( | |
46 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | |
47 tile_manager_ = | |
48 make_scoped_ptr(new FakeTileManager(this, resource_pool_.get())); | |
49 | |
50 memory_limit_policy_ = memory_limit_policy; | |
51 max_tiles_ = max_tiles; | |
52 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | |
53 | |
54 SetTreePriority(tree_priority); | |
55 } | |
56 | |
57 void SetTreePriority(TreePriority tree_priority) { | |
58 GlobalStateThatImpactsTilePriority state; | |
59 gfx::Size tile_size = settings_.default_tile_size; | |
60 | |
61 if (UsingMemoryLimit()) { | |
62 state.soft_memory_limit_in_bytes = | |
63 max_tiles_ * 4 * tile_size.width() * tile_size.height(); | |
64 state.num_resources_limit = 100; | |
65 } else { | |
66 state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; | |
67 state.num_resources_limit = max_tiles_; | |
68 } | |
69 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; | |
70 state.memory_limit_policy = memory_limit_policy_; | |
71 state.tree_priority = tree_priority; | |
72 | |
73 global_state_ = state; | |
74 resource_pool_->SetResourceUsageLimits(state.soft_memory_limit_in_bytes, | |
75 state.soft_memory_limit_in_bytes, | |
76 state.num_resources_limit); | |
77 tile_manager_->SetGlobalStateForTesting(state); | |
78 } | |
79 | |
80 virtual void TearDown() OVERRIDE { | |
81 tile_manager_.reset(NULL); | |
82 picture_pile_ = NULL; | |
83 | |
84 testing::Test::TearDown(); | |
85 } | |
86 | |
87 // TileManagerClient implementation. | |
88 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() | |
89 const OVERRIDE { | |
90 return picture_layers_; | |
91 } | |
92 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | |
93 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} | |
94 virtual void BuildRasterQueue(RasterTilePriorityQueue* queue, | |
95 TreePriority priority) OVERRIDE {} | |
96 virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue, | |
97 TreePriority priority) OVERRIDE {} | |
98 | |
99 TileVector CreateTilesWithSize(int count, | |
100 TilePriority active_priority, | |
101 TilePriority pending_priority, | |
102 const gfx::Size& tile_size) { | |
103 TileVector tiles; | |
104 for (int i = 0; i < count; ++i) { | |
105 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | |
106 tile_size, | |
107 gfx::Rect(), | |
108 gfx::Rect(), | |
109 1.0, | |
110 0, | |
111 0, | |
112 0); | |
113 tile->SetPriority(ACTIVE_TREE, active_priority); | |
114 tile->SetPriority(PENDING_TREE, pending_priority); | |
115 tiles.push_back(tile); | |
116 } | |
117 return tiles; | |
118 } | |
119 | |
120 TileVector CreateTiles(int count, | |
121 TilePriority active_priority, | |
122 TilePriority pending_priority) { | |
123 return CreateTilesWithSize( | |
124 count, active_priority, pending_priority, settings_.default_tile_size); | |
125 } | |
126 | |
127 void ReleaseTiles(TileVector* tiles) { | |
128 for (TileVector::iterator it = tiles->begin(); it != tiles->end(); it++) { | |
129 Tile* tile = *it; | |
130 tile->SetPriority(ACTIVE_TREE, TilePriority()); | |
131 tile->SetPriority(PENDING_TREE, TilePriority()); | |
132 } | |
133 } | |
134 | |
135 FakeTileManager* tile_manager() { return tile_manager_.get(); } | |
136 | |
137 int AssignedMemoryCount(const TileVector& tiles) { | |
138 int has_memory_count = 0; | |
139 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | |
140 ++it) { | |
141 if (tile_manager_->HasBeenAssignedMemory(*it)) | |
142 ++has_memory_count; | |
143 } | |
144 return has_memory_count; | |
145 } | |
146 | |
147 bool ready_to_activate() const { return ready_to_activate_; } | |
148 | |
149 // The parametrization specifies whether the max tile limit should | |
150 // be applied to memory or resources. | |
151 bool UsingResourceLimit() { return !GetParam(); } | |
152 bool UsingMemoryLimit() { return GetParam(); } | |
153 | |
154 protected: | |
155 GlobalStateThatImpactsTilePriority global_state_; | |
156 | |
157 private: | |
158 LayerTreeSettings settings_; | |
159 scoped_ptr<FakeTileManager> tile_manager_; | |
160 scoped_refptr<FakePicturePileImpl> picture_pile_; | |
161 FakeOutputSurfaceClient output_surface_client_; | |
162 scoped_ptr<FakeOutputSurface> output_surface_; | |
163 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
164 scoped_ptr<ResourceProvider> resource_provider_; | |
165 scoped_ptr<ResourcePool> resource_pool_; | |
166 TileMemoryLimitPolicy memory_limit_policy_; | |
167 int max_tiles_; | |
168 bool ready_to_activate_; | |
169 std::vector<PictureLayerImpl*> picture_layers_; | |
170 }; | |
171 | |
172 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { | |
173 // A few tiles of each type of priority, with enough memory for all tiles. | |
174 | |
175 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
176 TileVector active_now = | |
177 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
178 TileVector pending_now = | |
179 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
180 TileVector active_pending_soon = | |
181 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
182 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
183 | |
184 tile_manager()->AssignMemoryToTiles(global_state_); | |
185 | |
186 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
187 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
188 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
189 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
190 | |
191 ReleaseTiles(&active_now); | |
192 ReleaseTiles(&pending_now); | |
193 ReleaseTiles(&active_pending_soon); | |
194 ReleaseTiles(&never_bin); | |
195 } | |
196 | |
197 TEST_P(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { | |
198 // A few tiles of each type of priority, with enough memory for all tiles, | |
199 // with the exception of never bin. | |
200 | |
201 Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); | |
202 TileVector active_now = | |
203 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
204 TileVector pending_now = | |
205 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
206 TileVector active_pending_soon = | |
207 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
208 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
209 | |
210 tile_manager()->AssignMemoryToTiles(global_state_); | |
211 | |
212 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
213 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
214 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
215 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
216 | |
217 ReleaseTiles(&active_now); | |
218 ReleaseTiles(&pending_now); | |
219 ReleaseTiles(&active_pending_soon); | |
220 ReleaseTiles(&never_bin); | |
221 } | |
222 | |
223 TEST_P(TileManagerTest, EnoughMemoryPendingLowResAllowAbsoluteMinimum) { | |
224 // A few low-res tiles required for activation, with enough memory for all | |
225 // tiles. | |
226 | |
227 Initialize(5, ALLOW_ABSOLUTE_MINIMUM, SAME_PRIORITY_FOR_BOTH_TREES); | |
228 TileVector pending_low_res = | |
229 CreateTiles(5, TilePriority(), TilePriorityLowRes()); | |
230 | |
231 tile_manager()->AssignMemoryToTiles(global_state_); | |
232 | |
233 EXPECT_EQ(5, AssignedMemoryCount(pending_low_res)); | |
234 ReleaseTiles(&pending_low_res); | |
235 } | |
236 | |
237 TEST_P(TileManagerTest, EnoughMemoryAllowAbsoluteMinimum) { | |
238 // A few tiles of each type of priority, with enough memory for all tiles, | |
239 // with the exception of never and soon bins. | |
240 | |
241 Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY); | |
242 TileVector active_now = | |
243 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
244 TileVector pending_now = | |
245 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
246 TileVector active_pending_soon = | |
247 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
248 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
249 | |
250 tile_manager()->AssignMemoryToTiles(global_state_); | |
251 | |
252 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
253 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
254 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
255 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
256 | |
257 ReleaseTiles(&active_now); | |
258 ReleaseTiles(&pending_now); | |
259 ReleaseTiles(&active_pending_soon); | |
260 ReleaseTiles(&never_bin); | |
261 } | |
262 | |
263 TEST_P(TileManagerTest, EnoughMemoryAllowNothing) { | |
264 // A few tiles of each type of priority, with enough memory for all tiles, | |
265 // but allow nothing should not assign any memory. | |
266 | |
267 Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY); | |
268 TileVector active_now = | |
269 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
270 TileVector pending_now = | |
271 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
272 TileVector active_pending_soon = | |
273 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
274 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
275 | |
276 tile_manager()->AssignMemoryToTiles(global_state_); | |
277 | |
278 EXPECT_EQ(0, AssignedMemoryCount(active_now)); | |
279 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); | |
280 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
281 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
282 | |
283 ReleaseTiles(&active_now); | |
284 ReleaseTiles(&pending_now); | |
285 ReleaseTiles(&active_pending_soon); | |
286 ReleaseTiles(&never_bin); | |
287 } | |
288 | |
289 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { | |
290 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | |
291 // required for activation, but only enough memory for 8 tiles. The result | |
292 // is all pending tree tiles get memory, and 3 of the active tree tiles | |
293 // get memory. None of these tiles is needed to avoid calimity (flickering or | |
294 // raster-on-demand) so the soft memory limit is used. | |
295 | |
296 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
297 TileVector active_tree_tiles = | |
298 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | |
299 TileVector pending_tree_tiles = | |
300 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | |
301 tile_manager()->AssignMemoryToTiles(global_state_); | |
302 | |
303 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
304 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
305 | |
306 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
307 tile_manager()->AssignMemoryToTiles(global_state_); | |
308 | |
309 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); | |
310 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); | |
311 | |
312 ReleaseTiles(&active_tree_tiles); | |
313 ReleaseTiles(&pending_tree_tiles); | |
314 } | |
315 | |
316 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { | |
317 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | |
318 // but only enough memory for 8 tiles. The result is all active tree tiles | |
319 // get memory, and 3 of the pending tree tiles get memory. | |
320 // The pending tiles are not needed to avoid calimity (flickering or | |
321 // raster-on-demand) and the active tiles fit, so the soft limit is used. | |
322 | |
323 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
324 TileVector active_tree_tiles = | |
325 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
326 TileVector pending_tree_tiles = | |
327 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
328 | |
329 tile_manager()->AssignMemoryToTiles(global_state_); | |
330 | |
331 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
332 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
333 | |
334 ReleaseTiles(&active_tree_tiles); | |
335 ReleaseTiles(&pending_tree_tiles); | |
336 } | |
337 | |
338 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { | |
339 // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are | |
340 // required for activation, but only enough tiles for 4 tiles. The result | |
341 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
342 // get memory. | |
343 | |
344 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
345 TileVector active_tree_tiles = | |
346 CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); | |
347 TileVector pending_tree_tiles = | |
348 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
349 | |
350 tile_manager()->AssignMemoryToTiles(global_state_); | |
351 | |
352 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
353 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
354 | |
355 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
356 tile_manager()->AssignMemoryToTiles(global_state_); | |
357 | |
358 if (UsingResourceLimit()) { | |
359 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
360 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
361 } else { | |
362 // Pending tiles are now required to avoid calimity (flickering or | |
363 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
364 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
365 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
366 } | |
367 | |
368 ReleaseTiles(&active_tree_tiles); | |
369 ReleaseTiles(&pending_tree_tiles); | |
370 } | |
371 | |
372 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | |
373 // 10 tiles on active tree soon bin, 10 tiles on pending tree that are | |
374 // required for activation, but only enough tiles for 4 tiles. The result | |
375 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
376 // get memory. | |
377 | |
378 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
379 TileVector active_tree_tiles = | |
380 CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); | |
381 TileVector pending_tree_tiles = | |
382 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
383 | |
384 tile_manager()->AssignMemoryToTiles(global_state_); | |
385 | |
386 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
387 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
388 | |
389 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
390 tile_manager()->AssignMemoryToTiles(global_state_); | |
391 | |
392 if (UsingResourceLimit()) { | |
393 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
394 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
395 } else { | |
396 // Pending tiles are now required to avoid calimity (flickering or | |
397 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
398 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
399 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
400 } | |
401 | |
402 ReleaseTiles(&active_tree_tiles); | |
403 ReleaseTiles(&pending_tree_tiles); | |
404 } | |
405 | |
406 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { | |
407 // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, | |
408 // but only enough memory for 4 tiles. The result is 4 active tree tiles | |
409 // get memory, and none of the pending tree tiles get memory. | |
410 | |
411 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
412 TileVector active_tree_tiles = | |
413 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
414 TileVector pending_tree_tiles = | |
415 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
416 | |
417 tile_manager()->AssignMemoryToTiles(global_state_); | |
418 | |
419 if (UsingResourceLimit()) { | |
420 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
421 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
422 } else { | |
423 // Active tiles are required to avoid calimity (flickering or | |
424 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
425 EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); | |
426 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
427 } | |
428 | |
429 ReleaseTiles(&active_tree_tiles); | |
430 ReleaseTiles(&pending_tree_tiles); | |
431 } | |
432 | |
433 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { | |
434 // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, | |
435 // but only enough memory for 8 tiles. Any tile missing would cause | |
436 // a calamity (flickering or raster-on-demand). Depending on mode, | |
437 // we should use varying amounts of the higher hard memory limit. | |
438 if (UsingResourceLimit()) | |
439 return; | |
440 | |
441 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
442 TileVector active_tree_tiles = | |
443 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
444 TileVector pending_tree_tiles = | |
445 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
446 | |
447 // Active tiles are required to avoid calimity. The hard-limit is used and all | |
448 // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 | |
449 // tiles total are used. | |
450 tile_manager()->AssignMemoryToTiles(global_state_); | |
451 EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); | |
452 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
453 | |
454 // Even the hard-limit won't save us now. All tiles are required to avoid | |
455 // a clamity but we only have 16. The tiles will be distribted randomly | |
456 // given they are identical, in practice depending on their screen location. | |
457 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
458 tile_manager()->AssignMemoryToTiles(global_state_); | |
459 EXPECT_EQ(16, | |
460 AssignedMemoryCount(active_tree_tiles) + | |
461 AssignedMemoryCount(pending_tree_tiles)); | |
462 | |
463 // The pending tree is now more important. Active tiles will take higher | |
464 // priority if they are ready-to-draw in practice. Importantly though, | |
465 // pending tiles also utilize the hard-limit. | |
466 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); | |
467 tile_manager()->AssignMemoryToTiles(global_state_); | |
468 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
469 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | |
470 | |
471 ReleaseTiles(&active_tree_tiles); | |
472 ReleaseTiles(&pending_tree_tiles); | |
473 } | |
474 | |
475 // If true, the max tile limit should be applied as bytes; if false, | |
476 // as num_resources_limit. | |
477 INSTANTIATE_TEST_CASE_P(TileManagerTests, | |
478 TileManagerTest, | |
479 ::testing::Values(true, false)); | |
480 | |
481 class TileManagerTilePriorityQueueTest : public testing::Test { | 25 class TileManagerTilePriorityQueueTest : public testing::Test { |
482 public: | 26 public: |
483 TileManagerTilePriorityQueueTest() | 27 TileManagerTilePriorityQueueTest() |
484 : memory_limit_policy_(ALLOW_ANYTHING), | 28 : memory_limit_policy_(ALLOW_ANYTHING), |
485 max_tiles_(10000), | 29 max_tiles_(10000), |
486 ready_to_activate_(false), | 30 ready_to_activate_(false), |
487 id_(7), | 31 id_(7), |
488 proxy_(base::MessageLoopProxy::current()), | 32 proxy_(base::MessageLoopProxy::current()), |
489 host_impl_(ImplSidePaintingSettings(), | 33 host_impl_(ImplSidePaintingSettings(), |
490 &proxy_, | 34 &proxy_, |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 all_tiles.insert(active_high_res_tiles[i]); | 435 all_tiles.insert(active_high_res_tiles[i]); |
892 | 436 |
893 std::vector<Tile*> active_low_res_tiles = | 437 std::vector<Tile*> active_low_res_tiles = |
894 active_layer_->LowResTiling()->AllTilesForTesting(); | 438 active_layer_->LowResTiling()->AllTilesForTesting(); |
895 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 439 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
896 all_tiles.insert(active_low_res_tiles[i]); | 440 all_tiles.insert(active_low_res_tiles[i]); |
897 | 441 |
898 tile_manager()->InitializeTilesWithResourcesForTesting( | 442 tile_manager()->InitializeTilesWithResourcesForTesting( |
899 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 443 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
900 | 444 |
901 pending_layer_->MarkVisibleResourcesAsRequired(); | |
902 | |
903 Tile* last_tile = NULL; | 445 Tile* last_tile = NULL; |
904 smoothness_tiles.clear(); | 446 smoothness_tiles.clear(); |
905 tile_count = 0; | 447 tile_count = 0; |
906 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 448 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
907 queue.Reset(); | 449 queue.Reset(); |
908 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 450 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
909 while (!queue.IsEmpty()) { | 451 while (!queue.IsEmpty()) { |
910 Tile* tile = queue.Top(); | 452 Tile* tile = queue.Top(); |
911 EXPECT_TRUE(tile); | 453 EXPECT_TRUE(tile); |
912 EXPECT_TRUE(tile->HasResources()); | 454 EXPECT_TRUE(tile->HasResources()); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1056 all_tiles.insert(pending_high_res_tiles[i]); | 598 all_tiles.insert(pending_high_res_tiles[i]); |
1057 | 599 |
1058 std::vector<Tile*> pending_low_res_tiles = | 600 std::vector<Tile*> pending_low_res_tiles = |
1059 pending_layer_->LowResTiling()->AllTilesForTesting(); | 601 pending_layer_->LowResTiling()->AllTilesForTesting(); |
1060 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) | 602 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) |
1061 all_tiles.insert(pending_low_res_tiles[i]); | 603 all_tiles.insert(pending_low_res_tiles[i]); |
1062 | 604 |
1063 // Set all tiles on the pending_child_layer as occluded on the pending tree. | 605 // Set all tiles on the pending_child_layer as occluded on the pending tree. |
1064 std::vector<Tile*> pending_child_high_res_tiles = | 606 std::vector<Tile*> pending_child_high_res_tiles = |
1065 pending_child_layer->HighResTiling()->AllTilesForTesting(); | 607 pending_child_layer->HighResTiling()->AllTilesForTesting(); |
| 608 pending_child_layer->HighResTiling()->SetAllTilesOccludedForTesting(); |
1066 for (size_t i = 0; i < pending_child_high_res_tiles.size(); ++i) { | 609 for (size_t i = 0; i < pending_child_high_res_tiles.size(); ++i) { |
1067 pending_child_high_res_tiles[i]->set_is_occluded(PENDING_TREE, true); | |
1068 all_tiles.insert(pending_child_high_res_tiles[i]); | 610 all_tiles.insert(pending_child_high_res_tiles[i]); |
1069 } | 611 } |
1070 | 612 |
1071 std::vector<Tile*> pending_child_low_res_tiles = | 613 std::vector<Tile*> pending_child_low_res_tiles = |
1072 pending_child_layer->LowResTiling()->AllTilesForTesting(); | 614 pending_child_layer->LowResTiling()->AllTilesForTesting(); |
| 615 pending_child_layer->LowResTiling()->SetAllTilesOccludedForTesting(); |
1073 for (size_t i = 0; i < pending_child_low_res_tiles.size(); ++i) { | 616 for (size_t i = 0; i < pending_child_low_res_tiles.size(); ++i) { |
1074 pending_child_low_res_tiles[i]->set_is_occluded(PENDING_TREE, true); | |
1075 all_tiles.insert(pending_child_low_res_tiles[i]); | 617 all_tiles.insert(pending_child_low_res_tiles[i]); |
1076 } | 618 } |
1077 | 619 |
1078 tile_manager()->InitializeTilesWithResourcesForTesting( | 620 tile_manager()->InitializeTilesWithResourcesForTesting( |
1079 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 621 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
1080 | 622 |
1081 // Verify occlusion is considered by EvictionTilePriorityQueue. | 623 // Verify occlusion is considered by EvictionTilePriorityQueue. |
1082 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; | 624 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; |
1083 size_t occluded_count = 0u; | 625 size_t occluded_count = 0u; |
1084 Tile* last_tile = NULL; | 626 Tile* last_tile = NULL; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 all_tiles.insert(queue.Top()); | 751 all_tiles.insert(queue.Top()); |
1210 ++tile_count; | 752 ++tile_count; |
1211 queue.Pop(); | 753 queue.Pop(); |
1212 } | 754 } |
1213 EXPECT_EQ(tile_count, all_tiles.size()); | 755 EXPECT_EQ(tile_count, all_tiles.size()); |
1214 EXPECT_EQ(17u, tile_count); | 756 EXPECT_EQ(17u, tile_count); |
1215 } | 757 } |
1216 | 758 |
1217 } // namespace | 759 } // namespace |
1218 } // namespace cc | 760 } // namespace cc |
OLD | NEW |