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) {
57 struct gbm_bo *bo = KMSDRM_gbm_bo_create(viddata->
gbm,
w,
h, bo_format,
58 GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
61 SDL_SetError(
"Could not create GBM cursor BO width size %dx%d for size testing",
w,
h);
65 bo_handle = KMSDRM_gbm_bo_get_handle(bo).u32;
72 KMSDRM_gbm_bo_destroy(bo);
78 KMSDRM_gbm_bo_destroy(bo);
90 KMSDRM_CursorData *curdata;
93 int i, ret, usable_cursor_w, usable_cursor_h;
100 bo_format = GBM_FORMAT_RGB332;
103 bo_format = GBM_FORMAT_ARGB4444;
106 bo_format = GBM_FORMAT_RGBA4444;
109 bo_format = GBM_FORMAT_ABGR4444;
112 bo_format = GBM_FORMAT_BGRA4444;
115 bo_format = GBM_FORMAT_ARGB1555;
118 bo_format = GBM_FORMAT_RGBA5551;
121 bo_format = GBM_FORMAT_ABGR1555;
124 bo_format = GBM_FORMAT_BGRA5551;
127 bo_format = GBM_FORMAT_RGB565;
130 bo_format = GBM_FORMAT_BGR565;
134 bo_format = GBM_FORMAT_RGB888;
138 bo_format = GBM_FORMAT_BGR888;
141 bo_format = GBM_FORMAT_RGBX8888;
144 bo_format = GBM_FORMAT_BGRX8888;
147 bo_format = GBM_FORMAT_ARGB8888;
150 bo_format = GBM_FORMAT_RGBA8888;
153 bo_format = GBM_FORMAT_ABGR8888;
156 bo_format = GBM_FORMAT_BGRA8888;
159 bo_format = GBM_FORMAT_ARGB2101010;
166 if (!KMSDRM_gbm_device_is_format_supported(viddata->
gbm, bo_format, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE)) {
176 curdata = (KMSDRM_CursorData *)
SDL_calloc(1,
sizeof(*curdata));
192 if (KMSDRM_IsCursorSizeSupported(usable_cursor_w, usable_cursor_h, bo_format)) {
196 usable_cursor_w += usable_cursor_w;
197 usable_cursor_h += usable_cursor_h;
200 if (!cursor_supported) {
201 SDL_SetError(
"Could not find a cursor size supported by the kernel driver");
205 curdata->hot_x =
hot_x;
206 curdata->hot_y = hot_y;
207 curdata->w = usable_cursor_w;
208 curdata->h = usable_cursor_h;
210 curdata->bo = KMSDRM_gbm_bo_create(viddata->
gbm, usable_cursor_w, usable_cursor_h, bo_format,
211 GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
218 bo_stride = KMSDRM_gbm_bo_get_stride(curdata->bo);
219 bufsize = bo_stride * curdata->h;
221 if (
surface->pitch != bo_stride) {
292 KMSDRM_gbm_bo_destroy(curdata->bo);
306 KMSDRM_CursorData *curdata;
329 if (curdata->crtc_id != 0) {
330 ret = KMSDRM_drmModeSetCursor(viddata->
drm_fd, curdata->crtc_id, 0, 0, 0);
332 SDL_SetError(
"Could not hide current cursor with drmModeSetCursor().");
336 curdata->crtc_id = 0;
342 if (dispdata && dispdata->
crtc_id != 0) {
343 ret = KMSDRM_drmModeSetCursor(viddata->
drm_fd, dispdata->
crtc_id, 0, 0, 0);
345 SDL_SetError(
"Could not hide display's cursor with drmModeSetCursor().");
355 return SDL_SetError(
"Could not get display for mouse.");
358 return SDL_SetError(
"Could not get display driverdata.");
362 if (!curdata || !curdata->bo) {
363 return SDL_SetError(
"Cursor not initialized properly.");
366 bo_handle = KMSDRM_gbm_bo_get_handle(curdata->bo).u32;
367 if (curdata->hot_x == 0 && curdata->hot_y == 0) {
369 curdata->w, curdata->h);
372 curdata->w, curdata->h, curdata->hot_x, curdata->hot_y);
379 curdata->crtc_id = dispdata->
crtc_id;
388 KMSDRM_CursorData *curdata;
396 if (curdata->crtc_id != 0) {
397 drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
399 KMSDRM_drmModeSetCursor(drm_fd, curdata->crtc_id, 0, 0, 0);
400 curdata->crtc_id = 0;
402 KMSDRM_gbm_bo_destroy(curdata->bo);
416 KMSDRM_WarpMouseGlobal(
x,
y);
421 KMSDRM_WarpMouseGlobal(
int x,
int y)
423 KMSDRM_CursorData *curdata;
434 if (curdata->crtc_id != 0) {
436 drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
437 ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id,
x,
y);
448 return SDL_SetError(
"Cursor not initialized properly.");
484 KMSDRM_CursorData *curdata;
491 drm_fd = KMSDRM_gbm_device_get_fd(KMSDRM_gbm_bo_get_device(curdata->bo));
492 ret = KMSDRM_drmModeMoveCursor(drm_fd, curdata->crtc_id, mouse->
x, mouse->
y);