summaryrefslogtreecommitdiffstats
path: root/ui/gl
diff options
context:
space:
mode:
Diffstat (limited to 'ui/gl')
-rw-r--r--ui/gl/gl_gl_api_implementation.cc17
-rw-r--r--ui/gl/gl_implementation.h2
-rw-r--r--ui/gl/gl_implementation_android.cc3
-rw-r--r--ui/gl/gl_implementation_mac.cc3
-rw-r--r--ui/gl/gl_implementation_ozone.cc3
-rw-r--r--ui/gl/gl_implementation_win.cc3
-rw-r--r--ui/gl/gl_implementation_x11.cc3
-rw-r--r--ui/gl/gl_surface.cc88
-rw-r--r--ui/gl/gl_surface.h12
-rw-r--r--ui/gl/gl_surface_egl.cc16
10 files changed, 30 insertions, 120 deletions
diff --git a/ui/gl/gl_gl_api_implementation.cc b/ui/gl/gl_gl_api_implementation.cc
index 9184fc3..ce8a711 100644
--- a/ui/gl/gl_gl_api_implementation.cc
+++ b/ui/gl/gl_gl_api_implementation.cc
@@ -148,31 +148,16 @@ static void GL_BINDING_CALL CustomRenderbufferStorageMultisampleEXT(
void DriverGL::InitializeCustomDynamicBindings(GLContext* context) {
InitializeDynamicBindings(context);
-
- DCHECK(orig_fn.glTexImage2DFn == NULL);
- orig_fn.glTexImage2DFn = fn.glTexImage2DFn;
+ orig_fn = fn;
fn.glTexImage2DFn =
reinterpret_cast<glTexImage2DProc>(CustomTexImage2D);
-
- DCHECK(orig_fn.glTexSubImage2DFn == NULL);
- orig_fn.glTexSubImage2DFn = fn.glTexSubImage2DFn;
fn.glTexSubImage2DFn =
reinterpret_cast<glTexSubImage2DProc>(CustomTexSubImage2D);
-
- DCHECK(orig_fn.glTexStorage2DEXTFn == NULL);
- orig_fn.glTexStorage2DEXTFn = fn.glTexStorage2DEXTFn;
fn.glTexStorage2DEXTFn =
reinterpret_cast<glTexStorage2DEXTProc>(CustomTexStorage2DEXT);
-
- DCHECK(orig_fn.glRenderbufferStorageEXTFn == NULL);
- orig_fn.glRenderbufferStorageEXTFn = fn.glRenderbufferStorageEXTFn;
fn.glRenderbufferStorageEXTFn =
reinterpret_cast<glRenderbufferStorageEXTProc>(
CustomRenderbufferStorageEXT);
-
- DCHECK(orig_fn.glRenderbufferStorageMultisampleEXTFn == NULL);
- orig_fn.glRenderbufferStorageMultisampleEXTFn =
- fn.glRenderbufferStorageMultisampleEXTFn;
fn.glRenderbufferStorageMultisampleEXTFn =
reinterpret_cast<glRenderbufferStorageMultisampleEXTProc>(
CustomRenderbufferStorageMultisampleEXT);
diff --git a/ui/gl/gl_implementation.h b/ui/gl/gl_implementation.h
index 0881e10..628fc1f 100644
--- a/ui/gl/gl_implementation.h
+++ b/ui/gl/gl_implementation.h
@@ -47,7 +47,7 @@ GL_EXPORT bool InitializeStaticGLBindings(GLImplementation implementation);
// Initialize function bindings that depend on the context for a GL
// implementation.
GL_EXPORT bool InitializeDynamicGLBindings(GLImplementation implementation,
- GLContext* context);
+ GLContext* context);
// Initialize Debug logging wrappers for GL bindings.
void InitializeDebugGLBindings();
diff --git a/ui/gl/gl_implementation_android.cc b/ui/gl/gl_implementation_android.cc
index 190f669..31fec9a 100644
--- a/ui/gl/gl_implementation_android.cc
+++ b/ui/gl/gl_implementation_android.cc
@@ -52,7 +52,8 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
// Prevent reinitialization with a different implementation. Once the gpu
// unit tests have initialized with kGLImplementationMock, we don't want to
// later switch to another GL implementation.
- DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+ if (GetGLImplementation() != kGLImplementationNone)
+ return true;
switch (implementation) {
case kGLImplementationEGLGLES2: {
diff --git a/ui/gl/gl_implementation_mac.cc b/ui/gl/gl_implementation_mac.cc
index 1011406..546a082f 100644
--- a/ui/gl/gl_implementation_mac.cc
+++ b/ui/gl/gl_implementation_mac.cc
@@ -31,7 +31,8 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
// Prevent reinitialization with a different implementation. Once the gpu
// unit tests have initialized with kGLImplementationMock, we don't want to
// later switch to another GL implementation.
- DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+ if (GetGLImplementation() != kGLImplementationNone)
+ return true;
// Allow the main thread or another to initialize these bindings
// after instituting restrictions on I/O. Going forward they will
diff --git a/ui/gl/gl_implementation_ozone.cc b/ui/gl/gl_implementation_ozone.cc
index b8dd2c4..3659a02 100644
--- a/ui/gl/gl_implementation_ozone.cc
+++ b/ui/gl/gl_implementation_ozone.cc
@@ -37,7 +37,8 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
// Prevent reinitialization with a different implementation. Once the gpu
// unit tests have initialized with kGLImplementationMock, we don't want to
// later switch to another GL implementation.
- DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+ if (GetGLImplementation() != kGLImplementationNone)
+ return true;
switch (implementation) {
case kGLImplementationOSMesaGL:
diff --git a/ui/gl/gl_implementation_win.cc b/ui/gl/gl_implementation_win.cc
index 5269297..ddc9c57 100644
--- a/ui/gl/gl_implementation_win.cc
+++ b/ui/gl/gl_implementation_win.cc
@@ -112,7 +112,8 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
// Prevent reinitialization with a different implementation. Once the gpu
// unit tests have initialized with kGLImplementationMock, we don't want to
// later switch to another GL implementation.
- DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+ if (GetGLImplementation() != kGLImplementationNone)
+ return true;
// Allow the main thread or another to initialize these bindings
// after instituting restrictions on I/O. Going forward they will
diff --git a/ui/gl/gl_implementation_x11.cc b/ui/gl/gl_implementation_x11.cc
index c19b39e..7588a37 100644
--- a/ui/gl/gl_implementation_x11.cc
+++ b/ui/gl/gl_implementation_x11.cc
@@ -43,7 +43,8 @@ bool InitializeStaticGLBindings(GLImplementation implementation) {
// Prevent reinitialization with a different implementation. Once the gpu
// unit tests have initialized with kGLImplementationMock, we don't want to
// later switch to another GL implementation.
- DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+ if (GetGLImplementation() != kGLImplementationNone)
+ return true;
// Allow the main thread or another to initialize these bindings
// after instituting restrictions on I/O. Going forward they will
diff --git a/ui/gl/gl_surface.cc b/ui/gl/gl_surface.cc
index e9c7ce9..a52a3f7 100644
--- a/ui/gl/gl_surface.cc
+++ b/ui/gl/gl_surface.cc
@@ -14,7 +14,6 @@
#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 {
@@ -25,7 +24,9 @@ base::LazyInstance<base::ThreadLocalPointer<GLSurface> >::Leaky
// static
bool GLSurface::InitializeOneOff() {
- DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+ static bool initialized = false;
+ if (initialized)
+ return true;
TRACE_EVENT0("gpu", "GLSurface::InitializeOneOff");
@@ -33,14 +34,12 @@ 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 (cmd->HasSwitch(switches::kUseGL)) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseGL)) {
std::string requested_implementation_name =
- cmd->GetSwitchValueASCII(switches::kUseGL);
+ CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switches::kUseGL);
if (requested_implementation_name == "any") {
fallback_to_osmesa = true;
} else if (requested_implementation_name == "swiftshader") {
@@ -56,94 +55,27 @@ bool GLSurface::InitializeOneOff() {
}
}
- 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();
+ 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 (gpu_service_logging)
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableGPUServiceLogging))
InitializeDebugGLBindings();
- if (disable_gl_drawing)
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kDisableGLDrawingForTests))
InitializeNullDrawGLBindings();
}
return initialized;
}
-// static
-void GLSurface::InitializeOneOffForTests() {
- bool use_osmesa = true;
-
-#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() {
diff --git a/ui/gl/gl_surface.h b/ui/gl/gl_surface.h
index f7a02f0..8eaf60d 100644
--- a/ui/gl/gl_surface.h
+++ b/ui/gl/gl_surface.h
@@ -12,7 +12,6 @@
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/size.h"
#include "ui/gl/gl_export.h"
-#include "ui/gl/gl_implementation.h"
namespace gfx {
@@ -70,15 +69,8 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> {
// Copy part of the backbuffer to the frontbuffer.
virtual bool PostSubBuffer(int x, int y, int width, int height);
- // Initialize GL bindings.
static bool InitializeOneOff();
- // Unit tests should call these instead of InitializeOneOff() to set up
- // GL bindings appropriate for tests.
- static void InitializeOneOffForTests();
- static void InitializeOneOffWithMockBindingsForTests();
- static void InitializeDynamicMockBindingsForTests(GLContext* context);
-
// Called after a context is made current with this surface. Returns false
// on error.
virtual bool OnMakeCurrent(GLContext* context);
@@ -117,10 +109,6 @@ class GL_EXPORT GLSurface : public base::RefCounted<GLSurface> {
protected:
virtual ~GLSurface();
- static bool InitializeOneOffImplementation(GLImplementation impl,
- bool fallback_to_osmesa,
- bool gpu_service_logging,
- bool disable_gl_drawing);
static bool InitializeOneOffInternal();
static void SetCurrent(GLSurface* surface);
diff --git a/ui/gl/gl_surface_egl.cc b/ui/gl/gl_surface_egl.cc
index 635595c..0db2fc7 100644
--- a/ui/gl/gl_surface_egl.cc
+++ b/ui/gl/gl_surface_egl.cc
@@ -784,14 +784,14 @@ GLSurfaceOSMesaHeadless::~GLSurfaceOSMesaHeadless() { Destroy(); }
// static
bool GLSurface::InitializeOneOffInternal() {
- switch (GetGLImplementation()) {
- case kGLImplementationEGLGLES2:
- if (!GLSurfaceEGL::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
- return false;
- }
- default:
- break;
+ if (GetGLImplementation() == kGLImplementationOSMesaGL) {
+ return true;
+ }
+ DCHECK(GetGLImplementation() == kGLImplementationEGLGLES2);
+
+ if (!GLSurfaceEGL::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
+ return false;
}
return true;
}