Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: cc/animation/layer_animation_controller_unittest.cc

Issue 1734063003: Share animations from compositor to main thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix win trybot failure Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 takeover_(false),
1028 start_time_(base::TimeTicks()) {} 1029 start_time_(base::TimeTicks()) {}
1029 1030
1030 void NotifyAnimationStarted(TimeTicks monotonic_time, 1031 void NotifyAnimationStarted(TimeTicks monotonic_time,
1031 TargetProperty::Type target_property, 1032 TargetProperty::Type target_property,
1032 int group) override { 1033 int group) override {
1033 started_ = true; 1034 started_ = true;
1034 start_time_ = monotonic_time; 1035 start_time_ = monotonic_time;
1035 } 1036 }
1036 1037
1037 void NotifyAnimationFinished(TimeTicks monotonic_time, 1038 void NotifyAnimationFinished(TimeTicks monotonic_time,
1038 TargetProperty::Type target_property, 1039 TargetProperty::Type target_property,
1039 int group) override { 1040 int group) override {
1040 finished_ = true; 1041 finished_ = true;
1041 } 1042 }
1042 1043
1043 void NotifyAnimationAborted(TimeTicks monotonic_time, 1044 void NotifyAnimationAborted(TimeTicks monotonic_time,
1044 TargetProperty::Type target_property, 1045 TargetProperty::Type target_property,
1045 int group) override { 1046 int group) override {
1046 aborted_ = true; 1047 aborted_ = true;
1047 } 1048 }
1048 1049
1050 void NotifyAnimationTakeover(base::TimeTicks monotonic_time,
1051 TargetProperty::Type target_property,
1052 double animation_start_time,
1053 scoped_ptr<AnimationCurve> curve) override {
1054 takeover_ = true;
1055 }
1056
1049 bool started() { return started_; } 1057 bool started() { return started_; }
1050 1058
1051 bool finished() { return finished_; } 1059 bool finished() { return finished_; }
1052 1060
1053 bool aborted() { return aborted_; } 1061 bool aborted() { return aborted_; }
1054 1062
1063 bool takeover() { return takeover_; }
1064
1055 TimeTicks start_time() { return start_time_; } 1065 TimeTicks start_time() { return start_time_; }
1056 1066
1057 private: 1067 private:
1058 bool started_; 1068 bool started_;
1059 bool finished_; 1069 bool finished_;
1060 bool aborted_; 1070 bool aborted_;
1071 bool takeover_;
1061 TimeTicks start_time_; 1072 TimeTicks start_time_;
1062 }; 1073 };
1063 1074
1064 // Tests that impl-only animations lead to start and finished notifications 1075 // Tests that impl-only animations lead to start and finished notifications
1065 // on the impl thread controller's animation delegate. 1076 // on the impl thread controller's animation delegate.
1066 TEST(LayerAnimationControllerTest, 1077 TEST(LayerAnimationControllerTest,
1067 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) { 1078 NotificationsForImplOnlyAnimationsAreSentToImplThreadDelegate) {
1068 FakeLayerAnimationValueObserver dummy_impl; 1079 FakeLayerAnimationValueObserver dummy_impl;
1069 scoped_refptr<LayerAnimationController> controller_impl( 1080 scoped_refptr<LayerAnimationController> controller_impl(
1070 LayerAnimationController::Create(0)); 1081 LayerAnimationController::Create(0));
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
1899 EXPECT_TRUE(dummy.animation_waiting_for_deletion()); 1910 EXPECT_TRUE(dummy.animation_waiting_for_deletion());
1900 EXPECT_EQ(Animation::WAITING_FOR_DELETION, 1911 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
1901 controller->GetAnimation(TargetProperty::OPACITY)->run_state()); 1912 controller->GetAnimation(TargetProperty::OPACITY)->run_state());
1902 1913
1903 controller->PushAnimationUpdatesTo(controller_impl.get()); 1914 controller->PushAnimationUpdatesTo(controller_impl.get());
1904 controller_impl->ActivateAnimations(); 1915 controller_impl->ActivateAnimations();
1905 EXPECT_FALSE(controller->GetAnimationById(animation_id)); 1916 EXPECT_FALSE(controller->GetAnimationById(animation_id));
1906 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id)); 1917 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
1907 } 1918 }
1908 1919
1920 // Test that an impl-only scroll offset animation that needs to be completed on
1921 // the main thread gets deleted.
1922 TEST(LayerAnimationControllerTest, ImplThreadTakeoverAnimationGetsDeleted) {
1923 FakeLayerAnimationValueObserver dummy_impl;
1924 scoped_refptr<LayerAnimationController> controller_impl(
1925 LayerAnimationController::Create(0));
1926 controller_impl->AddValueObserver(&dummy_impl);
1927 FakeLayerAnimationValueObserver dummy;
1928 scoped_refptr<LayerAnimationController> controller(
1929 LayerAnimationController::Create(0));
1930 controller->AddValueObserver(&dummy);
1931 FakeAnimationDelegate delegate_impl;
1932 controller_impl->set_layer_animation_delegate(&delegate_impl);
1933 FakeAnimationDelegate delegate;
1934 controller->set_layer_animation_delegate(&delegate);
1935
1936 // Add impl-only scroll offset animation.
1937 int animation_id = 1;
1938 gfx::ScrollOffset initial_value(100.f, 300.f);
1939 gfx::ScrollOffset target_value(300.f, 200.f);
1940 scoped_ptr<ScrollOffsetAnimationCurve> curve(
1941 ScrollOffsetAnimationCurve::Create(target_value,
1942 EaseInOutTimingFunction::Create()));
1943 curve->SetInitialValue(initial_value);
1944 scoped_ptr<Animation> animation(Animation::Create(
1945 std::move(curve), animation_id, 0, TargetProperty::SCROLL_OFFSET));
1946 animation->set_start_time(TicksFromSecondsF(123));
1947 animation->set_is_impl_only(true);
1948 controller_impl->AddAnimation(std::move(animation));
1949
1950 controller->PushAnimationUpdatesTo(controller_impl.get());
1951 controller_impl->ActivateAnimations();
1952 EXPECT_TRUE(controller_impl->GetAnimationById(animation_id));
1953
1954 controller_impl->AbortAnimations(TargetProperty::SCROLL_OFFSET,
1955 true /* needs_completion*/);
1956 EXPECT_EQ(Animation::ABORTED_BUT_NEEDS_COMPLETION,
1957 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
1958 ->run_state());
1959 EXPECT_FALSE(dummy.animation_waiting_for_deletion());
1960 EXPECT_FALSE(dummy_impl.animation_waiting_for_deletion());
1961
1962 AnimationEvents events;
1963 controller_impl->Animate(kInitialTickTime);
1964 controller_impl->UpdateState(true, &events);
1965 EXPECT_TRUE(delegate_impl.finished());
1966 EXPECT_TRUE(dummy_impl.animation_waiting_for_deletion());
1967 EXPECT_EQ(1u, events.events_.size());
1968 EXPECT_EQ(AnimationEvent::TAKEOVER, events.events_[0].type);
1969 EXPECT_EQ(123, events.events_[0].animation_start_time);
1970 EXPECT_EQ(
1971 target_value,
1972 events.events_[0].curve->ToScrollOffsetAnimationCurve()->target_value());
1973 EXPECT_EQ(Animation::WAITING_FOR_DELETION,
1974 controller_impl->GetAnimation(TargetProperty::SCROLL_OFFSET)
1975 ->run_state());
1976
1977 controller->NotifyAnimationTakeover(events.events_[0]);
1978 EXPECT_TRUE(delegate.takeover());
1979
1980 controller->PushAnimationUpdatesTo(controller_impl.get());
1981 controller_impl->ActivateAnimations();
1982 EXPECT_FALSE(controller->GetAnimationById(animation_id));
1983 EXPECT_FALSE(controller_impl->GetAnimationById(animation_id));
1984 }
1985
1909 // Ensure that we only generate FINISHED events for animations in a group 1986 // Ensure that we only generate FINISHED events for animations in a group
1910 // once all animations in that group are finished. 1987 // once all animations in that group are finished.
1911 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) { 1988 TEST(LayerAnimationControllerTest, FinishedEventsForGroup) {
1912 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents)); 1989 scoped_ptr<AnimationEvents> events(make_scoped_ptr(new AnimationEvents));
1913 FakeLayerAnimationValueObserver dummy_impl; 1990 FakeLayerAnimationValueObserver dummy_impl;
1914 scoped_refptr<LayerAnimationController> controller_impl( 1991 scoped_refptr<LayerAnimationController> controller_impl(
1915 LayerAnimationController::Create(0)); 1992 LayerAnimationController::Create(0));
1916 controller_impl->AddValueObserver(&dummy_impl); 1993 controller_impl->AddValueObserver(&dummy_impl);
1917 1994
1918 const int group_id = 1; 1995 const int group_id = 1;
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
3015 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); 3092 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
3016 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( 3093 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
3017 TargetProperty::OPACITY, 3094 TargetProperty::OPACITY,
3018 LayerAnimationController::ObserverType::PENDING)); 3095 LayerAnimationController::ObserverType::PENDING));
3019 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty( 3096 EXPECT_FALSE(controller->IsCurrentlyAnimatingProperty(
3020 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE)); 3097 TargetProperty::OPACITY, LayerAnimationController::ObserverType::ACTIVE));
3021 } 3098 }
3022 3099
3023 } // namespace 3100 } // namespace
3024 } // namespace cc 3101 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.cc ('k') | cc/animation/scroll_offset_animation_curve.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698