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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 #include "cc/test/fake_picture_layer_impl.h" | 54 #include "cc/test/fake_picture_layer_impl.h" |
55 #include "cc/test/fake_raster_source.h" | 55 #include "cc/test/fake_raster_source.h" |
56 #include "cc/test/fake_video_frame_provider.h" | 56 #include "cc/test/fake_video_frame_provider.h" |
57 #include "cc/test/geometry_test_utils.h" | 57 #include "cc/test/geometry_test_utils.h" |
58 #include "cc/test/gpu_rasterization_enabled_settings.h" | 58 #include "cc/test/gpu_rasterization_enabled_settings.h" |
59 #include "cc/test/layer_test_common.h" | 59 #include "cc/test/layer_test_common.h" |
60 #include "cc/test/layer_tree_test.h" | 60 #include "cc/test/layer_tree_test.h" |
61 #include "cc/test/test_compositor_frame_sink.h" | 61 #include "cc/test/test_compositor_frame_sink.h" |
62 #include "cc/test/test_task_graph_runner.h" | 62 #include "cc/test/test_task_graph_runner.h" |
63 #include "cc/test/test_web_graphics_context_3d.h" | 63 #include "cc/test/test_web_graphics_context_3d.h" |
64 #include "cc/trees/draw_property_utils.h" | |
65 #include "cc/trees/effect_node.h" | 64 #include "cc/trees/effect_node.h" |
66 #include "cc/trees/layer_tree_host_common.h" | 65 #include "cc/trees/layer_tree_host_common.h" |
67 #include "cc/trees/layer_tree_impl.h" | 66 #include "cc/trees/layer_tree_impl.h" |
68 #include "cc/trees/mutator_host.h" | 67 #include "cc/trees/mutator_host.h" |
69 #include "cc/trees/single_thread_proxy.h" | 68 #include "cc/trees/single_thread_proxy.h" |
70 #include "cc/trees/transform_node.h" | 69 #include "cc/trees/transform_node.h" |
71 #include "media/base/media.h" | 70 #include "media/base/media.h" |
72 #include "testing/gmock/include/gmock/gmock.h" | 71 #include "testing/gmock/include/gmock/gmock.h" |
73 #include "testing/gtest/include/gtest/gtest.h" | 72 #include "testing/gtest/include/gtest/gtest.h" |
74 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 73 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
(...skipping 2174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 host_impl_->ScrollEnd(EndState().get()); | 2248 host_impl_->ScrollEnd(EndState().get()); |
2250 | 2249 |
2251 std::unique_ptr<ScrollAndScaleSet> scroll_info = | 2250 std::unique_ptr<ScrollAndScaleSet> scroll_info = |
2252 host_impl_->ProcessScrollDeltas(); | 2251 host_impl_->ProcessScrollDeltas(); |
2253 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); | 2252 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); |
2254 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), | 2253 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
2255 gfx::Vector2d(10, 10))); | 2254 gfx::Vector2d(10, 10))); |
2256 } | 2255 } |
2257 } | 2256 } |
2258 | 2257 |
2259 TEST_F(LayerTreeHostImplTest, SyncSubpixelScrollDelta) { | |
2260 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | |
2261 host_impl_->SetViewportSize(gfx::Size(50, 50)); | |
2262 DrawFrame(); | |
2263 | |
2264 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); | |
2265 DCHECK(scroll_layer); | |
2266 | |
2267 float min_page_scale = 1.f; | |
2268 float max_page_scale = 4.f; | |
2269 | |
2270 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, | |
2271 max_page_scale); | |
2272 SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); | |
2273 scroll_layer->layer_tree_impl() | |
2274 ->property_trees() | |
2275 ->scroll_tree.CollectScrollDeltasForTesting(); | |
2276 scroll_layer->layer_tree_impl() | |
2277 ->property_trees() | |
2278 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), | |
2279 gfx::ScrollOffset(0, 20)); | |
2280 | |
2281 float page_scale_delta = 1.f; | |
2282 host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), | |
2283 InputHandler::TOUCHSCREEN); | |
2284 host_impl_->PinchGestureBegin(); | |
2285 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); | |
2286 host_impl_->ScrollBy( | |
2287 UpdateState(gfx::Point(10, 10), gfx::Vector2dF(0, -1.001f)).get()); | |
2288 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 9)); | |
2289 host_impl_->PinchGestureEnd(); | |
2290 host_impl_->ScrollEnd(EndState().get()); | |
2291 | |
2292 std::unique_ptr<ScrollAndScaleSet> scroll_info = | |
2293 host_impl_->ProcessScrollDeltas(); | |
2294 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | |
2295 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), | |
2296 gfx::Vector2d(0, -1))); | |
2297 | |
2298 // Verify this scroll delta is consistent with the snapped position of the | |
2299 // scroll layer. | |
2300 draw_property_utils::ComputeTransforms( | |
2301 &scroll_layer->layer_tree_impl()->property_trees()->transform_tree); | |
2302 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, -19.f), | |
2303 scroll_layer->ScreenSpaceTransform().To2dTranslation()); | |
2304 } | |
2305 | |
2306 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { | 2258 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { |
2307 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2259 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
2308 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 2260 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
2309 DrawFrame(); | 2261 DrawFrame(); |
2310 | 2262 |
2311 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); | 2263 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
2312 DCHECK(scroll_layer); | 2264 DCHECK(scroll_layer); |
2313 | 2265 |
2314 float min_page_scale = 0.5f; | 2266 float min_page_scale = 0.5f; |
2315 float max_page_scale = 4.f; | 2267 float max_page_scale = 4.f; |
(...skipping 3417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5733 | 5685 |
5734 gfx::Vector2d gesture_scroll_deltas[4]; | 5686 gfx::Vector2d gesture_scroll_deltas[4]; |
5735 gesture_scroll_deltas[0] = gfx::Vector2d(4, 10); | 5687 gesture_scroll_deltas[0] = gfx::Vector2d(4, 10); |
5736 gesture_scroll_deltas[1] = gfx::Vector2d(4, 10); | 5688 gesture_scroll_deltas[1] = gfx::Vector2d(4, 10); |
5737 gesture_scroll_deltas[2] = gfx::Vector2d(10, 0); | 5689 gesture_scroll_deltas[2] = gfx::Vector2d(10, 0); |
5738 gesture_scroll_deltas[3] = gfx::Vector2d(10, 0); | 5690 gesture_scroll_deltas[3] = gfx::Vector2d(10, 0); |
5739 | 5691 |
5740 gfx::Vector2d expected_scroll_deltas[4]; | 5692 gfx::Vector2d expected_scroll_deltas[4]; |
5741 // Perspective affects the vertical delta by a different | 5693 // Perspective affects the vertical delta by a different |
5742 // amount depending on the vertical position of the |viewport_point|. | 5694 // amount depending on the vertical position of the |viewport_point|. |
5743 expected_scroll_deltas[0] = gfx::Vector2d(2, 9); | 5695 expected_scroll_deltas[0] = gfx::Vector2d(2, 8); |
5744 expected_scroll_deltas[1] = gfx::Vector2d(1, 4); | 5696 expected_scroll_deltas[1] = gfx::Vector2d(1, 4); |
5745 // Deltas which start with the same vertical position of the | 5697 // Deltas which start with the same vertical position of the |
5746 // |viewport_point| are subject to identical perspective effects. | 5698 // |viewport_point| are subject to identical perspective effects. |
5747 expected_scroll_deltas[2] = gfx::Vector2d(5, 0); | 5699 expected_scroll_deltas[2] = gfx::Vector2d(4, 0); |
5748 expected_scroll_deltas[3] = gfx::Vector2d(5, 0); | 5700 expected_scroll_deltas[3] = gfx::Vector2d(4, 0); |
5749 | 5701 |
5750 gfx::Point viewport_point(1, 1); | 5702 gfx::Point viewport_point(1, 1); |
5751 | 5703 |
5752 // Scroll in screen coordinates with a gesture. Each scroll starts | 5704 // Scroll in screen coordinates with a gesture. Each scroll starts |
5753 // where the previous scroll ended, but the scroll position is reset | 5705 // where the previous scroll ended, but the scroll position is reset |
5754 // for each scroll. | 5706 // for each scroll. |
5755 for (int i = 0; i < 4; ++i) { | 5707 for (int i = 0; i < 4; ++i) { |
5756 SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); | 5708 SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); |
5757 DrawFrame(); | 5709 DrawFrame(); |
5758 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 5710 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
(...skipping 6008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11767 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11719 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
11768 host_impl_->MouseMoveAt(gfx::Point(10, 150)); | 11720 host_impl_->MouseMoveAt(gfx::Point(10, 150)); |
11769 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); | 11721 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); |
11770 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); | 11722 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); |
11771 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); | 11723 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); |
11772 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11724 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
11773 } | 11725 } |
11774 | 11726 |
11775 } // namespace | 11727 } // namespace |
11776 } // namespace cc | 11728 } // namespace cc |
OLD | NEW |