Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: cc/trees/layer_tree_host_unittest_animation.cc

Issue 1950243005: Communicate MT changes to impl-only scroll offset animations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: skobes' feedback Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/animation_host.h" 10 #include "cc/animation/animation_host.h"
11 #include "cc/animation/animation_id_provider.h" 11 #include "cc/animation/animation_id_provider.h"
12 #include "cc/animation/animation_player.h" 12 #include "cc/animation/animation_player.h"
13 #include "cc/animation/animation_timeline.h" 13 #include "cc/animation/animation_timeline.h"
14 #include "cc/animation/element_animations.h" 14 #include "cc/animation/element_animations.h"
15 #include "cc/animation/scroll_offset_animation_curve.h" 15 #include "cc/animation/scroll_offset_animation_curve.h"
16 #include "cc/animation/scroll_offset_animations.h"
16 #include "cc/animation/timing_function.h" 17 #include "cc/animation/timing_function.h"
17 #include "cc/animation/transform_operations.h" 18 #include "cc/animation/transform_operations.h"
18 #include "cc/base/completion_event.h" 19 #include "cc/base/completion_event.h"
19 #include "cc/base/time_util.h" 20 #include "cc/base/time_util.h"
20 #include "cc/layers/layer.h" 21 #include "cc/layers/layer.h"
21 #include "cc/layers/layer_impl.h" 22 #include "cc/layers/layer_impl.h"
22 #include "cc/test/animation_test_common.h" 23 #include "cc/test/animation_test_common.h"
23 #include "cc/test/fake_content_layer_client.h" 24 #include "cc/test/fake_content_layer_client.h"
24 #include "cc/test/fake_picture_layer.h" 25 #include "cc/test/fake_picture_layer.h"
25 #include "cc/test/layer_tree_test.h" 26 #include "cc/test/layer_tree_test.h"
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 804
804 void AfterTest() override {} 805 void AfterTest() override {}
805 806
806 private: 807 private:
807 FakeContentLayerClient client_; 808 FakeContentLayerClient client_;
808 scoped_refptr<FakePictureLayer> scroll_layer_; 809 scoped_refptr<FakePictureLayer> scroll_layer_;
809 }; 810 };
810 811
811 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationTakeover); 812 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationTakeover);
812 813
814 // Verifies that an impl-only scroll offset animation gets updated when the
815 // scroll offset is adjusted on the main thread.
816 class LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted
817 : public LayerTreeHostAnimationTest {
818 public:
819 LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted() {}
820
821 void SetupTree() override {
822 LayerTreeHostAnimationTest::SetupTree();
823
824 scroll_layer_ = FakePictureLayer::Create(&client_);
825 scroll_layer_->SetBounds(gfx::Size(10000, 10000));
826 client_.set_bounds(scroll_layer_->bounds());
827 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(10, 20));
828 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
829
830 AttachPlayersToTimeline();
831 player_child_->AttachElement(scroll_layer_->id());
832 }
833
834 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
835
836 void DidCommit() override {
837 if (layer_tree_host()->source_frame_number() == 1) {
838 // Add an update after the first commit to trigger the animation update
839 // path.
840 ScrollOffsetAnimationUpdate update(
841 ScrollOffsetAnimationUpdate::Type::SCROLL_OFFSET_CHANGED,
842 scroll_layer_->id());
843 update.adjustment_ = gfx::Vector2dF(100.f, 100.f);
844 layer_tree_host()->animation_host()->scroll_offset_animations().AddUpdate(
845 update);
846 EXPECT_TRUE(layer_tree_host()
847 ->animation_host()
848 ->scroll_offset_animations()
849 .HasUpdatesForTesting());
850 } else if (layer_tree_host()->source_frame_number() == 2) {
851 // Verify that the update queue is cleared after the update is applied.
852 EXPECT_FALSE(layer_tree_host()
853 ->animation_host()
854 ->scroll_offset_animations()
855 .HasUpdatesForTesting());
856 }
857 }
858
859 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
860 // Note that the frame number gets incremented after BeginCommitOnThread but
861 // before WillCommitCompleteOnThread and CommitCompleteOnThread.
862 if (host_impl->sync_tree()->source_frame_number() == 0) {
863 // This happens after the impl-only animation is added in
864 // WillCommitCompleteOnThread.
865 Animation* animation =
866 host_impl->animation_host()
867 ->GetElementAnimationsForElementId(scroll_layer_->id())
868 ->GetAnimation(TargetProperty::SCROLL_OFFSET);
869 ScrollOffsetAnimationCurve* curve =
870 animation->curve()->ToScrollOffsetAnimationCurve();
871
872 // Verifiy the initial and target position before the scroll offset
873 // update from MT.
874 EXPECT_EQ(Animation::RunState::RUNNING, animation->run_state());
875 EXPECT_EQ(gfx::ScrollOffset(10.f, 20.f),
876 curve->GetValue(base::TimeDelta()));
877 EXPECT_EQ(gfx::ScrollOffset(650.f, 750.f), curve->target_value());
878
879 // This is how far the animation is reached until now. It is used to
880 // determine the expecation of initial_positon_ after the update.
881 current_offset_ = curve->GetValue(animation->TrimTimeToCurrentIteration(
882 host_impl->CurrentBeginFrameArgs().frame_time));
883 }
884 }
885
886 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
887 if (host_impl->sync_tree()->source_frame_number() == 0) {
888 host_impl->animation_host()->ImplOnlyScrollAnimationCreate(
889 scroll_layer_->id(), gfx::ScrollOffset(650.f, 750.f),
890 gfx::ScrollOffset(10, 20));
891 }
892 }
893
894 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
895 if (host_impl->sync_tree()->source_frame_number() == 1) {
896 Animation* animation =
897 host_impl->animation_host()
898 ->GetElementAnimationsForElementId(scroll_layer_->id())
899 ->GetAnimation(TargetProperty::SCROLL_OFFSET);
900 ScrollOffsetAnimationCurve* curve =
901 animation->curve()->ToScrollOffsetAnimationCurve();
902 // Verifiy the initial and target position after the scroll offset
903 // update from MT
904 EXPECT_EQ(Animation::RunState::STARTING, animation->run_state());
905 EXPECT_EQ(gfx::ScrollOffset(110.f, 120.f),
906 curve->GetValue(base::TimeDelta()));
907 EXPECT_EQ(gfx::ScrollOffset(750.f, 850.f), curve->target_value());
ajuma 2016/05/16 13:41:57 Do you need to take current_offset_ into account h
ymalik 2016/05/16 18:21:36 Thanks! current_offset_ should have been removed b
908
909 EndTest();
910 }
911 }
912
913 void AfterTest() override {}
914
915 private:
916 FakeContentLayerClient client_;
917 gfx::ScrollOffset current_offset_;
918 scoped_refptr<FakePictureLayer> scroll_layer_;
919 };
920
921 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationAdjusted);
922
813 // Verifies that when the main thread removes a scroll animation and sets a new 923 // Verifies that when the main thread removes a scroll animation and sets a new
814 // scroll position, the active tree takes on exactly this new scroll position 924 // scroll position, the active tree takes on exactly this new scroll position
815 // after activation, and the main thread doesn't receive a spurious scroll 925 // after activation, and the main thread doesn't receive a spurious scroll
816 // delta. 926 // delta.
817 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval 927 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval
818 : public LayerTreeHostAnimationTest { 928 : public LayerTreeHostAnimationTest {
819 public: 929 public:
820 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval() 930 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval()
821 : final_postion_(50.0, 100.0) {} 931 : final_postion_(50.0, 100.0) {}
822 932
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 private: 1767 private:
1658 scoped_refptr<Layer> layer_; 1768 scoped_refptr<Layer> layer_;
1659 FakeContentLayerClient client_; 1769 FakeContentLayerClient client_;
1660 }; 1770 };
1661 1771
1662 MULTI_THREAD_TEST_F( 1772 MULTI_THREAD_TEST_F(
1663 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); 1773 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit);
1664 1774
1665 } // namespace 1775 } // namespace
1666 } // namespace cc 1776 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698