OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 2534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2545 SetLayerPropertiesForTesting( | 2545 SetLayerPropertiesForTesting( |
2546 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), | 2546 grand_child_of_root, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
2547 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); | 2547 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
2548 SetLayerPropertiesForTesting( | 2548 SetLayerPropertiesForTesting( |
2549 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), | 2549 grand_child_of_rs1, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
2550 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); | 2550 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
2551 SetLayerPropertiesForTesting( | 2551 SetLayerPropertiesForTesting( |
2552 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), | 2552 grand_child_of_rs2, layer_transform, gfx::Point3F(0.25f, 0.f, 0.f), |
2553 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); | 2553 gfx::PointF(2.5f, 0.f), gfx::Size(10, 10), true, false, false); |
2554 | 2554 |
| 2555 parent->layer_tree_impl()->BuildPropertyTreesForTesting(); |
| 2556 |
2555 // Put an animated opacity on the render surface. | 2557 // Put an animated opacity on the render surface. |
2556 AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(), | 2558 AddOpacityTransitionToLayerWithPlayer(render_surface1->id(), timeline_impl(), |
2557 10.0, 1.f, 0.f, false); | 2559 10.0, 1.f, 0.f, false); |
2558 | 2560 |
2559 // Also put an animated opacity on a layer without descendants. | 2561 // Also put an animated opacity on a layer without descendants. |
2560 AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(), | 2562 AddOpacityTransitionToLayerWithPlayer(grand_child_of_root->id(), |
2561 timeline_impl(), 10.0, 1.f, 0.f, false); | 2563 timeline_impl(), 10.0, 1.f, 0.f, false); |
2562 | 2564 |
2563 // Put a transform animation on the render surface. | 2565 // Put a transform animation on the render surface. |
2564 AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(), | 2566 AddAnimatedTransformToLayerWithPlayer(render_surface2->id(), timeline_impl(), |
2565 10.0, 30, 0); | 2567 10.0, 30, 0); |
2566 | 2568 |
2567 // Also put transform animations on grand_child_of_root, and | 2569 // Also put transform animations on grand_child_of_root, and |
2568 // grand_child_of_rs2 | 2570 // grand_child_of_rs2 |
2569 AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(), | 2571 AddAnimatedTransformToLayerWithPlayer(grand_child_of_root->id(), |
2570 timeline_impl(), 10.0, 30, 0); | 2572 timeline_impl(), 10.0, 30, 0); |
2571 AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(), | 2573 AddAnimatedTransformToLayerWithPlayer(grand_child_of_rs2->id(), |
2572 timeline_impl(), 10.0, 30, 0); | 2574 timeline_impl(), 10.0, 30, 0); |
2573 | 2575 |
| 2576 parent->layer_tree_impl()->property_trees()->needs_rebuild = true; |
2574 ExecuteCalculateDrawProperties(parent); | 2577 ExecuteCalculateDrawProperties(parent); |
2575 | 2578 |
2576 // Only layers that are associated with render surfaces should have an actual | 2579 // Only layers that are associated with render surfaces should have an actual |
2577 // RenderSurface() value. | 2580 // RenderSurface() value. |
2578 ASSERT_TRUE(parent->render_surface()); | 2581 ASSERT_TRUE(parent->render_surface()); |
2579 ASSERT_FALSE(child_of_root->render_surface()); | 2582 ASSERT_FALSE(child_of_root->render_surface()); |
2580 ASSERT_FALSE(grand_child_of_root->render_surface()); | 2583 ASSERT_FALSE(grand_child_of_root->render_surface()); |
2581 | 2584 |
2582 ASSERT_TRUE(render_surface1->render_surface()); | 2585 ASSERT_TRUE(render_surface1->render_surface()); |
2583 ASSERT_FALSE(child_of_rs1->render_surface()); | 2586 ASSERT_FALSE(child_of_rs1->render_surface()); |
(...skipping 2560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5144 root->SetDrawsContent(true); | 5147 root->SetDrawsContent(true); |
5145 | 5148 |
5146 std::unique_ptr<LayerImpl> child = | 5149 std::unique_ptr<LayerImpl> child = |
5147 LayerImpl::Create(host_impl.pending_tree(), 2); | 5150 LayerImpl::Create(host_impl.pending_tree(), 2); |
5148 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), | 5151 SetLayerPropertiesForTesting(child.get(), identity_matrix, gfx::Point3F(), |
5149 gfx::PointF(), gfx::Size(50, 50), true, false, | 5152 gfx::PointF(), gfx::Size(50, 50), true, false, |
5150 false); | 5153 false); |
5151 child->SetDrawsContent(true); | 5154 child->SetDrawsContent(true); |
5152 child->SetOpacity(0.0f); | 5155 child->SetOpacity(0.0f); |
5153 | 5156 |
| 5157 const int child_id = child->id(); |
| 5158 root->AddChild(std::move(child)); |
| 5159 root->SetHasRenderSurface(true); |
| 5160 LayerImpl* root_layer = root.get(); |
| 5161 host_impl.pending_tree()->SetRootLayer(std::move(root)); |
| 5162 host_impl.pending_tree()->BuildPropertyTreesForTesting(); |
5154 // Add opacity animation. | 5163 // Add opacity animation. |
5155 scoped_refptr<AnimationTimeline> timeline = | 5164 scoped_refptr<AnimationTimeline> timeline = |
5156 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); | 5165 AnimationTimeline::Create(AnimationIdProvider::NextTimelineId()); |
5157 host_impl.animation_host()->AddAnimationTimeline(timeline); | 5166 host_impl.animation_host()->AddAnimationTimeline(timeline); |
5158 | 5167 |
5159 AddOpacityTransitionToLayerWithPlayer(child->id(), timeline, 10.0, 0.0f, 1.0f, | 5168 AddOpacityTransitionToLayerWithPlayer(child_id, timeline, 10.0, 0.0f, 1.0f, |
5160 false); | 5169 false); |
5161 | 5170 |
5162 root->AddChild(std::move(child)); | |
5163 root->SetHasRenderSurface(true); | |
5164 LayerImpl* root_layer = root.get(); | |
5165 host_impl.pending_tree()->SetRootLayer(std::move(root)); | |
5166 | |
5167 LayerImplList render_surface_layer_list; | 5171 LayerImplList render_surface_layer_list; |
5168 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 5172 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
5169 root_layer, root_layer->bounds(), &render_surface_layer_list); | 5173 root_layer, root_layer->bounds(), &render_surface_layer_list); |
5170 inputs.can_adjust_raster_scales = true; | 5174 inputs.can_adjust_raster_scales = true; |
5171 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 5175 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
5172 | 5176 |
5173 // We should have one render surface and two layers. The child | 5177 // We should have one render surface and two layers. The child |
5174 // layer should be included even though it is transparent. | 5178 // layer should be included even though it is transparent. |
5175 ASSERT_EQ(1u, render_surface_layer_list.size()); | 5179 ASSERT_EQ(1u, render_surface_layer_list.size()); |
5176 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); | 5180 ASSERT_EQ(2u, root_layer->render_surface()->layer_list().size()); |
(...skipping 4630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9807 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || | 9811 is_inf_or_nan = std::isinf(child->DrawTransform().matrix().get(1, 1)) || |
9808 std::isnan(child->DrawTransform().matrix().get(1, 1)); | 9812 std::isnan(child->DrawTransform().matrix().get(1, 1)); |
9809 EXPECT_TRUE(is_inf_or_nan); | 9813 EXPECT_TRUE(is_inf_or_nan); |
9810 | 9814 |
9811 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl(); | 9815 std::vector<LayerImpl*>* rsll = render_surface_layer_list_impl(); |
9812 bool root_in_rsll = | 9816 bool root_in_rsll = |
9813 std::find(rsll->begin(), rsll->end(), root) != rsll->end(); | 9817 std::find(rsll->begin(), rsll->end(), root) != rsll->end(); |
9814 EXPECT_TRUE(root_in_rsll); | 9818 EXPECT_TRUE(root_in_rsll); |
9815 } | 9819 } |
9816 | 9820 |
| 9821 TEST_F(LayerTreeHostCommonTest, OpacityAnimationsTrackingTest) { |
| 9822 const gfx::Transform identity_matrix; |
| 9823 scoped_refptr<Layer> root = Layer::Create(); |
| 9824 scoped_refptr<LayerWithForcedDrawsContent> animated = |
| 9825 make_scoped_refptr(new LayerWithForcedDrawsContent()); |
| 9826 root->AddChild(animated); |
| 9827 |
| 9828 host()->SetRootLayer(root); |
| 9829 |
| 9830 SetLayerPropertiesForTesting(root.get(), identity_matrix, gfx::Point3F(), |
| 9831 gfx::PointF(), gfx::Size(100, 100), true, false); |
| 9832 SetLayerPropertiesForTesting(animated.get(), identity_matrix, gfx::Point3F(), |
| 9833 gfx::PointF(), gfx::Size(20, 20), true, false); |
| 9834 |
| 9835 root->SetForceRenderSurfaceForTesting(true); |
| 9836 animated->SetOpacity(0.f); |
| 9837 |
| 9838 scoped_refptr<AnimationPlayer> player = |
| 9839 AnimationPlayer::Create(AnimationIdProvider::NextPlayerId()); |
| 9840 timeline()->AttachPlayer(player); |
| 9841 player->AttachElement(animated->id()); |
| 9842 |
| 9843 int animation_id = 0; |
| 9844 std::unique_ptr<Animation> animation = Animation::Create( |
| 9845 std::unique_ptr<AnimationCurve>(new FakeFloatTransition(1.0, 0.f, 1.f)), |
| 9846 animation_id, 1, TargetProperty::OPACITY); |
| 9847 animation->set_fill_mode(Animation::FILL_MODE_NONE); |
| 9848 animation->set_time_offset(base::TimeDelta::FromMilliseconds(-1000)); |
| 9849 Animation* animation_ptr = animation.get(); |
| 9850 AddAnimationToLayerWithExistingPlayer(animated->id(), timeline(), |
| 9851 std::move(animation)); |
| 9852 |
| 9853 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 9854 |
| 9855 EffectTree& tree = root->layer_tree_host()->property_trees()->effect_tree; |
| 9856 EffectNode* node = tree.Node(animated->effect_tree_index()); |
| 9857 EXPECT_FALSE(node->data.is_currently_animating_opacity); |
| 9858 EXPECT_TRUE(node->data.has_potential_opacity_animation); |
| 9859 |
| 9860 animation_ptr->set_time_offset(base::TimeDelta::FromMilliseconds(0)); |
| 9861 root->layer_tree_host()->AnimateLayers( |
| 9862 base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max())); |
| 9863 node = tree.Node(animated->effect_tree_index()); |
| 9864 EXPECT_TRUE(node->data.is_currently_animating_opacity); |
| 9865 EXPECT_TRUE(node->data.has_potential_opacity_animation); |
| 9866 |
| 9867 player->AbortAnimations(TargetProperty::OPACITY, false /*needs_completion*/); |
| 9868 node = tree.Node(animated->effect_tree_index()); |
| 9869 EXPECT_FALSE(node->data.is_currently_animating_opacity); |
| 9870 EXPECT_FALSE(node->data.has_potential_opacity_animation); |
| 9871 } |
| 9872 |
9817 TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { | 9873 TEST_F(LayerTreeHostCommonTest, SerializeScrollUpdateInfo) { |
9818 LayerTreeHostCommon::ScrollUpdateInfo scroll; | 9874 LayerTreeHostCommon::ScrollUpdateInfo scroll; |
9819 scroll.layer_id = 2; | 9875 scroll.layer_id = 2; |
9820 scroll.scroll_delta = gfx::Vector2d(5, 10); | 9876 scroll.scroll_delta = gfx::Vector2d(5, 10); |
9821 | 9877 |
9822 proto::ScrollUpdateInfo proto; | 9878 proto::ScrollUpdateInfo proto; |
9823 scroll.ToProtobuf(&proto); | 9879 scroll.ToProtobuf(&proto); |
9824 LayerTreeHostCommon::ScrollUpdateInfo new_scroll; | 9880 LayerTreeHostCommon::ScrollUpdateInfo new_scroll; |
9825 new_scroll.FromProtobuf(proto); | 9881 new_scroll.FromProtobuf(proto); |
9826 | 9882 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10039 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 10095 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
10040 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 10096 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
10041 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 10097 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
10042 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 10098 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
10043 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 10099 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
10044 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 10100 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
10045 } | 10101 } |
10046 | 10102 |
10047 } // namespace | 10103 } // namespace |
10048 } // namespace cc | 10104 } // namespace cc |
OLD | NEW |