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 "base/trace_event/trace_event_argument.h" | 16 #include "base/trace_event/trace_event_argument.h" |
17 #include "cc/animation/animation_id_provider.h" | 17 #include "cc/animation/animation_id_provider.h" |
18 #include "cc/animation/scroll_offset_animation_curve.h" | 18 #include "cc/animation/scroll_offset_animation_curve.h" |
19 #include "cc/animation/scrollbar_animation_controller.h" | 19 #include "cc/animation/scrollbar_animation_controller.h" |
20 #include "cc/animation/timing_function.h" | 20 #include "cc/animation/timing_function.h" |
21 #include "cc/base/latency_info_swap_promise_monitor.h" | |
22 #include "cc/base/math_util.h" | 21 #include "cc/base/math_util.h" |
23 #include "cc/base/util.h" | 22 #include "cc/base/util.h" |
24 #include "cc/debug/benchmark_instrumentation.h" | 23 #include "cc/debug/benchmark_instrumentation.h" |
25 #include "cc/debug/debug_rect_history.h" | 24 #include "cc/debug/debug_rect_history.h" |
26 #include "cc/debug/devtools_instrumentation.h" | 25 #include "cc/debug/devtools_instrumentation.h" |
27 #include "cc/debug/frame_rate_counter.h" | 26 #include "cc/debug/frame_rate_counter.h" |
28 #include "cc/debug/paint_time_counter.h" | 27 #include "cc/debug/paint_time_counter.h" |
29 #include "cc/debug/rendering_stats_instrumentation.h" | 28 #include "cc/debug/rendering_stats_instrumentation.h" |
30 #include "cc/debug/traced_value.h" | 29 #include "cc/debug/traced_value.h" |
31 #include "cc/input/page_scale_animation.h" | 30 #include "cc/input/page_scale_animation.h" |
(...skipping 26 matching lines...) Expand all Loading... |
58 #include "cc/resources/prioritized_resource_manager.h" | 57 #include "cc/resources/prioritized_resource_manager.h" |
59 #include "cc/resources/raster_tile_priority_queue.h" | 58 #include "cc/resources/raster_tile_priority_queue.h" |
60 #include "cc/resources/resource_pool.h" | 59 #include "cc/resources/resource_pool.h" |
61 #include "cc/resources/software_rasterizer.h" | 60 #include "cc/resources/software_rasterizer.h" |
62 #include "cc/resources/texture_mailbox_deleter.h" | 61 #include "cc/resources/texture_mailbox_deleter.h" |
63 #include "cc/resources/tile_task_worker_pool.h" | 62 #include "cc/resources/tile_task_worker_pool.h" |
64 #include "cc/resources/ui_resource_bitmap.h" | 63 #include "cc/resources/ui_resource_bitmap.h" |
65 #include "cc/resources/zero_copy_tile_task_worker_pool.h" | 64 #include "cc/resources/zero_copy_tile_task_worker_pool.h" |
66 #include "cc/scheduler/delay_based_time_source.h" | 65 #include "cc/scheduler/delay_based_time_source.h" |
67 #include "cc/trees/damage_tracker.h" | 66 #include "cc/trees/damage_tracker.h" |
| 67 #include "cc/trees/latency_info_swap_promise_monitor.h" |
68 #include "cc/trees/layer_tree_host.h" | 68 #include "cc/trees/layer_tree_host.h" |
69 #include "cc/trees/layer_tree_host_common.h" | 69 #include "cc/trees/layer_tree_host_common.h" |
70 #include "cc/trees/layer_tree_impl.h" | 70 #include "cc/trees/layer_tree_impl.h" |
71 #include "cc/trees/single_thread_proxy.h" | 71 #include "cc/trees/single_thread_proxy.h" |
72 #include "cc/trees/tree_synchronizer.h" | 72 #include "cc/trees/tree_synchronizer.h" |
| 73 #include "gpu/GLES2/gl2extchromium.h" |
73 #include "gpu/command_buffer/client/gles2_interface.h" | 74 #include "gpu/command_buffer/client/gles2_interface.h" |
74 #include "gpu/GLES2/gl2extchromium.h" | |
75 #include "ui/gfx/frame_time.h" | 75 #include "ui/gfx/frame_time.h" |
76 #include "ui/gfx/geometry/rect_conversions.h" | 76 #include "ui/gfx/geometry/rect_conversions.h" |
| 77 #include "ui/gfx/geometry/scroll_offset.h" |
77 #include "ui/gfx/geometry/size_conversions.h" | 78 #include "ui/gfx/geometry/size_conversions.h" |
78 #include "ui/gfx/geometry/vector2d_conversions.h" | 79 #include "ui/gfx/geometry/vector2d_conversions.h" |
79 | 80 |
80 namespace cc { | 81 namespace cc { |
81 namespace { | 82 namespace { |
82 | 83 |
83 // Small helper class that saves the current viewport location as the user sees | 84 // Small helper class that saves the current viewport location as the user sees |
84 // it and resets to the same location. | 85 // it and resets to the same location. |
85 class ViewportAnchor { | 86 class ViewportAnchor { |
86 public: | 87 public: |
(...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2428 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); | 2429 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); |
2429 return SCROLL_STARTED; | 2430 return SCROLL_STARTED; |
2430 } | 2431 } |
2431 return SCROLL_IGNORED; | 2432 return SCROLL_IGNORED; |
2432 } | 2433 } |
2433 | 2434 |
2434 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( | 2435 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( |
2435 const gfx::Point& viewport_point, | 2436 const gfx::Point& viewport_point, |
2436 const gfx::Vector2dF& scroll_delta) { | 2437 const gfx::Vector2dF& scroll_delta) { |
2437 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { | 2438 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { |
2438 Animation* animation = | 2439 return ScrollAnimationUpdateTarget(layer_impl, scroll_delta) |
2439 layer_impl->layer_animation_controller()->GetAnimation( | 2440 ? SCROLL_STARTED |
2440 Animation::SCROLL_OFFSET); | 2441 : SCROLL_IGNORED; |
2441 if (!animation) | |
2442 return SCROLL_IGNORED; | |
2443 | |
2444 ScrollOffsetAnimationCurve* curve = | |
2445 animation->curve()->ToScrollOffsetAnimationCurve(); | |
2446 | |
2447 gfx::ScrollOffset new_target = | |
2448 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); | |
2449 new_target.SetToMax(gfx::ScrollOffset()); | |
2450 new_target.SetToMin(layer_impl->MaxScrollOffset()); | |
2451 | |
2452 curve->UpdateTarget( | |
2453 animation->TrimTimeToCurrentIteration( | |
2454 CurrentBeginFrameArgs().frame_time).InSecondsF(), | |
2455 new_target); | |
2456 | |
2457 return SCROLL_STARTED; | |
2458 } | 2442 } |
2459 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling | 2443 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling |
2460 // behavior as ScrollBy to determine which layer to animate, but we do not | 2444 // behavior as ScrollBy to determine which layer to animate, but we do not |
2461 // do the Android-specific things in ScrollBy like showing top controls. | 2445 // do the Android-specific things in ScrollBy like showing top controls. |
2462 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, WHEEL); | 2446 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, WHEEL); |
2463 if (scroll_status == SCROLL_STARTED) { | 2447 if (scroll_status == SCROLL_STARTED) { |
2464 gfx::Vector2dF pending_delta = scroll_delta; | 2448 gfx::Vector2dF pending_delta = scroll_delta; |
2465 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2449 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
2466 layer_impl = layer_impl->parent()) { | 2450 layer_impl = layer_impl->parent()) { |
2467 if (!layer_impl->scrollable()) | 2451 if (!layer_impl->scrollable()) |
(...skipping 11 matching lines...) Expand all Loading... |
2479 std::abs(actual_delta.y()) > kEpsilon); | 2463 std::abs(actual_delta.y()) > kEpsilon); |
2480 | 2464 |
2481 if (!can_layer_scroll) { | 2465 if (!can_layer_scroll) { |
2482 layer_impl->ScrollBy(actual_delta); | 2466 layer_impl->ScrollBy(actual_delta); |
2483 pending_delta -= actual_delta; | 2467 pending_delta -= actual_delta; |
2484 continue; | 2468 continue; |
2485 } | 2469 } |
2486 | 2470 |
2487 active_tree_->SetCurrentlyScrollingLayer(layer_impl); | 2471 active_tree_->SetCurrentlyScrollingLayer(layer_impl); |
2488 | 2472 |
2489 scoped_ptr<ScrollOffsetAnimationCurve> curve = | 2473 ScrollAnimationCreate(layer_impl, target_offset, current_offset); |
2490 ScrollOffsetAnimationCurve::Create(target_offset, | |
2491 EaseInOutTimingFunction::Create()); | |
2492 curve->SetInitialValue(current_offset); | |
2493 | |
2494 scoped_ptr<Animation> animation = Animation::Create( | |
2495 curve.Pass(), AnimationIdProvider::NextAnimationId(), | |
2496 AnimationIdProvider::NextGroupId(), Animation::SCROLL_OFFSET); | |
2497 animation->set_is_impl_only(true); | |
2498 | |
2499 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass()); | |
2500 | 2474 |
2501 SetNeedsAnimate(); | 2475 SetNeedsAnimate(); |
2502 return SCROLL_STARTED; | 2476 return SCROLL_STARTED; |
2503 } | 2477 } |
2504 } | 2478 } |
2505 ScrollEnd(); | 2479 ScrollEnd(); |
2506 return scroll_status; | 2480 return scroll_status; |
2507 } | 2481 } |
2508 | 2482 |
2509 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta( | 2483 gfx::Vector2dF LayerTreeHostImpl::ScrollLayerWithViewportSpaceDelta( |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3452 for (; it != swap_promise_monitor_.end(); it++) | 3426 for (; it != swap_promise_monitor_.end(); it++) |
3453 (*it)->OnSetNeedsRedrawOnImpl(); | 3427 (*it)->OnSetNeedsRedrawOnImpl(); |
3454 } | 3428 } |
3455 | 3429 |
3456 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() { | 3430 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() { |
3457 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3431 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
3458 for (; it != swap_promise_monitor_.end(); it++) | 3432 for (; it != swap_promise_monitor_.end(); it++) |
3459 (*it)->OnForwardScrollUpdateToMainThreadOnImpl(); | 3433 (*it)->OnForwardScrollUpdateToMainThreadOnImpl(); |
3460 } | 3434 } |
3461 | 3435 |
| 3436 void LayerTreeHostImpl::ScrollAnimationCreate( |
| 3437 LayerImpl* layer_impl, |
| 3438 const gfx::ScrollOffset& target_offset, |
| 3439 const gfx::ScrollOffset& current_offset) { |
| 3440 scoped_ptr<ScrollOffsetAnimationCurve> curve = |
| 3441 ScrollOffsetAnimationCurve::Create(target_offset, |
| 3442 EaseInOutTimingFunction::Create()); |
| 3443 curve->SetInitialValue(current_offset); |
| 3444 |
| 3445 scoped_ptr<Animation> animation = Animation::Create( |
| 3446 curve.Pass(), AnimationIdProvider::NextAnimationId(), |
| 3447 AnimationIdProvider::NextGroupId(), Animation::SCROLL_OFFSET); |
| 3448 animation->set_is_impl_only(true); |
| 3449 |
| 3450 layer_impl->layer_animation_controller()->AddAnimation(animation.Pass()); |
| 3451 } |
| 3452 |
| 3453 bool LayerTreeHostImpl::ScrollAnimationUpdateTarget( |
| 3454 LayerImpl* layer_impl, |
| 3455 const gfx::Vector2dF& scroll_delta) { |
| 3456 Animation* animation = |
| 3457 layer_impl->layer_animation_controller() |
| 3458 ? layer_impl->layer_animation_controller()->GetAnimation( |
| 3459 Animation::SCROLL_OFFSET) |
| 3460 : nullptr; |
| 3461 if (!animation) |
| 3462 return false; |
| 3463 |
| 3464 ScrollOffsetAnimationCurve* curve = |
| 3465 animation->curve()->ToScrollOffsetAnimationCurve(); |
| 3466 |
| 3467 gfx::ScrollOffset new_target = |
| 3468 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); |
| 3469 new_target.SetToMax(gfx::ScrollOffset()); |
| 3470 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
| 3471 |
| 3472 curve->UpdateTarget( |
| 3473 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) |
| 3474 .InSecondsF(), |
| 3475 new_target); |
| 3476 |
| 3477 return true; |
| 3478 } |
3462 } // namespace cc | 3479 } // namespace cc |
OLD | NEW |