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::Vector2d& scroll_delta) { | 200 const gfx::Vector2dF& 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_VECTOR_EQ(scroll_delta, scroll_info.scrolls[i].scroll_delta); | 206 EXPECT_VECTOR2DF_NEAR(scroll_delta, scroll_info.scrolls[i].scroll_delta, |
| 207 1.0e-10); |
207 times_encountered++; | 208 times_encountered++; |
208 } | 209 } |
209 | 210 |
210 ASSERT_EQ(1, times_encountered); | 211 ASSERT_EQ(1, times_encountered); |
211 } | 212 } |
212 | 213 |
213 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { | 214 static void ExpectNone(const ScrollAndScaleSet& scroll_info, int id) { |
214 int times_encountered = 0; | 215 int times_encountered = 0; |
215 | 216 |
216 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 217 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
(...skipping 3324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3541 // Scroll to the right in screen coordinates with a gesture. | 3542 // Scroll to the right in screen coordinates with a gesture. |
3542 gfx::Vector2d gesture_scroll_delta(10, 0); | 3543 gfx::Vector2d gesture_scroll_delta(10, 0); |
3543 EXPECT_EQ(InputHandler::ScrollStarted, | 3544 EXPECT_EQ(InputHandler::ScrollStarted, |
3544 host_impl_->ScrollBegin(gfx::Point(), | 3545 host_impl_->ScrollBegin(gfx::Point(), |
3545 InputHandler::Gesture)); | 3546 InputHandler::Gesture)); |
3546 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3547 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
3547 host_impl_->ScrollEnd(); | 3548 host_impl_->ScrollEnd(); |
3548 | 3549 |
3549 // The layer should have scrolled down in its local coordinates. | 3550 // The layer should have scrolled down in its local coordinates. |
3550 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); | 3551 scoped_ptr<ScrollAndScaleSet> scroll_info = host_impl_->ProcessScrollDeltas(); |
3551 ExpectContains(*scroll_info.get(), | 3552 ExpectContains(*scroll_info.get(), scroll_layer->id(), |
3552 scroll_layer->id(), | 3553 gfx::Vector2dF(0, gesture_scroll_delta.x())); |
3553 gfx::Vector2d(0, gesture_scroll_delta.x())); | |
3554 | 3554 |
3555 // Reset and scroll down with the wheel. | 3555 // Reset and scroll down with the wheel. |
3556 scroll_layer->SetScrollDelta(gfx::Vector2dF()); | 3556 scroll_layer->SetScrollDelta(gfx::Vector2dF()); |
3557 gfx::Vector2d wheel_scroll_delta(0, 10); | 3557 gfx::Vector2d wheel_scroll_delta(0, 10); |
3558 EXPECT_EQ(InputHandler::ScrollStarted, | 3558 EXPECT_EQ(InputHandler::ScrollStarted, |
3559 host_impl_->ScrollBegin(gfx::Point(), | 3559 host_impl_->ScrollBegin(gfx::Point(), |
3560 InputHandler::Wheel)); | 3560 InputHandler::Wheel)); |
3561 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); | 3561 host_impl_->ScrollBy(gfx::Point(), wheel_scroll_delta); |
3562 host_impl_->ScrollEnd(); | 3562 host_impl_->ScrollEnd(); |
3563 | 3563 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3604 // Scroll down in screen coordinates with a gesture. | 3604 // Scroll down in screen coordinates with a gesture. |
3605 gfx::Vector2d gesture_scroll_delta(0, 10); | 3605 gfx::Vector2d gesture_scroll_delta(0, 10); |
3606 EXPECT_EQ(InputHandler::ScrollStarted, | 3606 EXPECT_EQ(InputHandler::ScrollStarted, |
3607 host_impl_->ScrollBegin(gfx::Point(1, 1), | 3607 host_impl_->ScrollBegin(gfx::Point(1, 1), |
3608 InputHandler::Gesture)); | 3608 InputHandler::Gesture)); |
3609 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3609 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
3610 host_impl_->ScrollEnd(); | 3610 host_impl_->ScrollEnd(); |
3611 | 3611 |
3612 // The child layer should have scrolled down in its local coordinates an | 3612 // The child layer should have scrolled down in its local coordinates an |
3613 // amount proportional to the angle between it and the input scroll delta. | 3613 // amount proportional to the angle between it and the input scroll delta. |
3614 gfx::Vector2d expected_scroll_delta( | 3614 gfx::Vector2dF expected_scroll_delta( |
3615 0, | 3615 0, gesture_scroll_delta.y() * |
3616 gesture_scroll_delta.y() * | 3616 std::cos(MathUtil::Deg2Rad(child_layer_angle))); |
3617 std::cos(MathUtil::Deg2Rad(child_layer_angle))); | |
3618 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3617 scoped_ptr<ScrollAndScaleSet> scroll_info = |
3619 host_impl_->ProcessScrollDeltas(); | 3618 host_impl_->ProcessScrollDeltas(); |
3620 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3619 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
3621 | 3620 |
3622 // The root scroll layer should not have scrolled, because the input delta | 3621 // The root scroll layer should not have scrolled, because the input delta |
3623 // was close to the layer's axis of movement. | 3622 // was close to the layer's axis of movement. |
3624 EXPECT_EQ(scroll_info->scrolls.size(), 1u); | 3623 EXPECT_EQ(scroll_info->scrolls.size(), 1u); |
3625 } | 3624 } |
3626 { | 3625 { |
3627 // Now reset and scroll the same amount horizontally. | 3626 // Now reset and scroll the same amount horizontally. |
3628 child_ptr->SetScrollDelta(gfx::Vector2dF()); | 3627 child_ptr->SetScrollDelta(gfx::Vector2dF()); |
3629 gfx::Vector2d gesture_scroll_delta(10, 0); | 3628 gfx::Vector2d gesture_scroll_delta(10, 0); |
3630 EXPECT_EQ(InputHandler::ScrollStarted, | 3629 EXPECT_EQ(InputHandler::ScrollStarted, |
3631 host_impl_->ScrollBegin(gfx::Point(1, 1), | 3630 host_impl_->ScrollBegin(gfx::Point(1, 1), |
3632 InputHandler::Gesture)); | 3631 InputHandler::Gesture)); |
3633 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); | 3632 host_impl_->ScrollBy(gfx::Point(), gesture_scroll_delta); |
3634 host_impl_->ScrollEnd(); | 3633 host_impl_->ScrollEnd(); |
3635 | 3634 |
3636 // The child layer should have scrolled down in its local coordinates an | 3635 // The child layer should have scrolled down in its local coordinates an |
3637 // amount proportional to the angle between it and the input scroll delta. | 3636 // amount proportional to the angle between it and the input scroll delta. |
3638 gfx::Vector2d expected_scroll_delta( | 3637 gfx::Vector2dF expected_scroll_delta( |
3639 0, | 3638 0, -gesture_scroll_delta.x() * |
3640 -gesture_scroll_delta.x() * | 3639 std::sin(MathUtil::Deg2Rad(child_layer_angle))); |
3641 std::sin(MathUtil::Deg2Rad(child_layer_angle))); | |
3642 scoped_ptr<ScrollAndScaleSet> scroll_info = | 3640 scoped_ptr<ScrollAndScaleSet> scroll_info = |
3643 host_impl_->ProcessScrollDeltas(); | 3641 host_impl_->ProcessScrollDeltas(); |
3644 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); | 3642 ExpectContains(*scroll_info.get(), child_layer_id, expected_scroll_delta); |
3645 | 3643 |
3646 // The root scroll layer should have scrolled more, since the input scroll | 3644 // The root scroll layer should have scrolled more, since the input scroll |
3647 // delta was mostly orthogonal to the child layer's vertical scroll axis. | 3645 // delta was mostly orthogonal to the child layer's vertical scroll axis. |
3648 gfx::Vector2d expected_root_scroll_delta( | 3646 gfx::Vector2dF expected_root_scroll_delta( |
3649 gesture_scroll_delta.x() * | 3647 gesture_scroll_delta.x() * |
3650 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), | 3648 std::pow(std::cos(MathUtil::Deg2Rad(child_layer_angle)), 2), |
3651 0); | 3649 0); |
3652 ExpectContains(*scroll_info.get(), | 3650 ExpectContains(*scroll_info.get(), |
3653 scroll_layer->id(), | 3651 scroll_layer->id(), |
3654 expected_root_scroll_delta); | 3652 expected_root_scroll_delta); |
3655 } | 3653 } |
3656 } | 3654 } |
3657 | 3655 |
3658 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { | 3656 TEST_F(LayerTreeHostImplTest, ScrollScaledLayer) { |
(...skipping 4394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8053 // surface. | 8051 // surface. |
8054 EXPECT_EQ(0, num_lost_surfaces_); | 8052 EXPECT_EQ(0, num_lost_surfaces_); |
8055 host_impl_->DidLoseOutputSurface(); | 8053 host_impl_->DidLoseOutputSurface(); |
8056 EXPECT_EQ(1, num_lost_surfaces_); | 8054 EXPECT_EQ(1, num_lost_surfaces_); |
8057 host_impl_->DidLoseOutputSurface(); | 8055 host_impl_->DidLoseOutputSurface(); |
8058 EXPECT_LE(1, num_lost_surfaces_); | 8056 EXPECT_LE(1, num_lost_surfaces_); |
8059 } | 8057 } |
8060 | 8058 |
8061 } // namespace | 8059 } // namespace |
8062 } // namespace cc | 8060 } // namespace cc |
OLD | NEW |