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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 #include "cc/raster/gpu_raster_buffer_provider.h" | 60 #include "cc/raster/gpu_raster_buffer_provider.h" |
61 #include "cc/raster/one_copy_raster_buffer_provider.h" | 61 #include "cc/raster/one_copy_raster_buffer_provider.h" |
62 #include "cc/raster/raster_buffer_provider.h" | 62 #include "cc/raster/raster_buffer_provider.h" |
63 #include "cc/raster/synchronous_task_graph_runner.h" | 63 #include "cc/raster/synchronous_task_graph_runner.h" |
64 #include "cc/raster/zero_copy_raster_buffer_provider.h" | 64 #include "cc/raster/zero_copy_raster_buffer_provider.h" |
65 #include "cc/resources/memory_history.h" | 65 #include "cc/resources/memory_history.h" |
66 #include "cc/resources/resource_pool.h" | 66 #include "cc/resources/resource_pool.h" |
67 #include "cc/resources/ui_resource_bitmap.h" | 67 #include "cc/resources/ui_resource_bitmap.h" |
68 #include "cc/scheduler/delay_based_time_source.h" | 68 #include "cc/scheduler/delay_based_time_source.h" |
69 #include "cc/tiles/eviction_tile_priority_queue.h" | 69 #include "cc/tiles/eviction_tile_priority_queue.h" |
70 #include "cc/tiles/gpu_image_decode_controller.h" | 70 #include "cc/tiles/gpu_image_decode_cache.h" |
71 #include "cc/tiles/picture_layer_tiling.h" | 71 #include "cc/tiles/picture_layer_tiling.h" |
72 #include "cc/tiles/raster_tile_priority_queue.h" | 72 #include "cc/tiles/raster_tile_priority_queue.h" |
73 #include "cc/tiles/software_image_decode_controller.h" | 73 #include "cc/tiles/software_image_decode_cache.h" |
74 #include "cc/trees/damage_tracker.h" | 74 #include "cc/trees/damage_tracker.h" |
75 #include "cc/trees/draw_property_utils.h" | 75 #include "cc/trees/draw_property_utils.h" |
76 #include "cc/trees/latency_info_swap_promise_monitor.h" | 76 #include "cc/trees/latency_info_swap_promise_monitor.h" |
77 #include "cc/trees/layer_tree_host_common.h" | 77 #include "cc/trees/layer_tree_host_common.h" |
78 #include "cc/trees/layer_tree_impl.h" | 78 #include "cc/trees/layer_tree_impl.h" |
79 #include "cc/trees/mutator_host.h" | 79 #include "cc/trees/mutator_host.h" |
80 #include "cc/trees/scroll_node.h" | 80 #include "cc/trees/scroll_node.h" |
81 #include "cc/trees/single_thread_proxy.h" | 81 #include "cc/trees/single_thread_proxy.h" |
82 #include "cc/trees/tree_synchronizer.h" | 82 #include "cc/trees/tree_synchronizer.h" |
83 #include "gpu/GLES2/gl2extchromium.h" | 83 #include "gpu/GLES2/gl2extchromium.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); | 279 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
280 TRACE_EVENT_OBJECT_DELETED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 280 TRACE_EVENT_OBJECT_DELETED_WITH_ID(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
281 "cc::LayerTreeHostImpl", id_); | 281 "cc::LayerTreeHostImpl", id_); |
282 | 282 |
283 // It is released before shutdown. | 283 // It is released before shutdown. |
284 DCHECK(!compositor_frame_sink_); | 284 DCHECK(!compositor_frame_sink_); |
285 | 285 |
286 DCHECK(!resource_provider_); | 286 DCHECK(!resource_provider_); |
287 DCHECK(!resource_pool_); | 287 DCHECK(!resource_pool_); |
288 DCHECK(!single_thread_synchronous_task_graph_runner_); | 288 DCHECK(!single_thread_synchronous_task_graph_runner_); |
289 DCHECK(!image_decode_controller_); | 289 DCHECK(!image_decode_cache_); |
290 | 290 |
291 if (input_handler_client_) { | 291 if (input_handler_client_) { |
292 input_handler_client_->WillShutdown(); | 292 input_handler_client_->WillShutdown(); |
293 input_handler_client_ = NULL; | 293 input_handler_client_ = NULL; |
294 } | 294 } |
295 if (scroll_elasticity_helper_) | 295 if (scroll_elasticity_helper_) |
296 scroll_elasticity_helper_.reset(); | 296 scroll_elasticity_helper_.reset(); |
297 | 297 |
298 // The layer trees must be destroyed before the layer tree host. | 298 // The layer trees must be destroyed before the layer tree host. |
299 if (recycle_tree_) | 299 if (recycle_tree_) |
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1229 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we | 1229 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we |
1230 // consider our contexts visible. Notify the contexts here. We handle | 1230 // consider our contexts visible. Notify the contexts here. We handle |
1231 // becoming invisible in NotifyAllTileTasksComplete to avoid interrupting | 1231 // becoming invisible in NotifyAllTileTasksComplete to avoid interrupting |
1232 // running work. | 1232 // running work. |
1233 SetContextVisibility(true); | 1233 SetContextVisibility(true); |
1234 | 1234 |
1235 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we | 1235 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we |
1236 // allow the image decode controller to retain resources. We handle the | 1236 // allow the image decode controller to retain resources. We handle the |
1237 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting | 1237 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting |
1238 // running work. | 1238 // running work. |
1239 if (image_decode_controller_) | 1239 if (image_decode_cache_) |
1240 image_decode_controller_->SetShouldAggressivelyFreeResources(false); | 1240 image_decode_cache_->SetShouldAggressivelyFreeResources(false); |
1241 } | 1241 } |
1242 | 1242 |
1243 DCHECK(resource_pool_); | 1243 DCHECK(resource_pool_); |
1244 resource_pool_->CheckBusyResources(); | 1244 resource_pool_->CheckBusyResources(); |
1245 // Soft limit is used for resource pool such that memory returns to soft | 1245 // Soft limit is used for resource pool such that memory returns to soft |
1246 // limit after going over. | 1246 // limit after going over. |
1247 resource_pool_->SetResourceUsageLimits( | 1247 resource_pool_->SetResourceUsageLimits( |
1248 global_tile_state_.soft_memory_limit_in_bytes, | 1248 global_tile_state_.soft_memory_limit_in_bytes, |
1249 global_tile_state_.num_resources_limit); | 1249 global_tile_state_.num_resources_limit); |
1250 | 1250 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1313 } | 1313 } |
1314 | 1314 |
1315 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { | 1315 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { |
1316 // The tile tasks started by the most recent call to PrepareTiles have | 1316 // The tile tasks started by the most recent call to PrepareTiles have |
1317 // completed. Now is a good time to free resources if necessary. | 1317 // completed. Now is a good time to free resources if necessary. |
1318 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { | 1318 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { |
1319 // Free image decode controller resources before notifying the | 1319 // Free image decode controller resources before notifying the |
1320 // contexts of visibility change. This ensures that the imaged decode | 1320 // contexts of visibility change. This ensures that the imaged decode |
1321 // controller has released all Skia refs at the time Skia's cleanup | 1321 // controller has released all Skia refs at the time Skia's cleanup |
1322 // executes (within worker context's cleanup). | 1322 // executes (within worker context's cleanup). |
1323 if (image_decode_controller_) | 1323 if (image_decode_cache_) |
1324 image_decode_controller_->SetShouldAggressivelyFreeResources(true); | 1324 image_decode_cache_->SetShouldAggressivelyFreeResources(true); |
1325 SetContextVisibility(false); | 1325 SetContextVisibility(false); |
1326 } | 1326 } |
1327 } | 1327 } |
1328 | 1328 |
1329 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { | 1329 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { |
1330 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); | 1330 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); |
1331 | 1331 |
1332 if (active_tree_) { | 1332 if (active_tree_) { |
1333 LayerImpl* layer_impl = | 1333 LayerImpl* layer_impl = |
1334 active_tree_->FindActiveTreeLayerById(tile->layer_id()); | 1334 active_tree_->FindActiveTreeLayerById(tile->layer_id()); |
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 pending_tree_->RecreateTileResources(); | 2099 pending_tree_->RecreateTileResources(); |
2100 if (recycle_tree_) | 2100 if (recycle_tree_) |
2101 recycle_tree_->RecreateTileResources(); | 2101 recycle_tree_->RecreateTileResources(); |
2102 } | 2102 } |
2103 | 2103 |
2104 void LayerTreeHostImpl::CreateTileManagerResources() { | 2104 void LayerTreeHostImpl::CreateTileManagerResources() { |
2105 CreateResourceAndRasterBufferProvider(&raster_buffer_provider_, | 2105 CreateResourceAndRasterBufferProvider(&raster_buffer_provider_, |
2106 &resource_pool_); | 2106 &resource_pool_); |
2107 | 2107 |
2108 if (use_gpu_rasterization_) { | 2108 if (use_gpu_rasterization_) { |
2109 image_decode_controller_ = base::MakeUnique<GpuImageDecodeController>( | 2109 image_decode_cache_ = base::MakeUnique<GpuImageDecodeCache>( |
2110 compositor_frame_sink_->worker_context_provider(), | 2110 compositor_frame_sink_->worker_context_provider(), |
2111 settings_.renderer_settings.preferred_tile_format, | 2111 settings_.renderer_settings.preferred_tile_format, |
2112 settings_.gpu_decoded_image_budget_bytes); | 2112 settings_.gpu_decoded_image_budget_bytes); |
2113 } else { | 2113 } else { |
2114 image_decode_controller_ = base::MakeUnique<SoftwareImageDecodeController>( | 2114 image_decode_cache_ = base::MakeUnique<SoftwareImageDecodeCache>( |
2115 settings_.renderer_settings.preferred_tile_format, | 2115 settings_.renderer_settings.preferred_tile_format, |
2116 settings_.software_decoded_image_budget_bytes); | 2116 settings_.software_decoded_image_budget_bytes); |
2117 } | 2117 } |
2118 | 2118 |
2119 // Pass the single-threaded synchronous task graph runner to the worker pool | 2119 // Pass the single-threaded synchronous task graph runner to the worker pool |
2120 // if we're in synchronous single-threaded mode. | 2120 // if we're in synchronous single-threaded mode. |
2121 TaskGraphRunner* task_graph_runner = task_graph_runner_; | 2121 TaskGraphRunner* task_graph_runner = task_graph_runner_; |
2122 if (is_synchronous_single_threaded_) { | 2122 if (is_synchronous_single_threaded_) { |
2123 DCHECK(!single_thread_synchronous_task_graph_runner_); | 2123 DCHECK(!single_thread_synchronous_task_graph_runner_); |
2124 single_thread_synchronous_task_graph_runner_.reset( | 2124 single_thread_synchronous_task_graph_runner_.reset( |
2125 new SynchronousTaskGraphRunner); | 2125 new SynchronousTaskGraphRunner); |
2126 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); | 2126 task_graph_runner = single_thread_synchronous_task_graph_runner_.get(); |
2127 } | 2127 } |
2128 | 2128 |
2129 // TODO(vmpstr): Initialize tile task limit at ctor time. | 2129 // TODO(vmpstr): Initialize tile task limit at ctor time. |
2130 tile_manager_.SetResources( | 2130 tile_manager_.SetResources(resource_pool_.get(), image_decode_cache_.get(), |
2131 resource_pool_.get(), image_decode_controller_.get(), task_graph_runner, | 2131 task_graph_runner, raster_buffer_provider_.get(), |
2132 raster_buffer_provider_.get(), | 2132 is_synchronous_single_threaded_ |
2133 is_synchronous_single_threaded_ ? std::numeric_limits<size_t>::max() | 2133 ? std::numeric_limits<size_t>::max() |
2134 : settings_.scheduled_raster_task_limit, | 2134 : settings_.scheduled_raster_task_limit, |
2135 use_gpu_rasterization_); | 2135 use_gpu_rasterization_); |
2136 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); | 2136 UpdateTileManagerMemoryPolicy(ActualManagedMemoryPolicy()); |
2137 } | 2137 } |
2138 | 2138 |
2139 void LayerTreeHostImpl::CreateResourceAndRasterBufferProvider( | 2139 void LayerTreeHostImpl::CreateResourceAndRasterBufferProvider( |
2140 std::unique_ptr<RasterBufferProvider>* raster_buffer_provider, | 2140 std::unique_ptr<RasterBufferProvider>* raster_buffer_provider, |
2141 std::unique_ptr<ResourcePool>* resource_pool) { | 2141 std::unique_ptr<ResourcePool>* resource_pool) { |
2142 DCHECK(GetTaskRunner()); | 2142 DCHECK(GetTaskRunner()); |
2143 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is | 2143 // TODO(vmpstr): Make this a DCHECK (or remove) when crbug.com/419086 is |
2144 // resolved. | 2144 // resolved. |
2145 CHECK(resource_provider_); | 2145 CHECK(resource_provider_); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2230 | 2230 |
2231 void LayerTreeHostImpl::DidChangeScrollbarVisibility() { | 2231 void LayerTreeHostImpl::DidChangeScrollbarVisibility() { |
2232 client_->SetNeedsCommitOnImplThread(); | 2232 client_->SetNeedsCommitOnImplThread(); |
2233 } | 2233 } |
2234 | 2234 |
2235 void LayerTreeHostImpl::CleanUpTileManagerAndUIResources() { | 2235 void LayerTreeHostImpl::CleanUpTileManagerAndUIResources() { |
2236 ClearUIResources(); | 2236 ClearUIResources(); |
2237 tile_manager_.FinishTasksAndCleanUp(); | 2237 tile_manager_.FinishTasksAndCleanUp(); |
2238 resource_pool_ = nullptr; | 2238 resource_pool_ = nullptr; |
2239 single_thread_synchronous_task_graph_runner_ = nullptr; | 2239 single_thread_synchronous_task_graph_runner_ = nullptr; |
2240 image_decode_controller_ = nullptr; | 2240 image_decode_cache_ = nullptr; |
2241 | 2241 |
2242 // We've potentially just freed a large number of resources on our various | 2242 // We've potentially just freed a large number of resources on our various |
2243 // contexts. Flushing now helps ensure these are cleaned up quickly | 2243 // contexts. Flushing now helps ensure these are cleaned up quickly |
2244 // preventing driver cache growth. See crbug.com/643251 | 2244 // preventing driver cache growth. See crbug.com/643251 |
2245 if (compositor_frame_sink_) { | 2245 if (compositor_frame_sink_) { |
2246 if (auto* compositor_context = compositor_frame_sink_->context_provider()) | 2246 if (auto* compositor_context = compositor_frame_sink_->context_provider()) |
2247 compositor_context->ContextGL()->ShallowFlushCHROMIUM(); | 2247 compositor_context->ContextGL()->ShallowFlushCHROMIUM(); |
2248 if (auto* worker_context = | 2248 if (auto* worker_context = |
2249 compositor_frame_sink_->worker_context_provider()) { | 2249 compositor_frame_sink_->worker_context_provider()) { |
2250 ContextProvider::ScopedContextLock hold(worker_context); | 2250 ContextProvider::ScopedContextLock hold(worker_context); |
(...skipping 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4085 worker_context_visibility_ = | 4085 worker_context_visibility_ = |
4086 worker_context->CacheController()->ClientBecameVisible(); | 4086 worker_context->CacheController()->ClientBecameVisible(); |
4087 } else { | 4087 } else { |
4088 worker_context->CacheController()->ClientBecameNotVisible( | 4088 worker_context->CacheController()->ClientBecameNotVisible( |
4089 std::move(worker_context_visibility_)); | 4089 std::move(worker_context_visibility_)); |
4090 } | 4090 } |
4091 } | 4091 } |
4092 } | 4092 } |
4093 | 4093 |
4094 } // namespace cc | 4094 } // namespace cc |
OLD | NEW |