Abstract window creation into compat function

This commit is contained in:
Cameron Gutman 2025-01-30 22:15:28 -06:00
parent a37020b974
commit d1f3b98a1f
4 changed files with 54 additions and 54 deletions

View File

@ -232,3 +232,21 @@ void SDLC_LeaveFullscreen(SDL_Window* window)
{
SDL_SetWindowFullscreen(window, 0);
}
SDL_Window* SDLC_CreateWindowWithFallback(const char *title,
int x, int y, int w, int h,
Uint32 requiredFlags,
Uint32 optionalFlags)
{
SDL_Window* window = SDL_CreateWindow(title, x, y, w, h, requiredFlags | optionalFlags);
if (!window) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Failed to create window with optional flags: %s",
SDL_GetError());
// Try the fallback flags now
window = SDL_CreateWindow(title, x, y, w, h, requiredFlags);
}
return window;
}

View File

@ -97,6 +97,11 @@ bool SDLC_IsFullscreenDesktop(SDL_Window* window);
void SDLC_EnterFullscreen(SDL_Window* window, bool exclusive);
void SDLC_LeaveFullscreen(SDL_Window* window);
SDL_Window* SDLC_CreateWindowWithFallback(const char *title,
int x, int y, int w, int h,
Uint32 requiredFlags,
Uint32 optionalFlags);
#ifdef __cplusplus
}
#endif

View File

@ -139,14 +139,9 @@ void SystemProperties::querySdlVideoInfoInternal()
// We call the internal variant because we're already in a safe thread context.
refreshDisplaysInternal();
SDL_Window* testWindow = SDL_CreateWindow("", 0, 0, 1280, 720,
SDL_WINDOW_HIDDEN | StreamUtils::getPlatformWindowFlags());
if (!testWindow) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Failed to create test window with platform flags: %s",
SDL_GetError());
testWindow = SDL_CreateWindow("", 0, 0, 1280, 720, SDL_WINDOW_HIDDEN);
SDL_Window* testWindow = SDLC_CreateWindowWithFallback("", 0, 0, 1280, 720,
SDL_WINDOW_HIDDEN,
StreamUtils::getPlatformWindowFlags());
if (!testWindow) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Failed to create window for hardware decode test: %s",
@ -154,7 +149,6 @@ void SystemProperties::querySdlVideoInfoInternal()
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return;
}
}
Session::getDecoderInfo(testWindow, hasHardwareAcceleration, rendererAlwaysFullScreen, supportsHdr, maximumResolution);

View File

@ -618,14 +618,9 @@ bool Session::initialize()
getWindowDimensions(x, y, width, height);
// Create a hidden window to use for decoder initialization tests
SDL_Window* testWindow = SDL_CreateWindow("", x, y, width, height,
SDL_WINDOW_HIDDEN | StreamUtils::getPlatformWindowFlags());
if (!testWindow) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Failed to create test window with platform flags: %s",
SDL_GetError());
testWindow = SDL_CreateWindow("", x, y, width, height, SDL_WINDOW_HIDDEN);
SDL_Window* testWindow = SDLC_CreateWindowWithFallback("", x, y, width, height,
SDL_WINDOW_HIDDEN,
StreamUtils::getPlatformWindowFlags());
if (!testWindow) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Failed to create window for hardware decode test: %s",
@ -633,7 +628,6 @@ bool Session::initialize()
SDL_QuitSubSystem(SDL_INIT_VIDEO);
return false;
}
}
qInfo() << "Server GPU:" << m_Computer->gpuModel;
qInfo() << "Server GFE version:" << m_Computer->gfeVersion;
@ -1835,23 +1829,13 @@ void Session::execInternal()
std::string windowName = QString(m_Computer->name + " - Moonlight").toStdString();
#endif
m_Window = SDL_CreateWindow(windowName.c_str(),
m_Window = SDLC_CreateWindowWithFallback(windowName.c_str(),
x,
y,
width,
height,
defaultWindowFlags | StreamUtils::getPlatformWindowFlags());
if (!m_Window) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"SDL_CreateWindow() failed with platform flags: %s",
SDL_GetError());
m_Window = SDL_CreateWindow(windowName.c_str(),
x,
y,
width,
height,
defaultWindowFlags);
defaultWindowFlags,
StreamUtils::getPlatformWindowFlags());
if (!m_Window) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"SDL_CreateWindow() failed: %s",
@ -1863,7 +1847,6 @@ void Session::execInternal()
QThreadPool::globalInstance()->start(new DeferredSessionCleanupTask(this));
return;
}
}
// HACK: Remove once proper Dark Mode support lands in SDL
#ifdef Q_OS_WIN32