22 #include "../../SDL_internal.h" 24 #if SDL_VIDEO_DRIVER_KMSDRM 27 #include "../SDL_sysvideo.h" 31 #include "../../events/SDL_mouse_c.h" 32 #include "../../events/SDL_keyboard_c.h" 34 #ifdef SDL_INPUT_LINUXEV 35 #include "../../core/linux/SDL_evdev.h" 48 #define KMSDRM_DRI_PATH "/dev/dri/" 51 check_modestting(
int devindex)
57 SDL_snprintf(device,
sizeof (device),
"%scard%d", KMSDRM_DRI_PATH, devindex);
59 drm_fd = open(device, O_RDWR | O_CLOEXEC);
62 drmModeRes *resources = KMSDRM_drmModeGetResources(drm_fd);
63 if (resources !=
NULL) {
65 KMSDRM_drmModeFreeResources(resources);
75 static int get_dricount(
void)
82 if (!(stat(KMSDRM_DRI_PATH, &sb) == 0
83 && S_ISDIR(sb.st_mode))) {
84 printf(
"The path %s cannot be opened or is not available\n",
89 if (
access(KMSDRM_DRI_PATH, F_OK) == -1) {
90 printf(
"The path %s cannot be opened\n",
95 folder = opendir(KMSDRM_DRI_PATH);
97 while ((res = readdir(folder))) {
98 if (res->d_type == DT_CHR) {
111 const int devcount = get_dricount();
114 for (i = 0; i < devcount; i++) {
115 if (check_modestting(i)) {
124 KMSDRM_Available(
void)
128 ret = get_driindex();
148 KMSDRM_Create(
int devindex)
153 if (!devindex || (devindex > 99)) {
154 devindex = get_driindex();
158 SDL_SetError(
"devindex (%d) must be between 0 and 99.\n", devindex);
168 if (device ==
NULL) {
188 device->
free = KMSDRM_Destroy;
210 #if SDL_VIDEO_OPENGL_EGL 236 "KMS/DRM Video Driver",
243 KMSDRM_FBDestroyCallback(
struct gbm_bo *bo,
void *
data)
247 if (fb_info && fb_info->
drm_fd > 0 && fb_info->
fb_id != 0) {
248 KMSDRM_drmModeRmFB(fb_info->
drm_fd, fb_info->
fb_id);
264 if (fb_info !=
NULL) {
271 if (fb_info ==
NULL) {
277 w = KMSDRM_gbm_bo_get_width(bo);
278 h = KMSDRM_gbm_bo_get_height(bo);
279 stride = KMSDRM_gbm_bo_get_stride(bo);
280 handle = KMSDRM_gbm_bo_get_handle(bo).u32;
282 ret = KMSDRM_drmModeAddFB(vdata->
drm_fd, w, h, 24, 32, stride, handle, &fb_info->
fb_id);
290 KMSDRM_gbm_bo_set_user_data(bo, fb_info, KMSDRM_FBDestroyCallback);
300 if (poll(&vdata->
drm_pollfd, 1, timeout) < 0) {
305 if (vdata->
drm_pollfd.revents & (POLLHUP | POLLERR)) {
323 KMSDRM_FlipHandler(
int fd,
unsigned int frame,
unsigned int sec,
unsigned int usec,
void *data)
340 drmModeRes *resources =
NULL;
341 drmModeConnector *connector =
NULL;
342 drmModeEncoder *encoder =
NULL;
356 if (devname ==
NULL) {
361 vdata->
drm_fd = open(devname, O_RDWR | O_CLOEXEC);
370 vdata->
gbm = KMSDRM_gbm_create_device(vdata->
drm_fd);
377 resources = KMSDRM_drmModeGetResources(vdata->
drm_fd);
383 for (i = 0; i < resources->count_connectors; i++) {
384 connector = KMSDRM_drmModeGetConnector(vdata->
drm_fd, resources->connectors[i]);
385 if (connector ==
NULL)
388 if (connector->connection == DRM_MODE_CONNECTED &&
389 connector->count_modes > 0) {
391 connector->connector_id, connector->count_modes);
396 KMSDRM_drmModeFreeConnector(connector);
400 if (i == resources->count_connectors) {
401 ret =
SDL_SetError(
"No currently active connector found.");
405 for (i = 0; i < resources->count_encoders; i++) {
406 encoder = KMSDRM_drmModeGetEncoder(vdata->
drm_fd, resources->encoders[i]);
411 if (encoder->encoder_id == connector->encoder_id) {
417 KMSDRM_drmModeFreeEncoder(encoder);
421 if (i == resources->count_encoders) {
434 data->
crtc_id = encoder->crtc_id;
436 vdata->
crtc_id = encoder->crtc_id;
464 vdata->
drm_evctx.version = DRM_EVENT_CONTEXT_VERSION;
465 vdata->
drm_evctx.page_flip_handler = KMSDRM_FlipHandler;
467 #ifdef SDL_INPUT_LINUXEV 475 KMSDRM_drmModeFreeEncoder(encoder);
476 if (connector !=
NULL)
477 KMSDRM_drmModeFreeConnector(connector);
478 if (resources !=
NULL)
479 KMSDRM_drmModeFreeResources(resources);
489 KMSDRM_gbm_device_destroy(vdata->
gbm);
515 if(KMSDRM_drmModeSetCrtc(vdata->
drm_fd, crtc->crtc_id, crtc->buffer_id,
525 KMSDRM_gbm_device_destroy(vdata->
gbm);
533 #ifdef SDL_INPUT_LINUXEV 557 Uint32 surface_fmt, surface_flags;
576 surface_fmt = GBM_FORMAT_XRGB8888;
577 surface_flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
579 if (!KMSDRM_gbm_device_is_format_supported(vdata->
gbm, surface_fmt, surface_flags)) {
582 wdata->
gs = KMSDRM_gbm_surface_create(vdata->
gbm, window->
w, window->
h, surface_fmt, surface_flags);
584 #if SDL_VIDEO_OPENGL_EGL 585 if (!
_this->egl_data) {
622 #if SDL_VIDEO_OPENGL_EGL 627 KMSDRM_gbm_surface_destroy(wdata->
gs);
641 KMSDRM_gbm_surface_release_buffer(data->
gs, data->
crtc_bo);
645 KMSDRM_gbm_surface_release_buffer(data->
gs, data->
next_bo);
649 KMSDRM_gbm_surface_release_buffer(data->
gs, data->
current_bo);
652 #if SDL_VIDEO_OPENGL_EGL 659 KMSDRM_gbm_surface_destroy(data->
gs);
728 SDL_SetError(
"application not compiled with SDL %d.%d\n",
int KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
int KMSDRM_GLES_GetSwapInterval(_THIS)
#define SDL_MINOR_VERSION
void SDL_KMSDRM_UnloadSymbols(void)
void KMSDRM_SetWindowSize(_THIS, SDL_Window *window)
void(* RestoreWindow)(_THIS, SDL_Window *window)
void * KMSDRM_GLES_GetProcAddress(_THIS, const char *proc)
SDL_bool waiting_for_flip
void SDL_SetKeyboardFocus(SDL_Window *window)
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 local 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
VideoBootStrap KMSDRM_bootstrap
struct gbm_bo * current_bo
#define SDL_MAJOR_VERSION
void KMSDRM_InitMouse(_THIS)
void KMSDRM_MaximizeWindow(_THIS, SDL_Window *window)
GLfloat GLfloat GLfloat GLfloat h
A collection of pixels used in software blitting.
int(* GL_SetSwapInterval)(_THIS, int interval)
void(* ShowWindow)(_THIS, SDL_Window *window)
The structure that defines a display mode.
int KMSDRM_CreateWindowFrom(_THIS, SDL_Window *window, const void *data)
int SDL_KMSDRM_LoadSymbols(void)
void(* SetWindowSize)(_THIS, SDL_Window *window)
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
int KMSDRM_GLES_SetSwapInterval(_THIS, int interval)
int KMSDRM_GLES_LoadLibrary(_THIS, const char *path)
void SDL_SetMouseFocus(SDL_Window *window)
void KMSDRM_GLES_UnloadLibrary(_THIS)
#define SDL_GL_LoadLibrary
SDL_GLContext KMSDRM_GLES_CreateContext(_THIS, SDL_Window *window)
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display)
int KMSDRM_CreateWindow(_THIS, SDL_Window *window)
int(* GL_LoadLibrary)(_THIS, const char *path)
GLuint GLint GLboolean GLint GLenum access
int(* SetDisplayMode)(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
#define SDL_GetHintBoolean
struct SDL_VideoDevice::@33 gl_config
static SDL_VideoDevice * _this
void(* HideWindow)(_THIS, SDL_Window *window)
static SDL_AudioDeviceID device
#define SDL_GL_UnloadLibrary
void KMSDRM_SetWindowGrab(_THIS, SDL_Window *window, SDL_bool grabbed)
void(* RaiseWindow)(_THIS, SDL_Window *window)
SDL_bool(* GetWindowWMInfo)(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
SDL_GLContext(* GL_CreateContext)(_THIS, SDL_Window *window)
EGLImageKHR EGLint EGLint * handle
void KMSDRM_PumpEvents(_THIS)
int KMSDRM_VideoInit(_THIS)
int(* GL_MakeCurrent)(_THIS, SDL_Window *window, SDL_GLContext context)
int KMSDRM_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
SDL_DisplayMode current_mode
GLubyte GLubyte GLubyte GLubyte w
void(* DestroyWindow)(_THIS, SDL_Window *window)
void(* SetWindowIcon)(_THIS, SDL_Window *window, SDL_Surface *icon)
drmEventContext drm_evctx
void KMSDRM_RestoreWindow(_THIS, SDL_Window *window)
void KMSDRM_SetWindowIcon(_THIS, SDL_Window *window, SDL_Surface *icon)
void KMSDRM_HideWindow(_THIS, SDL_Window *window)
void(* GL_UnloadLibrary)(_THIS)
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(* GetDisplayModes)(_THIS, SDL_VideoDisplay *display)
SDL_bool KMSDRM_GetWindowWMInfo(_THIS, SDL_Window *window, struct SDL_SysWMinfo *info)
SDL_bool KMSDRM_WaitPageFlip(_THIS, SDL_WindowData *wdata, int timeout)
int(* CreateSDLWindow)(_THIS, SDL_Window *window)
#define SDL_OutOfMemory()
SDL_DisplayMode desktop_mode
void KMSDRM_SetWindowPosition(_THIS, SDL_Window *window)
void KMSDRM_RaiseWindow(_THIS, SDL_Window *window)
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
EGLSurface EGLNativeWindowType * window
void KMSDRM_GLES_DeleteContext(_THIS, SDL_GLContext context)
void(* SetWindowPosition)(_THIS, SDL_Window *window)
int(* GL_SwapWindow)(_THIS, SDL_Window *window)
#define SDL_HINT_VIDEO_DOUBLE_BUFFER
Tell the video driver that we only want a double buffer.
The type used to identify a window.
GLbitfield GLuint64 timeout
void(* MinimizeWindow)(_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)
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
int(* CreateSDLWindowFrom)(_THIS, SDL_Window *window, const void *data)
KMSDRM_FBInfo * KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
void(* GL_DeleteContext)(_THIS, SDL_GLContext context)
void(* SetWindowTitle)(_THIS, SDL_Window *window)
int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window *window)
void KMSDRM_ShowWindow(_THIS, SDL_Window *window)
int(* GL_GetSwapInterval)(_THIS)
void(* MaximizeWindow)(_THIS, SDL_Window *window)
void KMSDRM_VideoQuit(_THIS)
void(* SetWindowGrab)(_THIS, SDL_Window *window, SDL_bool grabbed)
void *(* GL_GetProcAddress)(_THIS, const char *proc)
void KMSDRM_DestroyWindow(_THIS, SDL_Window *window)
void(* PumpEvents)(_THIS)