From bfa51c3845687ed16f651e3d9c7ef92183662088 Mon Sep 17 00:00:00 2001 From: Manuel Alfayate Corchete Date: Sun, 31 Jan 2021 03:48:29 +0100 Subject: [PATCH] [KMS/DRM] Fix for bug #5518: only do async pageflips when hardware supports them. --- src/video/kmsdrm/SDL_kmsdrmopengles.c | 2 +- src/video/kmsdrm/SDL_kmsdrmvideo.c | 8 ++++++++ src/video/kmsdrm/SDL_kmsdrmvideo.h | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c index 529eeeaf1..0053e5245 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c @@ -168,7 +168,7 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) { to do so, so even if we don't block on EGL, the flip will have completed when we get here again. */ - if (_this->egl_data->egl_swapinterval == 0) { + if (_this->egl_data->egl_swapinterval == 0 && viddata->async_pageflip_support) { flip_flags |= DRM_MODE_PAGE_FLIP_ASYNC; } diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 78ed3b2ce..b5fc16c40 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -653,6 +653,7 @@ int KMSDRM_InitDisplays (_THIS) { SDL_VideoData *viddata = ((SDL_VideoData *)_this->driverdata); drmModeRes *resources = NULL; + uint64_t async_pageflip = 0; int ret = 0; int i; @@ -705,6 +706,13 @@ int KMSDRM_InitDisplays (_THIS) { goto cleanup; } + /* Determine if video hardware supports async pageflips. */ + ret = KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_ASYNC_PAGE_FLIP, &async_pageflip); + if (ret) { + SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not determine async page flip capability."); + } + viddata->async_pageflip_support = async_pageflip ? SDL_TRUE : SDL_FALSE; + /***********************************/ /* Block for Vulkan compatibility. */ /***********************************/ diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h index 29cfc1833..31df3b9e4 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.h +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h @@ -41,8 +41,9 @@ typedef struct SDL_VideoData struct gbm_device *gbm_dev; - SDL_bool video_init; /* Has VideoInit succeeded? */ - SDL_bool vulkan_mode; /* Are we in Vulkan mode? One VK window is enough to be. */ + SDL_bool video_init; /* Has VideoInit succeeded? */ + SDL_bool vulkan_mode; /* Are we in Vulkan mode? One VK window is enough to be. */ + SDL_bool async_pageflip_support; /* Does the hardware support async. pageflips? */ SDL_Window **windows; int max_windows;