kmsdrm: move cursor-related atomic helper functions and related struct typedefs to the SDL_kmsdrmmouse unit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c
index 55902fc..ec560be 100644
--- a/src/video/kmsdrm/SDL_kmsdrmmouse.c
+++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c
@@ -39,6 +39,84 @@ static void KMSDRM_FreeCursor(SDL_Cursor * cursor);
static void KMSDRM_WarpMouse(SDL_Window * window, 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,
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
diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.h b/src/video/kmsdrm/SDL_kmsdrmmouse.h
index 4d21448..030bde4 100644
--- a/src/video/kmsdrm/SDL_kmsdrmmouse.h
+++ b/src/video/kmsdrm/SDL_kmsdrmmouse.h
@@ -29,6 +29,19 @@
#define MAX_CURSOR_W 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_QuitMouse(_THIS);
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index b8f0d1c..2ff4951 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -194,8 +194,8 @@ static int add_crtc_property(drmModeAtomicReq *req, struct crtc *crtc,
return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value);
}
-static int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
- const char *name, uint64_t value)
+int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
+ const char *name, uint64_t value)
{
unsigned int i;
int prop_id = -1;
@@ -389,9 +389,9 @@ static uint32_t get_plane_id(_THIS, uint32_t plane_type)
}
/* Setup cursor plane and it's props. */
-static int
-setup_plane(_THIS, struct plane **plane, uint32_t plane_type ) {
-
+int
+setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
+{
uint32_t plane_id;
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
@@ -430,8 +430,9 @@ cleanup:
}
/* Free a plane and it's props. */
-static void
-free_plane(struct plane **plane) {
+void
+free_plane(struct plane **plane)
+{
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
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)
{
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index 9948897..1fa82ec 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -119,30 +119,18 @@ typedef struct KMSDRM_FBInfo
uint32_t fb_id; /* DRM framebuffer ID */
} 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 */
int KMSDRM_CreateSurfaces(_THIS, SDL_Window * window);
KMSDRM_FBInfo *KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo);
/* 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_waitpending(_THIS);
int drm_atomic_commit(_THIS, SDL_bool blocking);
-int drm_atomic_setcursor(KMSDRM_CursorData *curdata, int x, int y);
-int drm_atomic_movecursor(KMSDRM_CursorData *curdata, int x, int y);
+int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
+ 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 */