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_output_surface_client.h" | 8 #include "cc/test/fake_output_surface_client.h" |
9 #include "cc/test/fake_picture_pile_impl.h" | 9 #include "cc/test/fake_picture_pile_impl.h" |
10 #include "cc/test/fake_tile_manager.h" | 10 #include "cc/test/fake_tile_manager.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // The parametrization specifies whether the max tile limit should | 37 // The parametrization specifies whether the max tile limit should |
38 // be applied to RAM or to tile limit. | 38 // be applied to RAM or to tile limit. |
39 if (GetParam()) { | 39 if (GetParam()) { |
40 state.memory_limit_in_bytes = | 40 state.memory_limit_in_bytes = |
41 max_tiles * 4 * tile_size.width() * tile_size.height(); | 41 max_tiles * 4 * tile_size.width() * tile_size.height(); |
42 state.num_resources_limit = 100; | 42 state.num_resources_limit = 100; |
43 } else { | 43 } else { |
44 state.memory_limit_in_bytes = 100 * 1000 * 1000; | 44 state.memory_limit_in_bytes = 100 * 1000 * 1000; |
45 state.num_resources_limit = max_tiles; | 45 state.num_resources_limit = max_tiles; |
46 } | 46 } |
| 47 state.unused_memory_limit_in_bytes = state.memory_limit_in_bytes; |
47 state.memory_limit_policy = memory_limit_policy; | 48 state.memory_limit_policy = memory_limit_policy; |
48 state.tree_priority = tree_priority; | 49 state.tree_priority = tree_priority; |
49 | 50 |
50 tile_manager_->SetGlobalState(state); | 51 tile_manager_->SetGlobalState(state); |
51 picture_pile_ = FakePicturePileImpl::CreatePile(); | 52 picture_pile_ = FakePicturePileImpl::CreatePile(); |
52 } | 53 } |
53 | 54 |
54 void SetTreePriority(TreePriority tree_priority) { | 55 void SetTreePriority(TreePriority tree_priority) { |
55 GlobalStateThatImpactsTilePriority state; | 56 GlobalStateThatImpactsTilePriority state; |
56 gfx::Size tile_size = settings_.default_tile_size; | 57 gfx::Size tile_size = settings_.default_tile_size; |
57 state.memory_limit_in_bytes = | 58 state.memory_limit_in_bytes = |
58 max_memory_tiles_ * 4 * tile_size.width() * tile_size.height(); | 59 max_memory_tiles_ * 4 * tile_size.width() * tile_size.height(); |
| 60 state.unused_memory_limit_in_bytes = state.memory_limit_in_bytes; |
59 state.memory_limit_policy = memory_limit_policy_; | 61 state.memory_limit_policy = memory_limit_policy_; |
60 state.num_resources_limit = 100; | 62 state.num_resources_limit = 100; |
61 state.tree_priority = tree_priority; | 63 state.tree_priority = tree_priority; |
62 tile_manager_->SetGlobalState(state); | 64 tile_manager_->SetGlobalState(state); |
63 } | 65 } |
64 | 66 |
65 virtual void TearDown() OVERRIDE { | 67 virtual void TearDown() OVERRIDE { |
66 tile_manager_.reset(NULL); | 68 tile_manager_.reset(NULL); |
67 picture_pile_ = NULL; | 69 picture_pile_ = NULL; |
68 | 70 |
69 testing::Test::TearDown(); | 71 testing::Test::TearDown(); |
70 } | 72 } |
71 | 73 |
72 TileVector CreateTiles(int count, | 74 TileVector CreateTilesWithSize(int count, |
73 TilePriority active_priority, | 75 TilePriority active_priority, |
74 TilePriority pending_priority) { | 76 TilePriority pending_priority, |
| 77 gfx::Size tile_size) { |
75 TileVector tiles; | 78 TileVector tiles; |
76 for (int i = 0; i < count; ++i) { | 79 for (int i = 0; i < count; ++i) { |
77 scoped_refptr<Tile> tile = | 80 scoped_refptr<Tile> tile = |
78 make_scoped_refptr(new Tile(tile_manager_.get(), | 81 make_scoped_refptr(new Tile(tile_manager_.get(), |
79 picture_pile_.get(), | 82 picture_pile_.get(), |
80 settings_.default_tile_size, | 83 tile_size, |
81 gfx::Rect(), | 84 gfx::Rect(), |
82 gfx::Rect(), | 85 gfx::Rect(), |
83 1.0, | 86 1.0, |
84 0, | 87 0, |
85 0, | 88 0, |
86 true)); | 89 true)); |
87 tile->SetPriority(ACTIVE_TREE, active_priority); | 90 tile->SetPriority(ACTIVE_TREE, active_priority); |
88 tile->SetPriority(PENDING_TREE, pending_priority); | 91 tile->SetPriority(PENDING_TREE, pending_priority); |
89 tiles.push_back(tile); | 92 tiles.push_back(tile); |
90 } | 93 } |
91 return tiles; | 94 return tiles; |
92 } | 95 } |
93 | 96 |
| 97 TileVector CreateTiles(int count, |
| 98 TilePriority active_priority, |
| 99 TilePriority pending_priority) { |
| 100 return CreateTilesWithSize(count, |
| 101 active_priority, |
| 102 pending_priority, |
| 103 settings_.default_tile_size); |
| 104 } |
| 105 |
94 FakeTileManager* tile_manager() { | 106 FakeTileManager* tile_manager() { |
95 return tile_manager_.get(); | 107 return tile_manager_.get(); |
96 } | 108 } |
97 | 109 |
98 int AssignedMemoryCount(const TileVector& tiles) { | 110 int AssignedMemoryCount(const TileVector& tiles) { |
99 int has_memory_count = 0; | 111 int has_memory_count = 0; |
100 for (TileVector::const_iterator it = tiles.begin(); | 112 for (TileVector::const_iterator it = tiles.begin(); |
101 it != tiles.end(); | 113 it != tiles.end(); |
102 ++it) { | 114 ++it) { |
103 if (tile_manager_->HasBeenAssignedMemory(*it)) | 115 if (tile_manager_->HasBeenAssignedMemory(*it)) |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 | 470 |
459 EXPECT_TRUE((*it)->IsReadyToDraw()); | 471 EXPECT_TRUE((*it)->IsReadyToDraw()); |
460 } | 472 } |
461 | 473 |
462 tile_manager()->ManageTiles(); | 474 tile_manager()->ManageTiles(); |
463 | 475 |
464 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); | 476 EXPECT_EQ(0, TilesWithLCDCount(active_tree_tiles)); |
465 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); | 477 EXPECT_EQ(0, TilesWithLCDCount(pending_tree_tiles)); |
466 } | 478 } |
467 | 479 |
| 480 TEST_P(TileManagerTest, RespectMemoryLimit) { |
| 481 Initialize(5, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
| 482 TileVector large_tiles = CreateTiles( |
| 483 5, TilePriorityForNowBin(), TilePriority()); |
| 484 |
| 485 size_t memory_required_bytes; |
| 486 size_t memory_nice_to_have_bytes; |
| 487 size_t memory_allocated_bytes; |
| 488 size_t memory_used_bytes; |
| 489 |
| 490 tile_manager()->ManageTiles(); |
| 491 tile_manager()->GetMemoryStats(&memory_required_bytes, |
| 492 &memory_nice_to_have_bytes, |
| 493 &memory_allocated_bytes, |
| 494 &memory_used_bytes); |
| 495 // Allocated bytes should never be more than the memory limit. |
| 496 EXPECT_LE(memory_allocated_bytes, |
| 497 tile_manager()->GlobalState().memory_limit_in_bytes); |
| 498 |
| 499 // Finish raster of large tiles. |
| 500 tile_manager()->UpdateVisibleTiles(); |
| 501 |
| 502 // Remove all large tiles. This will leave the memory currently |
| 503 // used by these tiles as unused when ManageTiles() is called. |
| 504 large_tiles.clear(); |
| 505 |
| 506 // Create a new set of tiles using a different size. These tiles |
| 507 // can use the memory currently assigned to the lerge tiles but |
| 508 // they can't use the same resources as the size doesn't match. |
| 509 TileVector small_tiles = CreateTilesWithSize( |
| 510 5, TilePriorityForNowBin(), TilePriority(), gfx::Size(128, 128)); |
| 511 |
| 512 tile_manager()->ManageTiles(); |
| 513 tile_manager()->GetMemoryStats(&memory_required_bytes, |
| 514 &memory_nice_to_have_bytes, |
| 515 &memory_allocated_bytes, |
| 516 &memory_used_bytes); |
| 517 // Allocated bytes should never be more than the memory limit. |
| 518 EXPECT_LE(memory_allocated_bytes, |
| 519 tile_manager()->GlobalState().memory_limit_in_bytes); |
| 520 } |
| 521 |
468 // If true, the max tile limit should be applied as bytes; if false, | 522 // If true, the max tile limit should be applied as bytes; if false, |
469 // as num_resources_limit. | 523 // as num_resources_limit. |
470 INSTANTIATE_TEST_CASE_P(TileManagerTests, | 524 INSTANTIATE_TEST_CASE_P(TileManagerTests, |
471 TileManagerTest, | 525 TileManagerTest, |
472 ::testing::Values(true, false)); | 526 ::testing::Values(true, false)); |
473 | 527 |
474 } // namespace | 528 } // namespace |
475 } // namespace cc | 529 } // namespace cc |
OLD | NEW |