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

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

Issue 1905713002: cc: Remove LayerImpl::children() calls from descendants of LayerTreeTest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Resolve comments Created 4 years, 8 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
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 host_impl->BlockNotifyReadyToActivateForTesting(false); 818 host_impl->BlockNotifyReadyToActivateForTesting(false);
819 return; 819 return;
820 } 820 }
821 821
822 scoped_refptr<AnimationTimeline> timeline_impl = 822 scoped_refptr<AnimationTimeline> timeline_impl =
823 host_impl->animation_host()->GetTimelineById(timeline_id_); 823 host_impl->animation_host()->GetTimelineById(timeline_id_);
824 scoped_refptr<AnimationPlayer> player_impl = 824 scoped_refptr<AnimationPlayer> player_impl =
825 timeline_impl->GetPlayerById(player_child_id_); 825 timeline_impl->GetPlayerById(player_child_id_);
826 826
827 LayerImpl* scroll_layer_impl = 827 LayerImpl* scroll_layer_impl =
828 host_impl->active_tree()->root_layer()->children()[0]; 828 host_impl->active_tree()->LayerById(scroll_layer_->id());
829 Animation* animation = player_impl->element_animations() 829 Animation* animation = player_impl->element_animations()
830 ->GetAnimation(TargetProperty::SCROLL_OFFSET); 830 ->GetAnimation(TargetProperty::SCROLL_OFFSET);
831 831
832 if (!animation || animation->run_state() != Animation::RUNNING) { 832 if (!animation || animation->run_state() != Animation::RUNNING) {
833 host_impl->BlockNotifyReadyToActivateForTesting(false); 833 host_impl->BlockNotifyReadyToActivateForTesting(false);
834 return; 834 return;
835 } 835 }
836 836
837 // Block activation until the running animation has a chance to produce a 837 // Block activation until the running animation has a chance to produce a
838 // scroll delta. 838 // scroll delta.
839 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl); 839 gfx::Vector2dF scroll_delta = ScrollDelta(scroll_layer_impl);
840 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) 840 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f)
841 return; 841 return;
842 842
843 host_impl->BlockNotifyReadyToActivateForTesting(false); 843 host_impl->BlockNotifyReadyToActivateForTesting(false);
844 } 844 }
845 845
846 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 846 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
847 if (host_impl->pending_tree()->source_frame_number() != 1) 847 if (host_impl->pending_tree()->source_frame_number() != 1)
848 return; 848 return;
849 LayerImpl* scroll_layer_impl = 849 LayerImpl* scroll_layer_impl =
850 host_impl->pending_tree()->root_layer()->children()[0]; 850 host_impl->pending_tree()->LayerById(scroll_layer_->id());
851 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); 851 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset());
852 } 852 }
853 853
854 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { 854 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override {
855 if (host_impl->active_tree()->source_frame_number() != 1) 855 if (host_impl->active_tree()->source_frame_number() != 1)
856 return; 856 return;
857 LayerImpl* scroll_layer_impl = 857 LayerImpl* scroll_layer_impl =
858 host_impl->active_tree()->root_layer()->children()[0]; 858 host_impl->active_tree()->LayerById(scroll_layer_->id());
859 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); 859 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset());
860 EndTest(); 860 EndTest();
861 } 861 }
862 862
863 void AfterTest() override { 863 void AfterTest() override {
864 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); 864 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset());
865 } 865 }
866 866
867 private: 867 private:
868 FakeContentLayerClient client_; 868 FakeContentLayerClient client_;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 // After checking this on the sync tree, we will activate, which will cause 1008 // After checking this on the sync tree, we will activate, which will cause
1009 // PrepareTiles to happen again (which races with the test exiting). 1009 // PrepareTiles to happen again (which races with the test exiting).
1010 if (TestEnded()) 1010 if (TestEnded())
1011 return; 1011 return;
1012 1012
1013 scoped_refptr<AnimationTimeline> timeline_impl = 1013 scoped_refptr<AnimationTimeline> timeline_impl =
1014 host_impl->animation_host()->GetTimelineById(timeline_id_); 1014 host_impl->animation_host()->GetTimelineById(timeline_id_);
1015 scoped_refptr<AnimationPlayer> player_impl = 1015 scoped_refptr<AnimationPlayer> player_impl =
1016 timeline_impl->GetPlayerById(player_id_); 1016 timeline_impl->GetPlayerById(player_id_);
1017 1017
1018 LayerImpl* root = host_impl->sync_tree()->root_layer(); 1018 LayerImpl* child = host_impl->sync_tree()->LayerById(layer_->id());
1019 LayerImpl* child = root->children()[0];
1020 Animation* animation = player_impl->element_animations()->GetAnimation( 1019 Animation* animation = player_impl->element_animations()->GetAnimation(
1021 TargetProperty::TRANSFORM); 1020 TargetProperty::TRANSFORM);
1022 1021
1023 // The animation should be starting for the first frame. 1022 // The animation should be starting for the first frame.
1024 EXPECT_EQ(Animation::STARTING, animation->run_state()); 1023 EXPECT_EQ(Animation::STARTING, animation->run_state());
1025 1024
1026 // And the transform should be propogated to the sync tree layer, at its 1025 // And the transform should be propogated to the sync tree layer, at its
1027 // starting state which is 6,7. 1026 // starting state which is 6,7.
1028 gfx::Transform expected_transform; 1027 gfx::Transform expected_transform;
1029 expected_transform.Translate(6.0, 7.0); 1028 expected_transform.Translate(6.0, 7.0);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 if (host_impl->active_tree()->source_frame_number() < 2) 1165 if (host_impl->active_tree()->source_frame_number() < 2)
1167 return; 1166 return;
1168 AnimationHost::AnimationControllerMap controllers_copy = 1167 AnimationHost::AnimationControllerMap controllers_copy =
1169 host_impl->animation_host()->active_animation_controllers_for_testing(); 1168 host_impl->animation_host()->active_animation_controllers_for_testing();
1170 EXPECT_EQ(2u, controllers_copy.size()); 1169 EXPECT_EQ(2u, controllers_copy.size());
1171 for (auto& it : controllers_copy) { 1170 for (auto& it : controllers_copy) {
1172 int id = it.first; 1171 int id = it.first;
1173 if (id == host_impl->RootLayer()->id()) { 1172 if (id == host_impl->RootLayer()->id()) {
1174 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); 1173 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM);
1175 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); 1174 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
1176 } else if (id == host_impl->RootLayer()->children()[0]->id()) { 1175 } else if (id == layer_->id()) {
1177 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); 1176 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY);
1178 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); 1177 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0);
1179 } 1178 }
1180 EndTest(); 1179 EndTest();
1181 } 1180 }
1182 } 1181 }
1183 1182
1184 void AfterTest() override {} 1183 void AfterTest() override {}
1185 1184
1186 private: 1185 private:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1230 // animation still had its own transform node). But nodes can only get 1229 // animation still had its own transform node). But nodes can only get
1231 // added/deleted when something triggers a rebuild. Adding a layer 1230 // added/deleted when something triggers a rebuild. Adding a layer
1232 // triggers a rebuild, and since the layer that had an animation before 1231 // triggers a rebuild, and since the layer that had an animation before
1233 // no longer has one, it doesn't get a transform node in the rebuild. 1232 // no longer has one, it doesn't get a transform node in the rebuild.
1234 layer_->AddChild(Layer::Create()); 1233 layer_->AddChild(Layer::Create());
1235 break; 1234 break;
1236 } 1235 }
1237 } 1236 }
1238 1237
1239 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 1238 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
1240 LayerImpl* root = host_impl->active_tree()->root_layer(); 1239 LayerImpl* child = host_impl->active_tree()->LayerById(layer_->id());
1241 LayerImpl* child = root->children()[0];
1242 switch (host_impl->active_tree()->source_frame_number()) { 1240 switch (host_impl->active_tree()->source_frame_number()) {
1243 case 0: 1241 case 0:
1244 // No animation yet. 1242 // No animation yet.
1245 break; 1243 break;
1246 case 1: 1244 case 1:
1247 // Animation is started. 1245 // Animation is started.
1248 EXPECT_TRUE(child->screen_space_transform_is_animating()); 1246 EXPECT_TRUE(child->screen_space_transform_is_animating());
1249 break; 1247 break;
1250 case 2: { 1248 case 2: {
1251 // The animation is removed, the transform that was set afterward is 1249 // The animation is removed, the transform that was set afterward is
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 break; 1292 break;
1295 case 2: 1293 case 2:
1296 Animation* animation = player_->element_animations()->GetAnimation( 1294 Animation* animation = player_->element_animations()->GetAnimation(
1297 TargetProperty::TRANSFORM); 1295 TargetProperty::TRANSFORM);
1298 player_->RemoveAnimation(animation->id()); 1296 player_->RemoveAnimation(animation->id());
1299 break; 1297 break;
1300 } 1298 }
1301 } 1299 }
1302 1300
1303 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 1301 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
1304 LayerImpl* root = host_impl->sync_tree()->root_layer(); 1302 LayerImpl* child = host_impl->sync_tree()->LayerById(layer_->id());
1305 LayerImpl* child = root->children()[0];
1306 switch (host_impl->sync_tree()->source_frame_number()) { 1303 switch (host_impl->sync_tree()->source_frame_number()) {
1307 case 0: 1304 case 0:
1308 // No animation yet. 1305 // No animation yet.
1309 break; 1306 break;
1310 case 1: 1307 case 1:
1311 // Animation is started. 1308 // Animation is started.
1312 EXPECT_TRUE(child->screen_space_transform_is_animating()); 1309 EXPECT_TRUE(child->screen_space_transform_is_animating());
1313 break; 1310 break;
1314 case 2: 1311 case 2:
1315 // The animation is removed/stopped. 1312 // The animation is removed/stopped.
1316 EXPECT_FALSE(child->screen_space_transform_is_animating()); 1313 EXPECT_FALSE(child->screen_space_transform_is_animating());
1317 EndTest(); 1314 EndTest();
1318 break; 1315 break;
1319 default: 1316 default:
1320 NOTREACHED(); 1317 NOTREACHED();
1321 } 1318 }
1322 } 1319 }
1323 1320
1324 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { 1321 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
1325 LayerImpl* root = host_impl->active_tree()->root_layer(); 1322 LayerImpl* child = host_impl->active_tree()->LayerById(layer_->id());
1326 LayerImpl* child = root->children()[0];
1327 switch (host_impl->active_tree()->source_frame_number()) { 1323 switch (host_impl->active_tree()->source_frame_number()) {
1328 case 0: 1324 case 0:
1329 // No animation yet. 1325 // No animation yet.
1330 break; 1326 break;
1331 case 1: 1327 case 1:
1332 // Animation is started. 1328 // Animation is started.
1333 EXPECT_TRUE(child->screen_space_transform_is_animating()); 1329 EXPECT_TRUE(child->screen_space_transform_is_animating());
1334 break; 1330 break;
1335 case 2: 1331 case 2:
1336 // The animation is removed/stopped. 1332 // The animation is removed/stopped.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 } 1385 }
1390 1386
1391 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { 1387 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override {
1392 switch (host_impl->sync_tree()->source_frame_number()) { 1388 switch (host_impl->sync_tree()->source_frame_number()) {
1393 case 1: 1389 case 1:
1394 PostSetNeedsCommitToMainThread(); 1390 PostSetNeedsCommitToMainThread();
1395 break; 1391 break;
1396 case 2: 1392 case 2:
1397 gfx::Transform expected_transform; 1393 gfx::Transform expected_transform;
1398 expected_transform.Translate(5.f, 5.f); 1394 expected_transform.Translate(5.f, 5.f);
1399 LayerImpl* layer_impl = 1395 LayerImpl* layer_impl = host_impl->sync_tree()->LayerById(layer_->id());
1400 host_impl->sync_tree()->root_layer()->children()[0];
1401 EXPECT_EQ(expected_transform, layer_impl->DrawTransform()); 1396 EXPECT_EQ(expected_transform, layer_impl->DrawTransform());
1402 EndTest(); 1397 EndTest();
1403 break; 1398 break;
1404 } 1399 }
1405 } 1400 }
1406 1401
1407 void UpdateAnimationState(LayerTreeHostImpl* host_impl, 1402 void UpdateAnimationState(LayerTreeHostImpl* host_impl,
1408 bool has_unfinished_animation) override { 1403 bool has_unfinished_animation) override {
1409 if (host_impl->active_tree()->source_frame_number() == 1 && 1404 if (host_impl->active_tree()->source_frame_number() == 1 &&
1410 !has_unfinished_animation && !signalled_) { 1405 !has_unfinished_animation && !signalled_) {
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 private: 1601 private:
1607 scoped_refptr<Layer> layer_; 1602 scoped_refptr<Layer> layer_;
1608 FakeContentLayerClient client_; 1603 FakeContentLayerClient client_;
1609 }; 1604 };
1610 1605
1611 MULTI_THREAD_TEST_F( 1606 MULTI_THREAD_TEST_F(
1612 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); 1607 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit);
1613 1608
1614 } // namespace 1609 } // namespace
1615 } // namespace cc 1610 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_unittest.cc ('k') | cc/trees/layer_tree_host_unittest_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698