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

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

Issue 2252163003: Update Context Client Visibility to use Scoped Pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: feedback Created 4 years, 4 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
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 #include "cc/trees/damage_tracker.h" 77 #include "cc/trees/damage_tracker.h"
78 #include "cc/trees/draw_property_utils.h" 78 #include "cc/trees/draw_property_utils.h"
79 #include "cc/trees/latency_info_swap_promise_monitor.h" 79 #include "cc/trees/latency_info_swap_promise_monitor.h"
80 #include "cc/trees/layer_tree_host.h" 80 #include "cc/trees/layer_tree_host.h"
81 #include "cc/trees/layer_tree_host_common.h" 81 #include "cc/trees/layer_tree_host_common.h"
82 #include "cc/trees/layer_tree_impl.h" 82 #include "cc/trees/layer_tree_impl.h"
83 #include "cc/trees/scroll_node.h" 83 #include "cc/trees/scroll_node.h"
84 #include "cc/trees/single_thread_proxy.h" 84 #include "cc/trees/single_thread_proxy.h"
85 #include "cc/trees/tree_synchronizer.h" 85 #include "cc/trees/tree_synchronizer.h"
86 #include "gpu/GLES2/gl2extchromium.h" 86 #include "gpu/GLES2/gl2extchromium.h"
87 #include "gpu/command_buffer/client/context_support.h"
88 #include "gpu/command_buffer/client/gles2_interface.h" 87 #include "gpu/command_buffer/client/gles2_interface.h"
89 #include "ui/gfx/geometry/point_conversions.h" 88 #include "ui/gfx/geometry/point_conversions.h"
90 #include "ui/gfx/geometry/rect_conversions.h" 89 #include "ui/gfx/geometry/rect_conversions.h"
91 #include "ui/gfx/geometry/scroll_offset.h" 90 #include "ui/gfx/geometry/scroll_offset.h"
92 #include "ui/gfx/geometry/size_conversions.h" 91 #include "ui/gfx/geometry/size_conversions.h"
93 #include "ui/gfx/geometry/vector2d_conversions.h" 92 #include "ui/gfx/geometry/vector2d_conversions.h"
94 93
95 namespace cc { 94 namespace cc {
96 namespace { 95 namespace {
97 96
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 bool scroll_on_main_thread = (scroll_thread == MAIN_THREAD); 149 bool scroll_on_main_thread = (scroll_thread == MAIN_THREAD);
151 if (IsWheelBasedScroll(type)) { 150 if (IsWheelBasedScroll(type)) {
152 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorWheelScrollUpdateThread", 151 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorWheelScrollUpdateThread",
153 scroll_on_main_thread); 152 scroll_on_main_thread);
154 } else { 153 } else {
155 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorTouchScrollUpdateThread", 154 UMA_HISTOGRAM_BOOLEAN("Renderer4.CompositorTouchScrollUpdateThread",
156 scroll_on_main_thread); 155 scroll_on_main_thread);
157 } 156 }
158 } 157 }
159 158
160 // Calls SetClientVisible on the provided |context_provider| and handles 159 void UpdateVisibilityForContextProvider(
161 // additional cache cleanup. 160 ContextProvider* context_provider,
162 void UpdateVisibilityForContextProvider(int client_id, 161 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>* scoped_visibility,
163 ContextProvider* context_provider, 162 bool is_visible) {
164 bool is_visible) {
165 if (!context_provider) 163 if (!context_provider)
166 return; 164 return;
165 if (!!*scoped_visibility == is_visible)
166 return;
167
167 gpu::ContextSupport* context_support = context_provider->ContextSupport(); 168 gpu::ContextSupport* context_support = context_provider->ContextSupport();
168 169
169 context_support->SetClientVisible(client_id, is_visible); 170 if (is_visible)
171 *scoped_visibility = context_support->ClientBecameVisible();
172 else
173 context_support->ClientBecameNotVisible(std::move(*scoped_visibility));
174
170 bool aggressively_free_resources = !context_support->AnyClientsVisible(); 175 bool aggressively_free_resources = !context_support->AnyClientsVisible();
171 if (aggressively_free_resources) { 176 if (aggressively_free_resources)
172 context_provider->DeleteCachedResources(); 177 context_provider->DeleteCachedResources();
173 }
174 context_support->SetAggressivelyFreeResources(aggressively_free_resources); 178 context_support->SetAggressivelyFreeResources(aggressively_free_resources);
175 } 179 }
176 180
177 // Same as UpdateVisibilityForContextProvider, except that the 181 // Same as UpdateVisibilityForContextProvider, except that the
178 // |context_provider| is locked before being used. 182 // |context_provider| is locked before being used.
179 void LockAndUpdateVisibilityForContextProvider( 183 void LockAndUpdateVisibilityForContextProvider(
180 int client_id,
181 ContextProvider* context_provider, 184 ContextProvider* context_provider,
185 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>* scoped_visibility,
182 bool is_visible) { 186 bool is_visible) {
183 if (!context_provider) 187 if (!context_provider)
184 return; 188 return;
189 if (!!*scoped_visibility == is_visible)
190 return;
191
185 ContextProvider::ScopedContextLock hold(context_provider); 192 ContextProvider::ScopedContextLock hold(context_provider);
186 UpdateVisibilityForContextProvider(client_id, context_provider, is_visible); 193 UpdateVisibilityForContextProvider(context_provider, scoped_visibility,
194 is_visible);
187 } 195 }
188 196
189 } // namespace 197 } // namespace
190 198
191 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer, 199 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer,
192 "Scheduling.%s.PendingTreeDuration"); 200 "Scheduling.%s.PendingTreeDuration");
193 201
194 LayerTreeHostImpl::FrameData::FrameData() 202 LayerTreeHostImpl::FrameData::FrameData()
195 : render_surface_layer_list(nullptr), 203 : render_surface_layer_list(nullptr),
196 has_no_damage(false), 204 has_no_damage(false),
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); 1299 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING);
1292 global_tile_state_.num_resources_limit = policy.num_resources_limit; 1300 global_tile_state_.num_resources_limit = policy.num_resources_limit;
1293 1301
1294 if (global_tile_state_.hard_memory_limit_in_bytes > 0) { 1302 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 1303 // 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 1304 // are visible. Notify the worker context here. We handle becoming
1297 // invisible in NotifyAllTileTasksComplete to avoid interrupting running 1305 // invisible in NotifyAllTileTasksComplete to avoid interrupting running
1298 // work. 1306 // work.
1299 if (output_surface_) { 1307 if (output_surface_) {
1300 LockAndUpdateVisibilityForContextProvider( 1308 LockAndUpdateVisibilityForContextProvider(
1301 id_, output_surface_->worker_context_provider(), 1309 output_surface_->worker_context_provider(),
1302 true /* is_visible */); 1310 &worker_context_client_visibility_, true /* is_visible */);
1303 } 1311 }
1304 1312
1305 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we 1313 // 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 1314 // allow the image decode controller to retain resources. We handle the
1307 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting 1315 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting
1308 // running work. 1316 // running work.
1309 if (image_decode_controller_) { 1317 if (image_decode_controller_) {
1310 image_decode_controller_->SetShouldAggressivelyFreeResources( 1318 image_decode_controller_->SetShouldAggressivelyFreeResources(
1311 false /* aggressively_free_resources */); 1319 false /* aggressively_free_resources */);
1312 } 1320 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // Free image decode controller resources before notifying the worker 1393 // Free image decode controller resources before notifying the worker
1386 // context of visibility change. This ensures that the imaged decode 1394 // context of visibility change. This ensures that the imaged decode
1387 // controller has released all Skia refs at the time Skia's cleanup 1395 // controller has released all Skia refs at the time Skia's cleanup
1388 // executes (within worker context's cleanup). 1396 // executes (within worker context's cleanup).
1389 if (image_decode_controller_) { 1397 if (image_decode_controller_) {
1390 image_decode_controller_->SetShouldAggressivelyFreeResources( 1398 image_decode_controller_->SetShouldAggressivelyFreeResources(
1391 true /* aggressively_free_resources */); 1399 true /* aggressively_free_resources */);
1392 } 1400 }
1393 if (output_surface_) { 1401 if (output_surface_) {
1394 LockAndUpdateVisibilityForContextProvider( 1402 LockAndUpdateVisibilityForContextProvider(
1395 id_, output_surface_->worker_context_provider(), 1403 output_surface_->worker_context_provider(),
1396 false /* is_visible */); 1404 &worker_context_client_visibility_, false /* is_visible */);
1397 } 1405 }
1398 } 1406 }
1399 } 1407 }
1400 1408
1401 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { 1409 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) {
1402 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); 1410 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged");
1403 1411
1404 if (active_tree_) { 1412 if (active_tree_) {
1405 LayerImpl* layer_impl = 1413 LayerImpl* layer_impl =
1406 active_tree_->FindActiveTreeLayerById(tile->layer_id()); 1414 active_tree_->FindActiveTreeLayerById(tile->layer_id());
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. 2125 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw.
2118 SetRequiresHighResToDraw(); 2126 SetRequiresHighResToDraw();
2119 } else { 2127 } else {
2120 EvictAllUIResources(); 2128 EvictAllUIResources();
2121 // Call PrepareTiles to evict tiles when we become invisible. 2129 // Call PrepareTiles to evict tiles when we become invisible.
2122 PrepareTiles(); 2130 PrepareTiles();
2123 } 2131 }
2124 2132
2125 // Update visibility for the compositor context provider. 2133 // Update visibility for the compositor context provider.
2126 if (output_surface_) { 2134 if (output_surface_) {
2127 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), 2135 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
2136 &main_context_client_visibility_,
2128 visible); 2137 visible);
2129 } 2138 }
2130 } 2139 }
2131 2140
2132 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { 2141 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() {
2133 // TODO(miletus): This is just the compositor-thread-side call to the 2142 // TODO(miletus): This is just the compositor-thread-side call to the
2134 // SwapPromiseMonitor to say something happened that may cause a swap in the 2143 // SwapPromiseMonitor to say something happened that may cause a swap in the
2135 // future. The name should not refer to SetNeedsRedraw but it does for now. 2144 // future. The name should not refer to SetNeedsRedraw but it does for now.
2136 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 2145 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
2137 client_->SetNeedsOneBeginImplFrameOnImplThread(); 2146 client_->SetNeedsOneBeginImplFrameOnImplThread();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 // Since we will create a new resource provider, we cannot continue to use 2340 // Since we will create a new resource provider, we cannot continue to use
2332 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2341 // the old resources (i.e. render_surfaces and texture IDs). Clear them
2333 // before we destroy the old resource provider. 2342 // before we destroy the old resource provider.
2334 ReleaseTreeResources(); 2343 ReleaseTreeResources();
2335 2344
2336 // Note: order is important here. 2345 // Note: order is important here.
2337 renderer_ = nullptr; 2346 renderer_ = nullptr;
2338 CleanUpTileManagerAndUIResources(); 2347 CleanUpTileManagerAndUIResources();
2339 resource_provider_ = nullptr; 2348 resource_provider_ = nullptr;
2340 2349
2341 // Detach from the old output surface and reset |output_surface_| pointer
2342 // as this surface is going to be destroyed independent of if binding the
2343 // new output surface succeeds or not.
2344 if (output_surface_) { 2350 if (output_surface_) {
2351 // Ensure that any context client visibility is left in a good state.
2352 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
2353 &main_context_client_visibility_, false);
2354 LockAndUpdateVisibilityForContextProvider(
2355 output_surface_->worker_context_provider(),
2356 &worker_context_client_visibility_, false);
2357
2358 // Detach from the old output surface and reset |output_surface_| pointer
2359 // as this surface is going to be destroyed independent of if binding the
2360 // new output surface succeeds or not.
2345 output_surface_->DetachFromClient(); 2361 output_surface_->DetachFromClient();
2346 output_surface_ = nullptr; 2362 output_surface_ = nullptr;
2347 } 2363 }
2348 2364
2349 // We don't know if the next OutputSurface will support GPU rasterization. 2365 // We don't know if the next OutputSurface will support GPU rasterization.
2350 // Make sure to clear the flag so that we force a re-computation. 2366 // Make sure to clear the flag so that we force a re-computation.
2351 use_gpu_rasterization_ = false; 2367 use_gpu_rasterization_ = false;
2352 } 2368 }
2353 2369
2354 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { 2370 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) {
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
4088 return task_runner_provider_->HasImplThread(); 4104 return task_runner_provider_->HasImplThread();
4089 } 4105 }
4090 4106
4091 bool LayerTreeHostImpl::CommitToActiveTree() const { 4107 bool LayerTreeHostImpl::CommitToActiveTree() const {
4092 // In single threaded mode we skip the pending tree and commit directly to the 4108 // In single threaded mode we skip the pending tree and commit directly to the
4093 // active tree. 4109 // active tree.
4094 return !task_runner_provider_->HasImplThread(); 4110 return !task_runner_provider_->HasImplThread();
4095 } 4111 }
4096 4112
4097 } // namespace cc 4113 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698