| 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 <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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 274 } |
| 275 | 275 |
| 276 void BeginTest() override { | 276 void BeginTest() override { |
| 277 PostAddAnimationToMainThreadPlayer(player_child_.get()); | 277 PostAddAnimationToMainThreadPlayer(player_child_.get()); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void AnimateLayers(LayerTreeHostImpl* host_impl, | 280 void AnimateLayers(LayerTreeHostImpl* host_impl, |
| 281 base::TimeTicks monotonic_time) override { | 281 base::TimeTicks monotonic_time) override { |
| 282 // TODO(ajuma): This test only checks the active tree. Add checks for | 282 // TODO(ajuma): This test only checks the active tree. Add checks for |
| 283 // pending tree too. | 283 // pending tree too. |
| 284 if (!host_impl->active_tree()->root_layer()) | 284 if (!host_impl->active_tree()->root_layer_for_testing()) |
| 285 return; | 285 return; |
| 286 | 286 |
| 287 // Wait for the commit with the animation to happen. | 287 // Wait for the commit with the animation to happen. |
| 288 if (host_impl->sync_tree()->source_frame_number() != 0) | 288 if (host_impl->sync_tree()->source_frame_number() != 0) |
| 289 return; | 289 return; |
| 290 | 290 |
| 291 scoped_refptr<AnimationTimeline> timeline_impl = | 291 scoped_refptr<AnimationTimeline> timeline_impl = |
| 292 host_impl->animation_host()->GetTimelineById(timeline_id_); | 292 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 293 scoped_refptr<AnimationPlayer> player_child_impl = | 293 scoped_refptr<AnimationPlayer> player_child_impl = |
| 294 timeline_impl->GetPlayerById(player_child_id_); | 294 timeline_impl->GetPlayerById(player_child_id_); |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 | 1003 |
| 1004 void AfterTest() override { | 1004 void AfterTest() override { |
| 1005 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); | 1005 EXPECT_EQ(final_postion_, scroll_layer_->scroll_offset()); |
| 1006 } | 1006 } |
| 1007 | 1007 |
| 1008 private: | 1008 private: |
| 1009 bool ShouldBlockActivation(LayerTreeHostImpl* host_impl) { | 1009 bool ShouldBlockActivation(LayerTreeHostImpl* host_impl) { |
| 1010 if (!host_impl->pending_tree()) | 1010 if (!host_impl->pending_tree()) |
| 1011 return false; | 1011 return false; |
| 1012 | 1012 |
| 1013 if (!host_impl->active_tree()->root_layer()) | 1013 if (!host_impl->active_tree()->root_layer_for_testing()) |
| 1014 return false; | 1014 return false; |
| 1015 | 1015 |
| 1016 scoped_refptr<AnimationTimeline> timeline_impl = | 1016 scoped_refptr<AnimationTimeline> timeline_impl = |
| 1017 host_impl->animation_host()->GetTimelineById(timeline_id_); | 1017 host_impl->animation_host()->GetTimelineById(timeline_id_); |
| 1018 scoped_refptr<AnimationPlayer> player_impl = | 1018 scoped_refptr<AnimationPlayer> player_impl = |
| 1019 timeline_impl->GetPlayerById(player_child_id_); | 1019 timeline_impl->GetPlayerById(player_child_id_); |
| 1020 | 1020 |
| 1021 LayerImpl* scroll_layer_impl = | 1021 LayerImpl* scroll_layer_impl = |
| 1022 host_impl->active_tree()->LayerById(scroll_layer_->id()); | 1022 host_impl->active_tree()->LayerById(scroll_layer_->id()); |
| 1023 Animation* animation = player_impl->element_animations()->GetAnimation( | 1023 Animation* animation = player_impl->element_animations()->GetAnimation( |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { | 1332 void SwapBuffersOnThread(LayerTreeHostImpl* host_impl, bool result) override { |
| 1333 // After both animations have started, verify that they have valid | 1333 // After both animations have started, verify that they have valid |
| 1334 // start times. | 1334 // start times. |
| 1335 if (host_impl->active_tree()->source_frame_number() < 2) | 1335 if (host_impl->active_tree()->source_frame_number() < 2) |
| 1336 return; | 1336 return; |
| 1337 AnimationHost::ElementToAnimationsMap element_animations_copy = | 1337 AnimationHost::ElementToAnimationsMap element_animations_copy = |
| 1338 host_impl->animation_host()->active_element_animations_for_testing(); | 1338 host_impl->animation_host()->active_element_animations_for_testing(); |
| 1339 EXPECT_EQ(2u, element_animations_copy.size()); | 1339 EXPECT_EQ(2u, element_animations_copy.size()); |
| 1340 for (auto& it : element_animations_copy) { | 1340 for (auto& it : element_animations_copy) { |
| 1341 int id = it.first; | 1341 int id = it.first; |
| 1342 if (id == host_impl->active_tree()->root_layer()->id()) { | 1342 if (id == host_impl->active_tree()->root_layer_for_testing()->id()) { |
| 1343 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); | 1343 Animation* anim = it.second->GetAnimation(TargetProperty::TRANSFORM); |
| 1344 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1344 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1345 } else if (id == layer_->id()) { | 1345 } else if (id == layer_->id()) { |
| 1346 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); | 1346 Animation* anim = it.second->GetAnimation(TargetProperty::OPACITY); |
| 1347 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); | 1347 EXPECT_GT((anim->start_time() - base::TimeTicks()).InSecondsF(), 0); |
| 1348 } | 1348 } |
| 1349 EndTest(); | 1349 EndTest(); |
| 1350 } | 1350 } |
| 1351 } | 1351 } |
| 1352 | 1352 |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 start.AppendTranslate(5.f, 5.f, 0.f); | 1660 start.AppendTranslate(5.f, 5.f, 0.f); |
| 1661 TransformOperations end; | 1661 TransformOperations end; |
| 1662 end.AppendTranslate(5.f, 5.f, 0.f); | 1662 end.AppendTranslate(5.f, 5.f, 0.f); |
| 1663 AddAnimatedTransformToPlayer(player_.get(), 1.0, start, end); | 1663 AddAnimatedTransformToPlayer(player_.get(), 1.0, start, end); |
| 1664 } | 1664 } |
| 1665 | 1665 |
| 1666 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1666 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1667 | 1667 |
| 1668 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1668 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 1669 PropertyTrees* property_trees = host_impl->sync_tree()->property_trees(); | 1669 PropertyTrees* property_trees = host_impl->sync_tree()->property_trees(); |
| 1670 TransformNode* node = property_trees->transform_tree.Node( | 1670 TransformNode* node = |
| 1671 host_impl->sync_tree()->root_layer()->transform_tree_index()); | 1671 property_trees->transform_tree.Node(host_impl->sync_tree() |
| 1672 ->root_layer_for_testing() |
| 1673 ->transform_tree_index()); |
| 1672 gfx::Transform translate; | 1674 gfx::Transform translate; |
| 1673 translate.Translate(5, 5); | 1675 translate.Translate(5, 5); |
| 1674 switch (host_impl->sync_tree()->source_frame_number()) { | 1676 switch (host_impl->sync_tree()->source_frame_number()) { |
| 1675 case 2: | 1677 case 2: |
| 1676 EXPECT_EQ(node->data.local, translate); | 1678 EXPECT_EQ(node->data.local, translate); |
| 1677 EndTest(); | 1679 EndTest(); |
| 1678 break; | 1680 break; |
| 1679 default: | 1681 default: |
| 1680 break; | 1682 break; |
| 1681 } | 1683 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 AttachPlayersToTimeline(); | 1719 AttachPlayersToTimeline(); |
| 1718 player_->AttachElement(layer_tree_host()->root_layer()->id()); | 1720 player_->AttachElement(layer_tree_host()->root_layer()->id()); |
| 1719 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); | 1721 AddAnimatedTransformToPlayer(player_.get(), 1.0, 5, 5); |
| 1720 } | 1722 } |
| 1721 | 1723 |
| 1722 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 1724 void BeginTest() override { PostSetNeedsCommitToMainThread(); } |
| 1723 | 1725 |
| 1724 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 1726 void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { |
| 1725 if (host_impl->pending_tree()->source_frame_number() <= 1) { | 1727 if (host_impl->pending_tree()->source_frame_number() <= 1) { |
| 1726 EXPECT_TRUE(host_impl->pending_tree() | 1728 EXPECT_TRUE(host_impl->pending_tree() |
| 1727 ->root_layer() | 1729 ->root_layer_for_testing() |
| 1728 ->screen_space_transform_is_animating()); | 1730 ->screen_space_transform_is_animating()); |
| 1729 } else { | 1731 } else { |
| 1730 EXPECT_FALSE(host_impl->pending_tree() | 1732 EXPECT_FALSE(host_impl->pending_tree() |
| 1731 ->root_layer() | 1733 ->root_layer_for_testing() |
| 1732 ->screen_space_transform_is_animating()); | 1734 ->screen_space_transform_is_animating()); |
| 1733 } | 1735 } |
| 1734 } | 1736 } |
| 1735 | 1737 |
| 1736 void DidCommit() override { PostSetNeedsCommitToMainThread(); } | 1738 void DidCommit() override { PostSetNeedsCommitToMainThread(); } |
| 1737 | 1739 |
| 1738 void UpdateLayerTreeHost() override { | 1740 void UpdateLayerTreeHost() override { |
| 1739 if (layer_tree_host()->source_frame_number() == 2) { | 1741 if (layer_tree_host()->source_frame_number() == 2) { |
| 1740 // Destroy player. | 1742 // Destroy player. |
| 1741 timeline_->DetachPlayer(player_.get()); | 1743 timeline_->DetachPlayer(player_.get()); |
| 1742 player_ = nullptr; | 1744 player_ = nullptr; |
| 1743 } | 1745 } |
| 1744 } | 1746 } |
| 1745 | 1747 |
| 1746 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | 1748 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, |
| 1747 LayerTreeHostImpl::FrameData* frame_data, | 1749 LayerTreeHostImpl::FrameData* frame_data, |
| 1748 DrawResult draw_result) override { | 1750 DrawResult draw_result) override { |
| 1749 const bool screen_space_transform_is_animating = | 1751 const bool screen_space_transform_is_animating = |
| 1750 host_impl->active_tree() | 1752 host_impl->active_tree() |
| 1751 ->root_layer() | 1753 ->root_layer_for_testing() |
| 1752 ->screen_space_transform_is_animating(); | 1754 ->screen_space_transform_is_animating(); |
| 1753 | 1755 |
| 1754 // Check that screen_space_transform_is_animating changes only once. | 1756 // Check that screen_space_transform_is_animating changes only once. |
| 1755 if (screen_space_transform_is_animating && | 1757 if (screen_space_transform_is_animating && |
| 1756 prev_screen_space_transform_is_animating_) | 1758 prev_screen_space_transform_is_animating_) |
| 1757 EXPECT_FALSE(screen_space_transform_animation_stopped_); | 1759 EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| 1758 if (!screen_space_transform_is_animating && | 1760 if (!screen_space_transform_is_animating && |
| 1759 prev_screen_space_transform_is_animating_) { | 1761 prev_screen_space_transform_is_animating_) { |
| 1760 EXPECT_FALSE(screen_space_transform_animation_stopped_); | 1762 EXPECT_FALSE(screen_space_transform_animation_stopped_); |
| 1761 screen_space_transform_animation_stopped_ = true; | 1763 screen_space_transform_animation_stopped_ = true; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 private: | 1832 private: |
| 1831 scoped_refptr<Layer> layer_; | 1833 scoped_refptr<Layer> layer_; |
| 1832 FakeContentLayerClient client_; | 1834 FakeContentLayerClient client_; |
| 1833 }; | 1835 }; |
| 1834 | 1836 |
| 1835 MULTI_THREAD_TEST_F( | 1837 MULTI_THREAD_TEST_F( |
| 1836 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); | 1838 LayerTreeHostAnimationTestRebuildPropertyTreesOnAnimationSetNeedsCommit); |
| 1837 | 1839 |
| 1838 } // namespace | 1840 } // namespace |
| 1839 } // namespace cc | 1841 } // namespace cc |
| OLD | NEW |