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 7325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7336 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); | 7336 LayerImpl* inner_scroll = layer_tree_impl->InnerViewportScrollLayer(); |
7337 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | 7337 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
7338 | 7338 |
7339 // Initially the sticky element is moved to the bottom of the container. | 7339 // Initially the sticky element is moved to the bottom of the container. |
7340 EXPECT_VECTOR2DF_EQ( | 7340 EXPECT_VECTOR2DF_EQ( |
7341 gfx::Vector2dF(0.f, 70.f), | 7341 gfx::Vector2dF(0.f, 70.f), |
7342 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7342 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7343 | 7343 |
7344 // We start to hide the toolbar, but not far enough that the sticky element | 7344 // We start to hide the toolbar, but not far enough that the sticky element |
7345 // should be moved up yet. | 7345 // should be moved up yet. |
7346 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); | 7346 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
7347 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, | 7347 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
7348 nullptr); | 7348 nullptr); |
7349 EXPECT_VECTOR2DF_EQ( | 7349 EXPECT_VECTOR2DF_EQ( |
7350 gfx::Vector2dF(0.f, 70.f), | 7350 gfx::Vector2dF(0.f, 70.f), |
7351 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7351 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7352 | 7352 |
7353 // On hiding more of the toolbar the sticky element starts to stick. | 7353 // On hiding more of the toolbar the sticky element starts to stick. |
7354 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); | 7354 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
7355 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, | 7355 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
7356 nullptr); | 7356 nullptr); |
7357 EXPECT_VECTOR2DF_EQ( | 7357 EXPECT_VECTOR2DF_EQ( |
7358 gfx::Vector2dF(0.f, 60.f), | 7358 gfx::Vector2dF(0.f, 60.f), |
7359 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7359 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7360 | 7360 |
7361 // On hiding more the sticky element stops moving as it has reached its | 7361 // On hiding more the sticky element stops moving as it has reached its |
7362 // limit. | 7362 // limit. |
7363 root_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); | 7363 root_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
7364 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, | 7364 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
7365 nullptr); | 7365 nullptr); |
7366 EXPECT_VECTOR2DF_EQ( | 7366 EXPECT_VECTOR2DF_EQ( |
7367 gfx::Vector2dF(0.f, 60.f), | 7367 gfx::Vector2dF(0.f, 60.f), |
7368 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7368 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7369 } | 7369 } |
7370 | 7370 |
7371 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { | 7371 TEST_F(LayerTreeHostCommonTest, StickyPositionBottomOuterViewportDelta) { |
7372 scoped_refptr<Layer> root = Layer::Create(); | 7372 scoped_refptr<Layer> root = Layer::Create(); |
7373 scoped_refptr<Layer> scroller = Layer::Create(); | 7373 scoped_refptr<Layer> scroller = Layer::Create(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7413 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); | 7413 LayerImpl* sticky_pos_impl = layer_tree_impl->LayerById(sticky_pos->id()); |
7414 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); | 7414 LayerImpl* outer_clip_impl = layer_tree_impl->LayerById(outer_clip->id()); |
7415 | 7415 |
7416 // Initially the sticky element is moved to the bottom of the container. | 7416 // Initially the sticky element is moved to the bottom of the container. |
7417 EXPECT_VECTOR2DF_EQ( | 7417 EXPECT_VECTOR2DF_EQ( |
7418 gfx::Vector2dF(0.f, 70.f), | 7418 gfx::Vector2dF(0.f, 70.f), |
7419 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7419 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7420 | 7420 |
7421 // We start to hide the toolbar, but not far enough that the sticky element | 7421 // We start to hide the toolbar, but not far enough that the sticky element |
7422 // should be moved up yet. | 7422 // should be moved up yet. |
7423 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -10.f)); | 7423 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -10.f)); |
7424 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, | 7424 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
7425 outer_scroll); | 7425 outer_scroll); |
7426 EXPECT_VECTOR2DF_EQ( | 7426 EXPECT_VECTOR2DF_EQ( |
7427 gfx::Vector2dF(0.f, 70.f), | 7427 gfx::Vector2dF(0.f, 70.f), |
7428 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7428 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7429 | 7429 |
7430 // On hiding more of the toolbar the sticky element starts to stick. | 7430 // On hiding more of the toolbar the sticky element starts to stick. |
7431 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -20.f)); | 7431 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -20.f)); |
7432 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, | 7432 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
7433 outer_scroll); | 7433 outer_scroll); |
7434 | 7434 |
7435 // On hiding more the sticky element stops moving as it has reached its | 7435 // On hiding more the sticky element stops moving as it has reached its |
7436 // limit. | 7436 // limit. |
7437 EXPECT_VECTOR2DF_EQ( | 7437 EXPECT_VECTOR2DF_EQ( |
7438 gfx::Vector2dF(0.f, 60.f), | 7438 gfx::Vector2dF(0.f, 60.f), |
7439 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7439 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7440 | 7440 |
7441 outer_clip_impl->SetBoundsDelta(gfx::Vector2dF(0.f, -30.f)); | 7441 outer_clip_impl->SetViewportBoundsDelta(gfx::Vector2dF(0.f, -30.f)); |
7442 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, | 7442 ExecuteCalculateDrawProperties(root_impl, 1.f, 1.f, root_impl, inner_scroll, |
7443 outer_scroll); | 7443 outer_scroll); |
7444 | 7444 |
7445 EXPECT_VECTOR2DF_EQ( | 7445 EXPECT_VECTOR2DF_EQ( |
7446 gfx::Vector2dF(0.f, 60.f), | 7446 gfx::Vector2dF(0.f, 60.f), |
7447 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); | 7447 sticky_pos_impl->ScreenSpaceTransform().To2dTranslation()); |
7448 } | 7448 } |
7449 | 7449 |
7450 TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { | 7450 TEST_F(LayerTreeHostCommonTest, StickyPositionLeftRight) { |
7451 scoped_refptr<Layer> root = Layer::Create(); | 7451 scoped_refptr<Layer> root = Layer::Create(); |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8850 | 8850 |
8851 // Layers in the root render surface have their visible content rect clipped | 8851 // Layers in the root render surface have their visible content rect clipped |
8852 // by the viewport. | 8852 // by the viewport. |
8853 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); | 8853 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), root->visible_layer_rect()); |
8854 | 8854 |
8855 // Layers drawing to a child render surface should still have their visible | 8855 // Layers drawing to a child render surface should still have their visible |
8856 // content rect clipped by the viewport. | 8856 // content rect clipped by the viewport. |
8857 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); | 8857 EXPECT_EQ(gfx::Rect(768 / 2, 582 / 2), content->visible_layer_rect()); |
8858 } | 8858 } |
8859 | 8859 |
8860 TEST_F(LayerTreeHostCommonTest, BoundsDeltaAffectVisibleContentRect) { | 8860 TEST_F(LayerTreeHostCommonTest, ViewportBoundsDeltaAffectVisibleContentRect) { |
8861 FakeImplTaskRunnerProvider task_runner_provider; | 8861 FakeImplTaskRunnerProvider task_runner_provider; |
8862 TestTaskGraphRunner task_graph_runner; | 8862 TestTaskGraphRunner task_graph_runner; |
8863 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); | 8863 FakeLayerTreeHostImpl host_impl(&task_runner_provider, &task_graph_runner); |
8864 | 8864 |
8865 // Set two layers: the root layer clips it's child, | 8865 // Set two layers: the root layer clips it's child, |
8866 // the child draws its content. | 8866 // the child draws its content. |
8867 | 8867 |
8868 gfx::Size root_size = gfx::Size(300, 500); | 8868 gfx::Size root_size = gfx::Size(300, 500); |
8869 | 8869 |
8870 // Sublayer should be bigger than the root enlarged by bounds_delta. | 8870 // Sublayer should be bigger than the root enlarged by bounds_delta. |
8871 gfx::Size sublayer_size = gfx::Size(300, 1000); | 8871 gfx::Size sublayer_size = gfx::Size(300, 1000); |
8872 | 8872 |
8873 // Device viewport accomidated the root and the browser controls. | 8873 // Device viewport accomidated the root and the browser controls. |
8874 gfx::Size device_viewport_size = gfx::Size(300, 600); | 8874 gfx::Size device_viewport_size = gfx::Size(300, 600); |
8875 | 8875 |
8876 host_impl.SetViewportSize(device_viewport_size); | 8876 host_impl.SetViewportSize(device_viewport_size); |
8877 host_impl.active_tree()->SetRootLayerForTesting( | 8877 host_impl.active_tree()->SetRootLayerForTesting( |
8878 LayerImpl::Create(host_impl.active_tree(), 1)); | 8878 LayerImpl::Create(host_impl.active_tree(), 1)); |
8879 | 8879 |
8880 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); | 8880 LayerImpl* root = host_impl.active_tree()->root_layer_for_testing(); |
8881 root->SetBounds(root_size); | 8881 root->SetBounds(root_size); |
8882 root->SetMasksToBounds(true); | 8882 root->SetMasksToBounds(true); |
8883 | 8883 |
| 8884 // Make root the inner viewport scroll layer. This ensures the later call to |
| 8885 // |SetViewportBoundsDelta| will be on a viewport layer. |
| 8886 host_impl.active_tree()->SetViewportLayersFromIds( |
| 8887 Layer::INVALID_ID, Layer::INVALID_ID, root->id(), Layer::INVALID_ID); |
| 8888 |
8884 root->test_properties()->AddChild( | 8889 root->test_properties()->AddChild( |
8885 LayerImpl::Create(host_impl.active_tree(), 2)); | 8890 LayerImpl::Create(host_impl.active_tree(), 2)); |
8886 | 8891 |
8887 LayerImpl* sublayer = root->test_properties()->children[0]; | 8892 LayerImpl* sublayer = root->test_properties()->children[0]; |
8888 sublayer->SetBounds(sublayer_size); | 8893 sublayer->SetBounds(sublayer_size); |
8889 sublayer->SetDrawsContent(true); | 8894 sublayer->SetDrawsContent(true); |
8890 | 8895 |
8891 host_impl.active_tree()->BuildPropertyTreesForTesting(); | 8896 host_impl.active_tree()->BuildPropertyTreesForTesting(); |
8892 | 8897 |
8893 LayerImplList layer_impl_list; | 8898 LayerImplList layer_impl_list; |
8894 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 8899 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
8895 root, device_viewport_size, &layer_impl_list); | 8900 root, device_viewport_size, &layer_impl_list); |
8896 | 8901 |
8897 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 8902 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
8898 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); | 8903 EXPECT_EQ(gfx::Rect(root_size), sublayer->visible_layer_rect()); |
8899 | 8904 |
8900 root->SetBoundsDelta(gfx::Vector2dF(0.0, 50.0)); | 8905 root->SetViewportBoundsDelta(gfx::Vector2dF(0.0, 50.0)); |
8901 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 8906 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
8902 | 8907 |
8903 gfx::Rect affected_by_delta(0, 0, root_size.width(), | 8908 gfx::Rect affected_by_delta(0, 0, root_size.width(), |
8904 root_size.height() + 50); | 8909 root_size.height() + 50); |
8905 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); | 8910 EXPECT_EQ(affected_by_delta, sublayer->visible_layer_rect()); |
8906 } | 8911 } |
8907 | 8912 |
8908 TEST_F(LayerTreeHostCommonTest, NodesAffectedByBoundsDeltaGetUpdated) { | 8913 TEST_F(LayerTreeHostCommonTest, NodesAffectedByViewportBoundsDeltaGetUpdated) { |
8909 scoped_refptr<Layer> root = Layer::Create(); | 8914 scoped_refptr<Layer> root = Layer::Create(); |
8910 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); | 8915 scoped_refptr<Layer> inner_viewport_container_layer = Layer::Create(); |
8911 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); | 8916 scoped_refptr<Layer> inner_viewport_scroll_layer = Layer::Create(); |
8912 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); | 8917 scoped_refptr<Layer> outer_viewport_container_layer = Layer::Create(); |
8913 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); | 8918 scoped_refptr<Layer> outer_viewport_scroll_layer = Layer::Create(); |
8914 | 8919 |
8915 root->AddChild(inner_viewport_container_layer); | 8920 root->AddChild(inner_viewport_container_layer); |
8916 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); | 8921 inner_viewport_container_layer->AddChild(inner_viewport_scroll_layer); |
8917 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); | 8922 inner_viewport_scroll_layer->AddChild(outer_viewport_container_layer); |
8918 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); | 8923 outer_viewport_container_layer->AddChild(outer_viewport_scroll_layer); |
(...skipping 1941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10860 | 10865 |
10861 // Check child layer draw properties. | 10866 // Check child layer draw properties. |
10862 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); | 10867 EXPECT_EQ(gfx::Rect(10, 10), child->visible_layer_rect()); |
10863 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); | 10868 EXPECT_EQ(gfx::Transform(), child->DrawTransform()); |
10864 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); | 10869 EXPECT_EQ(gfx::Rect(10, 10), child->clip_rect()); |
10865 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); | 10870 EXPECT_EQ(gfx::Rect(10, 10), child->drawable_content_rect()); |
10866 } | 10871 } |
10867 | 10872 |
10868 } // namespace | 10873 } // namespace |
10869 } // namespace cc | 10874 } // namespace cc |
OLD | NEW |