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 /* is_visible */); |
|
danakj
2016/08/26 23:49:09
i think the name of this bool is in the function n
ericrk
2016/08/29 22:43:22
Done.
| |
| 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( |
| 1311 false /* aggressively_free_resources */); | 1278 false /* aggressively_free_resources */); |
| 1312 } | 1279 } |
| 1313 } | 1280 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1383 // completed. Now is a good time to free resources if necessary. | 1350 // completed. Now is a good time to free resources if necessary. |
| 1384 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { | 1351 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { |
| 1385 // Free image decode controller resources before notifying the worker | 1352 // Free image decode controller resources before notifying the worker |
| 1386 // context of visibility change. This ensures that the imaged decode | 1353 // context of visibility change. This ensures that the imaged decode |
| 1387 // controller has released all Skia refs at the time Skia's cleanup | 1354 // controller has released all Skia refs at the time Skia's cleanup |
| 1388 // executes (within worker context's cleanup). | 1355 // executes (within worker context's cleanup). |
| 1389 if (image_decode_controller_) { | 1356 if (image_decode_controller_) { |
| 1390 image_decode_controller_->SetShouldAggressivelyFreeResources( | 1357 image_decode_controller_->SetShouldAggressivelyFreeResources( |
| 1391 true /* aggressively_free_resources */); | 1358 true /* aggressively_free_resources */); |
| 1392 } | 1359 } |
| 1393 if (output_surface_) { | 1360 SetWorkerContextVisibility(false /* is_visible */); |
|
danakj
2016/08/26 23:49:09
dittos
ericrk
2016/08/29 22:43:23
Done.
| |
| 1394 LockAndUpdateVisibilityForContextProvider( | |
| 1395 id_, output_surface_->worker_context_provider(), | |
| 1396 false /* is_visible */); | |
| 1397 } | |
| 1398 } | 1361 } |
| 1399 } | 1362 } |
| 1400 | 1363 |
| 1401 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { | 1364 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { |
| 1402 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); | 1365 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); |
| 1403 | 1366 |
| 1404 if (active_tree_) { | 1367 if (active_tree_) { |
| 1405 LayerImpl* layer_impl = | 1368 LayerImpl* layer_impl = |
| 1406 active_tree_->FindActiveTreeLayerById(tile->layer_id()); | 1369 active_tree_->FindActiveTreeLayerById(tile->layer_id()); |
| 1407 if (layer_impl) | 1370 if (layer_impl) |
| (...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2125 if (visible_) { | 2088 if (visible_) { |
| 2126 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. | 2089 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. |
| 2127 SetRequiresHighResToDraw(); | 2090 SetRequiresHighResToDraw(); |
| 2128 } else { | 2091 } else { |
| 2129 EvictAllUIResources(); | 2092 EvictAllUIResources(); |
| 2130 // Call PrepareTiles to evict tiles when we become invisible. | 2093 // Call PrepareTiles to evict tiles when we become invisible. |
| 2131 PrepareTiles(); | 2094 PrepareTiles(); |
| 2132 } | 2095 } |
| 2133 | 2096 |
| 2134 // Update visibility for the compositor context provider. | 2097 // Update visibility for the compositor context provider. |
| 2135 if (output_surface_) { | 2098 SetMainContextVisibility(visible); |
| 2136 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), | |
| 2137 visible); | |
| 2138 } | |
| 2139 } | 2099 } |
| 2140 | 2100 |
| 2141 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { | 2101 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { |
| 2142 // TODO(miletus): This is just the compositor-thread-side call to the | 2102 // 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 | 2103 // 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. | 2104 // future. The name should not refer to SetNeedsRedraw but it does for now. |
| 2145 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 2105 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
| 2146 client_->SetNeedsOneBeginImplFrameOnImplThread(); | 2106 client_->SetNeedsOneBeginImplFrameOnImplThread(); |
| 2147 } | 2107 } |
| 2148 | 2108 |
| (...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 | 2303 // 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 | 2304 // the old resources (i.e. render_surfaces and texture IDs). Clear them |
| 2345 // before we destroy the old resource provider. | 2305 // before we destroy the old resource provider. |
| 2346 ReleaseTreeResources(); | 2306 ReleaseTreeResources(); |
| 2347 | 2307 |
| 2348 // Note: order is important here. | 2308 // Note: order is important here. |
| 2349 renderer_ = nullptr; | 2309 renderer_ = nullptr; |
| 2350 CleanUpTileManagerAndUIResources(); | 2310 CleanUpTileManagerAndUIResources(); |
| 2351 resource_provider_ = nullptr; | 2311 resource_provider_ = nullptr; |
| 2352 | 2312 |
| 2313 // Release any context visibility before we destroy the OutputSurface. | |
| 2314 SetMainContextVisibility(false /* is_visible */); | |
|
danakj
2016/08/26 23:49:09
dittos
ericrk
2016/08/29 22:43:23
Done.
| |
| 2315 SetWorkerContextVisibility(false /* is_visible */); | |
| 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. |
| 2363 use_gpu_rasterization_ = false; | 2327 use_gpu_rasterization_ = false; |
| 2364 } | 2328 } |
| 2365 | 2329 |
| 2366 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { | 2330 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { |
| 2367 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); | 2331 TRACE_EVENT0("cc", "LayerTreeHostImpl::InitializeRenderer"); |
| 2368 | 2332 |
| 2369 ReleaseOutputSurface(); | 2333 ReleaseOutputSurface(); |
| 2370 if (!output_surface->BindToClient(this)) { | 2334 if (!output_surface->BindToClient(this)) { |
| 2371 // Avoid recreating tree resources because we might not have enough | 2335 // Avoid recreating tree resources because we might not have enough |
| 2372 // information to do this yet (eg. we don't have a TileManager at this | 2336 // information to do this yet (eg. we don't have a TileManager at this |
| 2373 // point). | 2337 // point). |
| 2374 return false; | 2338 return false; |
| 2375 } | 2339 } |
| 2376 | 2340 |
| 2377 output_surface_ = output_surface; | 2341 output_surface_ = output_surface; |
|
danakj
2016/08/26 23:49:08
Should we set visibility on the compositor context
ericrk
2016/08/29 22:43:23
Yeah, if we are visible_, and only for the main co
| |
| 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 |
| (...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4122 // Supported in threaded mode. | 4086 // Supported in threaded mode. |
| 4123 return task_runner_provider_->HasImplThread(); | 4087 return task_runner_provider_->HasImplThread(); |
| 4124 } | 4088 } |
| 4125 | 4089 |
| 4126 bool LayerTreeHostImpl::CommitToActiveTree() const { | 4090 bool LayerTreeHostImpl::CommitToActiveTree() const { |
| 4127 // In single threaded mode we skip the pending tree and commit directly to the | 4091 // In single threaded mode we skip the pending tree and commit directly to the |
| 4128 // active tree. | 4092 // active tree. |
| 4129 return !task_runner_provider_->HasImplThread(); | 4093 return !task_runner_provider_->HasImplThread(); |
| 4130 } | 4094 } |
| 4131 | 4095 |
| 4096 void LayerTreeHostImpl::SetMainContextVisibility(bool is_visible) { | |
| 4097 if (is_visible == !!main_context_visibility_) | |
|
danakj
2016/08/26 23:49:09
Is it actually possible to have this early out hap
ericrk
2016/08/29 22:43:22
Sure, only change I may need to make is not call i
| |
| 4098 return; | |
| 4099 | |
| 4100 if (!output_surface_) | |
| 4101 return; | |
| 4102 | |
| 4103 auto* main_context = output_surface_->context_provider(); | |
| 4104 | |
|
danakj
2016/08/26 23:49:08
nit: remove whitespace
ericrk
2016/08/29 22:43:23
Done.
| |
| 4105 if (!main_context) | |
| 4106 return; | |
| 4107 | |
| 4108 if (is_visible) { | |
| 4109 main_context_visibility_ = | |
| 4110 main_context->CacheController()->ClientBecameVisible(); | |
| 4111 } else { | |
| 4112 main_context->CacheController()->ClientBecameNotVisible( | |
| 4113 std::move(main_context_visibility_)); | |
| 4114 } | |
| 4115 } | |
| 4116 | |
| 4117 void LayerTreeHostImpl::SetWorkerContextVisibility(bool is_visible) { | |
| 4118 if (is_visible == !!worker_context_visibility_) | |
|
danakj
2016/08/26 23:49:08
Same Q
ericrk
2016/08/29 22:43:23
Worker context visibility is handled through both
| |
| 4119 return; | |
| 4120 | |
| 4121 if (!output_surface_) | |
| 4122 return; | |
| 4123 | |
| 4124 auto* worker_context = output_surface_->worker_context_provider(); | |
| 4125 | |
|
danakj
2016/08/26 23:49:09
nit: remove whitespace
fwiw I try to think of emp
ericrk
2016/08/29 22:43:23
Done.
| |
| 4126 if (!worker_context) | |
| 4127 return; | |
| 4128 | |
| 4129 ContextProvider::ScopedContextLock hold(worker_context); | |
| 4130 | |
|
danakj
2016/08/26 23:49:09
nit: remove whitespace
ericrk
2016/08/29 22:43:22
Done.
| |
| 4131 if (is_visible) { | |
| 4132 worker_context_visibility_ = | |
| 4133 worker_context->CacheController()->ClientBecameVisible(); | |
| 4134 } else { | |
| 4135 worker_context->CacheController()->ClientBecameNotVisible( | |
| 4136 std::move(worker_context_visibility_)); | |
| 4137 } | |
| 4138 } | |
| 4139 | |
| 4132 } // namespace cc | 4140 } // namespace cc |
| OLD | NEW |