diff --git a/gfx/common/egl_common.c b/gfx/common/egl_common.c index ef5cb945ab..29866de35b 100644 --- a/gfx/common/egl_common.c +++ b/gfx/common/egl_common.c @@ -164,3 +164,20 @@ void egl_get_video_size(void *data, unsigned *width, unsigned *height) *height = gl_height; } } + +static void egl_sighandler(int sig) +{ + (void)sig; + g_egl_quit = 1; +} + +void egl_install_sighandlers(void) +{ + struct sigaction sa = {{0}}; + + sa.sa_handler = egl_sighandler; + sa.sa_flags = SA_RESTART; + sigemptyset(&sa.sa_mask); + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); +} diff --git a/gfx/common/egl_common.h b/gfx/common/egl_common.h index 55fa35d60e..63420d4a56 100644 --- a/gfx/common/egl_common.h +++ b/gfx/common/egl_common.h @@ -49,4 +49,6 @@ void egl_set_swap_interval(void *data, unsigned interval); void egl_get_video_size(void *data, unsigned *width, unsigned *height); +void egl_install_sighandlers(void); + #endif diff --git a/gfx/drivers_context/drm_egl_ctx.c b/gfx/drivers_context/drm_egl_ctx.c index 7857da1f90..90cdbdda84 100644 --- a/gfx/drivers_context/drm_egl_ctx.c +++ b/gfx/drivers_context/drm_egl_ctx.c @@ -129,12 +129,6 @@ static struct drm_fb *drm_fb_get_from_bo( return fb; } -static void sighandler(int sig) -{ - (void)sig; - g_egl_quit = 1; -} - static void gfx_ctx_drm_egl_swap_interval(void *data, unsigned interval) { g_interval = interval; @@ -376,7 +370,6 @@ static void gfx_ctx_drm_egl_destroy_resources(gfx_ctx_drm_egl_data_t *drm) free_drm_resources(drm); drm->g_drm_mode = NULL; - g_egl_quit = 0; drm->g_crtc_id = 0; drm->g_connector_id = 0; @@ -655,7 +648,6 @@ static bool gfx_ctx_drm_egl_set_video_mode(void *data, EGLint major, minor, n, egl_attribs[16], *attr; float refresh_mod; int i, ret = 0; - struct sigaction sa = {{0}}; struct drm_fb *fb = NULL; driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); @@ -665,11 +657,7 @@ static bool gfx_ctx_drm_egl_set_video_mode(void *data, if (!drm) return false; - sa.sa_handler = sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); + egl_install_sighandlers(); switch (g_api) { diff --git a/gfx/drivers_context/mali_fbdev_ctx.c b/gfx/drivers_context/mali_fbdev_ctx.c index 8077a78794..1a6477fea4 100644 --- a/gfx/drivers_context/mali_fbdev_ctx.c +++ b/gfx/drivers_context/mali_fbdev_ctx.c @@ -35,12 +35,6 @@ struct fbdev_window native_window; static bool g_resize; static unsigned g_width, g_height; -static void gfx_ctx_mali_fbdev_sighandler(int sig) -{ - (void)sig; - g_egl_quit = 1; -} - static void gfx_ctx_mali_fbdev_destroy(void *data) { int fb; @@ -75,7 +69,6 @@ static bool gfx_ctx_mali_fbdev_init(void *data) EGLint num_config; EGLint egl_version_major, egl_version_minor; EGLint format; - struct sigaction sa = {{0}}; static const EGLint attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, @@ -86,13 +79,7 @@ static bool gfx_ctx_mali_fbdev_init(void *data) EGL_NONE }; - (void)data; - - sa.sa_handler = gfx_ctx_mali_fbdev_sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); + egl_install_sighandlers(); /* Disable cursor blinking so it's not visible in RetroArch. */ system("setterm -cursor off"); diff --git a/gfx/drivers_context/vc_egl_ctx.c b/gfx/drivers_context/vc_egl_ctx.c index 82fb0f5dd3..b150d40691 100644 --- a/gfx/drivers_context/vc_egl_ctx.c +++ b/gfx/drivers_context/vc_egl_ctx.c @@ -64,12 +64,6 @@ static INLINE bool gfx_ctx_vc_egl_query_extension(const char *ext) return ret; } -static void sighandler(int sig) -{ - (void)sig; - g_egl_quit = 1; -} - static void gfx_ctx_vc_check_window(void *data, bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count) { @@ -305,17 +299,10 @@ static bool gfx_ctx_vc_set_video_mode(void *data, unsigned width, unsigned height, bool fullscreen) { - struct sigaction sa = {{0}}; - if (g_inited) return false; - sa.sa_handler = sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); - + egl_install_sighandlers(); egl_set_swap_interval(data, g_interval); g_inited = true; diff --git a/gfx/drivers_context/vivante_fbdev_ctx.c b/gfx/drivers_context/vivante_fbdev_ctx.c index 62e878d431..68134cc914 100644 --- a/gfx/drivers_context/vivante_fbdev_ctx.c +++ b/gfx/drivers_context/vivante_fbdev_ctx.c @@ -26,12 +26,6 @@ static bool g_resize; static unsigned g_width, g_height; -static void sighandler(int sig) -{ - (void)sig; - g_egl_quit = 1; -} - static void gfx_ctx_vivante_destroy(void *data) { egl_destroy(data); @@ -44,7 +38,6 @@ static bool gfx_ctx_vivante_init(void *data) EGLint num_config; EGLint egl_version_major, egl_version_minor; EGLint format; - struct sigaction sa = {{0}}; static const EGLint attribs[] = { #if 0 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, @@ -60,11 +53,7 @@ static bool gfx_ctx_vivante_init(void *data) (void)data; - sa.sa_handler = sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); + egl_install_sighandlers(); RARCH_LOG("[Vivante fbdev]: Initializing context\n"); diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 3789fb9ddd..d15a70b21c 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -55,12 +55,6 @@ static unsigned g_minor; #define EGL_OPENGL_ES3_BIT_KHR 0x0040 #endif -static void sighandler(int sig) -{ - (void)sig; - g_egl_quit = 1; -} - /* Shell surface callbacks. */ static void shell_surface_handle_ping(void *data, struct wl_shell_surface *shell_surface, @@ -503,14 +497,9 @@ static bool gfx_ctx_wl_set_video_mode(void *data, driver_t *driver = driver_get_ptr(); gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*) driver->video_context_data; - struct sigaction sa = {{0}}; EGLint *attr = NULL; - sa.sa_handler = sighandler; - sa.sa_flags = SA_RESTART; - sigemptyset(&sa.sa_mask); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); + egl_install_sighandlers(); attr = egl_fill_attribs(egl_attribs);