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 4719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4730 ->ScrollBegin(BeginState(gfx::Point()).get(), | 4730 ->ScrollBegin(BeginState(gfx::Point()).get(), |
4731 InputHandler::TOUCHSCREEN) | 4731 InputHandler::TOUCHSCREEN) |
4732 .thread); | 4732 .thread); |
4733 } | 4733 } |
4734 | 4734 |
4735 // Tests that activating a pending tree while there's a bounds_delta on the | 4735 // Tests that activating a pending tree while there's a bounds_delta on the |
4736 // viewport layers from top controls doesn't cause a scroll jump. This bug was | 4736 // viewport layers from top controls doesn't cause a scroll jump. This bug was |
4737 // occurring because the UpdateViewportContainerSizes was being called before | 4737 // occurring because the UpdateViewportContainerSizes was being called before |
4738 // the property trees were updated with the bounds_delta. crbug.com/597266. | 4738 // the property trees were updated with the bounds_delta. crbug.com/597266. |
4739 TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { | 4739 TEST_F(LayerTreeHostImplTopControlsTest, ViewportBoundsDeltaOnTreeActivation) { |
4740 const gfx::Size inner_viewport_size(500, 500); | 4740 const gfx::Size inner_viewport_size(1000, 1000); |
4741 const gfx::Size outer_viewport_size(1000, 1000); | 4741 const gfx::Size outer_viewport_size(1000, 1000); |
4742 const gfx::Size content_size(2000, 2000); | 4742 const gfx::Size content_size(2000, 2000); |
4743 | 4743 |
4744 SetupTopControlsAndScrollLayerWithVirtualViewport( | 4744 // Initialization |
4745 inner_viewport_size, outer_viewport_size, content_size); | 4745 { |
4746 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 0.25f, 4.f); | 4746 SetupTopControlsAndScrollLayerWithVirtualViewport( |
| 4747 inner_viewport_size, outer_viewport_size, content_size); |
| 4748 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
4747 | 4749 |
4748 host_impl_->CreatePendingTree(); | 4750 // Start off with the top controls hidden on both main and impl. |
4749 SetupTopControlsAndScrollLayerWithVirtualViewport( | 4751 host_impl_->active_tree()->set_top_controls_shrink_blink_size(false); |
4750 host_impl_->pending_tree(), inner_viewport_size, outer_viewport_size, | 4752 host_impl_->active_tree()->PushTopControlsFromMainThread(0); |
4751 content_size); | |
4752 | 4753 |
4753 // Zoom in to 2X. | 4754 host_impl_->CreatePendingTree(); |
4754 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | 4755 SetupTopControlsAndScrollLayerWithVirtualViewport( |
4755 InputHandler::TOUCHSCREEN); | 4756 host_impl_->pending_tree(), inner_viewport_size, outer_viewport_size, |
4756 host_impl_->PinchGestureBegin(); | 4757 content_size); |
4757 host_impl_->PinchGestureUpdate(2.f, gfx::Point()); | 4758 host_impl_->pending_tree()->set_top_controls_shrink_blink_size(false); |
4758 host_impl_->PinchGestureEnd(); | |
4759 host_impl_->ScrollEnd(EndState().get()); | |
4760 | 4759 |
4761 ASSERT_EQ(2.0f, host_impl_->active_tree()->current_page_scale_factor()); | 4760 // Fully scroll the viewport. |
| 4761 host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), |
| 4762 InputHandler::TOUCHSCREEN); |
| 4763 host_impl_->ScrollBy( |
| 4764 UpdateState(gfx::Point(), gfx::Vector2d(0, 2000)).get()); |
| 4765 host_impl_->ScrollEnd(EndState().get()); |
| 4766 } |
4762 | 4767 |
4763 // All scroll types outside this region should succeed. | |
4764 host_impl_->ScrollBegin(BeginState(gfx::Point(75, 75)).get(), | |
4765 InputHandler::TOUCHSCREEN); | |
4766 // Fully scroll the viewports. | |
4767 host_impl_->ScrollBy(UpdateState(gfx::Point(), gfx::Vector2d(0, 2000)).get()); | |
4768 host_impl_->ScrollEnd(EndState().get()); | |
4769 | |
4770 LayerImpl* inner_scroll = | |
4771 host_impl_->active_tree()->InnerViewportScrollLayer(); | |
4772 LayerImpl* outer_scroll = | 4768 LayerImpl* outer_scroll = |
4773 host_impl_->active_tree()->OuterViewportScrollLayer(); | 4769 host_impl_->active_tree()->OuterViewportScrollLayer(); |
4774 | 4770 |
4775 EXPECT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); | 4771 ASSERT_FLOAT_EQ(0, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4772 ASSERT_EQ(1000, outer_scroll->MaxScrollOffset().y()); |
| 4773 ASSERT_EQ(1000, outer_scroll->CurrentScrollOffset().y()); |
4776 | 4774 |
4777 EXPECT_EQ(925, inner_scroll->MaxScrollOffset().y()); | 4775 // Kick off an animation to show the top controls. |
4778 EXPECT_EQ(800, outer_scroll->MaxScrollOffset().y()); | 4776 host_impl_->top_controls_manager()->UpdateTopControlsState(BOTH, SHOWN, true); |
| 4777 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 4778 BeginFrameArgs begin_frame_args = |
| 4779 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
4779 | 4780 |
4780 // Activate the pending tree which should have all the same values as the | 4781 // Pump an animation frame to put some delta in the top controls. |
| 4782 { |
| 4783 begin_frame_args.frame_time = |
| 4784 start_time + base::TimeDelta::FromMilliseconds(50); |
| 4785 host_impl_->WillBeginImplFrame(begin_frame_args); |
| 4786 host_impl_->Animate(); |
| 4787 host_impl_->UpdateAnimationState(true); |
| 4788 host_impl_->DidFinishImplFrame(); |
| 4789 } |
| 4790 |
| 4791 // Pull the top controls delta and get it back to the pending tree so that |
| 4792 // when we go to activate the pending tree we cause a change to top controls. |
| 4793 { |
| 4794 float delta = |
| 4795 host_impl_->active_tree()->top_controls_shown_ratio()->Delta(); |
| 4796 ASSERT_GT(delta, 0); |
| 4797 ASSERT_LT(delta, 1); |
| 4798 host_impl_->active_tree() |
| 4799 ->top_controls_shown_ratio() |
| 4800 ->PullDeltaForMainThread(); |
| 4801 host_impl_->active_tree()->top_controls_shown_ratio()->PushFromMainThread( |
| 4802 delta); |
| 4803 } |
| 4804 |
| 4805 // 200 is the kShowHideMaxDurationMs value from top_controls_manager.cc so the |
| 4806 // top controls should be fully animated in this frame. |
| 4807 { |
| 4808 begin_frame_args.frame_time = |
| 4809 start_time + base::TimeDelta::FromMilliseconds(200); |
| 4810 host_impl_->WillBeginImplFrame(begin_frame_args); |
| 4811 host_impl_->Animate(); |
| 4812 host_impl_->UpdateAnimationState(true); |
| 4813 host_impl_->DidFinishImplFrame(); |
| 4814 |
| 4815 ASSERT_EQ(50, host_impl_->top_controls_manager()->ContentTopOffset()); |
| 4816 ASSERT_EQ(1050, outer_scroll->MaxScrollOffset().y()); |
| 4817 // NEAR because clip layer bounds are truncated in MaxScrollOffset so we |
| 4818 // lose some precision in the intermediate animation steps. |
| 4819 ASSERT_NEAR(1050, outer_scroll->CurrentScrollOffset().y(), 1.f); |
| 4820 } |
| 4821 |
| 4822 // Activate the pending tree which should have the same scroll value as the |
4781 // active tree. | 4823 // active tree. |
4782 host_impl_->pending_tree()->SetCurrentTopControlsShownRatio(0); | 4824 { |
4783 host_impl_->pending_tree()->PushPageScaleFromMainThread(2.f, 0.25f, 4.f); | 4825 host_impl_->pending_tree() |
4784 host_impl_->pending_tree() | 4826 ->property_trees() |
4785 ->property_trees() | 4827 ->scroll_tree.SetScrollOffsetDeltaForTesting(outer_scroll->id(), |
4786 ->scroll_tree.SetScrollOffsetDeltaForTesting(inner_scroll->id(), | 4828 gfx::Vector2dF(0, 1050)); |
4787 gfx::Vector2dF(0, 925)); | 4829 host_impl_->ActivateSyncTree(); |
4788 host_impl_->pending_tree() | |
4789 ->property_trees() | |
4790 ->scroll_tree.SetScrollOffsetDeltaForTesting(outer_scroll->id(), | |
4791 gfx::Vector2dF(0, 800)); | |
4792 host_impl_->ActivateSyncTree(); | |
4793 | 4830 |
4794 inner_scroll = host_impl_->active_tree()->InnerViewportScrollLayer(); | 4831 // Make sure we don't accidentally clamp the outer offset based on a bounds |
4795 outer_scroll = host_impl_->active_tree()->OuterViewportScrollLayer(); | 4832 // delta that hasn't yet been updated. |
4796 | 4833 EXPECT_NEAR(1050, outer_scroll->CurrentScrollOffset().y(), 1.f); |
4797 // The test should pass if the scroll offets remain as they are. We fail if | 4834 } |
4798 // the offets get clamped due to MaxScrollOffset not having the proper | |
4799 // bounds_delta set when UpdateViewportContainerSizes is called. | |
4800 EXPECT_EQ(925, inner_scroll->CurrentScrollOffset().y()); | |
4801 EXPECT_EQ(800, outer_scroll->CurrentScrollOffset().y()); | |
4802 } | 4835 } |
4803 | 4836 |
4804 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { | 4837 TEST_F(LayerTreeHostImplTest, ScrollNonCompositedRoot) { |
4805 // Test the configuration where a non-composited root layer is embedded in a | 4838 // Test the configuration where a non-composited root layer is embedded in a |
4806 // scrollable outer layer. | 4839 // scrollable outer layer. |
4807 gfx::Size surface_size(10, 10); | 4840 gfx::Size surface_size(10, 10); |
4808 gfx::Size contents_size(20, 20); | 4841 gfx::Size contents_size(20, 20); |
4809 | 4842 |
4810 std::unique_ptr<LayerImpl> content_layer = | 4843 std::unique_ptr<LayerImpl> content_layer = |
4811 LayerImpl::Create(host_impl_->active_tree(), 1); | 4844 LayerImpl::Create(host_impl_->active_tree(), 1); |
(...skipping 6233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11045 | 11078 |
11046 // Re-initialize with a software output surface. | 11079 // Re-initialize with a software output surface. |
11047 output_surface_ = FakeOutputSurface::CreateSoftware( | 11080 output_surface_ = FakeOutputSurface::CreateSoftware( |
11048 base::WrapUnique(new SoftwareOutputDevice)); | 11081 base::WrapUnique(new SoftwareOutputDevice)); |
11049 host_impl_->InitializeRenderer(output_surface_.get()); | 11082 host_impl_->InitializeRenderer(output_surface_.get()); |
11050 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); | 11083 EXPECT_FALSE(host_impl_->use_gpu_rasterization()); |
11051 } | 11084 } |
11052 | 11085 |
11053 } // namespace | 11086 } // namespace |
11054 } // namespace cc | 11087 } // namespace cc |
OLD | NEW |