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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // Use WillAnimateLayers to set visible false before the animation runs and | 267 // 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 | 268 // causes a commit, so we block the second visible animate in single-thread |
269 // mode. | 269 // mode. |
270 virtual void WillAnimateLayers( | 270 virtual void WillAnimateLayers( |
271 LayerTreeHostImpl* host_impl, | 271 LayerTreeHostImpl* host_impl, |
272 base::TimeTicks monotonic_time) OVERRIDE { | 272 base::TimeTicks monotonic_time) OVERRIDE { |
273 if (!host_impl->active_tree()->root_layer()) | |
enne (OOO)
2013/08/15 19:47:59
I'm a little confused why animation is happening w
brianderson
2013/08/15 23:05:10
I would be fine with moving the early out up to th
brianderson
2013/08/15 23:45:12
Animation used to be coupled with drawing, but thi
enne (OOO)
2013/08/16 00:53:22
Yeah. LayerTreeHostImpl::Animate does this check.
| |
274 return; | |
275 | |
273 // Verify that the host can draw, it's just not visible. | 276 // Verify that the host can draw, it's just not visible. |
274 EXPECT_TRUE(host_impl->CanDraw()); | 277 EXPECT_TRUE(host_impl->CanDraw()); |
275 if (num_animates_ < 2) { | 278 if (num_animates_ < 2) { |
276 if (!num_animates_) { | 279 if (!num_animates_) { |
277 // We have a long animation running. It should continue to tick even | 280 // We have a long animation running. It should continue to tick even |
278 // if we are not visible. | 281 // if we are not visible. |
279 PostSetVisibleToMainThread(false); | 282 PostSetVisibleToMainThread(false); |
280 } | 283 } |
281 num_animates_++; | 284 num_animates_++; |
282 return; | 285 return; |
(...skipping 23 matching lines...) Expand all Loading... | |
306 layer_tree_host()->root_layer()->AddChild(content_); | 309 layer_tree_host()->root_layer()->AddChild(content_); |
307 } | 310 } |
308 | 311 |
309 virtual void BeginTest() OVERRIDE { | 312 virtual void BeginTest() OVERRIDE { |
310 PostAddAnimationToMainThread(content_.get()); | 313 PostAddAnimationToMainThread(content_.get()); |
311 } | 314 } |
312 | 315 |
313 virtual void AnimateLayers( | 316 virtual void AnimateLayers( |
314 LayerTreeHostImpl* host_impl, | 317 LayerTreeHostImpl* host_impl, |
315 base::TimeTicks monotonic_time) OVERRIDE { | 318 base::TimeTicks monotonic_time) OVERRIDE { |
319 if (!host_impl->active_tree()->root_layer()) | |
320 return; | |
316 LayerAnimationController* controller_impl = | 321 LayerAnimationController* controller_impl = |
317 host_impl->active_tree()->root_layer()->children()[0]-> | 322 host_impl->active_tree()->root_layer()->children()[0]-> |
318 layer_animation_controller(); | 323 layer_animation_controller(); |
319 Animation* animation = | 324 Animation* animation = |
320 controller_impl->GetAnimation(Animation::Opacity); | 325 controller_impl->GetAnimation(Animation::Opacity); |
321 if (!animation) | 326 if (!animation) |
322 return; | 327 return; |
323 | 328 |
324 const FloatAnimationCurve* curve = | 329 const FloatAnimationCurve* curve = |
325 animation->curve()->ToFloatAnimationCurve(); | 330 animation->curve()->ToFloatAnimationCurve(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 main_start_time_ = animation->start_time(); | 380 main_start_time_ = animation->start_time(); |
376 controller->RemoveAnimation(animation->id()); | 381 controller->RemoveAnimation(animation->id()); |
377 | 382 |
378 if (impl_start_time_ > 0.0) | 383 if (impl_start_time_ > 0.0) |
379 EndTest(); | 384 EndTest(); |
380 } | 385 } |
381 | 386 |
382 virtual void UpdateAnimationState( | 387 virtual void UpdateAnimationState( |
383 LayerTreeHostImpl* impl_host, | 388 LayerTreeHostImpl* impl_host, |
384 bool has_unfinished_animation) OVERRIDE { | 389 bool has_unfinished_animation) OVERRIDE { |
390 if (!impl_host->active_tree()->root_layer()) | |
391 return; | |
392 | |
385 LayerAnimationController* controller = | 393 LayerAnimationController* controller = |
386 impl_host->active_tree()->root_layer()->children()[0]-> | 394 impl_host->active_tree()->root_layer()->children()[0]-> |
387 layer_animation_controller(); | 395 layer_animation_controller(); |
388 Animation* animation = | 396 Animation* animation = |
389 controller->GetAnimation(Animation::Opacity); | 397 controller->GetAnimation(Animation::Opacity); |
390 if (!animation) | 398 if (!animation) |
391 return; | 399 return; |
392 | 400 |
393 impl_start_time_ = animation->start_time(); | 401 impl_start_time_ = animation->start_time(); |
394 controller->RemoveAnimation(animation->id()); | 402 controller->RemoveAnimation(animation->id()); |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
736 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation) | 744 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation) |
737 OVERRIDE { | 745 OVERRIDE { |
738 LayerTreeHostAnimationTest::DispatchAddInstantAnimation( | 746 LayerTreeHostAnimationTest::DispatchAddInstantAnimation( |
739 layer_to_receive_animation); | 747 layer_to_receive_animation); |
740 added_animations_++; | 748 added_animations_++; |
741 } | 749 } |
742 | 750 |
743 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 751 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
744 LayerTreeHostImpl::FrameData* frame_data, | 752 LayerTreeHostImpl::FrameData* frame_data, |
745 bool result) OVERRIDE { | 753 bool result) OVERRIDE { |
746 if (added_animations_ < 2) | 754 if (host_impl->active_tree()->source_frame_number() < 2) |
747 return result; | 755 return result; |
748 if (TestEnded()) | 756 if (TestEnded()) |
749 return result; | 757 return result; |
750 // Act like there is checkerboard when the second animation wants to draw. | 758 // Act like there is checkerboard when the second animation wants to draw. |
751 ++prevented_draw_; | 759 ++prevented_draw_; |
760 if (finished_times_) | |
761 EndTest(); | |
752 return false; | 762 return false; |
753 } | 763 } |
754 | 764 |
755 virtual void DidCommitAndDrawFrame() OVERRIDE { | 765 virtual void DidCommit() OVERRIDE { |
756 switch (layer_tree_host()->source_frame_number()) { | 766 switch (layer_tree_host()->source_frame_number()) { |
757 case 1: | 767 case 1: |
758 // The animation is longer than 1 BeginFrame interval. | 768 // The animation is longer than 1 BeginFrame interval. |
759 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); | 769 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false); |
760 added_animations_++; | 770 added_animations_++; |
761 break; | 771 break; |
762 case 2: | 772 case 2: |
763 // This second animation will not be drawn so it should not start. | 773 // This second animation will not be drawn so it should not start. |
764 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); | 774 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5); |
765 added_animations_++; | 775 added_animations_++; |
766 break; | 776 break; |
767 } | 777 } |
768 } | 778 } |
769 | 779 |
770 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { | 780 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE { |
771 if (TestEnded()) | 781 if (TestEnded()) |
772 return; | 782 return; |
773 started_times_++; | 783 started_times_++; |
774 } | 784 } |
775 | 785 |
776 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { | 786 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE { |
777 // We should be checkerboarding already, but it should still finish the | 787 // We should be checkerboarding already, but it should still finish the |
778 // first animation. | 788 // first animation. |
779 EXPECT_EQ(2, added_animations_); | |
enne (OOO)
2013/08/15 19:47:59
Just as a sanity check, move this to AfterTest rat
brianderson
2013/08/15 23:05:10
Ok.
| |
780 finished_times_++; | 789 finished_times_++; |
781 EndTest(); | 790 if (prevented_draw_) |
791 EndTest(); | |
782 } | 792 } |
783 | 793 |
784 virtual void AfterTest() OVERRIDE { | 794 virtual void AfterTest() OVERRIDE { |
785 // Make sure we tried to draw the second animation but failed. | 795 // Make sure we tried to draw the second animation but failed. |
786 EXPECT_LT(0, prevented_draw_); | 796 EXPECT_LT(0, prevented_draw_); |
787 // The first animation should be started, but the second should not because | 797 // The first animation should be started, but the second should not because |
788 // of checkerboard. | 798 // of checkerboard. |
789 EXPECT_EQ(1, started_times_); | 799 EXPECT_EQ(1, started_times_); |
790 // The first animation should still be finished. | 800 // The first animation should still be finished. |
791 EXPECT_EQ(1, finished_times_); | 801 EXPECT_EQ(1, finished_times_); |
792 } | 802 } |
793 | 803 |
794 int prevented_draw_; | 804 int prevented_draw_; |
795 int added_animations_; | 805 int added_animations_; |
796 int started_times_; | 806 int started_times_; |
797 int finished_times_; | 807 int finished_times_; |
798 FakeContentLayerClient client_; | 808 FakeContentLayerClient client_; |
799 scoped_refptr<FakeContentLayer> content_; | 809 scoped_refptr<FakeContentLayer> content_; |
800 }; | 810 }; |
801 | 811 |
802 MULTI_THREAD_TEST_F( | 812 MULTI_THREAD_TEST_F( |
803 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 813 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
804 | 814 |
805 } // namespace | 815 } // namespace |
806 } // namespace cc | 816 } // namespace cc |
OLD | NEW |