src/video/SDL_sysvideo.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 02 Aug 2017 10:22:48 -0700
changeset 11175 cbc6a8a5b701
parent 11147 5b2841f73a33
child 11255 0302e7e91db7
permissions -rw-r--r--
Fixed bug 3690 - SDL2 KMS/DRM render context support

Manuel

The attached patch adds support for KMS/DRM context graphics.

It builds with no problem on X86_64 GNU/Linux systems, provided the needed libraries are present, and on ARM GNU/Linux systems that have KMS/DRM support and a GLES2 implementation.
Tested on Raspberry Pi: KMS/DRM is what the Raspberry Pi will use as default in the near future, once the propietary DispmanX API by Broadcom is overtaken by open graphics stack, it's possible to boot current Raspbian system in KMS mode by adding "dtoverlay=vc4-kms-v3d" to config.txt on Raspbian's boot partition.
X86 systems use KMS right away in every current GNU/Linux system.

Simple build instructions:

$./autogen.sh
$./configure --enable-video-kmsdrm
$make
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
     4 
     5   This software is provided 'as-is', without any express or implied
     6   warranty.  In no event will the authors be held liable for any damages
     7   arising from the use of this software.
     8 
     9   Permission is granted to anyone to use this software for any purpose,
    10   including commercial applications, and to alter it and redistribute it
    11   freely, subject to the following restrictions:
    12 
    13   1. The origin of this software must not be misrepresented; you must not
    14      claim that you wrote the original software. If you use this software
    15      in a product, an acknowledgment in the product documentation would be
    16      appreciated but is not required.
    17   2. Altered source versions must be plainly marked as such, and must not be
    18      misrepresented as being the original software.
    19   3. This notice may not be removed or altered from any source distribution.
    20 */
    21 #include "../SDL_internal.h"
    22 
    23 #ifndef SDL_sysvideo_h_
    24 #define SDL_sysvideo_h_
    25 
    26 #include "SDL_messagebox.h"
    27 #include "SDL_shape.h"
    28 #include "SDL_thread.h"
    29 
    30 /* The SDL video driver */
    31 
    32 typedef struct SDL_WindowShaper SDL_WindowShaper;
    33 typedef struct SDL_ShapeDriver SDL_ShapeDriver;
    34 typedef struct SDL_VideoDisplay SDL_VideoDisplay;
    35 typedef struct SDL_VideoDevice SDL_VideoDevice;
    36 
    37 /* Define the SDL window-shaper structure */
    38 struct SDL_WindowShaper
    39 {
    40     /* The window associated with the shaper */
    41     SDL_Window *window;
    42 
    43     /* The user's specified coordinates for the window, for once we give it a shape. */
    44     Uint32 userx,usery;
    45 
    46     /* The parameters for shape calculation. */
    47     SDL_WindowShapeMode mode;
    48 
    49     /* Has this window been assigned a shape? */
    50     SDL_bool hasshape;
    51 
    52     void *driverdata;
    53 };
    54 
    55 /* Define the SDL shape driver structure */
    56 struct SDL_ShapeDriver
    57 {
    58     SDL_WindowShaper *(*CreateShaper)(SDL_Window * window);
    59     int (*SetWindowShape)(SDL_WindowShaper *shaper,SDL_Surface *shape,SDL_WindowShapeMode *shape_mode);
    60     int (*ResizeWindowShape)(SDL_Window *window);
    61 };
    62 
    63 typedef struct SDL_WindowUserData
    64 {
    65     char *name;
    66     void *data;
    67     struct SDL_WindowUserData *next;
    68 } SDL_WindowUserData;
    69 
    70 /* Define the SDL window structure, corresponding to toplevel windows */
    71 struct SDL_Window
    72 {
    73     const void *magic;
    74     Uint32 id;
    75     char *title;
    76     SDL_Surface *icon;
    77     int x, y;
    78     int w, h;
    79     int min_w, min_h;
    80     int max_w, max_h;
    81     Uint32 flags;
    82     Uint32 last_fullscreen_flags;
    83 
    84     /* Stored position and size for windowed mode */
    85     SDL_Rect windowed;
    86 
    87     SDL_DisplayMode fullscreen_mode;
    88 
    89     float opacity;
    90 
    91     float brightness;
    92     Uint16 *gamma;
    93     Uint16 *saved_gamma;        /* (just offset into gamma) */
    94 
    95     SDL_Surface *surface;
    96     SDL_bool surface_valid;
    97 
    98     SDL_bool is_hiding;
    99     SDL_bool is_destroying;
   100     SDL_bool is_dropping;       /* drag/drop in progress, expecting SDL_SendDropComplete(). */
   101 
   102     SDL_WindowShaper *shaper;
   103 
   104     SDL_HitTest hit_test;
   105     void *hit_test_data;
   106 
   107     SDL_WindowUserData *data;
   108 
   109     void *driverdata;
   110 
   111     SDL_Window *prev;
   112     SDL_Window *next;
   113 };
   114 #define FULLSCREEN_VISIBLE(W) \
   115     (((W)->flags & SDL_WINDOW_FULLSCREEN) && \
   116      ((W)->flags & SDL_WINDOW_SHOWN) && \
   117      !((W)->flags & SDL_WINDOW_MINIMIZED))
   118 
   119 /*
   120  * Define the SDL display structure This corresponds to physical monitors
   121  * attached to the system.
   122  */
   123 struct SDL_VideoDisplay
   124 {
   125     char *name;
   126     int max_display_modes;
   127     int num_display_modes;
   128     SDL_DisplayMode *display_modes;
   129     SDL_DisplayMode desktop_mode;
   130     SDL_DisplayMode current_mode;
   131 
   132     SDL_Window *fullscreen_window;
   133 
   134     SDL_VideoDevice *device;
   135 
   136     void *driverdata;
   137 };
   138 
   139 /* Forward declaration */
   140 struct SDL_SysWMinfo;
   141 
   142 /* Define the SDL video driver structure */
   143 #define _THIS   SDL_VideoDevice *_this
   144 
   145 struct SDL_VideoDevice
   146 {
   147     /* * * */
   148     /* The name of this video driver */
   149     const char *name;
   150 
   151     /* * * */
   152     /* Initialization/Query functions */
   153 
   154     /*
   155      * Initialize the native video subsystem, filling in the list of
   156      * displays for this driver, returning 0 or -1 if there's an error.
   157      */
   158     int (*VideoInit) (_THIS);
   159 
   160     /*
   161      * Reverse the effects VideoInit() -- called if VideoInit() fails or
   162      * if the application is shutting down the video subsystem.
   163      */
   164     void (*VideoQuit) (_THIS);
   165 
   166     /*
   167      * Reinitialize the touch devices -- called if an unknown touch ID occurs.
   168      */
   169     void (*ResetTouch) (_THIS);
   170 
   171     /* * * */
   172     /*
   173      * Display functions
   174      */
   175 
   176     /*
   177      * Get the bounds of a display
   178      */
   179     int (*GetDisplayBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   180 
   181     /*
   182      * Get the dots/pixels-per-inch of a display
   183      */
   184     int (*GetDisplayDPI) (_THIS, SDL_VideoDisplay * display, float * ddpi, float * hdpi, float * vdpi);
   185 
   186     /*
   187      * Get the usable bounds of a display (bounds minus menubar or whatever)
   188      */
   189     int (*GetDisplayUsableBounds) (_THIS, SDL_VideoDisplay * display, SDL_Rect * rect);
   190 
   191     /*
   192      * Get a list of the available display modes for a display.
   193      */
   194     void (*GetDisplayModes) (_THIS, SDL_VideoDisplay * display);
   195 
   196     /*
   197      * Setting the display mode is independent of creating windows, so
   198      * when the display mode is changed, all existing windows should have
   199      * their data updated accordingly, including the display surfaces
   200      * associated with them.
   201      */
   202     int (*SetDisplayMode) (_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
   203 
   204     /* * * */
   205     /*
   206      * Window functions
   207      */
   208     int (*CreateWindow) (_THIS, SDL_Window * window);
   209     int (*CreateWindowFrom) (_THIS, SDL_Window * window, const void *data);
   210     void (*SetWindowTitle) (_THIS, SDL_Window * window);
   211     void (*SetWindowIcon) (_THIS, SDL_Window * window, SDL_Surface * icon);
   212     void (*SetWindowPosition) (_THIS, SDL_Window * window);
   213     void (*SetWindowSize) (_THIS, SDL_Window * window);
   214     void (*SetWindowMinimumSize) (_THIS, SDL_Window * window);
   215     void (*SetWindowMaximumSize) (_THIS, SDL_Window * window);
   216     int (*GetWindowBordersSize) (_THIS, SDL_Window * window, int *top, int *left, int *bottom, int *right);
   217     int (*SetWindowOpacity) (_THIS, SDL_Window * window, float opacity);
   218     int (*SetWindowModalFor) (_THIS, SDL_Window * modal_window, SDL_Window * parent_window);
   219     int (*SetWindowInputFocus) (_THIS, SDL_Window * window);
   220     void (*ShowWindow) (_THIS, SDL_Window * window);
   221     void (*HideWindow) (_THIS, SDL_Window * window);
   222     void (*RaiseWindow) (_THIS, SDL_Window * window);
   223     void (*MaximizeWindow) (_THIS, SDL_Window * window);
   224     void (*MinimizeWindow) (_THIS, SDL_Window * window);
   225     void (*RestoreWindow) (_THIS, SDL_Window * window);
   226     void (*SetWindowBordered) (_THIS, SDL_Window * window, SDL_bool bordered);
   227     void (*SetWindowResizable) (_THIS, SDL_Window * window, SDL_bool resizable);
   228     void (*SetWindowFullscreen) (_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
   229     int (*SetWindowGammaRamp) (_THIS, SDL_Window * window, const Uint16 * ramp);
   230     int (*GetWindowGammaRamp) (_THIS, SDL_Window * window, Uint16 * ramp);
   231     void (*SetWindowGrab) (_THIS, SDL_Window * window, SDL_bool grabbed);
   232     void (*DestroyWindow) (_THIS, SDL_Window * window);
   233     int (*CreateWindowFramebuffer) (_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);
   234     int (*UpdateWindowFramebuffer) (_THIS, SDL_Window * window, const SDL_Rect * rects, int numrects);
   235     void (*DestroyWindowFramebuffer) (_THIS, SDL_Window * window);
   236     void (*OnWindowEnter) (_THIS, SDL_Window * window);
   237 
   238     /* * * */
   239     /*
   240      * Shaped-window functions
   241      */
   242     SDL_ShapeDriver shape_driver;
   243 
   244     /* Get some platform dependent window information */
   245     SDL_bool(*GetWindowWMInfo) (_THIS, SDL_Window * window,
   246                                 struct SDL_SysWMinfo * info);
   247 
   248     /* * * */
   249     /*
   250      * OpenGL support
   251      */
   252     int (*GL_LoadLibrary) (_THIS, const char *path);
   253     void *(*GL_GetProcAddress) (_THIS, const char *proc);
   254     void (*GL_UnloadLibrary) (_THIS);
   255       SDL_GLContext(*GL_CreateContext) (_THIS, SDL_Window * window);
   256     int (*GL_MakeCurrent) (_THIS, SDL_Window * window, SDL_GLContext context);
   257     void (*GL_GetDrawableSize) (_THIS, SDL_Window * window, int *w, int *h);
   258     int (*GL_SetSwapInterval) (_THIS, int interval);
   259     int (*GL_GetSwapInterval) (_THIS);
   260     int (*GL_SwapWindow) (_THIS, SDL_Window * window);
   261     void (*GL_DeleteContext) (_THIS, SDL_GLContext context);
   262 
   263     /* * * */
   264     /*
   265      * Event manager functions
   266      */
   267     void (*PumpEvents) (_THIS);
   268 
   269     /* Suspend the screensaver */
   270     void (*SuspendScreenSaver) (_THIS);
   271 
   272     /* Text input */
   273     void (*StartTextInput) (_THIS);
   274     void (*StopTextInput) (_THIS);
   275     void (*SetTextInputRect) (_THIS, SDL_Rect *rect);
   276 
   277     /* Screen keyboard */
   278     SDL_bool (*HasScreenKeyboardSupport) (_THIS);
   279     void (*ShowScreenKeyboard) (_THIS, SDL_Window *window);
   280     void (*HideScreenKeyboard) (_THIS, SDL_Window *window);
   281     SDL_bool (*IsScreenKeyboardShown) (_THIS, SDL_Window *window);
   282 
   283     /* Clipboard */
   284     int (*SetClipboardText) (_THIS, const char *text);
   285     char * (*GetClipboardText) (_THIS);
   286     SDL_bool (*HasClipboardText) (_THIS);
   287 
   288     /* MessageBox */
   289     int (*ShowMessageBox) (_THIS, const SDL_MessageBoxData *messageboxdata, int *buttonid);
   290 
   291     /* Hit-testing */
   292     int (*SetWindowHitTest)(SDL_Window * window, SDL_bool enabled);
   293 
   294     /* * * */
   295     /* Data common to all drivers */
   296     SDL_bool is_dummy;
   297     SDL_bool suspend_screensaver;
   298     int num_displays;
   299     SDL_VideoDisplay *displays;
   300     SDL_Window *windows;
   301     SDL_Window *grabbed_window;
   302     Uint8 window_magic;
   303     Uint32 next_object_id;
   304     char *clipboard_text;
   305 
   306     /* * * */
   307     /* Data used by the GL drivers */
   308     struct
   309     {
   310         int red_size;
   311         int green_size;
   312         int blue_size;
   313         int alpha_size;
   314         int depth_size;
   315         int buffer_size;
   316         int stencil_size;
   317         int double_buffer;
   318         int accum_red_size;
   319         int accum_green_size;
   320         int accum_blue_size;
   321         int accum_alpha_size;
   322         int stereo;
   323         int multisamplebuffers;
   324         int multisamplesamples;
   325         int accelerated;
   326         int major_version;
   327         int minor_version;
   328         int flags;
   329         int profile_mask;
   330         int share_with_current_context;
   331         int release_behavior;
   332         int framebuffer_srgb_capable;
   333         int retained_backing;
   334         int driver_loaded;
   335         char driver_path[256];
   336         void *dll_handle;
   337     } gl_config;
   338 
   339     /* * * */
   340     /* Cache current GL context; don't call the OS when it hasn't changed. */
   341     /* We have the global pointers here so Cocoa continues to work the way
   342        it always has, and the thread-local storage for the general case.
   343      */
   344     SDL_Window *current_glwin;
   345     SDL_GLContext current_glctx;
   346     SDL_TLSID current_glwin_tls;
   347     SDL_TLSID current_glctx_tls;
   348 
   349     /* * * */
   350     /* Data private to this driver */
   351     void *driverdata;
   352     struct SDL_GLDriverData *gl_data;
   353     
   354 #if SDL_VIDEO_OPENGL_EGL
   355     struct SDL_EGL_VideoData *egl_data;
   356 #endif
   357     
   358 #if SDL_VIDEO_OPENGL_ES || SDL_VIDEO_OPENGL_ES2
   359     struct SDL_PrivateGLESData *gles_data;
   360 #endif
   361 
   362     /* * * */
   363     /* The function used to dispose of this structure */
   364     void (*free) (_THIS);
   365 };
   366 
   367 typedef struct VideoBootStrap
   368 {
   369     const char *name;
   370     const char *desc;
   371     int (*available) (void);
   372     SDL_VideoDevice *(*create) (int devindex);
   373 } VideoBootStrap;
   374 
   375 /* Not all of these are available in a given build. Use #ifdefs, etc. */
   376 extern VideoBootStrap COCOA_bootstrap;
   377 extern VideoBootStrap X11_bootstrap;
   378 extern VideoBootStrap MIR_bootstrap;
   379 extern VideoBootStrap DirectFB_bootstrap;
   380 extern VideoBootStrap WINDOWS_bootstrap;
   381 extern VideoBootStrap WINRT_bootstrap;
   382 extern VideoBootStrap HAIKU_bootstrap;
   383 extern VideoBootStrap PND_bootstrap;
   384 extern VideoBootStrap UIKIT_bootstrap;
   385 extern VideoBootStrap Android_bootstrap;
   386 extern VideoBootStrap PSP_bootstrap;
   387 extern VideoBootStrap RPI_bootstrap;
   388 extern VideoBootStrap KMSDRM_bootstrap;
   389 extern VideoBootStrap DUMMY_bootstrap;
   390 extern VideoBootStrap Wayland_bootstrap;
   391 extern VideoBootStrap NACL_bootstrap;
   392 extern VideoBootStrap VIVANTE_bootstrap;
   393 extern VideoBootStrap Emscripten_bootstrap;
   394 extern VideoBootStrap QNX_bootstrap;
   395 
   396 extern SDL_VideoDevice *SDL_GetVideoDevice(void);
   397 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
   398 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
   399 extern SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode * mode);
   400 extern SDL_VideoDisplay *SDL_GetDisplayForWindow(SDL_Window *window);
   401 extern void *SDL_GetDisplayDriverData( int displayIndex );
   402 
   403 extern void SDL_GL_DeduceMaxSupportedESProfile(int* major, int* minor);
   404 
   405 extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   406 
   407 extern void SDL_OnWindowShown(SDL_Window * window);
   408 extern void SDL_OnWindowHidden(SDL_Window * window);
   409 extern void SDL_OnWindowResized(SDL_Window * window);
   410 extern void SDL_OnWindowMinimized(SDL_Window * window);
   411 extern void SDL_OnWindowRestored(SDL_Window * window);
   412 extern void SDL_OnWindowEnter(SDL_Window * window);
   413 extern void SDL_OnWindowLeave(SDL_Window * window);
   414 extern void SDL_OnWindowFocusGained(SDL_Window * window);
   415 extern void SDL_OnWindowFocusLost(SDL_Window * window);
   416 extern void SDL_UpdateWindowGrab(SDL_Window * window);
   417 extern SDL_Window * SDL_GetFocusWindow(void);
   418 
   419 extern SDL_bool SDL_ShouldAllowTopmost(void);
   420 
   421 extern float SDL_ComputeDiagonalDPI(int hpix, int vpix, float hinches, float vinches);
   422 
   423 extern void SDL_OnApplicationWillTerminate(void);
   424 extern void SDL_OnApplicationDidReceiveMemoryWarning(void);
   425 extern void SDL_OnApplicationWillResignActive(void);
   426 extern void SDL_OnApplicationDidEnterBackground(void);
   427 extern void SDL_OnApplicationWillEnterForeground(void);
   428 extern void SDL_OnApplicationDidBecomeActive(void);
   429 
   430 #endif /* SDL_sysvideo_h_ */
   431 
   432 /* vi: set ts=4 sw=4 expandtab: */