From 0d543baa4b6c8e86b53afb05cd041370b16b340f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 7 Mar 2020 18:21:49 +0100 Subject: [PATCH] (Drivers context) Move more static global state to structs --- frontend/drivers/platform_switch.c | 1 - gfx/drivers_context/emscriptenegl_ctx.c | 9 ++- gfx/drivers_context/fpga_ctx.c | 2 - gfx/drivers_context/orbis_ctx.c | 4 - gfx/drivers_context/osmesa_ctx.c | 4 +- gfx/drivers_context/sdl_gl_ctx.c | 4 - gfx/drivers_context/switch_ctx.c | 3 - gfx/drivers_context/wayland_ctx.c | 99 +++++++++++++------------ 8 files changed, 60 insertions(+), 66 deletions(-) diff --git a/frontend/drivers/platform_switch.c b/frontend/drivers/platform_switch.c index 791136bd13..d3975496c9 100644 --- a/frontend/drivers/platform_switch.c +++ b/frontend/drivers/platform_switch.c @@ -278,7 +278,6 @@ static void frontend_switch_get_environment_settings( sizeof(g_defaults.path.config)); } -extern switch_ctx_data_t *nx_ctx_ptr; static void frontend_switch_deinit(void *data) { (void)data; diff --git a/gfx/drivers_context/emscriptenegl_ctx.c b/gfx/drivers_context/emscriptenegl_ctx.c index 9353bd16a5..85fb7eeeb6 100644 --- a/gfx/drivers_context/emscriptenegl_ctx.c +++ b/gfx/drivers_context/emscriptenegl_ctx.c @@ -46,8 +46,11 @@ typedef struct unsigned fb_height; } emscripten_ctx_data_t; +/* TODO/FIXME - would like to move these to emscripten_ctx_data_t - + * see the TODO/FIXME note down below */ static int emscripten_initial_width; static int emscripten_initial_height; + static enum gfx_ctx_api emscripten_api = GFX_CTX_NONE; static void gfx_ctx_emscripten_swap_interval(void *data, int interval) @@ -102,8 +105,8 @@ static void gfx_ctx_emscripten_check_window(void *data, bool *quit, if (input_width == 0 || input_height == 0) { - input_width = emscripten_initial_width; - input_height = emscripten_initial_height; + input_width = emscripten_initial_width; + input_height = emscripten_initial_height; emscripten->fb_width = emscripten->fb_height = 0; } @@ -202,6 +205,8 @@ static void *gfx_ctx_emscripten_init(void *video_driver) (void)video_driver; + /* TODO/FIXME - why is this conditional here - shouldn't these always + * be grabbed? */ if (emscripten_initial_width == 0 || emscripten_initial_height == 0) emscripten_get_canvas_element_size("#canvas", &emscripten_initial_width, &emscripten_initial_height); diff --git a/gfx/drivers_context/fpga_ctx.c b/gfx/drivers_context/fpga_ctx.c index e9a769c5b1..66b1c030dc 100644 --- a/gfx/drivers_context/fpga_ctx.c +++ b/gfx/drivers_context/fpga_ctx.c @@ -99,8 +99,6 @@ static void gfx_ctx_fpga_input_driver(void *data, const char *joypad_name, const input_driver_t **input, void **input_data) { - (void)data; - settings_t *settings = config_get_ptr(); } static bool gfx_ctx_fpga_has_focus(void *data) diff --git a/gfx/drivers_context/orbis_ctx.c b/gfx/drivers_context/orbis_ctx.c index ede966e248..a56f96ba5e 100644 --- a/gfx/drivers_context/orbis_ctx.c +++ b/gfx/drivers_context/orbis_ctx.c @@ -28,8 +28,6 @@ static enum gfx_ctx_api ctx_orbis_api = GFX_CTX_OPENGL_API; -orbis_ctx_data_t *nx_ctx_ptr = NULL; - extern bool platform_orbis_has_focus; void orbis_ctx_destroy(void *data) @@ -80,8 +78,6 @@ static void *orbis_ctx_init(void *video_driver) if (!ctx_orbis) return NULL; - nx_ctx_ptr = ctx_orbis; - #ifdef HAVE_EGL memset(&ctx_orbis->pgl_config, 0, sizeof(ctx_orbis->pgl_config)); diff --git a/gfx/drivers_context/osmesa_ctx.c b/gfx/drivers_context/osmesa_ctx.c index 63a8c21506..6bd2336088 100644 --- a/gfx/drivers_context/osmesa_ctx.c +++ b/gfx/drivers_context/osmesa_ctx.c @@ -44,8 +44,8 @@ static bool g_osmesa_profile = OSMESA_COMPAT_PROFILE; static int g_osmesa_major = 2; static int g_osmesa_minor = 1; -static int g_osmesa_format = OSMESA_RGBA; -static int g_osmesa_bpp = 4; +static const int g_osmesa_format = OSMESA_RGBA; +static const int g_osmesa_bpp = 4; static const char *g_osmesa_fifo = "/tmp/osmesa-retroarch.sock"; static enum gfx_ctx_api osmesa_api = GFX_CTX_NONE; diff --git a/gfx/drivers_context/sdl_gl_ctx.c b/gfx/drivers_context/sdl_gl_ctx.c index 5666cd342f..9c0c475ae7 100644 --- a/gfx/drivers_context/sdl_gl_ctx.c +++ b/gfx/drivers_context/sdl_gl_ctx.c @@ -33,8 +33,6 @@ #endif static enum gfx_ctx_api sdl_api = GFX_CTX_OPENGL_API; -static unsigned g_major = 2; -static unsigned g_minor = 1; typedef struct gfx_ctx_sdl_data { @@ -151,8 +149,6 @@ static bool sdl_ctx_bind_api(void *data, #endif sdl_api = api; - g_major = major; - g_minor = minor; #ifndef HAVE_SDL2 if (api != GFX_CTX_OPENGL_API) diff --git a/gfx/drivers_context/switch_ctx.c b/gfx/drivers_context/switch_ctx.c index ec30b43e31..a6cf2dc278 100644 --- a/gfx/drivers_context/switch_ctx.c +++ b/gfx/drivers_context/switch_ctx.c @@ -28,7 +28,6 @@ #include "../../frontend/frontend_driver.h" static enum gfx_ctx_api ctx_nx_api = GFX_CTX_OPENGL_API; -switch_ctx_data_t *nx_ctx_ptr = NULL; extern bool platform_switch_has_focus; @@ -81,8 +80,6 @@ static void *switch_ctx_init(void *video_driver) if (!ctx_nx) return NULL; - nx_ctx_ptr = ctx_nx; - /* Comment below to enable error checking */ setenv("MESA_NO_ERROR", "1", 1); diff --git a/gfx/drivers_context/wayland_ctx.c b/gfx/drivers_context/wayland_ctx.c index e2c16609bc..f6368705a3 100644 --- a/gfx/drivers_context/wayland_ctx.c +++ b/gfx/drivers_context/wayland_ctx.c @@ -86,8 +86,6 @@ typedef struct output_info struct wl_list link; /* wl->all_outputs */ } output_info_t; -static int num_active_touches; -static touch_pos_t active_touch_positions[MAX_TOUCHES]; typedef struct gfx_ctx_wayland_data { @@ -144,6 +142,8 @@ typedef struct gfx_ctx_wayland_data #ifdef HAVE_VULKAN gfx_ctx_vulkan_data_t vk; #endif + int num_active_touches; + touch_pos_t active_touch_positions[MAX_TOUCHES]; } gfx_ctx_wayland_data_t; static enum gfx_ctx_api wl_api = GFX_CTX_NONE; @@ -406,49 +406,49 @@ static void touch_handle_down(void *data, int i; gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; - if (num_active_touches < MAX_TOUCHES) + if (wl->num_active_touches < MAX_TOUCHES) { for (i = 0; i < MAX_TOUCHES; i++) { /* Use next empty slot */ - if (!active_touch_positions[i].active) + if (!wl->active_touch_positions[i].active) { - active_touch_positions[num_active_touches].active = true; - active_touch_positions[num_active_touches].id = id; - active_touch_positions[num_active_touches].x = (unsigned) + wl->active_touch_positions[wl->num_active_touches].active = true; + wl->active_touch_positions[wl->num_active_touches].id = id; + wl->active_touch_positions[wl->num_active_touches].x = (unsigned) wl_fixed_to_int(x); - active_touch_positions[num_active_touches].y = (unsigned) + wl->active_touch_positions[wl->num_active_touches].y = (unsigned) wl_fixed_to_int(y); - num_active_touches++; + wl->num_active_touches++; break; } } } } -static void reorder_touches(void) +static void reorder_touches(gfx_ctx_wayland_data_t *wl) { int i, j; - if (num_active_touches == 0) + if (wl->num_active_touches == 0) return; for (i = 0; i < MAX_TOUCHES; i++) { - if (!active_touch_positions[i].active) + if (!wl->active_touch_positions[i].active) { for (j=i+1; jactive_touch_positions[j].active) { - active_touch_positions[i].active = - active_touch_positions[j].active; - active_touch_positions[i].id = - active_touch_positions[j].id; - active_touch_positions[i].x = active_touch_positions[j].x; - active_touch_positions[i].y = active_touch_positions[j].y; - active_touch_positions[j].active = false; - active_touch_positions[j].id = -1; - active_touch_positions[j].x = (unsigned) 0; - active_touch_positions[j].y = (unsigned) 0; + wl->active_touch_positions[i].active = + wl->active_touch_positions[j].active; + wl->active_touch_positions[i].id = + wl->active_touch_positions[j].id; + wl->active_touch_positions[i].x = wl->active_touch_positions[j].x; + wl->active_touch_positions[i].y = wl->active_touch_positions[j].y; + wl->active_touch_positions[j].active = false; + wl->active_touch_positions[j].id = -1; + wl->active_touch_positions[j].x = (unsigned) 0; + wl->active_touch_positions[j].y = (unsigned) 0; break; } @@ -470,18 +470,19 @@ static void touch_handle_up(void *data, for (i = 0; i < MAX_TOUCHES; i++) { - if ( active_touch_positions[i].active && - active_touch_positions[i].id == id) + if ( wl->active_touch_positions[i].active && + wl->active_touch_positions[i].id == id) { - active_touch_positions[i].active = false; - active_touch_positions[i].id = -1; - active_touch_positions[i].x = (unsigned)0; - active_touch_positions[i].y = (unsigned)0; - num_active_touches--; + wl->active_touch_positions[i].active = false; + wl->active_touch_positions[i].id = -1; + wl->active_touch_positions[i].x = (unsigned)0; + wl->active_touch_positions[i].y = (unsigned)0; + wl->num_active_touches--; } } - reorder_touches(); + reorder_touches(wl); } + static void touch_handle_motion(void *data, struct wl_touch *wl_touch, uint32_t time, @@ -494,11 +495,11 @@ static void touch_handle_motion(void *data, for (i = 0; i < MAX_TOUCHES; i++) { - if ( active_touch_positions[i].active && - active_touch_positions[i].id == id) + if ( wl->active_touch_positions[i].active && + wl->active_touch_positions[i].id == id) { - active_touch_positions[i].x = (unsigned) wl_fixed_to_int(x); - active_touch_positions[i].y = (unsigned) wl_fixed_to_int(y); + wl->active_touch_positions[i].x = (unsigned) wl_fixed_to_int(x); + wl->active_touch_positions[i].y = (unsigned) wl_fixed_to_int(y); } } } @@ -517,12 +518,13 @@ static void touch_handle_cancel(void *data, for (i = 0; i < MAX_TOUCHES; i++) { - active_touch_positions[i].active = false; - active_touch_positions[i].id = -1; - active_touch_positions[i].x = (unsigned) 0; - active_touch_positions[i].y = (unsigned) 0; + wl->active_touch_positions[i].active = false; + wl->active_touch_positions[i].id = -1; + wl->active_touch_positions[i].x = (unsigned) 0; + wl->active_touch_positions[i].y = (unsigned) 0; } - num_active_touches = 0; + + wl->num_active_touches = 0; } static const struct wl_touch_listener touch_listener = { touch_handle_down, @@ -592,9 +594,9 @@ bool wayland_context_gettouchpos(void *data, unsigned id, if (id >= MAX_TOUCHES) return false; - *touch_x = active_touch_positions[id].x; - *touch_y = active_touch_positions[id].y; - return active_touch_positions[id].active; + *touch_x = wl->active_touch_positions[id].x; + *touch_y = wl->active_touch_positions[id].y; + return wl->active_touch_positions[id].active; } /* Surface callbacks. */ @@ -1390,13 +1392,14 @@ static void *gfx_ctx_wl_init(void *video_driver) wl->cursor.theme = wl_cursor_theme_load(NULL, 16, wl->shm); wl->cursor.default_cursor = wl_cursor_theme_get_cursor(wl->cursor.theme, "left_ptr"); - num_active_touches = 0; + wl->num_active_touches = 0; + for (i = 0;i < MAX_TOUCHES;i++) { - active_touch_positions[i].active = false; - active_touch_positions[i].id = -1; - active_touch_positions[i].x = (unsigned) 0; - active_touch_positions[i].y = (unsigned) 0; + wl->active_touch_positions[i].active = false; + wl->active_touch_positions[i].id = -1; + wl->active_touch_positions[i].x = (unsigned) 0; + wl->active_touch_positions[i].y = (unsigned) 0; } flush_wayland_fd(&wl->input);