mirror of https://github.com/mpv-player/mpv
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:
parent
710872bc22
commit
1fa674c109
|
@ -966,6 +966,7 @@ cat > $TMPC << EOF
|
||||||
#define HAVE_VIDEOTOOLBOX_GL 0
|
#define HAVE_VIDEOTOOLBOX_GL 0
|
||||||
#define HAVE_VIDEOTOOLBOX_VDA_GL 0
|
#define HAVE_VIDEOTOOLBOX_VDA_GL 0
|
||||||
#define HAVE_SSE4_INTRINSICS 1
|
#define HAVE_SSE4_INTRINSICS 1
|
||||||
|
#define HAVE_C11_TLS 1
|
||||||
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
#define DEFAULT_CDROM_DEVICE "/dev/rcd0c"
|
#define DEFAULT_CDROM_DEVICE "/dev/rcd0c"
|
||||||
|
|
|
@ -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;
|
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,
|
static MPGLContext *init_backend(struct vo *vo, const struct backend *backend,
|
||||||
bool probing, int vo_flags)
|
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);
|
ctx->gl->debug_context = !!(vo_flags & VOFLAG_GL_DEBUG);
|
||||||
|
|
||||||
|
set_current_context(ctx);
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -657,6 +682,7 @@ void mpgl_swap_buffers(struct MPGLContext *ctx)
|
||||||
|
|
||||||
void mpgl_uninit(MPGLContext *ctx)
|
void mpgl_uninit(MPGLContext *ctx)
|
||||||
{
|
{
|
||||||
|
set_current_context(NULL);
|
||||||
if (ctx) {
|
if (ctx) {
|
||||||
if (ctx->driver) {
|
if (ctx->driver) {
|
||||||
ctx->driver->uninit(ctx);
|
ctx->driver->uninit(ctx);
|
||||||
|
|
|
@ -115,6 +115,10 @@ typedef struct MPGLContext {
|
||||||
// Bit size of each component in the created framebuffer. 0 if unknown.
|
// Bit size of each component in the created framebuffer. 0 if unknown.
|
||||||
int depth_r, depth_g, depth_b;
|
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.
|
// For free use by the mpgl_driver.
|
||||||
void *priv;
|
void *priv;
|
||||||
|
|
||||||
|
|
|
@ -31,21 +31,11 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
struct priv {
|
struct priv {
|
||||||
Display *x_display;
|
|
||||||
EGLDisplay egl_display;
|
EGLDisplay egl_display;
|
||||||
EGLContext egl_context;
|
EGLContext egl_context;
|
||||||
EGLSurface egl_surface;
|
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)
|
static void mpegl_uninit(MPGLContext *ctx)
|
||||||
{
|
{
|
||||||
struct priv *p = ctx->priv;
|
struct priv *p = ctx->priv;
|
||||||
|
@ -55,7 +45,6 @@ static void mpegl_uninit(MPGLContext *ctx)
|
||||||
eglDestroyContext(p->egl_display, p->egl_context);
|
eglDestroyContext(p->egl_display, p->egl_context);
|
||||||
}
|
}
|
||||||
p->egl_context = EGL_NO_CONTEXT;
|
p->egl_context = EGL_NO_CONTEXT;
|
||||||
current_context = NULL;
|
|
||||||
vo_x11_uninit(ctx->vo);
|
vo_x11_uninit(ctx->vo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,8 +117,6 @@ static int mpegl_init(struct MPGLContext *ctx, int flags)
|
||||||
if (!vo_x11_init(vo))
|
if (!vo_x11_init(vo))
|
||||||
goto uninit;
|
goto uninit;
|
||||||
|
|
||||||
p->x_display = vo->x11->display;
|
|
||||||
|
|
||||||
if (!eglBindAPI(es ? EGL_OPENGL_ES_API : EGL_OPENGL_API)) {
|
if (!eglBindAPI(es ? EGL_OPENGL_ES_API : EGL_OPENGL_API)) {
|
||||||
mp_msg(vo->log, msgl, "Could not bind API (%s).\n", es ? "GLES" : "GL");
|
mp_msg(vo->log, msgl, "Could not bind API (%s).\n", es ? "GLES" : "GL");
|
||||||
goto uninit;
|
goto uninit;
|
||||||
|
@ -166,10 +153,10 @@ static int mpegl_init(struct MPGLContext *ctx, int flags)
|
||||||
|
|
||||||
void *(*gpa)(const GLubyte*) = (void *(*)(const GLubyte*))eglGetProcAddress;
|
void *(*gpa)(const GLubyte*) = (void *(*)(const GLubyte*))eglGetProcAddress;
|
||||||
mpgl_load_functions(ctx->gl, gpa, egl_exts, vo->log);
|
mpgl_load_functions(ctx->gl, gpa, egl_exts, vo->log);
|
||||||
ctx->gl->MPGetNativeDisplay = get_native_display;
|
|
||||||
|
|
||||||
assert(!current_context);
|
ctx->native_display_type = "x11";
|
||||||
current_context = p;
|
ctx->native_display = vo->x11->display;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
uninit:
|
uninit:
|
||||||
|
|
3
wscript
3
wscript
|
@ -609,7 +609,7 @@ video_output_features = [
|
||||||
} , {
|
} , {
|
||||||
'name': '--egl-x11',
|
'name': '--egl-x11',
|
||||||
'desc': 'OpenGL X11 EGL Backend',
|
'desc': 'OpenGL X11 EGL Backend',
|
||||||
'deps': [ 'x11', 'c11-tls' ],
|
'deps': [ 'x11' ],
|
||||||
'groups': [ 'gl' ],
|
'groups': [ 'gl' ],
|
||||||
'func': check_pkg_config('egl', 'gl'),
|
'func': check_pkg_config('egl', 'gl'),
|
||||||
} , {
|
} , {
|
||||||
|
@ -665,6 +665,7 @@ video_output_features = [
|
||||||
}, {
|
}, {
|
||||||
'name': 'vaapi-egl',
|
'name': 'vaapi-egl',
|
||||||
'desc': 'VAAPI EGL',
|
'desc': 'VAAPI EGL',
|
||||||
|
'deps': [ 'c11-tls' ], # indirectly
|
||||||
'deps_any': [ 'vaapi-x-egl' ],
|
'deps_any': [ 'vaapi-x-egl' ],
|
||||||
'func': check_true,
|
'func': check_true,
|
||||||
}, {
|
}, {
|
||||||
|
|
Loading…
Reference in New Issue