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

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: cleanup 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 // Calls SetClientVisible on the provided |context_provider| and handles
danakj 2016/08/18 21:39:44 SetClientVisible is a lie
ericrk 2016/08/19 17:23:19 Comment wasn't really saying much... removed.
161 // additional cache cleanup. 160 // additional cache cleanup.
162 void UpdateVisibilityForContextProvider(int client_id, 161 void UpdateVisibilityForContextProvider(
163 ContextProvider* context_provider, 162 ContextProvider* context_provider,
164 bool is_visible) { 163 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>* scoped_visibility,
164 bool is_visible) {
165 if (!context_provider) 165 if (!context_provider)
166 return; 166 return;
167 if (*scoped_visibility && is_visible)
danakj 2016/08/18 21:39:44 Combine?
ericrk 2016/08/19 17:23:19 Done.
168 return;
169 if (!*scoped_visibility && !is_visible)
170 return;
171
167 gpu::ContextSupport* context_support = context_provider->ContextSupport(); 172 gpu::ContextSupport* context_support = context_provider->ContextSupport();
168 173
169 context_support->SetClientVisible(client_id, is_visible); 174 if (is_visible)
175 *scoped_visibility = context_support->ClientBecameVisible();
176 else
177 context_support->ClientBecameNotVisible(std::move(*scoped_visibility));
178
170 bool aggressively_free_resources = !context_support->AnyClientsVisible(); 179 bool aggressively_free_resources = !context_support->AnyClientsVisible();
171 if (aggressively_free_resources) { 180 if (aggressively_free_resources) {
172 context_provider->DeleteCachedResources(); 181 context_provider->DeleteCachedResources();
173 } 182 }
174 context_support->SetAggressivelyFreeResources(aggressively_free_resources); 183 context_support->SetAggressivelyFreeResources(aggressively_free_resources);
175 } 184 }
176 185
177 // Same as UpdateVisibilityForContextProvider, except that the 186 // Same as UpdateVisibilityForContextProvider, except that the
178 // |context_provider| is locked before being used. 187 // |context_provider| is locked before being used.
179 void LockAndUpdateVisibilityForContextProvider( 188 void LockAndUpdateVisibilityForContextProvider(
180 int client_id,
181 ContextProvider* context_provider, 189 ContextProvider* context_provider,
190 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>* scoped_visibility,
182 bool is_visible) { 191 bool is_visible) {
183 if (!context_provider) 192 if (!context_provider)
184 return; 193 return;
194 if (*scoped_visibility && is_visible)
danakj 2016/08/18 21:39:44 Combine?
ericrk 2016/08/19 17:23:19 Done.
195 return;
196 if (!*scoped_visibility && !is_visible)
197 return;
198
185 ContextProvider::ScopedContextLock hold(context_provider); 199 ContextProvider::ScopedContextLock hold(context_provider);
186 UpdateVisibilityForContextProvider(client_id, context_provider, is_visible); 200 UpdateVisibilityForContextProvider(context_provider, scoped_visibility,
201 is_visible);
187 } 202 }
188 203
189 } // namespace 204 } // namespace
190 205
191 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer, 206 DEFINE_SCOPED_UMA_HISTOGRAM_TIMER(PendingTreeDurationHistogramTimer,
192 "Scheduling.%s.PendingTreeDuration"); 207 "Scheduling.%s.PendingTreeDuration");
193 208
194 LayerTreeHostImpl::FrameData::FrameData() 209 LayerTreeHostImpl::FrameData::FrameData()
195 : render_surface_layer_list(nullptr), 210 : render_surface_layer_list(nullptr),
196 has_no_damage(false), 211 has_no_damage(false),
(...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING); 1306 : gpu::MemoryAllocation::CUTOFF_ALLOW_NOTHING);
1292 global_tile_state_.num_resources_limit = policy.num_resources_limit; 1307 global_tile_state_.num_resources_limit = policy.num_resources_limit;
1293 1308
1294 if (global_tile_state_.hard_memory_limit_in_bytes > 0) { 1309 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 1310 // 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 1311 // are visible. Notify the worker context here. We handle becoming
1297 // invisible in NotifyAllTileTasksComplete to avoid interrupting running 1312 // invisible in NotifyAllTileTasksComplete to avoid interrupting running
1298 // work. 1313 // work.
1299 if (output_surface_) { 1314 if (output_surface_) {
1300 LockAndUpdateVisibilityForContextProvider( 1315 LockAndUpdateVisibilityForContextProvider(
1301 id_, output_surface_->worker_context_provider(), 1316 output_surface_->worker_context_provider(),
1302 true /* is_visible */); 1317 &worker_context_client_visibility_, true /* is_visible */);
1303 } 1318 }
1304 1319
1305 // If |global_tile_state_.hard_memory_limit_in_bytes| is greater than 0, we 1320 // 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 1321 // allow the image decode controller to retain resources. We handle the
1307 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting 1322 // equal to 0 case in NotifyAllTileTasksComplete to avoid interrupting
1308 // running work. 1323 // running work.
1309 if (image_decode_controller_) { 1324 if (image_decode_controller_) {
1310 image_decode_controller_->SetShouldAggressivelyFreeResources( 1325 image_decode_controller_->SetShouldAggressivelyFreeResources(
1311 false /* aggressively_free_resources */); 1326 false /* aggressively_free_resources */);
1312 } 1327 }
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 // Free image decode controller resources before notifying the worker 1400 // Free image decode controller resources before notifying the worker
1386 // context of visibility change. This ensures that the imaged decode 1401 // context of visibility change. This ensures that the imaged decode
1387 // controller has released all Skia refs at the time Skia's cleanup 1402 // controller has released all Skia refs at the time Skia's cleanup
1388 // executes (within worker context's cleanup). 1403 // executes (within worker context's cleanup).
1389 if (image_decode_controller_) { 1404 if (image_decode_controller_) {
1390 image_decode_controller_->SetShouldAggressivelyFreeResources( 1405 image_decode_controller_->SetShouldAggressivelyFreeResources(
1391 true /* aggressively_free_resources */); 1406 true /* aggressively_free_resources */);
1392 } 1407 }
1393 if (output_surface_) { 1408 if (output_surface_) {
1394 LockAndUpdateVisibilityForContextProvider( 1409 LockAndUpdateVisibilityForContextProvider(
1395 id_, output_surface_->worker_context_provider(), 1410 output_surface_->worker_context_provider(),
1396 false /* is_visible */); 1411 &worker_context_client_visibility_, false /* is_visible */);
1397 } 1412 }
1398 } 1413 }
1399 } 1414 }
1400 1415
1401 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) { 1416 void LayerTreeHostImpl::NotifyTileStateChanged(const Tile* tile) {
1402 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged"); 1417 TRACE_EVENT0("cc", "LayerTreeHostImpl::NotifyTileStateChanged");
1403 1418
1404 if (active_tree_) { 1419 if (active_tree_) {
1405 LayerImpl* layer_impl = 1420 LayerImpl* layer_impl =
1406 active_tree_->FindActiveTreeLayerById(tile->layer_id()); 1421 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. 2132 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw.
2118 SetRequiresHighResToDraw(); 2133 SetRequiresHighResToDraw();
2119 } else { 2134 } else {
2120 EvictAllUIResources(); 2135 EvictAllUIResources();
2121 // Call PrepareTiles to evict tiles when we become invisible. 2136 // Call PrepareTiles to evict tiles when we become invisible.
2122 PrepareTiles(); 2137 PrepareTiles();
2123 } 2138 }
2124 2139
2125 // Update visibility for the compositor context provider. 2140 // Update visibility for the compositor context provider.
2126 if (output_surface_) { 2141 if (output_surface_) {
2127 UpdateVisibilityForContextProvider(id_, output_surface_->context_provider(), 2142 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
2143 &main_context_client_visibility_,
2128 visible); 2144 visible);
2129 } 2145 }
2130 } 2146 }
2131 2147
2132 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() { 2148 void LayerTreeHostImpl::SetNeedsOneBeginImplFrame() {
2133 // 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
2134 // 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
2135 // 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.
2136 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); 2152 NotifySwapPromiseMonitorsOfSetNeedsRedraw();
2137 client_->SetNeedsOneBeginImplFrameOnImplThread(); 2153 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 2347 // 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 2348 // the old resources (i.e. render_surfaces and texture IDs). Clear them
2333 // before we destroy the old resource provider. 2349 // before we destroy the old resource provider.
2334 ReleaseTreeResources(); 2350 ReleaseTreeResources();
2335 2351
2336 // Note: order is important here. 2352 // Note: order is important here.
2337 renderer_ = nullptr; 2353 renderer_ = nullptr;
2338 CleanUpTileManagerAndUIResources(); 2354 CleanUpTileManagerAndUIResources();
2339 resource_provider_ = nullptr; 2355 resource_provider_ = nullptr;
2340 2356
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_) { 2357 if (output_surface_) {
2358 // Ensure that any context client visibility is left in a good state.
2359 if (main_context_client_visibility_) {
danakj 2016/08/18 21:39:44 They already early out appropriately, can you ment
ericrk 2016/08/19 17:23:19 Oh yeah... no reason I guess.
2360 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
2361 &main_context_client_visibility_,
2362 false);
2363 }
2364 if (worker_context_client_visibility_) {
2365 LockAndUpdateVisibilityForContextProvider(
2366 output_surface_->worker_context_provider(),
2367 &worker_context_client_visibility_, false);
2368 }
2369
2370 // Detach from the old output surface and reset |output_surface_| pointer
2371 // as this surface is going to be destroyed independent of if binding the
2372 // new output surface succeeds or not.
2345 output_surface_->DetachFromClient(); 2373 output_surface_->DetachFromClient();
2346 output_surface_ = nullptr; 2374 output_surface_ = nullptr;
2347 } 2375 }
2348 2376
2349 // We don't know if the next OutputSurface will support GPU rasterization. 2377 // 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. 2378 // Make sure to clear the flag so that we force a re-computation.
2351 use_gpu_rasterization_ = false; 2379 use_gpu_rasterization_ = false;
2352 } 2380 }
2353 2381
2354 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) { 2382 bool LayerTreeHostImpl::InitializeRenderer(OutputSurface* output_surface) {
(...skipping 1733 matching lines...) Expand 10 before | Expand all | Expand 10 after
4088 return task_runner_provider_->HasImplThread(); 4116 return task_runner_provider_->HasImplThread();
4089 } 4117 }
4090 4118
4091 bool LayerTreeHostImpl::CommitToActiveTree() const { 4119 bool LayerTreeHostImpl::CommitToActiveTree() const {
4092 // In single threaded mode we skip the pending tree and commit directly to the 4120 // In single threaded mode we skip the pending tree and commit directly to the
4093 // active tree. 4121 // active tree.
4094 return !task_runner_provider_->HasImplThread(); 4122 return !task_runner_provider_->HasImplThread();
4095 } 4123 }
4096 4124
4097 } // namespace cc 4125 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698