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

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: fix webview 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 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)
170 bool aggressively_free_resources = !context_support->AnyClientsVisible(); 171 *scoped_visibility = context_support->ClientBecameVisible();
171 if (aggressively_free_resources) { 172 else
173 context_support->ClientBecameNotVisible(std::move(*scoped_visibility));
174
175 if (!context_support->AnyClientsVisible())
172 context_provider->DeleteCachedResources(); 176 context_provider->DeleteCachedResources();
173 }
174 context_support->SetAggressivelyFreeResources(aggressively_free_resources);
175 } 177 }
176 178
177 // Same as UpdateVisibilityForContextProvider, except that the 179 // Same as UpdateVisibilityForContextProvider, except that the
178 // |context_provider| is locked before being used. 180 // |context_provider| is locked before being used.
179 void LockAndUpdateVisibilityForContextProvider( 181 void LockAndUpdateVisibilityForContextProvider(
180 int client_id,
181 ContextProvider* context_provider, 182 ContextProvider* context_provider,
183 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>* scoped_visibility,
182 bool is_visible) { 184 bool is_visible) {
183 if (!context_provider) 185 if (!context_provider)
184 return; 186 return;
187 if (!!*scoped_visibility == is_visible)
188 return;
189
185 ContextProvider::ScopedContextLock hold(context_provider); 190 ContextProvider::ScopedContextLock hold(context_provider);
186 UpdateVisibilityForContextProvider(client_id, context_provider, is_visible); 191 UpdateVisibilityForContextProvider(context_provider, scoped_visibility,
192 is_visible);
187 } 193 }
188 194
189 } // namespace 195 } // namespace
190 196
191 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer, 197 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer,
192 "Scheduling.%s.PendingTreeDuration"); 198 "Scheduling.%s.PendingTreeDuration");
193 199
194 LayerTreeHostImpl::FrameData::FrameData() 200 LayerTreeHostImpl::FrameData::FrameData()
195 : render_surface_layer_list(nullptr), 201 : render_surface_layer_list(nullptr),
196 has_no_damage(false), 202 has_no_damage(false),
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); 1297 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING);
1292 global_tile_state_.num_resources_limit = policy.num_resources_limit; 1298 global_tile_state_.num_resources_limit = policy.num_resources_limit;
1293 1299
1294 if (global_tile_state_.hard_memory_limit_in_bytes > 0) { 1300 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 1301 // 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 1302 // are visible. Notify the worker context here. We handle becoming
1297 // invisible in NotifyAllTileTasksComplete to avoid interrupting running 1303 // invisible in NotifyAllTileTasksComplete to avoid interrupting running
1298 // work. 1304 // work.
1299 if (output_surface_) { 1305 if (output_surface_) {
1300 LockAndUpdateVisibilityForContextProvider( 1306 LockAndUpdateVisibilityForContextProvider(
1301 id_, output_surface_->worker_context_provider(), 1307 output_surface_->worker_context_provider(),
1302 true /* is_visible */); 1308 &worker_context_client_visibility_, true /* is_visible */);
1303 } 1309 }
1304 1310
1305 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we 1311 // 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 1312 // allow the image decode controller to retain resources. We handle the
1307 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting 1313 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting
1308 // running work. 1314 // running work.
1309 if (image_decode_controller_) { 1315 if (image_decode_controller_) {
1310 image_decode_controller_->SetShouldAggressivelyFreeResources( 1316 image_decode_controller_->SetShouldAggressivelyFreeResources(
1311 false /* aggressively_free_resources */); 1317 false /* aggressively_free_resources */);
1312 } 1318 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // Free image decode controller resources before notifying the worker 1391 // Free image decode controller resources before notifying the worker
1386 // context of visibility change. This ensures that the imaged decode 1392 // context of visibility change. This ensures that the imaged decode
1387 // controller has released all Skia refs at the time Skia's cleanup 1393 // controller has released all Skia refs at the time Skia's cleanup
1388 // executes (within worker context's cleanup). 1394 // executes (within worker context's cleanup).
1389 if (image_decode_controller_) { 1395 if (image_decode_controller_) {
1390 image_decode_controller_->SetShouldAggressivelyFreeResources( 1396 image_decode_controller_->SetShouldAggressivelyFreeResources(
1391 true /* aggressively_free_resources */); 1397 true /* aggressively_free_resources */);
1392 } 1398 }
1393 if (output_surface_) { 1399 if (output_surface_) {
1394 LockAndUpdateVisibilityForContextProvider( 1400 LockAndUpdateVisibilityForContextProvider(
1395 id_, output_surface_->worker_context_provider(), 1401 output_surface_->worker_context_provider(),
1396 false /* is_visible */); 1402 &worker_context_client_visibility_, false /* is_visible */);
1397 } 1403 }
1398 } 1404 }
1399 } 1405 }
1400 1406
1401 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { 1407 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) {
1402 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); 1408 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged");
1403 1409
1404 if (active_tree_) { 1410 if (active_tree_) {
1405 LayerImpl* layer_impl = 1411 LayerImpl* layer_impl =
1406 active_tree_->FindActiveTreeLayerById(tile->layer_id()); 1412 active_tree_->FindActiveTreeLayerById(tile->layer_id());
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. 2132 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw.
2127 SetRequiresHighResToDraw(); 2133 SetRequiresHighResToDraw();
2128 } else { 2134 } else {
2129 EvictAllUIResources(); 2135 EvictAllUIResources();
2130 // Call PrepareTiles to evict tiles when we become invisible. 2136 // Call PrepareTiles to evict tiles when we become invisible.
2131 PrepareTiles(); 2137 PrepareTiles();
2132 } 2138 }
2133 2139
2134 // Update visibility for the compositor context provider. 2140 // Update visibility for the compositor context provider.
2135 if (output_surface_) { 2141 if (output_surface_) {
2136 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), 2142 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
2143 &main_context_client_visibility_,
2137 visible); 2144 visible);
2138 } 2145 }
2139 } 2146 }
2140 2147
2141 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { 2148 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() {
2142 // TODO(miletus): This is just the compositor-thread-side call to the 2149 // 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 2150 // 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. 2151 // future. The name should not refer to SetNeedsRedraw but it does for now.
2145 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 2152 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
2146 client_->SetNeedsOneBeginImplFrameOnImplThread(); 2153 client_->SetNeedsOneBeginImplFrameOnImplThread();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
2340 // Since we will create a new resource provider, we cannot continue to use 2347 // Since we will create a new resource provider, we cannot continue to use
2341 // the old resources (i.e. render_surfaces and texture IDs). Clear them 2348 // the old resources (i.e. render_surfaces and texture IDs). Clear them
2342 // before we destroy the old resource provider. 2349 // before we destroy the old resource provider.
2343 ReleaseTreeResources(); 2350 ReleaseTreeResources();
2344 2351
2345 // Note: order is important here. 2352 // Note: order is important here.
2346 renderer_ = nullptr; 2353 renderer_ = nullptr;
2347 CleanUpTileManagerAndUIResources(); 2354 CleanUpTileManagerAndUIResources();
2348 resource_provider_ = nullptr; 2355 resource_provider_ = nullptr;
2349 2356
2350 // Detach from the old output surface and reset |output_surface_| pointer
2351 // as this surface is going to be destroyed independent of if binding the
2352 // new output surface succeeds or not.
2353 if (output_surface_) { 2357 if (output_surface_) {
2358 // Ensure that any context client visibility is left in a good state.
2359 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
2360 &main_context_client_visibility_, false);
2361 LockAndUpdateVisibilityForContextProvider(
2362 output_surface_->worker_context_provider(),
2363 &worker_context_client_visibility_, false);
2364
2365 // Detach from the old output surface and reset |output_surface_| pointer
2366 // as this surface is going to be destroyed independent of if binding the
2367 // new output surface succeeds or not.
2354 output_surface_->DetachFromClient(); 2368 output_surface_->DetachFromClient();
2355 output_surface_ = nullptr; 2369 output_surface_ = nullptr;
2356 } 2370 }
2357 2371
2358 // We don't know if the next OutputSurface will support GPU rasterization. 2372 // We don't know if the next OutputSurface will support GPU rasterization.
2359 // Make sure to clear the flag so that we force a re-computation. 2373 // Make sure to clear the flag so that we force a re-computation.
2360 use_gpu_rasterization_ = false; 2374 use_gpu_rasterization_ = false;
2361 } 2375 }
2362 2376
2363 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { 2377 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) {
(...skipping 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after
4101 return task_runner_provider_->HasImplThread(); 4115 return task_runner_provider_->HasImplThread();
4102 } 4116 }
4103 4117
4104 bool LayerTreeHostImpl::CommitToActiveTree() const { 4118 bool LayerTreeHostImpl::CommitToActiveTree() const {
4105 // In single threaded mode we skip the pending tree and commit directly to the 4119 // In single threaded mode we skip the pending tree and commit directly to the
4106 // active tree. 4120 // active tree.
4107 return !task_runner_provider_->HasImplThread(); 4121 return !task_runner_provider_->HasImplThread();
4108 } 4122 }
4109 4123
4110 } // namespace cc 4124 } // 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