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(output_surface_.get(), | |
43 shared_bitmap_manager_.get(), | |
44 NULL, | |
45 0, | |
46 false, | |
47 1, | |
48 false); | |
49 resource_pool_ = ResourcePool::Create( | |
50 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | |
51 tile_manager_ = | |
52 make_scoped_ptr(new FakeTileManager(this, resource_pool_.get())); | |
53 | |
54 memory_limit_policy_ = memory_limit_policy; | |
55 max_tiles_ = max_tiles; | |
56 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | |
57 | |
58 SetTreePriority(tree_priority); | |
59 } | |
60 | |
61 void SetTreePriority(TreePriority tree_priority) { | |
62 GlobalStateThatImpactsTilePriority state; | |
63 gfx::Size tile_size = settings_.default_tile_size; | |
64 | |
65 if (UsingMemoryLimit()) { | |
66 state.soft_memory_limit_in_bytes = | |
67 max_tiles_ * 4 * tile_size.width() * tile_size.height(); | |
68 state.num_resources_limit = 100; | |
69 } else { | |
70 state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; | |
71 state.num_resources_limit = max_tiles_; | |
72 } | |
73 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; | |
74 state.memory_limit_policy = memory_limit_policy_; | |
75 state.tree_priority = tree_priority; | |
76 | |
77 global_state_ = state; | |
78 resource_pool_->SetResourceUsageLimits(state.soft_memory_limit_in_bytes, | |
79 state.soft_memory_limit_in_bytes, | |
80 state.num_resources_limit); | |
81 tile_manager_->SetGlobalStateForTesting(state); | |
82 } | |
83 | |
84 virtual void TearDown() OVERRIDE { | |
85 tile_manager_.reset(NULL); | |
86 picture_pile_ = NULL; | |
87 | |
88 testing::Test::TearDown(); | |
89 } | |
90 | |
91 // TileManagerClient implementation. | |
92 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() | |
93 const OVERRIDE { | |
94 return picture_layers_; | |
95 } | |
96 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | |
97 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} | |
98 virtual void BuildRasterQueue(RasterTilePriorityQueue* queue, | |
99 TreePriority priority) OVERRIDE {} | |
100 virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue, | |
101 TreePriority priority) OVERRIDE {} | |
102 | |
103 TileVector CreateTilesWithSize(int count, | |
104 TilePriority active_priority, | |
105 TilePriority pending_priority, | |
106 const gfx::Size& tile_size) { | |
107 TileVector tiles; | |
108 for (int i = 0; i < count; ++i) { | |
109 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | |
110 tile_size, | |
111 gfx::Rect(), | |
112 gfx::Rect(), | |
113 1.0, | |
114 0, | |
115 0, | |
116 0); | |
117 tile->SetPriority(ACTIVE_TREE, active_priority); | |
118 tile->SetPriority(PENDING_TREE, pending_priority); | |
119 tiles.push_back(tile); | |
120 } | |
121 return tiles; | |
122 } | |
123 | |
124 TileVector CreateTiles(int count, | |
125 TilePriority active_priority, | |
126 TilePriority pending_priority) { | |
127 return CreateTilesWithSize( | |
128 count, active_priority, pending_priority, settings_.default_tile_size); | |
129 } | |
130 | |
131 void ReleaseTiles(TileVector* tiles) { | |
132 for (TileVector::iterator it = tiles->begin(); it != tiles->end(); it++) { | |
133 Tile* tile = it->get(); | |
134 tile->SetPriority(ACTIVE_TREE, TilePriority()); | |
135 tile->SetPriority(PENDING_TREE, TilePriority()); | |
136 } | |
137 } | |
138 | |
139 FakeTileManager* tile_manager() { return tile_manager_.get(); } | |
140 | |
141 int AssignedMemoryCount(const TileVector& tiles) { | |
142 int has_memory_count = 0; | |
143 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | |
144 ++it) { | |
145 if (tile_manager_->HasBeenAssignedMemory(it->get())) | |
146 ++has_memory_count; | |
147 } | |
148 return has_memory_count; | |
149 } | |
150 | |
151 bool ready_to_activate() const { return ready_to_activate_; } | |
152 | |
153 // The parametrization specifies whether the max tile limit should | |
154 // be applied to memory or resources. | |
155 bool UsingResourceLimit() { return !GetParam(); } | |
156 bool UsingMemoryLimit() { return GetParam(); } | |
157 | |
158 protected: | |
159 GlobalStateThatImpactsTilePriority global_state_; | |
160 | |
161 private: | |
162 LayerTreeSettings settings_; | |
163 scoped_ptr<FakeTileManager> tile_manager_; | |
164 scoped_refptr<FakePicturePileImpl> picture_pile_; | |
165 FakeOutputSurfaceClient output_surface_client_; | |
166 scoped_ptr<FakeOutputSurface> output_surface_; | |
167 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
168 scoped_ptr<ResourceProvider> resource_provider_; | |
169 scoped_ptr<ResourcePool> resource_pool_; | |
170 TileMemoryLimitPolicy memory_limit_policy_; | |
171 int max_tiles_; | |
172 bool ready_to_activate_; | |
173 std::vector<PictureLayerImpl*> picture_layers_; | |
174 }; | |
175 | |
176 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { | |
177 // A few tiles of each type of priority, with enough memory for all tiles. | |
178 | |
179 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
180 TileVector active_now = | |
181 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
182 TileVector pending_now = | |
183 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
184 TileVector active_pending_soon = | |
185 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
186 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
187 | |
188 tile_manager()->AssignMemoryToTiles(global_state_); | |
189 | |
190 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
191 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
192 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
193 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
194 | |
195 ReleaseTiles(&active_now); | |
196 ReleaseTiles(&pending_now); | |
197 ReleaseTiles(&active_pending_soon); | |
198 ReleaseTiles(&never_bin); | |
199 } | |
200 | |
201 TEST_P(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { | |
202 // A few tiles of each type of priority, with enough memory for all tiles, | |
203 // with the exception of never bin. | |
204 | |
205 Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); | |
206 TileVector active_now = | |
207 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
208 TileVector pending_now = | |
209 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
210 TileVector active_pending_soon = | |
211 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
212 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
213 | |
214 tile_manager()->AssignMemoryToTiles(global_state_); | |
215 | |
216 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
217 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
218 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
219 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
220 | |
221 ReleaseTiles(&active_now); | |
222 ReleaseTiles(&pending_now); | |
223 ReleaseTiles(&active_pending_soon); | |
224 ReleaseTiles(&never_bin); | |
225 } | |
226 | |
227 TEST_P(TileManagerTest, EnoughMemoryPendingLowResAllowAbsoluteMinimum) { | |
228 // A few low-res tiles required for activation, with enough memory for all | |
229 // tiles. | |
230 | |
231 Initialize(5, ALLOW_ABSOLUTE_MINIMUM, SAME_PRIORITY_FOR_BOTH_TREES); | |
232 TileVector pending_low_res = | |
233 CreateTiles(5, TilePriority(), TilePriorityLowRes()); | |
234 | |
235 tile_manager()->AssignMemoryToTiles(global_state_); | |
236 | |
237 EXPECT_EQ(5, AssignedMemoryCount(pending_low_res)); | |
238 ReleaseTiles(&pending_low_res); | |
239 } | |
240 | |
241 TEST_P(TileManagerTest, EnoughMemoryAllowAbsoluteMinimum) { | |
242 // A few tiles of each type of priority, with enough memory for all tiles, | |
243 // with the exception of never and soon bins. | |
244 | |
245 Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY); | |
246 TileVector active_now = | |
247 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
248 TileVector pending_now = | |
249 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
250 TileVector active_pending_soon = | |
251 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
252 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
253 | |
254 tile_manager()->AssignMemoryToTiles(global_state_); | |
255 | |
256 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
257 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
258 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
259 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
260 | |
261 ReleaseTiles(&active_now); | |
262 ReleaseTiles(&pending_now); | |
263 ReleaseTiles(&active_pending_soon); | |
264 ReleaseTiles(&never_bin); | |
265 } | |
266 | |
267 TEST_P(TileManagerTest, EnoughMemoryAllowNothing) { | |
268 // A few tiles of each type of priority, with enough memory for all tiles, | |
269 // but allow nothing should not assign any memory. | |
270 | |
271 Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY); | |
272 TileVector active_now = | |
273 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
274 TileVector pending_now = | |
275 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
276 TileVector active_pending_soon = | |
277 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
278 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
279 | |
280 tile_manager()->AssignMemoryToTiles(global_state_); | |
281 | |
282 EXPECT_EQ(0, AssignedMemoryCount(active_now)); | |
283 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); | |
284 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
285 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
286 | |
287 ReleaseTiles(&active_now); | |
288 ReleaseTiles(&pending_now); | |
289 ReleaseTiles(&active_pending_soon); | |
290 ReleaseTiles(&never_bin); | |
291 } | |
292 | |
293 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { | |
294 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | |
295 // required for activation, but only enough memory for 8 tiles. The result | |
296 // is all pending tree tiles get memory, and 3 of the active tree tiles | |
297 // get memory. None of these tiles is needed to avoid calimity (flickering or | |
298 // raster-on-demand) so the soft memory limit is used. | |
299 | |
300 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
301 TileVector active_tree_tiles = | |
302 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | |
303 TileVector pending_tree_tiles = | |
304 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | |
305 tile_manager()->AssignMemoryToTiles(global_state_); | |
306 | |
307 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
308 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
309 | |
310 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
311 tile_manager()->AssignMemoryToTiles(global_state_); | |
312 | |
313 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); | |
314 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); | |
315 | |
316 ReleaseTiles(&active_tree_tiles); | |
317 ReleaseTiles(&pending_tree_tiles); | |
318 } | |
319 | |
320 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { | |
321 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | |
322 // but only enough memory for 8 tiles. The result is all active tree tiles | |
323 // get memory, and 3 of the pending tree tiles get memory. | |
324 // The pending tiles are not needed to avoid calimity (flickering or | |
325 // raster-on-demand) and the active tiles fit, so the soft limit is used. | |
326 | |
327 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
328 TileVector active_tree_tiles = | |
329 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
330 TileVector pending_tree_tiles = | |
331 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
332 | |
333 tile_manager()->AssignMemoryToTiles(global_state_); | |
334 | |
335 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
336 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
337 | |
338 ReleaseTiles(&active_tree_tiles); | |
339 ReleaseTiles(&pending_tree_tiles); | |
340 } | |
341 | |
342 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { | |
343 // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are | |
344 // required for activation, but only enough tiles for 4 tiles. The result | |
345 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
346 // get memory. | |
347 | |
348 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
349 TileVector active_tree_tiles = | |
350 CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); | |
351 TileVector pending_tree_tiles = | |
352 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
353 | |
354 tile_manager()->AssignMemoryToTiles(global_state_); | |
355 | |
356 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
357 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
358 | |
359 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
360 tile_manager()->AssignMemoryToTiles(global_state_); | |
361 | |
362 if (UsingResourceLimit()) { | |
363 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
364 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
365 } else { | |
366 // Pending tiles are now required to avoid calimity (flickering or | |
367 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
368 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
369 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
370 } | |
371 | |
372 ReleaseTiles(&active_tree_tiles); | |
373 ReleaseTiles(&pending_tree_tiles); | |
374 } | |
375 | |
376 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | |
377 // 10 tiles on active tree soon bin, 10 tiles on pending tree that are | |
378 // required for activation, but only enough tiles for 4 tiles. The result | |
379 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
380 // get memory. | |
381 | |
382 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
383 TileVector active_tree_tiles = | |
384 CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); | |
385 TileVector pending_tree_tiles = | |
386 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
387 | |
388 tile_manager()->AssignMemoryToTiles(global_state_); | |
389 | |
390 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
391 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
392 | |
393 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
394 tile_manager()->AssignMemoryToTiles(global_state_); | |
395 | |
396 if (UsingResourceLimit()) { | |
397 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
398 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
399 } else { | |
400 // Pending tiles are now required to avoid calimity (flickering or | |
401 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
402 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
403 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
404 } | |
405 | |
406 ReleaseTiles(&active_tree_tiles); | |
407 ReleaseTiles(&pending_tree_tiles); | |
408 } | |
409 | |
410 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { | |
411 // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, | |
412 // but only enough memory for 4 tiles. The result is 4 active tree tiles | |
413 // get memory, and none of the pending tree tiles get memory. | |
414 | |
415 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
416 TileVector active_tree_tiles = | |
417 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
418 TileVector pending_tree_tiles = | |
419 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
420 | |
421 tile_manager()->AssignMemoryToTiles(global_state_); | |
422 | |
423 if (UsingResourceLimit()) { | |
424 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
425 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
426 } else { | |
427 // Active tiles are required to avoid calimity (flickering or | |
428 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
429 EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); | |
430 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
431 } | |
432 | |
433 ReleaseTiles(&active_tree_tiles); | |
434 ReleaseTiles(&pending_tree_tiles); | |
435 } | |
436 | |
437 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { | |
438 // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, | |
439 // but only enough memory for 8 tiles. Any tile missing would cause | |
440 // a calamity (flickering or raster-on-demand). Depending on mode, | |
441 // we should use varying amounts of the higher hard memory limit. | |
442 if (UsingResourceLimit()) | |
443 return; | |
444 | |
445 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
446 TileVector active_tree_tiles = | |
447 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
448 TileVector pending_tree_tiles = | |
449 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
450 | |
451 // Active tiles are required to avoid calimity. The hard-limit is used and all | |
452 // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 | |
453 // tiles total are used. | |
454 tile_manager()->AssignMemoryToTiles(global_state_); | |
455 EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); | |
456 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
457 | |
458 // Even the hard-limit won't save us now. All tiles are required to avoid | |
459 // a clamity but we only have 16. The tiles will be distribted randomly | |
460 // given they are identical, in practice depending on their screen location. | |
461 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
462 tile_manager()->AssignMemoryToTiles(global_state_); | |
463 EXPECT_EQ(16, | |
464 AssignedMemoryCount(active_tree_tiles) + | |
465 AssignedMemoryCount(pending_tree_tiles)); | |
466 | |
467 // The pending tree is now more important. Active tiles will take higher | |
468 // priority if they are ready-to-draw in practice. Importantly though, | |
469 // pending tiles also utilize the hard-limit. | |
470 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); | |
471 tile_manager()->AssignMemoryToTiles(global_state_); | |
472 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
473 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | |
474 | |
475 ReleaseTiles(&active_tree_tiles); | |
476 ReleaseTiles(&pending_tree_tiles); | |
477 } | |
478 | |
479 // If true, the max tile limit should be applied as bytes; if false, | |
480 // as num_resources_limit. | |
481 INSTANTIATE_TEST_CASE_P(TileManagerTests, | |
482 TileManagerTest, | |
483 ::testing::Values(true, false)); | |
484 | |
485 class LowResTilingsSettings : public ImplSidePaintingSettings { | 25 class LowResTilingsSettings : public ImplSidePaintingSettings { |
486 public: | 26 public: |
487 LowResTilingsSettings() { create_low_res_tiling = true; } | 27 LowResTilingsSettings() { create_low_res_tiling = true; } |
488 }; | 28 }; |
489 | 29 |
490 class TileManagerTilePriorityQueueTest : public testing::Test { | 30 class TileManagerTilePriorityQueueTest : public testing::Test { |
491 public: | 31 public: |
492 TileManagerTilePriorityQueueTest() | 32 TileManagerTilePriorityQueueTest() |
493 : memory_limit_policy_(ALLOW_ANYTHING), | 33 : memory_limit_policy_(ALLOW_ANYTHING), |
494 max_tiles_(10000), | 34 max_tiles_(10000), |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 all_tiles.insert(active_high_res_tiles[i]); | 390 all_tiles.insert(active_high_res_tiles[i]); |
851 | 391 |
852 std::vector<Tile*> active_low_res_tiles = | 392 std::vector<Tile*> active_low_res_tiles = |
853 active_layer_->LowResTiling()->AllTilesForTesting(); | 393 active_layer_->LowResTiling()->AllTilesForTesting(); |
854 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 394 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
855 all_tiles.insert(active_low_res_tiles[i]); | 395 all_tiles.insert(active_low_res_tiles[i]); |
856 | 396 |
857 tile_manager()->InitializeTilesWithResourcesForTesting( | 397 tile_manager()->InitializeTilesWithResourcesForTesting( |
858 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 398 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
859 | 399 |
860 pending_layer_->MarkVisibleResourcesAsRequired(); | |
861 | |
862 Tile* last_tile = NULL; | 400 Tile* last_tile = NULL; |
863 smoothness_tiles.clear(); | 401 smoothness_tiles.clear(); |
864 tile_count = 0; | 402 tile_count = 0; |
865 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 403 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
866 queue.Reset(); | 404 queue.Reset(); |
867 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 405 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
868 while (!queue.IsEmpty()) { | 406 while (!queue.IsEmpty()) { |
869 Tile* tile = queue.Top(); | 407 Tile* tile = queue.Top(); |
870 EXPECT_TRUE(tile); | 408 EXPECT_TRUE(tile); |
871 EXPECT_TRUE(tile->HasResources()); | 409 EXPECT_TRUE(tile->HasResources()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
991 all_tiles.insert(pending_high_res_tiles[i]); | 529 all_tiles.insert(pending_high_res_tiles[i]); |
992 | 530 |
993 std::vector<Tile*> pending_low_res_tiles = | 531 std::vector<Tile*> pending_low_res_tiles = |
994 pending_layer_->LowResTiling()->AllTilesForTesting(); | 532 pending_layer_->LowResTiling()->AllTilesForTesting(); |
995 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) | 533 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) |
996 all_tiles.insert(pending_low_res_tiles[i]); | 534 all_tiles.insert(pending_low_res_tiles[i]); |
997 | 535 |
998 // Set all tiles on the pending_child_layer as occluded on the pending tree. | 536 // Set all tiles on the pending_child_layer as occluded on the pending tree. |
999 std::vector<Tile*> pending_child_high_res_tiles = | 537 std::vector<Tile*> pending_child_high_res_tiles = |
1000 pending_child_layer->HighResTiling()->AllTilesForTesting(); | 538 pending_child_layer->HighResTiling()->AllTilesForTesting(); |
| 539 pending_child_layer->HighResTiling()->SetAllTilesOccludedForTesting(); |
1001 for (size_t i = 0; i < pending_child_high_res_tiles.size(); ++i) { | 540 for (size_t i = 0; i < pending_child_high_res_tiles.size(); ++i) { |
1002 pending_child_high_res_tiles[i]->set_is_occluded(PENDING_TREE, true); | |
1003 all_tiles.insert(pending_child_high_res_tiles[i]); | 541 all_tiles.insert(pending_child_high_res_tiles[i]); |
1004 } | 542 } |
1005 | 543 |
1006 std::vector<Tile*> pending_child_low_res_tiles = | 544 std::vector<Tile*> pending_child_low_res_tiles = |
1007 pending_child_layer->LowResTiling()->AllTilesForTesting(); | 545 pending_child_layer->LowResTiling()->AllTilesForTesting(); |
| 546 pending_child_layer->LowResTiling()->SetAllTilesOccludedForTesting(); |
1008 for (size_t i = 0; i < pending_child_low_res_tiles.size(); ++i) { | 547 for (size_t i = 0; i < pending_child_low_res_tiles.size(); ++i) { |
1009 pending_child_low_res_tiles[i]->set_is_occluded(PENDING_TREE, true); | |
1010 all_tiles.insert(pending_child_low_res_tiles[i]); | 548 all_tiles.insert(pending_child_low_res_tiles[i]); |
1011 } | 549 } |
1012 | 550 |
1013 tile_manager()->InitializeTilesWithResourcesForTesting( | 551 tile_manager()->InitializeTilesWithResourcesForTesting( |
1014 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 552 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
1015 | 553 |
1016 // Verify occlusion is considered by EvictionTilePriorityQueue. | 554 // Verify occlusion is considered by EvictionTilePriorityQueue. |
1017 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; | 555 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; |
1018 size_t occluded_count = 0u; | 556 size_t occluded_count = 0u; |
1019 Tile* last_tile = NULL; | 557 Tile* last_tile = NULL; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 all_tiles.insert(queue.Top()); | 682 all_tiles.insert(queue.Top()); |
1145 ++tile_count; | 683 ++tile_count; |
1146 queue.Pop(); | 684 queue.Pop(); |
1147 } | 685 } |
1148 EXPECT_EQ(tile_count, all_tiles.size()); | 686 EXPECT_EQ(tile_count, all_tiles.size()); |
1149 EXPECT_EQ(17u, tile_count); | 687 EXPECT_EQ(17u, tile_count); |
1150 } | 688 } |
1151 | 689 |
1152 } // namespace | 690 } // namespace |
1153 } // namespace cc | 691 } // namespace cc |
OLD | NEW |