| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 namespace { | 71 namespace { |
| 72 | 72 |
| 73 class LayerTreeHostTest : public LayerTreeTest {}; | 73 class LayerTreeHostTest : public LayerTreeTest {}; |
| 74 | 74 |
| 75 // Test if the LTHI receives ReadyToActivate notifications from the TileManager | 75 // Test if the LTHI receives ReadyToActivate notifications from the TileManager |
| 76 // when no raster tasks get scheduled. | 76 // when no raster tasks get scheduled. |
| 77 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { | 77 class LayerTreeHostTestReadyToActivateEmpty : public LayerTreeHostTest { |
| 78 public: | 78 public: |
| 79 LayerTreeHostTestReadyToActivateEmpty() | 79 LayerTreeHostTestReadyToActivateEmpty() |
| 80 : did_notify_ready_to_activate_(false), | 80 : did_notify_ready_to_activate_(false), |
| 81 all_tiles_required_for_activation_are_ready_to_draw_(false), | 81 all_tiles_required_for_activation_are_ready_to_draw_(false) {} |
| 82 required_for_activation_count_(0) {} | |
| 83 | 82 |
| 84 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 83 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 85 | 84 |
| 86 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { | 85 void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| 87 const std::vector<PictureLayerImpl*>& layers = | 86 bool ready_to_activate_on_commit_complete = |
| 88 impl->sync_tree()->picture_layers(); | 87 impl->tile_manager()->IsReadyToActivate(); |
| 89 required_for_activation_count_ = 0; | 88 // This being true means that we have no tiles required for activation |
| 90 for (const auto& layer : layers) { | 89 // (since we had no time to prepare any tiles if they were required for |
| 91 FakePictureLayerImpl* fake_layer = | 90 // activation). |
| 92 static_cast<FakePictureLayerImpl*>(layer); | 91 EXPECT_TRUE(ready_to_activate_on_commit_complete); |
| 93 required_for_activation_count_ += | |
| 94 fake_layer->CountTilesRequiredForActivation(); | |
| 95 } | |
| 96 } | 92 } |
| 97 | 93 |
| 98 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { | 94 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { |
| 99 did_notify_ready_to_activate_ = true; | 95 did_notify_ready_to_activate_ = true; |
| 100 all_tiles_required_for_activation_are_ready_to_draw_ = | 96 all_tiles_required_for_activation_are_ready_to_draw_ = |
| 101 impl->tile_manager()->IsReadyToActivate(); | 97 impl->tile_manager()->IsReadyToActivate(); |
| 102 EndTest(); | 98 EndTest(); |
| 103 } | 99 } |
| 104 | 100 |
| 105 void AfterTest() override { | 101 void AfterTest() override { |
| 106 EXPECT_TRUE(did_notify_ready_to_activate_); | 102 EXPECT_TRUE(did_notify_ready_to_activate_); |
| 107 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); | 103 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); |
| 108 EXPECT_EQ(size_t(0), required_for_activation_count_); | |
| 109 } | 104 } |
| 110 | 105 |
| 111 protected: | 106 private: |
| 112 bool did_notify_ready_to_activate_; | 107 bool did_notify_ready_to_activate_; |
| 113 bool all_tiles_required_for_activation_are_ready_to_draw_; | 108 bool all_tiles_required_for_activation_are_ready_to_draw_; |
| 114 size_t required_for_activation_count_; | |
| 115 }; | 109 }; |
| 116 | 110 |
| 117 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateEmpty); | 111 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateEmpty); |
| 118 | 112 |
| 119 // Test if the LTHI receives ReadyToActivate notifications from the TileManager | 113 // Test if the LTHI receives ReadyToActivate notifications from the TileManager |
| 120 // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled. | 114 // when some raster tasks flagged as REQUIRED_FOR_ACTIVATION got scheduled. |
| 121 class LayerTreeHostTestReadyToActivateNonEmpty | 115 class LayerTreeHostTestReadyToActivateNonEmpty : public LayerTreeHostTest { |
| 122 : public LayerTreeHostTestReadyToActivateEmpty { | |
| 123 public: | 116 public: |
| 117 LayerTreeHostTestReadyToActivateNonEmpty() |
| 118 : did_notify_ready_to_activate_(false), |
| 119 all_tiles_required_for_activation_are_ready_to_draw_(false) {} |
| 120 |
| 124 void SetupTree() override { | 121 void SetupTree() override { |
| 125 client_.set_fill_with_nonsolid_color(true); | 122 client_.set_fill_with_nonsolid_color(true); |
| 126 scoped_refptr<FakePictureLayer> root_layer = | 123 scoped_refptr<FakePictureLayer> root_layer = |
| 127 FakePictureLayer::Create(&client_); | 124 FakePictureLayer::Create(&client_); |
| 128 root_layer->SetBounds(gfx::Size(1024, 1024)); | 125 root_layer->SetBounds(gfx::Size(1024, 1024)); |
| 129 root_layer->SetIsDrawable(true); | 126 root_layer->SetIsDrawable(true); |
| 130 | 127 |
| 131 layer_tree_host()->SetRootLayer(root_layer); | 128 layer_tree_host()->SetRootLayer(root_layer); |
| 132 LayerTreeHostTest::SetupTree(); | 129 LayerTreeHostTest::SetupTree(); |
| 133 } | 130 } |
| 134 | 131 |
| 132 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 133 |
| 134 void NotifyReadyToActivateOnThread(LayerTreeHostImpl* impl) override { |
| 135 did_notify_ready_to_activate_ = true; |
| 136 all_tiles_required_for_activation_are_ready_to_draw_ = |
| 137 impl->tile_manager()->IsReadyToActivate(); |
| 138 EndTest(); |
| 139 } |
| 140 |
| 135 void AfterTest() override { | 141 void AfterTest() override { |
| 136 EXPECT_TRUE(did_notify_ready_to_activate_); | 142 EXPECT_TRUE(did_notify_ready_to_activate_); |
| 137 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); | 143 EXPECT_TRUE(all_tiles_required_for_activation_are_ready_to_draw_); |
| 138 EXPECT_LE(size_t(1), required_for_activation_count_); | |
| 139 } | 144 } |
| 140 | 145 |
| 141 private: | 146 private: |
| 142 FakeContentLayerClient client_; | 147 FakeContentLayerClient client_; |
| 148 bool did_notify_ready_to_activate_; |
| 149 bool all_tiles_required_for_activation_are_ready_to_draw_; |
| 143 }; | 150 }; |
| 144 | 151 |
| 145 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty); | 152 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToActivateNonEmpty); |
| 146 | 153 |
| 147 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when | 154 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when |
| 148 // no raster tasks get scheduled. | 155 // no raster tasks get scheduled. |
| 149 class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest { | 156 class LayerTreeHostTestReadyToDrawEmpty : public LayerTreeHostTest { |
| 150 public: | 157 public: |
| 151 LayerTreeHostTestReadyToDrawEmpty() | 158 LayerTreeHostTestReadyToDrawEmpty() |
| 152 : did_notify_ready_to_draw_(false), | 159 : did_notify_ready_to_draw_(false), |
| 153 all_tiles_required_for_draw_are_ready_to_draw_(false), | 160 all_tiles_required_for_draw_are_ready_to_draw_(false) {} |
| 154 required_for_draw_count_(0) {} | |
| 155 | 161 |
| 156 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 162 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 157 | 163 |
| 158 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override { | 164 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override { |
| 159 did_notify_ready_to_draw_ = true; | 165 did_notify_ready_to_draw_ = true; |
| 160 const std::vector<PictureLayerImpl*>& layers = | |
| 161 impl->active_tree()->picture_layers(); | |
| 162 all_tiles_required_for_draw_are_ready_to_draw_ = | 166 all_tiles_required_for_draw_are_ready_to_draw_ = |
| 163 impl->tile_manager()->IsReadyToDraw(); | 167 impl->tile_manager()->IsReadyToDraw(); |
| 164 for (const auto& layer : layers) { | |
| 165 FakePictureLayerImpl* fake_layer = | |
| 166 static_cast<FakePictureLayerImpl*>(layer); | |
| 167 required_for_draw_count_ += fake_layer->CountTilesRequiredForDraw(); | |
| 168 } | |
| 169 | |
| 170 EndTest(); | 168 EndTest(); |
| 171 } | 169 } |
| 172 | 170 |
| 173 void AfterTest() override { | 171 void AfterTest() override { |
| 174 EXPECT_TRUE(did_notify_ready_to_draw_); | 172 EXPECT_TRUE(did_notify_ready_to_draw_); |
| 175 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_); | 173 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_); |
| 176 EXPECT_EQ(size_t(0), required_for_draw_count_); | |
| 177 } | 174 } |
| 178 | 175 |
| 179 protected: | 176 private: |
| 180 bool did_notify_ready_to_draw_; | 177 bool did_notify_ready_to_draw_; |
| 181 bool all_tiles_required_for_draw_are_ready_to_draw_; | 178 bool all_tiles_required_for_draw_are_ready_to_draw_; |
| 182 size_t required_for_draw_count_; | |
| 183 }; | 179 }; |
| 184 | 180 |
| 185 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDrawEmpty); | 181 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDrawEmpty); |
| 186 | 182 |
| 187 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when | 183 // Test if the LTHI receives ReadyToDraw notifications from the TileManager when |
| 188 // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled. | 184 // some raster tasks flagged as REQUIRED_FOR_DRAW got scheduled. |
| 189 class LayerTreeHostTestReadyToDrawNonEmpty | 185 class LayerTreeHostTestReadyToDrawNonEmpty : public LayerTreeHostTest { |
| 190 : public LayerTreeHostTestReadyToDrawEmpty { | |
| 191 public: | 186 public: |
| 187 LayerTreeHostTestReadyToDrawNonEmpty() |
| 188 : did_notify_ready_to_draw_(false), |
| 189 all_tiles_required_for_draw_are_ready_to_draw_(false) {} |
| 190 |
| 192 void SetupTree() override { | 191 void SetupTree() override { |
| 193 client_.set_fill_with_nonsolid_color(true); | 192 client_.set_fill_with_nonsolid_color(true); |
| 194 scoped_refptr<FakePictureLayer> root_layer = | 193 scoped_refptr<FakePictureLayer> root_layer = |
| 195 FakePictureLayer::Create(&client_); | 194 FakePictureLayer::Create(&client_); |
| 196 root_layer->SetBounds(gfx::Size(1024, 1024)); | 195 root_layer->SetBounds(gfx::Size(1024, 1024)); |
| 197 root_layer->SetIsDrawable(true); | 196 root_layer->SetIsDrawable(true); |
| 198 | 197 |
| 199 layer_tree_host()->SetRootLayer(root_layer); | 198 layer_tree_host()->SetRootLayer(root_layer); |
| 200 LayerTreeHostTest::SetupTree(); | 199 LayerTreeHostTest::SetupTree(); |
| 201 } | 200 } |
| 202 | 201 |
| 202 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 203 |
| 204 void NotifyReadyToDrawOnThread(LayerTreeHostImpl* impl) override { |
| 205 did_notify_ready_to_draw_ = true; |
| 206 all_tiles_required_for_draw_are_ready_to_draw_ = |
| 207 impl->tile_manager()->IsReadyToDraw(); |
| 208 EndTest(); |
| 209 } |
| 210 |
| 203 void AfterTest() override { | 211 void AfterTest() override { |
| 204 EXPECT_TRUE(did_notify_ready_to_draw_); | 212 EXPECT_TRUE(did_notify_ready_to_draw_); |
| 205 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_); | 213 EXPECT_TRUE(all_tiles_required_for_draw_are_ready_to_draw_); |
| 206 EXPECT_LE(size_t(1), required_for_draw_count_); | |
| 207 } | 214 } |
| 208 | 215 |
| 209 private: | 216 private: |
| 210 FakeContentLayerClient client_; | 217 FakeContentLayerClient client_; |
| 218 bool did_notify_ready_to_draw_; |
| 219 bool all_tiles_required_for_draw_are_ready_to_draw_; |
| 211 }; | 220 }; |
| 212 | 221 |
| 213 // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in | 222 // Note: With this test setup, we only get tiles flagged as REQUIRED_FOR_DRAW in |
| 214 // single threaded mode. | 223 // single threaded mode. |
| 215 SINGLE_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty); | 224 SINGLE_THREAD_IMPL_TEST_F(LayerTreeHostTestReadyToDrawNonEmpty); |
| 216 | 225 |
| 217 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 | 226 // Two setNeedsCommits in a row should lead to at least 1 commit and at least 1 |
| 218 // draw with frame 0. | 227 // draw with frame 0. |
| 219 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { | 228 class LayerTreeHostTestSetNeedsCommit1 : public LayerTreeHostTest { |
| 220 public: | 229 public: |
| (...skipping 5631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5852 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 5861 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 5853 | 5862 |
| 5854 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 5863 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 5855 LayerTreeHostImpl::FrameData* frame_data, | 5864 LayerTreeHostImpl::FrameData* frame_data, |
| 5856 DrawResult draw_result) override { | 5865 DrawResult draw_result) override { |
| 5857 EXPECT_EQ(4u, host_impl->resource_provider()->num_resources()); | 5866 EXPECT_EQ(4u, host_impl->resource_provider()->num_resources()); |
| 5858 | 5867 |
| 5859 // Verify which tiles got resources using an eviction iterator, which has to | 5868 // Verify which tiles got resources using an eviction iterator, which has to |
| 5860 // return all tiles that have resources. | 5869 // return all tiles that have resources. |
| 5861 scoped_ptr<EvictionTilePriorityQueue> eviction_queue( | 5870 scoped_ptr<EvictionTilePriorityQueue> eviction_queue( |
| 5862 host_impl->BuildEvictionQueue(SAME_PRIORITY_FOR_BOTH_TREES)); | 5871 host_impl->tile_manager()->BuildEvictionQueue()); |
| 5863 int tile_count = 0; | 5872 int tile_count = 0; |
| 5864 for (; !eviction_queue->IsEmpty(); eviction_queue->Pop()) { | 5873 for (; !eviction_queue->IsEmpty(); eviction_queue->Pop()) { |
| 5865 Tile* tile = eviction_queue->Top(); | 5874 Tile* tile = eviction_queue->Top(); |
| 5866 // Ensure this tile is within the viewport. | 5875 // Ensure this tile is within the viewport. |
| 5867 EXPECT_TRUE(tile->content_rect().Intersects(gfx::Rect(viewport_size_))); | 5876 EXPECT_TRUE(tile->content_rect().Intersects(gfx::Rect(viewport_size_))); |
| 5868 // Ensure that the tile is 1/4 of the viewport tall (plus padding). | 5877 // Ensure that the tile is 1/4 of the viewport tall (plus padding). |
| 5869 EXPECT_EQ(tile->content_rect().height(), | 5878 EXPECT_EQ(tile->content_rect().height(), |
| 5870 (viewport_size_.height() / 4) + 2); | 5879 (viewport_size_.height() / 4) + 2); |
| 5871 ++tile_count; | 5880 ++tile_count; |
| 5872 } | 5881 } |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6261 | 6270 |
| 6262 void AfterTest() override { EXPECT_TRUE(did_commit_); } | 6271 void AfterTest() override { EXPECT_TRUE(did_commit_); } |
| 6263 | 6272 |
| 6264 private: | 6273 private: |
| 6265 bool did_commit_; | 6274 bool did_commit_; |
| 6266 }; | 6275 }; |
| 6267 | 6276 |
| 6268 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); | 6277 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); |
| 6269 | 6278 |
| 6270 } // namespace cc | 6279 } // namespace cc |
| OLD | NEW |