From 24e6ed7fdcb8801b1e3740df4fe79f10ff181a9d Mon Sep 17 00:00:00 2001 From: Mahyar Koshkouei Date: Wed, 3 Jan 2018 00:04:43 +0000 Subject: [PATCH] Set framebuffer size to video resolution We now automatically select the correct video size and aspect ratio. Now the video doesn't look like a blury mess. Closes issue #8. Signed-off-by: Mahyar Koshkouei --- mpv-libretro.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/mpv-libretro.c b/mpv-libretro.c index a3fe46f..381b509 100644 --- a/mpv-libretro.c +++ b/mpv-libretro.c @@ -84,8 +84,8 @@ void retro_get_system_av_info(struct retro_system_av_info *info) }; info->geometry = (struct retro_game_geometry) { - .base_width = 320, - .base_height = 240, + .base_width = 256, + .base_height = 144, .max_width = 1920, .max_height = 1080, .aspect_ratio = -1, @@ -300,12 +300,38 @@ static void retropad_update_input(void) void retro_run(void) { + /* We only need to update the base video size once, and we do it here since + * the input file is not processed during the first + * retro_get_system_av_info() call. + */ + static bool updated_video_dimensions = false; + static int64_t width, height; + + if(updated_video_dimensions == false) + { + mpv_get_property(mpv, "width", MPV_FORMAT_INT64, &width); + mpv_get_property(mpv, "height", MPV_FORMAT_INT64, &height); + + struct retro_game_geometry geometry = { + .base_width = width, + .base_height = height, + /* max_width and max_height are ignored */ + .max_width = width, + .max_height = height, + /* Aspect ratio calculated automatically from base dimensions */ + .aspect_ratio = -1, + }; + + environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &geometry); + updated_video_dimensions = true; + } + retropad_update_input(); /* TODO: Implement an audio callback feature in to libmpv */ //audio_callback(); - mpv_opengl_cb_draw(mpv_gl, hw_render.get_current_framebuffer(), 320, 240); - video_cb(RETRO_HW_FRAME_BUFFER_VALID, 320, 240, 0); + mpv_opengl_cb_draw(mpv_gl, hw_render.get_current_framebuffer(), width, height); + video_cb(RETRO_HW_FRAME_BUFFER_VALID, width, height, 0); return; }