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

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

Issue 2501063003: Handle compositor/worker context the same wrt. visibility (Closed)
Patch Set: cleanup Created 4 years, 1 month 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') | no next file » | 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 1204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 100; 1215 100;
1216 } 1216 }
1217 global_tile_state_.memory_limit_policy = 1217 global_tile_state_.memory_limit_policy =
1218 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy( 1218 ManagedMemoryPolicy::PriorityCutoffToTileMemoryLimitPolicy(
1219 visible_ ? policy.priority_cutoff_when_visible 1219 visible_ ? policy.priority_cutoff_when_visible
1220 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); 1220 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING);
1221 global_tile_state_.num_resources_limit = policy.num_resources_limit; 1221 global_tile_state_.num_resources_limit = policy.num_resources_limit;
1222 1222
1223 if (global_tile_state_.hard_memory_limit_in_bytes > 0) { 1223 if (global_tile_state_.hard_memory_limit_in_bytes > 0) {
1224 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we 1224 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we
1225 // are visible. Notify the worker context here. We handle becoming 1225 // consider our contexts visible. Notify the contexts here. We handle
1226 // invisible in NotifyAllTileTasksComplete to avoid interrupting running 1226 // becoming invisible in NotifyAllTileTasksComplete to avoid interrupting
1227 // work. 1227 // running work.
1228 SetWorkerContextVisibility(true); 1228 SetContextVisibility(true);
1229 1229
1230 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we 1230 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we
1231 // allow the image decode controller to retain resources. We handle the 1231 // allow the image decode controller to retain resources. We handle the
1232 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting 1232 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting
1233 // running work. 1233 // running work.
1234 if (image_decode_controller_) 1234 if (image_decode_controller_)
1235 image_decode_controller_->SetShouldAggressivelyFreeResources(false); 1235 image_decode_controller_->SetShouldAggressivelyFreeResources(false);
1236 } 1236 }
1237 1237
1238 DCHECK(resource_pool_); 1238 DCHECK(resource_pool_);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 // causing optimistic requests to draw a frame. 1304 // causing optimistic requests to draw a frame.
1305 is_likely_to_require_a_draw_ = false; 1305 is_likely_to_require_a_draw_ = false;
1306 1306
1307 client_->NotifyReadyToDraw(); 1307 client_->NotifyReadyToDraw();
1308 } 1308 }
1309 1309
1310 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() { 1310 void LayerTreeHostImpl::NotifyAllTileTasksCompleted() {
1311 // The tile tasks started by the most recent call to PrepareTiles have 1311 // The tile tasks started by the most recent call to PrepareTiles have
1312 // completed. Now is a good time to free resources if necessary. 1312 // completed. Now is a good time to free resources if necessary.
1313 if (global_tile_state_.hard_memory_limit_in_bytes == 0) { 1313 if (global_tile_state_.hard_memory_limit_in_bytes == 0) {
1314 // Free image decode controller resources before notifying the worker 1314 // Free image decode controller resources before notifying the
1315 // context of visibility change. This ensures that the imaged decode 1315 // contexts of visibility change. This ensures that the imaged decode
1316 // controller has released all Skia refs at the time Skia's cleanup 1316 // controller has released all Skia refs at the time Skia's cleanup
1317 // executes (within worker context's cleanup). 1317 // executes (within worker context's cleanup).
1318 if (image_decode_controller_) 1318 if (image_decode_controller_)
1319 image_decode_controller_->SetShouldAggressivelyFreeResources(true); 1319 image_decode_controller_->SetShouldAggressivelyFreeResources(true);
1320 SetWorkerContextVisibility(false); 1320 SetContextVisibility(false);
1321 } 1321 }
1322 } 1322 }
1323 1323
1324 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { 1324 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) {
1325 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); 1325 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged");
1326 1326
1327 if (active_tree_) { 1327 if (active_tree_) {
1328 LayerImpl* layer_impl = 1328 LayerImpl* layer_impl =
1329 active_tree_->FindActiveTreeLayerById(tile->layer_id()); 1329 active_tree_->FindActiveTreeLayerById(tile->layer_id());
1330 if (layer_impl) 1330 if (layer_impl)
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 // If we just became visible, we have to ensure that we draw high res tiles, 2033 // If we just became visible, we have to ensure that we draw high res tiles,
2034 // to prevent checkerboard/low res flashes. 2034 // to prevent checkerboard/low res flashes.
2035 if (visible_) { 2035 if (visible_) {
2036 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. 2036 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw.
2037 SetRequiresHighResToDraw(); 2037 SetRequiresHighResToDraw();
2038 } else { 2038 } else {
2039 EvictAllUIResources(); 2039 EvictAllUIResources();
2040 // Call PrepareTiles to evict tiles when we become invisible. 2040 // Call PrepareTiles to evict tiles when we become invisible.
2041 PrepareTiles(); 2041 PrepareTiles();
2042 } 2042 }
2043
2044 // Update visibility for the compositor context provider.
2045 SetCompositorContextVisibility(visible);
2046 } 2043 }
2047 2044
2048 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { 2045 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() {
2049 // TODO(miletus): This is just the compositor-thread-side call to the 2046 // TODO(miletus): This is just the compositor-thread-side call to the
2050 // SwapPromiseMonitor to say something happened that may cause a swap in the 2047 // SwapPromiseMonitor to say something happened that may cause a swap in the
2051 // future. The name should not refer to SetNeedsRedraw but it does for now. 2048 // future. The name should not refer to SetNeedsRedraw but it does for now.
2052 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 2049 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
2053 client_->SetNeedsOneBeginImplFrameOnImplThread(); 2050 client_->SetNeedsOneBeginImplFrameOnImplThread();
2054 } 2051 }
2055 2052
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
2258 // Since we will create a new resource provider, we cannot continue to use 2255 // Since we will create a new resource provider, we cannot continue to use
2259 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2256 // the old resources (i.e. render_surfaces and texture IDs). Clear them
2260 // before we destroy the old resource provider. 2257 // before we destroy the old resource provider.
2261 ReleaseTreeResources(); 2258 ReleaseTreeResources();
2262 2259
2263 // Note: ui resource cleanup uses the |resource_provider_|. 2260 // Note: ui resource cleanup uses the |resource_provider_|.
2264 CleanUpTileManagerAndUIResources(); 2261 CleanUpTileManagerAndUIResources();
2265 resource_provider_ = nullptr; 2262 resource_provider_ = nullptr;
2266 2263
2267 // Release any context visibility before we destroy the CompositorFrameSink. 2264 // Release any context visibility before we destroy the CompositorFrameSink.
2268 if (visible_) 2265 SetContextVisibility(false);
2269 SetCompositorContextVisibility(false);
2270 // Worker context visibility is based on both LTHI visibility as well as
2271 // memory policy, so we directly check |worker_context_visibility_| here,
2272 // rather than just relying on |visibility_|.
2273 if (worker_context_visibility_)
2274 SetWorkerContextVisibility(false);
2275 2266
2276 // Detach from the old CompositorFrameSink and reset |compositor_frame_sink_| 2267 // Detach from the old CompositorFrameSink and reset |compositor_frame_sink_|
2277 // pointer as this surface is going to be destroyed independent of if binding 2268 // pointer as this surface is going to be destroyed independent of if binding
2278 // the new CompositorFrameSink succeeds or not. 2269 // the new CompositorFrameSink succeeds or not.
2279 compositor_frame_sink_->DetachFromClient(); 2270 compositor_frame_sink_->DetachFromClient();
2280 compositor_frame_sink_ = nullptr; 2271 compositor_frame_sink_ = nullptr;
2281 2272
2282 // We don't know if the next CompositorFrameSink will support GPU 2273 // We don't know if the next CompositorFrameSink will support GPU
2283 // rasterization. Make sure to clear the flag so that we force a 2274 // rasterization. Make sure to clear the flag so that we force a
2284 // re-computation. 2275 // re-computation.
(...skipping 25 matching lines...) Expand all
2310 compositor_frame_sink_->shared_bitmap_manager(), 2301 compositor_frame_sink_->shared_bitmap_manager(),
2311 compositor_frame_sink_->gpu_memory_buffer_manager(), 2302 compositor_frame_sink_->gpu_memory_buffer_manager(),
2312 task_runner_provider_->blocking_main_thread_task_runner(), 2303 task_runner_provider_->blocking_main_thread_task_runner(),
2313 settings_.renderer_settings.highp_threshold_min, 2304 settings_.renderer_settings.highp_threshold_min,
2314 settings_.renderer_settings.texture_id_allocation_chunk_size, 2305 settings_.renderer_settings.texture_id_allocation_chunk_size,
2315 compositor_frame_sink_->capabilities().delegated_sync_points_required, 2306 compositor_frame_sink_->capabilities().delegated_sync_points_required,
2316 settings_.renderer_settings.use_gpu_memory_buffer_resources, 2307 settings_.renderer_settings.use_gpu_memory_buffer_resources,
2317 settings_.enable_color_correct_rendering, 2308 settings_.enable_color_correct_rendering,
2318 settings_.renderer_settings.buffer_to_texture_target_map); 2309 settings_.renderer_settings.buffer_to_texture_target_map);
2319 2310
2320 // Make sure the main context visibility is restored. Worker context
2321 // visibility will be set via the memory policy update in
2322 // CreateTileManagerResources below.
2323 if (visible_)
2324 SetCompositorContextVisibility(true);
2325
2326 // Since the new context may be capable of MSAA, update status here. We don't 2311 // Since the new context may be capable of MSAA, update status here. We don't
2327 // need to check the return value since we are recreating all resources 2312 // need to check the return value since we are recreating all resources
2328 // already. 2313 // already.
2329 UpdateGpuRasterizationStatus(); 2314 UpdateGpuRasterizationStatus();
2330 2315
2331 // See note in LayerTreeImpl::UpdateDrawProperties, new CompositorFrameSink 2316 // See note in LayerTreeImpl::UpdateDrawProperties, new CompositorFrameSink
2332 // means a new max texture size which affects draw properties. Also, if the 2317 // means a new max texture size which affects draw properties. Also, if the
2333 // draw properties were up to date, layers still lost resources and we need to 2318 // draw properties were up to date, layers still lost resources and we need to
2334 // UpdateDrawProperties() after calling RecreateTreeResources(). 2319 // UpdateDrawProperties() after calling RecreateTreeResources().
2335 active_tree_->set_needs_update_draw_properties(); 2320 active_tree_->set_needs_update_draw_properties();
(...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after
4040 // Supported in threaded mode. 4025 // Supported in threaded mode.
4041 return task_runner_provider_->HasImplThread(); 4026 return task_runner_provider_->HasImplThread();
4042 } 4027 }
4043 4028
4044 bool LayerTreeHostImpl::CommitToActiveTree() const { 4029 bool LayerTreeHostImpl::CommitToActiveTree() const {
4045 // In single threaded mode we skip the pending tree and commit directly to the 4030 // In single threaded mode we skip the pending tree and commit directly to the
4046 // active tree. 4031 // active tree.
4047 return !task_runner_provider_->HasImplThread(); 4032 return !task_runner_provider_->HasImplThread();
4048 } 4033 }
4049 4034
4050 void LayerTreeHostImpl::SetCompositorContextVisibility(bool is_visible) { 4035 void LayerTreeHostImpl::SetContextVisibility(bool is_visible) {
4051 if (!compositor_frame_sink_) 4036 if (!compositor_frame_sink_)
4052 return; 4037 return;
4053 4038
4039 // Update the compositor context. If we are already in the correct visibility
4040 // state, skip. This can happen if we transition invisible/visible rapidly,
4041 // before we get a chance to go invisible in NotifyAllTileTasksComplete.
4054 auto* compositor_context = compositor_frame_sink_->context_provider(); 4042 auto* compositor_context = compositor_frame_sink_->context_provider();
4055 if (!compositor_context) 4043 if (compositor_context && is_visible != !!compositor_context_visibility_) {
4056 return; 4044 if (is_visible) {
4045 compositor_context_visibility_ =
4046 compositor_context->CacheController()->ClientBecameVisible();
4047 } else {
4048 compositor_context->CacheController()->ClientBecameNotVisible(
4049 std::move(compositor_context_visibility_));
4050 }
4051 }
4057 4052
4058 DCHECK_NE(is_visible, !!compositor_context_visibility_); 4053 // Update the worker context. If we are already in the correct visibility
4059 4054 // state, skip. This can happen if we transition invisible/visible rapidly,
4060 if (is_visible) { 4055 // before we get a chance to go invisible in NotifyAllTileTasksComplete.
4061 compositor_context_visibility_ = 4056 auto* worker_context = compositor_frame_sink_->worker_context_provider();
4062 compositor_context->CacheController()->ClientBecameVisible(); 4057 if (worker_context && is_visible != !!worker_context_visibility_) {
4063 } else { 4058 ContextProvider::ScopedContextLock hold(worker_context);
4064 compositor_context->CacheController()->ClientBecameNotVisible( 4059 if (is_visible) {
4065 std::move(compositor_context_visibility_)); 4060 worker_context_visibility_ =
4061 worker_context->CacheController()->ClientBecameVisible();
4062 } else {
4063 worker_context->CacheController()->ClientBecameNotVisible(
4064 std::move(worker_context_visibility_));
4065 }
4066 } 4066 }
4067 } 4067 }
4068 4068
4069 void LayerTreeHostImpl::SetWorkerContextVisibility(bool is_visible) {
4070 if (!compositor_frame_sink_)
4071 return;
4072
4073 auto* worker_context = compositor_frame_sink_->worker_context_provider();
4074 if (!worker_context)
4075 return;
4076
4077 // TODO(ericrk): This check is here because worker context visibility is a
4078 // bit less controlled, being settable both by memory policy changes as well
4079 // as direct visibility changes. We should simplify this. crbug.com/642154
4080 if (is_visible == !!worker_context_visibility_)
4081 return;
4082
4083 ContextProvider::ScopedContextLock hold(worker_context);
4084 if (is_visible) {
4085 worker_context_visibility_ =
4086 worker_context->CacheController()->ClientBecameVisible();
4087 } else {
4088 worker_context->CacheController()->ClientBecameNotVisible(
4089 std::move(worker_context_visibility_));
4090 }
4091 }
4092
4093 } // namespace cc 4069 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/layer_tree_host_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698