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/tile.h" | 5 #include "cc/resources/tile.h" |
6 #include "cc/resources/tile_priority.h" | 6 #include "cc/resources/tile_priority.h" |
7 #include "cc/test/fake_impl_proxy.h" | 7 #include "cc/test/fake_impl_proxy.h" |
8 #include "cc/test/fake_layer_tree_host_impl.h" | 8 #include "cc/test/fake_layer_tree_host_impl.h" |
9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
10 #include "cc/test/fake_output_surface_client.h" | 10 #include "cc/test/fake_output_surface_client.h" |
11 #include "cc/test/fake_picture_layer_impl.h" | 11 #include "cc/test/fake_picture_layer_impl.h" |
12 #include "cc/test/fake_picture_pile_impl.h" | 12 #include "cc/test/fake_picture_pile_impl.h" |
13 #include "cc/test/fake_tile_manager.h" | 13 #include "cc/test/fake_tile_manager.h" |
14 #include "cc/test/impl_side_painting_settings.h" | 14 #include "cc/test/impl_side_painting_settings.h" |
15 #include "cc/test/test_shared_bitmap_manager.h" | 15 #include "cc/test/test_shared_bitmap_manager.h" |
16 #include "cc/test/test_tile_priorities.h" | 16 #include "cc/test/test_tile_priorities.h" |
17 #include "cc/trees/layer_tree_impl.h" | 17 #include "cc/trees/layer_tree_impl.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 | 19 |
20 namespace cc { | 20 namespace cc { |
21 namespace { | 21 namespace { |
22 | 22 |
23 class TileManagerTest : public testing::TestWithParam<bool>, | |
24 public TileManagerClient { | |
25 public: | |
26 typedef std::vector<scoped_refptr<Tile> > TileVector; | |
27 | |
28 TileManagerTest() | |
29 : memory_limit_policy_(ALLOW_ANYTHING), | |
30 max_tiles_(0), | |
31 ready_to_activate_(false) {} | |
32 | |
33 void Initialize(int max_tiles, | |
34 TileMemoryLimitPolicy memory_limit_policy, | |
35 TreePriority tree_priority, | |
36 bool allow_on_demand_raster = true) { | |
37 output_surface_ = FakeOutputSurface::Create3d(); | |
38 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
39 | |
40 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | |
41 resource_provider_ = ResourceProvider::Create( | |
42 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, | |
43 false); | |
44 resource_pool_ = ResourcePool::Create( | |
45 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | |
46 tile_manager_ = make_scoped_ptr(new FakeTileManager( | |
47 this, resource_pool_.get(), allow_on_demand_raster)); | |
48 | |
49 memory_limit_policy_ = memory_limit_policy; | |
50 max_tiles_ = max_tiles; | |
51 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | |
52 | |
53 SetTreePriority(tree_priority); | |
54 } | |
55 | |
56 void SetTreePriority(TreePriority tree_priority) { | |
57 GlobalStateThatImpactsTilePriority state; | |
58 gfx::Size tile_size = settings_.default_tile_size; | |
59 | |
60 if (UsingMemoryLimit()) { | |
61 state.soft_memory_limit_in_bytes = | |
62 max_tiles_ * 4 * tile_size.width() * tile_size.height(); | |
63 state.num_resources_limit = 100; | |
64 } else { | |
65 state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; | |
66 state.num_resources_limit = max_tiles_; | |
67 } | |
68 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; | |
69 state.memory_limit_policy = memory_limit_policy_; | |
70 state.tree_priority = tree_priority; | |
71 | |
72 global_state_ = state; | |
73 resource_pool_->SetResourceUsageLimits(state.soft_memory_limit_in_bytes, | |
74 state.soft_memory_limit_in_bytes, | |
75 state.num_resources_limit); | |
76 tile_manager_->SetGlobalStateForTesting(state); | |
77 } | |
78 | |
79 virtual void TearDown() OVERRIDE { | |
80 tile_manager_.reset(NULL); | |
81 picture_pile_ = NULL; | |
82 | |
83 testing::Test::TearDown(); | |
84 } | |
85 | |
86 // TileManagerClient implementation. | |
87 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | |
88 virtual void NotifyTileInitialized(const Tile* tile) OVERRIDE {} | |
89 | |
90 TileVector CreateTilesWithSize(int count, | |
91 TilePriority active_priority, | |
92 TilePriority pending_priority, | |
93 const gfx::Size& tile_size) { | |
94 TileVector tiles; | |
95 for (int i = 0; i < count; ++i) { | |
96 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | |
97 tile_size, | |
98 gfx::Rect(), | |
99 gfx::Rect(), | |
100 1.0, | |
101 0, | |
102 0, | |
103 Tile::USE_LCD_TEXT); | |
104 tile->SetPriority(ACTIVE_TREE, active_priority); | |
105 tile->SetPriority(PENDING_TREE, pending_priority); | |
106 tiles.push_back(tile); | |
107 } | |
108 return tiles; | |
109 } | |
110 | |
111 TileVector CreateTiles(int count, | |
112 TilePriority active_priority, | |
113 TilePriority pending_priority) { | |
114 return CreateTilesWithSize( | |
115 count, active_priority, pending_priority, settings_.default_tile_size); | |
116 } | |
117 | |
118 FakeTileManager* tile_manager() { return tile_manager_.get(); } | |
119 | |
120 int AssignedMemoryCount(const TileVector& tiles) { | |
121 int has_memory_count = 0; | |
122 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | |
123 ++it) { | |
124 if (tile_manager_->HasBeenAssignedMemory(*it)) | |
125 ++has_memory_count; | |
126 } | |
127 return has_memory_count; | |
128 } | |
129 | |
130 int TilesWithLCDCount(const TileVector& tiles) { | |
131 int has_lcd_count = 0; | |
132 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | |
133 ++it) { | |
134 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE) | |
135 ++has_lcd_count; | |
136 } | |
137 return has_lcd_count; | |
138 } | |
139 | |
140 bool ready_to_activate() const { return ready_to_activate_; } | |
141 | |
142 // The parametrization specifies whether the max tile limit should | |
143 // be applied to memory or resources. | |
144 bool UsingResourceLimit() { return !GetParam(); } | |
145 bool UsingMemoryLimit() { return GetParam(); } | |
146 | |
147 protected: | |
148 GlobalStateThatImpactsTilePriority global_state_; | |
149 | |
150 private: | |
151 LayerTreeSettings settings_; | |
152 scoped_ptr<FakeTileManager> tile_manager_; | |
153 scoped_refptr<FakePicturePileImpl> picture_pile_; | |
154 FakeOutputSurfaceClient output_surface_client_; | |
155 scoped_ptr<FakeOutputSurface> output_surface_; | |
156 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
157 scoped_ptr<ResourceProvider> resource_provider_; | |
158 scoped_ptr<ResourcePool> resource_pool_; | |
159 TileMemoryLimitPolicy memory_limit_policy_; | |
160 int max_tiles_; | |
161 bool ready_to_activate_; | |
162 }; | |
163 | |
164 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { | |
165 // A few tiles of each type of priority, with enough memory for all tiles. | |
166 | |
167 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
168 TileVector active_now = | |
169 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
170 TileVector pending_now = | |
171 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
172 TileVector active_pending_soon = | |
173 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
174 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
175 | |
176 tile_manager()->AssignMemoryToTiles(global_state_); | |
177 | |
178 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
179 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
180 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
181 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
182 } | |
183 | |
184 TEST_P(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { | |
185 // A few tiles of each type of priority, with enough memory for all tiles, | |
186 // with the exception of never bin. | |
187 | |
188 Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); | |
189 TileVector active_now = | |
190 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
191 TileVector pending_now = | |
192 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
193 TileVector active_pending_soon = | |
194 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
195 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
196 | |
197 tile_manager()->AssignMemoryToTiles(global_state_); | |
198 | |
199 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
200 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
201 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
202 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
203 } | |
204 | |
205 TEST_P(TileManagerTest, EnoughMemoryPendingLowResAllowAbsoluteMinimum) { | |
206 // A few low-res tiles required for activation, with enough memory for all | |
207 // tiles. | |
208 | |
209 Initialize(5, ALLOW_ABSOLUTE_MINIMUM, SAME_PRIORITY_FOR_BOTH_TREES); | |
210 TileVector pending_low_res = | |
211 CreateTiles(5, TilePriority(), TilePriorityLowRes()); | |
212 | |
213 tile_manager()->AssignMemoryToTiles(global_state_); | |
214 | |
215 EXPECT_EQ(5, AssignedMemoryCount(pending_low_res)); | |
216 } | |
217 | |
218 TEST_P(TileManagerTest, EnoughMemoryAllowAbsoluteMinimum) { | |
219 // A few tiles of each type of priority, with enough memory for all tiles, | |
220 // with the exception of never and soon bins. | |
221 | |
222 Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY); | |
223 TileVector active_now = | |
224 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
225 TileVector pending_now = | |
226 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
227 TileVector active_pending_soon = | |
228 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
229 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
230 | |
231 tile_manager()->AssignMemoryToTiles(global_state_); | |
232 | |
233 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
234 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
235 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
236 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
237 } | |
238 | |
239 TEST_P(TileManagerTest, EnoughMemoryAllowNothing) { | |
240 // A few tiles of each type of priority, with enough memory for all tiles, | |
241 // but allow nothing should not assign any memory. | |
242 | |
243 Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY); | |
244 TileVector active_now = | |
245 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
246 TileVector pending_now = | |
247 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
248 TileVector active_pending_soon = | |
249 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
250 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
251 | |
252 tile_manager()->AssignMemoryToTiles(global_state_); | |
253 | |
254 EXPECT_EQ(0, AssignedMemoryCount(active_now)); | |
255 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); | |
256 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
257 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
258 } | |
259 | |
260 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { | |
261 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | |
262 // required for activation, but only enough memory for 8 tiles. The result | |
263 // is all pending tree tiles get memory, and 3 of the active tree tiles | |
264 // get memory. None of these tiles is needed to avoid calimity (flickering or | |
265 // raster-on-demand) so the soft memory limit is used. | |
266 | |
267 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
268 TileVector active_tree_tiles = | |
269 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | |
270 TileVector pending_tree_tiles = | |
271 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | |
272 tile_manager()->AssignMemoryToTiles(global_state_); | |
273 | |
274 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
275 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
276 | |
277 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
278 tile_manager()->AssignMemoryToTiles(global_state_); | |
279 | |
280 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); | |
281 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); | |
282 } | |
283 | |
284 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { | |
285 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | |
286 // but only enough memory for 8 tiles. The result is all active tree tiles | |
287 // get memory, and 3 of the pending tree tiles get memory. | |
288 // The pending tiles are not needed to avoid calimity (flickering or | |
289 // raster-on-demand) and the active tiles fit, so the soft limit is used. | |
290 | |
291 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
292 TileVector active_tree_tiles = | |
293 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
294 TileVector pending_tree_tiles = | |
295 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
296 | |
297 tile_manager()->AssignMemoryToTiles(global_state_); | |
298 | |
299 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
300 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
301 } | |
302 | |
303 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { | |
304 // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are | |
305 // required for activation, but only enough tiles for 4 tiles. The result | |
306 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
307 // get memory. | |
308 | |
309 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
310 TileVector active_tree_tiles = | |
311 CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); | |
312 TileVector pending_tree_tiles = | |
313 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
314 | |
315 tile_manager()->AssignMemoryToTiles(global_state_); | |
316 | |
317 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
318 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
319 | |
320 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
321 tile_manager()->AssignMemoryToTiles(global_state_); | |
322 | |
323 if (UsingResourceLimit()) { | |
324 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
325 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
326 } else { | |
327 // Pending tiles are now required to avoid calimity (flickering or | |
328 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
329 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
330 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
331 } | |
332 } | |
333 | |
334 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | |
335 // 10 tiles on active tree soon bin, 10 tiles on pending tree that are | |
336 // required for activation, but only enough tiles for 4 tiles. The result | |
337 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
338 // get memory. | |
339 | |
340 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
341 TileVector active_tree_tiles = | |
342 CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); | |
343 TileVector pending_tree_tiles = | |
344 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
345 | |
346 tile_manager()->AssignMemoryToTiles(global_state_); | |
347 | |
348 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
349 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
350 | |
351 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
352 tile_manager()->AssignMemoryToTiles(global_state_); | |
353 | |
354 if (UsingResourceLimit()) { | |
355 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
356 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
357 } else { | |
358 // Pending tiles are now required to avoid calimity (flickering or | |
359 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
360 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
361 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
362 } | |
363 } | |
364 | |
365 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { | |
366 // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, | |
367 // but only enough memory for 4 tiles. The result is 4 active tree tiles | |
368 // get memory, and none of the pending tree tiles get memory. | |
369 | |
370 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
371 TileVector active_tree_tiles = | |
372 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
373 TileVector pending_tree_tiles = | |
374 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
375 | |
376 tile_manager()->AssignMemoryToTiles(global_state_); | |
377 | |
378 if (UsingResourceLimit()) { | |
379 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
380 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
381 } else { | |
382 // Active tiles are required to avoid calimity (flickering or | |
383 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
384 EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); | |
385 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
386 } | |
387 } | |
388 | |
389 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { | |
390 // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, | |
391 // but only enough memory for 8 tiles. Any tile missing would cause | |
392 // a calamity (flickering or raster-on-demand). Depending on mode, | |
393 // we should use varying amounts of the higher hard memory limit. | |
394 if (UsingResourceLimit()) | |
395 return; | |
396 | |
397 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
398 TileVector active_tree_tiles = | |
399 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
400 TileVector pending_tree_tiles = | |
401 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
402 | |
403 // Active tiles are required to avoid calimity. The hard-limit is used and all | |
404 // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 | |
405 // tiles total are used. | |
406 tile_manager()->AssignMemoryToTiles(global_state_); | |
407 EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); | |
408 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
409 | |
410 // Even the hard-limit won't save us now. All tiles are required to avoid | |
411 // a clamity but we only have 16. The tiles will be distribted randomly | |
412 // given they are identical, in practice depending on their screen location. | |
413 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
414 tile_manager()->AssignMemoryToTiles(global_state_); | |
415 EXPECT_EQ(16, | |
416 AssignedMemoryCount(active_tree_tiles) + | |
417 AssignedMemoryCount(pending_tree_tiles)); | |
418 | |
419 // The pending tree is now more important. Active tiles will take higher | |
420 // priority if they are ready-to-draw in practice. Importantly though, | |
421 // pending tiles also utilize the hard-limit. | |
422 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); | |
423 tile_manager()->AssignMemoryToTiles(global_state_); | |
424 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
425 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | |
426 } | |
427 | |
428 TEST_P(TileManagerTest, RasterAsLCD) { | |
429 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
430 TileVector active_tree_tiles = | |
431 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
432 TileVector pending_tree_tiles = | |
433 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
434 | |
435 tile_manager()->AssignMemoryToTiles(global_state_); | |
436 | |
437 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
438 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
439 } | |
440 | |
441 TEST_P(TileManagerTest, RasterAsNoLCD) { | |
442 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
443 TileVector active_tree_tiles = | |
444 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
445 TileVector pending_tree_tiles = | |
446 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
447 | |
448 for (TileVector::iterator it = active_tree_tiles.begin(); | |
449 it != active_tree_tiles.end(); | |
450 ++it) { | |
451 (*it)->set_can_use_lcd_text(false); | |
452 } | |
453 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
454 it != pending_tree_tiles.end(); | |
455 ++it) { | |
456 (*it)->set_can_use_lcd_text(false); | |
457 } | |
458 | |
459 tile_manager()->AssignMemoryToTiles(global_state_); | |
460 | |
461 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
462 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
463 } | |
464 | |
465 TEST_P(TileManagerTest, ReRasterAsNoLCD) { | |
466 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
467 TileVector active_tree_tiles = | |
468 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
469 TileVector pending_tree_tiles = | |
470 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
471 | |
472 tile_manager()->AssignMemoryToTiles(global_state_); | |
473 | |
474 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
475 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
476 | |
477 for (TileVector::iterator it = active_tree_tiles.begin(); | |
478 it != active_tree_tiles.end(); | |
479 ++it) { | |
480 (*it)->set_can_use_lcd_text(false); | |
481 } | |
482 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
483 it != pending_tree_tiles.end(); | |
484 ++it) { | |
485 (*it)->set_can_use_lcd_text(false); | |
486 } | |
487 | |
488 tile_manager()->AssignMemoryToTiles(global_state_); | |
489 | |
490 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
491 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
492 } | |
493 | |
494 TEST_P(TileManagerTest, NoTextDontReRasterAsNoLCD) { | |
495 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
496 TileVector active_tree_tiles = | |
497 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
498 TileVector pending_tree_tiles = | |
499 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
500 | |
501 tile_manager()->AssignMemoryToTiles(global_state_); | |
502 | |
503 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
504 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
505 | |
506 for (TileVector::iterator it = active_tree_tiles.begin(); | |
507 it != active_tree_tiles.end(); | |
508 ++it) { | |
509 ManagedTileState::TileVersion& tile_version = | |
510 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
511 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
512 (*it)->set_can_use_lcd_text(false); | |
513 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
514 } | |
515 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
516 it != pending_tree_tiles.end(); | |
517 ++it) { | |
518 ManagedTileState::TileVersion& tile_version = | |
519 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
520 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
521 (*it)->set_can_use_lcd_text(false); | |
522 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
523 } | |
524 | |
525 tile_manager()->AssignMemoryToTiles(global_state_); | |
526 | |
527 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
528 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
529 } | |
530 | |
531 TEST_P(TileManagerTest, TextReRasterAsNoLCD) { | |
532 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
533 TileVector active_tree_tiles = | |
534 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
535 TileVector pending_tree_tiles = | |
536 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
537 | |
538 tile_manager()->AssignMemoryToTiles(global_state_); | |
539 | |
540 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
541 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
542 | |
543 for (TileVector::iterator it = active_tree_tiles.begin(); | |
544 it != active_tree_tiles.end(); | |
545 ++it) { | |
546 ManagedTileState::TileVersion& tile_version = | |
547 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
548 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
549 tile_version.SetHasTextForTesting(true); | |
550 (*it)->set_can_use_lcd_text(false); | |
551 | |
552 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
553 } | |
554 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
555 it != pending_tree_tiles.end(); | |
556 ++it) { | |
557 ManagedTileState::TileVersion& tile_version = | |
558 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
559 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
560 tile_version.SetHasTextForTesting(true); | |
561 (*it)->set_can_use_lcd_text(false); | |
562 | |
563 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
564 } | |
565 | |
566 tile_manager()->AssignMemoryToTiles(global_state_); | |
567 | |
568 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
569 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
570 } | |
571 | |
572 TEST_P(TileManagerTest, RespectMemoryLimit) { | |
573 if (UsingResourceLimit()) | |
574 return; | |
575 | |
576 Initialize(5, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
577 | |
578 // We use double the tiles since the hard-limit is double. | |
579 TileVector large_tiles = | |
580 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
581 | |
582 size_t memory_required_bytes; | |
583 size_t memory_nice_to_have_bytes; | |
584 size_t memory_allocated_bytes; | |
585 size_t memory_used_bytes; | |
586 | |
587 tile_manager()->AssignMemoryToTiles(global_state_); | |
588 tile_manager()->GetMemoryStats(&memory_required_bytes, | |
589 &memory_nice_to_have_bytes, | |
590 &memory_allocated_bytes, | |
591 &memory_used_bytes); | |
592 // Allocated bytes should never be more than the memory limit. | |
593 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); | |
594 | |
595 // Finish raster of large tiles. | |
596 tile_manager()->UpdateVisibleTiles(); | |
597 | |
598 // Remove all large tiles. This will leave the memory currently | |
599 // used by these tiles as unused when AssignMemoryToTiles() is called. | |
600 large_tiles.clear(); | |
601 | |
602 // Create a new set of tiles using a different size. These tiles | |
603 // can use the memory currently assigned to the large tiles but | |
604 // they can't use the same resources as the size doesn't match. | |
605 TileVector small_tiles = CreateTilesWithSize( | |
606 10, TilePriorityForNowBin(), TilePriority(), gfx::Size(128, 128)); | |
607 | |
608 tile_manager()->AssignMemoryToTiles(global_state_); | |
609 tile_manager()->GetMemoryStats(&memory_required_bytes, | |
610 &memory_nice_to_have_bytes, | |
611 &memory_allocated_bytes, | |
612 &memory_used_bytes); | |
613 // Allocated bytes should never be more than the memory limit. | |
614 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); | |
615 } | |
616 | |
617 TEST_P(TileManagerTest, AllowRasterizeOnDemand) { | |
618 // Not enough memory to initialize tiles required for activation. | |
619 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES); | |
620 TileVector tiles = | |
621 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
622 | |
623 tile_manager()->AssignMemoryToTiles(global_state_); | |
624 | |
625 // This should make required tiles ready to draw by marking them as | |
626 // required tiles for on-demand raster. | |
627 tile_manager()->DidFinishRunningTasksForTesting(); | |
628 | |
629 EXPECT_TRUE(ready_to_activate()); | |
630 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
631 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
632 } | |
633 | |
634 TEST_P(TileManagerTest, PreventRasterizeOnDemand) { | |
635 // Not enough memory to initialize tiles required for activation. | |
636 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES, false); | |
637 TileVector tiles = | |
638 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
639 | |
640 tile_manager()->AssignMemoryToTiles(global_state_); | |
641 | |
642 // This should make required tiles ready to draw by marking them as | |
643 // required tiles for on-demand raster. | |
644 tile_manager()->DidFinishRunningTasksForTesting(); | |
645 | |
646 EXPECT_TRUE(ready_to_activate()); | |
647 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
648 EXPECT_FALSE((*it)->IsReadyToDraw()); | |
649 } | |
650 | |
651 // If true, the max tile limit should be applied as bytes; if false, | |
652 // as num_resources_limit. | |
653 INSTANTIATE_TEST_CASE_P(TileManagerTests, | |
654 TileManagerTest, | |
655 ::testing::Values(true, false)); | |
656 | |
657 class TileManagerTileIteratorTest : public testing::Test, | 23 class TileManagerTileIteratorTest : public testing::Test, |
658 public TileManagerClient { | 24 public TileManagerClient { |
659 public: | 25 public: |
660 TileManagerTileIteratorTest() | 26 TileManagerTileIteratorTest() |
661 : memory_limit_policy_(ALLOW_ANYTHING), | 27 : memory_limit_policy_(ALLOW_ANYTHING), |
662 max_tiles_(10000), | 28 max_tiles_(10000), |
663 ready_to_activate_(false), | 29 ready_to_activate_(false), |
664 id_(7), | 30 id_(7), |
665 proxy_(base::MessageLoopProxy::current()), | 31 proxy_(base::MessageLoopProxy::current()), |
666 host_impl_(ImplSidePaintingSettings(), | 32 host_impl_(ImplSidePaintingSettings(), |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 | 512 |
1147 last_tile = tile; | 513 last_tile = tile; |
1148 new_content_tiles.insert(tile); | 514 new_content_tiles.insert(tile); |
1149 } | 515 } |
1150 | 516 |
1151 EXPECT_EQ(tile_count, new_content_tiles.size()); | 517 EXPECT_EQ(tile_count, new_content_tiles.size()); |
1152 EXPECT_EQ(all_tiles, new_content_tiles); | 518 EXPECT_EQ(all_tiles, new_content_tiles); |
1153 } | 519 } |
1154 } // namespace | 520 } // namespace |
1155 } // namespace cc | 521 } // namespace cc |
OLD | NEW |