Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 30ae958a authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "[egl] add support for vendor-specific GL extensions" into gingerbread

parents 91f8cbe1 28806637
Loading
Loading
Loading
Loading
+62 −0
Original line number Diff line number Diff line
@@ -44,6 +44,15 @@
#include "egl_impl.h"
#include "Loader.h"

// Enable this define to allow querying vendor-specific GL extensions. This
// currently will only work correctly for implementations which have a single
// EGL backend; multiple EGL backends are not supported.
// There's also an extra subtlety with the EGLimage entry points in GL, which
// can't work properly if they're called directly (they have to go through
// a wrapper).
#define ENABLE_VENDOR_EXTENSIONS

#define MAKE_CONFIG(_impl, _index)  ((EGLConfig)(((_impl)<<24) | (_index)))
#define setError(_e, _r) setErrorEtc(__FUNCTION__, __LINE__, _e, _r)

// ----------------------------------------------------------------------------
@@ -59,6 +68,11 @@ static char const * const gExtensionString =
        "EGL_KHR_image "
        "EGL_KHR_image_base "
        "EGL_KHR_image_pixmap "
#ifdef ENABLE_VENDOR_EXTENSIONS
        "EGL_KHR_gl_texture_2D_image "
        "EGL_KHR_gl_texture_cubemap_image "
        "EGL_KHR_gl_renderbuffer_image "
#endif
        "EGL_ANDROID_image_native_buffer "
        "EGL_ANDROID_swap_rectangle "
        ;
@@ -1365,6 +1379,31 @@ EGLint eglGetError(void)
    return result;
}

#ifdef ENABLE_VENDOR_EXTENSIONS
// Note: Similar implementations of this function also exist in gl2.cpp and
// gl.cpp, and are used by applications that call the exported entry points
// directly.
typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) (GLenum target, GLeglImageOES image);
typedef void (GL_APIENTRYP PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC) (GLenum target, GLeglImageOES image);

static PFNGLEGLIMAGETARGETTEXTURE2DOESPROC glEGLImageTargetTexture2DOES_impl = NULL;
static PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC glEGLImageTargetRenderbufferStorageOES_impl = NULL;

static void glEGLImageTargetTexture2DOES_wrapper(GLenum target, GLeglImageOES image)
{
    GLeglImageOES implImage =
        (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
    glEGLImageTargetTexture2DOES_impl(target, implImage);
}

static void glEGLImageTargetRenderbufferStorageOES_wrapper(GLenum target, GLeglImageOES image)
{
    GLeglImageOES implImage =
        (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
    glEGLImageTargetRenderbufferStorageOES_impl(target, implImage);
}
#endif

__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
{
    // eglGetProcAddress() could be the very first function called
@@ -1380,6 +1419,29 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
    addr = findProcAddress(procname, gExtentionMap, NELEM(gExtentionMap));
    if (addr) return addr;

#ifdef ENABLE_VENDOR_EXTENSIONS
    addr = 0;
    for (int i=0 ; i<IMPL_NUM_IMPLEMENTATIONS ; i++) {
        egl_connection_t* const cnx = &gEGLImpl[i];
        if (cnx->dso) {
            if (cnx->egl.eglGetProcAddress) {
                addr = cnx->egl.eglGetProcAddress(procname);
                if (addr) {
                    if (!strcmp(procname, "glEGLImageTargetTexture2DOES")) {
                        glEGLImageTargetTexture2DOES_impl = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)addr;
                        return (__eglMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES_wrapper;
                    }
                    if (!strcmp(procname, "glEGLImageTargetRenderbufferStorageOES")) {
                        glEGLImageTargetRenderbufferStorageOES_impl = (PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC)addr;
                        return (__eglMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES_wrapper;
                    }
                    return addr;
                }
            }
        }
    }
#endif

    // this protects accesses to gGLExtentionMap and gGLExtentionSlot
    pthread_mutex_lock(&gInitDriverMutex);