Chromium Code Reviews| 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() { |