[email protected] | 2e3d9e4 | 2012-02-14 03:23:38 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 5 | #include <stdlib.h> |
| 6 | |
[email protected] | cafd0b6 | 2011-01-19 01:22:05 | [diff] [blame] | 7 | #if defined(OS_WIN) |
| 8 | #include <windows.h> |
| 9 | #endif |
| 10 | |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 11 | #include "base/debug/trace_event.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 12 | #include "base/message_loop.h" |
[email protected] | 2436a6b | 2012-04-13 21:08:51 | [diff] [blame] | 13 | #include "base/rand_util.h" |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 14 | #include "base/string_number_conversions.h" |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 15 | #include "base/stringprintf.h" |
[email protected] | ce072a7 | 2010-12-31 20:02:16 | [diff] [blame] | 16 | #include "base/threading/platform_thread.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 17 | #include "build/build_config.h" |
[email protected] | f24a1e2b | 2011-04-08 01:48:48 | [diff] [blame] | 18 | #include "content/common/gpu/gpu_config.h" |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 19 | #include "content/gpu/gpu_child_thread.h" |
[email protected] | f091824 | 2012-02-18 00:30:50 | [diff] [blame] | 20 | #include "content/gpu/gpu_info_collector.h" |
[email protected] | 623c0bd | 2011-03-12 01:00:41 | [diff] [blame] | 21 | #include "content/gpu/gpu_process.h" |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame^] | 22 | #include "content/gpu/gpu_watchdog_thread.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 23 | #include "content/public/common/content_client.h" |
| 24 | #include "content/public/common/content_switches.h" |
[email protected] | 1bb06b0 | 2012-09-23 19:37:24 | [diff] [blame] | 25 | #include "content/public/common/gpu_switching_option.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 26 | #include "content/public/common/main_function_params.h" |
[email protected] | 5fa097a | 2012-05-10 21:59:07 | [diff] [blame] | 27 | #include "crypto/hmac.h" |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame^] | 28 | #include "ui/gl/gl_implementation.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 29 | #include "ui/gl/gl_surface.h" |
| 30 | #include "ui/gl/gl_switches.h" |
[email protected] | 1bb06b0 | 2012-09-23 19:37:24 | [diff] [blame] | 31 | #include "ui/gl/gpu_switching_manager.h" |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 32 | |
[email protected] | d7de5787 | 2011-12-06 23:32:43 | [diff] [blame] | 33 | #if defined(OS_WIN) |
[email protected] | 5f7e451 | 2012-10-01 20:51:37 | [diff] [blame] | 34 | #include "base/win/scoped_com_initializer.h" |
[email protected] | 7ad3a435 | 2011-12-22 22:18:00 | [diff] [blame] | 35 | #include "content/common/gpu/media/dxva_video_decode_accelerator.h" |
[email protected] | 18149178 | 2012-07-18 00:59:15 | [diff] [blame] | 36 | #include "sandbox/win/src/sandbox.h" |
[email protected] | d254e7e | 2012-08-04 08:38:10 | [diff] [blame] | 37 | #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 38 | #include "content/common/gpu/media/omx_video_decode_accelerator.h" |
| 39 | #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 40 | #include "content/common/gpu/media/vaapi_video_decode_accelerator.h" |
[email protected] | 802a13a0 | 2010-12-02 01:48:37 | [diff] [blame] | 41 | #endif |
| 42 | |
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 43 | #if defined(USE_X11) |
[email protected] | 57b5d7dc | 2011-03-09 14:11:34 | [diff] [blame] | 44 | #include "ui/base/x/x11_util.h" |
[email protected] | 02ec37a | 2010-09-20 22:32:16 | [diff] [blame] | 45 | #endif |
| 46 | |
[email protected] | 2436a6b | 2012-04-13 21:08:51 | [diff] [blame] | 47 | #if defined(OS_LINUX) |
| 48 | #include "content/public/common/sandbox_init.h" |
| 49 | #endif |
| 50 | |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame^] | 51 | const int kGpuTimeout = 10000; |
| 52 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 53 | namespace content { |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 54 | namespace { |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 55 | void WarmUpSandbox(const GPUInfo&, bool); |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 58 | // Main function for starting the Gpu process. |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 59 | int GpuMain(const MainFunctionParams& parameters) { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 60 | TRACE_EVENT0("gpu", "GpuMain"); |
| 61 | |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 62 | base::Time start_time = base::Time::Now(); |
| 63 | |
[email protected] | badf5cf | 2011-10-29 03:44:44 | [diff] [blame] | 64 | const CommandLine& command_line = parameters.command_line; |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 65 | if (command_line.HasSwitch(switches::kGpuStartupDialog)) { |
[email protected] | 75fcc27 | 2011-03-08 20:50:48 | [diff] [blame] | 66 | ChildProcess::WaitForDebugger("Gpu"); |
[email protected] | 6b889fb | 2010-03-23 20:09:49 | [diff] [blame] | 67 | } |
| 68 | |
[email protected] | 23f4656 | 2011-09-07 01:42:39 | [diff] [blame] | 69 | if (!command_line.HasSwitch(switches::kSingleProcess)) { |
| 70 | #if defined(OS_WIN) |
| 71 | // Prevent Windows from displaying a modal dialog on failures like not being |
| 72 | // able to load a DLL. |
| 73 | SetErrorMode( |
| 74 | SEM_FAILCRITICALERRORS | |
| 75 | SEM_NOGPFAULTERRORBOX | |
| 76 | SEM_NOOPENFILEERRORBOX); |
| 77 | #elif defined(USE_X11) |
| 78 | ui::SetDefaultX11ErrorHandlers(); |
| 79 | #endif |
| 80 | } |
| 81 | |
[email protected] | 48fe7e4 | 2012-10-01 23:06:04 | [diff] [blame] | 82 | if (command_line.HasSwitch(switches::kSupportsDualGpus) && |
| 83 | command_line.HasSwitch(switches::kGpuSwitching)) { |
[email protected] | 1bb06b0 | 2012-09-23 19:37:24 | [diff] [blame] | 84 | std::string option = command_line.GetSwitchValueASCII( |
| 85 | switches::kGpuSwitching); |
| 86 | if (option == switches::kGpuSwitchingOptionNameForceDiscrete) |
[email protected] | a2221e8 | 2012-10-08 22:33:14 | [diff] [blame] | 87 | ui::GpuSwitchingManager::GetInstance()->ForceUseOfDiscreteGpu(); |
[email protected] | 1bb06b0 | 2012-09-23 19:37:24 | [diff] [blame] | 88 | else if (option == switches::kGpuSwitchingOptionNameForceIntegrated) |
[email protected] | a2221e8 | 2012-10-08 22:33:14 | [diff] [blame] | 89 | ui::GpuSwitchingManager::GetInstance()->ForceUseOfIntegratedGpu(); |
[email protected] | 1bb06b0 | 2012-09-23 19:37:24 | [diff] [blame] | 90 | } |
| 91 | |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 92 | // Initialization of the OpenGL bindings may fail, in which case we |
| 93 | // will need to tear down this process. However, we can not do so |
| 94 | // safely until the IPC channel is set up, because the detection of |
| 95 | // early return of a child process is implemented using an IPC |
| 96 | // channel error. If the IPC channel is not fully set up between the |
| 97 | // browser and GPU process, and the GPU process crashes or exits |
| 98 | // early, the browser process will never detect it. For this reason |
| 99 | // we defer tearing down the GPU process until receiving the |
| 100 | // GpuMsg_Initialize message from the browser. |
| 101 | bool dead_on_arrival = false; |
| 102 | |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame^] | 103 | MessageLoop::Type message_loop_type = MessageLoop::TYPE_IO; |
| 104 | #if defined(OS_WIN) |
| 105 | // Unless we're running on desktop GL, we don't need a UI message |
| 106 | // loop, so avoid its use to work around apparent problems with some |
| 107 | // third-party software. |
| 108 | if (command_line.HasSwitch(switches::kUseGL) && |
| 109 | command_line.GetSwitchValueASCII(switches::kUseGL) == |
| 110 | gfx::kGLImplementationDesktopName) { |
| 111 | message_loop_type = MessageLoop::TYPE_UI; |
| 112 | } |
| 113 | #elif defined(OS_LINUX) |
| 114 | message_loop_type = MessageLoop::TYPE_DEFAULT; |
| 115 | #endif |
| 116 | |
| 117 | MessageLoop main_message_loop(message_loop_type); |
| 118 | base::PlatformThread::SetName("CrGpuMain"); |
| 119 | |
| 120 | // In addition to disabling the watchdog if the command line switch is |
| 121 | // present, disable the watchdog on valgrind because the code is expected |
| 122 | // to run slowly in that case. |
| 123 | bool enable_watchdog = |
| 124 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 125 | switches::kDisableGpuWatchdog) && |
| 126 | !RunningOnValgrind(); |
| 127 | |
| 128 | // Disable the watchdog in debug builds because they tend to only be run by |
| 129 | // developers who will not appreciate the watchdog killing the GPU process. |
| 130 | #ifndef NDEBUG |
| 131 | enable_watchdog = false; |
| 132 | #endif |
| 133 | |
| 134 | scoped_refptr<GpuWatchdogThread> watchdog_thread; |
| 135 | |
| 136 | // Start the GPU watchdog only after anything that is expected to be time |
| 137 | // consuming has completed, otherwise the process is liable to be aborted. |
| 138 | if (enable_watchdog) { |
| 139 | watchdog_thread = new GpuWatchdogThread(kGpuTimeout); |
| 140 | watchdog_thread->Start(); |
| 141 | } |
| 142 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 143 | GPUInfo gpu_info; |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 144 | // Get vendor_id, device_id, driver_version from browser process through |
| 145 | // commandline switches. |
| 146 | DCHECK(command_line.HasSwitch(switches::kGpuVendorID) && |
| 147 | command_line.HasSwitch(switches::kGpuDeviceID) && |
| 148 | command_line.HasSwitch(switches::kGpuDriverVersion)); |
| 149 | bool success = base::HexStringToInt( |
| 150 | command_line.GetSwitchValueASCII(switches::kGpuVendorID), |
| 151 | reinterpret_cast<int*>(&(gpu_info.gpu.vendor_id))); |
| 152 | DCHECK(success); |
| 153 | success = base::HexStringToInt( |
| 154 | command_line.GetSwitchValueASCII(switches::kGpuDeviceID), |
| 155 | reinterpret_cast<int*>(&(gpu_info.gpu.device_id))); |
[email protected] | 8114edfb | 2012-06-22 01:07:21 | [diff] [blame] | 156 | DCHECK(success); |
| 157 | gpu_info.driver_vendor = |
| 158 | command_line.GetSwitchValueASCII(switches::kGpuDriverVendor); |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 159 | gpu_info.driver_version = |
| 160 | command_line.GetSwitchValueASCII(switches::kGpuDriverVersion); |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 161 | GetContentClient()->SetGpuInfo(gpu_info); |
[email protected] | f091824 | 2012-02-18 00:30:50 | [diff] [blame] | 162 | |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 163 | // We need to track that information for the WarmUpSandbox function. |
| 164 | bool initialized_gl_context = false; |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 165 | // Load and initialize the GL implementation and locate the GL entry points. |
| 166 | if (gfx::GLSurface::InitializeOneOff()) { |
[email protected] | 3a62be09 | 2012-10-09 20:58:19 | [diff] [blame] | 167 | if (!command_line.HasSwitch(switches::kSkipGpuFullInfoCollection)) { |
| 168 | if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info)) |
| 169 | VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 170 | GetContentClient()->SetGpuInfo(gpu_info); |
[email protected] | 3a62be09 | 2012-10-09 20:58:19 | [diff] [blame] | 171 | |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 172 | // We know that CollectGraphicsInfo will initialize a GLContext. |
| 173 | initialized_gl_context = true; |
[email protected] | 8114edfb | 2012-06-22 01:07:21 | [diff] [blame] | 174 | } |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 175 | |
[email protected] | 3a62be09 | 2012-10-09 20:58:19 | [diff] [blame] | 176 | #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
[email protected] | a094e2c | 2012-05-10 23:02:42 | [diff] [blame] | 177 | if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA |
[email protected] | 4b550b1a | 2012-04-16 22:01:25 | [diff] [blame] | 178 | gpu_info.driver_vendor == "NVIDIA") { |
[email protected] | 42dc3c0 | 2012-03-28 00:28:55 | [diff] [blame] | 179 | base::ThreadRestrictions::AssertIOAllowed(); |
| 180 | if (access("/dev/nvidiactl", R_OK) != 0) { |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 181 | VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied"; |
[email protected] | 42dc3c0 | 2012-03-28 00:28:55 | [diff] [blame] | 182 | gpu_info.gpu_accessible = false; |
| 183 | dead_on_arrival = true; |
| 184 | } |
| 185 | } |
[email protected] | 0204bf1 | 2012-05-25 22:31:12 | [diff] [blame] | 186 | #endif // OS_CHROMEOS |
[email protected] | f091824 | 2012-02-18 00:30:50 | [diff] [blame] | 187 | } else { |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 188 | VLOG(1) << "gfx::GLSurface::InitializeOneOff failed"; |
[email protected] | 42dc3c0 | 2012-03-28 00:28:55 | [diff] [blame] | 189 | gpu_info.gpu_accessible = false; |
[email protected] | 085170ca | 2012-05-17 20:27:28 | [diff] [blame] | 190 | gpu_info.finalized = true; |
[email protected] | 4a2a4d2 | 2011-07-25 23:20:34 | [diff] [blame] | 191 | dead_on_arrival = true; |
| 192 | } |
| 193 | |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame^] | 194 | // OSMesa is expected to run very slowly, so disable the watchdog in that |
| 195 | // case. |
| 196 | if (enable_watchdog && |
| 197 | gfx::GetGLImplementation() == gfx::kGLImplementationOSMesaGL) { |
| 198 | watchdog_thread->Stop(); |
| 199 | |
| 200 | watchdog_thread = NULL; |
| 201 | } |
| 202 | |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 203 | { |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 204 | const bool should_initialize_gl_context = !initialized_gl_context && |
| 205 | !dead_on_arrival; |
| 206 | // Warm up the current process before enabling the sandbox. |
| 207 | WarmUpSandbox(gpu_info, should_initialize_gl_context); |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 208 | } |
[email protected] | 5fa097a | 2012-05-10 21:59:07 | [diff] [blame] | 209 | |
[email protected] | c90e84d | 2012-06-12 17:55:00 | [diff] [blame] | 210 | #if defined(OS_LINUX) |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 211 | { |
| 212 | TRACE_EVENT0("gpu", "Initialize sandbox"); |
[email protected] | c90e84d | 2012-06-12 17:55:00 | [diff] [blame] | 213 | bool do_init_sandbox = true; |
| 214 | |
| 215 | #if defined(OS_CHROMEOS) && defined(NDEBUG) |
| 216 | // On Chrome OS and when not on a debug build, initialize |
| 217 | // the GPU process' sandbox only for Intel GPUs. |
| 218 | do_init_sandbox = gpu_info.gpu.vendor_id == 0x8086; // Intel GPU. |
| 219 | #endif |
| 220 | |
| 221 | if (do_init_sandbox) { |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 222 | gpu_info.sandboxed = InitializeSandbox(); |
[email protected] | c90e84d | 2012-06-12 17:55:00 | [diff] [blame] | 223 | } |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 224 | } |
[email protected] | 2436a6b | 2012-04-13 21:08:51 | [diff] [blame] | 225 | #endif |
| 226 | |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 227 | #if defined(OS_WIN) |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 228 | { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 229 | TRACE_EVENT0("gpu", "Lower token"); |
| 230 | // For windows, if the target_services interface is not zero, the process |
| 231 | // is sandboxed and we must call LowerToken() before rendering untrusted |
| 232 | // content. |
| 233 | sandbox::TargetServices* target_services = |
| 234 | parameters.sandbox_info->target_services; |
[email protected] | fad3ccf | 2012-09-11 22:36:00 | [diff] [blame] | 235 | if (target_services) { |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 236 | target_services->LowerToken(); |
[email protected] | fad3ccf | 2012-09-11 22:36:00 | [diff] [blame] | 237 | gpu_info.sandboxed = true; |
| 238 | } |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 239 | } |
[email protected] | 0b2cec6 | 2011-07-22 18:13:28 | [diff] [blame] | 240 | #endif |
| 241 | |
[email protected] | 983c33d | 2010-11-16 22:38:44 | [diff] [blame] | 242 | GpuProcess gpu_process; |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 243 | |
[email protected] | db6101db | 2012-10-25 15:20:08 | [diff] [blame^] | 244 | GpuChildThread* child_thread = new GpuChildThread(watchdog_thread.get(), |
| 245 | dead_on_arrival, gpu_info); |
[email protected] | 8fe0ec52 | 2011-03-03 00:31:33 | [diff] [blame] | 246 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 247 | child_thread->Init(start_time); |
[email protected] | 995a7f1 | 2011-02-11 23:07:17 | [diff] [blame] | 248 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 249 | gpu_process.set_main_thread(child_thread); |
[email protected] | 983c33d | 2010-11-16 22:38:44 | [diff] [blame] | 250 | |
[email protected] | d13f35d | 2012-05-18 02:28:15 | [diff] [blame] | 251 | { |
| 252 | TRACE_EVENT0("gpu", "Run Message Loop"); |
| 253 | main_message_loop.Run(); |
| 254 | } |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 255 | |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 256 | child_thread->StopWatchdog(); |
[email protected] | e09cee4 | 2010-11-09 01:50:08 | [diff] [blame] | 257 | |
[email protected] | c0fc094 | 2010-01-13 00:55:37 | [diff] [blame] | 258 | return 0; |
| 259 | } |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 260 | |
| 261 | namespace { |
| 262 | |
[email protected] | 59a7ae4e | 2012-10-01 23:54:44 | [diff] [blame] | 263 | #if defined(OS_LINUX) |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 264 | void CreateDummyGlContext() { |
| 265 | scoped_refptr<gfx::GLSurface> surface( |
| 266 | gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1))); |
| 267 | if (!surface.get()) { |
| 268 | VLOG(1) << "gfx::GLSurface::CreateOffscreenGLSurface failed"; |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | // On Linux, this is needed to make sure /dev/nvidiactl has |
| 273 | // been opened and its descriptor cached. |
| 274 | scoped_refptr<gfx::GLContext> context( |
| 275 | gfx::GLContext::CreateGLContext(NULL, |
| 276 | surface, |
| 277 | gfx::PreferDiscreteGpu)); |
| 278 | if (!context.get()) { |
| 279 | VLOG(1) << "gfx::GLContext::CreateGLContext failed"; |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | // Similarly, this is needed for /dev/nvidia0. |
| 284 | if (context->MakeCurrent(surface)) { |
| 285 | context->ReleaseCurrent(surface.get()); |
| 286 | } else { |
| 287 | VLOG(1) << "gfx::GLContext::MakeCurrent failed"; |
| 288 | } |
| 289 | } |
[email protected] | 59a7ae4e | 2012-10-01 23:54:44 | [diff] [blame] | 290 | #endif |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 291 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 292 | void WarmUpSandbox(const GPUInfo& gpu_info, |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 293 | bool should_initialize_gl_context) { |
| 294 | { |
| 295 | TRACE_EVENT0("gpu", "Warm up rand"); |
| 296 | // Warm up the random subsystem, which needs to be done pre-sandbox on all |
| 297 | // platforms. |
| 298 | (void) base::RandUint64(); |
| 299 | } |
| 300 | { |
| 301 | TRACE_EVENT0("gpu", "Warm up HMAC"); |
| 302 | // Warm up the crypto subsystem, which needs to done pre-sandbox on all |
| 303 | // platforms. |
| 304 | crypto::HMAC hmac(crypto::HMAC::SHA256); |
| 305 | unsigned char key = '\0'; |
| 306 | bool ret = hmac.Init(&key, sizeof(key)); |
| 307 | (void) ret; |
| 308 | } |
| 309 | |
| 310 | #if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) |
| 311 | OmxVideoDecodeAccelerator::PreSandboxInitialization(); |
| 312 | #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 313 | VaapiVideoDecodeAccelerator::PreSandboxInitialization(); |
| 314 | #endif |
| 315 | |
| 316 | #if defined(OS_LINUX) |
[email protected] | 9b5d2d3 | 2012-08-23 00:53:54 | [diff] [blame] | 317 | // We special case Optimus since the vendor_id we see may not be Nvidia. |
| 318 | bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA. |
| 319 | gpu_info.driver_vendor == "NVIDIA") || |
| 320 | gpu_info.optimus; |
| 321 | if (uses_nvidia_driver && should_initialize_gl_context) { |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 322 | // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0. |
| 323 | CreateDummyGlContext(); |
| 324 | } |
| 325 | #endif |
| 326 | |
[email protected] | 5f7e451 | 2012-10-01 20:51:37 | [diff] [blame] | 327 | #if defined(OS_WIN) |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 328 | { |
| 329 | TRACE_EVENT0("gpu", "Initialize COM"); |
| 330 | base::win::ScopedCOMInitializer com_initializer; |
| 331 | } |
| 332 | |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 333 | { |
| 334 | TRACE_EVENT0("gpu", "Preload setupapi.dll"); |
| 335 | // Preload this DLL because the sandbox prevents it from loading. |
| 336 | LoadLibrary(L"setupapi.dll"); |
| 337 | } |
| 338 | |
| 339 | { |
| 340 | TRACE_EVENT0("gpu", "Initialize DXVA"); |
| 341 | // Initialize H/W video decoding stuff which fails in the sandbox. |
| 342 | DXVAVideoDecodeAccelerator::PreSandboxInitialization(); |
| 343 | } |
| 344 | #endif |
| 345 | } |
| 346 | |
[email protected] | 6ec3a57 | 2012-08-17 02:09:51 | [diff] [blame] | 347 | } // namespace. |
| 348 | |
[email protected] | eb39819 | 2012-10-22 20:16:19 | [diff] [blame] | 349 | } // namespace content |