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