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 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 } | 1566 } |
1559 | 1567 |
1560 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { | 1568 if (draw_mode == DRAW_MODE_RESOURCELESS_SOFTWARE) { |
1561 bool disable_picture_quad_image_filtering = | 1569 bool disable_picture_quad_image_filtering = |
1562 IsActivelyScrolling() || | 1570 IsActivelyScrolling() || |
1563 (animation_host_ ? animation_host_->NeedsAnimateLayers() | 1571 (animation_host_ ? animation_host_->NeedsAnimateLayers() |
1564 : animation_registrar_->needs_animate_layers()); | 1572 : animation_registrar_->needs_animate_layers()); |
1565 | 1573 |
1566 scoped_ptr<SoftwareRenderer> temp_software_renderer = | 1574 scoped_ptr<SoftwareRenderer> temp_software_renderer = |
1567 SoftwareRenderer::Create(this, &settings_.renderer_settings, | 1575 SoftwareRenderer::Create(this, &settings_.renderer_settings, |
1568 output_surface_.get(), NULL); | 1576 output_surface_, NULL); |
1569 temp_software_renderer->DrawFrame(&frame->render_passes, | 1577 temp_software_renderer->DrawFrame(&frame->render_passes, |
1570 device_scale_factor_, | 1578 device_scale_factor_, |
1571 DeviceViewport(), | 1579 DeviceViewport(), |
1572 DeviceClip(), | 1580 DeviceClip(), |
1573 disable_picture_quad_image_filtering); | 1581 disable_picture_quad_image_filtering); |
1574 } else { | 1582 } else { |
1575 renderer_->DrawFrame(&frame->render_passes, | 1583 renderer_->DrawFrame(&frame->render_passes, |
1576 device_scale_factor_, | 1584 device_scale_factor_, |
1577 DeviceViewport(), | 1585 DeviceViewport(), |
1578 DeviceClip(), | 1586 DeviceClip(), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1620 return settings_.gpu_rasterization_msaa_sample_count; | 1628 return settings_.gpu_rasterization_msaa_sample_count; |
1621 } | 1629 } |
1622 | 1630 |
1623 bool LayerTreeHostImpl::CanUseGpuRasterization() { | 1631 bool LayerTreeHostImpl::CanUseGpuRasterization() { |
1624 if (!(output_surface_ && output_surface_->context_provider() && | 1632 if (!(output_surface_ && output_surface_->context_provider() && |
1625 output_surface_->worker_context_provider())) | 1633 output_surface_->worker_context_provider())) |
1626 return false; | 1634 return false; |
1627 | 1635 |
1628 ContextProvider* context_provider = | 1636 ContextProvider* context_provider = |
1629 output_surface_->worker_context_provider(); | 1637 output_surface_->worker_context_provider(); |
1630 base::AutoLock context_lock(*context_provider->GetLock()); | 1638 ContextProvider::ScopedContextLock scoped_context(context_provider); |
1631 if (!context_provider->GrContext()) | 1639 if (!context_provider->GrContext()) |
1632 return false; | 1640 return false; |
1633 | 1641 |
1634 return true; | 1642 return true; |
1635 } | 1643 } |
1636 | 1644 |
1637 void LayerTreeHostImpl::UpdateGpuRasterizationStatus() { | 1645 void LayerTreeHostImpl::UpdateGpuRasterizationStatus() { |
1638 bool use_gpu = false; | 1646 bool use_gpu = false; |
1639 bool use_msaa = false; | 1647 bool use_msaa = false; |
1640 bool using_msaa_for_complex_content = | 1648 bool using_msaa_for_complex_content = |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2002 if (recycle_tree_) | 2010 if (recycle_tree_) |
2003 recycle_tree_->RecreateResources(); | 2011 recycle_tree_->RecreateResources(); |
2004 } | 2012 } |
2005 | 2013 |
2006 void LayerTreeHostImpl::CreateAndSetRenderer() { | 2014 void LayerTreeHostImpl::CreateAndSetRenderer() { |
2007 DCHECK(!renderer_); | 2015 DCHECK(!renderer_); |
2008 DCHECK(output_surface_); | 2016 DCHECK(output_surface_); |
2009 DCHECK(resource_provider_); | 2017 DCHECK(resource_provider_); |
2010 | 2018 |
2011 if (output_surface_->capabilities().delegated_rendering) { | 2019 if (output_surface_->capabilities().delegated_rendering) { |
2012 renderer_ = DelegatingRenderer::Create(this, &settings_.renderer_settings, | 2020 renderer_ = |
2013 output_surface_.get(), | 2021 DelegatingRenderer::Create(this, &settings_.renderer_settings, |
2014 resource_provider_.get()); | 2022 output_surface_, resource_provider_.get()); |
2015 } else if (output_surface_->context_provider()) { | 2023 } else if (output_surface_->context_provider()) { |
2016 renderer_ = GLRenderer::Create( | 2024 renderer_ = GLRenderer::Create( |
2017 this, &settings_.renderer_settings, output_surface_.get(), | 2025 this, &settings_.renderer_settings, output_surface_, |
2018 resource_provider_.get(), texture_mailbox_deleter_.get(), | 2026 resource_provider_.get(), texture_mailbox_deleter_.get(), |
2019 settings_.renderer_settings.highp_threshold_min); | 2027 settings_.renderer_settings.highp_threshold_min); |
2020 } else if (output_surface_->software_device()) { | 2028 } else if (output_surface_->software_device()) { |
2021 renderer_ = SoftwareRenderer::Create(this, &settings_.renderer_settings, | 2029 renderer_ = |
2022 output_surface_.get(), | 2030 SoftwareRenderer::Create(this, &settings_.renderer_settings, |
2023 resource_provider_.get()); | 2031 output_surface_, resource_provider_.get()); |
2024 } | 2032 } |
2025 DCHECK(renderer_); | 2033 DCHECK(renderer_); |
2026 | 2034 |
2027 renderer_->SetVisible(visible_); | 2035 renderer_->SetVisible(visible_); |
2028 SetFullRootLayerDamage(); | 2036 SetFullRootLayerDamage(); |
2029 | 2037 |
2030 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be | 2038 // See note in LayerTreeImpl::UpdateDrawProperties. Renderer needs to be |
2031 // initialized to get max texture size. Also, after releasing resources, | 2039 // initialized to get max texture size. Also, after releasing resources, |
2032 // trees need another update to generate new ones. | 2040 // trees need another update to generate new ones. |
2033 active_tree_->set_needs_update_draw_properties(); | 2041 active_tree_->set_needs_update_draw_properties(); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2142 main_frame_events.Pass()); | 2150 main_frame_events.Pass()); |
2143 } | 2151 } |
2144 | 2152 |
2145 void LayerTreeHostImpl::CleanUpTileManager() { | 2153 void LayerTreeHostImpl::CleanUpTileManager() { |
2146 tile_manager_->FinishTasksAndCleanUp(); | 2154 tile_manager_->FinishTasksAndCleanUp(); |
2147 resource_pool_ = nullptr; | 2155 resource_pool_ = nullptr; |
2148 tile_task_worker_pool_ = nullptr; | 2156 tile_task_worker_pool_ = nullptr; |
2149 single_thread_synchronous_task_graph_runner_ = nullptr; | 2157 single_thread_synchronous_task_graph_runner_ = nullptr; |
2150 } | 2158 } |
2151 | 2159 |
2152 bool LayerTreeHostImpl::InitializeRenderer( | 2160 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { |
2153 scoped_ptr<OutputSurface> output_surface) { | |
2154 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2161 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
2155 | 2162 |
2156 // Since we will create a new resource provider, we cannot continue to use | 2163 // Since we will create a new resource provider, we cannot continue to use |
2157 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2164 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
2158 // before we destroy the old resource provider. | 2165 // before we destroy the old resource provider. |
2159 ReleaseTreeResources(); | 2166 ReleaseTreeResources(); |
2160 | 2167 |
2161 // Note: order is important here. | 2168 // Note: order is important here. |
2162 renderer_ = nullptr; | 2169 renderer_ = nullptr; |
2163 CleanUpTileManager(); | 2170 CleanUpTileManager(); |
2164 resource_provider_ = nullptr; | 2171 resource_provider_ = nullptr; |
2165 output_surface_ = nullptr; | 2172 |
| 2173 // Detach from the old output surface and reset |output_surface_| pointer |
| 2174 // as this surface is going to be destroyed independent of if binding the |
| 2175 // new output surface succeeds or not. |
| 2176 if (output_surface_) { |
| 2177 output_surface_->DetachFromClient(); |
| 2178 output_surface_ = nullptr; |
| 2179 } |
2166 | 2180 |
2167 if (!output_surface->BindToClient(this)) { | 2181 if (!output_surface->BindToClient(this)) { |
2168 // Avoid recreating tree resources because we might not have enough | 2182 // Avoid recreating tree resources because we might not have enough |
2169 // information to do this yet (eg. we don't have a TileManager at this | 2183 // information to do this yet (eg. we don't have a TileManager at this |
2170 // point). | 2184 // point). |
2171 return false; | 2185 return false; |
2172 } | 2186 } |
2173 | 2187 |
2174 output_surface_ = output_surface.Pass(); | 2188 output_surface_ = output_surface; |
2175 resource_provider_ = ResourceProvider::Create( | 2189 resource_provider_ = ResourceProvider::Create( |
2176 output_surface_.get(), shared_bitmap_manager_, gpu_memory_buffer_manager_, | 2190 output_surface_, shared_bitmap_manager_, gpu_memory_buffer_manager_, |
2177 proxy_->blocking_main_thread_task_runner(), | 2191 proxy_->blocking_main_thread_task_runner(), |
2178 settings_.renderer_settings.highp_threshold_min, | 2192 settings_.renderer_settings.highp_threshold_min, |
2179 settings_.renderer_settings.use_rgba_4444_textures, | 2193 settings_.renderer_settings.use_rgba_4444_textures, |
2180 settings_.renderer_settings.texture_id_allocation_chunk_size, | 2194 settings_.renderer_settings.texture_id_allocation_chunk_size, |
2181 settings_.use_image_texture_targets); | 2195 settings_.use_image_texture_targets); |
2182 | 2196 |
2183 CreateAndSetRenderer(); | 2197 CreateAndSetRenderer(); |
2184 | 2198 |
2185 // Since the new renderer may be capable of MSAA, update status here. | 2199 // Since the new renderer may be capable of MSAA, update status here. |
2186 UpdateGpuRasterizationStatus(); | 2200 UpdateGpuRasterizationStatus(); |
(...skipping 1407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3594 if (active_tree()) { | 3608 if (active_tree()) { |
3595 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3609 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
3596 if (layer) | 3610 if (layer) |
3597 return layer->ScrollOffsetForAnimation(); | 3611 return layer->ScrollOffsetForAnimation(); |
3598 } | 3612 } |
3599 | 3613 |
3600 return gfx::ScrollOffset(); | 3614 return gfx::ScrollOffset(); |
3601 } | 3615 } |
3602 | 3616 |
3603 } // namespace cc | 3617 } // namespace cc |
OLD | NEW |