| Index: cc/output/gl_renderer.cc | 
| diff --git a/cc/output/gl_renderer.cc b/cc/output/gl_renderer.cc | 
| index 727d158838925d081cad96bed0ccdff9dc63c981..a338eaf1367faf7057920d3826af146317dafd94 100644 | 
| --- a/cc/output/gl_renderer.cc | 
| +++ b/cc/output/gl_renderer.cc | 
| @@ -47,7 +47,6 @@ | 
| #include "cc/resources/resource_pool.h" | 
| #include "cc/resources/scoped_resource.h" | 
| #include "gpu/GLES2/gl2extchromium.h" | 
| -#include "gpu/command_buffer/client/context_support.h" | 
| #include "gpu/command_buffer/client/gles2_interface.h" | 
| #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 
| #include "media/base/media_switches.h" | 
| @@ -417,6 +416,9 @@ GLRenderer::~GLRenderer() { | 
| pending_async_read_pixels_.pop_back(); | 
| } | 
|  | 
| +  // Set our visibility to false to ensure we clean up context resources. | 
| +  UpdateVisibilityForContextProvider(false); | 
| + | 
| CleanupSharedObjects(); | 
| } | 
|  | 
| @@ -440,15 +442,7 @@ void GLRenderer::DidChangeVisibility() { | 
|  | 
| PrepareGeometry(NO_BINDING); | 
|  | 
| -  // Handle cleanup of resources on the ContextProvider. The compositor | 
| -  // ContextProvider is not shared, so always pass 0 for the client_id. | 
| -  // TODO(crbug.com/487471): Update this when we share compositor | 
| -  // ContextProviders. | 
| -  context_support_->SetClientVisible(0 /* client_id */, visible_); | 
| -  bool aggressively_free_resources = !context_support_->AnyClientsVisible(); | 
| -  if (aggressively_free_resources) | 
| -    output_surface_->context_provider()->DeleteCachedResources(); | 
| -  context_support_->SetAggressivelyFreeResources(aggressively_free_resources); | 
| +  UpdateVisibilityForContextProvider(visible_); | 
| } | 
|  | 
| void GLRenderer::ReleaseRenderPassTextures() { render_pass_textures_.clear(); } | 
| @@ -4036,4 +4030,19 @@ void GLRenderer::ScheduleRenderPassDrawQuad( | 
| ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 
| } | 
|  | 
| +void GLRenderer::UpdateVisibilityForContextProvider(bool is_visible) { | 
| +  if (is_visible == !!context_client_visibility_) | 
| +    return; | 
| + | 
| +  if (is_visible) { | 
| +    context_client_visibility_ = context_support_->ClientBecameVisible(); | 
| +  } else { | 
| +    context_support_->ClientBecameNotVisible( | 
| +        std::move(context_client_visibility_)); | 
| +  } | 
| + | 
| +  if (!context_support_->AnyClientsVisible()) | 
| +    output_surface_->context_provider()->DeleteCachedResources(); | 
| +} | 
| + | 
| }  // namespace cc | 
|  |