blob: dc59afbfec9c144abb98a379ea85e32f6ab1cd1e [file] [log] [blame]
[email protected]2e3d9e42012-02-14 03:23:381// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c0fc0942010-01-13 00:55:372// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]e09cee42010-11-09 01:50:085#include <stdlib.h>
6
[email protected]cafd0b62011-01-19 01:22:057#if defined(OS_WIN)
8#include <windows.h>
9#endif
10
[email protected]d13f35d2012-05-18 02:28:1511#include "base/debug/trace_event.h"
[email protected]ec4bda62013-06-14 15:51:0312#include "base/lazy_instance.h"
[email protected]c0fc0942010-01-13 00:55:3713#include "base/message_loop.h"
[email protected]2436a6b2012-04-13 21:08:5114#include "base/rand_util.h"
[email protected]d0ea4782013-06-11 04:58:2415#include "base/strings/string_number_conversions.h"
16#include "base/strings/stringprintf.h"
[email protected]ce072a72010-12-31 20:02:1617#include "base/threading/platform_thread.h"
[email protected]c0fc0942010-01-13 00:55:3718#include "build/build_config.h"
[email protected]10208ea2013-06-06 20:08:0319#include "content/child/child_process.h"
[email protected]f24a1e2b2011-04-08 01:48:4820#include "content/common/gpu/gpu_config.h"
[email protected]ec4bda62013-06-14 15:51:0321#include "content/common/gpu/gpu_messages.h"
[email protected]1b73f77e2013-04-13 02:00:4722#include "content/common/sandbox_linux.h"
[email protected]7a31f7c2011-03-21 23:22:0423#include "content/gpu/gpu_child_thread.h"
[email protected]623c0bd2011-03-12 01:00:4124#include "content/gpu/gpu_process.h"
[email protected]db6101db2012-10-25 15:20:0825#include "content/gpu/gpu_watchdog_thread.h"
[email protected]c9e2cbbb2012-05-12 21:17:2726#include "content/public/common/content_client.h"
27#include "content/public/common/content_switches.h"
28#include "content/public/common/main_function_params.h"
[email protected]5fa097a2012-05-10 21:59:0729#include "crypto/hmac.h"
[email protected]d7b5cc72013-05-23 20:05:0030#include "gpu/config/gpu_info_collector.h"
[email protected]db6101db2012-10-25 15:20:0831#include "ui/gl/gl_implementation.h"
[email protected]c9e2cbbb2012-05-12 21:17:2732#include "ui/gl/gl_surface.h"
33#include "ui/gl/gl_switches.h"
[email protected]1bb06b02012-09-23 19:37:2434#include "ui/gl/gpu_switching_manager.h"
[email protected]c0fc0942010-01-13 00:55:3735
[email protected]d7de57872011-12-06 23:32:4336#if defined(OS_WIN)
[email protected]5f7e4512012-10-01 20:51:3737#include "base/win/scoped_com_initializer.h"
[email protected]7ad3a4352011-12-22 22:18:0038#include "content/common/gpu/media/dxva_video_decode_accelerator.h"
[email protected]181491782012-07-18 00:59:1539#include "sandbox/win/src/sandbox.h"
[email protected]106e38b2013-03-11 23:16:4540#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
[email protected]10f5d592013-01-16 13:21:1241#include "content/common/gpu/media/exynos_video_decode_accelerator.h"
[email protected]d254e7e2012-08-04 08:38:1042#include "content/common/gpu/media/omx_video_decode_accelerator.h"
[email protected]106e38b2013-03-11 23:16:4543#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
[email protected]fd99f1f2013-05-31 06:52:4144#include "content/common/gpu/media/vaapi_wrapper.h"
[email protected]802a13a02010-12-02 01:48:3745#endif
46
[email protected]02ec37a2010-09-20 22:32:1647#if defined(USE_X11)
[email protected]57b5d7dc2011-03-09 14:11:3448#include "ui/base/x/x11_util.h"
[email protected]02ec37a2010-09-20 22:32:1649#endif
50
[email protected]2436a6b2012-04-13 21:08:5151#if defined(OS_LINUX)
52#include "content/public/common/sandbox_init.h"
53#endif
54
[email protected]db6101db2012-10-25 15:20:0855const int kGpuTimeout = 10000;
56
[email protected]eb398192012-10-22 20:16:1957namespace content {
[email protected]ec4bda62013-06-14 15:51:0358
[email protected]6ec3a572012-08-17 02:09:5159namespace {
[email protected]ec4bda62013-06-14 15:51:0360
[email protected]ca23992b02013-06-13 17:25:1961bool WarmUpSandbox(const CommandLine& command_line);
[email protected]663c4b32013-04-18 05:52:5462#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:0063bool StartSandboxLinux(const gpu::GPUInfo&, GpuWatchdogThread*, bool);
[email protected]663c4b32013-04-18 05:52:5464#elif defined(OS_WIN)
65bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*);
66#endif
[email protected]ec4bda62013-06-14 15:51:0367
68base::LazyInstance<GpuChildThread::DeferredMessages> deferred_messages =
69 LAZY_INSTANCE_INITIALIZER;
70
71bool GpuProcessLogMessageHandler(int severity,
72 const char* file, int line,
73 size_t message_start,
74 const std::string& str) {
75 std::string header = str.substr(0, message_start);
76 std::string message = str.substr(message_start);
77 deferred_messages.Get().push(new GpuHostMsg_OnLogMessage(
78 severity, header, message));
79 return false;
[email protected]6ec3a572012-08-17 02:09:5180}
81
[email protected]ec4bda62013-06-14 15:51:0382} // namespace anonymous
83
[email protected]c0fc0942010-01-13 00:55:3784// Main function for starting the Gpu process.
[email protected]eb398192012-10-22 20:16:1985int GpuMain(const MainFunctionParams& parameters) {
[email protected]d13f35d2012-05-18 02:28:1586 TRACE_EVENT0("gpu", "GpuMain");
87
[email protected]badf5cf2011-10-29 03:44:4488 const CommandLine& command_line = parameters.command_line;
[email protected]6b889fb2010-03-23 20:09:4989 if (command_line.HasSwitch(switches::kGpuStartupDialog)) {
[email protected]75fcc272011-03-08 20:50:4890 ChildProcess::WaitForDebugger("Gpu");
[email protected]6b889fb2010-03-23 20:09:4991 }
92
[email protected]ca23992b02013-06-13 17:25:1993 base::Time start_time = base::Time::Now();
94
[email protected]ec4bda62013-06-14 15:51:0395 bool in_browser_process = command_line.HasSwitch(switches::kSingleProcess) ||
96 command_line.HasSwitch(switches::kInProcessGPU);
97
98 if (!in_browser_process) {
[email protected]23f46562011-09-07 01:42:3999#if defined(OS_WIN)
100 // Prevent Windows from displaying a modal dialog on failures like not being
101 // able to load a DLL.
102 SetErrorMode(
103 SEM_FAILCRITICALERRORS |
104 SEM_NOGPFAULTERRORBOX |
105 SEM_NOOPENFILEERRORBOX);
106#elif defined(USE_X11)
107 ui::SetDefaultX11ErrorHandlers();
108#endif
[email protected]ec4bda62013-06-14 15:51:03109
110 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
[email protected]23f46562011-09-07 01:42:39111 }
112
[email protected]48fe7e42012-10-01 23:06:04113 if (command_line.HasSwitch(switches::kSupportsDualGpus) &&
114 command_line.HasSwitch(switches::kGpuSwitching)) {
[email protected]1bb06b02012-09-23 19:37:24115 std::string option = command_line.GetSwitchValueASCII(
116 switches::kGpuSwitching);
117 if (option == switches::kGpuSwitchingOptionNameForceDiscrete)
[email protected]a2221e82012-10-08 22:33:14118 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu();
[email protected]1bb06b02012-09-23 19:37:24119 else if (option == switches::kGpuSwitchingOptionNameForceIntegrated)
[email protected]a2221e82012-10-08 22:33:14120 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu();
[email protected]1bb06b02012-09-23 19:37:24121 }
122
[email protected]0b2cec62011-07-22 18:13:28123 // Initialization of the OpenGL bindings may fail, in which case we
124 // will need to tear down this process. However, we can not do so
125 // safely until the IPC channel is set up, because the detection of
126 // early return of a child process is implemented using an IPC
127 // channel error. If the IPC channel is not fully set up between the
128 // browser and GPU process, and the GPU process crashes or exits
129 // early, the browser process will never detect it. For this reason
130 // we defer tearing down the GPU process until receiving the
131 // GpuMsg_Initialize message from the browser.
132 bool dead_on_arrival = false;
133
[email protected]dd32b1272013-05-04 14:17:11134 base::MessageLoop::Type message_loop_type = base::MessageLoop::TYPE_IO;
[email protected]db6101db2012-10-25 15:20:08135#if defined(OS_WIN)
136 // Unless we're running on desktop GL, we don't need a UI message
137 // loop, so avoid its use to work around apparent problems with some
138 // third-party software.
139 if (command_line.HasSwitch(switches::kUseGL) &&
140 command_line.GetSwitchValueASCII(switches::kUseGL) ==
141 gfx::kGLImplementationDesktopName) {
[email protected]dd32b1272013-05-04 14:17:11142 message_loop_type = base::MessageLoop::TYPE_UI;
[email protected]db6101db2012-10-25 15:20:08143 }
144#elif defined(OS_LINUX)
[email protected]dd32b1272013-05-04 14:17:11145 message_loop_type = base::MessageLoop::TYPE_DEFAULT;
[email protected]db6101db2012-10-25 15:20:08146#endif
147
[email protected]dd32b1272013-05-04 14:17:11148 base::MessageLoop main_message_loop(message_loop_type);
[email protected]db6101db2012-10-25 15:20:08149 base::PlatformThread::SetName("CrGpuMain");
150
151 // In addition to disabling the watchdog if the command line switch is
152 // present, disable the watchdog on valgrind because the code is expected
153 // to run slowly in that case.
154 bool enable_watchdog =
[email protected]ca23992b02013-06-13 17:25:19155 !command_line.HasSwitch(switches::kDisableGpuWatchdog) &&
[email protected]db6101db2012-10-25 15:20:08156 !RunningOnValgrind();
157
158 // Disable the watchdog in debug builds because they tend to only be run by
159 // developers who will not appreciate the watchdog killing the GPU process.
160#ifndef NDEBUG
161 enable_watchdog = false;
162#endif
163
[email protected]42719602012-11-08 02:51:12164 bool delayed_watchdog_enable = false;
165
166#if defined(OS_CHROMEOS)
167 // Don't start watchdog immediately, to allow developers to switch to VT2 on
168 // startup.
169 delayed_watchdog_enable = true;
170#endif
171
[email protected]db6101db2012-10-25 15:20:08172 scoped_refptr<GpuWatchdogThread> watchdog_thread;
173
174 // Start the GPU watchdog only after anything that is expected to be time
175 // consuming has completed, otherwise the process is liable to be aborted.
[email protected]42719602012-11-08 02:51:12176 if (enable_watchdog && !delayed_watchdog_enable) {
[email protected]db6101db2012-10-25 15:20:08177 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
178 watchdog_thread->Start();
179 }
180
[email protected]d7b5cc72013-05-23 20:05:00181 gpu::GPUInfo gpu_info;
[email protected]085170ca2012-05-17 20:27:28182 // Get vendor_id, device_id, driver_version from browser process through
183 // commandline switches.
184 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) &&
185 command_line.HasSwitch(switches::kGpuDeviceID) &&
186 command_line.HasSwitch(switches::kGpuDriverVersion));
187 bool success = base::HexStringToInt(
188 command_line.GetSwitchValueASCII(switches::kGpuVendorID),
189 reinterpret_cast<int*>(&(gpu_info.gpu.vendor_id)));
190 DCHECK(success);
191 success = base::HexStringToInt(
192 command_line.GetSwitchValueASCII(switches::kGpuDeviceID),
193 reinterpret_cast<int*>(&(gpu_info.gpu.device_id)));
[email protected]8114edfb2012-06-22 01:07:21194 DCHECK(success);
195 gpu_info.driver_vendor =
196 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor);
[email protected]085170ca2012-05-17 20:27:28197 gpu_info.driver_version =
198 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion);
[email protected]eb398192012-10-22 20:16:19199 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]f0918242012-02-18 00:30:50200
[email protected]663c4b32013-04-18 05:52:54201 // Warm up resources that don't need access to GPUInfo.
[email protected]ca23992b02013-06-13 17:25:19202 if (WarmUpSandbox(command_line)) {
[email protected]663c4b32013-04-18 05:52:54203#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19204 bool initialized_sandbox = false;
205 bool initialized_gl_context = false;
206 bool should_initialize_gl_context = false;
[email protected]663c4b32013-04-18 05:52:54207#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
[email protected]ca23992b02013-06-13 17:25:19208 // On Chrome OS ARM, GPU driver userspace creates threads when initializing
209 // a GL context, so start the sandbox early.
210 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
211 should_initialize_gl_context);
212 initialized_sandbox = true;
[email protected]663c4b32013-04-18 05:52:54213#endif
214#endif // defined(OS_LINUX)
215
[email protected]ca23992b02013-06-13 17:25:19216 // Load and initialize the GL implementation and locate the GL entry points.
217 if (gfx::GLSurface::InitializeOneOff()) {
218 // We need to collect GL strings (VENDOR, RENDERER) for blacklisting
219 // purposes. However, on Mac we don't actually use them. As documented in
220 // crbug.com/222934, due to some driver issues, glGetString could take
221 // multiple seconds to finish, which in turn cause the GPU process to
222 // crash.
223 // By skipping the following code on Mac, we don't really lose anything,
224 // because the basic GPU information is passed down from browser process
[email protected]ec4bda62013-06-14 15:51:03225 // and we already registered them through SetGpuInfo() above.
[email protected]e9931a42013-04-11 00:48:41226#if !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19227 if (!gpu::CollectContextGraphicsInfo(&gpu_info))
228 VLOG(1) << "gpu::CollectGraphicsInfo failed";
229 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]3a62be092012-10-09 20:58:19230
[email protected]663c4b32013-04-18 05:52:54231#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19232 initialized_gl_context = true;
[email protected]663c4b32013-04-18 05:52:54233#if !defined(OS_CHROMEOS)
[email protected]ca23992b02013-06-13 17:25:19234 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
235 gpu_info.driver_vendor == "NVIDIA") {
236 base::ThreadRestrictions::AssertIOAllowed();
237 if (access("/dev/nvidiactl", R_OK) != 0) {
238 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied";
239 gpu_info.gpu_accessible = false;
240 dead_on_arrival = true;
241 }
[email protected]42dc3c02012-03-28 00:28:55242 }
[email protected]663c4b32013-04-18 05:52:54243#endif // !defined(OS_CHROMEOS)
244#endif // defined(OS_LINUX)
245#endif // !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19246 } else {
247 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed";
248 gpu_info.gpu_accessible = false;
249 gpu_info.finalized = true;
250 dead_on_arrival = true;
251 }
[email protected]4a2a4d22011-07-25 23:20:34252
[email protected]ca23992b02013-06-13 17:25:19253 if (enable_watchdog && delayed_watchdog_enable) {
254 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
255 watchdog_thread->Start();
256 }
[email protected]42719602012-11-08 02:51:12257
[email protected]ca23992b02013-06-13 17:25:19258 // OSMesa is expected to run very slowly, so disable the watchdog in that
259 // case.
260 if (enable_watchdog &&
261 gfx::GetGLImplementation() == gfx::kGLImplementationOSMesaGL) {
262 watchdog_thread->Stop();
263 watchdog_thread = NULL;
264 }
[email protected]db6101db2012-10-25 15:20:08265
[email protected]c90e84d2012-06-12 17:55:00266#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19267 should_initialize_gl_context = !initialized_gl_context &&
268 !dead_on_arrival;
[email protected]c90e84d2012-06-12 17:55:00269
[email protected]ca23992b02013-06-13 17:25:19270 if (!initialized_sandbox) {
271 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
272 should_initialize_gl_context);
273 }
[email protected]663c4b32013-04-18 05:52:54274#elif defined(OS_WIN)
[email protected]ca23992b02013-06-13 17:25:19275 gpu_info.sandboxed = StartSandboxWindows(parameters.sandbox_info);
[email protected]0b2cec62011-07-22 18:13:28276#endif
[email protected]ec4bda62013-06-14 15:51:03277 } else {
278 dead_on_arrival = true;
[email protected]ca23992b02013-06-13 17:25:19279 }
[email protected]0b2cec62011-07-22 18:13:28280
[email protected]ec4bda62013-06-14 15:51:03281 logging::SetLogMessageHandler(NULL);
282
[email protected]983c33d2010-11-16 22:38:44283 GpuProcess gpu_process;
[email protected]8fe0ec522011-03-03 00:31:33284
[email protected]db6101db2012-10-25 15:20:08285 GpuChildThread* child_thread = new GpuChildThread(watchdog_thread.get(),
[email protected]ec4bda62013-06-14 15:51:03286 dead_on_arrival,
287 gpu_info,
288 deferred_messages.Get());
289 while (!deferred_messages.Get().empty())
290 deferred_messages.Get().pop();
[email protected]8fe0ec522011-03-03 00:31:33291
[email protected]7a31f7c2011-03-21 23:22:04292 child_thread->Init(start_time);
[email protected]995a7f12011-02-11 23:07:17293
[email protected]7a31f7c2011-03-21 23:22:04294 gpu_process.set_main_thread(child_thread);
[email protected]983c33d2010-11-16 22:38:44295
[email protected]d13f35d2012-05-18 02:28:15296 {
297 TRACE_EVENT0("gpu", "Run Message Loop");
298 main_message_loop.Run();
299 }
[email protected]c0fc0942010-01-13 00:55:37300
[email protected]7a31f7c2011-03-21 23:22:04301 child_thread->StopWatchdog();
[email protected]e09cee42010-11-09 01:50:08302
[email protected]c0fc0942010-01-13 00:55:37303 return 0;
304}
[email protected]6ec3a572012-08-17 02:09:51305
306namespace {
307
[email protected]59a7ae4e2012-10-01 23:54:44308#if defined(OS_LINUX)
[email protected]6ec3a572012-08-17 02:09:51309void CreateDummyGlContext() {
310 scoped_refptr<gfx::GLSurface> surface(
311 gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)));
[email protected]fc72bb12013-06-02 21:13:46312 if (!surface.get()) {
[email protected]6ec3a572012-08-17 02:09:51313 VLOG(1) << "gfx::GLSurface::CreateOffscreenGLSurface failed";
314 return;
315 }
316
317 // On Linux, this is needed to make sure /dev/nvidiactl has
318 // been opened and its descriptor cached.
[email protected]fc72bb12013-06-02 21:13:46319 scoped_refptr<gfx::GLContext> context(gfx::GLContext::CreateGLContext(
320 NULL, surface.get(), gfx::PreferDiscreteGpu));
321 if (!context.get()) {
[email protected]6ec3a572012-08-17 02:09:51322 VLOG(1) << "gfx::GLContext::CreateGLContext failed";
323 return;
324 }
325
326 // Similarly, this is needed for /dev/nvidia0.
[email protected]fc72bb12013-06-02 21:13:46327 if (context->MakeCurrent(surface.get())) {
[email protected]6ec3a572012-08-17 02:09:51328 context->ReleaseCurrent(surface.get());
329 } else {
330 VLOG(1) << "gfx::GLContext::MakeCurrent failed";
331 }
332}
[email protected]59a7ae4e2012-10-01 23:54:44333#endif
[email protected]6ec3a572012-08-17 02:09:51334
[email protected]ca23992b02013-06-13 17:25:19335bool WarmUpSandbox(const CommandLine& command_line) {
[email protected]6ec3a572012-08-17 02:09:51336 {
337 TRACE_EVENT0("gpu", "Warm up rand");
338 // Warm up the random subsystem, which needs to be done pre-sandbox on all
339 // platforms.
340 (void) base::RandUint64();
341 }
342 {
343 TRACE_EVENT0("gpu", "Warm up HMAC");
344 // Warm up the crypto subsystem, which needs to done pre-sandbox on all
345 // platforms.
346 crypto::HMAC hmac(crypto::HMAC::SHA256);
347 unsigned char key = '\0';
[email protected]ca23992b02013-06-13 17:25:19348 if (!hmac.Init(&key, sizeof(key))) {
349 LOG(ERROR) << "WarmUpSandbox() failed with crypto::HMAC::Init()";
350 return false;
351 }
[email protected]6ec3a572012-08-17 02:09:51352 }
353
[email protected]106e38b2013-03-11 23:16:45354#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
[email protected]10f5d592013-01-16 13:21:12355 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseExynosVda))
356 ExynosVideoDecodeAccelerator::PreSandboxInitialization();
357 else
358 OmxVideoDecodeAccelerator::PreSandboxInitialization();
[email protected]106e38b2013-03-11 23:16:45359#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
[email protected]fd99f1f2013-05-31 06:52:41360 VaapiWrapper::PreSandboxInitialization();
[email protected]6ec3a572012-08-17 02:09:51361#endif
362
[email protected]5f7e4512012-10-01 20:51:37363#if defined(OS_WIN)
[email protected]2abf9122013-03-12 03:00:19364 {
[email protected]2abf9122013-03-12 03:00:19365 TRACE_EVENT0("gpu", "Preload setupapi.dll");
366 // Preload this DLL because the sandbox prevents it from loading.
[email protected]ca23992b02013-06-13 17:25:19367 if (LoadLibrary(L"setupapi.dll") == NULL) {
368 LOG(ERROR) << "WarmUpSandbox() failed with loading setupapi.dll";
369 return false;
370 }
[email protected]2abf9122013-03-12 03:00:19371 }
372
[email protected]ca23992b02013-06-13 17:25:19373 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode)) {
[email protected]2abf9122013-03-12 03:00:19374 TRACE_EVENT0("gpu", "Initialize DXVA");
375 // Initialize H/W video decoding stuff which fails in the sandbox.
376 DXVAVideoDecodeAccelerator::PreSandboxInitialization();
377 }
[email protected]6ec3a572012-08-17 02:09:51378#endif
[email protected]ca23992b02013-06-13 17:25:19379 return true;
[email protected]6ec3a572012-08-17 02:09:51380}
381
[email protected]663c4b32013-04-18 05:52:54382#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:00383void WarmUpSandboxNvidia(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54384 bool should_initialize_gl_context) {
385 // We special case Optimus since the vendor_id we see may not be Nvidia.
386 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA.
387 gpu_info.driver_vendor == "NVIDIA") ||
388 gpu_info.optimus;
389 if (uses_nvidia_driver && should_initialize_gl_context) {
390 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
391 CreateDummyGlContext();
392 }
393}
394
[email protected]d7b5cc72013-05-23 20:05:00395bool StartSandboxLinux(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54396 GpuWatchdogThread* watchdog_thread,
397 bool should_initialize_gl_context) {
398 TRACE_EVENT0("gpu", "Initialize sandbox");
399
400 bool res = false;
401
402 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context);
403
404 if (watchdog_thread)
405 watchdog_thread->Stop();
406 // LinuxSandbox::InitializeSandbox() must always be called
407 // with only one thread.
408 res = LinuxSandbox::InitializeSandbox();
409 if (watchdog_thread)
410 watchdog_thread->Start();
411
412 return res;
413}
414#endif // defined(OS_LINUX)
415
416#if defined(OS_WIN)
417bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo* sandbox_info) {
418 TRACE_EVENT0("gpu", "Lower token");
419
420 // For Windows, if the target_services interface is not zero, the process
421 // is sandboxed and we must call LowerToken() before rendering untrusted
422 // content.
423 sandbox::TargetServices* target_services = sandbox_info->target_services;
424 if (target_services) {
425 target_services->LowerToken();
426 return true;
427 }
428
429 return false;
430}
431#endif // defined(OS_WIN)
432
[email protected]6ec3a572012-08-17 02:09:51433} // namespace.
434
[email protected]eb398192012-10-22 20:16:19435} // namespace content