| 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" | |
| 6 #include "cc/resources/raster_tile_priority_queue.h" | |
| 7 #include "cc/resources/tile.h" | 5 #include "cc/resources/tile.h" |
| 8 #include "cc/resources/tile_priority.h" | 6 #include "cc/resources/tile_priority.h" |
| 9 #include "cc/test/fake_impl_proxy.h" | 7 #include "cc/test/fake_impl_proxy.h" |
| 10 #include "cc/test/fake_layer_tree_host_impl.h" | 8 #include "cc/test/fake_layer_tree_host_impl.h" |
| 11 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
| 12 #include "cc/test/fake_output_surface_client.h" | 10 #include "cc/test/fake_output_surface_client.h" |
| 13 #include "cc/test/fake_picture_layer_impl.h" | 11 #include "cc/test/fake_picture_layer_impl.h" |
| 14 #include "cc/test/fake_picture_pile_impl.h" | 12 #include "cc/test/fake_picture_pile_impl.h" |
| 15 #include "cc/test/fake_tile_manager.h" | 13 #include "cc/test/fake_tile_manager.h" |
| 16 #include "cc/test/impl_side_painting_settings.h" | 14 #include "cc/test/impl_side_painting_settings.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 76 } |
| 79 | 77 |
| 80 virtual void TearDown() OVERRIDE { | 78 virtual void TearDown() OVERRIDE { |
| 81 tile_manager_.reset(NULL); | 79 tile_manager_.reset(NULL); |
| 82 picture_pile_ = NULL; | 80 picture_pile_ = NULL; |
| 83 | 81 |
| 84 testing::Test::TearDown(); | 82 testing::Test::TearDown(); |
| 85 } | 83 } |
| 86 | 84 |
| 87 // TileManagerClient implementation. | 85 // TileManagerClient implementation. |
| 88 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() | 86 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() OVERRIDE { |
| 89 const OVERRIDE { | |
| 90 return picture_layers_; | 87 return picture_layers_; |
| 91 } | 88 } |
| 92 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | 89 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |
| 93 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} | 90 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} |
| 94 virtual void BuildRasterQueue(RasterTilePriorityQueue* queue, | |
| 95 TreePriority priority) OVERRIDE {} | |
| 96 virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue, | |
| 97 TreePriority priority) OVERRIDE {} | |
| 98 | 91 |
| 99 TileVector CreateTilesWithSize(int count, | 92 TileVector CreateTilesWithSize(int count, |
| 100 TilePriority active_priority, | 93 TilePriority active_priority, |
| 101 TilePriority pending_priority, | 94 TilePriority pending_priority, |
| 102 const gfx::Size& tile_size) { | 95 const gfx::Size& tile_size) { |
| 103 TileVector tiles; | 96 TileVector tiles; |
| 104 for (int i = 0; i < count; ++i) { | 97 for (int i = 0; i < count; ++i) { |
| 105 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | 98 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), |
| 106 tile_size, | 99 tile_size, |
| 107 gfx::Rect(), | 100 gfx::Rect(), |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); | 417 EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |
| 425 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); | 418 EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); |
| 426 } | 419 } |
| 427 | 420 |
| 428 // If true, the max tile limit should be applied as bytes; if false, | 421 // If true, the max tile limit should be applied as bytes; if false, |
| 429 // as num_resources_limit. | 422 // as num_resources_limit. |
| 430 INSTANTIATE_TEST_CASE_P(TileManagerTests, | 423 INSTANTIATE_TEST_CASE_P(TileManagerTests, |
| 431 TileManagerTest, | 424 TileManagerTest, |
| 432 ::testing::Values(true, false)); | 425 ::testing::Values(true, false)); |
| 433 | 426 |
| 434 class TileManagerTilePriorityQueueTest : public testing::Test { | 427 class TileManagerTileIteratorTest : public testing::Test { |
| 435 public: | 428 public: |
| 436 TileManagerTilePriorityQueueTest() | 429 TileManagerTileIteratorTest() |
| 437 : memory_limit_policy_(ALLOW_ANYTHING), | 430 : memory_limit_policy_(ALLOW_ANYTHING), |
| 438 max_tiles_(10000), | 431 max_tiles_(10000), |
| 439 ready_to_activate_(false), | 432 ready_to_activate_(false), |
| 440 id_(7), | 433 id_(7), |
| 441 proxy_(base::MessageLoopProxy::current()), | 434 proxy_(base::MessageLoopProxy::current()), |
| 442 host_impl_(ImplSidePaintingSettings(), | 435 host_impl_(ImplSidePaintingSettings(), |
| 443 &proxy_, | 436 &proxy_, |
| 444 &shared_bitmap_manager_) {} | 437 &shared_bitmap_manager_) {} |
| 445 | 438 |
| 446 void SetTreePriority(TreePriority tree_priority) { | 439 void SetTreePriority(TreePriority tree_priority) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 TileMemoryLimitPolicy memory_limit_policy_; | 530 TileMemoryLimitPolicy memory_limit_policy_; |
| 538 int max_tiles_; | 531 int max_tiles_; |
| 539 bool ready_to_activate_; | 532 bool ready_to_activate_; |
| 540 int id_; | 533 int id_; |
| 541 FakeImplProxy proxy_; | 534 FakeImplProxy proxy_; |
| 542 FakeLayerTreeHostImpl host_impl_; | 535 FakeLayerTreeHostImpl host_impl_; |
| 543 FakePictureLayerImpl* pending_layer_; | 536 FakePictureLayerImpl* pending_layer_; |
| 544 FakePictureLayerImpl* active_layer_; | 537 FakePictureLayerImpl* active_layer_; |
| 545 }; | 538 }; |
| 546 | 539 |
| 547 TEST_F(TileManagerTilePriorityQueueTest, RasterTilePriorityQueue) { | 540 TEST_F(TileManagerTileIteratorTest, PairedPictureLayers) { |
| 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) { |
| 548 SetupDefaultTrees(gfx::Size(1000, 1000)); | 588 SetupDefaultTrees(gfx::Size(1000, 1000)); |
| 589 TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager(); |
| 590 EXPECT_TRUE(tile_manager); |
| 549 | 591 |
| 550 active_layer_->CreateDefaultTilingsAndTiles(); | 592 active_layer_->CreateDefaultTilingsAndTiles(); |
| 551 pending_layer_->CreateDefaultTilingsAndTiles(); | 593 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 552 | 594 |
| 553 RasterTilePriorityQueue queue; | 595 std::vector<TileManager::PairedPictureLayer> paired_layers; |
| 554 host_impl_.BuildRasterQueue(&queue, SAME_PRIORITY_FOR_BOTH_TREES); | 596 tile_manager->GetPairedPictureLayers(&paired_layers); |
| 555 EXPECT_FALSE(queue.IsEmpty()); | 597 EXPECT_EQ(1u, paired_layers.size()); |
| 598 |
| 599 TileManager::RasterTileIterator it(tile_manager, |
| 600 SAME_PRIORITY_FOR_BOTH_TREES); |
| 601 EXPECT_TRUE(it); |
| 556 | 602 |
| 557 size_t tile_count = 0; | 603 size_t tile_count = 0; |
| 558 std::set<Tile*> all_tiles; | 604 std::set<Tile*> all_tiles; |
| 559 while (!queue.IsEmpty()) { | 605 for (; it; ++it) { |
| 560 EXPECT_TRUE(queue.Top()); | 606 EXPECT_TRUE(*it); |
| 561 all_tiles.insert(queue.Top()); | 607 all_tiles.insert(*it); |
| 562 ++tile_count; | 608 ++tile_count; |
| 563 queue.Pop(); | |
| 564 } | 609 } |
| 565 | 610 |
| 566 EXPECT_EQ(tile_count, all_tiles.size()); | 611 EXPECT_EQ(tile_count, all_tiles.size()); |
| 567 EXPECT_EQ(17u, tile_count); | 612 EXPECT_EQ(17u, tile_count); |
| 568 | 613 |
| 569 // Sanity check, all tiles should be visible. | 614 // Sanity check, all tiles should be visible. |
| 570 std::set<Tile*> smoothness_tiles; | 615 std::set<Tile*> smoothness_tiles; |
| 571 queue.Reset(); | 616 for (TileManager::RasterTileIterator it(tile_manager, |
| 572 host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 617 SMOOTHNESS_TAKES_PRIORITY); |
| 573 while (!queue.IsEmpty()) { | 618 it; |
| 574 Tile* tile = queue.Top(); | 619 ++it) { |
| 620 Tile* tile = *it; |
| 575 EXPECT_TRUE(tile); | 621 EXPECT_TRUE(tile); |
| 576 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); | 622 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); |
| 577 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); | 623 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); |
| 578 smoothness_tiles.insert(tile); | 624 smoothness_tiles.insert(tile); |
| 579 queue.Pop(); | |
| 580 } | 625 } |
| 581 EXPECT_EQ(all_tiles, smoothness_tiles); | 626 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 582 | 627 |
| 583 Region invalidation(gfx::Rect(0, 0, 500, 500)); | 628 Region invalidation(gfx::Rect(0, 0, 500, 500)); |
| 584 | 629 |
| 585 // Invalidate the pending tree. | 630 // Invalidate the pending tree. |
| 586 pending_layer_->set_invalidation(invalidation); | 631 pending_layer_->set_invalidation(invalidation); |
| 587 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( | 632 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( |
| 588 invalidation, gfx::Size(1000, 1000)); | 633 invalidation, gfx::Size(1000, 1000)); |
| 589 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( | 634 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 std::vector<Tile*> active_low_res_tiles = | 692 std::vector<Tile*> active_low_res_tiles = |
| 648 active_layer_->LowResTiling()->AllTilesForTesting(); | 693 active_layer_->LowResTiling()->AllTilesForTesting(); |
| 649 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 694 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
| 650 all_tiles.insert(active_low_res_tiles[i]); | 695 all_tiles.insert(active_low_res_tiles[i]); |
| 651 | 696 |
| 652 Tile* last_tile = NULL; | 697 Tile* last_tile = NULL; |
| 653 smoothness_tiles.clear(); | 698 smoothness_tiles.clear(); |
| 654 tile_count = 0; | 699 tile_count = 0; |
| 655 size_t increasing_distance_tiles = 0u; | 700 size_t increasing_distance_tiles = 0u; |
| 656 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 701 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 657 queue.Reset(); | 702 for (TileManager::RasterTileIterator it(tile_manager, |
| 658 host_impl_.BuildRasterQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 703 SMOOTHNESS_TAKES_PRIORITY); |
| 659 while (!queue.IsEmpty()) { | 704 it; |
| 660 Tile* tile = queue.Top(); | 705 ++it) { |
| 706 Tile* tile = *it; |
| 661 EXPECT_TRUE(tile); | 707 EXPECT_TRUE(tile); |
| 662 | 708 |
| 663 if (!last_tile) | 709 if (!last_tile) |
| 664 last_tile = tile; | 710 last_tile = tile; |
| 665 | 711 |
| 666 EXPECT_LE(last_tile->priority(ACTIVE_TREE).priority_bin, | 712 EXPECT_LE(last_tile->priority(ACTIVE_TREE).priority_bin, |
| 667 tile->priority(ACTIVE_TREE).priority_bin); | 713 tile->priority(ACTIVE_TREE).priority_bin); |
| 668 if (last_tile->priority(ACTIVE_TREE).priority_bin == | 714 if (last_tile->priority(ACTIVE_TREE).priority_bin == |
| 669 tile->priority(ACTIVE_TREE).priority_bin) { | 715 tile->priority(ACTIVE_TREE).priority_bin) { |
| 670 increasing_distance_tiles += | 716 increasing_distance_tiles += |
| 671 last_tile->priority(ACTIVE_TREE).distance_to_visible <= | 717 last_tile->priority(ACTIVE_TREE).distance_to_visible <= |
| 672 tile->priority(ACTIVE_TREE).distance_to_visible; | 718 tile->priority(ACTIVE_TREE).distance_to_visible; |
| 673 } | 719 } |
| 674 | 720 |
| 675 if (tile->priority(ACTIVE_TREE).priority_bin == TilePriority::NOW && | 721 if (tile->priority(ACTIVE_TREE).priority_bin == TilePriority::NOW && |
| 676 last_tile->priority(ACTIVE_TREE).resolution != | 722 last_tile->priority(ACTIVE_TREE).resolution != |
| 677 tile->priority(ACTIVE_TREE).resolution) { | 723 tile->priority(ACTIVE_TREE).resolution) { |
| 678 // Low resolution should come first. | 724 // Low resolution should come first. |
| 679 EXPECT_EQ(LOW_RESOLUTION, last_tile->priority(ACTIVE_TREE).resolution); | 725 EXPECT_EQ(LOW_RESOLUTION, last_tile->priority(ACTIVE_TREE).resolution); |
| 680 } | 726 } |
| 681 | 727 |
| 682 last_tile = tile; | 728 last_tile = tile; |
| 683 ++tile_count; | 729 ++tile_count; |
| 684 smoothness_tiles.insert(tile); | 730 smoothness_tiles.insert(tile); |
| 685 queue.Pop(); | |
| 686 } | 731 } |
| 687 | 732 |
| 688 EXPECT_EQ(tile_count, smoothness_tiles.size()); | 733 EXPECT_EQ(tile_count, smoothness_tiles.size()); |
| 689 EXPECT_EQ(all_tiles, smoothness_tiles); | 734 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 690 // Since we don't guarantee increasing distance due to spiral iterator, we | 735 // Since we don't guarantee increasing distance due to spiral iterator, we |
| 691 // should check that we're _mostly_ right. | 736 // should check that we're _mostly_ right. |
| 692 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); | 737 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); |
| 693 | 738 |
| 694 std::set<Tile*> new_content_tiles; | 739 std::set<Tile*> new_content_tiles; |
| 695 last_tile = NULL; | 740 last_tile = NULL; |
| 696 increasing_distance_tiles = 0u; | 741 increasing_distance_tiles = 0u; |
| 697 // Here we expect to get increasing PENDING_TREE priority_bin. | 742 // Here we expect to get increasing PENDING_TREE priority_bin. |
| 698 queue.Reset(); | 743 for (TileManager::RasterTileIterator it(tile_manager, |
| 699 host_impl_.BuildRasterQueue(&queue, NEW_CONTENT_TAKES_PRIORITY); | 744 NEW_CONTENT_TAKES_PRIORITY); |
| 700 while (!queue.IsEmpty()) { | 745 it; |
| 701 Tile* tile = queue.Top(); | 746 ++it) { |
| 747 Tile* tile = *it; |
| 702 EXPECT_TRUE(tile); | 748 EXPECT_TRUE(tile); |
| 703 | 749 |
| 704 if (!last_tile) | 750 if (!last_tile) |
| 705 last_tile = tile; | 751 last_tile = tile; |
| 706 | 752 |
| 707 EXPECT_LE(last_tile->priority(PENDING_TREE).priority_bin, | 753 EXPECT_LE(last_tile->priority(PENDING_TREE).priority_bin, |
| 708 tile->priority(PENDING_TREE).priority_bin); | 754 tile->priority(PENDING_TREE).priority_bin); |
| 709 if (last_tile->priority(PENDING_TREE).priority_bin == | 755 if (last_tile->priority(PENDING_TREE).priority_bin == |
| 710 tile->priority(PENDING_TREE).priority_bin) { | 756 tile->priority(PENDING_TREE).priority_bin) { |
| 711 increasing_distance_tiles += | 757 increasing_distance_tiles += |
| 712 last_tile->priority(PENDING_TREE).distance_to_visible <= | 758 last_tile->priority(PENDING_TREE).distance_to_visible <= |
| 713 tile->priority(PENDING_TREE).distance_to_visible; | 759 tile->priority(PENDING_TREE).distance_to_visible; |
| 714 } | 760 } |
| 715 | 761 |
| 716 if (tile->priority(PENDING_TREE).priority_bin == TilePriority::NOW && | 762 if (tile->priority(PENDING_TREE).priority_bin == TilePriority::NOW && |
| 717 last_tile->priority(PENDING_TREE).resolution != | 763 last_tile->priority(PENDING_TREE).resolution != |
| 718 tile->priority(PENDING_TREE).resolution) { | 764 tile->priority(PENDING_TREE).resolution) { |
| 719 // High resolution should come first. | 765 // High resolution should come first. |
| 720 EXPECT_EQ(HIGH_RESOLUTION, last_tile->priority(PENDING_TREE).resolution); | 766 EXPECT_EQ(HIGH_RESOLUTION, last_tile->priority(PENDING_TREE).resolution); |
| 721 } | 767 } |
| 722 | 768 |
| 723 last_tile = tile; | 769 last_tile = tile; |
| 724 new_content_tiles.insert(tile); | 770 new_content_tiles.insert(tile); |
| 725 queue.Pop(); | |
| 726 } | 771 } |
| 727 | 772 |
| 728 EXPECT_EQ(tile_count, new_content_tiles.size()); | 773 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 729 EXPECT_EQ(all_tiles, new_content_tiles); | 774 EXPECT_EQ(all_tiles, new_content_tiles); |
| 730 // Since we don't guarantee increasing distance due to spiral iterator, we | 775 // Since we don't guarantee increasing distance due to spiral iterator, we |
| 731 // should check that we're _mostly_ right. | 776 // should check that we're _mostly_ right. |
| 732 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); | 777 EXPECT_GT(increasing_distance_tiles, 3 * tile_count / 4); |
| 733 } | 778 } |
| 734 | 779 |
| 735 TEST_F(TileManagerTilePriorityQueueTest, EvictionTilePriorityQueue) { | 780 TEST_F(TileManagerTileIteratorTest, EvictionTileIterator) { |
| 736 SetupDefaultTrees(gfx::Size(1000, 1000)); | 781 SetupDefaultTrees(gfx::Size(1000, 1000)); |
| 782 TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager(); |
| 783 EXPECT_TRUE(tile_manager); |
| 737 | 784 |
| 738 active_layer_->CreateDefaultTilingsAndTiles(); | 785 active_layer_->CreateDefaultTilingsAndTiles(); |
| 739 pending_layer_->CreateDefaultTilingsAndTiles(); | 786 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 740 | 787 |
| 741 EvictionTilePriorityQueue empty_queue; | 788 std::vector<TileManager::PairedPictureLayer> paired_layers; |
| 742 host_impl_.BuildEvictionQueue(&empty_queue, SAME_PRIORITY_FOR_BOTH_TREES); | 789 tile_manager->GetPairedPictureLayers(&paired_layers); |
| 743 EXPECT_TRUE(empty_queue.IsEmpty()); | 790 EXPECT_EQ(1u, paired_layers.size()); |
| 791 |
| 792 TileManager::EvictionTileIterator empty_it(tile_manager, |
| 793 SAME_PRIORITY_FOR_BOTH_TREES); |
| 794 EXPECT_FALSE(empty_it); |
| 744 std::set<Tile*> all_tiles; | 795 std::set<Tile*> all_tiles; |
| 745 size_t tile_count = 0; | 796 size_t tile_count = 0; |
| 746 | 797 |
| 747 RasterTilePriorityQueue raster_queue; | 798 for (TileManager::RasterTileIterator raster_it(tile_manager, |
| 748 host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES); | 799 SAME_PRIORITY_FOR_BOTH_TREES); |
| 749 while (!raster_queue.IsEmpty()) { | 800 raster_it; |
| 801 ++raster_it) { |
| 750 ++tile_count; | 802 ++tile_count; |
| 751 EXPECT_TRUE(raster_queue.Top()); | 803 EXPECT_TRUE(*raster_it); |
| 752 all_tiles.insert(raster_queue.Top()); | 804 all_tiles.insert(*raster_it); |
| 753 raster_queue.Pop(); | |
| 754 } | 805 } |
| 755 | 806 |
| 756 EXPECT_EQ(tile_count, all_tiles.size()); | 807 EXPECT_EQ(tile_count, all_tiles.size()); |
| 757 EXPECT_EQ(17u, tile_count); | 808 EXPECT_EQ(17u, tile_count); |
| 758 | 809 |
| 759 tile_manager()->InitializeTilesWithResourcesForTesting( | 810 tile_manager->InitializeTilesWithResourcesForTesting( |
| 760 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 811 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 761 | 812 |
| 762 EvictionTilePriorityQueue queue; | 813 TileManager::EvictionTileIterator it(tile_manager, SMOOTHNESS_TAKES_PRIORITY); |
| 763 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 814 EXPECT_TRUE(it); |
| 764 EXPECT_FALSE(queue.IsEmpty()); | |
| 765 | 815 |
| 766 // Sanity check, all tiles should be visible. | 816 // Sanity check, all tiles should be visible. |
| 767 std::set<Tile*> smoothness_tiles; | 817 std::set<Tile*> smoothness_tiles; |
| 768 while (!queue.IsEmpty()) { | 818 for (; it; ++it) { |
| 769 Tile* tile = queue.Top(); | 819 Tile* tile = *it; |
| 770 EXPECT_TRUE(tile); | 820 EXPECT_TRUE(tile); |
| 771 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); | 821 EXPECT_EQ(TilePriority::NOW, tile->priority(ACTIVE_TREE).priority_bin); |
| 772 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); | 822 EXPECT_EQ(TilePriority::NOW, tile->priority(PENDING_TREE).priority_bin); |
| 773 EXPECT_TRUE(tile->HasResources()); | 823 EXPECT_TRUE(tile->HasResources()); |
| 774 smoothness_tiles.insert(tile); | 824 smoothness_tiles.insert(tile); |
| 775 queue.Pop(); | |
| 776 } | 825 } |
| 777 EXPECT_EQ(all_tiles, smoothness_tiles); | 826 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 778 | 827 |
| 779 tile_manager()->ReleaseTileResourcesForTesting( | 828 tile_manager->ReleaseTileResourcesForTesting( |
| 780 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 829 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 781 | 830 |
| 782 Region invalidation(gfx::Rect(0, 0, 500, 500)); | 831 Region invalidation(gfx::Rect(0, 0, 500, 500)); |
| 783 | 832 |
| 784 // Invalidate the pending tree. | 833 // Invalidate the pending tree. |
| 785 pending_layer_->set_invalidation(invalidation); | 834 pending_layer_->set_invalidation(invalidation); |
| 786 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( | 835 pending_layer_->HighResTiling()->UpdateTilesToCurrentPile( |
| 787 invalidation, gfx::Size(1000, 1000)); | 836 invalidation, gfx::Size(1000, 1000)); |
| 788 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( | 837 pending_layer_->LowResTiling()->UpdateTilesToCurrentPile( |
| 789 invalidation, gfx::Size(1000, 1000)); | 838 invalidation, gfx::Size(1000, 1000)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 std::vector<Tile*> active_high_res_tiles = | 890 std::vector<Tile*> active_high_res_tiles = |
| 842 active_layer_->HighResTiling()->AllTilesForTesting(); | 891 active_layer_->HighResTiling()->AllTilesForTesting(); |
| 843 for (size_t i = 0; i < active_high_res_tiles.size(); ++i) | 892 for (size_t i = 0; i < active_high_res_tiles.size(); ++i) |
| 844 all_tiles.insert(active_high_res_tiles[i]); | 893 all_tiles.insert(active_high_res_tiles[i]); |
| 845 | 894 |
| 846 std::vector<Tile*> active_low_res_tiles = | 895 std::vector<Tile*> active_low_res_tiles = |
| 847 active_layer_->LowResTiling()->AllTilesForTesting(); | 896 active_layer_->LowResTiling()->AllTilesForTesting(); |
| 848 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 897 for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |
| 849 all_tiles.insert(active_low_res_tiles[i]); | 898 all_tiles.insert(active_low_res_tiles[i]); |
| 850 | 899 |
| 851 tile_manager()->InitializeTilesWithResourcesForTesting( | 900 tile_manager->InitializeTilesWithResourcesForTesting( |
| 852 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 901 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 853 | 902 |
| 854 Tile* last_tile = NULL; | 903 Tile* last_tile = NULL; |
| 855 smoothness_tiles.clear(); | 904 smoothness_tiles.clear(); |
| 856 tile_count = 0; | 905 tile_count = 0; |
| 857 // Here we expect to get increasing ACTIVE_TREE priority_bin. | 906 // Here we expect to get increasing ACTIVE_TREE priority_bin. |
| 858 queue.Reset(); | 907 for (TileManager::EvictionTileIterator it(tile_manager, |
| 859 host_impl_.BuildEvictionQueue(&queue, SMOOTHNESS_TAKES_PRIORITY); | 908 SMOOTHNESS_TAKES_PRIORITY); |
| 860 while (!queue.IsEmpty()) { | 909 it; |
| 861 Tile* tile = queue.Top(); | 910 ++it) { |
| 911 Tile* tile = *it; |
| 862 EXPECT_TRUE(tile); | 912 EXPECT_TRUE(tile); |
| 863 EXPECT_TRUE(tile->HasResources()); | 913 EXPECT_TRUE(tile->HasResources()); |
| 864 | 914 |
| 865 if (!last_tile) | 915 if (!last_tile) |
| 866 last_tile = tile; | 916 last_tile = tile; |
| 867 | 917 |
| 868 EXPECT_GE(last_tile->priority(ACTIVE_TREE).priority_bin, | 918 EXPECT_GE(last_tile->priority(ACTIVE_TREE).priority_bin, |
| 869 tile->priority(ACTIVE_TREE).priority_bin); | 919 tile->priority(ACTIVE_TREE).priority_bin); |
| 870 if (last_tile->priority(ACTIVE_TREE).priority_bin == | 920 if (last_tile->priority(ACTIVE_TREE).priority_bin == |
| 871 tile->priority(ACTIVE_TREE).priority_bin) { | 921 tile->priority(ACTIVE_TREE).priority_bin) { |
| 872 EXPECT_GE(last_tile->priority(ACTIVE_TREE).distance_to_visible, | 922 EXPECT_GE(last_tile->priority(ACTIVE_TREE).distance_to_visible, |
| 873 tile->priority(ACTIVE_TREE).distance_to_visible); | 923 tile->priority(ACTIVE_TREE).distance_to_visible); |
| 874 } | 924 } |
| 875 | 925 |
| 876 last_tile = tile; | 926 last_tile = tile; |
| 877 ++tile_count; | 927 ++tile_count; |
| 878 smoothness_tiles.insert(tile); | 928 smoothness_tiles.insert(tile); |
| 879 queue.Pop(); | |
| 880 } | 929 } |
| 881 | 930 |
| 882 EXPECT_EQ(tile_count, smoothness_tiles.size()); | 931 EXPECT_EQ(tile_count, smoothness_tiles.size()); |
| 883 EXPECT_EQ(all_tiles, smoothness_tiles); | 932 EXPECT_EQ(all_tiles, smoothness_tiles); |
| 884 | 933 |
| 885 std::set<Tile*> new_content_tiles; | 934 std::set<Tile*> new_content_tiles; |
| 886 last_tile = NULL; | 935 last_tile = NULL; |
| 887 // Here we expect to get increasing PENDING_TREE priority_bin. | 936 // Here we expect to get increasing PENDING_TREE priority_bin. |
| 888 queue.Reset(); | 937 for (TileManager::EvictionTileIterator it(tile_manager, |
| 889 host_impl_.BuildEvictionQueue(&queue, NEW_CONTENT_TAKES_PRIORITY); | 938 NEW_CONTENT_TAKES_PRIORITY); |
| 890 while (!queue.IsEmpty()) { | 939 it; |
| 891 Tile* tile = queue.Top(); | 940 ++it) { |
| 941 Tile* tile = *it; |
| 892 EXPECT_TRUE(tile); | 942 EXPECT_TRUE(tile); |
| 893 | 943 |
| 894 if (!last_tile) | 944 if (!last_tile) |
| 895 last_tile = tile; | 945 last_tile = tile; |
| 896 | 946 |
| 897 EXPECT_GE(last_tile->priority(PENDING_TREE).priority_bin, | 947 EXPECT_GE(last_tile->priority(PENDING_TREE).priority_bin, |
| 898 tile->priority(PENDING_TREE).priority_bin); | 948 tile->priority(PENDING_TREE).priority_bin); |
| 899 if (last_tile->priority(PENDING_TREE).priority_bin == | 949 if (last_tile->priority(PENDING_TREE).priority_bin == |
| 900 tile->priority(PENDING_TREE).priority_bin) { | 950 tile->priority(PENDING_TREE).priority_bin) { |
| 901 EXPECT_GE(last_tile->priority(PENDING_TREE).distance_to_visible, | 951 EXPECT_GE(last_tile->priority(PENDING_TREE).distance_to_visible, |
| 902 tile->priority(PENDING_TREE).distance_to_visible); | 952 tile->priority(PENDING_TREE).distance_to_visible); |
| 903 } | 953 } |
| 904 | 954 |
| 905 last_tile = tile; | 955 last_tile = tile; |
| 906 new_content_tiles.insert(tile); | 956 new_content_tiles.insert(tile); |
| 907 queue.Pop(); | |
| 908 } | 957 } |
| 909 | 958 |
| 910 EXPECT_EQ(tile_count, new_content_tiles.size()); | 959 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 911 EXPECT_EQ(all_tiles, new_content_tiles); | 960 EXPECT_EQ(all_tiles, new_content_tiles); |
| 912 } | 961 } |
| 913 | 962 |
| 914 TEST_F(TileManagerTilePriorityQueueTest, | 963 TEST_F(TileManagerTileIteratorTest, EvictionTileIteratorWithOcclusion) { |
| 915 EvictionTilePriorityQueueWithOcclusion) { | |
| 916 gfx::Size tile_size(102, 102); | 964 gfx::Size tile_size(102, 102); |
| 917 gfx::Size layer_bounds(1000, 1000); | 965 gfx::Size layer_bounds(1000, 1000); |
| 918 | 966 |
| 919 scoped_refptr<FakePicturePileImpl> pending_pile = | 967 scoped_refptr<FakePicturePileImpl> pending_pile = |
| 920 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); | 968 FakePicturePileImpl::CreateFilledPile(tile_size, layer_bounds); |
| 921 SetupPendingTree(pending_pile); | 969 SetupPendingTree(pending_pile); |
| 922 pending_layer_->CreateDefaultTilingsAndTiles(); | 970 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 923 | 971 |
| 924 scoped_ptr<FakePictureLayerImpl> pending_child = | 972 scoped_ptr<FakePictureLayerImpl> pending_child = |
| 925 FakePictureLayerImpl::CreateWithPile( | 973 FakePictureLayerImpl::CreateWithPile( |
| 926 host_impl_.pending_tree(), 2, pending_pile); | 974 host_impl_.pending_tree(), 2, pending_pile); |
| 927 pending_layer_->AddChild(pending_child.PassAs<LayerImpl>()); | 975 pending_layer_->AddChild(pending_child.PassAs<LayerImpl>()); |
| 928 | 976 |
| 929 FakePictureLayerImpl* pending_child_layer = | 977 FakePictureLayerImpl* pending_child_layer = |
| 930 static_cast<FakePictureLayerImpl*>(pending_layer_->children()[0]); | 978 static_cast<FakePictureLayerImpl*>(pending_layer_->children()[0]); |
| 931 pending_child_layer->SetDrawsContent(true); | 979 pending_child_layer->SetDrawsContent(true); |
| 932 pending_child_layer->DoPostCommitInitializationIfNeeded(); | 980 pending_child_layer->DoPostCommitInitializationIfNeeded(); |
| 933 pending_child_layer->CreateDefaultTilingsAndTiles(); | 981 pending_child_layer->CreateDefaultTilingsAndTiles(); |
| 934 | 982 |
| 983 TileManager* tile_manager = TileManagerTileIteratorTest::tile_manager(); |
| 984 EXPECT_TRUE(tile_manager); |
| 985 |
| 986 std::vector<TileManager::PairedPictureLayer> paired_layers; |
| 987 tile_manager->GetPairedPictureLayers(&paired_layers); |
| 988 EXPECT_EQ(2u, paired_layers.size()); |
| 989 |
| 935 std::set<Tile*> all_tiles; | 990 std::set<Tile*> all_tiles; |
| 936 size_t tile_count = 0; | 991 size_t tile_count = 0; |
| 937 RasterTilePriorityQueue raster_queue; | 992 for (TileManager::RasterTileIterator raster_it(tile_manager, |
| 938 host_impl_.BuildRasterQueue(&raster_queue, SAME_PRIORITY_FOR_BOTH_TREES); | 993 NEW_CONTENT_TAKES_PRIORITY); |
| 939 while (!raster_queue.IsEmpty()) { | 994 raster_it; |
| 995 ++raster_it) { |
| 940 ++tile_count; | 996 ++tile_count; |
| 941 EXPECT_TRUE(raster_queue.Top()); | 997 EXPECT_TRUE(*raster_it); |
| 942 all_tiles.insert(raster_queue.Top()); | 998 all_tiles.insert(*raster_it); |
| 943 raster_queue.Pop(); | |
| 944 } | 999 } |
| 945 EXPECT_EQ(tile_count, all_tiles.size()); | 1000 EXPECT_EQ(tile_count, all_tiles.size()); |
| 946 EXPECT_EQ(34u, tile_count); | 1001 EXPECT_EQ(34u, tile_count); |
| 947 | 1002 |
| 948 pending_layer_->ResetAllTilesPriorities(); | 1003 pending_layer_->ResetAllTilesPriorities(); |
| 949 | 1004 |
| 950 // Renew all of the tile priorities. | 1005 // Renew all of the tile priorities. |
| 951 gfx::Rect viewport(layer_bounds); | 1006 gfx::Rect viewport(layer_bounds); |
| 952 pending_layer_->HighResTiling()->UpdateTilePriorities( | 1007 pending_layer_->HighResTiling()->UpdateTilePriorities( |
| 953 PENDING_TREE, | 1008 PENDING_TREE, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 all_tiles.insert(pending_child_high_res_tiles[i]); | 1057 all_tiles.insert(pending_child_high_res_tiles[i]); |
| 1003 } | 1058 } |
| 1004 | 1059 |
| 1005 std::vector<Tile*> pending_child_low_res_tiles = | 1060 std::vector<Tile*> pending_child_low_res_tiles = |
| 1006 pending_child_layer->LowResTiling()->AllTilesForTesting(); | 1061 pending_child_layer->LowResTiling()->AllTilesForTesting(); |
| 1007 for (size_t i = 0; i < pending_child_low_res_tiles.size(); ++i) { | 1062 for (size_t i = 0; i < pending_child_low_res_tiles.size(); ++i) { |
| 1008 pending_child_low_res_tiles[i]->set_is_occluded(PENDING_TREE, true); | 1063 pending_child_low_res_tiles[i]->set_is_occluded(PENDING_TREE, true); |
| 1009 all_tiles.insert(pending_child_low_res_tiles[i]); | 1064 all_tiles.insert(pending_child_low_res_tiles[i]); |
| 1010 } | 1065 } |
| 1011 | 1066 |
| 1012 tile_manager()->InitializeTilesWithResourcesForTesting( | 1067 tile_manager->InitializeTilesWithResourcesForTesting( |
| 1013 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); | 1068 std::vector<Tile*>(all_tiles.begin(), all_tiles.end())); |
| 1014 | 1069 |
| 1015 // Verify occlusion is considered by EvictionTilePriorityQueue. | 1070 // Verify occlusion is considered by EvictionTileIterator. |
| 1016 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; | 1071 TreePriority tree_priority = NEW_CONTENT_TAKES_PRIORITY; |
| 1017 size_t occluded_count = 0u; | 1072 size_t occluded_count = 0u; |
| 1018 Tile* last_tile = NULL; | 1073 Tile* last_tile = NULL; |
| 1019 EvictionTilePriorityQueue queue; | 1074 for (TileManager::EvictionTileIterator it(tile_manager, tree_priority); it; |
| 1020 host_impl_.BuildEvictionQueue(&queue, tree_priority); | 1075 ++it) { |
| 1021 while (!queue.IsEmpty()) { | 1076 Tile* tile = *it; |
| 1022 Tile* tile = queue.Top(); | |
| 1023 if (!last_tile) | 1077 if (!last_tile) |
| 1024 last_tile = tile; | 1078 last_tile = tile; |
| 1025 | 1079 |
| 1026 bool tile_is_occluded = tile->is_occluded_for_tree_priority(tree_priority); | 1080 bool tile_is_occluded = tile->is_occluded_for_tree_priority(tree_priority); |
| 1027 | 1081 |
| 1028 // The only way we will encounter an occluded tile after an unoccluded | 1082 // The only way we will encounter an occluded tile after an unoccluded |
| 1029 // tile is if the priorty bin decreased, the tile is required for | 1083 // tile is if the priorty bin decreased, the tile is required for |
| 1030 // activation, or the scale changed. | 1084 // activation, or the scale changed. |
| 1031 if (tile_is_occluded) { | 1085 if (tile_is_occluded) { |
| 1032 occluded_count++; | 1086 occluded_count++; |
| 1033 | 1087 |
| 1034 bool last_tile_is_occluded = | 1088 bool last_tile_is_occluded = |
| 1035 last_tile->is_occluded_for_tree_priority(tree_priority); | 1089 last_tile->is_occluded_for_tree_priority(tree_priority); |
| 1036 if (!last_tile_is_occluded) { | 1090 if (!last_tile_is_occluded) { |
| 1037 TilePriority::PriorityBin tile_priority_bin = | 1091 TilePriority::PriorityBin tile_priority_bin = |
| 1038 tile->priority_for_tree_priority(tree_priority).priority_bin; | 1092 tile->priority_for_tree_priority(tree_priority).priority_bin; |
| 1039 TilePriority::PriorityBin last_tile_priority_bin = | 1093 TilePriority::PriorityBin last_tile_priority_bin = |
| 1040 last_tile->priority_for_tree_priority(tree_priority).priority_bin; | 1094 last_tile->priority_for_tree_priority(tree_priority).priority_bin; |
| 1041 | 1095 |
| 1042 EXPECT_TRUE((tile_priority_bin < last_tile_priority_bin) || | 1096 EXPECT_TRUE((tile_priority_bin < last_tile_priority_bin) || |
| 1043 tile->required_for_activation() || | 1097 tile->required_for_activation() || |
| 1044 (tile->contents_scale() != last_tile->contents_scale())); | 1098 (tile->contents_scale() != last_tile->contents_scale())); |
| 1045 } | 1099 } |
| 1046 } | 1100 } |
| 1047 last_tile = tile; | 1101 last_tile = tile; |
| 1048 queue.Pop(); | |
| 1049 } | 1102 } |
| 1050 size_t expected_occluded_count = | 1103 size_t expected_occluded_count = |
| 1051 pending_child_high_res_tiles.size() + pending_child_low_res_tiles.size(); | 1104 pending_child_high_res_tiles.size() + pending_child_low_res_tiles.size(); |
| 1052 EXPECT_EQ(expected_occluded_count, occluded_count); | 1105 EXPECT_EQ(expected_occluded_count, occluded_count); |
| 1053 } | 1106 } |
| 1054 } // namespace | 1107 } // namespace |
| 1055 } // namespace cc | 1108 } // namespace cc |
| OLD | NEW |