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, EnoughMemoryAllowAbsoluteMinimum) { | |
206 // A few tiles of each type of priority, with enough memory for all tiles, | |
207 // with the exception of never and soon bins. | |
208 | |
209 Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY); | |
210 TileVector active_now = | |
211 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
212 TileVector pending_now = | |
213 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
214 TileVector active_pending_soon = | |
215 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
216 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
217 | |
218 tile_manager()->AssignMemoryToTiles(global_state_); | |
219 | |
220 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
221 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
222 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
223 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
224 } | |
225 | |
226 TEST_P(TileManagerTest, EnoughMemoryAllowNothing) { | |
227 // A few tiles of each type of priority, with enough memory for all tiles, | |
228 // but allow nothing should not assign any memory. | |
229 | |
230 Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY); | |
231 TileVector active_now = | |
232 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
233 TileVector pending_now = | |
234 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
235 TileVector active_pending_soon = | |
236 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
237 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
238 | |
239 tile_manager()->AssignMemoryToTiles(global_state_); | |
240 | |
241 EXPECT_EQ(0, AssignedMemoryCount(active_now)); | |
242 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); | |
243 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
244 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
245 } | |
246 | |
247 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { | |
248 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | |
249 // required for activation, but only enough memory for 8 tiles. The result | |
250 // is all pending tree tiles get memory, and 3 of the active tree tiles | |
251 // get memory. None of these tiles is needed to avoid calimity (flickering or | |
252 // raster-on-demand) so the soft memory limit is used. | |
253 | |
254 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
255 TileVector active_tree_tiles = | |
256 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | |
257 TileVector pending_tree_tiles = | |
258 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | |
259 tile_manager()->AssignMemoryToTiles(global_state_); | |
260 | |
261 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
262 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
263 | |
264 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
265 tile_manager()->AssignMemoryToTiles(global_state_); | |
266 | |
267 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); | |
268 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); | |
269 } | |
270 | |
271 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { | |
272 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | |
273 // but only enough memory for 8 tiles. The result is all active tree tiles | |
274 // get memory, and 3 of the pending tree tiles get memory. | |
275 // The pending tiles are not needed to avoid calimity (flickering or | |
276 // raster-on-demand) and the active tiles fit, so the soft limit is used. | |
277 | |
278 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
279 TileVector active_tree_tiles = | |
280 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
281 TileVector pending_tree_tiles = | |
282 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
283 | |
284 tile_manager()->AssignMemoryToTiles(global_state_); | |
285 | |
286 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
287 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
288 } | |
289 | |
290 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { | |
291 // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are | |
292 // required for activation, but only enough tiles for 4 tiles. The result | |
293 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
294 // get memory. | |
295 | |
296 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
297 TileVector active_tree_tiles = | |
298 CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); | |
299 TileVector pending_tree_tiles = | |
300 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
301 | |
302 tile_manager()->AssignMemoryToTiles(global_state_); | |
303 | |
304 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
305 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
306 | |
307 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
308 tile_manager()->AssignMemoryToTiles(global_state_); | |
309 | |
310 if (UsingResourceLimit()) { | |
311 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
312 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
313 } else { | |
314 // Pending tiles are now required to avoid calimity (flickering or | |
315 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
316 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
317 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
318 } | |
319 } | |
320 | |
321 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | |
322 // 10 tiles on active tree soon bin, 10 tiles on pending tree that are | |
323 // required for activation, but only enough tiles for 4 tiles. The result | |
324 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
325 // get memory. | |
326 | |
327 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
328 TileVector active_tree_tiles = | |
329 CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); | |
330 TileVector pending_tree_tiles = | |
331 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
332 | |
333 tile_manager()->AssignMemoryToTiles(global_state_); | |
334 | |
335 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
336 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
337 | |
338 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
339 tile_manager()->AssignMemoryToTiles(global_state_); | |
340 | |
341 if (UsingResourceLimit()) { | |
342 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
343 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
344 } else { | |
345 // Pending tiles are now required to avoid calimity (flickering or | |
346 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
347 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
348 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
349 } | |
350 } | |
351 | |
352 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { | |
353 // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, | |
354 // but only enough memory for 4 tiles. The result is 4 active tree tiles | |
355 // get memory, and none of the pending tree tiles get memory. | |
356 | |
357 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
358 TileVector active_tree_tiles = | |
359 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
360 TileVector pending_tree_tiles = | |
361 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
362 | |
363 tile_manager()->AssignMemoryToTiles(global_state_); | |
364 | |
365 if (UsingResourceLimit()) { | |
366 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
367 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
368 } else { | |
369 // Active tiles are required to avoid calimity (flickering or | |
370 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
371 EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); | |
372 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
373 } | |
374 } | |
375 | |
376 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { | |
377 // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, | |
378 // but only enough memory for 8 tiles. Any tile missing would cause | |
379 // a calamity (flickering or raster-on-demand). Depending on mode, | |
380 // we should use varying amounts of the higher hard memory limit. | |
381 if (UsingResourceLimit()) | |
382 return; | |
383 | |
384 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
385 TileVector active_tree_tiles = | |
386 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
387 TileVector pending_tree_tiles = | |
388 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
389 | |
390 // Active tiles are required to avoid calimity. The hard-limit is used and all | |
391 // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 | |
392 // tiles total are used. | |
393 tile_manager()->AssignMemoryToTiles(global_state_); | |
394 EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); | |
395 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
396 | |
397 // Even the hard-limit won't save us now. All tiles are required to avoid | |
398 // a clamity but we only have 16. The tiles will be distribted randomly | |
399 // given they are identical, in practice depending on their screen location. | |
400 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
401 tile_manager()->AssignMemoryToTiles(global_state_); | |
402 EXPECT_EQ(16, | |
403 AssignedMemoryCount(active_tree_tiles) + | |
404 AssignedMemoryCount(pending_tree_tiles)); | |
405 | |
406 // The pending tree is now more important. Active tiles will take higher | |
407 // priority if they are ready-to-draw in practice. Importantly though, | |
408 // pending tiles also utilize the hard-limit. | |
409 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); | |
410 tile_manager()->AssignMemoryToTiles(global_state_); | |
411 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
412 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | |
413 } | |
414 | |
415 TEST_P(TileManagerTest, RasterAsLCD) { | |
416 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
417 TileVector active_tree_tiles = | |
418 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
419 TileVector pending_tree_tiles = | |
420 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
421 | |
422 tile_manager()->AssignMemoryToTiles(global_state_); | |
423 | |
424 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
425 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
426 } | |
427 | |
428 TEST_P(TileManagerTest, RasterAsNoLCD) { | |
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 for (TileVector::iterator it = active_tree_tiles.begin(); | |
436 it != active_tree_tiles.end(); | |
437 ++it) { | |
438 (*it)->set_can_use_lcd_text(false); | |
439 } | |
440 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
441 it != pending_tree_tiles.end(); | |
442 ++it) { | |
443 (*it)->set_can_use_lcd_text(false); | |
444 } | |
445 | |
446 tile_manager()->AssignMemoryToTiles(global_state_); | |
447 | |
448 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
449 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
450 } | |
451 | |
452 TEST_P(TileManagerTest, ReRasterAsNoLCD) { | |
453 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
454 TileVector active_tree_tiles = | |
455 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
456 TileVector pending_tree_tiles = | |
457 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
458 | |
459 tile_manager()->AssignMemoryToTiles(global_state_); | |
460 | |
461 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
462 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
463 | |
464 for (TileVector::iterator it = active_tree_tiles.begin(); | |
465 it != active_tree_tiles.end(); | |
466 ++it) { | |
467 (*it)->set_can_use_lcd_text(false); | |
468 } | |
469 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
470 it != pending_tree_tiles.end(); | |
471 ++it) { | |
472 (*it)->set_can_use_lcd_text(false); | |
473 } | |
474 | |
475 tile_manager()->AssignMemoryToTiles(global_state_); | |
476 | |
477 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
478 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
479 } | |
480 | |
481 TEST_P(TileManagerTest, NoTextDontReRasterAsNoLCD) { | |
482 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
483 TileVector active_tree_tiles = | |
484 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
485 TileVector pending_tree_tiles = | |
486 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
487 | |
488 tile_manager()->AssignMemoryToTiles(global_state_); | |
489 | |
490 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
491 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
492 | |
493 for (TileVector::iterator it = active_tree_tiles.begin(); | |
494 it != active_tree_tiles.end(); | |
495 ++it) { | |
496 ManagedTileState::TileVersion& tile_version = | |
497 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
498 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
499 (*it)->set_can_use_lcd_text(false); | |
500 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
501 } | |
502 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
503 it != pending_tree_tiles.end(); | |
504 ++it) { | |
505 ManagedTileState::TileVersion& tile_version = | |
506 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
507 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
508 (*it)->set_can_use_lcd_text(false); | |
509 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
510 } | |
511 | |
512 tile_manager()->AssignMemoryToTiles(global_state_); | |
513 | |
514 EXPECT_EQ(5, TilesWithLCDCount(active_tree_tiles)); | |
515 EXPECT_EQ(5, TilesWithLCDCount(pending_tree_tiles)); | |
516 } | |
517 | |
518 TEST_P(TileManagerTest, TextReRasterAsNoLCD) { | |
519 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
520 TileVector active_tree_tiles = | |
521 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
522 TileVector pending_tree_tiles = | |
523 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
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 for (TileVector::iterator it = active_tree_tiles.begin(); | |
531 it != active_tree_tiles.end(); | |
532 ++it) { | |
533 ManagedTileState::TileVersion& tile_version = | |
534 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
535 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
536 tile_version.SetHasTextForTesting(true); | |
537 (*it)->set_can_use_lcd_text(false); | |
538 | |
539 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
540 } | |
541 for (TileVector::iterator it = pending_tree_tiles.begin(); | |
542 it != pending_tree_tiles.end(); | |
543 ++it) { | |
544 ManagedTileState::TileVersion& tile_version = | |
545 (*it)->GetTileVersionForTesting(HIGH_QUALITY_RASTER_MODE); | |
546 tile_version.SetSolidColorForTesting(SkColorSetARGB(0, 0, 0, 0)); | |
547 tile_version.SetHasTextForTesting(true); | |
548 (*it)->set_can_use_lcd_text(false); | |
549 | |
550 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
551 } | |
552 | |
553 tile_manager()->AssignMemoryToTiles(global_state_); | |
554 | |
555 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | |
556 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | |
557 } | |
558 | |
559 TEST_P(TileManagerTest, RespectMemoryLimit) { | |
560 if (UsingResourceLimit()) | |
561 return; | |
562 | |
563 Initialize(5, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
564 | |
565 // We use double the tiles since the hard-limit is double. | |
566 TileVector large_tiles = | |
567 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
568 | |
569 size_t memory_required_bytes; | |
570 size_t memory_nice_to_have_bytes; | |
571 size_t memory_allocated_bytes; | |
572 size_t memory_used_bytes; | |
573 | |
574 tile_manager()->AssignMemoryToTiles(global_state_); | |
575 tile_manager()->GetMemoryStats(&memory_required_bytes, | |
576 &memory_nice_to_have_bytes, | |
577 &memory_allocated_bytes, | |
578 &memory_used_bytes); | |
579 // Allocated bytes should never be more than the memory limit. | |
580 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); | |
581 | |
582 // Finish raster of large tiles. | |
583 tile_manager()->UpdateVisibleTiles(); | |
584 | |
585 // Remove all large tiles. This will leave the memory currently | |
586 // used by these tiles as unused when AssignMemoryToTiles() is called. | |
587 large_tiles.clear(); | |
588 | |
589 // Create a new set of tiles using a different size. These tiles | |
590 // can use the memory currently assigned to the large tiles but | |
591 // they can't use the same resources as the size doesn't match. | |
592 TileVector small_tiles = CreateTilesWithSize( | |
593 10, TilePriorityForNowBin(), TilePriority(), gfx::Size(128, 128)); | |
594 | |
595 tile_manager()->AssignMemoryToTiles(global_state_); | |
596 tile_manager()->GetMemoryStats(&memory_required_bytes, | |
597 &memory_nice_to_have_bytes, | |
598 &memory_allocated_bytes, | |
599 &memory_used_bytes); | |
600 // Allocated bytes should never be more than the memory limit. | |
601 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); | |
602 } | |
603 | |
604 TEST_P(TileManagerTest, AllowRasterizeOnDemand) { | |
605 // Not enough memory to initialize tiles required for activation. | |
606 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES); | |
607 TileVector tiles = | |
608 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
609 | |
610 tile_manager()->AssignMemoryToTiles(global_state_); | |
611 | |
612 // This should make required tiles ready to draw by marking them as | |
613 // required tiles for on-demand raster. | |
614 tile_manager()->DidFinishRunningTasksForTesting(); | |
615 | |
616 EXPECT_TRUE(ready_to_activate()); | |
617 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
618 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
619 } | |
620 | |
621 TEST_P(TileManagerTest, PreventRasterizeOnDemand) { | |
622 // Not enough memory to initialize tiles required for activation. | |
623 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES, false); | |
624 TileVector tiles = | |
625 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
626 | |
627 tile_manager()->AssignMemoryToTiles(global_state_); | |
628 | |
629 // This should make required tiles ready to draw by marking them as | |
630 // required tiles for on-demand raster. | |
631 tile_manager()->DidFinishRunningTasksForTesting(); | |
632 | |
633 EXPECT_TRUE(ready_to_activate()); | |
634 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
635 EXPECT_FALSE((*it)->IsReadyToDraw()); | |
636 } | |
637 | |
638 // If true, the max tile limit should be applied as bytes; if false, | |
639 // as num_resources_limit. | |
640 INSTANTIATE_TEST_CASE_P(TileManagerTests, | |
641 TileManagerTest, | |
642 ::testing::Values(true, false)); | |
643 | |
644 class TileManagerTileIteratorTest : public testing::Test, | 23 class TileManagerTileIteratorTest : public testing::Test, |
645 public TileManagerClient { | 24 public TileManagerClient { |
646 public: | 25 public: |
647 TileManagerTileIteratorTest() | 26 TileManagerTileIteratorTest() |
648 : memory_limit_policy_(ALLOW_ANYTHING), | 27 : memory_limit_policy_(ALLOW_ANYTHING), |
649 max_tiles_(10000), | 28 max_tiles_(10000), |
650 ready_to_activate_(false), | 29 ready_to_activate_(false), |
651 id_(7), | 30 id_(7), |
652 proxy_(base::MessageLoopProxy::current()), | 31 proxy_(base::MessageLoopProxy::current()), |
653 host_impl_(ImplSidePaintingSettings(), | 32 host_impl_(ImplSidePaintingSettings(), |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 512 |
1134 last_tile = tile; | 513 last_tile = tile; |
1135 new_content_tiles.insert(tile); | 514 new_content_tiles.insert(tile); |
1136 } | 515 } |
1137 | 516 |
1138 EXPECT_EQ(tile_count, new_content_tiles.size()); | 517 EXPECT_EQ(tile_count, new_content_tiles.size()); |
1139 EXPECT_EQ(all_tiles, new_content_tiles); | 518 EXPECT_EQ(all_tiles, new_content_tiles); |
1140 } | 519 } |
1141 } // namespace | 520 } // namespace |
1142 } // namespace cc | 521 } // namespace cc |
OLD | NEW |