mirror of
https://github.com/libretro/RetroArch.git
synced 2024-11-24 16:39:43 +00:00
Replace filter cruft with new stuff.
This commit is contained in:
parent
cbc6775496
commit
4b97de0c9e
96
driver.c
96
driver.c
@ -1284,28 +1284,15 @@ void uninit_audio(void)
|
||||
#ifdef HAVE_DYLIB
|
||||
void rarch_deinit_filter(void)
|
||||
{
|
||||
g_extern.filter.active = false;
|
||||
|
||||
if (g_extern.filter.lib)
|
||||
dylib_close(g_extern.filter.lib);
|
||||
g_extern.filter.lib = NULL;
|
||||
|
||||
rarch_softfilter_free(g_extern.filter.filter);
|
||||
free(g_extern.filter.buffer);
|
||||
free(g_extern.filter.colormap);
|
||||
free(g_extern.filter.scaler_out);
|
||||
g_extern.filter.buffer = NULL;
|
||||
g_extern.filter.colormap = NULL;
|
||||
g_extern.filter.scaler_out = NULL;
|
||||
|
||||
scaler_ctx_gen_reset(&g_extern.filter.scaler);
|
||||
memset(&g_extern.filter.scaler, 0, sizeof(g_extern.filter.scaler));
|
||||
memset(&g_extern.filter, 0, sizeof(g_extern.filter));
|
||||
}
|
||||
|
||||
void rarch_init_filter(bool rgb32)
|
||||
{
|
||||
unsigned i;
|
||||
if (g_extern.filter.active)
|
||||
return;
|
||||
rarch_deinit_filter();
|
||||
if (!*g_settings.video.filter_path)
|
||||
return;
|
||||
|
||||
@ -1315,14 +1302,6 @@ void rarch_init_filter(bool rgb32)
|
||||
return;
|
||||
}
|
||||
|
||||
RARCH_LOG("Loading bSNES filter from \"%s\"\n", g_settings.video.filter_path);
|
||||
g_extern.filter.lib = dylib_load(g_settings.video.filter_path);
|
||||
if (!g_extern.filter.lib)
|
||||
{
|
||||
RARCH_ERR("Failed to load filter \"%s\"\n", g_settings.video.filter_path);
|
||||
return;
|
||||
}
|
||||
|
||||
struct retro_game_geometry *geom = &g_extern.system.av_info.geometry;
|
||||
unsigned width = geom->max_width;
|
||||
unsigned height = geom->max_height;
|
||||
@ -1330,66 +1309,37 @@ void rarch_init_filter(bool rgb32)
|
||||
unsigned pow2_y = 0;
|
||||
unsigned maxsize = 0;
|
||||
|
||||
g_extern.filter.psize =
|
||||
(void (*)(unsigned*, unsigned*))dylib_proc(g_extern.filter.lib, "filter_size");
|
||||
g_extern.filter.prender =
|
||||
(void (*)(uint32_t*, uint32_t*,
|
||||
unsigned, const uint16_t*,
|
||||
unsigned, unsigned, unsigned))dylib_proc(g_extern.filter.lib, "filter_render");
|
||||
RARCH_LOG("Loading softfilter from \"%s\"\n", g_settings.video.filter_path);
|
||||
g_extern.filter.filter = rarch_softfilter_new(g_settings.video.filter_path,
|
||||
RARCH_SOFTFILTER_THREADS_AUTO,
|
||||
rgb32 ? RETRO_PIXEL_FORMAT_XRGB8888 : RETRO_PIXEL_FORMAT_RGB565,
|
||||
width, height);
|
||||
|
||||
if (!g_extern.filter.psize || !g_extern.filter.prender)
|
||||
if (!g_extern.filter.filter)
|
||||
{
|
||||
RARCH_ERR("Failed to find functions in filter...\n");
|
||||
goto error;
|
||||
RARCH_ERR("Failed to load filter \"%s\"\n", g_settings.video.filter_path);
|
||||
return;
|
||||
}
|
||||
|
||||
g_extern.filter.active = true;
|
||||
g_extern.filter.psize(&width, &height);
|
||||
|
||||
pow2_x = next_pow2(width);
|
||||
pow2_y = next_pow2(height);
|
||||
maxsize = pow2_x > pow2_y ? pow2_x : pow2_y;
|
||||
rarch_softfilter_get_max_output_size(g_extern.filter.filter, &pow2_x, &pow2_y);
|
||||
pow2_x = next_pow2(pow2_x);
|
||||
pow2_y = next_pow2(pow2_y);
|
||||
maxsize = max(pow2_x, pow2_y);
|
||||
g_extern.filter.scale = maxsize / RARCH_SCALE_BASE;
|
||||
|
||||
g_extern.filter.buffer = (uint32_t*)malloc(RARCH_SCALE_BASE * RARCH_SCALE_BASE *
|
||||
g_extern.filter.scale * g_extern.filter.scale * sizeof(uint32_t));
|
||||
g_extern.filter.out_rgb32 = rarch_softfilter_get_output_format(g_extern.filter.filter) == RETRO_PIXEL_FORMAT_XRGB8888;
|
||||
g_extern.filter.out_bpp = g_extern.filter.out_rgb32 ? sizeof(uint32_t) : sizeof(uint16_t);
|
||||
|
||||
// TODO: Aligned output.
|
||||
g_extern.filter.buffer = malloc(width * height * g_extern.filter.out_bpp);
|
||||
if (!g_extern.filter.buffer)
|
||||
goto error;
|
||||
|
||||
g_extern.filter.pitch = RARCH_SCALE_BASE * g_extern.filter.scale * sizeof(uint32_t);
|
||||
|
||||
g_extern.filter.colormap = (uint32_t*)malloc(0x10000 * sizeof(uint32_t));
|
||||
if (!g_extern.filter.colormap)
|
||||
goto error;
|
||||
|
||||
// Set up conversion map from 16-bit XRGB1555 to 32-bit ARGB.
|
||||
for (i = 0; i < 0x10000; i++)
|
||||
{
|
||||
unsigned r = (i >> 10) & 0x1f;
|
||||
unsigned g = (i >> 5) & 0x1f;
|
||||
unsigned b = (i >> 0) & 0x1f;
|
||||
|
||||
r = (r << 3) | (r >> 2);
|
||||
g = (g << 3) | (g >> 2);
|
||||
b = (b << 3) | (b >> 2);
|
||||
g_extern.filter.colormap[i] = (r << 16) | (g << 8) | (b << 0);
|
||||
}
|
||||
|
||||
g_extern.filter.scaler_out = (uint16_t*)malloc(sizeof(uint16_t) * geom->max_width * geom->max_height);
|
||||
if (!g_extern.filter.scaler_out)
|
||||
goto error;
|
||||
|
||||
g_extern.filter.scaler.scaler_type = SCALER_TYPE_POINT;
|
||||
g_extern.filter.scaler.in_fmt = rgb32 ? SCALER_FMT_ARGB8888 : SCALER_FMT_RGB565;
|
||||
g_extern.filter.scaler.out_fmt = SCALER_FMT_0RGB1555;
|
||||
|
||||
if (!scaler_ctx_gen_filter(&g_extern.filter.scaler))
|
||||
goto error;
|
||||
|
||||
return;
|
||||
|
||||
error:
|
||||
RARCH_ERR("CPU filter init failed.\n");
|
||||
RARCH_ERR("Softfilter init failed.\n");
|
||||
rarch_deinit_filter();
|
||||
}
|
||||
#endif
|
||||
@ -1467,7 +1417,7 @@ void init_video_input(void)
|
||||
unsigned scale = next_pow2(max_dim) / RARCH_SCALE_BASE;
|
||||
scale = max(scale, 1);
|
||||
|
||||
if (g_extern.filter.active)
|
||||
if (g_extern.filter.filter)
|
||||
scale = g_extern.filter.scale;
|
||||
|
||||
// Update core-dependent aspect ratio values.
|
||||
@ -1532,7 +1482,7 @@ void init_video_input(void)
|
||||
video.force_aspect = g_settings.video.force_aspect;
|
||||
video.smooth = g_settings.video.smooth;
|
||||
video.input_scale = scale;
|
||||
video.rgb32 = g_extern.filter.active || (g_extern.system.pix_fmt == RETRO_PIXEL_FORMAT_XRGB8888);
|
||||
video.rgb32 = g_extern.filter.filter ? g_extern.filter.out_rgb32 : (g_extern.system.pix_fmt == RETRO_PIXEL_FORMAT_XRGB8888);
|
||||
|
||||
const input_driver_t *tmp = driver.input;
|
||||
find_video_driver(); // Need to grab the "real" video driver interface on a reinit.
|
||||
|
16
general.h
16
general.h
@ -507,20 +507,10 @@ struct global
|
||||
{
|
||||
rarch_softfilter_t *filter;
|
||||
|
||||
bool active;
|
||||
uint32_t *buffer;
|
||||
uint32_t *colormap;
|
||||
unsigned pitch;
|
||||
dylib_t lib;
|
||||
void *buffer;
|
||||
unsigned scale;
|
||||
|
||||
void (*psize)(unsigned *width, unsigned *height);
|
||||
void (*prender)(uint32_t *colormap, uint32_t *output, unsigned outpitch,
|
||||
const uint16_t *input, unsigned pitch, unsigned width, unsigned height);
|
||||
|
||||
// CPU filters only work on *XRGB1555*. We have to convert to XRGB1555 first.
|
||||
struct scaler_ctx scaler;
|
||||
uint16_t *scaler_out;
|
||||
unsigned out_bpp;
|
||||
bool out_rgb32;
|
||||
} filter;
|
||||
|
||||
msg_queue_t *msg_queue;
|
||||
|
@ -59,6 +59,8 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_path,
|
||||
goto error;
|
||||
|
||||
// Simple assumptions.
|
||||
filt->pix_fmt = in_pixel_format;
|
||||
filt->out_pix_fmt = in_pixel_format;
|
||||
unsigned input_fmt = in_pixel_format == RETRO_PIXEL_FORMAT_XRGB8888 ?
|
||||
SOFTFILTER_FMT_XRGB8888 : SOFTFILTER_FMT_RGB565;
|
||||
unsigned input_fmts = filt->impl->query_input_formats();
|
||||
@ -71,8 +73,6 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_path,
|
||||
|
||||
filt->max_width = max_width;
|
||||
filt->max_height = max_height;
|
||||
filt->pix_fmt = in_pixel_format;
|
||||
filt->out_pix_fmt = in_pixel_format;
|
||||
|
||||
filt->impl_data = filt->impl->create(input_fmt, input_fmt, max_width, max_height,
|
||||
threads != RARCH_SOFTFILTER_THREADS_AUTO ? threads : 1, cpu_features);
|
||||
|
28
retroarch.c
28
retroarch.c
@ -297,7 +297,7 @@ static void video_frame(const void *data, unsigned width, unsigned height, size_
|
||||
// Slightly messy code,
|
||||
// but we really need to do processing before blocking on VSync for best possible scheduling.
|
||||
#ifdef HAVE_FFMPEG
|
||||
if (g_extern.recording && (!g_extern.filter.active || !g_settings.video.post_filter_record || !data || g_extern.record_gpu_buffer))
|
||||
if (g_extern.recording && (!g_extern.filter.filter || !g_settings.video.post_filter_record || !data || g_extern.record_gpu_buffer))
|
||||
recording_dump_frame(data, width, height, pitch);
|
||||
#endif
|
||||
|
||||
@ -305,28 +305,26 @@ static void video_frame(const void *data, unsigned width, unsigned height, size_
|
||||
driver.current_msg = msg;
|
||||
|
||||
#ifdef HAVE_DYLIB
|
||||
if (g_extern.filter.active && data)
|
||||
if (g_extern.filter.filter && data)
|
||||
{
|
||||
struct scaler_ctx *scaler = &g_extern.filter.scaler;
|
||||
scaler->in_width = scaler->out_width = width;
|
||||
scaler->in_height = scaler->out_height = height;
|
||||
scaler->in_stride = pitch;
|
||||
scaler->out_stride = width * sizeof(uint16_t);
|
||||
unsigned owidth = 0;
|
||||
unsigned oheight = 0;
|
||||
unsigned opitch = 0;
|
||||
rarch_softfilter_get_output_size(g_extern.filter.filter,
|
||||
&owidth, &oheight, width, height);
|
||||
|
||||
scaler_ctx_scale(scaler, g_extern.filter.scaler_out, data);
|
||||
opitch = owidth * g_extern.filter.out_bpp;
|
||||
|
||||
unsigned owidth = width;
|
||||
unsigned oheight = height;
|
||||
g_extern.filter.psize(&owidth, &oheight);
|
||||
g_extern.filter.prender(g_extern.filter.colormap, g_extern.filter.buffer,
|
||||
g_extern.filter.pitch, g_extern.filter.scaler_out, scaler->out_stride, width, height);
|
||||
rarch_softfilter_process(g_extern.filter.filter,
|
||||
g_extern.filter.buffer, opitch,
|
||||
data, width, height, pitch);
|
||||
|
||||
#ifdef HAVE_FFMPEG
|
||||
if (g_extern.recording && g_settings.video.post_filter_record)
|
||||
recording_dump_frame(g_extern.filter.buffer, owidth, oheight, g_extern.filter.pitch);
|
||||
recording_dump_frame(g_extern.filter.buffer, owidth, oheight, opitch);
|
||||
#endif
|
||||
|
||||
if (!video_frame_func(g_extern.filter.buffer, owidth, oheight, g_extern.filter.pitch, msg))
|
||||
if (!video_frame_func(g_extern.filter.buffer, owidth, oheight, opitch, msg))
|
||||
g_extern.video_active = false;
|
||||
}
|
||||
else if (!video_frame_func(data, width, height, pitch, msg))
|
||||
|
Loading…
Reference in New Issue
Block a user