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

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: Add/update unit tests. 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 2229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2255 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); 2257 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl);
2256 should_bubble_scrolls_ = (type != NonBubblingGesture); 2258 should_bubble_scrolls_ = (type != NonBubblingGesture);
2257 wheel_scrolling_ = (type == Wheel); 2259 wheel_scrolling_ = (type == Wheel);
2258 client_->RenewTreePriority(); 2260 client_->RenewTreePriority();
2259 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); 2261 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false);
2260 return ScrollStarted; 2262 return ScrollStarted;
2261 } 2263 }
2262 return ScrollIgnored; 2264 return ScrollIgnored;
2263 } 2265 }
2264 2266
2267 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated(
2268 const gfx::Point& viewport_point,
2269 const gfx::Vector2dF& scroll_delta) {
2270 if (CurrentlyScrollingLayer()) {
2271 // TODO(skobes): Update the target of the existing animation.
2272 return ScrollIgnored;
2273 }
2274 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, Wheel);
2275 if (scroll_status == ScrollStarted) {
2276 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl;
2277 layer_impl = layer_impl->parent()) {
2278 if (!layer_impl->scrollable())
2279 continue;
2280
2281 gfx::Vector2dF current_offset = layer_impl->TotalScrollOffset();
2282 gfx::Vector2dF target_offset = current_offset + scroll_delta;
2283 target_offset.SetToMax(gfx::Vector2dF());
2284 target_offset.SetToMin(layer_impl->MaxScrollOffset());
2285 gfx::Vector2dF actual_delta = target_offset - current_offset;
2286
2287 const float kEpsilon = 0.1f;
2288 bool can_layer_scroll = (std::abs(actual_delta.x()) > kEpsilon ||
2289 std::abs(actual_delta.y()) > kEpsilon);
2290
2291 if (!can_layer_scroll)
2292 continue;
2293
2294 active_tree_->SetCurrentlyScrollingLayer(layer_impl);
2295
2296 scoped_ptr<ScrollOffsetAnimationCurve> curve =
2297 ScrollOffsetAnimationCurve::Create(target_offset,
2298 EaseInOutTimingFunction::Create());
2299 curve->SetInitialValue(current_offset);
2300
2301 scoped_ptr<Animation> animation =
2302 Animation::Create(curve->Clone().Pass(),
2303 AnimationIdProvider::NextAnimationId(),
2304 AnimationIdProvider::NextGroupId(),
2305 Animation::ScrollOffset);
2306 animation->set_is_impl_only(true);
2307
2308 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass());
2309
2310 SetNeedsAnimate();
2311 return ScrollStarted;
2312 }
2313 }
2314 ScrollEnd();
2315 return scroll_status;
2316 }
2317
2265 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta( 2318 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta(
2266 LayerImpl* layer_impl, 2319 LayerImpl* layer_impl,
2267 float scale_from_viewport_to_screen_space, 2320 float scale_from_viewport_to_screen_space,
2268 const gfx::PointF& viewport_point, 2321 const gfx::PointF& viewport_point,
2269 const gfx::Vector2dF& viewport_delta) { 2322 const gfx::Vector2dF& viewport_delta) {
2270 // Layers with non-invertible screen space transforms should not have passed 2323 // Layers with non-invertible screen space transforms should not have passed
2271 // the scroll hit test in the first place. 2324 // the scroll hit test in the first place.
2272 DCHECK(layer_impl->screen_space_transform().IsInvertible()); 2325 DCHECK(layer_impl->screen_space_transform().IsInvertible());
2273 gfx::Transform inverse_screen_space_transform( 2326 gfx::Transform inverse_screen_space_transform(
2274 gfx::Transform::kSkipInitialization); 2327 gfx::Transform::kSkipInitialization);
(...skipping 871 matching lines...) Expand 10 before | Expand all | Expand 10 after
3146 } 3199 }
3147 3200
3148 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { 3201 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
3149 std::vector<PictureLayerImpl*>::iterator it = 3202 std::vector<PictureLayerImpl*>::iterator it =
3150 std::find(picture_layers_.begin(), picture_layers_.end(), layer); 3203 std::find(picture_layers_.begin(), picture_layers_.end(), layer);
3151 DCHECK(it != picture_layers_.end()); 3204 DCHECK(it != picture_layers_.end());
3152 picture_layers_.erase(it); 3205 picture_layers_.erase(it);
3153 } 3206 }
3154 3207
3155 } // namespace cc 3208 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698