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" |
11 #include "cc/animation/animation_id_provider.h" | 11 #include "cc/animation/animation_id_provider.h" |
12 #include "cc/animation/animation_player.h" | 12 #include "cc/animation/animation_player.h" |
13 #include "cc/animation/animation_timeline.h" | 13 #include "cc/animation/animation_timeline.h" |
14 #include "cc/animation/element_animations.h" | 14 #include "cc/animation/element_animations.h" |
15 #include "cc/animation/scroll_offset_animation_curve.h" | 15 #include "cc/animation/scroll_offset_animation_curve.h" |
| 16 #include "cc/animation/scroll_offset_animations.h" |
16 #include "cc/animation/timing_function.h" | 17 #include "cc/animation/timing_function.h" |
17 #include "cc/animation/transform_operations.h" | 18 #include "cc/animation/transform_operations.h" |
18 #include "cc/base/completion_event.h" | 19 #include "cc/base/completion_event.h" |
19 #include "cc/base/time_util.h" | 20 #include "cc/base/time_util.h" |
20 #include "cc/layers/layer.h" | 21 #include "cc/layers/layer.h" |
21 #include "cc/layers/layer_impl.h" | 22 #include "cc/layers/layer_impl.h" |
22 #include "cc/test/animation_test_common.h" | 23 #include "cc/test/animation_test_common.h" |
23 #include "cc/test/fake_content_layer_client.h" | 24 #include "cc/test/fake_content_layer_client.h" |
24 #include "cc/test/fake_picture_layer.h" | 25 #include "cc/test/fake_picture_layer.h" |
25 #include "cc/test/layer_tree_test.h" | 26 #include "cc/test/layer_tree_test.h" |
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 | 804 |
804 void AfterTest() override {} | 805 void AfterTest() override {} |
805 | 806 |
806 private: | 807 private: |
807 FakeContentLayerClient client_; | 808 FakeContentLayerClient client_; |
808 scoped_refptr<FakePictureLayer> scroll_layer_; | 809 scoped_refptr<FakePictureLayer> scroll_layer_; |
809 }; | 810 }; |
810 | 811 |
811 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationTakeover); | 812 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationTakeover); |
812 | 813 |
| 814 // Verifies that an impl-only scroll offset animation gets updated when the |
| 815 // scroll offset is adjusted on the main thread. |
| 816 class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted |
| 817 : public LayerTreeHostAnimationTest { |
| 818 public: |
| 819 LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted() {} |
| 820 |
| 821 void SetupTree() override { |
| 822 LayerTreeHostAnimationTest::SetupTree(); |
| 823 |
| 824 scroll_layer_ = FakePictureLayer::Create(&client_); |
| 825 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
| 826 client_.set_bounds(scroll_layer_->bounds()); |
| 827 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 828 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 829 |
| 830 AttachPlayersToTimeline(); |
| 831 player_child_->AttachElement(scroll_layer_->id()); |
| 832 } |
| 833 |
| 834 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 835 |
| 836 void DidCommit() override { |
| 837 if (layer_tree_host()->source_frame_number() == 1) { |
| 838 // Add an update after the first commit to trigger the animation update |
| 839 // path. |
| 840 ScrollOffsetAnimationUpdate update( |
| 841 ScrollOffsetAnimationUpdate::Type::SCROLL_OFFSET_CHANGED, |
| 842 scroll_layer_->id()); |
| 843 update.adjustment_ = gfx::Vector2dF(100.f, 100.f); |
| 844 layer_tree_host()->animation_host()->scroll_offset_animations().AddUpdate( |
| 845 update); |
| 846 EXPECT_TRUE(layer_tree_host() |
| 847 ->animation_host() |
| 848 ->scroll_offset_animations() |
| 849 .HasUpdatesForTesting()); |
| 850 } else if (layer_tree_host()->source_frame_number() == 2) { |
| 851 // Verify that the update queue is cleared after the update is applied. |
| 852 EXPECT_FALSE(layer_tree_host() |
| 853 ->animation_host() |
| 854 ->scroll_offset_animations() |
| 855 .HasUpdatesForTesting()); |
| 856 } |
| 857 } |
| 858 |
| 859 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| 860 // Note that the frame number gets incremented after BeginCommitOnThread but |
| 861 // before WillCommitCompleteOnThread and CommitCompleteOnThread. |
| 862 if (host_impl->sync_tree()->source_frame_number() == 0) { |
| 863 // This happens after the impl-only animation is added in |
| 864 // WillCommitCompleteOnThread. |
| 865 Animation* animation = |
| 866 host_impl->animation_host() |
| 867 ->GetElementAnimationsForElementId(scroll_layer_->id()) |
| 868 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 869 ScrollOffsetAnimationCurve* curve = |
| 870 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 871 |
| 872 // Verifiy the initial and target position before the scroll offset |
| 873 // update from MT. |
| 874 EXPECT_EQ(Animation::RunState::RUNNING, animation->run_state()); |
| 875 EXPECT_EQ(gfx::ScrollOffset(10.f, 20.f), |
| 876 curve->GetValue(base::TimeDelta())); |
| 877 EXPECT_EQ(gfx::ScrollOffset(650.f, 750.f), curve->target_value()); |
| 878 } |
| 879 } |
| 880 |
| 881 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 882 if (host_impl->sync_tree()->source_frame_number() == 0) { |
| 883 host_impl->animation_host()->ImplOnlyScrollAnimationCreate( |
| 884 scroll_layer_->id(), gfx::ScrollOffset(650.f, 750.f), |
| 885 gfx::ScrollOffset(10, 20)); |
| 886 } |
| 887 } |
| 888 |
| 889 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 890 if (host_impl->sync_tree()->source_frame_number() == 1) { |
| 891 Animation* animation = |
| 892 host_impl->animation_host() |
| 893 ->GetElementAnimationsForElementId(scroll_layer_->id()) |
| 894 ->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 895 ScrollOffsetAnimationCurve* curve = |
| 896 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 897 // Verifiy the initial and target position after the scroll offset |
| 898 // update from MT |
| 899 EXPECT_EQ(Animation::RunState::STARTING, animation->run_state()); |
| 900 EXPECT_EQ(gfx::ScrollOffset(110.f, 120.f), |
| 901 curve->GetValue(base::TimeDelta())); |
| 902 EXPECT_EQ(gfx::ScrollOffset(750.f, 850.f), curve->target_value()); |
| 903 |
| 904 EndTest(); |
| 905 } |
| 906 } |
| 907 |
| 908 void AfterTest() override {} |
| 909 |
| 910 private: |
| 911 FakeContentLayerClient client_; |
| 912 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 913 }; |
| 914 |
| 915 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted); |
| 916 |
813 // Verifies that when the main thread removes a scroll animation and sets a new | 917 // 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 | 918 // 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 | 919 // after activation, and the main thread doesn't receive a spurious scroll |
816 // delta. | 920 // delta. |
817 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval | 921 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
818 : public LayerTreeHostAnimationTest { | 922 : public LayerTreeHostAnimationTest { |
819 public: | 923 public: |
820 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() | 924 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() |
821 : final_postion_(50.0, 100.0) {} | 925 : final_postion_(50.0, 100.0) {} |
822 | 926 |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1659 private: | 1763 private: |
1660 scoped_refptr<Layer> layer_; | 1764 scoped_refptr<Layer> layer_; |
1661 FakeContentLayerClient client_; | 1765 FakeContentLayerClient client_; |
1662 }; | 1766 }; |
1663 | 1767 |
1664 MULTI_THREAD_TEST_F( | 1768 MULTI_THREAD_TEST_F( |
1665 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | 1769 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
1666 | 1770 |
1667 } // namespace | 1771 } // namespace |
1668 } // namespace cc | 1772 } // namespace cc |
OLD | NEW |