mirror of
https://github.com/mpv-player/mpv
synced 2025-05-07 10:40:33 +00:00
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>
This commit is contained in:
parent
e3883512b1
commit
538fb6541e
@ -34,12 +34,6 @@ enum {
|
|||||||
FLUSH_AUTO,
|
FLUSH_AUTO,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
|
||||||
GLES_AUTO = 0,
|
|
||||||
GLES_YES,
|
|
||||||
GLES_NO,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct opengl_opts {
|
struct opengl_opts {
|
||||||
int use_glfinish;
|
int use_glfinish;
|
||||||
int waitvsync;
|
int waitvsync;
|
||||||
@ -93,23 +87,17 @@ struct priv {
|
|||||||
int num_vsync_fences;
|
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);
|
void *tmp = talloc_new(NULL);
|
||||||
|
struct opengl_opts *opts;
|
||||||
|
enum gles_mode mode;
|
||||||
|
|
||||||
opts = mp_get_config_group(tmp, ctx->global, &opengl_conf);
|
opts = mp_get_config_group(tmp, ctx->global, &opengl_conf);
|
||||||
|
mode = opts->gles_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();
|
|
||||||
}
|
|
||||||
|
|
||||||
done:
|
|
||||||
talloc_free(tmp);
|
talloc_free(tmp);
|
||||||
return ret;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ra_gl_ctx_uninit(struct ra_ctx *ctx)
|
void ra_gl_ctx_uninit(struct ra_ctx *ctx)
|
||||||
|
@ -6,10 +6,14 @@
|
|||||||
|
|
||||||
extern const int mpgl_min_required_gl_versions[];
|
extern const int mpgl_min_required_gl_versions[];
|
||||||
|
|
||||||
// Returns whether or not a candidate GL version should be accepted or not
|
enum gles_mode {
|
||||||
// (based on the --opengl opts). Implementations may call this before
|
GLES_AUTO = 0,
|
||||||
// ra_gl_ctx_init if they wish to probe for multiple possible GL versions.
|
GLES_YES,
|
||||||
bool ra_gl_ctx_test_version(struct ra_ctx *ctx, int version, bool es);
|
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.
|
// 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
|
// The init function also initializes ctx->ra and ctx->swapchain, so the user
|
||||||
|
@ -116,9 +116,6 @@ static bool create_context_x11_gl3(struct ra_ctx *ctx, GL *gl, int gl_version,
|
|||||||
if (p->context)
|
if (p->context)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!ra_gl_ctx_test_version(ctx, gl_version, es))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
glXCreateContextAttribsARBProc glXCreateContextAttribsARB =
|
glXCreateContextAttribsARBProc glXCreateContextAttribsARB =
|
||||||
(glXCreateContextAttribsARBProc)
|
(glXCreateContextAttribsARBProc)
|
||||||
glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB");
|
glXGetProcAddressARB((const GLubyte *)"glXCreateContextAttribsARB");
|
||||||
@ -312,19 +309,23 @@ static bool glx_init(struct ra_ctx *ctx)
|
|||||||
goto uninit;
|
goto uninit;
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
|
enum gles_mode mode = ra_gl_ctx_get_glesmode(ctx);
|
||||||
int version = mpgl_min_required_gl_versions[n];
|
|
||||||
MP_VERBOSE(ctx, "Creating OpenGL %d.%d context...\n",
|
if (mode == GLES_NO || mode == GLES_AUTO) {
|
||||||
MPGL_VER_P(version));
|
for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
|
||||||
if (version >= 300) {
|
int version = mpgl_min_required_gl_versions[n];
|
||||||
success = create_context_x11_gl3(ctx, gl, version, false);
|
MP_VERBOSE(ctx, "Creating OpenGL %d.%d context...\n",
|
||||||
} else {
|
MPGL_VER_P(version));
|
||||||
success = create_context_x11_old(ctx, gl);
|
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);
|
success = create_context_x11_gl3(ctx, gl, 200, true);
|
||||||
if (success && !glXIsDirect(vo->x11->display, p->context))
|
if (success && !glXIsDirect(vo->x11->display, p->context))
|
||||||
gl->mpgl_caps |= MPGL_CAP_SW;
|
gl->mpgl_caps |= MPGL_CAP_SW;
|
||||||
|
@ -164,9 +164,6 @@ static bool create_context(struct ra_ctx *ctx, EGLDisplay display,
|
|||||||
EGLContext *egl_ctx = NULL;
|
EGLContext *egl_ctx = NULL;
|
||||||
|
|
||||||
if (es) {
|
if (es) {
|
||||||
if (!ra_gl_ctx_test_version(ctx, MPGL_VER(2, 0), true))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
EGLint attrs[] = {
|
EGLint attrs[] = {
|
||||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||||
EGL_NONE
|
EGL_NONE
|
||||||
@ -176,8 +173,6 @@ static bool create_context(struct ra_ctx *ctx, EGLDisplay display,
|
|||||||
} else {
|
} else {
|
||||||
for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
|
for (int n = 0; mpgl_min_required_gl_versions[n]; n++) {
|
||||||
int ver = mpgl_min_required_gl_versions[n];
|
int ver = mpgl_min_required_gl_versions[n];
|
||||||
if (!ra_gl_ctx_test_version(ctx, ver, false))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
EGLint attrs[] = {
|
EGLint attrs[] = {
|
||||||
EGL_CONTEXT_MAJOR_VERSION, MPGL_VER_GET_MAJOR(ver),
|
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);
|
GL *gl = talloc_zero(ctx, struct GL);
|
||||||
mpgl_check_version(gl, mpegl_get_proc_address, NULL);
|
mpgl_check_version(gl, mpegl_get_proc_address, NULL);
|
||||||
if (gl->version < 210 ||
|
if (gl->version < 210) {
|
||||||
!ra_gl_ctx_test_version(ctx, gl->version, false))
|
|
||||||
{
|
|
||||||
eglDestroyContext(display, egl_ctx);
|
eglDestroyContext(display, egl_ctx);
|
||||||
egl_ctx = NULL;
|
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",
|
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));
|
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;
|
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;
|
return true;
|
||||||
|
|
||||||
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR;
|
int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR;
|
||||||
|
Loading…
Reference in New Issue
Block a user