| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/animation/element_animations.h" | 5 #include "cc/animation/element_animations.h" |
| 6 | 6 |
| 7 #include "cc/animation/animation_delegate.h" | 7 #include "cc/animation/animation_delegate.h" |
| 8 #include "cc/animation/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
| 9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
| 10 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); | 691 const AnimationEvent* event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 692 EXPECT_FALSE(event); | 692 EXPECT_FALSE(event); |
| 693 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 693 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 694 animations->UpdateState(true, events.get()); | 694 animations->UpdateState(true, events.get()); |
| 695 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); | 695 EXPECT_EQ(1.f, client_.GetOpacity(element_id_, ElementListType::ACTIVE)); |
| 696 EXPECT_FALSE(animations->HasActiveAnimation()); | 696 EXPECT_FALSE(animations->HasActiveAnimation()); |
| 697 event = GetMostRecentPropertyUpdateEvent(events.get()); | 697 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 698 EXPECT_FALSE(event); | 698 EXPECT_FALSE(event); |
| 699 } | 699 } |
| 700 | 700 |
| 701 TEST_F(ElementAnimationsTest, TrivialTransitionOnImpl) { | |
| 702 CreateTestLayer(true, false); | |
| 703 AttachTimelinePlayerLayer(); | |
| 704 CreateImplTimelineAndPlayer(); | |
| 705 | |
| 706 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
| 707 | |
| 708 auto events = host_impl_->CreateEvents(); | |
| 709 | |
| 710 std::unique_ptr<Animation> to_add(CreateAnimation( | |
| 711 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | |
| 712 1, TargetProperty::OPACITY)); | |
| 713 to_add->set_is_impl_only(true); | |
| 714 | |
| 715 animations_impl->AddAnimation(std::move(to_add)); | |
| 716 animations_impl->Animate(kInitialTickTime); | |
| 717 animations_impl->UpdateState(true, events.get()); | |
| 718 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | |
| 719 EXPECT_EQ(0.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | |
| 720 EXPECT_EQ(1u, events->events_.size()); | |
| 721 const AnimationEvent* start_opacity_event = | |
| 722 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 723 EXPECT_EQ(0.f, start_opacity_event->opacity); | |
| 724 | |
| 725 animations_impl->Animate(kInitialTickTime + | |
| 726 TimeDelta::FromMilliseconds(1000)); | |
| 727 animations_impl->UpdateState(true, events.get()); | |
| 728 EXPECT_EQ(1.f, client_impl_.GetOpacity(element_id_, ElementListType::ACTIVE)); | |
| 729 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | |
| 730 EXPECT_EQ(2u, events->events_.size()); | |
| 731 const AnimationEvent* end_opacity_event = | |
| 732 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 733 EXPECT_EQ(1.f, end_opacity_event->opacity); | |
| 734 } | |
| 735 | |
| 736 TEST_F(ElementAnimationsTest, TrivialTransformOnImpl) { | |
| 737 CreateTestLayer(true, false); | |
| 738 AttachTimelinePlayerLayer(); | |
| 739 CreateImplTimelineAndPlayer(); | |
| 740 | |
| 741 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
| 742 | |
| 743 auto events = host_impl_->CreateEvents(); | |
| 744 | |
| 745 // Choose different values for x and y to avoid coincidental values in the | |
| 746 // observed transforms. | |
| 747 const float delta_x = 3; | |
| 748 const float delta_y = 4; | |
| 749 | |
| 750 std::unique_ptr<KeyframedTransformAnimationCurve> curve( | |
| 751 KeyframedTransformAnimationCurve::Create()); | |
| 752 | |
| 753 // Create simple TRANSFORM animation. | |
| 754 TransformOperations operations; | |
| 755 curve->AddKeyframe( | |
| 756 TransformKeyframe::Create(base::TimeDelta(), operations, nullptr)); | |
| 757 operations.AppendTranslate(delta_x, delta_y, 0); | |
| 758 curve->AddKeyframe(TransformKeyframe::Create( | |
| 759 base::TimeDelta::FromSecondsD(1.0), operations, nullptr)); | |
| 760 | |
| 761 std::unique_ptr<Animation> animation( | |
| 762 Animation::Create(std::move(curve), 1, 0, TargetProperty::TRANSFORM)); | |
| 763 animation->set_is_impl_only(true); | |
| 764 animations_impl->AddAnimation(std::move(animation)); | |
| 765 | |
| 766 // Run animation. | |
| 767 animations_impl->Animate(kInitialTickTime); | |
| 768 animations_impl->UpdateState(true, events.get()); | |
| 769 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | |
| 770 EXPECT_EQ(gfx::Transform(), | |
| 771 client_impl_.GetTransform(element_id_, ElementListType::ACTIVE)); | |
| 772 EXPECT_EQ(1u, events->events_.size()); | |
| 773 const AnimationEvent* start_transform_event = | |
| 774 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 775 ASSERT_TRUE(start_transform_event); | |
| 776 EXPECT_EQ(gfx::Transform(), start_transform_event->transform); | |
| 777 EXPECT_TRUE(start_transform_event->is_impl_only); | |
| 778 | |
| 779 gfx::Transform expected_transform; | |
| 780 expected_transform.Translate(delta_x, delta_y); | |
| 781 | |
| 782 animations_impl->Animate(kInitialTickTime + | |
| 783 TimeDelta::FromMilliseconds(1000)); | |
| 784 animations_impl->UpdateState(true, events.get()); | |
| 785 EXPECT_EQ(expected_transform, | |
| 786 client_impl_.GetTransform(element_id_, ElementListType::ACTIVE)); | |
| 787 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | |
| 788 EXPECT_EQ(2u, events->events_.size()); | |
| 789 const AnimationEvent* end_transform_event = | |
| 790 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 791 EXPECT_EQ(expected_transform, end_transform_event->transform); | |
| 792 EXPECT_TRUE(end_transform_event->is_impl_only); | |
| 793 } | |
| 794 | |
| 795 TEST_F(ElementAnimationsTest, FilterTransition) { | 701 TEST_F(ElementAnimationsTest, FilterTransition) { |
| 796 CreateTestLayer(true, false); | 702 CreateTestLayer(true, false); |
| 797 AttachTimelinePlayerLayer(); | 703 AttachTimelinePlayerLayer(); |
| 798 | 704 |
| 799 scoped_refptr<ElementAnimations> animations = element_animations(); | 705 scoped_refptr<ElementAnimations> animations = element_animations(); |
| 800 | 706 |
| 801 auto events = host_impl_->CreateEvents(); | 707 auto events = host_impl_->CreateEvents(); |
| 802 | 708 |
| 803 std::unique_ptr<KeyframedFilterAnimationCurve> curve( | 709 std::unique_ptr<KeyframedFilterAnimationCurve> curve( |
| 804 KeyframedFilterAnimationCurve::Create()); | 710 KeyframedFilterAnimationCurve::Create()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 | 742 |
| 837 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); | 743 animations->Animate(kInitialTickTime + TimeDelta::FromMilliseconds(1000)); |
| 838 animations->UpdateState(true, events.get()); | 744 animations->UpdateState(true, events.get()); |
| 839 EXPECT_EQ(end_filters, | 745 EXPECT_EQ(end_filters, |
| 840 client_.GetFilters(element_id_, ElementListType::ACTIVE)); | 746 client_.GetFilters(element_id_, ElementListType::ACTIVE)); |
| 841 EXPECT_FALSE(animations->HasActiveAnimation()); | 747 EXPECT_FALSE(animations->HasActiveAnimation()); |
| 842 event = GetMostRecentPropertyUpdateEvent(events.get()); | 748 event = GetMostRecentPropertyUpdateEvent(events.get()); |
| 843 EXPECT_FALSE(event); | 749 EXPECT_FALSE(event); |
| 844 } | 750 } |
| 845 | 751 |
| 846 TEST_F(ElementAnimationsTest, FilterTransitionOnImplOnly) { | |
| 847 CreateTestLayer(true, false); | |
| 848 AttachTimelinePlayerLayer(); | |
| 849 CreateImplTimelineAndPlayer(); | |
| 850 | |
| 851 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | |
| 852 | |
| 853 auto events = host_impl_->CreateEvents(); | |
| 854 | |
| 855 std::unique_ptr<KeyframedFilterAnimationCurve> curve( | |
| 856 KeyframedFilterAnimationCurve::Create()); | |
| 857 | |
| 858 // Create simple FILTER animation. | |
| 859 FilterOperations start_filters; | |
| 860 start_filters.Append(FilterOperation::CreateBrightnessFilter(1.f)); | |
| 861 curve->AddKeyframe( | |
| 862 FilterKeyframe::Create(base::TimeDelta(), start_filters, nullptr)); | |
| 863 FilterOperations end_filters; | |
| 864 end_filters.Append(FilterOperation::CreateBrightnessFilter(2.f)); | |
| 865 curve->AddKeyframe(FilterKeyframe::Create(base::TimeDelta::FromSecondsD(1.0), | |
| 866 end_filters, nullptr)); | |
| 867 | |
| 868 std::unique_ptr<Animation> animation( | |
| 869 Animation::Create(std::move(curve), 1, 0, TargetProperty::FILTER)); | |
| 870 animation->set_is_impl_only(true); | |
| 871 animations_impl->AddAnimation(std::move(animation)); | |
| 872 | |
| 873 // Run animation. | |
| 874 animations_impl->Animate(kInitialTickTime); | |
| 875 animations_impl->UpdateState(true, events.get()); | |
| 876 EXPECT_TRUE(animations_impl->HasActiveAnimation()); | |
| 877 EXPECT_EQ(start_filters, | |
| 878 client_impl_.GetFilters(element_id_, ElementListType::ACTIVE)); | |
| 879 EXPECT_EQ(1u, events->events_.size()); | |
| 880 const AnimationEvent* start_filter_event = | |
| 881 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 882 EXPECT_TRUE(start_filter_event); | |
| 883 EXPECT_EQ(start_filters, start_filter_event->filters); | |
| 884 EXPECT_TRUE(start_filter_event->is_impl_only); | |
| 885 | |
| 886 animations_impl->Animate(kInitialTickTime + | |
| 887 TimeDelta::FromMilliseconds(1000)); | |
| 888 animations_impl->UpdateState(true, events.get()); | |
| 889 EXPECT_EQ(end_filters, | |
| 890 client_impl_.GetFilters(element_id_, ElementListType::ACTIVE)); | |
| 891 EXPECT_FALSE(animations_impl->HasActiveAnimation()); | |
| 892 EXPECT_EQ(2u, events->events_.size()); | |
| 893 const AnimationEvent* end_filter_event = | |
| 894 GetMostRecentPropertyUpdateEvent(events.get()); | |
| 895 EXPECT_TRUE(end_filter_event); | |
| 896 EXPECT_EQ(end_filters, end_filter_event->filters); | |
| 897 EXPECT_TRUE(end_filter_event->is_impl_only); | |
| 898 } | |
| 899 | |
| 900 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { | 752 TEST_F(ElementAnimationsTest, ScrollOffsetTransition) { |
| 901 CreateTestLayer(true, false); | 753 CreateTestLayer(true, false); |
| 902 AttachTimelinePlayerLayer(); | 754 AttachTimelinePlayerLayer(); |
| 903 CreateImplTimelineAndPlayer(); | 755 CreateImplTimelineAndPlayer(); |
| 904 | 756 |
| 905 scoped_refptr<ElementAnimations> animations = element_animations(); | 757 scoped_refptr<ElementAnimations> animations = element_animations(); |
| 906 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 758 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
| 907 | 759 |
| 908 auto events = host_impl_->CreateEvents(); | 760 auto events = host_impl_->CreateEvents(); |
| 909 | 761 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1226 CreateImplTimelineAndPlayer(); | 1078 CreateImplTimelineAndPlayer(); |
| 1227 | 1079 |
| 1228 scoped_refptr<ElementAnimations> animations = element_animations(); | 1080 scoped_refptr<ElementAnimations> animations = element_animations(); |
| 1229 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); | 1081 scoped_refptr<ElementAnimations> animations_impl = element_animations_impl(); |
| 1230 | 1082 |
| 1231 auto events = host_impl_->CreateEvents(); | 1083 auto events = host_impl_->CreateEvents(); |
| 1232 | 1084 |
| 1233 TestAnimationDelegate delegate; | 1085 TestAnimationDelegate delegate; |
| 1234 player_impl_->set_animation_delegate(&delegate); | 1086 player_impl_->set_animation_delegate(&delegate); |
| 1235 | 1087 |
| 1236 std::unique_ptr<Animation> to_add(CreateAnimation( | 1088 gfx::ScrollOffset initial_value(100.f, 300.f); |
| 1237 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), | 1089 gfx::ScrollOffset target_value(300.f, 200.f); |
| 1238 1, TargetProperty::OPACITY)); | 1090 std::unique_ptr<ScrollOffsetAnimationCurve> curve( |
| 1091 ScrollOffsetAnimationCurve::Create(target_value, |
| 1092 EaseInOutTimingFunction::Create())); |
| 1093 curve->SetInitialValue(initial_value); |
| 1094 TimeDelta duration = curve->Duration(); |
| 1095 std::unique_ptr<Animation> to_add( |
| 1096 Animation::Create(std::move(curve), 1, 0, TargetProperty::SCROLL_OFFSET)); |
| 1239 to_add->set_is_impl_only(true); | 1097 to_add->set_is_impl_only(true); |
| 1240 animations_impl->AddAnimation(std::move(to_add)); | 1098 animations_impl->AddAnimation(std::move(to_add)); |
| 1241 | 1099 |
| 1242 EXPECT_FALSE(delegate.started()); | 1100 EXPECT_FALSE(delegate.started()); |
| 1243 EXPECT_FALSE(delegate.finished()); | 1101 EXPECT_FALSE(delegate.finished()); |
| 1244 | 1102 |
| 1245 animations_impl->Animate(kInitialTickTime); | 1103 animations_impl->Animate(kInitialTickTime); |
| 1246 animations_impl->UpdateState(true, events.get()); | 1104 animations_impl->UpdateState(true, events.get()); |
| 1247 | 1105 |
| 1248 EXPECT_TRUE(delegate.started()); | 1106 EXPECT_TRUE(delegate.started()); |
| 1249 EXPECT_FALSE(delegate.finished()); | 1107 EXPECT_FALSE(delegate.finished()); |
| 1250 | 1108 |
| 1251 events = host_impl_->CreateEvents(); | 1109 events = host_impl_->CreateEvents(); |
| 1252 animations_impl->Animate(kInitialTickTime + | 1110 animations_impl->Animate(kInitialTickTime + duration); |
| 1253 TimeDelta::FromMilliseconds(1000)); | 1111 EXPECT_EQ(duration, |
| 1112 animations_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) |
| 1113 ->curve() |
| 1114 ->Duration()); |
| 1254 animations_impl->UpdateState(true, events.get()); | 1115 animations_impl->UpdateState(true, events.get()); |
| 1255 | 1116 |
| 1256 EXPECT_TRUE(delegate.started()); | 1117 EXPECT_TRUE(delegate.started()); |
| 1257 EXPECT_TRUE(delegate.finished()); | 1118 EXPECT_TRUE(delegate.finished()); |
| 1258 } | 1119 } |
| 1259 | 1120 |
| 1260 // Tests that specified start times are sent to the main thread delegate | 1121 // Tests that specified start times are sent to the main thread delegate |
| 1261 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) { | 1122 TEST_F(ElementAnimationsTest, SpecifiedStartTimesAreSentToMainThreadDelegate) { |
| 1262 CreateTestLayer(true, false); | 1123 CreateTestLayer(true, false); |
| 1263 AttachTimelinePlayerLayer(); | 1124 AttachTimelinePlayerLayer(); |
| (...skipping 2264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3528 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( | 3389 EXPECT_FALSE(animations->IsPotentiallyAnimatingProperty( |
| 3529 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3390 TargetProperty::OPACITY, ElementListType::ACTIVE)); |
| 3530 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3391 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( |
| 3531 TargetProperty::OPACITY, ElementListType::PENDING)); | 3392 TargetProperty::OPACITY, ElementListType::PENDING)); |
| 3532 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( | 3393 EXPECT_FALSE(animations->IsCurrentlyAnimatingProperty( |
| 3533 TargetProperty::OPACITY, ElementListType::ACTIVE)); | 3394 TargetProperty::OPACITY, ElementListType::ACTIVE)); |
| 3534 } | 3395 } |
| 3535 | 3396 |
| 3536 } // namespace | 3397 } // namespace |
| 3537 } // namespace cc | 3398 } // namespace cc |
| OLD | NEW |