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

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: 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
Index: ui/gl/gl_surface.cc
diff --git a/ui/gl/gl_surface.cc b/ui/gl/gl_surface.cc
index a52a3f7110f3e7eea942f4597e6a38237e51556a..5179811bfaf470cd218042751aace9597b71fa94 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");
@@ -44,6 +43,8 @@ bool GLSurface::InitializeOneOff() {
fallback_to_osmesa = true;
} else if (requested_implementation_name == "swiftshader") {
impl = kGLImplementationEGLGLES2;
+ } else if (requested_implementation_name == kGLImplementationMockName) {
+ impl = kGLImplementationMockGL;
} else {
impl = GetNamedGLImplementation(requested_implementation_name);
if (std::find(allowed_impls.begin(),
@@ -55,12 +56,15 @@ bool GLSurface::InitializeOneOff() {
}
}
- initialized = InitializeStaticGLBindings(impl) && InitializeOneOffInternal();
+ bool initialized =
+ InitializeStaticGLBindings(impl) && InitializeOneOffInternal();
if (!initialized && fallback_to_osmesa) {
ClearGLBindings();
initialized = InitializeStaticGLBindings(kGLImplementationOSMesaGL) &&
InitializeOneOffInternal();
}
+ if (!initialized)
+ ClearGLBindings();
if (initialized) {
DVLOG(1) << "Using "
@@ -76,6 +80,56 @@ bool GLSurface::InitializeOneOff() {
return initialized;
}
+// static
+void GLSurface::InitializeOneOffForTests() {
+ CommandLine* cmd = CommandLine::ForCurrentProcess();
+
+ bool use_osmesa = true;
+
+#if defined(OS_ANDROID)
+ // On Android we always use hardware GL.
+ use_osmesa = false;
+#endif
+
+ if (use_osmesa) {
+ if (cmd->HasSwitch(switches::kUseGL)) {
+ DCHECK(cmd->GetSwitchValueASCII(switches::kUseGL) ==
piman 2014/01/24 19:22:23 nit: maybe CHECK with an error message, so that na
danakj 2014/01/24 20:17:23 kk
+ kGLImplementationOSMesaName);
+ } else {
+ cmd->AppendSwitchASCII(switches::kUseGL, kGLImplementationOSMesaName);
+ }
+ } else {
+ DCHECK(!cmd->HasSwitch(switches::kUseGL));
+ }
+
+ // TODO(danakj): Unit tests do not produce pixel output by default.
+ // cmd->AppendSwitch(switches::kDisableGLDrawingForTests);
+
+ CHECK(InitializeOneOff());
+}
+
+// static
+void GLSurface::InitializeOneOffWithMockBindingsForTests() {
+ CommandLine* cmd = CommandLine::ForCurrentProcess();
+ if (cmd->HasSwitch(switches::kUseGL)) {
+ DCHECK(cmd->GetSwitchValueASCII(switches::kUseGL) ==
+ kGLImplementationMockName);
+ } else {
+ cmd->AppendSwitchASCII(switches::kUseGL, kGLImplementationMockName);
+ }
+
+ // This method may be called multiple times in the same process to set up
+ // mock bindings in different ways.
+ ClearGLBindings();
+
+ CHECK(InitializeOneOff());
+}
+
+// static
+void GLSurface::InitializeDynamicMockBindingsForTests(GLContext* context) {
+ CHECK(InitializeDynamicGLBindings(kGLImplementationMockGL, context));
+}
+
GLSurface::GLSurface() {}
bool GLSurface::Initialize() {

Powered by Google App Engine
This is Rietveld 408576698