summaryrefslogtreecommitdiffstats
path: root/video/out
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2014-11-26 20:48:11 +0100
committerwm4 <wm4@nowhere>2014-11-26 20:48:18 +0100
commit3fe57e3cb691d75dc8813c29cada5e3ddfd2a295 (patch)
tree93962472662b8d3c402d97cd3f78b91f2d0f4c89 /video/out
parent7e62f2b0527e2a4d96418b9d8009dd840a45df0c (diff)
downloadmpv-3fe57e3cb691d75dc8813c29cada5e3ddfd2a295.tar.bz2
mpv-3fe57e3cb691d75dc8813c29cada5e3ddfd2a295.tar.xz
gl_common: factor context creation
Always create the context in mpgl_init(), instead of doing it when mpgl_config_window() is called the first time. This is a small step towards cleaning up the GL backend interface, and adding other things like perhaps GLES support, or a callback-driven backend for libmpv.
Diffstat (limited to 'video/out')
-rw-r--r--video/out/gl_common.c21
-rw-r--r--video/out/gl_common.h10
-rw-r--r--video/out/vo_opengl.c39
-rw-r--r--video/out/vo_opengl_old.c31
4 files changed, 51 insertions, 50 deletions
diff --git a/video/out/gl_common.c b/video/out/gl_common.c
index 195ad72539..4d0a3c8dd4 100644
--- a/video/out/gl_common.c
+++ b/video/out/gl_common.c
@@ -930,7 +930,7 @@ static MPGLContext *init_backend(struct vo *vo, MPGLSetBackendFn set_backend,
return ctx;
}
-MPGLContext *mpgl_init(struct vo *vo, const char *backend_name)
+static MPGLContext *mpgl_create(struct vo *vo, const char *backend_name)
{
MPGLContext *ctx = NULL;
int index = mpgl_find_backend(backend_name);
@@ -946,17 +946,22 @@ MPGLContext *mpgl_init(struct vo *vo, const char *backend_name)
return ctx;
}
-bool mpgl_config_window(struct MPGLContext *ctx, int gl_caps, int flags)
+MPGLContext *mpgl_init(struct vo *vo, const char *backend_name,
+ int gl_caps, int vo_flags)
{
+ MPGLContext *ctx = mpgl_create(vo, backend_name);
+ if (!ctx)
+ return NULL;
+
gl_caps |= MPGL_CAP_GL;
ctx->requested_gl_version = (gl_caps & MPGL_CAP_GL_LEGACY)
? MPGL_VER(2, 1) : MPGL_VER(3, 0);
- if (ctx->config_window(ctx, flags)) {
+ if (ctx->config_window(ctx, vo_flags | VOFLAG_HIDDEN)) {
int missing = (ctx->gl->mpgl_caps & gl_caps) ^ gl_caps;
if (!missing)
- return true;
+ return ctx;
MP_WARN(ctx->vo, "Missing OpenGL features:");
list_features(missing, ctx->vo->log, MSGL_WARN, false);
@@ -970,7 +975,13 @@ bool mpgl_config_window(struct MPGLContext *ctx, int gl_caps, int flags)
}
MP_ERR(ctx->vo, "OpenGL context creation failed!\n");
- return false;
+ mpgl_uninit(ctx);
+ return NULL;
+}
+
+bool mpgl_reconfig_window(struct MPGLContext *ctx, int flags)
+{
+ return ctx->config_window(ctx, flags);
}
void mpgl_uninit(MPGLContext *ctx)
diff --git a/video/out/gl_common.h b/video/out/gl_common.h
index a8775ba09d..eb54ca41d2 100644
--- a/video/out/gl_common.h
+++ b/video/out/gl_common.h
@@ -136,9 +136,6 @@ typedef struct MPGLContext {
void *priv;
} MPGLContext;
-MPGLContext *mpgl_init(struct vo *vo, const char *backend_name);
-void mpgl_uninit(MPGLContext *ctx);
-
void mpgl_lock(MPGLContext *ctx);
void mpgl_unlock(MPGLContext *ctx);
void mpgl_set_context(MPGLContext *ctx);
@@ -150,7 +147,12 @@ bool mpgl_is_thread_safe(MPGLContext *ctx);
// gl_caps: bitfield of MPGL_CAP_* (required GL version and feature set)
// flags: passed to the backend's create window function
// Returns success.
-bool mpgl_config_window(struct MPGLContext *ctx, int gl_caps, int flags);
+MPGLContext *mpgl_init(struct vo *vo, const char *backend_name,
+ int gl_caps, int vo_flags);
+void mpgl_uninit(MPGLContext *ctx);
+
+// flags: passed to the backend function
+bool mpgl_reconfig_window(struct MPGLContext *ctx, int flags);
int mpgl_find_backend(const char *name);
diff --git a/video/out/vo_opengl.c b/video/out/vo_opengl.c
index 0c35ca3ee0..c7d274ec72 100644
--- a/video/out/vo_opengl.c
+++ b/video/out/vo_opengl.c
@@ -186,23 +186,6 @@ static int query_format(struct vo *vo, uint32_t format)
return caps;
}
-static bool config_window(struct gl_priv *p, int flags)
-{
- if (p->renderer_opts->stereo_mode == GL_3D_QUADBUFFER)
- flags |= VOFLAG_STEREO;
-
- if (p->renderer_opts->alpha_mode == 1)
- flags |= VOFLAG_ALPHA;
-
- if (p->use_gl_debug)
- flags |= VOFLAG_GL_DEBUG;
-
- int mpgl_caps = MPGL_CAP_GL21 | MPGL_CAP_TEX_RG;
- if (!p->allow_sw)
- mpgl_caps |= MPGL_CAP_NO_SW;
- return mpgl_config_window(p->glctx, mpgl_caps, flags);
-}
-
static void video_resize_redraw_callback(struct vo *vo, int w, int h)
{
struct gl_priv *p = vo->priv;
@@ -216,7 +199,7 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
mpgl_lock(p->glctx);
- if (!config_window(p, flags)) {
+ if (!mpgl_reconfig_window(p->glctx, flags)) {
mpgl_unlock(p->glctx);
return -1;
}
@@ -462,14 +445,26 @@ static int preinit(struct vo *vo)
struct gl_priv *p = vo->priv;
p->vo = vo;
- p->glctx = mpgl_init(vo, p->backend);
+ int vo_flags = 0;
+
+ if (p->renderer_opts->stereo_mode == GL_3D_QUADBUFFER)
+ vo_flags |= VOFLAG_STEREO;
+
+ if (p->renderer_opts->alpha_mode == 1)
+ vo_flags |= VOFLAG_ALPHA;
+
+ if (p->use_gl_debug)
+ vo_flags |= VOFLAG_GL_DEBUG;
+
+ int mpgl_caps = MPGL_CAP_GL21 | MPGL_CAP_TEX_RG;
+ if (!p->allow_sw)
+ mpgl_caps |= MPGL_CAP_NO_SW;
+
+ p->glctx = mpgl_init(vo, p->backend, mpgl_caps, vo_flags);
if (!p->glctx)
goto err_out;
p->gl = p->glctx->gl;
- if (!config_window(p, VOFLAG_HIDDEN))
- goto err_out;
-
mpgl_set_context(p->glctx);
if (p->gl->SwapInterval)
diff --git a/video/out/vo_opengl_old.c b/video/out/vo_opengl_old.c
index 91a14398d5..fb0831202e 100644
--- a/video/out/vo_opengl_old.c
+++ b/video/out/vo_opengl_old.c
@@ -1700,19 +1700,6 @@ static int initGl(struct vo *vo, uint32_t d_width, uint32_t d_height)
return 1;
}
-static bool config_window(struct vo *vo, int flags)
-{
- struct gl_priv *p = vo->priv;
-
- if (p->stereo_mode == GL_3D_QUADBUFFER)
- flags |= VOFLAG_STEREO;
-
- int mpgl_caps = MPGL_CAP_GL_LEGACY;
- if (!p->allow_sw)
- mpgl_caps |= MPGL_CAP_NO_SW;
- return mpgl_config_window(p->glctx, mpgl_caps, flags);
-}
-
static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
{
struct gl_priv *p = vo->priv;
@@ -1733,7 +1720,7 @@ static int reconfig(struct vo *vo, struct mp_image_params *params, int flags)
uninitGl(vo);
- if (!config_window(vo, flags))
+ if (!mpgl_reconfig_window(p->glctx, flags))
return -1;
initGl(vo, vo->dwidth, vo->dheight);
@@ -2085,16 +2072,22 @@ static int preinit(struct vo *vo)
p->use_yuv = 2;
}
- p->glctx = mpgl_init(vo, p->backend_arg);
+ int vo_flags = 0;
+
+ if (p->stereo_mode == GL_3D_QUADBUFFER)
+ vo_flags |= VOFLAG_STEREO;
+
+ int mpgl_caps = MPGL_CAP_GL_LEGACY;
+ if (!p->allow_sw)
+ mpgl_caps |= MPGL_CAP_NO_SW;
+
+ p->glctx = mpgl_init(vo, p->backend_arg, mpgl_caps, vo_flags);
if (!p->glctx)
goto err_out;
p->gl = p->glctx->gl;
- if (p->use_yuv == -1) {
- if (!config_window(vo, VOFLAG_HIDDEN))
- goto err_out;
+ if (p->use_yuv == -1)
autodetectGlExtensions(vo);
- }
MP_VERBOSE(vo, "Using %d as slice height "
"(0 means image height).\n", p->slice_height);