summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-09-27 21:20:46 +0200
committerwm4 <wm4@nowhere>2015-09-27 21:34:11 +0200
commit1fa674c109c05e082bf0fb43be064cbdabea3327 (patch)
tree9a4c109856a68c2795680f156aa394db5ba3ca2b
parent710872bc22c772d1ea8eb9a0383f5755dae08698 (diff)
downloadmpv-1fa674c109c05e082bf0fb43be064cbdabea3327.tar.bz2
mpv-1fa674c109c05e082bf0fb43be064cbdabea3327.tar.xz
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.
-rwxr-xr-xTOOLS/old-configure1
-rw-r--r--video/out/opengl/common.c26
-rw-r--r--video/out/opengl/common.h4
-rw-r--r--video/out/opengl/x11egl.c19
-rw-r--r--wscript3
5 files changed, 36 insertions, 17 deletions
diff --git a/TOOLS/old-configure b/TOOLS/old-configure
index a55e776da3..d5826ebc55 100755
--- a/TOOLS/old-configure
+++ b/TOOLS/old-configure
@@ -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"
diff --git a/video/out/opengl/common.c b/video/out/opengl/common.c
index 640a357b12..7fced42d01 100644
--- a/video/out/opengl/common.c
+++ b/video/out/opengl/common.c
@@ -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);
diff --git a/video/out/opengl/common.h b/video/out/opengl/common.h
index 0e3566d689..a7dfb65be1 100644
--- a/video/out/opengl/common.h
+++ b/video/out/opengl/common.h
@@ -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;
diff --git a/video/out/opengl/x11egl.c b/video/out/opengl/x11egl.c
index b196b7d9f4..13901860f8 100644
--- a/video/out/opengl/x11egl.c
+++ b/video/out/opengl/x11egl.c
@@ -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:
diff --git a/wscript b/wscript
index abccafdf36..f7cc62e211 100644
--- a/wscript
+++ b/wscript
@@ -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,
}, {