| 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 1.0, | |
| 113 0, | |
| 114 0, | |
| 115 0); | |
| 116 tile->SetPriority(ACTIVE_TREE, active_priority); | |
| 117 tile->SetPriority(PENDING_TREE, pending_priority); | |
| 118 tiles.push_back(tile); | |
| 119 } | |
| 120 return tiles; | |
| 121 } | |
| 122 | |
| 123 TileVector CreateTiles(int count, | |
| 124 TilePriority active_priority, | |
| 125 TilePriority pending_priority) { | |
| 126 return CreateTilesWithSize( | |
| 127 count, active_priority, pending_priority, settings_.default_tile_size); | |
| 128 } | |
| 129 | |
| 130 void ReleaseTiles(TileVector* tiles) { | |
| 131 for (TileVector::iterator it = tiles->begin(); it != tiles->end(); it++) { | |
| 132 Tile* tile = it->get(); | |
| 133 tile->SetPriority(ACTIVE_TREE, TilePriority()); | |
| 134 tile->SetPriority(PENDING_TREE, TilePriority()); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 FakeTileManager* tile_manager() { return tile_manager_.get(); } | |
| 139 | |
| 140 int AssignedMemoryCount(const TileVector& tiles) { | |
| 141 int has_memory_count = 0; | |
| 142 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | |
| 143 ++it) { | |
| 144 if (tile_manager_->HasBeenAssignedMemory(it->get())) | |
| 145 ++has_memory_count; | |
| 146 } | |
| 147 return has_memory_count; | |
| 148 } | |
| 149 | |
| 150 bool ready_to_activate() const { return ready_to_activate_; } | |
| 151 | |
| 152 // The parametrization specifies whether the max tile limit should | |
| 153 // be applied to memory or resources. | |
| 154 bool UsingResourceLimit() { return !GetParam(); } | |
| 155 bool UsingMemoryLimit() { return GetParam(); } | |
| 156 | |
| 157 protected: | |
| 158 GlobalStateThatImpactsTilePriority global_state_; | |
| 159 | |
| 160 private: | |
| 161 LayerTreeSettings settings_; | |
| 162 scoped_ptr<FakeTileManager> tile_manager_; | |
| 163 scoped_refptr<FakePicturePileImpl> picture_pile_; | |
| 164 FakeOutputSurfaceClient output_surface_client_; | |
| 165 scoped_ptr<FakeOutputSurface> output_surface_; | |
| 166 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
| 167 scoped_ptr<ResourceProvider> resource_provider_; | |
| 168 scoped_ptr<ResourcePool> resource_pool_; | |
| 169 TileMemoryLimitPolicy memory_limit_policy_; | |
| 170 int max_tiles_; | |
| 171 bool ready_to_activate_; | |
| 172 std::vector<PictureLayerImpl*> picture_layers_; | |
| 173 }; | |
| 174 | |
| 175 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { | |
| 176 // A few tiles of each type of priority, with enough memory for all tiles. | |
| 177 | |
| 178 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 179 TileVector active_now = | |
| 180 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 181 TileVector pending_now = | |
| 182 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 183 TileVector active_pending_soon = | |
| 184 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 185 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 186 | |
| 187 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 188 | |
| 189 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
| 190 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
| 191 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
| 192 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 193 | |
| 194 ReleaseTiles(&active_now); | |
| 195 ReleaseTiles(&pending_now); | |
| 196 ReleaseTiles(&active_pending_soon); | |
| 197 ReleaseTiles(&never_bin); | |
| 198 } | |
| 199 | |
| 200 TEST_P(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { | |
| 201 // A few tiles of each type of priority, with enough memory for all tiles, | |
| 202 // with the exception of never bin. | |
| 203 | |
| 204 Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); | |
| 205 TileVector active_now = | |
| 206 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 207 TileVector pending_now = | |
| 208 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 209 TileVector active_pending_soon = | |
| 210 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 211 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 212 | |
| 213 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 214 | |
| 215 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
| 216 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
| 217 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
| 218 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 219 | |
| 220 ReleaseTiles(&active_now); | |
| 221 ReleaseTiles(&pending_now); | |
| 222 ReleaseTiles(&active_pending_soon); | |
| 223 ReleaseTiles(&never_bin); | |
| 224 } | |
| 225 | |
| 226 TEST_P(TileManagerTest, EnoughMemoryPendingLowResAllowAbsoluteMinimum) { | |
| 227 // A few low-res tiles required for activation, with enough memory for all | |
| 228 // tiles. | |
| 229 | |
| 230 Initialize(5, ALLOW_ABSOLUTE_MINIMUM, SAME_PRIORITY_FOR_BOTH_TREES); | |
| 231 TileVector pending_low_res = | |
| 232 CreateTiles(5, TilePriority(), TilePriorityLowRes()); | |
| 233 | |
| 234 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 235 | |
| 236 EXPECT_EQ(5, AssignedMemoryCount(pending_low_res)); | |
| 237 ReleaseTiles(&pending_low_res); | |
| 238 } | |
| 239 | |
| 240 TEST_P(TileManagerTest, EnoughMemoryAllowAbsoluteMinimum) { | |
| 241 // A few tiles of each type of priority, with enough memory for all tiles, | |
| 242 // with the exception of never and soon bins. | |
| 243 | |
| 244 Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY); | |
| 245 TileVector active_now = | |
| 246 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 247 TileVector pending_now = | |
| 248 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 249 TileVector active_pending_soon = | |
| 250 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 251 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 252 | |
| 253 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 254 | |
| 255 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
| 256 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
| 257 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
| 258 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 259 | |
| 260 ReleaseTiles(&active_now); | |
| 261 ReleaseTiles(&pending_now); | |
| 262 ReleaseTiles(&active_pending_soon); | |
| 263 ReleaseTiles(&never_bin); | |
| 264 } | |
| 265 | |
| 266 TEST_P(TileManagerTest, EnoughMemoryAllowNothing) { | |
| 267 // A few tiles of each type of priority, with enough memory for all tiles, | |
| 268 // but allow nothing should not assign any memory. | |
| 269 | |
| 270 Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 271 TileVector active_now = | |
| 272 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 273 TileVector pending_now = | |
| 274 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 275 TileVector active_pending_soon = | |
| 276 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 277 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 278 | |
| 279 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 280 | |
| 281 EXPECT_EQ(0, AssignedMemoryCount(active_now)); | |
| 282 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); | |
| 283 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
| 284 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 285 | |
| 286 ReleaseTiles(&active_now); | |
| 287 ReleaseTiles(&pending_now); | |
| 288 ReleaseTiles(&active_pending_soon); | |
| 289 ReleaseTiles(&never_bin); | |
| 290 } | |
| 291 | |
| 292 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { | |
| 293 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | |
| 294 // required for activation, but only enough memory for 8 tiles. The result | |
| 295 // is all pending tree tiles get memory, and 3 of the active tree tiles | |
| 296 // get memory. None of these tiles is needed to avoid calimity (flickering or | |
| 297 // raster-on-demand) so the soft memory limit is used. | |
| 298 | |
| 299 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 300 TileVector active_tree_tiles = | |
| 301 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | |
| 302 TileVector pending_tree_tiles = | |
| 303 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | |
| 304 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 305 | |
| 306 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
| 307 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
| 308 | |
| 309 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 310 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 311 | |
| 312 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); | |
| 313 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); | |
| 314 | |
| 315 ReleaseTiles(&active_tree_tiles); | |
| 316 ReleaseTiles(&pending_tree_tiles); | |
| 317 } | |
| 318 | |
| 319 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { | |
| 320 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | |
| 321 // but only enough memory for 8 tiles. The result is all active tree tiles | |
| 322 // get memory, and 3 of the pending tree tiles get memory. | |
| 323 // The pending tiles are not needed to avoid calimity (flickering or | |
| 324 // raster-on-demand) and the active tiles fit, so the soft limit is used. | |
| 325 | |
| 326 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 327 TileVector active_tree_tiles = | |
| 328 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
| 329 TileVector pending_tree_tiles = | |
| 330 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
| 331 | |
| 332 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 333 | |
| 334 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
| 335 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
| 336 | |
| 337 ReleaseTiles(&active_tree_tiles); | |
| 338 ReleaseTiles(&pending_tree_tiles); | |
| 339 } | |
| 340 | |
| 341 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { | |
| 342 // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are | |
| 343 // required for activation, but only enough tiles for 4 tiles. The result | |
| 344 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
| 345 // get memory. | |
| 346 | |
| 347 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 348 TileVector active_tree_tiles = | |
| 349 CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); | |
| 350 TileVector pending_tree_tiles = | |
| 351 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
| 352 | |
| 353 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 354 | |
| 355 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
| 356 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 357 | |
| 358 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 359 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 360 | |
| 361 if (UsingResourceLimit()) { | |
| 362 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 363 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
| 364 } else { | |
| 365 // Pending tiles are now required to avoid calimity (flickering or | |
| 366 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
| 367 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 368 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
| 369 } | |
| 370 | |
| 371 ReleaseTiles(&active_tree_tiles); | |
| 372 ReleaseTiles(&pending_tree_tiles); | |
| 373 } | |
| 374 | |
| 375 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | |
| 376 // 10 tiles on active tree soon bin, 10 tiles on pending tree that are | |
| 377 // required for activation, but only enough tiles for 4 tiles. The result | |
| 378 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
| 379 // get memory. | |
| 380 | |
| 381 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 382 TileVector active_tree_tiles = | |
| 383 CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); | |
| 384 TileVector pending_tree_tiles = | |
| 385 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
| 386 | |
| 387 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 388 | |
| 389 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
| 390 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 391 | |
| 392 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 393 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 394 | |
| 395 if (UsingResourceLimit()) { | |
| 396 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 397 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
| 398 } else { | |
| 399 // Pending tiles are now required to avoid calimity (flickering or | |
| 400 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
| 401 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 402 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
| 403 } | |
| 404 | |
| 405 ReleaseTiles(&active_tree_tiles); | |
| 406 ReleaseTiles(&pending_tree_tiles); | |
| 407 } | |
| 408 | |
| 409 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { | |
| 410 // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, | |
| 411 // but only enough memory for 4 tiles. The result is 4 active tree tiles | |
| 412 // get memory, and none of the pending tree tiles get memory. | |
| 413 | |
| 414 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 415 TileVector active_tree_tiles = | |
| 416 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
| 417 TileVector pending_tree_tiles = | |
| 418 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
| 419 | |
| 420 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 421 | |
| 422 if (UsingResourceLimit()) { | |
| 423 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
| 424 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 425 } else { | |
| 426 // Active tiles are required to avoid calimity (flickering or | |
| 427 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
| 428 EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); | |
| 429 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 430 } | |
| 431 | |
| 432 ReleaseTiles(&active_tree_tiles); | |
| 433 ReleaseTiles(&pending_tree_tiles); | |
| 434 } | |
| 435 | |
| 436 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { | |
| 437 // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, | |
| 438 // but only enough memory for 8 tiles. Any tile missing would cause | |
| 439 // a calamity (flickering or raster-on-demand). Depending on mode, | |
| 440 // we should use varying amounts of the higher hard memory limit. | |
| 441 if (UsingResourceLimit()) | |
| 442 return; | |
| 443 | |
| 444 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 445 TileVector active_tree_tiles = | |
| 446 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
| 447 TileVector pending_tree_tiles = | |
| 448 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
| 449 | |
| 450 // Active tiles are required to avoid calimity. The hard-limit is used and all | |
| 451 // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 | |
| 452 // tiles total are used. | |
| 453 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 454 EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); | |
| 455 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 456 | |
| 457 // Even the hard-limit won't save us now. All tiles are required to avoid | |
| 458 // a clamity but we only have 16. The tiles will be distribted randomly | |
| 459 // given they are identical, in practice depending on their screen location. | |
| 460 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 461 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 462 EXPECT_EQ(16, | |
| 463 AssignedMemoryCount(active_tree_tiles) + | |
| 464 AssignedMemoryCount(pending_tree_tiles)); | |
| 465 | |
| 466 // The pending tree is now more important. Active tiles will take higher | |
| 467 // priority if they are ready-to-draw in practice. Importantly though, | |
| 468 // pending tiles also utilize the hard-limit. | |
| 469 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); | |
| 470 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 471 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 472 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | |
| 473 | |
| 474 ReleaseTiles(&active_tree_tiles); | |
| 475 ReleaseTiles(&pending_tree_tiles); | |
| 476 } | |
| 477 | |
| 478 // If true, the max tile limit should be applied as bytes; if false, | |
| 479 // as num_resources_limit. | |
| 480 INSTANTIATE_TEST_CASE_P(TileManagerTests, | |
| 481 TileManagerTest, | |
| 482 ::testing::Values(true, false)); | |
| 483 | |
| 484 class LowResTilingsSettings : public ImplSidePaintingSettings { | 25 class LowResTilingsSettings : public ImplSidePaintingSettings { |
| 485 public: | 26 public: |
| 486 LowResTilingsSettings() { create_low_res_tiling = true; } | 27 LowResTilingsSettings() { create_low_res_tiling = true; } |
| 487 }; | 28 }; |
| 488 | 29 |
| 489 class TileManagerTilePriorityQueueTest : public testing::Test { | 30 class TileManagerTilePriorityQueueTest : public testing::Test { |
| 490 public: | 31 public: |
| 491 TileManagerTilePriorityQueueTest() | 32 TileManagerTilePriorityQueueTest() |
| 492 : memory_limit_policy_(ALLOW_ANYTHING), | 33 : memory_limit_policy_(ALLOW_ANYTHING), |
| 493 max_tiles_(10000), | 34 max_tiles_(10000), |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( | 180 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( |
| 640 invalidation, gfx::Size(1000, 1000)); | 181 invalidation, gfx::Size(1000, 1000)); |
| 641 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( | 182 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( |
| 642 invalidation, gfx::Size(1000, 1000)); | 183 invalidation, gfx::Size(1000, 1000)); |
| 643 | 184 |
| 644 active_layer_->ResetAllTilesPriorities(); | 185 active_layer_->ResetAllTilesPriorities(); |
| 645 pending_layer_->ResetAllTilesPriorities(); | 186 pending_layer_->ResetAllTilesPriorities(); |
| 646 | 187 |
| 647 // Renew all of the tile priorities. | 188 // Renew all of the tile priorities. |
| 648 gfx::Rect viewport(50, 50, 100, 100); | 189 gfx::Rect viewport(50, 50, 100, 100); |
| 649 pending_layer_->HighResTiling()->UpdateTilePriorities( | 190 pending_layer_->HighResTiling()->ComputeTilePriorityRects( |
| 650 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 191 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 651 pending_layer_->LowResTiling()->UpdateTilePriorities( | 192 pending_layer_->LowResTiling()->ComputeTilePriorityRects( |
| 652 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 193 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 653 active_layer_->HighResTiling()->UpdateTilePriorities( | 194 active_layer_->HighResTiling()->ComputeTilePriorityRects( |
| 654 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); | 195 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 655 active_layer_->LowResTiling()->UpdateTilePriorities( | 196 active_layer_->LowResTiling()->ComputeTilePriorityRects( |
| 656 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); | 197 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 657 | 198 |
| 658 // Populate all tiles directly from the tilings. | 199 // Populate all tiles directly from the tilings. |
| 659 all_tiles.clear(); | 200 all_tiles.clear(); |
| 660 std::vector<Tile*> pending_high_res_tiles = | 201 std::vector<Tile*> pending_high_res_tiles = |
| 661 pending_layer_->HighResTiling()->AllTilesForTesting(); | 202 pending_layer_->HighResTiling()->AllTilesForTesting(); |
| 662 for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) | 203 for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) |
| 663 all_tiles.insert(pending_high_res_tiles[i]); | 204 all_tiles.insert(pending_high_res_tiles[i]); |
| 664 | 205 |
| 665 std::vector<Tile*> pending_low_res_tiles = | 206 std::vector<Tile*> pending_low_res_tiles = |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( | 355 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( |
| 815 invalidation, gfx::Size(1000, 1000)); | 356 invalidation, gfx::Size(1000, 1000)); |
| 816 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( | 357 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( |
| 817 invalidation, gfx::Size(1000, 1000)); | 358 invalidation, gfx::Size(1000, 1000)); |
| 818 | 359 |
| 819 active_layer_->ResetAllTilesPriorities(); | 360 active_layer_->ResetAllTilesPriorities(); |
| 820 pending_layer_->ResetAllTilesPriorities(); | 361 pending_layer_->ResetAllTilesPriorities(); |
| 821 | 362 |
| 822 // Renew all of the tile priorities. | 363 // Renew all of the tile priorities. |
| 823 gfx::Rect viewport(50, 50, 100, 100); | 364 gfx::Rect viewport(50, 50, 100, 100); |
| 824 pending_layer_->HighResTiling()->UpdateTilePriorities( | 365 pending_layer_->HighResTiling()->ComputeTilePriorityRects( |
| 825 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 366 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 826 pending_layer_->LowResTiling()->UpdateTilePriorities( | 367 pending_layer_->LowResTiling()->ComputeTilePriorityRects( |
| 827 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 368 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 828 active_layer_->HighResTiling()->UpdateTilePriorities( | 369 active_layer_->HighResTiling()->ComputeTilePriorityRects( |
| 829 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); | 370 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 830 active_layer_->LowResTiling()->UpdateTilePriorities( | 371 active_layer_->LowResTiling()->ComputeTilePriorityRects( |
| 831 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); | 372 ACTIVE_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 832 | 373 |
| 833 // Populate all tiles directly from the tilings. | 374 // Populate all tiles directly from the tilings. |
| 834 all_tiles.clear(); | 375 all_tiles.clear(); |
| 835 std::vector<Tile*> pending_high_res_tiles = | 376 std::vector<Tile*> pending_high_res_tiles = |
| 836 pending_layer_->HighResTiling()->AllTilesForTesting(); | 377 pending_layer_->HighResTiling()->AllTilesForTesting(); |
| 837 for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) | 378 for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) |
| 838 all_tiles.insert(pending_high_res_tiles[i]); | 379 all_tiles.insert(pending_high_res_tiles[i]); |
| 839 | 380 |
| 840 std::vector<Tile*> pending_low_res_tiles = | 381 std::vector<Tile*> pending_low_res_tiles = |
| 841 pending_layer_->LowResTiling()->AllTilesForTesting(); | 382 pending_layer_->LowResTiling()->AllTilesForTesting(); |
| 842 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) | 383 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) |
| 843 all_tiles.insert(pending_low_res_tiles[i]); | 384 all_tiles.insert(pending_low_res_tiles[i]); |
| 844 | 385 |
| 845 std::vector<Tile*> active_high_res_tiles = | 386 std::vector<Tile*> active_high_res_tiles = |
| 846 active_layer_->HighResTiling()->AllTilesForTesting(); | 387 active_layer_->HighResTiling()->AllTilesForTesting(); |
| 847 for (size_t i = 0; i < active_high_res_tiles.size(); ++i) | 388 for (size_t i = 0; i < active_high_res_tiles.size(); ++i) |
| 848 all_tiles.insert(active_high_res_tiles[i]); | 389 all_tiles.insert(active_high_res_tiles[i]); |
| 849 | 390 |
| 850 std::vector<Tile*> active_low_res_tiles = | 391 std::vector<Tile*> active_low_res_tiles = |
| 851 active_layer_->LowResTiling()->AllTilesForTesting(); | 392 active_layer_->LowResTiling()->AllTilesForTesting(); |
| 852 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 393 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
| 853 all_tiles.insert(active_low_res_tiles[i]); | 394 all_tiles.insert(active_low_res_tiles[i]); |
| 854 | 395 |
| 855 tile_manager()->InitializeTilesWithResourcesForTesting( | 396 tile_manager()->InitializeTilesWithResourcesForTesting( |
| 856 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 397 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 857 | 398 |
| 858 pending_layer_->MarkVisibleResourcesAsRequired(); | |
| 859 | |
| 860 Tile* last_tile = NULL; | 399 Tile* last_tile = NULL; |
| 861 smoothness_tiles.clear(); | 400 smoothness_tiles.clear(); |
| 862 tile_count = 0; | 401 tile_count = 0; |
| 863 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 402 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 864 queue.Reset(); | 403 queue.Reset(); |
| 865 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 404 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 866 while (!queue.IsEmpty()) { | 405 while (!queue.IsEmpty()) { |
| 867 Tile* tile = queue.Top(); | 406 Tile* tile = queue.Top(); |
| 868 EXPECT_TRUE(tile); | 407 EXPECT_TRUE(tile); |
| 869 EXPECT_TRUE(tile->HasResources()); | 408 EXPECT_TRUE(tile->HasResources()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 all_tiles.insert(raster_queue.Top()); | 497 all_tiles.insert(raster_queue.Top()); |
| 959 raster_queue.Pop(); | 498 raster_queue.Pop(); |
| 960 } | 499 } |
| 961 EXPECT_EQ(tile_count, all_tiles.size()); | 500 EXPECT_EQ(tile_count, all_tiles.size()); |
| 962 EXPECT_EQ(34u, tile_count); | 501 EXPECT_EQ(34u, tile_count); |
| 963 | 502 |
| 964 pending_layer_->ResetAllTilesPriorities(); | 503 pending_layer_->ResetAllTilesPriorities(); |
| 965 | 504 |
| 966 // Renew all of the tile priorities. | 505 // Renew all of the tile priorities. |
| 967 gfx::Rect viewport(layer_bounds); | 506 gfx::Rect viewport(layer_bounds); |
| 968 pending_layer_->HighResTiling()->UpdateTilePriorities( | 507 pending_layer_->HighResTiling()->ComputeTilePriorityRects( |
| 969 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 508 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 970 pending_layer_->LowResTiling()->UpdateTilePriorities( | 509 pending_layer_->LowResTiling()->ComputeTilePriorityRects( |
| 971 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 510 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 972 pending_child_layer->HighResTiling()->UpdateTilePriorities( | 511 pending_child_layer->HighResTiling()->ComputeTilePriorityRects( |
| 973 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 512 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 974 pending_child_layer->LowResTiling()->UpdateTilePriorities( | 513 pending_child_layer->LowResTiling()->ComputeTilePriorityRects( |
| 975 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); | 514 PENDING_TREE, viewport, 1.0f, 1.0, Occlusion()); |
| 976 | 515 |
| 977 // Populate all tiles directly from the tilings. | 516 // Populate all tiles directly from the tilings. |
| 978 all_tiles.clear(); | 517 all_tiles.clear(); |
| 979 std::vector<Tile*> pending_high_res_tiles = | 518 std::vector<Tile*> pending_high_res_tiles = |
| 980 pending_layer_->HighResTiling()->AllTilesForTesting(); | 519 pending_layer_->HighResTiling()->AllTilesForTesting(); |
| 981 for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) | 520 all_tiles.insert(pending_high_res_tiles.begin(), |
| 982 all_tiles.insert(pending_high_res_tiles[i]); | 521 pending_high_res_tiles.end()); |
| 983 | 522 |
| 984 std::vector<Tile*> pending_low_res_tiles = | 523 std::vector<Tile*> pending_low_res_tiles = |
| 985 pending_layer_->LowResTiling()->AllTilesForTesting(); | 524 pending_layer_->LowResTiling()->AllTilesForTesting(); |
| 986 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) | 525 all_tiles.insert(pending_low_res_tiles.begin(), pending_low_res_tiles.end()); |
| 987 all_tiles.insert(pending_low_res_tiles[i]); | |
| 988 | 526 |
| 989 // Set all tiles on the pending_child_layer as occluded on the pending tree. | 527 // Set all tiles on the pending_child_layer as occluded on the pending tree. |
| 990 std::vector<Tile*> pending_child_high_res_tiles = | 528 std::vector<Tile*> pending_child_high_res_tiles = |
| 991 pending_child_layer->HighResTiling()->AllTilesForTesting(); | 529 pending_child_layer->HighResTiling()->AllTilesForTesting(); |
| 992 for (size_t i = 0; i < pending_child_high_res_tiles.size(); ++i) { | 530 pending_child_layer->HighResTiling()->SetAllTilesOccludedForTesting(); |
| 993 pending_child_high_res_tiles[i]->set_is_occluded(PENDING_TREE, true); | 531 all_tiles.insert(pending_child_high_res_tiles.begin(), |
| 994 all_tiles.insert(pending_child_high_res_tiles[i]); | 532 pending_child_high_res_tiles.end()); |
| 995 } | |
| 996 | 533 |
| 997 std::vector<Tile*> pending_child_low_res_tiles = | 534 std::vector<Tile*> pending_child_low_res_tiles = |
| 998 pending_child_layer->LowResTiling()->AllTilesForTesting(); | 535 pending_child_layer->LowResTiling()->AllTilesForTesting(); |
| 999 for (size_t i = 0; i < pending_child_low_res_tiles.size(); ++i) { | 536 pending_child_layer->LowResTiling()->SetAllTilesOccludedForTesting(); |
| 1000 pending_child_low_res_tiles[i]->set_is_occluded(PENDING_TREE, true); | 537 all_tiles.insert(pending_child_low_res_tiles.begin(), |
| 1001 all_tiles.insert(pending_child_low_res_tiles[i]); | 538 pending_child_low_res_tiles.end()); |
| 1002 } | |
| 1003 | 539 |
| 1004 tile_manager()->InitializeTilesWithResourcesForTesting( | 540 tile_manager()->InitializeTilesWithResourcesForTesting( |
| 1005 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 541 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 1006 | 542 |
| 1007 // Verify occlusion is considered by EvictionTilePriorityQueue. | 543 // Verify occlusion is considered by EvictionTilePriorityQueue. |
| 1008 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; | 544 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; |
| 1009 size_t occluded_count = 0u; | 545 size_t occluded_count = 0u; |
| 1010 Tile* last_tile = NULL; | 546 Tile* last_tile = NULL; |
| 1011 EvictionTilePriorityQueue queue; | 547 EvictionTilePriorityQueue queue; |
| 1012 host_impl_.BuildEvictionQueue(&queue, tree_priority); | 548 host_impl_.BuildEvictionQueue(&queue, tree_priority); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 all_tiles.insert(queue.Top()); | 671 all_tiles.insert(queue.Top()); |
| 1136 ++tile_count; | 672 ++tile_count; |
| 1137 queue.Pop(); | 673 queue.Pop(); |
| 1138 } | 674 } |
| 1139 EXPECT_EQ(tile_count, all_tiles.size()); | 675 EXPECT_EQ(tile_count, all_tiles.size()); |
| 1140 EXPECT_EQ(17u, tile_count); | 676 EXPECT_EQ(17u, tile_count); |
| 1141 } | 677 } |
| 1142 | 678 |
| 1143 } // namespace | 679 } // namespace |
| 1144 } // namespace cc | 680 } // namespace cc |
| OLD | NEW |