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

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

Issue 862133002: Update from https://crrev.com/312398 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 "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 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 void AfterTest() override {} 1006 void AfterTest() override {}
1007 1007
1008 private: 1008 private:
1009 FakeContentLayerClient client_; 1009 FakeContentLayerClient client_;
1010 scoped_refptr<FakeContentLayer> scroll_layer_; 1010 scoped_refptr<FakeContentLayer> scroll_layer_;
1011 }; 1011 };
1012 1012
1013 SINGLE_AND_MULTI_THREAD_TEST_F( 1013 SINGLE_AND_MULTI_THREAD_TEST_F(
1014 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated); 1014 LayerTreeHostAnimationTestScrollOffsetChangesArePropagated);
1015 1015
1016 // Verifies that when the main thread removes a scroll animation and sets a new
1017 // scroll position, the active tree takes on exactly this new scroll position
1018 // after activation, and the main thread doesn't receive a spurious scroll
1019 // delta.
1020 class LayerTreeHostAnimationTestScrollOffsetAnimationRemoval
1021 : public LayerTreeHostAnimationTest {
1022 public:
1023 LayerTreeHostAnimationTestScrollOffsetAnimationRemoval()
1024 : final_postion_(50.0, 100.0) {}
1025
1026 void SetupTree() override {
1027 LayerTreeHostAnimationTest::SetupTree();
1028
1029 scroll_layer_ = FakeContentLayer::Create(&client_);
1030 scroll_layer_->SetScrollClipLayerId(layer_tree_host()->root_layer()->id());
1031 scroll_layer_->SetBounds(gfx::Size(10000, 10000));
1032 scroll_layer_->SetScrollOffset(gfx::ScrollOffset(100.0, 200.0));
1033 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
1034
1035 scoped_ptr<ScrollOffsetAnimationCurve> curve(
1036 ScrollOffsetAnimationCurve::Create(gfx::ScrollOffset(6500.f, 7500.f),
1037 EaseInOutTimingFunction::Create()));
1038 scoped_ptr<Animation> animation(
1039 Animation::Create(curve.Pass(), 1, 0, Animation::ScrollOffset));
1040 animation->set_needs_synchronized_start_time(true);
1041 scroll_layer_->AddAnimation(animation.Pass());
1042 }
1043
1044 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1045
1046 void DidCommit() override {
1047 Animation* animation =
1048 scroll_layer_->layer_animation_controller()->GetAnimation(
1049 Animation::ScrollOffset);
1050 if (animation) {
1051 scroll_layer_->layer_animation_controller()->RemoveAnimation(
1052 animation->id());
1053 scroll_layer_->SetScrollOffset(final_postion_);
1054 } else {
1055 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset());
1056 }
1057 }
1058
1059 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
1060 if (host_impl->settings().impl_side_painting)
1061 host_impl->BlockNotifyReadyToActivateForTesting(true);
1062 }
1063
1064 void WillBeginImplFrameOnThread(LayerTreeHostImpl* host_impl,
1065 const BeginFrameArgs& args) override {
1066 if (!host_impl->pending_tree())
1067 return;
1068
1069 if (!host_impl->active_tree()->root_layer()) {
1070 host_impl->BlockNotifyReadyToActivateForTesting(false);
1071 return;
1072 }
1073
1074 LayerImpl* scroll_layer_impl =
1075 host_impl->active_tree()->root_layer()->children()[0];
1076 Animation* animation =
1077 scroll_layer_impl->layer_animation_controller()->GetAnimation(
1078 Animation::ScrollOffset);
1079
1080 if (!animation || animation->run_state() != Animation::Running) {
1081 host_impl->BlockNotifyReadyToActivateForTesting(false);
1082 return;
1083 }
1084
1085 // Block activation until the running animation has a chance to produce a
1086 // scroll delta.
1087 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta() -
1088 scroll_layer_impl->sent_scroll_delta();
1089 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f)
1090 return;
1091
1092 host_impl->BlockNotifyReadyToActivateForTesting(false);
1093 }
1094
1095 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
1096 LayerImpl* scroll_layer_impl =
1097 host_impl->active_tree()->root_layer()->children()[0];
1098 if (scroll_layer_impl->layer_animation_controller()->GetAnimation(
1099 Animation::ScrollOffset))
1100 return;
1101
1102 EXPECT_EQ(final_postion_, scroll_layer_impl->TotalScrollOffset());
1103 EndTest();
1104 }
1105
1106 void AfterTest() override {
1107 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset());
1108 }
1109
1110 private:
1111 FakeContentLayerClient client_;
1112 scoped_refptr<FakeContentLayer> scroll_layer_;
1113 const gfx::ScrollOffset final_postion_;
1114 };
1115
1116 MULTI_THREAD_TEST_F(LayerTreeHostAnimationTestScrollOffsetAnimationRemoval);
1117
1016 // When animations are simultaneously added to an existing layer and to a new 1118 // When animations are simultaneously added to an existing layer and to a new
1017 // layer, they should start at the same time, even when there's already a 1119 // layer, they should start at the same time, even when there's already a
1018 // running animation on the existing layer. 1120 // running animation on the existing layer.
1019 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers 1121 class LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers
1020 : public LayerTreeHostAnimationTest { 1122 : public LayerTreeHostAnimationTest {
1021 public: 1123 public:
1022 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers() 1124 LayerTreeHostAnimationTestAnimationsAddedToNewAndExistingLayers()
1023 : frame_count_with_pending_tree_(0) {} 1125 : frame_count_with_pending_tree_(0) {}
1024 1126
1025 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1127 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 private: 1260 private:
1159 scoped_refptr<Layer> content_; 1261 scoped_refptr<Layer> content_;
1160 int num_swap_buffers_; 1262 int num_swap_buffers_;
1161 }; 1263 };
1162 1264
1163 SINGLE_AND_MULTI_THREAD_TEST_F( 1265 SINGLE_AND_MULTI_THREAD_TEST_F(
1164 LayerTreeHostAnimationTestAddAnimationAfterAnimating); 1266 LayerTreeHostAnimationTestAddAnimationAfterAnimating);
1165 1267
1166 } // namespace 1268 } // namespace
1167 } // namespace cc 1269 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | crypto/BUILD.gn » ('j') | shell/BUILD.gn » ('J')

Powered by Google App Engine
This is Rietveld 408576698