Fixed bug 3369 - RaspberryPI ability to specify a Dispmanx layer
authorSam Lantinga <slouken@libsdl.org>
Tue, 18 Oct 2016 23:24:49 -0700
changeset 10553c1bb718f6c3f
parent 10552 221d4601ab8c
child 10554 6c07c69fb842
Fixed bug 3369 - RaspberryPI ability to specify a Dispmanx layer

Albert Casals

On a RaspberryPI, it might become convenient to specify the Dispmanx layer SDL uses.
Currently, it is hardcoded to be 10000 to sit above most applications.

This can be specially useful when integrating other graphical apps and frameworks like OMXplayer, QT5 etc.. in order to have more flexibility on their Z-order.
include/SDL_hints.h
src/video/raspberry/SDL_rpimouse.c
src/video/raspberry/SDL_rpivideo.c
     1.1 --- a/include/SDL_hints.h	Tue Oct 18 23:12:45 2016 -0700
     1.2 +++ b/include/SDL_hints.h	Tue Oct 18 23:24:49 2016 -0700
     1.3 @@ -700,6 +700,14 @@
     1.4  #define SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING "SDL_WINDOWS_DISABLE_THREAD_NAMING"
     1.5  
     1.6  /**
     1.7 + * \brief Tell SDL which Dispmanx layer to use on a Raspberry PI
     1.8 + *
     1.9 + * Also known as Z-order. The variable can take a negative or positive value.
    1.10 + * The default is 10000.
    1.11 + */
    1.12 +#define SDL_HINT_RPI_VIDEO_LAYER           "SDL_RPI_VIDEO_LAYER"
    1.13 +
    1.14 +/**
    1.15   *  \brief  An enumeration of hint priorities
    1.16   */
    1.17  typedef enum
     2.1 --- a/src/video/raspberry/SDL_rpimouse.c	Tue Oct 18 23:12:45 2016 -0700
     2.2 +++ b/src/video/raspberry/SDL_rpimouse.c	Tue Oct 18 23:24:49 2016 -0700
     2.3 @@ -24,6 +24,7 @@
     2.4  
     2.5  #include "SDL_assert.h"
     2.6  #include "SDL_surface.h"
     2.7 +#include "SDL_hints.h"
     2.8  
     2.9  #include "SDL_rpivideo.h"
    2.10  #include "SDL_rpimouse.h"
    2.11 @@ -117,7 +118,9 @@
    2.12      SDL_VideoDisplay *display;
    2.13      SDL_DisplayData *data;
    2.14      VC_DISPMANX_ALPHA_T alpha = {  DISPMANX_FLAGS_ALPHA_FROM_SOURCE /* flags */ , 255 /*opacity 0->255*/,  0 /* mask */ };
    2.15 -    
    2.16 +    uint32_t layer = SDL_RPI_MOUSELAYER;
    2.17 +    const char *env;
    2.18 +
    2.19      mouse = SDL_GetMouse();
    2.20      if (mouse == NULL) {
    2.21          return -1;
    2.22 @@ -167,9 +170,14 @@
    2.23          update = vc_dispmanx_update_start(10);
    2.24          SDL_assert(update);
    2.25  
    2.26 +        env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER);
    2.27 +        if (env) {
    2.28 +            layer = SDL_atoi(env) + 1;
    2.29 +        }
    2.30 +
    2.31          curdata->element = vc_dispmanx_element_add(update,
    2.32                                                      data->dispman_display,
    2.33 -                                                    SDL_RPI_MOUSELAYER, // layer
    2.34 +                                                    layer,
    2.35                                                      &dst_rect,
    2.36                                                      curdata->resource,
    2.37                                                      &src_rect,
     3.1 --- a/src/video/raspberry/SDL_rpivideo.c	Tue Oct 18 23:12:45 2016 -0700
     3.2 +++ b/src/video/raspberry/SDL_rpivideo.c	Tue Oct 18 23:24:49 2016 -0700
     3.3 @@ -38,6 +38,7 @@
     3.4  #include "SDL_events.h"
     3.5  #include "../../events/SDL_mouse_c.h"
     3.6  #include "../../events/SDL_keyboard_c.h"
     3.7 +#include "SDL_hints.h"
     3.8  
     3.9  #ifdef SDL_INPUT_LINUXEV
    3.10  #include "../../core/linux/SDL_evdev.h"
    3.11 @@ -221,6 +222,8 @@
    3.12      VC_RECT_T src_rect;
    3.13      VC_DISPMANX_ALPHA_T         dispman_alpha;
    3.14      DISPMANX_UPDATE_HANDLE_T dispman_update;
    3.15 +    uint32_t layer = SDL_RPI_VIDEOLAYER;
    3.16 +    const char *env;
    3.17  
    3.18      /* Disable alpha, otherwise the app looks composed with whatever dispman is showing (X11, console,etc) */
    3.19      dispman_alpha.flags = DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS; 
    3.20 @@ -253,11 +256,25 @@
    3.21      src_rect.width = window->w << 16;
    3.22      src_rect.height = window->h << 16;
    3.23  
    3.24 +    env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER);
    3.25 +    if (env) {
    3.26 +        layer = SDL_atoi(env);
    3.27 +    }
    3.28 +
    3.29      dispman_update = vc_dispmanx_update_start( 0 );
    3.30 -    wdata->dispman_window.element = vc_dispmanx_element_add ( dispman_update, displaydata->dispman_display, SDL_RPI_VIDEOLAYER /* layer */, &dst_rect, 0/*src*/, &src_rect, DISPMANX_PROTECTION_NONE, &dispman_alpha /*alpha*/, 0/*clamp*/, 0/*transform*/);
    3.31 +    wdata->dispman_window.element = vc_dispmanx_element_add (dispman_update,
    3.32 +                                                             displaydata->dispman_display,
    3.33 +                                                             layer /* layer */,
    3.34 +                                                             &dst_rect,
    3.35 +                                                             0 /*src*/,
    3.36 +                                                             &src_rect,
    3.37 +                                                             DISPMANX_PROTECTION_NONE,
    3.38 +                                                             &dispman_alpha /*alpha*/,
    3.39 +                                                             0 /*clamp*/,
    3.40 +                                                             0 /*transform*/);
    3.41      wdata->dispman_window.width = window->w;
    3.42      wdata->dispman_window.height = window->h;
    3.43 -    vc_dispmanx_update_submit_sync( dispman_update );
    3.44 +    vc_dispmanx_update_submit_sync(dispman_update);
    3.45      
    3.46      if (!_this->egl_data) {
    3.47          if (SDL_GL_LoadLibrary(NULL) < 0) {