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