| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 player_->set_animation_delegate(this); | 43 player_->set_animation_delegate(this); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void AttachPlayersToTimeline() { | 46 void AttachPlayersToTimeline() { |
| 47 layer_tree()->animation_host()->AddAnimationTimeline(timeline_.get()); | 47 layer_tree()->animation_host()->AddAnimationTimeline(timeline_.get()); |
| 48 layer_tree()->SetElementIdsForTesting(); | 48 layer_tree()->SetElementIdsForTesting(); |
| 49 timeline_->AttachPlayer(player_.get()); | 49 timeline_->AttachPlayer(player_.get()); |
| 50 timeline_->AttachPlayer(player_child_.get()); | 50 timeline_->AttachPlayer(player_child_.get()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 void GetImplTimelineAndPlayerByID(const LayerTreeHostImpl& host_impl) { |
| 54 AnimationHost* animation_host_impl = host_impl.animation_host(); |
| 55 timeline_impl_ = animation_host_impl->GetTimelineById(timeline_id_); |
| 56 EXPECT_TRUE(timeline_impl_); |
| 57 player_impl_ = timeline_impl_->GetPlayerById(player_id_); |
| 58 EXPECT_TRUE(player_impl_); |
| 59 player_child_impl_ = timeline_impl_->GetPlayerById(player_child_id_); |
| 60 EXPECT_TRUE(player_child_impl_); |
| 61 } |
| 62 |
| 53 protected: | 63 protected: |
| 54 scoped_refptr<AnimationTimeline> timeline_; | 64 scoped_refptr<AnimationTimeline> timeline_; |
| 55 scoped_refptr<AnimationPlayer> player_; | 65 scoped_refptr<AnimationPlayer> player_; |
| 56 scoped_refptr<AnimationPlayer> player_child_; | 66 scoped_refptr<AnimationPlayer> player_child_; |
| 57 | 67 |
| 68 scoped_refptr<AnimationTimeline> timeline_impl_; |
| 69 scoped_refptr<AnimationPlayer> player_impl_; |
| 70 scoped_refptr<AnimationPlayer> player_child_impl_; |
| 71 |
| 58 const int timeline_id_; | 72 const int timeline_id_; |
| 59 const int player_id_; | 73 const int player_id_; |
| 60 const int player_child_id_; | 74 const int player_child_id_; |
| 61 }; | 75 }; |
| 62 | 76 |
| 63 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to | 77 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to |
| 64 // be set. | 78 // be set. |
| 65 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested | 79 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested |
| 66 : public LayerTreeHostAnimationTest { | 80 : public LayerTreeHostAnimationTest { |
| 67 public: | 81 public: |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 bool has_unfinished_animation) override { | 169 bool has_unfinished_animation) override { |
| 156 EXPECT_FALSE(has_unfinished_animation); | 170 EXPECT_FALSE(has_unfinished_animation); |
| 157 update_animation_state_was_called_ = true; | 171 update_animation_state_was_called_ = true; |
| 158 } | 172 } |
| 159 | 173 |
| 160 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 174 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 161 TargetProperty::Type target_property, | 175 TargetProperty::Type target_property, |
| 162 int group) override { | 176 int group) override { |
| 163 EXPECT_LT(base::TimeTicks(), monotonic_time); | 177 EXPECT_LT(base::TimeTicks(), monotonic_time); |
| 164 | 178 |
| 165 Animation* animation = | 179 Animation* animation = player_->GetAnimation(TargetProperty::OPACITY); |
| 166 player_->element_animations()->GetAnimation(TargetProperty::OPACITY); | |
| 167 if (animation) | 180 if (animation) |
| 168 player_->RemoveAnimation(animation->id()); | 181 player_->RemoveAnimation(animation->id()); |
| 169 | 182 |
| 170 EndTest(); | 183 EndTest(); |
| 171 } | 184 } |
| 172 | 185 |
| 173 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } | 186 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } |
| 174 | 187 |
| 175 private: | 188 private: |
| 176 bool update_animation_state_was_called_; | 189 bool update_animation_state_was_called_; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 // Wait for the commit with the animation to happen. | 302 // Wait for the commit with the animation to happen. |
| 290 if (host_impl->sync_tree()->source_frame_number() != 0) | 303 if (host_impl->sync_tree()->source_frame_number() != 0) |
| 291 return; | 304 return; |
| 292 | 305 |
| 293 scoped_refptr<AnimationTimeline> timeline_impl = | 306 scoped_refptr<AnimationTimeline> timeline_impl = |
| 294 host_impl->animation_host()->GetTimelineById(timeline_id_); | 307 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 295 scoped_refptr<AnimationPlayer> player_child_impl = | 308 scoped_refptr<AnimationPlayer> player_child_impl = |
| 296 timeline_impl->GetPlayerById(player_child_id_); | 309 timeline_impl->GetPlayerById(player_child_id_); |
| 297 | 310 |
| 298 Animation* animation = | 311 Animation* animation = |
| 299 player_child_impl->element_animations()->GetAnimation( | 312 player_child_impl->GetAnimation(TargetProperty::OPACITY); |
| 300 TargetProperty::OPACITY); | |
| 301 | 313 |
| 302 const FloatAnimationCurve* curve = | 314 const FloatAnimationCurve* curve = |
| 303 animation->curve()->ToFloatAnimationCurve(); | 315 animation->curve()->ToFloatAnimationCurve(); |
| 304 float start_opacity = curve->GetValue(base::TimeDelta()); | 316 float start_opacity = curve->GetValue(base::TimeDelta()); |
| 305 float end_opacity = curve->GetValue(curve->Duration()); | 317 float end_opacity = curve->GetValue(curve->Duration()); |
| 306 float linearly_interpolated_opacity = | 318 float linearly_interpolated_opacity = |
| 307 0.25f * end_opacity + 0.75f * start_opacity; | 319 0.25f * end_opacity + 0.75f * start_opacity; |
| 308 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); | 320 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); |
| 309 // If the linear timing function associated with this animation was not | 321 // If the linear timing function associated with this animation was not |
| 310 // picked up, then the linearly interpolated opacity would be different | 322 // picked up, then the linearly interpolated opacity would be different |
| (...skipping 30 matching lines...) Expand all Loading... |
| 341 player_child_->AttachElement(picture_->element_id()); | 353 player_child_->AttachElement(picture_->element_id()); |
| 342 } | 354 } |
| 343 | 355 |
| 344 void BeginTest() override { | 356 void BeginTest() override { |
| 345 PostAddAnimationToMainThreadPlayer(player_child_.get()); | 357 PostAddAnimationToMainThreadPlayer(player_child_.get()); |
| 346 } | 358 } |
| 347 | 359 |
| 348 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 360 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 349 TargetProperty::Type target_property, | 361 TargetProperty::Type target_property, |
| 350 int group) override { | 362 int group) override { |
| 351 Animation* animation = player_child_->element_animations()->GetAnimation( | 363 Animation* animation = player_child_->GetAnimation(TargetProperty::OPACITY); |
| 352 TargetProperty::OPACITY); | |
| 353 main_start_time_ = animation->start_time(); | 364 main_start_time_ = animation->start_time(); |
| 354 player_child_->element_animations()->RemoveAnimation(animation->id()); | 365 player_child_->RemoveAnimation(animation->id()); |
| 355 EndTest(); | 366 EndTest(); |
| 356 } | 367 } |
| 357 | 368 |
| 358 void UpdateAnimationState(LayerTreeHostImpl* impl_host, | 369 void UpdateAnimationState(LayerTreeHostImpl* impl_host, |
| 359 bool has_unfinished_animation) override { | 370 bool has_unfinished_animation) override { |
| 360 scoped_refptr<AnimationTimeline> timeline_impl = | 371 scoped_refptr<AnimationTimeline> timeline_impl = |
| 361 impl_host->animation_host()->GetTimelineById(timeline_id_); | 372 impl_host->animation_host()->GetTimelineById(timeline_id_); |
| 362 scoped_refptr<AnimationPlayer> player_child_impl = | 373 scoped_refptr<AnimationPlayer> player_child_impl = |
| 363 timeline_impl->GetPlayerById(player_child_id_); | 374 timeline_impl->GetPlayerById(player_child_id_); |
| 364 | 375 |
| 365 Animation* animation = | 376 Animation* animation = |
| 366 player_child_impl->element_animations()->GetAnimation( | 377 player_child_impl->GetAnimation(TargetProperty::OPACITY); |
| 367 TargetProperty::OPACITY); | |
| 368 if (!animation) | 378 if (!animation) |
| 369 return; | 379 return; |
| 370 | 380 |
| 371 impl_start_time_ = animation->start_time(); | 381 impl_start_time_ = animation->start_time(); |
| 372 } | 382 } |
| 373 | 383 |
| 374 void AfterTest() override { | 384 void AfterTest() override { |
| 375 EXPECT_EQ(impl_start_time_, main_start_time_); | 385 EXPECT_EQ(impl_start_time_, main_start_time_); |
| 376 EXPECT_LT(base::TimeTicks(), impl_start_time_); | 386 EXPECT_LT(base::TimeTicks(), impl_start_time_); |
| 377 } | 387 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 392 public: | 402 public: |
| 393 void BeginTest() override { | 403 void BeginTest() override { |
| 394 AttachPlayersToTimeline(); | 404 AttachPlayersToTimeline(); |
| 395 player_->AttachElement(layer_tree()->root_layer()->element_id()); | 405 player_->AttachElement(layer_tree()->root_layer()->element_id()); |
| 396 PostAddInstantAnimationToMainThreadPlayer(player_.get()); | 406 PostAddInstantAnimationToMainThreadPlayer(player_.get()); |
| 397 } | 407 } |
| 398 | 408 |
| 399 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 409 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
| 400 TargetProperty::Type target_property, | 410 TargetProperty::Type target_property, |
| 401 int group) override { | 411 int group) override { |
| 402 Animation* animation = | 412 Animation* animation = player_->GetAnimation(TargetProperty::OPACITY); |
| 403 player_->element_animations()->GetAnimation(TargetProperty::OPACITY); | |
| 404 if (animation) | 413 if (animation) |
| 405 player_->element_animations()->RemoveAnimation(animation->id()); | 414 player_->RemoveAnimation(animation->id()); |
| 406 EndTest(); | 415 EndTest(); |
| 407 } | 416 } |
| 408 | 417 |
| 409 void AfterTest() override {} | 418 void AfterTest() override {} |
| 410 }; | 419 }; |
| 411 | 420 |
| 412 SINGLE_AND_MULTI_THREAD_TEST_F( | 421 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 413 LayerTreeHostAnimationTestAnimationFinishedEvents); | 422 LayerTreeHostAnimationTestAnimationFinishedEvents); |
| 414 | 423 |
| 415 // Ensures that when opacity is being animated, this value does not cause the | 424 // Ensures that when opacity is being animated, this value does not cause the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 434 void BeginTest() override { | 443 void BeginTest() override { |
| 435 PostAddAnimationToMainThreadPlayer(player_.get()); | 444 PostAddAnimationToMainThreadPlayer(player_.get()); |
| 436 } | 445 } |
| 437 | 446 |
| 438 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 447 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 439 scoped_refptr<AnimationTimeline> timeline_impl = | 448 scoped_refptr<AnimationTimeline> timeline_impl = |
| 440 host_impl->animation_host()->GetTimelineById(timeline_id_); | 449 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 441 scoped_refptr<AnimationPlayer> player_impl = | 450 scoped_refptr<AnimationPlayer> player_impl = |
| 442 timeline_impl->GetPlayerById(player_id_); | 451 timeline_impl->GetPlayerById(player_id_); |
| 443 | 452 |
| 444 Animation* animation_impl = player_impl->element_animations()->GetAnimation( | 453 Animation* animation_impl = |
| 445 TargetProperty::OPACITY); | 454 player_impl->GetAnimation(TargetProperty::OPACITY); |
| 446 player_impl->element_animations()->RemoveAnimation(animation_impl->id()); | 455 player_impl->RemoveAnimation(animation_impl->id()); |
| 447 EndTest(); | 456 EndTest(); |
| 448 } | 457 } |
| 449 | 458 |
| 450 void AfterTest() override { | 459 void AfterTest() override { |
| 451 // Update() should have been called once, proving that the layer was not | 460 // Update() should have been called once, proving that the layer was not |
| 452 // skipped. | 461 // skipped. |
| 453 EXPECT_EQ(1, update_check_layer_->update_count()); | 462 EXPECT_EQ(1, update_check_layer_->update_count()); |
| 454 | 463 |
| 455 // clear update_check_layer_ so LayerTreeHost dies. | 464 // clear update_check_layer_ so LayerTreeHost dies. |
| 456 update_check_layer_ = NULL; | 465 update_check_layer_ = NULL; |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 LayerTreeHostAnimationTest::SetupTree(); | 842 LayerTreeHostAnimationTest::SetupTree(); |
| 834 | 843 |
| 835 scroll_layer_ = FakePictureLayer::Create(&client_); | 844 scroll_layer_ = FakePictureLayer::Create(&client_); |
| 836 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); | 845 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
| 837 client_.set_bounds(scroll_layer_->bounds()); | 846 client_.set_bounds(scroll_layer_->bounds()); |
| 838 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); | 847 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 839 scroll_layer_->SetScrollClipLayerId(layer_tree()->root_layer()->id()); | 848 scroll_layer_->SetScrollClipLayerId(layer_tree()->root_layer()->id()); |
| 840 layer_tree()->root_layer()->AddChild(scroll_layer_); | 849 layer_tree()->root_layer()->AddChild(scroll_layer_); |
| 841 | 850 |
| 842 AttachPlayersToTimeline(); | 851 AttachPlayersToTimeline(); |
| 843 player_child_->AttachElement(scroll_layer_->element_id()); | 852 } |
| 853 |
| 854 AnimationPlayer& ScrollOffsetPlayer( |
| 855 const LayerTreeHostImpl& host_impl, |
| 856 scoped_refptr<FakePictureLayer> layer) const { |
| 857 scoped_refptr<ElementAnimations> element_animations = |
| 858 host_impl.animation_host()->GetElementAnimationsForElementId( |
| 859 layer->element_id()); |
| 860 DCHECK(element_animations); |
| 861 DCHECK(element_animations->players_list().might_have_observers()); |
| 862 |
| 863 ElementAnimations::PlayersList::Iterator it( |
| 864 &element_animations->players_list()); |
| 865 AnimationPlayer* player = it.GetNext(); |
| 866 DCHECK(player); |
| 867 return *player; |
| 844 } | 868 } |
| 845 | 869 |
| 846 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 870 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 847 | 871 |
| 848 void DidCommit() override { | 872 void DidCommit() override { |
| 849 if (layer_tree_host()->SourceFrameNumber() == 1) { | 873 if (layer_tree_host()->SourceFrameNumber() == 1) { |
| 850 // Add an update after the first commit to trigger the animation update | 874 // Add an update after the first commit to trigger the animation update |
| 851 // path. | 875 // path. |
| 852 layer_tree() | 876 layer_tree() |
| 853 ->animation_host() | 877 ->animation_host() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 864 ->animation_host() | 888 ->animation_host() |
| 865 ->scroll_offset_animations() | 889 ->scroll_offset_animations() |
| 866 .HasUpdatesForTesting()); | 890 .HasUpdatesForTesting()); |
| 867 } | 891 } |
| 868 } | 892 } |
| 869 | 893 |
| 870 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 894 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| 871 // Note that the frame number gets incremented after BeginCommitOnThread but | 895 // Note that the frame number gets incremented after BeginCommitOnThread but |
| 872 // before WillCommitCompleteOnThread and CommitCompleteOnThread. | 896 // before WillCommitCompleteOnThread and CommitCompleteOnThread. |
| 873 if (host_impl->sync_tree()->source_frame_number() == 0) { | 897 if (host_impl->sync_tree()->source_frame_number() == 0) { |
| 898 GetImplTimelineAndPlayerByID(*host_impl); |
| 874 // This happens after the impl-only animation is added in | 899 // This happens after the impl-only animation is added in |
| 875 // WillCommitCompleteOnThread. | 900 // WillCommitCompleteOnThread. |
| 876 Animation* animation = | 901 Animation* animation = ScrollOffsetPlayer(*host_impl, scroll_layer_) |
| 877 host_impl->animation_host() | 902 .GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 878 ->GetElementAnimationsForElementId(scroll_layer_->element_id()) | 903 DCHECK(animation); |
| 879 ->GetAnimation(TargetProperty::SCROLL_OFFSET); | |
| 880 ScrollOffsetAnimationCurve* curve = | 904 ScrollOffsetAnimationCurve* curve = |
| 881 animation->curve()->ToScrollOffsetAnimationCurve(); | 905 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 882 | 906 |
| 883 // Verifiy the initial and target position before the scroll offset | 907 // Verifiy the initial and target position before the scroll offset |
| 884 // update from MT. | 908 // update from MT. |
| 885 EXPECT_EQ(Animation::RunState::RUNNING, animation->run_state()); | 909 EXPECT_EQ(Animation::RunState::RUNNING, animation->run_state()); |
| 886 EXPECT_EQ(gfx::ScrollOffset(10.f, 20.f), | 910 EXPECT_EQ(gfx::ScrollOffset(10.f, 20.f), |
| 887 curve->GetValue(base::TimeDelta())); | 911 curve->GetValue(base::TimeDelta())); |
| 888 EXPECT_EQ(gfx::ScrollOffset(650.f, 750.f), curve->target_value()); | 912 EXPECT_EQ(gfx::ScrollOffset(650.f, 750.f), curve->target_value()); |
| 889 } | 913 } |
| 890 } | 914 } |
| 891 | 915 |
| 892 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 916 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 893 if (host_impl->sync_tree()->source_frame_number() == 0) { | 917 if (host_impl->sync_tree()->source_frame_number() == 0) { |
| 894 host_impl->animation_host()->ImplOnlyScrollAnimationCreate( | 918 host_impl->animation_host()->ImplOnlyScrollAnimationCreate( |
| 895 scroll_layer_->element_id(), gfx::ScrollOffset(650.f, 750.f), | 919 scroll_layer_->element_id(), gfx::ScrollOffset(650.f, 750.f), |
| 896 gfx::ScrollOffset(10, 20), base::TimeDelta()); | 920 gfx::ScrollOffset(10, 20), base::TimeDelta()); |
| 897 } | 921 } |
| 898 } | 922 } |
| 899 | 923 |
| 900 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 924 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 901 if (host_impl->sync_tree()->source_frame_number() == 1) { | 925 if (host_impl->sync_tree()->source_frame_number() == 1) { |
| 902 Animation* animation = | 926 Animation* animation = ScrollOffsetPlayer(*host_impl, scroll_layer_) |
| 903 host_impl->animation_host() | 927 .GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 904 ->GetElementAnimationsForElementId(scroll_layer_->element_id()) | 928 DCHECK(animation); |
| 905 ->GetAnimation(TargetProperty::SCROLL_OFFSET); | |
| 906 ScrollOffsetAnimationCurve* curve = | 929 ScrollOffsetAnimationCurve* curve = |
| 907 animation->curve()->ToScrollOffsetAnimationCurve(); | 930 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 908 // Verifiy the initial and target position after the scroll offset | 931 // Verifiy the initial and target position after the scroll offset |
| 909 // update from MT | 932 // update from MT |
| 910 EXPECT_EQ(Animation::RunState::STARTING, animation->run_state()); | 933 EXPECT_EQ(Animation::RunState::STARTING, animation->run_state()); |
| 911 EXPECT_EQ(gfx::ScrollOffset(110.f, 120.f), | 934 EXPECT_EQ(gfx::ScrollOffset(110.f, 120.f), |
| 912 curve->GetValue(base::TimeDelta())); | 935 curve->GetValue(base::TimeDelta())); |
| 913 EXPECT_EQ(gfx::ScrollOffset(750.f, 850.f), curve->target_value()); | 936 EXPECT_EQ(gfx::ScrollOffset(750.f, 850.f), curve->target_value()); |
| 914 | 937 |
| 915 EndTest(); | 938 EndTest(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 } | 983 } |
| 961 | 984 |
| 962 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 985 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 963 | 986 |
| 964 void BeginMainFrame(const BeginFrameArgs& args) override { | 987 void BeginMainFrame(const BeginFrameArgs& args) override { |
| 965 switch (layer_tree_host()->SourceFrameNumber()) { | 988 switch (layer_tree_host()->SourceFrameNumber()) { |
| 966 case 0: | 989 case 0: |
| 967 break; | 990 break; |
| 968 case 1: { | 991 case 1: { |
| 969 Animation* animation = | 992 Animation* animation = |
| 970 player_child_->element_animations() | 993 player_child_->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 971 ->GetAnimation(TargetProperty::SCROLL_OFFSET); | |
| 972 player_child_->RemoveAnimation(animation->id()); | 994 player_child_->RemoveAnimation(animation->id()); |
| 973 scroll_layer_->SetScrollOffset(final_postion_); | 995 scroll_layer_->SetScrollOffset(final_postion_); |
| 974 break; | 996 break; |
| 975 } | 997 } |
| 976 default: | 998 default: |
| 977 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 999 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 978 } | 1000 } |
| 979 } | 1001 } |
| 980 | 1002 |
| 981 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 1003 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 if (!host_impl->active_tree()->root_layer_for_testing()) | 1040 if (!host_impl->active_tree()->root_layer_for_testing()) |
| 1019 return false; | 1041 return false; |
| 1020 | 1042 |
| 1021 scoped_refptr<AnimationTimeline> timeline_impl = | 1043 scoped_refptr<AnimationTimeline> timeline_impl = |
| 1022 host_impl->animation_host()->GetTimelineById(timeline_id_); | 1044 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 1023 scoped_refptr<AnimationPlayer> player_impl = | 1045 scoped_refptr<AnimationPlayer> player_impl = |
| 1024 timeline_impl->GetPlayerById(player_child_id_); | 1046 timeline_impl->GetPlayerById(player_child_id_); |
| 1025 | 1047 |
| 1026 LayerImpl* scroll_layer_impl = | 1048 LayerImpl* scroll_layer_impl = |
| 1027 host_impl->active_tree()->LayerById(scroll_layer_->id()); | 1049 host_impl->active_tree()->LayerById(scroll_layer_->id()); |
| 1028 Animation* animation = player_impl->element_animations()->GetAnimation( | 1050 Animation* animation = |
| 1029 TargetProperty::SCROLL_OFFSET); | 1051 player_impl->GetAnimation(TargetProperty::SCROLL_OFFSET); |
| 1030 | 1052 |
| 1031 if (!animation || animation->run_state() != Animation::RUNNING) | 1053 if (!animation || animation->run_state() != Animation::RUNNING) |
| 1032 return false; | 1054 return false; |
| 1033 | 1055 |
| 1034 // Block activation until the running animation has a chance to produce a | 1056 // Block activation until the running animation has a chance to produce a |
| 1035 // scroll delta. | 1057 // scroll delta. |
| 1036 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); | 1058 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); |
| 1037 if (scroll_delta.x() > 0.f || scroll_delta.y() > 0.f) | 1059 if (scroll_delta.x() > 0.f || scroll_delta.y() > 0.f) |
| 1038 return false; | 1060 return false; |
| 1039 | 1061 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 host_impl->animation_host()->GetTimelineById(timeline_id_); | 1134 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 1113 scoped_refptr<AnimationPlayer> player_impl = | 1135 scoped_refptr<AnimationPlayer> player_impl = |
| 1114 timeline_impl->GetPlayerById(player_id_); | 1136 timeline_impl->GetPlayerById(player_id_); |
| 1115 scoped_refptr<AnimationPlayer> player_child_impl = | 1137 scoped_refptr<AnimationPlayer> player_child_impl = |
| 1116 timeline_impl->GetPlayerById(player_child_id_); | 1138 timeline_impl->GetPlayerById(player_child_id_); |
| 1117 | 1139 |
| 1118 // wait for tree activation. | 1140 // wait for tree activation. |
| 1119 if (!player_impl->element_animations()) | 1141 if (!player_impl->element_animations()) |
| 1120 return; | 1142 return; |
| 1121 | 1143 |
| 1122 Animation* root_animation = player_impl->element_animations()->GetAnimation( | 1144 Animation* root_animation = |
| 1123 TargetProperty::OPACITY); | 1145 player_impl->GetAnimation(TargetProperty::OPACITY); |
| 1124 if (!root_animation || root_animation->run_state() != Animation::RUNNING) | 1146 if (!root_animation || root_animation->run_state() != Animation::RUNNING) |
| 1125 return; | 1147 return; |
| 1126 | 1148 |
| 1127 Animation* child_animation = | 1149 Animation* child_animation = |
| 1128 player_child_impl->element_animations()->GetAnimation( | 1150 player_child_impl->GetAnimation(TargetProperty::OPACITY); |
| 1129 TargetProperty::OPACITY); | |
| 1130 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); | 1151 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); |
| 1131 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); | 1152 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); |
| 1132 player_impl->element_animations()->AbortAnimations(TargetProperty::OPACITY); | 1153 player_impl->AbortAnimations(TargetProperty::OPACITY, false); |
| 1133 player_impl->element_animations()->AbortAnimations( | 1154 player_impl->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 1134 TargetProperty::TRANSFORM); | 1155 player_child_impl->AbortAnimations(TargetProperty::OPACITY, false); |
| 1135 player_child_impl->element_animations()->AbortAnimations( | |
| 1136 TargetProperty::OPACITY); | |
| 1137 EndTest(); | 1156 EndTest(); |
| 1138 } | 1157 } |
| 1139 | 1158 |
| 1140 void AfterTest() override {} | 1159 void AfterTest() override {} |
| 1141 | 1160 |
| 1142 private: | 1161 private: |
| 1143 int frame_count_with_pending_tree_; | 1162 int frame_count_with_pending_tree_; |
| 1144 }; | 1163 }; |
| 1145 | 1164 |
| 1146 // This test blocks activation which is not supported for single thread mode. | 1165 // This test blocks activation which is not supported for single thread mode. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 // PrepareTiles to happen again (which races with the test exiting). | 1207 // PrepareTiles to happen again (which races with the test exiting). |
| 1189 if (TestEnded()) | 1208 if (TestEnded()) |
| 1190 return; | 1209 return; |
| 1191 | 1210 |
| 1192 scoped_refptr<AnimationTimeline> timeline_impl = | 1211 scoped_refptr<AnimationTimeline> timeline_impl = |
| 1193 host_impl->animation_host()->GetTimelineById(timeline_id_); | 1212 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 1194 scoped_refptr<AnimationPlayer> player_impl = | 1213 scoped_refptr<AnimationPlayer> player_impl = |
| 1195 timeline_impl->GetPlayerById(player_id_); | 1214 timeline_impl->GetPlayerById(player_id_); |
| 1196 | 1215 |
| 1197 LayerImpl* child = host_impl->sync_tree()->LayerById(layer_->id()); | 1216 LayerImpl* child = host_impl->sync_tree()->LayerById(layer_->id()); |
| 1198 Animation* animation = player_impl->element_animations()->GetAnimation( | 1217 Animation* animation = player_impl->GetAnimation(TargetProperty::TRANSFORM); |
| 1199 TargetProperty::TRANSFORM); | |
| 1200 | 1218 |
| 1201 // The animation should be starting for the first frame. | 1219 // The animation should be starting for the first frame. |
| 1202 EXPECT_EQ(Animation::STARTING, animation->run_state()); | 1220 EXPECT_EQ(Animation::STARTING, animation->run_state()); |
| 1203 | 1221 |
| 1204 // And the transform should be propogated to the sync tree layer, at its | 1222 // And the transform should be propogated to the sync tree layer, at its |
| 1205 // starting state which is 6,7. | 1223 // starting state which is 6,7. |
| 1206 gfx::Transform expected_transform; | 1224 gfx::Transform expected_transform; |
| 1207 expected_transform.Translate(6.0, 7.0); | 1225 expected_transform.Translate(6.0, 7.0); |
| 1208 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, child->DrawTransform()); | 1226 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, child->DrawTransform()); |
| 1209 // And the sync tree layer should know it is animating. | 1227 // And the sync tree layer should know it is animating. |
| 1210 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1228 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
| 1211 | 1229 |
| 1212 player_impl->element_animations()->AbortAnimations( | 1230 player_impl->AbortAnimations(TargetProperty::TRANSFORM, false); |
| 1213 TargetProperty::TRANSFORM); | |
| 1214 EndTest(); | 1231 EndTest(); |
| 1215 } | 1232 } |
| 1216 | 1233 |
| 1217 void AfterTest() override {} | 1234 void AfterTest() override {} |
| 1218 | 1235 |
| 1219 FakeContentLayerClient client_; | 1236 FakeContentLayerClient client_; |
| 1220 scoped_refptr<Layer> layer_; | 1237 scoped_refptr<Layer> layer_; |
| 1221 }; | 1238 }; |
| 1222 | 1239 |
| 1223 SINGLE_AND_MULTI_THREAD_TEST_F( | 1240 SINGLE_AND_MULTI_THREAD_TEST_F( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 if (!TestEnded()) { | 1367 if (!TestEnded()) { |
| 1351 ImplThreadTaskRunner()->PostTask( | 1368 ImplThreadTaskRunner()->PostTask( |
| 1352 FROM_HERE, | 1369 FROM_HERE, |
| 1353 base::Bind(&LayerTreeHostAnimationTestAddAnimationAfterAnimating:: | 1370 base::Bind(&LayerTreeHostAnimationTestAddAnimationAfterAnimating:: |
| 1354 CheckAnimations, | 1371 CheckAnimations, |
| 1355 base::Unretained(this), host_impl)); | 1372 base::Unretained(this), host_impl)); |
| 1356 } | 1373 } |
| 1357 } | 1374 } |
| 1358 | 1375 |
| 1359 void CheckAnimations(LayerTreeHostImpl* host_impl) { | 1376 void CheckAnimations(LayerTreeHostImpl* host_impl) { |
| 1360 AnimationHost::ElementToAnimationsMap element_animations_copy = | 1377 GetImplTimelineAndPlayerByID(*host_impl); |
| 1361 host_impl->animation_host()->active_element_animations_for_testing(); | 1378 |
| 1362 EXPECT_EQ(2u, element_animations_copy.size()); | 1379 EXPECT_EQ(2u, host_impl->animation_host() |
| 1363 for (auto& it : element_animations_copy) { | 1380 ->active_element_animations_for_testing() |
| 1364 ElementId id = it.first; | 1381 .size()); |
| 1365 if (id == | 1382 |
| 1366 host_impl->active_tree()->root_layer_for_testing()->element_id()) { | 1383 Animation* root_anim = |
| 1367 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); | 1384 player_impl_->GetAnimation(TargetProperty::TRANSFORM); |
| 1368 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1385 EXPECT_GT((root_anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1369 } else if (id == layer_->element_id()) { | 1386 |
| 1370 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); | 1387 Animation* anim = player_child_impl_->GetAnimation(TargetProperty::OPACITY); |
| 1371 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1388 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1372 } | 1389 |
| 1373 EndTest(); | 1390 EndTest(); |
| 1374 } | |
| 1375 } | 1391 } |
| 1376 | 1392 |
| 1377 void AfterTest() override {} | 1393 void AfterTest() override {} |
| 1378 | 1394 |
| 1379 private: | 1395 private: |
| 1380 scoped_refptr<Layer> layer_; | 1396 scoped_refptr<Layer> layer_; |
| 1381 }; | 1397 }; |
| 1382 | 1398 |
| 1383 SINGLE_AND_MULTI_THREAD_TEST_F( | 1399 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1384 LayerTreeHostAnimationTestAddAnimationAfterAnimating); | 1400 LayerTreeHostAnimationTestAddAnimationAfterAnimating); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1401 | 1417 |
| 1402 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1418 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1403 | 1419 |
| 1404 void DidCommit() override { | 1420 void DidCommit() override { |
| 1405 switch (layer_tree_host()->SourceFrameNumber()) { | 1421 switch (layer_tree_host()->SourceFrameNumber()) { |
| 1406 case 1: | 1422 case 1: |
| 1407 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); | 1423 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 5, 5); |
| 1408 break; | 1424 break; |
| 1409 case 2: | 1425 case 2: |
| 1410 Animation* animation = | 1426 Animation* animation = |
| 1411 player_child_->element_animations()->GetAnimation( | 1427 player_child_->GetAnimation(TargetProperty::TRANSFORM); |
| 1412 TargetProperty::TRANSFORM); | |
| 1413 player_child_->RemoveAnimation(animation->id()); | 1428 player_child_->RemoveAnimation(animation->id()); |
| 1414 gfx::Transform transform; | 1429 gfx::Transform transform; |
| 1415 transform.Translate(10.f, 10.f); | 1430 transform.Translate(10.f, 10.f); |
| 1416 layer_->SetTransform(transform); | 1431 layer_->SetTransform(transform); |
| 1417 | 1432 |
| 1418 // Do something that causes property trees to get rebuilt. This is | 1433 // Do something that causes property trees to get rebuilt. This is |
| 1419 // intended to simulate the conditions that caused the bug whose fix | 1434 // intended to simulate the conditions that caused the bug whose fix |
| 1420 // this is testing (the test will pass without it but won't test what | 1435 // this is testing (the test will pass without it but won't test what |
| 1421 // we want it to). We were updating the wrong transform node at the end | 1436 // we want it to). We were updating the wrong transform node at the end |
| 1422 // of an animation (we were assuming the layer with the finished | 1437 // of an animation (we were assuming the layer with the finished |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 } | 1494 } |
| 1480 | 1495 |
| 1481 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1496 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1482 | 1497 |
| 1483 void DidCommit() override { | 1498 void DidCommit() override { |
| 1484 switch (layer_tree_host()->SourceFrameNumber()) { | 1499 switch (layer_tree_host()->SourceFrameNumber()) { |
| 1485 case 1: | 1500 case 1: |
| 1486 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); | 1501 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); |
| 1487 break; | 1502 break; |
| 1488 case 2: | 1503 case 2: |
| 1489 Animation* animation = player_->element_animations()->GetAnimation( | 1504 Animation* animation = player_->GetAnimation(TargetProperty::TRANSFORM); |
| 1490 TargetProperty::TRANSFORM); | |
| 1491 player_->RemoveAnimation(animation->id()); | 1505 player_->RemoveAnimation(animation->id()); |
| 1492 break; | 1506 break; |
| 1493 } | 1507 } |
| 1494 } | 1508 } |
| 1495 | 1509 |
| 1496 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1510 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 1497 LayerImpl* child = host_impl->sync_tree()->LayerById(layer_->id()); | 1511 LayerImpl* child = host_impl->sync_tree()->LayerById(layer_->id()); |
| 1498 switch (host_impl->sync_tree()->source_frame_number()) { | 1512 switch (host_impl->sync_tree()->source_frame_number()) { |
| 1499 case 0: | 1513 case 0: |
| 1500 // No animation yet. | 1514 // No animation yet. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 void DidCommit() override { PostSetNeedsCommitToMainThread(); } | 1726 void DidCommit() override { PostSetNeedsCommitToMainThread(); } |
| 1713 | 1727 |
| 1714 void WillBeginMainFrame() override { | 1728 void WillBeginMainFrame() override { |
| 1715 if (layer_tree_host()->SourceFrameNumber() == 2) { | 1729 if (layer_tree_host()->SourceFrameNumber() == 2) { |
| 1716 // Destroy player. | 1730 // Destroy player. |
| 1717 timeline_->DetachPlayer(player_.get()); | 1731 timeline_->DetachPlayer(player_.get()); |
| 1718 player_ = nullptr; | 1732 player_ = nullptr; |
| 1719 timeline_->AttachPlayer(player_child_.get()); | 1733 timeline_->AttachPlayer(player_child_.get()); |
| 1720 player_child_->AttachElement(layer_tree()->root_layer()->element_id()); | 1734 player_child_->AttachElement(layer_tree()->root_layer()->element_id()); |
| 1721 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 10, 10); | 1735 AddAnimatedTransformToPlayer(player_child_.get(), 1.0, 10, 10); |
| 1722 Animation* animation = player_child_->element_animations()->GetAnimation( | 1736 Animation* animation = |
| 1723 TargetProperty::TRANSFORM); | 1737 player_child_->GetAnimation(TargetProperty::TRANSFORM); |
| 1724 animation->set_start_time(base::TimeTicks::Now() + | 1738 animation->set_start_time(base::TimeTicks::Now() + |
| 1725 base::TimeDelta::FromSecondsD(1000)); | 1739 base::TimeDelta::FromSecondsD(1000)); |
| 1726 animation->set_fill_mode(Animation::FillMode::NONE); | 1740 animation->set_fill_mode(Animation::FillMode::NONE); |
| 1727 } | 1741 } |
| 1728 } | 1742 } |
| 1729 | 1743 |
| 1730 void AfterTest() override {} | 1744 void AfterTest() override {} |
| 1731 }; | 1745 }; |
| 1732 | 1746 |
| 1733 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestChangeAnimationPlayer); | 1747 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestChangeAnimationPlayer); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 private: | 1872 private: |
| 1859 scoped_refptr<Layer> layer_; | 1873 scoped_refptr<Layer> layer_; |
| 1860 FakeContentLayerClient client_; | 1874 FakeContentLayerClient client_; |
| 1861 }; | 1875 }; |
| 1862 | 1876 |
| 1863 MULTI_THREAD_TEST_F( | 1877 MULTI_THREAD_TEST_F( |
| 1864 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | 1878 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| 1865 | 1879 |
| 1866 } // namespace | 1880 } // namespace |
| 1867 } // namespace cc | 1881 } // namespace cc |
| OLD | NEW |