Fixed bug 3902 - Add a specific KMSDRM hint for low latency video

This commit is contained in:
Brandon Schaefer 2017-10-26 16:37:20 -07:00
parent f24c6672a7
commit 2ac567b715
4 changed files with 28 additions and 4 deletions

View file

@ -797,6 +797,16 @@ extern "C" {
*/
#define SDL_HINT_RPI_VIDEO_LAYER "SDL_RPI_VIDEO_LAYER"
/**
* \brief Tell SDL the KMS/DRM video driver that we want double buffer only.
*
* By default KMS/DRM will use a triple buffer solution that wastes no CPU
* time on waiting for vsync after issuing a flip, but introduces a frame of
* latency. Waiting for vsync immediately after issuing a flip on the other
* hand is recommended for cases where low latency is an important factor.
*/
#define SDL_HINT_KMSDRM_DOUBLE_BUFFER "SDL_KMSDRM_DOUBLE_BUFFER"
/**
* \brief A variable controlling what driver to use for OpenGL ES contexts.
*

View file

@ -71,7 +71,7 @@ KMSDRM_GLES_SetupCrtc(_THIS, SDL_Window * window) {
return SDL_FALSE;
}
wdata->crtc_ready = SDL_TRUE;
return SDL_TRUE;
}
@ -159,7 +159,7 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) {
if(!KMSDRM_GLES_SetupCrtc(_this, window)) {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set up CRTC for doing vsync-ed pageflips");
return 0;
}
}
}
/* SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "drmModePageFlip(%d, %u, %u, DRM_MODE_PAGE_FLIP_EVENT, &wdata->waiting_for_flip)",
@ -171,6 +171,12 @@ KMSDRM_GLES_SwapWindow(_THIS, SDL_Window * window) {
} else {
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not queue pageflip: %d", ret);
}
/* Wait immediately for vsync (as if we only had two buffers), for low input-lag scenarios.
Run your SDL2 program with "SDL_KMSDRM_DOUBLE_BUFFER=1 <program_name>" to enable this. */
if (wdata->double_buffer) {
KMSDRM_WaitPageFlip(_this, wdata, -1);
}
}
return 0;

View file

@ -27,6 +27,7 @@
#include "../SDL_sysvideo.h"
#include "SDL_syswm.h"
#include "SDL_log.h"
#include "SDL_hints.h"
#include "../../events/SDL_mouse_c.h"
#include "../../events/SDL_keyboard_c.h"
@ -522,11 +523,17 @@ KMSDRM_CreateWindow(_THIS, SDL_Window * window)
}
#endif /* SDL_VIDEO_OPENGL_EGL */
/* In case we want low-latency, double-buffer video, we take note here */
wdata->double_buffer = SDL_FALSE;
if (SDL_GetHintBoolean(SDL_HINT_KMSDRM_DOUBLE_BUFFER, SDL_FALSE)) {
wdata->double_buffer = SDL_TRUE;
}
/* Window is created, but we have yet to set up CRTC to one of the GBM buffers if we want
drmModePageFlip to work, and we can't do it until EGL is completely setup, because we
need to do eglSwapBuffers so we can get a valid GBM buffer object to call
need to do eglSwapBuffers so we can get a valid GBM buffer object to call
drmModeSetCrtc on it. */
wdata->crtc_ready = SDL_FALSE;
wdata->crtc_ready = SDL_FALSE;
/* Setup driver data for this window */
window->driverdata = wdata;

View file

@ -63,6 +63,7 @@ typedef struct SDL_WindowData
struct gbm_bo *next_bo;
SDL_bool waiting_for_flip;
SDL_bool crtc_ready;
SDL_bool double_buffer;
#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;
#endif