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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 static void SetScrollOffsetDelta(LayerImpl* layer_impl, | 473 static void SetScrollOffsetDelta(LayerImpl* layer_impl, |
474 const gfx::Vector2dF& delta) { | 474 const gfx::Vector2dF& delta) { |
475 if (layer_impl->layer_tree_impl() | 475 if (layer_impl->layer_tree_impl() |
476 ->property_trees() | 476 ->property_trees() |
477 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), | 477 ->scroll_tree.SetScrollOffsetDeltaForTesting(layer_impl->id(), |
478 delta)) | 478 delta)) |
479 layer_impl->layer_tree_impl()->DidUpdateScrollOffset( | 479 layer_impl->layer_tree_impl()->DidUpdateScrollOffset( |
480 layer_impl->id(), layer_impl->transform_tree_index()); | 480 layer_impl->id(), layer_impl->transform_tree_index()); |
481 } | 481 } |
482 | 482 |
| 483 void BeginImplFrameAndAnimate(BeginFrameArgs begin_frame_args, |
| 484 base::TimeTicks frame_time) { |
| 485 begin_frame_args.frame_time = frame_time; |
| 486 host_impl_->WillBeginImplFrame(begin_frame_args); |
| 487 host_impl_->Animate(); |
| 488 host_impl_->UpdateAnimationState(true); |
| 489 host_impl_->DidFinishImplFrame(); |
| 490 } |
| 491 |
483 FakeImplTaskRunnerProvider task_runner_provider_; | 492 FakeImplTaskRunnerProvider task_runner_provider_; |
484 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; | 493 DebugScopedSetMainThreadBlocked always_main_thread_blocked_; |
485 | 494 |
486 TestSharedBitmapManager shared_bitmap_manager_; | 495 TestSharedBitmapManager shared_bitmap_manager_; |
487 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; | 496 TestGpuMemoryBufferManager gpu_memory_buffer_manager_; |
488 TestTaskGraphRunner task_graph_runner_; | 497 TestTaskGraphRunner task_graph_runner_; |
489 scoped_ptr<OutputSurface> output_surface_; | 498 scoped_ptr<OutputSurface> output_surface_; |
490 scoped_ptr<LayerTreeHostImpl> host_impl_; | 499 scoped_ptr<LayerTreeHostImpl> host_impl_; |
491 FakeRenderingStatsInstrumentation stats_instrumentation_; | 500 FakeRenderingStatsInstrumentation stats_instrumentation_; |
492 bool on_can_draw_state_changed_called_; | 501 bool on_can_draw_state_changed_called_; |
(...skipping 9018 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9511 external_transform); | 9520 external_transform); |
9512 | 9521 |
9513 host_impl_->OnDraw(external_transform, external_viewport, external_clip, | 9522 host_impl_->OnDraw(external_transform, external_viewport, external_clip, |
9514 resourceless_software_draw); | 9523 resourceless_software_draw); |
9515 node = host_impl_->active_tree()->property_trees()->transform_tree.Node( | 9524 node = host_impl_->active_tree()->property_trees()->transform_tree.Node( |
9516 test_layer->transform_tree_index()); | 9525 test_layer->transform_tree_index()); |
9517 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f)); | 9526 EXPECT_EQ(node->data.sublayer_scale, gfx::Vector2dF(1.f, 1.f)); |
9518 } | 9527 } |
9519 | 9528 |
9520 TEST_F(LayerTreeHostImplTest, ScrollAnimated) { | 9529 TEST_F(LayerTreeHostImplTest, ScrollAnimated) { |
9521 SetupScrollAndContentsLayers(gfx::Size(100, 200)); | 9530 const gfx::Size content_size(1000, 1000); |
9522 | 9531 const gfx::Size viewport_size(50, 100); |
9523 // Shrink the outer viewport clip layer so that the outer viewport can scroll. | 9532 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
9524 host_impl_->OuterViewportScrollLayer()->parent()->SetBounds( | |
9525 gfx::Size(50, 100)); | |
9526 | 9533 |
9527 SetNeedsRebuildPropertyTrees(); | 9534 SetNeedsRebuildPropertyTrees(); |
9528 DrawFrame(); | 9535 DrawFrame(); |
9529 | 9536 |
9530 base::TimeTicks start_time = | 9537 base::TimeTicks start_time = |
9531 base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); | 9538 base::TimeTicks() + base::TimeDelta::FromMilliseconds(100); |
9532 | 9539 |
9533 BeginFrameArgs begin_frame_args = | 9540 BeginFrameArgs begin_frame_args = |
9534 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); | 9541 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
9535 | 9542 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9772 host_impl_->WillBeginImplFrame(begin_frame_args); | 9779 host_impl_->WillBeginImplFrame(begin_frame_args); |
9773 host_impl_->Animate(); | 9780 host_impl_->Animate(); |
9774 host_impl_->UpdateAnimationState(true); | 9781 host_impl_->UpdateAnimationState(true); |
9775 | 9782 |
9776 EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), | 9783 EXPECT_VECTOR_EQ(gfx::ScrollOffset(0, 100), |
9777 scrolling_layer->CurrentScrollOffset()); | 9784 scrolling_layer->CurrentScrollOffset()); |
9778 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); | 9785 EXPECT_EQ(NULL, host_impl_->CurrentlyScrollingLayer()); |
9779 host_impl_->DidFinishImplFrame(); | 9786 host_impl_->DidFinishImplFrame(); |
9780 } | 9787 } |
9781 | 9788 |
| 9789 // Test that the scroll delta for an animated scroll is distributed correctly |
| 9790 // between the inner and outer viewport. |
| 9791 TEST_F(LayerTreeHostImplTimelinesTest, ImplPinchZoomScrollAnimated) { |
| 9792 const gfx::Size content_size(200, 200); |
| 9793 const gfx::Size viewport_size(100, 100); |
| 9794 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 9795 |
| 9796 LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 9797 LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 9798 |
| 9799 // Zoom into the page by a 2X factor |
| 9800 float min_page_scale = 1.f, max_page_scale = 4.f; |
| 9801 float page_scale_factor = 2.f; |
| 9802 RebuildPropertyTrees(); |
| 9803 host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 9804 page_scale_factor, min_page_scale, max_page_scale); |
| 9805 host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 9806 |
| 9807 // Scroll by a small amount, there should be no bubbling to the outer |
| 9808 // viewport. |
| 9809 base::TimeTicks start_time = |
| 9810 base::TimeTicks() + base::TimeDelta::FromMilliseconds(250); |
| 9811 BeginFrameArgs begin_frame_args = |
| 9812 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 9813 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9814 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(10.f, 20.f)) |
| 9815 .thread); |
| 9816 host_impl_->Animate(); |
| 9817 host_impl_->UpdateAnimationState(true); |
| 9818 EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 9819 |
| 9820 BeginImplFrameAndAnimate(begin_frame_args, start_time); |
| 9821 EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 10), |
| 9822 inner_scroll_layer->CurrentScrollOffset()); |
| 9823 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 9824 outer_scroll_layer->CurrentScrollOffset()); |
| 9825 EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 9826 |
| 9827 // Scroll by the inner viewport's max scroll extent, the remainder |
| 9828 // should bubble up to the outer viewport. |
| 9829 EXPECT_EQ( |
| 9830 InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9831 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(100.f, 100.f)) |
| 9832 .thread); |
| 9833 host_impl_->Animate(); |
| 9834 host_impl_->UpdateAnimationState(true); |
| 9835 EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 9836 |
| 9837 BeginImplFrameAndAnimate(begin_frame_args, |
| 9838 start_time + base::TimeDelta::FromMilliseconds(350)); |
| 9839 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 9840 inner_scroll_layer->CurrentScrollOffset()); |
| 9841 EXPECT_VECTOR_EQ(gfx::Vector2dF(5, 10), |
| 9842 outer_scroll_layer->CurrentScrollOffset()); |
| 9843 |
| 9844 // Scroll by the outer viewport's max scroll extent, it should all go to the |
| 9845 // outer viewport. |
| 9846 EXPECT_EQ( |
| 9847 InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9848 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(190.f, 180.f)) |
| 9849 .thread); |
| 9850 host_impl_->Animate(); |
| 9851 host_impl_->UpdateAnimationState(true); |
| 9852 EXPECT_EQ(outer_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 9853 |
| 9854 BeginImplFrameAndAnimate(begin_frame_args, |
| 9855 start_time + base::TimeDelta::FromMilliseconds(850)); |
| 9856 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 9857 inner_scroll_layer->CurrentScrollOffset()); |
| 9858 EXPECT_VECTOR_EQ(gfx::Vector2dF(100, 100), |
| 9859 outer_scroll_layer->CurrentScrollOffset()); |
| 9860 |
| 9861 // Scroll upwards by the max scroll extent. The inner viewport should animate |
| 9862 // and the remainder should bubble to the outer viewport. |
| 9863 EXPECT_EQ( |
| 9864 InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9865 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(-110.f, -120.f)) |
| 9866 .thread); |
| 9867 host_impl_->Animate(); |
| 9868 host_impl_->UpdateAnimationState(true); |
| 9869 EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 9870 |
| 9871 BeginImplFrameAndAnimate( |
| 9872 begin_frame_args, start_time + base::TimeDelta::FromMilliseconds(1200)); |
| 9873 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 9874 inner_scroll_layer->CurrentScrollOffset()); |
| 9875 EXPECT_VECTOR_EQ(gfx::Vector2dF(95, 90), |
| 9876 outer_scroll_layer->CurrentScrollOffset()); |
| 9877 } |
| 9878 |
| 9879 // Test that the correct viewport scroll layer is updated when the target offset |
| 9880 // is updated. |
| 9881 TEST_F(LayerTreeHostImplTimelinesTest, ImplPinchZoomScrollAnimatedUpdate) { |
| 9882 const gfx::Size content_size(200, 200); |
| 9883 const gfx::Size viewport_size(100, 100); |
| 9884 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
| 9885 |
| 9886 LayerImpl* outer_scroll_layer = host_impl_->OuterViewportScrollLayer(); |
| 9887 LayerImpl* inner_scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 9888 |
| 9889 // Zoom into the page by a 2X factor |
| 9890 float min_page_scale = 1.f, max_page_scale = 4.f; |
| 9891 float page_scale_factor = 2.f; |
| 9892 RebuildPropertyTrees(); |
| 9893 host_impl_->active_tree()->PushPageScaleFromMainThread( |
| 9894 page_scale_factor, min_page_scale, max_page_scale); |
| 9895 host_impl_->active_tree()->SetPageScaleOnActiveTree(page_scale_factor); |
| 9896 |
| 9897 // Scroll the inner viewport. |
| 9898 base::TimeTicks start_time = |
| 9899 base::TimeTicks() + base::TimeDelta::FromMilliseconds(50); |
| 9900 BeginFrameArgs begin_frame_args = |
| 9901 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE); |
| 9902 EXPECT_EQ( |
| 9903 InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9904 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(90, 90)).thread); |
| 9905 host_impl_->Animate(); |
| 9906 host_impl_->UpdateAnimationState(true); |
| 9907 EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 9908 |
| 9909 BeginImplFrameAndAnimate(begin_frame_args, start_time); |
| 9910 float inner_x = inner_scroll_layer->CurrentScrollOffset().x(); |
| 9911 float inner_y = inner_scroll_layer->CurrentScrollOffset().y(); |
| 9912 EXPECT_TRUE(inner_x > 0 && inner_x < 45); |
| 9913 EXPECT_TRUE(inner_y > 0 && inner_y < 45); |
| 9914 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 9915 outer_scroll_layer->CurrentScrollOffset()); |
| 9916 |
| 9917 // Update target. |
| 9918 EXPECT_EQ( |
| 9919 InputHandler::SCROLL_ON_IMPL_THREAD, |
| 9920 host_impl_->ScrollAnimated(gfx::Point(), gfx::Vector2d(50, 50)).thread); |
| 9921 host_impl_->Animate(); |
| 9922 host_impl_->UpdateAnimationState(true); |
| 9923 EXPECT_EQ(inner_scroll_layer, host_impl_->CurrentlyScrollingLayer()); |
| 9924 |
| 9925 // Verify that all the delta is applied to the inner viewport and nothing is |
| 9926 // carried forward. |
| 9927 BeginImplFrameAndAnimate(begin_frame_args, |
| 9928 start_time + base::TimeDelta::FromMilliseconds(350)); |
| 9929 EXPECT_VECTOR_EQ(gfx::Vector2dF(50, 50), |
| 9930 inner_scroll_layer->CurrentScrollOffset()); |
| 9931 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), |
| 9932 outer_scroll_layer->CurrentScrollOffset()); |
| 9933 EXPECT_VECTOR_EQ(gfx::Vector2dF(), outer_scroll_layer->CurrentScrollOffset()); |
| 9934 } |
| 9935 |
9782 // Test that smooth scroll offset animation doesn't happen for non user | 9936 // Test that smooth scroll offset animation doesn't happen for non user |
9783 // scrollable layers. | 9937 // scrollable layers. |
9784 TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedNotUserScrollable) { | 9938 TEST_F(LayerTreeHostImplTimelinesTest, ScrollAnimatedNotUserScrollable) { |
9785 const gfx::Size content_size(1000, 1000); | 9939 const gfx::Size content_size(1000, 1000); |
9786 const gfx::Size viewport_size(500, 500); | 9940 const gfx::Size viewport_size(500, 500); |
9787 CreateBasicVirtualViewportLayers(viewport_size, content_size); | 9941 CreateBasicVirtualViewportLayers(viewport_size, content_size); |
9788 | 9942 |
9789 host_impl_->OuterViewportScrollLayer()->set_user_scrollable_vertical(true); | 9943 host_impl_->OuterViewportScrollLayer()->set_user_scrollable_vertical(true); |
9790 host_impl_->OuterViewportScrollLayer()->set_user_scrollable_horizontal(false); | 9944 host_impl_->OuterViewportScrollLayer()->set_user_scrollable_horizontal(false); |
9791 | 9945 |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10454 // There should not be any jitter measured till we hit the fixed point hits | 10608 // There should not be any jitter measured till we hit the fixed point hits |
10455 // threshold. | 10609 // threshold. |
10456 float expected_jitter = | 10610 float expected_jitter = |
10457 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; | 10611 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; |
10458 EXPECT_EQ(jitter, expected_jitter); | 10612 EXPECT_EQ(jitter, expected_jitter); |
10459 } | 10613 } |
10460 } | 10614 } |
10461 | 10615 |
10462 } // namespace | 10616 } // namespace |
10463 } // namespace cc | 10617 } // namespace cc |
OLD | NEW |