| 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_impl_proxy.h" |    7 #include "cc/test/fake_impl_proxy.h" | 
|    8 #include "cc/test/fake_layer_tree_host_impl.h" |    8 #include "cc/test/fake_layer_tree_host_impl.h" | 
|    9 #include "cc/test/fake_output_surface.h" |    9 #include "cc/test/fake_output_surface.h" | 
|   10 #include "cc/test/fake_output_surface_client.h" |   10 #include "cc/test/fake_output_surface_client.h" | 
|   11 #include "cc/test/fake_picture_layer_impl.h" |   11 #include "cc/test/fake_picture_layer_impl.h" | 
|   12 #include "cc/test/fake_picture_pile_impl.h" |   12 #include "cc/test/fake_picture_pile_impl.h" | 
|   13 #include "cc/test/fake_tile_manager.h" |   13 #include "cc/test/fake_tile_manager.h" | 
|   14 #include "cc/test/impl_side_painting_settings.h" |   14 #include "cc/test/impl_side_painting_settings.h" | 
|   15 #include "cc/test/test_shared_bitmap_manager.h" |   15 #include "cc/test/test_shared_bitmap_manager.h" | 
|   16 #include "cc/test/test_tile_priorities.h" |   16 #include "cc/test/test_tile_priorities.h" | 
|   17 #include "cc/trees/layer_tree_impl.h" |   17 #include "cc/trees/layer_tree_impl.h" | 
|   18 #include "testing/gtest/include/gtest/gtest.h" |   18 #include "testing/gtest/include/gtest/gtest.h" | 
|   19  |   19  | 
|   20 namespace cc { |   20 namespace cc { | 
|   21 namespace { |   21 namespace { | 
|   22  |   22  | 
|   23 class TileManagerTest : public testing::TestWithParam<bool>, |  | 
|   24                         public TileManagerClient { |  | 
|   25  public: |  | 
|   26   typedef std::vector<scoped_refptr<Tile> > TileVector; |  | 
|   27  |  | 
|   28   TileManagerTest() |  | 
|   29       : memory_limit_policy_(ALLOW_ANYTHING), |  | 
|   30         max_tiles_(0), |  | 
|   31         ready_to_activate_(false) {} |  | 
|   32  |  | 
|   33   void Initialize(int max_tiles, |  | 
|   34                   TileMemoryLimitPolicy memory_limit_policy, |  | 
|   35                   TreePriority tree_priority) { |  | 
|   36     output_surface_ = FakeOutputSurface::Create3d(); |  | 
|   37     CHECK(output_surface_->BindToClient(&output_surface_client_)); |  | 
|   38  |  | 
|   39     shared_bitmap_manager_.reset(new TestSharedBitmapManager()); |  | 
|   40     resource_provider_ = ResourceProvider::Create( |  | 
|   41         output_surface_.get(), shared_bitmap_manager_.get(), 0, false, 1, |  | 
|   42         false); |  | 
|   43     resource_pool_ = ResourcePool::Create( |  | 
|   44         resource_provider_.get(), GL_TEXTURE_2D, RGBA_8888); |  | 
|   45     tile_manager_ = |  | 
|   46         make_scoped_ptr(new FakeTileManager(this, resource_pool_.get())); |  | 
|   47  |  | 
|   48     memory_limit_policy_ = memory_limit_policy; |  | 
|   49     max_tiles_ = max_tiles; |  | 
|   50     picture_pile_ = FakePicturePileImpl::CreateInfiniteFilledPile(); |  | 
|   51  |  | 
|   52     SetTreePriority(tree_priority); |  | 
|   53   } |  | 
|   54  |  | 
|   55   void SetTreePriority(TreePriority tree_priority) { |  | 
|   56     GlobalStateThatImpactsTilePriority state; |  | 
|   57     gfx::Size tile_size = settings_.default_tile_size; |  | 
|   58  |  | 
|   59     if (UsingMemoryLimit()) { |  | 
|   60       state.soft_memory_limit_in_bytes = |  | 
|   61           max_tiles_ * 4 * tile_size.width() * tile_size.height(); |  | 
|   62       state.num_resources_limit = 100; |  | 
|   63     } else { |  | 
|   64       state.soft_memory_limit_in_bytes = 100 * 1000 * 1000; |  | 
|   65       state.num_resources_limit = max_tiles_; |  | 
|   66     } |  | 
|   67     state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2; |  | 
|   68     state.memory_limit_policy = memory_limit_policy_; |  | 
|   69     state.tree_priority = tree_priority; |  | 
|   70  |  | 
|   71     global_state_ = state; |  | 
|   72     resource_pool_->SetResourceUsageLimits(state.soft_memory_limit_in_bytes, |  | 
|   73                                            state.soft_memory_limit_in_bytes, |  | 
|   74                                            state.num_resources_limit); |  | 
|   75     tile_manager_->SetGlobalStateForTesting(state); |  | 
|   76   } |  | 
|   77  |  | 
|   78   virtual void TearDown() OVERRIDE { |  | 
|   79     tile_manager_.reset(NULL); |  | 
|   80     picture_pile_ = NULL; |  | 
|   81  |  | 
|   82     testing::Test::TearDown(); |  | 
|   83   } |  | 
|   84  |  | 
|   85   // TileManagerClient implementation. |  | 
|   86   virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() OVERRIDE { |  | 
|   87     return picture_layers_; |  | 
|   88   } |  | 
|   89   virtual void NotifyReadyToActivate() OVERRIDE { ready_to_activate_ = true; } |  | 
|   90   virtual void NotifyTileStateChanged(const Tile* tile) OVERRIDE {} |  | 
|   91  |  | 
|   92   TileVector CreateTilesWithSize(int count, |  | 
|   93                                  TilePriority active_priority, |  | 
|   94                                  TilePriority pending_priority, |  | 
|   95                                  const gfx::Size& tile_size) { |  | 
|   96     TileVector tiles; |  | 
|   97     for (int i = 0; i < count; ++i) { |  | 
|   98       scoped_refptr<Tile> tile = tile_manager_->CreateTile(picture_pile_.get(), |  | 
|   99                                                            tile_size, |  | 
|  100                                                            gfx::Rect(), |  | 
|  101                                                            gfx::Rect(), |  | 
|  102                                                            1.0, |  | 
|  103                                                            0, |  | 
|  104                                                            0, |  | 
|  105                                                            0); |  | 
|  106       tile->SetPriority(ACTIVE_TREE, active_priority); |  | 
|  107       tile->SetPriority(PENDING_TREE, pending_priority); |  | 
|  108       tiles.push_back(tile); |  | 
|  109     } |  | 
|  110     return tiles; |  | 
|  111   } |  | 
|  112  |  | 
|  113   TileVector CreateTiles(int count, |  | 
|  114                          TilePriority active_priority, |  | 
|  115                          TilePriority pending_priority) { |  | 
|  116     return CreateTilesWithSize( |  | 
|  117         count, active_priority, pending_priority, settings_.default_tile_size); |  | 
|  118   } |  | 
|  119  |  | 
|  120   FakeTileManager* tile_manager() { return tile_manager_.get(); } |  | 
|  121  |  | 
|  122   int AssignedMemoryCount(const TileVector& tiles) { |  | 
|  123     int has_memory_count = 0; |  | 
|  124     for (TileVector::const_iterator it = tiles.begin(); it != tiles.end(); |  | 
|  125          ++it) { |  | 
|  126       if (tile_manager_->HasBeenAssignedMemory(*it)) |  | 
|  127         ++has_memory_count; |  | 
|  128     } |  | 
|  129     return has_memory_count; |  | 
|  130   } |  | 
|  131  |  | 
|  132   bool ready_to_activate() const { return ready_to_activate_; } |  | 
|  133  |  | 
|  134   // The parametrization specifies whether the max tile limit should |  | 
|  135   // be applied to memory or resources. |  | 
|  136   bool UsingResourceLimit() { return !GetParam(); } |  | 
|  137   bool UsingMemoryLimit() { return GetParam(); } |  | 
|  138  |  | 
|  139  protected: |  | 
|  140   GlobalStateThatImpactsTilePriority global_state_; |  | 
|  141  |  | 
|  142  private: |  | 
|  143   LayerTreeSettings settings_; |  | 
|  144   scoped_ptr<FakeTileManager> tile_manager_; |  | 
|  145   scoped_refptr<FakePicturePileImpl> picture_pile_; |  | 
|  146   FakeOutputSurfaceClient output_surface_client_; |  | 
|  147   scoped_ptr<FakeOutputSurface> output_surface_; |  | 
|  148   scoped_ptr<SharedBitmapManager> shared_bitmap_manager_; |  | 
|  149   scoped_ptr<ResourceProvider> resource_provider_; |  | 
|  150   scoped_ptr<ResourcePool> resource_pool_; |  | 
|  151   TileMemoryLimitPolicy memory_limit_policy_; |  | 
|  152   int max_tiles_; |  | 
|  153   bool ready_to_activate_; |  | 
|  154   std::vector<PictureLayerImpl*> picture_layers_; |  | 
|  155 }; |  | 
|  156  |  | 
|  157 TEST_P(TileManagerTest, EnoughMemoryAllowAnything) { |  | 
|  158   // A few tiles of each type of priority, with enough memory for all tiles. |  | 
|  159  |  | 
|  160   Initialize(10, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  161   TileVector active_now = |  | 
|  162       CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |  | 
|  163   TileVector pending_now = |  | 
|  164       CreateTiles(3, TilePriority(), TilePriorityForNowBin()); |  | 
|  165   TileVector active_pending_soon = |  | 
|  166       CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); |  | 
|  167   TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); |  | 
|  168  |  | 
|  169   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  170  |  | 
|  171   EXPECT_EQ(3, AssignedMemoryCount(active_now)); |  | 
|  172   EXPECT_EQ(3, AssignedMemoryCount(pending_now)); |  | 
|  173   EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); |  | 
|  174   EXPECT_EQ(0, AssignedMemoryCount(never_bin)); |  | 
|  175 } |  | 
|  176  |  | 
|  177 TEST_P(TileManagerTest, EnoughMemoryAllowPrepaintOnly) { |  | 
|  178   // A few tiles of each type of priority, with enough memory for all tiles, |  | 
|  179   // with the exception of never bin. |  | 
|  180  |  | 
|  181   Initialize(10, ALLOW_PREPAINT_ONLY, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  182   TileVector active_now = |  | 
|  183       CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |  | 
|  184   TileVector pending_now = |  | 
|  185       CreateTiles(3, TilePriority(), TilePriorityForNowBin()); |  | 
|  186   TileVector active_pending_soon = |  | 
|  187       CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); |  | 
|  188   TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); |  | 
|  189  |  | 
|  190   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  191  |  | 
|  192   EXPECT_EQ(3, AssignedMemoryCount(active_now)); |  | 
|  193   EXPECT_EQ(3, AssignedMemoryCount(pending_now)); |  | 
|  194   EXPECT_EQ(3, AssignedMemoryCount(active_pending_soon)); |  | 
|  195   EXPECT_EQ(0, AssignedMemoryCount(never_bin)); |  | 
|  196 } |  | 
|  197  |  | 
|  198 TEST_P(TileManagerTest, EnoughMemoryPendingLowResAllowAbsoluteMinimum) { |  | 
|  199   // A few low-res tiles required for activation, with enough memory for all |  | 
|  200   // tiles. |  | 
|  201  |  | 
|  202   Initialize(5, ALLOW_ABSOLUTE_MINIMUM, SAME_PRIORITY_FOR_BOTH_TREES); |  | 
|  203   TileVector pending_low_res = |  | 
|  204       CreateTiles(5, TilePriority(), TilePriorityLowRes()); |  | 
|  205  |  | 
|  206   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  207  |  | 
|  208   EXPECT_EQ(5, AssignedMemoryCount(pending_low_res)); |  | 
|  209 } |  | 
|  210  |  | 
|  211 TEST_P(TileManagerTest, EnoughMemoryAllowAbsoluteMinimum) { |  | 
|  212   // A few tiles of each type of priority, with enough memory for all tiles, |  | 
|  213   // with the exception of never and soon bins. |  | 
|  214  |  | 
|  215   Initialize(10, ALLOW_ABSOLUTE_MINIMUM, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  216   TileVector active_now = |  | 
|  217       CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |  | 
|  218   TileVector pending_now = |  | 
|  219       CreateTiles(3, TilePriority(), TilePriorityForNowBin()); |  | 
|  220   TileVector active_pending_soon = |  | 
|  221       CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); |  | 
|  222   TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); |  | 
|  223  |  | 
|  224   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  225  |  | 
|  226   EXPECT_EQ(3, AssignedMemoryCount(active_now)); |  | 
|  227   EXPECT_EQ(3, AssignedMemoryCount(pending_now)); |  | 
|  228   EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); |  | 
|  229   EXPECT_EQ(0, AssignedMemoryCount(never_bin)); |  | 
|  230 } |  | 
|  231  |  | 
|  232 TEST_P(TileManagerTest, EnoughMemoryAllowNothing) { |  | 
|  233   // A few tiles of each type of priority, with enough memory for all tiles, |  | 
|  234   // but allow nothing should not assign any memory. |  | 
|  235  |  | 
|  236   Initialize(10, ALLOW_NOTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  237   TileVector active_now = |  | 
|  238       CreateTiles(3, TilePriorityForNowBin(), TilePriority()); |  | 
|  239   TileVector pending_now = |  | 
|  240       CreateTiles(3, TilePriority(), TilePriorityForNowBin()); |  | 
|  241   TileVector active_pending_soon = |  | 
|  242       CreateTiles(3, TilePriorityForSoonBin(), TilePriorityForSoonBin()); |  | 
|  243   TileVector never_bin = CreateTiles(1, TilePriority(), TilePriority()); |  | 
|  244  |  | 
|  245   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  246  |  | 
|  247   EXPECT_EQ(0, AssignedMemoryCount(active_now)); |  | 
|  248   EXPECT_EQ(0, AssignedMemoryCount(pending_now)); |  | 
|  249   EXPECT_EQ(0, AssignedMemoryCount(active_pending_soon)); |  | 
|  250   EXPECT_EQ(0, AssignedMemoryCount(never_bin)); |  | 
|  251 } |  | 
|  252  |  | 
|  253 TEST_P(TileManagerTest, PartialOOMMemoryToPending) { |  | 
|  254   // 5 tiles on active tree eventually bin, 5 tiles on pending tree that are |  | 
|  255   // required for activation, but only enough memory for 8 tiles. The result |  | 
|  256   // is all pending tree tiles get memory, and 3 of the active tree tiles |  | 
|  257   // get memory. None of these tiles is needed to avoid calimity (flickering or |  | 
|  258   // raster-on-demand) so the soft memory limit is used. |  | 
|  259  |  | 
|  260   Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  261   TileVector active_tree_tiles = |  | 
|  262       CreateTiles(5, TilePriorityForEventualBin(), TilePriority()); |  | 
|  263   TileVector pending_tree_tiles = |  | 
|  264       CreateTiles(5, TilePriority(), TilePriorityRequiredForActivation()); |  | 
|  265   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  266  |  | 
|  267   EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); |  | 
|  268   EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  269  |  | 
|  270   SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |  | 
|  271   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  272  |  | 
|  273   EXPECT_EQ(3, AssignedMemoryCount(active_tree_tiles)); |  | 
|  274   EXPECT_EQ(5, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  275 } |  | 
|  276  |  | 
|  277 TEST_P(TileManagerTest, PartialOOMMemoryToActive) { |  | 
|  278   // 5 tiles on active tree eventually bin, 5 tiles on pending tree now bin, |  | 
|  279   // but only enough memory for 8 tiles. The result is all active tree tiles |  | 
|  280   // get memory, and 3 of the pending tree tiles get memory. |  | 
|  281   // The pending tiles are not needed to avoid calimity (flickering or |  | 
|  282   // raster-on-demand) and the active tiles fit, so the soft limit is used. |  | 
|  283  |  | 
|  284   Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  285   TileVector active_tree_tiles = |  | 
|  286       CreateTiles(5, TilePriorityForNowBin(), TilePriority()); |  | 
|  287   TileVector pending_tree_tiles = |  | 
|  288       CreateTiles(5, TilePriority(), TilePriorityForNowBin()); |  | 
|  289  |  | 
|  290   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  291  |  | 
|  292   EXPECT_EQ(5, AssignedMemoryCount(active_tree_tiles)); |  | 
|  293   EXPECT_EQ(3, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  294 } |  | 
|  295  |  | 
|  296 TEST_P(TileManagerTest, TotalOOMMemoryToPending) { |  | 
|  297   // 10 tiles on active tree eventually bin, 10 tiles on pending tree that are |  | 
|  298   // required for activation, but only enough tiles for 4 tiles. The result |  | 
|  299   // is 4 pending tree tiles get memory, and none of the active tree tiles |  | 
|  300   // get memory. |  | 
|  301  |  | 
|  302   Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  303   TileVector active_tree_tiles = |  | 
|  304       CreateTiles(10, TilePriorityForEventualBin(), TilePriority()); |  | 
|  305   TileVector pending_tree_tiles = |  | 
|  306       CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); |  | 
|  307  |  | 
|  308   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  309  |  | 
|  310   EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); |  | 
|  311   EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  312  |  | 
|  313   SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |  | 
|  314   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  315  |  | 
|  316   if (UsingResourceLimit()) { |  | 
|  317     EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |  | 
|  318     EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  319   } else { |  | 
|  320     // Pending tiles are now required to avoid calimity (flickering or |  | 
|  321     // raster-on-demand). Hard-limit is used and double the tiles fit. |  | 
|  322     EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |  | 
|  323     EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  324   } |  | 
|  325 } |  | 
|  326  |  | 
|  327 TEST_P(TileManagerTest, TotalOOMActiveSoonMemoryToPending) { |  | 
|  328   // 10 tiles on active tree soon bin, 10 tiles on pending tree that are |  | 
|  329   // required for activation, but only enough tiles for 4 tiles. The result |  | 
|  330   // is 4 pending tree tiles get memory, and none of the active tree tiles |  | 
|  331   // get memory. |  | 
|  332  |  | 
|  333   Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  334   TileVector active_tree_tiles = |  | 
|  335       CreateTiles(10, TilePriorityForSoonBin(), TilePriority()); |  | 
|  336   TileVector pending_tree_tiles = |  | 
|  337       CreateTiles(10, TilePriority(), TilePriorityRequiredForActivation()); |  | 
|  338  |  | 
|  339   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  340  |  | 
|  341   EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); |  | 
|  342   EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  343  |  | 
|  344   SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |  | 
|  345   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  346  |  | 
|  347   if (UsingResourceLimit()) { |  | 
|  348     EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |  | 
|  349     EXPECT_EQ(4, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  350   } else { |  | 
|  351     // Pending tiles are now required to avoid calimity (flickering or |  | 
|  352     // raster-on-demand). Hard-limit is used and double the tiles fit. |  | 
|  353     EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |  | 
|  354     EXPECT_EQ(8, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  355   } |  | 
|  356 } |  | 
|  357  |  | 
|  358 TEST_P(TileManagerTest, TotalOOMMemoryToActive) { |  | 
|  359   // 10 tiles on active tree eventually bin, 10 tiles on pending tree now bin, |  | 
|  360   // but only enough memory for 4 tiles. The result is 4 active tree tiles |  | 
|  361   // get memory, and none of the pending tree tiles get memory. |  | 
|  362  |  | 
|  363   Initialize(4, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  364   TileVector active_tree_tiles = |  | 
|  365       CreateTiles(10, TilePriorityForNowBin(), TilePriority()); |  | 
|  366   TileVector pending_tree_tiles = |  | 
|  367       CreateTiles(10, TilePriority(), TilePriorityForNowBin()); |  | 
|  368  |  | 
|  369   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  370  |  | 
|  371   if (UsingResourceLimit()) { |  | 
|  372     EXPECT_EQ(4, AssignedMemoryCount(active_tree_tiles)); |  | 
|  373     EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  374   } else { |  | 
|  375     // Active tiles are required to avoid calimity (flickering or |  | 
|  376     // raster-on-demand). Hard-limit is used and double the tiles fit. |  | 
|  377     EXPECT_EQ(8, AssignedMemoryCount(active_tree_tiles)); |  | 
|  378     EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  379   } |  | 
|  380 } |  | 
|  381  |  | 
|  382 TEST_P(TileManagerTest, TotalOOMMemoryToNewContent) { |  | 
|  383   // 10 tiles on active tree now bin, 10 tiles on pending tree now bin, |  | 
|  384   // but only enough memory for 8 tiles. Any tile missing would cause |  | 
|  385   // a calamity (flickering or raster-on-demand). Depending on mode, |  | 
|  386   // we should use varying amounts of the higher hard memory limit. |  | 
|  387   if (UsingResourceLimit()) |  | 
|  388     return; |  | 
|  389  |  | 
|  390   Initialize(8, ALLOW_ANYTHING, SMOOTHNESS_TAKES_PRIORITY); |  | 
|  391   TileVector active_tree_tiles = |  | 
|  392       CreateTiles(10, TilePriorityForNowBin(), TilePriority()); |  | 
|  393   TileVector pending_tree_tiles = |  | 
|  394       CreateTiles(10, TilePriority(), TilePriorityForNowBin()); |  | 
|  395  |  | 
|  396   // Active tiles are required to avoid calimity. The hard-limit is used and all |  | 
|  397   // active-tiles fit. No pending tiles are needed to avoid calamity so only 10 |  | 
|  398   // tiles total are used. |  | 
|  399   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  400   EXPECT_EQ(10, AssignedMemoryCount(active_tree_tiles)); |  | 
|  401   EXPECT_EQ(0, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  402  |  | 
|  403   // Even the hard-limit won't save us now. All tiles are required to avoid |  | 
|  404   // a clamity but we only have 16. The tiles will be distribted randomly |  | 
|  405   // given they are identical, in practice depending on their screen location. |  | 
|  406   SetTreePriority(SAME_PRIORITY_FOR_BOTH_TREES); |  | 
|  407   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  408   EXPECT_EQ(16, |  | 
|  409             AssignedMemoryCount(active_tree_tiles) + |  | 
|  410                 AssignedMemoryCount(pending_tree_tiles)); |  | 
|  411  |  | 
|  412   // The pending tree is now more important. Active tiles will take higher |  | 
|  413   // priority if they are ready-to-draw in practice. Importantly though, |  | 
|  414   // pending tiles also utilize the hard-limit. |  | 
|  415   SetTreePriority(NEW_CONTENT_TAKES_PRIORITY); |  | 
|  416   tile_manager()->AssignMemoryToTiles(global_state_); |  | 
|  417   EXPECT_EQ(0, AssignedMemoryCount(active_tree_tiles)); |  | 
|  418   EXPECT_EQ(10, AssignedMemoryCount(pending_tree_tiles)); |  | 
|  419 } |  | 
|  420  |  | 
|  421 // If true, the max tile limit should be applied as bytes; if false, |  | 
|  422 // as num_resources_limit. |  | 
|  423 INSTANTIATE_TEST_CASE_P(TileManagerTests, |  | 
|  424                         TileManagerTest, |  | 
|  425                         ::testing::Values(true, false)); |  | 
|  426  |  | 
|  427 class TileManagerTileIteratorTest : public testing::Test { |   23 class TileManagerTileIteratorTest : public testing::Test { | 
|  428  public: |   24  public: | 
|  429   TileManagerTileIteratorTest() |   25   TileManagerTileIteratorTest() | 
|  430       : memory_limit_policy_(ALLOW_ANYTHING), |   26       : memory_limit_policy_(ALLOW_ANYTHING), | 
|  431         max_tiles_(10000), |   27         max_tiles_(10000), | 
|  432         ready_to_activate_(false), |   28         ready_to_activate_(false), | 
|  433         id_(7), |   29         id_(7), | 
|  434         proxy_(base::MessageLoopProxy::current()), |   30         proxy_(base::MessageLoopProxy::current()), | 
|  435         host_impl_(ImplSidePaintingSettings(), |   31         host_impl_(ImplSidePaintingSettings(), | 
|  436                    &proxy_, |   32                    &proxy_, | 
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  665       ACTIVE_TREE, |  261       ACTIVE_TREE, | 
|  666       viewport, |  262       viewport, | 
|  667       1.0f, |  263       1.0f, | 
|  668       1.0, |  264       1.0, | 
|  669       NULL, |  265       NULL, | 
|  670       active_layer_->render_target(), |  266       active_layer_->render_target(), | 
|  671       active_layer_->draw_transform()); |  267       active_layer_->draw_transform()); | 
|  672  |  268  | 
|  673   // Populate all tiles directly from the tilings. |  269   // Populate all tiles directly from the tilings. | 
|  674   all_tiles.clear(); |  270   all_tiles.clear(); | 
 |  271   pending_layer_->HighResTiling()->CreateAllTilesForTesting(); | 
|  675   std::vector<Tile*> pending_high_res_tiles = |  272   std::vector<Tile*> pending_high_res_tiles = | 
|  676       pending_layer_->HighResTiling()->AllTilesForTesting(); |  273       pending_layer_->HighResTiling()->AllTilesForTesting(); | 
|  677   for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) |  274   for (size_t i = 0; i < pending_high_res_tiles.size(); ++i) | 
|  678     all_tiles.insert(pending_high_res_tiles[i]); |  275     all_tiles.insert(pending_high_res_tiles[i]); | 
|  679  |  276  | 
 |  277   pending_layer_->LowResTiling()->CreateAllTilesForTesting(); | 
|  680   std::vector<Tile*> pending_low_res_tiles = |  278   std::vector<Tile*> pending_low_res_tiles = | 
|  681       pending_layer_->LowResTiling()->AllTilesForTesting(); |  279       pending_layer_->LowResTiling()->AllTilesForTesting(); | 
|  682   for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) |  280   for (size_t i = 0; i < pending_low_res_tiles.size(); ++i) | 
|  683     all_tiles.insert(pending_low_res_tiles[i]); |  281     all_tiles.insert(pending_low_res_tiles[i]); | 
|  684  |  282  | 
 |  283   active_layer_->HighResTiling()->CreateAllTilesForTesting(); | 
|  685   std::vector<Tile*> active_high_res_tiles = |  284   std::vector<Tile*> active_high_res_tiles = | 
|  686       active_layer_->HighResTiling()->AllTilesForTesting(); |  285       active_layer_->HighResTiling()->AllTilesForTesting(); | 
|  687   for (size_t i = 0; i < active_high_res_tiles.size(); ++i) |  286   for (size_t i = 0; i < active_high_res_tiles.size(); ++i) | 
|  688     all_tiles.insert(active_high_res_tiles[i]); |  287     all_tiles.insert(active_high_res_tiles[i]); | 
|  689  |  288  | 
 |  289   active_layer_->LowResTiling()->CreateAllTilesForTesting(); | 
|  690   std::vector<Tile*> active_low_res_tiles = |  290   std::vector<Tile*> active_low_res_tiles = | 
|  691       active_layer_->LowResTiling()->AllTilesForTesting(); |  291       active_layer_->LowResTiling()->AllTilesForTesting(); | 
|  692   for (size_t i = 0; i < active_low_res_tiles.size(); ++i) |  292   for (size_t i = 0; i < active_low_res_tiles.size(); ++i) | 
|  693     all_tiles.insert(active_low_res_tiles[i]); |  293     all_tiles.insert(active_low_res_tiles[i]); | 
|  694  |  294  | 
|  695   Tile* last_tile = NULL; |  295   Tile* last_tile = NULL; | 
|  696   smoothness_tiles.clear(); |  296   smoothness_tiles.clear(); | 
|  697   tile_count = 0; |  297   tile_count = 0; | 
|  698   size_t increasing_distance_tiles = 0u; |  298   size_t increasing_distance_tiles = 0u; | 
|  699   // Here we expect to get increasing ACTIVE_TREE priority_bin. |  299   // Here we expect to get increasing ACTIVE_TREE priority_bin. | 
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  950  |  550  | 
|  951     last_tile = tile; |  551     last_tile = tile; | 
|  952     new_content_tiles.insert(tile); |  552     new_content_tiles.insert(tile); | 
|  953   } |  553   } | 
|  954  |  554  | 
|  955   EXPECT_EQ(tile_count, new_content_tiles.size()); |  555   EXPECT_EQ(tile_count, new_content_tiles.size()); | 
|  956   EXPECT_EQ(all_tiles, new_content_tiles); |  556   EXPECT_EQ(all_tiles, new_content_tiles); | 
|  957 } |  557 } | 
|  958 }  // namespace |  558 }  // namespace | 
|  959 }  // namespace cc |  559 }  // namespace cc | 
| OLD | NEW |