Skip to content

Commit

Permalink
Move filter state code to video_state and out of global
Browse files Browse the repository at this point in the history
  • Loading branch information
inactive123 committed May 20, 2015
1 parent d8622e0 commit 197820c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 74 deletions.
107 changes: 84 additions & 23 deletions gfx/video_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ typedef struct video_driver_state
unsigned video_width;
unsigned video_height;
float aspect_ratio;

struct
{
rarch_softfilter_t *filter;

void *buffer;
unsigned scale;
unsigned out_bpp;
bool out_rgb32;
} filter;
} video_driver_state_t;

static video_driver_state_t video_state;
Expand Down Expand Up @@ -334,18 +344,15 @@ bool video_driver_set_shader(enum rarch_shader_type type,

static void deinit_video_filter(void)
{
global_t *global = global_get_ptr();

rarch_softfilter_free(global->filter.filter);
free(global->filter.buffer);
memset(&global->filter, 0, sizeof(global->filter));
rarch_softfilter_free(video_state.filter.filter);
free(video_state.filter.buffer);
memset(&video_state.filter, 0, sizeof(video_state.filter));
}

static void init_video_filter(enum retro_pixel_format colfmt)
{
unsigned width, height, pow2_x, pow2_y, maxsize;
struct retro_game_geometry *geom = NULL;
global_t *global = global_get_ptr();
settings_t *settings = config_get_ptr();
struct retro_system_av_info *av_info =
video_viewport_get_system_av_info();
Expand All @@ -369,33 +376,32 @@ static void init_video_filter(enum retro_pixel_format colfmt)
width = geom->max_width;
height = geom->max_height;

global->filter.filter = rarch_softfilter_new(
video_state.filter.filter = rarch_softfilter_new(
settings->video.softfilter_plugin,
RARCH_SOFTFILTER_THREADS_AUTO, colfmt, width, height);

if (!global->filter.filter)
if (!video_state.filter.filter)
{
RARCH_ERR("Failed to load filter.\n");
return;
}

rarch_softfilter_get_max_output_size(global->filter.filter,
rarch_softfilter_get_max_output_size(video_state.filter.filter,
&width, &height);

pow2_x = next_pow2(width);
pow2_y = next_pow2(height);
maxsize = max(pow2_x, pow2_y);
global->filter.scale = maxsize / RARCH_SCALE_BASE;
pow2_x = next_pow2(width);
pow2_y = next_pow2(height);
maxsize = max(pow2_x, pow2_y);
video_state.filter.scale = maxsize / RARCH_SCALE_BASE;
video_state.filter.out_rgb32 = rarch_softfilter_get_output_format(
video_state.filter.filter) == RETRO_PIXEL_FORMAT_XRGB8888;

global->filter.out_rgb32 = rarch_softfilter_get_output_format(
global->filter.filter) == RETRO_PIXEL_FORMAT_XRGB8888;

global->filter.out_bpp = global->filter.out_rgb32 ?
video_state.filter.out_bpp = video_state.filter.out_rgb32 ?
sizeof(uint32_t) : sizeof(uint16_t);

/* TODO: Aligned output. */
global->filter.buffer = malloc(width * height * global->filter.out_bpp);
if (!global->filter.buffer)
video_state.filter.buffer = malloc(width * height * video_state.filter.out_bpp);
if (!video_state.filter.buffer)
goto error;

return;
Expand Down Expand Up @@ -486,8 +492,8 @@ void init_video(void)
scale = next_pow2(max_dim) / RARCH_SCALE_BASE;
scale = max(scale, 1);

if (global->filter.filter)
scale = global->filter.scale;
if (video_state.filter.filter)
scale = video_state.filter.scale;

/* Update core-dependent aspect ratio values. */
video_viewport_set_square_pixel(geom->base_width, geom->base_height);
Expand Down Expand Up @@ -553,8 +559,8 @@ void init_video(void)
#endif
video.smooth = settings->video.smooth;
video.input_scale = scale;
video.rgb32 = global->filter.filter ?
global->filter.out_rgb32 :
video.rgb32 = video_state.filter.filter ?
video_state.filter.out_rgb32 :
(global->system.pix_fmt == RETRO_PIXEL_FORMAT_XRGB8888);

tmp = (const input_driver_t*)driver->input;
Expand Down Expand Up @@ -1120,3 +1126,58 @@ void video_driver_unset_callback(void)
if (hw_render)
hw_render = NULL;
}

bool video_driver_frame_filter(const void *data,
unsigned width, unsigned height,
size_t pitch,
unsigned *output_width, unsigned *output_height,
unsigned *output_pitch)
{
settings_t *settings = config_get_ptr();

RARCH_PERFORMANCE_INIT(softfilter_process);

if (!video_state.filter.filter)
return false;
if (!data)
return false;

rarch_softfilter_get_output_size(video_state.filter.filter,
output_width, output_height, width, height);

*output_pitch = (*output_width) * video_state.filter.out_bpp;

RARCH_PERFORMANCE_START(softfilter_process);
rarch_softfilter_process(video_state.filter.filter,
video_state.filter.buffer, *output_pitch,
data, width, height, pitch);
RARCH_PERFORMANCE_STOP(softfilter_process);

if (settings->video.post_filter_record)
recording_dump_frame(video_state.filter.buffer,
*output_width, *output_height, *output_pitch);

return true;
}

bool video_driver_frame_filter_is_32bit(void)
{
return video_state.filter.out_rgb32;
}

bool video_driver_frame_filter_alive(void)
{
if (video_state.filter.filter)
return true;
return false;
}

rarch_softfilter_t *video_driver_frame_filter_get_ptr(void)
{
return video_state.filter.filter;
}

void *video_driver_frame_filter_get_buf_ptr(void)
{
return video_state.filter.buffer;
}
14 changes: 14 additions & 0 deletions gfx/video_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,20 @@ struct retro_hw_render_callback *video_driver_callback(void);

void video_driver_unset_callback(void);

bool video_driver_frame_filter(const void *data,
unsigned width, unsigned height,
size_t pitch,
unsigned *output_width, unsigned *output_height,
unsigned *output_pitch);

bool video_driver_frame_filter_alive(void);

bool video_driver_frame_filter_is_32bit(void);

rarch_softfilter_t *video_driver_frame_filter_get_ptr(void);

void *video_driver_frame_filter_get_buf_ptr(void);

#ifdef __cplusplus
}
#endif
Expand Down
40 changes: 3 additions & 37 deletions libretro_version_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,6 @@ static bool video_frame_scale(const void *data,
return true;
}

static bool video_frame_filter(const void *data,
unsigned width, unsigned height,
size_t pitch,
unsigned *output_width, unsigned *output_height,
unsigned *output_pitch)
{
settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();

RARCH_PERFORMANCE_INIT(softfilter_process);

if (!global->filter.filter)
return false;
if (!data)
return false;

rarch_softfilter_get_output_size(global->filter.filter,
output_width, output_height, width, height);

*output_pitch = (*output_width) * global->filter.out_bpp;

RARCH_PERFORMANCE_START(softfilter_process);
rarch_softfilter_process(global->filter.filter,
global->filter.buffer, *output_pitch,
data, width, height, pitch);
RARCH_PERFORMANCE_STOP(softfilter_process);

if (settings->video.post_filter_record)
recording_dump_frame(global->filter.buffer,
*output_width, *output_height, *output_pitch);

return true;
}

/**
* video_frame:
* @data : pointer to data of the video frame.
Expand Down Expand Up @@ -144,7 +110,7 @@ static void video_frame(const void *data, unsigned width,
* but we really need to do processing before blocking on VSync
* for best possible scheduling.
*/
if ((!global->filter.filter
if ((!video_driver_frame_filter_alive()
|| !settings->video.post_filter_record || !data
|| global->record.gpu_buffer)
)
Expand All @@ -154,10 +120,10 @@ static void video_frame(const void *data, unsigned width,

driver->current_msg = msg;

if (video_frame_filter(data, width, height, pitch,
if (video_driver_frame_filter(data, width, height, pitch,
&output_width, &output_height, &output_pitch))
{
data = global->filter.buffer;
data = video_driver_frame_filter_get_buf_ptr();
width = output_width;
height = output_height;
pitch = output_pitch;
Expand Down
7 changes: 4 additions & 3 deletions record/record_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,17 +388,18 @@ bool recording_init(void)
else
params.aspect_ratio = (float)params.out_width / params.out_height;

if (settings->video.post_filter_record && global->filter.filter)
if (settings->video.post_filter_record && video_driver_frame_filter_alive())
{
unsigned max_width = 0;
unsigned max_height = 0;

if (global->filter.out_rgb32)
if (video_driver_frame_filter_is_32bit())
params.pix_fmt = FFEMU_PIX_ARGB8888;
else
params.pix_fmt = FFEMU_PIX_RGB565;

rarch_softfilter_get_max_output_size(global->filter.filter,
rarch_softfilter_get_max_output_size(
video_driver_frame_filter_get_ptr(),
&max_width, &max_height);
params.fb_width = next_pow2(max_width);
params.fb_height = next_pow2(max_height);
Expand Down
11 changes: 0 additions & 11 deletions runloop.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,6 @@ typedef struct global
unsigned num_ports;
} system;

struct
{
rarch_softfilter_t *filter;

void *buffer;
unsigned scale;
unsigned out_bpp;
bool out_rgb32;
} filter;

#ifdef HAVE_MENU
struct
{
Expand All @@ -201,7 +191,6 @@ typedef struct global
} menu;
#endif


bool exec;

struct
Expand Down

0 comments on commit 197820c

Please sign in to comment.