Chromium Code Reviews| 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 2015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2026 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2026 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 2027 host_impl_->ProcessScrollDeltas(); | 2027 host_impl_->ProcessScrollDeltas(); |
| 2028 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale); | 2028 EXPECT_EQ(scroll_info->page_scale_delta, max_page_scale); |
| 2029 } | 2029 } |
| 2030 | 2030 |
| 2031 // Zoom-out clamping | 2031 // Zoom-out clamping |
| 2032 { | 2032 { |
| 2033 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, | 2033 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
| 2034 max_page_scale); | 2034 max_page_scale); |
| 2035 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 2035 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
| 2036 scroll_layer->PullDeltaForMainThread(); | 2036 scroll_layer->synced_scroll_offset()->PullDeltaForMainThread(); |
| 2037 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(50, 50)); | 2037 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(50, 50)); |
| 2038 | 2038 |
| 2039 float page_scale_delta = 0.1f; | 2039 float page_scale_delta = 0.1f; |
| 2040 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), | 2040 host_impl_->ScrollBegin(BeginState(gfx::Point()).get(), |
| 2041 InputHandler::GESTURE); | 2041 InputHandler::GESTURE); |
| 2042 host_impl_->PinchGestureBegin(); | 2042 host_impl_->PinchGestureBegin(); |
| 2043 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); | 2043 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point()); |
| 2044 host_impl_->PinchGestureEnd(); | 2044 host_impl_->PinchGestureEnd(); |
| 2045 host_impl_->ScrollEnd(EndState().get()); | 2045 host_impl_->ScrollEnd(EndState().get()); |
| 2046 | 2046 |
| 2047 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2047 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 2048 host_impl_->ProcessScrollDeltas(); | 2048 host_impl_->ProcessScrollDeltas(); |
| 2049 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); | 2049 EXPECT_EQ(scroll_info->page_scale_delta, min_page_scale); |
| 2050 | 2050 |
| 2051 EXPECT_TRUE(scroll_info->scrolls.empty()); | 2051 EXPECT_TRUE(scroll_info->scrolls.empty()); |
| 2052 } | 2052 } |
| 2053 | 2053 |
| 2054 // Two-finger panning should not happen based on pinch events only | 2054 // Two-finger panning should not happen based on pinch events only |
| 2055 { | 2055 { |
| 2056 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, | 2056 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
| 2057 max_page_scale); | 2057 max_page_scale); |
| 2058 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 2058 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
| 2059 scroll_layer->PullDeltaForMainThread(); | 2059 scroll_layer->synced_scroll_offset()->PullDeltaForMainThread(); |
| 2060 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(20, 20)); | 2060 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(20, 20)); |
| 2061 | 2061 |
| 2062 float page_scale_delta = 1.f; | 2062 float page_scale_delta = 1.f; |
| 2063 host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), | 2063 host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
| 2064 InputHandler::GESTURE); | 2064 InputHandler::GESTURE); |
| 2065 host_impl_->PinchGestureBegin(); | 2065 host_impl_->PinchGestureBegin(); |
| 2066 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); | 2066 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); |
| 2067 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); | 2067 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); |
| 2068 host_impl_->PinchGestureEnd(); | 2068 host_impl_->PinchGestureEnd(); |
| 2069 host_impl_->ScrollEnd(EndState().get()); | 2069 host_impl_->ScrollEnd(EndState().get()); |
| 2070 | 2070 |
| 2071 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2071 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 2072 host_impl_->ProcessScrollDeltas(); | 2072 host_impl_->ProcessScrollDeltas(); |
| 2073 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | 2073 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 2074 EXPECT_TRUE(scroll_info->scrolls.empty()); | 2074 EXPECT_TRUE(scroll_info->scrolls.empty()); |
| 2075 } | 2075 } |
| 2076 | 2076 |
| 2077 // Two-finger panning should work with interleaved scroll events | 2077 // Two-finger panning should work with interleaved scroll events |
| 2078 { | 2078 { |
| 2079 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, | 2079 host_impl_->active_tree()->PushPageScaleFromMainThread(1.f, min_page_scale, |
| 2080 max_page_scale); | 2080 max_page_scale); |
| 2081 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 2081 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
| 2082 scroll_layer->PullDeltaForMainThread(); | 2082 scroll_layer->synced_scroll_offset()->PullDeltaForMainThread(); |
| 2083 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(20, 20)); | 2083 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(20, 20)); |
| 2084 | 2084 |
| 2085 float page_scale_delta = 1.f; | 2085 float page_scale_delta = 1.f; |
| 2086 host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), | 2086 host_impl_->ScrollBegin(BeginState(gfx::Point(10, 10)).get(), |
| 2087 InputHandler::GESTURE); | 2087 InputHandler::GESTURE); |
| 2088 host_impl_->PinchGestureBegin(); | 2088 host_impl_->PinchGestureBegin(); |
| 2089 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); | 2089 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(10, 10)); |
| 2090 host_impl_->ScrollBy( | 2090 host_impl_->ScrollBy( |
| 2091 UpdateState(gfx::Point(10, 10), gfx::Vector2d(-10, -10)).get()); | 2091 UpdateState(gfx::Point(10, 10), gfx::Vector2d(-10, -10)).get()); |
| 2092 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); | 2092 host_impl_->PinchGestureUpdate(page_scale_delta, gfx::Point(20, 20)); |
| 2093 host_impl_->PinchGestureEnd(); | 2093 host_impl_->PinchGestureEnd(); |
| 2094 host_impl_->ScrollEnd(EndState().get()); | 2094 host_impl_->ScrollEnd(EndState().get()); |
| 2095 | 2095 |
| 2096 scoped_ptr<ScrollAndScaleSet> scroll_info = | 2096 scoped_ptr<ScrollAndScaleSet> scroll_info = |
| 2097 host_impl_->ProcessScrollDeltas(); | 2097 host_impl_->ProcessScrollDeltas(); |
| 2098 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); | 2098 EXPECT_EQ(scroll_info->page_scale_delta, page_scale_delta); |
| 2099 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), | 2099 EXPECT_TRUE(ScrollInfoContains(*scroll_info, scroll_layer->id(), |
| 2100 gfx::Vector2d(-10, -10))); | 2100 gfx::Vector2d(-10, -10))); |
| 2101 } | 2101 } |
| 2102 | 2102 |
| 2103 // Two-finger panning should work when starting fully zoomed out. | 2103 // Two-finger panning should work when starting fully zoomed out. |
| 2104 { | 2104 { |
| 2105 host_impl_->active_tree()->PushPageScaleFromMainThread(0.5f, 0.5f, 4.f); | 2105 host_impl_->active_tree()->PushPageScaleFromMainThread(0.5f, 0.5f, 4.f); |
| 2106 scroll_layer->SetScrollDelta(gfx::Vector2d()); | 2106 scroll_layer->SetScrollDelta(gfx::Vector2d()); |
| 2107 scroll_layer->PullDeltaForMainThread(); | 2107 scroll_layer->synced_scroll_offset()->PullDeltaForMainThread(); |
| 2108 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 0)); | 2108 scroll_layer->PushScrollOffsetFromMainThread(gfx::ScrollOffset(0, 0)); |
| 2109 | 2109 |
| 2110 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), | 2110 host_impl_->ScrollBegin(BeginState(gfx::Point(0, 0)).get(), |
| 2111 InputHandler::GESTURE); | 2111 InputHandler::GESTURE); |
| 2112 host_impl_->PinchGestureBegin(); | 2112 host_impl_->PinchGestureBegin(); |
| 2113 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); | 2113 host_impl_->PinchGestureUpdate(2.f, gfx::Point(0, 0)); |
| 2114 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); | 2114 host_impl_->PinchGestureUpdate(1.f, gfx::Point(0, 0)); |
| 2115 | 2115 |
| 2116 // Needed so layer transform includes page scale. | 2116 // Needed so layer transform includes page scale. |
| 2117 DrawFrame(); | 2117 DrawFrame(); |
| (...skipping 8067 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10185 ->OuterViewportScrollLayer() | 10185 ->OuterViewportScrollLayer() |
| 10186 ->children()[0] | 10186 ->children()[0] |
| 10187 .get(); | 10187 .get(); |
| 10188 // The scroll done on the active tree is undone on the pending tree. | 10188 // The scroll done on the active tree is undone on the pending tree. |
| 10189 gfx::Transform translate; | 10189 gfx::Transform translate; |
| 10190 translate.Translate(0, accumulated_scroll); | 10190 translate.Translate(0, accumulated_scroll); |
| 10191 content_layer->SetTransform(translate); | 10191 content_layer->SetTransform(translate); |
| 10192 | 10192 |
| 10193 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); | 10193 LayerTreeImpl* pending_tree = host_impl_->pending_tree(); |
| 10194 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); | 10194 pending_tree->PushPageScaleFromMainThread(1.f, 1.f, 1.f); |
| 10195 LayerImpl* last_scrolled_layer = pending_tree->LayerById( | |
| 10196 host_impl_->active_tree()->LastScrolledLayerId()); | |
| 10197 gfx::ScrollOffset pending_base = | |
| 10198 last_scrolled_layer->synced_scroll_offset()->PendingBase(); | |
| 10195 pending_tree->property_trees()->needs_rebuild = true; | 10199 pending_tree->property_trees()->needs_rebuild = true; |
| 10196 pending_tree->BuildPropertyTreesForTesting(); | 10200 pending_tree->BuildPropertyTreesForTesting(); |
| 10201 last_scrolled_layer->synced_scroll_offset()->PushFromMainThread( | |
| 10202 pending_base); | |
|
ajuma
2016/03/03 18:05:06
The way this logic worked before relied on the pen
sunxd
2016/03/03 18:50:13
I think we don't need to. ScrollTree only clear it
| |
| 10203 | |
| 10197 pending_tree->set_needs_update_draw_properties(); | 10204 pending_tree->set_needs_update_draw_properties(); |
| 10198 pending_tree->UpdateDrawProperties(false); | 10205 pending_tree->UpdateDrawProperties(false); |
| 10199 LayerImpl* last_scrolled_layer = pending_tree->LayerById( | |
| 10200 host_impl_->active_tree()->LastScrolledLayerId()); | |
| 10201 float jitter = | 10206 float jitter = |
| 10202 LayerTreeHostCommon::CalculateFrameJitter(last_scrolled_layer); | 10207 LayerTreeHostCommon::CalculateFrameJitter(last_scrolled_layer); |
| 10203 // There should not be any jitter measured till we hit the fixed point hits | 10208 // There should not be any jitter measured till we hit the fixed point hits |
| 10204 // threshold. | 10209 // threshold. |
| 10205 float expected_jitter = | 10210 float expected_jitter = |
| 10206 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; | 10211 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; |
| 10207 EXPECT_EQ(jitter, expected_jitter); | 10212 EXPECT_EQ(jitter, expected_jitter); |
| 10208 } | 10213 } |
| 10209 } | 10214 } |
| 10210 | 10215 |
| 10211 } // namespace | 10216 } // namespace |
| 10212 } // namespace cc | 10217 } // namespace cc |
| OLD | NEW |