| 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 kDeviceScale)); | 598 kDeviceScale)); |
| 599 expected_transform.Scale(page_scale * kDeviceScale, | 599 expected_transform.Scale(page_scale * kDeviceScale, |
| 600 page_scale * kDeviceScale); | 600 page_scale * kDeviceScale); |
| 601 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, | 601 EXPECT_TRANSFORMATION_MATRIX_EQ(expected_transform, |
| 602 sublayer->DrawTransform()); | 602 sublayer->DrawTransform()); |
| 603 | 603 |
| 604 // Test that page scale is updated even when we don't rebuild property trees. | 604 // Test that page scale is updated even when we don't rebuild property trees. |
| 605 page_scale = 1.888f; | 605 page_scale = 1.888f; |
| 606 root_layer->layer_tree_impl()->SetViewportLayersFromIds( | 606 root_layer->layer_tree_impl()->SetViewportLayersFromIds( |
| 607 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), | 607 Layer::INVALID_ID, scroll_layer->test_properties()->parent->id(), |
| 608 Layer::INVALID_ID, Layer::INVALID_ID); | 608 Layer::INVALID_ID, Layer::INVALID_ID, Layer::INVALID_ID, |
| 609 Layer::INVALID_ID); |
| 609 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); | 610 root_layer->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale); |
| 610 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); | 611 EXPECT_FALSE(root_layer->layer_tree_impl()->property_trees()->needs_rebuild); |
| 611 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, | 612 ExecuteCalculateDrawProperties(root_layer, kDeviceScale, page_scale, |
| 612 scroll_layer->test_properties()->parent, | 613 scroll_layer->test_properties()->parent, |
| 613 nullptr, nullptr); | 614 nullptr, nullptr); |
| 614 | 615 |
| 615 expected_transform.MakeIdentity(); | 616 expected_transform.MakeIdentity(); |
| 616 expected_transform.Translate( | 617 expected_transform.Translate( |
| 617 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + | 618 MathUtil::Round(kTranslateX * page_scale * kDeviceScale + |
| 618 sub_layer_screen_position.x() * page_scale * | 619 sub_layer_screen_position.x() * page_scale * |
| (...skipping 3484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4103 LayerImpl* scale_surface = AddChild<LayerImpl>(parent); | 4104 LayerImpl* scale_surface = AddChild<LayerImpl>(parent); |
| 4104 scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); | 4105 scale_surface->SetPosition(gfx::PointF(2.f, 2.f)); |
| 4105 scale_surface->SetBounds(gfx::Size(10, 10)); | 4106 scale_surface->SetBounds(gfx::Size(10, 10)); |
| 4106 scale_surface->test_properties()->transform = scale_small_matrix; | 4107 scale_surface->test_properties()->transform = scale_small_matrix; |
| 4107 scale_surface->SetDrawsContent(true); | 4108 scale_surface->SetDrawsContent(true); |
| 4108 scale_surface->test_properties()->force_render_surface = true; | 4109 scale_surface->test_properties()->force_render_surface = true; |
| 4109 | 4110 |
| 4110 float device_scale_factor = 2.5f; | 4111 float device_scale_factor = 2.5f; |
| 4111 float page_scale_factor = 3.f; | 4112 float page_scale_factor = 3.f; |
| 4112 root->layer_tree_impl()->SetViewportLayersFromIds( | 4113 root->layer_tree_impl()->SetViewportLayersFromIds( |
| 4113 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, | 4114 Layer::INVALID_ID, page_scale->id(), Layer::INVALID_ID, Layer::INVALID_ID, |
| 4114 Layer::INVALID_ID); | 4115 Layer::INVALID_ID, Layer::INVALID_ID); |
| 4115 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); | 4116 root->layer_tree_impl()->BuildLayerListAndPropertyTreesForTesting(); |
| 4116 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); | 4117 root->layer_tree_impl()->SetPageScaleOnActiveTree(page_scale_factor); |
| 4117 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, | 4118 ExecuteCalculateDrawProperties(root, device_scale_factor, page_scale_factor, |
| 4118 root, nullptr, nullptr); | 4119 root, nullptr, nullptr); |
| 4119 | 4120 |
| 4120 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, | 4121 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4121 parent->GetIdealContentsScale()); | 4122 parent->GetIdealContentsScale()); |
| 4122 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, | 4123 EXPECT_FLOAT_EQ(device_scale_factor * page_scale_factor, |
| 4123 perspective_surface->GetIdealContentsScale()); | 4124 perspective_surface->GetIdealContentsScale()); |
| 4124 // Ideal scale is the max 2d scale component of the combined transform up to | 4125 // Ideal scale is the max 2d scale component of the combined transform up to |
| (...skipping 2416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6541 } | 6542 } |
| 6542 | 6543 |
| 6543 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { | 6544 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomInnerViewportDelta) { |
| 6544 scoped_refptr<Layer> root = Layer::Create(); | 6545 scoped_refptr<Layer> root = Layer::Create(); |
| 6545 scoped_refptr<Layer> scroller = Layer::Create(); | 6546 scoped_refptr<Layer> scroller = Layer::Create(); |
| 6546 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 6547 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6547 root->AddChild(scroller); | 6548 root->AddChild(scroller); |
| 6548 scroller->AddChild(sticky_pos); | 6549 scroller->AddChild(sticky_pos); |
| 6549 host()->SetRootLayer(root); | 6550 host()->SetRootLayer(root); |
| 6550 scroller->SetScrollClipLayerId(root->id()); | 6551 scroller->SetScrollClipLayerId(root->id()); |
| 6551 host()->RegisterViewportLayers(nullptr, root, scroller, nullptr); | 6552 host()->RegisterViewportLayers(nullptr, root, root, nullptr, scroller, |
| 6553 nullptr); |
| 6552 | 6554 |
| 6553 LayerStickyPositionConstraint sticky_position; | 6555 LayerStickyPositionConstraint sticky_position; |
| 6554 sticky_position.is_sticky = true; | 6556 sticky_position.is_sticky = true; |
| 6555 sticky_position.is_anchored_bottom = true; | 6557 sticky_position.is_anchored_bottom = true; |
| 6556 sticky_position.bottom_offset = 10.0f; | 6558 sticky_position.bottom_offset = 10.0f; |
| 6557 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); | 6559 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 6558 sticky_position.scroll_container_relative_sticky_box_rect = | 6560 sticky_position.scroll_container_relative_sticky_box_rect = |
| 6559 gfx::Rect(0, 70, 10, 10); | 6561 gfx::Rect(0, 70, 10, 10); |
| 6560 sticky_position.scroll_container_relative_containing_block_rect = | 6562 sticky_position.scroll_container_relative_containing_block_rect = |
| 6561 gfx::Rect(0, 60, 100, 100); | 6563 gfx::Rect(0, 60, 100, 100); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6614 scoped_refptr<Layer> outer_clip = Layer::Create(); | 6616 scoped_refptr<Layer> outer_clip = Layer::Create(); |
| 6615 scoped_refptr<Layer> outer_viewport = Layer::Create(); | 6617 scoped_refptr<Layer> outer_viewport = Layer::Create(); |
| 6616 scoped_refptr<Layer> sticky_pos = Layer::Create(); | 6618 scoped_refptr<Layer> sticky_pos = Layer::Create(); |
| 6617 root->AddChild(scroller); | 6619 root->AddChild(scroller); |
| 6618 scroller->AddChild(outer_clip); | 6620 scroller->AddChild(outer_clip); |
| 6619 outer_clip->AddChild(outer_viewport); | 6621 outer_clip->AddChild(outer_viewport); |
| 6620 outer_viewport->AddChild(sticky_pos); | 6622 outer_viewport->AddChild(sticky_pos); |
| 6621 host()->SetRootLayer(root); | 6623 host()->SetRootLayer(root); |
| 6622 scroller->SetScrollClipLayerId(root->id()); | 6624 scroller->SetScrollClipLayerId(root->id()); |
| 6623 outer_viewport->SetScrollClipLayerId(outer_clip->id()); | 6625 outer_viewport->SetScrollClipLayerId(outer_clip->id()); |
| 6624 host()->RegisterViewportLayers(nullptr, root, scroller, outer_viewport); | 6626 host()->RegisterViewportLayers(nullptr, root, root, outer_clip, scroller, |
| 6627 outer_viewport); |
| 6625 | 6628 |
| 6626 LayerStickyPositionConstraint sticky_position; | 6629 LayerStickyPositionConstraint sticky_position; |
| 6627 sticky_position.is_sticky = true; | 6630 sticky_position.is_sticky = true; |
| 6628 sticky_position.is_anchored_bottom = true; | 6631 sticky_position.is_anchored_bottom = true; |
| 6629 sticky_position.bottom_offset = 10.0f; | 6632 sticky_position.bottom_offset = 10.0f; |
| 6630 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); | 6633 sticky_position.parent_relative_sticky_box_offset = gfx::Point(0, 70); |
| 6631 sticky_position.scroll_container_relative_sticky_box_rect = | 6634 sticky_position.scroll_container_relative_sticky_box_rect = |
| 6632 gfx::Rect(0, 70, 10, 10); | 6635 gfx::Rect(0, 70, 10, 10); |
| 6633 sticky_position.scroll_container_relative_containing_block_rect = | 6636 sticky_position.scroll_container_relative_containing_block_rect = |
| 6634 gfx::Rect(0, 60, 100, 100); | 6637 gfx::Rect(0, 60, 100, 100); |
| (...skipping 1481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8116 host_impl.active_tree()->SetRootLayerForTesting( | 8119 host_impl.active_tree()->SetRootLayerForTesting( |
| 8117 LayerImpl::Create(host_impl.active_tree(), 1)); | 8120 LayerImpl::Create(host_impl.active_tree(), 1)); |
| 8118 | 8121 |
| 8119 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); | 8122 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
| 8120 root->SetBounds(root_size); | 8123 root->SetBounds(root_size); |
| 8121 root->SetMasksToBounds(true); | 8124 root->SetMasksToBounds(true); |
| 8122 | 8125 |
| 8123 // Make root the inner viewport scroll layer. This ensures the later call to | 8126 // Make root the inner viewport scroll layer. This ensures the later call to |
| 8124 // |SetViewportBoundsDelta| will be on a viewport layer. | 8127 // |SetViewportBoundsDelta| will be on a viewport layer. |
| 8125 host_impl.active_tree()->SetViewportLayersFromIds( | 8128 host_impl.active_tree()->SetViewportLayersFromIds( |
| 8126 Layer::INVALID_ID, Layer::INVALID_ID, root->id(), Layer::INVALID_ID); | 8129 Layer::INVALID_ID, Layer::INVALID_ID, Layer::INVALID_ID, |
| 8130 Layer::INVALID_ID, root->id(), Layer::INVALID_ID); |
| 8127 | 8131 |
| 8128 root->test_properties()->AddChild( | 8132 root->test_properties()->AddChild( |
| 8129 LayerImpl::Create(host_impl.active_tree(), 2)); | 8133 LayerImpl::Create(host_impl.active_tree(), 2)); |
| 8130 | 8134 |
| 8131 LayerImpl* sublayer = root->test_properties()->children[0]; | 8135 LayerImpl* sublayer = root->test_properties()->children[0]; |
| 8132 sublayer->SetBounds(sublayer_size); | 8136 sublayer->SetBounds(sublayer_size); |
| 8133 sublayer->SetDrawsContent(true); | 8137 sublayer->SetDrawsContent(true); |
| 8134 | 8138 |
| 8135 host_impl.active_tree()->BuildPropertyTreesForTesting(); | 8139 host_impl.active_tree()->BuildPropertyTreesForTesting(); |
| 8136 | 8140 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 8163 | 8167 |
| 8164 inner_viewport_scroll_layer->SetScrollClipLayerId( | 8168 inner_viewport_scroll_layer->SetScrollClipLayerId( |
| 8165 inner_viewport_container_layer->id()); | 8169 inner_viewport_container_layer->id()); |
| 8166 outer_viewport_scroll_layer->SetScrollClipLayerId( | 8170 outer_viewport_scroll_layer->SetScrollClipLayerId( |
| 8167 outer_viewport_container_layer->id()); | 8171 outer_viewport_container_layer->id()); |
| 8168 | 8172 |
| 8169 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); | 8173 inner_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8170 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); | 8174 outer_viewport_scroll_layer->SetIsContainerForFixedPositionLayers(true); |
| 8171 | 8175 |
| 8172 host()->SetRootLayer(root); | 8176 host()->SetRootLayer(root); |
| 8173 host()->RegisterViewportLayers(nullptr, root, inner_viewport_scroll_layer, | 8177 host()->RegisterViewportLayers(nullptr, root, inner_viewport_container_layer, |
| 8178 outer_viewport_container_layer, |
| 8179 inner_viewport_scroll_layer, |
| 8174 outer_viewport_scroll_layer); | 8180 outer_viewport_scroll_layer); |
| 8175 | 8181 |
| 8176 scoped_refptr<Layer> fixed_to_inner = Layer::Create(); | 8182 scoped_refptr<Layer> fixed_to_inner = Layer::Create(); |
| 8177 scoped_refptr<Layer> fixed_to_outer = Layer::Create(); | 8183 scoped_refptr<Layer> fixed_to_outer = Layer::Create(); |
| 8178 | 8184 |
| 8179 inner_viewport_scroll_layer->AddChild(fixed_to_inner); | 8185 inner_viewport_scroll_layer->AddChild(fixed_to_inner); |
| 8180 outer_viewport_scroll_layer->AddChild(fixed_to_outer); | 8186 outer_viewport_scroll_layer->AddChild(fixed_to_outer); |
| 8181 | 8187 |
| 8182 LayerPositionConstraint fixed_to_right; | 8188 LayerPositionConstraint fixed_to_right; |
| 8183 fixed_to_right.set_is_fixed_position(true); | 8189 fixed_to_right.set_is_fixed_position(true); |
| (...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9991 MainThreadScrollingReason::kScrollbarScrolling); | 9997 MainThreadScrollingReason::kScrollbarScrolling); |
| 9992 | 9998 |
| 9993 child7->SetScrollClipLayerId(parent3->id()); | 9999 child7->SetScrollClipLayerId(parent3->id()); |
| 9994 | 10000 |
| 9995 child8->SetScrollParent(child7.get()); | 10001 child8->SetScrollParent(child7.get()); |
| 9996 grand_child11->SetScrollClipLayerId(parent3->id()); | 10002 grand_child11->SetScrollClipLayerId(parent3->id()); |
| 9997 | 10003 |
| 9998 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); | 10004 parent5->SetNonFastScrollableRegion(gfx::Rect(0, 0, 50, 50)); |
| 9999 parent5->SetBounds(gfx::Size(10, 10)); | 10005 parent5->SetBounds(gfx::Size(10, 10)); |
| 10000 | 10006 |
| 10001 host()->RegisterViewportLayers(nullptr, page_scale_layer, parent2, nullptr); | 10007 host()->RegisterViewportLayers(nullptr, page_scale_layer, root1, nullptr, |
| 10008 parent2, nullptr); |
| 10002 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get()); | 10009 ExecuteCalculateDrawPropertiesAndSaveUpdateLayerList(root1.get()); |
| 10003 | 10010 |
| 10004 const int kRootPropertyTreeNodeId = 0; | 10011 const int kRootPropertyTreeNodeId = 0; |
| 10005 | 10012 |
| 10006 // Property tree root | 10013 // Property tree root |
| 10007 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; | 10014 ScrollTree& scroll_tree = host()->property_trees()->scroll_tree; |
| 10008 PropertyTrees property_trees; | 10015 PropertyTrees property_trees; |
| 10009 property_trees.is_main_thread = true; | 10016 property_trees.is_main_thread = true; |
| 10010 property_trees.is_active = false; | 10017 property_trees.is_active = false; |
| 10011 ScrollTree& expected_scroll_tree = property_trees.scroll_tree; | 10018 ScrollTree& expected_scroll_tree = property_trees.scroll_tree; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10148 | 10155 |
| 10149 // Check child layer draw properties. | 10156 // Check child layer draw properties. |
| 10150 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); | 10157 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
| 10151 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); | 10158 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); |
| 10152 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); | 10159 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); |
| 10153 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); | 10160 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); |
| 10154 } | 10161 } |
| 10155 | 10162 |
| 10156 } // namespace | 10163 } // namespace |
| 10157 } // namespace cc | 10164 } // namespace cc |
| OLD | NEW |