From 52903059442032d9c53c1b8bf4d69968c7d95c2e Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Thu, 30 Jan 2025 23:36:46 -0600 Subject: [PATCH] Abstract SDL success/failure checks inside a compat macro --- app/SDL_compat.h | 2 ++ app/backend/systemproperties.cpp | 4 ++-- app/gui/sdlgamepadkeynavigation.cpp | 2 +- app/main.cpp | 4 ++-- app/streaming/audio/renderers/sdlaud.cpp | 2 +- app/streaming/input/gamepad.cpp | 2 +- app/streaming/input/input.cpp | 6 +++--- app/streaming/session.cpp | 6 +++--- 8 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/SDL_compat.h b/app/SDL_compat.h index cb083a2a..672e3989 100644 --- a/app/SDL_compat.h +++ b/app/SDL_compat.h @@ -103,6 +103,8 @@ SDL_Window* SDLC_CreateWindowWithFallback(const char *title, Uint32 optionalFlags); void SDLC_FlushWindowEvents(); +#define SDLC_SUCCESS(x) ((x) == 0) +#define SDLC_FAILURE(x) ((x) != 0) #ifdef __cplusplus } diff --git a/app/backend/systemproperties.cpp b/app/backend/systemproperties.cpp index 0d9f1d81..e4877957 100644 --- a/app/backend/systemproperties.cpp +++ b/app/backend/systemproperties.cpp @@ -128,7 +128,7 @@ void SystemProperties::querySdlVideoInfoInternal() { hasHardwareAcceleration = false; - if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s", SDL_GetError()); @@ -188,7 +188,7 @@ void SystemProperties::refreshDisplays() void SystemProperties::refreshDisplaysInternal() { - if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s", SDL_GetError()); diff --git a/app/gui/sdlgamepadkeynavigation.cpp b/app/gui/sdlgamepadkeynavigation.cpp index 88693b87..d95e4caa 100644 --- a/app/gui/sdlgamepadkeynavigation.cpp +++ b/app/gui/sdlgamepadkeynavigation.cpp @@ -37,7 +37,7 @@ void SdlGamepadKeyNavigation::enable() // arrival events. Additionally, there's a race condition between // our QML objects being destroyed and SDL being deinitialized that // this solves too. - if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s", SDL_GetError()); diff --git a/app/main.cpp b/app/main.cpp index c096dede..a3d4f6c3 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -515,7 +515,7 @@ int main(int argc, char *argv[]) // The DXVA2 renderer uses Direct3D 9Ex itself directly. SDL_SetHint(SDL_HINT_WINDOWS_USE_D3D9EX, "1"); - if (SDL_InitSubSystem(SDL_INIT_TIMER) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_TIMER))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_TIMER) failed: %s", SDL_GetError()); @@ -525,7 +525,7 @@ int main(int argc, char *argv[]) #ifdef STEAM_LINK // Steam Link requires that we initialize video before creating our // QGuiApplication in order to configure the framebuffer correctly. - if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s", SDL_GetError()); diff --git a/app/streaming/audio/renderers/sdlaud.cpp b/app/streaming/audio/renderers/sdlaud.cpp index 16b90775..21e5db0c 100644 --- a/app/streaming/audio/renderers/sdlaud.cpp +++ b/app/streaming/audio/renderers/sdlaud.cpp @@ -8,7 +8,7 @@ SdlAudioRenderer::SdlAudioRenderer() { SDL_assert(!SDL_WasInit(SDL_INIT_AUDIO)); - if (SDL_InitSubSystem(SDL_INIT_AUDIO) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_AUDIO))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_AUDIO) failed: %s", SDL_GetError()); diff --git a/app/streaming/input/gamepad.cpp b/app/streaming/input/gamepad.cpp index 435c9d2f..5aca28d5 100644 --- a/app/streaming/input/gamepad.cpp +++ b/app/streaming/input/gamepad.cpp @@ -904,7 +904,7 @@ QString SdlInputHandler::getUnmappedGamepads() { QString ret; - if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s", SDL_GetError()); diff --git a/app/streaming/input/input.cpp b/app/streaming/input/input.cpp index 6f1fe6a6..db2bdf2b 100644 --- a/app/streaming/input/input.cpp +++ b/app/streaming/input/input.cpp @@ -148,7 +148,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i // can allow mapping manager to update the mappings before GC attach // events are generated. SDL_assert(!SDL_WasInit(SDL_INIT_JOYSTICK)); - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_JOYSTICK))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_JOYSTICK) failed: %s", SDL_GetError()); @@ -166,7 +166,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i // We need to reinit this each time, since you only get // an initial set of gamepad arrival events once per init. SDL_assert(!SDL_WasInit(SDL_INIT_GAMECONTROLLER)); - if (SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) failed: %s", SDL_GetError()); @@ -174,7 +174,7 @@ SdlInputHandler::SdlInputHandler(StreamingPreferences& prefs, int streamWidth, i #if !SDL_VERSION_ATLEAST(2, 0, 9) SDL_assert(!SDL_WasInit(SDL_INIT_HAPTIC)); - if (SDL_InitSubSystem(SDL_INIT_HAPTIC) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_HAPTIC))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_HAPTIC) failed: %s", SDL_GetError()); diff --git a/app/streaming/session.cpp b/app/streaming/session.cpp index e5256b50..a175cb3f 100644 --- a/app/streaming/session.cpp +++ b/app/streaming/session.cpp @@ -606,7 +606,7 @@ bool Session::initialize() } #endif - if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { + if (SDLC_FAILURE(SDL_InitSubSystem(SDL_INIT_VIDEO))) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_InitSubSystem(SDL_INIT_VIDEO) failed: %s", SDL_GetError()); @@ -1282,7 +1282,7 @@ void Session::getWindowDimensions(int& x, int& y, for (int i = 0; i < SDL_GetNumVideoDisplays(); i++) { SDL_Rect displayBounds; - if (SDL_GetDisplayBounds(i, &displayBounds) == 0) { + if (SDLC_SUCCESS(SDL_GetDisplayBounds(i, &displayBounds))) { if (displayBounds.x == displayRect.x() && displayBounds.y == displayRect.y()) { SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, @@ -1307,7 +1307,7 @@ void Session::getWindowDimensions(int& x, int& y, } SDL_Rect usableBounds; - if (SDL_GetDisplayUsableBounds(displayIndex, &usableBounds) == 0) { + if (SDLC_SUCCESS(SDL_GetDisplayUsableBounds(displayIndex, &usableBounds))) { // Don't use more than 80% of the display to leave room for system UI // and ensure the target size is not odd (otherwise one of the sides // of the image will have a one-pixel black bar next to it).