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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c
index 6088775..0f1ac00 100644
--- a/src/video/raspberry/SDL_rpivideo.c
+++ b/src/video/raspberry/SDL_rpivideo.c
@@ -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;
@@ -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) {