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 <set> | 10 #include <set> |
(...skipping 9819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9830 scroll_and_scale_set.top_controls_delta = 0.9f; | 9830 scroll_and_scale_set.top_controls_delta = 0.9f; |
9831 | 9831 |
9832 proto::ScrollAndScaleSet proto; | 9832 proto::ScrollAndScaleSet proto; |
9833 scroll_and_scale_set.ToProtobuf(&proto); | 9833 scroll_and_scale_set.ToProtobuf(&proto); |
9834 ScrollAndScaleSet new_scroll_and_scale_set; | 9834 ScrollAndScaleSet new_scroll_and_scale_set; |
9835 new_scroll_and_scale_set.FromProtobuf(proto); | 9835 new_scroll_and_scale_set.FromProtobuf(proto); |
9836 | 9836 |
9837 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); | 9837 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
9838 } | 9838 } |
9839 | 9839 |
| 9840 TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9841 // Test the behavior of scroll tree builder |
| 9842 // Topology: |
| 9843 // +root1(1) |
| 9844 // +--parent2(2)[should_scroll_on_main_thread & scrollable] |
| 9845 // +----child6(6)[should_scroll_on_main_thread] |
| 9846 // +------grand_child10(10)[should_scroll_on_main_thread] |
| 9847 // +--parent3(3) |
| 9848 // +----child7(7)[scrollable] |
| 9849 // +----child8(8)[scroll_parent=7] |
| 9850 // +------grand_child11(11)[scrollable] |
| 9851 // +--parent4(4) |
| 9852 // +----child9(9) |
| 9853 // +------grand_child12(12) |
| 9854 // +--parent5(5)[contains_non_fast_scrollable_region] |
| 9855 // |
| 9856 // Expected scroll tree topology: |
| 9857 // +property_tree_root---owner:-1 |
| 9858 // +--root---owner:1, id:1 |
| 9859 // +----node---owner:2, id:2 |
| 9860 // +------node---owner:6, id:3 |
| 9861 // +----node---owner:7, id:4 |
| 9862 // +------node---owner:11, id:5 |
| 9863 // +----node---owner:5, id:6 |
| 9864 // |
| 9865 // Extra check: |
| 9866 // scroll_tree_index() of: |
| 9867 // grand_child10:3 |
| 9868 // parent3:1 |
| 9869 // child8:4 |
| 9870 // parent4:1 |
| 9871 // child9:1 |
| 9872 // grand_child12:1 |
| 9873 scoped_refptr<Layer> root1 = Layer::Create(layer_settings()); |
| 9874 scoped_refptr<Layer> parent2 = Layer::Create(layer_settings()); |
| 9875 scoped_refptr<Layer> parent3 = Layer::Create(layer_settings()); |
| 9876 scoped_refptr<Layer> parent4 = Layer::Create(layer_settings()); |
| 9877 scoped_refptr<Layer> parent5 = Layer::Create(layer_settings()); |
| 9878 scoped_refptr<Layer> child6 = Layer::Create(layer_settings()); |
| 9879 scoped_refptr<Layer> child7 = Layer::Create(layer_settings()); |
| 9880 scoped_refptr<Layer> child8 = Layer::Create(layer_settings()); |
| 9881 scoped_refptr<Layer> child9 = Layer::Create(layer_settings()); |
| 9882 scoped_refptr<Layer> grand_child10 = Layer::Create(layer_settings()); |
| 9883 scoped_refptr<Layer> grand_child11 = Layer::Create(layer_settings()); |
| 9884 scoped_refptr<Layer> grand_child12 = Layer::Create(layer_settings()); |
| 9885 |
| 9886 root1->AddChild(parent2); |
| 9887 root1->AddChild(parent3); |
| 9888 root1->AddChild(parent4); |
| 9889 root1->AddChild(parent5); |
| 9890 parent2->AddChild(child6); |
| 9891 parent3->AddChild(child7); |
| 9892 parent3->AddChild(child8); |
| 9893 parent4->AddChild(child9); |
| 9894 child6->AddChild(grand_child10); |
| 9895 child8->AddChild(grand_child11); |
| 9896 child9->AddChild(grand_child12); |
| 9897 host()->SetRootLayer(root1); |
| 9898 |
| 9899 parent2->AddMainThreadScrollingReasons( |
| 9900 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 9901 parent2->SetScrollClipLayerId(root1->id()); |
| 9902 child6->AddMainThreadScrollingReasons( |
| 9903 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 9904 grand_child10->AddMainThreadScrollingReasons( |
| 9905 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 9906 |
| 9907 child7->SetScrollClipLayerId(root1->id()); |
| 9908 child8->SetScrollParent(child7.get()); |
| 9909 grand_child11->SetScrollClipLayerId(root1->id()); |
| 9910 |
| 9911 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 9912 |
| 9913 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get()); |
| 9914 |
| 9915 const int kInvalidPropertyTreeNodeId = -1; |
| 9916 const int kRootPropertyTreeNodeId = 0; |
| 9917 |
| 9918 // Property tree root |
| 9919 ScrollTree scroll_tree = host()->property_trees()->scroll_tree; |
| 9920 ScrollTree expected_scroll_tree; |
| 9921 ScrollNode* property_tree_root = expected_scroll_tree.Node(0); |
| 9922 property_tree_root->id = kRootPropertyTreeNodeId; |
| 9923 property_tree_root->parent_id = kInvalidPropertyTreeNodeId; |
| 9924 property_tree_root->owner_id = kInvalidPropertyTreeNodeId; |
| 9925 property_tree_root->data.scrollable = false; |
| 9926 property_tree_root->data.should_scroll_on_main_thread = false; |
| 9927 property_tree_root->data.contains_non_fast_scrollable_region = false; |
| 9928 property_tree_root->data.transform_id = kRootPropertyTreeNodeId; |
| 9929 |
| 9930 // The node owned by root1 |
| 9931 ScrollNode scroll_root1; |
| 9932 scroll_root1.id = 1; |
| 9933 scroll_root1.owner_id = root1->id(); |
| 9934 scroll_root1.data.transform_id = root1->transform_tree_index(); |
| 9935 expected_scroll_tree.Insert(scroll_root1, 0); |
| 9936 |
| 9937 // The node owned by parent2 |
| 9938 ScrollNode scroll_parent2; |
| 9939 scroll_parent2.id = 2; |
| 9940 scroll_parent2.owner_id = parent2->id(); |
| 9941 scroll_parent2.data.scrollable = true; |
| 9942 scroll_parent2.data.should_scroll_on_main_thread = true; |
| 9943 scroll_parent2.data.transform_id = parent2->transform_tree_index(); |
| 9944 expected_scroll_tree.Insert(scroll_parent2, 1); |
| 9945 |
| 9946 // The node owned by child6 |
| 9947 ScrollNode scroll_child6; |
| 9948 scroll_child6.id = 3; |
| 9949 scroll_child6.owner_id = child6->id(); |
| 9950 scroll_child6.data.should_scroll_on_main_thread = true; |
| 9951 scroll_child6.data.transform_id = child6->transform_tree_index(); |
| 9952 expected_scroll_tree.Insert(scroll_child6, 2); |
| 9953 |
| 9954 // The node owned by child7, child7 also owns a transform node |
| 9955 ScrollNode scroll_child7; |
| 9956 scroll_child7.id = 4; |
| 9957 scroll_child7.owner_id = child7->id(); |
| 9958 scroll_child7.data.scrollable = true; |
| 9959 scroll_child7.data.transform_id = child7->transform_tree_index(); |
| 9960 expected_scroll_tree.Insert(scroll_child7, 1); |
| 9961 |
| 9962 // The node owned by grand_child11, grand_child11 also owns a transform node |
| 9963 ScrollNode scroll_grand_child11; |
| 9964 scroll_grand_child11.id = 5; |
| 9965 scroll_grand_child11.owner_id = grand_child11->id(); |
| 9966 scroll_grand_child11.data.scrollable = true; |
| 9967 scroll_grand_child11.data.transform_id = |
| 9968 grand_child11->transform_tree_index(); |
| 9969 expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 9970 |
| 9971 // The node owned by parent5 |
| 9972 ScrollNode scroll_parent5; |
| 9973 scroll_parent5.id = 8; |
| 9974 scroll_parent5.owner_id = parent5->id(); |
| 9975 scroll_parent5.data.contains_non_fast_scrollable_region = true; |
| 9976 scroll_parent5.data.transform_id = parent5->transform_tree_index(); |
| 9977 expected_scroll_tree.Insert(scroll_parent5, 1); |
| 9978 |
| 9979 expected_scroll_tree.set_needs_update(false); |
| 9980 |
| 9981 EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 9982 |
| 9983 // Check other layers' scroll_tree_index |
| 9984 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 9985 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 9986 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 9987 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 9988 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 9989 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 9990 } |
| 9991 |
9840 } // namespace | 9992 } // namespace |
9841 } // namespace cc | 9993 } // namespace cc |
OLD | NEW |