kmsdrm: Always use spaces for indentation. Always use SDL_calloc() for calloc.

This commit is contained in:
Manuel Alfayate Corchete 2020-10-22 16:01:51 +02:00
parent cfc1362011
commit 87a86675ed
5 changed files with 179 additions and 170 deletions

View File

@ -117,7 +117,9 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888); SDL_assert(surface->format->format == SDL_PIXELFORMAT_ARGB8888);
SDL_assert(surface->pitch == surface->w * 4); 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)) { if (!KMSDRM_gbm_device_is_format_supported(viddata->gbm_dev, GBM_FORMAT_ARGB8888,
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE))
{
SDL_SetError("Unsupported pixel format for cursor"); SDL_SetError("Unsupported pixel format for cursor");
return NULL; return NULL;
} }
@ -136,14 +138,15 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
/* Find out what GBM cursor size is recommended by the driver. */ /* Find out what GBM cursor size is recommended by the driver. */
if (KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_WIDTH, &usable_cursor_w) || if (KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_WIDTH, &usable_cursor_w) ||
KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_HEIGHT, &usable_cursor_h)) { KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_HEIGHT, &usable_cursor_h))
SDL_SetError("Could not get the recommended GBM cursor size"); {
goto cleanup; SDL_SetError("Could not get the recommended GBM cursor size");
goto cleanup;
} }
if (usable_cursor_w == 0 || usable_cursor_h == 0) { if (usable_cursor_w == 0 || usable_cursor_h == 0) {
SDL_SetError("Could not get an usable GBM cursor size"); SDL_SetError("Could not get an usable GBM cursor size");
goto cleanup; goto cleanup;
} }
/* hox_x and hot_y are the coordinates of the "tip of the cursor" from it's base. */ /* hox_x and hot_y are the coordinates of the "tip of the cursor" from it's base. */
@ -152,8 +155,8 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
curdata->w = usable_cursor_w; curdata->w = usable_cursor_w;
curdata->h = usable_cursor_h; curdata->h = usable_cursor_h;
curdata->bo = KMSDRM_gbm_bo_create(viddata->gbm_dev, usable_cursor_w, usable_cursor_h, GBM_FORMAT_ARGB8888, curdata->bo = KMSDRM_gbm_bo_create(viddata->gbm_dev, usable_cursor_w, usable_cursor_h,
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE); GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
if (!curdata->bo) { if (!curdata->bo) {
SDL_SetError("Could not create GBM cursor BO"); SDL_SetError("Could not create GBM cursor BO");
@ -169,15 +172,15 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
SDL surface, line by line, to a gbm BO with different pitch. */ SDL surface, line by line, to a gbm BO with different pitch. */
buffer = (uint32_t*)SDL_malloc(bufsize); buffer = (uint32_t*)SDL_malloc(bufsize);
if (!buffer) { if (!buffer) {
SDL_OutOfMemory(); SDL_OutOfMemory();
goto cleanup; goto cleanup;
} }
if (SDL_MUSTLOCK(surface)) { if (SDL_MUSTLOCK(surface)) {
if (SDL_LockSurface(surface) < 0) { if (SDL_LockSurface(surface) < 0) {
/* Could not lock surface */ /* Could not lock surface */
goto cleanup; goto cleanup;
} }
} }
/* Clean the whole temporary buffer. */ /* Clean the whole temporary buffer. */
@ -188,17 +191,17 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
for (j = 0; j < surface->w; j++) { for (j = 0; j < surface->w; j++) {
pixel = ((uint32_t*)surface->pixels)[i * surface->w + j]; pixel = ((uint32_t*)surface->pixels)[i * surface->w + j];
alpha_premultiply_ARGB8888 (&pixel); alpha_premultiply_ARGB8888 (&pixel);
SDL_memcpy(buffer + (i * curdata->w) + j, &pixel, 4); SDL_memcpy(buffer + (i * curdata->w) + j, &pixel, 4);
} }
} }
if (SDL_MUSTLOCK(surface)) { if (SDL_MUSTLOCK(surface)) {
SDL_UnlockSurface(surface); SDL_UnlockSurface(surface);
} }
if (KMSDRM_gbm_bo_write(curdata->bo, buffer, bufsize)) { if (KMSDRM_gbm_bo_write(curdata->bo, buffer, bufsize)) {
SDL_SetError("Could not write to GBM cursor BO"); SDL_SetError("Could not write to GBM cursor BO");
goto cleanup; goto cleanup;
} }
/* Free temporary buffer */ /* Free temporary buffer */
@ -261,14 +264,14 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
/* Hide CURRENT cursor, a cursor that is already on screen /* Hide CURRENT cursor, a cursor that is already on screen
and SDL is stored in mouse->cur_cursor. */ and SDL is stored in mouse->cur_cursor. */
if (mouse->cur_cursor && mouse->cur_cursor->driverdata) { if (mouse->cur_cursor && mouse->cur_cursor->driverdata) {
if (dispdata && dispdata->cursor_plane) { if (dispdata && dispdata->cursor_plane) {
info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */ info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */
drm_atomic_set_plane_props(&info); drm_atomic_set_plane_props(&info);
if (drm_atomic_commit(display->device, SDL_TRUE)) if (drm_atomic_commit(display->device, SDL_TRUE))
return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor."); return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor.");
} }
return 0; return 0;
} }
return SDL_SetError("Couldn't find cursor to hide."); return SDL_SetError("Couldn't find cursor to hide.");
} }
@ -335,18 +338,18 @@ KMSDRM_FreeCursor(SDL_Cursor * cursor)
curdata = (KMSDRM_CursorData *) cursor->driverdata; curdata = (KMSDRM_CursorData *) cursor->driverdata;
if (video_device && curdata->bo && curdata->plane) { if (video_device && curdata->bo && curdata->plane) {
info.plane = curdata->plane; /* The other members are zeroed. */ info.plane = curdata->plane; /* The other members are zeroed. */
drm_atomic_set_plane_props(&info); drm_atomic_set_plane_props(&info);
/* Wait until the cursor is unset from the cursor plane before destroying it's BO. */ /* Wait until the cursor is unset from the cursor plane before destroying it's BO. */
if (drm_atomic_commit(video_device, SDL_TRUE)) { if (drm_atomic_commit(video_device, SDL_TRUE)) {
SDL_SetError("Failed atomic commit in KMSDRM_FreeCursor."); SDL_SetError("Failed atomic commit in KMSDRM_FreeCursor.");
} }
KMSDRM_gbm_bo_destroy(curdata->bo); KMSDRM_gbm_bo_destroy(curdata->bo);
curdata->bo = NULL; curdata->bo = NULL;
} }
/* Even if the cursor is not ours, free it. */ /* Even if the cursor is not ours, free it. */
SDL_free(cursor->driverdata); SDL_free(cursor->driverdata);
SDL_free(cursor); SDL_free(cursor);
} }
} }
@ -372,11 +375,9 @@ KMSDRM_WarpMouseGlobal(int x, int y)
/* And now update the cursor graphic position on screen. */ /* And now update the cursor graphic position on screen. */
curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata; curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->bo) { if (curdata->bo) {
if (drm_atomic_movecursor(curdata, x, y)) {
if (drm_atomic_movecursor(curdata, x, y)) { return SDL_SetError("drm_atomic_movecursor() failed.");
return SDL_SetError("drm_atomic_movecursor() failed."); }
}
} else { } else {
return SDL_SetError("Cursor not initialized properly."); return SDL_SetError("Cursor not initialized properly.");
} }
@ -405,7 +406,7 @@ KMSDRM_InitMouse(_THIS)
/* Init cursor plane, if we haven't yet. */ /* Init cursor plane, if we haven't yet. */
if (!dispdata->cursor_plane) { if (!dispdata->cursor_plane) {
setup_plane(_this, &(dispdata->cursor_plane), DRM_PLANE_TYPE_CURSOR); setup_plane(_this, &(dispdata->cursor_plane), DRM_PLANE_TYPE_CURSOR);
} }
SDL_SetDefaultCursor(KMSDRM_CreateDefaultCursor()); SDL_SetDefaultCursor(KMSDRM_CreateDefaultCursor());
@ -436,9 +437,9 @@ KMSDRM_MoveCursor(SDL_Cursor * cursor)
cursor movement request, but it cripples the movement to 30FPS, so a future solution cursor movement request, but it cripples the movement to 30FPS, so a future solution
is needed. SDLPoP "QUIT?" menu is an example of this situation. */ is needed. SDLPoP "QUIT?" menu is an example of this situation. */
if (drm_atomic_movecursor(curdata, mouse->x, mouse->y)) { if (drm_atomic_movecursor(curdata, mouse->x, mouse->y)) {
SDL_SetError("drm_atomic_movecursor() failed."); SDL_SetError("drm_atomic_movecursor() failed.");
} }
} }
} }

View File

@ -90,14 +90,15 @@ int KMSDRM_GLES_SetSwapInterval(_THIS, int interval) {
static EGLSyncKHR create_fence(int fd, _THIS) static EGLSyncKHR create_fence(int fd, _THIS)
{ {
EGLint attrib_list[] = { EGLint attrib_list[] = {
EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fd, EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fd,
EGL_NONE, EGL_NONE,
}; };
EGLSyncKHR fence = _this->egl_data->eglCreateSyncKHR(_this->egl_data->egl_display, EGLSyncKHR fence = _this->egl_data->eglCreateSyncKHR
EGL_SYNC_NATIVE_FENCE_ANDROID, attrib_list); (_this->egl_data->egl_display, EGL_SYNC_NATIVE_FENCE_ANDROID, attrib_list);
assert(fence);
return fence; assert(fence);
return fence;
} }
/***********************************************************************************/ /***********************************************************************************/
@ -132,6 +133,7 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
if (! _this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, windata->egl_surface)) { if (! _this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, windata->egl_surface)) {
return SDL_EGL_SetError("Failed to swap EGL buffers", "eglSwapBuffers"); return SDL_EGL_SetError("Failed to swap EGL buffers", "eglSwapBuffers");
} }
/******************************************************************/ /******************************************************************/
/* EXPORT the GPU-side FENCE OBJECT to the fence INPUT FD, so we */ /* EXPORT the GPU-side FENCE OBJECT to the fence INPUT FD, so we */
/* can pass it into the kernel. Atomic ioctl will pass the */ /* can pass it into the kernel. Atomic ioctl will pass the */
@ -144,8 +146,8 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
/* in the CMDSTREAM to be lifted when the CMDSTREAM to this point */ /* in the CMDSTREAM to be lifted when the CMDSTREAM to this point */
/* is completed). */ /* is completed). */
/******************************************************************/ /******************************************************************/
dispdata->kms_in_fence_fd = _this->egl_data->eglDupNativeFenceFDANDROID dispdata->kms_in_fence_fd = _this->egl_data->eglDupNativeFenceFDANDROID (_this->egl_data->egl_display,
(_this->egl_data->egl_display, dispdata->gpu_fence); dispdata->gpu_fence);
_this->egl_data->eglDestroySyncKHR(_this->egl_data->egl_display, dispdata->gpu_fence); _this->egl_data->eglDestroySyncKHR(_this->egl_data->egl_display, dispdata->gpu_fence);
assert(dispdata->kms_in_fence_fd != -1); assert(dispdata->kms_in_fence_fd != -1);
@ -157,11 +159,11 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
called after eglSwapBuffers(). */ called after eglSwapBuffers(). */
windata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(windata->gs); windata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(windata->gs);
if (!windata->next_bo) { if (!windata->next_bo) {
return SDL_SetError("Failed to lock frontbuffer"); return SDL_SetError("Failed to lock frontbuffer");
} }
fb = KMSDRM_FBFromBO(_this, windata->next_bo); fb = KMSDRM_FBFromBO(_this, windata->next_bo);
if (!fb) { if (!fb) {
return SDL_SetError("Failed to get a new framebuffer from BO"); return SDL_SetError("Failed to get a new framebuffer from BO");
} }
/* Add the pageflip to the request list. */ /* Add the pageflip to the request list. */
@ -196,19 +198,20 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
/*****************************************************************/ /*****************************************************************/
if (dispdata->kms_in_fence_fd != -1) if (dispdata->kms_in_fence_fd != -1)
{ {
add_plane_property(dispdata->atomic_req, dispdata->display_plane, add_plane_property(dispdata->atomic_req, dispdata->display_plane,
"IN_FENCE_FD", dispdata->kms_in_fence_fd); "IN_FENCE_FD", dispdata->kms_in_fence_fd);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, add_crtc_property(dispdata->atomic_req, dispdata->crtc,
"OUT_FENCE_PTR", VOID2U64(&dispdata->kms_out_fence_fd)); "OUT_FENCE_PTR", VOID2U64(&dispdata->kms_out_fence_fd));
} }
/* Do we have a pending modesetting? If so, set the necessary /* Do we have a pending modesetting? If so, set the necessary
props so it's included in the incoming atomic commit. */ props so it's included in the incoming atomic commit. */
if (dispdata->modeset_pending) { if (dispdata->modeset_pending) {
uint32_t blob_id;
SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
uint32_t blob_id;
dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET; dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id); add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id); KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id); add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1); add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1);
@ -227,7 +230,7 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
/* Release the previous front buffer so EGL can chose it as back buffer /* Release the previous front buffer so EGL can chose it as back buffer
and render on it again. */ and render on it again. */
if (windata->bo) { if (windata->bo) {
KMSDRM_gbm_surface_release_buffer(windata->gs, windata->bo); KMSDRM_gbm_surface_release_buffer(windata->gs, windata->bo);
} }
/* Take note of the buffer about to become front buffer, so next /* Take note of the buffer about to become front buffer, so next
@ -308,9 +311,9 @@ KMSDRM_GLES_SwapWindowDoubleBuffered(_THIS, SDL_Window * window)
props so it's included in the incoming atomic commit. */ props so it's included in the incoming atomic commit. */
if (dispdata->modeset_pending) { if (dispdata->modeset_pending) {
SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata; SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
uint32_t blob_id; uint32_t blob_id;
dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET; dispdata->atomic_flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id); add_connector_property(dispdata->atomic_req, dispdata->connector, "CRTC_ID", dispdata->crtc->crtc->crtc_id);
KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id); KMSDRM_drmModeCreatePropertyBlob(viddata->drm_fd, &dispdata->mode, sizeof(dispdata->mode), &blob_id);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id); add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1); add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1);
@ -325,7 +328,7 @@ KMSDRM_GLES_SwapWindowDoubleBuffered(_THIS, SDL_Window * window)
/* Release last front buffer so EGL can chose it as back buffer and render on it again. */ /* Release last front buffer so EGL can chose it as back buffer and render on it again. */
if (windata->bo) { if (windata->bo) {
KMSDRM_gbm_surface_release_buffer(windata->gs, windata->bo); KMSDRM_gbm_surface_release_buffer(windata->gs, windata->bo);
} }
/* Take note of current front buffer, so we can free it next time we come here. */ /* Take note of current front buffer, so we can free it next time we come here. */
@ -352,7 +355,8 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window)
if (windata->swap_window == NULL) { if (windata->swap_window == NULL) {
/* We want the fenced version by default, but it needs extensions. */ /* We want the fenced version by default, but it needs extensions. */
if ( (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) || if ( (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) ||
(!SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_ANDROID_native_fence_sync")) ) { (!SDL_EGL_HasExtension(_this, SDL_EGL_DISPLAY_EXTENSION, "EGL_ANDROID_native_fence_sync")) )
{
windata->swap_window = KMSDRM_GLES_SwapWindowDoubleBuffered; windata->swap_window = KMSDRM_GLES_SwapWindowDoubleBuffered;
} else { } else {
windata->swap_window = KMSDRM_GLES_SwapWindowFenced; windata->swap_window = KMSDRM_GLES_SwapWindowFenced;

View File

@ -49,15 +49,15 @@ SDL_KMSDRM_SYM(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_
uint32_t *buf_id)) uint32_t *buf_id))
SDL_KMSDRM_SYM(int,drmModeAddFB2,(int fd, uint32_t width, uint32_t height, SDL_KMSDRM_SYM(int,drmModeAddFB2,(int fd, uint32_t width, uint32_t height,
uint32_t pixel_format, const uint32_t bo_handles[4], uint32_t pixel_format, const uint32_t bo_handles[4],
const uint32_t pitches[4], const uint32_t offsets[4], const uint32_t pitches[4], const uint32_t offsets[4],
uint32_t *buf_id, uint32_t flags)) uint32_t *buf_id, uint32_t flags))
SDL_KMSDRM_SYM(int,drmModeAddFB2WithModifiers,(int fd, uint32_t width, uint32_t height, SDL_KMSDRM_SYM(int,drmModeAddFB2WithModifiers,(int fd, uint32_t width, uint32_t height,
uint32_t pixel_format, const uint32_t bo_handles[4], uint32_t pixel_format, const uint32_t bo_handles[4],
const uint32_t pitches[4], const uint32_t offsets[4], const uint32_t pitches[4], const uint32_t offsets[4],
const uint64_t modifier[4], uint32_t *buf_id, const uint64_t modifier[4], uint32_t *buf_id,
uint32_t flags)) uint32_t flags))
SDL_KMSDRM_SYM(int,drmModeRmFB,(int fd, uint32_t bufferId)) SDL_KMSDRM_SYM(int,drmModeRmFB,(int fd, uint32_t bufferId))
SDL_KMSDRM_SYM(drmModeFBPtr,drmModeGetFB,(int fd, uint32_t buf)) SDL_KMSDRM_SYM(drmModeFBPtr,drmModeGetFB,(int fd, uint32_t buf))

View File

@ -157,11 +157,16 @@ static dumb_buffer *KMSDRM_CreateDumbBuffer(_THIS)
SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata);
SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0); SDL_DisplayData *dispdata = (SDL_DisplayData *)SDL_GetDisplayDriverData(0);
dumb_buffer *ret = calloc(1, sizeof(*ret));
struct drm_mode_create_dumb create; struct drm_mode_create_dumb create;
struct drm_mode_map_dumb map; struct drm_mode_map_dumb map;
struct drm_mode_destroy_dumb destroy; struct drm_mode_destroy_dumb destroy;
dumb_buffer *ret = SDL_calloc(1, sizeof(*ret));
if (!ret)
SDL_OutOfMemory();
return NULL;
}
/* /*
* The create ioctl uses the combination of depth and bpp to infer * The create ioctl uses the combination of depth and bpp to infer
* a format; 24/32 refers to DRM_FORMAT_XRGB8888 as defined in * a format; 24/32 refers to DRM_FORMAT_XRGB8888 as defined in
@ -174,14 +179,14 @@ static dumb_buffer *KMSDRM_CreateDumbBuffer(_THIS)
* for us, also returning us the GEM handle. * for us, also returning us the GEM handle.
*/ */
create = (struct drm_mode_create_dumb) { create = (struct drm_mode_create_dumb) {
.width = dispdata->mode.hdisplay, .width = dispdata->mode.hdisplay,
.height = dispdata->mode.vdisplay, .height = dispdata->mode.vdisplay,
.bpp = 32, .bpp = 32,
}; };
if (KMSDRM_drmIoctl(viddata->drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create)) { if (KMSDRM_drmIoctl(viddata->drm_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create)) {
SDL_SetError("failed to create dumb buffer\n"); SDL_SetError("failed to create dumb buffer\n");
goto err; goto err;
} }
ret->gem_handles[0] = create.handle; ret->gem_handles[0] = create.handle;
@ -247,10 +252,10 @@ KMSDRM_FillDumbBuffer(dumb_buffer *buffer)
{ {
unsigned int x, y; unsigned int x, y;
for (y = 0; y < buffer->height; y++) { for (y = 0; y < buffer->height; y++) {
uint32_t *pix = (uint32_t *) ((uint8_t *) buffer->dumb.mem + (y * buffer->pitches[0])); uint32_t *pix = (uint32_t *) ((uint8_t *) buffer->dumb.mem + (y * buffer->pitches[0]));
for (x = 0; x < buffer->width; x++) { for (x = 0; x < buffer->width; x++) {
*pix++ = (0x00000000); *pix++ = (0x00000000);
} }
} }
} }
@ -302,15 +307,15 @@ int add_connector_property(drmModeAtomicReq *req, struct connector *connector,
int prop_id = 0; int prop_id = 0;
for (i = 0 ; i < connector->props->count_props ; i++) { for (i = 0 ; i < connector->props->count_props ; i++) {
if (strcmp(connector->props_info[i]->name, name) == 0) { if (strcmp(connector->props_info[i]->name, name) == 0) {
prop_id = connector->props_info[i]->prop_id; prop_id = connector->props_info[i]->prop_id;
break; break;
} }
} }
if (prop_id < 0) { if (prop_id < 0) {
SDL_SetError("no connector property: %s", name); SDL_SetError("no connector property: %s", name);
return -EINVAL; return -EINVAL;
} }
return KMSDRM_drmModeAtomicAddProperty(req, connector->connector->connector_id, prop_id, value); return KMSDRM_drmModeAtomicAddProperty(req, connector->connector->connector_id, prop_id, value);
@ -323,15 +328,15 @@ int add_crtc_property(drmModeAtomicReq *req, struct crtc *crtc,
int prop_id = -1; int prop_id = -1;
for (i = 0 ; i < crtc->props->count_props ; i++) { for (i = 0 ; i < crtc->props->count_props ; i++) {
if (strcmp(crtc->props_info[i]->name, name) == 0) { if (strcmp(crtc->props_info[i]->name, name) == 0) {
prop_id = crtc->props_info[i]->prop_id; prop_id = crtc->props_info[i]->prop_id;
break; break;
} }
} }
if (prop_id < 0) { if (prop_id < 0) {
SDL_SetError("no crtc property: %s", name); SDL_SetError("no crtc property: %s", name);
return -EINVAL; return -EINVAL;
} }
return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value); return KMSDRM_drmModeAtomicAddProperty(req, crtc->crtc->crtc_id, prop_id, value);
@ -345,8 +350,8 @@ int add_plane_property(drmModeAtomicReq *req, struct plane *plane,
for (i = 0 ; i < plane->props->count_props ; i++) { for (i = 0 ; i < plane->props->count_props ; i++) {
if (strcmp(plane->props_info[i]->name, name) == 0) { if (strcmp(plane->props_info[i]->name, name) == 0) {
prop_id = plane->props_info[i]->prop_id; prop_id = plane->props_info[i]->prop_id;
break; break;
} }
} }
@ -373,27 +378,27 @@ void print_plane_info(_THIS, drmModePlanePtr plane)
/* Search the plane props for the plane type. */ /* Search the plane props for the plane type. */
for (int j = 0; j < props->count_props; j++) { for (int j = 0; j < props->count_props; j++) {
drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd, props->props[j]); drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd, props->props[j]);
if ((strcmp(p->name, "type") == 0)) { if ((strcmp(p->name, "type") == 0)) {
type = props->prop_values[j]; type = props->prop_values[j];
} }
KMSDRM_drmModeFreeProperty(p); KMSDRM_drmModeFreeProperty(p);
} }
switch (type) { switch (type) {
case DRM_PLANE_TYPE_OVERLAY: case DRM_PLANE_TYPE_OVERLAY:
plane_type = "overlay"; plane_type = "overlay";
break; break;
case DRM_PLANE_TYPE_PRIMARY: case DRM_PLANE_TYPE_PRIMARY:
plane_type = "primary"; plane_type = "primary";
break; break;
case DRM_PLANE_TYPE_CURSOR: case DRM_PLANE_TYPE_CURSOR:
plane_type = "cursor"; plane_type = "cursor";
break; break;
} }
@ -408,11 +413,11 @@ void print_plane_info(_THIS, drmModePlanePtr plane)
printf("--PLANE ID: %d\nPLANE TYPE: %s\nCRTC READING THIS PLANE: %d\nCRTCS SUPPORTED BY THIS PLANE: ", plane->plane_id, plane_type, plane->crtc_id); printf("--PLANE ID: %d\nPLANE TYPE: %s\nCRTC READING THIS PLANE: %d\nCRTCS SUPPORTED BY THIS PLANE: ", plane->plane_id, plane_type, plane->crtc_id);
for (int i = 0; i < resources->count_crtcs; i++) { for (int i = 0; i < resources->count_crtcs; i++) {
if (plane->possible_crtcs & (1 << i)) { if (plane->possible_crtcs & (1 << i)) {
uint32_t crtc_id = resources->crtcs[i]; uint32_t crtc_id = resources->crtcs[i];
printf ("%d", crtc_id); printf ("%d", crtc_id);
break; break;
} }
} }
printf ("\n\n"); printf ("\n\n");
@ -428,8 +433,8 @@ void get_planes_info(_THIS)
plane_resources = KMSDRM_drmModeGetPlaneResources(viddata->drm_fd); plane_resources = KMSDRM_drmModeGetPlaneResources(viddata->drm_fd);
if (!plane_resources) { if (!plane_resources) {
printf("drmModeGetPlaneResources failed: %s\n", strerror(errno)); printf("drmModeGetPlaneResources failed: %s\n", strerror(errno));
return; return;
} }
printf("--Number of planes found: %d-- \n", plane_resources->count_planes); printf("--Number of planes found: %d-- \n", plane_resources->count_planes);
@ -440,11 +445,11 @@ void get_planes_info(_THIS)
uint32_t plane_id = plane_resources->planes[i]; uint32_t plane_id = plane_resources->planes[i];
drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id); drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id);
if (!plane) { if (!plane) {
printf("drmModeGetPlane(%u) failed: %s\n", plane_id, strerror(errno)); printf("drmModeGetPlane(%u) failed: %s\n", plane_id, strerror(errno));
continue; continue;
} }
/* Print plane info. */ /* Print plane info. */
print_plane_info(_this, plane); print_plane_info(_this, plane);
@ -475,54 +480,53 @@ static int get_plane_id(_THIS, uint32_t plane_type)
/* Get the crtc_index for the current CRTC. /* Get the crtc_index for the current CRTC.
It's needed to find out if a plane supports the CRTC. */ It's needed to find out if a plane supports the CRTC. */
for (i = 0; i < resources->count_crtcs; i++) { for (i = 0; i < resources->count_crtcs; i++) {
if (resources->crtcs[i] == dispdata->crtc->crtc->crtc_id) { if (resources->crtcs[i] == dispdata->crtc->crtc->crtc_id) {
crtc_index = i; crtc_index = i;
break; break;
} }
} }
plane_resources = KMSDRM_drmModeGetPlaneResources(viddata->drm_fd); plane_resources = KMSDRM_drmModeGetPlaneResources(viddata->drm_fd);
if (!plane_resources) { if (!plane_resources) {
return SDL_SetError("drmModeGetPlaneResources failed."); return SDL_SetError("drmModeGetPlaneResources failed.");
} }
/* Iterate on all the available planes. */ /* Iterate on all the available planes. */
for (i = 0; (i < plane_resources->count_planes) && !found; i++) { for (i = 0; (i < plane_resources->count_planes) && !found; i++) {
uint32_t plane_id = plane_resources->planes[i]; uint32_t plane_id = plane_resources->planes[i];
drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id); drmModePlanePtr plane = KMSDRM_drmModeGetPlane(viddata->drm_fd, plane_id);
if (!plane) { if (!plane) {
continue; continue;
} }
/* See if the current CRTC is available for this plane. */ /* See if the current CRTC is available for this plane. */
if (plane->possible_crtcs & (1 << crtc_index)) { if (plane->possible_crtcs & (1 << crtc_index)) {
drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd, drmModeObjectPropertiesPtr props = KMSDRM_drmModeObjectGetProperties(
plane_id, DRM_MODE_OBJECT_PLANE); viddata->drm_fd, plane_id, DRM_MODE_OBJECT_PLANE);
ret = plane_id; ret = plane_id;
/* Iterate on the plane props to find the type of the plane, /* Iterate on the plane props to find the type of the plane,
to see if it's of the type we want. */ to see if it's of the type we want. */
for (j = 0; j < props->count_props; j++) { for (j = 0; j < props->count_props; j++) {
drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd, drmModePropertyPtr p = KMSDRM_drmModeGetProperty(viddata->drm_fd,
props->props[j]); props->props[j]);
if ((strcmp(p->name, "type") == 0) && if ((strcmp(p->name, "type") == 0) && (props->prop_values[j] == plane_type)) {
(props->prop_values[j] == plane_type)) { /* found our plane, use that: */
/* found our plane, use that: */ found = 1;
found = 1; }
}
KMSDRM_drmModeFreeProperty(p); KMSDRM_drmModeFreeProperty(p);
} }
KMSDRM_drmModeFreeObjectProperties(props); KMSDRM_drmModeFreeObjectProperties(props);
} }
KMSDRM_drmModeFreePlane(plane); KMSDRM_drmModeFreePlane(plane);
} }
KMSDRM_drmModeFreePlaneResources(plane_resources); KMSDRM_drmModeFreePlaneResources(plane_resources);
@ -554,7 +558,7 @@ setup_plane(_THIS, struct plane **plane, uint32_t plane_type)
if ((*plane)->plane) { if ((*plane)->plane) {
unsigned int i; unsigned int i;
(*plane)->props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd, (*plane)->props = KMSDRM_drmModeObjectGetProperties(viddata->drm_fd,
(*plane)->plane->plane_id, DRM_MODE_OBJECT_PLANE); (*plane)->plane->plane_id, DRM_MODE_OBJECT_PLANE);
(*plane)->props_info = SDL_calloc((*plane)->props->count_props, (*plane)->props_info = SDL_calloc((*plane)->props->count_props,
sizeof(*(*plane)->props_info)); sizeof(*(*plane)->props_info));
@ -647,12 +651,12 @@ int drm_atomic_commit(_THIS, SDL_bool blocking)
SDL_SetError("Atomic commit failed, returned %d.", ret); SDL_SetError("Atomic commit failed, returned %d.", ret);
/* Uncomment this for fast-debugging */ /* Uncomment this for fast-debugging */
// printf("ATOMIC COMMIT FAILED: %d.\n", ret); // printf("ATOMIC COMMIT FAILED: %d.\n", ret);
goto out; goto out;
} }
if (dispdata->kms_in_fence_fd != -1) { if (dispdata->kms_in_fence_fd != -1) {
close(dispdata->kms_in_fence_fd); close(dispdata->kms_in_fence_fd);
dispdata->kms_in_fence_fd = -1; dispdata->kms_in_fence_fd = -1;
} }
out: out:
@ -671,15 +675,15 @@ drm_atomic_waitpending(_THIS)
/* Will return immediately if we have already destroyed the fence, because we NULL-ify it just after. /* Will return immediately if we have already destroyed the fence, because we NULL-ify it just after.
Also, will return immediately in double-buffer mode, because kms_fence will alsawys be NULL. */ Also, will return immediately in double-buffer mode, because kms_fence will alsawys be NULL. */
if (dispdata->kms_fence) { if (dispdata->kms_fence) {
EGLint status; EGLint status;
do { do {
status = _this->egl_data->eglClientWaitSyncKHR(_this->egl_data->egl_display, status = _this->egl_data->eglClientWaitSyncKHR(_this->egl_data->egl_display,
dispdata->kms_fence, 0, EGL_FOREVER_KHR); dispdata->kms_fence, 0, EGL_FOREVER_KHR);
} while (status != EGL_CONDITION_SATISFIED_KHR); } while (status != EGL_CONDITION_SATISFIED_KHR);
_this->egl_data->eglDestroySyncKHR(_this->egl_data->egl_display, dispdata->kms_fence); _this->egl_data->eglDestroySyncKHR(_this->egl_data->egl_display, dispdata->kms_fence);
dispdata->kms_fence = NULL; dispdata->kms_fence = NULL;
} }
} }
@ -883,16 +887,16 @@ KMSDRM_FBFromBO(_THIS, struct gbm_bo *bo)
format = KMSDRM_gbm_bo_get_format(bo); format = KMSDRM_gbm_bo_get_format(bo);
for (i = 0; i < num_planes; i++) { for (i = 0; i < num_planes; i++) {
strides[i] = KMSDRM_gbm_bo_get_stride_for_plane(bo, i); strides[i] = KMSDRM_gbm_bo_get_stride_for_plane(bo, i);
handles[i] = KMSDRM_gbm_bo_get_handle(bo).u32; handles[i] = KMSDRM_gbm_bo_get_handle(bo).u32;
offsets[i] = KMSDRM_gbm_bo_get_offset(bo, i); offsets[i] = KMSDRM_gbm_bo_get_offset(bo, i);
} }
/* Create framebuffer object for the buffer. /* Create framebuffer object for the buffer.
It's VERY important to note that fb_id is what we ise to set the FB_ID prop of a plane It's VERY important to note that fb_id is what we ise to set the FB_ID prop of a plane
when using the ATOMIC interface, and we get fb_id it here. */ when using the ATOMIC interface, and we get fb_id it here. */
ret = KMSDRM_drmModeAddFB2(viddata->drm_fd, width, height, format, ret = KMSDRM_drmModeAddFB2(viddata->drm_fd, width, height, format,
handles, strides, offsets, &fb_info->fb_id, 0); handles, strides, offsets, &fb_info->fb_id, 0);
if (ret) { if (ret) {
SDL_free(fb_info); SDL_free(fb_info);
@ -960,8 +964,8 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window *window)
} }
if (windata->next_bo) { if (windata->next_bo) {
KMSDRM_gbm_surface_release_buffer(windata->gs, windata->next_bo); KMSDRM_gbm_surface_release_buffer(windata->gs, windata->next_bo);
windata->next_bo = NULL; windata->next_bo = NULL;
} }
/* Destroy the EGL surface. */ /* Destroy the EGL surface. */
@ -985,8 +989,8 @@ KMSDRM_DestroySurfaces(_THIS, SDL_Window *window)
#endif #endif
if (windata->gs) { if (windata->gs) {
KMSDRM_gbm_surface_destroy(windata->gs); KMSDRM_gbm_surface_destroy(windata->gs);
windata->gs = NULL; windata->gs = NULL;
} }
} }
@ -1114,7 +1118,7 @@ KMSDRM_ReconfigureWindow( _THIS, SDL_Window * window) {
} }
if (KMSDRM_CreateSurfaces(_this, window)) { if (KMSDRM_CreateSurfaces(_this, window)) {
return -1; return -1;
} }
return 0; return 0;
@ -1133,9 +1137,9 @@ KMSDRM_VideoInit(_THIS)
SDL_VideoDisplay display = {0}; SDL_VideoDisplay display = {0};
dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData)); dispdata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
dispdata->display_plane = calloc(1, sizeof(*dispdata->display_plane)); dispdata->display_plane = SDL_calloc(1, sizeof(*dispdata->display_plane));
dispdata->crtc = calloc(1, sizeof(*dispdata->crtc)); dispdata->crtc = SDL_calloc(1, sizeof(*dispdata->crtc));
dispdata->connector = calloc(1, sizeof(*dispdata->connector)); dispdata->connector = SDL_calloc(1, sizeof(*dispdata->connector));
dispdata->atomic_flags = 0; dispdata->atomic_flags = 0;
dispdata->atomic_req = NULL; dispdata->atomic_req = NULL;
@ -1333,7 +1337,7 @@ KMSDRM_VideoInit(_THIS)
sizeof(*dispdata->crtc->props_info)); sizeof(*dispdata->crtc->props_info));
for (i = 0; i < dispdata->crtc->props->count_props; i++) { for (i = 0; i < dispdata->crtc->props->count_props; i++) {
dispdata->crtc->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd, dispdata->crtc->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
dispdata->crtc->props->props[i]); dispdata->crtc->props->props[i]);
} }
@ -1345,7 +1349,7 @@ KMSDRM_VideoInit(_THIS)
sizeof(*dispdata->connector->props_info)); sizeof(*dispdata->connector->props_info));
for (i = 0; i < dispdata->connector->props->count_props; i++) { for (i = 0; i < dispdata->connector->props->count_props; i++) {
dispdata->connector->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd, dispdata->connector->props_info[i] = KMSDRM_drmModeGetProperty(viddata->drm_fd,
dispdata->connector->props->props[i]); dispdata->connector->props->props[i]);
} }
@ -1615,9 +1619,9 @@ KMSDRM_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
for (i = 0; i < viddata->num_windows; i++) { for (i = 0; i < viddata->num_windows; i++) {
SDL_Window *window = viddata->windows[i]; SDL_Window *window = viddata->windows[i];
if (KMSDRM_CreateSurfaces(_this, window)) { if (KMSDRM_CreateSurfaces(_this, window)) {
return -1; return -1;
} }
/* Tell app about the window resize */ /* Tell app about the window resize */
SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, mode->w, mode->h); SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, mode->w, mode->h);
@ -1796,7 +1800,7 @@ KMSDRM_GetWindowWMInfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
return SDL_TRUE; return SDL_TRUE;
} else { } else {
SDL_SetError("application not compiled with SDL %d.%d\n", SDL_SetError("application not compiled with SDL %d.%d\n",
SDL_MAJOR_VERSION, SDL_MINOR_VERSION); SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return SDL_FALSE; return SDL_FALSE;
} }

View File

@ -60,8 +60,8 @@ typedef struct dumb_buffer {
/* Parameters for our memory-mapped image. */ /* Parameters for our memory-mapped image. */
struct { struct {
uint32_t *mem; uint32_t *mem;
unsigned int size; unsigned int size;
} dumb; } dumb;
unsigned int width; unsigned int width;