22 #include "../../SDL_internal.h" 24 #if SDL_VIDEO_DRIVER_KMSDRM 30 #include "../../events/SDL_mouse_c.h" 31 #include "../../events/default_cursor.h" 33 static SDL_Cursor *KMSDRM_CreateDefaultCursor(
void);
39 static int KMSDRM_WarpMouseGlobal(
int x,
int y);
42 KMSDRM_CreateDefaultCursor(
void)
49 KMSDRM_IsCursorSizeSupported (
int w,
int h,
uint32_t bo_format) {
55 struct gbm_bo *bo = KMSDRM_gbm_bo_create(vdata->
gbm, w, h, bo_format,
56 GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
59 SDL_SetError(
"Could not create GBM cursor BO width size %dx%d for size testing", w, h);
63 bo_handle = KMSDRM_gbm_bo_get_handle(bo).u32;
64 ret = KMSDRM_drmModeSetCursor(vdata->
drm_fd, vdata->
crtc_id, bo_handle, w, h);
70 KMSDRM_gbm_bo_destroy(bo);
76 KMSDRM_gbm_bo_destroy(bo);
91 int i, ret, usable_cursor_w, usable_cursor_h;
98 bo_format = GBM_FORMAT_RGB332;
101 bo_format = GBM_FORMAT_ARGB4444;
104 bo_format = GBM_FORMAT_RGBA4444;
107 bo_format = GBM_FORMAT_ABGR4444;
110 bo_format = GBM_FORMAT_BGRA4444;
113 bo_format = GBM_FORMAT_ARGB1555;
116 bo_format = GBM_FORMAT_RGBA5551;
119 bo_format = GBM_FORMAT_ABGR1555;
122 bo_format = GBM_FORMAT_BGRA5551;
125 bo_format = GBM_FORMAT_RGB565;
128 bo_format = GBM_FORMAT_BGR565;
132 bo_format = GBM_FORMAT_RGB888;
136 bo_format = GBM_FORMAT_BGR888;
139 bo_format = GBM_FORMAT_RGBX8888;
142 bo_format = GBM_FORMAT_BGRX8888;
145 bo_format = GBM_FORMAT_ARGB8888;
148 bo_format = GBM_FORMAT_RGBA8888;
151 bo_format = GBM_FORMAT_ABGR8888;
154 bo_format = GBM_FORMAT_BGRA8888;
157 bo_format = GBM_FORMAT_ARGB2101010;
164 if (!KMSDRM_gbm_device_is_format_supported(vdata->
gbm, bo_format, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE)) {
170 if (cursor ==
NULL) {
175 if (curdata ==
NULL) {
186 usable_cursor_w = surface->
w;
187 usable_cursor_h = surface->
h;
190 if (KMSDRM_IsCursorSizeSupported(usable_cursor_w, usable_cursor_h, bo_format)) {
194 usable_cursor_w += usable_cursor_w;
195 usable_cursor_h += usable_cursor_h;
198 if (!cursor_supported) {
199 SDL_SetError(
"Could not find a cursor size supported by the kernel driver");
204 curdata->
hot_y = hot_y;
205 curdata->
w = usable_cursor_w;
206 curdata->
h = usable_cursor_h;
208 curdata->
bo = KMSDRM_gbm_bo_create(vdata->
gbm, usable_cursor_w, usable_cursor_h, bo_format,
209 GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
211 if (curdata->
bo ==
NULL) {
216 bo_stride = KMSDRM_gbm_bo_get_stride(curdata->
bo);
217 bufsize = bo_stride * curdata->
h;
219 if (surface->
pitch != bo_stride) {
222 if (buffer ==
NULL) {
238 for (i = 0; i < surface->
h; i++) {
248 if (KMSDRM_gbm_bo_write(curdata->
bo, buffer, bufsize)) {
265 ret = KMSDRM_gbm_bo_write(curdata->
bo, surface->
pixels, bufsize);
282 if (buffer !=
NULL) {
285 if (cursor !=
NULL) {
288 if (curdata !=
NULL) {
289 if (curdata->
bo !=
NULL) {
290 KMSDRM_gbm_bo_destroy(curdata->
bo);
317 if (display !=
NULL) {
322 if (cursor ==
NULL) {
328 ret = KMSDRM_drmModeSetCursor(vdata->
drm_fd, curdata->
crtc_id, 0, 0, 0);
330 SDL_SetError(
"Could not hide current cursor with drmModeSetCursor().");
341 ret = KMSDRM_drmModeSetCursor(vdata->
drm_fd, ddata->
crtc_id, 0, 0, 0);
343 SDL_SetError(
"Could not hide display's cursor with drmModeSetCursor().");
352 if (display ==
NULL) {
353 return SDL_SetError(
"Could not get display for mouse.");
356 return SDL_SetError(
"Could not get display driverdata.");
361 return SDL_SetError(
"Cursor not initialized properly.");
364 bo_handle = KMSDRM_gbm_bo_get_handle(curdata->
bo).u32;
365 if (curdata->
hot_x == 0 && curdata->
hot_y == 0) {
366 ret = KMSDRM_drmModeSetCursor(vdata->
drm_fd, ddata->
crtc_id, bo_handle,
367 curdata->
w, curdata->
h);
369 ret = KMSDRM_drmModeSetCursor2(vdata->
drm_fd, ddata->
crtc_id, bo_handle,
370 curdata->
w, curdata->
h,
390 if (cursor !=
NULL) {
393 if (curdata !=
NULL) {
394 if (curdata->
bo !=
NULL) {
396 drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->
bo));
398 KMSDRM_drmModeSetCursor(drm_fd, curdata->
crtc_id, 0, 0, 0);
401 KMSDRM_gbm_bo_destroy(curdata->
bo);
415 KMSDRM_WarpMouseGlobal(x, y);
420 KMSDRM_WarpMouseGlobal(
int x,
int y)
431 if (curdata->
bo !=
NULL) {
435 drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->
bo));
436 ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->
crtc_id, x, y);
447 return SDL_SetError(
"Cursor not initialized properly.");
490 drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->
bo));
491 ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->
crtc_id, mouse->
x, mouse->
y);
SDL_Mouse * SDL_GetMouse(void)
void KMSDRM_QuitMouse(_THIS)
int(* ShowCursor)(SDL_Cursor *cursor)
#define SDL_UnlockSurface
GLint GLint GLint GLint GLint x
void KMSDRM_InitMouse(_THIS)
GLfloat GLfloat GLfloat GLfloat h
A collection of pixels used in software blitting.
GLenum GLuint GLsizei bufsize
SDL_Cursor *(* CreateCursor)(SDL_Surface *surface, int hot_x, int hot_y)
int SDL_SendMouseMotion(SDL_Window *window, SDL_MouseID mouseID, int relative, int x, int y)
GLubyte GLubyte GLubyte GLubyte w
int uint32_t uint32_t uint32_t uint32_t uint32_t int drmModeModeInfoPtr mode int uint32_t uint32_t bo_handle
GLint GLint GLint GLint GLint GLint y
void SDL_SetDefaultCursor(SDL_Cursor *cursor)
int(* WarpMouseGlobal)(int x, int y)
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(* FreeCursor)(SDL_Cursor *cursor)
#define SDL_OutOfMemory()
static const unsigned char default_cmask[]
SDL_VideoDisplay * SDL_GetDisplayForWindow(SDL_Window *window)
EGLSurface EGLNativeWindowType * window
The type used to identify a window.
void(* WarpMouse)(SDL_Window *window, int x, int y)
SDL_VideoDevice * SDL_GetVideoDevice(void)
static const unsigned char default_cdata[]
void(* MoveCursor)(SDL_Cursor *cursor)
static void cleanup(void)
int uint32_t uint32_t uint32_t uint32_t uint32_t int drmModeModeInfoPtr mode int uint32_t uint32_t uint32_t uint32_t int32_t hot_x