* Cleanups

* Less pointer grabbing (dispwidget_get_ptr)
This commit is contained in:
LibretroAdmin 2022-10-09 22:53:39 +02:00
parent 479e3b23d9
commit 2cddea21f8
4 changed files with 111 additions and 100 deletions

View File

@ -366,10 +366,9 @@ static void driver_adjust_system_rates(
if (video_st->current_video->set_nonblock_state)
video_st->current_video->set_nonblock_state(
video_st->data, true,
video_driver_test_all_flags(GFX_CTX_FLAGS_ADAPTIVE_VSYNC) &&
video_adaptive_vsync,
video_swap_interval
);
video_driver_test_all_flags(GFX_CTX_FLAGS_ADAPTIVE_VSYNC)
&& video_adaptive_vsync,
video_swap_interval);
}
return;
}
@ -438,33 +437,30 @@ void drivers_init(
int flags,
bool verbosity_enabled)
{
runloop_state_t *runloop_st = runloop_state_get_ptr();
audio_driver_state_t
*audio_st = audio_state_get_ptr();
input_driver_state_t
*input_st = input_state_get_ptr();
video_driver_state_t
*video_st = video_state_get_ptr();
runloop_state_t *runloop_st = runloop_state_get_ptr();
audio_driver_state_t *audio_st = audio_state_get_ptr();
input_driver_state_t *input_st = input_state_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr();
#ifdef HAVE_MENU
struct menu_state *menu_st = menu_state_get_ptr();
struct menu_state *menu_st = menu_state_get_ptr();
#endif
camera_driver_state_t
*camera_st = camera_state_get_ptr();
*camera_st = camera_state_get_ptr();
location_driver_state_t
*location_st = location_state_get_ptr();
bool video_is_threaded = VIDEO_DRIVER_IS_THREADED_INTERNAL(video_st);
gfx_display_t *p_disp = disp_get_ptr();
*location_st = location_state_get_ptr();
bool video_is_threaded = VIDEO_DRIVER_IS_THREADED_INTERNAL(video_st);
gfx_display_t *p_disp = disp_get_ptr();
#if defined(HAVE_GFX_WIDGETS)
bool video_font_enable = settings->bools.video_font_enable;
bool menu_enable_widgets = settings->bools.menu_enable_widgets;
bool video_font_enable = settings->bools.video_font_enable;
bool menu_enable_widgets = settings->bools.menu_enable_widgets;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
/* By default, we want display widgets to persist through driver reinits. */
dispwidget_get_ptr()->flags |= DISPGFX_WIDGET_FLAG_PERSISTING;
p_dispwidget->flags |= DISPGFX_WIDGET_FLAG_PERSISTING;
#endif
#ifdef HAVE_MENU
/* By default, we want the menu to persist through driver reinits. */
if (menu_st)
menu_st->flags |= MENU_ST_FLAG_DATA_OWN;
menu_st->flags |= MENU_ST_FLAG_DATA_OWN;
#endif
if (flags & (DRIVER_VIDEO_MASK | DRIVER_AUDIO_MASK))
@ -572,7 +568,7 @@ void drivers_init(
settings->uints.camera_width : camera_st->cb.width,
settings->uints.camera_height ?
settings->uints.camera_height : camera_st->cb.height);
if (!camera_st->data)
{
RARCH_ERR("Failed to initialize camera driver. Will continue without camera.\n");
@ -620,11 +616,11 @@ void drivers_init(
bool video_is_fullscreen = settings->bools.video_fullscreen ||
rarch_force_fullscreen;
dispwidget_get_ptr()->active= gfx_widgets_init(
p_dispwidget->active= gfx_widgets_init(
p_disp,
anim_get_ptr(),
settings,
(uintptr_t)&dispwidget_get_ptr()->active,
(uintptr_t)&p_dispwidget->active,
video_is_threaded,
video_st->width,
video_st->height,
@ -692,11 +688,12 @@ void drivers_init(
void driver_uninit(int flags)
{
runloop_state_t *runloop_st = runloop_state_get_ptr();
video_driver_state_t
*video_st = video_state_get_ptr();
camera_driver_state_t
*camera_st = camera_state_get_ptr();
runloop_state_t *runloop_st = runloop_state_get_ptr();
video_driver_state_t *video_st = video_state_get_ptr();
camera_driver_state_t *camera_st = camera_state_get_ptr();
#if defined(HAVE_GFX_WIDGETS)
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
#endif
core_info_deinit_list();
core_info_free_current_core();
@ -705,10 +702,10 @@ void driver_uninit(int flags)
/* This absolutely has to be done before video_driver_free_internal()
* is called/completes, otherwise certain menu drivers
* (e.g. Vulkan) will segfault */
if (dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_INITED)
if (p_dispwidget->flags & DISPGFX_WIDGET_FLAG_INITED)
{
gfx_widgets_deinit(dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_PERSISTING);
dispwidget_get_ptr()->active = false;
gfx_widgets_deinit(p_dispwidget->flags & DISPGFX_WIDGET_FLAG_PERSISTING);
p_dispwidget->active = false;
}
#endif
@ -795,17 +792,17 @@ void retroarch_deinit_drivers(struct retro_callbacks *cbs)
location_driver_state_t
*location_st = location_state_get_ptr();
runloop_state_t *runloop_st = runloop_state_get_ptr();
#if defined(HAVE_GFX_WIDGETS)
/* Tear down display widgets no matter what
* in case the handle is lost in the threaded
* video driver in the meantime
* (breaking video_driver_has_widgets) */
if (dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_INITED)
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
if (p_dispwidget->flags & DISPGFX_WIDGET_FLAG_INITED)
{
gfx_widgets_deinit(
dispwidget_get_ptr()->flags & DISPGFX_WIDGET_FLAG_PERSISTING);
dispwidget_get_ptr()->active = false;
p_dispwidget->flags & DISPGFX_WIDGET_FLAG_PERSISTING);
p_dispwidget->active = false;
}
#endif

View File

@ -3621,25 +3621,25 @@ void video_driver_frame(const void *data, unsigned width,
static int8_t nonblock_active;
/* Initialise 'last_frame_duped' to 'true'
* to ensure that the first frame is rendered */
static bool last_frame_duped = true;
bool render_frame = true;
static bool last_frame_duped = true;
bool render_frame = true;
retro_time_t new_time;
video_frame_info_t video_info;
size_t buf_pos = 0;
video_driver_state_t *video_st= &video_driver_st;
runloop_state_t *runloop_st = runloop_state_get_ptr();
size_t buf_pos = 0;
video_driver_state_t *video_st = &video_driver_st;
runloop_state_t *runloop_st = runloop_state_get_ptr();
const enum retro_pixel_format
video_driver_pix_fmt = video_st->pix_fmt;
bool runloop_idle = runloop_st->idle;
bool video_driver_active = video_st->flags & VIDEO_FLAG_ACTIVE;
video_driver_pix_fmt = video_st->pix_fmt;
bool runloop_idle = runloop_st->idle;
bool video_driver_active = video_st->flags & VIDEO_FLAG_ACTIVE;
#if defined(HAVE_GFX_WIDGETS)
bool widgets_active = dispwidget_get_ptr()->active;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
bool widgets_active = p_dispwidget->active;
#endif
recording_state_t
*recording_st = recording_state_get_ptr();
recording_state_t *recording_st= recording_state_get_ptr();
status_text[0] = '\0';
video_driver_msg[0] = '\0';
status_text[0] = '\0';
video_driver_msg[0] = '\0';
if (!video_driver_active)
return;
@ -4100,9 +4100,9 @@ void video_driver_frame(const void *data, unsigned width,
#if defined(HAVE_GFX_WIDGETS)
if (widgets_active)
strlcpy(
dispwidget_get_ptr()->gfx_widgets_status_text,
p_dispwidget->gfx_widgets_status_text,
status_text,
sizeof(dispwidget_get_ptr()->gfx_widgets_status_text)
sizeof(p_dispwidget->gfx_widgets_status_text)
);
else
#endif

View File

@ -1741,9 +1741,9 @@ bool runloop_environment_cb(unsigned cmd, void *data)
case RETRO_ENVIRONMENT_SET_MESSAGE:
{
const struct retro_message *msg = (const struct retro_message*)data;
RARCH_LOG("[Environ]: SET_MESSAGE: %s\n", msg->msg);
#if defined(HAVE_GFX_WIDGETS)
if (dispwidget_get_ptr()->active)
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
if (p_dispwidget->active)
gfx_widget_set_libretro_message(
msg->msg,
roundf((float)msg->frames / 60.0f * 1000.0f));
@ -1752,6 +1752,7 @@ bool runloop_environment_cb(unsigned cmd, void *data)
runloop_msg_queue_push(msg->msg, 3, msg->frames,
true, NULL, MESSAGE_QUEUE_ICON_DEFAULT,
MESSAGE_QUEUE_CATEGORY_INFO);
RARCH_LOG("[Environ]: SET_MESSAGE: %s\n", msg->msg);
break;
}
@ -1837,7 +1838,8 @@ bool runloop_environment_cb(unsigned cmd, void *data)
{
video_driver_state_t *video_st =
video_state_get_ptr();
if (dispwidget_get_ptr()->active)
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
if (p_dispwidget->active)
gfx_widget_set_libretro_message(
msg->msg, msg->duration);
else
@ -1852,7 +1854,8 @@ bool runloop_environment_cb(unsigned cmd, void *data)
{
video_driver_state_t *video_st =
video_state_get_ptr();
if (dispwidget_get_ptr()->active)
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
if (p_dispwidget->active)
gfx_widget_set_progress_message(
msg->msg, msg->duration,
msg->priority, msg->progress);
@ -4984,6 +4987,7 @@ static bool core_unload_game(void)
static void runloop_apply_fastmotion_override(runloop_state_t *runloop_st, settings_t *settings)
{
float fastforward_ratio_current;
video_driver_state_t *video_st = video_state_get_ptr();
bool frame_time_counter_reset_after_fastforwarding = settings ?
settings->bools.frame_time_counter_reset_after_fastforwarding : false;
@ -4994,7 +4998,9 @@ static void runloop_apply_fastmotion_override(runloop_state_t *runloop_st, setti
(runloop_st->fastmotion_override.current.ratio >= 0.0f)) ?
runloop_st->fastmotion_override.current.ratio :
fastforward_ratio_default;
float fastforward_ratio_current;
#if defined(HAVE_GFX_WIDGETS)
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
#endif
memcpy(&runloop_st->fastmotion_override.current,
&runloop_st->fastmotion_override.next,
@ -5032,7 +5038,7 @@ static void runloop_apply_fastmotion_override(runloop_state_t *runloop_st, setti
* (required if RETRO_ENVIRONMENT_SET_FASTFORWARDING_OVERRIDE
* is called during core de-initialisation) */
#if defined(HAVE_GFX_WIDGETS)
if (dispwidget_get_ptr()->active && !runloop_st->fastmotion)
if (p_dispwidget->active && !runloop_st->fastmotion)
video_st->flags &= ~VIDEO_FLAG_WIDGETS_FAST_FORWARD;
#endif
}
@ -5635,7 +5641,8 @@ void runloop_pause_checks(void)
bool is_idle = runloop_st->idle;
#if defined(HAVE_GFX_WIDGETS)
video_driver_state_t *video_st = video_state_get_ptr();
bool widgets_active = dispwidget_get_ptr()->active;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
bool widgets_active = p_dispwidget->active;
if (widgets_active)
{
if (is_paused)
@ -5679,7 +5686,7 @@ void runloop_pause_checks(void)
}
#if defined(HAVE_TRANSLATE) && defined(HAVE_GFX_WIDGETS)
if (dispwidget_get_ptr()->ai_service_overlay_state == 1)
if (p_dispwidget->ai_service_overlay_state == 1)
gfx_widgets_ai_service_overlay_unload();
#endif
}
@ -6273,15 +6280,16 @@ void runloop_msg_queue_push(const char *msg,
enum message_queue_category category)
{
#if defined(HAVE_GFX_WIDGETS)
bool widgets_active = dispwidget_get_ptr()->active;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
bool widgets_active = p_dispwidget->active;
#endif
#ifdef HAVE_ACCESSIBILITY
settings_t *settings = config_get_ptr();
bool accessibility_enable = settings->bools.accessibility_enable;
settings_t *settings = config_get_ptr();
bool accessibility_enable = settings->bools.accessibility_enable;
unsigned accessibility_narrator_speech_speed = settings->uints.accessibility_narrator_speech_speed;
access_state_t *access_st = access_state_get_ptr();
access_state_t *access_st = access_state_get_ptr();
#endif
runloop_state_t *runloop_st = &runloop_state;
runloop_state_t *runloop_st = &runloop_state;
RUNLOOP_MSG_QUEUE_LOCK(runloop_st);
#ifdef HAVE_ACCESSIBILITY
@ -6440,17 +6448,18 @@ MENU_ST_FLAG_IS_BINDING;
bool display_kb = menu_input_dialog_get_display_kb();
#endif
#if defined(HAVE_GFX_WIDGETS)
bool widgets_active = dispwidget_get_ptr()->active;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
bool widgets_active = p_dispwidget->active;
#endif
#ifdef HAVE_CHEEVOS
bool cheevos_hardcore_active = false;
#endif
#if defined(HAVE_TRANSLATE) && defined(HAVE_GFX_WIDGETS)
if (dispwidget_get_ptr()->ai_service_overlay_state == 3)
if (p_dispwidget->ai_service_overlay_state == 3)
{
command_event(CMD_EVENT_PAUSE, NULL);
dispwidget_get_ptr()->ai_service_overlay_state = 1;
p_dispwidget->ai_service_overlay_state = 1;
}
#endif
@ -6531,12 +6540,15 @@ MENU_ST_FLAG_IS_BINDING;
#else
;
#endif
HOTKEY_CHECK(RARCH_FULLSCREEN_TOGGLE_KEY, CMD_EVENT_FULLSCREEN_TOGGLE,
fullscreen_toggled, NULL);
HOTKEY_CHECK(RARCH_FULLSCREEN_TOGGLE_KEY,
CMD_EVENT_FULLSCREEN_TOGGLE,
fullscreen_toggled, NULL);
}
/* Check mouse grab toggle */
HOTKEY_CHECK(RARCH_GRAB_MOUSE_TOGGLE, CMD_EVENT_GRAB_MOUSE_TOGGLE, true, NULL);
HOTKEY_CHECK(RARCH_GRAB_MOUSE_TOGGLE,
CMD_EVENT_GRAB_MOUSE_TOGGLE,
true, NULL);
/* Automatic mouse grab on focus */
if ( settings->bools.input_auto_mouse_grab
@ -8092,16 +8104,17 @@ void runloop_task_msg_queue_push(
{
#if defined(HAVE_GFX_WIDGETS)
#ifdef HAVE_MENU
struct menu_state *menu_st = menu_state_get_ptr();
struct menu_state *menu_st = menu_state_get_ptr();
#endif
#ifdef HAVE_ACCESSIBILITY
access_state_t *access_st = access_state_get_ptr();
settings_t *settings = config_get_ptr();
bool accessibility_enable = settings->bools.accessibility_enable;
access_state_t *access_st = access_state_get_ptr();
settings_t *settings = config_get_ptr();
bool accessibility_enable = settings->bools.accessibility_enable;
unsigned accessibility_narrator_speech_speed = settings->uints.accessibility_narrator_speech_speed;
#endif
runloop_state_t *runloop_st = &runloop_state;
bool widgets_active = dispwidget_get_ptr()->active;
runloop_state_t *runloop_st = &runloop_state;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
bool widgets_active = p_dispwidget->active;
if (widgets_active && task->title && !task->mute)
{

View File

@ -175,9 +175,10 @@ static void handle_translation_cb(
bool accessibility_enable = settings->bools.accessibility_enable;
unsigned accessibility_narrator_speech_speed = settings->uints.accessibility_narrator_speech_speed;
#ifdef HAVE_GFX_WIDGETS
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
/* When auto mode is on, we turn off the overlay
* once we have the result for the next call.*/
if (dispwidget_get_ptr()->ai_service_overlay_state != 0
if (p_dispwidget->ai_service_overlay_state != 0
&& access_st->ai_service_auto == 2)
gfx_widgets_ai_service_overlay_unload();
#endif
@ -275,7 +276,7 @@ static void handle_translation_cb(
if (gfx_widgets_paused)
{
/* In this case we have to unpause and then repause for a frame */
dispwidget_get_ptr()->ai_service_overlay_state = 2;
p_dispwidget->ai_service_overlay_state = 2;
command_event(CMD_EVENT_UNPAUSE, NULL);
}
#endif
@ -340,7 +341,7 @@ static void handle_translation_cb(
{
/* In this case we have to unpause and then repause for a frame */
/* Unpausing state */
dispwidget_get_ptr()->ai_service_overlay_state = 2;
p_dispwidget->ai_service_overlay_state = 2;
command_event(CMD_EVENT_UNPAUSE, NULL);
}
}
@ -776,37 +777,37 @@ bool run_translation_service(settings_t *settings, bool paused)
uint8_t header[54];
size_t pitch;
unsigned width, height;
const void *data = NULL;
uint8_t *bit24_image = NULL;
uint8_t *bit24_image_prev = NULL;
struct scaler_ctx *scaler = (struct scaler_ctx*)
const void *data = NULL;
uint8_t *bit24_image = NULL;
uint8_t *bit24_image_prev = NULL;
struct scaler_ctx *scaler = (struct scaler_ctx*)
calloc(1, sizeof(struct scaler_ctx));
bool error = false;
bool error = false;
uint8_t *bmp_buffer = NULL;
uint64_t buffer_bytes = 0;
char *bmp64_buffer = NULL;
rjsonwriter_t* jsonwriter = NULL;
const char *json_buffer = NULL;
uint8_t *bmp_buffer = NULL;
uint64_t buffer_bytes = 0;
char *bmp64_buffer = NULL;
rjsonwriter_t* jsonwriter = NULL;
const char *json_buffer = NULL;
int bmp64_length = 0;
bool TRANSLATE_USE_BMP = false;
int bmp64_length = 0;
bool TRANSLATE_USE_BMP = false;
const char *label = NULL;
char* system_label = NULL;
core_info_t *core_info = NULL;
video_driver_state_t
*video_st = video_state_get_ptr();
const char *label = NULL;
char* system_label = NULL;
core_info_t *core_info = NULL;
video_driver_state_t *video_st = video_state_get_ptr();
const enum retro_pixel_format
video_driver_pix_fmt = video_st->pix_fmt;
access_state_t *access_st = access_state_get_ptr();
video_driver_pix_fmt = video_st->pix_fmt;
access_state_t *access_st = access_state_get_ptr();
#ifdef HAVE_ACCESSIBILITY
input_driver_state_t *input_st = input_state_get_ptr();
input_driver_state_t *input_st = input_state_get_ptr();
#endif
#ifdef HAVE_GFX_WIDGETS
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
/* For the case when ai service pause is disabled. */
if ( (dispwidget_get_ptr()->ai_service_overlay_state != 0)
if ( (p_dispwidget->ai_service_overlay_state != 0)
&& (access_st->ai_service_auto == 1))
{
gfx_widgets_ai_service_overlay_unload();