diff --git a/driver.c b/driver.c index b696b2e46e..edbd18fd2d 100644 --- a/driver.c +++ b/driver.c @@ -1291,7 +1291,11 @@ void rarch_deinit_filter(void) void rarch_init_filter(enum retro_pixel_format colfmt) { rarch_deinit_filter(); +#ifdef HAVE_FILTERS_BUILTIN + if (!g_settings.video.filter_idx) +#else if (!*g_settings.video.filter_path) +#endif return; // Deprecated format. Gets pre-converted. @@ -1311,13 +1315,21 @@ void rarch_init_filter(enum retro_pixel_format colfmt) unsigned pow2_y = 0; unsigned maxsize = 0; +#ifdef HAVE_FILTERS_BUILTIN + RARCH_LOG("Loading softfilter %d\n", g_settings.video.filter_idx); +#else RARCH_LOG("Loading softfilter from \"%s\"\n", g_settings.video.filter_path); +#endif g_extern.filter.filter = rarch_softfilter_new(g_settings.video.filter_path, RARCH_SOFTFILTER_THREADS_AUTO, colfmt, width, height); if (!g_extern.filter.filter) { +#ifdef HAVE_FILTERS_BUILTIN + RARCH_LOG("Loading softfilter %d\n", g_settings.video.filter_idx); +#else RARCH_ERR("Failed to load filter \"%s\"\n", g_settings.video.filter_path); +#endif return; } diff --git a/frontend/menu/menu_settings.c b/frontend/menu/menu_settings.c index a4882e6c4e..5ac59eb459 100644 --- a/frontend/menu/menu_settings.c +++ b/frontend/menu/menu_settings.c @@ -777,14 +777,32 @@ int menu_set_settings(void *data, unsigned setting, unsigned action) case RGUI_SETTINGS_VIDEO_SOFTFILTER: switch (action) { -#ifdef HAVE_DYLIB +#if defined(HAVE_FILTERS_BUILTIN) + case RGUI_ACTION_LEFT: + if (g_settings.video.filter_idx > 0) + g_settings.video.filter_idx--; + break; + case RGUI_ACTION_RIGHT: + if ((g_settings.video.filter_idx + 1) != SOFTFILTER_LAST) + g_settings.video.filter_idx++; + break; +#endif case RGUI_ACTION_OK: +#if defined(HAVE_FILTERS_BUILTIN) + rarch_set_fullscreen(g_settings.video.fullscreen); + rgui->need_refresh = true; +#if defined(HAVE_DYLIB) file_list_push(rgui->menu_stack, g_settings.video.filter_dir, setting, rgui->selection_ptr); menu_clear_navigation(rgui); rgui->need_refresh = true; +#endif break; case RGUI_ACTION_START: +#if defined(HAVE_FILTERS_BUILTIN) + g_settings.video.filter_idx = SOFTFILTER_NONE; +#else strlcpy(g_settings.video.filter_path, "", sizeof(g_settings.video.filter_path)); +#endif rarch_set_fullscreen(g_settings.video.fullscreen); break; default: @@ -2242,7 +2260,24 @@ void menu_set_settings_label(char *type_str, size_t type_str_size, unsigned *w, strlcpy(type_str, "...", type_str_size); break; case RGUI_SETTINGS_VIDEO_SOFTFILTER: - strlcpy(type_str, path_basename(g_settings.video.filter_path), type_str_size); + { +#ifdef HAVE_FILTERS_BUILTIN + unsigned cpu_features; + const struct softfilter_implementation *impl; + softfilter_get_implementation_t cb = softfilter_get_implementation_from_idx(g_settings.video.filter_idx); + if (cb) + { + cpu_features = rarch_get_cpu_features(); + impl = (const struct softfilter_implementation *)cb(cpu_features); + if (impl) + strlcpy(type_str, impl->ident, type_str_size); + } + else + strlcpy(type_str, "N/A", type_str_size); +#else + strlcpy(type_str, path_basename(g_settings.video.filter_path), type_str_size); +#endif + } break; #ifdef HAVE_OVERLAY case RGUI_SETTINGS_OVERLAY_PRESET: diff --git a/general.h b/general.h index 5844f96ae3..466a1a2282 100644 --- a/general.h +++ b/general.h @@ -156,6 +156,9 @@ struct settings char shader_path[PATH_MAX]; bool shader_enable; +#ifdef HAVE_FILTERS_BUILTIN + unsigned filter_idx; +#endif char filter_path[PATH_MAX]; float refresh_rate; bool threaded; diff --git a/gfx/filter.c b/gfx/filter.c index 300b792663..0d3dfa8795 100644 --- a/gfx/filter.c +++ b/gfx/filter.c @@ -14,6 +14,7 @@ */ #include "filter.h" +#include "filters/softfilter.h" #include "../dynamic.h" #include "../general.h" #include "../performance.h" @@ -64,7 +65,7 @@ static void filter_thread_loop(void *data) struct rarch_softfilter { -#ifdef HAVE_DYLIB +#if !defined(HAVE_FILTERS_BUILTIN) && defined(HAVE_DYLIB) dylib_t lib; #endif @@ -82,6 +83,26 @@ struct rarch_softfilter #endif }; +#ifdef HAVE_FILTERS_BUILTIN +static softfilter_get_implementation_t softfilter_get_implementation_from_idx(unsigned idx) +{ + switch (idx) + { +#if 0 + case SOFTFILTER_2XBR: + return twoxbr_get_implementation; + break; +#endif + case SOFTFILTER_DARKEN: + return darken_get_implementation; + case SOFTFILTER_SCALE2X: + return scale2x_get_implementation; + } + + return NULL; +} +#endif + rarch_softfilter_t *rarch_softfilter_new(const char *filter_path, unsigned threads, enum retro_pixel_format in_pixel_format, @@ -95,15 +116,14 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_path, if (!filt) return NULL; - (void)cb; -#ifdef HAVE_DYLIB +#if defined(HAVE_FILTERS_BUILTIN) + cb = softfilter_get_implementation_from_idx(g_settings.video.filter_idx); +#elif defined(HAVE_DYLIB) filt->lib = dylib_load(filter_path); if (!filt->lib) goto error; cb = (softfilter_get_implementation_t)dylib_proc(filt->lib, "softfilter_get_implementation"); -#else - // FIXME - TODO - implement for non-HAVE_DYLIB #endif if (!cb) { @@ -225,7 +245,7 @@ void rarch_softfilter_free(rarch_softfilter_t *filt) free(filt->packets); if (filt->impl && filt->impl_data) filt->impl->destroy(filt->impl_data); -#ifdef HAVE_DYLIB +#if !defined(HAVE_FILTERS_BUILTIN) && defined(HAVE_DYLIB) if (filt->lib) dylib_close(filt->lib); #endif diff --git a/gfx/filter.h b/gfx/filter.h index ca544b7713..8e2ca80346 100644 --- a/gfx/filter.h +++ b/gfx/filter.h @@ -44,5 +44,20 @@ void rarch_softfilter_process(rarch_softfilter_t *filt, void *output, size_t output_stride, const void *input, unsigned width, unsigned height, size_t input_stride); +enum +{ + SOFTFILTER_NONE = 0, + //SOFTFILTER_2XBR, + SOFTFILTER_DARKEN, + SOFTFILTER_SCALE2X, + SOFTFILTER_LAST, +}; + +#ifdef HAVE_FILTERS_BUILTIN +const struct softfilter_implementation *twoxbr_get_implementation(softfilter_simd_mask_t simd); +const struct softfilter_implementation *darken_get_implementation(softfilter_simd_mask_t simd); +const struct softfilter_implementation *scale2x_get_implementation(softfilter_simd_mask_t simd); +#endif + #endif diff --git a/griffin/griffin.c b/griffin/griffin.c index 9eb99c127f..b7ca7b19b5 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -14,6 +14,10 @@ * If not, see . */ +#ifndef HAVE_DYLIB +#define HAVE_FILTERS_BUILTIN +#endif + #if defined(_XBOX) #include "../msvc/msvc_compat.h" #endif @@ -471,7 +475,8 @@ SCALERS /*============================================================ FILTERS ============================================================ */ -#ifndef HAVE_DYLIB + +#ifdef HAVE_FILTERS_BUILTIN #include "../gfx/filters/2xbr.c" #include "../gfx/filters/darken.c" #include "../gfx/filters/scale2x.c" diff --git a/performance.c b/performance.c index 0dc36ed09d..729608cae9 100644 --- a/performance.c +++ b/performance.c @@ -301,6 +301,8 @@ unsigned rarch_get_cpu_cores(void) return sysinfo.dwNumberOfProcessors; #elif defined(ANDROID) return android_getCpuCount(); +#elif defined(GEKKO) + return 1; #elif defined(_SC_NPROCESSORS_ONLN) // Linux, most unix-likes. long ret = sysconf(_SC_NPROCESSORS_ONLN); if (ret <= 0)