James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "cc/resources/eviction_tile_priority_queue.h" |
| 6 | #include "cc/resources/raster_tile_priority_queue.h" |
| 7 | #include "cc/resources/tile.h" |
| 8 | #include "cc/resources/tile_priority.h" |
| 9 | #include "cc/test/fake_impl_proxy.h" |
| 10 | #include "cc/test/fake_layer_tree_host_impl.h" |
| 11 | #include "cc/test/fake_output_surface.h" |
| 12 | #include "cc/test/fake_output_surface_client.h" |
| 13 | #include "cc/test/fake_picture_layer_impl.h" |
| 14 | #include "cc/test/fake_picture_pile_impl.h" |
| 15 | #include "cc/test/fake_tile_manager.h" |
| 16 | #include "cc/test/impl_side_painting_settings.h" |
| 17 | #include "cc/test/test_shared_bitmap_manager.h" |
| 18 | #include "cc/test/test_tile_priorities.h" |
| 19 | #include "cc/trees/layer_tree_impl.h" |
| 20 | #include "testing/gtest/include/gtest/gtest.h" |
| 21 | |
| 22 | namespace cc { |
| 23 | namespace { |
| 24 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 25 | class LowResTilingsSettings : public ImplSidePaintingSettings { |
| 26 | public: |
| 27 | LowResTilingsSettings() { create_low_res_tiling = true; } |
| 28 | }; |
| 29 | |
| 30 | class TileManagerTilePriorityQueueTest : public testing::Test { |
| 31 | public: |
| 32 | TileManagerTilePriorityQueueTest() |
| 33 | : memory_limit_policy_(ALLOW_ANYTHING), |
| 34 | max_tiles_(10000), |
| 35 | ready_to_activate_(false), |
| 36 | id_(7), |
| 37 | proxy_(base::MessageLoopProxy::current()), |
| 38 | host_impl_(LowResTilingsSettings(), &proxy_, &shared_bitmap_manager_) {} |
| 39 | |
| 40 | void SetTreePriority(TreePriority tree_priority) { |
| 41 | GlobalStateThatImpactsTilePriority state; |
| 42 | gfx::Size tile_size(256, 256); |
| 43 | |
| 44 | state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; |
| 45 | state.num_resources_limit = max_tiles_; |
| 46 | state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; |
| 47 | state.memory_limit_policy = memory_limit_policy_; |
| 48 | state.tree_priority = tree_priority; |
| 49 | |
| 50 | global_state_ = state; |
| 51 | host_impl_.resource_pool()->SetResourceUsageLimits( |
| 52 | state.soft_memory_limit_in_bytes, |
| 53 | state.soft_memory_limit_in_bytes, |
| 54 | state.num_resources_limit); |
| 55 | host_impl_.tile_manager()->SetGlobalStateForTesting(state); |
| 56 | } |
| 57 | |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 58 | void SetUp() override { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 59 | InitializeRenderer(); |
| 60 | SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |
| 61 | } |
| 62 | |
| 63 | virtual void InitializeRenderer() { |
| 64 | host_impl_.InitializeRenderer(FakeOutputSurface::Create3d()); |
| 65 | } |
| 66 | |
| 67 | void SetupDefaultTrees(const gfx::Size& layer_bounds) { |
| 68 | gfx::Size tile_size(100, 100); |
| 69 | |
| 70 | scoped_refptr<FakePicturePileImpl> pending_pile = |
| 71 | FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 72 | scoped_refptr<FakePicturePileImpl> active_pile = |
| 73 | FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 74 | |
| 75 | SetupTrees(pending_pile, active_pile); |
| 76 | } |
| 77 | |
| 78 | void ActivateTree() { |
| 79 | host_impl_.ActivateSyncTree(); |
| 80 | CHECK(!host_impl_.pending_tree()); |
| 81 | pending_layer_ = NULL; |
| 82 | active_layer_ = static_cast<FakePictureLayerImpl*>( |
| 83 | host_impl_.active_tree()->LayerById(id_)); |
| 84 | } |
| 85 | |
| 86 | void SetupDefaultTreesWithFixedTileSize(const gfx::Size& layer_bounds, |
| 87 | const gfx::Size& tile_size) { |
| 88 | SetupDefaultTrees(layer_bounds); |
| 89 | pending_layer_->set_fixed_tile_size(tile_size); |
| 90 | active_layer_->set_fixed_tile_size(tile_size); |
| 91 | } |
| 92 | |
| 93 | void SetupTrees(scoped_refptr<PicturePileImpl> pending_pile, |
| 94 | scoped_refptr<PicturePileImpl> active_pile) { |
| 95 | SetupPendingTree(active_pile); |
| 96 | ActivateTree(); |
| 97 | SetupPendingTree(pending_pile); |
| 98 | } |
| 99 | |
| 100 | void SetupPendingTree(scoped_refptr<PicturePileImpl> pile) { |
| 101 | host_impl_.CreatePendingTree(); |
| 102 | LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 103 | |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 104 | // Steal from the recycled tree. |
| 105 | scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree(); |
| 106 | DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_); |
| 107 | |
| 108 | scoped_ptr<FakePictureLayerImpl> pending_layer; |
| 109 | if (old_pending_root) { |
| 110 | pending_layer.reset( |
| 111 | static_cast<FakePictureLayerImpl*>(old_pending_root.release())); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 112 | pending_layer->SetRasterSource(pile); |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 113 | } else { |
| 114 | pending_layer = |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 115 | FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_, pile); |
James Robinson | 53b7758 | 2014-10-28 17:00:48 -0700 | [diff] [blame] | 116 | pending_layer->SetDrawsContent(true); |
| 117 | } |
| 118 | // The bounds() just mirror the pile size. |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 119 | pending_layer->SetBounds(pending_layer->raster_source()->GetSize()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 120 | pending_tree->SetRootLayer(pending_layer.Pass()); |
| 121 | |
| 122 | pending_layer_ = static_cast<FakePictureLayerImpl*>( |
| 123 | host_impl_.pending_tree()->LayerById(id_)); |
| 124 | pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 125 | } |
| 126 | |
| 127 | void CreateHighLowResAndSetAllTilesVisible() { |
| 128 | // Active layer must get updated first so pending layer can share from it. |
| 129 | active_layer_->CreateDefaultTilingsAndTiles(); |
| 130 | active_layer_->SetAllTilesVisible(); |
| 131 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 132 | pending_layer_->SetAllTilesVisible(); |
| 133 | } |
| 134 | |
| 135 | TileManager* tile_manager() { return host_impl_.tile_manager(); } |
| 136 | |
| 137 | protected: |
| 138 | GlobalStateThatImpactsTilePriority global_state_; |
| 139 | |
| 140 | TestSharedBitmapManager shared_bitmap_manager_; |
| 141 | TileMemoryLimitPolicy memory_limit_policy_; |
| 142 | int max_tiles_; |
| 143 | bool ready_to_activate_; |
| 144 | int id_; |
| 145 | FakeImplProxy proxy_; |
| 146 | FakeLayerTreeHostImpl host_impl_; |
| 147 | FakePictureLayerImpl* pending_layer_; |
| 148 | FakePictureLayerImpl* active_layer_; |
| 149 | }; |
| 150 | |
| 151 | TEST_F(TileManagerTilePriorityQueueTest, RasterTilePriorityQueue) { |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame^] | 152 | const gfx::Size layer_bounds(1000, 1000); |
| 153 | host_impl_.SetViewportSize(layer_bounds); |
| 154 | SetupDefaultTrees(layer_bounds); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 155 | |
| 156 | active_layer_->CreateDefaultTilingsAndTiles(); |
| 157 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 158 | |
| 159 | RasterTilePriorityQueue queue; |
| 160 | host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 161 | EXPECT_FALSE(queue.IsEmpty()); |
| 162 | |
| 163 | size_t tile_count = 0; |
| 164 | std::set<Tile*> all_tiles; |
| 165 | while (!queue.IsEmpty()) { |
| 166 | EXPECT_TRUE(queue.Top()); |
| 167 | all_tiles.insert(queue.Top()); |
| 168 | ++tile_count; |
| 169 | queue.Pop(); |
| 170 | } |
| 171 | |
| 172 | EXPECT_EQ(tile_count, all_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 173 | EXPECT_EQ(16u, tile_count); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 174 | |
| 175 | // Sanity check, all tiles should be visible. |
| 176 | std::set<Tile*> smoothness_tiles; |
| 177 | queue.Reset(); |
| 178 | host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 179 | bool had_low_res = false; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 180 | while (!queue.IsEmpty()) { |
| 181 | Tile* tile = queue.Top(); |
| 182 | EXPECT_TRUE(tile); |
| 183 | EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); |
| 184 | EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 185 | if (tile->priority(ACTIVE_TREE).resolution == LOW_RESOLUTION) |
| 186 | had_low_res = true; |
| 187 | else |
| 188 | smoothness_tiles.insert(tile); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 189 | queue.Pop(); |
| 190 | } |
| 191 | EXPECT_EQ(all_tiles, smoothness_tiles); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 192 | EXPECT_TRUE(had_low_res); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 193 | |
| 194 | Region invalidation(gfx::Rect(0, 0, 500, 500)); |
| 195 | |
| 196 | // Invalidate the pending tree. |
| 197 | pending_layer_->set_invalidation(invalidation); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 198 | pending_layer_->HighResTiling()->UpdateTilesToCurrentRasterSource( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 199 | pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 200 | pending_layer_->LowResTiling()->UpdateTilesToCurrentRasterSource( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 201 | pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 202 | |
| 203 | active_layer_->ResetAllTilesPriorities(); |
| 204 | pending_layer_->ResetAllTilesPriorities(); |
| 205 | |
| 206 | // Renew all of the tile priorities. |
| 207 | gfx::Rect viewport(50, 50, 100, 100); |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 208 | pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 209 | Occlusion()); |
| 210 | pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 211 | Occlusion()); |
| 212 | active_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 213 | Occlusion()); |
| 214 | active_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 215 | Occlusion()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 216 | |
| 217 | // Populate all tiles directly from the tilings. |
| 218 | all_tiles.clear(); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 219 | std::set<Tile*> high_res_tiles; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 220 | std::vector<Tile*> pending_high_res_tiles = |
| 221 | pending_layer_->HighResTiling()->AllTilesForTesting(); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 222 | for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 223 | all_tiles.insert(pending_high_res_tiles[i]); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 224 | high_res_tiles.insert(pending_high_res_tiles[i]); |
| 225 | } |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 226 | |
| 227 | std::vector<Tile*> pending_low_res_tiles = |
| 228 | pending_layer_->LowResTiling()->AllTilesForTesting(); |
| 229 | for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) |
| 230 | all_tiles.insert(pending_low_res_tiles[i]); |
| 231 | |
| 232 | std::vector<Tile*> active_high_res_tiles = |
| 233 | active_layer_->HighResTiling()->AllTilesForTesting(); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 234 | for (size_t i = 0; i < active_high_res_tiles.size(); ++i) { |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 235 | all_tiles.insert(active_high_res_tiles[i]); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 236 | high_res_tiles.insert(active_high_res_tiles[i]); |
| 237 | } |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 238 | |
| 239 | std::vector<Tile*> active_low_res_tiles = |
| 240 | active_layer_->LowResTiling()->AllTilesForTesting(); |
| 241 | for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
| 242 | all_tiles.insert(active_low_res_tiles[i]); |
| 243 | |
| 244 | Tile* last_tile = NULL; |
| 245 | smoothness_tiles.clear(); |
| 246 | tile_count = 0; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 247 | size_t correct_order_tiles = 0u; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 248 | // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 249 | queue.Reset(); |
| 250 | host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 251 | while (!queue.IsEmpty()) { |
| 252 | Tile* tile = queue.Top(); |
| 253 | EXPECT_TRUE(tile); |
| 254 | |
| 255 | if (!last_tile) |
| 256 | last_tile = tile; |
| 257 | |
| 258 | EXPECT_LE(last_tile->priority(ACTIVE_TREE).priority_bin, |
| 259 | tile->priority(ACTIVE_TREE).priority_bin); |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 260 | bool skip_updating_last_tile = false; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 261 | if (last_tile->priority(ACTIVE_TREE).priority_bin == |
| 262 | tile->priority(ACTIVE_TREE).priority_bin) { |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 263 | correct_order_tiles += |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 264 | last_tile->priority(ACTIVE_TREE).distance_to_visible <= |
| 265 | tile->priority(ACTIVE_TREE).distance_to_visible; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 266 | } else if (tile->priority(ACTIVE_TREE).priority_bin == |
| 267 | TilePriority::EVENTUALLY && |
| 268 | tile->priority(PENDING_TREE).priority_bin == TilePriority::NOW) { |
| 269 | // Since we'd return pending tree now tiles before the eventually tiles on |
| 270 | // the active tree, update the value. |
| 271 | ++correct_order_tiles; |
| 272 | skip_updating_last_tile = true; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | if (tile->priority(ACTIVE_TREE).priority_bin == TilePriority::NOW && |
| 276 | last_tile->priority(ACTIVE_TREE).resolution != |
| 277 | tile->priority(ACTIVE_TREE).resolution) { |
| 278 | // Low resolution should come first. |
| 279 | EXPECT_EQ(LOW_RESOLUTION, last_tile->priority(ACTIVE_TREE).resolution); |
| 280 | } |
| 281 | |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 282 | if (!skip_updating_last_tile) |
| 283 | last_tile = tile; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 284 | ++tile_count; |
| 285 | smoothness_tiles.insert(tile); |
| 286 | queue.Pop(); |
| 287 | } |
| 288 | |
| 289 | EXPECT_EQ(tile_count, smoothness_tiles.size()); |
| 290 | EXPECT_EQ(all_tiles, smoothness_tiles); |
| 291 | // Since we don't guarantee increasing distance due to spiral iterator, we |
| 292 | // should check that we're _mostly_ right. |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 293 | EXPECT_GT(correct_order_tiles, 3 * tile_count / 4); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 294 | |
| 295 | std::set<Tile*> new_content_tiles; |
| 296 | last_tile = NULL; |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 297 | size_t increasing_distance_tiles = 0u; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 298 | // Here we expect to get increasing PENDING_TREE priority_bin. |
| 299 | queue.Reset(); |
| 300 | host_impl_.BuildRasterQueue(&queue, NEW_CONTENT_TAKES_PRIORITY); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 301 | tile_count = 0; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 302 | while (!queue.IsEmpty()) { |
| 303 | Tile* tile = queue.Top(); |
| 304 | EXPECT_TRUE(tile); |
| 305 | |
| 306 | if (!last_tile) |
| 307 | last_tile = tile; |
| 308 | |
| 309 | EXPECT_LE(last_tile->priority(PENDING_TREE).priority_bin, |
| 310 | tile->priority(PENDING_TREE).priority_bin); |
| 311 | if (last_tile->priority(PENDING_TREE).priority_bin == |
| 312 | tile->priority(PENDING_TREE).priority_bin) { |
| 313 | increasing_distance_tiles += |
| 314 | last_tile->priority(PENDING_TREE).distance_to_visible <= |
| 315 | tile->priority(PENDING_TREE).distance_to_visible; |
| 316 | } |
| 317 | |
| 318 | if (tile->priority(PENDING_TREE).priority_bin == TilePriority::NOW && |
| 319 | last_tile->priority(PENDING_TREE).resolution != |
| 320 | tile->priority(PENDING_TREE).resolution) { |
| 321 | // High resolution should come first. |
| 322 | EXPECT_EQ(HIGH_RESOLUTION, last_tile->priority(PENDING_TREE).resolution); |
| 323 | } |
| 324 | |
| 325 | last_tile = tile; |
| 326 | new_content_tiles.insert(tile); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 327 | ++tile_count; |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 328 | queue.Pop(); |
| 329 | } |
| 330 | |
| 331 | EXPECT_EQ(tile_count, new_content_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 332 | EXPECT_EQ(high_res_tiles, new_content_tiles); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 333 | // Since we don't guarantee increasing distance due to spiral iterator, we |
| 334 | // should check that we're _mostly_ right. |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 335 | EXPECT_GE(increasing_distance_tiles, 3 * tile_count / 4); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 336 | } |
| 337 | |
James Robinson | 30d547e | 2014-10-23 18:20:06 -0700 | [diff] [blame] | 338 | TEST_F(TileManagerTilePriorityQueueTest, ActivationComesBeforeEventually) { |
| 339 | SetupDefaultTrees(gfx::Size(1000, 1000)); |
| 340 | |
| 341 | active_layer_->CreateDefaultTilingsAndTiles(); |
| 342 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 343 | |
| 344 | // Create a pending child layer. |
| 345 | gfx::Size tile_size(256, 256); |
| 346 | scoped_refptr<FakePicturePileImpl> pending_pile = |
| 347 | FakePicturePileImpl::CreateFilledPile(tile_size, gfx::Size(1000, 1000)); |
| 348 | scoped_ptr<FakePictureLayerImpl> pending_child = |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 349 | FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), |
| 350 | id_ + 1, pending_pile); |
James Robinson | 30d547e | 2014-10-23 18:20:06 -0700 | [diff] [blame] | 351 | pending_layer_->AddChild(pending_child.Pass()); |
| 352 | FakePictureLayerImpl* pending_child_raw = static_cast<FakePictureLayerImpl*>( |
| 353 | host_impl_.pending_tree()->LayerById(id_ + 1)); |
| 354 | ASSERT_TRUE(pending_child_raw); |
| 355 | |
| 356 | pending_child_raw->SetDrawsContent(true); |
| 357 | pending_child_raw->DoPostCommitInitializationIfNeeded(); |
| 358 | pending_child_raw->CreateDefaultTilingsAndTiles(); |
| 359 | ASSERT_TRUE(pending_child_raw->HighResTiling()); |
| 360 | |
| 361 | // Set a small viewport, so we have soon and eventually tiles. |
| 362 | gfx::Rect viewport(200, 200); |
| 363 | active_layer_->draw_properties().visible_content_rect = viewport; |
| 364 | active_layer_->UpdateTiles(Occlusion(), false); |
| 365 | pending_layer_->draw_properties().visible_content_rect = viewport; |
| 366 | pending_layer_->UpdateTiles(Occlusion(), false); |
| 367 | pending_child_raw->draw_properties().visible_content_rect = viewport; |
| 368 | pending_child_raw->UpdateTiles(Occlusion(), false); |
| 369 | |
| 370 | RasterTilePriorityQueue queue; |
| 371 | host_impl_.SetRequiresHighResToDraw(); |
| 372 | host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 373 | EXPECT_FALSE(queue.IsEmpty()); |
| 374 | |
| 375 | // Get all the tiles that are NOW or SOON and make sure they are ready to |
| 376 | // draw. |
| 377 | std::vector<Tile*> all_tiles; |
| 378 | while (!queue.IsEmpty()) { |
| 379 | Tile* tile = queue.Top(); |
| 380 | if (tile->combined_priority().priority_bin >= TilePriority::EVENTUALLY) |
| 381 | break; |
| 382 | |
| 383 | all_tiles.push_back(tile); |
| 384 | queue.Pop(); |
| 385 | } |
| 386 | |
| 387 | tile_manager()->InitializeTilesWithResourcesForTesting( |
| 388 | std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 389 | |
| 390 | // Ensure we can activate. |
| 391 | EXPECT_TRUE(pending_layer_->AllTilesRequiredForActivationAreReadyToDraw()); |
| 392 | EXPECT_TRUE(pending_child_raw->AllTilesRequiredForActivationAreReadyToDraw()); |
| 393 | } |
| 394 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 395 | TEST_F(TileManagerTilePriorityQueueTest, EvictionTilePriorityQueue) { |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame^] | 396 | const gfx::Size layer_bounds(1000, 1000); |
| 397 | host_impl_.SetViewportSize(layer_bounds); |
| 398 | SetupDefaultTrees(layer_bounds); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 399 | |
| 400 | active_layer_->CreateDefaultTilingsAndTiles(); |
| 401 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 402 | |
| 403 | EvictionTilePriorityQueue empty_queue; |
| 404 | host_impl_.BuildEvictionQueue(&empty_queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 405 | EXPECT_TRUE(empty_queue.IsEmpty()); |
| 406 | std::set<Tile*> all_tiles; |
| 407 | size_t tile_count = 0; |
| 408 | |
| 409 | RasterTilePriorityQueue raster_queue; |
| 410 | host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 411 | while (!raster_queue.IsEmpty()) { |
| 412 | ++tile_count; |
| 413 | EXPECT_TRUE(raster_queue.Top()); |
| 414 | all_tiles.insert(raster_queue.Top()); |
| 415 | raster_queue.Pop(); |
| 416 | } |
| 417 | |
| 418 | EXPECT_EQ(tile_count, all_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 419 | EXPECT_EQ(16u, tile_count); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 420 | |
| 421 | tile_manager()->InitializeTilesWithResourcesForTesting( |
| 422 | std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 423 | |
| 424 | EvictionTilePriorityQueue queue; |
| 425 | host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 426 | EXPECT_FALSE(queue.IsEmpty()); |
| 427 | |
| 428 | // Sanity check, all tiles should be visible. |
| 429 | std::set<Tile*> smoothness_tiles; |
| 430 | while (!queue.IsEmpty()) { |
| 431 | Tile* tile = queue.Top(); |
| 432 | EXPECT_TRUE(tile); |
| 433 | EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); |
| 434 | EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); |
| 435 | EXPECT_TRUE(tile->HasResources()); |
| 436 | smoothness_tiles.insert(tile); |
| 437 | queue.Pop(); |
| 438 | } |
| 439 | EXPECT_EQ(all_tiles, smoothness_tiles); |
| 440 | |
| 441 | tile_manager()->ReleaseTileResourcesForTesting( |
| 442 | std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 443 | |
| 444 | Region invalidation(gfx::Rect(0, 0, 500, 500)); |
| 445 | |
| 446 | // Invalidate the pending tree. |
| 447 | pending_layer_->set_invalidation(invalidation); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 448 | pending_layer_->HighResTiling()->UpdateTilesToCurrentRasterSource( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 449 | pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 450 | pending_layer_->LowResTiling()->UpdateTilesToCurrentRasterSource( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 451 | pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 452 | |
| 453 | active_layer_->ResetAllTilesPriorities(); |
| 454 | pending_layer_->ResetAllTilesPriorities(); |
| 455 | |
| 456 | // Renew all of the tile priorities. |
| 457 | gfx::Rect viewport(50, 50, 100, 100); |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 458 | pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 459 | Occlusion()); |
| 460 | pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 461 | Occlusion()); |
| 462 | active_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 463 | Occlusion()); |
| 464 | active_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 465 | Occlusion()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 466 | |
| 467 | // Populate all tiles directly from the tilings. |
| 468 | all_tiles.clear(); |
| 469 | std::vector<Tile*> pending_high_res_tiles = |
| 470 | pending_layer_->HighResTiling()->AllTilesForTesting(); |
| 471 | for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) |
| 472 | all_tiles.insert(pending_high_res_tiles[i]); |
| 473 | |
| 474 | std::vector<Tile*> pending_low_res_tiles = |
| 475 | pending_layer_->LowResTiling()->AllTilesForTesting(); |
| 476 | for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) |
| 477 | all_tiles.insert(pending_low_res_tiles[i]); |
| 478 | |
| 479 | std::vector<Tile*> active_high_res_tiles = |
| 480 | active_layer_->HighResTiling()->AllTilesForTesting(); |
| 481 | for (size_t i = 0; i < active_high_res_tiles.size(); ++i) |
| 482 | all_tiles.insert(active_high_res_tiles[i]); |
| 483 | |
| 484 | std::vector<Tile*> active_low_res_tiles = |
| 485 | active_layer_->LowResTiling()->AllTilesForTesting(); |
| 486 | for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
| 487 | all_tiles.insert(active_low_res_tiles[i]); |
| 488 | |
| 489 | tile_manager()->InitializeTilesWithResourcesForTesting( |
| 490 | std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 491 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 492 | Tile* last_tile = NULL; |
| 493 | smoothness_tiles.clear(); |
| 494 | tile_count = 0; |
| 495 | // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 496 | queue.Reset(); |
| 497 | host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 498 | while (!queue.IsEmpty()) { |
| 499 | Tile* tile = queue.Top(); |
| 500 | EXPECT_TRUE(tile); |
| 501 | EXPECT_TRUE(tile->HasResources()); |
| 502 | |
| 503 | if (!last_tile) |
| 504 | last_tile = tile; |
| 505 | |
| 506 | EXPECT_GE(last_tile->priority(ACTIVE_TREE).priority_bin, |
| 507 | tile->priority(ACTIVE_TREE).priority_bin); |
| 508 | if (last_tile->priority(ACTIVE_TREE).priority_bin == |
| 509 | tile->priority(ACTIVE_TREE).priority_bin) { |
| 510 | EXPECT_LE(last_tile->required_for_activation(), |
| 511 | tile->required_for_activation()); |
| 512 | if (last_tile->required_for_activation() == |
| 513 | tile->required_for_activation()) { |
| 514 | EXPECT_GE(last_tile->priority(ACTIVE_TREE).distance_to_visible, |
| 515 | tile->priority(ACTIVE_TREE).distance_to_visible); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | last_tile = tile; |
| 520 | ++tile_count; |
| 521 | smoothness_tiles.insert(tile); |
| 522 | queue.Pop(); |
| 523 | } |
| 524 | |
| 525 | EXPECT_EQ(tile_count, smoothness_tiles.size()); |
| 526 | EXPECT_EQ(all_tiles, smoothness_tiles); |
| 527 | |
| 528 | std::set<Tile*> new_content_tiles; |
| 529 | last_tile = NULL; |
| 530 | // Here we expect to get increasing PENDING_TREE priority_bin. |
| 531 | queue.Reset(); |
| 532 | host_impl_.BuildEvictionQueue(&queue, NEW_CONTENT_TAKES_PRIORITY); |
| 533 | while (!queue.IsEmpty()) { |
| 534 | Tile* tile = queue.Top(); |
| 535 | EXPECT_TRUE(tile); |
| 536 | |
| 537 | if (!last_tile) |
| 538 | last_tile = tile; |
| 539 | |
| 540 | EXPECT_GE(last_tile->priority(PENDING_TREE).priority_bin, |
| 541 | tile->priority(PENDING_TREE).priority_bin); |
| 542 | if (last_tile->priority(PENDING_TREE).priority_bin == |
| 543 | tile->priority(PENDING_TREE).priority_bin) { |
| 544 | EXPECT_LE(last_tile->required_for_activation(), |
| 545 | tile->required_for_activation()); |
| 546 | if (last_tile->required_for_activation() == |
| 547 | tile->required_for_activation()) { |
| 548 | EXPECT_GE(last_tile->priority(PENDING_TREE).distance_to_visible, |
| 549 | tile->priority(PENDING_TREE).distance_to_visible); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | last_tile = tile; |
| 554 | new_content_tiles.insert(tile); |
| 555 | queue.Pop(); |
| 556 | } |
| 557 | |
| 558 | EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 559 | EXPECT_EQ(all_tiles, new_content_tiles); |
| 560 | } |
| 561 | |
| 562 | TEST_F(TileManagerTilePriorityQueueTest, |
| 563 | EvictionTilePriorityQueueWithOcclusion) { |
| 564 | gfx::Size tile_size(102, 102); |
| 565 | gfx::Size layer_bounds(1000, 1000); |
| 566 | |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame^] | 567 | host_impl_.SetViewportSize(layer_bounds); |
| 568 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 569 | scoped_refptr<FakePicturePileImpl> pending_pile = |
| 570 | FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 571 | SetupPendingTree(pending_pile); |
| 572 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 573 | |
| 574 | scoped_ptr<FakePictureLayerImpl> pending_child = |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 575 | FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 2, |
| 576 | pending_pile); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 577 | pending_layer_->AddChild(pending_child.Pass()); |
| 578 | |
| 579 | FakePictureLayerImpl* pending_child_layer = |
| 580 | static_cast<FakePictureLayerImpl*>(pending_layer_->children()[0]); |
| 581 | pending_child_layer->SetDrawsContent(true); |
| 582 | pending_child_layer->DoPostCommitInitializationIfNeeded(); |
| 583 | pending_child_layer->CreateDefaultTilingsAndTiles(); |
| 584 | |
| 585 | std::set<Tile*> all_tiles; |
| 586 | size_t tile_count = 0; |
| 587 | RasterTilePriorityQueue raster_queue; |
| 588 | host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 589 | while (!raster_queue.IsEmpty()) { |
| 590 | ++tile_count; |
| 591 | EXPECT_TRUE(raster_queue.Top()); |
| 592 | all_tiles.insert(raster_queue.Top()); |
| 593 | raster_queue.Pop(); |
| 594 | } |
| 595 | EXPECT_EQ(tile_count, all_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 596 | EXPECT_EQ(32u, tile_count); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 597 | |
| 598 | pending_layer_->ResetAllTilesPriorities(); |
| 599 | |
| 600 | // Renew all of the tile priorities. |
| 601 | gfx::Rect viewport(layer_bounds); |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 602 | pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 603 | Occlusion()); |
| 604 | pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 605 | Occlusion()); |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 606 | pending_child_layer->HighResTiling()->ComputeTilePriorityRects( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 607 | viewport, 1.0f, 1.0, Occlusion()); |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 608 | pending_child_layer->LowResTiling()->ComputeTilePriorityRects( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 609 | viewport, 1.0f, 1.0, Occlusion()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 610 | |
| 611 | // Populate all tiles directly from the tilings. |
| 612 | all_tiles.clear(); |
| 613 | std::vector<Tile*> pending_high_res_tiles = |
| 614 | pending_layer_->HighResTiling()->AllTilesForTesting(); |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 615 | all_tiles.insert(pending_high_res_tiles.begin(), |
| 616 | pending_high_res_tiles.end()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 617 | |
| 618 | std::vector<Tile*> pending_low_res_tiles = |
| 619 | pending_layer_->LowResTiling()->AllTilesForTesting(); |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 620 | all_tiles.insert(pending_low_res_tiles.begin(), pending_low_res_tiles.end()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 621 | |
| 622 | // Set all tiles on the pending_child_layer as occluded on the pending tree. |
| 623 | std::vector<Tile*> pending_child_high_res_tiles = |
| 624 | pending_child_layer->HighResTiling()->AllTilesForTesting(); |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 625 | pending_child_layer->HighResTiling()->SetAllTilesOccludedForTesting(); |
| 626 | all_tiles.insert(pending_child_high_res_tiles.begin(), |
| 627 | pending_child_high_res_tiles.end()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 628 | |
| 629 | std::vector<Tile*> pending_child_low_res_tiles = |
| 630 | pending_child_layer->LowResTiling()->AllTilesForTesting(); |
James Robinson | e2ac7e8 | 2014-10-15 13:21:59 -0700 | [diff] [blame] | 631 | pending_child_layer->LowResTiling()->SetAllTilesOccludedForTesting(); |
| 632 | all_tiles.insert(pending_child_low_res_tiles.begin(), |
| 633 | pending_child_low_res_tiles.end()); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 634 | |
| 635 | tile_manager()->InitializeTilesWithResourcesForTesting( |
| 636 | std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 637 | |
| 638 | // Verify occlusion is considered by EvictionTilePriorityQueue. |
| 639 | TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; |
| 640 | size_t occluded_count = 0u; |
| 641 | Tile* last_tile = NULL; |
| 642 | EvictionTilePriorityQueue queue; |
| 643 | host_impl_.BuildEvictionQueue(&queue, tree_priority); |
| 644 | while (!queue.IsEmpty()) { |
| 645 | Tile* tile = queue.Top(); |
| 646 | if (!last_tile) |
| 647 | last_tile = tile; |
| 648 | |
| 649 | bool tile_is_occluded = tile->is_occluded_for_tree_priority(tree_priority); |
| 650 | |
| 651 | // The only way we will encounter an occluded tile after an unoccluded |
| 652 | // tile is if the priorty bin decreased, the tile is required for |
| 653 | // activation, or the scale changed. |
| 654 | if (tile_is_occluded) { |
| 655 | occluded_count++; |
| 656 | |
| 657 | bool last_tile_is_occluded = |
| 658 | last_tile->is_occluded_for_tree_priority(tree_priority); |
| 659 | if (!last_tile_is_occluded) { |
| 660 | TilePriority::PriorityBin tile_priority_bin = |
| 661 | tile->priority_for_tree_priority(tree_priority).priority_bin; |
| 662 | TilePriority::PriorityBin last_tile_priority_bin = |
| 663 | last_tile->priority_for_tree_priority(tree_priority).priority_bin; |
| 664 | |
| 665 | EXPECT_TRUE((tile_priority_bin < last_tile_priority_bin) || |
| 666 | tile->required_for_activation() || |
| 667 | (tile->contents_scale() != last_tile->contents_scale())); |
| 668 | } |
| 669 | } |
| 670 | last_tile = tile; |
| 671 | queue.Pop(); |
| 672 | } |
| 673 | size_t expected_occluded_count = |
| 674 | pending_child_high_res_tiles.size() + pending_child_low_res_tiles.size(); |
| 675 | EXPECT_EQ(expected_occluded_count, occluded_count); |
| 676 | } |
| 677 | |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 678 | TEST_F(TileManagerTilePriorityQueueTest, |
| 679 | EvictionTilePriorityQueueWithTransparentLayer) { |
| 680 | gfx::Size tile_size(102, 102); |
| 681 | gfx::Size layer_bounds(1000, 1000); |
| 682 | |
| 683 | scoped_refptr<FakePicturePileImpl> pending_pile = |
| 684 | FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 685 | SetupPendingTree(pending_pile); |
| 686 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 687 | |
| 688 | scoped_ptr<FakePictureLayerImpl> pending_child = |
| 689 | FakePictureLayerImpl::CreateWithRasterSource(host_impl_.pending_tree(), 2, |
| 690 | pending_pile); |
| 691 | pending_layer_->AddChild(pending_child.Pass()); |
| 692 | |
| 693 | // Create a fully transparent child layer so that its tile priorities are not |
| 694 | // considered to be valid. |
| 695 | FakePictureLayerImpl* pending_child_layer = |
| 696 | static_cast<FakePictureLayerImpl*>(pending_layer_->children()[0]); |
| 697 | pending_child_layer->SetDrawsContent(true); |
| 698 | pending_child_layer->CreateDefaultTilingsAndTiles(); |
| 699 | pending_child_layer->SetOpacity(0.0); |
| 700 | pending_child_layer->layer_tree_impl()->UpdateDrawProperties(); |
| 701 | pending_child_layer->DoPostCommitInitializationIfNeeded(); |
| 702 | |
| 703 | // Renew all of the tile priorities. |
| 704 | gfx::Rect viewport(layer_bounds); |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 705 | pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 706 | Occlusion()); |
| 707 | pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 708 | Occlusion()); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 709 | pending_child_layer->HighResTiling()->ComputeTilePriorityRects( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 710 | viewport, 1.0f, 1.0, Occlusion()); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 711 | pending_child_layer->LowResTiling()->ComputeTilePriorityRects( |
Benjamin Lerman | 5799890 | 2014-11-18 16:06:02 +0100 | [diff] [blame] | 712 | viewport, 1.0f, 1.0, Occlusion()); |
James Robinson | 6e9a1c9 | 2014-11-13 17:05:42 -0800 | [diff] [blame] | 713 | |
| 714 | // Populate all tiles directly from the tilings. |
| 715 | std::set<Tile*> all_pending_tiles; |
| 716 | std::vector<Tile*> pending_high_res_tiles = |
| 717 | pending_layer_->HighResTiling()->AllTilesForTesting(); |
| 718 | all_pending_tiles.insert(pending_high_res_tiles.begin(), |
| 719 | pending_high_res_tiles.end()); |
| 720 | EXPECT_EQ(16u, pending_high_res_tiles.size()); |
| 721 | |
| 722 | std::vector<Tile*> pending_low_res_tiles = |
| 723 | pending_layer_->LowResTiling()->AllTilesForTesting(); |
| 724 | all_pending_tiles.insert(pending_low_res_tiles.begin(), |
| 725 | pending_low_res_tiles.end()); |
| 726 | EXPECT_EQ(1u, pending_low_res_tiles.size()); |
| 727 | |
| 728 | std::set<Tile*> all_pending_child_tiles; |
| 729 | std::vector<Tile*> pending_child_high_res_tiles = |
| 730 | pending_child_layer->HighResTiling()->AllTilesForTesting(); |
| 731 | all_pending_child_tiles.insert(pending_child_high_res_tiles.begin(), |
| 732 | pending_child_high_res_tiles.end()); |
| 733 | EXPECT_EQ(16u, pending_child_high_res_tiles.size()); |
| 734 | |
| 735 | std::vector<Tile*> pending_child_low_res_tiles = |
| 736 | pending_child_layer->LowResTiling()->AllTilesForTesting(); |
| 737 | all_pending_child_tiles.insert(pending_child_low_res_tiles.begin(), |
| 738 | pending_child_low_res_tiles.end()); |
| 739 | EXPECT_EQ(1u, pending_child_low_res_tiles.size()); |
| 740 | |
| 741 | std::set<Tile*> all_tiles = all_pending_tiles; |
| 742 | all_tiles.insert(all_pending_child_tiles.begin(), |
| 743 | all_pending_child_tiles.end()); |
| 744 | |
| 745 | tile_manager()->InitializeTilesWithResourcesForTesting( |
| 746 | std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 747 | |
| 748 | EXPECT_TRUE(pending_layer_->HasValidTilePriorities()); |
| 749 | EXPECT_FALSE(pending_child_layer->HasValidTilePriorities()); |
| 750 | |
| 751 | // Verify that eviction queue returns tiles also from layers without valid |
| 752 | // tile priorities and that the tile priority bin of those tiles is (at most) |
| 753 | // EVENTUALLY. |
| 754 | TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; |
| 755 | std::set<Tile*> new_content_tiles; |
| 756 | size_t tile_count = 0; |
| 757 | EvictionTilePriorityQueue queue; |
| 758 | host_impl_.BuildEvictionQueue(&queue, tree_priority); |
| 759 | while (!queue.IsEmpty()) { |
| 760 | Tile* tile = queue.Top(); |
| 761 | const TilePriority& pending_priority = tile->priority(PENDING_TREE); |
| 762 | EXPECT_NE(std::numeric_limits<float>::infinity(), |
| 763 | pending_priority.distance_to_visible); |
| 764 | if (all_pending_child_tiles.find(tile) != all_pending_child_tiles.end()) |
| 765 | EXPECT_EQ(TilePriority::EVENTUALLY, pending_priority.priority_bin); |
| 766 | else |
| 767 | EXPECT_EQ(TilePriority::NOW, pending_priority.priority_bin); |
| 768 | new_content_tiles.insert(tile); |
| 769 | ++tile_count; |
| 770 | queue.Pop(); |
| 771 | } |
| 772 | EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 773 | EXPECT_EQ(all_tiles, new_content_tiles); |
| 774 | } |
| 775 | |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 776 | TEST_F(TileManagerTilePriorityQueueTest, RasterTilePriorityQueueEmptyLayers) { |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame^] | 777 | const gfx::Size layer_bounds(1000, 1000); |
| 778 | host_impl_.SetViewportSize(layer_bounds); |
| 779 | SetupDefaultTrees(layer_bounds); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 780 | |
| 781 | active_layer_->CreateDefaultTilingsAndTiles(); |
| 782 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 783 | |
| 784 | RasterTilePriorityQueue queue; |
| 785 | host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 786 | EXPECT_FALSE(queue.IsEmpty()); |
| 787 | |
| 788 | size_t tile_count = 0; |
| 789 | std::set<Tile*> all_tiles; |
| 790 | while (!queue.IsEmpty()) { |
| 791 | EXPECT_TRUE(queue.Top()); |
| 792 | all_tiles.insert(queue.Top()); |
| 793 | ++tile_count; |
| 794 | queue.Pop(); |
| 795 | } |
| 796 | |
| 797 | EXPECT_EQ(tile_count, all_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 798 | EXPECT_EQ(16u, tile_count); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 799 | |
| 800 | queue.Reset(); |
| 801 | for (int i = 1; i < 10; ++i) { |
| 802 | scoped_ptr<FakePictureLayerImpl> pending_layer = |
| 803 | FakePictureLayerImpl::Create(host_impl_.pending_tree(), id_ + i); |
| 804 | pending_layer->SetDrawsContent(true); |
| 805 | pending_layer->DoPostCommitInitializationIfNeeded(); |
| 806 | pending_layer->set_has_valid_tile_priorities(true); |
| 807 | pending_layer_->AddChild(pending_layer.Pass()); |
| 808 | } |
| 809 | |
| 810 | host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 811 | EXPECT_FALSE(queue.IsEmpty()); |
| 812 | |
| 813 | tile_count = 0; |
| 814 | all_tiles.clear(); |
| 815 | while (!queue.IsEmpty()) { |
| 816 | EXPECT_TRUE(queue.Top()); |
| 817 | all_tiles.insert(queue.Top()); |
| 818 | ++tile_count; |
| 819 | queue.Pop(); |
| 820 | } |
| 821 | EXPECT_EQ(tile_count, all_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 822 | EXPECT_EQ(16u, tile_count); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | TEST_F(TileManagerTilePriorityQueueTest, EvictionTilePriorityQueueEmptyLayers) { |
James Robinson | 6a64b81 | 2014-12-03 13:38:42 -0800 | [diff] [blame^] | 826 | const gfx::Size layer_bounds(1000, 1000); |
| 827 | host_impl_.SetViewportSize(layer_bounds); |
| 828 | SetupDefaultTrees(layer_bounds); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 829 | |
| 830 | active_layer_->CreateDefaultTilingsAndTiles(); |
| 831 | pending_layer_->CreateDefaultTilingsAndTiles(); |
| 832 | |
| 833 | RasterTilePriorityQueue raster_queue; |
| 834 | host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 835 | EXPECT_FALSE(raster_queue.IsEmpty()); |
| 836 | |
| 837 | size_t tile_count = 0; |
| 838 | std::set<Tile*> all_tiles; |
| 839 | while (!raster_queue.IsEmpty()) { |
| 840 | EXPECT_TRUE(raster_queue.Top()); |
| 841 | all_tiles.insert(raster_queue.Top()); |
| 842 | ++tile_count; |
| 843 | raster_queue.Pop(); |
| 844 | } |
| 845 | EXPECT_EQ(tile_count, all_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 846 | EXPECT_EQ(16u, tile_count); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 847 | |
| 848 | std::vector<Tile*> tiles(all_tiles.begin(), all_tiles.end()); |
| 849 | host_impl_.tile_manager()->InitializeTilesWithResourcesForTesting(tiles); |
| 850 | |
| 851 | EvictionTilePriorityQueue queue; |
| 852 | for (int i = 1; i < 10; ++i) { |
| 853 | scoped_ptr<FakePictureLayerImpl> pending_layer = |
| 854 | FakePictureLayerImpl::Create(host_impl_.pending_tree(), id_ + i); |
| 855 | pending_layer->SetDrawsContent(true); |
| 856 | pending_layer->DoPostCommitInitializationIfNeeded(); |
| 857 | pending_layer->set_has_valid_tile_priorities(true); |
| 858 | pending_layer_->AddChild(pending_layer.Pass()); |
| 859 | } |
| 860 | |
| 861 | host_impl_.BuildEvictionQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES); |
| 862 | EXPECT_FALSE(queue.IsEmpty()); |
| 863 | |
| 864 | tile_count = 0; |
| 865 | all_tiles.clear(); |
| 866 | while (!queue.IsEmpty()) { |
| 867 | EXPECT_TRUE(queue.Top()); |
| 868 | all_tiles.insert(queue.Top()); |
| 869 | ++tile_count; |
| 870 | queue.Pop(); |
| 871 | } |
| 872 | EXPECT_EQ(tile_count, all_tiles.size()); |
James Robinson | 675df57 | 2014-10-22 17:20:33 -0700 | [diff] [blame] | 873 | EXPECT_EQ(16u, tile_count); |
James Robinson | 646469d | 2014-10-03 15:33:28 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | } // namespace |
| 877 | } // namespace cc |