diff --git a/app/SDL_compat.c b/app/SDL_compat.c index e6df6c78..f2963805 100644 --- a/app/SDL_compat.c +++ b/app/SDL_compat.c @@ -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; +} diff --git a/app/SDL_compat.h b/app/SDL_compat.h index 2fac3172..a4515adf 100644 --- a/app/SDL_compat.h +++ b/app/SDL_compat.h @@ -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 diff --git a/app/backend/systemproperties.cpp b/app/backend/systemproperties.cpp index 554f4334..0d9f1d81 100644 --- a/app/backend/systemproperties.cpp +++ b/app/backend/systemproperties.cpp @@ -139,21 +139,15 @@ 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()); + SDL_Window* testWindow = SDLC_CreateWindowWithFallback("", 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); - if (!testWindow) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Failed to create window for hardware decode test: %s", - SDL_GetError()); - SDL_QuitSubSystem(SDL_INIT_VIDEO); - return; - } + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Failed to create window for hardware decode test: %s", + SDL_GetError()); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + return; } Session::getDecoderInfo(testWindow, hasHardwareAcceleration, rendererAlwaysFullScreen, supportsHdr, maximumResolution); diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index 14e3cd41..f51b8987 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -618,21 +618,15 @@ 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()); + SDL_Window* testWindow = SDLC_CreateWindowWithFallback("", 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); - if (!testWindow) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "Failed to create window for hardware decode test: %s", - SDL_GetError()); - SDL_QuitSubSystem(SDL_INIT_VIDEO); - return false; - } + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "Failed to create window for hardware decode test: %s", + SDL_GetError()); + SDL_QuitSubSystem(SDL_INIT_VIDEO); + return false; } qInfo() << "Server GPU:" << m_Computer->gpuModel; @@ -1835,34 +1829,23 @@ void Session::execInternal() std::string windowName = QString(m_Computer->name + " - Moonlight").toStdString(); #endif - m_Window = SDL_CreateWindow(windowName.c_str(), - x, - y, - width, - height, - defaultWindowFlags | StreamUtils::getPlatformWindowFlags()); + 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()); + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, + "SDL_CreateWindow() failed: %s", + SDL_GetError()); - m_Window = SDL_CreateWindow(windowName.c_str(), - x, - y, - width, - height, - defaultWindowFlags); - if (!m_Window) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, - "SDL_CreateWindow() failed: %s", - SDL_GetError()); - - delete m_InputHandler; - m_InputHandler = nullptr; - SDL_QuitSubSystem(SDL_INIT_VIDEO); - QThreadPool::globalInstance()->start(new DeferredSessionCleanupTask(this)); - return; - } + delete m_InputHandler; + m_InputHandler = nullptr; + SDL_QuitSubSystem(SDL_INIT_VIDEO); + QThreadPool::globalInstance()->start(new DeferredSessionCleanupTask(this)); + return; } // HACK: Remove once proper Dark Mode support lands in SDL