SDL  2.0
SDL_kmsdrmvideo.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4  Atomic KMSDRM backend by Manuel Alfayate Corchete <redwindwanderer@gmail.com>
5 
6  This software is provided 'as-is', without any express or implied
7  warranty. In no event will the authors be held liable for any damages
8  arising from the use of this software.
9 
10  Permission is granted to anyone to use this software for any purpose,
11  including commercial applications, and to alter it and redistribute it
12  freely, subject to the following restrictions:
13 
14  1. The origin of this software must not be misrepresented; you must not
15  claim that you wrote the original software. If you use this software
16  in a product, an acknowledgment in the product documentation would be
17  appreciated but is not required.
18  2. Altered source versions must be plainly marked as such, and must not be
19  misrepresented as being the original software.
20  3. This notice may not be removed or altered from any source distribution.
21 */
22 
23 #include "../../SDL_internal.h"
24 
25 #ifndef __SDL_KMSDRMVIDEO_H__
26 #define __SDL_KMSDRMVIDEO_H__
27 
28 #include "../SDL_sysvideo.h"
29 
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <xf86drm.h>
33 #include <xf86drmMode.h>
34 
35 #include <gbm.h>
36 #include <assert.h>
37 #if SDL_VIDEO_OPENGL_EGL
38 #include <EGL/egl.h>
39 #include <EGL/eglext.h>
40 #endif
41 
42 /****************************************************************************************/
43 /* Driverdata pointers are void struct* used to store backend-specific variables */
44 /* and info that supports the SDL-side structs like SDL Display Devices, SDL_Windows... */
45 /* which need to be "supported" with backend-side info and mechanisms to work. */
46 /****************************************************************************************/
47 
48 typedef struct SDL_VideoData
49 {
50  int devindex; /* device index that was passed on creation */
51  int drm_fd; /* DRM file desc */
52  char devpath[32]; /* DRM dev path. */
53 
54  struct gbm_device *gbm_dev;
55 
57  unsigned int max_windows;
58  unsigned int num_windows;
59 
60  SDL_bool video_init; /* Has VideoInit succeeded? */
61 
63 
64 typedef struct plane {
65  drmModePlane *plane;
66  drmModeObjectProperties *props;
67  drmModePropertyRes **props_info;
68 } plane;
69 
70 typedef struct crtc {
71  drmModeCrtc *crtc;
72  drmModeObjectProperties *props;
73  drmModePropertyRes **props_info;
74 } crtc;
75 
76 typedef struct connector {
77  drmModeConnector *connector;
78  drmModeObjectProperties *props;
79  drmModePropertyRes **props_info;
80 } connector;
81 
82 /* More general driverdata info that gives support and substance to the SDL_Display. */
83 typedef struct SDL_DisplayData
84 {
85  drmModeModeInfo mode;
86  drmModeModeInfo preferred_mode;
88 
93 
94  /* Central atomic request list, used for the prop
95  changeset related to pageflip in SwapWindow. */
96  drmModeAtomicReq *atomic_req;
97 
100 
103 
104 #if SDL_VIDEO_OPENGL_EGL
105  EGLSurface old_egl_surface;
106 #endif
107 
110 
111  /* DRM & GBM cursor stuff lives here, not in an SDL_Cursor's driverdata struct,
112  because setting/unsetting up these is done on window creation/destruction,
113  where we may not have an SDL_Cursor at all (so no SDL_Cursor driverdata).
114  There's only one cursor GBM BO because we only support one cursor. */
115  struct gbm_bo *cursor_bo;
117 
119 
120 /* Driverdata info that gives KMSDRM-side support and substance to the SDL_Window. */
121 typedef struct SDL_WindowData
122 {
124  /* SDL internals expect EGL surface to be here, and in KMSDRM the GBM surface is
125  what supports the EGL surface on the driver side, so all these surfaces and buffers
126  are expected to be here, in the struct pointed by SDL_Window driverdata pointer:
127  this one. So don't try to move these to dispdata! */
128  struct gbm_surface *gs;
129  struct gbm_bo *bo;
130  struct gbm_bo *next_bo;
131 
132 #if SDL_VIDEO_OPENGL_EGL
134 #endif
135 
136  /* For scaling and AR correction. */
142 
143  /* This dictates what approach we'll use for SwapBuffers. */
145 
147 
148 typedef struct SDL_DisplayModeData
149 {
152 
153 typedef struct KMSDRM_FBInfo
154 {
155  int drm_fd; /* DRM file desc */
156  uint32_t fb_id; /* DRM framebuffer ID */
157 } KMSDRM_FBInfo;
158 
159 typedef struct KMSDRM_PlaneInfo
160 {
161  struct plane *plane;
173 
174 /* Helper functions */
176 KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
177 
178 /* Atomic functions that are used from SDL_kmsdrmopengles.c and SDL_kmsdrmmouse.c */
180 
183 int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
184  const char *name, uint64_t value);
185 int add_crtc_property(drmModeAtomicReq *req, struct crtc *crtc,
186  const char *name, uint64_t value);
187 int add_connector_property(drmModeAtomicReq *req, struct connector *connector,
188  const char *name, uint64_t value);
189 int setup_plane(_THIS, struct plane **plane, uint32_t plane_type);
190 void free_plane(struct plane **plane);
191 
192 /****************************************************************************/
193 /* SDL_VideoDevice functions declaration */
194 /****************************************************************************/
195 
196 /* Display and window functions */
216 
217 /* Window manager function */
219  struct SDL_SysWMinfo *info);
220 
221 /* OpenGL/OpenGL ES functions */
223 void *KMSDRM_GLES_GetProcAddress(_THIS, const char *proc);
231 
232 #endif /* __SDL_KMSDRMVIDEO_H__ */
233 
234 /* vi: set ts=4 sw=4 expandtab: */
#define _THIS
unsigned int uint32_t
unsigned long long uint64_t
signed int int32_t
void KMSDRM_RaiseWindow(_THIS, SDL_Window *window)
int KMSDRM_GLES_SetSwapInterval(_THIS, int interval)
int setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
void KMSDRM_RestoreWindow(_THIS, SDL_Window *window)
int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
void KMSDRM_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
void KMSDRM_ShowWindow(_THIS, SDL_Window *window)
int KMSDRM_GLES_LoadLibrary(_THIS, const char *path)
int KMSDRM_CreateEGLSurface(_THIS, SDL_Window *window)
void KMSDRM_MaximizeWindow(_THIS, SDL_Window *window)
int drm_atomic_commit(_THIS, SDL_bool blocking)
int KMSDRM_CreateWindow(_THIS, SDL_Window *window)
void KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
void KMSDRM_SetWindowSize(_THIS, SDL_Window *window)
int add_crtc_property(drmModeAtomicReq *req, struct crtc *crtc, const char *name, uint64_t value)
void KMSDRM_SetWindowPosition(_THIS, SDL_Window *window)
void * KMSDRM_GLES_GetProcAddress(_THIS, const char *proc)
void KMSDRM_GLES_DeleteContext(_THIS, SDL_GLContext context)
void drm_atomic_waitpending(_THIS)
void KMSDRM_HideWindow(_THIS, SDL_Window *window)
void KMSDRM_MinimizeWindow(_THIS, SDL_Window *window)
void KMSDRM_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
void KMSDRM_VideoQuit(_THIS)
int KMSDRM_VideoInit(_THIS)
void KMSDRM_SetWindowTitle(_THIS, SDL_Window *window)
SDL_bool KMSDRM_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
int KMSDRM_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
SDL_GLContext KMSDRM_GLES_CreateContext(_THIS, SDL_Window *window)
void drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info)
void KMSDRM_SetWindowFullscreen(_THIS, SDL_Window *window, SDL_VideoDisplay *_display, SDL_bool fullscreen)
void KMSDRM_GLES_UnloadLibrary(_THIS)
int add_plane_property(drmModeAtomicReq *req, struct plane *plane, const char *name, uint64_t value)
int KMSDRM_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
int add_connector_property(drmModeAtomicReq *req, struct connector *connector, const char *name, uint64_t value)
KMSDRM_FBInfo * KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
int KMSDRM_GLES_GetSwapInterval(_THIS)
void free_plane(struct plane **plane)
int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window *window)
void KMSDRM_DestroyWindow(_THIS, SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
GLenum mode
GLuint const GLchar * name
GLsizei const GLchar *const * path
GLsizei const GLfloat * value
SDL_bool
Definition: SDL_stdinc.h:168
void * SDL_GLContext
An opaque handle to an OpenGL context.
Definition: SDL_video.h:195
void * EGLSurface
Definition: egl.h:59
void * EGLSyncKHR
Definition: eglext.h:61
EGLSurface EGLNativeWindowType * window
Definition: eglext.h:1025
struct plane * plane
EGLSyncKHR gpu_fence
drmModeModeInfo mode
drmModeAtomicReq * atomic_req
EGLSyncKHR kms_fence
drmModeModeInfo preferred_mode
connector * connector
uint32_t atomic_flags
SDL_bool modeset_pending
struct gbm_bo * cursor_bo
The structure that defines a display mode.
Definition: SDL_video.h:54
A collection of pixels used in software blitting.
Definition: SDL_surface.h:71
unsigned int max_windows
SDL_Window ** windows
unsigned int num_windows
SDL_bool video_init
struct gbm_device * gbm_dev
char devpath[32]
int(* swap_window)(_THIS, SDL_Window *window)
SDL_Window * window
EGLSurface egl_surface
struct gbm_bo * next_bo
SDL_VideoData * viddata
struct gbm_bo * bo
struct gbm_surface * gs
The type used to identify a window.
Definition: SDL_sysvideo.h:75
drmModePropertyRes ** props_info
drmModeConnector * connector
drmModeObjectProperties * props
drmModeObjectProperties * props
drmModePropertyRes ** props_info
drmModeCrtc * crtc
drmModeObjectProperties * props
drmModePlane * plane
drmModePropertyRes ** props_info
static screen_context_t context
Definition: video.c:25
typedef int(__stdcall *FARPROC)()