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" |
11 #include "cc/test/fake_tile_manager_client.h" | |
12 #include "cc/test/test_tile_priorities.h" | 11 #include "cc/test/test_tile_priorities.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 namespace cc { | 14 namespace cc { |
16 namespace { | 15 namespace { |
17 | 16 |
18 class TileManagerTest : public testing::TestWithParam<bool> { | 17 class TileManagerTest : public testing::TestWithParam<bool>, |
| 18 public TileManagerClient { |
19 public: | 19 public: |
20 typedef std::vector<scoped_refptr<Tile> > TileVector; | 20 typedef std::vector<scoped_refptr<Tile> > TileVector; |
21 | 21 |
| 22 TileManagerTest() |
| 23 : memory_limit_policy_(ALLOW_ANYTHING), |
| 24 max_memory_tiles_(0), |
| 25 ready_to_activate_(false) {} |
| 26 |
22 void Initialize(int max_tiles, | 27 void Initialize(int max_tiles, |
23 TileMemoryLimitPolicy memory_limit_policy, | 28 TileMemoryLimitPolicy memory_limit_policy, |
24 TreePriority tree_priority) { | 29 TreePriority tree_priority, |
| 30 bool allow_on_demand_raster = true) { |
25 output_surface_ = FakeOutputSurface::Create3d(); | 31 output_surface_ = FakeOutputSurface::Create3d(); |
26 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 32 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
27 | 33 |
28 resource_provider_ = | 34 resource_provider_ = |
29 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1); | 35 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1); |
30 tile_manager_ = make_scoped_ptr( | 36 tile_manager_ = make_scoped_ptr(new FakeTileManager( |
31 new FakeTileManager(&tile_manager_client_, resource_provider_.get())); | 37 this, resource_provider_.get(), allow_on_demand_raster)); |
32 | 38 |
33 memory_limit_policy_ = memory_limit_policy; | 39 memory_limit_policy_ = memory_limit_policy; |
34 max_memory_tiles_ = max_tiles; | 40 max_memory_tiles_ = max_tiles; |
35 GlobalStateThatImpactsTilePriority state; | 41 GlobalStateThatImpactsTilePriority state; |
36 gfx::Size tile_size = settings_.default_tile_size; | 42 gfx::Size tile_size = settings_.default_tile_size; |
37 | 43 |
38 // The parametrization specifies whether the max tile limit should | 44 // The parametrization specifies whether the max tile limit should |
39 // be applied to RAM or to tile limit. | 45 // be applied to RAM or to tile limit. |
40 if (GetParam()) { | 46 if (GetParam()) { |
41 state.memory_limit_in_bytes = | 47 state.memory_limit_in_bytes = |
(...skipping 24 matching lines...) Expand all Loading... |
66 global_state_ = state; | 72 global_state_ = state; |
67 } | 73 } |
68 | 74 |
69 virtual void TearDown() OVERRIDE { | 75 virtual void TearDown() OVERRIDE { |
70 tile_manager_.reset(NULL); | 76 tile_manager_.reset(NULL); |
71 picture_pile_ = NULL; | 77 picture_pile_ = NULL; |
72 | 78 |
73 testing::Test::TearDown(); | 79 testing::Test::TearDown(); |
74 } | 80 } |
75 | 81 |
| 82 // TileManagerClient implementation. |
| 83 virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |
| 84 |
76 TileVector CreateTilesWithSize(int count, | 85 TileVector CreateTilesWithSize(int count, |
77 TilePriority active_priority, | 86 TilePriority active_priority, |
78 TilePriority pending_priority, | 87 TilePriority pending_priority, |
79 const gfx::Size& tile_size) { | 88 const gfx::Size& tile_size) { |
80 TileVector tiles; | 89 TileVector tiles; |
81 for (int i = 0; i < count; ++i) { | 90 for (int i = 0; i < count; ++i) { |
82 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), | 91 scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), |
83 tile_size, | 92 tile_size, |
84 gfx::Rect(), | 93 gfx::Rect(), |
85 gfx::Rect(), | 94 gfx::Rect(), |
(...skipping 30 matching lines...) Expand all Loading... |
116 int TilesWithLCDCount(const TileVector& tiles) { | 125 int TilesWithLCDCount(const TileVector& tiles) { |
117 int has_lcd_count = 0; | 126 int has_lcd_count = 0; |
118 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); | 127 for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); |
119 ++it) { | 128 ++it) { |
120 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE) | 129 if ((*it)->GetRasterModeForTesting() == HIGH_QUALITY_RASTER_MODE) |
121 ++has_lcd_count; | 130 ++has_lcd_count; |
122 } | 131 } |
123 return has_lcd_count; | 132 return has_lcd_count; |
124 } | 133 } |
125 | 134 |
| 135 bool ready_to_activate() const { return ready_to_activate_; } |
| 136 |
126 protected: | 137 protected: |
127 GlobalStateThatImpactsTilePriority global_state_; | 138 GlobalStateThatImpactsTilePriority global_state_; |
128 | 139 |
129 private: | 140 private: |
130 FakeTileManagerClient tile_manager_client_; | |
131 LayerTreeSettings settings_; | 141 LayerTreeSettings settings_; |
132 scoped_ptr<FakeTileManager> tile_manager_; | 142 scoped_ptr<FakeTileManager> tile_manager_; |
133 scoped_refptr<FakePicturePileImpl> picture_pile_; | 143 scoped_refptr<FakePicturePileImpl> picture_pile_; |
134 FakeOutputSurfaceClient output_surface_client_; | 144 FakeOutputSurfaceClient output_surface_client_; |
135 scoped_ptr<FakeOutputSurface> output_surface_; | 145 scoped_ptr<FakeOutputSurface> output_surface_; |
136 scoped_ptr<ResourceProvider> resource_provider_; | 146 scoped_ptr<ResourceProvider> resource_provider_; |
137 TileMemoryLimitPolicy memory_limit_policy_; | 147 TileMemoryLimitPolicy memory_limit_policy_; |
138 int max_memory_tiles_; | 148 int max_memory_tiles_; |
| 149 bool ready_to_activate_; |
139 }; | 150 }; |
140 | 151 |
141 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { | 152 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { |
142 // A few tiles of each type of priority, with enough memory for all tiles. | 153 // A few tiles of each type of priority, with enough memory for all tiles. |
143 | 154 |
144 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); | 155 Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |
145 TileVector active_now = | 156 TileVector active_now = |
146 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); | 157 CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |
147 TileVector pending_now = | 158 TileVector pending_now = |
148 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); | 159 CreateTiles(3, TilePriority(), TilePriorityForNowBin()); |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 | 515 |
505 tile_manager()->AssignMemoryToTiles(global_state_); | 516 tile_manager()->AssignMemoryToTiles(global_state_); |
506 tile_manager()->GetMemoryStats(&memory_required_bytes, | 517 tile_manager()->GetMemoryStats(&memory_required_bytes, |
507 &memory_nice_to_have_bytes, | 518 &memory_nice_to_have_bytes, |
508 &memory_allocated_bytes, | 519 &memory_allocated_bytes, |
509 &memory_used_bytes); | 520 &memory_used_bytes); |
510 // Allocated bytes should never be more than the memory limit. | 521 // Allocated bytes should never be more than the memory limit. |
511 EXPECT_LE(memory_allocated_bytes, global_state_.memory_limit_in_bytes); | 522 EXPECT_LE(memory_allocated_bytes, global_state_.memory_limit_in_bytes); |
512 } | 523 } |
513 | 524 |
| 525 TEST_P(TileManagerTest, AllowRasterizeOnDemand) { |
| 526 // Not enough memory to initialize tiles required for activation. |
| 527 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES); |
| 528 TileVector tiles = |
| 529 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); |
| 530 |
| 531 tile_manager()->AssignMemoryToTiles(global_state_); |
| 532 |
| 533 // This should make required tiles ready to draw by marking them as |
| 534 // required tiles for on-demand raster. |
| 535 tile_manager()->DidFinishRunningTasksForTesting(); |
| 536 |
| 537 EXPECT_TRUE(ready_to_activate()); |
| 538 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) |
| 539 EXPECT_TRUE((*it)->IsReadyToDraw()); |
| 540 } |
| 541 |
| 542 TEST_P(TileManagerTest, PreventRasterizeOnDemand) { |
| 543 // Not enough memory to initialize tiles required for activation. |
| 544 Initialize(0, ALLOW_ANYTHING, SAME_PRIORITY_FOR_BOTH_TREES, false); |
| 545 TileVector tiles = |
| 546 CreateTiles(2, TilePriority(), TilePriorityRequiredForActivation()); |
| 547 |
| 548 tile_manager()->AssignMemoryToTiles(global_state_); |
| 549 |
| 550 // This should make required tiles ready to draw by marking them as |
| 551 // required tiles for on-demand raster. |
| 552 tile_manager()->DidFinishRunningTasksForTesting(); |
| 553 |
| 554 EXPECT_TRUE(ready_to_activate()); |
| 555 for (TileVector::iterator it = tiles.begin(); it != tiles.end(); ++it) |
| 556 EXPECT_FALSE((*it)->IsReadyToDraw()); |
| 557 } |
| 558 |
514 // If true, the max tile limit should be applied as bytes; if false, | 559 // If true, the max tile limit should be applied as bytes; if false, |
515 // as num_resources_limit. | 560 // as num_resources_limit. |
516 INSTANTIATE_TEST_CASE_P(TileManagerTests, | 561 INSTANTIATE_TEST_CASE_P(TileManagerTests, |
517 TileManagerTest, | 562 TileManagerTest, |
518 ::testing::Values(true, false)); | 563 ::testing::Values(true, false)); |
519 | 564 |
520 } // namespace | 565 } // namespace |
521 } // namespace cc | 566 } // namespace cc |
OLD | NEW |