OLD | NEW |
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 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 const BeginFrameArgs& args) override { | 734 const BeginFrameArgs& args) override { |
735 if (!host_impl->pending_tree()) | 735 if (!host_impl->pending_tree()) |
736 return; | 736 return; |
737 | 737 |
738 if (!host_impl->active_tree()->root_layer()) { | 738 if (!host_impl->active_tree()->root_layer()) { |
739 host_impl->BlockNotifyReadyToActivateForTesting(false); | 739 host_impl->BlockNotifyReadyToActivateForTesting(false); |
740 return; | 740 return; |
741 } | 741 } |
742 | 742 |
743 LayerImpl* scroll_layer_impl = | 743 LayerImpl* scroll_layer_impl = |
744 host_impl->active_tree()->root_layer()->children()[0]; | 744 host_impl->active_tree()->root_layer()->children()[0].get(); |
745 Animation* animation = | 745 Animation* animation = |
746 scroll_layer_impl->layer_animation_controller()->GetAnimation( | 746 scroll_layer_impl->layer_animation_controller()->GetAnimation( |
747 Animation::SCROLL_OFFSET); | 747 Animation::SCROLL_OFFSET); |
748 | 748 |
749 if (!animation || animation->run_state() != Animation::RUNNING) { | 749 if (!animation || animation->run_state() != Animation::RUNNING) { |
750 host_impl->BlockNotifyReadyToActivateForTesting(false); | 750 host_impl->BlockNotifyReadyToActivateForTesting(false); |
751 return; | 751 return; |
752 } | 752 } |
753 | 753 |
754 // Block activation until the running animation has a chance to produce a | 754 // Block activation until the running animation has a chance to produce a |
755 // scroll delta. | 755 // scroll delta. |
756 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); | 756 gfx::Vector2dF scroll_delta = scroll_layer_impl->ScrollDelta(); |
757 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) | 757 if (scroll_delta.x() < 1.f || scroll_delta.y() < 1.f) |
758 return; | 758 return; |
759 | 759 |
760 host_impl->BlockNotifyReadyToActivateForTesting(false); | 760 host_impl->BlockNotifyReadyToActivateForTesting(false); |
761 } | 761 } |
762 | 762 |
763 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 763 void WillActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
764 if (host_impl->pending_tree()->source_frame_number() != 1) | 764 if (host_impl->pending_tree()->source_frame_number() != 1) |
765 return; | 765 return; |
766 LayerImpl* scroll_layer_impl = | 766 LayerImpl* scroll_layer_impl = |
767 host_impl->pending_tree()->root_layer()->children()[0]; | 767 host_impl->pending_tree()->root_layer()->children()[0].get(); |
768 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); | 768 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
769 } | 769 } |
770 | 770 |
771 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 771 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { |
772 if (host_impl->active_tree()->source_frame_number() != 1) | 772 if (host_impl->active_tree()->source_frame_number() != 1) |
773 return; | 773 return; |
774 LayerImpl* scroll_layer_impl = | 774 LayerImpl* scroll_layer_impl = |
775 host_impl->active_tree()->root_layer()->children()[0]; | 775 host_impl->active_tree()->root_layer()->children()[0].get(); |
776 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); | 776 EXPECT_EQ(final_postion_, scroll_layer_impl->CurrentScrollOffset()); |
777 EndTest(); | 777 EndTest(); |
778 } | 778 } |
779 | 779 |
780 void AfterTest() override { | 780 void AfterTest() override { |
781 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 781 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
782 } | 782 } |
783 | 783 |
784 private: | 784 private: |
785 FakeContentLayerClient client_; | 785 FakeContentLayerClient client_; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { | 903 void WillPrepareTiles(LayerTreeHostImpl* host_impl) override { |
904 if (host_impl->sync_tree()->source_frame_number() != 0) | 904 if (host_impl->sync_tree()->source_frame_number() != 0) |
905 return; | 905 return; |
906 | 906 |
907 // After checking this on the sync tree, we will activate, which will cause | 907 // After checking this on the sync tree, we will activate, which will cause |
908 // PrepareTiles to happen again (which races with the test exiting). | 908 // PrepareTiles to happen again (which races with the test exiting). |
909 if (TestEnded()) | 909 if (TestEnded()) |
910 return; | 910 return; |
911 | 911 |
912 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 912 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
913 LayerImpl* child = root->children()[0]; | 913 LayerImpl* child = root->children()[0].get(); |
914 LayerAnimationController* controller_impl = | 914 LayerAnimationController* controller_impl = |
915 child->layer_animation_controller(); | 915 child->layer_animation_controller(); |
916 Animation* animation = controller_impl->GetAnimation(Animation::TRANSFORM); | 916 Animation* animation = controller_impl->GetAnimation(Animation::TRANSFORM); |
917 | 917 |
918 // The animation should be starting for the first frame. | 918 // The animation should be starting for the first frame. |
919 EXPECT_EQ(Animation::STARTING, animation->run_state()); | 919 EXPECT_EQ(Animation::STARTING, animation->run_state()); |
920 | 920 |
921 // And the transform should be propogated to the sync tree layer, at its | 921 // And the transform should be propogated to the sync tree layer, at its |
922 // starting state which is 6,7. | 922 // starting state which is 6,7. |
923 gfx::Transform expected_transform; | 923 gfx::Transform expected_transform; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 // added/deleted when something triggers a rebuild. Adding a layer | 1081 // added/deleted when something triggers a rebuild. Adding a layer |
1082 // triggers a rebuild, and since the layer that had an animation before | 1082 // triggers a rebuild, and since the layer that had an animation before |
1083 // no longer has one, it doesn't get a transform node in the rebuild. | 1083 // no longer has one, it doesn't get a transform node in the rebuild. |
1084 layer_->AddChild(Layer::Create(layer_settings())); | 1084 layer_->AddChild(Layer::Create(layer_settings())); |
1085 break; | 1085 break; |
1086 } | 1086 } |
1087 } | 1087 } |
1088 | 1088 |
1089 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 1089 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
1090 LayerImpl* root = host_impl->active_tree()->root_layer(); | 1090 LayerImpl* root = host_impl->active_tree()->root_layer(); |
1091 LayerImpl* child = root->children()[0]; | 1091 LayerImpl* child = root->children()[0].get(); |
1092 switch (host_impl->active_tree()->source_frame_number()) { | 1092 switch (host_impl->active_tree()->source_frame_number()) { |
1093 case 0: | 1093 case 0: |
1094 // No animation yet. | 1094 // No animation yet. |
1095 break; | 1095 break; |
1096 case 1: | 1096 case 1: |
1097 // Animation is started. | 1097 // Animation is started. |
1098 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1098 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
1099 break; | 1099 break; |
1100 case 2: { | 1100 case 2: { |
1101 // The animation is removed, the transform that was set afterward is | 1101 // The animation is removed, the transform that was set afterward is |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 LayerAnimationController* controller = | 1142 LayerAnimationController* controller = |
1143 layer_->layer_animation_controller(); | 1143 layer_->layer_animation_controller(); |
1144 Animation* animation = controller->GetAnimation(Animation::TRANSFORM); | 1144 Animation* animation = controller->GetAnimation(Animation::TRANSFORM); |
1145 layer_->RemoveAnimation(animation->id()); | 1145 layer_->RemoveAnimation(animation->id()); |
1146 break; | 1146 break; |
1147 } | 1147 } |
1148 } | 1148 } |
1149 | 1149 |
1150 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1150 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
1151 LayerImpl* root = host_impl->sync_tree()->root_layer(); | 1151 LayerImpl* root = host_impl->sync_tree()->root_layer(); |
1152 LayerImpl* child = root->children()[0]; | 1152 LayerImpl* child = root->children()[0].get(); |
1153 switch (host_impl->sync_tree()->source_frame_number()) { | 1153 switch (host_impl->sync_tree()->source_frame_number()) { |
1154 case 0: | 1154 case 0: |
1155 // No animation yet. | 1155 // No animation yet. |
1156 break; | 1156 break; |
1157 case 1: | 1157 case 1: |
1158 // Animation is started. | 1158 // Animation is started. |
1159 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1159 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
1160 break; | 1160 break; |
1161 case 2: | 1161 case 2: |
1162 // The animation is removed/stopped. | 1162 // The animation is removed/stopped. |
1163 EXPECT_FALSE(child->screen_space_transform_is_animating()); | 1163 EXPECT_FALSE(child->screen_space_transform_is_animating()); |
1164 EndTest(); | 1164 EndTest(); |
1165 break; | 1165 break; |
1166 default: | 1166 default: |
1167 NOTREACHED(); | 1167 NOTREACHED(); |
1168 } | 1168 } |
1169 } | 1169 } |
1170 | 1170 |
1171 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 1171 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |
1172 LayerImpl* root = host_impl->active_tree()->root_layer(); | 1172 LayerImpl* root = host_impl->active_tree()->root_layer(); |
1173 LayerImpl* child = root->children()[0]; | 1173 LayerImpl* child = root->children()[0].get(); |
1174 switch (host_impl->active_tree()->source_frame_number()) { | 1174 switch (host_impl->active_tree()->source_frame_number()) { |
1175 case 0: | 1175 case 0: |
1176 // No animation yet. | 1176 // No animation yet. |
1177 break; | 1177 break; |
1178 case 1: | 1178 case 1: |
1179 // Animation is started. | 1179 // Animation is started. |
1180 EXPECT_TRUE(child->screen_space_transform_is_animating()); | 1180 EXPECT_TRUE(child->screen_space_transform_is_animating()); |
1181 break; | 1181 break; |
1182 case 2: | 1182 case 2: |
1183 // The animation is removed/stopped. | 1183 // The animation is removed/stopped. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 | 1231 |
1232 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1232 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
1233 switch (host_impl->sync_tree()->source_frame_number()) { | 1233 switch (host_impl->sync_tree()->source_frame_number()) { |
1234 case 1: | 1234 case 1: |
1235 PostSetNeedsCommitToMainThread(); | 1235 PostSetNeedsCommitToMainThread(); |
1236 break; | 1236 break; |
1237 case 2: | 1237 case 2: |
1238 gfx::Transform expected_transform; | 1238 gfx::Transform expected_transform; |
1239 expected_transform.Translate(5.f, 5.f); | 1239 expected_transform.Translate(5.f, 5.f); |
1240 LayerImpl* layer_impl = | 1240 LayerImpl* layer_impl = |
1241 host_impl->sync_tree()->root_layer()->children()[0]; | 1241 host_impl->sync_tree()->root_layer()->children()[0].get(); |
1242 EXPECT_EQ(expected_transform, layer_impl->draw_transform()); | 1242 EXPECT_EQ(expected_transform, layer_impl->draw_transform()); |
1243 EndTest(); | 1243 EndTest(); |
1244 break; | 1244 break; |
1245 } | 1245 } |
1246 } | 1246 } |
1247 | 1247 |
1248 void UpdateAnimationState(LayerTreeHostImpl* host_impl, | 1248 void UpdateAnimationState(LayerTreeHostImpl* host_impl, |
1249 bool has_unfinished_animation) override { | 1249 bool has_unfinished_animation) override { |
1250 if (host_impl->active_tree()->source_frame_number() == 1 && | 1250 if (host_impl->active_tree()->source_frame_number() == 1 && |
1251 !has_unfinished_animation && !signalled_) { | 1251 !has_unfinished_animation && !signalled_) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 bool called_animation_finished_; | 1312 bool called_animation_finished_; |
1313 FakeContentLayerClient client_; | 1313 FakeContentLayerClient client_; |
1314 scoped_refptr<FakePictureLayer> picture_; | 1314 scoped_refptr<FakePictureLayer> picture_; |
1315 }; | 1315 }; |
1316 | 1316 |
1317 SINGLE_AND_MULTI_THREAD_TEST_F( | 1317 SINGLE_AND_MULTI_THREAD_TEST_F( |
1318 LayerTreeHostAnimationTestNotifyAnimationFinished); | 1318 LayerTreeHostAnimationTestNotifyAnimationFinished); |
1319 | 1319 |
1320 } // namespace | 1320 } // namespace |
1321 } // namespace cc | 1321 } // namespace cc |
OLD | NEW |