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

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

Issue 361143002: Impl thread smooth scrolling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments. Created 6 years, 5 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 | Annotate | Revision Log
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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/containers/hash_tables.h" 11 #include "base/containers/hash_tables.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "cc/animation/animation_id_provider.h"
17 #include "cc/animation/scroll_offset_animation_curve.h"
16 #include "cc/animation/scrollbar_animation_controller.h" 18 #include "cc/animation/scrollbar_animation_controller.h"
17 #include "cc/animation/timing_function.h" 19 #include "cc/animation/timing_function.h"
18 #include "cc/base/latency_info_swap_promise_monitor.h" 20 #include "cc/base/latency_info_swap_promise_monitor.h"
19 #include "cc/base/math_util.h" 21 #include "cc/base/math_util.h"
20 #include "cc/base/util.h" 22 #include "cc/base/util.h"
21 #include "cc/debug/benchmark_instrumentation.h" 23 #include "cc/debug/benchmark_instrumentation.h"
22 #include "cc/debug/debug_rect_history.h" 24 #include "cc/debug/debug_rect_history.h"
23 #include "cc/debug/devtools_instrumentation.h" 25 #include "cc/debug/devtools_instrumentation.h"
24 #include "cc/debug/frame_rate_counter.h" 26 #include "cc/debug/frame_rate_counter.h"
25 #include "cc/debug/paint_time_counter.h" 27 #include "cc/debug/paint_time_counter.h"
(...skipping 2235 matching lines...) Expand 10 before | Expand all | Expand 10 after
2261 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); 2263 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl);
2262 should_bubble_scrolls_ = (type != NonBubblingGesture); 2264 should_bubble_scrolls_ = (type != NonBubblingGesture);
2263 wheel_scrolling_ = (type == Wheel); 2265 wheel_scrolling_ = (type == Wheel);
2264 client_->RenewTreePriority(); 2266 client_->RenewTreePriority();
2265 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); 2267 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false);
2266 return ScrollStarted; 2268 return ScrollStarted;
2267 } 2269 }
2268 return ScrollIgnored; 2270 return ScrollIgnored;
2269 } 2271 }
2270 2272
2273 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated(
2274 const gfx::Point& viewport_point,
jdduke (slow) 2014/07/08 22:12:35 Was there a particular reason for adding a new ani
skobes 2014/07/08 22:22:49 I wanted to reuse cc::ScrollOffsetAnimationCurve,
2275 const gfx::Vector2dF& scroll_delta) {
2276 if (CurrentlyScrollingLayer()) {
2277 // TODO(skobes): Update the target of the existing animation.
jdduke (slow) 2014/07/08 22:12:35 Do you have specific plans on how to achieve this?
skobes 2014/07/08 22:22:49 My plan was to grab the existing animation from th
2278 return ScrollIgnored;
2279 }
2280 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling
2281 // behavior as ScrollBy to determine which layer to animate, but we do not
2282 // do the Android-specific things in ScrollBy like showing top controls.
2283 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel);
2284 if (scroll_status == ScrollStarted) {
2285 gfx::Vector2dF pending_delta = scroll_delta;
2286 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl;
2287 layer_impl = layer_impl->parent()) {
2288 if (!layer_impl->scrollable())
2289 continue;
2290
2291 gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset();
2292 gfx::Vector2dF target_offset = current_offset + pending_delta;
2293 target_offset.SetToMax(gfx::Vector2dF());
2294 target_offset.SetToMin(layer_impl->MaxScrollOffset());
2295 gfx::Vector2dF actual_delta = target_offset - current_offset;
2296
jdduke (slow) 2014/07/08 22:12:35 Is it intentional that the (potential) excess delt
skobes 2014/07/08 22:22:49 Yes, this code does not attempt to support bubblin
2297 const float kEpsilon = 0.1f;
2298 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon ||
2299 std::abs(actual_delta.y()) > kEpsilon);
2300
2301 if (!can_layer_scroll) {
2302 layer_impl->ScrollBy(actual_delta);
2303 pending_delta -= actual_delta;
2304 continue;
2305 }
2306
2307 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
2308
2309 scoped_ptr<ScrollOffsetAnimationCurve> curve =
2310 ScrollOffsetAnimationCurve::Create(target_offset,
2311 EaseInOutTimingFunction::Create());
2312 curve->SetInitialValue(current_offset);
2313
2314 scoped_ptr<Animation> animation =
2315 Animation::Create(curve->Clone().Pass(),
2316 AnimationIdProvider::NextAnimationId(),
2317 AnimationIdProvider::NextGroupId(),
2318 Animation::ScrollOffset);
2319 animation->set_is_impl_only(true);
2320
2321 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass());
2322
2323 SetNeedsAnimate();
2324 return ScrollStarted;
2325 }
2326 }
2327 ScrollEnd();
2328 return scroll_status;
2329 }
2330
2271 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta( 2331 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta(
2272 LayerImpl* layer_impl, 2332 LayerImpl* layer_impl,
2273 float scale_from_viewport_to_screen_space, 2333 float scale_from_viewport_to_screen_space,
2274 const gfx::PointF& viewport_point, 2334 const gfx::PointF& viewport_point,
2275 const gfx::Vector2dF& viewport_delta) { 2335 const gfx::Vector2dF& viewport_delta) {
2276 // Layers with non-invertible screen space transforms should not have passed 2336 // Layers with non-invertible screen space transforms should not have passed
2277 // the scroll hit test in the first place. 2337 // the scroll hit test in the first place.
2278 DCHECK(layer_impl->screen_space_transform().IsInvertible()); 2338 DCHECK(layer_impl->screen_space_transform().IsInvertible());
2279 gfx::Transform inverse_screen_space_transform( 2339 gfx::Transform inverse_screen_space_transform(
2280 gfx::Transform::kSkipInitialization); 2340 gfx::Transform::kSkipInitialization);
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
3152 } 3212 }
3153 3213
3154 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { 3214 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
3155 std::vector<PictureLayerImpl*>::iterator it = 3215 std::vector<PictureLayerImpl*>::iterator it =
3156 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 3216 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
3157 DCHECK(it != picture_layers_.end()); 3217 DCHECK(it != picture_layers_.end());
3158 picture_layers_.erase(it); 3218 picture_layers_.erase(it);
3159 } 3219 }
3160 3220
3161 } // namespace cc 3221 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698