Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: cc/trees/layer_tree_host_impl.cc

Issue 2357673002: Refactor client visibility handling (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2336 // Since we will create a new resource provider, we cannot continue to use 2292 // Since we will create a new resource provider, we cannot continue to use
2337 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2293 // the old resources (i.e. render_surfaces and texture IDs). Clear them
2338 // before we destroy the old resource provider. 2294 // before we destroy the old resource provider.
2339 ReleaseTreeResources(); 2295 ReleaseTreeResources();
2340 2296
2341 // Note: order is important here. 2297 // Note: order is important here.
2342 renderer_ = nullptr; 2298 renderer_ = nullptr;
2343 CleanUpTileManagerAndUIResources(); 2299 CleanUpTileManagerAndUIResources();
2344 resource_provider_ = nullptr; 2300 resource_provider_ = nullptr;
2345 2301
2302 // Release any context visibility before we destroy the OutputSurface.
2303 if (visible_)
2304 SetCompositorContextVisibility(false);
2305 // Worker context visibility is based on both LTHI visibility as well as
2306 // memory policy, so we directly check |worker_context_visibility_| here,
2307 // rather than just relying on |visibility_|.
2308 if (worker_context_visibility_)
2309 SetWorkerContextVisibility(false);
2310
2346 // Detach from the old output surface and reset |output_surface_| pointer 2311 // Detach from the old output surface and reset |output_surface_| pointer
2347 // as this surface is going to be destroyed independent of if binding the 2312 // as this surface is going to be destroyed independent of if binding the
2348 // new output surface succeeds or not. 2313 // new output surface succeeds or not.
2349 if (output_surface_) { 2314 if (output_surface_) {
2350 output_surface_->DetachFromClient(); 2315 output_surface_->DetachFromClient();
2351 output_surface_ = nullptr; 2316 output_surface_ = nullptr;
2352 } 2317 }
2353 2318
2354 // We don't know if the next OutputSurface will support GPU rasterization. 2319 // We don't know if the next OutputSurface will support GPU rasterization.
2355 // Make sure to clear the flag so that we force a re-computation. 2320 // Make sure to clear the flag so that we force a re-computation.
(...skipping 15 matching lines...) Expand all
2371 resource_provider_ = base::MakeUnique<ResourceProvider>( 2336 resource_provider_ = base::MakeUnique<ResourceProvider>(
2372 output_surface_->context_provider(), shared_bitmap_manager_, 2337 output_surface_->context_provider(), shared_bitmap_manager_,
2373 gpu_memory_buffer_manager_, 2338 gpu_memory_buffer_manager_,
2374 task_runner_provider_->blocking_main_thread_task_runner(), 2339 task_runner_provider_->blocking_main_thread_task_runner(),
2375 settings_.renderer_settings.highp_threshold_min, 2340 settings_.renderer_settings.highp_threshold_min,
2376 settings_.renderer_settings.texture_id_allocation_chunk_size, 2341 settings_.renderer_settings.texture_id_allocation_chunk_size,
2377 output_surface_->capabilities().delegated_sync_points_required, 2342 output_surface_->capabilities().delegated_sync_points_required,
2378 settings_.renderer_settings.use_gpu_memory_buffer_resources, 2343 settings_.renderer_settings.use_gpu_memory_buffer_resources,
2379 settings_.renderer_settings.buffer_to_texture_target_map); 2344 settings_.renderer_settings.buffer_to_texture_target_map);
2380 2345
2346 // Make sure the main context visibility is restored. Worker context
2347 // visibility will be set via the memory policy update in
2348 // CreateTileManagerResources below.
2349 if (visible_)
2350 SetCompositorContextVisibility(true);
2351
2381 // Since the new context may be capable of MSAA, update status here. We don't 2352 // Since the new context may be capable of MSAA, update status here. We don't
2382 // need to check the return value since we are recreating all resources 2353 // need to check the return value since we are recreating all resources
2383 // already. 2354 // already.
2384 UpdateGpuRasterizationStatus(); 2355 UpdateGpuRasterizationStatus();
2385 2356
2386 CreateAndSetRenderer(); 2357 CreateAndSetRenderer();
2387 2358
2388 CreateTileManagerResources(); 2359 CreateTileManagerResources();
2389 RecreateTreeResources(); 2360 RecreateTreeResources();
2390 2361
(...skipping 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 // Supported in threaded mode. 4152 // Supported in threaded mode.
4182 return task_runner_provider_->HasImplThread(); 4153 return task_runner_provider_->HasImplThread();
4183 } 4154 }
4184 4155
4185 bool LayerTreeHostImpl::CommitToActiveTree() const { 4156 bool LayerTreeHostImpl::CommitToActiveTree() const {
4186 // In single threaded mode we skip the pending tree and commit directly to the 4157 // In single threaded mode we skip the pending tree and commit directly to the
4187 // active tree. 4158 // active tree.
4188 return !task_runner_provider_->HasImplThread(); 4159 return !task_runner_provider_->HasImplThread();
4189 } 4160 }
4190 4161
4162 void LayerTreeHostImpl::SetCompositorContextVisibility(bool is_visible) {
4163 if (!output_surface_)
4164 return;
4165
4166 auto* compositor_context = output_surface_->context_provider();
4167 if (!compositor_context)
4168 return;
4169
4170 DCHECK_NE(is_visible, !!compositor_context_visibility_);
4171
4172 if (is_visible) {
4173 compositor_context_visibility_ =
4174 compositor_context->CacheController()->ClientBecameVisible();
4175 } else {
4176 compositor_context->CacheController()->ClientBecameNotVisible(
4177 std::move(compositor_context_visibility_));
4178 }
4179 }
4180
4181 void LayerTreeHostImpl::SetWorkerContextVisibility(bool is_visible) {
4182 if (!output_surface_)
4183 return;
4184
4185 auto* worker_context = output_surface_->worker_context_provider();
4186 if (!worker_context)
4187 return;
4188
4189 // TODO(ericrk): This check is here because worker context visibility is a
4190 // bit less controlled, being settable both by memory policy changes as well
4191 // as direct visibility changes. We should simplify this. crbug.com/642154
4192 if (is_visible == !!worker_context_visibility_)
4193 return;
4194
4195 ContextProvider::ScopedContextLock hold(worker_context);
4196 if (is_visible) {
4197 worker_context_visibility_ =
4198 worker_context->CacheController()->ClientBecameVisible();
4199 } else {
4200 worker_context->CacheController()->ClientBecameNotVisible(
4201 std::move(worker_context_visibility_));
4202 }
4203 }
4204
4191 } // namespace cc 4205 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | cc/trees/layer_tree_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698