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

Side by Side Diff: cc/trees/layer_tree_host_unittest_animation.cc

Issue 99733003: Add monotonic time and target property to cc::AnimationDelegate notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years 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 | Annotate | Revision Log
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/trees/layer_tree_host.h" 5 #include "cc/trees/layer_tree_host.h"
6 6
7 #include "cc/animation/animation_curve.h" 7 #include "cc/animation/animation_curve.h"
8 #include "cc/animation/layer_animation_controller.h" 8 #include "cc/animation/layer_animation_controller.h"
9 #include "cc/animation/scroll_offset_animation_curve.h" 9 #include "cc/animation/scroll_offset_animation_curve.h"
10 #include "cc/animation/timing_function.h" 10 #include "cc/animation/timing_function.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); 109 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback);
110 110
111 // Add a layer animation and confirm that 111 // Add a layer animation and confirm that
112 // LayerTreeHostImpl::updateAnimationState does get called and continues to 112 // LayerTreeHostImpl::updateAnimationState does get called and continues to
113 // get called. 113 // get called.
114 class LayerTreeHostAnimationTestAddAnimation 114 class LayerTreeHostAnimationTestAddAnimation
115 : public LayerTreeHostAnimationTest { 115 : public LayerTreeHostAnimationTest {
116 public: 116 public:
117 LayerTreeHostAnimationTestAddAnimation() 117 LayerTreeHostAnimationTestAddAnimation()
118 : num_animates_(0), 118 : num_animates_(0),
119 received_animation_started_notification_(false), 119 received_animation_started_notification_(false) {
120 start_time_(0.0) {
121 } 120 }
122 121
123 virtual void BeginTest() OVERRIDE { 122 virtual void BeginTest() OVERRIDE {
124 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); 123 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer());
125 } 124 }
126 125
127 virtual void UpdateAnimationState( 126 virtual void UpdateAnimationState(
128 LayerTreeHostImpl* host_impl, 127 LayerTreeHostImpl* host_impl,
129 bool has_unfinished_animation) OVERRIDE { 128 bool has_unfinished_animation) OVERRIDE {
130 if (!num_animates_) { 129 if (!num_animates_) {
131 // The animation had zero duration so LayerTreeHostImpl should no 130 // The animation had zero duration so LayerTreeHostImpl should no
132 // longer need to animate its layers. 131 // longer need to animate its layers.
133 EXPECT_FALSE(has_unfinished_animation); 132 EXPECT_FALSE(has_unfinished_animation);
134 num_animates_++; 133 num_animates_++;
135 return; 134 return;
136 } 135 }
137 136
138 if (received_animation_started_notification_) { 137 if (received_animation_started_notification_) {
139 EXPECT_LT(0.0, start_time_); 138 EXPECT_LT(base::TimeTicks(), start_time_);
140 139
141 LayerAnimationController* controller_impl = 140 LayerAnimationController* controller_impl =
142 host_impl->active_tree()->root_layer()->layer_animation_controller(); 141 host_impl->active_tree()->root_layer()->layer_animation_controller();
143 Animation* animation_impl = 142 Animation* animation_impl =
144 controller_impl->GetAnimation(Animation::Opacity); 143 controller_impl->GetAnimation(Animation::Opacity);
145 if (animation_impl) 144 if (animation_impl)
146 controller_impl->RemoveAnimation(animation_impl->id()); 145 controller_impl->RemoveAnimation(animation_impl->id());
147 146
148 EndTest(); 147 EndTest();
149 } 148 }
150 } 149 }
151 150
152 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { 151 virtual void NotifyAnimationStarted(
152 double wall_clock_time,
153 base::TimeTicks monotonic_time,
154 Animation::TargetProperty target_property) OVERRIDE {
153 received_animation_started_notification_ = true; 155 received_animation_started_notification_ = true;
154 start_time_ = wall_clock_time; 156 start_time_ = monotonic_time;
155 if (num_animates_) { 157 if (num_animates_) {
156 EXPECT_LT(0.0, start_time_); 158 EXPECT_LT(base::TimeTicks(), start_time_);
157 159
158 LayerAnimationController* controller = 160 LayerAnimationController* controller =
159 layer_tree_host()->root_layer()->layer_animation_controller(); 161 layer_tree_host()->root_layer()->layer_animation_controller();
160 Animation* animation = 162 Animation* animation =
161 controller->GetAnimation(Animation::Opacity); 163 controller->GetAnimation(Animation::Opacity);
162 if (animation) 164 if (animation)
163 controller->RemoveAnimation(animation->id()); 165 controller->RemoveAnimation(animation->id());
164 166
165 EndTest(); 167 EndTest();
166 } 168 }
167 } 169 }
168 170
169 virtual void AfterTest() OVERRIDE {} 171 virtual void AfterTest() OVERRIDE {}
170 172
171 private: 173 private:
172 int num_animates_; 174 int num_animates_;
173 bool received_animation_started_notification_; 175 bool received_animation_started_notification_;
174 double start_time_; 176 base::TimeTicks start_time_;
175 }; 177 };
176 178
177 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); 179 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation);
178 180
179 // Add a layer animation to a layer, but continually fail to draw. Confirm that 181 // Add a layer animation to a layer, but continually fail to draw. Confirm that
180 // after a while, we do eventually force a draw. 182 // after a while, we do eventually force a draw.
181 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws 183 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws
182 : public LayerTreeHostAnimationTest { 184 : public LayerTreeHostAnimationTest {
183 public: 185 public:
184 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() 186 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 active_animation_controllers().empty(); 235 active_animation_controllers().empty();
234 if (!started_animating_ && have_animations) { 236 if (!started_animating_ && have_animations) {
235 started_animating_ = true; 237 started_animating_ = true;
236 return; 238 return;
237 } 239 }
238 240
239 if (started_animating_ && !have_animations) 241 if (started_animating_ && !have_animations)
240 EndTest(); 242 EndTest();
241 } 243 }
242 244
243 virtual void NotifyAnimationFinished(double time) OVERRIDE { 245 virtual void NotifyAnimationFinished(
246 double wall_clock_time,
247 base::TimeTicks monotonic_time,
248 Animation::TargetProperty target_property) OVERRIDE {
244 // Animations on the impl-side controller only get deleted during a commit, 249 // Animations on the impl-side controller only get deleted during a commit,
245 // so we need to schedule a commit. 250 // so we need to schedule a commit.
246 layer_tree_host()->SetNeedsCommit(); 251 layer_tree_host()->SetNeedsCommit();
247 } 252 }
248 253
249 virtual void AfterTest() OVERRIDE {} 254 virtual void AfterTest() OVERRIDE {}
250 255
251 private: 256 private:
252 bool started_animating_; 257 bool started_animating_;
253 }; 258 };
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 : active_tree_was_animated_(false) {} 308 : active_tree_was_animated_(false) {}
304 309
305 virtual base::TimeDelta LowFrequencyAnimationInterval() const OVERRIDE { 310 virtual base::TimeDelta LowFrequencyAnimationInterval() const OVERRIDE {
306 return base::TimeDelta::FromMilliseconds(4); 311 return base::TimeDelta::FromMilliseconds(4);
307 } 312 }
308 313
309 virtual void BeginTest() OVERRIDE { 314 virtual void BeginTest() OVERRIDE {
310 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); 315 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
311 } 316 }
312 317
313 virtual void NotifyAnimationFinished(double time) OVERRIDE { 318 virtual void NotifyAnimationFinished(
319 double wall_clock_time,
320 base::TimeTicks monotonic_time,
321 Animation::TargetProperty target_property) OVERRIDE {
314 // Replace animated commits with an empty tree. 322 // Replace animated commits with an empty tree.
315 layer_tree_host()->SetRootLayer(make_scoped_refptr<Layer>(NULL)); 323 layer_tree_host()->SetRootLayer(make_scoped_refptr<Layer>(NULL));
316 } 324 }
317 325
318 virtual void DidCommit() OVERRIDE { 326 virtual void DidCommit() OVERRIDE {
319 // This alternates setting an empty tree and a non-empty tree with an 327 // This alternates setting an empty tree and a non-empty tree with an
320 // animation. 328 // animation.
321 switch (layer_tree_host()->source_frame_number()) { 329 switch (layer_tree_host()->source_frame_number()) {
322 case 1: 330 case 1:
323 // Wait for NotifyAnimationFinished to commit an empty tree. 331 // Wait for NotifyAnimationFinished to commit an empty tree.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 content_ = FakeContentLayer::Create(&client_); 501 content_ = FakeContentLayer::Create(&client_);
494 content_->SetBounds(gfx::Size(4, 4)); 502 content_->SetBounds(gfx::Size(4, 4));
495 content_->set_layer_animation_delegate(this); 503 content_->set_layer_animation_delegate(this);
496 layer_tree_host()->root_layer()->AddChild(content_); 504 layer_tree_host()->root_layer()->AddChild(content_);
497 } 505 }
498 506
499 virtual void BeginTest() OVERRIDE { 507 virtual void BeginTest() OVERRIDE {
500 PostAddAnimationToMainThread(content_.get()); 508 PostAddAnimationToMainThread(content_.get());
501 } 509 }
502 510
503 virtual void NotifyAnimationStarted(double time) OVERRIDE { 511 virtual void NotifyAnimationStarted(
512 double wall_clock_time,
513 base::TimeTicks monotonic_time,
514 Animation::TargetProperty target_property) OVERRIDE {
504 LayerAnimationController* controller = 515 LayerAnimationController* controller =
505 layer_tree_host()->root_layer()->children()[0]-> 516 layer_tree_host()->root_layer()->children()[0]->
506 layer_animation_controller(); 517 layer_animation_controller();
507 Animation* animation = 518 Animation* animation =
508 controller->GetAnimation(Animation::Opacity); 519 controller->GetAnimation(Animation::Opacity);
509 main_start_time_ = animation->start_time(); 520 main_start_time_ = animation->start_time();
510 controller->RemoveAnimation(animation->id()); 521 controller->RemoveAnimation(animation->id());
511 522
512 if (impl_start_time_ > 0.0) 523 if (impl_start_time_ > 0.0)
513 EndTest(); 524 EndTest();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 // Ensures that notify animation finished is called. 559 // Ensures that notify animation finished is called.
549 class LayerTreeHostAnimationTestAnimationFinishedEvents 560 class LayerTreeHostAnimationTestAnimationFinishedEvents
550 : public LayerTreeHostAnimationTest { 561 : public LayerTreeHostAnimationTest {
551 public: 562 public:
552 LayerTreeHostAnimationTestAnimationFinishedEvents() {} 563 LayerTreeHostAnimationTestAnimationFinishedEvents() {}
553 564
554 virtual void BeginTest() OVERRIDE { 565 virtual void BeginTest() OVERRIDE {
555 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); 566 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer());
556 } 567 }
557 568
558 virtual void NotifyAnimationFinished(double time) OVERRIDE { 569 virtual void NotifyAnimationFinished(
570 double wall_clock_time,
571 base::TimeTicks monotonic_time,
572 Animation::TargetProperty target_property) OVERRIDE {
559 LayerAnimationController* controller = 573 LayerAnimationController* controller =
560 layer_tree_host()->root_layer()->layer_animation_controller(); 574 layer_tree_host()->root_layer()->layer_animation_controller();
561 Animation* animation = 575 Animation* animation =
562 controller->GetAnimation(Animation::Opacity); 576 controller->GetAnimation(Animation::Opacity);
563 if (animation) 577 if (animation)
564 controller->RemoveAnimation(animation->id()); 578 controller->RemoveAnimation(animation->id());
565 EndTest(); 579 EndTest();
566 } 580 }
567 581
568 virtual void AfterTest() OVERRIDE {} 582 virtual void AfterTest() OVERRIDE {}
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 content_->SetBounds(gfx::Size(4, 4)); 778 content_->SetBounds(gfx::Size(4, 4));
765 content_->set_layer_animation_delegate(this); 779 content_->set_layer_animation_delegate(this);
766 layer_tree_host()->root_layer()->AddChild(content_); 780 layer_tree_host()->root_layer()->AddChild(content_);
767 } 781 }
768 782
769 virtual void BeginTest() OVERRIDE { 783 virtual void BeginTest() OVERRIDE {
770 layer_tree_host()->SetViewportSize(gfx::Size()); 784 layer_tree_host()->SetViewportSize(gfx::Size());
771 PostAddAnimationToMainThread(content_.get()); 785 PostAddAnimationToMainThread(content_.get());
772 } 786 }
773 787
774 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { 788 virtual void NotifyAnimationStarted(
789 double wall_clock_time,
790 base::TimeTicks monotonic_time,
791 Animation::TargetProperty target_property) OVERRIDE {
775 started_times_++; 792 started_times_++;
776 } 793 }
777 794
778 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { 795 virtual void NotifyAnimationFinished(
796 double wall_clock_time,
797 base::TimeTicks monotonic_time,
798 Animation::TargetProperty target_property) OVERRIDE {
779 EndTest(); 799 EndTest();
780 } 800 }
781 801
782 virtual void AfterTest() OVERRIDE { 802 virtual void AfterTest() OVERRIDE {
783 EXPECT_EQ(1, started_times_); 803 EXPECT_EQ(1, started_times_);
784 } 804 }
785 805
786 private: 806 private:
787 int started_times_; 807 int started_times_;
788 FakeContentLayerClient client_; 808 FakeContentLayerClient client_;
(...skipping 21 matching lines...) Expand all
810 virtual void BeginTest() OVERRIDE { 830 virtual void BeginTest() OVERRIDE {
811 visible_ = true; 831 visible_ = true;
812 PostAddAnimationToMainThread(content_.get()); 832 PostAddAnimationToMainThread(content_.get());
813 } 833 }
814 834
815 virtual void DidCommit() OVERRIDE { 835 virtual void DidCommit() OVERRIDE {
816 visible_ = false; 836 visible_ = false;
817 layer_tree_host()->SetVisible(false); 837 layer_tree_host()->SetVisible(false);
818 } 838 }
819 839
820 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { 840 virtual void NotifyAnimationStarted(
841 double wall_clock_time,
842 base::TimeTicks monotonic_time,
843 Animation::TargetProperty target_property) OVERRIDE {
821 EXPECT_FALSE(visible_); 844 EXPECT_FALSE(visible_);
822 started_times_++; 845 started_times_++;
823 } 846 }
824 847
825 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { 848 virtual void NotifyAnimationFinished(
849 double wall_clock_time,
850 base::TimeTicks monotonic_time,
851 Animation::TargetProperty target_property) OVERRIDE {
826 EXPECT_FALSE(visible_); 852 EXPECT_FALSE(visible_);
827 EXPECT_EQ(1, started_times_); 853 EXPECT_EQ(1, started_times_);
828 EndTest(); 854 EndTest();
829 } 855 }
830 856
831 virtual void AfterTest() OVERRIDE {} 857 virtual void AfterTest() OVERRIDE {}
832 858
833 private: 859 private:
834 bool visible_; 860 bool visible_;
835 int started_times_; 861 int started_times_;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 added_animations_++; 913 added_animations_++;
888 break; 914 break;
889 case 2: 915 case 2:
890 // This second animation will not be drawn so it should not start. 916 // This second animation will not be drawn so it should not start.
891 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); 917 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5);
892 added_animations_++; 918 added_animations_++;
893 break; 919 break;
894 } 920 }
895 } 921 }
896 922
897 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { 923 virtual void NotifyAnimationStarted(
924 double wall_clock_time,
925 base::TimeTicks monotonic_time,
926 Animation::TargetProperty target_property) OVERRIDE {
898 if (TestEnded()) 927 if (TestEnded())
899 return; 928 return;
900 started_times_++; 929 started_times_++;
901 } 930 }
902 931
903 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { 932 virtual void NotifyAnimationFinished(
933 double wall_clock_time,
934 base::TimeTicks monotonic_time,
935 Animation::TargetProperty target_property) OVERRIDE {
904 // We should be checkerboarding already, but it should still finish the 936 // We should be checkerboarding already, but it should still finish the
905 // first animation. 937 // first animation.
906 EXPECT_EQ(2, added_animations_); 938 EXPECT_EQ(2, added_animations_);
907 finished_times_++; 939 finished_times_++;
908 EndTest(); 940 EndTest();
909 } 941 }
910 942
911 virtual void AfterTest() OVERRIDE { 943 virtual void AfterTest() OVERRIDE {
912 // Make sure we tried to draw the second animation but failed. 944 // Make sure we tried to draw the second animation but failed.
913 EXPECT_LT(0, prevented_draw_); 945 EXPECT_LT(0, prevented_draw_);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 FakeContentLayerClient client_; 1008 FakeContentLayerClient client_;
977 scoped_refptr<FakeContentLayer> scroll_layer_; 1009 scoped_refptr<FakeContentLayer> scroll_layer_;
978 }; 1010 };
979 1011
980 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to 1012 // SingleThreadProxy doesn't send scroll updates from LayerTreeHostImpl to
981 // LayerTreeHost. 1013 // LayerTreeHost.
982 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); 1014 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetChangesArePropagated);
983 1015
984 } // namespace 1016 } // namespace
985 } // namespace cc 1017 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/layer_tree_test.h ('k') | webkit/renderer/compositor_bindings/web_to_cc_animation_delegate_adapter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698