Atlas - SDL_kmsdrmvideo.h
Home / ext / SDL / src / video / kmsdrm Lines: 1 | Size: 8456 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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// Atomic KMSDRM backend originally written by Manuel Alfayate Corchete <[email protected]> 23 24#include "SDL_internal.h" 25 26#ifndef SDL_kmsdrmvideo_h 27#define SDL_kmsdrmvideo_h 28 29#include "../SDL_sysvideo.h" 30 31#include <fcntl.h> 32#include <unistd.h> 33#include <xf86drm.h> 34#include <xf86drmMode.h> 35#include <gbm.h> 36#include <EGL/egl.h> 37#include <EGL/eglext.h> 38 39#ifndef DRM_FORMAT_MOD_INVALID 40#define DRM_FORMAT_MOD_INVALID 0x00ffffffffffffffULL 41#endif 42 43#ifndef DRM_MODE_FB_MODIFIERS 44#define DRM_MODE_FB_MODIFIERS 2 45#endif 46 47#ifndef DRM_MODE_PAGE_FLIP_ASYNC 48#define DRM_MODE_PAGE_FLIP_ASYNC 2 49#endif 50 51#ifndef DRM_MODE_OBJECT_CONNECTOR 52#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0 53#endif 54 55#ifndef DRM_MODE_OBJECT_CRTC 56#define DRM_MODE_OBJECT_CRTC 0xcccccccc 57#endif 58 59#ifndef DRM_CAP_ASYNC_PAGE_FLIP 60#define DRM_CAP_ASYNC_PAGE_FLIP 7 61#endif 62 63#ifndef DRM_CAP_CURSOR_WIDTH 64#define DRM_CAP_CURSOR_WIDTH 8 65#endif 66 67#ifndef DRM_CAP_CURSOR_HEIGHT 68#define DRM_CAP_CURSOR_HEIGHT 9 69#endif 70 71#ifndef GBM_FORMAT_ARGB8888 72#define GBM_FORMAT_ARGB8888 ((uint32_t)('A') | ((uint32_t)('R') << 8) | ((uint32_t)('2') << 16) | ((uint32_t)('4') << 24)) 73#define GBM_BO_USE_CURSOR (1 << 1) 74#define GBM_BO_USE_WRITE (1 << 3) 75#define GBM_BO_USE_LINEAR (1 << 4) 76#endif 77 78typedef struct KMSDRM_plane 79{ 80 drmModePlane *plane; 81 drmModeObjectProperties *props; 82 drmModePropertyRes **props_info; 83} KMSDRM_plane; 84 85typedef struct KMSDRM_crtc 86{ 87 drmModeCrtc *crtc; 88 drmModeObjectProperties *props; 89 drmModePropertyRes **props_info; 90} KMSDRM_crtc; 91 92typedef struct KMSDRM_connector 93{ 94 drmModeConnector *connector; 95 drmModeObjectProperties *props; 96 drmModePropertyRes **props_info; 97} KMSDRM_connector; 98 99struct SDL_VideoData 100{ 101 int devindex; // device index that was passed on creation 102 int drm_fd; // DRM file desc 103 char devpath[32]; // DRM dev path. 104 105 struct gbm_device *gbm_dev; 106 107 bool video_init; // Has VideoInit succeeded? 108 bool vulkan_mode; // Are we in Vulkan mode? One VK window is enough to be. 109 bool async_pageflip_support; // Does the hardware support async. pageflips? 110 111 SDL_Window **windows; 112 int max_windows; 113 int num_windows; 114 115 /* Even if we have several displays, we only have to 116 open 1 FD and create 1 gbm device. */ 117 bool gbm_init; 118 119 bool is_atomic; // true if atomic interfaces are supported. 120}; 121 122struct SDL_DisplayModeData 123{ 124 int mode_index; 125}; 126 127struct SDL_DisplayData 128{ 129 KMSDRM_plane *display_plane; 130 KMSDRM_plane *cursor_plane; 131 KMSDRM_crtc crtc; 132 KMSDRM_connector connector; 133 134 drmModeModeInfo mode; 135 drmModeModeInfo original_mode; 136 drmModeModeInfo fullscreen_mode; 137 138 drmModeCrtc *saved_crtc; // CRTC to restore on quit 139 bool saved_vrr; 140 141 /* DRM & GBM cursor stuff lives here, not in an SDL_Cursor's internal struct, 142 because setting/unsetting up these is done on window creation/destruction, 143 where we may not have an SDL_Cursor at all (so no SDL_Cursor internal). 144 There's only one cursor GBM BO because we only support one cursor. */ 145 struct gbm_bo *cursor_bo; 146 int cursor_bo_drm_fd; 147 uint64_t cursor_w, cursor_h; 148 149 /* Central atomic request list, used for the prop 150 changeset related to pageflip in SwapWindow. */ 151 drmModeAtomicReq *atomic_req; 152 153 int kms_in_fence_fd; 154 int kms_out_fence_fd; 155 EGLSyncKHR kms_fence; 156 EGLSyncKHR gpu_fence; 157 158 bool default_cursor_init; 159}; 160 161struct SDL_WindowData 162{ 163 SDL_VideoData *viddata; 164 /* SDL internals expect EGL surface to be here, and in KMSDRM the GBM surface is 165 what supports the EGL surface on the driver side, so all these surfaces and buffers 166 are expected to be here, in the struct pointed by SDL_Window internal pointer: 167 this one. So don't try to move these to dispdata! */ 168 struct gbm_surface *gs; 169 struct gbm_bo *bo; 170 struct gbm_bo *next_bo; 171 172 bool waiting_for_flip; 173 bool double_buffer; 174 175 EGLSurface egl_surface; 176 bool egl_surface_dirty; 177 178 /* This dictates what approach we'll use for SwapBuffers. */ 179 bool (*swap_window)(SDL_VideoDevice *_this, SDL_Window *window); 180}; 181 182typedef struct KMSDRM_FBInfo 183{ 184 int drm_fd; // DRM file desc 185 uint32_t fb_id; // DRM framebuffer ID 186} KMSDRM_FBInfo; 187 188typedef struct KMSDRM_PlaneInfo 189{ 190 struct KMSDRM_plane *plane; 191 uint32_t fb_id; 192 uint32_t crtc_id; 193 int32_t src_x; 194 int32_t src_y; 195 int32_t src_w; 196 int32_t src_h; 197 int32_t crtc_x; 198 int32_t crtc_y; 199 int32_t crtc_w; 200 int32_t crtc_h; 201} KMSDRM_PlaneInfo; 202 203// Helper functions 204extern bool KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window); 205extern KMSDRM_FBInfo *KMSDRM_FBFromBO(SDL_VideoDevice *_this, struct gbm_bo *bo); 206extern KMSDRM_FBInfo *KMSDRM_FBFromBO2(SDL_VideoDevice *_this, struct gbm_bo *bo, int w, int h); 207extern bool KMSDRM_WaitPageflip(SDL_VideoDevice *_this, SDL_WindowData *windata); 208 209// Atomic functions that are used from SDL_kmsdrmopengles.c and SDL_kmsdrmmouse.c 210void drm_atomic_set_plane_props(SDL_DisplayData *dispdata, struct KMSDRM_PlaneInfo *info); 211void drm_atomic_waitpending(SDL_VideoDevice *_this, SDL_DisplayData *dispdata); 212int drm_atomic_commit(SDL_VideoDevice *_this, SDL_DisplayData *dispdata, bool blocking, bool allow_modeset); 213int add_plane_property(drmModeAtomicReq *req, struct KMSDRM_plane *plane, const char *name, uint64_t value); 214int add_crtc_property(drmModeAtomicReq *req, struct KMSDRM_crtc *crtc, const char *name, uint64_t value); 215int add_connector_property(drmModeAtomicReq *req, struct KMSDRM_connector *connector, const char *name, uint64_t value); 216bool setup_plane(SDL_VideoDevice *_this, SDL_DisplayData *dispdata, struct KMSDRM_plane **plane, uint32_t plane_type); 217void free_plane(struct KMSDRM_plane **plane); 218 219/****************************************************************************/ 220// SDL_VideoDevice functions declaration 221/****************************************************************************/ 222 223// Display and window functions 224extern bool KMSDRM_VideoInit(SDL_VideoDevice *_this); 225extern void KMSDRM_VideoQuit(SDL_VideoDevice *_this); 226extern bool KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); 227extern bool KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); 228extern bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); 229extern void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); 230extern bool KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); 231extern void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); 232extern SDL_FullscreenResult KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen); 233extern void KMSDRM_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); 234extern void KMSDRM_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); 235extern void KMSDRM_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); 236extern void KMSDRM_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); 237extern void KMSDRM_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); 238extern void KMSDRM_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); 239extern void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); 240extern bool KMSDRM_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); 241 242#endif // SDL_kmsdrmvideo_h 243[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.