| 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 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 player_child_->RemoveAnimation(animation->id()); | 855 player_child_->RemoveAnimation(animation->id()); |
| 856 scroll_layer_->SetScrollOffset(final_postion_); | 856 scroll_layer_->SetScrollOffset(final_postion_); |
| 857 break; | 857 break; |
| 858 } | 858 } |
| 859 default: | 859 default: |
| 860 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 860 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 861 } | 861 } |
| 862 } | 862 } |
| 863 | 863 |
| 864 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 864 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| 865 host_impl->BlockNotifyReadyToActivateForTesting(true); | 865 host_impl->BlockNotifyReadyToActivateForTesting( |
| 866 ShouldBlockActivation(host_impl)); |
| 866 } | 867 } |
| 867 | 868 |
| 868 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, | 869 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
| 869 const BeginFrameArgs& args) override { | 870 const BeginFrameArgs& args) override { |
| 870 if (!host_impl->pending_tree()) | 871 host_impl->BlockNotifyReadyToActivateForTesting( |
| 871 return; | 872 ShouldBlockActivation(host_impl)); |
| 872 | |
| 873 if (!host_impl->active_tree()->root_layer()) { | |
| 874 host_impl->BlockNotifyReadyToActivateForTesting(false); | |
| 875 return; | |
| 876 } | |
| 877 | |
| 878 scoped_refptr<AnimationTimeline> timeline_impl = | |
| 879 host_impl->animation_host()->GetTimelineById(timeline_id_); | |
| 880 scoped_refptr<AnimationPlayer> player_impl = | |
| 881 timeline_impl->GetPlayerById(player_child_id_); | |
| 882 | |
| 883 LayerImpl* scroll_layer_impl = | |
| 884 host_impl->active_tree()->LayerById(scroll_layer_->id()); | |
| 885 Animation* animation = player_impl->element_animations() | |
| 886 ->GetAnimation(TargetProperty::SCROLL_OFFSET); | |
| 887 | |
| 888 if (!animation || animation->run_state() != Animation::RUNNING) { | |
| 889 host_impl->BlockNotifyReadyToActivateForTesting(false); | |
| 890 return; | |
| 891 } | |
| 892 | |
| 893 // Block activation until the running animation has a chance to produce a | |
| 894 // scroll delta. | |
| 895 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); | |
| 896 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) | |
| 897 return; | |
| 898 | |
| 899 host_impl->BlockNotifyReadyToActivateForTesting(false); | |
| 900 } | 873 } |
| 901 | 874 |
| 902 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 875 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 903 if (host_impl->pending_tree()->source_frame_number() != 1) | 876 if (host_impl->pending_tree()->source_frame_number() != 1) |
| 904 return; | 877 return; |
| 905 LayerImpl* scroll_layer_impl = | 878 LayerImpl* scroll_layer_impl = |
| 906 host_impl->pending_tree()->LayerById(scroll_layer_->id()); | 879 host_impl->pending_tree()->LayerById(scroll_layer_->id()); |
| 907 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); | 880 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| 908 } | 881 } |
| 909 | 882 |
| 910 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 883 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 911 if (host_impl->active_tree()->source_frame_number() != 1) | 884 if (host_impl->active_tree()->source_frame_number() != 1) |
| 912 return; | 885 return; |
| 913 LayerImpl* scroll_layer_impl = | 886 LayerImpl* scroll_layer_impl = |
| 914 host_impl->active_tree()->LayerById(scroll_layer_->id()); | 887 host_impl->active_tree()->LayerById(scroll_layer_->id()); |
| 915 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); | 888 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| 916 EndTest(); | 889 EndTest(); |
| 917 } | 890 } |
| 918 | 891 |
| 919 void AfterTest() override { | 892 void AfterTest() override { |
| 920 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 893 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 921 } | 894 } |
| 922 | 895 |
| 923 private: | 896 private: |
| 897 bool ShouldBlockActivation(LayerTreeHostImpl* host_impl) { |
| 898 if (!host_impl->pending_tree()) |
| 899 return false; |
| 900 |
| 901 if (!host_impl->active_tree()->root_layer()) |
| 902 return false; |
| 903 |
| 904 scoped_refptr<AnimationTimeline> timeline_impl = |
| 905 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 906 scoped_refptr<AnimationPlayer> player_impl = |
| 907 timeline_impl->GetPlayerById(player_child_id_); |
| 908 |
| 909 LayerImpl* scroll_layer_impl = |
| 910 host_impl->active_tree()->LayerById(scroll_layer_->id()); |
| 911 Animation* animation = player_impl->element_animations()->GetAnimation( |
| 912 TargetProperty::SCROLL_OFFSET); |
| 913 |
| 914 if (!animation || animation->run_state() != Animation::RUNNING) |
| 915 return false; |
| 916 |
| 917 // Block activation until the running animation has a chance to produce a |
| 918 // scroll delta. |
| 919 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); |
| 920 if (scroll_delta.x() > 0.f || scroll_delta.y() > 0.f) |
| 921 return false; |
| 922 |
| 923 return true; |
| 924 } |
| 925 |
| 924 FakeContentLayerClient client_; | 926 FakeContentLayerClient client_; |
| 925 scoped_refptr<FakePictureLayer> scroll_layer_; | 927 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 926 const gfx::ScrollOffset final_postion_; | 928 const gfx::ScrollOffset final_postion_; |
| 927 }; | 929 }; |
| 928 | 930 |
| 929 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval); | 931 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval); |
| 930 | 932 |
| 931 // When animations are simultaneously added to an existing layer and to a new | 933 // When animations are simultaneously added to an existing layer and to a new |
| 932 // layer, they should start at the same time, even when there's already a | 934 // layer, they should start at the same time, even when there's already a |
| 933 // running animation on the existing layer. | 935 // running animation on the existing layer. |
| (...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 private: | 1659 private: |
| 1658 scoped_refptr<Layer> layer_; | 1660 scoped_refptr<Layer> layer_; |
| 1659 FakeContentLayerClient client_; | 1661 FakeContentLayerClient client_; |
| 1660 }; | 1662 }; |
| 1661 | 1663 |
| 1662 MULTI_THREAD_TEST_F( | 1664 MULTI_THREAD_TEST_F( |
| 1663 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | 1665 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| 1664 | 1666 |
| 1665 } // namespace | 1667 } // namespace |
| 1666 } // namespace cc | 1668 } // namespace cc |
| OLD | NEW |