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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 SetDebugState(settings.initial_debug_state); | 234 SetDebugState(settings.initial_debug_state); |
235 | 235 |
236 // LTHI always has an active tree. | 236 // LTHI always has an active tree. |
237 active_tree_ = | 237 active_tree_ = |
238 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), | 238 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), |
239 new SyncedTopControls, new SyncedElasticOverscroll); | 239 new SyncedTopControls, new SyncedElasticOverscroll); |
240 | 240 |
241 TRACE_EVENT_OBJECT_CREATED_WITH_ID( | 241 TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
242 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); | 242 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); |
243 | 243 |
244 top_controls_manager_ = | 244 if (settings.calculate_top_controls_position) { |
245 TopControlsManager::Create(this, | 245 top_controls_manager_ = |
246 settings.top_controls_show_threshold, | 246 TopControlsManager::Create(this, |
247 settings.top_controls_hide_threshold); | 247 settings.top_controls_show_threshold, |
| 248 settings.top_controls_hide_threshold); |
| 249 } |
248 } | 250 } |
249 | 251 |
250 LayerTreeHostImpl::~LayerTreeHostImpl() { | 252 LayerTreeHostImpl::~LayerTreeHostImpl() { |
251 DCHECK(proxy_->IsImplThread()); | 253 DCHECK(proxy_->IsImplThread()); |
252 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); | 254 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
253 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 255 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
254 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); | 256 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); |
255 | 257 |
256 if (input_handler_client_) { | 258 if (input_handler_client_) { |
257 input_handler_client_->WillShutdown(); | 259 input_handler_client_->WillShutdown(); |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 909 |
908 // Should only have one render pass in resourceless software mode. | 910 // Should only have one render pass in resourceless software mode. |
909 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE || | 911 DCHECK(draw_mode != DRAW_MODE_RESOURCELESS_SOFTWARE || |
910 frame->render_passes.size() == 1u) | 912 frame->render_passes.size() == 1u) |
911 << frame->render_passes.size(); | 913 << frame->render_passes.size(); |
912 | 914 |
913 return draw_result; | 915 return draw_result; |
914 } | 916 } |
915 | 917 |
916 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { | 918 void LayerTreeHostImpl::MainThreadHasStoppedFlinging() { |
917 top_controls_manager_->MainThreadHasStoppedFlinging(); | 919 if (top_controls_manager_) |
| 920 top_controls_manager_->MainThreadHasStoppedFlinging(); |
918 if (input_handler_client_) | 921 if (input_handler_client_) |
919 input_handler_client_->MainThreadHasStoppedFlinging(); | 922 input_handler_client_->MainThreadHasStoppedFlinging(); |
920 } | 923 } |
921 | 924 |
922 void LayerTreeHostImpl::DidAnimateScrollOffset() { | 925 void LayerTreeHostImpl::DidAnimateScrollOffset() { |
923 client_->SetNeedsCommitOnImplThread(); | 926 client_->SetNeedsCommitOnImplThread(); |
924 client_->RenewTreePriority(); | 927 client_->RenewTreePriority(); |
925 } | 928 } |
926 | 929 |
927 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { | 930 void LayerTreeHostImpl::SetViewportDamage(const gfx::Rect& damage_rect) { |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1413 } | 1416 } |
1414 | 1417 |
1415 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { | 1418 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { |
1416 CompositorFrameMetadata metadata; | 1419 CompositorFrameMetadata metadata; |
1417 metadata.device_scale_factor = device_scale_factor_; | 1420 metadata.device_scale_factor = device_scale_factor_; |
1418 metadata.page_scale_factor = active_tree_->current_page_scale_factor(); | 1421 metadata.page_scale_factor = active_tree_->current_page_scale_factor(); |
1419 metadata.scrollable_viewport_size = active_tree_->ScrollableViewportSize(); | 1422 metadata.scrollable_viewport_size = active_tree_->ScrollableViewportSize(); |
1420 metadata.root_layer_size = active_tree_->ScrollableSize(); | 1423 metadata.root_layer_size = active_tree_->ScrollableSize(); |
1421 metadata.min_page_scale_factor = active_tree_->min_page_scale_factor(); | 1424 metadata.min_page_scale_factor = active_tree_->min_page_scale_factor(); |
1422 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); | 1425 metadata.max_page_scale_factor = active_tree_->max_page_scale_factor(); |
1423 metadata.location_bar_offset = | 1426 if (top_controls_manager_) { |
1424 gfx::Vector2dF(0.f, top_controls_manager_->ControlsTopOffset()); | 1427 metadata.location_bar_offset = |
1425 metadata.location_bar_content_translation = | 1428 gfx::Vector2dF(0.f, top_controls_manager_->ControlsTopOffset()); |
1426 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); | 1429 metadata.location_bar_content_translation = |
| 1430 gfx::Vector2dF(0.f, top_controls_manager_->ContentTopOffset()); |
| 1431 } |
1427 | 1432 |
1428 active_tree_->GetViewportSelection(&metadata.selection_start, | 1433 active_tree_->GetViewportSelection(&metadata.selection_start, |
1429 &metadata.selection_end); | 1434 &metadata.selection_end); |
1430 | 1435 |
1431 LayerImpl* root_layer_for_overflow = OuterViewportScrollLayer() | 1436 LayerImpl* root_layer_for_overflow = OuterViewportScrollLayer() |
1432 ? OuterViewportScrollLayer() | 1437 ? OuterViewportScrollLayer() |
1433 : InnerViewportScrollLayer(); | 1438 : InnerViewportScrollLayer(); |
1434 if (root_layer_for_overflow) { | 1439 if (root_layer_for_overflow) { |
1435 metadata.root_overflow_x_hidden = | 1440 metadata.root_overflow_x_hidden = |
1436 !root_layer_for_overflow->user_scrollable_horizontal(); | 1441 !root_layer_for_overflow->user_scrollable_horizontal(); |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 // to complete its work so that we can draw new tiles within the impl frame | 1651 // to complete its work so that we can draw new tiles within the impl frame |
1647 // we are beginning now. | 1652 // we are beginning now. |
1648 SetNeedsRedraw(); | 1653 SetNeedsRedraw(); |
1649 } | 1654 } |
1650 } | 1655 } |
1651 | 1656 |
1652 void LayerTreeHostImpl::UpdateViewportContainerSizes() { | 1657 void LayerTreeHostImpl::UpdateViewportContainerSizes() { |
1653 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); | 1658 LayerImpl* inner_container = active_tree_->InnerViewportContainerLayer(); |
1654 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); | 1659 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); |
1655 | 1660 |
1656 if (!inner_container) | 1661 if (!inner_container || !top_controls_manager_) |
1657 return; | 1662 return; |
1658 | 1663 |
1659 ViewportAnchor anchor(InnerViewportScrollLayer(), | 1664 ViewportAnchor anchor(InnerViewportScrollLayer(), |
1660 OuterViewportScrollLayer()); | 1665 OuterViewportScrollLayer()); |
1661 | 1666 |
1662 // Adjust the inner viewport by shrinking/expanding the container to account | 1667 // Adjust the inner viewport by shrinking/expanding the container to account |
1663 // for the change in top controls height since the last Resize from Blink. | 1668 // for the change in top controls height since the last Resize from Blink. |
1664 float top_controls_layout_height = | 1669 float top_controls_layout_height = |
1665 active_tree_->top_controls_shrink_blink_size() | 1670 active_tree_->top_controls_shrink_blink_size() |
1666 ? active_tree_->top_controls_height() | 1671 ? active_tree_->top_controls_height() |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2344 return ancestor == scroll_ancestor; | 2349 return ancestor == scroll_ancestor; |
2345 } | 2350 } |
2346 return false; | 2351 return false; |
2347 } | 2352 } |
2348 | 2353 |
2349 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( | 2354 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
2350 const gfx::Point& viewport_point, | 2355 const gfx::Point& viewport_point, |
2351 InputHandler::ScrollInputType type) { | 2356 InputHandler::ScrollInputType type) { |
2352 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 2357 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
2353 | 2358 |
2354 top_controls_manager_->ScrollBegin(); | 2359 if (top_controls_manager_) |
| 2360 top_controls_manager_->ScrollBegin(); |
2355 | 2361 |
2356 DCHECK(!CurrentlyScrollingLayer()); | 2362 DCHECK(!CurrentlyScrollingLayer()); |
2357 ClearCurrentlyScrollingLayer(); | 2363 ClearCurrentlyScrollingLayer(); |
2358 | 2364 |
2359 gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point, | 2365 gfx::PointF device_viewport_point = gfx::ScalePoint(viewport_point, |
2360 device_scale_factor_); | 2366 device_scale_factor_); |
2361 LayerImpl* layer_impl = | 2367 LayerImpl* layer_impl = |
2362 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 2368 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
2363 | 2369 |
2364 if (layer_impl) { | 2370 if (layer_impl) { |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2555 layer_impl->ScrollBy(delta); | 2561 layer_impl->ScrollBy(delta); |
2556 gfx::ScrollOffset scrolled = | 2562 gfx::ScrollOffset scrolled = |
2557 layer_impl->CurrentScrollOffset() - previous_offset; | 2563 layer_impl->CurrentScrollOffset() - previous_offset; |
2558 return gfx::Vector2dF(scrolled.x(), scrolled.y()); | 2564 return gfx::Vector2dF(scrolled.x(), scrolled.y()); |
2559 } | 2565 } |
2560 | 2566 |
2561 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( | 2567 bool LayerTreeHostImpl::ShouldTopControlsConsumeScroll( |
2562 const gfx::Vector2dF& scroll_delta) const { | 2568 const gfx::Vector2dF& scroll_delta) const { |
2563 DCHECK(CurrentlyScrollingLayer()); | 2569 DCHECK(CurrentlyScrollingLayer()); |
2564 | 2570 |
| 2571 if (!top_controls_manager_) |
| 2572 return false; |
| 2573 |
2565 // Always consume if it's in the direction to show the top controls. | 2574 // Always consume if it's in the direction to show the top controls. |
2566 if (scroll_delta.y() < 0) | 2575 if (scroll_delta.y() < 0) |
2567 return true; | 2576 return true; |
2568 | 2577 |
2569 if (active_tree()->TotalScrollOffset().y() < | 2578 if (active_tree()->TotalScrollOffset().y() < |
2570 active_tree()->TotalMaxScrollOffset().y()) | 2579 active_tree()->TotalMaxScrollOffset().y()) |
2571 return true; | 2580 return true; |
2572 | 2581 |
2573 return false; | 2582 return false; |
2574 } | 2583 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2795 } | 2804 } |
2796 | 2805 |
2797 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { | 2806 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { |
2798 active_tree_->ClearCurrentlyScrollingLayer(); | 2807 active_tree_->ClearCurrentlyScrollingLayer(); |
2799 did_lock_scrolling_layer_ = false; | 2808 did_lock_scrolling_layer_ = false; |
2800 scroll_affects_scroll_handler_ = false; | 2809 scroll_affects_scroll_handler_ = false; |
2801 accumulated_root_overscroll_ = gfx::Vector2dF(); | 2810 accumulated_root_overscroll_ = gfx::Vector2dF(); |
2802 } | 2811 } |
2803 | 2812 |
2804 void LayerTreeHostImpl::ScrollEnd() { | 2813 void LayerTreeHostImpl::ScrollEnd() { |
2805 top_controls_manager_->ScrollEnd(); | 2814 if (top_controls_manager_) |
| 2815 top_controls_manager_->ScrollEnd(); |
2806 ClearCurrentlyScrollingLayer(); | 2816 ClearCurrentlyScrollingLayer(); |
2807 } | 2817 } |
2808 | 2818 |
2809 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { | 2819 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { |
2810 if (!active_tree_->CurrentlyScrollingLayer()) | 2820 if (!active_tree_->CurrentlyScrollingLayer()) |
2811 return SCROLL_IGNORED; | 2821 return SCROLL_IGNORED; |
2812 | 2822 |
2813 if (settings_.ignore_root_layer_flings && | 2823 if (settings_.ignore_root_layer_flings && |
2814 (active_tree_->CurrentlyScrollingLayer() == InnerViewportScrollLayer() || | 2824 (active_tree_->CurrentlyScrollingLayer() == InnerViewportScrollLayer() || |
2815 active_tree_->CurrentlyScrollingLayer() == OuterViewportScrollLayer())) { | 2825 active_tree_->CurrentlyScrollingLayer() == OuterViewportScrollLayer())) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2916 previous_pinch_anchor_ = gfx::Point(); | 2926 previous_pinch_anchor_ = gfx::Point(); |
2917 client_->RenewTreePriority(); | 2927 client_->RenewTreePriority(); |
2918 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); | 2928 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); |
2919 if (active_tree_->OuterViewportScrollLayer()) { | 2929 if (active_tree_->OuterViewportScrollLayer()) { |
2920 active_tree_->SetCurrentlyScrollingLayer( | 2930 active_tree_->SetCurrentlyScrollingLayer( |
2921 active_tree_->OuterViewportScrollLayer()); | 2931 active_tree_->OuterViewportScrollLayer()); |
2922 } else { | 2932 } else { |
2923 active_tree_->SetCurrentlyScrollingLayer( | 2933 active_tree_->SetCurrentlyScrollingLayer( |
2924 active_tree_->InnerViewportScrollLayer()); | 2934 active_tree_->InnerViewportScrollLayer()); |
2925 } | 2935 } |
2926 top_controls_manager_->PinchBegin(); | 2936 if (top_controls_manager_) |
| 2937 top_controls_manager_->PinchBegin(); |
2927 } | 2938 } |
2928 | 2939 |
2929 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, | 2940 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, |
2930 const gfx::Point& anchor) { | 2941 const gfx::Point& anchor) { |
2931 if (!InnerViewportScrollLayer()) | 2942 if (!InnerViewportScrollLayer()) |
2932 return; | 2943 return; |
2933 | 2944 |
2934 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); | 2945 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); |
2935 | 2946 |
2936 // For a moment the scroll offset ends up being outside of the max range. This | 2947 // For a moment the scroll offset ends up being outside of the max range. This |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2975 SetNeedsRedraw(); | 2986 SetNeedsRedraw(); |
2976 client_->RenewTreePriority(); | 2987 client_->RenewTreePriority(); |
2977 } | 2988 } |
2978 | 2989 |
2979 void LayerTreeHostImpl::PinchGestureEnd() { | 2990 void LayerTreeHostImpl::PinchGestureEnd() { |
2980 pinch_gesture_active_ = false; | 2991 pinch_gesture_active_ = false; |
2981 if (pinch_gesture_end_should_clear_scrolling_layer_) { | 2992 if (pinch_gesture_end_should_clear_scrolling_layer_) { |
2982 pinch_gesture_end_should_clear_scrolling_layer_ = false; | 2993 pinch_gesture_end_should_clear_scrolling_layer_ = false; |
2983 ClearCurrentlyScrollingLayer(); | 2994 ClearCurrentlyScrollingLayer(); |
2984 } | 2995 } |
2985 top_controls_manager_->PinchEnd(); | 2996 if (top_controls_manager_) |
| 2997 top_controls_manager_->PinchEnd(); |
2986 client_->SetNeedsCommitOnImplThread(); | 2998 client_->SetNeedsCommitOnImplThread(); |
2987 // When a pinch ends, we may be displaying content cached at incorrect scales, | 2999 // When a pinch ends, we may be displaying content cached at incorrect scales, |
2988 // so updating draw properties and drawing will ensure we are using the right | 3000 // so updating draw properties and drawing will ensure we are using the right |
2989 // scales that we want when we're not inside a pinch. | 3001 // scales that we want when we're not inside a pinch. |
2990 active_tree_->set_needs_update_draw_properties(); | 3002 active_tree_->set_needs_update_draw_properties(); |
2991 SetNeedsRedraw(); | 3003 SetNeedsRedraw(); |
2992 } | 3004 } |
2993 | 3005 |
2994 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, | 3006 static void CollectScrollDeltas(ScrollAndScaleSet* scroll_info, |
2995 LayerImpl* layer_impl) { | 3007 LayerImpl* layer_impl) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3070 page_scale_animation_ = nullptr; | 3082 page_scale_animation_ = nullptr; |
3071 client_->SetNeedsCommitOnImplThread(); | 3083 client_->SetNeedsCommitOnImplThread(); |
3072 client_->RenewTreePriority(); | 3084 client_->RenewTreePriority(); |
3073 client_->DidCompletePageScaleAnimationOnImplThread(); | 3085 client_->DidCompletePageScaleAnimationOnImplThread(); |
3074 } else { | 3086 } else { |
3075 SetNeedsAnimate(); | 3087 SetNeedsAnimate(); |
3076 } | 3088 } |
3077 } | 3089 } |
3078 | 3090 |
3079 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { | 3091 void LayerTreeHostImpl::AnimateTopControls(base::TimeTicks time) { |
3080 if (!top_controls_manager_->animation()) | 3092 if (!top_controls_manager_ || !top_controls_manager_->animation()) |
3081 return; | 3093 return; |
3082 | 3094 |
3083 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); | 3095 gfx::Vector2dF scroll = top_controls_manager_->Animate(time); |
3084 | 3096 |
3085 if (top_controls_manager_->animation()) | 3097 if (top_controls_manager_->animation()) |
3086 SetNeedsAnimate(); | 3098 SetNeedsAnimate(); |
3087 | 3099 |
3088 if (active_tree_->TotalScrollOffset().y() == 0.f) | 3100 if (active_tree_->TotalScrollOffset().y() == 0.f) |
3089 return; | 3101 return; |
3090 | 3102 |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3450 (*it)->OnSetNeedsRedrawOnImpl(); | 3462 (*it)->OnSetNeedsRedrawOnImpl(); |
3451 } | 3463 } |
3452 | 3464 |
3453 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() { | 3465 void LayerTreeHostImpl::NotifySwapPromiseMonitorsOfForwardingToMainThread() { |
3454 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); | 3466 std::set<SwapPromiseMonitor*>::iterator it = swap_promise_monitor_.begin(); |
3455 for (; it != swap_promise_monitor_.end(); it++) | 3467 for (; it != swap_promise_monitor_.end(); it++) |
3456 (*it)->OnForwardScrollUpdateToMainThreadOnImpl(); | 3468 (*it)->OnForwardScrollUpdateToMainThreadOnImpl(); |
3457 } | 3469 } |
3458 | 3470 |
3459 } // namespace cc | 3471 } // namespace cc |
OLD | NEW |