kmsdrm: move cursor-related atomic helper functions and related struct typedefs to the SDL_kmsdrmmouse unit.

This commit is contained in:
Manuel Alfayate Corchete 2020-08-23 11:26:55 +02:00
parent 0b7b7721b9
commit e06e9c35c8
4 changed files with 103 additions and 93 deletions

View File

@ -39,6 +39,84 @@ static void KMSDRM_FreeCursor(SDL_Cursor * cursor);
static void KMSDRM_WarpMouse(SDL_Window * window, int x, int y); static void KMSDRM_WarpMouse(SDL_Window * window, int x, int y);
static int KMSDRM_WarpMouseGlobal(int x, int y); static int KMSDRM_WarpMouseGlobal(int x, int y);
/**********************************/
/* Atomic helper functions block. */
/**********************************/
int
drm_atomic_setcursor(KMSDRM_CursorData *curdata, int x, int y)
{
KMSDRM_FBInfo *fb;
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
/* Do we have a set of changes already in the making? If not, allocate a new one. */
if (!dispdata->atomic_req)
dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc();
if (curdata)
{
if (!dispdata->cursor_plane) {
setup_plane(curdata->video, &(dispdata->cursor_plane), DRM_PLANE_TYPE_CURSOR);
/* "curdata->video" is the _THIS pointer, which points to an SDL_Display, as passed from kmsdrmmouse.c */
}
fb = KMSDRM_FBFromBO(curdata->video, curdata->bo);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "FB_ID", fb->fb_id);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_X", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_Y", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_W", curdata->w << 16);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_H", curdata->h << 16);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_X", x);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_Y", y);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_W", curdata->w);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_H", curdata->h);
}
else if (dispdata->cursor_plane) /* Don't go further if plane has already been freed. */
{
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "FB_ID", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_ID", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_X", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_Y", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_W", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_H", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_W", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_H", 0);
free_plane(&dispdata->cursor_plane);
}
/* GPU <-> DISPLAY synchronization is done ON the display_plane,
so no need to set any fence props here, we do that only on the main
display plane. */
return 0;
}
int
drm_atomic_movecursor(KMSDRM_CursorData *curdata, int x, int y)
{
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
if (!dispdata->cursor_plane) /* We can't move a non-existing cursor, but that's ok. */
return 0;
/* Do we have a set of changes already in the making? If not, allocate a new one. */
if (!dispdata->atomic_req)
dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc();
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_X", x - curdata->hot_x);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_Y", y - curdata->hot_y);
return 0;
}
/***************************************/
/* Atomic helper functions block ends. */
/***************************************/
/* Converts a pixel from straight-alpha [AA, RR, GG, BB], which the SDL cursor surface has, /* Converts a pixel from straight-alpha [AA, RR, GG, BB], which the SDL cursor surface has,
to premultiplied-alpha [AA. AA*RR, AA*GG, AA*BB]. to premultiplied-alpha [AA. AA*RR, AA*GG, AA*BB].
These multiplications have to be done with floats instead of uint32_t's, and the resulting values have These multiplications have to be done with floats instead of uint32_t's, and the resulting values have

View File

@ -29,6 +29,19 @@
#define MAX_CURSOR_W 512 #define MAX_CURSOR_W 512
#define MAX_CURSOR_H 512 #define MAX_CURSOR_H 512
/* Driverdata with driver-side info about the cursor. */
typedef struct _KMSDRM_CursorData
{
struct gbm_bo *bo;
uint32_t crtc_id;
int hot_x, hot_y;
int w, h;
/* The video devide implemented on SDL_kmsdrmvideo.c
* to be used as _THIS pointer in SDL_kmsdrmvideo.c
* functions that need it. */
SDL_VideoDevice *video;
} KMSDRM_CursorData;
extern void KMSDRM_InitMouse(_THIS); extern void KMSDRM_InitMouse(_THIS);
extern void KMSDRM_QuitMouse(_THIS); extern void KMSDRM_QuitMouse(_THIS);

View File

@ -194,7 +194,7 @@ static int add_crtc_property(drmModeAtomicReq *req, struct crtc *crtc,
return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value); return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value);
} }
static int add_plane_property(drmModeAtomicReq *req, struct plane *plane, int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
const char *name, uint64_t value) const char *name, uint64_t value)
{ {
unsigned int i; unsigned int i;
@ -389,9 +389,9 @@ static uint32_t get_plane_id(_THIS, uint32_t plane_type)
} }
/* Setup cursor plane and it's props. */ /* Setup cursor plane and it's props. */
static int int
setup_plane(_THIS, struct plane **plane, uint32_t plane_type ) { setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
{
uint32_t plane_id; uint32_t plane_id;
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
@ -430,8 +430,9 @@ cleanup:
} }
/* Free a plane and it's props. */ /* Free a plane and it's props. */
static void void
free_plane(struct plane **plane) { free_plane(struct plane **plane)
{
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
if (dispdata && (*plane)) { if (dispdata && (*plane)) {
@ -492,76 +493,6 @@ drm_atomic_setbuffer(_THIS, struct plane *plane, uint32_t fb_id, uint32_t crtc_i
} }
} }
int
drm_atomic_setcursor(KMSDRM_CursorData *curdata, int x, int y)
{
KMSDRM_FBInfo *fb;
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
/* Do we have a set of changes already in the making? If not, allocate a new one. */
if (!dispdata->atomic_req)
dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc();
if (curdata)
{
if (!dispdata->cursor_plane) {
setup_plane(curdata->video, &(dispdata->cursor_plane), DRM_PLANE_TYPE_CURSOR);
/* "curdata->video" is the _THIS pointer, which points to an SDL_Display, as passed from kmsdrmmouse.c */
}
fb = KMSDRM_FBFromBO(curdata->video, curdata->bo);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "FB_ID", fb->fb_id);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_X", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_Y", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_W", curdata->w << 16);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_H", curdata->h << 16);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_X", x);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_Y", y);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_W", curdata->w);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_H", curdata->h);
}
else if (dispdata->cursor_plane) /* Don't go further if plane has already been freed. */
{
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "FB_ID", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_ID", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_X", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_Y", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_W", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "SRC_H", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_W", 0);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_H", 0);
free_plane(&dispdata->cursor_plane);
}
/* GPU <-> DISPLAY synchronization is done ON the display_plane,
so no need to set any fence props here, we do that only on the main
display plane. */
return 0;
}
int
drm_atomic_movecursor(KMSDRM_CursorData *curdata, int x, int y)
{
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
if (!dispdata->cursor_plane) /* We can't move a non-existing cursor, but that's ok. */
return 0;
/* Do we have a set of changes already in the making? If not, allocate a new one. */
if (!dispdata->atomic_req)
dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc();
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_X", x - curdata->hot_x);
add_plane_property(dispdata->atomic_req, dispdata->cursor_plane, "CRTC_Y", y - curdata->hot_y);
return 0;
}
int drm_atomic_commit(_THIS, SDL_bool blocking) int drm_atomic_commit(_THIS, SDL_bool blocking)
{ {
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);

View File

@ -119,30 +119,18 @@ typedef struct KMSDRM_FBInfo
uint32_t fb_id; /* DRM framebuffer ID */ uint32_t fb_id; /* DRM framebuffer ID */
} KMSDRM_FBInfo; } KMSDRM_FBInfo;
/* Driverdata with driver-side info about the cursor. */
typedef struct _KMSDRM_CursorData
{
struct gbm_bo *bo;
uint32_t crtc_id;
int hot_x, hot_y;
int w, h;
/* The video devide implemented on SDL_kmsdrmvideo.c
* to be used as _THIS pointer in SDL_kmsdrmvideo.c
* functions that need it. */
SDL_VideoDevice *video;
} KMSDRM_CursorData;
/* Helper functions */ /* Helper functions */
int KMSDRM_CreateSurfaces(_THIS, SDL_Window * window); int KMSDRM_CreateSurfaces(_THIS, SDL_Window * window);
KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo); KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
/* Atomic functions that are used from SDL_kmsdrmopengles.c and SDL_kmsdrmmouse.c */ /* Atomic functions that are used from SDL_kmsdrmopengles.c and SDL_kmsdrmmouse.c */
void drm_atomic_modeset(_THIS, int mode_index);
void drm_atomic_setbuffer(_THIS, struct plane *plane, uint32_t fb_id, uint32_t crtc_id); void drm_atomic_setbuffer(_THIS, struct plane *plane, uint32_t fb_id, uint32_t crtc_id);
void drm_atomic_waitpending(_THIS); void drm_atomic_waitpending(_THIS);
int drm_atomic_commit(_THIS, SDL_bool blocking); int drm_atomic_commit(_THIS, SDL_bool blocking);
int drm_atomic_setcursor(KMSDRM_CursorData *curdata, int x, int y); int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
int drm_atomic_movecursor(KMSDRM_CursorData *curdata, int x, int y); const char *name, uint64_t value);
int setup_plane(_THIS, struct plane **plane, uint32_t plane_type);
void free_plane(struct plane **plane);
/****************************************************************************/ /****************************************************************************/
/* SDL_VideoDevice functions declaration */ /* SDL_VideoDevice functions declaration */