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

Unified Diff: content/gpu/gpu_main.cc

Issue 10831343: GPU: call CollectGraphicsinfo() for warming up the sandbox on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Create a CreateDummyGlContext function. Created 8 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/gpu/gpu_main.cc
diff --git a/content/gpu/gpu_main.cc b/content/gpu/gpu_main.cc
index be583047eba9bc3f51e3f6329094e067907564fc..be324a4d108e8d1a48d6666bc35963c758cb67a5 100644
--- a/content/gpu/gpu_main.cc
+++ b/content/gpu/gpu_main.cc
@@ -44,6 +44,11 @@
#include "content/public/common/sandbox_init.h"
#endif
+namespace {
+void WarmUpSandbox(const content::GPUInfo&, bool);
+void CollectGraphicsInfo(content::GPUInfo*);
+}
+
// Main function for starting the Gpu process.
int GpuMain(const content::MainFunctionParams& parameters) {
TRACE_EVENT0("gpu", "GpuMain");
@@ -99,6 +104,8 @@ int GpuMain(const content::MainFunctionParams& parameters) {
command_line.GetSwitchValueASCII(switches::kGpuDriverVersion);
content::GetContentClient()->SetGpuInfo(gpu_info);
+ // We need to track that information for the WarmUpSandbox function.
+ bool initialized_gl_context = false;
// Load and initialize the GL implementation and locate the GL entry points.
if (gfx::GLSurface::InitializeOneOff()) {
#if defined(OS_LINUX)
@@ -108,9 +115,9 @@ int GpuMain(const content::MainFunctionParams& parameters) {
// However, on Linux, we may not have enough info for blacklisting.
if (!gpu_info.gpu.vendor_id || !gpu_info.gpu.device_id ||
gpu_info.driver_vendor.empty() || gpu_info.driver_version.empty()) {
- if (!gpu_info_collector::CollectGraphicsInfo(&gpu_info))
- VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed";
- content::GetContentClient()->SetGpuInfo(gpu_info);
+ CollectGraphicsInfo(&gpu_info);
+ // We know that CollectGraphicsInfo will initialize a GLContext.
+ initialized_gl_context = true;
}
#if !defined(OS_CHROMEOS)
@@ -133,19 +140,10 @@ int GpuMain(const content::MainFunctionParams& parameters) {
}
{
- TRACE_EVENT0("gpu", "Warm up rand");
- // Warm up the random subsystem, which needs to be done pre-sandbox on all
- // platforms.
- (void) base::RandUint64();
- }
- {
- TRACE_EVENT0("gpu", "Warm up HMAC");
- // Warm up the crypto subsystem, which needs to done pre-sandbox on all
- // platforms.
- crypto::HMAC hmac(crypto::HMAC::SHA256);
- unsigned char key = '\0';
- bool ret = hmac.Init(&key, sizeof(key));
- (void) ret;
+ const bool should_initialize_gl_context = !initialized_gl_context &&
+ !dead_on_arrival;
+ // Warm up the current process before enabling the sandbox.
+ WarmUpSandbox(gpu_info, should_initialize_gl_context);
}
#if defined(OS_LINUX)
@@ -153,12 +151,6 @@ int GpuMain(const content::MainFunctionParams& parameters) {
TRACE_EVENT0("gpu", "Initialize sandbox");
bool do_init_sandbox = true;
-#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
- OmxVideoDecodeAccelerator::PreSandboxInitialization();
-#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
- VaapiVideoDecodeAccelerator::PreSandboxInitialization();
-#endif
-
#if defined(OS_CHROMEOS) && defined(NDEBUG)
// On Chrome OS and when not on a debug build, initialize
// the GPU process' sandbox only for Intel GPUs.
@@ -171,25 +163,8 @@ int GpuMain(const content::MainFunctionParams& parameters) {
}
#endif
- {
- TRACE_EVENT0("gpu", "Initialize COM");
- base::win::ScopedCOMInitializer com_initializer;
- }
-
#if defined(OS_WIN)
{
- TRACE_EVENT0("gpu", "Preload setupapi.dll");
- // Preload this DLL because the sandbox prevents it from loading.
- LoadLibrary(L"setupapi.dll");
- }
-
- {
- TRACE_EVENT0("gpu", "Initialize DXVA");
- // Initialize H/W video decoding stuff which fails in the sandbox.
- DXVAVideoDecodeAccelerator::PreSandboxInitialization();
- }
-
- {
TRACE_EVENT0("gpu", "Lower token");
// For windows, if the target_services interface is not zero, the process
// is sandboxed and we must call LowerToken() before rendering untrusted
@@ -235,3 +210,94 @@ int GpuMain(const content::MainFunctionParams& parameters) {
return 0;
}
+
+namespace {
+
+void CreateDummyGlContext() {
+ scoped_refptr<gfx::GLSurface> surface(
+ gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)));
+ if (!surface.get()) {
+ VLOG(1) << "gfx::GLSurface::CreateOffscreenGLSurface failed";
+ return;
+ }
+
+ // On Linux, this is needed to make sure /dev/nvidiactl has
+ // been opened and its descriptor cached.
+ scoped_refptr<gfx::GLContext> context(
+ gfx::GLContext::CreateGLContext(NULL,
+ surface,
+ gfx::PreferDiscreteGpu));
+ if (!context.get()) {
+ VLOG(1) << "gfx::GLContext::CreateGLContext failed";
+ return;
+ }
+
+ // Similarly, this is needed for /dev/nvidia0.
+ if (context->MakeCurrent(surface)) {
+ context->ReleaseCurrent(surface.get());
+ } else {
+ VLOG(1) << "gfx::GLContext::MakeCurrent failed";
+ }
+}
+
+void WarmUpSandbox(const content::GPUInfo& gpu_info,
+ bool should_initialize_gl_context) {
+ {
+ TRACE_EVENT0("gpu", "Warm up rand");
+ // Warm up the random subsystem, which needs to be done pre-sandbox on all
+ // platforms.
+ (void) base::RandUint64();
+ }
+ {
+ TRACE_EVENT0("gpu", "Warm up HMAC");
+ // Warm up the crypto subsystem, which needs to done pre-sandbox on all
+ // platforms.
+ crypto::HMAC hmac(crypto::HMAC::SHA256);
+ unsigned char key = '\0';
+ bool ret = hmac.Init(&key, sizeof(key));
+ (void) ret;
+ }
+
+#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL)
+ OmxVideoDecodeAccelerator::PreSandboxInitialization();
+#elif defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
+ VaapiVideoDecodeAccelerator::PreSandboxInitialization();
+#endif
+
+#if defined(OS_LINUX)
+ if (gpu_info.gpu.vendor_id == 0x10de && // NVIDIA
+ gpu_info.driver_vendor == "NVIDIA" &&
+ should_initialize_gl_context) {
+ // We need this on Nvidia to pre-open /dev/nvidiactl and /dev/nvidia0.
+ CreateDummyGlContext();
+ }
+#endif
+
+ {
+ TRACE_EVENT0("gpu", "Initialize COM");
+ base::win::ScopedCOMInitializer com_initializer;
+ }
+
+#if defined(OS_WIN)
+ {
+ TRACE_EVENT0("gpu", "Preload setupapi.dll");
+ // Preload this DLL because the sandbox prevents it from loading.
+ LoadLibrary(L"setupapi.dll");
+ }
+
+ {
+ TRACE_EVENT0("gpu", "Initialize DXVA");
+ // Initialize H/W video decoding stuff which fails in the sandbox.
+ DXVAVideoDecodeAccelerator::PreSandboxInitialization();
+ }
+#endif
+}
+
+void CollectGraphicsInfo(content::GPUInfo* gpu_info) {
+ if (!gpu_info_collector::CollectGraphicsInfo(gpu_info))
+ VLOG(1) << "gpu_info_collector::CollectGraphicsInfo failed";
+ content::GetContentClient()->SetGpuInfo(*gpu_info);
+}
+
+} // namespace.
+
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698