Chromium Code Reviews| Index: cc/trees/layer_tree_host_unittest_animation_timelines.cc |
| diff --git a/cc/trees/layer_tree_host_unittest_animation.cc b/cc/trees/layer_tree_host_unittest_animation_timelines.cc |
| similarity index 75% |
| copy from cc/trees/layer_tree_host_unittest_animation.cc |
| copy to cc/trees/layer_tree_host_unittest_animation_timelines.cc |
| index 819571471be0b8783a7643f35e4af0c72b1072f3..1125086cb326dec89caff1610423462497995068 100644 |
| --- a/cc/trees/layer_tree_host_unittest_animation.cc |
| +++ b/cc/trees/layer_tree_host_unittest_animation_timelines.cc |
| @@ -1,22 +1,18 @@ |
| -// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #include "cc/trees/layer_tree_host.h" |
| -#include <stdint.h> |
| - |
| #include "cc/animation/animation_curve.h" |
| #include "cc/animation/animation_host.h" |
| #include "cc/animation/animation_id_provider.h" |
| #include "cc/animation/animation_player.h" |
| -#include "cc/animation/animation_registrar.h" |
| #include "cc/animation/animation_timeline.h" |
| #include "cc/animation/element_animations.h" |
| #include "cc/animation/layer_animation_controller.h" |
| #include "cc/animation/scroll_offset_animation_curve.h" |
| #include "cc/animation/timing_function.h" |
| -#include "cc/animation/transform_operations.h" |
| #include "cc/base/completion_event.h" |
| #include "cc/base/time_util.h" |
| #include "cc/layers/layer.h" |
| @@ -30,9 +26,9 @@ |
| namespace cc { |
| namespace { |
| -class LayerTreeHostAnimationTest : public LayerTreeTest { |
| +class LayerTreeHostTimelinesTest : public LayerTreeTest { |
| public: |
| - LayerTreeHostAnimationTest() |
| + LayerTreeHostTimelinesTest() |
| : timeline_id_(AnimationIdProvider::NextTimelineId()), |
| player_id_(AnimationIdProvider::NextPlayerId()), |
| player_child_id_(AnimationIdProvider::NextPlayerId()) { |
| @@ -43,6 +39,16 @@ class LayerTreeHostAnimationTest : public LayerTreeTest { |
| player_->set_layer_animation_delegate(this); |
| } |
| + void InitializeSettings(LayerTreeSettings* settings) override { |
| + settings->use_compositor_animation_timelines = true; |
| + } |
| + |
| + void InitializeLayerSettings(LayerSettings* layer_settings) override { |
| + layer_settings->use_compositor_animation_timelines = true; |
| + } |
| + |
| + void SetupTree() override { LayerTreeTest::SetupTree(); } |
| + |
| void AttachPlayersToTimeline() { |
| layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); |
| timeline_->AttachPlayer(player_.get()); |
| @@ -59,89 +65,13 @@ class LayerTreeHostAnimationTest : public LayerTreeTest { |
| const int player_child_id_; |
| }; |
| -// Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to |
|
ajuma
2016/03/18 22:09:21
The changes in this file seem mostly unrelated to
Ian Vollick
2016/03/19 03:05:22
Yep, definitely rebasing weirdness. Shouldn't have
|
| -// be set. |
| -class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() |
| - : num_commits_(0) {} |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void BeginMainFrame(const BeginFrameArgs& args) override { |
| - // We skip the first commit because its the commit that populates the |
| - // impl thread with a tree. After the second commit, the test is done. |
| - if (num_commits_ != 1) |
| - return; |
| - |
| - layer_tree_host()->SetNeedsAnimate(); |
| - // Right now, CommitRequested is going to be true, because during |
| - // BeginFrame, we force CommitRequested to true to prevent requests from |
| - // hitting the impl thread. But, when the next DidCommit happens, we should |
| - // verify that CommitRequested has gone back to false. |
| - } |
| - |
| - void DidCommit() override { |
| - if (!num_commits_) { |
| - EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
| - layer_tree_host()->SetNeedsAnimate(); |
| - EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
| - } |
| - |
| - // Verifies that the SetNeedsAnimate we made in ::Animate did not |
| - // trigger CommitRequested. |
| - EXPECT_FALSE(layer_tree_host()->CommitRequested()); |
| - EndTest(); |
| - num_commits_++; |
| - } |
| - |
| - void AfterTest() override {} |
| - |
| - private: |
| - int num_commits_; |
| -}; |
| - |
| -MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested); |
| - |
| -// Trigger a frame with SetNeedsCommit. Then, inside the resulting animate |
| -// callback, request another frame using SetNeedsAnimate. End the test when |
| -// animate gets called yet-again, indicating that the proxy is correctly |
| -// handling the case where SetNeedsAnimate() is called inside the BeginFrame |
| -// flow. |
| -class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() |
| - : num_begin_frames_(0) {} |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void BeginMainFrame(const BeginFrameArgs& args) override { |
| - if (!num_begin_frames_) { |
| - layer_tree_host()->SetNeedsAnimate(); |
| - num_begin_frames_++; |
| - return; |
| - } |
| - EndTest(); |
| - } |
| - |
| - void AfterTest() override {} |
| - |
| - private: |
| - int num_begin_frames_; |
| -}; |
| - |
| -SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); |
| - |
| // Add a layer animation and confirm that |
| // LayerTreeHostImpl::UpdateAnimationState does get called. |
| -class LayerTreeHostAnimationTestAddAnimation |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestAddAnimation |
| +class LayerTreeHostTimelinesTestAddAnimation |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| - LayerTreeHostAnimationTestAddAnimation() |
| + LayerTreeHostTimelinesTestAddAnimation() |
| : update_animation_state_was_called_(false) {} |
| void BeginTest() override { |
| @@ -176,14 +106,15 @@ class LayerTreeHostAnimationTestAddAnimation |
| bool update_animation_state_was_called_; |
| }; |
| -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); |
| +SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestAddAnimation); |
| // Add a layer animation to a layer, but continually fail to draw. Confirm that |
| // after a while, we do eventually force a draw. |
| -class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws. |
| +class LayerTreeHostTimelinesTestCheckerboardDoesNotStarveDraws |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| - LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() |
| + LayerTreeHostTimelinesTestCheckerboardDoesNotStarveDraws() |
| : started_animating_(false) {} |
| void BeginTest() override { |
| @@ -215,13 +146,14 @@ class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws |
| }; |
| // Starvation can only be an issue with the MT compositor. |
| -MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws); |
| +MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestCheckerboardDoesNotStarveDraws); |
| // Ensures that animations eventually get deleted. |
| -class LayerTreeHostAnimationTestAnimationsGetDeleted |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestAnimationsGetDeleted. |
| +class LayerTreeHostTimelinesTestAnimationsGetDeleted |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| - LayerTreeHostAnimationTestAnimationsGetDeleted() |
| + LayerTreeHostTimelinesTestAnimationsGetDeleted() |
| : started_animating_(false) {} |
| void BeginTest() override { |
| @@ -259,15 +191,18 @@ class LayerTreeHostAnimationTestAnimationsGetDeleted |
| bool started_animating_; |
| }; |
| -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationsGetDeleted); |
| +SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestAnimationsGetDeleted); |
| // Ensure that an animation's timing function is respected. |
| -class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestAddAnimationWithTimingFunction. |
| +class LayerTreeHostTimelinesTestAddAnimationWithTimingFunction |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| + LayerTreeHostTimelinesTestAddAnimationWithTimingFunction() {} |
| + |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - picture_ = FakePictureLayer::Create(&client_); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| picture_->SetBounds(gfx::Size(4, 4)); |
| client_.set_bounds(picture_->bounds()); |
| layer_tree_host()->root_layer()->AddChild(picture_); |
| @@ -282,11 +217,6 @@ class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
| void AnimateLayers(LayerTreeHostImpl* host_impl, |
| base::TimeTicks monotonic_time) override { |
| - // TODO(ajuma): This test only checks the active tree. Add checks for |
| - // pending tree too. |
| - if (!host_impl->active_tree()->root_layer()) |
| - return; |
| - |
| // Wait for the commit with the animation to happen. |
| if (host_impl->sync_tree()->source_frame_number() != 0) |
| return; |
| @@ -323,16 +253,19 @@ class LayerTreeHostAnimationTestAddAnimationWithTimingFunction |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestAddAnimationWithTimingFunction); |
| + LayerTreeHostTimelinesTestAddAnimationWithTimingFunction); |
| // Ensures that main thread animations have their start times synchronized with |
| // impl thread animations. |
| -class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestSynchronizeAnimationStartTimes. |
| +class LayerTreeHostTimelinesTestSynchronizeAnimationStartTimes |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| + LayerTreeHostTimelinesTestSynchronizeAnimationStartTimes() {} |
| + |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - picture_ = FakePictureLayer::Create(&client_); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| picture_->SetBounds(gfx::Size(4, 4)); |
| client_.set_bounds(picture_->bounds()); |
| @@ -387,12 +320,15 @@ class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); |
| + LayerTreeHostTimelinesTestSynchronizeAnimationStartTimes); |
| // Ensures that notify animation finished is called. |
| -class LayerTreeHostAnimationTestAnimationFinishedEvents |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestAnimationFinishedEvents. |
| +class LayerTreeHostTimelinesTestAnimationFinishedEvents |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| + LayerTreeHostTimelinesTestAnimationFinishedEvents() {} |
| + |
| void BeginTest() override { |
| AttachPlayersToTimeline(); |
| player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| @@ -414,22 +350,23 @@ class LayerTreeHostAnimationTestAnimationFinishedEvents |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestAnimationFinishedEvents); |
| + LayerTreeHostTimelinesTestAnimationFinishedEvents); |
| // Ensures that when opacity is being animated, this value does not cause the |
| // subtree to be skipped. |
| -class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity. |
| +class LayerTreeHostTimelinesTestDoNotSkipLayersWithAnimatedOpacity |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| - LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity() |
| - : update_check_layer_() {} |
| + LayerTreeHostTimelinesTestDoNotSkipLayersWithAnimatedOpacity() |
| + : update_check_layer_( |
| + FakePictureLayer::Create(layer_settings(), &client_)) {} |
| void SetupTree() override { |
| - update_check_layer_ = FakePictureLayer::Create(&client_); |
| update_check_layer_->SetOpacity(0.f); |
| layer_tree_host()->SetRootLayer(update_check_layer_); |
| client_.set_bounds(update_check_layer_->bounds()); |
| - LayerTreeHostAnimationTest::SetupTree(); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| AttachPlayersToTimeline(); |
| player_->AttachLayer(update_check_layer_->id()); |
| @@ -468,20 +405,23 @@ class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity); |
| + LayerTreeHostTimelinesTestDoNotSkipLayersWithAnimatedOpacity); |
| // Layers added to tree with existing active animations should have the |
| // animation correctly recognized. |
| -class LayerTreeHostAnimationTestLayerAddedWithAnimation |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestLayerAddedWithAnimation. |
| +class LayerTreeHostTimelinesTestLayerAddedWithAnimation |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| + LayerTreeHostTimelinesTestLayerAddedWithAnimation() {} |
| + |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| void DidCommit() override { |
| if (layer_tree_host()->source_frame_number() == 1) { |
| AttachPlayersToTimeline(); |
| - scoped_refptr<Layer> layer = Layer::Create(); |
| + scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
| player_->AttachLayer(layer->id()); |
| player_->set_layer_animation_delegate(this); |
| @@ -505,129 +445,16 @@ class LayerTreeHostAnimationTestLayerAddedWithAnimation |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestLayerAddedWithAnimation); |
| - |
| -class LayerTreeHostAnimationTestCancelAnimateCommit |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - LayerTreeHostAnimationTestCancelAnimateCommit() |
| - : num_begin_frames_(0), num_commit_calls_(0), num_draw_calls_(0) {} |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void BeginMainFrame(const BeginFrameArgs& args) override { |
| - num_begin_frames_++; |
| - // No-op animate will cancel the commit. |
| - if (layer_tree_host()->source_frame_number() == 1) { |
| - EndTest(); |
| - return; |
| - } |
| - layer_tree_host()->SetNeedsAnimate(); |
| - } |
| - |
| - void CommitCompleteOnThread(LayerTreeHostImpl* impl) override { |
| - num_commit_calls_++; |
| - if (impl->active_tree()->source_frame_number() > 1) |
| - FAIL() << "Commit should have been canceled."; |
| - } |
| - |
| - void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| - num_draw_calls_++; |
| - if (impl->active_tree()->source_frame_number() > 1) |
| - FAIL() << "Draw should have been canceled."; |
| - } |
| - |
| - void AfterTest() override { |
| - EXPECT_EQ(2, num_begin_frames_); |
| - EXPECT_EQ(1, num_commit_calls_); |
| - EXPECT_EQ(1, num_draw_calls_); |
| - } |
| - |
| - private: |
| - int num_begin_frames_; |
| - int num_commit_calls_; |
| - int num_draw_calls_; |
| -}; |
| - |
| -MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCancelAnimateCommit); |
| - |
| -class LayerTreeHostAnimationTestForceRedraw |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - LayerTreeHostAnimationTestForceRedraw() |
| - : num_animate_(0), num_draw_layers_(0) {} |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void BeginMainFrame(const BeginFrameArgs& args) override { |
| - if (++num_animate_ < 2) |
| - layer_tree_host()->SetNeedsAnimate(); |
| - } |
| - |
| - void UpdateLayerTreeHost() override { |
| - layer_tree_host()->SetNextCommitForcesRedraw(); |
| - } |
| - |
| - void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| - if (++num_draw_layers_ == 2) |
| - EndTest(); |
| - } |
| - |
| - void AfterTest() override { |
| - // The first commit will always draw; make sure the second draw triggered |
| - // by the animation was not cancelled. |
| - EXPECT_EQ(2, num_draw_layers_); |
| - EXPECT_EQ(2, num_animate_); |
| - } |
| - |
| - private: |
| - int num_animate_; |
| - int num_draw_layers_; |
| -}; |
| - |
| -MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestForceRedraw); |
| - |
| -class LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit() |
| - : num_animate_(0), num_draw_layers_(0) {} |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void BeginMainFrame(const BeginFrameArgs& args) override { |
| - if (++num_animate_ <= 2) { |
| - layer_tree_host()->SetNeedsCommit(); |
| - layer_tree_host()->SetNeedsAnimate(); |
| - } |
| - } |
| - |
| - void DrawLayersOnThread(LayerTreeHostImpl* impl) override { |
| - if (++num_draw_layers_ == 2) |
| - EndTest(); |
| - } |
| - |
| - void AfterTest() override { |
| - // The first commit will always draw; make sure the second draw triggered |
| - // by the SetNeedsCommit was not cancelled. |
| - EXPECT_EQ(2, num_draw_layers_); |
| - EXPECT_GE(num_animate_, 2); |
| - } |
| - |
| - private: |
| - int num_animate_; |
| - int num_draw_layers_; |
| -}; |
| - |
| -MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimateAfterSetNeedsCommit); |
| + LayerTreeHostTimelinesTestLayerAddedWithAnimation); |
| // Animations should not be started when frames are being skipped due to |
| // checkerboard. |
| -class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations. |
| +class LayerTreeHostTimelinesTestCheckerboardDoesntStartAnimations |
| + : public LayerTreeHostTimelinesTest { |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - picture_ = FakePictureLayer::Create(&client_); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| picture_->SetBounds(gfx::Size(4, 4)); |
| client_.set_bounds(picture_->bounds()); |
| layer_tree_host()->root_layer()->AddChild(picture_); |
| @@ -641,7 +468,7 @@ class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations |
| // Make sure that drawing many times doesn't cause a checkerboarded |
| // animation to start so we avoid flake in this test. |
| settings->timeout_and_draw_when_animation_checkerboards = false; |
| - LayerTreeHostAnimationTest::InitializeSettings(settings); |
| + LayerTreeHostTimelinesTest::InitializeSettings(settings); |
| } |
| void BeginTest() override { |
| @@ -703,18 +530,21 @@ class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations |
| }; |
| MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
| + LayerTreeHostTimelinesTestCheckerboardDoesntStartAnimations); |
| // Verifies that scroll offset animations are only accepted when impl-scrolling |
| // is supported, and that when scroll offset animations are accepted, |
| // scroll offset updates are sent back to the main thread. |
| -class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestScrollOffsetChangesArePropagated |
| +class LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| + LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated() {} |
| + |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| - scroll_layer_ = FakePictureLayer::Create(&client_); |
| + scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| scroll_layer_->SetBounds(gfx::Size(1000, 1000)); |
| client_.set_bounds(scroll_layer_->bounds()); |
| @@ -760,22 +590,23 @@ class LayerTreeHostAnimationTestScrollOffsetChangesArePropagated |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); |
| + LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated); |
| // Verifies that when the main thread removes a scroll animation and sets a new |
| // scroll position, the active tree takes on exactly this new scroll position |
| // after activation, and the main thread doesn't receive a spurious scroll |
| // delta. |
| -class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| +class LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| - LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() |
| + LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval() |
| : final_postion_(50.0, 100.0) {} |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| - scroll_layer_ = FakePictureLayer::Create(&client_); |
| + scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
| client_.set_bounds(scroll_layer_->bounds()); |
| @@ -834,7 +665,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| timeline_impl->GetPlayerById(player_child_id_); |
| LayerImpl* scroll_layer_impl = |
| - host_impl->active_tree()->root_layer()->children()[0].get(); |
| + host_impl->active_tree()->root_layer()->children()[0]; |
| Animation* animation = player_impl->element_animations() |
| ->layer_animation_controller() |
| ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| @@ -846,7 +677,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| // Block activation until the running animation has a chance to produce a |
| // scroll delta. |
| - gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); |
| + gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); |
| if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) |
| return; |
| @@ -857,7 +688,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| if (host_impl->pending_tree()->source_frame_number() != 1) |
| return; |
| LayerImpl* scroll_layer_impl = |
| - host_impl->pending_tree()->root_layer()->children()[0].get(); |
| + host_impl->pending_tree()->root_layer()->children()[0]; |
| EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| } |
| @@ -865,7 +696,7 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| if (host_impl->active_tree()->source_frame_number() != 1) |
| return; |
| LayerImpl* scroll_layer_impl = |
| - host_impl->active_tree()->root_layer()->children()[0].get(); |
| + host_impl->active_tree()->root_layer()->children()[0]; |
| EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| EndTest(); |
| } |
| @@ -880,15 +711,16 @@ class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| const gfx::ScrollOffset final_postion_; |
| }; |
| -MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval); |
| +MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval); |
| // When animations are simultaneously added to an existing layer and to a new |
| // layer, they should start at the same time, even when there's already a |
| // running animation on the existing layer. |
| -class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers. |
| +class LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| - LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers() |
| + LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers() |
| : frame_count_with_pending_tree_(0) {} |
| void BeginTest() override { |
| @@ -903,7 +735,7 @@ class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers |
| } else if (layer_tree_host()->source_frame_number() == 2) { |
| AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 0.5f, true); |
| - scoped_refptr<Layer> layer = Layer::Create(); |
| + scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
| layer_tree_host()->root_layer()->AddChild(layer); |
| layer->SetBounds(gfx::Size(4, 4)); |
| @@ -979,191 +811,139 @@ class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers |
| // This test blocks activation which is not supported for single thread mode. |
| MULTI_THREAD_BLOCKNOTIFY_TEST_F( |
| - LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers); |
| + LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers); |
| -class LayerTreeHostAnimationTestPendingTreeAnimatesFirstCommit |
| - : public LayerTreeHostAnimationTest { |
| +// Evolved from LayerTreeHostAnimationTestAddAnimationAfterAnimating. |
| +class LayerTreeHostTimelinesTestAddAnimationAfterAnimating |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - |
| - layer_ = FakePictureLayer::Create(&client_); |
| - layer_->SetBounds(gfx::Size(2, 2)); |
| - client_.set_bounds(layer_->bounds()); |
| - // Transform the layer to 4,4 to start. |
| - gfx::Transform start_transform; |
| - start_transform.Translate(4.0, 4.0); |
| - layer_->SetTransform(start_transform); |
| - |
| - layer_tree_host()->root_layer()->AddChild(layer_); |
| - player_->AttachLayer(layer_->id()); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + content_ = Layer::Create(layer_settings()); |
| + content_->SetBounds(gfx::Size(4, 4)); |
| + layer_tree_host()->root_layer()->AddChild(content_); |
| AttachPlayersToTimeline(); |
| + |
| + player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| + player_child_->AttachLayer(content_->id()); |
| } |
| - void BeginTest() override { |
| - // Add a translate from 6,7 to 8,9. |
| - TransformOperations start; |
| - start.AppendTranslate(6.f, 7.f, 0.f); |
| - TransformOperations end; |
| - end.AppendTranslate(8.f, 9.f, 0.f); |
| - AddAnimatedTransformToPlayer(player_.get(), 4.0, start, end); |
| + void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - PostSetNeedsCommitToMainThread(); |
| + void DidCommit() override { |
| + switch (layer_tree_host()->source_frame_number()) { |
| + case 1: |
| + // First frame: add an animation to the root layer. |
| + AddAnimatedTransformToPlayer(player_.get(), 0.1, 5, 5); |
| + break; |
| + case 2: |
| + // Second frame: add an animation to the content layer. The root layer |
| + // animation has caused us to animate already during this frame. |
| + AddOpacityTransitionToPlayer(player_child_.get(), 0.1, 5, 5, false); |
| + break; |
| + } |
| } |
| - void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { |
| - if (host_impl->sync_tree()->source_frame_number() != 0) |
| - return; |
| - |
| - // After checking this on the sync tree, we will activate, which will cause |
| - // PrepareTiles to happen again (which races with the test exiting). |
| - if (TestEnded()) |
| + void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| + // After both animations have started, verify that they have valid |
| + // start times. |
| + if (host_impl->active_tree()->source_frame_number() < 2) |
| return; |
| - |
| - scoped_refptr<AnimationTimeline> timeline_impl = |
| - host_impl->animation_host()->GetTimelineById(timeline_id_); |
| - scoped_refptr<AnimationPlayer> player_impl = |
| - timeline_impl->GetPlayerById(player_id_); |
| - |
| - LayerAnimationController* controller_impl = |
| - player_impl->element_animations()->layer_animation_controller(); |
| - |
| - LayerImpl* root = host_impl->sync_tree()->root_layer(); |
| - LayerImpl* child = root->children()[0].get(); |
| - Animation* animation = |
| - controller_impl->GetAnimation(TargetProperty::TRANSFORM); |
| - |
| - // The animation should be starting for the first frame. |
| - EXPECT_EQ(Animation::STARTING, animation->run_state()); |
| - |
| - // And the transform should be propogated to the sync tree layer, at its |
| - // starting state which is 6,7. |
| - gfx::Transform expected_transform; |
| - expected_transform.Translate(6.0, 7.0); |
| - EXPECT_EQ(expected_transform, child->DrawTransform()); |
| - // And the sync tree layer should know it is animating. |
| - EXPECT_TRUE(child->screen_space_transform_is_animating()); |
| - |
| - controller_impl->AbortAnimations(TargetProperty::TRANSFORM); |
| - EndTest(); |
| + AnimationRegistrar::AnimationControllerMap controllers_copy = |
| + host_impl->animation_host() |
| + ->animation_registrar() |
| + ->active_animation_controllers_for_testing(); |
| + EXPECT_EQ(2u, controllers_copy.size()); |
| + for (auto& it : controllers_copy) { |
| + int id = it.first; |
| + if (id == host_impl->RootLayer()->id()) { |
| + Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); |
| + EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| + } else if (id == host_impl->RootLayer()->children()[0]->id()) { |
| + Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); |
| + EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| + } |
| + EndTest(); |
| + } |
| } |
| void AfterTest() override {} |
| - FakeContentLayerClient client_; |
| - scoped_refptr<Layer> layer_; |
| + private: |
| + scoped_refptr<Layer> content_; |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestPendingTreeAnimatesFirstCommit); |
| + LayerTreeHostTimelinesTestAddAnimationAfterAnimating); |
| -// When a layer with an animation is removed from the tree and later re-added, |
| -// the animation should resume. |
| -class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded |
| - : public LayerTreeHostAnimationTest { |
| +class LayerTreeHostTimelinesTestRemoveAnimation |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - layer_ = Layer::Create(); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| layer_->SetBounds(gfx::Size(4, 4)); |
| + client_.set_bounds(layer_->bounds()); |
| layer_tree_host()->root_layer()->AddChild(layer_); |
| - layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); |
| - timeline_->AttachPlayer(player_.get()); |
| - player_->AttachLayer(layer_->id()); |
| - DCHECK(player_->element_animations()); |
| + AttachPlayersToTimeline(); |
| - AddOpacityTransitionToPlayer(player_.get(), 10000.0, 0.1f, 0.9f, true); |
| + player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| + player_child_->AttachLayer(layer_->id()); |
| } |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| void DidCommit() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| - case 0: |
| - EXPECT_TRUE(player_->element_animations() |
| - ->has_active_value_observer_for_testing()); |
| - EXPECT_FALSE(player_->element_animations() |
| - ->has_pending_value_observer_for_testing()); |
| - EXPECT_TRUE(layer_tree_host() |
| - ->animation_host() |
| - ->animation_registrar() |
| - ->needs_animate_layers()); |
| - break; |
| case 1: |
| - layer_->RemoveFromParent(); |
| - EXPECT_FALSE(player_->element_animations() |
| - ->has_active_value_observer_for_testing()); |
| - EXPECT_FALSE(player_->element_animations() |
| - ->has_pending_value_observer_for_testing()); |
| - EXPECT_TRUE(layer_tree_host() |
| - ->animation_host() |
| - ->animation_registrar() |
| - ->needs_animate_layers()); |
| + AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| break; |
| case 2: |
| - layer_tree_host()->root_layer()->AddChild(layer_); |
| - EXPECT_TRUE(player_->element_animations() |
| - ->has_active_value_observer_for_testing()); |
| - EXPECT_FALSE(player_->element_animations() |
| - ->has_pending_value_observer_for_testing()); |
| - EXPECT_TRUE(layer_tree_host() |
| - ->animation_host() |
| - ->animation_registrar() |
| - ->needs_animate_layers()); |
| + LayerAnimationController* controller = |
| + player_child_->element_animations()->layer_animation_controller(); |
| + Animation* animation = |
| + controller->GetAnimation(TargetProperty::TRANSFORM); |
| + player_child_->RemoveAnimation(animation->id()); |
| + gfx::Transform transform; |
| + transform.Translate(10.f, 10.f); |
| + layer_->SetTransform(transform); |
| + |
| + // Do something that causes property trees to get rebuilt. |
| + layer_->AddChild(Layer::Create(layer_settings())); |
| break; |
| } |
| } |
| - void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| - scoped_refptr<AnimationTimeline> timeline_impl = |
| - host_impl->animation_host()->GetTimelineById(timeline_id_); |
| - scoped_refptr<AnimationPlayer> player_impl = |
| - timeline_impl->GetPlayerById(player_id_); |
| - |
| - switch (host_impl->active_tree()->source_frame_number()) { |
| - case 0: |
| - EXPECT_TRUE(player_impl->element_animations() |
| - ->has_active_value_observer_for_testing()); |
| - EXPECT_TRUE(host_impl->animation_host() |
| - ->animation_registrar() |
| - ->needs_animate_layers()); |
| - break; |
| - case 1: |
| - EXPECT_FALSE(player_impl->element_animations() |
| - ->has_active_value_observer_for_testing()); |
| - EXPECT_TRUE(host_impl->animation_host() |
| - ->animation_registrar() |
| - ->needs_animate_layers()); |
| - break; |
| - case 2: |
| - EXPECT_TRUE(player_impl->element_animations() |
| - ->has_active_value_observer_for_testing()); |
| - EXPECT_TRUE(host_impl->animation_host() |
| - ->animation_registrar() |
| - ->needs_animate_layers()); |
| - EndTest(); |
| - break; |
| - } |
| + void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| + if (host_impl->active_tree()->source_frame_number() < 2) |
| + return; |
| + gfx::Transform expected_transform; |
| + expected_transform.Translate(10.f, 10.f); |
| + EXPECT_EQ( |
| + expected_transform, |
| + host_impl->active_tree()->root_layer()->children()[0]->DrawTransform()); |
| + EndTest(); |
| } |
| void AfterTest() override {} |
| private: |
| scoped_refptr<Layer> layer_; |
| + FakeContentLayerClient client_; |
| }; |
| -SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded); |
| +SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestRemoveAnimation); |
| -class LayerTreeHostAnimationTestAddAnimationAfterAnimating |
| - : public LayerTreeHostAnimationTest { |
| +class LayerTreeHostTimelinesTestAnimationFinishesDuringCommit |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - layer_ = Layer::Create(); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| layer_->SetBounds(gfx::Size(4, 4)); |
| + client_.set_bounds(layer_->bounds()); |
| layer_tree_host()->root_layer()->AddChild(layer_); |
| AttachPlayersToTimeline(); |
| @@ -1175,39 +955,43 @@ class LayerTreeHostAnimationTestAddAnimationAfterAnimating |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| void DidCommit() override { |
| - switch (layer_tree_host()->source_frame_number()) { |
| + if (layer_tree_host()->source_frame_number() == 1) |
| + AddAnimatedTransformToPlayer(player_child_.get(), 0.04, 5, 5); |
| + } |
| + |
| + void WillCommit() override { |
| + if (layer_tree_host()->source_frame_number() == 2) { |
| + // Block until the animation finishes on the compositor thread. Since |
| + // animations have already been ticked on the main thread, when the commit |
| + // happens the state on the main thread will be consistent with having a |
| + // running animation but the state on the compositor thread will be |
| + // consistent with having only a finished animation. |
| + completion_.Wait(); |
| + } |
| + } |
| + |
| + void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| + switch (host_impl->sync_tree()->source_frame_number()) { |
| case 1: |
| - // First frame: add an animation to the root layer. |
| - AddAnimatedTransformToPlayer(player_.get(), 0.1, 5, 5); |
| + PostSetNeedsCommitToMainThread(); |
| break; |
| case 2: |
| - // Second frame: add an animation to the content layer. The root layer |
| - // animation has caused us to animate already during this frame. |
| - AddOpacityTransitionToPlayer(player_child_.get(), 0.1, 5, 5, false); |
| + gfx::Transform expected_transform; |
| + expected_transform.Translate(5.f, 5.f); |
| + LayerImpl* layer_impl = |
| + host_impl->sync_tree()->root_layer()->children()[0]; |
| + EXPECT_EQ(expected_transform, layer_impl->DrawTransform()); |
| + EndTest(); |
| break; |
| } |
| } |
| - void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| - // After both animations have started, verify that they have valid |
| - // start times. |
| - if (host_impl->active_tree()->source_frame_number() < 2) |
| - return; |
| - AnimationRegistrar::AnimationControllerMap controllers_copy = |
| - host_impl->animation_host() |
| - ->animation_registrar() |
| - ->active_animation_controllers_for_testing(); |
| - EXPECT_EQ(2u, controllers_copy.size()); |
| - for (auto& it : controllers_copy) { |
| - int id = it.first; |
| - if (id == host_impl->RootLayer()->id()) { |
| - Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); |
| - EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| - } else if (id == host_impl->RootLayer()->children()[0]->id()) { |
| - Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); |
| - EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| - } |
| - EndTest(); |
| + void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| + bool has_unfinished_animation) override { |
| + if (host_impl->active_tree()->source_frame_number() == 1 && |
| + !has_unfinished_animation) { |
| + // The animation has finished, so allow the main thread to commit. |
| + completion_.Signal(); |
| } |
| } |
| @@ -1215,17 +999,103 @@ class LayerTreeHostAnimationTestAddAnimationAfterAnimating |
| private: |
| scoped_refptr<Layer> layer_; |
| + FakeContentLayerClient client_; |
| + CompletionEvent completion_; |
| }; |
| -SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestAddAnimationAfterAnimating); |
| +// An animation finishing during commit can only happen when we have a separate |
| +// compositor thread. |
| +MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestAnimationFinishesDuringCommit); |
| + |
| +// Check that SetTransformIsPotentiallyAnimatingChanged is called |
| +// if we destroy LayerAnimationController and ElementAnimations. |
| +class LayerTreeHostTimelinesTestSetPotentiallyAnimatingOnLacDestruction |
| + : public LayerTreeHostTimelinesTest { |
| + public: |
| + void SetupTree() override { |
| + prev_screen_space_transform_is_animating_ = true; |
| + screen_space_transform_animation_stopped_ = false; |
| + |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + AttachPlayersToTimeline(); |
| + player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| + AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); |
| + } |
| + |
| + void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| + |
| + void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| + if (host_impl->pending_tree()->source_frame_number() <= 1) { |
| + EXPECT_TRUE(host_impl->pending_tree() |
| + ->root_layer() |
| + ->screen_space_transform_is_animating()); |
| + } else { |
| + EXPECT_FALSE(host_impl->pending_tree() |
| + ->root_layer() |
| + ->screen_space_transform_is_animating()); |
| + } |
| + } |
| + |
| + void DidCommit() override { PostSetNeedsCommitToMainThread(); } |
| + |
| + void UpdateLayerTreeHost() override { |
| + if (layer_tree_host()->source_frame_number() == 2) { |
| + // Destroy player. |
| + timeline_->DetachPlayer(player_.get()); |
| + player_ = nullptr; |
| + } |
| + } |
| + |
| + DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| + LayerTreeHostImpl::FrameData* frame_data, |
| + DrawResult draw_result) override { |
| + const bool screen_space_transform_is_animating = |
| + host_impl->active_tree() |
| + ->root_layer() |
| + ->screen_space_transform_is_animating(); |
| + |
| + // Check that screen_space_transform_is_animating changes only once. |
| + if (screen_space_transform_is_animating && |
| + prev_screen_space_transform_is_animating_) |
| + EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| + if (!screen_space_transform_is_animating && |
| + prev_screen_space_transform_is_animating_) { |
| + EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| + screen_space_transform_animation_stopped_ = true; |
| + } |
| + if (!screen_space_transform_is_animating && |
| + !prev_screen_space_transform_is_animating_) |
| + EXPECT_TRUE(screen_space_transform_animation_stopped_); |
| + |
| + prev_screen_space_transform_is_animating_ = |
| + screen_space_transform_is_animating; |
| -class LayerTreeHostAnimationTestRemoveAnimation |
| - : public LayerTreeHostAnimationTest { |
| + return draw_result; |
| + } |
| + |
| + void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| + if (host_impl->active_tree()->source_frame_number() >= 2) |
| + EndTest(); |
| + } |
| + |
| + void AfterTest() override { |
| + EXPECT_TRUE(screen_space_transform_animation_stopped_); |
| + } |
| + |
| + bool prev_screen_space_transform_is_animating_; |
| + bool screen_space_transform_animation_stopped_; |
| +}; |
| + |
| +MULTI_THREAD_TEST_F( |
| + LayerTreeHostTimelinesTestSetPotentiallyAnimatingOnLacDestruction); |
| + |
| +// Check that we invalidate property trees on AnimationPlayer::SetNeedsCommit. |
| +class LayerTreeHostTimelinesTestRebuildPropertyTreesOnAnimationSetNeedsCommit |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - layer_ = FakePictureLayer::Create(&client_); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| layer_->SetBounds(gfx::Size(4, 4)); |
| client_.set_bounds(layer_->bounds()); |
| layer_tree_host()->root_layer()->AddChild(layer_); |
| @@ -1239,57 +1109,199 @@ class LayerTreeHostAnimationTestRemoveAnimation |
| void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| void DidCommit() override { |
| + if (layer_tree_host()->source_frame_number() == 1 || |
| + layer_tree_host()->source_frame_number() == 2) |
| + PostSetNeedsCommitToMainThread(); |
| + } |
| + |
| + void UpdateLayerTreeHost() override { |
| + if (layer_tree_host()->source_frame_number() == 1) { |
| + EXPECT_FALSE(layer_tree_host()->property_trees()->needs_rebuild); |
| + AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| + } |
| + |
| + EXPECT_TRUE(layer_tree_host()->property_trees()->needs_rebuild); |
| + } |
| + |
| + void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| + if (host_impl->active_tree()->source_frame_number() >= 2) |
| + EndTest(); |
| + } |
| + |
| + void AfterTest() override {} |
| + |
| + private: |
| + scoped_refptr<Layer> layer_; |
| + FakeContentLayerClient client_; |
| +}; |
| + |
| +MULTI_THREAD_TEST_F( |
| + LayerTreeHostTimelinesTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| + |
| +class LayerTreeHostTimelinesTestPendingTreeAnimatesFirstCommit |
| + : public LayerTreeHostTimelinesTest { |
| + public: |
| + void SetupTree() override { |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + |
| + layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| + layer_->SetBounds(gfx::Size(2, 2)); |
| + client_.set_bounds(layer_->bounds()); |
| + // Transform the layer to 4,4 to start. |
| + gfx::Transform start_transform; |
| + start_transform.Translate(4.0, 4.0); |
| + layer_->SetTransform(start_transform); |
| + |
| + layer_tree_host()->root_layer()->AddChild(layer_); |
| + player_->AttachLayer(layer_->id()); |
| + |
| + AttachPlayersToTimeline(); |
| + } |
| + |
| + void BeginTest() override { |
| + // Add a translate from 6,7 to 8,9. |
| + TransformOperations start; |
| + start.AppendTranslate(6.f, 7.f, 0.f); |
| + TransformOperations end; |
| + end.AppendTranslate(8.f, 9.f, 0.f); |
| + AddAnimatedTransformToPlayer(player_.get(), 4.0, start, end); |
| + |
| + PostSetNeedsCommitToMainThread(); |
| + } |
| + |
| + void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { |
| + if (host_impl->sync_tree()->source_frame_number() != 0) |
| + return; |
| + |
| + // After checking this on the sync tree, we will activate, which will cause |
| + // PrepareTiles to happen again (which races with the test exiting). |
| + if (TestEnded()) |
| + return; |
| + |
| + scoped_refptr<AnimationTimeline> timeline_impl = |
| + host_impl->animation_host()->GetTimelineById(timeline_id_); |
| + scoped_refptr<AnimationPlayer> player_impl = |
| + timeline_impl->GetPlayerById(player_id_); |
| + |
| + LayerAnimationController* controller_impl = |
| + player_impl->element_animations()->layer_animation_controller(); |
| + |
| + LayerImpl* root = host_impl->sync_tree()->root_layer(); |
| + LayerImpl* child = root->children()[0]; |
| + Animation* animation = |
| + controller_impl->GetAnimation(TargetProperty::TRANSFORM); |
| + |
| + // The animation should be starting for the first frame. |
| + EXPECT_EQ(Animation::STARTING, animation->run_state()); |
| + |
| + // And the transform should be propogated to the sync tree layer, at its |
| + // starting state which is 6,7. |
| + gfx::Transform expected_transform; |
| + expected_transform.Translate(6.0, 7.0); |
| + EXPECT_EQ(expected_transform, child->DrawTransform()); |
| + // And the sync tree layer should know it is animating. |
| + EXPECT_TRUE(child->screen_space_transform_is_animating()); |
| + |
| + controller_impl->AbortAnimations(TargetProperty::TRANSFORM); |
| + EndTest(); |
| + } |
| + |
| + void AfterTest() override {} |
| + |
| + FakeContentLayerClient client_; |
| + scoped_refptr<Layer> layer_; |
| +}; |
| + |
| +SINGLE_AND_MULTI_THREAD_TEST_F( |
| + LayerTreeHostTimelinesTestPendingTreeAnimatesFirstCommit); |
| + |
| +// When a layer with an animation is removed from the tree and later re-added, |
| +// the animation should resume. |
| +class LayerTreeHostTimelinesTestAnimatedLayerRemovedAndAdded |
| + : public LayerTreeHostTimelinesTest { |
| + public: |
| + void SetupTree() override { |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + layer_ = Layer::Create(layer_settings()); |
| + layer_->SetBounds(gfx::Size(4, 4)); |
| + layer_tree_host()->root_layer()->AddChild(layer_); |
| + |
| + layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); |
| + timeline_->AttachPlayer(player_.get()); |
| + player_->AttachLayer(layer_->id()); |
| + DCHECK(player_->element_animations()); |
| + |
| + AddOpacityTransitionToPlayer(player_.get(), 10000.0, 0.1f, 0.9f, true); |
| + } |
| + |
| + void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| + |
| + void DidCommit() override { |
| switch (layer_tree_host()->source_frame_number()) { |
| + case 0: |
| + EXPECT_TRUE(player_->element_animations() |
| + ->has_active_value_observer_for_testing()); |
| + EXPECT_FALSE(player_->element_animations() |
| + ->has_pending_value_observer_for_testing()); |
| + EXPECT_TRUE(layer_tree_host() |
| + ->animation_host() |
| + ->animation_registrar() |
| + ->needs_animate_layers()); |
| + break; |
| case 1: |
| - AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| + layer_->RemoveFromParent(); |
| + EXPECT_FALSE(player_->element_animations() |
| + ->has_active_value_observer_for_testing()); |
| + EXPECT_FALSE(player_->element_animations() |
| + ->has_pending_value_observer_for_testing()); |
| + EXPECT_TRUE(layer_tree_host() |
| + ->animation_host() |
| + ->animation_registrar() |
| + ->needs_animate_layers()); |
| break; |
| case 2: |
| - LayerAnimationController* controller = |
| - player_child_->element_animations()->layer_animation_controller(); |
| - Animation* animation = |
| - controller->GetAnimation(TargetProperty::TRANSFORM); |
| - player_child_->RemoveAnimation(animation->id()); |
| - gfx::Transform transform; |
| - transform.Translate(10.f, 10.f); |
| - layer_->SetTransform(transform); |
| - |
| - // Do something that causes property trees to get rebuilt. This is |
| - // intended to simulate the conditions that caused the bug whose fix |
| - // this is testing (the test will pass without it but won't test what |
| - // we want it to). We were updating the wrong transform node at the end |
| - // of an animation (we were assuming the layer with the finished |
| - // animation still had its own transform node). But nodes can only get |
| - // added/deleted when something triggers a rebuild. Adding a layer |
| - // triggers a rebuild, and since the layer that had an animation before |
| - // no longer has one, it doesn't get a transform node in the rebuild. |
| - layer_->AddChild(Layer::Create()); |
| + layer_tree_host()->root_layer()->AddChild(layer_); |
| + EXPECT_TRUE(player_->element_animations() |
| + ->has_active_value_observer_for_testing()); |
| + EXPECT_FALSE(player_->element_animations() |
| + ->has_pending_value_observer_for_testing()); |
| + EXPECT_TRUE(layer_tree_host() |
| + ->animation_host() |
| + ->animation_registrar() |
| + ->needs_animate_layers()); |
| break; |
| } |
| } |
| - void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| - LayerImpl* root = host_impl->active_tree()->root_layer(); |
| - LayerImpl* child = root->children()[0].get(); |
| + void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| + scoped_refptr<AnimationTimeline> timeline_impl = |
| + host_impl->animation_host()->GetTimelineById(timeline_id_); |
| + scoped_refptr<AnimationPlayer> player_impl = |
| + timeline_impl->GetPlayerById(player_id_); |
| + |
| switch (host_impl->active_tree()->source_frame_number()) { |
| case 0: |
| - // No animation yet. |
| + EXPECT_TRUE(player_impl->element_animations() |
| + ->has_active_value_observer_for_testing()); |
| + EXPECT_TRUE(host_impl->animation_host() |
| + ->animation_registrar() |
| + ->needs_animate_layers()); |
| break; |
| case 1: |
| - // Animation is started. |
| - EXPECT_TRUE(child->screen_space_transform_is_animating()); |
| + EXPECT_FALSE(player_impl->element_animations() |
| + ->has_active_value_observer_for_testing()); |
| + EXPECT_TRUE(host_impl->animation_host() |
| + ->animation_registrar() |
| + ->needs_animate_layers()); |
| break; |
| - case 2: { |
| - // The animation is removed, the transform that was set afterward is |
| - // applied. |
| - gfx::Transform expected_transform; |
| - expected_transform.Translate(10.f, 10.f); |
| - EXPECT_EQ(expected_transform, child->DrawTransform()); |
| - EXPECT_FALSE(child->screen_space_transform_is_animating()); |
| + case 2: |
| + EXPECT_TRUE(player_impl->element_animations() |
| + ->has_active_value_observer_for_testing()); |
| + EXPECT_TRUE(host_impl->animation_host() |
| + ->animation_registrar() |
| + ->needs_animate_layers()); |
| EndTest(); |
| break; |
| - } |
| - default: |
| - NOTREACHED(); |
| } |
| } |
| @@ -1297,17 +1309,17 @@ class LayerTreeHostAnimationTestRemoveAnimation |
| private: |
| scoped_refptr<Layer> layer_; |
| - FakeContentLayerClient client_; |
| }; |
| -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestRemoveAnimation); |
| +SINGLE_AND_MULTI_THREAD_TEST_F( |
| + LayerTreeHostTimelinesTestAnimatedLayerRemovedAndAdded); |
| -class LayerTreeHostAnimationTestIsAnimating |
| - : public LayerTreeHostAnimationTest { |
| +class LayerTreeHostTimelinesTestIsAnimating |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - layer_ = FakePictureLayer::Create(&client_); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| layer_->SetBounds(gfx::Size(4, 4)); |
| client_.set_bounds(layer_->bounds()); |
| layer_tree_host()->root_layer()->AddChild(layer_); |
| @@ -1335,7 +1347,7 @@ class LayerTreeHostAnimationTestIsAnimating |
| void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| LayerImpl* root = host_impl->sync_tree()->root_layer(); |
| - LayerImpl* child = root->children()[0].get(); |
| + LayerImpl* child = root->children()[0]; |
| switch (host_impl->sync_tree()->source_frame_number()) { |
| case 0: |
| // No animation yet. |
| @@ -1356,7 +1368,7 @@ class LayerTreeHostAnimationTestIsAnimating |
| void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| LayerImpl* root = host_impl->active_tree()->root_layer(); |
| - LayerImpl* child = root->children()[0].get(); |
| + LayerImpl* child = root->children()[0]; |
| switch (host_impl->active_tree()->source_frame_number()) { |
| case 0: |
| // No animation yet. |
| @@ -1382,93 +1394,17 @@ class LayerTreeHostAnimationTestIsAnimating |
| FakeContentLayerClient client_; |
| }; |
| -SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestIsAnimating); |
| - |
| -class LayerTreeHostAnimationTestAnimationFinishesDuringCommit |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - LayerTreeHostAnimationTestAnimationFinishesDuringCommit() |
| - : signalled_(false) {} |
| - |
| - void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - layer_ = FakePictureLayer::Create(&client_); |
| - layer_->SetBounds(gfx::Size(4, 4)); |
| - client_.set_bounds(layer_->bounds()); |
| - layer_tree_host()->root_layer()->AddChild(layer_); |
| - |
| - AttachPlayersToTimeline(); |
| - |
| - player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| - player_child_->AttachLayer(layer_->id()); |
| - } |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void DidCommit() override { |
| - if (layer_tree_host()->source_frame_number() == 1) |
| - AddAnimatedTransformToPlayer(player_child_.get(), 0.04, 5, 5); |
| - } |
| - |
| - void WillCommit() override { |
| - if (layer_tree_host()->source_frame_number() == 2) { |
| - // Block until the animation finishes on the compositor thread. Since |
| - // animations have already been ticked on the main thread, when the commit |
| - // happens the state on the main thread will be consistent with having a |
| - // running animation but the state on the compositor thread will be |
| - // consistent with having only a finished animation. |
| - completion_.Wait(); |
| - } |
| - } |
| - |
| - void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| - switch (host_impl->sync_tree()->source_frame_number()) { |
| - case 1: |
| - PostSetNeedsCommitToMainThread(); |
| - break; |
| - case 2: |
| - gfx::Transform expected_transform; |
| - expected_transform.Translate(5.f, 5.f); |
| - LayerImpl* layer_impl = |
| - host_impl->sync_tree()->root_layer()->children()[0].get(); |
| - EXPECT_EQ(expected_transform, layer_impl->DrawTransform()); |
| - EndTest(); |
| - break; |
| - } |
| - } |
| - |
| - void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| - bool has_unfinished_animation) override { |
| - if (host_impl->active_tree()->source_frame_number() == 1 && |
| - !has_unfinished_animation && !signalled_) { |
| - // The animation has finished, so allow the main thread to commit. |
| - completion_.Signal(); |
| - signalled_ = true; |
| - } |
| - } |
| - |
| - void AfterTest() override {} |
| - |
| - private: |
| - scoped_refptr<Layer> layer_; |
| - FakeContentLayerClient client_; |
| - CompletionEvent completion_; |
| - bool signalled_; |
| -}; |
| - |
| -// An animation finishing during commit can only happen when we have a separate |
| -// compositor thread. |
| -MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationFinishesDuringCommit); |
| +SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestIsAnimating); |
| -class LayerTreeHostAnimationTestNotifyAnimationFinished |
| - : public LayerTreeHostAnimationTest { |
| +class LayerTreeHostTimelinesTestNotifyAnimationFinished |
| + : public LayerTreeHostTimelinesTest { |
| public: |
| - LayerTreeHostAnimationTestNotifyAnimationFinished() |
| + LayerTreeHostTimelinesTestNotifyAnimationFinished() |
| : called_animation_started_(false), called_animation_finished_(false) {} |
| void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - picture_ = FakePictureLayer::Create(&client_); |
| + LayerTreeHostTimelinesTest::SetupTree(); |
| + picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
| picture_->SetBounds(gfx::Size(4, 4)); |
| client_.set_bounds(picture_->bounds()); |
| layer_tree_host()->root_layer()->AddChild(picture_); |
| @@ -1511,138 +1447,7 @@ class LayerTreeHostAnimationTestNotifyAnimationFinished |
| }; |
| SINGLE_AND_MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestNotifyAnimationFinished); |
| - |
| -// Check that SetTransformIsPotentiallyAnimatingChanged is called |
| -// if we destroy LayerAnimationController and ElementAnimations. |
| -class LayerTreeHostAnimationTestSetPotentiallyAnimatingOnLacDestruction |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - void SetupTree() override { |
| - prev_screen_space_transform_is_animating_ = true; |
| - screen_space_transform_animation_stopped_ = false; |
| - |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - AttachPlayersToTimeline(); |
| - player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| - AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); |
| - } |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| - if (host_impl->pending_tree()->source_frame_number() <= 1) { |
| - EXPECT_TRUE(host_impl->pending_tree() |
| - ->root_layer() |
| - ->screen_space_transform_is_animating()); |
| - } else { |
| - EXPECT_FALSE(host_impl->pending_tree() |
| - ->root_layer() |
| - ->screen_space_transform_is_animating()); |
| - } |
| - } |
| - |
| - void DidCommit() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void UpdateLayerTreeHost() override { |
| - if (layer_tree_host()->source_frame_number() == 2) { |
| - // Destroy player. |
| - timeline_->DetachPlayer(player_.get()); |
| - player_ = nullptr; |
| - } |
| - } |
| - |
| - DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| - LayerTreeHostImpl::FrameData* frame_data, |
| - DrawResult draw_result) override { |
| - const bool screen_space_transform_is_animating = |
| - host_impl->active_tree() |
| - ->root_layer() |
| - ->screen_space_transform_is_animating(); |
| - |
| - // Check that screen_space_transform_is_animating changes only once. |
| - if (screen_space_transform_is_animating && |
| - prev_screen_space_transform_is_animating_) |
| - EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| - if (!screen_space_transform_is_animating && |
| - prev_screen_space_transform_is_animating_) { |
| - EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| - screen_space_transform_animation_stopped_ = true; |
| - } |
| - if (!screen_space_transform_is_animating && |
| - !prev_screen_space_transform_is_animating_) |
| - EXPECT_TRUE(screen_space_transform_animation_stopped_); |
| - |
| - prev_screen_space_transform_is_animating_ = |
| - screen_space_transform_is_animating; |
| - |
| - return draw_result; |
| - } |
| - |
| - void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| - if (host_impl->active_tree()->source_frame_number() >= 2) |
| - EndTest(); |
| - } |
| - |
| - void AfterTest() override { |
| - EXPECT_TRUE(screen_space_transform_animation_stopped_); |
| - } |
| - |
| - bool prev_screen_space_transform_is_animating_; |
| - bool screen_space_transform_animation_stopped_; |
| -}; |
| - |
| -MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestSetPotentiallyAnimatingOnLacDestruction); |
| - |
| -// Check that we invalidate property trees on AnimationPlayer::SetNeedsCommit. |
| -class LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit |
| - : public LayerTreeHostAnimationTest { |
| - public: |
| - void SetupTree() override { |
| - LayerTreeHostAnimationTest::SetupTree(); |
| - layer_ = FakePictureLayer::Create(&client_); |
| - layer_->SetBounds(gfx::Size(4, 4)); |
| - client_.set_bounds(layer_->bounds()); |
| - layer_tree_host()->root_layer()->AddChild(layer_); |
| - |
| - AttachPlayersToTimeline(); |
| - |
| - player_->AttachLayer(layer_tree_host()->root_layer()->id()); |
| - player_child_->AttachLayer(layer_->id()); |
| - } |
| - |
| - void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| - |
| - void DidCommit() override { |
| - if (layer_tree_host()->source_frame_number() == 1 || |
| - layer_tree_host()->source_frame_number() == 2) |
| - PostSetNeedsCommitToMainThread(); |
| - } |
| - |
| - void UpdateLayerTreeHost() override { |
| - if (layer_tree_host()->source_frame_number() == 1) { |
| - EXPECT_FALSE(layer_tree_host()->property_trees()->needs_rebuild); |
| - AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| - } |
| - |
| - EXPECT_TRUE(layer_tree_host()->property_trees()->needs_rebuild); |
| - } |
| - |
| - void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
| - if (host_impl->active_tree()->source_frame_number() >= 2) |
| - EndTest(); |
| - } |
| - |
| - void AfterTest() override {} |
| - |
| - private: |
| - scoped_refptr<Layer> layer_; |
| - FakeContentLayerClient client_; |
| -}; |
| - |
| -MULTI_THREAD_TEST_F( |
| - LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| + LayerTreeHostTimelinesTestNotifyAnimationFinished); |
| } // namespace |
| } // namespace cc |