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

Unified Diff: ui/gl/gl_surface.cc

Issue 135213003: Ensure GL initialization only happens once, and provide common init path (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: initgl: compile3 Created 6 years, 11 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 | « ui/gl/gl_surface.h ('k') | ui/gl/gl_surface_egl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gl/gl_surface.cc
diff --git a/ui/gl/gl_surface.cc b/ui/gl/gl_surface.cc
index a52a3f7110f3e7eea942f4597e6a38237e51556a..9531fc4f6eea2dca4b07770e86811a14d8b46635 100644
--- a/ui/gl/gl_surface.cc
+++ b/ui/gl/gl_surface.cc
@@ -14,6 +14,7 @@
#include "base/threading/thread_local.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
+#include "ui/gl/gl_switches.h"
namespace gfx {
@@ -24,9 +25,7 @@ base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky
// static
bool GLSurface::InitializeOneOff() {
- static bool initialized = false;
- if (initialized)
- return true;
+ DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
TRACE_EVENT0("gpu", "GLSurface::InitializeOneOff");
@@ -34,12 +33,14 @@ bool GLSurface::InitializeOneOff() {
GetAllowedGLImplementations(&allowed_impls);
DCHECK(!allowed_impls.empty());
+ CommandLine* cmd = CommandLine::ForCurrentProcess();
+
// The default implementation is always the first one in list.
GLImplementation impl = allowed_impls[0];
bool fallback_to_osmesa = false;
- if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
+ if (cmd->HasSwitch(switches::kUseGL)) {
std::string requested_implementation_name =
- CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
+ cmd->GetSwitchValueASCII(switches::kUseGL);
if (requested_implementation_name == "any") {
fallback_to_osmesa = true;
} else if (requested_implementation_name == "swiftshader") {
@@ -55,27 +56,99 @@ bool GLSurface::InitializeOneOff() {
}
}
- initialized = InitializeStaticGLBindings(impl) && InitializeOneOffInternal();
+ bool gpu_service_logging = cmd->HasSwitch(switches::kEnableGPUServiceLogging);
+ bool disable_gl_drawing = cmd->HasSwitch(switches::kDisableGLDrawingForTests);
+
+ return InitializeOneOffImplementation(
+ impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing);
+}
+
+// static
+bool GLSurface::InitializeOneOffImplementation(GLImplementation impl,
+ bool fallback_to_osmesa,
+ bool gpu_service_logging,
+ bool disable_gl_drawing) {
+ bool initialized =
+ InitializeStaticGLBindings(impl) && InitializeOneOffInternal();
if (!initialized && fallback_to_osmesa) {
ClearGLBindings();
initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) &&
InitializeOneOffInternal();
}
+ if (!initialized)
+ ClearGLBindings();
if (initialized) {
DVLOG(1) << "Using "
<< GetGLImplementationName(GetGLImplementation())
<< " GL implementation.";
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kEnableGPUServiceLogging))
+ if (gpu_service_logging)
InitializeDebugGLBindings();
- if (CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kDisableGLDrawingForTests))
+ if (disable_gl_drawing)
InitializeNullDrawGLBindings();
}
return initialized;
}
+// static
+void GLSurface::InitializeOneOffForTests() {
+ bool use_osmesa = true;
+
+ // We usually use OSMesa as this works on all bots. The command line can
+ // override this behaviour to use hardware GL.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGpuInTests))
+ use_osmesa = false;
+
+#if defined(OS_ANDROID)
+ // On Android we always use hardware GL.
+ use_osmesa = false;
+#endif
+
+ std::vector<GLImplementation> allowed_impls;
+ GetAllowedGLImplementations(&allowed_impls);
+ DCHECK(!allowed_impls.empty());
+
+ GLImplementation impl = allowed_impls[0];
+ if (use_osmesa)
+ impl = kGLImplementationOSMesaGL;
+
+ DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
+ << "kUseGL has not effect in tests";
+
+ bool fallback_to_osmesa = false;
+ bool gpu_service_logging = false;
+ bool disable_gl_drawing = false;
+ // TODO(danakj): Unit tests do not produce pixel output by default.
+ // bool disable_gl_drawing = true;
+
+ CHECK(InitializeOneOffImplementation(
+ impl, fallback_to_osmesa, gpu_service_logging, disable_gl_drawing));
+}
+
+// static
+void GLSurface::InitializeOneOffWithMockBindingsForTests() {
+ DCHECK(!CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL))
+ << "kUseGL has not effect in tests";
+
+ // This method may be called multiple times in the same process to set up
+ // mock bindings in different ways.
+ ClearGLBindings();
+
+ bool fallback_to_osmesa = false;
+ bool gpu_service_logging = false;
+ bool disable_gl_drawing = false;
+
+ CHECK(InitializeOneOffImplementation(kGLImplementationMockGL,
+ fallback_to_osmesa,
+ gpu_service_logging,
+ disable_gl_drawing));
+}
+
+// static
+void GLSurface::InitializeDynamicMockBindingsForTests(GLContext* context) {
+ CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context));
+}
+
GLSurface::GLSurface() {}
bool GLSurface::Initialize() {
« no previous file with comments | « ui/gl/gl_surface.h ('k') | ui/gl/gl_surface_egl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698