| 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 7163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7174 fixed_layer->draw_properties().screen_space_transform); | 7174 fixed_layer->draw_properties().screen_space_transform); |
| 7175 EXPECT_VECTOR_EQ( | 7175 EXPECT_VECTOR_EQ( |
| 7176 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | 7176 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), |
| 7177 container_offset); | 7177 container_offset); |
| 7178 | 7178 |
| 7179 container_layer->SetTransform(container_transform); | 7179 container_layer->SetTransform(container_transform); |
| 7180 } | 7180 } |
| 7181 } | 7181 } |
| 7182 | 7182 |
| 7183 TEST_F(LayerTreeHostCommonTest, | 7183 TEST_F(LayerTreeHostCommonTest, |
| 7184 ScrollCompensationMainScrollOffsetFractionalPart) { | |
| 7185 // This test verifies that a scrolling layer that has fractional scroll offset | |
| 7186 // from main doesn't move a fixed position child. | |
| 7187 // | |
| 7188 // + root | |
| 7189 // + container | |
| 7190 // + scroller | |
| 7191 // + fixed | |
| 7192 // | |
| 7193 FakeImplTaskRunnerProvider task_runner_provider; | |
| 7194 TestSharedBitmapManager shared_bitmap_manager; | |
| 7195 TestTaskGraphRunner task_graph_runner; | |
| 7196 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &shared_bitmap_manager, | |
| 7197 &task_graph_runner); | |
| 7198 host_impl.CreatePendingTree(); | |
| 7199 scoped_ptr<LayerImpl> root_ptr = | |
| 7200 LayerImpl::Create(host_impl.active_tree(), 1); | |
| 7201 LayerImpl* root = root_ptr.get(); | |
| 7202 scoped_ptr<LayerImpl> container = | |
| 7203 LayerImpl::Create(host_impl.active_tree(), 2); | |
| 7204 LayerImpl* container_layer = container.get(); | |
| 7205 scoped_ptr<LayerImpl> scroller = | |
| 7206 LayerImpl::Create(host_impl.active_tree(), 3); | |
| 7207 LayerImpl* scroll_layer = scroller.get(); | |
| 7208 scoped_ptr<LayerImpl> fixed = LayerImpl::Create(host_impl.active_tree(), 4); | |
| 7209 LayerImpl* fixed_layer = fixed.get(); | |
| 7210 | |
| 7211 container->SetIsContainerForFixedPositionLayers(true); | |
| 7212 | |
| 7213 LayerPositionConstraint constraint; | |
| 7214 constraint.set_is_fixed_position(true); | |
| 7215 container->SetDrawsContent(true); | |
| 7216 fixed->SetDrawsContent(true); | |
| 7217 fixed->SetPositionConstraint(constraint); | |
| 7218 | |
| 7219 scroller->SetDrawsContent(true); | |
| 7220 scroller->SetScrollClipLayer(container->id()); | |
| 7221 | |
| 7222 gfx::Transform identity_transform; | |
| 7223 gfx::Transform container_transform; | |
| 7224 container_transform.Translate3d(10.0, 20.0, 0.0); | |
| 7225 gfx::Vector2dF container_offset = container_transform.To2dTranslation(); | |
| 7226 | |
| 7227 SetLayerPropertiesForTesting(root, identity_transform, gfx::Point3F(), | |
| 7228 gfx::PointF(), gfx::Size(50, 50), true, false, | |
| 7229 true); | |
| 7230 SetLayerPropertiesForTesting(container.get(), container_transform, | |
| 7231 gfx::Point3F(), gfx::PointF(), gfx::Size(40, 40), | |
| 7232 true, false, false); | |
| 7233 SetLayerPropertiesForTesting(scroller.get(), identity_transform, | |
| 7234 gfx::Point3F(), gfx::PointF(0.0, 0.0), | |
| 7235 gfx::Size(30, 30), true, false, false); | |
| 7236 | |
| 7237 gfx::ScrollOffset scroll_offset(3.3, 4.2); | |
| 7238 gfx::Vector2dF main_scroll_fractional_part(0.3f, 0.2f); | |
| 7239 gfx::Vector2dF scroll_delta(0.1f, 0.4f); | |
| 7240 // Blink only uses the integer part of the scroll_offset for fixed | |
| 7241 // position layer. | |
| 7242 SetLayerPropertiesForTesting(fixed.get(), identity_transform, gfx::Point3F(), | |
| 7243 gfx::PointF(3.0f, 4.0f), gfx::Size(50, 50), true, | |
| 7244 false, false); | |
| 7245 scroll_layer->layer_tree_impl() | |
| 7246 ->property_trees() | |
| 7247 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), | |
| 7248 scroll_offset); | |
| 7249 | |
| 7250 scroll_layer->SetScrollCompensationAdjustment(main_scroll_fractional_part); | |
| 7251 | |
| 7252 scroller->AddChild(std::move(fixed)); | |
| 7253 container->AddChild(std::move(scroller)); | |
| 7254 root->AddChild(std::move(container)); | |
| 7255 | |
| 7256 root->layer_tree_impl()->SetRootLayer(std::move(root_ptr)); | |
| 7257 root->layer_tree_impl()->BuildPropertyTreesForTesting(); | |
| 7258 | |
| 7259 SetScrollOffsetDelta(scroll_layer, scroll_delta); | |
| 7260 | |
| 7261 LayerImplList render_surface_layer_list; | |
| 7262 root->layer_tree_impl()->IncrementRenderSurfaceListIdForTesting(); | |
| 7263 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | |
| 7264 root, root->bounds(), &render_surface_layer_list, | |
| 7265 root->layer_tree_impl()->current_render_surface_list_id()); | |
| 7266 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | |
| 7267 | |
| 7268 EXPECT_TRANSFORMATION_MATRIX_EQ( | |
| 7269 container_layer->draw_properties().screen_space_transform, | |
| 7270 fixed_layer->draw_properties().screen_space_transform); | |
| 7271 EXPECT_VECTOR_EQ( | |
| 7272 fixed_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7273 container_offset); | |
| 7274 | |
| 7275 gfx::ScrollOffset effective_scroll_offset = | |
| 7276 ScrollOffsetWithDelta(scroll_offset, scroll_delta); | |
| 7277 gfx::Vector2d rounded_effective_scroll_offset = | |
| 7278 ToRoundedVector2d(ScrollOffsetToVector2dF(effective_scroll_offset)); | |
| 7279 EXPECT_VECTOR_EQ( | |
| 7280 scroll_layer->draw_properties().screen_space_transform.To2dTranslation(), | |
| 7281 container_offset - rounded_effective_scroll_offset); | |
| 7282 } | |
| 7283 | |
| 7284 TEST_F(LayerTreeHostCommonTest, | |
| 7285 ScrollSnappingWithAnimatedScreenSpaceTransform) { | 7184 ScrollSnappingWithAnimatedScreenSpaceTransform) { |
| 7286 // This test verifies that a scrolling layer whose screen space transform is | 7185 // This test verifies that a scrolling layer whose screen space transform is |
| 7287 // animating doesn't get snapped to integer coordinates. | 7186 // animating doesn't get snapped to integer coordinates. |
| 7288 // | 7187 // |
| 7289 // + root | 7188 // + root |
| 7290 // + animated layer | 7189 // + animated layer |
| 7291 // + surface | 7190 // + surface |
| 7292 // + container | 7191 // + container |
| 7293 // + scroller | 7192 // + scroller |
| 7294 // | 7193 // |
| (...skipping 1328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8623 frame_clip->AddChild(fixed); | 8522 frame_clip->AddChild(fixed); |
| 8624 | 8523 |
| 8625 host()->SetRootLayer(root); | 8524 host()->SetRootLayer(root); |
| 8626 | 8525 |
| 8627 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); | 8526 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); |
| 8628 | 8527 |
| 8629 gfx::Rect expected(0, 0, 100, 100); | 8528 gfx::Rect expected(0, 0, 100, 100); |
| 8630 EXPECT_EQ(expected, fixed->visible_layer_rect()); | 8529 EXPECT_EQ(expected, fixed->visible_layer_rect()); |
| 8631 } | 8530 } |
| 8632 | 8531 |
| 8633 TEST_F(LayerTreeHostCommonTest, | |
| 8634 PropertyTreesAccountForScrollCompensationAdjustment) { | |
| 8635 gfx::Transform identity; | |
| 8636 gfx::Transform translate_z; | |
| 8637 translate_z.Translate3d(0, 0, 10); | |
| 8638 | |
| 8639 scoped_refptr<Layer> root = Layer::Create(); | |
| 8640 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), | |
| 8641 gfx::PointF(), gfx::Size(800, 800), true, false); | |
| 8642 root->SetIsContainerForFixedPositionLayers(true); | |
| 8643 | |
| 8644 scoped_refptr<Layer> frame_clip = Layer::Create(); | |
| 8645 SetLayerPropertiesForTesting(frame_clip.get(), translate_z, gfx::Point3F(), | |
| 8646 gfx::PointF(500, 100), gfx::Size(100, 100), true, | |
| 8647 false); | |
| 8648 frame_clip->SetMasksToBounds(true); | |
| 8649 | |
| 8650 scoped_refptr<LayerWithForcedDrawsContent> scroller = | |
| 8651 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8652 SetLayerPropertiesForTesting(scroller.get(), identity, gfx::Point3F(), | |
| 8653 gfx::PointF(), gfx::Size(1000, 1000), true, | |
| 8654 false); | |
| 8655 | |
| 8656 scroller->SetScrollCompensationAdjustment(gfx::Vector2dF(0.3f, 0.7f)); | |
| 8657 scroller->SetScrollOffset(gfx::ScrollOffset(0.3, 0.7)); | |
| 8658 scroller->SetScrollClipLayerId(frame_clip->id()); | |
| 8659 | |
| 8660 scoped_refptr<LayerWithForcedDrawsContent> fixed = | |
| 8661 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8662 SetLayerPropertiesForTesting(fixed.get(), identity, gfx::Point3F(), | |
| 8663 gfx::PointF(), gfx::Size(50, 50), true, false); | |
| 8664 | |
| 8665 LayerPositionConstraint constraint; | |
| 8666 constraint.set_is_fixed_position(true); | |
| 8667 fixed->SetPositionConstraint(constraint); | |
| 8668 | |
| 8669 scoped_refptr<LayerWithForcedDrawsContent> fixed_child = | |
| 8670 make_scoped_refptr(new LayerWithForcedDrawsContent()); | |
| 8671 SetLayerPropertiesForTesting(fixed_child.get(), identity, gfx::Point3F(), | |
| 8672 gfx::PointF(), gfx::Size(10, 10), true, false); | |
| 8673 | |
| 8674 fixed_child->SetPositionConstraint(constraint); | |
| 8675 | |
| 8676 root->AddChild(frame_clip); | |
| 8677 frame_clip->AddChild(scroller); | |
| 8678 scroller->AddChild(fixed); | |
| 8679 fixed->AddChild(fixed_child); | |
| 8680 | |
| 8681 host()->SetRootLayer(root); | |
| 8682 | |
| 8683 ExecuteCalculateDrawPropertiesWithPropertyTrees(root.get()); | |
| 8684 | |
| 8685 gfx::Rect expected(0, 0, 50, 50); | |
| 8686 EXPECT_EQ(expected, fixed->visible_layer_rect()); | |
| 8687 | |
| 8688 expected = gfx::Rect(0, 0, 10, 10); | |
| 8689 EXPECT_EQ(expected, fixed_child->visible_layer_rect()); | |
| 8690 } | |
| 8691 | |
| 8692 TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { | 8532 TEST_F(LayerTreeHostCommonTest, FixedClipsShouldBeAssociatedWithTheRightNode) { |
| 8693 gfx::Transform identity; | 8533 gfx::Transform identity; |
| 8694 | 8534 |
| 8695 scoped_refptr<Layer> root = Layer::Create(); | 8535 scoped_refptr<Layer> root = Layer::Create(); |
| 8696 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), | 8536 SetLayerPropertiesForTesting(root.get(), identity, gfx::Point3F(), |
| 8697 gfx::PointF(), gfx::Size(800, 800), true, false); | 8537 gfx::PointF(), gfx::Size(800, 800), true, false); |
| 8698 root->SetIsContainerForFixedPositionLayers(true); | 8538 root->SetIsContainerForFixedPositionLayers(true); |
| 8699 | 8539 |
| 8700 scoped_refptr<Layer> frame_clip = Layer::Create(); | 8540 scoped_refptr<Layer> frame_clip = Layer::Create(); |
| 8701 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), | 8541 SetLayerPropertiesForTesting(frame_clip.get(), identity, gfx::Point3F(), |
| (...skipping 1361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10063 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); | 9903 EXPECT_EQ(scroll_child6.id, grand_child10->scroll_tree_index()); |
| 10064 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); | 9904 EXPECT_EQ(scroll_root1.id, parent3->scroll_tree_index()); |
| 10065 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); | 9905 EXPECT_EQ(scroll_child7.id, child8->scroll_tree_index()); |
| 10066 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); | 9906 EXPECT_EQ(scroll_root1.id, parent4->scroll_tree_index()); |
| 10067 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); | 9907 EXPECT_EQ(scroll_root1.id, child9->scroll_tree_index()); |
| 10068 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); | 9908 EXPECT_EQ(scroll_root1.id, grand_child12->scroll_tree_index()); |
| 10069 } | 9909 } |
| 10070 | 9910 |
| 10071 } // namespace | 9911 } // namespace |
| 10072 } // namespace cc | 9912 } // namespace cc |
| OLD | NEW |