mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-01-11 21:37:17 +00:00
EGL: Add callback to select EGLConfig.
A more robust fix for DRM/GBM shenanigans.
This commit is contained in:
parent
669f16c00c
commit
868465ad01
@ -309,14 +309,31 @@ static EGLDisplay get_egl_display(EGLenum platform, void *native)
|
||||
return eglGetDisplay((EGLNativeDisplayType) native);
|
||||
}
|
||||
|
||||
bool egl_default_accept_config_cb(void *display_data, EGLDisplay dpy, EGLConfig config)
|
||||
{
|
||||
/* Makes sure we have 8 bit color. */
|
||||
EGLint r, g, b;
|
||||
if (!eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r))
|
||||
return false;
|
||||
if (!eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g))
|
||||
return false;
|
||||
if (!eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b))
|
||||
return false;
|
||||
|
||||
if (r != 8 || g != 8 || b != 8)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool egl_init_context(egl_ctx_data_t *egl,
|
||||
EGLenum platform,
|
||||
void *display_data,
|
||||
EGLint *major, EGLint *minor,
|
||||
EGLint *n, const EGLint *attrib_ptr)
|
||||
EGLint *n, const EGLint *attrib_ptr,
|
||||
egl_accept_config_cb_t cb)
|
||||
{
|
||||
int i;
|
||||
EGLint id;
|
||||
EGLint i;
|
||||
EGLConfig *configs = NULL;
|
||||
EGLint count = 0;
|
||||
EGLint matched = 0;
|
||||
@ -336,14 +353,13 @@ bool egl_init_context(egl_ctx_data_t *egl,
|
||||
|
||||
RARCH_LOG("[EGL]: EGL version: %d.%d\n", *major, *minor);
|
||||
|
||||
#ifdef HAVE_GBM
|
||||
if (!eglGetConfigs(egl->dpy, NULL, 0, &count) || count < 1)
|
||||
{
|
||||
RARCH_ERR("[EGL]: No configs to choose from.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
configs = malloc(count * sizeof *configs);
|
||||
configs = malloc(count * sizeof(*configs));
|
||||
if (!configs)
|
||||
return false;
|
||||
|
||||
@ -354,31 +370,22 @@ bool egl_init_context(egl_ctx_data_t *egl,
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
if (!eglGetConfigAttrib(egl->dpy,
|
||||
configs[i], EGL_NATIVE_VISUAL_ID, &id))
|
||||
continue;
|
||||
|
||||
if (id == GBM_FORMAT_XRGB8888)
|
||||
if (!cb || cb(display_data, egl->dpy, configs[i]))
|
||||
{
|
||||
egl->config = configs[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (id != GBM_FORMAT_XRGB8888)
|
||||
{
|
||||
RARCH_ERR("[EGL]: No EGL configs with format XRGB8888\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
config_index = i;
|
||||
if (config_index != -1)
|
||||
egl->config = configs[config_index];
|
||||
|
||||
free(configs);
|
||||
#else
|
||||
if (!eglChooseConfig(egl->dpy, attrib_ptr, &egl->config, 1, n) || *n != 1)
|
||||
|
||||
if (i == count)
|
||||
{
|
||||
RARCH_ERR("[EGL]: No EGL config found which satifies requirements.\n");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
egl->major = g_egl_major;
|
||||
egl->minor = g_egl_minor;
|
||||
|
@ -88,13 +88,17 @@ void egl_set_swap_interval(egl_ctx_data_t *egl, int interval);
|
||||
|
||||
void egl_get_video_size(egl_ctx_data_t *egl, unsigned *width, unsigned *height);
|
||||
|
||||
typedef bool (*egl_accept_config_cb_t)(void *display_data, EGLDisplay dpy, EGLConfig config);
|
||||
bool egl_default_accept_config_cb(void *display_data, EGLDisplay dpy, EGLConfig config);
|
||||
|
||||
bool egl_init_context(egl_ctx_data_t *egl,
|
||||
EGLenum platform,
|
||||
void *display_data,
|
||||
EGLint *major,
|
||||
EGLint *minor,
|
||||
EGLint *n,
|
||||
const EGLint *attrib_ptr);
|
||||
const EGLint *attrib_ptr,
|
||||
egl_accept_config_cb_t cb);
|
||||
|
||||
bool egl_create_context(egl_ctx_data_t *egl, const EGLint *egl_attribs);
|
||||
|
||||
|
@ -137,7 +137,7 @@ static void *android_gfx_ctx_init(video_frame_info_t *video_info, void *video_dr
|
||||
RARCH_LOG("Android EGL: GLES version = %d.\n", g_es3 ? 3 : 2);
|
||||
|
||||
if (!egl_init_context(&and->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
|
||||
&major, &minor, &n, attribs))
|
||||
&major, &minor, &n, attribs, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -497,6 +497,28 @@ static EGLint *gfx_ctx_drm_egl_fill_attribs(
|
||||
}
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
static bool gbm_choose_xrgb8888_cb(void *display_data, EGLDisplay dpy, EGLConfig config)
|
||||
{
|
||||
EGLint r, g, b, id;
|
||||
(void)display_data;
|
||||
|
||||
/* Makes sure we have 8 bit color. */
|
||||
if (!eglGetConfigAttrib(dpy, config, EGL_RED_SIZE, &r))
|
||||
return false;
|
||||
if (!eglGetConfigAttrib(dpy, config, EGL_GREEN_SIZE, &g))
|
||||
return false;
|
||||
if (!eglGetConfigAttrib(dpy, config, EGL_BLUE_SIZE, &b))
|
||||
return false;
|
||||
|
||||
if (r != 8 || g != 8 || b != 8)
|
||||
return false;
|
||||
|
||||
if (!eglGetConfigAttrib(dpy, config, EGL_NATIVE_VISUAL_ID, &id))
|
||||
return false;
|
||||
|
||||
return id == GBM_FORMAT_XRGB8888;
|
||||
}
|
||||
|
||||
#define DRM_EGL_ATTRIBS_BASE \
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, \
|
||||
EGL_RED_SIZE, 1, \
|
||||
@ -575,7 +597,7 @@ static bool gfx_ctx_drm_egl_set_video_mode(gfx_ctx_drm_data_t *drm)
|
||||
#ifdef HAVE_EGL
|
||||
if (!egl_init_context(&drm->egl, EGL_PLATFORM_GBM_KHR,
|
||||
(EGLNativeDisplayType)g_gbm_dev, &major,
|
||||
&minor, &n, attrib_ptr))
|
||||
&minor, &n, attrib_ptr, gbm_choose_xrgb8888_cb))
|
||||
goto error;
|
||||
|
||||
attr = gfx_ctx_drm_egl_fill_attribs(drm, egl_attribs);
|
||||
|
@ -212,7 +212,7 @@ static void *gfx_ctx_emscripten_init(video_frame_info_t *video_info,
|
||||
}
|
||||
|
||||
if (!egl_init_context(&emscripten->egl, EGL_NONE,
|
||||
(void *)EGL_DEFAULT_DISPLAY, &major, &minor, &n, attribute_list))
|
||||
(void *)EGL_DEFAULT_DISPLAY, &major, &minor, &n, attribute_list, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -116,7 +116,7 @@ static void *gfx_ctx_mali_fbdev_init(video_frame_info_t *video_info, void *video
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
if (!egl_init_context(&mali->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
|
||||
&major, &minor, &n, attribs))
|
||||
&major, &minor, &n, attribs, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -87,7 +87,7 @@ static void *gfx_ctx_opendingux_init(video_frame_info_t *video_info, void *video
|
||||
|
||||
if (!egl_init_context(&viv->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
|
||||
&major, &minor,
|
||||
&n, attribs))
|
||||
&n, attribs, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -134,7 +134,7 @@ static void *gfx_ctx_qnx_init(video_frame_info_t *video_info, void *video_driver
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
if (!egl_init_context(&qnx->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, &major, &minor,
|
||||
&n, attribs))
|
||||
&n, attribs, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -88,7 +88,7 @@ static void *switch_ctx_init(video_frame_info_t *video_info, void *video_driver)
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
if (!egl_init_context(&ctx_nx->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
|
||||
&major, &minor, &n, attribs))
|
||||
&major, &minor, &n, attribs, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -210,7 +210,7 @@ static void *gfx_ctx_vc_init(video_frame_info_t *video_info, void *video_driver)
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
if (!egl_init_context(&vc->egl, EGL_NONE, EGL_DEFAULT_DISPLAY,
|
||||
&major, &minor, &n, attribute_list))
|
||||
&major, &minor, &n, attribute_list, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -93,7 +93,7 @@ static void *gfx_ctx_vivante_init(video_frame_info_t *video_info, void *video_dr
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
if (!egl_init_context(&viv->egl, EGL_NONE, EGL_DEFAULT_DISPLAY, &major, &minor,
|
||||
&n, attribs))
|
||||
&n, attribs, NULL))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -1305,7 +1305,8 @@ static void *gfx_ctx_wl_init(video_frame_info_t *video_info, void *video_driver)
|
||||
if (!egl_init_context(&wl->egl,
|
||||
EGL_PLATFORM_WAYLAND_KHR,
|
||||
(EGLNativeDisplayType)wl->input.dpy,
|
||||
&major, &minor, &n, attrib_ptr))
|
||||
&major, &minor, &n, attrib_ptr,
|
||||
egl_default_accept_config_cb))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
@ -172,7 +172,7 @@ static void *gfx_ctx_xegl_init(video_frame_info_t *video_info, void *video_drive
|
||||
|
||||
#ifdef HAVE_EGL
|
||||
if (!egl_init_context(&xegl->egl, EGL_PLATFORM_X11_KHR,
|
||||
(EGLNativeDisplayType)g_x11_dpy, &major, &minor, &n, attrib_ptr))
|
||||
(EGLNativeDisplayType)g_x11_dpy, &major, &minor, &n, attrib_ptr, egl_default_accept_config_cb))
|
||||
{
|
||||
egl_report_error();
|
||||
goto error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user