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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 is_likely_to_require_a_draw_(false), | 232 is_likely_to_require_a_draw_(false), |
233 frame_timing_tracker_(FrameTimingTracker::Create()) { | 233 frame_timing_tracker_(FrameTimingTracker::Create()) { |
234 DCHECK(proxy_->IsImplThread()); | 234 DCHECK(proxy_->IsImplThread()); |
235 DidVisibilityChange(this, visible_); | 235 DidVisibilityChange(this, visible_); |
236 animation_registrar_->set_supports_scroll_animations( | 236 animation_registrar_->set_supports_scroll_animations( |
237 proxy_->SupportsImplScrolling()); | 237 proxy_->SupportsImplScrolling()); |
238 | 238 |
239 SetDebugState(settings.initial_debug_state); | 239 SetDebugState(settings.initial_debug_state); |
240 | 240 |
241 // LTHI always has an active tree. | 241 // LTHI always has an active tree. |
242 active_tree_ = LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), | 242 active_tree_ = |
243 new SyncedElasticOverscroll); | 243 LayerTreeImpl::create(this, new SyncedProperty<ScaleGroup>(), |
| 244 new SyncedTopControls, new SyncedElasticOverscroll); |
244 | 245 |
245 TRACE_EVENT_OBJECT_CREATED_WITH_ID( | 246 TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
246 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); | 247 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); |
247 | 248 |
248 if (settings.calculate_top_controls_position) { | 249 if (settings.calculate_top_controls_position) { |
249 top_controls_manager_ = | 250 top_controls_manager_ = |
250 TopControlsManager::Create(this, | 251 TopControlsManager::Create(this, |
251 settings.top_controls_show_threshold, | 252 settings.top_controls_show_threshold, |
252 settings.top_controls_hide_threshold); | 253 settings.top_controls_hide_threshold); |
253 } | 254 } |
(...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0)); | 1087 EnforceManagedMemoryPolicy(ManagedMemoryPolicy(0)); |
1087 } | 1088 } |
1088 | 1089 |
1089 void LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting(bool block) { | 1090 void LayerTreeHostImpl::BlockNotifyReadyToActivateForTesting(bool block) { |
1090 NOTREACHED(); | 1091 NOTREACHED(); |
1091 } | 1092 } |
1092 | 1093 |
1093 void LayerTreeHostImpl::ResetTreesForTesting() { | 1094 void LayerTreeHostImpl::ResetTreesForTesting() { |
1094 if (active_tree_) | 1095 if (active_tree_) |
1095 active_tree_->DetachLayerTree(); | 1096 active_tree_->DetachLayerTree(); |
1096 active_tree_ = LayerTreeImpl::create(this, active_tree()->page_scale_factor(), | 1097 active_tree_ = |
1097 active_tree()->elastic_overscroll()); | 1098 LayerTreeImpl::create(this, active_tree()->page_scale_factor(), |
| 1099 active_tree()->top_controls_shown_ratio(), |
| 1100 active_tree()->elastic_overscroll()); |
1098 if (pending_tree_) | 1101 if (pending_tree_) |
1099 pending_tree_->DetachLayerTree(); | 1102 pending_tree_->DetachLayerTree(); |
1100 pending_tree_ = nullptr; | 1103 pending_tree_ = nullptr; |
1101 if (recycle_tree_) | 1104 if (recycle_tree_) |
1102 recycle_tree_->DetachLayerTree(); | 1105 recycle_tree_->DetachLayerTree(); |
1103 recycle_tree_ = nullptr; | 1106 recycle_tree_ = nullptr; |
1104 } | 1107 } |
1105 | 1108 |
1106 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( | 1109 void LayerTreeHostImpl::EnforceManagedMemoryPolicy( |
1107 const ManagedMemoryPolicy& policy) { | 1110 const ManagedMemoryPolicy& policy) { |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1650 | 1653 |
1651 ViewportAnchor anchor(InnerViewportScrollLayer(), | 1654 ViewportAnchor anchor(InnerViewportScrollLayer(), |
1652 OuterViewportScrollLayer()); | 1655 OuterViewportScrollLayer()); |
1653 | 1656 |
1654 // Adjust the inner viewport by shrinking/expanding the container to account | 1657 // Adjust the inner viewport by shrinking/expanding the container to account |
1655 // for the change in top controls height since the last Resize from Blink. | 1658 // for the change in top controls height since the last Resize from Blink. |
1656 float top_controls_layout_height = | 1659 float top_controls_layout_height = |
1657 active_tree_->top_controls_shrink_blink_size() | 1660 active_tree_->top_controls_shrink_blink_size() |
1658 ? active_tree_->top_controls_height() | 1661 ? active_tree_->top_controls_height() |
1659 : 0.f; | 1662 : 0.f; |
1660 inner_container->SetBoundsDelta( | 1663 inner_container->SetBoundsDelta(gfx::Vector2dF( |
1661 gfx::Vector2dF(0, top_controls_layout_height - | 1664 0, |
1662 active_tree_->total_top_controls_content_offset())); | 1665 top_controls_layout_height - top_controls_manager_->ContentTopOffset())); |
1663 | 1666 |
1664 if (!outer_container || outer_container->BoundsForScrolling().IsEmpty()) | 1667 if (!outer_container || outer_container->BoundsForScrolling().IsEmpty()) |
1665 return; | 1668 return; |
1666 | 1669 |
1667 // Adjust the outer viewport container as well, since adjusting only the | 1670 // Adjust the outer viewport container as well, since adjusting only the |
1668 // inner may cause its bounds to exceed those of the outer, causing scroll | 1671 // inner may cause its bounds to exceed those of the outer, causing scroll |
1669 // clamping. We adjust it so it maintains the same aspect ratio as the | 1672 // clamping. We adjust it so it maintains the same aspect ratio as the |
1670 // inner viewport. | 1673 // inner viewport. |
1671 float aspect_ratio = inner_container->BoundsForScrolling().width() / | 1674 float aspect_ratio = inner_container->BoundsForScrolling().width() / |
1672 inner_container->BoundsForScrolling().height(); | 1675 inner_container->BoundsForScrolling().height(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1740 return NULL; | 1743 return NULL; |
1741 } | 1744 } |
1742 | 1745 |
1743 void LayerTreeHostImpl::CreatePendingTree() { | 1746 void LayerTreeHostImpl::CreatePendingTree() { |
1744 CHECK(!pending_tree_); | 1747 CHECK(!pending_tree_); |
1745 if (recycle_tree_) | 1748 if (recycle_tree_) |
1746 recycle_tree_.swap(pending_tree_); | 1749 recycle_tree_.swap(pending_tree_); |
1747 else | 1750 else |
1748 pending_tree_ = | 1751 pending_tree_ = |
1749 LayerTreeImpl::create(this, active_tree()->page_scale_factor(), | 1752 LayerTreeImpl::create(this, active_tree()->page_scale_factor(), |
| 1753 active_tree()->top_controls_shown_ratio(), |
1750 active_tree()->elastic_overscroll()); | 1754 active_tree()->elastic_overscroll()); |
1751 | 1755 |
1752 // Update the delta from the active tree, which may have | |
1753 // adjusted its delta prior to the pending tree being created. | |
1754 DCHECK_EQ(0.f, pending_tree_->sent_top_controls_delta()); | |
1755 pending_tree_->set_top_controls_delta( | |
1756 active_tree_->top_controls_delta() - | |
1757 active_tree_->sent_top_controls_delta()); | |
1758 pending_tree_->set_top_controls_height(active_tree_->top_controls_height()); | |
1759 | |
1760 client_->OnCanDrawStateChanged(CanDraw()); | 1756 client_->OnCanDrawStateChanged(CanDraw()); |
1761 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree:waiting", pending_tree_.get()); | 1757 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree:waiting", pending_tree_.get()); |
1762 } | 1758 } |
1763 | 1759 |
1764 void LayerTreeHostImpl::ActivateSyncTree() { | 1760 void LayerTreeHostImpl::ActivateSyncTree() { |
1765 if (pending_tree_) { | 1761 if (pending_tree_) { |
1766 TRACE_EVENT_ASYNC_END0("cc", "PendingTree:waiting", pending_tree_.get()); | 1762 TRACE_EVENT_ASYNC_END0("cc", "PendingTree:waiting", pending_tree_.get()); |
1767 | 1763 |
1768 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); | 1764 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); |
1769 active_tree_->PushPersistedState(pending_tree_.get()); | 1765 active_tree_->PushPersistedState(pending_tree_.get()); |
(...skipping 14 matching lines...) Expand all Loading... |
1784 | 1780 |
1785 // Now that we've synced everything from the pending tree to the active | 1781 // Now that we've synced everything from the pending tree to the active |
1786 // tree, rename the pending tree the recycle tree so we can reuse it on the | 1782 // tree, rename the pending tree the recycle tree so we can reuse it on the |
1787 // next sync. | 1783 // next sync. |
1788 DCHECK(!recycle_tree_); | 1784 DCHECK(!recycle_tree_); |
1789 pending_tree_.swap(recycle_tree_); | 1785 pending_tree_.swap(recycle_tree_); |
1790 | 1786 |
1791 active_tree_->SetRootLayerScrollOffsetDelegate( | 1787 active_tree_->SetRootLayerScrollOffsetDelegate( |
1792 root_layer_scroll_offset_delegate_); | 1788 root_layer_scroll_offset_delegate_); |
1793 | 1789 |
1794 if (top_controls_manager_) { | |
1795 top_controls_manager_->SetTopControlsHeight( | |
1796 active_tree_->top_controls_height()); | |
1797 top_controls_manager_->SetControlsTopOffset( | |
1798 active_tree_->total_top_controls_content_offset() - | |
1799 active_tree_->top_controls_height()); | |
1800 } | |
1801 | |
1802 UpdateViewportContainerSizes(); | 1790 UpdateViewportContainerSizes(); |
1803 } else { | 1791 } else { |
1804 active_tree_->ProcessUIResourceRequestQueue(); | 1792 active_tree_->ProcessUIResourceRequestQueue(); |
1805 } | 1793 } |
1806 | 1794 |
1807 active_tree_->DidBecomeActive(); | 1795 active_tree_->DidBecomeActive(); |
1808 ActivateAnimations(); | 1796 ActivateAnimations(); |
1809 if (settings_.impl_side_painting) { | 1797 if (settings_.impl_side_painting) { |
1810 client_->RenewTreePriority(); | 1798 client_->RenewTreePriority(); |
1811 // If we have any picture layers, then by activating we also modified tile | 1799 // If we have any picture layers, then by activating we also modified tile |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2251 } | 2239 } |
2252 | 2240 |
2253 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 2241 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
2254 UpdateViewportContainerSizes(); | 2242 UpdateViewportContainerSizes(); |
2255 SetNeedsRedraw(); | 2243 SetNeedsRedraw(); |
2256 SetNeedsAnimate(); | 2244 SetNeedsAnimate(); |
2257 active_tree_->set_needs_update_draw_properties(); | 2245 active_tree_->set_needs_update_draw_properties(); |
2258 SetFullRootLayerDamage(); | 2246 SetFullRootLayerDamage(); |
2259 } | 2247 } |
2260 | 2248 |
2261 void LayerTreeHostImpl::SetControlsTopOffset(float offset) { | 2249 float LayerTreeHostImpl::TopControlsHeight() const { |
2262 float current_top_offset = active_tree_->top_controls_content_offset() - | 2250 return active_tree_->top_controls_height(); |
2263 active_tree_->top_controls_height(); | |
2264 active_tree_->set_top_controls_delta(offset - current_top_offset); | |
2265 } | 2251 } |
2266 | 2252 |
2267 float LayerTreeHostImpl::ControlsTopOffset() const { | 2253 void LayerTreeHostImpl::SetCurrentTopControlsShownRatio(float ratio) { |
2268 return active_tree_->total_top_controls_content_offset() - | 2254 if (active_tree_->SetCurrentTopControlsShownRatio(ratio)) |
2269 active_tree_->top_controls_height(); | 2255 DidChangeTopControlsPosition(); |
| 2256 } |
| 2257 |
| 2258 float LayerTreeHostImpl::CurrentTopControlsShownRatio() const { |
| 2259 return active_tree_->CurrentTopControlsShownRatio(); |
2270 } | 2260 } |
2271 | 2261 |
2272 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { | 2262 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { |
2273 DCHECK(input_handler_client_ == NULL); | 2263 DCHECK(input_handler_client_ == NULL); |
2274 input_handler_client_ = client; | 2264 input_handler_client_ = client; |
2275 } | 2265 } |
2276 | 2266 |
2277 static LayerImpl* NextScrollLayer(LayerImpl* layer) { | 2267 static LayerImpl* NextScrollLayer(LayerImpl* layer) { |
2278 if (LayerImpl* scroll_parent = layer->scroll_parent()) | 2268 if (LayerImpl* scroll_parent = layer->scroll_parent()) |
2279 return scroll_parent; | 2269 return scroll_parent; |
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3014 for (size_t i = 0; i < layer_impl->children().size(); ++i) | 3004 for (size_t i = 0; i < layer_impl->children().size(); ++i) |
3015 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); | 3005 CollectScrollDeltas(scroll_info, layer_impl->children()[i]); |
3016 } | 3006 } |
3017 | 3007 |
3018 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { | 3008 scoped_ptr<ScrollAndScaleSet> LayerTreeHostImpl::ProcessScrollDeltas() { |
3019 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); | 3009 scoped_ptr<ScrollAndScaleSet> scroll_info(new ScrollAndScaleSet()); |
3020 | 3010 |
3021 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); | 3011 CollectScrollDeltas(scroll_info.get(), active_tree_->root_layer()); |
3022 scroll_info->page_scale_delta = | 3012 scroll_info->page_scale_delta = |
3023 active_tree_->page_scale_factor()->PullDeltaForMainThread(); | 3013 active_tree_->page_scale_factor()->PullDeltaForMainThread(); |
| 3014 scroll_info->top_controls_delta = |
| 3015 active_tree()->top_controls_shown_ratio()->PullDeltaForMainThread(); |
3024 scroll_info->elastic_overscroll_delta = | 3016 scroll_info->elastic_overscroll_delta = |
3025 active_tree_->elastic_overscroll()->PullDeltaForMainThread(); | 3017 active_tree_->elastic_overscroll()->PullDeltaForMainThread(); |
3026 scroll_info->swap_promises.swap(swap_promises_for_main_thread_scroll_update_); | 3018 scroll_info->swap_promises.swap(swap_promises_for_main_thread_scroll_update_); |
3027 scroll_info->top_controls_delta = active_tree()->top_controls_delta(); | |
3028 active_tree_->set_sent_top_controls_delta(scroll_info->top_controls_delta); | |
3029 | 3019 |
3030 return scroll_info.Pass(); | 3020 return scroll_info.Pass(); |
3031 } | 3021 } |
3032 | 3022 |
3033 void LayerTreeHostImpl::SetFullRootLayerDamage() { | 3023 void LayerTreeHostImpl::SetFullRootLayerDamage() { |
3034 SetViewportDamage(gfx::Rect(DrawViewportSize())); | 3024 SetViewportDamage(gfx::Rect(DrawViewportSize())); |
3035 } | 3025 } |
3036 | 3026 |
3037 void LayerTreeHostImpl::ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta) { | 3027 void LayerTreeHostImpl::ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta) { |
3038 DCHECK(InnerViewportScrollLayer()); | 3028 DCHECK(InnerViewportScrollLayer()); |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3478 } | 3468 } |
3479 | 3469 |
3480 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3470 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3481 std::vector<PictureLayerImpl*>::iterator it = | 3471 std::vector<PictureLayerImpl*>::iterator it = |
3482 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3472 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3483 DCHECK(it != picture_layers_.end()); | 3473 DCHECK(it != picture_layers_.end()); |
3484 picture_layers_.erase(it); | 3474 picture_layers_.erase(it); |
3485 } | 3475 } |
3486 | 3476 |
3487 } // namespace cc | 3477 } // namespace cc |
OLD | NEW |