Skip to content

Commit

Permalink
raspberry: expose second display.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
icculus committed Feb 20, 2019
1 parent 90a075d commit 6fbe9e2
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions src/video/raspberry/SDL_rpivideo.c
Expand Up @@ -154,28 +154,34 @@ VideoBootStrap RPI_bootstrap = {
RPI_Create
};


/*****************************************************************************/
/* SDL Video and Display initialization/handling functions */
/*****************************************************************************/
int
RPI_VideoInit(_THIS)

static void
AddDispManXDisplay(const int display_id)
{
DISPMANX_MODEINFO_T modeinfo;
DISPMANX_DISPLAY_HANDLE_T handle;
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
SDL_DisplayData *data;
uint32_t w,h;

/* Initialize BCM Host */
bcm_host_init();

SDL_zero(current_mode);
handle = vc_dispmanx_display_open(display_id);
if (!handle) {
return; /* this display isn't available */
}

if (graphics_get_display_size( 0, &w, &h) < 0) {
return -1;
if (vc_dispmanx_display_get_info(handle, &modeinfo) < 0) {
vc_dispmanx_display_close(handle);
return;
}

current_mode.w = w;
current_mode.h = h;
/* RPI_GetRefreshRate() doesn't distinguish between displays. I'm not sure the hardware distinguishes either */
SDL_zero(current_mode);
current_mode.w = modeinfo.width;
current_mode.h = modeinfo.height;
current_mode.refresh_rate = RPI_GetRefreshRate();
/* 32 bpp for default */
current_mode.format = SDL_PIXELFORMAT_ABGR8888;
Expand All @@ -189,14 +195,25 @@ RPI_VideoInit(_THIS)
/* Allocate display internal data */
data = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (data == NULL) {
return SDL_OutOfMemory();
vc_dispmanx_display_close(handle);
return; /* oh well */
}

data->dispman_display = vc_dispmanx_display_open( 0 /* LCD */);
data->dispman_display = handle;

display.driverdata = data;

SDL_AddVideoDisplay(&display);
}

int
RPI_VideoInit(_THIS)
{
/* Initialize BCM Host */
bcm_host_init();

AddDispManXDisplay(DISPMANX_ID_MAIN_LCD); /* your default display */
AddDispManXDisplay(DISPMANX_ID_FORCE_OTHER); /* an "other" display...maybe DSI-connected screen while HDMI is your main */

#ifdef SDL_INPUT_LINUXEV
if (SDL_EVDEV_Init() < 0) {
Expand Down

0 comments on commit 6fbe9e2

Please sign in to comment.