raspberry: expose second display.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 19 Feb 2019 23:46:54 -0500
changeset 126156f0eb21dd7d1
parent 12614 8c5251cbf63c
child 12616 8a160ecca90f
raspberry: expose second display.

This lets apps see and choose between both an HDMI and DSI-connected display,
such as a television and the Pi Foundation's official touchscreen. It only
exposes the second display if the hardware reports that it is connected.
src/video/raspberry/SDL_rpivideo.c
     1.1 --- a/src/video/raspberry/SDL_rpivideo.c	Mon Feb 18 22:48:14 2019 +0100
     1.2 +++ b/src/video/raspberry/SDL_rpivideo.c	Tue Feb 19 23:46:54 2019 -0500
     1.3 @@ -154,28 +154,34 @@
     1.4      RPI_Create
     1.5  };
     1.6  
     1.7 +
     1.8  /*****************************************************************************/
     1.9  /* SDL Video and Display initialization/handling functions                   */
    1.10  /*****************************************************************************/
    1.11 -int
    1.12 -RPI_VideoInit(_THIS)
    1.13 +
    1.14 +static void
    1.15 +AddDispManXDisplay(const int display_id)
    1.16  {
    1.17 +    DISPMANX_MODEINFO_T modeinfo;
    1.18 +    DISPMANX_DISPLAY_HANDLE_T handle;
    1.19      SDL_VideoDisplay display;
    1.20      SDL_DisplayMode current_mode;
    1.21      SDL_DisplayData *data;
    1.22 -    uint32_t w,h;
    1.23  
    1.24 -    /* Initialize BCM Host */
    1.25 -    bcm_host_init();
    1.26 -
    1.27 -    SDL_zero(current_mode);
    1.28 -
    1.29 -    if (graphics_get_display_size( 0, &w, &h) < 0) {
    1.30 -        return -1;
    1.31 +    handle = vc_dispmanx_display_open(display_id);
    1.32 +    if (!handle) {
    1.33 +        return;  /* this display isn't available */
    1.34      }
    1.35  
    1.36 -    current_mode.w = w;
    1.37 -    current_mode.h = h;
    1.38 +    if (vc_dispmanx_display_get_info(handle, &modeinfo) < 0) {
    1.39 +        vc_dispmanx_display_close(handle);
    1.40 +        return;
    1.41 +    }
    1.42 +
    1.43 +    /* RPI_GetRefreshRate() doesn't distinguish between displays. I'm not sure the hardware distinguishes either */
    1.44 +    SDL_zero(current_mode);
    1.45 +    current_mode.w = modeinfo.width;
    1.46 +    current_mode.h = modeinfo.height;
    1.47      current_mode.refresh_rate = RPI_GetRefreshRate();
    1.48      /* 32 bpp for default */
    1.49      current_mode.format = SDL_PIXELFORMAT_ABGR8888;
    1.50 @@ -189,14 +195,25 @@
    1.51      /* Allocate display internal data */
    1.52      data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
    1.53      if (data == NULL) {
    1.54 -        return SDL_OutOfMemory();
    1.55 +        vc_dispmanx_display_close(handle);
    1.56 +        return;  /* oh well */
    1.57      }
    1.58  
    1.59 -    data->dispman_display = vc_dispmanx_display_open( 0 /* LCD */);
    1.60 +    data->dispman_display = handle;
    1.61  
    1.62      display.driverdata = data;
    1.63  
    1.64      SDL_AddVideoDisplay(&display);
    1.65 +}
    1.66 +
    1.67 +int
    1.68 +RPI_VideoInit(_THIS)
    1.69 +{
    1.70 +    /* Initialize BCM Host */
    1.71 +    bcm_host_init();
    1.72 +
    1.73 +    AddDispManXDisplay(DISPMANX_ID_MAIN_LCD);  /* your default display */
    1.74 +    AddDispManXDisplay(DISPMANX_ID_FORCE_OTHER);  /* an "other" display...maybe DSI-connected screen while HDMI is your main */
    1.75  
    1.76  #ifdef SDL_INPUT_LINUXEV    
    1.77      if (SDL_EVDEV_Init() < 0) {