| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/resources/tile.h" | 5 #include "cc/resources/tile.h" |
| 6 #include "cc/resources/tile_priority.h" | 6 #include "cc/resources/tile_priority.h" |
| 7 #include "cc/test/fake_impl_proxy.h" | 7 #include "cc/test/fake_impl_proxy.h" |
| 8 #include "cc/test/fake_layer_tree_host_impl.h" | 8 #include "cc/test/fake_layer_tree_host_impl.h" |
| 9 #include "cc/test/fake_output_surface.h" | 9 #include "cc/test/fake_output_surface.h" |
| 10 #include "cc/test/fake_output_surface_client.h" | 10 #include "cc/test/fake_output_surface_client.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 public: | 25 public: |
| 26 typedef std::vector<scoped_refptr<Tile> > TileVector; | 26 typedef std::vector<scoped_refptr<Tile> > TileVector; |
| 27 | 27 |
| 28 TileManagerTest() | 28 TileManagerTest() |
| 29 : memory_limit_policy_(ALLOW_ANYTHING), | 29 : memory_limit_policy_(ALLOW_ANYTHING), |
| 30 max_tiles_(0), | 30 max_tiles_(0), |
| 31 ready_to_activate_(false) {} | 31 ready_to_activate_(false) {} |
| 32 | 32 |
| 33 void Initialize(int max_tiles, | 33 void Initialize(int max_tiles, |
| 34 TileMemoryLimitPolicy memory_limit_policy, | 34 TileMemoryLimitPolicy memory_limit_policy, |
| 35 TreePriority tree_priority, | 35 TreePriority tree_priority) { |
| 36 bool allow_on_demand_raster = true) { | |
| 37 output_surface_ = FakeOutputSurface::Create3d(); | 36 output_surface_ = FakeOutputSurface::Create3d(); |
| 38 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 37 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 39 | 38 |
| 40 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 39 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
| 41 resource_provider_ = ResourceProvider::Create( | 40 resource_provider_ = ResourceProvider::Create( |
| 42 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, | 41 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, |
| 43 false); | 42 false); |
| 44 resource_pool_ = ResourcePool::Create( | 43 resource_pool_ = ResourcePool::Create( |
| 45 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | 44 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); |
| 46 tile_manager_ = make_scoped_ptr(new FakeTileManager( | 45 tile_manager_ = |
| 47 this, resource_pool_.get(), allow_on_demand_raster)); | 46 make_scoped_ptr(new FakeTileManager(this, resource_pool_.get())); |
| 48 | 47 |
| 49 memory_limit_policy_ = memory_limit_policy; | 48 memory_limit_policy_ = memory_limit_policy; |
| 50 max_tiles_ = max_tiles; | 49 max_tiles_ = max_tiles; |
| 51 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | 50 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); |
| 52 | 51 |
| 53 SetTreePriority(tree_priority); | 52 SetTreePriority(tree_priority); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void SetTreePriority(TreePriority tree_priority) { | 55 void SetTreePriority(TreePriority tree_priority) { |
| 57 GlobalStateThatImpactsTilePriority state; | 56 GlobalStateThatImpactsTilePriority state; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 78 | 77 |
| 79 virtual void TearDown() OVERRIDE { | 78 virtual void TearDown() OVERRIDE { |
| 80 tile_manager_.reset(NULL); | 79 tile_manager_.reset(NULL); |
| 81 picture_pile_ = NULL; | 80 picture_pile_ = NULL; |
| 82 | 81 |
| 83 testing::Test::TearDown(); | 82 testing::Test::TearDown(); |
| 84 } | 83 } |
| 85 | 84 |
| 86 // TileManagerClient implementation. | 85 // TileManagerClient implementation. |
| 87 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | 86 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |
| 88 virtual void NotifyTileInitialized(const Tile* tile) OVERRIDE {} | 87 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} |
| 89 | 88 |
| 90 TileVector CreateTilesWithSize(int count, | 89 TileVector CreateTilesWithSize(int count, |
| 91 TilePriority active_priority, | 90 TilePriority active_priority, |
| 92 TilePriority pending_priority, | 91 TilePriority pending_priority, |
| 93 const gfx::Size& tile_size) { | 92 const gfx::Size& tile_size) { |
| 94 TileVector tiles; | 93 TileVector tiles; |
| 95 for (int i = 0; i < count; ++i) { | 94 for (int i = 0; i < count; ++i) { |
| 96 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | 95 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), |
| 97 tile_size, | 96 tile_size, |
| 98 gfx::Rect(), | 97 gfx::Rect(), |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 | 606 |
| 608 tile_manager()->AssignMemoryToTiles(global_state_); | 607 tile_manager()->AssignMemoryToTiles(global_state_); |
| 609 tile_manager()->GetMemoryStats(&memory_required_bytes, | 608 tile_manager()->GetMemoryStats(&memory_required_bytes, |
| 610 &memory_nice_to_have_bytes, | 609 &memory_nice_to_have_bytes, |
| 611 &memory_allocated_bytes, | 610 &memory_allocated_bytes, |
| 612 &memory_used_bytes); | 611 &memory_used_bytes); |
| 613 // Allocated bytes should never be more than the memory limit. | 612 // Allocated bytes should never be more than the memory limit. |
| 614 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); | 613 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); |
| 615 } | 614 } |
| 616 | 615 |
| 617 TEST_P(TileManagerTest, AllowRasterizeOnDemand) { | |
| 618 // Not enough memory to initialize tiles required for activation. | |
| 619 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES); | |
| 620 TileVector tiles = | |
| 621 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
| 622 | |
| 623 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 624 | |
| 625 // This should make required tiles ready to draw by marking them as | |
| 626 // required tiles for on-demand raster. | |
| 627 tile_manager()->DidFinishRunningTasksForTesting(); | |
| 628 | |
| 629 EXPECT_TRUE(ready_to_activate()); | |
| 630 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
| 631 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
| 632 } | |
| 633 | |
| 634 TEST_P(TileManagerTest, PreventRasterizeOnDemand) { | |
| 635 // Not enough memory to initialize tiles required for activation. | |
| 636 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES, false); | |
| 637 TileVector tiles = | |
| 638 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
| 639 | |
| 640 tile_manager()->AssignMemoryToTiles(global_state_); | |
| 641 | |
| 642 // This should make required tiles ready to draw by marking them as | |
| 643 // required tiles for on-demand raster. | |
| 644 tile_manager()->DidFinishRunningTasksForTesting(); | |
| 645 | |
| 646 EXPECT_TRUE(ready_to_activate()); | |
| 647 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
| 648 EXPECT_FALSE((*it)->IsReadyToDraw()); | |
| 649 } | |
| 650 | |
| 651 // If true, the max tile limit should be applied as bytes; if false, | 616 // If true, the max tile limit should be applied as bytes; if false, |
| 652 // as num_resources_limit. | 617 // as num_resources_limit. |
| 653 INSTANTIATE_TEST_CASE_P(TileManagerTests, | 618 INSTANTIATE_TEST_CASE_P(TileManagerTests, |
| 654 TileManagerTest, | 619 TileManagerTest, |
| 655 ::testing::Values(true, false)); | 620 ::testing::Values(true, false)); |
| 656 | 621 |
| 657 class TileManagerTileIteratorTest : public testing::Test, | 622 class TileManagerTileIteratorTest : public testing::Test, |
| 658 public TileManagerClient { | 623 public TileManagerClient { |
| 659 public: | 624 public: |
| 660 TileManagerTileIteratorTest() | 625 TileManagerTileIteratorTest() |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 void CreateHighLowResAndSetAllTilesVisible() { | 712 void CreateHighLowResAndSetAllTilesVisible() { |
| 748 // Active layer must get updated first so pending layer can share from it. | 713 // Active layer must get updated first so pending layer can share from it. |
| 749 active_layer_->CreateDefaultTilingsAndTiles(); | 714 active_layer_->CreateDefaultTilingsAndTiles(); |
| 750 active_layer_->SetAllTilesVisible(); | 715 active_layer_->SetAllTilesVisible(); |
| 751 pending_layer_->CreateDefaultTilingsAndTiles(); | 716 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 752 pending_layer_->SetAllTilesVisible(); | 717 pending_layer_->SetAllTilesVisible(); |
| 753 } | 718 } |
| 754 | 719 |
| 755 // TileManagerClient implementation. | 720 // TileManagerClient implementation. |
| 756 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | 721 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |
| 757 virtual void NotifyTileInitialized(const Tile* tile) OVERRIDE {} | 722 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} |
| 758 | 723 |
| 759 TileManager* tile_manager() { return host_impl_.tile_manager(); } | 724 TileManager* tile_manager() { return host_impl_.tile_manager(); } |
| 760 | 725 |
| 761 protected: | 726 protected: |
| 762 GlobalStateThatImpactsTilePriority global_state_; | 727 GlobalStateThatImpactsTilePriority global_state_; |
| 763 | 728 |
| 764 TestSharedBitmapManager shared_bitmap_manager_; | 729 TestSharedBitmapManager shared_bitmap_manager_; |
| 765 TileMemoryLimitPolicy memory_limit_policy_; | 730 TileMemoryLimitPolicy memory_limit_policy_; |
| 766 int max_tiles_; | 731 int max_tiles_; |
| 767 bool ready_to_activate_; | 732 bool ready_to_activate_; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1146 | 1111 |
| 1147 last_tile = tile; | 1112 last_tile = tile; |
| 1148 new_content_tiles.insert(tile); | 1113 new_content_tiles.insert(tile); |
| 1149 } | 1114 } |
| 1150 | 1115 |
| 1151 EXPECT_EQ(tile_count, new_content_tiles.size()); | 1116 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 1152 EXPECT_EQ(all_tiles, new_content_tiles); | 1117 EXPECT_EQ(all_tiles, new_content_tiles); |
| 1153 } | 1118 } |
| 1154 } // namespace | 1119 } // namespace |
| 1155 } // namespace cc | 1120 } // namespace cc |
| OLD | NEW |