Skip to content

Commit

Permalink
Merge pull request #7729 from Themaister/master
Browse files Browse the repository at this point in the history
EGL: Add callback to select EGLConfig.
  • Loading branch information
inactive123 authored Dec 11, 2018
2 parents 669f16c + 868465a commit c7b3b0f
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 35 deletions.
53 changes: 30 additions & 23 deletions gfx/common/egl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -354,32 +370,23 @@ 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)
free(configs);

if (i == count)
{
RARCH_ERR("[EGL]: No EGL configs with format XRGB8888\n");
RARCH_ERR("[EGL]: No EGL config found which satifies requirements.\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)
return false;
#endif

egl->major = g_egl_major;
egl->minor = g_egl_minor;

Expand Down
6 changes: 5 additions & 1 deletion gfx/common/egl_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/android_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 23 additions & 1 deletion gfx/drivers_context/drm_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/emscriptenegl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/mali_fbdev_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/opendingux_fbdev_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/qnx_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/switch_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/vc_egl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/vivante_fbdev_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion gfx/drivers_context/wayland_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion gfx/drivers_context/xegl_ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c7b3b0f

Please sign in to comment.