summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-10 23:45:38 +0000
committerbacker@chromium.org <backer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-05-10 23:45:38 +0000
commit8f1d2aa6f3433d4ea36e624ee2bb84155bbd67b4 (patch)
tree3ee5ae5244a5322673361b79030e1b57ff044f9d /ui
parentaa9b14d66749ef7d81702ef53ce1cd765e6affd2 (diff)
downloadchromium_src-8f1d2aa6f3433d4ea36e624ee2bb84155bbd67b4.zip
chromium_src-8f1d2aa6f3433d4ea36e624ee2bb84155bbd67b4.tar.gz
chromium_src-8f1d2aa6f3433d4ea36e624ee2bb84155bbd67b4.tar.bz2
Reland 199454: "Move WrappedTexImage functionality to ui/gl"
Move WrappedTexImage functionality to ui/gl BUG=235031 Review URL: https://chromiumcodereview.appspot.com/14983005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@199573 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rwxr-xr-xui/gl/generate_bindings.py16
-rw-r--r--ui/gl/gl_bindings.h71
-rw-r--r--ui/gl/gl_gl_api_implementation.cc123
3 files changed, 192 insertions, 18 deletions
diff --git a/ui/gl/generate_bindings.py b/ui/gl/generate_bindings.py
index c19488c..968ec77 100755
--- a/ui/gl/generate_bindings.py
+++ b/ui/gl/generate_bindings.py
@@ -1218,22 +1218,6 @@ class GLContext;
file.write('};\n')
file.write('\n')
- # Write Driver struct.
- file.write(
-"""struct GL_EXPORT Driver%(name)s {
- void InitializeBindings();
- void InitializeExtensionBindings(GLContext* context);
- void InitializeDebugBindings();
- void ClearBindings();
- void UpdateDebugExtensionBindings();
-
- Procs%(name)s fn;
- Procs%(name)s debug_fn;
- Extensions%(name)s ext;
-""" % {'name': set_name.upper()})
- file.write('};\n')
- file.write('\n')
-
# Write Api class.
file.write(
"""class GL_EXPORT %(name)sApi {
diff --git a/ui/gl/gl_bindings.h b/ui/gl/gl_bindings.h
index e7bd808..38cadde 100644
--- a/ui/gl/gl_bindings.h
+++ b/ui/gl/gl_bindings.h
@@ -212,6 +212,77 @@ typedef uint64 EGLuint64CHROMIUM;
namespace gfx {
+struct GL_EXPORT DriverGL {
+ void Initialize();
+ void InitializeExtensions(GLContext* context);
+ void InitializeDebugBindings();
+ void ClearBindings();
+ void UpdateDebugExtensionBindings();
+
+ ProcsGL fn;
+ ProcsGL orig_fn;
+ ProcsGL debug_fn;
+ ExtensionsGL ext;
+
+ private:
+ void InitializeBindings();
+ void InitializeExtensionBindings(GLContext* context);
+};
+
+struct GL_EXPORT DriverOSMESA {
+ void InitializeBindings();
+ void InitializeExtensionBindings(GLContext* context);
+ void InitializeDebugBindings();
+ void ClearBindings();
+ void UpdateDebugExtensionBindings();
+
+ ProcsOSMESA fn;
+ ProcsOSMESA debug_fn;
+ ExtensionsOSMESA ext;
+};
+
+#if defined(OS_WIN)
+struct GL_EXPORT DriverWGL {
+ void InitializeBindings();
+ void InitializeExtensionBindings(GLContext* context);
+ void InitializeDebugBindings();
+ void ClearBindings();
+ void UpdateDebugExtensionBindings();
+
+ ProcsWGL fn;
+ ProcsWGL debug_fn;
+ ExtensionsWGL ext;
+};
+#endif
+
+#if defined(OS_WIN) || defined(USE_X11) || defined(OS_ANDROID)
+struct GL_EXPORT DriverEGL {
+ void InitializeBindings();
+ void InitializeExtensionBindings(GLContext* context);
+ void InitializeDebugBindings();
+ void ClearBindings();
+ void UpdateDebugExtensionBindings();
+
+ ProcsEGL fn;
+ ProcsEGL debug_fn;
+ ExtensionsEGL ext;
+};
+#endif
+
+#if defined(USE_X11)
+struct GL_EXPORT DriverGLX {
+ void InitializeBindings();
+ void InitializeExtensionBindings(GLContext* context);
+ void InitializeDebugBindings();
+ void ClearBindings();
+ void UpdateDebugExtensionBindings();
+
+ ProcsGLX fn;
+ ProcsGLX debug_fn;
+ ExtensionsGLX ext;
+};
+#endif
+
GL_EXPORT extern GLApi* g_current_gl_context;
GL_EXPORT extern OSMESAApi* g_current_osmesa_context;
GL_EXPORT extern DriverGL g_driver_gl;
diff --git a/ui/gl/gl_gl_api_implementation.cc b/ui/gl/gl_gl_api_implementation.cc
index 303ae1d..1002dbd 100644
--- a/ui/gl/gl_gl_api_implementation.cc
+++ b/ui/gl/gl_gl_api_implementation.cc
@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/string_util.h"
#include "ui/gl/gl_context.h"
+#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_state_restorer.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/gl_switches.h"
@@ -23,8 +24,126 @@ static RealGLApi* g_real_gl;
// A GL Api that calls TRACE and then calls another GL api.
static TraceGLApi* g_trace_gl;
+namespace {
+
+static inline GLenum GetTexInternalFormat(GLenum internal_format) {
+ if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
+ if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT)
+ return GL_RGBA8;
+ }
+ return internal_format;
+}
+
+// TODO(epenner): Could the above function be merged into this and removed?
+static inline GLenum GetTexInternalFormat(GLenum internal_format,
+ GLenum format,
+ GLenum type) {
+ GLenum gl_internal_format = GetTexInternalFormat(internal_format);
+
+ if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2)
+ return gl_internal_format;
+
+ if (type == GL_FLOAT) {
+ switch (format) {
+ case GL_RGBA:
+ gl_internal_format = GL_RGBA32F_ARB;
+ break;
+ case GL_RGB:
+ gl_internal_format = GL_RGB32F_ARB;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ gl_internal_format = GL_LUMINANCE_ALPHA32F_ARB;
+ break;
+ case GL_LUMINANCE:
+ gl_internal_format = GL_LUMINANCE32F_ARB;
+ break;
+ case GL_ALPHA:
+ gl_internal_format = GL_ALPHA32F_ARB;
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ } else if (type == GL_HALF_FLOAT_OES) {
+ switch (format) {
+ case GL_RGBA:
+ gl_internal_format = GL_RGBA16F_ARB;
+ break;
+ case GL_RGB:
+ gl_internal_format = GL_RGB16F_ARB;
+ break;
+ case GL_LUMINANCE_ALPHA:
+ gl_internal_format = GL_LUMINANCE_ALPHA16F_ARB;
+ break;
+ case GL_LUMINANCE:
+ gl_internal_format = GL_LUMINANCE16F_ARB;
+ break;
+ case GL_ALPHA:
+ gl_internal_format = GL_ALPHA16F_ARB;
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ }
+ return gl_internal_format;
+}
+
+static inline GLenum GetTexType(GLenum type) {
+ if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
+ if (type == GL_HALF_FLOAT_OES)
+ return GL_HALF_FLOAT_ARB;
+ }
+ return type;
+}
+
+static void GL_BINDING_CALL CustomTexImage2D(
+ GLenum target, GLint level, GLint internalformat,
+ GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type,
+ const void* pixels) {
+ GLenum gl_internal_format = GetTexInternalFormat(
+ internalformat, format, type);
+ GLenum gl_type = GetTexType(type);
+ return g_driver_gl.orig_fn.glTexImage2DFn(
+ target, level, gl_internal_format, width, height, border, format, gl_type,
+ pixels);
+}
+
+static void GL_BINDING_CALL CustomTexSubImage2D(
+ GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
+ GLsizei height, GLenum format, GLenum type, const void* pixels) {
+ GLenum gl_type = GetTexType(type);
+ return g_driver_gl.orig_fn.glTexSubImage2DFn(
+ target, level, xoffset, yoffset, width, height, format, gl_type, pixels);
+}
+
+static void GL_BINDING_CALL CustomTexStorage2DEXT(
+ GLenum target, GLsizei levels, GLenum internalformat, GLsizei width,
+ GLsizei height) {
+ GLenum gl_internal_format = GetTexInternalFormat(internalformat);
+ return g_driver_gl.orig_fn.glTexStorage2DEXTFn(
+ target, levels, gl_internal_format, width, height);
+}
+
+} // anonymous namespace
+
+void DriverGL::Initialize() {
+ InitializeBindings();
+}
+
+void DriverGL::InitializeExtensions(GLContext* context) {
+ InitializeExtensionBindings(context);
+ orig_fn = fn;
+ fn.glTexImage2DFn =
+ reinterpret_cast<glTexImage2DProc>(CustomTexImage2D);
+ fn.glTexSubImage2DFn =
+ reinterpret_cast<glTexSubImage2DProc>(CustomTexSubImage2D);
+ fn.glTexStorage2DEXTFn =
+ reinterpret_cast<glTexStorage2DEXTProc>(CustomTexStorage2DEXT);
+}
+
void InitializeGLBindingsGL() {
- g_driver_gl.InitializeBindings();
+ g_driver_gl.Initialize();
if (!g_real_gl) {
g_real_gl = new RealGLApi();
g_trace_gl = new TraceGLApi(g_real_gl);
@@ -51,7 +170,7 @@ void SetGLToRealGLApi() {
}
void InitializeGLExtensionBindingsGL(GLContext* context) {
- g_driver_gl.InitializeExtensionBindings(context);
+ g_driver_gl.InitializeExtensions(context);
}
void InitializeDebugGLBindingsGL() {