| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #endif | 39 #endif |
| 40 | 40 |
| 41 #if defined(USE_X11) | 41 #if defined(USE_X11) |
| 42 #include "ui/base/x/x11_util.h" | 42 #include "ui/base/x/x11_util.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 #if defined(OS_LINUX) | 45 #if defined(OS_LINUX) |
| 46 #include "content/public/common/sandbox_init.h" | 46 #include "content/public/common/sandbox_init.h" |
| 47 #endif | 47 #endif |
| 48 | 48 |
| 49 namespace content { |
| 49 namespace { | 50 namespace { |
| 50 void WarmUpSandbox(const content::GPUInfo&, bool); | 51 void WarmUpSandbox(const GPUInfo&, bool); |
| 51 } | 52 } |
| 52 | 53 |
| 53 // Main function for starting the Gpu process. | 54 // Main function for starting the Gpu process. |
| 54 int GpuMain(const content::MainFunctionParams& parameters) { | 55 int GpuMain(const MainFunctionParams& parameters) { |
| 55 TRACE_EVENT0("gpu", "GpuMain"); | 56 TRACE_EVENT0("gpu", "GpuMain"); |
| 56 | 57 |
| 57 base::Time start_time = base::Time::Now(); | 58 base::Time start_time = base::Time::Now(); |
| 58 | 59 |
| 59 const CommandLine& command_line = parameters.command_line; | 60 const CommandLine& command_line = parameters.command_line; |
| 60 if (command_line.HasSwitch(switches::kGpuStartupDialog)) { | 61 if (command_line.HasSwitch(switches::kGpuStartupDialog)) { |
| 61 ChildProcess::WaitForDebugger("Gpu"); | 62 ChildProcess::WaitForDebugger("Gpu"); |
| 62 } | 63 } |
| 63 | 64 |
| 64 if (!command_line.HasSwitch(switches::kSingleProcess)) { | 65 if (!command_line.HasSwitch(switches::kSingleProcess)) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 // will need to tear down this process. However, we can not do so | 89 // will need to tear down this process. However, we can not do so |
| 89 // safely until the IPC channel is set up, because the detection of | 90 // safely until the IPC channel is set up, because the detection of |
| 90 // early return of a child process is implemented using an IPC | 91 // early return of a child process is implemented using an IPC |
| 91 // channel error. If the IPC channel is not fully set up between the | 92 // channel error. If the IPC channel is not fully set up between the |
| 92 // browser and GPU process, and the GPU process crashes or exits | 93 // browser and GPU process, and the GPU process crashes or exits |
| 93 // early, the browser process will never detect it. For this reason | 94 // early, the browser process will never detect it. For this reason |
| 94 // we defer tearing down the GPU process until receiving the | 95 // we defer tearing down the GPU process until receiving the |
| 95 // GpuMsg_Initialize message from the browser. | 96 // GpuMsg_Initialize message from the browser. |
| 96 bool dead_on_arrival = false; | 97 bool dead_on_arrival = false; |
| 97 | 98 |
| 98 content::GPUInfo gpu_info; | 99 GPUInfo gpu_info; |
| 99 // Get vendor_id, device_id, driver_version from browser process through | 100 // Get vendor_id, device_id, driver_version from browser process through |
| 100 // commandline switches. | 101 // commandline switches. |
| 101 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) && | 102 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) && |
| 102 command_line.HasSwitch(switches::kGpuDeviceID) && | 103 command_line.HasSwitch(switches::kGpuDeviceID) && |
| 103 command_line.HasSwitch(switches::kGpuDriverVersion)); | 104 command_line.HasSwitch(switches::kGpuDriverVersion)); |
| 104 bool success = base::HexStringToInt( | 105 bool success = base::HexStringToInt( |
| 105 command_line.GetSwitchValueASCII(switches::kGpuVendorID), | 106 command_line.GetSwitchValueASCII(switches::kGpuVendorID), |
| 106 reinterpret_cast<int*>(&(gpu_info.gpu.vendor_id))); | 107 reinterpret_cast<int*>(&(gpu_info.gpu.vendor_id))); |
| 107 DCHECK(success); | 108 DCHECK(success); |
| 108 success = base::HexStringToInt( | 109 success = base::HexStringToInt( |
| 109 command_line.GetSwitchValueASCII(switches::kGpuDeviceID), | 110 command_line.GetSwitchValueASCII(switches::kGpuDeviceID), |
| 110 reinterpret_cast<int*>(&(gpu_info.gpu.device_id))); | 111 reinterpret_cast<int*>(&(gpu_info.gpu.device_id))); |
| 111 DCHECK(success); | 112 DCHECK(success); |
| 112 gpu_info.driver_vendor = | 113 gpu_info.driver_vendor = |
| 113 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor); | 114 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor); |
| 114 gpu_info.driver_version = | 115 gpu_info.driver_version = |
| 115 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion); | 116 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion); |
| 116 content::GetContentClient()->SetGpuInfo(gpu_info); | 117 GetContentClient()->SetGpuInfo(gpu_info); |
| 117 | 118 |
| 118 // We need to track that information for the WarmUpSandbox function. | 119 // We need to track that information for the WarmUpSandbox function. |
| 119 bool initialized_gl_context = false; | 120 bool initialized_gl_context = false; |
| 120 // Load and initialize the GL implementation and locate the GL entry points. | 121 // Load and initialize the GL implementation and locate the GL entry points. |
| 121 if (gfx::GLSurface::InitializeOneOff()) { | 122 if (gfx::GLSurface::InitializeOneOff()) { |
| 122 if (!command_line.HasSwitch(switches::kSkipGpuFullInfoCollection)) { | 123 if (!command_line.HasSwitch(switches::kSkipGpuFullInfoCollection)) { |
| 123 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info)) | 124 if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info)) |
| 124 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; | 125 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; |
| 125 content::GetContentClient()->SetGpuInfo(gpu_info); | 126 GetContentClient()->SetGpuInfo(gpu_info); |
| 126 | 127 |
| 127 // We know that CollectGraphicsInfo will initialize a GLContext. | 128 // We know that CollectGraphicsInfo will initialize a GLContext. |
| 128 initialized_gl_context = true; | 129 initialized_gl_context = true; |
| 129 } | 130 } |
| 130 | 131 |
| 131 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 132 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 132 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA | 133 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA |
| 133 gpu_info.driver_vendor == "NVIDIA") { | 134 gpu_info.driver_vendor == "NVIDIA") { |
| 134 base::ThreadRestrictions::AssertIOAllowed(); | 135 base::ThreadRestrictions::AssertIOAllowed(); |
| 135 if (access("/dev/nvidiactl", R_OK) != 0) { | 136 if (access("/dev/nvidiactl", R_OK) != 0) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 158 TRACE_EVENT0("gpu", "Initialize sandbox"); | 159 TRACE_EVENT0("gpu", "Initialize sandbox"); |
| 159 bool do_init_sandbox = true; | 160 bool do_init_sandbox = true; |
| 160 | 161 |
| 161 #if defined(OS_CHROMEOS) && defined(NDEBUG) | 162 #if defined(OS_CHROMEOS) && defined(NDEBUG) |
| 162 // On Chrome OS and when not on a debug build, initialize | 163 // On Chrome OS and when not on a debug build, initialize |
| 163 // the GPU process' sandbox only for Intel GPUs. | 164 // the GPU process' sandbox only for Intel GPUs. |
| 164 do_init_sandbox = gpu_info.gpu.vendor_id == 0x8086; // Intel GPU. | 165 do_init_sandbox = gpu_info.gpu.vendor_id == 0x8086; // Intel GPU. |
| 165 #endif | 166 #endif |
| 166 | 167 |
| 167 if (do_init_sandbox) { | 168 if (do_init_sandbox) { |
| 168 gpu_info.sandboxed = content::InitializeSandbox(); | 169 gpu_info.sandboxed = InitializeSandbox(); |
| 169 } | 170 } |
| 170 } | 171 } |
| 171 #endif | 172 #endif |
| 172 | 173 |
| 173 #if defined(OS_WIN) | 174 #if defined(OS_WIN) |
| 174 { | 175 { |
| 175 TRACE_EVENT0("gpu", "Lower token"); | 176 TRACE_EVENT0("gpu", "Lower token"); |
| 176 // For windows, if the target_services interface is not zero, the process | 177 // For windows, if the target_services interface is not zero, the process |
| 177 // is sandboxed and we must call LowerToken() before rendering untrusted | 178 // is sandboxed and we must call LowerToken() before rendering untrusted |
| 178 // content. | 179 // content. |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 245 |
| 245 // Similarly, this is needed for /dev/nvidia0. | 246 // Similarly, this is needed for /dev/nvidia0. |
| 246 if (context->MakeCurrent(surface)) { | 247 if (context->MakeCurrent(surface)) { |
| 247 context->ReleaseCurrent(surface.get()); | 248 context->ReleaseCurrent(surface.get()); |
| 248 } else { | 249 } else { |
| 249 VLOG(1) << "gfx::GLContext::MakeCurrent failed"; | 250 VLOG(1) << "gfx::GLContext::MakeCurrent failed"; |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 #endif | 253 #endif |
| 253 | 254 |
| 254 void WarmUpSandbox(const content::GPUInfo& gpu_info, | 255 void WarmUpSandbox(const GPUInfo& gpu_info, |
| 255 bool should_initialize_gl_context) { | 256 bool should_initialize_gl_context) { |
| 256 { | 257 { |
| 257 TRACE_EVENT0("gpu", "Warm up rand"); | 258 TRACE_EVENT0("gpu", "Warm up rand"); |
| 258 // Warm up the random subsystem, which needs to be done pre-sandbox on all | 259 // Warm up the random subsystem, which needs to be done pre-sandbox on all |
| 259 // platforms. | 260 // platforms. |
| 260 (void) base::RandUint64(); | 261 (void) base::RandUint64(); |
| 261 } | 262 } |
| 262 { | 263 { |
| 263 TRACE_EVENT0("gpu", "Warm up HMAC"); | 264 TRACE_EVENT0("gpu", "Warm up HMAC"); |
| 264 // Warm up the crypto subsystem, which needs to done pre-sandbox on all | 265 // Warm up the crypto subsystem, which needs to done pre-sandbox on all |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 { | 302 { |
| 302 TRACE_EVENT0("gpu", "Initialize DXVA"); | 303 TRACE_EVENT0("gpu", "Initialize DXVA"); |
| 303 // Initialize H/W video decoding stuff which fails in the sandbox. | 304 // Initialize H/W video decoding stuff which fails in the sandbox. |
| 304 DXVAVideoDecodeAccelerator::PreSandboxInitialization(); | 305 DXVAVideoDecodeAccelerator::PreSandboxInitialization(); |
| 305 } | 306 } |
| 306 #endif | 307 #endif |
| 307 } | 308 } |
| 308 | 309 |
| 309 } // namespace. | 310 } // namespace. |
| 310 | 311 |
| 312 } // namespace content |
| OLD | NEW |