[vlc-devel] [PATCH 1/2] egl: Import GLES symbols with a direct library dlopen

Rémi Denis-Courmont remi at remlab.net
Tue May 22 16:59:09 CEST 2018


Le tiistaina 22. toukokuuta 2018, 17.32.43 EEST Paul Kocialkowski a écrit :
> It appears that some EGL blobs (usually used with GLES) don't expose all
> the required core GLES API functions through eglGetProcAddress.

AFAICT, this is undefined behaviour. This might be fine for an embedded build 
where you know the bugs in your driver, but it looks totally unsafe in 
general, and therefore unacceptable in upstream VLC.

> 
> Resort to mapping these symbols using dlopen directly instead.
> 
> Signed-off-by: Paul Kocialkowski <paul.kocialkowski at bootlin.com>
> ---
>  modules/video_output/opengl/egl.c | 28 ++++++++++++++++++++++++++--
>  1 file changed, 26 insertions(+), 2 deletions(-)
> 
> diff --git a/modules/video_output/opengl/egl.c
> b/modules/video_output/opengl/egl.c index 9162675447..0477be5474 100644
> --- a/modules/video_output/opengl/egl.c
> +++ b/modules/video_output/opengl/egl.c
> @@ -26,6 +26,7 @@
> 
>  #include <stdlib.h>
>  #include <assert.h>
> +#include <dlfcn.h>
>  #include <EGL/egl.h>
>  #include <EGL/eglext.h>
> 
> @@ -43,6 +44,8 @@
>  # include "../android/utils.h"
>  #endif
> 
> +#define LIBGLESv2_DL_NAME "libGLESv2.so.2"
> +
>  typedef struct vlc_gl_sys_t
>  {
>      EGLDisplay display;
> @@ -57,6 +60,8 @@ typedef struct vlc_gl_sys_t
>  #endif
>      PFNEGLCREATEIMAGEKHRPROC    eglCreateImageKHR;
>      PFNEGLDESTROYIMAGEKHRPROC   eglDestroyImageKHR;
> +    bool is_gles;

No way. We already track the API.

> +    void *gles_handle;
>  } vlc_gl_sys_t;
> 
>  static int MakeCurrent (vlc_gl_t *gl)
> @@ -101,8 +106,12 @@ static void SwapBuffers (vlc_gl_t *gl)
> 
>  static void *GetSymbol(vlc_gl_t *gl, const char *procname)
>  {
> -    (void) gl;
> -    return (void *)eglGetProcAddress (procname);
> +    vlc_gl_sys_t *sys = gl->sys;
> +
> +    if (sys->is_gles)
> +        return dlsym(sys->gles_handle, procname);
> +    else
> +        return (void *)eglGetProcAddress (procname);
>  }
> 
>  static const char *QueryString(vlc_gl_t *gl, int32_t name)
> @@ -220,6 +229,10 @@ static void Close (vlc_object_t *obj)
>      AWindowHandler_releaseANativeWindow(gl->surface->handle.anativewindow,
>                                          AWindow_Video);
>  #endif
> +
> +    if (sys->is_gles && sys->gles_handle != NULL)
> +        dlclose(sys->gles_handle);
> +
>      free (sys);
>  }
> 
> @@ -238,6 +251,8 @@ static int Open (vlc_object_t *obj, const struct gl_api
> *api) sys->surface = EGL_NO_SURFACE;
>      sys->eglCreateImageKHR = NULL;
>      sys->eglDestroyImageKHR = NULL;
> +    sys->is_gles = api->api == EGL_OPENGL_ES_API;
> +    sys->gles_handle = NULL;
> 
>      vout_window_t *wnd = gl->surface;
>      EGLSurface (*createSurface)(EGLDisplay, EGLConfig, void *, const EGLint
> *) @@ -392,6 +407,15 @@ static int Open (vlc_object_t *obj, const struct
> gl_api *api) }
>      sys->context = ctx;
> 
> +    if (sys->is_gles) {
> +        sys->gles_handle = dlopen(LIBGLESv2_DL_NAME, RTLD_NOW);
> +	if (sys->gles_handle == NULL)
> +        {
> +            msg_Err (obj, "cannot get GLES library handle from dlopen");
> +            goto error;
> +        }
> +    }
> +
>      /* Initialize OpenGL callbacks */
>      gl->ext = VLC_GL_EXT_EGL;
>      gl->makeCurrent = MakeCurrent;


-- 
レミ・デニ-クールモン
http://www.remlab.net/





More information about the vlc-devel mailing list