Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: content/gpu/gpu_main.cc

Issue 15745014: Move GPU device/driver info related code from content to gpu. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/gpu/gpu_info_collector_x11.cc ('k') | content/public/browser/gpu_data_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdlib.h> 5 #include <stdlib.h>
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/rand_util.h" 13 #include "base/rand_util.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/stringprintf.h" 15 #include "base/stringprintf.h"
16 #include "base/threading/platform_thread.h" 16 #include "base/threading/platform_thread.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "content/common/gpu/gpu_config.h" 18 #include "content/common/gpu/gpu_config.h"
19 #include "content/common/sandbox_linux.h" 19 #include "content/common/sandbox_linux.h"
20 #include "content/gpu/gpu_child_thread.h" 20 #include "content/gpu/gpu_child_thread.h"
21 #include "content/gpu/gpu_info_collector.h"
22 #include "content/gpu/gpu_process.h" 21 #include "content/gpu/gpu_process.h"
23 #include "content/gpu/gpu_watchdog_thread.h" 22 #include "content/gpu/gpu_watchdog_thread.h"
24 #include "content/public/common/content_client.h" 23 #include "content/public/common/content_client.h"
25 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
26 #include "content/public/common/gpu_switching_option.h"
27 #include "content/public/common/main_function_params.h" 25 #include "content/public/common/main_function_params.h"
28 #include "crypto/hmac.h" 26 #include "crypto/hmac.h"
27 #include "gpu/config/gpu_info_collector.h"
29 #include "ui/gl/gl_implementation.h" 28 #include "ui/gl/gl_implementation.h"
30 #include "ui/gl/gl_surface.h" 29 #include "ui/gl/gl_surface.h"
31 #include "ui/gl/gl_switches.h" 30 #include "ui/gl/gl_switches.h"
32 #include "ui/gl/gpu_switching_manager.h" 31 #include "ui/gl/gpu_switching_manager.h"
33 32
34 #if defined(OS_WIN) 33 #if defined(OS_WIN)
35 #include "base/win/scoped_com_initializer.h" 34 #include "base/win/scoped_com_initializer.h"
36 #include "content/common/gpu/media/dxva_video_decode_accelerator.h" 35 #include "content/common/gpu/media/dxva_video_decode_accelerator.h"
37 #include "sandbox/win/src/sandbox.h" 36 #include "sandbox/win/src/sandbox.h"
38 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11) 37 #elif defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
(...skipping 10 matching lines...) Expand all
49 #if defined(OS_LINUX) 48 #if defined(OS_LINUX)
50 #include "content/public/common/sandbox_init.h" 49 #include "content/public/common/sandbox_init.h"
51 #endif 50 #endif
52 51
53 const int kGpuTimeout = 10000; 52 const int kGpuTimeout = 10000;
54 53
55 namespace content { 54 namespace content {
56 namespace { 55 namespace {
57 void WarmUpSandbox(); 56 void WarmUpSandbox();
58 #if defined(OS_LINUX) 57 #if defined(OS_LINUX)
59 bool StartSandboxLinux(const GPUInfo&, GpuWatchdogThread*, bool); 58 bool StartSandboxLinux(const gpu::GPUInfo&, GpuWatchdogThread*, bool);
60 #elif defined(OS_WIN) 59 #elif defined(OS_WIN)
61 bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*); 60 bool StartSandboxWindows(const sandbox::SandboxInterfaceInfo*);
62 #endif 61 #endif
63 } 62 }
64 63
65 // Main function for starting the Gpu process. 64 // Main function for starting the Gpu process.
66 int GpuMain(const MainFunctionParams& parameters) { 65 int GpuMain(const MainFunctionParams& parameters) {
67 TRACE_EVENT0("gpu", "GpuMain"); 66 TRACE_EVENT0("gpu", "GpuMain");
68 67
69 base::Time start_time = base::Time::Now(); 68 base::Time start_time = base::Time::Now();
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 147
149 scoped_refptr<GpuWatchdogThread> watchdog_thread; 148 scoped_refptr<GpuWatchdogThread> watchdog_thread;
150 149
151 // Start the GPU watchdog only after anything that is expected to be time 150 // Start the GPU watchdog only after anything that is expected to be time
152 // consuming has completed, otherwise the process is liable to be aborted. 151 // consuming has completed, otherwise the process is liable to be aborted.
153 if (enable_watchdog && !delayed_watchdog_enable) { 152 if (enable_watchdog && !delayed_watchdog_enable) {
154 watchdog_thread = new GpuWatchdogThread(kGpuTimeout); 153 watchdog_thread = new GpuWatchdogThread(kGpuTimeout);
155 watchdog_thread->Start(); 154 watchdog_thread->Start();
156 } 155 }
157 156
158 GPUInfo gpu_info; 157 gpu::GPUInfo gpu_info;
159 // Get vendor_id, device_id, driver_version from browser process through 158 // Get vendor_id, device_id, driver_version from browser process through
160 // commandline switches. 159 // commandline switches.
161 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) && 160 DCHECK(command_line.HasSwitch(switches::kGpuVendorID) &&
162 command_line.HasSwitch(switches::kGpuDeviceID) && 161 command_line.HasSwitch(switches::kGpuDeviceID) &&
163 command_line.HasSwitch(switches::kGpuDriverVersion)); 162 command_line.HasSwitch(switches::kGpuDriverVersion));
164 bool success = base::HexStringToInt( 163 bool success = base::HexStringToInt(
165 command_line.GetSwitchValueASCII(switches::kGpuVendorID), 164 command_line.GetSwitchValueASCII(switches::kGpuVendorID),
166 reinterpret_cast<int*>(&(gpu_info.gpu.vendor_id))); 165 reinterpret_cast<int*>(&(gpu_info.gpu.vendor_id)));
167 DCHECK(success); 166 DCHECK(success);
168 success = base::HexStringToInt( 167 success = base::HexStringToInt(
(...skipping 25 matching lines...) Expand all
194 // Load and initialize the GL implementation and locate the GL entry points. 193 // Load and initialize the GL implementation and locate the GL entry points.
195 if (gfx::GLSurface::InitializeOneOff()) { 194 if (gfx::GLSurface::InitializeOneOff()) {
196 // We need to collect GL strings (VENDOR, RENDERER) for blacklisting 195 // We need to collect GL strings (VENDOR, RENDERER) for blacklisting
197 // purposes. However, on Mac we don't actually use them. As documented in 196 // purposes. However, on Mac we don't actually use them. As documented in
198 // crbug.com/222934, due to some driver issues, glGetString could take 197 // crbug.com/222934, due to some driver issues, glGetString could take
199 // multiple seconds to finish, which in turn cause the GPU process to crash. 198 // multiple seconds to finish, which in turn cause the GPU process to crash.
200 // By skipping the following code on Mac, we don't really lose anything, 199 // By skipping the following code on Mac, we don't really lose anything,
201 // because the basic GPU information is passed down from browser process 200 // because the basic GPU information is passed down from browser process
202 // and we already registered them through SetGpuInfo() above. 201 // and we already registered them through SetGpuInfo() above.
203 #if !defined(OS_MACOSX) 202 #if !defined(OS_MACOSX)
204 if (!gpu_info_collector::CollectContextGraphicsInfo(&gpu_info)) 203 if (!gpu::CollectContextGraphicsInfo(&gpu_info))
205 VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed"; 204 VLOG(1) << "gpu::CollectGraphicsInfo failed";
206 GetContentClient()->SetGpuInfo(gpu_info); 205 GetContentClient()->SetGpuInfo(gpu_info);
207 206
208 #if defined(OS_LINUX) 207 #if defined(OS_LINUX)
209 initialized_gl_context = true; 208 initialized_gl_context = true;
210 #if !defined(OS_CHROMEOS) 209 #if !defined(OS_CHROMEOS)
211 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA 210 if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
212 gpu_info.driver_vendor == "NVIDIA") { 211 gpu_info.driver_vendor == "NVIDIA") {
213 base::ThreadRestrictions::AssertIOAllowed(); 212 base::ThreadRestrictions::AssertIOAllowed();
214 if (access("/dev/nvidiactl", R_OK) != 0) { 213 if (access("/dev/nvidiactl", R_OK) != 0) {
215 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied"; 214 VLOG(1) << "NVIDIA device file /dev/nvidiactl access denied";
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 336
338 { 337 {
339 TRACE_EVENT0("gpu", "Initialize DXVA"); 338 TRACE_EVENT0("gpu", "Initialize DXVA");
340 // Initialize H/W video decoding stuff which fails in the sandbox. 339 // Initialize H/W video decoding stuff which fails in the sandbox.
341 DXVAVideoDecodeAccelerator::PreSandboxInitialization(); 340 DXVAVideoDecodeAccelerator::PreSandboxInitialization();
342 } 341 }
343 #endif 342 #endif
344 } 343 }
345 344
346 #if defined(OS_LINUX) 345 #if defined(OS_LINUX)
347 void WarmUpSandboxNvidia(const GPUInfo& gpu_info, 346 void WarmUpSandboxNvidia(const gpu::GPUInfo& gpu_info,
348 bool should_initialize_gl_context) { 347 bool should_initialize_gl_context) {
349 // We special case Optimus since the vendor_id we see may not be Nvidia. 348 // We special case Optimus since the vendor_id we see may not be Nvidia.
350 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA. 349 bool uses_nvidia_driver = (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA.
351 gpu_info.driver_vendor == "NVIDIA") || 350 gpu_info.driver_vendor == "NVIDIA") ||
352 gpu_info.optimus; 351 gpu_info.optimus;
353 if (uses_nvidia_driver && should_initialize_gl_context) { 352 if (uses_nvidia_driver && should_initialize_gl_context) {
354 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0. 353 // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
355 CreateDummyGlContext(); 354 CreateDummyGlContext();
356 } 355 }
357 } 356 }
358 357
359 bool StartSandboxLinux(const GPUInfo& gpu_info, 358 bool StartSandboxLinux(const gpu::GPUInfo& gpu_info,
360 GpuWatchdogThread* watchdog_thread, 359 GpuWatchdogThread* watchdog_thread,
361 bool should_initialize_gl_context) { 360 bool should_initialize_gl_context) {
362 TRACE_EVENT0("gpu", "Initialize sandbox"); 361 TRACE_EVENT0("gpu", "Initialize sandbox");
363 362
364 bool res = false; 363 bool res = false;
365 364
366 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context); 365 WarmUpSandboxNvidia(gpu_info, should_initialize_gl_context);
367 366
368 if (watchdog_thread) 367 if (watchdog_thread)
369 watchdog_thread->Stop(); 368 watchdog_thread->Stop();
(...skipping 20 matching lines...) Expand all
390 return true; 389 return true;
391 } 390 }
392 391
393 return false; 392 return false;
394 } 393 }
395 #endif // defined(OS_WIN) 394 #endif // defined(OS_WIN)
396 395
397 } // namespace. 396 } // namespace.
398 397
399 } // namespace content 398 } // namespace content
OLDNEW
« no previous file with comments | « content/gpu/gpu_info_collector_x11.cc ('k') | content/public/browser/gpu_data_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698