From 7033a4334bcf457b0cadaca7f4b0ce8099469632 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 30 Dec 2016 19:52:47 +0100 Subject: vo_opengl: egl_helpers: add a way to override config selection Preparation for the following commits. Since at least theoretically the config selection depends on the context type (EGL_RENDERABLE_TYPE has separate bits for ES 2, ES 3, and desktop GL), doing it any other way would be too painful. --- video/out/opengl/egl_helpers.c | 16 ++++++++++++++-- video/out/opengl/egl_helpers.h | 7 +++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/video/out/opengl/egl_helpers.c b/video/out/opengl/egl_helpers.c index 3594f72022..0169ab264e 100644 --- a/video/out/opengl/egl_helpers.c +++ b/video/out/opengl/egl_helpers.c @@ -72,15 +72,27 @@ static bool create_context(EGLDisplay display, struct mp_log *log, bool probing, }; EGLint config_count; - EGLConfig config; + EGLConfig *configs = NULL; - eglChooseConfig(display, attributes, &config, 1, &config_count); + eglChooseConfig(display, attributes, NULL, 0, &config_count); + + if (config_count) { + configs = talloc_array(NULL, EGLConfig, config_count); + eglChooseConfig(display, attributes, configs, config_count, &config_count); + } if (!config_count) { mp_msg(log, msgl, "Could not find EGL configuration!\n"); return false; } + int chosen = 0; + if (opts->refine_config) + chosen = opts->refine_config(opts->user_data, configs, config_count); + EGLConfig config = configs[chosen]; + + talloc_free(configs); + EGLContext *ctx = NULL; if (es_version) { diff --git a/video/out/opengl/egl_helpers.h b/video/out/opengl/egl_helpers.h index 15033834f4..ea751d4c5e 100644 --- a/video/out/opengl/egl_helpers.h +++ b/video/out/opengl/egl_helpers.h @@ -14,6 +14,13 @@ bool mpegl_create_context(EGLDisplay display, struct mp_log *log, int vo_flags, struct mpegl_opts { // combination of VOFLAG_* values. int vo_flags; + + // for callbacks + void *user_data; + + // if set, pick the desired config from the given list and return its index + // defaults to 0 (they are sorted by eglChooseConfig) + int (*refine_config)(void *user_data, EGLConfig *configs, int num_configs); }; bool mpegl_create_context_opts(EGLDisplay display, struct mp_log *log, -- cgit v1.2.3