kmsdrm: Add error control to plane prop setting function. Do most plane prop setting with a single function.
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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c
index ec560be..6759b62 100644
--- a/src/video/kmsdrm/SDL_kmsdrmmouse.c
+++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c
@@ -44,58 +44,6 @@ static int KMSDRM_WarpMouseGlobal(int x, int y);
/**********************************/
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);
@@ -140,7 +88,6 @@ void alpha_premultiply_ARGB8888 (uint32_t *pixel) {
(*pixel) = (((uint32_t)A << 24) | ((uint32_t)R << 16) | ((uint32_t)G << 8)) | ((uint32_t)B << 0);
}
-
static SDL_Cursor *
KMSDRM_CreateDefaultCursor(void)
{
@@ -169,7 +116,7 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
SDL_assert(surface->pitch == surface->w * 4);
if (!KMSDRM_gbm_device_is_format_supported(viddata->gbm_dev, GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE)) {
- printf("Unsupported pixel format for cursor\n");
+ SDL_SetError("Unsupported pixel format for cursor");
return NULL;
}
@@ -291,6 +238,8 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
KMSDRM_CursorData *curdata;
SDL_VideoDisplay *display = NULL;
SDL_DisplayData *dispdata = NULL;
+ KMSDRM_FBInfo *fb;
+ KMSDRM_PlaneInfo info = {0};
int ret;
mouse = SDL_GetMouse();
@@ -305,18 +254,21 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
}
}
- /* Hide cursor */
+ /**********************************/
+ /* if cursor == NULL, HIDE cursor */
+ /**********************************/
if (!cursor) {
/* Hide CURRENT cursor, a cursor that is already on screen
and SDL stores in mouse->cur_cursor. */
if (mouse->cur_cursor && mouse->cur_cursor->driverdata) {
- curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
- if (curdata->video) {
-
- ret = drm_atomic_setcursor(0, 0, 0);
+ if (dispdata && dispdata->cursor_plane) {
+ info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */
+ ret = drm_atomic_set_plane_props(&info);
+ /* Free the plane on which the cursor was being shown. */
+ free_plane(&dispdata->cursor_plane);
if (ret) {
- SDL_SetError("Could not hide current cursor with drm_atomic_setcursor).");
+ SDL_SetError("Could not hide current cursor.");
return ret;
}
@@ -328,8 +280,10 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
return SDL_SetError("Couldn't find cursor to hide.");
}
-
- /* If cursor != NULL, show new cursor on display */
+ /************************************************/
+ /* If cursor != NULL, DO show cursor on display */
+ /************************************************/
+
if (!display) {
return SDL_SetError("Could not get display for mouse.");
}
@@ -338,15 +292,33 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
}
curdata = (KMSDRM_CursorData *) cursor->driverdata;
+
if (!curdata || !curdata->bo) {
return SDL_SetError("Cursor not initialized properly.");
}
curdata->crtc_id = dispdata->crtc->crtc->crtc_id;
- curdata->video = video_device;
+ curdata->plane = dispdata->cursor_plane;
+ curdata->video = video_device;
+
+ /* Init cursor plane, if we haven't yet. */
+ if (!dispdata->cursor_plane) {
+ setup_plane(curdata->video, &(dispdata->cursor_plane), DRM_PLANE_TYPE_CURSOR);
+ }
+
+ fb = KMSDRM_FBFromBO(curdata->video, curdata->bo);
+
+ info.plane = dispdata->cursor_plane;
+ info.crtc_id = curdata->crtc_id;
+ info.fb_id = fb->fb_id;
+ info.src_w = curdata->w;
+ info.src_h = curdata->h;
+ info.crtc_x = mouse->x - curdata->hot_x;
+ info.crtc_y = mouse->y - curdata->hot_y;
+ info.crtc_w = curdata->w;
+ info.crtc_h = curdata->h;
- /* DO show cursor */
- ret = drm_atomic_setcursor(curdata, mouse->x - curdata->hot_x, mouse->y - curdata->hot_y);
+ ret = drm_atomic_set_plane_props(&info);
if (ret) {
SDL_SetError("KMSDRM_SetCursor failed.");
@@ -356,12 +328,12 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
return 0;
}
-/* Unset the cursor from the cusror plane, and ONLY WHEN THAT'S DONE,
+/* Unset the cursor from the cursor plane, and ONLY WHEN THAT'S DONE,
DONE FOR REAL, and not only requested, destroy it by destroying the curso BO.
Destroying the cursor BO is an special an delicate situation,
- because drm_atomic_setcursor() returns immediately, and we DON'T
+ because drm_atomic_set_plane_props() returns immediately, and we DON'T
want to get to gbm_bo_destroy() before the prop changes requested
- in drm_atomic_setcursor() have effectively been done. So we
+ in drm_atomic_set_plane_props() have effectively been done. So we
issue a BLOCKING atomic_commit here to avoid that situation.
REMEMBER you yan issue an atomic_commit whenever you want, and
the changes requested until that moment (for any planes, crtcs, etc.)
@@ -371,12 +343,14 @@ KMSDRM_FreeCursor(SDL_Cursor * cursor)
{
KMSDRM_CursorData *curdata = NULL;
SDL_VideoDevice *video = NULL;
+ KMSDRM_PlaneInfo info = {0};
if (cursor) {
curdata = (KMSDRM_CursorData *) cursor->driverdata;
video = curdata->video;
- if (video && curdata->bo) {
- drm_atomic_setcursor(0, 0, 0);
+ if (video && curdata->bo && curdata->plane) {
+ info.plane = curdata->plane; /* The other members are zeroed. */
+ drm_atomic_set_plane_props(&info);
/* Wait until the cursor is unset from the cursor plane before destroying it's BO. */
drm_atomic_commit(video, SDL_TRUE);
KMSDRM_gbm_bo_destroy(curdata->bo);
@@ -427,6 +401,7 @@ KMSDRM_WarpMouseGlobal(int x, int y)
} else {
return SDL_SetError("No mouse or current cursor.");
}
+return 0;
}
void
diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.h b/src/video/kmsdrm/SDL_kmsdrmmouse.h
index 030bde4..8bb1200 100644
--- a/src/video/kmsdrm/SDL_kmsdrmmouse.h
+++ b/src/video/kmsdrm/SDL_kmsdrmmouse.h
@@ -33,6 +33,7 @@
typedef struct _KMSDRM_CursorData
{
struct gbm_bo *bo;
+ struct plane *plane;
uint32_t crtc_id;
int hot_x, hot_y;
int w, h;
diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c
index 4b3f6e0..5588dbf 100644
--- a/src/video/kmsdrm/SDL_kmsdrmopengles.c
+++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c
@@ -79,6 +79,7 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window)
SDL_WindowData *windata = ((SDL_WindowData *) window->driverdata);
SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
KMSDRM_FBInfo *fb;
+ KMSDRM_PlaneInfo info = {0};
int ret;
/*************************************************************************/
@@ -108,25 +109,37 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window)
/***************/
/* Lock the buffer that is marked by eglSwapBuffers() to become the next front buffer (so it can not
- be chosen by EGL as back buffer to draw on), and get a handle to it to request the pageflip on it. */
+ be chosen by EGL as back buffer to draw on), and get a handle to it to request the pageflip on it.
+ REMEMBER that gbm_surface_lock_front_buffer() ALWAYS has to be called after eglSwapBuffers(). */
windata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(windata->gs);
if (!windata->next_bo) {
- return SDL_SetError("Failed to lock frontbuffer on GBM surface destruction");
+ return SDL_SetError("Failed to lock frontbuffer");
}
fb = KMSDRM_FBFromBO(_this, windata->next_bo);
if (!fb) {
- return SDL_SetError("Failed to get a new framebuffer on GBM surface destruction");
+ return SDL_SetError("Failed to get a new framebuffer from BO");
}
- /* Add the pageflip to te request list. */
- drm_atomic_setbuffer(_this, dispdata->display_plane, fb->fb_id, dispdata->crtc->crtc->crtc_id);
+ /* Add the pageflip to the request list. */
+ info.plane = dispdata->display_plane;
+ info.crtc_id = dispdata->crtc->crtc->crtc_id;
+ info.fb_id = fb->fb_id;
+ info.src_w = dispdata->mode.hdisplay;
+ info.src_h = dispdata->mode.vdisplay;
+ info.crtc_w = dispdata->mode.hdisplay;
+ info.crtc_h = dispdata->mode.vdisplay;
+
+ ret = drm_atomic_set_plane_props(&info);
+ if (ret) {
+ return SDL_SetError("Failed to request prop changes for setting plane buffer and CRTC");
+ }
/* Issue the one and only atomic commit where all changes will be requested!.
We need e a non-blocking atomic commit for triple buffering, because we
must not block on this atomic commit so we can re-enter program loop once more. */
ret = drm_atomic_commit(_this, SDL_FALSE);
if (ret) {
- return SDL_SetError("failed to issue atomic commit on GBM surface destruction");
+ return SDL_SetError("Failed to issue atomic commit on pageflip");
}
/* Release the last front buffer so EGL can chose it as back buffer and render on it again. */
@@ -165,6 +178,7 @@ KMSDRM_GLES_SwapWindowDB(_THIS, SDL_Window * window)
SDL_WindowData *windata = ((SDL_WindowData *) window->driverdata);
SDL_DisplayData *dispdata = (SDL_DisplayData *) SDL_GetDisplayForWindow(window)->driverdata;
KMSDRM_FBInfo *fb;
+ KMSDRM_PlaneInfo info = {0};
int ret;
/* In double-buffer mode, atomic commit will always be synchronous/blocking (ie: won't return until
@@ -187,15 +201,26 @@ KMSDRM_GLES_SwapWindowDB(_THIS, SDL_Window * window)
return SDL_SetError("Failed to get a new framebuffer BO");
}
- /* Add the pageflip to te request list. */
- drm_atomic_setbuffer(_this, dispdata->display_plane, fb->fb_id, dispdata->crtc->crtc->crtc_id);
+ /* Add the pageflip to the request list. */
+ info.plane = dispdata->display_plane;
+ info.crtc_id = dispdata->crtc->crtc->crtc_id;
+ info.fb_id = fb->fb_id;
+ info.src_w = dispdata->mode.hdisplay;
+ info.src_h = dispdata->mode.vdisplay;
+ info.crtc_w = dispdata->mode.hdisplay;
+ info.crtc_h = dispdata->mode.vdisplay;
+
+ ret = drm_atomic_set_plane_props(&info);
+ if (ret) {
+ return SDL_SetError("Failed to request prop changes for setting plane buffer and CRTC");
+ }
/* Issue the one and only atomic commit where all changes will be requested!.
Blocking for double buffering: won't return until completed. */
ret = drm_atomic_commit(_this, SDL_TRUE);
if (ret) {
- return SDL_SetError("failed to issue atomic commit");
+ return SDL_SetError("Failed to issue atomic commit");
}
/* Release last front buffer so EGL can chose it as back buffer and render on it again. */
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index 2ff4951..aff994e 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -102,16 +102,15 @@ static int get_dricount(void)
struct stat sb;
DIR *folder;
- if (!(stat(KMSDRM_DRI_PATH, &sb) == 0
- && S_ISDIR(sb.st_mode))) {
- printf("The path %s cannot be opened or is not available\n",
- KMSDRM_DRI_PATH);
+ if (!(stat(KMSDRM_DRI_PATH, &sb) == 0 && S_ISDIR(sb.st_mode))) {
+ SDL_SetError("The path %s cannot be opened or is not available",
+ KMSDRM_DRI_PATH);
return 0;
}
if (access(KMSDRM_DRI_PATH, F_OK) == -1) {
- printf("The path %s cannot be opened\n",
- KMSDRM_DRI_PATH);
+ SDL_SetError("The path %s cannot be opened",
+ KMSDRM_DRI_PATH);
return 0;
}
@@ -154,44 +153,44 @@ get_driindex(void)
static int add_connector_property(drmModeAtomicReq *req, struct connector *connector,
const char *name, uint64_t value)
{
- unsigned int i;
- int prop_id = 0;
+ unsigned int i;
+ int prop_id = 0;
- for (i = 0 ; i < connector->props->count_props ; i++) {
- if (strcmp(connector->props_info[i]->name, name) == 0) {
- prop_id = connector->props_info[i]->prop_id;
- break;
- }
+ for (i = 0 ; i < connector->props->count_props ; i++) {
+ if (strcmp(connector->props_info[i]->name, name) == 0) {
+ prop_id = connector->props_info[i]->prop_id;
+ break;
}
+ }
- if (prop_id < 0) {
- printf("no connector property: %s\n", name);
- return -EINVAL;
- }
+ if (prop_id < 0) {
+ SDL_SetError("no connector property: %s", name);
+ return -EINVAL;
+ }
- return KMSDRM_drmModeAtomicAddProperty(req, connector->connector->connector_id, prop_id, value);
+ return KMSDRM_drmModeAtomicAddProperty(req, connector->connector->connector_id, prop_id, value);
}
#endif
static int add_crtc_property(drmModeAtomicReq *req, struct crtc *crtc,
const char *name, uint64_t value)
{
- unsigned int i;
- int prop_id = -1;
+ unsigned int i;
+ int prop_id = -1;
- for (i = 0 ; i < crtc->props->count_props ; i++) {
- if (strcmp(crtc->props_info[i]->name, name) == 0) {
- prop_id = crtc->props_info[i]->prop_id;
- break;
- }
+ for (i = 0 ; i < crtc->props->count_props ; i++) {
+ if (strcmp(crtc->props_info[i]->name, name) == 0) {
+ prop_id = crtc->props_info[i]->prop_id;
+ break;
}
+ }
- if (prop_id < 0) {
- printf("no crtc property: %s\n", name);
- return -EINVAL;
- }
+ if (prop_id < 0) {
+ SDL_SetError("no crtc property: %s", name);
+ return -EINVAL;
+ }
- return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value);
+ return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value);
}
int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
@@ -201,15 +200,15 @@ int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
int prop_id = -1;
for (i = 0 ; i < plane->props->count_props ; i++) {
- if (strcmp(plane->props_info[i]->name, name) == 0) {
- prop_id = plane->props_info[i]->prop_id;
- break;
- }
+ if (strcmp(plane->props_info[i]->name, name) == 0) {
+ prop_id = plane->props_info[i]->prop_id;
+ break;
+ }
}
if (prop_id < 0) {
- printf("no plane property: %s\n", name);
- return -EINVAL;
+ SDL_SetError("no plane property: %s", name);
+ return -EINVAL;
}
return KMSDRM_drmModeAtomicAddProperty(req, plane->plane->plane_id, prop_id, value);
@@ -466,8 +465,8 @@ free_plane(struct plane **plane)
/* first, move the plane away from those buffers and ONLY THEN destroy the */
/* buffers and/or the GBM surface containig them. */
/**********************************************************************************/
-void
-drm_atomic_setbuffer(_THIS, struct plane *plane, uint32_t fb_id, uint32_t crtc_id)
+int
+drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info)
{
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
@@ -475,22 +474,40 @@ drm_atomic_setbuffer(_THIS, struct plane *plane, uint32_t fb_id, uint32_t crtc_i
if (!dispdata->atomic_req)
dispdata->atomic_req = KMSDRM_drmModeAtomicAlloc();
- add_plane_property(dispdata->atomic_req, plane, "FB_ID", fb_id);
- add_plane_property(dispdata->atomic_req, plane, "CRTC_ID", crtc_id);
- add_plane_property(dispdata->atomic_req, plane, "SRC_W", dispdata->mode.hdisplay << 16);
- add_plane_property(dispdata->atomic_req, plane, "SRC_H", dispdata->mode.vdisplay << 16);
- add_plane_property(dispdata->atomic_req, plane, "SRC_X", 0);
- add_plane_property(dispdata->atomic_req, plane, "SRC_Y", 0);
- add_plane_property(dispdata->atomic_req, plane, "CRTC_W", dispdata->mode.hdisplay);
- add_plane_property(dispdata->atomic_req, plane, "CRTC_H", dispdata->mode.vdisplay);
- add_plane_property(dispdata->atomic_req, plane, "CRTC_X", 0);
- add_plane_property(dispdata->atomic_req, plane, "CRTC_Y", 0);
-
- if (dispdata->kms_in_fence_fd != -1) {
- add_crtc_property(dispdata->atomic_req, dispdata->crtc, "OUT_FENCE_PTR",
- VOID2U64(&dispdata->kms_out_fence_fd));
- add_plane_property(dispdata->atomic_req, plane, "IN_FENCE_FD", dispdata->kms_in_fence_fd);
+ if (add_plane_property(dispdata->atomic_req, info->plane, "FB_ID", info->fb_id) < 0)
+ return SDL_SetError("Failed to set plane FB_ID prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_ID", info->crtc_id) < 0)
+ return SDL_SetError("Failed to set plane CRTC_ID prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_W", info->src_w << 16) < 0)
+ return SDL_SetError("Failed to set plane SRC_W prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_H", info->src_h << 16) < 0)
+ return SDL_SetError("Failed to set plane SRC_H prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_X", info->src_x) < 0)
+ return SDL_SetError("Failed to set plane SRC_X prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "SRC_Y", info->src_y) < 0)
+ return SDL_SetError("Failed to set plane SRC_Y prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_W", info->crtc_w) < 0)
+ return SDL_SetError("Failed to set plane CRTC_W prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_H", info->crtc_h) < 0)
+ return SDL_SetError("Failed to set plane CRTC_H prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_X", info->crtc_x) < 0)
+ return SDL_SetError("Failed to set plane CRTC_X prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "CRTC_Y", info->crtc_y) < 0)
+ return SDL_SetError("Failed to set plane CRTC_Y prop");
+
+ /* Only set the IN_FENCE aqnd OUT_FENCE props if we're operationg on the display plane,
+ since that's the only plane for which we manage who and when should access the buffers
+ it uses. */
+ if ((info->plane == dispdata->display_plane) && (dispdata->kms_in_fence_fd != -1))
+ {
+ if (add_crtc_property(dispdata->atomic_req, dispdata->crtc, "OUT_FENCE_PTR",
+ VOID2U64(&dispdata->kms_out_fence_fd)) < 0)
+ return SDL_SetError("Failed to set CRTC OUT_FENCE_PTR prop");
+ if (add_plane_property(dispdata->atomic_req, info->plane, "IN_FENCE_FD", dispdata->kms_in_fence_fd) < 0)
+ return SDL_SetError("Failed to set plane IN_FENCE_FD prop");
}
+
+ return 0;
}
int drm_atomic_commit(_THIS, SDL_bool blocking)
@@ -507,8 +524,9 @@ int drm_atomic_commit(_THIS, SDL_bool blocking)
ret = KMSDRM_drmModeAtomicCommit(viddata->drm_fd, dispdata->atomic_req, dispdata->atomic_flags, NULL);
if (ret) {
- //SDL_SetError("Atomic commit failed, returned %d.", ret);
- printf("ATOMIC COMMIT FAILED: %d.\n", ret);
+ SDL_SetError("Atomic commit failed, returned %d.", ret);
+ /* Uncomment this for fast-debugging */
+ //printf("ATOMIC COMMIT FAILED: %d.\n", ret);
goto out;
}
@@ -753,7 +771,10 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window * window)
the display plane from the GBM surface buffer it's reading by setting
it's CRTC_ID and FB_ID props to 0.
*/
- drm_atomic_setbuffer(_this, dispdata->display_plane, 0, 0);
+ KMSDRM_PlaneInfo info = {0};
+ info.plane = dispdata->display_plane;
+
+ drm_atomic_set_plane_props(&info);
drm_atomic_commit(_this, SDL_TRUE);
if (windata->bo) {
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h
index 1fa82ec..10d7006 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.h
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -119,12 +119,29 @@ typedef struct KMSDRM_FBInfo
uint32_t fb_id; /* DRM framebuffer ID */
} KMSDRM_FBInfo;
+/* Info passed to set_plane_props calls. */
+typedef struct KMSDRM_PlaneInfo
+{
+ struct plane *plane;
+ uint32_t fb_id;
+ uint32_t crtc_id;
+ int src_x;
+ int src_y;
+ int src_w;
+ int src_h;
+ int crtc_x;
+ int crtc_y;
+ int crtc_w;
+ int crtc_h;
+} KMSDRM_PlaneInfo;
+
/* 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_setbuffer(_THIS, struct plane *plane, uint32_t fb_id, uint32_t crtc_id);
+int drm_atomic_set_plane_props(struct KMSDRM_PlaneInfo *info);
+
void drm_atomic_waitpending(_THIS);
int drm_atomic_commit(_THIS, SDL_bool blocking);
int add_plane_property(drmModeAtomicReq *req, struct plane *plane,