Decouple 'overlay' state from driver_t

This commit is contained in:
twinaphex 2015-07-09 01:10:30 +02:00
parent 387d687ef9
commit cdf3ce309e
9 changed files with 163 additions and 102 deletions

View File

@ -1261,41 +1261,19 @@ bool event_command(enum event_command cmd)
break;
case EVENT_CMD_OVERLAY_DEINIT:
#ifdef HAVE_OVERLAY
if (driver->overlay)
input_overlay_free(driver->overlay);
driver->overlay = NULL;
memset(&driver->overlay_state, 0, sizeof(driver->overlay_state));
input_overlay_free_ptr();
#endif
break;
case EVENT_CMD_OVERLAY_INIT:
event_command(EVENT_CMD_OVERLAY_DEINIT);
#ifdef HAVE_OVERLAY
if (driver->osk_enable)
{
if (!*settings->osk.overlay)
break;
}
else
{
if (!*settings->input.overlay)
break;
}
driver->overlay = input_overlay_new(
driver->osk_enable ?
settings->osk.overlay : settings->input.overlay,
driver->osk_enable ?
settings->osk.enable : settings->input.overlay_enable,
settings->input.overlay_opacity,
settings->input.overlay_scale);
if (!driver->overlay)
if (input_overlay_new_ptr() == -1)
RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_OVERLAY));
#endif
break;
case EVENT_CMD_OVERLAY_NEXT:
#ifdef HAVE_OVERLAY
input_overlay_next(driver->overlay, settings->input.overlay_opacity);
input_overlay_next(input_overlay_get_ptr(), settings->input.overlay_opacity);
#endif
break;
case EVENT_CMD_DSP_FILTER_DEINIT:
@ -1395,13 +1373,13 @@ bool event_command(enum event_command cmd)
break;
case EVENT_CMD_OVERLAY_SET_SCALE_FACTOR:
#ifdef HAVE_OVERLAY
input_overlay_set_scale_factor(driver->overlay,
input_overlay_set_scale_factor(input_overlay_get_ptr(),
settings->input.overlay_scale);
#endif
break;
case EVENT_CMD_OVERLAY_SET_ALPHA_MOD:
#ifdef HAVE_OVERLAY
input_overlay_set_alpha_mod(driver->overlay,
input_overlay_set_alpha_mod(input_overlay_get_ptr(),
settings->input.overlay_opacity);
#endif
break;

View File

@ -287,11 +287,6 @@ typedef struct driver
* TODO: Refactor this better. */
bool gfx_use_rgba;
#ifdef HAVE_OVERLAY
input_overlay_t *overlay;
input_overlay_state_t overlay_state;
#endif
/* Interface for "poking". */
const video_poke_interface_t *video_poke;

View File

@ -213,9 +213,10 @@ bool input_driver_key_pressed(int key)
retro_input_t input_driver_keys_pressed(void)
{
int key;
retro_input_t ret = 0;
driver_t *driver = driver_get_ptr();
const input_driver_t *input = input_get_ptr(driver);
retro_input_t ret = 0;
driver_t *driver = driver_get_ptr();
const input_driver_t *input = input_get_ptr(driver);
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
for (key = 0; key < RARCH_BIND_LIST_END; key++)
{
@ -225,7 +226,8 @@ retro_input_t input_driver_keys_pressed(void)
state = input->key_pressed(driver->input_data, key);
#ifdef HAVE_OVERLAY
state = state || (driver->overlay_state.buttons & (1ULL << key));
if (ol_state)
state = state || (ol_state->buttons & (1ULL << key));
#endif
#ifdef HAVE_COMMAND

View File

@ -26,6 +26,7 @@
#include <rhash.h>
#include "input_overlay.h"
#include "../configuration.h"
#include "../driver.h"
#include "input_common.h"
@ -35,6 +36,33 @@
#define KEY_ANALOG_LEFT 0x56b92e81U
#define KEY_ANALOG_RIGHT 0x2e4dc654U
static input_overlay_t *overlay_ptr;
static input_overlay_state_t *overlay_state_ptr;
input_overlay_t *input_overlay_get_ptr(void)
{
return overlay_ptr;
}
input_overlay_state_t *input_overlay_get_state_ptr(void)
{
return overlay_state_ptr;
}
bool input_overlay_is_active(void)
{
input_overlay_t *overlay = input_overlay_get_ptr();
if (!overlay)
return false;
if (overlay->state == OVERLAY_STATUS_ALIVE)
return false;
if (overlay->state == OVERLAY_STATUS_NONE)
return false;
return true;
}
/**
* input_overlay_scale:
* @ol : Overlay handle.
@ -1156,6 +1184,54 @@ void input_overlay_free(input_overlay_t *ol)
free(ol);
}
void input_overlay_free_ptr(void)
{
input_overlay_free(overlay_ptr);
overlay_ptr = NULL;
if (overlay_state_ptr)
free(overlay_state_ptr);
overlay_state_ptr = NULL;
}
int input_overlay_new_ptr(void)
{
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
if (driver->osk_enable)
{
if (!*settings->osk.overlay)
return 1;
}
else
{
if (!*settings->input.overlay)
return 1;
}
overlay_state_ptr = (input_overlay_state_t *)calloc(1, sizeof(*overlay_state_ptr));
if (!overlay_state_ptr)
return -1;
overlay_ptr = input_overlay_new(
driver->osk_enable ?
settings->osk.overlay : settings->input.overlay,
driver->osk_enable ?
settings->osk.enable : settings->input.overlay_enable,
settings->input.overlay_opacity,
settings->input.overlay_scale);
if (!overlay_ptr)
{
free(overlay_state_ptr);
return -1;
}
return 0;
}
/**
* input_overlay_set_alpha_mod:
* @ol : Overlay handle.

View File

@ -338,6 +338,16 @@ void input_overlay_set_scale_factor(input_overlay_t *ol, float scale);
**/
void input_overlay_next(input_overlay_t *ol, float opacity);
input_overlay_t *input_overlay_get_ptr(void);
input_overlay_state_t *input_overlay_get_state_ptr(void);
bool input_overlay_is_active(void);
void input_overlay_free_ptr(void);
int input_overlay_new_ptr(void);
#ifdef __cplusplus
}
#endif

View File

@ -157,10 +157,11 @@ static int16_t input_state(unsigned port, unsigned device,
{
size_t i;
const struct retro_keybind *libretro_input_binds[MAX_USERS];
int16_t res = 0;
settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
int16_t res = 0;
settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr();
global_t *global = global_get_ptr();
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
for (i = 0; i < MAX_USERS; i++)
libretro_input_binds[i] = settings->input.binds[i];
@ -190,13 +191,13 @@ static int16_t input_state(unsigned port, unsigned device,
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (driver->overlay_state.buttons & (UINT64_C(1) << id))
if (ol_state->buttons & (UINT64_C(1) << id))
res |= 1;
break;
case RETRO_DEVICE_KEYBOARD:
if (id < RETROK_LAST)
{
if (OVERLAY_GET_KEY(&driver->overlay_state, id))
if (OVERLAY_GET_KEY(ol_state, id))
res |= 1;
}
break;
@ -208,8 +209,8 @@ static int16_t input_state(unsigned port, unsigned device,
base = 2;
if (id == RETRO_DEVICE_ID_ANALOG_Y)
base += 1;
if (driver->overlay_state.analog[base])
res = driver->overlay_state.analog[base];
if (ol_state->analog[base])
res = ol_state->analog[base];
}
break;
}
@ -245,17 +246,18 @@ static INLINE void input_poll_overlay(
{
input_overlay_state_t old_key_state;
unsigned i, j, device;
uint16_t key_mod = 0;
bool polled = false;
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
uint16_t key_mod = 0;
bool polled = false;
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
input_overlay_state_t *ol_state = input_overlay_get_state_ptr();
if (overlay_device->state != OVERLAY_STATUS_ALIVE)
if (overlay_device->state != OVERLAY_STATUS_ALIVE || !ol_state)
return;
memcpy(old_key_state.keys, driver->overlay_state.keys,
sizeof(driver->overlay_state.keys));
memset(&driver->overlay_state, 0, sizeof(driver->overlay_state));
memcpy(old_key_state.keys, ol_state->keys,
sizeof(ol_state->keys));
memset(ol_state, 0, sizeof(*ol_state));
device = input_overlay_full_screen(overlay_device) ?
RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER;
@ -273,43 +275,43 @@ static INLINE void input_poll_overlay(
input_overlay_poll(overlay_device, &polled_data, x, y);
driver->overlay_state.buttons |= polled_data.buttons;
ol_state->buttons |= polled_data.buttons;
for (j = 0; j < ARRAY_SIZE(driver->overlay_state.keys); j++)
driver->overlay_state.keys[j] |= polled_data.keys[j];
for (j = 0; j < ARRAY_SIZE(ol_state->keys); j++)
ol_state->keys[j] |= polled_data.keys[j];
/* Fingers pressed later take prio and matched up
* with overlay poll priorities. */
for (j = 0; j < 4; j++)
if (polled_data.analog[j])
driver->overlay_state.analog[j] = polled_data.analog[j];
ol_state->analog[j] = polled_data.analog[j];
polled = true;
}
if (OVERLAY_GET_KEY(&driver->overlay_state, RETROK_LSHIFT) ||
OVERLAY_GET_KEY(&driver->overlay_state, RETROK_RSHIFT))
if (OVERLAY_GET_KEY(ol_state, RETROK_LSHIFT) ||
OVERLAY_GET_KEY(ol_state, RETROK_RSHIFT))
key_mod |= RETROKMOD_SHIFT;
if (OVERLAY_GET_KEY(&driver->overlay_state, RETROK_LCTRL) ||
OVERLAY_GET_KEY(&driver->overlay_state, RETROK_RCTRL))
if (OVERLAY_GET_KEY(ol_state, RETROK_LCTRL) ||
OVERLAY_GET_KEY(ol_state, RETROK_RCTRL))
key_mod |= RETROKMOD_CTRL;
if (OVERLAY_GET_KEY(&driver->overlay_state, RETROK_LALT) ||
OVERLAY_GET_KEY(&driver->overlay_state, RETROK_RALT))
if (OVERLAY_GET_KEY(ol_state, RETROK_LALT) ||
OVERLAY_GET_KEY(ol_state, RETROK_RALT))
key_mod |= RETROKMOD_ALT;
if (OVERLAY_GET_KEY(&driver->overlay_state, RETROK_LMETA) ||
OVERLAY_GET_KEY(&driver->overlay_state, RETROK_RMETA))
if (OVERLAY_GET_KEY(ol_state, RETROK_LMETA) ||
OVERLAY_GET_KEY(ol_state, RETROK_RMETA))
key_mod |= RETROKMOD_META;
/* CAPSLOCK SCROLLOCK NUMLOCK */
for (i = 0; i < ARRAY_SIZE(driver->overlay_state.keys); i++)
for (i = 0; i < ARRAY_SIZE(ol_state->keys); i++)
{
if (driver->overlay_state.keys[i] != old_key_state.keys[i])
if (ol_state->keys[i] != old_key_state.keys[i])
{
uint32_t orig_bits = old_key_state.keys[i];
uint32_t new_bits = driver->overlay_state.keys[i];
uint32_t new_bits = ol_state->keys[i];
for (j = 0; j < 32; j++)
if ((orig_bits & (1 << j)) != (new_bits & (1 << j)))
@ -324,13 +326,13 @@ static INLINE void input_poll_overlay(
unsigned bind_plus = RARCH_ANALOG_LEFT_X_PLUS + 2 * j;
unsigned bind_minus = bind_plus + 1;
if (driver->overlay_state.analog[j])
if (ol_state->analog[j])
continue;
if (driver->overlay_state.buttons & (1UL << bind_plus))
driver->overlay_state.analog[j] += 0x7fff;
if (driver->overlay_state.buttons & (1UL << bind_minus))
driver->overlay_state.analog[j] -= 0x7fff;
if (ol_state->buttons & (1UL << bind_plus))
ol_state->analog[j] += 0x7fff;
if (ol_state->buttons & (1UL << bind_minus))
ol_state->analog[j] -= 0x7fff;
}
/* Check for analog_dpad_mode.
@ -346,17 +348,17 @@ static INLINE void input_poll_overlay(
if (settings->input.analog_dpad_mode[0] == ANALOG_DPAD_LSTICK)
analog_base = 0;
analog_x = (float)driver->overlay_state.analog[analog_base + 0] / 0x7fff;
analog_y = (float)driver->overlay_state.analog[analog_base + 1] / 0x7fff;
analog_x = (float)ol_state->analog[analog_base + 0] / 0x7fff;
analog_y = (float)ol_state->analog[analog_base + 1] / 0x7fff;
if (analog_x <= -settings->input.axis_threshold)
driver->overlay_state.buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_LEFT);
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_LEFT);
if (analog_x >= settings->input.axis_threshold)
driver->overlay_state.buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_RIGHT);
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_RIGHT);
if (analog_y <= -settings->input.axis_threshold)
driver->overlay_state.buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_UP);
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_UP);
if (analog_y >= settings->input.axis_threshold)
driver->overlay_state.buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_DOWN);
ol_state->buttons |= (1UL << RETRO_DEVICE_ID_JOYPAD_DOWN);
break;
}
@ -380,12 +382,13 @@ static void input_poll(void)
{
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
input_overlay_t *overlay = input_overlay_get_ptr();
input_driver_poll();
#ifdef HAVE_OVERLAY
if (driver->overlay)
input_poll_overlay(driver->overlay,
if (overlay)
input_poll_overlay(overlay,
settings->input.overlay_opacity);
#endif

View File

@ -595,10 +595,11 @@ static int menu_input_mouse(unsigned *action)
menu_input_t *menu_input = menu_input_get_ptr();
menu_framebuf_t *frame_buf= menu_display_fb_get_ptr();
settings_t *settings = config_get_ptr();
input_overlay_t *overlay = input_overlay_get_ptr();
if (!settings->menu.mouse.enable
#ifdef HAVE_OVERLAY
|| (settings->input.overlay_enable && driver && driver->overlay)
|| (settings->input.overlay_enable && driver && overlay)
#endif
)
{
@ -760,12 +761,13 @@ static int menu_input_mouse_post_iterate(uint64_t *input_mouse,
menu_input_t *menu_input = menu_input_get_ptr();
menu_list_t *menu_list = menu_list_get_ptr();
menu_navigation_t *nav = menu_navigation_get_ptr();
input_overlay_t *overlay = input_overlay_get_ptr();
*input_mouse = MOUSE_ACTION_NONE;
if (!settings->menu.mouse.enable
#ifdef HAVE_OVERLAY
|| (settings->input.overlay_enable && driver && driver->overlay)
|| (settings->input.overlay_enable && driver && overlay)
#endif
)
{
@ -874,13 +876,14 @@ static int menu_input_pointer_post_iterate(menu_file_list_cbs_t *cbs,
menu_input_t *menu_input = menu_input_get_ptr();
driver_t *driver = driver_get_ptr();
settings_t *settings = config_get_ptr();
input_overlay_t *overlay = input_overlay_get_ptr();
if (!menu_input)
return -1;
if (!settings->menu.pointer.enable
#ifdef HAVE_OVERLAY
|| (settings->input.overlay_enable && driver && driver->overlay)
|| (settings->input.overlay_enable && driver && overlay)
#endif
)
return 0;

View File

@ -147,16 +147,13 @@ static void data_runloop_iterate(bool is_thread)
bool rarch_main_data_active(void)
{
bool active = false;
driver_t *driver = driver_get_ptr();
#ifdef HAVE_LIBRETRODB
if (rarch_main_data_db_is_active())
active = true;
#endif
#ifdef HAVE_OVERLAY
if (driver && driver->overlay &&
(driver->overlay->state != OVERLAY_STATUS_ALIVE
&& driver->overlay->state != OVERLAY_STATUS_NONE))
if (input_overlay_is_active())
active = true;
#endif
if (rarch_main_data_nbio_image_get_handle())

View File

@ -18,7 +18,7 @@
#include <rthreads/rthreads.h>
#endif
#include "../driver.h"
#include "../input/input_overlay.h"
#include "../runloop.h"
#include "tasks.h"
@ -28,11 +28,10 @@ static slock_t *overlay_lock;
void rarch_main_data_overlay_image_upload_iterate(bool is_thread)
{
driver_t *driver = driver_get_ptr();
input_overlay_t *overlay = input_overlay_get_ptr();
if (rarch_main_is_idle())
return;
if (!driver->overlay)
if (!overlay)
return;
#ifdef HAVE_THREADS
@ -40,10 +39,10 @@ void rarch_main_data_overlay_image_upload_iterate(bool is_thread)
slock_lock(overlay_lock);
#endif
switch (driver->overlay->state)
switch (overlay->state)
{
case OVERLAY_STATUS_DEFERRED_LOADING:
input_overlay_load_overlays_iterate(driver->overlay);
input_overlay_load_overlays_iterate(overlay);
break;
default:
break;
@ -57,7 +56,7 @@ void rarch_main_data_overlay_image_upload_iterate(bool is_thread)
void rarch_main_data_overlay_iterate(bool is_thread)
{
driver_t *driver = NULL;
input_overlay_t *overlay = input_overlay_get_ptr();
if (rarch_main_is_idle())
return;
@ -67,27 +66,25 @@ void rarch_main_data_overlay_iterate(bool is_thread)
slock_lock(overlay_lock);
#endif
driver = driver_get_ptr();
if (!driver || !driver->overlay)
if (!overlay)
goto end;
switch (driver->overlay->state)
switch (overlay->state)
{
case OVERLAY_STATUS_DEFERRED_LOAD:
input_overlay_load_overlays(driver->overlay);
input_overlay_load_overlays(overlay);
break;
case OVERLAY_STATUS_NONE:
case OVERLAY_STATUS_ALIVE:
break;
case OVERLAY_STATUS_DEFERRED_LOADING_RESOLVE:
input_overlay_load_overlays_resolve_iterate(driver->overlay);
input_overlay_load_overlays_resolve_iterate(overlay);
break;
case OVERLAY_STATUS_DEFERRED_DONE:
input_overlay_new_done(driver->overlay);
input_overlay_new_done(overlay);
break;
case OVERLAY_STATUS_DEFERRED_ERROR:
input_overlay_free(driver->overlay);
input_overlay_free(overlay);
break;
default:
break;