summaryrefslogtreecommitdiffstats
path: root/video/out/opengl
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-09-25 00:18:05 +0200
committerwm4 <wm4@nowhere>2015-09-25 00:20:11 +0200
commit0e9cfa6b642266af66cba59a259e0edef44d60f0 (patch)
tree66ad0a2d4805efa78eb9534d0fe308718a38edc8 /video/out/opengl
parentd47dff3faa246256d9e29daa215db4b5aedcb3f2 (diff)
downloadmpv-0e9cfa6b642266af66cba59a259e0edef44d60f0.tar.bz2
mpv-0e9cfa6b642266af66cba59a259e0edef44d60f0.tar.xz
vo_opengl: add mechanism to retrieve Display from EGL context
The VAAPI EGL interop code will need access to the X11 Display. While GLX could return it from the current GLX context, EGL has no such mechanism. (At least no standard one supported by all implementations.) So mpv makes up such a mechanism. For internal purposes, this is very rather awkward solution, but it's needed for libmpv anyway.
Diffstat (limited to 'video/out/opengl')
-rw-r--r--video/out/opengl/x11egl.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/video/out/opengl/x11egl.c b/video/out/opengl/x11egl.c
index 53cd5ae677..87e0e89fff 100644
--- a/video/out/opengl/x11egl.c
+++ b/video/out/opengl/x11egl.c
@@ -20,6 +20,8 @@
* version 2.1 of the License, or (at your option) any later version.
*/
+#include <assert.h>
+
#include <X11/Xlib.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
@@ -29,11 +31,21 @@
#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 EGLConfig select_fb_config_egl(struct MPGLContext *ctx, bool es)
{
struct priv *p = ctx->priv;
@@ -99,6 +111,8 @@ static bool config_window_x11_egl(struct MPGLContext *ctx, int flags)
struct vo *vo = ctx->vo;
bool es = flags & VOFLAG_GLES;
+ p->x_display = vo->x11->display;
+
if (!eglBindAPI(es ? EGL_OPENGL_ES_API : EGL_OPENGL_API)) {
MP_FATAL(vo, "Could not bind API (%s).\n", es ? "GLES" : "GL");
return false;
@@ -138,7 +152,10 @@ static bool config_window_x11_egl(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;
return true;
}
@@ -171,6 +188,7 @@ 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);
}