| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "cc/animation/layer_animation_controller.h" | 10 #include "cc/animation/layer_animation_controller.h" |
| (...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3036 AddAnimatedTransformToLayer( | 3036 AddAnimatedTransformToLayer( |
| 3037 root.get(), 10.0, start_transform_operations, end_transform_operations); | 3037 root.get(), 10.0, start_transform_operations, end_transform_operations); |
| 3038 | 3038 |
| 3039 EXPECT_TRUE(root->TransformIsAnimating()); | 3039 EXPECT_TRUE(root->TransformIsAnimating()); |
| 3040 | 3040 |
| 3041 ExecuteCalculateDrawProperties(root.get()); | 3041 ExecuteCalculateDrawProperties(root.get()); |
| 3042 | 3042 |
| 3043 EXPECT_FALSE(child->draw_properties().sorted_for_recursion); | 3043 EXPECT_FALSE(child->draw_properties().sorted_for_recursion); |
| 3044 } | 3044 } |
| 3045 | 3045 |
| 3046 TEST_F(LayerTreeHostCommonTest, WillSortAtContextBoundary) { | |
| 3047 // Creates a layer tree that looks as follows: | |
| 3048 // * root (sorting-context-id1) | |
| 3049 // * parent (sorting-context-id2) | |
| 3050 // * child1 (sorting-context-id2) | |
| 3051 // * child2 (sorting-context-id2) | |
| 3052 // | |
| 3053 // This test ensures that we sort at |parent| even though both it and root are | |
| 3054 // set to be 3d sorted. | |
| 3055 FakeImplProxy proxy; | |
| 3056 TestSharedBitmapManager shared_bitmap_manager; | |
| 3057 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | |
| 3058 | |
| 3059 scoped_ptr<LayerImpl> root_ptr(LayerImpl::Create(host_impl.active_tree(), 1)); | |
| 3060 LayerImpl* root = root_ptr.get(); | |
| 3061 scoped_ptr<LayerImpl> parent_ptr( | |
| 3062 LayerImpl::Create(host_impl.active_tree(), 2)); | |
| 3063 LayerImpl* parent = parent_ptr.get(); | |
| 3064 scoped_ptr<LayerImpl> child1_ptr( | |
| 3065 LayerImpl::Create(host_impl.active_tree(), 3)); | |
| 3066 LayerImpl* child1 = child1_ptr.get(); | |
| 3067 scoped_ptr<LayerImpl> child2_ptr( | |
| 3068 LayerImpl::Create(host_impl.active_tree(), 4)); | |
| 3069 LayerImpl* child2 = child2_ptr.get(); | |
| 3070 | |
| 3071 gfx::Transform identity_matrix; | |
| 3072 gfx::Transform below_matrix; | |
| 3073 below_matrix.Translate3d(0.f, 0.f, -10.f); | |
| 3074 gfx::Transform above_matrix; | |
| 3075 above_matrix.Translate3d(0.f, 0.f, 10.f); | |
| 3076 | |
| 3077 SetLayerPropertiesForTesting(root, identity_matrix, gfx::Point3F(), | |
| 3078 gfx::PointF(), gfx::Size(100, 100), true, true, | |
| 3079 true); | |
| 3080 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), | |
| 3081 gfx::PointF(), gfx::Size(50, 50), true, true, | |
| 3082 true); | |
| 3083 SetLayerPropertiesForTesting(child1, above_matrix, gfx::Point3F(), | |
| 3084 gfx::PointF(), gfx::Size(50, 50), true, true, | |
| 3085 false); | |
| 3086 SetLayerPropertiesForTesting(child2, below_matrix, gfx::Point3F(), | |
| 3087 gfx::PointF(), gfx::Size(50, 50), true, true, | |
| 3088 false); | |
| 3089 | |
| 3090 root->Set3dSortingContextId(3); | |
| 3091 root->SetDrawsContent(true); | |
| 3092 parent->Set3dSortingContextId(7); | |
| 3093 parent->SetDrawsContent(true); | |
| 3094 child1->Set3dSortingContextId(7); | |
| 3095 child1->SetDrawsContent(true); | |
| 3096 child2->Set3dSortingContextId(7); | |
| 3097 child2->SetDrawsContent(true); | |
| 3098 | |
| 3099 parent->AddChild(child1_ptr.Pass()); | |
| 3100 parent->AddChild(child2_ptr.Pass()); | |
| 3101 root->AddChild(parent_ptr.Pass()); | |
| 3102 | |
| 3103 LayerImplList render_surface_layer_list; | |
| 3104 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 3105 root_ptr.get(), root->bounds(), &render_surface_layer_list); | |
| 3106 inputs.can_adjust_raster_scales = true; | |
| 3107 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 3108 | |
| 3109 EXPECT_TRUE(root->render_surface()); | |
| 3110 EXPECT_EQ(2u, render_surface_layer_list.size()); | |
| 3111 | |
| 3112 EXPECT_EQ(3u, parent->render_surface()->layer_list().size()); | |
| 3113 EXPECT_EQ(child2->id(), parent->render_surface()->layer_list().at(0)->id()); | |
| 3114 EXPECT_EQ(parent->id(), parent->render_surface()->layer_list().at(1)->id()); | |
| 3115 EXPECT_EQ(child1->id(), parent->render_surface()->layer_list().at(2)->id()); | |
| 3116 } | |
| 3117 | |
| 3118 TEST_F(LayerTreeHostCommonTest, | 3046 TEST_F(LayerTreeHostCommonTest, |
| 3119 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { | 3047 SingularNonAnimatingTransformDoesNotPreventClearingDrawProperties) { |
| 3120 scoped_refptr<Layer> root = Layer::Create(); | 3048 scoped_refptr<Layer> root = Layer::Create(); |
| 3121 | 3049 |
| 3122 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 3050 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 3123 host->SetRootLayer(root); | 3051 host->SetRootLayer(root); |
| 3124 | 3052 |
| 3125 gfx::Transform identity_matrix; | 3053 gfx::Transform identity_matrix; |
| 3126 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); | 3054 gfx::Transform uninvertible_matrix(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); |
| 3127 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); | 3055 ASSERT_FALSE(uninvertible_matrix.IsInvertible()); |
| (...skipping 4525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7653 // right clip, our render_surface_layer_list's order should be unaffected. | 7581 // right clip, our render_surface_layer_list's order should be unaffected. |
| 7654 EXPECT_EQ(3u, render_surface_layer_list.size()); | 7582 EXPECT_EQ(3u, render_surface_layer_list.size()); |
| 7655 EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); | 7583 EXPECT_EQ(root.get(), render_surface_layer_list.at(0)); |
| 7656 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); | 7584 EXPECT_EQ(render_surface2.get(), render_surface_layer_list.at(1)); |
| 7657 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); | 7585 EXPECT_EQ(render_surface1.get(), render_surface_layer_list.at(2)); |
| 7658 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); | 7586 EXPECT_TRUE(render_surface_layer_list.at(0)->render_surface()); |
| 7659 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); | 7587 EXPECT_TRUE(render_surface_layer_list.at(1)->render_surface()); |
| 7660 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); | 7588 EXPECT_TRUE(render_surface_layer_list.at(2)->render_surface()); |
| 7661 } | 7589 } |
| 7662 | 7590 |
| 7663 TEST_F(LayerTreeHostCommonTest, DoNotClobberSorting) { | |
| 7664 // We rearrange layer list contributions if we have to visit children out of | |
| 7665 // order, but it should be a 'stable' rearrangement. That is, the layer list | |
| 7666 // additions for a single layer should not be reordered, though their position | |
| 7667 // wrt to the contributions due to a sibling may vary. | |
| 7668 // | |
| 7669 // + root | |
| 7670 // + scroll_child | |
| 7671 // + top_content | |
| 7672 // + bottom_content | |
| 7673 // + scroll_parent_border | |
| 7674 // + scroll_parent_clip | |
| 7675 // + scroll_parent | |
| 7676 // | |
| 7677 FakeImplProxy proxy; | |
| 7678 TestSharedBitmapManager shared_bitmap_manager; | |
| 7679 FakeLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager); | |
| 7680 host_impl.CreatePendingTree(); | |
| 7681 scoped_ptr<LayerImpl> root = LayerImpl::Create(host_impl.active_tree(), 1); | |
| 7682 scoped_ptr<LayerImpl> scroll_parent_border = | |
| 7683 LayerImpl::Create(host_impl.active_tree(), 2); | |
| 7684 scoped_ptr<LayerImpl> scroll_parent_clip = | |
| 7685 LayerImpl::Create(host_impl.active_tree(), 3); | |
| 7686 scoped_ptr<LayerImpl> scroll_parent = | |
| 7687 LayerImpl::Create(host_impl.active_tree(), 4); | |
| 7688 scoped_ptr<LayerImpl> scroll_child = | |
| 7689 LayerImpl::Create(host_impl.active_tree(), 5); | |
| 7690 scoped_ptr<LayerImpl> bottom_content = | |
| 7691 LayerImpl::Create(host_impl.active_tree(), 6); | |
| 7692 scoped_ptr<LayerImpl> top_content = | |
| 7693 LayerImpl::Create(host_impl.active_tree(), 7); | |
| 7694 | |
| 7695 scroll_parent_clip->SetMasksToBounds(true); | |
| 7696 | |
| 7697 scroll_child->SetScrollParent(scroll_parent.get()); | |
| 7698 scoped_ptr<std::set<LayerImpl*>> scroll_children(new std::set<LayerImpl*>); | |
| 7699 scroll_children->insert(scroll_child.get()); | |
| 7700 scroll_parent->SetScrollChildren(scroll_children.release()); | |
| 7701 | |
| 7702 scroll_child->SetDrawsContent(true); | |
| 7703 scroll_parent->SetDrawsContent(true); | |
| 7704 top_content->SetDrawsContent(true); | |
| 7705 bottom_content->SetDrawsContent(true); | |
| 7706 | |
| 7707 gfx::Transform identity_transform; | |
| 7708 gfx::Transform top_transform; | |
| 7709 top_transform.Translate3d(0.0, 0.0, 5.0); | |
| 7710 gfx::Transform bottom_transform; | |
| 7711 bottom_transform.Translate3d(0.0, 0.0, 3.0); | |
| 7712 | |
| 7713 SetLayerPropertiesForTesting(root.get(), identity_transform, gfx::Point3F(), | |
| 7714 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 7715 true); | |
| 7716 SetLayerPropertiesForTesting(scroll_parent_border.get(), identity_transform, | |
| 7717 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), | |
| 7718 true, false, false); | |
| 7719 SetLayerPropertiesForTesting(scroll_parent_clip.get(), identity_transform, | |
| 7720 gfx::Point3F(), gfx::PointF(), gfx::Size(30, 30), | |
| 7721 true, false, false); | |
| 7722 SetLayerPropertiesForTesting(scroll_parent.get(), identity_transform, | |
| 7723 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), | |
| 7724 true, false, false); | |
| 7725 SetLayerPropertiesForTesting(scroll_child.get(), identity_transform, | |
| 7726 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), | |
| 7727 true, false, false); | |
| 7728 SetLayerPropertiesForTesting(top_content.get(), top_transform, gfx::Point3F(), | |
| 7729 gfx::PointF(), gfx::Size(50, 50), false, true, | |
| 7730 true); | |
| 7731 SetLayerPropertiesForTesting(bottom_content.get(), bottom_transform, | |
| 7732 gfx::Point3F(), gfx::PointF(), gfx::Size(50, 50), | |
| 7733 false, true, true); | |
| 7734 | |
| 7735 scroll_child->SetShouldFlattenTransform(false); | |
| 7736 scroll_child->Set3dSortingContextId(1); | |
| 7737 | |
| 7738 scroll_child->AddChild(top_content.Pass()); | |
| 7739 scroll_child->AddChild(bottom_content.Pass()); | |
| 7740 root->AddChild(scroll_child.Pass()); | |
| 7741 | |
| 7742 scroll_parent_clip->AddChild(scroll_parent.Pass()); | |
| 7743 scroll_parent_border->AddChild(scroll_parent_clip.Pass()); | |
| 7744 root->AddChild(scroll_parent_border.Pass()); | |
| 7745 | |
| 7746 LayerImplList render_surface_layer_list; | |
| 7747 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7748 root.get(), root->bounds(), &render_surface_layer_list); | |
| 7749 | |
| 7750 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7751 | |
| 7752 EXPECT_TRUE(root->render_surface()); | |
| 7753 | |
| 7754 // If we don't sort by depth and let the layers get added in the order they | |
| 7755 // would normally be visited in, then layers 6 and 7 will be out of order. In | |
| 7756 // other words, although we've had to shift 5, 6, and 7 to appear before 4 | |
| 7757 // in the list (because of the scroll parent relationship), this should not | |
| 7758 // have an effect on the the order of 5, 6, and 7 (which had been reordered | |
| 7759 // due to layer sorting). | |
| 7760 EXPECT_EQ(4u, root->render_surface()->layer_list().size()); | |
| 7761 EXPECT_EQ(5, root->render_surface()->layer_list().at(0)->id()); | |
| 7762 EXPECT_EQ(6, root->render_surface()->layer_list().at(1)->id()); | |
| 7763 EXPECT_EQ(7, root->render_surface()->layer_list().at(2)->id()); | |
| 7764 EXPECT_EQ(4, root->render_surface()->layer_list().at(3)->id()); | |
| 7765 } | |
| 7766 | |
| 7767 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { | 7591 TEST_F(LayerTreeHostCommonTest, ScrollCompensationWithRounding) { |
| 7768 // This test verifies that a scrolling layer that gets snapped to | 7592 // This test verifies that a scrolling layer that gets snapped to |
| 7769 // integer coordinates doesn't move a fixed position child. | 7593 // integer coordinates doesn't move a fixed position child. |
| 7770 // | 7594 // |
| 7771 // + root | 7595 // + root |
| 7772 // + container | 7596 // + container |
| 7773 // + scroller | 7597 // + scroller |
| 7774 // + fixed | 7598 // + fixed |
| 7775 // | 7599 // |
| 7776 FakeImplProxy proxy; | 7600 FakeImplProxy proxy; |
| (...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8967 surface->AddChild(box); | 8791 surface->AddChild(box); |
| 8968 | 8792 |
| 8969 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); | 8793 scoped_ptr<FakeLayerTreeHost> host(CreateFakeLayerTreeHost()); |
| 8970 host->SetRootLayer(root); | 8794 host->SetRootLayer(root); |
| 8971 | 8795 |
| 8972 ExecuteCalculateDrawProperties(root.get()); | 8796 ExecuteCalculateDrawProperties(root.get()); |
| 8973 } | 8797 } |
| 8974 | 8798 |
| 8975 } // namespace | 8799 } // namespace |
| 8976 } // namespace cc | 8800 } // namespace cc |
| OLD | NEW |