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_output_surface.h" |
8 #include "cc/test/fake_tile_manager.h" | 8 #include "cc/test/fake_tile_manager.h" |
9 #include "cc/test/fake_tile_manager_client.h" | 9 #include "cc/test/fake_tile_manager_client.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 }; | 42 }; |
43 | 43 |
44 class TilePriorityForNowBin : public TilePriority { | 44 class TilePriorityForNowBin : public TilePriority { |
45 public: | 45 public: |
46 TilePriorityForNowBin() : TilePriority( | 46 TilePriorityForNowBin() : TilePriority( |
47 HIGH_RESOLUTION, | 47 HIGH_RESOLUTION, |
48 0, | 48 0, |
49 0) {} | 49 0) {} |
50 }; | 50 }; |
51 | 51 |
| 52 class TilePriorityRequiredForActivation : public TilePriority { |
| 53 public: |
| 54 TilePriorityRequiredForActivation() : TilePriority( |
| 55 HIGH_RESOLUTION, |
| 56 0, |
| 57 0) { |
| 58 required_for_activation = true; |
| 59 } |
| 60 }; |
| 61 |
52 class TileManagerTest : public testing::Test { | 62 class TileManagerTest : public testing::Test { |
53 public: | 63 public: |
54 typedef std::vector<scoped_refptr<Tile> > TileVector; | 64 typedef std::vector<scoped_refptr<Tile> > TileVector; |
55 | 65 |
56 void Initialize(int max_memory_tiles, | 66 void Initialize(int max_memory_tiles, |
57 TileMemoryLimitPolicy memory_limit_policy, | 67 TileMemoryLimitPolicy memory_limit_policy, |
58 TreePriority tree_priority) { | 68 TreePriority tree_priority) { |
59 output_surface_ = FakeOutputSurface::Create3d(); | 69 output_surface_ = FakeOutputSurface::Create3d(); |
60 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); | 70 resource_provider_ = ResourceProvider::Create(output_surface_.get(), 0); |
61 tile_manager_ = make_scoped_ptr( | 71 tile_manager_ = make_scoped_ptr( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 112 |
103 FakeTileManager* tile_manager() { | 113 FakeTileManager* tile_manager() { |
104 return tile_manager_.get(); | 114 return tile_manager_.get(); |
105 } | 115 } |
106 | 116 |
107 int AssignedMemoryCounts(const TileVector& tiles) { | 117 int AssignedMemoryCounts(const TileVector& tiles) { |
108 int has_memory_count = 0; | 118 int has_memory_count = 0; |
109 for (TileVector::const_iterator it = tiles.begin(); | 119 for (TileVector::const_iterator it = tiles.begin(); |
110 it != tiles.end(); | 120 it != tiles.end(); |
111 ++it) { | 121 ++it) { |
112 if ((*it)->HasRasterTaskForTesting()) | 122 if (tile_manager_->HasBeenAssignedMemory(*it)) |
113 ++has_memory_count; | 123 ++has_memory_count; |
114 (*it)->ResetRasterTaskForTesting(); | |
115 } | 124 } |
116 return has_memory_count; | 125 return has_memory_count; |
117 } | 126 } |
118 | 127 |
119 private: | 128 private: |
120 FakeTileManagerClient tile_manager_client_; | 129 FakeTileManagerClient tile_manager_client_; |
121 LayerTreeSettings settings_; | 130 LayerTreeSettings settings_; |
122 scoped_ptr<FakeTileManager> tile_manager_; | 131 scoped_ptr<FakeTileManager> tile_manager_; |
123 scoped_refptr<FakePicturePileImpl> picture_pile_; | 132 scoped_refptr<FakePicturePileImpl> picture_pile_; |
124 scoped_ptr<FakeOutputSurface> output_surface_; | 133 scoped_ptr<FakeOutputSurface> output_surface_; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 EXPECT_EQ(0, AssignedMemoryCounts(never_bin)); | 236 EXPECT_EQ(0, AssignedMemoryCounts(never_bin)); |
228 | 237 |
229 active_now.clear(); | 238 active_now.clear(); |
230 pending_now.clear(); | 239 pending_now.clear(); |
231 active_pending_soon.clear(); | 240 active_pending_soon.clear(); |
232 never_bin.clear(); | 241 never_bin.clear(); |
233 TearDown(); | 242 TearDown(); |
234 } | 243 } |
235 | 244 |
236 TEST_F(TileManagerTest, PartialOOMMemoryToPending) { | 245 TEST_F(TileManagerTest, PartialOOMMemoryToPending) { |
237 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | 246 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are |
238 // but only enough memory for 8 tiles. The result is all pending tree tiles | 247 // required for activation, but only enough memory for 8 tiles. The result |
239 // get memory, and 3 of the active tree tiles get memory. | 248 // is all pending tree tiles get memory, and 3 of the active tree tiles |
| 249 // get memory. |
240 | 250 |
241 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 251 Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
242 TileVector active_tree_tiles = | 252 TileVector active_tree_tiles = |
243 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | 253 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); |
244 TileVector pending_tree_tiles = | 254 TileVector pending_tree_tiles = |
245 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | 255 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); |
246 | 256 |
247 tile_manager()->ManageTiles(); | 257 tile_manager()->ManageTiles(); |
248 | 258 |
| 259 EXPECT_EQ(5, AssignedMemoryCounts(active_tree_tiles)); |
| 260 EXPECT_EQ(3, AssignedMemoryCounts(pending_tree_tiles)); |
| 261 |
| 262 tile_manager()->ReassignMemoryToOOMTilesRequiredForActivation(); |
| 263 |
249 EXPECT_EQ(3, AssignedMemoryCounts(active_tree_tiles)); | 264 EXPECT_EQ(3, AssignedMemoryCounts(active_tree_tiles)); |
250 EXPECT_EQ(5, AssignedMemoryCounts(pending_tree_tiles)); | 265 EXPECT_EQ(5, AssignedMemoryCounts(pending_tree_tiles)); |
251 | 266 |
252 pending_tree_tiles.clear(); | 267 pending_tree_tiles.clear(); |
253 active_tree_tiles.clear(); | 268 active_tree_tiles.clear(); |
254 TearDown(); | 269 TearDown(); |
255 } | 270 } |
256 | 271 |
257 TEST_F(TileManagerTest, PartialOOMMemoryToActive) { | 272 TEST_F(TileManagerTest, PartialOOMMemoryToActive) { |
258 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | 273 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, |
(...skipping 10 matching lines...) Expand all Loading... |
269 | 284 |
270 EXPECT_EQ(5, AssignedMemoryCounts(active_tree_tiles)); | 285 EXPECT_EQ(5, AssignedMemoryCounts(active_tree_tiles)); |
271 EXPECT_EQ(3, AssignedMemoryCounts(pending_tree_tiles)); | 286 EXPECT_EQ(3, AssignedMemoryCounts(pending_tree_tiles)); |
272 | 287 |
273 pending_tree_tiles.clear(); | 288 pending_tree_tiles.clear(); |
274 active_tree_tiles.clear(); | 289 active_tree_tiles.clear(); |
275 TearDown(); | 290 TearDown(); |
276 } | 291 } |
277 | 292 |
278 TEST_F(TileManagerTest, TotalOOMMemoryToPending) { | 293 TEST_F(TileManagerTest, TotalOOMMemoryToPending) { |
279 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | 294 // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are |
280 // but only enough memory for 4 tiles. The result is 4 pending tree tiles | 295 // required for activation, but only enough memory for 4 tiles. The result |
281 // get memory, and none of the active tree tiles get memory. | 296 // is 4 pending tree tiles get memory, and none of the active tree tiles |
| 297 // get memory. |
282 | 298 |
283 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 299 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
284 TileVector active_tree_tiles = | 300 TileVector active_tree_tiles = |
285 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); | 301 CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); |
286 TileVector pending_tree_tiles = | 302 TileVector pending_tree_tiles = |
287 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | 303 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); |
288 | 304 |
289 tile_manager()->ManageTiles(); | 305 tile_manager()->ManageTiles(); |
290 | 306 |
| 307 EXPECT_EQ(4, AssignedMemoryCounts(active_tree_tiles)); |
| 308 EXPECT_EQ(0, AssignedMemoryCounts(pending_tree_tiles)); |
| 309 |
| 310 tile_manager()->ReassignMemoryToOOMTilesRequiredForActivation(); |
| 311 |
291 EXPECT_EQ(0, AssignedMemoryCounts(active_tree_tiles)); | 312 EXPECT_EQ(0, AssignedMemoryCounts(active_tree_tiles)); |
292 EXPECT_EQ(4, AssignedMemoryCounts(pending_tree_tiles)); | 313 EXPECT_EQ(4, AssignedMemoryCounts(pending_tree_tiles)); |
293 | 314 |
294 pending_tree_tiles.clear(); | 315 pending_tree_tiles.clear(); |
295 active_tree_tiles.clear(); | 316 active_tree_tiles.clear(); |
296 TearDown(); | 317 TearDown(); |
297 } | 318 } |
298 | 319 |
299 TEST_F(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { | 320 TEST_F(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { |
300 // 5 tiles on active tree soon bin, 5 tiles on pending tree now bin, | 321 // 5 tiles on active tree soon bin, 5 tiles on pending tree that are |
301 // but only enough memory for 4 tiles. The result is 4 pending tree tiles | 322 // required for activation, but only enough memory for 4 tiles. The result |
302 // get memory, and none of the active tree tiles get memory. | 323 // is 4 pending tree tiles get memory, and none of the active tree tiles |
| 324 // get memory. |
303 | 325 |
304 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 326 Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
305 TileVector active_tree_tiles = | 327 TileVector active_tree_tiles = |
306 CreateTiles(5, TilePriorityForSoonBin(), TilePriority()); | 328 CreateTiles(5, TilePriorityForSoonBin(), TilePriority()); |
307 TileVector pending_tree_tiles = | 329 TileVector pending_tree_tiles = |
308 CreateTiles(5, TilePriority(), TilePriorityForNowBin()); | 330 CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); |
309 | 331 |
310 tile_manager()->ManageTiles(); | 332 tile_manager()->ManageTiles(); |
311 | 333 |
| 334 EXPECT_EQ(4, AssignedMemoryCounts(active_tree_tiles)); |
| 335 EXPECT_EQ(0, AssignedMemoryCounts(pending_tree_tiles)); |
| 336 |
| 337 tile_manager()->ReassignMemoryToOOMTilesRequiredForActivation(); |
| 338 |
312 EXPECT_EQ(0, AssignedMemoryCounts(active_tree_tiles)); | 339 EXPECT_EQ(0, AssignedMemoryCounts(active_tree_tiles)); |
313 EXPECT_EQ(4, AssignedMemoryCounts(pending_tree_tiles)); | 340 EXPECT_EQ(4, AssignedMemoryCounts(pending_tree_tiles)); |
314 | 341 |
315 pending_tree_tiles.clear(); | 342 pending_tree_tiles.clear(); |
316 active_tree_tiles.clear(); | 343 active_tree_tiles.clear(); |
317 TearDown(); | 344 TearDown(); |
318 } | 345 } |
319 | 346 |
320 TEST_F(TileManagerTest, TotalOOMMemoryToActive) { | 347 TEST_F(TileManagerTest, TotalOOMMemoryToActive) { |
321 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, | 348 // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, |
(...skipping 11 matching lines...) Expand all Loading... |
333 EXPECT_EQ(4, AssignedMemoryCounts(active_tree_tiles)); | 360 EXPECT_EQ(4, AssignedMemoryCounts(active_tree_tiles)); |
334 EXPECT_EQ(0, AssignedMemoryCounts(pending_tree_tiles)); | 361 EXPECT_EQ(0, AssignedMemoryCounts(pending_tree_tiles)); |
335 | 362 |
336 pending_tree_tiles.clear(); | 363 pending_tree_tiles.clear(); |
337 active_tree_tiles.clear(); | 364 active_tree_tiles.clear(); |
338 TearDown(); | 365 TearDown(); |
339 } | 366 } |
340 | 367 |
341 } // namespace | 368 } // namespace |
342 } // namespace cc | 369 } // namespace cc |
OLD | NEW |