| 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_output_surface.h" | 7 #include "cc/test/fake_output_surface.h" |
| 8 #include "cc/test/fake_output_surface_client.h" | 8 #include "cc/test/fake_output_surface_client.h" |
| 9 #include "cc/test/fake_picture_pile_impl.h" | 9 #include "cc/test/fake_picture_pile_impl.h" |
| 10 #include "cc/test/fake_tile_manager.h" | 10 #include "cc/test/fake_tile_manager.h" |
| 11 #include "cc/test/test_tile_priorities.h" | 11 #include "cc/test/test_tile_priorities.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 class TileManagerTest : public testing::TestWithParam<bool>, | 17 class TileManagerTest : public testing::TestWithParam<bool>, |
| 18 public TileManagerClient { | 18 public TileManagerClient { |
| 19 public: | 19 public: |
| 20 typedef std::vector<scoped_refptr<Tile> > TileVector; | 20 typedef std::vector<scoped_refptr<Tile> > TileVector; |
| 21 | 21 |
| 22 TileManagerTest() | 22 TileManagerTest() |
| 23 : memory_limit_policy_(ALLOW_ANYTHING), | 23 : memory_limit_policy_(ALLOW_ANYTHING), |
| 24 max_memory_tiles_(0), | 24 max_tiles_(0), |
| 25 ready_to_activate_(false) {} | 25 ready_to_activate_(false) {} |
| 26 | 26 |
| 27 void Initialize(int max_tiles, | 27 void Initialize(int max_tiles, |
| 28 TileMemoryLimitPolicy memory_limit_policy, | 28 TileMemoryLimitPolicy memory_limit_policy, |
| 29 TreePriority tree_priority, | 29 TreePriority tree_priority, |
| 30 bool allow_on_demand_raster = true) { | 30 bool allow_on_demand_raster = true) { |
| 31 output_surface_ = FakeOutputSurface::Create3d(); | 31 output_surface_ = FakeOutputSurface::Create3d(); |
| 32 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 32 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 33 | 33 |
| 34 resource_provider_ = | 34 resource_provider_ = |
| 35 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1); | 35 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1); |
| 36 tile_manager_ = make_scoped_ptr(new FakeTileManager( | 36 tile_manager_ = make_scoped_ptr(new FakeTileManager( |
| 37 this, resource_provider_.get(), allow_on_demand_raster)); | 37 this, resource_provider_.get(), allow_on_demand_raster)); |
| 38 | 38 |
| 39 memory_limit_policy_ = memory_limit_policy; | 39 memory_limit_policy_ = memory_limit_policy; |
| 40 max_memory_tiles_ = max_tiles; | 40 max_tiles_ = max_tiles; |
| 41 GlobalStateThatImpactsTilePriority state; | 41 picture_pile_ = FakePicturePileImpl::CreatePile(); |
| 42 gfx::Size tile_size = settings_.default_tile_size; | |
| 43 | 42 |
| 44 // The parametrization specifies whether the max tile limit should | 43 SetTreePriority(tree_priority); |
| 45 // be applied to RAM or to tile limit. | |
| 46 if (GetParam()) { | |
| 47 state.memory_limit_in_bytes = | |
| 48 max_tiles * 4 * tile_size.width() * tile_size.height(); | |
| 49 state.num_resources_limit = 100; | |
| 50 } else { | |
| 51 state.memory_limit_in_bytes = 100 * 1000 * 1000; | |
| 52 state.num_resources_limit = max_tiles; | |
| 53 } | |
| 54 state.unused_memory_limit_in_bytes = state.memory_limit_in_bytes; | |
| 55 state.memory_limit_policy = memory_limit_policy; | |
| 56 state.tree_priority = tree_priority; | |
| 57 | |
| 58 global_state_ = state; | |
| 59 tile_manager_->SetGlobalStateForTesting(state); | |
| 60 picture_pile_ = FakePicturePileImpl::CreatePile(); | |
| 61 } | 44 } |
| 62 | 45 |
| 63 void SetTreePriority(TreePriority tree_priority) { | 46 void SetTreePriority(TreePriority tree_priority) { |
| 64 GlobalStateThatImpactsTilePriority state; | 47 GlobalStateThatImpactsTilePriority state; |
| 65 gfx::Size tile_size = settings_.default_tile_size; | 48 gfx::Size tile_size = settings_.default_tile_size; |
| 66 state.memory_limit_in_bytes = | 49 |
| 67 max_memory_tiles_ * 4 * tile_size.width() * tile_size.height(); | 50 if (UsingMemoryLimit()) { |
| 68 state.unused_memory_limit_in_bytes = state.memory_limit_in_bytes; | 51 state.soft_memory_limit_in_bytes = |
| 52 max_tiles_ * 4 * tile_size.width() * tile_size.height(); |
| 53 state.num_resources_limit = 100; |
| 54 } else { |
| 55 state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; |
| 56 state.num_resources_limit = max_tiles_; |
| 57 } |
| 58 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; |
| 59 state.unused_memory_limit_in_bytes = state.soft_memory_limit_in_bytes; |
| 69 state.memory_limit_policy = memory_limit_policy_; | 60 state.memory_limit_policy = memory_limit_policy_; |
| 70 state.num_resources_limit = 100; | |
| 71 state.tree_priority = tree_priority; | 61 state.tree_priority = tree_priority; |
| 62 |
| 72 global_state_ = state; | 63 global_state_ = state; |
| 64 tile_manager_->SetGlobalStateForTesting(state); |
| 73 } | 65 } |
| 74 | 66 |
| 75 virtual void TearDown() OVERRIDE { | 67 virtual void TearDown() OVERRIDE { |
| 76 tile_manager_.reset(NULL); | 68 tile_manager_.reset(NULL); |
| 77 picture_pile_ = NULL; | 69 picture_pile_ = NULL; |
| 78 | 70 |
| 79 testing::Test::TearDown(); | 71 testing::Test::TearDown(); |
| 80 } | 72 } |
| 81 | 73 |
| 82 // TileManagerClient implementation. | 74 // TileManagerClient implementation. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | 119 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); |
| 128 ++it) { | 120 ++it) { |
| 129 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE) | 121 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE) |
| 130 ++has_lcd_count; | 122 ++has_lcd_count; |
| 131 } | 123 } |
| 132 return has_lcd_count; | 124 return has_lcd_count; |
| 133 } | 125 } |
| 134 | 126 |
| 135 bool ready_to_activate() const { return ready_to_activate_; } | 127 bool ready_to_activate() const { return ready_to_activate_; } |
| 136 | 128 |
| 129 // The parametrization specifies whether the max tile limit should |
| 130 // be applied to memory or resources. |
| 131 bool UsingResourceLimit() { return !GetParam(); } |
| 132 bool UsingMemoryLimit() { return GetParam(); } |
| 133 |
| 137 protected: | 134 protected: |
| 138 GlobalStateThatImpactsTilePriority global_state_; | 135 GlobalStateThatImpactsTilePriority global_state_; |
| 139 | 136 |
| 140 private: | 137 private: |
| 141 LayerTreeSettings settings_; | 138 LayerTreeSettings settings_; |
| 142 scoped_ptr<FakeTileManager> tile_manager_; | 139 scoped_ptr<FakeTileManager> tile_manager_; |
| 143 scoped_refptr<FakePicturePileImpl> picture_pile_; | 140 scoped_refptr<FakePicturePileImpl> picture_pile_; |
| 144 FakeOutputSurfaceClient output_surface_client_; | 141 FakeOutputSurfaceClient output_surface_client_; |
| 145 scoped_ptr<FakeOutputSurface> output_surface_; | 142 scoped_ptr<FakeOutputSurface> output_surface_; |
| 146 scoped_ptr<ResourceProvider> resource_provider_; | 143 scoped_ptr<ResourceProvider> resource_provider_; |
| 147 TileMemoryLimitPolicy memory_limit_policy_; | 144 TileMemoryLimitPolicy memory_limit_policy_; |
| 148 int max_memory_tiles_; | 145 int max_tiles_; |
| 149 bool ready_to_activate_; | 146 bool ready_to_activate_; |
| 150 }; | 147 }; |
| 151 | 148 |
| 152 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { | 149 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { |
| 153 // A few tiles of each type of priority, with enough memory for all tiles. | 150 // A few tiles of each type of priority, with enough memory for all tiles. |
| 154 | 151 |
| 155 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 152 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 156 TileVector active_now = | 153 TileVector active_now = |
| 157 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | 154 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |
| 158 TileVector pending_now = | 155 TileVector pending_now = |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 EXPECT_EQ(0, AssignedMemoryCount(active_now)); | 226 EXPECT_EQ(0, AssignedMemoryCount(active_now)); |
| 230 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); | 227 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); |
| 231 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | 228 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); |
| 232 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | 229 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); |
| 233 } | 230 } |
| 234 | 231 |
| 235 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { | 232 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { |
| 236 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | 233 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are |
| 237 // required for activation, but only enough memory for 8 tiles. The result | 234 // required for activation, but only enough memory for 8 tiles. The result |
| 238 // is all pending tree tiles get memory, and 3 of the active tree tiles | 235 // is all pending tree tiles get memory, and 3 of the active tree tiles |
| 239 // get memory. | 236 // get memory. None of these tiles is needed to avoid calimity (flickering or |
| 237 // raster-on-demand) so the soft memory limit is used. |
| 240 | 238 |
| 241 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 239 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 242 TileVector active_tree_tiles = | 240 TileVector active_tree_tiles = |
| 243 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | 241 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); |
| 244 TileVector pending_tree_tiles = | 242 TileVector pending_tree_tiles = |
| 245 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | 243 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); |
| 246 | |
| 247 tile_manager()->AssignMemoryToTiles(global_state_); | 244 tile_manager()->AssignMemoryToTiles(global_state_); |
| 248 | 245 |
| 249 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | 246 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); |
| 250 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | 247 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); |
| 251 | 248 |
| 252 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | 249 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |
| 253 tile_manager()->AssignMemoryToTiles(global_state_); | 250 tile_manager()->AssignMemoryToTiles(global_state_); |
| 254 | 251 |
| 255 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); | 252 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); |
| 256 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); | 253 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); |
| 257 } | 254 } |
| 258 | 255 |
| 259 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { | 256 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { |
| 260 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | 257 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, |
| 261 // but only enough memory for 8 tiles. The result is all active tree tiles | 258 // but only enough memory for 8 tiles. The result is all active tree tiles |
| 262 // get memory, and 3 of the pending tree tiles get memory. | 259 // get memory, and 3 of the pending tree tiles get memory. |
| 260 // The pending tiles are not needed to avoid calimity (flickering or |
| 261 // raster-on-demand) and the active tiles fit, so the soft limit is used. |
| 263 | 262 |
| 264 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 263 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 265 TileVector active_tree_tiles = | 264 TileVector active_tree_tiles = |
| 266 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | 265 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); |
| 267 TileVector pending_tree_tiles = | 266 TileVector pending_tree_tiles = |
| 268 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | 267 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); |
| 269 | 268 |
| 270 tile_manager()->AssignMemoryToTiles(global_state_); | 269 tile_manager()->AssignMemoryToTiles(global_state_); |
| 271 | 270 |
| 272 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | 271 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); |
| 273 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | 272 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); |
| 274 } | 273 } |
| 275 | 274 |
| 276 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { | 275 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { |
| 277 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | 276 // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are |
| 278 // required for activation, but only enough memory for 4 tiles. The result | 277 // required for activation, but only enough tiles for 4 tiles. The result |
| 279 // is 4 pending tree tiles get memory, and none of the active tree tiles | 278 // is 4 pending tree tiles get memory, and none of the active tree tiles |
| 280 // get memory. | 279 // get memory. |
| 281 | 280 |
| 282 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 281 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 283 TileVector active_tree_tiles = | 282 TileVector active_tree_tiles = |
| 284 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | 283 CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); |
| 285 TileVector pending_tree_tiles = | 284 TileVector pending_tree_tiles = |
| 286 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | 285 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); |
| 287 | 286 |
| 288 tile_manager()->AssignMemoryToTiles(global_state_); | 287 tile_manager()->AssignMemoryToTiles(global_state_); |
| 289 | 288 |
| 290 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | 289 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); |
| 291 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | 290 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |
| 292 | 291 |
| 293 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | 292 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |
| 294 tile_manager()->AssignMemoryToTiles(global_state_); | 293 tile_manager()->AssignMemoryToTiles(global_state_); |
| 295 | 294 |
| 296 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | 295 if (UsingResourceLimit()) { |
| 297 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | 296 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |
| 297 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); |
| 298 } else { |
| 299 // Pending tiles are now required to avoid calimity (flickering or |
| 300 // raster-on-demand). Hard-limit is used and double the tiles fit. |
| 301 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |
| 302 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); |
| 303 } |
| 298 } | 304 } |
| 299 | 305 |
| 300 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | 306 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { |
| 301 // 5 tiles on active tree soon bin, 5 tiles on pending tree that are | 307 // 10 tiles on active tree soon bin, 10 tiles on pending tree that are |
| 302 // required for activation, but only enough memory for 4 tiles. The result | 308 // required for activation, but only enough tiles for 4 tiles. The result |
| 303 // is 4 pending tree tiles get memory, and none of the active tree tiles | 309 // is 4 pending tree tiles get memory, and none of the active tree tiles |
| 304 // get memory. | 310 // get memory. |
| 305 | 311 |
| 306 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 312 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 307 TileVector active_tree_tiles = | 313 TileVector active_tree_tiles = |
| 308 CreateTiles(5, TilePriorityForSoonBin(), TilePriority()); | 314 CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); |
| 309 TileVector pending_tree_tiles = | 315 TileVector pending_tree_tiles = |
| 310 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | 316 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); |
| 311 | 317 |
| 312 tile_manager()->AssignMemoryToTiles(global_state_); | 318 tile_manager()->AssignMemoryToTiles(global_state_); |
| 313 | 319 |
| 314 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | 320 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); |
| 315 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | 321 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |
| 316 | 322 |
| 317 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | 323 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |
| 318 tile_manager()->AssignMemoryToTiles(global_state_); | 324 tile_manager()->AssignMemoryToTiles(global_state_); |
| 319 | 325 |
| 320 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | 326 if (UsingResourceLimit()) { |
| 321 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | 327 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |
| 328 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); |
| 329 } else { |
| 330 // Pending tiles are now required to avoid calimity (flickering or |
| 331 // raster-on-demand). Hard-limit is used and double the tiles fit. |
| 332 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |
| 333 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); |
| 334 } |
| 322 } | 335 } |
| 323 | 336 |
| 324 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { | 337 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { |
| 325 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | 338 // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, |
| 326 // but only enough memory for 4 tiles. The result is 5 active tree tiles | 339 // but only enough memory for 4 tiles. The result is 4 active tree tiles |
| 327 // get memory, and none of the pending tree tiles get memory. | 340 // get memory, and none of the pending tree tiles get memory. |
| 328 | 341 |
| 329 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 342 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 330 TileVector active_tree_tiles = | 343 TileVector active_tree_tiles = |
| 331 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | 344 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); |
| 332 TileVector pending_tree_tiles = | 345 TileVector pending_tree_tiles = |
| 333 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | 346 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); |
| 334 | 347 |
| 335 tile_manager()->AssignMemoryToTiles(global_state_); | 348 tile_manager()->AssignMemoryToTiles(global_state_); |
| 336 | 349 |
| 337 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | 350 if (UsingResourceLimit()) { |
| 351 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); |
| 352 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |
| 353 } else { |
| 354 // Active tiles are required to avoid calimity (flickering or |
| 355 // raster-on-demand). Hard-limit is used and double the tiles fit. |
| 356 EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); |
| 357 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |
| 358 } |
| 359 } |
| 360 |
| 361 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { |
| 362 // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, |
| 363 // but only enough memory for 8 tiles. Any tile missing would cause |
| 364 // a calamity (flickering or raster-on-demand). Depending on mode, |
| 365 // we should use varying amounts of the higher hard memory limit. |
| 366 if (UsingResourceLimit()) |
| 367 return; |
| 368 |
| 369 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 370 TileVector active_tree_tiles = |
| 371 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); |
| 372 TileVector pending_tree_tiles = |
| 373 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); |
| 374 |
| 375 // Active tiles are required to avoid calimity. The hard-limit is used and all |
| 376 // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 |
| 377 // tiles total are used. |
| 378 tile_manager()->AssignMemoryToTiles(global_state_); |
| 379 EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); |
| 338 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | 380 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |
| 381 |
| 382 // Even the hard-limit won't save us now. All tiles are required to avoid |
| 383 // a clamity but we only have 16. The tiles will be distribted randomly |
| 384 // given they are identical, in practice depending on their screen location. |
| 385 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |
| 386 tile_manager()->AssignMemoryToTiles(global_state_); |
| 387 EXPECT_EQ(16, |
| 388 AssignedMemoryCount(active_tree_tiles) + |
| 389 AssignedMemoryCount(pending_tree_tiles)); |
| 390 |
| 391 // The pending tree is now more important. Active tiles will take higher |
| 392 // priority if they are ready-to-draw in practice. Importantly though, |
| 393 // pending tiles also utilize the hard-limit. |
| 394 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); |
| 395 tile_manager()->AssignMemoryToTiles(global_state_); |
| 396 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |
| 397 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); |
| 339 } | 398 } |
| 340 | 399 |
| 341 TEST_P(TileManagerTest, RasterAsLCD) { | 400 TEST_P(TileManagerTest, RasterAsLCD) { |
| 342 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 401 Initialize(20, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 343 TileVector active_tree_tiles = | 402 TileVector active_tree_tiles = |
| 344 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | 403 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); |
| 345 TileVector pending_tree_tiles = | 404 TileVector pending_tree_tiles = |
| 346 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | 405 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); |
| 347 | 406 |
| 348 tile_manager()->AssignMemoryToTiles(global_state_); | 407 tile_manager()->AssignMemoryToTiles(global_state_); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 EXPECT_TRUE((*it)->IsReadyToDraw()); | 535 EXPECT_TRUE((*it)->IsReadyToDraw()); |
| 477 } | 536 } |
| 478 | 537 |
| 479 tile_manager()->AssignMemoryToTiles(global_state_); | 538 tile_manager()->AssignMemoryToTiles(global_state_); |
| 480 | 539 |
| 481 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | 540 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); |
| 482 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | 541 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); |
| 483 } | 542 } |
| 484 | 543 |
| 485 TEST_P(TileManagerTest, RespectMemoryLimit) { | 544 TEST_P(TileManagerTest, RespectMemoryLimit) { |
| 545 if (UsingResourceLimit()) |
| 546 return; |
| 547 |
| 486 Initialize(5, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 548 Initialize(5, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 549 |
| 550 // We use double the tiles since the hard-limit is double. |
| 487 TileVector large_tiles = | 551 TileVector large_tiles = |
| 488 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | 552 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); |
| 489 | 553 |
| 490 size_t memory_required_bytes; | 554 size_t memory_required_bytes; |
| 491 size_t memory_nice_to_have_bytes; | 555 size_t memory_nice_to_have_bytes; |
| 492 size_t memory_allocated_bytes; | 556 size_t memory_allocated_bytes; |
| 493 size_t memory_used_bytes; | 557 size_t memory_used_bytes; |
| 494 | 558 |
| 495 tile_manager()->AssignMemoryToTiles(global_state_); | 559 tile_manager()->AssignMemoryToTiles(global_state_); |
| 496 tile_manager()->GetMemoryStats(&memory_required_bytes, | 560 tile_manager()->GetMemoryStats(&memory_required_bytes, |
| 497 &memory_nice_to_have_bytes, | 561 &memory_nice_to_have_bytes, |
| 498 &memory_allocated_bytes, | 562 &memory_allocated_bytes, |
| 499 &memory_used_bytes); | 563 &memory_used_bytes); |
| 500 // Allocated bytes should never be more than the memory limit. | 564 // Allocated bytes should never be more than the memory limit. |
| 501 EXPECT_LE(memory_allocated_bytes, global_state_.memory_limit_in_bytes); | 565 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); |
| 502 | 566 |
| 503 // Finish raster of large tiles. | 567 // Finish raster of large tiles. |
| 504 tile_manager()->UpdateVisibleTiles(); | 568 tile_manager()->UpdateVisibleTiles(); |
| 505 | 569 |
| 506 // Remove all large tiles. This will leave the memory currently | 570 // Remove all large tiles. This will leave the memory currently |
| 507 // used by these tiles as unused when AssignMemoryToTiles() is called. | 571 // used by these tiles as unused when AssignMemoryToTiles() is called. |
| 508 large_tiles.clear(); | 572 large_tiles.clear(); |
| 509 | 573 |
| 510 // Create a new set of tiles using a different size. These tiles | 574 // Create a new set of tiles using a different size. These tiles |
| 511 // can use the memory currently assigned to the lerge tiles but | 575 // can use the memory currently assigned to the large tiles but |
| 512 // they can't use the same resources as the size doesn't match. | 576 // they can't use the same resources as the size doesn't match. |
| 513 TileVector small_tiles = CreateTilesWithSize( | 577 TileVector small_tiles = CreateTilesWithSize( |
| 514 5, TilePriorityForNowBin(), TilePriority(), gfx::Size(128, 128)); | 578 10, TilePriorityForNowBin(), TilePriority(), gfx::Size(128, 128)); |
| 515 | 579 |
| 516 tile_manager()->AssignMemoryToTiles(global_state_); | 580 tile_manager()->AssignMemoryToTiles(global_state_); |
| 517 tile_manager()->GetMemoryStats(&memory_required_bytes, | 581 tile_manager()->GetMemoryStats(&memory_required_bytes, |
| 518 &memory_nice_to_have_bytes, | 582 &memory_nice_to_have_bytes, |
| 519 &memory_allocated_bytes, | 583 &memory_allocated_bytes, |
| 520 &memory_used_bytes); | 584 &memory_used_bytes); |
| 521 // Allocated bytes should never be more than the memory limit. | 585 // Allocated bytes should never be more than the memory limit. |
| 522 EXPECT_LE(memory_allocated_bytes, global_state_.memory_limit_in_bytes); | 586 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); |
| 523 } | 587 } |
| 524 | 588 |
| 525 TEST_P(TileManagerTest, AllowRasterizeOnDemand) { | 589 TEST_P(TileManagerTest, AllowRasterizeOnDemand) { |
| 526 // Not enough memory to initialize tiles required for activation. | 590 // Not enough memory to initialize tiles required for activation. |
| 527 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES); | 591 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES); |
| 528 TileVector tiles = | 592 TileVector tiles = |
| 529 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | 593 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); |
| 530 | 594 |
| 531 tile_manager()->AssignMemoryToTiles(global_state_); | 595 tile_manager()->AssignMemoryToTiles(global_state_); |
| 532 | 596 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 557 } | 621 } |
| 558 | 622 |
| 559 // If true, the max tile limit should be applied as bytes; if false, | 623 // If true, the max tile limit should be applied as bytes; if false, |
| 560 // as num_resources_limit. | 624 // as num_resources_limit. |
| 561 INSTANTIATE_TEST_CASE_P(TileManagerTests, | 625 INSTANTIATE_TEST_CASE_P(TileManagerTests, |
| 562 TileManagerTest, | 626 TileManagerTest, |
| 563 ::testing::Values(true, false)); | 627 ::testing::Values(true, false)); |
| 564 | 628 |
| 565 } // namespace | 629 } // namespace |
| 566 } // namespace cc | 630 } // namespace cc |
| OLD | NEW |