Chromium Code Reviews| 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 bool scroll_on_main_thread = (scroll_thread == MAIN_THREAD); | 150 bool scroll_on_main_thread = (scroll_thread == MAIN_THREAD); |
| 151 if (IsWheelBasedScroll(type)) { | 151 if (IsWheelBasedScroll(type)) { |
| 152 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorWheelScrollUpdateThread", | 152 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorWheelScrollUpdateThread", |
| 153 scroll_on_main_thread); | 153 scroll_on_main_thread); |
| 154 } else { | 154 } else { |
| 155 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorTouchScrollUpdateThread", | 155 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorTouchScrollUpdateThread", |
| 156 scroll_on_main_thread); | 156 scroll_on_main_thread); |
| 157 } | 157 } |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Calls SetClientVisible on the provided |context_provider| and handles | |
| 161 // additional cache cleanup. | |
| 162 void UpdateVisibilityForContextProvider(int client_id, | |
| 163 ContextProvider* context_provider, | |
| 164 bool is_visible) { | |
| 165 if (!context_provider) | |
| 166 return; | |
| 167 gpu::ContextSupport* context_support = context_provider->ContextSupport(); | |
| 168 | |
| 169 context_support->SetClientVisible(client_id, is_visible); | |
| 170 bool aggressively_free_resources = !context_support->AnyClientsVisible(); | |
| 171 if (aggressively_free_resources) { | |
| 172 context_provider->DeleteCachedResources(); | |
| 173 } | |
| 174 context_support->SetAggressivelyFreeResources(aggressively_free_resources); | |
| 175 } | |
| 176 | |
| 177 // Same as UpdateVisibilityForContextProvider, except that the | |
| 178 // |context_provider| is locked before being used. | |
| 179 void LockAndUpdateVisibilityForContextProvider( | |
| 180 int client_id, | |
| 181 ContextProvider* context_provider, | |
| 182 bool is_visible) { | |
| 183 if (!context_provider) | |
| 184 return; | |
| 185 ContextProvider::ScopedContextLock hold(context_provider); | |
| 186 UpdateVisibilityForContextProvider(client_id, context_provider, is_visible); | |
| 187 } | |
| 188 | |
| 189 } // namespace | 160 } // namespace |
| 190 | 161 |
| 191 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer, | 162 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer, |
| 192 "Scheduling.%s.PendingTreeDuration"); | 163 "Scheduling.%s.PendingTreeDuration"); |
| 193 | 164 |
| 194 LayerTreeHostImpl::FrameData::FrameData() | 165 LayerTreeHostImpl::FrameData::FrameData() |
| 195 : render_surface_layer_list(nullptr), | 166 : render_surface_layer_list(nullptr), |
| 196 has_no_damage(false), | 167 has_no_damage(false), |
| 197 may_contain_video(false) {} | 168 may_contain_video(false) {} |
| 198 | 169 |
| (...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1289 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( | 1260 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( |
| 1290 visible_ ? policy.priority_cutoff_when_visible | 1261 visible_ ? policy.priority_cutoff_when_visible |
| 1291 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); | 1262 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); |
| 1292 global_tile_state_.num_resources_limit = policy.num_resources_limit; | 1263 global_tile_state_.num_resources_limit = policy.num_resources_limit; |
| 1293 | 1264 |
| 1294 if (global_tile_state_.hard_memory_limit_in_bytes > 0) { | 1265 if (global_tile_state_.hard_memory_limit_in_bytes > 0) { |
| 1295 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we | 1266 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we |
| 1296 // are visible. Notify the worker context here. We handle becoming | 1267 // are visible. Notify the worker context here. We handle becoming |
| 1297 // invisible in NotifyAllTileTasksComplete to avoid interrupting running | 1268 // invisible in NotifyAllTileTasksComplete to avoid interrupting running |
| 1298 // work. | 1269 // work. |
| 1299 if (output_surface_) { | 1270 SetWorkerContextVisibility(true); |
| 1300 LockAndUpdateVisibilityForContextProvider( | |
| 1301 id_, output_surface_->worker_context_provider(), | |
| 1302 true /* is_visible */); | |
| 1303 } | |
| 1304 | 1271 |
| 1305 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we | 1272 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we |
| 1306 // allow the image decode controller to retain resources. We handle the | 1273 // allow the image decode controller to retain resources. We handle the |
| 1307 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting | 1274 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting |
| 1308 // running work. | 1275 // running work. |
| 1309 if (image_decode_controller_) { | 1276 if (image_decode_controller_) { |
|
danakj
2016/08/29 23:56:20
nit: no {} needed now
ericrk
2016/08/30 18:18:58
Done.
| |
| 1310 image_decode_controller_->SetShouldAggressivelyFreeResources( | 1277 image_decode_controller_->SetShouldAggressivelyFreeResources(false); |
| 1311 false /* aggressively_free_resources */); | |
| 1312 } | 1278 } |
| 1313 } | 1279 } |
| 1314 | 1280 |
| 1315 DCHECK(resource_pool_); | 1281 DCHECK(resource_pool_); |
| 1316 resource_pool_->CheckBusyResources(); | 1282 resource_pool_->CheckBusyResources(); |
| 1317 // Soft limit is used for resource pool such that memory returns to soft | 1283 // Soft limit is used for resource pool such that memory returns to soft |
| 1318 // limit after going over. | 1284 // limit after going over. |
| 1319 resource_pool_->SetResourceUsageLimits( | 1285 resource_pool_->SetResourceUsageLimits( |
| 1320 global_tile_state_.soft_memory_limit_in_bytes, | 1286 global_tile_state_.soft_memory_limit_in_bytes, |
| 1321 global_tile_state_.num_resources_limit); | 1287 global_tile_state_.num_resources_limit); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1379 } | 1345 } |
| 1380 | 1346 |
| 1381 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { | 1347 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { |
| 1382 // The tile tasks started by the most recent call to PrepareTiles have | 1348 // The tile tasks started by the most recent call to PrepareTiles have |
| 1383 // completed. Now is a good time to free resources if necessary. | 1349 // completed. Now is a good time to free resources if necessary. |
| 1384 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { | 1350 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { |
| 1385 // Free image decode controller resources before notifying the worker | 1351 // Free image decode controller resources before notifying the worker |
| 1386 // context of visibility change. This ensures that the imaged decode | 1352 // context of visibility change. This ensures that the imaged decode |
| 1387 // controller has released all Skia refs at the time Skia's cleanup | 1353 // controller has released all Skia refs at the time Skia's cleanup |
| 1388 // executes (within worker context's cleanup). | 1354 // executes (within worker context's cleanup). |
| 1389 if (image_decode_controller_) { | 1355 if (image_decode_controller_) { |
|
danakj
2016/08/29 23:56:20
nitto
ericrk
2016/08/30 18:18:58
Done.
| |
| 1390 image_decode_controller_->SetShouldAggressivelyFreeResources( | 1356 image_decode_controller_->SetShouldAggressivelyFreeResources(true); |
| 1391 true /* aggressively_free_resources */); | |
| 1392 } | 1357 } |
| 1393 if (output_surface_) { | 1358 SetWorkerContextVisibility(false); |
| 1394 LockAndUpdateVisibilityForContextProvider( | |
| 1395 id_, output_surface_->worker_context_provider(), | |
| 1396 false /* is_visible */); | |
| 1397 } | |
| 1398 } | 1359 } |
| 1399 } | 1360 } |
| 1400 | 1361 |
| 1401 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { | 1362 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { |
| 1402 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); | 1363 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); |
| 1403 | 1364 |
| 1404 if (active_tree_) { | 1365 if (active_tree_) { |
| 1405 LayerImpl* layer_impl = | 1366 LayerImpl* layer_impl = |
| 1406 active_tree_->FindActiveTreeLayerById(tile->layer_id()); | 1367 active_tree_->FindActiveTreeLayerById(tile->layer_id()); |
| 1407 if (layer_impl) | 1368 if (layer_impl) |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2125 if (visible_) { | 2086 if (visible_) { |
| 2126 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. | 2087 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. |
| 2127 SetRequiresHighResToDraw(); | 2088 SetRequiresHighResToDraw(); |
| 2128 } else { | 2089 } else { |
| 2129 EvictAllUIResources(); | 2090 EvictAllUIResources(); |
| 2130 // Call PrepareTiles to evict tiles when we become invisible. | 2091 // Call PrepareTiles to evict tiles when we become invisible. |
| 2131 PrepareTiles(); | 2092 PrepareTiles(); |
| 2132 } | 2093 } |
| 2133 | 2094 |
| 2134 // Update visibility for the compositor context provider. | 2095 // Update visibility for the compositor context provider. |
| 2135 if (output_surface_) { | 2096 SetMainContextVisibility(visible); |
| 2136 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), | |
| 2137 visible); | |
| 2138 } | |
| 2139 } | 2097 } |
| 2140 | 2098 |
| 2141 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { | 2099 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { |
| 2142 // TODO(miletus): This is just the compositor-thread-side call to the | 2100 // TODO(miletus): This is just the compositor-thread-side call to the |
| 2143 // SwapPromiseMonitor to say something happened that may cause a swap in the | 2101 // SwapPromiseMonitor to say something happened that may cause a swap in the |
| 2144 // future. The name should not refer to SetNeedsRedraw but it does for now. | 2102 // future. The name should not refer to SetNeedsRedraw but it does for now. |
| 2145 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 2103 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
| 2146 client_->SetNeedsOneBeginImplFrameOnImplThread(); | 2104 client_->SetNeedsOneBeginImplFrameOnImplThread(); |
| 2147 } | 2105 } |
| 2148 | 2106 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2343 // Since we will create a new resource provider, we cannot continue to use | 2301 // Since we will create a new resource provider, we cannot continue to use |
| 2344 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2302 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
| 2345 // before we destroy the old resource provider. | 2303 // before we destroy the old resource provider. |
| 2346 ReleaseTreeResources(); | 2304 ReleaseTreeResources(); |
| 2347 | 2305 |
| 2348 // Note: order is important here. | 2306 // Note: order is important here. |
| 2349 renderer_ = nullptr; | 2307 renderer_ = nullptr; |
| 2350 CleanUpTileManagerAndUIResources(); | 2308 CleanUpTileManagerAndUIResources(); |
| 2351 resource_provider_ = nullptr; | 2309 resource_provider_ = nullptr; |
| 2352 | 2310 |
| 2311 // Release any context visibility before we destroy the OutputSurface. | |
| 2312 if (main_context_visibility_) | |
|
danakj
2016/08/29 23:56:20
can you use if (visible_) for the main context, an
ericrk
2016/08/30 18:18:58
Done.
| |
| 2313 SetMainContextVisibility(false); | |
| 2314 if (worker_context_visibility_) | |
| 2315 SetWorkerContextVisibility(false); | |
| 2316 | |
| 2353 // Detach from the old output surface and reset |output_surface_| pointer | 2317 // Detach from the old output surface and reset |output_surface_| pointer |
| 2354 // as this surface is going to be destroyed independent of if binding the | 2318 // as this surface is going to be destroyed independent of if binding the |
| 2355 // new output surface succeeds or not. | 2319 // new output surface succeeds or not. |
| 2356 if (output_surface_) { | 2320 if (output_surface_) { |
| 2357 output_surface_->DetachFromClient(); | 2321 output_surface_->DetachFromClient(); |
| 2358 output_surface_ = nullptr; | 2322 output_surface_ = nullptr; |
| 2359 } | 2323 } |
| 2360 | 2324 |
| 2361 // We don't know if the next OutputSurface will support GPU rasterization. | 2325 // We don't know if the next OutputSurface will support GPU rasterization. |
| 2362 // Make sure to clear the flag so that we force a re-computation. | 2326 // Make sure to clear the flag so that we force a re-computation. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2378 resource_provider_ = base::MakeUnique<ResourceProvider>( | 2342 resource_provider_ = base::MakeUnique<ResourceProvider>( |
| 2379 output_surface_->context_provider(), shared_bitmap_manager_, | 2343 output_surface_->context_provider(), shared_bitmap_manager_, |
| 2380 gpu_memory_buffer_manager_, | 2344 gpu_memory_buffer_manager_, |
| 2381 task_runner_provider_->blocking_main_thread_task_runner(), | 2345 task_runner_provider_->blocking_main_thread_task_runner(), |
| 2382 settings_.renderer_settings.highp_threshold_min, | 2346 settings_.renderer_settings.highp_threshold_min, |
| 2383 settings_.renderer_settings.texture_id_allocation_chunk_size, | 2347 settings_.renderer_settings.texture_id_allocation_chunk_size, |
| 2384 output_surface_->capabilities().delegated_sync_points_required, | 2348 output_surface_->capabilities().delegated_sync_points_required, |
| 2385 settings_.renderer_settings.use_gpu_memory_buffer_resources, | 2349 settings_.renderer_settings.use_gpu_memory_buffer_resources, |
| 2386 settings_.renderer_settings.buffer_to_texture_target_map); | 2350 settings_.renderer_settings.buffer_to_texture_target_map); |
| 2387 | 2351 |
| 2352 // Make sure the main context visibility is restored. Worker context | |
| 2353 // visibility will be set via the memory policy update in | |
| 2354 // CreateTileManagerResources below. | |
| 2355 if (visible_) | |
| 2356 SetMainContextVisibility(true); | |
| 2357 | |
| 2388 // Since the new context may be capable of MSAA, update status here. We don't | 2358 // Since the new context may be capable of MSAA, update status here. We don't |
| 2389 // need to check the return value since we are recreating all resources | 2359 // need to check the return value since we are recreating all resources |
| 2390 // already. | 2360 // already. |
| 2391 UpdateGpuRasterizationStatus(); | 2361 UpdateGpuRasterizationStatus(); |
| 2392 | 2362 |
| 2393 CreateAndSetRenderer(); | 2363 CreateAndSetRenderer(); |
| 2394 | 2364 |
| 2395 CreateTileManagerResources(); | 2365 CreateTileManagerResources(); |
| 2396 RecreateTreeResources(); | 2366 RecreateTreeResources(); |
| 2397 | 2367 |
| (...skipping 1724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4122 // Supported in threaded mode. | 4092 // Supported in threaded mode. |
| 4123 return task_runner_provider_->HasImplThread(); | 4093 return task_runner_provider_->HasImplThread(); |
| 4124 } | 4094 } |
| 4125 | 4095 |
| 4126 bool LayerTreeHostImpl::CommitToActiveTree() const { | 4096 bool LayerTreeHostImpl::CommitToActiveTree() const { |
| 4127 // In single threaded mode we skip the pending tree and commit directly to the | 4097 // In single threaded mode we skip the pending tree and commit directly to the |
| 4128 // active tree. | 4098 // active tree. |
| 4129 return !task_runner_provider_->HasImplThread(); | 4099 return !task_runner_provider_->HasImplThread(); |
| 4130 } | 4100 } |
| 4131 | 4101 |
| 4102 void LayerTreeHostImpl::SetMainContextVisibility(bool is_visible) { | |
| 4103 if (!output_surface_) | |
| 4104 return; | |
| 4105 | |
| 4106 DCHECK_NE(is_visible, !!main_context_visibility_); | |
| 4107 | |
| 4108 auto* main_context = output_surface_->context_provider(); | |
| 4109 if (!main_context) | |
| 4110 return; | |
| 4111 | |
| 4112 if (is_visible) { | |
| 4113 main_context_visibility_ = | |
| 4114 main_context->CacheController()->ClientBecameVisible(); | |
| 4115 } else { | |
| 4116 main_context->CacheController()->ClientBecameNotVisible( | |
| 4117 std::move(main_context_visibility_)); | |
| 4118 } | |
| 4119 } | |
| 4120 | |
| 4121 void LayerTreeHostImpl::SetWorkerContextVisibility(bool is_visible) { | |
| 4122 if (!output_surface_) | |
| 4123 return; | |
| 4124 | |
| 4125 // TODO(ericrk): This check is here because worker context visibility is a | |
| 4126 // bit less controlled, being settable both by memory policy changes as well | |
| 4127 // as direct visibility changes. We should simplify this. crbug.com/642154 | |
| 4128 if (is_visible == !!worker_context_visibility_) | |
| 4129 return; | |
| 4130 | |
| 4131 auto* worker_context = output_surface_->worker_context_provider(); | |
| 4132 if (!worker_context) | |
| 4133 return; | |
| 4134 | |
| 4135 ContextProvider::ScopedContextLock hold(worker_context); | |
| 4136 if (is_visible) { | |
| 4137 worker_context_visibility_ = | |
| 4138 worker_context->CacheController()->ClientBecameVisible(); | |
| 4139 } else { | |
| 4140 worker_context->CacheController()->ClientBecameNotVisible( | |
| 4141 std::move(worker_context_visibility_)); | |
| 4142 } | |
| 4143 } | |
| 4144 | |
| 4132 } // namespace cc | 4145 } // namespace cc |
| OLD | NEW |