From d58c802e3bd1bca8ab0b28196de2d7f52078a256 Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 30 Jul 2016 14:36:01 -0500 Subject: [PATCH] restore the original shader on close --- command.c | 11 +++++++++++ command.h | 3 ++- configuration.c | 24 ++++++++++++++++++++++++ configuration.h | 10 ++++++++++ runloop.c | 21 +++++++++++++++++++++ runloop.h | 4 ++++ 6 files changed, 72 insertions(+), 1 deletion(-) diff --git a/command.c b/command.c index 286e996128..af5f331d67 100644 --- a/command.c +++ b/command.c @@ -1170,6 +1170,7 @@ static void command_event_deinit_core(bool reinit) } command_event(CMD_EVENT_DISABLE_OVERRIDES, NULL); + command_event(CMD_EVENT_RESTORE_DEFAULT_SHADER_PRESET, NULL); } static void command_event_init_cheats(void) @@ -1386,6 +1387,12 @@ static void command_event_disable_overrides(void) } } +static void command_event_restore_default_shader_preset(void) +{ + /* auto shader preset: reload the original shader */ + config_unload_shader_preset(); +} + static bool command_event_save_auto_state(void) { bool ret; @@ -1910,6 +1917,7 @@ bool command_event(enum event_command cmd, void *data) case CMD_EVENT_QUIT: command_event(CMD_EVENT_AUTOSAVE_STATE, NULL); command_event(CMD_EVENT_DISABLE_OVERRIDES, NULL); + command_event(CMD_EVENT_RESTORE_DEFAULT_SHADER_PRESET, NULL); switch (cmd) { @@ -2523,6 +2531,9 @@ bool command_event(enum event_command cmd, void *data) case CMD_EVENT_DISABLE_OVERRIDES: command_event_disable_overrides(); break; + case CMD_EVENT_RESTORE_DEFAULT_SHADER_PRESET: + command_event_restore_default_shader_preset(); + break; case CMD_EVENT_NONE: default: return false; diff --git a/command.h b/command.h index 2725022923..5e64daa059 100644 --- a/command.h +++ b/command.h @@ -212,7 +212,8 @@ enum event_command CMD_EVENT_PERFCNT_REPORT_FRONTEND_LOG, CMD_EVENT_VOLUME_UP, CMD_EVENT_VOLUME_DOWN, - CMD_EVENT_DISABLE_OVERRIDES + CMD_EVENT_DISABLE_OVERRIDES, + CMD_EVENT_RESTORE_DEFAULT_SHADER_PRESET }; #ifdef HAVE_COMMAND diff --git a/configuration.c b/configuration.c index db29a57431..29531d8842 100644 --- a/configuration.c +++ b/configuration.c @@ -2295,6 +2295,7 @@ bool config_load_shader_preset(void) if (new_conf) { RARCH_LOG("Shaders: game-specific shader preset found at %s.\n", game_path); + runloop_ctl(RUNLOOP_CTL_SET_DEFAULT_SHADER_PRESET, settings->path.shader); strlcpy(settings->path.shader, game_path, sizeof(settings->path.shader)); return true; } @@ -2310,6 +2311,7 @@ bool config_load_shader_preset(void) if (new_conf) { RARCH_LOG("Shaders: core-specific shader preset found at %s.\n", core_path); + runloop_ctl(RUNLOOP_CTL_SET_DEFAULT_SHADER_PRESET, settings->path.shader); strlcpy(settings->path.shader, core_path, sizeof(settings->path.shader)); return true; } @@ -2322,6 +2324,28 @@ bool config_load_shader_preset(void) return false; } +/** + * config_unload_shader_preset: + * + * Restores the original preset that was loaded before a core/game. + * preset was loaded + * + * Returns: false if there was an error. + */ +bool config_unload_shader_preset(void) +{ + char *preset = NULL; + settings_t *settings = config_get_ptr(); + if (runloop_ctl(RUNLOOP_CTL_GET_DEFAULT_SHADER_PRESET, &preset) && + preset) + { + RARCH_WARN("Shaders: restoring default shader preset to %s\n", + preset); + strlcpy(settings->path.shader, preset, sizeof(settings->path.shader)); + } +} + + static void parse_config_file(void) { global_t *global = global_get_ptr(); diff --git a/configuration.h b/configuration.h index 71fe065f92..aa92daa3c9 100644 --- a/configuration.h +++ b/configuration.h @@ -628,6 +628,16 @@ bool config_load_remap(void); */ bool config_load_shader_preset(void); +/** + * config_unload_shader_preset: + * + * Restores the original preset that was loaded before a core/game. + * preset was loaded + * + * Returns: false if there was an error. + */ +bool config_unload_shader_preset(void); + /** * config_save_autoconf_profile: * @path : Path that shall be written to. diff --git a/runloop.c b/runloop.c index 6ee95c8a33..2ff9b7d734 100644 --- a/runloop.c +++ b/runloop.c @@ -100,6 +100,7 @@ typedef struct event_cmd_state static rarch_dir_list_t runloop_shader_dir; static char runloop_fullpath[PATH_MAX_LENGTH]; +static char runloop_default_shader_preset[PATH_MAX_LENGTH]; static rarch_system_info_t runloop_system; static unsigned runloop_pending_windowed_scale; static struct retro_frame_time_callback runloop_frame_time; @@ -931,6 +932,26 @@ bool runloop_ctl(enum runloop_ctl_state state, void *data) strlcpy(runloop_fullpath, fullpath, sizeof(runloop_fullpath)); } break; + case RUNLOOP_CTL_CLEAR_DEFAULT_SHADER_PRESET: + *runloop_default_shader_preset = '\0'; + break; + case RUNLOOP_CTL_GET_DEFAULT_SHADER_PRESET: + { + char **preset = (char**)data; + if (!preset) + return false; + *preset = (char*)runloop_default_shader_preset; + } + break; + case RUNLOOP_CTL_SET_DEFAULT_SHADER_PRESET: + { + const char *preset = (const char*)data; + if (!preset) + return false; + strlcpy(runloop_default_shader_preset, preset, + sizeof(runloop_default_shader_preset)); + } + break; case RUNLOOP_CTL_FRAME_TIME_FREE: memset(&runloop_frame_time, 0, sizeof(struct retro_frame_time_callback)); runloop_frame_time_last = 0; diff --git a/runloop.h b/runloop.h index 19abb7173f..f31e86e172 100644 --- a/runloop.h +++ b/runloop.h @@ -61,6 +61,10 @@ enum runloop_ctl_state RUNLOOP_CTL_SET_CONTENT_PATH, RUNLOOP_CTL_CLEAR_CONTENT_PATH, + RUNLOOP_CTL_GET_DEFAULT_SHADER_PRESET, + RUNLOOP_CTL_SET_DEFAULT_SHADER_PRESET, + RUNLOOP_CTL_CLEAR_DEFAULT_SHADER_PRESET, + RUNLOOP_CTL_SET_LIBRETRO_PATH, RUNLOOP_CTL_IS_SLOWMOTION,