vo_opengl: refactor EGL context information callback

Move the ugliness from x11egl.c to common.c, so that the ugliness
doesn't have to be duplicated in wayland.c.
This commit is contained in:
wm4 2015-09-27 21:20:46 +02:00
parent 710872bc22
commit 1fa674c109
5 changed files with 36 additions and 17 deletions

View File

@ -966,6 +966,7 @@ cat > $TMPC << EOF
#define HAVE_VIDEOTOOLBOX_GL 0
#define HAVE_VIDEOTOOLBOX_VDA_GL 0
#define HAVE_SSE4_INTRINSICS 1
#define HAVE_C11_TLS 1
#ifdef __OpenBSD__
#define DEFAULT_CDROM_DEVICE "/dev/rcd0c"

View File

@ -555,6 +555,29 @@ int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
return mpgl_find_backend(s) >= -1 ? 1 : M_OPT_INVALID;
}
#if HAVE_C11_TLS
static _Thread_local MPGLContext *current_context;
static void * GLAPIENTRY get_native_display(const char *name)
{
if (current_context && current_context->native_display_type &&
name && strcmp(current_context->native_display_type, name) == 0)
return current_context->native_display;
return NULL;
}
static void set_current_context(MPGLContext *context)
{
current_context = context;
if (context && !context->gl->MPGetNativeDisplay)
context->gl->MPGetNativeDisplay = get_native_display;
}
#else
static void set_current_context(MPGLContext *context)
{
}
#endif
static MPGLContext *init_backend(struct vo *vo, const struct backend *backend,
bool probing, int vo_flags)
{
@ -602,6 +625,8 @@ static MPGLContext *init_backend(struct vo *vo, const struct backend *backend,
ctx->gl->debug_context = !!(vo_flags & VOFLAG_GL_DEBUG);
set_current_context(ctx);
return ctx;
cleanup:
@ -657,6 +682,7 @@ void mpgl_swap_buffers(struct MPGLContext *ctx)
void mpgl_uninit(MPGLContext *ctx)
{
set_current_context(NULL);
if (ctx) {
if (ctx->driver) {
ctx->driver->uninit(ctx);

View File

@ -115,6 +115,10 @@ typedef struct MPGLContext {
// Bit size of each component in the created framebuffer. 0 if unknown.
int depth_r, depth_g, depth_b;
// For hwdec_vaegl.c.
const char *native_display_type;
void *native_display;
// For free use by the mpgl_driver.
void *priv;

View File

@ -31,21 +31,11 @@
#include "common.h"
struct priv {
Display *x_display;
EGLDisplay egl_display;
EGLContext egl_context;
EGLSurface egl_surface;
};
static _Thread_local struct priv *current_context;
static void * GLAPIENTRY get_native_display(const char *name)
{
if (current_context && strcmp(name, "x11") == 0)
return current_context->x_display;
return NULL;
}
static void mpegl_uninit(MPGLContext *ctx)
{
struct priv *p = ctx->priv;
@ -55,7 +45,6 @@ static void mpegl_uninit(MPGLContext *ctx)
eglDestroyContext(p->egl_display, p->egl_context);
}
p->egl_context = EGL_NO_CONTEXT;
current_context = NULL;
vo_x11_uninit(ctx->vo);
}
@ -128,8 +117,6 @@ static int mpegl_init(struct MPGLContext *ctx, int flags)
if (!vo_x11_init(vo))
goto uninit;
p->x_display = vo->x11->display;
if (!eglBindAPI(es ? EGL_OPENGL_ES_API : EGL_OPENGL_API)) {
mp_msg(vo->log, msgl, "Could not bind API (%s).\n", es ? "GLES" : "GL");
goto uninit;
@ -166,10 +153,10 @@ static int mpegl_init(struct MPGLContext *ctx, int flags)
void *(*gpa)(const GLubyte*) = (void *(*)(const GLubyte*))eglGetProcAddress;
mpgl_load_functions(ctx->gl, gpa, egl_exts, vo->log);
ctx->gl->MPGetNativeDisplay = get_native_display;
assert(!current_context);
current_context = p;
ctx->native_display_type = "x11";
ctx->native_display = vo->x11->display;
return true;
uninit:

View File

@ -609,7 +609,7 @@ video_output_features = [
} , {
'name': '--egl-x11',
'desc': 'OpenGL X11 EGL Backend',
'deps': [ 'x11', 'c11-tls' ],
'deps': [ 'x11' ],
'groups': [ 'gl' ],
'func': check_pkg_config('egl', 'gl'),
} , {
@ -665,6 +665,7 @@ video_output_features = [
}, {
'name': 'vaapi-egl',
'desc': 'VAAPI EGL',
'deps': [ 'c11-tls' ], # indirectly
'deps_any': [ 'vaapi-x-egl' ],
'func': check_true,
}, {