diff --git a/gfx/context/drm_egl_ctx.c b/gfx/context/drm_egl_ctx.c index d610ac7d2b..3d090594d3 100644 --- a/gfx/context/drm_egl_ctx.c +++ b/gfx/context/drm_egl_ctx.c @@ -630,6 +630,7 @@ const gfx_ctx_driver_t gfx_ctx_drm_egl = { gfx_ctx_swap_interval, gfx_ctx_set_video_mode, gfx_ctx_get_video_size, + NULL, gfx_ctx_update_window_title, gfx_ctx_check_window, gfx_ctx_set_resize, diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 108715f44a..baf1a178e8 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -422,6 +422,7 @@ const gfx_ctx_driver_t gfx_ctx_ps3 = { gfx_ctx_set_swap_interval, gfx_ctx_set_video_mode, gfx_ctx_get_video_size, + NULL, gfx_ctx_update_window_title, gfx_ctx_check_window, gfx_ctx_set_resize, diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index d2c44b0377..b3397203f6 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -304,6 +304,7 @@ const gfx_ctx_driver_t gfx_ctx_sdl_gl = { gfx_ctx_swap_interval, gfx_ctx_set_video_mode, gfx_ctx_get_video_size, + NULL, gfx_ctx_update_window_title, gfx_ctx_check_window, gfx_ctx_set_resize, diff --git a/gfx/context/vc_egl_ctx.c b/gfx/context/vc_egl_ctx.c index 6b04a4af6e..bed77255db 100644 --- a/gfx/context/vc_egl_ctx.c +++ b/gfx/context/vc_egl_ctx.c @@ -270,6 +270,15 @@ static bool gfx_ctx_bind_api(enum gfx_ctx_api api) } } +static float gfx_ctx_translate_aspect(unsigned width, unsigned height) +{ + // check for SD televisions: they should always be 4:3. + if ((width == 640 || width == 720) && (height == 480 || height == 576)) + return 4.0f / 3.0f; + else + return (float)width / height; +} + const gfx_ctx_driver_t gfx_ctx_videocore = { gfx_ctx_init, gfx_ctx_destroy, @@ -277,6 +286,7 @@ const gfx_ctx_driver_t gfx_ctx_videocore = { gfx_ctx_swap_interval, gfx_ctx_set_video_mode, gfx_ctx_get_video_size, + gfx_ctx_translate_aspect, gfx_ctx_update_window_title, gfx_ctx_check_window, gfx_ctx_set_resize, diff --git a/gfx/context/xegl_ctx.c b/gfx/context/xegl_ctx.c index 5b87f3751c..0f5b5ae0b7 100644 --- a/gfx/context/xegl_ctx.c +++ b/gfx/context/xegl_ctx.c @@ -469,6 +469,7 @@ const gfx_ctx_driver_t gfx_ctx_x_egl = { gfx_ctx_swap_interval, gfx_ctx_set_video_mode, gfx_ctx_get_video_size, + NULL, gfx_ctx_update_window_title, gfx_ctx_check_window, gfx_ctx_set_resize, diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index 326f97bdad..a5f211a6d1 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -55,6 +55,12 @@ typedef struct gfx_ctx_driver // If not initialized yet, it returns current screen size. void (*get_video_size)(unsigned*, unsigned*); + // Translates a window size to an aspect ratio. + // In most cases this will be just width / height, but + // some contexts will better know which actual aspect ratio is used. + // This can be NULL to assume the default behavior. + float (*translate_aspect)(unsigned, unsigned); + // Asks driver to update window title (FPS, etc). void (*update_window_title)(bool); diff --git a/gfx/gl.c b/gfx/gl.c index cd1df875d1..4e2a44c85c 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -609,11 +609,12 @@ void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, if (gl->keep_aspect && !force_full) { float desired_aspect = g_settings.video.aspect_ratio; - float device_aspect = (float)width / height; - // check for SD televisions: they should always be 4:3 - if ((width == 640 || width == 720) && (height == 480 || height == 576)) - device_aspect = 4.0f / 3.0f; + float device_aspect; + if (gl->driver->translate_aspect) + device_aspect = gl->driver->translate_aspect(width, height); + else + device_aspect = (float)width / height; float delta;