| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "cc/test/fake_content_layer_client.h" | 7 #include "cc/test/fake_content_layer_client.h" |
| 8 #include "cc/test/fake_picture_layer.h" | 8 #include "cc/test/fake_picture_layer.h" |
| 9 #include "cc/test/layer_tree_test.h" | 9 #include "cc/test/layer_tree_test.h" |
| 10 #include "cc/trees/proxy_impl.h" | 10 #include "cc/trees/proxy_impl.h" |
| 11 #include "cc/trees/proxy_main.h" | 11 #include "cc/trees/proxy_main.h" |
| 12 | 12 |
| 13 #define PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME) \ | |
| 14 TEST_F(TEST_FIXTURE_NAME, MultiThread) { Run(true); } | |
| 15 | |
| 16 // Do common tests for single thread proxy and proxy main in threaded mode. | |
| 17 // TODO(simonhong): Add SINGLE_THREAD_PROXY_TEST_F | |
| 18 #define PROXY_TEST_SCHEDULED_ACTION(TEST_FIXTURE_NAME) \ | |
| 19 PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME); | |
| 20 | |
| 21 namespace cc { | 13 namespace cc { |
| 22 | 14 |
| 23 class ProxyTest : public LayerTreeTest { | 15 class LayerTreeHostProxyTest : public LayerTreeTest { |
| 24 protected: | 16 protected: |
| 25 ProxyTest() {} | |
| 26 ~ProxyTest() override {} | |
| 27 | |
| 28 void Run(bool threaded) { | |
| 29 // We don't need to care about delegating mode. | |
| 30 bool delegating_renderer = true; | |
| 31 | |
| 32 CompositorMode mode = | |
| 33 threaded ? CompositorMode::THREADED : CompositorMode::SINGLE_THREADED; | |
| 34 RunTest(mode, delegating_renderer); | |
| 35 } | |
| 36 | |
| 37 void BeginTest() override {} | |
| 38 void AfterTest() override {} | |
| 39 | |
| 40 private: | |
| 41 DISALLOW_COPY_AND_ASSIGN(ProxyTest); | |
| 42 }; | |
| 43 | |
| 44 class ProxyTestScheduledActionsBasic : public ProxyTest { | |
| 45 protected: | |
| 46 void BeginTest() override { proxy()->SetNeedsCommit(); } | |
| 47 | |
| 48 void ScheduledActionBeginOutputSurfaceCreation() override { | |
| 49 EXPECT_EQ(0, action_phase_++); | |
| 50 } | |
| 51 | |
| 52 void ScheduledActionSendBeginMainFrame() override { | |
| 53 EXPECT_EQ(1, action_phase_++); | |
| 54 } | |
| 55 | |
| 56 void ScheduledActionCommit() override { EXPECT_EQ(2, action_phase_++); } | |
| 57 | |
| 58 void ScheduledActionDrawAndSwapIfPossible() override { | |
| 59 EXPECT_EQ(3, action_phase_++); | |
| 60 EndTest(); | |
| 61 } | |
| 62 | |
| 63 void AfterTest() override { EXPECT_EQ(4, action_phase_); } | |
| 64 | |
| 65 ProxyTestScheduledActionsBasic() : action_phase_(0) { | |
| 66 } | |
| 67 ~ProxyTestScheduledActionsBasic() override {} | |
| 68 | |
| 69 private: | |
| 70 int action_phase_; | |
| 71 | |
| 72 DISALLOW_COPY_AND_ASSIGN(ProxyTestScheduledActionsBasic); | |
| 73 }; | |
| 74 | |
| 75 PROXY_TEST_SCHEDULED_ACTION(ProxyTestScheduledActionsBasic); | |
| 76 | |
| 77 class ProxyMainThreaded : public ProxyTest { | |
| 78 protected: | |
| 79 ProxyMainThreaded() | |
| 80 : update_check_layer_(FakePictureLayer::Create(&client_)) {} | |
| 81 ~ProxyMainThreaded() override {} | |
| 82 | |
| 83 void SetupTree() override { | 17 void SetupTree() override { |
| 18 update_check_layer_ = FakePictureLayer::Create(&client_); |
| 84 layer_tree_host()->SetRootLayer(update_check_layer_); | 19 layer_tree_host()->SetRootLayer(update_check_layer_); |
| 85 ProxyTest::SetupTree(); | 20 LayerTreeTest::SetupTree(); |
| 86 client_.set_bounds(update_check_layer_->bounds()); | 21 client_.set_bounds(update_check_layer_->bounds()); |
| 87 } | 22 } |
| 88 | 23 |
| 89 protected: | 24 FakePictureLayer* update_check_layer() const { |
| 25 return update_check_layer_.get(); |
| 26 } |
| 27 |
| 28 private: |
| 90 FakeContentLayerClient client_; | 29 FakeContentLayerClient client_; |
| 91 scoped_refptr<FakePictureLayer> update_check_layer_; | 30 scoped_refptr<FakePictureLayer> update_check_layer_; |
| 92 | 31 }; |
| 93 private: | 32 |
| 94 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreaded); | 33 class LayerTreeHostProxyTestSetNeedsCommit : public LayerTreeHostProxyTest { |
| 95 }; | 34 protected: |
| 96 | 35 LayerTreeHostProxyTestSetNeedsCommit() {} |
| 97 class ProxyMainThreadedSetNeedsCommit : public ProxyMainThreaded { | 36 ~LayerTreeHostProxyTestSetNeedsCommit() override {} |
| 98 protected: | |
| 99 ProxyMainThreadedSetNeedsCommit() {} | |
| 100 ~ProxyMainThreadedSetNeedsCommit() override {} | |
| 101 | 37 |
| 102 void BeginTest() override { | 38 void BeginTest() override { |
| 103 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 39 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 104 GetProxyMainForTest()->max_requested_pipeline_stage()); | 40 GetProxyMain()->max_requested_pipeline_stage()); |
| 105 | 41 |
| 106 proxy()->SetNeedsCommit(); | 42 proxy()->SetNeedsCommit(); |
| 107 | 43 |
| 108 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, | 44 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, |
| 109 GetProxyMainForTest()->max_requested_pipeline_stage()); | 45 GetProxyMain()->max_requested_pipeline_stage()); |
| 110 } | 46 } |
| 111 | 47 |
| 112 void DidBeginMainFrame() override { | 48 void DidBeginMainFrame() override { |
| 113 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 49 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 114 GetProxyMainForTest()->max_requested_pipeline_stage()); | 50 GetProxyMain()->max_requested_pipeline_stage()); |
| 115 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 51 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 116 GetProxyMainForTest()->current_pipeline_stage()); | 52 GetProxyMain()->current_pipeline_stage()); |
| 117 } | 53 } |
| 118 | 54 |
| 119 void DidCommit() override { | 55 void DidCommit() override { |
| 120 EXPECT_EQ(1, update_check_layer_->update_count()); | 56 EXPECT_EQ(1, update_check_layer()->update_count()); |
| 121 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 57 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 122 GetProxyMainForTest()->current_pipeline_stage()); | 58 GetProxyMain()->current_pipeline_stage()); |
| 123 EndTest(); | 59 EndTest(); |
| 124 } | 60 } |
| 125 | 61 |
| 126 private: | 62 void AfterTest() override {} |
| 127 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommit); | 63 |
| 128 }; | 64 private: |
| 129 | 65 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsCommit); |
| 130 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommit); | 66 }; |
| 131 | 67 |
| 132 class ProxyMainThreadedSetNeedsAnimate : public ProxyMainThreaded { | 68 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsCommit); |
| 133 protected: | 69 |
| 134 ProxyMainThreadedSetNeedsAnimate() {} | 70 class LayerTreeHostProxyTestSetNeedsAnimate : public LayerTreeHostProxyTest { |
| 135 ~ProxyMainThreadedSetNeedsAnimate() override {} | 71 protected: |
| 72 LayerTreeHostProxyTestSetNeedsAnimate() {} |
| 73 ~LayerTreeHostProxyTestSetNeedsAnimate() override {} |
| 136 | 74 |
| 137 void BeginTest() override { | 75 void BeginTest() override { |
| 138 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 76 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 139 GetProxyMainForTest()->max_requested_pipeline_stage()); | 77 GetProxyMain()->max_requested_pipeline_stage()); |
| 140 | 78 |
| 141 proxy()->SetNeedsAnimate(); | 79 proxy()->SetNeedsAnimate(); |
| 142 | 80 |
| 143 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 81 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
| 144 GetProxyMainForTest()->max_requested_pipeline_stage()); | 82 GetProxyMain()->max_requested_pipeline_stage()); |
| 145 } | 83 } |
| 146 | 84 |
| 147 void DidBeginMainFrame() override { | 85 void DidBeginMainFrame() override { |
| 148 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 86 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 149 GetProxyMainForTest()->max_requested_pipeline_stage()); | 87 GetProxyMain()->max_requested_pipeline_stage()); |
| 150 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 88 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 151 GetProxyMainForTest()->current_pipeline_stage()); | 89 GetProxyMain()->current_pipeline_stage()); |
| 152 } | 90 } |
| 153 | 91 |
| 154 void DidCommit() override { | 92 void DidCommit() override { |
| 155 EXPECT_EQ(0, update_check_layer_->update_count()); | 93 EXPECT_EQ(0, update_check_layer()->update_count()); |
| 156 EndTest(); | 94 EndTest(); |
| 157 } | 95 } |
| 158 | 96 |
| 159 private: | 97 void AfterTest() override {} |
| 160 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsAnimate); | 98 |
| 161 }; | 99 private: |
| 162 | 100 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsAnimate); |
| 163 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsAnimate); | 101 }; |
| 164 | 102 |
| 165 class ProxyMainThreadedSetNeedsUpdateLayers : public ProxyMainThreaded { | 103 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsAnimate); |
| 166 protected: | 104 |
| 167 ProxyMainThreadedSetNeedsUpdateLayers() {} | 105 class LayerTreeHostProxyTestSetNeedsUpdateLayers |
| 168 ~ProxyMainThreadedSetNeedsUpdateLayers() override {} | 106 : public LayerTreeHostProxyTest { |
| 107 protected: |
| 108 LayerTreeHostProxyTestSetNeedsUpdateLayers() {} |
| 109 ~LayerTreeHostProxyTestSetNeedsUpdateLayers() override {} |
| 169 | 110 |
| 170 void BeginTest() override { | 111 void BeginTest() override { |
| 171 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 112 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 172 GetProxyMainForTest()->max_requested_pipeline_stage()); | 113 GetProxyMain()->max_requested_pipeline_stage()); |
| 173 | 114 |
| 174 proxy()->SetNeedsUpdateLayers(); | 115 proxy()->SetNeedsUpdateLayers(); |
| 175 | 116 |
| 176 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, | 117 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, |
| 177 GetProxyMainForTest()->max_requested_pipeline_stage()); | 118 GetProxyMain()->max_requested_pipeline_stage()); |
| 178 } | 119 } |
| 179 | 120 |
| 180 void DidBeginMainFrame() override { | 121 void DidBeginMainFrame() override { |
| 181 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 122 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 182 GetProxyMainForTest()->max_requested_pipeline_stage()); | 123 GetProxyMain()->max_requested_pipeline_stage()); |
| 183 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 124 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 184 GetProxyMainForTest()->current_pipeline_stage()); | 125 GetProxyMain()->current_pipeline_stage()); |
| 185 } | 126 } |
| 186 | 127 |
| 187 void DidCommit() override { | 128 void DidCommit() override { |
| 188 EXPECT_EQ(1, update_check_layer_->update_count()); | 129 EXPECT_EQ(1, update_check_layer()->update_count()); |
| 189 EndTest(); | 130 EndTest(); |
| 190 } | 131 } |
| 191 | 132 |
| 192 private: | 133 void AfterTest() override {} |
| 193 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsUpdateLayers); | 134 |
| 194 }; | 135 private: |
| 195 | 136 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsUpdateLayers); |
| 196 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsUpdateLayers); | 137 }; |
| 197 | 138 |
| 198 class ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating | 139 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsUpdateLayers); |
| 199 : public ProxyMainThreaded { | 140 |
| 200 protected: | 141 class LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating |
| 201 ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating() {} | 142 : public LayerTreeHostProxyTest { |
| 202 ~ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating() override {} | 143 protected: |
| 144 LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating() {} |
| 145 ~LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating() override {} |
| 203 | 146 |
| 204 void BeginTest() override { proxy()->SetNeedsAnimate(); } | 147 void BeginTest() override { proxy()->SetNeedsAnimate(); } |
| 205 | 148 |
| 206 void WillBeginMainFrame() override { | 149 void WillBeginMainFrame() override { |
| 207 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 150 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 208 GetProxyMainForTest()->max_requested_pipeline_stage()); | 151 GetProxyMain()->max_requested_pipeline_stage()); |
| 209 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 152 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
| 210 GetProxyMainForTest()->current_pipeline_stage()); | 153 GetProxyMain()->current_pipeline_stage()); |
| 211 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 154 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
| 212 GetProxyMainForTest()->final_pipeline_stage()); | 155 GetProxyMain()->final_pipeline_stage()); |
| 213 | 156 |
| 214 proxy()->SetNeedsUpdateLayers(); | 157 proxy()->SetNeedsUpdateLayers(); |
| 215 | 158 |
| 216 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 159 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 217 GetProxyMainForTest()->max_requested_pipeline_stage()); | 160 GetProxyMain()->max_requested_pipeline_stage()); |
| 218 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, | 161 EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE, |
| 219 GetProxyMainForTest()->final_pipeline_stage()); | 162 GetProxyMain()->final_pipeline_stage()); |
| 220 } | 163 } |
| 221 | 164 |
| 222 void DidBeginMainFrame() override { | 165 void DidBeginMainFrame() override { |
| 223 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 166 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 224 GetProxyMainForTest()->max_requested_pipeline_stage()); | 167 GetProxyMain()->max_requested_pipeline_stage()); |
| 225 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 168 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 226 GetProxyMainForTest()->current_pipeline_stage()); | 169 GetProxyMain()->current_pipeline_stage()); |
| 227 } | 170 } |
| 228 | 171 |
| 229 void DidCommit() override { | 172 void DidCommit() override { |
| 230 EXPECT_EQ(1, update_check_layer_->update_count()); | 173 EXPECT_EQ(1, update_check_layer()->update_count()); |
| 231 EndTest(); | 174 EndTest(); |
| 232 } | 175 } |
| 233 | 176 |
| 234 private: | 177 void AfterTest() override {} |
| 235 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating); | 178 |
| 236 }; | 179 private: |
| 237 | 180 DISALLOW_COPY_AND_ASSIGN( |
| 238 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating); | 181 LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating); |
| 239 | 182 }; |
| 240 class ProxyMainThreadedSetNeedsCommitWhileAnimating : public ProxyMainThreaded { | 183 |
| 241 protected: | 184 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating); |
| 242 ProxyMainThreadedSetNeedsCommitWhileAnimating() {} | 185 |
| 243 ~ProxyMainThreadedSetNeedsCommitWhileAnimating() override {} | 186 class LayerTreeHostProxyTestSetNeedsCommitWhileAnimating |
| 187 : public LayerTreeHostProxyTest { |
| 188 protected: |
| 189 LayerTreeHostProxyTestSetNeedsCommitWhileAnimating() {} |
| 190 ~LayerTreeHostProxyTestSetNeedsCommitWhileAnimating() override {} |
| 244 | 191 |
| 245 void BeginTest() override { proxy()->SetNeedsAnimate(); } | 192 void BeginTest() override { proxy()->SetNeedsAnimate(); } |
| 246 | 193 |
| 247 void WillBeginMainFrame() override { | 194 void WillBeginMainFrame() override { |
| 248 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 195 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 249 GetProxyMainForTest()->max_requested_pipeline_stage()); | 196 GetProxyMain()->max_requested_pipeline_stage()); |
| 250 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 197 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
| 251 GetProxyMainForTest()->current_pipeline_stage()); | 198 GetProxyMain()->current_pipeline_stage()); |
| 252 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, | 199 EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE, |
| 253 GetProxyMainForTest()->final_pipeline_stage()); | 200 GetProxyMain()->final_pipeline_stage()); |
| 254 | 201 |
| 255 proxy()->SetNeedsCommit(); | 202 proxy()->SetNeedsCommit(); |
| 256 | 203 |
| 257 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 204 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 258 GetProxyMainForTest()->max_requested_pipeline_stage()); | 205 GetProxyMain()->max_requested_pipeline_stage()); |
| 259 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, | 206 EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE, |
| 260 GetProxyMainForTest()->final_pipeline_stage()); | 207 GetProxyMain()->final_pipeline_stage()); |
| 261 } | 208 } |
| 262 | 209 |
| 263 void DidBeginMainFrame() override { | 210 void DidBeginMainFrame() override { |
| 264 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 211 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 265 GetProxyMainForTest()->max_requested_pipeline_stage()); | 212 GetProxyMain()->max_requested_pipeline_stage()); |
| 266 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, | 213 EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE, |
| 267 GetProxyMainForTest()->current_pipeline_stage()); | 214 GetProxyMain()->current_pipeline_stage()); |
| 268 } | 215 } |
| 269 | 216 |
| 270 void DidCommit() override { | 217 void DidCommit() override { |
| 271 EXPECT_EQ(1, update_check_layer_->update_count()); | 218 EXPECT_EQ(1, update_check_layer()->update_count()); |
| 272 EndTest(); | 219 EndTest(); |
| 273 } | 220 } |
| 274 | 221 |
| 275 private: | 222 void AfterTest() override {} |
| 276 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommitWhileAnimating); | 223 |
| 277 }; | 224 private: |
| 278 | 225 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsCommitWhileAnimating); |
| 279 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommitWhileAnimating); | 226 }; |
| 280 | 227 |
| 281 class ProxyMainThreadedCommitWaitsForActivation : public ProxyMainThreaded { | 228 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsCommitWhileAnimating); |
| 282 protected: | 229 |
| 283 ProxyMainThreadedCommitWaitsForActivation() : num_commits_(0) {} | 230 class LayerTreeHostProxyTestCommitWaitsForActivation |
| 284 ~ProxyMainThreadedCommitWaitsForActivation() override {} | 231 : public LayerTreeHostProxyTest { |
| 285 | 232 protected: |
| 286 void BeginTest() override { proxy()->SetNeedsCommit(); } | 233 LayerTreeHostProxyTestCommitWaitsForActivation() = default; |
| 287 | 234 |
| 288 void ScheduledActionCommit() override { | 235 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 289 switch (num_commits_) { | 236 |
| 290 case 0: | 237 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { |
| 291 // Set next commit waits for activation and start another commit. | 238 LOG(ERROR) << "BeginCommitOnThread " |
| 292 PostNextCommitWaitsForActivationToMainThread(); | 239 << impl->sync_tree()->source_frame_number(); |
| 293 PostSetNeedsCommitToMainThread(); | 240 |
| 294 break; | 241 if (impl->sync_tree()->source_frame_number() < 0) |
| 242 return; // The initial commit, don't do anything here. |
| 243 |
| 244 // The main thread will request a commit, and may request that it does |
| 245 // not complete before activating. So make activation take a long time, to |
| 246 // verify that we waited. |
| 247 impl->BlockNotifyReadyToActivateForTesting(true); |
| 248 { |
| 249 base::AutoLock hold(activate_blocked_lock_); |
| 250 activate_blocked_ = true; |
| 251 } |
| 252 switch (impl->sync_tree()->source_frame_number()) { |
| 253 case 0: { |
| 254 // This is for case 1 in DidCommit. |
| 255 auto unblock = base::Bind( |
| 256 &LayerTreeHostProxyTestCommitWaitsForActivation::UnblockActivation, |
| 257 base::Unretained(this), impl); |
| 258 ImplThreadTaskRunner()->PostDelayedTask( |
| 259 FROM_HERE, unblock, |
| 260 // Use a delay to allow the main frame to start if it would. This |
| 261 // should cause failures (or flakiness) if we fail to wait for the |
| 262 // activation before starting the main frame. |
| 263 base::TimeDelta::FromMilliseconds(16 * 4)); |
| 264 break; |
| 265 } |
| 295 case 1: | 266 case 1: |
| 296 PostSetNeedsCommitToMainThread(); | 267 // This is for case 2 in DidCommit. |
| 297 break; | 268 // Here we don't ever unblock activation. Since the commit hasn't |
| 298 } | 269 // requested to wait, we can verify that activation is blocked when the |
| 299 num_commits_++; | 270 // commit completes (case 3 in DidCommit). |
| 300 } | 271 break; |
| 301 | 272 } |
| 302 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 273 } |
| 303 CompletionEvent* activation_completion_event = | 274 |
| 304 GetProxyImplForTest()->ActivationCompletionEventForTesting(); | 275 void DidCommit() override { |
| 305 switch (num_commits_) { | 276 LOG(ERROR) << "DidCommit " << layer_tree_host()->source_frame_number(); |
| 277 switch (layer_tree_host()->source_frame_number()) { |
| 306 case 1: | 278 case 1: |
| 307 EXPECT_FALSE(activation_completion_event); | 279 // Request a new commit, but DidCommit will be delayed until activation |
| 308 break; | 280 // completes. |
| 309 case 2: | 281 layer_tree_host()->SetNextCommitWaitsForActivation(); |
| 310 EXPECT_TRUE(activation_completion_event); | 282 layer_tree_host()->SetNeedsCommit(); |
| 311 EXPECT_FALSE(activation_completion_event->IsSignaled()); | 283 break; |
| 312 break; | 284 case 2: { |
| 313 case 3: | 285 base::AutoLock hold(activate_blocked_lock_); |
| 314 EXPECT_FALSE(activation_completion_event); | 286 EXPECT_FALSE(activate_blocked_); |
| 287 } |
| 288 // Request a new commit, but DidCommit will not be delayed. |
| 289 layer_tree_host()->SetNeedsCommit(); |
| 290 break; |
| 291 case 3: { |
| 292 base::AutoLock hold(activate_blocked_lock_); |
| 293 EXPECT_TRUE(activate_blocked_); |
| 294 } |
| 295 // This commit completed before unblocking activation. |
| 315 EndTest(); | 296 EndTest(); |
| 316 break; | 297 break; |
| 317 } | 298 } |
| 318 } | 299 } |
| 319 | 300 |
| 320 void AfterTest() override { | 301 void UnblockActivation(LayerTreeHostImpl* impl) { |
| 321 // It is safe to read num_commits_ on the main thread now since AfterTest() | 302 LOG(ERROR) << "Unblocked"; |
| 322 // runs after the LayerTreeHost is destroyed and the impl thread tear down | 303 { |
| 323 // is finished. | 304 base::AutoLock hold(activate_blocked_lock_); |
| 324 EXPECT_EQ(3, num_commits_); | 305 activate_blocked_ = false; |
| 325 } | 306 } |
| 326 | 307 impl->BlockNotifyReadyToActivateForTesting(false); |
| 327 private: | 308 } |
| 328 int num_commits_; | 309 |
| 329 | 310 void AfterTest() override {} |
| 330 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivation); | 311 |
| 331 }; | 312 private: |
| 332 | 313 base::Lock activate_blocked_lock_; |
| 333 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivation); | 314 bool activate_blocked_ = false; |
| 315 |
| 316 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestCommitWaitsForActivation); |
| 317 }; |
| 318 |
| 319 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestCommitWaitsForActivation); |
| 334 | 320 |
| 335 // Test for a corner case of main frame before activation (MFBA) and commit | 321 // Test for a corner case of main frame before activation (MFBA) and commit |
| 336 // waits for activation. If a commit (with wait for activation flag set) | 322 // waits for activation. If a commit (with wait for activation flag set) |
| 337 // is ready before the activation for a previous commit then the activation | 323 // is ready before the activation for a previous commit then the activation |
| 338 // should not signal the completion event of the second commit. | 324 // should not signal the completion event of the second commit. |
| 339 class ProxyMainThreadedCommitWaitsForActivationMFBA : public ProxyMainThreaded { | 325 class LayerTreeHostProxyTestCommitWaitsForActivationMFBA |
| 340 protected: | 326 : public LayerTreeHostProxyTest { |
| 341 ProxyMainThreadedCommitWaitsForActivationMFBA() : num_commits_(0) {} | 327 protected: |
| 342 ~ProxyMainThreadedCommitWaitsForActivationMFBA() override {} | 328 LayerTreeHostProxyTestCommitWaitsForActivationMFBA() = default; |
| 343 | 329 |
| 344 void InitializeSettings(LayerTreeSettings* settings) override { | 330 void InitializeSettings(LayerTreeSettings* settings) override { |
| 345 settings->main_frame_before_activation_enabled = true; | 331 settings->main_frame_before_activation_enabled = true; |
| 346 ProxyMainThreaded::InitializeSettings(settings); | 332 LayerTreeHostProxyTest::InitializeSettings(settings); |
| 347 } | 333 } |
| 348 | 334 |
| 349 void BeginTest() override { proxy()->SetNeedsCommit(); } | 335 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 350 | 336 |
| 351 // This is called right before NotifyReadyToCommit. | 337 void BeginCommitOnThread(LayerTreeHostImpl* impl) override { |
| 352 void StartCommitOnImpl() override { | 338 LOG(ERROR) << "BeginCommitOnThread " |
| 353 switch (num_commits_) { | 339 << impl->sync_tree()->source_frame_number(); |
| 354 case 0: | 340 } |
| 355 // Block activation until next commit is ready. | 341 |
| 356 GetProxyImplForTest()->BlockNotifyReadyToActivateForTesting(true); | 342 void BeginMainFrameCompletedOnThread(LayerTreeHostImpl* impl) override { |
| 357 break; | 343 LOG(ERROR) << "BeginMainFrameCompletedOnThread " |
| 344 << impl->sync_tree()->source_frame_number(); |
| 345 switch (impl->sync_tree()->source_frame_number()) { |
| 346 case -1: |
| 347 // Block the activation of the initial commit until the second main |
| 348 // frame is ready. |
| 349 impl->BlockNotifyReadyToActivateForTesting(true); |
| 350 break; |
| 351 case 0: { |
| 352 // This is the main frame with SetNextCommitWaitsForActivation(). |
| 353 // Activation is currently blocked for the previous main frame (from the |
| 354 // case above). We unblock activate to allow this main frame to commit. |
| 355 auto unblock = |
| 356 base::Bind(&LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting, |
| 357 base::Unretained(impl), false); |
| 358 // Post the unblock instead of doing it immediately so that the main |
| 359 // frame is fully processed by the compositor thread, and it has a full |
| 360 // opportunity to wrongly unblock the main thread. |
| 361 ImplThreadTaskRunner()->PostTask(FROM_HERE, unblock); |
| 362 // Once activation completes, we'll begin the commit for frame 1. |
| 363 break; |
| 364 } |
| 365 } |
| 366 } |
| 367 |
| 368 void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override { |
| 369 LOG(ERROR) << "DidActivateTreeOnThread " |
| 370 << impl->active_tree()->source_frame_number(); |
| 371 |
| 372 if (impl->active_tree()->source_frame_number() == 0) { |
| 373 // The main thread requests a commit does not complete before activating. |
| 374 // So make activation take a long time, to verify that we waited. |
| 375 impl->BlockNotifyReadyToActivateForTesting(true); |
| 376 { |
| 377 base::AutoLock hold(activate_blocked_lock_); |
| 378 // Record that we've blocked activation for this frame of interest. |
| 379 activate_blocked_ = true; |
| 380 } |
| 381 // Then unblock activation eventually to complete the test. We use a |
| 382 // delay to allow the main frame to start if it would. This should cause |
| 383 // failures (or flakiness) if we fail to wait for the activation before |
| 384 // starting the main frame. |
| 385 auto unblock = |
| 386 base::Bind(&LayerTreeHostProxyTestCommitWaitsForActivationMFBA:: |
| 387 UnblockActivation, |
| 388 base::Unretained(this), impl); |
| 389 ImplThreadTaskRunner()->PostDelayedTask( |
| 390 FROM_HERE, unblock, base::TimeDelta::FromMilliseconds(16 * 4)); |
| 391 } |
| 392 } |
| 393 |
| 394 void DidCommit() override { |
| 395 LOG(ERROR) << "DidCommit " << layer_tree_host()->source_frame_number(); |
| 396 switch (layer_tree_host()->source_frame_number()) { |
| 358 case 1: | 397 case 1: |
| 359 // Unblock activation of first commit after second commit is ready. | 398 // Request a new commit, but DidCommit will be delayed until activation |
| 360 ImplThreadTaskRunner()->PostTask( | 399 // completes. |
| 361 FROM_HERE, | 400 layer_tree_host()->SetNextCommitWaitsForActivation(); |
| 362 base::Bind(&ProxyImplForTest::BlockNotifyReadyToActivateForTesting, | 401 layer_tree_host()->SetNeedsCommit(); |
| 363 base::Unretained(GetProxyImplForTest()), false)); | |
| 364 break; | |
| 365 } | |
| 366 } | |
| 367 | |
| 368 void ScheduledActionCommit() override { | |
| 369 switch (num_commits_) { | |
| 370 case 0: | |
| 371 // Set next commit waits for activation and start another commit. | |
| 372 PostNextCommitWaitsForActivationToMainThread(); | |
| 373 PostSetNeedsCommitToMainThread(); | |
| 374 break; | |
| 375 case 1: | |
| 376 PostSetNeedsCommitToMainThread(); | |
| 377 break; | |
| 378 } | |
| 379 num_commits_++; | |
| 380 } | |
| 381 | |
| 382 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | |
| 383 CompletionEvent* activation_completion_event = | |
| 384 GetProxyImplForTest()->ActivationCompletionEventForTesting(); | |
| 385 switch (num_commits_) { | |
| 386 case 1: | |
| 387 EXPECT_FALSE(activation_completion_event); | |
| 388 break; | 402 break; |
| 389 case 2: | 403 case 2: |
| 390 EXPECT_TRUE(activation_completion_event); | 404 // This DidCommit should not happen until activation is done for the |
| 391 EXPECT_FALSE(activation_completion_event->IsSignaled()); | 405 // frame. |
| 392 break; | 406 { |
| 393 case 3: | 407 base::AutoLock hold(activate_blocked_lock_); |
| 394 EXPECT_FALSE(activation_completion_event); | 408 EXPECT_FALSE(activate_blocked_); |
| 409 } |
| 395 EndTest(); | 410 EndTest(); |
| 396 break; | 411 break; |
| 397 } | 412 } |
| 398 } | 413 } |
| 399 | 414 |
| 400 void AfterTest() override { | 415 void UnblockActivation(LayerTreeHostImpl* impl) { |
| 401 // It is safe to read num_commits_ on the main thread now since AfterTest() | 416 LOG(ERROR) << "Unblocked"; |
| 402 // runs after the LayerTreeHost is destroyed and the impl thread tear down | 417 { |
| 403 // is finished. | 418 base::AutoLock hold(activate_blocked_lock_); |
| 404 EXPECT_EQ(3, num_commits_); | 419 activate_blocked_ = false; |
| 405 } | 420 } |
| 406 | 421 impl->BlockNotifyReadyToActivateForTesting(false); |
| 407 private: | 422 } |
| 408 int num_commits_; | 423 |
| 409 | 424 void AfterTest() override {} |
| 410 DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivationMFBA); | 425 |
| 411 }; | 426 private: |
| 412 | 427 base::Lock activate_blocked_lock_; |
| 413 PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivationMFBA); | 428 bool activate_blocked_ = false; |
| 429 |
| 430 DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestCommitWaitsForActivationMFBA); |
| 431 }; |
| 432 |
| 433 MULTI_THREAD_TEST_F(LayerTreeHostProxyTestCommitWaitsForActivationMFBA); |
| 414 | 434 |
| 415 } // namespace cc | 435 } // namespace cc |
| OLD | NEW |