Also skip SDL_RENDERER_PRESENTVSYNC on Wayland

This commit is contained in:
Cameron Gutman 2023-09-09 10:41:33 -05:00
parent aaff04167b
commit 3094185cd6

View file

@ -5,6 +5,8 @@
#include <Limelight.h> #include <Limelight.h>
#include <SDL_syswm.h>
SdlRenderer::SdlRenderer() SdlRenderer::SdlRenderer()
: m_VideoFormat(0), : m_VideoFormat(0),
m_Renderer(nullptr), m_Renderer(nullptr),
@ -98,15 +100,36 @@ bool SdlRenderer::initialize(PDECODER_PARAMETERS params)
return false; return false;
} }
#ifdef Q_OS_WIN32 SDL_SysWMinfo info;
// The Windows DWM has tear-free behavior even with V-Sync off, so we will only set SDL_RENDERER_PRESENTVSYNC SDL_VERSION(&info.version);
// when we're in full-screen exclusive mode if we're running on Windows. if (!SDL_GetWindowWMInfo(params->window, &info)) {
if ((SDL_GetWindowFlags(params->window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
#endif "SDL_GetWindowWMInfo() failed: %s",
{ SDL_GetError());
return false;
}
// Only set SDL_RENDERER_PRESENTVSYNC if we know we'll get tearing otherwise.
// Since we don't use V-Sync to pace our frame rate, we want non-blocking
// presents to reduce video latency.
switch (info.subsystem) {
case SDL_SYSWM_WINDOWS:
// DWM is always tear-free except in full-screen exclusive mode
if ((SDL_GetWindowFlags(params->window) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN) {
if (params->enableVsync) {
rendererFlags |= SDL_RENDERER_PRESENTVSYNC;
}
}
break;
case SDL_SYSWM_WAYLAND:
// Wayland is always tear-free in all modes
break;
default:
// For other subsystems, just set SDL_RENDERER_PRESENTVSYNC if asked
if (params->enableVsync) { if (params->enableVsync) {
rendererFlags |= SDL_RENDERER_PRESENTVSYNC; rendererFlags |= SDL_RENDERER_PRESENTVSYNC;
} }
break;
} }
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32