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

Side by Side Diff: content/browser/gpu/gpu_process_host.cc

Issue 712343003: Infrastructure for temportarily relinquishing GPU resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/gpu/gpu_process_host.h" 5 #include "content/browser/gpu/gpu_process_host.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/base_switches.h" 8 #include "base/base_switches.h"
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 ChildProcessHost* host) 149 ChildProcessHost* host)
150 #if defined(OS_WIN) 150 #if defined(OS_WIN)
151 : cmd_line_(cmd_line) {} 151 : cmd_line_(cmd_line) {}
152 #elif defined(OS_POSIX) 152 #elif defined(OS_POSIX)
153 : ipc_fd_(host->TakeClientFileDescriptor()) {} 153 : ipc_fd_(host->TakeClientFileDescriptor()) {}
154 #endif 154 #endif
155 155
156 ~GpuSandboxedProcessLauncherDelegate() override {} 156 ~GpuSandboxedProcessLauncherDelegate() override {}
157 157
158 #if defined(OS_WIN) 158 #if defined(OS_WIN)
159 virtual bool ShouldSandbox() override { 159 bool ShouldSandbox() override {
160 bool sandbox = !cmd_line_->HasSwitch(switches::kDisableGpuSandbox); 160 bool sandbox = !cmd_line_->HasSwitch(switches::kDisableGpuSandbox);
161 if(! sandbox) { 161 if (!sandbox) {
162 DVLOG(1) << "GPU sandbox is disabled"; 162 DVLOG(1) << "GPU sandbox is disabled";
163 } 163 }
164 return sandbox; 164 return sandbox;
165 } 165 }
166 166
167 virtual void PreSandbox(bool* disable_default_policy, 167 void PreSandbox(bool* disable_default_policy,
168 base::FilePath* exposed_dir) override { 168 base::FilePath* exposed_dir) override {
169 *disable_default_policy = true; 169 *disable_default_policy = true;
170 } 170 }
171 171
172 // For the GPU process we gotten as far as USER_LIMITED. The next level 172 // For the GPU process we gotten as far as USER_LIMITED. The next level
173 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL 173 // which is USER_RESTRICTED breaks both the DirectX backend and the OpenGL
174 // backend. Note that the GPU process is connected to the interactive 174 // backend. Note that the GPU process is connected to the interactive
175 // desktop. 175 // desktop.
176 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy, 176 virtual void PreSpawnTarget(sandbox::TargetPolicy* policy,
177 bool* success) { 177 bool* success) {
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 CauseForGpuLaunch cause, 341 CauseForGpuLaunch cause,
342 IPC::Message* message) { 342 IPC::Message* message) {
343 if (!BrowserThread::PostTask( 343 if (!BrowserThread::PostTask(
344 BrowserThread::IO, FROM_HERE, 344 BrowserThread::IO, FROM_HERE,
345 base::Bind( 345 base::Bind(
346 &SendGpuProcessMessage, kind, cause, message))) { 346 &SendGpuProcessMessage, kind, cause, message))) {
347 delete message; 347 delete message;
348 } 348 }
349 } 349 }
350 350
351 // static
352 void GpuProcessHost::RelinquishResources(const RelinquishCallback& callback) {
353 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
354 BrowserThread::PostTask(
355 BrowserThread::IO,
356 FROM_HERE,
357 base::Bind(&GpuProcessHost::RelinquishResources, callback));
358 return;
359 }
360 GpuProcessHost* host = GpuProcessHost::Get(GPU_PROCESS_KIND_SANDBOXED,
361 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH);
362 if (!host ||
363 !BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
364 base::Bind(&GpuProcessHost::RelinquishResourcesInternal,
365 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
366 callback))) {
367 callback.Run(false);
368 }
369 }
370
371 void GpuProcessHost::RelinquishResourcesInternal(
372 const RelinquishCallback& callback) {
373 if (gpu_enabled()) {
374 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.
375 // We send two messages to the GPU process. the first is handled by
376 // GpuChannelManager to release the default_offscreen_surface which
377 // may hold a pointer to the EGL display which is about to be released.
378 // The second is handled by the Ozone platform to release all remaining
379 // OpenGL and EGL resources. It sendsback a ResourcesRelinquished message
380 // once this is completed and it is safe for an external process to
381 // access the GPU.
382 SendGpuProcessMessage(GPU_PROCESS_KIND_SANDBOXED,
383 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH,
384 new GpuMsg_DeleteDefaultOffscreenSurface);
385 #if defined(USE_OZONE)
386 SendGpuProcessMessage(GPU_PROCESS_KIND_SANDBOXED,
387 CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH,
388 new GpuMsg_RelinquishDisplay);
389 return;
390 #endif
391 }
392 BrowserThread::PostTask(BrowserThread::UI,
393 FROM_HERE,
394 base::Bind(callback, false));
395 }
396
397 void GpuProcessHost::OnResourcesRelinquished(bool success) {
398 BrowserThread::PostTask(BrowserThread::UI,
399 FROM_HERE,
400 base::Bind(relinquish_callback_, success));
401 }
jbauman 2014/11/12 01:47:28 reset relinquish_callback_ here. Also you should d
GusFernandez 2014/11/15 02:11:56 Done.
402
351 GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL; 403 GpuMainThreadFactoryFunction g_gpu_main_thread_factory = NULL;
352 404
353 void GpuProcessHost::RegisterGpuMainThreadFactory( 405 void GpuProcessHost::RegisterGpuMainThreadFactory(
354 GpuMainThreadFactoryFunction create) { 406 GpuMainThreadFactoryFunction create) {
355 g_gpu_main_thread_factory = create; 407 g_gpu_main_thread_factory = create;
356 } 408 }
357 409
358 // static 410 // static
359 GpuProcessHost* GpuProcessHost::FromID(int host_id) { 411 GpuProcessHost* GpuProcessHost::FromID(int host_id) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats, 626 IPC_MESSAGE_HANDLER(GpuHostMsg_GpuMemoryUmaStats,
575 OnGpuMemoryUmaStatsReceived) 627 OnGpuMemoryUmaStatsReceived)
576 #if defined(OS_MACOSX) 628 #if defined(OS_MACOSX)
577 IPC_MESSAGE_HANDLER_GENERIC(GpuHostMsg_AcceleratedSurfaceBuffersSwapped, 629 IPC_MESSAGE_HANDLER_GENERIC(GpuHostMsg_AcceleratedSurfaceBuffersSwapped,
578 OnAcceleratedSurfaceBuffersSwapped(message)) 630 OnAcceleratedSurfaceBuffersSwapped(message))
579 #endif 631 #endif
580 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyChannel, 632 IPC_MESSAGE_HANDLER(GpuHostMsg_DestroyChannel,
581 OnDestroyChannel) 633 OnDestroyChannel)
582 IPC_MESSAGE_HANDLER(GpuHostMsg_CacheShader, 634 IPC_MESSAGE_HANDLER(GpuHostMsg_CacheShader,
583 OnCacheShader) 635 OnCacheShader)
636 IPC_MESSAGE_HANDLER(GpuHostMsg_ResourceRelinquished,
637 OnResourcesRelinquished)
584 638
585 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message)) 639 IPC_MESSAGE_UNHANDLED(RouteOnUIThread(message))
586 IPC_END_MESSAGE_MAP() 640 IPC_END_MESSAGE_MAP()
587 641
588 return true; 642 return true;
589 } 643 }
590 644
591 void GpuProcessHost::OnChannelConnected(int32 peer_pid) { 645 void GpuProcessHost::OnChannelConnected(int32 peer_pid) {
592 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected"); 646 TRACE_EVENT0("gpu", "GpuProcessHost::OnChannelConnected");
593 647
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); 1124 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader");
1071 ClientIdToShaderCacheMap::iterator iter = 1125 ClientIdToShaderCacheMap::iterator iter =
1072 client_id_to_shader_cache_.find(client_id); 1126 client_id_to_shader_cache_.find(client_id);
1073 // If the cache doesn't exist then this is an off the record profile. 1127 // If the cache doesn't exist then this is an off the record profile.
1074 if (iter == client_id_to_shader_cache_.end()) 1128 if (iter == client_id_to_shader_cache_.end())
1075 return; 1129 return;
1076 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); 1130 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader);
1077 } 1131 }
1078 1132
1079 } // namespace content 1133 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698