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 int frame_number = host_impl->active_tree()->source_frame_number();
379 switch (frame_number) {
382 EXPECT_TRUE(host_impl->active_tree()->root_layer())
383 << "frame: " << frame_number;
387 EXPECT_FALSE(host_impl->active_tree()->root_layer())
388 << "frame: " << frame_number;
392 if (host_impl->active_tree()->source_frame_number() < 3) {
393 // Initiate the next commit after a delay to give us a chance to
394 // background tick if the active tree isn't empty.
395 base::MessageLoopProxy::current()->PostDelayedTask(
398 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree::
400 base::Unretained(this),
402 4 * LowFrequencyAnimationInterval());
406 virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl,
407 base::TimeTicks monotonic_time) OVERRIDE {
408 EXPECT_TRUE(host_impl->active_tree()->root_layer());
409 active_tree_was_animated_ = true;
412 void InitiateNextCommit(LayerTreeHostImpl* host_impl) {
413 // Verify that we actually animated when we should have.
414 bool has_active_tree = host_impl->active_tree()->root_layer();
415 EXPECT_EQ(has_active_tree, active_tree_was_animated_);
417 // The next commit is blocked until we become visible again.
418 PostSetVisibleToMainThread(true);
421 virtual void AfterTest() OVERRIDE {}
423 bool active_tree_was_animated_;
426 SINGLE_AND_MULTI_THREAD_TEST_F(
427 LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree);
429 // Ensure that an animation's timing function is respected.
430 class LayerTreeHostAnimationTestAddAnimationWithTimingFunction
431 : public LayerTreeHostAnimationTest {
433 LayerTreeHostAnimationTestAddAnimationWithTimingFunction() {}
435 virtual void SetupTree() OVERRIDE {
436 LayerTreeHostAnimationTest::SetupTree();
437 content_ = FakeContentLayer::Create(&client_);
438 content_->SetBounds(gfx::Size(4, 4));
439 layer_tree_host()->root_layer()->AddChild(content_);
442 virtual void BeginTest() OVERRIDE {
443 PostAddAnimationToMainThread(content_.get());
446 virtual void AnimateLayers(
447 LayerTreeHostImpl* host_impl,
448 base::TimeTicks monotonic_time) OVERRIDE {
449 LayerAnimationController* controller_impl =
450 host_impl->active_tree()->root_layer()->children()[0]->
451 layer_animation_controller();
452 Animation* animation =
453 controller_impl->GetAnimation(Animation::Opacity);
457 const FloatAnimationCurve* curve =
458 animation->curve()->ToFloatAnimationCurve();
459 float start_opacity = curve->GetValue(0.0);
460 float end_opacity = curve->GetValue(curve->Duration());
461 float linearly_interpolated_opacity =
462 0.25f * end_opacity + 0.75f * start_opacity;
463 double time = curve->Duration() * 0.25;
464 // If the linear timing function associated with this animation was not
465 // picked up, then the linearly interpolated opacity would be different
466 // because of the default ease timing function.
467 EXPECT_FLOAT_EQ(linearly_interpolated_opacity, curve->GetValue(time));
472 virtual void AfterTest() OVERRIDE {}
474 FakeContentLayerClient client_;
475 scoped_refptr<FakeContentLayer> content_;
478 SINGLE_AND_MULTI_THREAD_TEST_F(
479 LayerTreeHostAnimationTestAddAnimationWithTimingFunction);
481 // Ensures that main thread animations have their start times synchronized with
482 // impl thread animations.
483 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes
484 : public LayerTreeHostAnimationTest {
486 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes()
487 : main_start_time_(-1.0),
488 impl_start_time_(-1.0) {}
490 virtual void SetupTree() OVERRIDE {
491 LayerTreeHostAnimationTest::SetupTree();
492 content_ = FakeContentLayer::Create(&client_);
493 content_->SetBounds(gfx::Size(4, 4));
494 content_->set_layer_animation_delegate(this);
495 layer_tree_host()->root_layer()->AddChild(content_);
498 virtual void BeginTest() OVERRIDE {
499 PostAddAnimationToMainThread(content_.get());
502 virtual void NotifyAnimationStarted(double time) OVERRIDE {
503 LayerAnimationController* controller =
504 layer_tree_host()->root_layer()->children()[0]->
505 layer_animation_controller();
506 Animation* animation =
507 controller->GetAnimation(Animation::Opacity);
508 main_start_time_ = animation->start_time();
509 controller->RemoveAnimation(animation->id());
511 if (impl_start_time_ > 0.0)
515 virtual void UpdateAnimationState(
516 LayerTreeHostImpl* impl_host,
517 bool has_unfinished_animation) OVERRIDE {
518 LayerAnimationController* controller =
519 impl_host->active_tree()->root_layer()->children()[0]->
520 layer_animation_controller();
521 Animation* animation =
522 controller->GetAnimation(Animation::Opacity);
526 impl_start_time_ = animation->start_time();
527 controller->RemoveAnimation(animation->id());
529 if (main_start_time_ > 0.0)
533 virtual void AfterTest() OVERRIDE {
534 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_);
538 double main_start_time_;
539 double impl_start_time_;
540 FakeContentLayerClient client_;
541 scoped_refptr<FakeContentLayer> content_;
544 SINGLE_AND_MULTI_THREAD_TEST_F(
545 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes);
547 // Ensures that notify animation finished is called.
548 class LayerTreeHostAnimationTestAnimationFinishedEvents
549 : public LayerTreeHostAnimationTest {
551 LayerTreeHostAnimationTestAnimationFinishedEvents() {}
553 virtual void BeginTest() OVERRIDE {
554 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer());
557 virtual void NotifyAnimationFinished(double time) OVERRIDE {
558 LayerAnimationController* controller =
559 layer_tree_host()->root_layer()->layer_animation_controller();
560 Animation* animation =
561 controller->GetAnimation(Animation::Opacity);
563 controller->RemoveAnimation(animation->id());
567 virtual void AfterTest() OVERRIDE {}
570 SINGLE_AND_MULTI_THREAD_TEST_F(
571 LayerTreeHostAnimationTestAnimationFinishedEvents);
573 // Ensures that when opacity is being animated, this value does not cause the
574 // subtree to be skipped.
575 class LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity
576 : public LayerTreeHostAnimationTest {
578 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity()
579 : update_check_layer_(FakeContentLayer::Create(&client_)) {
582 virtual void SetupTree() OVERRIDE {
583 update_check_layer_->SetOpacity(0.f);
584 layer_tree_host()->SetRootLayer(update_check_layer_);
585 LayerTreeHostAnimationTest::SetupTree();
588 virtual void BeginTest() OVERRIDE {
589 PostAddAnimationToMainThread(update_check_layer_.get());
592 virtual void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) OVERRIDE {
593 LayerAnimationController* controller_impl =
594 host_impl->active_tree()->root_layer()->layer_animation_controller();
595 Animation* animation_impl =
596 controller_impl->GetAnimation(Animation::Opacity);
597 controller_impl->RemoveAnimation(animation_impl->id());
601 virtual void AfterTest() OVERRIDE {
602 // Update() should have been called once, proving that the layer was not
604 EXPECT_EQ(1u, update_check_layer_->update_count());
606 // clear update_check_layer_ so LayerTreeHost dies.
607 update_check_layer_ = NULL;
611 FakeContentLayerClient client_;
612 scoped_refptr<FakeContentLayer> update_check_layer_;
615 SINGLE_AND_MULTI_THREAD_TEST_F(
616 LayerTreeHostAnimationTestDoNotSkipLayersWithAnimatedOpacity);
618 // Layers added to tree with existing active animations should have the
619 // animation correctly recognized.
620 class LayerTreeHostAnimationTestLayerAddedWithAnimation
621 : public LayerTreeHostAnimationTest {
623 LayerTreeHostAnimationTestLayerAddedWithAnimation() {}
625 virtual void BeginTest() OVERRIDE {
626 PostSetNeedsCommitToMainThread();
629 virtual void DidCommit() OVERRIDE {
630 if (layer_tree_host()->source_frame_number() == 1) {
631 scoped_refptr<Layer> layer = Layer::Create();
632 layer->set_layer_animation_delegate(this);
634 // Any valid AnimationCurve will do here.
635 scoped_ptr<AnimationCurve> curve(EaseTimingFunction::Create());
636 scoped_ptr<Animation> animation(
637 Animation::Create(curve.Pass(), 1, 1,
638 Animation::Opacity));
639 layer->layer_animation_controller()->AddAnimation(animation.Pass());
641 // We add the animation *before* attaching the layer to the tree.
642 layer_tree_host()->root_layer()->AddChild(layer);
646 virtual void AnimateLayers(
647 LayerTreeHostImpl* impl_host,
648 base::TimeTicks monotonic_time) OVERRIDE {
652 virtual void AfterTest() OVERRIDE {}
655 SINGLE_AND_MULTI_THREAD_TEST_F(
656 LayerTreeHostAnimationTestLayerAddedWithAnimation);
658 class LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount
659 : public LayerTreeHostAnimationTest {
661 LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount()
662 : animated_commit_(-1) {
665 virtual void Animate(base::TimeTicks) OVERRIDE {
666 // We shouldn't animate on the CompositeAndReadback-forced commit, but we
667 // should for the SetNeedsCommit-triggered commit.
668 animated_commit_ = layer_tree_host()->source_frame_number();
669 EXPECT_NE(2, animated_commit_);
672 virtual void BeginTest() OVERRIDE {
673 PostSetNeedsCommitToMainThread();
676 virtual void DidCommit() OVERRIDE {
677 switch (layer_tree_host()->source_frame_number()) {
679 layer_tree_host()->SetNeedsCommit();
683 layer_tree_host()->CompositeAndReadback(&pixels, gfx::Rect(0, 0, 1, 1));
687 // This is finishing the readback's commit.
690 // This is finishing the followup commit.
698 virtual void AfterTest() OVERRIDE {
699 EXPECT_EQ(3, animated_commit_);
703 int animated_commit_;
706 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount);
708 class LayerTreeHostAnimationTestContinuousAnimate
709 : public LayerTreeHostAnimationTest {
711 LayerTreeHostAnimationTestContinuousAnimate()
712 : num_commit_complete_(0),
713 num_draw_layers_(0) {
716 virtual void BeginTest() OVERRIDE {
717 PostSetNeedsCommitToMainThread();
720 virtual void Animate(base::TimeTicks) OVERRIDE {
721 if (num_draw_layers_ == 2)
723 layer_tree_host()->SetNeedsAnimate();
726 virtual void Layout() OVERRIDE {
727 layer_tree_host()->root_layer()->SetNeedsDisplay();
730 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE {
731 if (num_draw_layers_ == 1)
732 num_commit_complete_++;
735 virtual void DrawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE {
737 if (num_draw_layers_ == 2)
741 virtual void AfterTest() OVERRIDE {
742 // Check that we didn't commit twice between first and second draw.
743 EXPECT_EQ(1, num_commit_complete_);
747 int num_commit_complete_;
748 int num_draw_layers_;
751 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestContinuousAnimate);
753 // Make sure the main thread can still execute animations when CanDraw() is not
755 class LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw
756 : public LayerTreeHostAnimationTest {
758 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw() : started_times_(0) {}
760 virtual void SetupTree() OVERRIDE {
761 LayerTreeHostAnimationTest::SetupTree();
762 content_ = FakeContentLayer::Create(&client_);
763 content_->SetBounds(gfx::Size(4, 4));
764 content_->set_layer_animation_delegate(this);
765 layer_tree_host()->root_layer()->AddChild(content_);
768 virtual void BeginTest() OVERRIDE {
769 layer_tree_host()->SetViewportSize(gfx::Size());
770 PostAddAnimationToMainThread(content_.get());
773 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE {
777 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE {
781 virtual void AfterTest() OVERRIDE {
782 EXPECT_EQ(1, started_times_);
787 FakeContentLayerClient client_;
788 scoped_refptr<FakeContentLayer> content_;
791 SINGLE_AND_MULTI_THREAD_TEST_F(
792 LayerTreeHostAnimationTestRunAnimationWhenNotCanDraw);
794 // Make sure the main thread can still execute animations when the renderer is
796 class LayerTreeHostAnimationTestRunAnimationWhenNotVisible
797 : public LayerTreeHostAnimationTest {
799 LayerTreeHostAnimationTestRunAnimationWhenNotVisible() : started_times_(0) {}
801 virtual void SetupTree() OVERRIDE {
802 LayerTreeHostAnimationTest::SetupTree();
803 content_ = FakeContentLayer::Create(&client_);
804 content_->SetBounds(gfx::Size(4, 4));
805 content_->set_layer_animation_delegate(this);
806 layer_tree_host()->root_layer()->AddChild(content_);
809 virtual void BeginTest() OVERRIDE {
811 PostAddAnimationToMainThread(content_.get());
814 virtual void DidCommit() OVERRIDE {
816 layer_tree_host()->SetVisible(false);
819 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE {
820 EXPECT_FALSE(visible_);
824 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE {
825 EXPECT_FALSE(visible_);
826 EXPECT_EQ(1, started_times_);
830 virtual void AfterTest() OVERRIDE {}
835 FakeContentLayerClient client_;
836 scoped_refptr<FakeContentLayer> content_;
839 SINGLE_AND_MULTI_THREAD_TEST_F(
840 LayerTreeHostAnimationTestRunAnimationWhenNotVisible);
842 // Animations should not be started when frames are being skipped due to
844 class LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations
845 : public LayerTreeHostAnimationTest {
846 virtual void SetupTree() OVERRIDE {
847 LayerTreeHostAnimationTest::SetupTree();
848 content_ = FakeContentLayer::Create(&client_);
849 content_->SetBounds(gfx::Size(4, 4));
850 content_->set_layer_animation_delegate(this);
851 layer_tree_host()->root_layer()->AddChild(content_);
854 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE {
855 // Make sure that drawing many times doesn't cause a checkerboarded
856 // animation to start so we avoid flake in this test.
857 settings->timeout_and_draw_when_animation_checkerboards = false;
860 virtual void BeginTest() OVERRIDE {
862 added_animations_ = 0;
866 PostSetNeedsCommitToMainThread();
869 virtual void DispatchAddInstantAnimation(Layer* layer_to_receive_animation)
871 LayerTreeHostAnimationTest::DispatchAddInstantAnimation(
872 layer_to_receive_animation);
876 virtual bool PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
877 LayerTreeHostImpl::FrameData* frame_data,
878 bool result) OVERRIDE {
879 if (added_animations_ < 2)
883 // Act like there is checkerboard when the second animation wants to draw.
888 virtual void DidCommitAndDrawFrame() OVERRIDE {
889 switch (layer_tree_host()->source_frame_number()) {
891 // The animation is longer than 1 BeginFrame interval.
892 AddOpacityTransitionToLayer(content_.get(), 0.1, 0.2f, 0.8f, false);
896 // This second animation will not be drawn so it should not start.
897 AddAnimatedTransformToLayer(content_.get(), 0.1, 5, 5);
903 virtual void NotifyAnimationStarted(double wall_clock_time) OVERRIDE {
909 virtual void NotifyAnimationFinished(double wall_clock_time) OVERRIDE {
910 // We should be checkerboarding already, but it should still finish the
912 EXPECT_EQ(2, added_animations_);
917 virtual void AfterTest() OVERRIDE {
918 // Make sure we tried to draw the second animation but failed.
919 EXPECT_LT(0, prevented_draw_);
920 // The first animation should be started, but the second should not because
922 EXPECT_EQ(1, started_times_);
923 // The first animation should still be finished.
924 EXPECT_EQ(1, finished_times_);
928 int added_animations_;
931 FakeContentLayerClient client_;
932 scoped_refptr<FakeContentLayer> content_;
936 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations);