src/video/kmsdrm/SDL_kmsdrmvideo.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 02 Aug 2017 10:22:48 -0700
changeset 11175 cbc6a8a5b701
child 11181 951807bdae20
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-2016 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 
    22 #ifndef __SDL_KMSDRMVIDEO_H__
    23 #define __SDL_KMSDRMVIDEO_H__
    24 
    25 #include "../../SDL_internal.h"
    26 #include "../SDL_sysvideo.h"
    27 
    28 #include <fcntl.h>
    29 #include <unistd.h>
    30 #include <poll.h>
    31 #include <xf86drm.h>
    32 #include <xf86drmMode.h>
    33 #include <gbm.h>
    34 #if SDL_VIDEO_OPENGL_EGL
    35 #include <EGL/egl.h>
    36 #endif
    37 
    38 typedef struct SDL_VideoData
    39 {
    40     int devindex;               /* device index that was passed on creation */
    41     int drm_fd;                 /* DRM file desc */
    42     struct gbm_device *gbm;
    43     drmEventContext drm_evctx;  /* DRM event context */
    44     struct pollfd drm_pollfd;   /* pollfd containing DRM file desc */
    45     drmModeCrtc *saved_crtc;    /* Saved CRTC to restore on quit */
    46     uint32_t saved_conn_id;     /* Saved DRM connector ID */
    47 } SDL_VideoData;
    48 
    49 
    50 typedef struct SDL_DisplayData
    51 {
    52     uint32_t encoder_id;
    53     uint32_t crtc_id;
    54     drmModeModeInfo cur_mode;
    55 } SDL_DisplayData;
    56 
    57 
    58 typedef struct SDL_WindowData
    59 {
    60     struct gbm_surface *gs;
    61     struct gbm_bo *locked_bo;
    62     SDL_bool waiting_for_flip;
    63 #if SDL_VIDEO_OPENGL_EGL
    64     EGLSurface egl_surface;
    65 #endif
    66 } SDL_WindowData;
    67 
    68 typedef struct KMSDRM_FBInfo
    69 {
    70     int drm_fd;         /* DRM file desc */
    71     uint32_t fb_id;     /* DRM framebuffer ID */
    72 } KMSDRM_FBInfo;
    73 
    74 /* Helper functions */
    75 KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
    76 SDL_bool KMSDRM_WaitPageFlip(_THIS, SDL_WindowData *wdata, int timeout);
    77 
    78 /****************************************************************************/
    79 /* SDL_VideoDevice functions declaration                                    */
    80 /****************************************************************************/
    81 
    82 /* Display and window functions */
    83 int KMSDRM_VideoInit(_THIS);
    84 void KMSDRM_VideoQuit(_THIS);
    85 void KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
    86 int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
    87 int KMSDRM_CreateWindow(_THIS, SDL_Window * window);
    88 int KMSDRM_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
    89 void KMSDRM_SetWindowTitle(_THIS, SDL_Window * window);
    90 void KMSDRM_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
    91 void KMSDRM_SetWindowPosition(_THIS, SDL_Window * window);
    92 void KMSDRM_SetWindowSize(_THIS, SDL_Window * window);
    93 void KMSDRM_ShowWindow(_THIS, SDL_Window * window);
    94 void KMSDRM_HideWindow(_THIS, SDL_Window * window);
    95 void KMSDRM_RaiseWindow(_THIS, SDL_Window * window);
    96 void KMSDRM_MaximizeWindow(_THIS, SDL_Window * window);
    97 void KMSDRM_MinimizeWindow(_THIS, SDL_Window * window);
    98 void KMSDRM_RestoreWindow(_THIS, SDL_Window * window);
    99 void KMSDRM_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
   100 void KMSDRM_DestroyWindow(_THIS, SDL_Window * window);
   101 
   102 /* Window manager function */
   103 SDL_bool KMSDRM_GetWindowWMInfo(_THIS, SDL_Window * window,
   104                              struct SDL_SysWMinfo *info);
   105 
   106 /* OpenGL/OpenGL ES functions */
   107 int KMSDRM_GLES_LoadLibrary(_THIS, const char *path);
   108 void *KMSDRM_GLES_GetProcAddress(_THIS, const char *proc);
   109 void KMSDRM_GLES_UnloadLibrary(_THIS);
   110 SDL_GLContext KMSDRM_GLES_CreateContext(_THIS, SDL_Window * window);
   111 int KMSDRM_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
   112 int KMSDRM_GLES_SetSwapInterval(_THIS, int interval);
   113 int KMSDRM_GLES_GetSwapInterval(_THIS);
   114 int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window);
   115 void KMSDRM_GLES_DeleteContext(_THIS, SDL_GLContext context);
   116 
   117 #endif /* __SDL_KMSDRMVIDEO_H__ */
   118 
   119 /* vi: set ts=4 sw=4 expandtab: */