author Sam Lantinga <>
Wed, 02 Aug 2017 10:22:48 -0700
changeset 11175 cbc6a8a5b701
child 11811 5d94cb6b24d3
permissions -rw-r--r--
Fixed bug 3690 - SDL2 KMS/DRM render context support


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:

$./configure --enable-video-kmsdrm
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2016 Sam Lantinga <>
     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.
     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:
    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 */
    22 /* *INDENT-OFF* */
    24 #ifndef SDL_KMSDRM_MODULE
    25 #define SDL_KMSDRM_MODULE(modname)
    26 #endif
    28 #ifndef SDL_KMSDRM_SYM
    29 #define SDL_KMSDRM_SYM(rc,fn,params)
    30 #endif
    32 #ifndef SDL_KMSDRM_SYM_CONST
    33 #define SDL_KMSDRM_SYM_CONST(type, name)
    34 #endif
    38 SDL_KMSDRM_SYM(void,drmModeFreeResources,(drmModeResPtr ptr))
    39 SDL_KMSDRM_SYM(void,drmModeFreeFB,(drmModeFBPtr ptr))
    40 SDL_KMSDRM_SYM(void,drmModeFreeCrtc,(drmModeCrtcPtr ptr))
    41 SDL_KMSDRM_SYM(void,drmModeFreeConnector,(drmModeConnectorPtr ptr))
    42 SDL_KMSDRM_SYM(void,drmModeFreeEncoder,(drmModeEncoderPtr ptr))
    43 SDL_KMSDRM_SYM(drmModeResPtr,drmModeGetResources,(int fd))
    44 SDL_KMSDRM_SYM(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_t depth,
    45                                  uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
    46                                  uint32_t *buf_id))
    47 SDL_KMSDRM_SYM(int,drmModeRmFB,(int fd, uint32_t bufferId))
    48 SDL_KMSDRM_SYM(drmModeFBPtr,drmModeGetFB,(int fd, uint32_t buf))
    49 SDL_KMSDRM_SYM(drmModeCrtcPtr,drmModeGetCrtc,(int fd, uint32_t crtcId))
    50 SDL_KMSDRM_SYM(int,drmModeSetCrtc,(int fd, uint32_t crtcId, uint32_t bufferId,
    51                                    uint32_t x, uint32_t y, uint32_t *connectors, int count,
    52                                    drmModeModeInfoPtr mode))
    53 SDL_KMSDRM_SYM(int,drmModeSetCursor,(int fd, uint32_t crtcId, uint32_t bo_handle,
    54                                      uint32_t width, uint32_t height))
    55 SDL_KMSDRM_SYM(int,drmModeSetCursor2,(int fd, uint32_t crtcId, uint32_t bo_handle,
    56                                       uint32_t width, uint32_t height,
    57                                       int32_t hot_x, int32_t hot_y))
    58 SDL_KMSDRM_SYM(int,drmModeMoveCursor,(int fd, uint32_t crtcId, int x, int y))
    59 SDL_KMSDRM_SYM(drmModeEncoderPtr,drmModeGetEncoder,(int fd, uint32_t encoder_id))
    60 SDL_KMSDRM_SYM(drmModeConnectorPtr,drmModeGetConnector,(int fd, uint32_t connector_id))
    61 SDL_KMSDRM_SYM(int,drmHandleEvent,(int fd,drmEventContextPtr evctx))
    62 SDL_KMSDRM_SYM(int,drmModePageFlip,(int fd, uint32_t crtc_id, uint32_t fb_id,
    63                                     uint32_t flags, void *user_data))
    67 SDL_KMSDRM_SYM(int,gbm_device_get_fd,(struct gbm_device *gbm))
    68 SDL_KMSDRM_SYM(int,gbm_device_is_format_supported,(struct gbm_device *gbm,
    69                                                    uint32_t format, uint32_t usage))
    70 SDL_KMSDRM_SYM(void,gbm_device_destroy,(struct gbm_device *gbm))
    71 SDL_KMSDRM_SYM(struct gbm_device *,gbm_create_device,(int fd))
    72 SDL_KMSDRM_SYM(unsigned int,gbm_bo_get_width,(struct gbm_bo *bo))
    73 SDL_KMSDRM_SYM(unsigned int,gbm_bo_get_height,(struct gbm_bo *bo))
    74 SDL_KMSDRM_SYM(uint32_t,gbm_bo_get_stride,(struct gbm_bo *bo))
    75 SDL_KMSDRM_SYM(union gbm_bo_handle,gbm_bo_get_handle,(struct gbm_bo *bo))
    76 SDL_KMSDRM_SYM(int,gbm_bo_write,(struct gbm_bo *bo, const void *buf, size_t count))
    77 SDL_KMSDRM_SYM(struct gbm_device *,gbm_bo_get_device,(struct gbm_bo *bo))
    78 SDL_KMSDRM_SYM(void,gbm_bo_set_user_data,(struct gbm_bo *bo, void *data,
    79                                           void (*destroy_user_data)(struct gbm_bo *, void *)))
    80 SDL_KMSDRM_SYM(void *,gbm_bo_get_user_data,(struct gbm_bo *bo))
    81 SDL_KMSDRM_SYM(void,gbm_bo_destroy,(struct gbm_bo *bo))
    82 SDL_KMSDRM_SYM(struct gbm_bo *,gbm_bo_create,(struct gbm_device *gbm,
    83                                               uint32_t width, uint32_t height,
    84                                               uint32_t format, uint32_t usage))
    85 SDL_KMSDRM_SYM(struct gbm_surface *,gbm_surface_create,(struct gbm_device *gbm,
    86                                                         uint32_t width, uint32_t height,
    87                                                         uint32_t format, uint32_t flags))
    88 SDL_KMSDRM_SYM(void,gbm_surface_destroy,(struct gbm_surface *surf))
    89 SDL_KMSDRM_SYM(struct gbm_bo *,gbm_surface_lock_front_buffer,(struct gbm_surface *surf))
    90 SDL_KMSDRM_SYM(void,gbm_surface_release_buffer,(struct gbm_surface *surf, struct gbm_bo *bo))
    93 #undef SDL_KMSDRM_MODULE
    94 #undef SDL_KMSDRM_SYM
    95 #undef SDL_KMSDRM_SYM_CONST
    97 /* *INDENT-ON* */
    99 /* vi: set ts=4 sw=4 expandtab: */