diff --git a/gfx/common/egl_common.c b/gfx/common/egl_common.c index edcf526f9a..b2877fe1ba 100644 --- a/gfx/common/egl_common.c +++ b/gfx/common/egl_common.c @@ -300,11 +300,11 @@ void egl_destroy(egl_ctx_data_t *egl) * If we screw up, any TTY will not restore. */ - egl->ctx = EGL_NO_CONTEXT; - egl->hw_ctx = EGL_NO_CONTEXT; - egl->surf = EGL_NO_SURFACE; - egl->dpy = EGL_NO_DISPLAY; - egl->config = 0; + egl->ctx = EGL_NO_CONTEXT; + egl->hw_ctx = EGL_NO_CONTEXT; + egl->surf = EGL_NO_SURFACE; + egl->dpy = EGL_NO_DISPLAY; + egl->config = 0; g_egl_inited = false; frontend_driver_destroy_signal_handler_state(); @@ -312,13 +312,12 @@ void egl_destroy(egl_ctx_data_t *egl) void egl_bind_hw_render(egl_ctx_data_t *egl, bool enable) { - egl->use_hw_ctx = enable; + egl->use_hw_ctx = enable; if (egl->dpy == EGL_NO_DISPLAY) return; if (egl->surf == EGL_NO_SURFACE) return; - _egl_make_current(egl->dpy, egl->surf, egl->surf, enable ? egl->hw_ctx : egl->ctx); diff --git a/gfx/common/wayland_common.c b/gfx/common/wayland_common.c index ad7c05ad6c..4931e1dede 100644 --- a/gfx/common/wayland_common.c +++ b/gfx/common/wayland_common.c @@ -40,7 +40,7 @@ #define DEFAULT_WINDOWED_WIDTH 640 #define DEFAULT_WINDOWED_HEIGHT 480 -// Icon is 16x15 scaled by 16 +/* Icon is 16x15 scaled by 16 */ #define SPLASH_WINDOW_WIDTH 240 #define SPLASH_WINDOW_HEIGHT 256 @@ -89,7 +89,7 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl, int32_t width, int32_t height, struct wl_array *states) { const uint32_t *state; - bool floating = true; + bool floating = true; wl->fullscreen = false; wl->maximized = false; @@ -100,23 +100,23 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl, { case XDG_TOPLEVEL_STATE_FULLSCREEN: wl->fullscreen = true; - floating = false; + floating = false; break; case XDG_TOPLEVEL_STATE_MAXIMIZED: - wl->maximized = true; - floating = false; + wl->maximized = true; + floating = false; break; case XDG_TOPLEVEL_STATE_TILED_LEFT: case XDG_TOPLEVEL_STATE_TILED_RIGHT: case XDG_TOPLEVEL_STATE_TILED_TOP: case XDG_TOPLEVEL_STATE_TILED_BOTTOM: - floating = false; + floating = false; break; case XDG_TOPLEVEL_STATE_RESIZING: - wl->resize = true; + wl->resize = true; break; case XDG_TOPLEVEL_STATE_ACTIVATED: - wl->activated = true; + wl->activated = true; break; } } @@ -127,14 +127,14 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl, height = wl->floating_height; } - if ( width > 0 - && height > 0) + if ( (width > 0) + && (height > 0)) { - wl->width = width; - wl->height = height; + wl->width = width; + wl->height = height; wl->buffer_width = wl->width * wl->buffer_scale; wl->buffer_height = wl->height * wl->buffer_scale; - wl->resize = true; + wl->resize = true; if (wl->viewport) update_viewport(wl); } @@ -147,11 +147,7 @@ void xdg_toplevel_handle_configure_common(gfx_ctx_wayland_data_t *wl, } void xdg_toplevel_handle_close(void *data, - struct xdg_toplevel *xdg_toplevel) -{ - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - command_event(CMD_EVENT_QUIT, NULL); -} + struct xdg_toplevel *xdg_toplevel) { command_event(CMD_EVENT_QUIT, NULL); } #ifdef HAVE_LIBDECOR_H void libdecor_frame_handle_configure_common(struct libdecor_frame *frame, @@ -218,23 +214,18 @@ void libdecor_frame_handle_configure_common(struct libdecor_frame *frame, } void libdecor_frame_handle_close(struct libdecor_frame *frame, - void *data) -{ - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - command_event(CMD_EVENT_QUIT, NULL); -} - + void *data) { command_event(CMD_EVENT_QUIT, NULL); } void libdecor_frame_handle_commit(struct libdecor_frame *frame, - void *data) -{ - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; -} + void *data) { } #endif -void gfx_ctx_wl_get_video_size_common(gfx_ctx_wayland_data_t *wl, +void gfx_ctx_wl_get_video_size_common(void *data, unsigned *width, unsigned *height) { + gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; + if (!wl) + return; if (!wl->reported_display_size) { display_output_t *od; @@ -361,35 +352,39 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl) wl->wl_pointer = NULL; wl->wl_keyboard = NULL; - wl->width = 0; - wl->height = 0; - wl->buffer_width = 0; - wl->buffer_height = 0; + wl->width = 0; + wl->height = 0; + wl->buffer_width = 0; + wl->buffer_height = 0; } -void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl) +void gfx_ctx_wl_update_title_common(void *data) { char title[128]; + gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; title[0] = '\0'; video_driver_get_window_title(title, sizeof(title)); + if (wl) + { #ifdef HAVE_LIBDECOR_H - if (wl->libdecor) - { - if (wl && title[0]) - wl->libdecor_frame_set_title(wl->libdecor_frame, title); - } - else -#endif - { - if (wl && title[0]) + if (wl->libdecor) { - if (wl->deco) - zxdg_toplevel_decoration_v1_set_mode(wl->deco, - ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); - xdg_toplevel_set_title(wl->xdg_toplevel, title); + if (title[0]) + wl->libdecor_frame_set_title(wl->libdecor_frame, title); + } + else +#endif + { + if (title[0]) + { + if (wl->deco) + zxdg_toplevel_decoration_v1_set_mode(wl->deco, + ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE); + xdg_toplevel_set_title(wl->xdg_toplevel, title); + } } } } @@ -397,8 +392,8 @@ void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl) bool gfx_ctx_wl_get_metrics_common(void *data, enum display_metric_types type, float *value) { - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; display_output_t *od; + gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; output_info_t *oi = wl ? wl->current_output : NULL; if (!oi) @@ -419,8 +414,8 @@ bool gfx_ctx_wl_get_metrics_common(void *data, break; case DISPLAY_METRIC_DPI: - *value = (float)oi->width * 25.4f / - (float)oi->physical_width; + *value = (float)oi->width * 25.4f + / (float)oi->physical_width; break; default: @@ -745,11 +740,12 @@ bool gfx_ctx_wl_init_common( /* Bind SHM based wl_buffer to wl_surface until the vulkan surface is ready. * This shows the window which assigns us a display (wl_output) * which is usefull for HiDPI and auto selecting a display for fullscreen. */ - if (video_monitor_index == 0 && wl_list_length (&wl->all_outputs) > 1) { + if (video_monitor_index == 0 && wl_list_length (&wl->all_outputs) > 1) + { if (!wl_draw_splash_screen(wl)) RARCH_ERR("[Wayland]: Failed to draw splash screen\n"); - // Make sure splash screen is on screen and sized + /* Make sure splash screen is on screen and sized */ #ifdef HAVE_LIBDECOR_H if (wl->libdecor) { @@ -842,7 +838,7 @@ bool gfx_ctx_wl_set_video_mode_common_fullscreen(gfx_ctx_wayland_data_t *wl, if (video_monitor_index <= 0 && wl->current_output != NULL) { - oi = wl->current_output; + oi = wl->current_output; output = oi->output; RARCH_LOG("[Wayland]: Auto fullscreen on display \"%s\" \"%s\"\n", oi->make, oi->model); } @@ -892,32 +888,31 @@ bool gfx_ctx_wl_suppress_screensaver(void *data, bool state) if (!wl->idle_inhibit_manager) return false; - if (state == (!!wl->idle_inhibitor)) - return true; + if (state != (!!wl->idle_inhibitor)) + { + if (state) + { + RARCH_LOG("[Wayland]: Enabling idle inhibitor\n"); + struct zwp_idle_inhibit_manager_v1 *mgr = wl->idle_inhibit_manager; + wl->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(mgr, wl->surface); + } + else + { + RARCH_LOG("[Wayland]: Disabling the idle inhibitor\n"); + zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor); + wl->idle_inhibitor = NULL; + } + } - if (state) - { - RARCH_LOG("[Wayland]: Enabling idle inhibitor\n"); - struct zwp_idle_inhibit_manager_v1 *mgr = wl->idle_inhibit_manager; - wl->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(mgr, wl->surface); - } - else - { - RARCH_LOG("[Wayland]: Disabling the idle inhibitor\n"); - zwp_idle_inhibitor_v1_destroy(wl->idle_inhibitor); - wl->idle_inhibitor = NULL; - } return true; } float gfx_ctx_wl_get_refresh_rate(void *data) { gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - if (!wl || !wl->current_output) return false; - - return (float) wl->current_output->refresh_rate / 1000.0f; + return (float)wl->current_output->refresh_rate / 1000.0f; } bool gfx_ctx_wl_has_focus(void *data) @@ -961,8 +956,8 @@ static void shm_buffer_handle_release(void *data, } #if 0 -static void xdg_surface_handle_configure(void *data, struct xdg_surface *surface, - uint32_t serial) +static void xdg_surface_handle_configure(void *data, + struct xdg_surface *surface, uint32_t serial) { xdg_surface_ack_configure(surface, serial); } diff --git a/gfx/common/wayland_common.h b/gfx/common/wayland_common.h index eae66001b5..a5e1c903b0 100644 --- a/gfx/common/wayland_common.h +++ b/gfx/common/wayland_common.h @@ -53,12 +53,12 @@ void libdecor_frame_handle_commit(struct libdecor_frame *frame, void *data); #endif -void gfx_ctx_wl_get_video_size_common(gfx_ctx_wayland_data_t *wl, - unsigned *width, unsigned *height); +void gfx_ctx_wl_get_video_size_common(void *data, unsigned *width, + unsigned *height); void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl); -void gfx_ctx_wl_update_title_common(gfx_ctx_wayland_data_t *wl); +void gfx_ctx_wl_update_title_common(void *data); bool gfx_ctx_wl_get_metrics_common(void *data, enum display_metric_types type, float *value); diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index 1bfd88862a..4c883f093f 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -79,14 +79,6 @@ static void xdg_toplevel_handle_configure(void *data, wl->configured = false; } -static void gfx_ctx_wl_get_video_size(void *data, - unsigned *width, unsigned *height) -{ - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - - gfx_ctx_wl_get_video_size_common(wl, width, height); -} - static void gfx_ctx_wl_destroy_resources(gfx_ctx_wayland_data_t *wl) { if (!wl) @@ -110,14 +102,14 @@ static void gfx_ctx_wl_check_window(void *data, bool *quit, bool *resize, unsigned *width, unsigned *height) { gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - gfx_ctx_wl_check_window_common(wl, gfx_ctx_wl_get_video_size, quit, resize, width, height); + gfx_ctx_wl_check_window_common(wl, gfx_ctx_wl_get_video_size_common, quit, resize, width, height); } static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height) { gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - wl->last_buffer_scale = wl->buffer_scale; + wl->last_buffer_scale = wl->buffer_scale; wl_surface_set_buffer_scale(wl->surface, wl->buffer_scale); #ifdef HAVE_EGL @@ -127,19 +119,6 @@ static bool gfx_ctx_wl_set_resize(void *data, unsigned width, unsigned height) return true; } -static void gfx_ctx_wl_update_title(void *data) -{ - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - gfx_ctx_wl_update_title_common(wl); -} - -static bool gfx_ctx_wl_get_metrics(void *data, - enum display_metric_types type, float *value) -{ - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - return gfx_ctx_wl_get_metrics_common(wl, type, value); -} - #ifdef HAVE_LIBDECOR_H static void libdecor_frame_handle_configure(struct libdecor_frame *frame, @@ -155,7 +134,7 @@ libdecor_frame_handle_configure(struct libdecor_frame *frame, wl->buffer_height, 0, 0); else - wl->win = wl_egl_window_create( + wl->win = wl_egl_window_create( wl->surface, wl->buffer_width, wl->buffer_height); @@ -474,7 +453,7 @@ static bool gfx_ctx_wl_bind_api(void *data, #ifdef HAVE_OPENGL #ifndef EGL_KHR_create_context if ((major * 1000 + minor) >= 3001) - return false; + break; #endif #ifdef HAVE_EGL if (egl_bind_api(EGL_OPENGL_API)) @@ -486,7 +465,7 @@ static bool gfx_ctx_wl_bind_api(void *data, #ifdef HAVE_OPENGLES #ifndef EGL_KHR_create_context if (major >= 3) - return false; + break; #endif #ifdef HAVE_EGL if (egl_bind_api(EGL_OPENGL_ES_API)) @@ -527,11 +506,10 @@ static const struct wl_callback_listener wl_surface_frame_listener = { static void gfx_ctx_wl_swap_buffers(void *data) { #ifdef HAVE_EGL - gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - + struct wl_callback *cb; + gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; settings_t *settings = config_get_ptr(); unsigned max_swapchain_images = settings->uints.video_max_swapchain_images; - struct wl_callback *cb; if (max_swapchain_images <= 2) { @@ -628,14 +606,14 @@ const gfx_ctx_driver_t gfx_ctx_wayland = { gfx_ctx_wl_bind_api, gfx_ctx_wl_set_swap_interval, gfx_ctx_wl_set_video_mode, - gfx_ctx_wl_get_video_size, + gfx_ctx_wl_get_video_size_common, gfx_ctx_wl_get_refresh_rate, NULL, /* get_video_output_size */ NULL, /* get_video_output_prev */ NULL, /* get_video_output_next */ - gfx_ctx_wl_get_metrics, + gfx_ctx_wl_get_metrics_common, NULL, - gfx_ctx_wl_update_title, + gfx_ctx_wl_update_title_common, gfx_ctx_wl_check_window, gfx_ctx_wl_set_resize, gfx_ctx_wl_has_focus,