| 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_) |
| 1310 image_decode_controller_->SetShouldAggressivelyFreeResources( | 1277 image_decode_controller_->SetShouldAggressivelyFreeResources(false); |
| 1311 false /* aggressively_free_resources */); | |
| 1312 } | |
| 1313 } | 1278 } |
| 1314 | 1279 |
| 1315 DCHECK(resource_pool_); | 1280 DCHECK(resource_pool_); |
| 1316 resource_pool_->CheckBusyResources(); | 1281 resource_pool_->CheckBusyResources(); |
| 1317 // Soft limit is used for resource pool such that memory returns to soft | 1282 // Soft limit is used for resource pool such that memory returns to soft |
| 1318 // limit after going over. | 1283 // limit after going over. |
| 1319 resource_pool_->SetResourceUsageLimits( | 1284 resource_pool_->SetResourceUsageLimits( |
| 1320 global_tile_state_.soft_memory_limit_in_bytes, | 1285 global_tile_state_.soft_memory_limit_in_bytes, |
| 1321 global_tile_state_.num_resources_limit); | 1286 global_tile_state_.num_resources_limit); |
| 1322 | 1287 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 } | 1344 } |
| 1380 | 1345 |
| 1381 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { | 1346 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { |
| 1382 // The tile tasks started by the most recent call to PrepareTiles have | 1347 // The tile tasks started by the most recent call to PrepareTiles have |
| 1383 // completed. Now is a good time to free resources if necessary. | 1348 // completed. Now is a good time to free resources if necessary. |
| 1384 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { | 1349 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { |
| 1385 // Free image decode controller resources before notifying the worker | 1350 // Free image decode controller resources before notifying the worker |
| 1386 // context of visibility change. This ensures that the imaged decode | 1351 // context of visibility change. This ensures that the imaged decode |
| 1387 // controller has released all Skia refs at the time Skia's cleanup | 1352 // controller has released all Skia refs at the time Skia's cleanup |
| 1388 // executes (within worker context's cleanup). | 1353 // executes (within worker context's cleanup). |
| 1389 if (image_decode_controller_) { | 1354 if (image_decode_controller_) |
| 1390 image_decode_controller_->SetShouldAggressivelyFreeResources( | 1355 image_decode_controller_->SetShouldAggressivelyFreeResources(true); |
| 1391 true /* aggressively_free_resources */); | 1356 SetWorkerContextVisibility(false); |
| 1392 } | |
| 1393 if (output_surface_) { | |
| 1394 LockAndUpdateVisibilityForContextProvider( | |
| 1395 id_, output_surface_->worker_context_provider(), | |
| 1396 false /* is_visible */); | |
| 1397 } | |
| 1398 } | 1357 } |
| 1399 } | 1358 } |
| 1400 | 1359 |
| 1401 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { | 1360 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { |
| 1402 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); | 1361 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); |
| 1403 | 1362 |
| 1404 if (active_tree_) { | 1363 if (active_tree_) { |
| 1405 LayerImpl* layer_impl = | 1364 LayerImpl* layer_impl = |
| 1406 active_tree_->FindActiveTreeLayerById(tile->layer_id()); | 1365 active_tree_->FindActiveTreeLayerById(tile->layer_id()); |
| 1407 if (layer_impl) | 1366 if (layer_impl) |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2119 if (visible_) { | 2078 if (visible_) { |
| 2120 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. | 2079 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. |
| 2121 SetRequiresHighResToDraw(); | 2080 SetRequiresHighResToDraw(); |
| 2122 } else { | 2081 } else { |
| 2123 EvictAllUIResources(); | 2082 EvictAllUIResources(); |
| 2124 // Call PrepareTiles to evict tiles when we become invisible. | 2083 // Call PrepareTiles to evict tiles when we become invisible. |
| 2125 PrepareTiles(); | 2084 PrepareTiles(); |
| 2126 } | 2085 } |
| 2127 | 2086 |
| 2128 // Update visibility for the compositor context provider. | 2087 // Update visibility for the compositor context provider. |
| 2129 if (output_surface_) { | 2088 SetCompositorContextVisibility(visible); |
| 2130 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), | |
| 2131 visible); | |
| 2132 } | |
| 2133 } | 2089 } |
| 2134 | 2090 |
| 2135 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { | 2091 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { |
| 2136 // TODO(miletus): This is just the compositor-thread-side call to the | 2092 // TODO(miletus): This is just the compositor-thread-side call to the |
| 2137 // SwapPromiseMonitor to say something happened that may cause a swap in the | 2093 // SwapPromiseMonitor to say something happened that may cause a swap in the |
| 2138 // future. The name should not refer to SetNeedsRedraw but it does for now. | 2094 // future. The name should not refer to SetNeedsRedraw but it does for now. |
| 2139 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 2095 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
| 2140 client_->SetNeedsOneBeginImplFrameOnImplThread(); | 2096 client_->SetNeedsOneBeginImplFrameOnImplThread(); |
| 2141 } | 2097 } |
| 2142 | 2098 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2339 // Since we will create a new resource provider, we cannot continue to use | 2295 // Since we will create a new resource provider, we cannot continue to use |
| 2340 // the old resources (i.e. render_surfaces and texture IDs). Clear them | 2296 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
| 2341 // before we destroy the old resource provider. | 2297 // before we destroy the old resource provider. |
| 2342 ReleaseTreeResources(); | 2298 ReleaseTreeResources(); |
| 2343 | 2299 |
| 2344 // Note: order is important here. | 2300 // Note: order is important here. |
| 2345 renderer_ = nullptr; | 2301 renderer_ = nullptr; |
| 2346 CleanUpTileManagerAndUIResources(); | 2302 CleanUpTileManagerAndUIResources(); |
| 2347 resource_provider_ = nullptr; | 2303 resource_provider_ = nullptr; |
| 2348 | 2304 |
| 2305 // Release any context visibility before we destroy the OutputSurface. |
| 2306 if (visible_) |
| 2307 SetCompositorContextVisibility(false); |
| 2308 // Worker context visibility is based on both LTHI visibility as well as |
| 2309 // memory policy, so we directly check |worker_context_visibility_| here, |
| 2310 // rather than just relying on |visibility_|. |
| 2311 if (worker_context_visibility_) |
| 2312 SetWorkerContextVisibility(false); |
| 2313 |
| 2349 // Detach from the old output surface and reset |output_surface_| pointer | 2314 // Detach from the old output surface and reset |output_surface_| pointer |
| 2350 // as this surface is going to be destroyed independent of if binding the | 2315 // as this surface is going to be destroyed independent of if binding the |
| 2351 // new output surface succeeds or not. | 2316 // new output surface succeeds or not. |
| 2352 output_surface_->DetachFromClient(); | 2317 output_surface_->DetachFromClient(); |
| 2353 output_surface_ = nullptr; | 2318 output_surface_ = nullptr; |
| 2354 | 2319 |
| 2355 // We don't know if the next OutputSurface will support GPU rasterization. | 2320 // We don't know if the next OutputSurface will support GPU rasterization. |
| 2356 // Make sure to clear the flag so that we force a re-computation. | 2321 // Make sure to clear the flag so that we force a re-computation. |
| 2357 use_gpu_rasterization_ = false; | 2322 use_gpu_rasterization_ = false; |
| 2358 } | 2323 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2372 resource_provider_ = base::MakeUnique<ResourceProvider>( | 2337 resource_provider_ = base::MakeUnique<ResourceProvider>( |
| 2373 output_surface_->context_provider(), shared_bitmap_manager_, | 2338 output_surface_->context_provider(), shared_bitmap_manager_, |
| 2374 gpu_memory_buffer_manager_, | 2339 gpu_memory_buffer_manager_, |
| 2375 task_runner_provider_->blocking_main_thread_task_runner(), | 2340 task_runner_provider_->blocking_main_thread_task_runner(), |
| 2376 settings_.renderer_settings.highp_threshold_min, | 2341 settings_.renderer_settings.highp_threshold_min, |
| 2377 settings_.renderer_settings.texture_id_allocation_chunk_size, | 2342 settings_.renderer_settings.texture_id_allocation_chunk_size, |
| 2378 output_surface_->capabilities().delegated_sync_points_required, | 2343 output_surface_->capabilities().delegated_sync_points_required, |
| 2379 settings_.renderer_settings.use_gpu_memory_buffer_resources, | 2344 settings_.renderer_settings.use_gpu_memory_buffer_resources, |
| 2380 settings_.renderer_settings.buffer_to_texture_target_map); | 2345 settings_.renderer_settings.buffer_to_texture_target_map); |
| 2381 | 2346 |
| 2347 // Make sure the main context visibility is restored. Worker context |
| 2348 // visibility will be set via the memory policy update in |
| 2349 // CreateTileManagerResources below. |
| 2350 if (visible_) |
| 2351 SetCompositorContextVisibility(true); |
| 2352 |
| 2382 // Since the new context may be capable of MSAA, update status here. We don't | 2353 // Since the new context may be capable of MSAA, update status here. We don't |
| 2383 // need to check the return value since we are recreating all resources | 2354 // need to check the return value since we are recreating all resources |
| 2384 // already. | 2355 // already. |
| 2385 UpdateGpuRasterizationStatus(); | 2356 UpdateGpuRasterizationStatus(); |
| 2386 | 2357 |
| 2387 CreateAndSetRenderer(); | 2358 CreateAndSetRenderer(); |
| 2388 | 2359 |
| 2389 CreateTileManagerResources(); | 2360 CreateTileManagerResources(); |
| 2390 RecreateTreeResources(); | 2361 RecreateTreeResources(); |
| 2391 | 2362 |
| (...skipping 1795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4187 // Supported in threaded mode. | 4158 // Supported in threaded mode. |
| 4188 return task_runner_provider_->HasImplThread(); | 4159 return task_runner_provider_->HasImplThread(); |
| 4189 } | 4160 } |
| 4190 | 4161 |
| 4191 bool LayerTreeHostImpl::CommitToActiveTree() const { | 4162 bool LayerTreeHostImpl::CommitToActiveTree() const { |
| 4192 // In single threaded mode we skip the pending tree and commit directly to the | 4163 // In single threaded mode we skip the pending tree and commit directly to the |
| 4193 // active tree. | 4164 // active tree. |
| 4194 return !task_runner_provider_->HasImplThread(); | 4165 return !task_runner_provider_->HasImplThread(); |
| 4195 } | 4166 } |
| 4196 | 4167 |
| 4168 void LayerTreeHostImpl::SetCompositorContextVisibility(bool is_visible) { |
| 4169 if (!output_surface_) |
| 4170 return; |
| 4171 |
| 4172 auto* compositor_context = output_surface_->context_provider(); |
| 4173 if (!compositor_context) |
| 4174 return; |
| 4175 |
| 4176 DCHECK_NE(is_visible, !!compositor_context_visibility_); |
| 4177 |
| 4178 if (is_visible) { |
| 4179 compositor_context_visibility_ = |
| 4180 compositor_context->CacheController()->ClientBecameVisible(); |
| 4181 } else { |
| 4182 compositor_context->CacheController()->ClientBecameNotVisible( |
| 4183 std::move(compositor_context_visibility_)); |
| 4184 } |
| 4185 } |
| 4186 |
| 4187 void LayerTreeHostImpl::SetWorkerContextVisibility(bool is_visible) { |
| 4188 if (!output_surface_) |
| 4189 return; |
| 4190 |
| 4191 auto* worker_context = output_surface_->worker_context_provider(); |
| 4192 if (!worker_context) |
| 4193 return; |
| 4194 |
| 4195 // TODO(ericrk): This check is here because worker context visibility is a |
| 4196 // bit less controlled, being settable both by memory policy changes as well |
| 4197 // as direct visibility changes. We should simplify this. crbug.com/642154 |
| 4198 if (is_visible == !!worker_context_visibility_) |
| 4199 return; |
| 4200 |
| 4201 ContextProvider::ScopedContextLock hold(worker_context); |
| 4202 if (is_visible) { |
| 4203 worker_context_visibility_ = |
| 4204 worker_context->CacheController()->ClientBecameVisible(); |
| 4205 } else { |
| 4206 worker_context->CacheController()->ClientBecameNotVisible( |
| 4207 std::move(worker_context_visibility_)); |
| 4208 } |
| 4209 } |
| 4210 |
| 4197 } // namespace cc | 4211 } // namespace cc |
| OLD | NEW |