From cd74f8f7c5073448182c22e87f33a606396d0734 Mon Sep 17 00:00:00 2001 From: Misaki Kasumi Date: Mon, 27 May 2024 16:58:11 +0800 Subject: [PATCH] opengl: add --egl-config-id --- DOCS/interface-changes/egl-output-format.txt | 1 + DOCS/man/options.rst | 6 +++ options/options.c | 5 +++ options/options.h | 1 + video/out/opengl/egl_helpers.c | 45 +++++++++++++++----- 5 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 DOCS/interface-changes/egl-output-format.txt diff --git a/DOCS/interface-changes/egl-output-format.txt b/DOCS/interface-changes/egl-output-format.txt new file mode 100644 index 0000000000..9cc5bd0ce5 --- /dev/null +++ b/DOCS/interface-changes/egl-output-format.txt @@ -0,0 +1 @@ +add `--egl-config-id` option diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 929136e8e6..47910ae8b9 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -5716,6 +5716,12 @@ them. results, as can missing or incorrect display FPS information (see ``--display-fps-override``). +``--egl-config-id=`` + (EGL only) + Select EGLConfig with specific EGL_CONFIG_ID. + Rendering surfaces and contexts will be created using this EGLConfig. + You can use ``--msg-level=vo=trace`` to obtain a list of available configs. + ``--vulkan-device=`` The name or UUID of the Vulkan device to use for rendering and presentation. Use ``--vulkan-device=help`` to see the list of available devices and their diff --git a/options/options.c b/options/options.c index 55ecab8f52..175b5e0916 100644 --- a/options/options.c +++ b/options/options.c @@ -100,6 +100,7 @@ extern const struct m_sub_options macos_conf; extern const struct m_sub_options wayland_conf; extern const struct m_sub_options wingl_conf; extern const struct m_sub_options vaapi_conf; +extern const struct m_sub_options egl_conf; static const struct m_sub_options screenshot_conf = { .opts = image_writer_opts, @@ -903,6 +904,10 @@ static const m_option_t mp_opts[] = { {"", OPT_SUBSTRUCT(opengl_opts, opengl_conf)}, #endif +#if HAVE_EGL || HAVE_EGL_ANDROID || HAVE_EGL_ANGLE_WIN32 + {"", OPT_SUBSTRUCT(egl_opts, egl_conf)}, +#endif + #if HAVE_VULKAN {"", OPT_SUBSTRUCT(vulkan_opts, vulkan_conf)}, #if HAVE_VK_KHR_DISPLAY diff --git a/options/options.h b/options/options.h index 6ab17c2a93..b80a128b21 100644 --- a/options/options.h +++ b/options/options.h @@ -389,6 +389,7 @@ typedef struct MPOpts { struct vaapi_opts *vaapi_opts; struct sws_opts *sws_opts; struct zimg_opts *zimg_opts; + struct egl_opts *egl_opts; int cuda_device; } MPOpts; diff --git a/video/out/opengl/egl_helpers.c b/video/out/opengl/egl_helpers.c index 18d9027762..6320d700bc 100644 --- a/video/out/opengl/egl_helpers.c +++ b/video/out/opengl/egl_helpers.c @@ -16,6 +16,7 @@ */ #include "config.h" +#include "options/m_config.h" #if HAVE_LIBDL #include @@ -100,8 +101,21 @@ static void *mpegl_get_proc_address(void *ctx, const char *name) return p; } +struct egl_opts { + int config_id; +}; + +#define OPT_BASE_STRUCT struct egl_opts +const struct m_sub_options egl_conf = { + .opts = (const struct m_option[]) { + {"egl-config-id", OPT_INT(config_id)}, + {0}, + }, + .size = sizeof(struct egl_opts), +}; + static bool create_context(struct ra_ctx *ctx, EGLDisplay display, - bool es, struct mpegl_cb cb, + bool es, struct mpegl_cb cb, struct egl_opts *opts, EGLContext *out_context, EGLConfig *out_config) { int msgl = ctx->opts.probing ? MSGL_V : MSGL_FATAL; @@ -136,6 +150,11 @@ static bool create_context(struct ra_ctx *ctx, EGLDisplay display, EGL_RENDERABLE_TYPE, rend, EGL_NONE }; + if (opts->config_id) { + attributes[0] = EGL_CONFIG_ID; + attributes[1] = opts->config_id; + attributes[2] = EGL_NONE; + } EGLint num_configs; if (!eglChooseConfig(display, attributes, NULL, 0, &num_configs)) @@ -243,17 +262,23 @@ bool mpegl_create_context_cb(struct ra_ctx *ctx, EGLDisplay display, 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; + void *tmp = talloc_new(NULL); + struct egl_opts *opts = mp_get_config_group(tmp, ctx->global, &egl_conf); - if ((mode == GLES_YES || mode == GLES_AUTO) && - create_context(ctx, display, true, cb, out_context, out_config)) - return true; + bool r = false; + if (!r && (mode == GLES_NO || mode == GLES_AUTO)) + r = create_context(ctx, display, false, cb, opts, out_context, out_config); + if (!r && (mode == GLES_YES || mode == GLES_AUTO)) + r = create_context(ctx, display, true, cb, opts, out_context, out_config); - int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR; - MP_MSG(ctx, msgl, "Could not create a GL context.\n"); - return false; + talloc_free(tmp); + + if (!r) { + int msgl = ctx->opts.probing ? MSGL_V : MSGL_ERR; + MP_MSG(ctx, msgl, "Could not create a GL context.\n"); + } + + return r; } static int GLAPIENTRY swap_interval(int interval)