Fixed bug 4054 - Raspberry Pi refresh rate detection
authorSam Lantinga <slouken@libsdl.org>
Wed, 07 Feb 2018 15:05:30 -0800
changeset 11853c7946b873fe8
parent 11852 c3fc99758ad2
child 11854 934d77867168
Fixed bug 4054 - Raspberry Pi refresh rate detection

Viacheslav Slavinsky

SDL_rpivideo driver has 60 frames per second hardcoded in it, this is a problem for games that need to keep pace using VSYNC. I believe that I have found a solution to this. It is based on code in tvservice.c in rpi userland:

https://github.com/raspberrypi/userland/blob/a1b89e91f393c7134b4cdc36431f863bb3333163/host_applications/linux/apps/tvservice/tvservice.c#L433
src/video/raspberry/SDL_rpivideo.c
     1.1 --- a/src/video/raspberry/SDL_rpivideo.c	Wed Jan 17 11:53:09 2018 -0500
     1.2 +++ b/src/video/raspberry/SDL_rpivideo.c	Wed Feb 07 15:05:30 2018 -0800
     1.3 @@ -63,6 +63,23 @@
     1.4      SDL_free(device);
     1.5  }
     1.6  
     1.7 +static int 
     1.8 +RPI_GetRefreshRate()
     1.9 +{
    1.10 +    TV_DISPLAY_STATE_T tvstate;
    1.11 +    if (vc_tv_get_display_state( &tvstate ) == 0) {
    1.12 +        //The width/height parameters are in the same position in the union
    1.13 +        //for HDMI and SDTV
    1.14 +        HDMI_PROPERTY_PARAM_T property;
    1.15 +        property.property = HDMI_PROPERTY_PIXEL_CLOCK_TYPE;
    1.16 +        vc_tv_hdmi_get_property(&property);
    1.17 +        return property.param1 == HDMI_PIXEL_CLOCK_TYPE_NTSC ? 
    1.18 +            tvstate.display.hdmi.frame_rate * (1000.0f/1001.0f) : 
    1.19 +            tvstate.display.hdmi.frame_rate;
    1.20 +    } 
    1.21 +    return 60;  /* Failed to get display state, default to 60 */
    1.22 +}
    1.23 +
    1.24  static SDL_VideoDevice *
    1.25  RPI_Create()
    1.26  {
    1.27 @@ -159,8 +176,7 @@
    1.28  
    1.29      current_mode.w = w;
    1.30      current_mode.h = h;
    1.31 -    /* FIXME: Is there a way to tell the actual refresh rate? */
    1.32 -    current_mode.refresh_rate = 60;
    1.33 +    current_mode.refresh_rate = RPI_GetRefreshRate();
    1.34      /* 32 bpp for default */
    1.35      current_mode.format = SDL_PIXELFORMAT_ABGR8888;
    1.36