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

Commit 7c0441ac authored by Mathias Agopian's avatar Mathias Agopian
Browse files

Don't wrap EGLImageKHR and EGLSyncKHR anymore

this simplify our EGL wrapper implementation a lot.
This wrapping is no longer needed now that we can only
support a single underlaying EGL implementation.

Change-Id: I8213df7ac69daac447f1fe6e37044b78aac4e9a9
parent f234ad00
Loading
Loading
Loading
Loading
+0 −28
Original line number Original line Diff line number Diff line
@@ -202,34 +202,6 @@ egl_connection_t* validate_display_config(EGLDisplay dpy, EGLConfig,


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


EGLImageKHR egl_get_image_for_current_context(EGLImageKHR image)
{
    EGLContext context = egl_tls_t::getContext();
    if (context == EGL_NO_CONTEXT || image == EGL_NO_IMAGE_KHR)
        return EGL_NO_IMAGE_KHR;

    egl_context_t const * const c = get_context(context);
    if (c == NULL) // this should never happen, by construction
        return EGL_NO_IMAGE_KHR;

    egl_display_t* display = egl_display_t::get(c->dpy);
    if (display == NULL) // this should never happen, by construction
        return EGL_NO_IMAGE_KHR;

    ImageRef _i(display, image);
    if (!_i.get())
        return EGL_NO_IMAGE_KHR;

    // here we don't validate the context because if it's been marked for
    // termination, this call should still succeed since it's internal to
    // EGL.

    egl_image_t const * const i = get_image(image);
    return i->image;
}

// ----------------------------------------------------------------------------

const GLubyte * egl_get_string_for_current_context(GLenum name) {
const GLubyte * egl_get_string_for_current_context(GLenum name) {
    // NOTE: returning NULL here will fall-back to the default
    // NOTE: returning NULL here will fall-back to the default
    // implementation.
    // implementation.
+35 −162
Original line number Original line Diff line number Diff line
@@ -627,29 +627,6 @@ EGLint eglGetError(void)
    return err;
    return err;
}
}


// Note: Similar implementations of these functions 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);
}

__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
__eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)
{
{
    // eglGetProcAddress() could be the very first function called
    // eglGetProcAddress() could be the very first function called
@@ -724,16 +701,6 @@ __eglMustCastToProperFunctionPointerType eglGetProcAddress(const char *procname)


            if (found) {
            if (found) {
                addr = gExtensionForwarders[slot];
                addr = gExtensionForwarders[slot];

                if (!strcmp(procname, "glEGLImageTargetTexture2DOES")) {
                    glEGLImageTargetTexture2DOES_impl = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)addr;
                    addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetTexture2DOES_wrapper;
                }
                if (!strcmp(procname, "glEGLImageTargetRenderbufferStorageOES")) {
                    glEGLImageTargetRenderbufferStorageOES_impl = (PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC)addr;
                    addr = (__eglMustCastToProperFunctionPointerType)glEGLImageTargetRenderbufferStorageOES_wrapper;
                }

                sGLExtentionMap.add(name, addr);
                sGLExtentionMap.add(name, addr);
                sGLExtentionSlot++;
                sGLExtentionSlot++;
            }
            }
@@ -1024,57 +991,18 @@ EGLImageKHR eglCreateImageKHR(EGLDisplay dpy, EGLContext ctx, EGLenum target,
    egl_display_t const * const dp = validate_display(dpy);
    egl_display_t const * const dp = validate_display(dpy);
    if (!dp) return EGL_NO_IMAGE_KHR;
    if (!dp) return EGL_NO_IMAGE_KHR;


    if (ctx != EGL_NO_CONTEXT) {
    ContextRef _c(dp, ctx);
    ContextRef _c(dp, ctx);
        if (!_c.get())
    egl_context_t * const c = _c.get();
            return setError(EGL_BAD_CONTEXT, EGL_NO_IMAGE_KHR);
        egl_context_t * const c = get_context(ctx);
        // since we have an EGLContext, we know which implementation to use
        EGLImageKHR image = c->cnx->egl.eglCreateImageKHR(
                dp->disp.dpy, c->context, target, buffer, attrib_list);
        if (image == EGL_NO_IMAGE_KHR)
            return image;
            
        egl_image_t* result = new egl_image_t(dpy, ctx);
        result->image = image;
        return (EGLImageKHR)result;
    } else {
        // EGL_NO_CONTEXT is a valid parameter

        /* Since we don't have a way to know which implementation to call,
         * we're calling all of them. If at least one of the implementation
         * succeeded, this is a success.
         */

        EGLint currentError = eglGetError();


        EGLImageKHR implImage = EGL_NO_IMAGE_KHR;
    EGLImageKHR result = EGL_NO_IMAGE_KHR;
    egl_connection_t* const cnx = &gEGLImpl;
    egl_connection_t* const cnx = &gEGLImpl;
    if (cnx->dso && cnx->egl.eglCreateImageKHR) {
    if (cnx->dso && cnx->egl.eglCreateImageKHR) {
            implImage = cnx->egl.eglCreateImageKHR(
        result = cnx->egl.eglCreateImageKHR(
                    dp->disp.dpy, ctx, target, buffer, attrib_list);
                dp->disp.dpy,
        }
                c ? c->context : EGL_NO_CONTEXT,

                target, buffer, attrib_list);
        if (implImage == EGL_NO_IMAGE_KHR) {
            // failure, if there was an error when we entered this function,
            // the error flag must not be updated.
            // Otherwise, the error is whatever happened in the implementation
            // that faulted.
            if (currentError != EGL_SUCCESS) {
                setError(currentError, EGL_NO_IMAGE_KHR);
            }
            return EGL_NO_IMAGE_KHR;
        } else {
            // In case of success, we need to clear all error flags
            // (especially those caused by the implementation that didn't
            // succeed).
            eglGetError();
        }

        egl_image_t* result = new egl_image_t(dpy, ctx);
        result->image = implImage;
        return (EGLImageKHR)result;
    }
    }
    return result;
}
}


EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
@@ -1084,27 +1012,10 @@ EGLBoolean eglDestroyImageKHR(EGLDisplay dpy, EGLImageKHR img)
    egl_display_t const * const dp = validate_display(dpy);
    egl_display_t const * const dp = validate_display(dpy);
    if (!dp) return EGL_FALSE;
    if (!dp) return EGL_FALSE;


    ImageRef _i(dp, img);
    if (!_i.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE);

    egl_image_t* image = get_image(img);
    bool success = false;

    egl_connection_t* const cnx = &gEGLImpl;
    egl_connection_t* const cnx = &gEGLImpl;
    if (image->image != EGL_NO_IMAGE_KHR) {
    if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
    if (cnx->dso && cnx->egl.eglDestroyImageKHR) {
            if (cnx->egl.eglDestroyImageKHR(
        cnx->egl.eglDestroyImageKHR(dp->disp.dpy, img);
                    dp->disp.dpy, image->image)) {
                success = true;
    }
    }
        }
    }

    if (!success)
        return EGL_FALSE;

    _i.terminate();

    return EGL_TRUE;
    return EGL_TRUE;
}
}


@@ -1120,21 +1031,12 @@ EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, EGLenum type, const EGLint *attrib_l
    egl_display_t const * const dp = validate_display(dpy);
    egl_display_t const * const dp = validate_display(dpy);
    if (!dp) return EGL_NO_SYNC_KHR;
    if (!dp) return EGL_NO_SYNC_KHR;


    EGLContext ctx = eglGetCurrentContext();
    ContextRef _c(dp, ctx);
    if (!_c.get())
        return setError(EGL_BAD_CONTEXT, EGL_NO_SYNC_KHR);

    egl_context_t * const c = get_context(ctx);
    EGLSyncKHR result = EGL_NO_SYNC_KHR;
    EGLSyncKHR result = EGL_NO_SYNC_KHR;
    if (c->cnx->egl.eglCreateSyncKHR) {
    egl_connection_t* const cnx = &gEGLImpl;
        EGLSyncKHR sync = c->cnx->egl.eglCreateSyncKHR(
    if (cnx->dso && cnx->egl.eglCreateSyncKHR) {
                dp->disp.dpy, type, attrib_list);
        result = cnx->egl.eglCreateSyncKHR(dp->disp.dpy, type, attrib_list);
        if (sync == EGL_NO_SYNC_KHR)
            return sync;
        result = (egl_sync_t*)new egl_sync_t(dpy, ctx, sync);
    }
    }
    return (EGLSyncKHR)result;
    return result;
}
}


EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
@@ -1144,75 +1046,46 @@ EGLBoolean eglDestroySyncKHR(EGLDisplay dpy, EGLSyncKHR sync)
    egl_display_t const * const dp = validate_display(dpy);
    egl_display_t const * const dp = validate_display(dpy);
    if (!dp) return EGL_FALSE;
    if (!dp) return EGL_FALSE;


    SyncRef _s(dp, sync);
    if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE);
    egl_sync_t* syncObject = get_sync(sync);

    EGLContext ctx = syncObject->context;
    ContextRef _c(dp, ctx);
    if (!_c.get())
        return setError(EGL_BAD_CONTEXT, EGL_FALSE);

    EGLBoolean result = EGL_FALSE;
    EGLBoolean result = EGL_FALSE;
    egl_context_t * const c = get_context(ctx);
    egl_connection_t* const cnx = &gEGLImpl;
    if (c->cnx->egl.eglDestroySyncKHR) {
    if (cnx->dso && cnx->egl.eglDestroySyncKHR) {
        result = c->cnx->egl.eglDestroySyncKHR(
        result = cnx->egl.eglDestroySyncKHR(dp->disp.dpy, sync);
                dp->disp.dpy, syncObject->sync);
        if (result)
            _s.terminate();
    }
    }
    return result;
    return result;
}
}


EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint flags, EGLTimeKHR timeout)
EGLint eglClientWaitSyncKHR(EGLDisplay dpy, EGLSyncKHR sync,
        EGLint flags, EGLTimeKHR timeout)
{
{
    clearError();
    clearError();


    egl_display_t const * const dp = validate_display(dpy);
    egl_display_t const * const dp = validate_display(dpy);
    if (!dp) return EGL_FALSE;
    if (!dp) return EGL_FALSE;


    SyncRef _s(dp, sync);
    EGLBoolean result = EGL_FALSE;
    if (!_s.get()) return setError(EGL_BAD_PARAMETER, EGL_FALSE);
    egl_connection_t* const cnx = &gEGLImpl;
    egl_sync_t* syncObject = get_sync(sync);
    if (cnx->dso && cnx->egl.eglClientWaitSyncKHR) {

        result = cnx->egl.eglClientWaitSyncKHR(
    EGLContext ctx = syncObject->context;
                dp->disp.dpy, sync, flags, timeout);
    ContextRef _c(dp, ctx);
    if (!_c.get())
        return setError(EGL_BAD_CONTEXT, EGL_FALSE);

    egl_context_t * const c = get_context(ctx);
    if (c->cnx->egl.eglClientWaitSyncKHR) {
        return c->cnx->egl.eglClientWaitSyncKHR(
                dp->disp.dpy, syncObject->sync, flags, timeout);
    }
    }

    return result;
    return EGL_FALSE;
}
}


EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, EGLint attribute, EGLint *value)
EGLBoolean eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync,
        EGLint attribute, EGLint *value)
{
{
    clearError();
    clearError();


    egl_display_t const * const dp = validate_display(dpy);
    egl_display_t const * const dp = validate_display(dpy);
    if (!dp) return EGL_FALSE;
    if (!dp) return EGL_FALSE;


    SyncRef _s(dp, sync);
    EGLBoolean result = EGL_FALSE;
    if (!_s.get())
    egl_connection_t* const cnx = &gEGLImpl;
        return setError(EGL_BAD_PARAMETER, EGL_FALSE);
    if (cnx->dso && cnx->egl.eglGetSyncAttribKHR) {

        result = cnx->egl.eglGetSyncAttribKHR(
    egl_sync_t* syncObject = get_sync(sync);
                dp->disp.dpy, sync, attribute, value);
    EGLContext ctx = syncObject->context;
    ContextRef _c(dp, ctx);
    if (!_c.get())
        return setError(EGL_BAD_CONTEXT, EGL_FALSE);

    egl_context_t * const c = get_context(ctx);
    if (c->cnx->egl.eglGetSyncAttribKHR) {
        return c->cnx->egl.eglGetSyncAttribKHR(
                dp->disp.dpy, syncObject->sync, attribute, value);
    }
    }

    return result;
    return EGL_FALSE;
}
}


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
+0 −40
Original line number Original line Diff line number Diff line
@@ -173,40 +173,10 @@ public:
    String8 gl_extensions;
    String8 gl_extensions;
};
};


class egl_image_t: public egl_object_t {
protected:
    ~egl_image_t() {}
public:
    typedef egl_object_t::LocalRef<egl_image_t, EGLImageKHR> Ref;

    egl_image_t(EGLDisplay dpy, EGLContext context) :
        egl_object_t(get_display(dpy)),
        dpy(dpy), context(context), image(EGL_NO_IMAGE_KHR) { }
    EGLDisplay dpy;
    EGLContext context;
    EGLImageKHR image;
};

class egl_sync_t: public egl_object_t {
protected:
    ~egl_sync_t() {}
public:
    typedef egl_object_t::LocalRef<egl_sync_t, EGLSyncKHR> Ref;

    egl_sync_t(EGLDisplay dpy, EGLContext context, EGLSyncKHR sync) :
        egl_object_t(get_display(dpy)), dpy(dpy), context(context), sync(sync) {
    }
    EGLDisplay dpy;
    EGLContext context;
    EGLSyncKHR sync;
};

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


typedef egl_surface_t::Ref  SurfaceRef;
typedef egl_surface_t::Ref  SurfaceRef;
typedef egl_context_t::Ref  ContextRef;
typedef egl_context_t::Ref  ContextRef;
typedef egl_image_t::Ref    ImageRef;
typedef egl_sync_t::Ref     SyncRef;


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


@@ -225,16 +195,6 @@ egl_context_t* get_context(EGLContext context) {
    return egl_to_native_cast<egl_context_t>(context);
    return egl_to_native_cast<egl_context_t>(context);
}
}


static inline
egl_image_t* get_image(EGLImageKHR image) {
    return egl_to_native_cast<egl_image_t>(image);
}

static inline
egl_sync_t* get_sync(EGLSyncKHR sync) {
    return egl_to_native_cast<egl_sync_t>(sync);
}

// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
}; // namespace android
}; // namespace android
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
+0 −24
Original line number Original line Diff line number Diff line
@@ -124,27 +124,3 @@ const GLubyte * glGetString(GLenum name)
    }
    }
    return ret;
    return ret;
}
}

/*
 * These GL calls are special because they need to EGL to retrieve some
 * informations before they can execute.
 */

extern "C" void __glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image);
extern "C" void __glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image);


void glEGLImageTargetTexture2DOES(GLenum target, GLeglImageOES image)
{
    GLeglImageOES implImage = 
        (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
    __glEGLImageTargetTexture2DOES(target, implImage);
}

void glEGLImageTargetRenderbufferStorageOES(GLenum target, GLeglImageOES image)
{
    GLeglImageOES implImage = 
        (GLeglImageOES)egl_get_image_for_current_context((EGLImageKHR)image);
    __glEGLImageTargetRenderbufferStorageOES(target, implImage);
}
+2 −2
Original line number Original line Diff line number Diff line
void API_ENTRY(__glEGLImageTargetTexture2DOES)(GLenum target, GLeglImageOES image) {
void API_ENTRY(glEGLImageTargetTexture2DOES)(GLenum target, GLeglImageOES image) {
    CALL_GL_API(glEGLImageTargetTexture2DOES, target, image);
    CALL_GL_API(glEGLImageTargetTexture2DOES, target, image);
}
}
void API_ENTRY(__glEGLImageTargetRenderbufferStorageOES)(GLenum target, GLeglImageOES image) {
void API_ENTRY(glEGLImageTargetRenderbufferStorageOES)(GLenum target, GLeglImageOES image) {
    CALL_GL_API(glEGLImageTargetRenderbufferStorageOES, target, image);
    CALL_GL_API(glEGLImageTargetRenderbufferStorageOES, target, image);
}
}
void API_ENTRY(glGetProgramBinaryOES)(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary) {
void API_ENTRY(glGetProgramBinaryOES)(GLuint program, GLsizei bufSize, GLsizei *length, GLenum *binaryFormat, GLvoid *binary) {
Loading