OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/animation_host.h" | 8 #include "cc/animation/animation_host.h" |
9 #include "cc/animation/animation_id_provider.h" | 9 #include "cc/animation/animation_id_provider.h" |
10 #include "cc/animation/animation_player.h" | 10 #include "cc/animation/animation_player.h" |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 int prevented_draw_; | 570 int prevented_draw_; |
571 int added_animations_; | 571 int added_animations_; |
572 int started_times_; | 572 int started_times_; |
573 FakeContentLayerClient client_; | 573 FakeContentLayerClient client_; |
574 scoped_refptr<FakePictureLayer> picture_; | 574 scoped_refptr<FakePictureLayer> picture_; |
575 }; | 575 }; |
576 | 576 |
577 MULTI_THREAD_TEST_F( | 577 MULTI_THREAD_TEST_F( |
578 LayerTreeHostTimelinesTestCheckerboardDoesntStartAnimations); | 578 LayerTreeHostTimelinesTestCheckerboardDoesntStartAnimations); |
579 | 579 |
| 580 // Verifies that scroll offset animations are only accepted when impl-scrolling |
| 581 // is supported, and that when scroll offset animations are accepted, |
| 582 // scroll offset updates are sent back to the main thread. |
| 583 // Evolved from LayerTreeHostAnimationTestScrollOffsetChangesArePropagated |
| 584 class LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated |
| 585 : public LayerTreeHostTimelinesTest { |
| 586 public: |
| 587 LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated() {} |
| 588 |
| 589 void SetupTree() override { |
| 590 LayerTreeHostTimelinesTest::SetupTree(); |
| 591 |
| 592 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 593 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| 594 scroll_layer_->SetBounds(gfx::Size(1000, 1000)); |
| 595 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20)); |
| 596 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 597 |
| 598 AttachPlayersToTimeline(); |
| 599 player_child_->AttachLayer(scroll_layer_->id()); |
| 600 } |
| 601 |
| 602 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 603 |
| 604 void DidCommit() override { |
| 605 switch (layer_tree_host()->source_frame_number()) { |
| 606 case 1: { |
| 607 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 608 ScrollOffsetAnimationCurve::Create( |
| 609 gfx::ScrollOffset(500.f, 550.f), |
| 610 EaseInOutTimingFunction::Create())); |
| 611 scoped_ptr<Animation> animation( |
| 612 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET)); |
| 613 animation->set_needs_synchronized_start_time(true); |
| 614 bool impl_scrolling_supported = |
| 615 layer_tree_host()->proxy()->SupportsImplScrolling(); |
| 616 if (impl_scrolling_supported) |
| 617 player_child_->AddAnimation(animation.Pass()); |
| 618 else |
| 619 EndTest(); |
| 620 break; |
| 621 } |
| 622 default: |
| 623 if (scroll_layer_->scroll_offset().x() > 10 && |
| 624 scroll_layer_->scroll_offset().y() > 20) |
| 625 EndTest(); |
| 626 } |
| 627 } |
| 628 |
| 629 void AfterTest() override {} |
| 630 |
| 631 private: |
| 632 FakeContentLayerClient client_; |
| 633 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 634 }; |
| 635 |
| 636 SINGLE_AND_MULTI_THREAD_TEST_F( |
| 637 LayerTreeHostTimelinesTestScrollOffsetChangesArePropagated); |
| 638 |
| 639 // Verifies that when the main thread removes a scroll animation and sets a new |
| 640 // scroll position, the active tree takes on exactly this new scroll position |
| 641 // after activation, and the main thread doesn't receive a spurious scroll |
| 642 // delta. |
| 643 // Evolved from LayerTreeHostAnimationTestScrollOffsetAnimationRemoval |
| 644 class LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval |
| 645 : public LayerTreeHostTimelinesTest { |
| 646 public: |
| 647 LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval() |
| 648 : final_postion_(50.0, 100.0) {} |
| 649 |
| 650 void SetupTree() override { |
| 651 LayerTreeHostTimelinesTest::SetupTree(); |
| 652 |
| 653 scroll_layer_ = FakePictureLayer::Create(layer_settings(), &client_); |
| 654 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id()); |
| 655 scroll_layer_->SetBounds(gfx::Size(10000, 10000)); |
| 656 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0)); |
| 657 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 658 |
| 659 scoped_ptr<ScrollOffsetAnimationCurve> curve( |
| 660 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f), |
| 661 EaseInOutTimingFunction::Create())); |
| 662 scoped_ptr<Animation> animation( |
| 663 Animation::Create(curve.Pass(), 1, 0, Animation::SCROLL_OFFSET)); |
| 664 animation->set_needs_synchronized_start_time(true); |
| 665 |
| 666 AttachPlayersToTimeline(); |
| 667 player_child_->AttachLayer(scroll_layer_->id()); |
| 668 player_child_->AddAnimation(animation.Pass()); |
| 669 } |
| 670 |
| 671 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 672 |
| 673 void BeginMainFrame(const BeginFrameArgs& args) override { |
| 674 switch (layer_tree_host()->source_frame_number()) { |
| 675 case 0: |
| 676 break; |
| 677 case 1: { |
| 678 Animation* animation = player_child_->element_animations() |
| 679 ->layer_animation_controller() |
| 680 ->GetAnimation(Animation::SCROLL_OFFSET); |
| 681 player_child_->RemoveAnimation(animation->id()); |
| 682 scroll_layer_->SetScrollOffset(final_postion_); |
| 683 break; |
| 684 } |
| 685 default: |
| 686 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 687 } |
| 688 } |
| 689 |
| 690 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { |
| 691 host_impl->BlockNotifyReadyToActivateForTesting(true); |
| 692 } |
| 693 |
| 694 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl, |
| 695 const BeginFrameArgs& args) override { |
| 696 if (!host_impl->pending_tree()) |
| 697 return; |
| 698 |
| 699 if (!host_impl->active_tree()->root_layer()) { |
| 700 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 701 return; |
| 702 } |
| 703 |
| 704 scoped_refptr<AnimationTimeline> timeline_impl = |
| 705 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 706 scoped_refptr<AnimationPlayer> player_impl = |
| 707 timeline_impl->GetPlayerById(player_child_id_); |
| 708 |
| 709 LayerImpl* scroll_layer_impl = |
| 710 host_impl->active_tree()->root_layer()->children()[0]; |
| 711 Animation* animation = player_impl->element_animations() |
| 712 ->layer_animation_controller() |
| 713 ->GetAnimation(Animation::SCROLL_OFFSET); |
| 714 |
| 715 if (!animation || animation->run_state() != Animation::RUNNING) { |
| 716 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 717 return; |
| 718 } |
| 719 |
| 720 // Block activation until the running animation has a chance to produce a |
| 721 // scroll delta. |
| 722 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); |
| 723 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) |
| 724 return; |
| 725 |
| 726 host_impl->BlockNotifyReadyToActivateForTesting(false); |
| 727 } |
| 728 |
| 729 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 730 if (host_impl->pending_tree()->source_frame_number() != 1) |
| 731 return; |
| 732 LayerImpl* scroll_layer_impl = |
| 733 host_impl->pending_tree()->root_layer()->children()[0]; |
| 734 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| 735 } |
| 736 |
| 737 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
| 738 if (host_impl->active_tree()->source_frame_number() != 1) |
| 739 return; |
| 740 LayerImpl* scroll_layer_impl = |
| 741 host_impl->active_tree()->root_layer()->children()[0]; |
| 742 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
| 743 EndTest(); |
| 744 } |
| 745 |
| 746 void AfterTest() override { |
| 747 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 748 } |
| 749 |
| 750 private: |
| 751 FakeContentLayerClient client_; |
| 752 scoped_refptr<FakePictureLayer> scroll_layer_; |
| 753 const gfx::ScrollOffset final_postion_; |
| 754 }; |
| 755 |
| 756 MULTI_THREAD_TEST_F(LayerTreeHostTimelinesTestScrollOffsetAnimationRemoval); |
| 757 |
580 // When animations are simultaneously added to an existing layer and to a new | 758 // When animations are simultaneously added to an existing layer and to a new |
581 // layer, they should start at the same time, even when there's already a | 759 // layer, they should start at the same time, even when there's already a |
582 // running animation on the existing layer. | 760 // running animation on the existing layer. |
583 // Evolved from LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers. | 761 // Evolved from LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers. |
584 class LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers | 762 class LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers |
585 : public LayerTreeHostTimelinesTest { | 763 : public LayerTreeHostTimelinesTest { |
586 public: | 764 public: |
587 LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers() | 765 LayerTreeHostTimelinesTestAnimationsAddedToNewAndExistingLayers() |
588 : frame_count_with_pending_tree_(0) {} | 766 : frame_count_with_pending_tree_(0) {} |
589 | 767 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 | 914 |
737 private: | 915 private: |
738 scoped_refptr<Layer> content_; | 916 scoped_refptr<Layer> content_; |
739 }; | 917 }; |
740 | 918 |
741 SINGLE_AND_MULTI_THREAD_TEST_F( | 919 SINGLE_AND_MULTI_THREAD_TEST_F( |
742 LayerTreeHostTimelinesTestAddAnimationAfterAnimating); | 920 LayerTreeHostTimelinesTestAddAnimationAfterAnimating); |
743 | 921 |
744 } // namespace | 922 } // namespace |
745 } // namespace cc | 923 } // namespace cc |
OLD | NEW |