From c9d3a79187a9a45ecae8e97af9b68427d1f06eac Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 6 Apr 2017 14:50:19 +0200 Subject: vo_opengl: add a generic EGL function loader function This is pretty trivial, but also quite annoying due to details like mismatching eglGetProcAddress() function signature (most callers just cast the function pointer), and ARM/Linux hacks. So move them all to one place. --- video/out/opengl/context_angle.c | 7 +------ video/out/opengl/context_drm_egl.c | 4 +--- video/out/opengl/context_mali_fbdev.c | 13 +------------ video/out/opengl/context_rpi.c | 13 +------------ video/out/opengl/context_wayland.c | 6 +----- video/out/opengl/context_x11egl.c | 5 +---- video/out/opengl/egl_helpers.c | 31 +++++++++++++++++++++++++++++++ video/out/opengl/egl_helpers.h | 3 +++ 8 files changed, 40 insertions(+), 42 deletions(-) diff --git a/video/out/opengl/context_angle.c b/video/out/opengl/context_angle.c index 062835da30..3e227f93f8 100644 --- a/video/out/opengl/context_angle.c +++ b/video/out/opengl/context_angle.c @@ -623,11 +623,6 @@ static int GLAPIENTRY angle_swap_interval(int interval) } } -static void *get_proc_address(const GLubyte *proc_name) -{ - return eglGetProcAddress(proc_name); -} - static int angle_init(struct MPGLContext *ctx, int flags) { struct priv *p = ctx->priv; @@ -709,7 +704,7 @@ static int angle_init(struct MPGLContext *ctx, int flags) if (!surface_ok) goto fail; - mpgl_load_functions(ctx->gl, get_proc_address, NULL, vo->log); + mpegl_load_functions(ctx->gl, vo->log); current_ctx = ctx; ctx->gl->SwapInterval = angle_swap_interval; diff --git a/video/out/opengl/context_drm_egl.c b/video/out/opengl/context_drm_egl.c index cf23423619..1852cb76fa 100644 --- a/video/out/opengl/context_drm_egl.c +++ b/video/out/opengl/context_drm_egl.c @@ -307,9 +307,7 @@ static int drm_egl_init(struct MPGLContext *ctx, int flags) return -1; } - const char *egl_exts = eglQueryString(p->egl.display, EGL_EXTENSIONS); - void *(*gpa)(const GLubyte*) = (void *(*)(const GLubyte*))eglGetProcAddress; - mpgl_load_functions(ctx->gl, gpa, egl_exts, ctx->vo->log); + mpegl_load_functions(ctx->gl, ctx->vo->log); ctx->native_display_type = "drm"; ctx->native_display = (void *)(intptr_t)p->kms->fd; diff --git a/video/out/opengl/context_mali_fbdev.c b/video/out/opengl/context_mali_fbdev.c index e76d220939..66daa7f9ee 100644 --- a/video/out/opengl/context_mali_fbdev.c +++ b/video/out/opengl/context_mali_fbdev.c @@ -49,16 +49,6 @@ static bool get_fbdev_size(int *w, int *h) return ok; } -static void *get_proc_address(const GLubyte *name) -{ - void *p = eglGetProcAddress(name); - // EGL 1.4 (supported by the MALI drivers) does not necessarily return - // function pointers for core functions. - if (!p) - p = dlsym(RTLD_DEFAULT, name); - return p; -} - struct priv { struct mp_log *log; struct GL *gl; @@ -127,8 +117,7 @@ static int mali_init(struct MPGLContext *ctx, int flags) ctx->gl = talloc_zero(ctx, GL); - const char *exts = eglQueryString(p->egl_display, EGL_EXTENSIONS); - mpgl_load_functions(ctx->gl, get_proc_address, exts, p->log); + mpegl_load_functions(ctx->gl, p->log); return 0; diff --git a/video/out/opengl/context_rpi.c b/video/out/opengl/context_rpi.c index fa19a6c205..e79622be5d 100644 --- a/video/out/opengl/context_rpi.c +++ b/video/out/opengl/context_rpi.c @@ -208,16 +208,6 @@ fail: return -1; } -static void *get_proc_address(const GLubyte *name) -{ - void *p = eglGetProcAddress(name); - // EGL 1.4 (supported by the RPI firmware) does not necessarily return - // function pointers for core functions. - if (!p) - p = dlsym(RTLD_DEFAULT, name); - return p; -} - static int rpi_init(struct MPGLContext *ctx, int flags) { struct priv *p = ctx->priv; @@ -242,8 +232,7 @@ static int rpi_init(struct MPGLContext *ctx, int flags) ctx->gl = talloc_zero(ctx, GL); - const char *exts = eglQueryString(p->egl_display, EGL_EXTENSIONS); - mpgl_load_functions(ctx->gl, get_proc_address, exts, p->log); + mpegl_load_functions(ctx->gl, p->log); ctx->native_display_type = "MPV_RPI_WINDOW"; ctx->native_display = p->win_params; diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index 127ddcaa93..87e98cd64f 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -67,7 +67,6 @@ static int egl_create_context(struct vo_wayland_state *wl, MPGLContext *ctx, int flags) { GL *gl = ctx->gl; - const char *eglstr = ""; if (!(wl->egl_context.egl.dpy = eglGetDisplay(wl->display.display))) return -1; @@ -82,10 +81,7 @@ static int egl_create_context(struct vo_wayland_state *wl, MPGLContext *ctx, eglMakeCurrent(wl->egl_context.egl.dpy, NULL, NULL, wl->egl_context.egl.ctx); - eglstr = eglQueryString(wl->egl_context.egl.dpy, EGL_EXTENSIONS); - - mpgl_load_functions(gl, (void*(*)(const GLubyte*))eglGetProcAddress, eglstr, - wl->log); + mpegl_load_functions(gl, wl->log); ctx->native_display_type = "wl"; ctx->native_display = wl->display.display; diff --git a/video/out/opengl/context_x11egl.c b/video/out/opengl/context_x11egl.c index 2cf249fe1a..2b68007a33 100644 --- a/video/out/opengl/context_x11egl.c +++ b/video/out/opengl/context_x11egl.c @@ -131,10 +131,7 @@ static int mpegl_init(struct MPGLContext *ctx, int flags) goto uninit; } - const char *egl_exts = eglQueryString(p->egl_display, EGL_EXTENSIONS); - - void *(*gpa)(const GLubyte*) = (void *(*)(const GLubyte*))eglGetProcAddress; - mpgl_load_functions(ctx->gl, gpa, egl_exts, vo->log); + mpegl_load_functions(ctx->gl, vo->log); ctx->native_display_type = "x11"; ctx->native_display = vo->x11->display; diff --git a/video/out/opengl/egl_helpers.c b/video/out/opengl/egl_helpers.c index d1ebd9aeca..ac152df06a 100644 --- a/video/out/opengl/egl_helpers.c +++ b/video/out/opengl/egl_helpers.c @@ -15,6 +15,12 @@ * License along with mpv. If not, see . */ +#include "config.h" + +#if HAVE_LIBDL +#include +#endif + #include "common/common.h" #include "egl_helpers.h" @@ -199,3 +205,28 @@ bool mpegl_create_context_opts(EGLDisplay display, struct mp_log *log, return false; } +static void *mpegl_get_proc_address(void *ctx, const char *name) +{ + void *p = eglGetProcAddress(name); +#if defined(__GLIBC__) && HAVE_LIBDL + // Some crappy ARM/Linux things do not provide EGL 1.5, so above call does + // not necessarily return function pointers for core functions. Try to get + // them from a loaded GLES lib. As POSIX leaves RTLD_DEFAULT "reserved", + // use it only with glibc. + if (!p) + p = dlsym(RTLD_DEFAULT, name); +#endif + return p; +} + +// Load gl version and function pointers into *gl. +// Expects a current EGL context set. +void mpegl_load_functions(struct GL *gl, struct mp_log *log) +{ + const char *egl_exts = ""; + EGLDisplay display = eglGetCurrentDisplay(); + if (display != EGL_NO_DISPLAY) + egl_exts = eglQueryString(display, EGL_EXTENSIONS); + + mpgl_load_functions2(gl, mpegl_get_proc_address, NULL, egl_exts, log); +} diff --git a/video/out/opengl/egl_helpers.h b/video/out/opengl/egl_helpers.h index ea751d4c5e..05f9dccb70 100644 --- a/video/out/opengl/egl_helpers.h +++ b/video/out/opengl/egl_helpers.h @@ -27,4 +27,7 @@ bool mpegl_create_context_opts(EGLDisplay display, struct mp_log *log, struct mpegl_opts *opts, EGLContext *out_context, EGLConfig *out_config); +struct GL; +void mpegl_load_functions(struct GL *gl, struct mp_log *log); + #endif -- cgit v1.2.3