| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1510 viewport_rect_for_tile_priority_ = | 1510 viewport_rect_for_tile_priority_ = |
| 1511 viewport_rect_for_tile_priority_in_view_space; | 1511 viewport_rect_for_tile_priority_in_view_space; |
| 1512 | 1512 |
| 1513 if (tile_priority_params_changed) { | 1513 if (tile_priority_params_changed) { |
| 1514 active_tree_->set_needs_update_draw_properties(); | 1514 active_tree_->set_needs_update_draw_properties(); |
| 1515 if (pending_tree_) | 1515 if (pending_tree_) |
| 1516 pending_tree_->set_needs_update_draw_properties(); | 1516 pending_tree_->set_needs_update_draw_properties(); |
| 1517 | 1517 |
| 1518 // Compositor, not OutputSurface, is responsible for setting damage and | 1518 // Compositor, not OutputSurface, is responsible for setting damage and |
| 1519 // triggering redraw for constraint changes. | 1519 // triggering redraw for constraint changes. |
| 1520 SetFullRootLayerDamage(); | 1520 SetFullViewportDamage(); |
| 1521 SetNeedsRedraw(); | 1521 SetNeedsRedraw(); |
| 1522 } | 1522 } |
| 1523 } | 1523 } |
| 1524 | 1524 |
| 1525 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { | 1525 void LayerTreeHostImpl::SetNeedsRedrawRect(const gfx::Rect& damage_rect) { |
| 1526 if (damage_rect.IsEmpty()) | 1526 if (damage_rect.IsEmpty()) |
| 1527 return; | 1527 return; |
| 1528 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1528 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
| 1529 client_->SetNeedsRedrawRectOnImplThread(damage_rect); | 1529 client_->SetNeedsRedrawRectOnImplThread(damage_rect); |
| 1530 } | 1530 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 external_viewport_ = viewport; | 1582 external_viewport_ = viewport; |
| 1583 | 1583 |
| 1584 { | 1584 { |
| 1585 base::AutoReset<bool> resourceless_software_draw_reset( | 1585 base::AutoReset<bool> resourceless_software_draw_reset( |
| 1586 &resourceless_software_draw_, resourceless_software_draw); | 1586 &resourceless_software_draw_, resourceless_software_draw); |
| 1587 | 1587 |
| 1588 // For resourceless software draw, always set full damage to ensure they | 1588 // For resourceless software draw, always set full damage to ensure they |
| 1589 // always swap. Otherwise, need to set redraw for any changes to draw | 1589 // always swap. Otherwise, need to set redraw for any changes to draw |
| 1590 // parameters. | 1590 // parameters. |
| 1591 if (transform_changed || viewport_changed || resourceless_software_draw_) { | 1591 if (transform_changed || viewport_changed || resourceless_software_draw_) { |
| 1592 SetFullRootLayerDamage(); | 1592 SetFullViewportDamage(); |
| 1593 SetNeedsRedraw(); | 1593 SetNeedsRedraw(); |
| 1594 active_tree_->set_needs_update_draw_properties(); | 1594 active_tree_->set_needs_update_draw_properties(); |
| 1595 } | 1595 } |
| 1596 | 1596 |
| 1597 if (resourceless_software_draw) { | 1597 if (resourceless_software_draw) { |
| 1598 client_->OnCanDrawStateChanged(CanDraw()); | 1598 client_->OnCanDrawStateChanged(CanDraw()); |
| 1599 } | 1599 } |
| 1600 | 1600 |
| 1601 client_->OnDrawForOutputSurface(resourceless_software_draw_); | 1601 client_->OnDrawForOutputSurface(resourceless_software_draw_); |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 if (resourceless_software_draw) { | 1604 if (resourceless_software_draw) { |
| 1605 active_tree_->set_needs_update_draw_properties(); | 1605 active_tree_->set_needs_update_draw_properties(); |
| 1606 client_->OnCanDrawStateChanged(CanDraw()); | 1606 client_->OnCanDrawStateChanged(CanDraw()); |
| 1607 // This draw may have reset all damage, which would lead to subsequent | 1607 // This draw may have reset all damage, which would lead to subsequent |
| 1608 // incorrect hardware draw, so explicitly set damage for next hardware | 1608 // incorrect hardware draw, so explicitly set damage for next hardware |
| 1609 // draw as well. | 1609 // draw as well. |
| 1610 SetFullRootLayerDamage(); | 1610 SetFullViewportDamage(); |
| 1611 } | 1611 } |
| 1612 } | 1612 } |
| 1613 | 1613 |
| 1614 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { | 1614 void LayerTreeHostImpl::OnCanDrawStateChangedForTree() { |
| 1615 client_->OnCanDrawStateChanged(CanDraw()); | 1615 client_->OnCanDrawStateChanged(CanDraw()); |
| 1616 } | 1616 } |
| 1617 | 1617 |
| 1618 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { | 1618 CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() const { |
| 1619 CompositorFrameMetadata metadata; | 1619 CompositorFrameMetadata metadata; |
| 1620 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() * | 1620 metadata.device_scale_factor = active_tree_->painted_device_scale_factor() * |
| (...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 DidVisibilityChange(this, visible_); | 2087 DidVisibilityChange(this, visible_); |
| 2088 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | 2088 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
| 2089 | 2089 |
| 2090 // If we just became visible, we have to ensure that we draw high res tiles, | 2090 // If we just became visible, we have to ensure that we draw high res tiles, |
| 2091 // to prevent checkerboard/low res flashes. | 2091 // to prevent checkerboard/low res flashes. |
| 2092 if (visible_) { | 2092 if (visible_) { |
| 2093 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. | 2093 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. |
| 2094 SetRequiresHighResToDraw(); | 2094 SetRequiresHighResToDraw(); |
| 2095 } else { | 2095 } else { |
| 2096 EvictAllUIResources(); | 2096 EvictAllUIResources(); |
| 2097 // Call PrepareTiles to evict tiles when we become invisible. |
| 2098 PrepareTiles(); |
| 2097 } | 2099 } |
| 2098 | 2100 |
| 2099 // Call PrepareTiles to evict tiles when we become invisible. | |
| 2100 if (!visible) | |
| 2101 PrepareTiles(); | |
| 2102 | |
| 2103 // Update visibility for the compositor context provider. | 2101 // Update visibility for the compositor context provider. |
| 2104 if (output_surface_) { | 2102 if (output_surface_) { |
| 2105 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), | 2103 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), |
| 2106 visible); | 2104 visible); |
| 2107 } | 2105 } |
| 2108 } | 2106 } |
| 2109 | 2107 |
| 2110 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { | 2108 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { |
| 2111 // TODO(miletus): This is just the compositor-thread-side call to the | 2109 // TODO(miletus): This is just the compositor-thread-side call to the |
| 2112 // SwapPromiseMonitor to say something happened that may cause a swap in the | 2110 // SwapPromiseMonitor to say something happened that may cause a swap in the |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2154 recycle_tree_->RecreateResources(); | 2152 recycle_tree_->RecreateResources(); |
| 2155 } | 2153 } |
| 2156 | 2154 |
| 2157 void LayerTreeHostImpl::CreateAndSetRenderer() { | 2155 void LayerTreeHostImpl::CreateAndSetRenderer() { |
| 2158 DCHECK(!renderer_); | 2156 DCHECK(!renderer_); |
| 2159 DCHECK(output_surface_); | 2157 DCHECK(output_surface_); |
| 2160 DCHECK(resource_provider_); | 2158 DCHECK(resource_provider_); |
| 2161 | 2159 |
| 2162 DCHECK(output_surface_->capabilities().delegated_rendering); | 2160 DCHECK(output_surface_->capabilities().delegated_rendering); |
| 2163 renderer_ = base::MakeUnique<DelegatingRenderer>( | 2161 renderer_ = base::MakeUnique<DelegatingRenderer>( |
| 2164 this, &settings_.renderer_settings, output_surface_, | 2162 &settings_.renderer_settings, output_surface_, resource_provider_.get()); |
| 2165 resource_provider_.get()); | |
| 2166 renderer_->SetVisible(visible_); | 2163 renderer_->SetVisible(visible_); |
| 2167 SetFullRootLayerDamage(); | 2164 SetFullViewportDamage(); |
| 2168 | 2165 |
| 2169 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be | 2166 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be |
| 2170 // initialized to get max texture size. Also, after releasing resources, | 2167 // initialized to get max texture size. Also, after releasing resources, |
| 2171 // trees need another update to generate new ones. | 2168 // trees need another update to generate new ones. |
| 2172 active_tree_->set_needs_update_draw_properties(); | 2169 active_tree_->set_needs_update_draw_properties(); |
| 2173 if (pending_tree_) | 2170 if (pending_tree_) |
| 2174 pending_tree_->set_needs_update_draw_properties(); | 2171 pending_tree_->set_needs_update_draw_properties(); |
| 2175 client_->UpdateRendererCapabilitiesOnImplThread(); | 2172 client_->UpdateRendererCapabilitiesOnImplThread(); |
| 2176 } | 2173 } |
| 2177 | 2174 |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2405 device_viewport_size.width(), "height", | 2402 device_viewport_size.width(), "height", |
| 2406 device_viewport_size.height()); | 2403 device_viewport_size.height()); |
| 2407 | 2404 |
| 2408 if (pending_tree_) | 2405 if (pending_tree_) |
| 2409 active_tree_->SetViewportSizeInvalid(); | 2406 active_tree_->SetViewportSizeInvalid(); |
| 2410 | 2407 |
| 2411 device_viewport_size_ = device_viewport_size; | 2408 device_viewport_size_ = device_viewport_size; |
| 2412 | 2409 |
| 2413 UpdateViewportContainerSizes(); | 2410 UpdateViewportContainerSizes(); |
| 2414 client_->OnCanDrawStateChanged(CanDraw()); | 2411 client_->OnCanDrawStateChanged(CanDraw()); |
| 2415 SetFullRootLayerDamage(); | 2412 SetFullViewportDamage(); |
| 2416 active_tree_->set_needs_update_draw_properties(); | 2413 active_tree_->set_needs_update_draw_properties(); |
| 2417 } | 2414 } |
| 2418 | 2415 |
| 2419 const gfx::Rect LayerTreeHostImpl::ViewportRectForTilePriority() const { | 2416 const gfx::Rect LayerTreeHostImpl::ViewportRectForTilePriority() const { |
| 2420 if (viewport_rect_for_tile_priority_.IsEmpty()) | 2417 if (viewport_rect_for_tile_priority_.IsEmpty()) |
| 2421 return DeviceViewport(); | 2418 return DeviceViewport(); |
| 2422 | 2419 |
| 2423 return viewport_rect_for_tile_priority_; | 2420 return viewport_rect_for_tile_priority_; |
| 2424 } | 2421 } |
| 2425 | 2422 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2436 | 2433 |
| 2437 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { | 2434 const gfx::Transform& LayerTreeHostImpl::DrawTransform() const { |
| 2438 return external_transform_; | 2435 return external_transform_; |
| 2439 } | 2436 } |
| 2440 | 2437 |
| 2441 void LayerTreeHostImpl::DidChangeTopControlsPosition() { | 2438 void LayerTreeHostImpl::DidChangeTopControlsPosition() { |
| 2442 UpdateViewportContainerSizes(); | 2439 UpdateViewportContainerSizes(); |
| 2443 SetNeedsRedraw(); | 2440 SetNeedsRedraw(); |
| 2444 SetNeedsOneBeginImplFrame(); | 2441 SetNeedsOneBeginImplFrame(); |
| 2445 active_tree_->set_needs_update_draw_properties(); | 2442 active_tree_->set_needs_update_draw_properties(); |
| 2446 SetFullRootLayerDamage(); | 2443 SetFullViewportDamage(); |
| 2447 } | 2444 } |
| 2448 | 2445 |
| 2449 float LayerTreeHostImpl::TopControlsHeight() const { | 2446 float LayerTreeHostImpl::TopControlsHeight() const { |
| 2450 return active_tree_->top_controls_height(); | 2447 return active_tree_->top_controls_height(); |
| 2451 } | 2448 } |
| 2452 | 2449 |
| 2453 void LayerTreeHostImpl::SetCurrentTopControlsShownRatio(float ratio) { | 2450 void LayerTreeHostImpl::SetCurrentTopControlsShownRatio(float ratio) { |
| 2454 if (active_tree_->SetCurrentTopControlsShownRatio(ratio)) | 2451 if (active_tree_->SetCurrentTopControlsShownRatio(ratio)) |
| 2455 DidChangeTopControlsPosition(); | 2452 DidChangeTopControlsPosition(); |
| 2456 } | 2453 } |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3210 void LayerTreeHostImpl::SetSynchronousInputHandlerRootScrollOffset( | 3207 void LayerTreeHostImpl::SetSynchronousInputHandlerRootScrollOffset( |
| 3211 const gfx::ScrollOffset& root_offset) { | 3208 const gfx::ScrollOffset& root_offset) { |
| 3212 bool changed = active_tree_->DistributeRootScrollOffset(root_offset); | 3209 bool changed = active_tree_->DistributeRootScrollOffset(root_offset); |
| 3213 if (!changed) | 3210 if (!changed) |
| 3214 return; | 3211 return; |
| 3215 | 3212 |
| 3216 client_->SetNeedsCommitOnImplThread(); | 3213 client_->SetNeedsCommitOnImplThread(); |
| 3217 // After applying the synchronous input handler's scroll offset, tell it what | 3214 // After applying the synchronous input handler's scroll offset, tell it what |
| 3218 // we ended up with. | 3215 // we ended up with. |
| 3219 UpdateRootLayerStateForSynchronousInputHandler(); | 3216 UpdateRootLayerStateForSynchronousInputHandler(); |
| 3220 SetFullRootLayerDamage(); | 3217 SetFullViewportDamage(); |
| 3221 SetNeedsRedraw(); | 3218 SetNeedsRedraw(); |
| 3222 } | 3219 } |
| 3223 | 3220 |
| 3224 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { | 3221 void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() { |
| 3225 active_tree_->ClearCurrentlyScrollingLayer(); | 3222 active_tree_->ClearCurrentlyScrollingLayer(); |
| 3226 did_lock_scrolling_layer_ = false; | 3223 did_lock_scrolling_layer_ = false; |
| 3227 scroll_affects_scroll_handler_ = false; | 3224 scroll_affects_scroll_handler_ = false; |
| 3228 accumulated_root_overscroll_ = gfx::Vector2dF(); | 3225 accumulated_root_overscroll_ = gfx::Vector2dF(); |
| 3229 } | 3226 } |
| 3230 | 3227 |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3396 active_tree_->page_scale_factor()->PullDeltaForMainThread(); | 3393 active_tree_->page_scale_factor()->PullDeltaForMainThread(); |
| 3397 scroll_info->top_controls_delta = | 3394 scroll_info->top_controls_delta = |
| 3398 active_tree()->top_controls_shown_ratio()->PullDeltaForMainThread(); | 3395 active_tree()->top_controls_shown_ratio()->PullDeltaForMainThread(); |
| 3399 scroll_info->elastic_overscroll_delta = | 3396 scroll_info->elastic_overscroll_delta = |
| 3400 active_tree_->elastic_overscroll()->PullDeltaForMainThread(); | 3397 active_tree_->elastic_overscroll()->PullDeltaForMainThread(); |
| 3401 scroll_info->swap_promises.swap(swap_promises_for_main_thread_scroll_update_); | 3398 scroll_info->swap_promises.swap(swap_promises_for_main_thread_scroll_update_); |
| 3402 | 3399 |
| 3403 return scroll_info; | 3400 return scroll_info; |
| 3404 } | 3401 } |
| 3405 | 3402 |
| 3406 void LayerTreeHostImpl::SetFullRootLayerDamage() { | 3403 void LayerTreeHostImpl::SetFullViewportDamage() { |
| 3407 SetViewportDamage(gfx::Rect(DrawViewportSize())); | 3404 SetViewportDamage(gfx::Rect(DrawViewportSize())); |
| 3408 } | 3405 } |
| 3409 | 3406 |
| 3410 void LayerTreeHostImpl::ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta) { | 3407 void LayerTreeHostImpl::ScrollViewportInnerFirst(gfx::Vector2dF scroll_delta) { |
| 3411 DCHECK(InnerViewportScrollLayer()); | 3408 DCHECK(InnerViewportScrollLayer()); |
| 3412 LayerImpl* scroll_layer = InnerViewportScrollLayer(); | 3409 LayerImpl* scroll_layer = InnerViewportScrollLayer(); |
| 3413 | 3410 |
| 3414 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); | 3411 gfx::Vector2dF unused_delta = scroll_layer->ScrollBy(scroll_delta); |
| 3415 if (!unused_delta.IsZero() && OuterViewportScrollLayer()) | 3412 if (!unused_delta.IsZero() && OuterViewportScrollLayer()) |
| 3416 OuterViewportScrollLayer()->ScrollBy(unused_delta); | 3413 OuterViewportScrollLayer()->ScrollBy(unused_delta); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3685 state->EndDictionary(); | 3682 state->EndDictionary(); |
| 3686 } | 3683 } |
| 3687 | 3684 |
| 3688 void LayerTreeHostImpl::SetDebugState( | 3685 void LayerTreeHostImpl::SetDebugState( |
| 3689 const LayerTreeDebugState& new_debug_state) { | 3686 const LayerTreeDebugState& new_debug_state) { |
| 3690 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) | 3687 if (LayerTreeDebugState::Equal(debug_state_, new_debug_state)) |
| 3691 return; | 3688 return; |
| 3692 | 3689 |
| 3693 debug_state_ = new_debug_state; | 3690 debug_state_ = new_debug_state; |
| 3694 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | 3691 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
| 3695 SetFullRootLayerDamage(); | 3692 SetFullViewportDamage(); |
| 3696 } | 3693 } |
| 3697 | 3694 |
| 3698 void LayerTreeHostImpl::CreateUIResource(UIResourceId uid, | 3695 void LayerTreeHostImpl::CreateUIResource(UIResourceId uid, |
| 3699 const UIResourceBitmap& bitmap) { | 3696 const UIResourceBitmap& bitmap) { |
| 3700 DCHECK_GT(uid, 0); | 3697 DCHECK_GT(uid, 0); |
| 3701 | 3698 |
| 3702 // Allow for multiple creation requests with the same UIResourceId. The | 3699 // Allow for multiple creation requests with the same UIResourceId. The |
| 3703 // previous resource is simply deleted. | 3700 // previous resource is simply deleted. |
| 3704 ResourceId id = ResourceIdForUIResource(uid); | 3701 ResourceId id = ResourceIdForUIResource(uid); |
| 3705 if (id) | 3702 if (id) |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4066 return task_runner_provider_->HasImplThread(); | 4063 return task_runner_provider_->HasImplThread(); |
| 4067 } | 4064 } |
| 4068 | 4065 |
| 4069 bool LayerTreeHostImpl::CommitToActiveTree() const { | 4066 bool LayerTreeHostImpl::CommitToActiveTree() const { |
| 4070 // In single threaded mode we skip the pending tree and commit directly to the | 4067 // In single threaded mode we skip the pending tree and commit directly to the |
| 4071 // active tree. | 4068 // active tree. |
| 4072 return !task_runner_provider_->HasImplThread(); | 4069 return !task_runner_provider_->HasImplThread(); |
| 4073 } | 4070 } |
| 4074 | 4071 |
| 4075 } // namespace cc | 4072 } // namespace cc |
| OLD | NEW |