Skip to content
Permalink
Browse files

kmsdrm: Fix tearing in neverputt/ball

  • Loading branch information
BrandonSchaefer committed Aug 3, 2017
1 parent c544d2b commit 86e95a607b5d375e4a80ad9eac7597924d8e1882
Showing with 26 additions and 12 deletions.
  1. +17 −8 src/video/kmsdrm/SDL_kmsdrmopengles.c
  2. +7 −3 src/video/kmsdrm/SDL_kmsdrmvideo.c
  3. +2 −1 src/video/kmsdrm/SDL_kmsdrmvideo.h
@@ -73,26 +73,35 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) {
}

/* Release previously displayed buffer (which is now the backbuffer) and lock a new one */
if (wdata->locked_bo != NULL) {
KMSDRM_gbm_surface_release_buffer(wdata->gs, wdata->locked_bo);
/* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Released GBM surface %p", (void *)wdata->locked_bo); */
wdata->locked_bo = NULL;
if (wdata->next_bo != NULL) {
KMSDRM_gbm_surface_release_buffer(wdata->gs, wdata->current_bo);
/* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Released GBM surface %p", (void *)wdata->next_bo); */

wdata->current_bo = wdata->next_bo;
wdata->next_bo = NULL;
}

if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed.");
return 0;
}

wdata->locked_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
if (wdata->locked_bo == NULL) {
if (wdata->current_bo == NULL) {
wdata->current_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
if (wdata->current_bo == NULL) {
return 0;
}
}

wdata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(wdata->gs);
if (wdata->next_bo == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock GBM surface front buffer");
return 0;
/* } else {
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Locked GBM surface %p", (void *)wdata->locked_bo); */
SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Locked GBM surface %p", (void *)wdata->next_bo); */
}

fb_info = KMSDRM_FBFromBO(_this, wdata->locked_bo);
fb_info = KMSDRM_FBFromBO(_this, wdata->next_bo);
if (_this->egl_data->egl_swapinterval == 0) {
/* Swap buffers instantly, possible tearing */
/* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModeSetCrtc(%d, %u, %u, 0, 0, &%u, 1, &%ux%u@%u)",
@@ -542,9 +542,13 @@ KMSDRM_DestroyWindow(_THIS, SDL_Window * window)
if(data) {
/* Wait for any pending page flips and unlock buffer */
KMSDRM_WaitPageFlip(_this, data, -1);
if (data->locked_bo != NULL) {
KMSDRM_gbm_surface_release_buffer(data->gs, data->locked_bo);
data->locked_bo = NULL;
if (data->next_bo != NULL) {
KMSDRM_gbm_surface_release_buffer(data->gs, data->next_bo);
data->next_bo = NULL;
}
if (data->current_bo != NULL) {
KMSDRM_gbm_surface_release_buffer(data->gs, data->current_bo);
data->current_bo = NULL;
}
#if SDL_VIDEO_OPENGL_EGL
SDL_EGL_MakeCurrent(_this, EGL_NO_SURFACE, EGL_NO_CONTEXT);
@@ -58,7 +58,8 @@ typedef struct SDL_DisplayData
typedef struct SDL_WindowData
{
struct gbm_surface *gs;
struct gbm_bo *locked_bo;
struct gbm_bo *current_bo;
struct gbm_bo *next_bo;
SDL_bool waiting_for_flip;
#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;

0 comments on commit 86e95a6

Please sign in to comment.