1
mirror of https://github.com/mpv-player/mpv synced 2024-11-14 22:48:35 +01:00

vo_opengl: drop old backend API

This commit is contained in:
wm4 2015-10-02 18:43:45 +02:00
parent e87f705497
commit e72ca08554
3 changed files with 26 additions and 87 deletions

View File

@ -490,14 +490,6 @@ void mpgl_load_functions(GL *gl, void *(*getProcAddress)(const GLubyte *),
mpgl_load_functions2(gl, get_procaddr_wrapper, getProcAddress, ext2, log); mpgl_load_functions2(gl, get_procaddr_wrapper, getProcAddress, ext2, log);
} }
typedef void (*MPGLSetBackendFn)(MPGLContext *ctx);
struct backend {
const char *name;
MPGLSetBackendFn init;
const struct mpgl_driver *driver;
};
extern const struct mpgl_driver mpgl_driver_x11; extern const struct mpgl_driver mpgl_driver_x11;
extern const struct mpgl_driver mpgl_driver_x11egl; extern const struct mpgl_driver mpgl_driver_x11egl;
extern const struct mpgl_driver mpgl_driver_cocoa; extern const struct mpgl_driver mpgl_driver_cocoa;
@ -505,26 +497,24 @@ extern const struct mpgl_driver mpgl_driver_wayland;
extern const struct mpgl_driver mpgl_driver_w32; extern const struct mpgl_driver mpgl_driver_w32;
extern const struct mpgl_driver mpgl_driver_rpi; extern const struct mpgl_driver mpgl_driver_rpi;
static const struct backend backends[] = { static const struct mpgl_driver *const backends[] = {
#if HAVE_RPI #if HAVE_RPI
{.driver = &mpgl_driver_rpi}, &mpgl_driver_rpi,
#endif #endif
#if HAVE_GL_COCOA #if HAVE_GL_COCOA
{.driver = &mpgl_driver_cocoa}, &mpgl_driver_cocoa,
#endif #endif
#if HAVE_GL_WIN32 #if HAVE_GL_WIN32
{.driver = &mpgl_driver_w32}, &mpgl_driver_w32,
#endif #endif
//Add the wayland backend before x11, in order to probe for a wayland-server before a x11-server and avoid using xwayland
#if HAVE_GL_WAYLAND #if HAVE_GL_WAYLAND
{.driver = &mpgl_driver_wayland}, &mpgl_driver_wayland,
#endif #endif
#if HAVE_EGL_X11 #if HAVE_EGL_X11
{.driver = &mpgl_driver_x11egl}, &mpgl_driver_x11egl,
#endif #endif
#if HAVE_GL_X11 #if HAVE_GL_X11
{.driver = &mpgl_driver_x11}, &mpgl_driver_x11,
#endif #endif
}; };
@ -533,10 +523,8 @@ int mpgl_find_backend(const char *name)
if (name == NULL || strcmp(name, "auto") == 0) if (name == NULL || strcmp(name, "auto") == 0)
return -1; return -1;
for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) { for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
const struct backend *entry = &backends[n]; if (strcmp(backends[n]->name, name) == 0)
const char *ename = entry->driver ? entry->driver->name : entry->name; return n;
if (strcmp(ename, name) == 0)
return entry - backends;
} }
return -2; return -2;
} }
@ -547,11 +535,8 @@ int mpgl_validate_backend_opt(struct mp_log *log, const struct m_option *opt,
if (bstr_equals0(param, "help")) { if (bstr_equals0(param, "help")) {
mp_info(log, "OpenGL windowing backends:\n"); mp_info(log, "OpenGL windowing backends:\n");
mp_info(log, " auto (autodetect)\n"); mp_info(log, " auto (autodetect)\n");
for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) { for (int n = 0; n < MP_ARRAY_SIZE(backends); n++)
const struct backend *entry = &backends[n]; mp_info(log, " %s\n", backends[n]->name);
const char *ename = entry->driver ? entry->driver->name : entry->name;
mp_info(log, " %s\n", ename);
}
return M_OPT_EXIT - 1; return M_OPT_EXIT - 1;
} }
char s[20]; char s[20];
@ -582,37 +567,25 @@ static void set_current_context(MPGLContext *context)
} }
#endif #endif
static MPGLContext *init_backend(struct vo *vo, const struct backend *backend, static MPGLContext *init_backend(struct vo *vo, const struct mpgl_driver *driver,
bool probing, int vo_flags) bool probing, int vo_flags)
{ {
MPGLContext *ctx = talloc_ptrtype(NULL, ctx); MPGLContext *ctx = talloc_ptrtype(NULL, ctx);
*ctx = (MPGLContext) { *ctx = (MPGLContext) {
.gl = talloc_zero(ctx, GL), .gl = talloc_zero(ctx, GL),
.vo = vo, .vo = vo,
.driver = backend->driver, .driver = driver,
}; };
bool old_probing = vo->probing; bool old_probing = vo->probing;
vo->probing = probing; // hack; kill it once backends are separate vo->probing = probing; // hack; kill it once backends are separate
if (ctx->driver) {
MP_VERBOSE(vo, "Initializing OpenGL backend '%s'\n", ctx->driver->name); MP_VERBOSE(vo, "Initializing OpenGL backend '%s'\n", ctx->driver->name);
ctx->priv = talloc_zero_size(ctx, ctx->driver->priv_size); ctx->priv = talloc_zero_size(ctx, ctx->driver->priv_size);
if (ctx->driver->init(ctx, vo_flags) < 0) { if (ctx->driver->init(ctx, vo_flags) < 0) {
talloc_free(ctx); talloc_free(ctx);
return NULL; return NULL;
} }
} else {
MP_VERBOSE(vo, "Initializing OpenGL backend '%s'\n", backend->name);
backend->init(ctx);
if (!ctx->vo_init(vo)) {
talloc_free(ctx);
return NULL;
}
}
vo->probing = old_probing; vo->probing = old_probing;
if (!ctx->driver && !ctx->config_window(ctx, vo_flags | VOFLAG_HIDDEN))
goto cleanup;
if (!ctx->gl->version && !ctx->gl->es) if (!ctx->gl->version && !ctx->gl->es)
goto cleanup; goto cleanup;
@ -646,12 +619,12 @@ MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags)
int index = mpgl_find_backend(backend_name); int index = mpgl_find_backend(backend_name);
if (index == -1) { if (index == -1) {
for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) { for (int n = 0; n < MP_ARRAY_SIZE(backends); n++) {
ctx = init_backend(vo, &backends[n], true, vo_flags); ctx = init_backend(vo, backends[n], true, vo_flags);
if (ctx) if (ctx)
break; break;
} }
} else if (index >= 0) { } else if (index >= 0) {
ctx = init_backend(vo, &backends[index], false, vo_flags); ctx = init_backend(vo, backends[index], false, vo_flags);
} }
return ctx; return ctx;
} }
@ -659,41 +632,23 @@ MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags)
// flags: passed to the backend function // flags: passed to the backend function
bool mpgl_reconfig_window(struct MPGLContext *ctx, int vo_flags) bool mpgl_reconfig_window(struct MPGLContext *ctx, int vo_flags)
{ {
if (ctx->driver) {
return ctx->driver->reconfig(ctx, vo_flags) >= 0; return ctx->driver->reconfig(ctx, vo_flags) >= 0;
} else {
return ctx->config_window(ctx, vo_flags);
}
} }
int mpgl_control(struct MPGLContext *ctx, int *events, int request, void *arg) int mpgl_control(struct MPGLContext *ctx, int *events, int request, void *arg)
{ {
if (ctx->driver) {
return ctx->driver->control(ctx, events, request, arg); return ctx->driver->control(ctx, events, request, arg);
} else {
return ctx->vo_control(ctx->vo, events, request, arg);
}
} }
void mpgl_swap_buffers(struct MPGLContext *ctx) void mpgl_swap_buffers(struct MPGLContext *ctx)
{ {
if (ctx->driver) {
ctx->driver->swap_buffers(ctx); ctx->driver->swap_buffers(ctx);
} else {
ctx->swapGlBuffers(ctx);
}
} }
void mpgl_uninit(MPGLContext *ctx) void mpgl_uninit(MPGLContext *ctx)
{ {
set_current_context(NULL); set_current_context(NULL);
if (ctx) { if (ctx)
if (ctx->driver) {
ctx->driver->uninit(ctx); ctx->driver->uninit(ctx);
} else {
ctx->releaseGlContext(ctx);
ctx->vo_uninit(ctx->vo);
}
}
talloc_free(ctx); talloc_free(ctx);
} }

View File

@ -76,9 +76,7 @@ enum {
struct MPGLContext; struct MPGLContext;
// A backend (like X11, win32, ...), which provides OpenGL rendering. // A windowing backend (like X11, win32, ...), which provides OpenGL rendering.
// This should be preferred for new code, instead of setting the callbacks
// in MPGLContext directly.
struct mpgl_driver { struct mpgl_driver {
const char *name; const char *name;
@ -124,19 +122,6 @@ typedef struct MPGLContext {
// For free use by the mpgl_driver. // For free use by the mpgl_driver.
void *priv; void *priv;
// Warning: all callbacks below are legacy. Newer code should use
// a mpgl_driver struct, which replaces these callbacks.
void (*swapGlBuffers)(struct MPGLContext *);
int (*vo_init)(struct vo *vo);
void (*vo_uninit)(struct vo *vo);
int (*vo_control)(struct vo *vo, int *events, int request, void *arg);
void (*releaseGlContext)(struct MPGLContext *);
// Resize the window, or create a new window if there isn't one yet.
// On the first call, it creates a GL context.
bool (*config_window)(struct MPGLContext *ctx, int flags);
} MPGLContext; } MPGLContext;
MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags); MPGLContext *mpgl_init(struct vo *vo, const char *backend_name, int vo_flags);

View File

@ -130,7 +130,6 @@ struct voctrl_get_equalizer_args {
#define VO_NOTAVAIL -2 #define VO_NOTAVAIL -2
#define VO_NOTIMPL -3 #define VO_NOTIMPL -3
#define VOFLAG_HIDDEN 0x10 //< Use to create a hidden window
#define VOFLAG_GLES 0x20 // Hint to prefer GLES2 if possible #define VOFLAG_GLES 0x20 // Hint to prefer GLES2 if possible
#define VOFLAG_GL_DEBUG 0x40 // Hint to request debug OpenGL context #define VOFLAG_GL_DEBUG 0x40 // Hint to request debug OpenGL context
#define VOFLAG_ALPHA 0x80 // Hint to request alpha framebuffer #define VOFLAG_ALPHA 0x80 // Hint to request alpha framebuffer