| 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_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 5688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5699 // Tear down the LayerTreeHostImpl before the InputHandlerClient. | 5699 // Tear down the LayerTreeHostImpl before the InputHandlerClient. |
| 5700 host_impl_->ReleaseCompositorFrameSink(); | 5700 host_impl_->ReleaseCompositorFrameSink(); |
| 5701 host_impl_ = nullptr; | 5701 host_impl_ = nullptr; |
| 5702 } | 5702 } |
| 5703 | 5703 |
| 5704 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { | 5704 TEST_F(LayerTreeHostImplTest, ScrollWithoutBubbling) { |
| 5705 // Scroll a child layer beyond its maximum scroll range and make sure the | 5705 // Scroll a child layer beyond its maximum scroll range and make sure the |
| 5706 // the scroll doesn't bubble up to the parent layer. | 5706 // the scroll doesn't bubble up to the parent layer. |
| 5707 gfx::Size surface_size(20, 20); | 5707 gfx::Size surface_size(20, 20); |
| 5708 gfx::Size viewport_size(10, 10); | 5708 gfx::Size viewport_size(10, 10); |
| 5709 const int kPageScaleLayerId = 1; |
| 5710 const int kViewportClipLayerId = 2; |
| 5711 const int kViewportScrollLayerId = 3; |
| 5709 std::unique_ptr<LayerImpl> root_ptr = | 5712 std::unique_ptr<LayerImpl> root_ptr = |
| 5710 LayerImpl::Create(host_impl_->active_tree(), 1); | 5713 LayerImpl::Create(host_impl_->active_tree(), kPageScaleLayerId); |
| 5711 std::unique_ptr<LayerImpl> root_clip = | 5714 std::unique_ptr<LayerImpl> root_clip = |
| 5712 LayerImpl::Create(host_impl_->active_tree(), 2); | 5715 LayerImpl::Create(host_impl_->active_tree(), kViewportClipLayerId); |
| 5713 root_clip->test_properties()->force_render_surface = true; | 5716 root_clip->test_properties()->force_render_surface = true; |
| 5714 std::unique_ptr<LayerImpl> root_scrolling = | 5717 std::unique_ptr<LayerImpl> root_scrolling = CreateScrollableLayer( |
| 5715 CreateScrollableLayer(3, surface_size, root_clip.get()); | 5718 kViewportScrollLayerId, surface_size, root_clip.get()); |
| 5716 root_scrolling->test_properties()->is_container_for_fixed_position_layers = | 5719 root_scrolling->test_properties()->is_container_for_fixed_position_layers = |
| 5717 true; | 5720 true; |
| 5718 | 5721 |
| 5719 std::unique_ptr<LayerImpl> grand_child = | 5722 std::unique_ptr<LayerImpl> grand_child = |
| 5720 CreateScrollableLayer(5, surface_size, root_clip.get()); | 5723 CreateScrollableLayer(5, surface_size, root_clip.get()); |
| 5721 | 5724 |
| 5722 std::unique_ptr<LayerImpl> child = | 5725 std::unique_ptr<LayerImpl> child = |
| 5723 CreateScrollableLayer(4, surface_size, root_clip.get()); | 5726 CreateScrollableLayer(4, surface_size, root_clip.get()); |
| 5724 LayerImpl* grand_child_layer = grand_child.get(); | 5727 LayerImpl* grand_child_layer = grand_child.get(); |
| 5725 child->test_properties()->AddChild(std::move(grand_child)); | 5728 child->test_properties()->AddChild(std::move(grand_child)); |
| 5726 | 5729 |
| 5727 LayerImpl* child_layer = child.get(); | 5730 LayerImpl* child_layer = child.get(); |
| 5728 root_scrolling->test_properties()->AddChild(std::move(child)); | 5731 root_scrolling->test_properties()->AddChild(std::move(child)); |
| 5729 root_clip->test_properties()->AddChild(std::move(root_scrolling)); | 5732 root_clip->test_properties()->AddChild(std::move(root_scrolling)); |
| 5730 EXPECT_EQ(viewport_size, root_clip->bounds()); | 5733 EXPECT_EQ(viewport_size, root_clip->bounds()); |
| 5731 root_ptr->test_properties()->AddChild(std::move(root_clip)); | 5734 root_ptr->test_properties()->AddChild(std::move(root_clip)); |
| 5732 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); | 5735 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
| 5733 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 5736 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5734 host_impl_->active_tree()->SetViewportLayersFromIds( | 5737 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 5735 Layer::INVALID_ID, 1, Layer::INVALID_ID, Layer::INVALID_ID, 3, | 5738 Layer::INVALID_ID, kPageScaleLayerId, kViewportClipLayerId, |
| 5736 Layer::INVALID_ID); | 5739 Layer::INVALID_ID, kViewportScrollLayerId, Layer::INVALID_ID); |
| 5737 host_impl_->active_tree()->DidBecomeActive(); | 5740 host_impl_->active_tree()->DidBecomeActive(); |
| 5738 host_impl_->SetViewportSize(viewport_size); | 5741 host_impl_->SetViewportSize(viewport_size); |
| 5739 | 5742 |
| 5740 grand_child_layer->layer_tree_impl() | 5743 grand_child_layer->layer_tree_impl() |
| 5741 ->property_trees() | 5744 ->property_trees() |
| 5742 ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), | 5745 ->scroll_tree.UpdateScrollOffsetBaseForTesting(grand_child_layer->id(), |
| 5743 gfx::ScrollOffset(0, 2)); | 5746 gfx::ScrollOffset(0, 2)); |
| 5744 child_layer->layer_tree_impl() | 5747 child_layer->layer_tree_impl() |
| 5745 ->property_trees() | 5748 ->property_trees() |
| 5746 ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), | 5749 ->scroll_tree.UpdateScrollOffsetBaseForTesting(child_layer->id(), |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5845 // Should have scrolled by half the amount in layer space (5 - 2/2) | 5848 // Should have scrolled by half the amount in layer space (5 - 2/2) |
| 5846 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), | 5849 EXPECT_TRUE(ScrollInfoContains(*scroll_info.get(), grand_child->id(), |
| 5847 gfx::Vector2d(0, 4))); | 5850 gfx::Vector2d(0, 4))); |
| 5848 } | 5851 } |
| 5849 } | 5852 } |
| 5850 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { | 5853 TEST_F(LayerTreeHostImplTest, ScrollEventBubbling) { |
| 5851 // When we try to scroll a non-scrollable child layer, the scroll delta | 5854 // When we try to scroll a non-scrollable child layer, the scroll delta |
| 5852 // should be applied to one of its ancestors if possible. | 5855 // should be applied to one of its ancestors if possible. |
| 5853 gfx::Size surface_size(10, 10); | 5856 gfx::Size surface_size(10, 10); |
| 5854 gfx::Size content_size(20, 20); | 5857 gfx::Size content_size(20, 20); |
| 5858 const int kPageScaleLayerId = 4; |
| 5859 const int kViewportClipLayerId = 1; |
| 5860 const int kViewportScrollLayerId = 2; |
| 5855 std::unique_ptr<LayerImpl> root_ptr = | 5861 std::unique_ptr<LayerImpl> root_ptr = |
| 5856 LayerImpl::Create(host_impl_->active_tree(), 4); | 5862 LayerImpl::Create(host_impl_->active_tree(), kPageScaleLayerId); |
| 5857 std::unique_ptr<LayerImpl> root_clip = | 5863 std::unique_ptr<LayerImpl> root_clip = |
| 5858 LayerImpl::Create(host_impl_->active_tree(), 3); | 5864 LayerImpl::Create(host_impl_->active_tree(), 3); |
| 5859 root_clip->test_properties()->force_render_surface = true; | 5865 root_clip->test_properties()->force_render_surface = true; |
| 5860 std::unique_ptr<LayerImpl> root_scroll = | 5866 std::unique_ptr<LayerImpl> root_scroll = CreateScrollableLayer( |
| 5861 CreateScrollableLayer(1, content_size, root_clip.get()); | 5867 kViewportClipLayerId, content_size, root_clip.get()); |
| 5862 // Make 'root' the clip layer for child: since they have the same sizes the | 5868 // Make 'root' the clip layer for child: since they have the same sizes the |
| 5863 // child will have zero max_scroll_offset and scrolls will bubble. | 5869 // child will have zero max_scroll_offset and scrolls will bubble. |
| 5864 std::unique_ptr<LayerImpl> child = | 5870 std::unique_ptr<LayerImpl> child = CreateScrollableLayer( |
| 5865 CreateScrollableLayer(2, content_size, root_scroll.get()); | 5871 kViewportScrollLayerId, content_size, root_scroll.get()); |
| 5866 child->test_properties()->is_container_for_fixed_position_layers = true; | 5872 child->test_properties()->is_container_for_fixed_position_layers = true; |
| 5867 root_scroll->SetBounds(content_size); | 5873 root_scroll->SetBounds(content_size); |
| 5868 | 5874 |
| 5869 int root_scroll_id = root_scroll->id(); | 5875 int root_scroll_id = root_scroll->id(); |
| 5870 root_scroll->test_properties()->AddChild(std::move(child)); | 5876 root_scroll->test_properties()->AddChild(std::move(child)); |
| 5871 root_clip->test_properties()->AddChild(std::move(root_scroll)); | 5877 root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 5872 root_ptr->test_properties()->AddChild(std::move(root_clip)); | 5878 root_ptr->test_properties()->AddChild(std::move(root_clip)); |
| 5873 | 5879 |
| 5874 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); | 5880 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
| 5875 host_impl_->active_tree()->SetViewportLayersFromIds( | 5881 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 5876 Layer::INVALID_ID, 4, Layer::INVALID_ID, Layer::INVALID_ID, 2, | 5882 Layer::INVALID_ID, kPageScaleLayerId, kViewportClipLayerId, |
| 5877 Layer::INVALID_ID); | 5883 Layer::INVALID_ID, kViewportScrollLayerId, Layer::INVALID_ID); |
| 5878 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 5884 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5879 host_impl_->active_tree()->DidBecomeActive(); | 5885 host_impl_->active_tree()->DidBecomeActive(); |
| 5880 | 5886 |
| 5881 host_impl_->SetViewportSize(surface_size); | 5887 host_impl_->SetViewportSize(surface_size); |
| 5882 DrawFrame(); | 5888 DrawFrame(); |
| 5883 { | 5889 { |
| 5884 gfx::Vector2d scroll_delta(0, 4); | 5890 gfx::Vector2d scroll_delta(0, 4); |
| 5885 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 5891 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 5886 host_impl_ | 5892 host_impl_ |
| 5887 ->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), | 5893 ->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), |
| 5888 InputHandler::WHEEL) | 5894 InputHandler::WHEEL) |
| 5889 .thread); | 5895 .thread); |
| 5890 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); | 5896 host_impl_->ScrollBy(UpdateState(gfx::Point(), scroll_delta).get()); |
| 5891 host_impl_->ScrollEnd(EndState().get()); | 5897 host_impl_->ScrollEnd(EndState().get()); |
| 5892 | 5898 |
| 5893 std::unique_ptr<ScrollAndScaleSet> scroll_info = | 5899 std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 5894 host_impl_->ProcessScrollDeltas(); | 5900 host_impl_->ProcessScrollDeltas(); |
| 5895 | 5901 |
| 5896 // Only the root scroll should have scrolled. | 5902 // Only the root scroll should have scrolled. |
| 5897 ASSERT_EQ(scroll_info->scrolls.size(), 1u); | 5903 ASSERT_EQ(scroll_info->scrolls.size(), 1u); |
| 5898 EXPECT_TRUE( | 5904 EXPECT_TRUE( |
| 5899 ScrollInfoContains(*scroll_info.get(), root_scroll_id, scroll_delta)); | 5905 ScrollInfoContains(*scroll_info.get(), root_scroll_id, scroll_delta)); |
| 5900 } | 5906 } |
| 5901 } | 5907 } |
| 5902 | 5908 |
| 5903 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { | 5909 TEST_F(LayerTreeHostImplTest, ScrollBeforeRedraw) { |
| 5910 const int kPageScaleLayerId = 1; |
| 5911 const int kInnerViewportClipLayerId = 2; |
| 5912 const int kOuterViewportClipLayerId = 7; |
| 5913 const int kInnerViewportScrollLayerId = 3; |
| 5914 const int kOuterViewportScrollLayerId = 8; |
| 5904 gfx::Size surface_size(10, 10); | 5915 gfx::Size surface_size(10, 10); |
| 5905 std::unique_ptr<LayerImpl> root_ptr = | 5916 std::unique_ptr<LayerImpl> root_ptr = |
| 5906 LayerImpl::Create(host_impl_->active_tree(), 1); | 5917 LayerImpl::Create(host_impl_->active_tree(), kPageScaleLayerId); |
| 5907 std::unique_ptr<LayerImpl> inner_clip = | 5918 std::unique_ptr<LayerImpl> inner_clip = |
| 5908 LayerImpl::Create(host_impl_->active_tree(), 2); | 5919 LayerImpl::Create(host_impl_->active_tree(), kInnerViewportClipLayerId); |
| 5909 std::unique_ptr<LayerImpl> inner_scroll = | 5920 std::unique_ptr<LayerImpl> inner_scroll = CreateScrollableLayer( |
| 5910 CreateScrollableLayer(3, surface_size, inner_clip.get()); | 5921 kInnerViewportScrollLayerId, surface_size, inner_clip.get()); |
| 5911 std::unique_ptr<LayerImpl> outer_clip = | 5922 std::unique_ptr<LayerImpl> outer_clip = |
| 5912 LayerImpl::Create(host_impl_->active_tree(), 7); | 5923 LayerImpl::Create(host_impl_->active_tree(), kOuterViewportClipLayerId); |
| 5913 std::unique_ptr<LayerImpl> outer_scroll = | 5924 std::unique_ptr<LayerImpl> outer_scroll = CreateScrollableLayer( |
| 5914 CreateScrollableLayer(8, surface_size, outer_clip.get()); | 5925 kOuterViewportScrollLayerId, surface_size, outer_clip.get()); |
| 5915 inner_clip->test_properties()->force_render_surface = true; | 5926 inner_clip->test_properties()->force_render_surface = true; |
| 5916 inner_scroll->test_properties()->is_container_for_fixed_position_layers = | 5927 inner_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 5917 true; | 5928 true; |
| 5918 outer_scroll->test_properties()->is_container_for_fixed_position_layers = | 5929 outer_scroll->test_properties()->is_container_for_fixed_position_layers = |
| 5919 true; | 5930 true; |
| 5920 outer_clip->test_properties()->AddChild(std::move(outer_scroll)); | 5931 outer_clip->test_properties()->AddChild(std::move(outer_scroll)); |
| 5921 inner_scroll->test_properties()->AddChild(std::move(outer_clip)); | 5932 inner_scroll->test_properties()->AddChild(std::move(outer_clip)); |
| 5922 inner_clip->test_properties()->AddChild(std::move(inner_scroll)); | 5933 inner_clip->test_properties()->AddChild(std::move(inner_scroll)); |
| 5923 root_ptr->test_properties()->AddChild(std::move(inner_clip)); | 5934 root_ptr->test_properties()->AddChild(std::move(inner_clip)); |
| 5924 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); | 5935 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
| 5925 host_impl_->active_tree()->SetViewportLayersFromIds( | 5936 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 5926 Layer::INVALID_ID, 1, Layer::INVALID_ID, Layer::INVALID_ID, 3, 8); | 5937 Layer::INVALID_ID, kPageScaleLayerId, kInnerViewportClipLayerId, |
| 5938 kOuterViewportClipLayerId, kInnerViewportScrollLayerId, |
| 5939 kOuterViewportScrollLayerId); |
| 5927 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 5940 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5928 host_impl_->active_tree()->DidBecomeActive(); | 5941 host_impl_->active_tree()->DidBecomeActive(); |
| 5929 | 5942 |
| 5930 host_impl_->SetViewportSize(surface_size); | 5943 host_impl_->SetViewportSize(surface_size); |
| 5931 | 5944 |
| 5932 // Draw one frame and then immediately rebuild the layer tree to mimic a tree | 5945 // Draw one frame and then immediately rebuild the layer tree to mimic a tree |
| 5933 // synchronization. | 5946 // synchronization. |
| 5934 DrawFrame(); | 5947 DrawFrame(); |
| 5935 | 5948 |
| 5949 const int kPageScaleLayerId2 = 4; |
| 5950 const int kInnerViewportClipLayerId2 = 5; |
| 5951 const int kOuterViewportClipLayerId2 = 9; |
| 5952 const int kInnerViewportScrollLayerId2 = 6; |
| 5953 const int kOuterViewportScrollLayerId2 = 10; |
| 5936 host_impl_->active_tree()->DetachLayers(); | 5954 host_impl_->active_tree()->DetachLayers(); |
| 5937 std::unique_ptr<LayerImpl> root_ptr2 = | 5955 std::unique_ptr<LayerImpl> root_ptr2 = |
| 5938 LayerImpl::Create(host_impl_->active_tree(), 4); | 5956 LayerImpl::Create(host_impl_->active_tree(), 4); |
| 5939 std::unique_ptr<LayerImpl> inner_clip2 = | 5957 std::unique_ptr<LayerImpl> inner_clip2 = |
| 5940 LayerImpl::Create(host_impl_->active_tree(), 5); | 5958 LayerImpl::Create(host_impl_->active_tree(), kInnerViewportClipLayerId2); |
| 5941 std::unique_ptr<LayerImpl> inner_scroll2 = | 5959 std::unique_ptr<LayerImpl> inner_scroll2 = CreateScrollableLayer( |
| 5942 CreateScrollableLayer(6, surface_size, inner_clip2.get()); | 5960 kInnerViewportScrollLayerId2, surface_size, inner_clip2.get()); |
| 5943 std::unique_ptr<LayerImpl> outer_clip2 = | 5961 std::unique_ptr<LayerImpl> outer_clip2 = |
| 5944 LayerImpl::Create(host_impl_->active_tree(), 9); | 5962 LayerImpl::Create(host_impl_->active_tree(), kOuterViewportClipLayerId2); |
| 5945 std::unique_ptr<LayerImpl> outer_scroll2 = | 5963 std::unique_ptr<LayerImpl> outer_scroll2 = CreateScrollableLayer( |
| 5946 CreateScrollableLayer(10, surface_size, outer_clip2.get()); | 5964 kOuterViewportScrollLayerId2, surface_size, outer_clip2.get()); |
| 5947 inner_scroll2->test_properties()->is_container_for_fixed_position_layers = | 5965 inner_scroll2->test_properties()->is_container_for_fixed_position_layers = |
| 5948 true; | 5966 true; |
| 5949 outer_scroll2->test_properties()->is_container_for_fixed_position_layers = | 5967 outer_scroll2->test_properties()->is_container_for_fixed_position_layers = |
| 5950 true; | 5968 true; |
| 5951 outer_clip2->test_properties()->AddChild(std::move(outer_scroll2)); | 5969 outer_clip2->test_properties()->AddChild(std::move(outer_scroll2)); |
| 5952 inner_scroll2->test_properties()->AddChild(std::move(outer_clip2)); | 5970 inner_scroll2->test_properties()->AddChild(std::move(outer_clip2)); |
| 5953 inner_clip2->test_properties()->AddChild(std::move(inner_scroll2)); | 5971 inner_clip2->test_properties()->AddChild(std::move(inner_scroll2)); |
| 5954 inner_clip2->test_properties()->force_render_surface = true; | 5972 inner_clip2->test_properties()->force_render_surface = true; |
| 5955 root_ptr2->test_properties()->AddChild(std::move(inner_clip2)); | 5973 root_ptr2->test_properties()->AddChild(std::move(inner_clip2)); |
| 5956 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2)); | 5974 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr2)); |
| 5957 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 5975 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 5958 host_impl_->active_tree()->SetViewportLayersFromIds( | 5976 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 5959 Layer::INVALID_ID, 4, Layer::INVALID_ID, Layer::INVALID_ID, 6, 10); | 5977 Layer::INVALID_ID, kPageScaleLayerId2, kInnerViewportClipLayerId2, |
| 5978 kOuterViewportClipLayerId2, kInnerViewportScrollLayerId2, |
| 5979 kOuterViewportScrollLayerId2); |
| 5960 host_impl_->active_tree()->DidBecomeActive(); | 5980 host_impl_->active_tree()->DidBecomeActive(); |
| 5961 | 5981 |
| 5962 // Scrolling should still work even though we did not draw yet. | 5982 // Scrolling should still work even though we did not draw yet. |
| 5963 EXPECT_EQ( | 5983 EXPECT_EQ( |
| 5964 InputHandler::SCROLL_ON_IMPL_THREAD, | 5984 InputHandler::SCROLL_ON_IMPL_THREAD, |
| 5965 host_impl_ | 5985 host_impl_ |
| 5966 ->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), InputHandler::WHEEL) | 5986 ->ScrollBegin(BeginState(gfx::Point(5, 5)).get(), InputHandler::WHEEL) |
| 5967 .thread); | 5987 .thread); |
| 5968 } | 5988 } |
| 5969 | 5989 |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6516 host_impl_->accumulated_root_overscroll()); | 6536 host_impl_->accumulated_root_overscroll()); |
| 6517 | 6537 |
| 6518 host_impl_->ScrollEnd(EndState().get()); | 6538 host_impl_->ScrollEnd(EndState().get()); |
| 6519 } | 6539 } |
| 6520 | 6540 |
| 6521 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { | 6541 TEST_F(LayerTreeHostImplTest, OverscrollChildWithoutBubbling) { |
| 6522 // Scroll child layers beyond their maximum scroll range and make sure root | 6542 // Scroll child layers beyond their maximum scroll range and make sure root |
| 6523 // overscroll does not accumulate. | 6543 // overscroll does not accumulate. |
| 6524 InputHandlerScrollResult scroll_result; | 6544 InputHandlerScrollResult scroll_result; |
| 6525 gfx::Size surface_size(10, 10); | 6545 gfx::Size surface_size(10, 10); |
| 6546 const int kInnerViewportClipLayerId = 4; |
| 6547 const int kInnerViewportScrollLayerId = 1; |
| 6526 std::unique_ptr<LayerImpl> root_clip = | 6548 std::unique_ptr<LayerImpl> root_clip = |
| 6527 LayerImpl::Create(host_impl_->active_tree(), 4); | 6549 LayerImpl::Create(host_impl_->active_tree(), kInnerViewportClipLayerId); |
| 6528 root_clip->test_properties()->force_render_surface = true; | 6550 root_clip->test_properties()->force_render_surface = true; |
| 6529 | 6551 |
| 6530 std::unique_ptr<LayerImpl> root = | 6552 std::unique_ptr<LayerImpl> root = CreateScrollableLayer( |
| 6531 CreateScrollableLayer(1, surface_size, root_clip.get()); | 6553 kInnerViewportScrollLayerId, surface_size, root_clip.get()); |
| 6532 | 6554 |
| 6533 std::unique_ptr<LayerImpl> grand_child = | 6555 std::unique_ptr<LayerImpl> grand_child = |
| 6534 CreateScrollableLayer(3, surface_size, root_clip.get()); | 6556 CreateScrollableLayer(3, surface_size, root_clip.get()); |
| 6535 | 6557 |
| 6536 std::unique_ptr<LayerImpl> child = | 6558 std::unique_ptr<LayerImpl> child = |
| 6537 CreateScrollableLayer(2, surface_size, root_clip.get()); | 6559 CreateScrollableLayer(2, surface_size, root_clip.get()); |
| 6538 LayerImpl* grand_child_layer = grand_child.get(); | 6560 LayerImpl* grand_child_layer = grand_child.get(); |
| 6539 child->test_properties()->AddChild(std::move(grand_child)); | 6561 child->test_properties()->AddChild(std::move(grand_child)); |
| 6540 | 6562 |
| 6541 host_impl_->active_tree()->SetViewportLayersFromIds( | 6563 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 6542 Layer::INVALID_ID, Layer::INVALID_ID, Layer::INVALID_ID, | 6564 Layer::INVALID_ID, Layer::INVALID_ID, kInnerViewportClipLayerId, |
| 6543 Layer::INVALID_ID, root->id(), Layer::INVALID_ID); | 6565 Layer::INVALID_ID, kInnerViewportScrollLayerId, Layer::INVALID_ID); |
| 6544 | 6566 |
| 6545 LayerImpl* child_layer = child.get(); | 6567 LayerImpl* child_layer = child.get(); |
| 6546 root->test_properties()->AddChild(std::move(child)); | 6568 root->test_properties()->AddChild(std::move(child)); |
| 6547 root_clip->test_properties()->AddChild(std::move(root)); | 6569 root_clip->test_properties()->AddChild(std::move(root)); |
| 6548 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip)); | 6570 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_clip)); |
| 6549 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 6571 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 6550 host_impl_->active_tree()->DidBecomeActive(); | 6572 host_impl_->active_tree()->DidBecomeActive(); |
| 6551 | 6573 |
| 6552 child_layer->layer_tree_impl() | 6574 child_layer->layer_tree_impl() |
| 6553 ->property_trees() | 6575 ->property_trees() |
| (...skipping 2274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8828 // released, and the texture deleted. | 8850 // released, and the texture deleted. |
| 8829 EXPECT_TRUE(context_provider->HasOneRef()); | 8851 EXPECT_TRUE(context_provider->HasOneRef()); |
| 8830 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 8852 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
| 8831 } | 8853 } |
| 8832 | 8854 |
| 8833 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { | 8855 TEST_F(LayerTreeHostImplTest, TouchFlingShouldNotBubble) { |
| 8834 // When flinging via touch, only the child should scroll (we should not | 8856 // When flinging via touch, only the child should scroll (we should not |
| 8835 // bubble). | 8857 // bubble). |
| 8836 gfx::Size surface_size(10, 10); | 8858 gfx::Size surface_size(10, 10); |
| 8837 gfx::Size content_size(20, 20); | 8859 gfx::Size content_size(20, 20); |
| 8860 const int kPageScaleLayerId = 4; |
| 8861 const int kInnerViewportClipLayerId = 3; |
| 8862 const int kInnerViewportScrollLayerId = 1; |
| 8838 std::unique_ptr<LayerImpl> root_ptr = | 8863 std::unique_ptr<LayerImpl> root_ptr = |
| 8839 LayerImpl::Create(host_impl_->active_tree(), 4); | 8864 LayerImpl::Create(host_impl_->active_tree(), kPageScaleLayerId); |
| 8840 std::unique_ptr<LayerImpl> root_clip = | 8865 std::unique_ptr<LayerImpl> root_clip = |
| 8841 LayerImpl::Create(host_impl_->active_tree(), 3); | 8866 LayerImpl::Create(host_impl_->active_tree(), kInnerViewportClipLayerId); |
| 8842 root_clip->test_properties()->force_render_surface = true; | 8867 root_clip->test_properties()->force_render_surface = true; |
| 8843 | 8868 |
| 8844 std::unique_ptr<LayerImpl> root_scroll = | 8869 std::unique_ptr<LayerImpl> root_scroll = CreateScrollableLayer( |
| 8845 CreateScrollableLayer(1, content_size, root_clip.get()); | 8870 kInnerViewportScrollLayerId, content_size, root_clip.get()); |
| 8846 root_scroll->test_properties()->is_container_for_fixed_position_layers = true; | 8871 root_scroll->test_properties()->is_container_for_fixed_position_layers = true; |
| 8847 std::unique_ptr<LayerImpl> child = | 8872 std::unique_ptr<LayerImpl> child = |
| 8848 CreateScrollableLayer(2, content_size, root_clip.get()); | 8873 CreateScrollableLayer(2, content_size, root_clip.get()); |
| 8849 | 8874 |
| 8850 root_scroll->test_properties()->AddChild(std::move(child)); | 8875 root_scroll->test_properties()->AddChild(std::move(child)); |
| 8851 int root_id = root_scroll->id(); | 8876 int root_id = root_scroll->id(); |
| 8852 root_clip->test_properties()->AddChild(std::move(root_scroll)); | 8877 root_clip->test_properties()->AddChild(std::move(root_scroll)); |
| 8853 root_ptr->test_properties()->AddChild(std::move(root_clip)); | 8878 root_ptr->test_properties()->AddChild(std::move(root_clip)); |
| 8854 | 8879 |
| 8855 host_impl_->SetViewportSize(surface_size); | 8880 host_impl_->SetViewportSize(surface_size); |
| 8856 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); | 8881 host_impl_->active_tree()->SetRootLayerForTesting(std::move(root_ptr)); |
| 8857 host_impl_->active_tree()->SetViewportLayersFromIds( | 8882 host_impl_->active_tree()->SetViewportLayersFromIds( |
| 8858 Layer::INVALID_ID, 4, Layer::INVALID_ID, Layer::INVALID_ID, 1, | 8883 Layer::INVALID_ID, kPageScaleLayerId, kInnerViewportClipLayerId, |
| 8859 Layer::INVALID_ID); | 8884 Layer::INVALID_ID, kInnerViewportScrollLayerId, Layer::INVALID_ID); |
| 8860 host_impl_->active_tree()->BuildPropertyTreesForTesting(); | 8885 host_impl_->active_tree()->BuildPropertyTreesForTesting(); |
| 8861 host_impl_->active_tree()->DidBecomeActive(); | 8886 host_impl_->active_tree()->DidBecomeActive(); |
| 8862 DrawFrame(); | 8887 DrawFrame(); |
| 8863 { | 8888 { |
| 8864 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 8889 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 8865 host_impl_ | 8890 host_impl_ |
| 8866 ->ScrollBegin(BeginState(gfx::Point()).get(), | 8891 ->ScrollBegin(BeginState(gfx::Point()).get(), |
| 8867 InputHandler::TOUCHSCREEN) | 8892 InputHandler::TOUCHSCREEN) |
| 8868 .thread); | 8893 .thread); |
| 8869 | 8894 |
| (...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9856 const gfx::Size root_layer_size(200, 200); | 9881 const gfx::Size root_layer_size(200, 200); |
| 9857 const gfx::Size viewport_size(100, 100); | 9882 const gfx::Size viewport_size(100, 100); |
| 9858 | 9883 |
| 9859 SetupBrowserControlsAndScrollLayerWithVirtualViewport( | 9884 SetupBrowserControlsAndScrollLayerWithVirtualViewport( |
| 9860 viewport_size, viewport_size, root_layer_size); | 9885 viewport_size, viewport_size, root_layer_size); |
| 9861 | 9886 |
| 9862 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); | 9887 LayerImpl* outer_scroll = host_impl_->OuterViewportScrollLayer(); |
| 9863 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); | 9888 LayerImpl* inner_scroll = host_impl_->InnerViewportScrollLayer(); |
| 9864 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); | 9889 LayerTreeImpl* layer_tree_impl = host_impl_->active_tree(); |
| 9865 LayerImpl* scroll_layer = nullptr; | 9890 LayerImpl* scroll_layer = nullptr; |
| 9891 LayerImpl* clip_layer = nullptr; |
| 9866 | 9892 |
| 9867 // Initialization: Add a child scrolling layer to the outer scroll layer and | 9893 // Initialization: Add a child scrolling layer to the outer scroll layer and |
| 9868 // set its scroll layer as the outer viewport. This simulates setting a | 9894 // set its scroll layer as the outer viewport. This simulates setting a |
| 9869 // scrolling element as the root scroller on the page. | 9895 // scrolling element as the root scroller on the page. |
| 9870 { | 9896 { |
| 9871 std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); | 9897 std::unique_ptr<LayerImpl> clip = LayerImpl::Create(layer_tree_impl, 10); |
| 9872 clip->SetBounds(root_layer_size); | 9898 clip->SetBounds(root_layer_size); |
| 9873 clip->SetPosition(gfx::PointF()); | 9899 clip->SetPosition(gfx::PointF()); |
| 9874 | 9900 |
| 9875 std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); | 9901 std::unique_ptr<LayerImpl> scroll = LayerImpl::Create(layer_tree_impl, 11); |
| 9876 scroll->SetBounds(scroll_content_size); | 9902 scroll->SetBounds(scroll_content_size); |
| 9877 scroll->SetScrollClipLayer(clip->id()); | 9903 scroll->SetScrollClipLayer(clip->id()); |
| 9878 scroll->SetElementId(LayerIdToElementIdForTesting(scroll->id())); | 9904 scroll->SetElementId(LayerIdToElementIdForTesting(scroll->id())); |
| 9879 scroll->SetDrawsContent(true); | 9905 scroll->SetDrawsContent(true); |
| 9880 | 9906 |
| 9881 scroll_layer = scroll.get(); | 9907 scroll_layer = scroll.get(); |
| 9908 clip_layer = clip.get(); |
| 9882 | 9909 |
| 9883 clip->test_properties()->AddChild(std::move(scroll)); | 9910 clip->test_properties()->AddChild(std::move(scroll)); |
| 9884 outer_scroll->test_properties()->AddChild(std::move(clip)); | 9911 outer_scroll->test_properties()->AddChild(std::move(clip)); |
| 9885 | |
| 9886 layer_tree_impl->SetViewportLayersFromIds( | 9912 layer_tree_impl->SetViewportLayersFromIds( |
| 9887 Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), | 9913 Layer::INVALID_ID, layer_tree_impl->PageScaleLayer()->id(), |
| 9888 Layer::INVALID_ID, Layer::INVALID_ID, inner_scroll->id(), | 9914 layer_tree_impl->InnerViewportContainerLayer()->id(), clip_layer->id(), |
| 9889 scroll_layer->id()); | 9915 inner_scroll->id(), scroll_layer->id()); |
| 9890 layer_tree_impl->BuildPropertyTreesForTesting(); | 9916 layer_tree_impl->BuildPropertyTreesForTesting(); |
| 9891 DrawFrame(); | 9917 DrawFrame(); |
| 9892 } | 9918 } |
| 9893 | 9919 |
| 9894 ASSERT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); | 9920 ASSERT_EQ(1.f, host_impl_->active_tree()->CurrentBrowserControlsShownRatio()); |
| 9895 | 9921 |
| 9896 // Scrolling should scroll the child content and the browser controls. The | 9922 // Scrolling should scroll the child content and the browser controls. The |
| 9897 // original outer viewport should get no scroll. | 9923 // original outer viewport should get no scroll. |
| 9898 { | 9924 { |
| 9899 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), | 9925 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| (...skipping 2505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12405 else | 12431 else |
| 12406 EXPECT_FALSE(tile->HasRasterTask()); | 12432 EXPECT_FALSE(tile->HasRasterTask()); |
| 12407 } | 12433 } |
| 12408 Region expected_invalidation( | 12434 Region expected_invalidation( |
| 12409 raster_source->GetRectForImage(checkerable_image.stable_id())); | 12435 raster_source->GetRectForImage(checkerable_image.stable_id())); |
| 12410 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); | 12436 EXPECT_EQ(expected_invalidation, *(root->GetPendingInvalidation())); |
| 12411 } | 12437 } |
| 12412 | 12438 |
| 12413 } // namespace | 12439 } // namespace |
| 12414 } // namespace cc | 12440 } // namespace cc |
| OLD | NEW |