blob: 82c1bff2c432a021b4d1778c971217e86e05a47f [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)
[email protected]b5b9bfc2013-09-07 02:09:078#include <dwmapi.h>
[email protected]cafd0b62011-01-19 01:22:059#include <windows.h>
10#endif
11
[email protected]d13f35d2012-05-18 02:28:1512#include "base/debug/trace_event.h"
[email protected]ec4bda62013-06-14 15:51:0313#include "base/lazy_instance.h"
[email protected]e55f5642013-07-18 00:22:5414#include "base/message_loop/message_loop.h"
[email protected]2436a6b2012-04-13 21:08:5115#include "base/rand_util.h"
[email protected]d0ea4782013-06-11 04:58:2416#include "base/strings/string_number_conversions.h"
17#include "base/strings/stringprintf.h"
[email protected]ce072a72010-12-31 20:02:1618#include "base/threading/platform_thread.h"
[email protected]c0fc0942010-01-13 00:55:3719#include "build/build_config.h"
[email protected]10208ea2013-06-06 20:08:0320#include "content/child/child_process.h"
[email protected]91a2aea2013-07-08 23:14:3921#include "content/common/content_constants_internal.h"
[email protected]f24a1e2b2011-04-08 01:48:4822#include "content/common/gpu/gpu_config.h"
[email protected]ec4bda62013-06-14 15:51:0323#include "content/common/gpu/gpu_messages.h"
[email protected]1b73f77e2013-04-13 02:00:4724#include "content/common/sandbox_linux.h"
[email protected]7a31f7c2011-03-21 23:22:0425#include "content/gpu/gpu_child_thread.h"
[email protected]623c0bd2011-03-12 01:00:4126#include "content/gpu/gpu_process.h"
[email protected]db6101db2012-10-25 15:20:0827#include "content/gpu/gpu_watchdog_thread.h"
[email protected]c9e2cbbb2012-05-12 21:17:2728#include "content/public/common/content_client.h"
29#include "content/public/common/content_switches.h"
30#include "content/public/common/main_function_params.h"
[email protected]5fa097a2012-05-10 21:59:0731#include "crypto/hmac.h"
[email protected]40c19e722013-11-05 23:51:2432#include "gpu/command_buffer/service/gpu_switches.h"
[email protected]d7b5cc72013-05-23 20:05:0033#include "gpu/config/gpu_info_collector.h"
[email protected]40c19e722013-11-05 23:51:2434#include "gpu/config/gpu_util.h"
[email protected]db6101db2012-10-25 15:20:0835#include "ui/gl/gl_implementation.h"
[email protected]c9e2cbbb2012-05-12 21:17:2736#include "ui/gl/gl_surface.h"
37#include "ui/gl/gl_switches.h"
[email protected]1bb06b02012-09-23 19:37:2438#include "ui/gl/gpu_switching_manager.h"
[email protected]c0fc0942010-01-13 00:55:3739
[email protected]d7de57872011-12-06 23:32:4340#if defined(OS_WIN)
[email protected]b5b9bfc2013-09-07 02:09:0741#include "base/win/windows_version.h"
[email protected]5f7e4512012-10-01 20:51:3742#include "base/win/scoped_com_initializer.h"
[email protected]181491782012-07-18 00:59:1543#include "sandbox/win/src/sandbox.h"
[email protected]106e38b2013-03-11 23:16:4544#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
[email protected]10f5d592013-01-16 13:21:1245#include "content/common/gpu/media/exynos_video_decode_accelerator.h"
[email protected]106e38b2013-03-11 23:16:4546#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
[email protected]fd99f1f2013-05-31 06:52:4147#include "content/common/gpu/media/vaapi_wrapper.h"
[email protected]802a13a02010-12-02 01:48:3748#endif
49
[email protected]02ec37a2010-09-20 22:32:1650#if defined(USE_X11)
[email protected]57b5d7dc2011-03-09 14:11:3451#include "ui/base/x/x11_util.h"
[email protected]02ec37a2010-09-20 22:32:1652#endif
53
[email protected]2436a6b2012-04-13 21:08:5154#if defined(OS_LINUX)
55#include "content/public/common/sandbox_init.h"
56#endif
57
[email protected]db6101db2012-10-25 15:20:0858const int kGpuTimeout = 10000;
59
[email protected]eb398192012-10-22 20:16:1960namespace content {
[email protected]ec4bda62013-06-14 15:51:0361
[email protected]6ec3a572012-08-17 02:09:5162namespace {
[email protected]ec4bda62013-06-14 15:51:0363
[email protected]ca23992b02013-06-13 17:25:1964bool WarmUpSandbox(const CommandLine& command_line);
[email protected]663c4b32013-04-18 05:52:5465#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:0066bool StartSandboxLinux(const gpu::GPUInfo&, GpuWatchdogThread*, bool);
[email protected]663c4b32013-04-18 05:52:5467#elif defined(OS_WIN)
68bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*);
69#endif
[email protected]ec4bda62013-06-14 15:51:0370
71base::LazyInstance<GpuChildThread::DeferredMessages> deferred_messages =
72 LAZY_INSTANCE_INITIALIZER;
73
74bool GpuProcessLogMessageHandler(int severity,
75 const char* file, int line,
76 size_t message_start,
77 const std::string& str) {
78 std::string header = str.substr(0, message_start);
79 std::string message = str.substr(message_start);
80 deferred_messages.Get().push(new GpuHostMsg_OnLogMessage(
81 severity, header, message));
82 return false;
[email protected]6ec3a572012-08-17 02:09:5183}
84
[email protected]ec4bda62013-06-14 15:51:0385} // namespace anonymous
86
[email protected]c0fc0942010-01-13 00:55:3787// Main function for starting the Gpu process.
[email protected]eb398192012-10-22 20:16:1988int GpuMain(const MainFunctionParams& parameters) {
[email protected]d13f35d2012-05-18 02:28:1589 TRACE_EVENT0("gpu", "GpuMain");
[email protected]91a2aea2013-07-08 23:14:3990 base::debug::TraceLog::GetInstance()->SetProcessName("GPU Process");
91 base::debug::TraceLog::GetInstance()->SetProcessSortIndex(
92 kTraceEventGpuProcessSortIndex);
[email protected]d13f35d2012-05-18 02:28:1593
[email protected]badf5cf2011-10-29 03:44:4494 const CommandLine& command_line = parameters.command_line;
[email protected]6b889fb2010-03-23 20:09:4995 if (command_line.HasSwitch(switches::kGpuStartupDialog)) {
[email protected]75fcc272011-03-08 20:50:4896 ChildProcess::WaitForDebugger("Gpu");
[email protected]6b889fb2010-03-23 20:09:4997 }
98
[email protected]ca23992b02013-06-13 17:25:1999 base::Time start_time = base::Time::Now();
100
[email protected]ec4bda62013-06-14 15:51:03101 bool in_browser_process = command_line.HasSwitch(switches::kSingleProcess) ||
102 command_line.HasSwitch(switches::kInProcessGPU);
103
104 if (!in_browser_process) {
[email protected]23f46562011-09-07 01:42:39105#if defined(OS_WIN)
106 // Prevent Windows from displaying a modal dialog on failures like not being
107 // able to load a DLL.
108 SetErrorMode(
109 SEM_FAILCRITICALERRORS |
110 SEM_NOGPFAULTERRORBOX |
111 SEM_NOOPENFILEERRORBOX);
112#elif defined(USE_X11)
113 ui::SetDefaultX11ErrorHandlers();
114#endif
[email protected]ec4bda62013-06-14 15:51:03115
116 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
[email protected]23f46562011-09-07 01:42:39117 }
118
[email protected]40c19e722013-11-05 23:51:24119 if (command_line.HasSwitch(switches::kSupportsDualGpus)) {
120 std::string types = command_line.GetSwitchValueASCII(
121 switches::kGpuDriverBugWorkarounds);
122 std::set<int> workarounds;
123 gpu::StringToFeatureSet(types, &workarounds);
124 if (workarounds.count(gpu::FORCE_DISCRETE_GPU) == 1)
[email protected]a2221e82012-10-08 22:33:14125 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu();
[email protected]40c19e722013-11-05 23:51:24126 else if (workarounds.count(gpu::FORCE_INTEGRATED_GPU) == 1)
[email protected]a2221e82012-10-08 22:33:14127 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu();
[email protected]1bb06b02012-09-23 19:37:24128 }
129
[email protected]0b2cec62011-07-22 18:13:28130 // Initialization of the OpenGL bindings may fail, in which case we
131 // will need to tear down this process. However, we can not do so
132 // safely until the IPC channel is set up, because the detection of
133 // early return of a child process is implemented using an IPC
134 // channel error. If the IPC channel is not fully set up between the
135 // browser and GPU process, and the GPU process crashes or exits
136 // early, the browser process will never detect it. For this reason
137 // we defer tearing down the GPU process until receiving the
138 // GpuMsg_Initialize message from the browser.
139 bool dead_on_arrival = false;
140
[email protected]dd32b1272013-05-04 14:17:11141 base::MessageLoop::Type message_loop_type = base::MessageLoop::TYPE_IO;
[email protected]db6101db2012-10-25 15:20:08142#if defined(OS_WIN)
143 // Unless we're running on desktop GL, we don't need a UI message
144 // loop, so avoid its use to work around apparent problems with some
145 // third-party software.
146 if (command_line.HasSwitch(switches::kUseGL) &&
147 command_line.GetSwitchValueASCII(switches::kUseGL) ==
148 gfx::kGLImplementationDesktopName) {
[email protected]dd32b1272013-05-04 14:17:11149 message_loop_type = base::MessageLoop::TYPE_UI;
[email protected]db6101db2012-10-25 15:20:08150 }
[email protected]4fc7cc52013-09-12 22:51:10151#elif defined(TOOLKIT_GTK)
152 message_loop_type = base::MessageLoop::TYPE_GPU;
[email protected]db6101db2012-10-25 15:20:08153#elif defined(OS_LINUX)
[email protected]dd32b1272013-05-04 14:17:11154 message_loop_type = base::MessageLoop::TYPE_DEFAULT;
[email protected]db6101db2012-10-25 15:20:08155#endif
156
[email protected]dd32b1272013-05-04 14:17:11157 base::MessageLoop main_message_loop(message_loop_type);
[email protected]db6101db2012-10-25 15:20:08158 base::PlatformThread::SetName("CrGpuMain");
159
160 // In addition to disabling the watchdog if the command line switch is
161 // present, disable the watchdog on valgrind because the code is expected
162 // to run slowly in that case.
163 bool enable_watchdog =
[email protected]ca23992b02013-06-13 17:25:19164 !command_line.HasSwitch(switches::kDisableGpuWatchdog) &&
[email protected]db6101db2012-10-25 15:20:08165 !RunningOnValgrind();
166
167 // Disable the watchdog in debug builds because they tend to only be run by
168 // developers who will not appreciate the watchdog killing the GPU process.
169#ifndef NDEBUG
170 enable_watchdog = false;
171#endif
172
[email protected]42719602012-11-08 02:51:12173 bool delayed_watchdog_enable = false;
174
175#if defined(OS_CHROMEOS)
176 // Don't start watchdog immediately, to allow developers to switch to VT2 on
177 // startup.
178 delayed_watchdog_enable = true;
179#endif
180
[email protected]db6101db2012-10-25 15:20:08181 scoped_refptr<GpuWatchdogThread> watchdog_thread;
182
183 // Start the GPU watchdog only after anything that is expected to be time
184 // consuming has completed, otherwise the process is liable to be aborted.
[email protected]42719602012-11-08 02:51:12185 if (enable_watchdog && !delayed_watchdog_enable) {
[email protected]db6101db2012-10-25 15:20:08186 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
187 watchdog_thread->Start();
188 }
189
[email protected]d7b5cc72013-05-23 20:05:00190 gpu::GPUInfo gpu_info;
[email protected]085170ca2012-05-17 20:27:28191 // Get vendor_id, device_id, driver_version from browser process through
192 // commandline switches.
193 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) &&
194 command_line.HasSwitch(switches::kGpuDeviceID) &&
195 command_line.HasSwitch(switches::kGpuDriverVersion));
[email protected]3fb01692013-10-23 13:37:04196 bool success = base::HexStringToUInt(
[email protected]085170ca2012-05-17 20:27:28197 command_line.GetSwitchValueASCII(switches::kGpuVendorID),
[email protected]3fb01692013-10-23 13:37:04198 &gpu_info.gpu.vendor_id);
[email protected]085170ca2012-05-17 20:27:28199 DCHECK(success);
[email protected]3fb01692013-10-23 13:37:04200 success = base::HexStringToUInt(
[email protected]085170ca2012-05-17 20:27:28201 command_line.GetSwitchValueASCII(switches::kGpuDeviceID),
[email protected]3fb01692013-10-23 13:37:04202 &gpu_info.gpu.device_id);
[email protected]8114edfb2012-06-22 01:07:21203 DCHECK(success);
204 gpu_info.driver_vendor =
205 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor);
[email protected]085170ca2012-05-17 20:27:28206 gpu_info.driver_version =
207 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion);
[email protected]eb398192012-10-22 20:16:19208 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]f0918242012-02-18 00:30:50209
[email protected]663c4b32013-04-18 05:52:54210 // Warm up resources that don't need access to GPUInfo.
[email protected]ca23992b02013-06-13 17:25:19211 if (WarmUpSandbox(command_line)) {
[email protected]663c4b32013-04-18 05:52:54212#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19213 bool initialized_sandbox = false;
214 bool initialized_gl_context = false;
215 bool should_initialize_gl_context = false;
[email protected]663c4b32013-04-18 05:52:54216#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
[email protected]ca23992b02013-06-13 17:25:19217 // On Chrome OS ARM, GPU driver userspace creates threads when initializing
218 // a GL context, so start the sandbox early.
219 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
220 should_initialize_gl_context);
221 initialized_sandbox = true;
[email protected]663c4b32013-04-18 05:52:54222#endif
223#endif // defined(OS_LINUX)
224
[email protected]ca23992b02013-06-13 17:25:19225 // Load and initialize the GL implementation and locate the GL entry points.
226 if (gfx::GLSurface::InitializeOneOff()) {
227 // We need to collect GL strings (VENDOR, RENDERER) for blacklisting
228 // purposes. However, on Mac we don't actually use them. As documented in
229 // crbug.com/222934, due to some driver issues, glGetString could take
230 // multiple seconds to finish, which in turn cause the GPU process to
231 // crash.
232 // By skipping the following code on Mac, we don't really lose anything,
233 // because the basic GPU information is passed down from browser process
[email protected]ec4bda62013-06-14 15:51:03234 // and we already registered them through SetGpuInfo() above.
[email protected]e9931a42013-04-11 00:48:41235#if !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19236 if (!gpu::CollectContextGraphicsInfo(&gpu_info))
237 VLOG(1) << "gpu::CollectGraphicsInfo failed";
238 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]3a62be02012-10-09 20:58:19239
[email protected]663c4b32013-04-18 05:52:54240#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19241 initialized_gl_context = true;
[email protected]663c4b32013-04-18 05:52:54242#if !defined(OS_CHROMEOS)
[email protected]ca23992b02013-06-13 17:25:19243 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
244 gpu_info.driver_vendor == "NVIDIA") {
245 base::ThreadRestrictions::AssertIOAllowed();
246 if (access("/dev/nvidiactl", R_OK) != 0) {
247 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied";
[email protected]ca23992b02013-06-13 17:25:19248 dead_on_arrival = true;
249 }
[email protected]42dc3c02012-03-28 00:28:55250 }
[email protected]663c4b32013-04-18 05:52:54251#endif // !defined(OS_CHROMEOS)
252#endif // defined(OS_LINUX)
253#endif // !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19254 } else {
255 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed";
[email protected]ca23992b02013-06-13 17:25:19256 dead_on_arrival = true;
257 }
[email protected]4a2a4d22011-07-25 23:20:34258
[email protected]ca23992b02013-06-13 17:25:19259 if (enable_watchdog && delayed_watchdog_enable) {
260 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
261 watchdog_thread->Start();
262 }
[email protected]42719602012-11-08 02:51:12263
[email protected]ca23992b02013-06-13 17:25:19264 // OSMesa is expected to run very slowly, so disable the watchdog in that
265 // case.
266 if (enable_watchdog &&
267 gfx::GetGLImplementation() == gfx::kGLImplementationOSMesaGL) {
268 watchdog_thread->Stop();
269 watchdog_thread = NULL;
270 }
[email protected]db6101db2012-10-25 15:20:08271
[email protected]c90e84d2012-06-12 17:55:00272#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19273 should_initialize_gl_context = !initialized_gl_context &&
274 !dead_on_arrival;
[email protected]c90e84d2012-06-12 17:55:00275
[email protected]ca23992b02013-06-13 17:25:19276 if (!initialized_sandbox) {
277 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
278 should_initialize_gl_context);
279 }
[email protected]663c4b32013-04-18 05:52:54280#elif defined(OS_WIN)
[email protected]ca23992b02013-06-13 17:25:19281 gpu_info.sandboxed = StartSandboxWindows(parameters.sandbox_info);
[email protected]0b2cec62011-07-22 18:13:28282#endif
[email protected]ec4bda62013-06-14 15:51:03283 } else {
284 dead_on_arrival = true;
[email protected]ca23992b02013-06-13 17:25:19285 }
[email protected]0b2cec62011-07-22 18:13:28286
[email protected]ec4bda62013-06-14 15:51:03287 logging::SetLogMessageHandler(NULL);
288
[email protected]983c33d2010-11-16 22:38:44289 GpuProcess gpu_process;
[email protected]8fe0ec522011-03-03 00:31:33290
[email protected]db6101db2012-10-25 15:20:08291 GpuChildThread* child_thread = new GpuChildThread(watchdog_thread.get(),
[email protected]ec4bda62013-06-14 15:51:03292 dead_on_arrival,
293 gpu_info,
294 deferred_messages.Get());
295 while (!deferred_messages.Get().empty())
296 deferred_messages.Get().pop();
[email protected]8fe0ec522011-03-03 00:31:33297
[email protected]7a31f7c2011-03-21 23:22:04298 child_thread->Init(start_time);
[email protected]995a7f12011-02-11 23:07:17299
[email protected]7a31f7c2011-03-21 23:22:04300 gpu_process.set_main_thread(child_thread);
[email protected]983c33d2010-11-16 22:38:44301
[email protected]21e24902013-08-06 20:23:48302 if (watchdog_thread)
303 watchdog_thread->AddPowerObserver();
304
[email protected]d13f35d2012-05-18 02:28:15305 {
306 TRACE_EVENT0("gpu", "Run Message Loop");
307 main_message_loop.Run();
308 }
[email protected]c0fc0942010-01-13 00:55:37309
[email protected]7a31f7c2011-03-21 23:22:04310 child_thread->StopWatchdog();
[email protected]e09cee42010-11-09 01:50:08311
[email protected]c0fc0942010-01-13 00:55:37312 return 0;
313}
[email protected]6ec3a572012-08-17 02:09:51314
315namespace {
316
[email protected]59a7ae4e2012-10-01 23:54:44317#if defined(OS_LINUX)
[email protected]6ec3a572012-08-17 02:09:51318void CreateDummyGlContext() {
319 scoped_refptr<gfx::GLSurface> surface(
[email protected]658f03f2013-06-17 18:28:09320 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
[email protected]fc72bb12013-06-02 21:13:46321 if (!surface.get()) {
[email protected]6ec3a572012-08-17 02:09:51322 VLOG(1) << "gfx::GLSurface::CreateOffscreenGLSurface failed";
323 return;
324 }
325
326 // On Linux, this is needed to make sure /dev/nvidiactl has
327 // been opened and its descriptor cached.
[email protected]fc72bb12013-06-02 21:13:46328 scoped_refptr<gfx::GLContext> context(gfx::GLContext::CreateGLContext(
329 NULL, surface.get(), gfx::PreferDiscreteGpu));
330 if (!context.get()) {
[email protected]6ec3a572012-08-17 02:09:51331 VLOG(1) << "gfx::GLContext::CreateGLContext failed";
332 return;
333 }
334
335 // Similarly, this is needed for /dev/nvidia0.
[email protected]fc72bb12013-06-02 21:13:46336 if (context->MakeCurrent(surface.get())) {
[email protected]6ec3a572012-08-17 02:09:51337 context->ReleaseCurrent(surface.get());
338 } else {
339 VLOG(1) << "gfx::GLContext::MakeCurrent failed";
340 }
341}
[email protected]59a7ae4e2012-10-01 23:54:44342#endif
[email protected]6ec3a572012-08-17 02:09:51343
[email protected]ca23992b02013-06-13 17:25:19344bool WarmUpSandbox(const CommandLine& command_line) {
[email protected]6ec3a572012-08-17 02:09:51345 {
346 TRACE_EVENT0("gpu", "Warm up rand");
347 // Warm up the random subsystem, which needs to be done pre-sandbox on all
348 // platforms.
349 (void) base::RandUint64();
350 }
351 {
352 TRACE_EVENT0("gpu", "Warm up HMAC");
353 // Warm up the crypto subsystem, which needs to done pre-sandbox on all
354 // platforms.
355 crypto::HMAC hmac(crypto::HMAC::SHA256);
356 unsigned char key = '\0';
[email protected]ca23992b02013-06-13 17:25:19357 if (!hmac.Init(&key, sizeof(key))) {
358 LOG(ERROR) << "WarmUpSandbox() failed with crypto::HMAC::Init()";
359 return false;
360 }
[email protected]6ec3a572012-08-17 02:09:51361 }
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]b5b9bfc2013-09-07 02:09:07373 {
374 TRACE_EVENT0("gpu", "Warm up DWM");
375
376 // DWM was introduced with Windows Vista. DwmFlush seems to be sufficient
377 // to warm it up before lowering the token. DWM is required to present to
378 // a window with Vista and later and this allows us to do so with the
379 // GPU process sandbox enabled.
380 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
381 HMODULE module = LoadLibrary(L"dwmapi.dll");
382 if (module) {
383 typedef HRESULT (WINAPI *DwmFlushFunc)();
384 DwmFlushFunc dwm_flush = reinterpret_cast<DwmFlushFunc>(
385 GetProcAddress(module, "DwmFlush"));
386 if (dwm_flush)
387 dwm_flush();
388 }
389 }
390 }
[email protected]6ec3a572012-08-17 02:09:51391#endif
[email protected]ca23992b02013-06-13 17:25:19392 return true;
[email protected]6ec3a572012-08-17 02:09:51393}
394
[email protected]663c4b32013-04-18 05:52:54395#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:00396void WarmUpSandboxNvidia(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54397 bool should_initialize_gl_context) {
398 // We special case Optimus since the vendor_id we see may not be Nvidia.
399 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA.
400 gpu_info.driver_vendor == "NVIDIA") ||
401 gpu_info.optimus;
402 if (uses_nvidia_driver && should_initialize_gl_context) {
403 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
404 CreateDummyGlContext();
405 }
406}
407
[email protected]d7b5cc72013-05-23 20:05:00408bool StartSandboxLinux(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54409 GpuWatchdogThread* watchdog_thread,
410 bool should_initialize_gl_context) {
411 TRACE_EVENT0("gpu", "Initialize sandbox");
412
413 bool res = false;
414
415 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context);
416
417 if (watchdog_thread)
418 watchdog_thread->Stop();
419 // LinuxSandbox::InitializeSandbox() must always be called
420 // with only one thread.
421 res = LinuxSandbox::InitializeSandbox();
422 if (watchdog_thread)
423 watchdog_thread->Start();
424
425 return res;
426}
427#endif // defined(OS_LINUX)
428
429#if defined(OS_WIN)
430bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo* sandbox_info) {
431 TRACE_EVENT0("gpu", "Lower token");
432
433 // For Windows, if the target_services interface is not zero, the process
434 // is sandboxed and we must call LowerToken() before rendering untrusted
435 // content.
436 sandbox::TargetServices* target_services = sandbox_info->target_services;
437 if (target_services) {
438 target_services->LowerToken();
439 return true;
440 }
441
442 return false;
443}
444#endif // defined(OS_WIN)
445
[email protected]6ec3a572012-08-17 02:09:51446} // namespace.
447
[email protected]eb398192012-10-22 20:16:19448} // namespace content