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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); | 161 new DebugScopedSetImplThread(layer_tree_host_impl_->proxy())); |
162 } | 162 } |
163 | 163 |
164 // TODO(enne): This should probably happen post-animate. | 164 // TODO(enne): This should probably happen post-animate. |
165 if (layer_tree_host_impl_->pending_tree()) { | 165 if (layer_tree_host_impl_->pending_tree()) { |
166 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); | 166 layer_tree_host_impl_->pending_tree()->UpdateDrawProperties(); |
167 layer_tree_host_impl_->ManageTiles(); | 167 layer_tree_host_impl_->ManageTiles(); |
168 } | 168 } |
169 | 169 |
170 layer_tree_host_impl_->Animate( | 170 layer_tree_host_impl_->Animate( |
171 layer_tree_host_impl_->CurrentFrameTimeTicks(), | 171 layer_tree_host_impl_->CurrentFrameTimeTicks()); |
172 layer_tree_host_impl_->CurrentFrameTime()); | |
173 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); | 172 layer_tree_host_impl_->UpdateBackgroundAnimateTicking(true); |
174 bool start_ready_animations = true; | 173 bool start_ready_animations = true; |
175 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); | 174 layer_tree_host_impl_->UpdateAnimationState(start_ready_animations); |
176 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); | 175 layer_tree_host_impl_->ResetCurrentFrameTimeForNextFrame(); |
177 } | 176 } |
178 | 177 |
179 void SetActive(bool active) { | 178 void SetActive(bool active) { |
180 if (active != time_source_->Active()) | 179 if (active != time_source_->Active()) |
181 time_source_->SetActive(active); | 180 time_source_->SetActive(active); |
182 } | 181 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 } | 389 } |
391 if (EvictedUIResourcesExist()) { | 390 if (EvictedUIResourcesExist()) { |
392 TRACE_EVENT_INSTANT0( | 391 TRACE_EVENT_INSTANT0( |
393 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", | 392 "cc", "LayerTreeHostImpl::CanDraw UI resources evicted not recreated", |
394 TRACE_EVENT_SCOPE_THREAD); | 393 TRACE_EVENT_SCOPE_THREAD); |
395 return false; | 394 return false; |
396 } | 395 } |
397 return true; | 396 return true; |
398 } | 397 } |
399 | 398 |
400 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time, | 399 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { |
401 base::Time wall_clock_time) { | |
402 if (input_handler_client_) | 400 if (input_handler_client_) |
403 input_handler_client_->Animate(monotonic_time); | 401 input_handler_client_->Animate(monotonic_time); |
404 AnimatePageScale(monotonic_time); | 402 AnimatePageScale(monotonic_time); |
405 AnimateLayers(monotonic_time, wall_clock_time); | 403 AnimateLayers(monotonic_time); |
406 AnimateScrollbars(monotonic_time); | 404 AnimateScrollbars(monotonic_time); |
407 AnimateTopControls(monotonic_time); | 405 AnimateTopControls(monotonic_time); |
408 } | 406 } |
409 | 407 |
410 void LayerTreeHostImpl::ManageTiles() { | 408 void LayerTreeHostImpl::ManageTiles() { |
411 if (!tile_manager_) | 409 if (!tile_manager_) |
412 return; | 410 return; |
413 if (!tile_priorities_dirty_) | 411 if (!tile_priorities_dirty_) |
414 return; | 412 return; |
415 | 413 |
(...skipping 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2639 LayerImpl* scroll_layer = OuterViewportScrollLayer() | 2637 LayerImpl* scroll_layer = OuterViewportScrollLayer() |
2640 ? OuterViewportScrollLayer() | 2638 ? OuterViewportScrollLayer() |
2641 : InnerViewportScrollLayer(); | 2639 : InnerViewportScrollLayer(); |
2642 | 2640 |
2643 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); | 2641 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); |
2644 | 2642 |
2645 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) | 2643 if (!unused_delta.IsZero() && (scroll_layer == OuterViewportScrollLayer())) |
2646 InnerViewportScrollLayer()->ScrollBy(unused_delta); | 2644 InnerViewportScrollLayer()->ScrollBy(unused_delta); |
2647 } | 2645 } |
2648 | 2646 |
2649 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks time) { | 2647 void LayerTreeHostImpl::AnimatePageScale(base::TimeTicks monotonic_time) { |
2650 if (!page_scale_animation_) | 2648 if (!page_scale_animation_) |
2651 return; | 2649 return; |
2652 | 2650 |
2653 double monotonic_time = (time - base::TimeTicks()).InSecondsF(); | 2651 // TODO(ajuma): http://crbug.com/178171 - Animations use double for monotonic |
| 2652 // time. |
| 2653 double monotonic_time_for_cc_animations = |
| 2654 (monotonic_time - base::TimeTicks()).InSecondsF(); |
2654 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); | 2655 gfx::Vector2dF scroll_total = active_tree_->TotalScrollOffset(); |
2655 | 2656 |
2656 if (!page_scale_animation_->IsAnimationStarted()) | 2657 if (!page_scale_animation_->IsAnimationStarted()) |
2657 page_scale_animation_->StartAnimation(monotonic_time); | 2658 page_scale_animation_->StartAnimation(monotonic_time_for_cc_animations); |
2658 | 2659 |
2659 active_tree_->SetPageScaleDelta( | 2660 active_tree_->SetPageScaleDelta(page_scale_animation_->PageScaleFactorAtTime( |
2660 page_scale_animation_->PageScaleFactorAtTime(monotonic_time) / | 2661 monotonic_time_for_cc_animations) / |
2661 active_tree_->page_scale_factor()); | 2662 active_tree_->page_scale_factor()); |
2662 gfx::Vector2dF next_scroll = | 2663 gfx::Vector2dF next_scroll = page_scale_animation_->ScrollOffsetAtTime( |
2663 page_scale_animation_->ScrollOffsetAtTime(monotonic_time); | 2664 monotonic_time_for_cc_animations); |
2664 | 2665 |
2665 ScrollViewportBy(next_scroll - scroll_total); | 2666 ScrollViewportBy(next_scroll - scroll_total); |
2666 SetNeedsRedraw(); | 2667 SetNeedsRedraw(); |
2667 | 2668 |
2668 if (page_scale_animation_->IsAnimationCompleteAtTime(monotonic_time)) { | 2669 if (page_scale_animation_->IsAnimationCompleteAtTime( |
| 2670 monotonic_time_for_cc_animations)) { |
2669 page_scale_animation_.reset(); | 2671 page_scale_animation_.reset(); |
2670 client_->SetNeedsCommitOnImplThread(); | 2672 client_->SetNeedsCommitOnImplThread(); |
2671 client_->RenewTreePriority(); | 2673 client_->RenewTreePriority(); |
2672 } | 2674 } |
2673 } | 2675 } |
2674 | 2676 |
2675 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { | 2677 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { |
2676 if (!top_controls_manager_ || !top_controls_manager_->animation()) | 2678 if (!top_controls_manager_ || !top_controls_manager_->animation()) |
2677 return; | 2679 return; |
2678 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); | 2680 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); |
2679 if (active_tree_->TotalScrollOffset().y() == 0.f) | 2681 if (active_tree_->TotalScrollOffset().y() == 0.f) |
2680 return; | 2682 return; |
2681 if (scroll.IsZero()) { | 2683 if (scroll.IsZero()) { |
2682 // This may happen on the first animation step. Force redraw otherwise | 2684 // This may happen on the first animation step. Force redraw otherwise |
2683 // the animation would stop because of no new frames. | 2685 // the animation would stop because of no new frames. |
2684 SetNeedsRedraw(); | 2686 SetNeedsRedraw(); |
2685 } else { | 2687 } else { |
2686 ScrollViewportBy(gfx::ScaleVector2d( | 2688 ScrollViewportBy(gfx::ScaleVector2d( |
2687 scroll, 1.f / active_tree_->total_page_scale_factor())); | 2689 scroll, 1.f / active_tree_->total_page_scale_factor())); |
2688 } | 2690 } |
2689 } | 2691 } |
2690 | 2692 |
2691 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time, | 2693 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { |
2692 base::Time wall_clock_time) { | |
2693 if (!settings_.accelerated_animation_enabled || | 2694 if (!settings_.accelerated_animation_enabled || |
2694 animation_registrar_->active_animation_controllers().empty() || | 2695 animation_registrar_->active_animation_controllers().empty() || |
2695 !active_tree_->root_layer()) | 2696 !active_tree_->root_layer()) |
2696 return; | 2697 return; |
2697 | 2698 |
2698 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); | 2699 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); |
2699 | 2700 |
2700 double monotonic_seconds = (monotonic_time - base::TimeTicks()).InSecondsF(); | 2701 // TODO(ajuma): http://crbug.com/178171 - Animations use double for monotonic |
2701 | 2702 // time. |
| 2703 double monotonic_time_for_cc_animations = |
| 2704 (monotonic_time - base::TimeTicks()).InSecondsF(); |
2702 AnimationRegistrar::AnimationControllerMap copy = | 2705 AnimationRegistrar::AnimationControllerMap copy = |
2703 animation_registrar_->active_animation_controllers(); | 2706 animation_registrar_->active_animation_controllers(); |
2704 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 2707 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
2705 iter != copy.end(); | 2708 iter != copy.end(); |
2706 ++iter) | 2709 ++iter) |
2707 (*iter).second->Animate(monotonic_seconds); | 2710 (*iter).second->Animate(monotonic_time_for_cc_animations); |
2708 | 2711 |
2709 SetNeedsRedraw(); | 2712 SetNeedsRedraw(); |
2710 } | 2713 } |
2711 | 2714 |
2712 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { | 2715 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { |
2713 if (!settings_.accelerated_animation_enabled || | 2716 if (!settings_.accelerated_animation_enabled || |
2714 animation_registrar_->active_animation_controllers().empty() || | 2717 animation_registrar_->active_animation_controllers().empty() || |
2715 !active_tree_->root_layer()) | 2718 !active_tree_->root_layer()) |
2716 return; | 2719 return; |
2717 | 2720 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2854 return; | 2857 return; |
2855 | 2858 |
2856 if (global_tile_state_.tree_priority == priority) | 2859 if (global_tile_state_.tree_priority == priority) |
2857 return; | 2860 return; |
2858 global_tile_state_.tree_priority = priority; | 2861 global_tile_state_.tree_priority = priority; |
2859 DidModifyTilePriorities(); | 2862 DidModifyTilePriorities(); |
2860 } | 2863 } |
2861 | 2864 |
2862 void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() { | 2865 void LayerTreeHostImpl::ResetCurrentFrameTimeForNextFrame() { |
2863 current_frame_timeticks_ = base::TimeTicks(); | 2866 current_frame_timeticks_ = base::TimeTicks(); |
2864 current_frame_time_ = base::Time(); | |
2865 } | 2867 } |
2866 | 2868 |
2867 void LayerTreeHostImpl::UpdateCurrentFrameTime(base::TimeTicks* ticks, | 2869 void LayerTreeHostImpl::UpdateCurrentFrameTime(base::TimeTicks* ticks) const { |
2868 base::Time* now) const { | |
2869 if (ticks->is_null()) { | 2870 if (ticks->is_null()) { |
2870 DCHECK(now->is_null()); | |
2871 *ticks = CurrentPhysicalTimeTicks(); | 2871 *ticks = CurrentPhysicalTimeTicks(); |
2872 *now = base::Time::Now(); | |
2873 } | 2872 } |
2874 } | 2873 } |
2875 | 2874 |
2876 base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() { | 2875 base::TimeTicks LayerTreeHostImpl::CurrentFrameTimeTicks() { |
2877 UpdateCurrentFrameTime(¤t_frame_timeticks_, ¤t_frame_time_); | 2876 UpdateCurrentFrameTime(¤t_frame_timeticks_); |
2878 return current_frame_timeticks_; | 2877 return current_frame_timeticks_; |
2879 } | 2878 } |
2880 | 2879 |
2881 base::Time LayerTreeHostImpl::CurrentFrameTime() { | |
2882 UpdateCurrentFrameTime(¤t_frame_timeticks_, ¤t_frame_time_); | |
2883 return current_frame_time_; | |
2884 } | |
2885 | |
2886 base::TimeTicks LayerTreeHostImpl::CurrentPhysicalTimeTicks() const { | 2880 base::TimeTicks LayerTreeHostImpl::CurrentPhysicalTimeTicks() const { |
2887 return gfx::FrameTime::Now(); | 2881 return gfx::FrameTime::Now(); |
2888 } | 2882 } |
2889 | 2883 |
2890 scoped_ptr<base::Value> LayerTreeHostImpl::AsValueWithFrame( | 2884 scoped_ptr<base::Value> LayerTreeHostImpl::AsValueWithFrame( |
2891 FrameData* frame) const { | 2885 FrameData* frame) const { |
2892 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | 2886 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
2893 if (this->pending_tree_) | 2887 if (this->pending_tree_) |
2894 state->Set("activation_state", ActivationStateAsValue().release()); | 2888 state->Set("activation_state", ActivationStateAsValue().release()); |
2895 state->Set("device_viewport_size", | 2889 state->Set("device_viewport_size", |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3036 swap_promise_monitor_.erase(monitor); | 3030 swap_promise_monitor_.erase(monitor); |
3037 } | 3031 } |
3038 | 3032 |
3039 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3033 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
3040 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3034 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
3041 for (; it != swap_promise_monitor_.end(); it++) | 3035 for (; it != swap_promise_monitor_.end(); it++) |
3042 (*it)->OnSetNeedsRedrawOnImpl(); | 3036 (*it)->OnSetNeedsRedrawOnImpl(); |
3043 } | 3037 } |
3044 | 3038 |
3045 } // namespace cc | 3039 } // namespace cc |
OLD | NEW |