| 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" |
| 11 #include "cc/layers/layer_impl.h" | 11 #include "cc/layers/layer_impl.h" |
| 12 #include "cc/test/animation_test_common.h" | 12 #include "cc/test/animation_test_common.h" |
| 13 #include "cc/test/fake_content_layer.h" | 13 #include "cc/test/fake_content_layer.h" |
| 14 #include "cc/test/fake_content_layer_client.h" | 14 #include "cc/test/fake_content_layer_client.h" |
| 15 #include "cc/test/layer_tree_test.h" | 15 #include "cc/test/layer_tree_test.h" |
| 16 #include "cc/trees/layer_tree_impl.h" | 16 #include "cc/trees/layer_tree_impl.h" |
| 17 #include "ui/gfx/frame_time.h" |
| 17 | 18 |
| 18 namespace cc { | 19 namespace cc { |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 class LayerTreeHostAnimationTest : public LayerTreeTest { | 22 class LayerTreeHostAnimationTest : public LayerTreeTest { |
| 22 public: | 23 public: |
| 23 virtual void SetupTree() OVERRIDE { | 24 virtual void SetupTree() OVERRIDE { |
| 24 LayerTreeTest::SetupTree(); | 25 LayerTreeTest::SetupTree(); |
| 25 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); | 26 layer_tree_host()->root_layer()->set_layer_animation_delegate(this); |
| 26 } | 27 } |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to | 30 // Makes sure that SetNeedsAnimate does not cause the CommitRequested() state to |
| 30 // be set. | 31 // be set. |
| 31 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested | 32 class LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested |
| 32 : public LayerTreeHostAnimationTest { | 33 : public LayerTreeHostAnimationTest { |
| 33 public: | 34 public: |
| 34 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() | 35 LayerTreeHostAnimationTestSetNeedsAnimateShouldNotSetCommitRequested() |
| 35 : num_commits_(0) {} | 36 : num_commits_(0) {} |
| 36 | 37 |
| 37 virtual void BeginTest() OVERRIDE { | 38 virtual void BeginTest() OVERRIDE { |
| 38 PostSetNeedsCommitToMainThread(); | 39 PostSetNeedsCommitToMainThread(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 virtual void Animate(base::TimeTicks monotonic_time) OVERRIDE { | 42 virtual void Animate(gfx::FrameTime monotonic_time) OVERRIDE { |
| 42 // We skip the first commit becasue its the commit that populates the | 43 // 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 // impl thread with a tree. After the second commit, the test is done. |
| 44 if (num_commits_ != 1) | 45 if (num_commits_ != 1) |
| 45 return; | 46 return; |
| 46 | 47 |
| 47 layer_tree_host()->SetNeedsAnimate(); | 48 layer_tree_host()->SetNeedsAnimate(); |
| 48 // Right now, CommitRequested is going to be true, because during | 49 // Right now, CommitRequested is going to be true, because during |
| 49 // BeginFrame, we force CommitRequested to true to prevent requests from | 50 // BeginFrame, we force CommitRequested to true to prevent requests from |
| 50 // hitting the impl thread. But, when the next DidCommit happens, we should | 51 // hitting the impl thread. But, when the next DidCommit happens, we should |
| 51 // verify that CommitRequested has gone back to false. | 52 // verify that CommitRequested has gone back to false. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 82 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback | 83 class LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback |
| 83 : public LayerTreeHostAnimationTest { | 84 : public LayerTreeHostAnimationTest { |
| 84 public: | 85 public: |
| 85 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() | 86 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback() |
| 86 : num_animates_(0) {} | 87 : num_animates_(0) {} |
| 87 | 88 |
| 88 virtual void BeginTest() OVERRIDE { | 89 virtual void BeginTest() OVERRIDE { |
| 89 PostSetNeedsCommitToMainThread(); | 90 PostSetNeedsCommitToMainThread(); |
| 90 } | 91 } |
| 91 | 92 |
| 92 virtual void Animate(base::TimeTicks) OVERRIDE { | 93 virtual void Animate(gfx::FrameTime) OVERRIDE { |
| 93 if (!num_animates_) { | 94 if (!num_animates_) { |
| 94 layer_tree_host()->SetNeedsAnimate(); | 95 layer_tree_host()->SetNeedsAnimate(); |
| 95 num_animates_++; | 96 num_animates_++; |
| 96 return; | 97 return; |
| 97 } | 98 } |
| 98 EndTest(); | 99 EndTest(); |
| 99 } | 100 } |
| 100 | 101 |
| 101 virtual void AfterTest() OVERRIDE {} | 102 virtual void AfterTest() OVERRIDE {} |
| 102 | 103 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 public: | 183 public: |
| 183 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() | 184 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() |
| 184 : started_animating_(false) {} | 185 : started_animating_(false) {} |
| 185 | 186 |
| 186 virtual void BeginTest() OVERRIDE { | 187 virtual void BeginTest() OVERRIDE { |
| 187 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 188 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
| 188 } | 189 } |
| 189 | 190 |
| 190 virtual void AnimateLayers( | 191 virtual void AnimateLayers( |
| 191 LayerTreeHostImpl* host_impl, | 192 LayerTreeHostImpl* host_impl, |
| 192 base::TimeTicks monotonic_time) OVERRIDE { | 193 gfx::FrameTime monotonic_time) OVERRIDE { |
| 193 started_animating_ = true; | 194 started_animating_ = true; |
| 194 } | 195 } |
| 195 | 196 |
| 196 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { | 197 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 197 if (started_animating_) | 198 if (started_animating_) |
| 198 EndTest(); | 199 EndTest(); |
| 199 } | 200 } |
| 200 | 201 |
| 201 virtual bool PrepareToDrawOnThread( | 202 virtual bool PrepareToDrawOnThread( |
| 202 LayerTreeHostImpl* host_impl, | 203 LayerTreeHostImpl* host_impl, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 220 public: | 221 public: |
| 221 LayerTreeHostAnimationTestAnimationsGetDeleted() | 222 LayerTreeHostAnimationTestAnimationsGetDeleted() |
| 222 : started_animating_(false) {} | 223 : started_animating_(false) {} |
| 223 | 224 |
| 224 virtual void BeginTest() OVERRIDE { | 225 virtual void BeginTest() OVERRIDE { |
| 225 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 226 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
| 226 } | 227 } |
| 227 | 228 |
| 228 virtual void AnimateLayers( | 229 virtual void AnimateLayers( |
| 229 LayerTreeHostImpl* host_impl, | 230 LayerTreeHostImpl* host_impl, |
| 230 base::TimeTicks monotonic_time) OVERRIDE { | 231 gfx::FrameTime monotonic_time) OVERRIDE { |
| 231 bool have_animations = !host_impl->animation_registrar()-> | 232 bool have_animations = !host_impl->animation_registrar()-> |
| 232 active_animation_controllers().empty(); | 233 active_animation_controllers().empty(); |
| 233 if (!started_animating_ && have_animations) { | 234 if (!started_animating_ && have_animations) { |
| 234 started_animating_ = true; | 235 started_animating_ = true; |
| 235 return; | 236 return; |
| 236 } | 237 } |
| 237 | 238 |
| 238 if (started_animating_ && !have_animations) | 239 if (started_animating_ && !have_animations) |
| 239 EndTest(); | 240 EndTest(); |
| 240 } | 241 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 262 | 263 |
| 263 virtual void BeginTest() OVERRIDE { | 264 virtual void BeginTest() OVERRIDE { |
| 264 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); | 265 PostAddAnimationToMainThread(layer_tree_host()->root_layer()); |
| 265 } | 266 } |
| 266 | 267 |
| 267 // Use WillAnimateLayers to set visible false before the animation runs and | 268 // 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 | 269 // causes a commit, so we block the second visible animate in single-thread |
| 269 // mode. | 270 // mode. |
| 270 virtual void WillAnimateLayers( | 271 virtual void WillAnimateLayers( |
| 271 LayerTreeHostImpl* host_impl, | 272 LayerTreeHostImpl* host_impl, |
| 272 base::TimeTicks monotonic_time) OVERRIDE { | 273 gfx::FrameTime monotonic_time) OVERRIDE { |
| 273 // Verify that the host can draw, it's just not visible. | 274 // Verify that the host can draw, it's just not visible. |
| 274 EXPECT_TRUE(host_impl->CanDraw()); | 275 EXPECT_TRUE(host_impl->CanDraw()); |
| 275 if (num_animates_ < 2) { | 276 if (num_animates_ < 2) { |
| 276 if (!num_animates_) { | 277 if (!num_animates_) { |
| 277 // We have a long animation running. It should continue to tick even | 278 // We have a long animation running. It should continue to tick even |
| 278 // if we are not visible. | 279 // if we are not visible. |
| 279 PostSetVisibleToMainThread(false); | 280 PostSetVisibleToMainThread(false); |
| 280 } | 281 } |
| 281 num_animates_++; | 282 num_animates_++; |
| 282 return; | 283 return; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 base::Bind( | 395 base::Bind( |
| 395 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: | 396 &LayerTreeHostAnimationTestNoBackgroundTickingWithoutActiveTree:: |
| 396 InitiateNextCommit, | 397 InitiateNextCommit, |
| 397 base::Unretained(this), | 398 base::Unretained(this), |
| 398 host_impl), | 399 host_impl), |
| 399 4 * LowFrequencyAnimationInterval()); | 400 4 * LowFrequencyAnimationInterval()); |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 | 403 |
| 403 virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl, | 404 virtual void WillAnimateLayers(LayerTreeHostImpl* host_impl, |
| 404 base::TimeTicks monotonic_time) OVERRIDE { | 405 gfx::FrameTime monotonic_time) OVERRIDE { |
| 405 EXPECT_TRUE(host_impl->active_tree()->root_layer()); | 406 EXPECT_TRUE(host_impl->active_tree()->root_layer()); |
| 406 active_tree_was_animated_ = true; | 407 active_tree_was_animated_ = true; |
| 407 } | 408 } |
| 408 | 409 |
| 409 void InitiateNextCommit(LayerTreeHostImpl* host_impl) { | 410 void InitiateNextCommit(LayerTreeHostImpl* host_impl) { |
| 410 // Verify that we actually animated when we should have. | 411 // Verify that we actually animated when we should have. |
| 411 bool has_active_tree = host_impl->active_tree()->root_layer(); | 412 bool has_active_tree = host_impl->active_tree()->root_layer(); |
| 412 EXPECT_EQ(has_active_tree, active_tree_was_animated_); | 413 EXPECT_EQ(has_active_tree, active_tree_was_animated_); |
| 413 | 414 |
| 414 // The next commit is blocked until we become visible again. | 415 // The next commit is blocked until we become visible again. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 435 content_->SetBounds(gfx::Size(4, 4)); | 436 content_->SetBounds(gfx::Size(4, 4)); |
| 436 layer_tree_host()->root_layer()->AddChild(content_); | 437 layer_tree_host()->root_layer()->AddChild(content_); |
| 437 } | 438 } |
| 438 | 439 |
| 439 virtual void BeginTest() OVERRIDE { | 440 virtual void BeginTest() OVERRIDE { |
| 440 PostAddAnimationToMainThread(content_.get()); | 441 PostAddAnimationToMainThread(content_.get()); |
| 441 } | 442 } |
| 442 | 443 |
| 443 virtual void AnimateLayers( | 444 virtual void AnimateLayers( |
| 444 LayerTreeHostImpl* host_impl, | 445 LayerTreeHostImpl* host_impl, |
| 445 base::TimeTicks monotonic_time) OVERRIDE { | 446 gfx::FrameTime monotonic_time) OVERRIDE { |
| 446 LayerAnimationController* controller_impl = | 447 LayerAnimationController* controller_impl = |
| 447 host_impl->active_tree()->root_layer()->children()[0]-> | 448 host_impl->active_tree()->root_layer()->children()[0]-> |
| 448 layer_animation_controller(); | 449 layer_animation_controller(); |
| 449 Animation* animation = | 450 Animation* animation = |
| 450 controller_impl->GetAnimation(Animation::Opacity); | 451 controller_impl->GetAnimation(Animation::Opacity); |
| 451 if (!animation) | 452 if (!animation) |
| 452 return; | 453 return; |
| 453 | 454 |
| 454 const FloatAnimationCurve* curve = | 455 const FloatAnimationCurve* curve = |
| 455 animation->curve()->ToFloatAnimationCurve(); | 456 animation->curve()->ToFloatAnimationCurve(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 Animation::Opacity)); | 636 Animation::Opacity)); |
| 636 layer->layer_animation_controller()->AddAnimation(animation.Pass()); | 637 layer->layer_animation_controller()->AddAnimation(animation.Pass()); |
| 637 | 638 |
| 638 // We add the animation *before* attaching the layer to the tree. | 639 // We add the animation *before* attaching the layer to the tree. |
| 639 layer_tree_host()->root_layer()->AddChild(layer); | 640 layer_tree_host()->root_layer()->AddChild(layer); |
| 640 } | 641 } |
| 641 } | 642 } |
| 642 | 643 |
| 643 virtual void AnimateLayers( | 644 virtual void AnimateLayers( |
| 644 LayerTreeHostImpl* impl_host, | 645 LayerTreeHostImpl* impl_host, |
| 645 base::TimeTicks monotonic_time) OVERRIDE { | 646 gfx::FrameTime monotonic_time) OVERRIDE { |
| 646 EndTest(); | 647 EndTest(); |
| 647 } | 648 } |
| 648 | 649 |
| 649 virtual void AfterTest() OVERRIDE {} | 650 virtual void AfterTest() OVERRIDE {} |
| 650 }; | 651 }; |
| 651 | 652 |
| 652 SINGLE_AND_MULTI_THREAD_TEST_F( | 653 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 653 LayerTreeHostAnimationTestLayerAddedWithAnimation); | 654 LayerTreeHostAnimationTestLayerAddedWithAnimation); |
| 654 | 655 |
| 655 class LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount | 656 class LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount |
| 656 : public LayerTreeHostAnimationTest { | 657 : public LayerTreeHostAnimationTest { |
| 657 public: | 658 public: |
| 658 LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount() | 659 LayerTreeHostAnimationTestCompositeAndReadbackAnimateCount() |
| 659 : animated_commit_(-1) { | 660 : animated_commit_(-1) { |
| 660 } | 661 } |
| 661 | 662 |
| 662 virtual void Animate(base::TimeTicks) OVERRIDE { | 663 virtual void Animate(gfx::FrameTime) OVERRIDE { |
| 663 // We shouldn't animate on the CompositeAndReadback-forced commit, but we | 664 // We shouldn't animate on the CompositeAndReadback-forced commit, but we |
| 664 // should for the SetNeedsCommit-triggered commit. | 665 // should for the SetNeedsCommit-triggered commit. |
| 665 animated_commit_ = layer_tree_host()->source_frame_number(); | 666 animated_commit_ = layer_tree_host()->source_frame_number(); |
| 666 EXPECT_NE(2, animated_commit_); | 667 EXPECT_NE(2, animated_commit_); |
| 667 } | 668 } |
| 668 | 669 |
| 669 virtual void BeginTest() OVERRIDE { | 670 virtual void BeginTest() OVERRIDE { |
| 670 PostSetNeedsCommitToMainThread(); | 671 PostSetNeedsCommitToMainThread(); |
| 671 } | 672 } |
| 672 | 673 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 public: | 708 public: |
| 708 LayerTreeHostAnimationTestContinuousAnimate() | 709 LayerTreeHostAnimationTestContinuousAnimate() |
| 709 : num_commit_complete_(0), | 710 : num_commit_complete_(0), |
| 710 num_draw_layers_(0) { | 711 num_draw_layers_(0) { |
| 711 } | 712 } |
| 712 | 713 |
| 713 virtual void BeginTest() OVERRIDE { | 714 virtual void BeginTest() OVERRIDE { |
| 714 PostSetNeedsCommitToMainThread(); | 715 PostSetNeedsCommitToMainThread(); |
| 715 } | 716 } |
| 716 | 717 |
| 717 virtual void Animate(base::TimeTicks) OVERRIDE { | 718 virtual void Animate(gfx::FrameTime) OVERRIDE { |
| 718 if (num_draw_layers_ == 2) | 719 if (num_draw_layers_ == 2) |
| 719 return; | 720 return; |
| 720 layer_tree_host()->SetNeedsAnimate(); | 721 layer_tree_host()->SetNeedsAnimate(); |
| 721 } | 722 } |
| 722 | 723 |
| 723 virtual void Layout() OVERRIDE { | 724 virtual void Layout() OVERRIDE { |
| 724 layer_tree_host()->root_layer()->SetNeedsDisplay(); | 725 layer_tree_host()->root_layer()->SetNeedsDisplay(); |
| 725 } | 726 } |
| 726 | 727 |
| 727 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { | 728 virtual void CommitCompleteOnThread(LayerTreeHostImpl* tree_impl) OVERRIDE { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 int finished_times_; | 928 int finished_times_; |
| 928 FakeContentLayerClient client_; | 929 FakeContentLayerClient client_; |
| 929 scoped_refptr<FakeContentLayer> content_; | 930 scoped_refptr<FakeContentLayer> content_; |
| 930 }; | 931 }; |
| 931 | 932 |
| 932 MULTI_THREAD_TEST_F( | 933 MULTI_THREAD_TEST_F( |
| 933 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); | 934 LayerTreeHostAnimationTestCheckerboardDoesntStartAnimations); |
| 934 | 935 |
| 935 } // namespace | 936 } // namespace |
| 936 } // namespace cc | 937 } // namespace cc |
| OLD | NEW |