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_output_surface.h" |
7 #include "cc/test/fake_tile_manager.h" | 8 #include "cc/test/fake_tile_manager.h" |
8 #include "cc/test/fake_tile_manager_client.h" | 9 #include "cc/test/fake_tile_manager_client.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 | 11 |
11 namespace cc { | 12 namespace cc { |
12 namespace { | 13 namespace { |
13 | 14 |
14 class FakePicturePileImpl : public PicturePileImpl { | 15 class FakePicturePileImpl : public PicturePileImpl { |
15 public: | 16 public: |
16 FakePicturePileImpl() : PicturePileImpl(false) { | 17 FakePicturePileImpl() : PicturePileImpl(false) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 0) {} | 49 0) {} |
49 }; | 50 }; |
50 | 51 |
51 class TileManagerTest : public testing::Test { | 52 class TileManagerTest : public testing::Test { |
52 public: | 53 public: |
53 typedef std::vector<scoped_refptr<Tile> > TileVector; | 54 typedef std::vector<scoped_refptr<Tile> > TileVector; |
54 | 55 |
55 void Initialize(int max_memory_tiles, | 56 void Initialize(int max_memory_tiles, |
56 TileMemoryLimitPolicy memory_limit_policy, | 57 TileMemoryLimitPolicy memory_limit_policy, |
57 TreePriority tree_priority) { | 58 TreePriority tree_priority) { |
58 tile_manager_ = make_scoped_ptr(new FakeTileManager(&tile_manager_client_)); | 59 output_surface_ = FakeOutputSurface::Create3d(); |
| 60 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); |
| 61 tile_manager_ = make_scoped_ptr( |
| 62 new FakeTileManager(&tile_manager_client_, resource_provider_.get())); |
59 | 63 |
60 GlobalStateThatImpactsTilePriority state; | 64 GlobalStateThatImpactsTilePriority state; |
61 gfx::Size tile_size = settings_.default_tile_size; | 65 gfx::Size tile_size = settings_.default_tile_size; |
62 state.memory_limit_in_bytes = | 66 state.memory_limit_in_bytes = |
63 max_memory_tiles * 4 * tile_size.width() * tile_size.height(); | 67 max_memory_tiles * 4 * tile_size.width() * tile_size.height(); |
64 state.memory_limit_policy = memory_limit_policy; | 68 state.memory_limit_policy = memory_limit_policy; |
65 state.tree_priority = tree_priority; | 69 state.tree_priority = tree_priority; |
66 | 70 |
67 tile_manager_->SetGlobalState(state); | 71 tile_manager_->SetGlobalState(state); |
68 picture_pile_ = make_scoped_refptr(new FakePicturePileImpl()); | 72 picture_pile_ = make_scoped_refptr(new FakePicturePileImpl()); |
(...skipping 29 matching lines...) Expand all Loading... |
98 | 102 |
99 FakeTileManager* tile_manager() { | 103 FakeTileManager* tile_manager() { |
100 return tile_manager_.get(); | 104 return tile_manager_.get(); |
101 } | 105 } |
102 | 106 |
103 int AssignedMemoryCounts(const TileVector& tiles) { | 107 int AssignedMemoryCounts(const TileVector& tiles) { |
104 int has_memory_count = 0; | 108 int has_memory_count = 0; |
105 for (TileVector::const_iterator it = tiles.begin(); | 109 for (TileVector::const_iterator it = tiles.begin(); |
106 it != tiles.end(); | 110 it != tiles.end(); |
107 ++it) { | 111 ++it) { |
108 if ((*it)->IsAssignedGpuMemory()) | 112 if ((*it)->HasRasterTaskForTesting()) |
109 ++has_memory_count; | 113 ++has_memory_count; |
| 114 (*it)->ResetRasterTaskForTesting(); |
110 } | 115 } |
111 return has_memory_count; | 116 return has_memory_count; |
112 } | 117 } |
113 | 118 |
114 private: | 119 private: |
115 FakeTileManagerClient tile_manager_client_; | 120 FakeTileManagerClient tile_manager_client_; |
116 LayerTreeSettings settings_; | 121 LayerTreeSettings settings_; |
117 scoped_ptr<FakeTileManager> tile_manager_; | 122 scoped_ptr<FakeTileManager> tile_manager_; |
118 scoped_refptr<FakePicturePileImpl> picture_pile_; | 123 scoped_refptr<FakePicturePileImpl> picture_pile_; |
| 124 scoped_ptr<FakeOutputSurface> output_surface_; |
| 125 scoped_ptr<ResourceProvider> resource_provider_; |
119 }; | 126 }; |
120 | 127 |
121 TEST_F(TileManagerTest, EnoughMemoryAllowAnything) { | 128 TEST_F(TileManagerTest, EnoughMemoryAllowAnything) { |
122 // A few tiles of each type of priority, with enough memory for all tiles. | 129 // A few tiles of each type of priority, with enough memory for all tiles. |
123 | 130 |
124 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 131 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
125 TileVector active_now = | 132 TileVector active_now = |
126 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | 133 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |
127 TileVector pending_now = | 134 TileVector pending_now = |
128 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | 135 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); |
129 TileVector active_pending_soon = CreateTiles( | 136 TileVector active_pending_soon = CreateTiles( |
130 3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); | 137 3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); |
131 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); | 138 TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); |
132 | 139 |
133 tile_manager()->ManageTiles(); | 140 tile_manager()->ManageTiles(); |
134 | 141 |
135 EXPECT_EQ(3, AssignedMemoryCounts(active_now)); | 142 EXPECT_EQ(3, AssignedMemoryCounts(active_now)); |
136 EXPECT_EQ(3, AssignedMemoryCounts(pending_now)); | 143 EXPECT_EQ(3, AssignedMemoryCounts(pending_now)); |
137 EXPECT_EQ(3, AssignedMemoryCounts(active_pending_soon)); | 144 EXPECT_EQ(3, AssignedMemoryCounts(active_pending_soon)); |
138 EXPECT_EQ(1, AssignedMemoryCounts(never_bin)); | 145 EXPECT_EQ(1, AssignedMemoryCounts(never_bin)); |
139 | 146 |
140 active_now.clear(); | 147 active_now.clear(); |
141 pending_now.clear(); | 148 pending_now.clear(); |
142 active_pending_soon.clear(); | 149 active_pending_soon.clear(); |
143 never_bin.clear(); | 150 never_bin.clear(); |
| 151 |
144 TearDown(); | 152 TearDown(); |
145 } | 153 } |
146 | 154 |
147 TEST_F(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { | 155 TEST_F(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { |
148 // A few tiles of each type of priority, with enough memory for all tiles, | 156 // A few tiles of each type of priority, with enough memory for all tiles, |
149 // with the exception of never bin. | 157 // with the exception of never bin. |
150 | 158 |
151 Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); | 159 Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); |
152 TileVector active_now = | 160 TileVector active_now = |
153 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | 161 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 EXPECT_EQ(4, AssignedMemoryCounts(active_tree_tiles)); | 312 EXPECT_EQ(4, AssignedMemoryCounts(active_tree_tiles)); |
305 EXPECT_EQ(0, AssignedMemoryCounts(pending_tree_tiles)); | 313 EXPECT_EQ(0, AssignedMemoryCounts(pending_tree_tiles)); |
306 | 314 |
307 pending_tree_tiles.clear(); | 315 pending_tree_tiles.clear(); |
308 active_tree_tiles.clear(); | 316 active_tree_tiles.clear(); |
309 TearDown(); | 317 TearDown(); |
310 } | 318 } |
311 | 319 |
312 } // namespace | 320 } // namespace |
313 } // namespace cc | 321 } // namespace cc |
OLD | NEW |