diff --git a/gfx/common/egl_common.c b/gfx/common/egl_common.c index 29866de35b..121501a0c3 100644 --- a/gfx/common/egl_common.c +++ b/gfx/common/egl_common.c @@ -173,11 +173,32 @@ static void egl_sighandler(int sig) void egl_install_sighandlers(void) { - struct sigaction sa = {{0}}; + struct sigaction sa; - sa.sa_handler = egl_sighandler; - sa.sa_flags = SA_RESTART; + sa.sa_sigaction = NULL; + sa.sa_handler = egl_sighandler; + sa.sa_flags = SA_RESTART; sigemptyset(&sa.sa_mask); sigaction(SIGINT, &sa, NULL); sigaction(SIGTERM, &sa, NULL); } + +bool egl_init_context(NativeDisplayType display, + EGLint *major, EGLint *minor, + EGLint *n, const EGLint *attrib_ptr) +{ + g_egl_dpy = eglGetDisplay(display); + if (!g_egl_dpy) + { + RARCH_ERR("[KMS/EGL]: Couldn't get EGL display.\n"); + return false; + } + + if (!eglInitialize(g_egl_dpy, major, minor)) + return false; + + if (!eglChooseConfig(g_egl_dpy, attrib_ptr, &g_egl_config, 1, n) || *n != 1) + return false; + + return true; +} diff --git a/gfx/common/egl_common.h b/gfx/common/egl_common.h index 63420d4a56..e88a1bdc3a 100644 --- a/gfx/common/egl_common.h +++ b/gfx/common/egl_common.h @@ -51,4 +51,8 @@ void egl_get_video_size(void *data, unsigned *width, unsigned *height); void egl_install_sighandlers(void); +bool egl_init_context(NativeDisplayType display, + EGLint *major, EGLint *minor, + EGLint *n, const EGLint *attrib_ptr); + #endif diff --git a/gfx/drivers_context/drm_egl_ctx.c b/gfx/drivers_context/drm_egl_ctx.c index 4791572c79..325e9a9dbd 100644 --- a/gfx/drivers_context/drm_egl_ctx.c +++ b/gfx/drivers_context/drm_egl_ctx.c @@ -722,17 +722,8 @@ static bool gfx_ctx_drm_egl_set_video_mode(void *data, goto error; } - g_egl_dpy = eglGetDisplay((EGLNativeDisplayType)drm->g_gbm_dev); - if (!g_egl_dpy) - { - RARCH_ERR("[KMS/EGL]: Couldn't get EGL display.\n"); - goto error; - } - - if (!eglInitialize(g_egl_dpy, &major, &minor)) - goto error; - - if (!eglChooseConfig(g_egl_dpy, attrib_ptr, &g_egl_config, 1, &n) || n != 1) + if (!egl_init_context((EGLNativeDisplayType)drm->g_gbm_dev, &major, + &minor, &n, attrib_ptr)) goto error; attr = egl_fill_attribs(egl_attribs);