Chromium Code Reviews| 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/animation/layer_animation_controller.h" | 5 #include "cc/animation/layer_animation_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "cc/animation/animation.h" | 9 #include "cc/animation/animation.h" |
| 10 #include "cc/animation/animation_curve.h" | 10 #include "cc/animation/animation_curve.h" |
| (...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 controller_impl->ActivateAnimations(); | 1018 controller_impl->ActivateAnimations(); |
| 1019 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); | 1019 EXPECT_FALSE(controller_impl->scroll_offset_animation_was_interrupted()); |
| 1020 } | 1020 } |
| 1021 | 1021 |
| 1022 class FakeAnimationDelegate : public AnimationDelegate { | 1022 class FakeAnimationDelegate : public AnimationDelegate { |
| 1023 public: | 1023 public: |
| 1024 FakeAnimationDelegate() | 1024 FakeAnimationDelegate() |
| 1025 : started_(false), | 1025 : started_(false), |
| 1026 finished_(false), | 1026 finished_(false), |
| 1027 aborted_(false), | 1027 aborted_(false), |
| 1028 start_time_(base::TimeTicks()) {} | 1028 start_time_(base::TimeTicks()) {} |
|
ajuma
2016/02/26 23:56:54
Initialize takeover_ here.
ymalik
2016/02/29 16:31:09
Done.
| |
| 1029 | 1029 |
| 1030 void NotifyAnimationStarted(TimeTicks monotonic_time, | 1030 void NotifyAnimationStarted(TimeTicks monotonic_time, |
| 1031 TargetProperty::Type target_property, | 1031 TargetProperty::Type target_property, |
| 1032 int group) override { | 1032 int group) override { |
| 1033 started_ = true; | 1033 started_ = true; |
| 1034 start_time_ = monotonic_time; | 1034 start_time_ = monotonic_time; |
| 1035 } | 1035 } |
| 1036 | 1036 |
| 1037 void NotifyAnimationFinished(TimeTicks monotonic_time, | 1037 void NotifyAnimationFinished(TimeTicks monotonic_time, |
| 1038 TargetProperty::Type target_property, | 1038 TargetProperty::Type target_property, |
| 1039 int group) override { | 1039 int group) override { |
| 1040 finished_ = true; | 1040 finished_ = true; |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 void NotifyAnimationAborted(TimeTicks monotonic_time, | 1043 void NotifyAnimationAborted(TimeTicks monotonic_time, |
| 1044 TargetProperty::Type target_property, | 1044 TargetProperty::Type target_property, |
| 1045 int group) override { | 1045 int group) override { |
| 1046 aborted_ = true; | 1046 aborted_ = true; |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 void NotifyAnimationTakeover(base::TimeTicks monotonic_time, | |
| 1050 double animation_start_time, | |
| 1051 scoped_ptr<AnimationCurve> curve) override { | |
| 1052 takeover_ = true; | |
| 1053 } | |
| 1054 | |
| 1049 bool started() { return started_; } | 1055 bool started() { return started_; } |
| 1050 | 1056 |
| 1051 bool finished() { return finished_; } | 1057 bool finished() { return finished_; } |
| 1052 | 1058 |
| 1053 bool aborted() { return aborted_; } | 1059 bool aborted() { return aborted_; } |
| 1054 | 1060 |
| 1061 bool takeover() { return takeover_; } | |
| 1062 | |
| 1055 TimeTicks start_time() { return start_time_; } | 1063 TimeTicks start_time() { return start_time_; } |
| 1056 | 1064 |
| 1057 private: | 1065 private: |
| 1058 bool started_; | 1066 bool started_; |
| 1059 bool finished_; | 1067 bool finished_; |
| 1060 bool aborted_; | 1068 bool aborted_; |
| 1069 bool takeover_; | |
| 1061 TimeTicks start_time_; | 1070 TimeTicks start_time_; |
| 1062 }; | 1071 }; |
| 1063 | 1072 |
| 1064 // Tests that impl-only animations lead to start and finished notifications | 1073 // Tests that impl-only animations lead to start and finished notifications |
| 1065 // on the impl thread controller's animation delegate. | 1074 // on the impl thread controller's animation delegate. |
| 1066 TEST(LayerAnimationControllerTest, | 1075 TEST(LayerAnimationControllerTest, |
| 1067 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { | 1076 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { |
| 1068 FakeLayerAnimationValueObserver dummy_impl; | 1077 FakeLayerAnimationValueObserver dummy_impl; |
| 1069 scoped_refptr<LayerAnimationController> controller_impl( | 1078 scoped_refptr<LayerAnimationController> controller_impl( |
| 1070 LayerAnimationController::Create(0)); | 1079 LayerAnimationController::Create(0)); |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1899 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); | 1908 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); |
| 1900 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | 1909 EXPECT_EQ(Animation::WAITING_FOR_DELETION, |
| 1901 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); | 1910 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); |
| 1902 | 1911 |
| 1903 controller->PushAnimationUpdatesTo(controller_impl.get()); | 1912 controller->PushAnimationUpdatesTo(controller_impl.get()); |
| 1904 controller_impl->ActivateAnimations(); | 1913 controller_impl->ActivateAnimations(); |
| 1905 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | 1914 EXPECT_FALSE(controller->GetAnimationById(animation_id)); |
| 1906 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | 1915 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); |
| 1907 } | 1916 } |
| 1908 | 1917 |
| 1918 // Test that an impl-only scroll offset animation that needs to be completed on | |
| 1919 // the main thread gets deleted. | |
| 1920 TEST(LayerAnimationControllerTest, ImplThreadTakeoverAnimationGetsDeleted) { | |
| 1921 FakeLayerAnimationValueObserver dummy_impl; | |
| 1922 scoped_refptr<LayerAnimationController> controller_impl( | |
| 1923 LayerAnimationController::Create(0)); | |
| 1924 controller_impl->AddValueObserver(&dummy_impl); | |
| 1925 FakeLayerAnimationValueObserver dummy; | |
| 1926 scoped_refptr<LayerAnimationController> controller( | |
| 1927 LayerAnimationController::Create(0)); | |
| 1928 controller->AddValueObserver(&dummy); | |
| 1929 FakeAnimationDelegate delegate_impl; | |
| 1930 controller_impl->set_layer_animation_delegate(&delegate_impl); | |
| 1931 FakeAnimationDelegate delegate; | |
| 1932 controller->set_layer_animation_delegate(&delegate); | |
| 1933 | |
| 1934 // Add impl-only scroll offset animation. | |
| 1935 int animation_id = 1; | |
| 1936 gfx::ScrollOffset initial_value(100.f, 300.f); | |
| 1937 gfx::ScrollOffset target_value(300.f, 200.f); | |
| 1938 scoped_ptr<ScrollOffsetAnimationCurve> curve( | |
| 1939 ScrollOffsetAnimationCurve::Create(target_value, | |
| 1940 EaseInOutTimingFunction::Create())); | |
| 1941 curve->SetInitialValue(initial_value); | |
| 1942 scoped_ptr<Animation> animation(Animation::Create( | |
| 1943 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET)); | |
| 1944 animation->set_start_time(TicksFromSecondsF(123)); | |
| 1945 animation->set_is_impl_only(true); | |
| 1946 controller_impl->AddAnimation(std::move(animation)); | |
| 1947 | |
| 1948 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1949 controller_impl->ActivateAnimations(); | |
| 1950 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id)); | |
| 1951 | |
| 1952 controller_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET, | |
| 1953 true /* needs_completion*/); | |
| 1954 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION, | |
| 1955 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 1956 ->run_state()); | |
| 1957 EXPECT_FALSE(dummy.animation_waiting_for_deletion()); | |
| 1958 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion()); | |
| 1959 | |
| 1960 AnimationEvents events; | |
| 1961 controller_impl->Animate(kInitialTickTime); | |
| 1962 controller_impl->UpdateState(true, &events); | |
| 1963 EXPECT_TRUE(delegate_impl.finished()); | |
| 1964 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion()); | |
| 1965 EXPECT_EQ(1u, events.events_.size()); | |
| 1966 EXPECT_EQ(AnimationEvent::TAKEOVER, events.events_[0].type); | |
| 1967 EXPECT_EQ(123, events.events_[0].animation_start_time); | |
| 1968 EXPECT_EQ( | |
| 1969 target_value, | |
| 1970 events.events_[0].curve->ToScrollOffsetAnimationCurve()->target_value()); | |
| 1971 EXPECT_EQ(Animation::WAITING_FOR_DELETION, | |
| 1972 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET) | |
| 1973 ->run_state()); | |
| 1974 | |
| 1975 controller->NotifyAnimationTakeover(events.events_[0]); | |
| 1976 EXPECT_TRUE(delegate.takeover()); | |
| 1977 | |
| 1978 controller->PushAnimationUpdatesTo(controller_impl.get()); | |
| 1979 controller_impl->ActivateAnimations(); | |
| 1980 EXPECT_FALSE(controller->GetAnimationById(animation_id)); | |
| 1981 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); | |
| 1982 } | |
| 1983 | |
| 1909 // Ensure that we only generate FINISHED events for animations in a group | 1984 // Ensure that we only generate FINISHED events for animations in a group |
| 1910 // once all animations in that group are finished. | 1985 // once all animations in that group are finished. |
| 1911 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { | 1986 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { |
| 1912 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); | 1987 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); |
| 1913 FakeLayerAnimationValueObserver dummy_impl; | 1988 FakeLayerAnimationValueObserver dummy_impl; |
| 1914 scoped_refptr<LayerAnimationController> controller_impl( | 1989 scoped_refptr<LayerAnimationController> controller_impl( |
| 1915 LayerAnimationController::Create(0)); | 1990 LayerAnimationController::Create(0)); |
| 1916 controller_impl->AddValueObserver(&dummy_impl); | 1991 controller_impl->AddValueObserver(&dummy_impl); |
| 1917 | 1992 |
| 1918 const int group_id = 1; | 1993 const int group_id = 1; |
| (...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3015 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3090 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3016 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3091 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3017 TargetProperty::OPACITY, | 3092 TargetProperty::OPACITY, |
| 3018 LayerAnimationController::ObserverType::PENDING)); | 3093 LayerAnimationController::ObserverType::PENDING)); |
| 3019 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( | 3094 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( |
| 3020 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); | 3095 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); |
| 3021 } | 3096 } |
| 3022 | 3097 |
| 3023 } // namespace | 3098 } // namespace |
| 3024 } // namespace cc | 3099 } // namespace cc |
| OLD | NEW |