| 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded | 257 class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded |
| 258 : public LayerTreeHostAnimationTest { | 258 : public LayerTreeHostAnimationTest { |
| 259 public: | 259 public: |
| 260 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded() | 260 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded() |
| 261 : num_animates_(0) {} | 261 : num_animates_(0) {} |
| 262 | 262 |
| 263 virtual void BeginTest() OVERRIDE { | 263 virtual void BeginTest() OVERRIDE { |
| 264 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 264 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 268 if (num_animates_ == 1) |
| 269 PostSetVisibleToMainThread(false); |
| 270 } |
| 271 |
| 267 // Use WillAnimateLayers to set visible false before the animation runs and | 272 // Use WillAnimateLayers to set visible false before the animation runs and |
| 268 // causes a commit, so we block the second visible animate in single-thread | 273 // causes a commit, so we block the second visible animate in single-thread |
| 269 // mode. | 274 // mode. |
| 270 virtual void WillAnimateLayers( | 275 virtual void WillAnimateLayers( |
| 271 LayerTreeHostImpl* host_impl, | 276 LayerTreeHostImpl* host_impl, |
| 272 base::TimeTicks monotonic_time) OVERRIDE { | 277 base::TimeTicks monotonic_time) OVERRIDE { |
| 273 if (num_animates_ < 2) { | 278 if (num_animates_ < 3) { |
| 274 if (!num_animates_) { | |
| 275 // We have a long animation running. It should continue to tick even | |
| 276 // if we are not visible. | |
| 277 PostSetVisibleToMainThread(false); | |
| 278 } | |
| 279 num_animates_++; | 279 num_animates_++; |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 EndTest(); | 282 EndTest(); |
| 283 } | 283 } |
| 284 | 284 |
| 285 virtual void AfterTest() OVERRIDE {} | 285 virtual void AfterTest() OVERRIDE {} |
| 286 | 286 |
| 287 private: | 287 private: |
| 288 int num_animates_; | 288 int num_animates_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 304 layer_tree_host()->root_layer()->AddChild(content_); | 304 layer_tree_host()->root_layer()->AddChild(content_); |
| 305 } | 305 } |
| 306 | 306 |
| 307 virtual void BeginTest() OVERRIDE { | 307 virtual void BeginTest() OVERRIDE { |
| 308 PostAddAnimationToMainThread(content_.get()); | 308 PostAddAnimationToMainThread(content_.get()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 virtual void AnimateLayers( | 311 virtual void AnimateLayers( |
| 312 LayerTreeHostImpl* host_impl, | 312 LayerTreeHostImpl* host_impl, |
| 313 base::TimeTicks monotonic_time) OVERRIDE { | 313 base::TimeTicks monotonic_time) OVERRIDE { |
| 314 if (!host_impl->active_tree()->root_layer()) |
| 315 return; |
| 314 LayerAnimationController* controller_impl = | 316 LayerAnimationController* controller_impl = |
| 315 host_impl->active_tree()->root_layer()->children()[0]-> | 317 host_impl->active_tree()->root_layer()->children()[0]-> |
| 316 layer_animation_controller(); | 318 layer_animation_controller(); |
| 317 Animation* animation = | 319 Animation* animation = |
| 318 controller_impl->GetAnimation(Animation::Opacity); | 320 controller_impl->GetAnimation(Animation::Opacity); |
| 319 if (!animation) | 321 if (!animation) |
| 320 return; | 322 return; |
| 321 | 323 |
| 322 const FloatAnimationCurve* curve = | 324 const FloatAnimationCurve* curve = |
| 323 animation->curve()->ToFloatAnimationCurve(); | 325 animation->curve()->ToFloatAnimationCurve(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 main_start_time_ = animation->start_time(); | 375 main_start_time_ = animation->start_time(); |
| 374 controller->RemoveAnimation(animation->id()); | 376 controller->RemoveAnimation(animation->id()); |
| 375 | 377 |
| 376 if (impl_start_time_ > 0.0) | 378 if (impl_start_time_ > 0.0) |
| 377 EndTest(); | 379 EndTest(); |
| 378 } | 380 } |
| 379 | 381 |
| 380 virtual void UpdateAnimationState( | 382 virtual void UpdateAnimationState( |
| 381 LayerTreeHostImpl* impl_host, | 383 LayerTreeHostImpl* impl_host, |
| 382 bool has_unfinished_animation) OVERRIDE { | 384 bool has_unfinished_animation) OVERRIDE { |
| 385 if (!impl_host->active_tree()->root_layer()) |
| 386 return; |
| 387 |
| 383 LayerAnimationController* controller = | 388 LayerAnimationController* controller = |
| 384 impl_host->active_tree()->root_layer()->children()[0]-> | 389 impl_host->active_tree()->root_layer()->children()[0]-> |
| 385 layer_animation_controller(); | 390 layer_animation_controller(); |
| 386 Animation* animation = | 391 Animation* animation = |
| 387 controller->GetAnimation(Animation::Opacity); | 392 controller->GetAnimation(Animation::Opacity); |
| 388 if (!animation) | 393 if (!animation) |
| 389 return; | 394 return; |
| 390 | 395 |
| 391 impl_start_time_ = animation->start_time(); | 396 impl_start_time_ = animation->start_time(); |
| 392 controller->RemoveAnimation(animation->id()); | 397 controller->RemoveAnimation(animation->id()); |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation) | 739 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation) |
| 735 OVERRIDE { | 740 OVERRIDE { |
| 736 LayerTreeHostAnimationTest::DispatchAddInstantAnimation( | 741 LayerTreeHostAnimationTest::DispatchAddInstantAnimation( |
| 737 layer_to_receive_animation); | 742 layer_to_receive_animation); |
| 738 added_animations_++; | 743 added_animations_++; |
| 739 } | 744 } |
| 740 | 745 |
| 741 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 746 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 742 LayerTreeHostImpl::FrameData* frame_data, | 747 LayerTreeHostImpl::FrameData* frame_data, |
| 743 bool result) OVERRIDE { | 748 bool result) OVERRIDE { |
| 744 if (added_animations_ < 2) | 749 if (host_impl->active_tree()->source_frame_number() < 2) |
| 745 return result; | 750 return result; |
| 746 if (TestEnded()) | 751 if (TestEnded()) |
| 747 return result; | 752 return result; |
| 748 // Act like there is checkerboard when the second animation wants to draw. | 753 // Act like there is checkerboard when the second animation wants to draw. |
| 749 ++prevented_draw_; | 754 ++prevented_draw_; |
| 755 if (finished_times_) |
| 756 EndTest(); |
| 750 return false; | 757 return false; |
| 751 } | 758 } |
| 752 | 759 |
| 753 virtual void DidCommitAndDrawFrame() OVERRIDE { | 760 virtual void DidCommit() OVERRIDE { |
| 754 switch (layer_tree_host()->source_frame_number()) { | 761 switch (layer_tree_host()->source_frame_number()) { |
| 755 case 1: | 762 case 1: |
| 756 // The animation is longer than 1 BeginFrame interval. | 763 // The animation is longer than 1 BeginFrame interval. |
| 757 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); | 764 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); |
| 758 added_animations_++; | 765 added_animations_++; |
| 759 break; | 766 break; |
| 760 case 2: | 767 case 2: |
| 761 // This second animation will not be drawn so it should not start. | 768 // This second animation will not be drawn so it should not start. |
| 762 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); | 769 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); |
| 763 added_animations_++; | 770 added_animations_++; |
| 764 break; | 771 break; |
| 765 } | 772 } |
| 766 } | 773 } |
| 767 | 774 |
| 768 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { | 775 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { |
| 769 if (TestEnded()) | 776 if (TestEnded()) |
| 770 return; | 777 return; |
| 771 started_times_++; | 778 started_times_++; |
| 772 } | 779 } |
| 773 | 780 |
| 774 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { | 781 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { |
| 775 // We should be checkerboarding already, but it should still finish the | 782 // We should be checkerboarding already, but it should still finish the |
| 776 // first animation. | 783 // first animation. |
| 777 EXPECT_EQ(2, added_animations_); | |
| 778 finished_times_++; | 784 finished_times_++; |
| 779 EndTest(); | 785 if (prevented_draw_) |
| 786 EndTest(); |
| 780 } | 787 } |
| 781 | 788 |
| 782 virtual void AfterTest() OVERRIDE { | 789 virtual void AfterTest() OVERRIDE { |
| 783 // Make sure we tried to draw the second animation but failed. | 790 // Make sure we tried to draw the second animation but failed. |
| 784 EXPECT_LT(0, prevented_draw_); | 791 EXPECT_LT(0, prevented_draw_); |
| 785 // The first animation should be started, but the second should not because | 792 // The first animation should be started, but the second should not because |
| 786 // of checkerboard. | 793 // of checkerboard. |
| 787 EXPECT_EQ(1, started_times_); | 794 EXPECT_EQ(1, started_times_); |
| 788 // The first animation should still be finished. | 795 // The first animation should still be finished. |
| 789 EXPECT_EQ(1, finished_times_); | 796 EXPECT_EQ(1, finished_times_); |
| 790 } | 797 } |
| 791 | 798 |
| 792 int prevented_draw_; | 799 int prevented_draw_; |
| 793 int added_animations_; | 800 int added_animations_; |
| 794 int started_times_; | 801 int started_times_; |
| 795 int finished_times_; | 802 int finished_times_; |
| 796 FakeContentLayerClient client_; | 803 FakeContentLayerClient client_; |
| 797 scoped_refptr<FakeContentLayer> content_; | 804 scoped_refptr<FakeContentLayer> content_; |
| 798 }; | 805 }; |
| 799 | 806 |
| 800 MULTI_THREAD_TEST_F( | 807 MULTI_THREAD_TEST_F( |
| 801 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 808 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
| 802 | 809 |
| 803 } // namespace | 810 } // namespace |
| 804 } // namespace cc | 811 } // namespace cc |
| OLD | NEW |