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.
This commit is contained in:
wm4 2017-04-06 14:50:19 +02:00
parent 4e6867c771
commit c9d3a79187
8 changed files with 40 additions and 42 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -15,6 +15,12 @@
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#if HAVE_LIBDL
#include <dlfcn.h>
#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);
}

View File

@ -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