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