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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "cc/animation/animation_curve.h" | 9 #include "cc/animation/animation_curve.h" |
10 #include "cc/animation/layer_animation_controller.h" | 10 #include "cc/animation/layer_animation_controller.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 129 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
130 } | 130 } |
131 | 131 |
132 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 132 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
133 bool has_unfinished_animation) override { | 133 bool has_unfinished_animation) override { |
134 EXPECT_FALSE(has_unfinished_animation); | 134 EXPECT_FALSE(has_unfinished_animation); |
135 update_animation_state_was_called_ = true; | 135 update_animation_state_was_called_ = true; |
136 } | 136 } |
137 | 137 |
138 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 138 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
139 Animation::TargetProperty target_property, | 139 AnimationTargetProperty target_property, |
140 int group) override { | 140 int group) override { |
141 EXPECT_LT(base::TimeTicks(), monotonic_time); | 141 EXPECT_LT(base::TimeTicks(), monotonic_time); |
142 | 142 |
143 LayerAnimationController* controller = | 143 LayerAnimationController* controller = |
144 layer_tree_host()->root_layer()->layer_animation_controller(); | 144 layer_tree_host()->root_layer()->layer_animation_controller(); |
145 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 145 Animation* animation = |
| 146 controller->GetAnimation(AnimationTargetProperty::OPACITY); |
146 if (animation) | 147 if (animation) |
147 controller->RemoveAnimation(animation->id()); | 148 controller->RemoveAnimation(animation->id()); |
148 | 149 |
149 EndTest(); | 150 EndTest(); |
150 } | 151 } |
151 | 152 |
152 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } | 153 void AfterTest() override { EXPECT_TRUE(update_animation_state_was_called_); } |
153 | 154 |
154 private: | 155 private: |
155 bool update_animation_state_was_called_; | 156 bool update_animation_state_was_called_; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (!started_animating_ && have_animations) { | 214 if (!started_animating_ && have_animations) { |
214 started_animating_ = true; | 215 started_animating_ = true; |
215 return; | 216 return; |
216 } | 217 } |
217 | 218 |
218 if (started_animating_ && !have_animations) | 219 if (started_animating_ && !have_animations) |
219 EndTest(); | 220 EndTest(); |
220 } | 221 } |
221 | 222 |
222 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 223 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
223 Animation::TargetProperty target_property, | 224 AnimationTargetProperty target_property, |
224 int group) override { | 225 int group) override { |
225 // Animations on the impl-side controller only get deleted during a commit, | 226 // Animations on the impl-side controller only get deleted during a commit, |
226 // so we need to schedule a commit. | 227 // so we need to schedule a commit. |
227 layer_tree_host()->SetNeedsCommit(); | 228 layer_tree_host()->SetNeedsCommit(); |
228 } | 229 } |
229 | 230 |
230 void AfterTest() override {} | 231 void AfterTest() override {} |
231 | 232 |
232 private: | 233 private: |
233 bool started_animating_; | 234 bool started_animating_; |
(...skipping 17 matching lines...) Expand all Loading... |
251 | 252 |
252 void AnimateLayers(LayerTreeHostImpl* host_impl, | 253 void AnimateLayers(LayerTreeHostImpl* host_impl, |
253 base::TimeTicks monotonic_time) override { | 254 base::TimeTicks monotonic_time) override { |
254 // TODO(ajuma): This test only checks the active tree. Add checks for | 255 // TODO(ajuma): This test only checks the active tree. Add checks for |
255 // pending tree too. | 256 // pending tree too. |
256 if (!host_impl->active_tree()->root_layer()) | 257 if (!host_impl->active_tree()->root_layer()) |
257 return; | 258 return; |
258 LayerAnimationController* controller_impl = | 259 LayerAnimationController* controller_impl = |
259 host_impl->active_tree()->root_layer()->children()[0]-> | 260 host_impl->active_tree()->root_layer()->children()[0]-> |
260 layer_animation_controller(); | 261 layer_animation_controller(); |
261 Animation* animation = controller_impl->GetAnimation(Animation::OPACITY); | 262 Animation* animation = |
| 263 controller_impl->GetAnimation(AnimationTargetProperty::OPACITY); |
262 if (!animation) | 264 if (!animation) |
263 return; | 265 return; |
264 | 266 |
265 const FloatAnimationCurve* curve = | 267 const FloatAnimationCurve* curve = |
266 animation->curve()->ToFloatAnimationCurve(); | 268 animation->curve()->ToFloatAnimationCurve(); |
267 float start_opacity = curve->GetValue(base::TimeDelta()); | 269 float start_opacity = curve->GetValue(base::TimeDelta()); |
268 float end_opacity = curve->GetValue(curve->Duration()); | 270 float end_opacity = curve->GetValue(curve->Duration()); |
269 float linearly_interpolated_opacity = | 271 float linearly_interpolated_opacity = |
270 0.25f * end_opacity + 0.75f * start_opacity; | 272 0.25f * end_opacity + 0.75f * start_opacity; |
271 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); | 273 base::TimeDelta time = TimeUtil::Scale(curve->Duration(), 0.25f); |
(...skipping 24 matching lines...) Expand all Loading... |
296 picture_ = FakePictureLayer::Create(layer_settings(), &client_); | 298 picture_ = FakePictureLayer::Create(layer_settings(), &client_); |
297 picture_->SetBounds(gfx::Size(4, 4)); | 299 picture_->SetBounds(gfx::Size(4, 4)); |
298 client_.set_bounds(picture_->bounds()); | 300 client_.set_bounds(picture_->bounds()); |
299 picture_->set_layer_animation_delegate(this); | 301 picture_->set_layer_animation_delegate(this); |
300 layer_tree_host()->root_layer()->AddChild(picture_); | 302 layer_tree_host()->root_layer()->AddChild(picture_); |
301 } | 303 } |
302 | 304 |
303 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } | 305 void BeginTest() override { PostAddAnimationToMainThread(picture_.get()); } |
304 | 306 |
305 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 307 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
306 Animation::TargetProperty target_property, | 308 AnimationTargetProperty target_property, |
307 int group) override { | 309 int group) override { |
308 LayerAnimationController* controller = | 310 LayerAnimationController* controller = |
309 layer_tree_host()->root_layer()->children()[0]-> | 311 layer_tree_host()->root_layer()->children()[0]-> |
310 layer_animation_controller(); | 312 layer_animation_controller(); |
311 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 313 Animation* animation = |
| 314 controller->GetAnimation(AnimationTargetProperty::OPACITY); |
312 main_start_time_ = animation->start_time(); | 315 main_start_time_ = animation->start_time(); |
313 controller->RemoveAnimation(animation->id()); | 316 controller->RemoveAnimation(animation->id()); |
314 EndTest(); | 317 EndTest(); |
315 } | 318 } |
316 | 319 |
317 void UpdateAnimationState(LayerTreeHostImpl* impl_host, | 320 void UpdateAnimationState(LayerTreeHostImpl* impl_host, |
318 bool has_unfinished_animation) override { | 321 bool has_unfinished_animation) override { |
319 LayerAnimationController* controller = | 322 LayerAnimationController* controller = |
320 impl_host->active_tree()->root_layer()->children()[0]-> | 323 impl_host->active_tree()->root_layer()->children()[0]-> |
321 layer_animation_controller(); | 324 layer_animation_controller(); |
322 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 325 Animation* animation = |
| 326 controller->GetAnimation(AnimationTargetProperty::OPACITY); |
323 if (!animation) | 327 if (!animation) |
324 return; | 328 return; |
325 | 329 |
326 impl_start_time_ = animation->start_time(); | 330 impl_start_time_ = animation->start_time(); |
327 } | 331 } |
328 | 332 |
329 void AfterTest() override { | 333 void AfterTest() override { |
330 EXPECT_EQ(impl_start_time_, main_start_time_); | 334 EXPECT_EQ(impl_start_time_, main_start_time_); |
331 EXPECT_LT(base::TimeTicks(), impl_start_time_); | 335 EXPECT_LT(base::TimeTicks(), impl_start_time_); |
332 } | 336 } |
(...skipping 10 matching lines...) Expand all Loading... |
343 | 347 |
344 // Ensures that notify animation finished is called. | 348 // Ensures that notify animation finished is called. |
345 class LayerTreeHostAnimationTestAnimationFinishedEvents | 349 class LayerTreeHostAnimationTestAnimationFinishedEvents |
346 : public LayerTreeHostAnimationTest { | 350 : public LayerTreeHostAnimationTest { |
347 public: | 351 public: |
348 void BeginTest() override { | 352 void BeginTest() override { |
349 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); | 353 PostAddInstantAnimationToMainThread(layer_tree_host()->root_layer()); |
350 } | 354 } |
351 | 355 |
352 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 356 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
353 Animation::TargetProperty target_property, | 357 AnimationTargetProperty target_property, |
354 int group) override { | 358 int group) override { |
355 LayerAnimationController* controller = | 359 LayerAnimationController* controller = |
356 layer_tree_host()->root_layer()->layer_animation_controller(); | 360 layer_tree_host()->root_layer()->layer_animation_controller(); |
357 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 361 Animation* animation = |
| 362 controller->GetAnimation(AnimationTargetProperty::OPACITY); |
358 if (animation) | 363 if (animation) |
359 controller->RemoveAnimation(animation->id()); | 364 controller->RemoveAnimation(animation->id()); |
360 EndTest(); | 365 EndTest(); |
361 } | 366 } |
362 | 367 |
363 void AfterTest() override {} | 368 void AfterTest() override {} |
364 }; | 369 }; |
365 | 370 |
366 SINGLE_AND_MULTI_THREAD_TEST_F( | 371 SINGLE_AND_MULTI_THREAD_TEST_F( |
367 LayerTreeHostAnimationTestAnimationFinishedEvents); | 372 LayerTreeHostAnimationTestAnimationFinishedEvents); |
(...skipping 15 matching lines...) Expand all Loading... |
383 } | 388 } |
384 | 389 |
385 void BeginTest() override { | 390 void BeginTest() override { |
386 PostAddAnimationToMainThread(update_check_layer_.get()); | 391 PostAddAnimationToMainThread(update_check_layer_.get()); |
387 } | 392 } |
388 | 393 |
389 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 394 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
390 LayerAnimationController* controller_impl = | 395 LayerAnimationController* controller_impl = |
391 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 396 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
392 Animation* animation_impl = | 397 Animation* animation_impl = |
393 controller_impl->GetAnimation(Animation::OPACITY); | 398 controller_impl->GetAnimation(AnimationTargetProperty::OPACITY); |
394 controller_impl->RemoveAnimation(animation_impl->id()); | 399 controller_impl->RemoveAnimation(animation_impl->id()); |
395 EndTest(); | 400 EndTest(); |
396 } | 401 } |
397 | 402 |
398 void AfterTest() override { | 403 void AfterTest() override { |
399 // Update() should have been called once, proving that the layer was not | 404 // Update() should have been called once, proving that the layer was not |
400 // skipped. | 405 // skipped. |
401 EXPECT_EQ(1, update_check_layer_->update_count()); | 406 EXPECT_EQ(1, update_check_layer_->update_count()); |
402 | 407 |
403 // clear update_check_layer_ so LayerTreeHost dies. | 408 // clear update_check_layer_ so LayerTreeHost dies. |
(...skipping 15 matching lines...) Expand all Loading... |
419 public: | 424 public: |
420 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 425 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
421 | 426 |
422 void DidCommit() override { | 427 void DidCommit() override { |
423 if (layer_tree_host()->source_frame_number() == 1) { | 428 if (layer_tree_host()->source_frame_number() == 1) { |
424 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); | 429 scoped_refptr<Layer> layer = Layer::Create(layer_settings()); |
425 layer->set_layer_animation_delegate(this); | 430 layer->set_layer_animation_delegate(this); |
426 | 431 |
427 // Any valid AnimationCurve will do here. | 432 // Any valid AnimationCurve will do here. |
428 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); | 433 scoped_ptr<AnimationCurve> curve(new FakeFloatAnimationCurve()); |
429 scoped_ptr<Animation> animation( | 434 scoped_ptr<Animation> animation(Animation::Create( |
430 Animation::Create(std::move(curve), 1, 1, Animation::OPACITY)); | 435 std::move(curve), 1, 1, AnimationTargetProperty::OPACITY)); |
431 layer->layer_animation_controller()->AddAnimation(std::move(animation)); | 436 layer->layer_animation_controller()->AddAnimation(std::move(animation)); |
432 | 437 |
433 // We add the animation *before* attaching the layer to the tree. | 438 // We add the animation *before* attaching the layer to the tree. |
434 layer_tree_host()->root_layer()->AddChild(layer); | 439 layer_tree_host()->root_layer()->AddChild(layer); |
435 } | 440 } |
436 } | 441 } |
437 | 442 |
438 void AnimateLayers(LayerTreeHostImpl* impl_host, | 443 void AnimateLayers(LayerTreeHostImpl* impl_host, |
439 base::TimeTicks monotonic_time) override { | 444 base::TimeTicks monotonic_time) override { |
440 EndTest(); | 445 EndTest(); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 AddOpacityTransitionToLayer(picture_.get(), 0.1, 0.2f, 0.8f, false); | 614 AddOpacityTransitionToLayer(picture_.get(), 0.1, 0.2f, 0.8f, false); |
610 break; | 615 break; |
611 case 2: | 616 case 2: |
612 // This second animation will not be drawn so it should not start. | 617 // This second animation will not be drawn so it should not start. |
613 AddAnimatedTransformToLayer(picture_.get(), 0.1, 5, 5); | 618 AddAnimatedTransformToLayer(picture_.get(), 0.1, 5, 5); |
614 break; | 619 break; |
615 } | 620 } |
616 } | 621 } |
617 | 622 |
618 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 623 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
619 Animation::TargetProperty target_property, | 624 AnimationTargetProperty target_property, |
620 int group) override { | 625 int group) override { |
621 if (TestEnded()) | 626 if (TestEnded()) |
622 return; | 627 return; |
623 started_times_++; | 628 started_times_++; |
624 } | 629 } |
625 | 630 |
626 void AfterTest() override { | 631 void AfterTest() override { |
627 // Make sure we tried to draw the second animation but failed. | 632 // Make sure we tried to draw the second animation but failed. |
628 EXPECT_LT(0, prevented_draw_); | 633 EXPECT_LT(0, prevented_draw_); |
629 // The first animation should be started, but the second should not because | 634 // The first animation should be started, but the second should not because |
(...skipping 30 matching lines...) Expand all Loading... |
660 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 665 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
661 | 666 |
662 void DidCommit() override { | 667 void DidCommit() override { |
663 switch (layer_tree_host()->source_frame_number()) { | 668 switch (layer_tree_host()->source_frame_number()) { |
664 case 1: { | 669 case 1: { |
665 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 670 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
666 ScrollOffsetAnimationCurve::Create( | 671 ScrollOffsetAnimationCurve::Create( |
667 gfx::ScrollOffset(500.f, 550.f), | 672 gfx::ScrollOffset(500.f, 550.f), |
668 EaseInOutTimingFunction::Create())); | 673 EaseInOutTimingFunction::Create())); |
669 scoped_ptr<Animation> animation(Animation::Create( | 674 scoped_ptr<Animation> animation(Animation::Create( |
670 std::move(curve), 1, 0, Animation::SCROLL_OFFSET)); | 675 std::move(curve), 1, 0, AnimationTargetProperty::SCROLL_OFFSET)); |
671 animation->set_needs_synchronized_start_time(true); | 676 animation->set_needs_synchronized_start_time(true); |
672 bool animation_added = | 677 bool animation_added = |
673 scroll_layer_->AddAnimation(std::move(animation)); | 678 scroll_layer_->AddAnimation(std::move(animation)); |
674 bool impl_scrolling_supported = | 679 bool impl_scrolling_supported = |
675 layer_tree_host()->proxy()->SupportsImplScrolling(); | 680 layer_tree_host()->proxy()->SupportsImplScrolling(); |
676 EXPECT_EQ(impl_scrolling_supported, animation_added); | 681 EXPECT_EQ(impl_scrolling_supported, animation_added); |
677 if (!impl_scrolling_supported) | 682 if (!impl_scrolling_supported) |
678 EndTest(); | 683 EndTest(); |
679 break; | 684 break; |
680 } | 685 } |
(...skipping 30 matching lines...) Expand all Loading... |
711 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); | 716 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
712 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); | 717 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
713 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); | 718 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
714 client_.set_bounds(scroll_layer_->bounds()); | 719 client_.set_bounds(scroll_layer_->bounds()); |
715 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); | 720 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); |
716 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 721 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
717 | 722 |
718 scoped_ptr<ScrollOffsetAnimationCurve> curve( | 723 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
719 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), | 724 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), |
720 EaseInOutTimingFunction::Create())); | 725 EaseInOutTimingFunction::Create())); |
721 scoped_ptr<Animation> animation( | 726 scoped_ptr<Animation> animation(Animation::Create( |
722 Animation::Create(std::move(curve), 1, 0, Animation::SCROLL_OFFSET)); | 727 std::move(curve), 1, 0, AnimationTargetProperty::SCROLL_OFFSET)); |
723 animation->set_needs_synchronized_start_time(true); | 728 animation->set_needs_synchronized_start_time(true); |
724 scroll_layer_->AddAnimation(std::move(animation)); | 729 scroll_layer_->AddAnimation(std::move(animation)); |
725 } | 730 } |
726 | 731 |
727 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 732 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
728 | 733 |
729 void BeginMainFrame(const BeginFrameArgs& args) override { | 734 void BeginMainFrame(const BeginFrameArgs& args) override { |
730 switch (layer_tree_host()->source_frame_number()) { | 735 switch (layer_tree_host()->source_frame_number()) { |
731 case 0: | 736 case 0: |
732 break; | 737 break; |
733 case 1: { | 738 case 1: { |
734 Animation* animation = | 739 Animation* animation = |
735 scroll_layer_->layer_animation_controller()->GetAnimation( | 740 scroll_layer_->layer_animation_controller()->GetAnimation( |
736 Animation::SCROLL_OFFSET); | 741 AnimationTargetProperty::SCROLL_OFFSET); |
737 scroll_layer_->layer_animation_controller()->RemoveAnimation( | 742 scroll_layer_->layer_animation_controller()->RemoveAnimation( |
738 animation->id()); | 743 animation->id()); |
739 scroll_layer_->SetScrollOffset(final_postion_); | 744 scroll_layer_->SetScrollOffset(final_postion_); |
740 break; | 745 break; |
741 } | 746 } |
742 default: | 747 default: |
743 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 748 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
744 } | 749 } |
745 } | 750 } |
746 | 751 |
747 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { | 752 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
748 host_impl->BlockNotifyReadyToActivateForTesting(true); | 753 host_impl->BlockNotifyReadyToActivateForTesting(true); |
749 } | 754 } |
750 | 755 |
751 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, | 756 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
752 const BeginFrameArgs& args) override { | 757 const BeginFrameArgs& args) override { |
753 if (!host_impl->pending_tree()) | 758 if (!host_impl->pending_tree()) |
754 return; | 759 return; |
755 | 760 |
756 if (!host_impl->active_tree()->root_layer()) { | 761 if (!host_impl->active_tree()->root_layer()) { |
757 host_impl->BlockNotifyReadyToActivateForTesting(false); | 762 host_impl->BlockNotifyReadyToActivateForTesting(false); |
758 return; | 763 return; |
759 } | 764 } |
760 | 765 |
761 LayerImpl* scroll_layer_impl = | 766 LayerImpl* scroll_layer_impl = |
762 host_impl->active_tree()->root_layer()->children()[0].get(); | 767 host_impl->active_tree()->root_layer()->children()[0].get(); |
763 Animation* animation = | 768 Animation* animation = |
764 scroll_layer_impl->layer_animation_controller()->GetAnimation( | 769 scroll_layer_impl->layer_animation_controller()->GetAnimation( |
765 Animation::SCROLL_OFFSET); | 770 AnimationTargetProperty::SCROLL_OFFSET); |
766 | 771 |
767 if (!animation || animation->run_state() != Animation::RUNNING) { | 772 if (!animation || animation->run_state() != Animation::RUNNING) { |
768 host_impl->BlockNotifyReadyToActivateForTesting(false); | 773 host_impl->BlockNotifyReadyToActivateForTesting(false); |
769 return; | 774 return; |
770 } | 775 } |
771 | 776 |
772 // Block activation until the running animation has a chance to produce a | 777 // Block activation until the running animation has a chance to produce a |
773 // scroll delta. | 778 // scroll delta. |
774 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); | 779 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); |
775 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) | 780 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 if (frame_count_with_pending_tree_ == 2) { | 862 if (frame_count_with_pending_tree_ == 2) { |
858 host_impl->BlockNotifyReadyToActivateForTesting(false); | 863 host_impl->BlockNotifyReadyToActivateForTesting(false); |
859 } | 864 } |
860 } | 865 } |
861 | 866 |
862 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 867 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
863 bool has_unfinished_animation) override { | 868 bool has_unfinished_animation) override { |
864 LayerAnimationController* root_controller_impl = | 869 LayerAnimationController* root_controller_impl = |
865 host_impl->active_tree()->root_layer()->layer_animation_controller(); | 870 host_impl->active_tree()->root_layer()->layer_animation_controller(); |
866 Animation* root_animation = | 871 Animation* root_animation = |
867 root_controller_impl->GetAnimation(Animation::OPACITY); | 872 root_controller_impl->GetAnimation(AnimationTargetProperty::OPACITY); |
868 if (!root_animation || root_animation->run_state() != Animation::RUNNING) | 873 if (!root_animation || root_animation->run_state() != Animation::RUNNING) |
869 return; | 874 return; |
870 | 875 |
871 LayerAnimationController* child_controller_impl = | 876 LayerAnimationController* child_controller_impl = |
872 host_impl->active_tree()->root_layer()->children() | 877 host_impl->active_tree()->root_layer()->children() |
873 [0]->layer_animation_controller(); | 878 [0]->layer_animation_controller(); |
874 Animation* child_animation = | 879 Animation* child_animation = |
875 child_controller_impl->GetAnimation(Animation::OPACITY); | 880 child_controller_impl->GetAnimation(AnimationTargetProperty::OPACITY); |
876 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); | 881 EXPECT_EQ(Animation::RUNNING, child_animation->run_state()); |
877 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); | 882 EXPECT_EQ(root_animation->start_time(), child_animation->start_time()); |
878 root_controller_impl->AbortAnimations(Animation::OPACITY); | 883 root_controller_impl->AbortAnimations(AnimationTargetProperty::OPACITY); |
879 root_controller_impl->AbortAnimations(Animation::TRANSFORM); | 884 root_controller_impl->AbortAnimations(AnimationTargetProperty::TRANSFORM); |
880 child_controller_impl->AbortAnimations(Animation::OPACITY); | 885 child_controller_impl->AbortAnimations(AnimationTargetProperty::OPACITY); |
881 EndTest(); | 886 EndTest(); |
882 } | 887 } |
883 | 888 |
884 void AfterTest() override {} | 889 void AfterTest() override {} |
885 | 890 |
886 private: | 891 private: |
887 int frame_count_with_pending_tree_; | 892 int frame_count_with_pending_tree_; |
888 }; | 893 }; |
889 | 894 |
890 // This test blocks activation which is not supported for single thread mode. | 895 // This test blocks activation which is not supported for single thread mode. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 | 930 |
926 // After checking this on the sync tree, we will activate, which will cause | 931 // After checking this on the sync tree, we will activate, which will cause |
927 // PrepareTiles to happen again (which races with the test exiting). | 932 // PrepareTiles to happen again (which races with the test exiting). |
928 if (TestEnded()) | 933 if (TestEnded()) |
929 return; | 934 return; |
930 | 935 |
931 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 936 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
932 LayerImpl* child = root->children()[0].get(); | 937 LayerImpl* child = root->children()[0].get(); |
933 LayerAnimationController* controller_impl = | 938 LayerAnimationController* controller_impl = |
934 child->layer_animation_controller(); | 939 child->layer_animation_controller(); |
935 Animation* animation = controller_impl->GetAnimation(Animation::TRANSFORM); | 940 Animation* animation = |
| 941 controller_impl->GetAnimation(AnimationTargetProperty::TRANSFORM); |
936 | 942 |
937 // The animation should be starting for the first frame. | 943 // The animation should be starting for the first frame. |
938 EXPECT_EQ(Animation::STARTING, animation->run_state()); | 944 EXPECT_EQ(Animation::STARTING, animation->run_state()); |
939 | 945 |
940 // And the transform should be propogated to the sync tree layer, at its | 946 // And the transform should be propogated to the sync tree layer, at its |
941 // starting state which is 6,7. | 947 // starting state which is 6,7. |
942 gfx::Transform expected_transform; | 948 gfx::Transform expected_transform; |
943 expected_transform.Translate(6.0, 7.0); | 949 expected_transform.Translate(6.0, 7.0); |
944 EXPECT_EQ(expected_transform, child->DrawTransform()); | 950 EXPECT_EQ(expected_transform, child->DrawTransform()); |
945 // And the sync tree layer should know it is animating. | 951 // And the sync tree layer should know it is animating. |
946 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 952 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
947 | 953 |
948 controller_impl->AbortAnimations(Animation::TRANSFORM); | 954 controller_impl->AbortAnimations(AnimationTargetProperty::TRANSFORM); |
949 EndTest(); | 955 EndTest(); |
950 } | 956 } |
951 | 957 |
952 void AfterTest() override {} | 958 void AfterTest() override {} |
953 | 959 |
954 FakeContentLayerClient client_; | 960 FakeContentLayerClient client_; |
955 scoped_refptr<Layer> layer_; | 961 scoped_refptr<Layer> layer_; |
956 }; | 962 }; |
957 | 963 |
958 SINGLE_AND_MULTI_THREAD_TEST_F( | 964 SINGLE_AND_MULTI_THREAD_TEST_F( |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 // start times. | 1045 // start times. |
1040 if (host_impl->active_tree()->source_frame_number() < 2) | 1046 if (host_impl->active_tree()->source_frame_number() < 2) |
1041 return; | 1047 return; |
1042 AnimationRegistrar::AnimationControllerMap controllers_copy = | 1048 AnimationRegistrar::AnimationControllerMap controllers_copy = |
1043 host_impl->animation_registrar() | 1049 host_impl->animation_registrar() |
1044 ->active_animation_controllers_for_testing(); | 1050 ->active_animation_controllers_for_testing(); |
1045 EXPECT_EQ(2u, controllers_copy.size()); | 1051 EXPECT_EQ(2u, controllers_copy.size()); |
1046 for (auto& it : controllers_copy) { | 1052 for (auto& it : controllers_copy) { |
1047 int id = it.first; | 1053 int id = it.first; |
1048 if (id == host_impl->RootLayer()->id()) { | 1054 if (id == host_impl->RootLayer()->id()) { |
1049 Animation* anim = it.second->GetAnimation(Animation::TRANSFORM); | 1055 Animation* anim = |
| 1056 it.second->GetAnimation(AnimationTargetProperty::TRANSFORM); |
1050 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1057 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
1051 } else if (id == host_impl->RootLayer()->children()[0]->id()) { | 1058 } else if (id == host_impl->RootLayer()->children()[0]->id()) { |
1052 Animation* anim = it.second->GetAnimation(Animation::OPACITY); | 1059 Animation* anim = |
| 1060 it.second->GetAnimation(AnimationTargetProperty::OPACITY); |
1053 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1061 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
1054 } | 1062 } |
1055 EndTest(); | 1063 EndTest(); |
1056 } | 1064 } |
1057 } | 1065 } |
1058 | 1066 |
1059 void AfterTest() override {} | 1067 void AfterTest() override {} |
1060 | 1068 |
1061 private: | 1069 private: |
1062 scoped_refptr<Layer> layer_; | 1070 scoped_refptr<Layer> layer_; |
(...skipping 16 matching lines...) Expand all Loading... |
1079 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1087 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1080 | 1088 |
1081 void DidCommit() override { | 1089 void DidCommit() override { |
1082 switch (layer_tree_host()->source_frame_number()) { | 1090 switch (layer_tree_host()->source_frame_number()) { |
1083 case 1: | 1091 case 1: |
1084 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); | 1092 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); |
1085 break; | 1093 break; |
1086 case 2: | 1094 case 2: |
1087 LayerAnimationController* controller = | 1095 LayerAnimationController* controller = |
1088 layer_->layer_animation_controller(); | 1096 layer_->layer_animation_controller(); |
1089 Animation* animation = controller->GetAnimation(Animation::TRANSFORM); | 1097 Animation* animation = |
| 1098 controller->GetAnimation(AnimationTargetProperty::TRANSFORM); |
1090 layer_->RemoveAnimation(animation->id()); | 1099 layer_->RemoveAnimation(animation->id()); |
1091 gfx::Transform transform; | 1100 gfx::Transform transform; |
1092 transform.Translate(10.f, 10.f); | 1101 transform.Translate(10.f, 10.f); |
1093 layer_->SetTransform(transform); | 1102 layer_->SetTransform(transform); |
1094 | 1103 |
1095 // Do something that causes property trees to get rebuilt. This is | 1104 // Do something that causes property trees to get rebuilt. This is |
1096 // intended to simulate the conditions that caused the bug whose fix | 1105 // intended to simulate the conditions that caused the bug whose fix |
1097 // this is testing (the test will pass without it but won't test what | 1106 // this is testing (the test will pass without it but won't test what |
1098 // we want it to). We were updating the wrong transform node at the end | 1107 // we want it to). We were updating the wrong transform node at the end |
1099 // of an animation (we were assuming the layer with the finished | 1108 // of an animation (we were assuming the layer with the finished |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1164 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
1156 | 1165 |
1157 void DidCommit() override { | 1166 void DidCommit() override { |
1158 switch (layer_tree_host()->source_frame_number()) { | 1167 switch (layer_tree_host()->source_frame_number()) { |
1159 case 1: | 1168 case 1: |
1160 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); | 1169 AddAnimatedTransformToLayer(layer_.get(), 1.0, 5, 5); |
1161 break; | 1170 break; |
1162 case 2: | 1171 case 2: |
1163 LayerAnimationController* controller = | 1172 LayerAnimationController* controller = |
1164 layer_->layer_animation_controller(); | 1173 layer_->layer_animation_controller(); |
1165 Animation* animation = controller->GetAnimation(Animation::TRANSFORM); | 1174 Animation* animation = |
| 1175 controller->GetAnimation(AnimationTargetProperty::TRANSFORM); |
1166 layer_->RemoveAnimation(animation->id()); | 1176 layer_->RemoveAnimation(animation->id()); |
1167 break; | 1177 break; |
1168 } | 1178 } |
1169 } | 1179 } |
1170 | 1180 |
1171 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1181 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
1172 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 1182 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
1173 LayerImpl* child = root->children()[0].get(); | 1183 LayerImpl* child = root->children()[0].get(); |
1174 switch (host_impl->sync_tree()->source_frame_number()) { | 1184 switch (host_impl->sync_tree()->source_frame_number()) { |
1175 case 0: | 1185 case 0: |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1303 client_.set_bounds(picture_->bounds()); | 1313 client_.set_bounds(picture_->bounds()); |
1304 picture_->set_layer_animation_delegate(this); | 1314 picture_->set_layer_animation_delegate(this); |
1305 layer_tree_host()->root_layer()->AddChild(picture_); | 1315 layer_tree_host()->root_layer()->AddChild(picture_); |
1306 } | 1316 } |
1307 | 1317 |
1308 void BeginTest() override { | 1318 void BeginTest() override { |
1309 PostAddLongAnimationToMainThread(picture_.get()); | 1319 PostAddLongAnimationToMainThread(picture_.get()); |
1310 } | 1320 } |
1311 | 1321 |
1312 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 1322 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
1313 Animation::TargetProperty target_property, | 1323 AnimationTargetProperty target_property, |
1314 int group) override { | 1324 int group) override { |
1315 called_animation_started_ = true; | 1325 called_animation_started_ = true; |
1316 layer_tree_host()->AnimateLayers(base::TimeTicks::FromInternalValue( | 1326 layer_tree_host()->AnimateLayers(base::TimeTicks::FromInternalValue( |
1317 std::numeric_limits<int64_t>::max())); | 1327 std::numeric_limits<int64_t>::max())); |
1318 PostSetNeedsCommitToMainThread(); | 1328 PostSetNeedsCommitToMainThread(); |
1319 } | 1329 } |
1320 | 1330 |
1321 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 1331 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
1322 Animation::TargetProperty target_property, | 1332 AnimationTargetProperty target_property, |
1323 int group) override { | 1333 int group) override { |
1324 called_animation_finished_ = true; | 1334 called_animation_finished_ = true; |
1325 EndTest(); | 1335 EndTest(); |
1326 } | 1336 } |
1327 | 1337 |
1328 void AfterTest() override { | 1338 void AfterTest() override { |
1329 EXPECT_TRUE(called_animation_started_); | 1339 EXPECT_TRUE(called_animation_started_); |
1330 EXPECT_TRUE(called_animation_finished_); | 1340 EXPECT_TRUE(called_animation_finished_); |
1331 } | 1341 } |
1332 | 1342 |
1333 private: | 1343 private: |
1334 bool called_animation_started_; | 1344 bool called_animation_started_; |
1335 bool called_animation_finished_; | 1345 bool called_animation_finished_; |
1336 FakeContentLayerClient client_; | 1346 FakeContentLayerClient client_; |
1337 scoped_refptr<FakePictureLayer> picture_; | 1347 scoped_refptr<FakePictureLayer> picture_; |
1338 }; | 1348 }; |
1339 | 1349 |
1340 SINGLE_AND_MULTI_THREAD_TEST_F( | 1350 SINGLE_AND_MULTI_THREAD_TEST_F( |
1341 LayerTreeHostAnimationTestNotifyAnimationFinished); | 1351 LayerTreeHostAnimationTestNotifyAnimationFinished); |
1342 | 1352 |
1343 } // namespace | 1353 } // namespace |
1344 } // namespace cc | 1354 } // namespace cc |
OLD | NEW |