| 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 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 LayerTreeHostImplClient* client, | 165 LayerTreeHostImplClient* client, |
| 166 Proxy* proxy, | 166 Proxy* proxy, |
| 167 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 167 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 168 SharedBitmapManager* shared_bitmap_manager, | 168 SharedBitmapManager* shared_bitmap_manager, |
| 169 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 169 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 170 TaskGraphRunner* task_graph_runner, | 170 TaskGraphRunner* task_graph_runner, |
| 171 int id) | 171 int id) |
| 172 : client_(client), | 172 : client_(client), |
| 173 proxy_(proxy), | 173 proxy_(proxy), |
| 174 current_begin_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), | 174 current_begin_frame_tracker_(BEGINFRAMETRACKER_FROM_HERE), |
| 175 output_surface_(nullptr), | |
| 176 content_is_suitable_for_gpu_rasterization_(true), | 175 content_is_suitable_for_gpu_rasterization_(true), |
| 177 has_gpu_rasterization_trigger_(false), | 176 has_gpu_rasterization_trigger_(false), |
| 178 use_gpu_rasterization_(false), | 177 use_gpu_rasterization_(false), |
| 179 use_msaa_(false), | 178 use_msaa_(false), |
| 180 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), | 179 gpu_rasterization_status_(GpuRasterizationStatus::OFF_DEVICE), |
| 181 tree_resources_for_gpu_rasterization_dirty_(false), | 180 tree_resources_for_gpu_rasterization_dirty_(false), |
| 182 input_handler_client_(NULL), | 181 input_handler_client_(NULL), |
| 183 did_lock_scrolling_layer_(false), | 182 did_lock_scrolling_layer_(false), |
| 184 should_bubble_scrolls_(false), | 183 should_bubble_scrolls_(false), |
| 185 wheel_scrolling_(false), | 184 wheel_scrolling_(false), |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 recycle_tree_ = nullptr; | 278 recycle_tree_ = nullptr; |
| 280 pending_tree_ = nullptr; | 279 pending_tree_ = nullptr; |
| 281 active_tree_ = nullptr; | 280 active_tree_ = nullptr; |
| 282 | 281 |
| 283 if (animation_host_) { | 282 if (animation_host_) { |
| 284 animation_host_->ClearTimelines(); | 283 animation_host_->ClearTimelines(); |
| 285 animation_host_->SetMutatorHostClient(nullptr); | 284 animation_host_->SetMutatorHostClient(nullptr); |
| 286 } | 285 } |
| 287 | 286 |
| 288 CleanUpTileManager(); | 287 CleanUpTileManager(); |
| 289 renderer_ = nullptr; | |
| 290 resource_provider_ = nullptr; | |
| 291 | |
| 292 if (output_surface_) { | |
| 293 output_surface_->DetachFromClient(); | |
| 294 output_surface_ = nullptr; | |
| 295 } | |
| 296 } | 288 } |
| 297 | 289 |
| 298 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { | 290 void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { |
| 299 // If the begin frame data was handled, then scroll and scale set was applied | 291 // If the begin frame data was handled, then scroll and scale set was applied |
| 300 // by the main thread, so the active tree needs to be updated as if these sent | 292 // by the main thread, so the active tree needs to be updated as if these sent |
| 301 // values were applied and committed. | 293 // values were applied and committed. |
| 302 if (CommitEarlyOutHandledCommit(reason)) | 294 if (CommitEarlyOutHandledCommit(reason)) |
| 303 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); | 295 active_tree_->ApplySentScrollAndScaleDeltasFromAbortedCommit(); |
| 304 } | 296 } |
| 305 | 297 |
| (...skipping 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1563 } | 1555 } |
| 1564 | 1556 |
| 1565 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { | 1557 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
| 1566 bool disable_picture_quad_image_filtering = | 1558 bool disable_picture_quad_image_filtering = |
| 1567 IsActivelyScrolling() || | 1559 IsActivelyScrolling() || |
| 1568 (animation_host_ ? animation_host_->NeedsAnimateLayers() | 1560 (animation_host_ ? animation_host_->NeedsAnimateLayers() |
| 1569 : animation_registrar_->needs_animate_layers()); | 1561 : animation_registrar_->needs_animate_layers()); |
| 1570 | 1562 |
| 1571 scoped_ptr<SoftwareRenderer> temp_software_renderer = | 1563 scoped_ptr<SoftwareRenderer> temp_software_renderer = |
| 1572 SoftwareRenderer::Create(this, &settings_.renderer_settings, | 1564 SoftwareRenderer::Create(this, &settings_.renderer_settings, |
| 1573 output_surface_, NULL); | 1565 output_surface_.get(), NULL); |
| 1574 temp_software_renderer->DrawFrame(&frame->render_passes, | 1566 temp_software_renderer->DrawFrame(&frame->render_passes, |
| 1575 device_scale_factor_, | 1567 device_scale_factor_, |
| 1576 DeviceViewport(), | 1568 DeviceViewport(), |
| 1577 DeviceClip(), | 1569 DeviceClip(), |
| 1578 disable_picture_quad_image_filtering); | 1570 disable_picture_quad_image_filtering); |
| 1579 } else { | 1571 } else { |
| 1580 renderer_->DrawFrame(&frame->render_passes, | 1572 renderer_->DrawFrame(&frame->render_passes, |
| 1581 device_scale_factor_, | 1573 device_scale_factor_, |
| 1582 DeviceViewport(), | 1574 DeviceViewport(), |
| 1583 DeviceClip(), | 1575 DeviceClip(), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1625 return settings_.gpu_rasterization_msaa_sample_count; | 1617 return settings_.gpu_rasterization_msaa_sample_count; |
| 1626 } | 1618 } |
| 1627 | 1619 |
| 1628 bool LayerTreeHostImpl::CanUseGpuRasterization() { | 1620 bool LayerTreeHostImpl::CanUseGpuRasterization() { |
| 1629 if (!(output_surface_ && output_surface_->context_provider() && | 1621 if (!(output_surface_ && output_surface_->context_provider() && |
| 1630 output_surface_->worker_context_provider())) | 1622 output_surface_->worker_context_provider())) |
| 1631 return false; | 1623 return false; |
| 1632 | 1624 |
| 1633 ContextProvider* context_provider = | 1625 ContextProvider* context_provider = |
| 1634 output_surface_->worker_context_provider(); | 1626 output_surface_->worker_context_provider(); |
| 1635 ContextProvider::ScopedContextLock scoped_context(context_provider); | 1627 base::AutoLock context_lock(*context_provider->GetLock()); |
| 1636 if (!context_provider->GrContext()) | 1628 if (!context_provider->GrContext()) |
| 1637 return false; | 1629 return false; |
| 1638 | 1630 |
| 1639 return true; | 1631 return true; |
| 1640 } | 1632 } |
| 1641 | 1633 |
| 1642 void LayerTreeHostImpl::UpdateGpuRasterizationStatus() { | 1634 void LayerTreeHostImpl::UpdateGpuRasterizationStatus() { |
| 1643 bool use_gpu = false; | 1635 bool use_gpu = false; |
| 1644 bool use_msaa = false; | 1636 bool use_msaa = false; |
| 1645 bool using_msaa_for_complex_content = | 1637 bool using_msaa_for_complex_content = |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2009 if (recycle_tree_) | 2001 if (recycle_tree_) |
| 2010 recycle_tree_->RecreateResources(); | 2002 recycle_tree_->RecreateResources(); |
| 2011 } | 2003 } |
| 2012 | 2004 |
| 2013 void LayerTreeHostImpl::CreateAndSetRenderer() { | 2005 void LayerTreeHostImpl::CreateAndSetRenderer() { |
| 2014 DCHECK(!renderer_); | 2006 DCHECK(!renderer_); |
| 2015 DCHECK(output_surface_); | 2007 DCHECK(output_surface_); |
| 2016 DCHECK(resource_provider_); | 2008 DCHECK(resource_provider_); |
| 2017 | 2009 |
| 2018 if (output_surface_->capabilities().delegated_rendering) { | 2010 if (output_surface_->capabilities().delegated_rendering) { |
| 2019 renderer_ = | 2011 renderer_ = DelegatingRenderer::Create(this, &settings_.renderer_settings, |
| 2020 DelegatingRenderer::Create(this, &settings_.renderer_settings, | 2012 output_surface_.get(), |
| 2021 output_surface_, resource_provider_.get()); | 2013 resource_provider_.get()); |
| 2022 } else if (output_surface_->context_provider()) { | 2014 } else if (output_surface_->context_provider()) { |
| 2023 renderer_ = GLRenderer::Create( | 2015 renderer_ = GLRenderer::Create( |
| 2024 this, &settings_.renderer_settings, output_surface_, | 2016 this, &settings_.renderer_settings, output_surface_.get(), |
| 2025 resource_provider_.get(), texture_mailbox_deleter_.get(), | 2017 resource_provider_.get(), texture_mailbox_deleter_.get(), |
| 2026 settings_.renderer_settings.highp_threshold_min); | 2018 settings_.renderer_settings.highp_threshold_min); |
| 2027 } else if (output_surface_->software_device()) { | 2019 } else if (output_surface_->software_device()) { |
| 2028 renderer_ = | 2020 renderer_ = SoftwareRenderer::Create(this, &settings_.renderer_settings, |
| 2029 SoftwareRenderer::Create(this, &settings_.renderer_settings, | 2021 output_surface_.get(), |
| 2030 output_surface_, resource_provider_.get()); | 2022 resource_provider_.get()); |
| 2031 } | 2023 } |
| 2032 DCHECK(renderer_); | 2024 DCHECK(renderer_); |
| 2033 | 2025 |
| 2034 renderer_->SetVisible(visible_); | 2026 renderer_->SetVisible(visible_); |
| 2035 SetFullRootLayerDamage(); | 2027 SetFullRootLayerDamage(); |
| 2036 | 2028 |
| 2037 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be | 2029 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be |
| 2038 // initialized to get max texture size. Also, after releasing resources, | 2030 // initialized to get max texture size. Also, after releasing resources, |
| 2039 // trees need another update to generate new ones. | 2031 // trees need another update to generate new ones. |
| 2040 active_tree_->set_needs_update_draw_properties(); | 2032 active_tree_->set_needs_update_draw_properties(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2149 main_frame_events.Pass()); | 2141 main_frame_events.Pass()); |
| 2150 } | 2142 } |
| 2151 | 2143 |
| 2152 void LayerTreeHostImpl::CleanUpTileManager() { | 2144 void LayerTreeHostImpl::CleanUpTileManager() { |
| 2153 tile_manager_->FinishTasksAndCleanUp(); | 2145 tile_manager_->FinishTasksAndCleanUp(); |
| 2154 resource_pool_ = nullptr; | 2146 resource_pool_ = nullptr; |
| 2155 tile_task_worker_pool_ = nullptr; | 2147 tile_task_worker_pool_ = nullptr; |
| 2156 single_thread_synchronous_task_graph_runner_ = nullptr; | 2148 single_thread_synchronous_task_graph_runner_ = nullptr; |
| 2157 } | 2149 } |
| 2158 | 2150 |
| 2159 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { | 2151 bool LayerTreeHostImpl::InitializeRenderer( |
| 2152 scoped_ptr<OutputSurface> output_surface) { |
| 2160 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2153 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
| 2161 | 2154 |
| 2162 // Since we will create a new resource provider, we cannot continue to use | 2155 // Since we will create a new resource provider, we cannot continue to use |
| 2163 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2156 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
| 2164 // before we destroy the old resource provider. | 2157 // before we destroy the old resource provider. |
| 2165 ReleaseTreeResources(); | 2158 ReleaseTreeResources(); |
| 2166 | 2159 |
| 2167 // Note: order is important here. | 2160 // Note: order is important here. |
| 2168 renderer_ = nullptr; | 2161 renderer_ = nullptr; |
| 2169 CleanUpTileManager(); | 2162 CleanUpTileManager(); |
| 2170 resource_provider_ = nullptr; | 2163 resource_provider_ = nullptr; |
| 2171 | 2164 output_surface_ = nullptr; |
| 2172 // Detach from the old output surface and reset |output_surface_| pointer | |
| 2173 // as this surface is going to be destroyed independent of if binding the | |
| 2174 // new output surface succeeds or not. | |
| 2175 if (output_surface_) { | |
| 2176 output_surface_->DetachFromClient(); | |
| 2177 output_surface_ = nullptr; | |
| 2178 } | |
| 2179 | 2165 |
| 2180 if (!output_surface->BindToClient(this)) { | 2166 if (!output_surface->BindToClient(this)) { |
| 2181 // Avoid recreating tree resources because we might not have enough | 2167 // Avoid recreating tree resources because we might not have enough |
| 2182 // information to do this yet (eg. we don't have a TileManager at this | 2168 // information to do this yet (eg. we don't have a TileManager at this |
| 2183 // point). | 2169 // point). |
| 2184 return false; | 2170 return false; |
| 2185 } | 2171 } |
| 2186 | 2172 |
| 2187 output_surface_ = output_surface; | 2173 output_surface_ = output_surface.Pass(); |
| 2188 resource_provider_ = ResourceProvider::Create( | 2174 resource_provider_ = ResourceProvider::Create( |
| 2189 output_surface_, shared_bitmap_manager_, gpu_memory_buffer_manager_, | 2175 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, |
| 2190 proxy_->blocking_main_thread_task_runner(), | 2176 proxy_->blocking_main_thread_task_runner(), |
| 2191 settings_.renderer_settings.highp_threshold_min, | 2177 settings_.renderer_settings.highp_threshold_min, |
| 2192 settings_.renderer_settings.use_rgba_4444_textures, | 2178 settings_.renderer_settings.use_rgba_4444_textures, |
| 2193 settings_.renderer_settings.texture_id_allocation_chunk_size, | 2179 settings_.renderer_settings.texture_id_allocation_chunk_size, |
| 2194 settings_.use_image_texture_targets); | 2180 settings_.use_image_texture_targets); |
| 2195 | 2181 |
| 2196 CreateAndSetRenderer(); | 2182 CreateAndSetRenderer(); |
| 2197 | 2183 |
| 2198 // Since the new renderer may be capable of MSAA, update status here. | 2184 // Since the new renderer may be capable of MSAA, update status here. |
| 2199 UpdateGpuRasterizationStatus(); | 2185 UpdateGpuRasterizationStatus(); |
| (...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3601 if (active_tree()) { | 3587 if (active_tree()) { |
| 3602 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3588 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
| 3603 if (layer) | 3589 if (layer) |
| 3604 return layer->ScrollOffsetForAnimation(); | 3590 return layer->ScrollOffsetForAnimation(); |
| 3605 } | 3591 } |
| 3606 | 3592 |
| 3607 return gfx::ScrollOffset(); | 3593 return gfx::ScrollOffset(); |
| 3608 } | 3594 } |
| 3609 | 3595 |
| 3610 } // namespace cc | 3596 } // namespace cc |
| OLD | NEW |