blob: 22a8bf30711b79a6288e504c054d8ae522174137 [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]91a2aea2013-07-08 23:14:3920#include "content/common/content_constants_internal.h"
[email protected]f24a1e2b2011-04-08 01:48:4821#include "content/common/gpu/gpu_config.h"
[email protected]ec4bda62013-06-14 15:51:0322#include "content/common/gpu/gpu_messages.h"
[email protected]1b73f77e2013-04-13 02:00:4723#include "content/common/sandbox_linux.h"
[email protected]7a31f7c2011-03-21 23:22:0424#include "content/gpu/gpu_child_thread.h"
[email protected]623c0bd2011-03-12 01:00:4125#include "content/gpu/gpu_process.h"
[email protected]db6101db2012-10-25 15:20:0826#include "content/gpu/gpu_watchdog_thread.h"
[email protected]c9e2cbbb2012-05-12 21:17:2727#include "content/public/common/content_client.h"
28#include "content/public/common/content_switches.h"
29#include "content/public/common/main_function_params.h"
[email protected]5fa097a2012-05-10 21:59:0730#include "crypto/hmac.h"
[email protected]d7b5cc72013-05-23 20:05:0031#include "gpu/config/gpu_info_collector.h"
[email protected]db6101db2012-10-25 15:20:0832#include "ui/gl/gl_implementation.h"
[email protected]c9e2cbbb2012-05-12 21:17:2733#include "ui/gl/gl_surface.h"
34#include "ui/gl/gl_switches.h"
[email protected]1bb06b02012-09-23 19:37:2435#include "ui/gl/gpu_switching_manager.h"
[email protected]c0fc0942010-01-13 00:55:3736
[email protected]d7de57872011-12-06 23:32:4337#if defined(OS_WIN)
[email protected]5f7e4512012-10-01 20:51:3738#include "base/win/scoped_com_initializer.h"
[email protected]7ad3a4352011-12-22 22:18:0039#include "content/common/gpu/media/dxva_video_decode_accelerator.h"
[email protected]181491782012-07-18 00:59:1540#include "sandbox/win/src/sandbox.h"
[email protected]106e38b2013-03-11 23:16:4541#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
[email protected]10f5d592013-01-16 13:21:1242#include "content/common/gpu/media/exynos_video_decode_accelerator.h"
[email protected]d254e7e2012-08-04 08:38:1043#include "content/common/gpu/media/omx_video_decode_accelerator.h"
[email protected]106e38b2013-03-11 23:16:4544#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
[email protected]fd99f1f2013-05-31 06:52:4145#include "content/common/gpu/media/vaapi_wrapper.h"
[email protected]802a13a02010-12-02 01:48:3746#endif
47
[email protected]02ec37a2010-09-20 22:32:1648#if defined(USE_X11)
[email protected]57b5d7dc2011-03-09 14:11:3449#include "ui/base/x/x11_util.h"
[email protected]02ec37a2010-09-20 22:32:1650#endif
51
[email protected]2436a6b2012-04-13 21:08:5152#if defined(OS_LINUX)
53#include "content/public/common/sandbox_init.h"
54#endif
55
[email protected]db6101db2012-10-25 15:20:0856const int kGpuTimeout = 10000;
57
[email protected]eb398192012-10-22 20:16:1958namespace content {
[email protected]ec4bda62013-06-14 15:51:0359
[email protected]6ec3a572012-08-17 02:09:5160namespace {
[email protected]ec4bda62013-06-14 15:51:0361
[email protected]ca23992b02013-06-13 17:25:1962bool WarmUpSandbox(const CommandLine& command_line);
[email protected]663c4b32013-04-18 05:52:5463#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:0064bool StartSandboxLinux(const gpu::GPUInfo&, GpuWatchdogThread*, bool);
[email protected]663c4b32013-04-18 05:52:5465#elif defined(OS_WIN)
66bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*);
67#endif
[email protected]ec4bda62013-06-14 15:51:0368
69base::LazyInstance<GpuChildThread::DeferredMessages> deferred_messages =
70 LAZY_INSTANCE_INITIALIZER;
71
72bool GpuProcessLogMessageHandler(int severity,
73 const char* file, int line,
74 size_t message_start,
75 const std::string& str) {
76 std::string header = str.substr(0, message_start);
77 std::string message = str.substr(message_start);
78 deferred_messages.Get().push(new GpuHostMsg_OnLogMessage(
79 severity, header, message));
80 return false;
[email protected]6ec3a572012-08-17 02:09:5181}
82
[email protected]ec4bda62013-06-14 15:51:0383} // namespace anonymous
84
[email protected]c0fc0942010-01-13 00:55:3785// Main function for starting the Gpu process.
[email protected]eb398192012-10-22 20:16:1986int GpuMain(const MainFunctionParams& parameters) {
[email protected]d13f35d2012-05-18 02:28:1587 TRACE_EVENT0("gpu", "GpuMain");
[email protected]91a2aea2013-07-08 23:14:3988 base::debug::TraceLog::GetInstance()->SetProcessName("GPU Process");
89 base::debug::TraceLog::GetInstance()->SetProcessSortIndex(
90 kTraceEventGpuProcessSortIndex);
[email protected]d13f35d2012-05-18 02:28:1591
[email protected]badf5cf2011-10-29 03:44:4492 const CommandLine& command_line = parameters.command_line;
[email protected]6b889fb2010-03-23 20:09:4993 if (command_line.HasSwitch(switches::kGpuStartupDialog)) {
[email protected]75fcc272011-03-08 20:50:4894 ChildProcess::WaitForDebugger("Gpu");
[email protected]6b889fb2010-03-23 20:09:4995 }
96
[email protected]ca23992b02013-06-13 17:25:1997 base::Time start_time = base::Time::Now();
98
[email protected]ec4bda62013-06-14 15:51:0399 bool in_browser_process = command_line.HasSwitch(switches::kSingleProcess) ||
100 command_line.HasSwitch(switches::kInProcessGPU);
101
102 if (!in_browser_process) {
[email protected]23f46562011-09-07 01:42:39103#if defined(OS_WIN)
104 // Prevent Windows from displaying a modal dialog on failures like not being
105 // able to load a DLL.
106 SetErrorMode(
107 SEM_FAILCRITICALERRORS |
108 SEM_NOGPFAULTERRORBOX |
109 SEM_NOOPENFILEERRORBOX);
110#elif defined(USE_X11)
111 ui::SetDefaultX11ErrorHandlers();
112#endif
[email protected]ec4bda62013-06-14 15:51:03113
114 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
[email protected]23f46562011-09-07 01:42:39115 }
116
[email protected]48fe7e42012-10-01 23:06:04117 if (command_line.HasSwitch(switches::kSupportsDualGpus) &&
118 command_line.HasSwitch(switches::kGpuSwitching)) {
[email protected]1bb06b02012-09-23 19:37:24119 std::string option = command_line.GetSwitchValueASCII(
120 switches::kGpuSwitching);
121 if (option == switches::kGpuSwitchingOptionNameForceDiscrete)
[email protected]a2221e82012-10-08 22:33:14122 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu();
[email protected]1bb06b02012-09-23 19:37:24123 else if (option == switches::kGpuSwitchingOptionNameForceIntegrated)
[email protected]a2221e82012-10-08 22:33:14124 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu();
[email protected]1bb06b02012-09-23 19:37:24125 }
126
[email protected]0b2cec62011-07-22 18:13:28127 // Initialization of the OpenGL bindings may fail, in which case we
128 // will need to tear down this process. However, we can not do so
129 // safely until the IPC channel is set up, because the detection of
130 // early return of a child process is implemented using an IPC
131 // channel error. If the IPC channel is not fully set up between the
132 // browser and GPU process, and the GPU process crashes or exits
133 // early, the browser process will never detect it. For this reason
134 // we defer tearing down the GPU process until receiving the
135 // GpuMsg_Initialize message from the browser.
136 bool dead_on_arrival = false;
137
[email protected]dd32b1272013-05-04 14:17:11138 base::MessageLoop::Type message_loop_type = base::MessageLoop::TYPE_IO;
[email protected]db6101db2012-10-25 15:20:08139#if defined(OS_WIN)
140 // Unless we're running on desktop GL, we don't need a UI message
141 // loop, so avoid its use to work around apparent problems with some
142 // third-party software.
143 if (command_line.HasSwitch(switches::kUseGL) &&
144 command_line.GetSwitchValueASCII(switches::kUseGL) ==
145 gfx::kGLImplementationDesktopName) {
[email protected]dd32b1272013-05-04 14:17:11146 message_loop_type = base::MessageLoop::TYPE_UI;
[email protected]db6101db2012-10-25 15:20:08147 }
148#elif defined(OS_LINUX)
[email protected]dd32b1272013-05-04 14:17:11149 message_loop_type = base::MessageLoop::TYPE_DEFAULT;
[email protected]db6101db2012-10-25 15:20:08150#endif
151
[email protected]dd32b1272013-05-04 14:17:11152 base::MessageLoop main_message_loop(message_loop_type);
[email protected]db6101db2012-10-25 15:20:08153 base::PlatformThread::SetName("CrGpuMain");
154
155 // In addition to disabling the watchdog if the command line switch is
156 // present, disable the watchdog on valgrind because the code is expected
157 // to run slowly in that case.
158 bool enable_watchdog =
[email protected]ca23992b02013-06-13 17:25:19159 !command_line.HasSwitch(switches::kDisableGpuWatchdog) &&
[email protected]db6101db2012-10-25 15:20:08160 !RunningOnValgrind();
161
162 // Disable the watchdog in debug builds because they tend to only be run by
163 // developers who will not appreciate the watchdog killing the GPU process.
164#ifndef NDEBUG
165 enable_watchdog = false;
166#endif
167
[email protected]42719602012-11-08 02:51:12168 bool delayed_watchdog_enable = false;
169
170#if defined(OS_CHROMEOS)
171 // Don't start watchdog immediately, to allow developers to switch to VT2 on
172 // startup.
173 delayed_watchdog_enable = true;
174#endif
175
[email protected]db6101db2012-10-25 15:20:08176 scoped_refptr<GpuWatchdogThread> watchdog_thread;
177
178 // Start the GPU watchdog only after anything that is expected to be time
179 // consuming has completed, otherwise the process is liable to be aborted.
[email protected]42719602012-11-08 02:51:12180 if (enable_watchdog && !delayed_watchdog_enable) {
[email protected]db6101db2012-10-25 15:20:08181 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
182 watchdog_thread->Start();
183 }
184
[email protected]d7b5cc72013-05-23 20:05:00185 gpu::GPUInfo gpu_info;
[email protected]085170ca2012-05-17 20:27:28186 // Get vendor_id, device_id, driver_version from browser process through
187 // commandline switches.
188 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) &&
189 command_line.HasSwitch(switches::kGpuDeviceID) &&
190 command_line.HasSwitch(switches::kGpuDriverVersion));
191 bool success = base::HexStringToInt(
192 command_line.GetSwitchValueASCII(switches::kGpuVendorID),
193 reinterpret_cast<int*>(&(gpu_info.gpu.vendor_id)));
194 DCHECK(success);
195 success = base::HexStringToInt(
196 command_line.GetSwitchValueASCII(switches::kGpuDeviceID),
197 reinterpret_cast<int*>(&(gpu_info.gpu.device_id)));
[email protected]8114edfb2012-06-22 01:07:21198 DCHECK(success);
199 gpu_info.driver_vendor =
200 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor);
[email protected]085170ca2012-05-17 20:27:28201 gpu_info.driver_version =
202 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion);
[email protected]eb398192012-10-22 20:16:19203 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]f0918242012-02-18 00:30:50204
[email protected]663c4b32013-04-18 05:52:54205 // Warm up resources that don't need access to GPUInfo.
[email protected]ca23992b02013-06-13 17:25:19206 if (WarmUpSandbox(command_line)) {
[email protected]663c4b32013-04-18 05:52:54207#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19208 bool initialized_sandbox = false;
209 bool initialized_gl_context = false;
210 bool should_initialize_gl_context = false;
[email protected]663c4b32013-04-18 05:52:54211#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
[email protected]ca23992b02013-06-13 17:25:19212 // On Chrome OS ARM, GPU driver userspace creates threads when initializing
213 // a GL context, so start the sandbox early.
214 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
215 should_initialize_gl_context);
216 initialized_sandbox = true;
[email protected]663c4b32013-04-18 05:52:54217#endif
218#endif // defined(OS_LINUX)
219
[email protected]ca23992b02013-06-13 17:25:19220 // Load and initialize the GL implementation and locate the GL entry points.
221 if (gfx::GLSurface::InitializeOneOff()) {
222 // We need to collect GL strings (VENDOR, RENDERER) for blacklisting
223 // purposes. However, on Mac we don't actually use them. As documented in
224 // crbug.com/222934, due to some driver issues, glGetString could take
225 // multiple seconds to finish, which in turn cause the GPU process to
226 // crash.
227 // By skipping the following code on Mac, we don't really lose anything,
228 // because the basic GPU information is passed down from browser process
[email protected]ec4bda62013-06-14 15:51:03229 // and we already registered them through SetGpuInfo() above.
[email protected]e9931a42013-04-11 00:48:41230#if !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19231 if (!gpu::CollectContextGraphicsInfo(&gpu_info))
232 VLOG(1) << "gpu::CollectGraphicsInfo failed";
233 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]3a62be02012-10-09 20:58:19234
[email protected]663c4b32013-04-18 05:52:54235#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19236 initialized_gl_context = true;
[email protected]663c4b32013-04-18 05:52:54237#if !defined(OS_CHROMEOS)
[email protected]ca23992b02013-06-13 17:25:19238 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
239 gpu_info.driver_vendor == "NVIDIA") {
240 base::ThreadRestrictions::AssertIOAllowed();
241 if (access("/dev/nvidiactl", R_OK) != 0) {
242 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied";
[email protected]ca23992b02013-06-13 17:25:19243 dead_on_arrival = true;
244 }
[email protected]42dc3c02012-03-28 00:28:55245 }
[email protected]663c4b32013-04-18 05:52:54246#endif // !defined(OS_CHROMEOS)
247#endif // defined(OS_LINUX)
248#endif // !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19249 } else {
250 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed";
[email protected]ca23992b02013-06-13 17:25:19251 dead_on_arrival = true;
252 }
[email protected]4a2a4d22011-07-25 23:20:34253
[email protected]ca23992b02013-06-13 17:25:19254 if (enable_watchdog && delayed_watchdog_enable) {
255 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
256 watchdog_thread->Start();
257 }
[email protected]42719602012-11-08 02:51:12258
[email protected]ca23992b02013-06-13 17:25:19259 // OSMesa is expected to run very slowly, so disable the watchdog in that
260 // case.
261 if (enable_watchdog &&
262 gfx::GetGLImplementation() == gfx::kGLImplementationOSMesaGL) {
263 watchdog_thread->Stop();
264 watchdog_thread = NULL;
265 }
[email protected]db6101db2012-10-25 15:20:08266
[email protected]c90e84d2012-06-12 17:55:00267#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19268 should_initialize_gl_context = !initialized_gl_context &&
269 !dead_on_arrival;
[email protected]c90e84d2012-06-12 17:55:00270
[email protected]ca23992b02013-06-13 17:25:19271 if (!initialized_sandbox) {
272 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
273 should_initialize_gl_context);
274 }
[email protected]663c4b32013-04-18 05:52:54275#elif defined(OS_WIN)
[email protected]ca23992b02013-06-13 17:25:19276 gpu_info.sandboxed = StartSandboxWindows(parameters.sandbox_info);
[email protected]0b2cec62011-07-22 18:13:28277#endif
[email protected]ec4bda62013-06-14 15:51:03278 } else {
279 dead_on_arrival = true;
[email protected]ca23992b02013-06-13 17:25:19280 }
[email protected]0b2cec62011-07-22 18:13:28281
[email protected]ec4bda62013-06-14 15:51:03282 logging::SetLogMessageHandler(NULL);
283
[email protected]983c33d2010-11-16 22:38:44284 GpuProcess gpu_process;
[email protected]8fe0ec522011-03-03 00:31:33285
[email protected]db6101db2012-10-25 15:20:08286 GpuChildThread* child_thread = new GpuChildThread(watchdog_thread.get(),
[email protected]ec4bda62013-06-14 15:51:03287 dead_on_arrival,
288 gpu_info,
289 deferred_messages.Get());
290 while (!deferred_messages.Get().empty())
291 deferred_messages.Get().pop();
[email protected]8fe0ec522011-03-03 00:31:33292
[email protected]7a31f7c2011-03-21 23:22:04293 child_thread->Init(start_time);
[email protected]995a7f12011-02-11 23:07:17294
[email protected]7a31f7c2011-03-21 23:22:04295 gpu_process.set_main_thread(child_thread);
[email protected]983c33d2010-11-16 22:38:44296
[email protected]d13f35d2012-05-18 02:28:15297 {
298 TRACE_EVENT0("gpu", "Run Message Loop");
299 main_message_loop.Run();
300 }
[email protected]c0fc0942010-01-13 00:55:37301
[email protected]7a31f7c2011-03-21 23:22:04302 child_thread->StopWatchdog();
[email protected]e09cee42010-11-09 01:50:08303
[email protected]c0fc0942010-01-13 00:55:37304 return 0;
305}
[email protected]6ec3a572012-08-17 02:09:51306
307namespace {
308
[email protected]59a7ae4e2012-10-01 23:54:44309#if defined(OS_LINUX)
[email protected]6ec3a572012-08-17 02:09:51310void CreateDummyGlContext() {
311 scoped_refptr<gfx::GLSurface> surface(
[email protected]658f03f2013-06-17 18:28:09312 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
[email protected]fc72bb12013-06-02 21:13:46313 if (!surface.get()) {
[email protected]6ec3a572012-08-17 02:09:51314 VLOG(1) << "gfx::GLSurface::CreateOffscreenGLSurface failed";
315 return;
316 }
317
318 // On Linux, this is needed to make sure /dev/nvidiactl has
319 // been opened and its descriptor cached.
[email protected]fc72bb12013-06-02 21:13:46320 scoped_refptr<gfx::GLContext> context(gfx::GLContext::CreateGLContext(
321 NULL, surface.get(), gfx::PreferDiscreteGpu));
322 if (!context.get()) {
[email protected]6ec3a572012-08-17 02:09:51323 VLOG(1) << "gfx::GLContext::CreateGLContext failed";
324 return;
325 }
326
327 // Similarly, this is needed for /dev/nvidia0.
[email protected]fc72bb12013-06-02 21:13:46328 if (context->MakeCurrent(surface.get())) {
[email protected]6ec3a572012-08-17 02:09:51329 context->ReleaseCurrent(surface.get());
330 } else {
331 VLOG(1) << "gfx::GLContext::MakeCurrent failed";
332 }
333}
[email protected]59a7ae4e2012-10-01 23:54:44334#endif
[email protected]6ec3a572012-08-17 02:09:51335
[email protected]ca23992b02013-06-13 17:25:19336bool WarmUpSandbox(const CommandLine& command_line) {
[email protected]6ec3a572012-08-17 02:09:51337 {
338 TRACE_EVENT0("gpu", "Warm up rand");
339 // Warm up the random subsystem, which needs to be done pre-sandbox on all
340 // platforms.
341 (void) base::RandUint64();
342 }
343 {
344 TRACE_EVENT0("gpu", "Warm up HMAC");
345 // Warm up the crypto subsystem, which needs to done pre-sandbox on all
346 // platforms.
347 crypto::HMAC hmac(crypto::HMAC::SHA256);
348 unsigned char key = '\0';
[email protected]ca23992b02013-06-13 17:25:19349 if (!hmac.Init(&key, sizeof(key))) {
350 LOG(ERROR) << "WarmUpSandbox() failed with crypto::HMAC::Init()";
351 return false;
352 }
[email protected]6ec3a572012-08-17 02:09:51353 }
354
[email protected]106e38b2013-03-11 23:16:45355#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
[email protected]10f5d592013-01-16 13:21:12356 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseExynosVda))
357 ExynosVideoDecodeAccelerator::PreSandboxInitialization();
358 else
359 OmxVideoDecodeAccelerator::PreSandboxInitialization();
[email protected]106e38b2013-03-11 23:16:45360#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
[email protected]fd99f1f2013-05-31 06:52:41361 VaapiWrapper::PreSandboxInitialization();
[email protected]6ec3a572012-08-17 02:09:51362#endif
363
[email protected]5f7e4512012-10-01 20:51:37364#if defined(OS_WIN)
[email protected]2abf9122013-03-12 03:00:19365 {
[email protected]2abf9122013-03-12 03:00:19366 TRACE_EVENT0("gpu", "Preload setupapi.dll");
367 // Preload this DLL because the sandbox prevents it from loading.
[email protected]ca23992b02013-06-13 17:25:19368 if (LoadLibrary(L"setupapi.dll") == NULL) {
369 LOG(ERROR) << "WarmUpSandbox() failed with loading setupapi.dll";
370 return false;
371 }
[email protected]2abf9122013-03-12 03:00:19372 }
373
[email protected]ca23992b02013-06-13 17:25:19374 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode)) {
[email protected]2abf9122013-03-12 03:00:19375 TRACE_EVENT0("gpu", "Initialize DXVA");
376 // Initialize H/W video decoding stuff which fails in the sandbox.
377 DXVAVideoDecodeAccelerator::PreSandboxInitialization();
378 }
[email protected]6ec3a572012-08-17 02:09:51379#endif
[email protected]ca23992b02013-06-13 17:25:19380 return true;
[email protected]6ec3a572012-08-17 02:09:51381}
382
[email protected]663c4b32013-04-18 05:52:54383#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:00384void WarmUpSandboxNvidia(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54385 bool should_initialize_gl_context) {
386 // We special case Optimus since the vendor_id we see may not be Nvidia.
387 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA.
388 gpu_info.driver_vendor == "NVIDIA") ||
389 gpu_info.optimus;
390 if (uses_nvidia_driver && should_initialize_gl_context) {
391 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
392 CreateDummyGlContext();
393 }
394}
395
[email protected]d7b5cc72013-05-23 20:05:00396bool StartSandboxLinux(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54397 GpuWatchdogThread* watchdog_thread,
398 bool should_initialize_gl_context) {
399 TRACE_EVENT0("gpu", "Initialize sandbox");
400
401 bool res = false;
402
403 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context);
404
405 if (watchdog_thread)
406 watchdog_thread->Stop();
407 // LinuxSandbox::InitializeSandbox() must always be called
408 // with only one thread.
409 res = LinuxSandbox::InitializeSandbox();
410 if (watchdog_thread)
411 watchdog_thread->Start();
412
413 return res;
414}
415#endif // defined(OS_LINUX)
416
417#if defined(OS_WIN)
418bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo* sandbox_info) {
419 TRACE_EVENT0("gpu", "Lower token");
420
421 // For Windows, if the target_services interface is not zero, the process
422 // is sandboxed and we must call LowerToken() before rendering untrusted
423 // content.
424 sandbox::TargetServices* target_services = sandbox_info->target_services;
425 if (target_services) {
426 target_services->LowerToken();
427 return true;
428 }
429
430 return false;
431}
432#endif // defined(OS_WIN)
433
[email protected]6ec3a572012-08-17 02:09:51434} // namespace.
435
[email protected]eb398192012-10-22 20:16:19436} // namespace content