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" |
64 #include "cc/trees/effect_node.h" | 65 #include "cc/trees/effect_node.h" |
65 #include "cc/trees/layer_tree_host_common.h" | 66 #include "cc/trees/layer_tree_host_common.h" |
66 #include "cc/trees/layer_tree_impl.h" | 67 #include "cc/trees/layer_tree_impl.h" |
67 #include "cc/trees/mutator_host.h" | 68 #include "cc/trees/mutator_host.h" |
68 #include "cc/trees/single_thread_proxy.h" | 69 #include "cc/trees/single_thread_proxy.h" |
69 #include "cc/trees/transform_node.h" | 70 #include "cc/trees/transform_node.h" |
70 #include "media/base/media.h" | 71 #include "media/base/media.h" |
71 #include "testing/gmock/include/gmock/gmock.h" | 72 #include "testing/gmock/include/gmock/gmock.h" |
72 #include "testing/gtest/include/gtest/gtest.h" | 73 #include "testing/gtest/include/gtest/gtest.h" |
73 #include "third_party/skia/include/core/SkMallocPixelRef.h" | 74 #include "third_party/skia/include/core/SkMallocPixelRef.h" |
(...skipping 2193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2267 host_impl_->ScrollEnd(EndState().get()); | 2268 host_impl_->ScrollEnd(EndState().get()); |
2268 | 2269 |
2269 std::unique_ptr<ScrollAndScaleSet> scroll_info = | 2270 std::unique_ptr<ScrollAndScaleSet> scroll_info = |
2270 host_impl_->ProcessScrollDeltas(); | 2271 host_impl_->ProcessScrollDeltas(); |
2271 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); | 2272 EXPECT_EQ(scroll_info->page_scale_delta, 2.f); |
2272 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), | 2273 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
2273 gfx::Vector2d(10, 10))); | 2274 gfx::Vector2d(10, 10))); |
2274 } | 2275 } |
2275 } | 2276 } |
2276 | 2277 |
| 2278 TEST_F(LayerTreeHostImplTest, SyncSubpixelScrollDelta) { |
| 2279 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
| 2280 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
| 2281 DrawFrame(); |
| 2282 |
| 2283 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
| 2284 DCHECK(scroll_layer); |
| 2285 |
| 2286 float min_page_scale = 1.f; |
| 2287 float max_page_scale = 4.f; |
| 2288 |
| 2289 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
| 2290 max_page_scale); |
| 2291 SetScrollOffsetDelta(scroll_layer, gfx::Vector2d()); |
| 2292 scroll_layer->layer_tree_impl() |
| 2293 ->property_trees() |
| 2294 ->scroll_tree.CollectScrollDeltasForTesting(); |
| 2295 scroll_layer->layer_tree_impl() |
| 2296 ->property_trees() |
| 2297 ->scroll_tree.UpdateScrollOffsetBaseForTesting(scroll_layer->id(), |
| 2298 gfx::ScrollOffset(0, 20)); |
| 2299 |
| 2300 float page_scale_delta = 1.f; |
| 2301 host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
| 2302 InputHandler::TOUCHSCREEN); |
| 2303 host_impl_->PinchGestureBegin(); |
| 2304 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); |
| 2305 host_impl_->ScrollBy( |
| 2306 UpdateState(gfx::Point(10, 10), gfx::Vector2dF(0, -1.001f)).get()); |
| 2307 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 9)); |
| 2308 host_impl_->PinchGestureEnd(); |
| 2309 host_impl_->ScrollEnd(EndState().get()); |
| 2310 |
| 2311 std::unique_ptr<ScrollAndScaleSet> scroll_info = |
| 2312 host_impl_->ProcessScrollDeltas(); |
| 2313 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 2314 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2315 gfx::Vector2d(0, -1))); |
| 2316 |
| 2317 // Verify this scroll delta is consistent with the snapped position of the |
| 2318 // scroll layer. |
| 2319 draw_property_utils::ComputeTransforms( |
| 2320 &scroll_layer->layer_tree_impl()->property_trees()->transform_tree); |
| 2321 EXPECT_VECTOR_EQ(gfx::Vector2dF(0.f, -19.f), |
| 2322 scroll_layer->ScreenSpaceTransform().To2dTranslation()); |
| 2323 } |
| 2324 |
2277 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { | 2325 TEST_F(LayerTreeHostImplTest, PageScaleAnimation) { |
2278 SetupScrollAndContentsLayers(gfx::Size(100, 100)); | 2326 SetupScrollAndContentsLayers(gfx::Size(100, 100)); |
2279 host_impl_->SetViewportSize(gfx::Size(50, 50)); | 2327 host_impl_->SetViewportSize(gfx::Size(50, 50)); |
2280 DrawFrame(); | 2328 DrawFrame(); |
2281 | 2329 |
2282 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); | 2330 LayerImpl* scroll_layer = host_impl_->InnerViewportScrollLayer(); |
2283 DCHECK(scroll_layer); | 2331 DCHECK(scroll_layer); |
2284 | 2332 |
2285 float min_page_scale = 0.5f; | 2333 float min_page_scale = 0.5f; |
2286 float max_page_scale = 4.f; | 2334 float max_page_scale = 4.f; |
(...skipping 3387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5674 | 5722 |
5675 gfx::Vector2d gesture_scroll_deltas[4]; | 5723 gfx::Vector2d gesture_scroll_deltas[4]; |
5676 gesture_scroll_deltas[0] = gfx::Vector2d(4, 10); | 5724 gesture_scroll_deltas[0] = gfx::Vector2d(4, 10); |
5677 gesture_scroll_deltas[1] = gfx::Vector2d(4, 10); | 5725 gesture_scroll_deltas[1] = gfx::Vector2d(4, 10); |
5678 gesture_scroll_deltas[2] = gfx::Vector2d(10, 0); | 5726 gesture_scroll_deltas[2] = gfx::Vector2d(10, 0); |
5679 gesture_scroll_deltas[3] = gfx::Vector2d(10, 0); | 5727 gesture_scroll_deltas[3] = gfx::Vector2d(10, 0); |
5680 | 5728 |
5681 gfx::Vector2d expected_scroll_deltas[4]; | 5729 gfx::Vector2d expected_scroll_deltas[4]; |
5682 // Perspective affects the vertical delta by a different | 5730 // Perspective affects the vertical delta by a different |
5683 // amount depending on the vertical position of the |viewport_point|. | 5731 // amount depending on the vertical position of the |viewport_point|. |
5684 expected_scroll_deltas[0] = gfx::Vector2d(2, 8); | 5732 expected_scroll_deltas[0] = gfx::Vector2d(2, 9); |
5685 expected_scroll_deltas[1] = gfx::Vector2d(1, 4); | 5733 expected_scroll_deltas[1] = gfx::Vector2d(1, 4); |
5686 // Deltas which start with the same vertical position of the | 5734 // Deltas which start with the same vertical position of the |
5687 // |viewport_point| are subject to identical perspective effects. | 5735 // |viewport_point| are subject to identical perspective effects. |
5688 expected_scroll_deltas[2] = gfx::Vector2d(4, 0); | 5736 expected_scroll_deltas[2] = gfx::Vector2d(5, 0); |
5689 expected_scroll_deltas[3] = gfx::Vector2d(4, 0); | 5737 expected_scroll_deltas[3] = gfx::Vector2d(5, 0); |
5690 | 5738 |
5691 gfx::Point viewport_point(1, 1); | 5739 gfx::Point viewport_point(1, 1); |
5692 | 5740 |
5693 // Scroll in screen coordinates with a gesture. Each scroll starts | 5741 // Scroll in screen coordinates with a gesture. Each scroll starts |
5694 // where the previous scroll ended, but the scroll position is reset | 5742 // where the previous scroll ended, but the scroll position is reset |
5695 // for each scroll. | 5743 // for each scroll. |
5696 for (int i = 0; i < 4; ++i) { | 5744 for (int i = 0; i < 4; ++i) { |
5697 SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); | 5745 SetScrollOffsetDelta(child_ptr, gfx::Vector2dF()); |
5698 DrawFrame(); | 5746 DrawFrame(); |
5699 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, | 5747 EXPECT_EQ(InputHandler::SCROLL_ON_IMPL_THREAD, |
(...skipping 5921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11621 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11669 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
11622 host_impl_->MouseMoveAt(gfx::Point(10, 150)); | 11670 host_impl_->MouseMoveAt(gfx::Point(10, 150)); |
11623 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); | 11671 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_near_scrollbar()); |
11624 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); | 11672 EXPECT_TRUE(scrollbar_1_animation_controller->mouse_is_over_scrollbar()); |
11625 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); | 11673 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_near_scrollbar()); |
11626 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); | 11674 EXPECT_FALSE(scrollbar_2_animation_controller->mouse_is_over_scrollbar()); |
11627 } | 11675 } |
11628 | 11676 |
11629 } // namespace | 11677 } // namespace |
11630 } // namespace cc | 11678 } // namespace cc |
OLD | NEW |