Index: content/browser/gpu/gpu_process_host.cc |
diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc |
index be7db476b0bd1524ac6e51a8884a709403fbd2e3..34897771db48e47af14b409ff9fd9e2a63952764 100644 |
--- a/content/browser/gpu/gpu_process_host.cc |
+++ b/content/browser/gpu/gpu_process_host.cc |
@@ -156,15 +156,15 @@ class GpuSandboxedProcessLauncherDelegate |
~GpuSandboxedProcessLauncherDelegate() override {} |
#if defined(OS_WIN) |
- virtual bool ShouldSandbox() override { |
+ bool ShouldSandbox() override { |
bool sandbox = !cmd_line_->HasSwitch(switches::kDisableGpuSandbox); |
- if(! sandbox) { |
+ if (!sandbox) { |
DVLOG(1) << "GPU sandbox is disabled"; |
} |
return sandbox; |
} |
- virtual void PreSandbox(bool* disable_default_policy, |
+ void PreSandbox(bool* disable_default_policy, |
base::FilePath* exposed_dir) override { |
*disable_default_policy = true; |
} |
@@ -348,6 +348,58 @@ void GpuProcessHost::SendOnIO(GpuProcessKind kind, |
} |
} |
+// static |
+void GpuProcessHost::RelinquishResources(const RelinquishCallback& callback) { |
+ if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&GpuProcessHost::RelinquishResources, callback)); |
+ return; |
+ } |
+ GpuProcessHost* host = GpuProcessHost::Get(GPU_PROCESS_KIND_SANDBOXED, |
+ CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH); |
+ if (!host || |
+ !BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
+ base::Bind(&GpuProcessHost::RelinquishResourcesInternal, |
+ base::Unretained(host), |
jbauman
2014/11/12 01:47:28
I don't think this use of base::Unretained is safe
GusFernandez
2014/11/15 02:11:56
This is now completely re-written and simplified i
|
+ callback))) { |
+ callback.Run(false); |
+ } |
+} |
+ |
+void GpuProcessHost::RelinquishResourcesInternal( |
+ const RelinquishCallback& callback) { |
+ if (gpu_enabled()) { |
+ relinquish_callback_ = callback; |
jbauman
2014/11/12 01:47:28
DCHECK(relinquish_callback_.is_null()); before thi
GusFernandez
2014/11/15 02:11:56
Done.
|
+ // We send two messages to the GPU process. the first is handled by |
+ // GpuChannelManager to release the default_offscreen_surface which |
+ // may hold a pointer to the EGL display which is about to be released. |
+ // The second is handled by the Ozone platform to release all remaining |
+ // OpenGL and EGL resources. It sendsback a ResourcesRelinquished message |
+ // once this is completed and it is safe for an external process to |
+ // access the GPU. |
+ SendGpuProcessMessage(GPU_PROCESS_KIND_SANDBOXED, |
+ CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
+ new GpuMsg_DeleteDefaultOffscreenSurface); |
+#if defined(USE_OZONE) |
+ SendGpuProcessMessage(GPU_PROCESS_KIND_SANDBOXED, |
+ CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH, |
+ new GpuMsg_RelinquishDisplay); |
+ return; |
+#endif |
+ } |
+ BrowserThread::PostTask(BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(callback, false)); |
+} |
+ |
+void GpuProcessHost::OnResourcesRelinquished(bool success) { |
+ BrowserThread::PostTask(BrowserThread::UI, |
+ FROM_HERE, |
+ base::Bind(relinquish_callback_, success)); |
+} |
jbauman
2014/11/12 01:47:28
reset relinquish_callback_ here. Also you should d
GusFernandez
2014/11/15 02:11:56
Done.
|
+ |
GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL; |
void GpuProcessHost::RegisterGpuMainThreadFactory( |
@@ -581,6 +633,8 @@ bool GpuProcessHost::OnMessageReceived(const IPC::Message& message) { |
OnDestroyChannel) |
IPC_MESSAGE_HANDLER(GpuHostMsg_CacheShader, |
OnCacheShader) |
+ IPC_MESSAGE_HANDLER(GpuHostMsg_ResourceRelinquished, |
+ OnResourcesRelinquished) |
IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) |
IPC_END_MESSAGE_MAP() |