Go to the documentation of this file.
22 #include "../../SDL_internal.h"
24 #if SDL_VIDEO_DRIVER_KMSDRM
27 #include "../SDL_sysvideo.h"
31 #include "../../events/SDL_events_c.h"
32 #include "../../events/SDL_mouse_c.h"
33 #include "../../events/SDL_keyboard_c.h"
35 #ifdef SDL_INPUT_LINUXEV
36 #include "../../core/linux/SDL_evdev.h"
50 #define KMSDRM_DRI_PATH "/dev/dri/"
53 check_modestting(
int devindex)
61 drm_fd = open(
device, O_RDWR | O_CLOEXEC);
64 drmModeRes *resources = KMSDRM_drmModeGetResources(drm_fd);
67 KMSDRM_DRI_PATH, devindex,
68 resources->count_connectors, resources->count_encoders, resources->count_crtcs);
70 if (resources->count_connectors > 0 && resources->count_encoders > 0 && resources->count_crtcs > 0) {
73 KMSDRM_drmModeFreeResources(resources);
83 static int get_dricount(
void)
90 if (!(stat(KMSDRM_DRI_PATH, &sb) == 0
91 && S_ISDIR(sb.st_mode))) {
92 printf(
"The path %s cannot be opened or is not available\n",
97 if (
access(KMSDRM_DRI_PATH, F_OK) == -1) {
98 printf(
"The path %s cannot be opened\n",
103 folder = opendir(KMSDRM_DRI_PATH);
105 while ((
res = readdir(folder))) {
120 const int devcount = get_dricount();
123 for (
i = 0;
i < devcount;
i++) {
124 if (check_modestting(
i)) {
133 KMSDRM_Available(
void)
137 ret = get_driindex();
158 KMSDRM_CreateDevice(
int devindex)
163 if (!devindex || (devindex > 99)) {
164 devindex = get_driindex();
168 SDL_SetError(
"devindex (%d) must be between 0 and 99.\n", devindex);
190 device->driverdata = viddata;
212 #if SDL_VIDEO_OPENGL_EGL
224 device->free = KMSDRM_DeleteDevice;
238 "KMS/DRM Video Driver",
245 KMSDRM_FBDestroyCallback(
struct gbm_bo *bo,
void *
data)
249 if (fb_info && fb_info->
drm_fd >= 0 && fb_info->
fb_id != 0) {
250 KMSDRM_drmModeRmFB(fb_info->
drm_fd, fb_info->
fb_id);
284 w = KMSDRM_gbm_bo_get_width(bo);
285 h = KMSDRM_gbm_bo_get_height(bo);
286 stride = KMSDRM_gbm_bo_get_stride(bo);
287 handle = KMSDRM_gbm_bo_get_handle(bo).u32;
299 KMSDRM_gbm_bo_set_user_data(bo, fb_info, KMSDRM_FBDestroyCallback);
305 KMSDRM_FlipHandler(
int fd,
unsigned int frame,
unsigned int sec,
unsigned int usec,
void *
data)
313 drmEventContext ev = {0};
314 struct pollfd pfd = {0};
316 ev.version = DRM_EVENT_CONTEXT_VERSION;
317 ev.page_flip_handler = KMSDRM_FlipHandler;
325 if (poll(&pfd, 1,
timeout) < 0) {
330 if (pfd.revents & (POLLHUP | POLLERR)) {
335 if (pfd.revents & POLLIN) {
337 KMSDRM_drmHandleEvent(viddata->
drm_fd, &ev);
360 KMSDRM_gbm_surface_release_buffer(windata->
gs, windata->
curr_bo);
365 KMSDRM_gbm_surface_release_buffer(windata->
gs, windata->
next_bo);
369 #if SDL_VIDEO_OPENGL_EGL
379 KMSDRM_gbm_surface_destroy(windata->
gs);
392 Uint32 surface_fmt = GBM_FORMAT_XRGB8888;
393 Uint32 surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
396 if (!KMSDRM_gbm_device_is_format_supported(viddata->
gbm, surface_fmt, surface_flags)) {
400 #if SDL_VIDEO_OPENGL_EGL
401 SDL_EGL_SetRequiredVisualId(
_this, surface_fmt);
407 windata->
gs = KMSDRM_gbm_surface_create(viddata->
gbm,
width,
height, surface_fmt, surface_flags);
413 #if SDL_VIDEO_OPENGL_EGL
417 return SDL_SetError(
"Could not create EGL window surface");
422 windata->egl_surface_dirty = 0;
434 drmModeRes *resources =
NULL;
435 drmModeEncoder *encoder =
NULL;
451 viddata->
drm_fd = open(devname, O_RDWR | O_CLOEXEC);
453 if (viddata->
drm_fd < 0) {
460 viddata->
gbm = KMSDRM_gbm_create_device(viddata->
drm_fd);
467 resources = KMSDRM_drmModeGetResources(viddata->
drm_fd);
473 for (
int i = 0;
i < resources->count_connectors;
i++) {
474 drmModeConnector *conn = KMSDRM_drmModeGetConnector(viddata->
drm_fd, resources->connectors[
i]);
480 if (conn->connection == DRM_MODE_CONNECTED && conn->count_modes) {
482 conn->connector_id, conn->count_modes);
483 dispdata->
conn = conn;
487 KMSDRM_drmModeFreeConnector(conn);
490 if (!dispdata->
conn) {
491 ret =
SDL_SetError(
"No currently active connector found.");
496 for (
int i = 0;
i < resources->count_encoders;
i++) {
497 encoder = KMSDRM_drmModeGetEncoder(viddata->
drm_fd, resources->encoders[
i]);
503 if (encoder->encoder_id == dispdata->
conn->encoder_id) {
508 KMSDRM_drmModeFreeEncoder(encoder);
514 for (
int i = 0,
j;
i < resources->count_encoders;
i++) {
515 encoder = KMSDRM_drmModeGetEncoder(viddata->
drm_fd, resources->encoders[
i]);
521 for (
j = 0;
j < dispdata->
conn->count_encoders;
j++) {
522 if (dispdata->
conn->encoders[
j] == encoder->encoder_id) {
527 if (
j != dispdata->
conn->count_encoders) {
531 KMSDRM_drmModeFreeEncoder(encoder);
544 dispdata->
saved_crtc = KMSDRM_drmModeGetCrtc(viddata->
drm_fd, encoder->crtc_id);
548 for (
int i = 0;
i < resources->count_crtcs;
i++) {
549 if (encoder->possible_crtcs & (1 <<
i)) {
550 encoder->crtc_id = resources->crtcs[
i];
551 dispdata->
saved_crtc = KMSDRM_drmModeGetCrtc(viddata->
drm_fd, encoder->crtc_id);
566 dispdata->
crtc_id = encoder->crtc_id;
576 "Current mode is invalid, selecting connector's mode #0.");
577 dispdata->
mode = dispdata->
conn->modes[0];
589 drmModeFB *fb = drmModeGetFB(viddata->
drm_fd, dispdata->
saved_crtc->buffer_id);
597 #ifdef SDL_INPUT_LINUXEV
607 KMSDRM_drmModeFreeEncoder(encoder);
609 KMSDRM_drmModeFreeResources(resources);
613 if (dispdata->
conn) {
614 KMSDRM_drmModeFreeConnector(dispdata->
conn);
622 KMSDRM_gbm_device_destroy(viddata->
gbm);
625 if (viddata->
drm_fd >= 0) {
654 drmModeConnector *conn = dispdata->
conn;
657 int ret = KMSDRM_drmModeSetCrtc(viddata->
drm_fd, crtc->crtc_id, crtc->buffer_id,
658 crtc->x, crtc->y, &conn->connector_id, 1, &crtc->mode);
664 if (dispdata && dispdata->
conn) {
665 KMSDRM_drmModeFreeConnector(dispdata->
conn);
673 KMSDRM_gbm_device_destroy(viddata->
gbm);
676 if (viddata->
drm_fd >= 0) {
681 #ifdef SDL_INPUT_LINUXEV
690 drmModeConnector *conn = dispdata->
conn;
693 for (
int i = 0;
i < conn->count_modes;
i++) {
700 mode.w = conn->modes[
i].hdisplay;
701 mode.h = conn->modes[
i].vdisplay;
702 mode.refresh_rate = conn->modes[
i].vrefresh;
704 mode.driverdata = modedata;
718 drmModeConnector *conn = dispdata->
conn;
721 return SDL_SetError(
"Mode doesn't have an associated index");
733 windata->egl_surface_dirty = 1;
786 window->driverdata = windata;
915 SDL_SetError(
"application not compiled with SDL %d.%d\n",
#define SDL_VIDEO_OPENGL_EGL
void * KMSDRM_GLES_GetProcAddress(_THIS, const char *proc)
void KMSDRM_DestroyWindow(_THIS, SDL_Window *window)
int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
A collection of pixels used in software blitting.
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld if[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1(dst_w_bpp<=(lowbit *8)) &&((lowbit *8)<(pixblock_size *dst_w_bpp)) .if lowbit< 16 tst DST_R
void KMSDRM_SetWindowSize(_THIS, SDL_Window *window)
EGLImageKHR EGLint EGLint * handle
GLint GLint GLsizei width
GLbitfield GLuint64 timeout
GLuint GLint GLboolean GLint GLenum access
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
@ SDL_WINDOWEVENT_RESIZED
void KMSDRM_MaximizeWindow(_THIS, SDL_Window *window)
int KMSDRM_GLES_LoadLibrary(_THIS, const char *path)
int KMSDRM_GLES_SetSwapInterval(_THIS, int interval)
void KMSDRM_InitMouse(_THIS)
#define SDL_GL_LoadLibrary
void SDL_SetKeyboardFocus(SDL_Window *window)
int KMSDRM_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
SDL_DisplayMode desktop_mode
int KMSDRM_CreateWindow(_THIS, SDL_Window *window)
GLfloat GLfloat GLfloat GLfloat h
int KMSDRM_CreateSurfaces(_THIS, SDL_Window *window)
void * SDL_GetDisplayDriverData(int displayIndex)
void SDL_SetMouseFocus(SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
void KMSDRM_GLES_UnloadLibrary(_THIS)
The type used to identify a window.
The structure that defines a display mode.
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
#define SDL_GL_UnloadLibrary
SDL_GLContext KMSDRM_GLES_CreateContext(_THIS, SDL_Window *window)
struct SDL_VideoDevice::@255 gl_config
#define SDL_GetHintBoolean
void SDL_KMSDRM_UnloadSymbols(void)
static SDL_VideoDevice * _this
void KMSDRM_PumpEvents(_THIS)
#define SDL_MINOR_VERSION
EGLSurface EGLNativeWindowType * window
VideoBootStrap KMSDRM_bootstrap
SDL_bool KMSDRM_WaitPageFlip(_THIS, SDL_WindowData *windata, int timeout)
void KMSDRM_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
GLint GLint GLsizei GLsizei height
int KMSDRM_VideoInit(_THIS)
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d ®2 endm macro vzip8 reg2 vzip d d ®2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld cleanup[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
int KMSDRM_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
@ SDL_PIXELFORMAT_ARGB8888
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display)
#define SDL_GL_GetCurrentContext
#define SDL_OutOfMemory()
void KMSDRM_RestoreWindow(_THIS, SDL_Window *window)
void KMSDRM_SetWindowPosition(_THIS, SDL_Window *window)
void KMSDRM_RaiseWindow(_THIS, SDL_Window *window)
void KMSDRM_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
void KMSDRM_HideWindow(_THIS, SDL_Window *window)
SDL_bool waiting_for_flip
SDL_bool KMSDRM_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void KMSDRM_GLES_DeleteContext(_THIS, SDL_GLContext context)
#define SDL_HINT_VIDEO_DOUBLE_BUFFER
Tell the video driver that we only want a double buffer.
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
KMSDRM_FBInfo * KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
void KMSDRM_ShowWindow(_THIS, SDL_Window *window)
int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window *window)
void KMSDRM_MinimizeWindow(_THIS, SDL_Window *window)
void KMSDRM_SetWindowTitle(_THIS, SDL_Window *window)
void KMSDRM_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
int SDL_KMSDRM_LoadSymbols(void)
SDL_DisplayMode current_mode
#define SDL_MAJOR_VERSION
static SDL_AudioDeviceID device
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
void KMSDRM_VideoQuit(_THIS)
int KMSDRM_GLES_GetSwapInterval(_THIS)
GLubyte GLubyte GLubyte GLubyte w