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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 SetDebugState(settings.initial_debug_state); | 252 SetDebugState(settings.initial_debug_state); |
253 | 253 |
254 // LTHI always has an active tree. | 254 // LTHI always has an active tree. |
255 active_tree_ = LayerTreeImpl::create(this); | 255 active_tree_ = LayerTreeImpl::create(this); |
256 TRACE_EVENT_OBJECT_CREATED_WITH_ID( | 256 TRACE_EVENT_OBJECT_CREATED_WITH_ID( |
257 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); | 257 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); |
258 | 258 |
259 if (settings.calculate_top_controls_position) { | 259 if (settings.calculate_top_controls_position) { |
260 top_controls_manager_ = | 260 top_controls_manager_ = |
261 TopControlsManager::Create(this, | 261 TopControlsManager::Create(this, |
262 settings.top_controls_height, | |
263 settings.top_controls_show_threshold, | 262 settings.top_controls_show_threshold, |
264 settings.top_controls_hide_threshold); | 263 settings.top_controls_hide_threshold); |
265 | |
266 // TODO(bokan): This is a quick fix. The browser should lock the top | |
267 // controls to shown on creation but this appears not to work. Tracked | |
268 // in crbug.com/417680. | |
269 // Initialize with top controls showing. | |
270 SetControlsTopOffset(0.f); | |
271 } | 264 } |
272 } | 265 } |
273 | 266 |
274 LayerTreeHostImpl::~LayerTreeHostImpl() { | 267 LayerTreeHostImpl::~LayerTreeHostImpl() { |
275 DCHECK(proxy_->IsImplThread()); | 268 DCHECK(proxy_->IsImplThread()); |
276 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); | 269 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
277 TRACE_EVENT_OBJECT_DELETED_WITH_ID( | 270 TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
278 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); | 271 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerTreeHostImpl", id_); |
279 | 272 |
280 if (input_handler_client_) { | 273 if (input_handler_client_) { |
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1669 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); | 1662 LayerImpl* outer_container = active_tree_->OuterViewportContainerLayer(); |
1670 | 1663 |
1671 if (!inner_container || !top_controls_manager_) | 1664 if (!inner_container || !top_controls_manager_) |
1672 return; | 1665 return; |
1673 | 1666 |
1674 ViewportAnchor anchor(InnerViewportScrollLayer(), | 1667 ViewportAnchor anchor(InnerViewportScrollLayer(), |
1675 OuterViewportScrollLayer()); | 1668 OuterViewportScrollLayer()); |
1676 | 1669 |
1677 // Adjust the inner viewport by shrinking/expanding the container to account | 1670 // Adjust the inner viewport by shrinking/expanding the container to account |
1678 // for the change in top controls height since the last Resize from Blink. | 1671 // for the change in top controls height since the last Resize from Blink. |
| 1672 float top_controls_layout_height = |
| 1673 active_tree_->top_controls_shrink_blink_size() |
| 1674 ? active_tree_->top_controls_height() |
| 1675 : 0.f; |
1679 inner_container->SetBoundsDelta( | 1676 inner_container->SetBoundsDelta( |
1680 gfx::Vector2dF(0, active_tree_->top_controls_layout_height() - | 1677 gfx::Vector2dF(0, top_controls_layout_height - |
1681 active_tree_->total_top_controls_content_offset())); | 1678 active_tree_->total_top_controls_content_offset())); |
1682 | 1679 |
1683 if (!outer_container || outer_container->BoundsForScrolling().IsEmpty()) | 1680 if (!outer_container || outer_container->BoundsForScrolling().IsEmpty()) |
1684 return; | 1681 return; |
1685 | 1682 |
1686 // Adjust the outer viewport container as well, since adjusting only the | 1683 // Adjust the outer viewport container as well, since adjusting only the |
1687 // inner may cause its bounds to exceed those of the outer, causing scroll | 1684 // inner may cause its bounds to exceed those of the outer, causing scroll |
1688 // clamping. We adjust it so it maintains the same aspect ratio as the | 1685 // clamping. We adjust it so it maintains the same aspect ratio as the |
1689 // inner viewport. | 1686 // inner viewport. |
1690 float aspect_ratio = inner_container->BoundsForScrolling().width() / | 1687 float aspect_ratio = inner_container->BoundsForScrolling().width() / |
1691 inner_container->BoundsForScrolling().height(); | 1688 inner_container->BoundsForScrolling().height(); |
1692 float target_height = outer_container->BoundsForScrolling().width() / | 1689 float target_height = outer_container->BoundsForScrolling().width() / |
1693 aspect_ratio; | 1690 aspect_ratio; |
1694 float current_outer_height = outer_container->BoundsForScrolling().height() - | 1691 float current_outer_height = outer_container->BoundsForScrolling().height() - |
1695 outer_container->bounds_delta().y(); | 1692 outer_container->bounds_delta().y(); |
1696 gfx::Vector2dF delta(0, target_height - current_outer_height); | 1693 gfx::Vector2dF delta(0, target_height - current_outer_height); |
1697 | 1694 |
1698 outer_container->SetBoundsDelta(delta); | 1695 outer_container->SetBoundsDelta(delta); |
1699 active_tree_->InnerViewportScrollLayer()->SetBoundsDelta(delta); | 1696 active_tree_->InnerViewportScrollLayer()->SetBoundsDelta(delta); |
1700 | 1697 |
1701 anchor.ResetViewportToAnchoredPosition(); | 1698 anchor.ResetViewportToAnchoredPosition(); |
1702 } | 1699 } |
1703 | 1700 |
1704 void LayerTreeHostImpl::SetTopControlsLayoutHeight(float height) { | |
1705 if (active_tree_->top_controls_layout_height() == height) | |
1706 return; | |
1707 | |
1708 active_tree_->set_top_controls_layout_height(height); | |
1709 UpdateViewportContainerSizes(); | |
1710 SetFullRootLayerDamage(); | |
1711 } | |
1712 | |
1713 void LayerTreeHostImpl::SynchronouslyInitializeAllTiles() { | 1701 void LayerTreeHostImpl::SynchronouslyInitializeAllTiles() { |
1714 // Only valid for the single-threaded non-scheduled/synchronous case | 1702 // Only valid for the single-threaded non-scheduled/synchronous case |
1715 // using the zero copy raster worker pool. | 1703 // using the zero copy raster worker pool. |
1716 single_thread_synchronous_task_graph_runner_->RunUntilIdle(); | 1704 single_thread_synchronous_task_graph_runner_->RunUntilIdle(); |
1717 } | 1705 } |
1718 | 1706 |
1719 void LayerTreeHostImpl::DidLoseOutputSurface() { | 1707 void LayerTreeHostImpl::DidLoseOutputSurface() { |
1720 if (resource_provider_) | 1708 if (resource_provider_) |
1721 resource_provider_->DidLoseOutputSurface(); | 1709 resource_provider_->DidLoseOutputSurface(); |
1722 client_->DidLoseOutputSurfaceOnImplThread(); | 1710 client_->DidLoseOutputSurfaceOnImplThread(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1777 | 1765 |
1778 // Update the delta from the active tree, which may have | 1766 // Update the delta from the active tree, which may have |
1779 // adjusted its delta prior to the pending tree being created. | 1767 // adjusted its delta prior to the pending tree being created. |
1780 DCHECK_EQ(1.f, pending_tree_->sent_page_scale_delta()); | 1768 DCHECK_EQ(1.f, pending_tree_->sent_page_scale_delta()); |
1781 DCHECK_EQ(0.f, pending_tree_->sent_top_controls_delta()); | 1769 DCHECK_EQ(0.f, pending_tree_->sent_top_controls_delta()); |
1782 pending_tree_->SetPageScaleDelta(active_tree_->page_scale_delta() / | 1770 pending_tree_->SetPageScaleDelta(active_tree_->page_scale_delta() / |
1783 active_tree_->sent_page_scale_delta()); | 1771 active_tree_->sent_page_scale_delta()); |
1784 pending_tree_->set_top_controls_delta( | 1772 pending_tree_->set_top_controls_delta( |
1785 active_tree_->top_controls_delta() - | 1773 active_tree_->top_controls_delta() - |
1786 active_tree_->sent_top_controls_delta()); | 1774 active_tree_->sent_top_controls_delta()); |
| 1775 pending_tree_->set_top_controls_height(active_tree_->top_controls_height()); |
1787 | 1776 |
1788 client_->OnCanDrawStateChanged(CanDraw()); | 1777 client_->OnCanDrawStateChanged(CanDraw()); |
1789 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree:waiting", pending_tree_.get()); | 1778 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree:waiting", pending_tree_.get()); |
1790 } | 1779 } |
1791 | 1780 |
1792 void LayerTreeHostImpl::ActivateSyncTree() { | 1781 void LayerTreeHostImpl::ActivateSyncTree() { |
1793 if (pending_tree_) { | 1782 if (pending_tree_) { |
1794 TRACE_EVENT_ASYNC_END0("cc", "PendingTree:waiting", pending_tree_.get()); | 1783 TRACE_EVENT_ASYNC_END0("cc", "PendingTree:waiting", pending_tree_.get()); |
1795 | 1784 |
1796 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); | 1785 active_tree_->SetRootLayerScrollOffsetDelegate(NULL); |
(...skipping 16 matching lines...) Expand all Loading... |
1813 // Now that we've synced everything from the pending tree to the active | 1802 // Now that we've synced everything from the pending tree to the active |
1814 // tree, rename the pending tree the recycle tree so we can reuse it on the | 1803 // tree, rename the pending tree the recycle tree so we can reuse it on the |
1815 // next sync. | 1804 // next sync. |
1816 DCHECK(!recycle_tree_); | 1805 DCHECK(!recycle_tree_); |
1817 pending_tree_.swap(recycle_tree_); | 1806 pending_tree_.swap(recycle_tree_); |
1818 | 1807 |
1819 active_tree_->SetRootLayerScrollOffsetDelegate( | 1808 active_tree_->SetRootLayerScrollOffsetDelegate( |
1820 root_layer_scroll_offset_delegate_); | 1809 root_layer_scroll_offset_delegate_); |
1821 | 1810 |
1822 if (top_controls_manager_) { | 1811 if (top_controls_manager_) { |
| 1812 top_controls_manager_->SetTopControlsHeight( |
| 1813 active_tree_->top_controls_height()); |
1823 top_controls_manager_->SetControlsTopOffset( | 1814 top_controls_manager_->SetControlsTopOffset( |
1824 active_tree_->total_top_controls_content_offset() - | 1815 active_tree_->total_top_controls_content_offset() - |
1825 top_controls_manager_->top_controls_height()); | 1816 active_tree_->top_controls_height()); |
1826 } | 1817 } |
1827 | 1818 |
1828 UpdateViewportContainerSizes(); | 1819 UpdateViewportContainerSizes(); |
1829 } else { | 1820 } else { |
1830 active_tree_->ProcessUIResourceRequestQueue(); | 1821 active_tree_->ProcessUIResourceRequestQueue(); |
1831 } | 1822 } |
1832 | 1823 |
1833 active_tree_->DidBecomeActive(); | 1824 active_tree_->DidBecomeActive(); |
1834 ActivateAnimations(); | 1825 ActivateAnimations(); |
1835 if (settings_.impl_side_painting) | 1826 if (settings_.impl_side_painting) |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2275 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 2266 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
2276 UpdateViewportContainerSizes(); | 2267 UpdateViewportContainerSizes(); |
2277 SetNeedsRedraw(); | 2268 SetNeedsRedraw(); |
2278 SetNeedsAnimate(); | 2269 SetNeedsAnimate(); |
2279 active_tree_->set_needs_update_draw_properties(); | 2270 active_tree_->set_needs_update_draw_properties(); |
2280 SetFullRootLayerDamage(); | 2271 SetFullRootLayerDamage(); |
2281 } | 2272 } |
2282 | 2273 |
2283 void LayerTreeHostImpl::SetControlsTopOffset(float offset) { | 2274 void LayerTreeHostImpl::SetControlsTopOffset(float offset) { |
2284 float current_top_offset = active_tree_->top_controls_content_offset() - | 2275 float current_top_offset = active_tree_->top_controls_content_offset() - |
2285 top_controls_manager_->top_controls_height(); | 2276 active_tree_->top_controls_height(); |
2286 active_tree_->set_top_controls_delta(offset - current_top_offset); | 2277 active_tree_->set_top_controls_delta(offset - current_top_offset); |
2287 } | 2278 } |
2288 | 2279 |
2289 float LayerTreeHostImpl::ControlsTopOffset() const { | 2280 float LayerTreeHostImpl::ControlsTopOffset() const { |
2290 return active_tree_->total_top_controls_content_offset() - | 2281 return active_tree_->total_top_controls_content_offset() - |
2291 top_controls_manager_->top_controls_height(); | 2282 active_tree_->top_controls_height(); |
2292 } | 2283 } |
2293 | 2284 |
2294 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { | 2285 void LayerTreeHostImpl::BindToClient(InputHandlerClient* client) { |
2295 DCHECK(input_handler_client_ == NULL); | 2286 DCHECK(input_handler_client_ == NULL); |
2296 input_handler_client_ = client; | 2287 input_handler_client_ = client; |
2297 } | 2288 } |
2298 | 2289 |
2299 static LayerImpl* NextScrollLayer(LayerImpl* layer) { | 2290 static LayerImpl* NextScrollLayer(LayerImpl* layer) { |
2300 if (LayerImpl* scroll_parent = layer->scroll_parent()) | 2291 if (LayerImpl* scroll_parent = layer->scroll_parent()) |
2301 return scroll_parent; | 2292 return scroll_parent; |
(...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3491 } | 3482 } |
3492 | 3483 |
3493 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { | 3484 void LayerTreeHostImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
3494 std::vector<PictureLayerImpl*>::iterator it = | 3485 std::vector<PictureLayerImpl*>::iterator it = |
3495 std::find(picture_layers_.begin(), picture_layers_.end(), layer); | 3486 std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
3496 DCHECK(it != picture_layers_.end()); | 3487 DCHECK(it != picture_layers_.end()); |
3497 picture_layers_.erase(it); | 3488 picture_layers_.erase(it); |
3498 } | 3489 } |
3499 | 3490 |
3500 } // namespace cc | 3491 } // namespace cc |
OLD | NEW |