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