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

Side by Side Diff: cc/output/gl_renderer.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 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/output/gl_renderer.h" 5 #include "cc/output/gl_renderer.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 29 matching lines...) Expand all
40 #include "cc/output/texture_mailbox_deleter.h" 40 #include "cc/output/texture_mailbox_deleter.h"
41 #include "cc/quads/draw_polygon.h" 41 #include "cc/quads/draw_polygon.h"
42 #include "cc/quads/picture_draw_quad.h" 42 #include "cc/quads/picture_draw_quad.h"
43 #include "cc/quads/render_pass.h" 43 #include "cc/quads/render_pass.h"
44 #include "cc/quads/stream_video_draw_quad.h" 44 #include "cc/quads/stream_video_draw_quad.h"
45 #include "cc/quads/texture_draw_quad.h" 45 #include "cc/quads/texture_draw_quad.h"
46 #include "cc/raster/scoped_gpu_raster.h" 46 #include "cc/raster/scoped_gpu_raster.h"
47 #include "cc/resources/resource_pool.h" 47 #include "cc/resources/resource_pool.h"
48 #include "cc/resources/scoped_resource.h" 48 #include "cc/resources/scoped_resource.h"
49 #include "gpu/GLES2/gl2extchromium.h" 49 #include "gpu/GLES2/gl2extchromium.h"
50 #include "gpu/command_buffer/client/context_support.h"
51 #include "gpu/command_buffer/client/gles2_interface.h" 50 #include "gpu/command_buffer/client/gles2_interface.h"
52 #include "gpu/command_buffer/common/gpu_memory_allocation.h" 51 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
53 #include "media/base/media_switches.h" 52 #include "media/base/media_switches.h"
54 #include "skia/ext/texture_handle.h" 53 #include "skia/ext/texture_handle.h"
55 #include "third_party/skia/include/core/SkBitmap.h" 54 #include "third_party/skia/include/core/SkBitmap.h"
56 #include "third_party/skia/include/core/SkColor.h" 55 #include "third_party/skia/include/core/SkColor.h"
57 #include "third_party/skia/include/core/SkColorFilter.h" 56 #include "third_party/skia/include/core/SkColorFilter.h"
58 #include "third_party/skia/include/core/SkImage.h" 57 #include "third_party/skia/include/core/SkImage.h"
59 #include "third_party/skia/include/core/SkSurface.h" 58 #include "third_party/skia/include/core/SkSurface.h"
60 #include "third_party/skia/include/gpu/GrContext.h" 59 #include "third_party/skia/include/gpu/GrContext.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 case SkXfermode::kColor_Mode: 137 case SkXfermode::kColor_Mode:
139 return BLEND_MODE_COLOR; 138 return BLEND_MODE_COLOR;
140 case SkXfermode::kLuminosity_Mode: 139 case SkXfermode::kLuminosity_Mode:
141 return BLEND_MODE_LUMINOSITY; 140 return BLEND_MODE_LUMINOSITY;
142 default: 141 default:
143 NOTREACHED(); 142 NOTREACHED();
144 return BLEND_MODE_NONE; 143 return BLEND_MODE_NONE;
145 } 144 }
146 } 145 }
147 146
147 void UpdateVisibilityForContextProvider(
148 ContextProvider* context_provider,
149 std::unique_ptr<gpu::ContextSupport::ScopedVisibility>* scoped_visibility,
150 bool is_visible) {
151 if (is_visible && *scoped_visibility)
danakj 2016/08/18 21:39:44 These 2 can be combined as is_visible == *scoped_v
ericrk 2016/08/19 17:23:18 good point
152 return;
153 if (!is_visible && !*scoped_visibility)
154 return;
155
156 gpu::ContextSupport* context_support = context_provider->ContextSupport();
157
158 if (is_visible)
159 *scoped_visibility = context_support->ClientBecameVisible();
160 else
161 context_support->ClientBecameNotVisible(std::move(*scoped_visibility));
162
163 bool aggressively_free_resources = !context_support->AnyClientsVisible();
164 if (aggressively_free_resources)
165 context_provider->DeleteCachedResources();
166 context_support->SetAggressivelyFreeResources(aggressively_free_resources);
167 }
168
148 // Smallest unit that impact anti-aliasing output. We use this to 169 // Smallest unit that impact anti-aliasing output. We use this to
149 // determine when anti-aliasing is unnecessary. 170 // determine when anti-aliasing is unnecessary.
150 const float kAntiAliasingEpsilon = 1.0f / 1024.0f; 171 const float kAntiAliasingEpsilon = 1.0f / 1024.0f;
151 172
152 // Block or crash if the number of pending sync queries reach this high as 173 // Block or crash if the number of pending sync queries reach this high as
153 // something is seriously wrong on the service side if this happens. 174 // something is seriously wrong on the service side if this happens.
154 const size_t kMaxPendingSyncQueries = 16; 175 const size_t kMaxPendingSyncQueries = 16;
155 } // anonymous namespace 176 } // anonymous namespace
156 177
157 // Parameters needed to draw a RenderPassDrawQuad. 178 // Parameters needed to draw a RenderPassDrawQuad.
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 431 }
411 432
412 GLRenderer::~GLRenderer() { 433 GLRenderer::~GLRenderer() {
413 while (!pending_async_read_pixels_.empty()) { 434 while (!pending_async_read_pixels_.empty()) {
414 PendingAsyncReadPixels* pending_read = 435 PendingAsyncReadPixels* pending_read =
415 pending_async_read_pixels_.back().get(); 436 pending_async_read_pixels_.back().get();
416 pending_read->finished_read_pixels_callback.Cancel(); 437 pending_read->finished_read_pixels_callback.Cancel();
417 pending_async_read_pixels_.pop_back(); 438 pending_async_read_pixels_.pop_back();
418 } 439 }
419 440
441 // Set our visibility to false to ensure we clean up context resources.
442 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
443 &context_client_visibility_, false);
444
420 CleanupSharedObjects(); 445 CleanupSharedObjects();
421 } 446 }
422 447
423 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { 448 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const {
424 return capabilities_; 449 return capabilities_;
425 } 450 }
426 451
427 bool GLRenderer::CanPartialSwap() { 452 bool GLRenderer::CanPartialSwap() {
428 auto* context_provider = output_surface_->context_provider(); 453 auto* context_provider = output_surface_->context_provider();
429 return context_provider->ContextCapabilities().post_sub_buffer; 454 return context_provider->ContextCapabilities().post_sub_buffer;
430 } 455 }
431 456
432 void GLRenderer::DidChangeVisibility() { 457 void GLRenderer::DidChangeVisibility() {
433 if (visible_) { 458 if (visible_) {
434 output_surface_->EnsureBackbuffer(); 459 output_surface_->EnsureBackbuffer();
435 } else { 460 } else {
436 TRACE_EVENT0("cc", "GLRenderer::DidChangeVisibility dropping resources"); 461 TRACE_EVENT0("cc", "GLRenderer::DidChangeVisibility dropping resources");
437 ReleaseRenderPassTextures(); 462 ReleaseRenderPassTextures();
438 output_surface_->DiscardBackbuffer(); 463 output_surface_->DiscardBackbuffer();
439 } 464 }
440 465
441 PrepareGeometry(NO_BINDING); 466 PrepareGeometry(NO_BINDING);
442 467
443 // Handle cleanup of resources on the ContextProvider. The compositor 468 UpdateVisibilityForContextProvider(output_surface_->context_provider(),
444 // ContextProvider is not shared, so always pass 0 for the client_id. 469 &context_client_visibility_, visible_);
445 // TODO(crbug.com/487471): Update this when we share compositor
446 // ContextProviders.
447 context_support_->SetClientVisible(0 /* client_id */, visible_);
448 bool aggressively_free_resources = !context_support_->AnyClientsVisible();
449 if (aggressively_free_resources)
450 output_surface_->context_provider()->DeleteCachedResources();
451 context_support_->SetAggressivelyFreeResources(aggressively_free_resources);
452 } 470 }
453 471
454 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } 472 void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); }
455 473
456 void GLRenderer::DiscardPixels() { 474 void GLRenderer::DiscardPixels() {
457 if (!use_discard_framebuffer_) 475 if (!use_discard_framebuffer_)
458 return; 476 return;
459 bool using_default_framebuffer = 477 bool using_default_framebuffer =
460 !current_framebuffer_lock_ && 478 !current_framebuffer_lock_ &&
461 output_surface_->capabilities().uses_default_gl_framebuffer; 479 output_surface_->capabilities().uses_default_gl_framebuffer;
(...skipping 3576 matching lines...) Expand 10 before | Expand all | Expand 10 after
4038 4056
4039 gl_->ScheduleCALayerSharedStateCHROMIUM( 4057 gl_->ScheduleCALayerSharedStateCHROMIUM(
4040 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, 4058 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect,
4041 sorting_context_id, gl_transform); 4059 sorting_context_id, gl_transform);
4042 gl_->ScheduleCALayerCHROMIUM( 4060 gl_->ScheduleCALayerCHROMIUM(
4043 texture_id, contents_rect, ca_layer_overlay->background_color, 4061 texture_id, contents_rect, ca_layer_overlay->background_color,
4044 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 4062 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
4045 } 4063 }
4046 4064
4047 } // namespace cc 4065 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698