Chromium Code Reviews| 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 "base/time/time.h" | 5 #include "base/time/time.h" |
| 6 #include "cc/resources/tile.h" | 6 #include "cc/resources/tile.h" |
| 7 #include "cc/resources/tile_priority.h" | 7 #include "cc/resources/tile_priority.h" |
| 8 #include "cc/test/fake_output_surface.h" | 8 #include "cc/test/fake_output_surface.h" |
| 9 #include "cc/test/fake_output_surface_client.h" | 9 #include "cc/test/fake_output_surface_client.h" |
| 10 #include "cc/test/fake_picture_layer_tiling_client.h" | |
| 10 #include "cc/test/fake_picture_pile_impl.h" | 11 #include "cc/test/fake_picture_pile_impl.h" |
| 11 #include "cc/test/fake_tile_manager.h" | 12 #include "cc/test/fake_tile_manager.h" |
| 12 #include "cc/test/fake_tile_manager_client.h" | 13 #include "cc/test/fake_tile_manager_client.h" |
| 13 #include "cc/test/lap_timer.h" | 14 #include "cc/test/lap_timer.h" |
| 14 #include "cc/test/test_tile_priorities.h" | 15 #include "cc/test/test_tile_priorities.h" |
| 15 | 16 |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "testing/perf/perf_test.h" | 18 #include "testing/perf/perf_test.h" |
| 18 | 19 |
| 19 namespace cc { | 20 namespace cc { |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 static const int kTimeLimitMillis = 2000; | 24 static const int kTimeLimitMillis = 2000; |
| 24 static const int kWarmupRuns = 5; | 25 static const int kWarmupRuns = 5; |
| 25 static const int kTimeCheckInterval = 10; | 26 static const int kTimeCheckInterval = 10; |
| 26 | 27 |
| 27 class TileManagerPerfTest : public testing::Test { | 28 class TileManagerPerfTest : public testing::Test { |
| 28 public: | 29 public: |
| 29 typedef std::vector<std::pair<scoped_refptr<Tile>, ManagedTileBin> > | 30 typedef std::vector<std::pair<scoped_refptr<TileBundle>, ManagedTileBin> > |
| 30 TileBinVector; | 31 TileBundleBinVector; |
| 31 | 32 |
| 32 TileManagerPerfTest() | 33 TileManagerPerfTest() |
| 33 : timer_(kWarmupRuns, | 34 : timer_(kWarmupRuns, |
| 34 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), | 35 base::TimeDelta::FromMilliseconds(kTimeLimitMillis), |
| 35 kTimeCheckInterval) {} | 36 kTimeCheckInterval) {} |
| 36 | 37 |
| 37 // Overridden from testing::Test: | 38 // Overridden from testing::Test: |
| 38 virtual void SetUp() OVERRIDE { | 39 virtual void SetUp() OVERRIDE { |
| 39 output_surface_ = FakeOutputSurface::Create3d(); | 40 output_surface_ = FakeOutputSurface::Create3d(); |
| 40 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 41 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 41 | 42 |
| 42 resource_provider_ = | 43 resource_provider_ = |
| 43 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1); | 44 ResourceProvider::Create(output_surface_.get(), NULL, 0, false, 1); |
| 44 size_t raster_task_limit_bytes = 32 * 1024 * 1024; // 16-64MB in practice. | 45 size_t raster_task_limit_bytes = 32 * 1024 * 1024; // 16-64MB in practice. |
| 45 tile_manager_ = make_scoped_ptr( | 46 tile_manager_ = make_scoped_ptr( |
| 46 new FakeTileManager(&tile_manager_client_, | 47 new FakeTileManager(&tile_manager_client_, |
| 47 resource_provider_.get(), | 48 resource_provider_.get(), |
| 48 raster_task_limit_bytes)); | 49 raster_task_limit_bytes)); |
| 49 picture_pile_ = FakePicturePileImpl::CreatePile(); | 50 picture_pile_ = FakePicturePileImpl::CreatePile(); |
| 51 picture_layer_tiling_client_.set_tile_manager(tile_manager_.get()); | |
| 50 } | 52 } |
| 51 | 53 |
| 52 GlobalStateThatImpactsTilePriority GlobalStateForTest() { | 54 GlobalStateThatImpactsTilePriority GlobalStateForTest() { |
| 53 GlobalStateThatImpactsTilePriority state; | 55 GlobalStateThatImpactsTilePriority state; |
| 54 gfx::Size tile_size = settings_.default_tile_size; | 56 gfx::Size tile_size = settings_.default_tile_size; |
| 55 state.memory_limit_in_bytes = | 57 state.memory_limit_in_bytes = |
| 56 10000u * 4u * | 58 10000u * 4u * |
| 57 static_cast<size_t>(tile_size.width() * tile_size.height()); | 59 static_cast<size_t>(tile_size.width() * tile_size.height()); |
| 58 state.num_resources_limit = 10000; | 60 state.num_resources_limit = 10000; |
| 59 state.memory_limit_policy = ALLOW_ANYTHING; | 61 state.memory_limit_policy = ALLOW_ANYTHING; |
| 60 state.tree_priority = SMOOTHNESS_TAKES_PRIORITY; | 62 state.tree_priority = SMOOTHNESS_TAKES_PRIORITY; |
| 61 return state; | 63 return state; |
| 62 } | 64 } |
| 63 | 65 |
| 64 virtual void TearDown() OVERRIDE { | 66 virtual void TearDown() OVERRIDE { |
| 67 picture_layer_tiling_client_.set_tile_manager(NULL); | |
| 65 tile_manager_.reset(NULL); | 68 tile_manager_.reset(NULL); |
| 66 picture_pile_ = NULL; | 69 picture_pile_ = NULL; |
| 67 } | 70 } |
| 68 | 71 |
| 69 TilePriority GetTilePriorityFromBin(ManagedTileBin bin) { | 72 TilePriority GetTilePriorityFromBin(ManagedTileBin bin) { |
| 70 switch (bin) { | 73 switch (bin) { |
| 71 case NOW_AND_READY_TO_DRAW_BIN: | 74 case NOW_AND_READY_TO_DRAW_BIN: |
| 72 case NOW_BIN: | 75 case NOW_BIN: |
| 73 return TilePriorityForNowBin(); | 76 return TilePriorityForNowBin(); |
| 74 case SOON_BIN: | 77 case SOON_BIN: |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 99 case AT_LAST_BIN: | 102 case AT_LAST_BIN: |
| 100 case AT_LAST_AND_ACTIVE_BIN: | 103 case AT_LAST_AND_ACTIVE_BIN: |
| 101 case NEVER_BIN: | 104 case NEVER_BIN: |
| 102 return NOW_BIN; | 105 return NOW_BIN; |
| 103 default: | 106 default: |
| 104 NOTREACHED(); | 107 NOTREACHED(); |
| 105 return NEVER_BIN; | 108 return NEVER_BIN; |
| 106 } | 109 } |
| 107 } | 110 } |
| 108 | 111 |
| 109 void CreateBinTiles(int count, ManagedTileBin bin, TileBinVector* tiles) { | 112 void CreateBinTileBundles(int count, |
| 113 ManagedTileBin bin, | |
| 114 TileBundleBinVector* bundles) { | |
| 110 for (int i = 0; i < count; ++i) { | 115 for (int i = 0; i < count; ++i) { |
| 111 scoped_refptr<Tile> tile = | 116 scoped_refptr<TileBundle> bundle = |
| 112 tile_manager_->CreateTile(picture_pile_.get(), | 117 picture_layer_tiling_client_.CreateTileBundle(gfx::Rect(0, 0, 2, 2)); |
| 113 settings_.default_tile_size, | 118 bundle->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); |
| 114 gfx::Rect(), | 119 bundle->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); |
| 115 gfx::Rect(), | 120 for (int j = 0; j < 4; ++j) { |
| 116 1.0, | 121 scoped_refptr<Tile> tile = |
| 117 0, | 122 tile_manager_->CreateTile(picture_pile_.get(), |
| 118 0, | 123 settings_.default_tile_size, |
| 119 true); | 124 gfx::Rect(), |
| 120 tile->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); | 125 gfx::Rect(), |
| 121 tile->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); | 126 1.0, |
| 122 tiles->push_back(std::make_pair(tile, bin)); | 127 0, |
| 128 0, | |
| 129 true); | |
| 130 bundle->AddTileAt(ACTIVE_TREE, j % 2, j / 2, tile); | |
| 131 bundle->AddTileAt(PENDING_TREE, j % 2, j / 2, tile); | |
| 132 } | |
| 133 bundles->push_back(std::make_pair(bundle, bin)); | |
| 123 } | 134 } |
| 124 } | 135 } |
| 125 | 136 |
| 126 void CreateTiles(int count, TileBinVector* tiles) { | 137 void CreateBundles(int count, TileBundleBinVector* bundles) { |
| 127 // Roughly an equal amount of all bins. | 138 // Roughly an equal amount of all bins. |
| 128 int count_per_bin = count / NUM_BINS; | 139 int count_per_bin = count / NUM_BINS; |
| 129 CreateBinTiles(count_per_bin, NOW_BIN, tiles); | 140 CreateBinTileBundles(count_per_bin, NOW_BIN, bundles); |
| 130 CreateBinTiles(count_per_bin, SOON_BIN, tiles); | 141 CreateBinTileBundles(count_per_bin, SOON_BIN, bundles); |
| 131 CreateBinTiles(count_per_bin, EVENTUALLY_BIN, tiles); | 142 CreateBinTileBundles(count_per_bin, EVENTUALLY_BIN, bundles); |
| 132 CreateBinTiles(count - 3 * count_per_bin, NEVER_BIN, tiles); | 143 CreateBinTileBundles(count - 3 * count_per_bin, NEVER_BIN, bundles); |
| 133 } | 144 } |
| 134 | 145 |
| 135 void RunManageTilesTest(const std::string& test_name, | 146 void RunManageTilesTest(const std::string& test_name, |
| 136 unsigned tile_count, | 147 unsigned tile_count, |
| 137 int priority_change_percent) { | 148 int priority_change_percent) { |
| 138 DCHECK_GE(tile_count, 100u); | 149 DCHECK_GE(tile_count, 100u); |
| 139 DCHECK_GE(priority_change_percent, 0); | 150 DCHECK_GE(priority_change_percent, 0); |
| 140 DCHECK_LE(priority_change_percent, 100); | 151 DCHECK_LE(priority_change_percent, 100); |
| 141 TileBinVector tiles; | 152 TileBundleBinVector bundles; |
| 142 CreateTiles(tile_count, &tiles); | 153 |
| 154 unsigned bundle_count = tile_count / 4; | |
| 155 CreateBundles(bundle_count, &bundles); | |
| 143 timer_.Reset(); | 156 timer_.Reset(); |
| 144 do { | 157 do { |
| 145 if (priority_change_percent > 0) { | 158 if (priority_change_percent > 0) { |
| 146 for (unsigned i = 0; | 159 for (unsigned i = 0; |
| 147 i < tile_count; | 160 i < bundle_count; |
|
vmpstr
2013/11/27 00:03:15
I tried running this loop 4 times, but it made no
enne (OOO)
2013/11/27 01:38:05
Thanks for trying!
| |
| 148 i += 100 / priority_change_percent) { | 161 i += 100 / priority_change_percent) { |
| 149 Tile* tile = tiles[i].first.get(); | 162 TileBundle* bundle = bundles[i].first.get(); |
| 150 ManagedTileBin bin = GetNextBin(tiles[i].second); | 163 ManagedTileBin bin = GetNextBin(bundles[i].second); |
| 151 tile->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); | 164 bundle->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); |
| 152 tile->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); | 165 bundle->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); |
| 153 tiles[i].second = bin; | 166 bundles[i].second = bin; |
| 154 } | 167 } |
| 155 } | 168 } |
| 156 | 169 |
| 157 tile_manager_->ManageTiles(GlobalStateForTest()); | 170 tile_manager_->ManageTiles(GlobalStateForTest()); |
| 158 tile_manager_->CheckForCompletedTasks(); | 171 tile_manager_->CheckForCompletedTasks(); |
| 159 timer_.NextLap(); | 172 timer_.NextLap(); |
| 160 } while (!timer_.HasTimeLimitExpired()); | 173 } while (!timer_.HasTimeLimitExpired()); |
| 161 | 174 |
| 162 perf_test::PrintResult("manage_tiles", "", test_name, | 175 perf_test::PrintResult("manage_tiles", "", test_name, |
| 163 timer_.LapsPerSecond(), "runs/s", true); | 176 timer_.LapsPerSecond(), "runs/s", true); |
| 164 } | 177 } |
| 165 | 178 |
| 166 private: | 179 private: |
| 167 FakeTileManagerClient tile_manager_client_; | 180 FakeTileManagerClient tile_manager_client_; |
| 181 FakePictureLayerTilingClient picture_layer_tiling_client_; | |
| 168 LayerTreeSettings settings_; | 182 LayerTreeSettings settings_; |
| 169 scoped_ptr<FakeTileManager> tile_manager_; | 183 scoped_ptr<FakeTileManager> tile_manager_; |
| 170 scoped_refptr<FakePicturePileImpl> picture_pile_; | 184 scoped_refptr<FakePicturePileImpl> picture_pile_; |
| 171 FakeOutputSurfaceClient output_surface_client_; | 185 FakeOutputSurfaceClient output_surface_client_; |
| 172 scoped_ptr<FakeOutputSurface> output_surface_; | 186 scoped_ptr<FakeOutputSurface> output_surface_; |
| 173 scoped_ptr<ResourceProvider> resource_provider_; | 187 scoped_ptr<ResourceProvider> resource_provider_; |
| 174 LapTimer timer_; | 188 LapTimer timer_; |
| 175 }; | 189 }; |
| 176 | 190 |
| 177 TEST_F(TileManagerPerfTest, ManageTiles) { | 191 TEST_F(TileManagerPerfTest, ManageTiles) { |
| 178 RunManageTilesTest("100_0", 100, 0); | 192 RunManageTilesTest("100_0", 100, 0); |
| 179 RunManageTilesTest("1000_0", 1000, 0); | 193 RunManageTilesTest("1000_0", 1000, 0); |
| 180 RunManageTilesTest("10000_0", 10000, 0); | 194 RunManageTilesTest("10000_0", 10000, 0); |
| 181 RunManageTilesTest("100_10", 100, 10); | 195 RunManageTilesTest("100_10", 100, 10); |
| 182 RunManageTilesTest("1000_10", 1000, 10); | 196 RunManageTilesTest("1000_10", 1000, 10); |
| 183 RunManageTilesTest("10000_10", 10000, 10); | 197 RunManageTilesTest("10000_10", 10000, 10); |
| 184 RunManageTilesTest("100_100", 100, 100); | 198 RunManageTilesTest("100_100", 100, 100); |
| 185 RunManageTilesTest("1000_100", 1000, 100); | 199 RunManageTilesTest("1000_100", 1000, 100); |
| 186 RunManageTilesTest("10000_100", 10000, 100); | 200 RunManageTilesTest("10000_100", 10000, 100); |
| 187 } | 201 } |
| 188 | 202 |
| 189 } // namespace | 203 } // namespace |
| 190 | 204 |
| 191 } // namespace cc | 205 } // namespace cc |
| OLD | NEW |