Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: cc/trees/layer_tree_host_impl_unittest.cc

Issue 1736073002: cc: Move SyncedScrollOffset to scroll tree (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and add comment Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
10198 // When building property trees from impl side, the builder uses the scroll
10199 // offset of layer_impl to initialize the scroll offset in scroll tree:
10200 // scroll_tree.synced_scroll_offset.PushFromMainThread(
10201 // layer->CurrentScrollOffset()).
10202 // However, layer_impl does not store scroll_offset, so it is using scroll
10203 // tree's scroll offset to initialize itself. Usually this approach works
10204 // because this is a simple assignment. However if scroll_offset's pending
10205 // delta is not zero, the delta would be counted twice.
10206 // This hacking here is to restore the damaged scroll offset.
10207 gfx::ScrollOffset pending_base =
10208 last_scrolled_layer->synced_scroll_offset()->PendingBase();
10195 pending_tree->property_trees()->needs_rebuild = true; 10209 pending_tree->property_trees()->needs_rebuild = true;
10196 pending_tree->BuildPropertyTreesForTesting(); 10210 pending_tree->BuildPropertyTreesForTesting();
10211 last_scrolled_layer->synced_scroll_offset()->PushFromMainThread(
10212 pending_base);
10213
10197 pending_tree->set_needs_update_draw_properties(); 10214 pending_tree->set_needs_update_draw_properties();
10198 pending_tree->UpdateDrawProperties(false); 10215 pending_tree->UpdateDrawProperties(false);
10199 LayerImpl* last_scrolled_layer = pending_tree->LayerById(
10200 host_impl_->active_tree()->LastScrolledLayerId());
10201 float jitter = 10216 float jitter =
10202 LayerTreeHostCommon::CalculateFrameJitter(last_scrolled_layer); 10217 LayerTreeHostCommon::CalculateFrameJitter(last_scrolled_layer);
10203 // There should not be any jitter measured till we hit the fixed point hits 10218 // There should not be any jitter measured till we hit the fixed point hits
10204 // threshold. 10219 // threshold.
10205 float expected_jitter = 10220 float expected_jitter =
10206 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0; 10221 (i == pending_tree->kFixedPointHitsThreshold) ? 500 : 0;
10207 EXPECT_EQ(jitter, expected_jitter); 10222 EXPECT_EQ(jitter, expected_jitter);
10208 } 10223 }
10209 } 10224 }
10210 10225
10211 } // namespace 10226 } // namespace
10212 } // namespace cc 10227 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.cc ('k') | cc/trees/layer_tree_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698