| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "cc/animation/animation_curve.h" | 9 #include "cc/animation/animation_curve.h" |
| 10 #include "cc/animation/animation_host.h" | 10 #include "cc/animation/animation_host.h" |
| (...skipping 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 803 |
| 804 void AfterTest() override {} | 804 void AfterTest() override {} |
| 805 | 805 |
| 806 private: | 806 private: |
| 807 FakeContentLayerClient client_; | 807 FakeContentLayerClient client_; |
| 808 scoped_refptr<FakePictureLayer> scroll_layer_; | 808 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 809 }; | 809 }; |
| 810 | 810 |
| 811 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationTakeover); | 811 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationTakeover); |
| 812 | 812 |
| 813 // Verifies that an impl-only scroll offset animation gets updated when the |
| 814 // scroll offset is adjusted on the main thread. |
| 815 class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted |
| 816 : public LayerTreeHostAnimationTest { |
| 817 public: |
| 818 LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted() {} |
| 819 |
| 820 void SetupTree() override { |
| 821 LayerTreeHostAnimationTest::SetupTree(); |
| 822 |
| 823 scroll_layer_ = FakePictureLayer::Create(&client_); |
| 824 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
| 825 client_.set_bounds(scroll_layer_->bounds()); |
| 826 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 827 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 828 |
| 829 AttachPlayersToTimeline(); |
| 830 player_child_->AttachElement(scroll_layer_->id()); |
| 831 } |
| 832 |
| 833 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 834 |
| 835 void DidCommit() override { |
| 836 if (layer_tree_host()->source_frame_number() == 1) { |
| 837 // Add an update after the first commit to trigger the animation update |
| 838 // path. |
| 839 ScrollOffsetAnimationUpdate update; |
| 840 update.type_ = ScrollOffsetAnimationUpdate::Type::SCROLL_OFFSET_CHANGED; |
| 841 update.adjustment_ = gfx::Vector2dF(100.f, 100.f); |
| 842 update.element_id_ = scroll_layer_->id(); |
| 843 layer_tree_host()->animation_host()->AddScrollOffsetAnimationUpdate( |
| 844 update); |
| 845 EXPECT_TRUE(layer_tree_host() |
| 846 ->animation_host() |
| 847 ->HasScrollOffsetAnimationUpdatesForTesting()); |
| 848 } else if (layer_tree_host()->source_frame_number() == 2) { |
| 849 // Verify that the update queue is cleared after the update is applied. |
| 850 EXPECT_FALSE(layer_tree_host() |
| 851 ->animation_host() |
| 852 ->HasScrollOffsetAnimationUpdatesForTesting()); |
| 853 } |
| 854 } |
| 855 |
| 856 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| 857 // Note that the frame number gets incremented after BeginCommitOnThread but |
| 858 // before WillCommitCompleteOnThread and CommitCompleteOnThread. |
| 859 if (host_impl->sync_tree()->source_frame_number() == 0) { |
| 860 // This happens after the impl-only animation is added in |
| 861 // WillCommitCompleteOnThread. |
| 862 Animation* animation = |
| 863 host_impl->animation_host() |
| 864 ->GetElementAnimationsForElementId(scroll_layer_->id()) |
| 865 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 866 ScrollOffsetAnimationCurve* curve = |
| 867 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 868 |
| 869 // Verifiy the initial and target position before the scroll offset |
| 870 // update from MT. |
| 871 EXPECT_EQ(Animation::RunState::RUNNING, animation->run_state()); |
| 872 EXPECT_EQ(gfx::ScrollOffset(10.f, 20.f), |
| 873 curve->GetValue(base::TimeDelta())); |
| 874 EXPECT_EQ(gfx::ScrollOffset(650.f, 750.f), curve->target_value()); |
| 875 |
| 876 // This is how far the animation is reached until now. It is used to |
| 877 // determine the expecation of initial_positon_ after the update. |
| 878 current_offset_ = curve->GetValue(animation->TrimTimeToCurrentIteration( |
| 879 host_impl->CurrentBeginFrameArgs().frame_time)); |
| 880 } |
| 881 } |
| 882 |
| 883 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 884 if (host_impl->sync_tree()->source_frame_number() == 0) { |
| 885 host_impl->animation_host()->ImplOnlyScrollAnimationCreate( |
| 886 scroll_layer_->id(), gfx::ScrollOffset(650.f, 750.f), |
| 887 gfx::ScrollOffset(10, 20)); |
| 888 } |
| 889 } |
| 890 |
| 891 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 892 if (host_impl->sync_tree()->source_frame_number() == 1) { |
| 893 Animation* animation = |
| 894 host_impl->animation_host() |
| 895 ->GetElementAnimationsForElementId(scroll_layer_->id()) |
| 896 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 897 ScrollOffsetAnimationCurve* curve = |
| 898 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 899 // Verifiy the initial and target position after the scroll offset |
| 900 // update from MT |
| 901 EXPECT_EQ(Animation::RunState::STARTING, animation->run_state()); |
| 902 EXPECT_EQ( |
| 903 ScrollOffsetWithDelta(current_offset_, gfx::Vector2dF(100.f, 100.f)), |
| 904 curve->GetValue(base::TimeDelta())); |
| 905 EXPECT_EQ(gfx::ScrollOffset(750.f, 850.f), curve->target_value()); |
| 906 |
| 907 EndTest(); |
| 908 } |
| 909 } |
| 910 |
| 911 void AfterTest() override {} |
| 912 |
| 913 private: |
| 914 FakeContentLayerClient client_; |
| 915 gfx::ScrollOffset current_offset_; |
| 916 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 917 }; |
| 918 |
| 919 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted); |
| 920 |
| 813 // Verifies that when the main thread removes a scroll animation and sets a new | 921 // Verifies that when the main thread removes a scroll animation and sets a new |
| 814 // scroll position, the active tree takes on exactly this new scroll position | 922 // scroll position, the active tree takes on exactly this new scroll position |
| 815 // after activation, and the main thread doesn't receive a spurious scroll | 923 // after activation, and the main thread doesn't receive a spurious scroll |
| 816 // delta. | 924 // delta. |
| 817 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval | 925 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| 818 : public LayerTreeHostAnimationTest { | 926 : public LayerTreeHostAnimationTest { |
| 819 public: | 927 public: |
| 820 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() | 928 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() |
| 821 : final_postion_(50.0, 100.0) {} | 929 : final_postion_(50.0, 100.0) {} |
| 822 | 930 |
| (...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 private: | 1765 private: |
| 1658 scoped_refptr<Layer> layer_; | 1766 scoped_refptr<Layer> layer_; |
| 1659 FakeContentLayerClient client_; | 1767 FakeContentLayerClient client_; |
| 1660 }; | 1768 }; |
| 1661 | 1769 |
| 1662 MULTI_THREAD_TEST_F( | 1770 MULTI_THREAD_TEST_F( |
| 1663 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | 1771 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| 1664 | 1772 |
| 1665 } // namespace | 1773 } // namespace |
| 1666 } // namespace cc | 1774 } // namespace cc |
| OLD | NEW |