From 0b25cd2196d1f1764c4bc5d65ea66717b3d124e5 Mon Sep 17 00:00:00 2001
From: vanfanel <[EMAIL REDACTED]>
Date: Thu, 18 Jul 2024 21:21:52 +0200
Subject: [PATCH] Fix KMSDRM double buffering.
(cherry picked from commit 5ab1151508ef514b9c5f944da8fc1f3dd6ea0558)
---
src/video/kmsdrm/SDL_kmsdrmopengles.c | 2 +-
src/video/kmsdrm/SDL_kmsdrmvideo.c | 6 ++++++
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c
index 9b34d68961527..cbf86c9498c54 100644
--- a/src/video/kmsdrm/SDL_kmsdrmopengles.c
+++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c
@@ -194,7 +194,7 @@ int KMSDRM_GLES_SwapWindow(_THIS, SDL_Window *window)
we have waited here, there won't be a pending pageflip so the
WaitPageflip at the beginning of this function will be a no-op.
Just leave it here and don't worry.
- Run your SDL2 program with "SDL_KMSDRM_DOUBLE_BUFFER=1 <program_name>"
+ Run your SDL2 program with "SDL_VIDEO_DOUBLE_BUFFER=1 <program_name>"
to enable this. */
if (windata->double_buffer) {
if (!KMSDRM_WaitPageflip(_this, windata)) {
diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c
index e4457921c46ae..307b4b67c2f59 100644
--- a/src/video/kmsdrm/SDL_kmsdrmvideo.c
+++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c
@@ -1478,6 +1478,12 @@ int KMSDRM_CreateWindow(_THIS, SDL_Window *window)
windata->viddata = viddata;
window->driverdata = windata;
+ /* Do we want a double buffering scheme to get low video lag? */
+ windata->double_buffer = SDL_FALSE;
+ if (SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_FALSE)) {
+ windata->double_buffer = SDL_TRUE;
+ }
+
if (!is_vulkan && !vulkan_mode) { /* NON-Vulkan block. */
/* Maybe you didn't ask for an OPENGL window, but that's what you will get.