Skip to content

Commit

Permalink
kmsdrm: Fix tearing in neverputt/ball
Browse files Browse the repository at this point in the history
  • Loading branch information
BrandonSchaefer committed Aug 3, 2017
1 parent c544d2b commit 86e95a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
25 changes: 17 additions & 8 deletions src/video/kmsdrm/SDL_kmsdrmopengles.c
Expand Up @@ -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)",
Expand Down
10 changes: 7 additions & 3 deletions src/video/kmsdrm/SDL_kmsdrmvideo.c
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/video/kmsdrm/SDL_kmsdrmvideo.h
Expand Up @@ -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;
Expand Down

0 comments on commit 86e95a6

Please sign in to comment.