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_LEGACY_DRI_PATH "/dev/dri/"
53 check_modestting(
int devindex)
61 drm_fd = open(
device, O_RDWR | O_CLOEXEC);
64 drmModeRes *resources = KMSDRM_LEGACY_drmModeGetResources(drm_fd);
67 KMSDRM_LEGACY_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_LEGACY_drmModeFreeResources(resources);
83 static int get_dricount(
void)
90 if (!(stat(KMSDRM_LEGACY_DRI_PATH, &sb) == 0
91 && S_ISDIR(sb.st_mode))) {
92 printf(
"The path %s cannot be opened or is not available\n",
93 KMSDRM_LEGACY_DRI_PATH);
97 if (
access(KMSDRM_LEGACY_DRI_PATH, F_OK) == -1) {
98 printf(
"The path %s cannot be opened\n",
99 KMSDRM_LEGACY_DRI_PATH);
103 folder = opendir(KMSDRM_LEGACY_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_LEGACY_Available(
void)
137 ret = get_driindex();
158 KMSDRM_LEGACY_CreateDevice(
int devindex)
163 if (!KMSDRM_LEGACY_Available()) {
167 if (!devindex || (devindex > 99)) {
168 devindex = get_driindex();
172 SDL_SetError(
"devindex (%d) must be between 0 and 99.\n", devindex);
194 device->driverdata = viddata;
216 #if SDL_VIDEO_OPENGL_EGL
228 device->free = KMSDRM_LEGACY_DeleteDevice;
242 "KMS/DRM Video Driver",
243 KMSDRM_LEGACY_CreateDevice
248 KMSDRM_LEGACY_FBDestroyCallback(
struct gbm_bo *bo,
void *
data)
252 if (fb_info && fb_info->
drm_fd >= 0 && fb_info->
fb_id != 0) {
253 KMSDRM_LEGACY_drmModeRmFB(fb_info->
drm_fd, fb_info->
fb_id);
287 w = KMSDRM_LEGACY_gbm_bo_get_width(bo);
288 h = KMSDRM_LEGACY_gbm_bo_get_height(bo);
289 stride = KMSDRM_LEGACY_gbm_bo_get_stride(bo);
290 handle = KMSDRM_LEGACY_gbm_bo_get_handle(bo).u32;
302 KMSDRM_LEGACY_gbm_bo_set_user_data(bo, fb_info, KMSDRM_LEGACY_FBDestroyCallback);
308 KMSDRM_LEGACY_FlipHandler(
int fd,
unsigned int frame,
unsigned int sec,
unsigned int usec,
void *
data)
316 drmEventContext ev = {0};
317 struct pollfd pfd = {0};
319 ev.version = DRM_EVENT_CONTEXT_VERSION;
320 ev.page_flip_handler = KMSDRM_LEGACY_FlipHandler;
328 if (poll(&pfd, 1,
timeout) < 0) {
333 if (pfd.revents & (POLLHUP | POLLERR)) {
338 if (pfd.revents & POLLIN) {
340 KMSDRM_LEGACY_drmHandleEvent(viddata->
drm_fd, &ev);
363 KMSDRM_LEGACY_gbm_surface_release_buffer(windata->
gs, windata->
curr_bo);
368 KMSDRM_LEGACY_gbm_surface_release_buffer(windata->
gs, windata->
next_bo);
372 #if SDL_VIDEO_OPENGL_EGL
382 KMSDRM_LEGACY_gbm_surface_destroy(windata->
gs);
395 Uint32 surface_fmt = GBM_FORMAT_XRGB8888;
396 Uint32 surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
397 #if SDL_VIDEO_OPENGL_EGL
401 if (!KMSDRM_LEGACY_gbm_device_is_format_supported(viddata->
gbm, surface_fmt, surface_flags)) {
405 #if SDL_VIDEO_OPENGL_EGL
406 SDL_EGL_SetRequiredVisualId(
_this, surface_fmt);
412 windata->
gs = KMSDRM_LEGACY_gbm_surface_create(viddata->
gbm,
width,
height, surface_fmt, surface_flags);
418 #if SDL_VIDEO_OPENGL_EGL
422 return SDL_SetError(
"Could not create EGL window surface");
427 windata->egl_surface_dirty = 0;
439 drmModeRes *resources =
NULL;
440 drmModeEncoder *encoder =
NULL;
456 viddata->
drm_fd = open(devname, O_RDWR | O_CLOEXEC);
458 if (viddata->
drm_fd < 0) {
465 viddata->
gbm = KMSDRM_LEGACY_gbm_create_device(viddata->
drm_fd);
472 resources = KMSDRM_LEGACY_drmModeGetResources(viddata->
drm_fd);
478 for (
i = 0;
i < resources->count_connectors;
i++) {
479 drmModeConnector *conn = KMSDRM_LEGACY_drmModeGetConnector(viddata->
drm_fd, resources->connectors[
i]);
485 if (conn->connection == DRM_MODE_CONNECTED && conn->count_modes) {
487 conn->connector_id, conn->count_modes);
488 dispdata->
conn = conn;
492 KMSDRM_LEGACY_drmModeFreeConnector(conn);
495 if (!dispdata->
conn) {
496 ret =
SDL_SetError(
"No currently active connector found.");
501 for (
i = 0;
i < resources->count_encoders;
i++) {
502 encoder = KMSDRM_LEGACY_drmModeGetEncoder(viddata->
drm_fd, resources->encoders[
i]);
508 if (encoder->encoder_id == dispdata->
conn->encoder_id) {
513 KMSDRM_LEGACY_drmModeFreeEncoder(encoder);
519 for (
i = 0;
i < resources->count_encoders;
i++) {
520 encoder = KMSDRM_LEGACY_drmModeGetEncoder(viddata->
drm_fd, resources->encoders[
i]);
526 for (
j = 0;
j < dispdata->
conn->count_encoders;
j++) {
527 if (dispdata->
conn->encoders[
j] == encoder->encoder_id) {
532 if (
j != dispdata->
conn->count_encoders) {
536 KMSDRM_LEGACY_drmModeFreeEncoder(encoder);
549 dispdata->
saved_crtc = KMSDRM_LEGACY_drmModeGetCrtc(viddata->
drm_fd, encoder->crtc_id);
553 for (
i = 0;
i < resources->count_crtcs;
i++) {
554 if (encoder->possible_crtcs & (1 <<
i)) {
555 encoder->crtc_id = resources->crtcs[
i];
556 dispdata->
saved_crtc = KMSDRM_LEGACY_drmModeGetCrtc(viddata->
drm_fd, encoder->crtc_id);
571 dispdata->
crtc_id = encoder->crtc_id;
581 "Current mode is invalid, selecting connector's mode #0.");
582 dispdata->
mode = dispdata->
conn->modes[0];
594 drmModeFB *fb = drmModeGetFB(viddata->
drm_fd, dispdata->
saved_crtc->buffer_id);
602 #ifdef SDL_INPUT_LINUXEV
612 KMSDRM_LEGACY_drmModeFreeEncoder(encoder);
614 KMSDRM_LEGACY_drmModeFreeResources(resources);
618 if (dispdata->
conn) {
619 KMSDRM_LEGACY_drmModeFreeConnector(dispdata->
conn);
623 KMSDRM_LEGACY_drmModeFreeCrtc(dispdata->
saved_crtc);
627 KMSDRM_LEGACY_gbm_device_destroy(viddata->
gbm);
630 if (viddata->
drm_fd >= 0) {
659 drmModeConnector *conn = dispdata->
conn;
662 int ret = KMSDRM_LEGACY_drmModeSetCrtc(viddata->
drm_fd,
crtc->crtc_id,
crtc->buffer_id,
669 if (dispdata && dispdata->
conn) {
670 KMSDRM_LEGACY_drmModeFreeConnector(dispdata->
conn);
674 KMSDRM_LEGACY_drmModeFreeCrtc(dispdata->
saved_crtc);
678 KMSDRM_LEGACY_gbm_device_destroy(viddata->
gbm);
681 if (viddata->
drm_fd >= 0) {
686 #ifdef SDL_INPUT_LINUXEV
695 drmModeConnector *conn = dispdata->
conn;
699 for (
i = 0;
i < conn->count_modes;
i++) {
706 mode.w = conn->modes[
i].hdisplay;
707 mode.h = conn->modes[
i].vdisplay;
708 mode.refresh_rate = conn->modes[
i].vrefresh;
710 mode.driverdata = modedata;
724 drmModeConnector *conn = dispdata->
conn;
728 return SDL_SetError(
"Mode doesn't have an associated index");
740 windata->egl_surface_dirty = 1;
794 window->driverdata = windata;
923 SDL_SetError(
"application not compiled with SDL %d.%d\n",
#define SDL_GL_LoadLibrary
#define SDL_GetHintBoolean
#define SDL_GL_UnloadLibrary
#define SDL_GL_GetCurrentContext
#define SDL_OutOfMemory()
#define SDL_HINT_VIDEO_DOUBLE_BUFFER
Tell the video driver that we only want a double buffer.
void SDL_SetKeyboardFocus(SDL_Window *window)
void SDL_KMSDRM_LEGACY_UnloadSymbols(void)
int SDL_KMSDRM_LEGACY_LoadSymbols(void)
void KMSDRM_LEGACY_PumpEvents(_THIS)
void KMSDRM_LEGACY_InitMouse(_THIS)
int KMSDRM_LEGACY_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
int KMSDRM_LEGACY_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
void KMSDRM_LEGACY_SetWindowPosition(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_GLES_DeleteContext(_THIS, SDL_GLContext context)
void KMSDRM_LEGACY_RestoreWindow(_THIS, SDL_Window *window)
void * KMSDRM_LEGACY_GLES_GetProcAddress(_THIS, const char *proc)
void KMSDRM_LEGACY_HideWindow(_THIS, SDL_Window *window)
int KMSDRM_LEGACY_CreateSurfaces(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_SetWindowTitle(_THIS, SDL_Window *window)
int KMSDRM_LEGACY_GLES_LoadLibrary(_THIS, const char *path)
SDL_GLContext KMSDRM_LEGACY_GLES_CreateContext(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_MaximizeWindow(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_ShowWindow(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_VideoQuit(_THIS)
void KMSDRM_LEGACY_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
int KMSDRM_LEGACY_GLES_SwapWindow(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_RaiseWindow(_THIS, SDL_Window *window)
int KMSDRM_LEGACY_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
int KMSDRM_LEGACY_VideoInit(_THIS)
SDL_bool KMSDRM_LEGACY_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
void KMSDRM_LEGACY_GLES_UnloadLibrary(_THIS)
void KMSDRM_LEGACY_DestroyWindow(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_MinimizeWindow(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_SetWindowSize(_THIS, SDL_Window *window)
void KMSDRM_LEGACY_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
SDL_bool KMSDRM_LEGACY_WaitPageFlip(_THIS, SDL_WindowData *windata, int timeout)
int KMSDRM_LEGACY_GLES_SetSwapInterval(_THIS, int interval)
int KMSDRM_LEGACY_CreateWindow(_THIS, SDL_Window *window)
KMSDRM_LEGACY_FBInfo * KMSDRM_LEGACY_FBFromBO(_THIS, struct gbm_bo *bo)
void KMSDRM_LEGACY_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
int KMSDRM_LEGACY_GLES_GetSwapInterval(_THIS)
void SDL_SetMouseFocus(SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLsizei width
GLint GLint GLsizei GLsizei height
GLbitfield GLuint64 timeout
GLuint GLint GLboolean GLint GLenum access
GLfloat GLfloat GLfloat GLfloat h
GLubyte GLubyte GLubyte GLubyte w
@ SDL_PIXELFORMAT_ARGB8888
void * SDL_GetDisplayDriverData(int displayIndex)
VideoBootStrap KMSDRM_LEGACY_bootstrap
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send_event)
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
#define SDL_MINOR_VERSION
#define SDL_MAJOR_VERSION
static SDL_VideoDevice * _this
@ SDL_WINDOWEVENT_RESIZED
int SDL_SendWindowEvent(SDL_Window *window, Uint8 windowevent, int data1, int data2)
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)
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)
EGLImageKHR EGLint EGLint * handle
EGLSurface EGLNativeWindowType * window
#define SDL_VIDEO_OPENGL_EGL
static SDL_AudioDeviceID device
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
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
The structure that defines a display mode.
A collection of pixels used in software blitting.
struct SDL_VideoDevice::@440 gl_config
SDL_DisplayMode desktop_mode
SDL_DisplayMode current_mode
SDL_bool waiting_for_flip
The type used to identify a window.