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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 | 593 |
595 tile_manager()->AssignMemoryToTiles(global_state_); | 594 tile_manager()->AssignMemoryToTiles(global_state_); |
596 tile_manager()->GetMemoryStats(&memory_required_bytes, | 595 tile_manager()->GetMemoryStats(&memory_required_bytes, |
597 &memory_nice_to_have_bytes, | 596 &memory_nice_to_have_bytes, |
598 &memory_allocated_bytes, | 597 &memory_allocated_bytes, |
599 &memory_used_bytes); | 598 &memory_used_bytes); |
600 // Allocated bytes should never be more than the memory limit. | 599 // Allocated bytes should never be more than the memory limit. |
601 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); | 600 EXPECT_LE(memory_allocated_bytes, global_state_.hard_memory_limit_in_bytes); |
602 } | 601 } |
603 | 602 |
604 TEST_P(TileManagerTest, AllowRasterizeOnDemand) { | |
605 // Not enough memory to initialize tiles required for activation. | |
606 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES); | |
607 TileVector tiles = | |
608 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
609 | |
610 tile_manager()->AssignMemoryToTiles(global_state_); | |
611 | |
612 // This should make required tiles ready to draw by marking them as | |
613 // required tiles for on-demand raster. | |
614 tile_manager()->DidFinishRunningTasksForTesting(); | |
615 | |
616 EXPECT_TRUE(ready_to_activate()); | |
617 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
618 EXPECT_TRUE((*it)->IsReadyToDraw()); | |
619 } | |
620 | |
621 TEST_P(TileManagerTest, PreventRasterizeOnDemand) { | |
622 // Not enough memory to initialize tiles required for activation. | |
623 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES, false); | |
624 TileVector tiles = | |
625 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); | |
626 | |
627 tile_manager()->AssignMemoryToTiles(global_state_); | |
628 | |
629 // This should make required tiles ready to draw by marking them as | |
630 // required tiles for on-demand raster. | |
631 tile_manager()->DidFinishRunningTasksForTesting(); | |
632 | |
633 EXPECT_TRUE(ready_to_activate()); | |
634 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) | |
635 EXPECT_FALSE((*it)->IsReadyToDraw()); | |
636 } | |
637 | |
638 // If true, the max tile limit should be applied as bytes; if false, | 603 // If true, the max tile limit should be applied as bytes; if false, |
639 // as num_resources_limit. | 604 // as num_resources_limit. |
640 INSTANTIATE_TEST_CASE_P(TileManagerTests, | 605 INSTANTIATE_TEST_CASE_P(TileManagerTests, |
641 TileManagerTest, | 606 TileManagerTest, |
642 ::testing::Values(true, false)); | 607 ::testing::Values(true, false)); |
643 | 608 |
644 class TileManagerTileIteratorTest : public testing::Test, | 609 class TileManagerTileIteratorTest : public testing::Test, |
645 public TileManagerClient { | 610 public TileManagerClient { |
646 public: | 611 public: |
647 TileManagerTileIteratorTest() | 612 TileManagerTileIteratorTest() |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 void CreateHighLowResAndSetAllTilesVisible() { | 699 void CreateHighLowResAndSetAllTilesVisible() { |
735 // Active layer must get updated first so pending layer can share from it. | 700 // Active layer must get updated first so pending layer can share from it. |
736 active_layer_->CreateDefaultTilingsAndTiles(); | 701 active_layer_->CreateDefaultTilingsAndTiles(); |
737 active_layer_->SetAllTilesVisible(); | 702 active_layer_->SetAllTilesVisible(); |
738 pending_layer_->CreateDefaultTilingsAndTiles(); | 703 pending_layer_->CreateDefaultTilingsAndTiles(); |
739 pending_layer_->SetAllTilesVisible(); | 704 pending_layer_->SetAllTilesVisible(); |
740 } | 705 } |
741 | 706 |
742 // TileManagerClient implementation. | 707 // TileManagerClient implementation. |
743 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } | 708 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |
744 virtual void NotifyTileInitialized(const Tile* tile) OVERRIDE {} | 709 virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} |
745 | 710 |
746 TileManager* tile_manager() { return host_impl_.tile_manager(); } | 711 TileManager* tile_manager() { return host_impl_.tile_manager(); } |
747 | 712 |
748 protected: | 713 protected: |
749 GlobalStateThatImpactsTilePriority global_state_; | 714 GlobalStateThatImpactsTilePriority global_state_; |
750 | 715 |
751 TestSharedBitmapManager shared_bitmap_manager_; | 716 TestSharedBitmapManager shared_bitmap_manager_; |
752 TileMemoryLimitPolicy memory_limit_policy_; | 717 TileMemoryLimitPolicy memory_limit_policy_; |
753 int max_tiles_; | 718 int max_tiles_; |
754 bool ready_to_activate_; | 719 bool ready_to_activate_; |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1133 | 1098 |
1134 last_tile = tile; | 1099 last_tile = tile; |
1135 new_content_tiles.insert(tile); | 1100 new_content_tiles.insert(tile); |
1136 } | 1101 } |
1137 | 1102 |
1138 EXPECT_EQ(tile_count, new_content_tiles.size()); | 1103 EXPECT_EQ(tile_count, new_content_tiles.size()); |
1139 EXPECT_EQ(all_tiles, new_content_tiles); | 1104 EXPECT_EQ(all_tiles, new_content_tiles); |
1140 } | 1105 } |
1141 } // namespace | 1106 } // namespace |
1142 } // namespace cc | 1107 } // namespace cc |
OLD | NEW |