| 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" |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); | 102 LayerTreeImpl* pending_tree = host_impl_.pending_tree(); |
| 103 | 103 |
| 104 // Steal from the recycled tree. | 104 // Steal from the recycled tree. |
| 105 scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree(); | 105 scoped_ptr<LayerImpl> old_pending_root = pending_tree->DetachLayerTree(); |
| 106 DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_); | 106 DCHECK_IMPLIES(old_pending_root, old_pending_root->id() == id_); |
| 107 | 107 |
| 108 scoped_ptr<FakePictureLayerImpl> pending_layer; | 108 scoped_ptr<FakePictureLayerImpl> pending_layer; |
| 109 if (old_pending_root) { | 109 if (old_pending_root) { |
| 110 pending_layer.reset( | 110 pending_layer.reset( |
| 111 static_cast<FakePictureLayerImpl*>(old_pending_root.release())); | 111 static_cast<FakePictureLayerImpl*>(old_pending_root.release())); |
| 112 pending_layer->SetRasterSource(pile); | 112 pending_layer->SetRasterSourceOnPending(pile, Region()); |
| 113 } else { | 113 } else { |
| 114 pending_layer = | 114 pending_layer = |
| 115 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_, pile); | 115 FakePictureLayerImpl::CreateWithRasterSource(pending_tree, id_, pile); |
| 116 pending_layer->SetDrawsContent(true); | 116 pending_layer->SetDrawsContent(true); |
| 117 } | 117 } |
| 118 // The bounds() just mirror the pile size. | 118 // The bounds() just mirror the pile size. |
| 119 pending_layer->SetBounds(pending_layer->raster_source()->GetSize()); | 119 pending_layer->SetBounds(pending_layer->raster_source()->GetSize()); |
| 120 pending_tree->SetRootLayer(pending_layer.Pass()); | 120 pending_tree->SetRootLayer(pending_layer.Pass()); |
| 121 | 121 |
| 122 pending_layer_ = static_cast<FakePictureLayerImpl*>( | 122 pending_layer_ = static_cast<FakePictureLayerImpl*>( |
| 123 host_impl_.pending_tree()->LayerById(id_)); | 123 host_impl_.pending_tree()->LayerById(id_)); |
| 124 pending_layer_->DoPostCommitInitializationIfNeeded(); | 124 pending_layer_->DoPostCommitInitializationIfNeeded(); |
| 125 } | 125 } |
| 126 | 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(); } | 127 TileManager* tile_manager() { return host_impl_.tile_manager(); } |
| 136 | 128 |
| 137 protected: | 129 protected: |
| 138 GlobalStateThatImpactsTilePriority global_state_; | 130 GlobalStateThatImpactsTilePriority global_state_; |
| 139 | 131 |
| 140 TestSharedBitmapManager shared_bitmap_manager_; | 132 TestSharedBitmapManager shared_bitmap_manager_; |
| 141 TileMemoryLimitPolicy memory_limit_policy_; | 133 TileMemoryLimitPolicy memory_limit_policy_; |
| 142 int max_tiles_; | 134 int max_tiles_; |
| 143 bool ready_to_activate_; | 135 bool ready_to_activate_; |
| 144 int id_; | 136 int id_; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 smoothness_tiles.insert(tile); | 180 smoothness_tiles.insert(tile); |
| 189 queue.Pop(); | 181 queue.Pop(); |
| 190 } | 182 } |
| 191 EXPECT_EQ(all_tiles, smoothness_tiles); | 183 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 192 EXPECT_TRUE(had_low_res); | 184 EXPECT_TRUE(had_low_res); |
| 193 | 185 |
| 194 Region invalidation(gfx::Rect(0, 0, 500, 500)); | 186 Region invalidation(gfx::Rect(0, 0, 500, 500)); |
| 195 | 187 |
| 196 // Invalidate the pending tree. | 188 // Invalidate the pending tree. |
| 197 pending_layer_->set_invalidation(invalidation); | 189 pending_layer_->set_invalidation(invalidation); |
| 198 pending_layer_->HighResTiling()->UpdateTilesToCurrentRasterSource( | 190 pending_layer_->HighResTiling()->Invalidate(invalidation); |
| 199 pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); | 191 pending_layer_->LowResTiling()->Invalidate(invalidation); |
| 200 pending_layer_->LowResTiling()->UpdateTilesToCurrentRasterSource( | |
| 201 pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); | |
| 202 | 192 |
| 203 active_layer_->ResetAllTilesPriorities(); | 193 active_layer_->ResetAllTilesPriorities(); |
| 204 pending_layer_->ResetAllTilesPriorities(); | 194 pending_layer_->ResetAllTilesPriorities(); |
| 205 | 195 |
| 206 // Renew all of the tile priorities. | 196 // Renew all of the tile priorities. |
| 207 gfx::Rect viewport(50, 50, 100, 100); | 197 gfx::Rect viewport(50, 50, 100, 100); |
| 208 pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, | 198 pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 209 Occlusion()); | 199 Occlusion()); |
| 210 pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, | 200 pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 211 Occlusion()); | 201 Occlusion()); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 } | 428 } |
| 439 EXPECT_EQ(all_tiles, smoothness_tiles); | 429 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 440 | 430 |
| 441 tile_manager()->ReleaseTileResourcesForTesting( | 431 tile_manager()->ReleaseTileResourcesForTesting( |
| 442 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 432 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 443 | 433 |
| 444 Region invalidation(gfx::Rect(0, 0, 500, 500)); | 434 Region invalidation(gfx::Rect(0, 0, 500, 500)); |
| 445 | 435 |
| 446 // Invalidate the pending tree. | 436 // Invalidate the pending tree. |
| 447 pending_layer_->set_invalidation(invalidation); | 437 pending_layer_->set_invalidation(invalidation); |
| 448 pending_layer_->HighResTiling()->UpdateTilesToCurrentRasterSource( | 438 pending_layer_->HighResTiling()->Invalidate(invalidation); |
| 449 pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); | 439 pending_layer_->LowResTiling()->Invalidate(invalidation); |
| 450 pending_layer_->LowResTiling()->UpdateTilesToCurrentRasterSource( | |
| 451 pending_layer_->raster_source(), invalidation, gfx::Size(1000, 1000)); | |
| 452 | 440 |
| 453 active_layer_->ResetAllTilesPriorities(); | 441 active_layer_->ResetAllTilesPriorities(); |
| 454 pending_layer_->ResetAllTilesPriorities(); | 442 pending_layer_->ResetAllTilesPriorities(); |
| 455 | 443 |
| 456 // Renew all of the tile priorities. | 444 // Renew all of the tile priorities. |
| 457 gfx::Rect viewport(50, 50, 100, 100); | 445 gfx::Rect viewport(50, 50, 100, 100); |
| 458 pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, | 446 pending_layer_->HighResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 459 Occlusion()); | 447 Occlusion()); |
| 460 pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, | 448 pending_layer_->LowResTiling()->ComputeTilePriorityRects(viewport, 1.0f, 1.0, |
| 461 Occlusion()); | 449 Occlusion()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 488 | 476 |
| 489 tile_manager()->InitializeTilesWithResourcesForTesting( | 477 tile_manager()->InitializeTilesWithResourcesForTesting( |
| 490 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 478 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 491 | 479 |
| 492 Tile* last_tile = NULL; | 480 Tile* last_tile = NULL; |
| 493 smoothness_tiles.clear(); | 481 smoothness_tiles.clear(); |
| 494 tile_count = 0; | 482 tile_count = 0; |
| 495 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 483 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 496 queue.Reset(); | 484 queue.Reset(); |
| 497 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 485 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); |
| 486 int distance_increasing = 0; |
| 487 int distance_decreasing = 0; |
| 498 while (!queue.IsEmpty()) { | 488 while (!queue.IsEmpty()) { |
| 499 Tile* tile = queue.Top(); | 489 Tile* tile = queue.Top(); |
| 500 EXPECT_TRUE(tile); | 490 EXPECT_TRUE(tile); |
| 501 EXPECT_TRUE(tile->HasResources()); | 491 EXPECT_TRUE(tile->HasResources()); |
| 502 | 492 |
| 503 if (!last_tile) | 493 if (!last_tile) |
| 504 last_tile = tile; | 494 last_tile = tile; |
| 505 | 495 |
| 506 EXPECT_GE(last_tile->priority(ACTIVE_TREE).priority_bin, | 496 EXPECT_GE(last_tile->priority(ACTIVE_TREE).priority_bin, |
| 507 tile->priority(ACTIVE_TREE).priority_bin); | 497 tile->priority(ACTIVE_TREE).priority_bin); |
| 508 if (last_tile->priority(ACTIVE_TREE).priority_bin == | 498 if (last_tile->priority(ACTIVE_TREE).priority_bin == |
| 509 tile->priority(ACTIVE_TREE).priority_bin) { | 499 tile->priority(ACTIVE_TREE).priority_bin) { |
| 510 EXPECT_LE(last_tile->required_for_activation(), | 500 EXPECT_LE(last_tile->required_for_activation(), |
| 511 tile->required_for_activation()); | 501 tile->required_for_activation()); |
| 512 if (last_tile->required_for_activation() == | 502 if (last_tile->required_for_activation() == |
| 513 tile->required_for_activation()) { | 503 tile->required_for_activation()) { |
| 514 EXPECT_GE(last_tile->priority(ACTIVE_TREE).distance_to_visible, | 504 if (last_tile->priority(ACTIVE_TREE).distance_to_visible >= |
| 515 tile->priority(ACTIVE_TREE).distance_to_visible); | 505 tile->priority(ACTIVE_TREE).distance_to_visible) |
| 506 ++distance_decreasing; |
| 507 else |
| 508 ++distance_increasing; |
| 516 } | 509 } |
| 517 } | 510 } |
| 518 | 511 |
| 519 last_tile = tile; | 512 last_tile = tile; |
| 520 ++tile_count; | 513 ++tile_count; |
| 521 smoothness_tiles.insert(tile); | 514 smoothness_tiles.insert(tile); |
| 522 queue.Pop(); | 515 queue.Pop(); |
| 523 } | 516 } |
| 524 | 517 |
| 518 EXPECT_EQ(3, distance_increasing); |
| 519 EXPECT_EQ(16, distance_decreasing); |
| 525 EXPECT_EQ(tile_count, smoothness_tiles.size()); | 520 EXPECT_EQ(tile_count, smoothness_tiles.size()); |
| 526 EXPECT_EQ(all_tiles, smoothness_tiles); | 521 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 527 | 522 |
| 528 std::set<Tile*> new_content_tiles; | 523 std::set<Tile*> new_content_tiles; |
| 529 last_tile = NULL; | 524 last_tile = NULL; |
| 530 // Here we expect to get increasing PENDING_TREE priority_bin. | 525 // Here we expect to get increasing PENDING_TREE priority_bin. |
| 531 queue.Reset(); | 526 queue.Reset(); |
| 532 host_impl_.BuildEvictionQueue(&queue, NEW_CONTENT_TAKES_PRIORITY); | 527 host_impl_.BuildEvictionQueue(&queue, NEW_CONTENT_TAKES_PRIORITY); |
| 528 distance_decreasing = 0; |
| 529 distance_increasing = 0; |
| 533 while (!queue.IsEmpty()) { | 530 while (!queue.IsEmpty()) { |
| 534 Tile* tile = queue.Top(); | 531 Tile* tile = queue.Top(); |
| 535 EXPECT_TRUE(tile); | 532 EXPECT_TRUE(tile); |
| 536 | 533 |
| 537 if (!last_tile) | 534 if (!last_tile) |
| 538 last_tile = tile; | 535 last_tile = tile; |
| 539 | 536 |
| 540 EXPECT_GE(last_tile->priority(PENDING_TREE).priority_bin, | 537 EXPECT_GE(last_tile->priority(PENDING_TREE).priority_bin, |
| 541 tile->priority(PENDING_TREE).priority_bin); | 538 tile->priority(PENDING_TREE).priority_bin); |
| 542 if (last_tile->priority(PENDING_TREE).priority_bin == | 539 if (last_tile->priority(PENDING_TREE).priority_bin == |
| 543 tile->priority(PENDING_TREE).priority_bin) { | 540 tile->priority(PENDING_TREE).priority_bin) { |
| 544 EXPECT_LE(last_tile->required_for_activation(), | 541 EXPECT_LE(last_tile->required_for_activation(), |
| 545 tile->required_for_activation()); | 542 tile->required_for_activation()); |
| 546 if (last_tile->required_for_activation() == | 543 if (last_tile->required_for_activation() == |
| 547 tile->required_for_activation()) { | 544 tile->required_for_activation()) { |
| 548 EXPECT_GE(last_tile->priority(PENDING_TREE).distance_to_visible, | 545 if (last_tile->priority(PENDING_TREE).distance_to_visible >= |
| 549 tile->priority(PENDING_TREE).distance_to_visible); | 546 tile->priority(PENDING_TREE).distance_to_visible) |
| 547 ++distance_decreasing; |
| 548 else |
| 549 ++distance_increasing; |
| 550 } | 550 } |
| 551 } | 551 } |
| 552 | 552 |
| 553 last_tile = tile; | 553 last_tile = tile; |
| 554 new_content_tiles.insert(tile); | 554 new_content_tiles.insert(tile); |
| 555 queue.Pop(); | 555 queue.Pop(); |
| 556 } | 556 } |
| 557 | 557 |
| 558 EXPECT_EQ(3, distance_increasing); |
| 559 EXPECT_EQ(16, distance_decreasing); |
| 558 EXPECT_EQ(tile_count, new_content_tiles.size()); | 560 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 559 EXPECT_EQ(all_tiles, new_content_tiles); | 561 EXPECT_EQ(all_tiles, new_content_tiles); |
| 560 } | 562 } |
| 561 | 563 |
| 562 TEST_F(TileManagerTilePriorityQueueTest, | 564 TEST_F(TileManagerTilePriorityQueueTest, |
| 563 EvictionTilePriorityQueueWithOcclusion) { | 565 EvictionTilePriorityQueueWithOcclusion) { |
| 564 gfx::Size tile_size(102, 102); | 566 gfx::Size tile_size(102, 102); |
| 565 gfx::Size layer_bounds(1000, 1000); | 567 gfx::Size layer_bounds(1000, 1000); |
| 566 | 568 |
| 567 host_impl_.SetViewportSize(layer_bounds); | 569 host_impl_.SetViewportSize(layer_bounds); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 all_tiles.insert(queue.Top()); | 870 all_tiles.insert(queue.Top()); |
| 869 ++tile_count; | 871 ++tile_count; |
| 870 queue.Pop(); | 872 queue.Pop(); |
| 871 } | 873 } |
| 872 EXPECT_EQ(tile_count, all_tiles.size()); | 874 EXPECT_EQ(tile_count, all_tiles.size()); |
| 873 EXPECT_EQ(16u, tile_count); | 875 EXPECT_EQ(16u, tile_count); |
| 874 } | 876 } |
| 875 | 877 |
| 876 } // namespace | 878 } // namespace |
| 877 } // namespace cc | 879 } // namespace cc |
| OLD | NEW |