diff --git a/audio/audio_driver.c b/audio/audio_driver.c index b31cdffd9f..95a5c0214e 100644 --- a/audio/audio_driver.c +++ b/audio/audio_driver.c @@ -824,10 +824,11 @@ void audio_driver_frame_is_reverse(void) void audio_monitor_adjust_system_rates(void) { float timing_skew; - global_t *global = global_get_ptr(); - const struct retro_system_timing *info = - (const struct retro_system_timing*)&global->system.av_info.timing; settings_t *settings = config_get_ptr(); + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); + const struct retro_system_timing *info = + av_info ? (const struct retro_system_timing*)&av_info->timing : NULL; if (info->sample_rate <= 0.0) return; diff --git a/driver.c b/driver.c index e0ef9a2e5a..34d61f2402 100644 --- a/driver.c +++ b/driver.c @@ -309,10 +309,10 @@ void driver_set_nonblock_state(bool enable) **/ bool driver_update_system_av_info(const struct retro_system_av_info *info) { - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); driver_t *driver = driver_get_ptr(); - global->system.av_info = *info; + memcpy(av_info, info, sizeof(*av_info)); event_command(EVENT_CMD_REINIT); /* Cannot continue recording with different parameters. diff --git a/dynamic.c b/dynamic.c index 72772af101..8f91362519 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1102,9 +1102,11 @@ bool rarch_environment_cb(unsigned cmd, void *data) case RETRO_ENVIRONMENT_SET_GEOMETRY: { + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); const struct retro_game_geometry *in_geom = (const struct retro_game_geometry*)data; - struct retro_game_geometry *geom = &global->system.av_info.geometry; + struct retro_game_geometry *geom = av_info ? + (struct retro_game_geometry*)&av_info->geometry : NULL; RARCH_LOG("Environ SET_GEOMETRY.\n"); diff --git a/gfx/d3d/d3d.cpp b/gfx/d3d/d3d.cpp index f55cf2b378..8f7a3dd5ee 100644 --- a/gfx/d3d/d3d.cpp +++ b/gfx/d3d/d3d.cpp @@ -518,14 +518,15 @@ static bool d3d_has_windowed(void *data) static void d3d_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { d3d_video_t *d3d = (d3d_video_t*)data; - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info =- + video_viewport_get_system_av_info(); switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: video_viewport_set_square_pixel( - global->system.av_info.geometry.base_width, - global->system.av_info.geometry.base_height); + av_info->geometry.base_width, + av_info->geometry.base_height); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/exynos_gfx.c b/gfx/drivers/exynos_gfx.c index 08e9a17aab..29b6249ea1 100644 --- a/gfx/drivers/exynos_gfx.c +++ b/gfx/drivers/exynos_gfx.c @@ -1540,14 +1540,15 @@ static void exynos_gfx_viewport_info(void *data, struct video_viewport *vp) static void exynos_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { struct exynos_video *vid = (struct exynos_video*)data; - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: video_viewport_set_square_pixel( - global->system.av_info.geometry.base_width, - global->system.av_info.geometry.base_height); + av_info->geometry.base_width, + av_info->geometry.base_height); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 926be3be85..f76186eff8 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -805,7 +805,7 @@ static void gl_set_viewport(void *data, unsigned viewport_width, #if defined(HAVE_MENU) if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { - const struct video_viewport *custom = &global->console.screen.viewports.custom_vp; + const struct video_viewport *custom = video_viewport_get_custom(); /* GL has bottom-left origin viewport. */ x = custom->x; @@ -3100,14 +3100,14 @@ static retro_proc_address_t gl_get_proc_address(void *data, const char *sym) static void gl_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { gl_t *gl = (gl_t*)data; - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); switch (aspect_ratio_idx) { case ASPECT_RATIO_SQUARE: video_viewport_set_square_pixel( - global->system.av_info.geometry.base_width, - global->system.av_info.geometry.base_height); + av_info->geometry.base_width, + av_info->geometry.base_height); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 8a5126158d..d98c85d3b9 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -435,13 +435,13 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) { driver_t *driver = driver_get_ptr(); - global_t *global = global_get_ptr(); gx_video_t *gx = (gx_video_t*)driver->video_data; + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); if (aspect_ratio_idx == ASPECT_RATIO_SQUARE) video_viewport_set_square_pixel( - global->system.av_info.geometry.base_width, - global->system.av_info.geometry.base_height); + av_info->geometry.base_width, + av_info->geometry.base_height); else if (aspect_ratio_idx == ASPECT_RATIO_CORE) video_viewport_set_core(); else if (aspect_ratio_idx == ASPECT_RATIO_CONFIG) diff --git a/gfx/drivers/omap_gfx.c b/gfx/drivers/omap_gfx.c index 79e7d2504c..46997771f3 100644 --- a/gfx/drivers/omap_gfx.c +++ b/gfx/drivers/omap_gfx.c @@ -391,6 +391,7 @@ static int omapfb_alloc_mem(omapfb_data_t *pdata) unsigned mem_size; void* mem = NULL; const struct retro_game_geometry *geom = NULL; + struct retro_system_av_info *av_info = NULL; global_t *global = global_get_ptr(); assert(pdata->current_state == NULL); @@ -423,7 +424,10 @@ static int omapfb_alloc_mem(omapfb_data_t *pdata) } } - geom = &global->system.av_info.geometry; + av_info = video_viewport_get_system_av_info(); + + if (av_info) + geom = &av_info->geometry; mem_size = geom->max_width * geom->max_height * pdata->bpp * pdata->num_pages; diff --git a/gfx/drivers/psp1_gfx.c b/gfx/drivers/psp1_gfx.c index c582edb77e..8aa8e44251 100644 --- a/gfx/drivers/psp1_gfx.c +++ b/gfx/drivers/psp1_gfx.c @@ -796,14 +796,14 @@ static void psp_set_filtering(void *data, unsigned index, bool smooth) static void psp_set_aspect_ratio(void *data, unsigned aspectratio_index) { psp1_video_t *psp = (psp1_video_t*)data; - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: video_viewport_set_square_pixel( - global->system.av_info.geometry.base_width, - global->system.av_info.geometry.base_height); + av_info->geometry.base_width, + av_info->geometry.base_height); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/sdl2_gfx.c b/gfx/drivers/sdl2_gfx.c index 5f82ca49b5..75a17f00ed 100644 --- a/gfx/drivers/sdl2_gfx.c +++ b/gfx/drivers/sdl2_gfx.c @@ -639,13 +639,13 @@ void sdl2_poke_set_filtering(void *data, unsigned index, bool smooth) static void sdl2_poke_set_aspect_ratio(void *data, unsigned aspectratio_index) { sdl2_video_t *vid = (sdl2_video_t*)data; - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: - video_viewport_set_square_pixel(global->system.av_info.geometry.base_width, - global->system.av_info.geometry.base_height); + video_viewport_set_square_pixel(av_info->geometry.base_width, + av_info->geometry.base_height); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/sdl_gfx.c b/gfx/drivers/sdl_gfx.c index 0ff1be41c5..80b02ffca2 100644 --- a/gfx/drivers/sdl_gfx.c +++ b/gfx/drivers/sdl_gfx.c @@ -445,14 +445,15 @@ static void sdl_set_filtering(void *data, unsigned index, bool smooth) static void sdl_set_aspect_ratio(void *data, unsigned aspectratio_index) { sdl_video_t *vid = (sdl_video_t*)data; - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); switch (aspectratio_index) { case ASPECT_RATIO_SQUARE: video_viewport_set_square_pixel( - global->system.av_info.geometry.base_width, - global->system.av_info.geometry.base_height); + av_info->geometry.base_width, + av_info->geometry.base_height); break; case ASPECT_RATIO_CORE: diff --git a/gfx/drivers/xvideo.c b/gfx/drivers/xvideo.c index 4982fc9dca..cc1155f485 100644 --- a/gfx/drivers/xvideo.c +++ b/gfx/drivers/xvideo.c @@ -419,10 +419,11 @@ static void *xv_init(const video_info_t *video, XVisualInfo *visualinfo = NULL; XVisualInfo visualtemplate = {0}; XvAdaptorInfo *adaptor_info = NULL; - const struct retro_game_geometry *geom = NULL; driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); + const struct retro_game_geometry *geom = NULL; + struct retro_system_av_info *av_info = NULL; xv_t *xv = (xv_t*)calloc(1, sizeof(*xv)); if (!xv) return NULL; @@ -430,7 +431,11 @@ static void *xv_init(const video_info_t *video, XInitThreads(); xv->display = XOpenDisplay(NULL); - geom = &global->system.av_info.geometry; + + av_info = video_viewport_get_system_av_info(); + + if (av_info) + geom = &av_info->geometry; if (!XShmQueryExtension(xv->display)) { diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 49495de7be..d89b682540 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -350,6 +350,8 @@ static void init_video_filter(enum retro_pixel_format colfmt) 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(); deinit_video_filter(); @@ -366,7 +368,7 @@ static void init_video_filter(enum retro_pixel_format colfmt) return; } - geom = (struct retro_game_geometry*)&global->system.av_info.geometry; + geom = av_info ? (struct retro_game_geometry*)&av_info->geometry : NULL; width = geom->max_width; height = geom->max_height; @@ -474,11 +476,14 @@ void init_video(void) driver_t *driver = driver_get_ptr(); 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(); init_video_filter(global->system.pix_fmt); event_command(EVENT_CMD_SHADER_DIR_INIT); - geom = (const struct retro_game_geometry*)&global->system.av_info.geometry; + if (av_info) + geom = (const struct retro_game_geometry*)&av_info->geometry; max_dim = max(geom->max_width, geom->max_height); scale = next_pow2(max_dim) / RARCH_SCALE_BASE; scale = max(scale, 1); @@ -876,12 +881,17 @@ void video_driver_set_size_height(unsigned height) void video_monitor_adjust_system_rates(void) { float timing_skew; - global_t *global = global_get_ptr(); - const struct retro_system_timing *info = - (const struct retro_system_timing*)&global->system.av_info.timing; + const struct retro_system_timing *info = NULL; + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); settings_t *settings = config_get_ptr(); + global_t *global = global_get_ptr(); - global->system.force_nonblock = false; + if (global) + global->system.force_nonblock = false; + + if (av_info) + info = (const struct retro_system_timing*)&av_info->timing; if (info->fps <= 0.0) return; diff --git a/gfx/video_viewport.c b/gfx/video_viewport.c index cae4cb6fbf..3ac9cd0b8a 100644 --- a/gfx/video_viewport.c +++ b/gfx/video_viewport.c @@ -51,6 +51,8 @@ char rotation_lut[4][32] = "270 deg" }; +static struct retro_system_av_info video_viewport_av_info; + /** * video_viewport_set_square_pixel: * @width : Width. @@ -90,8 +92,9 @@ void video_viewport_set_square_pixel(unsigned width, unsigned height) **/ void video_viewport_set_core(void) { - global_t *global = global_get_ptr(); - struct retro_game_geometry *geom = &global->system.av_info.geometry; + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); + struct retro_game_geometry *geom = &av_info->geometry; if (!geom || geom->base_width <= 0.0f || geom->base_height <= 0.0f) return; @@ -112,11 +115,11 @@ void video_viewport_set_core(void) void video_viewport_set_config(void) { settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); if (settings->video.aspect_ratio < 0.0f) { - struct retro_game_geometry *geom = &global->system.av_info.geometry; + struct retro_game_geometry *geom = &av_info->geometry; if (geom && geom->aspect_ratio > 0.0f && settings->video.aspect_ratio_auto) aspectratio_lut[ASPECT_RATIO_CONFIG].value = geom->aspect_ratio; @@ -156,15 +159,13 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp, { int padding_x = 0, padding_y = 0; settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); if (!vp) return; if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM) { - const struct video_viewport *custom = - &global->console.screen.viewports.custom_vp; + struct video_viewport *custom = video_viewport_get_custom(); if (custom) { @@ -179,7 +180,8 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp, unsigned base_width; /* Use system reported sizes as these define the * geometry for the "normal" case. */ - unsigned base_height = global->system.av_info.geometry.base_height; + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); + unsigned base_height = av_info ? av_info->geometry.base_height : 0; if (base_height == 0) base_height = 1; @@ -219,3 +221,16 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp, vp->x = padding_x / 2; vp->y = padding_y / 2; } + +struct retro_system_av_info *video_viewport_get_system_av_info(void) +{ + return (struct retro_system_av_info*)&video_viewport_av_info; +} + +struct video_viewport *video_viewport_get_custom(void) +{ + global_t *global = global_get_ptr(); + if (!global) + return NULL; + return &global->console.screen.viewports.custom_vp; +} diff --git a/gfx/video_viewport.h b/gfx/video_viewport.h index bbdc9b5b52..2b3b26bb39 100644 --- a/gfx/video_viewport.h +++ b/gfx/video_viewport.h @@ -137,6 +137,10 @@ void video_viewport_get_scaled_integer(struct video_viewport *vp, unsigned width, unsigned height, float aspect_ratio, bool keep_aspect); +struct retro_system_av_info *video_viewport_get_system_av_info(void); + +struct video_viewport *video_viewport_get_custom(void); + #ifdef __cplusplus } #endif diff --git a/menu/menu_entries_cbs_iterate.c b/menu/menu_entries_cbs_iterate.c index 020515e355..79eb0ba820 100644 --- a/menu/menu_entries_cbs_iterate.c +++ b/menu/menu_entries_cbs_iterate.c @@ -270,18 +270,18 @@ static int action_iterate_menu_viewport(char *s, size_t len, const char *label, struct retro_game_geometry *geom = NULL; const char *base_msg = NULL; unsigned type = 0; - global_t *global = global_get_ptr(); - video_viewport_t *custom = &global->console.screen.viewports.custom_vp; + video_viewport_t *custom = video_viewport_get_custom(); menu_handle_t *menu = menu_driver_get_ptr(); menu_list_t *menu_list = menu_list_get_ptr(); settings_t *settings = config_get_ptr(); + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); if (!menu) return -1; menu_list_get_last_stack(menu_list, NULL, NULL, &type); - geom = (struct retro_game_geometry*)&global->system.av_info.geometry; + geom = (struct retro_game_geometry*)&av_info->geometry; if (settings->video.scale_integer) { diff --git a/record/record_driver.c b/record/record_driver.c index cb3688fddb..228dec7340 100644 --- a/record/record_driver.c +++ b/record/record_driver.c @@ -291,7 +291,7 @@ bool recording_init(void) global_t *global = global_get_ptr(); driver_t *driver = driver_get_ptr(); settings_t *settings = config_get_ptr(); - const struct retro_system_av_info *info = &global->system.av_info; + struct retro_system_av_info *av_info = video_viewport_get_system_av_info(); if (!global->record.enable) return false; @@ -310,8 +310,8 @@ bool recording_init(void) } RARCH_LOG("Custom timing given: FPS: %.4f, Sample rate: %.4f\n", - (float)global->system.av_info.timing.fps, - (float)global->system.av_info.timing.sample_rate); + (float)av_info->timing.fps, + (float)av_info->timing.sample_rate); strlcpy(recording_file, global->record.path, sizeof(recording_file)); @@ -320,14 +320,14 @@ bool recording_init(void) global->record.output_dir, global->record.path, sizeof(recording_file)); - params.out_width = info->geometry.base_width; - params.out_height = info->geometry.base_height; - params.fb_width = info->geometry.max_width; - params.fb_height = info->geometry.max_height; + params.out_width = av_info->geometry.base_width; + params.out_height = av_info->geometry.base_height; + params.fb_width = av_info->geometry.max_width; + params.fb_height = av_info->geometry.max_height; params.channels = 2; params.filename = recording_file; - params.fps = global->system.av_info.timing.fps; - params.samplerate = global->system.av_info.timing.sample_rate; + params.fps = av_info->timing.fps; + params.samplerate = av_info->timing.sample_rate; params.pix_fmt = (global->system.pix_fmt == RETRO_PIXEL_FORMAT_XRGB8888) ? FFEMU_PIX_ARGB8888 : FFEMU_PIX_RGB565; params.config = NULL; diff --git a/retroarch.c b/retroarch.c index c8ef98fb66..5ceded463a 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1085,9 +1085,10 @@ static void validate_cpu_features(void) void rarch_init_system_av_info(void) { runloop_t *runloop = rarch_main_get_ptr(); - global_t *global = global_get_ptr(); + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); - pretro_get_system_av_info(&global->system.av_info); + pretro_get_system_av_info(av_info); runloop->frames.limit.last_time = rarch_get_time_usec(); } diff --git a/runloop.c b/runloop.c index b26b06816e..3472855da3 100644 --- a/runloop.c +++ b/runloop.c @@ -645,10 +645,10 @@ static void rarch_limit_frame_time(void) retro_time_t to_sleep_ms = 0; runloop_t *runloop = rarch_main_get_ptr(); settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); retro_time_t current = rarch_get_time_usec(); - double effective_fps = global->system.av_info.timing.fps - * settings->fastforward_ratio; + struct retro_system_av_info *av_info = + video_viewport_get_system_av_info(); + double effective_fps = av_info->timing.fps * settings->fastforward_ratio; double mft_f = 1000000.0f / effective_fps; runloop->frames.limit.minimum_time = (retro_time_t) roundf(mft_f); diff --git a/runloop.h b/runloop.h index e2baf5bf2e..4e42adfce0 100644 --- a/runloop.h +++ b/runloop.h @@ -152,7 +152,6 @@ typedef struct global struct { struct retro_system_info info; - struct retro_system_av_info av_info; unsigned rotation; bool shutdown;