Commit aec301ce authored by gusfernandez's avatar gusfernandez Committed by Commit bot

Release GPU resources only after renderer GPU channels are closed.

The RelinquishGpuResource message from the browser process may
come before or after the rederer process closes it GPU channel.
As such, we need to wait until only the Browser GPU channel is
open until we can actually release the default off-screen
PBuffer surface and the EGL display.

This is a follow-up to https://codereview.chromium.org/712343003

Bug: 18724066
BUG=432268

Review URL: https://codereview.chromium.org/800103005

Cr-Commit-Position: refs/heads/master@{#308468}
parent 22c5f0f2
...@@ -101,6 +101,7 @@ GpuChannelManager::GpuChannelManager(MessageRouter* router, ...@@ -101,6 +101,7 @@ GpuChannelManager::GpuChannelManager(MessageRouter* router,
channel_(channel), channel_(channel),
filter_( filter_(
new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())), new GpuChannelManagerMessageFilter(gpu_memory_buffer_factory_.get())),
relinquish_resources_pending_(false),
weak_factory_(this) { weak_factory_(this) {
DCHECK(router_); DCHECK(router_);
DCHECK(io_message_loop); DCHECK(io_message_loop);
...@@ -137,6 +138,7 @@ GpuChannelManager::shader_translator_cache() { ...@@ -137,6 +138,7 @@ GpuChannelManager::shader_translator_cache() {
void GpuChannelManager::RemoveChannel(int client_id) { void GpuChannelManager::RemoveChannel(int client_id) {
Send(new GpuHostMsg_DestroyChannel(client_id)); Send(new GpuHostMsg_DestroyChannel(client_id));
gpu_channels_.erase(client_id); gpu_channels_.erase(client_id);
CheckRelinquishGpuResources();
} }
int GpuChannelManager::GenerateRouteID() { int GpuChannelManager::GenerateRouteID() {
...@@ -224,6 +226,7 @@ void GpuChannelManager::OnCloseChannel( ...@@ -224,6 +226,7 @@ void GpuChannelManager::OnCloseChannel(
iter != gpu_channels_.end(); ++iter) { iter != gpu_channels_.end(); ++iter) {
if (iter->second->GetChannelName() == channel_handle.name) { if (iter->second->GetChannelName() == channel_handle.name) {
gpu_channels_.erase(iter); gpu_channels_.erase(iter);
CheckRelinquishGpuResources();
return; return;
} }
} }
...@@ -327,6 +330,7 @@ void GpuChannelManager::LoseAllContexts() { ...@@ -327,6 +330,7 @@ void GpuChannelManager::LoseAllContexts() {
void GpuChannelManager::OnLoseAllContexts() { void GpuChannelManager::OnLoseAllContexts() {
gpu_channels_.clear(); gpu_channels_.clear();
CheckRelinquishGpuResources();
} }
gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() {
...@@ -338,19 +342,27 @@ gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() { ...@@ -338,19 +342,27 @@ gfx::GLSurface* GpuChannelManager::GetDefaultOffscreenSurface() {
} }
void GpuChannelManager::OnRelinquishResources() { void GpuChannelManager::OnRelinquishResources() {
if (default_offscreen_surface_.get()) { relinquish_resources_pending_ = true;
default_offscreen_surface_->DestroyAndTerminateDisplay(); CheckRelinquishGpuResources();
default_offscreen_surface_ = nullptr; }
}
void GpuChannelManager::CheckRelinquishGpuResources() {
if (relinquish_resources_pending_ && gpu_channels_.size() <= 1) {
relinquish_resources_pending_ = false;
if (default_offscreen_surface_.get()) {
default_offscreen_surface_->DestroyAndTerminateDisplay();
default_offscreen_surface_ = NULL;
}
#if defined(USE_OZONE) #if defined(USE_OZONE)
ui::OzonePlatform::GetInstance() ui::OzonePlatform::GetInstance()
->GetGpuPlatformSupport() ->GetGpuPlatformSupport()
->RelinquishGpuResources( ->RelinquishGpuResources(
base::Bind(&GpuChannelManager::OnResourcesRelinquished, base::Bind(&GpuChannelManager::OnResourcesRelinquished,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
#else #else
OnResourcesRelinquished(); OnResourcesRelinquished();
#endif #endif
}
} }
void GpuChannelManager::OnResourcesRelinquished() { void GpuChannelManager::OnResourcesRelinquished() {
......
...@@ -141,6 +141,7 @@ class CONTENT_EXPORT GpuChannelManager : public IPC::Listener, ...@@ -141,6 +141,7 @@ class CONTENT_EXPORT GpuChannelManager : public IPC::Listener,
const gpu::ValueState& state); const gpu::ValueState& state);
void OnLoseAllContexts(); void OnLoseAllContexts();
void CheckRelinquishGpuResources();
scoped_refptr<base::MessageLoopProxy> io_message_loop_; scoped_refptr<base::MessageLoopProxy> io_message_loop_;
base::WaitableEvent* shutdown_event_; base::WaitableEvent* shutdown_event_;
...@@ -164,6 +165,7 @@ class CONTENT_EXPORT GpuChannelManager : public IPC::Listener, ...@@ -164,6 +165,7 @@ class CONTENT_EXPORT GpuChannelManager : public IPC::Listener,
scoped_ptr<GpuMemoryBufferFactory> gpu_memory_buffer_factory_; scoped_ptr<GpuMemoryBufferFactory> gpu_memory_buffer_factory_;
IPC::SyncChannel* channel_; IPC::SyncChannel* channel_;
scoped_refptr<IPC::MessageFilter> filter_; scoped_refptr<IPC::MessageFilter> filter_;
bool relinquish_resources_pending_;
// Member variables should appear before the WeakPtrFactory, to ensure // Member variables should appear before the WeakPtrFactory, to ensure
// that any WeakPtrs to Controller are invalidated before its members // that any WeakPtrs to Controller are invalidated before its members
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment