| 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/scroll_offset_animation_curve.h" | 9 #include "cc/animation/scroll_offset_animation_curve.h" |
| 10 #include "cc/animation/timing_function.h" | 10 #include "cc/animation/timing_function.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void AfterTest() override {} | 99 void AfterTest() override {} |
| 100 | 100 |
| 101 private: | 101 private: |
| 102 int num_begin_frames_; | 102 int num_begin_frames_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 MULTI_THREAD_TEST_F( | 105 MULTI_THREAD_TEST_F( |
| 106 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); | 106 LayerTreeHostAnimationTestSetNeedsAnimateInsideAnimationCallback); |
| 107 | 107 |
| 108 // Add a layer animation and confirm that | 108 // Add a layer animation and confirm that |
| 109 // LayerTreeHostImpl::updateAnimationState does get called and continues to | 109 // LayerTreeHostImpl::UpdateAnimationState does get called. |
| 110 // get called. | |
| 111 class LayerTreeHostAnimationTestAddAnimation | 110 class LayerTreeHostAnimationTestAddAnimation |
| 112 : public LayerTreeHostAnimationTest { | 111 : public LayerTreeHostAnimationTest { |
| 113 public: | 112 public: |
| 114 LayerTreeHostAnimationTestAddAnimation() | 113 LayerTreeHostAnimationTestAddAnimation() |
| 115 : num_begin_frames_(0), received_animation_started_notification_(false) {} | 114 : update_animation_state_was_called_(false) {} |
| 116 | 115 |
| 117 void BeginTest() override { | 116 void BeginTest() override { |
| 118 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 117 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
| 119 } | 118 } |
| 120 | 119 |
| 121 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 120 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
| 122 bool has_unfinished_animation) override { | 121 bool has_unfinished_animation) override { |
| 123 if (!num_begin_frames_) { | 122 EXPECT_FALSE(has_unfinished_animation); |
| 124 // The animation had zero duration so LayerTreeHostImpl should no | 123 update_animation_state_was_called_ = true; |
| 125 // longer need to animate its layers. | |
| 126 EXPECT_FALSE(has_unfinished_animation); | |
| 127 num_begin_frames_++; | |
| 128 return; | |
| 129 } | |
| 130 | |
| 131 if (received_animation_started_notification_) { | |
| 132 EXPECT_LT(base::TimeTicks(), start_time_); | |
| 133 | |
| 134 LayerAnimationController* controller_impl = | |
| 135 host_impl->active_tree()->root_layer()->layer_animation_controller(); | |
| 136 Animation* animation_impl = | |
| 137 controller_impl->GetAnimation(Animation::Opacity); | |
| 138 if (animation_impl) | |
| 139 controller_impl->RemoveAnimation(animation_impl->id()); | |
| 140 | |
| 141 EndTest(); | |
| 142 } | |
| 143 } | 124 } |
| 144 | 125 |
| 145 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 126 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 146 Animation::TargetProperty target_property, | 127 Animation::TargetProperty target_property, |
| 147 int group) override { | 128 int group) override { |
| 148 received_animation_started_notification_ = true; | 129 EXPECT_LT(base::TimeTicks(), monotonic_time); |
| 149 start_time_ = monotonic_time; | |
| 150 if (num_begin_frames_) { | |
| 151 EXPECT_LT(base::TimeTicks(), start_time_); | |
| 152 | 130 |
| 153 LayerAnimationController* controller = | 131 LayerAnimationController* controller = |
| 154 layer_tree_host()->root_layer()->layer_animation_controller(); | 132 layer_tree_host()->root_layer()->layer_animation_controller(); |
| 155 Animation* animation = | 133 Animation* animation = controller->GetAnimation(Animation::Opacity); |
| 156 controller->GetAnimation(Animation::Opacity); | 134 if (animation) |
| 157 if (animation) | 135 controller->RemoveAnimation(animation->id()); |
| 158 controller->RemoveAnimation(animation->id()); | |
| 159 | 136 |
| 160 EndTest(); | 137 EndTest(); |
| 161 } | |
| 162 } | 138 } |
| 163 | 139 |
| 164 void AfterTest() override {} | 140 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } |
| 165 | 141 |
| 166 private: | 142 private: |
| 167 int num_begin_frames_; | 143 bool update_animation_state_was_called_; |
| 168 bool received_animation_started_notification_; | |
| 169 base::TimeTicks start_time_; | |
| 170 }; | 144 }; |
| 171 | 145 |
| 172 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); | 146 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestAddAnimation); |
| 173 | 147 |
| 174 // Add a layer animation to a layer, but continually fail to draw. Confirm that | 148 // Add a layer animation to a layer, but continually fail to draw. Confirm that |
| 175 // after a while, we do eventually force a draw. | 149 // after a while, we do eventually force a draw. |
| 176 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws | 150 class LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws |
| 177 : public LayerTreeHostAnimationTest { | 151 : public LayerTreeHostAnimationTest { |
| 178 public: | 152 public: |
| 179 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() | 153 LayerTreeHostAnimationTestCheckerboardDoesNotStarveDraws() |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 }; | 498 }; |
| 525 | 499 |
| 526 SINGLE_AND_MULTI_THREAD_TEST_F( | 500 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 527 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); | 501 LayerTreeHostAnimationTestAddAnimationWithTimingFunction); |
| 528 | 502 |
| 529 // Ensures that main thread animations have their start times synchronized with | 503 // Ensures that main thread animations have their start times synchronized with |
| 530 // impl thread animations. | 504 // impl thread animations. |
| 531 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes | 505 class LayerTreeHostAnimationTestSynchronizeAnimationStartTimes |
| 532 : public LayerTreeHostAnimationTest { | 506 : public LayerTreeHostAnimationTest { |
| 533 public: | 507 public: |
| 534 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() | 508 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes() {} |
| 535 : main_start_time_(-1.0), | |
| 536 impl_start_time_(-1.0) {} | |
| 537 | 509 |
| 538 void SetupTree() override { | 510 void SetupTree() override { |
| 539 LayerTreeHostAnimationTest::SetupTree(); | 511 LayerTreeHostAnimationTest::SetupTree(); |
| 540 content_ = FakeContentLayer::Create(&client_); | 512 content_ = FakeContentLayer::Create(&client_); |
| 541 content_->SetBounds(gfx::Size(4, 4)); | 513 content_->SetBounds(gfx::Size(4, 4)); |
| 542 content_->set_layer_animation_delegate(this); | 514 content_->set_layer_animation_delegate(this); |
| 543 layer_tree_host()->root_layer()->AddChild(content_); | 515 layer_tree_host()->root_layer()->AddChild(content_); |
| 544 } | 516 } |
| 545 | 517 |
| 546 void BeginTest() override { PostAddAnimationToMainThread(content_.get()); } | 518 void BeginTest() override { PostAddAnimationToMainThread(content_.get()); } |
| 547 | 519 |
| 548 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 520 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
| 549 Animation::TargetProperty target_property, | 521 Animation::TargetProperty target_property, |
| 550 int group) override { | 522 int group) override { |
| 551 LayerAnimationController* controller = | 523 LayerAnimationController* controller = |
| 552 layer_tree_host()->root_layer()->children()[0]-> | 524 layer_tree_host()->root_layer()->children()[0]-> |
| 553 layer_animation_controller(); | 525 layer_animation_controller(); |
| 554 Animation* animation = | 526 Animation* animation = |
| 555 controller->GetAnimation(Animation::Opacity); | 527 controller->GetAnimation(Animation::Opacity); |
| 556 main_start_time_ = | 528 main_start_time_ = animation->start_time(); |
| 557 (animation->start_time() - base::TimeTicks()).InSecondsF(); | |
| 558 controller->RemoveAnimation(animation->id()); | 529 controller->RemoveAnimation(animation->id()); |
| 559 | 530 EndTest(); |
| 560 if (impl_start_time_ > 0.0) | |
| 561 EndTest(); | |
| 562 } | 531 } |
| 563 | 532 |
| 564 void UpdateAnimationState(LayerTreeHostImpl* impl_host, | 533 void UpdateAnimationState(LayerTreeHostImpl* impl_host, |
| 565 bool has_unfinished_animation) override { | 534 bool has_unfinished_animation) override { |
| 566 LayerAnimationController* controller = | 535 LayerAnimationController* controller = |
| 567 impl_host->active_tree()->root_layer()->children()[0]-> | 536 impl_host->active_tree()->root_layer()->children()[0]-> |
| 568 layer_animation_controller(); | 537 layer_animation_controller(); |
| 569 Animation* animation = | 538 Animation* animation = |
| 570 controller->GetAnimation(Animation::Opacity); | 539 controller->GetAnimation(Animation::Opacity); |
| 571 if (!animation) | 540 if (!animation) |
| 572 return; | 541 return; |
| 573 | 542 |
| 574 impl_start_time_ = | 543 impl_start_time_ = animation->start_time(); |
| 575 (animation->start_time() - base::TimeTicks()).InSecondsF(); | |
| 576 controller->RemoveAnimation(animation->id()); | |
| 577 | |
| 578 if (main_start_time_ > 0.0) | |
| 579 EndTest(); | |
| 580 } | 544 } |
| 581 | 545 |
| 582 void AfterTest() override { | 546 void AfterTest() override { |
| 583 EXPECT_FLOAT_EQ(impl_start_time_, main_start_time_); | 547 EXPECT_EQ(impl_start_time_, main_start_time_); |
| 548 EXPECT_LT(base::TimeTicks(), impl_start_time_); |
| 584 } | 549 } |
| 585 | 550 |
| 586 private: | 551 private: |
| 587 double main_start_time_; | 552 base::TimeTicks main_start_time_; |
| 588 double impl_start_time_; | 553 base::TimeTicks impl_start_time_; |
| 589 FakeContentLayerClient client_; | 554 FakeContentLayerClient client_; |
| 590 scoped_refptr<FakeContentLayer> content_; | 555 scoped_refptr<FakeContentLayer> content_; |
| 591 }; | 556 }; |
| 592 | 557 |
| 593 SINGLE_AND_MULTI_THREAD_TEST_F( | 558 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 594 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); | 559 LayerTreeHostAnimationTestSynchronizeAnimationStartTimes); |
| 595 | 560 |
| 596 // Ensures that notify animation finished is called. | 561 // Ensures that notify animation finished is called. |
| 597 class LayerTreeHostAnimationTestAnimationFinishedEvents | 562 class LayerTreeHostAnimationTestAnimationFinishedEvents |
| 598 : public LayerTreeHostAnimationTest { | 563 : public LayerTreeHostAnimationTest { |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1193 private: | 1158 private: |
| 1194 scoped_refptr<Layer> content_; | 1159 scoped_refptr<Layer> content_; |
| 1195 int num_swap_buffers_; | 1160 int num_swap_buffers_; |
| 1196 }; | 1161 }; |
| 1197 | 1162 |
| 1198 SINGLE_AND_MULTI_THREAD_TEST_F( | 1163 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 1199 LayerTreeHostAnimationTestAddAnimationAfterAnimating); | 1164 LayerTreeHostAnimationTestAddAnimationAfterAnimating); |
| 1200 | 1165 |
| 1201 } // namespace | 1166 } // namespace |
| 1202 } // namespace cc | 1167 } // namespace cc |
| OLD | NEW |