Merge pull request #13043 from libretro/refactors

Refactors - moves dispwidget_get_ptr to gfx_widgets
This commit is contained in:
Autechre 2021-09-30 16:49:52 +02:00 committed by GitHub
commit d819251ffd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 143 additions and 145 deletions

View File

@ -18,6 +18,10 @@
#include <retro_miscellaneous.h>
#include <retro_inline.h>
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include <queues/fifo_queue.h>
#include <file/file_path.h>
#include <streams/file_stream.h>
@ -32,6 +36,7 @@
#include "../msg_hash.h"
#include "../tasks/task_content.h"
#include "../tasks/tasks_internal.h"
#ifdef HAVE_THREADS
#define SLOCK_LOCK(x) slock_lock(x)
@ -61,6 +66,8 @@ static const char
"menu_achievements.png"
};
static dispgfx_widget_t dispwidget_st = {0}; /* uint64_t alignment */
static void INLINE gfx_widgets_font_free(gfx_widget_font_data_t *font_data)
{
if (font_data->font)
@ -182,7 +189,6 @@ static void msg_widget_msg_transition_animation_done(void *userdata)
}
void gfx_widgets_msg_queue_push(
void *data,
retro_task_t *task,
const char *msg,
unsigned duration,
@ -193,7 +199,7 @@ void gfx_widgets_msg_queue_push(
bool menu_is_alive)
{
disp_widget_msg_t *msg_widget = NULL;
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
if (FIFO_WRITE_AVAIL_NONPTR(p_dispwidget->msg_queue) > 0)
{
@ -399,7 +405,7 @@ void gfx_widgets_msg_queue_push(
static void gfx_widgets_unfold_end(void *userdata)
{
disp_widget_msg_t *unfold = (disp_widget_msg_t*)userdata;
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)dispwidget_get_ptr();
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
unfold->unfolding = false;
p_dispwidget->widgets_moving = false;
@ -407,7 +413,7 @@ static void gfx_widgets_unfold_end(void *userdata)
static void gfx_widgets_move_end(void *userdata)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)dispwidget_get_ptr();
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
if (userdata)
{
@ -526,7 +532,7 @@ static void gfx_widgets_msg_queue_kill_end(void *userdata)
{
unsigned i;
disp_widget_msg_t* msg;
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)dispwidget_get_ptr();
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
SLOCK_LOCK(p_dispwidget->current_msgs_lock);
@ -896,7 +902,6 @@ static void gfx_widgets_layout(
void gfx_widgets_iterate(
void *data,
void *data_disp,
void *settings_data,
unsigned width, unsigned height, bool fullscreen,
@ -904,7 +909,7 @@ void gfx_widgets_iterate(
bool is_threaded)
{
size_t i;
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
/* c.f. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=323
* On some platforms (e.g. 32-bit x86 without SSE),
* gcc can produce inconsistent floating point results
@ -1951,7 +1956,6 @@ static void gfx_widgets_context_reset(
}
bool gfx_widgets_init(
void *data,
void *data_disp,
void *data_anim,
void *settings_data,
@ -1962,7 +1966,7 @@ bool gfx_widgets_init(
{
unsigned i;
unsigned color = 0x222222;
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
gfx_display_t *p_disp = (gfx_display_t*)data_disp;
gfx_animation_t *p_anim = (gfx_animation_t*)data_anim;
settings_t *settings = (settings_t*)settings_data;
@ -2068,9 +2072,9 @@ static void gfx_widgets_context_destroy(dispgfx_widget_t *p_dispwidget)
}
void gfx_widgets_deinit(void *data, bool widgets_persisting)
void gfx_widgets_deinit(bool widgets_persisting)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
gfx_widgets_context_destroy(p_dispwidget);
@ -2109,10 +2113,10 @@ static bool gfx_widgets_reset_textures_list_buffer(
}
bool gfx_widgets_ai_service_overlay_load(
dispgfx_widget_t *p_dispwidget,
char* buffer, unsigned buffer_len,
enum image_type_enum image_type)
{
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
if (p_dispwidget->ai_service_overlay_state == 0)
{
if (!gfx_widgets_reset_textures_list_buffer(
@ -2127,8 +2131,9 @@ bool gfx_widgets_ai_service_overlay_load(
return true;
}
void gfx_widgets_ai_service_overlay_unload(dispgfx_widget_t *p_dispwidget)
void gfx_widgets_ai_service_overlay_unload(void)
{
dispgfx_widget_t *p_dispwidget = &dispwidget_st;
if (p_dispwidget->ai_service_overlay_state == 1)
{
video_driver_texture_unload(&p_dispwidget->ai_service_overlay_texture);
@ -2137,3 +2142,35 @@ void gfx_widgets_ai_service_overlay_unload(dispgfx_widget_t *p_dispwidget)
}
}
#endif
#ifdef HAVE_SCREENSHOTS
void task_screenshot_callback(retro_task_t *task,
void *task_data,
void *user_data, const char *error)
{
screenshot_task_state_t *state = NULL;
if (!task)
return;
state = (screenshot_task_state_t*)task->state;
if (!state)
return;
if (!state->silence && state->widgets_ready)
gfx_widget_screenshot_taken(&dispwidget_st,
state->shotname, state->filename);
free(state);
/* Must explicitly set task->state to NULL here,
* to avoid potential heap-use-after-free errors */
state = NULL;
task->state = NULL;
}
#endif
dispgfx_widget_t *dispwidget_get_ptr(void)
{
return &dispwidget_st;
}

View File

@ -20,6 +20,7 @@
#include "../config.h"
#endif
#include <retro_common_api.h>
#include <formats/image.h>
#include <queues/task_queue.h>
#include <queues/message_queue.h>
@ -51,6 +52,8 @@
#endif
#define TEXT_COLOR_FAINT 0x878787FF
RETRO_BEGIN_DECLS
enum gfx_widgets_icon
{
MENU_WIDGETS_ICON_PAUSED = 0,
@ -306,7 +309,6 @@ void gfx_widgets_flush_text(
typedef struct gfx_widget gfx_widget_t;
bool gfx_widgets_init(
void *data,
void *data_disp,
void *data_anim,
void *settings_data,
@ -315,10 +317,9 @@ bool gfx_widgets_init(
unsigned width, unsigned height, bool fullscreen,
const char *dir_assets, char *font_path);
void gfx_widgets_deinit(void *data, bool widgets_persisting);
void gfx_widgets_deinit(bool widgets_persisting);
void gfx_widgets_msg_queue_push(
void *data,
retro_task_t *task, const char *msg,
unsigned duration,
char *title,
@ -331,7 +332,6 @@ void gfx_widget_volume_update_and_show(float new_volume,
bool mute);
void gfx_widgets_iterate(
void *data,
void *data_disp,
void *settings_data,
unsigned width, unsigned height, bool fullscreen,
@ -344,11 +344,10 @@ void gfx_widget_screenshot_taken(void *data,
/* AI Service functions */
#ifdef HAVE_TRANSLATE
bool gfx_widgets_ai_service_overlay_load(
dispgfx_widget_t *p_dispwidget,
char* buffer, unsigned buffer_len,
enum image_type_enum image_type);
void gfx_widgets_ai_service_overlay_unload(dispgfx_widget_t *p_dispwidget);
void gfx_widgets_ai_service_overlay_unload(void);
#endif
#ifdef HAVE_CHEEVOS
@ -357,22 +356,14 @@ void gfx_widgets_set_leaderboard_display(unsigned id, const char* value);
void gfx_widgets_set_challenge_display(unsigned id, const char* badge);
#endif
/* Warning: not thread safe! */
/* TODO/FIXME/WARNING: Not thread safe! */
void gfx_widget_set_generic_message(
void *data,
const char *message, unsigned duration);
/* Warning: not thread safe! */
void gfx_widget_set_libretro_message(
void *data,
const char *message, unsigned duration);
/* Warning: not thread safe! */
void gfx_widget_set_progress_message(void *data,
void gfx_widget_set_progress_message(
const char *message, unsigned duration,
unsigned priority, int8_t progress);
/* Warning: not thread safe! */
bool gfx_widget_start_load_content_animation(void);
/* All the functions below should be called in
@ -380,7 +371,7 @@ bool gfx_widget_start_load_content_animation(void);
* enable_menu_widgets to true for that driver */
void gfx_widgets_frame(void *data);
void *dispwidget_get_ptr(void);
dispgfx_widget_t *dispwidget_get_ptr(void);
extern const gfx_widget_t gfx_widget_screenshot;
extern const gfx_widget_t gfx_widget_volume;
@ -394,4 +385,6 @@ extern const gfx_widget_t gfx_widget_achievement_popup;
extern const gfx_widget_t gfx_widget_leaderboard_display;
#endif
RETRO_END_DECLS
#endif

View File

@ -38,6 +38,7 @@ struct gfx_widget_achievement_popup_state
slock_t* queue_lock;
#endif
cheevo_popup queue[CHEEVO_QUEUE_SIZE]; /* ptr alignment */
const dispgfx_widget_t *dispwidget_ptr;
int queue_read_index;
int queue_write_index;
unsigned width;
@ -64,6 +65,8 @@ static bool gfx_widget_achievement_popup_init(
{
gfx_widget_achievement_popup_state_t* state = &p_w_achievement_popup_st;
memset(state, 0, sizeof(*state));
state->dispwidget_ptr = (const dispgfx_widget_t*)
dispwidget_get_ptr();
state->queue_read_index = -1;
@ -81,6 +84,8 @@ static void gfx_widget_achievement_popup_free_all(gfx_widget_achievement_popup_s
SLOCK_UNLOCK(state->queue_lock);
}
state->dispwidget_ptr = NULL;
}
static void gfx_widget_achievement_popup_free(void)
@ -93,6 +98,7 @@ static void gfx_widget_achievement_popup_free(void)
slock_free(state->queue_lock);
state->queue_lock = NULL;
#endif
state->dispwidget_ptr = NULL;
}
static void gfx_widget_achievement_popup_context_destroy(void)
@ -293,9 +299,9 @@ static void gfx_widget_achievement_popup_next(void* userdata)
static void gfx_widget_achievement_popup_dismiss(void *userdata)
{
gfx_animation_ctx_entry_t entry;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
dispwidget_get_ptr();
gfx_widget_achievement_popup_state_t *state = &p_w_achievement_popup_st;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
state->dispwidget_ptr;
/* Slide up animation */
entry.cb = gfx_widget_achievement_popup_next;
@ -312,9 +318,9 @@ static void gfx_widget_achievement_popup_dismiss(void *userdata)
static void gfx_widget_achievement_popup_fold(void *userdata)
{
gfx_animation_ctx_entry_t entry;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
dispwidget_get_ptr();
gfx_widget_achievement_popup_state_t *state = &p_w_achievement_popup_st;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
state->dispwidget_ptr;
/* Fold */
entry.cb = gfx_widget_achievement_popup_dismiss;
@ -332,9 +338,9 @@ static void gfx_widget_achievement_popup_unfold(void *userdata)
{
gfx_timer_ctx_entry_t timer;
gfx_animation_ctx_entry_t entry;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
dispwidget_get_ptr();
gfx_widget_achievement_popup_state_t *state = &p_w_achievement_popup_st;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
state->dispwidget_ptr;
/* Unfold */
entry.cb = NULL;
@ -358,8 +364,9 @@ static void gfx_widget_achievement_popup_unfold(void *userdata)
static void gfx_widget_achievement_popup_start(
gfx_widget_achievement_popup_state_t* state)
{
const dispgfx_widget_t* p_dispwidget = (const dispgfx_widget_t*)dispwidget_get_ptr();
gfx_animation_ctx_entry_t entry;
const dispgfx_widget_t *p_dispwidget = (const dispgfx_widget_t*)
state->dispwidget_ptr;
state->height = p_dispwidget->gfx_widget_fonts.regular.line_height * 4;
state->width = MAX(

View File

@ -158,11 +158,10 @@ static void gfx_widget_generic_message_slide_in_cb(void *userdata)
}
/* Widget interface */
void gfx_widget_set_generic_message(void *data,
void gfx_widget_set_generic_message(
const char *msg, unsigned duration)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
gfx_widget_generic_message_state_t *state = &p_w_generic_message_st;
unsigned last_video_width = p_dispwidget->last_video_width;
int text_width = 0;

View File

@ -51,6 +51,7 @@ struct gfx_widget_leaderboard_display_state
#ifdef HAVE_THREADS
slock_t* array_lock;
#endif
const dispgfx_widget_t *dispwidget_ptr;
struct leaderboard_display_info tracker_info[CHEEVO_LBOARD_ARRAY_SIZE];
unsigned tracker_count;
struct challenge_display_info challenge_info[CHEEVO_CHALLENGE_ARRAY_SIZE];
@ -69,6 +70,8 @@ static bool gfx_widget_leaderboard_display_init(
gfx_widget_leaderboard_display_state_t *state =
&p_w_leaderboard_display_st;
memset(state, 0, sizeof(*state));
state->dispwidget_ptr = (const dispgfx_widget_t*)
dispwidget_get_ptr();
return true;
}
@ -83,6 +86,7 @@ static void gfx_widget_leaderboard_display_free(void)
slock_free(state->array_lock);
state->array_lock = NULL;
#endif
state->dispwidget_ptr = NULL;
}
static void gfx_widget_leaderboard_display_context_destroy(void)
@ -228,14 +232,12 @@ void gfx_widgets_set_leaderboard_display(unsigned id, const char* value)
else
{
/* show or update display */
const dispgfx_widget_t* p_dispwidget = (const dispgfx_widget_t*)dispwidget_get_ptr();
if (i == state->tracker_count)
state->tracker_info[state->tracker_count++].id = id;
strncpy(state->tracker_info[i].display, value, sizeof(state->tracker_info[i].display));
state->tracker_info[i].width = font_driver_get_message_width(
p_dispwidget->gfx_widget_fonts.regular.font,
state->dispwidget_ptr->gfx_widget_fonts.regular.font,
state->tracker_info[i].display, 0, 1);
state->tracker_info[i].width += CHEEVO_LBOARD_DISPLAY_PADDING * 2;
}

View File

@ -153,10 +153,10 @@ static void gfx_widget_libretro_message_slide_in_cb(void *userdata)
/* Widget interface */
void gfx_widget_set_libretro_message(void *data,
void gfx_widget_set_libretro_message(
const char *msg, unsigned duration)
{
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
gfx_widget_libretro_message_state_t *state = &p_w_libretro_message_st;
gfx_widget_font_data_t *font_msg_queue = &p_dispwidget->gfx_widget_fonts.msg_queue;

View File

@ -122,12 +122,12 @@ static void gfx_widget_progress_message_fadeout(void *userdata)
/* Widget interface */
void gfx_widget_set_progress_message(void *data,
void gfx_widget_set_progress_message(
const char *message, unsigned duration,
unsigned priority, int8_t progress)
{
gfx_timer_ctx_entry_t timer;
dispgfx_widget_t *p_dispwidget = (dispgfx_widget_t*)data;
dispgfx_widget_t *p_dispwidget = dispwidget_get_ptr();
gfx_widget_progress_message_state_t *state = &p_w_progress_message_st;
gfx_widget_font_data_t *font_regular = &p_dispwidget->gfx_widget_fonts.regular;
uintptr_t alpha_tag = (uintptr_t)&state->alpha;

View File

@ -408,14 +408,6 @@ gfx_display_t *disp_get_ptr(void)
return &p_rarch->dispgfx;
}
#ifdef HAVE_GFX_WIDGETS
void *dispwidget_get_ptr(void)
{
struct rarch_state *p_rarch = &rarch_st;
return &p_rarch->dispwidget_st;
}
#endif
settings_t *config_get_ptr(void)
{
struct rarch_state *p_rarch = &rarch_st;
@ -5168,8 +5160,7 @@ static bool retroarch_apply_shader(
);
#ifdef HAVE_GFX_WIDGETS
if (p_rarch->widgets_active)
gfx_widget_set_generic_message(&p_rarch->dispwidget_st,
msg, 2000);
gfx_widget_set_generic_message(msg, 2000);
else
#endif
runloop_msg_queue_push(msg, 1, 120, true, NULL,
@ -5363,9 +5354,9 @@ static void handle_translation_cb(
/* When auto mode is on, we turn off the overlay
* once we have the result for the next call.*/
if (p_rarch->dispwidget_st.ai_service_overlay_state != 0
if (dispwidget_get_ptr()->ai_service_overlay_state != 0
&& p_rarch->ai_service_auto == 2)
gfx_widgets_ai_service_overlay_unload(&p_rarch->dispwidget_st);
gfx_widgets_ai_service_overlay_unload();
#endif
#ifdef DEBUG
@ -5460,7 +5451,7 @@ static void handle_translation_cb(
if (gfx_widgets_paused)
{
/* In this case we have to unpause and then repause for a frame */
p_rarch->dispwidget_st.ai_service_overlay_state = 2;
dispwidget_get_ptr()->ai_service_overlay_state = 2;
command_event(CMD_EVENT_UNPAUSE, NULL);
}
#endif
@ -5509,7 +5500,6 @@ static void handle_translation_cb(
}
ai_res = gfx_widgets_ai_service_overlay_load(
&p_rarch->dispwidget_st,
raw_image_file_data, (unsigned)new_image_size,
image_type);
@ -5527,7 +5517,7 @@ static void handle_translation_cb(
/* In this case we have to unpause and then repause for a frame */
#ifdef HAVE_TRANSLATE
/* Unpausing state */
p_rarch->dispwidget_st.ai_service_overlay_state = 2;
dispwidget_get_ptr()->ai_service_overlay_state = 2;
#endif
command_event(CMD_EVENT_UNPAUSE, NULL);
}
@ -6030,10 +6020,10 @@ static bool run_translation_service(
#ifdef HAVE_GFX_WIDGETS
/* For the case when ai service pause is disabled. */
if ( (p_rarch->dispwidget_st.ai_service_overlay_state != 0)
if ( (dispwidget_get_ptr()->ai_service_overlay_state != 0)
&& (p_rarch->ai_service_auto == 1))
{
gfx_widgets_ai_service_overlay_unload(&p_rarch->dispwidget_st);
gfx_widgets_ai_service_overlay_unload();
goto finish;
}
#endif
@ -7377,8 +7367,8 @@ static void retroarch_pause_checks(struct rarch_state *p_rarch)
}
#if defined(HAVE_TRANSLATE) && defined(HAVE_GFX_WIDGETS)
if (p_rarch->dispwidget_st.ai_service_overlay_state == 1)
gfx_widgets_ai_service_overlay_unload(&p_rarch->dispwidget_st);
if (dispwidget_get_ptr()->ai_service_overlay_state == 1)
gfx_widgets_ai_service_overlay_unload();
#endif
}
@ -7524,8 +7514,8 @@ bool command_event(enum event_command cmd, void *data)
/* Because the overlay is a display widget,
* it's going to be written
* over the menu, so we unset it here. */
if (p_rarch->dispwidget_st.ai_service_overlay_state != 0)
gfx_widgets_ai_service_overlay_unload(&p_rarch->dispwidget_st);
if (dispwidget_get_ptr()->ai_service_overlay_state != 0)
gfx_widgets_ai_service_overlay_unload();
#endif
break;
case CMD_EVENT_OVERLAY_INIT:
@ -7615,7 +7605,7 @@ bool command_event(enum event_command cmd, void *data)
* toggle button, so turn it off now. */
p_rarch->ai_service_auto = 0;
#ifdef HAVE_MENU_WIDGETS
gfx_widgets_ai_service_overlay_unload(&p_rarch->dispwidget_st);
gfx_widgets_ai_service_overlay_unload();
#endif
}
else
@ -10923,7 +10913,7 @@ static bool retroarch_environment_cb(unsigned cmd, void *data)
RARCH_LOG("[Environ]: SET_MESSAGE: %s\n", msg->msg);
#if defined(HAVE_GFX_WIDGETS)
if (p_rarch->widgets_active)
gfx_widget_set_libretro_message(&p_rarch->dispwidget_st,
gfx_widget_set_libretro_message(
msg->msg,
roundf((float)msg->frames / 60.0f * 1000.0f));
else
@ -11014,7 +11004,7 @@ static bool retroarch_environment_cb(unsigned cmd, void *data)
/* Handle 'alternate' non-queued notifications */
case RETRO_MESSAGE_TYPE_NOTIFICATION_ALT:
if (p_rarch->widgets_active)
gfx_widget_set_libretro_message(&p_rarch->dispwidget_st,
gfx_widget_set_libretro_message(
msg->msg, msg->duration);
else
runloop_core_msg_queue_push(
@ -11025,7 +11015,7 @@ static bool retroarch_environment_cb(unsigned cmd, void *data)
/* Handle 'progress' messages */
case RETRO_MESSAGE_TYPE_PROGRESS:
if (p_rarch->widgets_active)
gfx_widget_set_progress_message(&p_rarch->dispwidget_st,
gfx_widget_set_progress_message(
msg->msg, msg->duration,
msg->priority, msg->progress);
else
@ -22601,7 +22591,6 @@ static void video_driver_frame(const void *data, unsigned width,
if (msg_found)
gfx_widgets_msg_queue_push(
&p_rarch->dispwidget_st,
NULL,
msg_entry.msg,
roundf((float)msg_entry.duration / 60.0f * 1000.0f),
@ -22715,9 +22704,9 @@ static void video_driver_frame(const void *data, unsigned width,
#if defined(HAVE_GFX_WIDGETS)
if (widgets_active)
strlcpy(
p_rarch->dispwidget_st.gfx_widgets_status_text,
dispwidget_get_ptr()->gfx_widgets_status_text,
status_text,
sizeof(p_rarch->dispwidget_st.gfx_widgets_status_text)
sizeof(dispwidget_get_ptr()->gfx_widgets_status_text)
);
else
#endif
@ -22914,7 +22903,7 @@ void video_driver_build_info(video_frame_info_t *video_info)
video_info->custom_vp_full_height = custom_vp->full_height;
#if defined(HAVE_GFX_WIDGETS)
video_info->widgets_userdata = &p_rarch->dispwidget_st;
video_info->widgets_userdata = dispwidget_get_ptr();
video_info->widgets_is_paused = p_rarch->gfx_widgets_paused;
video_info->widgets_is_fast_forwarding = p_rarch->gfx_widgets_fast_forward;
video_info->widgets_is_rewinding = p_rarch->gfx_widgets_rewinding;
@ -23779,7 +23768,6 @@ static void drivers_init(struct rarch_state *p_rarch,
rarch_force_fullscreen;
p_rarch->widgets_active = gfx_widgets_init(
&p_rarch->dispwidget_st,
&p_rarch->dispgfx,
anim_get_ptr(),
settings,
@ -23872,9 +23860,9 @@ static void driver_uninit(struct rarch_state *p_rarch, 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 (p_rarch->dispwidget_st.widgets_inited)
if (dispwidget_get_ptr()->widgets_inited)
{
gfx_widgets_deinit(&p_rarch->dispwidget_st, p_rarch->widgets_persisting);
gfx_widgets_deinit(p_rarch->widgets_persisting);
p_rarch->widgets_active = false;
}
#endif
@ -23954,9 +23942,9 @@ static void retroarch_deinit_drivers(
* in case the handle is lost in the threaded
* video driver in the meantime
* (breaking video_driver_has_widgets) */
if (p_rarch->dispwidget_st.widgets_inited)
if (dispwidget_get_ptr()->widgets_inited)
{
gfx_widgets_deinit(&p_rarch->dispwidget_st,
gfx_widgets_deinit(
p_rarch->widgets_persisting);
p_rarch->widgets_active = false;
}
@ -26516,7 +26504,6 @@ static void runloop_task_msg_queue_push(
(char*)msg, 0);
#endif
gfx_widgets_msg_queue_push(
&p_rarch->dispwidget_st,
task,
msg,
duration,
@ -27211,7 +27198,6 @@ void runloop_msg_queue_push(const char *msg,
if (widgets_active)
{
gfx_widgets_msg_queue_push(
&p_rarch->dispwidget_st,
NULL,
msg,
roundf((float)duration / 60.0f * 1000.0f),
@ -27399,10 +27385,10 @@ static enum runloop_state runloop_check_state(
#endif
#if defined(HAVE_TRANSLATE) && defined(HAVE_GFX_WIDGETS)
if (p_rarch->dispwidget_st.ai_service_overlay_state == 3)
if (dispwidget_get_ptr()->ai_service_overlay_state == 3)
{
command_event(CMD_EVENT_PAUSE, NULL);
p_rarch->dispwidget_st.ai_service_overlay_state = 1;
dispwidget_get_ptr()->ai_service_overlay_state = 1;
}
#endif
@ -27883,7 +27869,6 @@ static enum runloop_state runloop_check_state(
RUNLOOP_MSG_QUEUE_LOCK(runloop_state);
gfx_widgets_iterate(
&p_rarch->dispwidget_st,
&p_rarch->dispgfx,
settings,
p_rarch->video_driver_width,

View File

@ -842,9 +842,6 @@ struct rarch_state
#endif
#ifdef HAVE_DISCORD
discord_state_t discord_st; /* int64_t alignment */
#endif
#ifdef HAVE_GFX_WIDGETS
dispgfx_widget_t dispwidget_st; /* uint64_t alignment */
#endif
struct retro_core_t current_core; /* uint64_t alignment */
#if defined(HAVE_RUNAHEAD)

View File

@ -57,53 +57,28 @@
#include "tasks_internal.h"
typedef struct screenshot_task_state screenshot_task_state_t;
struct screenshot_task_state
{
struct scaler_ctx scaler;
uint8_t *out_buffer;
const void *frame;
void *userbuf;
int pitch;
unsigned width;
unsigned height;
unsigned pixel_format_type;
char filename[PATH_MAX_LENGTH];
char shotname[256];
bool bgr24;
bool silence;
bool is_idle;
bool is_paused;
bool history_list_enable;
bool widgets_ready;
};
static bool screenshot_dump_direct(screenshot_task_state_t *state)
{
struct scaler_ctx *scaler = (struct scaler_ctx*)&state->scaler;
struct scaler_ctx scaler;
bool ret = false;
#if defined(HAVE_RPNG)
if (state->bgr24)
scaler->in_fmt = SCALER_FMT_BGR24;
scaler.in_fmt = SCALER_FMT_BGR24;
else if (state->pixel_format_type == RETRO_PIXEL_FORMAT_XRGB8888)
scaler->in_fmt = SCALER_FMT_ARGB8888;
scaler.in_fmt = SCALER_FMT_ARGB8888;
else
scaler->in_fmt = SCALER_FMT_RGB565;
scaler.in_fmt = SCALER_FMT_RGB565;
video_frame_convert_to_bgr24(
scaler,
&scaler,
state->out_buffer,
(const uint8_t*)state->frame + ((int)state->height - 1)
* state->pitch,
state->width, state->height,
-state->pitch);
scaler_ctx_gen_reset(&state->scaler);
scaler_ctx_gen_reset(&scaler);
ret = rpng_save_image_bgr24(
state->filename,
@ -221,30 +196,9 @@ task_finished:
}
#if defined(HAVE_GFX_WIDGETS)
static void task_screenshot_callback(retro_task_t *task,
void task_screenshot_callback(retro_task_t *task,
void *task_data,
void *user_data, const char *error)
{
screenshot_task_state_t *state = NULL;
if (!task)
return;
state = (screenshot_task_state_t*)task->state;
if (!state)
return;
if (!state->silence && state->widgets_ready)
gfx_widget_screenshot_taken(dispwidget_get_ptr(),
state->shotname, state->filename);
free(state);
/* Must explicitly set task->state to NULL here,
* to avoid potential heap-use-after-free errors */
state = NULL;
task->state = NULL;
}
void *user_data, const char *error);
#endif
/* Take frame bottom-up. */

View File

@ -206,6 +206,30 @@ void *task_push_decompress(
void task_file_load_handler(retro_task_t *task);
typedef struct screenshot_task_state screenshot_task_state_t;
struct screenshot_task_state
{
uint8_t *out_buffer;
const void *frame;
void *userbuf;
int pitch;
unsigned width;
unsigned height;
unsigned pixel_format_type;
char filename[PATH_MAX_LENGTH];
char shotname[256];
bool bgr24;
bool silence;
bool is_idle;
bool is_paused;
bool history_list_enable;
bool widgets_ready;
};
bool take_screenshot(
const char *screenshot_dir,
const char *path, bool silence,