| 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_ = | 
 |   52         make_scoped_ptr(new FakePictureLayerTilingClient(tile_manager_.get())); | 
|   50   } |   53   } | 
|   51  |   54  | 
|   52   GlobalStateThatImpactsTilePriority GlobalStateForTest() { |   55   GlobalStateThatImpactsTilePriority GlobalStateForTest() { | 
|   53     GlobalStateThatImpactsTilePriority state; |   56     GlobalStateThatImpactsTilePriority state; | 
|   54     gfx::Size tile_size = settings_.default_tile_size; |   57     gfx::Size tile_size = settings_.default_tile_size; | 
|   55     state.memory_limit_in_bytes = |   58     state.memory_limit_in_bytes = | 
|   56         10000u * 4u * |   59         10000u * 4u * | 
|   57         static_cast<size_t>(tile_size.width() * tile_size.height()); |   60         static_cast<size_t>(tile_size.width() * tile_size.height()); | 
|   58     state.num_resources_limit = 10000; |   61     state.num_resources_limit = 10000; | 
|   59     state.memory_limit_policy = ALLOW_ANYTHING; |   62     state.memory_limit_policy = ALLOW_ANYTHING; | 
|   60     state.tree_priority = SMOOTHNESS_TAKES_PRIORITY; |   63     state.tree_priority = SMOOTHNESS_TAKES_PRIORITY; | 
|   61     return state; |   64     return state; | 
|   62   } |   65   } | 
|   63  |   66  | 
|   64   virtual void TearDown() OVERRIDE { |   67   virtual void TearDown() OVERRIDE { | 
 |   68     picture_layer_tiling_client_.reset(NULL); | 
|   65     tile_manager_.reset(NULL); |   69     tile_manager_.reset(NULL); | 
|   66     picture_pile_ = NULL; |   70     picture_pile_ = NULL; | 
|   67   } |   71   } | 
|   68  |   72  | 
|   69   TilePriority GetTilePriorityFromBin(ManagedTileBin bin) { |   73   TilePriority GetTilePriorityFromBin(ManagedTileBin bin) { | 
|   70     switch (bin) { |   74     switch (bin) { | 
|   71       case NOW_AND_READY_TO_DRAW_BIN: |   75       case NOW_AND_READY_TO_DRAW_BIN: | 
|   72       case NOW_BIN: |   76       case NOW_BIN: | 
|   73         return TilePriorityForNowBin(); |   77         return TilePriorityForNowBin(); | 
|   74       case SOON_BIN: |   78       case SOON_BIN: | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|   99       case AT_LAST_BIN: |  103       case AT_LAST_BIN: | 
|  100       case AT_LAST_AND_ACTIVE_BIN: |  104       case AT_LAST_AND_ACTIVE_BIN: | 
|  101       case NEVER_BIN: |  105       case NEVER_BIN: | 
|  102         return NOW_BIN; |  106         return NOW_BIN; | 
|  103       default: |  107       default: | 
|  104         NOTREACHED(); |  108         NOTREACHED(); | 
|  105         return NEVER_BIN; |  109         return NEVER_BIN; | 
|  106     } |  110     } | 
|  107   } |  111   } | 
|  108  |  112  | 
|  109   void CreateBinTiles(int count, ManagedTileBin bin, TileBinVector* tiles) { |  113   void CreateBinTileBundles(int count, | 
 |  114                             ManagedTileBin bin, | 
 |  115                             TileBundleBinVector* bundles) { | 
|  110     for (int i = 0; i < count; ++i) { |  116     for (int i = 0; i < count; ++i) { | 
|  111       scoped_refptr<Tile> tile = |  117       scoped_refptr<TileBundle> bundle = | 
|  112           tile_manager_->CreateTile(picture_pile_.get(), |  118           picture_layer_tiling_client_->CreateTileBundle(0, 0, 2, 2); | 
|  113                                     settings_.default_tile_size, |  119       bundle->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); | 
|  114                                     gfx::Rect(), |  120       bundle->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); | 
|  115                                     gfx::Rect(), |  121       for (int j = 0; j < 4; ++j) { | 
|  116                                     1.0, |  122         scoped_refptr<Tile> tile = | 
|  117                                     0, |  123             tile_manager_->CreateTile(picture_pile_.get(), | 
|  118                                     0, |  124                                       settings_.default_tile_size, | 
|  119                                     Tile::USE_LCD_TEXT); |  125                                       gfx::Rect(), | 
|  120       tile->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); |  126                                       gfx::Rect(), | 
|  121       tile->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); |  127                                       1.0, | 
|  122       tiles->push_back(std::make_pair(tile, bin)); |  128                                       0, | 
 |  129                                       0, | 
 |  130                                       Tile::USE_LCD_TEXT); | 
 |  131         bundle->AddTileAt(ACTIVE_TREE, j % 2, j / 2, tile); | 
 |  132         bundle->AddTileAt(PENDING_TREE, j % 2, j / 2, tile); | 
 |  133       } | 
 |  134       bundles->push_back(std::make_pair(bundle, bin)); | 
|  123     } |  135     } | 
|  124   } |  136   } | 
|  125  |  137  | 
|  126   void CreateTiles(int count, TileBinVector* tiles) { |  138   void CreateBundles(int count, TileBundleBinVector* bundles) { | 
|  127     // Roughly an equal amount of all bins. |  139     // Roughly an equal amount of all bins. | 
|  128     int count_per_bin = count / NUM_BINS; |  140     int count_per_bin = count / NUM_BINS; | 
|  129     CreateBinTiles(count_per_bin, NOW_BIN, tiles); |  141     CreateBinTileBundles(count_per_bin, NOW_BIN, bundles); | 
|  130     CreateBinTiles(count_per_bin, SOON_BIN, tiles); |  142     CreateBinTileBundles(count_per_bin, SOON_BIN, bundles); | 
|  131     CreateBinTiles(count_per_bin, EVENTUALLY_BIN, tiles); |  143     CreateBinTileBundles(count_per_bin, EVENTUALLY_BIN, bundles); | 
|  132     CreateBinTiles(count - 3 * count_per_bin, NEVER_BIN, tiles); |  144     CreateBinTileBundles(count - 3 * count_per_bin, NEVER_BIN, bundles); | 
|  133   } |  145   } | 
|  134  |  146  | 
|  135   void RunManageTilesTest(const std::string& test_name, |  147   void RunManageTilesTest(const std::string& test_name, | 
|  136                           unsigned tile_count, |  148                           unsigned tile_count, | 
|  137                           int priority_change_percent) { |  149                           int priority_change_percent) { | 
|  138     DCHECK_GE(tile_count, 100u); |  150     DCHECK_GE(tile_count, 100u); | 
|  139     DCHECK_GE(priority_change_percent, 0); |  151     DCHECK_GE(priority_change_percent, 0); | 
|  140     DCHECK_LE(priority_change_percent, 100); |  152     DCHECK_LE(priority_change_percent, 100); | 
|  141     TileBinVector tiles; |  153     TileBundleBinVector bundles; | 
|  142     CreateTiles(tile_count, &tiles); |  154  | 
 |  155     unsigned bundle_count = tile_count / 4; | 
 |  156     CreateBundles(bundle_count, &bundles); | 
|  143     timer_.Reset(); |  157     timer_.Reset(); | 
|  144     do { |  158     do { | 
|  145       if (priority_change_percent > 0) { |  159       if (priority_change_percent > 0) { | 
|  146         for (unsigned i = 0; |  160         for (unsigned i = 0; | 
|  147              i < tile_count; |  161              i < bundle_count; | 
|  148              i += 100 / priority_change_percent) { |  162              i += 100 / priority_change_percent) { | 
|  149           Tile* tile = tiles[i].first.get(); |  163           TileBundle* bundle = bundles[i].first.get(); | 
|  150           ManagedTileBin bin = GetNextBin(tiles[i].second); |  164           ManagedTileBin bin = GetNextBin(bundles[i].second); | 
|  151           tile->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); |  165           bundle->SetPriority(ACTIVE_TREE, GetTilePriorityFromBin(bin)); | 
|  152           tile->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); |  166           bundle->SetPriority(PENDING_TREE, GetTilePriorityFromBin(bin)); | 
|  153           tiles[i].second = bin; |  167           bundles[i].second = bin; | 
|  154         } |  168         } | 
|  155       } |  169       } | 
|  156  |  170  | 
|  157       tile_manager_->ManageTiles(GlobalStateForTest()); |  171       tile_manager_->ManageTiles(GlobalStateForTest()); | 
|  158       tile_manager_->CheckForCompletedTasks(); |  172       tile_manager_->CheckForCompletedTasks(); | 
|  159       timer_.NextLap(); |  173       timer_.NextLap(); | 
|  160     } while (!timer_.HasTimeLimitExpired()); |  174     } while (!timer_.HasTimeLimitExpired()); | 
|  161  |  175  | 
|  162     perf_test::PrintResult("manage_tiles", "", test_name, |  176     perf_test::PrintResult("manage_tiles", "", test_name, | 
|  163                            timer_.LapsPerSecond(), "runs/s", true); |  177                            timer_.LapsPerSecond(), "runs/s", true); | 
|  164   } |  178   } | 
|  165  |  179  | 
|  166  private: |  180  private: | 
|  167   FakeTileManagerClient tile_manager_client_; |  181   FakeTileManagerClient tile_manager_client_; | 
 |  182   scoped_ptr<FakePictureLayerTilingClient> picture_layer_tiling_client_; | 
|  168   LayerTreeSettings settings_; |  183   LayerTreeSettings settings_; | 
|  169   scoped_ptr<FakeTileManager> tile_manager_; |  184   scoped_ptr<FakeTileManager> tile_manager_; | 
|  170   scoped_refptr<FakePicturePileImpl> picture_pile_; |  185   scoped_refptr<FakePicturePileImpl> picture_pile_; | 
|  171   FakeOutputSurfaceClient output_surface_client_; |  186   FakeOutputSurfaceClient output_surface_client_; | 
|  172   scoped_ptr<FakeOutputSurface> output_surface_; |  187   scoped_ptr<FakeOutputSurface> output_surface_; | 
|  173   scoped_ptr<ResourceProvider> resource_provider_; |  188   scoped_ptr<ResourceProvider> resource_provider_; | 
|  174   LapTimer timer_; |  189   LapTimer timer_; | 
|  175 }; |  190 }; | 
|  176  |  191  | 
|  177 TEST_F(TileManagerPerfTest, ManageTiles) { |  192 TEST_F(TileManagerPerfTest, ManageTiles) { | 
|  178   RunManageTilesTest("100_0", 100, 0); |  193   RunManageTilesTest("100_0", 100, 0); | 
|  179   RunManageTilesTest("1000_0", 1000, 0); |  194   RunManageTilesTest("1000_0", 1000, 0); | 
|  180   RunManageTilesTest("10000_0", 10000, 0); |  195   RunManageTilesTest("10000_0", 10000, 0); | 
|  181   RunManageTilesTest("100_10", 100, 10); |  196   RunManageTilesTest("100_10", 100, 10); | 
|  182   RunManageTilesTest("1000_10", 1000, 10); |  197   RunManageTilesTest("1000_10", 1000, 10); | 
|  183   RunManageTilesTest("10000_10", 10000, 10); |  198   RunManageTilesTest("10000_10", 10000, 10); | 
|  184   RunManageTilesTest("100_100", 100, 100); |  199   RunManageTilesTest("100_100", 100, 100); | 
|  185   RunManageTilesTest("1000_100", 1000, 100); |  200   RunManageTilesTest("1000_100", 1000, 100); | 
|  186   RunManageTilesTest("10000_100", 10000, 100); |  201   RunManageTilesTest("10000_100", 10000, 100); | 
|  187 } |  202 } | 
|  188  |  203  | 
|  189 }  // namespace |  204 }  // namespace | 
|  190  |  205  | 
|  191 }  // namespace cc |  206 }  // namespace cc | 
| OLD | NEW |