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 <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 Loading... | |
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); | |
ajuma
2014/07/08 14:44:49
If actual_delta is less than kEpsilon but non-zero
skobes
2014/07/08 17:49:12
I based this on the logic in ScrollBy, I think the
ajuma
2014/07/08 18:45:32
It looks like ScrollBy actually performs the scrol
skobes
2014/07/08 21:21:58
Fair point, done.
| |
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 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2879 scoped_ptr<AnimationEventsVector> events = | 2932 scoped_ptr<AnimationEventsVector> events = |
2880 make_scoped_ptr(new AnimationEventsVector); | 2933 make_scoped_ptr(new AnimationEventsVector); |
2881 AnimationRegistrar::AnimationControllerMap copy = | 2934 AnimationRegistrar::AnimationControllerMap copy = |
2882 animation_registrar_->active_animation_controllers(); | 2935 animation_registrar_->active_animation_controllers(); |
2883 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 2936 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
2884 iter != copy.end(); | 2937 iter != copy.end(); |
2885 ++iter) | 2938 ++iter) |
2886 (*iter).second->UpdateState(start_ready_animations, events.get()); | 2939 (*iter).second->UpdateState(start_ready_animations, events.get()); |
2887 | 2940 |
2888 if (!events->empty()) { | 2941 if (!events->empty()) { |
2942 if (std::find_if(events->begin(), | |
2943 events->end(), | |
2944 IsScrollOffsetAnimationFinished()) != events->end()) | |
2945 ScrollEnd(); | |
ajuma
2014/07/08 14:44:49
I think a better approach would be to modify Layer
skobes
2014/07/08 17:49:12
Done.
| |
2889 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); | 2946 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); |
2890 } | 2947 } |
2891 | 2948 |
2892 SetNeedsAnimate(); | 2949 SetNeedsAnimate(); |
2893 } | 2950 } |
2894 | 2951 |
2895 void LayerTreeHostImpl::ActivateAnimations() { | 2952 void LayerTreeHostImpl::ActivateAnimations() { |
2896 if (!settings_.accelerated_animation_enabled || !needs_animate_layers() || | 2953 if (!settings_.accelerated_animation_enabled || !needs_animate_layers() || |
2897 !active_tree_->root_layer()) | 2954 !active_tree_->root_layer()) |
2898 return; | 2955 return; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3146 } | 3203 } |
3147 | 3204 |
3148 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3205 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3149 std::vector<PictureLayerImpl*>::iterator it = | 3206 std::vector<PictureLayerImpl*>::iterator it = |
3150 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3207 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3151 DCHECK(it != picture_layers_.end()); | 3208 DCHECK(it != picture_layers_.end()); |
3152 picture_layers_.erase(it); | 3209 picture_layers_.erase(it); |
3153 } | 3210 } |
3154 | 3211 |
3155 } // namespace cc | 3212 } // namespace cc |
OLD | NEW |