| 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) { |
| 36 output_surface_ = FakeOutputSurface::Create3d(); | 37 output_surface_ = FakeOutputSurface::Create3d(); |
| 37 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 38 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 38 | 39 |
| 39 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); | 40 shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |
| 40 resource_provider_ = ResourceProvider::Create( | 41 resource_provider_ = ResourceProvider::Create( |
| 41 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, | 42 output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, |
| 42 false); | 43 false); |
| 43 resource_pool_ = ResourcePool::Create( | 44 resource_pool_ = ResourcePool::Create( |
| 44 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); | 45 resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); |
| 45 tile_manager_ = | 46 tile_manager_ = make_scoped_ptr(new FakeTileManager( |
| 46 make_scoped_ptr(new FakeTileManager(this, resource_pool_.get())); | 47 this, resource_pool_.get(), allow_on_demand_raster)); |
| 47 | 48 |
| 48 memory_limit_policy_ = memory_limit_policy; | 49 memory_limit_policy_ = memory_limit_policy; |
| 49 max_tiles_ = max_tiles; | 50 max_tiles_ = max_tiles; |
| 50 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); | 51 picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); |
| 51 | 52 |
| 52 SetTreePriority(tree_priority); | 53 SetTreePriority(tree_priority); |
| 53 } | 54 } |
| 54 | 55 |
| 55 void SetTreePriority(TreePriority tree_priority) { | 56 void SetTreePriority(TreePriority tree_priority) { |
| 56 GlobalStateThatImpactsTilePriority state; | 57 GlobalStateThatImpactsTilePriority state; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 77 | 78 |
| 78 virtual void TearDown() OVERRIDE { | 79 virtual void TearDown() OVERRIDE { |
| 79 tile_manager_.reset(NULL); | 80 tile_manager_.reset(NULL); |
| 80 picture_pile_ = NULL; | 81 picture_pile_ = NULL; |
| 81 | 82 |
| 82 testing::Test::TearDown(); | 83 testing::Test::TearDown(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 // TileManagerClient implementation. | 86 // TileManagerClient implementation. |
| 86 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | 87 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |
| 87 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} | 88 virtual void NotifyTileInitialized(const Tile* tile) OVERRIDE {} |
| 88 | 89 |
| 89 TileVector CreateTilesWithSize(int count, | 90 TileVector CreateTilesWithSize(int count, |
| 90 TilePriority active_priority, | 91 TilePriority active_priority, |
| 91 TilePriority pending_priority, | 92 TilePriority pending_priority, |
| 92 const gfx::Size& tile_size) { | 93 const gfx::Size& tile_size) { |
| 93 TileVector tiles; | 94 TileVector tiles; |
| 94 for (int i = 0; i < count; ++i) { | 95 for (int i = 0; i < count; ++i) { |
| 95 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | 96 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), |
| 96 tile_size, | 97 tile_size, |
| 97 gfx::Rect(), | 98 gfx::Rect(), |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 | 607 |
| 607 tile_manager()->AssignMemoryToTiles(global_state_); | 608 tile_manager()->AssignMemoryToTiles(global_state_); |
| 608 tile_manager()->GetMemoryStats(&memory_required_bytes, | 609 tile_manager()->GetMemoryStats(&memory_required_bytes, |
| 609 &memory_nice_to_have_bytes, | 610 &memory_nice_to_have_bytes, |
| 610 &memory_allocated_bytes, | 611 &memory_allocated_bytes, |
| 611 &memory_used_bytes); | 612 &memory_used_bytes); |
| 612 // Allocated bytes should never be more than the memory limit. | 613 // Allocated bytes should never be more than the memory limit. |
| 613 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); | 614 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); |
| 614 } | 615 } |
| 615 | 616 |
| 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 |
| 616 // If true, the max tile limit should be applied as bytes; if false, | 651 // If true, the max tile limit should be applied as bytes; if false, |
| 617 // as num_resources_limit. | 652 // as num_resources_limit. |
| 618 INSTANTIATE_TEST_CASE_P(TileManagerTests, | 653 INSTANTIATE_TEST_CASE_P(TileManagerTests, |
| 619 TileManagerTest, | 654 TileManagerTest, |
| 620 ::testing::Values(true, false)); | 655 ::testing::Values(true, false)); |
| 621 | 656 |
| 622 class TileManagerTileIteratorTest : public testing::Test, | 657 class TileManagerTileIteratorTest : public testing::Test, |
| 623 public TileManagerClient { | 658 public TileManagerClient { |
| 624 public: | 659 public: |
| 625 TileManagerTileIteratorTest() | 660 TileManagerTileIteratorTest() |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 void CreateHighLowResAndSetAllTilesVisible() { | 747 void CreateHighLowResAndSetAllTilesVisible() { |
| 713 // Active layer must get updated first so pending layer can share from it. | 748 // Active layer must get updated first so pending layer can share from it. |
| 714 active_layer_->CreateDefaultTilingsAndTiles(); | 749 active_layer_->CreateDefaultTilingsAndTiles(); |
| 715 active_layer_->SetAllTilesVisible(); | 750 active_layer_->SetAllTilesVisible(); |
| 716 pending_layer_->CreateDefaultTilingsAndTiles(); | 751 pending_layer_->CreateDefaultTilingsAndTiles(); |
| 717 pending_layer_->SetAllTilesVisible(); | 752 pending_layer_->SetAllTilesVisible(); |
| 718 } | 753 } |
| 719 | 754 |
| 720 // TileManagerClient implementation. | 755 // TileManagerClient implementation. |
| 721 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | 756 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |
| 722 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} | 757 virtual void NotifyTileInitialized(const Tile* tile) OVERRIDE {} |
| 723 | 758 |
| 724 TileManager* tile_manager() { return host_impl_.tile_manager(); } | 759 TileManager* tile_manager() { return host_impl_.tile_manager(); } |
| 725 | 760 |
| 726 protected: | 761 protected: |
| 727 GlobalStateThatImpactsTilePriority global_state_; | 762 GlobalStateThatImpactsTilePriority global_state_; |
| 728 | 763 |
| 729 TestSharedBitmapManager shared_bitmap_manager_; | 764 TestSharedBitmapManager shared_bitmap_manager_; |
| 730 TileMemoryLimitPolicy memory_limit_policy_; | 765 TileMemoryLimitPolicy memory_limit_policy_; |
| 731 int max_tiles_; | 766 int max_tiles_; |
| 732 bool ready_to_activate_; | 767 bool ready_to_activate_; |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 | 1146 |
| 1112 last_tile = tile; | 1147 last_tile = tile; |
| 1113 new_content_tiles.insert(tile); | 1148 new_content_tiles.insert(tile); |
| 1114 } | 1149 } |
| 1115 | 1150 |
| 1116 EXPECT_EQ(tile_count, new_content_tiles.size()); | 1151 EXPECT_EQ(tile_count, new_content_tiles.size()); |
| 1117 EXPECT_EQ(all_tiles, new_content_tiles); | 1152 EXPECT_EQ(all_tiles, new_content_tiles); |
| 1118 } | 1153 } |
| 1119 } // namespace | 1154 } // namespace |
| 1120 } // namespace cc | 1155 } // namespace cc |
| OLD | NEW |