| 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" |
| (...skipping 2442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 LayerImpl* scroll_layer_impl = active_tree_->LayerById( | 2453 LayerImpl* scroll_layer_impl = active_tree_->LayerById( |
| 2454 scroll_layer_id_when_mouse_over_scrollbar_); | 2454 scroll_layer_id_when_mouse_over_scrollbar_); |
| 2455 | 2455 |
| 2456 // The check for a null scroll_layer_impl below was added to see if it will | 2456 // The check for a null scroll_layer_impl below was added to see if it will |
| 2457 // eliminate the crashes described in http://crbug.com/326635. | 2457 // eliminate the crashes described in http://crbug.com/326635. |
| 2458 // TODO(wjmaclean) Add a unit test if this fixes the crashes. | 2458 // TODO(wjmaclean) Add a unit test if this fixes the crashes. |
| 2459 ScrollbarAnimationController* animation_controller = | 2459 ScrollbarAnimationController* animation_controller = |
| 2460 scroll_layer_impl ? scroll_layer_impl->scrollbar_animation_controller() | 2460 scroll_layer_impl ? scroll_layer_impl->scrollbar_animation_controller() |
| 2461 : NULL; | 2461 : NULL; |
| 2462 if (animation_controller) { | 2462 if (animation_controller) { |
| 2463 animation_controller->DidMouseMoveOffScrollbar( | 2463 animation_controller->DidMouseMoveOffScrollbar(CurrentFrameTimeTicks()); |
| 2464 CurrentPhysicalTimeTicks()); | |
| 2465 StartScrollbarAnimation(); | 2464 StartScrollbarAnimation(); |
| 2466 } | 2465 } |
| 2467 scroll_layer_id_when_mouse_over_scrollbar_ = 0; | 2466 scroll_layer_id_when_mouse_over_scrollbar_ = 0; |
| 2468 } | 2467 } |
| 2469 | 2468 |
| 2470 bool scroll_on_main_thread = false; | 2469 bool scroll_on_main_thread = false; |
| 2471 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint( | 2470 LayerImpl* scroll_layer_impl = FindScrollLayerForDeviceViewportPoint( |
| 2472 device_viewport_point, InputHandler::Gesture, layer_impl, | 2471 device_viewport_point, InputHandler::Gesture, layer_impl, |
| 2473 &scroll_on_main_thread); | 2472 &scroll_on_main_thread); |
| 2474 if (scroll_on_main_thread || !scroll_layer_impl) | 2473 if (scroll_on_main_thread || !scroll_layer_impl) |
| 2475 return; | 2474 return; |
| 2476 | 2475 |
| 2477 ScrollbarAnimationController* animation_controller = | 2476 ScrollbarAnimationController* animation_controller = |
| 2478 scroll_layer_impl->scrollbar_animation_controller(); | 2477 scroll_layer_impl->scrollbar_animation_controller(); |
| 2479 if (!animation_controller) | 2478 if (!animation_controller) |
| 2480 return; | 2479 return; |
| 2481 | 2480 |
| 2482 // TODO(wjmaclean) Is it ok to choose distance from more than two scrollbars? | 2481 // TODO(wjmaclean) Is it ok to choose distance from more than two scrollbars? |
| 2483 float distance_to_scrollbar = std::numeric_limits<float>::max(); | 2482 float distance_to_scrollbar = std::numeric_limits<float>::max(); |
| 2484 for (LayerImpl::ScrollbarSet::iterator it = | 2483 for (LayerImpl::ScrollbarSet::iterator it = |
| 2485 scroll_layer_impl->scrollbars()->begin(); | 2484 scroll_layer_impl->scrollbars()->begin(); |
| 2486 it != scroll_layer_impl->scrollbars()->end(); | 2485 it != scroll_layer_impl->scrollbars()->end(); |
| 2487 ++it) | 2486 ++it) |
| 2488 distance_to_scrollbar = | 2487 distance_to_scrollbar = |
| 2489 std::min(distance_to_scrollbar, | 2488 std::min(distance_to_scrollbar, |
| 2490 DeviceSpaceDistanceToLayer(device_viewport_point, *it)); | 2489 DeviceSpaceDistanceToLayer(device_viewport_point, *it)); |
| 2491 | 2490 |
| 2492 bool should_animate = animation_controller->DidMouseMoveNear( | 2491 bool should_animate = animation_controller->DidMouseMoveNear( |
| 2493 CurrentPhysicalTimeTicks(), distance_to_scrollbar / device_scale_factor_); | 2492 CurrentFrameTimeTicks(), distance_to_scrollbar / device_scale_factor_); |
| 2494 if (should_animate) | 2493 if (should_animate) |
| 2495 StartScrollbarAnimation(); | 2494 StartScrollbarAnimation(); |
| 2496 } | 2495 } |
| 2497 | 2496 |
| 2498 bool LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl, | 2497 bool LayerTreeHostImpl::HandleMouseOverScrollbar(LayerImpl* layer_impl, |
| 2499 const gfx::PointF& device_viewport_point) { | 2498 const gfx::PointF& device_viewport_point) { |
| 2500 if (layer_impl && layer_impl->ToScrollbarLayer()) { | 2499 if (layer_impl && layer_impl->ToScrollbarLayer()) { |
| 2501 int scroll_layer_id = layer_impl->ToScrollbarLayer()->ScrollLayerId(); | 2500 int scroll_layer_id = layer_impl->ToScrollbarLayer()->ScrollLayerId(); |
| 2502 layer_impl = active_tree_->LayerById(scroll_layer_id); | 2501 layer_impl = active_tree_->LayerById(scroll_layer_id); |
| 2503 if (layer_impl && layer_impl->scrollbar_animation_controller()) { | 2502 if (layer_impl && layer_impl->scrollbar_animation_controller()) { |
| 2504 scroll_layer_id_when_mouse_over_scrollbar_ = scroll_layer_id; | 2503 scroll_layer_id_when_mouse_over_scrollbar_ = scroll_layer_id; |
| 2505 bool should_animate = | 2504 bool should_animate = |
| 2506 layer_impl->scrollbar_animation_controller()->DidMouseMoveNear( | 2505 layer_impl->scrollbar_animation_controller()->DidMouseMoveNear( |
| 2507 CurrentPhysicalTimeTicks(), 0); | 2506 CurrentFrameTimeTicks(), 0); |
| 2508 if (should_animate) | 2507 if (should_animate) |
| 2509 StartScrollbarAnimation(); | 2508 StartScrollbarAnimation(); |
| 2510 } else { | 2509 } else { |
| 2511 scroll_layer_id_when_mouse_over_scrollbar_ = 0; | 2510 scroll_layer_id_when_mouse_over_scrollbar_ = 0; |
| 2512 } | 2511 } |
| 2513 | 2512 |
| 2514 return true; | 2513 return true; |
| 2515 } | 2514 } |
| 2516 | 2515 |
| 2517 return false; | 2516 return false; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2813 TRACE_EVENT_SCOPE_THREAD); | 2812 TRACE_EVENT_SCOPE_THREAD); |
| 2814 SetNeedsRedraw(); | 2813 SetNeedsRedraw(); |
| 2815 } | 2814 } |
| 2816 | 2815 |
| 2817 for (size_t i = 0; i < layer->children().size(); ++i) | 2816 for (size_t i = 0; i < layer->children().size(); ++i) |
| 2818 AnimateScrollbarsRecursive(layer->children()[i], time); | 2817 AnimateScrollbarsRecursive(layer->children()[i], time); |
| 2819 } | 2818 } |
| 2820 | 2819 |
| 2821 void LayerTreeHostImpl::StartScrollbarAnimation() { | 2820 void LayerTreeHostImpl::StartScrollbarAnimation() { |
| 2822 TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation"); | 2821 TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation"); |
| 2823 StartScrollbarAnimationRecursive(RootLayer(), CurrentPhysicalTimeTicks()); | 2822 StartScrollbarAnimationRecursive(RootLayer(), CurrentFrameTimeTicks()); |
| 2824 } | 2823 } |
| 2825 | 2824 |
| 2826 void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer, | 2825 void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer, |
| 2827 base::TimeTicks time) { | 2826 base::TimeTicks time) { |
| 2828 if (!layer) | 2827 if (!layer) |
| 2829 return; | 2828 return; |
| 2830 | 2829 |
| 2831 ScrollbarAnimationController* scrollbar_controller = | 2830 ScrollbarAnimationController* scrollbar_controller = |
| 2832 layer->scrollbar_animation_controller(); | 2831 layer->scrollbar_animation_controller(); |
| 2833 if (scrollbar_controller && scrollbar_controller->IsAnimating()) { | 2832 if (scrollbar_controller && scrollbar_controller->IsAnimating()) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2845 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { | 2844 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { |
| 2846 if (!tile_manager_) | 2845 if (!tile_manager_) |
| 2847 return; | 2846 return; |
| 2848 | 2847 |
| 2849 if (global_tile_state_.tree_priority == priority) | 2848 if (global_tile_state_.tree_priority == priority) |
| 2850 return; | 2849 return; |
| 2851 global_tile_state_.tree_priority = priority; | 2850 global_tile_state_.tree_priority = priority; |
| 2852 DidModifyTilePriorities(); | 2851 DidModifyTilePriorities(); |
| 2853 } | 2852 } |
| 2854 | 2853 |
| 2854 void LayerTreeHostImpl::UpdateCurrentFrameTime() { |
| 2855 DCHECK(current_frame_timeticks_.is_null()); |
| 2856 current_frame_timeticks_ = gfx::FrameTime::Now(); |
| 2857 } |
| 2858 |
| 2855 void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() { | 2859 void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() { |
| 2856 current_frame_timeticks_ = base::TimeTicks(); | 2860 current_frame_timeticks_ = base::TimeTicks(); |
| 2857 } | 2861 } |
| 2858 | 2862 |
| 2859 void LayerTreeHostImpl::UpdateCurrentFrameTime(base::TimeTicks* ticks) const { | |
| 2860 if (ticks->is_null()) { | |
| 2861 *ticks = CurrentPhysicalTimeTicks(); | |
| 2862 } | |
| 2863 } | |
| 2864 | |
| 2865 base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() { | 2863 base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() { |
| 2866 UpdateCurrentFrameTime(¤t_frame_timeticks_); | 2864 // Try to use the current frame time to keep animations non-jittery. But if |
| 2867 return current_frame_timeticks_; | 2865 // we're not in a frame (because this is during an input event or a delayed |
| 2868 } | 2866 // task), fall back to physical time. This should still be monotonic. |
| 2869 | 2867 if (!current_frame_timeticks_.is_null()) |
| 2870 base::TimeTicks LayerTreeHostImpl::CurrentPhysicalTimeTicks() const { | 2868 return current_frame_timeticks_; |
| 2871 return gfx::FrameTime::Now(); | 2869 return gfx::FrameTime::Now(); |
| 2872 } | 2870 } |
| 2873 | 2871 |
| 2874 scoped_ptr<base::Value> LayerTreeHostImpl::AsValueWithFrame( | 2872 scoped_ptr<base::Value> LayerTreeHostImpl::AsValueWithFrame( |
| 2875 FrameData* frame) const { | 2873 FrameData* frame) const { |
| 2876 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 2874 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 2877 if (this->pending_tree_) | 2875 if (this->pending_tree_) |
| 2878 state->Set("activation_state", ActivationStateAsValue().release()); | 2876 state->Set("activation_state", ActivationStateAsValue().release()); |
| 2879 state->Set("device_viewport_size", | 2877 state->Set("device_viewport_size", |
| 2880 MathUtil::AsValue(device_viewport_size_).release()); | 2878 MathUtil::AsValue(device_viewport_size_).release()); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3020 swap_promise_monitor_.erase(monitor); | 3018 swap_promise_monitor_.erase(monitor); |
| 3021 } | 3019 } |
| 3022 | 3020 |
| 3023 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3021 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
| 3024 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3022 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
| 3025 for (; it != swap_promise_monitor_.end(); it++) | 3023 for (; it != swap_promise_monitor_.end(); it++) |
| 3026 (*it)->OnSetNeedsRedrawOnImpl(); | 3024 (*it)->OnSetNeedsRedrawOnImpl(); |
| 3027 } | 3025 } |
| 3028 | 3026 |
| 3029 } // namespace cc | 3027 } // namespace cc |
| OLD | NEW |