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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 page_scale_animation_->ZoomWithAnchor(anchor, | 463 page_scale_animation_->ZoomWithAnchor(anchor, |
464 page_scale, | 464 page_scale, |
465 duration.InSecondsF()); | 465 duration.InSecondsF()); |
466 } else { | 466 } else { |
467 gfx::Vector2dF scaled_target_offset = target_offset; | 467 gfx::Vector2dF scaled_target_offset = target_offset; |
468 page_scale_animation_->ZoomTo(scaled_target_offset, | 468 page_scale_animation_->ZoomTo(scaled_target_offset, |
469 page_scale, | 469 page_scale, |
470 duration.InSecondsF()); | 470 duration.InSecondsF()); |
471 } | 471 } |
472 | 472 |
473 SetNeedsRedraw(); | 473 SetNeedsAnimate(); |
474 client_->SetNeedsCommitOnImplThread(); | 474 client_->SetNeedsCommitOnImplThread(); |
475 client_->RenewTreePriority(); | 475 client_->RenewTreePriority(); |
476 } | 476 } |
477 | 477 |
478 void LayerTreeHostImpl::ScheduleAnimation() { | |
479 SetNeedsRedraw(); | |
480 } | |
481 | |
482 bool LayerTreeHostImpl::HaveTouchEventHandlersAt( | 478 bool LayerTreeHostImpl::HaveTouchEventHandlersAt( |
483 const gfx::Point& viewport_point) { | 479 const gfx::Point& viewport_point) { |
484 if (!settings_.touch_hit_testing) | 480 if (!settings_.touch_hit_testing) |
485 return true; | 481 return true; |
486 if (!EnsureRenderSurfaceLayerList()) | 482 if (!EnsureRenderSurfaceLayerList()) |
487 return false; | 483 return false; |
488 | 484 |
489 gfx::PointF device_viewport_point = | 485 gfx::PointF device_viewport_point = |
490 gfx::ScalePoint(viewport_point, device_scale_factor_); | 486 gfx::ScalePoint(viewport_point, device_scale_factor_); |
491 | 487 |
(...skipping 1243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1735 // draw or timer tick. | 1731 // draw or timer tick. |
1736 if (!visible_) | 1732 if (!visible_) |
1737 ManageTiles(); | 1733 ManageTiles(); |
1738 | 1734 |
1739 if (!renderer_) | 1735 if (!renderer_) |
1740 return; | 1736 return; |
1741 | 1737 |
1742 renderer_->SetVisible(visible); | 1738 renderer_->SetVisible(visible); |
1743 } | 1739 } |
1744 | 1740 |
| 1741 void LayerTreeHostImpl::SetNeedsAnimate() { |
| 1742 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
| 1743 client_->SetNeedsAnimateOnImplThread(); |
| 1744 } |
| 1745 |
1745 void LayerTreeHostImpl::SetNeedsRedraw() { | 1746 void LayerTreeHostImpl::SetNeedsRedraw() { |
1746 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1747 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
1747 client_->SetNeedsRedrawOnImplThread(); | 1748 client_->SetNeedsRedrawOnImplThread(); |
1748 } | 1749 } |
1749 | 1750 |
1750 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { | 1751 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { |
1751 ManagedMemoryPolicy actual = cached_managed_memory_policy_; | 1752 ManagedMemoryPolicy actual = cached_managed_memory_policy_; |
1752 // TODO(ernstm): The second condition disables pre-painting for all layers | 1753 // TODO(ernstm): The second condition disables pre-painting for all layers |
1753 // when GPU rasterization is enabled. Once we selectively enable GPU | 1754 // when GPU rasterization is enabled. Once we selectively enable GPU |
1754 // rasterization per layer, we also need to disable pre-painting selectively: | 1755 // rasterization per layer, we also need to disable pre-painting selectively: |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 return external_clip_; | 2047 return external_clip_; |
2047 } | 2048 } |
2048 | 2049 |
2049 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { | 2050 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { |
2050 return external_transform_; | 2051 return external_transform_; |
2051 } | 2052 } |
2052 | 2053 |
2053 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 2054 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
2054 UpdateInnerViewportContainerSize(); | 2055 UpdateInnerViewportContainerSize(); |
2055 SetNeedsRedraw(); | 2056 SetNeedsRedraw(); |
| 2057 SetNeedsAnimate(); |
2056 active_tree_->set_needs_update_draw_properties(); | 2058 active_tree_->set_needs_update_draw_properties(); |
2057 SetFullRootLayerDamage(); | 2059 SetFullRootLayerDamage(); |
2058 } | 2060 } |
2059 | 2061 |
2060 bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() { | 2062 bool LayerTreeHostImpl::EnsureRenderSurfaceLayerList() { |
2061 active_tree_->UpdateDrawProperties(); | 2063 active_tree_->UpdateDrawProperties(); |
2062 return !active_tree_->RenderSurfaceLayerList().empty(); | 2064 return !active_tree_->RenderSurfaceLayerList().empty(); |
2063 } | 2065 } |
2064 | 2066 |
2065 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { | 2067 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2730 monotonic_time_for_cc_animations); | 2732 monotonic_time_for_cc_animations); |
2731 | 2733 |
2732 ScrollViewportBy(next_scroll - scroll_total); | 2734 ScrollViewportBy(next_scroll - scroll_total); |
2733 SetNeedsRedraw(); | 2735 SetNeedsRedraw(); |
2734 | 2736 |
2735 if (page_scale_animation_->IsAnimationCompleteAtTime( | 2737 if (page_scale_animation_->IsAnimationCompleteAtTime( |
2736 monotonic_time_for_cc_animations)) { | 2738 monotonic_time_for_cc_animations)) { |
2737 page_scale_animation_.reset(); | 2739 page_scale_animation_.reset(); |
2738 client_->SetNeedsCommitOnImplThread(); | 2740 client_->SetNeedsCommitOnImplThread(); |
2739 client_->RenewTreePriority(); | 2741 client_->RenewTreePriority(); |
| 2742 } else { |
| 2743 SetNeedsAnimate(); |
2740 } | 2744 } |
2741 } | 2745 } |
2742 | 2746 |
2743 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { | 2747 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { |
2744 if (!top_controls_manager_ || !top_controls_manager_->animation()) | 2748 if (!top_controls_manager_ || !top_controls_manager_->animation()) |
2745 return; | 2749 return; |
2746 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); | 2750 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); |
2747 if (active_tree_->TotalScrollOffset().y() == 0.f) | 2751 if (active_tree_->TotalScrollOffset().y() == 0.f) |
2748 return; | 2752 return; |
2749 if (scroll.IsZero()) { | 2753 if (!scroll.IsZero()) { |
2750 // This may happen on the first animation step. Force redraw otherwise | |
2751 // the animation would stop because of no new frames. | |
2752 SetNeedsRedraw(); | |
2753 } else { | |
2754 ScrollViewportBy(gfx::ScaleVector2d( | 2754 ScrollViewportBy(gfx::ScaleVector2d( |
2755 scroll, 1.f / active_tree_->total_page_scale_factor())); | 2755 scroll, 1.f / active_tree_->total_page_scale_factor())); |
| 2756 SetNeedsRedraw(); |
2756 } | 2757 } |
| 2758 SetNeedsAnimate(); |
2757 } | 2759 } |
2758 | 2760 |
2759 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { | 2761 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { |
2760 if (!settings_.accelerated_animation_enabled || | 2762 if (!settings_.accelerated_animation_enabled || |
2761 !needs_animate_layers() || | 2763 !needs_animate_layers() || |
2762 !active_tree_->root_layer()) | 2764 !active_tree_->root_layer()) |
2763 return; | 2765 return; |
2764 | 2766 |
2765 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); | 2767 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); |
2766 | 2768 |
2767 // TODO(ajuma): http://crbug.com/178171 - Animations use double for monotonic | 2769 // TODO(ajuma): http://crbug.com/178171 - Animations use double for monotonic |
2768 // time. | 2770 // time. |
2769 double monotonic_time_for_cc_animations = | 2771 double monotonic_time_for_cc_animations = |
2770 (monotonic_time - base::TimeTicks()).InSecondsF(); | 2772 (monotonic_time - base::TimeTicks()).InSecondsF(); |
2771 AnimationRegistrar::AnimationControllerMap copy = | 2773 AnimationRegistrar::AnimationControllerMap copy = |
2772 animation_registrar_->active_animation_controllers(); | 2774 animation_registrar_->active_animation_controllers(); |
2773 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 2775 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
2774 iter != copy.end(); | 2776 iter != copy.end(); |
2775 ++iter) | 2777 ++iter) |
2776 (*iter).second->Animate(monotonic_time_for_cc_animations); | 2778 (*iter).second->Animate(monotonic_time_for_cc_animations); |
2777 | 2779 |
2778 SetNeedsRedraw(); | 2780 SetNeedsAnimate(); |
2779 } | 2781 } |
2780 | 2782 |
2781 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { | 2783 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { |
2782 if (!settings_.accelerated_animation_enabled || | 2784 if (!settings_.accelerated_animation_enabled || |
2783 !needs_animate_layers() || | 2785 !needs_animate_layers() || |
2784 !active_tree_->root_layer()) | 2786 !active_tree_->root_layer()) |
2785 return; | 2787 return; |
2786 | 2788 |
2787 TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState"); | 2789 TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState"); |
2788 scoped_ptr<AnimationEventsVector> events = | 2790 scoped_ptr<AnimationEventsVector> events = |
2789 make_scoped_ptr(new AnimationEventsVector); | 2791 make_scoped_ptr(new AnimationEventsVector); |
2790 AnimationRegistrar::AnimationControllerMap copy = | 2792 AnimationRegistrar::AnimationControllerMap copy = |
2791 animation_registrar_->active_animation_controllers(); | 2793 animation_registrar_->active_animation_controllers(); |
2792 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); | 2794 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); |
2793 iter != copy.end(); | 2795 iter != copy.end(); |
2794 ++iter) | 2796 ++iter) |
2795 (*iter).second->UpdateState(start_ready_animations, events.get()); | 2797 (*iter).second->UpdateState(start_ready_animations, events.get()); |
2796 | 2798 |
2797 if (!events->empty()) { | 2799 if (!events->empty()) { |
2798 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); | 2800 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); |
2799 } | 2801 } |
| 2802 |
| 2803 SetNeedsAnimate(); |
2800 } | 2804 } |
2801 | 2805 |
2802 base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const { | 2806 base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const { |
2803 return base::TimeDelta::FromSeconds(1); | 2807 return base::TimeDelta::FromSeconds(1); |
2804 } | 2808 } |
2805 | 2809 |
2806 void LayerTreeHostImpl::SendReleaseResourcesRecursive(LayerImpl* current) { | 2810 void LayerTreeHostImpl::SendReleaseResourcesRecursive(LayerImpl* current) { |
2807 DCHECK(current); | 2811 DCHECK(current); |
2808 current->ReleaseResources(); | 2812 current->ReleaseResources(); |
2809 if (current->mask_layer()) | 2813 if (current->mask_layer()) |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2863 | 2867 |
2864 void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer, | 2868 void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer, |
2865 base::TimeTicks time) { | 2869 base::TimeTicks time) { |
2866 if (!layer) | 2870 if (!layer) |
2867 return; | 2871 return; |
2868 | 2872 |
2869 ScrollbarAnimationController* scrollbar_controller = | 2873 ScrollbarAnimationController* scrollbar_controller = |
2870 layer->scrollbar_animation_controller(); | 2874 layer->scrollbar_animation_controller(); |
2871 if (scrollbar_controller && scrollbar_controller->Animate(time)) { | 2875 if (scrollbar_controller && scrollbar_controller->Animate(time)) { |
2872 TRACE_EVENT_INSTANT0( | 2876 TRACE_EVENT_INSTANT0( |
2873 "cc", "LayerTreeHostImpl::SetNeedsRedraw due to AnimateScrollbars", | 2877 "cc", |
| 2878 "LayerTreeHostImpl::SetNeedsAnimate due to AnimateScrollbars", |
2874 TRACE_EVENT_SCOPE_THREAD); | 2879 TRACE_EVENT_SCOPE_THREAD); |
2875 SetNeedsRedraw(); | 2880 SetNeedsAnimate(); |
2876 } | 2881 } |
2877 | 2882 |
2878 for (size_t i = 0; i < layer->children().size(); ++i) | 2883 for (size_t i = 0; i < layer->children().size(); ++i) |
2879 AnimateScrollbarsRecursive(layer->children()[i], time); | 2884 AnimateScrollbarsRecursive(layer->children()[i], time); |
2880 } | 2885 } |
2881 | 2886 |
2882 void LayerTreeHostImpl::StartScrollbarAnimation() { | 2887 void LayerTreeHostImpl::StartScrollbarAnimation() { |
2883 TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation"); | 2888 TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation"); |
2884 StartScrollbarAnimationRecursive(RootLayer(), CurrentFrameTimeTicks()); | 2889 StartScrollbarAnimationRecursive(RootLayer(), CurrentFrameTimeTicks()); |
2885 } | 2890 } |
2886 | 2891 |
2887 void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer, | 2892 void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer, |
2888 base::TimeTicks time) { | 2893 base::TimeTicks time) { |
2889 if (!layer) | 2894 if (!layer) |
2890 return; | 2895 return; |
2891 | 2896 |
2892 ScrollbarAnimationController* scrollbar_controller = | 2897 ScrollbarAnimationController* scrollbar_controller = |
2893 layer->scrollbar_animation_controller(); | 2898 layer->scrollbar_animation_controller(); |
2894 if (scrollbar_controller && scrollbar_controller->IsAnimating()) { | 2899 if (scrollbar_controller && scrollbar_controller->IsAnimating()) { |
2895 base::TimeDelta delay = scrollbar_controller->DelayBeforeStart(time); | 2900 base::TimeDelta delay = scrollbar_controller->DelayBeforeStart(time); |
2896 if (delay > base::TimeDelta()) | 2901 if (delay > base::TimeDelta()) { |
2897 client_->RequestScrollbarAnimationOnImplThread(delay); | 2902 client_->RequestScrollbarAnimationOnImplThread(delay); |
2898 else if (scrollbar_controller->Animate(time)) | 2903 } else if (scrollbar_controller->Animate(time)) { |
2899 SetNeedsRedraw(); | 2904 SetNeedsAnimate(); |
| 2905 } |
2900 } | 2906 } |
2901 | 2907 |
2902 for (size_t i = 0; i < layer->children().size(); ++i) | 2908 for (size_t i = 0; i < layer->children().size(); ++i) |
2903 StartScrollbarAnimationRecursive(layer->children()[i], time); | 2909 StartScrollbarAnimationRecursive(layer->children()[i], time); |
2904 } | 2910 } |
2905 | 2911 |
2906 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { | 2912 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { |
2907 if (!tile_manager_) | 2913 if (!tile_manager_) |
2908 return; | 2914 return; |
2909 | 2915 |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3080 swap_promise_monitor_.erase(monitor); | 3086 swap_promise_monitor_.erase(monitor); |
3081 } | 3087 } |
3082 | 3088 |
3083 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { | 3089 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { |
3084 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3090 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
3085 for (; it != swap_promise_monitor_.end(); it++) | 3091 for (; it != swap_promise_monitor_.end(); it++) |
3086 (*it)->OnSetNeedsRedrawOnImpl(); | 3092 (*it)->OnSetNeedsRedrawOnImpl(); |
3087 } | 3093 } |
3088 | 3094 |
3089 } // namespace cc | 3095 } // namespace cc |
OLD | NEW |