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
slouken@11175
     1
/*
slouken@11175
     2
  Simple DirectMedia Layer
slouken@11175
     3
  Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
slouken@11175
     4
slouken@11175
     5
  This software is provided 'as-is', without any express or implied
slouken@11175
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@11175
     7
  arising from the use of this software.
slouken@11175
     8
slouken@11175
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@11175
    10
  including commercial applications, and to alter it and redistribute it
slouken@11175
    11
  freely, subject to the following restrictions:
slouken@11175
    12
slouken@11175
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@11175
    14
     claim that you wrote the original software. If you use this software
slouken@11175
    15
     in a product, an acknowledgment in the product documentation would be
slouken@11175
    16
     appreciated but is not required.
slouken@11175
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@11175
    18
     misrepresented as being the original software.
slouken@11175
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@11175
    20
*/
slouken@11175
    21
slouken@11175
    22
#ifndef __SDL_KMSDRMVIDEO_H__
slouken@11175
    23
#define __SDL_KMSDRMVIDEO_H__
slouken@11175
    24
slouken@11175
    25
#include "../../SDL_internal.h"
slouken@11175
    26
#include "../SDL_sysvideo.h"
slouken@11175
    27
slouken@11175
    28
#include <fcntl.h>
slouken@11175
    29
#include <unistd.h>
slouken@11175
    30
#include <poll.h>
slouken@11175
    31
#include <xf86drm.h>
slouken@11175
    32
#include <xf86drmMode.h>
slouken@11175
    33
#include <gbm.h>
slouken@11175
    34
#if SDL_VIDEO_OPENGL_EGL
slouken@11175
    35
#include <EGL/egl.h>
slouken@11175
    36
#endif
slouken@11175
    37
slouken@11175
    38
typedef struct SDL_VideoData
slouken@11175
    39
{
slouken@11175
    40
    int devindex;               /* device index that was passed on creation */
slouken@11175
    41
    int drm_fd;                 /* DRM file desc */
slouken@11175
    42
    struct gbm_device *gbm;
slouken@11175
    43
    drmEventContext drm_evctx;  /* DRM event context */
slouken@11175
    44
    struct pollfd drm_pollfd;   /* pollfd containing DRM file desc */
slouken@11175
    45
    drmModeCrtc *saved_crtc;    /* Saved CRTC to restore on quit */
slouken@11175
    46
    uint32_t saved_conn_id;     /* Saved DRM connector ID */
slouken@11175
    47
} SDL_VideoData;
slouken@11175
    48
slouken@11175
    49
slouken@11175
    50
typedef struct SDL_DisplayData
slouken@11175
    51
{
slouken@11175
    52
    uint32_t encoder_id;
slouken@11175
    53
    uint32_t crtc_id;
slouken@11175
    54
    drmModeModeInfo cur_mode;
slouken@11175
    55
} SDL_DisplayData;
slouken@11175
    56
slouken@11175
    57
slouken@11175
    58
typedef struct SDL_WindowData
slouken@11175
    59
{
slouken@11175
    60
    struct gbm_surface *gs;
slouken@11175
    61
    struct gbm_bo *locked_bo;
slouken@11175
    62
    SDL_bool waiting_for_flip;
slouken@11175
    63
#if SDL_VIDEO_OPENGL_EGL
slouken@11175
    64
    EGLSurface egl_surface;
slouken@11175
    65
#endif
slouken@11175
    66
} SDL_WindowData;
slouken@11175
    67
slouken@11175
    68
typedef struct KMSDRM_FBInfo
slouken@11175
    69
{
slouken@11175
    70
    int drm_fd;         /* DRM file desc */
slouken@11175
    71
    uint32_t fb_id;     /* DRM framebuffer ID */
slouken@11175
    72
} KMSDRM_FBInfo;
slouken@11175
    73
slouken@11175
    74
/* Helper functions */
slouken@11175
    75
KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
slouken@11175
    76
SDL_bool KMSDRM_WaitPageFlip(_THIS, SDL_WindowData *wdata, int timeout);
slouken@11175
    77
slouken@11175
    78
/****************************************************************************/
slouken@11175
    79
/* SDL_VideoDevice functions declaration                                    */
slouken@11175
    80
/****************************************************************************/
slouken@11175
    81
slouken@11175
    82
/* Display and window functions */
slouken@11175
    83
int KMSDRM_VideoInit(_THIS);
slouken@11175
    84
void KMSDRM_VideoQuit(_THIS);
slouken@11175
    85
void KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay * display);
slouken@11175
    86
int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
slouken@11175
    87
int KMSDRM_CreateWindow(_THIS, SDL_Window * window);
slouken@11175
    88
int KMSDRM_CreateWindowFrom(_THIS, SDL_Window * window, const void *data);
slouken@11175
    89
void KMSDRM_SetWindowTitle(_THIS, SDL_Window * window);
slouken@11175
    90
void KMSDRM_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
slouken@11175
    91
void KMSDRM_SetWindowPosition(_THIS, SDL_Window * window);
slouken@11175
    92
void KMSDRM_SetWindowSize(_THIS, SDL_Window * window);
slouken@11175
    93
void KMSDRM_ShowWindow(_THIS, SDL_Window * window);
slouken@11175
    94
void KMSDRM_HideWindow(_THIS, SDL_Window * window);
slouken@11175
    95
void KMSDRM_RaiseWindow(_THIS, SDL_Window * window);
slouken@11175
    96
void KMSDRM_MaximizeWindow(_THIS, SDL_Window * window);
slouken@11175
    97
void KMSDRM_MinimizeWindow(_THIS, SDL_Window * window);
slouken@11175
    98
void KMSDRM_RestoreWindow(_THIS, SDL_Window * window);
slouken@11175
    99
void KMSDRM_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
slouken@11175
   100
void KMSDRM_DestroyWindow(_THIS, SDL_Window * window);
slouken@11175
   101
slouken@11175
   102
/* Window manager function */
slouken@11175
   103
SDL_bool KMSDRM_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@11175
   104
                             struct SDL_SysWMinfo *info);
slouken@11175
   105
slouken@11175
   106
/* OpenGL/OpenGL ES functions */
slouken@11175
   107
int KMSDRM_GLES_LoadLibrary(_THIS, const char *path);
slouken@11175
   108
void *KMSDRM_GLES_GetProcAddress(_THIS, const char *proc);
slouken@11175
   109
void KMSDRM_GLES_UnloadLibrary(_THIS);
slouken@11175
   110
SDL_GLContext KMSDRM_GLES_CreateContext(_THIS, SDL_Window * window);
slouken@11175
   111
int KMSDRM_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
slouken@11175
   112
int KMSDRM_GLES_SetSwapInterval(_THIS, int interval);
slouken@11175
   113
int KMSDRM_GLES_GetSwapInterval(_THIS);
slouken@11175
   114
int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window);
slouken@11175
   115
void KMSDRM_GLES_DeleteContext(_THIS, SDL_GLContext context);
slouken@11175
   116
slouken@11175
   117
#endif /* __SDL_KMSDRMVIDEO_H__ */
slouken@11175
   118
slouken@11175
   119
/* vi: set ts=4 sw=4 expandtab: */