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