(Drivers context) Move more static global state to structs

This commit is contained in:
twinaphex 2020-03-07 18:21:49 +01:00
parent 3aa8afd60d
commit 0d543baa4b
8 changed files with 60 additions and 66 deletions

View File

@ -278,7 +278,6 @@ static void frontend_switch_get_environment_settings(
sizeof(g_defaults.path.config)); sizeof(g_defaults.path.config));
} }
extern switch_ctx_data_t *nx_ctx_ptr;
static void frontend_switch_deinit(void *data) static void frontend_switch_deinit(void *data)
{ {
(void)data; (void)data;

View File

@ -46,8 +46,11 @@ typedef struct
unsigned fb_height; unsigned fb_height;
} emscripten_ctx_data_t; } 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_width;
static int emscripten_initial_height; static int emscripten_initial_height;
static enum gfx_ctx_api emscripten_api = GFX_CTX_NONE; static enum gfx_ctx_api emscripten_api = GFX_CTX_NONE;
static void gfx_ctx_emscripten_swap_interval(void *data, int interval) 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) if (input_width == 0 || input_height == 0)
{ {
input_width = emscripten_initial_width; input_width = emscripten_initial_width;
input_height = emscripten_initial_height; input_height = emscripten_initial_height;
emscripten->fb_width = emscripten->fb_height = 0; emscripten->fb_width = emscripten->fb_height = 0;
} }
@ -202,6 +205,8 @@ static void *gfx_ctx_emscripten_init(void *video_driver)
(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) if (emscripten_initial_width == 0 || emscripten_initial_height == 0)
emscripten_get_canvas_element_size("#canvas", emscripten_get_canvas_element_size("#canvas",
&emscripten_initial_width, &emscripten_initial_height); &emscripten_initial_width, &emscripten_initial_height);

View File

@ -99,8 +99,6 @@ static void gfx_ctx_fpga_input_driver(void *data,
const char *joypad_name, const char *joypad_name,
const input_driver_t **input, void **input_data) 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) static bool gfx_ctx_fpga_has_focus(void *data)

View File

@ -28,8 +28,6 @@
static enum gfx_ctx_api ctx_orbis_api = GFX_CTX_OPENGL_API; 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; extern bool platform_orbis_has_focus;
void orbis_ctx_destroy(void *data) void orbis_ctx_destroy(void *data)
@ -80,8 +78,6 @@ static void *orbis_ctx_init(void *video_driver)
if (!ctx_orbis) if (!ctx_orbis)
return NULL; return NULL;
nx_ctx_ptr = ctx_orbis;
#ifdef HAVE_EGL #ifdef HAVE_EGL
memset(&ctx_orbis->pgl_config, 0, sizeof(ctx_orbis->pgl_config)); memset(&ctx_orbis->pgl_config, 0, sizeof(ctx_orbis->pgl_config));

View File

@ -44,8 +44,8 @@
static bool g_osmesa_profile = OSMESA_COMPAT_PROFILE; static bool g_osmesa_profile = OSMESA_COMPAT_PROFILE;
static int g_osmesa_major = 2; static int g_osmesa_major = 2;
static int g_osmesa_minor = 1; static int g_osmesa_minor = 1;
static int g_osmesa_format = OSMESA_RGBA; static const int g_osmesa_format = OSMESA_RGBA;
static int g_osmesa_bpp = 4; static const int g_osmesa_bpp = 4;
static const char *g_osmesa_fifo = "/tmp/osmesa-retroarch.sock"; static const char *g_osmesa_fifo = "/tmp/osmesa-retroarch.sock";
static enum gfx_ctx_api osmesa_api = GFX_CTX_NONE; static enum gfx_ctx_api osmesa_api = GFX_CTX_NONE;

View File

@ -33,8 +33,6 @@
#endif #endif
static enum gfx_ctx_api sdl_api = GFX_CTX_OPENGL_API; 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 typedef struct gfx_ctx_sdl_data
{ {
@ -151,8 +149,6 @@ static bool sdl_ctx_bind_api(void *data,
#endif #endif
sdl_api = api; sdl_api = api;
g_major = major;
g_minor = minor;
#ifndef HAVE_SDL2 #ifndef HAVE_SDL2
if (api != GFX_CTX_OPENGL_API) if (api != GFX_CTX_OPENGL_API)

View File

@ -28,7 +28,6 @@
#include "../../frontend/frontend_driver.h" #include "../../frontend/frontend_driver.h"
static enum gfx_ctx_api ctx_nx_api = GFX_CTX_OPENGL_API; 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; extern bool platform_switch_has_focus;
@ -81,8 +80,6 @@ static void *switch_ctx_init(void *video_driver)
if (!ctx_nx) if (!ctx_nx)
return NULL; return NULL;
nx_ctx_ptr = ctx_nx;
/* Comment below to enable error checking */ /* Comment below to enable error checking */
setenv("MESA_NO_ERROR", "1", 1); setenv("MESA_NO_ERROR", "1", 1);

View File

@ -86,8 +86,6 @@ typedef struct output_info
struct wl_list link; /* wl->all_outputs */ struct wl_list link; /* wl->all_outputs */
} output_info_t; } output_info_t;
static int num_active_touches;
static touch_pos_t active_touch_positions[MAX_TOUCHES];
typedef struct gfx_ctx_wayland_data typedef struct gfx_ctx_wayland_data
{ {
@ -144,6 +142,8 @@ typedef struct gfx_ctx_wayland_data
#ifdef HAVE_VULKAN #ifdef HAVE_VULKAN
gfx_ctx_vulkan_data_t vk; gfx_ctx_vulkan_data_t vk;
#endif #endif
int num_active_touches;
touch_pos_t active_touch_positions[MAX_TOUCHES];
} gfx_ctx_wayland_data_t; } gfx_ctx_wayland_data_t;
static enum gfx_ctx_api wl_api = GFX_CTX_NONE; static enum gfx_ctx_api wl_api = GFX_CTX_NONE;
@ -406,49 +406,49 @@ static void touch_handle_down(void *data,
int i; int i;
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data; 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++) for (i = 0; i < MAX_TOUCHES; i++)
{ {
/* Use next empty slot */ /* 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; wl->active_touch_positions[wl->num_active_touches].active = true;
active_touch_positions[num_active_touches].id = id; wl->active_touch_positions[wl->num_active_touches].id = id;
active_touch_positions[num_active_touches].x = (unsigned) wl->active_touch_positions[wl->num_active_touches].x = (unsigned)
wl_fixed_to_int(x); 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); wl_fixed_to_int(y);
num_active_touches++; wl->num_active_touches++;
break; break;
} }
} }
} }
} }
static void reorder_touches(void) static void reorder_touches(gfx_ctx_wayland_data_t *wl)
{ {
int i, j; int i, j;
if (num_active_touches == 0) if (wl->num_active_touches == 0)
return; return;
for (i = 0; i < MAX_TOUCHES; i++) for (i = 0; i < MAX_TOUCHES; i++)
{ {
if (!active_touch_positions[i].active) if (!wl->active_touch_positions[i].active)
{ {
for (j=i+1; j<MAX_TOUCHES; j++) for (j=i+1; j<MAX_TOUCHES; j++)
{ {
if (active_touch_positions[j].active) if (wl->active_touch_positions[j].active)
{ {
active_touch_positions[i].active = wl->active_touch_positions[i].active =
active_touch_positions[j].active; wl->active_touch_positions[j].active;
active_touch_positions[i].id = wl->active_touch_positions[i].id =
active_touch_positions[j].id; wl->active_touch_positions[j].id;
active_touch_positions[i].x = active_touch_positions[j].x; wl->active_touch_positions[i].x = wl->active_touch_positions[j].x;
active_touch_positions[i].y = active_touch_positions[j].y; wl->active_touch_positions[i].y = wl->active_touch_positions[j].y;
active_touch_positions[j].active = false; wl->active_touch_positions[j].active = false;
active_touch_positions[j].id = -1; wl->active_touch_positions[j].id = -1;
active_touch_positions[j].x = (unsigned) 0; wl->active_touch_positions[j].x = (unsigned) 0;
active_touch_positions[j].y = (unsigned) 0; wl->active_touch_positions[j].y = (unsigned) 0;
break; break;
} }
@ -470,18 +470,19 @@ static void touch_handle_up(void *data,
for (i = 0; i < MAX_TOUCHES; i++) for (i = 0; i < MAX_TOUCHES; i++)
{ {
if ( active_touch_positions[i].active && if ( wl->active_touch_positions[i].active &&
active_touch_positions[i].id == id) wl->active_touch_positions[i].id == id)
{ {
active_touch_positions[i].active = false; wl->active_touch_positions[i].active = false;
active_touch_positions[i].id = -1; wl->active_touch_positions[i].id = -1;
active_touch_positions[i].x = (unsigned)0; wl->active_touch_positions[i].x = (unsigned)0;
active_touch_positions[i].y = (unsigned)0; wl->active_touch_positions[i].y = (unsigned)0;
num_active_touches--; wl->num_active_touches--;
} }
} }
reorder_touches(); reorder_touches(wl);
} }
static void touch_handle_motion(void *data, static void touch_handle_motion(void *data,
struct wl_touch *wl_touch, struct wl_touch *wl_touch,
uint32_t time, uint32_t time,
@ -494,11 +495,11 @@ static void touch_handle_motion(void *data,
for (i = 0; i < MAX_TOUCHES; i++) for (i = 0; i < MAX_TOUCHES; i++)
{ {
if ( active_touch_positions[i].active && if ( wl->active_touch_positions[i].active &&
active_touch_positions[i].id == id) wl->active_touch_positions[i].id == id)
{ {
active_touch_positions[i].x = (unsigned) wl_fixed_to_int(x); wl->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].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++) for (i = 0; i < MAX_TOUCHES; i++)
{ {
active_touch_positions[i].active = false; wl->active_touch_positions[i].active = false;
active_touch_positions[i].id = -1; wl->active_touch_positions[i].id = -1;
active_touch_positions[i].x = (unsigned) 0; wl->active_touch_positions[i].x = (unsigned) 0;
active_touch_positions[i].y = (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 = { static const struct wl_touch_listener touch_listener = {
touch_handle_down, touch_handle_down,
@ -592,9 +594,9 @@ bool wayland_context_gettouchpos(void *data, unsigned id,
if (id >= MAX_TOUCHES) if (id >= MAX_TOUCHES)
return false; return false;
*touch_x = active_touch_positions[id].x; *touch_x = wl->active_touch_positions[id].x;
*touch_y = active_touch_positions[id].y; *touch_y = wl->active_touch_positions[id].y;
return active_touch_positions[id].active; return wl->active_touch_positions[id].active;
} }
/* Surface callbacks. */ /* 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.theme = wl_cursor_theme_load(NULL, 16, wl->shm);
wl->cursor.default_cursor = wl_cursor_theme_get_cursor(wl->cursor.theme, "left_ptr"); 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++) for (i = 0;i < MAX_TOUCHES;i++)
{ {
active_touch_positions[i].active = false; wl->active_touch_positions[i].active = false;
active_touch_positions[i].id = -1; wl->active_touch_positions[i].id = -1;
active_touch_positions[i].x = (unsigned) 0; wl->active_touch_positions[i].x = (unsigned) 0;
active_touch_positions[i].y = (unsigned) 0; wl->active_touch_positions[i].y = (unsigned) 0;
} }
flush_wayland_fd(&wl->input); flush_wayland_fd(&wl->input);