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
3 // found in the LICENSE file.
5 #include "cc/trees/layer_tree_host.h"
7 #include "cc/animation/animation_curve.h"
8 #include "cc/animation/layer_animation_controller.h"
9 #include "cc/animation/timing_function.h"
10 #include "cc/layers/layer.h"
11 #include "cc/layers/layer_impl.h"
12 #include "cc/test/animation_test_common.h"
13 #include "cc/test/fake_content_layer.h"
14 #include "cc/test/fake_content_layer_client.h"
15 #include "cc/test/layer_tree_test.h"
16 #include "cc/trees/layer_tree_impl.h"
21 class LayerTreeHostAnimationTest
: public LayerTreeTest
{
23 virtual void SetupTree() OVERRIDE
{
24 LayerTreeTest::SetupTree();
25 layer_tree_host()->root_layer()->set_layer_animation_delegate(this);
29 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to
31 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested
32 : public LayerTreeHostAnimationTest
{
34 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested()
37 virtual void BeginTest() OVERRIDE
{
38 PostSetNeedsCommitToMainThread();
41 virtual void Animate(base::TimeTicks monotonic_time
) OVERRIDE
{
42 // We skip the first commit becasue its the commit that populates the
43 // impl thread with a tree. After the second commit, the test is done.
44 if (num_commits_
!= 1)
47 layer_tree_host()->SetNeedsAnimate();
48 // Right now, CommitRequested is going to be true, because during
49 // BeginFrame, we force CommitRequested to true to prevent requests from
50 // hitting the impl thread. But, when the next DidCommit happens, we should
51 // verify that CommitRequested has gone back to false.
54 virtual void DidCommit() OVERRIDE
{
56 EXPECT_FALSE(layer_tree_host()->CommitRequested());
57 layer_tree_host()->SetNeedsAnimate();
58 EXPECT_FALSE(layer_tree_host()->CommitRequested());
61 // Verifies that the SetNeedsAnimate we made in ::Animate did not
62 // trigger CommitRequested.
63 EXPECT_FALSE(layer_tree_host()->CommitRequested());
68 virtual void AfterTest() OVERRIDE
{}
75 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested
);
77 // Trigger a frame with SetNeedsCommit. Then, inside the resulting animate
78 // callback, request another frame using SetNeedsAnimate. End the test when
79 // animate gets called yet-again, indicating that the proxy is correctly
80 // handling the case where SetNeedsAnimate() is called inside the BeginFrame
82 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback
83 : public LayerTreeHostAnimationTest
{
85 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback()
88 virtual void BeginTest() OVERRIDE
{
89 PostSetNeedsCommitToMainThread();
92 virtual void Animate(base::TimeTicks
) OVERRIDE
{
94 layer_tree_host()->SetNeedsAnimate();
101 virtual void AfterTest() OVERRIDE
{}
108 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback
);
110 // Add a layer animation and confirm that
111 // LayerTreeHostImpl::updateAnimationState does get called and continues to
113 class LayerTreeHostAnimationTestAddAnimation
114 : public LayerTreeHostAnimationTest
{
116 LayerTreeHostAnimationTestAddAnimation()
118 received_animation_started_notification_(false),
122 virtual void BeginTest() OVERRIDE
{
123 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer());
126 virtual void UpdateAnimationState(
127 LayerTreeHostImpl
* host_impl
,
128 bool has_unfinished_animation
) OVERRIDE
{
129 if (!num_animates_
) {
130 // The animation had zero duration so LayerTreeHostImpl should no
131 // longer need to animate its layers.
132 EXPECT_FALSE(has_unfinished_animation
);
137 if (received_animation_started_notification_
) {
138 EXPECT_LT(0.0, start_time_
);
140 LayerAnimationController
* controller_impl
=
141 host_impl
->active_tree()->root_layer()->layer_animation_controller();
142 Animation
* animation_impl
=
143 controller_impl
->GetAnimation(Animation::Opacity
);
145 controller_impl
->RemoveAnimation(animation_impl
->id());
151 virtual void NotifyAnimationStarted(double wall_clock_time
) OVERRIDE
{
152 received_animation_started_notification_
= true;
153 start_time_
= wall_clock_time
;
155 EXPECT_LT(0.0, start_time_
);
157 LayerAnimationController
* controller
=
158 layer_tree_host()->root_layer()->layer_animation_controller();
159 Animation
* animation
=
160 controller
->GetAnimation(Animation::Opacity
);
162 controller
->RemoveAnimation(animation
->id());
168 virtual void AfterTest() OVERRIDE
{}
172 bool received_animation_started_notification_
;
176 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation
);
178 // Add a layer animation to a layer, but continually fail to draw. Confirm that
179 // after a while, we do eventually force a draw.
180 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws
181 : public LayerTreeHostAnimationTest
{
183 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws()
184 : started_animating_(false) {}
186 virtual void BeginTest() OVERRIDE
{
187 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
190 virtual void AnimateLayers(
191 LayerTreeHostImpl
* host_impl
,
192 base::TimeTicks monotonic_time
) OVERRIDE
{
193 started_animating_
= true;
196 virtual void DrawLayersOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
197 if (started_animating_
)
201 virtual bool PrepareToDrawOnThread(
202 LayerTreeHostImpl
* host_impl
,
203 LayerTreeHostImpl::FrameData
* frame
,
204 bool result
) OVERRIDE
{
208 virtual void AfterTest() OVERRIDE
{ }
211 bool started_animating_
;
214 // Starvation can only be an issue with the MT compositor.
215 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws
);
217 // Ensures that animations eventually get deleted.
218 class LayerTreeHostAnimationTestAnimationsGetDeleted
219 : public LayerTreeHostAnimationTest
{
221 LayerTreeHostAnimationTestAnimationsGetDeleted()
222 : started_animating_(false) {}
224 virtual void BeginTest() OVERRIDE
{
225 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
228 virtual void AnimateLayers(
229 LayerTreeHostImpl
* host_impl
,
230 base::TimeTicks monotonic_time
) OVERRIDE
{
231 bool have_animations
= !host_impl
->animation_registrar()->
232 active_animation_controllers().empty();
233 if (!started_animating_
&& have_animations
) {
234 started_animating_
= true;
238 if (started_animating_
&& !have_animations
)
242 virtual void NotifyAnimationFinished(double time
) OVERRIDE
{
243 // Animations on the impl-side controller only get deleted during a commit,
244 // so we need to schedule a commit.
245 layer_tree_host()->SetNeedsCommit();
248 virtual void AfterTest() OVERRIDE
{}
251 bool started_animating_
;
254 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAnimationsGetDeleted
);
256 // Ensures that animations continue to be ticked when we are backgrounded.
257 class LayerTreeHostAnimationTestTickAnimationWhileBackgrounded
258 : public LayerTreeHostAnimationTest
{
260 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded()
261 : num_animates_(0) {}
263 virtual void BeginTest() OVERRIDE
{
264 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
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
270 virtual void WillAnimateLayers(
271 LayerTreeHostImpl
* host_impl
,
272 base::TimeTicks monotonic_time
) OVERRIDE
{
273 // Verify that the host can draw, it's just not visible.
274 EXPECT_TRUE(host_impl
->CanDraw());
275 if (num_animates_
< 2) {
276 if (!num_animates_
) {
277 // We have a long animation running. It should continue to tick even
278 // if we are not visible.
279 PostSetVisibleToMainThread(false);
287 virtual void AfterTest() OVERRIDE
{}
293 SINGLE_AND_MULTI_THREAD_TEST_F(
294 LayerTreeHostAnimationTestTickAnimationWhileBackgrounded
);
296 // Ensures that animations do not tick when we are backgrounded and
297 // and we have an empty active tree.
298 class LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree
299 : public LayerTreeHostAnimationTest
{
301 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree()
302 : active_tree_was_animated_(false) {}
304 virtual base::TimeDelta
LowFrequencyAnimationInterval() const OVERRIDE
{
305 return base::TimeDelta::FromMilliseconds(4);
308 virtual void BeginTest() OVERRIDE
{
309 PostAddAnimationToMainThread(layer_tree_host()->root_layer());
312 virtual void NotifyAnimationFinished(double time
) OVERRIDE
{
313 // Replace animated commits with an empty tree.
314 layer_tree_host()->SetRootLayer(make_scoped_refptr
<Layer
>(NULL
));
317 virtual void DidCommit() OVERRIDE
{
318 // This alternates setting an empty tree and a non-empty tree with an
320 switch (layer_tree_host()->source_frame_number()) {
322 // Wait for NotifyAnimationFinished to commit an empty tree.
326 AddOpacityTransitionToLayer(
327 layer_tree_host()->root_layer(), 0.000001, 0, 0.5, true);
330 // Wait for NotifyAnimationFinished to commit an empty tree.
338 virtual void BeginCommitOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
339 // At the start of every commit, block activations and make sure
340 // we are backgrounded.
341 host_impl
->BlockNotifyReadyToActivateForTesting(true);
342 PostSetVisibleToMainThread(false);
345 virtual void CommitCompleteOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
346 if (!host_impl
->settings().impl_side_painting
) {
347 // There are no activations to block if we're not impl-side-painting,
348 // so just advance the test immediately.
349 if (host_impl
->active_tree()->source_frame_number() < 3)
350 UnblockActivations(host_impl
);
354 // We block activation for several ticks to make sure that, even though
355 // there is a pending tree with animations, we still do not background
356 // tick if the active tree is empty.
357 if (host_impl
->pending_tree()->source_frame_number() < 3) {
358 base::MessageLoopProxy::current()->PostDelayedTask(
361 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree::
363 base::Unretained(this),
365 4 * LowFrequencyAnimationInterval());
369 virtual void UnblockActivations(LayerTreeHostImpl
* host_impl
) {
370 host_impl
->BlockNotifyReadyToActivateForTesting(false);
373 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
374 active_tree_was_animated_
= false;
376 // Verify that commits are actually alternating with empty / non-empty
378 switch (host_impl
->active_tree()->source_frame_number()) {
381 EXPECT_TRUE(host_impl
->active_tree()->root_layer());
385 EXPECT_FALSE(host_impl
->active_tree()->root_layer());
389 if (host_impl
->active_tree()->source_frame_number() < 3) {
390 // Initiate the next commit after a delay to give us a chance to
391 // background tick if the active tree isn't empty.
392 base::MessageLoopProxy::current()->PostDelayedTask(
395 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree::
397 base::Unretained(this),
399 4 * LowFrequencyAnimationInterval());
403 virtual void WillAnimateLayers(LayerTreeHostImpl
* host_impl
,
404 base::TimeTicks monotonic_time
) OVERRIDE
{
405 EXPECT_TRUE(host_impl
->active_tree()->root_layer());
406 active_tree_was_animated_
= true;
409 void InitiateNextCommit(LayerTreeHostImpl
* host_impl
) {
410 // Verify that we actually animated when we should have.
411 bool has_active_tree
= host_impl
->active_tree()->root_layer();
412 EXPECT_EQ(has_active_tree
, active_tree_was_animated_
);
414 // The next commit is blocked until we become visible again.
415 PostSetVisibleToMainThread(true);
418 virtual void AfterTest() OVERRIDE
{}
420 bool active_tree_was_animated_
;
423 SINGLE_AND_MULTI_THREAD_TEST_F(
424 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree
);
426 // Ensure that an animation's timing function is respected.
427 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction
428 : public LayerTreeHostAnimationTest
{
430 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {}
432 virtual void SetupTree() OVERRIDE
{
433 LayerTreeHostAnimationTest::SetupTree();
434 content_
= FakeContentLayer::Create(&client_
);
435 content_
->SetBounds(gfx::Size(4, 4));
436 layer_tree_host()->root_layer()->AddChild(content_
);
439 virtual void BeginTest() OVERRIDE
{
440 PostAddAnimationToMainThread(content_
.get());
443 virtual void AnimateLayers(
444 LayerTreeHostImpl
* host_impl
,
445 base::TimeTicks monotonic_time
) OVERRIDE
{
446 LayerAnimationController
* controller_impl
=
447 host_impl
->active_tree()->root_layer()->children()[0]->
448 layer_animation_controller();
449 Animation
* animation
=
450 controller_impl
->GetAnimation(Animation::Opacity
);
454 const FloatAnimationCurve
* curve
=
455 animation
->curve()->ToFloatAnimationCurve();
456 float start_opacity
= curve
->GetValue(0.0);
457 float end_opacity
= curve
->GetValue(curve
->Duration());
458 float linearly_interpolated_opacity
=
459 0.25f
* end_opacity
+ 0.75f
* start_opacity
;
460 double time
= curve
->Duration() * 0.25;
461 // If the linear timing function associated with this animation was not
462 // picked up, then the linearly interpolated opacity would be different
463 // because of the default ease timing function.
464 EXPECT_FLOAT_EQ(linearly_interpolated_opacity
, curve
->GetValue(time
));
469 virtual void AfterTest() OVERRIDE
{}
471 FakeContentLayerClient client_
;
472 scoped_refptr
<FakeContentLayer
> content_
;
475 SINGLE_AND_MULTI_THREAD_TEST_F(
476 LayerTreeHostAnimationTestAddAnimationWithTimingFunction
);
478 // Ensures that main thread animations have their start times synchronized with
479 // impl thread animations.
480 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes
481 : public LayerTreeHostAnimationTest
{
483 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes()
484 : main_start_time_(-1.0),
485 impl_start_time_(-1.0) {}
487 virtual void SetupTree() OVERRIDE
{
488 LayerTreeHostAnimationTest::SetupTree();
489 content_
= FakeContentLayer::Create(&client_
);
490 content_
->SetBounds(gfx::Size(4, 4));
491 content_
->set_layer_animation_delegate(this);
492 layer_tree_host()->root_layer()->AddChild(content_
);
495 virtual void BeginTest() OVERRIDE
{
496 PostAddAnimationToMainThread(content_
.get());
499 virtual void NotifyAnimationStarted(double time
) OVERRIDE
{
500 LayerAnimationController
* controller
=
501 layer_tree_host()->root_layer()->children()[0]->
502 layer_animation_controller();
503 Animation
* animation
=
504 controller
->GetAnimation(Animation::Opacity
);
505 main_start_time_
= animation
->start_time();
506 controller
->RemoveAnimation(animation
->id());
508 if (impl_start_time_
> 0.0)
512 virtual void UpdateAnimationState(
513 LayerTreeHostImpl
* impl_host
,
514 bool has_unfinished_animation
) OVERRIDE
{
515 LayerAnimationController
* controller
=
516 impl_host
->active_tree()->root_layer()->children()[0]->
517 layer_animation_controller();
518 Animation
* animation
=
519 controller
->GetAnimation(Animation::Opacity
);
523 impl_start_time_
= animation
->start_time();
524 controller
->RemoveAnimation(animation
->id());
526 if (main_start_time_
> 0.0)
530 virtual void AfterTest() OVERRIDE
{
531 EXPECT_FLOAT_EQ(impl_start_time_
, main_start_time_
);
535 double main_start_time_
;
536 double impl_start_time_
;
537 FakeContentLayerClient client_
;
538 scoped_refptr
<FakeContentLayer
> content_
;
541 SINGLE_AND_MULTI_THREAD_TEST_F(
542 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes
);
544 // Ensures that notify animation finished is called.
545 class LayerTreeHostAnimationTestAnimationFinishedEvents
546 : public LayerTreeHostAnimationTest
{
548 LayerTreeHostAnimationTestAnimationFinishedEvents() {}
550 virtual void BeginTest() OVERRIDE
{
551 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer());
554 virtual void NotifyAnimationFinished(double time
) OVERRIDE
{
555 LayerAnimationController
* controller
=
556 layer_tree_host()->root_layer()->layer_animation_controller();
557 Animation
* animation
=
558 controller
->GetAnimation(Animation::Opacity
);
560 controller
->RemoveAnimation(animation
->id());
564 virtual void AfterTest() OVERRIDE
{}
567 SINGLE_AND_MULTI_THREAD_TEST_F(
568 LayerTreeHostAnimationTestAnimationFinishedEvents
);
570 // Ensures that when opacity is being animated, this value does not cause the
571 // subtree to be skipped.
572 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity
573 : public LayerTreeHostAnimationTest
{
575 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity()
576 : update_check_layer_(FakeContentLayer::Create(&client_
)) {
579 virtual void SetupTree() OVERRIDE
{
580 update_check_layer_
->SetOpacity(0.f
);
581 layer_tree_host()->SetRootLayer(update_check_layer_
);
582 LayerTreeHostAnimationTest::SetupTree();
585 virtual void BeginTest() OVERRIDE
{
586 PostAddAnimationToMainThread(update_check_layer_
.get());
589 virtual void DidActivateTreeOnThread(LayerTreeHostImpl
* host_impl
) OVERRIDE
{
590 LayerAnimationController
* controller_impl
=
591 host_impl
->active_tree()->root_layer()->layer_animation_controller();
592 Animation
* animation_impl
=
593 controller_impl
->GetAnimation(Animation::Opacity
);
594 controller_impl
->RemoveAnimation(animation_impl
->id());
598 virtual void AfterTest() OVERRIDE
{
599 // Update() should have been called once, proving that the layer was not
601 EXPECT_EQ(1u, update_check_layer_
->update_count());
603 // clear update_check_layer_ so LayerTreeHost dies.
604 update_check_layer_
= NULL
;
608 FakeContentLayerClient client_
;
609 scoped_refptr
<FakeContentLayer
> update_check_layer_
;
612 SINGLE_AND_MULTI_THREAD_TEST_F(
613 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity
);
615 // Layers added to tree with existing active animations should have the
616 // animation correctly recognized.
617 class LayerTreeHostAnimationTestLayerAddedWithAnimation
618 : public LayerTreeHostAnimationTest
{
620 LayerTreeHostAnimationTestLayerAddedWithAnimation() {}
622 virtual void BeginTest() OVERRIDE
{
623 PostSetNeedsCommitToMainThread();
626 virtual void DidCommit() OVERRIDE
{
627 if (layer_tree_host()->source_frame_number() == 1) {
628 scoped_refptr
<Layer
> layer
= Layer::Create();
629 layer
->set_layer_animation_delegate(this);
631 // Any valid AnimationCurve will do here.
632 scoped_ptr
<AnimationCurve
> curve(EaseTimingFunction::Create());
633 scoped_ptr
<Animation
> animation(
634 Animation::Create(curve
.Pass(), 1, 1,
635 Animation::Opacity
));
636 layer
->layer_animation_controller()->AddAnimation(animation
.Pass());
638 // We add the animation *before* attaching the layer to the tree.
639 layer_tree_host()->root_layer()->AddChild(layer
);
643 virtual void AnimateLayers(
644 LayerTreeHostImpl
* impl_host
,
645 base::TimeTicks monotonic_time
) OVERRIDE
{
649 virtual void AfterTest() OVERRIDE
{}
652 SINGLE_AND_MULTI_THREAD_TEST_F(
653 LayerTreeHostAnimationTestLayerAddedWithAnimation
);
655 class LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount
656 : public LayerTreeHostAnimationTest
{
658 LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount()
659 : animated_commit_(-1) {
662 virtual void Animate(base::TimeTicks
) OVERRIDE
{
663 // We shouldn't animate on the CompositeAndReadback-forced commit, but we
664 // should for the SetNeedsCommit-triggered commit.
665 animated_commit_
= layer_tree_host()->source_frame_number();
666 EXPECT_NE(2, animated_commit_
);
669 virtual void BeginTest() OVERRIDE
{
670 PostSetNeedsCommitToMainThread();
673 virtual void DidCommit() OVERRIDE
{
674 switch (layer_tree_host()->source_frame_number()) {
676 layer_tree_host()->SetNeedsCommit();
680 layer_tree_host()->CompositeAndReadback(&pixels
, gfx::Rect(0, 0, 1, 1));
684 // This is finishing the readback's commit.
687 // This is finishing the followup commit.
695 virtual void AfterTest() OVERRIDE
{
696 EXPECT_EQ(3, animated_commit_
);
700 int animated_commit_
;
703 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount
);
705 class LayerTreeHostAnimationTestContinuousAnimate
706 : public LayerTreeHostAnimationTest
{
708 LayerTreeHostAnimationTestContinuousAnimate()
709 : num_commit_complete_(0),
710 num_draw_layers_(0) {
713 virtual void BeginTest() OVERRIDE
{
714 PostSetNeedsCommitToMainThread();
717 virtual void Animate(base::TimeTicks
) OVERRIDE
{
718 if (num_draw_layers_
== 2)
720 layer_tree_host()->SetNeedsAnimate();
723 virtual void Layout() OVERRIDE
{
724 layer_tree_host()->root_layer()->SetNeedsDisplay();
727 virtual void CommitCompleteOnThread(LayerTreeHostImpl
* tree_impl
) OVERRIDE
{
728 if (num_draw_layers_
== 1)
729 num_commit_complete_
++;
732 virtual void DrawLayersOnThread(LayerTreeHostImpl
* impl
) OVERRIDE
{
734 if (num_draw_layers_
== 2)
738 virtual void AfterTest() OVERRIDE
{
739 // Check that we didn't commit twice between first and second draw.
740 EXPECT_EQ(1, num_commit_complete_
);
744 int num_commit_complete_
;
745 int num_draw_layers_
;
748 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate
);
750 // Make sure the main thread can still execute animations when CanDraw() is not
752 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw
753 : public LayerTreeHostAnimationTest
{
755 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {}
757 virtual void SetupTree() OVERRIDE
{
758 LayerTreeHostAnimationTest::SetupTree();
759 content_
= FakeContentLayer::Create(&client_
);
760 content_
->SetBounds(gfx::Size(4, 4));
761 content_
->set_layer_animation_delegate(this);
762 layer_tree_host()->root_layer()->AddChild(content_
);
765 virtual void BeginTest() OVERRIDE
{
766 layer_tree_host()->SetViewportSize(gfx::Size());
767 PostAddAnimationToMainThread(content_
.get());
770 virtual void NotifyAnimationStarted(double wall_clock_time
) OVERRIDE
{
774 virtual void NotifyAnimationFinished(double wall_clock_time
) OVERRIDE
{
778 virtual void AfterTest() OVERRIDE
{
779 EXPECT_EQ(1, started_times_
);
784 FakeContentLayerClient client_
;
785 scoped_refptr
<FakeContentLayer
> content_
;
788 SINGLE_AND_MULTI_THREAD_TEST_F(
789 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw
);
791 // Make sure the main thread can still execute animations when the renderer is
793 class LayerTreeHostAnimationTestRunAnimationWhenNotVisible
794 : public LayerTreeHostAnimationTest
{
796 LayerTreeHostAnimationTestRunAnimationWhenNotVisible() : started_times_(0) {}
798 virtual void SetupTree() OVERRIDE
{
799 LayerTreeHostAnimationTest::SetupTree();
800 content_
= FakeContentLayer::Create(&client_
);
801 content_
->SetBounds(gfx::Size(4, 4));
802 content_
->set_layer_animation_delegate(this);
803 layer_tree_host()->root_layer()->AddChild(content_
);
806 virtual void BeginTest() OVERRIDE
{
808 PostAddAnimationToMainThread(content_
.get());
811 virtual void DidCommit() OVERRIDE
{
813 layer_tree_host()->SetVisible(false);
816 virtual void NotifyAnimationStarted(double wall_clock_time
) OVERRIDE
{
817 EXPECT_FALSE(visible_
);
821 virtual void NotifyAnimationFinished(double wall_clock_time
) OVERRIDE
{
822 EXPECT_FALSE(visible_
);
823 EXPECT_EQ(1, started_times_
);
827 virtual void AfterTest() OVERRIDE
{}
832 FakeContentLayerClient client_
;
833 scoped_refptr
<FakeContentLayer
> content_
;
836 SINGLE_AND_MULTI_THREAD_TEST_F(
837 LayerTreeHostAnimationTestRunAnimationWhenNotVisible
);
839 // Animations should not be started when frames are being skipped due to
841 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations
842 : public LayerTreeHostAnimationTest
{
843 virtual void SetupTree() OVERRIDE
{
844 LayerTreeHostAnimationTest::SetupTree();
845 content_
= FakeContentLayer::Create(&client_
);
846 content_
->SetBounds(gfx::Size(4, 4));
847 content_
->set_layer_animation_delegate(this);
848 layer_tree_host()->root_layer()->AddChild(content_
);
851 virtual void InitializeSettings(LayerTreeSettings
* settings
) OVERRIDE
{
852 // Make sure that drawing many times doesn't cause a checkerboarded
853 // animation to start so we avoid flake in this test.
854 settings
->timeout_and_draw_when_animation_checkerboards
= false;
857 virtual void BeginTest() OVERRIDE
{
859 added_animations_
= 0;
863 PostSetNeedsCommitToMainThread();
866 virtual void DispatchAddInstantAnimation(Layer
* layer_to_receive_animation
)
868 LayerTreeHostAnimationTest::DispatchAddInstantAnimation(
869 layer_to_receive_animation
);
873 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl
* host_impl
,
874 LayerTreeHostImpl::FrameData
* frame_data
,
875 bool result
) OVERRIDE
{
876 if (added_animations_
< 2)
880 // Act like there is checkerboard when the second animation wants to draw.
885 virtual void DidCommitAndDrawFrame() OVERRIDE
{
886 switch (layer_tree_host()->source_frame_number()) {
888 // The animation is longer than 1 BeginFrame interval.
889 AddOpacityTransitionToLayer(content_
.get(), 0.1, 0.2f
, 0.8f
, false);
893 // This second animation will not be drawn so it should not start.
894 AddAnimatedTransformToLayer(content_
.get(), 0.1, 5, 5);
900 virtual void NotifyAnimationStarted(double wall_clock_time
) OVERRIDE
{
906 virtual void NotifyAnimationFinished(double wall_clock_time
) OVERRIDE
{
907 // We should be checkerboarding already, but it should still finish the
909 EXPECT_EQ(2, added_animations_
);
914 virtual void AfterTest() OVERRIDE
{
915 // Make sure we tried to draw the second animation but failed.
916 EXPECT_LT(0, prevented_draw_
);
917 // The first animation should be started, but the second should not because
919 EXPECT_EQ(1, started_times_
);
920 // The first animation should still be finished.
921 EXPECT_EQ(1, finished_times_
);
925 int added_animations_
;
928 FakeContentLayerClient client_
;
929 scoped_refptr
<FakeContentLayer
> content_
;
933 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations
);