blob: 0bed8c28a8a942252c2343c88fd65fc795eecb60 [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]7ad3a4352011-12-22 22:18:0043#include "content/common/gpu/media/dxva_video_decode_accelerator.h"
[email protected]181491782012-07-18 00:59:1544#include "sandbox/win/src/sandbox.h"
[email protected]106e38b2013-03-11 23:16:4545#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
[email protected]10f5d592013-01-16 13:21:1246#include "content/common/gpu/media/exynos_video_decode_accelerator.h"
[email protected]106e38b2013-03-11 23:16:4547#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
[email protected]fd99f1f2013-05-31 06:52:4148#include "content/common/gpu/media/vaapi_wrapper.h"
[email protected]802a13a02010-12-02 01:48:3749#endif
50
[email protected]02ec37a2010-09-20 22:32:1651#if defined(USE_X11)
[email protected]57b5d7dc2011-03-09 14:11:3452#include "ui/base/x/x11_util.h"
[email protected]02ec37a2010-09-20 22:32:1653#endif
54
[email protected]2436a6b2012-04-13 21:08:5155#if defined(OS_LINUX)
56#include "content/public/common/sandbox_init.h"
57#endif
58
[email protected]db6101db2012-10-25 15:20:0859const int kGpuTimeout = 10000;
60
[email protected]eb398192012-10-22 20:16:1961namespace content {
[email protected]ec4bda62013-06-14 15:51:0362
[email protected]6ec3a572012-08-17 02:09:5163namespace {
[email protected]ec4bda62013-06-14 15:51:0364
[email protected]ca23992b02013-06-13 17:25:1965bool WarmUpSandbox(const CommandLine& command_line);
[email protected]663c4b32013-04-18 05:52:5466#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:0067bool StartSandboxLinux(const gpu::GPUInfo&, GpuWatchdogThread*, bool);
[email protected]663c4b32013-04-18 05:52:5468#elif defined(OS_WIN)
69bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*);
70#endif
[email protected]ec4bda62013-06-14 15:51:0371
72base::LazyInstance<GpuChildThread::DeferredMessages> deferred_messages =
73 LAZY_INSTANCE_INITIALIZER;
74
75bool GpuProcessLogMessageHandler(int severity,
76 const char* file, int line,
77 size_t message_start,
78 const std::string& str) {
79 std::string header = str.substr(0, message_start);
80 std::string message = str.substr(message_start);
81 deferred_messages.Get().push(new GpuHostMsg_OnLogMessage(
82 severity, header, message));
83 return false;
[email protected]6ec3a572012-08-17 02:09:5184}
85
[email protected]ec4bda62013-06-14 15:51:0386} // namespace anonymous
87
[email protected]c0fc0942010-01-13 00:55:3788// Main function for starting the Gpu process.
[email protected]eb398192012-10-22 20:16:1989int GpuMain(const MainFunctionParams& parameters) {
[email protected]d13f35d2012-05-18 02:28:1590 TRACE_EVENT0("gpu", "GpuMain");
[email protected]91a2aea2013-07-08 23:14:3991 base::debug::TraceLog::GetInstance()->SetProcessName("GPU Process");
92 base::debug::TraceLog::GetInstance()->SetProcessSortIndex(
93 kTraceEventGpuProcessSortIndex);
[email protected]d13f35d2012-05-18 02:28:1594
[email protected]badf5cf2011-10-29 03:44:4495 const CommandLine& command_line = parameters.command_line;
[email protected]6b889fb2010-03-23 20:09:4996 if (command_line.HasSwitch(switches::kGpuStartupDialog)) {
[email protected]75fcc272011-03-08 20:50:4897 ChildProcess::WaitForDebugger("Gpu");
[email protected]6b889fb2010-03-23 20:09:4998 }
99
[email protected]ca23992b02013-06-13 17:25:19100 base::Time start_time = base::Time::Now();
101
[email protected]ec4bda62013-06-14 15:51:03102 bool in_browser_process = command_line.HasSwitch(switches::kSingleProcess) ||
103 command_line.HasSwitch(switches::kInProcessGPU);
104
105 if (!in_browser_process) {
[email protected]23f46562011-09-07 01:42:39106#if defined(OS_WIN)
107 // Prevent Windows from displaying a modal dialog on failures like not being
108 // able to load a DLL.
109 SetErrorMode(
110 SEM_FAILCRITICALERRORS |
111 SEM_NOGPFAULTERRORBOX |
112 SEM_NOOPENFILEERRORBOX);
113#elif defined(USE_X11)
114 ui::SetDefaultX11ErrorHandlers();
115#endif
[email protected]ec4bda62013-06-14 15:51:03116
117 logging::SetLogMessageHandler(GpuProcessLogMessageHandler);
[email protected]23f46562011-09-07 01:42:39118 }
119
[email protected]40c19e722013-11-05 23:51:24120 if (command_line.HasSwitch(switches::kSupportsDualGpus)) {
121 std::string types = command_line.GetSwitchValueASCII(
122 switches::kGpuDriverBugWorkarounds);
123 std::set<int> workarounds;
124 gpu::StringToFeatureSet(types, &workarounds);
125 if (workarounds.count(gpu::FORCE_DISCRETE_GPU) == 1)
[email protected]a2221e82012-10-08 22:33:14126 ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu();
[email protected]40c19e722013-11-05 23:51:24127 else if (workarounds.count(gpu::FORCE_INTEGRATED_GPU) == 1)
[email protected]a2221e82012-10-08 22:33:14128 ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu();
[email protected]1bb06b02012-09-23 19:37:24129 }
130
[email protected]0b2cec62011-07-22 18:13:28131 // Initialization of the OpenGL bindings may fail, in which case we
132 // will need to tear down this process. However, we can not do so
133 // safely until the IPC channel is set up, because the detection of
134 // early return of a child process is implemented using an IPC
135 // channel error. If the IPC channel is not fully set up between the
136 // browser and GPU process, and the GPU process crashes or exits
137 // early, the browser process will never detect it. For this reason
138 // we defer tearing down the GPU process until receiving the
139 // GpuMsg_Initialize message from the browser.
140 bool dead_on_arrival = false;
141
[email protected]dd32b1272013-05-04 14:17:11142 base::MessageLoop::Type message_loop_type = base::MessageLoop::TYPE_IO;
[email protected]db6101db2012-10-25 15:20:08143#if defined(OS_WIN)
144 // Unless we're running on desktop GL, we don't need a UI message
145 // loop, so avoid its use to work around apparent problems with some
146 // third-party software.
147 if (command_line.HasSwitch(switches::kUseGL) &&
148 command_line.GetSwitchValueASCII(switches::kUseGL) ==
149 gfx::kGLImplementationDesktopName) {
[email protected]dd32b1272013-05-04 14:17:11150 message_loop_type = base::MessageLoop::TYPE_UI;
[email protected]db6101db2012-10-25 15:20:08151 }
[email protected]4fc7cc52013-09-12 22:51:10152#elif defined(TOOLKIT_GTK)
153 message_loop_type = base::MessageLoop::TYPE_GPU;
[email protected]db6101db2012-10-25 15:20:08154#elif defined(OS_LINUX)
[email protected]dd32b1272013-05-04 14:17:11155 message_loop_type = base::MessageLoop::TYPE_DEFAULT;
[email protected]db6101db2012-10-25 15:20:08156#endif
157
[email protected]dd32b1272013-05-04 14:17:11158 base::MessageLoop main_message_loop(message_loop_type);
[email protected]db6101db2012-10-25 15:20:08159 base::PlatformThread::SetName("CrGpuMain");
160
161 // In addition to disabling the watchdog if the command line switch is
162 // present, disable the watchdog on valgrind because the code is expected
163 // to run slowly in that case.
164 bool enable_watchdog =
[email protected]ca23992b02013-06-13 17:25:19165 !command_line.HasSwitch(switches::kDisableGpuWatchdog) &&
[email protected]db6101db2012-10-25 15:20:08166 !RunningOnValgrind();
167
168 // Disable the watchdog in debug builds because they tend to only be run by
169 // developers who will not appreciate the watchdog killing the GPU process.
170#ifndef NDEBUG
171 enable_watchdog = false;
172#endif
173
[email protected]42719602012-11-08 02:51:12174 bool delayed_watchdog_enable = false;
175
176#if defined(OS_CHROMEOS)
177 // Don't start watchdog immediately, to allow developers to switch to VT2 on
178 // startup.
179 delayed_watchdog_enable = true;
180#endif
181
[email protected]db6101db2012-10-25 15:20:08182 scoped_refptr<GpuWatchdogThread> watchdog_thread;
183
184 // Start the GPU watchdog only after anything that is expected to be time
185 // consuming has completed, otherwise the process is liable to be aborted.
[email protected]42719602012-11-08 02:51:12186 if (enable_watchdog && !delayed_watchdog_enable) {
[email protected]db6101db2012-10-25 15:20:08187 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
188 watchdog_thread->Start();
189 }
190
[email protected]d7b5cc72013-05-23 20:05:00191 gpu::GPUInfo gpu_info;
[email protected]085170ca2012-05-17 20:27:28192 // Get vendor_id, device_id, driver_version from browser process through
193 // commandline switches.
194 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) &&
195 command_line.HasSwitch(switches::kGpuDeviceID) &&
196 command_line.HasSwitch(switches::kGpuDriverVersion));
[email protected]3fb01692013-10-23 13:37:04197 bool success = base::HexStringToUInt(
[email protected]085170ca2012-05-17 20:27:28198 command_line.GetSwitchValueASCII(switches::kGpuVendorID),
[email protected]3fb01692013-10-23 13:37:04199 &gpu_info.gpu.vendor_id);
[email protected]085170ca2012-05-17 20:27:28200 DCHECK(success);
[email protected]3fb01692013-10-23 13:37:04201 success = base::HexStringToUInt(
[email protected]085170ca2012-05-17 20:27:28202 command_line.GetSwitchValueASCII(switches::kGpuDeviceID),
[email protected]3fb01692013-10-23 13:37:04203 &gpu_info.gpu.device_id);
[email protected]8114edfb2012-06-22 01:07:21204 DCHECK(success);
205 gpu_info.driver_vendor =
206 command_line.GetSwitchValueASCII(switches::kGpuDriverVendor);
[email protected]085170ca2012-05-17 20:27:28207 gpu_info.driver_version =
208 command_line.GetSwitchValueASCII(switches::kGpuDriverVersion);
[email protected]eb398192012-10-22 20:16:19209 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]f0918242012-02-18 00:30:50210
[email protected]663c4b32013-04-18 05:52:54211 // Warm up resources that don't need access to GPUInfo.
[email protected]ca23992b02013-06-13 17:25:19212 if (WarmUpSandbox(command_line)) {
[email protected]663c4b32013-04-18 05:52:54213#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19214 bool initialized_sandbox = false;
215 bool initialized_gl_context = false;
216 bool should_initialize_gl_context = false;
[email protected]663c4b32013-04-18 05:52:54217#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
[email protected]ca23992b02013-06-13 17:25:19218 // On Chrome OS ARM, GPU driver userspace creates threads when initializing
219 // a GL context, so start the sandbox early.
220 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
221 should_initialize_gl_context);
222 initialized_sandbox = true;
[email protected]663c4b32013-04-18 05:52:54223#endif
224#endif // defined(OS_LINUX)
225
[email protected]ca23992b02013-06-13 17:25:19226 // Load and initialize the GL implementation and locate the GL entry points.
227 if (gfx::GLSurface::InitializeOneOff()) {
228 // We need to collect GL strings (VENDOR, RENDERER) for blacklisting
229 // purposes. However, on Mac we don't actually use them. As documented in
230 // crbug.com/222934, due to some driver issues, glGetString could take
231 // multiple seconds to finish, which in turn cause the GPU process to
232 // crash.
233 // By skipping the following code on Mac, we don't really lose anything,
234 // because the basic GPU information is passed down from browser process
[email protected]ec4bda62013-06-14 15:51:03235 // and we already registered them through SetGpuInfo() above.
[email protected]e9931a42013-04-11 00:48:41236#if !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19237 if (!gpu::CollectContextGraphicsInfo(&gpu_info))
238 VLOG(1) << "gpu::CollectGraphicsInfo failed";
239 GetContentClient()->SetGpuInfo(gpu_info);
[email protected]3a62be092012-10-09 20:58:19240
[email protected]663c4b32013-04-18 05:52:54241#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19242 initialized_gl_context = true;
[email protected]663c4b32013-04-18 05:52:54243#if !defined(OS_CHROMEOS)
[email protected]ca23992b02013-06-13 17:25:19244 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
245 gpu_info.driver_vendor == "NVIDIA") {
246 base::ThreadRestrictions::AssertIOAllowed();
247 if (access("/dev/nvidiactl", R_OK) != 0) {
248 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied";
[email protected]ca23992b02013-06-13 17:25:19249 dead_on_arrival = true;
250 }
[email protected]42dc3c02012-03-28 00:28:55251 }
[email protected]663c4b32013-04-18 05:52:54252#endif // !defined(OS_CHROMEOS)
253#endif // defined(OS_LINUX)
254#endif // !defined(OS_MACOSX)
[email protected]ca23992b02013-06-13 17:25:19255 } else {
256 VLOG(1) << "gfx::GLSurface::InitializeOneOff failed";
[email protected]ca23992b02013-06-13 17:25:19257 dead_on_arrival = true;
258 }
[email protected]4a2a4d22011-07-25 23:20:34259
[email protected]ca23992b02013-06-13 17:25:19260 if (enable_watchdog && delayed_watchdog_enable) {
261 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
262 watchdog_thread->Start();
263 }
[email protected]42719602012-11-08 02:51:12264
[email protected]ca23992b02013-06-13 17:25:19265 // OSMesa is expected to run very slowly, so disable the watchdog in that
266 // case.
267 if (enable_watchdog &&
268 gfx::GetGLImplementation() == gfx::kGLImplementationOSMesaGL) {
269 watchdog_thread->Stop();
270 watchdog_thread = NULL;
271 }
[email protected]db6101db2012-10-25 15:20:08272
[email protected]c90e84d2012-06-12 17:55:00273#if defined(OS_LINUX)
[email protected]ca23992b02013-06-13 17:25:19274 should_initialize_gl_context = !initialized_gl_context &&
275 !dead_on_arrival;
[email protected]c90e84d2012-06-12 17:55:00276
[email protected]ca23992b02013-06-13 17:25:19277 if (!initialized_sandbox) {
278 gpu_info.sandboxed = StartSandboxLinux(gpu_info, watchdog_thread.get(),
279 should_initialize_gl_context);
280 }
[email protected]663c4b32013-04-18 05:52:54281#elif defined(OS_WIN)
[email protected]ca23992b02013-06-13 17:25:19282 gpu_info.sandboxed = StartSandboxWindows(parameters.sandbox_info);
[email protected]0b2cec62011-07-22 18:13:28283#endif
[email protected]ec4bda62013-06-14 15:51:03284 } else {
285 dead_on_arrival = true;
[email protected]ca23992b02013-06-13 17:25:19286 }
[email protected]0b2cec62011-07-22 18:13:28287
[email protected]ec4bda62013-06-14 15:51:03288 logging::SetLogMessageHandler(NULL);
289
[email protected]983c33d2010-11-16 22:38:44290 GpuProcess gpu_process;
[email protected]8fe0ec522011-03-03 00:31:33291
[email protected]db6101db2012-10-25 15:20:08292 GpuChildThread* child_thread = new GpuChildThread(watchdog_thread.get(),
[email protected]ec4bda62013-06-14 15:51:03293 dead_on_arrival,
294 gpu_info,
295 deferred_messages.Get());
296 while (!deferred_messages.Get().empty())
297 deferred_messages.Get().pop();
[email protected]8fe0ec522011-03-03 00:31:33298
[email protected]7a31f7c2011-03-21 23:22:04299 child_thread->Init(start_time);
[email protected]995a7f12011-02-11 23:07:17300
[email protected]7a31f7c2011-03-21 23:22:04301 gpu_process.set_main_thread(child_thread);
[email protected]983c33d2010-11-16 22:38:44302
[email protected]21e24902013-08-06 20:23:48303 if (watchdog_thread)
304 watchdog_thread->AddPowerObserver();
305
[email protected]d13f35d2012-05-18 02:28:15306 {
307 TRACE_EVENT0("gpu", "Run Message Loop");
308 main_message_loop.Run();
309 }
[email protected]c0fc0942010-01-13 00:55:37310
[email protected]7a31f7c2011-03-21 23:22:04311 child_thread->StopWatchdog();
[email protected]e09cee42010-11-09 01:50:08312
[email protected]c0fc0942010-01-13 00:55:37313 return 0;
314}
[email protected]6ec3a572012-08-17 02:09:51315
316namespace {
317
[email protected]59a7ae4e2012-10-01 23:54:44318#if defined(OS_LINUX)
[email protected]6ec3a572012-08-17 02:09:51319void CreateDummyGlContext() {
320 scoped_refptr<gfx::GLSurface> surface(
[email protected]658f03f2013-06-17 18:28:09321 gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1)));
[email protected]fc72bb12013-06-02 21:13:46322 if (!surface.get()) {
[email protected]6ec3a572012-08-17 02:09:51323 VLOG(1) << "gfx::GLSurface::CreateOffscreenGLSurface failed";
324 return;
325 }
326
327 // On Linux, this is needed to make sure /dev/nvidiactl has
328 // been opened and its descriptor cached.
[email protected]fc72bb12013-06-02 21:13:46329 scoped_refptr<gfx::GLContext> context(gfx::GLContext::CreateGLContext(
330 NULL, surface.get(), gfx::PreferDiscreteGpu));
331 if (!context.get()) {
[email protected]6ec3a572012-08-17 02:09:51332 VLOG(1) << "gfx::GLContext::CreateGLContext failed";
333 return;
334 }
335
336 // Similarly, this is needed for /dev/nvidia0.
[email protected]fc72bb12013-06-02 21:13:46337 if (context->MakeCurrent(surface.get())) {
[email protected]6ec3a572012-08-17 02:09:51338 context->ReleaseCurrent(surface.get());
339 } else {
340 VLOG(1) << "gfx::GLContext::MakeCurrent failed";
341 }
342}
[email protected]59a7ae4e2012-10-01 23:54:44343#endif
[email protected]6ec3a572012-08-17 02:09:51344
[email protected]ca23992b02013-06-13 17:25:19345bool WarmUpSandbox(const CommandLine& command_line) {
[email protected]6ec3a572012-08-17 02:09:51346 {
347 TRACE_EVENT0("gpu", "Warm up rand");
348 // Warm up the random subsystem, which needs to be done pre-sandbox on all
349 // platforms.
350 (void) base::RandUint64();
351 }
352 {
353 TRACE_EVENT0("gpu", "Warm up HMAC");
354 // Warm up the crypto subsystem, which needs to done pre-sandbox on all
355 // platforms.
356 crypto::HMAC hmac(crypto::HMAC::SHA256);
357 unsigned char key = '\0';
[email protected]ca23992b02013-06-13 17:25:19358 if (!hmac.Init(&key, sizeof(key))) {
359 LOG(ERROR) << "WarmUpSandbox() failed with crypto::HMAC::Init()";
360 return false;
361 }
[email protected]6ec3a572012-08-17 02:09:51362 }
363
[email protected]106e38b2013-03-11 23:16:45364#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
[email protected]3943be22013-08-06 18:11:42365 ExynosVideoDecodeAccelerator::PreSandboxInitialization();
[email protected]106e38b2013-03-11 23:16:45366#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) && defined(USE_X11)
[email protected]fd99f1f2013-05-31 06:52:41367 VaapiWrapper::PreSandboxInitialization();
[email protected]6ec3a572012-08-17 02:09:51368#endif
369
[email protected]5f7e4512012-10-01 20:51:37370#if defined(OS_WIN)
[email protected]2abf9122013-03-12 03:00:19371 {
[email protected]2abf9122013-03-12 03:00:19372 TRACE_EVENT0("gpu", "Preload setupapi.dll");
373 // Preload this DLL because the sandbox prevents it from loading.
[email protected]ca23992b02013-06-13 17:25:19374 if (LoadLibrary(L"setupapi.dll") == NULL) {
375 LOG(ERROR) << "WarmUpSandbox() failed with loading setupapi.dll";
376 return false;
377 }
[email protected]2abf9122013-03-12 03:00:19378 }
379
[email protected]ca23992b02013-06-13 17:25:19380 if (!command_line.HasSwitch(switches::kDisableAcceleratedVideoDecode)) {
[email protected]2abf9122013-03-12 03:00:19381 TRACE_EVENT0("gpu", "Initialize DXVA");
382 // Initialize H/W video decoding stuff which fails in the sandbox.
383 DXVAVideoDecodeAccelerator::PreSandboxInitialization();
384 }
[email protected]b5b9bfc2013-09-07 02:09:07385
386 {
387 TRACE_EVENT0("gpu", "Warm up DWM");
388
389 // DWM was introduced with Windows Vista. DwmFlush seems to be sufficient
390 // to warm it up before lowering the token. DWM is required to present to
391 // a window with Vista and later and this allows us to do so with the
392 // GPU process sandbox enabled.
393 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
394 HMODULE module = LoadLibrary(L"dwmapi.dll");
395 if (module) {
396 typedef HRESULT (WINAPI *DwmFlushFunc)();
397 DwmFlushFunc dwm_flush = reinterpret_cast<DwmFlushFunc>(
398 GetProcAddress(module, "DwmFlush"));
399 if (dwm_flush)
400 dwm_flush();
401 }
402 }
403 }
[email protected]6ec3a572012-08-17 02:09:51404#endif
[email protected]ca23992b02013-06-13 17:25:19405 return true;
[email protected]6ec3a572012-08-17 02:09:51406}
407
[email protected]663c4b32013-04-18 05:52:54408#if defined(OS_LINUX)
[email protected]d7b5cc72013-05-23 20:05:00409void WarmUpSandboxNvidia(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54410 bool should_initialize_gl_context) {
411 // We special case Optimus since the vendor_id we see may not be Nvidia.
412 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA.
413 gpu_info.driver_vendor == "NVIDIA") ||
414 gpu_info.optimus;
415 if (uses_nvidia_driver && should_initialize_gl_context) {
416 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
417 CreateDummyGlContext();
418 }
419}
420
[email protected]d7b5cc72013-05-23 20:05:00421bool StartSandboxLinux(const gpu::GPUInfo& gpu_info,
[email protected]663c4b32013-04-18 05:52:54422 GpuWatchdogThread* watchdog_thread,
423 bool should_initialize_gl_context) {
424 TRACE_EVENT0("gpu", "Initialize sandbox");
425
426 bool res = false;
427
428 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context);
429
430 if (watchdog_thread)
431 watchdog_thread->Stop();
432 // LinuxSandbox::InitializeSandbox() must always be called
433 // with only one thread.
434 res = LinuxSandbox::InitializeSandbox();
435 if (watchdog_thread)
436 watchdog_thread->Start();
437
438 return res;
439}
440#endif // defined(OS_LINUX)
441
442#if defined(OS_WIN)
443bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo* sandbox_info) {
444 TRACE_EVENT0("gpu", "Lower token");
445
446 // For Windows, if the target_services interface is not zero, the process
447 // is sandboxed and we must call LowerToken() before rendering untrusted
448 // content.
449 sandbox::TargetServices* target_services = sandbox_info->target_services;
450 if (target_services) {
451 target_services->LowerToken();
452 return true;
453 }
454
455 return false;
456}
457#endif // defined(OS_WIN)
458
[email protected]6ec3a572012-08-17 02:09:51459} // namespace.
460
[email protected]eb398192012-10-22 20:16:19461} // namespace content