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

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

Issue 2216203002: Refactor MutatorHostClient from LayerTreeHost to LayerTree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes according to code review. Created 4 years, 4 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"
(...skipping 26 matching lines...) Expand all
37 player_id_(AnimationIdProvider::NextPlayerId()), 37 player_id_(AnimationIdProvider::NextPlayerId()),
38 player_child_id_(AnimationIdProvider::NextPlayerId()) { 38 player_child_id_(AnimationIdProvider::NextPlayerId()) {
39 timeline_ = AnimationTimeline::Create(timeline_id_); 39 timeline_ = AnimationTimeline::Create(timeline_id_);
40 player_ = AnimationPlayer::Create(player_id_); 40 player_ = AnimationPlayer::Create(player_id_);
41 player_child_ = AnimationPlayer::Create(player_child_id_); 41 player_child_ = AnimationPlayer::Create(player_child_id_);
42 42
43 player_->set_animation_delegate(this); 43 player_->set_animation_delegate(this);
44 } 44 }
45 45
46 void AttachPlayersToTimeline() { 46 void AttachPlayersToTimeline() {
47 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); 47 layer_tree()->animation_host()->AddAnimationTimeline(timeline_.get());
48 layer_tree_host()->SetElementIdsForTesting(); 48 layer_tree()->SetElementIdsForTesting();
49 timeline_->AttachPlayer(player_.get()); 49 timeline_->AttachPlayer(player_.get());
50 timeline_->AttachPlayer(player_child_.get()); 50 timeline_->AttachPlayer(player_child_.get());
51 } 51 }
52 52
53 protected: 53 protected:
54 scoped_refptr<AnimationTimeline> timeline_; 54 scoped_refptr<AnimationTimeline> timeline_;
55 scoped_refptr<AnimationPlayer> player_; 55 scoped_refptr<AnimationPlayer> player_;
56 scoped_refptr<AnimationPlayer> player_child_; 56 scoped_refptr<AnimationPlayer> player_child_;
57 57
58 const int timeline_id_; 58 const int timeline_id_;
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // Allows NotifyAnimationTakeover to get called. 779 // Allows NotifyAnimationTakeover to get called.
780 player_child_->set_animation_delegate(this); 780 player_child_->set_animation_delegate(this);
781 } 781 }
782 782
783 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 783 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
784 784
785 void DidCommit() override { 785 void DidCommit() override {
786 if (layer_tree_host()->source_frame_number() == 1) { 786 if (layer_tree_host()->source_frame_number() == 1) {
787 // Add an update after the first commit to trigger the animation takeover 787 // Add an update after the first commit to trigger the animation takeover
788 // path. 788 // path.
789 layer_tree_host() 789 layer_tree()
790 ->animation_host() 790 ->animation_host()
791 ->scroll_offset_animations() 791 ->scroll_offset_animations()
792 .AddTakeoverUpdate(scroll_layer_->element_id()); 792 .AddTakeoverUpdate(scroll_layer_->element_id());
793 EXPECT_TRUE(layer_tree_host() 793 EXPECT_TRUE(layer_tree()
794 ->animation_host() 794 ->animation_host()
795 ->scroll_offset_animations() 795 ->scroll_offset_animations()
796 .HasUpdatesForTesting()); 796 .HasUpdatesForTesting());
797 } 797 }
798 } 798 }
799 799
800 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 800 void WillCommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
801 if (host_impl->sync_tree()->source_frame_number() == 0) { 801 if (host_impl->sync_tree()->source_frame_number() == 0) {
802 host_impl->animation_host()->ImplOnlyScrollAnimationCreate( 802 host_impl->animation_host()->ImplOnlyScrollAnimationCreate(
803 scroll_layer_->element_id(), gfx::ScrollOffset(650.f, 750.f), 803 scroll_layer_->element_id(), gfx::ScrollOffset(650.f, 750.f),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 AttachPlayersToTimeline(); 840 AttachPlayersToTimeline();
841 player_child_->AttachElement(scroll_layer_->element_id()); 841 player_child_->AttachElement(scroll_layer_->element_id());
842 } 842 }
843 843
844 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 844 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
845 845
846 void DidCommit() override { 846 void DidCommit() override {
847 if (layer_tree_host()->source_frame_number() == 1) { 847 if (layer_tree_host()->source_frame_number() == 1) {
848 // Add an update after the first commit to trigger the animation update 848 // Add an update after the first commit to trigger the animation update
849 // path. 849 // path.
850 layer_tree_host() 850 layer_tree()
851 ->animation_host() 851 ->animation_host()
852 ->scroll_offset_animations() 852 ->scroll_offset_animations()
853 .AddAdjustmentUpdate(scroll_layer_->element_id(), 853 .AddAdjustmentUpdate(scroll_layer_->element_id(),
854 gfx::Vector2dF(100.f, 100.f)); 854 gfx::Vector2dF(100.f, 100.f));
855 EXPECT_TRUE(layer_tree_host() 855 EXPECT_TRUE(layer_tree()
856 ->animation_host() 856 ->animation_host()
857 ->scroll_offset_animations() 857 ->scroll_offset_animations()
858 .HasUpdatesForTesting()); 858 .HasUpdatesForTesting());
859 } else if (layer_tree_host()->source_frame_number() == 2) { 859 } else if (layer_tree_host()->source_frame_number() == 2) {
860 // Verify that the update queue is cleared after the update is applied. 860 // Verify that the update queue is cleared after the update is applied.
861 EXPECT_FALSE(layer_tree_host() 861 EXPECT_FALSE(layer_tree()
862 ->animation_host() 862 ->animation_host()
863 ->scroll_offset_animations() 863 ->scroll_offset_animations()
864 .HasUpdatesForTesting()); 864 .HasUpdatesForTesting());
865 } 865 }
866 } 866 }
867 867
868 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { 868 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
869 // Note that the frame number gets incremented after BeginCommitOnThread but 869 // Note that the frame number gets incremented after BeginCommitOnThread but
870 // before WillCommitCompleteOnThread and CommitCompleteOnThread. 870 // before WillCommitCompleteOnThread and CommitCompleteOnThread.
871 if (host_impl->sync_tree()->source_frame_number() == 0) { 871 if (host_impl->sync_tree()->source_frame_number() == 0) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 void DidCommit() override { 1062 void DidCommit() override {
1063 if (layer_tree_host()->source_frame_number() == 1) { 1063 if (layer_tree_host()->source_frame_number() == 1) {
1064 player_->AttachElement(layer_tree_host()->root_layer()->element_id()); 1064 player_->AttachElement(layer_tree_host()->root_layer()->element_id());
1065 AddAnimatedTransformToPlayer(player_.get(), 4, 1, 1); 1065 AddAnimatedTransformToPlayer(player_.get(), 4, 1, 1);
1066 } else if (layer_tree_host()->source_frame_number() == 2) { 1066 } else if (layer_tree_host()->source_frame_number() == 2) {
1067 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 0.5f, true); 1067 AddOpacityTransitionToPlayer(player_.get(), 1, 0.f, 0.5f, true);
1068 1068
1069 scoped_refptr<Layer> layer = Layer::Create(); 1069 scoped_refptr<Layer> layer = Layer::Create();
1070 layer_tree_host()->root_layer()->AddChild(layer); 1070 layer_tree_host()->root_layer()->AddChild(layer);
1071 1071
1072 layer_tree_host()->SetElementIdsForTesting(); 1072 layer_tree()->SetElementIdsForTesting();
1073 layer->SetBounds(gfx::Size(4, 4)); 1073 layer->SetBounds(gfx::Size(4, 4));
1074 1074
1075 player_child_->AttachElement(layer->element_id()); 1075 player_child_->AttachElement(layer->element_id());
1076 player_child_->set_animation_delegate(this); 1076 player_child_->set_animation_delegate(this);
1077 AddOpacityTransitionToPlayer(player_child_.get(), 1, 0.f, 0.5f, true); 1077 AddOpacityTransitionToPlayer(player_child_.get(), 1, 0.f, 0.5f, true);
1078 } 1078 }
1079 } 1079 }
1080 1080
1081 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override { 1081 void BeginCommitOnThread(LayerTreeHostImpl* host_impl) override {
1082 host_impl->BlockNotifyReadyToActivateForTesting(true); 1082 host_impl->BlockNotifyReadyToActivateForTesting(true);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 1153
1154 layer_ = FakePictureLayer::Create(&client_); 1154 layer_ = FakePictureLayer::Create(&client_);
1155 layer_->SetBounds(gfx::Size(2, 2)); 1155 layer_->SetBounds(gfx::Size(2, 2));
1156 client_.set_bounds(layer_->bounds()); 1156 client_.set_bounds(layer_->bounds());
1157 // Transform the layer to 4,4 to start. 1157 // Transform the layer to 4,4 to start.
1158 gfx::Transform start_transform; 1158 gfx::Transform start_transform;
1159 start_transform.Translate(4.0, 4.0); 1159 start_transform.Translate(4.0, 4.0);
1160 layer_->SetTransform(start_transform); 1160 layer_->SetTransform(start_transform);
1161 1161
1162 layer_tree_host()->root_layer()->AddChild(layer_); 1162 layer_tree_host()->root_layer()->AddChild(layer_);
1163 layer_tree_host()->SetElementIdsForTesting(); 1163 layer_tree()->SetElementIdsForTesting();
1164 1164
1165 player_->AttachElement(layer_->element_id()); 1165 player_->AttachElement(layer_->element_id());
1166 1166
1167 AttachPlayersToTimeline(); 1167 AttachPlayersToTimeline();
1168 } 1168 }
1169 1169
1170 void BeginTest() override { 1170 void BeginTest() override {
1171 // Add a translate from 6,7 to 8,9. 1171 // Add a translate from 6,7 to 8,9.
1172 TransformOperations start; 1172 TransformOperations start;
1173 start.AppendTranslate(6.f, 7.f, 0.f); 1173 start.AppendTranslate(6.f, 7.f, 0.f);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 // the animation should resume. 1225 // the animation should resume.
1226 class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded 1226 class LayerTreeHostAnimationTestAnimatedLayerRemovedAndAdded
1227 : public LayerTreeHostAnimationTest { 1227 : public LayerTreeHostAnimationTest {
1228 public: 1228 public:
1229 void SetupTree() override { 1229 void SetupTree() override {
1230 LayerTreeHostAnimationTest::SetupTree(); 1230 LayerTreeHostAnimationTest::SetupTree();
1231 layer_ = Layer::Create(); 1231 layer_ = Layer::Create();
1232 layer_->SetBounds(gfx::Size(4, 4)); 1232 layer_->SetBounds(gfx::Size(4, 4));
1233 layer_tree_host()->root_layer()->AddChild(layer_); 1233 layer_tree_host()->root_layer()->AddChild(layer_);
1234 1234
1235 layer_tree_host()->SetElementIdsForTesting(); 1235 layer_tree()->SetElementIdsForTesting();
1236 1236
1237 layer_tree_host()->animation_host()->AddAnimationTimeline(timeline_.get()); 1237 layer_tree()->animation_host()->AddAnimationTimeline(timeline_.get());
1238 timeline_->AttachPlayer(player_.get()); 1238 timeline_->AttachPlayer(player_.get());
1239 player_->AttachElement(layer_->element_id()); 1239 player_->AttachElement(layer_->element_id());
1240 DCHECK(player_->element_animations()); 1240 DCHECK(player_->element_animations());
1241 1241
1242 AddOpacityTransitionToPlayer(player_.get(), 10000.0, 0.1f, 0.9f, true); 1242 AddOpacityTransitionToPlayer(player_.get(), 10000.0, 0.1f, 0.9f, true);
1243 } 1243 }
1244 1244
1245 void BeginTest() override { PostSetNeedsCommitToMainThread(); } 1245 void BeginTest() override { PostSetNeedsCommitToMainThread(); }
1246 1246
1247 void DidCommit() override { 1247 void DidCommit() override {
1248 switch (layer_tree_host()->source_frame_number()) { 1248 switch (layer_tree_host()->source_frame_number()) {
1249 case 0: 1249 case 0:
1250 EXPECT_TRUE( 1250 EXPECT_TRUE(
1251 player_->element_animations()->has_element_in_active_list()); 1251 player_->element_animations()->has_element_in_active_list());
1252 EXPECT_FALSE( 1252 EXPECT_FALSE(
1253 player_->element_animations()->has_element_in_pending_list()); 1253 player_->element_animations()->has_element_in_pending_list());
1254 EXPECT_TRUE(layer_tree_host()->animation_host()->NeedsAnimateLayers()); 1254 EXPECT_TRUE(layer_tree()->animation_host()->NeedsAnimateLayers());
1255 break; 1255 break;
1256 case 1: 1256 case 1:
1257 layer_->RemoveFromParent(); 1257 layer_->RemoveFromParent();
1258 EXPECT_FALSE( 1258 EXPECT_FALSE(
1259 player_->element_animations()->has_element_in_active_list()); 1259 player_->element_animations()->has_element_in_active_list());
1260 EXPECT_FALSE( 1260 EXPECT_FALSE(
1261 player_->element_animations()->has_element_in_pending_list()); 1261 player_->element_animations()->has_element_in_pending_list());
1262 EXPECT_FALSE(layer_tree_host()->animation_host()->NeedsAnimateLayers()); 1262 EXPECT_FALSE(layer_tree()->animation_host()->NeedsAnimateLayers());
1263 break; 1263 break;
1264 case 2: 1264 case 2:
1265 layer_tree_host()->root_layer()->AddChild(layer_); 1265 layer_tree_host()->root_layer()->AddChild(layer_);
1266 EXPECT_TRUE( 1266 EXPECT_TRUE(
1267 player_->element_animations()->has_element_in_active_list()); 1267 player_->element_animations()->has_element_in_active_list());
1268 EXPECT_FALSE( 1268 EXPECT_FALSE(
1269 player_->element_animations()->has_element_in_pending_list()); 1269 player_->element_animations()->has_element_in_pending_list());
1270 EXPECT_TRUE(layer_tree_host()->animation_host()->NeedsAnimateLayers()); 1270 EXPECT_TRUE(layer_tree()->animation_host()->NeedsAnimateLayers());
1271 break; 1271 break;
1272 } 1272 }
1273 } 1273 }
1274 1274
1275 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 1275 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
1276 scoped_refptr<AnimationTimeline> timeline_impl = 1276 scoped_refptr<AnimationTimeline> timeline_impl =
1277 host_impl->animation_host()->GetTimelineById(timeline_id_); 1277 host_impl->animation_host()->GetTimelineById(timeline_id_);
1278 scoped_refptr<AnimationPlayer> player_impl = 1278 scoped_refptr<AnimationPlayer> player_impl =
1279 timeline_impl->GetPlayerById(player_id_); 1279 timeline_impl->GetPlayerById(player_id_);
1280 1280
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1857 private: 1857 private:
1858 scoped_refptr<Layer> layer_; 1858 scoped_refptr<Layer> layer_;
1859 FakeContentLayerClient client_; 1859 FakeContentLayerClient client_;
1860 }; 1860 };
1861 1861
1862 MULTI_THREAD_TEST_F( 1862 MULTI_THREAD_TEST_F(
1863 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); 1863 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit);
1864 1864
1865 } // namespace 1865 } // namespace
1866 } // namespace cc 1866 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698