diff --git a/gfx/drivers/gl1.c b/gfx/drivers/gl1.c index 93ab3818f9..b4af249385 100644 --- a/gfx/drivers/gl1.c +++ b/gfx/drivers/gl1.c @@ -429,7 +429,7 @@ static void *gl1_gfx_init(const video_info_t *video, return gl1; error: - video_context_driver_destroy(); + video_context_driver_free(); if (gl1) { if (gl1->extensions) diff --git a/gfx/drivers/gl2.c b/gfx/drivers/gl2.c index 00f8b4d4c1..d9083e7ae9 100644 --- a/gfx/drivers/gl2.c +++ b/gfx/drivers/gl2.c @@ -3981,7 +3981,7 @@ static void *gl2_init(const video_info_t *video, return gl; error: - video_context_driver_destroy(); + video_context_driver_free(); gl2_destroy_resources(gl); return NULL; } diff --git a/gfx/drivers/gl3.c b/gfx/drivers/gl3.c index e692c6880c..c62631fdf3 100644 --- a/gfx/drivers/gl3.c +++ b/gfx/drivers/gl3.c @@ -1353,7 +1353,7 @@ static void *gl_core_init(const video_info_t *video, return gl; error: - video_context_driver_destroy(); + video_context_driver_free(); gl_core_destroy_resources(gl); if (gl) free(gl); diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 76e046a2e1..17019006db 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -288,9 +288,9 @@ static void *vg_init(const video_info_t *video, return vg; error: + video_context_driver_free(); if (vg) free(vg); - video_context_driver_destroy(); return NULL; } diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 00c3fcc6d8..e840767484 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -23,6 +23,8 @@ #include "video_driver.h" #include "../ui/ui_companion_driver.h" +#include "../list_special.h" +#include "../retroarch.h" #include "../verbosity.h" typedef struct @@ -235,12 +237,31 @@ bool video_driver_translate_coord_viewport( return true; } -/** - * video_monitor_set_refresh_rate: - * @hz : New refresh rate for monitor. - * - * Sets monitor refresh rate to new value. - **/ +void video_monitor_compute_fps_statistics(uint64_t + frame_time_count) +{ + double avg_fps = 0.0; + double stddev = 0.0; + unsigned samples = 0; + + if (frame_time_count < + (2 * MEASURE_FRAME_TIME_SAMPLES_COUNT)) + { + RARCH_LOG( + "[Video]: Does not have enough samples for monitor refresh rate" + " estimation. Requires to run for at least %u frames.\n", + 2 * MEASURE_FRAME_TIME_SAMPLES_COUNT); + return; + } + + if (video_monitor_fps_statistics(&avg_fps, &stddev, &samples)) + { + RARCH_LOG("[Video]: Average monitor Hz: %.6f Hz. (%.3f %% frame time" + " deviation, based on %u last samples).\n", + avg_fps, 100.0f * stddev, samples); + } +} + void video_monitor_set_refresh_rate(float hz) { char msg[128]; @@ -297,3 +318,128 @@ void video_driver_force_fallback(const char *driver) } exit(1); } + +static bool video_context_driver_get_metrics_null( + void *data, enum display_metric_types type, + float *value) { return false; } + +void video_context_driver_destroy(gfx_ctx_driver_t *ctx_driver) +{ + if (!ctx_driver) + return; + + ctx_driver->init = NULL; + ctx_driver->bind_api = NULL; + ctx_driver->swap_interval = NULL; + ctx_driver->set_video_mode = NULL; + ctx_driver->get_video_size = NULL; + ctx_driver->get_video_output_size = NULL; + ctx_driver->get_video_output_prev = NULL; + ctx_driver->get_video_output_next = NULL; + ctx_driver->get_metrics = + video_context_driver_get_metrics_null; + ctx_driver->translate_aspect = NULL; + ctx_driver->update_window_title = NULL; + ctx_driver->check_window = NULL; + ctx_driver->set_resize = NULL; + ctx_driver->suppress_screensaver = NULL; + ctx_driver->swap_buffers = NULL; + ctx_driver->input_driver = NULL; + ctx_driver->get_proc_address = NULL; + ctx_driver->image_buffer_init = NULL; + ctx_driver->image_buffer_write = NULL; + ctx_driver->show_mouse = NULL; + ctx_driver->ident = NULL; + ctx_driver->get_flags = NULL; + ctx_driver->set_flags = NULL; + ctx_driver->bind_hw_render = NULL; + ctx_driver->get_context_data = NULL; + ctx_driver->make_current = NULL; +} + +/** + * config_get_video_driver_options: + * + * Get an enumerated list of all video driver names, separated by '|'. + * + * Returns: string listing of all video driver names, separated by '|'. + **/ +const char* config_get_video_driver_options(void) +{ + return char_list_new_special(STRING_LIST_VIDEO_DRIVERS, NULL); +} + +void video_driver_pixel_converter_free( + video_pixel_scaler_t *scalr) +{ + if (!scalr) + return; + + if (scalr->scaler) + { + scaler_ctx_gen_reset(scalr->scaler); + free(scalr->scaler); + } + if (scalr->scaler_out) + free(scalr->scaler_out); + + scalr->scaler = NULL; + scalr->scaler_out = NULL; + + free(scalr); +} + +video_pixel_scaler_t *video_driver_pixel_converter_init( + const enum retro_pixel_format video_driver_pix_fmt, + struct retro_hw_render_callback *hwr, + unsigned size) +{ + void *scalr_out = NULL; + video_pixel_scaler_t *scalr = NULL; + struct scaler_ctx *scalr_ctx = NULL; + + /* If pixel format is not 0RGB1555, we don't need to do + * any internal pixel conversion. */ + if (video_driver_pix_fmt != RETRO_PIXEL_FORMAT_0RGB1555) + return NULL; + + /* No need to perform pixel conversion for HW rendering contexts. */ + if (hwr && hwr->context_type != RETRO_HW_CONTEXT_NONE) + return NULL; + + RARCH_WARN("[Video]: 0RGB1555 pixel format is deprecated," + " and will be slower. For 15/16-bit, RGB565" + " format is preferred.\n"); + + if (!(scalr = (video_pixel_scaler_t*)malloc(sizeof(*scalr)))) + goto error; + + scalr->scaler = NULL; + scalr->scaler_out = NULL; + + if (!(scalr_ctx = (struct scaler_ctx*)calloc(1, sizeof(*scalr_ctx)))) + goto error; + + scalr->scaler = scalr_ctx; + scalr->scaler->scaler_type = SCALER_TYPE_POINT; + scalr->scaler->in_fmt = SCALER_FMT_0RGB1555; + /* TODO/FIXME: Pick either ARGB8888 or RGB565 depending on driver. */ + scalr->scaler->out_fmt = SCALER_FMT_RGB565; + + if (!scaler_ctx_gen_filter(scalr_ctx)) + goto error; + + if (!(scalr_out = calloc(sizeof(uint16_t), size * size))) + goto error; + + scalr->scaler_out = scalr_out; + + return scalr; + +error: + video_driver_pixel_converter_free(scalr); +#ifdef HAVE_VIDEO_FILTER + video_driver_filter_free(); +#endif + return NULL; +} diff --git a/gfx/video_driver.h b/gfx/video_driver.h index 129c21d229..669e2e41a8 100644 --- a/gfx/video_driver.h +++ b/gfx/video_driver.h @@ -26,6 +26,9 @@ #include "../config.h" #endif +#include +#include + #include "../input/input_driver.h" #include "../input/input_types.h" @@ -317,6 +320,12 @@ typedef struct video_shader_ctx_texture unsigned id; } video_shader_ctx_texture_t; +typedef struct video_pixel_scaler +{ + struct scaler_ctx *scaler; + void *scaler_out; +} video_pixel_scaler_t; + typedef void (*gfx_ctx_proc_t)(void); typedef struct video_info @@ -984,6 +993,14 @@ struct video_viewport *video_viewport_get_custom(void); **/ void video_monitor_set_refresh_rate(float hz); +/** + * video_monitor_compute_fps_statistics: + * + * Computes monitor FPS statistics. + **/ +void video_monitor_compute_fps_statistics(uint64_t + frame_time_count); + /** * video_monitor_fps_statistics * @refresh_rate : Monitor refresh rate. @@ -1085,8 +1102,6 @@ const gfx_ctx_driver_t *video_context_driver_init_first( bool video_context_driver_set(const gfx_ctx_driver_t *data); -void video_context_driver_destroy(void); - bool video_context_driver_get_ident(gfx_ctx_ident_t *ident); bool video_context_driver_get_refresh_rate(float *refresh_rate); @@ -1095,6 +1110,8 @@ bool video_context_driver_set_flags(gfx_ctx_flags_t *flags); bool video_context_driver_get_metrics(gfx_ctx_metrics_t *metrics); +void video_context_driver_destroy(gfx_ctx_driver_t *ctx_driver); + enum gfx_ctx_api video_context_driver_get_api(void); void video_context_driver_free(void); @@ -1140,6 +1157,18 @@ const char *hw_render_context_name( video_driver_t *hw_render_context_driver( enum retro_hw_context_type type, int major, int minor); +void video_driver_pixel_converter_free( + video_pixel_scaler_t *scalr); + +video_pixel_scaler_t *video_driver_pixel_converter_init( + const enum retro_pixel_format video_driver_pix_fmt, + struct retro_hw_render_callback *hwr, + unsigned size); + +#ifdef HAVE_VIDEO_FILTER +void video_driver_filter_free(void); +#endif + extern video_driver_t video_gl_core; extern video_driver_t video_gl2; extern video_driver_t video_gl1; diff --git a/retroarch.c b/retroarch.c index 640274eb6a..f9296129c1 100644 --- a/retroarch.c +++ b/retroarch.c @@ -20272,18 +20272,6 @@ bool video_driver_started_fullscreen(void) static bool get_metrics_null(void *data, enum display_metric_types type, float *value) { return false; } -/** - * config_get_video_driver_options: - * - * Get an enumerated list of all video driver names, separated by '|'. - * - * Returns: string listing of all video driver names, separated by '|'. - **/ -const char* config_get_video_driver_options(void) -{ - return char_list_new_special(STRING_LIST_VIDEO_DRIVERS, NULL); -} - bool video_driver_is_threaded(void) { #ifdef HAVE_THREADS @@ -20352,46 +20340,6 @@ bool video_context_driver_set(const gfx_ctx_driver_t *data) return true; } -static void video_context_driver_destroy_internal( - gfx_ctx_driver_t *ctx_driver) -{ - if (!ctx_driver) - return; - - ctx_driver->init = NULL; - ctx_driver->bind_api = NULL; - ctx_driver->swap_interval = NULL; - ctx_driver->set_video_mode = NULL; - ctx_driver->get_video_size = NULL; - ctx_driver->get_video_output_size = NULL; - ctx_driver->get_video_output_prev = NULL; - ctx_driver->get_video_output_next = NULL; - ctx_driver->get_metrics = get_metrics_null; - ctx_driver->translate_aspect = NULL; - ctx_driver->update_window_title = NULL; - ctx_driver->check_window = NULL; - ctx_driver->set_resize = NULL; - ctx_driver->suppress_screensaver = NULL; - ctx_driver->swap_buffers = NULL; - ctx_driver->input_driver = NULL; - ctx_driver->get_proc_address = NULL; - ctx_driver->image_buffer_init = NULL; - ctx_driver->image_buffer_write = NULL; - ctx_driver->show_mouse = NULL; - ctx_driver->ident = NULL; - ctx_driver->get_flags = NULL; - ctx_driver->set_flags = NULL; - ctx_driver->bind_hw_render = NULL; - ctx_driver->get_context_data = NULL; - ctx_driver->make_current = NULL; -} - -void video_context_driver_destroy(void) -{ - struct rarch_state *p_rarch = &rarch_st; - video_context_driver_destroy_internal(&p_rarch->current_video_context); -} - /** * video_driver_get_current_framebuffer: * @@ -20421,7 +20369,7 @@ static retro_proc_address_t video_driver_get_proc_address(const char *sym) } #ifdef HAVE_VIDEO_FILTER -static void video_driver_filter_free(void) +void video_driver_filter_free(void) { struct rarch_state *p_rarch = &rarch_st; @@ -20443,9 +20391,7 @@ static void video_driver_filter_free(void) p_rarch->video_driver_state_out_bpp = 0; p_rarch->video_driver_state_out_rgb32 = false; } -#endif -#ifdef HAVE_VIDEO_FILTER static void video_driver_init_filter(enum retro_pixel_format colfmt_int, settings_t *settings) { @@ -20570,56 +20516,6 @@ static void video_driver_init_input( input_driver_st->current_data = new_data; } -/** - * video_driver_monitor_compute_fps_statistics: - * - * Computes monitor FPS statistics. - **/ -static void video_driver_monitor_compute_fps_statistics(uint64_t - frame_time_count) -{ - double avg_fps = 0.0; - double stddev = 0.0; - unsigned samples = 0; - - if (frame_time_count < - (2 * MEASURE_FRAME_TIME_SAMPLES_COUNT)) - { - RARCH_LOG( - "[Video]: Does not have enough samples for monitor refresh rate" - " estimation. Requires to run for at least %u frames.\n", - 2 * MEASURE_FRAME_TIME_SAMPLES_COUNT); - return; - } - - if (video_monitor_fps_statistics(&avg_fps, &stddev, &samples)) - { - RARCH_LOG("[Video]: Average monitor Hz: %.6f Hz. (%.3f %% frame time" - " deviation, based on %u last samples).\n", - avg_fps, 100.0f * stddev, samples); - } -} - -static void video_driver_pixel_converter_free( - video_pixel_scaler_t *scalr) -{ - if (!scalr) - return; - - if (scalr->scaler) - { - scaler_ctx_gen_reset(scalr->scaler); - free(scalr->scaler); - } - if (scalr->scaler_out) - free(scalr->scaler_out); - - scalr->scaler = NULL; - scalr->scaler_out = NULL; - - free(scalr); -} - static void video_driver_free_hw_context(struct rarch_state *p_rarch) { VIDEO_DRIVER_CONTEXT_LOCK(); @@ -20695,62 +20591,7 @@ static void video_driver_free_internal(struct rarch_state *p_rarch) return; #endif - video_driver_monitor_compute_fps_statistics(p_rarch->video_driver_frame_time_count); -} - -static video_pixel_scaler_t *video_driver_pixel_converter_init( - const enum retro_pixel_format video_driver_pix_fmt, - struct retro_hw_render_callback *hwr, - unsigned size) -{ - void *scalr_out = NULL; - video_pixel_scaler_t *scalr = NULL; - struct scaler_ctx *scalr_ctx = NULL; - - /* If pixel format is not 0RGB1555, we don't need to do - * any internal pixel conversion. */ - if (video_driver_pix_fmt != RETRO_PIXEL_FORMAT_0RGB1555) - return NULL; - - /* No need to perform pixel conversion for HW rendering contexts. */ - if (hwr && hwr->context_type != RETRO_HW_CONTEXT_NONE) - return NULL; - - RARCH_WARN("[Video]: 0RGB1555 pixel format is deprecated," - " and will be slower. For 15/16-bit, RGB565" - " format is preferred.\n"); - - if (!(scalr = (video_pixel_scaler_t*)malloc(sizeof(*scalr)))) - goto error; - - scalr->scaler = NULL; - scalr->scaler_out = NULL; - - if (!(scalr_ctx = (struct scaler_ctx*)calloc(1, sizeof(*scalr_ctx)))) - goto error; - - scalr->scaler = scalr_ctx; - scalr->scaler->scaler_type = SCALER_TYPE_POINT; - scalr->scaler->in_fmt = SCALER_FMT_0RGB1555; - /* TODO/FIXME: Pick either ARGB8888 or RGB565 depending on driver. */ - scalr->scaler->out_fmt = SCALER_FMT_RGB565; - - if (!scaler_ctx_gen_filter(scalr_ctx)) - goto error; - - if (!(scalr_out = calloc(sizeof(uint16_t), size * size))) - goto error; - - scalr->scaler_out = scalr_out; - - return scalr; - -error: - video_driver_pixel_converter_free(scalr); -#ifdef HAVE_VIDEO_FILTER - video_driver_filter_free(); -#endif - return NULL; + video_monitor_compute_fps_statistics(p_rarch->video_driver_frame_time_count); } static void video_driver_set_viewport_config( @@ -23159,7 +23000,7 @@ const gfx_ctx_driver_t *video_context_driver_init_first(void *data, void video_context_driver_free(void) { struct rarch_state *p_rarch = &rarch_st; - video_context_driver_destroy_internal(&p_rarch->current_video_context); + video_context_driver_destroy(&p_rarch->current_video_context); p_rarch->video_context_data = NULL; } diff --git a/retroarch.h b/retroarch.h index 30401a1457..bd8aacdfbb 100644 --- a/retroarch.h +++ b/retroarch.h @@ -52,6 +52,8 @@ RETRO_BEGIN_DECLS +#define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024) + #define RETRO_ENVIRONMENT_RETROARCH_START_BLOCK 0x800000 #define RETRO_ENVIRONMENT_SET_SAVE_STATE_IN_BACKGROUND (2 | RETRO_ENVIRONMENT_RETROARCH_START_BLOCK) diff --git a/retroarch_data.h b/retroarch_data.h index 5f0288cfa3..e5df0d5e7b 100644 --- a/retroarch_data.h +++ b/retroarch_data.h @@ -73,8 +73,6 @@ #define BSV_MOVIE_IS_PLAYBACK_OFF() (p_rarch->bsv_movie_state_handle && !p_rarch->bsv_movie_state.movie_playback) #endif -#define MEASURE_FRAME_TIME_SAMPLES_COUNT (2 * 1024) - #define TIME_TO_FPS(last_time, new_time, frames) ((1000000.0f * (frames)) / ((new_time) - (last_time))) #define AUDIO_BUFFER_FREE_SAMPLES_COUNT (8 * 1024) @@ -930,12 +928,6 @@ enum input_game_focus_cmd_type GAME_FOCUS_CMD_REAPPLY }; -typedef struct video_pixel_scaler -{ - struct scaler_ctx *scaler; - void *scaler_out; -} video_pixel_scaler_t; - typedef void *(*constructor_t)(void); typedef void (*destructor_t )(void*); diff --git a/ui/drivers/ui_win32.c b/ui/drivers/ui_win32.c index 29771e85ba..6c239f6800 100644 --- a/ui/drivers/ui_win32.c +++ b/ui/drivers/ui_win32.c @@ -228,7 +228,7 @@ static enum ui_msg_window_response ui_msg_window_win32_warning( MessageBoxA(NULL, (LPCSTR)state->text, (LPCSTR)state->title, flags)); } -static ui_msg_window_t ui_msg_window_win32 = { +ui_msg_window_t ui_msg_window_win32 = { ui_msg_window_win32_error, ui_msg_window_win32_information, ui_msg_window_win32_question, diff --git a/ui/ui_companion_driver.h b/ui/ui_companion_driver.h index 442518f044..287839e79e 100644 --- a/ui/ui_companion_driver.h +++ b/ui/ui_companion_driver.h @@ -149,6 +149,8 @@ extern ui_companion_driver_t ui_companion_cocoatouch; extern ui_companion_driver_t ui_companion_qt; extern ui_companion_driver_t ui_companion_win32; +extern ui_msg_window_t ui_msg_window_win32; + bool ui_companion_is_on_foreground(void); void ui_companion_set_foreground(unsigned enable);