Skip to content

Commit

Permalink
kmsdrm: Always use spaces for indentation. Always use SDL_calloc() fo…
Browse files Browse the repository at this point in the history
…r calloc.
  • Loading branch information
vanfanel committed Oct 22, 2020
1 parent cfc1362 commit 87a8667
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 170 deletions.
79 changes: 40 additions & 39 deletions src/video/kmsdrm/SDL_kmsdrmmouse.c
Expand Up @@ -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->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");
return NULL;
}
Expand All @@ -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. */
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)) {
SDL_SetError("Could not get the recommended GBM cursor size");
goto cleanup;
KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_CURSOR_HEIGHT, &usable_cursor_h))
{
SDL_SetError("Could not get the recommended GBM cursor size");
goto cleanup;
}

if (usable_cursor_w == 0 || usable_cursor_h == 0) {
SDL_SetError("Could not get an usable GBM cursor size");
goto cleanup;
SDL_SetError("Could not get an usable GBM cursor size");
goto cleanup;
}

/* hox_x and hot_y are the coordinates of the "tip of the cursor" from it's base. */
Expand All @@ -152,8 +155,8 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
curdata->w = usable_cursor_w;
curdata->h = usable_cursor_h;

curdata->bo = KMSDRM_gbm_bo_create(viddata->gbm_dev, usable_cursor_w, usable_cursor_h, GBM_FORMAT_ARGB8888,
GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);
curdata->bo = KMSDRM_gbm_bo_create(viddata->gbm_dev, usable_cursor_w, usable_cursor_h,
GBM_FORMAT_ARGB8888, GBM_BO_USE_CURSOR | GBM_BO_USE_WRITE);

if (!curdata->bo) {
SDL_SetError("Could not create GBM cursor BO");
Expand All @@ -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. */
buffer = (uint32_t*)SDL_malloc(bufsize);
if (!buffer) {
SDL_OutOfMemory();
goto cleanup;
SDL_OutOfMemory();
goto cleanup;
}

if (SDL_MUSTLOCK(surface)) {
if (SDL_LockSurface(surface) < 0) {
/* Could not lock surface */
goto cleanup;
}
if (SDL_LockSurface(surface) < 0) {
/* Could not lock surface */
goto cleanup;
}
}

/* Clean the whole temporary buffer. */
Expand All @@ -188,17 +191,17 @@ KMSDRM_CreateCursor(SDL_Surface * surface, int hot_x, int hot_y)
for (j = 0; j < surface->w; j++) {
pixel = ((uint32_t*)surface->pixels)[i * surface->w + j];
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)) {
SDL_UnlockSurface(surface);
SDL_UnlockSurface(surface);
}

if (KMSDRM_gbm_bo_write(curdata->bo, buffer, bufsize)) {
SDL_SetError("Could not write to GBM cursor BO");
goto cleanup;
SDL_SetError("Could not write to GBM cursor BO");
goto cleanup;
}

/* Free temporary buffer */
Expand Down Expand Up @@ -261,14 +264,14 @@ KMSDRM_ShowCursor(SDL_Cursor * cursor)
/* Hide CURRENT cursor, a cursor that is already on screen
and SDL is stored in mouse->cur_cursor. */
if (mouse->cur_cursor && mouse->cur_cursor->driverdata) {
if (dispdata && dispdata->cursor_plane) {
info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */
drm_atomic_set_plane_props(&info);
if (drm_atomic_commit(display->device, SDL_TRUE))
return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor.");
if (dispdata && dispdata->cursor_plane) {
info.plane = dispdata->cursor_plane; /* The rest of the members are zeroed. */
drm_atomic_set_plane_props(&info);
if (drm_atomic_commit(display->device, SDL_TRUE))
return SDL_SetError("Failed atomic commit in KMSDRM_ShowCursor.");
}
return 0;
}
}
return SDL_SetError("Couldn't find cursor to hide.");
}

Expand Down Expand Up @@ -335,18 +338,18 @@ KMSDRM_FreeCursor(SDL_Cursor * cursor)
curdata = (KMSDRM_CursorData *) cursor->driverdata;
if (video_device && curdata->bo && curdata->plane) {
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. */
if (drm_atomic_commit(video_device, SDL_TRUE)) {
SDL_SetError("Failed atomic commit in KMSDRM_FreeCursor.");
}
KMSDRM_gbm_bo_destroy(curdata->bo);
curdata->bo = NULL;
KMSDRM_gbm_bo_destroy(curdata->bo);
curdata->bo = NULL;
}

/* Even if the cursor is not ours, free it. */
SDL_free(cursor->driverdata);
SDL_free(cursor);
/* Even if the cursor is not ours, free it. */
SDL_free(cursor->driverdata);
SDL_free(cursor);
}
}

Expand All @@ -372,11 +375,9 @@ KMSDRM_WarpMouseGlobal(int x, int y)
/* And now update the cursor graphic position on screen. */
curdata = (KMSDRM_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->bo) {

if (drm_atomic_movecursor(curdata, x, y)) {
return SDL_SetError("drm_atomic_movecursor() failed.");
}

if (drm_atomic_movecursor(curdata, x, y)) {
return SDL_SetError("drm_atomic_movecursor() failed.");
}
} else {
return SDL_SetError("Cursor not initialized properly.");
}
Expand Down Expand Up @@ -405,7 +406,7 @@ KMSDRM_InitMouse(_THIS)

/* Init cursor plane, if we haven't yet. */
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());
Expand Down Expand Up @@ -436,9 +437,9 @@ KMSDRM_MoveCursor(SDL_Cursor * cursor)
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. */

if (drm_atomic_movecursor(curdata, mouse->x, mouse->y)) {
SDL_SetError("drm_atomic_movecursor() failed.");
}
if (drm_atomic_movecursor(curdata, mouse->x, mouse->y)) {
SDL_SetError("drm_atomic_movecursor() failed.");
}
}
}

Expand Down
46 changes: 25 additions & 21 deletions src/video/kmsdrm/SDL_kmsdrmopengles.c
Expand Up @@ -90,14 +90,15 @@ int KMSDRM_GLES_SetSwapInterval(_THIS, int interval) {

static EGLSyncKHR create_fence(int fd, _THIS)
{
EGLint attrib_list[] = {
EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fd,
EGL_NONE,
};
EGLSyncKHR fence = _this->egl_data->eglCreateSyncKHR(_this->egl_data->egl_display,
EGL_SYNC_NATIVE_FENCE_ANDROID, attrib_list);
assert(fence);
return fence;
EGLint attrib_list[] = {
EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fd,
EGL_NONE,
};
EGLSyncKHR fence = _this->egl_data->eglCreateSyncKHR
(_this->egl_data->egl_display, EGL_SYNC_NATIVE_FENCE_ANDROID, attrib_list);

assert(fence);
return fence;
}

/***********************************************************************************/
Expand Down Expand Up @@ -132,6 +133,7 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
if (! _this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, windata->egl_surface)) {
return SDL_EGL_SetError("Failed to swap EGL buffers", "eglSwapBuffers");
}

/******************************************************************/
/* EXPORT the GPU-side FENCE OBJECT to the fence INPUT FD, so we */
/* can pass it into the kernel. Atomic ioctl will pass the */
Expand All @@ -144,8 +146,8 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
/* in the CMDSTREAM to be lifted when the CMDSTREAM to this point */
/* is completed). */
/******************************************************************/
dispdata->kms_in_fence_fd = _this->egl_data->eglDupNativeFenceFDANDROID
(_this->egl_data->egl_display, dispdata->gpu_fence);
dispdata->kms_in_fence_fd = _this->egl_data->eglDupNativeFenceFDANDROID (_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);
Expand All @@ -157,11 +159,11 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
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");
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 from BO");
return SDL_SetError("Failed to get a new framebuffer from BO");
}

/* Add the pageflip to the request list. */
Expand Down Expand Up @@ -196,19 +198,20 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
/*****************************************************************/
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);
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));
}

/* Do we have a pending modesetting? If so, set the necessary
props so it's included in the incoming atomic commit. */
if (dispdata->modeset_pending) {
uint32_t blob_id;
SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
uint32_t blob_id;

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);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1);
Expand All @@ -227,7 +230,7 @@ KMSDRM_GLES_SwapWindowFenced(_THIS, SDL_Window * window)
/* Release the previous front buffer so EGL can chose it as back buffer
and render on it again. */
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
Expand Down Expand Up @@ -308,9 +311,9 @@ KMSDRM_GLES_SwapWindowDoubleBuffered(_THIS, SDL_Window * window)
props so it's included in the incoming atomic commit. */
if (dispdata->modeset_pending) {
SDL_VideoData *viddata = (SDL_VideoData *)_this->driverdata;
uint32_t blob_id;
uint32_t blob_id;
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);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "MODE_ID", blob_id);
add_crtc_property(dispdata->atomic_req, dispdata->crtc, "ACTIVE", 1);
Expand All @@ -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. */
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. */
Expand All @@ -352,7 +355,8 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window)
if (windata->swap_window == NULL) {
/* We want the fenced version by default, but it needs extensions. */
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;
} else {
windata->swap_window = KMSDRM_GLES_SwapWindowFenced;
Expand Down
14 changes: 7 additions & 7 deletions src/video/kmsdrm/SDL_kmsdrmsym.h
Expand Up @@ -49,15 +49,15 @@ SDL_KMSDRM_SYM(int,drmModeAddFB,(int fd, uint32_t width, uint32_t height, uint8_
uint32_t *buf_id))

SDL_KMSDRM_SYM(int,drmModeAddFB2,(int fd, uint32_t width, uint32_t height,
uint32_t pixel_format, const uint32_t bo_handles[4],
const uint32_t pitches[4], const uint32_t offsets[4],
uint32_t *buf_id, uint32_t flags))
uint32_t pixel_format, const uint32_t bo_handles[4],
const uint32_t pitches[4], const uint32_t offsets[4],
uint32_t *buf_id, uint32_t flags))

SDL_KMSDRM_SYM(int,drmModeAddFB2WithModifiers,(int fd, uint32_t width, uint32_t height,
uint32_t pixel_format, const uint32_t bo_handles[4],
const uint32_t pitches[4], const uint32_t offsets[4],
const uint64_t modifier[4], uint32_t *buf_id,
uint32_t flags))
uint32_t pixel_format, const uint32_t bo_handles[4],
const uint32_t pitches[4], const uint32_t offsets[4],
const uint64_t modifier[4], uint32_t *buf_id,
uint32_t flags))

SDL_KMSDRM_SYM(int,drmModeRmFB,(int fd, uint32_t bufferId))
SDL_KMSDRM_SYM(drmModeFBPtr,drmModeGetFB,(int fd, uint32_t buf))
Expand Down

0 comments on commit 87a8667

Please sign in to comment.