| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 | 938 |
| 939 scoped_ptr<ScrollAndScaleSet> scroll_info = | 939 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 940 host_impl_->ProcessScrollDeltas(); | 940 host_impl_->ProcessScrollDeltas(); |
| 941 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | 941 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 942 | 942 |
| 943 EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(), | 943 EXPECT_EQ(gfx::ScrollOffset(75.0, 75.0).ToString(), |
| 944 scroll_layer->MaxScrollOffset().ToString()); | 944 scroll_layer->MaxScrollOffset().ToString()); |
| 945 } | 945 } |
| 946 | 946 |
| 947 // Scrolling after a pinch gesture should always be in local space. The | 947 // Scrolling after a pinch gesture should always be in local space. The |
| 948 // scroll deltas do not have the page scale factor applied. | 948 // scroll deltas have the page scale factor applied. |
| 949 { | 949 { |
| 950 host_impl_->active_tree()->SetPageScaleFactorAndLimits( | 950 host_impl_->active_tree()->SetPageScaleFactorAndLimits( |
| 951 page_scale_factor, min_page_scale, max_page_scale); | 951 page_scale_factor, min_page_scale, max_page_scale); |
| 952 host_impl_->active_tree()->SetPageScaleDelta(1.f); | 952 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
| 953 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 953 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
| 954 | 954 |
| 955 float page_scale_delta = 2.f; | 955 float page_scale_delta = 2.f; |
| 956 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); | 956 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
| 957 host_impl_->PinchGestureBegin(); | 957 host_impl_->PinchGestureBegin(); |
| 958 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); | 958 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 959 host_impl_->PinchGestureEnd(); | 959 host_impl_->PinchGestureEnd(); |
| 960 host_impl_->ScrollEnd(); | 960 host_impl_->ScrollEnd(); |
| 961 | 961 |
| 962 gfx::Vector2d scroll_delta(0, 10); | 962 gfx::Vector2d scroll_delta(0, 10); |
| 963 EXPECT_EQ(InputHandler::ScrollStarted, | 963 EXPECT_EQ(InputHandler::ScrollStarted, |
| 964 host_impl_->ScrollBegin(gfx::Point(5, 5), | 964 host_impl_->ScrollBegin(gfx::Point(5, 5), |
| 965 InputHandler::Wheel)); | 965 InputHandler::Wheel)); |
| 966 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 966 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 967 host_impl_->ScrollEnd(); | 967 host_impl_->ScrollEnd(); |
| 968 | 968 |
| 969 scoped_ptr<ScrollAndScaleSet> scroll_info = | 969 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 970 host_impl_->ProcessScrollDeltas(); | 970 host_impl_->ProcessScrollDeltas(); |
| 971 ExpectContains(*scroll_info.get(), | 971 ExpectContains(*scroll_info.get(), scroll_layer->id(), |
| 972 scroll_layer->id(), | 972 gfx::Vector2d(0, scroll_delta.y() / page_scale_delta)); |
| 973 scroll_delta); | |
| 974 } | 973 } |
| 975 } | 974 } |
| 976 | 975 |
| 977 TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) { | 976 TEST_F(LayerTreeHostImplTest, ScrollWithSwapPromises) { |
| 978 ui::LatencyInfo latency_info; | 977 ui::LatencyInfo latency_info; |
| 979 latency_info.trace_id = 1234; | 978 latency_info.trace_id = 1234; |
| 980 scoped_ptr<SwapPromise> swap_promise( | 979 scoped_ptr<SwapPromise> swap_promise( |
| 981 new LatencyInfoSwapPromise(latency_info)); | 980 new LatencyInfoSwapPromise(latency_info)); |
| 982 | 981 |
| 983 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 982 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1388 RenderingStatsInstrumentation* rendering_stats_instrumentation) | 1387 RenderingStatsInstrumentation* rendering_stats_instrumentation) |
| 1389 : LayerTreeHostImpl(settings, | 1388 : LayerTreeHostImpl(settings, |
| 1390 client, | 1389 client, |
| 1391 proxy, | 1390 proxy, |
| 1392 rendering_stats_instrumentation, | 1391 rendering_stats_instrumentation, |
| 1393 manager, | 1392 manager, |
| 1394 NULL, | 1393 NULL, |
| 1395 0) {} | 1394 0) {} |
| 1396 | 1395 |
| 1397 BeginFrameArgs CurrentBeginFrameArgs() const override { | 1396 BeginFrameArgs CurrentBeginFrameArgs() const override { |
| 1398 return CreateBeginFrameArgsForTesting(fake_current_physical_time_); | 1397 return CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, |
| 1398 fake_current_physical_time_); |
| 1399 } | 1399 } |
| 1400 | 1400 |
| 1401 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { | 1401 void SetCurrentPhysicalTimeTicksForTest(base::TimeTicks fake_now) { |
| 1402 fake_current_physical_time_ = fake_now; | 1402 fake_current_physical_time_ = fake_now; |
| 1403 } | 1403 } |
| 1404 | 1404 |
| 1405 private: | 1405 private: |
| 1406 base::TimeTicks fake_current_physical_time_; | 1406 base::TimeTicks fake_current_physical_time_; |
| 1407 }; | 1407 }; |
| 1408 | 1408 |
| (...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3589 gfx::Vector2d(0, scroll_delta.y() / scale)); | 3589 gfx::Vector2d(0, scroll_delta.y() / scale)); |
| 3590 | 3590 |
| 3591 // Reset and scroll down with the wheel. | 3591 // Reset and scroll down with the wheel. |
| 3592 scroll_layer->SetScrollDelta(gfx::Vector2dF()); | 3592 scroll_layer->SetScrollDelta(gfx::Vector2dF()); |
| 3593 gfx::Vector2d wheel_scroll_delta(0, 10); | 3593 gfx::Vector2d wheel_scroll_delta(0, 10); |
| 3594 EXPECT_EQ(InputHandler::ScrollStarted, | 3594 EXPECT_EQ(InputHandler::ScrollStarted, |
| 3595 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 3595 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
| 3596 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); | 3596 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); |
| 3597 host_impl_->ScrollEnd(); | 3597 host_impl_->ScrollEnd(); |
| 3598 | 3598 |
| 3599 // The scale should not have been applied to the scroll delta. | 3599 // It should apply the scale factor to the scroll delta for the wheel event. |
| 3600 scroll_info = host_impl_->ProcessScrollDeltas(); | 3600 scroll_info = host_impl_->ProcessScrollDeltas(); |
| 3601 ExpectContains(*scroll_info.get(), | 3601 ExpectContains(*scroll_info.get(), |
| 3602 scroll_layer->id(), | 3602 scroll_layer->id(), |
| 3603 wheel_scroll_delta); | 3603 wheel_scroll_delta); |
| 3604 } | 3604 } |
| 3605 | 3605 |
| 3606 TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { | 3606 TEST_F(LayerTreeHostImplTest, ScrollViewportRounding) { |
| 3607 int width = 332; | 3607 int width = 332; |
| 3608 int height = 20; | 3608 int height = 20; |
| 3609 int scale = 3; | 3609 int scale = 3; |
| (...skipping 4183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7793 | 7793 |
| 7794 EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); | 7794 EXPECT_EQ(2u, raw_pending_layer->did_become_active_call_count()); |
| 7795 EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); | 7795 EXPECT_EQ(1u, raw_mask_layer->did_become_active_call_count()); |
| 7796 EXPECT_EQ(0u, raw_replica_mask_layer->did_become_active_call_count()); | 7796 EXPECT_EQ(0u, raw_replica_mask_layer->did_become_active_call_count()); |
| 7797 pending_tree->DidBecomeActive(); | 7797 pending_tree->DidBecomeActive(); |
| 7798 EXPECT_EQ(3u, raw_pending_layer->did_become_active_call_count()); | 7798 EXPECT_EQ(3u, raw_pending_layer->did_become_active_call_count()); |
| 7799 EXPECT_EQ(2u, raw_mask_layer->did_become_active_call_count()); | 7799 EXPECT_EQ(2u, raw_mask_layer->did_become_active_call_count()); |
| 7800 EXPECT_EQ(1u, raw_replica_mask_layer->did_become_active_call_count()); | 7800 EXPECT_EQ(1u, raw_replica_mask_layer->did_become_active_call_count()); |
| 7801 } | 7801 } |
| 7802 | 7802 |
| 7803 TEST_F(LayerTreeHostImplTest, WheelScrollWithPageScaleFactorOnInnerLayer) { |
| 7804 LayerImpl* scroll_layer = SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 7805 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 7806 DrawFrame(); |
| 7807 |
| 7808 EXPECT_EQ(scroll_layer, host_impl_->InnerViewportScrollLayer()); |
| 7809 |
| 7810 float min_page_scale = 1.f, max_page_scale = 4.f; |
| 7811 float page_scale_factor = 1.f; |
| 7812 |
| 7813 // The scroll deltas should have the page scale factor applied. |
| 7814 { |
| 7815 host_impl_->active_tree()->SetPageScaleFactorAndLimits( |
| 7816 page_scale_factor, min_page_scale, max_page_scale); |
| 7817 host_impl_->active_tree()->SetPageScaleDelta(1.f); |
| 7818 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
| 7819 |
| 7820 float page_scale_delta = 2.f; |
| 7821 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Gesture); |
| 7822 host_impl_->PinchGestureBegin(); |
| 7823 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 7824 host_impl_->PinchGestureEnd(); |
| 7825 host_impl_->ScrollEnd(); |
| 7826 |
| 7827 gfx::Vector2dF scroll_delta(0, 5); |
| 7828 EXPECT_EQ(InputHandler::ScrollStarted, |
| 7829 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
| 7830 EXPECT_VECTOR_EQ(gfx::Vector2dF(), scroll_layer->TotalScrollOffset()); |
| 7831 |
| 7832 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
| 7833 host_impl_->ScrollEnd(); |
| 7834 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 2.5), scroll_layer->TotalScrollOffset()); |
| 7835 } |
| 7836 } |
| 7837 |
| 7803 class LayerTreeHostImplCountingLostSurfaces : public LayerTreeHostImplTest { | 7838 class LayerTreeHostImplCountingLostSurfaces : public LayerTreeHostImplTest { |
| 7804 public: | 7839 public: |
| 7805 LayerTreeHostImplCountingLostSurfaces() : num_lost_surfaces_(0) {} | 7840 LayerTreeHostImplCountingLostSurfaces() : num_lost_surfaces_(0) {} |
| 7806 void DidLoseOutputSurfaceOnImplThread() override { num_lost_surfaces_++; } | 7841 void DidLoseOutputSurfaceOnImplThread() override { num_lost_surfaces_++; } |
| 7807 | 7842 |
| 7808 protected: | 7843 protected: |
| 7809 int num_lost_surfaces_; | 7844 int num_lost_surfaces_; |
| 7810 }; | 7845 }; |
| 7811 | 7846 |
| 7812 TEST_F(LayerTreeHostImplCountingLostSurfaces, TwiceLostSurface) { | 7847 TEST_F(LayerTreeHostImplCountingLostSurfaces, TwiceLostSurface) { |
| 7813 // Really we just need at least one client notification each time | 7848 // Really we just need at least one client notification each time |
| 7814 // we go from having a valid output surface to not having a valid output | 7849 // we go from having a valid output surface to not having a valid output |
| 7815 // surface. | 7850 // surface. |
| 7816 EXPECT_EQ(0, num_lost_surfaces_); | 7851 EXPECT_EQ(0, num_lost_surfaces_); |
| 7817 host_impl_->DidLoseOutputSurface(); | 7852 host_impl_->DidLoseOutputSurface(); |
| 7818 EXPECT_EQ(1, num_lost_surfaces_); | 7853 EXPECT_EQ(1, num_lost_surfaces_); |
| 7819 host_impl_->DidLoseOutputSurface(); | 7854 host_impl_->DidLoseOutputSurface(); |
| 7820 EXPECT_LE(1, num_lost_surfaces_); | 7855 EXPECT_LE(1, num_lost_surfaces_); |
| 7821 } | 7856 } |
| 7822 | 7857 |
| 7823 } // namespace | 7858 } // namespace |
| 7824 } // namespace cc | 7859 } // namespace cc |
| OLD | NEW |