summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmil Velikov <emil.l.velikov@gmail.com>2021-10-02 21:22:46 +0100
committerDudemanguy <random342@airmail.cc>2021-10-16 20:33:53 +0000
commit538fb6541e621fd6eb1c0fe42bb88520e8e45dda (patch)
tree9cdf85b6194fe0ee154ba975309e15658661e324
parente3883512b119429004376cefff8a29043dbaff8d (diff)
downloadmpv-538fb6541e621fd6eb1c0fe42bb88520e8e45dda.tar.bz2
mpv-538fb6541e621fd6eb1c0fe42bb88520e8e45dda.tar.xz
video: opengl: rework and remove ra_gl_ctx_test_version()
The ra_gl_ctx_test_version() helper is quite clunky, in that it pushes a simple check too deep into the call chain. As such it makes it hard to reason, let alone have the GLX and EGL code paths symmetrical. Introduce a simple helper ra_gl_ctx_get_glesmode() which returns the current glesmode, so the platforms can clearly reason about should and should not be executed. v2: - mpgl_preferred_gl_versions -> mpgl_min_required_gl_versions - 320 -> 300 (in glx code path) Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
-rw-r--r--video/out/opengl/context.c24
-rw-r--r--video/out/opengl/context.h12
-rw-r--r--video/out/opengl/context_glx.c29
-rw-r--r--video/out/opengl/egl_helpers.c18
4 files changed, 37 insertions, 46 deletions
diff --git a/video/out/opengl/context.c b/video/out/opengl/context.c
index 325dc86f0f..59a7eda31c 100644
--- a/video/out/opengl/context.c
+++ b/video/out/opengl/context.c
@@ -34,12 +34,6 @@ enum {
FLUSH_AUTO,
};
-enum {
- GLES_AUTO = 0,
- GLES_YES,
- GLES_NO,
-};
-
struct opengl_opts {
int use_glfinish;
int waitvsync;
@@ -93,23 +87,17 @@ struct priv {
int num_vsync_fences;
};
-bool ra_gl_ctx_test_version(struct ra_ctx *ctx, int version, bool es)
+enum gles_mode ra_gl_ctx_get_glesmode(struct ra_ctx *ctx)
{
- bool ret;
- struct opengl_opts *opts;
void *tmp = talloc_new(NULL);
- opts = mp_get_config_group(tmp, ctx->global, &opengl_conf);
+ struct opengl_opts *opts;
+ enum gles_mode mode;
- switch (opts->gles_mode) {
- case GLES_YES: ret = es; goto done;
- case GLES_NO: ret = !es; goto done;
- case GLES_AUTO: ret = true; goto done;
- default: abort();
- }
+ opts = mp_get_config_group(tmp, ctx->global, &opengl_conf);
+ mode = opts->gles_mode;
-done:
talloc_free(tmp);
- return ret;
+ return mode;
}
void ra_gl_ctx_uninit(struct ra_ctx *ctx)
diff --git a/video/out/opengl/context.h b/video/out/opengl/context.h
index d78d17094c..222661ad83 100644
--- a/video/out/opengl/context.h
+++ b/video/out/opengl/context.h
@@ -6,10 +6,14 @@
extern const int mpgl_min_required_gl_versions[];
-// Returns whether or not a candidate GL version should be accepted or not
-// (based on the --opengl opts). Implementations may call this before
-// ra_gl_ctx_init if they wish to probe for multiple possible GL versions.
-bool ra_gl_ctx_test_version(struct ra_ctx *ctx, int version, bool es);
+enum gles_mode {
+ GLES_AUTO = 0,
+ GLES_YES,
+ GLES_NO,
+};
+
+// Returns the gles mode based on the --opengl opts.
+enum gles_mode ra_gl_ctx_get_glesmode(struct ra_ctx *ctx);
// These are a set of helpers for ra_ctx providers based on ra_gl.
// The init function also initializes ctx->ra and ctx->swapchain, so the user
diff --git a/video/out/opengl/context_glx.c b/video/out/opengl/context_glx.c
index ee1fb30abf..529991fac2 100644
--- a/video/out/opengl/context_glx.c
+++ b/video/out/opengl/context_glx.c
@@ -116,9 +116,6 @@ static bool create_context_x11_gl3(struct ra_ctx *ctx, GL *gl, int gl_version,
if (p->context)
return true;
- if (!ra_gl_ctx_test_version(ctx, gl_version, es))
- return false;
-
glXCreateContextAttribsARBProc glXCreateContextAttribsARB =
(glXCreateContextAttribsARBProc)
glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB");
@@ -312,19 +309,23 @@ static bool glx_init(struct ra_ctx *ctx)
goto uninit;
bool success = false;
- for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
- int version = mpgl_min_required_gl_versions[n];
- MP_VERBOSE(ctx, "Creating OpenGL %d.%d context...\n",
- MPGL_VER_P(version));
- if (version >= 300) {
- success = create_context_x11_gl3(ctx, gl, version, false);
- } else {
- success = create_context_x11_old(ctx, gl);
+ enum gles_mode mode = ra_gl_ctx_get_glesmode(ctx);
+
+ if (mode == GLES_NO || mode == GLES_AUTO) {
+ for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
+ int version = mpgl_min_required_gl_versions[n];
+ MP_VERBOSE(ctx, "Creating OpenGL %d.%d context...\n",
+ MPGL_VER_P(version));
+ if (version >= 300) {
+ success = create_context_x11_gl3(ctx, gl, version, false);
+ } else {
+ success = create_context_x11_old(ctx, gl);
+ }
+ if (success)
+ break;
}
- if (success)
- break;
}
- if (!success) // try again for GLES
+ if (!success && (mode == GLES_YES || mode == GLES_AUTO))
success = create_context_x11_gl3(ctx, gl, 200, true);
if (success && !glXIsDirect(vo->x11->display, p->context))
gl->mpgl_caps |= MPGL_CAP_SW;
diff --git a/video/out/opengl/egl_helpers.c b/video/out/opengl/egl_helpers.c
index 834ec25166..68cfa8e55d 100644
--- a/video/out/opengl/egl_helpers.c
+++ b/video/out/opengl/egl_helpers.c
@@ -164,9 +164,6 @@ static bool create_context(struct ra_ctx *ctx, EGLDisplay display,
EGLContext *egl_ctx = NULL;
if (es) {
- if (!ra_gl_ctx_test_version(ctx, MPGL_VER(2, 0), true))
- return false;
-
EGLint attrs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
@@ -176,8 +173,6 @@ static bool create_context(struct ra_ctx *ctx, EGLDisplay display,
} else {
for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
int ver = mpgl_min_required_gl_versions[n];
- if (!ra_gl_ctx_test_version(ctx, ver, false))
- continue;
EGLint attrs[] = {
EGL_CONTEXT_MAJOR_VERSION, MPGL_VER_GET_MAJOR(ver),
@@ -199,9 +194,7 @@ static bool create_context(struct ra_ctx *ctx, EGLDisplay display,
GL *gl = talloc_zero(ctx, struct GL);
mpgl_check_version(gl, mpegl_get_proc_address, NULL);
- if (gl->version < 210 ||
- !ra_gl_ctx_test_version(ctx, gl->version, false))
- {
+ if (gl->version < 210) {
eglDestroyContext(display, egl_ctx);
egl_ctx = NULL;
}
@@ -246,9 +239,14 @@ bool mpegl_create_context_cb(struct ra_ctx *ctx, EGLDisplay display,
MP_VERBOSE(ctx, "EGL_VERSION=%s\nEGL_VENDOR=%s\nEGL_CLIENT_APIS=%s\n",
STR_OR_ERR(version), STR_OR_ERR(vendor), STR_OR_ERR(apis));
- if (create_context(ctx, display, false, cb, out_context, out_config))
+ enum gles_mode mode = ra_gl_ctx_get_glesmode(ctx);
+
+ if ((mode == GLES_NO || mode == GLES_AUTO) &&
+ create_context(ctx, display, false, cb, out_context, out_config))
return true;
- if (create_context(ctx, display, true, cb, out_context, out_config))
+
+ if ((mode == GLES_YES || mode == GLES_AUTO) &&
+ create_context(ctx, display, true, cb, out_context, out_config))
return true;
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR;