| OLD | NEW |
| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 if (gpu_data_manager != NULL && !gpu_data_manager->GpuAccessAllowed()) | 193 if (gpu_data_manager != NULL && !gpu_data_manager->GpuAccessAllowed()) |
| 194 return NULL; | 194 return NULL; |
| 195 | 195 |
| 196 // The current policy is to ignore the renderer ID and use a single GPU | 196 // The current policy is to ignore the renderer ID and use a single GPU |
| 197 // process (the first valid host in the host-id map) for all renderers. Later | 197 // process (the first valid host in the host-id map) for all renderers. Later |
| 198 // this will be extended to allow the use of multiple GPU processes. | 198 // this will be extended to allow the use of multiple GPU processes. |
| 199 for (IDMap<GpuProcessHost>::iterator it(g_hosts_by_id.Pointer()); | 199 for (IDMap<GpuProcessHost>::iterator it(g_hosts_by_id.Pointer()); |
| 200 !it.IsAtEnd(); it.Advance()) { | 200 !it.IsAtEnd(); it.Advance()) { |
| 201 GpuProcessHost *host = it.GetCurrentValue(); | 201 GpuProcessHost *host = it.GetCurrentValue(); |
| 202 | 202 |
| 203 if (host->sandboxed() != (client_id != 0)) |
| 204 continue; |
| 205 |
| 203 if (HostIsValid(host)) | 206 if (HostIsValid(host)) |
| 204 return host; | 207 return host; |
| 205 } | 208 } |
| 206 | 209 |
| 207 if (cause == content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH) | 210 if (cause == content::CAUSE_FOR_GPU_LAUNCH_NO_LAUNCH) |
| 208 return NULL; | 211 return NULL; |
| 209 | 212 |
| 210 int host_id; | 213 int host_id; |
| 211 host_id = ++g_last_host_id; | 214 host_id = ++g_last_host_id; |
| 212 | 215 |
| 213 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLaunchCause", | 216 UMA_HISTOGRAM_ENUMERATION("GPU.GPUProcessLaunchCause", |
| 214 cause, | 217 cause, |
| 215 content::CAUSE_FOR_GPU_LAUNCH_MAX_ENUM); | 218 content::CAUSE_FOR_GPU_LAUNCH_MAX_ENUM); |
| 216 | 219 |
| 217 GpuProcessHost* host = new GpuProcessHost(host_id); | 220 GpuProcessHost* host = new GpuProcessHost(host_id, client_id != 0); |
| 218 if (host->Init()) | 221 if (host->Init()) |
| 219 return host; | 222 return host; |
| 220 | 223 |
| 221 delete host; | 224 delete host; |
| 222 return NULL; | 225 return NULL; |
| 223 } | 226 } |
| 224 | 227 |
| 225 // static | 228 // static |
| 226 void GpuProcessHost::SendOnIO(int client_id, | 229 void GpuProcessHost::SendOnIO(int client_id, |
| 227 content::CauseForGpuLaunch cause, | 230 content::CauseForGpuLaunch cause, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 239 if (host_id == 0) | 242 if (host_id == 0) |
| 240 return NULL; | 243 return NULL; |
| 241 | 244 |
| 242 GpuProcessHost *host = g_hosts_by_id.Pointer()->Lookup(host_id); | 245 GpuProcessHost *host = g_hosts_by_id.Pointer()->Lookup(host_id); |
| 243 if (HostIsValid(host)) | 246 if (HostIsValid(host)) |
| 244 return host; | 247 return host; |
| 245 | 248 |
| 246 return NULL; | 249 return NULL; |
| 247 } | 250 } |
| 248 | 251 |
| 249 GpuProcessHost::GpuProcessHost(int host_id) | 252 GpuProcessHost::GpuProcessHost(int host_id, bool sandboxed) |
| 250 : host_id_(host_id), | 253 : host_id_(host_id), |
| 251 gpu_process_(base::kNullProcessHandle), | 254 gpu_process_(base::kNullProcessHandle), |
| 252 in_process_(false), | 255 in_process_(false), |
| 253 software_rendering_(false) { | 256 software_rendering_(false), |
| 257 sandboxed_(sandboxed) { |
| 254 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 258 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || |
| 255 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) | 259 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) |
| 256 in_process_ = true; | 260 in_process_ = true; |
| 257 | 261 |
| 258 // If the 'single GPU process' policy ever changes, we still want to maintain | 262 // If the 'single GPU process' policy ever changes, we still want to maintain |
| 259 // it for 'gpu thread' mode and only create one instance of host and thread. | 263 // it for 'gpu thread' mode and only create one instance of host and thread. |
| 260 DCHECK(!in_process_ || g_hosts_by_id.Pointer()->IsEmpty()); | 264 DCHECK(!in_process_ || g_hosts_by_id.Pointer()->IsEmpty()); |
| 261 | 265 |
| 262 g_hosts_by_id.Pointer()->AddWithID(this, host_id_); | 266 g_hosts_by_id.Pointer()->AddWithID(this, host_id_); |
| 263 | 267 |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 if (++g_gpu_crash_count >= kGpuMaxCrashCount) { | 515 if (++g_gpu_crash_count >= kGpuMaxCrashCount) { |
| 512 // The gpu process is too unstable to use. Disable it for current session. | 516 // The gpu process is too unstable to use. Disable it for current session. |
| 513 gpu_enabled_ = false; | 517 gpu_enabled_ = false; |
| 514 } | 518 } |
| 515 } | 519 } |
| 516 | 520 |
| 517 bool GpuProcessHost::software_rendering() { | 521 bool GpuProcessHost::software_rendering() { |
| 518 return software_rendering_; | 522 return software_rendering_; |
| 519 } | 523 } |
| 520 | 524 |
| 525 bool GpuProcessHost::sandboxed() { |
| 526 return sandboxed_; |
| 527 } |
| 528 |
| 521 void GpuProcessHost::ForceShutdown() { | 529 void GpuProcessHost::ForceShutdown() { |
| 522 g_hosts_by_id.Pointer()->Remove(host_id_); | 530 g_hosts_by_id.Pointer()->Remove(host_id_); |
| 523 process_->ForceShutdown(); | 531 process_->ForceShutdown(); |
| 524 } | 532 } |
| 525 | 533 |
| 526 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { | 534 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { |
| 527 if (!gpu_enabled_ || g_gpu_crash_count >= kGpuMaxCrashCount) { | 535 if (!gpu_enabled_ || g_gpu_crash_count >= kGpuMaxCrashCount) { |
| 528 SendOutstandingReplies(); | 536 SendOutstandingReplies(); |
| 529 gpu_enabled_ = false; | 537 gpu_enabled_ = false; |
| 530 return false; | 538 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 543 #endif | 551 #endif |
| 544 | 552 |
| 545 FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 553 FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
| 546 if (exe_path.empty()) | 554 if (exe_path.empty()) |
| 547 return false; | 555 return false; |
| 548 | 556 |
| 549 CommandLine* cmd_line = new CommandLine(exe_path); | 557 CommandLine* cmd_line = new CommandLine(exe_path); |
| 550 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 558 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
| 551 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 559 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 552 | 560 |
| 561 if (!sandboxed_) |
| 562 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); |
| 563 |
| 553 // Propagate relevant command line switches. | 564 // Propagate relevant command line switches. |
| 554 static const char* const kSwitchNames[] = { | 565 static const char* const kSwitchNames[] = { |
| 555 switches::kDisableBreakpad, | 566 switches::kDisableBreakpad, |
| 556 switches::kDisableGLMultisampling, | 567 switches::kDisableGLMultisampling, |
| 557 switches::kDisableGpuDriverBugWorkarounds, | 568 switches::kDisableGpuDriverBugWorkarounds, |
| 558 switches::kDisableGpuSandbox, | 569 switches::kDisableGpuSandbox, |
| 559 switches::kDisableGpuVsync, | 570 switches::kDisableGpuVsync, |
| 560 switches::kDisableGpuWatchdog, | 571 switches::kDisableGpuWatchdog, |
| 561 switches::kDisableImageTransportSurface, | 572 switches::kDisableImageTransportSurface, |
| 562 switches::kDisableLogging, | 573 switches::kDisableLogging, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 const IPC::ChannelHandle& channel_handle, | 632 const IPC::ChannelHandle& channel_handle, |
| 622 base::ProcessHandle renderer_process_for_gpu, | 633 base::ProcessHandle renderer_process_for_gpu, |
| 623 const content::GPUInfo& gpu_info) { | 634 const content::GPUInfo& gpu_info) { |
| 624 callback.Run(channel_handle, renderer_process_for_gpu, gpu_info); | 635 callback.Run(channel_handle, renderer_process_for_gpu, gpu_info); |
| 625 } | 636 } |
| 626 | 637 |
| 627 void GpuProcessHost::CreateCommandBufferError( | 638 void GpuProcessHost::CreateCommandBufferError( |
| 628 const CreateCommandBufferCallback& callback, int32 route_id) { | 639 const CreateCommandBufferCallback& callback, int32 route_id) { |
| 629 callback.Run(route_id); | 640 callback.Run(route_id); |
| 630 } | 641 } |
| OLD | NEW |