mirror of
https://github.com/libretro/RetroArch
synced 2025-04-11 00:44:20 +00:00
Better error handling of filter stuff.
This commit is contained in:
parent
4b97de0c9e
commit
3e83e45a7d
39
gfx/filter.c
39
gfx/filter.c
@ -58,18 +58,37 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_path,
|
|||||||
if (!filt->impl)
|
if (!filt->impl)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
RARCH_LOG("Loaded softfilter \"%s\".\n", filt->impl->ident);
|
||||||
|
|
||||||
|
if (filt->impl->api_version != SOFTFILTER_API_VERSION)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Softfilter ABI mismatch.\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
// Simple assumptions.
|
// Simple assumptions.
|
||||||
filt->pix_fmt = in_pixel_format;
|
filt->pix_fmt = in_pixel_format;
|
||||||
filt->out_pix_fmt = in_pixel_format;
|
|
||||||
unsigned input_fmt = in_pixel_format == RETRO_PIXEL_FORMAT_XRGB8888 ?
|
unsigned input_fmt = in_pixel_format == RETRO_PIXEL_FORMAT_XRGB8888 ?
|
||||||
SOFTFILTER_FMT_XRGB8888 : SOFTFILTER_FMT_RGB565;
|
SOFTFILTER_FMT_XRGB8888 : SOFTFILTER_FMT_RGB565;
|
||||||
unsigned input_fmts = filt->impl->query_input_formats();
|
unsigned input_fmts = filt->impl->query_input_formats();
|
||||||
if (!(input_fmt & input_fmts))
|
if (!(input_fmt & input_fmts))
|
||||||
|
{
|
||||||
|
RARCH_ERR("Softfilter does not support input format.\n");
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned output_fmts = filt->impl->query_output_formats(input_fmt);
|
unsigned output_fmts = filt->impl->query_output_formats(input_fmt);
|
||||||
if (!(output_fmts & input_fmt))
|
if (output_fmts & input_fmt) // If we have a match of input/output formats, use that.
|
||||||
|
filt->out_pix_fmt = in_pixel_format;
|
||||||
|
else if (output_fmts & SOFTFILTER_FMT_XRGB8888)
|
||||||
|
filt->out_pix_fmt = RETRO_PIXEL_FORMAT_XRGB8888;
|
||||||
|
else if (output_fmts & SOFTFILTER_FMT_RGB565)
|
||||||
|
filt->out_pix_fmt = RETRO_PIXEL_FORMAT_RGB565;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RARCH_ERR("Did not find suitable output format for softfilter.\n");
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
filt->max_width = max_width;
|
filt->max_width = max_width;
|
||||||
filt->max_height = max_height;
|
filt->max_height = max_height;
|
||||||
@ -77,14 +96,26 @@ rarch_softfilter_t *rarch_softfilter_new(const char *filter_path,
|
|||||||
filt->impl_data = filt->impl->create(input_fmt, input_fmt, max_width, max_height,
|
filt->impl_data = filt->impl->create(input_fmt, input_fmt, max_width, max_height,
|
||||||
threads != RARCH_SOFTFILTER_THREADS_AUTO ? threads : 1, cpu_features);
|
threads != RARCH_SOFTFILTER_THREADS_AUTO ? threads : 1, cpu_features);
|
||||||
if (!filt->impl_data)
|
if (!filt->impl_data)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Failed to create softfilter state.\n");
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
threads = filt->impl->query_num_threads(filt->impl_data);
|
threads = filt->impl->query_num_threads(filt->impl_data);
|
||||||
|
if (!threads)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Invalid number of threads.\n");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
filt->packets = (struct softfilter_work_packet*)calloc(threads, sizeof(*filt->packets));
|
filt->packets = (struct softfilter_work_packet*)calloc(threads, sizeof(*filt->packets));
|
||||||
if (!filt->packets)
|
if (!filt->packets)
|
||||||
|
{
|
||||||
|
RARCH_ERR("Failed to allocate softfilter packets.\n");
|
||||||
goto error;
|
goto error;
|
||||||
filt->threads = threads;
|
}
|
||||||
|
|
||||||
|
filt->threads = threads;
|
||||||
return filt;
|
return filt;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
@ -128,7 +159,7 @@ void rarch_softfilter_process(rarch_softfilter_t *filt,
|
|||||||
const void *input, unsigned width, unsigned height, size_t input_stride)
|
const void *input, unsigned width, unsigned height, size_t input_stride)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
filt->impl->process(filt->impl_data, filt->packets,
|
filt->impl->get_work_packets(filt->impl_data, filt->packets,
|
||||||
output, output_stride, input, width, height, input_stride);
|
output, output_stride, input, width, height, input_stride);
|
||||||
|
|
||||||
// TODO: Move to worker threads.
|
// TODO: Move to worker threads.
|
||||||
|
@ -82,11 +82,10 @@ typedef void (*softfilter_query_output_size_t)(void *data,
|
|||||||
unsigned *out_width, unsigned *out_height,
|
unsigned *out_width, unsigned *out_height,
|
||||||
unsigned width, unsigned height);
|
unsigned width, unsigned height);
|
||||||
|
|
||||||
// Process a frame. The filter submits work by filling in the packets array.
|
// First step of processing a frame. The filter submits work by filling in the packets array.
|
||||||
// The number of elements in the array is as returned by query_num_threads.
|
// The number of elements in the array is as returned by query_num_threads.
|
||||||
// The processing itself happens in worker threads after this returns.
|
// The processing itself happens in worker threads after this returns.
|
||||||
// The filter can ignore the process callback.
|
typedef void (*softfilter_get_work_packets_t)(void *data,
|
||||||
typedef void (*softfilter_process_t)(void *data,
|
|
||||||
struct softfilter_work_packet *packets,
|
struct softfilter_work_packet *packets,
|
||||||
void *output, size_t output_stride,
|
void *output, size_t output_stride,
|
||||||
const void *input, unsigned width, unsigned height, size_t input_stride);
|
const void *input, unsigned width, unsigned height, size_t input_stride);
|
||||||
@ -106,7 +105,7 @@ struct softfilter_implementation
|
|||||||
|
|
||||||
softfilter_query_num_threads_t query_num_threads;
|
softfilter_query_num_threads_t query_num_threads;
|
||||||
softfilter_query_output_size_t query_output_size;
|
softfilter_query_output_size_t query_output_size;
|
||||||
softfilter_process_t process;
|
softfilter_get_work_packets_t get_work_packets;
|
||||||
|
|
||||||
const char *ident; // Human readable identifier of implementation.
|
const char *ident; // Human readable identifier of implementation.
|
||||||
unsigned api_version; // Must be SOFTFILTER_API_VERSION
|
unsigned api_version; // Must be SOFTFILTER_API_VERSION
|
||||||
|
Loading…
x
Reference in New Issue
Block a user