| 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 output_surface_ = FakeOutputSurface::Create3d(); | |
| 37 CHECK(output_surface_->BindToClient(&output_surface_client_)); | |
| 38 | |
| 39 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | |
| 40 resource_provider_ = ResourceProvider::Create( | |
| 41 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, | |
| 42 false); | |
| 43 resource_pool_ = ResourcePool::Create( | |
| 44 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | |
| 45 tile_manager_ = | |
| 46 make_scoped_ptr(new FakeTileManager(this, resource_pool_.get())); | |
| 47 | |
| 48 memory_limit_policy_ = memory_limit_policy; | |
| 49 max_tiles_ = max_tiles; | |
| 50 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | |
| 51 | |
| 52 SetTreePriority(tree_priority); | |
| 53 } | |
| 54 | |
| 55 void SetTreePriority(TreePriority tree_priority) { | |
| 56 GlobalStateThatImpactsTilePriority state; | |
| 57 gfx::Size tile_size = settings_.default_tile_size; | |
| 58 | |
| 59 if (UsingMemoryLimit()) { | |
| 60 state.soft_memory_limit_in_bytes = | |
| 61 max_tiles_ * 4 * tile_size.width() * tile_size.height(); | |
| 62 state.num_resources_limit = 100; | |
| 63 } else { | |
| 64 state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; | |
| 65 state.num_resources_limit = max_tiles_; | |
| 66 } | |
| 67 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; | |
| 68 state.memory_limit_policy = memory_limit_policy_; | |
| 69 state.tree_priority = tree_priority; | |
| 70 | |
| 71 global_state_ = state; | |
| 72 resource_pool_->SetResourceUsageLimits(state.soft_memory_limit_in_bytes, | |
| 73 state.soft_memory_limit_in_bytes, | |
| 74 state.num_resources_limit); | |
| 75 tile_manager_->SetGlobalStateForTesting(state); | |
| 76 } | |
| 77 | |
| 78 virtual void TearDown() OVERRIDE { | |
| 79 tile_manager_.reset(NULL); | |
| 80 picture_pile_ = NULL; | |
| 81 | |
| 82 testing::Test::TearDown(); | |
| 83 } | |
| 84 | |
| 85 // TileManagerClient implementation. | |
| 86 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() OVERRIDE { | |
| 87 return picture_layers_; | |
| 88 } | |
| 89 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | |
| 90 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} | |
| 91 | |
| 92 TileVector CreateTilesWithSize(int count, | |
| 93 TilePriority active_priority, | |
| 94 TilePriority pending_priority, | |
| 95 const gfx::Size& tile_size) { | |
| 96 TileVector tiles; | |
| 97 for (int i = 0; i < count; ++i) { | |
| 98 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | |
| 99 tile_size, | |
| 100 gfx::Rect(), | |
| 101 gfx::Rect(), | |
| 102 1.0, | |
| 103 0, | |
| 104 0, | |
| 105 0); | |
| 106 tile->SetPriority(ACTIVE_TREE, active_priority); | |
| 107 tile->SetPriority(PENDING_TREE, pending_priority); | |
| 108 tiles.push_back(tile); | |
| 109 } | |
| 110 return tiles; | |
| 111 } | |
| 112 | |
| 113 TileVector CreateTiles(int count, | |
| 114 TilePriority active_priority, | |
| 115 TilePriority pending_priority) { | |
| 116 return CreateTilesWithSize( | |
| 117 count, active_priority, pending_priority, settings_.default_tile_size); | |
| 118 } | |
| 119 | |
| 120 FakeTileManager* tile_manager() { return tile_manager_.get(); } | |
| 121 | |
| 122 int AssignedMemoryCount(const TileVector& tiles) { | |
| 123 int has_memory_count = 0; | |
| 124 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | |
| 125 ++it) { | |
| 126 if (tile_manager_->HasBeenAssignedMemory(*it)) | |
| 127 ++has_memory_count; | |
| 128 } | |
| 129 return has_memory_count; | |
| 130 } | |
| 131 | |
| 132 bool ready_to_activate() const { return ready_to_activate_; } | |
| 133 | |
| 134 // The parametrization specifies whether the max tile limit should | |
| 135 // be applied to memory or resources. | |
| 136 bool UsingResourceLimit() { return !GetParam(); } | |
| 137 bool UsingMemoryLimit() { return GetParam(); } | |
| 138 | |
| 139 protected: | |
| 140 GlobalStateThatImpactsTilePriority global_state_; | |
| 141 | |
| 142 private: | |
| 143 LayerTreeSettings settings_; | |
| 144 scoped_ptr<FakeTileManager> tile_manager_; | |
| 145 scoped_refptr<FakePicturePileImpl> picture_pile_; | |
| 146 FakeOutputSurfaceClient output_surface_client_; | |
| 147 scoped_ptr<FakeOutputSurface> output_surface_; | |
| 148 scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; | |
| 149 scoped_ptr<ResourceProvider> resource_provider_; | |
| 150 scoped_ptr<ResourcePool> resource_pool_; | |
| 151 TileMemoryLimitPolicy memory_limit_policy_; | |
| 152 int max_tiles_; | |
| 153 bool ready_to_activate_; | |
| 154 std::vector<PictureLayerImpl*> picture_layers_; | |
| 155 }; | |
| 156 | |
| 157 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { | |
| 158 // A few tiles of each type of priority, with enough memory for all tiles. | |
| 159 | |
| 160 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 161 TileVector active_now = | |
| 162 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 163 TileVector pending_now = | |
| 164 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 165 TileVector active_pending_soon = | |
| 166 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 167 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 168 | |
| 169 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 170 | |
| 171 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
| 172 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
| 173 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
| 174 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 175 } | |
| 176 | |
| 177 TEST_P(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { | |
| 178 // A few tiles of each type of priority, with enough memory for all tiles, | |
| 179 // with the exception of never bin. | |
| 180 | |
| 181 Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); | |
| 182 TileVector active_now = | |
| 183 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 184 TileVector pending_now = | |
| 185 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 186 TileVector active_pending_soon = | |
| 187 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 188 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 189 | |
| 190 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 191 | |
| 192 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
| 193 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
| 194 EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); | |
| 195 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 196 } | |
| 197 | |
| 198 TEST_P(TileManagerTest, EnoughMemoryPendingLowResAllowAbsoluteMinimum) { | |
| 199 // A few low-res tiles required for activation, with enough memory for all | |
| 200 // tiles. | |
| 201 | |
| 202 Initialize(5, ALLOW_ABSOLUTE_MINIMUM, SAME_PRIORITY_FOR_BOTH_TREES); | |
| 203 TileVector pending_low_res = | |
| 204 CreateTiles(5, TilePriority(), TilePriorityLowRes()); | |
| 205 | |
| 206 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 207 | |
| 208 EXPECT_EQ(5, AssignedMemoryCount(pending_low_res)); | |
| 209 } | |
| 210 | |
| 211 TEST_P(TileManagerTest, EnoughMemoryAllowAbsoluteMinimum) { | |
| 212 // A few tiles of each type of priority, with enough memory for all tiles, | |
| 213 // with the exception of never and soon bins. | |
| 214 | |
| 215 Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY); | |
| 216 TileVector active_now = | |
| 217 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 218 TileVector pending_now = | |
| 219 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 220 TileVector active_pending_soon = | |
| 221 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 222 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 223 | |
| 224 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 225 | |
| 226 EXPECT_EQ(3, AssignedMemoryCount(active_now)); | |
| 227 EXPECT_EQ(3, AssignedMemoryCount(pending_now)); | |
| 228 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
| 229 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 230 } | |
| 231 | |
| 232 TEST_P(TileManagerTest, EnoughMemoryAllowNothing) { | |
| 233 // A few tiles of each type of priority, with enough memory for all tiles, | |
| 234 // but allow nothing should not assign any memory. | |
| 235 | |
| 236 Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 237 TileVector active_now = | |
| 238 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | |
| 239 TileVector pending_now = | |
| 240 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | |
| 241 TileVector active_pending_soon = | |
| 242 CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | |
| 243 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | |
| 244 | |
| 245 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 246 | |
| 247 EXPECT_EQ(0, AssignedMemoryCount(active_now)); | |
| 248 EXPECT_EQ(0, AssignedMemoryCount(pending_now)); | |
| 249 EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); | |
| 250 EXPECT_EQ(0, AssignedMemoryCount(never_bin)); | |
| 251 } | |
| 252 | |
| 253 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { | |
| 254 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are | |
| 255 // required for activation, but only enough memory for 8 tiles. The result | |
| 256 // is all pending tree tiles get memory, and 3 of the active tree tiles | |
| 257 // get memory. None of these tiles is needed to avoid calimity (flickering or | |
| 258 // raster-on-demand) so the soft memory limit is used. | |
| 259 | |
| 260 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 261 TileVector active_tree_tiles = | |
| 262 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | |
| 263 TileVector pending_tree_tiles = | |
| 264 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); | |
| 265 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 266 | |
| 267 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
| 268 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
| 269 | |
| 270 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 271 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 272 | |
| 273 EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); | |
| 274 EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); | |
| 275 } | |
| 276 | |
| 277 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { | |
| 278 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | |
| 279 // but only enough memory for 8 tiles. The result is all active tree tiles | |
| 280 // get memory, and 3 of the pending tree tiles get memory. | |
| 281 // The pending tiles are not needed to avoid calimity (flickering or | |
| 282 // raster-on-demand) and the active tiles fit, so the soft limit is used. | |
| 283 | |
| 284 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 285 TileVector active_tree_tiles = | |
| 286 CreateTiles(5, TilePriorityForNowBin(), TilePriority()); | |
| 287 TileVector pending_tree_tiles = | |
| 288 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | |
| 289 | |
| 290 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 291 | |
| 292 EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); | |
| 293 EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); | |
| 294 } | |
| 295 | |
| 296 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { | |
| 297 // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are | |
| 298 // required for activation, but only enough tiles for 4 tiles. The result | |
| 299 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
| 300 // get memory. | |
| 301 | |
| 302 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 303 TileVector active_tree_tiles = | |
| 304 CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); | |
| 305 TileVector pending_tree_tiles = | |
| 306 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
| 307 | |
| 308 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 309 | |
| 310 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
| 311 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 312 | |
| 313 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 314 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 315 | |
| 316 if (UsingResourceLimit()) { | |
| 317 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 318 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
| 319 } else { | |
| 320 // Pending tiles are now required to avoid calimity (flickering or | |
| 321 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
| 322 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 323 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
| 324 } | |
| 325 } | |
| 326 | |
| 327 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | |
| 328 // 10 tiles on active tree soon bin, 10 tiles on pending tree that are | |
| 329 // required for activation, but only enough tiles for 4 tiles. The result | |
| 330 // is 4 pending tree tiles get memory, and none of the active tree tiles | |
| 331 // get memory. | |
| 332 | |
| 333 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 334 TileVector active_tree_tiles = | |
| 335 CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); | |
| 336 TileVector pending_tree_tiles = | |
| 337 CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); | |
| 338 | |
| 339 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 340 | |
| 341 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
| 342 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 343 | |
| 344 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 345 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 346 | |
| 347 if (UsingResourceLimit()) { | |
| 348 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 349 EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); | |
| 350 } else { | |
| 351 // Pending tiles are now required to avoid calimity (flickering or | |
| 352 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
| 353 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 354 EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); | |
| 355 } | |
| 356 } | |
| 357 | |
| 358 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { | |
| 359 // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, | |
| 360 // but only enough memory for 4 tiles. The result is 4 active tree tiles | |
| 361 // get memory, and none of the pending tree tiles get memory. | |
| 362 | |
| 363 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 364 TileVector active_tree_tiles = | |
| 365 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
| 366 TileVector pending_tree_tiles = | |
| 367 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
| 368 | |
| 369 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 370 | |
| 371 if (UsingResourceLimit()) { | |
| 372 EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); | |
| 373 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 374 } else { | |
| 375 // Active tiles are required to avoid calimity (flickering or | |
| 376 // raster-on-demand). Hard-limit is used and double the tiles fit. | |
| 377 EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); | |
| 378 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { | |
| 383 // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, | |
| 384 // but only enough memory for 8 tiles. Any tile missing would cause | |
| 385 // a calamity (flickering or raster-on-demand). Depending on mode, | |
| 386 // we should use varying amounts of the higher hard memory limit. | |
| 387 if (UsingResourceLimit()) | |
| 388 return; | |
| 389 | |
| 390 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | |
| 391 TileVector active_tree_tiles = | |
| 392 CreateTiles(10, TilePriorityForNowBin(), TilePriority()); | |
| 393 TileVector pending_tree_tiles = | |
| 394 CreateTiles(10, TilePriority(), TilePriorityForNowBin()); | |
| 395 | |
| 396 // Active tiles are required to avoid calimity. The hard-limit is used and all | |
| 397 // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 | |
| 398 // tiles total are used. | |
| 399 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 400 EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); | |
| 401 EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); | |
| 402 | |
| 403 // Even the hard-limit won't save us now. All tiles are required to avoid | |
| 404 // a clamity but we only have 16. The tiles will be distribted randomly | |
| 405 // given they are identical, in practice depending on their screen location. | |
| 406 SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); | |
| 407 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 408 EXPECT_EQ(16, | |
| 409 AssignedMemoryCount(active_tree_tiles) + | |
| 410 AssignedMemoryCount(pending_tree_tiles)); | |
| 411 | |
| 412 // The pending tree is now more important. Active tiles will take higher | |
| 413 // priority if they are ready-to-draw in practice. Importantly though, | |
| 414 // pending tiles also utilize the hard-limit. | |
| 415 SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); | |
| 416 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 417 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | |
| 418 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | |
| 419 } | |
| 420 | |
| 421 // If true, the max tile limit should be applied as bytes; if false, | |
| 422 // as num_resources_limit. | |
| 423 INSTANTIATE_TEST_CASE_P(TileManagerTests, | |
| 424 TileManagerTest, | |
| 425 ::testing::Values(true, false)); | |
| 426 | |
| 427 class TileManagerTileIteratorTest : public testing::Test { | 23 class TileManagerTileIteratorTest : public testing::Test { |
| 428 public: | 24 public: |
| 429 TileManagerTileIteratorTest() | 25 TileManagerTileIteratorTest() |
| 430 : memory_limit_policy_(ALLOW_ANYTHING), | 26 : memory_limit_policy_(ALLOW_ANYTHING), |
| 431 max_tiles_(10000), | 27 max_tiles_(10000), |
| 432 ready_to_activate_(false), | 28 ready_to_activate_(false), |
| 433 id_(7), | 29 id_(7), |
| 434 proxy_(base::MessageLoopProxy::current()), | 30 proxy_(base::MessageLoopProxy::current()), |
| 435 host_impl_(ImplSidePaintingSettings(), | 31 host_impl_(ImplSidePaintingSettings(), |
| 436 &proxy_, | 32 &proxy_, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 TileMemoryLimitPolicy memory_limit_policy_; | 126 TileMemoryLimitPolicy memory_limit_policy_; |
| 531 int max_tiles_; | 127 int max_tiles_; |
| 532 bool ready_to_activate_; | 128 bool ready_to_activate_; |
| 533 int id_; | 129 int id_; |
| 534 FakeImplProxy proxy_; | 130 FakeImplProxy proxy_; |
| 535 FakeLayerTreeHostImpl host_impl_; | 131 FakeLayerTreeHostImpl host_impl_; |
| 536 FakePictureLayerImpl* pending_layer_; | 132 FakePictureLayerImpl* pending_layer_; |
| 537 FakePictureLayerImpl* active_layer_; | 133 FakePictureLayerImpl* active_layer_; |
| 538 }; | 134 }; |
| 539 | 135 |
| 540 TEST_F(TileManagerTileIteratorTest, PairedPictureLayers) { | 136 TEST_F(TileManagerTileIteratorTest, RasterTilePriorityQueue) { |
| 541 host_impl_.CreatePendingTree(); | |
| 542 host_impl_.ActivateSyncTree(); | |
| 543 host_impl_.CreatePendingTree(); | |
| 544 | |
| 545 LayerTreeImpl* active_tree = host_impl_.active_tree(); | |
| 546 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | |
| 547 EXPECT_NE(active_tree, pending_tree); | |
| 548 | |
| 549 scoped_ptr<FakePictureLayerImpl> active_layer = | |
| 550 FakePictureLayerImpl::Create(active_tree, 10); | |
| 551 scoped_ptr<FakePictureLayerImpl> pending_layer = | |
| 552 FakePictureLayerImpl::Create(pending_tree, 10); | |
| 553 | |
| 554 TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager(); | |
| 555 EXPECT_TRUE(tile_manager); | |
| 556 | |
| 557 std::vector<TileManager::PairedPictureLayer> paired_layers; | |
| 558 tile_manager->GetPairedPictureLayers(&paired_layers); | |
| 559 | |
| 560 EXPECT_EQ(2u, paired_layers.size()); | |
| 561 if (paired_layers[0].active_layer) { | |
| 562 EXPECT_EQ(active_layer.get(), paired_layers[0].active_layer); | |
| 563 EXPECT_EQ(NULL, paired_layers[0].pending_layer); | |
| 564 } else { | |
| 565 EXPECT_EQ(pending_layer.get(), paired_layers[0].pending_layer); | |
| 566 EXPECT_EQ(NULL, paired_layers[0].active_layer); | |
| 567 } | |
| 568 | |
| 569 if (paired_layers[1].active_layer) { | |
| 570 EXPECT_EQ(active_layer.get(), paired_layers[1].active_layer); | |
| 571 EXPECT_EQ(NULL, paired_layers[1].pending_layer); | |
| 572 } else { | |
| 573 EXPECT_EQ(pending_layer.get(), paired_layers[1].pending_layer); | |
| 574 EXPECT_EQ(NULL, paired_layers[1].active_layer); | |
| 575 } | |
| 576 | |
| 577 active_layer->set_twin_layer(pending_layer.get()); | |
| 578 pending_layer->set_twin_layer(active_layer.get()); | |
| 579 | |
| 580 tile_manager->GetPairedPictureLayers(&paired_layers); | |
| 581 EXPECT_EQ(1u, paired_layers.size()); | |
| 582 | |
| 583 EXPECT_EQ(active_layer.get(), paired_layers[0].active_layer); | |
| 584 EXPECT_EQ(pending_layer.get(), paired_layers[0].pending_layer); | |
| 585 } | |
| 586 | |
| 587 TEST_F(TileManagerTileIteratorTest, RasterTileIterator) { | |
| 588 SetupDefaultTrees(gfx::Size(1000, 1000)); | 137 SetupDefaultTrees(gfx::Size(1000, 1000)); |
| 589 TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager(); | |
| 590 EXPECT_TRUE(tile_manager); | |
| 591 | 138 |
| 592 active_layer_->CreateDefaultTilingsAndTiles(); | 139 active_layer_->CreateDefaultTilingsAndTiles(); |
| 593 pending_layer_->CreateDefaultTilingsAndTiles(); | 140 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 594 | 141 |
| 595 std::vector<TileManager::PairedPictureLayer> paired_layers; | 142 std::vector<PairedPictureLayer> paired_layers; |
| 596 tile_manager->GetPairedPictureLayers(&paired_layers); | 143 host_impl_.GetPairedPictureLayers(&paired_layers); |
| 597 EXPECT_EQ(1u, paired_layers.size()); | 144 EXPECT_EQ(1u, paired_layers.size()); |
| 598 | 145 |
| 599 TileManager::RasterTileIterator it(tile_manager, | 146 RasterTilePriorityQueue queue; |
| 600 SAME_PRIORITY_FOR_BOTH_TREES); | 147 host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 601 EXPECT_TRUE(it); | 148 EXPECT_FALSE(queue.IsEmpty()); |
| 602 | 149 |
| 603 size_t tile_count = 0; | 150 size_t tile_count = 0; |
| 604 std::set<Tile*> all_tiles; | 151 std::set<Tile*> all_tiles; |
| 605 for (; it; ++it) { | 152 for (; !queue.IsEmpty(); queue.Pop()) { |
| 606 EXPECT_TRUE(*it); | 153 Tile* tile = queue.Top(); |
| 607 all_tiles.insert(*it); | 154 EXPECT_TRUE(tile); |
| 155 all_tiles.insert(tile); |
| 608 ++tile_count; | 156 ++tile_count; |
| 609 } | 157 } |
| 610 | 158 |
| 611 EXPECT_EQ(tile_count, all_tiles.size()); | 159 EXPECT_EQ(tile_count, all_tiles.size()); |
| 612 EXPECT_EQ(17u, tile_count); | 160 EXPECT_EQ(17u, tile_count); |
| 613 | 161 |
| 614 // Sanity check, all tiles should be visible. | 162 // Sanity check, all tiles should be visible. |
| 615 std::set<Tile*> smoothness_tiles; | 163 std::set<Tile*> smoothness_tiles; |
| 616 for (TileManager::RasterTileIterator it(tile_manager, | 164 queue.Reset(); |
| 617 SMOOTHNESS_TAKES_PRIORITY); | 165 host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 618 it; | 166 for (; !queue.IsEmpty(); queue.Pop()) { |
| 619 ++it) { | 167 Tile* tile = queue.Top(); |
| 620 Tile* tile = *it; | |
| 621 EXPECT_TRUE(tile); | 168 EXPECT_TRUE(tile); |
| 622 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); | 169 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); |
| 623 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); | 170 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); |
| 624 smoothness_tiles.insert(tile); | 171 smoothness_tiles.insert(tile); |
| 625 } | 172 } |
| 626 EXPECT_EQ(all_tiles, smoothness_tiles); | 173 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 627 | 174 |
| 628 Region invalidation(gfx::Rect(0, 0, 500, 500)); | 175 Region invalidation(gfx::Rect(0, 0, 500, 500)); |
| 629 | 176 |
| 630 // Invalidate the pending tree. | 177 // Invalidate the pending tree. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 ACTIVE_TREE, | 214 ACTIVE_TREE, |
| 668 viewport, | 215 viewport, |
| 669 1.0f, | 216 1.0f, |
| 670 1.0, | 217 1.0, |
| 671 NULL, | 218 NULL, |
| 672 active_layer_->render_target(), | 219 active_layer_->render_target(), |
| 673 active_layer_->draw_transform()); | 220 active_layer_->draw_transform()); |
| 674 | 221 |
| 675 // Populate all tiles directly from the tilings. | 222 // Populate all tiles directly from the tilings. |
| 676 all_tiles.clear(); | 223 all_tiles.clear(); |
| 224 pending_layer_->HighResTiling()->CreateAllTilesForTesting(); |
| 677 std::vector<Tile*> pending_high_res_tiles = | 225 std::vector<Tile*> pending_high_res_tiles = |
| 678 pending_layer_->HighResTiling()->AllTilesForTesting(); | 226 pending_layer_->HighResTiling()->AllTilesForTesting(); |
| 679 for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) | 227 for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) |
| 680 all_tiles.insert(pending_high_res_tiles[i]); | 228 all_tiles.insert(pending_high_res_tiles[i]); |
| 681 | 229 |
| 230 pending_layer_->LowResTiling()->CreateAllTilesForTesting(); |
| 682 std::vector<Tile*> pending_low_res_tiles = | 231 std::vector<Tile*> pending_low_res_tiles = |
| 683 pending_layer_->LowResTiling()->AllTilesForTesting(); | 232 pending_layer_->LowResTiling()->AllTilesForTesting(); |
| 684 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) | 233 for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) |
| 685 all_tiles.insert(pending_low_res_tiles[i]); | 234 all_tiles.insert(pending_low_res_tiles[i]); |
| 686 | 235 |
| 236 active_layer_->HighResTiling()->CreateAllTilesForTesting(); |
| 687 std::vector<Tile*> active_high_res_tiles = | 237 std::vector<Tile*> active_high_res_tiles = |
| 688 active_layer_->HighResTiling()->AllTilesForTesting(); | 238 active_layer_->HighResTiling()->AllTilesForTesting(); |
| 689 for (size_t i = 0; i < active_high_res_tiles.size(); ++i) | 239 for (size_t i = 0; i < active_high_res_tiles.size(); ++i) |
| 690 all_tiles.insert(active_high_res_tiles[i]); | 240 all_tiles.insert(active_high_res_tiles[i]); |
| 691 | 241 |
| 242 active_layer_->LowResTiling()->CreateAllTilesForTesting(); |
| 692 std::vector<Tile*> active_low_res_tiles = | 243 std::vector<Tile*> active_low_res_tiles = |
| 693 active_layer_->LowResTiling()->AllTilesForTesting(); | 244 active_layer_->LowResTiling()->AllTilesForTesting(); |
| 694 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 245 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
| 695 all_tiles.insert(active_low_res_tiles[i]); | 246 all_tiles.insert(active_low_res_tiles[i]); |
| 696 | 247 |
| 697 Tile* last_tile = NULL; | 248 Tile* last_tile = NULL; |
| 698 smoothness_tiles.clear(); | 249 smoothness_tiles.clear(); |
| 699 tile_count = 0; | 250 tile_count = 0; |
| 700 size_t increasing_distance_tiles = 0u; | 251 size_t increasing_distance_tiles = 0u; |
| 701 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 252 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 702 for (TileManager::RasterTileIterator it(tile_manager, | 253 queue.Reset(); |
| 703 SMOOTHNESS_TAKES_PRIORITY); | 254 host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 704 it; | 255 for (; !queue.IsEmpty(); queue.Pop()) { |
| 705 ++it) { | 256 Tile* tile = queue.Top(); |
| 706 Tile* tile = *it; | |
| 707 EXPECT_TRUE(tile); | 257 EXPECT_TRUE(tile); |
| 708 | 258 |
| 709 if (!last_tile) | 259 if (!last_tile) |
| 710 last_tile = tile; | 260 last_tile = tile; |
| 711 | 261 |
| 712 EXPECT_LE(last_tile->priority(ACTIVE_TREE).priority_bin, | 262 EXPECT_LE(last_tile->priority(ACTIVE_TREE).priority_bin, |
| 713 tile->priority(ACTIVE_TREE).priority_bin); | 263 tile->priority(ACTIVE_TREE).priority_bin); |
| 714 if (last_tile->priority(ACTIVE_TREE).priority_bin == | 264 if (last_tile->priority(ACTIVE_TREE).priority_bin == |
| 715 tile->priority(ACTIVE_TREE).priority_bin) { | 265 tile->priority(ACTIVE_TREE).priority_bin) { |
| 716 increasing_distance_tiles += | 266 increasing_distance_tiles += |
| (...skipping 16 matching lines...) Expand all Loading... |
| 733 EXPECT_EQ(tile_count, smoothness_tiles.size()); | 283 EXPECT_EQ(tile_count, smoothness_tiles.size()); |
| 734 EXPECT_EQ(all_tiles, smoothness_tiles); | 284 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 735 // Since we don't guarantee increasing distance due to spiral iterator, we | 285 // Since we don't guarantee increasing distance due to spiral iterator, we |
| 736 // should check that we're _mostly_ right. | 286 // should check that we're _mostly_ right. |
| 737 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); | 287 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); |
| 738 | 288 |
| 739 std::set<Tile*> new_content_tiles; | 289 std::set<Tile*> new_content_tiles; |
| 740 last_tile = NULL; | 290 last_tile = NULL; |
| 741 increasing_distance_tiles = 0u; | 291 increasing_distance_tiles = 0u; |
| 742 // Here we expect to get increasing PENDING_TREE priority_bin. | 292 // Here we expect to get increasing PENDING_TREE priority_bin. |
| 743 for (TileManager::RasterTileIterator it(tile_manager, | 293 queue.Reset(); |
| 744 NEW_CONTENT_TAKES_PRIORITY); | 294 host_impl_.BuildRasterQueue(&queue, NEW_CONTENT_TAKES_PRIORITY); |
| 745 it; | 295 for (; !queue.IsEmpty(); queue.Pop()) { |
| 746 ++it) { | 296 Tile* tile = queue.Top(); |
| 747 Tile* tile = *it; | |
| 748 EXPECT_TRUE(tile); | 297 EXPECT_TRUE(tile); |
| 749 | 298 |
| 750 if (!last_tile) | 299 if (!last_tile) |
| 751 last_tile = tile; | 300 last_tile = tile; |
| 752 | 301 |
| 753 EXPECT_LE(last_tile->priority(PENDING_TREE).priority_bin, | 302 EXPECT_LE(last_tile->priority(PENDING_TREE).priority_bin, |
| 754 tile->priority(PENDING_TREE).priority_bin); | 303 tile->priority(PENDING_TREE).priority_bin); |
| 755 if (last_tile->priority(PENDING_TREE).priority_bin == | 304 if (last_tile->priority(PENDING_TREE).priority_bin == |
| 756 tile->priority(PENDING_TREE).priority_bin) { | 305 tile->priority(PENDING_TREE).priority_bin) { |
| 757 increasing_distance_tiles += | 306 increasing_distance_tiles += |
| (...skipping 12 matching lines...) Expand all Loading... |
| 770 new_content_tiles.insert(tile); | 319 new_content_tiles.insert(tile); |
| 771 } | 320 } |
| 772 | 321 |
| 773 EXPECT_EQ(tile_count, new_content_tiles.size()); | 322 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 774 EXPECT_EQ(all_tiles, new_content_tiles); | 323 EXPECT_EQ(all_tiles, new_content_tiles); |
| 775 // Since we don't guarantee increasing distance due to spiral iterator, we | 324 // Since we don't guarantee increasing distance due to spiral iterator, we |
| 776 // should check that we're _mostly_ right. | 325 // should check that we're _mostly_ right. |
| 777 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); | 326 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); |
| 778 } | 327 } |
| 779 | 328 |
| 780 TEST_F(TileManagerTileIteratorTest, EvictionTileIterator) { | 329 TEST_F(TileManagerTileIteratorTest, EvictionTileQueue) { |
| 781 SetupDefaultTrees(gfx::Size(1000, 1000)); | 330 SetupDefaultTrees(gfx::Size(1000, 1000)); |
| 782 TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager(); | |
| 783 EXPECT_TRUE(tile_manager); | |
| 784 | 331 |
| 785 active_layer_->CreateDefaultTilingsAndTiles(); | 332 active_layer_->CreateDefaultTilingsAndTiles(); |
| 786 pending_layer_->CreateDefaultTilingsAndTiles(); | 333 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 787 | 334 |
| 788 std::vector<TileManager::PairedPictureLayer> paired_layers; | 335 std::vector<PairedPictureLayer> paired_layers; |
| 789 tile_manager->GetPairedPictureLayers(&paired_layers); | 336 host_impl_.GetPairedPictureLayers(&paired_layers); |
| 790 EXPECT_EQ(1u, paired_layers.size()); | 337 EXPECT_EQ(1u, paired_layers.size()); |
| 791 | 338 |
| 792 TileManager::EvictionTileIterator empty_it(tile_manager, | 339 EvictionTilePriorityQueue empty_queue; |
| 793 SAME_PRIORITY_FOR_BOTH_TREES); | 340 host_impl_.BuildEvictionQueue(&empty_queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 794 EXPECT_FALSE(empty_it); | 341 EXPECT_TRUE(empty_queue.IsEmpty()); |
| 795 std::set<Tile*> all_tiles; | 342 std::set<Tile*> all_tiles; |
| 796 size_t tile_count = 0; | 343 size_t tile_count = 0; |
| 797 | 344 |
| 798 for (TileManager::RasterTileIterator raster_it(tile_manager, | 345 RasterTilePriorityQueue raster_queue; |
| 799 SAME_PRIORITY_FOR_BOTH_TREES); | 346 host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 800 raster_it; | 347 for (; !raster_queue.IsEmpty(); raster_queue.Pop()) { |
| 801 ++raster_it) { | 348 Tile* tile = raster_queue.Top(); |
| 802 ++tile_count; | 349 ++tile_count; |
| 803 EXPECT_TRUE(*raster_it); | 350 EXPECT_TRUE(tile); |
| 804 all_tiles.insert(*raster_it); | 351 all_tiles.insert(tile); |
| 805 } | 352 } |
| 806 | 353 |
| 807 EXPECT_EQ(tile_count, all_tiles.size()); | 354 EXPECT_EQ(tile_count, all_tiles.size()); |
| 808 EXPECT_EQ(17u, tile_count); | 355 EXPECT_EQ(17u, tile_count); |
| 809 | 356 |
| 357 TileManager* tile_manager = host_impl_.tile_manager(); |
| 358 ASSERT_TRUE(tile_manager); |
| 359 |
| 810 tile_manager->InitializeTilesWithResourcesForTesting( | 360 tile_manager->InitializeTilesWithResourcesForTesting( |
| 811 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 361 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 812 | 362 |
| 813 TileManager::EvictionTileIterator it(tile_manager, SMOOTHNESS_TAKES_PRIORITY); | 363 EvictionTilePriorityQueue eviction_queue; |
| 814 EXPECT_TRUE(it); | 364 host_impl_.BuildEvictionQueue(&eviction_queue, SMOOTHNESS_TAKES_PRIORITY); |
| 365 EXPECT_FALSE(eviction_queue.IsEmpty()); |
| 815 | 366 |
| 816 // Sanity check, all tiles should be visible. | 367 // Sanity check, all tiles should be visible. |
| 817 std::set<Tile*> smoothness_tiles; | 368 std::set<Tile*> smoothness_tiles; |
| 818 for (; it; ++it) { | 369 for (; !eviction_queue.IsEmpty(); eviction_queue.Pop()) { |
| 819 Tile* tile = *it; | 370 Tile* tile = eviction_queue.Top(); |
| 820 EXPECT_TRUE(tile); | 371 EXPECT_TRUE(tile); |
| 821 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); | 372 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); |
| 822 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); | 373 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); |
| 823 EXPECT_TRUE(tile->HasResources()); | 374 EXPECT_TRUE(tile->HasResources()); |
| 824 smoothness_tiles.insert(tile); | 375 smoothness_tiles.insert(tile); |
| 825 } | 376 } |
| 826 EXPECT_EQ(all_tiles, smoothness_tiles); | 377 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 827 | 378 |
| 828 tile_manager->ReleaseTileResourcesForTesting( | 379 tile_manager->ReleaseTileResourcesForTesting( |
| 829 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 380 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 448 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
| 898 all_tiles.insert(active_low_res_tiles[i]); | 449 all_tiles.insert(active_low_res_tiles[i]); |
| 899 | 450 |
| 900 tile_manager->InitializeTilesWithResourcesForTesting( | 451 tile_manager->InitializeTilesWithResourcesForTesting( |
| 901 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 452 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 902 | 453 |
| 903 Tile* last_tile = NULL; | 454 Tile* last_tile = NULL; |
| 904 smoothness_tiles.clear(); | 455 smoothness_tiles.clear(); |
| 905 tile_count = 0; | 456 tile_count = 0; |
| 906 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 457 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 907 for (TileManager::EvictionTileIterator it(tile_manager, | 458 eviction_queue.Reset(); |
| 908 SMOOTHNESS_TAKES_PRIORITY); | 459 host_impl_.BuildEvictionQueue(&eviction_queue, SMOOTHNESS_TAKES_PRIORITY); |
| 909 it; | 460 for (; !eviction_queue.IsEmpty(); eviction_queue.Pop()) { |
| 910 ++it) { | 461 Tile* tile = eviction_queue.Top(); |
| 911 Tile* tile = *it; | |
| 912 EXPECT_TRUE(tile); | 462 EXPECT_TRUE(tile); |
| 913 EXPECT_TRUE(tile->HasResources()); | 463 EXPECT_TRUE(tile->HasResources()); |
| 914 | 464 |
| 915 if (!last_tile) | 465 if (!last_tile) |
| 916 last_tile = tile; | 466 last_tile = tile; |
| 917 | 467 |
| 918 EXPECT_GE(last_tile->priority(ACTIVE_TREE).priority_bin, | 468 EXPECT_GE(last_tile->priority(ACTIVE_TREE).priority_bin, |
| 919 tile->priority(ACTIVE_TREE).priority_bin); | 469 tile->priority(ACTIVE_TREE).priority_bin); |
| 920 if (last_tile->priority(ACTIVE_TREE).priority_bin == | 470 if (last_tile->priority(ACTIVE_TREE).priority_bin == |
| 921 tile->priority(ACTIVE_TREE).priority_bin) { | 471 tile->priority(ACTIVE_TREE).priority_bin) { |
| 922 EXPECT_GE(last_tile->priority(ACTIVE_TREE).distance_to_visible, | 472 EXPECT_GE(last_tile->priority(ACTIVE_TREE).distance_to_visible, |
| 923 tile->priority(ACTIVE_TREE).distance_to_visible); | 473 tile->priority(ACTIVE_TREE).distance_to_visible); |
| 924 } | 474 } |
| 925 | 475 |
| 926 last_tile = tile; | 476 last_tile = tile; |
| 927 ++tile_count; | 477 ++tile_count; |
| 928 smoothness_tiles.insert(tile); | 478 smoothness_tiles.insert(tile); |
| 929 } | 479 } |
| 930 | 480 |
| 931 EXPECT_EQ(tile_count, smoothness_tiles.size()); | 481 EXPECT_EQ(tile_count, smoothness_tiles.size()); |
| 932 EXPECT_EQ(all_tiles, smoothness_tiles); | 482 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 933 | 483 |
| 934 std::set<Tile*> new_content_tiles; | 484 std::set<Tile*> new_content_tiles; |
| 935 last_tile = NULL; | 485 last_tile = NULL; |
| 936 // Here we expect to get increasing PENDING_TREE priority_bin. | 486 // Here we expect to get increasing PENDING_TREE priority_bin. |
| 937 for (TileManager::EvictionTileIterator it(tile_manager, | 487 eviction_queue.Reset(); |
| 938 NEW_CONTENT_TAKES_PRIORITY); | 488 host_impl_.BuildEvictionQueue(&eviction_queue, NEW_CONTENT_TAKES_PRIORITY); |
| 939 it; | 489 for (; !eviction_queue.IsEmpty(); eviction_queue.Pop()) { |
| 940 ++it) { | 490 Tile* tile = eviction_queue.Top(); |
| 941 Tile* tile = *it; | |
| 942 EXPECT_TRUE(tile); | 491 EXPECT_TRUE(tile); |
| 943 | 492 |
| 944 if (!last_tile) | 493 if (!last_tile) |
| 945 last_tile = tile; | 494 last_tile = tile; |
| 946 | 495 |
| 947 EXPECT_GE(last_tile->priority(PENDING_TREE).priority_bin, | 496 EXPECT_GE(last_tile->priority(PENDING_TREE).priority_bin, |
| 948 tile->priority(PENDING_TREE).priority_bin); | 497 tile->priority(PENDING_TREE).priority_bin); |
| 949 if (last_tile->priority(PENDING_TREE).priority_bin == | 498 if (last_tile->priority(PENDING_TREE).priority_bin == |
| 950 tile->priority(PENDING_TREE).priority_bin) { | 499 tile->priority(PENDING_TREE).priority_bin) { |
| 951 EXPECT_GE(last_tile->priority(PENDING_TREE).distance_to_visible, | 500 EXPECT_GE(last_tile->priority(PENDING_TREE).distance_to_visible, |
| 952 tile->priority(PENDING_TREE).distance_to_visible); | 501 tile->priority(PENDING_TREE).distance_to_visible); |
| 953 } | 502 } |
| 954 | 503 |
| 955 last_tile = tile; | 504 last_tile = tile; |
| 956 new_content_tiles.insert(tile); | 505 new_content_tiles.insert(tile); |
| 957 } | 506 } |
| 958 | 507 |
| 959 EXPECT_EQ(tile_count, new_content_tiles.size()); | 508 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 960 EXPECT_EQ(all_tiles, new_content_tiles); | 509 EXPECT_EQ(all_tiles, new_content_tiles); |
| 961 } | 510 } |
| 962 } // namespace | 511 } // namespace |
| 963 } // namespace cc | 512 } // namespace cc |
| OLD | NEW |