| 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/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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 host->Send(message); | 97 host->Send(message); |
| 98 } else { | 98 } else { |
| 99 delete message; | 99 delete message; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 // NOTE: changes to this class need to be reviewed by the security team. | 103 // NOTE: changes to this class need to be reviewed by the security team. |
| 104 class GpuSandboxedProcessLauncherDelegate | 104 class GpuSandboxedProcessLauncherDelegate |
| 105 : public SandboxedProcessLauncherDelegate { | 105 : public SandboxedProcessLauncherDelegate { |
| 106 public: | 106 public: |
| 107 GpuSandboxedProcessLauncherDelegate(CommandLine* cmd_line, | 107 GpuSandboxedProcessLauncherDelegate(base::CommandLine* cmd_line, |
| 108 ChildProcessHost* host) | 108 ChildProcessHost* host) |
| 109 #if defined(OS_WIN) | 109 #if defined(OS_WIN) |
| 110 : cmd_line_(cmd_line) {} | 110 : cmd_line_(cmd_line) {} |
| 111 #elif defined(OS_POSIX) | 111 #elif defined(OS_POSIX) |
| 112 : ipc_fd_(host->TakeClientFileDescriptor()) {} | 112 : ipc_fd_(host->TakeClientFileDescriptor()) {} |
| 113 #endif | 113 #endif |
| 114 | 114 |
| 115 virtual ~GpuSandboxedProcessLauncherDelegate() {} | 115 virtual ~GpuSandboxedProcessLauncherDelegate() {} |
| 116 | 116 |
| 117 #if defined(OS_WIN) | 117 #if defined(OS_WIN) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 } | 209 } |
| 210 #elif defined(OS_POSIX) | 210 #elif defined(OS_POSIX) |
| 211 | 211 |
| 212 virtual int GetIpcFd() OVERRIDE { | 212 virtual int GetIpcFd() OVERRIDE { |
| 213 return ipc_fd_; | 213 return ipc_fd_; |
| 214 } | 214 } |
| 215 #endif // OS_WIN | 215 #endif // OS_WIN |
| 216 | 216 |
| 217 private: | 217 private: |
| 218 #if defined(OS_WIN) | 218 #if defined(OS_WIN) |
| 219 CommandLine* cmd_line_; | 219 base::CommandLine* cmd_line_; |
| 220 #elif defined(OS_POSIX) | 220 #elif defined(OS_POSIX) |
| 221 int ipc_fd_; | 221 int ipc_fd_; |
| 222 #endif // OS_WIN | 222 #endif // OS_WIN |
| 223 }; | 223 }; |
| 224 | 224 |
| 225 } // anonymous namespace | 225 } // anonymous namespace |
| 226 | 226 |
| 227 // static | 227 // static |
| 228 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { | 228 bool GpuProcessHost::ValidateHost(GpuProcessHost* host) { |
| 229 // The Gpu process is invalid if it's not using SwiftShader, the card is | 229 // The Gpu process is invalid if it's not using SwiftShader, the card is |
| 230 // blacklisted, and we can kill it and start over. | 230 // blacklisted, and we can kill it and start over. |
| 231 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 231 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 232 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU) || | 232 switches::kSingleProcess) || |
| 233 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 234 switches::kInProcessGPU) || |
| 233 (host->valid_ && | 235 (host->valid_ && |
| 234 (host->swiftshader_rendering_ || | 236 (host->swiftshader_rendering_ || |
| 235 !GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()))) { | 237 !GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()))) { |
| 236 return true; | 238 return true; |
| 237 } | 239 } |
| 238 | 240 |
| 239 host->ForceShutdown(); | 241 host->ForceShutdown(); |
| 240 return false; | 242 return false; |
| 241 } | 243 } |
| 242 | 244 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) | 332 GpuProcessHost::GpuProcessHost(int host_id, GpuProcessKind kind) |
| 331 : host_id_(host_id), | 333 : host_id_(host_id), |
| 332 valid_(true), | 334 valid_(true), |
| 333 in_process_(false), | 335 in_process_(false), |
| 334 swiftshader_rendering_(false), | 336 swiftshader_rendering_(false), |
| 335 kind_(kind), | 337 kind_(kind), |
| 336 process_launched_(false), | 338 process_launched_(false), |
| 337 initialized_(false), | 339 initialized_(false), |
| 338 gpu_crash_recorded_(false), | 340 gpu_crash_recorded_(false), |
| 339 uma_memory_stats_received_(false) { | 341 uma_memory_stats_received_(false) { |
| 340 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess) || | 342 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 341 CommandLine::ForCurrentProcess()->HasSwitch(switches::kInProcessGPU)) { | 343 switches::kSingleProcess) || |
| 344 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 345 switches::kInProcessGPU)) { |
| 342 in_process_ = true; | 346 in_process_ = true; |
| 343 } | 347 } |
| 344 | 348 |
| 345 // If the 'single GPU process' policy ever changes, we still want to maintain | 349 // If the 'single GPU process' policy ever changes, we still want to maintain |
| 346 // it for 'gpu thread' mode and only create one instance of host and thread. | 350 // it for 'gpu thread' mode and only create one instance of host and thread. |
| 347 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); | 351 DCHECK(!in_process_ || g_gpu_process_hosts[kind] == NULL); |
| 348 | 352 |
| 349 g_gpu_process_hosts[kind] = this; | 353 g_gpu_process_hosts[kind] = this; |
| 350 | 354 |
| 351 // Post a task to create the corresponding GpuProcessHostUIShim. The | 355 // Post a task to create the corresponding GpuProcessHostUIShim. The |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 init_start_time_ = base::TimeTicks::Now(); | 456 init_start_time_ = base::TimeTicks::Now(); |
| 453 | 457 |
| 454 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); | 458 TRACE_EVENT_INSTANT0("gpu", "LaunchGpuProcess", TRACE_EVENT_SCOPE_THREAD); |
| 455 | 459 |
| 456 std::string channel_id = process_->GetHost()->CreateChannel(); | 460 std::string channel_id = process_->GetHost()->CreateChannel(); |
| 457 if (channel_id.empty()) | 461 if (channel_id.empty()) |
| 458 return false; | 462 return false; |
| 459 | 463 |
| 460 if (in_process_) { | 464 if (in_process_) { |
| 461 DCHECK(g_gpu_main_thread_factory); | 465 DCHECK(g_gpu_main_thread_factory); |
| 462 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 466 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 463 command_line->AppendSwitch(switches::kDisableGpuWatchdog); | 467 command_line->AppendSwitch(switches::kDisableGpuWatchdog); |
| 464 | 468 |
| 465 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); | 469 GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); |
| 466 DCHECK(gpu_data_manager); | 470 DCHECK(gpu_data_manager); |
| 467 gpu_data_manager->AppendGpuCommandLine(command_line); | 471 gpu_data_manager->AppendGpuCommandLine(command_line); |
| 468 | 472 |
| 469 in_process_gpu_thread_.reset(g_gpu_main_thread_factory(channel_id)); | 473 in_process_gpu_thread_.reset(g_gpu_main_thread_factory(channel_id)); |
| 470 in_process_gpu_thread_->Start(); | 474 in_process_gpu_thread_->Start(); |
| 471 | 475 |
| 472 OnProcessLaunched(); // Fake a callback that the process is ready. | 476 OnProcessLaunched(); // Fake a callback that the process is ready. |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 } | 569 } |
| 566 | 570 |
| 567 if (Send(new GpuMsg_EstablishChannel( | 571 if (Send(new GpuMsg_EstablishChannel( |
| 568 client_id, share_context, allow_future_sync_points))) { | 572 client_id, share_context, allow_future_sync_points))) { |
| 569 channel_requests_.push(callback); | 573 channel_requests_.push(callback); |
| 570 } else { | 574 } else { |
| 571 DVLOG(1) << "Failed to send GpuMsg_EstablishChannel."; | 575 DVLOG(1) << "Failed to send GpuMsg_EstablishChannel."; |
| 572 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); | 576 callback.Run(IPC::ChannelHandle(), gpu::GPUInfo()); |
| 573 } | 577 } |
| 574 | 578 |
| 575 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 579 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 576 switches::kDisableGpuShaderDiskCache)) { | 580 switches::kDisableGpuShaderDiskCache)) { |
| 577 CreateChannelCache(client_id); | 581 CreateChannelCache(client_id); |
| 578 } | 582 } |
| 579 } | 583 } |
| 580 | 584 |
| 581 void GpuProcessHost::CreateViewCommandBuffer( | 585 void GpuProcessHost::CreateViewCommandBuffer( |
| 582 const gfx::GLSurfaceHandle& compositing_surface, | 586 const gfx::GLSurfaceHandle& compositing_surface, |
| 583 int surface_id, | 587 int surface_id, |
| 584 int client_id, | 588 int client_id, |
| 585 const GPUCreateCommandBufferConfig& init_params, | 589 const GPUCreateCommandBufferConfig& init_params, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 } | 839 } |
| 836 | 840 |
| 837 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { | 841 bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) { |
| 838 if (!(gpu_enabled_ && | 842 if (!(gpu_enabled_ && |
| 839 GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()) && | 843 GpuDataManagerImpl::GetInstance()->ShouldUseSwiftShader()) && |
| 840 !hardware_gpu_enabled_) { | 844 !hardware_gpu_enabled_) { |
| 841 SendOutstandingReplies(); | 845 SendOutstandingReplies(); |
| 842 return false; | 846 return false; |
| 843 } | 847 } |
| 844 | 848 |
| 845 const CommandLine& browser_command_line = *CommandLine::ForCurrentProcess(); | 849 const base::CommandLine& browser_command_line = |
| 850 *base::CommandLine::ForCurrentProcess(); |
| 846 | 851 |
| 847 CommandLine::StringType gpu_launcher = | 852 base::CommandLine::StringType gpu_launcher = |
| 848 browser_command_line.GetSwitchValueNative(switches::kGpuLauncher); | 853 browser_command_line.GetSwitchValueNative(switches::kGpuLauncher); |
| 849 | 854 |
| 850 #if defined(OS_LINUX) | 855 #if defined(OS_LINUX) |
| 851 int child_flags = gpu_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : | 856 int child_flags = gpu_launcher.empty() ? ChildProcessHost::CHILD_ALLOW_SELF : |
| 852 ChildProcessHost::CHILD_NORMAL; | 857 ChildProcessHost::CHILD_NORMAL; |
| 853 #else | 858 #else |
| 854 int child_flags = ChildProcessHost::CHILD_NORMAL; | 859 int child_flags = ChildProcessHost::CHILD_NORMAL; |
| 855 #endif | 860 #endif |
| 856 | 861 |
| 857 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); | 862 base::FilePath exe_path = ChildProcessHost::GetChildPath(child_flags); |
| 858 if (exe_path.empty()) | 863 if (exe_path.empty()) |
| 859 return false; | 864 return false; |
| 860 | 865 |
| 861 CommandLine* cmd_line = new CommandLine(exe_path); | 866 base::CommandLine* cmd_line = new base::CommandLine(exe_path); |
| 862 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); | 867 cmd_line->AppendSwitchASCII(switches::kProcessType, switches::kGpuProcess); |
| 863 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); | 868 cmd_line->AppendSwitchASCII(switches::kProcessChannelID, channel_id); |
| 864 | 869 |
| 865 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) | 870 if (kind_ == GPU_PROCESS_KIND_UNSANDBOXED) |
| 866 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); | 871 cmd_line->AppendSwitch(switches::kDisableGpuSandbox); |
| 867 | 872 |
| 868 // Propagate relevant command line switches. | 873 // Propagate relevant command line switches. |
| 869 static const char* const kSwitchNames[] = { | 874 static const char* const kSwitchNames[] = { |
| 870 switches::kDisableAcceleratedVideoDecode, | 875 switches::kDisableAcceleratedVideoDecode, |
| 871 switches::kDisableBreakpad, | 876 switches::kDisableBreakpad, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 return; | 980 return; |
| 976 | 981 |
| 977 // Maximum number of times the gpu process is allowed to crash in a session. | 982 // Maximum number of times the gpu process is allowed to crash in a session. |
| 978 // Once this limit is reached, any request to launch the gpu process will | 983 // Once this limit is reached, any request to launch the gpu process will |
| 979 // fail. | 984 // fail. |
| 980 const int kGpuMaxCrashCount = 3; | 985 const int kGpuMaxCrashCount = 3; |
| 981 | 986 |
| 982 // Last time the GPU process crashed. | 987 // Last time the GPU process crashed. |
| 983 static base::Time last_gpu_crash_time; | 988 static base::Time last_gpu_crash_time; |
| 984 | 989 |
| 985 bool disable_crash_limit = CommandLine::ForCurrentProcess()->HasSwitch( | 990 bool disable_crash_limit = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 986 switches::kDisableGpuProcessCrashLimit); | 991 switches::kDisableGpuProcessCrashLimit); |
| 987 | 992 |
| 988 // Ending only acts as a failure if the GPU process was actually started and | 993 // Ending only acts as a failure if the GPU process was actually started and |
| 989 // was intended for actual rendering (and not just checking caps or other | 994 // was intended for actual rendering (and not just checking caps or other |
| 990 // options). | 995 // options). |
| 991 if (process_launched_ && kind_ == GPU_PROCESS_KIND_SANDBOXED) { | 996 if (process_launched_ && kind_ == GPU_PROCESS_KIND_SANDBOXED) { |
| 992 gpu_crash_recorded_ = true; | 997 gpu_crash_recorded_ = true; |
| 993 if (swiftshader_rendering_) { | 998 if (swiftshader_rendering_) { |
| 994 UMA_HISTOGRAM_ENUMERATION("GPU.SwiftShaderLifetimeEvents", | 999 UMA_HISTOGRAM_ENUMERATION("GPU.SwiftShaderLifetimeEvents", |
| 995 DIED_FIRST_TIME + swiftshader_crash_count_, | 1000 DIED_FIRST_TIME + swiftshader_crash_count_, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1080 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); | 1085 TRACE_EVENT0("gpu", "GpuProcessHost::OnCacheShader"); |
| 1081 ClientIdToShaderCacheMap::iterator iter = | 1086 ClientIdToShaderCacheMap::iterator iter = |
| 1082 client_id_to_shader_cache_.find(client_id); | 1087 client_id_to_shader_cache_.find(client_id); |
| 1083 // If the cache doesn't exist then this is an off the record profile. | 1088 // If the cache doesn't exist then this is an off the record profile. |
| 1084 if (iter == client_id_to_shader_cache_.end()) | 1089 if (iter == client_id_to_shader_cache_.end()) |
| 1085 return; | 1090 return; |
| 1086 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); | 1091 iter->second->Cache(GetShaderPrefixKey() + ":" + key, shader); |
| 1087 } | 1092 } |
| 1088 | 1093 |
| 1089 } // namespace content | 1094 } // namespace content |
| OLD | NEW |