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;
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)) {
175 if (curdata ==
NULL) {
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);
219 if (
surface->pitch != bo_stride) {
288 if (curdata !=
NULL) {
289 if (curdata->
bo !=
NULL) {
290 KMSDRM_gbm_bo_destroy(curdata->
bo);
317 if (display !=
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) {
367 curdata->
w, curdata->
h);
370 curdata->
w, curdata->
h,
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);