| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 } | 190 } |
| 191 | 191 |
| 192 static void ExpectClearedScrollDeltasRecursive(LayerImpl* layer) { | 192 static void ExpectClearedScrollDeltasRecursive(LayerImpl* layer) { |
| 193 ASSERT_EQ(layer->ScrollDelta(), gfx::Vector2d()); | 193 ASSERT_EQ(layer->ScrollDelta(), gfx::Vector2d()); |
| 194 for (size_t i = 0; i < layer->children().size(); ++i) | 194 for (size_t i = 0; i < layer->children().size(); ++i) |
| 195 ExpectClearedScrollDeltasRecursive(layer->children()[i]); | 195 ExpectClearedScrollDeltasRecursive(layer->children()[i]); |
| 196 } | 196 } |
| 197 | 197 |
| 198 static void ExpectContains(const ScrollAndScaleSet& scroll_info, | 198 static void ExpectContains(const ScrollAndScaleSet& scroll_info, |
| 199 int id, | 199 int id, |
| 200 const gfx::Vector2dF& scroll_delta) { | 200 const gfx::Vector2d& scroll_delta) { |
| 201 int times_encountered = 0; | 201 int times_encountered = 0; |
| 202 | 202 |
| 203 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 203 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| 204 if (scroll_info.scrolls[i].layer_id != id) | 204 if (scroll_info.scrolls[i].layer_id != id) |
| 205 continue; | 205 continue; |
| 206 EXPECT_VECTOR2DF_NEAR(scroll_delta, scroll_info.scrolls[i].scroll_delta, | 206 EXPECT_VECTOR_EQ(scroll_delta, scroll_info.scrolls[i].scroll_delta); |
| 207 1.0e-10); | |
| 208 times_encountered++; | 207 times_encountered++; |
| 209 } | 208 } |
| 210 | 209 |
| 211 ASSERT_EQ(1, times_encountered); | 210 ASSERT_EQ(1, times_encountered); |
| 212 } | 211 } |
| 213 | 212 |
| 214 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { | 213 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { |
| 215 int times_encountered = 0; | 214 int times_encountered = 0; |
| 216 | 215 |
| 217 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 216 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
| (...skipping 3494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3712 // Scroll to the right in screen coordinates with a gesture. | 3711 // Scroll to the right in screen coordinates with a gesture. |
| 3713 gfx::Vector2d gesture_scroll_delta(10, 0); | 3712 gfx::Vector2d gesture_scroll_delta(10, 0); |
| 3714 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3713 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3715 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); | 3714 host_impl_->ScrollBegin(gfx::Point(), InputHandler::GESTURE)); |
| 3716 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3715 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
| 3717 host_impl_->ScrollEnd(); | 3716 host_impl_->ScrollEnd(); |
| 3718 | 3717 |
| 3719 // The layer should have scrolled down in its local coordinates. | 3718 // The layer should have scrolled down in its local coordinates. |
| 3720 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 3719 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
| 3721 ExpectContains(*scroll_info.get(), scroll_layer->id(), | 3720 ExpectContains(*scroll_info.get(), scroll_layer->id(), |
| 3722 gfx::Vector2dF(0, gesture_scroll_delta.x())); | 3721 gfx::Vector2d(0, gesture_scroll_delta.x())); |
| 3723 | 3722 |
| 3724 // Reset and scroll down with the wheel. | 3723 // Reset and scroll down with the wheel. |
| 3725 scroll_layer->SetScrollDelta(gfx::Vector2dF()); | 3724 scroll_layer->SetScrollDelta(gfx::Vector2dF()); |
| 3726 gfx::Vector2d wheel_scroll_delta(0, 10); | 3725 gfx::Vector2d wheel_scroll_delta(0, 10); |
| 3727 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3726 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3728 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL)); | 3727 host_impl_->ScrollBegin(gfx::Point(), InputHandler::WHEEL)); |
| 3729 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); | 3728 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); |
| 3730 host_impl_->ScrollEnd(); | 3729 host_impl_->ScrollEnd(); |
| 3731 | 3730 |
| 3732 // The layer should have scrolled down in its local coordinates. | 3731 // The layer should have scrolled down in its local coordinates. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3771 { | 3770 { |
| 3772 // Scroll down in screen coordinates with a gesture. | 3771 // Scroll down in screen coordinates with a gesture. |
| 3773 gfx::Vector2d gesture_scroll_delta(0, 10); | 3772 gfx::Vector2d gesture_scroll_delta(0, 10); |
| 3774 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3773 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3775 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); | 3774 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); |
| 3776 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3775 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
| 3777 host_impl_->ScrollEnd(); | 3776 host_impl_->ScrollEnd(); |
| 3778 | 3777 |
| 3779 // The child layer should have scrolled down in its local coordinates an | 3778 // The child layer should have scrolled down in its local coordinates an |
| 3780 // amount proportional to the angle between it and the input scroll delta. | 3779 // amount proportional to the angle between it and the input scroll delta. |
| 3781 gfx::Vector2dF expected_scroll_delta( | 3780 gfx::Vector2d expected_scroll_delta( |
| 3782 0, gesture_scroll_delta.y() * | 3781 0, gesture_scroll_delta.y() * |
| 3783 std::cos(MathUtil::Deg2Rad(child_layer_angle))); | 3782 std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
| 3784 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3783 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 3785 host_impl_->ProcessScrollDeltas(); | 3784 host_impl_->ProcessScrollDeltas(); |
| 3786 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3785 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
| 3787 | 3786 |
| 3788 // The root scroll layer should not have scrolled, because the input delta | 3787 // The root scroll layer should not have scrolled, because the input delta |
| 3789 // was close to the layer's axis of movement. | 3788 // was close to the layer's axis of movement. |
| 3790 EXPECT_EQ(scroll_info->scrolls.size(), 1u); | 3789 EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
| 3791 } | 3790 } |
| 3792 { | 3791 { |
| 3793 // Now reset and scroll the same amount horizontally. | 3792 // Now reset and scroll the same amount horizontally. |
| 3794 child_ptr->SetScrollDelta(gfx::Vector2dF()); | 3793 child_ptr->SetScrollDelta(gfx::Vector2dF()); |
| 3795 gfx::Vector2d gesture_scroll_delta(10, 0); | 3794 gfx::Vector2d gesture_scroll_delta(10, 0); |
| 3796 EXPECT_EQ(InputHandler::SCROLL_STARTED, | 3795 EXPECT_EQ(InputHandler::SCROLL_STARTED, |
| 3797 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); | 3796 host_impl_->ScrollBegin(gfx::Point(1, 1), InputHandler::GESTURE)); |
| 3798 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3797 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
| 3799 host_impl_->ScrollEnd(); | 3798 host_impl_->ScrollEnd(); |
| 3800 | 3799 |
| 3801 // The child layer should have scrolled down in its local coordinates an | 3800 // The child layer should have scrolled down in its local coordinates an |
| 3802 // amount proportional to the angle between it and the input scroll delta. | 3801 // amount proportional to the angle between it and the input scroll delta. |
| 3803 gfx::Vector2dF expected_scroll_delta( | 3802 gfx::Vector2d expected_scroll_delta( |
| 3804 0, -gesture_scroll_delta.x() * | 3803 0, -gesture_scroll_delta.x() * |
| 3805 std::sin(MathUtil::Deg2Rad(child_layer_angle))); | 3804 std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
| 3806 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3805 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 3807 host_impl_->ProcessScrollDeltas(); | 3806 host_impl_->ProcessScrollDeltas(); |
| 3808 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3807 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
| 3809 | 3808 |
| 3810 // The root scroll layer should have scrolled more, since the input scroll | 3809 // The root scroll layer should have scrolled more, since the input scroll |
| 3811 // delta was mostly orthogonal to the child layer's vertical scroll axis. | 3810 // delta was mostly orthogonal to the child layer's vertical scroll axis. |
| 3812 gfx::Vector2dF expected_root_scroll_delta( | 3811 gfx::Vector2d expected_root_scroll_delta( |
| 3813 gesture_scroll_delta.x() * | 3812 gesture_scroll_delta.x() * |
| 3814 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), | 3813 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), |
| 3815 0); | 3814 0); |
| 3816 ExpectContains(*scroll_info.get(), | 3815 ExpectContains(*scroll_info.get(), |
| 3817 scroll_layer->id(), | 3816 scroll_layer->id(), |
| 3818 expected_root_scroll_delta); | 3817 expected_root_scroll_delta); |
| 3819 } | 3818 } |
| 3820 } | 3819 } |
| 3821 | 3820 |
| 3822 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { | 3821 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { |
| (...skipping 4676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8499 // surface. | 8498 // surface. |
| 8500 EXPECT_EQ(0, num_lost_surfaces_); | 8499 EXPECT_EQ(0, num_lost_surfaces_); |
| 8501 host_impl_->DidLoseOutputSurface(); | 8500 host_impl_->DidLoseOutputSurface(); |
| 8502 EXPECT_EQ(1, num_lost_surfaces_); | 8501 EXPECT_EQ(1, num_lost_surfaces_); |
| 8503 host_impl_->DidLoseOutputSurface(); | 8502 host_impl_->DidLoseOutputSurface(); |
| 8504 EXPECT_LE(1, num_lost_surfaces_); | 8503 EXPECT_LE(1, num_lost_surfaces_); |
| 8505 } | 8504 } |
| 8506 | 8505 |
| 8507 } // namespace | 8506 } // namespace |
| 8508 } // namespace cc | 8507 } // namespace cc |
| OLD | NEW |