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 "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/timing_function.h" | 9 #include "cc/animation/timing_function.h" |
10 #include "cc/layers/layer.h" | 10 #include "cc/layers/layer.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 virtual void BeginTest() OVERRIDE { | 309 virtual void BeginTest() OVERRIDE { |
310 PostAddAnimationToMainThread(content_.get()); | 310 PostAddAnimationToMainThread(content_.get()); |
311 } | 311 } |
312 | 312 |
313 virtual void AnimateLayers( | 313 virtual void AnimateLayers( |
314 LayerTreeHostImpl* host_impl, | 314 LayerTreeHostImpl* host_impl, |
315 base::TimeTicks monotonic_time) OVERRIDE { | 315 base::TimeTicks monotonic_time) OVERRIDE { |
316 LayerAnimationController* controller_impl = | 316 LayerAnimationController* controller_impl = |
317 host_impl->active_tree()->root_layer()->children()[0]-> | 317 host_impl->active_tree()->root_layer()->children()[0] |
318 layer_animation_controller(); | 318 ->layer_animation_controller(); |
319 Animation* animation = | 319 Animation* animation = controller_impl->GetAnimation(Animation::Opacity); |
320 controller_impl->GetAnimation(Animation::Opacity); | |
321 if (!animation) | 320 if (!animation) |
322 return; | 321 return; |
323 | 322 |
324 const FloatAnimationCurve* curve = | 323 const FloatAnimationCurve* curve = |
325 animation->curve()->ToFloatAnimationCurve(); | 324 animation->curve()->ToFloatAnimationCurve(); |
326 float start_opacity = curve->GetValue(0.0); | 325 float start_opacity = curve->GetValue(0.0); |
327 float end_opacity = curve->GetValue(curve->Duration()); | 326 float end_opacity = curve->GetValue(curve->Duration()); |
328 float linearly_interpolated_opacity = | 327 float linearly_interpolated_opacity = |
329 0.25f * end_opacity + 0.75f * start_opacity; | 328 0.25f * end_opacity + 0.75f * start_opacity; |
330 double time = curve->Duration() * 0.25; | 329 double time = curve->Duration() * 0.25; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 controller->RemoveAnimation(animation->id()); | 375 controller->RemoveAnimation(animation->id()); |
377 | 376 |
378 if (impl_start_time_ > 0.0) | 377 if (impl_start_time_ > 0.0) |
379 EndTest(); | 378 EndTest(); |
380 } | 379 } |
381 | 380 |
382 virtual void UpdateAnimationState( | 381 virtual void UpdateAnimationState( |
383 LayerTreeHostImpl* impl_host, | 382 LayerTreeHostImpl* impl_host, |
384 bool has_unfinished_animation) OVERRIDE { | 383 bool has_unfinished_animation) OVERRIDE { |
385 LayerAnimationController* controller = | 384 LayerAnimationController* controller = |
386 impl_host->active_tree()->root_layer()->children()[0]-> | 385 impl_host->active_tree()->root_layer()->children()[0] |
387 layer_animation_controller(); | 386 ->layer_animation_controller(); |
388 Animation* animation = | 387 Animation* animation = controller->GetAnimation(Animation::Opacity); |
389 controller->GetAnimation(Animation::Opacity); | |
390 if (!animation) | 388 if (!animation) |
391 return; | 389 return; |
392 | 390 |
393 impl_start_time_ = animation->start_time(); | 391 impl_start_time_ = animation->start_time(); |
394 controller->RemoveAnimation(animation->id()); | 392 controller->RemoveAnimation(animation->id()); |
395 | 393 |
396 if (main_start_time_ > 0.0) | 394 if (main_start_time_ > 0.0) |
397 EndTest(); | 395 EndTest(); |
398 } | 396 } |
399 | 397 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation) | 734 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation) |
737 OVERRIDE { | 735 OVERRIDE { |
738 LayerTreeHostAnimationTest::DispatchAddInstantAnimation( | 736 LayerTreeHostAnimationTest::DispatchAddInstantAnimation( |
739 layer_to_receive_animation); | 737 layer_to_receive_animation); |
740 added_animations_++; | 738 added_animations_++; |
741 } | 739 } |
742 | 740 |
743 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 741 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
744 LayerTreeHostImpl::FrameData* frame_data, | 742 LayerTreeHostImpl::FrameData* frame_data, |
745 bool result) OVERRIDE { | 743 bool result) OVERRIDE { |
746 if (added_animations_ < 2) | 744 if (host_impl->active_tree()->source_frame_number() < 2) |
747 return result; | 745 return result; |
748 if (TestEnded()) | 746 if (TestEnded()) |
749 return result; | 747 return result; |
750 // Act like there is checkerboard when the second animation wants to draw. | 748 // Act like there is checkerboard when the second animation wants to draw. |
751 ++prevented_draw_; | 749 ++prevented_draw_; |
| 750 if (finished_times_) |
| 751 EndTest(); |
752 return false; | 752 return false; |
753 } | 753 } |
754 | 754 |
755 virtual void DidCommitAndDrawFrame() OVERRIDE { | 755 virtual void DidCommit() OVERRIDE { |
756 switch (layer_tree_host()->source_frame_number()) { | 756 switch (layer_tree_host()->source_frame_number()) { |
757 case 1: | 757 case 1: |
758 // The animation is longer than 1 BeginFrame interval. | 758 // The animation is longer than 1 BeginFrame interval. |
759 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); | 759 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); |
760 added_animations_++; | 760 added_animations_++; |
761 break; | 761 break; |
762 case 2: | 762 case 2: |
763 // This second animation will not be drawn so it should not start. | 763 // This second animation will not be drawn so it should not start. |
764 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); | 764 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); |
765 added_animations_++; | 765 added_animations_++; |
766 break; | 766 break; |
767 } | 767 } |
768 } | 768 } |
769 | 769 |
770 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { | 770 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { |
771 if (TestEnded()) | 771 if (TestEnded()) |
772 return; | 772 return; |
773 started_times_++; | 773 started_times_++; |
774 } | 774 } |
775 | 775 |
776 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { | 776 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { |
777 // We should be checkerboarding already, but it should still finish the | 777 // We should be checkerboarding already, but it should still finish the |
778 // first animation. | 778 // first animation. |
779 EXPECT_EQ(2, added_animations_); | |
780 finished_times_++; | 779 finished_times_++; |
781 EndTest(); | 780 if (prevented_draw_) |
| 781 EndTest(); |
782 } | 782 } |
783 | 783 |
784 virtual void AfterTest() OVERRIDE { | 784 virtual void AfterTest() OVERRIDE { |
| 785 // Make sure both animations were added. |
| 786 EXPECT_EQ(2, added_animations_); |
785 // Make sure we tried to draw the second animation but failed. | 787 // Make sure we tried to draw the second animation but failed. |
786 EXPECT_LT(0, prevented_draw_); | 788 EXPECT_LT(0, prevented_draw_); |
787 // The first animation should be started, but the second should not because | 789 // The first animation should be started, but the second should not because |
788 // of checkerboard. | 790 // of checkerboard. |
789 EXPECT_EQ(1, started_times_); | 791 EXPECT_EQ(1, started_times_); |
790 // The first animation should still be finished. | 792 // The first animation should still be finished. |
791 EXPECT_EQ(1, finished_times_); | 793 EXPECT_EQ(1, finished_times_); |
792 } | 794 } |
793 | 795 |
794 int prevented_draw_; | 796 int prevented_draw_; |
795 int added_animations_; | 797 int added_animations_; |
796 int started_times_; | 798 int started_times_; |
797 int finished_times_; | 799 int finished_times_; |
798 FakeContentLayerClient client_; | 800 FakeContentLayerClient client_; |
799 scoped_refptr<FakeContentLayer> content_; | 801 scoped_refptr<FakeContentLayer> content_; |
800 }; | 802 }; |
801 | 803 |
802 MULTI_THREAD_TEST_F( | 804 MULTI_THREAD_TEST_F( |
803 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 805 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
804 | 806 |
805 } // namespace | 807 } // namespace |
806 } // namespace cc | 808 } // namespace cc |
OLD | NEW |