From 6c671faed69797712922b9c06b211a8c1a77abd2 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 15 Aug 2019 14:20:51 +0200 Subject: [PATCH] Start preparing for menu_widgets_ready to be moved to retroarch.c --- cheevos-new/cheevos.c | 2 +- gfx/common/metal_common.m | 3 +- gfx/drivers/d3d10.c | 3 +- gfx/drivers/d3d11.c | 3 +- gfx/drivers/d3d12.c | 3 +- gfx/drivers/d3d9.c | 3 +- gfx/drivers/gl.c | 3 +- gfx/drivers/gl1.c | 3 +- gfx/drivers/gl_core.c | 3 +- gfx/drivers/gx2_gfx.c | 3 +- gfx/drivers/vulkan.c | 3 +- menu/widgets/menu_widgets.c | 70 ++++++------------------------------- menu/widgets/menu_widgets.h | 2 +- retroarch.c | 60 ++++++++++++++++++++++--------- retroarch.h | 1 + tasks/task_screenshot.c | 2 +- 16 files changed, 79 insertions(+), 88 deletions(-) diff --git a/cheevos-new/cheevos.c b/cheevos-new/cheevos.c index 0829eef447..e5ff1ede1c 100644 --- a/cheevos-new/cheevos.c +++ b/cheevos-new/cheevos.c @@ -504,7 +504,7 @@ static void rcheevos_award(rcheevos_cheevo_t* cheevo, int mode) /* Show the OSD message. */ #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) - if (!menu_widgets_push_achievement(cheevo->info->title, cheevo->info->badge)) + if (!menu_widgets_ready() || !menu_widgets_push_achievement(cheevo->info->title, cheevo->info->badge)) #endif { snprintf(buffer, sizeof(buffer), "Achievement Unlocked: %s", cheevo->info->title); diff --git a/gfx/common/metal_common.m b/gfx/common/metal_common.m index 9816215ec8..0d392e170c 100644 --- a/gfx/common/metal_common.m +++ b/gfx/common/metal_common.m @@ -297,7 +297,8 @@ #ifdef HAVE_MENU #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif #endif diff --git a/gfx/drivers/d3d10.c b/gfx/drivers/d3d10.c index 6df2afa207..5968169bdb 100644 --- a/gfx/drivers/d3d10.c +++ b/gfx/drivers/d3d10.c @@ -1501,7 +1501,8 @@ static bool d3d10_gfx_frame( #ifdef HAVE_MENU #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif #endif diff --git a/gfx/drivers/d3d11.c b/gfx/drivers/d3d11.c index e13b6f9183..5bab78a2ea 100644 --- a/gfx/drivers/d3d11.c +++ b/gfx/drivers/d3d11.c @@ -1567,7 +1567,8 @@ static bool d3d11_gfx_frame( #ifdef HAVE_MENU #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif #endif diff --git a/gfx/drivers/d3d12.c b/gfx/drivers/d3d12.c index 5596621683..4353b81c61 100644 --- a/gfx/drivers/d3d12.c +++ b/gfx/drivers/d3d12.c @@ -1558,7 +1558,8 @@ static bool d3d12_gfx_frame( #ifdef HAVE_MENU #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif #endif diff --git a/gfx/drivers/d3d9.c b/gfx/drivers/d3d9.c index 2f35fba975..b5b2cb4199 100644 --- a/gfx/drivers/d3d9.c +++ b/gfx/drivers/d3d9.c @@ -1658,7 +1658,8 @@ static bool d3d9_frame(void *data, const void *frame, #ifdef HAVE_MENU #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif #endif diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index ba7d053a96..916fea6cfd 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -3048,7 +3048,8 @@ static bool gl2_frame(void *data, const void *frame, #endif #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif if (!string_is_empty(msg)) diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index bc56790819..324bdf4c98 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -836,7 +836,8 @@ static bool gl1_gfx_frame(void *data, const void *frame, } #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif #endif diff --git a/gfx/drivers/gl_core.c b/gfx/drivers/gl_core.c index 7e8f588538..75023f1771 100644 --- a/gfx/drivers/gl_core.c +++ b/gfx/drivers/gl_core.c @@ -1698,7 +1698,8 @@ static bool gl_core_frame(void *data, const void *frame, #endif #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif if (!string_is_empty(msg)) diff --git a/gfx/drivers/gx2_gfx.c b/gfx/drivers/gx2_gfx.c index 29da72c7bd..7d8cbc3c10 100644 --- a/gfx/drivers/gx2_gfx.c +++ b/gfx/drivers/gx2_gfx.c @@ -1346,7 +1346,8 @@ static bool wiiu_gfx_frame(void *data, const void *frame, #ifdef HAVE_MENU #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif #endif diff --git a/gfx/drivers/vulkan.c b/gfx/drivers/vulkan.c index c630fbefc8..b3a3707535 100644 --- a/gfx/drivers/vulkan.c +++ b/gfx/drivers/vulkan.c @@ -1943,7 +1943,8 @@ static bool vulkan_frame(void *data, const void *frame, font_driver_render_msg(video_info, NULL, msg, NULL); #ifdef HAVE_MENU_WIDGETS - menu_widgets_frame(video_info); + if (video_info->widgets_inited) + menu_widgets_frame(video_info); #endif /* End the render pass. We're done rendering to backbuffer now. */ diff --git a/menu/widgets/menu_widgets.c b/menu/widgets/menu_widgets.c index 69aa885980..0fd401afb3 100644 --- a/menu/widgets/menu_widgets.c +++ b/menu/widgets/menu_widgets.c @@ -311,9 +311,6 @@ static unsigned generic_message_height; /* used for both generic and libretro me bool menu_widgets_set_paused(bool is_paused) { - if (!menu_widgets_inited) - return false; - menu_widgets_paused = is_paused; return true; } @@ -811,9 +808,6 @@ void menu_widgets_iterate(unsigned width, unsigned height) size_t i; settings_t *settings = config_get_ptr(); - if (!menu_widgets_inited) - return; - /* Messages queue */ /* Consume one message if available */ @@ -1297,9 +1291,6 @@ void menu_widgets_frame(video_frame_info_t *video_info) settings_t *settings = config_get_ptr(); - if (!menu_widgets_inited) - return; - menu_widgets_frame_count++; menu_display_set_viewport(video_info->width, video_info->height); @@ -1722,13 +1713,10 @@ void menu_widgets_frame(video_frame_info_t *video_info) menu_display_unset_viewport(video_info->width, video_info->height); } -void menu_widgets_init(bool video_is_threaded) +bool menu_widgets_init(bool video_is_threaded) { - if (menu_widgets_inited) - return; - if (!menu_display_init_first_driver(video_is_threaded)) - goto err; + goto error; menu_widgets_frame_count = 0; @@ -1737,21 +1725,24 @@ void menu_widgets_init(bool video_is_threaded) msg_queue = fifo_new(MSG_QUEUE_PENDING_MAX * sizeof(menu_widget_msg_t*)); if (!msg_queue) - goto err; + goto error; current_msgs = (file_list_t*)calloc(1, sizeof(file_list_t)); if (!current_msgs) - goto err; + goto error; if (!file_list_reserve(current_msgs, MSG_QUEUE_ONSCREEN_MAX)) - goto err; + goto error; menu_widgets_inited = true; - return; -err: - menu_widgets_free(); + return true; + +error: + if (menu_widgets_inited) + menu_widgets_free(); + return false; } void menu_widgets_context_reset(bool is_threaded, @@ -1766,9 +1757,6 @@ void menu_widgets_context_reset(bool is_threaded, char font_path[PATH_MAX_LENGTH]; settings_t *settings = config_get_ptr(); - if (!menu_widgets_inited) - return; - /* Textures paths */ fill_pathname_join( menu_widgets_path, @@ -1889,8 +1877,6 @@ void menu_widgets_context_reset(bool is_threaded, void menu_widgets_context_destroy(void) { int i; - if (!menu_widgets_inited) - return; /* TODO: Dismiss onscreen notifications that have been freed */ @@ -1932,9 +1918,6 @@ void menu_widgets_free(void) size_t i; menu_animation_ctx_tag libretro_tag; - if (!menu_widgets_inited) - return; - menu_widgets_inited = false; /* Kill any pending animation */ @@ -2027,9 +2010,6 @@ bool menu_widgets_volume_update_and_show(void) float new_volume = settings->floats.audio_volume; menu_timer_ctx_entry_t entry; - if (!menu_widgets_inited) - return false; - menu_animation_kill_by_tag(&volume_tag); volume_db = new_volume; @@ -2049,9 +2029,6 @@ bool menu_widgets_volume_update_and_show(void) bool menu_widgets_set_fps_text(char *new_fps_text) { - if (!menu_widgets_inited) - return false; - strlcpy(menu_widgets_fps_text, new_fps_text, sizeof(menu_widgets_fps_text)); @@ -2060,19 +2037,12 @@ bool menu_widgets_set_fps_text(char *new_fps_text) bool menu_widgets_set_fast_forward(bool is_fast_forward) { - if (!menu_widgets_inited) - return false; - menu_widgets_fast_forward = is_fast_forward; - return true; } bool menu_widgets_set_rewind(bool is_rewind) { - if (!menu_widgets_inited) - return false; - menu_widgets_rewinding = is_rewind; return true; @@ -2082,9 +2052,6 @@ static void menu_widgets_screenshot_fadeout(void *userdata) { menu_animation_ctx_entry_t entry; - if (!menu_widgets_inited) - return; - entry.cb = NULL; entry.duration = SCREENSHOT_DURATION_OUT; entry.easing_enum = EASING_OUT_QUAD; @@ -2100,9 +2067,6 @@ static void menu_widgets_play_screenshot_flash(void) { menu_animation_ctx_entry_t entry; - if (!menu_widgets_inited) - return; - entry.cb = menu_widgets_screenshot_fadeout; entry.duration = SCREENSHOT_DURATION_IN; entry.easing_enum = EASING_IN_QUAD; @@ -2116,9 +2080,6 @@ static void menu_widgets_play_screenshot_flash(void) void menu_widgets_screenshot_taken(const char *shotname, const char *filename) { - if (!menu_widgets_inited) - return; - menu_widgets_play_screenshot_flash(); strlcpy(screenshot_filename, filename, sizeof(screenshot_filename)); strlcpy(screenshot_shotname, shotname, sizeof(screenshot_shotname)); @@ -2344,9 +2305,6 @@ static void menu_widgets_get_badge_texture(menu_texture_item *tex, const char *b bool menu_widgets_push_achievement(const char *title, const char *badge) { - if (!menu_widgets_inited) - return false; - menu_widgets_achievement_free(NULL); /* TODO: Make a queue of notifications to display */ @@ -2381,9 +2339,6 @@ bool menu_widgets_set_message(char *msg) menu_animation_ctx_tag tag = (uintptr_t) &generic_message_timer; menu_timer_ctx_entry_t timer; - if (!menu_widgets_inited) - return false; - snprintf(generic_message, GENERIC_MESSAGE_SIZE, "%s", msg); generic_message_alpha = DEFAULT_BACKDROP; @@ -2423,9 +2378,6 @@ bool menu_widgets_set_libretro_message(const char *msg, unsigned duration) menu_animation_ctx_tag tag = (uintptr_t) &libretro_message_timer; menu_timer_ctx_entry_t timer; - if (!menu_widgets_inited) - return false; - snprintf(libretro_message, LIBRETRO_MESSAGE_SIZE, "%s", msg); libretro_message_alpha = DEFAULT_BACKDROP; diff --git a/menu/widgets/menu_widgets.h b/menu/widgets/menu_widgets.h index a809a204c9..6f63a84c8d 100644 --- a/menu/widgets/menu_widgets.h +++ b/menu/widgets/menu_widgets.h @@ -37,7 +37,7 @@ #define HOURGLASS_DURATION 1000 #define GENERIC_MESSAGE_DURATION 3000 -void menu_widgets_init(bool video_is_threaded); +bool menu_widgets_init(bool video_is_threaded); void menu_widgets_free(void); bool menu_widgets_ready(void); diff --git a/retroarch.c b/retroarch.c index 370bf0be87..40028f3d41 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2182,7 +2182,7 @@ bool command_set_shader(const char *arg) snprintf(msg, sizeof(msg), "Shader: \"%s\"", arg ? path_basename(arg) : "null"); #ifdef HAVE_MENU_WIDGETS - if (!menu_widgets_set_message(msg)) + if (!menu_widgets_ready() || !menu_widgets_set_message(msg)) #endif runloop_msg_queue_push(msg, 1, 120, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); @@ -2846,7 +2846,7 @@ static void command_event_set_volume(float gain) new_volume); #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) - if (!menu_widgets_volume_update_and_show()) + if (!menu_widgets_ready() || !menu_widgets_volume_update_and_show()) #endif runloop_msg_queue_push(msg, 1, 180, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); @@ -3752,7 +3752,7 @@ static void retroarch_pause_checks(void) command_event(CMD_EVENT_AUDIO_STOP, NULL); #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) - if (!menu_widgets_set_paused(is_paused)) + if (!menu_widgets_ready() || !menu_widgets_set_paused(is_paused)) #endif runloop_msg_queue_push(msg_hash_to_str(MSG_PAUSED), 1, 1, true, @@ -3769,7 +3769,8 @@ static void retroarch_pause_checks(void) else { #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) - menu_widgets_set_paused(is_paused); + if (menu_widgets_ready()) + menu_widgets_set_paused(is_paused); #endif RARCH_LOG("%s\n", msg_hash_to_str(MSG_UNPAUSED)); command_event(CMD_EVENT_AUDIO_START, NULL); @@ -6703,7 +6704,7 @@ static bool rarch_environment_cb(unsigned cmd, void *data) const struct retro_message *msg = (const struct retro_message*)data; RARCH_LOG("Environ SET_MESSAGE: %s\n", msg->msg); #ifdef HAVE_MENU_WIDGETS - if (!menu_widgets_set_libretro_message(msg->msg, roundf((float)msg->frames / 60.0f * 1000.0f))) + if (!menu_widgets_ready() || !menu_widgets_set_libretro_message(msg->msg, roundf((float)msg->frames / 60.0f * 1000.0f))) #endif runloop_msg_queue_push(msg->msg, 3, msg->frames, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); break; @@ -18300,7 +18301,7 @@ void video_driver_frame(const void *data, unsigned width, if (video_info.fps_show || video_info.framecount_show) { #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) - if (!menu_widgets_set_fps_text(video_info.fps_text)) + if (!menu_widgets_ready() || !menu_widgets_set_fps_text(video_info.fps_text)) #endif runloop_msg_queue_push(video_info.fps_text, 2, 1, true, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } @@ -18454,6 +18455,12 @@ void video_driver_build_info(video_frame_info_t *video_info) video_info->fps_text[0] = '\0'; +#ifdef HAVE_MENU_WIDGETS + video_info->widgets_inited = menu_widgets_ready(); +#else + video_info->widgets_inited = false; +#endif + video_info->width = video_driver_width; video_info->height = video_driver_height; @@ -19801,9 +19808,22 @@ static void drivers_init(int flags) if (settings->bools.menu_enable_widgets && video_driver_has_widgets()) { - menu_widgets_init(video_is_threaded); - menu_widgets_context_reset(video_is_threaded, - video_driver_width, video_driver_height); + /* TODO/FIXME - get rid of this local variable + * once we have moved it over */ + bool widgets_inited = menu_widgets_ready(); + + if (!widgets_inited) + { + if (menu_widgets_init(video_is_threaded)) + { + /* TODO/FIXME - set menu_widgets_inited to true here */ + } + } + + widgets_inited = menu_widgets_ready(); + if (widgets_inited) + menu_widgets_context_reset(video_is_threaded, + video_driver_width, video_driver_height); } #endif @@ -19861,8 +19881,11 @@ static void driver_uninit(int flags) /* This absolutely has to be done before video_driver_free() * is called/completes, otherwise certain menu drivers * (e.g. Vulkan) will segfault */ - menu_widgets_context_destroy(); - menu_widgets_free(); + if (menu_widgets_ready()) + { + menu_widgets_context_destroy(); + menu_widgets_free(); + } #endif menu_driver_ctl(RARCH_MENU_CTL_DEINIT, NULL); } @@ -19929,8 +19952,11 @@ bool driver_ctl(enum driver_ctl_state state, void *data) * in case the handle is lost in the threaded * video driver in the meantime * (breaking video_driver_has_widgets) */ - menu_widgets_context_destroy(); - menu_widgets_free(); + if (menu_widgets_ready()) + { + menu_widgets_context_destroy(); + menu_widgets_free(); + } #endif /* Video */ @@ -23149,7 +23175,7 @@ static void update_fastforwarding_state(void) if (runloop_fastmotion) { #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) - if (!menu_widgets_set_fast_forward(true)) + if (!menu_widgets_ready() || !menu_widgets_set_fast_forward(true)) #endif runloop_msg_queue_push( msg_hash_to_str(MSG_FAST_FORWARD), 1, 1, false, NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); @@ -23157,7 +23183,8 @@ static void update_fastforwarding_state(void) #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) else { - menu_widgets_set_fast_forward(false); + if (menu_widgets_ready()) + menu_widgets_set_fast_forward(false); } #endif } @@ -23859,7 +23886,8 @@ static enum runloop_state runloop_check_state(void) MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); #if defined(HAVE_MENU) && defined(HAVE_MENU_WIDGETS) - menu_widgets_set_rewind(rewinding); + if (menu_widgets_ready()) + menu_widgets_set_rewind(rewinding); #endif } diff --git a/retroarch.h b/retroarch.h index f78a93e539..a10ca05e9f 100644 --- a/retroarch.h +++ b/retroarch.h @@ -1122,6 +1122,7 @@ typedef struct video_info typedef struct video_frame_info { + bool widgets_inited; bool input_menu_swap_ok_cancel_buttons; bool input_driver_nonblock_state; bool shared_context; diff --git a/tasks/task_screenshot.c b/tasks/task_screenshot.c index d0bb6b951d..2e8daaf440 100644 --- a/tasks/task_screenshot.c +++ b/tasks/task_screenshot.c @@ -204,7 +204,7 @@ static void task_screenshot_callback(retro_task_t *task, if (!state->widgets_ready) return; - if (state && !state->silence) + if (state && !state->silence && state->widgets_ready) menu_widgets_screenshot_taken(state->shotname, state->filename); free(state);