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