Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 206793003: cc: Split animating and drawing into separate actions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added test for animation issue. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1711 // draw or timer tick. 1707 // draw or timer tick.
1712 if (!visible_) 1708 if (!visible_)
1713 ManageTiles(); 1709 ManageTiles();
1714 1710
1715 if (!renderer_) 1711 if (!renderer_)
1716 return; 1712 return;
1717 1713
1718 renderer_->SetVisible(visible); 1714 renderer_->SetVisible(visible);
1719 } 1715 }
1720 1716
1717 void LayerTreeHostImpl::SetNeedsAnimate() {
1718 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
1719 client_->SetNeedsAnimateOnImplThread();
1720 }
1721
1721 void LayerTreeHostImpl::SetNeedsRedraw() { 1722 void LayerTreeHostImpl::SetNeedsRedraw() {
1722 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 1723 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
1723 client_->SetNeedsRedrawOnImplThread(); 1724 client_->SetNeedsRedrawOnImplThread();
1724 } 1725 }
1725 1726
1726 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const { 1727 ManagedMemoryPolicy LayerTreeHostImpl::ActualManagedMemoryPolicy() const {
1727 ManagedMemoryPolicy actual = cached_managed_memory_policy_; 1728 ManagedMemoryPolicy actual = cached_managed_memory_policy_;
1728 // TODO(ernstm): The second condition disables pre-painting for all layers 1729 // TODO(ernstm): The second condition disables pre-painting for all layers
1729 // when GPU rasterization is enabled. Once we selectively enable GPU 1730 // when GPU rasterization is enabled. Once we selectively enable GPU
1730 // rasterization per layer, we also need to disable pre-painting selectively: 1731 // rasterization per layer, we also need to disable pre-painting selectively:
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after
2706 monotonic_time_for_cc_animations); 2707 monotonic_time_for_cc_animations);
2707 2708
2708 ScrollViewportBy(next_scroll - scroll_total); 2709 ScrollViewportBy(next_scroll - scroll_total);
2709 SetNeedsRedraw(); 2710 SetNeedsRedraw();
2710 2711
2711 if (page_scale_animation_->IsAnimationCompleteAtTime( 2712 if (page_scale_animation_->IsAnimationCompleteAtTime(
2712 monotonic_time_for_cc_animations)) { 2713 monotonic_time_for_cc_animations)) {
2713 page_scale_animation_.reset(); 2714 page_scale_animation_.reset();
2714 client_->SetNeedsCommitOnImplThread(); 2715 client_->SetNeedsCommitOnImplThread();
2715 client_->RenewTreePriority(); 2716 client_->RenewTreePriority();
2717 } else {
2718 SetNeedsAnimate();
2716 } 2719 }
2717 } 2720 }
2718 2721
2719 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { 2722 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) {
2720 if (!top_controls_manager_ || !top_controls_manager_->animation()) 2723 if (!top_controls_manager_ || !top_controls_manager_->animation())
2721 return; 2724 return;
2722 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); 2725 gfx::Vector2dF scroll = top_controls_manager_->Animate(time);
2723 if (active_tree_->TotalScrollOffset().y() == 0.f) 2726 if (active_tree_->TotalScrollOffset().y() == 0.f)
2724 return; 2727 return;
2725 if (scroll.IsZero()) { 2728 if (!scroll.IsZero()) {
2726 // This may happen on the first animation step. Force redraw otherwise
2727 // the animation would stop because of no new frames.
2728 SetNeedsRedraw();
2729 } else {
2730 ScrollViewportBy(gfx::ScaleVector2d( 2729 ScrollViewportBy(gfx::ScaleVector2d(
2731 scroll, 1.f / active_tree_->total_page_scale_factor())); 2730 scroll, 1.f / active_tree_->total_page_scale_factor()));
2731 SetNeedsRedraw();
2732 } 2732 }
2733 SetNeedsAnimate();
2733 } 2734 }
2734 2735
2735 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) { 2736 void LayerTreeHostImpl::AnimateLayers(base::TimeTicks monotonic_time) {
2736 if (!settings_.accelerated_animation_enabled || 2737 if (!settings_.accelerated_animation_enabled ||
2737 !needs_animate_layers() || 2738 !needs_animate_layers() ||
2738 !active_tree_->root_layer()) 2739 !active_tree_->root_layer())
2739 return; 2740 return;
2740 2741
2741 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers"); 2742 TRACE_EVENT0("cc", "LayerTreeHostImpl::AnimateLayers");
2742 2743
2743 // TODO(ajuma): http://crbug.com/178171 - Animations use double for monotonic 2744 // TODO(ajuma): http://crbug.com/178171 - Animations use double for monotonic
2744 // time. 2745 // time.
2745 double monotonic_time_for_cc_animations = 2746 double monotonic_time_for_cc_animations =
2746 (monotonic_time - base::TimeTicks()).InSecondsF(); 2747 (monotonic_time - base::TimeTicks()).InSecondsF();
2747 AnimationRegistrar::AnimationControllerMap copy = 2748 AnimationRegistrar::AnimationControllerMap copy =
2748 animation_registrar_->active_animation_controllers(); 2749 animation_registrar_->active_animation_controllers();
2749 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); 2750 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
2750 iter != copy.end(); 2751 iter != copy.end();
2751 ++iter) 2752 ++iter)
2752 (*iter).second->Animate(monotonic_time_for_cc_animations); 2753 (*iter).second->Animate(monotonic_time_for_cc_animations);
2753 2754
2754 SetNeedsRedraw(); 2755 SetNeedsAnimate();
2755 } 2756 }
2756 2757
2757 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) { 2758 void LayerTreeHostImpl::UpdateAnimationState(bool start_ready_animations) {
2758 if (!settings_.accelerated_animation_enabled || 2759 if (!settings_.accelerated_animation_enabled ||
2759 !needs_animate_layers() || 2760 !needs_animate_layers() ||
2760 !active_tree_->root_layer()) 2761 !active_tree_->root_layer())
2761 return; 2762 return;
2762 2763
2763 TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState"); 2764 TRACE_EVENT0("cc", "LayerTreeHostImpl::UpdateAnimationState");
2764 scoped_ptr<AnimationEventsVector> events = 2765 scoped_ptr<AnimationEventsVector> events =
2765 make_scoped_ptr(new AnimationEventsVector); 2766 make_scoped_ptr(new AnimationEventsVector);
2766 AnimationRegistrar::AnimationControllerMap copy = 2767 AnimationRegistrar::AnimationControllerMap copy =
2767 animation_registrar_->active_animation_controllers(); 2768 animation_registrar_->active_animation_controllers();
2768 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin(); 2769 for (AnimationRegistrar::AnimationControllerMap::iterator iter = copy.begin();
2769 iter != copy.end(); 2770 iter != copy.end();
2770 ++iter) 2771 ++iter)
2771 (*iter).second->UpdateState(start_ready_animations, events.get()); 2772 (*iter).second->UpdateState(start_ready_animations, events.get());
2772 2773
2773 if (!events->empty()) { 2774 if (!events->empty()) {
2774 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); 2775 client_->PostAnimationEventsToMainThreadOnImplThread(events.Pass());
2775 } 2776 }
2777
2778 SetNeedsAnimate();
2776 } 2779 }
2777 2780
2778 base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const { 2781 base::TimeDelta LayerTreeHostImpl::LowFrequencyAnimationInterval() const {
2779 return base::TimeDelta::FromSeconds(1); 2782 return base::TimeDelta::FromSeconds(1);
2780 } 2783 }
2781 2784
2782 void LayerTreeHostImpl::SendReleaseResourcesRecursive(LayerImpl* current) { 2785 void LayerTreeHostImpl::SendReleaseResourcesRecursive(LayerImpl* current) {
2783 DCHECK(current); 2786 DCHECK(current);
2784 current->ReleaseResources(); 2787 current->ReleaseResources();
2785 if (current->mask_layer()) 2788 if (current->mask_layer())
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2839 2842
2840 void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer, 2843 void LayerTreeHostImpl::AnimateScrollbarsRecursive(LayerImpl* layer,
2841 base::TimeTicks time) { 2844 base::TimeTicks time) {
2842 if (!layer) 2845 if (!layer)
2843 return; 2846 return;
2844 2847
2845 ScrollbarAnimationController* scrollbar_controller = 2848 ScrollbarAnimationController* scrollbar_controller =
2846 layer->scrollbar_animation_controller(); 2849 layer->scrollbar_animation_controller();
2847 if (scrollbar_controller && scrollbar_controller->Animate(time)) { 2850 if (scrollbar_controller && scrollbar_controller->Animate(time)) {
2848 TRACE_EVENT_INSTANT0( 2851 TRACE_EVENT_INSTANT0(
2849 "cc", "LayerTreeHostImpl::SetNeedsRedraw due to AnimateScrollbars", 2852 "cc",
2853 "LayerTreeHostImpl::SetNeedsAnimate due to AnimateScrollbars",
2850 TRACE_EVENT_SCOPE_THREAD); 2854 TRACE_EVENT_SCOPE_THREAD);
2851 SetNeedsRedraw(); 2855 SetNeedsAnimate();
2852 } 2856 }
2853 2857
2854 for (size_t i = 0; i < layer->children().size(); ++i) 2858 for (size_t i = 0; i < layer->children().size(); ++i)
2855 AnimateScrollbarsRecursive(layer->children()[i], time); 2859 AnimateScrollbarsRecursive(layer->children()[i], time);
2856 } 2860 }
2857 2861
2858 void LayerTreeHostImpl::StartScrollbarAnimation() { 2862 void LayerTreeHostImpl::StartScrollbarAnimation() {
2859 TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation"); 2863 TRACE_EVENT0("cc", "LayerTreeHostImpl::StartScrollbarAnimation");
2860 StartScrollbarAnimationRecursive(RootLayer(), CurrentFrameTimeTicks()); 2864 StartScrollbarAnimationRecursive(RootLayer(), CurrentFrameTimeTicks());
2861 } 2865 }
2862 2866
2863 void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer, 2867 void LayerTreeHostImpl::StartScrollbarAnimationRecursive(LayerImpl* layer,
2864 base::TimeTicks time) { 2868 base::TimeTicks time) {
2865 if (!layer) 2869 if (!layer)
2866 return; 2870 return;
2867 2871
2868 ScrollbarAnimationController* scrollbar_controller = 2872 ScrollbarAnimationController* scrollbar_controller =
2869 layer->scrollbar_animation_controller(); 2873 layer->scrollbar_animation_controller();
2870 if (scrollbar_controller && scrollbar_controller->IsAnimating()) { 2874 if (scrollbar_controller && scrollbar_controller->IsAnimating()) {
2871 base::TimeDelta delay = scrollbar_controller->DelayBeforeStart(time); 2875 base::TimeDelta delay = scrollbar_controller->DelayBeforeStart(time);
2872 if (delay > base::TimeDelta()) 2876 if (delay > base::TimeDelta()) {
2873 client_->RequestScrollbarAnimationOnImplThread(delay); 2877 client_->RequestScrollbarAnimationOnImplThread(delay);
2874 else if (scrollbar_controller->Animate(time)) 2878 } else if (scrollbar_controller->Animate(time)) {
2875 SetNeedsRedraw(); 2879 SetNeedsAnimate();
2880 }
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 StartScrollbarAnimationRecursive(layer->children()[i], time); 2884 StartScrollbarAnimationRecursive(layer->children()[i], time);
2880 } 2885 }
2881 2886
2882 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) { 2887 void LayerTreeHostImpl::SetTreePriority(TreePriority priority) {
2883 if (!tile_manager_) 2888 if (!tile_manager_)
2884 return; 2889 return;
2885 2890
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
3056 swap_promise_monitor_.erase(monitor); 3061 swap_promise_monitor_.erase(monitor);
3057 } 3062 }
3058 3063
3059 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() { 3064 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfSetNeedsRedraw() {
3060 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); 3065 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin();
3061 for (; it != swap_promise_monitor_.end(); it++) 3066 for (; it != swap_promise_monitor_.end(); it++)
3062 (*it)->OnSetNeedsRedrawOnImpl(); 3067 (*it)->OnSetNeedsRedrawOnImpl();
3063 } 3068 }
3064 3069
3065 } // namespace cc 3070 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698