| Index: cc/trees/layer_tree_host_unittest_proxy.cc
|
| diff --git a/cc/trees/layer_tree_host_unittest_proxy.cc b/cc/trees/layer_tree_host_unittest_proxy.cc
|
| index 8c3779bffecde06ef65268010e1b8ba1ec18f8cf..558592051b68beafd1452a7131fa2965a9c22054 100644
|
| --- a/cc/trees/layer_tree_host_unittest_proxy.cc
|
| +++ b/cc/trees/layer_tree_host_unittest_proxy.cc
|
| @@ -10,406 +10,426 @@
|
| #include "cc/trees/proxy_impl.h"
|
| #include "cc/trees/proxy_main.h"
|
|
|
| -#define PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME) \
|
| - TEST_F(TEST_FIXTURE_NAME, MultiThread) { Run(true); }
|
| -
|
| -// Do common tests for single thread proxy and proxy main in threaded mode.
|
| -// TODO(simonhong): Add SINGLE_THREAD_PROXY_TEST_F
|
| -#define PROXY_TEST_SCHEDULED_ACTION(TEST_FIXTURE_NAME) \
|
| - PROXY_MAIN_THREADED_TEST_F(TEST_FIXTURE_NAME);
|
| -
|
| namespace cc {
|
|
|
| -class ProxyTest : public LayerTreeTest {
|
| +class LayerTreeHostProxyTest : public LayerTreeTest {
|
| protected:
|
| - ProxyTest() {}
|
| - ~ProxyTest() override {}
|
| -
|
| - void Run(bool threaded) {
|
| - // We don't need to care about delegating mode.
|
| - bool delegating_renderer = true;
|
| -
|
| - CompositorMode mode =
|
| - threaded ? CompositorMode::THREADED : CompositorMode::SINGLE_THREADED;
|
| - RunTest(mode, delegating_renderer);
|
| - }
|
| -
|
| - void BeginTest() override {}
|
| - void AfterTest() override {}
|
| -
|
| - private:
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyTest);
|
| -};
|
| -
|
| -class ProxyTestScheduledActionsBasic : public ProxyTest {
|
| - protected:
|
| - void BeginTest() override { proxy()->SetNeedsCommit(); }
|
| -
|
| - void ScheduledActionBeginOutputSurfaceCreation() override {
|
| - EXPECT_EQ(0, action_phase_++);
|
| - }
|
| -
|
| - void ScheduledActionSendBeginMainFrame() override {
|
| - EXPECT_EQ(1, action_phase_++);
|
| - }
|
| -
|
| - void ScheduledActionCommit() override { EXPECT_EQ(2, action_phase_++); }
|
| -
|
| - void ScheduledActionDrawAndSwapIfPossible() override {
|
| - EXPECT_EQ(3, action_phase_++);
|
| - EndTest();
|
| - }
|
| -
|
| - void AfterTest() override { EXPECT_EQ(4, action_phase_); }
|
| -
|
| - ProxyTestScheduledActionsBasic() : action_phase_(0) {
|
| - }
|
| - ~ProxyTestScheduledActionsBasic() override {}
|
| -
|
| - private:
|
| - int action_phase_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyTestScheduledActionsBasic);
|
| -};
|
| -
|
| -PROXY_TEST_SCHEDULED_ACTION(ProxyTestScheduledActionsBasic);
|
| -
|
| -class ProxyMainThreaded : public ProxyTest {
|
| - protected:
|
| - ProxyMainThreaded()
|
| - : update_check_layer_(FakePictureLayer::Create(&client_)) {}
|
| - ~ProxyMainThreaded() override {}
|
| -
|
| void SetupTree() override {
|
| + update_check_layer_ = FakePictureLayer::Create(&client_);
|
| layer_tree_host()->SetRootLayer(update_check_layer_);
|
| - ProxyTest::SetupTree();
|
| + LayerTreeTest::SetupTree();
|
| client_.set_bounds(update_check_layer_->bounds());
|
| }
|
|
|
| - protected:
|
| - FakeContentLayerClient client_;
|
| - scoped_refptr<FakePictureLayer> update_check_layer_;
|
| + FakePictureLayer* update_check_layer() const {
|
| + return update_check_layer_.get();
|
| + }
|
|
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreaded);
|
| + FakeContentLayerClient client_;
|
| + scoped_refptr<FakePictureLayer> update_check_layer_;
|
| };
|
|
|
| -class ProxyMainThreadedSetNeedsCommit : public ProxyMainThreaded {
|
| +class LayerTreeHostProxyTestSetNeedsCommit : public LayerTreeHostProxyTest {
|
| protected:
|
| - ProxyMainThreadedSetNeedsCommit() {}
|
| - ~ProxyMainThreadedSetNeedsCommit() override {}
|
| + LayerTreeHostProxyTestSetNeedsCommit() {}
|
| + ~LayerTreeHostProxyTestSetNeedsCommit() override {}
|
|
|
| void BeginTest() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
|
|
| proxy()->SetNeedsCommit();
|
|
|
| EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| }
|
|
|
| void DidBeginMainFrame() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| }
|
|
|
| void DidCommit() override {
|
| - EXPECT_EQ(1, update_check_layer_->update_count());
|
| + EXPECT_EQ(1, update_check_layer()->update_count());
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| EndTest();
|
| }
|
|
|
| + void AfterTest() override {}
|
| +
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommit);
|
| + DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsCommit);
|
| };
|
|
|
| -PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommit);
|
| +MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsCommit);
|
|
|
| -class ProxyMainThreadedSetNeedsAnimate : public ProxyMainThreaded {
|
| +class LayerTreeHostProxyTestSetNeedsAnimate : public LayerTreeHostProxyTest {
|
| protected:
|
| - ProxyMainThreadedSetNeedsAnimate() {}
|
| - ~ProxyMainThreadedSetNeedsAnimate() override {}
|
| + LayerTreeHostProxyTestSetNeedsAnimate() {}
|
| + ~LayerTreeHostProxyTestSetNeedsAnimate() override {}
|
|
|
| void BeginTest() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
|
|
| proxy()->SetNeedsAnimate();
|
|
|
| EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| }
|
|
|
| void DidBeginMainFrame() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| }
|
|
|
| void DidCommit() override {
|
| - EXPECT_EQ(0, update_check_layer_->update_count());
|
| + EXPECT_EQ(0, update_check_layer()->update_count());
|
| EndTest();
|
| }
|
|
|
| + void AfterTest() override {}
|
| +
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsAnimate);
|
| + DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsAnimate);
|
| };
|
|
|
| -PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsAnimate);
|
| +MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsAnimate);
|
|
|
| -class ProxyMainThreadedSetNeedsUpdateLayers : public ProxyMainThreaded {
|
| +class LayerTreeHostProxyTestSetNeedsUpdateLayers
|
| + : public LayerTreeHostProxyTest {
|
| protected:
|
| - ProxyMainThreadedSetNeedsUpdateLayers() {}
|
| - ~ProxyMainThreadedSetNeedsUpdateLayers() override {}
|
| + LayerTreeHostProxyTestSetNeedsUpdateLayers() {}
|
| + ~LayerTreeHostProxyTestSetNeedsUpdateLayers() override {}
|
|
|
| void BeginTest() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
|
|
| proxy()->SetNeedsUpdateLayers();
|
|
|
| EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| }
|
|
|
| void DidBeginMainFrame() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| }
|
|
|
| void DidCommit() override {
|
| - EXPECT_EQ(1, update_check_layer_->update_count());
|
| + EXPECT_EQ(1, update_check_layer()->update_count());
|
| EndTest();
|
| }
|
|
|
| + void AfterTest() override {}
|
| +
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsUpdateLayers);
|
| + DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsUpdateLayers);
|
| };
|
|
|
| -PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsUpdateLayers);
|
| +MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsUpdateLayers);
|
|
|
| -class ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating
|
| - : public ProxyMainThreaded {
|
| +class LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating
|
| + : public LayerTreeHostProxyTest {
|
| protected:
|
| - ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating() {}
|
| - ~ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating() override {}
|
| + LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating() {}
|
| + ~LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating() override {}
|
|
|
| void BeginTest() override { proxy()->SetNeedsAnimate(); }
|
|
|
| void WillBeginMainFrame() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->final_pipeline_stage());
|
| + GetProxyMain()->final_pipeline_stage());
|
|
|
| proxy()->SetNeedsUpdateLayers();
|
|
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::UPDATE_LAYERS_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->final_pipeline_stage());
|
| + GetProxyMain()->final_pipeline_stage());
|
| }
|
|
|
| void DidBeginMainFrame() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| }
|
|
|
| void DidCommit() override {
|
| - EXPECT_EQ(1, update_check_layer_->update_count());
|
| + EXPECT_EQ(1, update_check_layer()->update_count());
|
| EndTest();
|
| }
|
|
|
| + void AfterTest() override {}
|
| +
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating);
|
| + DISALLOW_COPY_AND_ASSIGN(
|
| + LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating);
|
| };
|
|
|
| -PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsUpdateLayersWhileAnimating);
|
| +MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsUpdateLayersWhileAnimating);
|
|
|
| -class ProxyMainThreadedSetNeedsCommitWhileAnimating : public ProxyMainThreaded {
|
| +class LayerTreeHostProxyTestSetNeedsCommitWhileAnimating
|
| + : public LayerTreeHostProxyTest {
|
| protected:
|
| - ProxyMainThreadedSetNeedsCommitWhileAnimating() {}
|
| - ~ProxyMainThreadedSetNeedsCommitWhileAnimating() override {}
|
| + LayerTreeHostProxyTestSetNeedsCommitWhileAnimating() {}
|
| + ~LayerTreeHostProxyTestSetNeedsCommitWhileAnimating() override {}
|
|
|
| void BeginTest() override { proxy()->SetNeedsAnimate(); }
|
|
|
| void WillBeginMainFrame() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::ANIMATE_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->final_pipeline_stage());
|
| + GetProxyMain()->final_pipeline_stage());
|
|
|
| proxy()->SetNeedsCommit();
|
|
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::COMMIT_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->final_pipeline_stage());
|
| + GetProxyMain()->final_pipeline_stage());
|
| }
|
|
|
| void DidBeginMainFrame() override {
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->max_requested_pipeline_stage());
|
| + GetProxyMain()->max_requested_pipeline_stage());
|
| EXPECT_EQ(ProxyMain::NO_PIPELINE_STAGE,
|
| - GetProxyMainForTest()->current_pipeline_stage());
|
| + GetProxyMain()->current_pipeline_stage());
|
| }
|
|
|
| void DidCommit() override {
|
| - EXPECT_EQ(1, update_check_layer_->update_count());
|
| + EXPECT_EQ(1, update_check_layer()->update_count());
|
| EndTest();
|
| }
|
|
|
| + void AfterTest() override {}
|
| +
|
| private:
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedSetNeedsCommitWhileAnimating);
|
| + DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestSetNeedsCommitWhileAnimating);
|
| };
|
|
|
| -PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedSetNeedsCommitWhileAnimating);
|
| +MULTI_THREAD_TEST_F(LayerTreeHostProxyTestSetNeedsCommitWhileAnimating);
|
|
|
| -class ProxyMainThreadedCommitWaitsForActivation : public ProxyMainThreaded {
|
| +class LayerTreeHostProxyTestCommitWaitsForActivation
|
| + : public LayerTreeHostProxyTest {
|
| protected:
|
| - ProxyMainThreadedCommitWaitsForActivation() : num_commits_(0) {}
|
| - ~ProxyMainThreadedCommitWaitsForActivation() override {}
|
| + LayerTreeHostProxyTestCommitWaitsForActivation() = default;
|
| +
|
| + void BeginTest() override { PostSetNeedsCommitToMainThread(); }
|
|
|
| - void BeginTest() override { proxy()->SetNeedsCommit(); }
|
| + void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
|
| + LOG(ERROR) << "BeginCommitOnThread "
|
| + << impl->sync_tree()->source_frame_number();
|
|
|
| - void ScheduledActionCommit() override {
|
| - switch (num_commits_) {
|
| - case 0:
|
| - // Set next commit waits for activation and start another commit.
|
| - PostNextCommitWaitsForActivationToMainThread();
|
| - PostSetNeedsCommitToMainThread();
|
| + if (impl->sync_tree()->source_frame_number() < 0)
|
| + return; // The initial commit, don't do anything here.
|
| +
|
| + // The main thread will request a commit, and may request that it does
|
| + // not complete before activating. So make activation take a long time, to
|
| + // verify that we waited.
|
| + impl->BlockNotifyReadyToActivateForTesting(true);
|
| + {
|
| + base::AutoLock hold(activate_blocked_lock_);
|
| + activate_blocked_ = true;
|
| + }
|
| + switch (impl->sync_tree()->source_frame_number()) {
|
| + case 0: {
|
| + // This is for case 1 in DidCommit.
|
| + auto unblock = base::Bind(
|
| + &LayerTreeHostProxyTestCommitWaitsForActivation::UnblockActivation,
|
| + base::Unretained(this), impl);
|
| + ImplThreadTaskRunner()->PostDelayedTask(
|
| + FROM_HERE, unblock,
|
| + // Use a delay to allow the main frame to start if it would. This
|
| + // should cause failures (or flakiness) if we fail to wait for the
|
| + // activation before starting the main frame.
|
| + base::TimeDelta::FromMilliseconds(16 * 4));
|
| break;
|
| + }
|
| case 1:
|
| - PostSetNeedsCommitToMainThread();
|
| + // This is for case 2 in DidCommit.
|
| + // Here we don't ever unblock activation. Since the commit hasn't
|
| + // requested to wait, we can verify that activation is blocked when the
|
| + // commit completes (case 3 in DidCommit).
|
| break;
|
| }
|
| - num_commits_++;
|
| }
|
|
|
| - void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
|
| - CompletionEvent* activation_completion_event =
|
| - GetProxyImplForTest()->ActivationCompletionEventForTesting();
|
| - switch (num_commits_) {
|
| + void DidCommit() override {
|
| + LOG(ERROR) << "DidCommit " << layer_tree_host()->source_frame_number();
|
| + switch (layer_tree_host()->source_frame_number()) {
|
| case 1:
|
| - EXPECT_FALSE(activation_completion_event);
|
| + // Request a new commit, but DidCommit will be delayed until activation
|
| + // completes.
|
| + layer_tree_host()->SetNextCommitWaitsForActivation();
|
| + layer_tree_host()->SetNeedsCommit();
|
| break;
|
| - case 2:
|
| - EXPECT_TRUE(activation_completion_event);
|
| - EXPECT_FALSE(activation_completion_event->IsSignaled());
|
| + case 2: {
|
| + base::AutoLock hold(activate_blocked_lock_);
|
| + EXPECT_FALSE(activate_blocked_);
|
| + }
|
| + // Request a new commit, but DidCommit will not be delayed.
|
| + layer_tree_host()->SetNeedsCommit();
|
| break;
|
| - case 3:
|
| - EXPECT_FALSE(activation_completion_event);
|
| + case 3: {
|
| + base::AutoLock hold(activate_blocked_lock_);
|
| + EXPECT_TRUE(activate_blocked_);
|
| + }
|
| + // This commit completed before unblocking activation.
|
| EndTest();
|
| break;
|
| }
|
| }
|
|
|
| - void AfterTest() override {
|
| - // It is safe to read num_commits_ on the main thread now since AfterTest()
|
| - // runs after the LayerTreeHost is destroyed and the impl thread tear down
|
| - // is finished.
|
| - EXPECT_EQ(3, num_commits_);
|
| + void UnblockActivation(LayerTreeHostImpl* impl) {
|
| + LOG(ERROR) << "Unblocked";
|
| + {
|
| + base::AutoLock hold(activate_blocked_lock_);
|
| + activate_blocked_ = false;
|
| + }
|
| + impl->BlockNotifyReadyToActivateForTesting(false);
|
| }
|
|
|
| + void AfterTest() override {}
|
| +
|
| private:
|
| - int num_commits_;
|
| + base::Lock activate_blocked_lock_;
|
| + bool activate_blocked_ = false;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivation);
|
| + DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestCommitWaitsForActivation);
|
| };
|
|
|
| -PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivation);
|
| +MULTI_THREAD_TEST_F(LayerTreeHostProxyTestCommitWaitsForActivation);
|
|
|
| // Test for a corner case of main frame before activation (MFBA) and commit
|
| // waits for activation. If a commit (with wait for activation flag set)
|
| // is ready before the activation for a previous commit then the activation
|
| // should not signal the completion event of the second commit.
|
| -class ProxyMainThreadedCommitWaitsForActivationMFBA : public ProxyMainThreaded {
|
| +class LayerTreeHostProxyTestCommitWaitsForActivationMFBA
|
| + : public LayerTreeHostProxyTest {
|
| protected:
|
| - ProxyMainThreadedCommitWaitsForActivationMFBA() : num_commits_(0) {}
|
| - ~ProxyMainThreadedCommitWaitsForActivationMFBA() override {}
|
| + LayerTreeHostProxyTestCommitWaitsForActivationMFBA() = default;
|
|
|
| void InitializeSettings(LayerTreeSettings* settings) override {
|
| settings->main_frame_before_activation_enabled = true;
|
| - ProxyMainThreaded::InitializeSettings(settings);
|
| + LayerTreeHostProxyTest::InitializeSettings(settings);
|
| }
|
|
|
| - void BeginTest() override { proxy()->SetNeedsCommit(); }
|
| + void BeginTest() override { PostSetNeedsCommitToMainThread(); }
|
| +
|
| + void BeginCommitOnThread(LayerTreeHostImpl* impl) override {
|
| + LOG(ERROR) << "BeginCommitOnThread "
|
| + << impl->sync_tree()->source_frame_number();
|
| + }
|
|
|
| - // This is called right before NotifyReadyToCommit.
|
| - void StartCommitOnImpl() override {
|
| - switch (num_commits_) {
|
| - case 0:
|
| - // Block activation until next commit is ready.
|
| - GetProxyImplForTest()->BlockNotifyReadyToActivateForTesting(true);
|
| + void BeginMainFrameCompletedOnThread(LayerTreeHostImpl* impl) override {
|
| + LOG(ERROR) << "BeginMainFrameCompletedOnThread "
|
| + << impl->sync_tree()->source_frame_number();
|
| + switch (impl->sync_tree()->source_frame_number()) {
|
| + case -1:
|
| + // Block the activation of the initial commit until the second main
|
| + // frame is ready.
|
| + impl->BlockNotifyReadyToActivateForTesting(true);
|
| break;
|
| - case 1:
|
| - // Unblock activation of first commit after second commit is ready.
|
| - ImplThreadTaskRunner()->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&ProxyImplForTest::BlockNotifyReadyToActivateForTesting,
|
| - base::Unretained(GetProxyImplForTest()), false));
|
| + case 0: {
|
| + // This is the main frame with SetNextCommitWaitsForActivation().
|
| + // Activation is currently blocked for the previous main frame (from the
|
| + // case above). We unblock activate to allow this main frame to commit.
|
| + auto unblock =
|
| + base::Bind(&LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting,
|
| + base::Unretained(impl), false);
|
| + // Post the unblock instead of doing it immediately so that the main
|
| + // frame is fully processed by the compositor thread, and it has a full
|
| + // opportunity to wrongly unblock the main thread.
|
| + ImplThreadTaskRunner()->PostTask(FROM_HERE, unblock);
|
| + // Once activation completes, we'll begin the commit for frame 1.
|
| break;
|
| + }
|
| }
|
| }
|
|
|
| - void ScheduledActionCommit() override {
|
| - switch (num_commits_) {
|
| - case 0:
|
| - // Set next commit waits for activation and start another commit.
|
| - PostNextCommitWaitsForActivationToMainThread();
|
| - PostSetNeedsCommitToMainThread();
|
| - break;
|
| - case 1:
|
| - PostSetNeedsCommitToMainThread();
|
| - break;
|
| + void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
|
| + LOG(ERROR) << "DidActivateTreeOnThread "
|
| + << impl->active_tree()->source_frame_number();
|
| +
|
| + if (impl->active_tree()->source_frame_number() == 0) {
|
| + // The main thread requests a commit does not complete before activating.
|
| + // So make activation take a long time, to verify that we waited.
|
| + impl->BlockNotifyReadyToActivateForTesting(true);
|
| + {
|
| + base::AutoLock hold(activate_blocked_lock_);
|
| + // Record that we've blocked activation for this frame of interest.
|
| + activate_blocked_ = true;
|
| + }
|
| + // Then unblock activation eventually to complete the test. We use a
|
| + // delay to allow the main frame to start if it would. This should cause
|
| + // failures (or flakiness) if we fail to wait for the activation before
|
| + // starting the main frame.
|
| + auto unblock =
|
| + base::Bind(&LayerTreeHostProxyTestCommitWaitsForActivationMFBA::
|
| + UnblockActivation,
|
| + base::Unretained(this), impl);
|
| + ImplThreadTaskRunner()->PostDelayedTask(
|
| + FROM_HERE, unblock, base::TimeDelta::FromMilliseconds(16 * 4));
|
| }
|
| - num_commits_++;
|
| }
|
|
|
| - void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
|
| - CompletionEvent* activation_completion_event =
|
| - GetProxyImplForTest()->ActivationCompletionEventForTesting();
|
| - switch (num_commits_) {
|
| + void DidCommit() override {
|
| + LOG(ERROR) << "DidCommit " << layer_tree_host()->source_frame_number();
|
| + switch (layer_tree_host()->source_frame_number()) {
|
| case 1:
|
| - EXPECT_FALSE(activation_completion_event);
|
| + // Request a new commit, but DidCommit will be delayed until activation
|
| + // completes.
|
| + layer_tree_host()->SetNextCommitWaitsForActivation();
|
| + layer_tree_host()->SetNeedsCommit();
|
| break;
|
| case 2:
|
| - EXPECT_TRUE(activation_completion_event);
|
| - EXPECT_FALSE(activation_completion_event->IsSignaled());
|
| - break;
|
| - case 3:
|
| - EXPECT_FALSE(activation_completion_event);
|
| + // This DidCommit should not happen until activation is done for the
|
| + // frame.
|
| + {
|
| + base::AutoLock hold(activate_blocked_lock_);
|
| + EXPECT_FALSE(activate_blocked_);
|
| + }
|
| EndTest();
|
| break;
|
| }
|
| }
|
|
|
| - void AfterTest() override {
|
| - // It is safe to read num_commits_ on the main thread now since AfterTest()
|
| - // runs after the LayerTreeHost is destroyed and the impl thread tear down
|
| - // is finished.
|
| - EXPECT_EQ(3, num_commits_);
|
| + void UnblockActivation(LayerTreeHostImpl* impl) {
|
| + LOG(ERROR) << "Unblocked";
|
| + {
|
| + base::AutoLock hold(activate_blocked_lock_);
|
| + activate_blocked_ = false;
|
| + }
|
| + impl->BlockNotifyReadyToActivateForTesting(false);
|
| }
|
|
|
| + void AfterTest() override {}
|
| +
|
| private:
|
| - int num_commits_;
|
| + base::Lock activate_blocked_lock_;
|
| + bool activate_blocked_ = false;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(ProxyMainThreadedCommitWaitsForActivationMFBA);
|
| + DISALLOW_COPY_AND_ASSIGN(LayerTreeHostProxyTestCommitWaitsForActivationMFBA);
|
| };
|
|
|
| -PROXY_MAIN_THREADED_TEST_F(ProxyMainThreadedCommitWaitsForActivationMFBA);
|
| +MULTI_THREAD_TEST_F(LayerTreeHostProxyTestCommitWaitsForActivationMFBA);
|
|
|
| } // namespace cc
|
|
|