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 9775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9786 scroll_and_scale_set.top_controls_delta = 0.9f; | 9786 scroll_and_scale_set.top_controls_delta = 0.9f; |
9787 | 9787 |
9788 proto::ScrollAndScaleSet proto; | 9788 proto::ScrollAndScaleSet proto; |
9789 scroll_and_scale_set.ToProtobuf(&proto); | 9789 scroll_and_scale_set.ToProtobuf(&proto); |
9790 ScrollAndScaleSet new_scroll_and_scale_set; | 9790 ScrollAndScaleSet new_scroll_and_scale_set; |
9791 new_scroll_and_scale_set.FromProtobuf(proto); | 9791 new_scroll_and_scale_set.FromProtobuf(proto); |
9792 | 9792 |
9793 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); | 9793 EXPECT_TRUE(scroll_and_scale_set.EqualsForTesting(new_scroll_and_scale_set)); |
9794 } | 9794 } |
9795 | 9795 |
| 9796 TEST_F(LayerTreeHostCommonTest, ScrollTreeBuilderTest) { |
| 9797 // Test the behavior of scroll tree builder |
| 9798 // Topology: |
| 9799 // +root1(1) |
| 9800 // +--parent2(2)[should_scroll_on_main_thread & scroll_blocks_on] |
| 9801 // +----child6(6)[should_scroll_on_main_thread] |
| 9802 // +------grand_child10(10)[should_scroll_on_main_thread] |
| 9803 // +--parent3(3) |
| 9804 // +----child7(7)[scrollable] |
| 9805 // +----child8(8)[scroll_parent=7] |
| 9806 // +------grand_child11(11)[scrollable] |
| 9807 // +--parent4(4)[SCROLL_BLOCKS_ON_START_TOUCH] |
| 9808 // +----child9(9)[SCROLL_BLOCKS_ON_WHEEL_EVENT] |
| 9809 // +------grand_child12(12) |
| 9810 // +--parent5(5)[contains_non_fast_scrollable_region] |
| 9811 // |
| 9812 // Expected scroll tree topology: |
| 9813 // +property_tree_root---owner:-1 |
| 9814 // +--root---owner:1, id:1 |
| 9815 // +----node---owner:2, id:2 |
| 9816 // +------node---owner:6, id:3 |
| 9817 // +----node---owner:7, id:4 |
| 9818 // +------node---owner:11, id:5 |
| 9819 // +----node---owner:4, id:6 |
| 9820 // +------node---owner:9, id:7 |
| 9821 // +----node---owner:5, id:8 |
| 9822 // |
| 9823 // Extra check: |
| 9824 // scroll_tree_index() of: |
| 9825 // grand_child10:3 |
| 9826 // parent3:1 |
| 9827 // child8:4 |
| 9828 // grand_child12:7 |
| 9829 scoped_refptr<Layer> root1 = Layer::Create(layer_settings()); |
| 9830 scoped_refptr<Layer> parent2 = Layer::Create(layer_settings()); |
| 9831 scoped_refptr<Layer> parent3 = Layer::Create(layer_settings()); |
| 9832 scoped_refptr<Layer> parent4 = Layer::Create(layer_settings()); |
| 9833 scoped_refptr<Layer> parent5 = Layer::Create(layer_settings()); |
| 9834 scoped_refptr<Layer> child6 = Layer::Create(layer_settings()); |
| 9835 scoped_refptr<Layer> child7 = Layer::Create(layer_settings()); |
| 9836 scoped_refptr<Layer> child8 = Layer::Create(layer_settings()); |
| 9837 scoped_refptr<Layer> child9 = Layer::Create(layer_settings()); |
| 9838 scoped_refptr<Layer> grand_child10 = Layer::Create(layer_settings()); |
| 9839 scoped_refptr<Layer> grand_child11 = Layer::Create(layer_settings()); |
| 9840 scoped_refptr<Layer> grand_child12 = Layer::Create(layer_settings()); |
| 9841 |
| 9842 root1->AddChild(parent2); |
| 9843 root1->AddChild(parent3); |
| 9844 root1->AddChild(parent4); |
| 9845 root1->AddChild(parent5); |
| 9846 parent2->AddChild(child6); |
| 9847 parent3->AddChild(child7); |
| 9848 parent3->AddChild(child8); |
| 9849 parent4->AddChild(child9); |
| 9850 child6->AddChild(grand_child10); |
| 9851 child8->AddChild(grand_child11); |
| 9852 child9->AddChild(grand_child12); |
| 9853 host()->SetRootLayer(root1); |
| 9854 |
| 9855 parent2->AddMainThreadScrollingReasons( |
| 9856 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 9857 parent2->SetScrollBlocksOn(SCROLL_BLOCKS_ON_SCROLL_EVENT); |
| 9858 child6->AddMainThreadScrollingReasons( |
| 9859 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 9860 grand_child10->AddMainThreadScrollingReasons( |
| 9861 MainThreadScrollingReason::kHasBackgroundAttachmentFixedObjects); |
| 9862 |
| 9863 child7->SetScrollClipLayerId(root1->id()); |
| 9864 child8->SetScrollParent(child7.get()); |
| 9865 grand_child11->SetScrollClipLayerId(root1->id()); |
| 9866 |
| 9867 parent4->SetScrollBlocksOn(SCROLL_BLOCKS_ON_START_TOUCH); |
| 9868 child9->SetScrollBlocksOn(SCROLL_BLOCKS_ON_WHEEL_EVENT); |
| 9869 |
| 9870 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 9871 |
| 9872 ExecuteCalculateDrawPropertiesWithPropertyTrees(root1.get()); |
| 9873 |
| 9874 const int kInvalidPropertyTreeNodeId = -1; |
| 9875 const int kRootPropertyTreeNodeId = 0; |
| 9876 |
| 9877 // Property tree root |
| 9878 ScrollTree scroll_tree = host()->property_trees()->scroll_tree; |
| 9879 ScrollTree expected_scroll_tree; |
| 9880 ScrollNode property_tree_root = *expected_scroll_tree.Node(0); |
| 9881 property_tree_root.id = kRootPropertyTreeNodeId; |
| 9882 property_tree_root.parent_id = kInvalidPropertyTreeNodeId; |
| 9883 property_tree_root.owner_id = kInvalidPropertyTreeNodeId; |
| 9884 property_tree_root.data.scrollable = false; |
| 9885 property_tree_root.data.should_scroll_on_main_thread = false; |
| 9886 property_tree_root.data.scroll_blocks_on = SCROLL_BLOCKS_ON_NONE; |
| 9887 property_tree_root.data.contains_non_fast_scrollable_region = false; |
| 9888 property_tree_root.data.transform_id = kRootPropertyTreeNodeId; |
| 9889 |
| 9890 // The node owned by root1 |
| 9891 ScrollNode scroll_root1; |
| 9892 scroll_root1.id = 1; |
| 9893 scroll_root1.owner_id = root1->id(); |
| 9894 scroll_root1.data.transform_id = root1->transform_tree_index(); |
| 9895 expected_scroll_tree.Insert(scroll_root1, 0); |
| 9896 |
| 9897 // The node owned by parent2 |
| 9898 ScrollNode scroll_parent2; |
| 9899 scroll_parent2.id = 2; |
| 9900 scroll_parent2.owner_id = parent2->id(); |
| 9901 scroll_parent2.data.should_scroll_on_main_thread = true; |
| 9902 scroll_parent2.data.scroll_blocks_on = SCROLL_BLOCKS_ON_SCROLL_EVENT; |
| 9903 scroll_parent2.data.transform_id = parent2->transform_tree_index(); |
| 9904 expected_scroll_tree.Insert(scroll_parent2, 1); |
| 9905 |
| 9906 // The node owned by child6 |
| 9907 ScrollNode scroll_child6; |
| 9908 scroll_child6.id = 3; |
| 9909 scroll_child6.owner_id = child6->id(); |
| 9910 scroll_child6.data.should_scroll_on_main_thread = true; |
| 9911 scroll_child6.data.scroll_blocks_on = SCROLL_BLOCKS_ON_SCROLL_EVENT; |
| 9912 scroll_child6.data.transform_id = child6->transform_tree_index(); |
| 9913 expected_scroll_tree.Insert(scroll_child6, 2); |
| 9914 |
| 9915 // The node owned by child7, child7 also owns a transform node |
| 9916 ScrollNode scroll_child7; |
| 9917 scroll_child7.id = 4; |
| 9918 scroll_child7.owner_id = child7->id(); |
| 9919 scroll_child7.data.scrollable = true; |
| 9920 scroll_child7.data.transform_id = child7->transform_tree_index(); |
| 9921 expected_scroll_tree.Insert(scroll_child7, 1); |
| 9922 |
| 9923 // The node owned by grand_child11, grand_child11 also owns a transform node |
| 9924 ScrollNode scroll_grand_child11; |
| 9925 scroll_grand_child11.id = 5; |
| 9926 scroll_grand_child11.owner_id = grand_child11->id(); |
| 9927 scroll_grand_child11.data.scrollable = true; |
| 9928 scroll_grand_child11.data.transform_id = |
| 9929 grand_child11->transform_tree_index(); |
| 9930 expected_scroll_tree.Insert(scroll_grand_child11, 4); |
| 9931 |
| 9932 // The node owned by parent4 |
| 9933 ScrollNode scroll_parent4; |
| 9934 scroll_parent4.id = 6; |
| 9935 scroll_parent4.owner_id = parent4->id(); |
| 9936 scroll_parent4.data.scroll_blocks_on = SCROLL_BLOCKS_ON_START_TOUCH; |
| 9937 scroll_parent4.data.transform_id = parent4->transform_tree_index(); |
| 9938 expected_scroll_tree.Insert(scroll_parent4, 1); |
| 9939 |
| 9940 // The node owned by child9 |
| 9941 ScrollNode scroll_child9; |
| 9942 scroll_child9.id = 7; |
| 9943 scroll_child9.owner_id = child9->id(); |
| 9944 scroll_child9.data.scroll_blocks_on = |
| 9945 SCROLL_BLOCKS_ON_START_TOUCH | SCROLL_BLOCKS_ON_WHEEL_EVENT; |
| 9946 scroll_child9.data.transform_id = child9->transform_tree_index(); |
| 9947 expected_scroll_tree.Insert(scroll_child9, 6); |
| 9948 |
| 9949 // The node owned by parent5 |
| 9950 ScrollNode scroll_parent5; |
| 9951 scroll_parent5.id = 8; |
| 9952 scroll_parent5.owner_id = parent5->id(); |
| 9953 scroll_parent5.data.contains_non_fast_scrollable_region = true; |
| 9954 scroll_parent5.data.transform_id = parent5->transform_tree_index(); |
| 9955 expected_scroll_tree.Insert(scroll_parent5, 1); |
| 9956 |
| 9957 expected_scroll_tree.set_needs_update(false); |
| 9958 |
| 9959 EXPECT_EQ(expected_scroll_tree, scroll_tree); |
| 9960 |
| 9961 // Check other layers |
| 9962 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 9963 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 9964 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 9965 EXPECT_EQ(scroll_child9.id, grand_child12->scroll_tree_index()); |
| 9966 } |
| 9967 |
9796 } // namespace | 9968 } // namespace |
9797 } // namespace cc | 9969 } // namespace cc |
OLD | NEW |