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 6821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6832 gfx::Vector2dF scroll_delta(5.f, 9.f); | 6832 gfx::Vector2dF scroll_delta(5.f, 9.f); |
6833 SetScrollOffsetDelta(scroller, scroll_delta); | 6833 SetScrollOffsetDelta(scroller, scroll_delta); |
6834 | 6834 |
6835 ExecuteCalculateDrawProperties(root); | 6835 ExecuteCalculateDrawProperties(root); |
6836 | 6836 |
6837 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); | 6837 gfx::Vector2dF expected_draw_transform_translation(-7.5f, -13.5f); |
6838 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, | 6838 EXPECT_VECTOR2DF_EQ(expected_draw_transform_translation, |
6839 scroller->DrawTransform().To2dTranslation()); | 6839 scroller->DrawTransform().To2dTranslation()); |
6840 } | 6840 } |
6841 | 6841 |
| 6842 TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithScrollChild) { |
| 6843 // This test verifies that a scrolling child of a scrolling layer doesn't get |
| 6844 // snapped to integer coordinates. |
| 6845 // |
| 6846 // + root |
| 6847 // + container |
| 6848 // + scroller |
| 6849 // + scroll_child |
| 6850 // |
| 6851 scoped_refptr<Layer> root = Layer::Create(); |
| 6852 scoped_refptr<Layer> container = Layer::Create(); |
| 6853 scoped_refptr<Layer> scroller = Layer::Create(); |
| 6854 scoped_refptr<Layer> scroll_child = Layer::Create(); |
| 6855 root->AddChild(container); |
| 6856 root->AddChild(scroll_child); |
| 6857 container->AddChild(scroller); |
| 6858 host()->SetRootLayer(root); |
| 6859 |
| 6860 scroller->SetScrollClipLayerId(container->id()); |
| 6861 scroll_child->SetScrollParent(scroller.get()); |
| 6862 |
| 6863 gfx::Transform rotate; |
| 6864 rotate.RotateAboutYAxis(30); |
| 6865 root->SetBounds(gfx::Size(50, 50)); |
| 6866 container->SetBounds(gfx::Size(50, 50)); |
| 6867 scroller->SetBounds(gfx::Size(100, 100)); |
| 6868 scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6869 scroll_child->SetBounds(gfx::Size(10, 10)); |
| 6870 scroll_child->SetTransform(rotate); |
| 6871 |
| 6872 ExecuteCalculateDrawProperties(root.get()); |
| 6873 |
| 6874 host()->host_impl()->CreatePendingTree(); |
| 6875 host()->CommitAndCreatePendingTree(); |
| 6876 host()->host_impl()->ActivateSyncTree(); |
| 6877 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6878 |
| 6879 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6880 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6881 LayerImpl* scroll_child_impl = layer_tree_impl->LayerById(scroll_child->id()); |
| 6882 gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6883 SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6884 |
| 6885 ExecuteCalculateDrawProperties(root_impl); |
| 6886 |
| 6887 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6888 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6889 scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6890 |
| 6891 gfx::Transform expected_scroll_child_screen_space_transform; |
| 6892 expected_scroll_child_screen_space_transform.Translate(-5.3f, -9.3f); |
| 6893 expected_scroll_child_screen_space_transform.RotateAboutYAxis(30); |
| 6894 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_scroll_child_screen_space_transform, |
| 6895 scroll_child_impl->ScreenSpaceTransform()); |
| 6896 } |
| 6897 |
| 6898 TEST_F(LayerTreeHostCommonTest, ScrollSnappingWithFixedPosChild) { |
| 6899 // This test verifies that a fixed pos child of a scrolling layer doesn't get |
| 6900 // snapped to integer coordinates. |
| 6901 // |
| 6902 // + root |
| 6903 // + container |
| 6904 // + scroller |
| 6905 // + fixed_pos |
| 6906 // |
| 6907 scoped_refptr<Layer> root = Layer::Create(); |
| 6908 scoped_refptr<Layer> container = Layer::Create(); |
| 6909 scoped_refptr<Layer> scroller = Layer::Create(); |
| 6910 scoped_refptr<Layer> fixed_pos = Layer::Create(); |
| 6911 |
| 6912 scroller->SetIsContainerForFixedPositionLayers(true); |
| 6913 |
| 6914 root->AddChild(container); |
| 6915 container->AddChild(scroller); |
| 6916 scroller->AddChild(fixed_pos); |
| 6917 host()->SetRootLayer(root); |
| 6918 |
| 6919 LayerPositionConstraint fixed_position; |
| 6920 fixed_position.set_is_fixed_position(true); |
| 6921 scroller->SetScrollClipLayerId(container->id()); |
| 6922 fixed_pos->SetPositionConstraint(fixed_position); |
| 6923 |
| 6924 root->SetBounds(gfx::Size(50, 50)); |
| 6925 container->SetBounds(gfx::Size(50, 50)); |
| 6926 scroller->SetBounds(gfx::Size(100, 100)); |
| 6927 scroller->SetPosition(gfx::PointF(10.3f, 10.3f)); |
| 6928 fixed_pos->SetBounds(gfx::Size(10, 10)); |
| 6929 |
| 6930 ExecuteCalculateDrawProperties(root.get()); |
| 6931 |
| 6932 host()->host_impl()->CreatePendingTree(); |
| 6933 host()->CommitAndCreatePendingTree(); |
| 6934 host()->host_impl()->ActivateSyncTree(); |
| 6935 LayerTreeImpl* layer_tree_impl = host()->host_impl()->active_tree(); |
| 6936 |
| 6937 LayerImpl* root_impl = layer_tree_impl->LayerById(root->id()); |
| 6938 LayerImpl* scroller_impl = layer_tree_impl->LayerById(scroller->id()); |
| 6939 LayerImpl* fixed_pos_impl = layer_tree_impl->LayerById(fixed_pos->id()); |
| 6940 gfx::Vector2dF scroll_delta(5.f, 9.f); |
| 6941 SetScrollOffsetDelta(scroller_impl, scroll_delta); |
| 6942 |
| 6943 ExecuteCalculateDrawProperties(root_impl); |
| 6944 |
| 6945 gfx::Vector2dF expected_scroller_screen_space_transform_translation(5.f, 1.f); |
| 6946 EXPECT_VECTOR2DF_EQ(expected_scroller_screen_space_transform_translation, |
| 6947 scroller_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6948 |
| 6949 gfx::Vector2dF expected_fixed_pos_screen_space_transform_translation(10.3f, |
| 6950 10.3f); |
| 6951 EXPECT_VECTOR2DF_EQ(expected_fixed_pos_screen_space_transform_translation, |
| 6952 fixed_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
| 6953 } |
| 6954 |
6842 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { | 6955 class AnimationScaleFactorTrackingLayerImpl : public LayerImpl { |
6843 public: | 6956 public: |
6844 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( | 6957 static std::unique_ptr<AnimationScaleFactorTrackingLayerImpl> Create( |
6845 LayerTreeImpl* tree_impl, | 6958 LayerTreeImpl* tree_impl, |
6846 int id) { | 6959 int id) { |
6847 return base::WrapUnique( | 6960 return base::WrapUnique( |
6848 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); | 6961 new AnimationScaleFactorTrackingLayerImpl(tree_impl, id)); |
6849 } | 6962 } |
6850 | 6963 |
6851 ~AnimationScaleFactorTrackingLayerImpl() override {} | 6964 ~AnimationScaleFactorTrackingLayerImpl() override {} |
(...skipping 2746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9598 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 9711 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
9599 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 9712 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
9600 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 9713 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
9601 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 9714 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
9602 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 9715 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
9603 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 9716 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
9604 } | 9717 } |
9605 | 9718 |
9606 } // namespace | 9719 } // namespace |
9607 } // namespace cc | 9720 } // namespace cc |
OLD | NEW |