diff --git a/VisualC-GDK/tests/testgdk/src/testgdk.cpp b/VisualC-GDK/tests/testgdk/src/testgdk.cpp index b1818e5f7b..46301b2ca2 100644 --- a/VisualC-GDK/tests/testgdk/src/testgdk.cpp +++ b/VisualC-GDK/tests/testgdk/src/testgdk.cpp @@ -197,7 +197,7 @@ LoadSprite(const char *file) if (!sprites[i]) { return -1; } - if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) { + if (!SDL_SetTextureBlendMode(sprites[i], blendMode)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError()); SDL_DestroyTexture(sprites[i]); return -1; @@ -425,7 +425,7 @@ main(int argc, char *argv[]) } /* Load the wave file into memory */ - if (SDL_LoadWAV(soundname, &wave.spec, &wave.sound, &wave.soundlen) == -1) { + if (!SDL_LoadWAV(soundname, &wave.spec, &wave.sound, &wave.soundlen)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", soundname, SDL_GetError()); quit(1); } diff --git a/android-project/app/jni/src/YourSourceHere.c b/android-project/app/jni/src/YourSourceHere.c index 8b939161d1..87b8297368 100644 --- a/android-project/app/jni/src/YourSourceHere.c +++ b/android-project/app/jni/src/YourSourceHere.c @@ -10,13 +10,13 @@ int main(int argc, char *argv[]) { (void)argc; (void)argv; - if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_EVENTS | SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init failed (%s)", SDL_GetError()); return 1; } - if (SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Hello World", - "!! Your SDL project successfully runs on Android !!", NULL) < 0) { + if (!SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, "Hello World", + "!! Your SDL project successfully runs on Android !!", NULL)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_ShowSimpleMessageBox failed (%s)", SDL_GetError()); return 1; } diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java index b7d4bde0ee..c6da70f562 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -1473,11 +1473,11 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh if (SDLControllerManager.isDeviceSDLJoystick(deviceId)) { // Note that we process events with specific key codes here if (event.getAction() == KeyEvent.ACTION_DOWN) { - if (SDLControllerManager.onNativePadDown(deviceId, keyCode) == 0) { + if (SDLControllerManager.onNativePadDown(deviceId, keyCode)) { return true; } } else if (event.getAction() == KeyEvent.ACTION_UP) { - if (SDLControllerManager.onNativePadUp(deviceId, keyCode) == 0) { + if (SDLControllerManager.onNativePadUp(deviceId, keyCode)) { return true; } } @@ -1951,7 +1951,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh /** * This method is called by SDL using JNI. */ - public static int openURL(String url) + public static boolean openURL(String url) { try { Intent i = new Intent(Intent.ACTION_VIEW); @@ -1967,18 +1967,18 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh mSingleton.startActivity(i); } catch (Exception ex) { - return -1; + return false; } - return 0; + return true; } /** * This method is called by SDL using JNI. */ - public static int showToast(String message, int duration, int gravity, int xOffset, int yOffset) + public static boolean showToast(String message, int duration, int gravity, int xOffset, int yOffset) { if(null == mSingleton) { - return - 1; + return false; } try @@ -2013,9 +2013,9 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh } mSingleton.runOnUiThread(new OneShotTask(message, duration, gravity, xOffset, yOffset)); } catch(Exception ex) { - return -1; + return false; } - return 0; + return true; } /** diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java index 3a16832c58..b7faee8997 100644 --- a/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android-project/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -22,15 +22,15 @@ public class SDLControllerManager public static native int nativeSetupJNI(); - public static native int nativeAddJoystick(int device_id, String name, String desc, - int vendor_id, int product_id, - int button_mask, - int naxes, int axis_mask, int nhats, boolean can_rumble); - public static native int nativeRemoveJoystick(int device_id); - public static native int nativeAddHaptic(int device_id, String name); - public static native int nativeRemoveHaptic(int device_id); - public static native int onNativePadDown(int device_id, int keycode); - public static native int onNativePadUp(int device_id, int keycode); + public static native void nativeAddJoystick(int device_id, String name, String desc, + int vendor_id, int product_id, + int button_mask, + int naxes, int axis_mask, int nhats, boolean can_rumble); + public static native void nativeRemoveJoystick(int device_id); + public static native void nativeAddHaptic(int device_id, String name); + public static native void nativeRemoveHaptic(int device_id); + public static native boolean onNativePadDown(int device_id, int keycode); + public static native boolean onNativePadUp(int device_id, int keycode); public static native void onNativeJoy(int device_id, int axis, float value); public static native void onNativeHat(int device_id, int hat_id, diff --git a/build-scripts/SDL_migration.cocci b/build-scripts/SDL_migration.cocci index b5c34a03b2..79177f7644 100644 --- a/build-scripts/SDL_migration.cocci +++ b/build-scripts/SDL_migration.cocci @@ -30,7 +30,6 @@ // // So this file is a set of many semantic patches, mostly independent. - @ rule_audio_open @ expression e1, e2; @@ @@ -3600,3 +3599,32 @@ typedef SDL_JoystickGUID, SDL_GUID; @@ - SDL_HINT_VIDEO_WAYLAND_EMULATE_MOUSE_WARP + SDL_HINT_MOUSE_EMULATE_WARP_WITH_RELATIVE + +// This should be the last rule in the file, since it works on SDL3 functions and previous rules may have renamed old functions. +@ bool_return_type @ +identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAlternateImage|SDL_AddVulkanRenderSemaphores|SDL_BindAudioStream|SDL_BindAudioStreams|SDL_BlitSurface|SDL_BlitSurface9Grid|SDL_BlitSurfaceScaled|SDL_BlitSurfaceTiled|SDL_BlitSurfaceTiledWithScale|SDL_BlitSurfaceUnchecked|SDL_BlitSurfaceUncheckedScaled|SDL_CaptureMouse|SDL_ClearAudioStream|SDL_ClearClipboardData|SDL_ClearComposition|SDL_ClearError|SDL_ClearProperty|SDL_ClearSurface|SDL_CloseIO|SDL_CloseStorage|SDL_ConvertAudioSamples|SDL_ConvertEventToRenderCoordinates|SDL_ConvertPixels|SDL_ConvertPixelsAndColorspace|SDL_CopyFile|SDL_CopyProperties|SDL_CopyStorageFile|SDL_CreateDirectory|SDL_CreateStorageDirectory|SDL_CreateWindowAndRenderer|SDL_DateTimeToTime|SDL_DestroyWindowSurface|SDL_DetachVirtualJoystick|SDL_DisableScreenSaver|SDL_EnableScreenSaver|SDL_EnumerateDirectory|SDL_EnumerateProperties|SDL_EnumerateStorageDirectory|SDL_FillSurfaceRect|SDL_FillSurfaceRects|SDL_FlashWindow|SDL_FlipSurface|SDL_FlushAudioStream|SDL_FlushRenderer|SDL_GL_DestroyContext|SDL_GL_GetAttribute|SDL_GL_GetSwapInterval|SDL_GL_LoadLibrary|SDL_GL_MakeCurrent|SDL_GL_SetAttribute|SDL_GL_SetSwapInterval|SDL_GL_SwapWindow|SDL_GetAudioDeviceFormat|SDL_GetAudioStreamFormat|SDL_GetCameraFormat|SDL_GetClosestFullscreenDisplayMode|SDL_GetCurrentRenderOutputSize|SDL_GetCurrentTime|SDL_GetDXGIOutputInfo|SDL_GetDateTimeLocalePreferences|SDL_GetDisplayBounds|SDL_GetDisplayUsableBounds|SDL_GetGDKDefaultUser|SDL_GetGDKTaskQueue|SDL_GetGamepadSensorData|SDL_GetGamepadTouchpadFinger|SDL_GetHapticEffectStatus|SDL_GetJoystickBall|SDL_GetMasksForPixelFormat|SDL_GetPathInfo|SDL_GetRectUnion|SDL_GetRectUnionFloat|SDL_GetRenderClipRect|SDL_GetRenderColorScale|SDL_GetRenderDrawBlendMode|SDL_GetRenderDrawColor|SDL_GetRenderDrawColorFloat|SDL_GetRenderLogicalPresentation|SDL_GetRenderLogicalPresentationRect|SDL_GetRenderOutputSize|SDL_GetRenderSafeArea|SDL_GetRenderScale|SDL_GetRenderVSync|SDL_GetRenderViewport|SDL_GetSensorData|SDL_GetStorageFileSize|SDL_GetStoragePathInfo|SDL_GetSurfaceAlphaMod|SDL_GetSurfaceBlendMode|SDL_GetSurfaceClipRect|SDL_GetSurfaceColorKey|SDL_GetSurfaceColorMod|SDL_GetTextInputArea|SDL_GetTextureAlphaMod|SDL_GetTextureAlphaModFloat|SDL_GetTextureBlendMode|SDL_GetTextureColorMod|SDL_GetTextureColorModFloat|SDL_GetTextureScaleMode|SDL_GetTextureSize|SDL_GetWindowAspectRatio|SDL_GetWindowBordersSize|SDL_GetWindowMaximumSize|SDL_GetWindowMinimumSize|SDL_GetWindowPosition|SDL_GetWindowRelativeMouseMode|SDL_GetWindowSafeArea|SDL_GetWindowSize|SDL_GetWindowSizeInPixels|SDL_GetWindowSurfaceVSync|SDL_HideCursor|SDL_HideWindow|SDL_Init|SDL_InitHapticRumble|SDL_InitSubSystem|SDL_LoadWAV|SDL_LoadWAV_IO|SDL_LockAudioStream|SDL_LockProperties|SDL_LockSurface|SDL_LockTexture|SDL_LockTextureToSurface|SDL_MaximizeWindow|SDL_MinimizeWindow|SDL_MixAudio|SDL_OpenURL|SDL_OutOfMemory|SDL_PauseAudioDevice|SDL_PauseAudioStreamDevice|SDL_PauseHaptic|SDL_PlayHapticRumble|SDL_PremultiplyAlpha|SDL_PremultiplySurfaceAlpha|SDL_PushEvent|SDL_PutAudioStreamData|SDL_RaiseWindow|SDL_ReadStorageFile|SDL_ReadSurfacePixel|SDL_ReadSurfacePixelFloat|SDL_RegisterApp|SDL_ReloadGamepadMappings|SDL_RemovePath|SDL_RemoveStoragePath|SDL_RemoveTimer|SDL_RenamePath|SDL_RenameStoragePath|SDL_RenderClear|SDL_RenderCoordinatesFromWindow|SDL_RenderCoordinatesToWindow|SDL_RenderFillRect|SDL_RenderFillRects|SDL_RenderGeometry|SDL_RenderGeometryRaw|SDL_RenderLine|SDL_RenderLines|SDL_RenderPoint|SDL_RenderPoints|SDL_RenderPresent|SDL_RenderRect|SDL_RenderRects|SDL_RenderTexture|SDL_RenderTexture9Grid|SDL_RenderTextureRotated|SDL_RenderTextureTiled|SDL_RequestAndroidPermission|SDL_RestoreWindow|SDL_ResumeAudioDevice|SDL_ResumeAudioStreamDevice|SDL_ResumeHaptic|SDL_RumbleGamepad|SDL_RumbleGamepadTriggers|SDL_RumbleJoystick|SDL_RumbleJoystickTriggers|SDL_RunHapticEffect|SDL_SaveBMP|SDL_SaveBMP_IO|SDL_SendAndroidMessage|SDL_SendGamepadEffect|SDL_SendJoystickEffect|SDL_SendJoystickVirtualSensorData|SDL_SetAppMetadata|SDL_SetAppMetadataProperty|SDL_SetAudioDeviceGain|SDL_SetAudioPostmixCallback|SDL_SetAudioStreamFormat|SDL_SetAudioStreamFrequencyRatio|SDL_SetAudioStreamGain|SDL_SetAudioStreamGetCallback|SDL_SetAudioStreamInputChannelMap|SDL_SetAudioStreamOutputChannelMap|SDL_SetAudioStreamPutCallback|SDL_SetBooleanProperty|SDL_SetClipboardData|SDL_SetClipboardText|SDL_SetCursor|SDL_SetFloatProperty|SDL_SetGamepadLED|SDL_SetGamepadMapping|SDL_SetGamepadPlayerIndex|SDL_SetGamepadSensorEnabled|SDL_SetHapticAutocenter|SDL_SetHapticGain|SDL_SetJoystickLED|SDL_SetJoystickPlayerIndex|SDL_SetJoystickVirtualAxis|SDL_SetJoystickVirtualBall|SDL_SetJoystickVirtualButton|SDL_SetJoystickVirtualHat|SDL_SetJoystickVirtualTouchpad|SDL_SetLinuxThreadPriority|SDL_SetLinuxThreadPriorityAndPolicy|SDL_SetLogPriorityPrefix|SDL_SetMemoryFunctions|SDL_SetNumberProperty|SDL_SetPaletteColors|SDL_SetPointerProperty|SDL_SetPointerPropertyWithCleanup|SDL_SetPrimarySelectionText|SDL_SetRenderClipRect|SDL_SetRenderColorScale|SDL_SetRenderDrawBlendMode|SDL_SetRenderDrawColor|SDL_SetRenderDrawColorFloat|SDL_SetRenderLogicalPresentation|SDL_SetRenderScale|SDL_SetRenderTarget|SDL_SetRenderVSync|SDL_SetRenderViewport|SDL_SetScancodeName|SDL_SetStringProperty|SDL_SetSurfaceAlphaMod|SDL_SetSurfaceBlendMode|SDL_SetSurfaceColorKey|SDL_SetSurfaceColorMod|SDL_SetSurfaceColorspace|SDL_SetSurfacePalette|SDL_SetSurfaceRLE|SDL_SetTLS|SDL_SetTextInputArea|SDL_SetTextureAlphaMod|SDL_SetTextureAlphaModFloat|SDL_SetTextureBlendMode|SDL_SetTextureColorMod|SDL_SetTextureColorModFloat|SDL_SetTextureScaleMode|SDL_SetThreadPriority|SDL_SetWindowAlwaysOnTop|SDL_SetWindowAspectRatio|SDL_SetWindowBordered|SDL_SetWindowFocusable|SDL_SetWindowFullscreen|SDL_SetWindowFullscreenMode|SDL_SetWindowHitTest|SDL_SetWindowIcon|SDL_SetWindowKeyboardGrab|SDL_SetWindowMaximumSize|SDL_SetWindowMinimumSize|SDL_SetWindowModalFor|SDL_SetWindowMouseGrab|SDL_SetWindowMouseRect|SDL_SetWindowOpacity|SDL_SetWindowPosition|SDL_SetWindowRelativeMouseMode|SDL_SetWindowResizable|SDL_SetWindowShape|SDL_SetWindowSize|SDL_SetWindowSurfaceVSync|SDL_SetWindowTitle|SDL_SetiOSAnimationCallback|SDL_ShowAndroidToast|SDL_ShowCursor|SDL_ShowMessageBox|SDL_ShowSimpleMessageBox|SDL_ShowWindow|SDL_ShowWindowSystemMenu|SDL_StartTextInput|SDL_StartTextInputWithProperties|SDL_StopHapticEffect|SDL_StopHapticEffects|SDL_StopHapticRumble|SDL_StopTextInput|SDL_SyncWindow|SDL_TimeToDateTime|SDL_TryLockMutex|SDL_TryLockRWLockForReading|SDL_TryLockRWLockForWriting|SDL_TryWaitSemaphore|SDL_UnlockAudioStream|SDL_UpdateHapticEffect|SDL_UpdateNVTexture|SDL_UpdateTexture|SDL_UpdateWindowSurface|SDL_UpdateWindowSurfaceRects|SDL_UpdateYUVTexture|SDL_Vulkan_CreateSurface|SDL_Vulkan_LoadLibrary|SDL_WaitConditionTimeout|SDL_WaitSemaphoreTimeout|SDL_WarpMouseGlobal|SDL_WriteStorageFile|SDL_WriteSurfacePixel|SDL_WriteSurfacePixelFloat)$"; +@@ +( + func( + ... + ) +- == 0 +| +- func( ++ !func( + ... + ) +- < 0 +| +- func( ++ !func( + ... + ) +- != 0 +| +- func( ++ !func( + ... + ) +- == -1 +) diff --git a/cmake/test/main.swift b/cmake/test/main.swift index 6c5d8b8318..7932a39cbb 100644 --- a/cmake/test/main.swift +++ b/cmake/test/main.swift @@ -2,7 +2,7 @@ import SDL3 -guard SDL_Init(Uint32(SDL_INIT_VIDEO)) == 0 else { +guard SDL_Init(SDL_INIT_VIDEO) != 0 else { fatalError("SDL_Init error: \(String(cString: SDL_GetError()))") } diff --git a/cmake/test/main_cli.c b/cmake/test/main_cli.c index 25bb28aed8..5a1c0c6253 100644 --- a/cmake/test/main_cli.c +++ b/cmake/test/main_cli.c @@ -5,7 +5,7 @@ int main(int argc, char *argv[]) { SDL_SetMainReady(); - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_Log("Could not initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/cmake/test/main_gui.c b/cmake/test/main_gui.c index 0165738471..3df64e5fd0 100644 --- a/cmake/test/main_gui.c +++ b/cmake/test/main_gui.c @@ -5,7 +5,7 @@ int main(int argc, char *argv[]) { SDL_Window *window = NULL; SDL_Surface *screenSurface = NULL; - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_Log("Could not initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/cmake/test/main_lib.c b/cmake/test/main_lib.c index f33c4ef8b2..a59150b4a6 100644 --- a/cmake/test/main_lib.c +++ b/cmake/test/main_lib.c @@ -17,7 +17,7 @@ int MYLIBRARY_EXPORT mylibrary_work(void); int mylibrary_init(void) { SDL_SetMainReady(); - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_Log("Could not initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/docs/README-cmake.md b/docs/README-cmake.md index 6c96309426..b1491b1482 100644 --- a/docs/README-cmake.md +++ b/docs/README-cmake.md @@ -385,7 +385,7 @@ int main(int argc, char *argv[]) { (void)argc; (void)argv; - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_Log("SDL_Init failed (%s)", SDL_GetError()); return 1; } @@ -393,7 +393,7 @@ int main(int argc, char *argv[]) { SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; - if (SDL_CreateWindowAndRenderer("SDL issue", 640, 480, 0, &window, &renderer) < 0) { + if (!SDL_CreateWindowAndRenderer("SDL issue", 640, 480, 0, &window, &renderer)) { SDL_Log("SDL_CreateWindowAndRenderer failed (%s)", SDL_GetError()); SDL_Quit(); return 1; diff --git a/docs/README-dynapi.md b/docs/README-dynapi.md index 967f1bdf0c..60a2949829 100644 --- a/docs/README-dynapi.md +++ b/docs/README-dynapi.md @@ -35,7 +35,7 @@ SDL now has, internally, a table of function pointers. So, this is what SDL_Init now looks like: ```c -Uint32 SDL_Init(Uint32 flags) +SDL_bool SDL_Init(SDL_InitFlags flags) { return jump_table.SDL_Init(flags); } @@ -49,7 +49,7 @@ SDL_Init() that you've been calling all this time. But at startup, it looks more like this: ```c -Uint32 SDL_Init_DEFAULT(Uint32 flags) +SDL_bool SDL_Init_DEFAULT(SDL_InitFlags flags) { SDL_InitDynamicAPI(); return jump_table.SDL_Init(flags); diff --git a/docs/README-ios.md b/docs/README-ios.md index 8b6e0edfb5..cce35b58c4 100644 --- a/docs/README-ios.md +++ b/docs/README-ios.md @@ -225,7 +225,7 @@ Game Center Game Center integration might require that you break up your main loop in order to yield control back to the system. In other words, instead of running an endless main loop, you run each frame in a callback function, using: - int SDL_SetiOSAnimationCallback(SDL_Window * window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam); + SDL_bool SDL_SetiOSAnimationCallback(SDL_Window * window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam); This will set up the given function to be called back on the animation callback, and then you have to return from main() to let the Cocoa event loop run. diff --git a/docs/README-macos.md b/docs/README-macos.md index 3e4708de3c..e40cda3138 100644 --- a/docs/README-macos.md +++ b/docs/README-macos.md @@ -54,6 +54,7 @@ NSApplicationDelegate implementation: { if (SDL_GetEventState(SDL_EVENT_QUIT) == SDL_ENABLE) { SDL_Event event; + SDL_zero(event); event.type = SDL_EVENT_QUIT; SDL_PushEvent(&event); } @@ -65,9 +66,10 @@ NSApplicationDelegate implementation: { if (SDL_GetEventState(SDL_EVENT_DROP_FILE) == SDL_ENABLE) { SDL_Event event; + SDL_zero(event); event.type = SDL_EVENT_DROP_FILE; event.drop.file = SDL_strdup([filename UTF8String]); - return (SDL_PushEvent(&event) > 0); + return SDL_PushEvent(&event); } return NO; diff --git a/docs/README-migration.md b/docs/README-migration.md index aebcd7ecb7..63f0782581 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -6,6 +6,36 @@ Details on API changes are organized by SDL 2.0 header below. The file with your main() function should include , as that is no longer included in SDL.h. +Functions that previously returned a negative error code now return SDL_bool. + +Code that used to look like this: +```c + if (SDL_Function() < 0 || SDL_Function() == -1) { + /* Failure... */ + } +``` +or +```c + if (SDL_Function() == 0) { + /* Success... */ + } +``` +or +```c + if (!SDL_Function()) { + /* Success... */ + } +``` +should be changed to: +```c + if (SDL_Function()) { + /* Success... */ + } else { + /* Failure... */ + } +``` +This only applies to camel case functions, e.g. `SDL_[A-Z]*`. Lower case functions like SDL_strcmp() and SDL_memcmp() are unchanged, matching their C runtime counterpart. + Many functions and symbols have been renamed. We have provided a handy Python script [rename_symbols.py](https://github.com/libsdl-org/SDL/blob/main/build-scripts/rename_symbols.py) to rename SDL2 functions to their SDL3 counterparts: ```sh rename_symbols.py --all-symbols source_code_path @@ -152,7 +182,7 @@ Rather than iterating over audio devices using a device index, there are new fun ```c { - if (SDL_InitSubSystem(SDL_INIT_AUDIO) == 0) { + if (SDL_InitSubSystem(SDL_INIT_AUDIO)) { int i, num_devices; SDL_AudioDeviceID *devices = SDL_GetAudioPlaybackDevices(&num_devices); if (devices) { @@ -191,7 +221,7 @@ SDL_FreeWAV has been removed and calls can be replaced with SDL_free. SDL_LoadWAV() is a proper function now and no longer a macro (but offers the same functionality otherwise). -SDL_LoadWAV_IO() and SDL_LoadWAV() return an int now: zero on success, -1 on error, like most of SDL. They no longer return a pointer to an SDL_AudioSpec. +SDL_LoadWAV_IO() and SDL_LoadWAV() return an SDL_bool now, like most of SDL. They no longer return a pointer to an SDL_AudioSpec. SDL_AudioCVT interface has been removed, the SDL_AudioStream interface (for audio supplied in pieces) or the new SDL_ConvertAudioSamples() function (for converting a complete audio buffer in one call) can be used instead. @@ -211,7 +241,7 @@ should be changed to: int dst_len = 0; const SDL_AudioSpec src_spec = { src_format, src_channels, src_rate }; const SDL_AudioSpec dst_spec = { dst_format, dst_channels, dst_rate }; - if (SDL_ConvertAudioSamples(&src_spec, src_data, src_len, &dst_spec, &dst_data, &dst_len) < 0) { + if (!SDL_ConvertAudioSamples(&src_spec, src_data, src_len, &dst_spec, &dst_data, &dst_len)) { /* error */ } do_something(dst_data, dst_len); @@ -375,7 +405,7 @@ The iscapture field of SDL_AudioDeviceEvent has been renamed recording. SDL_QUERY, SDL_IGNORE, SDL_ENABLE, and SDL_DISABLE have been removed. You can use the functions SDL_SetEventEnabled() and SDL_EventEnabled() to set and query event processing state. -SDL_AddEventWatch() now returns -1 if it fails because it ran out of memory and couldn't add the event watch callback. +SDL_AddEventWatch() now returns SDL_FALSE_ if it fails because it ran out of memory and couldn't add the event watch callback. SDL_RegisterEvents() now returns 0 if it couldn't allocate any user events. @@ -702,7 +732,7 @@ Gamepads with simple rumble capability no longer show up in the SDL haptics inte Rather than iterating over haptic devices using device index, there is a new function SDL_GetHaptics() to get the current list of haptic devices, and new functions to get information about haptic devices from their instance ID: ```c { - if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0) { + if (SDL_InitSubSystem(SDL_INIT_HAPTIC)) { int i, num_haptics; SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics); if (haptics) { @@ -717,7 +747,7 @@ Rather than iterating over haptic devices using device index, there is a new fun } ``` -SDL_HapticEffectSupported(), SDL_HapticRumbleSupported(), and SDL_IsJoystickHaptic() now return SDL_bool instead of an optional negative error code. +SDL_GetHapticEffectStatus() now returns SDL_bool instead of an int result. You should call SDL_GetHapticFeatures() to make sure effect status is supported before calling this function. The following functions have been renamed: * SDL_HapticClose() => SDL_CloseHaptic() @@ -753,12 +783,8 @@ The following functions have been removed: ## SDL_hints.h -SDL_AddHintCallback() now returns a standard int result instead of void, returning 0 if the function succeeds or a negative error code if there was an error. - Calling SDL_GetHint() with the name of the hint being changed from within a hint callback will now return the new value rather than the old value. The old value is still passed as a parameter to the hint callback. -SDL_SetHint, SDL_SetHintWithPriority, and SDL_ResetHint now return int (-1 on error, 0 on success) instead of SDL_bool (SDL_FALSE on error, SDL_TRUE on success). - The environment variables SDL_VIDEODRIVER and SDL_AUDIODRIVER have been renamed to SDL_VIDEO_DRIVER and SDL_AUDIO_DRIVER. The environment variables SDL_VIDEO_X11_WMCLASS and SDL_VIDEO_WAYLAND_WMCLASS have been removed and replaced by either using the appindentifier param to SDL_SetAppMetadata() or setting SDL_PROP_APP_METADATA_IDENTIFIER_STRING with SDL_SetAppMetadataProperty() @@ -861,7 +887,7 @@ SDL_JoystickID has changed from Sint32 to Uint32, with an invalid ID being 0. Rather than iterating over joysticks using device index, there is a new function SDL_GetJoysticks() to get the current list of joysticks, and new functions to get information about joysticks from their instance ID: ```c { - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0) { + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK)) { int i, num_joysticks; SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); if (joysticks) { @@ -1128,7 +1154,11 @@ The following symbols have been renamed: SDL_MUTEX_MAXWAIT has been removed; it suggested there was a maximum timeout one could outlive, instead of an infinite wait. Instead, pass a -1 to functions that accepted this symbol. -SDL_LockMutex and SDL_UnlockMutex now return void; if the mutex is valid (including being a NULL pointer, which returns immediately), these functions never fail. If the mutex is invalid or the caller does something illegal, like unlock another thread's mutex, this is considered undefined behavior. +SDL_MUTEX_TIMEDOUT has been removed, the wait functions return SDL_TRUE if the operation succeeded or SDL_FALSE if they timed out. + +SDL_LockMutex(), SDL_UnlockMutex(), SDL_WaitSemaphore(), SDL_SignalSemaphore(), SDL_WaitCondition(), SDL_SignalCondition(), and SDL_BroadcastCondition() now return void; if the object is valid (including being a NULL pointer, which returns immediately), these functions never fail. If the object is invalid or the caller does something illegal, like unlock another thread's mutex, this is considered undefined behavior. + +SDL_TryWaitSemaphore(), SDL_WaitSemaphoreTimeout(), and SDL_WaitConditionTimeout() now return SDL_TRUE if the operation succeeded or SDL_FALSE if they timed out. The following functions have been renamed: * SDL_CondBroadcast() => SDL_BroadcastCondition() @@ -1174,8 +1204,6 @@ should be changed to: pixel = SDL_MapSurfaceRGBA(surface, r, g, b, a); ``` -SDL_GetMasksForPixelFormat() now returns the standard int error code. - SDL_CalculateGammaRamp has been removed, because SDL_SetWindowGammaRamp has been removed as well due to poor support in modern operating systems (see [SDL_video.h](#sdl_videoh)). The following functions have been renamed: @@ -1472,17 +1500,20 @@ static Sint64 SDLCALL stdio_seek(void *userdata, Sint64 offset, int whence) stdiowhence = SEEK_END; break; default: - return SDL_SetError("Unknown value for 'whence'"); + SDL_SetError("Unknown value for 'whence'"); + return -1; } if (fseek(fp, (fseek_off_t)offset, stdiowhence) == 0) { const Sint64 pos = ftell(fp); if (pos < 0) { - return SDL_SetError("Couldn't get stream offset"); + SDL_SetError("Couldn't get stream offset"); + return -1; } return pos; } - return SDL_Error(SDL_EFSEEK); + SDL_SetError("Couldn't seek in stream"); + return -1; } static size_t SDLCALL stdio_read(void *userdata, void *ptr, size_t size, SDL_IOStatus *status) @@ -1490,7 +1521,7 @@ static size_t SDLCALL stdio_read(void *userdata, void *ptr, size_t size, SDL_IOS FILE *fp = ((IOStreamStdioFPData *) userdata)->fp; const size_t bytes = fread(ptr, 1, size, fp); if (bytes == 0 && ferror(fp)) { - SDL_Error(SDL_EFREAD); + SDL_SetError("Couldn't read stream"); } return bytes; } @@ -1500,18 +1531,19 @@ static size_t SDLCALL stdio_write(void *userdata, const void *ptr, size_t size, FILE *fp = ((IOStreamStdioFPData *) userdata)->fp; const size_t bytes = fwrite(ptr, 1, size, fp); if (bytes == 0 && ferror(fp)) { - SDL_Error(SDL_EFWRITE); + SDL_SetError("Couldn't write stream"); } return bytes; } -static int SDLCALL stdio_close(void *userdata) +static SDL_bool SDLCALL stdio_close(void *userdata) { IOStreamStdioData *rwopsdata = (IOStreamStdioData *) userdata; - int status = 0; + SDL_bool status = SDL_TRUE; if (rwopsdata->autoclose) { if (fclose(rwopsdata->fp) != 0) { - status = SDL_Error(SDL_EFWRITE); + SDL_SetError("Couldn't close stream"); + status = SDL_FALSE; } } return status; @@ -1614,7 +1646,7 @@ SDL_SensorID has changed from Sint32 to Uint32, with an invalid ID being 0. Rather than iterating over sensors using device index, there is a new function SDL_GetSensors() to get the current list of sensors, and new functions to get information about sensors from their instance ID: ```c { - if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) { + if (SDL_InitSubSystem(SDL_INIT_SENSOR)) { int i, num_sensors; SDL_SensorID *sensors = SDL_GetSensors(&num_sensors); if (sensors) { @@ -1805,8 +1837,6 @@ SDL_RequestAndroidPermission is no longer a blocking call; the caller now provid SDL_iPhoneSetAnimationCallback() and SDL_iPhoneSetEventPump() have been renamed to SDL_SetiOSAnimationCallback() and SDL_SetiOSEventPump(), respectively. SDL2 has had macros to provide this new name with the old symbol since the introduction of the iPad, but now the correctly-named symbol is the only option. -SDL_GetDXGIOutputInfo() now returns the standard int error code. - The following functions have been removed: * SDL_RenderGetD3D11Device() - replaced with the "SDL.renderer.d3d11.device" property * SDL_RenderGetD3D12Device() - replaced with the "SDL.renderer.d3d12.device" property @@ -1982,8 +2012,6 @@ The callback passed to SDL_AddTimer() has changed parameters to: Uint32 SDLCALL TimerCallback(void *userdata, SDL_TimerID timerID, Uint32 interval); ```` -SDL_RemoveTimer() now returns the standard int error code. - ## SDL_touch.h SDL_GetTouchName is replaced with SDL_GetTouchDeviceName(), which takes an SDL_TouchID instead of an index. @@ -2023,7 +2051,7 @@ SDL_VideoInit() and SDL_VideoQuit() have been removed. Instead you can call SDL_ Rather than iterating over displays using display index, there is a new function SDL_GetDisplays() to get the current list of displays, and functions which used to take a display index now take SDL_DisplayID, with an invalid ID being 0. ```c { - if (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) { + if (SDL_InitSubSystem(SDL_INIT_VIDEO)) { int i, num_displays = 0; SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); if (displays) { @@ -2097,11 +2125,9 @@ Removed SDL_GL_CONTEXT_EGL from OpenGL configuration attributes. You can instead SDL_GL_GetProcAddress() and SDL_EGL_GetProcAddress() now return `SDL_FunctionPointer` instead of `void *`, and should be cast to the appropriate function type. You can define SDL_FUNCTION_POINTER_IS_VOID_POINTER in your project to restore the previous behavior. -SDL_GL_SwapWindow() returns 0 if the function succeeds or a negative error code if there was an error. +SDL_GL_DeleteContext() has been renamed to SDL_GL_DestroyContext to match SDL naming conventions (and glX/EGL!). -SDL_GL_DeleteContext() has been renamed to SDL_GL_DestroyContext to match SDL naming conventions (and glX!). It also now returns 0 if the function succeeds or a negative error code if there was an error (it returned void in SDL2). - -SDL_GL_GetSwapInterval() takes the interval as an output parameter and returns 0 if the function succeeds or a negative error code if there was an error. +SDL_GL_GetSwapInterval() takes the interval as an output parameter and returns SDL_TRUE if the function succeeds or SDL_FALSE if there was an error. SDL_GL_GetDrawableSize() has been removed. SDL_GetWindowSizeInPixels() can be used in its place. @@ -2188,8 +2214,6 @@ SDL_Vulkan_GetInstanceExtensions() no longer takes a window parameter, and no lo SDL_Vulkan_GetVkGetInstanceProcAddr() now returns `SDL_FunctionPointer` instead of `void *`, and should be cast to PFN_vkGetInstanceProcAddr. -SDL_Vulkan_CreateSurface() now returns an int (0=success, -1=error) instead of an SDL_bool (true=success, false=error). - SDL_Vulkan_CreateSurface() now takes a VkAllocationCallbacks pointer as its third parameter. If you don't have an allocator to supply, pass a NULL here to use the system default allocator (SDL2 always used the system default allocator here). SDL_Vulkan_GetDrawableSize() has been removed. SDL_GetWindowSizeInPixels() can be used in its place. diff --git a/docs/README-winrt.md b/docs/README-winrt.md index 58a3074205..45ce80a4c3 100644 --- a/docs/README-winrt.md +++ b/docs/README-winrt.md @@ -298,9 +298,9 @@ int main(int argc, char **argv) SDL_Event evt; SDL_bool keep_going = SDL_TRUE; - if (SDL_Init(SDL_INIT_VIDEO) != 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { return 1; - } else if (SDL_CreateWindowAndRenderer("Hello SDL", 0, 0, SDL_WINDOW_FULLSCREEN, &window, &renderer) != 0) { + } else if (!SDL_CreateWindowAndRenderer("Hello SDL", 0, 0, SDL_WINDOW_FULLSCREEN, &window, &renderer)) { return 1; } diff --git a/examples/audio/01-simple-playback/simple-playback.c b/examples/audio/01-simple-playback/simple-playback.c index efefd8be79..ca4fc8c49f 100644 --- a/examples/audio/01-simple-playback/simple-playback.c +++ b/examples/audio/01-simple-playback/simple-playback.c @@ -21,13 +21,13 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { SDL_AudioSpec spec; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } /* we don't _need_ a window for audio-only things but it's good policy to have one. */ - if (SDL_CreateWindowAndRenderer("examples/audio/simple-playback", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/audio/simple-playback", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/examples/audio/02-simple-playback-callback/simple-playback-callback.c b/examples/audio/02-simple-playback-callback/simple-playback-callback.c index ff71d746a1..a612c45b40 100644 --- a/examples/audio/02-simple-playback-callback/simple-playback-callback.c +++ b/examples/audio/02-simple-playback-callback/simple-playback-callback.c @@ -53,13 +53,13 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { SDL_AudioSpec spec; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } /* we don't _need_ a window for audio-only things but it's good policy to have one. */ - if (SDL_CreateWindowAndRenderer("examples/audio/simple-playback-callback", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/audio/simple-playback-callback", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/examples/audio/03-load-wav/load-wav.c b/examples/audio/03-load-wav/load-wav.c index 44f0c1e145..7f5d458450 100644 --- a/examples/audio/03-load-wav/load-wav.c +++ b/examples/audio/03-load-wav/load-wav.c @@ -31,20 +31,20 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) SDL_AudioSpec spec; char *wav_path = NULL; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } /* we don't _need_ a window for audio-only things but it's good policy to have one. */ - if (SDL_CreateWindowAndRenderer("examples/audio/load-wav", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/audio/load-wav", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } /* Load the .wav file from wherever the app is being run from. */ SDL_asprintf(&wav_path, "%ssample.wav", SDL_GetBasePath()); /* allocate a string of the full file path */ - if (SDL_LoadWAV(wav_path, &spec, &wav_data, &wav_data_len) == -1) { + if (!SDL_LoadWAV(wav_path, &spec, &wav_data, &wav_data_len)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't load .wav file!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/examples/camera/01-read-and-draw/read-and-draw.c b/examples/camera/01-read-and-draw/read-and-draw.c index 91997e3f2d..1a0363d816 100644 --- a/examples/camera/01-read-and-draw/read-and-draw.c +++ b/examples/camera/01-read-and-draw/read-and-draw.c @@ -26,12 +26,12 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) SDL_CameraID *devices = NULL; int devcount = 0; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_CAMERA) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_CAMERA)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } - if (SDL_CreateWindowAndRenderer("examples/camera/read-and-draw", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/camera/read-and-draw", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/examples/game/01-snake/main.c b/examples/game/01-snake/main.c index 8eda24e829..d958b71c54 100644 --- a/examples/game/01-snake/main.c +++ b/examples/game/01-snake/main.c @@ -26,17 +26,11 @@ typedef struct static Uint32 sdl_timer_callback_(void *payload, SDL_TimerID timer_id, Uint32 interval) { - SDL_Event e; - SDL_UserEvent ue; /* NOTE: snake_step is not called here directly for multithreaded concerns. */ - (void)payload; - ue.type = SDL_EVENT_USER; - ue.code = 0; - ue.data1 = NULL; - ue.data2 = NULL; - e.type = SDL_EVENT_USER; - e.user = ue; - SDL_PushEvent(&e); + SDL_Event event; + SDL_zero(event); + event.type = SDL_EVENT_USER; + SDL_PushEvent(&event); return interval; } @@ -113,14 +107,14 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { (void)argc; (void)argv; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) { return SDL_APP_FAILURE; } SDL_SetHint("SDL_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR", "0"); AppState *as = malloc(sizeof(AppState)); *appstate = as; as->step_timer = 0; - if (SDL_CreateWindowAndRenderer("examples/game/snake", SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT, 0, &as->window, &as->renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/game/snake", SDL_WINDOW_WIDTH, SDL_WINDOW_HEIGHT, 0, &as->window, &as->renderer)) { return SDL_APP_FAILURE; } snake_initialize(&as->snake_ctx, SDL_rand); diff --git a/examples/pen/01-drawing-lines/drawing-lines.c b/examples/pen/01-drawing-lines/drawing-lines.c index a8d82ae887..47c8d8686c 100644 --- a/examples/pen/01-drawing-lines/drawing-lines.c +++ b/examples/pen/01-drawing-lines/drawing-lines.c @@ -23,12 +23,12 @@ static float previous_touch_y = -1.0f; /* This function runs once at startup. */ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { - if (SDL_Init(SDL_INIT_VIDEO) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } - if (SDL_CreateWindowAndRenderer("examples/pen/drawing-lines", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/pen/drawing-lines", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/examples/renderer/01-clear/renderer-clear.c b/examples/renderer/01-clear/renderer-clear.c index c5da1335d1..7c7d6b6b3d 100644 --- a/examples/renderer/01-clear/renderer-clear.c +++ b/examples/renderer/01-clear/renderer-clear.c @@ -25,12 +25,12 @@ static int fade_direction = 1; /* This function runs once at startup. */ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { - if (SDL_Init(SDL_INIT_VIDEO) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } - if (SDL_CreateWindowAndRenderer("examples/renderer/clear", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/renderer/clear", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/examples/renderer/02-primitives/renderer-primitives.c b/examples/renderer/02-primitives/renderer-primitives.c index 76cb8e7bc0..34a6e93901 100644 --- a/examples/renderer/02-primitives/renderer-primitives.c +++ b/examples/renderer/02-primitives/renderer-primitives.c @@ -19,12 +19,12 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { int i; - if (SDL_Init(SDL_INIT_VIDEO) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } - if (SDL_CreateWindowAndRenderer("examples/renderer/primitives", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/renderer/primitives", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/examples/template.c b/examples/template.c index 48c23b037d..0404b5b119 100644 --- a/examples/template.c +++ b/examples/template.c @@ -16,12 +16,12 @@ static SDL_Renderer *renderer = NULL; /* This function runs once at startup. */ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { - if (SDL_Init(SDL_INIT_VIDEO) == -1) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't initialize SDL!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } - if (SDL_CreateWindowAndRenderer("examples/CATEGORY/NAME", 640, 480, 0, &window, &renderer) == -1) { + if (!SDL_CreateWindowAndRenderer("examples/CATEGORY/NAME", 640, 480, 0, &window, &renderer)) { SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create window/renderer!", SDL_GetError(), NULL); return SDL_APP_FAILURE; } diff --git a/include/SDL3/SDL_audio.h b/include/SDL3/SDL_audio.h index e4c5180736..a1b7e8cb66 100644 --- a/include/SDL3/SDL_audio.h +++ b/include/SDL3/SDL_audio.h @@ -531,14 +531,14 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceI * \param spec on return, will be filled with device details. * \param sample_frames pointer to store device buffer size, in sample frames. * Can be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames); /** * Get the current channel map of an audio device. @@ -658,7 +658,7 @@ extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDevic * created through SDL_OpenAudioDevice() can be. * * \param dev a device opened by SDL_OpenAudioDevice(). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -668,7 +668,7 @@ extern SDL_DECLSPEC SDL_AudioDeviceID SDLCALL SDL_OpenAudioDevice(SDL_AudioDevic * \sa SDL_ResumeAudioDevice * \sa SDL_AudioDevicePaused */ -extern SDL_DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev); /** * Use this function to unpause audio playback on a specified device. @@ -686,7 +686,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev); * created through SDL_OpenAudioDevice() can be. * * \param dev a device opened by SDL_OpenAudioDevice(). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -696,7 +696,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_PauseAudioDevice(SDL_AudioDeviceID dev); * \sa SDL_AudioDevicePaused * \sa SDL_PauseAudioDevice */ -extern SDL_DECLSPEC int SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID dev); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID dev); /** * Use this function to query if an audio device is paused. @@ -766,7 +766,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid * * \param devid the audio device on which to change gain. * \param gain the gain. 1.0f is no change, 0.0f is silence. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as it holds @@ -776,7 +776,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid * * \sa SDL_GetAudioDeviceGain */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain); /** * Close a previously-opened audio device. @@ -823,7 +823,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid); * \param devid an audio device to bind a stream to. * \param streams an array of audio streams to bind. * \param num_streams number streams listed in the `streams` array. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -834,7 +834,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseAudioDevice(SDL_AudioDeviceID devid); * \sa SDL_UnbindAudioStream * \sa SDL_GetAudioStreamDevice */ -extern SDL_DECLSPEC int SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams); /** * Bind a single audio stream to an audio device. @@ -844,7 +844,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SD * * \param devid an audio device to bind a stream to. * \param stream an audio stream to bind to a device. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -855,7 +855,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BindAudioStreams(SDL_AudioDeviceID devid, SD * \sa SDL_UnbindAudioStream * \sa SDL_GetAudioStreamDevice */ -extern SDL_DECLSPEC int SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream); /** * Unbind a list of audio streams from their audio devices. @@ -952,7 +952,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_Au * \param stream the SDL_AudioStream to query. * \param src_spec where to store the input audio format; ignored if NULL. * \param dst_spec where to store the output audio format; ignored if NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as it holds @@ -962,9 +962,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetAudioStreamProperties(SDL_Au * * \sa SDL_SetAudioStreamFormat */ -extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream, - SDL_AudioSpec *src_spec, - SDL_AudioSpec *dst_spec); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec); /** * Change the input and output formats of an audio stream. @@ -984,7 +982,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream * changed. * \param dst_spec the new format of the audio output; if NULL, it is not * changed. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as it holds @@ -995,9 +993,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamFormat(SDL_AudioStream *stream * \sa SDL_GetAudioStreamFormat * \sa SDL_SetAudioStreamFrequencyRatio */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream, - const SDL_AudioSpec *src_spec, - const SDL_AudioSpec *dst_spec); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec); /** * Get the frequency ratio of an audio stream. @@ -1030,7 +1026,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStre * \param stream the stream the frequency ratio is being changed. * \param ratio the frequency ratio. 1.0 is normal speed. Must be between 0.01 * and 100. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as it holds @@ -1041,7 +1037,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamFrequencyRatio(SDL_AudioStre * \sa SDL_GetAudioStreamFrequencyRatio * \sa SDL_SetAudioStreamFormat */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float ratio); /** * Get the gain of an audio stream. @@ -1077,7 +1073,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamGain(SDL_AudioStream *stream * * \param stream the stream on which the gain is being changed. * \param gain the gain. 1.0f is no change, 0.0f is silence. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as it holds @@ -1087,7 +1083,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetAudioStreamGain(SDL_AudioStream *stream * * \sa SDL_GetAudioStreamGain */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain); /** * Get the current input channel map of an audio stream. @@ -1174,7 +1170,7 @@ extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioSt * \param stream the SDL_AudioStream to change. * \param chmap the new channel map, NULL to reset to default. * \param count The number of channels in the map. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as it holds @@ -1186,7 +1182,7 @@ extern SDL_DECLSPEC int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioSt * * \sa SDL_SetAudioStreamInputChannelMap */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int count); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int count); /** * Set the current output channel map of an audio stream. @@ -1221,7 +1217,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStrea * \param stream the SDL_AudioStream to change. * \param chmap the new channel map, NULL to reset to default. * \param count The number of channels in the map. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as it holds @@ -1233,7 +1229,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamInputChannelMap(SDL_AudioStrea * * \sa SDL_SetAudioStreamInputChannelMap */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int count); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int count); /** * Add data to the stream. @@ -1249,7 +1245,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStre * \param stream the stream the audio data is being added to. * \param buf a pointer to the audio data to add. * \param len the number of bytes to write to the stream. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, but if the @@ -1263,7 +1259,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamOutputChannelMap(SDL_AudioStre * \sa SDL_GetAudioStreamData * \sa SDL_GetAudioStreamQueued */ -extern SDL_DECLSPEC int SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len); /** * Get converted/resampled data from the stream. @@ -1280,7 +1276,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_PutAudioStreamData(SDL_AudioStream *stream, * \param stream the stream the audio is being requested from. * \param buf a buffer to fill with audio data. * \param len the maximum number of bytes to fill. - * \returns the number of bytes read from the stream or a negative error code + * \returns the number of bytes read from the stream or -1 * on failure; call SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, but if the @@ -1309,8 +1305,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamData(SDL_AudioStream *stream, * clamped. * * \param stream the audio stream to query. - * \returns the number of converted/resampled bytes available or a negative - * error code on failure; call SDL_GetError() for more information. + * \returns the number of converted/resampled bytes available or -1 on failure; call SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * @@ -1342,7 +1337,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamAvailable(SDL_AudioStream *str * clamped. * * \param stream the audio stream to query. - * \returns the number of bytes queued or a negative error code on failure; + * \returns the number of bytes queued or -1 on failure; * call SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -1364,7 +1359,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamQueued(SDL_AudioStream *stream * input, so the complete output becomes available. * * \param stream the audio stream to flush. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -1373,7 +1368,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioStreamQueued(SDL_AudioStream *stream * * \sa SDL_PutAudioStreamData */ -extern SDL_DECLSPEC int SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream); /** * Clear any pending data in the stream. @@ -1382,7 +1377,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream); * stream until more is added. * * \param stream the audio stream to clear. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -1394,7 +1389,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_FlushAudioStream(SDL_AudioStream *stream); * \sa SDL_GetAudioStreamQueued * \sa SDL_PutAudioStreamData */ -extern SDL_DECLSPEC int SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream); /** * Use this function to pause audio playback on the audio device associated @@ -1409,7 +1404,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream); * loading, etc. * * \param stream the audio stream associated with the audio device to pause. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -1418,7 +1413,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ClearAudioStream(SDL_AudioStream *stream); * * \sa SDL_ResumeAudioStreamDevice */ -extern SDL_DECLSPEC int SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *stream); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *stream); /** * Use this function to unpause audio playback on the audio device associated @@ -1429,7 +1424,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *stre * to progress again, and audio can be generated. * * \param stream the audio stream associated with the audio device to resume. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -1438,7 +1433,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_PauseAudioStreamDevice(SDL_AudioStream *stre * * \sa SDL_PauseAudioStreamDevice */ -extern SDL_DECLSPEC int SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream); /** * Lock an audio stream for serialized access. @@ -1457,7 +1452,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *str * all the same attributes (recursive locks are allowed, etc). * * \param stream the audio stream to lock. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -1466,7 +1461,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ResumeAudioStreamDevice(SDL_AudioStream *str * * \sa SDL_UnlockAudioStream */ -extern SDL_DECLSPEC int SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream); /** @@ -1475,7 +1470,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream); * This unlocks an audio stream after a call to SDL_LockAudioStream. * * \param stream the audio stream to unlock. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety You should only call this from the same thread that @@ -1485,7 +1480,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LockAudioStream(SDL_AudioStream *stream); * * \sa SDL_LockAudioStream */ -extern SDL_DECLSPEC int SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UnlockAudioStream(SDL_AudioStream *stream); /** * A callback that fires when data passes through an SDL_AudioStream. @@ -1564,7 +1559,7 @@ typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream * stream. * \param userdata an opaque pointer provided to the callback for its own * personal use. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. This only fails if `stream` * is NULL. * @@ -1574,7 +1569,7 @@ typedef void (SDLCALL *SDL_AudioStreamCallback)(void *userdata, SDL_AudioStream * * \sa SDL_SetAudioStreamPutCallback */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata); /** * Set a callback that runs when data is added to an audio stream. @@ -1614,7 +1609,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *s * stream. * \param userdata an opaque pointer provided to the callback for its own * personal use. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. This only fails if `stream` * is NULL. * @@ -1624,7 +1619,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamGetCallback(SDL_AudioStream *s * * \sa SDL_SetAudioStreamGetCallback */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata); /** @@ -1793,14 +1788,14 @@ typedef void (SDLCALL *SDL_AudioPostmixCallback)(void *userdata, const SDL_Audio * \param devid the ID of an opened audio device. * \param callback a callback function to be called. Can be NULL. * \param userdata app-controlled pointer passed to callback. Can be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata); /** @@ -1863,11 +1858,11 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID de * function. * \param audio_len a pointer filled with the length of the audio data buffer * in bytes. - * \returns 0 on success. `audio_buf` will be filled with a pointer to an + * \returns SDL_TRUE on success. `audio_buf` will be filled with a pointer to an * allocated buffer containing the audio data, and `audio_len` is * filled with the length of that audio buffer in bytes. * - * This function returns -1 if the .WAV file cannot be opened, uses + * This function returns SDL_FALSE if the .WAV file cannot be opened, uses * an unknown data format, or is corrupt; call SDL_GetError() for * more information. * @@ -1881,9 +1876,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioPostmixCallback(SDL_AudioDeviceID de * \sa SDL_free * \sa SDL_LoadWAV */ -extern SDL_DECLSPEC int SDLCALL SDL_LoadWAV_IO(SDL_IOStream * src, SDL_bool closeio, - SDL_AudioSpec * spec, Uint8 ** audio_buf, - Uint32 * audio_len); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LoadWAV_IO(SDL_IOStream *src, SDL_bool closeio, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len); /** * Loads a WAV from a file path. @@ -1891,7 +1884,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LoadWAV_IO(SDL_IOStream * src, SDL_bool clos * This is a convenience function that is effectively the same as: * * ```c - * SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), 1, spec, audio_buf, audio_len); + * SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), SDL_TRUE, spec, audio_buf, audio_len); * ``` * * \param path the file path of the WAV file to open. @@ -1901,11 +1894,11 @@ extern SDL_DECLSPEC int SDLCALL SDL_LoadWAV_IO(SDL_IOStream * src, SDL_bool clos * function. * \param audio_len a pointer filled with the length of the audio data buffer * in bytes. - * \returns 0 on success. `audio_buf` will be filled with a pointer to an + * \returns SDL_TRUE on success. `audio_buf` will be filled with a pointer to an * allocated buffer containing the audio data, and `audio_len` is * filled with the length of that audio buffer in bytes. * - * This function returns -1 if the .WAV file cannot be opened, uses + * This function returns SDL_FALSE if the .WAV file cannot be opened, uses * an unknown data format, or is corrupt; call SDL_GetError() for * more information. * @@ -1919,8 +1912,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LoadWAV_IO(SDL_IOStream * src, SDL_bool clos * \sa SDL_free * \sa SDL_LoadWAV_IO */ -extern SDL_DECLSPEC int SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec * spec, - Uint8 ** audio_buf, Uint32 * audio_len); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len); /** * Mix audio data in a specified format. @@ -1949,17 +1941,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_LoadWAV(const char *path, SDL_AudioSpec * sp * \param len the length of the audio buffer in bytes. * \param volume ranges from 0.0 - 1.0, and should be set to 1.0 for full * audio volume. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_MixAudio(Uint8 * dst, - const Uint8 * src, - SDL_AudioFormat format, - Uint32 len, float volume); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, float volume); /** * Convert some audio data of one format to another format. @@ -1982,19 +1971,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_MixAudio(Uint8 * dst, * which should be freed with SDL_free(). On error, it will be * NULL. * \param dst_len will be filled with the len of dst_data. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, - const Uint8 *src_data, - int src_len, - const SDL_AudioSpec *dst_spec, - Uint8 **dst_data, - int *dst_len); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data, int src_len, const SDL_AudioSpec *dst_spec, Uint8 **dst_data, int *dst_len); /** * Get the human readable name of an audio format. diff --git a/include/SDL3/SDL_camera.h b/include/SDL3/SDL_camera.h index ad9c826b07..7282e7f82d 100644 --- a/include/SDL3/SDL_camera.h +++ b/include/SDL3/SDL_camera.h @@ -366,14 +366,14 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetCameraProperties(SDL_Camera * be converting to this format behind the scenes. * * If the system is waiting for the user to approve access to the camera, as - * some platforms require, this will return -1, but this isn't necessarily a + * some platforms require, this will return SDL_FALSE, but this isn't necessarily a * fatal error; you should either wait for an SDL_EVENT_CAMERA_DEVICE_APPROVED * (or SDL_EVENT_CAMERA_DEVICE_DENIED) event, or poll SDL_IsCameraApproved() * occasionally until it returns non-zero. * * \param camera opened camera device. * \param spec the SDL_CameraSpec to be initialized by this function. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -382,7 +382,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetCameraProperties(SDL_Camera * * \sa SDL_OpenCamera */ -extern SDL_DECLSPEC int SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec); /** * Acquire a frame. @@ -446,8 +446,6 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_AcquireCameraFrame(SDL_Camera *cam * * \param camera opened camera device. * \param frame the video frame surface to release. - * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * @@ -455,7 +453,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_AcquireCameraFrame(SDL_Camera *cam * * \sa SDL_AcquireCameraFrame */ -extern SDL_DECLSPEC int SDLCALL SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame); +extern SDL_DECLSPEC void SDLCALL SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame); /** * Use this function to shut down camera processing and close the camera diff --git a/include/SDL3/SDL_clipboard.h b/include/SDL3/SDL_clipboard.h index ccd32011c5..0e5230e677 100644 --- a/include/SDL3/SDL_clipboard.h +++ b/include/SDL3/SDL_clipboard.h @@ -46,7 +46,7 @@ extern "C" { * Put UTF-8 text into the clipboard. * * \param text the text to store in the clipboard. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -54,7 +54,7 @@ extern "C" { * \sa SDL_GetClipboardText * \sa SDL_HasClipboardText */ -extern SDL_DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetClipboardText(const char *text); /** * Get UTF-8 text from the clipboard. @@ -89,7 +89,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void); * Put UTF-8 text into the primary selection. * * \param text the text to store in the primary selection. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -97,7 +97,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasClipboardText(void); * \sa SDL_GetPrimarySelectionText * \sa SDL_HasPrimarySelectionText */ -extern SDL_DECLSPEC int SDLCALL SDL_SetPrimarySelectionText(const char *text); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPrimarySelectionText(const char *text); /** * Get UTF-8 text from the primary selection. @@ -185,7 +185,7 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata); * \param userdata an opaque pointer that will be forwarded to the callbacks. * \param mime_types a list of mime-types that are being offered. * \param num_mime_types the number of mime-types in the mime_types list. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -194,19 +194,19 @@ typedef void (SDLCALL *SDL_ClipboardCleanupCallback)(void *userdata); * \sa SDL_GetClipboardData * \sa SDL_HasClipboardData */ -extern SDL_DECLSPEC int SDLCALL SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types); /** * Clear the clipboard data. * - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetClipboardData */ -extern SDL_DECLSPEC int SDLCALL SDL_ClearClipboardData(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearClipboardData(void); /** * Get the data from clipboard for a given mime type. diff --git a/include/SDL3/SDL_error.h b/include/SDL3/SDL_error.h index 75e8370b14..a98823f9fc 100644 --- a/include/SDL3/SDL_error.h +++ b/include/SDL3/SDL_error.h @@ -56,25 +56,25 @@ extern "C" { * \param fmt a printf()-style message format string. * \param ... additional parameters matching % tokens in the `fmt` string, if * any. - * \returns -1. + * \returns SDL_FALSE. * * \since This function is available since SDL 3.0.0. * * \sa SDL_ClearError * \sa SDL_GetError */ -extern SDL_DECLSPEC int SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) SDL_PRINTF_VARARG_FUNC(1); /** * Set an error indicating that memory allocation failed. * * This function does not do any memory allocation. * - * \returns -1. + * \returns SDL_FALSE. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_OutOfMemory(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_OutOfMemory(void); /** * Retrieve a message about the last error that occurred on the current @@ -114,14 +114,14 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetError(void); /** * Clear any previous error message for this thread. * - * \returns 0. + * \returns SDL_TRUE. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetError * \sa SDL_SetError */ -extern SDL_DECLSPEC int SDLCALL SDL_ClearError(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearError(void); /** * \name Internal error functions diff --git a/include/SDL3/SDL_events.h b/include/SDL3/SDL_events.h index 6ee2cb9088..6d845fb83f 100644 --- a/include/SDL3/SDL_events.h +++ b/include/SDL3/SDL_events.h @@ -1039,7 +1039,7 @@ typedef enum SDL_EventAction * SDL_EVENT_FIRST is a safe choice. * \param maxType maximum value of the event type to be considered; * SDL_EVENT_LAST is a safe choice. - * \returns the number of events actually stored or a negative error code on + * \returns the number of events actually stored or -1 on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1254,8 +1254,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitEventTimeout(SDL_Event *event, Sint * its own custom event types. * * \param event the SDL_Event to be added to the queue. - * \returns 1 on success, 0 if the event was filtered, or a negative error - * code on failure; call SDL_GetError() for more information. A + * \returns SDL_TRUE on success, SDL_FALSE if the event was filtered or on failure; call SDL_GetError() for more information. A * common reason for error is the event queue being full. * * \since This function is available since SDL 3.0.0. @@ -1264,7 +1263,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitEventTimeout(SDL_Event *event, Sint * \sa SDL_PollEvent * \sa SDL_RegisterEvents */ -extern SDL_DECLSPEC int SDLCALL SDL_PushEvent(SDL_Event *event); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PushEvent(SDL_Event *event); /** * A function pointer used for callbacks that watch the event queue. @@ -1372,7 +1371,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter *filter, * * \param filter an SDL_EventFilter function to call when an event happens. * \param userdata a pointer that is passed to `filter`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -1382,7 +1381,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetEventFilter(SDL_EventFilter *filter, * \sa SDL_DelEventWatch * \sa SDL_SetEventFilter */ -extern SDL_DECLSPEC int SDLCALL SDL_AddEventWatch(SDL_EventFilter filter, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AddEventWatch(SDL_EventFilter filter, void *userdata); /** * Remove an event watch callback added with SDL_AddEventWatch(). diff --git a/include/SDL3/SDL_filesystem.h b/include/SDL3/SDL_filesystem.h index 756a52dcc1..abf9875bb3 100644 --- a/include/SDL3/SDL_filesystem.h +++ b/include/SDL3/SDL_filesystem.h @@ -266,12 +266,12 @@ typedef Uint32 SDL_GlobFlags; * Create a directory. * * \param path the path of the directory to create. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_CreateDirectory(const char *path); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CreateDirectory(const char *path); /* Callback for directory enumeration. Return 1 to keep enumerating, 0 to stop enumerating (no error), -1 to stop enumerating and @@ -289,47 +289,47 @@ typedef int (SDLCALL *SDL_EnumerateDirectoryCallback)(void *userdata, const char * \param path the path of the directory to enumerate. * \param callback a function that is called for each entry in the directory. * \param userdata a pointer that is passed to `callback`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata); /** * Remove a file or an empty directory. * * \param path the path of the directory to enumerate. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_RemovePath(const char *path); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RemovePath(const char *path); /** * Rename a file or directory. * * \param oldpath the old path. * \param newpath the new path. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_RenamePath(const char *oldpath, const char *newpath); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenamePath(const char *oldpath, const char *newpath); /** * Copy a file. * * \param oldpath the old path. * \param newpath the new path. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_CopyFile(const char *oldpath, const char *newpath); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyFile(const char *oldpath, const char *newpath); /** * Get information about a filesystem path. @@ -337,12 +337,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_CopyFile(const char *oldpath, const char *ne * \param path the path to query. * \param info a pointer filled in with information about the path, or NULL to * check for the existence of a file. - * \returns 0 on success or a negative error code if the file doesn't exist, + * \returns SDL_TRUE on success or SDL_FALSE if the file doesn't exist, * or another failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *info); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *info); /** * Enumerate a directory tree, filtered by pattern, and return a list. diff --git a/include/SDL3/SDL_gamepad.h b/include/SDL3/SDL_gamepad.h index cec068446e..22e315fbe9 100644 --- a/include/SDL3/SDL_gamepad.h +++ b/include/SDL3/SDL_gamepad.h @@ -379,12 +379,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddGamepadMappingsFromFile(const char *file) * * This will generate gamepad events as needed if device mappings change. * - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ReloadGamepadMappings(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReloadGamepadMappings(void); /** * Get the current gamepad mappings. @@ -442,7 +442,7 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad); * \param instance_id the joystick instance ID. * \param mapping the mapping to use for this device, or NULL to clear the * mapping. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -450,7 +450,7 @@ extern SDL_DECLSPEC char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad); * \sa SDL_AddGamepadMapping * \sa SDL_GetGamepadMapping */ -extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping); /** * Return whether a gamepad is currently connected. @@ -813,14 +813,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad); * \param gamepad the gamepad object to adjust. * \param player_index player index to assign to this gamepad, or -1 to clear * the player index and turn off player LEDs. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetGamepadPlayerIndex */ -extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index); /** * Get the USB vendor ID of an opened gamepad, if available. @@ -1257,14 +1257,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *ga * \param y filled with y position, normalized 0 to 1, with the origin in the * upper left. * \param pressure filled with pressure value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetNumGamepadTouchpadFingers */ -extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure); /** * Return whether a gamepad has a particular sensor. @@ -1287,7 +1287,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, * \param gamepad the gamepad to update. * \param type the type of sensor to enable/disable. * \param enabled whether data reporting should be enabled. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1295,7 +1295,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadHasSensor(SDL_Gamepad *gamepad, * \sa SDL_GamepadHasSensor * \sa SDL_GamepadSensorEnabled */ -extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled); /** * Query whether sensor data reporting is enabled for a gamepad. @@ -1331,12 +1331,12 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetGamepadSensorDataRate(SDL_Gamepad *game * \param type the type of sensor to query. * \param data a pointer filled with the current sensor state. * \param num_values the number of values to write to data. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values); /** * Start a rumble effect on a gamepad. @@ -1353,11 +1353,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, S * \param high_frequency_rumble the intensity of the high frequency (right) * rumble motor, from 0 to 0xFFFF. * \param duration_ms the duration of the rumble effect, in milliseconds. - * \returns 0, or -1 if rumble isn't supported on this gamepad. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call + * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); /** * Start a rumble effect in the gamepad's triggers. @@ -1378,14 +1379,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 l * \param right_rumble the intensity of the right trigger rumble motor, from 0 * to 0xFFFF. * \param duration_ms the duration of the rumble effect, in milliseconds. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RumbleGamepad */ -extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); /** * Update a gamepad's LED color. @@ -1400,12 +1401,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, * \param red the intensity of the red LED. * \param green the intensity of the green LED. * \param blue the intensity of the blue LED. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue); /** * Send a gamepad specific effect packet. @@ -1413,12 +1414,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 re * \param gamepad the gamepad to affect. * \param data the data to send to the gamepad. * \param size the size of the data to send to the gamepad. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size); /** * Close a gamepad previously opened with SDL_OpenGamepad(). diff --git a/include/SDL3/SDL_haptic.h b/include/SDL3/SDL_haptic.h index 93935e9b87..04f72fb703 100644 --- a/include/SDL3/SDL_haptic.h +++ b/include/SDL3/SDL_haptic.h @@ -48,15 +48,15 @@ * SDL_free(haptics); * } * if (haptic == NULL) - * return -1; + * return; * * // Initialize simple rumble - * if (SDL_InitHapticRumble(haptic) != 0) - * return -1; + * if (!SDL_InitHapticRumble(haptic)) + * return; * * // Play effect at 50% strength for 2 seconds - * if (SDL_PlayHapticRumble(haptic, 0.5, 2000) != 0) - * return -1; + * if (!SDL_PlayHapticRumble(haptic, 0.5, 2000)) + * return; * SDL_Delay(2000); * * // Clean up @@ -66,7 +66,7 @@ * Complete example: * * ```c - * int test_haptic(SDL_Joystick *joystick) + * SDL_bool test_haptic(SDL_Joystick *joystick) * { * SDL_Haptic *haptic; * SDL_HapticEffect effect; @@ -74,12 +74,12 @@ * * // Open the device * haptic = SDL_OpenHapticFromJoystick(joystick); - * if (haptic == NULL) return -1; // Most likely joystick isn't haptic + * if (haptic == NULL) return SDL_FALSE; // Most likely joystick isn't haptic * * // See if it can do sine waves * if ((SDL_GetHapticFeatures(haptic) & SDL_HAPTIC_SINE)==0) { * SDL_CloseHaptic(haptic); // No sine effect - * return -1; + * return SDL_FALSE; * } * * // Create the effect @@ -106,7 +106,7 @@ * // Close the device * SDL_CloseHaptic(haptic); * - * return 0; // Success + * return SDL_TRUE; // Success * } * ``` * @@ -1116,7 +1116,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetMaxHapticEffects(SDL_Haptic *haptic); * * \param haptic the SDL_Haptic device to query maximum playing effects. * \returns the number of effects the haptic device can play at the same time - * or a negative error code on failure; call SDL_GetError() for more + * or -1 on failure; call SDL_GetError() for more * information. * * \since This function is available since SDL 3.0.0. @@ -1147,7 +1147,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetHapticFeatures(SDL_Haptic *haptic); * SDL_HapticDirection effect. * * \param haptic the SDL_Haptic device to query. - * \returns the number of axes on success or a negative error code on failure; + * \returns the number of axes on success or -1 on failure; * call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1174,7 +1174,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HapticEffectSupported(SDL_Haptic *hapti * \param haptic an SDL_Haptic device to create the effect on. * \param effect an SDL_HapticEffect structure containing the properties of * the effect to create. - * \returns the ID of the effect on success or a negative error code on + * \returns the ID of the effect on success or -1 on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1197,7 +1197,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const * \param effect the identifier of the effect to update. * \param data an SDL_HapticEffect structure containing the new effect * properties to use. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1205,7 +1205,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_CreateHapticEffect(SDL_Haptic *haptic, const * \sa SDL_CreateHapticEffect * \sa SDL_RunHapticEffect */ -extern SDL_DECLSPEC int SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data); /** * Run the haptic effect on its associated haptic device. @@ -1220,7 +1220,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int e * \param effect the ID of the haptic effect to run. * \param iterations the number of iterations to run the effect; use * `SDL_HAPTIC_INFINITY` to repeat forever. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1229,14 +1229,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateHapticEffect(SDL_Haptic *haptic, int e * \sa SDL_StopHapticEffect * \sa SDL_StopHapticEffects */ -extern SDL_DECLSPEC int SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations); /** * Stop the haptic effect on its associated haptic device. * * \param haptic the SDL_Haptic device to stop the effect on. * \param effect the ID of the haptic effect to stop. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1244,7 +1244,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RunHapticEffect(SDL_Haptic *haptic, int effe * \sa SDL_RunHapticEffect * \sa SDL_StopHapticEffects */ -extern SDL_DECLSPEC int SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopHapticEffect(SDL_Haptic *haptic, int effect); /** * Destroy a haptic effect on the device. @@ -1268,12 +1268,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyHapticEffect(SDL_Haptic *haptic, int * * \param haptic the SDL_Haptic device to query for the effect status on. * \param effect the ID of the haptic effect to query its status. - * \returns 0 if it isn't playing, 1 if it is playing, or a negative error - * code on failure; call SDL_GetError() for more information. + * \returns SDL_TRUE if it is playing, SDL_FALSE if it isn't playing or haptic status isn't supported. * * \since This function is available since SDL 3.0.0. + * + * \sa SDL_GetHapticFeatures */ -extern SDL_DECLSPEC int SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect); /** * Set the global gain of the specified haptic device. @@ -1288,14 +1289,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetHapticEffectStatus(SDL_Haptic *haptic, in * \param haptic the SDL_Haptic device to set the gain on. * \param gain value to set the gain to, should be between 0 and 100 (0 - * 100). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetHapticFeatures */ -extern SDL_DECLSPEC int SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain); /** * Set the global autocenter of the device. @@ -1307,14 +1308,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetHapticGain(SDL_Haptic *haptic, int gain); * * \param haptic the SDL_Haptic device to set autocentering on. * \param autocenter value to set autocenter to (0-100). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetHapticFeatures */ -extern SDL_DECLSPEC int SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter); /** * Pause a haptic device. @@ -1326,14 +1327,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetHapticAutocenter(SDL_Haptic *haptic, int * can cause all sorts of weird errors. * * \param haptic the SDL_Haptic device to pause. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_ResumeHaptic */ -extern SDL_DECLSPEC int SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic); /** * Resume a haptic device. @@ -1341,20 +1342,20 @@ extern SDL_DECLSPEC int SDLCALL SDL_PauseHaptic(SDL_Haptic *haptic); * Call to unpause after SDL_PauseHaptic(). * * \param haptic the SDL_Haptic device to unpause. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_PauseHaptic */ -extern SDL_DECLSPEC int SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic); /** * Stop all the currently playing effects on a haptic device. * * \param haptic the SDL_Haptic device to stop. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1362,7 +1363,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ResumeHaptic(SDL_Haptic *haptic); * \sa SDL_RunHapticEffect * \sa SDL_StopHapticEffects */ -extern SDL_DECLSPEC int SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopHapticEffects(SDL_Haptic *haptic); /** * Check whether rumble is supported on a haptic device. @@ -1380,7 +1381,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *hapti * Initialize a haptic device for simple rumble playback. * * \param haptic the haptic device to initialize for simple rumble playback. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1389,7 +1390,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HapticRumbleSupported(SDL_Haptic *hapti * \sa SDL_StopHapticRumble * \sa SDL_HapticRumbleSupported */ -extern SDL_DECLSPEC int SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic); /** * Run a simple rumble effect on a haptic device. @@ -1397,7 +1398,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic); * \param haptic the haptic device to play the rumble effect on. * \param strength strength of the rumble to play as a 0-1 float value. * \param length length of the rumble to play in milliseconds. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1405,20 +1406,20 @@ extern SDL_DECLSPEC int SDLCALL SDL_InitHapticRumble(SDL_Haptic *haptic); * \sa SDL_InitHapticRumble * \sa SDL_StopHapticRumble */ -extern SDL_DECLSPEC int SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length); /** * Stop the simple rumble on a haptic device. * * \param haptic the haptic device to stop the rumble effect on. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_PlayHapticRumble */ -extern SDL_DECLSPEC int SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopHapticRumble(SDL_Haptic *haptic); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h index 5460863136..6bb28c7795 100644 --- a/include/SDL3/SDL_hints.h +++ b/include/SDL3/SDL_hints.h @@ -4168,7 +4168,7 @@ typedef enum SDL_HintPriority * \param name the hint to set. * \param value the value of the hint variable. * \param priority the SDL_HintPriority level for the hint. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -4179,9 +4179,7 @@ typedef enum SDL_HintPriority * \sa SDL_ResetHint * \sa SDL_SetHint */ -extern SDL_DECLSPEC int SDLCALL SDL_SetHintWithPriority(const char *name, - const char *value, - SDL_HintPriority priority); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority); /** * Set a hint with normal priority. @@ -4192,7 +4190,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetHintWithPriority(const char *name, * * \param name the hint to set. * \param value the value of the hint variable. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -4203,7 +4201,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetHintWithPriority(const char *name, * \sa SDL_ResetHint * \sa SDL_SetHintWithPriority */ -extern SDL_DECLSPEC int SDLCALL SDL_SetHint(const char *name, const char *value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetHint(const char *name, const char *value); /** * Reset a hint to the default value. @@ -4213,7 +4211,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetHint(const char *name, const char *value) * change. * * \param name the hint to set. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -4223,7 +4221,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetHint(const char *name, const char *value) * \sa SDL_SetHint * \sa SDL_ResetHints */ -extern SDL_DECLSPEC int SDLCALL SDL_ResetHint(const char *name); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ResetHint(const char *name); /** * Reset all hints to the default values. @@ -4308,7 +4306,7 @@ typedef void (SDLCALL *SDL_HintCallback)(void *userdata, const char *name, const * \param callback An SDL_HintCallback function that will be called when the * hint value changes. * \param userdata a pointer to pass to the callback function. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -4317,9 +4315,7 @@ typedef void (SDLCALL *SDL_HintCallback)(void *userdata, const char *name, const * * \sa SDL_DelHintCallback */ -extern SDL_DECLSPEC int SDLCALL SDL_AddHintCallback(const char *name, - SDL_HintCallback callback, - void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata); /** * Remove a function watching a particular hint. diff --git a/include/SDL3/SDL_init.h b/include/SDL3/SDL_init.h index 6f5d389c9b..973b5ed2fe 100644 --- a/include/SDL3/SDL_init.h +++ b/include/SDL3/SDL_init.h @@ -143,7 +143,7 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate); * SDL_SetAppMetadataProperty(). * * \param flags subsystem initialization flags. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -155,7 +155,7 @@ typedef void (SDLCALL *SDL_AppQuit_func)(void *appstate); * \sa SDL_SetMainReady * \sa SDL_WasInit */ -extern SDL_DECLSPEC int SDLCALL SDL_Init(SDL_InitFlags flags); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Init(SDL_InitFlags flags); /** * Compatibility function to initialize the SDL library. @@ -163,7 +163,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_Init(SDL_InitFlags flags); * This function and SDL_Init() are interchangeable. * * \param flags any of the flags used by SDL_Init(); see SDL_Init for details. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -172,7 +172,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_Init(SDL_InitFlags flags); * \sa SDL_Quit * \sa SDL_QuitSubSystem */ -extern SDL_DECLSPEC int SDLCALL SDL_InitSubSystem(SDL_InitFlags flags); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_InitSubSystem(SDL_InitFlags flags); /** * Shut down specific SDL subsystems. @@ -248,7 +248,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_Quit(void); * hash, or whatever makes sense). * \param appidentifier A unique string in reverse-domain format that * identifies this app ("com.example.mygame2"). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -257,7 +257,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_Quit(void); * * \sa SDL_SetAppMetadataProperty */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier); /** * Specify metadata about your app through a set of properties. @@ -310,7 +310,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAppMetadata(const char *appname, const ch * * \param name the name of the metadata property to set. * \param value the value of the property, or NULL to remove that property. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -320,7 +320,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAppMetadata(const char *appname, const ch * \sa SDL_GetAppMetadataProperty * \sa SDL_SetAppMetadata */ -extern SDL_DECLSPEC int SDLCALL SDL_SetAppMetadataProperty(const char *name, const char *value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetAppMetadataProperty(const char *name, const char *value); #define SDL_PROP_APP_METADATA_NAME_STRING "SDL.app.metadata.name" #define SDL_PROP_APP_METADATA_VERSION_STRING "SDL.app.metadata.version" diff --git a/include/SDL3/SDL_iostream.h b/include/SDL3/SDL_iostream.h index fce0e1245c..88ffa703a6 100644 --- a/include/SDL3/SDL_iostream.h +++ b/include/SDL3/SDL_iostream.h @@ -132,9 +132,10 @@ typedef struct SDL_IOStreamInterface * The SDL_IOStream is still destroyed even if this fails, so clean up anything * even if flushing to disk returns an error. * - * \return 0 if successful or -1 on write error when flushing data. + * \return SDL_TRUE if successful or SDL_FALSE on write error when flushing data. */ - int (SDLCALL *close)(void *userdata); + SDL_bool (SDLCALL *close)(void *userdata); + } SDL_IOStreamInterface; @@ -371,21 +372,21 @@ extern SDL_DECLSPEC SDL_IOStream * SDLCALL SDL_OpenIO(const SDL_IOStreamInterfac * * SDL_CloseIO() closes and cleans up the SDL_IOStream stream. It releases any * resources used by the stream and frees the SDL_IOStream itself. This - * returns 0 on success, or -1 if the stream failed to flush to its output + * returns SDL_TRUE on success, or SDL_FALSE if the stream failed to flush to its output * (e.g. to disk). * * Note that if this fails to flush the stream to disk, this function reports * an error, but the SDL_IOStream is still invalid once this function returns. * * \param context SDL_IOStream structure to close. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_OpenIO */ -extern SDL_DECLSPEC int SDLCALL SDL_CloseIO(SDL_IOStream *context); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CloseIO(SDL_IOStream *context); /** * Get the properties associated with an SDL_IOStream. diff --git a/include/SDL3/SDL_joystick.h b/include/SDL3/SDL_joystick.h index 9ae4b6ae7b..62de3f22c6 100644 --- a/include/SDL3/SDL_joystick.h +++ b/include/SDL3/SDL_joystick.h @@ -446,11 +446,11 @@ typedef struct SDL_VirtualJoystickDesc void *userdata; /**< User data pointer passed to callbacks */ void (SDLCALL *Update)(void *userdata); /**< Called when the joystick state should be updated */ void (SDLCALL *SetPlayerIndex)(void *userdata, int player_index); /**< Called when the player index is set */ - int (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */ - int (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */ - int (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */ - int (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */ - int (SDLCALL *SetSensorsEnabled)(void *userdata, SDL_bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */ + SDL_bool (SDLCALL *Rumble)(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); /**< Implements SDL_RumbleJoystick() */ + SDL_bool (SDLCALL *RumbleTriggers)(void *userdata, Uint16 left_rumble, Uint16 right_rumble); /**< Implements SDL_RumbleJoystickTriggers() */ + SDL_bool (SDLCALL *SetLED)(void *userdata, Uint8 red, Uint8 green, Uint8 blue); /**< Implements SDL_SetJoystickLED() */ + SDL_bool (SDLCALL *SendEffect)(void *userdata, const void *data, int size); /**< Implements SDL_SendJoystickEffect() */ + SDL_bool (SDLCALL *SetSensorsEnabled)(void *userdata, SDL_bool enabled); /**< Implements SDL_SetGamepadSensorEnabled() */ } SDL_VirtualJoystickDesc; /** @@ -471,14 +471,14 @@ extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_AttachVirtualJoystick(const SDL_V * * \param instance_id the joystick instance ID, previously returned from * SDL_AttachVirtualJoystick(). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_AttachVirtualJoystick */ -extern SDL_DECLSPEC int SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_DetachVirtualJoystick(SDL_JoystickID instance_id); /** * Query whether or not a joystick is virtual. @@ -506,12 +506,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsJoystickVirtual(SDL_JoystickID instan * \param joystick the virtual joystick on which to set state. * \param axis the index of the axis on the virtual joystick to update. * \param value the new value for the specified axis. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value); /** * Generate ball motion on an opened virtual joystick. @@ -526,12 +526,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualAxis(SDL_Joystick *joystic * \param ball the index of the ball on the virtual joystick to update. * \param xrel the relative motion on the X axis. * \param yrel the relative motion on the Y axis. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel); /** * Set the state of a button on an opened virtual joystick. @@ -545,12 +545,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualBall(SDL_Joystick *joystic * \param joystick the virtual joystick on which to set state. * \param button the index of the button on the virtual joystick to update. * \param value the new value for the specified button. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value); /** * Set the state of a hat on an opened virtual joystick. @@ -564,12 +564,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualButton(SDL_Joystick *joyst * \param joystick the virtual joystick on which to set state. * \param hat the index of the hat on the virtual joystick to update. * \param value the new value for the specified hat. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value); /** * Set touchpad finger state on an opened virtual joystick. @@ -591,12 +591,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualHat(SDL_Joystick *joystick * \param y the y coordinate of the finger on the touchpad, normalized 0 to 1, * with the origin in the upper left. * \param pressure the pressure of the finger. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure); /** * Send a sensor update for an opened virtual joystick. @@ -613,12 +613,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joy * the sensor reading. * \param data the data associated with the sensor reading. * \param num_values the number of values pointed to by `data`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); /** * Get the properties associated with a joystick. @@ -697,14 +697,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickPlayerIndex(SDL_Joystick *joystic * \param joystick the SDL_Joystick obtained from SDL_OpenJoystick(). * \param player_index player index to assign to this joystick, or -1 to clear * the player index and turn off player LEDs. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetJoystickPlayerIndex */ -extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index); /** * Get the implementation-dependent GUID for the joystick. @@ -852,8 +852,8 @@ extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetJoystickID(SDL_Joystick *joyst * device and platform. * * \param joystick an SDL_Joystick structure containing joystick information. - * \returns the number of axis controls/number of axes on success or a - * negative error code on failure; call SDL_GetError() for more + * \returns the number of axis controls/number of axes on success or -1 + * on failure; call SDL_GetError() for more * information. * * \since This function is available since SDL 3.0.0. @@ -874,7 +874,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickAxes(SDL_Joystick *joystick); * Most joysticks do not have trackballs. * * \param joystick an SDL_Joystick structure containing joystick information. - * \returns the number of trackballs on success or a negative error code on + * \returns the number of trackballs on success or -1 on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -890,7 +890,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickBalls(SDL_Joystick *joystick); * Get the number of POV hats on a joystick. * * \param joystick an SDL_Joystick structure containing joystick information. - * \returns the number of POV hats on success or a negative error code on + * \returns the number of POV hats on success or -1 on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -906,7 +906,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumJoystickHats(SDL_Joystick *joystick); * Get the number of buttons on a joystick. * * \param joystick an SDL_Joystick structure containing joystick information. - * \returns the number of buttons on success or a negative error code on + * \returns the number of buttons on success or -1 on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1012,14 +1012,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickAxisInitialState(SDL_Joystic * \param ball the ball index to query; ball indices start at index 0. * \param dx stores the difference in the x axis position since the last poll. * \param dy stores the difference in the y axis position since the last poll. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetNumJoystickBalls */ -extern SDL_DECLSPEC int SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy); /** * Get the current state of a POV hat on a joystick. @@ -1075,11 +1075,11 @@ extern SDL_DECLSPEC Uint8 SDLCALL SDL_GetJoystickButton(SDL_Joystick *joystick, * \param high_frequency_rumble the intensity of the high frequency (right) * rumble motor, from 0 to 0xFFFF. * \param duration_ms the duration of the rumble effect, in milliseconds. - * \returns 0, or -1 if rumble isn't supported on this joystick. + * \returns SDL_TRUE, or SDL_FALSE if rumble isn't supported on this joystick. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms); /** * Start a rumble effect in the joystick's triggers. @@ -1101,14 +1101,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystick(SDL_Joystick *joystick, Uint1 * \param right_rumble the intensity of the right trigger rumble motor, from 0 * to 0xFFFF. * \param duration_ms the duration of the rumble effect, in milliseconds. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RumbleJoystick */ -extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms); /** * Update a joystick's LED color. @@ -1123,12 +1123,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_RumbleJoystickTriggers(SDL_Joystick *joystic * \param red the intensity of the red LED. * \param green the intensity of the green LED. * \param blue the intensity of the blue LED. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); /** * Send a joystick specific effect packet. @@ -1136,12 +1136,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 * \param joystick the joystick to affect. * \param data the data to send to the joystick. * \param size the size of the data to send to the joystick. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size); /** * Close a joystick previously opened with SDL_OpenJoystick(). diff --git a/include/SDL3/SDL_keyboard.h b/include/SDL3/SDL_keyboard.h index 0fe05b938f..daa925971f 100644 --- a/include/SDL3/SDL_keyboard.h +++ b/include/SDL3/SDL_keyboard.h @@ -231,14 +231,14 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromKey(SDL_Keycode key, * \param name the name to use for the scancode, encoded as UTF-8. The string * is not copied, so the pointer given to this function must stay * valid while SDL is being used. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetScancodeName */ -extern SDL_DECLSPEC int SDLCALL SDL_SetScancodeName(SDL_Scancode scancode, const char *name); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetScancodeName(SDL_Scancode scancode, const char *name); /** * Get a human-readable name for a scancode. @@ -322,7 +322,7 @@ extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name); * On some platforms using this function shows the screen keyboard. * * \param window the window to enable text input. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -332,7 +332,7 @@ extern SDL_DECLSPEC SDL_Keycode SDLCALL SDL_GetKeyFromName(const char *name); * \sa SDL_StopTextInput * \sa SDL_TextInputActive */ -extern SDL_DECLSPEC int SDLCALL SDL_StartTextInput(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StartTextInput(SDL_Window *window); /** * Text input type. @@ -414,7 +414,7 @@ typedef enum SDL_Capitalization * * \param window the window to enable text input. * \param props the properties to use. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -424,7 +424,7 @@ typedef enum SDL_Capitalization * \sa SDL_StopTextInput * \sa SDL_TextInputActive */ -extern SDL_DECLSPEC int SDLCALL SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props); #define SDL_PROP_TEXTINPUT_TYPE_NUMBER "SDL.textinput.type" #define SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER "SDL.textinput.capitalization" @@ -451,20 +451,20 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TextInputActive(SDL_Window *window); * it. * * \param window the window to disable text input. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_StartTextInput */ -extern SDL_DECLSPEC int SDLCALL SDL_StopTextInput(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StopTextInput(SDL_Window *window); /** * Dismiss the composition window/IME without disabling the subsystem. * * \param window the window to affect. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -472,7 +472,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_StopTextInput(SDL_Window *window); * \sa SDL_StartTextInput * \sa SDL_StopTextInput */ -extern SDL_DECLSPEC int SDLCALL SDL_ClearComposition(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearComposition(SDL_Window *window); /** * Set the area used to type Unicode text input. @@ -485,7 +485,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ClearComposition(SDL_Window *window); * coordinates, or NULL to clear it. * \param cursor the offset of the current cursor location relative to * `rect->x`, in window coordinates. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -493,7 +493,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ClearComposition(SDL_Window *window); * \sa SDL_GetTextInputArea * \sa SDL_StartTextInput */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTextInputArea(SDL_Window *window, const SDL_Rect *rect, int cursor); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextInputArea(SDL_Window *window, const SDL_Rect *rect, int cursor); /** * Get the area used to type Unicode text input. @@ -505,14 +505,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextInputArea(SDL_Window *window, const S * may be NULL. * \param cursor a pointer to the offset of the current cursor location * relative to `rect->x`, may be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetTextInputArea */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextInputArea(SDL_Window *window, SDL_Rect *rect, int *cursor); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextInputArea(SDL_Window *window, SDL_Rect *rect, int *cursor); /** * Check whether the platform has screen keyboard support. diff --git a/include/SDL3/SDL_log.h b/include/SDL3/SDL_log.h index 078ab9dbea..1ee8b3a002 100644 --- a/include/SDL3/SDL_log.h +++ b/include/SDL3/SDL_log.h @@ -191,7 +191,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void); * \param priority the SDL_LogPriority to modify. * \param prefix the prefix to use for that log priority, or NULL to use no * prefix. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -199,7 +199,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetLogPriorities(void); * \sa SDL_SetLogPriorities * \sa SDL_SetLogPriority */ -extern SDL_DECLSPEC int SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix); /** * Log a message with SDL_LOG_CATEGORY_APPLICATION and SDL_LOG_PRIORITY_INFO. diff --git a/include/SDL3/SDL_main.h b/include/SDL3/SDL_main.h index 8b89e88071..7c21885516 100644 --- a/include/SDL3/SDL_main.h +++ b/include/SDL3/SDL_main.h @@ -478,7 +478,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetMainReady(void); * literally have to be `main`. * \param reserved should be NULL (reserved for future use, will probably be * platform-specific then). - * \returns the return value from mainFunction: 0 on success, -1 on failure; + * \returns the return value from mainFunction: 0 on success, otherwise failure; * SDL_GetError() might have more information on the failure. * * \threadsafety Generally this is called once, near startup, from the @@ -537,12 +537,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_EnterAppMainCallbacks(int argc, char *argv[] * what is specified here. * \param hInst the HINSTANCE to use in WNDCLASSEX::hInstance. If zero, SDL * will use `GetModuleHandle(NULL)` instead. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst); /** * Deregister the win32 window class from an SDL_RegisterApp call. diff --git a/include/SDL3/SDL_messagebox.h b/include/SDL3/SDL_messagebox.h index 6aa3853716..4aba3d470d 100644 --- a/include/SDL3/SDL_messagebox.h +++ b/include/SDL3/SDL_messagebox.h @@ -154,14 +154,14 @@ typedef struct SDL_MessageBoxData * other options. * \param buttonid the pointer to which user id of hit button should be * copied. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_ShowSimpleMessageBox */ -extern SDL_DECLSPEC int SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid); /** * Display a simple modal message box. @@ -196,14 +196,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_ShowMessageBox(const SDL_MessageBoxData *mes * \param title uTF-8 title text. * \param message uTF-8 message text. * \param window the parent window, or NULL for no parent. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_ShowMessageBox */ -extern SDL_DECLSPEC int SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window); /* Ends C function definitions when using C++ */ diff --git a/include/SDL3/SDL_misc.h b/include/SDL3/SDL_misc.h index 09dec9e066..a7e202cbfa 100644 --- a/include/SDL3/SDL_misc.h +++ b/include/SDL3/SDL_misc.h @@ -62,12 +62,12 @@ extern "C" { * * \param url a valid URL/URI to open. Use `file:///full/path/to/file` for * local files, if supported. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_OpenURL(const char *url); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_OpenURL(const char *url); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL3/SDL_mouse.h b/include/SDL3/SDL_mouse.h index f2d17d3be2..368df14fea 100644 --- a/include/SDL3/SDL_mouse.h +++ b/include/SDL3/SDL_mouse.h @@ -295,14 +295,14 @@ extern SDL_DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window, * * \param x the x coordinate. * \param y the y coordinate. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_WarpMouseInWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_WarpMouseGlobal(float x, float y); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WarpMouseGlobal(float x, float y); /** * Set relative mouse mode for a window. @@ -316,14 +316,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_WarpMouseGlobal(float x, float y); * * \param window the window to change. * \param enabled SDL_TRUE to enable relative mode, SDL_FALSE to disable. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowRelativeMouseMode */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowRelativeMouseMode(SDL_Window *window, SDL_bool enabled); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowRelativeMouseMode(SDL_Window *window, SDL_bool enabled); /** * Query whether relative mouse mode is enabled for a window. @@ -375,14 +375,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowRelativeMouseMode(SDL_Window * * `SDL_HINT_MOUSE_AUTO_CAPTURE` hint to zero. * * \param enabled SDL_TRUE to enable capturing, SDL_FALSE to disable. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetGlobalMouseState */ -extern SDL_DECLSPEC int SDLCALL SDL_CaptureMouse(SDL_bool enabled); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CaptureMouse(SDL_bool enabled); /** * Create a cursor using the specified bitmap data and mask (in MSB format). @@ -483,14 +483,14 @@ extern SDL_DECLSPEC SDL_Cursor * SDLCALL SDL_CreateSystemCursor(SDL_SystemCursor * this is desired for any reason. * * \param cursor a cursor to make active. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetCursor */ -extern SDL_DECLSPEC int SDLCALL SDL_SetCursor(SDL_Cursor *cursor); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetCursor(SDL_Cursor *cursor); /** * Get the active cursor. @@ -538,7 +538,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyCursor(SDL_Cursor *cursor); /** * Show the cursor. * - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -546,12 +546,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyCursor(SDL_Cursor *cursor); * \sa SDL_CursorVisible * \sa SDL_HideCursor */ -extern SDL_DECLSPEC int SDLCALL SDL_ShowCursor(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowCursor(void); /** * Hide the cursor. * - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -559,7 +559,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ShowCursor(void); * \sa SDL_CursorVisible * \sa SDL_ShowCursor */ -extern SDL_DECLSPEC int SDLCALL SDL_HideCursor(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HideCursor(void); /** * Return whether the cursor is currently being shown. diff --git a/include/SDL3/SDL_mutex.h b/include/SDL3/SDL_mutex.h index eea0030925..2bbbc6bf89 100644 --- a/include/SDL3/SDL_mutex.h +++ b/include/SDL3/SDL_mutex.h @@ -115,16 +115,6 @@ extern "C" { #endif -/** - * Synchronization functions return this value if they time out. - * - * Not all functions _can_ time out; some will block indefinitely. - * - * \since This macro is available since SDL 3.0.0. - */ -#define SDL_MUTEX_TIMEDOUT 1 - - /** * \name Mutex functions */ @@ -194,25 +184,22 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockMutex(SDL_Mutex *mutex) SDL_ACQUIRE(mut * Try to lock a mutex without blocking. * * This works just like SDL_LockMutex(), but if the mutex is not available, - * this function returns `SDL_MUTEX_TIMEDOUT` immediately. + * this function returns SDL_FALSE immediately. * * This technique is useful if you need exclusive access to a resource but * don't want to wait for it, and will return to it to try again later. * - * This function does not fail; if mutex is NULL, it will return 0 immediately - * having locked nothing. If the mutex is valid, this function will always - * either lock the mutex and return 0, or return SDL_MUTEX_TIMEOUT and lock - * nothing. - * + * This function returns SDL_TRUE if passed a NULL mutex. + * * \param mutex the mutex to try to lock. - * \returns 0 or `SDL_MUTEX_TIMEDOUT`. + * \returns SDL_TRUE on success, SDL_FALSE if the mutex would block. * * \since This function is available since SDL 3.0.0. * * \sa SDL_LockMutex * \sa SDL_UnlockMutex */ -extern SDL_DECLSPEC int SDLCALL SDL_TryLockMutex(SDL_Mutex *mutex) SDL_TRY_ACQUIRE(0, mutex); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockMutex(SDL_Mutex *mutex) SDL_TRY_ACQUIRE(0, mutex); /** * Unlock the mutex. @@ -278,19 +265,6 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_Mutex *mutex); */ typedef struct SDL_RWLock SDL_RWLock; -/* - * Synchronization functions return this value if they time out. - * - * Not all functions _can_ time out; some will block indefinitely. - * - * This symbol is just for clarity when dealing with SDL_RWLock - * functions; its value is equivalent to SDL_MUTEX_TIMEOUT. - * - * \since This macro is available since SDL 3.0.0. - */ -#define SDL_RWLOCK_TIMEDOUT SDL_MUTEX_TIMEDOUT - - /** * Create a new read/write lock. * @@ -405,7 +379,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SD * Try to lock a read/write lock _for reading_ without blocking. * * This works just like SDL_LockRWLockForReading(), but if the rwlock is not - * available, then this function returns `SDL_RWLOCK_TIMEDOUT` immediately. + * available, then this function returns SDL_FALSE immediately. * * This technique is useful if you need access to a resource but don't want to * wait for it, and will return to it to try again later. @@ -413,13 +387,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SD * Trying to lock for read-only access can succeed if other threads are * holding read-only locks, as this won't prevent access. * - * This function does not fail; if rwlock is NULL, it will return 0 - * immediately having locked nothing. If rwlock is valid, this function will - * always either lock the rwlock and return 0, or return SDL_RWLOCK_TIMEOUT - * and lock nothing. - * + * This function returns SDL_TRUE if passed a NULL rwlock. + * * \param rwlock the rwlock to try to lock. - * \returns 0 or `SDL_RWLOCK_TIMEDOUT`. + * \returns SDL_TRUE on success, SDL_FALSE if the lock would block. * * \since This function is available since SDL 3.0.0. * @@ -427,13 +398,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SD * \sa SDL_TryLockRWLockForWriting * \sa SDL_UnlockRWLock */ -extern SDL_DECLSPEC int SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE_SHARED(0, rwlock); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE_SHARED(0, rwlock); /** * Try to lock a read/write lock _for writing_ without blocking. * * This works just like SDL_LockRWLockForWriting(), but if the rwlock is not - * available, this function returns `SDL_RWLOCK_TIMEDOUT` immediately. + * available, then this function returns SDL_FALSE immediately. * * This technique is useful if you need exclusive access to a resource but * don't want to wait for it, and will return to it to try again later. @@ -446,13 +417,10 @@ extern SDL_DECLSPEC int SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) * read-only lock. Doing so results in undefined behavior. Unlock the * read-only lock before requesting a write lock. * - * This function does not fail; if rwlock is NULL, it will return 0 - * immediately having locked nothing. If rwlock is valid, this function will - * always either lock the rwlock and return 0, or return SDL_RWLOCK_TIMEOUT - * and lock nothing. - * + * This function returns SDL_TRUE if passed a NULL rwlock. + * * \param rwlock the rwlock to try to lock. - * \returns 0 or `SDL_RWLOCK_TIMEDOUT`. + * \returns SDL_TRUE on success, SDL_FALSE if the lock would block. * * \since This function is available since SDL 3.0.0. * @@ -460,7 +428,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) * \sa SDL_TryLockRWLockForReading * \sa SDL_UnlockRWLock */ -extern SDL_DECLSPEC int SDLCALL SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE(0, rwlock); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) SDL_TRY_ACQUIRE(0, rwlock); /** * Unlock the read/write lock. @@ -569,17 +537,13 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_Semaphore *sem); /** * Wait until a semaphore has a positive value and then decrements it. * - * This function suspends the calling thread until either the semaphore - * pointed to by `sem` has a positive value or the call is interrupted by a - * signal or error. If the call is successful it will atomically decrement the - * semaphore value. + * This function suspends the calling thread until the semaphore + * pointed to by `sem` has a positive value, and then atomically decrement the semaphore value. * * This function is the equivalent of calling SDL_WaitSemaphoreTimeout() with * a time length of -1. * * \param sem the semaphore wait on. - * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -587,7 +551,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroySemaphore(SDL_Semaphore *sem); * \sa SDL_TryWaitSemaphore * \sa SDL_WaitSemaphoreTimeout */ -extern SDL_DECLSPEC int SDLCALL SDL_WaitSemaphore(SDL_Semaphore *sem); +extern SDL_DECLSPEC void SDLCALL SDL_WaitSemaphore(SDL_Semaphore *sem); /** * See if a semaphore has a positive value and decrement it if it does. @@ -595,12 +559,11 @@ extern SDL_DECLSPEC int SDLCALL SDL_WaitSemaphore(SDL_Semaphore *sem); * This function checks to see if the semaphore pointed to by `sem` has a * positive value and atomically decrements the semaphore value if it does. If * the semaphore doesn't have a positive value, the function immediately - * returns SDL_MUTEX_TIMEDOUT. + * returns SDL_FALSE. * * \param sem the semaphore to wait on. - * \returns 0 if the wait succeeds, `SDL_MUTEX_TIMEDOUT` if the wait would - * block, or a negative error code on failure; call SDL_GetError() - * for more information. + * \returns SDL_TRUE if the wait succeeds, SDL_FALSE if the wait would + * block. * * \since This function is available since SDL 3.0.0. * @@ -608,21 +571,18 @@ extern SDL_DECLSPEC int SDLCALL SDL_WaitSemaphore(SDL_Semaphore *sem); * \sa SDL_WaitSemaphore * \sa SDL_WaitSemaphoreTimeout */ -extern SDL_DECLSPEC int SDLCALL SDL_TryWaitSemaphore(SDL_Semaphore *sem); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TryWaitSemaphore(SDL_Semaphore *sem); /** * Wait until a semaphore has a positive value and then decrements it. * * This function suspends the calling thread until either the semaphore - * pointed to by `sem` has a positive value, the call is interrupted by a - * signal or error, or the specified time has elapsed. If the call is + * pointed to by `sem` has a positive value or the specified time has elapsed. If the call is * successful it will atomically decrement the semaphore value. * * \param sem the semaphore to wait on. - * \param timeoutMS the length of the timeout, in milliseconds. - * \returns 0 if the wait succeeds, `SDL_MUTEX_TIMEDOUT` if the wait does not - * succeed in the allotted time, or a negative error code on failure; - * call SDL_GetError() for more information. + * \param timeoutMS the length of the timeout, in milliseconds, or -1 to wait indefinitely. + * \returns SDL_TRUE if the wait succeeds or SDL_FALSE if the wait times out. * * \since This function is available since SDL 3.0.0. * @@ -630,14 +590,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_TryWaitSemaphore(SDL_Semaphore *sem); * \sa SDL_TryWaitSemaphore * \sa SDL_WaitSemaphore */ -extern SDL_DECLSPEC int SDLCALL SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sint32 timeoutMS); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sint32 timeoutMS); /** * Atomically increment a semaphore's value and wake waiting threads. * * \param sem the semaphore to increment. - * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -645,7 +603,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sin * \sa SDL_WaitSemaphore * \sa SDL_WaitSemaphoreTimeout */ -extern SDL_DECLSPEC int SDLCALL SDL_SignalSemaphore(SDL_Semaphore *sem); +extern SDL_DECLSPEC void SDLCALL SDL_SignalSemaphore(SDL_Semaphore *sem); /** * Get the current value of a semaphore. @@ -711,8 +669,6 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyCondition(SDL_Condition *cond); * Restart one of the threads that are waiting on the condition variable. * * \param cond the condition variable to signal. - * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * @@ -722,14 +678,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyCondition(SDL_Condition *cond); * \sa SDL_WaitCondition * \sa SDL_WaitConditionTimeout */ -extern SDL_DECLSPEC int SDLCALL SDL_SignalCondition(SDL_Condition *cond); +extern SDL_DECLSPEC void SDLCALL SDL_SignalCondition(SDL_Condition *cond); /** * Restart all threads that are waiting on the condition variable. * * \param cond the condition variable to signal. - * \returns 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * @@ -739,7 +693,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SignalCondition(SDL_Condition *cond); * \sa SDL_WaitCondition * \sa SDL_WaitConditionTimeout */ -extern SDL_DECLSPEC int SDLCALL SDL_BroadcastCondition(SDL_Condition *cond); +extern SDL_DECLSPEC void SDLCALL SDL_BroadcastCondition(SDL_Condition *cond); /** * Wait until a condition variable is signaled. @@ -758,8 +712,6 @@ extern SDL_DECLSPEC int SDLCALL SDL_BroadcastCondition(SDL_Condition *cond); * * \param cond the condition variable to wait on. * \param mutex the mutex used to coordinate thread access. - * \returns 0 when it is signaled or a negative error code on failure; call - * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * @@ -769,7 +721,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BroadcastCondition(SDL_Condition *cond); * \sa SDL_SignalCondition * \sa SDL_WaitConditionTimeout */ -extern SDL_DECLSPEC int SDLCALL SDL_WaitCondition(SDL_Condition *cond, SDL_Mutex *mutex); +extern SDL_DECLSPEC void SDLCALL SDL_WaitCondition(SDL_Condition *cond, SDL_Mutex *mutex); /** * Wait until a condition variable is signaled or a certain time has passed. @@ -788,9 +740,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_WaitCondition(SDL_Condition *cond, SDL_Mutex * \param mutex the mutex used to coordinate thread access. * \param timeoutMS the maximum time to wait, in milliseconds, or -1 to wait * indefinitely. - * \returns 0 if the condition variable is signaled, `SDL_MUTEX_TIMEDOUT` if - * the condition is not signaled in the allotted time, or a negative - * error code on failure; call SDL_GetError() for more information. + * \returns SDL_TRUE if the condition variable is signaled, SDL_FALSE if + * the condition is not signaled in the allotted time. * * \threadsafety It is safe to call this function from any thread. * @@ -800,7 +751,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_WaitCondition(SDL_Condition *cond, SDL_Mutex * \sa SDL_SignalCondition * \sa SDL_WaitCondition */ -extern SDL_DECLSPEC int SDLCALL SDL_WaitConditionTimeout(SDL_Condition *cond, +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WaitConditionTimeout(SDL_Condition *cond, SDL_Mutex *mutex, Sint32 timeoutMS); /* @} *//* Condition variable functions */ diff --git a/include/SDL3/SDL_pixels.h b/include/SDL3/SDL_pixels.h index 42a6c29af0..baf683c03d 100644 --- a/include/SDL3/SDL_pixels.h +++ b/include/SDL3/SDL_pixels.h @@ -742,7 +742,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat * \param Gmask a pointer filled in with the green mask for the format. * \param Bmask a pointer filled in with the blue mask for the format. * \param Amask a pointer filled in with the alpha mask for the format. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -751,7 +751,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetPixelFormatName(SDL_PixelFormat * * \sa SDL_GetPixelFormatForMasks */ -extern SDL_DECLSPEC int SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask); /** * Convert a bpp value and RGBA masks to an enumerated pixel format. @@ -819,7 +819,7 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreatePalette(int ncolors); * \param colors an array of SDL_Color structures to copy into the palette. * \param firstcolor the index of the first palette entry to modify. * \param ncolors the number of entries to modify. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, as long as @@ -827,7 +827,7 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreatePalette(int ncolors); * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors); /** * Free a palette created with SDL_CreatePalette(). diff --git a/include/SDL3/SDL_properties.h b/include/SDL3/SDL_properties.h index b3e061adc1..231b2f3c4f 100644 --- a/include/SDL3/SDL_properties.h +++ b/include/SDL3/SDL_properties.h @@ -116,14 +116,14 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_CreateProperties(void); * * \param src the properties to copy. * \param dst the destination properties. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst); /** * Lock a group of properties. @@ -138,7 +138,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_Pro * thread. * * \param props the properties to lock. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -147,7 +147,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_CopyProperties(SDL_PropertiesID src, SDL_Pro * * \sa SDL_UnlockProperties */ -extern SDL_DECLSPEC int SDLCALL SDL_LockProperties(SDL_PropertiesID props); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockProperties(SDL_PropertiesID props); /** * Unlock a group of properties. @@ -204,7 +204,7 @@ typedef void (SDLCALL *SDL_CleanupPropertyCallback)(void *userdata, void *value) * \param cleanup the function to call when this property is deleted, or NULL * if no cleanup is necessary. * \param userdata a pointer that is passed to the cleanup function. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -215,7 +215,7 @@ typedef void (SDLCALL *SDL_CleanupPropertyCallback)(void *userdata, void *value) * \sa SDL_SetPointerProperty * \sa SDL_CleanupPropertyCallback */ -extern SDL_DECLSPEC int SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata); /** * Set a pointer property in a group of properties. @@ -223,7 +223,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_Properties * \param props the properties to modify. * \param name the name of the property to modify. * \param value the new value of the property, or NULL to delete the property. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -238,7 +238,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPointerPropertyWithCleanup(SDL_Properties * \sa SDL_SetPointerPropertyWithCleanup * \sa SDL_SetStringProperty */ -extern SDL_DECLSPEC int SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value); /** * Set a string property in a group of properties. @@ -249,7 +249,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, c * \param props the properties to modify. * \param name the name of the property to modify. * \param value the new value of the property, or NULL to delete the property. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -258,7 +258,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPointerProperty(SDL_PropertiesID props, c * * \sa SDL_GetStringProperty */ -extern SDL_DECLSPEC int SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value); /** * Set an integer property in a group of properties. @@ -266,7 +266,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, co * \param props the properties to modify. * \param name the name of the property to modify. * \param value the new value of the property. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -275,7 +275,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetStringProperty(SDL_PropertiesID props, co * * \sa SDL_GetNumberProperty */ -extern SDL_DECLSPEC int SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value); /** * Set a floating point property in a group of properties. @@ -283,7 +283,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, co * \param props the properties to modify. * \param name the name of the property to modify. * \param value the new value of the property. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -292,7 +292,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetNumberProperty(SDL_PropertiesID props, co * * \sa SDL_GetFloatProperty */ -extern SDL_DECLSPEC int SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value); /** * Set a boolean property in a group of properties. @@ -300,7 +300,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, con * \param props the properties to modify. * \param name the name of the property to modify. * \param value the new value of the property. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -309,7 +309,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetFloatProperty(SDL_PropertiesID props, con * * \sa SDL_GetBooleanProperty */ -extern SDL_DECLSPEC int SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value); /** * Return whether a property exists in a group of properties. @@ -470,14 +470,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetBooleanProperty(SDL_PropertiesID pro * * \param props the properties to modify. * \param name the name of the property to clear. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearProperty(SDL_PropertiesID props, const char *name); /** * A callback used to enumerate all the properties in a group of properties. @@ -507,14 +507,14 @@ typedef void (SDLCALL *SDL_EnumeratePropertiesCallback)(void *userdata, SDL_Prop * \param props the properties to query. * \param callback the function to call for each property. * \param userdata a pointer that is passed to `callback`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata); /** * Destroy a group of properties. diff --git a/include/SDL3/SDL_rect.h b/include/SDL3/SDL_rect.h index 0583300989..7d7a8a39ae 100644 --- a/include/SDL3/SDL_rect.h +++ b/include/SDL3/SDL_rect.h @@ -221,8 +221,7 @@ SDL_FORCE_INLINE SDL_bool SDL_RectsEqual(const SDL_Rect *a, const SDL_Rect *b) * * \sa SDL_GetRectIntersection */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersection(const SDL_Rect * A, - const SDL_Rect * B); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersection(const SDL_Rect *A, const SDL_Rect *B); /** * Calculate the intersection of two rectangles. @@ -239,9 +238,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersection(const SDL_Rect * A, * * \sa SDL_HasRectIntersection */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersection(const SDL_Rect * A, - const SDL_Rect * B, - SDL_Rect * result); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersection(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result); /** * Calculate the union of two rectangles. @@ -250,14 +247,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersection(const SDL_Rect * A, * \param B an SDL_Rect structure representing the second rectangle. * \param result an SDL_Rect structure filled in with the union of rectangles * `A` and `B`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRectUnion(const SDL_Rect * A, - const SDL_Rect * B, - SDL_Rect * result); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectUnion(const SDL_Rect *A, const SDL_Rect *B, SDL_Rect *result); /** * Calculate a minimal rectangle enclosing a set of points. @@ -276,10 +271,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRectUnion(const SDL_Rect * A, * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point * points, - int count, - const SDL_Rect * clip, - SDL_Rect * result); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point *points, int count, const SDL_Rect *clip, SDL_Rect *result); /** * Calculate the intersection of a rectangle and line segment. @@ -299,10 +291,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPoints(const SDL_Point * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectAndLineIntersection(const SDL_Rect * - rect, int *X1, - int *Y1, int *X2, - int *Y2); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectAndLineIntersection(const SDL_Rect *rect, int *X1, int *Y1, int *X2, int *Y2); /* SDL_FRect versions... */ @@ -435,8 +424,7 @@ SDL_FORCE_INLINE SDL_bool SDL_RectsEqualFloat(const SDL_FRect *a, const SDL_FRec * * \sa SDL_GetRectIntersection */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersectionFloat(const SDL_FRect * A, - const SDL_FRect * B); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersectionFloat(const SDL_FRect *A, const SDL_FRect *B); /** * Calculate the intersection of two rectangles with float precision. @@ -453,9 +441,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasRectIntersectionFloat(const SDL_FRec * * \sa SDL_HasRectIntersectionFloat */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersectionFloat(const SDL_FRect * A, - const SDL_FRect * B, - SDL_FRect * result); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersectionFloat(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result); /** * Calculate the union of two rectangles with float precision. @@ -464,14 +450,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectIntersectionFloat(const SDL_FRec * \param B an SDL_FRect structure representing the second rectangle. * \param result an SDL_FRect structure filled in with the union of rectangles * `A` and `B`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRectUnionFloat(const SDL_FRect * A, - const SDL_FRect * B, - SDL_FRect * result); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectUnionFloat(const SDL_FRect *A, const SDL_FRect *B, SDL_FRect *result); /** * Calculate a minimal rectangle enclosing a set of points with float @@ -491,10 +475,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRectUnionFloat(const SDL_FRect * A, * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_FPoint * points, - int count, - const SDL_FRect * clip, - SDL_FRect * result); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_FPoint *points, int count, const SDL_FRect *clip, SDL_FRect *result); /** * Calculate the intersection of a rectangle and line segment with float @@ -515,10 +496,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectEnclosingPointsFloat(const SDL_F * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectAndLineIntersectionFloat(const SDL_FRect * - rect, float *X1, - float *Y1, float *X2, - float *Y2); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRectAndLineIntersectionFloat(const SDL_FRect *rect, float *X1, float *Y1, float *X2, float *Y2); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL3/SDL_render.h b/include/SDL3/SDL_render.h index 20e45d519a..eb5de99643 100644 --- a/include/SDL3/SDL_render.h +++ b/include/SDL3/SDL_render.h @@ -133,8 +133,7 @@ typedef struct SDL_Texture SDL_Texture; * * There may be none if SDL was compiled without render support. * - * \returns a number >= 0 on success or a negative error code on failure; call - * SDL_GetError() for more information. + * \returns the number of built in render drivers. * * \since This function is available since SDL 3.0.0. * @@ -175,7 +174,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetRenderDriver(int index); * SDL_CreateWindow()). * \param window a pointer filled with the window, or NULL on error. * \param renderer a pointer filled with the renderer, or NULL on error. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -183,7 +182,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetRenderDriver(int index); * \sa SDL_CreateRenderer * \sa SDL_CreateWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer); /** * Create a 2D rendering context for a window. @@ -445,14 +444,14 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetRendererProperties(SDL_Rende * \param renderer the rendering context. * \param w a pointer filled in with the width in pixels. * \param h a pointer filled in with the height in pixels. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetCurrentRenderOutputSize */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h); /** * Get the current output size in pixels of a rendering context. @@ -465,14 +464,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderOutputSize(SDL_Renderer *renderer, * \param renderer the rendering context. * \param w a pointer filled in with the current width. * \param h a pointer filled in with the current height. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetRenderOutputSize */ -extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h); /** * Create a texture for a rendering context. @@ -802,12 +801,12 @@ extern SDL_DECLSPEC SDL_Renderer * SDLCALL SDL_GetRendererFromTexture(SDL_Textur * argument can be NULL if you don't need this information. * \param h a pointer filled in with the height of the texture in pixels. This * argument can be NULL if you don't need this information. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h); /** * Set an additional color value multiplied into render copy operations. @@ -818,14 +817,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float * * * `srcC = srcC * (color / 255)` * - * Color modulation is not always supported by the renderer; it will return -1 + * Color modulation is not always supported by the renderer; it will return SDL_FALSE * if color modulation is not supported. * * \param texture the texture to update. * \param r the red color value multiplied into copy operations. * \param g the green color value multiplied into copy operations. * \param b the blue color value multiplied into copy operations. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -834,7 +833,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureSize(SDL_Texture *texture, float * * \sa SDL_SetTextureAlphaMod * \sa SDL_SetTextureColorModFloat */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b); /** @@ -846,14 +845,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uin * * `srcC = srcC * color` * - * Color modulation is not always supported by the renderer; it will return -1 + * Color modulation is not always supported by the renderer; it will return SDL_FALSE * if color modulation is not supported. * * \param texture the texture to update. * \param r the red color value multiplied into copy operations. * \param g the green color value multiplied into copy operations. * \param b the blue color value multiplied into copy operations. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -862,7 +861,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureColorMod(SDL_Texture *texture, Uin * \sa SDL_SetTextureAlphaModFloat * \sa SDL_SetTextureColorMod */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b); /** @@ -872,7 +871,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureColorModFloat(SDL_Texture *texture * \param r a pointer filled in with the current red color value. * \param g a pointer filled in with the current green color value. * \param b a pointer filled in with the current blue color value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -881,7 +880,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureColorModFloat(SDL_Texture *texture * \sa SDL_GetTextureColorModFloat * \sa SDL_SetTextureColorMod */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b); /** * Get the additional color value multiplied into render copy operations. @@ -890,7 +889,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uin * \param r a pointer filled in with the current red color value. * \param g a pointer filled in with the current green color value. * \param b a pointer filled in with the current blue color value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -899,7 +898,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureColorMod(SDL_Texture *texture, Uin * \sa SDL_GetTextureColorMod * \sa SDL_SetTextureColorModFloat */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b); /** * Set an additional alpha value multiplied into render copy operations. @@ -909,12 +908,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureColorModFloat(SDL_Texture *texture * * `srcA = srcA * (alpha / 255)` * - * Alpha modulation is not always supported by the renderer; it will return -1 + * Alpha modulation is not always supported by the renderer; it will return SDL_FALSE * if alpha modulation is not supported. * * \param texture the texture to update. * \param alpha the source alpha value multiplied into copy operations. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -923,7 +922,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureColorModFloat(SDL_Texture *texture * \sa SDL_SetTextureAlphaModFloat * \sa SDL_SetTextureColorMod */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha); /** * Set an additional alpha value multiplied into render copy operations. @@ -933,12 +932,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uin * * `srcA = srcA * alpha` * - * Alpha modulation is not always supported by the renderer; it will return -1 + * Alpha modulation is not always supported by the renderer; it will return SDL_FALSE * if alpha modulation is not supported. * * \param texture the texture to update. * \param alpha the source alpha value multiplied into copy operations. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -947,14 +946,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureAlphaMod(SDL_Texture *texture, Uin * \sa SDL_SetTextureAlphaMod * \sa SDL_SetTextureColorModFloat */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha); /** * Get the additional alpha value multiplied into render copy operations. * * \param texture the texture to query. * \param alpha a pointer filled in with the current alpha value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -963,14 +962,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetTextureAlphaModFloat(SDL_Texture *texture * \sa SDL_GetTextureColorMod * \sa SDL_SetTextureAlphaMod */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha); /** * Get the additional alpha value multiplied into render copy operations. * * \param texture the texture to query. * \param alpha a pointer filled in with the current alpha value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -979,7 +978,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureAlphaMod(SDL_Texture *texture, Uin * \sa SDL_GetTextureColorModFloat * \sa SDL_SetTextureAlphaModFloat */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha); /** * Set the blend mode for a texture, used by SDL_RenderTexture(). @@ -989,28 +988,28 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureAlphaModFloat(SDL_Texture *texture * * \param texture the texture to update. * \param blendMode the SDL_BlendMode to use for texture blending. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetTextureBlendMode */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode); /** * Get the blend mode used for texture copy operations. * * \param texture the texture to query. * \param blendMode a pointer filled in with the current SDL_BlendMode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetTextureBlendMode */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode); /** * Set the scale mode used for texture scale operations. @@ -1021,28 +1020,28 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureBlendMode(SDL_Texture *texture, SD * * \param texture the texture to update. * \param scaleMode the SDL_ScaleMode to use for texture scaling. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetTextureScaleMode */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode); /** * Get the scale mode used for texture scale operations. * * \param texture the texture to query. * \param scaleMode a pointer filled in with the current scale mode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetTextureScaleMode */ -extern SDL_DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode); /** * Update the given texture rectangle with new pixel data. @@ -1064,7 +1063,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SD * \param pixels the raw pixel data in the format of the texture. * \param pitch the number of bytes in a row of pixel data, including padding * between lines. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1074,7 +1073,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetTextureScaleMode(SDL_Texture *texture, SD * \sa SDL_UpdateNVTexture * \sa SDL_UpdateYUVTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch); /** * Update a rectangle within a planar YV12 or IYUV texture with new pixel @@ -1096,7 +1095,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SD * \param Vplane the raw pixel data for the V plane. * \param Vpitch the number of bytes between rows of pixel data for the V * plane. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1104,7 +1103,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateTexture(SDL_Texture *texture, const SD * \sa SDL_UpdateNVTexture * \sa SDL_UpdateTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture, +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -1126,7 +1125,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture, * \param UVplane the raw pixel data for the UV plane. * \param UVpitch the number of bytes between rows of pixel data for the UV * plane. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1134,7 +1133,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture, * \sa SDL_UpdateTexture * \sa SDL_UpdateYUVTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture, +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch); @@ -1158,7 +1157,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture, * appropriately offset by the locked area. * \param pitch this is filled in with the pitch of the locked pixels; the * pitch is the length of one row in bytes. - * \returns 0 on success or a negative error code if the texture is not valid + * \returns SDL_TRUE on success or SDL_FALSE if the texture is not valid * or was not created with `SDL_TEXTUREACCESS_STREAMING`; call * SDL_GetError() for more information. * @@ -1167,7 +1166,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateNVTexture(SDL_Texture *texture, * \sa SDL_LockTextureToSurface * \sa SDL_UnlockTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture *texture, +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch); @@ -1195,7 +1194,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture *texture, * NULL, the entire texture will be locked. * \param surface this is filled in with an SDL surface representing the * locked area. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1203,9 +1202,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_LockTexture(SDL_Texture *texture, * \sa SDL_LockTexture * \sa SDL_UnlockTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_LockTextureToSurface(SDL_Texture *texture, - const SDL_Rect *rect, - SDL_Surface **surface); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Surface **surface); /** * Unlock a texture, uploading the changes to video memory, if needed. @@ -1237,14 +1234,14 @@ extern SDL_DECLSPEC void SDLCALL SDL_UnlockTexture(SDL_Texture *texture); * \param texture the targeted texture, which must be created with the * `SDL_TEXTUREACCESS_TARGET` flag, or NULL to render to the * window instead of a texture. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetRenderTarget */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture); /** * Get the current render target. @@ -1280,7 +1277,7 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *rend * \param h the height of the logical resolution. * \param mode the presentation mode used. * \param scale_mode the scale mode used. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1289,7 +1286,7 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *rend * \sa SDL_GetRenderLogicalPresentation * \sa SDL_GetRenderLogicalPresentationRect */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode); /** * Get device independent resolution and presentation mode for rendering. @@ -1302,14 +1299,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *r * \param h an int to be filled with the height. * \param mode a pointer filled in with the presentation mode. * \param scale_mode a pointer filled in with the scale mode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetRenderLogicalPresentation */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode); /** * Get the final presentation rectangle for rendering. @@ -1322,14 +1319,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *r * \param renderer the rendering context. * \param rect a pointer filled in with the final presentation rectangle, may * be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetRenderLogicalPresentation */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect); /** * Get a point in render coordinates when given a point in window coordinates. @@ -1339,7 +1336,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentationRect(SDL_Rendere * \param window_y the y coordinate in window coordinates. * \param x a pointer filled with the x coordinate in render coordinates. * \param y a pointer filled with the y coordinate in render coordinates. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1347,7 +1344,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderLogicalPresentationRect(SDL_Rendere * \sa SDL_SetRenderLogicalPresentation * \sa SDL_SetRenderScale */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y); /** * Get a point in window coordinates when given a point in render coordinates. @@ -1359,7 +1356,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *re * coordinates. * \param window_y a pointer filled with the y coordinate in window * coordinates. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1367,7 +1364,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderCoordinatesFromWindow(SDL_Renderer *re * \sa SDL_SetRenderLogicalPresentation * \sa SDL_SetRenderScale */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y); /** * Convert the coordinates in an event to render coordinates. @@ -1379,14 +1376,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderCoordinatesToWindow(SDL_Renderer *rend * * \param renderer the rendering context. * \param event the event to modify. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderCoordinatesFromWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event); /** * Set the drawing area for rendering on the current target. @@ -1394,7 +1391,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer * \param renderer the rendering context. * \param rect the SDL_Rect structure representing the drawing area, or NULL * to set the viewport to the entire target. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1402,14 +1399,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertEventToRenderCoordinates(SDL_Renderer * \sa SDL_GetRenderViewport * \sa SDL_RenderViewportSet */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect); /** * Get the drawing area for the current target. * * \param renderer the rendering context. * \param rect an SDL_Rect structure filled in with the current drawing area. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1417,7 +1414,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderViewport(SDL_Renderer *renderer, co * \sa SDL_RenderViewportSet * \sa SDL_SetRenderViewport */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect); /** * Return whether an explicit rectangle was set as the viewport. @@ -1450,12 +1447,12 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderViewportSet(SDL_Renderer *rendere * \param renderer the rendering context. * \param rect a pointer filled in with the area that is safe for interactive * content. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect); /** * Set the clip rectangle for rendering on the specified target. @@ -1463,7 +1460,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderSafeArea(SDL_Renderer *renderer, SD * \param renderer the rendering context. * \param rect an SDL_Rect structure representing the clip area, relative to * the viewport, or NULL to disable clipping. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1471,7 +1468,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderSafeArea(SDL_Renderer *renderer, SD * \sa SDL_GetRenderClipRect * \sa SDL_RenderClipEnabled */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect); /** * Get the clip rectangle for the current target. @@ -1479,7 +1476,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, co * \param renderer the rendering context. * \param rect an SDL_Rect structure filled in with the current clipping area * or an empty rectangle if clipping is disabled. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1487,7 +1484,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderClipRect(SDL_Renderer *renderer, co * \sa SDL_RenderClipEnabled * \sa SDL_SetRenderClipRect */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect); /** * Get whether clipping is enabled on the given renderer. @@ -1517,14 +1514,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderClipEnabled(SDL_Renderer *rendere * \param renderer the rendering context. * \param scaleX the horizontal scaling factor. * \param scaleY the vertical scaling factor. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetRenderScale */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY); /** * Get the drawing scale for the current target. @@ -1532,14 +1529,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderScale(SDL_Renderer *renderer, float * \param renderer the rendering context. * \param scaleX a pointer filled in with the horizontal scaling factor. * \param scaleY a pointer filled in with the vertical scaling factor. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetRenderScale */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY); /** * Set the color used for drawing operations. @@ -1554,7 +1551,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float * \param a the alpha value used to draw on the rendering target; usually * `SDL_ALPHA_OPAQUE` (255). Use SDL_SetRenderDrawBlendMode to * specify how the alpha channel is used. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1562,7 +1559,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderScale(SDL_Renderer *renderer, float * \sa SDL_GetRenderDrawColor * \sa SDL_SetRenderDrawColorFloat */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /** * Set the color used for drawing operations (Rect, Line and Clear). @@ -1577,7 +1574,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, U * \param a the alpha value used to draw on the rendering target. Use * SDL_SetRenderDrawBlendMode to specify how the alpha channel is * used. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1585,7 +1582,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawColor(SDL_Renderer *renderer, U * \sa SDL_GetRenderDrawColorFloat * \sa SDL_SetRenderDrawColor */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a); /** * Get the color used for drawing operations (Rect, Line and Clear). @@ -1599,7 +1596,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawColorFloat(SDL_Renderer *render * rendering target. * \param a a pointer filled in with the alpha value used to draw on the * rendering target; usually `SDL_ALPHA_OPAQUE` (255). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1607,7 +1604,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawColorFloat(SDL_Renderer *render * \sa SDL_GetRenderDrawColorFloat * \sa SDL_SetRenderDrawColor */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); /** * Get the color used for drawing operations (Rect, Line and Clear). @@ -1621,7 +1618,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, U * rendering target. * \param a a pointer filled in with the alpha value used to draw on the * rendering target. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1629,7 +1626,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawColor(SDL_Renderer *renderer, U * \sa SDL_SetRenderDrawColorFloat * \sa SDL_GetRenderDrawColor */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a); /** * Set the color scale used for render operations. @@ -1644,28 +1641,28 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawColorFloat(SDL_Renderer *render * * \param renderer the rendering context. * \param scale the color scale value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetRenderColorScale */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale); /** * Get the color scale used for render operations. * * \param renderer the rendering context. * \param scale a pointer filled in with the current color scale value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetRenderColorScale */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale); /** * Set the blend mode used for drawing operations (Fill and Line). @@ -1674,28 +1671,28 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderColorScale(SDL_Renderer *renderer, * * \param renderer the rendering context. * \param blendMode the SDL_BlendMode to use for blending. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetRenderDrawBlendMode */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode); /** * Get the blend mode used for drawing operations. * * \param renderer the rendering context. * \param blendMode a pointer filled in with the current SDL_BlendMode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetRenderDrawBlendMode */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode); /** * Clear the current rendering target with the drawing color. @@ -1706,14 +1703,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer *rendere * SDL_SetRenderDrawColor() when needed. * * \param renderer the rendering context. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetRenderDrawColor */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer *renderer); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderClear(SDL_Renderer *renderer); /** * Draw a point on the current rendering target at subpixel precision. @@ -1721,14 +1718,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer *renderer); * \param renderer the renderer which should draw a point. * \param x the x coordinate of the point. * \param y the y coordinate of the point. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderPoints */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderPoint(SDL_Renderer *renderer, float x, float y); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderPoint(SDL_Renderer *renderer, float x, float y); /** * Draw multiple points on the current rendering target at subpixel precision. @@ -1736,14 +1733,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderPoint(SDL_Renderer *renderer, float x, * \param renderer the renderer which should draw multiple points. * \param points the points to draw. * \param count the number of points to draw. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderPoint */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count); /** * Draw a line on the current rendering target at subpixel precision. @@ -1753,14 +1750,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderPoints(SDL_Renderer *renderer, const S * \param y1 the y coordinate of the start point. * \param x2 the x coordinate of the end point. * \param y2 the y coordinate of the end point. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderLines */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2); /** * Draw a series of connected lines on the current rendering target at @@ -1769,14 +1766,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderLine(SDL_Renderer *renderer, float x1, * \param renderer the renderer which should draw multiple lines. * \param points the points along the lines. * \param count the number of points, drawing count-1 lines. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderLine */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count); /** * Draw a rectangle on the current rendering target at subpixel precision. @@ -1784,14 +1781,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderLines(SDL_Renderer *renderer, const SD * \param renderer the renderer which should draw a rectangle. * \param rect a pointer to the destination rectangle, or NULL to outline the * entire rendering target. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderRects */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect); /** * Draw some number of rectangles on the current rendering target at subpixel @@ -1800,14 +1797,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderRect(SDL_Renderer *renderer, const SDL * \param renderer the renderer which should draw multiple rectangles. * \param rects a pointer to an array of destination rectangles. * \param count the number of rectangles. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderRect */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count); /** * Fill a rectangle on the current rendering target with the drawing color at @@ -1816,14 +1813,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderRects(SDL_Renderer *renderer, const SD * \param renderer the renderer which should fill a rectangle. * \param rect a pointer to the destination rectangle, or NULL for the entire * rendering target. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderFillRects */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect); /** * Fill some number of rectangles on the current rendering target with the @@ -1832,14 +1829,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer *renderer, const * \param renderer the renderer which should fill multiple rectangles. * \param rects a pointer to an array of destination rectangles. * \param count the number of rectangles. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderFillRect */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count); /** * Copy a portion of the texture to the current rendering target at subpixel @@ -1851,7 +1848,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, cons * texture. * \param dstrect a pointer to the destination rectangle, or NULL for the * entire rendering target. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1859,7 +1856,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer *renderer, cons * \sa SDL_RenderTextureRotated * \sa SDL_RenderTextureTiled */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect); /** * Copy a portion of the source texture to the current rendering target, with @@ -1878,14 +1875,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderTexture(SDL_Renderer *renderer, SDL_Te * around dstrect.w/2, dstrect.h/2). * \param flip an SDL_FlipMode value stating which flipping actions should be * performed on the texture. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_FlipMode flip); @@ -1906,14 +1903,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderTextureRotated(SDL_Renderer *renderer, * 64x64 tiles. * \param dstrect a pointer to the destination rectangle, or NULL for the * entire rendering target. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect); /** * Perform a scaled copy using the 9-grid algorithm to the current rendering @@ -1938,14 +1935,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderTextureTiled(SDL_Renderer *renderer, S * corner of `dstrect`, or 0.0f for an unscaled copy. * \param dstrect a pointer to the destination rectangle, or NULL for the * entire rendering target. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderTexture */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect); /** * Render a list of triangles, optionally using a texture and indices into the @@ -1960,14 +1957,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderTexture9Grid(SDL_Renderer *renderer, S * array, if NULL all vertices will be rendered in sequential * order. * \param num_indices number of indices. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderGeometryRaw */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer, +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Vertex *vertices, int num_vertices, const int *indices, int num_indices); @@ -1990,14 +1987,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometry(SDL_Renderer *renderer, * if NULL all vertices will be rendered in sequential order. * \param num_indices number of indices. * \param size_indices index size: 1 (byte), 2 (short), 4 (int). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_RenderGeometry */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer, +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, @@ -2050,7 +2047,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RenderReadPixels(SDL_Renderer *ren * do not have a concept of backbuffers. * * \param renderer the rendering context. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety You may only call this function on the main thread. @@ -2070,7 +2067,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_RenderReadPixels(SDL_Renderer *ren * \sa SDL_SetRenderDrawBlendMode * \sa SDL_SetRenderDrawColor */ -extern SDL_DECLSPEC int SDLCALL SDL_RenderPresent(SDL_Renderer *renderer); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenderPresent(SDL_Renderer *renderer); /** * Destroy the specified texture. @@ -2125,12 +2122,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer *renderer); * be prepared to make changes if specific state needs to be protected. * * \param renderer the rendering context. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_FlushRenderer(SDL_Renderer *renderer); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FlushRenderer(SDL_Renderer *renderer); /** * Get the CAMetalLayer associated with the given Metal renderer. @@ -2190,7 +2187,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetRenderMetalCommandEncoder(SDL_Renderer * \param signal_semaphore a VkSempahore that SDL will signal when rendering * for the current frame is complete, or 0 if not * needed. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is **NOT** safe to call this function from two threads at @@ -2198,7 +2195,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetRenderMetalCommandEncoder(SDL_Renderer * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore); /** * Toggle VSync of the given renderer. @@ -2214,14 +2211,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_AddVulkanRenderSemaphores(SDL_Renderer *rend * * \param renderer the renderer to toggle. * \param vsync the vertical refresh sync interval. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetRenderVSync */ -extern SDL_DECLSPEC int SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync); #define SDL_RENDERER_VSYNC_DISABLED 0 #define SDL_RENDERER_VSYNC_ADAPTIVE (-1) @@ -2232,14 +2229,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetRenderVSync(SDL_Renderer *renderer, int v * \param renderer the renderer to toggle. * \param vsync an int filled with the current vertical refresh sync interval. * See SDL_SetRenderVSync() for the meaning of the value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetRenderVSync */ -extern SDL_DECLSPEC int SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL3/SDL_sensor.h b/include/SDL3/SDL_sensor.h index f3beac42eb..3d2c67440e 100644 --- a/include/SDL3/SDL_sensor.h +++ b/include/SDL3/SDL_sensor.h @@ -277,12 +277,12 @@ extern SDL_DECLSPEC SDL_SensorID SDLCALL SDL_GetSensorID(SDL_Sensor *sensor); * \param sensor the SDL_Sensor object to query. * \param data a pointer filled with the current sensor state. * \param num_values the number of values to write to data. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values); /** * Close a sensor previously opened with SDL_OpenSensor(). diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h index b5ec668b00..3436c4ab6c 100644 --- a/include/SDL3/SDL_stdinc.h +++ b/include/SDL3/SDL_stdinc.h @@ -595,7 +595,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_ * \param calloc_func custom calloc function. * \param realloc_func custom realloc function. * \param free_func custom free function. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread, but one @@ -607,10 +607,10 @@ extern SDL_DECLSPEC void SDLCALL SDL_GetMemoryFunctions(SDL_malloc_func *malloc_ * \sa SDL_GetMemoryFunctions * \sa SDL_GetOriginalMemoryFunctions */ -extern SDL_DECLSPEC int SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, - SDL_calloc_func calloc_func, - SDL_realloc_func realloc_func, - SDL_free_func free_func); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, + SDL_calloc_func calloc_func, + SDL_realloc_func realloc_func, + SDL_free_func free_func); /** * Allocate memory aligned to a specific value. diff --git a/include/SDL3/SDL_storage.h b/include/SDL3/SDL_storage.h index 7fc58a887d..718577ce20 100644 --- a/include/SDL3/SDL_storage.h +++ b/include/SDL3/SDL_storage.h @@ -57,34 +57,34 @@ extern "C" { typedef struct SDL_StorageInterface { /* Called when the storage is closed */ - int (SDLCALL *close)(void *userdata); + SDL_bool (SDLCALL *close)(void *userdata); /* Optional, returns whether the storage is currently ready for access */ SDL_bool (SDLCALL *ready)(void *userdata); /* Enumerate a directory, optional for write-only storage */ - int (SDLCALL *enumerate)(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata); + SDL_bool (SDLCALL *enumerate)(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata); /* Get path information, optional for write-only storage */ - int (SDLCALL *info)(void *userdata, const char *path, SDL_PathInfo *info); + SDL_bool (SDLCALL *info)(void *userdata, const char *path, SDL_PathInfo *info); /* Read a file from storage, optional for write-only storage */ - int (SDLCALL *read_file)(void *userdata, const char *path, void *destination, Uint64 length); + SDL_bool (SDLCALL *read_file)(void *userdata, const char *path, void *destination, Uint64 length); /* Write a file to storage, optional for read-only storage */ - int (SDLCALL *write_file)(void *userdata, const char *path, const void *source, Uint64 length); + SDL_bool (SDLCALL *write_file)(void *userdata, const char *path, const void *source, Uint64 length); /* Create a directory, optional for read-only storage */ - int (SDLCALL *mkdir)(void *userdata, const char *path); + SDL_bool (SDLCALL *mkdir)(void *userdata, const char *path); /* Remove a file or empty directory, optional for read-only storage */ - int (SDLCALL *remove)(void *userdata, const char *path); + SDL_bool (SDLCALL *remove)(void *userdata, const char *path); /* Rename a path, optional for read-only storage */ - int (SDLCALL *rename)(void *userdata, const char *oldpath, const char *newpath); + SDL_bool (SDLCALL *rename)(void *userdata, const char *oldpath, const char *newpath); /* Copy a file, optional for read-only storage */ - int (SDLCALL *copy)(void *userdata, const char *oldpath, const char *newpath); + SDL_bool (SDLCALL *copy)(void *userdata, const char *oldpath, const char *newpath); /* Get the space remaining, optional for read-only storage */ Uint64 (SDLCALL *space_remaining)(void *userdata); @@ -196,7 +196,7 @@ extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenStorage(const SDL_StorageInter * Closes and frees a storage container. * * \param storage a storage container to close. - * \returns 0 if the container was freed with no errors, a negative value + * \returns SDL_TRUE if the container was freed with no errors, SDL_FALSE * otherwise; call SDL_GetError() for more information. Even if the * function returns an error, the container data will be freed; the * error is only for informational purposes. @@ -208,7 +208,7 @@ extern SDL_DECLSPEC SDL_Storage * SDLCALL SDL_OpenStorage(const SDL_StorageInter * \sa SDL_OpenTitleStorage * \sa SDL_OpenUserStorage */ -extern SDL_DECLSPEC int SDLCALL SDL_CloseStorage(SDL_Storage *storage); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CloseStorage(SDL_Storage *storage); /** * Checks if the storage container is ready to use. @@ -230,7 +230,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StorageReady(SDL_Storage *storage); * \param storage a storage container to query. * \param path the relative path of the file to query. * \param length a pointer to be filled with the file's length. - * \returns 0 if the file could be queried or a negative error code on + * \returns SDL_TRUE if the file could be queried or SDL_FALSE on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -238,7 +238,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_StorageReady(SDL_Storage *storage); * \sa SDL_ReadStorageFile * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_GetStorageFileSize(SDL_Storage *storage, const char *path, Uint64 *length); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetStorageFileSize(SDL_Storage *storage, const char *path, Uint64 *length); /** * Synchronously read a file from a storage container into a client-provided @@ -248,7 +248,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetStorageFileSize(SDL_Storage *storage, con * \param path the relative path of the file to read. * \param destination a client-provided buffer to read the file into. * \param length the length of the destination buffer. - * \returns 0 if the file was read or a negative error code on failure; call + * \returns SDL_TRUE if the file was read or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -257,7 +257,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetStorageFileSize(SDL_Storage *storage, con * \sa SDL_StorageReady * \sa SDL_WriteStorageFile */ -extern SDL_DECLSPEC int SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length); /** * Synchronously write a file from client memory into a storage container. @@ -266,7 +266,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const * \param path the relative path of the file to write. * \param source a client-provided buffer to write from. * \param length the length of the source buffer. - * \returns 0 if the file was written or a negative error code on failure; + * \returns SDL_TRUE if the file was written or SDL_FALSE on failure; * call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -275,21 +275,21 @@ extern SDL_DECLSPEC int SDLCALL SDL_ReadStorageFile(SDL_Storage *storage, const * \sa SDL_ReadStorageFile * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *source, Uint64 length); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *source, Uint64 length); /** * Create a directory in a writable storage container. * * \param storage a storage container. * \param path the path of the directory to create. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path); /** * Enumerate a directory in a storage container through a callback function. @@ -302,28 +302,28 @@ extern SDL_DECLSPEC int SDLCALL SDL_CreateStorageDirectory(SDL_Storage *storage, * \param path the path of the directory to enumerate. * \param callback a function that is called for each entry in the directory. * \param userdata a pointer that is passed to `callback`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata); /** * Remove a file or an empty directory in a writable storage container. * * \param storage a storage container. * \param path the path of the directory to enumerate. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_RemoveStoragePath(SDL_Storage *storage, const char *path); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RemoveStoragePath(SDL_Storage *storage, const char *path); /** * Rename a file or directory in a writable storage container. @@ -331,14 +331,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RemoveStoragePath(SDL_Storage *storage, cons * \param storage a storage container. * \param oldpath the old path. * \param newpath the new path. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char *newpath); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char *newpath); /** * Copy a file in a writable storage container. @@ -346,14 +346,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RenameStoragePath(SDL_Storage *storage, cons * \param storage a storage container. * \param oldpath the old path. * \param newpath the new path. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *newpath); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *newpath); /** * Get information about a filesystem path in a storage container. @@ -362,14 +362,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_CopyStorageFile(SDL_Storage *storage, const * \param path the path to query. * \param info a pointer filled in with information about the path, or NULL to * check for the existence of a file. - * \returns 0 on success or a negative error code if the file doesn't exist, + * \returns SDL_TRUE on success or SDL_FALSE if the file doesn't exist, * or another failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_StorageReady */ -extern SDL_DECLSPEC int SDLCALL SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info); /** * Queries the remaining space in a storage container. diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h index 8ca4ea2533..31c0a2624f 100644 --- a/include/SDL3/SDL_surface.h +++ b/include/SDL3/SDL_surface.h @@ -224,14 +224,14 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSurfaceProperties(SDL_Surfac * \param surface the SDL_Surface structure to update. * \param colorspace an SDL_ColorSpace value describing the surface * colorspace. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetSurfaceColorspace */ -extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace); /** * Get the colorspace used by a surface. @@ -285,7 +285,7 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface * * * \param surface the SDL_Surface structure to update. * \param palette the SDL_Palette structure to use. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -293,7 +293,7 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_CreateSurfacePalette(SDL_Surface * * \sa SDL_CreatePalette * \sa SDL_GetSurfacePalette */ -extern SDL_DECLSPEC int SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette); /** * Get the palette used by a surface. @@ -322,8 +322,8 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *sur * \param surface the SDL_Surface structure to update. * \param image a pointer to an alternate SDL_Surface to associate with this * surface. - * \returns SDL_TRUE if alternate versions are available or SDL_TRUE - * otherwise. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call + * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -331,7 +331,7 @@ extern SDL_DECLSPEC SDL_Palette * SDLCALL SDL_GetSurfacePalette(SDL_Surface *sur * \sa SDL_GetSurfaceImages * \sa SDL_SurfaceHasAlternateImages */ -extern SDL_DECLSPEC int SDLCALL SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image); /** * Return whether a surface has alternate versions available. @@ -402,7 +402,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *s * format of the surface will not change. * * \param surface the SDL_Surface structure to be locked. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -410,7 +410,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_RemoveSurfaceAlternateImages(SDL_Surface *s * \sa SDL_MUSTLOCK * \sa SDL_UnlockSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_LockSurface(SDL_Surface *surface); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_LockSurface(SDL_Surface *surface); /** * Release a surface after directly accessing the pixels. @@ -474,7 +474,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file); * \param dst a data stream to save to. * \param closeio if SDL_TRUE, calls SDL_CloseIO() on `dst` before returning, * even in the case of an error. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -482,7 +482,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file); * \sa SDL_LoadBMP_IO * \sa SDL_SaveBMP */ -extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio); /** * Save a surface to a file. @@ -495,7 +495,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStrea * * \param surface the SDL_Surface structure containing the image to be saved. * \param file a file to save to. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -503,7 +503,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStrea * \sa SDL_LoadBMP * \sa SDL_SaveBMP_IO */ -extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file); /** * Set the RLE acceleration hint for a surface. @@ -514,7 +514,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *fi * \param surface the SDL_Surface structure to optimize. * \param enabled SDL_TRUE to enable RLE acceleration, SDL_FALSE to disable * it. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -523,7 +523,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *fi * \sa SDL_LockSurface * \sa SDL_UnlockSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled); /** * Returns whether the surface is RLE enabled. @@ -553,7 +553,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface); * \param enabled SDL_TRUE to enable color key, SDL_FALSE to disable color * key. * \param key the transparent pixel. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -562,7 +562,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasRLE(SDL_Surface *surface); * \sa SDL_SetSurfaceRLE * \sa SDL_SurfaceHasColorKey */ -extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key); /** * Returns whether the surface has a color key. @@ -589,7 +589,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface * * \param surface the SDL_Surface structure to query. * \param key a pointer filled in with the transparent pixel. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -597,7 +597,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SurfaceHasColorKey(SDL_Surface *surface * \sa SDL_SetSurfaceColorKey * \sa SDL_SurfaceHasColorKey */ -extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key); /** * Set an additional color value multiplied into blit operations. @@ -612,7 +612,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uin * \param r the red color value multiplied into blit operations. * \param g the green color value multiplied into blit operations. * \param b the blue color value multiplied into blit operations. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -620,7 +620,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorKey(SDL_Surface *surface, Uin * \sa SDL_GetSurfaceColorMod * \sa SDL_SetSurfaceAlphaMod */ -extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b); /** @@ -630,7 +630,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uin * \param r a pointer filled in with the current red color value. * \param g a pointer filled in with the current green color value. * \param b a pointer filled in with the current blue color value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -638,7 +638,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceColorMod(SDL_Surface *surface, Uin * \sa SDL_GetSurfaceAlphaMod * \sa SDL_SetSurfaceColorMod */ -extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b); /** * Set an additional alpha value used in blit operations. @@ -650,7 +650,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uin * * \param surface the SDL_Surface structure to update. * \param alpha the alpha value multiplied into blit operations. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -658,14 +658,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceColorMod(SDL_Surface *surface, Uin * \sa SDL_GetSurfaceAlphaMod * \sa SDL_SetSurfaceColorMod */ -extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha); /** * Get the additional alpha value used in blit operations. * * \param surface the SDL_Surface structure to query. * \param alpha a pointer filled in with the current alpha value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -673,7 +673,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uin * \sa SDL_GetSurfaceColorMod * \sa SDL_SetSurfaceAlphaMod */ -extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha); /** * Set the blend mode used for blit operations. @@ -684,28 +684,28 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uin * * \param surface the SDL_Surface structure to update. * \param blendMode the SDL_BlendMode to use for blit blending. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetSurfaceBlendMode */ -extern SDL_DECLSPEC int SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode); /** * Get the blend mode used for blit operations. * * \param surface the SDL_Surface structure to query. * \param blendMode a pointer filled in with the current SDL_BlendMode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetSurfaceBlendMode */ -extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode); /** * Set the clipping rectangle for a surface. @@ -738,26 +738,26 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetSurfaceClipRect(SDL_Surface *surface * clipped. * \param rect an SDL_Rect structure filled in with the clipping rectangle for * the surface. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetSurfaceClipRect */ -extern SDL_DECLSPEC int SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect); /** * Flip a surface vertically or horizontally. * * \param surface the surface to flip. * \param flip the direction to flip. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip); /** * Creates a new surface identical to the existing surface. @@ -860,14 +860,14 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_ConvertSurfaceAndColorspace(SDL_Su * \param dst_format an SDL_PixelFormat value of the `dst` pixels format. * \param dst a pointer to be filled in with new pixel data. * \param dst_pitch the pitch of the destination pixels, in bytes. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_FALSE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_ConvertPixelsAndColorspace */ -extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch); /** * Copy a block of pixels of one format and colorspace to another format and @@ -889,14 +889,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, SDL_Pix * properties, or 0. * \param dst a pointer to be filled in with new pixel data. * \param dst_pitch the pitch of the destination pixels, in bytes. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_FALSE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_ConvertPixels */ -extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); /** * Premultiply the alpha on a block of pixels. @@ -913,12 +913,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_ConvertPixelsAndColorspace(int width, int he * \param dst_pitch the pitch of the destination pixels, in bytes. * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha * multiplication, SDL_FALSE to do multiplication in sRGB space. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, SDL_bool linear); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, SDL_bool linear); /** * Premultiply the alpha in a surface. @@ -928,12 +928,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_ * \param surface the surface to modify. * \param linear SDL_TRUE to convert from sRGB to linear space for the alpha * multiplication, SDL_FALSE to do multiplication in sRGB space. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear); /** * Clear a surface with a specific color, with floating point precision. @@ -948,12 +948,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_PremultiplySurfaceAlpha(SDL_Surface *surface * \param g the green component of the pixel, normally in the range 0-1. * \param b the blue component of the pixel, normally in the range 0-1. * \param a the alpha component of the pixel, normally in the range 0-1. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a); /** * Perform a fast fill of a rectangle with a specific color. @@ -971,14 +971,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_ClearSurface(SDL_Surface *surface, float r, * \param rect the SDL_Rect structure representing the rectangle to fill, or * NULL to fill the entire surface. * \param color the color to fill with. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_FillSurfaceRects */ -extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color); /** * Perform a fast fill of a set of rectangles with a specific color. @@ -996,14 +996,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_ * \param rects an array of SDL_Rects representing the rectangles to fill. * \param count the number of rectangles in the array. * \param color the color to fill with. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_FillSurfaceRect */ -extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color); /** * Performs a fast blit from the source surface to the destination surface. @@ -1067,7 +1067,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL * height are ignored, and are copied from `srcrect`. If you * want a specific width and height, you should use * SDL_BlitSurfaceScaled(). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety The same destination surface should not be used from two @@ -1078,7 +1078,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_FillSurfaceRects(SDL_Surface *dst, const SDL * * \sa SDL_BlitSurfaceScaled */ -extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); /** * Perform low-level surface blitting only. @@ -1092,7 +1092,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect * \param dst the SDL_Surface structure that is the blit target. * \param dstrect the SDL_Rect structure representing the target rectangle in * the destination surface, may not be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety The same destination surface should not be used from two @@ -1103,7 +1103,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface(SDL_Surface *src, const SDL_Rect * * \sa SDL_BlitSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); /** * Perform a scaled blit to a destination surface, which may be of a different @@ -1117,7 +1117,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const * the destination surface, or NULL to fill the entire * destination surface. * \param scaleMode the SDL_ScaleMode to be used. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety The same destination surface should not be used from two @@ -1128,7 +1128,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUnchecked(SDL_Surface *src, const * * \sa SDL_BlitSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); /** * Perform low-level surface scaled blitting only. @@ -1143,7 +1143,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SD * \param dstrect the SDL_Rect structure representing the target rectangle in * the destination surface, may not be NULL. * \param scaleMode the SDL_ScaleMode to be used. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety The same destination surface should not be used from two @@ -1154,7 +1154,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceScaled(SDL_Surface *src, const SD * * \sa SDL_BlitSurfaceScaled */ -extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); /** * Perform a tiled blit to a destination surface, which may be of a different @@ -1169,7 +1169,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, * \param dst the SDL_Surface structure that is the blit target. * \param dstrect the SDL_Rect structure representing the target rectangle in * the destination surface, or NULL to fill the entire surface. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety The same destination surface should not be used from two @@ -1180,7 +1180,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, * * \sa SDL_BlitSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); /** * Perform a scaled and tiled blit to a destination surface, which may be of a @@ -1199,7 +1199,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL * \param dst the SDL_Surface structure that is the blit target. * \param dstrect the SDL_Rect structure representing the target rectangle in * the destination surface, or NULL to fill the entire surface. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety The same destination surface should not be used from two @@ -1210,7 +1210,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL * * \sa SDL_BlitSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect); /** * Perform a scaled blit using the 9-grid algorithm to a destination surface, @@ -1236,7 +1236,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, * \param dst the SDL_Surface structure that is the blit target. * \param dstrect the SDL_Rect structure representing the target rectangle in * the destination surface, or NULL to fill the entire surface. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety The same destination surface should not be used from two @@ -1247,7 +1247,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, * * \sa SDL_BlitSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect); /** * Map an RGB triple to an opaque pixel value for a surface. @@ -1330,12 +1330,12 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint * ignore this channel. * \param a a pointer filled in with the alpha channel, 0-255, or NULL to * ignore this channel. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); /** * Retrieves a single pixel from a surface. @@ -1354,12 +1354,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x * 0-1, or NULL to ignore this channel. * \param a a pointer filled in with the alpha channel, normally in the range * 0-1, or NULL to ignore this channel. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a); /** * Writes a single pixel to a surface. @@ -1377,12 +1377,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_ReadSurfacePixelFloat(SDL_Surface *surface, * \param g the green channel value, 0-255. * \param b the blue channel value, 0-255. * \param a the alpha channel value, 0-255. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /** * Writes a single pixel to a surface. @@ -1397,12 +1397,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_WriteSurfacePixel(SDL_Surface *surface, int * \param g the green channel value, normally in the range 0-1. * \param b the blue channel value, normally in the range 0-1. * \param a the alpha channel value, normally in the range 0-1. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL3/SDL_system.h b/include/SDL3/SDL_system.h index 9e79e79408..0f2da28147 100644 --- a/include/SDL3/SDL_system.h +++ b/include/SDL3/SDL_system.h @@ -101,7 +101,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHoo * controls on which monitor a full screen application will appear. * * \param displayID the instance of the display to query. - * \returns the D3D9 adapter index on success or a negative error code on + * \returns the D3D9 adapter index on success or -1 on * failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -122,12 +122,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displ * \param displayID the instance of the display to query. * \param adapterIndex a pointer to be filled in with the adapter index. * \param outputIndex a pointer to be filled in with the output index. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex); #endif /* defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINGDK) */ @@ -162,12 +162,12 @@ extern SDL_DECLSPEC void SDLCALL SDL_SetX11EventHook(SDL_X11EventHook callback, * * \param threadID the Unix thread ID to change priority of. * \param priority the new, Unix-specific, priority value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority); /** * Sets the priority (not nice level) and scheduling policy for a thread. @@ -178,12 +178,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int * \param sdlPriority the new SDL_ThreadPriority value. * \param schedPolicy the new scheduling policy (SCHED_FIFO, SCHED_RR, * SCHED_OTHER, etc...). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy); #endif /* SDL_PLATFORM_LINUX */ @@ -240,14 +240,14 @@ typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata); * called. * \param callback the function to call for every frame. * \param callbackParam a pointer that is passed to `callback`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetiOSEventPump */ -extern SDL_DECLSPEC int SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam); /** * Use this function to enable or disable the SDL event pump on Apple iOS. @@ -503,7 +503,7 @@ typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, con * \param permission the permission to request. * \param cb the callback to trigger when the request has a response. * \param userdata an app-controlled pointer that is passed to the callback. - * \returns zero if the request was submitted, -1 if there was an error + * \returns SDL_TRUE if the request was submitted, SDL_FALSE if there was an error * submitting. The result of the request is only ever reported * through the callback, not this return value. * @@ -511,7 +511,7 @@ typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, con * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata); /** * Shows an Android toast notification. @@ -532,14 +532,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_RequestAndroidPermission(const char *permiss * \param gravity where the notification should appear on the screen. * \param xoffset set this parameter only when gravity >=0. * \param yoffset set this parameter only when gravity >=0. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xoffset, int yoffset); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xoffset, int yoffset); /** * Send a user command to SDLActivity. @@ -548,14 +548,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_ShowAndroidToast(const char *message, int du * * \param command user command that must be greater or equal to 0x8000. * \param param user parameter. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SendAndroidMessage(Uint32 command, int param); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SendAndroidMessage(Uint32 command, int param); #endif /* SDL_PLATFORM_ANDROID */ @@ -794,12 +794,12 @@ typedef struct XUser *XUserHandle; * leak. * * \param outTaskQueue a pointer to be filled in with task queue handle. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue); /** * Gets a reference to the default user handle for GDK. @@ -809,12 +809,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQue * * \param outUserHandle a pointer to be filled in with the default user * handle. - * \returns 0 if success or a negative error code on failure; call + * \returns SDL_TRUE if success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetGDKDefaultUser(XUserHandle *outUserHandle); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGDKDefaultUser(XUserHandle *outUserHandle); #endif diff --git a/include/SDL3/SDL_test_font.h b/include/SDL3/SDL_test_font.h index 867205b869..45437ca93c 100644 --- a/include/SDL3/SDL_test_font.h +++ b/include/SDL3/SDL_test_font.h @@ -50,9 +50,9 @@ extern int FONT_CHARACTER_SIZE; * \param y The Y coordinate of the upper left corner of the character. * \param c The character to draw. * - * \returns 0 on success, -1 on failure. + * \returns SDL_TRUE on success, SDL_FALSE on failure. */ -int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c); +SDL_bool SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c); /* * Draw a UTF-8 string in the currently set font. @@ -64,9 +64,9 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c); * \param y The Y coordinate of the upper left corner of the string. * \param s The string to draw. * - * \returns 0 on success, -1 on failure. + * \returns SDL_TRUE on success, SDL_FALSE on failure. */ -int SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s); +SDL_bool SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s); /* * Data used for multi-line text output diff --git a/include/SDL3/SDL_thread.h b/include/SDL3/SDL_thread.h index f0011bb8f5..ee79e000a2 100644 --- a/include/SDL3/SDL_thread.h +++ b/include/SDL3/SDL_thread.h @@ -381,12 +381,12 @@ extern SDL_DECLSPEC SDL_ThreadID SDLCALL SDL_GetThreadID(SDL_Thread *thread); * an administrator account. Be prepared for this to fail. * * \param priority the SDL_ThreadPriority to set. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetThreadPriority(SDL_ThreadPriority priority); /** * Wait for a thread to finish. @@ -504,7 +504,7 @@ typedef void (SDLCALL *SDL_TLSDestructorCallback)(void *value); * \param value the value to associate with the ID for the current thread. * \param destructor a function called when the thread exits, to free the * value, may be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \threadsafety It is safe to call this function from any thread. @@ -513,7 +513,7 @@ typedef void (SDLCALL *SDL_TLSDestructorCallback)(void *value); * * \sa SDL_GetTLS */ -extern SDL_DECLSPEC int SDLCALL SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destructor); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destructor); /** * Cleanup all TLS data for this thread. diff --git a/include/SDL3/SDL_time.h b/include/SDL3/SDL_time.h index de71506f39..e26f6f9c49 100644 --- a/include/SDL3/SDL_time.h +++ b/include/SDL3/SDL_time.h @@ -95,24 +95,24 @@ typedef enum SDL_TimeFormat * format, may be NULL. * \param timeFormat a pointer to the SDL_TimeFormat to hold the returned time * format, may be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat); /** * Gets the current value of the system realtime clock in nanoseconds since * Jan 1, 1970 in Universal Coordinated Time (UTC). * * \param ticks the SDL_Time to hold the returned tick count. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentTime(SDL_Time *ticks); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetCurrentTime(SDL_Time *ticks); /** * Converts an SDL_Time in nanoseconds since the epoch to a calendar time in @@ -123,12 +123,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCurrentTime(SDL_Time *ticks); * \param localTime the resulting SDL_DateTime will be expressed in local time * if true, otherwise it will be in Universal Coordinated * Time (UTC). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime); /** * Converts a calendar time to an SDL_Time in nanoseconds since the epoch. @@ -138,12 +138,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime * * \param dt the source SDL_DateTime. * \param ticks the resulting SDL_Time. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks); /** * Converts an SDL time into a Windows FILETIME (100-nanosecond intervals @@ -181,7 +181,7 @@ extern SDL_DECLSPEC SDL_Time SDLCALL SDL_TimeFromWindows(Uint32 dwLowDateTime, U * * \param year the year. * \param month the month [1-12]. - * \returns the number of days in the requested month or a negative error code + * \returns the number of days in the requested month or -1 * on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -194,8 +194,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDaysInMonth(int year, int month); * \param year the year component of the date. * \param month the month component of the date. * \param day the day component of the date. - * \returns the day of year [0-365] if the date is valid or a negative error - * code on failure; call SDL_GetError() for more information. + * \returns the day of year [0-365] if the date is valid or -1 + * on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ @@ -207,8 +207,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDayOfYear(int year, int month, int day); * \param year the year component of the date. * \param month the month component of the date. * \param day the day component of the date. - * \returns a value between 0 and 6 (0 being Sunday) if the date is valid or a - * negative error code on failure; call SDL_GetError() for more + * \returns a value between 0 and 6 (0 being Sunday) if the date is valid or -1 + * on failure; call SDL_GetError() for more * information. * * \since This function is available since SDL 3.0.0. diff --git a/include/SDL3/SDL_timer.h b/include/SDL3/SDL_timer.h index 1c7ccff487..b2f58b2fca 100644 --- a/include/SDL3/SDL_timer.h +++ b/include/SDL3/SDL_timer.h @@ -263,14 +263,14 @@ extern SDL_DECLSPEC SDL_TimerID SDLCALL SDL_AddTimerNS(Uint64 interval, SDL_NSTi * Remove a timer created with SDL_AddTimer(). * * \param id the ID of the timer to remove. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_AddTimer */ -extern SDL_DECLSPEC int SDLCALL SDL_RemoveTimer(SDL_TimerID id); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RemoveTimer(SDL_TimerID id); /* Ends C function definitions when using C++ */ diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h index d9cf08fca6..3539148b40 100644 --- a/include/SDL3/SDL_video.h +++ b/include/SDL3/SDL_video.h @@ -348,8 +348,7 @@ typedef enum SDL_GLContextResetNotification /** * Get the number of video drivers compiled into SDL. * - * \returns a number >= 1 on success or a negative error code on failure; call - * SDL_GetError() for more information. + * \returns the number of built in video drivers. * * \since This function is available since SDL 3.0.0. * @@ -476,7 +475,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetDisplayName(SDL_DisplayID displa * * \param displayID the instance ID of the display to query. * \param rect the SDL_Rect structure filled in with the display bounds. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -484,7 +483,7 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetDisplayName(SDL_DisplayID displa * \sa SDL_GetDisplayUsableBounds * \sa SDL_GetDisplays */ -extern SDL_DECLSPEC int SDLCALL SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect); /** * Get the usable desktop area represented by a display, in screen @@ -500,7 +499,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDisplayBounds(SDL_DisplayID displayID, SD * * \param displayID the instance ID of the display to query. * \param rect the SDL_Rect structure filled in with the display bounds. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -508,7 +507,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetDisplayBounds(SDL_DisplayID displayID, SD * \sa SDL_GetDisplayBounds * \sa SDL_GetDisplays */ -extern SDL_DECLSPEC int SDLCALL SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect); /** * Get the orientation of a display when it is unrotated. @@ -599,7 +598,7 @@ extern SDL_DECLSPEC SDL_DisplayMode ** SDLCALL SDL_GetFullscreenDisplayModes(SDL * the search. * \param mode a pointer filled in with the closest display mode equal to or * larger than the desired mode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -607,7 +606,7 @@ extern SDL_DECLSPEC SDL_DisplayMode ** SDLCALL SDL_GetFullscreenDisplayModes(SDL * \sa SDL_GetDisplays * \sa SDL_GetFullscreenDisplayModes */ -extern SDL_DECLSPEC int SDLCALL SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode *mode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode *mode); /** * Get information about the desktop's display mode. @@ -752,7 +751,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetWindowDisplayScale(SDL_Window *window); * borderless fullscreen desktop mode, or one of the fullscreen * modes returned by SDL_GetFullscreenDisplayModes() to set an * exclusive fullscreen mode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -761,7 +760,7 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetWindowDisplayScale(SDL_Window *window); * \sa SDL_SetWindowFullscreen * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode); /** * Query the display mode to use when a window is visible at fullscreen. @@ -1328,14 +1327,14 @@ extern SDL_DECLSPEC SDL_WindowFlags SDLCALL SDL_GetWindowFlags(SDL_Window *windo * * \param window the window to change. * \param title the desired window title in UTF-8 format. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowTitle */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowTitle(SDL_Window *window, const char *title); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowTitle(SDL_Window *window, const char *title); /** * Get the title of a window. @@ -1365,12 +1364,12 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetWindowTitle(SDL_Window *window); * * \param window the window to change. * \param icon an SDL_Surface structure containing the icon for the window. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon); /** * Request that the window's position be set. @@ -1402,7 +1401,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surfac * `SDL_WINDOWPOS_UNDEFINED`. * \param y the y coordinate of the window, or `SDL_WINDOWPOS_CENTERED` or * `SDL_WINDOWPOS_UNDEFINED`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1410,7 +1409,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surfac * \sa SDL_GetWindowPosition * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowPosition(SDL_Window *window, int x, int y); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowPosition(SDL_Window *window, int x, int y); /** * Get the position of a window. @@ -1426,14 +1425,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowPosition(SDL_Window *window, int x, * NULL. * \param y a pointer filled in with the y position of the window, may be * NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetWindowPosition */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *x, int *y); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *x, int *y); /** * Request that the size of a window's client area be set. @@ -1460,7 +1459,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *x * \param window the window to change. * \param w the width of the window, must be > 0. * \param h the height of the window, must be > 0. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1469,7 +1468,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *x * \sa SDL_SetWindowFullscreenMode * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int h); /** * Get the size of a window's client area. @@ -1481,7 +1480,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int * \param window the window to query the width and height from. * \param w a pointer filled in with the width of the window, may be NULL. * \param h a pointer filled in with the height of the window, may be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1490,7 +1489,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int * \sa SDL_GetWindowSizeInPixels * \sa SDL_SetWindowSize */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, int *h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, int *h); /** * Get the safe area for this window. @@ -1505,12 +1504,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSize(SDL_Window *window, int *w, in * \param window the window to query. * \param rect a pointer filled in with the client area that is safe for * interactive content. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSafeArea(SDL_Window *window, SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowSafeArea(SDL_Window *window, SDL_Rect *rect); /** * Request that the aspect ratio of a window's client area be set. @@ -1541,7 +1540,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSafeArea(SDL_Window *window, SDL_Re * limit. * \param max_aspect the maximum aspect ratio of the window, or 0.0f for no * limit. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1549,7 +1548,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSafeArea(SDL_Window *window, SDL_Re * \sa SDL_GetWindowAspectRatio * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowAspectRatio(SDL_Window *window, float min_aspect, float max_aspect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowAspectRatio(SDL_Window *window, float min_aspect, float max_aspect); /** * Get the size of a window's client area. @@ -1559,14 +1558,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowAspectRatio(SDL_Window *window, flo * window, may be NULL. * \param max_aspect a pointer filled in with the maximum aspect ratio of the * window, may be NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetWindowAspectRatio */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowAspectRatio(SDL_Window *window, float *min_aspect, float *max_aspect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowAspectRatio(SDL_Window *window, float *min_aspect, float *max_aspect); /** * Get the size of a window's borders (decorations) around the client area. @@ -1593,14 +1592,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowAspectRatio(SDL_Window *window, flo * border; NULL is permitted. * \param right pointer to variable for storing the size of the right border; * NULL is permitted. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowSize */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window *window, int *top, int *left, int *bottom, int *right); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowBordersSize(SDL_Window *window, int *top, int *left, int *bottom, int *right); /** * Get the size of a window's client area, in pixels. @@ -1610,7 +1609,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window *window, int * NULL. * \param h a pointer to variable for storing the height in pixels, may be * NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1618,7 +1617,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowBordersSize(SDL_Window *window, int * \sa SDL_CreateWindow * \sa SDL_GetWindowSize */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h); /** * Set the minimum size of a window's client area. @@ -1626,7 +1625,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSizeInPixels(SDL_Window *window, in * \param window the window to change. * \param min_w the minimum width of the window, or 0 for no limit. * \param min_h the minimum height of the window, or 0 for no limit. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1634,7 +1633,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSizeInPixels(SDL_Window *window, in * \sa SDL_GetWindowMinimumSize * \sa SDL_SetWindowMaximumSize */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h); /** * Get the minimum size of a window's client area. @@ -1644,7 +1643,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int * NULL. * \param h a pointer filled in with the minimum height of the window, may be * NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1652,7 +1651,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int * \sa SDL_GetWindowMaximumSize * \sa SDL_SetWindowMinimumSize */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int *w, int *h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int *w, int *h); /** * Set the maximum size of a window's client area. @@ -1660,7 +1659,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int * \param window the window to change. * \param max_w the maximum width of the window, or 0 for no limit. * \param max_h the maximum height of the window, or 0 for no limit. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1668,7 +1667,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int * \sa SDL_GetWindowMaximumSize * \sa SDL_SetWindowMinimumSize */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h); /** * Get the maximum size of a window's client area. @@ -1678,7 +1677,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMaximumSize(SDL_Window *window, int * NULL. * \param h a pointer filled in with the maximum height of the window, may be * NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1686,7 +1685,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMaximumSize(SDL_Window *window, int * \sa SDL_GetWindowMinimumSize * \sa SDL_SetWindowMaximumSize */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowMaximumSize(SDL_Window *window, int *w, int *h); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowMaximumSize(SDL_Window *window, int *w, int *h); /** * Set the border state of a window. @@ -1699,14 +1698,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowMaximumSize(SDL_Window *window, int * * \param window the window of which to change the border state. * \param bordered SDL_FALSE to remove border, SDL_TRUE to add border. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowFlags */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowBordered(SDL_Window *window, SDL_bool bordered); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowBordered(SDL_Window *window, SDL_bool bordered); /** * Set the user-resizable state of a window. @@ -1719,14 +1718,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowBordered(SDL_Window *window, SDL_bo * * \param window the window of which to change the resizable state. * \param resizable SDL_TRUE to allow resizing, SDL_FALSE to disallow. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowFlags */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowResizable(SDL_Window *window, SDL_bool resizable); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowResizable(SDL_Window *window, SDL_bool resizable); /** * Set the window to always be above the others. @@ -1737,20 +1736,20 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowResizable(SDL_Window *window, SDL_b * \param window the window of which to change the always on top state. * \param on_top SDL_TRUE to set the window always on top, SDL_FALSE to * disable. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowFlags */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowAlwaysOnTop(SDL_Window *window, SDL_bool on_top); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowAlwaysOnTop(SDL_Window *window, SDL_bool on_top); /** * Show a window. * * \param window the window to show. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1758,20 +1757,20 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowAlwaysOnTop(SDL_Window *window, SDL * \sa SDL_HideWindow * \sa SDL_RaiseWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_ShowWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowWindow(SDL_Window *window); /** * Hide a window. * * \param window the window to hide. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_ShowWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_HideWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HideWindow(SDL_Window *window); /** * Request that a window be raised above other windows and gain the input @@ -1784,12 +1783,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_HideWindow(SDL_Window *window); * the window will have the SDL_WINDOW_INPUT_FOCUS flag set. * * \param window the window to raise. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_RaiseWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RaiseWindow(SDL_Window *window); /** * Request that the window be made as large as possible. @@ -1812,7 +1811,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RaiseWindow(SDL_Window *window); * and Wayland window managers may vary. * * \param window the window to maximize. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1821,7 +1820,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RaiseWindow(SDL_Window *window); * \sa SDL_RestoreWindow * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_MaximizeWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_MaximizeWindow(SDL_Window *window); /** * Request that the window be minimized to an iconic representation. @@ -1836,7 +1835,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_MaximizeWindow(SDL_Window *window); * deny the state change. * * \param window the window to minimize. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1845,7 +1844,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_MaximizeWindow(SDL_Window *window); * \sa SDL_RestoreWindow * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_MinimizeWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_MinimizeWindow(SDL_Window *window); /** * Request that the size and position of a minimized or maximized window be @@ -1861,7 +1860,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_MinimizeWindow(SDL_Window *window); * deny the state change. * * \param window the window to restore. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1870,7 +1869,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_MinimizeWindow(SDL_Window *window); * \sa SDL_MinimizeWindow * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_RestoreWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_RestoreWindow(SDL_Window *window); /** * Request that the window's fullscreen state be changed. @@ -1891,7 +1890,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RestoreWindow(SDL_Window *window); * \param window the window to change. * \param fullscreen SDL_TRUE for fullscreen mode, SDL_FALSE for windowed * mode. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -1900,7 +1899,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_RestoreWindow(SDL_Window *window); * \sa SDL_SetWindowFullscreenMode * \sa SDL_SyncWindow */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window *window, SDL_bool fullscreen); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowFullscreen(SDL_Window *window, SDL_bool fullscreen); /** * Block until any pending window state is finalized. @@ -1916,9 +1915,8 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window *window, SDL_ * * \param window the window for which to wait for the pending state to be * applied. - * \returns 0 on success, a positive value if the operation timed out before - * the window was in the requested state, or a negative error code on - * failure; call SDL_GetError() for more information. + * \returns SDL_TRUE on success or SDL_FALSE if the operation timed out before + * the window was in the requested state. * * \since This function is available since SDL 3.0.0. * @@ -1930,7 +1928,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowFullscreen(SDL_Window *window, SDL_ * \sa SDL_RestoreWindow * \sa SDL_HINT_VIDEO_SYNC_WINDOW_OPERATIONS */ -extern SDL_DECLSPEC int SDLCALL SDL_SyncWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SyncWindow(SDL_Window *window); /** * Return whether the window has a surface associated with it. @@ -1987,14 +1985,14 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_GetWindowSurface(SDL_Window *windo * * \param window the window. * \param vsync the vertical refresh sync interval. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowSurfaceVSync */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowSurfaceVSync(SDL_Window *window, int vsync); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowSurfaceVSync(SDL_Window *window, int vsync); #define SDL_WINDOW_SURFACE_VSYNC_DISABLED 0 #define SDL_WINDOW_SURFACE_VSYNC_ADAPTIVE (-1) @@ -2005,14 +2003,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowSurfaceVSync(SDL_Window *window, in * \param window the window to query. * \param vsync an int filled with the current vertical refresh sync interval. * See SDL_SetWindowSurfaceVSync() for the meaning of the value. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_SetWindowSurfaceVSync */ -extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSurfaceVSync(SDL_Window *window, int *vsync); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowSurfaceVSync(SDL_Window *window, int *vsync); /** * Copy the window surface to the screen. @@ -2023,7 +2021,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSurfaceVSync(SDL_Window *window, in * This function is equivalent to the SDL 1.2 API SDL_Flip(). * * \param window the window to update. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2031,7 +2029,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetWindowSurfaceVSync(SDL_Window *window, in * \sa SDL_GetWindowSurface * \sa SDL_UpdateWindowSurfaceRects */ -extern SDL_DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateWindowSurface(SDL_Window *window); /** * Copy areas of the window surface to the screen. @@ -2050,7 +2048,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window *window); * \param rects an array of SDL_Rect structures representing areas of the * surface to copy, in pixels. * \param numrects the number of rectangles. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2058,13 +2056,13 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateWindowSurface(SDL_Window *window); * \sa SDL_GetWindowSurface * \sa SDL_UpdateWindowSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window *window, const SDL_Rect *rects, int numrects); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window *window, const SDL_Rect *rects, int numrects); /** * Destroy the surface associated with the window. * * \param window the window to update. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2072,7 +2070,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_UpdateWindowSurfaceRects(SDL_Window *window, * \sa SDL_GetWindowSurface * \sa SDL_WindowHasSurface */ -extern SDL_DECLSPEC int SDLCALL SDL_DestroyWindowSurface(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_DestroyWindowSurface(SDL_Window *window); /** * Set a window's keyboard grab mode. @@ -2095,7 +2093,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_DestroyWindowSurface(SDL_Window *window); * * \param window the window for which the keyboard grab mode should be set. * \param grabbed this is SDL_TRUE to grab keyboard, and SDL_FALSE to release. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2103,7 +2101,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_DestroyWindowSurface(SDL_Window *window); * \sa SDL_GetWindowKeyboardGrab * \sa SDL_SetWindowMouseGrab */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowKeyboardGrab(SDL_Window *window, SDL_bool grabbed); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowKeyboardGrab(SDL_Window *window, SDL_bool grabbed); /** * Set a window's mouse grab mode. @@ -2112,7 +2110,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowKeyboardGrab(SDL_Window *window, SD * * \param window the window for which the mouse grab mode should be set. * \param grabbed this is SDL_TRUE to grab mouse, and SDL_FALSE to release. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2120,7 +2118,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowKeyboardGrab(SDL_Window *window, SD * \sa SDL_GetWindowMouseGrab * \sa SDL_SetWindowKeyboardGrab */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMouseGrab(SDL_Window *window, SDL_bool grabbed); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowMouseGrab(SDL_Window *window, SDL_bool grabbed); /** * Get a window's keyboard grab mode. @@ -2167,7 +2165,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetGrabbedWindow(void); * \param window the window that will be associated with the barrier. * \param rect a rectangle area in window-relative coordinates. If NULL the * barrier for the specified window will be destroyed. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2175,7 +2173,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetGrabbedWindow(void); * \sa SDL_GetWindowMouseRect * \sa SDL_SetWindowMouseGrab */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowMouseRect(SDL_Window *window, const SDL_Rect *rect); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowMouseRect(SDL_Window *window, const SDL_Rect *rect); /** * Get the mouse confinement rectangle of a window. @@ -2200,14 +2198,14 @@ extern SDL_DECLSPEC const SDL_Rect * SDLCALL SDL_GetWindowMouseRect(SDL_Window * * * \param window the window which will be made transparent or opaque. * \param opacity the opacity value (0.0f - transparent, 1.0f - opaque). - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GetWindowOpacity */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowOpacity(SDL_Window *window, float opacity); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowOpacity(SDL_Window *window, float opacity); /** * Get the opacity of a window. @@ -2216,8 +2214,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowOpacity(SDL_Window *window, float o * as 1.0f without error. * * \param window the window to get the current opacity value from. - * \returns the opacity, (0.0f - transparent, 1.0f - opaque), or a negative - * error code on failure; call SDL_GetError() for more information. + * \returns the opacity, (0.0f - transparent, 1.0f - opaque), or -1.0f on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * @@ -2237,12 +2234,12 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetWindowOpacity(SDL_Window *window); * * \param modal_window the window that should be set modal. * \param parent_window the parent window for the modal window. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window); /** * Set whether the window may have input focus. @@ -2250,12 +2247,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowModalFor(SDL_Window *modal_window, * \param window the window to set focusable state. * \param focusable SDL_TRUE to allow input focus, SDL_FALSE to not allow * input focus. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable); /** @@ -2274,12 +2271,12 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowFocusable(SDL_Window *window, SDL_b * the client area. * \param y the y coordinate of the menu, relative to the origin (top-left) of * the client area. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_ShowWindowSystemMenu(SDL_Window *window, int x, int y); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowWindowSystemMenu(SDL_Window *window, int x, int y); /** * Possible return values from the SDL_HitTest callback. @@ -2337,7 +2334,7 @@ typedef SDL_HitTestResult (SDLCALL *SDL_HitTest)(SDL_Window *win, * Specifying NULL for a callback disables hit-testing. Hit-testing is * disabled by default. * - * Platforms that don't support this functionality will return -1 + * Platforms that don't support this functionality will return SDL_FALSE * unconditionally, even if you're attempting to disable hit-testing. * * Your callback may fire at any time, and its firing does not indicate any @@ -2351,12 +2348,12 @@ typedef SDL_HitTestResult (SDLCALL *SDL_HitTest)(SDL_Window *win, * \param window the window to set hit-testing on. * \param callback the function to call when doing a hit-test. * \param callback_data an app-defined void pointer passed to **callback**. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callback_data); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callback_data); /** * Set the shape of a transparent window. @@ -2375,24 +2372,24 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowHitTest(SDL_Window *window, SDL_Hit * \param window the window. * \param shape the surface representing the shape of the window, or NULL to * remove any current shape. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape); /** * Request a window to demand attention from the user. * * \param window the window to be flashed. * \param operation the operation to perform. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_FlashWindow(SDL_Window *window, SDL_FlashOperation operation); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_FlashWindow(SDL_Window *window, SDL_FlashOperation operation); /** * Destroy a window. @@ -2431,7 +2428,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ScreenSaverEnabled(void); /** * Allow the screen to be blanked by a screen saver. * - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2439,7 +2436,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_ScreenSaverEnabled(void); * \sa SDL_DisableScreenSaver * \sa SDL_ScreenSaverEnabled */ -extern SDL_DECLSPEC int SDLCALL SDL_EnableScreenSaver(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EnableScreenSaver(void); /** * Prevent the screen from being blanked by a screen saver. @@ -2450,7 +2447,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_EnableScreenSaver(void); * The screensaver is disabled by default, but this may by changed by * SDL_HINT_VIDEO_ALLOW_SCREENSAVER. * - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2458,7 +2455,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_EnableScreenSaver(void); * \sa SDL_EnableScreenSaver * \sa SDL_ScreenSaverEnabled */ -extern SDL_DECLSPEC int SDLCALL SDL_DisableScreenSaver(void); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_DisableScreenSaver(void); /** @@ -2478,7 +2475,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_DisableScreenSaver(void); * * \param path the platform dependent OpenGL library name, or NULL to open the * default OpenGL library. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2486,7 +2483,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_DisableScreenSaver(void); * \sa SDL_GL_GetProcAddress * \sa SDL_GL_UnloadLibrary */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_LoadLibrary(const char *path); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_LoadLibrary(const char *path); /** * Get an OpenGL function by name. @@ -2609,7 +2606,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GL_ResetAttributes(void); * \param attr an SDL_GLattr enum value specifying the OpenGL attribute to * set. * \param value the desired value for the attribute. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2617,7 +2614,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_GL_ResetAttributes(void); * \sa SDL_GL_GetAttribute * \sa SDL_GL_ResetAttributes */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); /** * Get the actual value for an attribute from the current context. @@ -2625,7 +2622,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); * \param attr an SDL_GLattr enum value specifying the OpenGL attribute to * get. * \param value a pointer filled in with the current value of `attr`. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -2633,7 +2630,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value); * \sa SDL_GL_ResetAttributes * \sa SDL_GL_SetAttribute */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value); /** * Create an OpenGL context for an OpenGL window, and make it current. @@ -2664,14 +2661,14 @@ extern SDL_DECLSPEC SDL_GLContext SDLCALL SDL_GL_CreateContext(SDL_Window *windo * * \param window the window to associate with the context. * \param context the OpenGL context to associate with the window. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GL_CreateContext */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context); /** * Get the currently active OpenGL window. @@ -2760,7 +2757,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_EGL_SetAttributeCallbacks(SDL_EGLAttribArra * the vertical retrace for a given frame, it swaps buffers immediately, which * might be less jarring for the user during occasional framerate drops. If an * application requests adaptive vsync and the system does not support it, - * this function will fail and return -1. In such a case, you should probably + * this function will fail and return SDL_FALSE. In such a case, you should probably * retry the call with 1 for the interval. * * Adaptive vsync is implemented for some glX drivers with @@ -2772,14 +2769,14 @@ extern SDL_DECLSPEC void SDLCALL SDL_EGL_SetAttributeCallbacks(SDL_EGLAttribArra * * \param interval 0 for immediate updates, 1 for updates synchronized with * the vertical retrace, -1 for adaptive vsync. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GL_GetSwapInterval */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_SetSwapInterval(int interval); /** * Get the swap interval for the current OpenGL context. @@ -2791,14 +2788,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GL_SetSwapInterval(int interval); * synchronization, 1 if the buffer swap is synchronized with * the vertical retrace, and -1 if late swaps happen * immediately instead of waiting for the next retrace. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GL_SetSwapInterval */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(int *interval); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_GetSwapInterval(int *interval); /** * Update a window with OpenGL rendering. @@ -2811,25 +2808,25 @@ extern SDL_DECLSPEC int SDLCALL SDL_GL_GetSwapInterval(int *interval); * extra. * * \param window the window to change. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_SwapWindow(SDL_Window *window); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_SwapWindow(SDL_Window *window); /** * Delete an OpenGL context. * * \param context the OpenGL context to be deleted. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. * * \sa SDL_GL_CreateContext */ -extern SDL_DECLSPEC int SDLCALL SDL_GL_DestroyContext(SDL_GLContext context); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GL_DestroyContext(SDL_GLContext context); /* @} *//* OpenGL support functions */ diff --git a/include/SDL3/SDL_vulkan.h b/include/SDL3/SDL_vulkan.h index 6dd05375f6..d724e19a6d 100644 --- a/include/SDL3/SDL_vulkan.h +++ b/include/SDL3/SDL_vulkan.h @@ -95,7 +95,7 @@ struct VkAllocationCallbacks; * library version. * * \param path the platform dependent Vulkan loader library name or NULL. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -103,7 +103,7 @@ struct VkAllocationCallbacks; * \sa SDL_Vulkan_GetVkGetInstanceProcAddr * \sa SDL_Vulkan_UnloadLibrary */ -extern SDL_DECLSPEC int SDLCALL SDL_Vulkan_LoadLibrary(const char *path); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_LoadLibrary(const char *path); /** * Get the address of the `vkGetInstanceProcAddr` function. @@ -175,7 +175,7 @@ extern SDL_DECLSPEC char const * const * SDLCALL SDL_Vulkan_GetInstanceExtension * allocator that creates the surface. Can be NULL. * \param surface a pointer to a VkSurfaceKHR handle to output the newly * created surface. - * \returns 0 on success or a negative error code on failure; call + * \returns SDL_TRUE on success or SDL_FALSE on failure; call * SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. @@ -183,10 +183,10 @@ extern SDL_DECLSPEC char const * const * SDLCALL SDL_Vulkan_GetInstanceExtension * \sa SDL_Vulkan_GetInstanceExtensions * \sa SDL_Vulkan_DestroySurface */ -extern SDL_DECLSPEC int SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window, - VkInstance instance, - const struct VkAllocationCallbacks *allocator, - VkSurfaceKHR* surface); +extern SDL_DECLSPEC SDL_bool SDLCALL SDL_Vulkan_CreateSurface(SDL_Window *window, + VkInstance instance, + const struct VkAllocationCallbacks *allocator, + VkSurfaceKHR* surface); /** * Destroy the Vulkan rendering surface of a window. diff --git a/src/SDL.c b/src/SDL.c index 44d0da679d..ef1d815d42 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -59,8 +59,8 @@ // Initialization/Cleanup routines #include "timer/SDL_timer_c.h" #ifdef SDL_VIDEO_DRIVER_WINDOWS -extern int SDL_HelperWindowCreate(void); -extern int SDL_HelperWindowDestroy(void); +extern bool SDL_HelperWindowCreate(void); +extern void SDL_HelperWindowDestroy(void); #endif #ifdef SDL_BUILD_MAJOR_VERSION @@ -109,12 +109,12 @@ SDL_NORETURN void SDL_ExitProcess(int exitcode) // App metadata -int SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier) +SDL_bool SDL_SetAppMetadata(const char *appname, const char *appversion, const char *appidentifier) { SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING, appname); SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_VERSION_STRING, appversion); SDL_SetAppMetadataProperty(SDL_PROP_APP_METADATA_IDENTIFIER_STRING, appidentifier); - return 0; + return true; } static bool SDL_ValidMetadataProperty(const char *name) @@ -135,7 +135,7 @@ static bool SDL_ValidMetadataProperty(const char *name) return false; } -int SDL_SetAppMetadataProperty(const char *name, const char *value) +SDL_bool SDL_SetAppMetadataProperty(const char *name, const char *value) { if (!SDL_ValidMetadataProperty(name)) { return SDL_InvalidParamError("name"); @@ -238,7 +238,7 @@ static bool SDL_InitOrIncrementSubsystem(Uint32 subsystem) ++SDL_SubsystemRefCount[subsystem_index]; return true; } - return SDL_InitSubSystem(subsystem) == 0; + return SDL_InitSubSystem(subsystem); } void SDL_SetMainReady(void) @@ -268,7 +268,7 @@ static void SDL_QuitMainThread(void) SDL_QuitTLSData(); } -int SDL_InitSubSystem(SDL_InitFlags flags) +SDL_bool SDL_InitSubSystem(SDL_InitFlags flags) { Uint32 flags_initialized = 0; @@ -284,7 +284,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) #ifdef SDL_VIDEO_DRIVER_WINDOWS if (flags & (SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK)) { - if (SDL_HelperWindowCreate() < 0) { + if (!SDL_HelperWindowCreate()) { goto quit_and_error; } } @@ -294,7 +294,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) if (flags & SDL_INIT_EVENTS) { if (SDL_ShouldInitSubsystem(SDL_INIT_EVENTS)) { SDL_IncrementSubsystemRefCount(SDL_INIT_EVENTS); - if (SDL_InitEvents() < 0) { + if (!SDL_InitEvents()) { SDL_DecrementSubsystemRefCount(SDL_INIT_EVENTS); goto quit_and_error; } @@ -308,7 +308,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) if (flags & SDL_INIT_TIMER) { if (SDL_ShouldInitSubsystem(SDL_INIT_TIMER)) { SDL_IncrementSubsystemRefCount(SDL_INIT_TIMER); - if (SDL_InitTimers() < 0) { + if (!SDL_InitTimers()) { SDL_DecrementSubsystemRefCount(SDL_INIT_TIMER); goto quit_and_error; } @@ -328,7 +328,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) } SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO); - if (SDL_VideoInit(NULL) < 0) { + if (!SDL_VideoInit(NULL)) { SDL_DecrementSubsystemRefCount(SDL_INIT_VIDEO); goto quit_and_error; } @@ -352,7 +352,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) } SDL_IncrementSubsystemRefCount(SDL_INIT_AUDIO); - if (SDL_InitAudio(NULL) < 0) { + if (!SDL_InitAudio(NULL)) { SDL_DecrementSubsystemRefCount(SDL_INIT_AUDIO); goto quit_and_error; } @@ -376,7 +376,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) } SDL_IncrementSubsystemRefCount(SDL_INIT_JOYSTICK); - if (SDL_InitJoysticks() < 0) { + if (!SDL_InitJoysticks()) { SDL_DecrementSubsystemRefCount(SDL_INIT_JOYSTICK); goto quit_and_error; } @@ -399,7 +399,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) } SDL_IncrementSubsystemRefCount(SDL_INIT_GAMEPAD); - if (SDL_InitGamepads() < 0) { + if (!SDL_InitGamepads()) { SDL_DecrementSubsystemRefCount(SDL_INIT_GAMEPAD); goto quit_and_error; } @@ -418,7 +418,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) #ifndef SDL_HAPTIC_DISABLED if (SDL_ShouldInitSubsystem(SDL_INIT_HAPTIC)) { SDL_IncrementSubsystemRefCount(SDL_INIT_HAPTIC); - if (SDL_InitHaptics() < 0) { + if (!SDL_InitHaptics()) { SDL_DecrementSubsystemRefCount(SDL_INIT_HAPTIC); goto quit_and_error; } @@ -437,7 +437,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) #ifndef SDL_SENSOR_DISABLED if (SDL_ShouldInitSubsystem(SDL_INIT_SENSOR)) { SDL_IncrementSubsystemRefCount(SDL_INIT_SENSOR); - if (SDL_InitSensors() < 0) { + if (!SDL_InitSensors()) { SDL_DecrementSubsystemRefCount(SDL_INIT_SENSOR); goto quit_and_error; } @@ -461,7 +461,7 @@ int SDL_InitSubSystem(SDL_InitFlags flags) } SDL_IncrementSubsystemRefCount(SDL_INIT_CAMERA); - if (SDL_CameraInit(NULL) < 0) { + if (!SDL_CameraInit(NULL)) { SDL_DecrementSubsystemRefCount(SDL_INIT_CAMERA); goto quit_and_error; } @@ -481,10 +481,10 @@ int SDL_InitSubSystem(SDL_InitFlags flags) quit_and_error: SDL_QuitSubSystem(flags_initialized); - return -1; + return false; } -int SDL_Init(SDL_InitFlags flags) +SDL_bool SDL_Init(SDL_InitFlags flags) { return SDL_InitSubSystem(flags); } diff --git a/src/SDL_assert.c b/src/SDL_assert.c index c80f3fd1d5..95d2122373 100644 --- a/src/SDL_assert.c +++ b/src/SDL_assert.c @@ -238,7 +238,7 @@ static SDL_AssertState SDLCALL SDL_PromptAssertion(const SDL_AssertData *data, v messagebox.numbuttons = SDL_arraysize(buttons); messagebox.buttons = buttons; - if (SDL_ShowMessageBox(&messagebox, &selected) == 0) { + if (SDL_ShowMessageBox(&messagebox, &selected)) { if (selected == -1) { state = SDL_ASSERTION_IGNORE; } else { diff --git a/src/SDL_error.c b/src/SDL_error.c index 5dff9c8fdf..78943e6677 100644 --- a/src/SDL_error.c +++ b/src/SDL_error.c @@ -24,7 +24,7 @@ #include "SDL_error_c.h" -int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) +SDL_bool SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { // Ignore call if invalid format pointer was passed if (fmt) { @@ -56,7 +56,7 @@ int SDL_SetError(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) } } - return -1; + return false; } const char *SDL_GetError(void) @@ -77,23 +77,23 @@ const char *SDL_GetError(void) } } -int SDL_ClearError(void) +SDL_bool SDL_ClearError(void) { SDL_error *error = SDL_GetErrBuf(false); if (error) { error->error = SDL_ErrorCodeNone; } - return 0; + return true; } -int SDL_OutOfMemory(void) +SDL_bool SDL_OutOfMemory(void) { SDL_error *error = SDL_GetErrBuf(true); if (error) { error->error = SDL_ErrorCodeOutOfMemory; } - return -1; + return false; } diff --git a/src/SDL_hints.c b/src/SDL_hints.c index ba11022e79..a3593051cd 100644 --- a/src/SDL_hints.c +++ b/src/SDL_hints.c @@ -66,7 +66,7 @@ static void SDLCALL CleanupHintProperty(void *userdata, void *value) SDL_free(hint); } -int SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority) +SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority) { if (!name || !*name) { return SDL_InvalidParamError("name"); @@ -79,10 +79,10 @@ int SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriorit const SDL_PropertiesID hints = GetHintProperties(true); if (!hints) { - return -1; + return false; } - int retval = -1; + bool result = false; SDL_LockProperties(hints); @@ -103,7 +103,7 @@ int SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriorit SDL_free(old_value); } hint->priority = priority; - retval = 0; + result = true; } } else { // Couldn't find the hint? Add a new one. hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); @@ -111,16 +111,16 @@ int SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriorit hint->value = value ? SDL_strdup(value) : NULL; hint->priority = priority; hint->callbacks = NULL; - retval = (SDL_SetPointerPropertyWithCleanup(hints, name, hint, CleanupHintProperty, NULL) != -1); + result = SDL_SetPointerPropertyWithCleanup(hints, name, hint, CleanupHintProperty, NULL); } } SDL_UnlockProperties(hints); - return retval; + return result; } -int SDL_ResetHint(const char *name) +SDL_bool SDL_ResetHint(const char *name) { if (!name || !*name) { return SDL_InvalidParamError("name"); @@ -130,10 +130,10 @@ int SDL_ResetHint(const char *name) const SDL_PropertiesID hints = GetHintProperties(false); if (!hints) { - return -1; + return false; } - int retval = -1; + bool result = false; SDL_LockProperties(hints); @@ -150,12 +150,12 @@ int SDL_ResetHint(const char *name) SDL_free(hint->value); hint->value = NULL; hint->priority = SDL_HINT_DEFAULT; - retval = 0; + result = true; } SDL_UnlockProperties(hints); - return retval; + return result; } static void SDLCALL ResetHintsCallback(void *userdata, SDL_PropertiesID hints, const char *name) @@ -185,7 +185,7 @@ void SDL_ResetHints(void) SDL_EnumerateProperties(GetHintProperties(false), ResetHintsCallback, NULL); } -int SDL_SetHint(const char *name, const char *value) +SDL_bool SDL_SetHint(const char *name, const char *value) { return SDL_SetHintWithPriority(name, value, SDL_HINT_NORMAL); } @@ -196,7 +196,7 @@ const char *SDL_GetHint(const char *name) return NULL; } - const char *retval = SDL_getenv(name); + const char *result = SDL_getenv(name); const SDL_PropertiesID hints = GetHintProperties(false); if (hints) { @@ -204,15 +204,15 @@ const char *SDL_GetHint(const char *name) SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL); if (hint) { - if (!retval || hint->priority == SDL_HINT_OVERRIDE) { - retval = SDL_GetPersistentString(hint->value); + if (!result || hint->priority == SDL_HINT_OVERRIDE) { + result = SDL_GetPersistentString(hint->value); } } SDL_UnlockProperties(hints); } - return retval; + return result; } int SDL_GetStringInteger(const char *value, int default_value) @@ -249,7 +249,7 @@ SDL_bool SDL_GetHintBoolean(const char *name, SDL_bool default_value) return SDL_GetStringBoolean(hint, default_value); } -int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata) +SDL_bool SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata) { if (!name || !*name) { return SDL_InvalidParamError("name"); @@ -259,17 +259,17 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd const SDL_PropertiesID hints = GetHintProperties(true); if (!hints) { - return -1; + return false; } SDL_HintWatch *entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry)); if (!entry) { - return -1; + return false; } entry->callback = callback; entry->userdata = userdata; - int retval = -1; + bool result = false; SDL_LockProperties(hints); @@ -277,18 +277,18 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd SDL_Hint *hint = SDL_GetPointerProperty(hints, name, NULL); if (hint) { - retval = 0; + result = true; } else { // Need to add a hint entry for this watcher hint = (SDL_Hint *)SDL_malloc(sizeof(*hint)); if (!hint) { SDL_free(entry); SDL_UnlockProperties(hints); - return -1; + return false; } else { hint->value = NULL; hint->priority = SDL_HINT_DEFAULT; hint->callbacks = NULL; - retval = SDL_SetPointerPropertyWithCleanup(hints, name, hint, CleanupHintProperty, NULL); + result = SDL_SetPointerPropertyWithCleanup(hints, name, hint, CleanupHintProperty, NULL); } } @@ -302,7 +302,7 @@ int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userd SDL_UnlockProperties(hints); - return retval; + return result; } void SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata) diff --git a/src/SDL_internal.h b/src/SDL_internal.h index d09e93a1ed..469b050210 100644 --- a/src/SDL_internal.h +++ b/src/SDL_internal.h @@ -302,8 +302,8 @@ extern void SDL_InitMainThread(void); /* The internal implementations of these functions have up to nanosecond precision. We can expose these functions as part of the API if we want to later. */ -extern int SDLCALL SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS); -extern int SDLCALL SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS); +extern SDL_bool SDLCALL SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS); +extern SDL_bool SDLCALL SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS); extern SDL_bool SDLCALL SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS); // Ends C function definitions when using C++ diff --git a/src/SDL_list.c b/src/SDL_list.c index b6c689ba27..d66cf0a8fa 100644 --- a/src/SDL_list.c +++ b/src/SDL_list.c @@ -23,18 +23,18 @@ #include "./SDL_list.h" // Push -int SDL_ListAdd(SDL_ListNode **head, void *ent) +bool SDL_ListAdd(SDL_ListNode **head, void *ent) { SDL_ListNode *node = (SDL_ListNode *)SDL_malloc(sizeof(*node)); if (!node) { - return -1; + return false; } node->entry = ent; node->next = *head; *head = node; - return 0; + return true; } // Pop from end as a FIFO (if add with SDL_ListAdd) diff --git a/src/SDL_list.h b/src/SDL_list.h index 3834e9af7b..aa2de3bb8f 100644 --- a/src/SDL_list.h +++ b/src/SDL_list.h @@ -28,7 +28,7 @@ typedef struct SDL_ListNode struct SDL_ListNode *next; } SDL_ListNode; -int SDL_ListAdd(SDL_ListNode **head, void *ent); +bool SDL_ListAdd(SDL_ListNode **head, void *ent); void SDL_ListPop(SDL_ListNode **head, void **ent); void SDL_ListRemove(SDL_ListNode **head, void *ent); void SDL_ListClear(SDL_ListNode **head); diff --git a/src/SDL_log.c b/src/SDL_log.c index 342ed8521a..c4be4483f9 100644 --- a/src/SDL_log.c +++ b/src/SDL_log.c @@ -338,7 +338,7 @@ static const char *SDL_GetLogPriorityPrefix(SDL_LogPriority priority) } } -int SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix) +SDL_bool SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix) { if (priority < SDL_LOG_PRIORITY_VERBOSE || priority >= SDL_NUM_LOG_PRIORITIES) { return SDL_InvalidParamError("priority"); @@ -349,11 +349,11 @@ int SDL_SetLogPriorityPrefix(SDL_LogPriority priority, const char *prefix) } else { prefix = SDL_GetPersistentString(prefix); if (!prefix) { - return -1; + return false; } } SDL_priority_prefixes[priority] = prefix; - return 0; + return true; } void SDL_Log(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) diff --git a/src/SDL_properties.c b/src/SDL_properties.c index bca4824709..78997d7ddf 100644 --- a/src/SDL_properties.c +++ b/src/SDL_properties.c @@ -97,21 +97,21 @@ static void SDL_FreeProperties(const void *key, const void *value, void *data) } } -int SDL_InitProperties(void) +bool SDL_InitProperties(void) { if (!SDL_properties_lock) { SDL_properties_lock = SDL_CreateMutex(); if (!SDL_properties_lock) { - return -1; + return false; } } if (!SDL_properties) { SDL_properties = SDL_CreateHashTable(NULL, 16, SDL_HashID, SDL_KeyMatchID, SDL_FreeProperties, false); if (!SDL_properties) { - return -1; + return false; } } - return 0; + return true; } void SDL_QuitProperties(void) @@ -144,7 +144,7 @@ SDL_PropertiesID SDL_CreateProperties(void) SDL_Properties *properties = NULL; bool inserted = false; - if (!SDL_properties && SDL_InitProperties() < 0) { + if (!SDL_properties && !SDL_InitProperties()) { return 0; } @@ -161,7 +161,7 @@ SDL_PropertiesID SDL_CreateProperties(void) goto error; } - if (SDL_InitProperties() < 0) { + if (!SDL_InitProperties()) { goto error; } @@ -186,11 +186,11 @@ error: return 0; } -int SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst) +SDL_bool SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst) { SDL_Properties *src_properties = NULL; SDL_Properties *dst_properties = NULL; - int result = 0; + bool result = true; if (!src) { return SDL_InvalidParamError("src"); @@ -233,13 +233,13 @@ int SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst) dst_name = SDL_strdup(src_name); if (!dst_name) { - result = -1; + result = false; continue; } dst_property = (SDL_Property *)SDL_malloc(sizeof(*dst_property)); if (!dst_property) { SDL_free(dst_name); - result = -1; + result = false; continue; } SDL_copyp(dst_property, src_property); @@ -248,7 +248,7 @@ int SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst) } if (!SDL_InsertIntoHashTable(dst_properties->props, dst_name, dst_property)) { SDL_FreePropertyWithCleanup(dst_name, dst_property, NULL, false); - result = -1; + result = false; } } } @@ -258,7 +258,7 @@ int SDL_CopyProperties(SDL_PropertiesID src, SDL_PropertiesID dst) return result; } -int SDL_LockProperties(SDL_PropertiesID props) +SDL_bool SDL_LockProperties(SDL_PropertiesID props) { SDL_Properties *properties = NULL; @@ -275,7 +275,7 @@ int SDL_LockProperties(SDL_PropertiesID props) } SDL_LockMutex(properties->lock); - return 0; + return true; } void SDL_UnlockProperties(SDL_PropertiesID props) @@ -297,10 +297,10 @@ void SDL_UnlockProperties(SDL_PropertiesID props) SDL_UnlockMutex(properties->lock); } -static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_Property *property) +static SDL_bool SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_Property *property) { SDL_Properties *properties = NULL; - int result = 0; + bool result = true; if (!props) { SDL_FreePropertyWithCleanup(NULL, property, NULL, true); @@ -327,7 +327,7 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_ char *key = SDL_strdup(name); if (!SDL_InsertIntoHashTable(properties->props, key, property)) { SDL_FreePropertyWithCleanup(key, property, NULL, true); - result = -1; + result = false; } } } @@ -336,7 +336,7 @@ static int SDL_PrivateSetProperty(SDL_PropertiesID props, const char *name, SDL_ return result; } -int SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata) +SDL_bool SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, void *value, SDL_CleanupPropertyCallback cleanup, void *userdata) { SDL_Property *property; @@ -353,7 +353,7 @@ int SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, cleanup(userdata, value); } SDL_FreePropertyWithCleanup(NULL, property, NULL, false); - return -1; + return false; } property->type = SDL_PROPERTY_TYPE_POINTER; property->value.pointer_value = value; @@ -362,7 +362,7 @@ int SDL_SetPointerPropertyWithCleanup(SDL_PropertiesID props, const char *name, return SDL_PrivateSetProperty(props, name, property); } -int SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value) +SDL_bool SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value) { SDL_Property *property; @@ -372,7 +372,7 @@ int SDL_SetPointerProperty(SDL_PropertiesID props, const char *name, void *value property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return -1; + return false; } property->type = SDL_PROPERTY_TYPE_POINTER; property->value.pointer_value = value; @@ -384,7 +384,7 @@ static void SDLCALL CleanupFreeableProperty(void *userdata, void *value) SDL_free(value); } -int SDL_SetFreeableProperty(SDL_PropertiesID props, const char *name, void *value) +bool SDL_SetFreeableProperty(SDL_PropertiesID props, const char *name, void *value) { return SDL_SetPointerPropertyWithCleanup(props, name, value, CleanupFreeableProperty, NULL); } @@ -396,12 +396,12 @@ static void SDLCALL CleanupSurface(void *userdata, void *value) SDL_DestroySurface(surface); } -int SDL_SetSurfaceProperty(SDL_PropertiesID props, const char *name, SDL_Surface *surface) +bool SDL_SetSurfaceProperty(SDL_PropertiesID props, const char *name, SDL_Surface *surface) { return SDL_SetPointerPropertyWithCleanup(props, name, surface, CleanupSurface, NULL); } -int SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value) +SDL_bool SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char *value) { SDL_Property *property; @@ -411,44 +411,44 @@ int SDL_SetStringProperty(SDL_PropertiesID props, const char *name, const char * property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return -1; + return false; } property->type = SDL_PROPERTY_TYPE_STRING; property->value.string_value = SDL_strdup(value); if (!property->value.string_value) { SDL_free(property); - return -1; + return false; } return SDL_PrivateSetProperty(props, name, property); } -int SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value) +SDL_bool SDL_SetNumberProperty(SDL_PropertiesID props, const char *name, Sint64 value) { SDL_Property *property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return -1; + return false; } property->type = SDL_PROPERTY_TYPE_NUMBER; property->value.number_value = value; return SDL_PrivateSetProperty(props, name, property); } -int SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value) +SDL_bool SDL_SetFloatProperty(SDL_PropertiesID props, const char *name, float value) { SDL_Property *property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return -1; + return false; } property->type = SDL_PROPERTY_TYPE_FLOAT; property->value.float_value = value; return SDL_PrivateSetProperty(props, name, property); } -int SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value) +SDL_bool SDL_SetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bool value) { SDL_Property *property = (SDL_Property *)SDL_calloc(1, sizeof(*property)); if (!property) { - return -1; + return false; } property->type = SDL_PROPERTY_TYPE_BOOLEAN; property->value.boolean_value = value ? true : false; @@ -732,12 +732,12 @@ SDL_bool SDL_GetBooleanProperty(SDL_PropertiesID props, const char *name, SDL_bo return value; } -int SDL_ClearProperty(SDL_PropertiesID props, const char *name) +SDL_bool SDL_ClearProperty(SDL_PropertiesID props, const char *name) { return SDL_PrivateSetProperty(props, name, NULL); } -int SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata) +SDL_bool SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallback callback, void *userdata) { SDL_Properties *properties = NULL; @@ -768,7 +768,7 @@ int SDL_EnumerateProperties(SDL_PropertiesID props, SDL_EnumeratePropertiesCallb } SDL_UnlockMutex(properties->lock); - return 0; + return true; } static void SDLCALL SDL_DumpPropertiesCallback(void *userdata, SDL_PropertiesID props, const char *name) @@ -798,7 +798,7 @@ static void SDLCALL SDL_DumpPropertiesCallback(void *userdata, SDL_PropertiesID } } -int SDL_DumpProperties(SDL_PropertiesID props) +bool SDL_DumpProperties(SDL_PropertiesID props) { return SDL_EnumerateProperties(props, SDL_DumpPropertiesCallback, NULL); } diff --git a/src/SDL_properties_c.h b/src/SDL_properties_c.h index fbbb7cce5c..b0a426b5cc 100644 --- a/src/SDL_properties_c.h +++ b/src/SDL_properties_c.h @@ -19,8 +19,8 @@ 3. This notice may not be removed or altered from any source distribution. */ -extern int SDL_InitProperties(void); -extern int SDL_SetFreeableProperty(SDL_PropertiesID props, const char *name, void *value); -extern int SDL_SetSurfaceProperty(SDL_PropertiesID props, const char *name, SDL_Surface *surface); -extern int SDL_DumpProperties(SDL_PropertiesID props); +extern bool SDL_InitProperties(void); +extern bool SDL_SetFreeableProperty(SDL_PropertiesID props, const char *name, void *value); +extern bool SDL_SetSurfaceProperty(SDL_PropertiesID props, const char *name, SDL_Surface *surface); +extern bool SDL_DumpProperties(SDL_PropertiesID props); extern void SDL_QuitProperties(void); diff --git a/src/SDL_utils.c b/src/SDL_utils.c index 76d0e2da32..0af6460e9e 100644 --- a/src/SDL_utils.c +++ b/src/SDL_utils.c @@ -53,6 +53,14 @@ int SDL_powerof2(int x) return value; } +Uint32 SDL_CalculateGCD(Uint32 a, Uint32 b) +{ + if (b == 0) { + return a; + } + return SDL_CalculateGCD(b, (a % b)); +} + // Algorithm adapted with thanks from John Cook's blog post: // http://www.johndcook.com/blog/2010/10/20/best-rational-approximation void SDL_CalculateFraction(float x, int *numerator, int *denominator) @@ -92,6 +100,14 @@ void SDL_CalculateFraction(float x, int *numerator, int *denominator) } } +bool SDL_startswith(const char *string, const char *prefix) +{ + if (SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0) { + return true; + } + return false; +} + bool SDL_endswith(const char *string, const char *suffix) { size_t string_length = string ? SDL_strlen(string) : 0; @@ -352,8 +368,8 @@ const char *SDL_GetPersistentString(const char *string) SDL_SetTLS(&SDL_string_storage, strings, SDL_FreePersistentStrings); } - const char *retval; - if (!SDL_FindInHashTable(strings, string, (const void **)&retval)) { + const char *result; + if (!SDL_FindInHashTable(strings, string, (const void **)&result)) { char *new_string = SDL_strdup(string); if (!new_string) { return NULL; @@ -361,7 +377,7 @@ const char *SDL_GetPersistentString(const char *string) // If the hash table insert fails, at least we can return the string we allocated SDL_InsertIntoHashTable(strings, new_string, new_string); - retval = new_string; + result = new_string; } - return retval; + return result; } diff --git a/src/SDL_utils_c.h b/src/SDL_utils_c.h index f864794dcf..500f804fe3 100644 --- a/src/SDL_utils_c.h +++ b/src/SDL_utils_c.h @@ -28,8 +28,10 @@ // Return the smallest power of 2 greater than or equal to 'x' extern int SDL_powerof2(int x); +extern Uint32 SDL_CalculateGCD(Uint32 a, Uint32 b); extern void SDL_CalculateFraction(float x, int *numerator, int *denominator); +extern bool SDL_startswith(const char *string, const char *prefix); extern bool SDL_endswith(const char *string, const char *suffix); /** Convert URI to a local filename, stripping the "file://" diff --git a/src/atomic/SDL_atomic.c b/src/atomic/SDL_atomic.c index 4afb963244..49351a89e9 100644 --- a/src/atomic/SDL_atomic.c +++ b/src/atomic/SDL_atomic.c @@ -136,16 +136,16 @@ SDL_bool SDL_AtomicCompareAndSwap(SDL_AtomicInt *a, int oldval, int newval) #elif defined(SDL_PLATFORM_SOLARIS) return ((int)atomic_cas_uint((volatile uint_t *)&a->value, (uint_t)oldval, (uint_t)newval) == oldval); #elif defined(EMULATE_CAS) - bool retval = false; + bool result = false; enterLock(a); if (a->value == oldval) { a->value = newval; - retval = true; + result = true; } leaveLock(a); - return retval; + return result; #else #error Please define your platform. #endif @@ -166,16 +166,16 @@ SDL_bool SDL_AtomicCompareAndSwapPointer(void **a, void *oldval, void *newval) #elif defined(SDL_PLATFORM_SOLARIS) return (atomic_cas_ptr(a, oldval, newval) == oldval); #elif defined(EMULATE_CAS) - bool retval = false; + bool result = false; enterLock(a); if (*a == oldval) { *a = newval; - retval = true; + result = true; } leaveLock(a); - return retval; + return result; #else #error Please define your platform. #endif diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index d4a1dab545..948ea242dd 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -278,18 +278,18 @@ bool SDL_AudioSpecsEqual(const SDL_AudioSpec *a, const SDL_AudioSpec *b, const i // These get used when a device is disconnected or fails, so audiostreams don't overflow with data that isn't being // consumed and apps relying on audio callbacks don't stop making progress. -static int ZombieWaitDevice(SDL_AudioDevice *device) +static bool ZombieWaitDevice(SDL_AudioDevice *device) { if (!SDL_AtomicGet(&device->shutdown)) { const int frames = device->buffer_size / SDL_AUDIO_FRAMESIZE(device->spec); SDL_Delay((frames * 1000) / device->spec.freq); } - return 0; + return true; } -static int ZombiePlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool ZombiePlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { - return 0; // no-op, just throw the audio away. + return true; // no-op, just throw the audio away. } static Uint8 *ZombieGetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -770,9 +770,9 @@ void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device) // stubs for audio drivers that don't need a specific entry point... static void SDL_AudioThreadDeinit_Default(SDL_AudioDevice *device) { /* no-op. */ } -static int SDL_AudioWaitDevice_Default(SDL_AudioDevice *device) { return 0; /* no-op. */ } -static int SDL_AudioPlayDevice_Default(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { return 0; /* no-op. */ } -static int SDL_AudioWaitRecordingDevice_Default(SDL_AudioDevice *device) { return 0; /* no-op. */ } +static bool SDL_AudioWaitDevice_Default(SDL_AudioDevice *device) { return true; /* no-op. */ } +static bool SDL_AudioPlayDevice_Default(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { return true; /* no-op. */ } +static bool SDL_AudioWaitRecordingDevice_Default(SDL_AudioDevice *device) { return true; /* no-op. */ } static void SDL_AudioFlushRecording_Default(SDL_AudioDevice *device) { /* no-op. */ } static void SDL_AudioCloseDevice_Default(SDL_AudioDevice *device) { /* no-op. */ } static void SDL_AudioDeinitializeStart_Default(void) { /* no-op. */ } @@ -804,10 +804,11 @@ static Uint8 *SDL_AudioGetDeviceBuf_Default(SDL_AudioDevice *device, int *buffer static int SDL_AudioRecordDevice_Default(SDL_AudioDevice *device, void *buffer, int buflen) { - return SDL_Unsupported(); + SDL_Unsupported(); + return -1; } -static int SDL_AudioOpenDevice_Default(SDL_AudioDevice *device) +static bool SDL_AudioOpenDevice_Default(SDL_AudioDevice *device) { return SDL_Unsupported(); } @@ -836,7 +837,7 @@ static void CompleteAudioEntryPoints(void) static SDL_AudioDevice *GetFirstAddedAudioDevice(const bool recording) { SDL_AudioDeviceID highest = (SDL_AudioDeviceID) SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK; // According to AssignAudioDeviceInstanceId, nothing can have a value this large. - SDL_AudioDevice *retval = NULL; + SDL_AudioDevice *result = NULL; // (Device IDs increase as new devices are added, so the first device added has the lowest SDL_AudioDeviceID value.) SDL_LockRWLockForReading(current_audio.device_hash_lock); @@ -852,12 +853,12 @@ static SDL_AudioDevice *GetFirstAddedAudioDevice(const bool recording) const bool isphysical = (devid & (1 << 1)); if (isphysical && (devid_recording == recording) && (devid < highest)) { highest = devid; - retval = (SDL_AudioDevice *) value; + result = (SDL_AudioDevice *) value; } } SDL_UnlockRWLock(current_audio.device_hash_lock); - return retval; + return result; } static Uint32 HashAudioDeviceID(const void *key, void *data) @@ -878,7 +879,7 @@ static void NukeAudioDeviceHashItem(const void *key, const void *value, void *da } // !!! FIXME: the video subsystem does SDL_VideoInit, not SDL_InitVideo. Make this match. -int SDL_InitAudio(const char *driver_name) +bool SDL_InitAudio(const char *driver_name) { if (SDL_GetCurrentAudioDriver()) { SDL_QuitAudio(); // shutdown driver if already running. @@ -892,13 +893,13 @@ int SDL_InitAudio(const char *driver_name) SDL_RWLock *device_hash_lock = SDL_CreateRWLock(); // create this early, so if it fails we don't have to tear down the whole audio subsystem. if (!device_hash_lock) { - return -1; + return false; } SDL_HashTable *device_hash = SDL_CreateHashTable(NULL, 8, HashAudioDeviceID, MatchAudioDeviceID, NukeAudioDeviceHashItem, false); if (!device_hash) { SDL_DestroyRWLock(device_hash_lock); - return -1; + return false; } // Select the proper audio driver @@ -916,7 +917,7 @@ int SDL_InitAudio(const char *driver_name) if (!driver_name_copy) { SDL_DestroyRWLock(device_hash_lock); SDL_DestroyHashTable(device_hash); - return -1; + return false; } while (driver_attempt && *driver_attempt != 0 && !initialized) { @@ -984,7 +985,7 @@ int SDL_InitAudio(const char *driver_name) SDL_DestroyRWLock(device_hash_lock); SDL_DestroyHashTable(device_hash); SDL_zero(current_audio); - return -1; // No driver was available, so fail. + return false; // No driver was available, so fail. } CompleteAudioEntryPoints(); @@ -1013,7 +1014,7 @@ int SDL_InitAudio(const char *driver_name) RefPhysicalAudioDevice(default_recording); // extra ref on default devices. } - return 0; + return true; } void SDL_QuitAudio(void) @@ -1073,7 +1074,7 @@ void SDL_AudioThreadFinalize(SDL_AudioDevice *device) static void MixFloat32Audio(float *dst, const float *src, const int buffer_size) { - if (SDL_MixAudio((Uint8 *) dst, (const Uint8 *) src, SDL_AUDIO_F32, buffer_size, 1.0f) < 0) { + if (!SDL_MixAudio((Uint8 *) dst, (const Uint8 *) src, SDL_AUDIO_F32, buffer_size, 1.0f)) { SDL_assert(!"This shouldn't happen."); } } @@ -1182,7 +1183,7 @@ bool SDL_PlaybackAudioThreadIterate(SDL_AudioDevice *device) } // PlayDevice SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice instead! - if (device->PlayDevice(device, device_buffer, buffer_size) < 0) { + if (!device->PlayDevice(device, device_buffer, buffer_size)) { failed = true; } } @@ -1216,7 +1217,7 @@ static int SDLCALL PlaybackAudioThread(void *devicep) // thread entry point SDL_PlaybackAudioThreadSetup(device); do { - if (device->WaitDevice(device) < 0) { + if (!device->WaitDevice(device)) { SDL_AudioDeviceDisconnected(device); // doh. (but don't break out of the loop, just be a zombie for now!) } } while (SDL_PlaybackAudioThreadIterate(device)); @@ -1288,7 +1289,7 @@ bool SDL_RecordingAudioThreadIterate(SDL_AudioDevice *device) for iterating here because the binding linked list can only change while the device lock is held. (we _do_ lock the stream during binding/unbinding to make sure that two threads can't try to bind the same stream to different devices at the same time, though.) */ - if (SDL_PutAudioStreamData(stream, output_buffer, br) < 0) { + if (!SDL_PutAudioStreamData(stream, output_buffer, br)) { // oh crud, we probably ran out of memory. This is possibly an overreaction to kill the audio device, but it's likely the whole thing is going down in a moment anyhow. failed = true; break; @@ -1323,7 +1324,7 @@ static int SDLCALL RecordingAudioThread(void *devicep) // thread entry point SDL_RecordingAudioThreadSetup(device); do { - if (device->WaitRecordingDevice(device) < 0) { + if (!device->WaitRecordingDevice(device)) { SDL_AudioDeviceDisconnected(device); // doh. (but don't break out of the loop, just be a zombie for now!) } } while (SDL_RecordingAudioThreadIterate(device)); @@ -1335,15 +1336,15 @@ static int SDLCALL RecordingAudioThread(void *devicep) // thread entry point static SDL_AudioDeviceID *GetAudioDevices(int *count, bool recording) { - SDL_AudioDeviceID *retval = NULL; + SDL_AudioDeviceID *result = NULL; int num_devices = 0; if (SDL_GetCurrentAudioDriver()) { SDL_LockRWLockForReading(current_audio.device_hash_lock); { num_devices = SDL_AtomicGet(recording ? ¤t_audio.recording_device_count : ¤t_audio.playback_device_count); - retval = (SDL_AudioDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_AudioDeviceID)); - if (retval) { + result = (SDL_AudioDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_AudioDeviceID)); + if (result) { int devs_seen = 0; const void *key; const void *value; @@ -1356,12 +1357,12 @@ static SDL_AudioDeviceID *GetAudioDevices(int *count, bool recording) const bool isphysical = (devid & (1<<1)); if (isphysical && (devid_recording == recording)) { SDL_assert(devs_seen < num_devices); - retval[devs_seen++] = devid; + result[devs_seen++] = devid; } } SDL_assert(devs_seen == num_devices); - retval[devs_seen] = 0; // null-terminated. + result[devs_seen] = 0; // null-terminated. } } SDL_UnlockRWLock(current_audio.device_hash_lock); @@ -1370,13 +1371,13 @@ static SDL_AudioDeviceID *GetAudioDevices(int *count, bool recording) } if (count) { - if (retval) { + if (result) { *count = num_devices; } else { *count = 0; } } - return retval; + return result; } SDL_AudioDeviceID *SDL_GetAudioPlaybackDevices(int *count) @@ -1432,44 +1433,44 @@ SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle) const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid) { - const char *retval = NULL; + const char *result = NULL; SDL_AudioDevice *device = ObtainPhysicalAudioDevice(devid); if (device) { - retval = SDL_GetPersistentString(device->name); + result = SDL_GetPersistentString(device->name); } ReleaseAudioDevice(device); - return retval; + return result; } -int SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames) +SDL_bool SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *sample_frames) { if (!spec) { return SDL_InvalidParamError("spec"); } - int retval = -1; + bool result = false; SDL_AudioDevice *device = ObtainPhysicalAudioDeviceDefaultAllowed(devid); if (device) { SDL_copyp(spec, &device->spec); if (sample_frames) { *sample_frames = device->sample_frames; } - retval = 0; + result = true; } ReleaseAudioDevice(device); - return retval; + return result; } int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count) { - int *retval = NULL; + int *result = NULL; int channels = 0; SDL_AudioDevice *device = ObtainPhysicalAudioDeviceDefaultAllowed(devid); if (device) { channels = device->spec.channels; - retval = SDL_ChannelMapDup(device->chmap, channels); + result = SDL_ChannelMapDup(device->chmap, channels); } ReleaseAudioDevice(device); @@ -1477,7 +1478,7 @@ int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count) *count = channels; } - return retval; + return result; } @@ -1620,17 +1621,17 @@ char *SDL_GetAudioThreadName(SDL_AudioDevice *device, char *buf, size_t buflen) // this expects the device lock to be held. -static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec) +static bool OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec *inspec) { SerializePhysicalDeviceClose(device); // make sure another thread that's closing didn't release the lock to let the device thread join... if (device->currently_opened) { - return 0; // we're already good. + return true; // we're already good. } // Just pretend to open a zombie device. It can still collect logical devices on a default device under the assumption they will all migrate when the default device is officially changed. if (SDL_AtomicGet(&device->zombie)) { - return 0; // Braaaaaaaaains. + return true; // Braaaaaaaaains. } // These start with the backend's implementation, but we might swap them out with zombie versions later. @@ -1656,9 +1657,9 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec SDL_UpdatedAudioDeviceFormat(device); // start this off sane. device->currently_opened = true; // mark this true even if impl.OpenDevice fails, so we know to clean up. - if (current_audio.impl.OpenDevice(device) < 0) { + if (!current_audio.impl.OpenDevice(device)) { ClosePhysicalAudioDevice(device); // clean up anything the backend left half-initialized. - return -1; + return false; } SDL_UpdatedAudioDeviceFormat(device); // in case the backend changed things and forgot to call this. @@ -1667,14 +1668,14 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec device->work_buffer = (Uint8 *)SDL_aligned_alloc(SDL_GetSIMDAlignment(), device->work_buffer_size); if (!device->work_buffer) { ClosePhysicalAudioDevice(device); - return -1; + return false; } if (device->spec.format != SDL_AUDIO_F32) { device->mix_buffer = (Uint8 *)SDL_aligned_alloc(SDL_GetSIMDAlignment(), device->work_buffer_size); if (!device->mix_buffer) { ClosePhysicalAudioDevice(device); - return -1; + return false; } } @@ -1690,7 +1691,7 @@ static int OpenPhysicalAudioDevice(SDL_AudioDevice *device, const SDL_AudioSpec } } - return 0; + return true; } SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec) @@ -1714,7 +1715,7 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp } } - SDL_AudioDeviceID retval = 0; + SDL_AudioDeviceID result = 0; if (device) { SDL_LogicalAudioDevice *logdev = NULL; @@ -1723,12 +1724,12 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp SDL_SetError("Device was already lost and can't accept new opens"); } else if ((logdev = (SDL_LogicalAudioDevice *) SDL_calloc(1, sizeof (SDL_LogicalAudioDevice))) == NULL) { // SDL_calloc already called SDL_OutOfMemory - } else if (OpenPhysicalAudioDevice(device, spec) < 0) { // if this is the first thing using this physical device, open at the OS level if necessary... + } else if (!OpenPhysicalAudioDevice(device, spec)) { // if this is the first thing using this physical device, open at the OS level if necessary... SDL_free(logdev); } else { RefPhysicalAudioDevice(device); // unref'd on successful SDL_CloseAudioDevice SDL_AtomicSet(&logdev->paused, 0); - retval = logdev->instance_id = AssignAudioDeviceInstanceId(device->recording, /*islogical=*/true); + result = logdev->instance_id = AssignAudioDeviceInstanceId(device->recording, /*islogical=*/true); logdev->physical_device = device; logdev->gain = 1.0f; logdev->opened_as_default = wants_default; @@ -1741,21 +1742,21 @@ SDL_AudioDeviceID SDL_OpenAudioDevice(SDL_AudioDeviceID devid, const SDL_AudioSp } ReleaseAudioDevice(device); - if (retval) { + if (result) { SDL_LockRWLockForWriting(current_audio.device_hash_lock); - const bool inserted = SDL_InsertIntoHashTable(current_audio.device_hash, (const void *) (uintptr_t) retval, logdev); + const bool inserted = SDL_InsertIntoHashTable(current_audio.device_hash, (const void *) (uintptr_t) result, logdev); SDL_UnlockRWLock(current_audio.device_hash_lock); if (!inserted) { - SDL_CloseAudioDevice(retval); - retval = 0; + SDL_CloseAudioDevice(result); + result = 0; } } } - return retval; + return result; } -static int SetLogicalAudioDevicePauseState(SDL_AudioDeviceID devid, int value) +static bool SetLogicalAudioDevicePauseState(SDL_AudioDeviceID devid, int value) { SDL_AudioDevice *device = NULL; SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device); @@ -1763,15 +1764,15 @@ static int SetLogicalAudioDevicePauseState(SDL_AudioDeviceID devid, int value) SDL_AtomicSet(&logdev->paused, value); } ReleaseAudioDevice(device); - return logdev ? 0 : -1; // ObtainLogicalAudioDevice will have set an error. + return logdev ? true : false; // ObtainLogicalAudioDevice will have set an error. } -int SDL_PauseAudioDevice(SDL_AudioDeviceID devid) +SDL_bool SDL_PauseAudioDevice(SDL_AudioDeviceID devid) { return SetLogicalAudioDevicePauseState(devid, 1); } -int SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID devid) +SDL_bool SDLCALL SDL_ResumeAudioDevice(SDL_AudioDeviceID devid) { return SetLogicalAudioDevicePauseState(devid, 0); } @@ -1780,24 +1781,24 @@ SDL_bool SDL_AudioDevicePaused(SDL_AudioDeviceID devid) { SDL_AudioDevice *device = NULL; SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device); - bool retval = false; + bool result = false; if (logdev && SDL_AtomicGet(&logdev->paused)) { - retval = true; + result = true; } ReleaseAudioDevice(device); - return retval; + return result; } float SDL_GetAudioDeviceGain(SDL_AudioDeviceID devid) { SDL_AudioDevice *device = NULL; SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device); - const float retval = logdev ? logdev->gain : -1.0f; + const float result = logdev ? logdev->gain : -1.0f; ReleaseAudioDevice(device); - return retval; + return result; } -int SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain) +SDL_bool SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain) { if (gain < 0.0f) { return SDL_InvalidParamError("gain"); @@ -1805,7 +1806,7 @@ int SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain) SDL_AudioDevice *device = NULL; SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device); - int retval = -1; + bool result = false; if (logdev) { logdev->gain = gain; if (device->recording) { @@ -1820,26 +1821,26 @@ int SDL_SetAudioDeviceGain(SDL_AudioDeviceID devid, float gain) } UpdateAudioStreamFormatsPhysical(device); - retval = 0; + result = true; } ReleaseAudioDevice(device); - return retval; + return result; } -int SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata) +SDL_bool SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallback callback, void *userdata) { SDL_AudioDevice *device = NULL; SDL_LogicalAudioDevice *logdev = ObtainLogicalAudioDevice(devid, &device); - int retval = 0; + bool result = true; if (logdev) { if (callback && !device->postmix_buffer) { device->postmix_buffer = (float *)SDL_aligned_alloc(SDL_GetSIMDAlignment(), device->work_buffer_size); if (!device->postmix_buffer) { - retval = -1; + result = false; } } - if (retval == 0) { + if (result) { logdev->postmix = callback; logdev->postmix_userdata = userdata; @@ -1858,18 +1859,18 @@ int SDL_SetAudioPostmixCallback(SDL_AudioDeviceID devid, SDL_AudioPostmixCallbac UpdateAudioStreamFormatsPhysical(device); } ReleaseAudioDevice(device); - return retval; + return result; } -int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams) +SDL_bool SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int num_streams) { const bool islogical = !(devid & (1<<1)); SDL_AudioDevice *device = NULL; SDL_LogicalAudioDevice *logdev = NULL; - int retval = 0; + bool result = true; if (num_streams == 0) { - return 0; // nothing to do + return true; // nothing to do } else if (num_streams < 0) { return SDL_InvalidParamError("num_streams"); } else if (!streams) { @@ -1880,9 +1881,9 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int logdev = ObtainLogicalAudioDevice(devid, &device); if (!logdev) { - retval = -1; // ObtainLogicalAudioDevice set the error string. + result = false; // ObtainLogicalAudioDevice set the error string. } else if (logdev->simplified) { - retval = SDL_SetError("Cannot change stream bindings on device opened with SDL_OpenAudioDeviceStream"); + result = SDL_SetError("Cannot change stream bindings on device opened with SDL_OpenAudioDeviceStream"); } else { // !!! FIXME: We'll set the device's side's format below, but maybe we should refuse to bind a stream if the app's side doesn't have a format set yet. @@ -1896,18 +1897,18 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int SDL_AudioStream *stream = streams[i]; if (!stream) { SDL_SetError("Stream #%d is NULL", i); - retval = -1; // to pacify the static analyzer, that doesn't realize SDL_SetError() always returns -1. + result = false; // to pacify the static analyzer, that doesn't realize SDL_SetError() always returns SDL_FALSE. } else { SDL_LockMutex(stream->lock); SDL_assert((stream->bound_device == NULL) == ((stream->prev_binding == NULL) || (stream->next_binding == NULL))); if (stream->bound_device) { - retval = SDL_SetError("Stream #%d is already bound to a device", i); + result = SDL_SetError("Stream #%d is already bound to a device", i); } else if (stream->simplified) { // You can get here if you closed the device instead of destroying the stream. - retval = SDL_SetError("Cannot change binding on a stream created with SDL_OpenAudioDeviceStream"); + result = SDL_SetError("Cannot change binding on a stream created with SDL_OpenAudioDeviceStream"); } } - if (retval != 0) { + if (!result) { int j; for (j = 0; j < i; j++) { SDL_UnlockMutex(streams[j]->lock); @@ -1920,7 +1921,7 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int } } - if (retval == 0) { + if (result) { // Now that everything is verified, chain everything together. const bool recording = device->recording; for (int i = 0; i < num_streams; i++) { @@ -1951,10 +1952,10 @@ int SDL_BindAudioStreams(SDL_AudioDeviceID devid, SDL_AudioStream **streams, int ReleaseAudioDevice(device); - return retval; + return result; } -int SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream) +SDL_bool SDL_BindAudioStream(SDL_AudioDeviceID devid, SDL_AudioStream *stream) { return SDL_BindAudioStreams(devid, &stream, 1); } @@ -2034,7 +2035,7 @@ void SDL_UnbindAudioStream(SDL_AudioStream *stream) SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream *stream) { - SDL_AudioDeviceID retval = 0; + SDL_AudioDeviceID result = 0; if (!stream) { SDL_InvalidParamError("stream"); @@ -2043,13 +2044,13 @@ SDL_AudioDeviceID SDL_GetAudioStreamDevice(SDL_AudioStream *stream) SDL_LockMutex(stream->lock); if (stream->bound_device) { - retval = stream->bound_device->instance_id; + result = stream->bound_device->instance_id; } else { SDL_SetError("Audio stream not bound to an audio device"); } SDL_UnlockMutex(stream->lock); - return retval; + return result; } SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata) @@ -2097,13 +2098,13 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au UpdateAudioStreamFormatsPhysical(device); if (callback) { - int rc; + bool rc; if (recording) { rc = SDL_SetAudioStreamPutCallback(stream, callback, userdata); } else { rc = SDL_SetAudioStreamGetCallback(stream, callback, userdata); } - SDL_assert(rc == 0); // should only fail if stream==NULL atm. + SDL_assert(rc); // should only fail if stream==NULL atm. } } } @@ -2119,21 +2120,21 @@ SDL_AudioStream *SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_Au return stream; } -int SDL_PauseAudioStreamDevice(SDL_AudioStream *stream) +SDL_bool SDL_PauseAudioStreamDevice(SDL_AudioStream *stream) { SDL_AudioDeviceID devid = SDL_GetAudioStreamDevice(stream); if (!devid) { - return -1; + return false; } return SDL_PauseAudioDevice(devid); } -int SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream) +SDL_bool SDL_ResumeAudioStreamDevice(SDL_AudioStream *stream) { SDL_AudioDeviceID devid = SDL_GetAudioStreamDevice(stream); if (!devid) { - return -1; + return false; } return SDL_ResumeAudioDevice(devid); @@ -2267,7 +2268,7 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device) if (needs_migration) { // New default physical device not been opened yet? Open at the OS level... - if (OpenPhysicalAudioDevice(new_default_device, &spec) < 0) { + if (!OpenPhysicalAudioDevice(new_default_device, &spec)) { needs_migration = false; // uhoh, just leave everything on the old default, nothing to be done. } } @@ -2350,13 +2351,13 @@ void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device) } } -int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames) +bool SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames) { const int orig_work_buffer_size = device->work_buffer_size; // we don't currently have any place where channel maps change from under you, but we can check that if necessary later. if (SDL_AudioSpecsEqual(&device->spec, newspec, NULL, NULL) && (new_sample_frames == device->sample_frames)) { - return 0; // we're already in that format. + return true; // we're already in that format. } SDL_copyp(&device->spec, newspec); @@ -2432,15 +2433,18 @@ int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL } } - return kill_device ? -1 : 0; + if (kill_device) { + return false; + } + return true; } -int SDL_AudioDeviceFormatChanged(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames) +bool SDL_AudioDeviceFormatChanged(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames) { ObtainPhysicalAudioDeviceObj(device); - const int retval = SDL_AudioDeviceFormatChangedAlreadyLocked(device, newspec, new_sample_frames); + const bool result = SDL_AudioDeviceFormatChangedAlreadyLocked(device, newspec, new_sample_frames); ReleaseAudioDevice(device); - return retval; + return result; } // This is an internal function, so SDL_PumpEvents() can check for pending audio device events. diff --git a/src/audio/SDL_audiocvt.c b/src/audio/SDL_audiocvt.c index ecd9b2971f..bb0f1c38df 100644 --- a/src/audio/SDL_audiocvt.c +++ b/src/audio/SDL_audiocvt.c @@ -377,14 +377,14 @@ static Sint64 GetAudioStreamResampleRate(SDL_AudioStream* stream, int src_freq, return resample_rate; } -static int UpdateAudioStreamInputSpec(SDL_AudioStream *stream, const SDL_AudioSpec *spec, const int *chmap) +static bool UpdateAudioStreamInputSpec(SDL_AudioStream *stream, const SDL_AudioSpec *spec, const int *chmap) { if (SDL_AudioSpecsEqual(&stream->input_spec, spec, stream->input_chmap, chmap)) { - return 0; + return true; } - if (SDL_ResetAudioQueueHistory(stream->queue, SDL_GetResamplerHistoryFrames()) < 0) { - return -1; + if (!SDL_ResetAudioQueueHistory(stream->queue, SDL_GetResamplerHistoryFrames())) { + return false; } if (!chmap) { @@ -397,7 +397,7 @@ static int UpdateAudioStreamInputSpec(SDL_AudioStream *stream, const SDL_AudioSp SDL_copyp(&stream->input_spec, spec); - return 0; + return true; } SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec) @@ -405,35 +405,35 @@ SDL_AudioStream *SDL_CreateAudioStream(const SDL_AudioSpec *src_spec, const SDL_ SDL_ChooseAudioConverters(); SDL_SetupAudioResampler(); - SDL_AudioStream *retval = (SDL_AudioStream *)SDL_calloc(1, sizeof(SDL_AudioStream)); - if (!retval) { + SDL_AudioStream *result = (SDL_AudioStream *)SDL_calloc(1, sizeof(SDL_AudioStream)); + if (!result) { return NULL; } - retval->freq_ratio = 1.0f; - retval->gain = 1.0f; - retval->queue = SDL_CreateAudioQueue(8192); + result->freq_ratio = 1.0f; + result->gain = 1.0f; + result->queue = SDL_CreateAudioQueue(8192); - if (!retval->queue) { - SDL_free(retval); + if (!result->queue) { + SDL_free(result); return NULL; } - retval->lock = SDL_CreateMutex(); - if (!retval->lock) { - SDL_free(retval->queue); - SDL_free(retval); + result->lock = SDL_CreateMutex(); + if (!result->lock) { + SDL_free(result->queue); + SDL_free(result); return NULL; } - OnAudioStreamCreated(retval); + OnAudioStreamCreated(result); - if (SDL_SetAudioStreamFormat(retval, src_spec, dst_spec) < 0) { - SDL_DestroyAudioStream(retval); + if (!SDL_SetAudioStreamFormat(result, src_spec, dst_spec)) { + SDL_DestroyAudioStream(result); return NULL; } - return retval; + return result; } SDL_PropertiesID SDL_GetAudioStreamProperties(SDL_AudioStream *stream) @@ -448,7 +448,7 @@ SDL_PropertiesID SDL_GetAudioStreamProperties(SDL_AudioStream *stream) return stream->props; } -int SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata) +SDL_bool SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -457,10 +457,10 @@ int SDL_SetAudioStreamGetCallback(SDL_AudioStream *stream, SDL_AudioStreamCallba stream->get_callback = callback; stream->get_callback_userdata = userdata; SDL_UnlockMutex(stream->lock); - return 0; + return true; } -int SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata) +SDL_bool SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallback callback, void *userdata) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -469,28 +469,28 @@ int SDL_SetAudioStreamPutCallback(SDL_AudioStream *stream, SDL_AudioStreamCallba stream->put_callback = callback; stream->put_callback_userdata = userdata; SDL_UnlockMutex(stream->lock); - return 0; + return true; } -int SDL_LockAudioStream(SDL_AudioStream *stream) +SDL_bool SDL_LockAudioStream(SDL_AudioStream *stream) { if (!stream) { return SDL_InvalidParamError("stream"); } SDL_LockMutex(stream->lock); - return 0; + return true; } -int SDL_UnlockAudioStream(SDL_AudioStream *stream) +SDL_bool SDL_UnlockAudioStream(SDL_AudioStream *stream) { if (!stream) { return SDL_InvalidParamError("stream"); } SDL_UnlockMutex(stream->lock); - return 0; + return true; } -int SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec) +SDL_bool SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, SDL_AudioSpec *dst_spec) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -511,10 +511,10 @@ int SDL_GetAudioStreamFormat(SDL_AudioStream *stream, SDL_AudioSpec *src_spec, S return SDL_SetError("Stream has no destination format"); } - return 0; + return true; } -int SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec) +SDL_bool SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_spec, const SDL_AudioSpec *dst_spec) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -581,27 +581,27 @@ int SDL_SetAudioStreamFormat(SDL_AudioStream *stream, const SDL_AudioSpec *src_s SDL_UnlockMutex(stream->lock); - return 0; + return true; } -int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, int isinput) +bool SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, int isinput) { if (!stream) { return SDL_InvalidParamError("stream"); } - int retval = 0; + bool result = true; SDL_LockMutex(stream->lock); if (channels != spec->channels) { - retval = SDL_SetError("Wrong number of channels"); + result = SDL_SetError("Wrong number of channels"); } else if (!*stream_chmap && !chmap) { // already at default, we're good. } else if (*stream_chmap && chmap && (SDL_memcmp(*stream_chmap, chmap, sizeof (*chmap) * channels) == 0)) { // already have this map, don't allocate/copy it again. } else if (SDL_ChannelMapIsBogus(chmap, channels)) { - retval = SDL_SetError("Invalid channel mapping"); + result = SDL_SetError("Invalid channel mapping"); } else if ((isinput != -1) && stream->bound_device && (!!isinput == !!stream->bound_device->physical_device->recording)) { // quietly refuse to change the format of the end currently bound to a device. } else { @@ -611,7 +611,7 @@ int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, if (chmap) { int *dupmap = SDL_ChannelMapDup(chmap, channels); if (!dupmap) { - retval = SDL_SetError("Invalid channel mapping"); + result = SDL_SetError("Invalid channel mapping"); } else { SDL_free(*stream_chmap); *stream_chmap = dupmap; @@ -623,27 +623,27 @@ int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, } SDL_UnlockMutex(stream->lock); - return retval; + return result; } -int SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int channels) +SDL_bool SDL_SetAudioStreamInputChannelMap(SDL_AudioStream *stream, const int *chmap, int channels) { return SetAudioStreamChannelMap(stream, &stream->src_spec, &stream->src_chmap, chmap, channels, true); } -int SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int channels) +SDL_bool SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap, int channels) { return SetAudioStreamChannelMap(stream, &stream->dst_spec, &stream->dst_chmap, chmap, channels, false); } int *SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count) { - int *retval = NULL; + int *result = NULL; int channels = 0; if (stream) { SDL_LockMutex(stream->lock); channels = stream->src_spec.channels; - retval = SDL_ChannelMapDup(stream->src_chmap, channels); + result = SDL_ChannelMapDup(stream->src_chmap, channels); SDL_UnlockMutex(stream->lock); } @@ -651,17 +651,17 @@ int *SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count) *count = channels; } - return retval; + return result; } int *SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count) { - int *retval = NULL; + int *result = NULL; int channels = 0; if (stream) { SDL_LockMutex(stream->lock); channels = stream->dst_spec.channels; - retval = SDL_ChannelMapDup(stream->dst_chmap, channels); + result = SDL_ChannelMapDup(stream->dst_chmap, channels); SDL_UnlockMutex(stream->lock); } @@ -669,7 +669,7 @@ int *SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count) *count = channels; } - return retval; + return result; } float SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream) @@ -686,7 +686,7 @@ float SDL_GetAudioStreamFrequencyRatio(SDL_AudioStream *stream) return freq_ratio; } -int SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float freq_ratio) +SDL_bool SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float freq_ratio) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -706,7 +706,7 @@ int SDL_SetAudioStreamFrequencyRatio(SDL_AudioStream *stream, float freq_ratio) stream->freq_ratio = freq_ratio; SDL_UnlockMutex(stream->lock); - return 0; + return true; } float SDL_GetAudioStreamGain(SDL_AudioStream *stream) @@ -723,7 +723,7 @@ float SDL_GetAudioStreamGain(SDL_AudioStream *stream) return gain; } -int SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain) +SDL_bool SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -735,10 +735,10 @@ int SDL_SetAudioStreamGain(SDL_AudioStream *stream, float gain) stream->gain = gain; SDL_UnlockMutex(stream->lock); - return 0; + return true; } -static int CheckAudioStreamIsFullySetup(SDL_AudioStream *stream) +static bool CheckAudioStreamIsFullySetup(SDL_AudioStream *stream) { if (stream->src_spec.format == 0) { return SDL_SetError("Stream has no source format"); @@ -746,10 +746,10 @@ static int CheckAudioStreamIsFullySetup(SDL_AudioStream *stream) return SDL_SetError("Stream has no destination format"); } - return 0; + return true; } -static int PutAudioStreamBuffer(SDL_AudioStream *stream, const void *buf, int len, SDL_ReleaseAudioBufferCallback callback, void* userdata) +static bool PutAudioStreamBuffer(SDL_AudioStream *stream, const void *buf, int len, SDL_ReleaseAudioBufferCallback callback, void* userdata) { #if DEBUG_AUDIOSTREAM SDL_Log("AUDIOSTREAM: wants to put %d bytes", len); @@ -757,9 +757,9 @@ static int PutAudioStreamBuffer(SDL_AudioStream *stream, const void *buf, int le SDL_LockMutex(stream->lock); - if (CheckAudioStreamIsFullySetup(stream) != 0) { + if (!CheckAudioStreamIsFullySetup(stream)) { SDL_UnlockMutex(stream->lock); - return -1; + return false; } if ((len % SDL_AUDIO_FRAMESIZE(stream->src_spec)) != 0) { @@ -774,21 +774,21 @@ static int PutAudioStreamBuffer(SDL_AudioStream *stream, const void *buf, int le if (!track) { SDL_UnlockMutex(stream->lock); - return -1; + return false; } } const int prev_available = stream->put_callback ? SDL_GetAudioStreamAvailable(stream) : 0; - int retval = 0; + bool result = true; if (track) { SDL_AddTrackToAudioQueue(stream->queue, track); } else { - retval = SDL_WriteToAudioQueue(stream->queue, &stream->src_spec, stream->src_chmap, (const Uint8 *)buf, len); + result = SDL_WriteToAudioQueue(stream->queue, &stream->src_spec, stream->src_chmap, (const Uint8 *)buf, len); } - if (retval == 0) { + if (result) { if (stream->put_callback) { const int newavail = SDL_GetAudioStreamAvailable(stream) - prev_available; stream->put_callback(stream->put_callback_userdata, stream, newavail, newavail); @@ -797,7 +797,7 @@ static int PutAudioStreamBuffer(SDL_AudioStream *stream, const void *buf, int le SDL_UnlockMutex(stream->lock); - return retval; + return result; } static void SDLCALL FreeAllocatedAudioBuffer(void *userdata, const void *buf, int len) @@ -805,7 +805,7 @@ static void SDLCALL FreeAllocatedAudioBuffer(void *userdata, const void *buf, in SDL_free((void*) buf); } -int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len) +SDL_bool SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -814,7 +814,7 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len) } else if (len < 0) { return SDL_InvalidParamError("len"); } else if (len == 0) { - return 0; // nothing to do. + return true; // nothing to do. } // When copying in large amounts of data, try and do as much work as possible @@ -822,28 +822,26 @@ int SDL_PutAudioStreamData(SDL_AudioStream *stream, const void *buf, int len) const int large_input_thresh = 64 * 1024; if (len >= large_input_thresh) { - void* data = SDL_malloc(len); + void *data = SDL_malloc(len); if (!data) { - return -1; + return false; } SDL_memcpy(data, buf, len); buf = data; - int ret = PutAudioStreamBuffer(stream, buf, len, FreeAllocatedAudioBuffer, NULL); - - if (ret < 0) { + bool ret = PutAudioStreamBuffer(stream, buf, len, FreeAllocatedAudioBuffer, NULL); + if (!ret) { SDL_free(data); } - return ret; } return PutAudioStreamBuffer(stream, buf, len, NULL, NULL); } -int SDL_FlushAudioStream(SDL_AudioStream *stream) +SDL_bool SDL_FlushAudioStream(SDL_AudioStream *stream) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -853,7 +851,7 @@ int SDL_FlushAudioStream(SDL_AudioStream *stream) SDL_FlushAudioQueue(stream->queue); SDL_UnlockMutex(stream->lock); - return 0; + return true; } /* this does not save the previous contents of stream->work_buffer. It's a work buffer!! @@ -970,7 +968,7 @@ static Sint64 GetAudioStreamHead(SDL_AudioStream* stream, SDL_AudioSpec* out_spe // You must hold stream->lock and validate your parameters before calling this! // Enough input data MUST be available! -static int GetAudioStreamDataInternal(SDL_AudioStream *stream, void *buf, int output_frames, float gain) +static bool GetAudioStreamDataInternal(SDL_AudioStream *stream, void *buf, int output_frames, float gain) { const SDL_AudioSpec* src_spec = &stream->input_spec; const SDL_AudioSpec* dst_spec = &stream->dst_spec; @@ -1000,15 +998,15 @@ static int GetAudioStreamDataInternal(SDL_AudioStream *stream, void *buf, int ou work_buffer = EnsureAudioStreamWorkBufferSize(stream, output_frames * max_frame_size); if (!work_buffer) { - return -1; + return false; } } - if (SDL_ReadFromAudioQueue(stream->queue, buf, dst_format, dst_channels, dst_map, 0, output_frames, 0, work_buffer, gain) != buf) { + if (SDL_ReadFromAudioQueue(stream->queue, (Uint8 *)buf, dst_format, dst_channels, dst_map, 0, output_frames, 0, work_buffer, gain) != buf) { return SDL_SetError("Not enough data in queue"); } - return 0; + return true; } // Time to do some resampling! @@ -1066,7 +1064,7 @@ static int GetAudioStreamDataInternal(SDL_AudioStream *stream, void *buf, int ou Uint8* work_buffer = EnsureAudioStreamWorkBufferSize(stream, work_buffer_capacity); if (!work_buffer) { - return -1; + return false; } // adjust gain either before resampling or after, depending on which point has less @@ -1096,7 +1094,7 @@ static int GetAudioStreamDataInternal(SDL_AudioStream *stream, void *buf, int ou // Convert to the final format, if necessary (src channel map is NULL because SDL_ReadFromAudioQueue already handled this). ConvertAudio(output_frames, resample_buffer, resample_format, resample_channels, NULL, buf, dst_format, dst_channels, dst_map, work_buffer, postresample_gain); - return 0; + return true; } // get converted/resampled data from the stream @@ -1109,18 +1107,21 @@ int SDL_GetAudioStreamDataAdjustGain(SDL_AudioStream *stream, void *voidbuf, int #endif if (!stream) { - return SDL_InvalidParamError("stream"); + SDL_InvalidParamError("stream"); + return -1; } else if (!buf) { - return SDL_InvalidParamError("buf"); + SDL_InvalidParamError("buf"); + return -1; } else if (len < 0) { - return SDL_InvalidParamError("len"); + SDL_InvalidParamError("len"); + return -1; } else if (len == 0) { return 0; // nothing to do. } SDL_LockMutex(stream->lock); - if (CheckAudioStreamIsFullySetup(stream) != 0) { + if (!CheckAudioStreamIsFullySetup(stream)) { SDL_UnlockMutex(stream->lock); return -1; } @@ -1176,7 +1177,7 @@ int SDL_GetAudioStreamDataAdjustGain(SDL_AudioStream *stream, void *voidbuf, int break; } - if (UpdateAudioStreamInputSpec(stream, &input_spec, input_chmap) != 0) { + if (!UpdateAudioStreamInputSpec(stream, &input_spec, input_chmap)) { total = total ? total : -1; break; } @@ -1187,7 +1188,7 @@ int SDL_GetAudioStreamDataAdjustGain(SDL_AudioStream *stream, void *voidbuf, int output_frames = SDL_min(output_frames, chunk_size); output_frames = (int) SDL_min(output_frames, available_frames); - if (GetAudioStreamDataInternal(stream, &buf[total], output_frames, gain) != 0) { + if (!GetAudioStreamDataInternal(stream, &buf[total], output_frames, gain)) { total = total ? total : -1; break; } @@ -1213,12 +1214,13 @@ int SDL_GetAudioStreamData(SDL_AudioStream *stream, void *voidbuf, int len) int SDL_GetAudioStreamAvailable(SDL_AudioStream *stream) { if (!stream) { - return SDL_InvalidParamError("stream"); + SDL_InvalidParamError("stream"); + return -1; } SDL_LockMutex(stream->lock); - if (CheckAudioStreamIsFullySetup(stream) != 0) { + if (!CheckAudioStreamIsFullySetup(stream)) { SDL_UnlockMutex(stream->lock); return 0; } @@ -1238,7 +1240,8 @@ int SDL_GetAudioStreamAvailable(SDL_AudioStream *stream) int SDL_GetAudioStreamQueued(SDL_AudioStream *stream) { if (!stream) { - return SDL_InvalidParamError("stream"); + SDL_InvalidParamError("stream"); + return -1; } SDL_LockMutex(stream->lock); @@ -1251,7 +1254,7 @@ int SDL_GetAudioStreamQueued(SDL_AudioStream *stream) return (int) SDL_min(total, SDL_INT_MAX); } -int SDL_ClearAudioStream(SDL_AudioStream *stream) +SDL_bool SDL_ClearAudioStream(SDL_AudioStream *stream) { if (!stream) { return SDL_InvalidParamError("stream"); @@ -1265,7 +1268,7 @@ int SDL_ClearAudioStream(SDL_AudioStream *stream) stream->resample_offset = 0; SDL_UnlockMutex(stream->lock); - return 0; + return true; } void SDL_DestroyAudioStream(SDL_AudioStream *stream) @@ -1300,8 +1303,7 @@ static void SDLCALL DontFreeThisAudioBuffer(void *userdata, const void *buf, int // We don't own the buffer, but know it will outlive the stream } -int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data, int src_len, - const SDL_AudioSpec *dst_spec, Uint8 **dst_data, int *dst_len) +SDL_bool SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data, int src_len, const SDL_AudioSpec *dst_spec, Uint8 **dst_data, int *dst_len) { if (dst_data) { *dst_data = NULL; @@ -1321,30 +1323,31 @@ int SDL_ConvertAudioSamples(const SDL_AudioSpec *src_spec, const Uint8 *src_data return SDL_InvalidParamError("dst_len"); } - int retval = -1; + bool result = false; Uint8 *dst = NULL; int dstlen = 0; SDL_AudioStream *stream = SDL_CreateAudioStream(src_spec, dst_spec); if (stream) { - if ((PutAudioStreamBuffer(stream, src_data, src_len, DontFreeThisAudioBuffer, NULL) == 0) && (SDL_FlushAudioStream(stream) == 0)) { + if (PutAudioStreamBuffer(stream, src_data, src_len, DontFreeThisAudioBuffer, NULL) && + SDL_FlushAudioStream(stream)) { dstlen = SDL_GetAudioStreamAvailable(stream); if (dstlen >= 0) { dst = (Uint8 *)SDL_malloc(dstlen); if (dst) { - retval = (SDL_GetAudioStreamData(stream, dst, dstlen) == dstlen) ? 0 : -1; + result = (SDL_GetAudioStreamData(stream, dst, dstlen) == dstlen); } } } } - if (retval < 0) { - SDL_free(dst); - } else { + if (result) { *dst_data = dst; *dst_len = dstlen; + } else { + SDL_free(dst); } SDL_DestroyAudioStream(stream); - return retval; + return result; } diff --git a/src/audio/SDL_audioqueue.c b/src/audio/SDL_audioqueue.c index 42fd74c983..039a65b57f 100644 --- a/src/audio/SDL_audioqueue.c +++ b/src/audio/SDL_audioqueue.c @@ -121,13 +121,13 @@ static void InitMemoryPool(SDL_MemoryPool *pool, size_t block_size, size_t max_f } // Allocates a number of blocks and adds them to the pool -static int ReserveMemoryPoolBlocks(SDL_MemoryPool *pool, size_t num_blocks) +static bool ReserveMemoryPoolBlocks(SDL_MemoryPool *pool, size_t num_blocks) { for (; num_blocks; --num_blocks) { void *block = AllocNewMemoryPoolBlock(pool); if (block == NULL) { - return -1; + return false; } *(void **)block = pool->free_blocks; @@ -135,7 +135,7 @@ static int ReserveMemoryPoolBlocks(SDL_MemoryPool *pool, size_t num_blocks) ++pool->num_free; } - return 0; + return true; } void SDL_DestroyAudioQueue(SDL_AudioQueue *queue) @@ -160,7 +160,7 @@ SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size) InitMemoryPool(&queue->track_pool, sizeof(SDL_AudioTrack), 8); InitMemoryPool(&queue->chunk_pool, chunk_size, 4); - if (ReserveMemoryPoolBlocks(&queue->track_pool, 2) != 0) { + if (!ReserveMemoryPoolBlocks(&queue->track_pool, 2)) { SDL_DestroyAudioQueue(queue); return NULL; } @@ -318,10 +318,10 @@ static size_t WriteToAudioTrack(SDL_AudioTrack *track, const Uint8 *data, size_t return len; } -int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const int *chmap, const Uint8 *data, size_t len) +bool SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const int *chmap, const Uint8 *data, size_t len) { if (len == 0) { - return 0; + return true; } SDL_AudioTrack *track = queue->tail; @@ -335,7 +335,7 @@ int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, cons track = CreateChunkedAudioTrack(queue, spec, chmap); if (!track) { - return -1; + return false; } queue->head = track; @@ -354,7 +354,7 @@ int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, cons SDL_AudioTrack *new_track = CreateChunkedAudioTrack(queue, spec, chmap); if (!new_track) { - return -1; + return false; } track->next = new_track; @@ -362,7 +362,7 @@ int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, cons track = new_track; } - return 0; + return true; } void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue) @@ -624,12 +624,12 @@ size_t SDL_GetAudioQueueQueued(SDL_AudioQueue *queue) return total; } -int SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames) +bool SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames) { SDL_AudioTrack *track = queue->head; if (!track) { - return -1; + return false; } size_t length = num_frames * SDL_AUDIO_FRAMESIZE(track->spec); @@ -638,7 +638,7 @@ int SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames) if (queue->history_capacity < length) { history_buffer = SDL_aligned_alloc(SDL_GetSIMDAlignment(), length); if (!history_buffer) { - return -1; + return false; } SDL_aligned_free(queue->history_buffer); queue->history_buffer = history_buffer; @@ -648,5 +648,5 @@ int SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames) queue->history_length = length; SDL_memset(history_buffer, SDL_GetSilenceValueForFormat(track->spec.format), length); - return 0; + return true; } diff --git a/src/audio/SDL_audioqueue.h b/src/audio/SDL_audioqueue.h index 2880b22c7c..3a6a5fe50b 100644 --- a/src/audio/SDL_audioqueue.h +++ b/src/audio/SDL_audioqueue.h @@ -25,55 +25,55 @@ // Internal functions used by SDL_AudioStream for queueing audio. -typedef void(SDLCALL *SDL_ReleaseAudioBufferCallback)(void *userdata, const void *buffer, int buflen); +typedef void (SDLCALL *SDL_ReleaseAudioBufferCallback)(void *userdata, const void *buffer, int buflen); typedef struct SDL_AudioQueue SDL_AudioQueue; typedef struct SDL_AudioTrack SDL_AudioTrack; // Create a new audio queue -SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size); +extern SDL_AudioQueue *SDL_CreateAudioQueue(size_t chunk_size); // Destroy an audio queue -void SDL_DestroyAudioQueue(SDL_AudioQueue *queue); +extern void SDL_DestroyAudioQueue(SDL_AudioQueue *queue); // Completely clear the queue -void SDL_ClearAudioQueue(SDL_AudioQueue *queue); +extern void SDL_ClearAudioQueue(SDL_AudioQueue *queue); // Mark the last track as flushed -void SDL_FlushAudioQueue(SDL_AudioQueue *queue); +extern void SDL_FlushAudioQueue(SDL_AudioQueue *queue); // Pop the current head track // REQUIRES: The head track must exist, and must have been flushed -void SDL_PopAudioQueueHead(SDL_AudioQueue *queue); +extern void SDL_PopAudioQueueHead(SDL_AudioQueue *queue); // Write data to the end of queue // REQUIRES: If the spec has changed, the last track must have been flushed -int SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const int *chmap, const Uint8 *data, size_t len); +extern bool SDL_WriteToAudioQueue(SDL_AudioQueue *queue, const SDL_AudioSpec *spec, const int *chmap, const Uint8 *data, size_t len); // Create a track where the input data is owned by the caller -SDL_AudioTrack *SDL_CreateAudioTrack(SDL_AudioQueue *queue, - const SDL_AudioSpec *spec, const int *chmap, Uint8 *data, size_t len, size_t capacity, - SDL_ReleaseAudioBufferCallback callback, void *userdata); +extern SDL_AudioTrack *SDL_CreateAudioTrack(SDL_AudioQueue *queue, + const SDL_AudioSpec *spec, const int *chmap, Uint8 *data, size_t len, size_t capacity, + SDL_ReleaseAudioBufferCallback callback, void *userdata); // Add a track to the end of the queue // REQUIRES: `track != NULL` -void SDL_AddTrackToAudioQueue(SDL_AudioQueue *queue, SDL_AudioTrack *track); +extern void SDL_AddTrackToAudioQueue(SDL_AudioQueue *queue, SDL_AudioTrack *track); // Iterate over the tracks in the queue -void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue); +extern void *SDL_BeginAudioQueueIter(SDL_AudioQueue *queue); // Query and update the track iterator // REQUIRES: `*inout_iter != NULL` (a valid iterator) -size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, int **out_chmap, bool *out_flushed); +extern size_t SDL_NextAudioQueueIter(SDL_AudioQueue *queue, void **inout_iter, SDL_AudioSpec *out_spec, int **out_chmap, bool *out_flushed); -const Uint8 *SDL_ReadFromAudioQueue(SDL_AudioQueue *queue, - Uint8 *dst, SDL_AudioFormat dst_format, int dst_channels, const int *dst_map, - int past_frames, int present_frames, int future_frames, - Uint8 *scratch, float gain); +extern const Uint8 *SDL_ReadFromAudioQueue(SDL_AudioQueue *queue, + Uint8 *dst, SDL_AudioFormat dst_format, int dst_channels, const int *dst_map, + int past_frames, int present_frames, int future_frames, + Uint8 *scratch, float gain); // Get the total number of bytes currently queued -size_t SDL_GetAudioQueueQueued(SDL_AudioQueue *queue); +extern size_t SDL_GetAudioQueueQueued(SDL_AudioQueue *queue); -int SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames); +extern bool SDL_ResetAudioQueueHistory(SDL_AudioQueue *queue, int num_frames); #endif // SDL_audioqueue_h_ diff --git a/src/audio/SDL_audioresample.c b/src/audio/SDL_audioresample.c index 98cf399fb4..f1660f7b1c 100644 --- a/src/audio/SDL_audioresample.c +++ b/src/audio/SDL_audioresample.c @@ -613,24 +613,24 @@ int SDL_GetResamplerPaddingFrames(Sint64 resample_rate) } // These are not general purpose. They do not check for all possible underflow/overflow -SDL_FORCE_INLINE Sint64 ResamplerAdd(Sint64 a, Sint64 b, Sint64 *ret) +SDL_FORCE_INLINE bool ResamplerAdd(Sint64 a, Sint64 b, Sint64 *ret) { if ((b > 0) && (a > SDL_MAX_SINT64 - b)) { - return -1; + return false; } *ret = a + b; - return 0; + return true; } -SDL_FORCE_INLINE Sint64 ResamplerMul(Sint64 a, Sint64 b, Sint64 *ret) +SDL_FORCE_INLINE bool ResamplerMul(Sint64 a, Sint64 b, Sint64 *ret) { if ((b > 0) && (a > SDL_MAX_SINT64 / b)) { - return -1; + return false; } *ret = a * b; - return 0; + return true; } Sint64 SDL_GetResamplerInputFrames(Sint64 output_frames, Sint64 resample_rate, Sint64 resample_offset) @@ -639,8 +639,8 @@ Sint64 SDL_GetResamplerInputFrames(Sint64 output_frames, Sint64 resample_rate, S // ((((output_frames - 1) * resample_rate) + resample_offset) >> 32) + 1 Sint64 output_offset; - if (ResamplerMul(output_frames, resample_rate, &output_offset) || - ResamplerAdd(output_offset, -resample_rate + resample_offset + 0x100000000, &output_offset)) { + if (!ResamplerMul(output_frames, resample_rate, &output_offset) || + !ResamplerAdd(output_offset, -resample_rate + resample_offset + 0x100000000, &output_offset)) { output_offset = SDL_MAX_SINT64; } @@ -656,8 +656,8 @@ Sint64 SDL_GetResamplerOutputFrames(Sint64 input_frames, Sint64 resample_rate, S // input_offset = (input_frames << 32) - resample_offset; Sint64 input_offset; - if (ResamplerMul(input_frames, 0x100000000, &input_offset) || - ResamplerAdd(input_offset, -resample_offset, &input_offset)) { + if (!ResamplerMul(input_frames, 0x100000000, &input_offset) || + !ResamplerAdd(input_offset, -resample_offset, &input_offset)) { input_offset = SDL_MAX_SINT64; } diff --git a/src/audio/SDL_mixer.c b/src/audio/SDL_mixer.c index ec7e948259..920b566802 100644 --- a/src/audio/SDL_mixer.c +++ b/src/audio/SDL_mixer.c @@ -86,13 +86,12 @@ static const Uint8 mix8[] = { // !!! FIXME: Add fast-path for volume = 1 // !!! FIXME: Use larger scales for 16-bit/32-bit integers -int SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, - Uint32 len, float fvolume) +SDL_bool SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, Uint32 len, float fvolume) { int volume = (int)SDL_roundf(fvolume * MIX_MAXVOLUME); if (volume == 0) { - return 0; + return true; } switch (format) { @@ -287,5 +286,5 @@ int SDL_MixAudio(Uint8 *dst, const Uint8 *src, SDL_AudioFormat format, return SDL_SetError("SDL_MixAudio(): unknown audio format"); } - return 0; + return true; } diff --git a/src/audio/SDL_sysaudio.h b/src/audio/SDL_sysaudio.h index 5a66440bf6..fc8ddd0325 100644 --- a/src/audio/SDL_sysaudio.h +++ b/src/audio/SDL_sysaudio.h @@ -54,7 +54,7 @@ typedef struct SDL_AudioDevice SDL_AudioDevice; typedef struct SDL_LogicalAudioDevice SDL_LogicalAudioDevice; // Used by src/SDL.c to initialize a particular audio driver. -extern int SDL_InitAudio(const char *driver_name); +extern bool SDL_InitAudio(const char *driver_name); // Used by src/SDL.c to shut down previously-initialized audio. extern void SDL_QuitAudio(void); @@ -79,10 +79,10 @@ extern void SDL_AudioDeviceDisconnected(SDL_AudioDevice *device); extern void SDL_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device); // Backends should call this if a device's format is changing (opened or not); SDL will update state and carry on with the new format. -extern int SDL_AudioDeviceFormatChanged(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames); +extern bool SDL_AudioDeviceFormatChanged(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames); // Same as above, but assume the device is already locked. -extern int SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames); +extern bool SDL_AudioDeviceFormatChangedAlreadyLocked(SDL_AudioDevice *device, const SDL_AudioSpec *newspec, int new_sample_frames); // Find the SDL_AudioDevice associated with the handle supplied to SDL_AddAudioDevice. NULL if not found. DOES NOT LOCK THE DEVICE. extern SDL_AudioDevice *SDL_FindPhysicalAudioDeviceByHandle(void *handle); @@ -138,19 +138,19 @@ extern void OnAudioStreamDestroy(SDL_AudioStream *stream); extern int SDL_GetAudioStreamDataAdjustGain(SDL_AudioStream *stream, void *voidbuf, int len, float extra_gain); // This is the bulk of `SDL_SetAudioStream*putChannelMap`'s work, but it lets you skip the check about changing the device end of a stream if isinput==-1. -extern int SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, int isinput); +extern bool SetAudioStreamChannelMap(SDL_AudioStream *stream, const SDL_AudioSpec *spec, int **stream_chmap, const int *chmap, int channels, int isinput); typedef struct SDL_AudioDriverImpl { void (*DetectDevices)(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording); - int (*OpenDevice)(SDL_AudioDevice *device); + bool (*OpenDevice)(SDL_AudioDevice *device); void (*ThreadInit)(SDL_AudioDevice *device); // Called by audio thread at start void (*ThreadDeinit)(SDL_AudioDevice *device); // Called by audio thread at end - int (*WaitDevice)(SDL_AudioDevice *device); - int (*PlayDevice)(SDL_AudioDevice *device, const Uint8 *buffer, int buflen); // buffer and buflen are always from GetDeviceBuf, passed here for convenience. + bool (*WaitDevice)(SDL_AudioDevice *device); + bool (*PlayDevice)(SDL_AudioDevice *device, const Uint8 *buffer, int buflen); // buffer and buflen are always from GetDeviceBuf, passed here for convenience. Uint8 *(*GetDeviceBuf)(SDL_AudioDevice *device, int *buffer_size); - int (*WaitRecordingDevice)(SDL_AudioDevice *device); + bool (*WaitRecordingDevice)(SDL_AudioDevice *device); int (*RecordDevice)(SDL_AudioDevice *device, void *buffer, int buflen); void (*FlushRecording)(SDL_AudioDevice *device); void (*CloseDevice)(SDL_AudioDevice *device); @@ -282,10 +282,10 @@ struct SDL_AudioDevice SDL_AtomicInt refcount; // These are, initially, set from current_audio, but we might swap them out with Zombie versions on disconnect/failure. - int (*WaitDevice)(SDL_AudioDevice *device); - int (*PlayDevice)(SDL_AudioDevice *device, const Uint8 *buffer, int buflen); + bool (*WaitDevice)(SDL_AudioDevice *device); + bool (*PlayDevice)(SDL_AudioDevice *device, const Uint8 *buffer, int buflen); Uint8 *(*GetDeviceBuf)(SDL_AudioDevice *device, int *buffer_size); - int (*WaitRecordingDevice)(SDL_AudioDevice *device); + bool (*WaitRecordingDevice)(SDL_AudioDevice *device); int (*RecordDevice)(SDL_AudioDevice *device, void *buffer, int buflen); void (*FlushRecording)(SDL_AudioDevice *device); diff --git a/src/audio/SDL_wave.c b/src/audio/SDL_wave.c index f87837058b..88e71fd1db 100644 --- a/src/audio/SDL_wave.c +++ b/src/audio/SDL_wave.c @@ -324,7 +324,8 @@ static Sint64 WaveAdjustToFactValue(WaveFile *file, Sint64 sampleframes) { if (file->fact.status == 2) { if (file->facthint == FactStrict && sampleframes < file->fact.samplelength) { - return SDL_SetError("Invalid number of sample frames in WAVE fact chunk (too many)"); + SDL_SetError("Invalid number of sample frames in WAVE fact chunk (too many)"); + return -1; } else if (sampleframes > file->fact.samplelength) { return file->fact.samplelength; } @@ -333,7 +334,7 @@ static Sint64 WaveAdjustToFactValue(WaveFile *file, Sint64 sampleframes) return sampleframes; } -static int MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength) +static bool MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength) { WaveFormat *format = &file->format; const size_t blockheadersize = (size_t)file->format.channels * 7; @@ -366,13 +367,13 @@ static int MS_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength) file->sampleframes = WaveAdjustToFactValue(file, file->sampleframes); if (file->sampleframes < 0) { - return -1; + return false; } - return 0; + return true; } -static int MS_ADPCM_Init(WaveFile *file, size_t datalength) +static bool MS_ADPCM_Init(WaveFile *file, size_t datalength) { WaveFormat *format = &file->format; WaveChunk *chunk = &file->chunk; @@ -440,7 +441,7 @@ static int MS_ADPCM_Init(WaveFile *file, size_t datalength) coeffdata = (MS_ADPCM_CoeffData *)SDL_malloc(sizeof(MS_ADPCM_CoeffData) + coeffcount * 4); file->decoderdata = coeffdata; // Freed in cleanup. if (!coeffdata) { - return -1; + return false; } coeffdata->coeff = &coeffdata->aligndummy; coeffdata->coeffcount = (Uint16)coeffcount; @@ -483,11 +484,11 @@ static int MS_ADPCM_Init(WaveFile *file, size_t datalength) return SDL_SetError("Invalid number of samples per MS ADPCM block (wSamplesPerBlock)"); } - if (MS_ADPCM_CalculateSampleFrames(file, datalength) < 0) { - return -1; + if (!MS_ADPCM_CalculateSampleFrames(file, datalength)) { + return false; } - return 0; + return true; } static Sint16 MS_ADPCM_ProcessNibble(MS_ADPCM_ChannelState *cstate, Sint32 sample1, Sint32 sample2, Uint8 nybble) @@ -526,7 +527,7 @@ static Sint16 MS_ADPCM_ProcessNibble(MS_ADPCM_ChannelState *cstate, Sint32 sampl return (Sint16)new_sample; } -static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) +static bool MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) { Uint8 coeffindex; const Uint32 channels = state->channels; @@ -578,7 +579,7 @@ static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) // Header provided two sample frames. state->framesleft -= 2; - return 0; + return true; } /* Decodes the data of the MS ADPCM block. Decoding will stop if a block is too @@ -586,7 +587,7 @@ static int MS_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) * will always contain full sample frames (same sample count for each channel). * Incomplete sample frames are discarded. */ -static int MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) +static bool MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) { Uint16 nybble = 0; Sint16 sample1, sample2; @@ -613,7 +614,7 @@ static int MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) } else { // Out of input data. Drop the incomplete frame and return. state->output.pos = outpos - c; - return -1; + return false; } // Load previous samples which may come from the block header. @@ -630,12 +631,12 @@ static int MS_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) state->output.pos = outpos; - return 0; + return true; } -static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) +static bool MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) { - int result; + bool result; size_t bytesleft, outputsize; WaveChunk *chunk = &file->chunk; ADPCM_DecoderState state; @@ -646,8 +647,8 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) if (chunk->size != chunk->length) { // Could not read everything. Recalculate number of sample frames. - if (MS_ADPCM_CalculateSampleFrames(file, chunk->size) < 0) { - return -1; + if (!MS_ADPCM_CalculateSampleFrames(file, chunk->size)) { + return false; } } @@ -655,7 +656,7 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) if (file->sampleframes == 0) { *audio_buf = NULL; *audio_len = 0; - return 0; + return true; } state.blocksize = file->format.blockalign; @@ -683,7 +684,7 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) state.output.size = outputsize / sizeof(Sint16); state.output.data = (Sint16 *)SDL_calloc(1, outputsize); if (!state.output.data) { - return -1; + return false; } state.cstate = cstate; @@ -703,14 +704,14 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) // Initialize decoder with the values from the block header. result = MS_ADPCM_DecodeBlockHeader(&state); - if (result < 0) { + if (!result) { SDL_free(state.output.data); - return -1; + return false; } // Decode the block data. It stores the samples directly in the output. result = MS_ADPCM_DecodeBlockData(&state); - if (result < 0) { + if (!result) { // Unexpected end. Stop decoding and return partial data if necessary. if (file->trunchint == TruncVeryStrict || file->trunchint == TruncStrict) { SDL_free(state.output.data); @@ -729,10 +730,10 @@ static int MS_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) *audio_buf = (Uint8 *)state.output.data; *audio_len = (Uint32)outputsize; - return 0; + return true; } -static int IMA_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength) +static bool IMA_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength) { WaveFormat *format = &file->format; const size_t blockheadersize = (size_t)format->channels * 4; @@ -779,13 +780,13 @@ static int IMA_ADPCM_CalculateSampleFrames(WaveFile *file, size_t datalength) file->sampleframes = WaveAdjustToFactValue(file, file->sampleframes); if (file->sampleframes < 0) { - return -1; + return false; } - return 0; + return true; } -static int IMA_ADPCM_Init(WaveFile *file, size_t datalength) +static bool IMA_ADPCM_Init(WaveFile *file, size_t datalength) { WaveFormat *format = &file->format; WaveChunk *chunk = &file->chunk; @@ -843,11 +844,11 @@ static int IMA_ADPCM_Init(WaveFile *file, size_t datalength) return SDL_SetError("Invalid number of samples per IMA ADPCM block (wSamplesPerBlock)"); } - if (IMA_ADPCM_CalculateSampleFrames(file, datalength) < 0) { - return -1; + if (!IMA_ADPCM_CalculateSampleFrames(file, datalength)) { + return false; } - return 0; + return true; } static Sint16 IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 nybble) @@ -919,7 +920,7 @@ static Sint16 IMA_ADPCM_ProcessNibble(Sint8 *cindex, Sint16 lastsample, Uint8 ny return (Sint16)sample; } -static int IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) +static bool IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) { Sint16 step; Uint32 c; @@ -950,7 +951,7 @@ static int IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) // Header provided one sample frame. state->framesleft--; - return 0; + return true; } /* Decodes the data of the IMA ADPCM block. Decoding will stop if a block is too @@ -958,14 +959,14 @@ static int IMA_ADPCM_DecodeBlockHeader(ADPCM_DecoderState *state) * contains full sample frames (same sample count for each channel). * Incomplete sample frames are discarded. */ -static int IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) +static bool IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) { size_t i; - int retval = 0; const Uint32 channels = state->channels; const size_t subblockframesize = (size_t)channels * 4; Uint64 bytesrequired; Uint32 c; + bool result = true; size_t blockpos = state->block.pos; size_t blocksize = state->block.size; @@ -988,7 +989,7 @@ static int IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) blockframesleft += (Sint64)(remainingbytes % 4) * 2; } // Signal the truncation. - retval = -1; + result = false; } /* Each channel has their nibbles packed into 32-bit blocks. These blocks @@ -1024,12 +1025,12 @@ static int IMA_ADPCM_DecodeBlockData(ADPCM_DecoderState *state) state->block.pos = blockpos; state->output.pos = outpos; - return retval; + return result; } -static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) +static bool IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) { - int result; + bool result; size_t bytesleft, outputsize; WaveChunk *chunk = &file->chunk; ADPCM_DecoderState state; @@ -1037,8 +1038,8 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len if (chunk->size != chunk->length) { // Could not read everything. Recalculate number of sample frames. - if (IMA_ADPCM_CalculateSampleFrames(file, chunk->size) < 0) { - return -1; + if (!IMA_ADPCM_CalculateSampleFrames(file, chunk->size)) { + return false; } } @@ -1046,7 +1047,7 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len if (file->sampleframes == 0) { *audio_buf = NULL; *audio_len = 0; - return 0; + return true; } SDL_zero(state); @@ -1074,13 +1075,13 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len state.output.size = outputsize / sizeof(Sint16); state.output.data = (Sint16 *)SDL_malloc(outputsize); if (!state.output.data) { - return -1; + return false; } cstate = (Sint8 *)SDL_calloc(state.channels, sizeof(Sint8)); if (!cstate) { SDL_free(state.output.data); - return -1; + return false; } state.cstate = cstate; @@ -1100,12 +1101,12 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len // Initialize decoder with the values from the block header. result = IMA_ADPCM_DecodeBlockHeader(&state); - if (result == 0) { + if (result) { // Decode the block data. It stores the samples directly in the output. result = IMA_ADPCM_DecodeBlockData(&state); } - if (result < 0) { + if (!result) { // Unexpected end. Stop decoding and return partial data if necessary. if (file->trunchint == TruncVeryStrict || file->trunchint == TruncStrict) { SDL_free(state.output.data); @@ -1127,10 +1128,10 @@ static int IMA_ADPCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len SDL_free(cstate); - return 0; + return true; } -static int LAW_Init(WaveFile *file, size_t datalength) +static bool LAW_Init(WaveFile *file, size_t datalength) { WaveFormat *format = &file->format; @@ -1152,13 +1153,13 @@ static int LAW_Init(WaveFile *file, size_t datalength) file->sampleframes = WaveAdjustToFactValue(file, datalength / format->blockalign); if (file->sampleframes < 0) { - return -1; + return false; } - return 0; + return true; } -static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) +static bool LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) { #ifdef SDL_WAVE_LAW_LUT const Sint16 alaw_lut[256] = { @@ -1208,7 +1209,7 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) if (chunk->length != chunk->size) { file->sampleframes = WaveAdjustToFactValue(file, chunk->size / format->blockalign); if (file->sampleframes < 0) { - return -1; + return false; } } @@ -1216,7 +1217,7 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) if (file->sampleframes == 0) { *audio_buf = NULL; *audio_len = 0; - return 0; + return true; } sample_count = (size_t)file->sampleframes; @@ -1234,7 +1235,7 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) // 1 to avoid allocating zero bytes, to keep static analysis happy. src = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1); if (!src) { - return -1; + return false; } chunk->data = NULL; chunk->size = 0; @@ -1297,10 +1298,10 @@ static int LAW_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) *audio_buf = src; *audio_len = (Uint32)expanded_len; - return 0; + return true; } -static int PCM_Init(WaveFile *file, size_t datalength) +static bool PCM_Init(WaveFile *file, size_t datalength) { WaveFormat *format = &file->format; @@ -1337,13 +1338,13 @@ static int PCM_Init(WaveFile *file, size_t datalength) file->sampleframes = WaveAdjustToFactValue(file, datalength / format->blockalign); if (file->sampleframes < 0) { - return -1; + return false; } - return 0; + return true; } -static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) +static bool PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) { WaveFormat *format = &file->format; WaveChunk *chunk = &file->chunk; @@ -1365,7 +1366,7 @@ static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 * // 1 to avoid allocating zero bytes, to keep static analysis happy. ptr = (Uint8 *)SDL_realloc(chunk->data, expanded_len ? expanded_len : 1); if (!ptr) { - return -1; + return false; } // This pointer is now invalid. @@ -1391,10 +1392,10 @@ static int PCM_ConvertSint24ToSint32(WaveFile *file, Uint8 **audio_buf, Uint32 * ptr[o * 4 + 3] = b[3]; } - return 0; + return true; } -static int PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) +static bool PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) { WaveFormat *format = &file->format; WaveChunk *chunk = &file->chunk; @@ -1403,7 +1404,7 @@ static int PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) if (chunk->length != chunk->size) { file->sampleframes = WaveAdjustToFactValue(file, chunk->size / format->blockalign); if (file->sampleframes < 0) { - return -1; + return false; } } @@ -1411,7 +1412,7 @@ static int PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) if (file->sampleframes == 0) { *audio_buf = NULL; *audio_len = 0; - return 0; + return true; } // 24-bit samples get shifted to 32 bits. @@ -1433,7 +1434,7 @@ static int PCM_Decode(WaveFile *file, Uint8 **audio_buf, Uint32 *audio_len) chunk->data = NULL; chunk->size = 0; - return 0; + return true; } static WaveRiffSizeHint WaveGetRiffSizeHint(void) @@ -1598,7 +1599,7 @@ static Uint16 WaveGetFormatGUIDEncoding(WaveFormat *format) return UNKNOWN_CODE; } -static int WaveReadFormat(WaveFile *file) +static bool WaveReadFormat(WaveFile *file) { WaveChunk *chunk = &file->chunk; WaveFormat *format = &file->format; @@ -1611,7 +1612,7 @@ static int WaveReadFormat(WaveFile *file) } fmtsrc = SDL_IOFromConstMem(chunk->data, (int)chunk->size); if (!fmtsrc) { - return -1; + return false; } if (!SDL_ReadU16LE(fmtsrc, &format->formattag) || @@ -1619,14 +1620,14 @@ static int WaveReadFormat(WaveFile *file) !SDL_ReadU32LE(fmtsrc, &format->frequency) || !SDL_ReadU32LE(fmtsrc, &format->byterate) || !SDL_ReadU16LE(fmtsrc, &format->blockalign)) { - return -1; + return false; } format->encoding = format->formattag; // This is PCM specific in the first version of the specification. if (fmtlen >= 16) { if (!SDL_ReadU16LE(fmtsrc, &format->bitspersample)) { - return -1; + return false; } } else if (format->encoding == PCM_CODE) { SDL_CloseIO(fmtsrc); @@ -1636,7 +1637,7 @@ static int WaveReadFormat(WaveFile *file) // The earlier versions also don't have this field. if (fmtlen >= 18) { if (!SDL_ReadU16LE(fmtsrc, &format->extsize)) { - return -1; + return false; } } @@ -1663,10 +1664,10 @@ static int WaveReadFormat(WaveFile *file) SDL_CloseIO(fmtsrc); - return 0; + return true; } -static int WaveCheckFormat(WaveFile *file, size_t datalength) +static bool WaveCheckFormat(WaveFile *file, size_t datalength) { WaveFormat *format = &file->format; @@ -1731,24 +1732,24 @@ static int WaveCheckFormat(WaveFile *file, size_t datalength) switch (format->encoding) { case PCM_CODE: case IEEE_FLOAT_CODE: - if (PCM_Init(file, datalength) < 0) { - return -1; + if (!PCM_Init(file, datalength)) { + return false; } break; case ALAW_CODE: case MULAW_CODE: - if (LAW_Init(file, datalength) < 0) { - return -1; + if (!LAW_Init(file, datalength)) { + return false; } break; case MS_ADPCM_CODE: - if (MS_ADPCM_Init(file, datalength) < 0) { - return -1; + if (!MS_ADPCM_Init(file, datalength)) { + return false; } break; case IMA_ADPCM_CODE: - if (IMA_ADPCM_Init(file, datalength) < 0) { - return -1; + if (!IMA_ADPCM_Init(file, datalength)) { + return false; } break; case MPEG_CODE: @@ -1766,10 +1767,10 @@ static int WaveCheckFormat(WaveFile *file, size_t datalength) return SDL_SetError("Unknown WAVE format tag: 0x%04x", (unsigned int)format->encoding); } - return 0; + return true; } -static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) +static bool WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) { int result; Uint32 chunkcount = 0; @@ -1965,10 +1966,10 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint return SDL_SetError("Invalid WAVE fmt chunk length (too small)"); } else if (chunk->size < 14) { return SDL_SetError("Could not read data of WAVE fmt chunk"); - } else if (WaveReadFormat(file) < 0) { - return -1; - } else if (WaveCheckFormat(file, (size_t)datachunk.length) < 0) { - return -1; + } else if (!WaveReadFormat(file)) { + return false; + } else if (!WaveCheckFormat(file, (size_t)datachunk.length)) { + return false; } #ifdef SDL_WAVE_DEBUG_LOG_FORMAT @@ -1986,7 +1987,7 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint if (chunk->length > 0) { result = WaveReadChunkData(src, chunk); if (result < 0) { - return -1; + return false; } else if (result == -2) { return SDL_SetError("Could not seek data of WAVE data chunk"); } @@ -2004,24 +2005,24 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint switch (format->encoding) { case PCM_CODE: case IEEE_FLOAT_CODE: - if (PCM_Decode(file, audio_buf, audio_len) < 0) { - return -1; + if (!PCM_Decode(file, audio_buf, audio_len)) { + return false; } break; case ALAW_CODE: case MULAW_CODE: - if (LAW_Decode(file, audio_buf, audio_len) < 0) { - return -1; + if (!LAW_Decode(file, audio_buf, audio_len)) { + return false; } break; case MS_ADPCM_CODE: - if (MS_ADPCM_Decode(file, audio_buf, audio_len) < 0) { - return -1; + if (!MS_ADPCM_Decode(file, audio_buf, audio_len)) { + return false; } break; case IMA_ADPCM_CODE: - if (IMA_ADPCM_Decode(file, audio_buf, audio_len) < 0) { - return -1; + if (!IMA_ADPCM_Decode(file, audio_buf, audio_len)) { + return false; } break; } @@ -2072,12 +2073,12 @@ static int WaveLoad(SDL_IOStream *src, WaveFile *file, SDL_AudioSpec *spec, Uint chunk->position = lastchunkpos; } - return 0; + return true; } -int SDL_LoadWAV_IO(SDL_IOStream *src, SDL_bool closeio, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) +SDL_bool SDL_LoadWAV_IO(SDL_IOStream *src, SDL_bool closeio, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) { - int result = -1; + bool result = false; WaveFile file; if (spec) { @@ -2110,7 +2111,7 @@ int SDL_LoadWAV_IO(SDL_IOStream *src, SDL_bool closeio, SDL_AudioSpec *spec, Uin file.facthint = WaveGetFactChunkHint(); result = WaveLoad(src, &file, spec, audio_buf, audio_len); - if (result < 0) { + if (!result) { SDL_free(*audio_buf); audio_buf = NULL; audio_len = 0; @@ -2129,7 +2130,7 @@ done: return result; } -int SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) +SDL_bool SDL_LoadWAV(const char *path, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len) { return SDL_LoadWAV_IO(SDL_IOFromFile(path, "rb"), 1, spec, audio_buf, audio_len); } diff --git a/src/audio/aaudio/SDL_aaudio.c b/src/audio/aaudio/SDL_aaudio.c index 0207a2d118..260ea6e14c 100644 --- a/src/audio/aaudio/SDL_aaudio.c +++ b/src/audio/aaudio/SDL_aaudio.c @@ -62,7 +62,7 @@ typedef struct AAUDIO_Data } AAUDIO_Data; static AAUDIO_Data ctx; -static int AAUDIO_LoadFunctions(AAUDIO_Data *data) +static bool AAUDIO_LoadFunctions(AAUDIO_Data *data) { #define SDL_PROC(ret, func, params) \ do { \ @@ -72,7 +72,7 @@ static int AAUDIO_LoadFunctions(AAUDIO_Data *data) } \ } while (0); #include "SDL_aaudiofuncs.h" - return 0; + return true; } @@ -162,26 +162,21 @@ static Uint8 *AAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *bufsize) return &hidden->mixbuf[offset]; } -static int AAUDIO_WaitDevice(SDL_AudioDevice *device) +static bool AAUDIO_WaitDevice(SDL_AudioDevice *device) { while (!SDL_AtomicGet(&device->shutdown)) { // this semaphore won't fire when the app is in the background (AAUDIO_PauseDevices was called). - const int rc = SDL_WaitSemaphoreTimeout(device->hidden->semaphore, 100); - if (rc == -1) { // uh, what? - return -1; - } else if (rc == 0) { - return 0; // semaphore was signaled, let's go! - } else { - SDL_assert(rc == SDL_MUTEX_TIMEDOUT); + if (SDL_WaitSemaphoreTimeout(device->hidden->semaphore, 100)) { + return true; // semaphore was signaled, let's go! } // Still waiting on the semaphore (or the system), check other things then wait again. } - return 0; + return true; } -static int BuildAAudioStream(SDL_AudioDevice *device); +static bool BuildAAudioStream(SDL_AudioDevice *device); -static int RecoverAAudioDevice(SDL_AudioDevice *device) +static bool RecoverAAudioDevice(SDL_AudioDevice *device) { struct SDL_PrivateAudioData *hidden = device->hidden; @@ -200,8 +195,8 @@ static int RecoverAAudioDevice(SDL_AudioDevice *device) SDL_AudioSpec prevspec; SDL_copyp(&prevspec, &device->spec); - if (BuildAAudioStream(device) < 0) { - return -1; // oh well, we tried. + if (!BuildAAudioStream(device)) { + return false; // oh well, we tried. } // we don't know the new device spec until we open the new device, so we saved off the old one and force it back @@ -212,14 +207,14 @@ static int RecoverAAudioDevice(SDL_AudioDevice *device) device->sample_frames = prev_sample_frames; SDL_copyp(&device->spec, &prevspec); - if (SDL_AudioDeviceFormatChangedAlreadyLocked(device, &newspec, new_sample_frames) < 0) { - return -1; // ugh + if (!SDL_AudioDeviceFormatChangedAlreadyLocked(device, &newspec, new_sample_frames)) { + return false; // ugh } - return 0; + return true; } -static int AAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool AAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { struct SDL_PrivateAudioData *hidden = device->hidden; @@ -228,14 +223,14 @@ static int AAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int b if (err) { SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "aaudio: Audio device triggered error %d (%s)", (int) err, ctx.AAudio_convertResultToText(err)); - if (RecoverAAudioDevice(device) < 0) { - return -1; // oh well, we went down hard. + if (!RecoverAAudioDevice(device)) { + return false; // oh well, we went down hard. } } else { SDL_MemoryBarrierRelease(); hidden->processed_bytes += buflen; } - return 0; + return true; } static int AAUDIO_RecordDevice(SDL_AudioDevice *device, void *buffer, int buflen) @@ -279,7 +274,7 @@ static void AAUDIO_CloseDevice(SDL_AudioDevice *device) } } -static int BuildAAudioStream(SDL_AudioDevice *device) +static bool BuildAAudioStream(SDL_AudioDevice *device) { struct SDL_PrivateAudioData *hidden = device->hidden; const bool recording = device->recording; @@ -365,7 +360,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device) hidden->mixbuf_bytes = (hidden->num_buffers * device->buffer_size); hidden->mixbuf = (Uint8 *)SDL_aligned_alloc(SDL_GetSIMDAlignment(), hidden->mixbuf_bytes); if (!hidden->mixbuf) { - return -1; + return false; } hidden->processed_bytes = 0; hidden->callback_bytes = 0; @@ -373,7 +368,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device) hidden->semaphore = SDL_CreateSemaphore(recording ? 0 : hidden->num_buffers); if (!hidden->semaphore) { LOGI("SDL Failed SDL_CreateSemaphore %s recording:%d", SDL_GetError(), recording); - return -1; + return false; } LOGI("AAudio Actually opened %u hz %u bit chan %u %s samples %u, buffers %d", @@ -388,7 +383,7 @@ static int BuildAAudioStream(SDL_AudioDevice *device) LOGI("SDL AAudioStream_requestStart OK"); - return 0; + return true; } // !!! FIXME: make this non-blocking! @@ -397,7 +392,7 @@ static void SDLCALL RequestAndroidPermissionBlockingCallback(void *userdata, con SDL_AtomicSet((SDL_AtomicInt *) userdata, granted ? 1 : -1); } -static int AAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool AAUDIO_OpenDevice(SDL_AudioDevice *device) { #if ALLOW_MULTIPLE_ANDROID_AUDIO_DEVICES SDL_assert(device->handle); // AAUDIO_UNSPECIFIED is zero, so legit devices should all be non-zero. @@ -409,8 +404,8 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device) // !!! FIXME: make this non-blocking! SDL_AtomicInt permission_response; SDL_AtomicSet(&permission_response, 0); - if (SDL_RequestAndroidPermission("android.permission.RECORD_AUDIO", RequestAndroidPermissionBlockingCallback, &permission_response) == -1) { - return -1; + if (!SDL_RequestAndroidPermission("android.permission.RECORD_AUDIO", RequestAndroidPermissionBlockingCallback, &permission_response)) { + return false; } while (SDL_AtomicGet(&permission_response) == 0) { @@ -425,7 +420,7 @@ static int AAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } return BuildAAudioStream(device); @@ -519,7 +514,7 @@ static bool AAUDIO_Init(SDL_AudioDriverImpl *impl) return false; } - if (AAUDIO_LoadFunctions(&ctx) < 0) { + if (!AAUDIO_LoadFunctions(&ctx)) { SDL_UnloadObject(ctx.handle); SDL_zero(ctx); return false; diff --git a/src/audio/alsa/SDL_alsa_audio.c b/src/audio/alsa/SDL_alsa_audio.c index 04ba46abdd..bf52cea7f0 100644 --- a/src/audio/alsa/SDL_alsa_audio.c +++ b/src/audio/alsa/SDL_alsa_audio.c @@ -93,26 +93,26 @@ static int (*ALSA_snd_pcm_chmap_print)(const snd_pcm_chmap_t *map, size_t maxlen static const char *alsa_library = SDL_AUDIO_DRIVER_ALSA_DYNAMIC; static void *alsa_handle = NULL; -static int load_alsa_sym(const char *fn, void **addr) +static bool load_alsa_sym(const char *fn, void **addr) { *addr = SDL_LoadFunction(alsa_handle, fn); if (!*addr) { // Don't call SDL_SetError(): SDL_LoadFunction already did. - return 0; + return false; } - return 1; + return true; } // cast funcs to char* first, to please GCC's strict aliasing rules. #define SDL_ALSA_SYM(x) \ if (!load_alsa_sym(#x, (void **)(char *)&ALSA_##x)) \ - return -1 + return false #else #define SDL_ALSA_SYM(x) ALSA_##x = x #endif -static int load_alsa_syms(void) +static bool load_alsa_syms(void) { SDL_ALSA_SYM(snd_pcm_open); SDL_ALSA_SYM(snd_pcm_close); @@ -156,7 +156,7 @@ static int load_alsa_syms(void) SDL_ALSA_SYM(snd_pcm_chmap_print); #endif - return 0; + return true; } #undef SDL_ALSA_SYM @@ -171,17 +171,17 @@ static void UnloadALSALibrary(void) } } -static int LoadALSALibrary(void) +static bool LoadALSALibrary(void) { - int retval = 0; + bool retval = true; if (!alsa_handle) { alsa_handle = SDL_LoadObject(alsa_library); if (!alsa_handle) { - retval = -1; + retval = false; // Don't call SDL_SetError(): SDL_LoadObject already did. } else { retval = load_alsa_syms(); - if (retval < 0) { + if (!retval) { UnloadALSALibrary(); } } @@ -195,10 +195,10 @@ static void UnloadALSALibrary(void) { } -static int LoadALSALibrary(void) +static bool LoadALSALibrary(void) { load_alsa_syms(); - return 0; + return true; } #endif // SDL_AUDIO_DRIVER_ALSA_DYNAMIC @@ -260,7 +260,7 @@ static const int swizzle_alsa_channels_8[8] = { 0, 1, 6, 7, 2, 3, 4, 5 }; // This function waits until it is possible to write a full sound buffer -static int ALSA_WaitDevice(SDL_AudioDevice *device) +static bool ALSA_WaitDevice(SDL_AudioDevice *device) { const int fulldelay = (int) ((((Uint64) device->sample_frames) * 1000) / device->spec.freq); const int delay = SDL_max(fulldelay, 10); @@ -272,7 +272,7 @@ static int ALSA_WaitDevice(SDL_AudioDevice *device) if (status < 0) { // Hmm, not much we can do - abort SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "ALSA: snd_pcm_wait failed (unrecoverable): %s", ALSA_snd_strerror(rc)); - return -1; + return false; } continue; } @@ -284,10 +284,10 @@ static int ALSA_WaitDevice(SDL_AudioDevice *device) // Timed out! Make sure we aren't shutting down and then wait again. } - return 0; + return true; } -static int ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { SDL_assert(buffer == device->hidden->mixbuf); Uint8 *sample_buf = (Uint8 *) buffer; // !!! FIXME: deal with this without casting away constness @@ -304,7 +304,7 @@ static int ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buf if (status < 0) { // Hmm, not much we can do - abort SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "ALSA write failed (unrecoverable): %s", ALSA_snd_strerror(rc)); - return -1; + return false; } continue; } @@ -313,7 +313,7 @@ static int ALSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buf frames_left -= rc; } - return 0; + return true; } static Uint8 *ALSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -434,7 +434,7 @@ static int ALSA_set_buffer_size(SDL_AudioDevice *device, snd_pcm_hw_params_t *pa return 0; } -static int ALSA_OpenDevice(SDL_AudioDevice *device) +static bool ALSA_OpenDevice(SDL_AudioDevice *device) { const bool recording = device->recording; int status = 0; @@ -442,7 +442,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // Open the audio device @@ -559,7 +559,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device) if (swizmap) { device->chmap = SDL_ChannelMapDup(swizmap, channels); if (!device->chmap) { - return -1; + return false; } } @@ -606,7 +606,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device) if (!recording) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return -1; + return false; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } @@ -619,7 +619,7 @@ static int ALSA_OpenDevice(SDL_AudioDevice *device) ALSA_snd_pcm_start(pcm_handle); - return 0; // We're ready to rock and roll. :-) + return true; // We're ready to rock and roll. :-) } static void add_device(const bool recording, const char *name, void *hint, ALSA_Device **pSeen) @@ -889,7 +889,7 @@ static void ALSA_Deinitialize(void) static bool ALSA_Init(SDL_AudioDriverImpl *impl) { - if (LoadALSALibrary() < 0) { + if (!LoadALSALibrary()) { return false; } diff --git a/src/audio/coreaudio/SDL_coreaudio.m b/src/audio/coreaudio/SDL_coreaudio.m index 1da1156b41..ecf185decc 100644 --- a/src/audio/coreaudio/SDL_coreaudio.m +++ b/src/audio/coreaudio/SDL_coreaudio.m @@ -548,7 +548,7 @@ static bool UpdateAudioSession(SDL_AudioDevice *device, bool open, bool allow_pl #endif -static int COREAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) +static bool COREAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { AudioQueueBufferRef current_buffer = device->hidden->current_buffer; SDL_assert(current_buffer != NULL); // should have been called from PlaybackBufferReadyCallback @@ -556,7 +556,7 @@ static int COREAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, in current_buffer->mAudioDataByteSize = current_buffer->mAudioDataBytesCapacity; device->hidden->current_buffer = NULL; AudioQueueEnqueueBuffer(device->hidden->audioQueue, current_buffer, 0, NULL); - return 0; + return true; } static Uint8 *COREAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -660,7 +660,7 @@ static void COREAUDIO_CloseDevice(SDL_AudioDevice *device) } #ifdef MACOSX_COREAUDIO -static int PrepareDevice(SDL_AudioDevice *device) +static bool PrepareDevice(SDL_AudioDevice *device) { SDL_assert(device->handle != NULL); // this meant "system default" in SDL2, but doesn't anymore @@ -696,10 +696,10 @@ static int PrepareDevice(SDL_AudioDevice *device) device->hidden->deviceID = devid; - return 0; + return true; } -static int AssignDeviceToAudioQueue(SDL_AudioDevice *device) +static bool AssignDeviceToAudioQueue(SDL_AudioDevice *device) { const AudioObjectPropertyAddress prop = { kAudioDevicePropertyDeviceUID, @@ -715,11 +715,11 @@ static int AssignDeviceToAudioQueue(SDL_AudioDevice *device) result = AudioQueueSetProperty(device->hidden->audioQueue, kAudioQueueProperty_CurrentDevice, &devuid, devuidsize); CFRelease(devuid); // Release devuid; we're done with it and AudioQueueSetProperty should have retained if it wants to keep it. CHECK_RESULT("AudioQueueSetProperty (kAudioQueueProperty_CurrentDevice)"); - return 0; + return true; } #endif -static int PrepareAudioQueue(SDL_AudioDevice *device) +static bool PrepareAudioQueue(SDL_AudioDevice *device) { const AudioStreamBasicDescription *strdesc = &device->hidden->strdesc; const bool recording = device->recording; @@ -736,8 +736,8 @@ static int PrepareAudioQueue(SDL_AudioDevice *device) } #ifdef MACOSX_COREAUDIO - if (AssignDeviceToAudioQueue(device) < 0) { - return -1; + if (!AssignDeviceToAudioQueue(device)) { + return false; } #endif @@ -796,7 +796,7 @@ static int PrepareAudioQueue(SDL_AudioDevice *device) device->hidden->numAudioBuffers = numAudioBuffers; device->hidden->audioBuffer = SDL_calloc(numAudioBuffers, sizeof(AudioQueueBufferRef)); if (device->hidden->audioBuffer == NULL) { - return -1; + return false; } #if DEBUG_COREAUDIO @@ -816,7 +816,7 @@ static int PrepareAudioQueue(SDL_AudioDevice *device) result = AudioQueueStart(device->hidden->audioQueue, NULL); CHECK_RESULT("AudioQueueStart"); - return 0; // We're running! + return true; // We're running! } static int AudioQueueThreadEntry(void *arg) @@ -829,7 +829,7 @@ static int AudioQueueThreadEntry(void *arg) SDL_PlaybackAudioThreadSetup(device); } - if (PrepareAudioQueue(device) < 0) { + if (!PrepareAudioQueue(device)) { device->hidden->thread_error = SDL_strdup(SDL_GetError()); SDL_SignalSemaphore(device->hidden->ready_semaphore); return 0; @@ -855,17 +855,17 @@ static int AudioQueueThreadEntry(void *arg) return 0; } -static int COREAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool COREAUDIO_OpenDevice(SDL_AudioDevice *device) { // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (device->hidden == NULL) { - return -1; + return false; } #ifndef MACOSX_COREAUDIO if (!UpdateAudioSession(device, true, true)) { - return -1; + return false; } // Stop CoreAudio from doing expensive audio rate conversion @@ -935,22 +935,22 @@ static int COREAUDIO_OpenDevice(SDL_AudioDevice *device) strdesc->mBytesPerPacket = strdesc->mBytesPerFrame * strdesc->mFramesPerPacket; #ifdef MACOSX_COREAUDIO - if (PrepareDevice(device) < 0) { - return -1; + if (!PrepareDevice(device)) { + return false; } #endif // This has to init in a new thread so it can get its own CFRunLoop. :/ device->hidden->ready_semaphore = SDL_CreateSemaphore(0); if (!device->hidden->ready_semaphore) { - return -1; // oh well. + return false; // oh well. } char threadname[64]; SDL_GetAudioThreadName(device, threadname, sizeof(threadname)); device->hidden->thread = SDL_CreateThread(AudioQueueThreadEntry, threadname, device); if (!device->hidden->thread) { - return -1; + return false; } SDL_WaitSemaphore(device->hidden->ready_semaphore); @@ -963,7 +963,7 @@ static int COREAUDIO_OpenDevice(SDL_AudioDevice *device) return SDL_SetError("%s", device->hidden->thread_error); } - return (device->hidden->thread != NULL) ? 0 : -1; + return (device->hidden->thread != NULL); } static void COREAUDIO_DeinitializeStart(void) diff --git a/src/audio/directsound/SDL_directsound.c b/src/audio/directsound/SDL_directsound.c index 729d2e5be8..43a2b79ee4 100644 --- a/src/audio/directsound/SDL_directsound.c +++ b/src/audio/directsound/SDL_directsound.c @@ -72,9 +72,9 @@ static void DSOUND_Unload(void) } } -static int DSOUND_Load(void) +static bool DSOUND_Load(void) { - int loaded = 0; + bool loaded = false; DSOUND_Unload(); @@ -87,9 +87,9 @@ static int DSOUND_Load(void) { \ p##f = (fn##f)SDL_LoadFunction(DSoundDLL, #f); \ if (!p##f) \ - loaded = 0; \ + loaded = false; \ } - loaded = 1; // will reset if necessary. + loaded = true; // will reset if necessary. DSOUNDLOAD(DirectSoundCreate8); DSOUNDLOAD(DirectSoundEnumerateW); DSOUNDLOAD(DirectSoundCaptureCreate8); @@ -109,7 +109,7 @@ static int DSOUND_Load(void) return loaded; } -static int SetDSerror(const char *function, int code) +static bool SetDSerror(const char *function, int code) { const char *error; @@ -229,7 +229,7 @@ static void DSOUND_DetectDevices(SDL_AudioDevice **default_playback, SDL_AudioDe } -static int DSOUND_WaitDevice(SDL_AudioDevice *device) +static bool DSOUND_WaitDevice(SDL_AudioDevice *device) { /* Semi-busy wait, since we have no way of getting play notification on a primary mixing buffer located in hardware (DirectX 5.0) @@ -255,23 +255,23 @@ static int DSOUND_WaitDevice(SDL_AudioDevice *device) } if ((result != DS_OK) && (result != DSERR_BUFFERLOST)) { - return -1; + return false; } SDL_Delay(1); // not ready yet; sleep a bit. } - return 0; + return true; } -static int DSOUND_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool DSOUND_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { // Unlock the buffer, allowing it to play SDL_assert(buflen == device->buffer_size); if (IDirectSoundBuffer_Unlock(device->hidden->mixbuf, (LPVOID) buffer, buflen, NULL, 0) != DS_OK) { - return -1; + return false; } - return 0; + return true; } static Uint8 *DSOUND_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -333,20 +333,20 @@ static Uint8 *DSOUND_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) return device->hidden->locked_buf; } -static int DSOUND_WaitRecordingDevice(SDL_AudioDevice *device) +static bool DSOUND_WaitRecordingDevice(SDL_AudioDevice *device) { struct SDL_PrivateAudioData *h = device->hidden; while (!SDL_AtomicGet(&device->shutdown)) { DWORD junk, cursor; if (IDirectSoundCaptureBuffer_GetCurrentPosition(h->capturebuf, &junk, &cursor) != DS_OK) { - return -1; + return false; } else if ((cursor / device->buffer_size) != h->lastchunk) { break; } SDL_Delay(1); } - return 0; + return true; } static int DSOUND_RecordDevice(SDL_AudioDevice *device, void *buffer, int buflen) @@ -411,7 +411,7 @@ static void DSOUND_CloseDevice(SDL_AudioDevice *device) number of audio chunks available in the created buffer. This is for playback devices, not recording. */ -static int CreateSecondary(SDL_AudioDevice *device, const DWORD bufsize, WAVEFORMATEX *wfmt) +static bool CreateSecondary(SDL_AudioDevice *device, const DWORD bufsize, WAVEFORMATEX *wfmt) { LPDIRECTSOUND sndObj = device->hidden->sound; LPDIRECTSOUNDBUFFER *sndbuf = &device->hidden->mixbuf; @@ -445,14 +445,14 @@ static int CreateSecondary(SDL_AudioDevice *device, const DWORD bufsize, WAVEFOR (LPVOID)pvAudioPtr2, dwAudioBytes2); } - return 0; // We're ready to go + return true; // We're ready to go } /* This function tries to create a capture buffer, and returns the number of audio chunks available in the created buffer. This is for recording devices, not playback. */ -static int CreateCaptureBuffer(SDL_AudioDevice *device, const DWORD bufsize, WAVEFORMATEX *wfmt) +static bool CreateCaptureBuffer(SDL_AudioDevice *device, const DWORD bufsize, WAVEFORMATEX *wfmt) { LPDIRECTSOUNDCAPTURE capture = device->hidden->capture; LPDIRECTSOUNDCAPTUREBUFFER *capturebuf = &device->hidden->capturebuf; @@ -488,15 +488,15 @@ static int CreateCaptureBuffer(SDL_AudioDevice *device, const DWORD bufsize, WAV device->hidden->lastchunk = cursor / device->buffer_size; #endif - return 0; + return true; } -static int DSOUND_OpenDevice(SDL_AudioDevice *device) +static bool DSOUND_OpenDevice(SDL_AudioDevice *device) { // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // Open the audio device @@ -603,8 +603,8 @@ static int DSOUND_OpenDevice(SDL_AudioDevice *device) wfmt.Format.nBlockAlign = wfmt.Format.nChannels * (wfmt.Format.wBitsPerSample / 8); wfmt.Format.nAvgBytesPerSec = wfmt.Format.nSamplesPerSec * wfmt.Format.nBlockAlign; - const int rc = device->recording ? CreateCaptureBuffer(device, bufsize, (WAVEFORMATEX *)&wfmt) : CreateSecondary(device, bufsize, (WAVEFORMATEX *)&wfmt); - if (rc == 0) { + const bool rc = device->recording ? CreateCaptureBuffer(device, bufsize, (WAVEFORMATEX *)&wfmt) : CreateSecondary(device, bufsize, (WAVEFORMATEX *)&wfmt); + if (rc) { device->hidden->num_buffers = numchunks; break; } @@ -618,14 +618,14 @@ static int DSOUND_OpenDevice(SDL_AudioDevice *device) if (!test_format) { if (tried_format) { - return -1; // CreateSecondary() should have called SDL_SetError(). + return false; // CreateSecondary() should have called SDL_SetError(). } return SDL_SetError("%s: Unsupported audio format", "directsound"); } // Playback buffers will auto-start playing in DSOUND_WaitDevice() - return 0; // good to go. + return true; // good to go. } static void DSOUND_DeinitializeStart(void) @@ -652,7 +652,7 @@ static bool DSOUND_Init(SDL_AudioDriverImpl *impl) } #ifdef HAVE_MMDEVICEAPI_H - SupportsIMMDevice = !(SDL_IMMDevice_Init(NULL) < 0); + SupportsIMMDevice = SDL_IMMDevice_Init(NULL); #endif impl->DetectDevices = DSOUND_DetectDevices; diff --git a/src/audio/disk/SDL_diskaudio.c b/src/audio/disk/SDL_diskaudio.c index 9c1e61338b..bf1e3d4f42 100644 --- a/src/audio/disk/SDL_diskaudio.c +++ b/src/audio/disk/SDL_diskaudio.c @@ -30,22 +30,22 @@ #define DISKDEFAULT_OUTFILE "sdlaudio.raw" #define DISKDEFAULT_INFILE "sdlaudio-in.raw" -static int DISKAUDIO_WaitDevice(SDL_AudioDevice *device) +static bool DISKAUDIO_WaitDevice(SDL_AudioDevice *device) { SDL_Delay(device->hidden->io_delay); - return 0; + return true; } -static int DISKAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) +static bool DISKAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { const int written = (int)SDL_WriteIO(device->hidden->io, buffer, (size_t)buffer_size); if (written != buffer_size) { // If we couldn't write, assume fatal error for now - return -1; + return false; } #ifdef DEBUG_AUDIO SDL_Log("DISKAUDIO: Wrote %d bytes of audio data", (int) written); #endif - return 0; + return true; } static Uint8 *DISKAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -100,14 +100,14 @@ static const char *get_filename(const bool recording) return devname; } -static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool DISKAUDIO_OpenDevice(SDL_AudioDevice *device) { bool recording = device->recording; const char *fname = get_filename(recording); device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } device->hidden->io_delay = ((device->sample_frames * 1000) / device->spec.freq); @@ -123,14 +123,14 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device) // Open the "audio device" device->hidden->io = SDL_IOFromFile(fname, recording ? "rb" : "wb"); if (!device->hidden->io) { - return -1; + return false; } // Allocate mixing buffer if (!recording) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return -1; + return false; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } @@ -138,7 +138,7 @@ static int DISKAUDIO_OpenDevice(SDL_AudioDevice *device) SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO, "You are using the SDL disk i/o audio driver!"); SDL_LogCritical(SDL_LOG_CATEGORY_AUDIO, " %s file [%s].\n", recording ? "Reading from" : "Writing to", fname); - return 0; // We're ready to rock and roll. :-) + return true; // We're ready to rock and roll. :-) } static void DISKAUDIO_DetectDevices(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording) diff --git a/src/audio/dsp/SDL_dspaudio.c b/src/audio/dsp/SDL_dspaudio.c index 8bff53924b..199fecb1d5 100644 --- a/src/audio/dsp/SDL_dspaudio.c +++ b/src/audio/dsp/SDL_dspaudio.c @@ -55,7 +55,7 @@ static void DSP_CloseDevice(SDL_AudioDevice *device) } } -static int DSP_OpenDevice(SDL_AudioDevice *device) +static bool DSP_OpenDevice(SDL_AudioDevice *device) { // Make sure fragment size stays a power of 2, or OSS fails. // (I don't know which of these are actually legal values, though...) @@ -70,7 +70,7 @@ static int DSP_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // Open the audio device; we hardcode the device path in `device->name` for lack of better info, so use that. @@ -191,15 +191,15 @@ static int DSP_OpenDevice(SDL_AudioDevice *device) if (!device->recording) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return -1; + return false; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } - return 0; // We're ready to rock and roll. :-) + return true; // We're ready to rock and roll. :-) } -static int DSP_WaitDevice(SDL_AudioDevice *device) +static bool DSP_WaitDevice(SDL_AudioDevice *device) { const unsigned long ioctlreq = device->recording ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE; struct SDL_PrivateAudioData *h = device->hidden; @@ -213,7 +213,7 @@ static int DSP_WaitDevice(SDL_AudioDevice *device) } // Hmm, not much we can do - abort fprintf(stderr, "dsp WaitDevice ioctl failed (unrecoverable): %s\n", strerror(errno)); - return -1; + return false; } else if (info.bytes < device->buffer_size) { SDL_Delay(10); } else { @@ -221,20 +221,20 @@ static int DSP_WaitDevice(SDL_AudioDevice *device) } } - return 0; + return true; } -static int DSP_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool DSP_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { struct SDL_PrivateAudioData *h = device->hidden; if (write(h->audio_fd, buffer, buflen) == -1) { perror("Audio write"); - return -1; + return false; } #ifdef DEBUG_AUDIO fprintf(stderr, "Wrote %d bytes of audio data\n", h->mixlen); #endif - return 0; + return true; } static Uint8 *DSP_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) diff --git a/src/audio/dummy/SDL_dummyaudio.c b/src/audio/dummy/SDL_dummyaudio.c index 9984d78fe3..c3b01f2007 100644 --- a/src/audio/dummy/SDL_dummyaudio.c +++ b/src/audio/dummy/SDL_dummyaudio.c @@ -29,23 +29,23 @@ #include #endif -static int DUMMYAUDIO_WaitDevice(SDL_AudioDevice *device) +static bool DUMMYAUDIO_WaitDevice(SDL_AudioDevice *device) { SDL_Delay(device->hidden->io_delay); - return 0; + return true; } -static int DUMMYAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool DUMMYAUDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } if (!device->recording) { device->hidden->mixbuf = (Uint8 *) SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return -1; + return false; } } @@ -68,7 +68,7 @@ static int DUMMYAUDIO_OpenDevice(SDL_AudioDevice *device) }, device->recording ? 1 : 0, device->sample_frames, device->spec.freq, device->recording ? SDL_RecordingAudioThreadIterate : SDL_PlaybackAudioThreadIterate, device); #endif - return 0; // we're good; don't change reported device format. + return true; // we're good; don't change reported device format. } static void DUMMYAUDIO_CloseDevice(SDL_AudioDevice *device) diff --git a/src/audio/emscripten/SDL_emscriptenaudio.c b/src/audio/emscripten/SDL_emscriptenaudio.c index 7e0bbfea69..89ddbcd236 100644 --- a/src/audio/emscripten/SDL_emscriptenaudio.c +++ b/src/audio/emscripten/SDL_emscriptenaudio.c @@ -36,7 +36,7 @@ static Uint8 *EMSCRIPTENAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_ return device->hidden->mixbuf; } -static int EMSCRIPTENAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) +static bool EMSCRIPTENAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { const int framelen = SDL_AUDIO_FRAMESIZE(device->spec); MAIN_THREAD_EM_ASM({ @@ -53,7 +53,7 @@ static int EMSCRIPTENAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buff } } }, buffer, buffer_size / framelen); - return 0; + return true; } @@ -138,12 +138,12 @@ static void EMSCRIPTENAUDIO_CloseDevice(SDL_AudioDevice *device) EM_JS_DEPS(sdlaudio, "$autoResumeAudioContext,$dynCall"); -static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) { // based on parts of library_sdl.js // create context - const int result = MAIN_THREAD_EM_ASM_INT({ + const bool result = MAIN_THREAD_EM_ASM_INT({ if (typeof(Module['SDL3']) === 'undefined') { Module['SDL3'] = {}; } @@ -166,10 +166,10 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) } } } - return SDL3.audioContext === undefined ? -1 : 0; + return (SDL3.audioContext !== undefined); }, device->recording); - if (result < 0) { + if (!result) { return SDL_SetError("Web Audio API is not available!"); } @@ -178,7 +178,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // limit to native freq @@ -189,7 +189,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) if (!device->recording) { device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return -1; + return false; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } @@ -294,7 +294,7 @@ static int EMSCRIPTENAUDIO_OpenDevice(SDL_AudioDevice *device) }, device->spec.channels, device->sample_frames, SDL_PlaybackAudioThreadIterate, device); } - return 0; + return true; } static bool EMSCRIPTENAUDIO_Init(SDL_AudioDriverImpl *impl) diff --git a/src/audio/haiku/SDL_haikuaudio.cc b/src/audio/haiku/SDL_haikuaudio.cc index 5de7b81199..5fe6538113 100644 --- a/src/audio/haiku/SDL_haikuaudio.cc +++ b/src/audio/haiku/SDL_haikuaudio.cc @@ -45,14 +45,14 @@ static Uint8 *HAIKUAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) return device->hidden->current_buffer; } -static int HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) +static bool HAIKUAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { // We already wrote our output right into the BSoundPlayer's callback's stream. Just clean up our stuff. SDL_assert(device->hidden->current_buffer != NULL); SDL_assert(device->hidden->current_buffer_len > 0); device->hidden->current_buffer = NULL; device->hidden->current_buffer_len = 0; - return 0; + return true; } // The Haiku callback for handling the audio buffer @@ -102,12 +102,12 @@ static inline void UnmaskSignals(sigset_t * omask) } -static int HAIKUAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool HAIKUAUDIO_OpenDevice(SDL_AudioDevice *device) { // Initialize all variables that we clean on shutdown device->hidden = new SDL_PrivateAudioData; - if (device->hidden == NULL) { - return SDL_OutOfMemory(); + if (!device->hidden) { + return false; } SDL_zerop(device->hidden); @@ -186,7 +186,7 @@ static int HAIKUAUDIO_OpenDevice(SDL_AudioDevice *device) return SDL_SetError("Unable to start Haiku audio"); } - return 0; // We're running! + return true; // We're running! } static void HAIKUAUDIO_Deinitialize(void) @@ -196,7 +196,7 @@ static void HAIKUAUDIO_Deinitialize(void) static bool HAIKUAUDIO_Init(SDL_AudioDriverImpl *impl) { - if (SDL_InitBeApp() < 0) { + if (!SDL_InitBeApp()) { return false; } diff --git a/src/audio/jack/SDL_jackaudio.c b/src/audio/jack/SDL_jackaudio.c index 91f7d0338a..958348ed9d 100644 --- a/src/audio/jack/SDL_jackaudio.c +++ b/src/audio/jack/SDL_jackaudio.c @@ -46,7 +46,7 @@ static int (*JACK_jack_set_process_callback)(jack_client_t *, JackProcessCallbac static int (*JACK_jack_set_sample_rate_callback)(jack_client_t *, JackSampleRateCallback, void *); static int (*JACK_jack_set_buffer_size_callback)(jack_client_t *, JackBufferSizeCallback, void *); -static int load_jack_syms(void); +static bool load_jack_syms(void); #ifdef SDL_AUDIO_DRIVER_JACK_DYNAMIC @@ -54,21 +54,21 @@ static const char *jack_library = SDL_AUDIO_DRIVER_JACK_DYNAMIC; static void *jack_handle = NULL; // !!! FIXME: this is copy/pasted in several places now -static int load_jack_sym(const char *fn, void **addr) +static bool load_jack_sym(const char *fn, void **addr) { *addr = SDL_LoadFunction(jack_handle, fn); if (!*addr) { // Don't call SDL_SetError(): SDL_LoadFunction already did. - return 0; + return false; } - return 1; + return true; } // cast funcs to char* first, to please GCC's strict aliasing rules. #define SDL_JACK_SYM(x) \ if (!load_jack_sym(#x, (void **)(char *)&JACK_##x)) \ - return -1 + return false static void UnloadJackLibrary(void) { @@ -78,22 +78,22 @@ static void UnloadJackLibrary(void) } } -static int LoadJackLibrary(void) +static bool LoadJackLibrary(void) { - int retval = 0; + bool result = true; if (!jack_handle) { jack_handle = SDL_LoadObject(jack_library); if (!jack_handle) { - retval = -1; + result = false; // Don't call SDL_SetError(): SDL_LoadObject already did. } else { - retval = load_jack_syms(); - if (retval < 0) { + result = load_jack_syms(); + if (!result) { UnloadJackLibrary(); } } } - return retval; + return result; } #else @@ -104,15 +104,15 @@ static void UnloadJackLibrary(void) { } -static int LoadJackLibrary(void) +static bool LoadJackLibrary(void) { load_jack_syms(); - return 0; + return true; } #endif // SDL_AUDIO_DRIVER_JACK_DYNAMIC -static int load_jack_syms(void) +static bool load_jack_syms(void) { SDL_JACK_SYM(jack_client_open); SDL_JACK_SYM(jack_client_close); @@ -134,7 +134,7 @@ static int load_jack_syms(void) SDL_JACK_SYM(jack_set_sample_rate_callback); SDL_JACK_SYM(jack_set_buffer_size_callback); - return 0; + return true; } static void jackShutdownCallback(void *arg) // JACK went away; device is lost. @@ -149,7 +149,7 @@ static int jackSampleRateCallback(jack_nframes_t nframes, void *arg) SDL_AudioSpec newspec; SDL_copyp(&newspec, &device->spec); newspec.freq = (int) nframes; - if (SDL_AudioDeviceFormatChanged(device, &newspec, device->sample_frames) < 0) { + if (!SDL_AudioDeviceFormatChanged(device, &newspec, device->sample_frames)) { SDL_AudioDeviceDisconnected(device); } return 0; @@ -161,7 +161,7 @@ static int jackBufferSizeCallback(jack_nframes_t nframes, void *arg) SDL_AudioDevice *device = (SDL_AudioDevice *) arg; SDL_AudioSpec newspec; SDL_copyp(&newspec, &device->spec); - if (SDL_AudioDeviceFormatChanged(device, &newspec, (int) nframes) < 0) { + if (!SDL_AudioDeviceFormatChanged(device, &newspec, (int) nframes)) { SDL_AudioDeviceDisconnected(device); } return 0; @@ -174,7 +174,7 @@ static int jackProcessPlaybackCallback(jack_nframes_t nframes, void *arg) return 0; } -static int JACK_PlayDevice(SDL_AudioDevice *device, const Uint8 *ui8buffer, int buflen) +static bool JACK_PlayDevice(SDL_AudioDevice *device, const Uint8 *ui8buffer, int buflen) { const float *buffer = (float *) ui8buffer; jack_port_t **ports = device->hidden->sdlports; @@ -193,7 +193,7 @@ static int JACK_PlayDevice(SDL_AudioDevice *device, const Uint8 *ui8buffer, int } } - return 0; + return true; } static Uint8 *JACK_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -267,7 +267,7 @@ static const char *GetJackAppName(void) return SDL_GetAppMetadataProperty(SDL_PROP_APP_METADATA_NAME_STRING); } -static int JACK_OpenDevice(SDL_AudioDevice *device) +static bool JACK_OpenDevice(SDL_AudioDevice *device) { /* Note that JACK uses "output" for recording devices (they output audio data to us) and "input" for playback (we input audio data to them). @@ -289,7 +289,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } client = JACK_jack_client_open(GetJackAppName(), JackNoStartServer, &status, NULL); @@ -335,7 +335,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device) device->hidden->iobuffer = (float *)SDL_calloc(1, device->buffer_size); if (!device->hidden->iobuffer) { SDL_free(audio_ports); - return -1; + return false; } } @@ -343,7 +343,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device) device->hidden->sdlports = (jack_port_t **)SDL_calloc(channels, sizeof(jack_port_t *)); if (!device->hidden->sdlports) { SDL_free(audio_ports); - return -1; + return false; } for (i = 0; i < channels; i++) { @@ -390,7 +390,7 @@ static int JACK_OpenDevice(SDL_AudioDevice *device) SDL_free(audio_ports); // We're ready to rock and roll. :-) - return 0; + return true; } static void JACK_Deinitialize(void) @@ -400,7 +400,7 @@ static void JACK_Deinitialize(void) static bool JACK_Init(SDL_AudioDriverImpl *impl) { - if (LoadJackLibrary() < 0) { + if (!LoadJackLibrary()) { return false; } else { // Make sure a JACK server is running and available. @@ -408,8 +408,7 @@ static bool JACK_Init(SDL_AudioDriverImpl *impl) jack_client_t *client = JACK_jack_client_open("SDL", JackNoStartServer, &status, NULL); if (!client) { UnloadJackLibrary(); - SDL_SetError("Can't open JACK client"); - return false; + return SDL_SetError("Can't open JACK client"); } JACK_jack_client_close(client); } diff --git a/src/audio/n3ds/SDL_n3dsaudio.c b/src/audio/n3ds/SDL_n3dsaudio.c index 8ef6579d76..6d3afa3181 100644 --- a/src/audio/n3ds/SDL_n3dsaudio.c +++ b/src/audio/n3ds/SDL_n3dsaudio.c @@ -76,7 +76,7 @@ static void AudioFrameFinished(void *vdevice) contextUnlock(device); } -static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool N3DSAUDIO_OpenDevice(SDL_AudioDevice *device) { Result ndsp_init_res; Uint8 *data_vaddr; @@ -84,18 +84,17 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // Initialise the DSP service ndsp_init_res = ndspInit(); if (R_FAILED(ndsp_init_res)) { if ((R_SUMMARY(ndsp_init_res) == RS_NOTFOUND) && (R_MODULE(ndsp_init_res) == RM_DSP)) { - SDL_SetError("DSP init failed: dspfirm.cdc missing!"); + return SDL_SetError("DSP init failed: dspfirm.cdc missing!"); } else { - SDL_SetError("DSP init failed. Error code: 0x%lX", ndsp_init_res); + return SDL_SetError("DSP init failed. Error code: 0x%lX", ndsp_init_res); } - return -1; } // Initialise internal state @@ -135,7 +134,7 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return -1; + return false; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); @@ -174,10 +173,10 @@ static int N3DSAUDIO_OpenDevice(SDL_AudioDevice *device) ndspSetCallback(AudioFrameFinished, device); dspHook(&dsp_hook, N3DSAUD_DspHook); - return 0; + return true; } -static int N3DSAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool N3DSAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { contextLock(device); @@ -186,7 +185,7 @@ static int N3DSAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, in if (device->hidden->isCancelled || device->hidden->waveBuf[nextbuf].status != NDSP_WBUF_FREE) { contextUnlock(device); - return 0; // !!! FIXME: is this a fatal error? If so, this should return -1. + return true; // !!! FIXME: is this a fatal error? If so, this should return false. } device->hidden->nextbuf = (nextbuf + 1) % NUM_BUFFERS; @@ -198,10 +197,10 @@ static int N3DSAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, in ndspChnWaveBufAdd(0, &device->hidden->waveBuf[nextbuf]); - return 0; + return true; } -static int N3DSAUDIO_WaitDevice(SDL_AudioDevice *device) +static bool N3DSAUDIO_WaitDevice(SDL_AudioDevice *device) { contextLock(device); while (!device->hidden->isCancelled && !SDL_AtomicGet(&device->shutdown) && @@ -209,7 +208,7 @@ static int N3DSAUDIO_WaitDevice(SDL_AudioDevice *device) CondVar_Wait(&device->hidden->cv, &device->hidden->lock); } contextUnlock(device); - return 0; + return true; } static Uint8 *N3DSAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) diff --git a/src/audio/netbsd/SDL_netbsdaudio.c b/src/audio/netbsd/SDL_netbsdaudio.c index 3d3680001c..92c99cd373 100644 --- a/src/audio/netbsd/SDL_netbsdaudio.c +++ b/src/audio/netbsd/SDL_netbsdaudio.c @@ -114,7 +114,7 @@ static void NETBSDAUDIO_Status(SDL_AudioDevice *device) #endif // DEBUG_AUDIO } -static int NETBSDAUDIO_WaitDevice(SDL_AudioDevice *device) +static bool NETBSDAUDIO_WaitDevice(SDL_AudioDevice *device) { const bool recording = device->recording; while (!SDL_AtomicGet(&device->shutdown)) { @@ -126,7 +126,7 @@ static int NETBSDAUDIO_WaitDevice(SDL_AudioDevice *device) } // Hmm, not much we can do - abort fprintf(stderr, "netbsdaudio WaitDevice ioctl failed (unrecoverable): %s\n", strerror(errno)); - return -1; + return false; } const size_t remain = (size_t)((recording ? info.record.seek : info.play.seek) * SDL_AUDIO_BYTESIZE(device->spec.format)); if (!recording && (remain >= device->buffer_size)) { @@ -138,21 +138,21 @@ static int NETBSDAUDIO_WaitDevice(SDL_AudioDevice *device) } } - return 0; + return true; } -static int NETBSDAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool NETBSDAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { struct SDL_PrivateAudioData *h = device->hidden; const int written = write(h->audio_fd, buffer, buflen); if (written != buflen) { // Treat even partial writes as fatal errors. - return -1; + return false; } #ifdef DEBUG_AUDIO fprintf(stderr, "Wrote %d bytes of audio data\n", written); #endif - return 0; + return true; } static Uint8 *NETBSDAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -206,7 +206,7 @@ static void NETBSDAUDIO_CloseDevice(SDL_AudioDevice *device) } } -static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device) { const bool recording = device->recording; int encoding = AUDIO_ENCODING_NONE; @@ -216,7 +216,7 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // Open the audio device; we hardcode the device path in `device->name` for lack of better info, so use that. @@ -294,14 +294,14 @@ static int NETBSDAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->mixlen = device->buffer_size; device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->hidden->mixlen); if (!device->hidden->mixbuf) { - return -1; + return false; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); } NETBSDAUDIO_Status(device); - return 0; // We're ready to rock and roll. :-) + return true; // We're ready to rock and roll. :-) } static bool NETBSDAUDIO_Init(SDL_AudioDriverImpl *impl) diff --git a/src/audio/openslES/SDL_openslES.c b/src/audio/openslES/SDL_openslES.c index d4f9132b2f..7bc083a2ce 100644 --- a/src/audio/openslES/SDL_openslES.c +++ b/src/audio/openslES/SDL_openslES.c @@ -135,7 +135,7 @@ static void OPENSLES_DestroyEngine(void) } } -static int OPENSLES_CreateEngine(void) +static bool OPENSLES_CreateEngine(void) { const SLInterfaceID ids[1] = { SL_IID_VOLUME }; const SLboolean req[1] = { SL_BOOLEAN_FALSE }; @@ -181,11 +181,11 @@ static int OPENSLES_CreateEngine(void) LOGE("RealizeOutputMix failed: %d", result); goto error; } - return 1; + return true; error: OPENSLES_DestroyEngine(); - return 0; + return false; } // this callback handler is called every time a buffer finishes recording @@ -234,7 +234,7 @@ static void SDLCALL RequestAndroidPermissionBlockingCallback(void *userdata, con SDL_AtomicSet((SDL_AtomicInt *) userdata, granted ? 1 : -1); } -static int OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device) +static bool OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device) { struct SDL_PrivateAudioData *audiodata = device->hidden; SLDataFormat_PCM format_pcm; @@ -251,8 +251,8 @@ static int OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device) { SDL_AtomicInt permission_response; SDL_AtomicSet(&permission_response, 0); - if (SDL_RequestAndroidPermission("android.permission.RECORD_AUDIO", RequestAndroidPermissionBlockingCallback, &permission_response) == -1) { - return -1; + if (!SDL_RequestAndroidPermission("android.permission.RECORD_AUDIO", RequestAndroidPermissionBlockingCallback, &permission_response)) { + return false; } while (SDL_AtomicGet(&permission_response) == 0) { @@ -378,7 +378,7 @@ static int OPENSLES_CreatePCMRecorder(SDL_AudioDevice *device) goto failed; } - return 0; + return true; failed: return SDL_SetError("Open device failed!"); @@ -424,7 +424,7 @@ static void OPENSLES_DestroyPCMPlayer(SDL_AudioDevice *device) } } -static int OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device) +static bool OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device) { /* If we want to add floating point audio support (requires API level 21) it can be done as described here: @@ -609,27 +609,27 @@ static int OPENSLES_CreatePCMPlayer(SDL_AudioDevice *device) goto failed; } - return 0; + return true; failed: - return -1; + return false; } -static int OPENSLES_OpenDevice(SDL_AudioDevice *device) +static bool OPENSLES_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } if (device->recording) { LOGI("OPENSLES_OpenDevice() for recording"); return OPENSLES_CreatePCMRecorder(device); } else { - int ret; + bool ret; LOGI("OPENSLES_OpenDevice() for playback"); ret = OPENSLES_CreatePCMPlayer(device); - if (ret < 0) { + if (!ret) { // Another attempt to open the device with a lower frequency if (device->spec.freq > 48000) { OPENSLES_DestroyPCMPlayer(device); @@ -638,15 +638,15 @@ static int OPENSLES_OpenDevice(SDL_AudioDevice *device) } } - if (ret != 0) { + if (!ret) { return SDL_SetError("Open device failed!"); } } - return 0; + return true; } -static int OPENSLES_WaitDevice(SDL_AudioDevice *device) +static bool OPENSLES_WaitDevice(SDL_AudioDevice *device) { struct SDL_PrivateAudioData *audiodata = device->hidden; @@ -654,20 +654,15 @@ static int OPENSLES_WaitDevice(SDL_AudioDevice *device) while (!SDL_AtomicGet(&device->shutdown)) { // this semaphore won't fire when the app is in the background (OPENSLES_PauseDevices was called). - const int rc = SDL_WaitSemaphoreTimeout(audiodata->playsem, 100); - if (rc == -1) { // uh, what? - return -1; - } else if (rc == 0) { - return 0; // semaphore was signaled, let's go! - } else { - SDL_assert(rc == SDL_MUTEX_TIMEDOUT); + if (SDL_WaitSemaphoreTimeout(audiodata->playsem, 100)) { + return true; // semaphore was signaled, let's go! } // Still waiting on the semaphore (or the system), check other things then wait again. } - return 0; + return true; } -static int OPENSLES_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool OPENSLES_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { struct SDL_PrivateAudioData *audiodata = device->hidden; @@ -687,7 +682,7 @@ static int OPENSLES_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int SDL_SignalSemaphore(audiodata->playsem); } - return 0; + return true; } /// n playn sem diff --git a/src/audio/pipewire/SDL_pipewire.c b/src/audio/pipewire/SDL_pipewire.c index 09f02ed441..d60d67d0b4 100644 --- a/src/audio/pipewire/SDL_pipewire.c +++ b/src/audio/pipewire/SDL_pipewire.c @@ -94,26 +94,25 @@ static int (*PIPEWIRE_pw_properties_setf)(struct pw_properties *, const char *, static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC; static void *pipewire_handle = NULL; -static int pipewire_dlsym(const char *fn, void **addr) +static bool pipewire_dlsym(const char *fn, void **addr) { *addr = SDL_LoadFunction(pipewire_handle, fn); if (!*addr) { // Don't call SDL_SetError(): SDL_LoadFunction already did. - return 0; + return false; } - return 1; + return true; } #define SDL_PIPEWIRE_SYM(x) \ - if (!pipewire_dlsym(#x, (void **)(char *)&PIPEWIRE_##x)) { \ - return -1; \ - } + if (!pipewire_dlsym(#x, (void **)(char *)&PIPEWIRE_##x)) \ + return false -static int load_pipewire_library(void) +static bool load_pipewire_library(void) { pipewire_handle = SDL_LoadObject(pipewire_library); - return pipewire_handle ? 0 : -1; + return pipewire_handle ? true : false; } static void unload_pipewire_library(void) @@ -128,9 +127,9 @@ static void unload_pipewire_library(void) #define SDL_PIPEWIRE_SYM(x) PIPEWIRE_##x = x -static int load_pipewire_library(void) +static bool load_pipewire_library(void) { - return 0; + return true; } static void unload_pipewire_library(void) @@ -140,7 +139,7 @@ static void unload_pipewire_library(void) #endif // SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC -static int load_pipewire_syms(void) +static bool load_pipewire_syms(void) { SDL_PIPEWIRE_SYM(pw_get_library_version); SDL_PIPEWIRE_SYM(pw_init); @@ -176,19 +175,19 @@ static int load_pipewire_syms(void) SDL_PIPEWIRE_SYM(pw_properties_set); SDL_PIPEWIRE_SYM(pw_properties_setf); - return 0; + return true; } -static int init_pipewire_library(void) +static bool init_pipewire_library(void) { - if (!load_pipewire_library()) { - if (!load_pipewire_syms()) { + if (load_pipewire_library()) { + if (load_pipewire_syms()) { PIPEWIRE_pw_init(NULL, NULL); - return 0; + return true; } } - return -1; + return false; } static void deinit_pipewire_library(void) @@ -705,7 +704,7 @@ static const struct pw_registry_events registry_events = { PW_VERSION_REGISTRY_E .global_remove = registry_event_remove_callback }; // The hotplug thread -static int hotplug_loop_init(void) +static bool hotplug_loop_init(void) { int res; @@ -745,7 +744,7 @@ static int hotplug_loop_init(void) return SDL_SetError("Pipewire: Failed to start hotplug detection loop"); } - return 0; + return true; } static void hotplug_loop_destroy(void) @@ -896,6 +895,9 @@ static void initialize_spa_info(const SDL_AudioSpec *spec, struct spa_audio_info case SDL_AUDIO_F32BE: info->format = SPA_AUDIO_FORMAT_F32_BE; break; + default: + info->format = SPA_AUDIO_FORMAT_UNKNOWN; + break; } } @@ -920,7 +922,7 @@ static Uint8 *PIPEWIRE_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) return (Uint8 *) spa_buf->datas[0].data; } -static int PIPEWIRE_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) +static bool PIPEWIRE_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { struct pw_stream *stream = device->hidden->stream; struct pw_buffer *pw_buf = device->hidden->pw_buf; @@ -932,7 +934,7 @@ static int PIPEWIRE_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int PIPEWIRE_pw_stream_queue_buffer(stream, pw_buf); device->hidden->pw_buf = NULL; - return 0; + return true; } static void output_callback(void *data) @@ -1022,7 +1024,7 @@ static const struct pw_stream_events stream_input_events = { PW_VERSION_STREAM_E .add_buffer = stream_add_buffer_callback, .process = input_callback }; -static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device) +static bool PIPEWIRE_OpenDevice(SDL_AudioDevice *device) { /* * NOTE: The PW_STREAM_FLAG_RT_PROCESS flag can be set to call the stream @@ -1083,7 +1085,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device) priv = SDL_calloc(1, sizeof(struct SDL_PrivateAudioData)); device->hidden = priv; if (!priv) { - return -1; + return false; } // Size of a single audio frame in bytes @@ -1172,7 +1174,7 @@ static int PIPEWIRE_OpenDevice(SDL_AudioDevice *device) return SDL_SetError("Pipewire: Stream error: %s", error); } - return 0; + return true; } static void PIPEWIRE_CloseDevice(SDL_AudioDevice *device) @@ -1221,14 +1223,13 @@ static void PIPEWIRE_Deinitialize(void) static bool PipewireInitialize(SDL_AudioDriverImpl *impl) { if (!pipewire_initialized) { - - if (init_pipewire_library() < 0) { + if (!init_pipewire_library()) { return false; } pipewire_initialized = true; - if (hotplug_loop_init() < 0) { + if (!hotplug_loop_init()) { PIPEWIRE_Deinitialize(); return false; } diff --git a/src/audio/ps2/SDL_ps2audio.c b/src/audio/ps2/SDL_ps2audio.c index 11f703263f..8396b265ad 100644 --- a/src/audio/ps2/SDL_ps2audio.c +++ b/src/audio/ps2/SDL_ps2audio.c @@ -27,11 +27,11 @@ #include #include -static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device) +static bool PS2AUDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // These are the native supported audio PS2 configs @@ -82,19 +82,19 @@ static int PS2AUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->mixbufs[i] = &device->hidden->rawbuf[i * device->buffer_size]; } - return 0; + return true; } -static int PS2AUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool PS2AUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { // this returns number of bytes accepted or a negative error. We assume anything other than buflen is a fatal error. - return (audsrv_play_audio((char *)buffer, buflen) != buflen) ? -1 : 0; + return (audsrv_play_audio((char *)buffer, buflen) == buflen); } -static int PS2AUDIO_WaitDevice(SDL_AudioDevice *device) +static bool PS2AUDIO_WaitDevice(SDL_AudioDevice *device) { audsrv_wait_audio(device->buffer_size); - return 0; + return true; } static Uint8 *PS2AUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) diff --git a/src/audio/psp/SDL_pspaudio.c b/src/audio/psp/SDL_pspaudio.c index f5a3bd6a21..9eb793b0d3 100644 --- a/src/audio/psp/SDL_pspaudio.c +++ b/src/audio/psp/SDL_pspaudio.c @@ -38,11 +38,11 @@ static bool isBasicAudioConfig(const SDL_AudioSpec *spec) return spec->freq == 44100; } -static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool PSPAUDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // device only natively supports S16LSB @@ -102,10 +102,10 @@ static int PSPAUDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->mixbufs[i] = &device->hidden->rawbuf[i * device->buffer_size]; } - return 0; + return true; } -static int PSPAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool PSPAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { int rc; if (!isBasicAudioConfig(&device->spec)) { @@ -114,12 +114,12 @@ static int PSPAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int } else { rc = sceAudioOutputPannedBlocking(device->hidden->channel, PSP_AUDIO_VOLUME_MAX, PSP_AUDIO_VOLUME_MAX, (void *) buffer); } - return (rc == 0) ? 0 : -1; + return (rc == 0); } -static int PSPAUDIO_WaitDevice(SDL_AudioDevice *device) +static bool PSPAUDIO_WaitDevice(SDL_AudioDevice *device) { - return 0; // Because we block when sending audio, there's no need for this function to do anything. + return true; // Because we block when sending audio, there's no need for this function to do anything. } static Uint8 *PSPAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c index 6b03eac260..d503dc6ae6 100644 --- a/src/audio/pulseaudio/SDL_pulseaudio.c +++ b/src/audio/pulseaudio/SDL_pulseaudio.c @@ -129,28 +129,28 @@ static void (*PULSEAUDIO_pa_stream_set_write_callback)(pa_stream *, pa_stream_re static void (*PULSEAUDIO_pa_stream_set_read_callback)(pa_stream *, pa_stream_request_cb_t, void *); static pa_operation *(*PULSEAUDIO_pa_context_get_server_info)(pa_context *, pa_server_info_cb_t, void *); -static int load_pulseaudio_syms(void); +static bool load_pulseaudio_syms(void); #ifdef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC static const char *pulseaudio_library = SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC; static void *pulseaudio_handle = NULL; -static int load_pulseaudio_sym(const char *fn, void **addr) +static bool load_pulseaudio_sym(const char *fn, void **addr) { *addr = SDL_LoadFunction(pulseaudio_handle, fn); if (!*addr) { // Don't call SDL_SetError(): SDL_LoadFunction already did. - return 0; + return false; } - return 1; + return true; } // cast funcs to char* first, to please GCC's strict aliasing rules. #define SDL_PULSEAUDIO_SYM(x) \ if (!load_pulseaudio_sym(#x, (void **)(char *)&PULSEAUDIO_##x)) \ - return -1 + return -1 static void UnloadPulseAudioLibrary(void) { @@ -160,22 +160,22 @@ static void UnloadPulseAudioLibrary(void) } } -static int LoadPulseAudioLibrary(void) +static bool LoadPulseAudioLibrary(void) { - int retval = 0; + bool result = true; if (!pulseaudio_handle) { pulseaudio_handle = SDL_LoadObject(pulseaudio_library); if (!pulseaudio_handle) { - retval = -1; + result = false; // Don't call SDL_SetError(): SDL_LoadObject already did. } else { - retval = load_pulseaudio_syms(); - if (retval < 0) { + result = load_pulseaudio_syms(); + if (!result) { UnloadPulseAudioLibrary(); } } } - return retval; + return result; } #else @@ -186,15 +186,15 @@ static void UnloadPulseAudioLibrary(void) { } -static int LoadPulseAudioLibrary(void) +static bool LoadPulseAudioLibrary(void) { load_pulseaudio_syms(); - return 0; + return true; } #endif // SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC -static int load_pulseaudio_syms(void) +static bool load_pulseaudio_syms(void) { SDL_PULSEAUDIO_SYM(pa_get_library_version); SDL_PULSEAUDIO_SYM(pa_threaded_mainloop_new); @@ -261,7 +261,7 @@ static int load_pulseaudio_syms(void) PULSEAUDIO_pa_threaded_mainloop_set_name = NULL; #endif - return 0; + return true; } static const char *getAppName(void) @@ -316,7 +316,7 @@ static void PulseContextStateChangeCallback(pa_context *context, void *userdata) PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // just signal any waiting code, it can look up the details. } -static int ConnectToPulseServer(void) +static bool ConnectToPulseServer(void) { pa_mainloop_api *mainloop_api = NULL; pa_proplist *proplist = NULL; @@ -384,12 +384,12 @@ static int ConnectToPulseServer(void) PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop); - return 0; // connected and ready! + return true; // connected and ready! failed: PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop); DisconnectFromPulseServer(); - return -1; + return false; } static void WriteCallback(pa_stream *p, size_t nbytes, void *userdata) @@ -401,10 +401,10 @@ static void WriteCallback(pa_stream *p, size_t nbytes, void *userdata) } // This function waits until it is possible to write a full sound buffer -static int PULSEAUDIO_WaitDevice(SDL_AudioDevice *device) +static bool PULSEAUDIO_WaitDevice(SDL_AudioDevice *device) { struct SDL_PrivateAudioData *h = device->hidden; - int retval = 0; + bool result = true; //SDL_Log("PULSEAUDIO PLAYDEVICE START! mixlen=%d", available); @@ -416,17 +416,17 @@ static int PULSEAUDIO_WaitDevice(SDL_AudioDevice *device) if ((PULSEAUDIO_pa_context_get_state(pulseaudio_context) != PA_CONTEXT_READY) || (PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY)) { //SDL_Log("PULSEAUDIO DEVICE FAILURE IN WAITDEVICE!"); - retval = -1; + result = false; break; } } PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop); - return retval; + return result; } -static int PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) +static bool PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { struct SDL_PrivateAudioData *h = device->hidden; @@ -439,14 +439,14 @@ static int PULSEAUDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, i PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop); if (rc < 0) { - return -1; + return false; } //SDL_Log("PULSEAUDIO FEED! nbytes=%d", buffer_size); h->bytes_requested -= buffer_size; //SDL_Log("PULSEAUDIO PLAYDEVICE END! written=%d", written); - return 0; + return true; } static Uint8 *PULSEAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -471,15 +471,15 @@ static void ReadCallback(pa_stream *p, size_t nbytes, void *userdata) PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // the recording code queries what it needs, we just need to signal to end any wait } -static int PULSEAUDIO_WaitRecordingDevice(SDL_AudioDevice *device) +static bool PULSEAUDIO_WaitRecordingDevice(SDL_AudioDevice *device) { struct SDL_PrivateAudioData *h = device->hidden; if (h->recordingbuf) { - return 0; // there's still data available to read. + return true; // there's still data available to read. } - int retval = 0; + bool result = true; PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop); @@ -487,7 +487,7 @@ static int PULSEAUDIO_WaitRecordingDevice(SDL_AudioDevice *device) PULSEAUDIO_pa_threaded_mainloop_wait(pulseaudio_threaded_mainloop); if ((PULSEAUDIO_pa_context_get_state(pulseaudio_context) != PA_CONTEXT_READY) || (PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY)) { //SDL_Log("PULSEAUDIO DEVICE FAILURE IN WAITRECORDINGDEVICE!"); - retval = -1; + result = false; break; } else if (PULSEAUDIO_pa_stream_readable_size(h->stream) > 0) { // a new fragment is available! @@ -509,7 +509,7 @@ static int PULSEAUDIO_WaitRecordingDevice(SDL_AudioDevice *device) PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop); - return retval; + return result; } static int PULSEAUDIO_RecordDevice(SDL_AudioDevice *device, void *buffer, int buflen) @@ -591,7 +591,7 @@ static void PulseStreamStateChangeCallback(pa_stream *stream, void *userdata) PULSEAUDIO_pa_threaded_mainloop_signal(pulseaudio_threaded_mainloop, 0); // just signal any waiting code, it can look up the details. } -static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) +static bool PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) { const bool recording = device->recording; struct SDL_PrivateAudioData *h = NULL; @@ -602,7 +602,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) pa_channel_map pacmap; pa_stream_flags_t flags = 0; int format = PA_SAMPLE_INVALID; - int retval = 0; + bool result = true; SDL_assert(pulseaudio_threaded_mainloop != NULL); SDL_assert(pulseaudio_context != NULL); @@ -610,7 +610,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown h = device->hidden = (struct SDL_PrivateAudioData *)SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // Try for a closest match on audio format @@ -659,7 +659,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) if (!recording) { h->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!h->mixbuf) { - return -1; + return false; } SDL_memset(h->mixbuf, device->silence_value, device->buffer_size); } @@ -690,7 +690,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) ); if (!h->stream) { - retval = SDL_SetError("Could not set up PulseAudio stream"); + result = SDL_SetError("Could not set up PulseAudio stream"); } else { int rc; @@ -709,7 +709,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) } if (rc < 0) { - retval = SDL_SetError("Could not connect PulseAudio stream"); + result = SDL_SetError("Could not connect PulseAudio stream"); } else { int state = PULSEAUDIO_pa_stream_get_state(h->stream); while (PA_STREAM_IS_GOOD(state) && (state != PA_STREAM_READY)) { @@ -718,11 +718,11 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) } if (!PA_STREAM_IS_GOOD(state)) { - retval = SDL_SetError("Could not connect PulseAudio stream"); + result = SDL_SetError("Could not connect PulseAudio stream"); } else { const pa_buffer_attr *actual_bufattr = PULSEAUDIO_pa_stream_get_buffer_attr(h->stream); if (!actual_bufattr) { - retval = SDL_SetError("Could not determine connected PulseAudio stream's buffer attributes"); + result = SDL_SetError("Could not determine connected PulseAudio stream's buffer attributes"); } else { device->buffer_size = (int) recording ? actual_bufattr->tlength : actual_bufattr->fragsize; device->sample_frames = device->buffer_size / SDL_AUDIO_FRAMESIZE(device->spec); @@ -734,7 +734,7 @@ static int PULSEAUDIO_OpenDevice(SDL_AudioDevice *device) PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop); // We're (hopefully) ready to rock and roll. :-) - return retval; + return result; } // device handles are device index + 1, cast to void*, so we never pass a NULL. @@ -994,9 +994,9 @@ static void PULSEAUDIO_Deinitialize(void) static bool PULSEAUDIO_Init(SDL_AudioDriverImpl *impl) { - if (LoadPulseAudioLibrary() < 0) { + if (!LoadPulseAudioLibrary()) { return false; - } else if (ConnectToPulseServer() < 0) { + } else if (!ConnectToPulseServer()) { UnloadPulseAudioLibrary(); return false; } diff --git a/src/audio/qnx/SDL_qsa_audio.c b/src/audio/qnx/SDL_qsa_audio.c index d8736b8805..7dffa1f945 100644 --- a/src/audio/qnx/SDL_qsa_audio.c +++ b/src/audio/qnx/SDL_qsa_audio.c @@ -52,7 +52,7 @@ #define QSA_MAX_NAME_LENGTH 81+16 // Hardcoded in QSA, can't be changed -static int QSA_SetError(const char *fn, int status) +static bool QSA_SetError(const char *fn, int status) { return SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status)); } @@ -86,7 +86,7 @@ static void QSA_InitAudioParams(snd_pcm_channel_params_t * cpars) } // This function waits until it is possible to write a full sound buffer -static int QSA_WaitDevice(SDL_AudioDevice *device) +static bool QSA_WaitDevice(SDL_AudioDevice *device) { // Setup timeout for playing one fragment equal to 2 seconds // If timeout occurred than something wrong with hardware or driver @@ -98,7 +98,7 @@ static int QSA_WaitDevice(SDL_AudioDevice *device) switch (result) { case -1: SDL_LogError(SDL_LOG_CATEGORY_AUDIO, "QSA: SDL_IOReady() failed: %s", strerror(errno)); - return -1; + return false; case 0: device->hidden->timeout_on_wait = true; // !!! FIXME: Should we just disconnect the device in this case? break; @@ -107,13 +107,13 @@ static int QSA_WaitDevice(SDL_AudioDevice *device) break; } - return 0; + return true; } -static int QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { if (SDL_AtomicGet(&device->shutdown) || !device->hidden) { - return 0; + return true; } int towrite = buflen; @@ -125,7 +125,7 @@ static int QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int bufl // Check if samples playback got stuck somewhere in hardware or in the audio device driver if ((errno == EAGAIN) && (bw == 0)) { if (device->hidden->timeout_on_wait) { - return 0; // oh well, try again next time. !!! FIXME: Should we just disconnect the device in this case? + return true; // oh well, try again next time. !!! FIXME: Should we just disconnect the device in this case? } } @@ -145,17 +145,17 @@ static int QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int bufl int status = snd_pcm_plugin_status(device->hidden->audio_handle, &cstatus); if (status < 0) { QSA_SetError("snd_pcm_plugin_status", status); - return -1; + return false; } else if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY)) { status = snd_pcm_plugin_prepare(device->hidden->audio_handle, device->recording ? SND_PCM_CHANNEL_CAPTURE : SND_PCM_CHANNEL_PLAYBACK); if (status < 0) { QSA_SetError("snd_pcm_plugin_prepare", status); - return -1; + return false; } } continue; } else { - return -1; + return false; } } else { // we wrote all remaining data @@ -165,7 +165,7 @@ static int QSA_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int bufl } // If we couldn't write, assume fatal error for now - return (towrite != 0) ? -1 : 0; + return (towrite == 0); } static Uint8 *QSA_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) @@ -190,7 +190,7 @@ static void QSA_CloseDevice(SDL_AudioDevice *device) } } -static int QSA_OpenDevice(SDL_AudioDevice *device) +static bool QSA_OpenDevice(SDL_AudioDevice *device) { if (device->recording) { return SDL_SetError("SDL recording support isn't available on QNX atm"); // !!! FIXME: most of this code has support for recording devices, but there's no RecordDevice, etc functions. Fill them in! @@ -206,7 +206,7 @@ static int QSA_OpenDevice(SDL_AudioDevice *device) // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, (sizeof (struct SDL_PrivateAudioData))); if (device->hidden == NULL) { - return -1; + return false; } // Initialize channel transfer parameters to default @@ -275,7 +275,7 @@ static int QSA_OpenDevice(SDL_AudioDevice *device) device->hidden->pcm_buf = (Uint8 *) SDL_malloc(device->buffer_size); if (device->hidden->pcm_buf == NULL) { - return -1; + return false; } SDL_memset(device->hidden->pcm_buf, device->silence_value, device->buffer_size); @@ -291,7 +291,7 @@ static int QSA_OpenDevice(SDL_AudioDevice *device) return QSA_SetError("snd_pcm_plugin_prepare", status); } - return 0; // We're really ready to rock and roll. :-) + return true; // We're really ready to rock and roll. :-) } static SDL_AudioFormat QnxFormatToSDLFormat(const int32_t qnxfmt) diff --git a/src/audio/sndio/SDL_sndioaudio.c b/src/audio/sndio/SDL_sndioaudio.c index 8a2d08fd7f..0e709fa0ef 100644 --- a/src/audio/sndio/SDL_sndioaudio.c +++ b/src/audio/sndio/SDL_sndioaudio.c @@ -68,25 +68,25 @@ static void (*SNDIO_sio_initpar)(struct sio_par *); static const char *sndio_library = SDL_AUDIO_DRIVER_SNDIO_DYNAMIC; static void *sndio_handle = NULL; -static int load_sndio_sym(const char *fn, void **addr) +static bool load_sndio_sym(const char *fn, void **addr) { *addr = SDL_LoadFunction(sndio_handle, fn); if (!*addr) { - return 0; // Don't call SDL_SetError(): SDL_LoadFunction already did. + return false; // Don't call SDL_SetError(): SDL_LoadFunction already did. } - return 1; + return true; } // cast funcs to char* first, to please GCC's strict aliasing rules. #define SDL_SNDIO_SYM(x) \ if (!load_sndio_sym(#x, (void **)(char *)&SNDIO_##x)) \ - return -1 + return false #else #define SDL_SNDIO_SYM(x) SNDIO_##x = x #endif -static int load_sndio_syms(void) +static bool load_sndio_syms(void) { SDL_SNDIO_SYM(sio_open); SDL_SNDIO_SYM(sio_close); @@ -101,7 +101,7 @@ static int load_sndio_syms(void) SDL_SNDIO_SYM(sio_revents); SDL_SNDIO_SYM(sio_eof); SDL_SNDIO_SYM(sio_initpar); - return 0; + return true; } #undef SDL_SNDIO_SYM @@ -116,21 +116,21 @@ static void UnloadSNDIOLibrary(void) } } -static int LoadSNDIOLibrary(void) +static bool LoadSNDIOLibrary(void) { - int retval = 0; + bool result = true; if (!sndio_handle) { sndio_handle = SDL_LoadObject(sndio_library); if (!sndio_handle) { - retval = -1; // Don't call SDL_SetError(): SDL_LoadObject already did. + result = false; // Don't call SDL_SetError(): SDL_LoadObject already did. } else { - retval = load_sndio_syms(); - if (retval < 0) { + result = load_sndio_syms(); + if (!result) { UnloadSNDIOLibrary(); } } } - return retval; + return result; } #else @@ -139,26 +139,26 @@ static void UnloadSNDIOLibrary(void) { } -static int LoadSNDIOLibrary(void) +static bool LoadSNDIOLibrary(void) { load_sndio_syms(); - return 0; + return true; } #endif // SDL_AUDIO_DRIVER_SNDIO_DYNAMIC -static int SNDIO_WaitDevice(SDL_AudioDevice *device) +static bool SNDIO_WaitDevice(SDL_AudioDevice *device) { const bool recording = device->recording; while (!SDL_AtomicGet(&device->shutdown)) { if (SNDIO_sio_eof(device->hidden->dev)) { - return -1; + return false; } const int nfds = SNDIO_sio_pollfd(device->hidden->dev, device->hidden->pfd, recording ? POLLIN : POLLOUT); if (nfds <= 0 || poll(device->hidden->pfd, nfds, 10) < 0) { - return -1; + return false; } const int revents = SNDIO_sio_revents(device->hidden->dev, device->hidden->pfd); @@ -167,24 +167,24 @@ static int SNDIO_WaitDevice(SDL_AudioDevice *device) } else if (!recording && (revents & POLLOUT)) { break; } else if (revents & POLLHUP) { - return -1; + return false; } } - return 0; + return true; } -static int SNDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool SNDIO_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { // !!! FIXME: this should be non-blocking so we can check device->shutdown. // this is set to blocking, because we _have_ to send the entire buffer down, but hopefully WaitDevice took most of the delay time. if (SNDIO_sio_write(device->hidden->dev, buffer, buflen) != buflen) { - return -1; // If we couldn't write, assume fatal error for now + return false; // If we couldn't write, assume fatal error for now } #ifdef DEBUG_AUDIO fprintf(stderr, "Wrote %d bytes of audio data\n", written); #endif - return 0; + return true; } static int SNDIO_RecordDevice(SDL_AudioDevice *device, void *buffer, int buflen) @@ -224,11 +224,11 @@ static void SNDIO_CloseDevice(SDL_AudioDevice *device) } } -static int SNDIO_OpenDevice(SDL_AudioDevice *device) +static bool SNDIO_OpenDevice(SDL_AudioDevice *device) { device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } // Recording devices must be non-blocking for SNDIO_FlushRecording @@ -240,7 +240,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device) device->hidden->pfd = SDL_malloc(sizeof(struct pollfd) * SNDIO_sio_nfds(device->hidden->dev)); if (!device->hidden->pfd) { - return -1; + return false; } struct sio_par par; @@ -305,7 +305,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device) // Allocate mixing buffer device->hidden->mixbuf = (Uint8 *)SDL_malloc(device->buffer_size); if (!device->hidden->mixbuf) { - return -1; + return false; } SDL_memset(device->hidden->mixbuf, device->silence_value, device->buffer_size); @@ -313,7 +313,7 @@ static int SNDIO_OpenDevice(SDL_AudioDevice *device) return SDL_SetError("sio_start() failed"); } - return 0; // We're ready to rock and roll. :-) + return true; // We're ready to rock and roll. :-) } static void SNDIO_Deinitialize(void) @@ -329,7 +329,7 @@ static void SNDIO_DetectDevices(SDL_AudioDevice **default_playback, SDL_AudioDev static bool SNDIO_Init(SDL_AudioDriverImpl *impl) { - if (LoadSNDIOLibrary() < 0) { + if (!LoadSNDIOLibrary()) { return false; } diff --git a/src/audio/vita/SDL_vitaaudio.c b/src/audio/vita/SDL_vitaaudio.c index 5b577bec8e..fcd046c643 100644 --- a/src/audio/vita/SDL_vitaaudio.c +++ b/src/audio/vita/SDL_vitaaudio.c @@ -37,7 +37,7 @@ #define SCE_AUDIO_SAMPLE_ALIGN(s) (((s) + 63) & ~63) #define SCE_AUDIO_MAX_VOLUME 0x8000 -static int VITAAUD_OpenRecordingDevice(SDL_AudioDevice *device) +static bool VITAAUD_OpenRecordingDevice(SDL_AudioDevice *device) { device->spec.freq = 16000; device->spec.channels = 1; @@ -51,10 +51,10 @@ static int VITAAUD_OpenRecordingDevice(SDL_AudioDevice *device) return SDL_SetError("Couldn't open audio in port: %x", device->hidden->port); } - return 0; + return true; } -static int VITAAUD_OpenDevice(SDL_AudioDevice *device) +static bool VITAAUD_OpenDevice(SDL_AudioDevice *device) { int format, mixlen, i, port = SCE_AUDIO_OUT_PORT_TYPE_MAIN; int vols[2] = { SCE_AUDIO_MAX_VOLUME, SCE_AUDIO_MAX_VOLUME }; @@ -64,7 +64,7 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device) device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; + return false; } closefmts = SDL_ClosestAudioFormats(device->spec.format); @@ -125,29 +125,29 @@ static int VITAAUD_OpenDevice(SDL_AudioDevice *device) } device->hidden->next_buffer = 0; - return 0; + return true; } -static int VITAAUD_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) +static bool VITAAUD_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buffer_size) { - return (sceAudioOutOutput(device->hidden->port, buffer) == 0) ? 0 : -1; + return (sceAudioOutOutput(device->hidden->port, buffer) == 0); } // This function waits until it is possible to write a full sound buffer -static int VITAAUD_WaitDevice(SDL_AudioDevice *device) +static bool VITAAUD_WaitDevice(SDL_AudioDevice *device) { // !!! FIXME: we might just need to sleep roughly as long as playback buffers take to process, based on sample rate, etc. while (!SDL_AtomicGet(&device->shutdown) && (sceAudioOutGetRestSample(device->hidden->port) >= device->buffer_size)) { SDL_Delay(1); } - return 0; + return true; } static Uint8 *VITAAUD_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) { - Uint8 *retval = device->hidden->mixbufs[device->hidden->next_buffer]; + Uint8 *result = device->hidden->mixbufs[device->hidden->next_buffer]; device->hidden->next_buffer = (device->hidden->next_buffer + 1) % NUM_BUFFERS; - return retval; + return result; } static void VITAAUD_CloseDevice(SDL_AudioDevice *device) @@ -171,7 +171,7 @@ static void VITAAUD_CloseDevice(SDL_AudioDevice *device) } } -static int VITAAUD_WaitRecordingDevice(SDL_AudioDevice *device) +static bool VITAAUD_WaitRecordingDevice(SDL_AudioDevice *device) { // there's only a blocking call to obtain more data, so we'll just sleep as // long as a buffer would run. @@ -179,7 +179,7 @@ static int VITAAUD_WaitRecordingDevice(SDL_AudioDevice *device) while (!SDL_AtomicGet(&device->shutdown) && (SDL_GetTicks() < endticks)) { SDL_Delay(1); } - return 0; + return true; } static int VITAAUD_RecordDevice(SDL_AudioDevice *device, void *buffer, int buflen) @@ -188,7 +188,8 @@ static int VITAAUD_RecordDevice(SDL_AudioDevice *device, void *buffer, int bufle SDL_assert(buflen == device->buffer_size); ret = sceAudioInInput(device->hidden->port, buffer); if (ret < 0) { - return SDL_SetError("Failed to record from device: %x", ret); + SDL_SetError("Failed to record from device: %x", ret); + return -1; } return device->buffer_size; } diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c index 732b10659c..434d077429 100644 --- a/src/audio/wasapi/SDL_wasapi.c +++ b/src/audio/wasapi/SDL_wasapi.c @@ -58,7 +58,7 @@ typedef struct ManagementThreadPendingTask { ManagementThreadTask fn; void *userdata; - int result; + bool result; SDL_Semaphore *task_complete_sem; char *errorstr; struct ManagementThreadPendingTask *next; @@ -93,12 +93,12 @@ static void ManagementThreadMainloop(void) SDL_UnlockMutex(ManagementThreadLock); // told to shut down and out of tasks, let go of the lock and return. } -int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, int *wait_on_result) +bool WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, bool *wait_on_result) { // We want to block for a result, but we are already running from the management thread! Just run the task now so we don't deadlock. if ((wait_on_result) && (SDL_GetCurrentThreadID() == SDL_GetThreadID(ManagementThread))) { *wait_on_result = task(userdata); - return 0; // completed! + return true; // completed! } if (SDL_AtomicGet(&ManagementThreadShutdown)) { @@ -107,7 +107,7 @@ int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, in ManagementThreadPendingTask *pending = (ManagementThreadPendingTask *)SDL_calloc(1, sizeof(ManagementThreadPendingTask)); if (!pending) { - return -1; + return false; } pending->fn = task; @@ -117,7 +117,7 @@ int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, in pending->task_complete_sem = SDL_CreateSemaphore(0); if (!pending->task_complete_sem) { SDL_free(pending); - return -1; + return false; } } @@ -152,19 +152,19 @@ int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, in SDL_free(pending); } - return 0; // successfully added (and possibly executed)! + return true; // successfully added (and possibly executed)! } -static int ManagementThreadPrepare(void) +static bool ManagementThreadPrepare(void) { - if (WASAPI_PlatformInit() < 0) { - return -1; + if (!WASAPI_PlatformInit()) { + return false; } ManagementThreadLock = SDL_CreateMutex(); if (!ManagementThreadLock) { WASAPI_PlatformDeinit(); - return -1; + return false; } ManagementThreadCondition = SDL_CreateCondition(); @@ -172,10 +172,10 @@ static int ManagementThreadPrepare(void) SDL_DestroyMutex(ManagementThreadLock); ManagementThreadLock = NULL; WASAPI_PlatformDeinit(); - return -1; + return false; } - return 0; + return true; } typedef struct @@ -188,7 +188,7 @@ static int ManagementThreadEntry(void *userdata) { ManagementThreadEntryData *data = (ManagementThreadEntryData *)userdata; - if (ManagementThreadPrepare() < 0) { + if (!ManagementThreadPrepare()) { data->errorstr = SDL_strdup(SDL_GetError()); SDL_SignalSemaphore(data->ready_sem); // unblock calling thread. return 0; @@ -201,20 +201,20 @@ static int ManagementThreadEntry(void *userdata) return 0; } -static int InitManagementThread(void) +static bool InitManagementThread(void) { ManagementThreadEntryData mgmtdata; SDL_zero(mgmtdata); mgmtdata.ready_sem = SDL_CreateSemaphore(0); if (!mgmtdata.ready_sem) { - return -1; + return false; } SDL_AtomicSetPtr((void **) &ManagementThreadPendingTasks, NULL); SDL_AtomicSet(&ManagementThreadShutdown, 0); ManagementThread = SDL_CreateThreadWithStackSize(ManagementThreadEntry, "SDLWASAPIMgmt", 256 * 1024, &mgmtdata); // !!! FIXME: maybe even smaller stack size? if (!ManagementThread) { - return -1; + return false; } SDL_WaitSemaphore(mgmtdata.ready_sem); @@ -225,10 +225,10 @@ static int InitManagementThread(void) ManagementThread = NULL; SDL_SetError("%s", mgmtdata.errorstr); SDL_free(mgmtdata.errorstr); - return -1; + return false; } - return 0; + return true; } static void DeinitManagementThread(void) @@ -257,16 +257,16 @@ typedef struct SDL_AudioDevice **default_recording; } mgmtthrtask_DetectDevicesData; -static int mgmtthrtask_DetectDevices(void *userdata) +static bool mgmtthrtask_DetectDevices(void *userdata) { mgmtthrtask_DetectDevicesData *data = (mgmtthrtask_DetectDevicesData *)userdata; WASAPI_EnumerateEndpoints(data->default_playback, data->default_recording); - return 0; + return true; } static void WASAPI_DetectDevices(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording) { - int rc; + bool rc; // this blocks because it needs to finish before the audio subsystem inits mgmtthrtask_DetectDevicesData data; data.default_playback = default_playback; @@ -274,15 +274,15 @@ static void WASAPI_DetectDevices(SDL_AudioDevice **default_playback, SDL_AudioDe WASAPI_ProxyToManagementThread(mgmtthrtask_DetectDevices, &data, &rc); } -static int mgmtthrtask_DisconnectDevice(void *userdata) +static bool mgmtthrtask_DisconnectDevice(void *userdata) { SDL_AudioDeviceDisconnected((SDL_AudioDevice *)userdata); - return 0; + return true; } void WASAPI_DisconnectDevice(SDL_AudioDevice *device) { - int rc; // block on this; don't disconnect while holding the device lock! + bool rc; // block on this; don't disconnect while holding the device lock! WASAPI_ProxyToManagementThread(mgmtthrtask_DisconnectDevice, device, &rc); } @@ -299,42 +299,42 @@ static bool WasapiFailed(SDL_AudioDevice *device, const HRESULT err) return true; } -static int mgmtthrtask_StopAndReleaseClient(void *userdata) +static bool mgmtthrtask_StopAndReleaseClient(void *userdata) { IAudioClient *client = (IAudioClient *) userdata; IAudioClient_Stop(client); IAudioClient_Release(client); - return 0; + return true; } -static int mgmtthrtask_ReleaseCaptureClient(void *userdata) +static bool mgmtthrtask_ReleaseCaptureClient(void *userdata) { IAudioCaptureClient_Release((IAudioCaptureClient *)userdata); - return 0; + return true; } -static int mgmtthrtask_ReleaseRenderClient(void *userdata) +static bool mgmtthrtask_ReleaseRenderClient(void *userdata) { IAudioRenderClient_Release((IAudioRenderClient *)userdata); - return 0; + return true; } -static int mgmtthrtask_CoTaskMemFree(void *userdata) +static bool mgmtthrtask_CoTaskMemFree(void *userdata) { CoTaskMemFree(userdata); - return 0; + return true; } -static int mgmtthrtask_PlatformDeleteActivationHandler(void *userdata) +static bool mgmtthrtask_PlatformDeleteActivationHandler(void *userdata) { WASAPI_PlatformDeleteActivationHandler(userdata); - return 0; + return true; } -static int mgmtthrtask_CloseHandle(void *userdata) +static bool mgmtthrtask_CloseHandle(void *userdata) { CloseHandle((HANDLE) userdata); - return 0; + return true; } static void ResetWasapiDevice(SDL_AudioDevice *device) @@ -383,17 +383,17 @@ static void ResetWasapiDevice(SDL_AudioDevice *device) } } -static int mgmtthrtask_ActivateDevice(void *userdata) +static bool mgmtthrtask_ActivateDevice(void *userdata) { return WASAPI_ActivateDevice((SDL_AudioDevice *)userdata); } -static int ActivateWasapiDevice(SDL_AudioDevice *device) +static bool ActivateWasapiDevice(SDL_AudioDevice *device) { // this blocks because we're either being notified from a background thread or we're running during device open, // both of which won't deadlock vs the device thread. - int rc = -1; - return ((WASAPI_ProxyToManagementThread(mgmtthrtask_ActivateDevice, device, &rc) < 0) || (rc < 0)) ? -1 : 0; + bool rc = false; + return (WASAPI_ProxyToManagementThread(mgmtthrtask_ActivateDevice, device, &rc) && rc); } // do not call when holding the device lock! @@ -402,7 +402,7 @@ static bool RecoverWasapiDevice(SDL_AudioDevice *device) ResetWasapiDevice(device); // dump the lost device's handles. // This handles a non-default device that simply had its format changed in the Windows Control Panel. - if (ActivateWasapiDevice(device) < 0) { + if (!ActivateWasapiDevice(device)) { WASAPI_DisconnectDevice(device); return false; } @@ -452,16 +452,16 @@ static Uint8 *WASAPI_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) return (Uint8 *)buffer; } -static int WASAPI_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) +static bool WASAPI_PlayDevice(SDL_AudioDevice *device, const Uint8 *buffer, int buflen) { if (device->hidden->render) { // definitely activated? // WasapiFailed() will mark the device for reacquisition or removal elsewhere. WasapiFailed(device, IAudioRenderClient_ReleaseBuffer(device->hidden->render, device->sample_frames, 0)); } - return 0; + return true; } -static int WASAPI_WaitDevice(SDL_AudioDevice *device) +static bool WASAPI_WaitDevice(SDL_AudioDevice *device) { // WaitDevice does not hold the device lock, so check for recovery/disconnect details here. while (RecoverWasapiIfLost(device) && device->hidden->client && device->hidden->event) { @@ -483,7 +483,7 @@ static int WASAPI_WaitDevice(SDL_AudioDevice *device) default: //SDL_Log("WASAPI FAILED EVENT!"); IAudioClient_Stop(device->hidden->client); - return -1; + return false; } } else { DWORD waitResult = WaitForSingleObjectEx(device->hidden->event, 200, FALSE); @@ -498,12 +498,12 @@ static int WASAPI_WaitDevice(SDL_AudioDevice *device) } else if (waitResult != WAIT_TIMEOUT) { //SDL_Log("WASAPI FAILED EVENT!");*/ IAudioClient_Stop(device->hidden->client); - return -1; + return false; } } } - return 0; + return true; } static int WASAPI_RecordDevice(SDL_AudioDevice *device, void *buffer, int buflen) @@ -572,7 +572,7 @@ static void WASAPI_CloseDevice(SDL_AudioDevice *device) } } -static int mgmtthrtask_PrepDevice(void *userdata) +static bool mgmtthrtask_PrepDevice(void *userdata) { SDL_AudioDevice *device = (SDL_AudioDevice *)userdata; @@ -719,8 +719,8 @@ static int mgmtthrtask_PrepDevice(void *userdata) } // Update the fragment size as size in bytes - if (SDL_AudioDeviceFormatChangedAlreadyLocked(device, &newspec, new_sample_frames) < 0) { - return -1; + if (!SDL_AudioDeviceFormatChangedAlreadyLocked(device, &newspec, new_sample_frames)) { + return false; } device->hidden->framesize = SDL_AUDIO_FRAMESIZE(device->spec); @@ -755,24 +755,24 @@ static int mgmtthrtask_PrepDevice(void *userdata) } } - return 0; // good to go. + return true; // good to go. } // This is called once a device is activated, possibly asynchronously. -int WASAPI_PrepDevice(SDL_AudioDevice *device) +bool WASAPI_PrepDevice(SDL_AudioDevice *device) { - int rc = 0; - return (WASAPI_ProxyToManagementThread(mgmtthrtask_PrepDevice, device, &rc) < 0) ? -1 : rc; + bool rc = true; + return (WASAPI_ProxyToManagementThread(mgmtthrtask_PrepDevice, device, &rc) && rc); } -static int WASAPI_OpenDevice(SDL_AudioDevice *device) +static bool WASAPI_OpenDevice(SDL_AudioDevice *device) { // Initialize all variables that we clean on shutdown device->hidden = (struct SDL_PrivateAudioData *) SDL_calloc(1, sizeof(*device->hidden)); if (!device->hidden) { - return -1; - } else if (ActivateWasapiDevice(device) < 0) { - return -1; // already set error. + return false; + } else if (!ActivateWasapiDevice(device)) { + return false; // already set error. } /* Ready, but possibly waiting for async device activation. @@ -780,7 +780,7 @@ static int WASAPI_OpenDevice(SDL_AudioDevice *device) devices and ignore data on playback devices. Upon activation, we'll make sure any bound audio streams are adjusted for the final device format. */ - return 0; + return true; } static void WASAPI_ThreadInit(SDL_AudioDevice *device) @@ -793,27 +793,27 @@ static void WASAPI_ThreadDeinit(SDL_AudioDevice *device) WASAPI_PlatformThreadDeinit(device); } -static int mgmtthrtask_FreeDeviceHandle(void *userdata) +static bool mgmtthrtask_FreeDeviceHandle(void *userdata) { WASAPI_PlatformFreeDeviceHandle((SDL_AudioDevice *)userdata); - return 0; + return true; } static void WASAPI_FreeDeviceHandle(SDL_AudioDevice *device) { - int rc; + bool rc; WASAPI_ProxyToManagementThread(mgmtthrtask_FreeDeviceHandle, device, &rc); } -static int mgmtthrtask_DeinitializeStart(void *userdata) +static bool mgmtthrtask_DeinitializeStart(void *userdata) { WASAPI_PlatformDeinitializeStart(); - return 0; + return true; } static void WASAPI_DeinitializeStart(void) { - int rc; + bool rc; WASAPI_ProxyToManagementThread(mgmtthrtask_DeinitializeStart, NULL, &rc); } @@ -824,7 +824,7 @@ static void WASAPI_Deinitialize(void) static bool WASAPI_Init(SDL_AudioDriverImpl *impl) { - if (InitManagementThread() < 0) { + if (!InitManagementThread()) { return false; } diff --git a/src/audio/wasapi/SDL_wasapi.h b/src/audio/wasapi/SDL_wasapi.h index 0ad9d8ae3b..107ddb53a0 100644 --- a/src/audio/wasapi/SDL_wasapi.h +++ b/src/audio/wasapi/SDL_wasapi.h @@ -46,21 +46,21 @@ struct SDL_PrivateAudioData }; // win32 and winrt implementations call into these. -int WASAPI_PrepDevice(SDL_AudioDevice *device); +bool WASAPI_PrepDevice(SDL_AudioDevice *device); void WASAPI_DisconnectDevice(SDL_AudioDevice *device); // don't hold the device lock when calling this! // BE CAREFUL: if you are holding the device lock and proxy to the management thread with wait_until_complete, and grab the lock again, you will deadlock. -typedef int (*ManagementThreadTask)(void *userdata); -int WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, int *wait_until_complete); +typedef bool (*ManagementThreadTask)(void *userdata); +bool WASAPI_ProxyToManagementThread(ManagementThreadTask task, void *userdata, bool *wait_until_complete); // These are functions that are implemented differently for Windows vs WinRT. // UNLESS OTHERWISE NOTED THESE ALL HAPPEN ON THE MANAGEMENT THREAD. -int WASAPI_PlatformInit(void); +bool WASAPI_PlatformInit(void); void WASAPI_PlatformDeinit(void); void WASAPI_PlatformDeinitializeStart(void); void WASAPI_EnumerateEndpoints(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording); -int WASAPI_ActivateDevice(SDL_AudioDevice *device); +bool WASAPI_ActivateDevice(SDL_AudioDevice *device); void WASAPI_PlatformThreadInit(SDL_AudioDevice *device); // this happens on the audio device thread, not the management thread. void WASAPI_PlatformThreadDeinit(SDL_AudioDevice *device); // this happens on the audio device thread, not the management thread. void WASAPI_PlatformDeleteActivationHandler(void *handler); diff --git a/src/audio/wasapi/SDL_wasapi_win32.c b/src/audio/wasapi/SDL_wasapi_win32.c index 905a66894a..e548c9994b 100644 --- a/src/audio/wasapi/SDL_wasapi_win32.c +++ b/src/audio/wasapi/SDL_wasapi_win32.c @@ -48,12 +48,12 @@ static bool immdevice_initialized = false; // Some GUIDs we need to know without linking to libraries that aren't available before Vista. static const IID SDL_IID_IAudioClient = { 0x1cb9ad4c, 0xdbfa, 0x4c32, { 0xb1, 0x78, 0xc2, 0xf5, 0x68, 0xa7, 0x03, 0xb2 } }; -static int mgmtthrtask_AudioDeviceDisconnected(void *userdata) +static bool mgmtthrtask_AudioDeviceDisconnected(void *userdata) { SDL_AudioDevice *device = (SDL_AudioDevice *) userdata; SDL_AudioDeviceDisconnected(device); UnrefPhysicalAudioDevice(device); // make sure this lived until the task completes. - return 0; + return true; } static void WASAPI_AudioDeviceDisconnected(SDL_AudioDevice *device) @@ -65,12 +65,12 @@ static void WASAPI_AudioDeviceDisconnected(SDL_AudioDevice *device) } } -static int mgmtthrtask_DefaultAudioDeviceChanged(void *userdata) +static bool mgmtthrtask_DefaultAudioDeviceChanged(void *userdata) { SDL_AudioDevice *device = (SDL_AudioDevice *) userdata; SDL_DefaultAudioDeviceChanged(device); UnrefPhysicalAudioDevice(device); // make sure this lived until the task completes. - return 0; + return true; } static void WASAPI_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device) @@ -82,13 +82,13 @@ static void WASAPI_DefaultAudioDeviceChanged(SDL_AudioDevice *new_default_device } } -int WASAPI_PlatformInit(void) +bool WASAPI_PlatformInit(void) { const SDL_IMMDevice_callbacks callbacks = { WASAPI_AudioDeviceDisconnected, WASAPI_DefaultAudioDeviceChanged }; if (FAILED(WIN_CoInitialize())) { return SDL_SetError("CoInitialize() failed"); - } else if (SDL_IMMDevice_Init(&callbacks) < 0) { - return -1; // Error string is set by SDL_IMMDevice_Init + } else if (!SDL_IMMDevice_Init(&callbacks)) { + return false; // Error string is set by SDL_IMMDevice_Init } immdevice_initialized = true; @@ -99,7 +99,7 @@ int WASAPI_PlatformInit(void) pAvRevertMmThreadCharacteristics = (pfnAvRevertMmThreadCharacteristics)GetProcAddress(libavrt, "AvRevertMmThreadCharacteristics"); } - return 0; + return true; } static void StopWasapiHotplug(void) @@ -161,12 +161,12 @@ void WASAPI_PlatformThreadDeinit(SDL_AudioDevice *device) } } -int WASAPI_ActivateDevice(SDL_AudioDevice *device) +bool WASAPI_ActivateDevice(SDL_AudioDevice *device) { IMMDevice *immdevice = NULL; - if (SDL_IMMDevice_Get(device, &immdevice, device->recording) < 0) { + if (!SDL_IMMDevice_Get(device, &immdevice, device->recording)) { device->hidden->client = NULL; - return -1; // This is already set by SDL_IMMDevice_Get + return false; // This is already set by SDL_IMMDevice_Get } // this is _not_ async in standard win32, yay! @@ -179,11 +179,11 @@ int WASAPI_ActivateDevice(SDL_AudioDevice *device) } SDL_assert(device->hidden->client != NULL); - if (WASAPI_PrepDevice(device) < 0) { // not async, fire it right away. - return -1; + if (!WASAPI_PrepDevice(device)) { // not async, fire it right away. + return false; } - return 0; // good to go. + return true; // good to go. } void WASAPI_EnumerateEndpoints(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording) diff --git a/src/audio/wasapi/SDL_wasapi_winrt.cpp b/src/audio/wasapi/SDL_wasapi_winrt.cpp index a5d0f3cef8..4b27df2967 100644 --- a/src/audio/wasapi/SDL_wasapi_winrt.cpp +++ b/src/audio/wasapi/SDL_wasapi_winrt.cpp @@ -214,9 +214,9 @@ void SDL_WasapiDeviceEventHandler::WaitForCompletion() static SDL_WasapiDeviceEventHandler *playback_device_event_handler; static SDL_WasapiDeviceEventHandler *recording_device_event_handler; -int WASAPI_PlatformInit(void) +bool WASAPI_PlatformInit(void) { - return 0; + return true; } static void StopWasapiHotplug(void) @@ -292,7 +292,7 @@ void WASAPI_PlatformDeleteActivationHandler(void *handler) ((SDL_WasapiActivationHandler *)handler)->Release(); } -int WASAPI_ActivateDevice(SDL_AudioDevice *device) +bool WASAPI_ActivateDevice(SDL_AudioDevice *device) { LPCWSTR devid = (LPCWSTR) device->handle; SDL_assert(devid != NULL); @@ -334,11 +334,11 @@ int WASAPI_ActivateDevice(SDL_AudioDevice *device) return SDL_SetError("Failed to query WASAPI client interface"); } - if (WASAPI_PrepDevice(device) == -1) { - return -1; + if (!WASAPI_PrepDevice(device)) { + return false; } - return 0; + return true; } void WASAPI_PlatformThreadInit(SDL_AudioDevice *device) diff --git a/src/camera/SDL_camera.c b/src/camera/SDL_camera.c index 6e40b7763f..25d70973cf 100644 --- a/src/camera/SDL_camera.c +++ b/src/camera/SDL_camera.c @@ -82,14 +82,14 @@ char *SDL_GetCameraThreadName(SDL_Camera *device, char *buf, size_t buflen) return buf; } -int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator) +bool SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator) { SDL_assert(data != NULL); if (data->allocated_specs <= data->num_specs) { const int newalloc = data->allocated_specs ? (data->allocated_specs * 2) : 16; void *ptr = SDL_realloc(data->specs, sizeof (SDL_CameraSpec) * newalloc); if (!ptr) { - return -1; + return false; } data->specs = (SDL_CameraSpec *) ptr; data->allocated_specs = newalloc; @@ -105,7 +105,7 @@ int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_C data->num_specs++; - return 0; + return true; } @@ -113,14 +113,14 @@ int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_C // These get used when a device is disconnected or fails. Apps that ignore the // loss notifications will get black frames but otherwise keep functioning. -static int ZombieWaitDevice(SDL_Camera *device) +static bool ZombieWaitDevice(SDL_Camera *device) { if (!SDL_AtomicGet(&device->shutdown)) { // !!! FIXME: this is bad for several reasons (uses double, could be precalculated, doesn't track elasped time). const double duration = ((double) device->actual_spec.framerate_denominator / ((double) device->actual_spec.framerate_numerator)); SDL_Delay((Uint32) (duration * 1000.0)); } - return 0; + return true; } static size_t GetFrameBufLen(const SDL_CameraSpec *spec) @@ -145,7 +145,7 @@ static size_t GetFrameBufLen(const SDL_CameraSpec *spec) return wxh * SDL_BYTESPERPIXEL(fmt); } -static int ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { const SDL_CameraSpec *spec = &device->actual_spec; @@ -155,7 +155,7 @@ static int ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *ti device->zombie_pixels = (Uint8 *)SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen); if (!device->zombie_pixels) { *timestampNS = 0; - return 0; // oh well, say there isn't a frame yet, so we'll go back to waiting. Maybe allocation will succeed later...? + return SDL_CAMERA_FRAME_SKIP; // oh well, say there isn't a frame yet, so we'll go back to waiting. Maybe allocation will succeed later...? } Uint8 *dst = device->zombie_pixels; @@ -212,7 +212,7 @@ static int ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *ti SDL_Log("CAMERA: dev[%p] Acquired Zombie frame, timestamp %llu", device, (unsigned long long) *timestampNS); #endif - return 1; // frame is available. + return SDL_CAMERA_FRAME_READY; // frame is available. } static void ZombieReleaseFrame(SDL_Camera *device, SDL_Surface *frame) // Reclaim frame->pixels and frame->pitch! @@ -650,8 +650,10 @@ void SDL_CloseCamera(SDL_Camera *camera) ClosePhysicalCamera(device); } -int SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec) +SDL_bool SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec) { + bool result; + if (!camera) { return SDL_InvalidParamError("camera"); } else if (!spec) { @@ -660,36 +662,38 @@ int SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec) SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device. ObtainPhysicalCameraObj(device); - const int retval = (device->permission > 0) ? 0 : SDL_SetError("Camera permission has not been granted"); - if (retval == 0) { + if (device->permission > 0) { SDL_copyp(spec, &device->spec); + result = true; } else { SDL_zerop(spec); + result = SDL_SetError("Camera permission has not been granted"); } ReleaseCamera(device); - return 0; + + return result; } const char *SDL_GetCameraName(SDL_CameraID instance_id) { - const char *retval = NULL; + const char *result = NULL; SDL_Camera *device = ObtainPhysicalCamera(instance_id); if (device) { - retval = SDL_GetPersistentString(device->name); + result = SDL_GetPersistentString(device->name); ReleaseCamera(device); } - return retval; + return result; } SDL_CameraPosition SDL_GetCameraPosition(SDL_CameraID instance_id) { - SDL_CameraPosition retval = SDL_CAMERA_POSITION_UNKNOWN; + SDL_CameraPosition result = SDL_CAMERA_POSITION_UNKNOWN; SDL_Camera *device = ObtainPhysicalCamera(instance_id); if (device) { - retval = device->position; + result = device->position; ReleaseCamera(device); } - return retval; + return result; } @@ -706,12 +710,12 @@ SDL_CameraID *SDL_GetCameras(int *count) return NULL; } - SDL_CameraID *retval = NULL; + SDL_CameraID *result = NULL; SDL_LockRWLockForReading(camera_driver.device_hash_lock); int num_devices = SDL_AtomicGet(&camera_driver.device_count); - retval = (SDL_CameraID *) SDL_malloc((num_devices + 1) * sizeof (SDL_CameraID)); - if (!retval) { + result = (SDL_CameraID *) SDL_malloc((num_devices + 1) * sizeof (SDL_CameraID)); + if (!result) { num_devices = 0; } else { int devs_seen = 0; @@ -719,17 +723,17 @@ SDL_CameraID *SDL_GetCameras(int *count) const void *value; void *iter = NULL; while (SDL_IterateHashTable(camera_driver.device_hash, &key, &value, &iter)) { - retval[devs_seen++] = (SDL_CameraID) (uintptr_t) key; + result[devs_seen++] = (SDL_CameraID) (uintptr_t) key; } SDL_assert(devs_seen == num_devices); - retval[devs_seen] = 0; // null-terminated. + result[devs_seen] = 0; // null-terminated. } SDL_UnlockRWLock(camera_driver.device_hash_lock); *count = num_devices; - return retval; + return result; } SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *count) @@ -745,14 +749,14 @@ SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *co int i; int num_specs = device->num_specs; - SDL_CameraSpec **retval = (SDL_CameraSpec **) SDL_malloc(((num_specs + 1) * sizeof(*retval)) + (num_specs * sizeof (**retval))); - if (retval) { - SDL_CameraSpec *specs = (SDL_CameraSpec *)(retval + (num_specs + 1)); + SDL_CameraSpec **result = (SDL_CameraSpec **) SDL_malloc(((num_specs + 1) * sizeof(*result)) + (num_specs * sizeof (**result))); + if (result) { + SDL_CameraSpec *specs = (SDL_CameraSpec *)(result + (num_specs + 1)); SDL_memcpy(specs, device->all_specs, num_specs * sizeof(*specs)); for (i = 0; i < num_specs; ++i) { - retval[i] = specs++; + result[i] = specs++; } - retval[i] = NULL; + result[i] = NULL; if (count) { *count = num_specs; @@ -761,7 +765,7 @@ SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *co ReleaseCamera(device); - return retval; + return result; } @@ -806,9 +810,9 @@ bool SDL_CameraThreadIterate(SDL_Camera *device) Uint64 timestampNS = 0; // AcquireFrame SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice instead! - const int rc = device->AcquireFrame(device, device->acquire_surface, ×tampNS); + const SDL_CameraFrameResult rc = device->AcquireFrame(device, device->acquire_surface, ×tampNS); - if (rc == 1) { // new frame acquired! + if (rc == SDL_CAMERA_FRAME_READY) { // new frame acquired! #if DEBUG_CAMERA SDL_Log("CAMERA: New frame available! pixels=%p pitch=%d", device->acquire_surface->pixels, device->acquire_surface->pitch); #endif @@ -842,12 +846,11 @@ bool SDL_CameraThreadIterate(SDL_Camera *device) acquired = device->acquire_surface; slist->timestampNS = timestampNS; } - } else if (rc == 0) { // no frame available yet; not an error. + } else if (rc == SDL_CAMERA_FRAME_SKIP) { // no frame available yet; not an error. #if 0 //DEBUG_CAMERA SDL_Log("CAMERA: No frame available yet."); #endif } else { // fatal error! - SDL_assert(rc == -1); #if DEBUG_CAMERA SDL_Log("CAMERA: dev[%p] error AcquireFrame: %s", device, SDL_GetError()); #endif @@ -931,7 +934,7 @@ static int SDLCALL CameraThread(void *devicep) SDL_CameraThreadSetup(device); do { - if (device->WaitDevice(device) < 0) { + if (!device->WaitDevice(device)) { SDL_CameraDisconnected(device); // doh. (but don't break out of the loop, just be a zombie for now!) } } while (SDL_CameraThreadIterate(device)); @@ -1091,7 +1094,7 @@ SDL_Camera *SDL_OpenCamera(SDL_CameraID instance_id, const SDL_CameraSpec *spec) closest.width, closest.height, SDL_GetPixelFormatName(closest.format), closest.framerate_numerator, closest.framerate_denominator); #endif - if (camera_driver.impl.OpenDevice(device, &closest) < 0) { + if (!camera_driver.impl.OpenDevice(device, &closest)) { ClosePhysicalCamera(device); // in case anything is half-initialized. ReleaseCamera(device); return NULL; @@ -1219,7 +1222,7 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS) return NULL; } - SDL_Surface *retval = NULL; + SDL_Surface *result = NULL; // frames are in this list from newest to oldest, so find the end of the list... SurfaceList *slistprev = &device->filled_output_surfaces; @@ -1234,7 +1237,7 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS) if (timestampNS) { *timestampNS = slist->timestampNS; } - retval = slist->surface; + result = slist->surface; slistprev->next = slist->next; // remove from filled list. slist->next = device->app_held_output_surfaces.next; // add to app_held list. device->app_held_output_surfaces.next = slist; @@ -1242,15 +1245,13 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS) ReleaseCamera(device); - return retval; + return result; } -int SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame) +void SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame) { - if (!camera) { - return SDL_InvalidParamError("camera"); - } else if (frame == NULL) { - return SDL_InvalidParamError("frame"); + if (!camera || !frame) { + return; } SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device. @@ -1267,7 +1268,7 @@ int SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame) if (!slist) { ReleaseCamera(device); - return SDL_SetError("Surface was not acquired from this camera, or was already released"); + return; } // this pointer was owned by the backend (DMA memory or whatever), clear it out. @@ -1287,28 +1288,26 @@ int SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame) device->empty_output_surfaces.next = slist; ReleaseCamera(device); - - return 0; } SDL_CameraID SDL_GetCameraID(SDL_Camera *camera) { - SDL_CameraID retval = 0; + SDL_CameraID result = 0; if (!camera) { SDL_InvalidParamError("camera"); } else { SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device. ObtainPhysicalCameraObj(device); - retval = device->instance_id; + result = device->instance_id; ReleaseCamera(device); } - return retval; + return result; } SDL_PropertiesID SDL_GetCameraProperties(SDL_Camera *camera) { - SDL_PropertiesID retval = 0; + SDL_PropertiesID result = 0; if (!camera) { SDL_InvalidParamError("camera"); } else { @@ -1317,26 +1316,26 @@ SDL_PropertiesID SDL_GetCameraProperties(SDL_Camera *camera) if (device->props == 0) { device->props = SDL_CreateProperties(); } - retval = device->props; + result = device->props; ReleaseCamera(device); } - return retval; + return result; } int SDL_GetCameraPermissionState(SDL_Camera *camera) { - int retval; + int result; if (!camera) { - retval = SDL_InvalidParamError("camera"); + SDL_InvalidParamError("camera"); + result = -1; } else { SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device. ObtainPhysicalCameraObj(device); - retval = device->permission; + result = device->permission; ReleaseCamera(device); } - - return retval; + return result; } @@ -1408,7 +1407,7 @@ static void NukeCameraHashItem(const void *key, const void *value, void *data) // no-op, keys and values in this hashtable are treated as Plain Old Data and don't get freed here. } -int SDL_CameraInit(const char *driver_name) +SDL_bool SDL_CameraInit(const char *driver_name) { if (SDL_GetCurrentCameraDriver()) { SDL_QuitCamera(); // shutdown driver if already running. @@ -1416,13 +1415,13 @@ int SDL_CameraInit(const char *driver_name) SDL_RWLock *device_hash_lock = SDL_CreateRWLock(); // create this early, so if it fails we don't have to tear down the whole camera subsystem. if (!device_hash_lock) { - return -1; + return false; } SDL_HashTable *device_hash = SDL_CreateHashTable(NULL, 8, HashCameraID, MatchCameraID, NukeCameraHashItem, false); if (!device_hash) { SDL_DestroyRWLock(device_hash_lock); - return -1; + return false; } // Select the proper camera driver @@ -1440,7 +1439,7 @@ int SDL_CameraInit(const char *driver_name) if (!driver_name_copy) { SDL_DestroyRWLock(device_hash_lock); SDL_DestroyHashTable(device_hash); - return -1; + return false; } while (driver_attempt && (*driver_attempt != 0) && !initialized) { @@ -1501,7 +1500,7 @@ int SDL_CameraInit(const char *driver_name) SDL_zero(camera_driver); SDL_DestroyRWLock(device_hash_lock); SDL_DestroyHashTable(device_hash); - return -1; // No driver was available, so fail. + return false; // No driver was available, so fail. } CompleteCameraEntryPoints(); @@ -1509,7 +1508,7 @@ int SDL_CameraInit(const char *driver_name) // Make sure we have a list of devices available at startup... camera_driver.impl.DetectDevices(); - return 0; + return true; } // This is an internal function, so SDL_PumpEvents() can check for pending camera device events. diff --git a/src/camera/SDL_camera_c.h b/src/camera/SDL_camera_c.h index 6fae3101df..2ffe2c1610 100644 --- a/src/camera/SDL_camera_c.h +++ b/src/camera/SDL_camera_c.h @@ -24,10 +24,10 @@ #define SDL_camera_c_h_ // Initialize the camera subsystem -int SDL_CameraInit(const char *driver_name); +extern SDL_bool SDL_CameraInit(const char *driver_name); // Shutdown the camera subsystem -void SDL_QuitCamera(void); +extern void SDL_QuitCamera(void); // "Pump" the event queue. extern void SDL_UpdateCamera(void); diff --git a/src/camera/SDL_syscamera.h b/src/camera/SDL_syscamera.h index a48779824e..cff81a5b00 100644 --- a/src/camera/SDL_syscamera.h +++ b/src/camera/SDL_syscamera.h @@ -64,7 +64,14 @@ typedef struct CameraFormatAddData int allocated_specs; } CameraFormatAddData; -int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator); +bool SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator); + +typedef enum SDL_CameraFrameResult +{ + SDL_CAMERA_FRAME_ERROR, + SDL_CAMERA_FRAME_SKIP, + SDL_CAMERA_FRAME_READY +} SDL_CameraFrameResult; typedef struct SurfaceList { @@ -89,8 +96,8 @@ struct SDL_Camera SDL_AtomicInt refcount; // These are, initially, set from camera_driver, but we might swap them out with Zombie versions on disconnect/failure. - int (*WaitDevice)(SDL_Camera *device); - int (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS); + bool (*WaitDevice)(SDL_Camera *device); + SDL_CameraFrameResult (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS); void (*ReleaseFrame)(SDL_Camera *device, SDL_Surface *frame); // All supported formats/dimensions for this device. @@ -161,10 +168,10 @@ struct SDL_Camera typedef struct SDL_CameraDriverImpl { void (*DetectDevices)(void); - int (*OpenDevice)(SDL_Camera *device, const SDL_CameraSpec *spec); + bool (*OpenDevice)(SDL_Camera *device, const SDL_CameraSpec *spec); void (*CloseDevice)(SDL_Camera *device); - int (*WaitDevice)(SDL_Camera *device); - int (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS); // set frame->pixels, frame->pitch, and *timestampNS! + bool (*WaitDevice)(SDL_Camera *device); + SDL_CameraFrameResult (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS); // set frame->pixels, frame->pitch, and *timestampNS! void (*ReleaseFrame)(SDL_Camera *device, SDL_Surface *frame); // Reclaim frame->pixels and frame->pitch! void (*FreeDeviceHandle)(SDL_Camera *device); // SDL is done with this device; free the handle from SDL_AddCamera() void (*Deinitialize)(void); diff --git a/src/camera/android/SDL_camera_android.c b/src/camera/android/SDL_camera_android.c index 9fb8deec46..640b291617 100644 --- a/src/camera/android/SDL_camera_android.c +++ b/src/camera/android/SDL_camera_android.c @@ -150,7 +150,7 @@ struct SDL_PrivateCameraData SDL_CameraSpec requested_spec; }; -static int SetErrorStr(const char *what, const char *errstr, const int rc) +static bool SetErrorStr(const char *what, const char *errstr, const int rc) { char errbuf[128]; if (!errstr) { @@ -185,7 +185,7 @@ static const char *CameraStatusStr(const camera_status_t rc) return NULL; // unknown error } -static int SetCameraError(const char *what, const camera_status_t rc) +static bool SetCameraError(const char *what, const camera_status_t rc) { return SetErrorStr(what, CameraStatusStr(rc), (int) rc); } @@ -225,7 +225,7 @@ static const char *MediaStatusStr(const media_status_t rc) return NULL; // unknown error } -static int SetMediaError(const char *what, const media_status_t rc) +static bool SetMediaError(const char *what, const media_status_t rc) { return SetErrorStr(what, MediaStatusStr(rc), (int) rc); } @@ -233,7 +233,7 @@ static int SetMediaError(const char *what, const media_status_t rc) static ACameraManager *cameraMgr = NULL; -static int CreateCameraManager(void) +static bool CreateCameraManager(void) { SDL_assert(cameraMgr == NULL); @@ -241,7 +241,7 @@ static int CreateCameraManager(void) if (!cameraMgr) { return SDL_SetError("Error creating ACameraManager"); } - return 0; + return true; } static void DestroyCameraManager(void) @@ -289,14 +289,14 @@ static Uint32 format_sdl_to_android(SDL_PixelFormat fmt) } } -static int ANDROIDCAMERA_WaitDevice(SDL_Camera *device) +static bool ANDROIDCAMERA_WaitDevice(SDL_Camera *device) { - return 0; // this isn't used atm, since we run our own thread via onImageAvailable callbacks. + return true; // this isn't used atm, since we run our own thread via onImageAvailable callbacks. } -static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { - int retval = 1; + SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY; media_status_t res; AImage *image = NULL; @@ -307,7 +307,8 @@ static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Ui SDL_assert(res != AMEDIA_IMGREADER_NO_BUFFER_AVAILABLE); // we should only be here if onImageAvailable was called. if (res != AMEDIA_OK) { - return SetMediaError("Error AImageReader_acquireNextImage", res); + SetMediaError("Error AImageReader_acquireNextImage", res); + return SDL_CAMERA_FRAME_ERROR; } int64_t atimestamp = 0; @@ -336,7 +337,7 @@ static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Ui frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen); if (frame->pixels == NULL) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { int32_t row_stride = 0; Uint8 *dst = frame->pixels; @@ -355,7 +356,7 @@ static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Ui pAImage_delete(image); - return retval; + return result; } static void ANDROIDCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) @@ -458,7 +459,7 @@ static void ANDROIDCAMERA_CloseDevice(SDL_Camera *device) } // this is where the "opening" of the camera happens, after permission is granted. -static int PrepareCamera(SDL_Camera *device) +static bool PrepareCamera(SDL_Camera *device) { SDL_assert(device->hidden != NULL); @@ -512,7 +513,7 @@ static int PrepareCamera(SDL_Camera *device) return SetMediaError("Error AImageReader_setImageListener", res2); } - return 0; + return true; } static void SDLCALL CameraPermissionCallback(void *userdata, const char *permission, SDL_bool granted) @@ -521,7 +522,7 @@ static void SDLCALL CameraPermissionCallback(void *userdata, const char *permiss if (device->hidden != NULL) { // if device was already closed, don't send an event. if (!granted) { SDL_CameraPermissionOutcome(device, false); // sorry, permission denied. - } else if (PrepareCamera(device) < 0) { // permission given? Actually open the camera now. + } else if (!PrepareCamera(device)) { // permission given? Actually open the camera now. // uhoh, setup failed; since the app thinks we already "opened" the device, mark it as disconnected and don't report the permission. SDL_CameraDisconnected(device); } else { @@ -534,7 +535,7 @@ static void SDLCALL CameraPermissionCallback(void *userdata, const char *permiss } -static int ANDROIDCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) +static bool ANDROIDCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) { #if 0 // !!! FIXME: for now, we'll just let this fail if it is going to fail, without checking for this /* Cannot open a second camera, while the first one is opened. @@ -552,19 +553,19 @@ static int ANDROIDCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *sp device->hidden = (struct SDL_PrivateCameraData *) SDL_calloc(1, sizeof (struct SDL_PrivateCameraData)); if (device->hidden == NULL) { - return -1; + return false; } RefPhysicalCamera(device); // ref'd until permission callback fires. // just in case SDL_OpenCamera is overwriting device->spec as CameraPermissionCallback runs, we work from a different copy. SDL_copyp(&device->hidden->requested_spec, spec); - if (SDL_RequestAndroidPermission("android.permission.CAMERA", CameraPermissionCallback, device) < 0) { + if (!SDL_RequestAndroidPermission("android.permission.CAMERA", CameraPermissionCallback, device)) { UnrefPhysicalCamera(device); - return -1; + return false; } - return 0; // we don't open the camera until permission is granted, so always succeed for now. + return true; // we don't open the camera until permission is granted, so always succeed for now. } static void ANDROIDCAMERA_FreeDeviceHandle(SDL_Camera *device) @@ -864,7 +865,7 @@ static bool ANDROIDCAMERA_Init(SDL_CameraDriverImpl *impl) dlclose(libcamera2); } - if (CreateCameraManager() < 0) { + if (!CreateCameraManager()) { dlclose(libmedia); dlclose(libcamera2); return false; diff --git a/src/camera/coremedia/SDL_camera_coremedia.m b/src/camera/coremedia/SDL_camera_coremedia.m index f865fcd5eb..800340b4dc 100644 --- a/src/camera/coremedia/SDL_camera_coremedia.m +++ b/src/camera/coremedia/SDL_camera_coremedia.m @@ -141,14 +141,14 @@ static bool CheckCameraPermissions(SDL_Camera *device) } @end -static int COREMEDIA_WaitDevice(SDL_Camera *device) +static bool COREMEDIA_WaitDevice(SDL_Camera *device) { - return 0; // this isn't used atm, since we run our own thread out of Grand Central Dispatch. + return true; // this isn't used atm, since we run our own thread out of Grand Central Dispatch. } -static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { - int retval = 1; + SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY; SDLPrivateCameraData *hidden = (__bridge SDLPrivateCameraData *) device->hidden; CMSampleBufferRef sample_buffer = hidden.current_sample; hidden.current_sample = NULL; @@ -185,7 +185,7 @@ static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 const size_t buflen = pitch * frame->h; frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen); if (frame->pixels == NULL) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { frame->pitch = pitch; SDL_memcpy(frame->pixels, CVPixelBufferGetBaseAddress(image), buflen); @@ -203,7 +203,7 @@ static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 frame->pitch = (int)CVPixelBufferGetBytesPerRowOfPlane(image, 0); // this is what SDL3 currently expects frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen); if (frame->pixels == NULL) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { Uint8 *dst = frame->pixels; for (int i = 0; i < numPlanes; i++) { @@ -219,7 +219,7 @@ static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 CVPixelBufferUnlockBaseAddress(image, 0); - return retval; + return result; } static void COREMEDIA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) @@ -248,7 +248,7 @@ static void COREMEDIA_CloseDevice(SDL_Camera *device) } } -static int COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) +static bool COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) { AVCaptureDevice *avdevice = (__bridge AVCaptureDevice *) device->handle; @@ -364,7 +364,7 @@ static int COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) CheckCameraPermissions(device); // check right away, in case the process is already granted permission. - return 0; + return true; } static void COREMEDIA_FreeDeviceHandle(SDL_Camera *device) diff --git a/src/camera/dummy/SDL_camera_dummy.c b/src/camera/dummy/SDL_camera_dummy.c index a46d7da8a8..d2e9a898e7 100644 --- a/src/camera/dummy/SDL_camera_dummy.c +++ b/src/camera/dummy/SDL_camera_dummy.c @@ -24,7 +24,7 @@ #include "../SDL_syscamera.h" -static int DUMMYCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) +static bool DUMMYCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) { return SDL_Unsupported(); } @@ -33,14 +33,15 @@ static void DUMMYCAMERA_CloseDevice(SDL_Camera *device) { } -static int DUMMYCAMERA_WaitDevice(SDL_Camera *device) +static bool DUMMYCAMERA_WaitDevice(SDL_Camera *device) { return SDL_Unsupported(); } -static int DUMMYCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult DUMMYCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { - return SDL_Unsupported(); + SDL_Unsupported(); + return SDL_CAMERA_FRAME_ERROR; } static void DUMMYCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) diff --git a/src/camera/emscripten/SDL_camera_emscripten.c b/src/camera/emscripten/SDL_camera_emscripten.c index 69cb921105..88f9a85fe6 100644 --- a/src/camera/emscripten/SDL_camera_emscripten.c +++ b/src/camera/emscripten/SDL_camera_emscripten.c @@ -34,17 +34,17 @@ EM_JS_DEPS(sdlcamera, "$dynCall"); -static int EMSCRIPTENCAMERA_WaitDevice(SDL_Camera *device) +static bool EMSCRIPTENCAMERA_WaitDevice(SDL_Camera *device) { SDL_assert(!"This shouldn't be called"); // we aren't using SDL's internal thread. - return -1; + return false; } -static int EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { void *rgba = SDL_malloc(device->actual_spec.width * device->actual_spec.height * 4); if (!rgba) { - return -1; + return SDL_CAMERA_FRAME_ERROR; } *timestampNS = SDL_GetTicksNS(); // best we can do here. @@ -67,13 +67,13 @@ static int EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, if (!rc) { SDL_free(rgba); - return 0; // something went wrong, maybe shutting down; just don't return a frame. + return SDL_CAMERA_FRAME_ERROR; // something went wrong, maybe shutting down; just don't return a frame. } frame->pixels = rgba; frame->pitch = device->actual_spec.width * 4; - return 1; + return SDL_CAMERA_FRAME_READY; } static void EMSCRIPTENCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) @@ -110,7 +110,7 @@ static void SDLEmscriptenCameraPermissionOutcome(SDL_Camera *device, int approve SDL_CameraPermissionOutcome(device, approved ? true : false); } -static int EMSCRIPTENCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) +static bool EMSCRIPTENCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) { MAIN_THREAD_EM_ASM({ // Since we can't get actual specs until we make a move that prompts the user for @@ -203,7 +203,7 @@ static int EMSCRIPTENCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec }); }, device, spec->width, spec->height, spec->framerate_numerator, spec->framerate_denominator, SDLEmscriptenCameraPermissionOutcome, SDL_CameraThreadIterate); - return 0; // the real work waits until the user approves a camera. + return true; // the real work waits until the user approves a camera. } static void EMSCRIPTENCAMERA_FreeDeviceHandle(SDL_Camera *device) diff --git a/src/camera/mediafoundation/SDL_camera_mediafoundation.c b/src/camera/mediafoundation/SDL_camera_mediafoundation.c index 192c26bf4c..d26fe6cbe2 100644 --- a/src/camera/mediafoundation/SDL_camera_mediafoundation.c +++ b/src/camera/mediafoundation/SDL_camera_mediafoundation.c @@ -347,7 +347,7 @@ typedef struct SDL_PrivateCameraData int pitch; } SDL_PrivateCameraData; -static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device) +static bool MEDIAFOUNDATION_WaitDevice(SDL_Camera *device) { SDL_assert(device->hidden->current_sample == NULL); @@ -358,7 +358,7 @@ static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device) DWORD stream_flags = 0; const HRESULT ret = IMFSourceReader_ReadSample(srcreader, (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, &stream_flags, NULL, &sample); if (FAILED(ret)) { - return -1; // ruh roh. + return false; // ruh roh. } // we currently ignore stream_flags format changes, but my _hope_ is that IMFSourceReader is handling this and @@ -368,7 +368,7 @@ static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device) if (sample != NULL) { break; } else if (stream_flags & (MF_SOURCE_READERF_ERROR | MF_SOURCE_READERF_ENDOFSTREAM)) { - return -1; // apparently this camera has gone down. :/ + return false; // apparently this camera has gone down. :/ } // otherwise, there was some minor burp, probably; just try again. @@ -376,7 +376,7 @@ static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device) device->hidden->current_sample = sample; - return 0; + return true; } @@ -421,17 +421,17 @@ static void SDLCALL CleanupIMFMediaBuffer(void *userdata, void *value) SDL_free(objs); } -static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { SDL_assert(device->hidden->current_sample != NULL); - - int retval = 1; + + SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY; HRESULT ret; LONGLONG timestamp100NS = 0; SDL_IMFObjects *objs = (SDL_IMFObjects *) SDL_calloc(1, sizeof (SDL_IMFObjects)); if (objs == NULL) { - return -1; + return SDL_CAMERA_FRAME_ERROR; } objs->sample = device->hidden->current_sample; @@ -439,21 +439,21 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, const SDL_PropertiesID surfprops = SDL_GetSurfaceProperties(frame); if (!surfprops) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { ret = IMFSample_GetSampleTime(objs->sample, ×tamp100NS); if (FAILED(ret)) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } *timestampNS = timestamp100NS * 100; // the timestamps are in 100-nanosecond increments; move to full nanoseconds. } - ret = (retval < 0) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(objs->sample, &objs->buffer); // IMFSample_GetBufferByIndex(objs->sample, 0, &objs->buffer); + ret = (result == SDL_CAMERA_FRAME_ERROR) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(objs->sample, &objs->buffer); // IMFSample_GetBufferByIndex(objs->sample, 0, &objs->buffer); if (FAILED(ret)) { SDL_free(objs); - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { BYTE *pixels = NULL; LONG pitch = 0; @@ -463,25 +463,25 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, DWORD buflen = 0; ret = IMF2DBuffer2_Lock2DSize(objs->buffer2d2, MF2DBuffer_LockFlags_Read, &pixels, &pitch, &bufstart, &buflen); if (FAILED(ret)) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; CleanupIMF2DBuffer2(NULL, objs); } else { frame->pixels = pixels; frame->pitch = (int) pitch; - if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL) < 0) { - retval = -1; + if (!SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL)) { + result = SDL_CAMERA_FRAME_ERROR; } } } else if (SUCCEEDED(IMFMediaBuffer_QueryInterface(objs->buffer, &SDL_IID_IMF2DBuffer, (void **)&objs->buffer2d))) { ret = IMF2DBuffer_Lock2D(objs->buffer2d, &pixels, &pitch); if (FAILED(ret)) { CleanupIMF2DBuffer(NULL, objs); - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { frame->pixels = pixels; frame->pitch = (int) pitch; - if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL) < 0) { - retval = -1; + if (!SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL)) { + result = SDL_CAMERA_FRAME_ERROR; } } } else { @@ -489,7 +489,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, ret = IMFMediaBuffer_Lock(objs->buffer, &pixels, &maxlen, ¤tlen); if (FAILED(ret)) { CleanupIMFMediaBuffer(NULL, objs); - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { pitch = (LONG) device->hidden->pitch; if (pitch < 0) { // image rows are reversed. @@ -497,18 +497,18 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, } frame->pixels = pixels; frame->pitch = (int) pitch; - if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL) < 0) { - retval = -1; + if (!SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL)) { + result = SDL_CAMERA_FRAME_ERROR; } } } } - if (retval < 0) { + if (result != SDL_CAMERA_FRAME_READY) { *timestampNS = 0; } - return retval; + return result; } static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) @@ -522,11 +522,11 @@ static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) #else -static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { SDL_assert(device->hidden->current_sample != NULL); - int retval = 1; + SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY; HRESULT ret; LONGLONG timestamp100NS = 0; @@ -535,21 +535,21 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, const SDL_PropertiesID surfprops = SDL_GetSurfaceProperties(frame); if (!surfprops) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { ret = IMFSample_GetSampleTime(sample, ×tamp100NS); if (FAILED(ret)) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } *timestampNS = timestamp100NS * 100; // the timestamps are in 100-nanosecond increments; move to full nanoseconds. } IMFMediaBuffer *buffer = NULL; - ret = (retval < 0) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(sample, &buffer); // IMFSample_GetBufferByIndex(sample, 0, &buffer); + ret = (result < 0) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(sample, &buffer); // IMFSample_GetBufferByIndex(sample, 0, &buffer); if (FAILED(ret)) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { IMF2DBuffer *buffer2d = NULL; IMF2DBuffer2 *buffer2d2 = NULL; @@ -561,11 +561,11 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, DWORD buflen = 0; ret = IMF2DBuffer2_Lock2DSize(buffer2d2, MF2DBuffer_LockFlags_Read, &pixels, &pitch, &bufstart, &buflen); if (FAILED(ret)) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen); if (frame->pixels == NULL) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { SDL_memcpy(frame->pixels, pixels, buflen); frame->pitch = (int)pitch; @@ -576,7 +576,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, } else if (SUCCEEDED(IMFMediaBuffer_QueryInterface(buffer, &SDL_IID_IMF2DBuffer, (void **)&buffer2d))) { ret = IMF2DBuffer_Lock2D(buffer2d, &pixels, &pitch); if (FAILED(ret)) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { BYTE *bufstart = pixels; const DWORD buflen = (SDL_abs((int)pitch) * frame->w) * frame->h; @@ -585,7 +585,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, } frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen); if (frame->pixels == NULL) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { SDL_memcpy(frame->pixels, bufstart, buflen); frame->pitch = (int)pitch; @@ -597,7 +597,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, DWORD maxlen = 0, currentlen = 0; ret = IMFMediaBuffer_Lock(buffer, &pixels, &maxlen, ¤tlen); if (FAILED(ret)) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { BYTE *bufstart = pixels; pitch = (LONG)device->hidden->pitch; @@ -607,7 +607,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, } frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen); if (frame->pixels == NULL) { - retval = -1; + result = SDL_CAMERA_FRAME_ERROR; } else { SDL_memcpy(frame->pixels, bufstart, buflen); frame->pitch = (int)pitch; @@ -620,11 +620,11 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, IMFSample_Release(sample); - if (retval < 0) { + if (result != SDL_CAMERA_FRAME_READY) { *timestampNS = 0; } - return retval; + return result; } static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) @@ -695,7 +695,7 @@ done: } -static int MEDIAFOUNDATION_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) +static bool MEDIAFOUNDATION_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) { const char *utf8symlink = (const char *) device->handle; IMFAttributes *attrs = NULL; @@ -825,7 +825,7 @@ static int MEDIAFOUNDATION_OpenDevice(SDL_Camera *device, const SDL_CameraSpec * #undef CHECK_HRESULT - return 0; + return true; failed: @@ -861,7 +861,7 @@ failed: } SDL_free(wstrsymlink); - return -1; + return false; } static void MEDIAFOUNDATION_FreeDeviceHandle(SDL_Camera *device) diff --git a/src/camera/pipewire/SDL_camera_pipewire.c b/src/camera/pipewire/SDL_camera_pipewire.c index e91804e29c..d1b37c47ad 100644 --- a/src/camera/pipewire/SDL_camera_pipewire.c +++ b/src/camera/pipewire/SDL_camera_pipewire.c @@ -86,8 +86,7 @@ static int (*PIPEWIRE_pw_core_disconnect)(struct pw_core *); static struct pw_node_info * (*PIPEWIRE_pw_node_info_merge)(struct pw_node_info *info, const struct pw_node_info *update, bool reset); static void (*PIPEWIRE_pw_node_info_free)(struct pw_node_info *info); static struct pw_stream *(*PIPEWIRE_pw_stream_new)(struct pw_core *, const char *, struct pw_properties *); -static void (*PIPEWIRE_pw_stream_add_listener)(struct pw_stream *stream, struct spa_hook *listener, - const struct pw_stream_events *events, void *data); +static void (*PIPEWIRE_pw_stream_add_listener)(struct pw_stream *stream, struct spa_hook *listener, const struct pw_stream_events *events, void *data); static void (*PIPEWIRE_pw_stream_destroy)(struct pw_stream *); static int (*PIPEWIRE_pw_stream_connect)(struct pw_stream *, enum pw_direction, uint32_t, enum pw_stream_flags, const struct spa_pod **, uint32_t); @@ -104,26 +103,25 @@ static int (*PIPEWIRE_pw_properties_setf)(struct pw_properties *, const char *, static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC; static void *pipewire_handle = NULL; -static int pipewire_dlsym(const char *fn, void **addr) +static bool pipewire_dlsym(const char *fn, void **addr) { *addr = SDL_LoadFunction(pipewire_handle, fn); if (!*addr) { // Don't call SDL_SetError(): SDL_LoadFunction already did. - return 0; + return false; } - return 1; + return true; } -#define SDL_PIPEWIRE_SYM(x) \ - if (!pipewire_dlsym(#x, (void **)(char *)&PIPEWIRE_##x)) { \ - return -1; \ - } +#define SDL_PIPEWIRE_SYM(x) \ + if (!pipewire_dlsym(#x, (void **)(char *)&PIPEWIRE_##x)) \ + return false -static int load_pipewire_library(void) +static bool load_pipewire_library(void) { pipewire_handle = SDL_LoadObject(pipewire_library); - return pipewire_handle ? 0 : -1; + return pipewire_handle ? true : false; } static void unload_pipewire_library(void) @@ -138,9 +136,9 @@ static void unload_pipewire_library(void) #define SDL_PIPEWIRE_SYM(x) PIPEWIRE_##x = x -static int load_pipewire_library(void) +static bool load_pipewire_library(void) { - return 0; + return true; } static void unload_pipewire_library(void) @@ -150,7 +148,7 @@ static void unload_pipewire_library(void) #endif // SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC -static int load_pipewire_syms(void) +static bool load_pipewire_syms(void) { SDL_PIPEWIRE_SYM(pw_get_library_version); SDL_PIPEWIRE_SYM(pw_check_library_version); @@ -192,18 +190,18 @@ static int load_pipewire_syms(void) SDL_PIPEWIRE_SYM(pw_properties_set); SDL_PIPEWIRE_SYM(pw_properties_setf); - return 0; + return true; } -static int init_pipewire_library(void) +static bool init_pipewire_library(void) { - if (!load_pipewire_library()) { - if (!load_pipewire_syms()) { + if (load_pipewire_library()) { + if (load_pipewire_syms()) { PIPEWIRE_pw_init(NULL, NULL); - return 0; + return true; } } - return -1; + return false; } static void deinit_pipewire_library(void) @@ -293,9 +291,9 @@ static uint32_t param_clear(struct spa_list *param_list, uint32_t id) } #if PW_CHECK_VERSION(0,3,60) -#define SPA_PARAMS_INFO_SEQ(p) ((p).seq) +#define SPA_PARAMS_INFO_SEQ(p) ((p).seq) #else -#define SPA_PARAMS_INFO_SEQ(p) ((p).padding[0]) +#define SPA_PARAMS_INFO_SEQ(p) ((p).padding[0]) #endif static struct param *param_add(struct spa_list *params, @@ -472,7 +470,7 @@ static const struct pw_stream_events stream_events = { .process = on_process, }; -static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) +static bool PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) { struct pw_properties *props; const struct spa_pod *params[3]; @@ -481,11 +479,11 @@ static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *s struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); if (!device) { - return -1; + return false; } device->hidden = (struct SDL_PrivateCameraData *) SDL_calloc(1, sizeof (struct SDL_PrivateCameraData)); if (device->hidden == NULL) { - return -1; + return false; } pw_array_init(&device->hidden->buffers, 64); @@ -497,13 +495,12 @@ static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *s PW_KEY_TARGET_OBJECT, device->name, NULL); if (props == NULL) { - return -1; + return false; } - device->hidden->stream = PIPEWIRE_pw_stream_new(hotplug.core, - "SDL PipeWire Camera", props); + device->hidden->stream = PIPEWIRE_pw_stream_new(hotplug.core, "SDL PipeWire Camera", props); if (device->hidden->stream == NULL) { - return -1; + return false; } PIPEWIRE_pw_stream_add_listener(device->hidden->stream, @@ -525,12 +522,12 @@ static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *s PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS, params, n_params)) < 0) { - return -1; + return false; } PIPEWIRE_pw_thread_loop_unlock(hotplug.loop); - return 0; + return true; } static void PIPEWIRECAMERA_CloseDevice(SDL_Camera *device) @@ -550,15 +547,15 @@ static void PIPEWIRECAMERA_CloseDevice(SDL_Camera *device) PIPEWIRE_pw_thread_loop_unlock(hotplug.loop); } -static int PIPEWIRECAMERA_WaitDevice(SDL_Camera *device) +static bool PIPEWIRECAMERA_WaitDevice(SDL_Camera *device) { PIPEWIRE_pw_thread_loop_lock(hotplug.loop); PIPEWIRE_pw_thread_loop_wait(hotplug.loop); PIPEWIRE_pw_thread_loop_unlock(hotplug.loop); - return 0; + return true; } -static int PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { struct pw_buffer *b; @@ -574,7 +571,7 @@ static int PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, U } if (b == NULL) { PIPEWIRE_pw_thread_loop_unlock(hotplug.loop); - return 0; + return SDL_CAMERA_FRAME_SKIP; } #if PW_CHECK_VERSION(1,0,5) @@ -587,7 +584,7 @@ static int PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, U PIPEWIRE_pw_thread_loop_unlock(hotplug.loop); - return 1; + return SDL_CAMERA_FRAME_READY; } static void PIPEWIRECAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) @@ -625,7 +622,7 @@ static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelF SPA_FALLTHROUGH; case SPA_CHOICE_Enum: for (i = 0; i < n_vals; i++) { - if (SDL_AddCameraFormat(data, sdlfmt, colorspace, size->width, size->height, rates[i].num, rates[i].denom) < 0) { + if (!SDL_AddCameraFormat(data, sdlfmt, colorspace, size->width, size->height, rates[i].num, rates[i].denom)) { return; // Probably out of memory; we'll go with what we have, if anything. } } @@ -976,7 +973,7 @@ static bool pipewire_server_version_at_least(int major, int minor, int patch) } // The hotplug thread -static int hotplug_loop_init(void) +static bool hotplug_loop_init(void) { int res; @@ -1028,7 +1025,7 @@ static int hotplug_loop_init(void) PW_REQUIRED_MAJOR, PW_REQUIRED_MINOR, PW_REQUIRED_PATCH); } - return 0; + return true; } @@ -1037,24 +1034,24 @@ static void PIPEWIRECAMERA_Deinitialize(void) if (pipewire_initialized) { if (hotplug.loop) { PIPEWIRE_pw_thread_loop_lock(hotplug.loop); - } + } if (hotplug.registry) { - spa_hook_remove(&hotplug.registry_listener); - PIPEWIRE_pw_proxy_destroy((struct pw_proxy*)hotplug.registry); - } + spa_hook_remove(&hotplug.registry_listener); + PIPEWIRE_pw_proxy_destroy((struct pw_proxy *)hotplug.registry); + } if (hotplug.core) { - spa_hook_remove(&hotplug.core_listener); - PIPEWIRE_pw_core_disconnect(hotplug.core); - } + spa_hook_remove(&hotplug.core_listener); + PIPEWIRE_pw_core_disconnect(hotplug.core); + } if (hotplug.context) { PIPEWIRE_pw_context_destroy(hotplug.context); - } + } if (hotplug.loop) { PIPEWIRE_pw_thread_loop_unlock(hotplug.loop); PIPEWIRE_pw_thread_loop_destroy(hotplug.loop); - } + } deinit_pipewire_library(); - spa_zero(hotplug); + spa_zero(hotplug); pipewire_initialized = false; } } @@ -1063,13 +1060,13 @@ static bool PIPEWIRECAMERA_Init(SDL_CameraDriverImpl *impl) { if (!pipewire_initialized) { - if (init_pipewire_library() < 0) { + if (!init_pipewire_library()) { return false; } pipewire_initialized = true; - if (hotplug_loop_init() < 0) { + if (!hotplug_loop_init()) { PIPEWIRECAMERA_Deinitialize(); return false; } diff --git a/src/camera/v4l2/SDL_camera_v4l2.c b/src/camera/v4l2/SDL_camera_v4l2.c index 4488c4bc32..819ea1455a 100644 --- a/src/camera/v4l2/SDL_camera_v4l2.c +++ b/src/camera/v4l2/SDL_camera_v4l2.c @@ -22,13 +22,14 @@ #ifdef SDL_CAMERA_DRIVER_V4L2 -#include -#include -#include -#include // low-level i/o +#include #include +#include // low-level i/o +#include +#include #include #include +#include #include #ifndef V4L2_CAP_DEVICE_CAPS @@ -88,11 +89,11 @@ static int xioctl(int fh, int request, void *arg) return r; } -static int V4L2_WaitDevice(SDL_Camera *device) +static bool V4L2_WaitDevice(SDL_Camera *device) { const int fd = device->hidden->fd; - int retval; + int rc; do { fd_set fds; @@ -103,22 +104,22 @@ static int V4L2_WaitDevice(SDL_Camera *device) tv.tv_sec = 0; tv.tv_usec = 100 * 1000; - retval = select(fd + 1, &fds, NULL, NULL, &tv); - if ((retval == -1) && (errno == EINTR)) { - retval = 0; // pretend it was a timeout, keep looping. + rc = select(fd + 1, &fds, NULL, NULL, &tv); + if ((rc == -1) && (errno == EINTR)) { + rc = 0; // pretend it was a timeout, keep looping. } // Thread is requested to shut down if (SDL_AtomicGet(&device->shutdown)) { - return 0; + return true; } - } while (retval == 0); + } while (rc == 0); - return retval; + return false; } -static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) +static SDL_CameraFrameResult V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS) { const int fd = device->hidden->fd; const io_method io = device->hidden->io; @@ -129,15 +130,16 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim case IO_METHOD_READ: if (read(fd, device->hidden->buffers[0].start, size) == -1) { switch (errno) { - case EAGAIN: - return 0; + case EAGAIN: + return SDL_CAMERA_FRAME_SKIP; - case EIO: - // Could ignore EIO, see spec. - // fall through + case EIO: + // Could ignore EIO, see spec. + // fall through - default: - return SDL_SetError("read"); + default: + SDL_SetError("read"); + return SDL_CAMERA_FRAME_ERROR; } } @@ -154,20 +156,22 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim if (xioctl(fd, VIDIOC_DQBUF, &buf) == -1) { switch (errno) { - case EAGAIN: - return 0; + case EAGAIN: + return SDL_CAMERA_FRAME_SKIP; - case EIO: - // Could ignore EIO, see spec. - // fall through + case EIO: + // Could ignore EIO, see spec. + // fall through - default: - return SDL_SetError("VIDIOC_DQBUF: %d", errno); + default: + SDL_SetError("VIDIOC_DQBUF: %d", errno); + return SDL_CAMERA_FRAME_ERROR; } } if ((int)buf.index < 0 || (int)buf.index >= device->hidden->nb_buffers) { - return SDL_SetError("invalid buffer index"); + SDL_SetError("invalid buffer index"); + return SDL_CAMERA_FRAME_ERROR; } frame->pixels = device->hidden->buffers[buf.index].start; @@ -189,16 +193,16 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim if (xioctl(fd, VIDIOC_DQBUF, &buf) == -1) { switch (errno) { - case EAGAIN: - return 0; + case EAGAIN: + return SDL_CAMERA_FRAME_SKIP; - case EIO: - // Could ignore EIO, see spec. + case EIO: + // Could ignore EIO, see spec. + // fall through - // fall through - - default: - return SDL_SetError("VIDIOC_DQBUF"); + default: + SDL_SetError("VIDIOC_DQBUF"); + return SDL_CAMERA_FRAME_ERROR; } } @@ -210,7 +214,8 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim } if (i >= device->hidden->nb_buffers) { - return SDL_SetError("invalid buffer index"); + SDL_SetError("invalid buffer index"); + return SDL_CAMERA_FRAME_ERROR; } frame->pixels = (void*)buf.m.userptr; @@ -229,7 +234,7 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim break; } - return 1; + return SDL_CAMERA_FRAME_READY; } static void V4L2_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) @@ -289,7 +294,7 @@ static void V4L2_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame) } } -static int EnqueueBuffers(SDL_Camera *device) +static bool EnqueueBuffers(SDL_Camera *device) { const int fd = device->hidden->fd; const io_method io = device->hidden->io; @@ -335,17 +340,17 @@ static int EnqueueBuffers(SDL_Camera *device) case IO_METHOD_INVALID: SDL_assert(!"Shouldn't have hit this"); break; } - return 0; + return true; } -static int AllocBufferRead(SDL_Camera *device, size_t buffer_size) +static bool AllocBufferRead(SDL_Camera *device, size_t buffer_size) { device->hidden->buffers[0].length = buffer_size; device->hidden->buffers[0].start = SDL_calloc(1, buffer_size); - return device->hidden->buffers[0].start ? 0 : -1; + return (device->hidden->buffers[0].start != NULL); } -static int AllocBufferMmap(SDL_Camera *device) +static bool AllocBufferMmap(SDL_Camera *device) { const int fd = device->hidden->fd; int i; @@ -374,10 +379,10 @@ static int AllocBufferMmap(SDL_Camera *device) return SDL_SetError("mmap"); } } - return 0; + return true; } -static int AllocBufferUserPtr(SDL_Camera *device, size_t buffer_size) +static bool AllocBufferUserPtr(SDL_Camera *device, size_t buffer_size) { int i; for (i = 0; i < device->hidden->nb_buffers; ++i) { @@ -385,10 +390,10 @@ static int AllocBufferUserPtr(SDL_Camera *device, size_t buffer_size) device->hidden->buffers[i].start = SDL_calloc(1, buffer_size); if (!device->hidden->buffers[i].start) { - return -1; + return false; } } - return 0; + return true; } static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormat *format, SDL_Colorspace *colorspace) @@ -415,7 +420,7 @@ static Uint32 format_sdl_to_v4l2(SDL_PixelFormat fmt) CASE(V4L2_PIX_FMT_MJPEG, SDL_PIXELFORMAT_UNKNOWN); #undef CASE default: - return 0; + return true; } } @@ -470,7 +475,7 @@ static void V4L2_CloseDevice(SDL_Camera *device) } } -static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) +static bool V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) { const V4L2DeviceHandle *handle = (const V4L2DeviceHandle *) device->handle; struct stat st; @@ -501,7 +506,7 @@ static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) device->hidden = (struct SDL_PrivateCameraData *) SDL_calloc(1, sizeof (struct SDL_PrivateCameraData)); if (device->hidden == NULL) { close(fd); - return -1; + return false; } device->hidden->fd = fd; @@ -597,13 +602,15 @@ static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) device->hidden->buffers = SDL_calloc(device->hidden->nb_buffers, sizeof(*device->hidden->buffers)); if (!device->hidden->buffers) { - return -1; + return false; } size_t size, pitch; - SDL_CalculateSurfaceSize(device->spec.format, device->spec.width, device->spec.height, &size, &pitch, false); + if (!SDL_CalculateSurfaceSize(device->spec.format, device->spec.width, device->spec.height, &size, &pitch, false)) { + return false; + } - int rc = 0; + bool rc = true; switch (io) { case IO_METHOD_READ: rc = AllocBufferRead(device, size); @@ -622,10 +629,10 @@ static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) break; } - if (rc < 0) { - return -1; - } else if (EnqueueBuffers(device) < 0) { - return -1; + if (!rc) { + return false; + } else if (!EnqueueBuffers(device)) { + return false; } else if (io != IO_METHOD_READ) { enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (xioctl(fd, VIDIOC_STREAMON, &type) == -1) { @@ -636,7 +643,7 @@ static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec) // Currently there is no user permission prompt for camera access, but maybe there will be a D-Bus portal interface at some point. SDL_CameraPermissionOutcome(device, true); - return 0; + return true; } static bool FindV4L2CameraByBusInfoCallback(SDL_Camera *device, void *userdata) @@ -645,7 +652,7 @@ static bool FindV4L2CameraByBusInfoCallback(SDL_Camera *device, void *userdata) return (SDL_strcmp(handle->bus_info, (const char *) userdata) == 0); } -static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h) +static bool AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h) { struct v4l2_frmivalenum frmivalenum; SDL_zero(frmivalenum); @@ -661,8 +668,8 @@ static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFor const float fps = (float) denominator / (float) numerator; SDL_Log("CAMERA: * Has discrete frame interval (%d / %d), fps=%f", numerator, denominator, fps); #endif - if (SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, denominator, numerator) == -1) { - return -1; // Probably out of memory; we'll go with what we have, if anything. + if (!SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, denominator, numerator)) { + return false; // Probably out of memory; we'll go with what we have, if anything. } frmivalenum.index++; // set up for the next one. } else if ((frmivalenum.type == V4L2_FRMIVAL_TYPE_STEPWISE) || (frmivalenum.type == V4L2_FRMIVAL_TYPE_CONTINUOUS)) { @@ -674,8 +681,8 @@ static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFor SDL_Log("CAMERA: * Has %s frame interval (%d / %d), fps=%f", (frmivalenum.type == V4L2_FRMIVAL_TYPE_STEPWISE) ? "stepwise" : "continuous", n, d, fps); #endif // SDL expects framerate, V4L2 provides interval - if (SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, d, n) == -1) { - return -1; // Probably out of memory; we'll go with what we have, if anything. + if (!SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, d, n)) { + return false; // Probably out of memory; we'll go with what we have, if anything. } d += (int) frmivalenum.stepwise.step.denominator; } @@ -683,7 +690,7 @@ static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFor } } - return 0; + return true; } @@ -756,7 +763,7 @@ static void MaybeAddDevice(const char *path) #if DEBUG_CAMERA SDL_Log("CAMERA: * Has discrete size %dx%d", w, h); #endif - if (AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h) == -1) { + if (!AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h)) { break; // Probably out of memory; we'll go with what we have, if anything. } frmsizeenum.index++; // set up for the next one. @@ -772,7 +779,7 @@ static void MaybeAddDevice(const char *path) #if DEBUG_CAMERA SDL_Log("CAMERA: * Has %s size %dx%d", (frmsizeenum.type == V4L2_FRMSIZE_TYPE_STEPWISE) ? "stepwise" : "continuous", w, h); #endif - if (AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h) == -1) { + if (!AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h)) { break; // Probably out of memory; we'll go with what we have, if anything. } } @@ -856,12 +863,14 @@ static void V4L2_Deinitialize(void) static void V4L2_DetectDevices(void) { #ifdef SDL_USE_LIBUDEV - if (SDL_UDEV_Init() == 0) { - if (SDL_UDEV_AddCallback(CameraUdevCallback) == 0) { + if (SDL_UDEV_Init()) { + if (SDL_UDEV_AddCallback(CameraUdevCallback)) { SDL_UDEV_Scan(); // Force a scan to build the initial device list } + return; } -#else +#endif // SDL_USE_LIBUDEV + DIR *dirp = opendir("/dev"); if (dirp) { struct dirent *dent; @@ -875,7 +884,6 @@ static void V4L2_DetectDevices(void) } closedir(dirp); } -#endif // SDL_USE_LIBUDEV } static bool V4L2_Init(SDL_CameraDriverImpl *impl) diff --git a/src/core/SDL_core_unsupported.c b/src/core/SDL_core_unsupported.c index 677243c3eb..3f39e54c7b 100644 --- a/src/core/SDL_core_unsupported.c +++ b/src/core/SDL_core_unsupported.c @@ -31,16 +31,16 @@ void SDL_SetX11EventHook(SDL_X11EventHook callback, void *userdata) #ifndef SDL_PLATFORM_LINUX -SDL_DECLSPEC int SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority); -int SDL_SetLinuxThreadPriority(Sint64 threadID, int priority) +SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriority(Sint64 threadID, int priority); +SDL_bool SDL_SetLinuxThreadPriority(Sint64 threadID, int priority) { (void)threadID; (void)priority; return SDL_Unsupported(); } -SDL_DECLSPEC int SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy); -int SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy) +SDL_DECLSPEC SDL_bool SDLCALL SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy); +SDL_bool SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy) { (void)threadID; (void)sdlPriority; @@ -58,8 +58,8 @@ void SDL_GDKSuspendComplete(void) SDL_Unsupported(); } -SDL_DECLSPEC int SDLCALL SDL_GetGDKDefaultUser(void *outUserHandle); /* XUserHandle *outUserHandle */ -int SDL_GetGDKDefaultUser(void *outUserHandle) +SDL_DECLSPEC SDL_bool SDLCALL SDL_GetGDKDefaultUser(void *outUserHandle); /* XUserHandle *outUserHandle */ +SDL_bool SDL_GetGDKDefaultUser(void *outUserHandle) { return SDL_Unsupported(); } @@ -68,8 +68,8 @@ int SDL_GetGDKDefaultUser(void *outUserHandle) #if !(defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_GDK)) -SDL_DECLSPEC int SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst); -int SDL_RegisterApp(const char *name, Uint32 style, void *hInst) +SDL_DECLSPEC SDL_bool SDLCALL SDL_RegisterApp(const char *name, Uint32 style, void *hInst); +SDL_bool SDL_RegisterApp(const char *name, Uint32 style, void *hInst) { (void)name; (void)style; @@ -163,8 +163,8 @@ void *SDL_GetAndroidJNIEnv(void) } typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, const char *permission, bool granted); -SDL_DECLSPEC int SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata); -int SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata) +SDL_DECLSPEC SDL_bool SDLCALL SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata); +SDL_bool SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata) { (void)permission; (void)cb; @@ -172,16 +172,16 @@ int SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermi return SDL_Unsupported(); } -SDL_DECLSPEC int SDLCALL SDL_SendAndroidMessage(Uint32 command, int param); -int SDL_SendAndroidMessage(Uint32 command, int param) +SDL_DECLSPEC SDL_bool SDLCALL SDL_SendAndroidMessage(Uint32 command, int param); +SDL_bool SDL_SendAndroidMessage(Uint32 command, int param) { (void)command; (void)param; return SDL_Unsupported(); } -SDL_DECLSPEC int SDLCALL SDL_ShowAndroidToast(const char* message, int duration, int gravity, int xoffset, int yoffset); -int SDL_ShowAndroidToast(const char* message, int duration, int gravity, int xoffset, int yoffset) +SDL_DECLSPEC SDL_bool SDLCALL SDL_ShowAndroidToast(const char* message, int duration, int gravity, int xoffset, int yoffset); +SDL_bool SDL_ShowAndroidToast(const char* message, int duration, int gravity, int xoffset, int yoffset) { (void)message; (void)duration; diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index 3b200e9b81..670160524a 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -268,11 +268,11 @@ static JNINativeMethod SDLAudioManager_tab[] = { JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI)( JNIEnv *env, jclass jcls); -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)( +JNIEXPORT jboolean JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)( JNIEnv *env, jclass jcls, jint device_id, jint keycode); -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)( +JNIEXPORT jboolean JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)( JNIEnv *env, jclass jcls, jint device_id, jint keycode); @@ -284,33 +284,33 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)( JNIEnv *env, jclass jcls, jint device_id, jint hat_id, jint x, jint y); -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)( JNIEnv *env, jclass jcls, jint device_id, jstring device_name, jstring device_desc, jint vendor_id, jint product_id, jint button_mask, jint naxes, jint axis_mask, jint nhats, jboolean can_rumble); -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)( JNIEnv *env, jclass jcls, jint device_id); -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)( JNIEnv *env, jclass jcls, jint device_id, jstring device_name); -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)( JNIEnv *env, jclass jcls, jint device_id); static JNINativeMethod SDLControllerManager_tab[] = { { "nativeSetupJNI", "()I", SDL_JAVA_CONTROLLER_INTERFACE(nativeSetupJNI) }, - { "onNativePadDown", "(II)I", SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown) }, - { "onNativePadUp", "(II)I", SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp) }, + { "onNativePadDown", "(II)Z", SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown) }, + { "onNativePadUp", "(II)Z", SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp) }, { "onNativeJoy", "(IIF)V", SDL_JAVA_CONTROLLER_INTERFACE(onNativeJoy) }, { "onNativeHat", "(IIII)V", SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat) }, - { "nativeAddJoystick", "(ILjava/lang/String;Ljava/lang/String;IIIIIIZ)I", SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick) }, - { "nativeRemoveJoystick", "(I)I", SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick) }, - { "nativeAddHaptic", "(ILjava/lang/String;)I", SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic) }, - { "nativeRemoveHaptic", "(I)I", SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic) } + { "nativeAddJoystick", "(ILjava/lang/String;Ljava/lang/String;IIIIIIZ)V", SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick) }, + { "nativeRemoveJoystick", "(I)V", SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick) }, + { "nativeAddHaptic", "(ILjava/lang/String;)V", SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic) }, + { "nativeRemoveHaptic", "(I)V", SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic) } }; // Uncomment this to log messages entering and exiting methods in this file @@ -434,13 +434,14 @@ static int Android_NumLifecycleEvents; */ // Set local storage value -static int Android_JNI_SetEnv(JNIEnv *env) +static bool Android_JNI_SetEnv(JNIEnv *env) { int status = pthread_setspecific(mThreadKey, env); if (status < 0) { __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed pthread_setspecific() in Android_JNI_SetEnv() (err=%d)", status); + return false; } - return status; + return true; } // Get local storage value @@ -467,7 +468,7 @@ JNIEnv *Android_JNI_GetEnv(void) } // Save JNIEnv into the Thread local storage - if (Android_JNI_SetEnv(env) < 0) { + if (!Android_JNI_SetEnv(env)) { return NULL; } } @@ -476,7 +477,7 @@ JNIEnv *Android_JNI_GetEnv(void) } // Set up an external thread for using JNI with Android_JNI_GetEnv() -int Android_JNI_SetupThread(void) +bool Android_JNI_SetupThread(void) { JNIEnv *env; int status; @@ -484,7 +485,7 @@ int Android_JNI_SetupThread(void) // There should be a JVM if (!mJavaVM) { __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed, there is no JavaVM"); - return 0; + return false; } /* Attach the current thread to the JVM and get a JNIEnv. @@ -492,15 +493,15 @@ int Android_JNI_SetupThread(void) status = (*mJavaVM)->AttachCurrentThread(mJavaVM, &env, NULL); if (status < 0) { __android_log_print(ANDROID_LOG_ERROR, "SDL", "Failed to attach current thread (err=%d)", status); - return 0; + return false; } // Save JNIEnv into the Thread local storage - if (Android_JNI_SetEnv(env) < 0) { - return 0; + if (!Android_JNI_SetEnv(env)) { + return false; } - return 1; + return true; } // Destructor called for each thread where mThreadKey is not NULL @@ -642,9 +643,9 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativeSetupJNI)(JNIEnv *env, jclass cl midIsTablet = (*env)->GetStaticMethodID(env, mActivityClass, "isTablet", "()Z"); midManualBackButton = (*env)->GetStaticMethodID(env, mActivityClass, "manualBackButton", "()V"); midMinimizeWindow = (*env)->GetStaticMethodID(env, mActivityClass, "minimizeWindow", "()V"); - midOpenURL = (*env)->GetStaticMethodID(env, mActivityClass, "openURL", "(Ljava/lang/String;)I"); + midOpenURL = (*env)->GetStaticMethodID(env, mActivityClass, "openURL", "(Ljava/lang/String;)Z"); midRequestPermission = (*env)->GetStaticMethodID(env, mActivityClass, "requestPermission", "(Ljava/lang/String;I)V"); - midShowToast = (*env)->GetStaticMethodID(env, mActivityClass, "showToast", "(Ljava/lang/String;IIII)I"); + midShowToast = (*env)->GetStaticMethodID(env, mActivityClass, "showToast", "(Ljava/lang/String;IIII)Z"); midSendMessage = (*env)->GetStaticMethodID(env, mActivityClass, "sendMessage", "(II)Z"); midSetActivityTitle = (*env)->GetStaticMethodID(env, mActivityClass, "setActivityTitle", "(Ljava/lang/String;)Z"); midSetCustomCursor = (*env)->GetStaticMethodID(env, mActivityClass, "setCustomCursor", "(I)Z"); @@ -960,7 +961,7 @@ bool Android_WaitLifecycleEvent(SDL_AndroidLifecycleEvent *event, Sint64 timeout { bool got_event = false; - while (!got_event && SDL_WaitSemaphoreTimeoutNS(Android_LifecycleEventSem, timeoutNS) == 0) { + while (!got_event && SDL_WaitSemaphoreTimeoutNS(Android_LifecycleEventSem, timeoutNS)) { SDL_LockMutex(Android_LifecycleMutex); { if (Android_NumLifecycleEvents > 0) { @@ -1117,26 +1118,26 @@ SDL_JAVA_AUDIO_INTERFACE(removeAudioDevice)(JNIEnv *env, jclass jcls, jboolean r } // Paddown -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)( +JNIEXPORT jboolean JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadDown)( JNIEnv *env, jclass jcls, jint device_id, jint keycode) { #ifdef SDL_JOYSTICK_ANDROID return Android_OnPadDown(device_id, keycode); #else - return -1; + return false; #endif // SDL_JOYSTICK_ANDROID } // Padup -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)( +JNIEXPORT jboolean JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativePadUp)( JNIEnv *env, jclass jcls, jint device_id, jint keycode) { #ifdef SDL_JOYSTICK_ANDROID return Android_OnPadUp(device_id, keycode); #else - return -1; + return false; #endif // SDL_JOYSTICK_ANDROID } @@ -1160,61 +1161,49 @@ JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(onNativeHat)( #endif // SDL_JOYSTICK_ANDROID } -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddJoystick)( JNIEnv *env, jclass jcls, jint device_id, jstring device_name, jstring device_desc, jint vendor_id, jint product_id, jint button_mask, jint naxes, jint axis_mask, jint nhats, jboolean can_rumble) { - int retval; #ifdef SDL_JOYSTICK_ANDROID const char *name = (*env)->GetStringUTFChars(env, device_name, NULL); const char *desc = (*env)->GetStringUTFChars(env, device_desc, NULL); - retval = Android_AddJoystick(device_id, name, desc, vendor_id, product_id, button_mask, naxes, axis_mask, nhats, can_rumble); + Android_AddJoystick(device_id, name, desc, vendor_id, product_id, button_mask, naxes, axis_mask, nhats, can_rumble); (*env)->ReleaseStringUTFChars(env, device_name, name); (*env)->ReleaseStringUTFChars(env, device_desc, desc); -#else - retval = -1; #endif // SDL_JOYSTICK_ANDROID - return retval; } -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveJoystick)( JNIEnv *env, jclass jcls, jint device_id) { #ifdef SDL_JOYSTICK_ANDROID - return Android_RemoveJoystick(device_id); -#else - return -1; + Android_RemoveJoystick(device_id); #endif // SDL_JOYSTICK_ANDROID } -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeAddHaptic)( JNIEnv *env, jclass jcls, jint device_id, jstring device_name) { - int retval; #ifdef SDL_HAPTIC_ANDROID const char *name = (*env)->GetStringUTFChars(env, device_name, NULL); - retval = Android_AddHaptic(device_id, name); + Android_AddHaptic(device_id, name); (*env)->ReleaseStringUTFChars(env, device_name, name); -#else - retval = -1; #endif // SDL_HAPTIC_ANDROID - return retval; } -JNIEXPORT jint JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)( +JNIEXPORT void JNICALL SDL_JAVA_CONTROLLER_INTERFACE(nativeRemoveHaptic)( JNIEnv *env, jclass jcls, jint device_id) { #ifdef SDL_HAPTIC_ANDROID - return Android_RemoveHaptic(device_id); -#else - return -1; + Android_RemoveHaptic(device_id); #endif } @@ -1650,7 +1639,7 @@ bool Android_JNI_ShouldMinimizeOnFocusLoss(void) bool Android_JNI_GetAccelerometerValues(float values[3]) { - bool retval = false; + bool result = false; if (bHasNewData) { int i; @@ -1658,10 +1647,10 @@ bool Android_JNI_GetAccelerometerValues(float values[3]) values[i] = fLastAccelerometer[i]; } bHasNewData = false; - retval = true; + result = true; } - return retval; + return result; } /* @@ -1789,7 +1778,7 @@ static void Internal_Android_Destroy_AssetManager(void) } } -int Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode) +bool Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode) { SDL_assert(puserdata != NULL); @@ -1810,7 +1799,7 @@ int Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mod } *puserdata = (void *)asset; - return 0; + return true; } size_t Android_JNI_FileRead(void *userdata, void *buffer, size_t size, SDL_IOStatus *status) @@ -1825,7 +1814,8 @@ size_t Android_JNI_FileRead(void *userdata, void *buffer, size_t size, SDL_IOSta size_t Android_JNI_FileWrite(void *userdata, const void *buffer, size_t size, SDL_IOStatus *status) { - return SDL_SetError("Cannot write to Android package filesystem"); + SDL_SetError("Cannot write to Android package filesystem"); + return 0; } Sint64 Android_JNI_FileSize(void *userdata) @@ -1838,19 +1828,19 @@ Sint64 Android_JNI_FileSeek(void *userdata, Sint64 offset, SDL_IOWhence whence) return (Sint64) AAsset_seek64((AAsset *)userdata, offset, (int)whence); } -int Android_JNI_FileClose(void *userdata) +SDL_bool Android_JNI_FileClose(void *userdata) { AAsset_close((AAsset *)userdata); - return 0; + return true; } -int Android_JNI_SetClipboardText(const char *text) +bool Android_JNI_SetClipboardText(const char *text) { JNIEnv *env = Android_JNI_GetEnv(); jstring string = (*env)->NewStringUTF(env, text); (*env)->CallStaticVoidMethod(env, mActivityClass, midClipboardSetText, string); (*env)->DeleteLocalRef(env, string); - return 0; + return true; } char *Android_JNI_GetClipboardText(void) @@ -2038,24 +2028,22 @@ void Android_JNI_HapticStop(int device_id) // See SDLActivity.java for constants. #define COMMAND_SET_KEEP_SCREEN_ON 5 -int SDL_SendAndroidMessage(Uint32 command, int param) +SDL_bool SDL_SendAndroidMessage(Uint32 command, int param) { - if (command >= 0x8000) { - return Android_JNI_SendMessage(command, param); + if (command < 0x8000) { + return SDL_InvalidParamError("command"); } - return -1; + return Android_JNI_SendMessage(command, param); } // sends message to be handled on the UI event dispatch thread -int Android_JNI_SendMessage(int command, int param) +bool Android_JNI_SendMessage(int command, int param) { JNIEnv *env = Android_JNI_GetEnv(); - jboolean success; - success = (*env)->CallStaticBooleanMethod(env, mActivityClass, midSendMessage, command, param); - return success ? 0 : -1; + return (*env)->CallStaticBooleanMethod(env, mActivityClass, midSendMessage, command, param); } -int Android_JNI_SuspendScreenSaver(bool suspend) +bool Android_JNI_SuspendScreenSaver(bool suspend) { return Android_JNI_SendMessage(COMMAND_SET_KEEP_SCREEN_ON, (suspend == false) ? 0 : 1); } @@ -2086,7 +2074,7 @@ bool Android_JNI_IsScreenKeyboardShown(void) return is_shown; } -int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { JNIEnv *env; jclass clazz; @@ -2176,7 +2164,7 @@ int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *bu (*env)->DeleteLocalRef(env, button_texts); (*env)->DeleteLocalRef(env, colors); - return 0; + return true; } /* @@ -2431,7 +2419,7 @@ const char *SDL_GetAndroidCachePath(void) return s_AndroidCachePath; } -int SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xOffset, int yOffset) +SDL_bool SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xOffset, int yOffset) { return Android_JNI_ShowToast(message, duration, gravity, xOffset, yOffset); } @@ -2530,7 +2518,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(nativePermissionResult)( SDL_UnlockMutex(Android_ActivityMutex); } -int SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata) +SDL_bool SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermissionCallback cb, void *userdata) { if (!permission) { return SDL_InvalidParamError("permission"); @@ -2540,13 +2528,13 @@ int SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermi NativePermissionRequestInfo *info = (NativePermissionRequestInfo *) SDL_calloc(1, sizeof (NativePermissionRequestInfo)); if (!info) { - return -1; + return false; } info->permission = SDL_strdup(permission); if (!info->permission) { SDL_free(info); - return -1; + return false; } static SDL_AtomicInt next_request_code; @@ -2565,13 +2553,13 @@ int SDL_RequestAndroidPermission(const char *permission, SDL_RequestAndroidPermi (*env)->CallStaticVoidMethod(env, mActivityClass, midRequestPermission, jpermission, info->request_code); (*env)->DeleteLocalRef(env, jpermission); - return 0; + return true; } // Show toast notification -int Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset) +bool Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset) { - int result = 0; + bool result; JNIEnv *env = Android_JNI_GetEnv(); jstring jmessage = (*env)->NewStringUTF(env, message); result = (*env)->CallStaticIntMethod(env, mActivityClass, midShowToast, jmessage, duration, gravity, xOffset, yOffset); @@ -2579,7 +2567,7 @@ int Android_JNI_ShowToast(const char *message, int duration, int gravity, int xO return result; } -int Android_JNI_GetLocale(char *buf, size_t buflen) +bool Android_JNI_GetLocale(char *buf, size_t buflen) { AConfiguration *cfg; @@ -2593,12 +2581,12 @@ int Android_JNI_GetLocale(char *buf, size_t buflen) } if (!asset_manager) { - return -1; + return false; } cfg = AConfiguration_new(); if (!cfg) { - return -1; + return false; } { @@ -2634,16 +2622,17 @@ int Android_JNI_GetLocale(char *buf, size_t buflen) AConfiguration_delete(cfg); - return 0; + return true; } -int Android_JNI_OpenURL(const char *url) +bool Android_JNI_OpenURL(const char *url) { + bool result; JNIEnv *env = Android_JNI_GetEnv(); jstring jurl = (*env)->NewStringUTF(env, url); - const int ret = (*env)->CallStaticIntMethod(env, mActivityClass, midOpenURL, jurl); + result = (*env)->CallStaticIntMethod(env, mActivityClass, midOpenURL, jurl); (*env)->DeleteLocalRef(env, jurl); - return ret; + return result; } int Android_JNI_OpenFileDescriptor(const char *uri, const char *mode) diff --git a/src/core/android/SDL_android.h b/src/core/android/SDL_android.h index 8eef801cbf..3ca03c9be9 100644 --- a/src/core/android/SDL_android.h +++ b/src/core/android/SDL_android.h @@ -80,19 +80,19 @@ extern void Android_AudioThreadInit(SDL_AudioDevice *device); extern bool Android_IsDeXMode(void); extern bool Android_IsChromebook(void); -int Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode); +bool Android_JNI_FileOpen(void **puserdata, const char *fileName, const char *mode); Sint64 Android_JNI_FileSize(void *userdata); Sint64 Android_JNI_FileSeek(void *userdata, Sint64 offset, SDL_IOWhence whence); size_t Android_JNI_FileRead(void *userdata, void *buffer, size_t size, SDL_IOStatus *status); size_t Android_JNI_FileWrite(void *userdata, const void *buffer, size_t size, SDL_IOStatus *status); -int Android_JNI_FileClose(void *userdata); +SDL_bool Android_JNI_FileClose(void *userdata); // Environment support void Android_JNI_GetManifestEnvironmentVariables(void); int Android_JNI_OpenFileDescriptor(const char *uri, const char *mode); // Clipboard support -int Android_JNI_SetClipboardText(const char *text); +bool Android_JNI_SetClipboardText(const char *text); char *Android_JNI_GetClipboardText(void); bool Android_JNI_HasClipboardText(void); @@ -109,7 +109,7 @@ void Android_JNI_HapticRumble(int device_id, float low_frequency_intensity, floa void Android_JNI_HapticStop(int device_id); // Video -int Android_JNI_SuspendScreenSaver(bool suspend); +bool Android_JNI_SuspendScreenSaver(bool suspend); // Touch support void Android_JNI_InitTouch(void); @@ -117,16 +117,16 @@ void Android_JNI_InitTouch(void); // Threads #include JNIEnv *Android_JNI_GetEnv(void); -int Android_JNI_SetupThread(void); +bool Android_JNI_SetupThread(void); // Locale -int Android_JNI_GetLocale(char *buf, size_t buflen); +bool Android_JNI_GetLocale(char *buf, size_t buflen); // Generic messages -int Android_JNI_SendMessage(int command, int param); +bool Android_JNI_SendMessage(int command, int param); // MessageBox -int Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +bool Android_JNI_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); // Cursor support int Android_JNI_CreateCustomCursor(SDL_Surface *surface, int hot_x, int hot_y); @@ -139,9 +139,9 @@ bool Android_JNI_SupportsRelativeMouse(void); bool Android_JNI_SetRelativeMouseEnabled(bool enabled); // Show toast notification -int Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset); +bool Android_JNI_ShowToast(const char *message, int duration, int gravity, int xOffset, int yOffset); -int Android_JNI_OpenURL(const char *url); +bool Android_JNI_OpenURL(const char *url); int SDL_GetAndroidSDKVersion(void); diff --git a/src/core/freebsd/SDL_evdev_kbd_freebsd.c b/src/core/freebsd/SDL_evdev_kbd_freebsd.c index faa7f70c1b..a421d8b15c 100644 --- a/src/core/freebsd/SDL_evdev_kbd_freebsd.c +++ b/src/core/freebsd/SDL_evdev_kbd_freebsd.c @@ -65,7 +65,7 @@ struct SDL_EVDEV_keyboard_state unsigned int text_len; }; -static int SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd) +static bool SDL_EVDEV_kbd_load_keymaps(SDL_EVDEV_keyboard_state *kbd) { return ioctl(kbd->keyboard_fd, GIO_KEYMAP, kbd->key_map) >= 0; } @@ -408,7 +408,7 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch) return ch; } -static int vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) +static bool vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { return (kbd->ledflagstate & flag) != 0; } diff --git a/src/core/gdk/SDL_gdk.cpp b/src/core/gdk/SDL_gdk.cpp index 354d052d5d..2cde67b66e 100644 --- a/src/core/gdk/SDL_gdk.cpp +++ b/src/core/gdk/SDL_gdk.cpp @@ -35,7 +35,7 @@ PAPPCONSTRAIN_REGISTRATION hCPLM = {}; HANDLE plmSuspendComplete = nullptr; extern "C" -int SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue) +SDL_bool SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue) { // If this is the first call, first create the global task queue. if (!GDK_GlobalTaskQueue) { @@ -57,7 +57,7 @@ int SDL_GetGDKTaskQueue(XTaskQueueHandle *outTaskQueue) } } - return 0; + return true; } extern "C" @@ -74,13 +74,12 @@ void GDK_DispatchTaskQueue(void) } extern "C" -int GDK_RegisterChangeNotifications(void) +bool GDK_RegisterChangeNotifications(void) { // Register suspend/resume handling plmSuspendComplete = CreateEventEx(nullptr, nullptr, 0, EVENT_MODIFY_STATE | SYNCHRONIZE); if (!plmSuspendComplete) { - SDL_SetError("[GDK] Unable to create plmSuspendComplete event"); - return -1; + return SDL_SetError("[GDK] Unable to create plmSuspendComplete event"); } auto rascn = [](BOOLEAN quiesced, PVOID context) { SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "[GDK] in RegisterAppStateChangeNotification handler"); @@ -98,8 +97,7 @@ int GDK_RegisterChangeNotifications(void) } }; if (RegisterAppStateChangeNotification(rascn, NULL, &hPLM)) { - SDL_SetError("[GDK] Unable to call RegisterAppStateChangeNotification"); - return -1; + return SDL_SetError("[GDK] Unable to call RegisterAppStateChangeNotification"); } // Register constrain/unconstrain handling @@ -115,11 +113,10 @@ int GDK_RegisterChangeNotifications(void) } }; if (RegisterAppConstrainedChangeNotification(raccn, NULL, &hCPLM)) { - SDL_SetError("[GDK] Unable to call RegisterAppConstrainedChangeNotification"); - return -1; + return SDL_SetError("[GDK] Unable to call RegisterAppConstrainedChangeNotification"); } - return 0; + return true; } extern "C" @@ -142,7 +139,7 @@ void SDL_GDKSuspendComplete() } extern "C" -int SDL_GetGDKDefaultUser(XUserHandle *outUserHandle) +SDL_bool SDL_GetGDKDefaultUser(XUserHandle *outUserHandle) { XAsyncBlock block = { 0 }; HRESULT result; @@ -158,5 +155,5 @@ int SDL_GetGDKDefaultUser(XUserHandle *outUserHandle) return WIN_SetErrorFromHRESULT("XUserAddResult", result); } - return 0; + return true; } diff --git a/src/core/gdk/SDL_gdk.h b/src/core/gdk/SDL_gdk.h index f5e814e87d..db2affa333 100644 --- a/src/core/gdk/SDL_gdk.h +++ b/src/core/gdk/SDL_gdk.h @@ -23,6 +23,5 @@ // This is called from WIN_PumpEvents on GDK extern void GDK_DispatchTaskQueue(void); -extern int GDK_RegisterChangeNotifications(void); - +extern bool GDK_RegisterChangeNotifications(void); extern void GDK_UnregisterChangeNotifications(void); diff --git a/src/core/haiku/SDL_BeApp.cc b/src/core/haiku/SDL_BeApp.cc index 5e914e253b..39612b8c53 100644 --- a/src/core/haiku/SDL_BeApp.cc +++ b/src/core/haiku/SDL_BeApp.cc @@ -104,7 +104,7 @@ static int StartBeApp(void *unused) } -static int StartBeLooper() +static bool StartBeLooper() { if (!be_app) { SDL_AppThread = SDL_CreateThread(StartBeApp, "SDLApplication", NULL); @@ -119,16 +119,18 @@ static int StartBeLooper() SDL_Looper = new SDL_BLooper("SDLLooper"); SDL_Looper->Run(); - return (0); + return true; } // Initialize the Be Application, if it's not already started -int SDL_InitBeApp(void) +bool SDL_InitBeApp(void) { // Create the BApplication that handles appserver interaction if (SDL_BeAppActive <= 0) { - StartBeLooper(); + if (!StartBeLooper()) { + return false; + } // Mark the application active SDL_BeAppActive = 0; @@ -138,7 +140,7 @@ int SDL_InitBeApp(void) ++SDL_BeAppActive; // The app is running, and we're ready to go - return 0; + return true; } // Quit the Be Application, if there's nothing left to do diff --git a/src/core/haiku/SDL_BeApp.h b/src/core/haiku/SDL_BeApp.h index 405900b608..b45e10eab0 100644 --- a/src/core/haiku/SDL_BeApp.h +++ b/src/core/haiku/SDL_BeApp.h @@ -26,7 +26,7 @@ extern "C" { // Handle the BeApp specific portions of the application // Initialize the Be Application, if it's not already started -extern int SDL_InitBeApp(void); +extern bool SDL_InitBeApp(void); // Quit the Be Application, if there's nothing left to do extern void SDL_QuitBeApp(void); diff --git a/src/core/linux/SDL_dbus.c b/src/core/linux/SDL_dbus.c index 3969471b00..01032334a3 100644 --- a/src/core/linux/SDL_dbus.c +++ b/src/core/linux/SDL_dbus.c @@ -31,14 +31,14 @@ static char *inhibit_handle = NULL; static unsigned int screensaver_cookie = 0; static SDL_DBusContext dbus; -static int LoadDBUSSyms(void) +static bool LoadDBUSSyms(void) { #define SDL_DBUS_SYM2_OPTIONAL(TYPE, x, y) \ dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y) #define SDL_DBUS_SYM2(TYPE, x, y) \ if (!(dbus.x = (TYPE)SDL_LoadFunction(dbus_handle, #y))) \ - return -1 + return false #define SDL_DBUS_SYM_OPTIONAL(TYPE, x) \ SDL_DBUS_SYM2_OPTIONAL(TYPE, x, dbus_##x) @@ -93,7 +93,7 @@ static int LoadDBUSSyms(void) #undef SDL_DBUS_SYM #undef SDL_DBUS_SYM2 - return 0; + return true; } static void UnloadDBUSLibrary(void) @@ -104,23 +104,22 @@ static void UnloadDBUSLibrary(void) } } -static int LoadDBUSLibrary(void) +static bool LoadDBUSLibrary(void) { - int retval = 0; + bool result = true; if (!dbus_handle) { dbus_handle = SDL_LoadObject(dbus_library); if (!dbus_handle) { - retval = -1; + result = false; // Don't call SDL_SetError(): SDL_LoadObject already did. } else { - retval = LoadDBUSSyms(); - if (retval < 0) { + result = LoadDBUSSyms(); + if (!result) { UnloadDBUSLibrary(); } } } - - return retval; + return result; } static SDL_SpinLock spinlock_dbus_init = 0; @@ -136,7 +135,7 @@ static void SDL_DBus_Init_Spinlocked(void) if (!dbus.session_conn) { DBusError err; - if (LoadDBUSLibrary() == -1) { + if (!LoadDBUSLibrary()) { is_dbus_available = false; // can't load at all? Don't keep trying. return; } @@ -209,7 +208,7 @@ SDL_DBusContext *SDL_DBus_GetContext(void) static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap) { - bool retval = false; + bool result = false; if (conn) { DBusMessage *msg = dbus.message_new_method_call(node, path, interface, method); @@ -237,7 +236,7 @@ static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, } firstarg = va_arg(ap_reply, int); if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_get_args_valist(reply, NULL, firstarg, ap_reply)) { - retval = true; + result = true; } dbus.message_unref(reply); } @@ -247,32 +246,32 @@ static bool SDL_DBus_CallMethodInternal(DBusConnection *conn, const char *node, } } - return retval; + return result; } bool SDL_DBus_CallMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...) { - bool retval; + bool result; va_list ap; va_start(ap, method); - retval = SDL_DBus_CallMethodInternal(conn, node, path, interface, method, ap); + result = SDL_DBus_CallMethodInternal(conn, node, path, interface, method, ap); va_end(ap); - return retval; + return result; } bool SDL_DBus_CallMethod(const char *node, const char *path, const char *interface, const char *method, ...) { - bool retval; + bool result; va_list ap; va_start(ap, method); - retval = SDL_DBus_CallMethodInternal(dbus.session_conn, node, path, interface, method, ap); + result = SDL_DBus_CallMethodInternal(dbus.session_conn, node, path, interface, method, ap); va_end(ap); - return retval; + return result; } static bool SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, va_list ap) { - bool retval = false; + bool result = false; if (conn) { DBusMessage *msg = dbus.message_new_method_call(node, path, interface, method); @@ -281,7 +280,7 @@ static bool SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *no if ((firstarg == DBUS_TYPE_INVALID) || dbus.message_append_args_valist(msg, firstarg, ap)) { if (dbus.connection_send(conn, msg, NULL)) { dbus.connection_flush(conn); - retval = true; + result = true; } } @@ -289,7 +288,7 @@ static bool SDL_DBus_CallVoidMethodInternal(DBusConnection *conn, const char *no } } - return retval; + return result; } static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg, const int expectedtype, void *result) @@ -319,22 +318,22 @@ static bool SDL_DBus_CallWithBasicReply(DBusConnection *conn, DBusMessage *msg, bool SDL_DBus_CallVoidMethodOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *method, ...) { - bool retval; + bool result; va_list ap; va_start(ap, method); - retval = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap); + result = SDL_DBus_CallVoidMethodInternal(conn, node, path, interface, method, ap); va_end(ap); - return retval; + return result; } bool SDL_DBus_CallVoidMethod(const char *node, const char *path, const char *interface, const char *method, ...) { - bool retval; + bool result; va_list ap; va_start(ap, method); - retval = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap); + result = SDL_DBus_CallVoidMethodInternal(dbus.session_conn, node, path, interface, method, ap); va_end(ap); - return retval; + return result; } bool SDL_DBus_QueryPropertyOnConnection(DBusConnection *conn, const char *node, const char *path, const char *interface, const char *property, const int expectedtype, void *result) @@ -449,7 +448,7 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit) if (inhibit) { DBusMessage *msg; - bool retval = false; + bool result = false; const char *key = "reason"; const char *reply = NULL; const char *reason = SDL_GetHint(SDL_HINT_SCREENSAVER_INHIBIT_ACTIVITY_NAME); @@ -477,11 +476,11 @@ bool SDL_DBus_ScreensaverInhibit(bool inhibit) if (SDL_DBus_CallWithBasicReply(dbus.session_conn, msg, DBUS_TYPE_OBJECT_PATH, &reply)) { inhibit_handle = SDL_strdup(reply); - retval = true; + result = true; } dbus.message_unref(msg); - return retval; + return result; } else { if (!SDL_DBus_CallVoidMethod(bus_name, inhibit_handle, "org.freedesktop.portal.Request", "Close", DBUS_TYPE_INVALID)) { return false; diff --git a/src/core/linux/SDL_evdev.c b/src/core/linux/SDL_evdev.c index b9808bed5f..758377d4fe 100644 --- a/src/core/linux/SDL_evdev.c +++ b/src/core/linux/SDL_evdev.c @@ -132,9 +132,8 @@ static SDL_EVDEV_PrivateData *_this = NULL; static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode); static void SDL_EVDEV_sync_device(SDL_evdevlist_item *item); -static int SDL_EVDEV_device_removed(const char *dev_path); - -static int SDL_EVDEV_device_added(const char *dev_path, int udev_class); +static bool SDL_EVDEV_device_removed(const char *dev_path); +static bool SDL_EVDEV_device_added(const char *dev_path, int udev_class); #ifdef SDL_USE_LIBUDEV static void SDL_EVDEV_udev_callback(SDL_UDEV_deviceevent udev_event, int udev_class, const char *dev_path); #endif // SDL_USE_LIBUDEV @@ -150,10 +149,10 @@ static Uint8 EVDEV_MouseButtons[] = { SDL_BUTTON_X2 + 3 // BTN_TASK 0x117 }; -static int SDL_EVDEV_SetRelativeMouseMode(bool enabled) +static bool SDL_EVDEV_SetRelativeMouseMode(bool enabled) { // Mice already send relative events through this interface - return 0; + return true; } static void SDL_EVDEV_UpdateKeyboardMute(void) @@ -165,27 +164,27 @@ static void SDL_EVDEV_UpdateKeyboardMute(void) } } -int SDL_EVDEV_Init(void) +SDL_bool SDL_EVDEV_Init(void) { if (!_this) { _this = (SDL_EVDEV_PrivateData *)SDL_calloc(1, sizeof(*_this)); if (!_this) { - return -1; + return false; } #ifdef SDL_USE_LIBUDEV - if (SDL_UDEV_Init() < 0) { + if (!SDL_UDEV_Init()) { SDL_free(_this); _this = NULL; - return -1; + return false; } // Set up the udev callback - if (SDL_UDEV_AddCallback(SDL_EVDEV_udev_callback) < 0) { + if (!SDL_UDEV_AddCallback(SDL_EVDEV_udev_callback)) { SDL_UDEV_Quit(); SDL_free(_this); _this = NULL; - return -1; + return false; } // Force a scan to build the initial device list @@ -226,7 +225,7 @@ int SDL_EVDEV_Init(void) _this->ref_count += 1; - return 0; + return true; } void SDL_EVDEV_Quit(void) @@ -603,7 +602,7 @@ static SDL_Scancode SDL_EVDEV_translate_keycode(int keycode) return scancode; } -static int SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class) +static bool SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class) { char name[128]; @@ -612,7 +611,7 @@ static int SDL_EVDEV_init_keyboard(SDL_evdevlist_item *item, int udev_class) SDL_AddKeyboard((SDL_KeyboardID)item->fd, name, true); - return 0; + return true; } static void SDL_EVDEV_destroy_keyboard(SDL_evdevlist_item *item) @@ -620,7 +619,7 @@ static void SDL_EVDEV_destroy_keyboard(SDL_evdevlist_item *item) SDL_RemoveKeyboard((SDL_KeyboardID)item->fd, true); } -static int SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class) +static bool SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class) { char name[128]; int ret; @@ -634,7 +633,7 @@ static int SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class) ret = ioctl(item->fd, EVIOCGABS(ABS_X), &abs_info); if (ret < 0) { // no absolute mode info, continue - return 0; + return true; } item->min_x = abs_info.minimum; item->max_x = abs_info.maximum; @@ -643,13 +642,13 @@ static int SDL_EVDEV_init_mouse(SDL_evdevlist_item *item, int udev_class) ret = ioctl(item->fd, EVIOCGABS(ABS_Y), &abs_info); if (ret < 0) { // no absolute mode info, continue - return 0; + return true; } item->min_y = abs_info.minimum; item->max_y = abs_info.maximum; item->range_y = abs_info.maximum - abs_info.minimum; - return 0; + return true; } static void SDL_EVDEV_destroy_mouse(SDL_evdevlist_item *item) @@ -657,7 +656,7 @@ static void SDL_EVDEV_destroy_mouse(SDL_evdevlist_item *item) SDL_RemoveMouse((SDL_MouseID)item->fd, true); } -static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) +static bool SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) { int ret; unsigned long xreq, yreq; @@ -665,12 +664,12 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) struct input_absinfo abs_info; if (!item->is_touchscreen) { - return 0; + return true; } item->touchscreen_data = SDL_calloc(1, sizeof(*item->touchscreen_data)); if (!item->touchscreen_data) { - return -1; + return false; } ret = ioctl(item->fd, EVIOCGNAME(sizeof(name)), name); @@ -682,7 +681,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) item->touchscreen_data->name = SDL_strdup(name); if (!item->touchscreen_data->name) { SDL_free(item->touchscreen_data); - return -1; + return false; } ret = ioctl(item->fd, EVIOCGABS(ABS_MT_SLOT), &abs_info); @@ -738,7 +737,7 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) if (!item->touchscreen_data->slots) { SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); - return -1; + return false; } ret = SDL_AddTouch(item->fd, // I guess our fd is unique enough @@ -748,10 +747,10 @@ static int SDL_EVDEV_init_touchscreen(SDL_evdevlist_item *item, int udev_class) SDL_free(item->touchscreen_data->slots); SDL_free(item->touchscreen_data->name); SDL_free(item->touchscreen_data); - return ret; + return false; } - return 0; + return true; } static void SDL_EVDEV_destroy_touchscreen(SDL_evdevlist_item *item) @@ -891,7 +890,7 @@ static void SDL_EVDEV_sync_device(SDL_evdevlist_item *item) #endif // EVIOCGMTSLOTS } -static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) +static bool SDL_EVDEV_device_added(const char *dev_path, int udev_class) { SDL_evdevlist_item *item; unsigned long relbit[NBITS(REL_MAX)] = { 0 }; @@ -899,13 +898,13 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) // Check to make sure it's not already in list. for (item = _this->first; item; item = item->next) { if (SDL_strcmp(dev_path, item->path) == 0) { - return -1; // already have this one + return false; // already have this one } } item = (SDL_evdevlist_item *)SDL_calloc(1, sizeof(SDL_evdevlist_item)); if (!item) { - return -1; + return false; } item->fd = open(dev_path, O_RDONLY | O_NONBLOCK | O_CLOEXEC); @@ -918,7 +917,7 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) if (!item->path) { close(item->fd); SDL_free(item); - return -1; + return false; } item->udev_class = udev_class; @@ -931,30 +930,26 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) // For now, we just treat a touchpad like a touchscreen if (udev_class & (SDL_UDEV_DEVICE_TOUCHSCREEN | SDL_UDEV_DEVICE_TOUCHPAD)) { - int ret; item->is_touchscreen = true; - ret = SDL_EVDEV_init_touchscreen(item, udev_class); - if (ret < 0) { + if (!SDL_EVDEV_init_touchscreen(item, udev_class)) { close(item->fd); SDL_free(item->path); SDL_free(item); - return ret; + return false; } } else if (udev_class & SDL_UDEV_DEVICE_MOUSE) { - int ret = SDL_EVDEV_init_mouse(item, udev_class); - if (ret < 0) { + if (!SDL_EVDEV_init_mouse(item, udev_class)) { close(item->fd); SDL_free(item->path); SDL_free(item); - return ret; + return false; } } else if (udev_class & SDL_UDEV_DEVICE_KEYBOARD) { - int ret = SDL_EVDEV_init_keyboard(item, udev_class); - if (ret < 0) { + if (!SDL_EVDEV_init_keyboard(item, udev_class)) { close(item->fd); SDL_free(item->path); SDL_free(item); - return ret; + return false; } } @@ -969,10 +964,11 @@ static int SDL_EVDEV_device_added(const char *dev_path, int udev_class) SDL_EVDEV_UpdateKeyboardMute(); - return _this->num_devices++; + ++_this->num_devices; + return true; } -static int SDL_EVDEV_device_removed(const char *dev_path) +static bool SDL_EVDEV_device_removed(const char *dev_path) { SDL_evdevlist_item *item; SDL_evdevlist_item *prev = NULL; @@ -1001,12 +997,12 @@ static int SDL_EVDEV_device_removed(const char *dev_path) SDL_free(item); SDL_EVDEV_UpdateKeyboardMute(); _this->num_devices--; - return 0; + return true; } prev = item; } - return -1; + return false; } Uint64 SDL_EVDEV_GetEventTimestamp(struct input_event *event) diff --git a/src/core/linux/SDL_evdev.h b/src/core/linux/SDL_evdev.h index 6a4be50719..3b4e3844a3 100644 --- a/src/core/linux/SDL_evdev.h +++ b/src/core/linux/SDL_evdev.h @@ -28,7 +28,7 @@ struct input_event; -extern int SDL_EVDEV_Init(void); +extern SDL_bool SDL_EVDEV_Init(void); extern void SDL_EVDEV_Quit(void); extern void SDL_EVDEV_SetVTSwitchCallbacks(void (*release_callback)(void*), void *release_callback_data, void (*acquire_callback)(void*), void *acquire_callback_data); diff --git a/src/core/linux/SDL_evdev_kbd.c b/src/core/linux/SDL_evdev_kbd.c index f6629f8cff..5ab45afff3 100644 --- a/src/core/linux/SDL_evdev_kbd.c +++ b/src/core/linux/SDL_evdev_kbd.c @@ -378,7 +378,7 @@ static void kbd_vt_quit(int console_fd) ioctl(console_fd, VT_SETMODE, &mode); } -static int kbd_vt_init(int console_fd) +static bool kbd_vt_init(int console_fd) { struct vt_mode mode; @@ -386,7 +386,7 @@ static int kbd_vt_init(int console_fd) vt_acquire_signal = find_free_signal(kbd_vt_acquire_signal_action); if (!vt_release_signal || !vt_acquire_signal ) { kbd_vt_quit(console_fd); - return -1; + return false; } SDL_zero(mode); @@ -396,9 +396,9 @@ static int kbd_vt_init(int console_fd) mode.frsig = SIGIO; if (ioctl(console_fd, VT_SETMODE, &mode) < 0) { kbd_vt_quit(console_fd); - return -1; + return false; } - return 0; + return true; } static void kbd_vt_update(SDL_EVDEV_keyboard_state *state) @@ -618,7 +618,7 @@ static unsigned int handle_diacr(SDL_EVDEV_keyboard_state *kbd, unsigned int ch) return ch; } -static int vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) +static bool vc_kbd_led(SDL_EVDEV_keyboard_state *kbd, int flag) { return (kbd->ledflagstate & flag) != 0; } diff --git a/src/core/linux/SDL_fcitx.c b/src/core/linux/SDL_fcitx.c index 91f46353c5..1ab49e38d0 100644 --- a/src/core/linux/SDL_fcitx.c +++ b/src/core/linux/SDL_fcitx.c @@ -252,7 +252,7 @@ static void SDLCALL Fcitx_SetCapabilities(void *data, static bool FcitxCreateInputContext(SDL_DBusContext *dbus, const char *appname, char **ic_path) { const char *program = "program"; - bool retval = false; + bool result = false; if (dbus && dbus->session_conn) { DBusMessage *msg = dbus->message_new_method_call(FCITX_DBUS_SERVICE, FCITX_IM_DBUS_PATH, FCITX_IM_DBUS_INTERFACE, "CreateInputContext"); @@ -269,14 +269,14 @@ static bool FcitxCreateInputContext(SDL_DBusContext *dbus, const char *appname, reply = dbus->connection_send_with_reply_and_block(dbus->session_conn, msg, 300, NULL); if (reply) { if (dbus->message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, ic_path, DBUS_TYPE_INVALID)) { - retval = true; + result = true; } dbus->message_unref(reply); } dbus->message_unref(msg); } } - return retval; + return result; } static bool FcitxClientCreateIC(FcitxClient *client) diff --git a/src/core/linux/SDL_threadprio.c b/src/core/linux/SDL_threadprio.c index 03a928877f..0a63b3b085 100644 --- a/src/core/linux/SDL_threadprio.c +++ b/src/core/linux/SDL_threadprio.c @@ -249,13 +249,13 @@ static bool rtkit_setpriority_realtime(pid_t thread, int rt_priority) #endif // threads // this is a public symbol, so it has to exist even if threads are disabled. -int SDL_SetLinuxThreadPriority(Sint64 threadID, int priority) +SDL_bool SDL_SetLinuxThreadPriority(Sint64 threadID, int priority) { #ifdef SDL_THREADS_DISABLED return SDL_Unsupported(); #else if (setpriority(PRIO_PROCESS, (id_t)threadID, priority) == 0) { - return 0; + return true; } #ifdef SDL_USE_LIBDBUS @@ -272,7 +272,7 @@ int SDL_SetLinuxThreadPriority(Sint64 threadID, int priority) README and sample code at: http://git.0pointer.net/rtkit.git */ if (rtkit_setpriority_nice((pid_t)threadID, priority)) { - return 0; + return true; } #endif @@ -281,7 +281,7 @@ int SDL_SetLinuxThreadPriority(Sint64 threadID, int priority) } // this is a public symbol, so it has to exist even if threads are disabled. -int SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy) +SDL_bool SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy) { #ifdef SDL_THREADS_DISABLED return SDL_Unsupported(); @@ -310,7 +310,7 @@ int SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int sc } if (setpriority(PRIO_PROCESS, (id_t)threadID, osPriority) == 0) { - return 0; + return true; } } @@ -329,11 +329,11 @@ int SDL_SetLinuxThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int sc */ if (schedPolicy == SCHED_RR || schedPolicy == SCHED_FIFO) { if (rtkit_setpriority_realtime((pid_t)threadID, osPriority)) { - return 0; + return true; } } else { if (rtkit_setpriority_nice((pid_t)threadID, osPriority)) { - return 0; + return true; } } #endif diff --git a/src/core/linux/SDL_udev.c b/src/core/linux/SDL_udev.c index 62f49a4e09..ada5a26b74 100644 --- a/src/core/linux/SDL_udev.c +++ b/src/core/linux/SDL_udev.c @@ -41,7 +41,7 @@ static const char *SDL_UDEV_LIBS[] = { "libudev.so.1", "libudev.so.0" }; static SDL_UDEV_PrivateData *_this = NULL; static bool SDL_UDEV_load_sym(const char *fn, void **addr); -static int SDL_UDEV_load_syms(void); +static bool SDL_UDEV_load_syms(void); static bool SDL_UDEV_hotplug_update_available(void); static void get_caps(struct udev_device *dev, struct udev_device *pdev, const char *attr, unsigned long *bitmask, size_t bitmask_len); static int guess_device_class(struct udev_device *dev); @@ -59,12 +59,12 @@ static bool SDL_UDEV_load_sym(const char *fn, void **addr) return true; } -static int SDL_UDEV_load_syms(void) +static bool SDL_UDEV_load_syms(void) { /* cast funcs to char* first, to please GCC's strict aliasing rules. */ #define SDL_UDEV_SYM(x) \ if (!SDL_UDEV_load_sym(#x, (void **)(char *)&_this->syms.x)) \ - return -1 + return false SDL_UDEV_SYM(udev_device_get_action); SDL_UDEV_SYM(udev_device_get_devnode); @@ -95,7 +95,7 @@ static int SDL_UDEV_load_syms(void) SDL_UDEV_SYM(udev_device_get_devnum); #undef SDL_UDEV_SYM - return 0; + return true; } static bool SDL_UDEV_hotplug_update_available(void) @@ -109,20 +109,17 @@ static bool SDL_UDEV_hotplug_update_available(void) return false; } -int SDL_UDEV_Init(void) +bool SDL_UDEV_Init(void) { - int retval = 0; - if (!_this) { _this = (SDL_UDEV_PrivateData *)SDL_calloc(1, sizeof(*_this)); if (!_this) { - return -1; + return false; } - retval = SDL_UDEV_LoadLibrary(); - if (retval < 0) { + if (!SDL_UDEV_LoadLibrary()) { SDL_UDEV_Quit(); - return retval; + return false; } /* Set up udev monitoring @@ -152,7 +149,7 @@ int SDL_UDEV_Init(void) _this->ref_count += 1; - return retval; + return true; } void SDL_UDEV_Quit(void) @@ -187,14 +184,14 @@ void SDL_UDEV_Quit(void) } } -int SDL_UDEV_Scan(void) +bool SDL_UDEV_Scan(void) { struct udev_enumerate *enumerate = NULL; struct udev_list_entry *devs = NULL; struct udev_list_entry *item = NULL; if (!_this) { - return 0; + return true; } enumerate = _this->syms.udev_enumerate_new(_this->udev); @@ -219,7 +216,7 @@ int SDL_UDEV_Scan(void) } _this->syms.udev_enumerate_unref(enumerate); - return 0; + return true; } bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version, int *class) @@ -291,17 +288,17 @@ void SDL_UDEV_UnloadLibrary(void) } } -int SDL_UDEV_LoadLibrary(void) +bool SDL_UDEV_LoadLibrary(void) { - int retval = 0, i; + bool result = true; if (!_this) { return SDL_SetError("UDEV not initialized"); } // See if there is a udev library already loaded - if (SDL_UDEV_load_syms() == 0) { - return 0; + if (SDL_UDEV_load_syms()) { + return true; } #ifdef SDL_UDEV_DYNAMIC @@ -309,8 +306,8 @@ int SDL_UDEV_LoadLibrary(void) if (!_this->udev_handle) { _this->udev_handle = SDL_LoadObject(SDL_UDEV_DYNAMIC); if (_this->udev_handle) { - retval = SDL_UDEV_load_syms(); - if (retval < 0) { + result = SDL_UDEV_load_syms(); + if (!result) { SDL_UDEV_UnloadLibrary(); } } @@ -318,11 +315,11 @@ int SDL_UDEV_LoadLibrary(void) #endif if (!_this->udev_handle) { - for (i = 0; i < SDL_arraysize(SDL_UDEV_LIBS); i++) { + for (int i = 0; i < SDL_arraysize(SDL_UDEV_LIBS); i++) { _this->udev_handle = SDL_LoadObject(SDL_UDEV_LIBS[i]); if (_this->udev_handle) { - retval = SDL_UDEV_load_syms(); - if (retval < 0) { + result = SDL_UDEV_load_syms(); + if (!result) { SDL_UDEV_UnloadLibrary(); } else { break; @@ -331,12 +328,12 @@ int SDL_UDEV_LoadLibrary(void) } if (!_this->udev_handle) { - retval = -1; + result = false; // Don't call SDL_SetError(): SDL_LoadObject already did. } } - return retval; + return result; } static void get_caps(struct udev_device *dev, struct udev_device *pdev, const char *attr, unsigned long *bitmask, size_t bitmask_len) @@ -529,12 +526,12 @@ void SDL_UDEV_Poll(void) } } -int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb) +bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb) { SDL_UDEV_CallbackList *item; item = (SDL_UDEV_CallbackList *)SDL_calloc(1, sizeof(SDL_UDEV_CallbackList)); if (!item) { - return -1; + return false; } item->callback = cb; @@ -546,7 +543,7 @@ int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb) _this->last = item; } - return 0; + return true; } void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb) @@ -579,7 +576,7 @@ void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb) const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void) { - if (SDL_UDEV_Init() < 0) { + if (!SDL_UDEV_Init()) { SDL_SetError("Could not initialize UDEV"); return NULL; } diff --git a/src/core/linux/SDL_udev.h b/src/core/linux/SDL_udev.h index c58e57bb2d..d501b385ed 100644 --- a/src/core/linux/SDL_udev.h +++ b/src/core/linux/SDL_udev.h @@ -96,14 +96,14 @@ typedef struct SDL_UDEV_PrivateData SDL_UDEV_Symbols syms; } SDL_UDEV_PrivateData; -extern int SDL_UDEV_Init(void); +extern bool SDL_UDEV_Init(void); extern void SDL_UDEV_Quit(void); extern void SDL_UDEV_UnloadLibrary(void); -extern int SDL_UDEV_LoadLibrary(void); +extern bool SDL_UDEV_LoadLibrary(void); extern void SDL_UDEV_Poll(void); -extern int SDL_UDEV_Scan(void); +extern bool SDL_UDEV_Scan(void); extern bool SDL_UDEV_GetProductInfo(const char *device_path, Uint16 *vendor, Uint16 *product, Uint16 *version, int *class); -extern int SDL_UDEV_AddCallback(SDL_UDEV_Callback cb); +extern bool SDL_UDEV_AddCallback(SDL_UDEV_Callback cb); extern void SDL_UDEV_DelCallback(SDL_UDEV_Callback cb); extern const SDL_UDEV_Symbols *SDL_UDEV_GetUdevSyms(void); extern void SDL_UDEV_ReleaseUdevSyms(void); diff --git a/src/core/windows/SDL_hid.c b/src/core/windows/SDL_hid.c index a427aba86e..2758b633f3 100644 --- a/src/core/windows/SDL_hid.c +++ b/src/core/windows/SDL_hid.c @@ -36,17 +36,17 @@ static HMODULE s_pHIDDLL = 0; static int s_HIDDLLRefCount = 0; -int WIN_LoadHIDDLL(void) +bool WIN_LoadHIDDLL(void) { if (s_pHIDDLL) { SDL_assert(s_HIDDLLRefCount > 0); s_HIDDLLRefCount++; - return 0; // already loaded + return true; // already loaded } s_pHIDDLL = LoadLibrary(TEXT("hid.dll")); if (!s_pHIDDLL) { - return -1; + return false; } SDL_assert(s_HIDDLLRefCount == 0); @@ -63,10 +63,10 @@ int WIN_LoadHIDDLL(void) !SDL_HidP_GetCaps || !SDL_HidP_GetButtonCaps || !SDL_HidP_GetValueCaps || !SDL_HidP_MaxDataListLength || !SDL_HidP_GetData) { WIN_UnloadHIDDLL(); - return -1; + return false; } - return 0; + return true; } void WIN_UnloadHIDDLL(void) diff --git a/src/core/windows/SDL_hid.h b/src/core/windows/SDL_hid.h index 01cca0a593..afa00717bb 100644 --- a/src/core/windows/SDL_hid.h +++ b/src/core/windows/SDL_hid.h @@ -190,7 +190,7 @@ typedef struct #define HIDP_STATUS_REPORT_DOES_NOT_EXIST HIDP_ERROR_CODES(0xC, 0x0010) #define HIDP_STATUS_NOT_IMPLEMENTED HIDP_ERROR_CODES(0xC, 0x0020) -extern int WIN_LoadHIDDLL(void); +extern bool WIN_LoadHIDDLL(void); extern void WIN_UnloadHIDDLL(void); typedef BOOLEAN (WINAPI *HidD_GetString_t)(HANDLE HidDeviceObject, PVOID Buffer, ULONG BufferLength); diff --git a/src/core/windows/SDL_immdevice.c b/src/core/windows/SDL_immdevice.c index 554355438d..54f12946f8 100644 --- a/src/core/windows/SDL_immdevice.c +++ b/src/core/windows/SDL_immdevice.c @@ -207,12 +207,12 @@ static ULONG STDMETHODCALLTYPE SDLMMNotificationClient_Release(IMMNotificationCl { // client is a static object; we don't ever free it. SDLMMNotificationClient *client = (SDLMMNotificationClient *)iclient; - const ULONG retval = SDL_AtomicDecRef(&client->refcount); - if (retval == 0) { + const ULONG rc = SDL_AtomicDecRef(&client->refcount); + if (rc == 0) { SDL_AtomicSet(&client->refcount, 0); // uhh... return 0; } - return retval - 1; + return rc - 1; } // These are the entry points called when WASAPI device endpoints change. @@ -288,7 +288,7 @@ static const IMMNotificationClientVtbl notification_client_vtbl = { static SDLMMNotificationClient notification_client = { ¬ification_client_vtbl, { 1 } }; -int SDL_IMMDevice_Init(const SDL_IMMDevice_callbacks *callbacks) +bool SDL_IMMDevice_Init(const SDL_IMMDevice_callbacks *callbacks) { HRESULT ret; @@ -320,7 +320,7 @@ int SDL_IMMDevice_Init(const SDL_IMMDevice_callbacks *callbacks) immcallbacks.default_audio_device_changed = SDL_DefaultAudioDeviceChanged; } - return 0; + return true; } void SDL_IMMDevice_Quit(void) @@ -336,7 +336,7 @@ void SDL_IMMDevice_Quit(void) WIN_CoUninitialize(); } -int SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, bool recording) +bool SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, bool recording) { const Uint64 timeout = SDL_GetTicks() + 8000; // intel's audio drivers can fail for up to EIGHT SECONDS after a device is connected or we wake from sleep. @@ -357,8 +357,10 @@ int SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, bool recor break; } - return SUCCEEDED(ret) ? 0 : WIN_SetErrorFromHRESULT("WASAPI can't find requested audio endpoint", ret); - + if (!SUCCEEDED(ret)) { + return WIN_SetErrorFromHRESULT("WASAPI can't find requested audio endpoint", ret); + } + return true; } static void EnumerateEndpointsForFlow(const bool recording, SDL_AudioDevice **default_device) diff --git a/src/core/windows/SDL_immdevice.h b/src/core/windows/SDL_immdevice.h index e196763377..9ebd142e92 100644 --- a/src/core/windows/SDL_immdevice.h +++ b/src/core/windows/SDL_immdevice.h @@ -34,9 +34,9 @@ typedef struct SDL_IMMDevice_callbacks void (*default_audio_device_changed)(SDL_AudioDevice *new_default_device); } SDL_IMMDevice_callbacks; -int SDL_IMMDevice_Init(const SDL_IMMDevice_callbacks *callbacks); +bool SDL_IMMDevice_Init(const SDL_IMMDevice_callbacks *callbacks); void SDL_IMMDevice_Quit(void); -int SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, bool recording); +bool SDL_IMMDevice_Get(SDL_AudioDevice *device, IMMDevice **immdevice, bool recording); void SDL_IMMDevice_EnumerateEndpoints(SDL_AudioDevice **default_playback, SDL_AudioDevice **default_recording); LPGUID SDL_IMMDevice_GetDirectSoundGUID(SDL_AudioDevice *device); LPCWSTR SDL_IMMDevice_GetDevID(SDL_AudioDevice *device); diff --git a/src/core/windows/SDL_windows.c b/src/core/windows/SDL_windows.c index f8d59dd406..397c37e77e 100644 --- a/src/core/windows/SDL_windows.c +++ b/src/core/windows/SDL_windows.c @@ -54,7 +54,7 @@ typedef enum RO_INIT_TYPE #endif // Sets an error message based on an HRESULT -int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr) +bool WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr) { TCHAR buffer[1024]; char *message; @@ -73,11 +73,11 @@ int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr) message = WIN_StringToUTF8(buffer); SDL_SetError("%s%s%s", prefix ? prefix : "", prefix ? ": " : "", message); SDL_free(message); - return -1; + return false; } // Sets an error message based on GetLastError() -int WIN_SetError(const char *prefix) +bool WIN_SetError(const char *prefix) { return WIN_SetErrorFromHRESULT(prefix, GetLastError()); } @@ -207,12 +207,12 @@ static BOOL IsWindowsVersionOrGreater(WORD wMajorVersion, WORD wMinorVersion, WO #else #define CHECKWINVER(notdesktop_platform_result, test) \ static bool checked = false; \ - static BOOL retval = FALSE; \ + static BOOL result = FALSE; \ if (!checked) { \ - retval = (test); \ + result = (test); \ checked = true; \ } \ - return retval; + return result; #endif // this is the oldest thing we run on (and we may lose support for this in SDL3 at any time!), @@ -275,7 +275,7 @@ char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid) bool rc; HKEY hkey; DWORD len = 0; - char *retval = NULL; + char *result = NULL; if (WIN_IsEqualGUID(guid, &nullguid)) { return WIN_StringToUTF8(name); // No GUID, go with what we've got. @@ -315,9 +315,9 @@ char *WIN_LookupAudioDeviceName(const WCHAR *name, const GUID *guid) strw[len / 2] = 0; // make sure it's null-terminated. - retval = WIN_StringToUTF8(strw); + result = WIN_StringToUTF8(strw); SDL_free(strw); - return retval ? retval : WIN_StringToUTF8(name); + return result ? result : WIN_StringToUTF8(name); #endif // if SDL_PLATFORM_WINRT / else } diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index 95f5aee34f..f83e21406a 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -117,10 +117,10 @@ extern "C" { #endif // Sets an error message based on a given HRESULT -extern int WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr); +extern bool WIN_SetErrorFromHRESULT(const char *prefix, HRESULT hr); // Sets an error message based on GetLastError(). Always return -1. -extern int WIN_SetError(const char *prefix); +extern bool WIN_SetError(const char *prefix); #ifndef SDL_PLATFORM_WINRT // Load a function from combase.dll diff --git a/src/core/windows/SDL_xinput.c b/src/core/windows/SDL_xinput.c index 7221904162..32d4722ef2 100644 --- a/src/core/windows/SDL_xinput.c +++ b/src/core/windows/SDL_xinput.c @@ -39,7 +39,7 @@ static int s_XInputDLLRefCount = 0; #if defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) -int WIN_LoadXInputDLL(void) +bool WIN_LoadXInputDLL(void) { /* Getting handles to system dlls (via LoadLibrary and its variants) is not * supported on WinRT, thus, pointers to XInput's functions can't be @@ -61,7 +61,7 @@ int WIN_LoadXInputDLL(void) // XInput 1.4 ships with Windows 8 and 8.1: SDL_XInputVersion = (1 << 16) | 4; - return 0; + return true; } void WIN_UnloadXInputDLL(void) @@ -70,14 +70,14 @@ void WIN_UnloadXInputDLL(void) #else // !(defined(SDL_PLATFORM_WINRT) || defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)) -int WIN_LoadXInputDLL(void) +bool WIN_LoadXInputDLL(void) { DWORD version = 0; if (s_pXInputDLL) { SDL_assert(s_XInputDLLRefCount > 0); s_XInputDLLRefCount++; - return 0; // already loaded + return true; // already loaded } /* NOTE: Don't load XinputUap.dll @@ -98,7 +98,7 @@ int WIN_LoadXInputDLL(void) s_pXInputDLL = LoadLibrary(TEXT("XInput9_1_0.dll")); } if (!s_pXInputDLL) { - return -1; + return false; } SDL_assert(s_XInputDLLRefCount == 0); @@ -117,10 +117,10 @@ int WIN_LoadXInputDLL(void) SDL_XInputGetBatteryInformation = (XInputGetBatteryInformation_t)GetProcAddress(s_pXInputDLL, "XInputGetBatteryInformation"); if (!SDL_XInputGetState || !SDL_XInputSetState || !SDL_XInputGetCapabilities) { WIN_UnloadXInputDLL(); - return -1; + return false; } - return 0; + return true; } void WIN_UnloadXInputDLL(void) diff --git a/src/core/windows/SDL_xinput.h b/src/core/windows/SDL_xinput.h index 48f6740927..ff72b23985 100644 --- a/src/core/windows/SDL_xinput.h +++ b/src/core/windows/SDL_xinput.h @@ -252,7 +252,7 @@ typedef DWORD(WINAPI *XInputGetBatteryInformation_t)( BYTE devType, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation); -extern int WIN_LoadXInputDLL(void); +extern bool WIN_LoadXInputDLL(void); extern void WIN_UnloadXInputDLL(void); extern XInputGetState_t SDL_XInputGetState; diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp index 2591eb7188..3017225546 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp @@ -94,12 +94,12 @@ IFrameworkView ^ SDLApplicationSource::CreateView() return app; } -int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **)) +bool SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **)) { WINRT_SDLAppEntryPoint = mainFunction; auto direct3DApplicationSource = ref new SDLApplicationSource(); CoreApplication::Run(direct3DApplicationSource); - return 0; + return true; } static void WINRT_ProcessWindowSizeChange() // TODO: Pass an SDL_Window-identifying thing into WINRT_ProcessWindowSizeChange() diff --git a/src/core/winrt/SDL_winrtapp_direct3d.h b/src/core/winrt/SDL_winrtapp_direct3d.h index 9fb21f3209..07e6f162db 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.h +++ b/src/core/winrt/SDL_winrtapp_direct3d.h @@ -20,7 +20,7 @@ */ #include -extern int SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **)); +extern bool SDL_WinRTInitNonXAMLApp(int (*mainFunction)(int, char **)); ref class SDL_WinRTApp sealed : public Windows::ApplicationModel::Core::IFrameworkView { diff --git a/src/core/winrt/SDL_winrtapp_xaml.cpp b/src/core/winrt/SDL_winrtapp_xaml.cpp index 5fa2ffa9d3..876c73a894 100644 --- a/src/core/winrt/SDL_winrtapp_xaml.cpp +++ b/src/core/winrt/SDL_winrtapp_xaml.cpp @@ -85,7 +85,7 @@ static void WINRT_OnRenderViaXAML(_In_ Platform::Object ^ sender, _In_ Platform: * SDL + XAML Initialization */ -int SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void *backgroundPanelAsIInspectable) +bool SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void *backgroundPanelAsIInspectable) { #if SDL_WINAPI_FAMILY_PHONE return SDL_SetError("XAML support is not yet available in Windows Phone."); @@ -133,14 +133,14 @@ int SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void *backgroundPane // Make sure video modes are detected now, while we still have access to the WinRT // CoreWindow. WinRT will not allow the app's CoreWindow to be accessed via the // SDL/WinRT thread. - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) { // SDL_InitSubSystem will, on error, set the SDL error. Let that propagate to // the caller to here: WINRT_XAMLWasEnabled = oldXAMLWasEnabledValue; - return -1; + return false; } // All done, for now. - return 0; + return true; #endif // SDL_WINAPI_FAMILY_PHONE } diff --git a/src/core/winrt/SDL_winrtapp_xaml.h b/src/core/winrt/SDL_winrtapp_xaml.h index c4797fa705..148e278dcb 100644 --- a/src/core/winrt/SDL_winrtapp_xaml.h +++ b/src/core/winrt/SDL_winrtapp_xaml.h @@ -25,7 +25,7 @@ #ifdef __cplusplus extern bool WINRT_XAMLWasEnabled; -extern int SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void *backgroundPanelAsIInspectable); +extern bool SDL_WinRTInitXAMLApp(int (*mainFunction)(int, char **), void *backgroundPanelAsIInspectable); #endif // ifdef __cplusplus #endif // SDL_winrtapp_xaml_h_ diff --git a/src/dialog/haiku/SDL_haikudialog.cc b/src/dialog/haiku/SDL_haikudialog.cc index 5dd4f0c9cf..2aa4858992 100644 --- a/src/dialog/haiku/SDL_haikudialog.cc +++ b/src/dialog/haiku/SDL_haikudialog.cc @@ -43,18 +43,18 @@ bool StringEndsWith(const std::string& str, const std::string& end) std::vector StringSplit(const std::string& str, const std::string& split) { - std::vector retval; + std::vector result; std::string s = str; size_t pos = 0; while ((pos = s.find(split)) != std::string::npos) { - retval.push_back(s.substr(0, pos)); + result.push_back(s.substr(0, pos)); s = s.substr(pos + split.size()); } - retval.push_back(s); + result.push_back(s); - return retval; + return result; } class SDLBRefFilter : public BRefFilter @@ -192,7 +192,7 @@ private: void ShowDialog(bool save, SDL_DialogFileCallback callback, void *userdata, bool many, bool modal, const SDL_DialogFileFilter *filters, int nfilters, bool folder, const char *location) { - if (SDL_InitBeApp()) { + if (!SDL_InitBeApp()) { char* err = SDL_strdup(SDL_GetError()); SDL_SetError("Couldn't init Be app: %s", err); SDL_free(err); diff --git a/src/dialog/unix/SDL_portaldialog.c b/src/dialog/unix/SDL_portaldialog.c index 66dbcd1d9d..7938567a0b 100644 --- a/src/dialog/unix/SDL_portaldialog.c +++ b/src/dialog/unix/SDL_portaldialog.c @@ -440,7 +440,7 @@ void SDL_Portal_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* user DBus_OpenDialog("OpenFile", "Open Folder", callback, userdata, window, NULL, 0, default_location, allow_many, 1); } -int SDL_Portal_detect(void) +bool SDL_Portal_detect(void) { SDL_DBusContext *dbus = SDL_DBus_GetContext(); DBusMessage *msg = NULL, *reply = NULL; @@ -450,14 +450,14 @@ int SDL_Portal_detect(void) // No need for this if the result is cached. if (portal_present != -1) { - return portal_present; + return (portal_present > 0); } portal_present = 0; if (!dbus) { SDL_SetError("%s", "Failed to connect to DBus!"); - return 0; + return false; } // Use introspection to get the available services. @@ -493,7 +493,7 @@ done: dbus->message_unref(reply); } - return portal_present; + return (portal_present > 0); } #else @@ -518,9 +518,9 @@ void SDL_Portal_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* user callback(userdata, NULL, -1); } -int SDL_Portal_detect(void) +bool SDL_Portal_detect(void) { - return 0; + return false; } #endif // SDL_USE_LIBDBUS diff --git a/src/dialog/unix/SDL_portaldialog.h b/src/dialog/unix/SDL_portaldialog.h index f6275d8343..495933cf60 100644 --- a/src/dialog/unix/SDL_portaldialog.h +++ b/src/dialog/unix/SDL_portaldialog.h @@ -26,4 +26,4 @@ void SDL_Portal_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userda void SDL_Portal_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const char* default_location, bool allow_many); /** @returns non-zero if available, zero if unavailable */ -int SDL_Portal_detect(void); +bool SDL_Portal_detect(void); diff --git a/src/dialog/unix/SDL_zenitydialog.c b/src/dialog/unix/SDL_zenitydialog.c index f6f037f285..131352e7d9 100644 --- a/src/dialog/unix/SDL_zenitydialog.c +++ b/src/dialog/unix/SDL_zenitydialog.c @@ -407,7 +407,7 @@ void SDL_Zenity_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* user SDL_DetachThread(thread); } -int SDL_Zenity_detect(void) +bool SDL_Zenity_detect(void) { pid_t process; int status = -1; @@ -416,7 +416,7 @@ int SDL_Zenity_detect(void) if (process < 0) { SDL_SetError("Could not fork process: %s", strerror(errno)); - return 0; + return false; } else if (process == 0){ // Disable output close(STDERR_FILENO); @@ -426,13 +426,13 @@ int SDL_Zenity_detect(void) } else { if (waitpid(process, &status, 0) == -1) { SDL_SetError("waitpid failed"); - return 0; + return false; } if (WIFEXITED(status)) { status = WEXITSTATUS(status); } - return !status; + return (status == 0); } } diff --git a/src/dialog/unix/SDL_zenitydialog.h b/src/dialog/unix/SDL_zenitydialog.h index 507f801e92..b17f79f381 100644 --- a/src/dialog/unix/SDL_zenitydialog.h +++ b/src/dialog/unix/SDL_zenitydialog.h @@ -21,9 +21,9 @@ #include "SDL_internal.h" -void SDL_Zenity_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const SDL_DialogFileFilter *filters, int nfilters, const char* default_location, bool allow_many); -void SDL_Zenity_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const SDL_DialogFileFilter *filters, int nfilters, const char* default_location); -void SDL_Zenity_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const char* default_location, bool allow_many); +extern void SDL_Zenity_ShowOpenFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const SDL_DialogFileFilter *filters, int nfilters, const char* default_location, bool allow_many); +extern void SDL_Zenity_ShowSaveFileDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const SDL_DialogFileFilter *filters, int nfilters, const char* default_location); +extern void SDL_Zenity_ShowOpenFolderDialog(SDL_DialogFileCallback callback, void* userdata, SDL_Window* window, const char* default_location, bool allow_many); /** @returns non-zero if available, zero if unavailable */ -int SDL_Zenity_detect(void); +extern bool SDL_Zenity_detect(void); diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c index 164f7d65e1..b67b6cb4eb 100644 --- a/src/dynapi/SDL_dynapi.c +++ b/src/dynapi/SDL_dynapi.c @@ -76,7 +76,7 @@ static void SDL_InitDynamicAPI(void); } #define SDL_DYNAPI_VARARGS(_static, name, initcall) \ - _static int SDLCALL SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ + _static SDL_bool SDLCALL SDL_SetError##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ { \ char buf[128], *str = buf; \ int result; \ @@ -95,62 +95,62 @@ static void SDL_InitDynamicAPI(void); } \ } \ if (result >= 0) { \ - result = jump_table.SDL_SetError("%s", str); \ + jump_table.SDL_SetError("%s", str); \ } \ if (str != buf) { \ jump_table.SDL_free(str); \ } \ - return result; \ + return SDL_FALSE; \ } \ _static int SDLCALL SDL_sscanf##name(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) \ { \ - int retval; \ + int result; \ va_list ap; \ initcall; \ va_start(ap, fmt); \ - retval = jump_table.SDL_vsscanf(buf, fmt, ap); \ + result = jump_table.SDL_vsscanf(buf, fmt, ap); \ va_end(ap); \ - return retval; \ + return result; \ } \ _static int SDLCALL SDL_snprintf##name(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ { \ - int retval; \ + int result; \ va_list ap; \ initcall; \ va_start(ap, fmt); \ - retval = jump_table.SDL_vsnprintf(buf, maxlen, fmt, ap); \ + result = jump_table.SDL_vsnprintf(buf, maxlen, fmt, ap); \ va_end(ap); \ - return retval; \ + return result; \ } \ _static int SDLCALL SDL_swprintf##name(SDL_OUT_Z_CAP(maxlen) wchar_t *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) \ { \ - int retval; \ + int result; \ va_list ap; \ initcall; \ va_start(ap, fmt); \ - retval = jump_table.SDL_vswprintf(buf, maxlen, fmt, ap); \ + result = jump_table.SDL_vswprintf(buf, maxlen, fmt, ap); \ va_end(ap); \ - return retval; \ + return result; \ } \ _static int SDLCALL SDL_asprintf##name(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ { \ - int retval; \ + int result; \ va_list ap; \ initcall; \ va_start(ap, fmt); \ - retval = jump_table.SDL_vasprintf(strp, fmt, ap); \ + result = jump_table.SDL_vasprintf(strp, fmt, ap); \ va_end(ap); \ - return retval; \ + return result; \ } \ _static size_t SDLCALL SDL_IOprintf##name(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ { \ - size_t retval; \ + size_t result; \ va_list ap; \ initcall; \ va_start(ap, fmt); \ - retval = jump_table.SDL_IOvprintf(context, fmt, ap); \ + result = jump_table.SDL_IOvprintf(context, fmt, ap); \ va_end(ap); \ - return retval; \ + return result; \ } \ _static void SDLCALL SDL_Log##name(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) \ { \ @@ -232,7 +232,7 @@ SDL_DYNAPI_VARARGS(, , ) #define ENABLE_SDL_CALL_LOGGING 0 #if ENABLE_SDL_CALL_LOGGING -static int SDLCALL SDL_SetError_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) +static SDL_bool SDLCALL SDL_SetError_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { char buf[512]; // !!! FIXME: dynamic allocation va_list ap; @@ -244,53 +244,53 @@ static int SDLCALL SDL_SetError_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char } static int SDLCALL SDL_sscanf_LOGSDLCALLS(const char *buf, SDL_SCANF_FORMAT_STRING const char *fmt, ...) { - int retval; + int result; va_list ap; SDL_Log_REAL("SDL3CALL SDL_sscanf"); va_start(ap, fmt); - retval = SDL_vsscanf_REAL(buf, fmt, ap); + result = SDL_vsscanf_REAL(buf, fmt, ap); va_end(ap); - return retval; + return result; } static int SDLCALL SDL_snprintf_LOGSDLCALLS(SDL_OUT_Z_CAP(maxlen) char *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { - int retval; + int result; va_list ap; SDL_Log_REAL("SDL3CALL SDL_snprintf"); va_start(ap, fmt); - retval = SDL_vsnprintf_REAL(buf, maxlen, fmt, ap); + result = SDL_vsnprintf_REAL(buf, maxlen, fmt, ap); va_end(ap); - return retval; + return result; } static int SDLCALL SDL_asprintf_LOGSDLCALLS(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { - int retval; + int result; va_list ap; SDL_Log_REAL("SDL3CALL SDL_asprintf"); va_start(ap, fmt); - retval = SDL_vasprintf_REAL(strp, fmt, ap); + result = SDL_vasprintf_REAL(strp, fmt, ap); va_end(ap); - return retval; + return result; } static int SDLCALL SDL_swprintf_LOGSDLCALLS(SDL_OUT_Z_CAP(maxlen) wchar_t *buf, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) { - int retval; + int result; va_list ap; SDL_Log_REAL("SDL3CALL SDL_swprintf"); va_start(ap, fmt); - retval = SDL_vswprintf_REAL(buf, maxlen, fmt, ap); + result = SDL_vswprintf_REAL(buf, maxlen, fmt, ap); va_end(ap); - return retval; + return result; } static size_t SDLCALL SDL_IOprintf_LOGSDLCALLS(SDL_IOStream *context, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { - size_t retval; + size_t result; va_list ap; SDL_Log_REAL("SDL3CALL SDL_IOprintf"); va_start(ap, fmt); - retval = SDL_IOvprintf_REAL(context, fmt, ap); + result = SDL_IOvprintf_REAL(context, fmt, ap); va_end(ap); - return retval; + return result; } static void SDLCALL SDL_Log_LOGSDLCALLS(SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { @@ -403,14 +403,14 @@ Sint32 SDL_DYNAPI_entry(Uint32 apiver, void *table, Uint32 tablesize) static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym) { HMODULE lib = LoadLibraryA(fname); - void *retval = NULL; + void *result = NULL; if (lib) { - retval = (void *) GetProcAddress(lib, sym); - if (!retval) { + result = (void *) GetProcAddress(lib, sym); + if (!result) { FreeLibrary(lib); } } - return retval; + return result; } #elif defined(SDL_PLATFORM_UNIX) || defined(SDL_PLATFORM_APPLE) || defined(SDL_PLATFORM_HAIKU) @@ -418,14 +418,14 @@ static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym) static SDL_INLINE void *get_sdlapi_entry(const char *fname, const char *sym) { void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL); - void *retval = NULL; + void *result = NULL; if (lib) { - retval = dlsym(lib, sym); - if (!retval) { + result = dlsym(lib, sym); + if (!result) { dlclose(lib); } } - return retval; + return result; } #else diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 74163819c9..acfdeffad7 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -39,7 +39,7 @@ SDL_DYNAPI_PROC(void,SDL_LogInfo,(int a, SDL_PRINTF_FORMAT_STRING const char *b, SDL_DYNAPI_PROC(void,SDL_LogMessage,(int a, SDL_LogPriority b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_LogVerbose,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),) SDL_DYNAPI_PROC(void,SDL_LogWarn,(int a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),) -SDL_DYNAPI_PROC(int,SDL_SetError,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetError,(SDL_PRINTF_FORMAT_STRING const char *a, ...),(a),return) SDL_DYNAPI_PROC(int,SDL_asprintf,(char **a, SDL_PRINTF_FORMAT_STRING const char *b, ...),(a,b),return) SDL_DYNAPI_PROC(int,SDL_snprintf,(SDL_OUT_Z_CAP(b) char *a, size_t b, SDL_PRINTF_FORMAT_STRING const char *c, ...),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_sscanf,(const char *a, SDL_SCANF_FORMAT_STRING const char *b, ...),(a,b),return) @@ -48,15 +48,15 @@ SDL_DYNAPI_PROC(int,SDL_swprintf,(SDL_OUT_Z_CAP(b) wchar_t *a, size_t b, SDL_PRI // New API symbols are added at the end SDL_DYNAPI_PROC(SDL_Surface*,SDL_AcquireCameraFrame,(SDL_Camera *a, Uint64 *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_AddEventWatch,(SDL_EventFilter a, void *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_AddEventWatch,(SDL_EventFilter a, void *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_AddGamepadMapping,(const char *a),(a),return) SDL_DYNAPI_PROC(int,SDL_AddGamepadMappingsFromFile,(const char *a),(a),return) SDL_DYNAPI_PROC(int,SDL_AddGamepadMappingsFromIO,(SDL_IOStream *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_AddHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_AddSurfaceAlternateImage,(SDL_Surface *a, SDL_Surface *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_AddHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_AddSurfaceAlternateImage,(SDL_Surface *a, SDL_Surface *b),(a,b),return) SDL_DYNAPI_PROC(SDL_TimerID,SDL_AddTimer,(Uint32 a, SDL_TimerCallback b, void *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_TimerID,SDL_AddTimerNS,(Uint64 a, SDL_NSTimerCallback b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_AddVulkanRenderSemaphores,(SDL_Renderer *a, Uint32 b, Sint64 c, Sint64 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_AddVulkanRenderSemaphores,(SDL_Renderer *a, Uint32 b, Sint64 c, Sint64 d),(a,b,c,d),return) SDL_DYNAPI_PROC(int,SDL_AtomicAdd,(SDL_AtomicInt *a, int b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCompareAndSwap,(SDL_AtomicInt *a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_AtomicCompareAndSwapPointer,(void **a, void *b, void *c),(a,b,c),return) @@ -66,47 +66,47 @@ SDL_DYNAPI_PROC(int,SDL_AtomicSet,(SDL_AtomicInt *a, int b),(a,b),return) SDL_DYNAPI_PROC(void*,SDL_AtomicSetPtr,(void **a, void *b),(a,b),return) SDL_DYNAPI_PROC(SDL_JoystickID,SDL_AttachVirtualJoystick,(const SDL_VirtualJoystickDesc *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_AudioDevicePaused,(SDL_AudioDeviceID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_BindAudioStream,(SDL_AudioDeviceID a, SDL_AudioStream *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_BindAudioStreams,(SDL_AudioDeviceID a, SDL_AudioStream **b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_BlitSurface,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_BlitSurface9Grid,(SDL_Surface *a, const SDL_Rect *b, int c, int d, int e, int f, float g, SDL_ScaleMode h, SDL_Surface *i, const SDL_Rect *j),(a,b,c,d,e,f,g,h,i,j),return) -SDL_DYNAPI_PROC(int,SDL_BlitSurfaceScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d, SDL_ScaleMode e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_BlitSurfaceTiled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_BlitSurfaceTiledWithScale,(SDL_Surface *a, const SDL_Rect *b, float c, SDL_ScaleMode d, SDL_Surface *e, const SDL_Rect *f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(int,SDL_BlitSurfaceUnchecked,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_BlitSurfaceUncheckedScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d, SDL_ScaleMode e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_BroadcastCondition,(SDL_Condition *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_CaptureMouse,(SDL_bool a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BindAudioStream,(SDL_AudioDeviceID a, SDL_AudioStream *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BindAudioStreams,(SDL_AudioDeviceID a, SDL_AudioStream **b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BlitSurface,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BlitSurface9Grid,(SDL_Surface *a, const SDL_Rect *b, int c, int d, int e, int f, float g, SDL_ScaleMode h, SDL_Surface *i, const SDL_Rect *j),(a,b,c,d,e,f,g,h,i,j),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BlitSurfaceScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d, SDL_ScaleMode e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BlitSurfaceTiled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BlitSurfaceTiledWithScale,(SDL_Surface *a, const SDL_Rect *b, float c, SDL_ScaleMode d, SDL_Surface *e, const SDL_Rect *f),(a,b,c,d,e,f),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BlitSurfaceUnchecked,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_BlitSurfaceUncheckedScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d, SDL_ScaleMode e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(void,SDL_BroadcastCondition,(SDL_Condition *a),(a),) +SDL_DYNAPI_PROC(SDL_bool,SDL_CaptureMouse,(SDL_bool a),(a),return) SDL_DYNAPI_PROC(void,SDL_CleanupTLS,(void),(),) -SDL_DYNAPI_PROC(int,SDL_ClearAudioStream,(SDL_AudioStream *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_ClearClipboardData,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_ClearComposition,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_ClearError,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_ClearProperty,(SDL_PropertiesID a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_ClearSurface,(SDL_Surface *a, float b, float c, float d, float e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ClearAudioStream,(SDL_AudioStream *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ClearClipboardData,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ClearComposition,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ClearError,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ClearProperty,(SDL_PropertiesID a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ClearSurface,(SDL_Surface *a, float b, float c, float d, float e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(void,SDL_CloseAudioDevice,(SDL_AudioDeviceID a),(a),) SDL_DYNAPI_PROC(void,SDL_CloseCamera,(SDL_Camera *a),(a),) SDL_DYNAPI_PROC(void,SDL_CloseGamepad,(SDL_Gamepad *a),(a),) SDL_DYNAPI_PROC(void,SDL_CloseHaptic,(SDL_Haptic *a),(a),) -SDL_DYNAPI_PROC(int,SDL_CloseIO,(SDL_IOStream *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CloseIO,(SDL_IOStream *a),(a),return) SDL_DYNAPI_PROC(void,SDL_CloseJoystick,(SDL_Joystick *a),(a),) SDL_DYNAPI_PROC(void,SDL_CloseSensor,(SDL_Sensor *a),(a),) -SDL_DYNAPI_PROC(int,SDL_CloseStorage,(SDL_Storage *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CloseStorage,(SDL_Storage *a),(a),return) SDL_DYNAPI_PROC(SDL_BlendMode,SDL_ComposeCustomBlendMode,(SDL_BlendFactor a, SDL_BlendFactor b, SDL_BlendOperation c, SDL_BlendFactor d, SDL_BlendFactor e, SDL_BlendOperation f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(int,SDL_ConvertAudioSamples,(const SDL_AudioSpec *a, const Uint8 *b, int c, const SDL_AudioSpec *d, Uint8 **e, int *f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(int,SDL_ConvertEventToRenderCoordinates,(SDL_Renderer *a, SDL_Event *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_ConvertPixels,(int a, int b, SDL_PixelFormat c, const void *d, int e, SDL_PixelFormat f, void *g, int h),(a,b,c,d,e,f,g,h),return) -SDL_DYNAPI_PROC(int,SDL_ConvertPixelsAndColorspace,(int a, int b, SDL_PixelFormat c, SDL_Colorspace d, SDL_PropertiesID e, const void *f, int g, SDL_PixelFormat h, SDL_Colorspace i, SDL_PropertiesID j, void *k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ConvertAudioSamples,(const SDL_AudioSpec *a, const Uint8 *b, int c, const SDL_AudioSpec *d, Uint8 **e, int *f),(a,b,c,d,e,f),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ConvertEventToRenderCoordinates,(SDL_Renderer *a, SDL_Event *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ConvertPixels,(int a, int b, SDL_PixelFormat c, const void *d, int e, SDL_PixelFormat f, void *g, int h),(a,b,c,d,e,f,g,h),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ConvertPixelsAndColorspace,(int a, int b, SDL_PixelFormat c, SDL_Colorspace d, SDL_PropertiesID e, const void *f, int g, SDL_PixelFormat h, SDL_Colorspace i, SDL_PropertiesID j, void *k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurface,(SDL_Surface *a, SDL_PixelFormat b),(a,b),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_ConvertSurfaceAndColorspace,(SDL_Surface *a, SDL_PixelFormat b, SDL_Palette *c, SDL_Colorspace d, SDL_PropertiesID e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_CopyFile,(const char *a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_CopyProperties,(SDL_PropertiesID a, SDL_PropertiesID b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_CopyStorageFile,(SDL_Storage *a, const char *b, const char *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CopyFile,(const char *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CopyProperties,(SDL_PropertiesID a, SDL_PropertiesID b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CopyStorageFile,(SDL_Storage *a, const char *b, const char *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_AudioStream*,SDL_CreateAudioStream,(const SDL_AudioSpec *a, const SDL_AudioSpec *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateColorCursor,(SDL_Surface *a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Condition*,SDL_CreateCondition,(void),(),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_CreateCursor,(const Uint8 *a, const Uint8 *b, int c, int d, int e, int f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(int,SDL_CreateDirectory,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CreateDirectory,(const char *a),(a),return) SDL_DYNAPI_PROC(int,SDL_CreateHapticEffect,(SDL_Haptic *a, const SDL_HapticEffect *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Mutex*,SDL_CreateMutex,(void),(),return) SDL_DYNAPI_PROC(SDL_Palette*,SDL_CreatePalette,(int a),(a),return) @@ -117,7 +117,7 @@ SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRenderer,(SDL_Window *a, const char *b), SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateRendererWithProperties,(SDL_PropertiesID a),(a),return) SDL_DYNAPI_PROC(SDL_Semaphore*,SDL_CreateSemaphore,(Uint32 a),(a),return) SDL_DYNAPI_PROC(SDL_Renderer*,SDL_CreateSoftwareRenderer,(SDL_Surface *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_CreateStorageDirectory,(SDL_Storage *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CreateStorageDirectory,(SDL_Storage *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurface,(int a, int b, SDL_PixelFormat c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurfaceFrom,(int a, int b, SDL_PixelFormat c, void *d, int e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(SDL_Palette*,SDL_CreateSurfacePalette,(SDL_Surface *a),(a),return) @@ -128,10 +128,10 @@ SDL_DYNAPI_PROC(SDL_Texture*,SDL_CreateTextureWithProperties,(SDL_Renderer *a, S SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadRuntime,(SDL_ThreadFunction a, const char *b, void *c, SDL_FunctionPointer d, SDL_FunctionPointer e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(SDL_Thread*,SDL_CreateThreadWithPropertiesRuntime,(SDL_PropertiesID a, SDL_FunctionPointer b, SDL_FunctionPointer c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindow,(const char *a, int b, int c, SDL_WindowFlags d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_CreateWindowAndRenderer,(const char *a, int b, int c, SDL_WindowFlags d, SDL_Window **e, SDL_Renderer **f),(a,b,c,d,e,f),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_CreateWindowAndRenderer,(const char *a, int b, int c, SDL_WindowFlags d, SDL_Window **e, SDL_Renderer **f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_CreateWindowWithProperties,(SDL_PropertiesID a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_CursorVisible,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_DateTimeToTime,(const SDL_DateTime *a, SDL_Time *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_DateTimeToTime,(const SDL_DateTime *a, SDL_Time *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_DelEventWatch,(SDL_EventFilter a, void *b),(a,b),) SDL_DYNAPI_PROC(void,SDL_DelHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_Delay,(Uint32 a),(a),) @@ -149,46 +149,46 @@ SDL_DYNAPI_PROC(void,SDL_DestroySemaphore,(SDL_Semaphore *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroySurface,(SDL_Surface *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroyTexture,(SDL_Texture *a),(a),) SDL_DYNAPI_PROC(void,SDL_DestroyWindow,(SDL_Window *a),(a),) -SDL_DYNAPI_PROC(int,SDL_DestroyWindowSurface,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_DestroyWindowSurface,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(void,SDL_DetachThread,(SDL_Thread *a),(a),) -SDL_DYNAPI_PROC(int,SDL_DetachVirtualJoystick,(SDL_JoystickID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_DisableScreenSaver,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_DetachVirtualJoystick,(SDL_JoystickID a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_DisableScreenSaver,(void),(),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_DuplicateSurface,(SDL_Surface *a),(a),return) SDL_DYNAPI_PROC(SDL_EGLConfig,SDL_EGL_GetCurrentConfig,(void),(),return) SDL_DYNAPI_PROC(SDL_EGLDisplay,SDL_EGL_GetCurrentDisplay,(void),(),return) SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_EGL_GetProcAddress,(const char *a),(a),return) SDL_DYNAPI_PROC(SDL_EGLSurface,SDL_EGL_GetWindowSurface,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(void,SDL_EGL_SetAttributeCallbacks,(SDL_EGLAttribArrayCallback a, SDL_EGLIntArrayCallback b, SDL_EGLIntArrayCallback c),(a,b,c),) -SDL_DYNAPI_PROC(int,SDL_EnableScreenSaver,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_EnableScreenSaver,(void),(),return) SDL_DYNAPI_PROC(int,SDL_EnterAppMainCallbacks,(int a, char *b[], SDL_AppInit_func c, SDL_AppIterate_func d, SDL_AppEvent_func e, SDL_AppQuit_func f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(int,SDL_EnumerateDirectory,(const char *a, SDL_EnumerateDirectoryCallback b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_EnumerateProperties,(SDL_PropertiesID a, SDL_EnumeratePropertiesCallback b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_EnumerateStorageDirectory,(SDL_Storage *a, const char *b, SDL_EnumerateDirectoryCallback c, void *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_EnumerateDirectory,(const char *a, SDL_EnumerateDirectoryCallback b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_EnumerateProperties,(SDL_PropertiesID a, SDL_EnumeratePropertiesCallback b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_EnumerateStorageDirectory,(SDL_Storage *a, const char *b, SDL_EnumerateDirectoryCallback c, void *d),(a,b,c,d),return) SDL_DYNAPI_PROC(SDL_bool,SDL_EventEnabled,(Uint32 a),(a),return) -SDL_DYNAPI_PROC(int,SDL_FillSurfaceRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_FillSurfaceRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_FillSurfaceRect,(SDL_Surface *a, const SDL_Rect *b, Uint32 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_FillSurfaceRects,(SDL_Surface *a, const SDL_Rect *b, int c, Uint32 d),(a,b,c,d),return) SDL_DYNAPI_PROC(void,SDL_FilterEvents,(SDL_EventFilter a, void *b),(a,b),) -SDL_DYNAPI_PROC(int,SDL_FlashWindow,(SDL_Window *a, SDL_FlashOperation b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_FlipSurface,(SDL_Surface *a, SDL_FlipMode b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_FlushAudioStream,(SDL_AudioStream *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_FlashWindow,(SDL_Window *a, SDL_FlashOperation b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_FlipSurface,(SDL_Surface *a, SDL_FlipMode b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_FlushAudioStream,(SDL_AudioStream *a),(a),return) SDL_DYNAPI_PROC(void,SDL_FlushEvent,(Uint32 a),(a),) SDL_DYNAPI_PROC(void,SDL_FlushEvents,(Uint32 a, Uint32 b),(a,b),) -SDL_DYNAPI_PROC(int,SDL_FlushRenderer,(SDL_Renderer *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_FlushRenderer,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(void,SDL_GDKSuspendComplete,(void),(),) SDL_DYNAPI_PROC(SDL_GLContext,SDL_GL_CreateContext,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GL_DestroyContext,(SDL_GLContext a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_DestroyContext,(SDL_GLContext a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GL_ExtensionSupported,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GL_GetAttribute,(SDL_GLattr a, int *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_GetAttribute,(SDL_GLattr a, int *b),(a,b),return) SDL_DYNAPI_PROC(SDL_GLContext,SDL_GL_GetCurrentContext,(void),(),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_GL_GetCurrentWindow,(void),(),return) SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_GL_GetProcAddress,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GL_GetSwapInterval,(int *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GL_LoadLibrary,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GL_MakeCurrent,(SDL_Window *a, SDL_GLContext b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_GetSwapInterval,(int *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_LoadLibrary,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_MakeCurrent,(SDL_Window *a, SDL_GLContext b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_GL_ResetAttributes,(void),(),) -SDL_DYNAPI_PROC(int,SDL_GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GL_SetSwapInterval,(int a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GL_SwapWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_SetSwapInterval,(int a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GL_SwapWindow,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(void,SDL_GL_UnloadLibrary,(void),(),) SDL_DYNAPI_PROC(void,SDL_GUIDToString,(SDL_GUID a, char *b, int c),(a,b,c),) SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadConnected,(SDL_Gamepad *a),(a),return) @@ -208,7 +208,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetAppMetadataProperty,(const char *a),(a),retur SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return) SDL_DYNAPI_PROC(const SDL_AssertData*,SDL_GetAssertionReport,(void),(),return) SDL_DYNAPI_PROC(int*,SDL_GetAudioDeviceChannelMap,(SDL_AudioDeviceID a, int *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetAudioDeviceFormat,(SDL_AudioDeviceID a, SDL_AudioSpec *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetAudioDeviceFormat,(SDL_AudioDeviceID a, SDL_AudioSpec *b, int *c),(a,b,c),return) SDL_DYNAPI_PROC(float,SDL_GetAudioDeviceGain,(SDL_AudioDeviceID a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetAudioDeviceName,(SDL_AudioDeviceID a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetAudioDriver,(int a),(a),return) @@ -218,7 +218,7 @@ SDL_DYNAPI_PROC(SDL_AudioDeviceID*,SDL_GetAudioRecordingDevices,(int *a),(a),ret SDL_DYNAPI_PROC(int,SDL_GetAudioStreamAvailable,(SDL_AudioStream *a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetAudioStreamData,(SDL_AudioStream *a, void *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_AudioDeviceID,SDL_GetAudioStreamDevice,(SDL_AudioStream *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetAudioStreamFormat,(SDL_AudioStream *a, SDL_AudioSpec *b, SDL_AudioSpec *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetAudioStreamFormat,(SDL_AudioStream *a, SDL_AudioSpec *b, SDL_AudioSpec *c),(a,b,c),return) SDL_DYNAPI_PROC(float,SDL_GetAudioStreamFrequencyRatio,(SDL_AudioStream *a),(a),return) SDL_DYNAPI_PROC(float,SDL_GetAudioStreamGain,(SDL_AudioStream *a),(a),return) SDL_DYNAPI_PROC(int*,SDL_GetAudioStreamInputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return) @@ -230,7 +230,7 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_GetBooleanProperty,(SDL_PropertiesID a, const char SDL_DYNAPI_PROC(int,SDL_GetCPUCacheLineSize,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetCPUCount,(void),(),return) SDL_DYNAPI_PROC(const char*,SDL_GetCameraDriver,(int a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetCameraFormat,(SDL_Camera *a, SDL_CameraSpec *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetCameraFormat,(SDL_Camera *a, SDL_CameraSpec *b),(a,b),return) SDL_DYNAPI_PROC(SDL_CameraID,SDL_GetCameraID,(SDL_Camera *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetCameraName,(SDL_CameraID a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetCameraPermissionState,(SDL_Camera *a),(a),return) @@ -240,18 +240,18 @@ SDL_DYNAPI_PROC(SDL_CameraSpec**,SDL_GetCameraSupportedFormats,(SDL_CameraID a, SDL_DYNAPI_PROC(SDL_CameraID*,SDL_GetCameras,(int *a),(a),return) SDL_DYNAPI_PROC(void*,SDL_GetClipboardData,(const char *a, size_t *b),(a,b),return) SDL_DYNAPI_PROC(char*,SDL_GetClipboardText,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_GetClosestFullscreenDisplayMode,(SDL_DisplayID a, int b, int c, float d, SDL_bool e, SDL_DisplayMode *f),(a,b,c,d,e,f),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetClosestFullscreenDisplayMode,(SDL_DisplayID a, int b, int c, float d, SDL_bool e, SDL_DisplayMode *f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return) SDL_DYNAPI_PROC(const char*,SDL_GetCurrentCameraDriver,(void),(),return) SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetCurrentDisplayMode,(SDL_DisplayID a),(a),return) SDL_DYNAPI_PROC(SDL_DisplayOrientation,SDL_GetCurrentDisplayOrientation,(SDL_DisplayID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetCurrentRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetCurrentRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetCurrentThreadID,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_GetCurrentTime,(SDL_Time *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetCurrentTime,(SDL_Time *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetCurrentVideoDriver,(void),(),return) SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetCursor,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_GetDXGIOutputInfo,(SDL_DisplayID a, int *b, int *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetDateTimeLocalePreferences,(SDL_DateFormat *a, SDL_TimeFormat *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetDXGIOutputInfo,(SDL_DisplayID a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetDateTimeLocalePreferences,(SDL_DateFormat *a, SDL_TimeFormat *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_GetDayOfWeek,(int a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetDayOfYear,(int a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_GetDaysInMonth,(int a, int b),(a,b),return) @@ -259,21 +259,21 @@ SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetDefaultAssertionHandler,(void),(),re SDL_DYNAPI_PROC(SDL_Cursor*,SDL_GetDefaultCursor,(void),(),return) SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetDesktopDisplayMode,(SDL_DisplayID a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetDirect3D9AdapterIndex,(SDL_DisplayID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetDisplayBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) SDL_DYNAPI_PROC(float,SDL_GetDisplayContentScale,(SDL_DisplayID a),(a),return) SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForPoint,(const SDL_Point *a),(a),return) SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForRect,(const SDL_Rect *a),(a),return) SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForWindow,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(SDL_DisplayID a),(a),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetDisplayProperties,(SDL_DisplayID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetDisplayUsableBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) SDL_DYNAPI_PROC(SDL_DisplayID*,SDL_GetDisplays,(int *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetError,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),return) SDL_DYNAPI_PROC(float,SDL_GetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_DisplayMode**,SDL_GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetGDKDefaultUser,(XUserHandle *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetGDKTaskQueue,(XTaskQueueHandle *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetGDKDefaultUser,(XUserHandle *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetGDKTaskQueue,(XTaskQueueHandle *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) SDL_DYNAPI_PROC(Sint16,SDL_GetGamepadAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) @@ -306,14 +306,14 @@ SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadProductForID,(SDL_JoystickID a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadProductVersion,(SDL_Gamepad *a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadProductVersionForID,(SDL_JoystickID a),(a),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGamepadProperties,(SDL_Gamepad *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetGamepadSensorData,(SDL_Gamepad *a, SDL_SensorType b, float *c, int d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetGamepadSensorData,(SDL_Gamepad *a, SDL_SensorType b, float *c, int d),(a,b,c,d),return) SDL_DYNAPI_PROC(float,SDL_GetGamepadSensorDataRate,(SDL_Gamepad *a, SDL_SensorType b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadSerial,(SDL_Gamepad *a),(a),return) SDL_DYNAPI_PROC(Uint64,SDL_GetGamepadSteamHandle,(SDL_Gamepad *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadStringForAxis,(SDL_GamepadAxis a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadStringForButton,(SDL_GamepadButton a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetGamepadStringForType,(SDL_GamepadType a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetGamepadTouchpadFinger,(SDL_Gamepad *a, int b, int c, Uint8 *d, float *e, float *f, float *g),(a,b,c,d,e,f,g),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetGamepadTouchpadFinger,(SDL_Gamepad *a, int b, int c, Uint8 *d, float *e, float *f, float *g),(a,b,c,d,e,f,g),return) SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadType,(SDL_Gamepad *a),(a),return) SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeForID,(SDL_JoystickID a),(a),return) SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeFromString,(const char *a),(a),return) @@ -323,7 +323,7 @@ SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetGamepads,(int *a),(a),return) SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetGlobalMouseState,(float *a, float *b),(a,b),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGlobalProperties,(void),(),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_GetHapticEffectStatus,(SDL_Haptic *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetHapticEffectStatus,(SDL_Haptic *a, int b),(a,b),return) SDL_DYNAPI_PROC(Uint32,SDL_GetHapticFeatures,(SDL_Haptic *a),(a),return) SDL_DYNAPI_PROC(SDL_Haptic*,SDL_GetHapticFromID,(SDL_HapticID a),(a),return) SDL_DYNAPI_PROC(SDL_HapticID,SDL_GetHapticID,(SDL_Haptic *a),(a),return) @@ -337,7 +337,7 @@ SDL_DYNAPI_PROC(Sint64,SDL_GetIOSize,(SDL_IOStream *a),(a),return) SDL_DYNAPI_PROC(SDL_IOStatus,SDL_GetIOStatus,(SDL_IOStream *a),(a),return) SDL_DYNAPI_PROC(Sint16,SDL_GetJoystickAxis,(SDL_Joystick *a, int b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetJoystickAxisInitialState,(SDL_Joystick *a, int b, Sint16 *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetJoystickBall,(SDL_Joystick *a, int b, int *c, int *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetJoystickBall,(SDL_Joystick *a, int b, int *c, int *d),(a,b,c,d),return) SDL_DYNAPI_PROC(Uint8,SDL_GetJoystickButton,(SDL_Joystick *a, int b),(a,b),return) SDL_DYNAPI_PROC(SDL_JoystickConnectionState,SDL_GetJoystickConnectionState,(SDL_Joystick *a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickFirmwareVersion,(SDL_Joystick *a),(a),return) @@ -375,7 +375,7 @@ SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return) SDL_DYNAPI_PROC(SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return) SDL_DYNAPI_PROC(void,SDL_GetLogOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),) SDL_DYNAPI_PROC(SDL_LogPriority,SDL_GetLogPriority,(int a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetMasksForPixelFormat,(SDL_PixelFormat a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetMasksForPixelFormat,(SDL_PixelFormat a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffects,(SDL_Haptic *a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffectsPlaying,(SDL_Haptic *a),(a),return) SDL_DYNAPI_PROC(void,SDL_GetMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),) @@ -399,7 +399,7 @@ SDL_DYNAPI_PROC(int,SDL_GetNumRenderDrivers,(void),(),return) SDL_DYNAPI_PROC(int,SDL_GetNumVideoDrivers,(void),(),return) SDL_DYNAPI_PROC(Sint64,SDL_GetNumberProperty,(SDL_PropertiesID a, const char *b, Sint64 c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_GetOriginalMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),) -SDL_DYNAPI_PROC(int,SDL_GetPathInfo,(const char *a, SDL_PathInfo *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetPathInfo,(const char *a, SDL_PathInfo *b),(a,b),return) SDL_DYNAPI_PROC(Uint64,SDL_GetPerformanceCounter,(void),(),return) SDL_DYNAPI_PROC(Uint64,SDL_GetPerformanceFrequency,(void),(),return) SDL_DYNAPI_PROC(const SDL_PixelFormatDetails*,SDL_GetPixelFormatDetails,(SDL_PixelFormat a),(a),return) @@ -423,25 +423,25 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_GetRectEnclosingPoints,(const SDL_Point *a, int b, SDL_DYNAPI_PROC(SDL_bool,SDL_GetRectEnclosingPointsFloat,(const SDL_FPoint *a, int b, const SDL_FRect *c, SDL_FRect *d),(a,b,c,d),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetRectIntersection,(const SDL_Rect *a, const SDL_Rect *b, SDL_Rect *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetRectIntersectionFloat,(const SDL_FRect *a, const SDL_FRect *b, SDL_FRect *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetRectUnion,(const SDL_Rect *a, const SDL_Rect *b, SDL_Rect *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetRectUnionFloat,(const SDL_FRect *a, const SDL_FRect *b, SDL_FRect *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRectUnion,(const SDL_Rect *a, const SDL_Rect *b, SDL_Rect *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRectUnionFloat,(const SDL_FRect *a, const SDL_FRect *b, SDL_FRect *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetRelativeMouseState,(float *a, float *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderClipRect,(SDL_Renderer *a, SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderColorScale,(SDL_Renderer *a, float *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderDrawColorFloat,(SDL_Renderer *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderClipRect,(SDL_Renderer *a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderColorScale,(SDL_Renderer *a, float *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderDrawColorFloat,(SDL_Renderer *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(const char*,SDL_GetRenderDriver,(int a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, int *b, int *c, SDL_RendererLogicalPresentation *d, SDL_ScaleMode *e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderLogicalPresentationRect,(SDL_Renderer *a, SDL_FRect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, int *b, int *c, SDL_RendererLogicalPresentation *d, SDL_ScaleMode *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderLogicalPresentationRect,(SDL_Renderer *a, SDL_FRect *b),(a,b),return) SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalCommandEncoder,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalLayer,(SDL_Renderer *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderSafeArea,(SDL_Renderer *a, SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderScale,(SDL_Renderer *a, float *b, float *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderOutputSize,(SDL_Renderer *a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderSafeArea,(SDL_Renderer *a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderScale,(SDL_Renderer *a, float *b, float *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Texture*,SDL_GetRenderTarget,(SDL_Renderer *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetRenderViewport,(SDL_Renderer *a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderVSync,(SDL_Renderer *a, int *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetRenderViewport,(SDL_Renderer *a, SDL_Rect *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_GetRenderWindow,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRenderer,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_Renderer*,SDL_GetRendererFromTexture,(SDL_Texture *a),(a),return) @@ -453,7 +453,7 @@ SDL_DYNAPI_PROC(SDL_Scancode,SDL_GetScancodeFromKey,(SDL_Keycode a, SDL_Keymod * SDL_DYNAPI_PROC(SDL_Scancode,SDL_GetScancodeFromName,(const char *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetScancodeName,(SDL_Scancode a),(a),return) SDL_DYNAPI_PROC(Uint32,SDL_GetSemaphoreValue,(SDL_Semaphore *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetSensorData,(SDL_Sensor *a, float *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetSensorData,(SDL_Sensor *a, float *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Sensor*,SDL_GetSensorFromID,(SDL_SensorID a),(a),return) SDL_DYNAPI_PROC(SDL_SensorID,SDL_GetSensorID,(SDL_Sensor *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetSensorName,(SDL_Sensor *a),(a),return) @@ -465,15 +465,15 @@ SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorType,(SDL_Sensor *a),(a),return) SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorTypeForID,(SDL_SensorID a),(a),return) SDL_DYNAPI_PROC(SDL_SensorID*,SDL_GetSensors,(int *a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetSilenceValueForFormat,(SDL_AudioFormat a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetStorageFileSize,(SDL_Storage *a, const char *b, Uint64 *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetStoragePathInfo,(SDL_Storage *a, const char *b, SDL_PathInfo *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetStorageFileSize,(SDL_Storage *a, const char *b, Uint64 *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetStoragePathInfo,(SDL_Storage *a, const char *b, SDL_PathInfo *c),(a,b,c),return) SDL_DYNAPI_PROC(Uint64,SDL_GetStorageSpaceRemaining,(SDL_Storage *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetSurfaceAlphaMod,(SDL_Surface *a, Uint8 *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetSurfaceClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorKey,(SDL_Surface *a, Uint32 *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetSurfaceColorMod,(SDL_Surface *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetSurfaceAlphaMod,(SDL_Surface *a, Uint8 *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetSurfaceClipRect,(SDL_Surface *a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetSurfaceColorKey,(SDL_Surface *a, Uint32 *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetSurfaceColorMod,(SDL_Surface *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return) SDL_DYNAPI_PROC(SDL_Colorspace,SDL_GetSurfaceColorspace,(SDL_Surface *a),(a),return) SDL_DYNAPI_PROC(SDL_Surface**,SDL_GetSurfaceImages,(SDL_Surface *a, int *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Palette*,SDL_GetSurfacePalette,(SDL_Surface *a),(a),return) @@ -481,15 +481,15 @@ SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSurfaceProperties,(SDL_Surface *a),(a),r SDL_DYNAPI_PROC(int,SDL_GetSystemRAM,(void),(),return) SDL_DYNAPI_PROC(SDL_SystemTheme,SDL_GetSystemTheme,(void),(),return) SDL_DYNAPI_PROC(void*,SDL_GetTLS,(SDL_TLSID *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetTextInputArea,(SDL_Window *a, SDL_Rect *b, int *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetTextureAlphaMod,(SDL_Texture *a, Uint8 *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetTextureAlphaModFloat,(SDL_Texture *a, float *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetTextureColorMod,(SDL_Texture *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_GetTextureColorModFloat,(SDL_Texture *a, float *b, float *c, float *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextInputArea,(SDL_Window *a, SDL_Rect *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextureAlphaMod,(SDL_Texture *a, Uint8 *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextureAlphaModFloat,(SDL_Texture *a, float *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextureColorMod,(SDL_Texture *a, Uint8 *b, Uint8 *c, Uint8 *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextureColorModFloat,(SDL_Texture *a, float *b, float *c, float *d),(a,b,c,d),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetTextureProperties,(SDL_Texture *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetTextureSize,(SDL_Texture *a, float *b, float *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetTextureSize,(SDL_Texture *a, float *b, float *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_ThreadID,SDL_GetThreadID,(SDL_Thread *a),(a),return) SDL_DYNAPI_PROC(const char*,SDL_GetThreadName,(SDL_Thread *a),(a),return) SDL_DYNAPI_PROC(Uint64,SDL_GetTicks,(void),(),return) @@ -503,8 +503,8 @@ SDL_DYNAPI_PROC(int,SDL_GetVersion,(void),(),return) SDL_DYNAPI_PROC(const char*,SDL_GetVideoDriver,(int a),(a),return) SDL_DYNAPI_PROC(SDL_WinRT_DeviceFamily,SDL_GetWinRTDeviceFamily,(void),(),return) SDL_DYNAPI_PROC(const char*,SDL_GetWinRTFSPath,(SDL_WinRT_Path a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowAspectRatio,(SDL_Window *a, float *b, float *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowAspectRatio,(SDL_Window *a, float *b, float *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowBordersSize,(SDL_Window *a, int *b, int *c, int *d, int *e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(float,SDL_GetWindowDisplayScale,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_WindowFlags,SDL_GetWindowFlags,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowFromEvent,(const SDL_Event *a),(a),return) @@ -513,22 +513,22 @@ SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetWindowFullscreenMode,(SDL_Window * SDL_DYNAPI_PROC(void*,SDL_GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return) SDL_DYNAPI_PROC(SDL_WindowID,SDL_GetWindowID,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowKeyboardGrab,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowMaximumSize,(SDL_Window *a, int *b, int *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowMinimumSize,(SDL_Window *a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowMaximumSize,(SDL_Window *a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowMinimumSize,(SDL_Window *a, int *b, int *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowMouseGrab,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(const SDL_Rect*,SDL_GetWindowMouseRect,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(float,SDL_GetWindowOpacity,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowParent,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(float,SDL_GetWindowPixelDensity,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_PixelFormat,SDL_GetWindowPixelFormat,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowPosition,(SDL_Window *a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowPosition,(SDL_Window *a, int *b, int *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetWindowProperties,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowRelativeMouseMode,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowSafeArea,(SDL_Window *a, SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowSize,(SDL_Window *a, int *b, int *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowSizeInPixels,(SDL_Window *a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowSafeArea,(SDL_Window *a, SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowSize,(SDL_Window *a, int *b, int *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowSizeInPixels,(SDL_Window *a, int *b, int *c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_GetWindowSurface,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_GetWindowSurfaceVSync,(SDL_Window *a, int *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowSurfaceVSync,(SDL_Window *a, int *b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetWindowTitle,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_Window**,SDL_GetWindows,(int *a),(a),return) SDL_DYNAPI_PROC(char **,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return) @@ -562,16 +562,16 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE3,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE41,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_HasSSE42,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_HasScreenKeyboardSupport,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_HideCursor,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_HideWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_HideCursor,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_HideWindow,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_IOStream*,SDL_IOFromConstMem,(const void *a, size_t b),(a,b),return) SDL_DYNAPI_PROC(SDL_IOStream*,SDL_IOFromDynamicMem,(void),(),return) SDL_DYNAPI_PROC(SDL_IOStream*,SDL_IOFromFile,(const char *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(SDL_IOStream*,SDL_IOFromMem,(void *a, size_t b),(a,b),return) SDL_DYNAPI_PROC(size_t,SDL_IOvprintf,(SDL_IOStream *a, SDL_PRINTF_FORMAT_STRING const char *b, va_list c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_Init,(SDL_InitFlags a),(a),return) -SDL_DYNAPI_PROC(int,SDL_InitHapticRumble,(SDL_Haptic *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_InitSubSystem,(SDL_InitFlags a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_Init,(SDL_InitFlags a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_InitHapticRumble,(SDL_Haptic *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_InitSubSystem,(SDL_InitFlags a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_IsAndroidTV,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_IsChromebook,(void),(),return) SDL_DYNAPI_PROC(SDL_bool,SDL_IsDeXMode,(void),(),return) @@ -588,31 +588,31 @@ SDL_DYNAPI_PROC(void*,SDL_LoadFile,(const char *a, size_t *b),(a,b),return) SDL_DYNAPI_PROC(void*,SDL_LoadFile_IO,(SDL_IOStream *a, size_t *b, SDL_bool c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_LoadFunction,(void *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(void*,SDL_LoadObject,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_LoadWAV,(const char *a, SDL_AudioSpec *b, Uint8 **c, Uint32 *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_LoadWAV_IO,(SDL_IOStream *a, SDL_bool b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_LockAudioStream,(SDL_AudioStream *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_LoadWAV,(const char *a, SDL_AudioSpec *b, Uint8 **c, Uint32 *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_LoadWAV_IO,(SDL_IOStream *a, SDL_bool b, SDL_AudioSpec *c, Uint8 **d, Uint32 *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_LockAudioStream,(SDL_AudioStream *a),(a),return) SDL_DYNAPI_PROC(void,SDL_LockJoysticks,(void),(),) SDL_DYNAPI_PROC(void,SDL_LockMutex,(SDL_Mutex *a),(a),) -SDL_DYNAPI_PROC(int,SDL_LockProperties,(SDL_PropertiesID a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_LockProperties,(SDL_PropertiesID a),(a),return) SDL_DYNAPI_PROC(void,SDL_LockRWLockForReading,(SDL_RWLock *a),(a),) SDL_DYNAPI_PROC(void,SDL_LockRWLockForWriting,(SDL_RWLock *a),(a),) SDL_DYNAPI_PROC(void,SDL_LockSpinlock,(SDL_SpinLock *a),(a),) -SDL_DYNAPI_PROC(int,SDL_LockSurface,(SDL_Surface *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_LockTexture,(SDL_Texture *a, const SDL_Rect *b, void **c, int *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_LockTextureToSurface,(SDL_Texture *a, const SDL_Rect *b, SDL_Surface **c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_LockSurface,(SDL_Surface *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_LockTexture,(SDL_Texture *a, const SDL_Rect *b, void **c, int *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_LockTextureToSurface,(SDL_Texture *a, const SDL_Rect *b, SDL_Surface **c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_LogMessageV,(int a, SDL_LogPriority b, SDL_PRINTF_FORMAT_STRING const char *c, va_list d),(a,b,c,d),) SDL_DYNAPI_PROC(Uint32,SDL_MapRGB,(const SDL_PixelFormatDetails *a, const SDL_Palette *b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(Uint32,SDL_MapRGBA,(const SDL_PixelFormatDetails *a, const SDL_Palette *b, Uint8 c, Uint8 d, Uint8 e, Uint8 f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(Uint32,SDL_MapSurfaceRGB,(SDL_Surface *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) SDL_DYNAPI_PROC(Uint32,SDL_MapSurfaceRGBA,(SDL_Surface *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_MaximizeWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_MaximizeWindow,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(void,SDL_MemoryBarrierAcquireFunction,(void),(),) SDL_DYNAPI_PROC(void,SDL_MemoryBarrierReleaseFunction,(void),(),) SDL_DYNAPI_PROC(SDL_MetalView,SDL_Metal_CreateView,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(void,SDL_Metal_DestroyView,(SDL_MetalView a),(a),) SDL_DYNAPI_PROC(void*,SDL_Metal_GetLayer,(SDL_MetalView a),(a),return) -SDL_DYNAPI_PROC(int,SDL_MinimizeWindow,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_MixAudio,(Uint8 *a, const Uint8 *b, SDL_AudioFormat c, Uint32 d, float e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_MinimizeWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_MixAudio,(Uint8 *a, const Uint8 *b, SDL_AudioFormat c, Uint32 d, float e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(void,SDL_OnApplicationDidChangeStatusBarOrientation,(void),(),) SDL_DYNAPI_PROC(void,SDL_OnApplicationDidEnterBackground,(void),(),) SDL_DYNAPI_PROC(void,SDL_OnApplicationDidEnterForeground,(void),(),) @@ -633,23 +633,23 @@ SDL_DYNAPI_PROC(SDL_Joystick*,SDL_OpenJoystick,(SDL_JoystickID a),(a),return) SDL_DYNAPI_PROC(SDL_Sensor*,SDL_OpenSensor,(SDL_SensorID a),(a),return) SDL_DYNAPI_PROC(SDL_Storage*,SDL_OpenStorage,(const SDL_StorageInterface *a, void *b),(a,b),return) SDL_DYNAPI_PROC(SDL_Storage*,SDL_OpenTitleStorage,(const char *a, SDL_PropertiesID b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_OpenURL,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_OpenURL,(const char *a),(a),return) SDL_DYNAPI_PROC(SDL_Storage*,SDL_OpenUserStorage,(const char *a, const char *b, SDL_PropertiesID c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_OutOfMemory,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_PauseAudioDevice,(SDL_AudioDeviceID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_PauseAudioStreamDevice,(SDL_AudioStream *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_PauseHaptic,(SDL_Haptic *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_OutOfMemory,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PauseAudioDevice,(SDL_AudioDeviceID a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PauseAudioStreamDevice,(SDL_AudioStream *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PauseHaptic,(SDL_Haptic *a),(a),return) SDL_DYNAPI_PROC(int,SDL_PeepEvents,(SDL_Event *a, int b, SDL_EventAction c, Uint32 d, Uint32 e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_PlayHapticRumble,(SDL_Haptic *a, float b, Uint32 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PlayHapticRumble,(SDL_Haptic *a, float b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_PollEvent,(SDL_Event *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_PremultiplyAlpha,(int a, int b, SDL_PixelFormat c, const void *d, int e, SDL_PixelFormat f, void *g, int h, SDL_bool i),(a,b,c,d,e,f,g,h,i),return) -SDL_DYNAPI_PROC(int,SDL_PremultiplySurfaceAlpha,(SDL_Surface *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PremultiplyAlpha,(int a, int b, SDL_PixelFormat c, const void *d, int e, SDL_PixelFormat f, void *g, int h, SDL_bool i),(a,b,c,d,e,f,g,h,i),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PremultiplySurfaceAlpha,(SDL_Surface *a, SDL_bool b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_PumpEvents,(void),(),) -SDL_DYNAPI_PROC(int,SDL_PushEvent,(SDL_Event *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_PutAudioStreamData,(SDL_AudioStream *a, const void *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PushEvent,(SDL_Event *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_PutAudioStreamData,(SDL_AudioStream *a, const void *b, int c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_Quit,(void),(),) SDL_DYNAPI_PROC(void,SDL_QuitSubSystem,(SDL_InitFlags a),(a),) -SDL_DYNAPI_PROC(int,SDL_RaiseWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RaiseWindow,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(size_t,SDL_ReadIO,(SDL_IOStream *a, void *b, size_t c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS16BE,(SDL_IOStream *a, Sint16 *b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS16LE,(SDL_IOStream *a, Sint16 *b),(a,b),return) @@ -658,9 +658,9 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS32LE,(SDL_IOStream *a, Sint32 *b),(a,b),return SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS64BE,(SDL_IOStream *a, Sint64 *b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS64LE,(SDL_IOStream *a, Sint64 *b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadS8,(SDL_IOStream *a, Sint8 *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_ReadStorageFile,(SDL_Storage *a, const char *b, void *c, Uint64 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_ReadSurfacePixel,(SDL_Surface *a, int b, int c, Uint8 *d, Uint8 *e, Uint8 *f, Uint8 *g),(a,b,c,d,e,f,g),return) -SDL_DYNAPI_PROC(int,SDL_ReadSurfacePixelFloat,(SDL_Surface *a, int b, int c, float *d, float *e, float *f, float *g),(a,b,c,d,e,f,g),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ReadStorageFile,(SDL_Storage *a, const char *b, void *c, Uint64 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ReadSurfacePixel,(SDL_Surface *a, int b, int c, Uint8 *d, Uint8 *e, Uint8 *f, Uint8 *g),(a,b,c,d,e,f,g),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ReadSurfacePixelFloat,(SDL_Surface *a, int b, int c, float *d, float *e, float *f, float *g),(a,b,c,d,e,f,g),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU16BE,(SDL_IOStream *a, Uint16 *b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU16LE,(SDL_IOStream *a, Uint16 *b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU32BE,(SDL_IOStream *a, Uint32 *b),(a,b),return) @@ -668,209 +668,209 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU32LE,(SDL_IOStream *a, Uint32 *b),(a,b),return SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU64BE,(SDL_IOStream *a, Uint64 *b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU64LE,(SDL_IOStream *a, Uint64 *b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ReadU8,(SDL_IOStream *a, Uint8 *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_RegisterApp,(const char *a, Uint32 b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RegisterApp,(const char *a, Uint32 b, void *c),(a,b,c),return) SDL_DYNAPI_PROC(Uint32,SDL_RegisterEvents,(int a),(a),return) -SDL_DYNAPI_PROC(int,SDL_ReleaseCameraFrame,(SDL_Camera *a, SDL_Surface *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_ReloadGamepadMappings,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_RemovePath,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_RemoveStoragePath,(SDL_Storage *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(void,SDL_ReleaseCameraFrame,(SDL_Camera *a, SDL_Surface *b),(a,b),) +SDL_DYNAPI_PROC(SDL_bool,SDL_ReloadGamepadMappings,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RemovePath,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RemoveStoragePath,(SDL_Storage *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_RemoveSurfaceAlternateImages,(SDL_Surface *a),(a),) -SDL_DYNAPI_PROC(int,SDL_RemoveTimer,(SDL_TimerID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_RenamePath,(const char *a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_RenameStoragePath,(SDL_Storage *a, const char *b, const char *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_RenderClear,(SDL_Renderer *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RemoveTimer,(SDL_TimerID a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenamePath,(const char *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenameStoragePath,(SDL_Storage *a, const char *b, const char *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderClear,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_RenderClipEnabled,(SDL_Renderer *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_RenderCoordinatesFromWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_RenderCoordinatesToWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_RenderFillRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_RenderFillRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_RenderGeometry,(SDL_Renderer *a, SDL_Texture *b, const SDL_Vertex *c, int d, const int *e, int f),(a,b,c,d,e,f),return) -SDL_DYNAPI_PROC(int,SDL_RenderGeometryRaw,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const SDL_FColor *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return) -SDL_DYNAPI_PROC(int,SDL_RenderLine,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_RenderLines,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_RenderPoint,(SDL_Renderer *a, float b, float c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_RenderPoints,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_RenderPresent,(SDL_Renderer *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderCoordinatesFromWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderCoordinatesToWindow,(SDL_Renderer *a, float b, float c, float *d, float *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderFillRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderFillRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGeometry,(SDL_Renderer *a, SDL_Texture *b, const SDL_Vertex *c, int d, const int *e, int f),(a,b,c,d,e,f),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGeometryRaw,(SDL_Renderer *a, SDL_Texture *b, const float *c, int d, const SDL_FColor *e, int f, const float *g, int h, int i, const void *j, int k, int l),(a,b,c,d,e,f,g,h,i,j,k,l),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderLine,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderLines,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderPoint,(SDL_Renderer *a, float b, float c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderPoints,(SDL_Renderer *a, const SDL_FPoint *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderPresent,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_RenderReadPixels,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_RenderRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_RenderRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_RenderTexture,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, const SDL_FRect *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_RenderTexture9Grid,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, float d, float e, float f, float g, float h, const SDL_FRect *i),(a,b,c,d,e,f,g,h,i),return) -SDL_DYNAPI_PROC(int,SDL_RenderTextureRotated,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, const SDL_FRect *d, const double e, const SDL_FPoint *f, const SDL_FlipMode g),(a,b,c,d,e,f,g),return) -SDL_DYNAPI_PROC(int,SDL_RenderTextureTiled,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, float d, const SDL_FRect *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderRect,(SDL_Renderer *a, const SDL_FRect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderRects,(SDL_Renderer *a, const SDL_FRect *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderTexture,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, const SDL_FRect *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderTexture9Grid,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, float d, float e, float f, float g, float h, const SDL_FRect *i),(a,b,c,d,e,f,g,h,i),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderTextureRotated,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, const SDL_FRect *d, const double e, const SDL_FPoint *f, const SDL_FlipMode g),(a,b,c,d,e,f,g),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RenderTextureTiled,(SDL_Renderer *a, SDL_Texture *b, const SDL_FRect *c, float d, const SDL_FRect *e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(SDL_bool,SDL_RenderViewportSet,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(SDL_AssertState,SDL_ReportAssertion,(SDL_AssertData *a, const char *b, const char *c, int d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_RequestAndroidPermission,(const char *a, SDL_RequestAndroidPermissionCallback b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RequestAndroidPermission,(const char *a, SDL_RequestAndroidPermissionCallback b, void *c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_ResetAssertionReport,(void),(),) -SDL_DYNAPI_PROC(int,SDL_ResetHint,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ResetHint,(const char *a),(a),return) SDL_DYNAPI_PROC(void,SDL_ResetHints,(void),(),) SDL_DYNAPI_PROC(void,SDL_ResetKeyboard,(void),(),) SDL_DYNAPI_PROC(void,SDL_ResetLogPriorities,(void),(),) -SDL_DYNAPI_PROC(int,SDL_RestoreWindow,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_ResumeAudioDevice,(SDL_AudioDeviceID a),(a),return) -SDL_DYNAPI_PROC(int,SDL_ResumeAudioStreamDevice,(SDL_AudioStream *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_ResumeHaptic,(SDL_Haptic *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_RumbleGamepad,(SDL_Gamepad *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_RumbleGamepadTriggers,(SDL_Gamepad *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_RumbleJoystick,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_RumbleJoystickTriggers,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RestoreWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ResumeAudioDevice,(SDL_AudioDeviceID a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ResumeAudioStreamDevice,(SDL_AudioStream *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ResumeHaptic,(SDL_Haptic *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RumbleGamepad,(SDL_Gamepad *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RumbleGamepadTriggers,(SDL_Gamepad *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RumbleJoystick,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RumbleJoystickTriggers,(SDL_Joystick *a, Uint16 b, Uint16 c, Uint32 d),(a,b,c,d),return) SDL_DYNAPI_PROC(int,SDL_RunApp,(int a, char *b[], SDL_main_func c, void *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_RunHapticEffect,(SDL_Haptic *a, int b, Uint32 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SaveBMP,(SDL_Surface *a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SaveBMP_IO,(SDL_Surface *a, SDL_IOStream *b, SDL_bool c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_RunHapticEffect,(SDL_Haptic *a, int b, Uint32 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SaveBMP,(SDL_Surface *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SaveBMP_IO,(SDL_Surface *a, SDL_IOStream *b, SDL_bool c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_Surface*,SDL_ScaleSurface,(SDL_Surface *a, int b, int c, SDL_ScaleMode d),(a,b,c,d),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ScreenKeyboardShown,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_ScreenSaverEnabled,(void),(),return) SDL_DYNAPI_PROC(Sint64,SDL_SeekIO,(SDL_IOStream *a, Sint64 b, SDL_IOWhence c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_SendAndroidBackButton,(void),(),) -SDL_DYNAPI_PROC(int,SDL_SendAndroidMessage,(Uint32 a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SendGamepadEffect,(SDL_Gamepad *a, const void *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SendJoystickEffect,(SDL_Joystick *a, const void *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SendJoystickVirtualSensorData,(SDL_Joystick *a, SDL_SensorType b, Uint64 c, const float *d, int e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_SetAppMetadata,(const char *a, const char *b, const char *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetAppMetadataProperty,(const char *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SendAndroidMessage,(Uint32 a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SendGamepadEffect,(SDL_Gamepad *a, const void *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SendJoystickEffect,(SDL_Joystick *a, const void *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SendJoystickVirtualSensorData,(SDL_Joystick *a, SDL_SensorType b, Uint64 c, const float *d, int e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAppMetadata,(const char *a, const char *b, const char *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAppMetadataProperty,(const char *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_SetAssertionHandler,(SDL_AssertionHandler a, void *b),(a,b),) -SDL_DYNAPI_PROC(int,SDL_SetAudioDeviceGain,(SDL_AudioDeviceID a, float b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioPostmixCallback,(SDL_AudioDeviceID a, SDL_AudioPostmixCallback b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioStreamFormat,(SDL_AudioStream *a, const SDL_AudioSpec *b, const SDL_AudioSpec *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioStreamFrequencyRatio,(SDL_AudioStream *a, float b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioStreamGain,(SDL_AudioStream *a, float b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioStreamGetCallback,(SDL_AudioStream *a, SDL_AudioStreamCallback b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioStreamInputChannelMap,(SDL_AudioStream *a, const int *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioStreamOutputChannelMap,(SDL_AudioStream *a, const int *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetAudioStreamPutCallback,(SDL_AudioStream *a, SDL_AudioStreamCallback b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetBooleanProperty,(SDL_PropertiesID a, const char *b, SDL_bool c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetClipboardData,(SDL_ClipboardDataCallback a, SDL_ClipboardCleanupCallback b, void *c, const char **d, size_t e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_SetClipboardText,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SetCursor,(SDL_Cursor *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioDeviceGain,(SDL_AudioDeviceID a, float b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioPostmixCallback,(SDL_AudioDeviceID a, SDL_AudioPostmixCallback b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioStreamFormat,(SDL_AudioStream *a, const SDL_AudioSpec *b, const SDL_AudioSpec *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioStreamFrequencyRatio,(SDL_AudioStream *a, float b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioStreamGain,(SDL_AudioStream *a, float b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioStreamGetCallback,(SDL_AudioStream *a, SDL_AudioStreamCallback b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioStreamInputChannelMap,(SDL_AudioStream *a, const int *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioStreamOutputChannelMap,(SDL_AudioStream *a, const int *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetAudioStreamPutCallback,(SDL_AudioStream *a, SDL_AudioStreamCallback b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetBooleanProperty,(SDL_PropertiesID a, const char *b, SDL_bool c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetClipboardData,(SDL_ClipboardDataCallback a, SDL_ClipboardCleanupCallback b, void *c, const char **d, size_t e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetClipboardText,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetCursor,(SDL_Cursor *a),(a),return) SDL_DYNAPI_PROC(void,SDL_SetEventEnabled,(Uint32 a, SDL_bool b),(a,b),) SDL_DYNAPI_PROC(void,SDL_SetEventFilter,(SDL_EventFilter a, void *b),(a,b),) -SDL_DYNAPI_PROC(int,SDL_SetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_SetGamepadEventsEnabled,(SDL_bool a),(a),) -SDL_DYNAPI_PROC(int,SDL_SetGamepadLED,(SDL_Gamepad *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_SetGamepadMapping,(SDL_JoystickID a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetGamepadPlayerIndex,(SDL_Gamepad *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetGamepadSensorEnabled,(SDL_Gamepad *a, SDL_SensorType b, SDL_bool c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetHapticAutocenter,(SDL_Haptic *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetHapticGain,(SDL_Haptic *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetHint,(const char *a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetHintWithPriority,(const char *a, const char *b, SDL_HintPriority c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetGamepadLED,(SDL_Gamepad *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetGamepadMapping,(SDL_JoystickID a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetGamepadPlayerIndex,(SDL_Gamepad *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetGamepadSensorEnabled,(SDL_Gamepad *a, SDL_SensorType b, SDL_bool c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetHapticAutocenter,(SDL_Haptic *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetHapticGain,(SDL_Haptic *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetHint,(const char *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetHintWithPriority,(const char *a, const char *b, SDL_HintPriority c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_SetJoystickEventsEnabled,(SDL_bool a),(a),) -SDL_DYNAPI_PROC(int,SDL_SetJoystickLED,(SDL_Joystick *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_SetJoystickPlayerIndex,(SDL_Joystick *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetJoystickVirtualAxis,(SDL_Joystick *a, int b, Sint16 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetJoystickVirtualBall,(SDL_Joystick *a, int b, Sint16 c, Sint16 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_SetJoystickVirtualButton,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetJoystickVirtualHat,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetJoystickVirtualTouchpad,(SDL_Joystick *a, int b, int c, Uint8 d, float e, float f, float g),(a,b,c,d,e,f,g),return) -SDL_DYNAPI_PROC(int,SDL_SetLinuxThreadPriority,(Sint64 a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetLinuxThreadPriorityAndPolicy,(Sint64 a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickLED,(SDL_Joystick *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickPlayerIndex,(SDL_Joystick *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualAxis,(SDL_Joystick *a, int b, Sint16 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualBall,(SDL_Joystick *a, int b, Sint16 c, Sint16 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualButton,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualHat,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetJoystickVirtualTouchpad,(SDL_Joystick *a, int b, int c, Uint8 d, float e, float f, float g),(a,b,c,d,e,f,g),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetLinuxThreadPriority,(Sint64 a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetLinuxThreadPriorityAndPolicy,(Sint64 a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_SetLogOutputFunction,(SDL_LogOutputFunction a, void *b),(a,b),) SDL_DYNAPI_PROC(void,SDL_SetLogPriorities,(SDL_LogPriority a),(a),) SDL_DYNAPI_PROC(void,SDL_SetLogPriority,(int a, SDL_LogPriority b),(a,b),) -SDL_DYNAPI_PROC(int,SDL_SetLogPriorityPrefix,(SDL_LogPriority a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetLogPriorityPrefix,(SDL_LogPriority a, const char *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_SetMainReady,(void),(),) -SDL_DYNAPI_PROC(int,SDL_SetMemoryFunctions,(SDL_malloc_func a, SDL_calloc_func b, SDL_realloc_func c, SDL_free_func d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetMemoryFunctions,(SDL_malloc_func a, SDL_calloc_func b, SDL_realloc_func c, SDL_free_func d),(a,b,c,d),return) SDL_DYNAPI_PROC(void,SDL_SetModState,(SDL_Keymod a),(a),) -SDL_DYNAPI_PROC(int,SDL_SetNumberProperty,(SDL_PropertiesID a, const char *b, Sint64 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetPaletteColors,(SDL_Palette *a, const SDL_Color *b, int c, int d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_SetPointerProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetPointerPropertyWithCleanup,(SDL_PropertiesID a, const char *b, void *c, SDL_CleanupPropertyCallback d, void *e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_SetPrimarySelectionText,(const char *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderClipRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderColorScale,(SDL_Renderer *a, float b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColor,(SDL_Renderer *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderDrawColorFloat,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, int b, int c, SDL_RendererLogicalPresentation d, SDL_ScaleMode e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderScale,(SDL_Renderer *a, float b, float c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderTarget,(SDL_Renderer *a, SDL_Texture *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderVSync,(SDL_Renderer *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetRenderViewport,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetScancodeName,(SDL_Scancode a, const char *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfaceAlphaMod,(SDL_Surface *a, Uint8 b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetNumberProperty,(SDL_PropertiesID a, const char *b, Sint64 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetPaletteColors,(SDL_Palette *a, const SDL_Color *b, int c, int d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetPointerProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetPointerPropertyWithCleanup,(SDL_PropertiesID a, const char *b, void *c, SDL_CleanupPropertyCallback d, void *e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetPrimarySelectionText,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderClipRect,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderColorScale,(SDL_Renderer *a, float b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderDrawColor,(SDL_Renderer *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderDrawColorFloat,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, int b, int c, SDL_RendererLogicalPresentation d, SDL_ScaleMode e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderScale,(SDL_Renderer *a, float b, float c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderTarget,(SDL_Renderer *a, SDL_Texture *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderVSync,(SDL_Renderer *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetRenderViewport,(SDL_Renderer *a, const SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetScancodeName,(SDL_Scancode a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetStringProperty,(SDL_PropertiesID a, const char *b, const char *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfaceAlphaMod,(SDL_Surface *a, Uint8 b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfaceBlendMode,(SDL_Surface *a, SDL_BlendMode b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfaceClipRect,(SDL_Surface *a, const SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorKey,(SDL_Surface *a, SDL_bool b, Uint32 c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorMod,(SDL_Surface *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfaceColorspace,(SDL_Surface *a, SDL_Colorspace b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfacePalette,(SDL_Surface *a, SDL_Palette *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetSurfaceRLE,(SDL_Surface *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetTLS,(SDL_TLSID *a, const void *b, SDL_TLSDestructorCallback c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetTextInputArea,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetTextureAlphaMod,(SDL_Texture *a, Uint8 b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetTextureAlphaModFloat,(SDL_Texture *a, float b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetTextureColorMod,(SDL_Texture *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_SetTextureColorModFloat,(SDL_Texture *a, float b, float c, float d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_SetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetThreadPriority,(SDL_ThreadPriority a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowAlwaysOnTop,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowAspectRatio,(SDL_Window *a, float b, float c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowBordered,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowFocusable,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreen,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreenMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowHitTest,(SDL_Window *a, SDL_HitTest b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowKeyboardGrab,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowMaximumSize,(SDL_Window *a, int b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowMinimumSize,(SDL_Window *a, int b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowModalFor,(SDL_Window *a, SDL_Window *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowMouseGrab,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowMouseRect,(SDL_Window *a, const SDL_Rect *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowOpacity,(SDL_Window *a, float b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowPosition,(SDL_Window *a, int b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowRelativeMouseMode,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowShape,(SDL_Window *a, SDL_Surface *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowSize,(SDL_Window *a, int b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowSurfaceVSync,(SDL_Window *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_SetWindowTitle,(SDL_Window *a, const char *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfaceColorKey,(SDL_Surface *a, SDL_bool b, Uint32 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfaceColorMod,(SDL_Surface *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfaceColorspace,(SDL_Surface *a, SDL_Colorspace b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfacePalette,(SDL_Surface *a, SDL_Palette *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetSurfaceRLE,(SDL_Surface *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTLS,(SDL_TLSID *a, const void *b, SDL_TLSDestructorCallback c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTextInputArea,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTextureAlphaMod,(SDL_Texture *a, Uint8 b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTextureAlphaModFloat,(SDL_Texture *a, float b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTextureBlendMode,(SDL_Texture *a, SDL_BlendMode b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTextureColorMod,(SDL_Texture *a, Uint8 b, Uint8 c, Uint8 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTextureColorModFloat,(SDL_Texture *a, float b, float c, float d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetTextureScaleMode,(SDL_Texture *a, SDL_ScaleMode b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetThreadPriority,(SDL_ThreadPriority a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowAlwaysOnTop,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowAspectRatio,(SDL_Window *a, float b, float c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowBordered,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowFocusable,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowFullscreen,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowFullscreenMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowHitTest,(SDL_Window *a, SDL_HitTest b, void *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowKeyboardGrab,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowMaximumSize,(SDL_Window *a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowMinimumSize,(SDL_Window *a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowModalFor,(SDL_Window *a, SDL_Window *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowMouseGrab,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowMouseRect,(SDL_Window *a, const SDL_Rect *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowOpacity,(SDL_Window *a, float b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowPosition,(SDL_Window *a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowRelativeMouseMode,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowShape,(SDL_Window *a, SDL_Surface *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowSize,(SDL_Window *a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowSurfaceVSync,(SDL_Window *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetWindowTitle,(SDL_Window *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_SetWindowsMessageHook,(SDL_WindowsMessageHook a, void *b),(a,b),) SDL_DYNAPI_PROC(void,SDL_SetX11EventHook,(SDL_X11EventHook a, void *b),(a,b),) -SDL_DYNAPI_PROC(int,SDL_SetiOSAnimationCallback,(SDL_Window *a, int b, SDL_iOSAnimationCallback c, void *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SetiOSAnimationCallback,(SDL_Window *a, int b, SDL_iOSAnimationCallback c, void *d),(a,b,c,d),return) SDL_DYNAPI_PROC(void,SDL_SetiOSEventPump,(SDL_bool a),(a),) -SDL_DYNAPI_PROC(int,SDL_ShowAndroidToast,(const char *a, int b, int c, int d, int e),(a,b,c,d,e),return) -SDL_DYNAPI_PROC(int,SDL_ShowCursor,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_ShowMessageBox,(const SDL_MessageBoxData *a, int *b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ShowAndroidToast,(const char *a, int b, int c, int d, int e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ShowCursor,(void),(),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ShowMessageBox,(const SDL_MessageBoxData *a, int *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_ShowOpenFileDialog,(SDL_DialogFileCallback a, void *b, SDL_Window *c, const SDL_DialogFileFilter *d, int e, const char *f, SDL_bool g),(a,b,c,d,e,f,g),) SDL_DYNAPI_PROC(void,SDL_ShowOpenFolderDialog,(SDL_DialogFileCallback a, void *b, SDL_Window *c, const char *d, SDL_bool e),(a,b,c,d,e),) SDL_DYNAPI_PROC(void,SDL_ShowSaveFileDialog,(SDL_DialogFileCallback a, void *b, SDL_Window *c, const SDL_DialogFileFilter *d, int e, const char *f),(a,b,c,d,e,f),) -SDL_DYNAPI_PROC(int,SDL_ShowSimpleMessageBox,(SDL_MessageBoxFlags a, const char *b, const char *c, SDL_Window *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_ShowWindow,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_ShowWindowSystemMenu,(SDL_Window *a, int b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_SignalCondition,(SDL_Condition *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SignalSemaphore,(SDL_Semaphore *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_StartTextInput,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_StartTextInputWithProperties,(SDL_Window *a, SDL_PropertiesID b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ShowSimpleMessageBox,(SDL_MessageBoxFlags a, const char *b, const char *c, SDL_Window *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ShowWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_ShowWindowSystemMenu,(SDL_Window *a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(void,SDL_SignalCondition,(SDL_Condition *a),(a),) +SDL_DYNAPI_PROC(void,SDL_SignalSemaphore,(SDL_Semaphore *a),(a),) +SDL_DYNAPI_PROC(SDL_bool,SDL_StartTextInput,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_StartTextInputWithProperties,(SDL_Window *a, SDL_PropertiesID b),(a,b),return) SDL_DYNAPI_PROC(Uint32,SDL_StepUTF8,(const char **a, size_t *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_StopHapticEffect,(SDL_Haptic *a, int b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_StopHapticEffects,(SDL_Haptic *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_StopHapticRumble,(SDL_Haptic *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_StopTextInput,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_StopHapticEffect,(SDL_Haptic *a, int b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_StopHapticEffects,(SDL_Haptic *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_StopHapticRumble,(SDL_Haptic *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_StopTextInput,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_StorageReady,(SDL_Storage *a),(a),return) SDL_DYNAPI_PROC(SDL_GUID,SDL_StringToGUID,(const char *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_SurfaceHasAlternateImages,(SDL_Surface *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_SurfaceHasColorKey,(SDL_Surface *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_SurfaceHasRLE,(SDL_Surface *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_SyncWindow,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_SyncWindow,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(Sint64,SDL_TellIO,(SDL_IOStream *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_TextInputActive,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(SDL_Time,SDL_TimeFromWindows,(Uint32 a, Uint32 b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_TimeToDateTime,(SDL_Time a, SDL_DateTime *b, SDL_bool c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_TimeToDateTime,(SDL_Time a, SDL_DateTime *b, SDL_bool c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_TimeToWindows,(SDL_Time a, Uint32 *b, Uint32 *c),(a,b,c),) -SDL_DYNAPI_PROC(int,SDL_TryLockMutex,(SDL_Mutex *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_TryLockRWLockForReading,(SDL_RWLock *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_TryLockRWLockForWriting,(SDL_RWLock *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_TryLockMutex,(SDL_Mutex *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_TryLockRWLockForReading,(SDL_RWLock *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_TryLockRWLockForWriting,(SDL_RWLock *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_TryLockSpinlock,(SDL_SpinLock *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_TryWaitSemaphore,(SDL_Semaphore *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_TryWaitSemaphore,(SDL_Semaphore *a),(a),return) SDL_DYNAPI_PROC(char*,SDL_UCS4ToUTF8,(Uint32 a, char *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_UnbindAudioStream,(SDL_AudioStream *a),(a),) SDL_DYNAPI_PROC(void,SDL_UnbindAudioStreams,(SDL_AudioStream **a, int b),(a,b),) SDL_DYNAPI_PROC(void,SDL_UnloadObject,(void *a),(a),) -SDL_DYNAPI_PROC(int,SDL_UnlockAudioStream,(SDL_AudioStream *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_UnlockAudioStream,(SDL_AudioStream *a),(a),return) SDL_DYNAPI_PROC(void,SDL_UnlockJoysticks,(void),(),) SDL_DYNAPI_PROC(void,SDL_UnlockMutex,(SDL_Mutex *a),(a),) SDL_DYNAPI_PROC(void,SDL_UnlockProperties,(SDL_PropertiesID a),(a),) @@ -880,29 +880,29 @@ SDL_DYNAPI_PROC(void,SDL_UnlockSurface,(SDL_Surface *a),(a),) SDL_DYNAPI_PROC(void,SDL_UnlockTexture,(SDL_Texture *a),(a),) SDL_DYNAPI_PROC(void,SDL_UnregisterApp,(void),(),) SDL_DYNAPI_PROC(void,SDL_UpdateGamepads,(void),(),) -SDL_DYNAPI_PROC(int,SDL_UpdateHapticEffect,(SDL_Haptic *a, int b, const SDL_HapticEffect *c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_UpdateHapticEffect,(SDL_Haptic *a, int b, const SDL_HapticEffect *c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_UpdateJoysticks,(void),(),) -SDL_DYNAPI_PROC(int,SDL_UpdateNVTexture,(SDL_Texture *a, const SDL_Rect *b, const Uint8 *c, int d, const Uint8 *e, int f),(a,b,c,d,e,f),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_UpdateNVTexture,(SDL_Texture *a, const SDL_Rect *b, const Uint8 *c, int d, const Uint8 *e, int f),(a,b,c,d,e,f),return) SDL_DYNAPI_PROC(void,SDL_UpdateSensors,(void),(),) -SDL_DYNAPI_PROC(int,SDL_UpdateTexture,(SDL_Texture *a, const SDL_Rect *b, const void *c, int d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurface,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_UpdateWindowSurfaceRects,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return) -SDL_DYNAPI_PROC(int,SDL_UpdateYUVTexture,(SDL_Texture *a, const SDL_Rect *b, const Uint8 *c, int d, const Uint8 *e, int f, const Uint8 *g, int h),(a,b,c,d,e,f,g,h),return) -SDL_DYNAPI_PROC(int,SDL_Vulkan_CreateSurface,(SDL_Window *a, VkInstance b, const struct VkAllocationCallbacks *c, VkSurfaceKHR *d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_UpdateTexture,(SDL_Texture *a, const SDL_Rect *b, const void *c, int d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_UpdateWindowSurface,(SDL_Window *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_UpdateWindowSurfaceRects,(SDL_Window *a, const SDL_Rect *b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_UpdateYUVTexture,(SDL_Texture *a, const SDL_Rect *b, const Uint8 *c, int d, const Uint8 *e, int f, const Uint8 *g, int h),(a,b,c,d,e,f,g,h),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_CreateSurface,(SDL_Window *a, VkInstance b, const struct VkAllocationCallbacks *c, VkSurfaceKHR *d),(a,b,c,d),return) SDL_DYNAPI_PROC(void,SDL_Vulkan_DestroySurface,(VkInstance a, VkSurfaceKHR b, const struct VkAllocationCallbacks *c),(a,b,c),) SDL_DYNAPI_PROC(char const* const*,SDL_Vulkan_GetInstanceExtensions,(Uint32 *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_GetPresentationSupport,(VkInstance a, VkPhysicalDevice b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_FunctionPointer,SDL_Vulkan_GetVkGetInstanceProcAddr,(void),(),return) -SDL_DYNAPI_PROC(int,SDL_Vulkan_LoadLibrary,(const char *a),(a),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_Vulkan_LoadLibrary,(const char *a),(a),return) SDL_DYNAPI_PROC(void,SDL_Vulkan_UnloadLibrary,(void),(),) -SDL_DYNAPI_PROC(int,SDL_WaitCondition,(SDL_Condition *a, SDL_Mutex *b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_WaitConditionTimeout,(SDL_Condition *a, SDL_Mutex *b, Sint32 c),(a,b,c),return) +SDL_DYNAPI_PROC(void,SDL_WaitCondition,(SDL_Condition *a, SDL_Mutex *b),(a,b),) +SDL_DYNAPI_PROC(SDL_bool,SDL_WaitConditionTimeout,(SDL_Condition *a, SDL_Mutex *b, Sint32 c),(a,b,c),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WaitEvent,(SDL_Event *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WaitEventTimeout,(SDL_Event *a, Sint32 b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_WaitSemaphore,(SDL_Semaphore *a),(a),return) -SDL_DYNAPI_PROC(int,SDL_WaitSemaphoreTimeout,(SDL_Semaphore *a, Sint32 b),(a,b),return) +SDL_DYNAPI_PROC(void,SDL_WaitSemaphore,(SDL_Semaphore *a),(a),) +SDL_DYNAPI_PROC(SDL_bool,SDL_WaitSemaphoreTimeout,(SDL_Semaphore *a, Sint32 b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_WaitThread,(SDL_Thread *a, int *b),(a,b),) -SDL_DYNAPI_PROC(int,SDL_WarpMouseGlobal,(float a, float b),(a,b),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_WarpMouseGlobal,(float a, float b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_WarpMouseInWindow,(SDL_Window *a, float b, float c),(a,b,c),) SDL_DYNAPI_PROC(SDL_InitFlags,SDL_WasInit,(SDL_InitFlags a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WindowHasSurface,(SDL_Window *a),(a),return) @@ -914,9 +914,9 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS32LE,(SDL_IOStream *a, Sint32 b),(a,b),return SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS64BE,(SDL_IOStream *a, Sint64 b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS64LE,(SDL_IOStream *a, Sint64 b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WriteS8,(SDL_IOStream *a, Sint8 b),(a,b),return) -SDL_DYNAPI_PROC(int,SDL_WriteStorageFile,(SDL_Storage *a, const char *b, const void *c, Uint64 d),(a,b,c,d),return) -SDL_DYNAPI_PROC(int,SDL_WriteSurfacePixel,(SDL_Surface *a, int b, int c, Uint8 d, Uint8 e, Uint8 f, Uint8 g),(a,b,c,d,e,f,g),return) -SDL_DYNAPI_PROC(int,SDL_WriteSurfacePixelFloat,(SDL_Surface *a, int b, int c, float d, float e, float f, float g),(a,b,c,d,e,f,g),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_WriteStorageFile,(SDL_Storage *a, const char *b, const void *c, Uint64 d),(a,b,c,d),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_WriteSurfacePixel,(SDL_Surface *a, int b, int c, Uint8 d, Uint8 e, Uint8 f, Uint8 g),(a,b,c,d,e,f,g),return) +SDL_DYNAPI_PROC(SDL_bool,SDL_WriteSurfacePixelFloat,(SDL_Surface *a, int b, int c, float d, float e, float f, float g),(a,b,c,d,e,f,g),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU16BE,(SDL_IOStream *a, Uint16 b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU16LE,(SDL_IOStream *a, Uint16 b),(a,b),return) SDL_DYNAPI_PROC(SDL_bool,SDL_WriteU32BE,(SDL_IOStream *a, Uint32 b),(a,b),return) diff --git a/src/events/SDL_categories.c b/src/events/SDL_categories.c index 8707e10eb8..57fb8c49c8 100644 --- a/src/events/SDL_categories.c +++ b/src/events/SDL_categories.c @@ -38,7 +38,8 @@ SDL_EventCategory SDL_GetEventCategory(Uint32 type) } switch (type) { default: - return SDL_SetError("Unknown event type"); + SDL_SetError("Unknown event type"); + return SDL_EVENTCATEGORY_UNKNOWN; case SDL_EVENT_KEYMAP_CHANGED: case SDL_EVENT_TERMINATING: diff --git a/src/events/SDL_categories_c.h b/src/events/SDL_categories_c.h index 1b527788f1..5f82c00cd1 100644 --- a/src/events/SDL_categories_c.h +++ b/src/events/SDL_categories_c.h @@ -25,6 +25,7 @@ typedef enum SDL_EventCategory { + SDL_EVENTCATEGORY_UNKNOWN, SDL_EVENTCATEGORY_SYSTEM, SDL_EVENTCATEGORY_DISPLAY, SDL_EVENTCATEGORY_WINDOW, diff --git a/src/events/SDL_clipboardevents.c b/src/events/SDL_clipboardevents.c index d30906cc99..0bf462a163 100644 --- a/src/events/SDL_clipboardevents.c +++ b/src/events/SDL_clipboardevents.c @@ -25,17 +25,12 @@ #include "SDL_events_c.h" #include "SDL_clipboardevents_c.h" -int SDL_SendClipboardUpdate(void) +void SDL_SendClipboardUpdate(void) { - int posted; - - // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_CLIPBOARD_UPDATE)) { SDL_Event event; event.type = SDL_EVENT_CLIPBOARD_UPDATE; event.clipboard.timestamp = 0; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - return posted; } diff --git a/src/events/SDL_clipboardevents_c.h b/src/events/SDL_clipboardevents_c.h index c4edda2978..0288a3af4b 100644 --- a/src/events/SDL_clipboardevents_c.h +++ b/src/events/SDL_clipboardevents_c.h @@ -23,6 +23,6 @@ #ifndef SDL_clipboardevents_c_h_ #define SDL_clipboardevents_c_h_ -extern int SDL_SendClipboardUpdate(void); +extern void SDL_SendClipboardUpdate(void); #endif // SDL_clipboardevents_c_h_ diff --git a/src/events/SDL_displayevents.c b/src/events/SDL_displayevents.c index 84eee4098c..b736fd4a05 100644 --- a/src/events/SDL_displayevents.c +++ b/src/events/SDL_displayevents.c @@ -24,17 +24,15 @@ #include "SDL_events_c.h" -int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1, int data2) +void SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1, int data2) { - int posted; - if (!display || display->id == 0) { - return 0; + return; } switch (displayevent) { case SDL_EVENT_DISPLAY_ORIENTATION: if (data1 == SDL_ORIENTATION_UNKNOWN || data1 == display->current_orientation) { - return 0; + return; } display->current_orientation = (SDL_DisplayOrientation)data1; break; @@ -43,7 +41,6 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(displayevent)) { SDL_Event event; event.type = displayevent; @@ -51,7 +48,7 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, event.display.displayID = display->id; event.display.data1 = data1; event.display.data2 = data2; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } switch (displayevent) { @@ -64,6 +61,4 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, default: break; } - - return posted; } diff --git a/src/events/SDL_displayevents_c.h b/src/events/SDL_displayevents_c.h index 138484299f..497b50b10e 100644 --- a/src/events/SDL_displayevents_c.h +++ b/src/events/SDL_displayevents_c.h @@ -23,6 +23,6 @@ #ifndef SDL_displayevents_c_h_ #define SDL_displayevents_c_h_ -extern int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1, int data2); +extern void SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1, int data2); #endif // SDL_displayevents_c_h_ diff --git a/src/events/SDL_dropevents.c b/src/events/SDL_dropevents.c index de6491ab4a..22388f3611 100644 --- a/src/events/SDL_dropevents.c +++ b/src/events/SDL_dropevents.c @@ -27,12 +27,12 @@ #include "../video/SDL_sysvideo.h" // for SDL_Window internals. -static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *source, const char *data, float x, float y) +static bool SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const char *source, const char *data, float x, float y) { static bool app_is_dropping = false; static float last_drop_x = 0; static float last_drop_y = 0; - int posted = 0; + bool posted = false; // Post the event, if desired if (SDL_EventEnabled(evtype)) { @@ -44,9 +44,9 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch event.type = SDL_EVENT_DROP_BEGIN; event.common.timestamp = 0; event.drop.windowID = window ? window->id : 0; - posted = (SDL_PushEvent(&event) > 0); + posted = SDL_PushEvent(&event); if (!posted) { - return 0; + return false; } if (window) { window->is_dropping = true; @@ -61,13 +61,13 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch if (source) { event.drop.source = SDL_CreateTemporaryString(source); if (!event.drop.source) { - return 0; + return false; } } if (data) { event.drop.data = SDL_CreateTemporaryString(data); if (!event.drop.data) { - return 0; + return false; } } event.drop.windowID = window ? window->id : 0; @@ -78,7 +78,7 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch } event.drop.x = last_drop_x; event.drop.y = last_drop_y; - posted = (SDL_PushEvent(&event) > 0); + posted = SDL_PushEvent(&event); if (posted && (evtype == SDL_EVENT_DROP_COMPLETE)) { if (window) { @@ -94,22 +94,22 @@ static int SDL_SendDrop(SDL_Window *window, const SDL_EventType evtype, const ch return posted; } -int SDL_SendDropFile(SDL_Window *window, const char *source, const char *file) +bool SDL_SendDropFile(SDL_Window *window, const char *source, const char *file) { return SDL_SendDrop(window, SDL_EVENT_DROP_FILE, source, file, 0, 0); } -int SDL_SendDropPosition(SDL_Window *window, float x, float y) +bool SDL_SendDropPosition(SDL_Window *window, float x, float y) { return SDL_SendDrop(window, SDL_EVENT_DROP_POSITION, NULL, NULL, x, y); } -int SDL_SendDropText(SDL_Window *window, const char *text) +bool SDL_SendDropText(SDL_Window *window, const char *text) { return SDL_SendDrop(window, SDL_EVENT_DROP_TEXT, NULL, text, 0, 0); } -int SDL_SendDropComplete(SDL_Window *window) +bool SDL_SendDropComplete(SDL_Window *window) { return SDL_SendDrop(window, SDL_EVENT_DROP_COMPLETE, NULL, NULL, 0, 0); } diff --git a/src/events/SDL_dropevents_c.h b/src/events/SDL_dropevents_c.h index d3d3bebb43..5dbdcf8519 100644 --- a/src/events/SDL_dropevents_c.h +++ b/src/events/SDL_dropevents_c.h @@ -23,9 +23,9 @@ #ifndef SDL_dropevents_c_h_ #define SDL_dropevents_c_h_ -extern int SDL_SendDropFile(SDL_Window *window, const char *source, const char *file); -extern int SDL_SendDropPosition(SDL_Window *window, float x, float y); -extern int SDL_SendDropText(SDL_Window *window, const char *text); -extern int SDL_SendDropComplete(SDL_Window *window); +extern bool SDL_SendDropFile(SDL_Window *window, const char *source, const char *file); +extern bool SDL_SendDropPosition(SDL_Window *window, float x, float y); +extern bool SDL_SendDropText(SDL_Window *window, const char *text); +extern bool SDL_SendDropComplete(SDL_Window *window); #endif // SDL_dropevents_c_h_ diff --git a/src/events/SDL_events.c b/src/events/SDL_events.c index 2279adcf75..f8b57e2059 100644 --- a/src/events/SDL_events.c +++ b/src/events/SDL_events.c @@ -134,7 +134,7 @@ static SDL_TemporaryMemoryState *SDL_GetTemporaryMemoryState(bool create) return NULL; } - if (SDL_SetTLS(&SDL_temporary_memory, state, SDL_CleanupTemporaryMemory) < 0) { + if (!SDL_SetTLS(&SDL_temporary_memory, state, SDL_CleanupTemporaryMemory)) { SDL_free(state); return NULL; } @@ -885,7 +885,7 @@ void SDL_StopEventLoop(void) } // This function (and associated calls) may be called more than once -int SDL_StartEventLoop(void) +bool SDL_StartEventLoop(void) { /* We'll leave the event queue alone, since we might have gotten some important events at launch (like SDL_EVENT_DROP_FILE) @@ -898,7 +898,7 @@ int SDL_StartEventLoop(void) if (!SDL_EventQ.lock) { SDL_EventQ.lock = SDL_CreateMutex(); if (SDL_EventQ.lock == NULL) { - return -1; + return false; } } SDL_LockMutex(SDL_EventQ.lock); @@ -907,14 +907,14 @@ int SDL_StartEventLoop(void) SDL_event_watchers_lock = SDL_CreateMutex(); if (SDL_event_watchers_lock == NULL) { SDL_UnlockMutex(SDL_EventQ.lock); - return -1; + return false; } } #endif // !SDL_THREADS_DISABLED SDL_EventQ.active = true; SDL_UnlockMutex(SDL_EventQ.lock); - return 0; + return true; } // Add an event to the event queue -- called with the queue locked @@ -1004,14 +1004,14 @@ static void SDL_CutEvent(SDL_EventEntry *entry) SDL_AtomicAdd(&SDL_EventQ.count, -1); } -static int SDL_SendWakeupEvent(void) +static void SDL_SendWakeupEvent(void) { #ifdef SDL_PLATFORM_ANDROID Android_SendLifecycleEvent(SDL_ANDROID_LIFECYCLE_WAKE); #else SDL_VideoDevice *_this = SDL_GetVideoDevice(); if (_this == NULL || !_this->SendWakeupEvent) { - return 0; + return; } SDL_LockMutex(_this->wakeup_lock); @@ -1025,8 +1025,6 @@ static int SDL_SendWakeupEvent(void) } SDL_UnlockMutex(_this->wakeup_lock); #endif - - return 0; } // Lock the event queue, take a peep at it, and unlock it @@ -1502,21 +1500,22 @@ static bool SDL_CallEventWatchers(SDL_Event *event) return true; } -int SDL_PushEvent(SDL_Event *event) +SDL_bool SDL_PushEvent(SDL_Event *event) { if (!event->common.timestamp) { event->common.timestamp = SDL_GetTicksNS(); } if (!SDL_CallEventWatchers(event)) { - return 0; + SDL_ClearError(); + return false; } if (SDL_PeepEvents(event, 1, SDL_ADDEVENT, 0, 0) <= 0) { - return -1; + return false; } - return 1; + return true; } void SDL_SetEventFilter(SDL_EventFilter filter, void *userdata) @@ -1563,9 +1562,9 @@ SDL_bool SDL_GetEventFilter(SDL_EventFilter *filter, void **userdata) return event_ok.callback ? true : false; } -int SDL_AddEventWatch(SDL_EventFilter filter, void *userdata) +SDL_bool SDL_AddEventWatch(SDL_EventFilter filter, void *userdata) { - int result = 0; + bool result = true; SDL_LockMutex(SDL_event_watchers_lock); { @@ -1582,7 +1581,7 @@ int SDL_AddEventWatch(SDL_EventFilter filter, void *userdata) watcher->removed = false; ++SDL_event_watchers_count; } else { - result = -1; + result = false; } } SDL_UnlockMutex(SDL_event_watchers_lock); @@ -1715,11 +1714,8 @@ Uint32 SDL_RegisterEvents(int numevents) return event_base; } -int SDL_SendAppEvent(SDL_EventType eventType) +void SDL_SendAppEvent(SDL_EventType eventType) { - int posted; - - posted = 0; if (SDL_EventEnabled(eventType)) { SDL_Event event; event.type = eventType; @@ -1736,32 +1732,31 @@ int SDL_SendAppEvent(SDL_EventType eventType) if (SDL_EventLoggingVerbosity > 0) { SDL_LogEvent(&event); } - posted = SDL_CallEventWatchers(&event); + SDL_CallEventWatchers(&event); break; default: - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); break; } } - return posted; } -int SDL_SendKeymapChangedEvent(void) +void SDL_SendKeymapChangedEvent(void) { - return SDL_SendAppEvent(SDL_EVENT_KEYMAP_CHANGED); + SDL_SendAppEvent(SDL_EVENT_KEYMAP_CHANGED); } -int SDL_SendLocaleChangedEvent(void) +void SDL_SendLocaleChangedEvent(void) { - return SDL_SendAppEvent(SDL_EVENT_LOCALE_CHANGED); + SDL_SendAppEvent(SDL_EVENT_LOCALE_CHANGED); } -int SDL_SendSystemThemeChangedEvent(void) +void SDL_SendSystemThemeChangedEvent(void) { - return SDL_SendAppEvent(SDL_EVENT_SYSTEM_THEME_CHANGED); + SDL_SendAppEvent(SDL_EVENT_SYSTEM_THEME_CHANGED); } -int SDL_InitEvents(void) +bool SDL_InitEvents(void) { #ifdef SDL_PLATFORM_ANDROID Android_InitEvents(); @@ -1774,14 +1769,14 @@ int SDL_InitEvents(void) #endif SDL_AddHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL); SDL_AddHintCallback(SDL_HINT_POLL_SENTINEL, SDL_PollSentinelChanged, NULL); - if (SDL_StartEventLoop() < 0) { + if (!SDL_StartEventLoop()) { SDL_DelHintCallback(SDL_HINT_EVENT_LOGGING, SDL_EventLoggingChanged, NULL); - return -1; + return false; } SDL_InitQuit(); - return 0; + return true; } void SDL_QuitEvents(void) diff --git a/src/events/SDL_events_c.h b/src/events/SDL_events_c.h index 284b576c11..d8f86eb3c0 100644 --- a/src/events/SDL_events_c.h +++ b/src/events/SDL_events_c.h @@ -37,28 +37,28 @@ #include "SDL_windowevents_c.h" // Start and stop the event processing loop -extern int SDL_StartEventLoop(void); +extern bool SDL_StartEventLoop(void); extern void SDL_StopEventLoop(void); extern void SDL_QuitInterrupt(void); -extern int SDL_SendAppEvent(SDL_EventType eventType); -extern int SDL_SendKeymapChangedEvent(void); -extern int SDL_SendLocaleChangedEvent(void); -extern int SDL_SendSystemThemeChangedEvent(void); +extern void SDL_SendAppEvent(SDL_EventType eventType); +extern void SDL_SendKeymapChangedEvent(void); +extern void SDL_SendLocaleChangedEvent(void); +extern void SDL_SendSystemThemeChangedEvent(void); extern void *SDL_AllocateTemporaryMemory(size_t size); extern const char *SDL_CreateTemporaryString(const char *string); extern void *SDL_ClaimTemporaryMemory(const void *mem); extern void SDL_FreeTemporaryMemory(void); -extern int SDL_SendQuit(void); +extern void SDL_SendQuit(void); -extern int SDL_InitEvents(void); +extern bool SDL_InitEvents(void); extern void SDL_QuitEvents(void); extern void SDL_SendPendingSignalEvents(void); -extern int SDL_InitQuit(void); +extern bool SDL_InitQuit(void); extern void SDL_QuitQuit(void); #endif // SDL_events_c_h_ diff --git a/src/events/SDL_keyboard.c b/src/events/SDL_keyboard.c index d966222494..f60732275f 100644 --- a/src/events/SDL_keyboard.c +++ b/src/events/SDL_keyboard.c @@ -92,11 +92,11 @@ static void SDLCALL SDL_KeycodeOptionsChanged(void *userdata, const char *name, } // Public functions -int SDL_InitKeyboard(void) +bool SDL_InitKeyboard(void) { SDL_AddHintCallback(SDL_HINT_KEYCODE_OPTIONS, SDL_KeycodeOptionsChanged, &SDL_keyboard); - return 0; + return true; } bool SDL_IsKeyboard(Uint16 vendor, Uint16 product, int num_keys) @@ -318,7 +318,7 @@ SDL_Window *SDL_GetKeyboardFocus(void) return keyboard->focus; } -int SDL_SetKeyboardFocus(SDL_Window *window) +bool SDL_SetKeyboardFocus(SDL_Window *window) { SDL_VideoDevice *video = SDL_GetVideoDevice(); SDL_Keyboard *keyboard = &SDL_keyboard; @@ -360,7 +360,7 @@ int SDL_SetKeyboardFocus(SDL_Window *window) SDL_UpdateRelativeMouseMode(); - return 0; + return true; } static SDL_Keycode SDL_ConvertNumpadKeycode(SDL_Keycode keycode, bool numlock) @@ -490,10 +490,10 @@ SDL_Scancode SDL_GetScancodeFromKey(SDL_Keycode key, SDL_Keymod *modstate) return SDL_GetKeymapScancode(keyboard->keymap, key, modstate); } -static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state) +static bool SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state) { SDL_Keyboard *keyboard = &SDL_keyboard; - int posted; + bool posted = false; SDL_Keycode keycode = SDLK_UNKNOWN; Uint32 type; Uint8 repeat = false; @@ -514,7 +514,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo break; default: // Invalid state -- bail - return 0; + return false; } if (scancode > SDL_SCANCODE_UNKNOWN && scancode < SDL_NUM_SCANCODES) { @@ -523,14 +523,14 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo if (keyboard->keystate[scancode]) { if (!(keyboard->keysource[scancode] & source)) { keyboard->keysource[scancode] |= source; - return 0; + return false; } repeat = true; } keyboard->keysource[scancode] |= source; } else { if (!keyboard->keystate[scancode]) { - return 0; + return false; } keyboard->keysource[scancode] = 0; } @@ -542,7 +542,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo } else if (rawcode == 0) { // Nothing to do! - return 0; + return false; } if (source == KEYBOARD_HARDWARE) { @@ -608,7 +608,6 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(type)) { SDL_Event event; event.type = type; @@ -621,7 +620,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo event.key.repeat = repeat; event.key.windowID = keyboard->focus ? keyboard->focus->id : 0; event.key.which = keyboardID; - posted = (SDL_PushEvent(&event) > 0); + posted = SDL_PushEvent(&event); } /* If the keyboard is grabbed and the grabbed window is in full-screen, @@ -642,7 +641,7 @@ static int SDL_SendKeyboardKeyInternal(Uint64 timestamp, Uint32 flags, SDL_Keybo return posted; } -int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch) +void SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch) { SDL_Keyboard *keyboard = &SDL_keyboard; SDL_Keymod modstate = SDL_KMOD_NONE; @@ -667,15 +666,14 @@ int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch) // If the character uses shift, release shift SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_VIRTUAL, SDL_GLOBAL_KEYBOARD_ID, 0, SDL_SCANCODE_LSHIFT, SDL_RELEASED); } - return 0; } -int SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state) +bool SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state) { return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, state); } -int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state) +bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state) { if (state == SDL_PRESSED) { // Make sure we have this keycode in our keymap @@ -685,12 +683,12 @@ int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, i return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE, keyboardID, rawcode, scancode, state); } -int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state) +bool SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state) { return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_HARDWARE | KEYBOARD_IGNOREMODIFIERS, keyboardID, rawcode, scancode, state); } -int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode) +bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode) { return SDL_SendKeyboardKeyInternal(timestamp, KEYBOARD_AUTORELEASE, SDL_GLOBAL_KEYBOARD_ID, 0, scancode, SDL_PRESSED); } @@ -731,26 +729,24 @@ bool SDL_HardwareKeyboardKeyPressed(void) return keyboard->hardware_timestamp ? true : false; } -int SDL_SendKeyboardText(const char *text) +void SDL_SendKeyboardText(const char *text) { SDL_Keyboard *keyboard = &SDL_keyboard; - int posted; if (!SDL_TextInputActive(keyboard->focus)) { - return 0; + return; } if (!text || !*text) { - return 0; + return; } // Don't post text events for unprintable characters if (SDL_iscntrl((unsigned char)*text)) { - return 0; + return; } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_TEXT_INPUT)) { SDL_Event event; event.type = SDL_EVENT_TEXT_INPUT; @@ -758,28 +754,25 @@ int SDL_SendKeyboardText(const char *text) event.text.windowID = keyboard->focus ? keyboard->focus->id : 0; event.text.text = SDL_CreateTemporaryString(text); if (!event.text.text) { - return 0; + return; } - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - return posted; } -int SDL_SendEditingText(const char *text, int start, int length) +void SDL_SendEditingText(const char *text, int start, int length) { SDL_Keyboard *keyboard = &SDL_keyboard; - int posted; if (!SDL_TextInputActive(keyboard->focus)) { - return 0; + return; } if (!text) { - return 0; + return; } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_TEXT_EDITING)) { SDL_Event event; @@ -790,11 +783,10 @@ int SDL_SendEditingText(const char *text, int start, int length) event.edit.length = length; event.edit.text = SDL_CreateTemporaryString(text); if (!event.edit.text) { - return 0; + return; } - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - return posted; } static const char * const *CreateCandidatesForEvent(char **candidates, int num_candidates) @@ -828,17 +820,15 @@ static const char * const *CreateCandidatesForEvent(char **candidates, int num_c return event_candidates; } -int SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int selected_candidate, bool horizontal) +void SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int selected_candidate, bool horizontal) { SDL_Keyboard *keyboard = &SDL_keyboard; - int posted; if (!SDL_TextInputActive(keyboard->focus)) { - return 0; + return; } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_TEXT_EDITING_CANDIDATES)) { SDL_Event event; @@ -848,7 +838,7 @@ int SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int sel if (num_candidates > 0) { const char * const *event_candidates = CreateCandidatesForEvent(candidates, num_candidates); if (!event_candidates) { - return 0; + return; } event.edit_candidates.candidates = event_candidates; event.edit_candidates.num_candidates = num_candidates; @@ -860,9 +850,8 @@ int SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int sel event.edit_candidates.selected_candidate = -1; event.edit_candidates.horizontal = false; } - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - return posted; } void SDL_QuitKeyboard(void) diff --git a/src/events/SDL_keyboard_c.h b/src/events/SDL_keyboard_c.h index a810c92031..28e8bce057 100644 --- a/src/events/SDL_keyboard_c.h +++ b/src/events/SDL_keyboard_c.h @@ -32,7 +32,7 @@ #define SDL_DEFAULT_KEYBOARD_ID 1 // Initialize the keyboard subsystem -extern int SDL_InitKeyboard(void); +extern bool SDL_InitKeyboard(void); // Return whether a device is actually a keyboard extern bool SDL_IsKeyboard(Uint16 vendor, Uint16 product, int num_keys); @@ -47,21 +47,21 @@ extern void SDL_RemoveKeyboard(SDL_KeyboardID keyboardID, bool send_event); extern void SDL_SetKeymap(SDL_Keymap *keymap, bool send_event); // Set the keyboard focus window -extern int SDL_SetKeyboardFocus(SDL_Window *window); +extern bool SDL_SetKeyboardFocus(SDL_Window *window); /* Send a character from an on-screen keyboard as scancode and modifier key events, currently assuming ASCII characters on a US keyboard layout */ -extern int SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch); +extern void SDL_SendKeyboardUnicodeKey(Uint64 timestamp, Uint32 ch); // Send a keyboard key event -extern int SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state); -extern int SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state); -extern int SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode); +extern bool SDL_SendKeyboardKey(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state); +extern bool SDL_SendKeyboardKeyIgnoreModifiers(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, Uint8 state); +extern bool SDL_SendKeyboardKeyAutoRelease(Uint64 timestamp, SDL_Scancode scancode); /* This is for platforms that don't know the keymap but can report scancode and keycode directly. Most platforms should prefer to optionally call SDL_SetKeymap and then use SDL_SendKeyboardKey. */ -extern int SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state); +extern bool SDL_SendKeyboardKeyAndKeycode(Uint64 timestamp, SDL_KeyboardID keyboardID, int rawcode, SDL_Scancode scancode, SDL_Keycode keycode, Uint8 state); // Release all the autorelease keys extern void SDL_ReleaseAutoReleaseKeys(void); @@ -70,13 +70,13 @@ extern void SDL_ReleaseAutoReleaseKeys(void); extern bool SDL_HardwareKeyboardKeyPressed(void); // Send keyboard text input -extern int SDL_SendKeyboardText(const char *text); +extern void SDL_SendKeyboardText(const char *text); // Send editing text for selected range from start to end -extern int SDL_SendEditingText(const char *text, int start, int length); +extern void SDL_SendEditingText(const char *text, int start, int length); // Send editing text candidates, which will be copied into the event -int SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int selected_candidate, bool horizontal); +extern void SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int selected_candidate, bool horizontal); // Shutdown the keyboard subsystem extern void SDL_QuitKeyboard(void); diff --git a/src/events/SDL_keymap.c b/src/events/SDL_keymap.c index acc4946fb1..dc1b31177c 100644 --- a/src/events/SDL_keymap.c +++ b/src/events/SDL_keymap.c @@ -933,14 +933,14 @@ static const char *SDL_scancode_names[SDL_NUM_SCANCODES] = /* 290 */ "EndCall", }; -int SDL_SetScancodeName(SDL_Scancode scancode, const char *name) +SDL_bool SDL_SetScancodeName(SDL_Scancode scancode, const char *name) { if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_NUM_SCANCODES) { return SDL_InvalidParamError("scancode"); } SDL_scancode_names[scancode] = name; - return 0; + return true; } const char *SDL_GetScancodeName(SDL_Scancode scancode) diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index fa7c09be79..dc8c305a25 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -48,7 +48,7 @@ static SDL_MouseInstance *SDL_mice; // for mapping mouse events to touch static bool track_mouse_down = false; -static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y); +static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y); static void SDLCALL SDL_MouseDoubleClickTimeChanged(void *userdata, const char *name, const char *oldValue, const char *hint) { @@ -203,7 +203,7 @@ static void SDLCALL SDL_MouseRelativeCursorVisibleChanged(void *userdata, const } // Public functions -int SDL_PreInitMouse(void) +bool SDL_PreInitMouse(void) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -254,7 +254,7 @@ int SDL_PreInitMouse(void) mouse->cursor_shown = true; - return 0; + return true; } void SDL_PostInitMouse(void) @@ -574,16 +574,16 @@ static bool SDL_UpdateMouseFocus(SDL_Window *window, float x, float y, Uint32 bu return true; } -int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y) +void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y) { if (window && !relative) { SDL_Mouse *mouse = SDL_GetMouse(); if (!SDL_UpdateMouseFocus(window, x, y, SDL_GetMouseButtonState(mouse, mouseID, true), (mouseID != SDL_TOUCH_MOUSEID))) { - return 0; + return; } } - return SDL_PrivateSendMouseMotion(timestamp, window, mouseID, relative, x, y); + SDL_PrivateSendMouseMotion(timestamp, window, mouseID, relative, x, y); } static float CalculateSystemScale(SDL_Mouse *mouse, SDL_Window *window, const float *x, const float *y) @@ -631,7 +631,7 @@ static float CalculateSystemScale(SDL_Mouse *mouse, SDL_Window *window, const fl } // You can set either a single scale, or a set of {speed, scale} values in ascending order -int SDL_SetMouseSystemScale(int num_values, const float *values) +bool SDL_SetMouseSystemScale(int num_values, const float *values) { SDL_Mouse *mouse = SDL_GetMouse(); float *v; @@ -639,7 +639,7 @@ int SDL_SetMouseSystemScale(int num_values, const float *values) if (num_values == mouse->num_system_scale_values && SDL_memcmp(values, mouse->system_scale_values, num_values * sizeof(*values)) == 0) { // Nothing has changed - return 0; + return true; } if (num_values < 1) { @@ -663,13 +663,13 @@ int SDL_SetMouseSystemScale(int num_values, const float *values) v = (float *)SDL_realloc(mouse->system_scale_values, num_values * sizeof(*values)); if (!v) { - return -1; + return false; } SDL_memcpy(v, values, num_values * sizeof(*values)); mouse->num_system_scale_values = num_values; mouse->system_scale_values = v; - return 0; + return true; } static void GetScaledMouseDeltas(SDL_Mouse *mouse, SDL_Window *window, float *x, float *y) @@ -732,10 +732,9 @@ static void ConstrainMousePosition(SDL_Mouse *mouse, SDL_Window *window, float * } } -static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y) +static void SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y) { SDL_Mouse *mouse = SDL_GetMouse(); - int posted; float xrel = 0.0f; float yrel = 0.0f; @@ -757,7 +756,7 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ // SDL_HINT_TOUCH_MOUSE_EVENTS: if not set, discard synthetic mouse events coming from platform layer if (!mouse->touch_mouse_events && mouseID == SDL_TOUCH_MOUSEID) { - return 0; + return; } if (mouseID != SDL_TOUCH_MOUSEID && mouse->relative_mode_warp) { @@ -771,7 +770,7 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ mouse->last_x = center_x; mouse->last_y = center_y; if (!mouse->relative_mode_warp_motion) { - return 0; + return; } } else { if (window && (window->flags & SDL_WINDOW_INPUT_FOCUS)) { @@ -804,7 +803,7 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ #ifdef DEBUG_MOUSE SDL_Log("Mouse event didn't change state - dropped!\n"); #endif - return 0; + return; } // Ignore relative motion positioning the first touch @@ -839,7 +838,6 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_MOUSE_MOTION)) { SDL_Event event; event.type = SDL_EVENT_MOUSE_MOTION; @@ -853,7 +851,7 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ event.motion.y = mouse->y; event.motion.xrel = xrel; event.motion.yrel = yrel; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } if (relative) { mouse->last_x = mouse->x; @@ -863,7 +861,6 @@ static int SDL_PrivateSendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_ mouse->last_x = x; mouse->last_y = y; } - return posted; } static SDL_MouseInputSource *GetMouseInputSource(SDL_Mouse *mouse, SDL_MouseID mouseID, Uint8 state, Uint8 button) @@ -925,10 +922,9 @@ static SDL_MouseClickState *GetMouseClickState(SDL_Mouse *mouse, Uint8 button) return &mouse->clickstate[button]; } -static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks) +static void SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks) { SDL_Mouse *mouse = SDL_GetMouse(); - int posted; Uint32 type; Uint32 buttonstate; SDL_MouseInputSource *source; @@ -940,7 +936,7 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ source = GetMouseInputSource(mouse, mouseID, state, button); if (!source) { - return 0; + return; } buttonstate = source->buttonstate; @@ -963,7 +959,7 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ // SDL_HINT_TOUCH_MOUSE_EVENTS: if not set, discard synthetic mouse events coming from platform layer if (mouse->touch_mouse_events == 0) { if (mouseID == SDL_TOUCH_MOUSEID) { - return 0; + return; } } @@ -979,7 +975,7 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ break; default: // Invalid state -- bail - return 0; + return; } // We do this after calculating buttonstate so button presses gain focus @@ -989,7 +985,7 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ if (buttonstate == source->buttonstate) { // Ignore this event, no state change - return 0; + return; } source->buttonstate = buttonstate; @@ -1018,7 +1014,6 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(type)) { SDL_Event event; event.type = type; @@ -1030,7 +1025,7 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ event.button.clicks = (Uint8)SDL_min(clicks, 255); event.button.x = mouse->x; event.button.y = mouse->y; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } // We do this after dispatching event so button releases can lose focus @@ -1042,36 +1037,32 @@ static int SDL_PrivateSendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_ if (mouse->auto_capture) { SDL_UpdateMouseCapture(false); } - - return posted; } -int SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks) +void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks) { clicks = SDL_max(clicks, 0); - return SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, clicks); + SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, clicks); } -int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button) +void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button) { - return SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, -1); + SDL_PrivateSendMouseButton(timestamp, window, mouseID, state, button, -1); } -int SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction) +void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction) { SDL_Mouse *mouse = SDL_GetMouse(); - int posted; if (window) { SDL_SetMouseFocus(window); } if (x == 0.0f && y == 0.0f) { - return 0; + return; } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_MOUSE_WHEEL)) { SDL_Event event; event.type = SDL_EVENT_MOUSE_WHEEL; @@ -1083,9 +1074,8 @@ int SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID event.wheel.direction = direction; event.wheel.mouse_x = mouse->x; event.wheel.mouse_y = mouse->y; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - return posted; } void SDL_QuitMouse(void) @@ -1299,7 +1289,7 @@ static void SDL_MaybeEnableWarpEmulation(SDL_Window *window, float x, float y) // Require two consecutive warps to the center within a certain timespan to enter warp emulation mode. const Uint64 now = SDL_GetTicksNS(); if (now - mouse->last_center_warp_time_ns < WARP_EMULATION_THRESHOLD_NS) { - if (SDL_SetRelativeMouseMode(true) == 0) { + if (SDL_SetRelativeMouseMode(true)) { mouse->warp_emulation_active = true; } } @@ -1321,7 +1311,7 @@ void SDL_WarpMouseInWindow(SDL_Window *window, float x, float y) SDL_PerformWarpMouseInWindow(window, x, y, mouse->warp_emulation_active); } -int SDL_WarpMouseGlobal(float x, float y) +SDL_bool SDL_WarpMouseGlobal(float x, float y) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -1342,7 +1332,7 @@ static bool SDL_ShouldUseRelativeModeWarp(SDL_Mouse *mouse) return SDL_GetHintBoolean(SDL_HINT_MOUSE_RELATIVE_MODE_WARP, false); } -int SDL_SetRelativeMouseMode(bool enabled) +bool SDL_SetRelativeMouseMode(bool enabled) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_Window *focusWindow = SDL_GetKeyboardFocus(); @@ -1353,7 +1343,7 @@ int SDL_SetRelativeMouseMode(bool enabled) } if (enabled == mouse->relative_mode) { - return 0; + return true; } // Set the relative mode @@ -1361,7 +1351,7 @@ int SDL_SetRelativeMouseMode(bool enabled) mouse->relative_mode_warp = false; } else if (enabled && SDL_ShouldUseRelativeModeWarp(mouse)) { mouse->relative_mode_warp = true; - } else if (!mouse->SetRelativeMouseMode || mouse->SetRelativeMouseMode(enabled) < 0) { + } else if (!mouse->SetRelativeMouseMode || !mouse->SetRelativeMouseMode(enabled)) { if (enabled) { // Fall back to warp mode if native relative mode failed if (!mouse->WarpMouse) { @@ -1406,7 +1396,7 @@ int SDL_SetRelativeMouseMode(bool enabled) // Flush pending mouse motion - ideally we would pump events, but that's not always safe SDL_FlushEvent(SDL_EVENT_MOUSE_MOTION); - return 0; + return true; } bool SDL_GetRelativeMouseMode(void) @@ -1427,13 +1417,13 @@ void SDL_UpdateRelativeMouseMode(void) } } -int SDL_UpdateMouseCapture(bool force_release) +bool SDL_UpdateMouseCapture(bool force_release) { SDL_Mouse *mouse = SDL_GetMouse(); SDL_Window *capture_window = NULL; if (!mouse->CaptureMouse) { - return 0; + return true; } if (!force_release) { @@ -1462,7 +1452,7 @@ int SDL_UpdateMouseCapture(bool force_release) mouse->capture_window = capture_window; - if (mouse->CaptureMouse(capture_window) < 0) { + if (!mouse->CaptureMouse(capture_window)) { // CaptureMouse() will have set an error, just restore the state if (previous_capture) { previous_capture->flags |= SDL_WINDOW_MOUSE_CAPTURE; @@ -1472,13 +1462,13 @@ int SDL_UpdateMouseCapture(bool force_release) } mouse->capture_window = previous_capture; - return -1; + return false; } } - return 0; + return true; } -int SDL_CaptureMouse(SDL_bool enabled) +SDL_bool SDL_CaptureMouse(SDL_bool enabled) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -1618,13 +1608,13 @@ SDL_Cursor *SDL_CreateSystemCursor(SDL_SystemCursor id) if this is desired for any reason. This is used when setting the video mode and when the SDL window gains the mouse focus. */ -int SDL_SetCursor(SDL_Cursor *cursor) +SDL_bool SDL_SetCursor(SDL_Cursor *cursor) { SDL_Mouse *mouse = SDL_GetMouse(); // Return immediately if setting the cursor to the currently set one (fixes #7151) if (cursor == mouse->cur_cursor) { - return 0; + return true; } // Set the new cursor @@ -1659,7 +1649,7 @@ int SDL_SetCursor(SDL_Cursor *cursor) mouse->ShowCursor(NULL); } } - return 0; + return true; } SDL_Cursor *SDL_GetCursor(void) @@ -1717,7 +1707,7 @@ void SDL_DestroyCursor(SDL_Cursor *cursor) } } -int SDL_ShowCursor(void) +SDL_bool SDL_ShowCursor(void) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -1730,10 +1720,10 @@ int SDL_ShowCursor(void) mouse->cursor_shown = true; SDL_SetCursor(NULL); } - return 0; + return true; } -int SDL_HideCursor(void) +SDL_bool SDL_HideCursor(void) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -1741,7 +1731,7 @@ int SDL_HideCursor(void) mouse->cursor_shown = false; SDL_SetCursor(NULL); } - return 0; + return true; } SDL_bool SDL_CursorVisible(void) diff --git a/src/events/SDL_mouse_c.h b/src/events/SDL_mouse_c.h index 5085b4ca7e..f093dcf30f 100644 --- a/src/events/SDL_mouse_c.h +++ b/src/events/SDL_mouse_c.h @@ -59,25 +59,25 @@ typedef struct SDL_Cursor *(*CreateSystemCursor)(SDL_SystemCursor id); // Show the specified cursor, or hide if cursor is NULL - int (*ShowCursor)(SDL_Cursor *cursor); + bool (*ShowCursor)(SDL_Cursor *cursor); // This is called when a mouse motion event occurs - int (*MoveCursor)(SDL_Cursor *cursor); + bool (*MoveCursor)(SDL_Cursor *cursor); // Free a window manager cursor void (*FreeCursor)(SDL_Cursor *cursor); // Warp the mouse to (x,y) within a window - int (*WarpMouse)(SDL_Window *window, float x, float y); + bool (*WarpMouse)(SDL_Window *window, float x, float y); // Warp the mouse to (x,y) in screen space - int (*WarpMouseGlobal)(float x, float y); + bool (*WarpMouseGlobal)(float x, float y); // Set relative mode - int (*SetRelativeMouseMode)(bool enabled); + bool (*SetRelativeMouseMode)(bool enabled); // Set mouse capture - int (*CaptureMouse)(SDL_Window *window); + bool (*CaptureMouse)(SDL_Window *window); // Get absolute mouse coordinates. (x) and (y) are never NULL and set to zero before call. SDL_MouseButtonFlags (*GetGlobalMouseState)(float *x, float *y); @@ -136,7 +136,7 @@ typedef struct } SDL_Mouse; // Initialize the mouse subsystem, called before the main video driver is initialized -extern int SDL_PreInitMouse(void); +extern bool SDL_PreInitMouse(void); // Finish initializing the mouse subsystem, called after the main video driver was initialized extern void SDL_PostInitMouse(void); @@ -160,28 +160,28 @@ extern void SDL_SetDefaultCursor(SDL_Cursor *cursor); extern void SDL_SetMouseFocus(SDL_Window *window); // Update the mouse capture window -extern int SDL_UpdateMouseCapture(bool force_release); +extern bool SDL_UpdateMouseCapture(bool force_release); // You can set either a single scale, or a set of {speed, scale} values in sorted order -extern int SDL_SetMouseSystemScale(int num_values, const float *values); +extern bool SDL_SetMouseSystemScale(int num_values, const float *values); // Send a mouse motion event -extern int SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y); +extern void SDL_SendMouseMotion(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, bool relative, float x, float y); // Send a mouse button event -extern int SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button); +extern void SDL_SendMouseButton(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button); // Send a mouse button event with a click count -extern int SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks); +extern void SDL_SendMouseButtonClicks(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, Uint8 state, Uint8 button, int clicks); // Send a mouse wheel event -extern int SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction); +extern void SDL_SendMouseWheel(Uint64 timestamp, SDL_Window *window, SDL_MouseID mouseID, float x, float y, SDL_MouseWheelDirection direction); // Warp the mouse within the window, potentially overriding relative mode extern void SDL_PerformWarpMouseInWindow(SDL_Window *window, float x, float y, bool ignore_relative_mode); // Relative mouse mode -extern int SDL_SetRelativeMouseMode(bool enabled); +extern bool SDL_SetRelativeMouseMode(bool enabled); extern bool SDL_GetRelativeMouseMode(void); extern void SDL_UpdateRelativeMouseMode(void); extern void SDL_DisableMouseWarpEmulation(void); diff --git a/src/events/SDL_pen.c b/src/events/SDL_pen.c index b7ef12b286..6ef721d1c0 100644 --- a/src/events/SDL_pen.c +++ b/src/events/SDL_pen.c @@ -44,7 +44,7 @@ static SDL_RWLock *pen_device_rwlock = NULL; static SDL_Pen *pen_devices SDL_GUARDED_BY(pen_device_rwlock) = NULL; static int pen_device_count SDL_GUARDED_BY(pen_device_rwlock) = 0; -// You must hold pen_device_rwlock before calling this, and retval is only safe while lock is held! +// You must hold pen_device_rwlock before calling this, and result is only safe while lock is held! // If SDL isn't initialized, grabbing the NULL lock is a no-op and there will be zero devices, so // locking and calling this in that case will do the right thing. static SDL_Pen *FindPenByInstanceId(SDL_PenID instance_id) SDL_REQUIRES_SHARED(pen_device_rwlock) @@ -62,46 +62,46 @@ static SDL_Pen *FindPenByInstanceId(SDL_PenID instance_id) SDL_REQUIRES_SHARED(p SDL_PenID SDL_FindPenByHandle(void *handle) { - SDL_PenID retval = 0; + SDL_PenID result = 0; SDL_LockRWLockForReading(pen_device_rwlock); for (int i = 0; i < pen_device_count; i++) { if (pen_devices[i].driverdata == handle) { - retval = pen_devices[i].instance_id; + result = pen_devices[i].instance_id; break; } } SDL_UnlockRWLock(pen_device_rwlock); - return retval; + return result; } SDL_PenID SDL_FindPenByCallback(bool (*callback)(void *handle, void *userdata), void *userdata) { - SDL_PenID retval = 0; + SDL_PenID result = 0; SDL_LockRWLockForReading(pen_device_rwlock); for (int i = 0; i < pen_device_count; i++) { if (callback(pen_devices[i].driverdata, userdata)) { - retval = pen_devices[i].instance_id; + result = pen_devices[i].instance_id; break; } } SDL_UnlockRWLock(pen_device_rwlock); - return retval; + return result; } // public API ... -int SDL_InitPen(void) +bool SDL_InitPen(void) { SDL_assert(pen_device_rwlock == NULL); SDL_assert(pen_devices == NULL); SDL_assert(pen_device_count == 0); pen_device_rwlock = SDL_CreateRWLock(); if (!pen_device_rwlock) { - return -1; + return false; } - return 0; + return true; } void SDL_QuitPen(void) @@ -118,19 +118,19 @@ SDL_PenID *SDL_GetPens(int *count) { SDL_LockRWLockForReading(pen_device_rwlock); const int num_devices = pen_device_count; - SDL_PenID *retval = (SDL_PenID *) SDL_malloc((num_devices + 1) * sizeof (SDL_PenID)); - if (retval) { + SDL_PenID *result = (SDL_PenID *) SDL_malloc((num_devices + 1) * sizeof (SDL_PenID)); + if (result) { for (int i = 0; i < num_devices; i++) { - retval[i] = pen_devices[i].instance_id; + result[i] = pen_devices[i].instance_id; } - retval[num_devices] = 0; // null-terminated. + result[num_devices] = 0; // null-terminated. } SDL_UnlockRWLock(pen_device_rwlock); if (count) { - *count = retval ? num_devices : 0; + *count = result ? num_devices : 0; } - return retval; + return result; } const char *SDL_GetPenName(SDL_PenID instance_id) @@ -142,20 +142,20 @@ const char *SDL_GetPenName(SDL_PenID instance_id) return result; } -int SDL_GetPenInfo(SDL_PenID instance_id, SDL_PenInfo *info) +SDL_bool SDL_GetPenInfo(SDL_PenID instance_id, SDL_PenInfo *info) { SDL_LockRWLockForReading(pen_device_rwlock); const SDL_Pen *pen = FindPenByInstanceId(instance_id); - const int retval = pen ? 0 : -1; + const bool result = pen ? true : false; if (info) { - if (retval == 0) { + if (result) { SDL_copyp(info, &pen->info); } else { SDL_zerop(info); } } SDL_UnlockRWLock(pen_device_rwlock); - return retval; + return result; } SDL_PenInputFlags SDL_GetPenStatus(SDL_PenID instance_id, float *axes, int num_axes) @@ -166,9 +166,9 @@ SDL_PenInputFlags SDL_GetPenStatus(SDL_PenID instance_id, float *axes, int num_a SDL_LockRWLockForReading(pen_device_rwlock); const SDL_Pen *pen = FindPenByInstanceId(instance_id); - SDL_PenInputFlags retval = 0; + SDL_PenInputFlags result = 0; if (pen) { - retval = pen->input_state; + result = pen->input_state; if (axes && num_axes) { SDL_memcpy(axes, pen->axes, SDL_min(num_axes, SDL_PEN_NUM_AXES) * sizeof (*axes)); // zero out axes we don't know about, in case the caller built with newer SDL headers that support more of them. @@ -178,16 +178,16 @@ SDL_PenInputFlags SDL_GetPenStatus(SDL_PenID instance_id, float *axes, int num_a } } SDL_UnlockRWLock(pen_device_rwlock); - return retval; + return result; } bool SDL_PenConnected(SDL_PenID instance_id) { SDL_LockRWLockForReading(pen_device_rwlock); const SDL_Pen *pen = FindPenByInstanceId(instance_id); - const bool retval = (pen != NULL); + const bool result = (pen != NULL); SDL_UnlockRWLock(pen_device_rwlock); - return retval; + return result; } #endif @@ -212,20 +212,20 @@ SDL_PenID SDL_AddPenDevice(Uint64 timestamp, const char *name, const SDL_PenInfo return 0; } - SDL_PenID retval = 0; + SDL_PenID result = 0; SDL_LockRWLockForWriting(pen_device_rwlock); SDL_Pen *pen = NULL; void *ptr = SDL_realloc(pen_devices, (pen_device_count + 1) * sizeof (*pen)); if (ptr) { - retval = (SDL_PenID) SDL_GetNextObjectID(); + result = (SDL_PenID) SDL_GetNextObjectID(); pen_devices = (SDL_Pen *) ptr; pen = &pen_devices[pen_device_count]; pen_device_count++; SDL_zerop(pen); - pen->instance_id = retval; + pen->instance_id = result; pen->name = namecpy; if (info) { SDL_copyp(&pen->info, info); @@ -239,16 +239,16 @@ SDL_PenID SDL_AddPenDevice(Uint64 timestamp, const char *name, const SDL_PenInfo SDL_free(namecpy); } - if (retval && SDL_EventEnabled(SDL_EVENT_PEN_PROXIMITY_IN)) { + if (result && SDL_EventEnabled(SDL_EVENT_PEN_PROXIMITY_IN)) { SDL_Event event; SDL_zero(event); event.pproximity.type = SDL_EVENT_PEN_PROXIMITY_IN; event.pproximity.timestamp = timestamp; - event.pproximity.which = retval; + event.pproximity.which = result; SDL_PushEvent(&event); } - return retval; + return result; } void SDL_RemovePenDevice(Uint64 timestamp, SDL_PenID instance_id) @@ -309,9 +309,9 @@ void SDL_RemoveAllPenDevices(void (*callback)(SDL_PenID instance_id, void *handl SDL_UnlockRWLock(pen_device_rwlock); } -int SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 eraser) +void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 eraser) { - bool push_event = false; + bool send_event = false; SDL_PenInputFlags input_state = 0; float x = 0.0f; float y = 0.0f; @@ -329,28 +329,27 @@ int SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window * if (state && ((input_state & SDL_PEN_INPUT_DOWN) == 0)) { input_state |= SDL_PEN_INPUT_DOWN; - push_event = true; + send_event = true; } else if (!state && (input_state & SDL_PEN_INPUT_DOWN)) { input_state &= ~SDL_PEN_INPUT_DOWN; - push_event = true; + send_event = true; } if (eraser && ((input_state & SDL_PEN_INPUT_ERASER_TIP) == 0)) { input_state |= SDL_PEN_INPUT_ERASER_TIP; - push_event = true; + send_event = true; } else if (!state && (input_state & SDL_PEN_INPUT_ERASER_TIP)) { input_state &= ~SDL_PEN_INPUT_ERASER_TIP; - push_event = true; + send_event = true; } pen->input_state = input_state; // we could do an SDL_AtomicSet here if we run into trouble... } SDL_UnlockRWLock(pen_device_rwlock); - int posted = 0; - if (push_event) { + if (send_event) { const SDL_EventType evtype = state ? SDL_EVENT_PEN_DOWN : SDL_EVENT_PEN_UP; - if (push_event && SDL_EventEnabled(evtype)) { + if (send_event && SDL_EventEnabled(evtype)) { SDL_Event event; SDL_zero(event); event.ptouch.type = evtype; @@ -362,18 +361,16 @@ int SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window * event.ptouch.y = y; event.ptouch.eraser = eraser ? 1 : 0; event.ptouch.state = state ? SDL_PRESSED : SDL_RELEASED; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } } - - return posted; } -int SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, SDL_PenAxis axis, float value) +void SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, SDL_PenAxis axis, float value) { SDL_assert((axis >= 0) && (axis < SDL_PEN_NUM_AXES)); // fix the backend if this triggers. - bool push_event = false; + bool send_event = false; SDL_PenInputFlags input_state = 0; float x = 0.0f; float y = 0.0f; @@ -390,13 +387,12 @@ int SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *w input_state = pen->input_state; x = pen->x; y = pen->y; - push_event = true; + send_event = true; } } SDL_UnlockRWLock(pen_device_rwlock); - int posted = 0; - if (push_event && SDL_EventEnabled(SDL_EVENT_PEN_AXIS)) { + if (send_event && SDL_EventEnabled(SDL_EVENT_PEN_AXIS)) { SDL_Event event; SDL_zero(event); event.paxis.type = SDL_EVENT_PEN_AXIS; @@ -408,15 +404,13 @@ int SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *w event.paxis.y = y; event.paxis.axis = axis; event.paxis.value = value; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - - return posted; } -int SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, float x, float y) +void SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, float x, float y) { - bool push_event = false; + bool send_event = false; SDL_PenInputFlags input_state = 0; // note that this locks for _reading_ because the lock protects the @@ -430,13 +424,12 @@ int SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window pen->x = x; // we could do an SDL_AtomicSet here if we run into trouble... pen->y = y; // we could do an SDL_AtomicSet here if we run into trouble... input_state = pen->input_state; - push_event = true; + send_event = true; } } SDL_UnlockRWLock(pen_device_rwlock); - int posted = 0; - if (push_event && SDL_EventEnabled(SDL_EVENT_PEN_MOTION)) { + if (send_event && SDL_EventEnabled(SDL_EVENT_PEN_MOTION)) { SDL_Event event; SDL_zero(event); event.pmotion.type = SDL_EVENT_PEN_MOTION; @@ -446,22 +439,21 @@ int SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window event.pmotion.pen_state = input_state; event.pmotion.x = x; event.pmotion.y = y; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - - return posted; } -int SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 button) +void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 button) { - if ((button < 1) || (button > 5)) { - return 0; // clamp for now. - } - bool push_event = false; + bool send_event = false; SDL_PenInputFlags input_state = 0; float x = 0.0f; float y = 0.0f; + if ((button < 1) || (button > 5)) { + return; // clamp for now. + } + // note that this locks for _reading_ because the lock protects the // pen_devices array from being reallocated from under us, not the data in it; // we assume only one thread (in the backend) is modifying an individual pen at @@ -476,19 +468,18 @@ int SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window y = pen->y; if (state && !current) { input_state |= flag; - push_event = true; + send_event = true; } else if (!state && current) { input_state &= ~flag; - push_event = true; + send_event = true; } pen->input_state = input_state; // we could do an SDL_AtomicSet here if we run into trouble... } SDL_UnlockRWLock(pen_device_rwlock); - int posted = 0; - if (push_event) { + if (send_event) { const SDL_EventType evtype = state ? SDL_EVENT_PEN_BUTTON_DOWN : SDL_EVENT_PEN_BUTTON_UP; - if (push_event && SDL_EventEnabled(evtype)) { + if (SDL_EventEnabled(evtype)) { SDL_Event event; SDL_zero(event); event.pbutton.type = evtype; @@ -500,10 +491,8 @@ int SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window event.pbutton.y = y; event.pbutton.button = button; event.pbutton.state = state ? SDL_PRESSED : SDL_RELEASED; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } } - - return posted; } diff --git a/src/events/SDL_pen_c.h b/src/events/SDL_pen_c.h index df3d944cbe..fba1e4e2c7 100644 --- a/src/events/SDL_pen_c.h +++ b/src/events/SDL_pen_c.h @@ -68,16 +68,16 @@ extern void SDL_RemovePenDevice(Uint64 timestamp, SDL_PenID instance_id); extern void SDL_RemoveAllPenDevices(void (*callback)(SDL_PenID instance_id, void *handle, void *userdata), void *userdata); // Backend calls this when a pen's button changes, to generate events and update state. -extern int SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 eraser); +extern void SDL_SendPenTouch(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 eraser); // Backend calls this when a pen moves on the tablet, to generate events and update state. -extern int SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, float x, float y); +extern void SDL_SendPenMotion(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, float x, float y); // Backend calls this when a pen's axis changes, to generate events and update state. -extern int SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, SDL_PenAxis axis, float value); +extern void SDL_SendPenAxis(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, SDL_PenAxis axis, float value); // Backend calls this when a pen's button changes, to generate events and update state. -extern int SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 button); +extern void SDL_SendPenButton(Uint64 timestamp, SDL_PenID instance_id, const SDL_Window *window, Uint8 state, Uint8 button); // Backend can optionally use this to find the SDL_PenID for the `handle` that was passed to SDL_AddPenDevice. extern SDL_PenID SDL_FindPenByHandle(void *handle); @@ -89,7 +89,7 @@ extern SDL_PenID SDL_FindPenByCallback(bool (*callback)(void *handle, void *user SDL_PenCapabilityFlags SDL_GetPenCapabilityFromAxis(SDL_PenAxis axis); // Higher-level SDL video subsystem code calls this when starting up. Backends shouldn't. -extern int SDL_InitPen(void); +extern bool SDL_InitPen(void); // Higher-level SDL video subsystem code calls this when shutting down. Backends shouldn't. extern void SDL_QuitPen(void); diff --git a/src/events/SDL_quit.c b/src/events/SDL_quit.c index dc3b6c84d7..c408291eb7 100644 --- a/src/events/SDL_quit.c +++ b/src/events/SDL_quit.c @@ -108,7 +108,7 @@ static void SDL_EventSignal_Quit(const int sig) } // Public functions -static int SDL_QuitInit_Internal(void) +static bool SDL_QuitInit_Internal(void) { // Both SIGINT and SIGTERM are translated into quit interrupts // and SDL can be built to simulate iOS/Android semantics with arbitrary signals. @@ -124,7 +124,7 @@ static int SDL_QuitInit_Internal(void) #endif // That's it! - return 0; + return true; } static void SDL_QuitQuit_Internal(void) @@ -142,14 +142,14 @@ static void SDL_QuitQuit_Internal(void) } #endif -int SDL_InitQuit(void) +bool SDL_InitQuit(void) { #ifdef HAVE_SIGNAL_SUPPORT if (!SDL_GetHintBoolean(SDL_HINT_NO_SIGNAL_HANDLERS, false)) { return SDL_QuitInit_Internal(); } #endif - return 0; + return true; } void SDL_QuitQuit(void) @@ -185,11 +185,10 @@ void SDL_SendPendingSignalEvents(void) #endif } -// This function returns 1 if it's okay to close the application window -int SDL_SendQuit(void) +void SDL_SendQuit(void) { #ifdef HAVE_SIGNAL_SUPPORT send_quit_pending = false; #endif - return SDL_SendAppEvent(SDL_EVENT_QUIT); + SDL_SendAppEvent(SDL_EVENT_QUIT); } diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index d560e65665..19c4db7199 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -39,9 +39,9 @@ static SDL_TouchID track_touchid; #endif // Public functions -int SDL_InitTouch(void) +bool SDL_InitTouch(void) { - return 0; + return true; } bool SDL_TouchDevicesAvailable(void) @@ -56,18 +56,18 @@ SDL_TouchID *SDL_GetTouchDevices(int *count) } const int total = SDL_num_touch; - SDL_TouchID *retval = (SDL_TouchID *) SDL_malloc(sizeof (SDL_TouchID) * (total + 1)); - if (retval) { + SDL_TouchID *result = (SDL_TouchID *) SDL_malloc(sizeof (SDL_TouchID) * (total + 1)); + if (result) { for (int i = 0; i < total; i++) { - retval[i] = SDL_touchDevices[i]->id; + result[i] = SDL_touchDevices[i]->id; } - retval[total] = 0; + result[total] = 0; if (count) { *count = SDL_num_touch; } } - return retval; + return result; } static int SDL_GetTouchIndex(SDL_TouchID id) @@ -208,7 +208,7 @@ int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name return index; } -static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure) +static bool SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float y, float pressure) { SDL_Finger *finger; @@ -218,12 +218,12 @@ static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float SDL_Finger **new_fingers; new_fingers = (SDL_Finger **)SDL_realloc(touch->fingers, (touch->max_fingers + 1) * sizeof(*touch->fingers)); if (!new_fingers) { - return -1; + return false; } touch->fingers = new_fingers; touch->fingers[touch->max_fingers] = (SDL_Finger *)SDL_malloc(sizeof(*finger)); if (!touch->fingers[touch->max_fingers]) { - return -1; + return false; } touch->max_fingers++; } @@ -233,14 +233,14 @@ static int SDL_AddFinger(SDL_Touch *touch, SDL_FingerID fingerid, float x, float finger->x = x; finger->y = y; finger->pressure = pressure; - return 0; + return true; } -static int SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid) +static void SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid) { int index = SDL_GetFingerIndex(touch, fingerid); if (index < 0) { - return -1; + return; } --touch->num_fingers; @@ -252,18 +252,16 @@ static int SDL_DelFinger(SDL_Touch *touch, SDL_FingerID fingerid) SDL_memmove(&touch->fingers[index], &touch->fingers[index + 1], (touch->num_fingers - index) * sizeof(touch->fingers[index])); touch->fingers[touch->num_fingers] = deleted_finger; } - return 0; } -int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, bool down, float x, float y, float pressure) +void SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, bool down, float x, float y, float pressure) { - int posted; SDL_Finger *finger; SDL_Mouse *mouse; SDL_Touch *touch = SDL_GetTouch(id); if (!touch) { - return -1; + return; } mouse = SDL_GetMouse(); @@ -324,7 +322,7 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W // SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer if (mouse->mouse_touch_events == 0) { if (id == SDL_MOUSE_TOUCHID) { - return 0; + return; } } @@ -336,11 +334,10 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W SDL_SendTouch(timestamp, id, fingerid, window, false, x, y, pressure); } - if (SDL_AddFinger(touch, fingerid, x, y, pressure) < 0) { - return 0; + if (!SDL_AddFinger(touch, fingerid, x, y, pressure)) { + return; } - posted = 0; if (SDL_EventEnabled(SDL_EVENT_FINGER_DOWN)) { SDL_Event event; event.type = SDL_EVENT_FINGER_DOWN; @@ -353,15 +350,14 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W event.tfinger.dy = 0; event.tfinger.pressure = pressure; event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } } else { if (!finger) { // This finger is already up - return 0; + return; } - posted = 0; if (SDL_EventEnabled(SDL_EVENT_FINGER_UP)) { SDL_Event event; event.type = SDL_EVENT_FINGER_UP; @@ -375,26 +371,24 @@ int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_W event.tfinger.dy = 0; event.tfinger.pressure = pressure; event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } SDL_DelFinger(touch, fingerid); } - return posted; } -int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, +void SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, float x, float y, float pressure) { SDL_Touch *touch; SDL_Finger *finger; SDL_Mouse *mouse; - int posted; float xrel, yrel, prel; touch = SDL_GetTouch(id); if (!touch) { - return -1; + return; } mouse = SDL_GetMouse(); @@ -431,13 +425,14 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, // SDL_HINT_MOUSE_TOUCH_EVENTS: if not set, discard synthetic touch events coming from platform layer if (mouse->mouse_touch_events == 0) { if (id == SDL_MOUSE_TOUCHID) { - return 0; + return; } } finger = SDL_GetFinger(touch, fingerid); if (!finger) { - return SDL_SendTouch(timestamp, id, fingerid, window, true, x, y, pressure); + SDL_SendTouch(timestamp, id, fingerid, window, true, x, y, pressure); + return; } xrel = x - finger->x; @@ -449,7 +444,7 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, #if 0 printf("Touch event didn't change state - dropped!\n"); #endif - return 0; + return; } // Update internal touch coordinates @@ -458,7 +453,6 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, finger->pressure = pressure; // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_FINGER_MOTION)) { SDL_Event event; event.type = SDL_EVENT_FINGER_MOTION; @@ -471,9 +465,8 @@ int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, event.tfinger.dy = yrel; event.tfinger.pressure = pressure; event.tfinger.windowID = window ? SDL_GetWindowID(window) : 0; - posted = (SDL_PushEvent(&event) > 0); + SDL_PushEvent(&event); } - return posted; } void SDL_DelTouch(SDL_TouchID id) diff --git a/src/events/SDL_touch_c.h b/src/events/SDL_touch_c.h index 7da34f6432..43e4fd1720 100644 --- a/src/events/SDL_touch_c.h +++ b/src/events/SDL_touch_c.h @@ -34,7 +34,7 @@ typedef struct SDL_Touch } SDL_Touch; // Initialize the touch subsystem -extern int SDL_InitTouch(void); +extern bool SDL_InitTouch(void); // Returns true if _any_ connected touch devices are known to SDL extern bool SDL_TouchDevicesAvailable(void); @@ -46,10 +46,10 @@ extern int SDL_AddTouch(SDL_TouchID id, SDL_TouchDeviceType type, const char *na extern SDL_Touch *SDL_GetTouch(SDL_TouchID id); // Send a touch down/up event for a touch -extern int SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, bool down, float x, float y, float pressure); +extern void SDL_SendTouch(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, bool down, float x, float y, float pressure); // Send a touch motion event for a touch -extern int SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, float x, float y, float pressure); +extern void SDL_SendTouchMotion(Uint64 timestamp, SDL_TouchID id, SDL_FingerID fingerid, SDL_Window *window, float x, float y, float pressure); // Remove a touch extern void SDL_DelTouch(SDL_TouchID id); diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c index bcb7927acc..82b39939ac 100644 --- a/src/events/SDL_windowevents.c +++ b/src/events/SDL_windowevents.c @@ -38,29 +38,28 @@ static SDL_bool SDLCALL RemoveSupercededWindowEvents(void *userdata, SDL_Event * return true; } -int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, - int data1, int data2) +bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data1, int data2) { - int posted; + bool posted = false; if (!window) { - return 0; + return false; } SDL_assert(SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW)); if (window->is_destroying && windowevent != SDL_EVENT_WINDOW_DESTROYED) { - return 0; + return false; } switch (windowevent) { case SDL_EVENT_WINDOW_SHOWN: if (!(window->flags & SDL_WINDOW_HIDDEN)) { - return 0; + return false; } window->flags &= ~(SDL_WINDOW_HIDDEN | SDL_WINDOW_MINIMIZED); break; case SDL_EVENT_WINDOW_HIDDEN: if (window->flags & SDL_WINDOW_HIDDEN) { - return 0; + return false; } window->flags |= SDL_WINDOW_HIDDEN; break; @@ -80,7 +79,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, } } if (data1 == window->x && data2 == window->y) { - return 0; + return false; } window->x = data1; window->y = data2; @@ -97,83 +96,83 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, } if (data1 == window->w && data2 == window->h) { SDL_CheckWindowPixelSizeChanged(window); - return 0; + return false; } window->w = data1; window->h = data2; break; case SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED: if (data1 == window->last_pixel_w && data2 == window->last_pixel_h) { - return 0; + return false; } window->last_pixel_w = data1; window->last_pixel_h = data2; break; case SDL_EVENT_WINDOW_MINIMIZED: if (window->flags & SDL_WINDOW_MINIMIZED) { - return 0; + return false; } window->flags &= ~SDL_WINDOW_MAXIMIZED; window->flags |= SDL_WINDOW_MINIMIZED; break; case SDL_EVENT_WINDOW_MAXIMIZED: if (window->flags & SDL_WINDOW_MAXIMIZED) { - return 0; + return false; } window->flags &= ~SDL_WINDOW_MINIMIZED; window->flags |= SDL_WINDOW_MAXIMIZED; break; case SDL_EVENT_WINDOW_RESTORED: if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) { - return 0; + return false; } window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED); break; case SDL_EVENT_WINDOW_MOUSE_ENTER: if (window->flags & SDL_WINDOW_MOUSE_FOCUS) { - return 0; + return false; } window->flags |= SDL_WINDOW_MOUSE_FOCUS; break; case SDL_EVENT_WINDOW_MOUSE_LEAVE: if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) { - return 0; + return false; } window->flags &= ~SDL_WINDOW_MOUSE_FOCUS; break; case SDL_EVENT_WINDOW_FOCUS_GAINED: if (window->flags & SDL_WINDOW_INPUT_FOCUS) { - return 0; + return false; } window->flags |= SDL_WINDOW_INPUT_FOCUS; break; case SDL_EVENT_WINDOW_FOCUS_LOST: if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) { - return 0; + return false; } window->flags &= ~SDL_WINDOW_INPUT_FOCUS; break; case SDL_EVENT_WINDOW_DISPLAY_CHANGED: if (data1 == 0 || (SDL_DisplayID)data1 == window->last_displayID) { - return 0; + return false; } window->last_displayID = (SDL_DisplayID)data1; break; case SDL_EVENT_WINDOW_OCCLUDED: if (window->flags & SDL_WINDOW_OCCLUDED) { - return 0; + return false; } window->flags |= SDL_WINDOW_OCCLUDED; break; case SDL_EVENT_WINDOW_ENTER_FULLSCREEN: if (window->flags & SDL_WINDOW_FULLSCREEN) { - return 0; + return false; } window->flags |= SDL_WINDOW_FULLSCREEN; break; case SDL_EVENT_WINDOW_LEAVE_FULLSCREEN: if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { - return 0; + return false; } window->flags &= ~SDL_WINDOW_FULLSCREEN; break; @@ -182,7 +181,6 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, } // Post the event, if desired - posted = 0; if (SDL_EventEnabled(windowevent)) { SDL_Event event; event.type = windowevent; @@ -200,7 +198,7 @@ int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, windowevent == SDL_EVENT_WINDOW_OCCLUDED) { SDL_FilterEvents(RemoveSupercededWindowEvents, &event); } - posted = (SDL_PushEvent(&event) > 0); + posted = SDL_PushEvent(&event); } switch (windowevent) { diff --git a/src/events/SDL_windowevents_c.h b/src/events/SDL_windowevents_c.h index 715a947200..addab6efe9 100644 --- a/src/events/SDL_windowevents_c.h +++ b/src/events/SDL_windowevents_c.h @@ -23,7 +23,6 @@ #ifndef SDL_windowevents_c_h_ #define SDL_windowevents_c_h_ -extern int SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, - int data1, int data2); +extern bool SDL_SendWindowEvent(SDL_Window *window, SDL_EventType windowevent, int data1, int data2); #endif // SDL_windowevents_c_h_ diff --git a/src/file/SDL_iostream.c b/src/file/SDL_iostream.c index 1fe2bbd690..0ec5ef5f66 100644 --- a/src/file/SDL_iostream.c +++ b/src/file/SDL_iostream.c @@ -73,7 +73,7 @@ typedef struct IOStreamWindowsData #define READAHEAD_BUFFER_SIZE 1024 -static int SDLCALL windows_file_open(IOStreamWindowsData *iodata, const char *filename, const char *mode) +static bool SDLCALL windows_file_open(IOStreamWindowsData *iodata, const char *filename, const char *mode) { #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) && !defined(SDL_PLATFORM_WINRT) UINT old_error_mode; @@ -100,13 +100,13 @@ static int SDLCALL windows_file_open(IOStreamWindowsData *iodata, const char *fi w_right = (a_mode || SDL_strchr(mode, '+') || truncate) ? GENERIC_WRITE : 0; if (!r_right && !w_right) { - return -1; // inconsistent mode + return false; // inconsistent mode } // failed (invalid call) iodata->data = (char *)SDL_malloc(READAHEAD_BUFFER_SIZE); if (!iodata->data) { - return -1; + return false; } #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) && !defined(SDL_PLATFORM_WINRT) // Do not open a dialog box if failure @@ -147,12 +147,12 @@ static int SDLCALL windows_file_open(IOStreamWindowsData *iodata, const char *fi SDL_free(iodata->data); iodata->data = NULL; SDL_SetError("Couldn't open %s", filename); - return -2; // failed (CreateFile) + return false; // failed (CreateFile) } iodata->h = h; iodata->append = a_mode ? true : false; - return 0; // ok + return true; // ok } static Sint64 SDLCALL windows_file_size(void *userdata) @@ -190,7 +190,8 @@ static Sint64 SDLCALL windows_file_seek(void *userdata, Sint64 offset, SDL_IOWhe windowswhence = FILE_END; break; default: - return SDL_SetError("windows_file_seek: Unknown value for 'whence'"); + SDL_SetError("windows_file_seek: Unknown value for 'whence'"); + return -1; } windowsoffset.QuadPart = offset; @@ -276,7 +277,7 @@ static size_t SDLCALL windows_file_write(void *userdata, const void *ptr, size_t return bytes; } -static int SDLCALL windows_file_close(void *userdata) +static SDL_bool SDLCALL windows_file_close(void *userdata) { IOStreamWindowsData *iodata = (IOStreamWindowsData *) userdata; if (iodata->h != INVALID_HANDLE_VALUE) { @@ -285,7 +286,7 @@ static int SDLCALL windows_file_close(void *userdata) } SDL_free(iodata->data); SDL_free(iodata); - return 0; + return SDL_TRUE; } #endif // defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) @@ -351,12 +352,14 @@ static Sint64 SDLCALL stdio_seek(void *userdata, Sint64 offset, SDL_IOWhence whe stdiowhence = SEEK_END; break; default: - return SDL_SetError("Unknown value for 'whence'"); + SDL_SetError("Unknown value for 'whence'"); + return -1; } #if defined(FSEEK_OFF_MIN) && defined(FSEEK_OFF_MAX) if (offset < (Sint64)(FSEEK_OFF_MIN) || offset > (Sint64)(FSEEK_OFF_MAX)) { - return SDL_SetError("Seek offset out of range"); + SDL_SetError("Seek offset out of range"); + return -1; } #endif @@ -366,11 +369,13 @@ static Sint64 SDLCALL stdio_seek(void *userdata, Sint64 offset, SDL_IOWhence whe if (is_noop || fseek(iodata->fp, (fseek_off_t)offset, stdiowhence) == 0) { const Sint64 pos = ftell(iodata->fp); if (pos < 0) { - return SDL_SetError("Couldn't get stream offset"); + SDL_SetError("Couldn't get stream offset"); + return -1; } return pos; } - return SDL_SetError("Error seeking in datastream"); + SDL_SetError("Error seeking in datastream"); + return -1; } static size_t SDLCALL stdio_read(void *userdata, void *ptr, size_t size, SDL_IOStatus *status) @@ -393,10 +398,10 @@ static size_t SDLCALL stdio_write(void *userdata, const void *ptr, size_t size, return bytes; } -static int SDLCALL stdio_close(void *userdata) +static SDL_bool SDLCALL stdio_close(void *userdata) { IOStreamStdioData *iodata = (IOStreamStdioData *) userdata; - int status = 0; + bool status = true; if (iodata->autoclose) { if (fclose(iodata->fp) != 0) { status = SDL_SetError("Error writing to datastream"); @@ -469,7 +474,8 @@ static Sint64 SDLCALL mem_seek(void *userdata, Sint64 offset, SDL_IOWhence whenc newpos = iodata->stop + offset; break; default: - return SDL_SetError("Unknown value for 'whence'"); + SDL_SetError("Unknown value for 'whence'"); + return -1; } if (newpos < iodata->base) { newpos = iodata->base; @@ -505,10 +511,10 @@ static size_t SDLCALL mem_write(void *userdata, const void *ptr, size_t size, SD return mem_io(userdata, iodata->here, ptr, size); } -static int SDLCALL mem_close(void *userdata) +static SDL_bool SDLCALL mem_close(void *userdata) { SDL_free(userdata); - return 0; + return SDL_TRUE; } // Functions to create SDL_IOStream structures from various data sources @@ -596,7 +602,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode) // Try to open the file from the asset system void *iodata = NULL; - if (Android_JNI_FileOpen(&iodata, file, mode) < 0) { + if (!Android_JNI_FileOpen(&iodata, file, mode)) { return NULL; } @@ -624,7 +630,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode) return NULL; } - if (windows_file_open(iodata, file, mode) < 0) { + if (!windows_file_open(iodata, file, mode)) { windows_file_close(iodata); return NULL; } @@ -769,7 +775,7 @@ static size_t SDLCALL dynamic_mem_read(void *userdata, void *ptr, size_t size, S return mem_io(&iodata->data, ptr, iodata->data.here, size); } -static int dynamic_mem_realloc(IOStreamDynamicMemData *iodata, size_t size) +static bool dynamic_mem_realloc(IOStreamDynamicMemData *iodata, size_t size) { size_t chunksize = (size_t)SDL_GetNumberProperty(SDL_GetIOProperties(iodata->stream), SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER, 0); if (!chunksize) { @@ -781,7 +787,7 @@ static int dynamic_mem_realloc(IOStreamDynamicMemData *iodata, size_t size) size_t length = (chunks * chunksize); Uint8 *base = (Uint8 *)SDL_realloc(iodata->data.base, length); if (!base) { - return -1; + return false; } size_t here_offset = (iodata->data.here - iodata->data.base); @@ -798,7 +804,7 @@ static size_t SDLCALL dynamic_mem_write(void *userdata, const void *ptr, size_t IOStreamDynamicMemData *iodata = (IOStreamDynamicMemData *) userdata; if (size > (size_t)(iodata->data.stop - iodata->data.here)) { if (size > (size_t)(iodata->end - iodata->data.here)) { - if (dynamic_mem_realloc(iodata, size) < 0) { + if (!dynamic_mem_realloc(iodata, size)) { return 0; } } @@ -807,7 +813,7 @@ static size_t SDLCALL dynamic_mem_write(void *userdata, const void *ptr, size_t return mem_io(&iodata->data, iodata->data.here, ptr, size); } -static int SDLCALL dynamic_mem_close(void *userdata) +static SDL_bool SDLCALL dynamic_mem_close(void *userdata) { const IOStreamDynamicMemData *iodata = (IOStreamDynamicMemData *) userdata; void *mem = SDL_GetPointerProperty(SDL_GetIOProperties(iodata->stream), SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER, NULL); @@ -815,7 +821,7 @@ static int SDLCALL dynamic_mem_close(void *userdata) SDL_free(mem); } SDL_free(userdata); - return 0; + return true; } SDL_IOStream *SDL_IOFromDynamicMem(void) @@ -871,17 +877,17 @@ SDL_IOStream *SDL_OpenIO(const SDL_IOStreamInterface *iface, void *userdata) return iostr; } -int SDL_CloseIO(SDL_IOStream *iostr) +SDL_bool SDL_CloseIO(SDL_IOStream *iostr) { - int retval = 0; + bool result = true; if (iostr) { if (iostr->iface.close) { - retval = iostr->iface.close(iostr->userdata); + result = iostr->iface.close(iostr->userdata); } SDL_DestroyProperties(iostr->props); SDL_free(iostr); } - return retval; + return result; } // Load all the data from an SDL data stream diff --git a/src/filesystem/SDL_filesystem.c b/src/filesystem/SDL_filesystem.c index d6d51265c5..25e2d316e4 100644 --- a/src/filesystem/SDL_filesystem.c +++ b/src/filesystem/SDL_filesystem.c @@ -25,7 +25,7 @@ #include "SDL_sysfilesystem.h" #include "../stdlib/SDL_sysstdlib.h" -int SDL_RemovePath(const char *path) +SDL_bool SDL_RemovePath(const char *path) { if (!path) { return SDL_InvalidParamError("path"); @@ -33,7 +33,7 @@ int SDL_RemovePath(const char *path) return SDL_SYS_RemovePath(path); } -int SDL_RenamePath(const char *oldpath, const char *newpath) +SDL_bool SDL_RenamePath(const char *oldpath, const char *newpath) { if (!oldpath) { return SDL_InvalidParamError("oldpath"); @@ -43,7 +43,7 @@ int SDL_RenamePath(const char *oldpath, const char *newpath) return SDL_SYS_RenamePath(oldpath, newpath); } -int SDL_CopyFile(const char *oldpath, const char *newpath) +SDL_bool SDL_CopyFile(const char *oldpath, const char *newpath) { if (!oldpath) { return SDL_InvalidParamError("oldpath"); @@ -53,7 +53,7 @@ int SDL_CopyFile(const char *oldpath, const char *newpath) return SDL_SYS_CopyFile(oldpath, newpath); } -int SDL_CreateDirectory(const char *path) +SDL_bool SDL_CreateDirectory(const char *path) { // TODO: Recursively create subdirectories if (!path) { @@ -62,17 +62,20 @@ int SDL_CreateDirectory(const char *path) return SDL_SYS_CreateDirectory(path); } -int SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata) +SDL_bool SDL_EnumerateDirectory(const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata) { if (!path) { return SDL_InvalidParamError("path"); } else if (!callback) { return SDL_InvalidParamError("callback"); } - return (SDL_SYS_EnumerateDirectory(path, path, callback, userdata) < 0) ? -1 : 0; + if (SDL_SYS_EnumerateDirectory(path, path, callback, userdata) < 0) { + return false; + } + return true; } -int SDL_GetPathInfo(const char *path, SDL_PathInfo *info) +SDL_bool SDL_GetPathInfo(const char *path, SDL_PathInfo *info) { SDL_PathInfo dummy; @@ -189,13 +192,13 @@ static char *CaseFoldUtf8String(const char *fname) { SDL_assert(fname != NULL); const size_t allocation = (SDL_strlen(fname) + 1) * 3 * 4; - char *retval = (char *) SDL_malloc(allocation); // lazy: just allocating the max needed. - if (!retval) { + char *result = (char *) SDL_malloc(allocation); // lazy: just allocating the max needed. + if (!result) { return NULL; } Uint32 codepoint; - char *ptr = retval; + char *ptr = result; size_t remaining = allocation; while ((codepoint = SDL_StepUTF8(&fname, NULL)) != 0) { Uint32 folded[3]; @@ -218,13 +221,13 @@ static char *CaseFoldUtf8String(const char *fname) if (remaining > 0) { SDL_assert(allocation > remaining); - ptr = SDL_realloc(retval, allocation - remaining); // shrink it down. - if (ptr) { // shouldn't fail, but if it does, `retval` is still valid. - retval = ptr; + ptr = SDL_realloc(result, allocation - remaining); // shrink it down. + if (ptr) { // shouldn't fail, but if it does, `result` is still valid. + result = ptr; } } - return retval; + return result; } @@ -282,20 +285,20 @@ static int SDLCALL GlobDirectoryCallback(void *userdata, const char *dirname, co data->num_entries++; } - int retval = 1; // keep enumerating by default. + int result = 1; // keep enumerating by default. if (matched_to_dir) { SDL_PathInfo info; - if ((data->getpathinfo(fullpath, &info, data->fsuserdata) == 0) && (info.type == SDL_PATHTYPE_DIRECTORY)) { + if (data->getpathinfo(fullpath, &info, data->fsuserdata) && (info.type == SDL_PATHTYPE_DIRECTORY)) { //SDL_Log("GlobDirectoryCallback: Descending into subdir '%s'", fname); - if (data->enumerator(fullpath, GlobDirectoryCallback, data, data->fsuserdata) < 0) { - retval = -1; + if (!data->enumerator(fullpath, GlobDirectoryCallback, data, data->fsuserdata)) { + result = -1; } } } SDL_free(fullpath); - return retval; + return result; } char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata) @@ -367,24 +370,24 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob data.fsuserdata = userdata; data.basedirlen = SDL_strlen(path) + 1; // +1 for the '/' we'll be adding. - char **retval = NULL; - if (data.enumerator(path, GlobDirectoryCallback, &data, data.fsuserdata) == 0) { + char **result = NULL; + if (data.enumerator(path, GlobDirectoryCallback, &data, data.fsuserdata)) { const size_t streamlen = (size_t) SDL_GetIOSize(data.string_stream); const size_t buflen = streamlen + ((data.num_entries + 1) * sizeof (char *)); // +1 for NULL terminator at end of array. - retval = (char **) SDL_malloc(buflen); - if (retval) { + result = (char **) SDL_malloc(buflen); + if (result) { if (data.num_entries > 0) { Sint64 iorc = SDL_SeekIO(data.string_stream, 0, SDL_IO_SEEK_SET); SDL_assert(iorc == 0); // this should never fail for a memory stream! - char *ptr = (char *) (retval + (data.num_entries + 1)); + char *ptr = (char *) (result + (data.num_entries + 1)); iorc = SDL_ReadIO(data.string_stream, ptr, streamlen); SDL_assert(iorc == (Sint64) streamlen); // this should never fail for a memory stream! for (int i = 0; i < data.num_entries; i++) { - retval[i] = ptr; + result[i] = ptr; ptr += SDL_strlen(ptr) + 1; } } - retval[data.num_entries] = NULL; // NULL terminate the list. + result[data.num_entries] = NULL; // NULL terminate the list. *count = data.num_entries; } } @@ -393,15 +396,15 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob SDL_free(folded); SDL_free(pathcpy); - return retval; + return result; } -static int GlobDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata) +static SDL_bool GlobDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata) { return SDL_GetPathInfo(path, info); } -static int GlobDirectoryEnumerator(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata) +static SDL_bool GlobDirectoryEnumerator(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata) { return SDL_EnumerateDirectory(path, cb, cbuserdata); } diff --git a/src/filesystem/SDL_sysfilesystem.h b/src/filesystem/SDL_sysfilesystem.h index 83a59d20a1..615f39476d 100644 --- a/src/filesystem/SDL_sysfilesystem.h +++ b/src/filesystem/SDL_sysfilesystem.h @@ -27,16 +27,16 @@ extern char *SDL_SYS_GetBasePath(void); extern char *SDL_SYS_GetPrefPath(const char *org, const char *app); extern char *SDL_SYS_GetUserFolder(SDL_Folder folder); -int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_EnumerateDirectoryCallback cb, void *userdata); -int SDL_SYS_RemovePath(const char *path); -int SDL_SYS_RenamePath(const char *oldpath, const char *newpath); -int SDL_SYS_CopyFile(const char *oldpath, const char *newpath); -int SDL_SYS_CreateDirectory(const char *path); -int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info); +extern int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_EnumerateDirectoryCallback cb, void *userdata); +extern bool SDL_SYS_RemovePath(const char *path); +extern bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath); +extern bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath); +extern bool SDL_SYS_CreateDirectory(const char *path); +extern bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info); -typedef int (*SDL_GlobEnumeratorFunc)(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata); -typedef int (*SDL_GlobGetPathInfoFunc)(const char *path, SDL_PathInfo *info, void *userdata); -char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata); +typedef SDL_bool (*SDL_GlobEnumeratorFunc)(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata); +typedef SDL_bool (*SDL_GlobGetPathInfoFunc)(const char *path, SDL_PathInfo *info, void *userdata); +extern char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata); #endif diff --git a/src/filesystem/cocoa/SDL_sysfilesystem.m b/src/filesystem/cocoa/SDL_sysfilesystem.m index 7d140d6dcd..07a75ff74e 100644 --- a/src/filesystem/cocoa/SDL_sysfilesystem.m +++ b/src/filesystem/cocoa/SDL_sysfilesystem.m @@ -37,7 +37,7 @@ char *SDL_SYS_GetBasePath(void) NSBundle *bundle = [NSBundle mainBundle]; const char *baseType = [[[bundle infoDictionary] objectForKey:@"SDL_FILESYSTEM_BASE_DIR_TYPE"] UTF8String]; const char *base = NULL; - char *retval = NULL; + char *result = NULL; if (baseType == NULL) { baseType = "resource"; @@ -53,20 +53,20 @@ char *SDL_SYS_GetBasePath(void) if (base) { const size_t len = SDL_strlen(base) + 2; - retval = (char *)SDL_malloc(len); - if (retval != NULL) { - SDL_snprintf(retval, len, "%s/", base); + result = (char *)SDL_malloc(len); + if (result != NULL) { + SDL_snprintf(result, len, "%s/", base); } } - return retval; + return result; } } char *SDL_SYS_GetPrefPath(const char *org, const char *app) { @autoreleasepool { - char *retval = NULL; + char *result = NULL; NSArray *array; if (!app) { @@ -104,27 +104,27 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) const char *base = [str fileSystemRepresentation]; if (base) { const size_t len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4; - retval = (char *)SDL_malloc(len); - if (retval != NULL) { + result = (char *)SDL_malloc(len); + if (result != NULL) { char *ptr; if (*org) { - SDL_snprintf(retval, len, "%s/%s/%s/", base, org, app); + SDL_snprintf(result, len, "%s/%s/%s/", base, org, app); } else { - SDL_snprintf(retval, len, "%s/%s/", base, app); + SDL_snprintf(result, len, "%s/%s/", base, app); } - for (ptr = retval + 1; *ptr; ptr++) { + for (ptr = result + 1; *ptr; ptr++) { if (*ptr == '/') { *ptr = '\0'; - mkdir(retval, 0700); + mkdir(result, 0700); *ptr = '/'; } } - mkdir(retval, 0700); + mkdir(result, 0700); } } } - return retval; + return result; } } @@ -135,7 +135,7 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) SDL_SetError("tvOS does not have persistent storage"); return NULL; #else - char *retval = NULL; + char *result = NULL; const char* base; NSArray *array; NSSearchPathDirectory dir; @@ -213,26 +213,26 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) } append_slash: - retval = SDL_malloc(SDL_strlen(base) + 2); - if (retval == NULL) { + result = SDL_malloc(SDL_strlen(base) + 2); + if (result == NULL) { return NULL; } - if (SDL_snprintf(retval, SDL_strlen(base) + 2, "%s/", base) < 0) { + if (SDL_snprintf(result, SDL_strlen(base) + 2, "%s/", base) < 0) { SDL_SetError("Couldn't snprintf folder path for Cocoa: %s", base); - SDL_free(retval); + SDL_free(result); return NULL; } - for (ptr = retval + 1; *ptr; ptr++) { + for (ptr = result + 1; *ptr; ptr++) { if (*ptr == '/') { *ptr = '\0'; - mkdir(retval, 0700); + mkdir(result, 0700); *ptr = '/'; } } - return retval; + return result; #endif // SDL_PLATFORM_TVOS } } diff --git a/src/filesystem/dummy/SDL_sysfsops.c b/src/filesystem/dummy/SDL_sysfsops.c index 802a12a79e..f1acdfd07c 100644 --- a/src/filesystem/dummy/SDL_sysfsops.c +++ b/src/filesystem/dummy/SDL_sysfsops.c @@ -30,30 +30,31 @@ int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_EnumerateDirectoryCallback cb, void *userdata) { - return SDL_Unsupported(); + SDL_Unsupported(); + return -1; } -int SDL_SYS_RemovePath(const char *path) +bool SDL_SYS_RemovePath(const char *path) { return SDL_Unsupported(); } -int SDL_SYS_RenamePath(const char *oldpath, const char *newpath) +bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath) { return SDL_Unsupported(); } -int SDL_SYS_CopyFile(const char *oldpath, const char *newpath) +bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath) { return SDL_Unsupported(); } -int SDL_SYS_CreateDirectory(const char *path) +bool SDL_SYS_CreateDirectory(const char *path) { return SDL_Unsupported(); } -int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) +bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) { return SDL_Unsupported(); } diff --git a/src/filesystem/emscripten/SDL_sysfilesystem.c b/src/filesystem/emscripten/SDL_sysfilesystem.c index 31190ec67f..e10081c775 100644 --- a/src/filesystem/emscripten/SDL_sysfilesystem.c +++ b/src/filesystem/emscripten/SDL_sysfilesystem.c @@ -40,7 +40,7 @@ char *SDL_SYS_GetBasePath(void) char *SDL_SYS_GetPrefPath(const char *org, const char *app) { const char *append = "/libsdl/"; - char *retval; + char *result; char *ptr = NULL; size_t len = 0; @@ -53,35 +53,35 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) } len = SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; - retval = (char *)SDL_malloc(len); - if (!retval) { + result = (char *)SDL_malloc(len); + if (!result) { return NULL; } if (*org) { - SDL_snprintf(retval, len, "%s%s/%s/", append, org, app); + SDL_snprintf(result, len, "%s%s/%s/", append, org, app); } else { - SDL_snprintf(retval, len, "%s%s/", append, app); + SDL_snprintf(result, len, "%s%s/", append, app); } - for (ptr = retval + 1; *ptr; ptr++) { + for (ptr = result + 1; *ptr; ptr++) { if (*ptr == '/') { *ptr = '\0'; - if (mkdir(retval, 0700) != 0 && errno != EEXIST) { + if (mkdir(result, 0700) != 0 && errno != EEXIST) { goto error; } *ptr = '/'; } } - if (mkdir(retval, 0700) != 0 && errno != EEXIST) { + if (mkdir(result, 0700) != 0 && errno != EEXIST) { error: - SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno)); - SDL_free(retval); + SDL_SetError("Couldn't create directory '%s': '%s'", result, strerror(errno)); + SDL_free(result); return NULL; } - return retval; + return result; } char *SDL_SYS_GetUserFolder(SDL_Folder folder) @@ -99,18 +99,18 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) return NULL; } - char *retval = SDL_malloc(SDL_strlen(home) + 2); - if (!retval) { + char *result = SDL_malloc(SDL_strlen(home) + 2); + if (!result) { return NULL; } - if (SDL_snprintf(retval, SDL_strlen(home) + 2, "%s/", home) < 0) { + if (SDL_snprintf(result, SDL_strlen(home) + 2, "%s/", home) < 0) { SDL_SetError("Couldn't snprintf home path for Emscripten: %s", home); - SDL_free(retval); + SDL_free(result); return NULL; } - return retval; + return result; } #endif // SDL_FILESYSTEM_EMSCRIPTEN diff --git a/src/filesystem/gdk/SDL_sysfilesystem.cpp b/src/filesystem/gdk/SDL_sysfilesystem.cpp index fa8d21549c..d5fb396288 100644 --- a/src/filesystem/gdk/SDL_sysfilesystem.cpp +++ b/src/filesystem/gdk/SDL_sysfilesystem.cpp @@ -101,7 +101,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) return SDL_strdup("T:\\"); } - if (SDL_GetGDKDefaultUser(&user) < 0) { + if (!SDL_GetGDKDefaultUser(&user)) { // Error already set, just return return NULL; } diff --git a/src/filesystem/haiku/SDL_sysfilesystem.cc b/src/filesystem/haiku/SDL_sysfilesystem.cc index 5a94f65b75..60e7d5b09d 100644 --- a/src/filesystem/haiku/SDL_sysfilesystem.cc +++ b/src/filesystem/haiku/SDL_sysfilesystem.cc @@ -54,14 +54,14 @@ char *SDL_SYS_GetBasePath(void) SDL_assert(str != NULL); const size_t len = SDL_strlen(str); - char *retval = (char *) SDL_malloc(len + 2); - if (retval) { - SDL_memcpy(retval, str, len); - retval[len] = '/'; - retval[len+1] = '\0'; + char *result = (char *) SDL_malloc(len + 2); + if (result) { + SDL_memcpy(result, str, len); + result[len] = '/'; + result[len+1] = '\0'; } - return retval; + return result; } @@ -84,23 +84,23 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) ++append; // home empty or ends with separator, skip the one from append } len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; - char *retval = (char *) SDL_malloc(len); - if (retval) { + char *result = (char *) SDL_malloc(len); + if (result) { if (*org) { - SDL_snprintf(retval, len, "%s%s%s/%s/", home, append, org, app); + SDL_snprintf(result, len, "%s%s%s/%s/", home, append, org, app); } else { - SDL_snprintf(retval, len, "%s%s%s/", home, append, app); + SDL_snprintf(result, len, "%s%s%s/", home, append, app); } - create_directory(retval, 0700); // Haiku api: creates missing dirs + create_directory(result, 0700); // Haiku api: creates missing dirs } - return retval; + return result; } char *SDL_SYS_GetUserFolder(SDL_Folder folder) { const char *home = NULL; - char *retval; + char *result; home = SDL_getenv("HOME"); if (!home) { @@ -110,33 +110,33 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) switch (folder) { case SDL_FOLDER_HOME: - retval = (char *) SDL_malloc(SDL_strlen(home) + 2); - if (!retval) { + result = (char *) SDL_malloc(SDL_strlen(home) + 2); + if (!result) { return NULL; } - if (SDL_snprintf(retval, SDL_strlen(home) + 2, "%s/", home) < 0) { + if (SDL_snprintf(result, SDL_strlen(home) + 2, "%s/", home) < 0) { SDL_SetError("Couldn't snprintf home path for Haiku: %s", home); - SDL_free(retval); + SDL_free(result); return NULL; } - return retval; + return result; // TODO: Is Haiku's desktop folder always ~/Desktop/ ? case SDL_FOLDER_DESKTOP: - retval = (char *) SDL_malloc(SDL_strlen(home) + 10); - if (!retval) { + result = (char *) SDL_malloc(SDL_strlen(home) + 10); + if (!result) { return NULL; } - if (SDL_snprintf(retval, SDL_strlen(home) + 10, "%s/Desktop/", home) < 0) { + if (SDL_snprintf(result, SDL_strlen(home) + 10, "%s/Desktop/", home) < 0) { SDL_SetError("Couldn't snprintf desktop path for Haiku: %s/Desktop/", home); - SDL_free(retval); + SDL_free(result); return NULL; } - return retval; + return result; case SDL_FOLDER_DOCUMENTS: case SDL_FOLDER_DOWNLOADS: diff --git a/src/filesystem/n3ds/SDL_sysfilesystem.c b/src/filesystem/n3ds/SDL_sysfilesystem.c index a45eb3f078..e4a118c951 100644 --- a/src/filesystem/n3ds/SDL_sysfilesystem.c +++ b/src/filesystem/n3ds/SDL_sysfilesystem.c @@ -32,7 +32,7 @@ #include static char *MakePrefPath(const char *app); -static int CreatePrefPathDir(const char *pref); +static bool CreatePrefPathDir(const char *pref); char *SDL_SYS_GetBasePath(void) { @@ -53,7 +53,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) return NULL; } - if (CreatePrefPathDir(pref_path) < 0) { + if (!CreatePrefPathDir(pref_path)) { SDL_free(pref_path); return NULL; } @@ -77,14 +77,14 @@ static char *MakePrefPath(const char *app) return pref_path; } -static int CreatePrefPathDir(const char *pref) +static bool CreatePrefPathDir(const char *pref) { int result = mkdir(pref, 0666); if (result == -1 && errno != EEXIST) { return SDL_SetError("Failed to create '%s' (%s)", pref, strerror(errno)); } - return 0; + return true; } #endif // SDL_FILESYSTEM_N3DS diff --git a/src/filesystem/posix/SDL_sysfsops.c b/src/filesystem/posix/SDL_sysfsops.c index 97749b6aea..9b1d963dfb 100644 --- a/src/filesystem/posix/SDL_sysfsops.c +++ b/src/filesystem/posix/SDL_sysfsops.c @@ -36,50 +36,51 @@ int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_EnumerateDirectoryCallback cb, void *userdata) { - int retval = 1; + int result = 1; DIR *dir = opendir(path); if (!dir) { - return SDL_SetError("Can't open directory: %s", strerror(errno)); + SDL_SetError("Can't open directory: %s", strerror(errno)); + return -1; } struct dirent *ent; - while ((retval == 1) && ((ent = readdir(dir)) != NULL)) + while ((result == 1) && ((ent = readdir(dir)) != NULL)) { const char *name = ent->d_name; if ((SDL_strcmp(name, ".") == 0) || (SDL_strcmp(name, "..") == 0)) { continue; } - retval = cb(userdata, dirname, name); + result = cb(userdata, dirname, name); } closedir(dir); - return retval; + return result; } -int SDL_SYS_RemovePath(const char *path) +bool SDL_SYS_RemovePath(const char *path) { int rc = remove(path); if (rc < 0) { if (errno == ENOENT) { // It's already gone, this is a success - return 0; + return true; } return SDL_SetError("Can't remove path: %s", strerror(errno)); } - return 0; + return true; } -int SDL_SYS_RenamePath(const char *oldpath, const char *newpath) +bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath) { if (rename(oldpath, newpath) < 0) { return SDL_SetError("Can't remove path: %s", strerror(errno)); } - return 0; + return true; } -int SDL_SYS_CopyFile(const char *oldpath, const char *newpath) +bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath) { char *buffer = NULL; char *tmppath = NULL; @@ -87,7 +88,7 @@ int SDL_SYS_CopyFile(const char *oldpath, const char *newpath) SDL_IOStream *output = NULL; const size_t maxlen = 4096; size_t len; - int retval = -1; + bool result = false; if (SDL_asprintf(&tmppath, "%s.tmp", newpath) < 0) { goto done; @@ -120,17 +121,17 @@ int SDL_SYS_CopyFile(const char *oldpath, const char *newpath) SDL_CloseIO(input); input = NULL; - if (SDL_CloseIO(output) < 0) { + if (!SDL_CloseIO(output)) { goto done; } output = NULL; - if (SDL_RenamePath(tmppath, newpath) < 0) { + if (!SDL_RenamePath(tmppath, newpath)) { SDL_RemovePath(tmppath); goto done; } - retval = 0; + result = true; done: if (output) { @@ -143,10 +144,10 @@ done: SDL_free(tmppath); SDL_free(buffer); - return retval; + return result; } -int SDL_SYS_CreateDirectory(const char *path) +bool SDL_SYS_CreateDirectory(const char *path) { const int rc = mkdir(path, 0770); if (rc < 0) { @@ -154,15 +155,15 @@ int SDL_SYS_CreateDirectory(const char *path) if (origerrno == EEXIST) { struct stat statbuf; if ((stat(path, &statbuf) == 0) && (S_ISDIR(statbuf.st_mode))) { - return 0; // it already exists and it's a directory, consider it success. + return true; // it already exists and it's a directory, consider it success. } } return SDL_SetError("Can't create directory: %s", strerror(origerrno)); } - return 0; + return true; } -int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) +bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) { struct stat statbuf; const int rc = stat(path, &statbuf); @@ -194,7 +195,7 @@ int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) info->modify_time = (SDL_Time)SDL_SECONDS_TO_NS(statbuf.st_mtime); info->access_time = (SDL_Time)SDL_SECONDS_TO_NS(statbuf.st_atime); #endif - return 0; + return true; } #endif // SDL_FSOPS_POSIX diff --git a/src/filesystem/ps2/SDL_sysfilesystem.c b/src/filesystem/ps2/SDL_sysfilesystem.c index 1feb1f93ce..ee90aabfb6 100644 --- a/src/filesystem/ps2/SDL_sysfilesystem.c +++ b/src/filesystem/ps2/SDL_sysfilesystem.c @@ -32,18 +32,18 @@ char *SDL_SYS_GetBasePath(void) { - char *retval = NULL; + char *result = NULL; size_t len; char cwd[FILENAME_MAX]; getcwd(cwd, sizeof(cwd)); len = SDL_strlen(cwd) + 2; - retval = (char *)SDL_malloc(len); - if (retval) { - SDL_snprintf(retval, len, "%s/", cwd); + result = (char *)SDL_malloc(len); + if (result) { + SDL_snprintf(result, len, "%s/", cwd); } - return retval; + return result; } // Do a recursive mkdir of parents folders @@ -77,7 +77,7 @@ static void recursive_mkdir(const char *dir) char *SDL_SYS_GetPrefPath(const char *org, const char *app) { - char *retval = NULL; + char *result = NULL; size_t len; if (!app) { @@ -95,18 +95,18 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) } len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4; - retval = (char *)SDL_malloc(len); - if (retval) { + result = (char *)SDL_malloc(len); + if (result) { if (*org) { - SDL_snprintf(retval, len, "%s%s/%s/", base, org, app); + SDL_snprintf(result, len, "%s%s/%s/", base, org, app); } else { - SDL_snprintf(retval, len, "%s%s/", base, app); + SDL_snprintf(result, len, "%s%s/", base, app); } - recursive_mkdir(retval); + recursive_mkdir(result); } - return retval; + return result; } // TODO diff --git a/src/filesystem/psp/SDL_sysfilesystem.c b/src/filesystem/psp/SDL_sysfilesystem.c index 35ce8d24d2..8f8d1c3a4c 100644 --- a/src/filesystem/psp/SDL_sysfilesystem.c +++ b/src/filesystem/psp/SDL_sysfilesystem.c @@ -32,23 +32,23 @@ char *SDL_SYS_GetBasePath(void) { - char *retval = NULL; + char *result = NULL; size_t len; char cwd[FILENAME_MAX]; getcwd(cwd, sizeof(cwd)); len = SDL_strlen(cwd) + 2; - retval = (char *)SDL_malloc(len); - if (retval) { - SDL_snprintf(retval, len, "%s/", cwd); + result = (char *)SDL_malloc(len); + if (result) { + SDL_snprintf(result, len, "%s/", cwd); } - return retval; + return result; } char *SDL_SYS_GetPrefPath(const char *org, const char *app) { - char *retval = NULL; + char *result = NULL; size_t len; if (!app) { SDL_InvalidParamError("app"); @@ -65,18 +65,18 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) } len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4; - retval = (char *)SDL_malloc(len); - if (retval) { + result = (char *)SDL_malloc(len); + if (result) { if (*org) { - SDL_snprintf(retval, len, "%s%s/%s/", base, org, app); + SDL_snprintf(result, len, "%s%s/%s/", base, org, app); } else { - SDL_snprintf(retval, len, "%s%s/", base, app); + SDL_snprintf(result, len, "%s%s/", base, app); } - mkdir(retval, 0755); + mkdir(result, 0755); } - return retval; + return result; } // TODO diff --git a/src/filesystem/riscos/SDL_sysfilesystem.c b/src/filesystem/riscos/SDL_sysfilesystem.c index c3d3cfca07..25e6e23880 100644 --- a/src/filesystem/riscos/SDL_sysfilesystem.c +++ b/src/filesystem/riscos/SDL_sysfilesystem.c @@ -129,7 +129,7 @@ char *SDL_SYS_GetBasePath(void) { _kernel_swi_regs regs; _kernel_oserror *error; - char *canon, *ptr, *retval; + char *canon, *ptr, *result; error = _kernel_swi(OS_GetEnv, ®s, ®s); if (error) { @@ -147,14 +147,14 @@ char *SDL_SYS_GetBasePath(void) *ptr = '\0'; } - retval = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED); + result = SDL_unixify_std(canon, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED); SDL_free(canon); - return retval; + return result; } char *SDL_SYS_GetPrefPath(const char *org, const char *app) { - char *canon, *dir, *retval; + char *canon, *dir, *result; size_t len; _kernel_oserror *error; @@ -193,9 +193,9 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) return NULL; } - retval = SDL_unixify_std(dir, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED); + result = SDL_unixify_std(dir, NULL, 0, __RISCOSIFY_FILETYPE_NOTSPECIFIED); SDL_free(dir); - return retval; + return result; } // TODO diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c index 44b6d7061c..630620e399 100644 --- a/src/filesystem/unix/SDL_sysfilesystem.c +++ b/src/filesystem/unix/SDL_sysfilesystem.c @@ -44,30 +44,30 @@ static char *readSymLink(const char *path) { - char *retval = NULL; + char *result = NULL; ssize_t len = 64; ssize_t rc = -1; while (1) { - char *ptr = (char *)SDL_realloc(retval, (size_t)len); + char *ptr = (char *)SDL_realloc(result, (size_t)len); if (!ptr) { break; } - retval = ptr; + result = ptr; - rc = readlink(path, retval, len); + rc = readlink(path, result, len); if (rc == -1) { break; // not a symlink, i/o error, etc. } else if (rc < len) { - retval[rc] = '\0'; // readlink doesn't null-terminate. - return retval; // we're good to go. + result[rc] = '\0'; // readlink doesn't null-terminate. + return result; // we're good to go. } len *= 2; // grow buffer, try again. } - SDL_free(retval); + SDL_free(result); return NULL; } @@ -124,15 +124,15 @@ static char *search_path_for_binary(const char *bin) char *SDL_SYS_GetBasePath(void) { - char *retval = NULL; + char *result = NULL; #ifdef SDL_PLATFORM_FREEBSD char fullpath[PATH_MAX]; size_t buflen = sizeof(fullpath); const int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; if (sysctl(mib, SDL_arraysize(mib), fullpath, &buflen, NULL, 0) != -1) { - retval = SDL_strdup(fullpath); - if (!retval) { + result = SDL_strdup(fullpath); + if (!result) { return NULL; } } @@ -173,11 +173,11 @@ char *SDL_SYS_GetBasePath(void) if (exe) { if (!pwddst) { if (realpath(exe, realpathbuf) != NULL) { - retval = realpathbuf; + result = realpathbuf; } } else { if (realpath(pwddst, realpathbuf) != NULL) { - retval = realpathbuf; + result = realpathbuf; } SDL_free(pwddst); } @@ -187,7 +187,7 @@ char *SDL_SYS_GetBasePath(void) } } - if (!retval) { + if (!result) { SDL_free(realpathbuf); } @@ -196,37 +196,37 @@ char *SDL_SYS_GetBasePath(void) #endif // is a Linux-style /proc filesystem available? - if (!retval && (access("/proc", F_OK) == 0)) { + if (!result && (access("/proc", F_OK) == 0)) { /* !!! FIXME: after 2.0.6 ships, let's delete this code and just use the /proc/%llu version. There's no reason to have two copies of this plus all the #ifdefs. --ryan. */ #ifdef SDL_PLATFORM_FREEBSD - retval = readSymLink("/proc/curproc/file"); + result = readSymLink("/proc/curproc/file"); #elif defined(SDL_PLATFORM_NETBSD) - retval = readSymLink("/proc/curproc/exe"); + result = readSymLink("/proc/curproc/exe"); #elif defined(SDL_PLATFORM_SOLARIS) - retval = readSymLink("/proc/self/path/a.out"); + result = readSymLink("/proc/self/path/a.out"); #else - retval = readSymLink("/proc/self/exe"); // linux. - if (!retval) { + result = readSymLink("/proc/self/exe"); // linux. + if (!result) { // older kernels don't have /proc/self ... try PID version... char path[64]; const int rc = SDL_snprintf(path, sizeof(path), "/proc/%llu/exe", (unsigned long long)getpid()); if ((rc > 0) && (rc < sizeof(path))) { - retval = readSymLink(path); + result = readSymLink(path); } } #endif } #ifdef SDL_PLATFORM_SOLARIS // try this as a fallback if /proc didn't pan out - if (!retval) { + if (!result) { const char *path = getexecname(); if ((path) && (path[0] == '/')) { // must be absolute path... - retval = SDL_strdup(path); - if (!retval) { + result = SDL_strdup(path); + if (!result) { return NULL; } } @@ -235,25 +235,25 @@ char *SDL_SYS_GetBasePath(void) /* If we had access to argv[0] here, we could check it for a path, or troll through $PATH looking for it, too. */ - if (retval) { // chop off filename. - char *ptr = SDL_strrchr(retval, '/'); + if (result) { // chop off filename. + char *ptr = SDL_strrchr(result, '/'); if (ptr) { *(ptr + 1) = '\0'; } else { // shouldn't happen, but just in case... - SDL_free(retval); - retval = NULL; + SDL_free(result); + result = NULL; } } - if (retval) { + if (result) { // try to shrink buffer... - char *ptr = (char *)SDL_realloc(retval, SDL_strlen(retval) + 1); + char *ptr = (char *)SDL_realloc(result, SDL_strlen(result) + 1); if (ptr) { - retval = ptr; // oh well if it failed. + result = ptr; // oh well if it failed. } } - return retval; + return result; } char *SDL_SYS_GetPrefPath(const char *org, const char *app) @@ -267,7 +267,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) */ const char *envr = SDL_getenv("XDG_DATA_HOME"); const char *append; - char *retval = NULL; + char *result = NULL; char *ptr = NULL; size_t len = 0; @@ -298,34 +298,34 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) } len += SDL_strlen(append) + SDL_strlen(org) + SDL_strlen(app) + 3; - retval = (char *)SDL_malloc(len); - if (!retval) { + result = (char *)SDL_malloc(len); + if (!result) { return NULL; } if (*org) { - (void)SDL_snprintf(retval, len, "%s%s%s/%s/", envr, append, org, app); + (void)SDL_snprintf(result, len, "%s%s%s/%s/", envr, append, org, app); } else { - (void)SDL_snprintf(retval, len, "%s%s%s/", envr, append, app); + (void)SDL_snprintf(result, len, "%s%s%s/", envr, append, app); } - for (ptr = retval + 1; *ptr; ptr++) { + for (ptr = result + 1; *ptr; ptr++) { if (*ptr == '/') { *ptr = '\0'; - if (mkdir(retval, 0700) != 0 && errno != EEXIST) { + if (mkdir(result, 0700) != 0 && errno != EEXIST) { goto error; } *ptr = '/'; } } - if (mkdir(retval, 0700) != 0 && errno != EEXIST) { + if (mkdir(result, 0700) != 0 && errno != EEXIST) { error: - SDL_SetError("Couldn't create directory '%s': '%s'", retval, strerror(errno)); - SDL_free(retval); + SDL_SetError("Couldn't create directory '%s': '%s'", result, strerror(errno)); + SDL_free(result); return NULL; } - return retval; + return result; } /* @@ -518,8 +518,8 @@ static char *xdg_user_dir_lookup (const char *type) char *SDL_SYS_GetUserFolder(SDL_Folder folder) { const char *param = NULL; - char *retval; - char *newretval; + char *result; + char *newresult; /* According to `man xdg-user-dir`, the possible values are: DESKTOP @@ -540,7 +540,7 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) return NULL; } - retval = SDL_strdup(param); + result = SDL_strdup(param); goto append_slash; case SDL_FOLDER_DESKTOP: @@ -594,25 +594,25 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) return NULL; } - retval = xdg_user_dir_lookup(param); + result = xdg_user_dir_lookup(param); - if (!retval) { + if (!result) { SDL_SetError("XDG directory not available"); return NULL; } append_slash: - newretval = (char *) SDL_realloc(retval, SDL_strlen(retval) + 2); + newresult = (char *) SDL_realloc(result, SDL_strlen(result) + 2); - if (!newretval) { - SDL_free(retval); + if (!newresult) { + SDL_free(result); return NULL; } - retval = newretval; - SDL_strlcat(retval, "/", SDL_strlen(retval) + 2); + result = newresult; + SDL_strlcat(result, "/", SDL_strlen(result) + 2); - return retval; + return result; } #endif // SDL_FILESYSTEM_UNIX diff --git a/src/filesystem/vita/SDL_sysfilesystem.c b/src/filesystem/vita/SDL_sysfilesystem.c index 884aa05897..f916183497 100644 --- a/src/filesystem/vita/SDL_sysfilesystem.c +++ b/src/filesystem/vita/SDL_sysfilesystem.c @@ -44,7 +44,7 @@ char *SDL_SYS_GetBasePath(void) char *SDL_SYS_GetPrefPath(const char *org, const char *app) { const char *envr = "ux0:/data/"; - char *retval = NULL; + char *result = NULL; char *ptr = NULL; size_t len = 0; @@ -59,27 +59,27 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) len = SDL_strlen(envr); len += SDL_strlen(org) + SDL_strlen(app) + 3; - retval = (char *)SDL_malloc(len); - if (!retval) { + result = (char *)SDL_malloc(len); + if (!result) { return NULL; } if (*org) { - SDL_snprintf(retval, len, "%s%s/%s/", envr, org, app); + SDL_snprintf(result, len, "%s%s/%s/", envr, org, app); } else { - SDL_snprintf(retval, len, "%s%s/", envr, app); + SDL_snprintf(result, len, "%s%s/", envr, app); } - for (ptr = retval + 1; *ptr; ptr++) { + for (ptr = result + 1; *ptr; ptr++) { if (*ptr == '/') { *ptr = '\0'; - sceIoMkdir(retval, 0777); + sceIoMkdir(result, 0777); *ptr = '/'; } } - sceIoMkdir(retval, 0777); + sceIoMkdir(result, 0777); - return retval; + return result; } // TODO diff --git a/src/filesystem/windows/SDL_sysfilesystem.c b/src/filesystem/windows/SDL_sysfilesystem.c index 401a0b0fb6..cef3c2b029 100644 --- a/src/filesystem/windows/SDL_sysfilesystem.c +++ b/src/filesystem/windows/SDL_sysfilesystem.c @@ -47,7 +47,7 @@ char *SDL_SYS_GetBasePath(void) { DWORD buflen = 128; WCHAR *path = NULL; - char *retval = NULL; + char *result = NULL; DWORD len = 0; int i; @@ -86,10 +86,10 @@ char *SDL_SYS_GetBasePath(void) SDL_assert(i > 0); // Should have been an absolute path. path[i + 1] = '\0'; // chop off filename. - retval = WIN_StringToUTF8W(path); + result = WIN_StringToUTF8W(path); SDL_free(path); - return retval; + return result; } char *SDL_SYS_GetPrefPath(const char *org, const char *app) @@ -103,7 +103,7 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) */ WCHAR path[MAX_PATH]; - char *retval = NULL; + char *result = NULL; WCHAR *worg = NULL; WCHAR *wapp = NULL; size_t new_wpath_len = 0; @@ -171,9 +171,9 @@ char *SDL_SYS_GetPrefPath(const char *org, const char *app) SDL_wcslcat(path, L"\\", SDL_arraysize(path)); - retval = WIN_StringToUTF8W(path); + result = WIN_StringToUTF8W(path); - return retval; + return result; } char *SDL_SYS_GetUserFolder(SDL_Folder folder) @@ -181,7 +181,7 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) typedef HRESULT (WINAPI *pfnSHGetKnownFolderPath)(REFGUID /* REFKNOWNFOLDERID */, DWORD, HANDLE, PWSTR*); HMODULE lib = LoadLibrary(L"Shell32.dll"); pfnSHGetKnownFolderPath pSHGetKnownFolderPath = NULL; - char *retval = NULL; + char *result = NULL; if (lib) { pSHGetKnownFolderPath = (pfnSHGetKnownFolderPath)GetProcAddress(lib, "SHGetKnownFolderPath"); @@ -189,7 +189,7 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) if (pSHGetKnownFolderPath) { GUID type; // KNOWNFOLDERID - HRESULT result; + HRESULT hr; wchar_t *path; switch (folder) { @@ -242,16 +242,16 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) goto done; }; - result = pSHGetKnownFolderPath(&type, 0x00008000 /* KF_FLAG_CREATE */, NULL, &path); - if (SUCCEEDED(result)) { - retval = WIN_StringToUTF8W(path); + hr = pSHGetKnownFolderPath(&type, 0x00008000 /* KF_FLAG_CREATE */, NULL, &path); + if (SUCCEEDED(hr)) { + result = WIN_StringToUTF8W(path); } else { - WIN_SetErrorFromHRESULT("Couldn't get folder", result); + WIN_SetErrorFromHRESULT("Couldn't get folder", hr); } } else { int type; - HRESULT result; + HRESULT hr; wchar_t path[MAX_PATH]; switch (folder) { @@ -309,38 +309,38 @@ char *SDL_SYS_GetUserFolder(SDL_Folder folder) #if 0 // Apparently the oldest, but not supported in modern Windows - HRESULT result = SHGetSpecialFolderPath(NULL, path, type, TRUE); + HRESULT hr = SHGetSpecialFolderPath(NULL, path, type, TRUE); #endif /* Windows 2000/XP and later, deprecated as of Windows 10 (still available), available in Wine (tested 6.0.3) */ - result = SHGetFolderPathW(NULL, type, NULL, SHGFP_TYPE_CURRENT, path); + hr = SHGetFolderPathW(NULL, type, NULL, SHGFP_TYPE_CURRENT, path); // use `== TRUE` for SHGetSpecialFolderPath - if (SUCCEEDED(result)) { - retval = WIN_StringToUTF8W(path); + if (SUCCEEDED(hr)) { + result = WIN_StringToUTF8W(path); } else { - WIN_SetErrorFromHRESULT("Couldn't get folder", result); + WIN_SetErrorFromHRESULT("Couldn't get folder", hr); } } - if (retval) { - char *newretval = (char *) SDL_realloc(retval, SDL_strlen(retval) + 2); + if (result) { + char *newresult = (char *) SDL_realloc(result, SDL_strlen(result) + 2); - if (!newretval) { - SDL_free(retval); - retval = NULL; // will be returned + if (!newresult) { + SDL_free(result); + result = NULL; // will be returned goto done; } - retval = newretval; - SDL_strlcat(retval, "\\", SDL_strlen(retval) + 2); + result = newresult; + SDL_strlcat(result, "\\", SDL_strlen(result) + 2); } done: if (lib) { FreeLibrary(lib); } - return retval; + return result; } #endif // SDL_FILESYSTEM_WINDOWS diff --git a/src/filesystem/windows/SDL_sysfsops.c b/src/filesystem/windows/SDL_sysfsops.c index 621ae9e839..29aa4e7992 100644 --- a/src/filesystem/windows/SDL_sysfsops.c +++ b/src/filesystem/windows/SDL_sysfsops.c @@ -31,14 +31,14 @@ int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_EnumerateDirectoryCallback cb, void *userdata) { - int retval = 1; + int result = 1; if (*path == '\0') { // if empty (completely at the root), we need to enumerate drive letters. const DWORD drives = GetLogicalDrives(); char name[3] = { 0, ':', '\0' }; - for (int i = 'A'; (retval == 1) && (i <= 'Z'); i++) { + for (int i = 'A'; (result == 1) && (i <= 'Z'); i++) { if (drives & (1 << (i - 'A'))) { name[0] = (char) i; - retval = cb(userdata, dirname, name); + result = cb(userdata, dirname, name); } } } else { @@ -63,7 +63,8 @@ int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_Enumer HANDLE dir = FindFirstFileExW(wpattern, FindExInfoStandard, &entw, FindExSearchNameMatch, NULL, 0); SDL_free(wpattern); if (dir == INVALID_HANDLE_VALUE) { - return WIN_SetError("Failed to enumerate directory"); + WIN_SetError("Failed to enumerate directory"); + return -1; } do { @@ -77,31 +78,31 @@ int SDL_SYS_EnumerateDirectory(const char *path, const char *dirname, SDL_Enumer char *utf8fn = WIN_StringToUTF8W(fn); if (!utf8fn) { - retval = -1; + result = -1; } else { - retval = cb(userdata, dirname, utf8fn); + result = cb(userdata, dirname, utf8fn); SDL_free(utf8fn); } - } while ((retval == 1) && (FindNextFileW(dir, &entw) != 0)); + } while ((result == 1) && (FindNextFileW(dir, &entw) != 0)); FindClose(dir); } - return retval; + return result; } -int SDL_SYS_RemovePath(const char *path) +bool SDL_SYS_RemovePath(const char *path) { WCHAR *wpath = WIN_UTF8ToStringW(path); if (!wpath) { - return -1; + return false; } WIN32_FILE_ATTRIBUTE_DATA info; if (!GetFileAttributesExW(wpath, GetFileExInfoStandard, &info)) { if (GetLastError() == ERROR_FILE_NOT_FOUND) { // Note that ERROR_PATH_NOT_FOUND means a parent dir is missing, and we consider that an error. - return 0; // thing is already gone, call it a success. + return true; // thing is already gone, call it a success. } return WIN_SetError("Couldn't get path's attributes"); } @@ -109,64 +110,76 @@ int SDL_SYS_RemovePath(const char *path) const int isdir = (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); const BOOL rc = isdir ? RemoveDirectoryW(wpath) : DeleteFileW(wpath); SDL_free(wpath); - return !rc ? WIN_SetError("Couldn't remove path") : 0; + if (!rc) { + return WIN_SetError("Couldn't remove path"); + } + return true; } -int SDL_SYS_RenamePath(const char *oldpath, const char *newpath) +bool SDL_SYS_RenamePath(const char *oldpath, const char *newpath) { WCHAR *woldpath = WIN_UTF8ToStringW(oldpath); if (!woldpath) { - return -1; + return false; } WCHAR *wnewpath = WIN_UTF8ToStringW(newpath); if (!wnewpath) { SDL_free(woldpath); - return -1; + return false; } const BOOL rc = MoveFileExW(woldpath, wnewpath, MOVEFILE_REPLACE_EXISTING); SDL_free(wnewpath); SDL_free(woldpath); - return !rc ? WIN_SetError("Couldn't rename path") : 0; + if (!rc) { + return WIN_SetError("Couldn't rename path"); + } + return true; } -int SDL_SYS_CopyFile(const char *oldpath, const char *newpath) +bool SDL_SYS_CopyFile(const char *oldpath, const char *newpath) { WCHAR *woldpath = WIN_UTF8ToStringW(oldpath); if (!woldpath) { - return -1; + return false; } WCHAR *wnewpath = WIN_UTF8ToStringW(newpath); if (!wnewpath) { SDL_free(woldpath); - return -1; + return false; } const BOOL rc = CopyFileW(woldpath, wnewpath, TRUE); SDL_free(wnewpath); SDL_free(woldpath); - return !rc ? WIN_SetError("Couldn't copy path") : 0; + if (!rc) { + return WIN_SetError("Couldn't copy path"); + } + return true; } -int SDL_SYS_CreateDirectory(const char *path) +bool SDL_SYS_CreateDirectory(const char *path) { WCHAR *wpath = WIN_UTF8ToStringW(path); if (!wpath) { - return -1; + return false; } const DWORD rc = CreateDirectoryW(wpath, NULL); SDL_free(wpath); - return !rc ? WIN_SetError("Couldn't create directory") : 0; + if (!rc) { + return WIN_SetError("Couldn't create directory"); + } + return true; } -int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) +bool SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) { WCHAR *wpath = WIN_UTF8ToStringW(path); if (!wpath) { - return -1; + return false; } WIN32_FILE_ATTRIBUTE_DATA winstat; @@ -191,7 +204,7 @@ int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info) info->modify_time = SDL_TimeFromWindows(winstat.ftLastWriteTime.dwLowDateTime, winstat.ftLastWriteTime.dwHighDateTime); info->access_time = SDL_TimeFromWindows(winstat.ftLastAccessTime.dwLowDateTime, winstat.ftLastAccessTime.dwHighDateTime); - return 0; + return true; } #endif // SDL_FSOPS_WINDOWS diff --git a/src/filesystem/winrt/SDL_sysfilesystem.cpp b/src/filesystem/winrt/SDL_sysfilesystem.cpp index d2f35c2025..fd73b0c6b4 100644 --- a/src/filesystem/winrt/SDL_sysfilesystem.cpp +++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp @@ -149,7 +149,7 @@ extern "C" char *SDL_SYS_GetPrefPath(const char *org, const char *app) const WCHAR *srcPath = NULL; WCHAR path[MAX_PATH]; - char *retval = NULL; + char *result = NULL; WCHAR *worg = NULL; WCHAR *wapp = NULL; size_t new_wpath_len = 0; @@ -224,9 +224,9 @@ extern "C" char *SDL_SYS_GetPrefPath(const char *org, const char *app) SDL_wcslcat(path, L"\\", new_wpath_len + 1); - retval = WIN_StringToUTF8W(path); + result = WIN_StringToUTF8W(path); - return retval; + return result; } char *SDL_SYS_GetUserFolder(SDL_Folder folder) diff --git a/src/haptic/SDL_haptic.c b/src/haptic/SDL_haptic.c index c7962aad32..2f6ef78ea1 100644 --- a/src/haptic/SDL_haptic.c +++ b/src/haptic/SDL_haptic.c @@ -26,22 +26,15 @@ static SDL_Haptic *SDL_haptics = NULL; -#define CHECK_HAPTIC_MAGIC(haptic, retval) \ +#define CHECK_HAPTIC_MAGIC(haptic, result) \ if (!SDL_ObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC)) { \ SDL_InvalidParamError("haptic"); \ - return retval; \ + return result; \ } -int SDL_InitHaptics(void) +bool SDL_InitHaptics(void) { - int status; - - status = SDL_SYS_HapticInit(); - if (status >= 0) { - status = 0; - } - - return status; + return SDL_SYS_HapticInit(); } static bool SDL_GetHapticIndex(SDL_HapticID instance_id, int *driver_index) @@ -137,7 +130,7 @@ SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id) SDL_SetObjectValid(haptic, SDL_OBJECT_TYPE_HAPTIC, true); haptic->instance_id = instance_id; haptic->rumble_id = -1; - if (SDL_SYS_HapticOpen(haptic) < 0) { + if (!SDL_SYS_HapticOpen(haptic)) { SDL_free(haptic); return NULL; } @@ -247,7 +240,7 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick) // Joystick must be haptic if (SDL_IsGamepad(SDL_GetJoystickID(joystick)) || - SDL_SYS_JoystickIsHaptic(joystick) <= 0) { + !SDL_SYS_JoystickIsHaptic(joystick)) { SDL_SetError("Haptic: Joystick isn't a haptic device."); SDL_UnlockJoysticks(); return NULL; @@ -276,7 +269,7 @@ SDL_Haptic *SDL_OpenHapticFromJoystick(SDL_Joystick *joystick) * This function should fill in the instance ID and name. */ haptic->rumble_id = -1; - if (SDL_SYS_HapticOpenFromJoystick(haptic, joystick) < 0) { + if (!SDL_SYS_HapticOpenFromJoystick(haptic, joystick)) { SDL_SetError("Haptic: SDL_SYS_HapticOpenFromJoystick failed."); SDL_free(haptic); SDL_UnlockJoysticks(); @@ -398,12 +391,14 @@ int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect) CHECK_HAPTIC_MAGIC(haptic, -1); if (!effect) { - return SDL_InvalidParamError("effect"); + SDL_InvalidParamError("effect"); + return -1; } // Check to see if effect is supported if (SDL_HapticEffectSupported(haptic, effect) == false) { - return SDL_SetError("Haptic: Effect not supported by haptic device."); + SDL_SetError("Haptic: Effect not supported by haptic device."); + return -1; } // See if there's a free slot @@ -411,7 +406,7 @@ int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect) if (haptic->effects[i].hweffect == NULL) { // Now let the backend create the real effect - if (SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect) < 0) { + if (!SDL_SYS_HapticNewEffect(haptic, &haptic->effects[i], effect)) { return -1; // Backend failed to create effect } @@ -421,24 +416,25 @@ int SDL_CreateHapticEffect(SDL_Haptic *haptic, const SDL_HapticEffect *effect) } } - return SDL_SetError("Haptic: Device has no free space left."); + SDL_SetError("Haptic: Device has no free space left."); + return -1; } -static int ValidEffect(SDL_Haptic *haptic, int effect) +static bool ValidEffect(SDL_Haptic *haptic, int effect) { if ((effect < 0) || (effect >= haptic->neffects)) { SDL_SetError("Haptic: Invalid effect identifier."); - return 0; + return false; } - return 1; + return true; } -int SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data) +SDL_bool SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffect *data) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!ValidEffect(haptic, effect)) { - return -1; + return false; } if (!data) { @@ -451,46 +447,45 @@ int SDL_UpdateHapticEffect(SDL_Haptic *haptic, int effect, const SDL_HapticEffec } // Updates the effect - if (SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data) < - 0) { - return -1; + if (!SDL_SYS_HapticUpdateEffect(haptic, &haptic->effects[effect], data)) { + return false; } SDL_memcpy(&haptic->effects[effect].effect, data, sizeof(SDL_HapticEffect)); - return 0; + return true; } -int SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations) +SDL_bool SDL_RunHapticEffect(SDL_Haptic *haptic, int effect, Uint32 iterations) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!ValidEffect(haptic, effect)) { - return -1; + return false; } // Run the effect - if (SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations) < 0) { - return -1; + if (!SDL_SYS_HapticRunEffect(haptic, &haptic->effects[effect], iterations)) { + return false; } - return 0; + return true; } -int SDL_StopHapticEffect(SDL_Haptic *haptic, int effect) +SDL_bool SDL_StopHapticEffect(SDL_Haptic *haptic, int effect) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!ValidEffect(haptic, effect)) { - return -1; + return false; } // Stop the effect - if (SDL_SYS_HapticStopEffect(haptic, &haptic->effects[effect]) < 0) { - return -1; + if (!SDL_SYS_HapticStopEffect(haptic, &haptic->effects[effect])) { + return false; } - return 0; + return true; } void SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect) @@ -509,27 +504,29 @@ void SDL_DestroyHapticEffect(SDL_Haptic *haptic, int effect) SDL_SYS_HapticDestroyEffect(haptic, &haptic->effects[effect]); } -int SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect) +SDL_bool SDL_GetHapticEffectStatus(SDL_Haptic *haptic, int effect) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!ValidEffect(haptic, effect)) { - return -1; + return false; } if (!(haptic->supported & SDL_HAPTIC_STATUS)) { return SDL_SetError("Haptic: Device does not support status queries."); } + SDL_ClearError(); + return SDL_SYS_HapticGetEffectStatus(haptic, &haptic->effects[effect]); } -int SDL_SetHapticGain(SDL_Haptic *haptic, int gain) +SDL_bool SDL_SetHapticGain(SDL_Haptic *haptic, int gain) { const char *env; int real_gain, max_gain; - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!(haptic->supported & SDL_HAPTIC_GAIN)) { return SDL_SetError("Haptic: Device does not support setting gain."); @@ -557,16 +554,12 @@ int SDL_SetHapticGain(SDL_Haptic *haptic, int gain) real_gain = gain; } - if (SDL_SYS_HapticSetGain(haptic, real_gain) < 0) { - return -1; - } - - return 0; + return SDL_SYS_HapticSetGain(haptic, real_gain); } -int SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter) +SDL_bool SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!(haptic->supported & SDL_HAPTIC_AUTOCENTER)) { return SDL_SetError("Haptic: Device does not support setting autocenter."); @@ -576,16 +569,12 @@ int SDL_SetHapticAutocenter(SDL_Haptic *haptic, int autocenter) return SDL_SetError("Haptic: Autocenter must be between 0 and 100."); } - if (SDL_SYS_HapticSetAutocenter(haptic, autocenter) < 0) { - return -1; - } - - return 0; + return SDL_SYS_HapticSetAutocenter(haptic, autocenter); } -int SDL_PauseHaptic(SDL_Haptic *haptic) +SDL_bool SDL_PauseHaptic(SDL_Haptic *haptic) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!(haptic->supported & SDL_HAPTIC_PAUSE)) { return SDL_SetError("Haptic: Device does not support setting pausing."); @@ -594,20 +583,20 @@ int SDL_PauseHaptic(SDL_Haptic *haptic) return SDL_SYS_HapticPause(haptic); } -int SDL_ResumeHaptic(SDL_Haptic *haptic) +SDL_bool SDL_ResumeHaptic(SDL_Haptic *haptic) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (!(haptic->supported & SDL_HAPTIC_PAUSE)) { - return 0; // Not going to be paused, so we pretend it's unpaused. + return true; // Not going to be paused, so we pretend it's unpaused. } - return SDL_SYS_HapticUnpause(haptic); + return SDL_SYS_HapticResume(haptic); } -int SDL_StopHapticEffects(SDL_Haptic *haptic) +SDL_bool SDL_StopHapticEffects(SDL_Haptic *haptic) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); return SDL_SYS_HapticStopAll(haptic); } @@ -620,15 +609,15 @@ SDL_bool SDL_HapticRumbleSupported(SDL_Haptic *haptic) return (haptic->supported & (SDL_HAPTIC_SINE | SDL_HAPTIC_LEFTRIGHT)) != 0; } -int SDL_InitHapticRumble(SDL_Haptic *haptic) +SDL_bool SDL_InitHapticRumble(SDL_Haptic *haptic) { SDL_HapticEffect *efx = &haptic->rumble_effect; - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); // Already allocated. if (haptic->rumble_id >= 0) { - return 0; + return true; } SDL_zerop(efx); @@ -651,17 +640,17 @@ int SDL_InitHapticRumble(SDL_Haptic *haptic) haptic->rumble_id = SDL_CreateHapticEffect(haptic, &haptic->rumble_effect); if (haptic->rumble_id >= 0) { - return 0; + return true; } - return -1; + return false; } -int SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length) +SDL_bool SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length) { SDL_HapticEffect *efx; Sint16 magnitude; - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (haptic->rumble_id < 0) { return SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); @@ -686,16 +675,16 @@ int SDL_PlayHapticRumble(SDL_Haptic *haptic, float strength, Uint32 length) SDL_assert(!"This should have been caught elsewhere"); } - if (SDL_UpdateHapticEffect(haptic, haptic->rumble_id, &haptic->rumble_effect) < 0) { - return -1; + if (!SDL_UpdateHapticEffect(haptic, haptic->rumble_id, &haptic->rumble_effect)) { + return false; } return SDL_RunHapticEffect(haptic, haptic->rumble_id, 1); } -int SDL_StopHapticRumble(SDL_Haptic *haptic) +SDL_bool SDL_StopHapticRumble(SDL_Haptic *haptic) { - CHECK_HAPTIC_MAGIC(haptic, -1); + CHECK_HAPTIC_MAGIC(haptic, false); if (haptic->rumble_id < 0) { return SDL_SetError("Haptic: Rumble effect not initialized on haptic device"); diff --git a/src/haptic/SDL_haptic_c.h b/src/haptic/SDL_haptic_c.h index 0044fbfa87..f6e8872b16 100644 --- a/src/haptic/SDL_haptic_c.h +++ b/src/haptic/SDL_haptic_c.h @@ -22,7 +22,7 @@ #ifndef SDL_haptic_c_h_ #define SDL_haptic_c_h_ -extern int SDL_InitHaptics(void); +extern bool SDL_InitHaptics(void); extern void SDL_QuitHaptics(void); #endif // SDL_haptic_c_h_ diff --git a/src/haptic/SDL_syshaptic.h b/src/haptic/SDL_syshaptic.h index ec8856f1ff..a1d86dbe62 100644 --- a/src/haptic/SDL_syshaptic.h +++ b/src/haptic/SDL_syshaptic.h @@ -62,7 +62,7 @@ struct SDL_Haptic * * Returns number of devices on success, -1 on error. */ -extern int SDL_SYS_HapticInit(void); +extern bool SDL_SYS_HapticInit(void); // Function to return the number of haptic devices plugged in right now extern int SDL_SYS_NumHaptics(void); @@ -80,15 +80,13 @@ extern const char *SDL_SYS_HapticName(int index); /* * Opens the haptic device for usage. The haptic device should have * the index value set previously. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticOpen(SDL_Haptic *haptic); +extern bool SDL_SYS_HapticOpen(SDL_Haptic *haptic); /* * Returns the index of the haptic core pointer or -1 if none is found. */ -int SDL_SYS_HapticMouse(void); +extern int SDL_SYS_HapticMouse(void); /* * Checks to see if the joystick has haptic capabilities. @@ -98,10 +96,8 @@ extern bool SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick); /* * Opens the haptic device for usage using the same device as * the joystick. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, +extern bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick); /* * Checks to see if haptic device and joystick device are the same. @@ -124,39 +120,31 @@ extern void SDL_SYS_HapticQuit(void); /* * Creates a new haptic effect on the haptic device using base * as a template for the effect. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, - struct haptic_effect *effect, - const SDL_HapticEffect *base); +extern bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, + struct haptic_effect *effect, + const SDL_HapticEffect *base); /* * Updates the haptic effect on the haptic device using data * as a template. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, - struct haptic_effect *effect, - const SDL_HapticEffect *data); +extern bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, + struct haptic_effect *effect, + const SDL_HapticEffect *data); /* * Runs the effect on the haptic device. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, - struct haptic_effect *effect, - Uint32 iterations); +extern bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, + struct haptic_effect *effect, + Uint32 iterations); /* * Stops the effect on the haptic device. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, - struct haptic_effect *effect); +extern bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, + struct haptic_effect *effect); /* * Cleanups up the effect on the haptic device. @@ -175,38 +163,28 @@ extern int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, /* * Sets the global gain of the haptic device. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain); +extern bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain); /* * Sets the autocenter feature of the haptic device. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter); +extern bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter); /* * Pauses the haptic device. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticPause(SDL_Haptic *haptic); +extern bool SDL_SYS_HapticPause(SDL_Haptic *haptic); /* * Unpauses the haptic device. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticUnpause(SDL_Haptic *haptic); +extern bool SDL_SYS_HapticResume(SDL_Haptic *haptic); /* * Stops all the currently playing haptic effects on the device. - * - * Returns 0 on success, -1 on error. */ -extern int SDL_SYS_HapticStopAll(SDL_Haptic *haptic); +extern bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic); // Ends C function definitions when using C++ #ifdef __cplusplus diff --git a/src/haptic/android/SDL_syshaptic.c b/src/haptic/android/SDL_syshaptic.c index e9bfc6834c..9c7b4ce79f 100644 --- a/src/haptic/android/SDL_syshaptic.c +++ b/src/haptic/android/SDL_syshaptic.c @@ -39,11 +39,11 @@ static SDL_hapticlist_item *SDL_hapticlist = NULL; static SDL_hapticlist_item *SDL_hapticlist_tail = NULL; static int numhaptics = 0; -int SDL_SYS_HapticInit(void) +bool SDL_SYS_HapticInit(void) { Android_JNI_PollHapticDevices(); - return numhaptics; + return true; } int SDL_SYS_NumHaptics(void) @@ -128,9 +128,9 @@ static SDL_hapticlist_item *OpenHapticByInstanceID(SDL_Haptic *haptic, SDL_Hapti return OpenHaptic(haptic, HapticByInstanceID(instance_id)); } -int SDL_SYS_HapticOpen(SDL_Haptic *haptic) +bool SDL_SYS_HapticOpen(SDL_Haptic *haptic) { - return OpenHapticByInstanceID(haptic, haptic->instance_id) == NULL ? -1 : 0; + return OpenHapticByInstanceID(haptic, haptic->instance_id) != NULL; } int SDL_SYS_HapticMouse(void) @@ -143,7 +143,7 @@ bool SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick) return false; } -int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { return SDL_Unsupported(); } @@ -179,20 +179,20 @@ void SDL_SYS_HapticQuit(void) #endif } -int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, +bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) { - return 0; + return true; } -int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, +bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) { - return 0; + return true; } -int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, +bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) { float large = effect->effect.leftright.large_magnitude / 32767.0f; @@ -201,13 +201,13 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, float total = (large * 0.6f) + (small * 0.4f); Android_JNI_HapticRun(((SDL_hapticlist_item *)haptic->hwdata)->device_id, total, effect->effect.leftright.length); - return 0; + return true; } -int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) +bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) { Android_JNI_HapticStop(((SDL_hapticlist_item *)haptic->hwdata)->device_id); - return 0; + return true; } void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect) @@ -219,37 +219,37 @@ int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effe return 0; } -int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) +bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) { - return 0; + return true; } -int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) +bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) { - return 0; + return true; } -int SDL_SYS_HapticPause(SDL_Haptic *haptic) +bool SDL_SYS_HapticPause(SDL_Haptic *haptic) { - return 0; + return true; } -int SDL_SYS_HapticUnpause(SDL_Haptic *haptic) +bool SDL_SYS_HapticResume(SDL_Haptic *haptic) { - return 0; + return true; } -int SDL_SYS_HapticStopAll(SDL_Haptic *haptic) +bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic) { - return 0; + return true; } -int Android_AddHaptic(int device_id, const char *name) +bool Android_AddHaptic(int device_id, const char *name) { SDL_hapticlist_item *item; item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); if (!item) { - return -1; + return false; } item->instance_id = SDL_GetNextObjectID(); @@ -257,7 +257,7 @@ int Android_AddHaptic(int device_id, const char *name) item->name = SDL_strdup(name); if (!item->name) { SDL_free(item); - return -1; + return false; } if (!SDL_hapticlist_tail) { @@ -268,10 +268,10 @@ int Android_AddHaptic(int device_id, const char *name) } ++numhaptics; - return numhaptics; + return true; } -int Android_RemoveHaptic(int device_id) +bool Android_RemoveHaptic(int device_id) { SDL_hapticlist_item *item; SDL_hapticlist_item *prev = NULL; @@ -279,7 +279,7 @@ int Android_RemoveHaptic(int device_id) for (item = SDL_hapticlist; item; item = item->next) { // found it, remove it. if (device_id == item->device_id) { - const int retval = item->haptic ? 0 : -1; + const bool result = item->haptic ? true : false; if (prev) { prev->next = item->next; @@ -297,11 +297,11 @@ int Android_RemoveHaptic(int device_id) SDL_free(item->name); SDL_free(item); - return retval; + return result; } prev = item; } - return -1; + return false; } #endif // SDL_HAPTIC_ANDROID diff --git a/src/haptic/android/SDL_syshaptic_c.h b/src/haptic/android/SDL_syshaptic_c.h index 2359fc38a9..b0e0ed90d7 100644 --- a/src/haptic/android/SDL_syshaptic_c.h +++ b/src/haptic/android/SDL_syshaptic_c.h @@ -22,7 +22,7 @@ #ifdef SDL_HAPTIC_ANDROID -extern int Android_AddHaptic(int device_id, const char *name); -extern int Android_RemoveHaptic(int device_id); +extern bool Android_AddHaptic(int device_id, const char *name); +extern bool Android_RemoveHaptic(int device_id); #endif // SDL_HAPTIC_ANDROID diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c index 38fb9e3473..01c37f8b51 100644 --- a/src/haptic/darwin/SDL_syshaptic.c +++ b/src/haptic/darwin/SDL_syshaptic.c @@ -77,7 +77,7 @@ struct haptic_hweffect * Prototypes. */ static void SDL_SYS_HapticFreeFFEFFECT(FFEFFECT *effect, int type); -static int HIDGetDeviceProduct(io_service_t dev, char *name); +static bool HIDGetDeviceProduct(io_service_t dev, char *name); static SDL_hapticlist_item *SDL_hapticlist = NULL; static SDL_hapticlist_item *SDL_hapticlist_tail = NULL; @@ -141,7 +141,7 @@ static const char *FFStrError(unsigned int err) /* * Initializes the haptic subsystem. */ -int SDL_SYS_HapticInit(void) +bool SDL_SYS_HapticInit(void) { IOReturn result; io_iterator_t iter; @@ -167,7 +167,7 @@ int SDL_SYS_HapticInit(void) // IOServiceGetMatchingServices consumes dictionary. if (!IOIteratorIsValid(iter)) { // No iterator. - return 0; + return true; } while ((device = IOIteratorNext(iter)) != IO_OBJECT_NULL) { @@ -177,7 +177,7 @@ int SDL_SYS_HapticInit(void) } IOObjectRelease(iter); - return numhaptics; + return true; } int SDL_SYS_NumHaptics(void) @@ -213,7 +213,7 @@ static SDL_hapticlist_item *HapticByInstanceID(SDL_HapticID instance_id) return NULL; } -int MacHaptic_MaybeAddDevice(io_object_t device) +bool MacHaptic_MaybeAddDevice(io_object_t device) { IOReturn result; CFMutableDictionaryRef hidProperties; @@ -221,19 +221,19 @@ int MacHaptic_MaybeAddDevice(io_object_t device) SDL_hapticlist_item *item; if (numhaptics == -1) { - return -1; // not initialized. We'll pick these up on enumeration if we init later. + return false; // not initialized. We'll pick these up on enumeration if we init later. } // Check for force feedback. if (FFIsForceFeedback(device) != FF_OK) { - return -1; + return false; } // Make sure we don't already have it for (item = SDL_hapticlist; item; item = item->next) { if (IOObjectIsEqualTo((io_object_t)item->dev, device)) { // Already added - return -1; + return false; } } @@ -285,22 +285,22 @@ int MacHaptic_MaybeAddDevice(io_object_t device) // Device has been added. ++numhaptics; - return numhaptics; + return true; } -int MacHaptic_MaybeRemoveDevice(io_object_t device) +bool MacHaptic_MaybeRemoveDevice(io_object_t device) { SDL_hapticlist_item *item; SDL_hapticlist_item *prev = NULL; if (numhaptics == -1) { - return -1; // not initialized. ignore this. + return false; // not initialized. ignore this. } for (item = SDL_hapticlist; item; item = item->next) { // found it, remove it. if (IOObjectIsEqualTo((io_object_t)item->dev, device)) { - const int retval = item->haptic ? 0 : -1; + bool result = item->haptic ? true : false; if (prev) { prev->next = item->next; @@ -318,12 +318,12 @@ int MacHaptic_MaybeRemoveDevice(io_object_t device) IOObjectRelease(item->dev); SDL_free(item); - return retval; + return result; } prev = item; } - return -1; + return false; } SDL_HapticID SDL_SYS_HapticInstanceID(int index) @@ -352,7 +352,7 @@ const char *SDL_SYS_HapticName(int index) /* * Gets the device's product name. */ -static int HIDGetDeviceProduct(io_service_t dev, char *name) +static bool HIDGetDeviceProduct(io_service_t dev, char *name) { CFMutableDictionaryRef hidProperties, usbProperties; io_registry_entry_t parent1, parent2; @@ -412,7 +412,7 @@ static int HIDGetDeviceProduct(io_service_t dev, char *name) return SDL_SetError("Haptic: Error getting registry entries."); } - return 0; + return true; } #define FF_TEST(ff, s) \ @@ -421,7 +421,7 @@ static int HIDGetDeviceProduct(io_service_t dev, char *name) /* * Gets supported features. */ -static unsigned int GetSupportedFeatures(SDL_Haptic *haptic) +static bool GetSupportedFeatures(SDL_Haptic *haptic) { HRESULT ret; FFDeviceObjectReference device; @@ -486,16 +486,15 @@ static unsigned int GetSupportedFeatures(SDL_Haptic *haptic) supported |= SDL_HAPTIC_STATUS | SDL_HAPTIC_PAUSE; haptic->supported = supported; - return 0; + return true; } /* * Opens the haptic device from the file descriptor. */ -static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t service) +static bool SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t service) { HRESULT ret; - int ret2; // Allocate the hwdata haptic->hwdata = (struct haptic_hwdata *) SDL_calloc(1, sizeof(*haptic->hwdata)); @@ -511,8 +510,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic } // Get supported features. - ret2 = GetSupportedFeatures(haptic); - if (ret2 < 0) { + if (!GetSupportedFeatures(haptic)) { goto open_err; } @@ -541,7 +539,7 @@ static int SDL_SYS_HapticOpenFromService(SDL_Haptic *haptic, io_service_t servic SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects); - return 0; + return true; // Error handling open_err: @@ -551,13 +549,13 @@ creat_err: SDL_free(haptic->hwdata); haptic->hwdata = NULL; } - return -1; + return false; } /* * Opens a haptic device for usage. */ -int SDL_SYS_HapticOpen(SDL_Haptic *haptic) +bool SDL_SYS_HapticOpen(SDL_Haptic *haptic) { SDL_hapticlist_item *item; item = HapticByInstanceID(haptic->instance_id); @@ -581,7 +579,7 @@ int SDL_SYS_HapticMouse(void) ++device_index; } - return -1; + return 0; } /* @@ -620,13 +618,13 @@ bool SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) /* * Opens a SDL_Haptic from a SDL_Joystick. */ -int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { #ifdef SDL_JOYSTICK_IOKIT SDL_hapticlist_item *item; if (joystick->driver != &SDL_DARWIN_JoystickDriver) { - return -1; + return false; } for (item = SDL_hapticlist; item; item = item->next) { if (IOObjectIsEqualTo((io_object_t)item->dev, @@ -642,7 +640,7 @@ int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) return SDL_SYS_HapticOpenFromService(haptic, joystick->hwdata->ffservice); #else - return -1; + return false; #endif } @@ -709,7 +707,7 @@ static DWORD FFGetTriggerButton(Uint16 button) /* * Sets the direction. */ -static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir, int naxes) +static bool SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir, int naxes) { LONG *rglDir; @@ -717,13 +715,13 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir if (naxes == 0) { effect->dwFlags |= FFEFF_SPHERICAL; // Set as default. effect->rglDirection = NULL; - return 0; + return true; } // Has axes. rglDir = SDL_malloc(sizeof(LONG) * naxes); if (!rglDir) { - return -1; + return false; } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -732,7 +730,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir case SDL_HAPTIC_POLAR: effect->dwFlags |= FFEFF_POLAR; rglDir[0] = dir->dir[0]; - return 0; + return true; case SDL_HAPTIC_CARTESIAN: effect->dwFlags |= FFEFF_CARTESIAN; rglDir[0] = dir->dir[0]; @@ -742,7 +740,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir if (naxes > 2) { rglDir[2] = dir->dir[2]; } - return 0; + return true; case SDL_HAPTIC_SPHERICAL: effect->dwFlags |= FFEFF_SPHERICAL; rglDir[0] = dir->dir[0]; @@ -752,11 +750,11 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir if (naxes > 2) { rglDir[2] = dir->dir[2]; } - return 0; + return true; case SDL_HAPTIC_STEERING_AXIS: effect->dwFlags |= FFEFF_CARTESIAN; rglDir[0] = 0; - return 0; + return true; default: return SDL_SetError("Haptic: Unknown direction type."); @@ -770,7 +768,7 @@ static int SDL_SYS_SetDirection(FFEFFECT *effect, const SDL_HapticDirection *dir /* * Creates the FFEFFECT from a SDL_HapticEffect. */ -static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_HapticEffect *src) +static bool SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_HapticEffect *src) { int i; FFCONSTANTFORCE *constant = NULL; @@ -796,7 +794,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt // Envelope. envelope = SDL_calloc(1, sizeof(FFENVELOPE)); if (!envelope) { - return -1; + return false; } dest->lpEnvelope = envelope; envelope->dwSize = sizeof(FFENVELOPE); // Always should be this. @@ -810,7 +808,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt if (dest->cAxes > 0) { axes = SDL_malloc(sizeof(DWORD) * dest->cAxes); if (!axes) { - return -1; + return false; } axes[0] = haptic->hwdata->axes[0]; // Always at least one axis. if (dest->cAxes > 1) { @@ -828,7 +826,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt hap_constant = &src->constant; constant = SDL_calloc(1, sizeof(FFCONSTANTFORCE)); if (!constant) { - return -1; + return false; } // Specifics @@ -843,8 +841,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt dest->dwStartDelay = hap_constant->delay * 1000; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes)) { + return false; } // Envelope @@ -868,7 +866,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt hap_periodic = &src->periodic; periodic = SDL_calloc(1, sizeof(FFPERIODIC)); if (!periodic) { - return -1; + return false; } // Specifics @@ -887,8 +885,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt dest->dwStartDelay = hap_periodic->delay * 1000; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)) { + return false; } // Envelope @@ -912,7 +910,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt if (dest->cAxes > 0) { condition = SDL_calloc(dest->cAxes, sizeof(FFCONDITION)); if (!condition) { - return -1; + return false; } // Specifics @@ -940,8 +938,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt dest->dwStartDelay = hap_condition->delay * 1000; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)) { + return false; } // Envelope - Not actually supported by most CONDITION implementations. @@ -954,7 +952,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt hap_ramp = &src->ramp; ramp = SDL_calloc(1, sizeof(FFRAMPFORCE)); if (!ramp) { - return -1; + return false; } // Specifics @@ -970,8 +968,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt dest->dwStartDelay = hap_ramp->delay * 1000; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes)) { + return false; } // Envelope @@ -991,7 +989,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt hap_custom = &src->custom; custom = SDL_calloc(1, sizeof(FFCUSTOMFORCE)); if (!custom) { - return -1; + return false; } // Specifics @@ -1013,9 +1011,8 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt dest->dwStartDelay = hap_custom->delay * 1000; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < - 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes)) { + return false; } // Envelope @@ -1035,7 +1032,7 @@ static int SDL_SYS_ToFFEFFECT(SDL_Haptic *haptic, FFEFFECT *dest, const SDL_Hapt return SDL_SetError("Haptic: Unknown effect type."); } - return 0; + return true; } /* @@ -1114,7 +1111,7 @@ SDL_SYS_HapticEffectType(Uint16 type) /* * Creates a new haptic effect. */ -int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, +bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) { HRESULT ret; @@ -1134,7 +1131,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, } // Get the effect. - if (SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base) < 0) { + if (!SDL_SYS_ToFFEFFECT(haptic, &effect->hweffect->effect, base)) { goto err_effectdone; } @@ -1147,20 +1144,20 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, goto err_effectdone; } - return 0; + return true; err_effectdone: SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, base->type); err_hweffect: SDL_free(effect->hweffect); effect->hweffect = NULL; - return -1; + return false; } /* * Updates an effect. */ -int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, +bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) { @@ -1170,7 +1167,7 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, // Get the effect. SDL_memset(&temp, 0, sizeof(FFEFFECT)); - if (SDL_SYS_ToFFEFFECT(haptic, &temp, data) < 0) { + if (!SDL_SYS_ToFFEFFECT(haptic, &temp, data)) { goto err_update; } @@ -1194,17 +1191,17 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, SDL_SYS_HapticFreeFFEFFECT(&effect->hweffect->effect, data->type); SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(FFEFFECT)); - return 0; + return true; err_update: SDL_SYS_HapticFreeFFEFFECT(&temp, data->type); - return -1; + return false; } /* * Runs an effect. */ -int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, +bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) { HRESULT ret; @@ -1224,13 +1221,13 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, FFStrError(ret)); } - return 0; + return true; } /* * Stops an effect. */ -int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) +bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) { HRESULT ret; @@ -1240,7 +1237,7 @@ int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) FFStrError(ret)); } - return 0; + return true; } /* @@ -1272,20 +1269,20 @@ int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, ret = FFEffectGetEffectStatus(effect->hweffect->ref, &status); if (ret != FF_OK) { - return SDL_SetError("Haptic: Unable to get effect status: %s.", - FFStrError(ret)); + SDL_SetError("Haptic: Unable to get effect status: %s.", FFStrError(ret)); + return -1; } if (status == 0) { - return false; + return 0; } - return true; // Assume it's playing or emulated. + return 1; // Assume it's playing or emulated. } /* * Sets the gain. */ -int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) +bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) { HRESULT ret; Uint32 val; @@ -1297,13 +1294,13 @@ int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) return SDL_SetError("Haptic: Error setting gain: %s.", FFStrError(ret)); } - return 0; + return true; } /* * Sets the autocentering. */ -int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) +bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) { HRESULT ret; Uint32 val; @@ -1322,13 +1319,13 @@ int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) FFStrError(ret)); } - return 0; + return true; } /* * Pauses the device. */ -int SDL_SYS_HapticPause(SDL_Haptic *haptic) +bool SDL_SYS_HapticPause(SDL_Haptic *haptic) { HRESULT ret; @@ -1338,29 +1335,29 @@ int SDL_SYS_HapticPause(SDL_Haptic *haptic) return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); } - return 0; + return true; } /* * Unpauses the device. */ -int SDL_SYS_HapticUnpause(SDL_Haptic *haptic) +bool SDL_SYS_HapticResume(SDL_Haptic *haptic) { HRESULT ret; ret = FFDeviceSendForceFeedbackCommand(haptic->hwdata->device, FFSFFC_CONTINUE); if (ret != FF_OK) { - return SDL_SetError("Haptic: Error pausing device: %s.", FFStrError(ret)); + return SDL_SetError("Haptic: Error resuming device: %s.", FFStrError(ret)); } - return 0; + return true; } /* * Stops all currently playing effects. */ -int SDL_SYS_HapticStopAll(SDL_Haptic *haptic) +bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic) { HRESULT ret; @@ -1370,7 +1367,7 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic) return SDL_SetError("Haptic: Error stopping device: %s.", FFStrError(ret)); } - return 0; + return true; } #endif // SDL_HAPTIC_IOKIT diff --git a/src/haptic/darwin/SDL_syshaptic_c.h b/src/haptic/darwin/SDL_syshaptic_c.h index 13682ffd17..fde16ba473 100644 --- a/src/haptic/darwin/SDL_syshaptic_c.h +++ b/src/haptic/darwin/SDL_syshaptic_c.h @@ -25,5 +25,5 @@ #define kIOMainPortDefault kIOMasterPortDefault #endif -extern int MacHaptic_MaybeAddDevice(io_object_t device); -extern int MacHaptic_MaybeRemoveDevice(io_object_t device); +extern bool MacHaptic_MaybeAddDevice(io_object_t device); +extern bool MacHaptic_MaybeRemoveDevice(io_object_t device); diff --git a/src/haptic/dummy/SDL_syshaptic.c b/src/haptic/dummy/SDL_syshaptic.c index c003354684..69632d1675 100644 --- a/src/haptic/dummy/SDL_syshaptic.c +++ b/src/haptic/dummy/SDL_syshaptic.c @@ -24,14 +24,14 @@ #include "../SDL_syshaptic.h" -static int SDL_SYS_LogicError(void) +static bool SDL_SYS_LogicError(void) { return SDL_SetError("Logic error: No haptic devices available."); } -int SDL_SYS_HapticInit(void) +bool SDL_SYS_HapticInit(void) { - return 0; + return true; } int SDL_SYS_NumHaptics(void) @@ -51,7 +51,7 @@ const char *SDL_SYS_HapticName(int index) return NULL; } -int SDL_SYS_HapticOpen(SDL_Haptic *haptic) +bool SDL_SYS_HapticOpen(SDL_Haptic *haptic) { return SDL_SYS_LogicError(); } @@ -66,7 +66,7 @@ bool SDL_SYS_JoystickIsHaptic(SDL_Joystick *joystick) return false; } -int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { return SDL_SYS_LogicError(); } @@ -86,26 +86,26 @@ void SDL_SYS_HapticQuit(void) return; } -int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, +bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) { return SDL_SYS_LogicError(); } -int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, +bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) { return SDL_SYS_LogicError(); } -int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, +bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) { return SDL_SYS_LogicError(); } -int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) +bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) { return SDL_SYS_LogicError(); } @@ -119,30 +119,31 @@ void SDL_SYS_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effec int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect) { - return SDL_SYS_LogicError(); + SDL_SYS_LogicError(); + return -1; } -int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) +bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) { return SDL_SYS_LogicError(); } -int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) +bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) { return SDL_SYS_LogicError(); } -int SDL_SYS_HapticPause(SDL_Haptic *haptic) +bool SDL_SYS_HapticPause(SDL_Haptic *haptic) { return SDL_SYS_LogicError(); } -int SDL_SYS_HapticUnpause(SDL_Haptic *haptic) +bool SDL_SYS_HapticResume(SDL_Haptic *haptic) { return SDL_SYS_LogicError(); } -int SDL_SYS_HapticStopAll(SDL_Haptic *haptic) +bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic) { return SDL_SYS_LogicError(); } diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c index 6a91e70372..112923f1e6 100644 --- a/src/haptic/linux/SDL_syshaptic.c +++ b/src/haptic/linux/SDL_syshaptic.c @@ -38,9 +38,9 @@ #define MAX_HAPTICS 32 // It's doubtful someone has more then 32 evdev -static int MaybeAddDevice(const char *path); +static bool MaybeAddDevice(const char *path); #ifdef SDL_USE_LIBUDEV -static int MaybeRemoveDevice(const char *path); +static bool MaybeRemoveDevice(const char *path); static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, const char *devpath); #endif // SDL_USE_LIBUDEV @@ -85,16 +85,15 @@ static int numhaptics = 0; * Test whether a device has haptic properties. * Returns available properties or 0 if there are none. */ -static int EV_IsHaptic(int fd) +static Uint32 EV_IsHaptic(int fd) { - unsigned int ret; unsigned long features[1 + FF_MAX / sizeof(unsigned long)]; + Uint32 ret = 0; // Ask device for what it has. - ret = 0; if (ioctl(fd, EVIOCGBIT(EV_FF, sizeof(features)), features) < 0) { - return SDL_SetError("Haptic: Unable to get device's features: %s", - strerror(errno)); + SDL_SetError("Haptic: Unable to get device's features: %s", strerror(errno)); + return 0; } // Convert supported features to SDL_HAPTIC platform-neutral features. @@ -121,27 +120,27 @@ static int EV_IsHaptic(int fd) /* * Tests whether a device is a mouse or not. */ -static int EV_IsMouse(int fd) +static bool EV_IsMouse(int fd) { unsigned long argp[40]; // Ask for supported features. if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(argp)), argp) < 0) { - return -1; + return false; } // Currently we only test for BTN_MOUSE which can give fake positives. if (test_bit(BTN_MOUSE, argp) != 0) { - return 1; + return true; } - return 0; + return true; } /* * Initializes the haptic subsystem by finding available devices. */ -int SDL_SYS_HapticInit(void) +bool SDL_SYS_HapticInit(void) { const char joydev_pattern[] = "/dev/input/event%d"; char path[PATH_MAX]; @@ -158,11 +157,11 @@ int SDL_SYS_HapticInit(void) } #ifdef SDL_USE_LIBUDEV - if (SDL_UDEV_Init() < 0) { + if (!SDL_UDEV_Init()) { return SDL_SetError("Could not initialize UDEV"); } - if (SDL_UDEV_AddCallback(haptic_udev_callback) < 0) { + if (!SDL_UDEV_AddCallback(haptic_udev_callback)) { SDL_UDEV_Quit(); return SDL_SetError("Could not setup haptic <-> udev callback"); } @@ -171,7 +170,7 @@ int SDL_SYS_HapticInit(void) SDL_UDEV_Scan(); #endif // SDL_USE_LIBUDEV - return numhaptics; + return true; } int SDL_SYS_NumHaptics(void) @@ -229,34 +228,34 @@ static void haptic_udev_callback(SDL_UDEV_deviceevent udev_type, int udev_class, } #endif // SDL_USE_LIBUDEV -static int MaybeAddDevice(const char *path) +static bool MaybeAddDevice(const char *path) { struct stat sb; int fd; - int success; + Uint32 supported; SDL_hapticlist_item *item; if (!path) { - return -1; + return false; } // try to open fd = open(path, O_RDWR | O_CLOEXEC, 0); if (fd < 0) { - return -1; + return false; } // get file status if (fstat(fd, &sb) != 0) { close(fd); - return -1; + return false; } // check for duplicates for (item = SDL_hapticlist; item; item = item->next) { if (item->dev_num == sb.st_rdev) { close(fd); - return -1; // duplicate. + return false; // duplicate. } } @@ -265,22 +264,22 @@ static int MaybeAddDevice(const char *path) #endif // see if it works - success = EV_IsHaptic(fd); + supported = EV_IsHaptic(fd); close(fd); - if (success <= 0) { - return -1; + if (!supported) { + return false; } item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); if (!item) { - return -1; + return false; } item->instance_id = SDL_GetNextObjectID(); item->fname = SDL_strdup(path); if (!item->fname) { SDL_free(item); - return -1; + return false; } item->dev_num = sb.st_rdev; @@ -297,23 +296,23 @@ static int MaybeAddDevice(const char *path) // !!! TODO: Send a haptic add event? - return numhaptics; + return true; } #ifdef SDL_USE_LIBUDEV -static int MaybeRemoveDevice(const char *path) +static bool MaybeRemoveDevice(const char *path) { SDL_hapticlist_item *item; SDL_hapticlist_item *prev = NULL; if (!path) { - return -1; + return false; } for (item = SDL_hapticlist; item; item = item->next) { // found it, remove it. if (SDL_strcmp(path, item->fname) == 0) { - const int retval = item->haptic ? 0 : -1; + const bool result = item->haptic ? true : false; if (prev) { prev->next = item->next; @@ -331,12 +330,12 @@ static int MaybeRemoveDevice(const char *path) SDL_free(item->fname); SDL_free(item); - return retval; + return result; } prev = item; } - return -1; + return false; } #endif // SDL_USE_LIBUDEV @@ -399,7 +398,7 @@ const char *SDL_SYS_HapticName(int index) /* * Opens the haptic device from the file descriptor. */ -static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd) +static bool SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd) { // Allocate the hwdata haptic->hwdata = (struct haptic_hwdata *) @@ -429,7 +428,7 @@ static int SDL_SYS_HapticOpenFromFD(SDL_Haptic *haptic, int fd) SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects); - return 0; + return true; // Error handling open_err: @@ -438,16 +437,15 @@ open_err: SDL_free(haptic->hwdata); haptic->hwdata = NULL; } - return -1; + return false; } /* * Opens a haptic device for usage. */ -int SDL_SYS_HapticOpen(SDL_Haptic *haptic) +bool SDL_SYS_HapticOpen(SDL_Haptic *haptic) { int fd; - int ret; SDL_hapticlist_item *item; item = HapticByInstanceID(haptic->instance_id); @@ -459,14 +457,14 @@ int SDL_SYS_HapticOpen(SDL_Haptic *haptic) } // Try to create the haptic. - ret = SDL_SYS_HapticOpenFromFD(haptic, fd); // Already closes on error. - if (ret < 0) { - return -1; + if (!SDL_SYS_HapticOpenFromFD(haptic, fd)) { + // Already closes on error. + return false; } // Set the fname. haptic->hwdata->fname = SDL_strdup(item->fname); - return 0; + return true; } /* @@ -541,18 +539,17 @@ bool SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) /* * Opens a SDL_Haptic from a SDL_Joystick. */ -int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { #ifdef SDL_JOYSTICK_LINUX int fd; - int ret; SDL_hapticlist_item *item; const char *name; SDL_AssertJoysticksLocked(); if (joystick->driver != &SDL_LINUX_JoystickDriver) { - return -1; + return false; } // Find the joystick in the haptic list. for (item = SDL_hapticlist; item; item = item->next) { @@ -567,9 +564,9 @@ int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) return SDL_SetError("Haptic: Unable to open %s: %s", joystick->hwdata->fname, strerror(errno)); } - ret = SDL_SYS_HapticOpenFromFD(haptic, fd); // Already closes on error. - if (ret < 0) { - return -1; + if (!SDL_SYS_HapticOpenFromFD(haptic, fd)) { + // Already closes on error. + return false; } haptic->hwdata->fname = SDL_strdup(joystick->hwdata->fname); @@ -578,9 +575,9 @@ int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) if (name) { haptic->name = SDL_strdup(name); } - return 0; + return true; #else - return -1; + return false; #endif } @@ -658,7 +655,7 @@ static Uint16 SDL_SYS_ToButton(Uint16 button) /* * Initializes the ff_effect usable direction from a SDL_HapticDirection. */ -static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src) +static bool SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src) { Uint32 tmp; @@ -711,7 +708,7 @@ static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src) return SDL_SetError("Haptic: Unsupported direction type."); } - return 0; + return true; } #define CLAMP(x) (((x) > 32767) ? 32767 : x) @@ -719,7 +716,7 @@ static int SDL_SYS_ToDirection(Uint16 *dest, const SDL_HapticDirection *src) * Initializes the Linux effect struct from a haptic_effect. * Values above 32767 (for unsigned) are unspecified so we must clamp. */ -static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *src) +static bool SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *src) { const SDL_HapticConstant *constant; const SDL_HapticPeriodic *periodic; @@ -736,8 +733,8 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr // Header dest->type = FF_CONSTANT; - if (SDL_SYS_ToDirection(&dest->direction, &constant->direction) == -1) { - return -1; + if (!SDL_SYS_ToDirection(&dest->direction, &constant->direction)) { + return false; } // Replay @@ -770,8 +767,8 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr // Header dest->type = FF_PERIODIC; - if (SDL_SYS_ToDirection(&dest->direction, &periodic->direction) == -1) { - return -1; + if (!SDL_SYS_ToDirection(&dest->direction, &periodic->direction)) { + return false; } // Replay @@ -864,8 +861,8 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr // Header dest->type = FF_RAMP; - if (SDL_SYS_ToDirection(&dest->direction, &ramp->direction) == -1) { - return -1; + if (!SDL_SYS_ToDirection(&dest->direction, &ramp->direction)) { + return false; } // Replay @@ -912,13 +909,13 @@ static int SDL_SYS_ToFFEffect(struct ff_effect *dest, const SDL_HapticEffect *sr return SDL_SetError("Haptic: Unknown effect type."); } - return 0; + return true; } /* * Creates a new haptic effect. */ -int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, +bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) { struct ff_effect *linux_effect; @@ -927,12 +924,12 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, effect->hweffect = (struct haptic_hweffect *) SDL_calloc(1, sizeof(struct haptic_hweffect)); if (!effect->hweffect) { - return -1; + return false; } // Prepare the ff_effect linux_effect = &effect->hweffect->effect; - if (SDL_SYS_ToFFEffect(linux_effect, base) != 0) { + if (!SDL_SYS_ToFFEffect(linux_effect, base)) { goto new_effect_err; } linux_effect->id = -1; // Have the kernel give it an id @@ -944,12 +941,12 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, goto new_effect_err; } - return 0; + return true; new_effect_err: SDL_free(effect->hweffect); effect->hweffect = NULL; - return -1; + return false; } /* @@ -958,15 +955,15 @@ new_effect_err: * Note: Dynamically updating the direction can in some cases force * the effect to restart and run once. */ -int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, +bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) { struct ff_effect linux_effect; // Create the new effect - if (SDL_SYS_ToFFEffect(&linux_effect, data) != 0) { - return -1; + if (!SDL_SYS_ToFFEffect(&linux_effect, data)) { + return false; } linux_effect.id = effect->hweffect->effect.id; @@ -980,13 +977,13 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, SDL_memcpy(&effect->hweffect->effect, &linux_effect, sizeof(struct ff_effect)); - return effect->hweffect->effect.id; + return true; } /* * Runs an effect. */ -int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, +bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) { struct input_event run; @@ -1001,13 +998,13 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, return SDL_SetError("Haptic: Unable to run the effect: %s", strerror(errno)); } - return 0; + return true; } /* * Stops an effect. */ -int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) +bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) { struct input_event stop; @@ -1020,7 +1017,7 @@ int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) strerror(errno)); } - return 0; + return true; } /* @@ -1050,19 +1047,21 @@ int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, ie.code = effect->hweffect->effect.id; if (write(haptic->hwdata->fd, &ie, sizeof(ie)) < 0) { - return SDL_SetError("Haptic: Error getting device status."); + SDL_SetError("Haptic: Error getting device status."); + return -1; } - return 0; + return 1; #endif + SDL_Unsupported(); return -1; } /* * Sets the gain. */ -int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) +bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) { struct input_event ie; @@ -1074,13 +1073,13 @@ int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) return SDL_SetError("Haptic: Error setting gain: %s", strerror(errno)); } - return 0; + return true; } /* * Sets the autocentering. */ -int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) +bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) { struct input_event ie; @@ -1092,29 +1091,29 @@ int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) return SDL_SetError("Haptic: Error setting autocenter: %s", strerror(errno)); } - return 0; + return true; } /* * Pausing is not supported atm by linux. */ -int SDL_SYS_HapticPause(SDL_Haptic *haptic) +bool SDL_SYS_HapticPause(SDL_Haptic *haptic) { - return -1; + return SDL_Unsupported(); } /* * Unpausing is not supported atm by linux. */ -int SDL_SYS_HapticUnpause(SDL_Haptic *haptic) +bool SDL_SYS_HapticResume(SDL_Haptic *haptic) { - return -1; + return SDL_Unsupported(); } /* * Stops all the currently playing effects. */ -int SDL_SYS_HapticStopAll(SDL_Haptic *haptic) +bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic) { int i, ret; @@ -1127,7 +1126,7 @@ int SDL_SYS_HapticStopAll(SDL_Haptic *haptic) } } } - return 0; + return true; } #endif // SDL_HAPTIC_LINUX diff --git a/src/haptic/windows/SDL_dinputhaptic.c b/src/haptic/windows/SDL_dinputhaptic.c index 0a5c3c69a3..30c7838e22 100644 --- a/src/haptic/windows/SDL_dinputhaptic.c +++ b/src/haptic/windows/SDL_dinputhaptic.c @@ -46,7 +46,7 @@ static LPDIRECTINPUT8 dinput = NULL; /* * Like SDL_SetError but for DX error codes. */ -static int DI_SetError(const char *str, HRESULT err) +static bool DI_SetError(const char *str, HRESULT err) { return SDL_SetError("Haptic error %s", str); } @@ -61,7 +61,7 @@ static BOOL CALLBACK EnumHapticsCallback(const DIDEVICEINSTANCE *pdidInstance, V return DIENUM_CONTINUE; // continue enumerating } -int SDL_DINPUT_HapticInit(void) +bool SDL_DINPUT_HapticInit(void) { HRESULT ret; HINSTANCE instance; @@ -73,7 +73,7 @@ int SDL_DINPUT_HapticInit(void) if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_DIRECTINPUT, true)) { // In some environments, IDirectInput8_Initialize / _EnumDevices can take a minute even with no controllers. - return 0; + return true; } ret = WIN_CoInitialize(); @@ -122,10 +122,10 @@ int SDL_DINPUT_HapticInit(void) } } - return 0; + return true; } -int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) +bool SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) { HRESULT ret; LPDIRECTINPUTDEVICE8 device; @@ -134,13 +134,13 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) SDL_hapticlist_item *item = NULL; if (!dinput) { - return -1; // not initialized. We'll pick these up on enumeration if we init later. + return false; // not initialized. We'll pick these up on enumeration if we init later. } // Make sure we don't already have it for (item = SDL_hapticlist; item; item = item->next) { if (SDL_memcmp(&item->instance, pdidInstance, sizeof(*pdidInstance)) == 0) { - return -1; // Already added + return false; // Already added } } @@ -148,7 +148,7 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) ret = IDirectInput8_CreateDevice(dinput, &pdidInstance->guidInstance, &device, NULL); if (FAILED(ret)) { // DI_SetError("Creating DirectInput device",ret); - return -1; + return false; } // Get capabilities. @@ -158,23 +158,23 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) IDirectInputDevice8_Release(device); if (FAILED(ret)) { // DI_SetError("Getting device capabilities",ret); - return -1; + return false; } if ((capabilities.dwFlags & needflags) != needflags) { - return -1; // not a device we can use. + return false; // not a device we can use. } item = (SDL_hapticlist_item *)SDL_calloc(1, sizeof(SDL_hapticlist_item)); if (!item) { - return -1; + return false; } item->instance_id = SDL_GetNextObjectID(); item->name = WIN_StringToUTF8(pdidInstance->tszProductName); if (!item->name) { SDL_free(item); - return -1; + return false; } // Copy the instance over, useful for creating devices. @@ -184,13 +184,13 @@ int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) return SDL_SYS_AddHapticDevice(item); } -int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance) +bool SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance) { SDL_hapticlist_item *item; SDL_hapticlist_item *prev = NULL; if (!dinput) { - return -1; // not initialized, ignore this. + return false; // not initialized, ignore this. } for (item = SDL_hapticlist; item; item = item->next) { @@ -200,7 +200,7 @@ int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance) } prev = item; } - return -1; + return false; } /* @@ -280,7 +280,7 @@ static BOOL CALLBACK DI_EffectCallback(LPCDIEFFECTINFO pei, LPVOID pv) * - Reset actuators. * - Get supported features. */ -static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVICE8 device8, bool is_joystick) +static bool SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVICE8 device8, bool is_joystick) { HRESULT ret; DIPROPDWORD dipdw; @@ -288,7 +288,7 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI // Allocate the hwdata haptic->hwdata = (struct haptic_hwdata *)SDL_calloc(1, sizeof(*haptic->hwdata)); if (!haptic->hwdata) { - return -1; + return false; } // We'll use the device8 from now on. @@ -407,15 +407,15 @@ static int SDL_DINPUT_HapticOpenFromDevice(SDL_Haptic *haptic, LPDIRECTINPUTDEVI SDL_memset(haptic->effects, 0, sizeof(struct haptic_effect) * haptic->neffects); - return 0; + return true; // Error handling acquire_err: IDirectInputDevice8_Unacquire(haptic->hwdata->device); - return -1; + return false; } -int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item) +bool SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item) { HRESULT ret; LPDIRECTINPUTDEVICE8 device; @@ -425,17 +425,17 @@ int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item) &device, NULL); if (FAILED(ret)) { DI_SetError("Creating DirectInput device", ret); - return -1; + return false; } - if (SDL_DINPUT_HapticOpenFromDevice(haptic, device, false) < 0) { + if (!SDL_DINPUT_HapticOpenFromDevice(haptic, device, false)) { IDirectInputDevice8_Release(device); - return -1; + return false; } - return 0; + return true; } -int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) { HRESULT ret; DIDEVICEINSTANCE hap_instance, joy_instance; @@ -447,18 +447,18 @@ int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) ret = IDirectInputDevice8_GetDeviceInfo(haptic->hwdata->device, &hap_instance); if (FAILED(ret)) { - return 0; + return false; } ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance); if (FAILED(ret)) { - return 0; + return false; } return WIN_IsEqualGUID(&hap_instance.guidInstance, &joy_instance.guidInstance); } -int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { SDL_hapticlist_item *item; HRESULT ret; @@ -467,7 +467,7 @@ int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick joy_instance.dwSize = sizeof(DIDEVICEINSTANCE); ret = IDirectInputDevice8_GetDeviceInfo(joystick->hwdata->InputDevice, &joy_instance); if (FAILED(ret)) { - return -1; + return false; } // Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. @@ -524,7 +524,7 @@ static DWORD DIGetTriggerButton(Uint16 button) /* * Sets the direction. */ -static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir, int naxes) +static bool SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir, int naxes) { LONG *rglDir; @@ -532,13 +532,13 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir if (naxes == 0) { effect->dwFlags |= DIEFF_SPHERICAL; // Set as default. effect->rglDirection = NULL; - return 0; + return true; } // Has axes. rglDir = (LONG *)SDL_malloc(sizeof(LONG) * naxes); if (!rglDir) { - return -1; + return false; } SDL_memset(rglDir, 0, sizeof(LONG) * naxes); effect->rglDirection = rglDir; @@ -547,7 +547,7 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir case SDL_HAPTIC_POLAR: effect->dwFlags |= DIEFF_POLAR; rglDir[0] = dir->dir[0]; - return 0; + return true; case SDL_HAPTIC_CARTESIAN: effect->dwFlags |= DIEFF_CARTESIAN; rglDir[0] = dir->dir[0]; @@ -557,7 +557,7 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir if (naxes > 2) { rglDir[2] = dir->dir[2]; } - return 0; + return true; case SDL_HAPTIC_SPHERICAL: effect->dwFlags |= DIEFF_SPHERICAL; rglDir[0] = dir->dir[0]; @@ -567,11 +567,11 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir if (naxes > 2) { rglDir[2] = dir->dir[2]; } - return 0; + return true; case SDL_HAPTIC_STEERING_AXIS: effect->dwFlags |= DIEFF_CARTESIAN; rglDir[0] = 0; - return 0; + return true; default: return SDL_SetError("Haptic: Unknown direction type."); @@ -585,7 +585,7 @@ static int SDL_SYS_SetDirection(DIEFFECT *effect, const SDL_HapticDirection *dir /* * Creates the DIEFFECT from a SDL_HapticEffect. */ -static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, +static bool SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, const SDL_HapticEffect *src) { int i; @@ -612,7 +612,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, // Envelope. envelope = (DIENVELOPE *)SDL_calloc(1, sizeof(DIENVELOPE)); if (!envelope) { - return -1; + return false; } dest->lpEnvelope = envelope; envelope->dwSize = sizeof(DIENVELOPE); // Always should be this. @@ -626,7 +626,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, if (dest->cAxes > 0) { axes = (DWORD *)SDL_malloc(sizeof(DWORD) * dest->cAxes); if (!axes) { - return -1; + return false; } axes[0] = haptic->hwdata->axes[0]; // Always at least one axis. if (dest->cAxes > 1) { @@ -644,7 +644,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, hap_constant = &src->constant; constant = (DICONSTANTFORCE *)SDL_calloc(1, sizeof(DICONSTANTFORCE)); if (!constant) { - return -1; + return false; } // Specifics @@ -659,8 +659,8 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, dest->dwStartDelay = hap_constant->delay * 1000UL; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_constant->direction, dest->cAxes)) { + return false; } // Envelope @@ -684,7 +684,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, hap_periodic = &src->periodic; periodic = (DIPERIODIC *)SDL_calloc(1, sizeof(DIPERIODIC)); if (!periodic) { - return -1; + return false; } // Specifics @@ -703,8 +703,8 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, dest->dwStartDelay = hap_periodic->delay * 1000UL; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_periodic->direction, dest->cAxes)) { + return false; } // Envelope @@ -727,7 +727,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, hap_condition = &src->condition; condition = (DICONDITION *)SDL_calloc(dest->cAxes, sizeof(DICONDITION)); if (!condition) { - return -1; + return false; } // Specifics @@ -753,8 +753,8 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, dest->dwStartDelay = hap_condition->delay * 1000UL; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_condition->direction, dest->cAxes)) { + return false; } // Envelope - Not actually supported by most CONDITION implementations. @@ -767,7 +767,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, hap_ramp = &src->ramp; ramp = (DIRAMPFORCE *)SDL_calloc(1, sizeof(DIRAMPFORCE)); if (!ramp) { - return -1; + return false; } // Specifics @@ -783,8 +783,8 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, dest->dwStartDelay = hap_ramp->delay * 1000UL; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_ramp->direction, dest->cAxes)) { + return false; } // Envelope @@ -804,7 +804,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, hap_custom = &src->custom; custom = (DICUSTOMFORCE *)SDL_calloc(1, sizeof(DICUSTOMFORCE)); if (!custom) { - return -1; + return false; } // Specifics @@ -825,8 +825,8 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, dest->dwStartDelay = hap_custom->delay * 1000UL; // In microseconds. // Direction. - if (SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes) < 0) { - return -1; + if (!SDL_SYS_SetDirection(dest, &hap_custom->direction, dest->cAxes)) { + return false; } // Envelope @@ -846,7 +846,7 @@ static int SDL_SYS_ToDIEFFECT(SDL_Haptic *haptic, DIEFFECT *dest, return SDL_SetError("Haptic: Unknown effect type."); } - return 0; + return true; } /* @@ -920,7 +920,7 @@ static REFGUID SDL_SYS_HapticEffectType(const SDL_HapticEffect *effect) return NULL; } } -int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) +bool SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) { HRESULT ret; REFGUID type = SDL_SYS_HapticEffectType(base); @@ -930,7 +930,7 @@ int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, } // Get the effect. - if (SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base) < 0) { + if (!SDL_SYS_ToDIEFFECT(haptic, &effect->hweffect->effect, base)) { goto err_effectdone; } @@ -943,14 +943,14 @@ int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, goto err_effectdone; } - return 0; + return true; err_effectdone: SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, base->type); - return -1; + return false; } -int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) +bool SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) { HRESULT ret; DWORD flags; @@ -958,7 +958,7 @@ int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effe // Get the effect. SDL_memset(&temp, 0, sizeof(DIEFFECT)); - if (SDL_SYS_ToDIEFFECT(haptic, &temp, data) < 0) { + if (!SDL_SYS_ToDIEFFECT(haptic, &temp, data)) { goto err_update; } @@ -996,14 +996,14 @@ int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effe SDL_SYS_HapticFreeDIEFFECT(&effect->hweffect->effect, data->type); SDL_memcpy(&effect->hweffect->effect, &temp, sizeof(DIEFFECT)); - return 0; + return true; err_update: SDL_SYS_HapticFreeDIEFFECT(&temp, data->type); - return -1; + return false; } -int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) +bool SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) { HRESULT ret; DWORD iter; @@ -1020,10 +1020,10 @@ int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, if (FAILED(ret)) { return DI_SetError("Running the effect", ret); } - return 0; + return true; } -int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) +bool SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) { HRESULT ret; @@ -1031,7 +1031,7 @@ int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect if (FAILED(ret)) { return DI_SetError("Unable to stop effect", ret); } - return 0; + return true; } void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect) @@ -1061,7 +1061,7 @@ int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *e return true; } -int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain) +bool SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain) { HRESULT ret; DIPROPDWORD dipdw; @@ -1079,10 +1079,10 @@ int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain) if (FAILED(ret)) { return DI_SetError("Setting gain", ret); } - return 0; + return true; } -int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) +bool SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) { HRESULT ret; DIPROPDWORD dipdw; @@ -1100,10 +1100,10 @@ int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) if (FAILED(ret)) { return DI_SetError("Setting autocenter", ret); } - return 0; + return true; } -int SDL_DINPUT_HapticPause(SDL_Haptic *haptic) +bool SDL_DINPUT_HapticPause(SDL_Haptic *haptic) { HRESULT ret; @@ -1113,10 +1113,10 @@ int SDL_DINPUT_HapticPause(SDL_Haptic *haptic) if (FAILED(ret)) { return DI_SetError("Pausing the device", ret); } - return 0; + return true; } -int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic) +bool SDL_DINPUT_HapticResume(SDL_Haptic *haptic) { HRESULT ret; @@ -1126,10 +1126,10 @@ int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic) if (FAILED(ret)) { return DI_SetError("Pausing the device", ret); } - return 0; + return true; } -int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic) +bool SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic) { HRESULT ret; @@ -1139,7 +1139,7 @@ int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic) if (FAILED(ret)) { return DI_SetError("Stopping the device", ret); } - return 0; + return true; } #else // !SDL_HAPTIC_DINPUT @@ -1147,32 +1147,32 @@ int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic) typedef struct DIDEVICEINSTANCE DIDEVICEINSTANCE; typedef struct SDL_hapticlist_item SDL_hapticlist_item; -int SDL_DINPUT_HapticInit(void) +bool SDL_DINPUT_HapticInit(void) { - return 0; + return true; } -int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) +bool SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance) +bool SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item) +bool SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item) { return SDL_Unsupported(); } -int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) { - return SDL_Unsupported(); + return false; } -int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { return SDL_Unsupported(); } @@ -1185,22 +1185,22 @@ void SDL_DINPUT_HapticQuit(void) { } -int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) +bool SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) +bool SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) +bool SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) +bool SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) { return SDL_Unsupported(); } @@ -1211,30 +1211,31 @@ void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *ef int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect) { - return SDL_Unsupported(); + SDL_Unsupported(); + return -1; } -int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain) +bool SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) +bool SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticPause(SDL_Haptic *haptic) +bool SDL_DINPUT_HapticPause(SDL_Haptic *haptic) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic) +bool SDL_DINPUT_HapticResume(SDL_Haptic *haptic) { return SDL_Unsupported(); } -int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic) +bool SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic) { return SDL_Unsupported(); } diff --git a/src/haptic/windows/SDL_dinputhaptic_c.h b/src/haptic/windows/SDL_dinputhaptic_c.h index 11deecdd53..8e23b515ce 100644 --- a/src/haptic/windows/SDL_dinputhaptic_c.h +++ b/src/haptic/windows/SDL_dinputhaptic_c.h @@ -27,25 +27,25 @@ extern "C" { #endif -extern int SDL_DINPUT_HapticInit(void); -extern int SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance); -extern int SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance); -extern int SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item); -extern int SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick); -extern int SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick); +extern bool SDL_DINPUT_HapticInit(void); +extern bool SDL_DINPUT_HapticMaybeAddDevice(const DIDEVICEINSTANCE *pdidInstance); +extern bool SDL_DINPUT_HapticMaybeRemoveDevice(const DIDEVICEINSTANCE *pdidInstance); +extern bool SDL_DINPUT_HapticOpen(SDL_Haptic *haptic, SDL_hapticlist_item *item); +extern bool SDL_DINPUT_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick); +extern bool SDL_DINPUT_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick); extern void SDL_DINPUT_HapticClose(SDL_Haptic *haptic); extern void SDL_DINPUT_HapticQuit(void); -extern int SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base); -extern int SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data); -extern int SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations); -extern int SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect); +extern bool SDL_DINPUT_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base); +extern bool SDL_DINPUT_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data); +extern bool SDL_DINPUT_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations); +extern bool SDL_DINPUT_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect); extern void SDL_DINPUT_HapticDestroyEffect(SDL_Haptic *haptic, struct haptic_effect *effect); extern int SDL_DINPUT_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effect); -extern int SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain); -extern int SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter); -extern int SDL_DINPUT_HapticPause(SDL_Haptic *haptic); -extern int SDL_DINPUT_HapticUnpause(SDL_Haptic *haptic); -extern int SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic); +extern bool SDL_DINPUT_HapticSetGain(SDL_Haptic *haptic, int gain); +extern bool SDL_DINPUT_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter); +extern bool SDL_DINPUT_HapticPause(SDL_Haptic *haptic); +extern bool SDL_DINPUT_HapticResume(SDL_Haptic *haptic); +extern bool SDL_DINPUT_HapticStopAll(SDL_Haptic *haptic); // Ends C function definitions when using C++ #ifdef __cplusplus diff --git a/src/haptic/windows/SDL_windowshaptic.c b/src/haptic/windows/SDL_windowshaptic.c index 9423161e31..7fdbd61188 100644 --- a/src/haptic/windows/SDL_windowshaptic.c +++ b/src/haptic/windows/SDL_windowshaptic.c @@ -45,12 +45,12 @@ static int numhaptics = 0; /* * Initializes the haptic subsystem. */ -int SDL_SYS_HapticInit(void) +bool SDL_SYS_HapticInit(void) { JoyStick_DeviceData *device; - if (SDL_DINPUT_HapticInit() < 0) { - return -1; + if (!SDL_DINPUT_HapticInit()) { + return false; } /* The joystick subsystem will usually be initialized before haptics, @@ -62,10 +62,10 @@ int SDL_SYS_HapticInit(void) SDL_DINPUT_HapticMaybeAddDevice(&device->dxdevice); } - return numhaptics; + return true; } -int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item) +bool SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item) { if (!SDL_hapticlist_tail) { SDL_hapticlist = SDL_hapticlist_tail = item; @@ -77,12 +77,12 @@ int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item) // Device has been added. ++numhaptics; - return numhaptics; + return true; } -int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item) +bool SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item) { - const int retval = item->haptic ? 0 : -1; + const bool result = item->haptic ? true : false; if (prev) { prev->next = item->next; } else { @@ -95,7 +95,7 @@ int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *i --numhaptics; // !!! TODO: Send a haptic remove event? SDL_free(item); - return retval; + return result; } int SDL_SYS_NumHaptics(void) @@ -151,7 +151,7 @@ const char *SDL_SYS_HapticName(int index) /* * Opens a haptic device for usage. */ -int SDL_SYS_HapticOpen(SDL_Haptic *haptic) +bool SDL_SYS_HapticOpen(SDL_Haptic *haptic) { SDL_hapticlist_item *item = HapticByInstanceID(haptic->instance_id); return SDL_DINPUT_HapticOpen(haptic, item); @@ -205,7 +205,7 @@ bool SDL_SYS_JoystickSameHaptic(SDL_Haptic *haptic, SDL_Joystick *joystick) /* * Opens a SDL_Haptic from a SDL_Joystick. */ -int SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) +bool SDL_SYS_HapticOpenFromJoystick(SDL_Haptic *haptic, SDL_Joystick *joystick) { SDL_assert(joystick->driver == &SDL_WINDOWS_JoystickDriver); @@ -260,19 +260,19 @@ void SDL_SYS_HapticQuit(void) /* * Creates a new haptic effect. */ -int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, +bool SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *base) { - int result; + bool result; // Alloc the effect. effect->hweffect = (struct haptic_hweffect *) SDL_calloc(1, sizeof(struct haptic_hweffect)); if (!effect->hweffect) { - return -1; + return false; } result = SDL_DINPUT_HapticNewEffect(haptic, effect, base); - if (result < 0) { + if (!result) { SDL_free(effect->hweffect); effect->hweffect = NULL; } @@ -282,7 +282,7 @@ int SDL_SYS_HapticNewEffect(SDL_Haptic *haptic, struct haptic_effect *effect, /* * Updates an effect. */ -int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) +bool SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, const SDL_HapticEffect *data) { return SDL_DINPUT_HapticUpdateEffect(haptic, effect, data); } @@ -290,7 +290,7 @@ int SDL_SYS_HapticUpdateEffect(SDL_Haptic *haptic, struct haptic_effect *effect, /* * Runs an effect. */ -int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) +bool SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Uint32 iterations) { return SDL_DINPUT_HapticRunEffect(haptic, effect, iterations); } @@ -298,7 +298,7 @@ int SDL_SYS_HapticRunEffect(SDL_Haptic *haptic, struct haptic_effect *effect, Ui /* * Stops an effect. */ -int SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) +bool SDL_SYS_HapticStopEffect(SDL_Haptic *haptic, struct haptic_effect *effect) { return SDL_DINPUT_HapticStopEffect(haptic, effect); } @@ -324,7 +324,7 @@ int SDL_SYS_HapticGetEffectStatus(SDL_Haptic *haptic, struct haptic_effect *effe /* * Sets the gain. */ -int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) +bool SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) { return SDL_DINPUT_HapticSetGain(haptic, gain); } @@ -332,7 +332,7 @@ int SDL_SYS_HapticSetGain(SDL_Haptic *haptic, int gain) /* * Sets the autocentering. */ -int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) +bool SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) { return SDL_DINPUT_HapticSetAutocenter(haptic, autocenter); } @@ -340,7 +340,7 @@ int SDL_SYS_HapticSetAutocenter(SDL_Haptic *haptic, int autocenter) /* * Pauses the device. */ -int SDL_SYS_HapticPause(SDL_Haptic *haptic) +bool SDL_SYS_HapticPause(SDL_Haptic *haptic) { return SDL_DINPUT_HapticPause(haptic); } @@ -348,15 +348,15 @@ int SDL_SYS_HapticPause(SDL_Haptic *haptic) /* * Pauses the device. */ -int SDL_SYS_HapticUnpause(SDL_Haptic *haptic) +bool SDL_SYS_HapticResume(SDL_Haptic *haptic) { - return SDL_DINPUT_HapticUnpause(haptic); + return SDL_DINPUT_HapticResume(haptic); } /* * Stops all the playing effects on the device. */ -int SDL_SYS_HapticStopAll(SDL_Haptic *haptic) +bool SDL_SYS_HapticStopAll(SDL_Haptic *haptic) { return SDL_DINPUT_HapticStopAll(haptic); } diff --git a/src/haptic/windows/SDL_windowshaptic_c.h b/src/haptic/windows/SDL_windowshaptic_c.h index cd1d1eb716..5f4ac85ee8 100644 --- a/src/haptic/windows/SDL_windowshaptic_c.h +++ b/src/haptic/windows/SDL_windowshaptic_c.h @@ -76,8 +76,8 @@ typedef struct SDL_hapticlist_item extern SDL_hapticlist_item *SDL_hapticlist; -extern int SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item); -extern int SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item); +extern bool SDL_SYS_AddHapticDevice(SDL_hapticlist_item *item); +extern bool SDL_SYS_RemoveHapticDevice(SDL_hapticlist_item *prev, SDL_hapticlist_item *item); // Ends C function definitions when using C++ #ifdef __cplusplus diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c index 19843fa14e..cf4c29e3dc 100644 --- a/src/hidapi/SDL_hidapi.c +++ b/src/hidapi/SDL_hidapi.c @@ -1029,10 +1029,10 @@ static void DeleteHIDDeviceWrapper(SDL_hid_device *wrapper) SDL_free(wrapper); } -#define CHECK_DEVICE_MAGIC(device, retval) \ +#define CHECK_DEVICE_MAGIC(device, result) \ if (!SDL_ObjectValid(device, SDL_OBJECT_TYPE_HIDAPI_DEVICE)) { \ SDL_SetError("Invalid device"); \ - return retval; \ + return result; \ } #define COPY_IF_EXISTS(var) \ diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index 68ebd272a3..b298b917fd 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -1040,7 +1040,7 @@ static bool RequestBluetoothPermissions(const char *permission) // !!! FIXME: make this non-blocking! SDL_AtomicInt permission_response; SDL_AtomicSet(&permission_response, 0); - if (SDL_RequestAndroidPermission(permission, RequestAndroidPermissionBlockingCallback, &permission_response) == -1) { + if (!SDL_RequestAndroidPermission(permission, RequestAndroidPermissionBlockingCallback, &permission_response)) { return false; } diff --git a/src/hidapi/libusb/hidapi_thread_sdl.h b/src/hidapi/libusb/hidapi_thread_sdl.h index fc27721c7e..a66b3915fb 100644 --- a/src/hidapi/libusb/hidapi_thread_sdl.h +++ b/src/hidapi/libusb/hidapi_thread_sdl.h @@ -74,7 +74,7 @@ static int SDL_WaitThreadBarrier(SDL_ThreadBarrier *barrier) #include "../../thread/SDL_systhread.h" -#define HIDAPI_THREAD_TIMED_OUT SDL_MUTEX_TIMEDOUT +#define HIDAPI_THREAD_TIMED_OUT 1 typedef Uint64 hidapi_timespec; @@ -136,7 +136,11 @@ static int hidapi_thread_cond_timedwait(hidapi_thread_state *state, hidapi_times } else { timeout_ms = (Sint32)SDL_NS_TO_MS(timeout_ns); } - return SDL_WaitConditionTimeout(state->condition, state->mutex, timeout_ms); + if (SDL_WaitConditionTimeout(state->condition, state->mutex, timeout_ms)) { + return 0; + } else { + return HIDAPI_THREAD_TIMED_OUT; + } } static void hidapi_thread_cond_signal(hidapi_thread_state *state) diff --git a/src/joystick/SDL_gamepad.c b/src/joystick/SDL_gamepad.c index 888ed7a0dd..d160cad06a 100644 --- a/src/joystick/SDL_gamepad.c +++ b/src/joystick/SDL_gamepad.c @@ -129,12 +129,12 @@ struct SDL_Gamepad #undef _guarded -#define CHECK_GAMEPAD_MAGIC(gamepad, retval) \ +#define CHECK_GAMEPAD_MAGIC(gamepad, result) \ if (!SDL_ObjectValid(gamepad, SDL_OBJECT_TYPE_GAMEPAD) || \ !SDL_IsJoystickValid(gamepad->joystick)) { \ SDL_InvalidParamError("gamepad"); \ SDL_UnlockJoysticks(); \ - return retval; \ + return result; \ } static SDL_vidpid_list SDL_allowed_gamepads = { @@ -153,8 +153,8 @@ static SDL_vidpid_list SDL_ignored_gamepads = { static GamepadMapping_t *SDL_PrivateAddMappingForGUID(SDL_GUID jGUID, const char *mappingString, bool *existing, SDL_GamepadMappingPriority priority); static void SDL_PrivateLoadButtonMapping(SDL_Gamepad *gamepad, GamepadMapping_t *pGamepadMapping); static GamepadMapping_t *SDL_PrivateGetGamepadMapping(SDL_JoystickID instance_id, bool create_mapping); -static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadAxis axis, Sint16 value); -static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state); +static void SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadAxis axis, Sint16 value); +static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state); static bool HasSameOutput(SDL_GamepadBinding *a, SDL_GamepadBinding *b) { @@ -1254,7 +1254,7 @@ static bool SDL_PrivateParseGamepadElement(SDL_Gamepad *gamepad, const char *szG /* * given a gamepad mapping string update our mapping object */ -static int SDL_PrivateParseGamepadConfigString(SDL_Gamepad *gamepad, const char *pchString) +static bool SDL_PrivateParseGamepadConfigString(SDL_Gamepad *gamepad, const char *pchString) { char szGameButton[20]; char szJoystickButton[20]; @@ -1300,7 +1300,7 @@ static int SDL_PrivateParseGamepadConfigString(SDL_Gamepad *gamepad, const char if (szGameButton[0] != '\0' || szJoystickButton[0] != '\0') { SDL_PrivateParseGamepadElement(gamepad, szGameButton, szJoystickButton); } - return 0; + return true; } static void SDL_UpdateGamepadType(SDL_Gamepad *gamepad) @@ -1809,7 +1809,8 @@ int SDL_AddGamepadMappingsFromIO(SDL_IOStream *src, SDL_bool closeio) buf = (char *)SDL_LoadFile_IO(src, &db_size, closeio); if (!buf) { - return SDL_SetError("Could not allocate space to read DB into memory"); + SDL_SetError("Could not allocate space to read DB into memory"); + return -1; } line = buf; @@ -1858,7 +1859,7 @@ int SDL_AddGamepadMappingsFromFile(const char *file) return SDL_AddGamepadMappingsFromIO(SDL_IOFromFile(file, "rb"), true); } -int SDL_ReloadGamepadMappings(void) +SDL_bool SDL_ReloadGamepadMappings(void) { SDL_Gamepad *gamepad; @@ -1877,7 +1878,7 @@ int SDL_ReloadGamepadMappings(void) SDL_UnlockJoysticks(); - return 0; + return true; } static char *SDL_ConvertMappingToPositional(const char *mapping) @@ -1932,7 +1933,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa bool is_xinput_mapping = false; bool existing = false; GamepadMapping_t *pGamepadMapping; - int retval = -1; + int result = false; SDL_AssertJoysticksLocked(); @@ -1989,7 +1990,7 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa value = !value; } if (!value) { - retval = 0; + result = true; goto done; } } @@ -2038,20 +2039,20 @@ static int SDL_PrivateAddGamepadMapping(const char *mappingString, SDL_GamepadMa } if (existing) { - retval = 0; + result = true; } else { if (is_default_mapping) { s_pDefaultMapping = pGamepadMapping; } else if (is_xinput_mapping) { s_pXInputMapping = pGamepadMapping; } - retval = 1; + result = 1; } done: if (remapped) { SDL_free(remapped); } - return retval; + return result; } /* @@ -2059,15 +2060,15 @@ done: */ int SDL_AddGamepadMapping(const char *mapping) { - int retval; + int result; SDL_LockJoysticks(); { - retval = SDL_PrivateAddGamepadMapping(mapping, SDL_GAMEPAD_MAPPING_PRIORITY_API); + result = SDL_PrivateAddGamepadMapping(mapping, SDL_GAMEPAD_MAPPING_PRIORITY_API); } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2128,7 +2129,7 @@ static char *CreateMappingString(GamepadMapping_t *mapping, SDL_GUID guid) char **SDL_GetGamepadMappings(int *count) { int num_mappings = 0; - char **retval = NULL; + char **result = NULL; char **mappings = NULL; if (count) { @@ -2172,18 +2173,18 @@ char **SDL_GetGamepadMappings(int *count) SDL_UnlockJoysticks(); if (!failed) { - retval = (char **) SDL_malloc(final_allocation); - if (retval) { + result = (char **) SDL_malloc(final_allocation); + if (result) { final_allocation -= (sizeof (char *) * num_mappings + 1); - char *strptr = (char *) (retval + (num_mappings + 1)); + char *strptr = (char *) (result + (num_mappings + 1)); for (int i = 0; i < num_mappings; i++) { - retval[i] = strptr; + result[i] = strptr; const size_t slen = SDL_strlcpy(strptr, mappings[i], final_allocation) + 1; SDL_assert(final_allocation >= slen); final_allocation -= slen; strptr += slen; } - retval[num_mappings] = NULL; + result[num_mappings] = NULL; if (count) { *count = num_mappings; @@ -2198,7 +2199,7 @@ char **SDL_GetGamepadMappings(int *count) SDL_free(mappings); } - return retval; + return result; } /* @@ -2206,21 +2207,21 @@ char **SDL_GetGamepadMappings(int *count) */ char *SDL_GetGamepadMappingForGUID(SDL_GUID guid) { - char *retval; + char *result; SDL_LockJoysticks(); { GamepadMapping_t *mapping = SDL_PrivateGetGamepadMappingForGUID(guid, false); if (mapping) { - retval = CreateMappingString(mapping, guid); + result = CreateMappingString(mapping, guid); } else { SDL_SetError("Mapping not available"); - retval = NULL; + result = NULL; } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2228,26 +2229,26 @@ char *SDL_GetGamepadMappingForGUID(SDL_GUID guid) */ char *SDL_GetGamepadMapping(SDL_Gamepad *gamepad) { - char *retval; + char *result; SDL_LockJoysticks(); { CHECK_GAMEPAD_MAGIC(gamepad, NULL); - retval = CreateMappingString(gamepad->mapping, gamepad->joystick->guid); + result = CreateMappingString(gamepad->mapping, gamepad->joystick->guid); } SDL_UnlockJoysticks(); - return retval; + return result; } /* * Set the mapping string for this device */ -int SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping) +SDL_bool SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping) { SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id); - int retval = -1; + bool result = false; if (SDL_memcmp(&guid, &s_zeroGUID, sizeof(guid)) == 0) { return SDL_InvalidParamError("instance_id"); @@ -2260,12 +2261,12 @@ int SDL_SetGamepadMapping(SDL_JoystickID instance_id, const char *mapping) SDL_LockJoysticks(); { if (SDL_PrivateAddMappingForGUID(guid, mapping, NULL, SDL_GAMEPAD_MAPPING_PRIORITY_API)) { - retval = 0; + result = true; } } SDL_UnlockJoysticks(); - return retval; + return result; } static void SDL_LoadGamepadHints(void) @@ -2322,7 +2323,7 @@ static bool SDL_GetGamepadMappingFilePath(char *path, size_t size) /* * Initialize the gamepad system, mostly load our DB of gamepad config mappings */ -int SDL_InitGamepadMappings(void) +bool SDL_InitGamepadMappings(void) { char szGamepadMapPath[1024]; int i = 0; @@ -2352,10 +2353,10 @@ int SDL_InitGamepadMappings(void) PopMappingChangeTracking(); - return 0; + return true; } -int SDL_InitGamepads(void) +bool SDL_InitGamepads(void) { int i; SDL_JoystickID *joysticks; @@ -2376,7 +2377,7 @@ int SDL_InitGamepads(void) SDL_free(joysticks); } - return 0; + return true; } SDL_bool SDL_HasGamepad(void) @@ -2422,22 +2423,22 @@ SDL_JoystickID *SDL_GetGamepads(int *count) const char *SDL_GetGamepadNameForID(SDL_JoystickID instance_id) { - const char *retval = NULL; + const char *result = NULL; SDL_LockJoysticks(); { GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id, true); if (mapping) { if (SDL_strcmp(mapping->name, "*") == 0) { - retval = SDL_GetJoystickNameForID(instance_id); + result = SDL_GetJoystickNameForID(instance_id); } else { - retval = SDL_GetPersistentString(mapping->name); + result = SDL_GetPersistentString(mapping->name); } } } SDL_UnlockJoysticks(); - return retval; + return result; } const char *SDL_GetGamepadPathForID(SDL_JoystickID instance_id) @@ -2521,7 +2522,7 @@ SDL_GamepadType SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id) char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id) { - char *retval = NULL; + char *result = NULL; SDL_LockJoysticks(); { @@ -2530,12 +2531,12 @@ char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id) char pchGUID[33]; SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id); SDL_GUIDToString(guid, pchGUID, sizeof(pchGUID)); - SDL_asprintf(&retval, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); + SDL_asprintf(&result, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2543,19 +2544,19 @@ char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id) */ bool SDL_IsGamepadNameAndGUID(const char *name, SDL_GUID guid) { - bool retval; + bool result; SDL_LockJoysticks(); { if (s_pDefaultMapping || SDL_PrivateGetGamepadMappingForNameAndGUID(name, guid) != NULL) { - retval = true; + result = true; } else { - retval = false; + result = false; } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2563,29 +2564,29 @@ bool SDL_IsGamepadNameAndGUID(const char *name, SDL_GUID guid) */ SDL_bool SDL_IsGamepad(SDL_JoystickID instance_id) { - bool retval; + bool result; SDL_LockJoysticks(); { const void *value; if (SDL_FindInHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)instance_id, &value)) { - retval = (bool)(uintptr_t)value; + result = (bool)(uintptr_t)value; } else { if (SDL_PrivateGetGamepadMapping(instance_id, true) != NULL) { - retval = true; + result = true; } else { - retval = false; + result = false; } if (!s_gamepadInstanceIDs) { s_gamepadInstanceIDs = SDL_CreateHashTable(NULL, 4, SDL_HashID, SDL_KeyMatchID, NULL, false); } - SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)instance_id, (void *)(uintptr_t)retval); + SDL_InsertIntoHashTable(s_gamepadInstanceIDs, (void *)(uintptr_t)instance_id, (void *)(uintptr_t)result); } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2752,7 +2753,7 @@ void SDL_UpdateGamepads(void) */ SDL_bool SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) { - bool retval = false; + bool result = false; SDL_LockJoysticks(); { @@ -2763,14 +2764,14 @@ SDL_bool SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) for (i = 0; i < gamepad->num_bindings; ++i) { SDL_GamepadBinding *binding = &gamepad->bindings[i]; if (binding->output_type == SDL_GAMEPAD_BINDTYPE_AXIS && binding->output.axis.axis == axis) { - retval = true; + result = true; break; } } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2778,7 +2779,7 @@ SDL_bool SDL_GamepadHasAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) */ Sint16 SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) { - Sint16 retval = 0; + Sint16 result = true; SDL_LockJoysticks(); { @@ -2827,7 +2828,7 @@ Sint16 SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) } // If the value is zero, there might be another binding that makes it non-zero if (value != 0 && valid_output_range) { - retval = (Sint16)value; + result = (Sint16)value; break; } } @@ -2835,7 +2836,7 @@ Sint16 SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) } SDL_UnlockJoysticks(); - return retval; + return result; } /** @@ -2843,7 +2844,7 @@ Sint16 SDL_GetGamepadAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) */ SDL_bool SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) { - bool retval = false; + bool result = false; SDL_LockJoysticks(); { @@ -2854,14 +2855,14 @@ SDL_bool SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) for (i = 0; i < gamepad->num_bindings; ++i) { SDL_GamepadBinding *binding = &gamepad->bindings[i]; if (binding->output_type == SDL_GAMEPAD_BINDTYPE_BUTTON && binding->output.button == button) { - retval = true; + result = true; break; } } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2869,7 +2870,7 @@ SDL_bool SDL_GamepadHasButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) */ Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) { - Uint8 retval = SDL_RELEASED; + Uint8 result = SDL_RELEASED; SDL_LockJoysticks(); { @@ -2888,22 +2889,22 @@ Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) if (binding->input.axis.axis_min < binding->input.axis.axis_max) { valid_input_range = (value >= binding->input.axis.axis_min && value <= binding->input.axis.axis_max); if (valid_input_range) { - retval = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED; + result = (value >= threshold) ? SDL_PRESSED : SDL_RELEASED; break; } } else { valid_input_range = (value >= binding->input.axis.axis_max && value <= binding->input.axis.axis_min); if (valid_input_range) { - retval = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED; + result = (value <= threshold) ? SDL_PRESSED : SDL_RELEASED; break; } } } else if (binding->input_type == SDL_GAMEPAD_BINDTYPE_BUTTON) { - retval = SDL_GetJoystickButton(gamepad->joystick, binding->input.button); + result = SDL_GetJoystickButton(gamepad->joystick, binding->input.button); break; } else if (binding->input_type == SDL_GAMEPAD_BINDTYPE_HAT) { int hat_mask = SDL_GetJoystickHat(gamepad->joystick, binding->input.hat.hat); - retval = (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED; + result = (hat_mask & binding->input.hat.hat_mask) ? SDL_PRESSED : SDL_RELEASED; break; } } @@ -2911,7 +2912,7 @@ Uint8 SDL_GetGamepadButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) } SDL_UnlockJoysticks(); - return retval; + return result; } /** @@ -3013,18 +3014,18 @@ SDL_GamepadButtonLabel SDL_GetGamepadButtonLabel(SDL_Gamepad *gamepad, SDL_Gamep */ int SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad) { - int retval = 0; + int result = true; SDL_LockJoysticks(); { SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); if (joystick) { - retval = joystick->ntouchpads; + result = joystick->ntouchpads; } } SDL_UnlockJoysticks(); - return retval; + return result; } /** @@ -3032,30 +3033,30 @@ int SDL_GetNumGamepadTouchpads(SDL_Gamepad *gamepad) */ int SDL_GetNumGamepadTouchpadFingers(SDL_Gamepad *gamepad, int touchpad) { - int retval = 0; + int result = true; SDL_LockJoysticks(); { SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); if (joystick) { if (touchpad >= 0 && touchpad < joystick->ntouchpads) { - retval = joystick->touchpads[touchpad].nfingers; + result = joystick->touchpads[touchpad].nfingers; } else { - retval = SDL_InvalidParamError("touchpad"); + result = SDL_InvalidParamError("touchpad"); } } } SDL_UnlockJoysticks(); - return retval; + return result; } /** * Get the current state of a finger on a touchpad on a gamepad. */ -int SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure) +SDL_bool SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, Uint8 *state, float *x, float *y, float *pressure) { - int retval = -1; + bool result = false; SDL_LockJoysticks(); { @@ -3078,18 +3079,18 @@ int SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, if (pressure) { *pressure = info->pressure; } - retval = 0; + result = true; } else { - retval = SDL_InvalidParamError("finger"); + result = SDL_InvalidParamError("finger"); } } else { - retval = SDL_InvalidParamError("touchpad"); + result = SDL_InvalidParamError("touchpad"); } } } SDL_UnlockJoysticks(); - return retval; + return result; } /** @@ -3097,7 +3098,7 @@ int SDL_GetGamepadTouchpadFinger(SDL_Gamepad *gamepad, int touchpad, int finger, */ SDL_bool SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type) { - bool retval = false; + bool result = false; SDL_LockJoysticks(); { @@ -3106,7 +3107,7 @@ SDL_bool SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type) int i; for (i = 0; i < joystick->nsensors; ++i) { if (joystick->sensors[i].type == type) { - retval = true; + result = true; break; } } @@ -3114,13 +3115,13 @@ SDL_bool SDL_GamepadHasSensor(SDL_Gamepad *gamepad, SDL_SensorType type) } SDL_UnlockJoysticks(); - return retval; + return result; } /* * Set whether data reporting for a gamepad sensor is enabled */ -int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled) +SDL_bool SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_bool enabled) { SDL_LockJoysticks(); { @@ -3133,7 +3134,7 @@ int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_b if (sensor->type == type) { if (sensor->enabled == enabled) { SDL_UnlockJoysticks(); - return 0; + return true; } if (type == SDL_SENSOR_ACCEL && joystick->accel_sensor) { @@ -3141,7 +3142,7 @@ int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_b joystick->accel = SDL_OpenSensor(joystick->accel_sensor); if (!joystick->accel) { SDL_UnlockJoysticks(); - return -1; + return false; } } else { if (joystick->accel) { @@ -3154,7 +3155,7 @@ int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_b joystick->gyro = SDL_OpenSensor(joystick->gyro_sensor); if (!joystick->gyro) { SDL_UnlockJoysticks(); - return -1; + return false; } } else { if (joystick->gyro) { @@ -3165,17 +3166,17 @@ int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_b } else { if (enabled) { if (joystick->nsensors_enabled == 0) { - if (joystick->driver->SetSensorsEnabled(joystick, true) < 0) { + if (!joystick->driver->SetSensorsEnabled(joystick, true)) { SDL_UnlockJoysticks(); - return -1; + return false; } } ++joystick->nsensors_enabled; } else { if (joystick->nsensors_enabled == 1) { - if (joystick->driver->SetSensorsEnabled(joystick, false) < 0) { + if (!joystick->driver->SetSensorsEnabled(joystick, false)) { SDL_UnlockJoysticks(); - return -1; + return false; } } --joystick->nsensors_enabled; @@ -3184,7 +3185,7 @@ int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_b sensor->enabled = enabled; SDL_UnlockJoysticks(); - return 0; + return true; } } } @@ -3199,7 +3200,7 @@ int SDL_SetGamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type, SDL_b */ SDL_bool SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type) { - bool retval = false; + bool result = false; SDL_LockJoysticks(); { @@ -3208,7 +3209,7 @@ SDL_bool SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type) int i; for (i = 0; i < joystick->nsensors; ++i) { if (joystick->sensors[i].type == type) { - retval = joystick->sensors[i].enabled; + result = joystick->sensors[i].enabled; break; } } @@ -3216,7 +3217,7 @@ SDL_bool SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type) } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -3224,7 +3225,7 @@ SDL_bool SDL_GamepadSensorEnabled(SDL_Gamepad *gamepad, SDL_SensorType type) */ float SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type) { - float retval = 0.0f; + float result = 0.0f; SDL_LockJoysticks(); { @@ -3235,7 +3236,7 @@ float SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type) SDL_JoystickSensorInfo *sensor = &joystick->sensors[i]; if (sensor->type == type) { - retval = sensor->rate; + result = sensor->rate; break; } } @@ -3243,13 +3244,13 @@ float SDL_GetGamepadSensorDataRate(SDL_Gamepad *gamepad, SDL_SensorType type) } SDL_UnlockJoysticks(); - return retval; + return result; } /* * Get the current state of a gamepad sensor. */ -int SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values) +SDL_bool SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *data, int num_values) { SDL_LockJoysticks(); { @@ -3263,7 +3264,7 @@ int SDL_GetGamepadSensorData(SDL_Gamepad *gamepad, SDL_SensorType type, float *d num_values = SDL_min(num_values, SDL_arraysize(sensor->data)); SDL_memcpy(data, sensor->data, num_values * sizeof(*data)); SDL_UnlockJoysticks(); - return 0; + return true; } } } @@ -3285,22 +3286,22 @@ SDL_JoystickID SDL_GetGamepadID(SDL_Gamepad *gamepad) SDL_PropertiesID SDL_GetGamepadProperties(SDL_Gamepad *gamepad) { - SDL_PropertiesID retval = 0; + SDL_PropertiesID result = true; SDL_LockJoysticks(); { CHECK_GAMEPAD_MAGIC(gamepad, 0); - retval = SDL_GetJoystickProperties(gamepad->joystick); + result = SDL_GetJoystickProperties(gamepad->joystick); } SDL_UnlockJoysticks(); - return retval; + return result; } const char *SDL_GetGamepadName(SDL_Gamepad *gamepad) { - const char *retval = NULL; + const char *result = NULL; SDL_LockJoysticks(); { @@ -3308,14 +3309,14 @@ const char *SDL_GetGamepadName(SDL_Gamepad *gamepad) if (SDL_strcmp(gamepad->name, "*") == 0 || gamepad->joystick->steam_handle != 0) { - retval = SDL_GetJoystickName(gamepad->joystick); + result = SDL_GetJoystickName(gamepad->joystick); } else { - retval = SDL_GetPersistentString(gamepad->name); + result = SDL_GetPersistentString(gamepad->name); } } SDL_UnlockJoysticks(); - return retval; + return result; } const char *SDL_GetGamepadPath(SDL_Gamepad *gamepad) @@ -3372,13 +3373,13 @@ int SDL_GetGamepadPlayerIndex(SDL_Gamepad *gamepad) /** * Set the player index of an opened gamepad */ -int SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index) +SDL_bool SDL_SetGamepadPlayerIndex(SDL_Gamepad *gamepad, int player_index) { SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); if (!joystick) { // SDL_SetError() will have been called already by SDL_GetGamepadJoystick() - return -1; + return false; } return SDL_SetJoystickPlayerIndex(joystick, player_index); } @@ -3529,18 +3530,18 @@ SDL_Gamepad *SDL_GetGamepadFromID(SDL_JoystickID joyid) */ SDL_Gamepad *SDL_GetGamepadFromPlayerIndex(int player_index) { - SDL_Gamepad *retval = NULL; + SDL_Gamepad *result = NULL; SDL_LockJoysticks(); { SDL_Joystick *joystick = SDL_GetJoystickFromPlayerIndex(player_index); if (joystick) { - retval = SDL_GetGamepadFromID(joystick->instance_id); + result = SDL_GetGamepadFromID(joystick->instance_id); } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -3580,42 +3581,42 @@ SDL_GamepadBinding **SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count) return bindings; } -int SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) +SDL_bool SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) { SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); if (!joystick) { - return -1; + return false; } return SDL_RumbleJoystick(joystick, low_frequency_rumble, high_frequency_rumble, duration_ms); } -int SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms) +SDL_bool SDL_RumbleGamepadTriggers(SDL_Gamepad *gamepad, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms) { SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); if (!joystick) { - return -1; + return false; } return SDL_RumbleJoystickTriggers(joystick, left_rumble, right_rumble, duration_ms); } -int SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue) +SDL_bool SDL_SetGamepadLED(SDL_Gamepad *gamepad, Uint8 red, Uint8 green, Uint8 blue) { SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); if (!joystick) { - return -1; + return false; } return SDL_SetJoystickLED(joystick, red, green, blue); } -int SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size) +SDL_bool SDL_SendGamepadEffect(SDL_Gamepad *gamepad, const void *data, int size) { SDL_Joystick *joystick = SDL_GetGamepadJoystick(gamepad); if (!joystick) { - return -1; + return false; } return SDL_SendJoystickEffect(joystick, data, size); } @@ -3715,14 +3716,11 @@ void SDL_QuitGamepadMappings(void) /* * Event filter to transform joystick events into appropriate gamepad ones */ -static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadAxis axis, Sint16 value) +static void SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadAxis axis, Sint16 value) { - int posted; - SDL_AssertJoysticksLocked(); // translate the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_GAMEPAD_AXIS_MOTION)) { SDL_Event event; event.type = SDL_EVENT_GAMEPAD_AXIS_MOTION; @@ -3730,23 +3728,18 @@ static int SDL_SendGamepadAxis(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gamep event.gaxis.which = gamepad->joystick->instance_id; event.gaxis.axis = axis; event.gaxis.value = value; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } - return posted; } -/* - * Event filter to transform joystick events into appropriate gamepad ones - */ -static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state) +static void SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_GamepadButton button, Uint8 state) { - int posted; SDL_Event event; SDL_AssertJoysticksLocked(); if (button == SDL_GAMEPAD_BUTTON_INVALID) { - return 0; + return; } switch (state) { @@ -3758,7 +3751,7 @@ static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gam break; default: // Invalid state -- bail - return 0; + return; } if (button == SDL_GAMEPAD_BUTTON_GUIDE) { @@ -3768,27 +3761,25 @@ static int SDL_SendGamepadButton(Uint64 timestamp, SDL_Gamepad *gamepad, SDL_Gam if (gamepad->joystick->delayed_guide_button) { // Skip duplicate press - return 0; + return; } } else { if (now < (gamepad->guide_button_down + SDL_MINIMUM_GUIDE_BUTTON_DELAY_MS)) { gamepad->joystick->delayed_guide_button = true; - return 0; + return; } gamepad->joystick->delayed_guide_button = false; } } // translate the event, if desired - posted = 0; if (SDL_EventEnabled(event.type)) { event.common.timestamp = timestamp; event.gbutton.which = gamepad->joystick->instance_id; event.gbutton.button = button; event.gbutton.state = state; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } - return posted; } static const Uint32 SDL_gamepad_event_list[] = { @@ -3848,7 +3839,7 @@ void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick) const char *SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) { - const char *retval = NULL; + const char *result = NULL; #ifdef SDL_JOYSTICK_MFI const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); @@ -3856,16 +3847,16 @@ const char *SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_ { CHECK_GAMEPAD_MAGIC(gamepad, NULL); - retval = IOS_GetAppleSFSymbolsNameForButton(gamepad, button); + result = IOS_GetAppleSFSymbolsNameForButton(gamepad, button); } SDL_UnlockJoysticks(); #endif - return retval; + return result; } const char *SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) { - const char *retval = NULL; + const char *result = NULL; #ifdef SDL_JOYSTICK_MFI const char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); @@ -3873,9 +3864,9 @@ const char *SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_Ga { CHECK_GAMEPAD_MAGIC(gamepad, NULL); - retval = IOS_GetAppleSFSymbolsNameForAxis(gamepad, axis); + result = IOS_GetAppleSFSymbolsNameForAxis(gamepad, axis); } SDL_UnlockJoysticks(); #endif - return retval; + return result; } diff --git a/src/joystick/SDL_gamepad_c.h b/src/joystick/SDL_gamepad_c.h index 23005261fc..6fffe8a37f 100644 --- a/src/joystick/SDL_gamepad_c.h +++ b/src/joystick/SDL_gamepad_c.h @@ -27,9 +27,9 @@ // Useful functions and variables from SDL_gamepad.c // Initialization and shutdown functions -extern int SDL_InitGamepadMappings(void); +extern bool SDL_InitGamepadMappings(void); extern void SDL_QuitGamepadMappings(void); -extern int SDL_InitGamepads(void); +extern bool SDL_InitGamepads(void); extern void SDL_QuitGamepads(void); extern void SDL_PrivateGamepadAdded(SDL_JoystickID instance_id); diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 1956367b78..e271ab9bdb 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -416,11 +416,11 @@ static SDL_vidpid_list zero_centered_devices = { false }; -#define CHECK_JOYSTICK_MAGIC(joystick, retval) \ +#define CHECK_JOYSTICK_MAGIC(joystick, result) \ if (!SDL_ObjectValid(joystick, SDL_OBJECT_TYPE_JOYSTICK)) { \ SDL_InvalidParamError("joystick"); \ SDL_UnlockJoysticks(); \ - return retval; \ + return result; \ } bool SDL_JoysticksInitialized(void) @@ -607,17 +607,18 @@ static void SDLCALL SDL_JoystickAllowBackgroundEventsChanged(void *userdata, con } } -int SDL_InitJoysticks(void) +bool SDL_InitJoysticks(void) { - int i, status; + int i; + bool result = false; // Create the joystick list lock if (SDL_joystick_lock == NULL) { SDL_joystick_lock = SDL_CreateMutex(); } - if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) { - return -1; + if (!SDL_InitSubSystem(SDL_INIT_EVENTS)) { + return false; } SDL_LockJoysticks(); @@ -641,19 +642,18 @@ int SDL_InitJoysticks(void) SDL_InitSteamVirtualGamepadInfo(); - status = -1; for (i = 0; i < SDL_arraysize(SDL_joystick_drivers); ++i) { - if (SDL_joystick_drivers[i]->Init() >= 0) { - status = 0; + if (SDL_joystick_drivers[i]->Init()) { + result = true; } } SDL_UnlockJoysticks(); - if (status < 0) { + if (!result) { SDL_QuitJoysticks(); } - return status; + return result; } bool SDL_JoysticksOpened(void) @@ -858,7 +858,7 @@ static bool IsROGAlly(SDL_Joystick *joystick) bool has_ally_accel = false; bool has_ally_gyro = false; - if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) { + if (SDL_InitSubSystem(SDL_INIT_SENSOR)) { SDL_SensorID *sensors = SDL_GetSensors(NULL); if (sensors) { int i; @@ -958,7 +958,7 @@ static void AttemptSensorFusion(SDL_Joystick *joystick, bool invert_sensors) SDL_AssertJoysticksLocked(); - if (SDL_InitSubSystem(SDL_INIT_SENSOR) < 0) { + if (!SDL_InitSubSystem(SDL_INIT_SENSOR)) { return; } @@ -1102,7 +1102,7 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id) joystick->led_expiration = SDL_GetTicks(); joystick->battery_percent = -1; - if (driver->Open(joystick, device_index) < 0) { + if (!driver->Open(joystick, device_index)) { SDL_SetObjectValid(joystick, SDL_OBJECT_TYPE_JOYSTICK, false); SDL_free(joystick); SDL_UnlockJoysticks(); @@ -1178,26 +1178,27 @@ SDL_Joystick *SDL_OpenJoystick(SDL_JoystickID instance_id) SDL_JoystickID SDL_AttachVirtualJoystick(const SDL_VirtualJoystickDesc *desc) { #ifdef SDL_JOYSTICK_VIRTUAL - SDL_JoystickID retval; + SDL_JoystickID result; SDL_LockJoysticks(); - retval = SDL_JoystickAttachVirtualInner(desc); + result = SDL_JoystickAttachVirtualInner(desc); SDL_UnlockJoysticks(); - return retval; + return result; #else - return SDL_SetError("SDL not built with virtual-joystick support"); + SDL_SetError("SDL not built with virtual-joystick support"); + return 0; #endif } -int SDL_DetachVirtualJoystick(SDL_JoystickID instance_id) +SDL_bool SDL_DetachVirtualJoystick(SDL_JoystickID instance_id) { #ifdef SDL_JOYSTICK_VIRTUAL - int retval; + bool result; SDL_LockJoysticks(); - retval = SDL_JoystickDetachVirtualInner(instance_id); + result = SDL_JoystickDetachVirtualInner(instance_id); SDL_UnlockJoysticks(); - return retval; + return result; #else return SDL_SetError("SDL not built with virtual-joystick support"); #endif @@ -1224,118 +1225,118 @@ SDL_bool SDL_IsJoystickVirtual(SDL_JoystickID instance_id) #endif } -int SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value) +SDL_bool SDL_SetJoystickVirtualAxis(SDL_Joystick *joystick, int axis, Sint16 value) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); #ifdef SDL_JOYSTICK_VIRTUAL - retval = SDL_SetJoystickVirtualAxisInner(joystick, axis, value); + result = SDL_SetJoystickVirtualAxisInner(joystick, axis, value); #else - retval = SDL_SetError("SDL not built with virtual-joystick support"); + result = SDL_SetError("SDL not built with virtual-joystick support"); #endif } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel) +SDL_bool SDL_SetJoystickVirtualBall(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); #ifdef SDL_JOYSTICK_VIRTUAL - retval = SDL_SetJoystickVirtualBallInner(joystick, ball, xrel, yrel); + result = SDL_SetJoystickVirtualBallInner(joystick, ball, xrel, yrel); #else - retval = SDL_SetError("SDL not built with virtual-joystick support"); + result = SDL_SetError("SDL not built with virtual-joystick support"); #endif } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value) +SDL_bool SDL_SetJoystickVirtualButton(SDL_Joystick *joystick, int button, Uint8 value) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); #ifdef SDL_JOYSTICK_VIRTUAL - retval = SDL_SetJoystickVirtualButtonInner(joystick, button, value); + result = SDL_SetJoystickVirtualButtonInner(joystick, button, value); #else - retval = SDL_SetError("SDL not built with virtual-joystick support"); + result = SDL_SetError("SDL not built with virtual-joystick support"); #endif } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value) +SDL_bool SDL_SetJoystickVirtualHat(SDL_Joystick *joystick, int hat, Uint8 value) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); #ifdef SDL_JOYSTICK_VIRTUAL - retval = SDL_SetJoystickVirtualHatInner(joystick, hat, value); + result = SDL_SetJoystickVirtualHatInner(joystick, hat, value); #else - retval = SDL_SetError("SDL not built with virtual-joystick support"); + result = SDL_SetError("SDL not built with virtual-joystick support"); #endif } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure) +SDL_bool SDL_SetJoystickVirtualTouchpad(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); #ifdef SDL_JOYSTICK_VIRTUAL - retval = SDL_SetJoystickVirtualTouchpadInner(joystick, touchpad, finger, state, x, y, pressure); + result = SDL_SetJoystickVirtualTouchpadInner(joystick, touchpad, finger, state, x, y, pressure); #else - retval = SDL_SetError("SDL not built with virtual-joystick support"); + result = SDL_SetError("SDL not built with virtual-joystick support"); #endif } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values) +SDL_bool SDL_SendJoystickVirtualSensorData(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); #ifdef SDL_JOYSTICK_VIRTUAL - retval = SDL_SendJoystickVirtualSensorDataInner(joystick, type, sensor_timestamp, data, num_values); + result = SDL_SendJoystickVirtualSensorDataInner(joystick, type, sensor_timestamp, data, num_values); #else - retval = SDL_SetError("SDL not built with virtual-joystick support"); + result = SDL_SetError("SDL not built with virtual-joystick support"); #endif } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1367,17 +1368,17 @@ bool SDL_PrivateJoystickGetAutoGamepadMapping(SDL_JoystickID instance_id, SDL_Ga */ int SDL_GetNumJoystickAxes(SDL_Joystick *joystick) { - int retval; + int result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, -1); - retval = joystick->naxes; + result = joystick->naxes; } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1385,17 +1386,17 @@ int SDL_GetNumJoystickAxes(SDL_Joystick *joystick) */ int SDL_GetNumJoystickHats(SDL_Joystick *joystick) { - int retval; + int result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, -1); - retval = joystick->nhats; + result = joystick->nhats; } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1413,17 +1414,17 @@ int SDL_GetNumJoystickBalls(SDL_Joystick *joystick) */ int SDL_GetNumJoystickButtons(SDL_Joystick *joystick) { - int retval; + int result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, -1); - retval = joystick->nbuttons; + result = joystick->nbuttons; } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1454,7 +1455,7 @@ Sint16 SDL_GetJoystickAxis(SDL_Joystick *joystick, int axis) */ SDL_bool SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint16 *state) { - bool retval; + bool result; SDL_LockJoysticks(); { @@ -1462,17 +1463,17 @@ SDL_bool SDL_GetJoystickAxisInitialState(SDL_Joystick *joystick, int axis, Sint1 if (axis >= joystick->naxes) { SDL_SetError("Joystick only has %d axes", joystick->naxes); - retval = false; + result = false; } else { if (state) { *state = joystick->axes[axis].initial_value; } - retval = joystick->axes[axis].has_initial_value; + result = joystick->axes[axis].has_initial_value; } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1501,26 +1502,31 @@ Uint8 SDL_GetJoystickHat(SDL_Joystick *joystick, int hat) /* * Get the ball axis change since the last poll */ -int SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy) +SDL_bool SDL_GetJoystickBall(SDL_Joystick *joystick, int ball, int *dx, int *dy) { - int retval; + bool result; - CHECK_JOYSTICK_MAGIC(joystick, -1); + SDL_LockJoysticks(); + { + CHECK_JOYSTICK_MAGIC(joystick, -1); - retval = 0; - if (ball < joystick->nballs) { - if (dx) { - *dx = joystick->balls[ball].dx; + if (ball < joystick->nballs) { + if (dx) { + *dx = joystick->balls[ball].dx; + } + if (dy) { + *dy = joystick->balls[ball].dy; + } + joystick->balls[ball].dx = 0; + joystick->balls[ball].dy = 0; + result = true; + } else { + result = SDL_SetError("Joystick only has %d balls", joystick->nballs); } - if (dy) { - *dy = joystick->balls[ball].dy; - } - joystick->balls[ball].dx = 0; - joystick->balls[ball].dy = 0; - } else { - return SDL_SetError("Joystick only has %d balls", joystick->nballs); } - return retval; + SDL_UnlockJoysticks(); + + return result; } /* @@ -1552,17 +1558,17 @@ Uint8 SDL_GetJoystickButton(SDL_Joystick *joystick, int button) */ SDL_bool SDL_JoystickConnected(SDL_Joystick *joystick) { - bool retval; + bool result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, false); - retval = joystick->attached; + result = joystick->attached; } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1570,17 +1576,17 @@ SDL_bool SDL_JoystickConnected(SDL_Joystick *joystick) */ SDL_JoystickID SDL_GetJoystickID(SDL_Joystick *joystick) { - SDL_JoystickID retval; + SDL_JoystickID result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, 0); - retval = joystick->instance_id; + result = joystick->instance_id; } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1624,7 +1630,7 @@ SDL_Joystick *SDL_GetJoystickFromPlayerIndex(int player_index) */ SDL_PropertiesID SDL_GetJoystickProperties(SDL_Joystick *joystick) { - SDL_PropertiesID retval; + SDL_PropertiesID result; SDL_LockJoysticks(); { @@ -1633,11 +1639,11 @@ SDL_PropertiesID SDL_GetJoystickProperties(SDL_Joystick *joystick) if (joystick->props == 0) { joystick->props = SDL_CreateProperties(); } - retval = joystick->props; + result = joystick->props; } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1645,7 +1651,7 @@ SDL_PropertiesID SDL_GetJoystickProperties(SDL_Joystick *joystick) */ const char *SDL_GetJoystickName(SDL_Joystick *joystick) { - const char *retval; + const char *result; const SDL_SteamVirtualGamepadInfo *info; SDL_LockJoysticks(); @@ -1654,14 +1660,14 @@ const char *SDL_GetJoystickName(SDL_Joystick *joystick) info = SDL_GetJoystickVirtualGamepadInfoForID(joystick->instance_id); if (info) { - retval = SDL_GetPersistentString(info->name); + result = SDL_GetPersistentString(info->name); } else { - retval = SDL_GetPersistentString(joystick->name); + result = SDL_GetPersistentString(joystick->name); } } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -1669,22 +1675,22 @@ const char *SDL_GetJoystickName(SDL_Joystick *joystick) */ const char *SDL_GetJoystickPath(SDL_Joystick *joystick) { - const char *retval; + const char *result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, NULL); if (joystick->path) { - retval = SDL_GetPersistentString(joystick->path); + result = SDL_GetPersistentString(joystick->path); } else { SDL_Unsupported(); - retval = NULL; + result = NULL; } } SDL_UnlockJoysticks(); - return retval; + return result; } /** @@ -1692,49 +1698,52 @@ const char *SDL_GetJoystickPath(SDL_Joystick *joystick) */ int SDL_GetJoystickPlayerIndex(SDL_Joystick *joystick) { - int retval; + int result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, -1); - retval = SDL_GetPlayerIndexForJoystickID(joystick->instance_id); + result = SDL_GetPlayerIndexForJoystickID(joystick->instance_id); } SDL_UnlockJoysticks(); - return retval; + return result; } /** * Set the player index of an opened joystick */ -int SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index) +SDL_bool SDL_SetJoystickPlayerIndex(SDL_Joystick *joystick, int player_index) { + bool result; + SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); - SDL_SetJoystickIDForPlayerIndex(player_index, joystick->instance_id); + result = SDL_SetJoystickIDForPlayerIndex(player_index, joystick->instance_id); } SDL_UnlockJoysticks(); - return 0; + + return result; } -int SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) +SDL_bool SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); if (low_frequency_rumble == joystick->low_frequency_rumble && high_frequency_rumble == joystick->high_frequency_rumble) { // Just update the expiration - retval = 0; + result = true; } else { - retval = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble); - if (retval == 0) { + result = joystick->driver->Rumble(joystick, low_frequency_rumble, high_frequency_rumble); + if (result) { joystick->rumble_resend = SDL_GetTicks() + SDL_RUMBLE_RESEND_MS; if (joystick->rumble_resend == 0) { joystick->rumble_resend = 1; @@ -1744,7 +1753,7 @@ int SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint } } - if (retval == 0) { + if (result) { joystick->low_frequency_rumble = low_frequency_rumble; joystick->high_frequency_rumble = high_frequency_rumble; @@ -1761,25 +1770,25 @@ int SDL_RumbleJoystick(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms) +SDL_bool SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble, Uint32 duration_ms) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); if (left_rumble == joystick->left_trigger_rumble && right_rumble == joystick->right_trigger_rumble) { // Just update the expiration - retval = 0; + result = true; } else { - retval = joystick->driver->RumbleTriggers(joystick, left_rumble, right_rumble); + result = joystick->driver->RumbleTriggers(joystick, left_rumble, right_rumble); } - if (retval == 0) { + if (result) { joystick->left_trigger_rumble = left_rumble; joystick->right_trigger_rumble = right_rumble; @@ -1792,28 +1801,28 @@ int SDL_RumbleJoystickTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint1 } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +SDL_bool SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { - int retval; + bool result; bool isfreshvalue; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); isfreshvalue = red != joystick->led_red || green != joystick->led_green || blue != joystick->led_blue; if (isfreshvalue || SDL_GetTicks() >= joystick->led_expiration) { - retval = joystick->driver->SetLED(joystick, red, green, blue); + result = joystick->driver->SetLED(joystick, red, green, blue); joystick->led_expiration = SDL_GetTicks() + SDL_LED_MIN_REPEAT_MS; } else { // Avoid spamming the driver - retval = 0; + result = true; } // Save the LED value regardless of success, so we don't spam the driver @@ -1823,22 +1832,22 @@ int SDL_SetJoystickLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blu } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size) +SDL_bool SDL_SendJoystickEffect(SDL_Joystick *joystick, const void *data, int size) { - int retval; + bool result; SDL_LockJoysticks(); { - CHECK_JOYSTICK_MAGIC(joystick, -1); + CHECK_JOYSTICK_MAGIC(joystick, false); - retval = joystick->driver->SendEffect(joystick, data, size); + result = joystick->driver->SendEffect(joystick, data, size); } SDL_UnlockJoysticks(); - return retval; + return result; } /* @@ -2159,16 +2168,15 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id) } } -int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value) +void SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value) { - int posted; SDL_JoystickAxisInfo *info; SDL_AssertJoysticksLocked(); // Make sure we're not getting garbage or duplicate events if (axis >= joystick->naxes) { - return 0; + return; } info = &joystick->axes[axis]; @@ -2179,7 +2187,7 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S info->zero = value; info->has_initial_value = true; } else if (value == info->value && !info->sending_initial_value) { - return 0; + return; } else { info->has_second_value = true; } @@ -2188,7 +2196,7 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S const int MAX_ALLOWED_JITTER = SDL_JOYSTICK_AXIS_MAX / 80; // ShanWan PS3 controller needed 96 if (SDL_abs(value - info->value) <= MAX_ALLOWED_JITTER && !SDL_IsJoystickVIRTUAL(joystick->guid)) { - return 0; + return; } info->sent_initial_value = true; info->sending_initial_value = true; @@ -2203,7 +2211,7 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S if (info->sending_initial_value || (value > info->zero && value >= info->value) || (value < info->zero && value <= info->value)) { - return 0; + return; } } @@ -2213,7 +2221,6 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S joystick->update_complete = timestamp; // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_JOYSTICK_AXIS_MOTION)) { SDL_Event event; event.type = SDL_EVENT_JOYSTICK_AXIS_MOTION; @@ -2221,25 +2228,22 @@ int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, S event.jaxis.which = joystick->instance_id; event.jaxis.axis = axis; event.jaxis.value = value; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } - return posted; } -int SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel) +void SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel) { - int posted; - SDL_AssertJoysticksLocked(); // Make sure we're not getting garbage events if (ball >= joystick->nballs) { - return 0; + return; } // We ignore events if we don't have keyboard focus. if (SDL_PrivateJoystickShouldIgnoreEvent()) { - return 0; + return; } // Update internal mouse state @@ -2247,7 +2251,6 @@ int SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, S joystick->balls[ball].dy += yrel; // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_JOYSTICK_BALL_MOTION)) { SDL_Event event; event.type = SDL_EVENT_JOYSTICK_BALL_MOTION; @@ -2256,23 +2259,20 @@ int SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, S event.jball.ball = ball; event.jball.xrel = xrel; event.jball.yrel = yrel; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } - return posted; } -int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value) +void SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value) { - int posted; - SDL_AssertJoysticksLocked(); // Make sure we're not getting garbage or duplicate events if (hat >= joystick->nhats) { - return 0; + return; } if (value == joystick->hats[hat]) { - return 0; + return; } /* We ignore events if we don't have keyboard focus, except for centering @@ -2280,7 +2280,7 @@ int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uin */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { if (value != SDL_HAT_CENTERED) { - return 0; + return; } } @@ -2290,7 +2290,6 @@ int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uin joystick->update_complete = timestamp; // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_JOYSTICK_HAT_MOTION)) { SDL_Event event; event.type = SDL_EVENT_JOYSTICK_HAT_MOTION; @@ -2298,14 +2297,12 @@ int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uin event.jhat.which = joystick->instance_id; event.jhat.hat = hat; event.jhat.value = value; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } - return posted; } -int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state) +void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state) { - int posted; SDL_Event event; SDL_AssertJoysticksLocked(); @@ -2319,22 +2316,22 @@ int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butto break; default: // Invalid state -- bail - return 0; + return; } // Make sure we're not getting garbage or duplicate events if (button >= joystick->nbuttons) { - return 0; + return; } if (state == joystick->buttons[button]) { - return 0; + return; } /* We ignore events if we don't have keyboard focus, except for button * release. */ if (SDL_PrivateJoystickShouldIgnoreEvent()) { if (state == SDL_PRESSED) { - return 0; + return; } } @@ -2344,15 +2341,13 @@ int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 butto joystick->update_complete = timestamp; // Post the event, if desired - posted = 0; if (SDL_EventEnabled(event.type)) { event.common.timestamp = timestamp; event.jbutton.which = joystick->instance_id; event.jbutton.button = button; event.jbutton.state = state; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } - return posted; } static void SendSteamHandleUpdateEvents(void) @@ -3346,7 +3341,7 @@ SDL_JoystickType SDL_GetJoystickTypeForID(SDL_JoystickID instance_id) SDL_GUID SDL_GetJoystickGUID(SDL_Joystick *joystick) { - SDL_GUID retval; + SDL_GUID result; SDL_LockJoysticks(); { @@ -3354,11 +3349,11 @@ SDL_GUID SDL_GetJoystickGUID(SDL_Joystick *joystick) CHECK_JOYSTICK_MAGIC(joystick, emptyGUID); - retval = joystick->guid; + result = joystick->guid; } SDL_UnlockJoysticks(); - return retval; + return result; } Uint16 SDL_GetJoystickVendor(SDL_Joystick *joystick) @@ -3418,32 +3413,32 @@ Uint16 SDL_GetJoystickProductVersion(SDL_Joystick *joystick) Uint16 SDL_GetJoystickFirmwareVersion(SDL_Joystick *joystick) { - Uint16 retval; + Uint16 result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, 0); - retval = joystick->firmware_version; + result = joystick->firmware_version; } SDL_UnlockJoysticks(); - return retval; + return result; } const char *SDL_GetJoystickSerial(SDL_Joystick *joystick) { - const char *retval; + const char *result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, NULL); - retval = SDL_GetPersistentString(joystick->serial); + result = SDL_GetPersistentString(joystick->serial); } SDL_UnlockJoysticks(); - return retval; + return result; } SDL_JoystickType SDL_GetJoystickType(SDL_Joystick *joystick) @@ -3488,22 +3483,22 @@ void SDL_SendJoystickPowerInfo(SDL_Joystick *joystick, SDL_PowerState state, int SDL_JoystickConnectionState SDL_GetJoystickConnectionState(SDL_Joystick *joystick) { - SDL_JoystickConnectionState retval; + SDL_JoystickConnectionState result; SDL_LockJoysticks(); { CHECK_JOYSTICK_MAGIC(joystick, SDL_JOYSTICK_CONNECTION_INVALID); - retval = joystick->connection_state; + result = joystick->connection_state; } SDL_UnlockJoysticks(); - return retval; + return result; } SDL_PowerState SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent) { - SDL_PowerState retval; + SDL_PowerState result; if (percent) { *percent = -1; @@ -3513,7 +3508,7 @@ SDL_PowerState SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent) { CHECK_JOYSTICK_MAGIC(joystick, SDL_POWERSTATE_ERROR); - retval = joystick->battery_state; + result = joystick->battery_state; if (percent) { *percent = joystick->battery_percent; @@ -3521,25 +3516,24 @@ SDL_PowerState SDL_GetJoystickPowerInfo(SDL_Joystick *joystick, int *percent) } SDL_UnlockJoysticks(); - return retval; + return result; } -int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure) +void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure) { SDL_JoystickTouchpadInfo *touchpad_info; SDL_JoystickTouchpadFingerInfo *finger_info; - int posted; Uint32 event_type; SDL_AssertJoysticksLocked(); if (touchpad < 0 || touchpad >= joystick->ntouchpads) { - return 0; + return; } touchpad_info = &joystick->touchpads[touchpad]; if (finger < 0 || finger >= touchpad_info->nfingers) { - return 0; + return; } finger_info = &touchpad_info->fingers[finger]; @@ -3571,7 +3565,7 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch if (state == finger_info->state) { if (!state || (x == finger_info->x && y == finger_info->y && pressure == finger_info->pressure)) { - return 0; + return; } } @@ -3586,7 +3580,7 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch // We ignore events if we don't have keyboard focus, except for touch release if (SDL_PrivateJoystickShouldIgnoreEvent()) { if (event_type != SDL_EVENT_GAMEPAD_TOUCHPAD_UP) { - return 0; + return; } } @@ -3599,7 +3593,6 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch joystick->update_complete = timestamp; // Post the event, if desired - posted = 0; if (SDL_EventEnabled(event_type)) { SDL_Event event; event.type = event_type; @@ -3610,24 +3603,20 @@ int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touch event.gtouchpad.x = x; event.gtouchpad.y = y; event.gtouchpad.pressure = pressure; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } - return posted; } -int SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values) +void SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values) { - int i; - int posted = 0; - SDL_AssertJoysticksLocked(); // We ignore events if we don't have keyboard focus if (SDL_PrivateJoystickShouldIgnoreEvent()) { - return 0; + return; } - for (i = 0; i < joystick->nsensors; ++i) { + for (int i = 0; i < joystick->nsensors; ++i) { SDL_JoystickSensorInfo *sensor = &joystick->sensors[i]; if (sensor->type == type) { @@ -3652,13 +3641,12 @@ int SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorT SDL_memcpy(event.gsensor.data, data, num_values * sizeof(*data)); event.gsensor.sensor_timestamp = sensor_timestamp; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } } break; } } - return posted; } static void SDL_LoadVIDPIDListFromHint(const char *hint, int *num_entries, int *max_entries, Uint32 **entries) diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h index c91c2ad5eb..dd7aaeb2ac 100644 --- a/src/joystick/SDL_joystick_c.h +++ b/src/joystick/SDL_joystick_c.h @@ -35,7 +35,7 @@ struct SDL_JoystickDriver; struct SDL_SteamVirtualGamepadInfo; // Initialization and shutdown functions -extern int SDL_InitJoysticks(void); +extern bool SDL_InitJoysticks(void); extern void SDL_QuitJoysticks(void); // Return whether the joystick system is currently initialized @@ -161,12 +161,12 @@ extern void SDL_PrivateJoystickAdded(SDL_JoystickID instance_id); extern bool SDL_IsJoystickBeingAdded(void); extern void SDL_PrivateJoystickRemoved(SDL_JoystickID instance_id); extern void SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick); -extern int SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value); -extern int SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel); -extern int SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value); -extern int SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state); -extern int SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure); -extern int SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); +extern void SDL_SendJoystickAxis(Uint64 timestamp, SDL_Joystick *joystick, Uint8 axis, Sint16 value); +extern void SDL_SendJoystickBall(Uint64 timestamp, SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel); +extern void SDL_SendJoystickHat(Uint64 timestamp, SDL_Joystick *joystick, Uint8 hat, Uint8 value); +extern void SDL_SendJoystickButton(Uint64 timestamp, SDL_Joystick *joystick, Uint8 button, Uint8 state); +extern void SDL_SendJoystickTouchpad(Uint64 timestamp, SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure); +extern void SDL_SendJoystickSensor(Uint64 timestamp, SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); extern void SDL_SendJoystickPowerInfo(SDL_Joystick *joystick, SDL_PowerState state, int percent); // Function to get the Steam virtual gamepad info for a joystick diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h index 219df4375d..963a6e90a3 100644 --- a/src/joystick/SDL_sysjoystick.h +++ b/src/joystick/SDL_sysjoystick.h @@ -160,7 +160,7 @@ typedef struct SDL_JoystickDriver * Joystick 0 should be the system default joystick. * This function should return 0, or -1 on an unrecoverable error. */ - int (*Init)(void); + bool (*Init)(void); // Function to return the number of joystick devices plugged in right now int (*GetCount)(void); @@ -197,20 +197,20 @@ typedef struct SDL_JoystickDriver This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ - int (*Open)(SDL_Joystick *joystick, int device_index); + bool (*Open)(SDL_Joystick *joystick, int device_index); // Rumble functionality - int (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); - int (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); + bool (*Rumble)(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); + bool (*RumbleTriggers)(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); // LED functionality - int (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); + bool (*SetLED)(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); // General effects - int (*SendEffect)(SDL_Joystick *joystick, const void *data, int size); + bool (*SendEffect)(SDL_Joystick *joystick, const void *data, int size); // Sensor functionality - int (*SetSensorsEnabled)(SDL_Joystick *joystick, bool enabled); + bool (*SetSensorsEnabled)(SDL_Joystick *joystick, bool enabled); /* Function to update the state of a joystick - called as a device poll. * This function shouldn't update the joystick structure directly, diff --git a/src/joystick/android/SDL_sysjoystick.c b/src/joystick/android/SDL_sysjoystick.c index fa137f403d..7379fa2307 100644 --- a/src/joystick/android/SDL_sysjoystick.c +++ b/src/joystick/android/SDL_sysjoystick.c @@ -194,7 +194,7 @@ static SDL_Scancode button_to_scancode(int button) return SDL_SCANCODE_UNKNOWN; } -int Android_OnPadDown(int device_id, int keycode) +bool Android_OnPadDown(int device_id, int keycode) { Uint64 timestamp = SDL_GetTicksNS(); SDL_joylist_item *item; @@ -208,13 +208,13 @@ int Android_OnPadDown(int device_id, int keycode) SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), SDL_PRESSED); } SDL_UnlockJoysticks(); - return 0; + return true; } - return -1; + return false; } -int Android_OnPadUp(int device_id, int keycode) +bool Android_OnPadUp(int device_id, int keycode) { Uint64 timestamp = SDL_GetTicksNS(); SDL_joylist_item *item; @@ -228,13 +228,13 @@ int Android_OnPadUp(int device_id, int keycode) SDL_SendKeyboardKey(timestamp, SDL_GLOBAL_KEYBOARD_ID, keycode, button_to_scancode(button), SDL_RELEASED); } SDL_UnlockJoysticks(); - return 0; + return true; } - return -1; + return false; } -int Android_OnJoy(int device_id, int axis, float value) +bool Android_OnJoy(int device_id, int axis, float value) { Uint64 timestamp = SDL_GetTicksNS(); // Android gives joy info normalized as [-1.0, 1.0] or [0.0, 1.0] @@ -247,10 +247,10 @@ int Android_OnJoy(int device_id, int axis, float value) } SDL_UnlockJoysticks(); - return 0; + return true; } -int Android_OnHat(int device_id, int hat_id, int x, int y) +bool Android_OnHat(int device_id, int hat_id, int x, int y) { Uint64 timestamp = SDL_GetTicksNS(); const int DPAD_UP_MASK = (1 << SDL_GAMEPAD_BUTTON_DPAD_UP); @@ -295,18 +295,17 @@ int Android_OnHat(int device_id, int hat_id, int x, int y) } } SDL_UnlockJoysticks(); - return 0; + return true; } - return -1; + return false; } -int Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, int button_mask, int naxes, int axis_mask, int nhats, bool can_rumble) +void Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, int button_mask, int naxes, int axis_mask, int nhats, bool can_rumble) { SDL_joylist_item *item; SDL_GUID guid; int i; - int result = -1; SDL_LockJoysticks(); @@ -386,23 +385,18 @@ int Android_AddJoystick(int device_id, const char *name, const char *desc, int v SDL_PrivateJoystickAdded(item->device_instance); - result = numjoysticks; - #ifdef DEBUG_JOYSTICK SDL_Log("Added joystick %s with device_id %d", item->name, device_id); #endif done: SDL_UnlockJoysticks(); - - return result; } -int Android_RemoveJoystick(int device_id) +void Android_RemoveJoystick(int device_id) { SDL_joylist_item *item = SDL_joylist; SDL_joylist_item *prev = NULL; - int result = -1; SDL_LockJoysticks(); @@ -438,8 +432,6 @@ int Android_RemoveJoystick(int device_id) SDL_PrivateJoystickRemoved(item->device_instance); - result = numjoysticks; - #ifdef DEBUG_JOYSTICK SDL_Log("Removed joystick with device_id %d", device_id); #endif @@ -449,16 +441,14 @@ int Android_RemoveJoystick(int device_id) done: SDL_UnlockJoysticks(); - - return result; } static void ANDROID_JoystickDetect(void); -static int ANDROID_JoystickInit(void) +static bool ANDROID_JoystickInit(void) { ANDROID_JoystickDetect(); - return 0; + return true; } static int ANDROID_JoystickGetCount(void) @@ -561,7 +551,7 @@ static SDL_JoystickID ANDROID_JoystickGetDeviceInstanceID(int device_index) return GetJoystickByDevIndex(device_index)->device_instance; } -static int ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index) { SDL_joylist_item *item = GetJoystickByDevIndex(device_index); @@ -583,10 +573,10 @@ static int ANDROID_JoystickOpen(SDL_Joystick *joystick, int device_index) SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true); } - return 0; + return true; } -static int ANDROID_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool ANDROID_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_joylist_item *item = (SDL_joylist_item *)joystick->hwdata; if (!item) { @@ -599,25 +589,25 @@ static int ANDROID_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_r float low_frequency_intensity = (float)low_frequency_rumble / SDL_MAX_UINT16; float high_frequency_intensity = (float)high_frequency_rumble / SDL_MAX_UINT16; Android_JNI_HapticRumble(item->device_id, low_frequency_intensity, high_frequency_intensity, 5000); - return 0; + return true; } -static int ANDROID_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool ANDROID_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } -static int ANDROID_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool ANDROID_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int ANDROID_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool ANDROID_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int ANDROID_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool ANDROID_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/android/SDL_sysjoystick_c.h b/src/joystick/android/SDL_sysjoystick_c.h index 90b6f7d378..4b45ff35cc 100644 --- a/src/joystick/android/SDL_sysjoystick_c.h +++ b/src/joystick/android/SDL_sysjoystick_c.h @@ -28,12 +28,12 @@ #include "../SDL_sysjoystick.h" -extern int Android_OnPadDown(int device_id, int keycode); -extern int Android_OnPadUp(int device_id, int keycode); -extern int Android_OnJoy(int device_id, int axisnum, float value); -extern int Android_OnHat(int device_id, int hat_id, int x, int y); -extern int Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, int button_mask, int naxes, int axis_mask, int nhats, bool can_rumble); -extern int Android_RemoveJoystick(int device_id); +extern bool Android_OnPadDown(int device_id, int keycode); +extern bool Android_OnPadUp(int device_id, int keycode); +extern bool Android_OnJoy(int device_id, int axisnum, float value); +extern bool Android_OnHat(int device_id, int hat_id, int x, int y); +extern void Android_AddJoystick(int device_id, const char *name, const char *desc, int vendor_id, int product_id, int button_mask, int naxes, int axis_mask, int nhats, bool can_rumble); +extern void Android_RemoveJoystick(int device_id); // A linked list of available joysticks typedef struct SDL_joylist_item diff --git a/src/joystick/apple/SDL_mfijoystick.m b/src/joystick/apple/SDL_mfijoystick.m index e1d1cfce14..ac15568dfe 100644 --- a/src/joystick/apple/SDL_mfijoystick.m +++ b/src/joystick/apple/SDL_mfijoystick.m @@ -133,94 +133,94 @@ static SDL_JoystickDeviceItem *GetDeviceForIndex(int device_index) } #ifdef SDL_JOYSTICK_MFI -static BOOL IsControllerPS4(GCController *controller) +static bool IsControllerPS4(GCController *controller) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { if ([controller.productCategory isEqualToString:@"DualShock 4"]) { - return TRUE; + return true; } } else { if ([controller.vendorName containsString:@"DUALSHOCK"]) { - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL IsControllerPS5(GCController *controller) +static bool IsControllerPS5(GCController *controller) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { if ([controller.productCategory isEqualToString:@"DualSense"]) { - return TRUE; + return true; } } else { if ([controller.vendorName containsString:@"DualSense"]) { - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL IsControllerXbox(GCController *controller) +static bool IsControllerXbox(GCController *controller) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { if ([controller.productCategory isEqualToString:@"Xbox One"]) { - return TRUE; + return true; } } else { if ([controller.vendorName containsString:@"Xbox"]) { - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL IsControllerSwitchPro(GCController *controller) +static bool IsControllerSwitchPro(GCController *controller) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { if ([controller.productCategory isEqualToString:@"Switch Pro Controller"]) { - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL IsControllerSwitchJoyConL(GCController *controller) +static bool IsControllerSwitchJoyConL(GCController *controller) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { if ([controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (L)"]) { - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL IsControllerSwitchJoyConR(GCController *controller) +static bool IsControllerSwitchJoyConR(GCController *controller) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { if ([controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (R)"]) { - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL IsControllerSwitchJoyConPair(GCController *controller) +static bool IsControllerSwitchJoyConPair(GCController *controller) { if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { if ([controller.productCategory isEqualToString:@"Nintendo Switch Joy-Con (L/R)"]) { - return TRUE; + return true; } } - return FALSE; + return false; } -static BOOL IsControllerStadia(GCController *controller) +static bool IsControllerStadia(GCController *controller) { if ([controller.vendorName hasPrefix:@"Stadia"]) { - return TRUE; + return true; } - return FALSE; + return false; } -static BOOL IsControllerBackboneOne(GCController *controller) +static bool IsControllerBackboneOne(GCController *controller) { if ([controller.vendorName hasPrefix:@"Backbone One"]) { - return TRUE; + return true; } - return FALSE; + return false; } static void CheckControllerSiriRemote(GCController *controller, int *is_siri_remote) { @@ -235,69 +235,69 @@ static void CheckControllerSiriRemote(GCController *controller, int *is_siri_rem } #ifdef ENABLE_PHYSICAL_INPUT_PROFILE -static BOOL ElementAlreadyHandled(SDL_JoystickDeviceItem *device, NSString *element, NSDictionary *elements) +static bool ElementAlreadyHandled(SDL_JoystickDeviceItem *device, NSString *element, NSDictionary *elements) { if ([element isEqualToString:@"Left Thumbstick Left"] || [element isEqualToString:@"Left Thumbstick Right"]) { if (elements[@"Left Thumbstick X Axis"]) { - return TRUE; + return true; } } if ([element isEqualToString:@"Left Thumbstick Up"] || [element isEqualToString:@"Left Thumbstick Down"]) { if (elements[@"Left Thumbstick Y Axis"]) { - return TRUE; + return true; } } if ([element isEqualToString:@"Right Thumbstick Left"] || [element isEqualToString:@"Right Thumbstick Right"]) { if (elements[@"Right Thumbstick X Axis"]) { - return TRUE; + return true; } } if ([element isEqualToString:@"Right Thumbstick Up"] || [element isEqualToString:@"Right Thumbstick Down"]) { if (elements[@"Right Thumbstick Y Axis"]) { - return TRUE; + return true; } } if (device->is_siri_remote) { if ([element isEqualToString:@"Direction Pad Left"] || [element isEqualToString:@"Direction Pad Right"]) { if (elements[@"Direction Pad X Axis"]) { - return TRUE; + return true; } } if ([element isEqualToString:@"Direction Pad Up"] || [element isEqualToString:@"Direction Pad Down"]) { if (elements[@"Direction Pad Y Axis"]) { - return TRUE; + return true; } } } else { if ([element isEqualToString:@"Direction Pad X Axis"]) { if (elements[@"Direction Pad Left"] && elements[@"Direction Pad Right"]) { - return TRUE; + return true; } } if ([element isEqualToString:@"Direction Pad Y Axis"]) { if (elements[@"Direction Pad Up"] && elements[@"Direction Pad Down"]) { - return TRUE; + return true; } } } if ([element isEqualToString:@"Cardinal Direction Pad X Axis"]) { if (elements[@"Cardinal Direction Pad Left"] && elements[@"Cardinal Direction Pad Right"]) { - return TRUE; + return true; } } if ([element isEqualToString:@"Cardinal Direction Pad Y Axis"]) { if (elements[@"Cardinal Direction Pad Up"] && elements[@"Cardinal Direction Pad Down"]) { - return TRUE; + return true; } } if ([element isEqualToString:@"Touchpad 1 X Axis"] || @@ -313,29 +313,29 @@ static BOOL ElementAlreadyHandled(SDL_JoystickDeviceItem *device, NSString *elem [element isEqualToString:@"Touchpad 2 Up"] || [element isEqualToString:@"Touchpad 2 Down"]) { // The touchpad is handled separately - return TRUE; + return true; } if ([element isEqualToString:@"Button Home"]) { if (device->is_switch_joycon_pair) { // The Nintendo Switch JoyCon home button doesn't ever show as being held down - return TRUE; + return true; } #ifdef SDL_PLATFORM_TVOS // The OS uses the home button, it's not available to apps - return TRUE; + return true; #endif } if ([element isEqualToString:@"Button Share"]) { if (device->is_backbone_one) { // The Backbone app uses share button - return TRUE; + return true; } } - return FALSE; + return false; } #endif // ENABLE_PHYSICAL_INPUT_PROFILE -static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller) +static bool IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCController *controller) { Uint16 vendor = 0; Uint16 product = 0; @@ -401,7 +401,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle (device->is_switch_joyconL && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_LEFT, 0, "")) || (device->is_switch_joyconR && HIDAPI_IsDevicePresent(USB_VENDOR_NINTENDO, USB_PRODUCT_NINTENDO_SWITCH_JOYCON_RIGHT, 0, ""))) { // The HIDAPI driver is taking care of this device - return FALSE; + return false; } #endif CheckControllerSiriRemote(controller, &device->is_siri_remote); @@ -501,29 +501,29 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle NSArray *axes = [[[elements allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id object, NSDictionary *bindings) { if (ElementAlreadyHandled(device, (NSString *)object, elements)) { - return NO; + return false; } GCControllerElement *element = elements[object]; if (element.analog) { if ([element isKindOfClass:[GCControllerAxisInput class]] || [element isKindOfClass:[GCControllerButtonInput class]]) { - return YES; + return true; } } - return NO; + return false; }]]; NSArray *buttons = [[[elements allKeys] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)] filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id object, NSDictionary *bindings) { if (ElementAlreadyHandled(device, (NSString *)object, elements)) { - return NO; + return false; } GCControllerElement *element = elements[object]; if ([element isKindOfClass:[GCControllerButtonInput class]]) { - return YES; + return true; } - return NO; + return false; }]]; /* Explicitly retain the arrays because SDL_JoystickDeviceItem is a * struct, and ARC doesn't work with structs. */ @@ -668,7 +668,7 @@ static BOOL IOS_AddMFIJoystickDevice(SDL_JoystickDeviceItem *device, GCControlle /* This will be set when the first button press of the controller is * detected. */ controller.playerIndex = -1; - return TRUE; + return true; } #endif // SDL_JOYSTICK_MFI @@ -796,10 +796,10 @@ static void SDLCALL SDL_AppleTVRemoteRotationHintChanged(void *udata, const char } #endif // SDL_PLATFORM_TVOS -static int IOS_JoystickInit(void) +static bool IOS_JoystickInit(void) { if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_MFI, true)) { - return 0; + return true; } #ifdef SDL_PLATFORM_MACOS @@ -807,11 +807,11 @@ static int IOS_JoystickInit(void) if (@available(macOS 10.16, *)) { // Continue with initialization on macOS 11+ } else { - return 0; + return true; } #else // No @available, must be an older macOS version - return 0; + return true; #endif #endif @@ -823,7 +823,7 @@ static int IOS_JoystickInit(void) #ifdef SDL_JOYSTICK_MFI // GameController.framework was added in iOS 7. if (![GCController class]) { - return 0; + return true; } /* For whatever reason, this always returns an empty array on @@ -867,7 +867,7 @@ static int IOS_JoystickInit(void) #endif // SDL_JOYSTICK_MFI } - return 0; + return true; } static int IOS_JoystickGetCount(void) @@ -937,10 +937,10 @@ static SDL_GUID IOS_JoystickGetDeviceGUID(int device_index) static SDL_JoystickID IOS_JoystickGetDeviceInstanceID(int device_index) { SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); - return device ? device->instance_id : -1; + return device ? device->instance_id : 0; } -static int IOS_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool IOS_JoystickOpen(SDL_Joystick *joystick, int device_index) { SDL_JoystickDeviceItem *device = GetDeviceForIndex(device_index); if (device == NULL) { @@ -1021,7 +1021,7 @@ static int IOS_JoystickOpen(SDL_Joystick *joystick, int device_index) ++SDL_AppleTVRemoteOpenedAsJoystick; } - return 0; + return true; } #ifdef SDL_JOYSTICK_MFI @@ -1349,7 +1349,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) } } -- (int)setIntensity:(float)intensity +- (bool)setIntensity:(float)intensity { @autoreleasepool { if (@available(macOS 10.16, iOS 14.0, tvOS 14.0, *)) { @@ -1365,7 +1365,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) [self.player stopAtTime:0 error:&error]; } self.active = false; - return 0; + return true; } if (self.player == nil) { @@ -1395,7 +1395,7 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) } } - return 0; + return true; } } @@ -1468,26 +1468,26 @@ static void IOS_MFIJoystickUpdate(SDL_Joystick *joystick) return self; } -- (int)rumbleWithLowFrequency:(Uint16)low_frequency_rumble andHighFrequency:(Uint16)high_frequency_rumble +- (bool)rumbleWithLowFrequency:(Uint16)low_frequency_rumble andHighFrequency:(Uint16)high_frequency_rumble { - int result = 0; + bool result = true; - result += [self.lowFrequencyMotor setIntensity:((float)low_frequency_rumble / 65535.0f)]; - result += [self.highFrequencyMotor setIntensity:((float)high_frequency_rumble / 65535.0f)]; - return ((result < 0) ? -1 : 0); + result &= [self.lowFrequencyMotor setIntensity:((float)low_frequency_rumble / 65535.0f)]; + result &= [self.highFrequencyMotor setIntensity:((float)high_frequency_rumble / 65535.0f)]; + return result; } -- (int)rumbleLeftTrigger:(Uint16)left_rumble andRightTrigger:(Uint16)right_rumble +- (bool)rumbleLeftTrigger:(Uint16)left_rumble andRightTrigger:(Uint16)right_rumble { - int result = 0; + bool result = false; if (self.leftTriggerMotor && self.rightTriggerMotor) { - result += [self.leftTriggerMotor setIntensity:((float)left_rumble / 65535.0f)]; - result += [self.rightTriggerMotor setIntensity:((float)right_rumble / 65535.0f)]; + result &= [self.leftTriggerMotor setIntensity:((float)left_rumble / 65535.0f)]; + result &= [self.rightTriggerMotor setIntensity:((float)right_rumble / 65535.0f)]; } else { result = SDL_Unsupported(); } - return ((result < 0) ? -1 : 0); + return result; } - (void)cleanup @@ -1519,7 +1519,7 @@ static SDL3_RumbleContext *IOS_JoystickInitRumble(GCController *controller) #endif // ENABLE_MFI_RUMBLE -static int IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { #ifdef ENABLE_MFI_RUMBLE SDL_JoystickDeviceItem *device = joystick->hwdata; @@ -1548,7 +1548,7 @@ static int IOS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl #endif } -static int IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { #ifdef ENABLE_MFI_RUMBLE SDL_JoystickDeviceItem *device = joystick->hwdata; @@ -1577,7 +1577,7 @@ static int IOS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble #endif } -static int IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { #ifdef ENABLE_MFI_LIGHT @autoreleasepool { @@ -1594,7 +1594,7 @@ static int IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Ui light.color = [[GCColor alloc] initWithRed:(float)red / 255.0f green:(float)green / 255.0f blue:(float)blue / 255.0f]; - return 0; + return true; } } } @@ -1603,12 +1603,12 @@ static int IOS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Ui return SDL_Unsupported(); } -static int IOS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool IOS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int IOS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool IOS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { #ifdef ENABLE_MFI_SENSORS @autoreleasepool { @@ -1623,7 +1623,7 @@ static int IOS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) GCMotion *motion = controller.motion; if (motion) { motion.sensorsActive = enabled ? YES : NO; - return 0; + return true; } } } diff --git a/src/joystick/bsd/SDL_bsdjoystick.c b/src/joystick/bsd/SDL_bsdjoystick.c index 26cf739729..d36b7379cb 100644 --- a/src/joystick/bsd/SDL_bsdjoystick.c +++ b/src/joystick/bsd/SDL_bsdjoystick.c @@ -182,7 +182,7 @@ static SDL_joylist_item *SDL_joylist = NULL; static SDL_joylist_item *SDL_joylist_tail = NULL; static int numjoysticks = 0; -static int report_alloc(struct report *, struct report_desc *, int); +static bool report_alloc(struct report *, struct report_desc *, int); static void report_free(struct report *); #if defined(USBHID_UCR_DATA) || (defined(__FreeBSD_kernel__) && __FreeBSD_kernel_version <= 800063) @@ -250,8 +250,7 @@ static void FreeHwData(struct joystick_hwdata *hw) SDL_free(hw); } -static struct joystick_hwdata * -CreateHwData(const char *path) +static struct joystick_hwdata *CreateHwData(const char *path) { struct joystick_hwdata *hw; struct hid_item hitem; @@ -304,7 +303,7 @@ CreateHwData(const char *path) #endif rep->rid = -1; // XXX } - if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) { + if (!report_alloc(rep, hw->repdesc, REPORT_INPUT)) { goto usberr; } if (rep->size <= 0) { @@ -389,7 +388,7 @@ usberr: return NULL; } -static int MaybeAddDevice(const char *path) +static bool MaybeAddDevice(const char *path) { struct stat sb; char *name = NULL; @@ -398,23 +397,23 @@ static int MaybeAddDevice(const char *path) struct joystick_hwdata *hw; if (!path) { - return -1; + return false; } if (stat(path, &sb) == -1) { - return -1; + return false; } // Check to make sure it's not already in list. for (item = SDL_joylist; item; item = item->next) { if (sb.st_rdev == item->devnum) { - return -1; // already have this one + return false; // already have this one } } hw = CreateHwData(path); if (!hw) { - return -1; + return false; } if (hw->type == BSDJOY_JOY) { @@ -431,7 +430,7 @@ static int MaybeAddDevice(const char *path) SDL_JoystickHandledByAnotherDriver(&SDL_BSD_JoystickDriver, di.udi_vendorNo, di.udi_productNo, di.udi_releaseNo, name)) { SDL_free(name); FreeHwData(hw); - return -1; + return false; } } #endif // USB_GET_DEVICEINFO @@ -445,7 +444,7 @@ static int MaybeAddDevice(const char *path) item = (SDL_joylist_item *)SDL_calloc(1, sizeof(SDL_joylist_item)); if (!item) { SDL_free(name); - return -1; + return false; } item->devnum = sb.st_rdev; @@ -455,7 +454,7 @@ static int MaybeAddDevice(const char *path) if ((!item->path) || (!item->name)) { FreeJoylistItem(item); - return -1; + return false; } item->device_instance = SDL_GetNextObjectID(); @@ -471,10 +470,10 @@ static int MaybeAddDevice(const char *path) SDL_PrivateJoystickAdded(item->device_instance); - return numjoysticks; + return true; } -static int BSD_JoystickInit(void) +static bool BSD_JoystickInit(void) { char s[16]; int i; @@ -497,7 +496,7 @@ static int BSD_JoystickInit(void) // Read the default USB HID usage table. hid_init(NULL); - return numjoysticks; + return true; } static int BSD_JoystickGetCount(void) @@ -581,7 +580,7 @@ static unsigned hatval_to_sdl(Sint32 hatval) return result; } -static int BSD_JoystickOpen(SDL_Joystick *joy, int device_index) +static bool BSD_JoystickOpen(SDL_Joystick *joy, int device_index) { SDL_joylist_item *item = GetJoystickByDevIndex(device_index); struct joystick_hwdata *hw; @@ -592,7 +591,7 @@ static int BSD_JoystickOpen(SDL_Joystick *joy, int device_index) hw = CreateHwData(item->path); if (!hw) { - return -1; + return false; } joy->hwdata = hw; @@ -600,7 +599,7 @@ static int BSD_JoystickOpen(SDL_Joystick *joy, int device_index) joy->nbuttons = hw->nbuttons; joy->nhats = hw->nhats; - return 0; + return true; } static void BSD_JoystickUpdate(SDL_Joystick *joy) @@ -759,7 +758,7 @@ static void BSD_JoystickQuit(void) numjoysticks = 0; } -static int report_alloc(struct report *r, struct report_desc *rd, int repind) +static bool report_alloc(struct report *r, struct report_desc *rd, int repind) { int len; @@ -796,14 +795,14 @@ static int report_alloc(struct report *r, struct report_desc *rd, int repind) r->size); #endif if (!r->buf) { - return -1; + return false; } } else { r->buf = NULL; } r->status = SREPORT_CLEAN; - return 0; + return true; } static void report_free(struct report *r) @@ -812,12 +811,12 @@ static void report_free(struct report *r) r->status = SREPORT_UNINIT; } -static int BSD_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool BSD_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } -static int BSD_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool BSD_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -827,17 +826,17 @@ static bool BSD_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping * return false; } -static int BSD_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool BSD_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int BSD_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool BSD_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int BSD_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool BSD_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/darwin/SDL_iokitjoystick.c b/src/joystick/darwin/SDL_iokitjoystick.c index fdefeb53fd..fd2e761570 100644 --- a/src/joystick/darwin/SDL_iokitjoystick.c +++ b/src/joystick/darwin/SDL_iokitjoystick.c @@ -175,7 +175,7 @@ static recDevice *FreeDevice(recDevice *removeDevice) static bool GetHIDElementState(recDevice *pDevice, recElement *pElement, SInt32 *pValue) { SInt32 value = 0; - int returnValue = false; + bool result = false; if (pDevice && pDevice->deviceRef && pElement) { IOHIDValueRef valueRef; @@ -191,26 +191,26 @@ static bool GetHIDElementState(recDevice *pDevice, recElement *pElement, SInt32 } *pValue = value; - returnValue = true; + result = true; } } - return returnValue; + return result; } static bool GetHIDScaledCalibratedState(recDevice *pDevice, recElement *pElement, SInt32 min, SInt32 max, SInt32 *pValue) { const float deviceScale = max - min; const float readScale = pElement->maxReport - pElement->minReport; - int returnValue = false; + bool result = false; if (GetHIDElementState(pDevice, pElement, pValue)) { if (readScale == 0) { - returnValue = true; // no scaling at all + result = true; // no scaling at all } else { *pValue = (Sint32)(((*pValue - pElement->minReport) * deviceScale / readScale) + min); - returnValue = true; + result = true; } } - return returnValue; + return result; } static void JoystickDeviceWasRemovedCallback(void *ctx, IOReturn result, void *sender) @@ -609,14 +609,14 @@ static bool ConfigHIDManager(CFArrayRef matchingArray) static CFDictionaryRef CreateHIDDeviceMatchDictionary(const UInt32 page, const UInt32 usage, int *okay) { - CFDictionaryRef retval = NULL; + CFDictionaryRef result = NULL; CFNumberRef pageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &page); CFNumberRef usageNumRef = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &usage); const void *keys[2] = { (void *)CFSTR(kIOHIDDeviceUsagePageKey), (void *)CFSTR(kIOHIDDeviceUsageKey) }; const void *vals[2] = { (void *)pageNumRef, (void *)usageNumRef }; if (pageNumRef && usageNumRef) { - retval = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + result = CFDictionaryCreate(kCFAllocatorDefault, keys, vals, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); } if (pageNumRef) { @@ -626,16 +626,16 @@ static CFDictionaryRef CreateHIDDeviceMatchDictionary(const UInt32 page, const U CFRelease(usageNumRef); } - if (!retval) { + if (!result) { *okay = 0; } - return retval; + return result; } static bool CreateHIDManager(void) { - bool retval = false; + bool result = false; int okay = 1; const void *vals[] = { (void *)CreateHIDDeviceMatchDictionary(kHIDPage_GenericDesktop, kHIDUsage_GD_Joystick, &okay), @@ -655,25 +655,25 @@ static bool CreateHIDManager(void) if (array) { hidman = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone); if (hidman != NULL) { - retval = ConfigHIDManager(array); + result = ConfigHIDManager(array); } CFRelease(array); } - return retval; + return result; } -static int DARWIN_JoystickInit(void) +static bool DARWIN_JoystickInit(void) { if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_IOKIT, true)) { - return 0; + return true; } if (!CreateHIDManager()) { return SDL_SetError("Joystick: Couldn't initialize HID Manager"); } - return 0; + return true; } static int DARWIN_JoystickGetCount(void) @@ -761,7 +761,7 @@ static SDL_JoystickID DARWIN_JoystickGetDeviceInstanceID(int device_index) return device ? device->instance_id : 0; } -static int DARWIN_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool DARWIN_JoystickOpen(SDL_Joystick *joystick, int device_index) { recDevice *device = GetDeviceForIndex(device_index); @@ -777,7 +777,7 @@ static int DARWIN_JoystickOpen(SDL_Joystick *joystick, int device_index) SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true); } - return 0; + return true; } /* @@ -835,7 +835,7 @@ static const char *FFStrError(unsigned int err) } } -static int DARWIN_JoystickInitRumble(recDevice *device, Sint16 magnitude) +static bool DARWIN_JoystickInitRumble(recDevice *device, Sint16 magnitude) { HRESULT result; @@ -860,7 +860,7 @@ static int DARWIN_JoystickInitRumble(recDevice *device, Sint16 magnitude) // Create the effect device->ffeffect = CreateRumbleEffectData(magnitude); if (!device->ffeffect) { - return -1; + return false; } result = FFDeviceCreateEffect(device->ffdevice, kFFEffectType_Sine_ID, @@ -868,10 +868,10 @@ static int DARWIN_JoystickInitRumble(recDevice *device, Sint16 magnitude) if (result != FF_OK) { return SDL_SetError("Haptic: Unable to create effect: %s", FFStrError(result)); } - return 0; + return true; } -static int DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { HRESULT result; recDevice *device = joystick->hwdata; @@ -897,8 +897,8 @@ static int DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_ru return SDL_SetError("Unable to update rumble effect: %s", FFStrError(result)); } } else { - if (DARWIN_JoystickInitRumble(device, magnitude) < 0) { - return -1; + if (!DARWIN_JoystickInitRumble(device, magnitude)) { + return false; } device->ff_initialized = true; } @@ -907,25 +907,25 @@ static int DARWIN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_ru if (result != FF_OK) { return SDL_SetError("Unable to run the rumble effect: %s", FFStrError(result)); } - return 0; + return true; } -static int DARWIN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool DARWIN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } -static int DARWIN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool DARWIN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int DARWIN_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool DARWIN_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int DARWIN_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool DARWIN_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/dummy/SDL_sysjoystick.c b/src/joystick/dummy/SDL_sysjoystick.c index e5c7ddf0ab..439c0db3bd 100644 --- a/src/joystick/dummy/SDL_sysjoystick.c +++ b/src/joystick/dummy/SDL_sysjoystick.c @@ -27,9 +27,9 @@ #include "../SDL_sysjoystick.h" #include "../SDL_joystick_c.h" -static int DUMMY_JoystickInit(void) +static bool DUMMY_JoystickInit(void) { - return 0; + return true; } static int DUMMY_JoystickGetCount(void) @@ -79,35 +79,35 @@ static SDL_GUID DUMMY_JoystickGetDeviceGUID(int device_index) static SDL_JoystickID DUMMY_JoystickGetDeviceInstanceID(int device_index) { - return -1; + return 0; } -static int DUMMY_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool DUMMY_JoystickOpen(SDL_Joystick *joystick, int device_index) { return SDL_SetError("Logic error: No joysticks available"); } -static int DUMMY_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool DUMMY_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } -static int DUMMY_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool DUMMY_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } -static int DUMMY_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool DUMMY_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int DUMMY_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool DUMMY_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int DUMMY_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool DUMMY_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/emscripten/SDL_sysjoystick.c b/src/joystick/emscripten/SDL_sysjoystick.c index e6bf9e7f87..a1e29aeafc 100644 --- a/src/joystick/emscripten/SDL_sysjoystick.c +++ b/src/joystick/emscripten/SDL_sysjoystick.c @@ -167,20 +167,18 @@ static void EMSCRIPTEN_JoystickQuit(void) emscripten_set_gamepaddisconnected_callback(NULL, 0, NULL); } -/* Function to scan the system for joysticks. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -static int EMSCRIPTEN_JoystickInit(void) +// Function to scan the system for joysticks. +static bool EMSCRIPTEN_JoystickInit(void) { - int retval, i, numjs; + int rc, i, numjs; EmscriptenGamepadEvent gamepadState; numjoysticks = 0; - retval = emscripten_sample_gamepad_data(); + rc = emscripten_sample_gamepad_data(); // Check if gamepad is supported by browser - if (retval == EMSCRIPTEN_RESULT_NOT_SUPPORTED) { + if (rc == EMSCRIPTEN_RESULT_NOT_SUPPORTED) { return SDL_SetError("Gamepads not supported"); } @@ -189,8 +187,8 @@ static int EMSCRIPTEN_JoystickInit(void) // handle already connected gamepads if (numjs > 0) { for (i = 0; i < numjs; i++) { - retval = emscripten_get_gamepad_status(i, &gamepadState); - if (retval == EMSCRIPTEN_RESULT_SUCCESS) { + rc = emscripten_get_gamepad_status(i, &gamepadState); + if (rc == EMSCRIPTEN_RESULT_SUCCESS) { Emscripten_JoyStickConnected(EMSCRIPTEN_EVENT_GAMEPADCONNECTED, &gamepadState, NULL); @@ -198,24 +196,24 @@ static int EMSCRIPTEN_JoystickInit(void) } } - retval = emscripten_set_gamepadconnected_callback(NULL, - 0, - Emscripten_JoyStickConnected); + rc = emscripten_set_gamepadconnected_callback(NULL, + 0, + Emscripten_JoyStickConnected); - if (retval != EMSCRIPTEN_RESULT_SUCCESS) { + if (rc != EMSCRIPTEN_RESULT_SUCCESS) { EMSCRIPTEN_JoystickQuit(); return SDL_SetError("Could not set gamepad connect callback"); } - retval = emscripten_set_gamepaddisconnected_callback(NULL, + rc = emscripten_set_gamepaddisconnected_callback(NULL, 0, Emscripten_JoyStickDisconnected); - if (retval != EMSCRIPTEN_RESULT_SUCCESS) { + if (rc != EMSCRIPTEN_RESULT_SUCCESS) { EMSCRIPTEN_JoystickQuit(); return SDL_SetError("Could not set gamepad disconnect callback"); } - return 0; + return true; } // Returns item matching given SDL device index. @@ -294,12 +292,7 @@ static SDL_JoystickID EMSCRIPTEN_JoystickGetDeviceInstanceID(int device_index) return JoystickByDeviceIndex(device_index)->device_instance; } -/* Function to open a joystick for use. - The joystick to open is specified by the device index. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -static int EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index) { SDL_joylist_item *item = JoystickByDeviceIndex(device_index); @@ -320,7 +313,7 @@ static int EMSCRIPTEN_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->nbuttons = item->nbuttons; joystick->naxes = item->naxes; - return 0; + return true; } /* Function to update the state of a joystick - called as a device poll. @@ -385,12 +378,12 @@ static SDL_GUID EMSCRIPTEN_JoystickGetDeviceGUID(int device_index) return SDL_CreateJoystickGUIDForName(name); } -static int EMSCRIPTEN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool EMSCRIPTEN_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } -static int EMSCRIPTEN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool EMSCRIPTEN_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -400,17 +393,17 @@ static bool EMSCRIPTEN_JoystickGetGamepadMapping(int device_index, SDL_GamepadMa return false; } -static int EMSCRIPTEN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool EMSCRIPTEN_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int EMSCRIPTEN_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool EMSCRIPTEN_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int EMSCRIPTEN_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool EMSCRIPTEN_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/gdk/SDL_gameinputjoystick.c b/src/joystick/gdk/SDL_gameinputjoystick.c index 4a7f9c559d..85a74577e6 100644 --- a/src/joystick/gdk/SDL_gameinputjoystick.c +++ b/src/joystick/gdk/SDL_gameinputjoystick.c @@ -75,7 +75,7 @@ static bool GAMEINPUT_InternalIsGamepad(const GameInputDeviceInfo *info) return false; } -static int GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice) +static bool GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice) { GAMEINPUT_InternalDevice **devicelist = NULL; GAMEINPUT_InternalDevice *elem = NULL; @@ -102,7 +102,7 @@ static int GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice) version = (info->firmwareVersion.major << 8) | info->firmwareVersion.minor; if (SDL_JoystickHandledByAnotherDriver(&SDL_GAMEINPUT_JoystickDriver, vendor, product, version, "")) { - return 0; + return true; } for (idx = 0; idx < g_GameInputList.count; ++idx) { @@ -110,19 +110,19 @@ static int GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice) if (elem && elem->device == pDevice) { // we're already added elem->isDeleteRequested = false; - return 0; + return true; } } elem = (GAMEINPUT_InternalDevice *)SDL_calloc(1, sizeof(*elem)); if (!elem) { - return -1; + return false; } devicelist = (GAMEINPUT_InternalDevice **)SDL_realloc(g_GameInputList.devices, sizeof(elem) * (g_GameInputList.count + 1LL)); if (!devicelist) { SDL_free(elem); - return -1; + return false; } // Generate a device path @@ -149,10 +149,10 @@ static int GAMEINPUT_InternalAddOrFind(IGameInputDevice *pDevice) g_GameInputList.devices = devicelist; g_GameInputList.devices[g_GameInputList.count++] = elem; - return 0; + return true; } -static int GAMEINPUT_InternalRemoveByIndex(int idx) +static bool GAMEINPUT_InternalRemoveByIndex(int idx) { GAMEINPUT_InternalDevice **devicelist = NULL; GAMEINPUT_InternalDevice *elem; @@ -184,7 +184,8 @@ static int GAMEINPUT_InternalRemoveByIndex(int idx) } // decrement the count and return - return g_GameInputList.count--; + --g_GameInputList.count; + return true; } static GAMEINPUT_InternalDevice *GAMEINPUT_InternalFindByIndex(int idx) @@ -230,18 +231,18 @@ static void CALLBACK GAMEINPUT_InternalJoystickDeviceCallback( static void GAMEINPUT_JoystickDetect(void); -static int GAMEINPUT_JoystickInit(void) +static bool GAMEINPUT_JoystickInit(void) { HRESULT hR; if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_GAMEINPUT, false)) { - return 0; + return true; } if (!g_hGameInputDLL) { g_hGameInputDLL = SDL_LoadObject("gameinput.dll"); if (!g_hGameInputDLL) { - return -1; + return false; } } @@ -249,7 +250,7 @@ static int GAMEINPUT_JoystickInit(void) typedef HRESULT (WINAPI *GameInputCreate_t)(IGameInput * *gameInput); GameInputCreate_t GameInputCreateFunc = (GameInputCreate_t)SDL_LoadFunction(g_hGameInputDLL, "GameInputCreate"); if (!GameInputCreateFunc) { - return -1; + return false; } hR = GameInputCreateFunc(&g_pGameInput); @@ -277,7 +278,7 @@ static int GAMEINPUT_JoystickInit(void) GAMEINPUT_JoystickDetect(); - return 0; + return true; } static int GAMEINPUT_JoystickGetCount(void) @@ -346,7 +347,6 @@ static const char *GAMEINPUT_JoystickGetDevicePath(int device_index) static int GAMEINPUT_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index) { - // Steamworks API is not available in GDK return -1; } @@ -430,19 +430,19 @@ static void CALLBACK GAMEINPUT_InternalSystemButtonCallback( #endif // IGameInput_RegisterSystemButtonCallback -static int GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) { GAMEINPUT_InternalDevice *elem = GAMEINPUT_InternalFindByIndex(device_index); const GameInputDeviceInfo *info = elem->info; GAMEINPUT_InternalJoystickHwdata *hwdata = NULL; if (!elem) { - return -1; + return false; } hwdata = (GAMEINPUT_InternalJoystickHwdata *)SDL_calloc(1, sizeof(*hwdata)); if (!hwdata) { - return -1; + return false; } hwdata->devref = elem; @@ -494,10 +494,10 @@ static int GAMEINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) } else { joystick->connection_state = SDL_JOYSTICK_CONNECTION_WIRED; } - return 0; + return true; } -static int GAMEINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool GAMEINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { // don't check for caps here, since SetRumbleState doesn't return any result - we don't need to check it GAMEINPUT_InternalJoystickHwdata *hwdata = joystick->hwdata; @@ -505,10 +505,10 @@ static int GAMEINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency params->lowFrequency = (float)low_frequency_rumble / (float)SDL_MAX_UINT16; params->highFrequency = (float)high_frequency_rumble / (float)SDL_MAX_UINT16; IGameInputDevice_SetRumbleState(hwdata->devref->device, params); - return 0; + return true; } -static int GAMEINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool GAMEINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { // don't check for caps here, since SetRumbleState doesn't return any result - we don't need to check it GAMEINPUT_InternalJoystickHwdata *hwdata = joystick->hwdata; @@ -516,23 +516,23 @@ static int GAMEINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ params->leftTrigger = (float)left_rumble / (float)SDL_MAX_UINT16; params->rightTrigger = (float)right_rumble / (float)SDL_MAX_UINT16; IGameInputDevice_SetRumbleState(hwdata->devref->device, params); - return 0; + return true; } -static int GAMEINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool GAMEINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int GAMEINPUT_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool GAMEINPUT_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int GAMEINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool GAMEINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { joystick->hwdata->report_sensors = enabled; - return 0; + return true; } static void GAMEINPUT_JoystickUpdate(SDL_Joystick *joystick) diff --git a/src/joystick/haiku/SDL_haikujoystick.cc b/src/joystick/haiku/SDL_haikujoystick.cc index 0ba9b3201a..2763c45745 100644 --- a/src/joystick/haiku/SDL_haikujoystick.cc +++ b/src/joystick/haiku/SDL_haikujoystick.cc @@ -51,11 +51,7 @@ extern "C" static int numjoysticks = 0; -/* Function to scan the system for joysticks. - * Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ - static int HAIKU_JoystickInit(void) + static bool HAIKU_JoystickInit(void) { BJoystick joystick; int i; @@ -81,7 +77,7 @@ extern "C" } } } - return (numjoysticks); + return true; } static int HAIKU_JoystickGetCount(void) @@ -123,7 +119,6 @@ extern "C" { } -// Function to perform the mapping from device index to the instance id for this index static SDL_JoystickID HAIKU_JoystickGetDeviceInstanceID(int device_index) { return device_index + 1; @@ -131,19 +126,14 @@ extern "C" static void HAIKU_JoystickClose(SDL_Joystick *joystick); -/* Function to open a joystick for use. - The joystick to open is specified by the device index. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ - static int HAIKU_JoystickOpen(SDL_Joystick *joystick, int device_index) + static bool HAIKU_JoystickOpen(SDL_Joystick *joystick, int device_index) { BJoystick *stick; // Create the joystick data structure joystick->hwdata = (struct joystick_hwdata *) SDL_calloc(1, sizeof(*joystick->hwdata)); if (joystick->hwdata == NULL) { - return -1; + return false; } stick = new BJoystick; joystick->hwdata->stick = stick; @@ -166,11 +156,11 @@ extern "C" joystick->hwdata->new_hats = (uint8 *) SDL_calloc(joystick->nhats, sizeof(uint8)); if (!joystick->hwdata->new_hats || !joystick->hwdata->new_axes) { HAIKU_JoystickClose(joystick); - return -1; + return false; } // We're done! - return 0; + return true; } /* Function to update the state of a joystick - called as a device poll. @@ -262,35 +252,34 @@ extern "C" return SDL_CreateJoystickGUIDForName(name); } - static int HAIKU_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) + static bool HAIKU_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } - static int HAIKU_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) + static bool HAIKU_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } - static bool - HAIKU_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out) + static bool HAIKU_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out) { return false; } - static int HAIKU_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) + static bool HAIKU_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } - static int HAIKU_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) + static bool HAIKU_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } - static int HAIKU_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) + static bool HAIKU_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/hidapi/SDL_hidapi_combined.c b/src/joystick/hidapi/SDL_hidapi_combined.c index 36de70d4a5..af8ecce176 100644 --- a/src/joystick/hidapi/SDL_hidapi_combined.c +++ b/src/joystick/hidapi/SDL_hidapi_combined.c @@ -108,29 +108,29 @@ static bool HIDAPI_DriverCombined_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo return true; } -static int HIDAPI_DriverCombined_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverCombined_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { int i; - int result = -1; + bool result = false; for (i = 0; i < device->num_children; ++i) { SDL_HIDAPI_Device *child = device->children[i]; if (child->driver->RumbleJoystick(child, joystick, low_frequency_rumble, high_frequency_rumble) == 0) { - result = 0; + result = true; } } return result; } -static int HIDAPI_DriverCombined_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverCombined_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { int i; - int result = -1; + bool result = false; for (i = 0; i < device->num_children; ++i) { SDL_HIDAPI_Device *child = device->children[i]; if (child->driver->RumbleJoystickTriggers(child, joystick, left_rumble, right_rumble) == 0) { - result = 0; + result = true; } } return result; @@ -148,34 +148,34 @@ static Uint32 HIDAPI_DriverCombined_GetJoystickCapabilities(SDL_HIDAPI_Device *d return caps; } -static int HIDAPI_DriverCombined_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverCombined_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { int i; - int result = -1; + bool result = false; for (i = 0; i < device->num_children; ++i) { SDL_HIDAPI_Device *child = device->children[i]; if (child->driver->SetJoystickLED(child, joystick, red, green, blue) == 0) { - result = 0; + result = true; } } return result; } -static int HIDAPI_DriverCombined_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverCombined_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverCombined_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverCombined_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { int i; - int result = -1; + bool result = false; for (i = 0; i < device->num_children; ++i) { SDL_HIDAPI_Device *child = device->children[i]; if (child->driver->SetJoystickSensorsEnabled(child, joystick, enabled) == 0) { - result = 0; + result = true; } } return result; diff --git a/src/joystick/hidapi/SDL_hidapi_gamecube.c b/src/joystick/hidapi/SDL_hidapi_gamecube.c index 270784cb6a..0932001c44 100644 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c +++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c @@ -403,7 +403,7 @@ static bool HIDAPI_DriverGameCube_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo return false; // Should never get here! } -static int HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverGameCube_Context *ctx = (SDL_DriverGameCube_Context *)device->context; Uint8 i, val; @@ -437,7 +437,7 @@ static int HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_J ctx->rumble[i + 1] = val; ctx->rumbleUpdate = true; } - return 0; + return true; } } @@ -445,7 +445,7 @@ static int HIDAPI_DriverGameCube_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_J return SDL_SetError("Couldn't find joystick"); } -static int HIDAPI_DriverGameCube_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverGameCube_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -473,17 +473,17 @@ static Uint32 HIDAPI_DriverGameCube_GetJoystickCapabilities(SDL_HIDAPI_Device *d return result; } -static int HIDAPI_DriverGameCube_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverGameCube_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverGameCube_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverGameCube_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverGameCube_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverGameCube_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/hidapi/SDL_hidapi_luna.c b/src/joystick/hidapi/SDL_hidapi_luna.c index 24147ea412..617b8bd840 100644 --- a/src/joystick/hidapi/SDL_hidapi_luna.c +++ b/src/joystick/hidapi/SDL_hidapi_luna.c @@ -107,7 +107,7 @@ static bool HIDAPI_DriverLuna_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joysti return true; } -static int HIDAPI_DriverLuna_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverLuna_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { #ifdef ENABLE_LUNA_BLUETOOTH_RUMBLE if (device->product_id == BLUETOOTH_PRODUCT_LUNA_CONTROLLER) { @@ -122,7 +122,7 @@ static int HIDAPI_DriverLuna_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joyst return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } #endif // ENABLE_LUNA_BLUETOOTH_RUMBLE @@ -130,7 +130,7 @@ static int HIDAPI_DriverLuna_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joyst return SDL_Unsupported(); } -static int HIDAPI_DriverLuna_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverLuna_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -148,17 +148,17 @@ static Uint32 HIDAPI_DriverLuna_GetJoystickCapabilities(SDL_HIDAPI_Device *devic return result; } -static int HIDAPI_DriverLuna_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverLuna_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverLuna_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverLuna_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverLuna_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverLuna_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -383,7 +383,7 @@ static bool HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverLuna_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_ps3.c b/src/joystick/hidapi/SDL_hidapi_ps3.c index dab821e75b..c27550798d 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps3.c +++ b/src/joystick/hidapi/SDL_hidapi_ps3.c @@ -89,7 +89,7 @@ typedef struct Uint8 last_state[USB_PACKET_LENGTH]; } SDL_DriverPS3_Context; -static int HIDAPI_DriverPS3_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size); +static bool HIDAPI_DriverPS3_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size); static void HIDAPI_DriverPS3_RegisterHints(SDL_HintCallback callback, void *userdata) { @@ -226,7 +226,7 @@ static int HIDAPI_DriverPS3_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_ return -1; } -static int HIDAPI_DriverPS3_UpdateEffects(SDL_HIDAPI_Device *device) +static bool HIDAPI_DriverPS3_UpdateEffects(SDL_HIDAPI_Device *device) { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; @@ -290,7 +290,7 @@ static bool HIDAPI_DriverPS3_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic return true; } -static int HIDAPI_DriverPS3_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverPS3_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; @@ -300,7 +300,7 @@ static int HIDAPI_DriverPS3_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joysti return HIDAPI_DriverPS3_UpdateEffects(device); } -static int HIDAPI_DriverPS3_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverPS3_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -310,12 +310,12 @@ static Uint32 HIDAPI_DriverPS3_GetJoystickCapabilities(SDL_HIDAPI_Device *device return SDL_JOYSTICK_CAP_RUMBLE; } -static int HIDAPI_DriverPS3_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverPS3_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverPS3_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) +static bool HIDAPI_DriverPS3_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) { Uint8 data[49]; int report_size, offset; @@ -330,16 +330,16 @@ static int HIDAPI_DriverPS3_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Jo if (SDL_HIDAPI_SendRumble(device, data, report_size) != report_size) { return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } -static int HIDAPI_DriverPS3_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverPS3_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; ctx->report_sensors = enabled; - return 0; + return true; } static float HIDAPI_DriverPS3_ScaleAccel(Sint16 value) @@ -576,7 +576,7 @@ static bool HIDAPI_DriverPS3_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverPS3_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) @@ -708,12 +708,12 @@ static bool HIDAPI_DriverPS3ThirdParty_OpenJoystick(SDL_HIDAPI_Device *device, S return true; } -static int HIDAPI_DriverPS3ThirdParty_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverPS3ThirdParty_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } -static int HIDAPI_DriverPS3ThirdParty_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverPS3ThirdParty_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -723,17 +723,17 @@ static Uint32 HIDAPI_DriverPS3ThirdParty_GetJoystickCapabilities(SDL_HIDAPI_Devi return 0; } -static int HIDAPI_DriverPS3ThirdParty_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverPS3ThirdParty_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverPS3ThirdParty_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) +static bool HIDAPI_DriverPS3ThirdParty_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverPS3ThirdParty_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverPS3ThirdParty_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -1013,7 +1013,7 @@ static bool HIDAPI_DriverPS3ThirdParty_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverPS3ThirdParty_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) @@ -1049,8 +1049,8 @@ SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3ThirdParty = { HIDAPI_DriverPS3ThirdParty_FreeDevice, }; -static int HIDAPI_DriverPS3_UpdateRumbleSonySixaxis(SDL_HIDAPI_Device *device); -static int HIDAPI_DriverPS3_UpdateLEDsSonySixaxis(SDL_HIDAPI_Device *device); +static bool HIDAPI_DriverPS3_UpdateRumbleSonySixaxis(SDL_HIDAPI_Device *device); +static bool HIDAPI_DriverPS3_UpdateLEDsSonySixaxis(SDL_HIDAPI_Device *device); static void HIDAPI_DriverPS3SonySixaxis_RegisterHints(SDL_HintCallback callback, void *userdata) { @@ -1166,7 +1166,7 @@ static bool HIDAPI_DriverPS3SonySixaxis_OpenJoystick(SDL_HIDAPI_Device *device, return true; } -static int HIDAPI_DriverPS3SonySixaxis_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverPS3SonySixaxis_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; @@ -1176,7 +1176,7 @@ static int HIDAPI_DriverPS3SonySixaxis_RumbleJoystick(SDL_HIDAPI_Device *device, return HIDAPI_DriverPS3_UpdateRumbleSonySixaxis(device); } -static int HIDAPI_DriverPS3SonySixaxis_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverPS3SonySixaxis_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -1186,12 +1186,12 @@ static Uint32 HIDAPI_DriverPS3SonySixaxis_GetJoystickCapabilities(SDL_HIDAPI_Dev return 0; } -static int HIDAPI_DriverPS3SonySixaxis_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverPS3SonySixaxis_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverPS3SonySixaxis_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) +static bool HIDAPI_DriverPS3SonySixaxis_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) { Uint8 data[49]; int report_size; @@ -1207,16 +1207,16 @@ static int HIDAPI_DriverPS3SonySixaxis_SendJoystickEffect(SDL_HIDAPI_Device *dev if (SDL_HIDAPI_SendRumble(device, data, report_size) != report_size) { return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } -static int HIDAPI_DriverPS3SonySixaxis_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverPS3SonySixaxis_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; ctx->report_sensors = enabled; - return 0; + return true; } static void HIDAPI_DriverPS3SonySixaxis_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverPS3_Context *ctx, Uint8 *data, int size) @@ -1366,7 +1366,7 @@ static bool HIDAPI_DriverPS3SonySixaxis_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverPS3SonySixaxis_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) @@ -1380,7 +1380,7 @@ static void HIDAPI_DriverPS3SonySixaxis_FreeDevice(SDL_HIDAPI_Device *device) { } -static int HIDAPI_DriverPS3_UpdateRumbleSonySixaxis(SDL_HIDAPI_Device *device) +static bool HIDAPI_DriverPS3_UpdateRumbleSonySixaxis(SDL_HIDAPI_Device *device) { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; @@ -1400,7 +1400,7 @@ static int HIDAPI_DriverPS3_UpdateRumbleSonySixaxis(SDL_HIDAPI_Device *device) return HIDAPI_DriverPS3SonySixaxis_SendJoystickEffect(device, ctx->joystick, effects, sizeof(effects)); } -static int HIDAPI_DriverPS3_UpdateLEDsSonySixaxis(SDL_HIDAPI_Device *device) +static bool HIDAPI_DriverPS3_UpdateLEDsSonySixaxis(SDL_HIDAPI_Device *device) { SDL_DriverPS3_Context *ctx = (SDL_DriverPS3_Context *)device->context; diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index ef4a905123..2ccd667b9a 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -182,7 +182,7 @@ typedef struct PS4StatePacket_t last_state; } SDL_DriverPS4_Context; -static int HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, bool application_usage); +static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, bool application_usage); static void HIDAPI_DriverPS4_RegisterHints(SDL_HintCallback callback, void *userdata) { @@ -655,7 +655,7 @@ static float HIDAPI_DriverPS4_ApplyCalibrationData(SDL_DriverPS4_Context *ctx, i return ((float)value - calibration->bias) * calibration->scale; } -static int HIDAPI_DriverPS4_UpdateEffects(SDL_DriverPS4_Context *ctx, bool application_usage) +static bool HIDAPI_DriverPS4_UpdateEffects(SDL_DriverPS4_Context *ctx, bool application_usage) { DS4EffectsState_t effects; @@ -692,7 +692,7 @@ static void HIDAPI_DriverPS4_TickleBluetooth(SDL_HIDAPI_Device *device) data[0] = k_EPS4ReportIdBluetoothEffects; data[1] = 0xC0; // Magic value HID + CRC - if (SDL_HIDAPI_LockRumble() == 0) { + if (SDL_HIDAPI_LockRumble()) { SDL_HIDAPI_SendRumbleAndUnlock(device, data, sizeof(data)); } } else { @@ -873,7 +873,7 @@ static bool HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic return true; } -static int HIDAPI_DriverPS4_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverPS4_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context; @@ -887,7 +887,7 @@ static int HIDAPI_DriverPS4_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joysti return HIDAPI_DriverPS4_UpdateEffects(ctx, true); } -static int HIDAPI_DriverPS4_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverPS4_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -909,7 +909,7 @@ static Uint32 HIDAPI_DriverPS4_GetJoystickCapabilities(SDL_HIDAPI_Device *device return result; } -static int HIDAPI_DriverPS4_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverPS4_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context; @@ -925,7 +925,7 @@ static int HIDAPI_DriverPS4_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joysti return HIDAPI_DriverPS4_UpdateEffects(ctx, true); } -static int HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, bool application_usage) +static bool HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ctx, const void *effect, int size, bool application_usage) { Uint8 data[78]; int report_size, offset; @@ -977,17 +977,17 @@ static int HIDAPI_DriverPS4_InternalSendJoystickEffect(SDL_DriverPS4_Context *ct if (SDL_HIDAPI_SendRumble(ctx->device, data, report_size) != report_size) { return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } -static int HIDAPI_DriverPS4_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) +static bool HIDAPI_DriverPS4_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) { SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context; return HIDAPI_DriverPS4_InternalSendJoystickEffect(ctx, effect, size, true); } -static int HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { SDL_DriverPS4_Context *ctx = (SDL_DriverPS4_Context *)device->context; @@ -1002,7 +1002,7 @@ static int HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, } ctx->report_sensors = enabled; - return 0; + return true; } static void HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet, int size) @@ -1343,7 +1343,7 @@ static bool HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverPS4_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c index de1e543089..9cb20e9c10 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps5.c +++ b/src/joystick/hidapi/SDL_hidapi_ps5.c @@ -272,7 +272,7 @@ typedef struct } last_state; } SDL_DriverPS5_Context; -static int HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *ctx, const void *effect, int size, bool application_usage); +static bool HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *ctx, const void *effect, int size, bool application_usage); static void HIDAPI_DriverPS5_RegisterHints(SDL_HintCallback callback, void *userdata) { @@ -669,7 +669,7 @@ static float HIDAPI_DriverPS5_ApplyCalibrationData(SDL_DriverPS5_Context *ctx, i return result; } -static int HIDAPI_DriverPS5_UpdateEffects(SDL_DriverPS5_Context *ctx, int effect_mask, bool application_usage) +static bool HIDAPI_DriverPS5_UpdateEffects(SDL_DriverPS5_Context *ctx, int effect_mask, bool application_usage) { DS5EffectsState_t effects; @@ -678,7 +678,7 @@ static int HIDAPI_DriverPS5_UpdateEffects(SDL_DriverPS5_Context *ctx, int effect (effect_mask & (k_EDS5EffectLED | k_EDS5EffectPadLights)) != 0) { if (ctx->led_reset_state != k_EDS5LEDResetStateComplete) { ctx->led_reset_state = k_EDS5LEDResetStatePending; - return 0; + return true; } } @@ -790,7 +790,7 @@ static void HIDAPI_DriverPS5_TickleBluetooth(SDL_HIDAPI_Device *device) data[0] = k_EPS5ReportIdBluetoothEffects; data[1] = 0x02; // Magic value - if (SDL_HIDAPI_LockRumble() == 0) { + if (SDL_HIDAPI_LockRumble()) { SDL_HIDAPI_SendRumbleAndUnlock(device, data, sizeof(data)); } } else { @@ -970,7 +970,7 @@ static bool HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic return true; } -static int HIDAPI_DriverPS5_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverPS5_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context; @@ -988,7 +988,7 @@ static int HIDAPI_DriverPS5_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joysti return HIDAPI_DriverPS5_UpdateEffects(ctx, k_EDS5EffectRumble, true); } -static int HIDAPI_DriverPS5_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverPS5_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -1013,7 +1013,7 @@ static Uint32 HIDAPI_DriverPS5_GetJoystickCapabilities(SDL_HIDAPI_Device *device return result; } -static int HIDAPI_DriverPS5_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverPS5_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context; @@ -1029,7 +1029,7 @@ static int HIDAPI_DriverPS5_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joysti return HIDAPI_DriverPS5_UpdateEffects(ctx, k_EDS5EffectLED, true); } -static int HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *ctx, const void *effect, int size, bool application_usage) +static bool HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *ctx, const void *effect, int size, bool application_usage) { Uint8 data[78]; int report_size, offset; @@ -1079,8 +1079,8 @@ static int HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *ct SDL_memcpy(&data[report_size - sizeof(unCRC)], &unCRC, sizeof(unCRC)); } - if (SDL_HIDAPI_LockRumble() < 0) { - return -1; + if (!SDL_HIDAPI_LockRumble()) { + return false; } // See if we can update an existing pending request @@ -1093,25 +1093,25 @@ static int HIDAPI_DriverPS5_InternalSendJoystickEffect(SDL_DriverPS5_Context *ct // We're simply updating the data for this request SDL_memcpy(pending_data, data, report_size); SDL_HIDAPI_UnlockRumble(); - return 0; + return true; } } if (SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, report_size) != report_size) { - return -1; + return false; } - return 0; + return true; } -static int HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) +static bool HIDAPI_DriverPS5_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *effect, int size) { SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context; return HIDAPI_DriverPS5_InternalSendJoystickEffect(ctx, effect, size, true); } -static int HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context; @@ -1126,7 +1126,7 @@ static int HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, } ctx->report_sensors = enabled; - return 0; + return true; } static void HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet, Uint64 timestamp) @@ -1582,7 +1582,7 @@ static bool HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_rumble.c b/src/joystick/hidapi/SDL_hidapi_rumble.c index 38b34adbec..865d714068 100644 --- a/src/joystick/hidapi/SDL_hidapi_rumble.c +++ b/src/joystick/hidapi/SDL_hidapi_rumble.c @@ -141,41 +141,41 @@ static void SDL_HIDAPI_StopRumbleThread(SDL_HIDAPI_RumbleContext *ctx) SDL_AtomicSet(&ctx->initialized, false); } -static int SDL_HIDAPI_StartRumbleThread(SDL_HIDAPI_RumbleContext *ctx) +static bool SDL_HIDAPI_StartRumbleThread(SDL_HIDAPI_RumbleContext *ctx) { SDL_HIDAPI_rumble_lock = SDL_CreateMutex(); if (!SDL_HIDAPI_rumble_lock) { SDL_HIDAPI_StopRumbleThread(ctx); - return -1; + return false; } ctx->request_sem = SDL_CreateSemaphore(0); if (!ctx->request_sem) { SDL_HIDAPI_StopRumbleThread(ctx); - return -1; + return false; } SDL_AtomicSet(&ctx->running, true); ctx->thread = SDL_CreateThread(SDL_HIDAPI_RumbleThread, "HIDAPI Rumble", ctx); if (!ctx->thread) { SDL_HIDAPI_StopRumbleThread(ctx); - return -1; + return false; } - return 0; + return true; } -int SDL_HIDAPI_LockRumble(void) +bool SDL_HIDAPI_LockRumble(void) { SDL_HIDAPI_RumbleContext *ctx = &rumble_context; if (SDL_AtomicCompareAndSwap(&ctx->initialized, false, true)) { - if (SDL_HIDAPI_StartRumbleThread(ctx) < 0) { - return -1; + if (!SDL_HIDAPI_StartRumbleThread(ctx)) { + return false; } } SDL_LockMutex(SDL_HIDAPI_rumble_lock); - return 0; + return true; } bool SDL_HIDAPI_GetPendingRumbleLocked(SDL_HIDAPI_Device *device, Uint8 **data, int **size, int *maximum_size) @@ -210,7 +210,8 @@ int SDL_HIDAPI_SendRumbleWithCallbackAndUnlock(SDL_HIDAPI_Device *device, const if (size > sizeof(request->data)) { SDL_HIDAPI_UnlockRumble(); - return SDL_SetError("Couldn't send rumble, size %d is greater than %d", size, (int)sizeof(request->data)); + SDL_SetError("Couldn't send rumble, size %d is greater than %d", size, (int)sizeof(request->data)); + return -1; } request = (SDL_HIDAPI_RumbleRequest *)SDL_calloc(1, sizeof(*request)); @@ -253,10 +254,11 @@ int SDL_HIDAPI_SendRumble(SDL_HIDAPI_Device *device, const Uint8 *data, int size int maximum_size; if (size <= 0) { - return SDL_SetError("Tried to send rumble with invalid size"); + SDL_SetError("Tried to send rumble with invalid size"); + return -1; } - if (SDL_HIDAPI_LockRumble() < 0) { + if (!SDL_HIDAPI_LockRumble()) { return -1; } diff --git a/src/joystick/hidapi/SDL_hidapi_rumble.h b/src/joystick/hidapi/SDL_hidapi_rumble.h index 7bbfcdfe92..aa0646e462 100644 --- a/src/joystick/hidapi/SDL_hidapi_rumble.h +++ b/src/joystick/hidapi/SDL_hidapi_rumble.h @@ -28,7 +28,7 @@ #ifdef SDL_THREAD_SAFETY_ANALYSIS extern SDL_Mutex *SDL_HIDAPI_rumble_lock; #endif -int SDL_HIDAPI_LockRumble(void) SDL_TRY_ACQUIRE(0, SDL_HIDAPI_rumble_lock); +bool SDL_HIDAPI_LockRumble(void) SDL_TRY_ACQUIRE(0, SDL_HIDAPI_rumble_lock); bool SDL_HIDAPI_GetPendingRumbleLocked(SDL_HIDAPI_Device *device, Uint8 **data, int **size, int *maximum_size); int SDL_HIDAPI_SendRumbleAndUnlock(SDL_HIDAPI_Device *device, const Uint8 *data, int size) SDL_RELEASE(SDL_HIDAPI_rumble_lock); typedef void (*SDL_HIDAPI_RumbleSentCallback)(void *userdata); diff --git a/src/joystick/hidapi/SDL_hidapi_shield.c b/src/joystick/hidapi/SDL_hidapi_shield.c index 576d9578ef..0af245d9a0 100644 --- a/src/joystick/hidapi/SDL_hidapi_shield.c +++ b/src/joystick/hidapi/SDL_hidapi_shield.c @@ -136,7 +136,7 @@ static void HIDAPI_DriverShield_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, { } -static int HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, const void *data, int size) +static bool HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, const void *data, int size) { SDL_DriverShield_Context *ctx = (SDL_DriverShield_Context *)device->context; ShieldCommandReport_t cmd_pkt; @@ -145,8 +145,8 @@ static int HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, return SDL_SetError("Command data exceeds HID report size"); } - if (SDL_HIDAPI_LockRumble() < 0) { - return -1; + if (!SDL_HIDAPI_LockRumble()) { + return false; } cmd_pkt.report_id = k_ShieldReportIdCommandRequest; @@ -165,7 +165,7 @@ static int HIDAPI_DriverShield_SendCommand(SDL_HIDAPI_Device *device, Uint8 cmd, return SDL_SetError("Couldn't send command packet"); } - return 0; + return true; } static bool HIDAPI_DriverShield_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) @@ -202,13 +202,13 @@ static bool HIDAPI_DriverShield_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys return true; } -static int HIDAPI_DriverShield_SendNextRumble(SDL_HIDAPI_Device *device) +static bool HIDAPI_DriverShield_SendNextRumble(SDL_HIDAPI_Device *device) { SDL_DriverShield_Context *ctx = (SDL_DriverShield_Context *)device->context; Uint8 rumble_data[3]; if (!ctx->rumble_update_pending) { - return 0; + return true; } rumble_data[0] = 0x01; // enable @@ -221,7 +221,7 @@ static int HIDAPI_DriverShield_SendNextRumble(SDL_HIDAPI_Device *device) return HIDAPI_DriverShield_SendCommand(device, CMD_RUMBLE, rumble_data, sizeof(rumble_data)); } -static int HIDAPI_DriverShield_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverShield_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { if (device->product_id == USB_PRODUCT_NVIDIA_SHIELD_CONTROLLER_V103) { Uint8 rumble_packet[] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -232,7 +232,7 @@ static int HIDAPI_DriverShield_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joy if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) { return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } else { SDL_DriverShield_Context *ctx = (SDL_DriverShield_Context *)device->context; @@ -244,14 +244,14 @@ static int HIDAPI_DriverShield_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joy if (ctx->rumble_report_pending) { // We will service this after the hardware acknowledges the previous request - return 0; + return true; } return HIDAPI_DriverShield_SendNextRumble(device); } } -static int HIDAPI_DriverShield_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverShield_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -261,12 +261,12 @@ static Uint32 HIDAPI_DriverShield_GetJoystickCapabilities(SDL_HIDAPI_Device *dev return SDL_JOYSTICK_CAP_RUMBLE; } -static int HIDAPI_DriverShield_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverShield_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverShield_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverShield_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { const Uint8 *data_bytes = (const Uint8 *)data; @@ -281,7 +281,7 @@ static int HIDAPI_DriverShield_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL } } -static int HIDAPI_DriverShield_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverShield_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -538,7 +538,7 @@ static bool HIDAPI_DriverShield_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverShield_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_stadia.c b/src/joystick/hidapi/SDL_hidapi_stadia.c index ccc9f1a9ab..9df0985022 100644 --- a/src/joystick/hidapi/SDL_hidapi_stadia.c +++ b/src/joystick/hidapi/SDL_hidapi_stadia.c @@ -113,7 +113,7 @@ static bool HIDAPI_DriverStadia_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys return true; } -static int HIDAPI_DriverStadia_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverStadia_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverStadia_Context *ctx = (SDL_DriverStadia_Context *)device->context; @@ -129,13 +129,13 @@ static int HIDAPI_DriverStadia_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joy if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) { return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } else { return SDL_Unsupported(); } } -static int HIDAPI_DriverStadia_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverStadia_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -151,17 +151,17 @@ static Uint32 HIDAPI_DriverStadia_GetJoystickCapabilities(SDL_HIDAPI_Device *dev return caps; } -static int HIDAPI_DriverStadia_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverStadia_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverStadia_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverStadia_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverStadia_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverStadia_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -286,7 +286,7 @@ static bool HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverStadia_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_steam.c b/src/joystick/hidapi/SDL_hidapi_steam.c index 2be41e9baa..c6a3d67046 100644 --- a/src/joystick/hidapi/SDL_hidapi_steam.c +++ b/src/joystick/hidapi/SDL_hidapi_steam.c @@ -1031,13 +1031,13 @@ static bool HIDAPI_DriverSteam_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joyst return true; } -static int HIDAPI_DriverSteam_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverSteam_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { // You should use the full Steam Input API for rumble support return SDL_Unsupported(); } -static int HIDAPI_DriverSteam_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverSteam_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -1048,18 +1048,18 @@ static Uint32 HIDAPI_DriverSteam_GetJoystickCapabilities(SDL_HIDAPI_Device *devi return 0; } -static int HIDAPI_DriverSteam_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverSteam_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { // You should use the full Steam Input API for LED support return SDL_Unsupported(); } -static int HIDAPI_DriverSteam_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverSteam_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverSteam_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverSteam_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { SDL_DriverSteam_Context *ctx = (SDL_DriverSteam_Context *)device->context; unsigned char buf[65]; @@ -1079,7 +1079,7 @@ static int HIDAPI_DriverSteam_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_J ctx->report_sensors = enabled; - return 0; + return true; } static bool HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device) diff --git a/src/joystick/hidapi/SDL_hidapi_steamdeck.c b/src/joystick/hidapi/SDL_hidapi_steamdeck.c index 7992383c1c..3c6d58fb1d 100644 --- a/src/joystick/hidapi/SDL_hidapi_steamdeck.c +++ b/src/joystick/hidapi/SDL_hidapi_steamdeck.c @@ -369,7 +369,7 @@ static bool HIDAPI_DriverSteamDeck_OpenJoystick(SDL_HIDAPI_Device *device, SDL_J return true; } -static int HIDAPI_DriverSteamDeck_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverSteamDeck_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { int rc; Uint8 buffer[HID_FEATURE_REPORT_BYTES + 1] = { 0 }; @@ -385,11 +385,11 @@ static int HIDAPI_DriverSteamDeck_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_ rc = SDL_hid_send_feature_report(device->dev, buffer, sizeof(buffer)); if (rc != sizeof(buffer)) - return -1; - return 0; + return false; + return true; } -static int HIDAPI_DriverSteamDeck_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverSteamDeck_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -399,20 +399,20 @@ static Uint32 HIDAPI_DriverSteamDeck_GetJoystickCapabilities(SDL_HIDAPI_Device * return SDL_JOYSTICK_CAP_RUMBLE; } -static int HIDAPI_DriverSteamDeck_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverSteamDeck_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverSteamDeck_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverSteamDeck_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverSteamDeck_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverSteamDeck_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { // On steam deck, sensors are enabled by default. Nothing to do here. - return 0; + return true; } static void HIDAPI_DriverSteamDeck_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index 99d76ac5e2..79a8797850 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -367,7 +367,7 @@ static int WriteOutput(SDL_DriverSwitch_Context *ctx, const Uint8 *data, int siz return SDL_hid_write(ctx->device->dev, data, size); #else // Use the rumble thread for general asynchronous writes - if (SDL_HIDAPI_LockRumble() != 0) { + if (!SDL_HIDAPI_LockRumble()) { return -1; } return SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size); @@ -1512,7 +1512,7 @@ static bool HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys return true; } -static int HIDAPI_DriverSwitch_ActuallyRumbleJoystick(SDL_DriverSwitch_Context *ctx, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverSwitch_ActuallyRumbleJoystick(SDL_DriverSwitch_Context *ctx, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { /* Experimentally determined rumble values. These will only matter on some controllers as tested ones * seem to disregard these and just use any non-zero rumble values as a binary flag for constant rumble @@ -1538,13 +1538,13 @@ static int HIDAPI_DriverSwitch_ActuallyRumbleJoystick(SDL_DriverSwitch_Context * if (!WriteRumble(ctx)) { return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } -static int HIDAPI_DriverSwitch_SendPendingRumble(SDL_DriverSwitch_Context *ctx) +static bool HIDAPI_DriverSwitch_SendPendingRumble(SDL_DriverSwitch_Context *ctx) { if (SDL_GetTicks() < (ctx->m_ulRumbleSent + RUMBLE_WRITE_FREQUENCY_MS)) { - return 0; + return true; } if (ctx->m_bRumblePending) { @@ -1569,10 +1569,10 @@ static int HIDAPI_DriverSwitch_SendPendingRumble(SDL_DriverSwitch_Context *ctx) return HIDAPI_DriverSwitch_ActuallyRumbleJoystick(ctx, 0, 0); } - return 0; + return true; } -static int HIDAPI_DriverSwitch_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverSwitch_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context; @@ -1591,8 +1591,8 @@ static int HIDAPI_DriverSwitch_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joy } if (ctx->m_bRumblePending) { - if (HIDAPI_DriverSwitch_SendPendingRumble(ctx) < 0) { - return -1; + if (!HIDAPI_DriverSwitch_SendPendingRumble(ctx)) { + return false; } } @@ -1610,7 +1610,7 @@ static int HIDAPI_DriverSwitch_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joy // When rumble is complete, turn it off ctx->m_bRumbleZeroPending = true; } - return 0; + return true; } #ifdef DEBUG_RUMBLE @@ -1620,7 +1620,7 @@ static int HIDAPI_DriverSwitch_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joy return HIDAPI_DriverSwitch_ActuallyRumbleJoystick(ctx, low_frequency_rumble, high_frequency_rumble); } -static int HIDAPI_DriverSwitch_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverSwitch_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -1644,12 +1644,12 @@ static Uint32 HIDAPI_DriverSwitch_GetJoystickCapabilities(SDL_HIDAPI_Device *dev return result; } -static int HIDAPI_DriverSwitch_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverSwitch_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverSwitch_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverSwitch_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context; @@ -1663,35 +1663,35 @@ static int HIDAPI_DriverSwitch_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL SDL_copyp(&ctx->m_RumblePacket.rumbleData[0], &packet->rumbleData[0]); SDL_copyp(&ctx->m_RumblePacket.rumbleData[1], &packet->rumbleData[1]); if (!WriteRumble(ctx)) { - return -1; + return false; } // This overwrites any internal rumble ctx->m_bRumblePending = false; ctx->m_bRumbleZeroPending = false; - return 0; + return true; } else if (size >= 2 && size <= 256) { const Uint8 *payload = (const Uint8 *)data; ESwitchSubcommandIDs cmd = (ESwitchSubcommandIDs)payload[0]; if (cmd == k_eSwitchSubcommandIDs_SetInputReportMode && !device->is_bluetooth) { // Going into simple mode over USB disables input reports, so don't do that - return 0; + return true; } if (cmd == k_eSwitchSubcommandIDs_SetHomeLight && !HasHomeLED(ctx)) { // Setting the home LED when it's not supported can cause the controller to reset - return 0; + return true; } if (!WriteSubcommand(ctx, cmd, &payload[1], (Uint8)(size - 1), NULL)) { - return -1; + return false; } - return 0; + return true; } return SDL_Unsupported(); } -static int HIDAPI_DriverSwitch_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverSwitch_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { SDL_DriverSwitch_Context *ctx = (SDL_DriverSwitch_Context *)device->context; Uint8 input_mode; @@ -1708,7 +1708,7 @@ static int HIDAPI_DriverSwitch_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *devi ctx->m_unIMUSamples = 0; ctx->m_ulIMUSampleTimestampNS = SDL_GetTicksNS(); - return 0; + return true; } static void HandleInputOnlyControllerState(SDL_Joystick *joystick, SDL_DriverSwitch_Context *ctx, SwitchInputOnlyControllerStatePacket_t *packet) @@ -2643,7 +2643,7 @@ static bool HIDAPI_DriverSwitch_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverSwitch_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_wii.c b/src/joystick/hidapi/SDL_hidapi_wii.c index 2e60081cf4..8768bfa715 100644 --- a/src/joystick/hidapi/SDL_hidapi_wii.c +++ b/src/joystick/hidapi/SDL_hidapi_wii.c @@ -218,7 +218,7 @@ static bool WriteOutput(SDL_DriverWii_Context *ctx, const Uint8 *data, int size, return SDL_hid_write(ctx->device->dev, data, size) >= 0; } else { // Use the rumble thread for general asynchronous writes - if (SDL_HIDAPI_LockRumble() < 0) { + if (!SDL_HIDAPI_LockRumble()) { return false; } return SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) >= 0; @@ -820,7 +820,7 @@ static bool HIDAPI_DriverWii_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystic return true; } -static int HIDAPI_DriverWii_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverWii_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverWii_Context *ctx = (SDL_DriverWii_Context *)device->context; bool active = (low_frequency_rumble || high_frequency_rumble); @@ -834,10 +834,10 @@ static int HIDAPI_DriverWii_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joysti ctx->m_bRumbleActive = active; } - return 0; + return true; } -static int HIDAPI_DriverWii_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverWii_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -847,17 +847,17 @@ static Uint32 HIDAPI_DriverWii_GetJoystickCapabilities(SDL_HIDAPI_Device *device return SDL_JOYSTICK_CAP_RUMBLE; } -static int HIDAPI_DriverWii_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverWii_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverWii_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverWii_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverWii_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverWii_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { SDL_DriverWii_Context *ctx = (SDL_DriverWii_Context *)device->context; @@ -874,7 +874,7 @@ static int HIDAPI_DriverWii_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, ResetButtonPacketType(ctx); } - return 0; + return true; } static void PostStickCalibrated(Uint64 timestamp, SDL_Joystick *joystick, StickCalibrationData *calibration, Uint8 axis, Uint16 data) @@ -1573,7 +1573,7 @@ static bool HIDAPI_DriverWii_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverWii_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 4973f74b5a..7883dadac5 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -195,7 +195,7 @@ static bool HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joy return true; } -static int HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { #ifdef SDL_PLATFORM_MACOS if (SDL_IsJoystickBluetoothXboxOne(device->vendor_id, device->product_id)) { @@ -230,10 +230,10 @@ static int HIDAPI_DriverXbox360_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Jo return SDL_SetError("Couldn't send rumble packet"); } #endif - return 0; + return true; } -static int HIDAPI_DriverXbox360_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverXbox360_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -249,17 +249,17 @@ static Uint32 HIDAPI_DriverXbox360_GetJoystickCapabilities(SDL_HIDAPI_Device *de return result; } -static int HIDAPI_DriverXbox360_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverXbox360_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverXbox360_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverXbox360_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverXbox360_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverXbox360_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -359,7 +359,7 @@ static bool HIDAPI_DriverXbox360_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverXbox360_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360w.c b/src/joystick/hidapi/SDL_hidapi_xbox360w.c index ea452d7571..f2404685de 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360w.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360w.c @@ -181,7 +181,7 @@ static bool HIDAPI_DriverXbox360W_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Jo return true; } -static int HIDAPI_DriverXbox360W_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverXbox360W_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { Uint8 rumble_packet[] = { 0x00, 0x01, 0x0f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; @@ -191,10 +191,10 @@ static int HIDAPI_DriverXbox360W_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_J if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) { return SDL_SetError("Couldn't send rumble packet"); } - return 0; + return true; } -static int HIDAPI_DriverXbox360W_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverXbox360W_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } @@ -210,17 +210,17 @@ static Uint32 HIDAPI_DriverXbox360W_GetJoystickCapabilities(SDL_HIDAPI_Device *d return result; } -static int HIDAPI_DriverXbox360W_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverXbox360W_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int HIDAPI_DriverXbox360W_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverXbox360W_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverXbox360W_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverXbox360W_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -344,7 +344,7 @@ static bool HIDAPI_DriverXbox360W_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverXbox360W_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index 5b24d97fac..67cf335e8a 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -235,7 +235,7 @@ static bool SendProtocolPacket(SDL_DriverXboxOne_Context *ctx, const Uint8 *data ctx->send_time = SDL_GetTicks(); - if (SDL_HIDAPI_LockRumble() < 0) { + if (!SDL_HIDAPI_LockRumble()) { return false; } if (SDL_HIDAPI_SendRumbleAndUnlock(ctx->device, data, size) != size) { @@ -443,7 +443,7 @@ static void HIDAPI_DriverXboxOne_RumbleSent(void *userdata) ctx->rumble_time = SDL_GetTicks(); } -static int HIDAPI_DriverXboxOne_UpdateRumble(SDL_DriverXboxOne_Context *ctx) +static bool HIDAPI_DriverXboxOne_UpdateRumble(SDL_DriverXboxOne_Context *ctx) { if (ctx->rumble_state == XBOX_ONE_RUMBLE_STATE_QUEUED) { if (ctx->rumble_time) { @@ -460,18 +460,18 @@ static int HIDAPI_DriverXboxOne_UpdateRumble(SDL_DriverXboxOne_Context *ctx) } if (!ctx->rumble_pending) { - return 0; + return true; } if (ctx->rumble_state != XBOX_ONE_RUMBLE_STATE_IDLE) { - return 0; + return true; } // We're no longer pending, even if we fail to send the rumble below ctx->rumble_pending = false; - if (SDL_HIDAPI_LockRumble() < 0) { - return -1; + if (!SDL_HIDAPI_LockRumble()) { + return false; } if (ctx->device->is_bluetooth) { @@ -500,10 +500,10 @@ static int HIDAPI_DriverXboxOne_UpdateRumble(SDL_DriverXboxOne_Context *ctx) ctx->rumble_state = XBOX_ONE_RUMBLE_STATE_QUEUED; - return 0; + return true; } -static int HIDAPI_DriverXboxOne_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_DriverXboxOne_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)device->context; @@ -515,7 +515,7 @@ static int HIDAPI_DriverXboxOne_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Jo return HIDAPI_DriverXboxOne_UpdateRumble(ctx); } -static int HIDAPI_DriverXboxOne_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_DriverXboxOne_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)device->context; @@ -548,7 +548,7 @@ static Uint32 HIDAPI_DriverXboxOne_GetJoystickCapabilities(SDL_HIDAPI_Device *de return result; } -static int HIDAPI_DriverXboxOne_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_DriverXboxOne_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { SDL_DriverXboxOne_Context *ctx = (SDL_DriverXboxOne_Context *)device->context; @@ -563,18 +563,18 @@ static int HIDAPI_DriverXboxOne_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Jo if (SDL_HIDAPI_SendRumble(device, led_packet, sizeof(led_packet)) != sizeof(led_packet)) { return SDL_SetError("Couldn't send LED packet"); } - return 0; + return true; } else { return SDL_Unsupported(); } } -static int HIDAPI_DriverXboxOne_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_DriverXboxOne_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int HIDAPI_DriverXboxOne_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_DriverXboxOne_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -1627,7 +1627,7 @@ static bool HIDAPI_DriverXboxOne_UpdateDevice(SDL_HIDAPI_Device *device) // Read error, device is disconnected HIDAPI_JoystickDisconnected(device, device->joysticks[0]); } - return size >= 0; + return (size >= 0); } static void HIDAPI_DriverXboxOne_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index 56a31fa12b..67539ceeb8 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -569,12 +569,12 @@ static void SDLCALL SDL_HIDAPIDriverHintChanged(void *userdata, const char *name SDL_HIDAPI_change_count = 0; } -static int HIDAPI_JoystickInit(void) +static bool HIDAPI_JoystickInit(void) { int i; if (initialized) { - return 0; + return true; } #ifdef SDL_USE_LIBUDEV @@ -614,7 +614,7 @@ static int HIDAPI_JoystickInit(void) initialized = true; - return 0; + return true; } static bool HIDAPI_AddJoystickInstanceToDevice(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID) @@ -1249,7 +1249,7 @@ bool HIDAPI_IsDeviceTypePresent(SDL_GamepadType type) bool result = false; // Make sure we're initialized, as this could be called from other drivers during startup - if (HIDAPI_JoystickInit() < 0) { + if (!HIDAPI_JoystickInit()) { return false; } @@ -1280,7 +1280,7 @@ bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, bool result = false; // Make sure we're initialized, as this could be called from other drivers during startup - if (HIDAPI_JoystickInit() < 0) { + if (!HIDAPI_JoystickInit()) { return false; } @@ -1385,7 +1385,7 @@ void HIDAPI_UpdateDevices(void) continue; } if (device->driver) { - if (SDL_TryLockMutex(device->dev_lock) == 0) { + if (SDL_TryLockMutex(device->dev_lock)) { device->updating = true; device->driver->UpdateDevice(device); device->updating = false; @@ -1477,7 +1477,7 @@ static SDL_JoystickID HIDAPI_JoystickGetDeviceInstanceID(int device_index) return joystickID; } -static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index) { SDL_JoystickID joystickID = 0; SDL_HIDAPI_Device *device = HIDAPI_GetDeviceByIndex(device_index, &joystickID); @@ -1492,7 +1492,7 @@ static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index) hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (!hwdata) { - return -1; + return false; } hwdata->device = device; @@ -1520,7 +1520,7 @@ static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index) // The open failed, mark this device as disconnected and update devices HIDAPI_JoystickDisconnected(device, joystickID); SDL_free(hwdata); - return -1; + return false; } HIDAPI_UpdateJoystickProperties(device, joystick); @@ -1530,7 +1530,7 @@ static int HIDAPI_JoystickOpen(SDL_Joystick *joystick, int device_index) } joystick->hwdata = hwdata; - return 0; + return true; } static bool HIDAPI_GetJoystickDevice(SDL_Joystick *joystick, SDL_HIDAPI_Device **device) @@ -1546,9 +1546,9 @@ static bool HIDAPI_GetJoystickDevice(SDL_Joystick *joystick, SDL_HIDAPI_Device * return false; } -static int HIDAPI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool HIDAPI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { - int result; + bool result; SDL_HIDAPI_Device *device = NULL; if (HIDAPI_GetJoystickDevice(joystick, &device)) { @@ -1560,9 +1560,9 @@ static int HIDAPI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_ru return result; } -static int HIDAPI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool HIDAPI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { - int result; + bool result; SDL_HIDAPI_Device *device = NULL; if (HIDAPI_GetJoystickDevice(joystick, &device)) { @@ -1574,9 +1574,9 @@ static int HIDAPI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rum return result; } -static int HIDAPI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool HIDAPI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { - int result; + bool result; SDL_HIDAPI_Device *device = NULL; if (HIDAPI_GetJoystickDevice(joystick, &device)) { @@ -1588,9 +1588,9 @@ static int HIDAPI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, return result; } -static int HIDAPI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool HIDAPI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { - int result; + bool result; SDL_HIDAPI_Device *device = NULL; if (HIDAPI_GetJoystickDevice(joystick, &device)) { @@ -1602,9 +1602,9 @@ static int HIDAPI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, i return result; } -static int HIDAPI_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool HIDAPI_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { - int result; + bool result; SDL_HIDAPI_Device *device = NULL; if (HIDAPI_GetJoystickDevice(joystick, &device)) { diff --git a/src/joystick/hidapi/SDL_hidapijoystick_c.h b/src/joystick/hidapi/SDL_hidapijoystick_c.h index 2c2c3c7466..afa002968f 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h @@ -119,12 +119,12 @@ typedef struct SDL_HIDAPI_DeviceDriver void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index); bool (*UpdateDevice)(SDL_HIDAPI_Device *device); bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); - int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); - int (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); + bool (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); + bool (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble); Uint32 (*GetJoystickCapabilities)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); - int (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); - int (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size); - int (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled); + bool (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue); + bool (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size); + bool (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled); void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick); void (*FreeDevice)(SDL_HIDAPI_Device *device); diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index f736b64ca4..e9355d07f6 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -258,25 +258,23 @@ static int GuessDeviceClass(int fd) return SDL_EVDEV_GuessDeviceClass(propbit, evbit, absbit, keybit, relbit); } -static int GuessIsJoystick(int fd) +static bool GuessIsJoystick(int fd) { if (GuessDeviceClass(fd) & SDL_UDEV_DEVICE_JOYSTICK) { - return 1; + return true; } - - return 0; + return false; } -static int GuessIsSensor(int fd) +static bool GuessIsSensor(int fd) { if (GuessDeviceClass(fd) & SDL_UDEV_DEVICE_ACCELEROMETER) { - return 1; + return true; } - - return 0; + return false; } -static int IsJoystick(const char *path, int *fd, char **name_return, Uint16 *vendor_return, Uint16 *product_return, SDL_GUID *guid) +static bool IsJoystick(const char *path, int *fd, char **name_return, Uint16 *vendor_return, Uint16 *product_return, SDL_GUID *guid) { struct input_id inpid; char *name; @@ -288,7 +286,7 @@ static int IsJoystick(const char *path, int *fd, char **name_return, Uint16 *ven // Opening input devices can generate synchronous device I/O, so avoid it if we can if (SDL_UDEV_GetProductInfo(path, &inpid.vendor, &inpid.product, &inpid.version, &class) && !(class & SDL_UDEV_DEVICE_JOYSTICK)) { - return 0; + return false; } #endif @@ -296,34 +294,34 @@ static int IsJoystick(const char *path, int *fd, char **name_return, Uint16 *ven *fd = open(path, O_RDONLY | O_CLOEXEC, 0); } if (!fd || *fd < 0) { - return 0; + return false; } if (ioctl(*fd, JSIOCGNAME(sizeof(product_string)), product_string) <= 0) { // When udev enumeration or classification, we only got joysticks here, so no need to test if (enumeration_method != ENUMERATION_LIBUDEV && !class && !GuessIsJoystick(*fd)) { - return 0; + return false; } // Could have vendor and product already from udev, but should agree with evdev if (ioctl(*fd, EVIOCGID, &inpid) < 0) { - return 0; + return false; } if (ioctl(*fd, EVIOCGNAME(sizeof(product_string)), product_string) < 0) { - return 0; + return false; } } name = SDL_CreateJoystickName(inpid.vendor, inpid.product, NULL, product_string); if (!name) { - return 0; + return false; } if (!IsVirtualJoystick(inpid.vendor, inpid.product, inpid.version, name) && SDL_JoystickHandledByAnotherDriver(&SDL_LINUX_JoystickDriver, inpid.vendor, inpid.product, inpid.version, name)) { SDL_free(name); - return 0; + return false; } FixupDeviceInfoForMapping(*fd, &inpid); @@ -336,15 +334,15 @@ static int IsJoystick(const char *path, int *fd, char **name_return, Uint16 *ven if (SDL_ShouldIgnoreJoystick(name, *guid)) { SDL_free(name); - return 0; + return false; } *name_return = name; *vendor_return = inpid.vendor; *product_return = inpid.product; - return 1; + return true; } -static int IsSensor(const char *path, int *fd) +static bool IsSensor(const char *path, int *fd) { struct input_id inpid; int class = 0; @@ -354,7 +352,7 @@ static int IsSensor(const char *path, int *fd) // Opening input devices can generate synchronous device I/O, so avoid it if we can if (SDL_UDEV_GetProductInfo(path, &inpid.vendor, &inpid.product, &inpid.version, &class) && !(class & SDL_UDEV_DEVICE_ACCELEROMETER)) { - return 0; + return false; } #endif @@ -362,24 +360,24 @@ static int IsSensor(const char *path, int *fd) *fd = open(path, O_RDONLY | O_CLOEXEC, 0); } if (!fd || *fd < 0) { - return 0; + return false; } if (!class && !GuessIsSensor(*fd)) { - return 0; + return false; } if (ioctl(*fd, EVIOCGID, &inpid) < 0) { - return 0; + return false; } if (inpid.vendor == USB_VENDOR_NINTENDO && inpid.product == USB_PRODUCT_NINTENDO_WII_REMOTE) { // Wii extension controls // These may create 3 sensor devices but we only support reading from 1: ignore them - return 0; + return false; } - return 1; + return true; } #ifdef SDL_USE_LIBUDEV @@ -717,26 +715,21 @@ static void SteamControllerDisconnectedCallback(SDL_JoystickID device_instance) SDL_UnlockJoysticks(); } -static int StrHasPrefix(const char *string, const char *prefix) -{ - return SDL_strncmp(string, prefix, SDL_strlen(prefix)) == 0; -} - -static int StrIsInteger(const char *string) +static bool StrIsInteger(const char *string) { const char *p; if (*string == '\0') { - return 0; + return false; } for (p = string; *p != '\0'; p++) { if (*p < '0' || *p > '9') { - return 0; + return false; } } - return 1; + return true; } static bool IsJoystickJSNode(const char *node) @@ -745,7 +738,7 @@ static bool IsJoystickJSNode(const char *node) if (last_slash) { node = last_slash + 1; } - return StrHasPrefix(node, "js") && StrIsInteger(node + 2); + return SDL_startswith(node, "js") && StrIsInteger(node + 2); } static bool IsJoystickEventNode(const char *node) @@ -754,7 +747,7 @@ static bool IsJoystickEventNode(const char *node) if (last_slash) { node = last_slash + 1; } - return StrHasPrefix(node, "event") && StrIsInteger(node + 5); + return SDL_startswith(node, "event") && StrIsInteger(node + 5); } static bool IsJoystickDeviceNode(const char *node) @@ -1033,11 +1026,11 @@ static bool LINUX_JoystickIsDevicePresent(Uint16 vendor_id, Uint16 product_id, U return false; } -static int LINUX_JoystickInit(void) +static bool LINUX_JoystickInit(void) { const char *devices = SDL_GetHint(SDL_HINT_JOYSTICK_DEVICE); #ifdef SDL_USE_LIBUDEV - int udev_status = SDL_UDEV_Init(); + bool udev_initialized = SDL_UDEV_Init(); #endif SDL_classic_joysticks = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_LINUX_CLASSIC, false); @@ -1089,9 +1082,9 @@ static int LINUX_JoystickInit(void) } if (enumeration_method == ENUMERATION_LIBUDEV) { - if (udev_status == 0) { + if (udev_initialized) { // Set up the udev callback - if (SDL_UDEV_AddCallback(joystick_udev_callback) < 0) { + if (!SDL_UDEV_AddCallback(joystick_udev_callback)) { SDL_UDEV_Quit(); return SDL_SetError("Could not set up joystick <-> udev callback"); } @@ -1132,7 +1125,7 @@ static int LINUX_JoystickInit(void) #endif // HAVE_INOTIFY } - return 0; + return true; } static int LINUX_JoystickGetCount(void) @@ -1197,17 +1190,17 @@ static SDL_JoystickID LINUX_JoystickGetDeviceInstanceID(int device_index) return GetJoystickByDevIndex(device_index)->device_instance; } -static int allocate_balldata(SDL_Joystick *joystick) +static bool allocate_balldata(SDL_Joystick *joystick) { joystick->hwdata->balls = (struct hwdata_ball *)SDL_calloc(joystick->nballs, sizeof(struct hwdata_ball)); if (joystick->hwdata->balls == NULL) { - return -1; + return false; } - return 0; + return true; } -static int allocate_hatdata(SDL_Joystick *joystick) +static bool allocate_hatdata(SDL_Joystick *joystick) { int i; @@ -1217,13 +1210,13 @@ static int allocate_hatdata(SDL_Joystick *joystick) (struct hwdata_hat *)SDL_malloc(joystick->nhats * sizeof(struct hwdata_hat)); if (!joystick->hwdata->hats) { - return -1; + return false; } for (i = 0; i < joystick->nhats; ++i) { joystick->hwdata->hats[i].axis[0] = 1; joystick->hwdata->hats[i].axis[1] = 1; } - return 0; + return true; } static bool GuessIfAxesAreDigitalHat(struct input_absinfo *absinfo_x, struct input_absinfo *absinfo_y) @@ -1490,12 +1483,12 @@ static void ConfigJoystick(SDL_Joystick *joystick, int fd, int fd_sensor) // Allocate data to keep track of these thingamajigs if (joystick->nballs > 0) { - if (allocate_balldata(joystick) < 0) { + if (!allocate_balldata(joystick)) { joystick->nballs = 0; } } if (joystick->nhats > 0) { - if (allocate_hatdata(joystick) < 0) { + if (!allocate_hatdata(joystick)) { joystick->nhats = 0; } } @@ -1515,7 +1508,7 @@ static void ConfigJoystick(SDL_Joystick *joystick, int fd, int fd_sensor) without adding an opened SDL_Joystick object to the system. This expects `joystick->hwdata` to be allocated and will not free it on error. Returns -1 on error, 0 on success. */ -static int PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item, SDL_sensorlist_item *item_sensor) +static bool PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item, SDL_sensorlist_item *item_sensor) { SDL_AssertJoysticksLocked(); @@ -1557,7 +1550,7 @@ static int PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item, if (fd_sensor >= 0) { close(fd_sensor); } - return -1; + return false; } // Set the joystick to non-blocking read mode @@ -1569,7 +1562,7 @@ static int PrepareJoystickHwdata(SDL_Joystick *joystick, SDL_joylist_item *item, // Get the number of buttons and axes on the joystick ConfigJoystick(joystick, fd, fd_sensor); } - return 0; + return true; } static SDL_sensorlist_item *GetSensor(SDL_joylist_item *item) @@ -1626,12 +1619,7 @@ static SDL_sensorlist_item *GetSensor(SDL_joylist_item *item) return NULL; } -/* Function to open a joystick for use. - The joystick to open is specified by the device index. - This should fill the nbuttons and naxes fields of the joystick structure. - It returns 0, or -1 if there is an error. - */ -static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index) { SDL_joylist_item *item; SDL_sensorlist_item *item_sensor; @@ -1646,14 +1634,14 @@ static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index) joystick->hwdata = (struct joystick_hwdata *) SDL_calloc(1, sizeof(*joystick->hwdata)); if (!joystick->hwdata) { - return -1; + return false; } item_sensor = GetSensor(item); - if (PrepareJoystickHwdata(joystick, item, item_sensor) == -1) { + if (!PrepareJoystickHwdata(joystick, item, item_sensor)) { SDL_free(joystick->hwdata); joystick->hwdata = NULL; - return -1; // SDL_SetError will already have been called + return false; // SDL_SetError will already have been called } SDL_assert(item->hwdata == NULL); @@ -1681,10 +1669,10 @@ static int LINUX_JoystickOpen(SDL_Joystick *joystick, int device_index) if (joystick->hwdata->ff_rumble || joystick->hwdata->ff_sine) { SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true); } - return 0; + return true; } -static int LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { struct input_event event; @@ -1724,25 +1712,25 @@ static int LINUX_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rum if (write(joystick->hwdata->fd, &event, sizeof(event)) < 0) { return SDL_SetError("Couldn't start rumble effect: %s", strerror(errno)); } - return 0; + return true; } -static int LINUX_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool LINUX_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } -static int LINUX_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool LINUX_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int LINUX_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool LINUX_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int LINUX_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool LINUX_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { SDL_AssertJoysticksLocked(); @@ -1750,7 +1738,7 @@ static int LINUX_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) return SDL_Unsupported(); } if (enabled == joystick->hwdata->report_sensor) { - return 0; + return true; } if (enabled) { @@ -1769,7 +1757,7 @@ static int LINUX_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) } joystick->hwdata->report_sensor = enabled; - return 0; + return true; } static void HandleHat(Uint64 timestamp, SDL_Joystick *stick, int hatidx, int axis, int value) @@ -2362,7 +2350,7 @@ static bool LINUX_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping item->checked_mapping = true; - if (PrepareJoystickHwdata(joystick, item, NULL) < 0) { + if (!PrepareJoystickHwdata(joystick, item, NULL)) { goto done; // SDL_SetError will already have been called } diff --git a/src/joystick/n3ds/SDL_sysjoystick.c b/src/joystick/n3ds/SDL_sysjoystick.c index db161b8a46..7aed7ad2fd 100644 --- a/src/joystick/n3ds/SDL_sysjoystick.c +++ b/src/joystick/n3ds/SDL_sysjoystick.c @@ -59,11 +59,11 @@ static void UpdateN3DSReleasedButtons(Uint64 timestamp, SDL_Joystick *joystick); static void UpdateN3DSCircle(Uint64 timestamp, SDL_Joystick *joystick); static void UpdateN3DSCStick(Uint64 timestamp, SDL_Joystick *joystick); -static int N3DS_JoystickInit(void) +static bool N3DS_JoystickInit(void) { hidInit(); SDL_PrivateJoystickAdded(1); - return 0; + return true; } static const char *N3DS_JoystickGetDeviceName(int device_index) @@ -87,16 +87,16 @@ static SDL_JoystickID N3DS_JoystickGetDeviceInstanceID(int device_index) return device_index + 1; } -static int N3DS_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool N3DS_JoystickOpen(SDL_Joystick *joystick, int device_index) { joystick->nbuttons = NB_BUTTONS; joystick->naxes = 4; joystick->nhats = 0; - return 0; + return true; } -static int N3DS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool N3DS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -251,22 +251,22 @@ static void N3DS_JoystickSetDevicePlayerIndex(int device_index, int player_index { } -static int N3DS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool N3DS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } -static int N3DS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool N3DS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } -static int N3DS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool N3DS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int N3DS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool N3DS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } diff --git a/src/joystick/ps2/SDL_sysjoystick.c b/src/joystick/ps2/SDL_sysjoystick.c index 64e5f8fd84..0c00ffa4a2 100644 --- a/src/joystick/ps2/SDL_sysjoystick.c +++ b/src/joystick/ps2/SDL_sysjoystick.c @@ -85,17 +85,14 @@ static inline uint8_t rumble_status(uint8_t index) return info->rumble_ready == 1; } -/* Function to scan the system for joysticks. - * Joystick 0 should be the system default joystick. - * This function should return 0, or -1 on an unrecoverable error. - */ -static int PS2_JoystickInit(void) +// Function to scan the system for joysticks. +static bool PS2_JoystickInit(void) { uint32_t port = 0; uint32_t slot = 0; if (init_joystick_driver(true) < 0) { - return -1; + return false; } for (port = 0; port < PS2_MAX_PORT; port++) { @@ -127,7 +124,7 @@ static int PS2_JoystickInit(void) } } - return enabled_pads > 0 ? 0 : -1; + return (enabled_pads > 0); } // Function to return the number of joystick devices plugged in right now @@ -200,7 +197,7 @@ static SDL_JoystickID PS2_JoystickGetDeviceInstanceID(int device_index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -static int PS2_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool PS2_JoystickOpen(SDL_Joystick *joystick, int device_index) { int index = joystick->instance_id; struct JoyInfo *info = &joyInfo[index]; @@ -209,7 +206,7 @@ static int PS2_JoystickOpen(SDL_Joystick *joystick, int device_index) if (padPortOpen(info->port, info->slot, (void *)info->padBuf) > 0) { info->opened = 1; } else { - return -1; + return false; } } joystick->nbuttons = PS2_BUTTONS; @@ -218,11 +215,11 @@ static int PS2_JoystickOpen(SDL_Joystick *joystick, int device_index) SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true); - return 0; + return true; } // Rumble functionality -static int PS2_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool PS2_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { char actAlign[6]; int res; @@ -230,7 +227,7 @@ static int PS2_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl struct JoyInfo *info = &joyInfo[index]; if (!rumble_status(index)) { - return -1; + return false; } // Initial value @@ -242,29 +239,29 @@ static int PS2_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl actAlign[5] = 0xff; res = padSetActDirect(info->port, info->slot, actAlign); - return res == 1 ? 0 : -1; + return (res == 1); } // Rumble functionality -static int PS2_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint16 right) +static bool PS2_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint16 right) { return SDL_Unsupported(); } // LED functionality -static int PS2_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool PS2_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } // General effects -static int PS2_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool PS2_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } // Sensor functionality -static int PS2_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool PS2_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/psp/SDL_sysjoystick.c b/src/joystick/psp/SDL_sysjoystick.c index a97f094598..68ba3ab021 100644 --- a/src/joystick/psp/SDL_sysjoystick.c +++ b/src/joystick/psp/SDL_sysjoystick.c @@ -71,7 +71,7 @@ static int calc_bezier_y(float t) * Joystick 0 should be the system default joystick. * It should return number of joysticks, or -1 on an unrecoverable fatal error. */ -static int PSP_JoystickInit(void) +static bool PSP_JoystickInit(void) { int i; @@ -155,36 +155,36 @@ static SDL_JoystickID PSP_JoystickGetDeviceInstanceID(int device_index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -static int PSP_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool PSP_JoystickOpen(SDL_Joystick *joystick, int device_index) { joystick->nbuttons = SDL_arraysize(button_map); joystick->naxes = 2; joystick->nhats = 0; - return 0; + return true; } -static int PSP_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool PSP_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } -static int PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } -static int PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int PSP_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool PSP_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int PSP_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool PSP_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/virtual/SDL_virtualjoystick.c b/src/joystick/virtual/SDL_virtualjoystick.c index 3579b463bf..294773e9d2 100644 --- a/src/joystick/virtual/SDL_virtualjoystick.c +++ b/src/joystick/virtual/SDL_virtualjoystick.c @@ -135,7 +135,8 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des SDL_AssertJoysticksLocked(); if (!desc) { - return SDL_InvalidParamError("desc"); + SDL_InvalidParamError("desc"); + return 0; } hwdata = (joystick_hwdata *)SDL_calloc(1, sizeof(joystick_hwdata)); @@ -317,7 +318,7 @@ SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *des return hwdata->instance_id; } -int SDL_JoystickDetachVirtualInner(SDL_JoystickID instance_id) +bool SDL_JoystickDetachVirtualInner(SDL_JoystickID instance_id) { joystick_hwdata *hwdata = VIRTUAL_HWDataForInstance(instance_id); if (!hwdata) { @@ -325,10 +326,10 @@ int SDL_JoystickDetachVirtualInner(SDL_JoystickID instance_id) } VIRTUAL_FreeHWData(hwdata); SDL_PrivateJoystickRemoved(instance_id); - return 0; + return true; } -int SDL_SetJoystickVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 value) +bool SDL_SetJoystickVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 value) { joystick_hwdata *hwdata; @@ -346,10 +347,10 @@ int SDL_SetJoystickVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 val hwdata->axes[axis] = value; hwdata->changes |= AXES_CHANGED; - return 0; + return true; } -int SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel) +bool SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel) { joystick_hwdata *hwdata; @@ -370,10 +371,10 @@ int SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xre hwdata->balls[ball].dy = SDL_clamp(hwdata->balls[ball].dy, SDL_MIN_SINT16, SDL_MAX_SINT16); hwdata->changes |= BALLS_CHANGED; - return 0; + return true; } -int SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 value) +bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 value) { joystick_hwdata *hwdata; @@ -391,10 +392,10 @@ int SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 hwdata->buttons[button] = value; hwdata->changes |= BUTTONS_CHANGED; - return 0; + return true; } -int SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value) +bool SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value) { joystick_hwdata *hwdata; @@ -412,10 +413,10 @@ int SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value) hwdata->hats[hat] = value; hwdata->changes |= HATS_CHANGED; - return 0; + return true; } -int SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure) +bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure) { joystick_hwdata *hwdata; @@ -440,10 +441,10 @@ int SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, in info->pressure = pressure; hwdata->changes |= TOUCHPADS_CHANGED; - return 0; + return true; } -int SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values) +bool SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values) { joystick_hwdata *hwdata; @@ -458,7 +459,7 @@ int SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorTyp int new_max_sensor_events = (hwdata->max_sensor_events + 1); VirtualSensorEvent *sensor_events = (VirtualSensorEvent *)SDL_realloc(hwdata->sensor_events, new_max_sensor_events * sizeof(*sensor_events)); if (!sensor_events) { - return -1; + return false; } hwdata->sensor_events = sensor_events; hwdata->max_sensor_events = hwdata->max_sensor_events; @@ -470,12 +471,12 @@ int SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorTyp event->num_values = SDL_min(num_values, SDL_arraysize(event->data)); SDL_memcpy(event->data, data, (event->num_values * sizeof(*event->data))); - return 0; + return true; } -static int VIRTUAL_JoystickInit(void) +static bool VIRTUAL_JoystickInit(void) { - return 0; + return true; } static int VIRTUAL_JoystickGetCount(void) @@ -549,12 +550,12 @@ static SDL_JoystickID VIRTUAL_JoystickGetDeviceInstanceID(int device_index) { joystick_hwdata *hwdata = VIRTUAL_HWDataForIndex(device_index); if (!hwdata) { - return 0; + return true; } return hwdata->instance_id; } -static int VIRTUAL_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool VIRTUAL_JoystickOpen(SDL_Joystick *joystick, int device_index) { joystick_hwdata *hwdata; @@ -588,12 +589,12 @@ static int VIRTUAL_JoystickOpen(SDL_Joystick *joystick, int device_index) if (hwdata->desc.RumbleTriggers) { SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, true); } - return 0; + return true; } -static int VIRTUAL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool VIRTUAL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { - int result; + bool result; SDL_AssertJoysticksLocked(); @@ -611,9 +612,9 @@ static int VIRTUAL_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_r return result; } -static int VIRTUAL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool VIRTUAL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { - int result; + bool result; SDL_AssertJoysticksLocked(); @@ -631,9 +632,9 @@ static int VIRTUAL_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ru return result; } -static int VIRTUAL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool VIRTUAL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { - int result; + bool result; SDL_AssertJoysticksLocked(); @@ -651,9 +652,9 @@ static int VIRTUAL_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green return result; } -static int VIRTUAL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool VIRTUAL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { - int result; + bool result; SDL_AssertJoysticksLocked(); @@ -671,9 +672,9 @@ static int VIRTUAL_JoystickSendEffect(SDL_Joystick *joystick, const void *data, return result; } -static int VIRTUAL_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool VIRTUAL_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { - int result; + bool result; SDL_AssertJoysticksLocked(); @@ -682,9 +683,9 @@ static int VIRTUAL_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enable if (hwdata->desc.SetSensorsEnabled) { result = hwdata->desc.SetSensorsEnabled(hwdata->desc.userdata, enabled); } else { - result = 0; + result = true; } - if (result == 0) { + if (result) { hwdata->sensors_enabled = enabled; } } else { diff --git a/src/joystick/virtual/SDL_virtualjoystick_c.h b/src/joystick/virtual/SDL_virtualjoystick_c.h index e8a94fa88e..796857856a 100644 --- a/src/joystick/virtual/SDL_virtualjoystick_c.h +++ b/src/joystick/virtual/SDL_virtualjoystick_c.h @@ -70,14 +70,14 @@ typedef struct joystick_hwdata } joystick_hwdata; extern SDL_JoystickID SDL_JoystickAttachVirtualInner(const SDL_VirtualJoystickDesc *desc); -extern int SDL_JoystickDetachVirtualInner(SDL_JoystickID instance_id); +extern bool SDL_JoystickDetachVirtualInner(SDL_JoystickID instance_id); -extern int SDL_SetJoystickVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 value); -extern int SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel); -extern int SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 value); -extern int SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value); -extern int SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure); -extern int SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); +extern bool SDL_SetJoystickVirtualAxisInner(SDL_Joystick *joystick, int axis, Sint16 value); +extern bool SDL_SetJoystickVirtualBallInner(SDL_Joystick *joystick, int ball, Sint16 xrel, Sint16 yrel); +extern bool SDL_SetJoystickVirtualButtonInner(SDL_Joystick *joystick, int button, Uint8 value); +extern bool SDL_SetJoystickVirtualHatInner(SDL_Joystick *joystick, int hat, Uint8 value); +extern bool SDL_SetJoystickVirtualTouchpadInner(SDL_Joystick *joystick, int touchpad, int finger, Uint8 state, float x, float y, float pressure); +extern bool SDL_SendJoystickVirtualSensorDataInner(SDL_Joystick *joystick, SDL_SensorType type, Uint64 sensor_timestamp, const float *data, int num_values); #endif // SDL_JOYSTICK_VIRTUAL diff --git a/src/joystick/vita/SDL_sysjoystick.c b/src/joystick/vita/SDL_sysjoystick.c index 1e401ce604..592c7aab44 100644 --- a/src/joystick/vita/SDL_sysjoystick.c +++ b/src/joystick/vita/SDL_sysjoystick.c @@ -95,7 +95,7 @@ static int calc_bezier_y(float t) * Joystick 0 should be the system default joystick. * It should return number of joysticks, or -1 on an unrecoverable fatal error. */ -static int VITA_JoystickInit(void) +static bool VITA_JoystickInit(void) { int i; SceCtrlPortInfo myPortInfo; @@ -201,7 +201,7 @@ static void VITA_JoystickSetDevicePlayerIndex(int device_index, int player_index This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -static int VITA_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool VITA_JoystickOpen(SDL_Joystick *joystick, int device_index) { joystick->nbuttons = SDL_arraysize(ext_button_map); joystick->naxes = 6; @@ -210,7 +210,7 @@ static int VITA_JoystickOpen(SDL_Joystick *joystick, int device_index) SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RGB_LED_BOOLEAN, true); SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true); - return 0; + return true; } /* Function to update the state of a joystick - called as a device poll. @@ -325,13 +325,13 @@ static SDL_GUID VITA_JoystickGetDeviceGUID(int device_index) return SDL_CreateJoystickGUIDForName(name); } -static int VITA_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool VITA_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { int index = (int)SDL_GetJoystickID(joystick) - 1; SceCtrlActuator act; if (index < 0 || index > 3) { - return -1; + return false; } SDL_zero(act); act.small = high_frequency_rumble / 256; @@ -339,32 +339,32 @@ static int VITA_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumb if (sceCtrlSetActuator(ext_port_map[index], &act) < 0) { return SDL_Unsupported(); } - return 0; + return true; } -static int VITA_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint16 right) +static bool VITA_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left, Uint16 right) { return SDL_Unsupported(); } -static int VITA_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool VITA_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { int index = (int)SDL_GetJoystickID(joystick) - 1; if (index < 0 || index > 3) { - return -1; + return false; } if (sceCtrlSetLightBar(ext_port_map[index], red, green, blue) < 0) { return SDL_Unsupported(); } - return 0; + return true; } -static int VITA_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool VITA_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int VITA_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool VITA_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/windows/SDL_dinputjoystick.c b/src/joystick/windows/SDL_dinputjoystick.c index 2df803236a..9ae04834d0 100644 --- a/src/joystick/windows/SDL_dinputjoystick.c +++ b/src/joystick/windows/SDL_dinputjoystick.c @@ -231,7 +231,7 @@ const DIDATAFORMAT SDL_c_dfDIJoystick2 = { }; // Convert a DirectInput return code to a text message -static int SetDIerror(const char *function, HRESULT code) +static bool SetDIerror(const char *function, HRESULT code) { return SDL_SetError("%s() DirectX error 0x%8.8lx", function, code); } @@ -393,7 +393,7 @@ DIEFFECT *CreateRumbleEffectData(Sint16 magnitude) return effect; } -int SDL_DINPUT_JoystickInit(void) +bool SDL_DINPUT_JoystickInit(void) { HRESULT result; HINSTANCE instance; @@ -401,7 +401,7 @@ int SDL_DINPUT_JoystickInit(void) if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_DIRECTINPUT, true)) { // In some environments, IDirectInput8_Initialize / _EnumDevices can take a minute even with no controllers. dinput = NULL; - return 0; + return true; } result = WIN_CoInitialize(); @@ -432,7 +432,7 @@ int SDL_DINPUT_JoystickInit(void) dinput = NULL; return SetDIerror("IDirectInput::Initialize", result); } - return 0; + return true; } static int GetSteamVirtualGamepadSlot(Uint16 vendor_id, Uint16 product_id, const char *device_path) @@ -734,7 +734,7 @@ static void SortDevObjects(SDL_Joystick *joystick) } } -int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) +bool SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) { HRESULT result; DIPROPDWORD dipdw; @@ -859,10 +859,10 @@ int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystic } SDL_Delay(50); - return 0; + return true; } -static int SDL_DINPUT_JoystickInitRumble(SDL_Joystick *joystick, Sint16 magnitude) +static bool SDL_DINPUT_JoystickInitRumble(SDL_Joystick *joystick, Sint16 magnitude) { HRESULT result; @@ -886,7 +886,7 @@ static int SDL_DINPUT_JoystickInitRumble(SDL_Joystick *joystick, Sint16 magnitud // Create the effect joystick->hwdata->ffeffect = CreateRumbleEffectData(magnitude); if (!joystick->hwdata->ffeffect) { - return -1; + return false; } result = IDirectInputDevice8_CreateEffect(joystick->hwdata->InputDevice, &GUID_Sine, @@ -894,10 +894,10 @@ static int SDL_DINPUT_JoystickInitRumble(SDL_Joystick *joystick, Sint16 magnitud if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::CreateEffect", result); } - return 0; + return true; } -int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +bool SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { HRESULT result; @@ -923,8 +923,8 @@ int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl return SetDIerror("IDirectInputDevice8::SetParameters", result); } } else { - if (SDL_DINPUT_JoystickInitRumble(joystick, magnitude) < 0) { - return -1; + if (!SDL_DINPUT_JoystickInitRumble(joystick, magnitude)) { + return false; } joystick->hwdata->ff_initialized = true; } @@ -939,7 +939,7 @@ int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl if (FAILED(result)) { return SetDIerror("IDirectInputDevice8::Start", result); } - return 0; + return true; } static Uint8 TranslatePOV(DWORD value) @@ -1162,9 +1162,9 @@ void SDL_DINPUT_JoystickQuit(void) typedef struct JoyStick_DeviceData JoyStick_DeviceData; -int SDL_DINPUT_JoystickInit(void) +bool SDL_DINPUT_JoystickInit(void) { - return 0; + return true; } void SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext) @@ -1176,12 +1176,12 @@ bool SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version) return false; } -int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) +bool SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) { return SDL_Unsupported(); } -int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +bool SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } diff --git a/src/joystick/windows/SDL_dinputjoystick_c.h b/src/joystick/windows/SDL_dinputjoystick_c.h index 3cc28c6bd1..fea61301c7 100644 --- a/src/joystick/windows/SDL_dinputjoystick_c.h +++ b/src/joystick/windows/SDL_dinputjoystick_c.h @@ -25,11 +25,11 @@ extern "C" { #endif -extern int SDL_DINPUT_JoystickInit(void); +extern bool SDL_DINPUT_JoystickInit(void); extern void SDL_DINPUT_JoystickDetect(JoyStick_DeviceData **pContext); extern bool SDL_DINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version); -extern int SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice); -extern int SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); +extern bool SDL_DINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice); +extern bool SDL_DINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); extern void SDL_DINPUT_JoystickUpdate(SDL_Joystick *joystick); extern void SDL_DINPUT_JoystickClose(SDL_Joystick *joystick); extern void SDL_DINPUT_JoystickQuit(void); diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index 55b7769ab8..b87d34517f 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -572,15 +572,15 @@ static bool RAWINPUT_MissingWindowsGamingInputSlot(void) return false; } -static int RAWINPUT_UpdateWindowsGamingInput(void) +static bool RAWINPUT_UpdateWindowsGamingInput(void) { int ii; if (!wgi_state.gamepad_statics) { - return 0; + return true; } if (!wgi_state.dirty) { - return 0; + return true; } wgi_state.dirty = false; @@ -620,12 +620,12 @@ static int RAWINPUT_UpdateWindowsGamingInput(void) WindowsGamingInputGamepadState **new_per_gamepad; gamepad_state = SDL_calloc(1, sizeof(*gamepad_state)); if (!gamepad_state) { - return -1; + return false; } new_per_gamepad = SDL_realloc(wgi_state.per_gamepad, sizeof(wgi_state.per_gamepad[0]) * (wgi_state.per_gamepad_count + 1)); if (!new_per_gamepad) { SDL_free(gamepad_state); - return -1; + return false; } wgi_state.per_gamepad = new_per_gamepad; wgi_state.per_gamepad_count++; @@ -663,7 +663,7 @@ static int RAWINPUT_UpdateWindowsGamingInput(void) wgi_state.per_gamepad[ii]->connected = false; // Not used by anything, currently } } - return 0; + return true; } static void RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx) { @@ -1025,28 +1025,28 @@ static void RAWINPUT_RemoveDevices(void) SDL_assert(SDL_RAWINPUT_numjoysticks == 0); } -static int RAWINPUT_JoystickInit(void) +static bool RAWINPUT_JoystickInit(void) { SDL_assert(!SDL_RAWINPUT_inited); if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_RAWINPUT, true)) { - return 0; + return true; } if (!WIN_IsWindowsVistaOrGreater()) { // According to bug 6400, this doesn't work on Windows XP - return -1; + return false; } - if (WIN_LoadHIDDLL() < 0) { - return -1; + if (!WIN_LoadHIDDLL()) { + return false; } SDL_RAWINPUT_inited = true; RAWINPUT_DetectDevices(); - return 0; + return true; } static int RAWINPUT_JoystickGetCount(void) @@ -1208,7 +1208,7 @@ static int RAWINPUT_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index) static int RAWINPUT_JoystickGetDevicePlayerIndex(int device_index) { - return -1; + return false; } static void RAWINPUT_JoystickSetDevicePlayerIndex(int device_index, int player_index) @@ -1234,7 +1234,7 @@ static int SDLCALL RAWINPUT_SortValueCaps(const void *A, const void *B) return (int)capsA->NotRange.Usage - capsB->NotRange.Usage; } -static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) { SDL_RAWINPUT_Device *device = RAWINPUT_GetDeviceByIndex(device_index); RAWINPUT_DeviceContext *ctx; @@ -1245,7 +1245,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ctx = (RAWINPUT_DeviceContext *)SDL_calloc(1, sizeof(RAWINPUT_DeviceContext)); if (!ctx) { - return -1; + return false; } joystick->hwdata = ctx; @@ -1257,7 +1257,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) #ifdef SDL_JOYSTICK_RAWINPUT_XINPUT xinput_device_change = true; ctx->xinput_enabled = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_RAWINPUT_CORRELATE_XINPUT, true); - if (ctx->xinput_enabled && (WIN_LoadXInputDLL() < 0 || !XINPUTGETSTATE)) { + if (ctx->xinput_enabled && (!WIN_LoadXInputDLL() || !XINPUTGETSTATE)) { ctx->xinput_enabled = false; } ctx->xinput_slot = XUSER_INDEX_ANY; @@ -1277,7 +1277,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) ctx->data = (HIDP_DATA *)SDL_malloc(ctx->max_data_length * sizeof(*ctx->data)); if (!ctx->data) { RAWINPUT_JoystickClose(joystick); - return -1; + return false; } if (SDL_HidP_GetCaps(ctx->preparsed_data, &caps) != HIDP_STATUS_SUCCESS) { @@ -1325,7 +1325,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) RAWINPUT_JoystickClose(joystick); SDL_stack_free(value_caps); SDL_stack_free(button_caps); - return -1; + return false; } for (i = 0; i < caps.NumberInputButtonCaps; ++i) { @@ -1381,7 +1381,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) if (!ctx->axis_indices) { RAWINPUT_JoystickClose(joystick); SDL_stack_free(value_caps); - return -1; + return false; } for (i = 0; i < caps.NumberInputValueCaps; ++i) { @@ -1415,7 +1415,7 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) if (!ctx->hat_indices) { RAWINPUT_JoystickClose(joystick); SDL_stack_free(value_caps); - return -1; + return false; } for (i = 0; i < caps.NumberInputValueCaps; ++i) { @@ -1450,10 +1450,10 @@ static int RAWINPUT_JoystickOpen(SDL_Joystick *joystick, int device_index) } #endif - return 0; + return true; } -static int RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { #if defined(SDL_JOYSTICK_RAWINPUT_WGI) || defined(SDL_JOYSTICK_RAWINPUT_XINPUT) RAWINPUT_DeviceContext *ctx = joystick->hwdata; @@ -1499,10 +1499,10 @@ static int RAWINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_ return SDL_Unsupported(); #endif } - return 0; + return true; } -static int RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { #ifdef SDL_JOYSTICK_RAWINPUT_WGI RAWINPUT_DeviceContext *ctx = joystick->hwdata; @@ -1516,7 +1516,7 @@ static int RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_r if (!SUCCEEDED(hr)) { return SDL_SetError("Setting vibration failed: 0x%lx\n", hr); } - return 0; + return true; } else { return SDL_SetError("Controller isn't correlated yet, try hitting a button first"); } @@ -1525,17 +1525,17 @@ static int RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_r #endif } -static int RAWINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool RAWINPUT_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int RAWINPUT_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool RAWINPUT_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int RAWINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool RAWINPUT_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } @@ -2089,13 +2089,13 @@ static void RAWINPUT_JoystickClose(SDL_Joystick *joystick) } } -int RAWINPUT_RegisterNotifications(HWND hWnd) +bool RAWINPUT_RegisterNotifications(HWND hWnd) { int i; RAWINPUTDEVICE rid[SDL_arraysize(subscribed_devices)]; if (!SDL_RAWINPUT_inited) { - return 0; + return true; } for (i = 0; i < SDL_arraysize(subscribed_devices); i++) { @@ -2108,16 +2108,16 @@ int RAWINPUT_RegisterNotifications(HWND hWnd) if (!RegisterRawInputDevices(rid, SDL_arraysize(rid), sizeof(RAWINPUTDEVICE))) { return SDL_SetError("Couldn't register for raw input events"); } - return 0; + return true; } -int RAWINPUT_UnregisterNotifications(void) +bool RAWINPUT_UnregisterNotifications(void) { int i; RAWINPUTDEVICE rid[SDL_arraysize(subscribed_devices)]; if (!SDL_RAWINPUT_inited) { - return 0; + return true; } for (i = 0; i < SDL_arraysize(subscribed_devices); i++) { @@ -2130,7 +2130,7 @@ int RAWINPUT_UnregisterNotifications(void) if (!RegisterRawInputDevices(rid, SDL_arraysize(rid), sizeof(RAWINPUTDEVICE))) { return SDL_SetError("Couldn't unregister for raw input events"); } - return 0; + return true; } LRESULT CALLBACK diff --git a/src/joystick/windows/SDL_windows_gaming_input.c b/src/joystick/windows/SDL_windows_gaming_input.c index 4876d28956..55cf23daf9 100644 --- a/src/joystick/windows/SDL_windows_gaming_input.c +++ b/src/joystick/windows/SDL_windows_gaming_input.c @@ -580,12 +580,12 @@ static RawGameControllerDelegate controller_removed = { #pragma warning(pop) #endif -static int WGI_JoystickInit(void) +static bool WGI_JoystickInit(void) { HRESULT hr; if (!SDL_GetHintBoolean(SDL_HINT_JOYSTICK_WGI, true)) { - return 0; + return true; } if (FAILED(WIN_RoInitialize())) { @@ -661,7 +661,7 @@ static int WGI_JoystickInit(void) } } - return 0; + return true; } static int WGI_JoystickGetCount(void) @@ -696,7 +696,7 @@ static int WGI_JoystickGetDeviceSteamVirtualGamepadSlot(int device_index) static int WGI_JoystickGetDevicePlayerIndex(int device_index) { - return -1; + return false; } static void WGI_JoystickSetDevicePlayerIndex(int device_index, int player_index) @@ -713,7 +713,7 @@ static SDL_JoystickID WGI_JoystickGetDeviceInstanceID(int device_index) return wgi.controllers[device_index].instance_id; } -static int WGI_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool WGI_JoystickOpen(SDL_Joystick *joystick, int device_index) { WindowsGamingInputControllerState *state = &wgi.controllers[device_index]; struct joystick_hwdata *hwdata; @@ -721,7 +721,7 @@ static int WGI_JoystickOpen(SDL_Joystick *joystick, int device_index) hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (!hwdata) { - return -1; + return false; } joystick->hwdata = hwdata; @@ -753,10 +753,10 @@ static int WGI_JoystickOpen(SDL_Joystick *joystick, int device_index) SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true); SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_TRIGGER_RUMBLE_BOOLEAN, true); } - return 0; + return true; } -static int WGI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool WGI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { struct joystick_hwdata *hwdata = joystick->hwdata; @@ -768,7 +768,7 @@ static int WGI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl hwdata->vibration.RightMotor = (DOUBLE)high_frequency_rumble / SDL_MAX_UINT16; hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(hwdata->gamepad, hwdata->vibration); if (SUCCEEDED(hr)) { - return 0; + return true; } else { return WIN_SetErrorFromHRESULT("Windows.Gaming.Input.IGamepad.put_Vibration failed", hr); } @@ -777,7 +777,7 @@ static int WGI_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl } } -static int WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { struct joystick_hwdata *hwdata = joystick->hwdata; @@ -789,7 +789,7 @@ static int WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble hwdata->vibration.RightTrigger = (DOUBLE)right_rumble / SDL_MAX_UINT16; hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(hwdata->gamepad, hwdata->vibration); if (SUCCEEDED(hr)) { - return 0; + return true; } else { return WIN_SetErrorFromHRESULT("Windows.Gaming.Input.IGamepad.put_Vibration failed", hr); } @@ -798,17 +798,17 @@ static int WGI_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble } } -static int WGI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool WGI_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int WGI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool WGI_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int WGI_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool WGI_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/windows/SDL_windowsjoystick.c b/src/joystick/windows/SDL_windowsjoystick.c index 0fcb13909e..727ff7c288 100644 --- a/src/joystick/windows/SDL_windowsjoystick.c +++ b/src/joystick/windows/SDL_windowsjoystick.c @@ -107,13 +107,13 @@ static LRESULT CALLBACK SDL_PrivateJoystickDetectProc(HWND hwnd, UINT msg, WPARA } break; } - return 0; + return true; case WM_TIMER: if (wParam == IDT_SDL_DEVICE_CHANGE_TIMER_1 || wParam == IDT_SDL_DEVICE_CHANGE_TIMER_2) { KillTimer(hwnd, wParam); SetWindowsDeviceChanged(); - return 0; + return true; } break; } @@ -146,7 +146,7 @@ static void SDL_CleanupDeviceNotification(SDL_DeviceNotificationData *data) } } -static int SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data) +static bool SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data) { DEV_BROADCAST_DEVICEINTERFACE dbh; @@ -162,14 +162,14 @@ static int SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data) if (!RegisterClassEx(&data->wincl)) { WIN_SetError("Failed to create register class for joystick autodetect"); SDL_CleanupDeviceNotification(data); - return -1; + return false; } data->messageWindow = CreateWindowEx(0, TEXT("Message"), NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL); if (!data->messageWindow) { WIN_SetError("Failed to create message window for joystick autodetect"); SDL_CleanupDeviceNotification(data); - return -1; + return false; } SDL_zero(dbh); @@ -181,13 +181,13 @@ static int SDL_CreateDeviceNotification(SDL_DeviceNotificationData *data) if (!data->hNotify) { WIN_SetError("Failed to create notify device for joystick autodetect"); SDL_CleanupDeviceNotification(data); - return -1; + return false; } #ifdef SDL_JOYSTICK_RAWINPUT RAWINPUT_RegisterNotifications(data->messageWindow); #endif - return 0; + return true; } static bool SDL_WaitForDeviceNotification(SDL_DeviceNotificationData *data, SDL_Mutex *mutex) @@ -228,8 +228,8 @@ static int SDLCALL SDL_JoystickThread(void *_data) #endif #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) - if (SDL_CreateDeviceNotification(&s_notification_data) < 0) { - return -1; + if (!SDL_CreateDeviceNotification(&s_notification_data)) { + return 0; } #endif @@ -273,24 +273,24 @@ static int SDLCALL SDL_JoystickThread(void *_data) } // spin up the thread to detect hotplug of devices -static int SDL_StartJoystickThread(void) +static bool SDL_StartJoystickThread(void) { s_mutexJoyStickEnum = SDL_CreateMutex(); if (!s_mutexJoyStickEnum) { - return -1; + return false; } s_condJoystickThread = SDL_CreateCondition(); if (!s_condJoystickThread) { - return -1; + return false; } s_bJoystickThreadQuit = false; s_joystickThread = SDL_CreateThreadWithStackSize(SDL_JoystickThread, "SDL_joystick", 64 * 1024, NULL); if (!s_joystickThread) { - return -1; + return false; } - return 0; + return true; } static void SDL_StopJoystickThread(void) @@ -333,20 +333,17 @@ void WINDOWS_AddJoystickDevice(JoyStick_DeviceData *device) void WINDOWS_JoystickDetect(void); void WINDOWS_JoystickQuit(void); -/* Function to scan the system for joysticks. - * Joystick 0 should be the system default joystick. - * It should return 0, or -1 on an unrecoverable fatal error. - */ -static int WINDOWS_JoystickInit(void) +// Function to scan the system for joysticks. +static bool WINDOWS_JoystickInit(void) { - if (SDL_DINPUT_JoystickInit() < 0) { + if (!SDL_DINPUT_JoystickInit()) { WINDOWS_JoystickQuit(); - return -1; + return false; } - if (SDL_XINPUT_JoystickInit() < 0) { + if (!SDL_XINPUT_JoystickInit()) { WINDOWS_JoystickQuit(); - return -1; + return false; } WIN_InitDeviceNotification(); @@ -354,12 +351,12 @@ static int WINDOWS_JoystickInit(void) #if !defined(SDL_PLATFORM_WINRT) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) s_bJoystickThread = SDL_GetHintBoolean(SDL_HINT_JOYSTICK_THREAD, false); if (s_bJoystickThread) { - if (SDL_StartJoystickThread() < 0) { - return -1; + if (!SDL_StartJoystickThread()) { + return false; } } else { - if (SDL_CreateDeviceNotification(&s_notification_data) < 0) { - return -1; + if (!SDL_CreateDeviceNotification(&s_notification_data)) { + return false; } } #endif @@ -367,8 +364,8 @@ static int WINDOWS_JoystickInit(void) #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) // On Xbox, force create the joystick thread for device detection (since other methods don't work s_bJoystickThread = true; - if (SDL_StartJoystickThread() < 0) { - return -1; + if (!SDL_StartJoystickThread()) { + return false; } #endif @@ -376,7 +373,7 @@ static int WINDOWS_JoystickInit(void) WINDOWS_JoystickDetect(); - return 0; + return true; } // return the number of joysticks that are connected right now @@ -552,7 +549,7 @@ static SDL_JoystickID WINDOWS_JoystickGetDeviceInstanceID(int device_index) This should fill the nbuttons and naxes fields of the joystick structure. It returns 0, or -1 if there is an error. */ -static int WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index) +static bool WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index) { JoyStick_DeviceData *device = SYS_Joystick; int index; @@ -564,7 +561,7 @@ static int WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index) // allocate memory for system specific hardware data joystick->hwdata = (struct joystick_hwdata *)SDL_calloc(1, sizeof(struct joystick_hwdata)); if (!joystick->hwdata) { - return -1; + return false; } joystick->hwdata->guid = device->guid; @@ -575,7 +572,7 @@ static int WINDOWS_JoystickOpen(SDL_Joystick *joystick, int device_index) } } -static int WINDOWS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static bool WINDOWS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { if (joystick->hwdata->bXInputDevice) { return SDL_XINPUT_JoystickRumble(joystick, low_frequency_rumble, high_frequency_rumble); @@ -584,22 +581,22 @@ static int WINDOWS_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_r } } -static int WINDOWS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) +static bool WINDOWS_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble) { return SDL_Unsupported(); } -static int WINDOWS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) +static bool WINDOWS_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue) { return SDL_Unsupported(); } -static int WINDOWS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) +static bool WINDOWS_JoystickSendEffect(SDL_Joystick *joystick, const void *data, int size) { return SDL_Unsupported(); } -static int WINDOWS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) +static bool WINDOWS_JoystickSetSensorsEnabled(SDL_Joystick *joystick, bool enabled) { return SDL_Unsupported(); } diff --git a/src/joystick/windows/SDL_xinputjoystick.c b/src/joystick/windows/SDL_xinputjoystick.c index 300aef9671..992be0816a 100644 --- a/src/joystick/windows/SDL_xinputjoystick.c +++ b/src/joystick/windows/SDL_xinputjoystick.c @@ -44,14 +44,14 @@ bool SDL_XINPUT_Enabled(void) return s_bXInputEnabled; } -int SDL_XINPUT_JoystickInit(void) +bool SDL_XINPUT_JoystickInit(void) { s_bXInputEnabled = SDL_GetHintBoolean(SDL_HINT_XINPUT_ENABLED, true); - if (s_bXInputEnabled && WIN_LoadXInputDLL() < 0) { + if (s_bXInputEnabled && !WIN_LoadXInputDLL()) { s_bXInputEnabled = false; // oh well. } - return 0; + return true; } static const char *GetXInputName(const Uint8 userid, BYTE SubType) @@ -255,7 +255,7 @@ bool SDL_XINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version) return false; } -int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) +bool SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) { const Uint8 userId = joystickdevice->XInputUserId; XINPUT_CAPABILITIES capabilities; @@ -284,7 +284,7 @@ int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystic SDL_SetBooleanProperty(SDL_GetJoystickProperties(joystick), SDL_PROP_JOYSTICK_CAP_RUMBLE_BOOLEAN, true); - return 0; + return true; } static void UpdateXInputJoystickBatteryInformation(SDL_Joystick *joystick, XINPUT_BATTERY_INFORMATION_EX *pBatteryInformation) @@ -362,7 +362,7 @@ static void UpdateXInputJoystickState(SDL_Joystick *joystick, XINPUT_STATE *pXIn UpdateXInputJoystickBatteryInformation(joystick, pBatteryInformation); } -int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +bool SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { XINPUT_VIBRATION XVibration; @@ -375,7 +375,7 @@ int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumbl if (XINPUTSETSTATE(joystick->hwdata->userid, &XVibration) != ERROR_SUCCESS) { return SDL_SetError("XInputSetState() failed"); } - return 0; + return true; } void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick) @@ -436,9 +436,9 @@ bool SDL_XINPUT_Enabled(void) return false; } -int SDL_XINPUT_JoystickInit(void) +bool SDL_XINPUT_JoystickInit(void) { - return 0; + return true; } void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext) @@ -450,12 +450,12 @@ bool SDL_XINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version) return false; } -int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) +bool SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice) { return SDL_Unsupported(); } -int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +bool SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { return SDL_Unsupported(); } diff --git a/src/joystick/windows/SDL_xinputjoystick_c.h b/src/joystick/windows/SDL_xinputjoystick_c.h index edf5d2bd8d..c43293b58d 100644 --- a/src/joystick/windows/SDL_xinputjoystick_c.h +++ b/src/joystick/windows/SDL_xinputjoystick_c.h @@ -28,11 +28,11 @@ extern "C" { #endif extern bool SDL_XINPUT_Enabled(void); -extern int SDL_XINPUT_JoystickInit(void); +extern bool SDL_XINPUT_JoystickInit(void); extern void SDL_XINPUT_JoystickDetect(JoyStick_DeviceData **pContext); extern bool SDL_XINPUT_JoystickPresent(Uint16 vendor, Uint16 product, Uint16 version); -extern int SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice); -extern int SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); +extern bool SDL_XINPUT_JoystickOpen(SDL_Joystick *joystick, JoyStick_DeviceData *joystickdevice); +extern bool SDL_XINPUT_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble); extern void SDL_XINPUT_JoystickUpdate(SDL_Joystick *joystick); extern void SDL_XINPUT_JoystickClose(SDL_Joystick *joystick); extern void SDL_XINPUT_JoystickQuit(void); diff --git a/src/locale/SDL_locale.c b/src/locale/SDL_locale.c index 6e253504e3..f13c4c5adb 100644 --- a/src/locale/SDL_locale.c +++ b/src/locale/SDL_locale.c @@ -29,7 +29,7 @@ static SDL_Locale **build_locales_from_csv_string(char *csv, int *count) size_t alloclen; char *ptr; SDL_Locale *loc; - SDL_Locale **retval; + SDL_Locale **result; if (count) { *count = 0; @@ -52,16 +52,16 @@ static SDL_Locale **build_locales_from_csv_string(char *csv, int *count) slen = ((size_t)(ptr - csv)) + 1; // SDL_strlen(csv) + 1 alloclen = ((num_locales + 1) * sizeof(SDL_Locale *)) + (num_locales * sizeof(SDL_Locale)) + slen; - retval = (SDL_Locale **)SDL_calloc(1, alloclen); - if (!retval) { + result = (SDL_Locale **)SDL_calloc(1, alloclen); + if (!result) { return NULL; // oh well } - loc = (SDL_Locale *)(retval + (num_locales + 1)); + loc = (SDL_Locale *)(result + (num_locales + 1)); ptr = (char *)(loc + num_locales); SDL_memcpy(ptr, csv, slen); i = 0; - retval[i++] = loc; + result[i++] = loc; while (true) { // parse out the string while (SDL_isspace(*ptr)) { ptr++; // skip whitespace. @@ -81,7 +81,7 @@ static SDL_Locale **build_locales_from_csv_string(char *csv, int *count) } else if (ch == ',') { *(ptr++) = '\0'; loc++; - retval[i++] = loc; + result[i++] = loc; break; } else if (ch == '\0') { break; @@ -95,7 +95,7 @@ static SDL_Locale **build_locales_from_csv_string(char *csv, int *count) *count = num_locales; } - return retval; + return result; } SDL_Locale **SDL_GetPreferredLocales(int *count) diff --git a/src/locale/SDL_syslocale.h b/src/locale/SDL_syslocale.h index 7ba69704dd..69374fd480 100644 --- a/src/locale/SDL_syslocale.h +++ b/src/locale/SDL_syslocale.h @@ -26,7 +26,7 @@ extern "C" { #endif -extern int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen); +extern bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen); #ifdef __cplusplus } diff --git a/src/locale/android/SDL_syslocale.c b/src/locale/android/SDL_syslocale.c index 03a6874860..c78a553025 100644 --- a/src/locale/android/SDL_syslocale.c +++ b/src/locale/android/SDL_syslocale.c @@ -23,8 +23,7 @@ #include "../SDL_syslocale.h" #include "../../core/android/SDL_android.h" -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { - Android_JNI_GetLocale(buf, buflen); - return 0; + return Android_JNI_GetLocale(buf, buflen); } diff --git a/src/locale/dummy/SDL_syslocale.c b/src/locale/dummy/SDL_syslocale.c index 55980f8b29..37d676e145 100644 --- a/src/locale/dummy/SDL_syslocale.c +++ b/src/locale/dummy/SDL_syslocale.c @@ -22,7 +22,7 @@ #include "SDL_internal.h" #include "../SDL_syslocale.h" -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { // dummy implementation. Caller already zero'd out buffer. return SDL_Unsupported(); diff --git a/src/locale/emscripten/SDL_syslocale.c b/src/locale/emscripten/SDL_syslocale.c index c9ee9a55bf..a926e654ec 100644 --- a/src/locale/emscripten/SDL_syslocale.c +++ b/src/locale/emscripten/SDL_syslocale.c @@ -24,7 +24,7 @@ #include "SDL_internal.h" #include "../SDL_syslocale.h" -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { /* *INDENT-OFF* */ // clang-format off EM_ASM({ @@ -67,5 +67,5 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) } }, buf, buflen); /* *INDENT-ON* */ // clang-format on - return 0; + return true; } diff --git a/src/locale/haiku/SDL_syslocale.cc b/src/locale/haiku/SDL_syslocale.cc index 5e5da395d8..dae57cb2fa 100644 --- a/src/locale/haiku/SDL_syslocale.cc +++ b/src/locale/haiku/SDL_syslocale.cc @@ -26,7 +26,7 @@ #include "SDL_internal.h" #include "../SDL_syslocale.h" -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { BLocaleRoster *roster = BLocaleRoster::Default(); roster->Refresh(); @@ -68,5 +68,5 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) buflen--; } } - return 0; + return true; } diff --git a/src/locale/macos/SDL_syslocale.m b/src/locale/macos/SDL_syslocale.m index a9d1af3c2b..6832d4e0b4 100644 --- a/src/locale/macos/SDL_syslocale.m +++ b/src/locale/macos/SDL_syslocale.m @@ -24,7 +24,7 @@ #import -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { @autoreleasepool { NSArray *languages = NSLocale.preferredLanguages; @@ -72,5 +72,5 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) } } } - return 0; + return true; } diff --git a/src/locale/n3ds/SDL_syslocale.c b/src/locale/n3ds/SDL_syslocale.c index 465e7c4e02..ba2a645ee2 100644 --- a/src/locale/n3ds/SDL_syslocale.c +++ b/src/locale/n3ds/SDL_syslocale.c @@ -29,7 +29,7 @@ static u8 GetLocaleIndex(void); -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { // The 3DS only supports these 12 languages, only one can be active at a time static const char AVAILABLE_LOCALES[][6] = { "ja_JP", "en_US", "fr_FR", "de_DE", @@ -39,7 +39,7 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) if (current_locale != BAD_LOCALE) { SDL_strlcpy(buf, AVAILABLE_LOCALES[current_locale], buflen); } - return 0; + return true; } static u8 GetLocaleIndex(void) diff --git a/src/locale/unix/SDL_syslocale.c b/src/locale/unix/SDL_syslocale.c index 2cea3deed3..e945da5c86 100644 --- a/src/locale/unix/SDL_syslocale.c +++ b/src/locale/unix/SDL_syslocale.c @@ -62,7 +62,7 @@ static void normalize_locales(char *dst, char *src, size_t buflen) normalize_locale_str(dst, src, buflen); } -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { // !!! FIXME: should we be using setlocale()? Or some D-Bus thing? bool isstack; @@ -72,7 +72,7 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) SDL_assert(buflen > 0); tmp = SDL_small_alloc(char, buflen, &isstack); if (!tmp) { - return -1; + return false; } *tmp = '\0'; @@ -99,5 +99,5 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) } SDL_small_free(tmp, isstack); - return 0; + return true; } diff --git a/src/locale/vita/SDL_syslocale.c b/src/locale/vita/SDL_syslocale.c index 42bdcd2c9d..f624f2f4cf 100644 --- a/src/locale/vita/SDL_syslocale.c +++ b/src/locale/vita/SDL_syslocale.c @@ -25,7 +25,7 @@ #include #include -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { const char *vita_locales[] = { "ja_JP", @@ -65,5 +65,5 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) SDL_strlcpy(buf, vita_locales[language], buflen); sceAppUtilShutdown(); - return 0; + return true; } diff --git a/src/locale/windows/SDL_syslocale.c b/src/locale/windows/SDL_syslocale.c index feafc55dd7..d1be3b9c17 100644 --- a/src/locale/windows/SDL_syslocale.c +++ b/src/locale/windows/SDL_syslocale.c @@ -32,7 +32,7 @@ static pfnGetUserPreferredUILanguages pGetUserPreferredUILanguages = NULL; static HMODULE kernel32 = 0; // this is the fallback for WinXP...one language, not a list. -static void SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen) +static bool SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen) { char lang[16]; char country[16]; @@ -47,14 +47,15 @@ static void SDL_SYS_GetPreferredLocales_winxp(char *buf, size_t buflen) /* Win95 systems will fail, because they don't have LOCALE_SISO*NAME ... */ if (langrc == 0) { - SDL_SetError("Couldn't obtain language info"); + return SDL_SetError("Couldn't obtain language info"); } else { (void)SDL_snprintf(buf, buflen, "%s%s%s", lang, ctryrc ? "_" : "", ctryrc ? country : ""); + return true; } } // this works on Windows Vista and later. -static int SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) +static bool SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) { ULONG numlangs = 0; WCHAR *wbuf = NULL; @@ -66,7 +67,7 @@ static int SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) wbuf = SDL_small_alloc(WCHAR, wbuflen, &isstack); if (!wbuf) { - return -1; + return false; } if (!pGetUserPreferredUILanguages(MUI_LANGUAGE_NAME, &numlangs, wbuf, &wbuflen)) { @@ -90,10 +91,10 @@ static int SDL_SYS_GetPreferredLocales_vista(char *buf, size_t buflen) } SDL_small_free(wbuf, isstack); - return 0; + return true; } -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { if (!kernel32) { kernel32 = GetModuleHandle(TEXT("kernel32.dll")); @@ -103,9 +104,8 @@ int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) } if (!pGetUserPreferredUILanguages) { - SDL_SYS_GetPreferredLocales_winxp(buf, buflen); // this is always available + return SDL_SYS_GetPreferredLocales_winxp(buf, buflen); // this is always available } else { - SDL_SYS_GetPreferredLocales_vista(buf, buflen); // available on Vista and later. + return SDL_SYS_GetPreferredLocales_vista(buf, buflen); // available on Vista and later. } - return 0; } diff --git a/src/locale/winrt/SDL_syslocale.c b/src/locale/winrt/SDL_syslocale.c index 6275556f9b..1ad9756e53 100644 --- a/src/locale/winrt/SDL_syslocale.c +++ b/src/locale/winrt/SDL_syslocale.c @@ -27,28 +27,28 @@ // using namespace Windows::Graphics::Display; #include -int SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) +bool SDL_SYS_GetPreferredLocales(char *buf, size_t buflen) { WCHAR wbuffer[128] = L""; - int ret = 0; + int rc = 0; // !!! FIXME: do we not have GetUserPreferredUILanguages on WinPhone or UWP? #if SDL_WINAPI_FAMILY_PHONE - ret = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SNAME, wbuffer, SDL_arraysize(wbuffer)); + rc = GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SNAME, wbuffer, SDL_arraysize(wbuffer)); #else - ret = GetSystemDefaultLocaleName(wbuffer, SDL_arraysize(wbuffer)); + rc = GetSystemDefaultLocaleName(wbuffer, SDL_arraysize(wbuffer)); #endif - if (ret > 0) { + if (rc > 0) { // Need to convert LPWSTR to LPSTR, that is wide char to char. int i; - if (((size_t)ret) >= (buflen - 1)) { - ret = (int)(buflen - 1); + if (((size_t)rc) >= (buflen - 1)) { + rc = (int)(buflen - 1); } - for (i = 0; i < ret; i++) { + for (i = 0; i < rc; i++) { buf[i] = (char)wbuffer[i]; // assume this was ASCII anyhow. } } - return 0; + return true; } diff --git a/src/main/SDL_main_callbacks.c b/src/main/SDL_main_callbacks.c index b3491bd60b..236662015d 100644 --- a/src/main/SDL_main_callbacks.c +++ b/src/main/SDL_main_callbacks.c @@ -99,14 +99,14 @@ SDL_AppResult SDL_InitMainCallbacks(int argc, char* argv[], SDL_AppInit_func app const SDL_AppResult rc = appinit(&SDL_main_appstate, argc, argv); if (SDL_AtomicCompareAndSwap(&apprc, SDL_APP_CONTINUE, rc) && (rc == SDL_APP_CONTINUE)) { // bounce if SDL_AppInit already said abort, otherwise... // make sure we definitely have events initialized, even if the app didn't do it. - if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) { + if (!SDL_InitSubSystem(SDL_INIT_EVENTS)) { SDL_AtomicSet(&apprc, SDL_APP_FAILURE); - return -1; + return SDL_APP_FAILURE; } - if (SDL_AddEventWatch(SDL_MainCallbackEventWatcher, NULL) < 0) { + if (!SDL_AddEventWatch(SDL_MainCallbackEventWatcher, NULL)) { SDL_AtomicSet(&apprc, SDL_APP_FAILURE); - return -1; + return SDL_APP_FAILURE; } } diff --git a/src/main/gdk/SDL_sysmain_runapp.cpp b/src/main/gdk/SDL_sysmain_runapp.cpp index 6e8197d082..78f521d6f4 100644 --- a/src/main/gdk/SDL_sysmain_runapp.cpp +++ b/src/main/gdk/SDL_sysmain_runapp.cpp @@ -85,7 +85,7 @@ int SDL_RunApp(int, char**, SDL_main_func mainFunction, void *reserved) hr = XGameRuntimeInitialize(); - if (SUCCEEDED(hr) && SDL_GetGDKTaskQueue(&taskQueue) == 0) { + if (SUCCEEDED(hr) && SDL_GetGDKTaskQueue(&taskQueue)) { Uint32 titleid = 0; char scidBuffer[64]; XblInitArgs xblArgs; @@ -106,7 +106,7 @@ int SDL_RunApp(int, char**, SDL_main_func mainFunction, void *reserved) SDL_SetMainReady(); - if (GDK_RegisterChangeNotifications() != 0) { + if (!GDK_RegisterChangeNotifications()) { return -1; } diff --git a/src/main/winrt/SDL_sysmain_runapp.cpp b/src/main/winrt/SDL_sysmain_runapp.cpp index 7a6e347c74..a69509d01e 100644 --- a/src/main/winrt/SDL_sysmain_runapp.cpp +++ b/src/main/winrt/SDL_sysmain_runapp.cpp @@ -29,12 +29,17 @@ extern "C" int SDL_RunApp(int, char**, SDL_main_func mainFunction, void * xamlBackgroundPanel) { if (xamlBackgroundPanel) { - return SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel); + if (!SDL_WinRTInitXAMLApp(mainFunction, xamlBackgroundPanel)) { + return 1; + } } else { if (FAILED(Windows::Foundation::Initialize(RO_INIT_MULTITHREADED))) { return 1; } - return SDL_WinRTInitNonXAMLApp(mainFunction); + if (!SDL_WinRTInitNonXAMLApp(mainFunction)) { + return 1; + } } + return 0; } diff --git a/src/misc/SDL_sysurl.h b/src/misc/SDL_sysurl.h index 0eca8ac19f..1f539315c4 100644 --- a/src/misc/SDL_sysurl.h +++ b/src/misc/SDL_sysurl.h @@ -24,7 +24,7 @@ extern "C" { #endif -extern int SDL_SYS_OpenURL(const char *url); +extern bool SDL_SYS_OpenURL(const char *url); #ifdef __cplusplus } diff --git a/src/misc/SDL_url.c b/src/misc/SDL_url.c index 34016bf96f..74d0671442 100644 --- a/src/misc/SDL_url.c +++ b/src/misc/SDL_url.c @@ -22,7 +22,7 @@ #include "SDL_sysurl.h" -int SDL_OpenURL(const char *url) +SDL_bool SDL_OpenURL(const char *url) { if (!url) { return SDL_InvalidParamError("url"); diff --git a/src/misc/android/SDL_sysurl.c b/src/misc/android/SDL_sysurl.c index 07067de101..c82cc53a3d 100644 --- a/src/misc/android/SDL_sysurl.c +++ b/src/misc/android/SDL_sysurl.c @@ -23,7 +23,7 @@ #include "../SDL_sysurl.h" #include "../../core/android/SDL_android.h" -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { return Android_JNI_OpenURL(url); } diff --git a/src/misc/dummy/SDL_sysurl.c b/src/misc/dummy/SDL_sysurl.c index 358b3e6d8c..43527f58d4 100644 --- a/src/misc/dummy/SDL_sysurl.c +++ b/src/misc/dummy/SDL_sysurl.c @@ -22,7 +22,7 @@ #include "../SDL_sysurl.h" -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { return SDL_Unsupported(); } diff --git a/src/misc/emscripten/SDL_sysurl.c b/src/misc/emscripten/SDL_sysurl.c index 023bd15b23..990794ca44 100644 --- a/src/misc/emscripten/SDL_sysurl.c +++ b/src/misc/emscripten/SDL_sysurl.c @@ -26,8 +26,8 @@ EM_JS_DEPS(sdlsysurl, "$UTF8ToString"); -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { EM_ASM(window.open(UTF8ToString($0), "_blank"), url); - return 0; + return true; } diff --git a/src/misc/haiku/SDL_sysurl.cc b/src/misc/haiku/SDL_sysurl.cc index 5c6dd00c8e..4db022fd45 100644 --- a/src/misc/haiku/SDL_sysurl.cc +++ b/src/misc/haiku/SDL_sysurl.cc @@ -23,9 +23,12 @@ #include "../SDL_sysurl.h" #include -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { BUrl burl(url); const status_t rc = burl.OpenWithPreferredApplication(false); - return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int) rc); + if (rc != B_NO_ERROR) { + return SDL_SetError("URL open failed (err=%d)", (int)rc); + } + return true; } diff --git a/src/misc/ios/SDL_sysurl.m b/src/misc/ios/SDL_sysurl.m index eba867feb5..9de531b9a4 100644 --- a/src/misc/ios/SDL_sysurl.m +++ b/src/misc/ios/SDL_sysurl.m @@ -26,7 +26,7 @@ #import -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { @autoreleasepool { @@ -35,7 +35,7 @@ int SDL_SYS_OpenURL(const char *url) #else NSString *nsstr = [NSString stringWithUTF8String:url]; NSURL *nsurl = [NSURL URLWithString:nsstr]; - return [[UIApplication sharedApplication] openURL:nsurl] ? 0 : -1; + return [[UIApplication sharedApplication] openURL:nsurl]; #endif } } diff --git a/src/misc/macos/SDL_sysurl.m b/src/misc/macos/SDL_sysurl.m index 18b2891202..8a61199f57 100644 --- a/src/misc/macos/SDL_sysurl.m +++ b/src/misc/macos/SDL_sysurl.m @@ -26,13 +26,16 @@ #import -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { @autoreleasepool { CFURLRef cfurl = CFURLCreateWithBytes(NULL, (const UInt8 *)url, SDL_strlen(url), kCFStringEncodingUTF8, NULL); OSStatus status = LSOpenCFURLRef(cfurl, NULL); CFRelease(cfurl); - return status == noErr ? 0 : -1; + if (status != noErr) { + return SDL_SetError("LSOpenCFURLRef() failed: %d", status); + } + return true; } } diff --git a/src/misc/riscos/SDL_sysurl.c b/src/misc/riscos/SDL_sysurl.c index f9285b76fe..cefc046d46 100644 --- a/src/misc/riscos/SDL_sysurl.c +++ b/src/misc/riscos/SDL_sysurl.c @@ -29,7 +29,7 @@ #define URI_Dispatch 0x4e381 #endif -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { _kernel_swi_regs regs; _kernel_oserror *error; @@ -42,5 +42,8 @@ int SDL_SYS_OpenURL(const char *url) return SDL_SetError("Couldn't open given URL: %s", error->errmess); } - return (regs.r[0] & 1) ? SDL_SetError("Couldn't open given URL.") : 0; + if (regs.r[0] & 1) { + return SDL_SetError("Couldn't open given URL."); + } + return true; } diff --git a/src/misc/unix/SDL_sysurl.c b/src/misc/unix/SDL_sysurl.c index 374463b459..c194a2d17d 100644 --- a/src/misc/unix/SDL_sysurl.c +++ b/src/misc/unix/SDL_sysurl.c @@ -33,7 +33,7 @@ extern char **environ; #endif -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { const pid_t pid1 = fork(); if (pid1 == 0) { // child process @@ -71,7 +71,7 @@ int SDL_SYS_OpenURL(const char *url) if (waitpid(pid1, &status, 0) == pid1) { if (WIFEXITED(status)) { if (WEXITSTATUS(status) == 0) { - return 0; // success! + return true; // success! } else { return SDL_SetError("xdg-open reported error or failed to launch: %d", WEXITSTATUS(status)); } diff --git a/src/misc/vita/SDL_sysurl.c b/src/misc/vita/SDL_sysurl.c index 5e0cb1d3c6..1ea93c4b8a 100644 --- a/src/misc/vita/SDL_sysurl.c +++ b/src/misc/vita/SDL_sysurl.c @@ -25,7 +25,7 @@ #include #include -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { SceAppUtilInitParam init_param; SceAppUtilBootParam boot_param; @@ -37,5 +37,5 @@ int SDL_SYS_OpenURL(const char *url) browser_param.str = url; browser_param.strlen = SDL_strlen(url); sceAppUtilLaunchWebBrowser(&browser_param); - return 0; + return true; } diff --git a/src/misc/windows/SDL_sysurl.c b/src/misc/windows/SDL_sysurl.c index bb2272e0a3..2821be520f 100644 --- a/src/misc/windows/SDL_sysurl.c +++ b/src/misc/windows/SDL_sysurl.c @@ -26,14 +26,14 @@ #include #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { // Not supported return SDL_Unsupported(); } #else // https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { WCHAR *wurl; HINSTANCE rc; @@ -47,13 +47,16 @@ int SDL_SYS_OpenURL(const char *url) wurl = WIN_UTF8ToStringW(url); if (!wurl) { WIN_CoUninitialize(); - return -1; + return false; } // Success returns value greater than 32. Less is an error. rc = ShellExecuteW(NULL, L"open", wurl, NULL, NULL, SW_SHOWNORMAL); SDL_free(wurl); WIN_CoUninitialize(); - return (rc > ((HINSTANCE)32)) ? 0 : WIN_SetError("Couldn't open given URL."); + if (rc <= ((HINSTANCE)32)) { + return WIN_SetError("Couldn't open given URL."); + } + return true; } #endif diff --git a/src/misc/winrt/SDL_sysurl.cpp b/src/misc/winrt/SDL_sysurl.cpp index cd6ae2f5d8..0026e615e5 100644 --- a/src/misc/winrt/SDL_sysurl.cpp +++ b/src/misc/winrt/SDL_sysurl.cpp @@ -23,16 +23,16 @@ #include "../SDL_sysurl.h" #include "../../core/windows/SDL_windows.h" -int SDL_SYS_OpenURL(const char *url) +bool SDL_SYS_OpenURL(const char *url) { WCHAR *wurl = WIN_UTF8ToStringW(url); if (!wurl) { - return -1; + return false; } auto strurl = ref new Platform::String(wurl); SDL_free(wurl); auto uri = ref new Windows::Foundation::Uri(strurl); Windows::System::Launcher::LaunchUriAsync(uri); - return 0; // oh well, we're not waiting on an async task here. + return true; // oh well, we're not waiting on an async task here. } diff --git a/src/power/SDL_power.c b/src/power/SDL_power.c index b964862ee7..255cecf38f 100644 --- a/src/power/SDL_power.c +++ b/src/power/SDL_power.c @@ -88,7 +88,7 @@ SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent) { #ifndef SDL_POWER_DISABLED const int total = sizeof(implementations) / sizeof(implementations[0]); - SDL_PowerState retval = SDL_POWERSTATE_UNKNOWN; + SDL_PowerState result = SDL_POWERSTATE_UNKNOWN; int i; #endif @@ -103,8 +103,8 @@ SDL_PowerState SDL_GetPowerInfo(int *seconds, int *percent) #ifndef SDL_POWER_DISABLED for (i = 0; i < total; i++) { - if (implementations[i](&retval, seconds, percent)) { - return retval; + if (implementations[i](&result, seconds, percent)) { + return result; } } #endif diff --git a/src/power/linux/SDL_syspower.c b/src/power/linux/SDL_syspower.c index dd7cad6ddb..a3cf1c9139 100644 --- a/src/power/linux/SDL_syspower.c +++ b/src/power/linux/SDL_syspower.c @@ -616,7 +616,7 @@ static void check_upower_device(DBusConnection *conn, const char *path, SDL_Powe bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, int *seconds, int *percent) { - bool retval = false; + bool result = false; #ifdef SDL_USE_LIBDBUS SDL_DBusContext *dbus = SDL_DBus_GetContext(); @@ -629,7 +629,7 @@ bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, int *s return false; // try a different approach than UPower. } - retval = true; // Clearly we can use this interface. + result = true; // Clearly we can use this interface. *state = SDL_POWERSTATE_NO_BATTERY; // assume we're just plugged in. *seconds = -1; *percent = -1; @@ -641,7 +641,7 @@ bool SDL_GetPowerInfo_Linux_org_freedesktop_upower(SDL_PowerState *state, int *s dbus->free_string_array(paths); #endif // SDL_USE_LIBDBUS - return retval; + return result; } #endif // SDL_POWER_LINUX diff --git a/src/power/n3ds/SDL_syspower.c b/src/power/n3ds/SDL_syspower.c index 6ee762a4da..94e57f645f 100644 --- a/src/power/n3ds/SDL_syspower.c +++ b/src/power/n3ds/SDL_syspower.c @@ -26,7 +26,7 @@ #include <3ds.h> static SDL_PowerState GetPowerState(void); -static int ReadStateFromPTMU(bool *is_plugged, u8 *is_charging); +static bool ReadStateFromPTMU(bool *is_plugged, u8 *is_charging); static int GetBatteryPercentage(void); #define BATTERY_PERCENT_REG 0xB @@ -46,7 +46,7 @@ static SDL_PowerState GetPowerState(void) bool is_plugged; u8 is_charging; - if (ReadStateFromPTMU(&is_plugged, &is_charging) < 0) { + if (!ReadStateFromPTMU(&is_plugged, &is_charging)) { return SDL_POWERSTATE_UNKNOWN; } @@ -61,7 +61,7 @@ static SDL_PowerState GetPowerState(void) return SDL_POWERSTATE_ON_BATTERY; } -static int ReadStateFromPTMU(bool *is_plugged, u8 *is_charging) +static bool ReadStateFromPTMU(bool *is_plugged, u8 *is_charging) { if (R_FAILED(ptmuInit())) { return SDL_SetError("Failed to initialise PTMU service"); @@ -78,7 +78,7 @@ static int ReadStateFromPTMU(bool *is_plugged, u8 *is_charging) } ptmuExit(); - return 0; + return true; } static int GetBatteryPercentage(void) @@ -86,12 +86,14 @@ static int GetBatteryPercentage(void) u8 data[BATTERY_PERCENT_REG_SIZE]; if (R_FAILED(mcuHwcInit())) { - return SDL_SetError("Failed to initialise mcuHwc service"); + SDL_SetError("Failed to initialise mcuHwc service"); + return -1; } if (R_FAILED(MCUHWC_ReadRegister(BATTERY_PERCENT_REG, data, BATTERY_PERCENT_REG_SIZE))) { mcuHwcExit(); - return SDL_SetError("Failed to read battery register"); + SDL_SetError("Failed to read battery register"); + return -1; } mcuHwcExit(); diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 07a737ddb7..a5babc7e0e 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -47,23 +47,23 @@ this should probably be removed at some point in the future. --ryan. */ #define SDL_PROP_WINDOW_RENDERER_POINTER "SDL.internal.window.renderer" #define SDL_PROP_TEXTURE_PARENT_POINTER "SDL.internal.texture.parent" -#define CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, retval) \ +#define CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, result) \ if (!SDL_ObjectValid(renderer, SDL_OBJECT_TYPE_RENDERER)) { \ SDL_InvalidParamError("renderer"); \ - return retval; \ + return result; \ } -#define CHECK_RENDERER_MAGIC(renderer, retval) \ - CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, retval); \ +#define CHECK_RENDERER_MAGIC(renderer, result) \ + CHECK_RENDERER_MAGIC_BUT_NOT_DESTROYED_FLAG(renderer, result); \ if ((renderer)->destroyed) { \ SDL_SetError("Renderer's window has been destroyed, can't use further"); \ - return retval; \ + return result; \ } -#define CHECK_TEXTURE_MAGIC(texture, retval) \ +#define CHECK_TEXTURE_MAGIC(texture, result) \ if (!SDL_ObjectValid(texture, SDL_OBJECT_TYPE_TEXTURE)) { \ SDL_InvalidParamError("texture"); \ - return retval; \ + return result; \ } // Predefined blend modes @@ -151,17 +151,17 @@ void SDL_QuitRender(void) } } -int SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format) +bool SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format) { SDL_PixelFormat *texture_formats = (SDL_PixelFormat *)SDL_realloc((void *)renderer->texture_formats, (renderer->num_texture_formats + 2) * sizeof(SDL_PixelFormat)); if (!texture_formats) { - return -1; + return false; } texture_formats[renderer->num_texture_formats++] = format; texture_formats[renderer->num_texture_formats] = SDL_PIXELFORMAT_UNKNOWN; renderer->texture_formats = texture_formats; SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, texture_formats); - return 0; + return true; } void SDL_SetupRendererColorspace(SDL_Renderer *renderer, SDL_PropertiesID props) @@ -308,20 +308,20 @@ static SDL_INLINE void DebugLogRenderCommands(const SDL_RenderCommand *cmd) #endif } -static int FlushRenderCommands(SDL_Renderer *renderer) +static bool FlushRenderCommands(SDL_Renderer *renderer) { - int retval; + bool result; SDL_assert((renderer->render_commands == NULL) == (renderer->render_commands_tail == NULL)); if (!renderer->render_commands) { // nothing to do! SDL_assert(renderer->vertex_data_used == 0); - return 0; + return true; } DebugLogRenderCommands(renderer->render_commands); - retval = renderer->RunCommandQueue(renderer, renderer->render_commands, renderer->vertex_data, renderer->vertex_data_used); + result = renderer->RunCommandQueue(renderer, renderer->render_commands, renderer->vertex_data, renderer->vertex_data_used); // Move the whole render command queue to the unused pool so we can reuse them next time. if (renderer->render_commands_tail) { @@ -336,26 +336,26 @@ static int FlushRenderCommands(SDL_Renderer *renderer) renderer->color_scale_queued = false; renderer->viewport_queued = false; renderer->cliprect_queued = false; - return retval; + return result; } -static int FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture) +static bool FlushRenderCommandsIfTextureNeeded(SDL_Texture *texture) { SDL_Renderer *renderer = texture->renderer; if (texture->last_command_generation == renderer->render_command_generation) { // the current command queue depends on this texture, flush the queue now before it changes return FlushRenderCommands(renderer); } - return 0; + return true; } -int SDL_FlushRenderer(SDL_Renderer *renderer) +SDL_bool SDL_FlushRenderer(SDL_Renderer *renderer) { - if (FlushRenderCommands(renderer) < 0) { - return -1; + if (!FlushRenderCommands(renderer)) { + return false; } renderer->InvalidateCachedState(renderer); - return 0; + return true; } void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset) @@ -394,29 +394,29 @@ void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, static SDL_RenderCommand *AllocateRenderCommand(SDL_Renderer *renderer) { - SDL_RenderCommand *retval = NULL; + SDL_RenderCommand *result = NULL; // !!! FIXME: are there threading limitations in SDL's render API? If not, we need to mutex this. - retval = renderer->render_commands_pool; - if (retval) { - renderer->render_commands_pool = retval->next; - retval->next = NULL; + result = renderer->render_commands_pool; + if (result) { + renderer->render_commands_pool = result->next; + result->next = NULL; } else { - retval = (SDL_RenderCommand *)SDL_calloc(1, sizeof(*retval)); - if (!retval) { + result = (SDL_RenderCommand *)SDL_calloc(1, sizeof(*result)); + if (!result) { return NULL; } } SDL_assert((renderer->render_commands == NULL) == (renderer->render_commands_tail == NULL)); if (renderer->render_commands_tail) { - renderer->render_commands_tail->next = retval; + renderer->render_commands_tail->next = result; } else { - renderer->render_commands = retval; + renderer->render_commands = result; } - renderer->render_commands_tail = retval; + renderer->render_commands_tail = result; - return retval; + return result; } static void UpdatePixelViewport(SDL_Renderer *renderer, SDL_RenderViewState *view) @@ -435,10 +435,10 @@ static void UpdatePixelViewport(SDL_Renderer *renderer, SDL_RenderViewState *vie } } -static int QueueCmdSetViewport(SDL_Renderer *renderer) +static bool QueueCmdSetViewport(SDL_Renderer *renderer) { SDL_Rect viewport; - int retval = 0; + bool result = true; viewport = renderer->view->pixel_viewport; @@ -449,18 +449,18 @@ static int QueueCmdSetViewport(SDL_Renderer *renderer) cmd->command = SDL_RENDERCMD_SETVIEWPORT; cmd->data.viewport.first = 0; // render backend will fill this in. SDL_copyp(&cmd->data.viewport.rect, &viewport); - retval = renderer->QueueSetViewport(renderer, cmd); - if (retval < 0) { + result = renderer->QueueSetViewport(renderer, cmd); + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } else { SDL_copyp(&renderer->last_queued_viewport, &viewport); renderer->viewport_queued = true; } } else { - retval = -1; + result = false; } } - return retval; + return result; } static void UpdatePixelClipRect(SDL_Renderer *renderer, SDL_RenderViewState *view) @@ -471,10 +471,10 @@ static void UpdatePixelClipRect(SDL_Renderer *renderer, SDL_RenderViewState *vie view->pixel_clip_rect.h = (int)SDL_ceilf(view->clip_rect.h * view->scale.y); } -static int QueueCmdSetClipRect(SDL_Renderer *renderer) +static bool QueueCmdSetClipRect(SDL_Renderer *renderer) { SDL_Rect clip_rect; - int retval = 0; + bool result = true; clip_rect = renderer->view->pixel_clip_rect; @@ -490,15 +490,15 @@ static int QueueCmdSetClipRect(SDL_Renderer *renderer) renderer->last_queued_cliprect_enabled = renderer->view->clipping_enabled; renderer->cliprect_queued = true; } else { - retval = -1; + result = false; } } - return retval; + return result; } -static int QueueCmdSetDrawColor(SDL_Renderer *renderer, SDL_FColor *color) +static bool QueueCmdSetDrawColor(SDL_Renderer *renderer, SDL_FColor *color) { - int retval = 0; + bool result = true; if (!renderer->color_queued || color->r != renderer->last_queued_color.r || @@ -506,15 +506,15 @@ static int QueueCmdSetDrawColor(SDL_Renderer *renderer, SDL_FColor *color) color->b != renderer->last_queued_color.b || color->a != renderer->last_queued_color.a) { SDL_RenderCommand *cmd = AllocateRenderCommand(renderer); - retval = -1; + result = false; if (cmd) { cmd->command = SDL_RENDERCMD_SETDRAWCOLOR; cmd->data.color.first = 0; // render backend will fill this in. cmd->data.color.color_scale = renderer->color_scale; cmd->data.color.color = *color; - retval = renderer->QueueSetDrawColor(renderer, cmd); - if (retval < 0) { + result = renderer->QueueSetDrawColor(renderer, cmd); + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } else { renderer->last_queued_color = *color; @@ -522,27 +522,27 @@ static int QueueCmdSetDrawColor(SDL_Renderer *renderer, SDL_FColor *color) } } } - return retval; + return result; } -static int QueueCmdClear(SDL_Renderer *renderer) +static bool QueueCmdClear(SDL_Renderer *renderer) { SDL_RenderCommand *cmd = AllocateRenderCommand(renderer); if (!cmd) { - return -1; + return false; } cmd->command = SDL_RENDERCMD_CLEAR; cmd->data.color.first = 0; cmd->data.color.color_scale = renderer->color_scale; cmd->data.color.color = renderer->color; - return 0; + return true; } static SDL_RenderCommand *PrepQueueCmdDraw(SDL_Renderer *renderer, const SDL_RenderCommandType cmdtype, SDL_Texture *texture) { SDL_RenderCommand *cmd = NULL; - int retval = 0; + bool result = true; SDL_FColor *color; SDL_BlendMode blendMode; @@ -555,19 +555,19 @@ static SDL_RenderCommand *PrepQueueCmdDraw(SDL_Renderer *renderer, const SDL_Ren } if (cmdtype != SDL_RENDERCMD_GEOMETRY) { - retval = QueueCmdSetDrawColor(renderer, color); + result = QueueCmdSetDrawColor(renderer, color); } /* Set the viewport and clip rect directly before draws, so the backends * don't have to worry about that state not being valid at draw time. */ - if (retval == 0 && !renderer->viewport_queued) { - retval = QueueCmdSetViewport(renderer); + if (result && !renderer->viewport_queued) { + result = QueueCmdSetViewport(renderer); } - if (retval == 0 && !renderer->cliprect_queued) { - retval = QueueCmdSetClipRect(renderer); + if (result && !renderer->cliprect_queued) { + result = QueueCmdSetClipRect(renderer); } - if (retval == 0) { + if (result) { cmd = AllocateRenderCommand(renderer); if (cmd) { cmd->command = cmdtype; @@ -583,36 +583,36 @@ static SDL_RenderCommand *PrepQueueCmdDraw(SDL_Renderer *renderer, const SDL_Ren return cmd; } -static int QueueCmdDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, const int count) +static bool QueueCmdDrawPoints(SDL_Renderer *renderer, const SDL_FPoint *points, const int count) { SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_DRAW_POINTS, NULL); - int retval = -1; + bool result = false; if (cmd) { - retval = renderer->QueueDrawPoints(renderer, cmd, points, count); - if (retval < 0) { + result = renderer->QueueDrawPoints(renderer, cmd, points, count); + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } } - return retval; + return result; } -static int QueueCmdDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, const int count) +static bool QueueCmdDrawLines(SDL_Renderer *renderer, const SDL_FPoint *points, const int count) { SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_DRAW_LINES, NULL); - int retval = -1; + bool result = false; if (cmd) { - retval = renderer->QueueDrawLines(renderer, cmd, points, count); - if (retval < 0) { + result = renderer->QueueDrawLines(renderer, cmd, points, count); + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } } - return retval; + return result; } -static int QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, const int count) +static bool QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, const int count) { SDL_RenderCommand *cmd; - int retval = -1; + bool result = false; const int use_rendergeometry = (!renderer->QueueFillRects); cmd = PrepQueueCmdDraw(renderer, (use_rendergeometry ? SDL_RENDERCMD_GEOMETRY : SDL_RENDERCMD_FILL_RECTS), NULL); @@ -661,12 +661,12 @@ static int QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, con cur_index += 4; } - retval = renderer->QueueGeometry(renderer, cmd, NULL, + result = renderer->QueueGeometry(renderer, cmd, NULL, xy, xy_stride, &renderer->color, 0 /* color_stride */, NULL, 0, num_vertices, indices, num_indices, size_indices, 1.0f, 1.0f); - if (retval < 0) { + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } } @@ -674,44 +674,44 @@ static int QueueCmdFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, con SDL_small_free(indices, isstack2); } else { - retval = renderer->QueueFillRects(renderer, cmd, rects, count); - if (retval < 0) { + result = renderer->QueueFillRects(renderer, cmd, rects, count); + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } } } - return retval; + return result; } -static int QueueCmdCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) +static bool QueueCmdCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) { SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_COPY, texture); - int retval = -1; + bool result = false; if (cmd) { - retval = renderer->QueueCopy(renderer, cmd, texture, srcrect, dstrect); - if (retval < 0) { + result = renderer->QueueCopy(renderer, cmd, texture, srcrect, dstrect); + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } } - return retval; + return result; } -static int QueueCmdCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, +static bool QueueCmdCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y) { SDL_RenderCommand *cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_COPY_EX, texture); - int retval = -1; + bool result = false; if (cmd) { - retval = renderer->QueueCopyEx(renderer, cmd, texture, srcquad, dstrect, angle, center, flip, scale_x, scale_y); - if (retval < 0) { + result = renderer->QueueCopyEx(renderer, cmd, texture, srcquad, dstrect, angle, center, flip, scale_x, scale_y); + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } } - return retval; + return result; } -static int QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture, +static bool QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, @@ -720,21 +720,21 @@ static int QueueCmdGeometry(SDL_Renderer *renderer, SDL_Texture *texture, float scale_x, float scale_y, SDL_TextureAddressMode texture_address_mode) { SDL_RenderCommand *cmd; - int retval = -1; + bool result = false; cmd = PrepQueueCmdDraw(renderer, SDL_RENDERCMD_GEOMETRY, texture); if (cmd) { cmd->data.draw.texture_address_mode = texture_address_mode; - retval = renderer->QueueGeometry(renderer, cmd, texture, + result = renderer->QueueGeometry(renderer, cmd, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices, scale_x, scale_y); - if (retval < 0) { + if (!result) { cmd->command = SDL_RENDERCMD_NO_OP; } } - return retval; + return result; } static void UpdateMainViewDimensions(SDL_Renderer *renderer) @@ -791,7 +791,7 @@ static void UpdateHDRProperties(SDL_Renderer *renderer) renderer->color_scale *= renderer->SDR_white_point; } -static int UpdateLogicalPresentation(SDL_Renderer *renderer); +static bool UpdateLogicalPresentation(SDL_Renderer *renderer); int SDL_GetNumRenderDrivers(void) @@ -858,7 +858,7 @@ static SDL_bool SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event) return true; } -int SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer) +SDL_bool SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_WindowFlags window_flags, SDL_Window **window, SDL_Renderer **renderer) { bool hidden = (window_flags & SDL_WINDOW_HIDDEN) != 0; @@ -875,21 +875,21 @@ int SDL_CreateWindowAndRenderer(const char *title, int width, int height, SDL_Wi *window = SDL_CreateWindow(title, width, height, window_flags); if (!*window) { *renderer = NULL; - return -1; + return false; } *renderer = SDL_CreateRenderer(*window, NULL); if (!*renderer) { SDL_DestroyWindow(*window); *window = NULL; - return -1; + return false; } if (!hidden) { SDL_ShowWindow(*window); } - return 0; + return true; } #ifndef SDL_RENDER_DISABLED @@ -963,7 +963,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) SDL_PropertiesID new_props; #ifdef SDL_PLATFORM_ANDROID - if (Android_WaitActiveAndLockActivity() < 0) { + if (!Android_WaitActiveAndLockActivity()) { return NULL; } #endif @@ -997,15 +997,15 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) if (surface) { #if SDL_VIDEO_RENDER_SW - const int rc = SW_CreateRendererForSurface(renderer, surface, props); + const bool rc = SW_CreateRendererForSurface(renderer, surface, props); #else - const int rc = SDL_SetError("SDL not built with software renderer"); + const bool rc = SDL_SetError("SDL not built with software renderer"); #endif - if (rc < 0) { + if (!rc) { goto error; } } else { - int rc = -1; + bool rc = false; if (!name) { name = SDL_GetHint(SDL_HINT_RENDER_DRIVER); } @@ -1026,7 +1026,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) // Create a new renderer instance ++attempted; rc = driver->CreateRenderer(renderer, window, props); - if (rc == 0) { + if (rc) { break; // Yay, we got one! } SDL_DestroyRendererWithoutFreeing(renderer); @@ -1034,7 +1034,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) } } - if (rc < 0) { + if (!rc) { if (!name || !attempted) { SDL_SetError("Couldn't find matching render driver"); } @@ -1117,7 +1117,7 @@ SDL_Renderer *SDL_CreateRendererWithProperties(SDL_PropertiesID props) } int vsync = (int)SDL_GetNumberProperty(props, SDL_PROP_RENDERER_CREATE_PRESENT_VSYNC_NUMBER, 0); - if (SDL_SetRenderVSync(renderer, vsync) < 0) { + if (!SDL_SetRenderVSync(renderer, vsync)) { if (vsync == 0) { // Some renderers require vsync enabled SDL_SetRenderVSync(renderer, 1); @@ -1215,7 +1215,7 @@ SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer) return renderer->props; } -int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) +SDL_bool SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) { if (w) { *w = 0; @@ -1224,7 +1224,7 @@ int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) *h = 0; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (renderer->GetOutputSize) { return renderer->GetOutputSize(renderer, w, h); @@ -1236,7 +1236,7 @@ int SDL_GetRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) } } -int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) +SDL_bool SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) { if (w) { *w = 0; @@ -1245,7 +1245,7 @@ int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) *h = 0; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (w) { *w = renderer->view->pixel_w; @@ -1253,7 +1253,7 @@ int SDL_GetCurrentRenderOutputSize(SDL_Renderer *renderer, int *w, int *h) if (h) { *h = renderer->view->pixel_h; } - return 0; + return true; } static bool IsSupportedBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode) @@ -1400,7 +1400,7 @@ SDL_Texture *SDL_CreateTextureWithProperties(SDL_Renderer *renderer, SDL_Propert texture_is_fourcc_and_target = (access == SDL_TEXTUREACCESS_TARGET && SDL_ISPIXELFORMAT_FOURCC(format)); if (!texture_is_fourcc_and_target && IsSupportedFormat(renderer, format)) { - if (renderer->CreateTexture(renderer, texture, props) < 0) { + if (!renderer->CreateTexture(renderer, texture, props)) { SDL_DestroyTexture(texture); return NULL; } @@ -1495,7 +1495,7 @@ SDL_Texture *SDL_CreateTexture(SDL_Renderer *renderer, SDL_PixelFormat format, S return texture; } -static int SDL_UpdateTextureFromSurface(SDL_Texture *texture, SDL_Rect *rect, SDL_Surface *surface) +static bool SDL_UpdateTextureFromSurface(SDL_Texture *texture, SDL_Rect *rect, SDL_Surface *surface) { SDL_TextureAccess access; bool direct_update; @@ -1506,24 +1506,24 @@ static int SDL_UpdateTextureFromSurface(SDL_Texture *texture, SDL_Rect *rect, SD SDL_Colorspace texture_colorspace = SDL_COLORSPACE_UNKNOWN; if (texture == NULL || surface == NULL) { - return -1; + return false; } tex_props = SDL_GetTextureProperties(texture); if (!tex_props) { - return -1; + return false; } surface_props = SDL_GetSurfaceProperties(surface); if (!surface_props) { - return -1; + return false; } tex_format = (SDL_PixelFormat)SDL_GetNumberProperty(tex_props, SDL_PROP_TEXTURE_FORMAT_NUMBER, 0); access = (SDL_TextureAccess)SDL_GetNumberProperty(tex_props, SDL_PROP_TEXTURE_ACCESS_NUMBER, 0); if (access != SDL_TEXTUREACCESS_STATIC && access != SDL_TEXTUREACCESS_STREAMING) { - return -1; + return false; } surface_colorspace = SDL_GetSurfaceColorspace(surface); @@ -1571,7 +1571,7 @@ static int SDL_UpdateTextureFromSurface(SDL_Texture *texture, SDL_Rect *rect, SD SDL_UpdateTexture(texture, NULL, temp->pixels, temp->pitch); SDL_DestroySurface(temp); } else { - return -1; + return false; } } @@ -1594,7 +1594,7 @@ static int SDL_UpdateTextureFromSurface(SDL_Texture *texture, SDL_Rect *rect, SD } } - return 0; + return true; } SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *surface) @@ -1724,7 +1724,7 @@ SDL_Texture *SDL_CreateTextureFromSurface(SDL_Renderer *renderer, SDL_Surface *s return NULL; } - if (SDL_UpdateTextureFromSurface(texture, NULL, surface) < 0) { + if (!SDL_UpdateTextureFromSurface(texture, NULL, surface)) { SDL_DestroyTexture(texture); return NULL; } @@ -1749,7 +1749,7 @@ SDL_PropertiesID SDL_GetTextureProperties(SDL_Texture *texture) return texture->props; } -int SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h) +SDL_bool SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h) { if (w) { *w = 0; @@ -1758,7 +1758,7 @@ int SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h) *h = 0; } - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (w) { *w = (float)texture->w; @@ -1766,10 +1766,10 @@ int SDL_GetTextureSize(SDL_Texture *texture, float *w, float *h) if (h) { *h = (float)texture->h; } - return 0; + return true; } -int SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b) +SDL_bool SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b) { const float fR = (float)r / 255.0f; const float fG = (float)g / 255.0f; @@ -1778,9 +1778,9 @@ int SDL_SetTextureColorMod(SDL_Texture *texture, Uint8 r, Uint8 g, Uint8 b) return SDL_SetTextureColorModFloat(texture, fR, fG, fB); } -int SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b) +SDL_bool SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b) { - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); texture->color.r = r; texture->color.g = g; @@ -1788,14 +1788,14 @@ int SDL_SetTextureColorModFloat(SDL_Texture *texture, float r, float g, float b) if (texture->native) { return SDL_SetTextureColorModFloat(texture->native, r, g, b); } - return 0; + return true; } -int SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b) +SDL_bool SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b) { float fR = 1.0f, fG = 1.0f, fB = 1.0f; - if (SDL_GetTextureColorModFloat(texture, &fR, &fG, &fB) < 0) { + if (!SDL_GetTextureColorModFloat(texture, &fR, &fG, &fB)) { if (r) { *r = 255; } @@ -1805,7 +1805,7 @@ int SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b) if (b) { *b = 255; } - return -1; + return false; } if (r) { @@ -1817,10 +1817,10 @@ int SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b) if (b) { *b = (Uint8)(fB * 255.0f); } - return 0; + return true; } -int SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b) +SDL_bool SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b) { SDL_FColor color; @@ -1834,7 +1834,7 @@ int SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float *b = 1.0f; } - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); color = texture->color; @@ -1847,63 +1847,63 @@ int SDL_GetTextureColorModFloat(SDL_Texture *texture, float *r, float *g, float if (b) { *b = color.b; } - return 0; + return true; } -int SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha) +SDL_bool SDL_SetTextureAlphaMod(SDL_Texture *texture, Uint8 alpha) { const float fA = (float)alpha / 255.0f; return SDL_SetTextureAlphaModFloat(texture, fA); } -int SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha) +SDL_bool SDL_SetTextureAlphaModFloat(SDL_Texture *texture, float alpha) { - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); texture->color.a = alpha; if (texture->native) { return SDL_SetTextureAlphaModFloat(texture->native, alpha); } - return 0; + return true; } -int SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha) +SDL_bool SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha) { float fA = 1.0f; - if (SDL_GetTextureAlphaModFloat(texture, &fA) < 0) { + if (!SDL_GetTextureAlphaModFloat(texture, &fA)) { if (alpha) { *alpha = 255; } - return -1; + return false; } if (alpha) { *alpha = (Uint8)(fA * 255.0f); } - return 0; + return true; } -int SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha) +SDL_bool SDL_GetTextureAlphaModFloat(SDL_Texture *texture, float *alpha) { if (alpha) { *alpha = 1.0f; } - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (alpha) { *alpha = texture->color.a; } - return 0; + return true; } -int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode) +SDL_bool SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode) { SDL_Renderer *renderer; - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (blendMode == SDL_BLENDMODE_INVALID) { return SDL_InvalidParamError("blendMode"); @@ -1917,28 +1917,28 @@ int SDL_SetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode blendMode) if (texture->native) { return SDL_SetTextureBlendMode(texture->native, blendMode); } - return 0; + return true; } -int SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode) +SDL_bool SDL_GetTextureBlendMode(SDL_Texture *texture, SDL_BlendMode *blendMode) { if (blendMode) { *blendMode = SDL_BLENDMODE_INVALID; } - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (blendMode) { *blendMode = texture->blendMode; } - return 0; + return true; } -int SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode) +SDL_bool SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode) { SDL_Renderer *renderer; - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); renderer = texture->renderer; texture->scaleMode = scaleMode; @@ -1947,32 +1947,32 @@ int SDL_SetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode scaleMode) } else { renderer->SetTextureScaleMode(renderer, texture, scaleMode); } - return 0; + return true; } -int SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode) +SDL_bool SDL_GetTextureScaleMode(SDL_Texture *texture, SDL_ScaleMode *scaleMode) { if (scaleMode) { *scaleMode = SDL_SCALEMODE_LINEAR; } - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (scaleMode) { *scaleMode = texture->scaleMode; } - return 0; + return true; } #if SDL_HAVE_YUV -static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, +static bool SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { SDL_Texture *native = texture->native; SDL_Rect full_rect; - if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) { - return -1; + if (!SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch)) { + return false; } full_rect.x = 0; @@ -1986,8 +1986,8 @@ static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, void *native_pixels = NULL; int native_pitch = 0; - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; + if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { + return false; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, native_pixels, native_pitch); @@ -1999,7 +1999,7 @@ static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return -1; + return false; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -2007,17 +2007,17 @@ static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, SDL_free(temp_pixels); } } - return 0; + return true; } #endif // SDL_HAVE_YUV -static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, +static bool SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { SDL_Texture *native = texture->native; if (!rect->w || !rect->h) { - return 0; // nothing to do. + return true; // nothing to do. } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -2025,8 +2025,8 @@ static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, void *native_pixels = NULL; int native_pitch = 0; - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; + if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { + return false; } SDL_ConvertPixels(rect->w, rect->h, texture->format, pixels, pitch, @@ -2039,7 +2039,7 @@ static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return -1; + return false; } SDL_ConvertPixels(rect->w, rect->h, texture->format, pixels, pitch, @@ -2048,14 +2048,14 @@ static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect, SDL_free(temp_pixels); } } - return 0; + return true; } -int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) +SDL_bool SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { SDL_Rect real_rect; - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (!pixels) { return SDL_InvalidParamError("pixels"); @@ -2070,12 +2070,12 @@ int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pi real_rect.h = texture->h; if (rect) { if (!SDL_GetRectIntersection(rect, &real_rect, &real_rect)) { - return 0; + return true; } } if (real_rect.w == 0 || real_rect.h == 0) { - return 0; // nothing to do. + return true; // nothing to do. #if SDL_HAVE_YUV } else if (texture->yuv) { return SDL_UpdateTextureYUV(texture, &real_rect, pixels, pitch); @@ -2084,15 +2084,15 @@ int SDL_UpdateTexture(SDL_Texture *texture, const SDL_Rect *rect, const void *pi return SDL_UpdateTextureNative(texture, &real_rect, pixels, pitch); } else { SDL_Renderer *renderer = texture->renderer; - if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { - return -1; + if (!FlushRenderCommandsIfTextureNeeded(texture)) { + return false; } return renderer->UpdateTexture(renderer, texture, &real_rect, pixels, pitch); } } #if SDL_HAVE_YUV -static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect, +static bool SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch) @@ -2100,8 +2100,8 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect SDL_Texture *native = texture->native; SDL_Rect full_rect; - if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) { - return -1; + if (!SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch)) { + return false; } full_rect.x = 0; @@ -2111,7 +2111,7 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect rect = &full_rect; if (!rect->w || !rect->h) { - return 0; // nothing to do. + return true; // nothing to do. } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -2119,8 +2119,8 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect void *native_pixels = NULL; int native_pitch = 0; - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; + if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { + return false; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, native_pixels, native_pitch); @@ -2132,7 +2132,7 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return -1; + return false; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -2140,18 +2140,18 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect SDL_free(temp_pixels); } } - return 0; + return true; } -static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, +static bool SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) { SDL_Texture *native = texture->native; SDL_Rect full_rect; - if (SDL_SW_UpdateNVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, UVplane, UVpitch) < 0) { - return -1; + if (!SDL_SW_UpdateNVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, UVplane, UVpitch)) { + return false; } full_rect.x = 0; @@ -2161,7 +2161,7 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, rect = &full_rect; if (!rect->w || !rect->h) { - return 0; // nothing to do. + return true; // nothing to do. } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -2169,8 +2169,8 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, void *native_pixels = NULL; int native_pitch = 0; - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { - return -1; + if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { + return false; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, native_pixels, native_pitch); @@ -2182,7 +2182,7 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, if (alloclen > 0) { void *temp_pixels = SDL_malloc(alloclen); if (!temp_pixels) { - return -1; + return false; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); @@ -2190,12 +2190,12 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect, SDL_free(temp_pixels); } } - return 0; + return true; } #endif // SDL_HAVE_YUV -int SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, +SDL_bool SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch) @@ -2204,7 +2204,7 @@ int SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, SDL_Renderer *renderer; SDL_Rect real_rect; - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (!Yplane) { return SDL_InvalidParamError("Yplane"); @@ -2239,7 +2239,7 @@ int SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, } if (real_rect.w == 0 || real_rect.h == 0) { - return 0; // nothing to do. + return true; // nothing to do. } if (texture->yuv) { @@ -2249,8 +2249,8 @@ int SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, renderer = texture->renderer; SDL_assert(renderer->UpdateTextureYUV); if (renderer->UpdateTextureYUV) { - if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { - return -1; + if (!FlushRenderCommandsIfTextureNeeded(texture)) { + return false; } return renderer->UpdateTextureYUV(renderer, texture, &real_rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); } else { @@ -2258,11 +2258,11 @@ int SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, } } #else - return -1; + return false; #endif } -int SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, +SDL_bool SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) { @@ -2270,7 +2270,7 @@ int SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, SDL_Renderer *renderer; SDL_Rect real_rect; - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (!Yplane) { return SDL_InvalidParamError("Yplane"); @@ -2299,7 +2299,7 @@ int SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, } if (real_rect.w == 0 || real_rect.h == 0) { - return 0; // nothing to do. + return true; // nothing to do. } if (texture->yuv) { @@ -2309,8 +2309,8 @@ int SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, renderer = texture->renderer; SDL_assert(renderer->UpdateTextureNV); if (renderer->UpdateTextureNV) { - if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { - return -1; + if (!FlushRenderCommandsIfTextureNeeded(texture)) { + return false; } return renderer->UpdateTextureNV(renderer, texture, &real_rect, Yplane, Ypitch, UVplane, UVpitch); } else { @@ -2318,19 +2318,19 @@ int SDL_UpdateNVTexture(SDL_Texture *texture, const SDL_Rect *rect, } } #else - return -1; + return false; #endif } #if SDL_HAVE_YUV -static int SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, +static bool SDL_LockTextureYUV(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch); } #endif // SDL_HAVE_YUV -static int SDL_LockTextureNative(SDL_Texture *texture, const SDL_Rect *rect, +static bool SDL_LockTextureNative(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { texture->locked_rect = *rect; @@ -2338,14 +2338,14 @@ static int SDL_LockTextureNative(SDL_Texture *texture, const SDL_Rect *rect, rect->y * texture->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = texture->pitch; - return 0; + return true; } -int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) +SDL_bool SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { SDL_Rect full_rect; - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (texture->access != SDL_TEXTUREACCESS_STREAMING) { return SDL_SetError("SDL_LockTexture(): texture must be streaming"); @@ -2361,8 +2361,8 @@ int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, i #if SDL_HAVE_YUV if (texture->yuv) { - if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { - return -1; + if (!FlushRenderCommandsIfTextureNeeded(texture)) { + return false; } return SDL_LockTextureYUV(texture, rect, pixels, pitch); } else @@ -2372,22 +2372,21 @@ int SDL_LockTexture(SDL_Texture *texture, const SDL_Rect *rect, void **pixels, i return SDL_LockTextureNative(texture, rect, pixels, pitch); } else { SDL_Renderer *renderer = texture->renderer; - if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { - return -1; + if (!FlushRenderCommandsIfTextureNeeded(texture)) { + return false; } return renderer->LockTexture(renderer, texture, rect, pixels, pitch); } } -int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Surface **surface) +SDL_bool SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Surface **surface) { SDL_Rect real_rect; void *pixels = NULL; int pitch = 0; // fix static analysis - int ret; if (!texture || !surface) { - return -1; + return false; } real_rect.x = 0; @@ -2398,19 +2397,18 @@ int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, SDL_Sur SDL_GetRectIntersection(rect, &real_rect, &real_rect); } - ret = SDL_LockTexture(texture, &real_rect, &pixels, &pitch); - if (ret < 0) { - return ret; + if (!SDL_LockTexture(texture, &real_rect, &pixels, &pitch)) { + return false; } texture->locked_surface = SDL_CreateSurfaceFrom(real_rect.w, real_rect.h, texture->format, pixels, pitch); if (!texture->locked_surface) { SDL_UnlockTexture(texture); - return -1; + return false; } *surface = texture->locked_surface; - return 0; + return true; } #if SDL_HAVE_YUV @@ -2426,7 +2424,7 @@ static void SDL_UnlockTextureYUV(SDL_Texture *texture) rect.w = texture->w; rect.h = texture->h; - if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) { + if (!SDL_LockTexture(native, &rect, &native_pixels, &native_pitch)) { return; } SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format, @@ -2446,7 +2444,7 @@ static void SDL_UnlockTextureNative(SDL_Texture *texture) rect->x * SDL_BYTESPERPIXEL(texture->format)); int pitch = texture->pitch; - if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { + if (!SDL_LockTexture(native, rect, &native_pixels, &native_pitch)) { return; } SDL_ConvertPixels(rect->w, rect->h, @@ -2478,11 +2476,11 @@ void SDL_UnlockTexture(SDL_Texture *texture) texture->locked_surface = NULL; } -static int SDL_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *texture) +static bool SDL_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *texture) { // texture == NULL is valid and means reset the target to the window if (texture) { - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (renderer != texture->renderer) { return SDL_SetError("Texture was not created with this renderer"); } @@ -2497,7 +2495,7 @@ static int SDL_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *text if (texture == renderer->target) { // Nothing to do! - return 0; + return true; } FlushRenderCommands(renderer); // time to send everything to the GPU! @@ -2511,25 +2509,25 @@ static int SDL_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *text renderer->view = &renderer->main_view; } - if (renderer->SetRenderTarget(renderer, texture) < 0) { + if (!renderer->SetRenderTarget(renderer, texture)) { SDL_UnlockMutex(renderer->target_mutex); - return -1; + return false; } SDL_UnlockMutex(renderer->target_mutex); - if (QueueCmdSetViewport(renderer) < 0) { - return -1; + if (!QueueCmdSetViewport(renderer)) { + return false; } - if (QueueCmdSetClipRect(renderer) < 0) { - return -1; + if (!QueueCmdSetClipRect(renderer)) { + return false; } // All set! - return 0; + return true; } -int SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +SDL_bool SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { if (!texture && renderer->logical_target) { return SDL_SetRenderTargetInternal(renderer, renderer->logical_target); @@ -2549,7 +2547,7 @@ SDL_Texture *SDL_GetRenderTarget(SDL_Renderer *renderer) } } -static int UpdateLogicalPresentation(SDL_Renderer *renderer) +static bool UpdateLogicalPresentation(SDL_Renderer *renderer) { float logical_w = 1.0f, logical_h = 1.0f; float output_w = (float)renderer->main_view.pixel_w; @@ -2560,10 +2558,10 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer) if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED) { // All done! - return 0; + return true; } - if (SDL_GetTextureSize(renderer->logical_target, &logical_w, &logical_h) < 0) { + if (!SDL_GetTextureSize(renderer->logical_target, &logical_w, &logical_h)) { goto error; } @@ -2644,16 +2642,16 @@ static int UpdateLogicalPresentation(SDL_Renderer *renderer) SDL_SetRenderTarget(renderer, renderer->logical_target); } - return 0; + return true; error: SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST); - return -1; + return false; } -int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode) +SDL_bool SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (mode == SDL_LOGICAL_PRESENTATION_DISABLED) { if (renderer->logical_target) { @@ -2689,10 +2687,10 @@ int SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_R error: SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST); - return -1; + return false; } -int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode) +SDL_bool SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode) { if (w) { *w = 0; @@ -2707,12 +2705,12 @@ int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL *scale_mode = SDL_SCALEMODE_NEAREST; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (renderer->logical_target) { SDL_PropertiesID props = SDL_GetTextureProperties(renderer->logical_target); if (!props) { - return -1; + return false; } if (w) { @@ -2730,23 +2728,23 @@ int SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL *scale_mode = renderer->logical_scale_mode; } - return 0; + return true; } -int SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect) +SDL_bool SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect) { if (rect) { SDL_zerop(rect); } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (rect) { if (renderer->logical_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED) { int output_w = 0, output_h = 0; - if (SDL_GetRenderOutputSize(renderer, &output_w, &output_h) < 0) { - return -1; + if (!SDL_GetRenderOutputSize(renderer, &output_w, &output_h)) { + return false; } rect->x = 0.0f; @@ -2757,7 +2755,7 @@ int SDL_GetRenderLogicalPresentationRect(SDL_Renderer *renderer, SDL_FRect *rect SDL_copyp(rect, &renderer->logical_dst_rect); } } - return 0; + return true; } static void SDL_RenderLogicalBorders(SDL_Renderer *renderer) @@ -2814,12 +2812,12 @@ static void SDL_RenderLogicalPresentation(SDL_Renderer *renderer) SDL_RenderTexture(renderer, renderer->logical_target, &renderer->logical_src_rect, &renderer->logical_dst_rect); } -int SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y) +SDL_bool SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, float window_y, float *x, float *y) { SDL_RenderViewState *view; float render_x, render_y; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); // Convert from window coordinates to pixels within the window render_x = window_x * renderer->dpi_scale.x; @@ -2848,14 +2846,14 @@ int SDL_RenderCoordinatesFromWindow(SDL_Renderer *renderer, float window_x, floa if (y) { *y = render_y; } - return 0; + return true; } -int SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y) +SDL_bool SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, float *window_x, float *window_y) { SDL_RenderViewState *view; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); // Convert from render coordinates to pixels within the view if (renderer->logical_target) { @@ -2884,12 +2882,12 @@ int SDL_RenderCoordinatesToWindow(SDL_Renderer *renderer, float x, float y, floa if (window_y) { *window_y = y; } - return 0; + return true; } -int SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event) +SDL_bool SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (event->type == SDL_EVENT_MOUSE_MOTION) { SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID); @@ -2963,8 +2961,8 @@ int SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event // FIXME: Are these events guaranteed to be window relative? if (renderer->window) { int w, h; - if (SDL_GetWindowSize(renderer->window, &w, &h) < 0) { - return -1; + if (!SDL_GetWindowSize(renderer->window, &w, &h)) { + return false; } SDL_RenderCoordinatesFromWindow(renderer, event->tfinger.x * w, event->tfinger.y * h, &event->tfinger.x, &event->tfinger.y); } @@ -2977,12 +2975,12 @@ int SDL_ConvertEventToRenderCoordinates(SDL_Renderer *renderer, SDL_Event *event SDL_RenderCoordinatesFromWindow(renderer, event->drop.x, event->drop.y, &event->drop.x, &event->drop.y); } } - return 0; + return true; } -int SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect) +SDL_bool SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (rect) { SDL_copyp(&renderer->view->viewport, rect); @@ -2997,13 +2995,13 @@ int SDL_SetRenderViewport(SDL_Renderer *renderer, const SDL_Rect *rect) return QueueCmdSetViewport(renderer); } -int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect) +SDL_bool SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect) { if (rect) { SDL_zerop(rect); } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (rect) { rect->x = renderer->view->viewport.x; @@ -3019,12 +3017,12 @@ int SDL_GetRenderViewport(SDL_Renderer *renderer, SDL_Rect *rect) rect->h = (int)SDL_ceilf(renderer->view->pixel_h / renderer->view->scale.y); } } - return 0; + return true; } SDL_bool SDL_RenderViewportSet(SDL_Renderer *renderer) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (renderer->view->viewport.w >= 0 && renderer->view->viewport.h >= 0) { @@ -3049,13 +3047,13 @@ static void GetRenderViewportSize(SDL_Renderer *renderer, SDL_FRect *rect) } } -int SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect) +SDL_bool SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect) { if (rect) { SDL_zerop(rect); } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (renderer->target || !renderer->window) { // The entire viewport is safe for rendering @@ -3065,8 +3063,8 @@ int SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect) if (rect) { // Get the window safe rect SDL_Rect safe; - if (SDL_GetWindowSafeArea(renderer->window, &safe) < 0) { - return -1; + if (!SDL_GetWindowSafeArea(renderer->window, &safe)) { + return false; } // Convert the coordinates into the render space @@ -3074,9 +3072,9 @@ int SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect) float miny = (float)safe.y; float maxx = (float)safe.x + safe.w; float maxy = (float)safe.y + safe.h; - if (SDL_RenderCoordinatesFromWindow(renderer, minx, miny, &minx, &miny) < 0 || - SDL_RenderCoordinatesFromWindow(renderer, maxx, maxy, &maxx, &maxy) < 0) { - return -1; + if (!SDL_RenderCoordinatesFromWindow(renderer, minx, miny, &minx, &miny) || + !SDL_RenderCoordinatesFromWindow(renderer, maxx, maxy, &maxx, &maxy)) { + return false; } rect->x = (int)SDL_ceilf(minx); @@ -3086,19 +3084,19 @@ int SDL_GetRenderSafeArea(SDL_Renderer *renderer, SDL_Rect *rect) // Clip with the viewport SDL_Rect viewport; - if (SDL_GetRenderViewport(renderer, &viewport) < 0) { - return -1; + if (!SDL_GetRenderViewport(renderer, &viewport)) { + return false; } if (!SDL_GetRectIntersection(rect, &viewport, rect)) { return SDL_SetError("No safe area within viewport"); } } - return 0; + return true; } -int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect) +SDL_bool SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect) { - CHECK_RENDERER_MAGIC(renderer, -1) + CHECK_RENDERER_MAGIC(renderer, false) if (rect && rect->w >= 0 && rect->h >= 0) { renderer->view->clipping_enabled = true; @@ -3112,18 +3110,18 @@ int SDL_SetRenderClipRect(SDL_Renderer *renderer, const SDL_Rect *rect) return QueueCmdSetClipRect(renderer); } -int SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect) +SDL_bool SDL_GetRenderClipRect(SDL_Renderer *renderer, SDL_Rect *rect) { if (rect) { SDL_zerop(rect); } - CHECK_RENDERER_MAGIC(renderer, -1) + CHECK_RENDERER_MAGIC(renderer, false) if (rect) { SDL_copyp(rect, &renderer->view->clip_rect); } - return 0; + return true; } SDL_bool SDL_RenderClipEnabled(SDL_Renderer *renderer) @@ -3132,15 +3130,15 @@ SDL_bool SDL_RenderClipEnabled(SDL_Renderer *renderer) return renderer->view->clipping_enabled; } -int SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY) +SDL_bool SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY) { - int retval = 0; + bool result = true; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (renderer->view->scale.x == scaleX && renderer->view->scale.y == scaleY) { - return 0; + return true; } renderer->view->scale.x = scaleX; @@ -3149,12 +3147,12 @@ int SDL_SetRenderScale(SDL_Renderer *renderer, float scaleX, float scaleY) UpdatePixelClipRect(renderer, renderer->view); // The scale affects the existing viewport and clip rectangle - retval += QueueCmdSetViewport(renderer); - retval += QueueCmdSetClipRect(renderer); - return retval; + result &= QueueCmdSetViewport(renderer); + result &= QueueCmdSetClipRect(renderer); + return result; } -int SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY) +SDL_bool SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY) { if (scaleX) { *scaleX = 1.0f; @@ -3163,7 +3161,7 @@ int SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY) *scaleY = 1.0f; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (scaleX) { *scaleX = renderer->view->scale.x; @@ -3171,10 +3169,10 @@ int SDL_GetRenderScale(SDL_Renderer *renderer, float *scaleX, float *scaleY) if (scaleY) { *scaleY = renderer->view->scale.y; } - return 0; + return true; } -int SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +SDL_bool SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { const float fR = (float)r / 255.0f; const float fG = (float)g / 255.0f; @@ -3184,22 +3182,22 @@ int SDL_SetRenderDrawColor(SDL_Renderer *renderer, Uint8 r, Uint8 g, Uint8 b, Ui return SDL_SetRenderDrawColorFloat(renderer, fR, fG, fB, fA); } -int SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a) +SDL_bool SDL_SetRenderDrawColorFloat(SDL_Renderer *renderer, float r, float g, float b, float a) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); renderer->color.r = r; renderer->color.g = g; renderer->color.b = b; renderer->color.a = a; - return 0; + return true; } -int SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) +SDL_bool SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) { float fR, fG, fB, fA; - if (SDL_GetRenderDrawColorFloat(renderer, &fR, &fG, &fB, &fA) < 0) { + if (!SDL_GetRenderDrawColorFloat(renderer, &fR, &fG, &fB, &fA)) { if (r) { *r = 0; } @@ -3212,7 +3210,7 @@ int SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, if (a) { *a = 0; } - return -1; + return false; } if (r) { @@ -3227,10 +3225,10 @@ int SDL_GetRenderDrawColor(SDL_Renderer *renderer, Uint8 *r, Uint8 *g, Uint8 *b, if (a) { *a = (Uint8)(fA * 255.0f); } - return 0; + return true; } -int SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a) +SDL_bool SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, float *b, float *a) { SDL_FColor color; @@ -3247,7 +3245,7 @@ int SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, floa *a = 0.0f; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); color = renderer->color; @@ -3263,34 +3261,34 @@ int SDL_GetRenderDrawColorFloat(SDL_Renderer *renderer, float *r, float *g, floa if (a) { *a = color.a; } - return 0; + return true; } -int SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale) +SDL_bool SDL_SetRenderColorScale(SDL_Renderer *renderer, float scale) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); renderer->color_scale = scale * renderer->SDR_white_point; - return 0; + return true; } -int SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale) +SDL_bool SDL_GetRenderColorScale(SDL_Renderer *renderer, float *scale) { if (scale) { *scale = 1.0f; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (scale) { *scale = renderer->color_scale / renderer->SDR_white_point; } - return 0; + return true; } -int SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode) +SDL_bool SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (blendMode == SDL_BLENDMODE_INVALID) { return SDL_InvalidParamError("blendMode"); @@ -3305,31 +3303,31 @@ int SDL_SetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode) } renderer->blendMode = blendMode; - return 0; + return true; } -int SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode) +SDL_bool SDL_GetRenderDrawBlendMode(SDL_Renderer *renderer, SDL_BlendMode *blendMode) { if (blendMode) { *blendMode = SDL_BLENDMODE_INVALID; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (blendMode) { *blendMode = renderer->blendMode; } - return 0; + return true; } -int SDL_RenderClear(SDL_Renderer *renderer) +SDL_bool SDL_RenderClear(SDL_Renderer *renderer) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); return QueueCmdClear(renderer); } -int SDL_RenderPoint(SDL_Renderer *renderer, float x, float y) +SDL_bool SDL_RenderPoint(SDL_Renderer *renderer, float x, float y) { SDL_FPoint fpoint; fpoint.x = x; @@ -3337,20 +3335,20 @@ int SDL_RenderPoint(SDL_Renderer *renderer, float x, float y) return SDL_RenderPoints(renderer, &fpoint, 1); } -static int RenderPointsWithRects(SDL_Renderer *renderer, const SDL_FPoint *fpoints, const int count) +static bool RenderPointsWithRects(SDL_Renderer *renderer, const SDL_FPoint *fpoints, const int count) { - int retval; + bool result; bool isstack; SDL_FRect *frects; int i; if (count < 1) { - return 0; + return true; } frects = SDL_small_alloc(SDL_FRect, count, &isstack); if (!frects) { - return -1; + return false; } for (i = 0; i < count; ++i) { @@ -3360,42 +3358,42 @@ static int RenderPointsWithRects(SDL_Renderer *renderer, const SDL_FPoint *fpoin frects[i].h = renderer->view->scale.y; } - retval = QueueCmdFillRects(renderer, frects, count); + result = QueueCmdFillRects(renderer, frects, count); SDL_small_free(frects, isstack); - return retval; + return result; } -int SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count) +SDL_bool SDL_RenderPoints(SDL_Renderer *renderer, const SDL_FPoint *points, int count) { - int retval; + bool result; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (!points) { return SDL_InvalidParamError("SDL_RenderPoints(): points"); } if (count < 1) { - return 0; + return true; } #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif if (renderer->view->scale.x != 1.0f || renderer->view->scale.y != 1.0f) { - retval = RenderPointsWithRects(renderer, points, count); + result = RenderPointsWithRects(renderer, points, count); } else { - retval = QueueCmdDrawPoints(renderer, points, count); + result = QueueCmdDrawPoints(renderer, points, count); } - return retval; + return result; } -int SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2) +SDL_bool SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y2) { SDL_FPoint points[2]; points[0].x = x1; @@ -3405,14 +3403,14 @@ int SDL_RenderLine(SDL_Renderer *renderer, float x1, float y1, float x2, float y return SDL_RenderLines(renderer, points, 2); } -static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, int y2, bool draw_last) +static bool RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, int y2, bool draw_last) { const int MAX_PIXELS = SDL_max(renderer->view->pixel_w, renderer->view->pixel_h) * 4; int i, deltax, deltay, numpixels; int d, dinc1, dinc2; int x, xinc1, xinc2; int y, yinc1, yinc2; - int retval; + bool result; bool isstack; SDL_FPoint *points; SDL_Rect viewport; @@ -3424,7 +3422,7 @@ static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, i viewport.x = 0; viewport.y = 0; if (!SDL_GetRectAndLineIntersection(&viewport, &x1, &y1, &x2, &y2)) { - return 0; + return true; } deltax = SDL_abs(x2 - x1); @@ -3472,7 +3470,7 @@ static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, i points = SDL_small_alloc(SDL_FPoint, numpixels, &isstack); if (!points) { - return -1; + return false; } for (i = 0; i < numpixels; ++i) { points[i].x = (float)x; @@ -3490,17 +3488,17 @@ static int RenderLineBresenham(SDL_Renderer *renderer, int x1, int y1, int x2, i } if (renderer->view->scale.x != 1.0f || renderer->view->scale.y != 1.0f) { - retval = RenderPointsWithRects(renderer, points, numpixels); + result = RenderPointsWithRects(renderer, points, numpixels); } else { - retval = QueueCmdDrawPoints(renderer, points, numpixels); + result = QueueCmdDrawPoints(renderer, points, numpixels); } SDL_small_free(points, isstack); - return retval; + return result; } -static int RenderLinesWithRectsF(SDL_Renderer *renderer, +static bool RenderLinesWithRectsF(SDL_Renderer *renderer, const SDL_FPoint *points, const int count) { const float scale_x = renderer->view->scale.x; @@ -3508,14 +3506,14 @@ static int RenderLinesWithRectsF(SDL_Renderer *renderer, SDL_FRect *frect; SDL_FRect *frects; int i, nrects = 0; - int retval = 0; + bool result = true; bool isstack; bool drew_line = false; bool draw_last = false; frects = SDL_small_alloc(SDL_FRect, count - 1, &isstack); if (!frects) { - return -1; + return false; } for (i = 0; i < count - 1; ++i) { @@ -3556,46 +3554,43 @@ static int RenderLinesWithRectsF(SDL_Renderer *renderer, frect->x += scale_x; } } else { - retval += RenderLineBresenham(renderer, (int)SDL_roundf(points[i].x), (int)SDL_roundf(points[i].y), + result &= RenderLineBresenham(renderer, (int)SDL_roundf(points[i].x), (int)SDL_roundf(points[i].y), (int)SDL_roundf(points[i + 1].x), (int)SDL_roundf(points[i + 1].y), draw_last); } drew_line = true; } if (nrects) { - retval += QueueCmdFillRects(renderer, frects, nrects); + result &= QueueCmdFillRects(renderer, frects, nrects); } SDL_small_free(frects, isstack); - if (retval < 0) { - retval = -1; - } - return retval; + return result; } -int SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count) +SDL_bool SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count) { - int retval = 0; + bool result = true; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (!points) { return SDL_InvalidParamError("SDL_RenderLines(): points"); } if (count < 2) { - return 0; + return true; } #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif if (renderer->line_method == SDL_RENDERLINEMETHOD_POINTS) { - retval = RenderLinesWithRectsF(renderer, points, count); + result = RenderLinesWithRectsF(renderer, points, count); } else if (renderer->line_method == SDL_RENDERLINEMETHOD_GEOMETRY) { bool isstack1; bool isstack2; @@ -3707,7 +3702,7 @@ int SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count) cur_index += 4; } - retval = QueueCmdGeometry(renderer, NULL, + result = QueueCmdGeometry(renderer, NULL, xy, xy_stride, &renderer->color, 0 /* color_stride */, NULL, 0, num_vertices, indices, num_indices, size_indices, 1.0f, 1.0f, SDL_TEXTURE_ADDRESS_CLAMP); @@ -3717,20 +3712,20 @@ int SDL_RenderLines(SDL_Renderer *renderer, const SDL_FPoint *points, int count) SDL_small_free(indices, isstack2); } else if (renderer->view->scale.x != 1.0f || renderer->view->scale.y != 1.0f) { - retval = RenderLinesWithRectsF(renderer, points, count); + result = RenderLinesWithRectsF(renderer, points, count); } else { - retval = QueueCmdDrawLines(renderer, points, count); + result = QueueCmdDrawLines(renderer, points, count); } - return retval; + return result; } -int SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect) +SDL_bool SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect) { SDL_FRect frect; SDL_FPoint points[5]; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); // If 'rect' == NULL, then outline the whole surface if (!rect) { @@ -3751,39 +3746,39 @@ int SDL_RenderRect(SDL_Renderer *renderer, const SDL_FRect *rect) return SDL_RenderLines(renderer, points, 5); } -int SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count) +SDL_bool SDL_RenderRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count) { int i; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (!rects) { return SDL_InvalidParamError("SDL_RenderRects(): rects"); } if (count < 1) { - return 0; + return true; } #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif for (i = 0; i < count; ++i) { - if (SDL_RenderRect(renderer, &rects[i]) < 0) { - return -1; + if (!SDL_RenderRect(renderer, &rects[i])) { + return false; } } - return 0; + return true; } -int SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect) +SDL_bool SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect) { SDL_FRect frect; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); // If 'rect' == NULL, then fill the whole surface if (!rect) { @@ -3793,32 +3788,32 @@ int SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_FRect *rect) return SDL_RenderFillRects(renderer, rect, 1); } -int SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count) +SDL_bool SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int count) { SDL_FRect *frects; int i; - int retval; + bool result; bool isstack; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (!rects) { return SDL_InvalidParamError("SDL_RenderFillRects(): rects"); } if (count < 1) { - return 0; + return true; } #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif frects = SDL_small_alloc(SDL_FRect, count, &isstack); if (!frects) { - return -1; + return false; } for (i = 0; i < count; ++i) { frects[i].x = rects[i].x * renderer->view->scale.x; @@ -3827,16 +3822,16 @@ int SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_FRect *rects, int coun frects[i].h = rects[i].h * renderer->view->scale.y; } - retval = QueueCmdFillRects(renderer, frects, count); + result = QueueCmdFillRects(renderer, frects, count); SDL_small_free(frects, isstack); - return retval; + return result; } -static int SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) +static bool SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) { - int retval; + bool result; bool use_rendergeometry = (!renderer->QueueCopy); if (use_rendergeometry) { @@ -3879,7 +3874,7 @@ static int SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *textur xy[6] = minx; xy[7] = maxy; - retval = QueueCmdGeometry(renderer, texture, + result = QueueCmdGeometry(renderer, texture, xy, xy_stride, &texture->color, 0 /* color_stride */, uv, uv_stride, num_vertices, indices, num_indices, size_indices, @@ -3893,18 +3888,18 @@ static int SDL_RenderTextureInternal(SDL_Renderer *renderer, SDL_Texture *textur rect.w = dstrect->w * renderer->view->scale.x; rect.h = dstrect->h * renderer->view->scale.y; - retval = QueueCmdCopy(renderer, texture, srcrect, &rect); + result = QueueCmdCopy(renderer, texture, srcrect, &rect); } - return retval; + return result; } -int SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) +SDL_bool SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) { SDL_FRect real_srcrect; SDL_FRect real_dstrect; - CHECK_RENDERER_MAGIC(renderer, -1); - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_RENDERER_MAGIC(renderer, false); + CHECK_TEXTURE_MAGIC(texture, false); if (renderer != texture->renderer) { return SDL_SetError("Texture was not created with this renderer"); @@ -3913,7 +3908,7 @@ int SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FR #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif @@ -3923,14 +3918,14 @@ int SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FR real_srcrect.h = (float)texture->h; if (srcrect) { if (!SDL_GetRectIntersectionFloat(srcrect, &real_srcrect, &real_srcrect)) { - return 0; + return true; } } GetRenderViewportSize(renderer, &real_dstrect); if (dstrect) { if (!SDL_HasRectIntersectionFloat(dstrect, &real_dstrect)) { - return 0; + return true; } real_dstrect = *dstrect; } @@ -3944,22 +3939,22 @@ int SDL_RenderTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FR return SDL_RenderTextureInternal(renderer, texture, &real_srcrect, &real_dstrect); } -int SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, +SDL_bool SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_FlipMode flip) { SDL_FRect real_srcrect; SDL_FRect real_dstrect; SDL_FPoint real_center; - int retval; + bool result; int use_rendergeometry; if (flip == SDL_FLIP_NONE && (int)(angle / 360) == angle / 360) { // fast path when we don't need rotation or flipping return SDL_RenderTexture(renderer, texture, srcrect, dstrect); } - CHECK_RENDERER_MAGIC(renderer, -1); - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_RENDERER_MAGIC(renderer, false); + CHECK_TEXTURE_MAGIC(texture, false); if (renderer != texture->renderer) { return SDL_SetError("Texture was not created with this renderer"); @@ -3971,7 +3966,7 @@ int SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif @@ -3983,7 +3978,7 @@ int SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, real_srcrect.h = (float)texture->h; if (srcrect) { if (!SDL_GetRectIntersectionFloat(srcrect, &real_srcrect, &real_srcrect)) { - return 0; + return true; } } @@ -4084,7 +4079,7 @@ int SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, xy[6] = (c_minx - s_maxy) + centerx; xy[7] = (s_minx + c_maxy) + centery; - retval = QueueCmdGeometry(renderer, texture, + result = QueueCmdGeometry(renderer, texture, xy, xy_stride, &texture->color, 0 /* color_stride */, uv, uv_stride, num_vertices, indices, num_indices, size_indices, @@ -4092,14 +4087,14 @@ int SDL_RenderTextureRotated(SDL_Renderer *renderer, SDL_Texture *texture, renderer->view->scale.y, SDL_TEXTURE_ADDRESS_CLAMP); } else { - retval = QueueCmdCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip, + result = QueueCmdCopyEx(renderer, texture, &real_srcrect, &real_dstrect, angle, &real_center, flip, renderer->view->scale.x, renderer->view->scale.y); } - return retval; + return result; } -static int SDL_RenderTextureTiled_Wrap(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect) +static bool SDL_RenderTextureTiled_Wrap(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect) { float xy[8]; const int xy_stride = 2 * sizeof(float); @@ -4148,7 +4143,7 @@ static int SDL_RenderTextureTiled_Wrap(SDL_Renderer *renderer, SDL_Texture *text renderer->view->scale.y, SDL_TEXTURE_ADDRESS_WRAP); } -static int SDL_RenderTextureTiled_Iterate(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect) +static bool SDL_RenderTextureTiled_Iterate(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect) { float tile_width = srcrect->w * scale; float tile_height = srcrect->h * scale; @@ -4170,16 +4165,16 @@ static int SDL_RenderTextureTiled_Iterate(SDL_Renderer *renderer, SDL_Texture *t for (int y = 0; y < rows; ++y) { curr_dst.x = dstrect->x; for (int x = 0; x < cols; ++x) { - if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst)) { + return false; } curr_dst.x += curr_dst.w; } if (remaining_dst_w > 0.0f) { curr_src.w = remaining_src_w; curr_dst.w = remaining_dst_w; - if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst)) { + return false; } curr_src.w = srcrect->w; curr_dst.w = tile_width; @@ -4191,29 +4186,29 @@ static int SDL_RenderTextureTiled_Iterate(SDL_Renderer *renderer, SDL_Texture *t curr_dst.h = remaining_dst_h; curr_dst.x = dstrect->x; for (int x = 0; x < cols; ++x) { - if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst)) { + return false; } curr_dst.x += curr_dst.w; } if (remaining_dst_w > 0.0f) { curr_src.w = remaining_src_w; curr_dst.w = remaining_dst_w; - if (SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTextureInternal(renderer, texture, &curr_src, &curr_dst)) { + return false; } } } - return 0; + return true; } -int SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect) +SDL_bool SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float scale, const SDL_FRect *dstrect) { SDL_FRect real_srcrect; SDL_FRect real_dstrect; - CHECK_RENDERER_MAGIC(renderer, -1); - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_RENDERER_MAGIC(renderer, false); + CHECK_TEXTURE_MAGIC(texture, false); if (renderer != texture->renderer) { return SDL_SetError("Texture was not created with this renderer"); @@ -4226,7 +4221,7 @@ int SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const S #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif @@ -4236,14 +4231,14 @@ int SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const S real_srcrect.h = (float)texture->h; if (srcrect) { if (!SDL_GetRectIntersectionFloat(srcrect, &real_srcrect, &real_srcrect)) { - return 0; + return true; } } GetRenderViewportSize(renderer, &real_dstrect); if (dstrect) { if (!SDL_HasRectIntersectionFloat(dstrect, &real_dstrect)) { - return 0; + return true; } real_dstrect = *dstrect; } @@ -4265,7 +4260,7 @@ int SDL_RenderTextureTiled(SDL_Renderer *renderer, SDL_Texture *texture, const S } } -int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect) +SDL_bool SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_FRect *srcrect, float left_width, float right_width, float top_height, float bottom_height, float scale, const SDL_FRect *dstrect) { SDL_FRect full_src, full_dst; SDL_FRect curr_src, curr_dst; @@ -4274,8 +4269,8 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S float dst_top_height; float dst_bottom_height; - CHECK_RENDERER_MAGIC(renderer, -1); - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_RENDERER_MAGIC(renderer, false); + CHECK_TEXTURE_MAGIC(texture, false); if (renderer != texture->renderer) { return SDL_SetError("Texture was not created with this renderer"); @@ -4315,8 +4310,8 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S curr_dst.y = dstrect->y; curr_dst.w = dst_left_width; curr_dst.h = dst_top_height; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Upper-right corner @@ -4324,16 +4319,16 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S curr_src.w = right_width; curr_dst.x = dstrect->x + dstrect->w - dst_right_width; curr_dst.w = dst_right_width; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Lower-right corner curr_src.y = srcrect->y + srcrect->h - bottom_height; curr_dst.y = dstrect->y + dstrect->h - dst_bottom_height; curr_dst.h = dst_bottom_height; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Lower-left corner @@ -4341,8 +4336,8 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S curr_src.w = left_width; curr_dst.x = dstrect->x; curr_dst.w = dst_left_width; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Left @@ -4350,8 +4345,8 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S curr_src.h = srcrect->h - top_height - bottom_height; curr_dst.y = dstrect->y + dst_top_height; curr_dst.h = dstrect->h - dst_top_height - dst_bottom_height; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Right @@ -4359,8 +4354,8 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S curr_src.w = right_width; curr_dst.x = dstrect->x + dstrect->w - dst_right_width; curr_dst.w = dst_right_width; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Top @@ -4372,16 +4367,16 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S curr_dst.y = dstrect->y; curr_dst.w = dstrect->w - dst_left_width - dst_right_width; curr_dst.h = dst_top_height; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Bottom curr_src.y = srcrect->y + srcrect->h - bottom_height; curr_dst.y = dstrect->y + dstrect->h - dst_bottom_height; curr_dst.h = dst_bottom_height; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } // Center @@ -4393,14 +4388,14 @@ int SDL_RenderTexture9Grid(SDL_Renderer *renderer, SDL_Texture *texture, const S curr_dst.y = dstrect->y + dst_top_height; curr_dst.w = dstrect->w - dst_left_width - dst_right_width; curr_dst.h = dstrect->h - dst_top_height - dst_bottom_height; - if (SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst) < 0) { - return -1; + if (!SDL_RenderTexture(renderer, texture, &curr_src, &curr_dst)) { + return false; } - return 0; + return true; } -int SDL_RenderGeometry(SDL_Renderer *renderer, +SDL_bool SDL_RenderGeometry(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Vertex *vertices, int num_vertices, const int *indices, int num_indices) @@ -4420,7 +4415,7 @@ int SDL_RenderGeometry(SDL_Renderer *renderer, } #if SDL_VIDEO_RENDER_SW -static int remap_one_indice( +static bool remap_one_indice( int prev, int k, SDL_Texture *texture, @@ -4458,7 +4453,7 @@ static int remap_one_indice( return prev; } -static int remap_indices( +static bool remap_indices( int prev[3], int k, SDL_Texture *texture, @@ -4482,7 +4477,7 @@ static int remap_indices( #define DEBUG_SW_RENDER_GEOMETRY 0 // For the software renderer, try to reinterpret triangles as SDL_Rect -static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, +static bool SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, @@ -4491,7 +4486,7 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, const void *indices, int num_indices, int size_indices) { int i; - int retval = 0; + bool result = true; int count = indices ? num_indices : num_vertices; int prev[3]; // Previous triangle vertex indices float texw = 0.0f, texh = 0.0f; @@ -4750,12 +4745,12 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, #if DEBUG_SW_RENDER_GEOMETRY SDL_Log("Triangle %d %d %d - is_uniform:%d is_rectangle:%d", prev[0], prev[1], prev[2], is_uniform, is_rectangle); #endif - retval = QueueCmdGeometry(renderer, texture, + result = QueueCmdGeometry(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, prev, 3, 4, renderer->view->scale.x, renderer->view->scale.y, SDL_TEXTURE_ADDRESS_CLAMP); - if (retval < 0) { + if (!result) { goto end; } } @@ -4771,12 +4766,12 @@ static int SDLCALL SDL_SW_RenderGeometryRaw(SDL_Renderer *renderer, #if DEBUG_SW_RENDER_GEOMETRY SDL_Log("Last triangle %d %d %d", prev[0], prev[1], prev[2]); #endif - retval = QueueCmdGeometry(renderer, texture, + result = QueueCmdGeometry(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, prev, 3, 4, renderer->view->scale.x, renderer->view->scale.y, SDL_TEXTURE_ADDRESS_CLAMP); - if (retval < 0) { + if (!result) { goto end; } } @@ -4786,11 +4781,11 @@ end: SDL_SetRenderDrawBlendMode(renderer, blendMode); SDL_SetRenderDrawColorFloat(renderer, r, g, b, a); - return retval; + return result; } #endif // SDL_VIDEO_RENDER_SW -int SDL_RenderGeometryRaw(SDL_Renderer *renderer, +SDL_bool SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, @@ -4802,14 +4797,14 @@ int SDL_RenderGeometryRaw(SDL_Renderer *renderer, int count = indices ? num_indices : num_vertices; SDL_TextureAddressMode texture_address_mode; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (!renderer->QueueGeometry) { return SDL_Unsupported(); } if (texture) { - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); if (renderer != texture->renderer) { return SDL_SetError("Texture was not created with this renderer"); @@ -4843,12 +4838,12 @@ int SDL_RenderGeometryRaw(SDL_Renderer *renderer, #if DONT_DRAW_WHILE_HIDDEN // Don't draw while we're hidden if (renderer->hidden) { - return 0; + return true; } #endif if (num_vertices < 3) { - return 0; + return true; } if (texture && texture->native) { @@ -4996,11 +4991,11 @@ static void SDL_SimulateRenderVSync(SDL_Renderer *renderer) } } -int SDL_RenderPresent(SDL_Renderer *renderer) +SDL_bool SDL_RenderPresent(SDL_Renderer *renderer) { bool presented = true; - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (renderer->logical_target) { SDL_SetRenderTargetInternal(renderer, NULL); @@ -5019,7 +5014,7 @@ int SDL_RenderPresent(SDL_Renderer *renderer) presented = false; } else #endif - if (renderer->RenderPresent(renderer) < 0) { + if (!renderer->RenderPresent(renderer)) { presented = false; } @@ -5031,14 +5026,14 @@ int SDL_RenderPresent(SDL_Renderer *renderer) (!presented && renderer->wanted_vsync)) { SDL_SimulateRenderVSync(renderer); } - return 0; + return true; } -static int SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying) +static bool SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying) { SDL_Renderer *renderer; - CHECK_TEXTURE_MAGIC(texture, -1); + CHECK_TEXTURE_MAGIC(texture, false); SDL_DestroyProperties(texture->props); @@ -5090,7 +5085,7 @@ static int SDL_DestroyTextureInternal(SDL_Texture *texture, bool is_destroying) texture->locked_surface = NULL; SDL_free(texture); - return 0; + return true; } void SDL_DestroyTexture(SDL_Texture *texture) @@ -5221,9 +5216,9 @@ void *SDL_GetRenderMetalCommandEncoder(SDL_Renderer *renderer) return NULL; } -int SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore) +SDL_bool SDL_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (!renderer->AddVulkanRenderSemaphores) { return SDL_Unsupported(); @@ -5329,9 +5324,9 @@ SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode) return (SDL_BlendOperation)(((Uint32)blendMode >> 16) & 0xF); } -int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync) +SDL_bool SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync) { - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); renderer->wanted_vsync = vsync ? true : false; @@ -5340,14 +5335,14 @@ int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync) if (renderer->software) { if (!renderer->window) { if (!vsync) { - return 0; + return true; } else { return SDL_Unsupported(); } } - if (SDL_SetWindowTextureVSync(NULL, renderer->window, vsync) == 0) { + if (SDL_SetWindowTextureVSync(NULL, renderer->window, vsync)) { renderer->simulate_vsync = false; - return 0; + return true; } } #endif @@ -5363,27 +5358,27 @@ int SDL_SetRenderVSync(SDL_Renderer *renderer, int vsync) default: return SDL_Unsupported(); } - } else if (renderer->SetVSync(renderer, vsync) < 0) { + } else if (!renderer->SetVSync(renderer, vsync)) { if (vsync == 1) { renderer->simulate_vsync = true; } else { - return -1; + return false; } } SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, vsync); - return 0; + return true; } -int SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync) +SDL_bool SDL_GetRenderVSync(SDL_Renderer *renderer, int *vsync) { if (vsync) { *vsync = 0; } - CHECK_RENDERER_MAGIC(renderer, -1); + CHECK_RENDERER_MAGIC(renderer, false); if (vsync) { *vsync = (int)SDL_GetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_VSYNC_NUMBER, 0); } - return 0; + return true; } diff --git a/src/render/SDL_sysrender.h b/src/render/SDL_sysrender.h index cba77ea60e..46b2e1ace4 100644 --- a/src/render/SDL_sysrender.h +++ b/src/render/SDL_sysrender.h @@ -168,60 +168,60 @@ typedef enum struct SDL_Renderer { void (*WindowEvent)(SDL_Renderer *renderer, const SDL_WindowEvent *event); - int (*GetOutputSize)(SDL_Renderer *renderer, int *w, int *h); + bool (*GetOutputSize)(SDL_Renderer *renderer, int *w, int *h); bool (*SupportsBlendMode)(SDL_Renderer *renderer, SDL_BlendMode blendMode); - int (*CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props); - int (*QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd); - int (*QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd); - int (*QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, + bool (*CreateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props); + bool (*QueueSetViewport)(SDL_Renderer *renderer, SDL_RenderCommand *cmd); + bool (*QueueSetDrawColor)(SDL_Renderer *renderer, SDL_RenderCommand *cmd); + bool (*QueueDrawPoints)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count); - int (*QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, + bool (*QueueDrawLines)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count); - int (*QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, + bool (*QueueFillRects)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count); - int (*QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, + bool (*QueueCopy)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect); - int (*QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, + bool (*QueueCopyEx)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_FRect *srcquad, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y); - int (*QueueGeometry)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, + bool (*QueueGeometry)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y); void (*InvalidateCachedState)(SDL_Renderer *renderer); - int (*RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize); - int (*UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, + bool (*RunCommandQueue)(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize); + bool (*UpdateTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch); #if SDL_HAVE_YUV - int (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture, + bool (*UpdateTextureYUV)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch); - int (*UpdateTextureNV)(SDL_Renderer *renderer, SDL_Texture *texture, + bool (*UpdateTextureNV)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch); #endif - int (*LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, + bool (*LockTexture)(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch); void (*UnlockTexture)(SDL_Renderer *renderer, SDL_Texture *texture); void (*SetTextureScaleMode)(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode); - int (*SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture); + bool (*SetRenderTarget)(SDL_Renderer *renderer, SDL_Texture *texture); SDL_Surface *(*RenderReadPixels)(SDL_Renderer *renderer, const SDL_Rect *rect); - int (*RenderPresent)(SDL_Renderer *renderer); + bool (*RenderPresent)(SDL_Renderer *renderer); void (*DestroyTexture)(SDL_Renderer *renderer, SDL_Texture *texture); void (*DestroyRenderer)(SDL_Renderer *renderer); - int (*SetVSync)(SDL_Renderer *renderer, int vsync); + bool (*SetVSync)(SDL_Renderer *renderer, int vsync); void *(*GetMetalLayer)(SDL_Renderer *renderer); void *(*GetMetalCommandEncoder)(SDL_Renderer *renderer); - int (*AddVulkanRenderSemaphores)(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore); + bool (*AddVulkanRenderSemaphores)(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore); // The current renderer info const char *name; @@ -307,7 +307,7 @@ struct SDL_Renderer // Define the SDL render driver structure struct SDL_RenderDriver { - int (*CreateRenderer)(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID props); + bool (*CreateRenderer)(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID props); const char *name; }; @@ -329,7 +329,7 @@ extern SDL_RenderDriver VITA_GXM_RenderDriver; extern void SDL_QuitRender(void); // Add a supported texture format to a renderer -extern int SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format); +extern bool SDL_AddSupportedTextureFormat(SDL_Renderer *renderer, SDL_PixelFormat format); // Setup colorspace conversion extern void SDL_SetupRendererColorspace(SDL_Renderer *renderer, SDL_PropertiesID props); diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c index 8c8dec73d7..18eaba20bc 100644 --- a/src/render/SDL_yuv_sw.c +++ b/src/render/SDL_yuv_sw.c @@ -57,7 +57,7 @@ SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h) swdata->h = h; { size_t dst_size; - if (SDL_CalculateYUVSize(format, w, h, &dst_size, NULL) < 0) { + if (!SDL_CalculateYUVSize(format, w, h, &dst_size, NULL)) { SDL_SW_DestroyYUVTexture(swdata); return NULL; } @@ -103,15 +103,15 @@ SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h) return swdata; } -int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels, +bool SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels, int *pitch) { *pixels = swdata->planes[0]; *pitch = swdata->pitches[0]; - return 0; + return true; } -int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, +bool SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const void *pixels, int pitch) { switch (swdata->format) { @@ -216,10 +216,10 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, default: return SDL_SetError("Unsupported YUV format"); } - return 0; + return true; } -int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, +bool SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch) @@ -270,10 +270,10 @@ int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rec src += Vpitch; dst += (swdata->w + 1) / 2; } - return 0; + return true; } -int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, +bool SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) { @@ -304,10 +304,10 @@ int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect dst += 2 * ((swdata->w + 1) / 2); } - return 0; + return true; } -int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, +bool SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, void **pixels, int *pitch) { switch (swdata->format) { @@ -329,16 +329,14 @@ int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, *pixels = swdata->planes[0]; } *pitch = swdata->pitches[0]; - return 0; + return true; } void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata) { } -int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, - SDL_PixelFormat target_format, int w, int h, void *pixels, - int pitch) +bool SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, SDL_PixelFormat target_format, int w, int h, void *pixels, int pitch) { int stretch; @@ -368,28 +366,27 @@ int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, } else { swdata->display = SDL_CreateSurfaceFrom(w, h, target_format, pixels, pitch); if (!swdata->display) { - return -1; + return false; } } if (!swdata->stretch) { swdata->stretch = SDL_CreateSurface(swdata->w, swdata->h, target_format); if (!swdata->stretch) { - return -1; + return false; } } pixels = swdata->stretch->pixels; pitch = swdata->stretch->pitch; } - if (SDL_ConvertPixels(swdata->w, swdata->h, swdata->format, - swdata->planes[0], swdata->pitches[0], - target_format, pixels, pitch) < 0) { - return -1; + if (!SDL_ConvertPixels(swdata->w, swdata->h, swdata->format, swdata->planes[0], swdata->pitches[0], target_format, pixels, pitch)) { + return false; } if (stretch) { SDL_Rect rect = *srcrect; - SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL, SDL_SCALEMODE_NEAREST); + return SDL_SoftStretch(swdata->stretch, &rect, swdata->display, NULL, SDL_SCALEMODE_NEAREST); + } else { + return true; } - return 0; } void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata) diff --git a/src/render/SDL_yuv_sw_c.h b/src/render/SDL_yuv_sw_c.h index 6a1309f2d8..026989983a 100644 --- a/src/render/SDL_yuv_sw_c.h +++ b/src/render/SDL_yuv_sw_c.h @@ -44,24 +44,19 @@ struct SDL_SW_YUVTexture typedef struct SDL_SW_YUVTexture SDL_SW_YUVTexture; -SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h); -int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels, - int *pitch); -int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, - const void *pixels, int pitch); -int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *Uplane, int Upitch, - const Uint8 *Vplane, int Vpitch); -int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, - const Uint8 *Yplane, int Ypitch, - const Uint8 *UVplane, int UVpitch); -int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, - void **pixels, int *pitch); -void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata); -int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, - SDL_PixelFormat target_format, int w, int h, void *pixels, - int pitch); -void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata); +extern SDL_SW_YUVTexture *SDL_SW_CreateYUVTexture(SDL_PixelFormat format, int w, int h); +extern bool SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture *swdata, void **pixels, int *pitch); +extern bool SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, const void *pixels, int pitch); +extern bool SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, + const Uint8 *Yplane, int Ypitch, + const Uint8 *Uplane, int Upitch, + const Uint8 *Vplane, int Vpitch); +extern bool SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, + const Uint8 *Yplane, int Ypitch, + const Uint8 *UVplane, int UVpitch); +extern bool SDL_SW_LockYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect, void **pixels, int *pitch); +extern void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture *swdata); +extern bool SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, SDL_PixelFormat target_format, int w, int h, void *pixels, int pitch); +extern void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture *swdata); #endif // SDL_yuv_sw_c_h_ diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c index 1dc361136a..dcdfa04799 100644 --- a/src/render/direct3d/SDL_render_d3d.c +++ b/src/render/direct3d/SDL_render_d3d.c @@ -113,7 +113,7 @@ typedef struct float u, v; } Vertex; -static int D3D_SetError(const char *prefix, HRESULT result) +static bool D3D_SetError(const char *prefix, HRESULT result) { const char *error; @@ -285,9 +285,9 @@ static void D3D_InitRenderState(D3D_RenderData *data) data->beginScene = true; } -static int D3D_Reset(SDL_Renderer *renderer); +static bool D3D_Reset(SDL_Renderer *renderer); -static int D3D_ActivateRenderer(SDL_Renderer *renderer) +static bool D3D_ActivateRenderer(SDL_Renderer *renderer) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; HRESULT result; @@ -312,8 +312,8 @@ static int D3D_ActivateRenderer(SDL_Renderer *renderer) data->pparams.BackBufferFormat = D3DFMT_UNKNOWN; data->pparams.FullScreen_RefreshRateInHz = 0; } - if (D3D_Reset(renderer) < 0) { - return -1; + if (!D3D_Reset(renderer)) { + return false; } data->updateSize = false; @@ -321,8 +321,8 @@ static int D3D_ActivateRenderer(SDL_Renderer *renderer) if (data->beginScene) { result = IDirect3DDevice9_BeginScene(data->device); if (result == D3DERR_DEVICELOST) { - if (D3D_Reset(renderer) < 0) { - return -1; + if (!D3D_Reset(renderer)) { + return false; } result = IDirect3DDevice9_BeginScene(data->device); } @@ -331,7 +331,7 @@ static int D3D_ActivateRenderer(SDL_Renderer *renderer) } data->beginScene = false; } - return 0; + return true; } static void D3D_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event) @@ -416,7 +416,7 @@ static bool D3D_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMod return true; } -static int D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, D3DFORMAT d3dfmt, int w, int h) +static bool D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, D3DFORMAT d3dfmt, int w, int h) { HRESULT result; @@ -433,10 +433,10 @@ static int D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *textur if (FAILED(result)) { return D3D_SetError("CreateTexture(D3DPOOL_DEFAULT)", result); } - return 0; + return true; } -static int D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture) +static bool D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture) { HRESULT result; @@ -447,10 +447,10 @@ static int D3D_CreateStagingTexture(IDirect3DDevice9 *device, D3D_TextureRep *te return D3D_SetError("CreateTexture(D3DPOOL_SYSTEMMEM)", result); } } - return 0; + return true; } -static int D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture) +static bool D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture) { if (texture->texture) { IDirect3DTexture9_Release(texture->texture); @@ -460,10 +460,10 @@ static int D3D_RecreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *text IDirect3DTexture9_AddDirtyRect(texture->staging, NULL); texture->dirty = true; } - return 0; + return true; } -static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, int y, int w, int h, const void *pixels, int pitch) +static bool D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, int x, int y, int w, int h, const void *pixels, int pitch) { RECT d3drect; D3DLOCKED_RECT locked; @@ -472,8 +472,8 @@ static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *textur int row, length; HRESULT result; - if (D3D_CreateStagingTexture(device, texture) < 0) { - return -1; + if (!D3D_CreateStagingTexture(device, texture)) { + return false; } d3drect.left = x; @@ -510,7 +510,7 @@ static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *textur } texture->dirty = true; - return 0; + return true; } static void D3D_DestroyTextureRep(D3D_TextureRep *texture) @@ -525,7 +525,7 @@ static void D3D_DestroyTextureRep(D3D_TextureRep *texture) } } -static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; D3D_TextureData *texturedata; @@ -533,7 +533,7 @@ static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P texturedata = (D3D_TextureData *)SDL_calloc(1, sizeof(*texturedata)); if (!texturedata) { - return -1; + return false; } texturedata->scaleMode = (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? D3DTEXF_POINT : D3DTEXF_LINEAR; @@ -545,20 +545,20 @@ static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P usage = 0; } - if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, PixelFormatToD3DFMT(texture->format), texture->w, texture->h) < 0) { - return -1; + if (!D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, PixelFormatToD3DFMT(texture->format), texture->w, texture->h)) { + return false; } #if SDL_HAVE_YUV if (texture->format == SDL_PIXELFORMAT_YV12 || texture->format == SDL_PIXELFORMAT_IYUV) { texturedata->yuv = true; - if (D3D_CreateTextureRep(data->device, &texturedata->utexture, usage, texture->format, PixelFormatToD3DFMT(texture->format), (texture->w + 1) / 2, (texture->h + 1) / 2) < 0) { - return -1; + if (!D3D_CreateTextureRep(data->device, &texturedata->utexture, usage, texture->format, PixelFormatToD3DFMT(texture->format), (texture->w + 1) / 2, (texture->h + 1) / 2)) { + return false; } - if (D3D_CreateTextureRep(data->device, &texturedata->vtexture, usage, texture->format, PixelFormatToD3DFMT(texture->format), (texture->w + 1) / 2, (texture->h + 1) / 2) < 0) { - return -1; + if (!D3D_CreateTextureRep(data->device, &texturedata->vtexture, usage, texture->format, PixelFormatToD3DFMT(texture->format), (texture->w + 1) / 2, (texture->h + 1) / 2)) { + return false; } texturedata->shader = SHADER_YUV; @@ -568,36 +568,36 @@ static int D3D_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P } } #endif - return 0; + return true; } -static int D3D_RecreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) +static bool D3D_RecreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; D3D_TextureData *texturedata = (D3D_TextureData *)texture->internal; if (!texturedata) { - return 0; + return true; } - if (D3D_RecreateTextureRep(data->device, &texturedata->texture) < 0) { - return -1; + if (!D3D_RecreateTextureRep(data->device, &texturedata->texture)) { + return false; } #if SDL_HAVE_YUV if (texturedata->yuv) { - if (D3D_RecreateTextureRep(data->device, &texturedata->utexture) < 0) { - return -1; + if (!D3D_RecreateTextureRep(data->device, &texturedata->utexture)) { + return false; } - if (D3D_RecreateTextureRep(data->device, &texturedata->vtexture) < 0) { - return -1; + if (!D3D_RecreateTextureRep(data->device, &texturedata->vtexture)) { + return false; } } #endif - return 0; + return true; } -static int D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; @@ -607,30 +607,30 @@ static int D3D_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) { - return -1; + if (!D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch)) { + return false; } #if SDL_HAVE_YUV if (texturedata->yuv) { // Skip to the correct offset into the next texture pixels = (const void *)((const Uint8 *)pixels + rect->h * pitch); - if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->vtexture : &texturedata->utexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2) < 0) { - return -1; + if (!D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->vtexture : &texturedata->utexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2)) { + return false; } // Skip to the correct offset into the next texture pixels = (const void *)((const Uint8 *)pixels + ((rect->h + 1) / 2) * ((pitch + 1) / 2)); - if (D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->utexture : &texturedata->vtexture, rect->x / 2, (rect->y + 1) / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2) < 0) { - return -1; + if (!D3D_UpdateTextureRep(data->device, texture->format == SDL_PIXELFORMAT_YV12 ? &texturedata->utexture : &texturedata->vtexture, rect->x / 2, (rect->y + 1) / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, pixels, (pitch + 1) / 2)) { + return false; } } #endif - return 0; + return true; } #if SDL_HAVE_YUV -static int D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -643,20 +643,20 @@ static int D3D_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) { - return -1; + if (!D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch)) { + return false; } - if (D3D_UpdateTextureRep(data->device, &texturedata->utexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Uplane, Upitch) < 0) { - return -1; + if (!D3D_UpdateTextureRep(data->device, &texturedata->utexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Uplane, Upitch)) { + return false; } - if (D3D_UpdateTextureRep(data->device, &texturedata->vtexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Vplane, Vpitch) < 0) { - return -1; + if (!D3D_UpdateTextureRep(data->device, &texturedata->vtexture, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Vplane, Vpitch)) { + return false; } - return 0; + return true; } #endif -static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; @@ -675,7 +675,7 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, texturedata->pitch = texture->w; texturedata->pixels = (Uint8 *)SDL_malloc((texture->h * texturedata->pitch * 3) / 2); if (!texturedata->pixels) { - return -1; + return false; } } *pixels = @@ -689,8 +689,8 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, D3DLOCKED_RECT locked; HRESULT result; - if (D3D_CreateStagingTexture(device, &texturedata->texture) < 0) { - return -1; + if (!D3D_CreateStagingTexture(device, &texturedata->texture)) { + return false; } d3drect.left = rect->x; @@ -705,7 +705,7 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, *pixels = locked.pBits; *pitch = locked.Pitch; } - return 0; + return true; } static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -749,7 +749,7 @@ static void D3D_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture texturedata->scaleMode = (scaleMode == SDL_SCALEMODE_NEAREST) ? D3DTEXF_POINT : D3DTEXF_LINEAR; } -static int D3D_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *texture) +static bool D3D_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *texture) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; D3D_TextureData *texturedata; @@ -765,7 +765,7 @@ static int D3D_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *text if (!texture) { IDirect3DDevice9_SetRenderTarget(data->device, 0, data->defaultRenderTarget); - return 0; + return true; } texturedata = (D3D_TextureData *)texture->internal; @@ -800,24 +800,24 @@ static int D3D_SetRenderTargetInternal(SDL_Renderer *renderer, SDL_Texture *text return D3D_SetError("SetRenderTarget()", result); } - return 0; + return true; } -static int D3D_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool D3D_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; + if (!D3D_ActivateRenderer(renderer)) { + return false; } return D3D_SetRenderTargetInternal(renderer, texture); } -static int D3D_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool D3D_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int D3D_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool D3D_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { const DWORD color = D3DCOLOR_COLORVALUE(cmd->data.draw.color.r * cmd->data.draw.color_scale, cmd->data.draw.color.g * cmd->data.draw.color_scale, @@ -828,7 +828,7 @@ static int D3D_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c int i; if (!verts) { - return -1; + return false; } SDL_memset(verts, '\0', vertslen); @@ -840,10 +840,10 @@ static int D3D_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c verts->color = color; } - return 0; + return true; } -static int D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -854,7 +854,7 @@ static int D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL const float color_scale = cmd->data.draw.color_scale; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -893,10 +893,10 @@ static int D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL verts += 1; } - return 0; + return true; } -static int UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture) +static bool UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture) { if (texture->dirty && texture->staging) { HRESULT result; @@ -914,10 +914,10 @@ static int UpdateDirtyTexture(IDirect3DDevice9 *device, D3D_TextureRep *texture) } texture->dirty = false; } - return 0; + return true; } -static int BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler) +static bool BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD sampler) { HRESULT result; UpdateDirtyTexture(device, texture); @@ -925,7 +925,7 @@ static int BindTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWO if (FAILED(result)) { return D3D_SetError("SetTexture()", result); } - return 0; + return true; } static void UpdateTextureScaleMode(D3D_RenderData *data, D3D_TextureData *texturedata, unsigned index) @@ -956,7 +956,7 @@ static void UpdateTextureAddressMode(D3D_RenderData *data, SDL_TextureAddressMod } } -static int SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_TextureAddressMode addressMode, D3D9_Shader *shader, const float **shader_params) +static bool SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_TextureAddressMode addressMode, D3D9_Shader *shader, const float **shader_params) { D3D_TextureData *texturedata = (D3D_TextureData *)texture->internal; @@ -970,8 +970,8 @@ static int SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_Tex *shader = texturedata->shader; *shader_params = texturedata->shader_params; - if (BindTextureRep(data->device, &texturedata->texture, 0) < 0) { - return -1; + if (!BindTextureRep(data->device, &texturedata->texture, 0)) { + return false; } #if SDL_HAVE_YUV if (texturedata->yuv) { @@ -980,18 +980,18 @@ static int SetupTextureState(D3D_RenderData *data, SDL_Texture *texture, SDL_Tex UpdateTextureAddressMode(data, addressMode, 1); UpdateTextureAddressMode(data, addressMode, 2); - if (BindTextureRep(data->device, &texturedata->utexture, 1) < 0) { - return -1; + if (!BindTextureRep(data->device, &texturedata->utexture, 1)) { + return false; } - if (BindTextureRep(data->device, &texturedata->vtexture, 2) < 0) { - return -1; + if (!BindTextureRep(data->device, &texturedata->vtexture, 2)) { + return false; } } #endif - return 0; + return true; } -static int SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd) +static bool SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd) { SDL_Texture *texture = cmd->data.draw.texture; const SDL_BlendMode blend = cmd->data.draw.blend; @@ -1014,8 +1014,8 @@ static int SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd) IDirect3DDevice9_SetTexture(data->device, 2, NULL); } #endif - if (texture && SetupTextureState(data, texture, cmd->data.draw.texture_address_mode, &shader, &shader_params) < 0) { - return -1; + if (texture && !SetupTextureState(data, texture, cmd->data.draw.texture_address_mode, &shader, &shader_params)) { + return false; } #if SDL_HAVE_YUV @@ -1119,7 +1119,7 @@ static int SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd) data->drawstate.cliprect_dirty = false; } - return 0; + return true; } static void D3D_InvalidateCachedState(SDL_Renderer *renderer) @@ -1134,15 +1134,15 @@ static void D3D_InvalidateCachedState(SDL_Renderer *renderer) data->drawstate.shader_params = NULL; } -static int D3D_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool D3D_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; const int vboidx = data->currentVertexBuffer; IDirect3DVertexBuffer9 *vbo = NULL; const bool istarget = renderer->target != NULL; - if (D3D_ActivateRenderer(renderer) < 0) { - return -1; + if (!D3D_ActivateRenderer(renderer)) { + return false; } if (vertsize > 0) { @@ -1330,7 +1330,7 @@ static int D3D_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v cmd = cmd->next; } - return 0; + return true; } static SDL_Surface *D3D_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect) @@ -1390,7 +1390,7 @@ static SDL_Surface *D3D_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect return output; } -static int D3D_RenderPresent(SDL_Renderer *renderer) +static bool D3D_RenderPresent(SDL_Renderer *renderer) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; HRESULT result; @@ -1403,7 +1403,7 @@ static int D3D_RenderPresent(SDL_Renderer *renderer) result = IDirect3DDevice9_TestCooperativeLevel(data->device); if (result == D3DERR_DEVICELOST) { // We'll reset later - return -1; + return false; } if (result == D3DERR_DEVICENOTRESET) { D3D_Reset(renderer); @@ -1412,7 +1412,7 @@ static int D3D_RenderPresent(SDL_Renderer *renderer) if (FAILED(result)) { return D3D_SetError("Present()", result); } - return 0; + return true; } static void D3D_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -1491,7 +1491,7 @@ static void D3D_DestroyRenderer(SDL_Renderer *renderer) } } -static int D3D_Reset(SDL_Renderer *renderer) +static bool D3D_Reset(SDL_Renderer *renderer) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; const Float4X4 d3dmatrix = MatrixIdentity(); @@ -1537,7 +1537,7 @@ static int D3D_Reset(SDL_Renderer *renderer) if (FAILED(result)) { if (result == D3DERR_DEVICELOST) { // Don't worry about it, we'll reset later... - return 0; + return true; } else { return D3D_SetError("Reset()", result); } @@ -1566,10 +1566,10 @@ static int D3D_Reset(SDL_Renderer *renderer) SDL_PushEvent(&event); } - return 0; + return true; } -static int D3D_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool D3D_SetVSync(SDL_Renderer *renderer, const int vsync) { D3D_RenderData *data = (D3D_RenderData *)renderer->internal; @@ -1604,14 +1604,14 @@ static int D3D_SetVSync(SDL_Renderer *renderer, const int vsync) } data->pparams.PresentationInterval = PresentationInterval; - if (D3D_Reset(renderer) < 0) { + if (!D3D_Reset(renderer)) { // D3D_Reset will call SDL_SetError() - return -1; + return false; } - return 0; + return true; } -int D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { D3D_RenderData *data; HRESULT result; @@ -1637,7 +1637,7 @@ int D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propertie data = (D3D_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } if (!D3D_LoadDLL(&data->d3dDLL, &data->d3d)) { @@ -1770,7 +1770,7 @@ int D3D_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propertie SDL_SetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_D3D9_DEVICE_POINTER, data->device); - return 0; + return true; } SDL_RenderDriver D3D_RenderDriver = { diff --git a/src/render/direct3d11/SDL_render_d3d11.c b/src/render/direct3d11/SDL_render_d3d11.c index 891096b2dd..bc3c822e21 100644 --- a/src/render/direct3d11/SDL_render_d3d11.c +++ b/src/render/direct3d11/SDL_render_d3d11.c @@ -725,7 +725,7 @@ static HRESULT D3D11_CreateDeviceResources(SDL_Renderer *renderer) goto done; } - if (D3D11_CreateVertexShader(data->d3dDevice, &data->vertexShader, &data->inputLayout) < 0) { + if (!D3D11_CreateVertexShader(data->d3dDevice, &data->vertexShader, &data->inputLayout)) { goto done; } @@ -851,7 +851,7 @@ static int D3D11_GetRotationForCurrentRenderTarget(SDL_Renderer *renderer) } } -static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rect *sdlRect, D3D11_RECT *outRect, BOOL includeViewportOffset) +static bool D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rect *sdlRect, D3D11_RECT *outRect, BOOL includeViewportOffset) { D3D11_RenderData *data = (D3D11_RenderData *)renderer->internal; const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer); @@ -891,7 +891,7 @@ static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec default: return SDL_SetError("The physical display is in an unknown or unsupported rotation"); } - return 0; + return true; } static HRESULT D3D11_CreateSwapChain(SDL_Renderer *renderer, int w, int h) @@ -1260,7 +1260,7 @@ static bool D3D11_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendM return true; } -static int GetTextureProperty(SDL_PropertiesID props, const char *name, ID3D11Texture2D **texture) +static bool GetTextureProperty(SDL_PropertiesID props, const char *name, ID3D11Texture2D **texture) { IUnknown *unknown = SDL_GetPointerProperty(props, name, NULL); if (unknown) { @@ -1269,10 +1269,10 @@ static int GetTextureProperty(SDL_PropertiesID props, const char *name, ID3D11Te return WIN_SetErrorFromHRESULT(name, result); } } - return 0; + return true; } -static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; D3D11_TextureData *textureData; @@ -1288,7 +1288,7 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureData = (D3D11_TextureData *)SDL_calloc(1, sizeof(*textureData)); if (!textureData) { - return -1; + return false; } textureData->scaleMode = (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR; @@ -1333,8 +1333,8 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureDesc.BindFlags = D3D11_BIND_SHADER_RESOURCE; } - if (GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER, &textureData->mainTexture) < 0) { - return -1; + if (!GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_POINTER, &textureData->mainTexture)) { + return false; } if (!textureData->mainTexture) { result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, @@ -1354,8 +1354,8 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureDesc.Width = (textureDesc.Width + 1) / 2; textureDesc.Height = (textureDesc.Height + 1) / 2; - if (GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER, &textureData->mainTextureU) < 0) { - return -1; + if (!GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_U_POINTER, &textureData->mainTextureU)) { + return false; } if (!textureData->mainTextureU) { result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, @@ -1368,8 +1368,8 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL } SDL_SetPointerProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_D3D11_TEXTURE_U_POINTER, textureData->mainTextureU); - if (GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER, &textureData->mainTextureV) < 0) { - return -1; + if (!GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D11_TEXTURE_V_POINTER, &textureData->mainTextureV)) { + return false; } if (!textureData->mainTextureV) { result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice, @@ -1473,7 +1473,7 @@ static int D3D11_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL } } - return 0; + return true; } static void D3D11_DestroyTexture(SDL_Renderer *renderer, @@ -1501,7 +1501,7 @@ static void D3D11_DestroyTexture(SDL_Renderer *renderer, texture->internal = NULL; } -static int D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture, int bpp, int x, int y, int w, int h, const void *pixels, int pitch) +static bool D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *texture, int bpp, int x, int y, int w, int h, const void *pixels, int pitch) { ID3D11Texture2D *stagingTexture; const Uint8 *src; @@ -1601,23 +1601,23 @@ static int D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Tex SAFE_RELEASE(stagingTexture); - return 0; + return true; } #if SDL_HAVE_YUV -static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch); -static int D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch); #endif -static int D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *srcPixels, int srcPitch) { @@ -1650,14 +1650,14 @@ static int D3D11_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, } #endif - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch) < 0) { - return -1; + if (!D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch)) { + return false; } - return 0; + return true; } #if SDL_HAVE_YUV -static int D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -1670,19 +1670,19 @@ static int D3D11_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) { - return -1; + if (!D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch)) { + return false; } - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Uplane, Upitch) < 0) { - return -1; + if (!D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureU, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Uplane, Upitch)) { + return false; } - if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Vplane, Vpitch) < 0) { - return -1; + if (!D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureV, SDL_BYTESPERPIXEL(texture->format), rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, Vplane, Vpitch)) { + return false; } - return 0; + return true; } -static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) @@ -1792,11 +1792,11 @@ static int D3D11_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, SAFE_RELEASE(stagingTexture); - return 0; + return true; } #endif -static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; @@ -1815,7 +1815,7 @@ static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, textureData->pitch = texture->w; textureData->pixels = (Uint8 *)SDL_malloc((texture->h * textureData->pitch * 3) / 2); if (!textureData->pixels) { - return -1; + return false; } } textureData->locked_rect = *rect; @@ -1823,7 +1823,7 @@ static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, (void *)(textureData->pixels + rect->y * textureData->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = textureData->pitch; - return 0; + return true; } #endif if (textureData->stagingTexture) { @@ -1876,7 +1876,7 @@ static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, */ *pixels = textureMemory.pData; *pitch = textureMemory.RowPitch; - return 0; + return true; } static void D3D11_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -1927,14 +1927,14 @@ static void D3D11_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu textureData->scaleMode = (scaleMode == SDL_SCALEMODE_NEAREST) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR; } -static int D3D11_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool D3D11_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; D3D11_TextureData *textureData = NULL; if (!texture) { rendererData->currentOffscreenRenderTargetView = NULL; - return 0; + return true; } textureData = (D3D11_TextureData *)texture->internal; @@ -1945,15 +1945,15 @@ static int D3D11_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) rendererData->currentOffscreenRenderTargetView = textureData->mainTextureRenderTargetView; - return 0; + return true; } -static int D3D11_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool D3D11_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int D3D11_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool D3D11_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); int i; @@ -1961,7 +1961,7 @@ static int D3D11_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, bool convert_color = SDL_RenderingLinearSpace(renderer); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -1979,10 +1979,10 @@ static int D3D11_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, verts++; } - return 0; + return true; } -static int D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -1996,7 +1996,7 @@ static int D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S float v_scale = textureData ? (float)texture->h / textureData->h : 0.0f; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -2035,10 +2035,10 @@ static int D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S verts += 1; } - return 0; + return true; } -static int D3D11_UpdateVertexBuffer(SDL_Renderer *renderer, +static bool D3D11_UpdateVertexBuffer(SDL_Renderer *renderer, const void *vertexData, size_t dataSizeInBytes) { D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; @@ -2048,7 +2048,7 @@ static int D3D11_UpdateVertexBuffer(SDL_Renderer *renderer, const UINT offset = 0; if (dataSizeInBytes == 0) { - return 0; // nothing to do. + return true; // nothing to do. } if (rendererData->vertexBuffers[vbidx] && rendererData->vertexBufferSizes[vbidx] >= dataSizeInBytes) { @@ -2104,10 +2104,10 @@ static int D3D11_UpdateVertexBuffer(SDL_Renderer *renderer, rendererData->currentVertexBuffer = 0; } - return 0; + return true; } -static int D3D11_UpdateViewport(SDL_Renderer *renderer) +static bool D3D11_UpdateViewport(SDL_Renderer *renderer) { D3D11_RenderData *data = (D3D11_RenderData *)renderer->internal; const SDL_Rect *viewport = &data->currentViewport; @@ -2124,7 +2124,7 @@ static int D3D11_UpdateViewport(SDL_Renderer *renderer) * with a non-empty viewport. */ // SDL_Log("%s, no viewport was set!\n", __FUNCTION__); - return -1; + return false; } /* Make sure the SDL viewport gets rotated to that of the physical display's rotation. @@ -2196,7 +2196,7 @@ static int D3D11_UpdateViewport(SDL_Renderer *renderer) data->viewportDirty = false; - return 0; + return true; } static ID3D11RenderTargetView *D3D11_GetCurrentRenderTargetView(SDL_Renderer *renderer) @@ -2271,7 +2271,7 @@ static void D3D11_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderC } } -static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, +static bool D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, D3D11_Shader shader, const PixelShaderConstants *shader_constants, const int numShaderResources, ID3D11ShaderResourceView **shaderResources, ID3D11SamplerState *sampler, const Float4X4 *matrix) @@ -2310,7 +2310,7 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c } if (rendererData->viewportDirty) { - if (D3D11_UpdateViewport(renderer) == 0) { + if (D3D11_UpdateViewport(renderer)) { // vertexShaderConstantsData.projectionAndView has changed updateSubresource = true; } @@ -2321,9 +2321,9 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c ID3D11DeviceContext_RSSetScissorRects(rendererData->d3dContext, 0, NULL); } else { D3D11_RECT scissorRect; - if (D3D11_GetViewportAlignedD3DRect(renderer, &rendererData->currentCliprect, &scissorRect, TRUE) != 0) { + if (!D3D11_GetViewportAlignedD3DRect(renderer, &rendererData->currentCliprect, &scissorRect, TRUE)) { // D3D11_GetViewportAlignedD3DRect will have set the SDL error - return -1; + return false; } ID3D11DeviceContext_RSSetScissorRects(rendererData->d3dContext, 1, &scissorRect); } @@ -2351,7 +2351,7 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c if (!blendState) { blendState = D3D11_CreateBlendState(renderer, blendMode); if (!blendState) { - return -1; + return false; } } } @@ -2382,7 +2382,7 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c HRESULT result = ID3D11Device_CreateBuffer(rendererData->d3dDevice, &desc, &data, &shader_state->constants); if (FAILED(result)) { WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device::CreateBuffer [create shader constants]"), result); - return -1; + return false; } SDL_memcpy(&shader_state->shader_constants, shader_constants, sizeof(*shader_constants)); @@ -2391,8 +2391,8 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c } if (shader != rendererData->currentShader) { if (!rendererData->pixelShaders[shader]) { - if (D3D11_CreatePixelShader(rendererData->d3dDevice, shader, &rendererData->pixelShaders[shader]) < 0) { - return -1; + if (!D3D11_CreatePixelShader(rendererData->d3dDevice, shader, &rendererData->pixelShaders[shader])) { + return false; } } ID3D11DeviceContext_PSSetShader(rendererData->d3dContext, rendererData->pixelShaders[shader], NULL, 0); @@ -2421,10 +2421,10 @@ static int D3D11_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c 0); } - return 0; + return true; } -static int D3D11_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const Float4X4 *matrix) +static bool D3D11_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const Float4X4 *matrix) { SDL_Texture *texture = cmd->data.draw.texture; D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; @@ -2511,7 +2511,7 @@ static void D3D11_InvalidateCachedState(SDL_Renderer *renderer) data->viewportDirty = true; } -static int D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->internal; const int viewportRotation = D3D11_GetRotationForCurrentRenderTarget(renderer); @@ -2526,8 +2526,8 @@ static int D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, rendererData->viewportDirty = true; } - if (D3D11_UpdateVertexBuffer(renderer, vertices, vertsize) < 0) { - return -1; + if (!D3D11_UpdateVertexBuffer(renderer, vertices, vertsize)) { + return false; } while (cmd) { @@ -2633,7 +2633,7 @@ static int D3D11_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, cmd = cmd->next; } - return 0; + return true; } static SDL_Surface *D3D11_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect) @@ -2679,7 +2679,7 @@ static SDL_Surface *D3D11_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec } // Copy the desired portion of the back buffer to the staging texture: - if (D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE) != 0) { + if (!D3D11_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE)) { // D3D11_GetViewportAlignedD3DRect will have set the SDL error goto done; } @@ -2728,7 +2728,7 @@ done: return output; } -static int D3D11_RenderPresent(SDL_Renderer *renderer) +static bool D3D11_RenderPresent(SDL_Renderer *renderer) { D3D11_RenderData *data = (D3D11_RenderData *)renderer->internal; HRESULT result; @@ -2769,12 +2769,12 @@ static int D3D11_RenderPresent(SDL_Renderer *renderer) } else { WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::Present"), result); } - return -1; + return false; } - return 0; + return true; } -static int D3D11_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool D3D11_SetVSync(SDL_Renderer *renderer, const int vsync) { D3D11_RenderData *data = (D3D11_RenderData *)renderer->internal; @@ -2805,10 +2805,10 @@ static int D3D11_SetVSync(SDL_Renderer *renderer, const int vsync) data->syncInterval = 0; data->presentFlags = DXGI_PRESENT_DO_NOT_WAIT; } - return 0; + return true; } -static int D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { D3D11_RenderData *data; @@ -2827,7 +2827,7 @@ static int D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ data = (D3D11_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } data->identity = MatrixIdentity(); @@ -2880,13 +2880,13 @@ static int D3D11_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ // Initialize Direct3D resources if (FAILED(D3D11_CreateDeviceResources(renderer))) { - return -1; + return false; } if (FAILED(D3D11_CreateWindowSizeDependentResources(renderer))) { - return -1; + return false; } - return 0; + return true; } SDL_RenderDriver D3D11_RenderDriver = { diff --git a/src/render/direct3d11/SDL_shaders_d3d11.c b/src/render/direct3d11/SDL_shaders_d3d11.c index 2b5b00c395..c8eef04415 100644 --- a/src/render/direct3d11/SDL_shaders_d3d11.c +++ b/src/render/direct3d11/SDL_shaders_d3d11.c @@ -65,7 +65,7 @@ static struct }; SDL_COMPILE_TIME_ASSERT(D3D11_shaders, SDL_arraysize(D3D11_shaders) == NUM_SHADERS); -int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout) +bool D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout) { // Declare how the input layout for SDL's vertex shader will be setup: const D3D11_INPUT_ELEMENT_DESC vertexDesc[] = { @@ -95,10 +95,10 @@ int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vert if (FAILED(result)) { return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateInputLayout"), result); } - return 0; + return true; } -int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader) +bool D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader) { HRESULT result; @@ -110,7 +110,7 @@ int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D1 if (FAILED(result)) { return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreatePixelShader"), result); } - return 0; + return true; } #endif // SDL_VIDEO_RENDER_D3D11 diff --git a/src/render/direct3d11/SDL_shaders_d3d11.h b/src/render/direct3d11/SDL_shaders_d3d11.h index 3e52eddc90..b54581b529 100644 --- a/src/render/direct3d11/SDL_shaders_d3d11.h +++ b/src/render/direct3d11/SDL_shaders_d3d11.h @@ -31,5 +31,5 @@ typedef enum NUM_SHADERS } D3D11_Shader; -extern int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout); -extern int D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader); +extern bool D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout); +extern bool D3D11_CreatePixelShader(ID3D11Device1 *d3dDevice, D3D11_Shader shader, ID3D11PixelShader **pixelShader); diff --git a/src/render/direct3d12/SDL_render_d3d12.c b/src/render/direct3d12/SDL_render_d3d12.c index b86c52fc40..b859d51a0b 100644 --- a/src/render/direct3d12/SDL_render_d3d12.c +++ b/src/render/direct3d12/SDL_render_d3d12.c @@ -544,7 +544,7 @@ static void D3D12_ResetCommandList(D3D12_RenderData *data) ID3D12GraphicsCommandList2_SetDescriptorHeaps(data->commandList, 2, rootDescriptorHeaps); } -static int D3D12_IssueBatch(D3D12_RenderData *data) +static bool D3D12_IssueBatch(D3D12_RenderData *data) { HRESULT result = S_OK; @@ -1158,7 +1158,7 @@ static BOOL D3D12_IsDisplayRotated90Degrees(DXGI_MODE_ROTATION rotation) } } -static int D3D12_GetRotationForCurrentRenderTarget(SDL_Renderer *renderer) +static bool D3D12_GetRotationForCurrentRenderTarget(SDL_Renderer *renderer) { D3D12_RenderData *data = (D3D12_RenderData *)renderer->internal; if (data->textureRenderTarget) { @@ -1168,7 +1168,7 @@ static int D3D12_GetRotationForCurrentRenderTarget(SDL_Renderer *renderer) } } -static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rect *sdlRect, D3D12_RECT *outRect, BOOL includeViewportOffset) +static bool D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rect *sdlRect, D3D12_RECT *outRect, BOOL includeViewportOffset) { D3D12_RenderData *data = (D3D12_RenderData *)renderer->internal; const int rotation = D3D12_GetRotationForCurrentRenderTarget(renderer); @@ -1208,7 +1208,7 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec default: return SDL_SetError("The physical display is in an unknown or unsupported rotation"); } - return 0; + return true; } #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) @@ -1539,7 +1539,7 @@ static void D3D12_FreeSRVIndex(SDL_Renderer *renderer, SIZE_T index) rendererData->srvPoolHead = &rendererData->srvPoolNodes[index]; } -static int GetTextureProperty(SDL_PropertiesID props, const char *name, ID3D12Resource **texture) +static bool GetTextureProperty(SDL_PropertiesID props, const char *name, ID3D12Resource **texture) { IUnknown *unknown = (IUnknown*)SDL_GetPointerProperty(props, name, NULL); if (unknown) { @@ -1552,10 +1552,10 @@ static int GetTextureProperty(SDL_PropertiesID props, const char *name, ID3D12Re return WIN_SetErrorFromHRESULT(name, result); } } - return 0; + return true; } -static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; D3D12_TextureData *textureData; @@ -1571,7 +1571,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureData = (D3D12_TextureData *)SDL_calloc(1, sizeof(*textureData)); if (!textureData) { - return -1; + return false; } textureData->scaleMode = (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? D3D12_FILTER_MIN_MAG_MIP_POINT : D3D12_FILTER_MIN_MAG_MIP_LINEAR; @@ -1613,8 +1613,8 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL heapProps.CreationNodeMask = 1; heapProps.VisibleNodeMask = 1; - if (GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER, &textureData->mainTexture) < 0) { - return -1; + if (!GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_POINTER, &textureData->mainTexture)) { + return false; } if (!textureData->mainTexture) { result = ID3D12Device1_CreateCommittedResource(rendererData->d3dDevice, @@ -1639,8 +1639,8 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureDesc.Width = (textureDesc.Width + 1) / 2; textureDesc.Height = (textureDesc.Height + 1) / 2; - if (GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER, &textureData->mainTextureU) < 0) { - return -1; + if (!GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_U_POINTER, &textureData->mainTextureU)) { + return false; } if (!textureData->mainTextureU) { result = ID3D12Device1_CreateCommittedResource(rendererData->d3dDevice, @@ -1658,8 +1658,8 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureData->mainResourceStateU = D3D12_RESOURCE_STATE_COPY_DEST; SDL_SetPointerProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_D3D12_TEXTURE_U_POINTER, textureData->mainTextureU); - if (GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER, &textureData->mainTextureV) < 0) { - return -1; + if (!GetTextureProperty(create_props, SDL_PROP_TEXTURE_CREATE_D3D12_TEXTURE_V_POINTER, &textureData->mainTextureV)) { + return false; } if (!textureData->mainTextureV) { result = ID3D12Device1_CreateCommittedResource(rendererData->d3dDevice, @@ -1773,7 +1773,7 @@ static int D3D12_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL textureData->mainTextureRenderTargetView); } - return 0; + return true; } static void D3D12_DestroyTexture(SDL_Renderer *renderer, @@ -1809,7 +1809,7 @@ static void D3D12_DestroyTexture(SDL_Renderer *renderer, texture->internal = NULL; } -static int D3D12_UpdateTextureInternal(D3D12_RenderData *rendererData, ID3D12Resource *texture, int plane, int x, int y, int w, int h, const void *pixels, int pitch, D3D12_RESOURCE_STATES *resourceState) +static bool D3D12_UpdateTextureInternal(D3D12_RenderData *rendererData, ID3D12Resource *texture, int plane, int x, int y, int w, int h, const void *pixels, int pitch, D3D12_RESOURCE_STATES *resourceState) { const Uint8 *src; Uint8 *dst; @@ -1944,10 +1944,10 @@ static int D3D12_UpdateTextureInternal(D3D12_RenderData *rendererData, ID3D12Res D3D12_IssueBatch(rendererData); } - return 0; + return true; } -static int D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *srcPixels, int srcPitch) { @@ -1958,22 +1958,22 @@ static int D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch, &textureData->mainResourceState) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch, &textureData->mainResourceState)) { + return false; } #if SDL_HAVE_YUV if (textureData->yuv) { // Skip to the correct offset into the next texture srcPixels = (const void *)((const Uint8 *)srcPixels + rect->h * srcPitch); - if (D3D12_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureV : textureData->mainTextureU, 0, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2, texture->format == SDL_PIXELFORMAT_YV12 ? &textureData->mainResourceStateV : &textureData->mainResourceStateU) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureV : textureData->mainTextureU, 0, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2, texture->format == SDL_PIXELFORMAT_YV12 ? &textureData->mainResourceStateV : &textureData->mainResourceStateU)) { + return false; } // Skip to the correct offset into the next texture srcPixels = (const void *)((const Uint8 *)srcPixels + ((rect->h + 1) / 2) * ((srcPitch + 1) / 2)); - if (D3D12_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureU : textureData->mainTextureV, 0, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2, texture->format == SDL_PIXELFORMAT_YV12 ? &textureData->mainResourceStateU : &textureData->mainResourceStateV) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, texture->format == SDL_PIXELFORMAT_YV12 ? textureData->mainTextureU : textureData->mainTextureV, 0, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2, texture->format == SDL_PIXELFORMAT_YV12 ? &textureData->mainResourceStateU : &textureData->mainResourceStateV)) { + return false; } } @@ -1986,16 +1986,16 @@ static int D3D12_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, } else { srcPitch = (srcPitch + 1) & ~1; } - if (D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 1, rect->x, rect->y, (rect->w + 1) & ~1, (rect->h + 1) & ~1, srcPixels, srcPitch, &textureData->mainResourceState) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 1, rect->x, rect->y, (rect->w + 1) & ~1, (rect->h + 1) & ~1, srcPixels, srcPitch, &textureData->mainResourceState)) { + return false; } } #endif // SDL_HAVE_YUV - return 0; + return true; } #if SDL_HAVE_YUV -static int D3D12_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D12_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -2008,19 +2008,19 @@ static int D3D12_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainResourceState) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainResourceState)) { + return false; } - if (D3D12_UpdateTextureInternal(rendererData, textureData->mainTextureU, 0, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch, &textureData->mainResourceStateU) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTextureU, 0, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch, &textureData->mainResourceStateU)) { + return false; } - if (D3D12_UpdateTextureInternal(rendererData, textureData->mainTextureV, 0, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch, &textureData->mainResourceStateV) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTextureV, 0, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch, &textureData->mainResourceStateV)) { + return false; } - return 0; + return true; } -static int D3D12_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D12_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) @@ -2032,18 +2032,18 @@ static int D3D12_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainResourceState) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainResourceState)) { + return false; } - if (D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 1, rect->x, rect->y, rect->w, rect->h, UVplane, UVpitch, &textureData->mainResourceState) < 0) { - return -1; + if (!D3D12_UpdateTextureInternal(rendererData, textureData->mainTexture, 1, rect->x, rect->y, rect->w, rect->h, UVplane, UVpitch, &textureData->mainResourceState)) { + return false; } - return 0; + return true; } #endif -static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; @@ -2067,7 +2067,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, textureData->pitch = texture->w; textureData->pixels = (Uint8 *)SDL_malloc((texture->h * textureData->pitch * 3) / 2); if (!textureData->pixels) { - return -1; + return false; } } textureData->lockedRect = *rect; @@ -2075,7 +2075,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, (void *)(textureData->pixels + rect->y * textureData->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = textureData->pitch; - return 0; + return true; } #endif if (textureData->stagingBuffer) { @@ -2161,7 +2161,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, */ *pixels = textureMemory; *pitch = pitchedDesc.RowPitch; - return 0; + return true; } static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -2254,7 +2254,7 @@ static void D3D12_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu textureData->scaleMode = (scaleMode == SDL_SCALEMODE_NEAREST) ? D3D12_FILTER_MIN_MAG_MIP_POINT : D3D12_FILTER_MIN_MAG_MIP_LINEAR; } -static int D3D12_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool D3D12_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; D3D12_TextureData *textureData = NULL; @@ -2268,7 +2268,7 @@ static int D3D12_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) rendererData->textureRenderTarget->mainResourceState = D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE; } rendererData->textureRenderTarget = NULL; - return 0; + return true; } textureData = (D3D12_TextureData *)texture->internal; @@ -2284,15 +2284,15 @@ static int D3D12_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) D3D12_RESOURCE_STATE_RENDER_TARGET); rendererData->textureRenderTarget->mainResourceState = D3D12_RESOURCE_STATE_RENDER_TARGET; - return 0; + return true; } -static int D3D12_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool D3D12_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int D3D12_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool D3D12_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); int i; @@ -2300,7 +2300,7 @@ static int D3D12_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, bool convert_color = SDL_RenderingLinearSpace(renderer); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -2318,10 +2318,10 @@ static int D3D12_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, verts++; } - return 0; + return true; } -static int D3D12_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool D3D12_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -2335,7 +2335,7 @@ static int D3D12_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S float v_scale = textureData ? (float)texture->h / textureData->h : 0.0f; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -2374,10 +2374,10 @@ static int D3D12_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S verts += 1; } - return 0; + return true; } -static int D3D12_UpdateVertexBuffer(SDL_Renderer *renderer, +static bool D3D12_UpdateVertexBuffer(SDL_Renderer *renderer, const void *vertexData, size_t dataSizeInBytes) { D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; @@ -2391,7 +2391,7 @@ static int D3D12_UpdateVertexBuffer(SDL_Renderer *renderer, range.End = 0; if (dataSizeInBytes == 0) { - return 0; // nothing to do. + return true; // nothing to do. } if (rendererData->issueBatch) { @@ -2427,7 +2427,7 @@ static int D3D12_UpdateVertexBuffer(SDL_Renderer *renderer, return S_OK; } -static int D3D12_UpdateViewport(SDL_Renderer *renderer) +static bool D3D12_UpdateViewport(SDL_Renderer *renderer) { D3D12_RenderData *data = (D3D12_RenderData *)renderer->internal; const SDL_Rect *viewport = &data->currentViewport; @@ -2444,7 +2444,7 @@ static int D3D12_UpdateViewport(SDL_Renderer *renderer) * with a non-empty viewport. */ // SDL_Log("%s, no viewport was set!\n", __FUNCTION__); - return -1; + return false; } /* Make sure the SDL viewport gets rotated to that of the physical display's rotation. @@ -2515,7 +2515,7 @@ static int D3D12_UpdateViewport(SDL_Renderer *renderer) data->viewportDirty = false; - return 0; + return true; } static void D3D12_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, PixelShaderConstants *constants) @@ -2580,7 +2580,7 @@ static void D3D12_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderC } } -static int D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, D3D12_Shader shader, const PixelShaderConstants *shader_constants, +static bool D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, D3D12_Shader shader, const PixelShaderConstants *shader_constants, D3D12_PRIMITIVE_TOPOLOGY_TYPE topology, const int numShaderResources, D3D12_CPU_DESCRIPTOR_HANDLE *shaderResources, D3D12_CPU_DESCRIPTOR_HANDLE *sampler, const Float4X4 *matrix) @@ -2633,7 +2633,7 @@ static int D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c if (!currentPipelineState) { // The error has been set inside D3D12_CreatePipelineState() - return -1; + return false; } ID3D12GraphicsCommandList2_SetPipelineState(rendererData->commandList, currentPipelineState->pipelineState); @@ -2652,7 +2652,7 @@ static int D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c } if (rendererData->viewportDirty) { - if (D3D12_UpdateViewport(renderer) == 0) { + if (D3D12_UpdateViewport(renderer)) { // vertexShaderConstantsData.projectionAndView has changed updateSubresource = true; } @@ -2660,9 +2660,9 @@ static int D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c if (rendererData->cliprectDirty) { D3D12_RECT scissorRect; - if (D3D12_GetViewportAlignedD3DRect(renderer, &rendererData->currentCliprect, &scissorRect, TRUE) != 0) { + if (!D3D12_GetViewportAlignedD3DRect(renderer, &rendererData->currentCliprect, &scissorRect, TRUE)) { // D3D12_GetViewportAlignedD3DRect will have set the SDL error - return -1; + return false; } ID3D12GraphicsCommandList2_RSSetScissorRects(rendererData->commandList, 1, &scissorRect); rendererData->cliprectDirty = false; @@ -2727,10 +2727,10 @@ static int D3D12_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *c SDL_memcpy(¤tPipelineState->shader_constants, shader_constants, sizeof(*shader_constants)); } - return 0; + return true; } -static int D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const Float4X4 *matrix) +static bool D3D12_SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const Float4X4 *matrix) { SDL_Texture *texture = cmd->data.draw.texture; D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; @@ -2820,7 +2820,7 @@ static void D3D12_InvalidateCachedState(SDL_Renderer *renderer) data->viewportDirty = true; } -static int D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { D3D12_RenderData *rendererData = (D3D12_RenderData *)renderer->internal; const int viewportRotation = D3D12_GetRotationForCurrentRenderTarget(renderer); @@ -2835,8 +2835,8 @@ static int D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, rendererData->viewportDirty = true; } - if (D3D12_UpdateVertexBuffer(renderer, vertices, vertsize) < 0) { - return -1; + if (!D3D12_UpdateVertexBuffer(renderer, vertices, vertsize)) { + return false; } while (cmd) { @@ -2953,7 +2953,7 @@ static int D3D12_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, cmd = cmd->next; } - return 0; + return true; } static SDL_Surface *D3D12_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect) @@ -3032,7 +3032,7 @@ static SDL_Surface *D3D12_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec D3D12_TransitionResource(data, backBuffer, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); // Copy the desired portion of the back buffer to the staging texture: - if (D3D12_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE) != 0) { + if (!D3D12_GetViewportAlignedD3DRect(renderer, rect, &srcRect, FALSE)) { // D3D12_GetViewportAlignedD3DRect will have set the SDL error goto done; } @@ -3103,7 +3103,7 @@ done: return output; } -static int D3D12_RenderPresent(SDL_Renderer *renderer) +static bool D3D12_RenderPresent(SDL_Renderer *renderer) { D3D12_RenderData *data = (D3D12_RenderData *)renderer->internal; HRESULT result; @@ -3139,7 +3139,7 @@ static int D3D12_RenderPresent(SDL_Renderer *renderer) } else { WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain::Present"), result); } - return -1; + return false; } else { // Wait for the GPU and move to the next frame result = ID3D12CommandQueue_Signal(data->commandQueue, data->fence, data->fenceValue); @@ -3169,11 +3169,11 @@ static int D3D12_RenderPresent(SDL_Renderer *renderer) #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) D3D12_XBOX_StartFrame(data->d3dDevice, &data->frameToken); #endif - return 0; + return true; } } -static int D3D12_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool D3D12_SetVSync(SDL_Renderer *renderer, const int vsync) { D3D12_RenderData *data = (D3D12_RenderData *)renderer->internal; @@ -3188,10 +3188,10 @@ static int D3D12_SetVSync(SDL_Renderer *renderer, const int vsync) data->syncInterval = 0; data->presentFlags = DXGI_PRESENT_ALLOW_TEARING; } - return 0; + return true; } -int D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +bool D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { D3D12_RenderData *data; @@ -3215,7 +3215,7 @@ int D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propert data = (D3D12_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } data->identity = MatrixIdentity(); @@ -3269,13 +3269,13 @@ int D3D12_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Propert // Initialize Direct3D resources if (FAILED(D3D12_CreateDeviceResources(renderer))) { - return -1; + return false; } if (FAILED(D3D12_CreateWindowSizeDependentResources(renderer))) { - return -1; + return false; } - return 0; + return true; } SDL_RenderDriver D3D12_RenderDriver = { diff --git a/src/render/direct3d12/SDL_render_d3d12_xbox.cpp b/src/render/direct3d12/SDL_render_d3d12_xbox.cpp index 0b79e36bfd..0a191991af 100644 --- a/src/render/direct3d12/SDL_render_d3d12_xbox.cpp +++ b/src/render/direct3d12/SDL_render_d3d12_xbox.cpp @@ -35,8 +35,8 @@ static const GUID SDL_IID_ID3D12Device1 = { 0x77acce80, 0x638e, 0x4e65, { 0x88, static const GUID SDL_IID_ID3D12Resource = { 0x696442be, 0xa72e, 0x4059, { 0xbc, 0x79, 0x5b, 0x5c, 0x98, 0x04, 0x0f, 0xad } }; static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } }; -extern "C" HRESULT -D3D12_XBOX_CreateDevice(ID3D12Device **device, bool createDebug) +extern "C" +HRESULT D3D12_XBOX_CreateDevice(ID3D12Device **device, bool createDebug) { HRESULT result; D3D12XBOX_CREATE_DEVICE_PARAMETERS params; @@ -92,8 +92,8 @@ done: return result; } -extern "C" HRESULT -D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, void **resource) +extern "C" +HRESULT D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, void **resource) { D3D12_HEAP_PROPERTIES heapProps; @@ -129,15 +129,15 @@ D3D12_XBOX_CreateBackBufferTarget(ID3D12Device1 *device, int width, int height, ); } -extern "C" HRESULT -D3D12_XBOX_StartFrame(ID3D12Device1 *device, UINT64 *outToken) +extern "C" +HRESULT D3D12_XBOX_StartFrame(ID3D12Device1 *device, UINT64 *outToken) { *outToken = D3D12XBOX_FRAME_PIPELINE_TOKEN_NULL; return device->WaitFrameEventX(D3D12XBOX_FRAME_EVENT_ORIGIN, INFINITE, NULL, D3D12XBOX_WAIT_FRAME_EVENT_FLAG_NONE, outToken); } -extern "C" HRESULT -D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Resource *renderTarget) +extern "C" +HRESULT D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Resource *renderTarget) { D3D12XBOX_PRESENT_PLANE_PARAMETERS planeParameters; SDL_zero(planeParameters); @@ -147,8 +147,8 @@ D3D12_XBOX_PresentFrame(ID3D12CommandQueue *commandQueue, UINT64 token, ID3D12Re return commandQueue->PresentX(1, &planeParameters, NULL); } -extern "C" void -D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height) +extern "C" +void D3D12_XBOX_GetResolution(Uint32 *width, Uint32 *height) { switch (XSystemGetDeviceType()) { case XSystemDeviceType::XboxScarlettLockhart: diff --git a/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp b/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp index cd3609b849..be952df3b7 100644 --- a/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp +++ b/src/render/direct3d12/SDL_shaders_d3d12_xboxone.cpp @@ -101,28 +101,28 @@ static struct { D3D12_RootSig_Advanced, sizeof(D3D12_RootSig_Advanced) }, }; -extern "C" void -D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +extern "C" +void D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) { outBytecode->pShaderBytecode = D3D12_shaders[shader].vs_shader_data; outBytecode->BytecodeLength = D3D12_shaders[shader].vs_shader_size; } -extern "C" void -D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +extern "C" +void D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) { outBytecode->pShaderBytecode = D3D12_shaders[shader].ps_shader_data; outBytecode->BytecodeLength = D3D12_shaders[shader].ps_shader_size; } -extern "C" D3D12_RootSignature -D3D12_GetRootSignatureType(D3D12_Shader shader) +extern "C" +D3D12_RootSignature D3D12_GetRootSignatureType(D3D12_Shader shader) { return D3D12_shaders[shader].root_sig; } -extern "C" void -D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode) +extern "C" +void D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode) { outBytecode->pShaderBytecode = D3D12_rootsigs[rootSig].rs_shader_data; outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size; diff --git a/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp b/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp index a949b7e753..939e941de7 100644 --- a/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp +++ b/src/render/direct3d12/SDL_shaders_d3d12_xboxseries.cpp @@ -102,28 +102,28 @@ static struct { D3D12_RootSig_Advanced, sizeof(D3D12_RootSig_Advanced) }, }; -extern "C" void -D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +extern "C" +void D3D12_GetVertexShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) { outBytecode->pShaderBytecode = D3D12_shaders[shader].vs_shader_data; outBytecode->BytecodeLength = D3D12_shaders[shader].vs_shader_size; } -extern "C" void -D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) +extern "C" +void D3D12_GetPixelShader(D3D12_Shader shader, D3D12_SHADER_BYTECODE *outBytecode) { outBytecode->pShaderBytecode = D3D12_shaders[shader].ps_shader_data; outBytecode->BytecodeLength = D3D12_shaders[shader].ps_shader_size; } -extern "C" D3D12_RootSignature -D3D12_GetRootSignatureType(D3D12_Shader shader) +extern "C" +D3D12_RootSignature D3D12_GetRootSignatureType(D3D12_Shader shader) { return D3D12_shaders[shader].root_sig; } -extern "C" void -D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode) +extern "C" +void D3D12_GetRootSignatureData(D3D12_RootSignature rootSig, D3D12_SHADER_BYTECODE *outBytecode) { outBytecode->pShaderBytecode = D3D12_rootsigs[rootSig].rs_shader_data; outBytecode->BytecodeLength = D3D12_rootsigs[rootSig].rs_shader_size; diff --git a/src/render/metal/SDL_render_metal.m b/src/render/metal/SDL_render_metal.m index 41fae98271..cba61bdc97 100644 --- a/src/render/metal/SDL_render_metal.m +++ b/src/render/metal/SDL_render_metal.m @@ -517,7 +517,7 @@ static void METAL_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *eve { } -static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) +static bool METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) { @autoreleasepool { SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal; @@ -527,7 +527,7 @@ static int METAL_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) if (h) { *h = (int)data.mtllayer.drawableSize.height; } - return 0; + return true; } } @@ -629,7 +629,7 @@ size_t GetYCbCRtoRGBConversionMatrix(SDL_Colorspace colorspace, int w, int h, in return 0; } -static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { @autoreleasepool { SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal; @@ -771,7 +771,7 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL #endif texture->internal = (void *)CFBridgingRetain(texturedata); - return 0; + return true; } } @@ -795,7 +795,7 @@ static MTLStorageMode METAL_GetStorageMode(id resource) return MTLStorageModeShared; } -static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, SDL3METAL_TextureData *texturedata, +static bool METAL_UpdateTextureInternal(SDL_Renderer *renderer, SDL3METAL_TextureData *texturedata, id texture, SDL_Rect rect, int slice, const void *pixels, int pitch) { @@ -810,7 +810,7 @@ static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, SDL3METAL_Texture * to a staging texture and copy that over. */ if (!texturedata.hasdata && METAL_GetStorageMode(texture) != MTLStorageModePrivate) { METAL_UploadTextureData(texture, rect, slice, pixels, pitch); - return 0; + return true; } desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:texture.pixelFormat @@ -860,17 +860,17 @@ static int METAL_UpdateTextureInternal(SDL_Renderer *renderer, SDL3METAL_Texture [data.mtlcmdbuffer commit]; data.mtlcmdbuffer = nil; - return 0; + return true; } -static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { @autoreleasepool { SDL3METAL_TextureData *texturedata = (__bridge SDL3METAL_TextureData *)texture->internal; - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, pixels, pitch) < 0) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, pixels, pitch)) { + return false; } #if SDL_HAVE_YUV if (texturedata.yuv) { @@ -881,14 +881,14 @@ static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, // Skip to the correct offset into the next texture pixels = (const void *)((const Uint8 *)pixels + rect->h * pitch); - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Uslice, pixels, UVpitch) < 0) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Uslice, pixels, UVpitch)) { + return false; } // Skip to the correct offset into the next texture pixels = (const void *)((const Uint8 *)pixels + UVrect.h * UVpitch); - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Vslice, pixels, UVpitch) < 0) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Vslice, pixels, UVpitch)) { + return false; } } @@ -898,19 +898,19 @@ static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, // Skip to the correct offset into the next texture pixels = (const void *)((const Uint8 *)pixels + rect->h * pitch); - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, 0, pixels, UVpitch) < 0) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, 0, pixels, UVpitch)) { + return false; } } #endif texturedata.hasdata = YES; - return 0; + return true; } } #if SDL_HAVE_YUV -static int METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -924,26 +924,26 @@ static int METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, // Bail out if we're supposed to update an empty rectangle if (rect->w <= 0 || rect->h <= 0) { - return 0; + return true; } - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, Yplane, Ypitch) < 0) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, Yplane, Ypitch)) { + return false; } - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Uslice, Uplane, Upitch)) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Uslice, Uplane, Upitch)) { + return false; } - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Vslice, Vplane, Vpitch)) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Vslice, Vplane, Vpitch)) { + return false; } texturedata.hasdata = YES; - return 0; + return true; } } -static int METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) @@ -954,25 +954,25 @@ static int METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, // Bail out if we're supposed to update an empty rectangle if (rect->w <= 0 || rect->h <= 0) { - return 0; + return true; } - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, Yplane, Ypitch) < 0) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, Yplane, Ypitch)) { + return false; } - if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, 0, UVplane, UVpitch) < 0) { - return -1; + if (!METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, 0, UVplane, UVpitch)) { + return false; } texturedata.hasdata = YES; - return 0; + return true; } } #endif -static int METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { @autoreleasepool { @@ -1004,7 +1004,7 @@ static int METAL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, texturedata.lockedbuffer = lockedbuffer; *pixels = [lockedbuffer contents]; - return 0; + return true; } } @@ -1099,7 +1099,7 @@ static void METAL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu { } -static int METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { @autoreleasepool { SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal; @@ -1117,11 +1117,11 @@ static int METAL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) /* We don't begin a new render pass right away - we delay it until an actual * draw or clear happens. That way we can use hardware clears when possible, * which are only available when beginning a new render pass. */ - return 0; + return true; } } -static int METAL_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool METAL_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { float projection[4][4]; // Prepare an orthographic projection const int w = cmd->data.viewport.rect.w; @@ -1129,7 +1129,7 @@ static int METAL_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd const size_t matrixlen = sizeof(projection); float *matrix = (float *)SDL_AllocateRenderVertices(renderer, matrixlen, CONSTANT_ALIGN(16), &cmd->data.viewport.first); if (!matrix) { - return -1; + return false; } SDL_memset(projection, '\0', matrixlen); @@ -1142,15 +1142,15 @@ static int METAL_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd } SDL_memcpy(matrix, projection, matrixlen); - return 0; + return true; } -static int METAL_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool METAL_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int METAL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool METAL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { SDL_FColor color = cmd->data.draw.color; bool convert_color = SDL_RenderingLinearSpace(renderer); @@ -1158,7 +1158,7 @@ static int METAL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const size_t vertlen = (2 * sizeof(float) + 4 * sizeof(float)) * count; float *verts = (float *)SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -1174,10 +1174,10 @@ static int METAL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, *(verts++) = color.b; *(verts++) = color.a; } - return 0; + return true; } -static int METAL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool METAL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { SDL_FColor color = cmd->data.draw.color; bool convert_color = SDL_RenderingLinearSpace(renderer); @@ -1189,7 +1189,7 @@ static int METAL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vertlen = (2 * sizeof(float) + 4 * sizeof(float)) * count; verts = (float *)SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -1230,10 +1230,10 @@ static int METAL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, } } - return 0; + return true; } -static int METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -1243,7 +1243,7 @@ static int METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S const size_t vertlen = (2 * sizeof(float) + 4 * sizeof(float) + (texture ? 2 : 0) * sizeof(float)) * count; float *verts = (float *)SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -1286,7 +1286,7 @@ static int METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S } } - return 0; + return true; } // These should mirror the definitions in SDL_shaders_metal.metal @@ -1540,7 +1540,7 @@ static void METAL_InvalidateCachedState(SDL_Renderer *renderer) // METAL_DrawStateCache only exists during a run of METAL_RunCommandQueue, so there's nothing to invalidate! } -static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { @autoreleasepool { SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal; @@ -1685,7 +1685,7 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, cmd = cmd->next; } - return 0; + return true; } } @@ -1754,7 +1754,7 @@ static SDL_Surface *METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec } } -static int METAL_RenderPresent(SDL_Renderer *renderer) +static bool METAL_RenderPresent(SDL_Renderer *renderer) { @autoreleasepool { SDL3METAL_RenderData *data = (__bridge SDL3METAL_RenderData *)renderer->internal; @@ -1788,9 +1788,9 @@ static int METAL_RenderPresent(SDL_Renderer *renderer) data.mtlbackbuffer = nil; if (renderer->hidden || !ready) { - return -1; + return false; } - return 0; + return true; } } @@ -1844,7 +1844,7 @@ static void *METAL_GetMetalCommandEncoder(SDL_Renderer *renderer) } } -static int METAL_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool METAL_SetVSync(SDL_Renderer *renderer, const int vsync) { #if (defined(SDL_PLATFORM_MACOS) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST if (@available(macOS 10.13, *)) { @@ -1859,12 +1859,12 @@ static int METAL_SetVSync(SDL_Renderer *renderer, const int vsync) default: return SDL_Unsupported(); } - return 0; + return true; } #endif switch (vsync) { case 1: - return 0; + return true; default: return SDL_Unsupported(); } @@ -1900,7 +1900,7 @@ static SDL_MetalView GetWindowView(SDL_Window *window) return nil; } -static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { @autoreleasepool { SDL3METAL_RenderData *data = NULL; @@ -1963,7 +1963,7 @@ static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ const size_t YCbCr_shader_matrix_size = 4 * 4 * sizeof(float); if (!IsMetalAvailable()) { - return -1; + return false; } SDL_SetupRendererColorspace(renderer, create_props); @@ -2008,7 +2008,7 @@ static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ } if (view == NULL) { - return -1; + return false; } // !!! FIXME: error checking on all of this. @@ -2232,7 +2232,7 @@ static int METAL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, maxtexsize); - return 0; + return true; } } diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 03fa8da010..6dda763e7d 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -196,20 +196,20 @@ static void GL_ClearErrors(SDL_Renderer *renderer) } } -static int GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function) +static bool GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function) { GL_RenderData *data = (GL_RenderData *)renderer->internal; - int ret = 0; + bool result = true; if (!data->debug_enabled) { - return 0; + return true; } if (data->GL_ARB_debug_output_supported) { if (data->errors) { int i; for (i = 0; i < data->errors; ++i) { SDL_SetError("%s: %s (%d): %s %s", prefix, file, line, function, data->error_messages[i]); - ret = -1; + result = false; } GL_ClearErrors(renderer); } @@ -222,13 +222,13 @@ static int GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const c prefix = "generic"; } SDL_SetError("%s: %s (%d): %s %s (0x%X)", prefix, file, line, function, GL_TranslateError(error), error); - ret = -1; + result = false; } else { break; } } } - return ret; + return result; } #if 0 @@ -237,39 +237,39 @@ static int GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const c #define GL_CheckError(prefix, renderer) GL_CheckAllErrors(prefix, renderer, SDL_FILE, SDL_LINE, SDL_FUNCTION) #endif -static int GL_LoadFunctions(GL_RenderData *data) +static bool GL_LoadFunctions(GL_RenderData *data) { #ifdef __SDL_NOGETPROCADDR__ #define SDL_PROC(ret, func, params) data->func = func; #else - int retval = 0; + bool result = true; #define SDL_PROC(ret, func, params) \ do { \ data->func = (ret (APIENTRY *) params)SDL_GL_GetProcAddress(#func); \ if (!data->func) { \ - retval = SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \ + result = SDL_SetError("Couldn't load GL function %s: %s", #func, SDL_GetError()); \ } \ } while (0); #endif // __SDL_NOGETPROCADDR__ #include "SDL_glfuncs.h" #undef SDL_PROC - return retval; + return result; } -static int GL_ActivateRenderer(SDL_Renderer *renderer) +static bool GL_ActivateRenderer(SDL_Renderer *renderer) { GL_RenderData *data = (GL_RenderData *)renderer->internal; if (SDL_GL_GetCurrentContext() != data->context) { - if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) { - return -1; + if (!SDL_GL_MakeCurrent(renderer->window, data->context)) { + return false; } } GL_ClearErrors(renderer); - return 0; + return true; } static void APIENTRY GL_HandleDebugMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const char *message, const void *userParam) @@ -439,7 +439,7 @@ static bool convert_format(Uint32 pixel_format, GLint *internalFormat, GLenum *f return true; } -static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { GL_RenderData *renderdata = (GL_RenderData *)renderer->internal; const GLenum textype = renderdata->textype; @@ -466,7 +466,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr data = (GL_TextureData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -486,7 +486,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr data->pixels = SDL_calloc(1, size); if (!data->pixels) { SDL_free(data); - return -1; + return false; } } @@ -502,12 +502,12 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr } else { GL_CheckError("", renderer); renderdata->glGenTextures(1, &data->texture); - if (GL_CheckError("glGenTextures()", renderer) < 0) { + if (!GL_CheckError("glGenTextures()", renderer)) { if (data->pixels) { SDL_free(data->pixels); } SDL_free(data); - return -1; + return false; } } texture->internal = data; @@ -573,8 +573,8 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr texture_h, 0, format, type, NULL); } renderdata->glDisable(textype); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; + if (!GL_CheckError("glTexImage2D()", renderer)) { + return false; } #if SDL_HAVE_YUV @@ -668,7 +668,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr return GL_CheckError("", renderer); } -static int GL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool GL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { GL_RenderData *renderdata = (GL_RenderData *)renderer->internal; @@ -730,7 +730,7 @@ static int GL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, } #if SDL_HAVE_YUV -static int GL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool GL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -766,7 +766,7 @@ static int GL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, return GL_CheckError("glTexSubImage2D()", renderer); } -static int GL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool GL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) @@ -796,7 +796,7 @@ static int GL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, } #endif -static int GL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool GL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { GL_TextureData *data = (GL_TextureData *)texture->internal; @@ -806,7 +806,7 @@ static int GL_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, (void *)((Uint8 *)data->pixels + rect->y * data->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = data->pitch; - return 0; + return true; } static void GL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -854,7 +854,7 @@ static void GL_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, #endif } -static int GL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool GL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { GL_RenderData *data = (GL_RenderData *)renderer->internal; GL_TextureData *texturedata; @@ -870,7 +870,7 @@ static int GL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) if (!texture) { data->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - return 0; + return true; } texturedata = (GL_TextureData *)texture->internal; @@ -882,24 +882,24 @@ static int GL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { return SDL_SetError("glFramebufferTexture2DEXT() failed"); } - return 0; + return true; } /* !!! FIXME: all these Queue* calls set up the vertex buffer the way the immediate mode !!! FIXME: renderer wants it, but this might want to operate differently if we move to !!! FIXME: VBOs at some point. */ -static int GL_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool GL_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int GL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool GL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(GLfloat), 0, &cmd->data.draw.first); int i; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -908,10 +908,10 @@ static int GL_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, co *(verts++) = 0.5f + points[i].y; } - return 0; + return true; } -static int GL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool GL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { int i; GLfloat prevx, prevy; @@ -919,7 +919,7 @@ static int GL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, con GLfloat *verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -948,10 +948,10 @@ static int GL_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, con *(verts++) = prevy; } - return 0; + return true; } -static int GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -965,7 +965,7 @@ static int GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_ verts = (GLfloat *)SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } if (texture) { @@ -1006,10 +1006,10 @@ static int GL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_ *(verts++) = uv_[1] * texturedata->texh; } } - return 0; + return true; } -static int SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, const GL_Shader shader, const float *shader_params) +static bool SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, const GL_Shader shader, const float *shader_params) { const SDL_BlendMode blend = cmd->data.draw.blend; bool vertex_array; @@ -1117,10 +1117,10 @@ static int SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, const data->drawstate.texture_array = texture_array; } - return 0; + return true; } -static int SetTextureAddressMode(GL_RenderData *data, GLenum textype, SDL_TextureAddressMode addressMode) +static bool SetTextureAddressMode(GL_RenderData *data, GLenum textype, SDL_TextureAddressMode addressMode) { switch (addressMode) { case SDL_TEXTURE_ADDRESS_CLAMP: @@ -1134,10 +1134,10 @@ static int SetTextureAddressMode(GL_RenderData *data, GLenum textype, SDL_Textur default: return SDL_SetError("Unknown texture address mode: %d\n", addressMode); } - return 0; + return true; } -static int SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) +static bool SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) { SDL_Texture *texture = cmd->data.draw.texture; const GL_TextureData *texturedata = (GL_TextureData *)texture->internal; @@ -1153,8 +1153,8 @@ static int SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) } data->glBindTexture(textype, texturedata->vtexture); - if (SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode)) { + return false; } if (data->GL_ARB_multitexture_supported) { @@ -1162,8 +1162,8 @@ static int SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) } data->glBindTexture(textype, texturedata->utexture); - if (SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode)) { + return false; } } if (texturedata->nv12) { @@ -1172,8 +1172,8 @@ static int SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) } data->glBindTexture(textype, texturedata->utexture); - if (SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode)) { + return false; } } #endif @@ -1182,14 +1182,14 @@ static int SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd) } data->glBindTexture(textype, texturedata->texture); - if (SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, textype, cmd->data.draw.texture_address_mode)) { + return false; } data->drawstate.texture = texture; } - return 0; + return true; } static void GL_InvalidateCachedState(SDL_Renderer *renderer) @@ -1211,13 +1211,13 @@ static void GL_InvalidateCachedState(SDL_Renderer *renderer) cache->clear_color_dirty = true; } -static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { // !!! FIXME: it'd be nice to use a vertex buffer instead of immediate mode... GL_RenderData *data = (GL_RenderData *)renderer->internal; - if (GL_ActivateRenderer(renderer) < 0) { - return -1; + if (!GL_ActivateRenderer(renderer)) { + return false; } data->drawstate.target = renderer->target; @@ -1327,7 +1327,7 @@ static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo case SDL_RENDERCMD_DRAW_LINES: { - if (SetDrawState(data, cmd, SHADER_SOLID, NULL) == 0) { + if (SetDrawState(data, cmd, SHADER_SOLID, NULL)) { size_t count = cmd->data.draw.count; const GLfloat *verts = (GLfloat *)(((Uint8 *)vertices) + cmd->data.draw.first); @@ -1396,7 +1396,7 @@ static int GL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo ret = SetDrawState(data, cmd, SHADER_SOLID, NULL); } - if (ret == 0) { + if (ret) { const GLfloat *verts = (GLfloat *)(((Uint8 *)vertices) + cmd->data.draw.first); int op = GL_TRIANGLES; // SDL_RENDERCMD_GEOMETRY if (thiscmdtype == SDL_RENDERCMD_DRAW_POINTS) { @@ -1488,7 +1488,7 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect * data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h, rect->w, rect->h, targetFormat, type, surface->pixels); - if (GL_CheckError("glReadPixels()", renderer) < 0) { + if (!GL_CheckError("glReadPixels()", renderer)) { SDL_DestroySurface(surface); return NULL; } @@ -1513,7 +1513,7 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect * return surface; } -static int GL_RenderPresent(SDL_Renderer *renderer) +static bool GL_RenderPresent(SDL_Renderer *renderer) { GL_ActivateRenderer(renderer); @@ -1596,27 +1596,25 @@ static void GL_DestroyRenderer(SDL_Renderer *renderer) } } -static int GL_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool GL_SetVSync(SDL_Renderer *renderer, const int vsync) { - int retval; int interval = 0; - retval = SDL_GL_SetSwapInterval(vsync); - if (retval < 0) { - return retval; + if (!SDL_GL_SetSwapInterval(vsync)) { + return false; } - retval = SDL_GL_GetSwapInterval(&interval); - if (retval < 0) { - return retval; + if (!SDL_GL_GetSwapInterval(&interval)) { + return false; } + if (interval != vsync) { return SDL_Unsupported(); } - return 0; + return true; } -static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { GL_RenderData *data = NULL; GLint value; @@ -1641,7 +1639,7 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR); - if (SDL_RecreateWindow(window, (window_flags & ~(SDL_WINDOW_VULKAN | SDL_WINDOW_METAL)) | SDL_WINDOW_OPENGL) < 0) { + if (!SDL_RecreateWindow(window, (window_flags & ~(SDL_WINDOW_VULKAN | SDL_WINDOW_METAL)) | SDL_WINDOW_OPENGL)) { goto error; } } @@ -1697,11 +1695,11 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro if (!data->context) { goto error; } - if (SDL_GL_MakeCurrent(window, data->context) < 0) { + if (!SDL_GL_MakeCurrent(window, data->context)) { goto error; } - if (GL_LoadFunctions(data) < 0) { + if (!GL_LoadFunctions(data)) { goto error; } @@ -1713,7 +1711,7 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro #endif // Check for debug output support - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 && + if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) && (value & SDL_GL_CONTEXT_DEBUG_FLAG)) { data->debug_enabled = true; } @@ -1841,7 +1839,7 @@ static int GL_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro data->drawstate.clear_color.b = 1.0f; data->drawstate.clear_color.a = 1.0f; - return 0; + return true; error: if (changed_window) { @@ -1854,7 +1852,7 @@ error: SDL_SetError("%s", error); SDL_free(error); } - return -1; + return false; } SDL_RenderDriver GL_RenderDriver = { diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 80a02f72f8..3fc9b270e3 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -223,13 +223,13 @@ static void GL_ClearErrors(SDL_Renderer *renderer) } } -static int GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function) +static bool GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const char *file, int line, const char *function) { GLES2_RenderData *data = (GLES2_RenderData *)renderer->internal; - int ret = 0; + bool result = true; if (!data->debug_enabled) { - return 0; + return true; } // check gl errors (can return multiple errors) for (;;) { @@ -239,12 +239,12 @@ static int GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const c prefix = "generic"; } SDL_SetError("%s: %s (%d): %s %s (0x%X)", prefix, file, line, function, GL_TranslateError(error), error); - ret = -1; + result = false; } else { break; } } - return ret; + return result; } #if 0 @@ -257,7 +257,7 @@ static int GL_CheckAllErrors(const char *prefix, SDL_Renderer *renderer, const c * Renderer state APIs * *************************************************************************************************/ -static int GLES2_LoadFunctions(GLES2_RenderData *data) +static bool GLES2_LoadFunctions(GLES2_RenderData *data) { #ifdef SDL_VIDEO_DRIVER_UIKIT #define __SDL_NOGETPROCADDR__ @@ -279,7 +279,7 @@ static int GLES2_LoadFunctions(GLES2_RenderData *data) #include "SDL_gles2funcs.h" #undef SDL_PROC - return 0; + return true; } static GLES2_FBOList *GLES2_GetFBO(GLES2_RenderData *data, Uint32 w, Uint32 h) @@ -299,7 +299,7 @@ static GLES2_FBOList *GLES2_GetFBO(GLES2_RenderData *data, Uint32 w, Uint32 h) return result; } -static int GLES2_ActivateRenderer(SDL_Renderer *renderer) +static bool GLES2_ActivateRenderer(SDL_Renderer *renderer) { GLES2_RenderData *data = (GLES2_RenderData *)renderer->internal; @@ -307,14 +307,14 @@ static int GLES2_ActivateRenderer(SDL_Renderer *renderer) // Null out the current program to ensure we set it again data->drawstate.program = NULL; - if (SDL_GL_MakeCurrent(renderer->window, data->context) < 0) { - return -1; + if (!SDL_GL_MakeCurrent(renderer->window, data->context)) { + return false; } } GL_ClearErrors(renderer); - return 0; + return true; } static void GLES2_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event) @@ -509,7 +509,7 @@ static GLuint GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, G if (!shader_body) { SDL_SetError("No shader body src"); - return 0; + return true; } for (attempt = 0; attempt < 2 && !compileSuccessful; ++attempt) { @@ -570,7 +570,7 @@ static GLuint GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, G SDL_SetError("Failed to load the shader %d", type); } data->glDeleteShader(id); - return 0; + return true; } // Cache @@ -579,7 +579,7 @@ static GLuint GLES2_CacheShader(GLES2_RenderData *data, GLES2_ShaderType type, G return id; } -static int GLES2_CacheShaders(GLES2_RenderData *data) +static bool GLES2_CacheShaders(GLES2_RenderData *data) { int shader; @@ -594,13 +594,13 @@ static int GLES2_CacheShaders(GLES2_RenderData *data) shader_type = GL_FRAGMENT_SHADER; } if (!GLES2_CacheShader(data, (GLES2_ShaderType)shader, shader_type)) { - return -1; + return false; } } - return 0; + return true; } -static int GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source, SDL_Colorspace colorspace) +static bool GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source, SDL_Colorspace colorspace) { GLuint vertex; GLuint fragment; @@ -689,7 +689,7 @@ static int GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source, data->drawstate.program->vertex_shader == vertex && data->drawstate.program->fragment_shader == fragment && data->drawstate.program->shader_params == shader_params) { - return 0; + return true; } // Generate a matching program @@ -727,18 +727,18 @@ static int GLES2_SelectProgram(GLES2_RenderData *data, GLES2_ImageSource source, data->drawstate.program = program; // Clean up and return - return 0; + return true; fault: data->drawstate.program = NULL; - return -1; + return false; } -static int GLES2_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool GLES2_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { const bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32)); SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first); @@ -747,7 +747,7 @@ static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const float color_scale = cmd->data.draw.color_scale; if (!verts) { - return -1; + return false; } color.r *= color_scale; @@ -768,10 +768,10 @@ static int GLES2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, verts++; } - return 0; + return true; } -static int GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { const bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32)); int i; @@ -781,7 +781,7 @@ static int GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const float color_scale = cmd->data.draw.color_scale; if (!verts) { - return -1; + return false; } color.r *= color_scale; @@ -825,10 +825,10 @@ static int GLES2_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, verts++; } - return 0; + return true; } -static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -844,7 +844,7 @@ static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S if (texture) { SDL_Vertex *verts = (SDL_Vertex *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -888,7 +888,7 @@ static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S } else { SDL_VertexSolid *verts = (SDL_VertexSolid *)SDL_AllocateRenderVertices(renderer, count * sizeof(*verts), 0, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -927,10 +927,10 @@ static int GLES2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, S } } - return 0; + return true; } -static int SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_ImageSource imgsrc, void *vertices) +static bool SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, const GLES2_ImageSource imgsrc, void *vertices) { SDL_Texture *texture = cmd->data.draw.texture; const SDL_BlendMode blend = cmd->data.draw.blend; @@ -992,8 +992,8 @@ static int SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, co data->glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, stride, (const GLvoid *)&verts->tex_coord); } - if (GLES2_SelectProgram(data, imgsrc, texture ? texture->colorspace : SDL_COLORSPACE_SRGB) < 0) { - return -1; + if (!GLES2_SelectProgram(data, imgsrc, texture ? texture->colorspace : SDL_COLORSPACE_SRGB)) { + return false; } program = data->drawstate.program; @@ -1027,10 +1027,10 @@ static int SetDrawState(GLES2_RenderData *data, const SDL_RenderCommand *cmd, co data->glVertexAttribPointer(GLES2_ATTRIBUTE_COLOR, 4, GL_FLOAT, GL_TRUE /* Normalized */, stride, (const GLvoid *)&verts->color); } - return 0; + return true; } -static int SetTextureAddressMode(GLES2_RenderData *data, GLenum textype, SDL_TextureAddressMode addressMode) +static bool SetTextureAddressMode(GLES2_RenderData *data, GLenum textype, SDL_TextureAddressMode addressMode) { switch (addressMode) { case SDL_TEXTURE_ADDRESS_CLAMP: @@ -1044,10 +1044,10 @@ static int SetTextureAddressMode(GLES2_RenderData *data, GLenum textype, SDL_Tex default: return SDL_SetError("Unknown texture address mode: %d\n", addressMode); } - return 0; + return true; } -static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, void *vertices) +static bool SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, void *vertices) { GLES2_RenderData *data = (GLES2_RenderData *)renderer->internal; GLES2_ImageSource sourceType = GLES2_IMAGESOURCE_TEXTURE_ABGR; @@ -1179,15 +1179,15 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo data->glActiveTexture(GL_TEXTURE2); data->glBindTexture(tdata->texture_type, tdata->texture_v); - if (SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode)) { + return false; } data->glActiveTexture(GL_TEXTURE1); data->glBindTexture(tdata->texture_type, tdata->texture_u); - if (SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode)) { + return false; } data->glActiveTexture(GL_TEXTURE0); @@ -1195,8 +1195,8 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo data->glActiveTexture(GL_TEXTURE1); data->glBindTexture(tdata->texture_type, tdata->texture_u); - if (SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode)) { + return false; } data->glActiveTexture(GL_TEXTURE0); @@ -1204,8 +1204,8 @@ static int SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, vo #endif data->glBindTexture(tdata->texture_type, tdata->texture); - if (SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode) < 0) { - return -1; + if (!SetTextureAddressMode(data, tdata->texture_type, cmd->data.draw.texture_address_mode)) { + return false; } data->drawstate.texture = texture; @@ -1229,7 +1229,7 @@ static void GLES2_InvalidateCachedState(SDL_Renderer *renderer) cache->program = NULL; } -static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { GLES2_RenderData *data = (GLES2_RenderData *)renderer->internal; const bool colorswap = (renderer->target && (renderer->target->format == SDL_PIXELFORMAT_BGRA32 || renderer->target->format == SDL_PIXELFORMAT_BGRX32)); @@ -1239,8 +1239,8 @@ static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const GLuint vbo = data->vertex_buffers[vboidx]; #endif - if (GLES2_ActivateRenderer(renderer) < 0) { - return -1; + if (!GLES2_ActivateRenderer(renderer)) { + return false; } data->drawstate.target = renderer->target; @@ -1345,7 +1345,7 @@ static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, case SDL_RENDERCMD_DRAW_LINES: { - if (SetDrawState(data, cmd, GLES2_IMAGESOURCE_SOLID, vertices) == 0) { + if (SetDrawState(data, cmd, GLES2_IMAGESOURCE_SOLID, vertices)) { size_t count = cmd->data.draw.count; if (count > 2) { // joined lines cannot be grouped @@ -1409,7 +1409,7 @@ static int GLES2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, ret = SetDrawState(data, cmd, GLES2_IMAGESOURCE_SOLID, vertices); } - if (ret == 0) { + if (ret) { int op = GL_TRIANGLES; // SDL_RENDERCMD_GEOMETRY if (thiscmdtype == SDL_RENDERCMD_DRAW_POINTS) { op = GL_POINTS; @@ -1481,7 +1481,7 @@ static void GLES2_DestroyRenderer(SDL_Renderer *renderer) } } -static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { GLES2_RenderData *renderdata = (GLES2_RenderData *)renderer->internal; GLES2_TextureData *data; @@ -1529,7 +1529,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL // Allocate a texture struct data = (GLES2_TextureData *)SDL_calloc(1, sizeof(GLES2_TextureData)); if (!data) { - return -1; + return false; } data->texture = 0; #ifdef GL_TEXTURE_EXTERNAL_OES @@ -1564,7 +1564,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL data->pixel_data = SDL_calloc(1, size); if (!data->pixel_data) { SDL_free(data); - return -1; + return false; } } @@ -1578,8 +1578,8 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL data->texture_v_external = true; } else { renderdata->glGenTextures(1, &data->texture_v); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; + if (!GL_CheckError("glGenTexures()", renderer)) { + return false; } } renderdata->glActiveTexture(GL_TEXTURE2); @@ -1594,8 +1594,8 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL data->texture_u_external = true; } else { renderdata->glGenTextures(1, &data->texture_u); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; + if (!GL_CheckError("glGenTexures()", renderer)) { + return false; } } renderdata->glActiveTexture(GL_TEXTURE1); @@ -1603,8 +1603,8 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode); renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); renderdata->glTexImage2D(data->texture_type, 0, format, (texture->w + 1) / 2, (texture->h + 1) / 2, 0, format, type, NULL); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; + if (!GL_CheckError("glTexImage2D()", renderer)) { + return false; } SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER, data->texture_u); @@ -1617,8 +1617,8 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL data->texture_u_external = true; } else { renderdata->glGenTextures(1, &data->texture_u); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; + if (!GL_CheckError("glGenTexures()", renderer)) { + return false; } } renderdata->glActiveTexture(GL_TEXTURE1); @@ -1626,8 +1626,8 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, scaleMode); renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); renderdata->glTexImage2D(data->texture_type, 0, GL_LUMINANCE_ALPHA, (texture->w + 1) / 2, (texture->h + 1) / 2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; + if (!GL_CheckError("glTexImage2D()", renderer)) { + return false; } SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER, data->texture_u); @@ -1642,8 +1642,8 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL data->texture_external = true; } else { renderdata->glGenTextures(1, &data->texture); - if (GL_CheckError("glGenTexures()", renderer) < 0) { - return -1; + if (!GL_CheckError("glGenTexures()", renderer)) { + return false; } } texture->internal = data; @@ -1653,8 +1653,8 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, scaleMode); if (texture->format != SDL_PIXELFORMAT_EXTERNAL_OES) { renderdata->glTexImage2D(data->texture_type, 0, format, texture->w, texture->h, 0, format, type, NULL); - if (GL_CheckError("glTexImage2D()", renderer) < 0) { - return -1; + if (!GL_CheckError("glTexImage2D()", renderer)) { + return false; } } SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER, data->texture); @@ -1669,7 +1669,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL return GL_CheckError("", renderer); } -static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp) +static bool GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels, GLint pitch, GLint bpp) { Uint8 *blob = NULL; Uint8 *src; @@ -1677,7 +1677,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff int y; if ((width == 0) || (height == 0) || (bpp == 0)) { - return 0; // nothing to do + return true; // nothing to do } // Reformat the texture data into a tightly packed array @@ -1686,7 +1686,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff if ((size_t)pitch != src_pitch) { blob = (Uint8 *)SDL_malloc(src_pitch * height); if (!blob) { - return -1; + return false; } src = blob; for (y = 0; y < height; ++y) { @@ -1701,10 +1701,10 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff if (blob) { SDL_free(blob); } - return 0; + return true; } -static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, +static bool GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { GLES2_RenderData *data = (GLES2_RenderData *)renderer->internal; @@ -1714,7 +1714,7 @@ static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, con // Bail out if we're supposed to update an empty rectangle if (rect->w <= 0 || rect->h <= 0) { - return 0; + return true; } data->drawstate.texture = NULL; // we trash this state. @@ -1782,7 +1782,7 @@ static int GLES2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, con } #if SDL_HAVE_YUV -static int GLES2_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool GLES2_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -1795,7 +1795,7 @@ static int GLES2_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, // Bail out if we're supposed to update an empty rectangle if (rect->w <= 0 || rect->h <= 0) { - return 0; + return true; } data->drawstate.texture = NULL; // we trash this state. @@ -1833,7 +1833,7 @@ static int GLES2_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, return GL_CheckError("glTexSubImage2D()", renderer); } -static int GLES2_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool GLES2_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) @@ -1845,7 +1845,7 @@ static int GLES2_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, // Bail out if we're supposed to update an empty rectangle if (rect->w <= 0 || rect->h <= 0) { - return 0; + return true; } data->drawstate.texture = NULL; // we trash this state. @@ -1874,7 +1874,7 @@ static int GLES2_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, } #endif -static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, +static bool GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { GLES2_TextureData *tdata = (GLES2_TextureData *)texture->internal; @@ -1885,7 +1885,7 @@ static int GLES2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const (rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = tdata->pitch; - return 0; + return true; } static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -1932,7 +1932,7 @@ static void GLES2_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *textu renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, glScaleMode); } -static int GLES2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool GLES2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { GLES2_RenderData *data = (GLES2_RenderData *)renderer->internal; GLES2_TextureData *texturedata = NULL; @@ -1953,7 +1953,7 @@ static int GLES2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) return SDL_SetError("glFramebufferTexture2D() failed"); } } - return 0; + return true; } static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -2005,7 +2005,7 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h, rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels); - if (GL_CheckError("glReadPixels()", renderer) < 0) { + if (!GL_CheckError("glReadPixels()", renderer)) { SDL_DestroySurface(surface); return NULL; } @@ -2030,15 +2030,14 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec return surface; } -static int GLES2_RenderPresent(SDL_Renderer *renderer) +static bool GLES2_RenderPresent(SDL_Renderer *renderer) { // Tell the video driver to swap buffers return SDL_GL_SwapWindow(renderer->window); } -static int GLES2_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool GLES2_SetVSync(SDL_Renderer *renderer, const int vsync) { - int retval; int interval = 0; #ifdef SDL_PLATFORM_WINRT @@ -2051,26 +2050,25 @@ static int GLES2_SetVSync(SDL_Renderer *renderer, const int vsync) } #endif - retval = SDL_GL_SetSwapInterval(vsync); - if (retval < 0) { - return retval; + if (!SDL_GL_SetSwapInterval(vsync)) { + return false; } - retval = SDL_GL_GetSwapInterval(&interval); - if (retval < 0) { - return retval; + if (!SDL_GL_GetSwapInterval(&interval)) { + return false; } + if (interval != vsync) { return SDL_Unsupported(); } - return 0; + return true; } /************************************************************************************************* * Renderer instantiation * *************************************************************************************************/ -static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { GLES2_RenderData *data = NULL; SDL_WindowFlags window_flags = 0; // -Wconditional-uninitialized @@ -2079,13 +2077,13 @@ static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ int profile_mask = 0, major = 0, minor = 0; bool changed_window = false; - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask) < 0) { + if (!SDL_GL_GetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, &profile_mask)) { goto error; } - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major) < 0) { + if (!SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major)) { goto error; } - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor) < 0) { + if (!SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &minor)) { goto error; } @@ -2101,7 +2099,7 @@ static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, RENDERER_CONTEXT_MAJOR); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, RENDERER_CONTEXT_MINOR); - if (SDL_RecreateWindow(window, (window_flags & ~(SDL_WINDOW_VULKAN | SDL_WINDOW_METAL)) | SDL_WINDOW_OPENGL) < 0) { + if (!SDL_RecreateWindow(window, (window_flags & ~(SDL_WINDOW_VULKAN | SDL_WINDOW_METAL)) | SDL_WINDOW_OPENGL)) { goto error; } } @@ -2132,20 +2130,20 @@ static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ if (!data->context) { goto error; } - if (SDL_GL_MakeCurrent(window, data->context) < 0) { + if (!SDL_GL_MakeCurrent(window, data->context)) { goto error; } - if (GLES2_LoadFunctions(data) < 0) { + if (!GLES2_LoadFunctions(data)) { goto error; } - if (GLES2_CacheShaders(data) < 0) { + if (!GLES2_CacheShaders(data)) { goto error; } // Check for debug output support - if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) == 0 && + if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_FLAGS, &value) && (value & SDL_GL_CONTEXT_DEBUG_FLAG)) { data->debug_enabled = true; } @@ -2231,7 +2229,7 @@ static int GLES2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_ GL_CheckError("", renderer); - return 0; + return true; error: if (changed_window) { @@ -2244,7 +2242,7 @@ error: SDL_SetError("%s", error); SDL_free(error); } - return -1; + return false; } SDL_RenderDriver GLES2_RenderDriver = { diff --git a/src/render/ps2/SDL_render_ps2.c b/src/render/ps2/SDL_render_ps2.c index 7dc147ed0f..f256a60235 100644 --- a/src/render/ps2/SDL_render_ps2.c +++ b/src/render/ps2/SDL_render_ps2.c @@ -127,12 +127,12 @@ static void PS2_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event { } -static int PS2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool PS2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { GSTEXTURE *ps2_tex = (GSTEXTURE *)SDL_calloc(1, sizeof(GSTEXTURE)); if (!ps2_tex) { - return -1; + return false; } ps2_tex->Width = texture->w; @@ -142,15 +142,15 @@ static int PS2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P if (!ps2_tex->Mem) { SDL_free(ps2_tex); - return -1; + return false; } texture->internal = ps2_tex; - return 0; + return true; } -static int PS2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool PS2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { GSTEXTURE *ps2_texture = (GSTEXTURE *)texture->internal; @@ -159,7 +159,7 @@ static int PS2_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, (void *)((Uint8 *)ps2_texture->Mem + rect->y * ps2_texture->Width * SDL_BYTESPERPIXEL(texture->format) + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = ps2_texture->Width * SDL_BYTESPERPIXEL(texture->format); - return 0; + return true; } static void PS2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -170,7 +170,7 @@ static void PS2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) gsKit_TexManager_invalidate(data->gsGlobal, ps2_texture); } -static int PS2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool PS2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { const Uint8 *src; @@ -192,7 +192,7 @@ static int PS2_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, PS2_UnlockTexture(renderer, texture); - return 0; + return true; } static void PS2_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode) @@ -210,12 +210,12 @@ static void PS2_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture ps2_texture->Filter = gsKitScaleMode; } -static int PS2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool PS2_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { - return 0; + return true; } -static int PS2_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool PS2_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; const SDL_Rect *viewport = &cmd->data.viewport.rect; @@ -225,15 +225,15 @@ static int PS2_QueueSetViewport(SDL_Renderer *renderer, SDL_RenderCommand *cmd) data->gsGlobal->OffsetY = (int)((2048.0f + (float)viewport->y) * 16.0f); gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(viewport->x, viewport->x + viewport->w, viewport->y, viewport->y + viewport->h)); - return 0; + return true; } -static int PS2_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool PS2_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int PS2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool PS2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; GSPRIMPOINT *vertices = (GSPRIMPOINT *)SDL_AllocateRenderVertices(renderer, count * sizeof(GSPRIMPOINT), 4, &cmd->data.draw.first); @@ -241,7 +241,7 @@ static int PS2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c int i; if (!vertices) { - return -1; + return false; } cmd->data.draw.count = count; @@ -252,10 +252,10 @@ static int PS2_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c vertices->xyz2 = vertex_to_XYZ2(data->gsGlobal, points->x, points->y, 0); vertices->rgbaq = rgbaq; } - return 0; + return true; } -static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -273,7 +273,7 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL GSTEXTURE *ps2_tex = (GSTEXTURE *) texture->internal; if (!vertices) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -306,7 +306,7 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL GSPRIMPOINT *vertices = (GSPRIMPOINT *)SDL_AllocateRenderVertices(renderer, count * sizeof(GSPRIMPOINT), 4, &cmd->data.draw.first); if (!vertices) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -333,15 +333,15 @@ static int PS2_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL } } - return 0; + return true; } -static int PS2_RenderSetViewPort(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool PS2_RenderSetViewPort(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int PS2_RenderSetClipRect(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool PS2_RenderSetClipRect(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; SDL_Rect *viewport = data->viewport; @@ -357,18 +357,18 @@ static int PS2_RenderSetClipRect(SDL_Renderer *renderer, SDL_RenderCommand *cmd) } gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(viewport->x, viewport->x + viewport->w, viewport->y, viewport->y + viewport->h)); - return 0; + return true; } -static int PS2_RenderSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool PS2_RenderSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; data->drawColor = float_GS_SETREG_RGBAQ(&cmd->data.color.color, cmd->data.color.color_scale); - return 0; + return true; } -static int PS2_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool PS2_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { int offsetX, offsetY; SDL_Rect *viewport; @@ -392,7 +392,7 @@ static int PS2_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd) viewport = data->viewport; gsKit_set_scissor(data->gsGlobal, GS_SETREG_SCISSOR(viewport->x, viewport->x + viewport->w, viewport->y, viewport->y + viewport->h)); - return 0; + return true; } static void PS2_SetBlendMode(PS2_RenderData *data, int blendMode) @@ -447,7 +447,7 @@ static void PS2_SetBlendMode(PS2_RenderData *data, int blendMode) } } -static int PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd) +static bool PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; const size_t count = cmd->data.draw.count; @@ -465,10 +465,10 @@ static int PS2_RenderGeometry(SDL_Renderer *renderer, void *vertices, SDL_Render gsKit_prim_list_triangle_gouraud_3d(data->gsGlobal, count, verts); } - return 0; + return true; } -int PS2_RenderLines(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd) +static bool PS2_RenderLines(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; const size_t count = cmd->data.draw.count; @@ -478,10 +478,10 @@ int PS2_RenderLines(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *c gsKit_prim_list_line_goraud_3d(data->gsGlobal, count, verts); // We're done! - return 0; + return true; } -int PS2_RenderPoints(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd) +static bool PS2_RenderPoints(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand *cmd) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; const size_t count = cmd->data.draw.count; @@ -491,7 +491,7 @@ int PS2_RenderPoints(SDL_Renderer *renderer, void *vertices, SDL_RenderCommand * gsKit_prim_list_points(data->gsGlobal, count, verts); // We're done! - return 0; + return true; } static void PS2_InvalidateCachedState(SDL_Renderer *renderer) @@ -499,7 +499,7 @@ static void PS2_InvalidateCachedState(SDL_Renderer *renderer) // currently this doesn't do anything. If this needs to do something (and someone is mixing their own rendering calls in!), update this. } -static int PS2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool PS2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { while (cmd) { switch (cmd->command) { @@ -550,10 +550,10 @@ static int PS2_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v } cmd = cmd->next; } - return 0; + return true; } -static int PS2_RenderPresent(SDL_Renderer *renderer) +static bool PS2_RenderPresent(SDL_Renderer *renderer) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; @@ -576,7 +576,7 @@ static int PS2_RenderPresent(SDL_Renderer *renderer) } gsKit_TexManager_nextFrame(data->gsGlobal); gsKit_clear(data->gsGlobal, GS_BLACK); - return 0; + return true; } static void PS2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -618,7 +618,7 @@ static void PS2_DestroyRenderer(SDL_Renderer *renderer) } } -static int PS2_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool PS2_SetVSync(SDL_Renderer *renderer, const int vsync) { PS2_RenderData *data = (PS2_RenderData *)renderer->internal; switch (vsync) { @@ -631,10 +631,10 @@ static int PS2_SetVSync(SDL_Renderer *renderer, const int vsync) return SDL_Unsupported(); } data->vsync = vsync; - return 0; + return true; } -static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { PS2_RenderData *data; GSGLOBAL *gsGlobal; @@ -648,7 +648,7 @@ static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr data = (PS2_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } // Specific gsKit init @@ -717,7 +717,7 @@ static int PS2_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr SDL_AddSupportedTextureFormat(renderer, SDL_PIXELFORMAT_ABGR8888); SDL_SetNumberProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_MAX_TEXTURE_SIZE_NUMBER, 1024); - return 0; + return true; } SDL_RenderDriver PS2_RenderDriver = { diff --git a/src/render/psp/SDL_render_psp.c b/src/render/psp/SDL_render_psp.c index db74da539e..d66a92f8a5 100644 --- a/src/render/psp/SDL_render_psp.c +++ b/src/render/psp/SDL_render_psp.c @@ -258,7 +258,7 @@ static void TextureStorageFree(void *storage) } } -static int TextureSwizzle(PSP_TextureData *psp_texture, void *dst) +static bool TextureSwizzle(PSP_TextureData *psp_texture, void *dst) { int bytewidth, height; int rowblocks, rowblocksadd; @@ -268,7 +268,7 @@ static int TextureSwizzle(PSP_TextureData *psp_texture, void *dst) unsigned char *data = NULL; if (psp_texture->swizzled) { - return 1; + return true; } bytewidth = psp_texture->textureWidth * (psp_texture->bits >> 3); @@ -285,7 +285,7 @@ static int TextureSwizzle(PSP_TextureData *psp_texture, void *dst) } if (!data) { - return -1; + return false; } for (j = 0; j < height; j++, blockaddress += 16) { @@ -311,10 +311,10 @@ static int TextureSwizzle(PSP_TextureData *psp_texture, void *dst) psp_texture->swizzled = true; sceKernelDcacheWritebackRange(psp_texture->data, psp_texture->size); - return 1; + return true; } -static int TextureUnswizzle(PSP_TextureData *psp_texture, void *dst) +static bool TextureUnswizzle(PSP_TextureData *psp_texture, void *dst) { int bytewidth, height; int widthblocks, heightblocks; @@ -326,7 +326,7 @@ static int TextureUnswizzle(PSP_TextureData *psp_texture, void *dst) unsigned char *ydst = NULL; if (!psp_texture->swizzled) { - return 1; + return true; } bytewidth = psp_texture->textureWidth * (psp_texture->bits >> 3); @@ -347,7 +347,7 @@ static int TextureUnswizzle(PSP_TextureData *psp_texture, void *dst) } if (!data) { - return -1; + return false; } ydst = (unsigned char *)data; @@ -381,29 +381,29 @@ static int TextureUnswizzle(PSP_TextureData *psp_texture, void *dst) psp_texture->swizzled = false; sceKernelDcacheWritebackRange(psp_texture->data, psp_texture->size); - return 1; + return true; } -static int TextureSpillToSram(PSP_RenderData *data, PSP_TextureData *psp_texture) +static bool TextureSpillToSram(PSP_RenderData *data, PSP_TextureData *psp_texture) { // Assumes the texture is in VRAM if (psp_texture->swizzled) { // Texture was swizzled in vram, just copy to system memory void *sdata = SDL_malloc(psp_texture->size); if (!sdata) { - return -1; + return false; } SDL_memcpy(sdata, psp_texture->data, psp_texture->size); vfree(psp_texture->data); psp_texture->data = sdata; - return 0; + return true; } else { return TextureSwizzle(psp_texture, NULL); // Will realloc in sysram } } -static int TexturePromoteToVram(PSP_RenderData *data, PSP_TextureData *psp_texture, bool target) +static bool TexturePromoteToVram(PSP_RenderData *data, PSP_TextureData *psp_texture, bool target) { // Assumes texture in sram and a large enough continuous block in vram void *tdata = vramalloc(psp_texture->size); @@ -413,46 +413,46 @@ static int TexturePromoteToVram(PSP_RenderData *data, PSP_TextureData *psp_textu SDL_memcpy(tdata, psp_texture->data, psp_texture->size); SDL_free(psp_texture->data); psp_texture->data = tdata; - return 0; + return true; } } -static int TextureSpillLRU(PSP_RenderData *data, size_t wanted) +static bool TextureSpillLRU(PSP_RenderData *data, size_t wanted) { PSP_TextureData *lru = data->least_recent_target; if (lru) { - if (TextureSpillToSram(data, lru) < 0) { - return -1; + if (!TextureSpillToSram(data, lru)) { + return false; } LRUTargetRemove(data, lru); } else { // Asked to spill but there nothing to spill return SDL_SetError("Could not spill more VRAM to system memory. VRAM : %dKB,(%dKB), wanted %dKB", vmemavail() / 1024, vlargestblock() / 1024, wanted / 1024); } - return 0; + return true; } -static int TextureSpillTargetsForSpace(PSP_RenderData *data, size_t size) +static bool TextureSpillTargetsForSpace(PSP_RenderData *data, size_t size) { while (vlargestblock() < size) { - if (TextureSpillLRU(data, size) < 0) { - return -1; + if (!TextureSpillLRU(data, size)) { + return false; } } - return 0; + return true; } -static int TextureBindAsTarget(PSP_RenderData *data, PSP_TextureData *psp_texture) +static bool TextureBindAsTarget(PSP_RenderData *data, PSP_TextureData *psp_texture) { unsigned int dstFormat; if (!InVram(psp_texture->data)) { // Bring back the texture in vram - if (TextureSpillTargetsForSpace(data, psp_texture->size) < 0) { - return -1; + if (!TextureSpillTargetsForSpace(data, psp_texture->size)) { + return false; } - if (TexturePromoteToVram(data, psp_texture, true) < 0) { - return -1; + if (!TexturePromoteToVram(data, psp_texture, true)) { + return false; } } LRUTargetBringFront(data, psp_texture); @@ -470,20 +470,20 @@ static int TextureBindAsTarget(PSP_RenderData *data, PSP_TextureData *psp_textur sceGuDisable(GU_STENCIL_TEST); sceGuDisable(GU_ALPHA_TEST); } - return 0; + return true; } static void PSP_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event) { } -static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { PSP_RenderData *data = renderer->internal; PSP_TextureData *psp_texture = (PSP_TextureData *)SDL_calloc(1, sizeof(*psp_texture)); if (!psp_texture) { - return -1; + return false; } psp_texture->swizzled = false; @@ -506,15 +506,15 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P default: SDL_free(psp_texture); - return -1; + return false; } psp_texture->pitch = psp_texture->textureWidth * SDL_BYTESPERPIXEL(texture->format); psp_texture->size = psp_texture->textureHeight * psp_texture->pitch; if (texture->access == SDL_TEXTUREACCESS_TARGET) { - if (TextureSpillTargetsForSpace(renderer->internal, psp_texture->size) < 0) { + if (!TextureSpillTargetsForSpace(renderer->internal, psp_texture->size)) { SDL_free(psp_texture); - return -1; + return false; } psp_texture->data = vramalloc(psp_texture->size); if (psp_texture->data) { @@ -526,14 +526,14 @@ static int PSP_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P if (!psp_texture->data) { SDL_free(psp_texture); - return -1; + return false; } texture->internal = psp_texture; - return 0; + return true; } -static int TextureShouldSwizzle(PSP_TextureData *psp_texture, SDL_Texture *texture) +static bool TextureShouldSwizzle(PSP_TextureData *psp_texture, SDL_Texture *texture) { return !((texture->access == SDL_TEXTUREACCESS_TARGET) && InVram(psp_texture->data)) && texture->access != SDL_TEXTUREACCESS_STREAMING && (texture->w >= 16 || texture->h >= 16); } @@ -555,10 +555,10 @@ static void TextureActivate(SDL_Texture *texture) sceGuTexImage(0, psp_texture->textureWidth, psp_texture->textureHeight, psp_texture->textureWidth, psp_texture->data); } -static int PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch); -static int PSP_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool PSP_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { /* PSP_TextureData *psp_texture = (PSP_TextureData *) texture->internal; */ @@ -580,10 +580,10 @@ static int PSP_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, } sceKernelDcacheWritebackAll(); - return 0; + return true; } -static int PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { PSP_TextureData *psp_texture = (PSP_TextureData *)texture->internal; @@ -592,7 +592,7 @@ static int PSP_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, (void *)((Uint8 *)psp_texture->data + rect->y * psp_texture->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); *pitch = psp_texture->pitch; - return 0; + return true; } static void PSP_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -613,23 +613,23 @@ static void PSP_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture // Nothing to do because TextureActivate takes care of it } -static int PSP_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool PSP_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { - return 0; + return true; } -static int PSP_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool PSP_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int PSP_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool PSP_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { VertV *verts = (VertV *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertV), 4, &cmd->data.draw.first); int i; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -640,10 +640,10 @@ static int PSP_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, c verts->z = 0.0f; } - return 0; + return true; } -static int PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -659,7 +659,7 @@ static int PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL VertCV *verts; verts = (VertCV *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertCV), 4, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -695,7 +695,7 @@ static int PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL VertTCV *verts; verts = (VertTCV *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertTCV), 4, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -734,16 +734,16 @@ static int PSP_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL } } - return 0; + return true; } -static int PSP_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count) +static bool PSP_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count) { VertV *verts = (VertV *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(VertV), 4, &cmd->data.draw.first); int i; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -759,10 +759,10 @@ static int PSP_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, co verts++; } - return 0; + return true; } -static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) { VertTV *verts; @@ -779,7 +779,7 @@ static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Tex if ((MathAbs(u1) - MathAbs(u0)) < 64.0f) { verts = (VertTV *)SDL_AllocateRenderVertices(renderer, 2 * sizeof(VertTV), 4, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = 1; @@ -815,7 +815,7 @@ static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Tex verts = (VertTV *)SDL_AllocateRenderVertices(renderer, count * 2 * sizeof(VertTV), 4, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } for (i = 0, start = 0, end = width; i < count; i++, start += slice) { @@ -843,10 +843,10 @@ static int PSP_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Tex } } - return 0; + return true; } -static int PSP_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool PSP_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y) { @@ -866,7 +866,7 @@ static int PSP_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_T float v1 = srcrect->y + srcrect->h; if (!verts) { - return -1; + return false; } cmd->data.draw.count = 1; @@ -931,7 +931,7 @@ static int PSP_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_T verts->y *= scale_y; } - return 0; + return true; } static void ResetBlendState(PSP_BlendState *state) @@ -1042,7 +1042,7 @@ static void PSP_InvalidateCachedState(SDL_Renderer *renderer) // currently this doesn't do anything. If this needs to do something (and someone is mixing their own rendering calls in!), update this. } -static int PSP_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool PSP_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { PSP_RenderData *data = (PSP_RenderData *)renderer->internal; Uint8 *gpumem = NULL; @@ -1215,14 +1215,14 @@ static int PSP_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v cmd = cmd->next; } - return 0; + return true; } -static int PSP_RenderPresent(SDL_Renderer *renderer) +static bool PSP_RenderPresent(SDL_Renderer *renderer) { PSP_RenderData *data = (PSP_RenderData *)renderer->internal; if (!data->displayListAvail) { - return -1; + return false; } data->displayListAvail = false; @@ -1237,7 +1237,7 @@ static int PSP_RenderPresent(SDL_Renderer *renderer) data->backbuffer = data->frontbuffer; data->frontbuffer = vabsptr(sceGuSwapBuffers()); - return 0; + return true; } static void PSP_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -1281,14 +1281,14 @@ static void PSP_DestroyRenderer(SDL_Renderer *renderer) } } -static int PSP_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool PSP_SetVSync(SDL_Renderer *renderer, const int vsync) { PSP_RenderData *data = renderer->internal; data->vsync = vsync; - return 0; + return true; } -static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { PSP_RenderData *data; int pixelformat; @@ -1302,7 +1302,7 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr data = (PSP_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } renderer->WindowEvent = PSP_WindowEvent; @@ -1394,7 +1394,7 @@ static int PSP_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pr sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, psp_on_vblank, data); sceKernelEnableSubIntr(PSP_VBLANK_INT, 0); - return 0; + return true; } SDL_RenderDriver PSP_RenderDriver = { diff --git a/src/render/software/SDL_blendfillrect.c b/src/render/software/SDL_blendfillrect.c index 5fc2b228ac..c50f94ccd0 100644 --- a/src/render/software/SDL_blendfillrect.c +++ b/src/render/software/SDL_blendfillrect.c @@ -25,7 +25,7 @@ #include "SDL_draw.h" #include "SDL_blendfillrect.h" -static int SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect, +static bool SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -51,10 +51,10 @@ static int SDL_BlendFillRect_RGB555(SDL_Surface *dst, const SDL_Rect *rect, FILLRECT(Uint16, DRAW_SETPIXEL_RGB555); break; } - return 0; + return true; } -static int SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect, +static bool SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -80,10 +80,10 @@ static int SDL_BlendFillRect_RGB565(SDL_Surface *dst, const SDL_Rect *rect, FILLRECT(Uint16, DRAW_SETPIXEL_RGB565); break; } - return 0; + return true; } -static int SDL_BlendFillRect_XRGB8888(SDL_Surface *dst, const SDL_Rect *rect, +static bool SDL_BlendFillRect_XRGB8888(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -109,10 +109,10 @@ static int SDL_BlendFillRect_XRGB8888(SDL_Surface *dst, const SDL_Rect *rect, FILLRECT(Uint32, DRAW_SETPIXEL_XRGB8888); break; } - return 0; + return true; } -static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect, +static bool SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -138,10 +138,10 @@ static int SDL_BlendFillRect_ARGB8888(SDL_Surface *dst, const SDL_Rect *rect, FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888); break; } - return 0; + return true; } -static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect, +static bool SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { const SDL_PixelFormatDetails *fmt = dst->internal->format; @@ -170,7 +170,7 @@ static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect, FILLRECT(Uint16, DRAW_SETPIXEL_RGB); break; } - return 0; + return true; case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: @@ -193,13 +193,13 @@ static int SDL_BlendFillRect_RGB(SDL_Surface *dst, const SDL_Rect *rect, FILLRECT(Uint32, DRAW_SETPIXEL_RGB); break; } - return 0; + return true; default: return SDL_Unsupported(); } } -static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect, +static bool SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { const SDL_PixelFormatDetails *fmt = dst->internal->format; @@ -228,14 +228,13 @@ static int SDL_BlendFillRect_RGBA(SDL_Surface *dst, const SDL_Rect *rect, FILLRECT(Uint32, DRAW_SETPIXEL_RGBA); break; } - return 0; + return true; default: return SDL_Unsupported(); } } -int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_Rect clipped; @@ -252,7 +251,7 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, if (rect) { // Perform clipping if (!SDL_GetRectIntersection(rect, &dst->internal->clip_rect, &clipped)) { - return 0; + return true; } rect = &clipped; } else { @@ -300,14 +299,12 @@ int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, } } -int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_Rect rect; int i; - int (*func)(SDL_Surface * dst, const SDL_Rect *rect, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; - int status = 0; + bool (*func)(SDL_Surface * dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; + bool result = true; if (!SDL_SurfaceValid(dst)) { return SDL_InvalidParamError("SDL_BlendFillRects(): dst"); @@ -366,9 +363,9 @@ int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, if (!SDL_GetRectIntersection(&rects[i], &dst->internal->clip_rect, &rect)) { continue; } - status = func(dst, &rect, blendMode, r, g, b, a); + result = func(dst, &rect, blendMode, r, g, b, a); } - return status; + return result; } #endif // SDL_VIDEO_RENDER_SW diff --git a/src/render/software/SDL_blendfillrect.h b/src/render/software/SDL_blendfillrect.h index 9d5f1108b2..89975ca112 100644 --- a/src/render/software/SDL_blendfillrect.h +++ b/src/render/software/SDL_blendfillrect.h @@ -24,7 +24,7 @@ #include "SDL_internal.h" -extern int SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern bool SDL_BlendFillRect(SDL_Surface *dst, const SDL_Rect *rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern bool SDL_BlendFillRects(SDL_Surface *dst, const SDL_Rect *rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); #endif // SDL_blendfillrect_h_ diff --git a/src/render/software/SDL_blendline.c b/src/render/software/SDL_blendline.c index 21ff8a3f7b..f24124908f 100644 --- a/src/render/software/SDL_blendline.c +++ b/src/render/software/SDL_blendline.c @@ -919,8 +919,7 @@ static BlendLineFunc SDL_CalculateBlendLineFunc(const SDL_PixelFormatDetails *fm return NULL; } -int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +bool SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { BlendLineFunc func; @@ -936,15 +935,14 @@ int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, // Perform clipping // FIXME: We don't actually want to clip, as it may change line slope if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) { - return 0; + return true; } func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, true); - return 0; + return true; } -int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +bool SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { int i; int x1, y1; @@ -982,7 +980,7 @@ int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendPoint(dst, points[count - 1].x, points[count - 1].y, blendMode, r, g, b, a); } - return 0; + return true; } #endif // SDL_VIDEO_RENDER_SW diff --git a/src/render/software/SDL_blendline.h b/src/render/software/SDL_blendline.h index 057e3b0f26..3c348ce19e 100644 --- a/src/render/software/SDL_blendline.h +++ b/src/render/software/SDL_blendline.h @@ -24,7 +24,7 @@ #include "SDL_internal.h" -extern int SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern bool SDL_BlendLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern bool SDL_BlendLines(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); #endif // SDL_blendline_h_ diff --git a/src/render/software/SDL_blendpoint.c b/src/render/software/SDL_blendpoint.c index 8cfedd0851..6724096a14 100644 --- a/src/render/software/SDL_blendpoint.c +++ b/src/render/software/SDL_blendpoint.c @@ -25,7 +25,7 @@ #include "SDL_draw.h" #include "SDL_blendpoint.h" -static int SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, +static bool SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -51,10 +51,10 @@ static int SDL_BlendPoint_RGB555(SDL_Surface *dst, int x, int y, SDL_BlendMode b DRAW_SETPIXELXY_RGB555(x, y); break; } - return 0; + return true; } -static int SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, +static bool SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -80,10 +80,10 @@ static int SDL_BlendPoint_RGB565(SDL_Surface *dst, int x, int y, SDL_BlendMode b DRAW_SETPIXELXY_RGB565(x, y); break; } - return 0; + return true; } -static int SDL_BlendPoint_XRGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, +static bool SDL_BlendPoint_XRGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -109,10 +109,10 @@ static int SDL_BlendPoint_XRGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode DRAW_SETPIXELXY_XRGB8888(x, y); break; } - return 0; + return true; } -static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, +static bool SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -138,10 +138,10 @@ static int SDL_BlendPoint_ARGB8888(SDL_Surface *dst, int x, int y, SDL_BlendMode DRAW_SETPIXELXY_ARGB8888(x, y); break; } - return 0; + return true; } -static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, +static bool SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { const SDL_PixelFormatDetails *fmt = dst->internal->format; @@ -170,7 +170,7 @@ static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blen DRAW_SETPIXELXY2_RGB(x, y); break; } - return 0; + return true; case 4: switch (blendMode) { case SDL_BLENDMODE_BLEND: @@ -193,13 +193,13 @@ static int SDL_BlendPoint_RGB(SDL_Surface *dst, int x, int y, SDL_BlendMode blen DRAW_SETPIXELXY4_RGB(x, y); break; } - return 0; + return true; default: return SDL_Unsupported(); } } -static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, +static bool SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { const SDL_PixelFormatDetails *fmt = dst->internal->format; @@ -228,14 +228,13 @@ static int SDL_BlendPoint_RGBA(SDL_Surface *dst, int x, int y, SDL_BlendMode ble DRAW_SETPIXELXY4_RGBA(x, y); break; } - return 0; + return true; default: return SDL_Unsupported(); } } -int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) +bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { if (!SDL_SurfaceValid(dst)) { return SDL_InvalidParamError("SDL_BlendPoint(): dst"); @@ -250,7 +249,7 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y || x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) || y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) { - return 0; + return true; } if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { @@ -294,16 +293,14 @@ int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint } } -int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { int minx, miny; int maxx, maxy; int i; int x, y; - int (*func)(SDL_Surface * dst, int x, int y, - SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; - int status = 0; + bool (*func)(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; + bool result = true; if (!SDL_SurfaceValid(dst)) { return SDL_InvalidParamError("SDL_BlendPoints(): dst"); @@ -371,9 +368,9 @@ int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, if (x < minx || x > maxx || y < miny || y > maxy) { continue; } - status = func(dst, x, y, blendMode, r, g, b, a); + result = func(dst, x, y, blendMode, r, g, b, a); } - return status; + return result; } #endif // SDL_VIDEO_RENDER_SW diff --git a/src/render/software/SDL_blendpoint.h b/src/render/software/SDL_blendpoint.h index d1a6c552c3..629f69f6ec 100644 --- a/src/render/software/SDL_blendpoint.h +++ b/src/render/software/SDL_blendpoint.h @@ -24,7 +24,7 @@ #include "SDL_internal.h" -extern int SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); -extern int SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern bool SDL_BlendPoint(SDL_Surface *dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern bool SDL_BlendPoints(SDL_Surface *dst, const SDL_Point *points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); #endif // SDL_blendpoint_h_ diff --git a/src/render/software/SDL_drawline.c b/src/render/software/SDL_drawline.c index 4a97d1e2b3..7a7d3eac1a 100644 --- a/src/render/software/SDL_drawline.c +++ b/src/render/software/SDL_drawline.c @@ -133,7 +133,7 @@ static DrawLineFunc SDL_CalculateDrawLineFunc(const SDL_PixelFormatDetails *fmt) return NULL; } -int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color) +bool SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color) { DrawLineFunc func; @@ -149,15 +149,14 @@ int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color) // Perform clipping // FIXME: We don't actually want to clip, as it may change line slope if (!SDL_GetRectAndLineIntersection(&dst->internal->clip_rect, &x1, &y1, &x2, &y2)) { - return 0; + return true; } func(dst, x1, y1, x2, y2, color, true); - return 0; + return true; } -int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, - Uint32 color) +bool SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color) { int i; int x1, y1; @@ -194,7 +193,7 @@ int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, if (points[0].x != points[count - 1].x || points[0].y != points[count - 1].y) { SDL_DrawPoint(dst, points[count - 1].x, points[count - 1].y, color); } - return 0; + return true; } #endif // SDL_VIDEO_RENDER_SW diff --git a/src/render/software/SDL_drawline.h b/src/render/software/SDL_drawline.h index 1486de0836..8b88388803 100644 --- a/src/render/software/SDL_drawline.h +++ b/src/render/software/SDL_drawline.h @@ -24,7 +24,7 @@ #include "SDL_internal.h" -extern int SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color); -extern int SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color); +extern bool SDL_DrawLine(SDL_Surface *dst, int x1, int y1, int x2, int y2, Uint32 color); +extern bool SDL_DrawLines(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color); #endif // SDL_drawline_h_ diff --git a/src/render/software/SDL_drawpoint.c b/src/render/software/SDL_drawpoint.c index d61ddce94a..c79272943c 100644 --- a/src/render/software/SDL_drawpoint.c +++ b/src/render/software/SDL_drawpoint.c @@ -25,7 +25,7 @@ #include "SDL_draw.h" #include "SDL_drawpoint.h" -int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color) +bool SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color) { if (!SDL_SurfaceValid(dst)) { return SDL_InvalidParamError("SDL_DrawPoint(): dst"); @@ -40,7 +40,7 @@ int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color) if (x < dst->internal->clip_rect.x || y < dst->internal->clip_rect.y || x >= (dst->internal->clip_rect.x + dst->internal->clip_rect.w) || y >= (dst->internal->clip_rect.y + dst->internal->clip_rect.h)) { - return 0; + return true; } switch (dst->internal->format->bytes_per_pixel) { @@ -56,11 +56,10 @@ int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color) DRAW_FASTSETPIXELXY4(x, y); break; } - return 0; + return true; } -int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, - Uint32 color) +bool SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color) { int minx, miny; int maxx, maxy; @@ -103,7 +102,7 @@ int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, break; } } - return 0; + return true; } #endif // SDL_VIDEO_RENDER_SW diff --git a/src/render/software/SDL_drawpoint.h b/src/render/software/SDL_drawpoint.h index 06e8829360..6a1899492e 100644 --- a/src/render/software/SDL_drawpoint.h +++ b/src/render/software/SDL_drawpoint.h @@ -24,7 +24,7 @@ #include "SDL_internal.h" -extern int SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color); -extern int SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color); +extern bool SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color); +extern bool SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color); #endif // SDL_drawpoint_h_ diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index b2a94ad4ba..1990bec52e 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -77,7 +77,7 @@ static void SW_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event) } } -static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) +static bool SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) { SW_RenderData *data = (SW_RenderData *)renderer->internal; @@ -88,18 +88,18 @@ static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) if (h) { *h = data->surface->h; } - return 0; + return true; } if (renderer->window) { SDL_GetWindowSizeInPixels(renderer->window, w, h); - return 0; + return true; } return SDL_SetError("Software renderer doesn't have an output surface"); } -static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { SDL_Surface *surface = SDL_CreateSurface(texture->w, texture->h, texture->format); Uint8 r, g, b, a; @@ -123,10 +123,10 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_Pr SDL_SetSurfaceRLE(surface, 1); } - return 0; + return true; } -static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { SDL_Surface *surface = (SDL_Surface *)texture->internal; @@ -135,8 +135,8 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, size_t length; if (SDL_MUSTLOCK(surface)) { - if (SDL_LockSurface(surface) < 0) { - return -1; + if (!SDL_LockSurface(surface)) { + return false; } } src = (Uint8 *)pixels; @@ -152,10 +152,10 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, if (SDL_MUSTLOCK(surface)) { SDL_UnlockSurface(surface); } - return 0; + return true; } -static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { SDL_Surface *surface = (SDL_Surface *)texture->internal; @@ -164,7 +164,7 @@ static int SW_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, (void *)((Uint8 *)surface->pixels + rect->y * surface->pitch + rect->x * surface->internal->format->bytes_per_pixel); *pitch = surface->pitch; - return 0; + return true; } static void SW_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -175,7 +175,7 @@ static void SW_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, { } -static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { SW_RenderData *data = (SW_RenderData *)renderer->internal; @@ -184,21 +184,21 @@ static int SW_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) } else { data->surface = data->window; } - return 0; + return true; } -static int SW_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool SW_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { SDL_Point *verts = (SDL_Point *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Point), 0, &cmd->data.draw.first); int i; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -208,16 +208,16 @@ static int SW_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, co verts->y = (int)points->y; } - return 0; + return true; } -static int SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count) +static bool SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FRect *rects, int count) { SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, count * sizeof(SDL_Rect), 0, &cmd->data.draw.first); int i; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -229,16 +229,16 @@ static int SW_QueueFillRects(SDL_Renderer *renderer, SDL_RenderCommand *cmd, con verts->h = SDL_max((int)rects->h, 1); } - return 0; + return true; } -static int SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect) { SDL_Rect *verts = (SDL_Rect *)SDL_AllocateRenderVertices(renderer, 2 * sizeof(SDL_Rect), 0, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = 1; @@ -254,7 +254,7 @@ static int SW_QueueCopy(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Text verts->w = (int)dstrect->w; verts->h = (int)dstrect->h; - return 0; + return true; } typedef struct CopyExData @@ -268,14 +268,14 @@ typedef struct CopyExData float scale_y; } CopyExData; -static int SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const SDL_FRect *srcrect, const SDL_FRect *dstrect, const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y) { CopyExData *verts = (CopyExData *)SDL_AllocateRenderVertices(renderer, sizeof(CopyExData), 0, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = 1; @@ -294,13 +294,13 @@ static int SW_QueueCopyEx(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Te verts->scale_x = scale_x; verts->scale_y = scale_y; - return 0; + return true; } -static int Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect, +static bool Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect, float scale_x, float scale_y, SDL_ScaleMode scaleMode) { - int retval; + bool result; // Renderer scaling, if needed if (scale_x != 1.0f || scale_y != 1.0f) { SDL_Rect r; @@ -308,22 +308,22 @@ static int Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surf r.y = (int)((float)dstrect->y * scale_y); r.w = (int)((float)dstrect->w * scale_x); r.h = (int)((float)dstrect->h * scale_y); - retval = SDL_BlitSurfaceScaled(src, srcrect, surface, &r, scaleMode); + result = SDL_BlitSurfaceScaled(src, srcrect, surface, &r, scaleMode); } else { - retval = SDL_BlitSurface(src, srcrect, surface, dstrect); + result = SDL_BlitSurface(src, srcrect, surface, dstrect); } - return retval; + return result; } -static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Texture *texture, - const SDL_Rect *srcrect, const SDL_Rect *final_rect, - const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y) +static bool SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Texture *texture, + const SDL_Rect *srcrect, const SDL_Rect *final_rect, + const double angle, const SDL_FPoint *center, const SDL_FlipMode flip, float scale_x, float scale_y) { SDL_Surface *src = (SDL_Surface *)texture->internal; SDL_Rect tmp_rect; SDL_Surface *src_clone, *src_rotated, *src_scaled; SDL_Surface *mask = NULL, *mask_rotated = NULL; - int retval = 0; + bool result = true; SDL_BlendMode blendmode; Uint8 alphaMod, rMod, gMod, bMod; int applyModulation = false; @@ -331,7 +331,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex int isOpaque = false; if (!SDL_SurfaceValid(surface)) { - return -1; + return false; } tmp_rect.x = 0; @@ -343,8 +343,8 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex * necessary because this code is going to access the pixel buffer directly. */ if (SDL_MUSTLOCK(src)) { - if (SDL_LockSurface(src) < 0) { - return -1; + if (!SDL_LockSurface(src)) { + return false; } } @@ -356,7 +356,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex if (SDL_MUSTLOCK(src)) { SDL_UnlockSurface(src); } - return -1; + return false; } SDL_GetSurfaceBlendMode(src, &blendmode); @@ -396,7 +396,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) { mask = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888); if (!mask) { - retval = -1; + result = false; } else { SDL_SetSurfaceBlendMode(mask, SDL_BLENDMODE_MOD); } @@ -405,14 +405,14 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex /* Create a new surface should there be a format mismatch or if scaling, cropping, * or modulation is required. It's possible to use the source surface directly otherwise. */ - if (!retval && (blitRequired || applyModulation)) { + if (result && (blitRequired || applyModulation)) { SDL_Rect scale_rect = tmp_rect; src_scaled = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888); if (!src_scaled) { - retval = -1; + result = false; } else { SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE); - retval = SDL_BlitSurfaceScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode); + result = SDL_BlitSurfaceScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode); SDL_DestroySurface(src_clone); src_clone = src_scaled; src_scaled = NULL; @@ -422,7 +422,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex // SDLgfx_rotateSurface is going to make decisions depending on the blend mode. SDL_SetSurfaceBlendMode(src_clone, blendmode); - if (!retval) { + if (result) { SDL_Rect rect_dest; double cangle, sangle; @@ -432,18 +432,18 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex (texture->scaleMode == SDL_SCALEMODE_NEAREST) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, &rect_dest, cangle, sangle, center); if (!src_rotated) { - retval = -1; + result = false; } - if (!retval && mask) { + if (result && mask) { // The mask needed for the NONE blend mode gets rotated with the same parameters. mask_rotated = SDLgfx_rotateSurface(mask, angle, false, 0, 0, &rect_dest, cangle, sangle, center); if (!mask_rotated) { - retval = -1; + result = false; } } - if (!retval) { + if (result) { tmp_rect.x = final_rect->x + rect_dest.x; tmp_rect.y = final_rect->y + rect_dest.y; @@ -460,7 +460,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex SDL_SetSurfaceColorMod(src_rotated, rMod, gMod, bMod); } // Renderer scaling, if needed - retval = Blit_to_Screen(src_rotated, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode); + result = Blit_to_Screen(src_rotated, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode); } else { /* The NONE blend mode requires three steps to get the pixels onto the destination surface. * First, the area where the rotated pixels will be blitted to get set to zero. @@ -470,8 +470,8 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex SDL_Rect mask_rect = tmp_rect; SDL_SetSurfaceBlendMode(mask_rotated, SDL_BLENDMODE_NONE); // Renderer scaling, if needed - retval = Blit_to_Screen(mask_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode); - if (!retval) { + result = Blit_to_Screen(mask_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode); + if (result) { /* The next step copies the alpha value. This is done with the BLEND blend mode and * by modulating the source colors with 0. Since the destination is all zeros, this * will effectively set the destination alpha to the source alpha. @@ -479,8 +479,8 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex SDL_SetSurfaceColorMod(src_rotated, 0, 0, 0); mask_rect = tmp_rect; // Renderer scaling, if needed - retval = Blit_to_Screen(src_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode); - if (!retval) { + result = Blit_to_Screen(src_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode); + if (result) { /* The last step gets the color values in place. The ADD blend mode simply adds them to * the destination (where the color values are all zero). However, because the ADD blend * mode modulates the colors with the alpha channel, a surface without an alpha mask needs @@ -488,11 +488,11 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex */ SDL_Surface *src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->w, src_rotated->h, src_rotated->format, src_rotated->pixels, src_rotated->pitch); if (!src_rotated_rgb) { - retval = -1; + result = false; } else { SDL_SetSurfaceBlendMode(src_rotated_rgb, SDL_BLENDMODE_ADD); // Renderer scaling, if needed - retval = Blit_to_Screen(src_rotated_rgb, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode); + result = Blit_to_Screen(src_rotated_rgb, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode); SDL_DestroySurface(src_rotated_rgb); } } @@ -514,7 +514,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex if (src_clone) { SDL_DestroySurface(src_clone); } - return retval; + return result; } typedef struct GeometryFillData @@ -530,7 +530,7 @@ typedef struct GeometryCopyData SDL_Color color; } GeometryCopyData; -static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -543,7 +543,7 @@ static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_ verts = SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -617,7 +617,7 @@ static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_ ptr++; } } - return 0; + return true; } static void PrepTextureForCopy(const SDL_RenderCommand *cmd, SW_DrawStateCache *drawstate) @@ -671,13 +671,13 @@ static void SW_InvalidateCachedState(SDL_Renderer *renderer) } -static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { SDL_Surface *surface = SW_ActivateRenderer(renderer); SW_DrawStateCache drawstate; if (!SDL_SurfaceValid(surface)) { - return -1; + return false; } drawstate.viewport = NULL; @@ -960,7 +960,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo cmd = cmd->next; } - return 0; + return true; } static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect) @@ -989,12 +989,12 @@ static SDL_Surface *SW_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect * return SDL_DuplicatePixels(rect->w, rect->h, surface->format, SDL_COLORSPACE_SRGB, pixels, surface->pitch); } -static int SW_RenderPresent(SDL_Renderer *renderer) +static bool SW_RenderPresent(SDL_Renderer *renderer) { SDL_Window *window = renderer->window; if (!window) { - return -1; + return false; } return SDL_UpdateWindowSurface(window); } @@ -1112,7 +1112,7 @@ static void SW_SelectBestFormats(SDL_Renderer *renderer, SDL_PixelFormat format) } } -int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props) +bool SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props) { SW_RenderData *data; @@ -1124,7 +1124,7 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD data = (SW_RenderData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } data->surface = surface; data->window = surface; @@ -1164,10 +1164,10 @@ int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SD return SDL_SetError("Unsupported output colorspace"); } - return 0; + return true; } -static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { // Set the vsync hint based on our flags, if it's not already set const char *hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC); @@ -1189,7 +1189,7 @@ static int SW_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_Pro } if (!SDL_SurfaceValid(surface)) { - return -1; + return false; } return SW_CreateRendererForSurface(renderer, surface, create_props); diff --git a/src/render/software/SDL_render_sw_c.h b/src/render/software/SDL_render_sw_c.h index 060c8ce0f9..a17e4120f2 100644 --- a/src/render/software/SDL_render_sw_c.h +++ b/src/render/software/SDL_render_sw_c.h @@ -22,6 +22,6 @@ #ifndef SDL_render_sw_c_h_ #define SDL_render_sw_c_h_ -extern int SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props); +extern bool SW_CreateRendererForSurface(SDL_Renderer *renderer, SDL_Surface *surface, SDL_PropertiesID create_props); #endif // SDL_render_sw_c_h_ diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c index e8105dd797..e7278b285a 100644 --- a/src/render/software/SDL_rotate.c +++ b/src/render/software/SDL_rotate.c @@ -501,7 +501,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in } if (SDL_SurfaceHasColorKey(src)) { - if (SDL_GetSurfaceColorKey(src, &colorkey) == 0) { + if (SDL_GetSurfaceColorKey(src, &colorkey)) { colorKeyAvailable = true; } } @@ -561,7 +561,7 @@ SDL_Surface *SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, in // Lock source surface if (SDL_MUSTLOCK(src)) { - if (SDL_LockSurface(src) < 0) { + if (!SDL_LockSurface(src)) { SDL_DestroySurface(rz_dst); return NULL; } diff --git a/src/render/software/SDL_triangle.c b/src/render/software/SDL_triangle.c index cded09f8e3..7af531f105 100644 --- a/src/render/software/SDL_triangle.c +++ b/src/render/software/SDL_triangle.c @@ -45,13 +45,13 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info, SDL_Color c0, SDL_Color c1, SDL_Color c2, bool is_uniform, SDL_TextureAddressMode texture_address_mode); #if 0 -int SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface *dst, const SDL_Point dstpoints[3]) +bool SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface *dst, const SDL_Point dstpoints[3]) { int i; SDL_Point points[6]; if (src == NULL || dst == NULL) { - return -1; + return false; } for (i = 0; i < 3; i++) { @@ -72,12 +72,12 @@ int SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface return SDL_SW_BlitTriangle(src, dst, points); } -int SDL_FillTriangle(SDL_Surface *dst, const SDL_Point points[3], Uint32 color) +bool SDL_FillTriangle(SDL_Surface *dst, const SDL_Point points[3], Uint32 color) { int i; SDL_Point points_tmp[3]; if (dst == NULL) { - return -1; + return false; } for (i = 0; i < 3; i++) { points_tmp[i] = points[i]; @@ -94,24 +94,24 @@ static Sint64 cross_product(const SDL_Point *a, const SDL_Point *b, int c_x, int } // check for top left rules -static int is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise) +static bool is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise) { if (is_clockwise) { if (a->y == b->y && a->x < b->x) { - return 1; + return true; } if (b->y < a->y) { - return 1; + return true; } } else { if (a->y == b->y && b->x < a->x) { - return 1; + return true; } if (a->y < b->y) { - return 1; + return true; } } - return 0; + return false; } // x = (y << FP_BITS) @@ -223,9 +223,9 @@ static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Poin } \ } -int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2) +bool SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2) { - int ret = 0; + bool result = true; int dst_locked = 0; SDL_Rect dstrect; @@ -246,7 +246,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin SDL_Surface *tmp = NULL; if (!SDL_SurfaceValid(dst)) { - return -1; + return false; } area = cross_product(d0, d1, d2->x, d2->y); @@ -255,13 +255,13 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin // Flat triangle if (area == 0) { - return 0; + return true; } // Lock the destination, if needed if (SDL_MUSTLOCK(dst)) { - if (SDL_LockSurface(dst) < 0) { - ret = -1; + if (!SDL_LockSurface(dst)) { + result = false; goto end; } else { dst_locked = 1; @@ -298,7 +298,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin // Use an intermediate surface tmp = SDL_CreateSurface(dstrect.w, dstrect.h, format); if (!tmp) { - ret = -1; + result = false; goto end; } @@ -456,10 +456,10 @@ end: SDL_UnlockSurface(dst); } - return ret; + return result; } -int SDL_SW_BlitTriangle( +bool SDL_SW_BlitTriangle( SDL_Surface *src, SDL_Point *s0, SDL_Point *s1, SDL_Point *s2, SDL_Surface *dst, @@ -467,8 +467,8 @@ int SDL_SW_BlitTriangle( SDL_Color c0, SDL_Color c1, SDL_Color c2, SDL_TextureAddressMode texture_address_mode) { + bool result = true; SDL_Surface *src_surface = src; - int ret = 0; int src_locked = 0; int dst_locked = 0; @@ -509,13 +509,13 @@ int SDL_SW_BlitTriangle( // Flat triangle if (area == 0) { - return 0; + return true; } // Lock the destination, if needed if (SDL_MUSTLOCK(dst)) { - if (SDL_LockSurface(dst) < 0) { - ret = -1; + if (!SDL_LockSurface(dst)) { + result = false; goto end; } else { dst_locked = 1; @@ -524,8 +524,8 @@ int SDL_SW_BlitTriangle( // Lock the source, if needed if (SDL_MUSTLOCK(src)) { - if (SDL_LockSurface(src) < 0) { - ret = -1; + if (!SDL_LockSurface(src)) { + result = false; goto end; } else { src_locked = 1; @@ -648,14 +648,14 @@ int SDL_SW_BlitTriangle( if (tmp64 >= INT_MIN && tmp64 <= INT_MAX) { s2_x_area.x = (int)tmp64; } else { - ret = SDL_SetError("triangle area overflow"); + result = SDL_SetError("triangle area overflow"); goto end; } tmp64 = s2->y * area; if (tmp64 >= INT_MIN && tmp64 <= INT_MAX) { s2_x_area.y = (int)tmp64; } else { - ret = SDL_SetError("triangle area overflow"); + result = SDL_SetError("triangle area overflow"); goto end; } @@ -706,7 +706,7 @@ int SDL_SW_BlitTriangle( #define CHECK_INT_RANGE(X) \ if ((X) < INT_MIN || (X) > INT_MAX) { \ - ret = SDL_SetError("integer overflow (%s = %" SDL_PRIs64 ")", #X, X); \ + result = SDL_SetError("integer overflow (%s = %" SDL_PRIs64 ")", #X, X); \ goto end; \ } CHECK_INT_RANGE(area); @@ -765,7 +765,7 @@ end: SDL_UnlockSurface(src); } - return ret; + return result; } #define FORMAT_ALPHA 0 diff --git a/src/render/software/SDL_triangle.h b/src/render/software/SDL_triangle.h index 5ecca68b54..1fe9ba65ba 100644 --- a/src/render/software/SDL_triangle.h +++ b/src/render/software/SDL_triangle.h @@ -26,17 +26,16 @@ #include "../SDL_sysrender.h" // For SDL_TextureAddressMode -extern int SDL_SW_FillTriangle(SDL_Surface *dst, - SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, - SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2); +extern bool SDL_SW_FillTriangle(SDL_Surface *dst, + SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, + SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2); -extern int SDL_SW_BlitTriangle( - SDL_Surface *src, - SDL_Point *s0, SDL_Point *s1, SDL_Point *s2, - SDL_Surface *dst, - SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, - SDL_Color c0, SDL_Color c1, SDL_Color c2, - SDL_TextureAddressMode texture_address_mode); +extern bool SDL_SW_BlitTriangle(SDL_Surface *src, + SDL_Point *s0, SDL_Point *s1, SDL_Point *s2, + SDL_Surface *dst, + SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, + SDL_Color c0, SDL_Color c1, SDL_Color c2, + SDL_TextureAddressMode texture_address_mode); extern void trianglepoint_2_fixedpoint(SDL_Point *a); diff --git a/src/render/vitagxm/SDL_render_vita_gxm.c b/src/render/vitagxm/SDL_render_vita_gxm.c index 6cf8bca8d1..3f0107d178 100644 --- a/src/render/vitagxm/SDL_render_vita_gxm.c +++ b/src/render/vitagxm/SDL_render_vita_gxm.c @@ -42,29 +42,29 @@ #include #endif -static int VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props); +static bool VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props); static void VITA_GXM_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event); static bool VITA_GXM_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blendMode); -static int VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props); +static bool VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props); -static int VITA_GXM_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch); -static int VITA_GXM_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch); -static int VITA_GXM_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch); -static int VITA_GXM_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch); static void VITA_GXM_UnlockTexture(SDL_Renderer *renderer, @@ -72,30 +72,30 @@ static void VITA_GXM_UnlockTexture(SDL_Renderer *renderer, static void VITA_GXM_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *texture, SDL_ScaleMode scaleMode); -static int VITA_GXM_SetRenderTarget(SDL_Renderer *renderer, +static bool VITA_GXM_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture); -static int VITA_GXM_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd); +static bool VITA_GXM_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd); -static int VITA_GXM_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd); +static bool VITA_GXM_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd); -static int VITA_GXM_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count); -static int VITA_GXM_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count); +static bool VITA_GXM_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count); +static bool VITA_GXM_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count); -static int VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y); -static int VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd); +static bool VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd); static void VITA_GXM_InvalidateCachedState(SDL_Renderer *renderer); -static int VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize); +static bool VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize); static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect); -static int VITA_GXM_RenderPresent(SDL_Renderer *renderer); +static bool VITA_GXM_RenderPresent(SDL_Renderer *renderer); static void VITA_GXM_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture); static void VITA_GXM_DestroyRenderer(SDL_Renderer *renderer); @@ -180,7 +180,7 @@ void StartDrawing(SDL_Renderer *renderer) data->drawing = true; } -static int VITA_GXM_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool VITA_GXM_SetVSync(SDL_Renderer *renderer, const int vsync) { VITA_GXM_RenderData *data = renderer->internal; if (vsync) { @@ -188,10 +188,10 @@ static int VITA_GXM_SetVSync(SDL_Renderer *renderer, const int vsync) } else { data->displayData.wait_vblank = false; } - return 0; + return true; } -static int VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { VITA_GXM_RenderData *data; @@ -203,7 +203,7 @@ static int VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, S data = (VITA_GXM_RenderData *)SDL_calloc(1, sizeof(VITA_GXM_RenderData)); if (!data) { - return -1; + return false; } renderer->WindowEvent = VITA_GXM_WindowEvent; @@ -257,7 +257,7 @@ static int VITA_GXM_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, S return SDL_SetError("gxm_init failed"); } - return 0; + return true; } static void VITA_GXM_WindowEvent(SDL_Renderer *renderer, const SDL_WindowEvent *event) @@ -270,13 +270,13 @@ static bool VITA_GXM_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode ble return false; } -static int VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal; VITA_GXM_TextureData *vita_texture = (VITA_GXM_TextureData *)SDL_calloc(1, sizeof(VITA_GXM_TextureData)); if (!vita_texture) { - return -1; + return false; } vita_texture->tex = create_gxm_texture( @@ -304,7 +304,7 @@ static int VITA_GXM_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, vita_texture->nv12 = ((texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21)); #endif - return 0; + return true; } static void VITA_GXM_SetYUVProfile(SDL_Renderer *renderer, SDL_Texture *texture) @@ -332,7 +332,7 @@ static void VITA_GXM_SetYUVProfile(SDL_Renderer *renderer, SDL_Texture *texture) } } -static int VITA_GXM_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *pixels, int pitch) { VITA_GXM_TextureData *vita_texture = (VITA_GXM_TextureData *)texture->internal; @@ -420,11 +420,11 @@ static int VITA_GXM_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, } #endif - return 0; + return true; } #if SDL_HAVE_YUV -static int VITA_GXM_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -495,10 +495,10 @@ static int VITA_GXM_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *textur } } - return 0; + return true; } -static int VITA_GXM_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) @@ -550,12 +550,12 @@ static int VITA_GXM_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture } } - return 0; + return true; } #endif -static int VITA_GXM_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VITA_GXM_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal; @@ -570,7 +570,7 @@ static int VITA_GXM_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, sceGxmFinish(data->gxm_context); } - return 0; + return true; } static void VITA_GXM_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture) @@ -599,9 +599,9 @@ static void VITA_GXM_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *te return; } -static int VITA_GXM_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool VITA_GXM_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { - return 0; + return true; } static void VITA_GXM_SetBlendMode(VITA_GXM_RenderData *data, int blendMode) @@ -632,12 +632,12 @@ static void VITA_GXM_SetBlendMode(VITA_GXM_RenderData *data, int blendMode) } } -static int VITA_GXM_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool VITA_GXM_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; + return true; } -static int VITA_GXM_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool VITA_GXM_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal; @@ -646,10 +646,10 @@ static int VITA_GXM_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand data->drawstate.color.b = cmd->data.color.color.b * cmd->data.color.color_scale; data->drawstate.color.a = cmd->data.color.color.a; - return 0; + return true; } -static int VITA_GXM_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool VITA_GXM_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal; @@ -668,10 +668,10 @@ static int VITA_GXM_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *c vertex[i].color = color; } - return 0; + return true; } -static int VITA_GXM_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool VITA_GXM_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal; SDL_FColor color = data->drawstate.color; @@ -693,10 +693,10 @@ static int VITA_GXM_QueueDrawLines(SDL_Renderer *renderer, SDL_RenderCommand *cm vertex[i * 2 + 1].color = color; } - return 0; + return true; } -static int VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -718,7 +718,7 @@ static int VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd count * sizeof(texture_vertex)); if (!vertices) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -761,7 +761,7 @@ static int VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd count * sizeof(color_vertex)); if (!vertices) { - return -1; + return false; } for (i = 0; i < count; i++) { @@ -792,10 +792,10 @@ static int VITA_GXM_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd cmd->data.draw.first = (size_t)vertices; } - return 0; + return true; } -static int VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { void *color_buffer; SDL_FColor color; @@ -822,10 +822,10 @@ static int VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd) sceGxmDraw(data->gxm_context, SCE_GXM_PRIMITIVE_TRIANGLES, SCE_GXM_INDEX_FORMAT_U16, data->linearIndices, 3); data->drawstate.cliprect_dirty = true; - return 0; + return true; } -static int SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd) +static bool SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd) { SDL_Texture *texture = cmd->data.draw.texture; const SDL_BlendMode blend = cmd->data.draw.blend; @@ -918,7 +918,7 @@ static int SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd) // all drawing commands use this sceGxmSetVertexStream(data->gxm_context, 0, (const void *)cmd->data.draw.first); - return 0; + return true; } static void VITA_GXM_InvalidateCachedState(SDL_Renderer *renderer) @@ -926,7 +926,7 @@ static void VITA_GXM_InvalidateCachedState(SDL_Renderer *renderer) // currently this doesn't do anything. If this needs to do something (and someone is mixing their own rendering calls in!), update this. } -static int VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal; StartDrawing(renderer); @@ -1018,7 +1018,7 @@ static int VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *c ret = SetDrawState(data, cmd); - if (ret == 0) { + if (ret) { int op = SCE_GXM_PRIMITIVE_TRIANGLES; if (thiscmdtype == SDL_RENDERCMD_DRAW_POINTS) { @@ -1050,7 +1050,7 @@ static int VITA_GXM_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *c sceGxmEndScene(data->gxm_context, NULL, NULL); data->drawing = false; - return 0; + return true; } void read_pixels(int x, int y, size_t width, size_t height, void *data) @@ -1120,7 +1120,7 @@ static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_ return surface; } -static int VITA_GXM_RenderPresent(SDL_Renderer *renderer) +static bool VITA_GXM_RenderPresent(SDL_Renderer *renderer) { VITA_GXM_RenderData *data = (VITA_GXM_RenderData *)renderer->internal; SceCommonDialogUpdateParam updateParam; @@ -1159,7 +1159,7 @@ static int VITA_GXM_RenderPresent(SDL_Renderer *renderer) data->pool_index = 0; data->current_pool = (data->current_pool + 1) % 2; - return 0; + return true; } static void VITA_GXM_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture) diff --git a/src/render/vulkan/SDL_render_vulkan.c b/src/render/vulkan/SDL_render_vulkan.c index 2cc6da444e..335d12c1ae 100644 --- a/src/render/vulkan/SDL_render_vulkan.c +++ b/src/render/vulkan/SDL_render_vulkan.c @@ -1331,7 +1331,7 @@ static VkResult VULKAN_CreateVertexBuffer(VULKAN_RenderData *rendererData, size_ return result; } -static int VULKAN_LoadGlobalFunctions(VULKAN_RenderData *rendererData) +static bool VULKAN_LoadGlobalFunctions(VULKAN_RenderData *rendererData) { #define VULKAN_DEVICE_FUNCTION(name) #define VULKAN_GLOBAL_FUNCTION(name) \ @@ -1339,7 +1339,7 @@ static int VULKAN_LoadGlobalFunctions(VULKAN_RenderData *rendererData) if (!name) { \ SDL_LogError(SDL_LOG_CATEGORY_RENDER, \ "vkGetInstanceProcAddr(VK_NULL_HANDLE, \"" #name "\") failed\n"); \ - return -1; \ + return false; \ } #define VULKAN_INSTANCE_FUNCTION(name) #define VULKAN_OPTIONAL_INSTANCE_FUNCTION(name) @@ -1351,10 +1351,10 @@ static int VULKAN_LoadGlobalFunctions(VULKAN_RenderData *rendererData) #undef VULKAN_OPTIONAL_INSTANCE_FUNCTION #undef VULKAN_OPTIONAL_DEVICE_FUNCTION - return 0; + return true; } -static int VULKAN_LoadInstanceFunctions(VULKAN_RenderData *rendererData) +static bool VULKAN_LoadInstanceFunctions(VULKAN_RenderData *rendererData) { #define VULKAN_DEVICE_FUNCTION(name) #define VULKAN_GLOBAL_FUNCTION(name) @@ -1363,7 +1363,7 @@ static int VULKAN_LoadInstanceFunctions(VULKAN_RenderData *rendererData) if (!name) { \ SDL_LogError(SDL_LOG_CATEGORY_RENDER, \ "vkGetInstanceProcAddr(instance, \"" #name "\") failed\n"); \ - return -1; \ + return false; \ } #define VULKAN_OPTIONAL_INSTANCE_FUNCTION(name) \ name = (PFN_##name)rendererData->vkGetInstanceProcAddr(rendererData->instance, #name); @@ -1376,17 +1376,17 @@ static int VULKAN_LoadInstanceFunctions(VULKAN_RenderData *rendererData) #undef VULKAN_OPTIONAL_INSTANCE_FUNCTION #undef VULKAN_OPTIONAL_DEVICE_FUNCTION - return 0; + return true; } -static int VULKAN_LoadDeviceFunctions(VULKAN_RenderData *rendererData) +static bool VULKAN_LoadDeviceFunctions(VULKAN_RenderData *rendererData) { #define VULKAN_DEVICE_FUNCTION(name) \ name = (PFN_##name)vkGetDeviceProcAddr(rendererData->device, #name); \ if (!name) { \ SDL_LogError(SDL_LOG_CATEGORY_RENDER, \ "vkGetDeviceProcAddr(device, \"" #name "\") failed\n"); \ - return -1; \ + return false; \ } #define VULKAN_GLOBAL_FUNCTION(name) #define VULKAN_OPTIONAL_DEVICE_FUNCTION(name) \ @@ -1399,7 +1399,7 @@ static int VULKAN_LoadDeviceFunctions(VULKAN_RenderData *rendererData) #undef VULKAN_INSTANCE_FUNCTION #undef VULKAN_OPTIONAL_INSTANCE_FUNCTION #undef VULKAN_OPTIONAL_DEVICE_FUNCTION - return 0; + return true; } static VkResult VULKAN_FindPhysicalDevice(VULKAN_RenderData *rendererData) @@ -1694,7 +1694,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert bool createDebug = SDL_GetHintBoolean(SDL_HINT_RENDER_VULKAN_DEBUG, false); const char *validationLayerName[] = { SDL_VULKAN_VALIDATION_LAYER_NAME }; - if (SDL_Vulkan_LoadLibrary(NULL) < 0) { + if (!SDL_Vulkan_LoadLibrary(NULL)) { SDL_LogDebug(SDL_LOG_CATEGORY_RENDER, "SDL_Vulkan_LoadLibrary failed." ); return VK_ERROR_UNKNOWN; } @@ -1706,7 +1706,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert // Load global Vulkan functions rendererData->vkGetInstanceProcAddr = vkGetInstanceProcAddr; - if (VULKAN_LoadGlobalFunctions(rendererData) != 0) { + if (!VULKAN_LoadGlobalFunctions(rendererData)) { return VK_ERROR_UNKNOWN; } @@ -1763,7 +1763,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert } // Load instance Vulkan functions - if (VULKAN_LoadInstanceFunctions(rendererData) != 0) { + if (!VULKAN_LoadInstanceFunctions(rendererData)) { VULKAN_DestroyAll(renderer); return VK_ERROR_UNKNOWN; } @@ -1773,7 +1773,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert if (rendererData->surface) { rendererData->surface_external = true; } else { - if (!device->Vulkan_CreateSurface || (device->Vulkan_CreateSurface(device, renderer->window, rendererData->instance, NULL, &rendererData->surface) < 0)) { + if (!device->Vulkan_CreateSurface || !device->Vulkan_CreateSurface(device, renderer->window, rendererData->instance, NULL, &rendererData->surface)) { VULKAN_DestroyAll(renderer); SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Vulkan_CreateSurface() failed.\n"); return VK_ERROR_UNKNOWN; @@ -1850,7 +1850,7 @@ static VkResult VULKAN_CreateDeviceResources(SDL_Renderer *renderer, SDL_Propert } } - if (VULKAN_LoadDeviceFunctions(rendererData) != 0) { + if (!VULKAN_LoadDeviceFunctions(rendererData)) { VULKAN_DestroyAll(renderer); return VK_ERROR_UNKNOWN; } @@ -2496,7 +2496,7 @@ static bool VULKAN_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode blend return true; } -static int VULKAN_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) +static bool VULKAN_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; VULKAN_TextureData *textureData; @@ -2511,7 +2511,7 @@ static int VULKAN_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD textureData = (VULKAN_TextureData *)SDL_calloc(1, sizeof(*textureData)); if (!textureData) { - return -1; + return false; } texture->internal = textureData; if (SDL_COLORSPACETRANSFER(texture->colorspace) == SDL_TRANSFER_CHARACTERISTICS_SRGB) { @@ -2822,7 +2822,7 @@ static VkResult VULKAN_UpdateTextureInternal(VULKAN_RenderData *rendererData, Vk } -static int VULKAN_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VULKAN_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const void *srcPixels, int srcPitch) { @@ -2833,8 +2833,8 @@ static int VULKAN_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 0, rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 0, rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch, &textureData->mainImage.imageLayout)) { + return false; } #if SDL_HAVE_YUV Uint32 numPlanes = VULKAN_VkFormatGetNumPlanes(textureData->mainImage.format); @@ -2843,8 +2843,8 @@ static int VULKAN_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, // YUV data if (numPlanes == 3) { for (Uint32 plane = 1; plane < numPlanes; plane++) { - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, plane, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, plane, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, (srcPitch + 1) / 2, &textureData->mainImage.imageLayout)) { + return false; } // Skip to the correct offset into the next texture @@ -2860,16 +2860,16 @@ static int VULKAN_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, srcPitch = (srcPitch + 1) & ~1; } - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 1, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, srcPitch, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 1, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, srcPixels, srcPitch, &textureData->mainImage.imageLayout)) { + return false; } } #endif - return 0; + return true; } #if SDL_HAVE_YUV -static int VULKAN_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VULKAN_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, @@ -2882,19 +2882,19 @@ static int VULKAN_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainImage.imageLayout)) { + return false; } - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 1, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 1, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch, &textureData->mainImage.imageLayout)) { + return false; } - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 2, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 2, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch, &textureData->mainImage.imageLayout)) { + return false; } - return 0; + return true; } -static int VULKAN_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VULKAN_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *UVplane, int UVpitch) @@ -2906,18 +2906,18 @@ static int VULKAN_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture, return SDL_SetError("Texture is not currently available"); } - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 0, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch, &textureData->mainImage.imageLayout)) { + return false; } - if (VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 1, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, UVplane, UVpitch, &textureData->mainImage.imageLayout) < 0) { - return -1; + if (!VULKAN_UpdateTextureInternal(rendererData, textureData->mainImage.image, textureData->mainImage.format, 1, rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2, UVplane, UVpitch, &textureData->mainImage.imageLayout)) { + return false; } - return 0; + return true; } #endif -static int VULKAN_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, +static bool VULKAN_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *rect, void **pixels, int *pitch) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; @@ -2955,7 +2955,7 @@ static int VULKAN_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture, */ *pixels = textureData->stagingBuffer.mappedBufferPtr; *pitch = (int)length; - return 0; + return true; } @@ -3023,7 +3023,7 @@ static void VULKAN_SetTextureScaleMode(SDL_Renderer *renderer, SDL_Texture *text textureData->scaleMode = (scaleMode == SDL_SCALEMODE_NEAREST) ? VK_FILTER_NEAREST : VK_FILTER_LINEAR; } -static int VULKAN_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) +static bool VULKAN_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; VULKAN_TextureData *textureData = NULL; @@ -3043,7 +3043,7 @@ static int VULKAN_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) &rendererData->textureRenderTarget->mainImage.imageLayout); } rendererData->textureRenderTarget = NULL; - return 0; + return true; } textureData = (VULKAN_TextureData *)texture->internal; @@ -3062,22 +3062,22 @@ static int VULKAN_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) rendererData->textureRenderTarget->mainImage.image, &rendererData->textureRenderTarget->mainImage.imageLayout); - return 0; + return true; } -static int VULKAN_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) +static bool VULKAN_QueueNoOp(SDL_Renderer *renderer, SDL_RenderCommand *cmd) { - return 0; // nothing to do in this backend. + return true; // nothing to do in this backend. } -static int VULKAN_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) +static bool VULKAN_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd, const SDL_FPoint *points, int count) { VertexPositionColor *verts = (VertexPositionColor *)SDL_AllocateRenderVertices(renderer, count * sizeof(VertexPositionColor), 0, &cmd->data.draw.first); int i; bool convert_color = SDL_RenderingLinearSpace(renderer); if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -3092,10 +3092,10 @@ static int VULKAN_QueueDrawPoints(SDL_Renderer *renderer, SDL_RenderCommand *cmd } verts++; } - return 0; + return true; } -static int VULKAN_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, +static bool VULKAN_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture, const float *xy, int xy_stride, const SDL_FColor *color, int color_stride, const float *uv, int uv_stride, int num_vertices, const void *indices, int num_indices, int size_indices, float scale_x, float scale_y) @@ -3109,7 +3109,7 @@ static int VULKAN_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, float v_scale = textureData ? (float)texture->h / textureData->height : 0.0f; if (!verts) { - return -1; + return false; } cmd->data.draw.count = count; @@ -3148,7 +3148,7 @@ static int VULKAN_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, verts += 1; } - return 0; + return true; } static bool VULKAN_UpdateVertexBuffer(SDL_Renderer *renderer, @@ -3189,7 +3189,7 @@ static bool VULKAN_UpdateVertexBuffer(SDL_Renderer *renderer, return true; } -static int VULKAN_UpdateViewport(SDL_Renderer *renderer) +static bool VULKAN_UpdateViewport(SDL_Renderer *renderer) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; const SDL_Rect *viewport = &rendererData->currentViewport; @@ -3202,7 +3202,7 @@ static int VULKAN_UpdateViewport(SDL_Renderer *renderer) * with a non-empty viewport. */ // SDL_Log("%s, no viewport was set!\n", __FUNCTION__); - return -1; + return false; } projection = MatrixIdentity(); @@ -3230,10 +3230,10 @@ static int VULKAN_UpdateViewport(SDL_Renderer *renderer) vkCmdSetViewport(rendererData->currentCommandBuffer, 0, 1, &vkViewport); rendererData->viewportDirty = false; - return 0; + return true; } -static int VULKAN_UpdateClipRect(SDL_Renderer *renderer) +static bool VULKAN_UpdateClipRect(SDL_Renderer *renderer) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; const SDL_Rect *viewport = &rendererData->currentViewport; @@ -3253,7 +3253,7 @@ static int VULKAN_UpdateClipRect(SDL_Renderer *renderer) vkCmdSetScissor(rendererData->currentCommandBuffer, 0, 1, &scissor); rendererData->cliprectDirty = false; - return 0; + return true; } static void VULKAN_SetupShaderConstants(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Texture *texture, PixelShaderConstants *constants) @@ -3535,7 +3535,7 @@ static bool VULKAN_SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand } if (rendererData->viewportDirty) { - if (VULKAN_UpdateViewport(renderer) == 0) { + if (!VULKAN_UpdateViewport(renderer)) { // vertexShaderConstantsData.projectionAndView has changed updateConstants = true; } @@ -3707,7 +3707,7 @@ static void VULKAN_InvalidateCachedState(SDL_Renderer *renderer) rendererData->cliprectDirty = true; } -static int VULKAN_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) +static bool VULKAN_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; VULKAN_DrawStateCache stateCache; @@ -3715,13 +3715,13 @@ static int VULKAN_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd if (rendererData->recreateSwapchain) { if (VULKAN_UpdateForWindowSizeChange(renderer) != VK_SUCCESS) { - return -1; + return false; } rendererData->recreateSwapchain = false; } if (!VULKAN_UpdateVertexBuffer(renderer, vertices, vertsize, &stateCache)) { - return -1; + return false; } while (cmd) { @@ -3833,7 +3833,7 @@ static int VULKAN_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd cmd = cmd->next; } - return 0; + return true; } static SDL_Surface* VULKAN_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect) @@ -3932,7 +3932,7 @@ static SDL_Surface* VULKAN_RenderReadPixels(SDL_Renderer *renderer, const SDL_Re return output; } -static int VULKAN_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore) +static bool VULKAN_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_stage_mask, Sint64 wait_semaphore, Sint64 signal_semaphore) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; @@ -3941,13 +3941,13 @@ static int VULKAN_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_ // Allocate an additional one at the end for the normal present wait VkPipelineStageFlags *waitDestStageMasks = (VkPipelineStageFlags *)SDL_realloc(rendererData->waitDestStageMasks, (rendererData->waitRenderSemaphoreMax + 2) * sizeof(*waitDestStageMasks)); if (!waitDestStageMasks) { - return -1; + return false; } rendererData->waitDestStageMasks = waitDestStageMasks; VkSemaphore *semaphores = (VkSemaphore *)SDL_realloc(rendererData->waitRenderSemaphores, (rendererData->waitRenderSemaphoreMax + 2) * sizeof(*semaphores)); if (!semaphores) { - return -1; + return false; } rendererData->waitRenderSemaphores = semaphores; ++rendererData->waitRenderSemaphoreMax; @@ -3962,7 +3962,7 @@ static int VULKAN_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_ // Allocate an additional one at the end for the normal present signal VkSemaphore *semaphores = (VkSemaphore *)SDL_realloc(rendererData->signalRenderSemaphores, (rendererData->signalRenderSemaphoreMax + 2) * sizeof(*semaphores)); if (!semaphores) { - return -1; + return false; } rendererData->signalRenderSemaphores = semaphores; ++rendererData->signalRenderSemaphoreMax; @@ -3971,10 +3971,10 @@ static int VULKAN_AddVulkanRenderSemaphores(SDL_Renderer *renderer, Uint32 wait_ ++rendererData->signalRenderSemaphoreCount; } - return 0; + return true; } -static int VULKAN_RenderPresent(SDL_Renderer *renderer) +static bool VULKAN_RenderPresent(SDL_Renderer *renderer) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; VkResult result = VK_SUCCESS; @@ -3997,7 +3997,7 @@ static int VULKAN_RenderPresent(SDL_Renderer *renderer) result = vkResetFences(rendererData->device, 1, &rendererData->fences[rendererData->currentCommandBufferIndex]); if (result != VK_SUCCESS) { SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkResetFences(): %s\n", SDL_Vulkan_GetResultString(result)); - return -1; + return false; } VkPipelineStageFlags waitDestStageMask = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT; @@ -4032,7 +4032,7 @@ static int VULKAN_RenderPresent(SDL_Renderer *renderer) result = vkQueueSubmit(rendererData->graphicsQueue, 1, &submitInfo, rendererData->fences[rendererData->currentCommandBufferIndex]); if (result != VK_SUCCESS) { SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkQueueSubmit(): %s\n", SDL_Vulkan_GetResultString(result)); - return -1; + return false; } rendererData->currentCommandBuffer = VK_NULL_HANDLE; rendererData->currentImageAvailableSemaphore = VK_NULL_HANDLE; @@ -4048,7 +4048,7 @@ static int VULKAN_RenderPresent(SDL_Renderer *renderer) result = vkQueuePresentKHR(rendererData->presentQueue, &presentInfo); if ((result != VK_SUCCESS) && (result != VK_ERROR_OUT_OF_DATE_KHR) && (result != VK_ERROR_SURFACE_LOST_KHR) && (result != VK_SUBOPTIMAL_KHR )) { SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkQueuePresentKHR(): %s\n", SDL_Vulkan_GetResultString(result)); - return -1; + return false; } rendererData->currentCommandBufferIndex = ( rendererData->currentCommandBufferIndex + 1 ) % rendererData->swapchainImageCount; @@ -4057,16 +4057,16 @@ static int VULKAN_RenderPresent(SDL_Renderer *renderer) result = vkWaitForFences(rendererData->device, 1, &rendererData->fences[rendererData->currentCommandBufferIndex], VK_TRUE, UINT64_MAX); if (result != VK_SUCCESS) { SDL_LogError(SDL_LOG_CATEGORY_RENDER, "vkWaitForFences(): %s\n", SDL_Vulkan_GetResultString(result)); - return -1; + return false; } VULKAN_AcquireNextSwapchainImage(renderer); } - return 0; + return true; } -static int VULKAN_SetVSync(SDL_Renderer *renderer, const int vsync) +static bool VULKAN_SetVSync(SDL_Renderer *renderer, const int vsync) { VULKAN_RenderData *rendererData = (VULKAN_RenderData *)renderer->internal; @@ -4083,10 +4083,10 @@ static int VULKAN_SetVSync(SDL_Renderer *renderer, const int vsync) rendererData->vsync = vsync; rendererData->recreateSwapchain = true; } - return 0; + return true; } -static int VULKAN_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) +static bool VULKAN_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL_PropertiesID create_props) { VULKAN_RenderData *rendererData; @@ -4100,7 +4100,7 @@ static int VULKAN_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL rendererData = (VULKAN_RenderData *)SDL_calloc(1, sizeof(*rendererData)); if (!rendererData) { - return -1; + return false; } rendererData->identity = MatrixIdentity(); @@ -4151,9 +4151,9 @@ static int VULKAN_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL // Initialize Vulkan resources if (VULKAN_CreateDeviceResources(renderer, create_props) != VK_SUCCESS) { - return -1; + return false; } else if (VULKAN_CreateWindowSizeDependentResources(renderer) != VK_SUCCESS) { - return -1; + return false; } #if SDL_HAVE_YUV @@ -4166,7 +4166,7 @@ static int VULKAN_CreateRenderer(SDL_Renderer *renderer, SDL_Window *window, SDL } #endif - return 0; + return true; } SDL_RenderDriver VULKAN_RenderDriver = { diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c index 80bbb4aa7e..069571ffec 100644 --- a/src/sensor/SDL_sensor.c +++ b/src/sensor/SDL_sensor.c @@ -57,11 +57,11 @@ static int SDL_sensors_locked; static bool SDL_sensors_initialized; static SDL_Sensor *SDL_sensors SDL_GUARDED_BY(SDL_sensor_lock) = NULL; -#define CHECK_SENSOR_MAGIC(sensor, retval) \ +#define CHECK_SENSOR_MAGIC(sensor, result) \ if (!SDL_ObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR)) { \ SDL_InvalidParamError("sensor"); \ SDL_UnlockSensors(); \ - return retval; \ + return result; \ } bool SDL_SensorsInitialized(void) @@ -120,33 +120,34 @@ void SDL_AssertSensorsLocked(void) SDL_assert(SDL_SensorsLocked()); } -int SDL_InitSensors(void) +bool SDL_InitSensors(void) { - int i, status; + int i; + bool status; // Create the sensor list lock if (SDL_sensor_lock == NULL) { SDL_sensor_lock = SDL_CreateMutex(); } - if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) { - return -1; + if (!SDL_InitSubSystem(SDL_INIT_EVENTS)) { + return false; } SDL_LockSensors(); SDL_sensors_initialized = true; - status = -1; + status = false; for (i = 0; i < SDL_arraysize(SDL_sensor_drivers); ++i) { - if (SDL_sensor_drivers[i]->Init() >= 0) { - status = 0; + if (SDL_sensor_drivers[i]->Init()) { + status = true; } } SDL_UnlockSensors(); - if (status < 0) { + if (!status) { SDL_QuitSensors(); } @@ -331,7 +332,7 @@ SDL_Sensor *SDL_OpenSensor(SDL_SensorID instance_id) sensor->type = driver->GetDeviceType(device_index); sensor->non_portable_type = driver->GetDeviceNonPortableType(device_index); - if (driver->Open(sensor, device_index) < 0) { + if (!driver->Open(sensor, device_index)) { SDL_SetObjectValid(sensor, SDL_OBJECT_TYPE_SENSOR, false); SDL_free(sensor); SDL_UnlockSensors(); @@ -380,7 +381,7 @@ SDL_Sensor *SDL_GetSensorFromID(SDL_SensorID instance_id) */ SDL_PropertiesID SDL_GetSensorProperties(SDL_Sensor *sensor) { - SDL_PropertiesID retval; + SDL_PropertiesID result; SDL_LockSensors(); { @@ -389,11 +390,11 @@ SDL_PropertiesID SDL_GetSensorProperties(SDL_Sensor *sensor) if (sensor->props == 0) { sensor->props = SDL_CreateProperties(); } - retval = sensor->props; + result = sensor->props; } SDL_UnlockSensors(); - return retval; + return result; } /* @@ -401,17 +402,17 @@ SDL_PropertiesID SDL_GetSensorProperties(SDL_Sensor *sensor) */ const char *SDL_GetSensorName(SDL_Sensor *sensor) { - const char *retval; + const char *result; SDL_LockSensors(); { CHECK_SENSOR_MAGIC(sensor, NULL); - retval = SDL_GetPersistentString(sensor->name); + result = SDL_GetPersistentString(sensor->name); } SDL_UnlockSensors(); - return retval; + return result; } /* @@ -419,17 +420,17 @@ const char *SDL_GetSensorName(SDL_Sensor *sensor) */ SDL_SensorType SDL_GetSensorType(SDL_Sensor *sensor) { - SDL_SensorType retval; + SDL_SensorType result; SDL_LockSensors(); { CHECK_SENSOR_MAGIC(sensor, SDL_SENSOR_INVALID); - retval = sensor->type; + result = sensor->type; } SDL_UnlockSensors(); - return retval; + return result; } /* @@ -437,17 +438,17 @@ SDL_SensorType SDL_GetSensorType(SDL_Sensor *sensor) */ int SDL_GetSensorNonPortableType(SDL_Sensor *sensor) { - int retval; + int result; SDL_LockSensors(); { CHECK_SENSOR_MAGIC(sensor, -1); - retval = sensor->non_portable_type; + result = sensor->non_portable_type; } SDL_UnlockSensors(); - return retval; + return result; } /* @@ -455,34 +456,34 @@ int SDL_GetSensorNonPortableType(SDL_Sensor *sensor) */ SDL_SensorID SDL_GetSensorID(SDL_Sensor *sensor) { - SDL_SensorID retval; + SDL_SensorID result; SDL_LockSensors(); { CHECK_SENSOR_MAGIC(sensor, 0); - retval = sensor->instance_id; + result = sensor->instance_id; } SDL_UnlockSensors(); - return retval; + return result; } /* * Get the current state of this sensor */ -int SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values) +SDL_bool SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values) { SDL_LockSensors(); { - CHECK_SENSOR_MAGIC(sensor, -1); + CHECK_SENSOR_MAGIC(sensor, false); num_values = SDL_min(num_values, SDL_arraysize(sensor->data)); SDL_memcpy(data, sensor->data, num_values * sizeof(*data)); } SDL_UnlockSensors(); - return 0; + return true; } /* @@ -558,10 +559,8 @@ void SDL_QuitSensors(void) // These are global for SDL_syssensor.c and SDL_events.c -int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_timestamp, float *data, int num_values) +void SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_timestamp, float *data, int num_values) { - int posted; - SDL_AssertSensorsLocked(); // Allow duplicate events, for things like steps and heartbeats @@ -571,7 +570,6 @@ int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_tim SDL_memcpy(sensor->data, data, num_values * sizeof(*data)); // Post the event, if desired - posted = 0; if (SDL_EventEnabled(SDL_EVENT_SENSOR_UPDATE)) { SDL_Event event; event.type = SDL_EVENT_SENSOR_UPDATE; @@ -581,12 +579,10 @@ int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_tim SDL_memset(event.sensor.data, 0, sizeof(event.sensor.data)); SDL_memcpy(event.sensor.data, data, num_values * sizeof(*data)); event.sensor.sensor_timestamp = sensor_timestamp; - posted = SDL_PushEvent(&event) == 1; + SDL_PushEvent(&event); } SDL_GamepadSensorWatcher(timestamp, sensor->instance_id, sensor_timestamp, data, num_values); - - return posted; } void SDL_UpdateSensor(SDL_Sensor *sensor) diff --git a/src/sensor/SDL_sensor_c.h b/src/sensor/SDL_sensor_c.h index 1adef0bcdc..141603f754 100644 --- a/src/sensor/SDL_sensor_c.h +++ b/src/sensor/SDL_sensor_c.h @@ -32,7 +32,7 @@ struct SDL_SensorDriver; // Useful functions and variables from SDL_sensor.c // Initialization and shutdown functions -extern int SDL_InitSensors(void); +extern bool SDL_InitSensors(void); extern void SDL_QuitSensors(void); // Return whether the sensor system is currently initialized @@ -54,6 +54,6 @@ extern bool SDL_SensorsOpened(void); extern void SDL_UpdateSensor(SDL_Sensor *sensor); // Internal event queueing functions -extern int SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_timestamp, float *data, int num_values); +extern void SDL_SendSensorUpdate(Uint64 timestamp, SDL_Sensor *sensor, Uint64 sensor_timestamp, float *data, int num_values); #endif // SDL_sensor_c_h_ diff --git a/src/sensor/SDL_syssensor.h b/src/sensor/SDL_syssensor.h index 1caed32002..01d7286c04 100644 --- a/src/sensor/SDL_syssensor.h +++ b/src/sensor/SDL_syssensor.h @@ -58,7 +58,7 @@ typedef struct SDL_SensorDriver * sensor 0 should be the system default sensor. * This function should return 0, or -1 on an unrecoverable fatal error. */ - int (*Init)(void); + bool (*Init)(void); // Function to return the number of sensors available right now int (*GetCount)(void); @@ -82,7 +82,7 @@ typedef struct SDL_SensorDriver The sensor to open is specified by the device index. It returns 0, or -1 if there is an error. */ - int (*Open)(SDL_Sensor *sensor, int device_index); + bool (*Open)(SDL_Sensor *sensor, int device_index); /* Function to update the state of a sensor - called as a device poll. * This function shouldn't update the sensor structure directly, diff --git a/src/sensor/android/SDL_androidsensor.c b/src/sensor/android/SDL_androidsensor.c index 93f4732ff9..87dceb8a0d 100644 --- a/src/sensor/android/SDL_androidsensor.c +++ b/src/sensor/android/SDL_androidsensor.c @@ -111,28 +111,28 @@ static void SDL_ANDROID_StopSensorThread(SDL_AndroidSensorThreadContext *ctx) } } -static int SDL_ANDROID_StartSensorThread(SDL_AndroidSensorThreadContext *ctx) +static bool SDL_ANDROID_StartSensorThread(SDL_AndroidSensorThreadContext *ctx) { ctx->sem = SDL_CreateSemaphore(0); if (!ctx->sem) { SDL_ANDROID_StopSensorThread(ctx); - return -1; + return false; } SDL_AtomicSet(&ctx->running, true); ctx->thread = SDL_CreateThread(SDL_ANDROID_SensorThread, "Sensors", ctx); if (!ctx->thread) { SDL_ANDROID_StopSensorThread(ctx); - return -1; + return false; } // Wait for the sensor thread to start SDL_WaitSemaphore(ctx->sem); - return 0; + return true; } -static int SDL_ANDROID_SensorInit(void) +static bool SDL_ANDROID_SensorInit(void) { int i, sensors_count; ASensorList sensors; @@ -147,7 +147,7 @@ static int SDL_ANDROID_SensorInit(void) if (sensors_count > 0) { SDL_sensors = (SDL_AndroidSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { - return -1; + return false; } for (i = 0; i < sensors_count; ++i) { @@ -157,10 +157,10 @@ static int SDL_ANDROID_SensorInit(void) SDL_sensors_count = sensors_count; } - if (SDL_ANDROID_StartSensorThread(&SDL_sensor_thread_context) < 0) { - return -1; + if (!SDL_ANDROID_StartSensorThread(&SDL_sensor_thread_context)) { + return false; } - return 0; + return true; } static int SDL_ANDROID_SensorGetCount(void) @@ -199,7 +199,7 @@ static SDL_SensorID SDL_ANDROID_SensorGetDeviceInstanceID(int device_index) return SDL_sensors[device_index].instance_id; } -static int SDL_ANDROID_SensorOpen(SDL_Sensor *sensor, int device_index) +static bool SDL_ANDROID_SensorOpen(SDL_Sensor *sensor, int device_index) { int delay_us, min_delay_us; @@ -230,7 +230,7 @@ static int SDL_ANDROID_SensorOpen(SDL_Sensor *sensor, int device_index) } SDL_UnlockSensors(); - return 0; + return true; } static void SDL_ANDROID_SensorUpdate(SDL_Sensor *sensor) diff --git a/src/sensor/coremotion/SDL_coremotionsensor.m b/src/sensor/coremotion/SDL_coremotionsensor.m index 2763316d0e..9c14a53711 100644 --- a/src/sensor/coremotion/SDL_coremotionsensor.m +++ b/src/sensor/coremotion/SDL_coremotionsensor.m @@ -39,7 +39,7 @@ static CMMotionManager *SDL_motion_manager; static SDL_CoreMotionSensor *SDL_sensors; static int SDL_sensors_count; -static int SDL_COREMOTION_SensorInit(void) +static bool SDL_COREMOTION_SensorInit(void) { int i, sensors_count = 0; @@ -57,7 +57,7 @@ static int SDL_COREMOTION_SensorInit(void) if (sensors_count > 0) { SDL_sensors = (SDL_CoreMotionSensor *)SDL_calloc(sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { - return -1; + return false; } i = 0; @@ -73,7 +73,7 @@ static int SDL_COREMOTION_SensorInit(void) } SDL_sensors_count = sensors_count; } - return 0; + return true; } static int SDL_COREMOTION_SensorGetCount(void) @@ -112,13 +112,13 @@ static SDL_SensorID SDL_COREMOTION_SensorGetDeviceInstanceID(int device_index) return SDL_sensors[device_index].instance_id; } -static int SDL_COREMOTION_SensorOpen(SDL_Sensor *sensor, int device_index) +static bool SDL_COREMOTION_SensorOpen(SDL_Sensor *sensor, int device_index) { struct sensor_hwdata *hwdata; hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (hwdata == NULL) { - return -1; + return false; } sensor->hwdata = hwdata; @@ -132,7 +132,7 @@ static int SDL_COREMOTION_SensorOpen(SDL_Sensor *sensor, int device_index) default: break; } - return 0; + return true; } static void SDL_COREMOTION_SensorUpdate(SDL_Sensor *sensor) diff --git a/src/sensor/dummy/SDL_dummysensor.c b/src/sensor/dummy/SDL_dummysensor.c index d23d24ff85..1358bd3611 100644 --- a/src/sensor/dummy/SDL_dummysensor.c +++ b/src/sensor/dummy/SDL_dummysensor.c @@ -25,9 +25,9 @@ #include "SDL_dummysensor.h" #include "../SDL_syssensor.h" -static int SDL_DUMMY_SensorInit(void) +static bool SDL_DUMMY_SensorInit(void) { - return 0; + return true; } static int SDL_DUMMY_SensorGetCount(void) @@ -59,7 +59,7 @@ static SDL_SensorID SDL_DUMMY_SensorGetDeviceInstanceID(int device_index) return -1; } -static int SDL_DUMMY_SensorOpen(SDL_Sensor *sensor, int device_index) +static bool SDL_DUMMY_SensorOpen(SDL_Sensor *sensor, int device_index) { return SDL_Unsupported(); } diff --git a/src/sensor/n3ds/SDL_n3dssensor.c b/src/sensor/n3ds/SDL_n3dssensor.c index 77996afea3..e3716c2812 100644 --- a/src/sensor/n3ds/SDL_n3dssensor.c +++ b/src/sensor/n3ds/SDL_n3dssensor.c @@ -38,7 +38,7 @@ typedef struct static SDL_N3DSSensor N3DS_sensors[N3DS_SENSOR_COUNT]; -static int InitN3DSServices(void); +static bool InitN3DSServices(void); static void UpdateN3DSAccelerometer(SDL_Sensor *sensor); static void UpdateN3DSGyroscope(SDL_Sensor *sensor); @@ -47,9 +47,9 @@ static bool IsDeviceIndexValid(int device_index) return device_index >= 0 && device_index < N3DS_SENSOR_COUNT; } -static int N3DS_SensorInit(void) +static bool N3DS_SensorInit(void) { - if (InitN3DSServices() < 0) { + if (!InitN3DSServices()) { return SDL_SetError("Failed to initialise N3DS services"); } @@ -57,23 +57,23 @@ static int N3DS_SensorInit(void) N3DS_sensors[0].instance_id = SDL_GetNextObjectID(); N3DS_sensors[1].type = SDL_SENSOR_GYRO; N3DS_sensors[1].instance_id = SDL_GetNextObjectID(); - return 0; + return true; } -static int InitN3DSServices(void) +static bool InitN3DSServices(void) { if (R_FAILED(hidInit())) { - return -1; + return false; } if (R_FAILED(HIDUSER_EnableAccelerometer())) { - return -1; + return false; } if (R_FAILED(HIDUSER_EnableGyroscope())) { - return -1; + return false; } - return 0; + return true; } static int N3DS_SensorGetCount(void) @@ -122,9 +122,9 @@ static SDL_SensorID N3DS_SensorGetDeviceInstanceID(int device_index) return -1; } -static int N3DS_SensorOpen(SDL_Sensor *sensor, int device_index) +static bool N3DS_SensorOpen(SDL_Sensor *sensor, int device_index) { - return 0; + return true; } static void N3DS_SensorUpdate(SDL_Sensor *sensor) diff --git a/src/sensor/vita/SDL_vitasensor.c b/src/sensor/vita/SDL_vitasensor.c index 047660ab0a..17c2b59549 100644 --- a/src/sensor/vita/SDL_vitasensor.c +++ b/src/sensor/vita/SDL_vitasensor.c @@ -39,7 +39,7 @@ typedef struct static SDL_VitaSensor *SDL_sensors; static int SDL_sensors_count; -static int SDL_VITA_SensorInit(void) +static bool SDL_VITA_SensorInit(void) { sceMotionReset(); sceMotionStartSampling(); @@ -52,7 +52,7 @@ static int SDL_VITA_SensorInit(void) SDL_sensors = (SDL_VitaSensor *)SDL_calloc(SDL_sensors_count, sizeof(*SDL_sensors)); if (!SDL_sensors) { - return -1; + return false; } SDL_sensors[0].type = SDL_SENSOR_ACCEL; @@ -60,7 +60,7 @@ static int SDL_VITA_SensorInit(void) SDL_sensors[1].type = SDL_SENSOR_GYRO; SDL_sensors[1].instance_id = SDL_GetNextObjectID(); - return 0; + return true; } static int SDL_VITA_SensorGetCount(void) @@ -113,17 +113,17 @@ static SDL_SensorID SDL_VITA_SensorGetDeviceInstanceID(int device_index) return -1; } -static int SDL_VITA_SensorOpen(SDL_Sensor *sensor, int device_index) +static bool SDL_VITA_SensorOpen(SDL_Sensor *sensor, int device_index) { struct sensor_hwdata *hwdata; hwdata = (struct sensor_hwdata *)SDL_calloc(1, sizeof(*hwdata)); if (!hwdata) { - return -1; + return false; } sensor->hwdata = hwdata; - return 0; + return true; } static void SDL_VITA_SensorUpdate(SDL_Sensor *sensor) diff --git a/src/sensor/windows/SDL_windowssensor.c b/src/sensor/windows/SDL_windowssensor.c index bab6dc8397..778d9d960d 100644 --- a/src/sensor/windows/SDL_windowssensor.c +++ b/src/sensor/windows/SDL_windowssensor.c @@ -57,8 +57,8 @@ static ISensorManager *SDL_sensor_manager; static int SDL_num_sensors; static SDL_Windows_Sensor *SDL_sensors; -static int ConnectSensor(ISensor *sensor); -static int DisconnectSensor(ISensor *sensor); +static bool ConnectSensor(ISensor *sensor); +static bool DisconnectSensor(ISensor *sensor); static HRESULT STDMETHODCALLTYPE ISensorManagerEventsVtbl_QueryInterface(ISensorManagerEvents *This, REFIID riid, void **ppvObject) { @@ -258,7 +258,7 @@ static ISensorEvents sensor_events = { &sensor_events_vtbl }; -static int ConnectSensor(ISensor *sensor) +static bool ConnectSensor(ISensor *sensor) { SDL_Windows_Sensor *new_sensor, *new_sensors; HRESULT hr; @@ -296,7 +296,7 @@ static int ConnectSensor(ISensor *sensor) SysFreeString(bstr_name); } if (!name) { - return -1; + return false; } SDL_LockSensors(); @@ -304,7 +304,7 @@ static int ConnectSensor(ISensor *sensor) if (!new_sensors) { SDL_UnlockSensors(); SDL_free(name); - return -1; + return false; } ISensor_AddRef(sensor); @@ -322,10 +322,10 @@ static int ConnectSensor(ISensor *sensor) SDL_UnlockSensors(); - return 0; + return true; } -static int DisconnectSensor(ISensor *sensor) +static bool DisconnectSensor(ISensor *sensor) { SDL_Windows_Sensor *old_sensor; int i; @@ -349,10 +349,10 @@ static int DisconnectSensor(ISensor *sensor) } SDL_UnlockSensors(); - return 0; + return true; } -static int SDL_WINDOWS_SensorInit(void) +static bool SDL_WINDOWS_SensorInit(void) { HRESULT hr; ISensorCollection *sensor_collection = NULL; @@ -364,7 +364,7 @@ static int SDL_WINDOWS_SensorInit(void) hr = CoCreateInstance(&SDL_CLSID_SensorManager, NULL, CLSCTX_INPROC_SERVER, &SDL_IID_SensorManager, (LPVOID *)&SDL_sensor_manager); if (FAILED(hr)) { // If we can't create a sensor manager (i.e. on Wine), we won't have any sensors, but don't fail the init - return 0; // WIN_SetErrorFromHRESULT("Couldn't create the sensor manager", hr); + return true; // WIN_SetErrorFromHRESULT("Couldn't create the sensor manager", hr); } hr = ISensorManager_SetEventSink(SDL_sensor_manager, &sensor_manager_events); @@ -397,7 +397,7 @@ static int SDL_WINDOWS_SensorInit(void) } ISensorCollection_Release(sensor_collection); } - return 0; + return true; } static int SDL_WINDOWS_SensorGetCount(void) @@ -429,10 +429,10 @@ static SDL_SensorID SDL_WINDOWS_SensorGetDeviceInstanceID(int device_index) return SDL_sensors[device_index].id; } -static int SDL_WINDOWS_SensorOpen(SDL_Sensor *sensor, int device_index) +static bool SDL_WINDOWS_SensorOpen(SDL_Sensor *sensor, int device_index) { SDL_sensors[device_index].sensor_opened = sensor; - return 0; + return true; } static void SDL_WINDOWS_SensorUpdate(SDL_Sensor *sensor) diff --git a/src/stdlib/SDL_getenv.c b/src/stdlib/SDL_getenv.c index f6ac7ff1df..1fcdb64e8b 100644 --- a/src/stdlib/SDL_getenv.c +++ b/src/stdlib/SDL_getenv.c @@ -245,7 +245,7 @@ const char *SDL_getenv(const char *name) { DWORD length, maxlen = 0; char *string = NULL; - const char *retval = NULL; + const char *result = NULL; // Input validation if (!name || *name == '\0') { @@ -274,10 +274,10 @@ const char *SDL_getenv(const char *name) } } if (string) { - retval = SDL_GetPersistentString(string); + result = SDL_GetPersistentString(string); SDL_free(string); } - return retval; + return result; } #else const char *SDL_getenv(const char *name) diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c index 356050ab0f..4f7667a98c 100644 --- a/src/stdlib/SDL_malloc.c +++ b/src/stdlib/SDL_malloc.c @@ -5257,10 +5257,10 @@ void SDL_GetMemoryFunctions(SDL_malloc_func *malloc_func, } } -int SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, - SDL_calloc_func calloc_func, - SDL_realloc_func realloc_func, - SDL_free_func free_func) +SDL_bool SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, + SDL_calloc_func calloc_func, + SDL_realloc_func realloc_func, + SDL_free_func free_func) { if (!malloc_func) { return SDL_InvalidParamError("malloc_func"); @@ -5279,7 +5279,7 @@ int SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, s_mem.calloc_func = calloc_func; s_mem.realloc_func = realloc_func; s_mem.free_func = free_func; - return 0; + return true; } int SDL_GetNumAllocations(void) diff --git a/src/stdlib/SDL_stdlib.c b/src/stdlib/SDL_stdlib.c index c92bf26752..45e6ba9be1 100644 --- a/src/stdlib/SDL_stdlib.c +++ b/src/stdlib/SDL_stdlib.c @@ -532,7 +532,7 @@ int SDL_isblank(int x) { return ((x) == ' ') || ((x) == '\t'); } void *SDL_aligned_alloc(size_t alignment, size_t size) { size_t padding; - Uint8 *retval = NULL; + Uint8 *result = NULL; if (alignment < sizeof(void*)) { alignment = sizeof(void*); @@ -545,16 +545,16 @@ void *SDL_aligned_alloc(size_t alignment, size_t size) void *original = SDL_malloc(size); if (original) { // Make sure we have enough space to store the original pointer - retval = (Uint8 *)original + sizeof(original); + result = (Uint8 *)original + sizeof(original); // Align the pointer we're going to return - retval += alignment - (((size_t)retval) % alignment); + result += alignment - (((size_t)result) % alignment); // Store the original pointer right before the returned value - SDL_memcpy(retval - sizeof(original), &original, sizeof(original)); + SDL_memcpy(result - sizeof(original), &original, sizeof(original)); } } - return retval; + return result; } void SDL_aligned_free(void *mem) diff --git a/src/stdlib/SDL_string.c b/src/stdlib/SDL_string.c index 2bf291face..0b7dad4460 100644 --- a/src/stdlib/SDL_string.c +++ b/src/stdlib/SDL_string.c @@ -213,10 +213,10 @@ static Uint32 StepUTF8(const char **_str, const size_t slen) } else if (((octet & 0xE0) == 0xC0) && (slen >= 2)) { // 110xxxxx 10xxxxxx: two byte codepoint. const Uint8 str1 = str[1]; if ((str1 & 0xC0) == 0x80) { // If trailing bytes aren't 10xxxxxx, sequence is bogus. - const Uint32 retval = ((octet & 0x1F) << 6) | (str1 & 0x3F); - if (retval >= 0x0080) { // rfc3629 says you can't use overlong sequences for smaller values. + const Uint32 result = ((octet & 0x1F) << 6) | (str1 & 0x3F); + if (result >= 0x0080) { // rfc3629 says you can't use overlong sequences for smaller values. *_str += 2; - return retval; + return result; } } } else if (((octet & 0xF0) == 0xE0) && (slen >= 3)) { // 1110xxxx 10xxxxxx 10xxxxxx: three byte codepoint. @@ -225,11 +225,11 @@ static Uint32 StepUTF8(const char **_str, const size_t slen) if (((str1 & 0xC0) == 0x80) && ((str2 & 0xC0) == 0x80)) { // If trailing bytes aren't 10xxxxxx, sequence is bogus. const Uint32 octet2 = ((Uint32) (str1 & 0x3F)) << 6; const Uint32 octet3 = ((Uint32) (str2 & 0x3F)); - const Uint32 retval = ((octet & 0x0F) << 12) | octet2 | octet3; - if (retval >= 0x800) { // rfc3629 says you can't use overlong sequences for smaller values. - if ((retval < 0xD800) || (retval > 0xDFFF)) { // UTF-16 surrogate values are illegal in UTF-8. + const Uint32 result = ((octet & 0x0F) << 12) | octet2 | octet3; + if (result >= 0x800) { // rfc3629 says you can't use overlong sequences for smaller values. + if ((result < 0xD800) || (result > 0xDFFF)) { // UTF-16 surrogate values are illegal in UTF-8. *_str += 3; - return retval; + return result; } } } @@ -241,10 +241,10 @@ static Uint32 StepUTF8(const char **_str, const size_t slen) const Uint32 octet2 = ((Uint32) (str1 & 0x1F)) << 12; const Uint32 octet3 = ((Uint32) (str2 & 0x3F)) << 6; const Uint32 octet4 = ((Uint32) (str3 & 0x3F)); - const Uint32 retval = ((octet & 0x07) << 18) | octet2 | octet3 | octet4; - if (retval >= 0x10000) { // rfc3629 says you can't use overlong sequences for smaller values. + const Uint32 result = ((octet & 0x07) << 18) | octet2 | octet3 | octet4; + if (result >= 0x10000) { // rfc3629 says you can't use overlong sequences for smaller values. *_str += 4; - return retval; + return result; } } } @@ -260,9 +260,9 @@ Uint32 SDL_StepUTF8(const char **pstr, size_t *pslen) return StepUTF8(pstr, 4); // 4 == max codepoint size. } const char *origstr = *pstr; - const Uint32 retval = StepUTF8(pstr, *pslen); + const Uint32 result = StepUTF8(pstr, *pslen); *pslen -= (size_t) (*pstr - origstr); - return retval; + return result; } #if (SDL_SIZEOF_WCHAR_T == 2) @@ -891,20 +891,20 @@ size_t SDL_utf8strlcpy(SDL_OUT_Z_CAP(dst_bytes) char *dst, const char *src, size size_t SDL_utf8strlen(const char *str) { - size_t retval = 0; + size_t result = 0; while (SDL_StepUTF8(&str, NULL)) { - retval++; + result++; } - return retval; + return result; } size_t SDL_utf8strnlen(const char *str, size_t bytes) { - size_t retval = 0; + size_t result = 0; while (SDL_StepUTF8(&str, &bytes)) { - retval++; + result++; } - return retval; + return result; } size_t SDL_strlcat(SDL_INOUT_Z_CAP(maxlen) char *dst, const char *src, size_t maxlen) @@ -1405,7 +1405,7 @@ static bool CharacterMatchesSet(char c, const char *set, size_t set_len) // NOLINTNEXTLINE(readability-non-const-parameter) int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_list ap) { - int retval = 0; + int result = 0; if (!text || !*text) { return -1; @@ -1462,7 +1462,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li while (count--) { *valuep++ = *text++; } - ++retval; + ++result; } continue; } @@ -1521,7 +1521,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li if (advance && !suppress) { Sint64 *valuep = va_arg(ap, Sint64 *); *valuep = value; - ++retval; + ++result; } } else if (inttype == DO_SIZE_T) { Sint64 value = 0; @@ -1530,7 +1530,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li if (advance && !suppress) { size_t *valuep = va_arg(ap, size_t *); *valuep = (size_t)value; - ++retval; + ++result; } } else { long value = 0; @@ -1558,7 +1558,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li // Handled above break; } - ++retval; + ++result; } } done = true; @@ -1582,7 +1582,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li if (advance && !suppress) { Uint64 *valuep = va_arg(ap, Uint64 *); *valuep = value; - ++retval; + ++result; } } else if (inttype == DO_SIZE_T) { Uint64 value = 0; @@ -1591,7 +1591,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li if (advance && !suppress) { size_t *valuep = va_arg(ap, size_t *); *valuep = (size_t)value; - ++retval; + ++result; } } else { unsigned long value = 0; @@ -1619,7 +1619,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li // Handled above break; } - ++retval; + ++result; } } done = true; @@ -1632,7 +1632,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li if (advance && !suppress) { void **valuep = va_arg(ap, void **); *valuep = (void *)value; - ++retval; + ++result; } } done = true; @@ -1645,7 +1645,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li if (advance && !suppress) { float *valuep = va_arg(ap, float *); *valuep = (float)value; - ++retval; + ++result; } } done = true; @@ -1671,7 +1671,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li } } *valuep = '\0'; - ++retval; + ++result; } done = true; break; @@ -1706,7 +1706,7 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li } *valuep = '\0'; if (had_match) { - ++retval; + ++result; } } } @@ -1730,50 +1730,50 @@ int SDL_vsscanf(const char *text, SDL_SCANF_FORMAT_STRING const char *fmt, va_li break; } - return retval; + return result; } #endif // HAVE_VSSCANF int SDL_snprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { va_list ap; - int retval; + int result; va_start(ap, fmt); - retval = SDL_vsnprintf(text, maxlen, fmt, ap); + result = SDL_vsnprintf(text, maxlen, fmt, ap); va_end(ap); - return retval; + return result; } int SDL_swprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, SDL_PRINTF_FORMAT_STRING const wchar_t *fmt, ...) { va_list ap; - int retval; + int result; va_start(ap, fmt); - retval = SDL_vswprintf(text, maxlen, fmt, ap); + result = SDL_vswprintf(text, maxlen, fmt, ap); va_end(ap); - return retval; + return result; } #if defined(HAVE_LIBC) && defined(__WATCOMC__) // _vsnprintf() doesn't ensure nul termination int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap) { - int retval; + int result; if (!fmt) { fmt = ""; } - retval = _vsnprintf(text, maxlen, fmt, ap); + result = _vsnprintf(text, maxlen, fmt, ap); if (maxlen > 0) { text[maxlen - 1] = '\0'; } - if (retval < 0) { - retval = (int)maxlen; + if (result < 0) { + result = (int)maxlen; } - return retval; + return result; } #elif defined(HAVE_VSNPRINTF) int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, const char *fmt, va_list ap) @@ -2305,7 +2305,7 @@ int SDL_vsnprintf(SDL_OUT_Z_CAP(maxlen) char *text, size_t maxlen, SDL_PRINTF_FO int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wchar_t *fmt, va_list ap) { char *text_utf8 = NULL, *fmt_utf8 = NULL; - int retval; + int result; if (fmt) { fmt_utf8 = SDL_iconv_string("UTF-8", "WCHAR_T", (const char *)fmt, (SDL_wcslen(fmt) + 1) * sizeof(wchar_t)); @@ -2324,42 +2324,42 @@ int SDL_vswprintf(SDL_OUT_Z_CAP(maxlen) wchar_t *text, size_t maxlen, const wcha return -1; } - retval = SDL_vsnprintf(text_utf8, maxlen * 4, fmt_utf8, ap); + result = SDL_vsnprintf(text_utf8, maxlen * 4, fmt_utf8, ap); - if (retval >= 0) { + if (result >= 0) { wchar_t *text_wchar = (wchar_t *)SDL_iconv_string("WCHAR_T", "UTF-8", text_utf8, SDL_strlen(text_utf8) + 1); if (text_wchar) { if (text) { SDL_wcslcpy(text, text_wchar, maxlen); } - retval = (int)SDL_wcslen(text_wchar); + result = (int)SDL_wcslen(text_wchar); SDL_free(text_wchar); } else { - retval = -1; + result = -1; } } SDL_free(text_utf8); SDL_free(fmt_utf8); - return retval; + return result; } int SDL_asprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, ...) { va_list ap; - int retval; + int result; va_start(ap, fmt); - retval = SDL_vasprintf(strp, fmt, ap); + result = SDL_vasprintf(strp, fmt, ap); va_end(ap); - return retval; + return result; } int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) { - int retval; + int result; int size = 100; // Guess we need no more than 100 bytes char *p, *np; va_list aq; @@ -2374,23 +2374,23 @@ int SDL_vasprintf(char **strp, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list while (1) { // Try to print in the allocated space va_copy(aq, ap); - retval = SDL_vsnprintf(p, size, fmt, aq); + result = SDL_vsnprintf(p, size, fmt, aq); va_end(aq); // Check error code - if (retval < 0) { + if (result < 0) { SDL_free(p); - return retval; + return result; } // If that worked, return the string - if (retval < size) { + if (result < size) { *strp = p; - return retval; + return result; } // Else try again with more space - size = retval + 1; // Precisely what is needed + size = result + 1; // Precisely what is needed np = (char *)SDL_realloc(p, size); if (!np) { diff --git a/src/storage/SDL_storage.c b/src/storage/SDL_storage.c index efb4b02fd1..5f8fb336c2 100644 --- a/src/storage/SDL_storage.c +++ b/src/storage/SDL_storage.c @@ -50,10 +50,10 @@ struct SDL_Storage return SDL_SetError("Invalid storage container"); \ } -#define CHECK_STORAGE_MAGIC_RET(retval) \ +#define CHECK_STORAGE_MAGIC_RET(result) \ if (!storage) { \ SDL_SetError("Invalid storage container"); \ - return retval; \ + return result; \ } SDL_Storage *SDL_OpenTitleStorage(const char *override, SDL_PropertiesID props) @@ -162,17 +162,17 @@ SDL_Storage *SDL_OpenStorage(const SDL_StorageInterface *iface, void *userdata) return storage; } -int SDL_CloseStorage(SDL_Storage *storage) +SDL_bool SDL_CloseStorage(SDL_Storage *storage) { - int retval = 0; + bool result = true; CHECK_STORAGE_MAGIC() if (storage->iface.close) { - retval = storage->iface.close(storage->userdata); + result = storage->iface.close(storage->userdata); } SDL_free(storage); - return retval; + return result; } SDL_bool SDL_StorageReady(SDL_Storage *storage) @@ -185,20 +185,24 @@ SDL_bool SDL_StorageReady(SDL_Storage *storage) return true; } -int SDL_GetStorageFileSize(SDL_Storage *storage, const char *path, Uint64 *length) +SDL_bool SDL_GetStorageFileSize(SDL_Storage *storage, const char *path, Uint64 *length) { SDL_PathInfo info; - if (SDL_GetStoragePathInfo(storage, path, &info) < 0) { - return -1; + if (SDL_GetStoragePathInfo(storage, path, &info)) { + if (length) { + *length = info.size; + } + return true; + } else { + if (length) { + *length = 0; + } + return false; } - if (length) { - *length = info.size; - } - return 0; } -int SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length) +SDL_bool SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destination, Uint64 length) { CHECK_STORAGE_MAGIC() @@ -213,7 +217,7 @@ int SDL_ReadStorageFile(SDL_Storage *storage, const char *path, void *destinatio return storage->iface.read_file(storage->userdata, path, destination, length); } -int SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *source, Uint64 length) +SDL_bool SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *source, Uint64 length) { CHECK_STORAGE_MAGIC() @@ -228,7 +232,7 @@ int SDL_WriteStorageFile(SDL_Storage *storage, const char *path, const void *sou return storage->iface.write_file(storage->userdata, path, source, length); } -int SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path) +SDL_bool SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path) { CHECK_STORAGE_MAGIC() @@ -243,7 +247,7 @@ int SDL_CreateStorageDirectory(SDL_Storage *storage, const char *path) return storage->iface.mkdir(storage->userdata, path); } -int SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata) +SDL_bool SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_EnumerateDirectoryCallback callback, void *userdata) { CHECK_STORAGE_MAGIC() @@ -258,7 +262,7 @@ int SDL_EnumerateStorageDirectory(SDL_Storage *storage, const char *path, SDL_En return storage->iface.enumerate(storage->userdata, path, callback, userdata); } -int SDL_RemoveStoragePath(SDL_Storage *storage, const char *path) +SDL_bool SDL_RemoveStoragePath(SDL_Storage *storage, const char *path) { CHECK_STORAGE_MAGIC() @@ -273,7 +277,7 @@ int SDL_RemoveStoragePath(SDL_Storage *storage, const char *path) return storage->iface.remove(storage->userdata, path); } -int SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char *newpath) +SDL_bool SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char *newpath) { CHECK_STORAGE_MAGIC() @@ -291,7 +295,7 @@ int SDL_RenameStoragePath(SDL_Storage *storage, const char *oldpath, const char return storage->iface.rename(storage->userdata, oldpath, newpath); } -int SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *newpath) +SDL_bool SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *newpath) { CHECK_STORAGE_MAGIC() @@ -309,7 +313,7 @@ int SDL_CopyStorageFile(SDL_Storage *storage, const char *oldpath, const char *n return storage->iface.copy(storage->userdata, oldpath, newpath); } -int SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info) +SDL_bool SDL_GetStoragePathInfo(SDL_Storage *storage, const char *path, SDL_PathInfo *info) { SDL_PathInfo dummy; @@ -343,12 +347,12 @@ Uint64 SDL_GetStorageSpaceRemaining(SDL_Storage *storage) return storage->iface.space_remaining(storage->userdata); } -static int GlobStorageDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata) +static SDL_bool GlobStorageDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata) { return SDL_GetStoragePathInfo((SDL_Storage *) userdata, path, info); } -static int GlobStorageDirectoryEnumerator(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata) +static SDL_bool GlobStorageDirectoryEnumerator(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata) { return SDL_EnumerateStorageDirectory((SDL_Storage *) userdata, path, cb, cbuserdata); } diff --git a/src/storage/generic/SDL_genericstorage.c b/src/storage/generic/SDL_genericstorage.c index e15efce658..430b93df2f 100644 --- a/src/storage/generic/SDL_genericstorage.c +++ b/src/storage/generic/SDL_genericstorage.c @@ -38,15 +38,15 @@ static char *GENERIC_INTERNAL_CreateFullPath(const char *base, const char *relat return result; } -static int GENERIC_CloseStorage(void *userdata) +static SDL_bool GENERIC_CloseStorage(void *userdata) { SDL_free(userdata); - return 0; + return true; } -static int GENERIC_EnumerateStorageDirectory(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata) +static SDL_bool GENERIC_EnumerateStorageDirectory(void *userdata, const char *path, SDL_EnumerateDirectoryCallback callback, void *callback_userdata) { - int result = -1; + bool result = false; char *fullpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, path); if (fullpath) { @@ -57,9 +57,9 @@ static int GENERIC_EnumerateStorageDirectory(void *userdata, const char *path, S return result; } -static int GENERIC_GetStoragePathInfo(void *userdata, const char *path, SDL_PathInfo *info) +static SDL_bool GENERIC_GetStoragePathInfo(void *userdata, const char *path, SDL_PathInfo *info) { - int result = -1; + bool result = false; char *fullpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, path); if (fullpath) { @@ -70,9 +70,9 @@ static int GENERIC_GetStoragePathInfo(void *userdata, const char *path, SDL_Path return result; } -static int GENERIC_ReadStorageFile(void *userdata, const char *path, void *destination, Uint64 length) +static SDL_bool GENERIC_ReadStorageFile(void *userdata, const char *path, void *destination, Uint64 length) { - int result = -1; + bool result = false; if (length > SDL_SIZE_MAX) { return SDL_SetError("Read size exceeds SDL_SIZE_MAX"); @@ -84,7 +84,7 @@ static int GENERIC_ReadStorageFile(void *userdata, const char *path, void *desti if (stream) { // FIXME: Should SDL_ReadIO use u64 now...? if (SDL_ReadIO(stream, destination, (size_t)length) == length) { - result = 0; + result = true; } SDL_CloseIO(stream); } @@ -93,10 +93,10 @@ static int GENERIC_ReadStorageFile(void *userdata, const char *path, void *desti return result; } -static int GENERIC_WriteStorageFile(void *userdata, const char *path, const void *source, Uint64 length) +static SDL_bool GENERIC_WriteStorageFile(void *userdata, const char *path, const void *source, Uint64 length) { // TODO: Recursively create subdirectories with SDL_CreateDirectory - int result = -1; + bool result = false; if (length > SDL_SIZE_MAX) { return SDL_SetError("Write size exceeds SDL_SIZE_MAX"); @@ -109,7 +109,7 @@ static int GENERIC_WriteStorageFile(void *userdata, const char *path, const void if (stream) { // FIXME: Should SDL_WriteIO use u64 now...? if (SDL_WriteIO(stream, source, (size_t)length) == length) { - result = 0; + result = true; } SDL_CloseIO(stream); } @@ -118,10 +118,10 @@ static int GENERIC_WriteStorageFile(void *userdata, const char *path, const void return result; } -static int GENERIC_CreateStorageDirectory(void *userdata, const char *path) +static SDL_bool GENERIC_CreateStorageDirectory(void *userdata, const char *path) { // TODO: Recursively create subdirectories with SDL_CreateDirectory - int result = -1; + bool result = false; char *fullpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, path); if (fullpath) { @@ -132,9 +132,9 @@ static int GENERIC_CreateStorageDirectory(void *userdata, const char *path) return result; } -static int GENERIC_RemoveStoragePath(void *userdata, const char *path) +static SDL_bool GENERIC_RemoveStoragePath(void *userdata, const char *path) { - int result = -1; + bool result = false; char *fullpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, path); if (fullpath) { @@ -145,9 +145,9 @@ static int GENERIC_RemoveStoragePath(void *userdata, const char *path) return result; } -static int GENERIC_RenameStoragePath(void *userdata, const char *oldpath, const char *newpath) +static SDL_bool GENERIC_RenameStoragePath(void *userdata, const char *oldpath, const char *newpath) { - int result = -1; + bool result = false; char *fulloldpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, oldpath); char *fullnewpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, newpath); @@ -160,9 +160,9 @@ static int GENERIC_RenameStoragePath(void *userdata, const char *oldpath, const return result; } -static int GENERIC_CopyStorageFile(void *userdata, const char *oldpath, const char *newpath) +static SDL_bool GENERIC_CopyStorageFile(void *userdata, const char *oldpath, const char *newpath) { - int result = -1; + bool result = false; char *fulloldpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, oldpath); char *fullnewpath = GENERIC_INTERNAL_CreateFullPath((char *)userdata, newpath); diff --git a/src/storage/steam/SDL_steamstorage.c b/src/storage/steam/SDL_steamstorage.c index 71377618f9..cd5b1307b0 100644 --- a/src/storage/steam/SDL_steamstorage.c +++ b/src/storage/steam/SDL_steamstorage.c @@ -40,9 +40,9 @@ typedef struct STEAM_RemoteStorage #include "SDL_steamstorage_proc.h" } STEAM_RemoteStorage; -static int STEAM_CloseStorage(void *userdata) +static SDL_bool STEAM_CloseStorage(void *userdata) { - int result = 0; + bool result = true; STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata; void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016(); if (steamremotestorage == NULL) { @@ -60,7 +60,7 @@ static SDL_bool STEAM_StorageReady(void *userdata) return true; } -static int STEAM_GetStoragePathInfo(void *userdata, const char *path, SDL_PathInfo *info) +static SDL_bool STEAM_GetStoragePathInfo(void *userdata, const char *path, SDL_PathInfo *info) { STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata; void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016(); @@ -73,12 +73,12 @@ static int STEAM_GetStoragePathInfo(void *userdata, const char *path, SDL_PathIn info->type = SDL_PATHTYPE_FILE; info->size = steam->SteamAPI_ISteamRemoteStorage_GetFileSize(steamremotestorage, path); } - return 0; + return true; } -static int STEAM_ReadStorageFile(void *userdata, const char *path, void *destination, Uint64 length) +static SDL_bool STEAM_ReadStorageFile(void *userdata, const char *path, void *destination, Uint64 length) { - int result = -1; + bool result = false; STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata; void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016(); if (steamremotestorage == NULL) { @@ -88,16 +88,16 @@ static int STEAM_ReadStorageFile(void *userdata, const char *path, void *destina return SDL_SetError("SteamRemoteStorage only supports INT32_MAX read size"); } if (steam->SteamAPI_ISteamRemoteStorage_FileRead(steamremotestorage, path, destination, (Sint32) length) == length) { - result = 0; + result = true; } else { SDL_SetError("SteamAPI_ISteamRemoteStorage_FileRead() failed"); } return result; } -static int STEAM_WriteStorageFile(void *userdata, const char *path, const void *source, Uint64 length) +static SDL_bool STEAM_WriteStorageFile(void *userdata, const char *path, const void *source, Uint64 length) { - int result = -1; + int result = false; STEAM_RemoteStorage *steam = (STEAM_RemoteStorage*) userdata; void *steamremotestorage = steam->SteamAPI_SteamRemoteStorage_v016(); if (steamremotestorage == NULL) { @@ -107,7 +107,7 @@ static int STEAM_WriteStorageFile(void *userdata, const char *path, const void * return SDL_SetError("SteamRemoteStorage only supports INT32_MAX write size"); } if (steam->SteamAPI_ISteamRemoteStorage_FileWrite(steamremotestorage, path, source, (Sint32) length) == length) { - result = 0; + result = true; } else { SDL_SetError("SteamAPI_ISteamRemoteStorage_FileRead() failed"); } diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index ae282c2143..4805fd9a91 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1164,7 +1164,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) SDL_Log("%s\n", text); } } - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) { SDL_Log("Couldn't initialize video driver: %s\n", SDL_GetError()); return SDL_FALSE; @@ -1431,7 +1431,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) if (state->render_vsync) { SDL_SetRenderVSync(state->renderers[i], state->render_vsync); } - if (SDL_SetRenderLogicalPresentation(state->renderers[i], state->logical_w, state->logical_h, state->logical_presentation, state->logical_scale_mode) < 0) { + if (!SDL_SetRenderLogicalPresentation(state->renderers[i], state->logical_w, state->logical_h, state->logical_presentation, state->logical_scale_mode)) { SDL_Log("Couldn't set logical presentation: %s\n", SDL_GetError()); return SDL_FALSE; } @@ -1467,7 +1467,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) SDL_Log("%s\n", text); } } - if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { + if (!SDL_InitSubSystem(SDL_INIT_AUDIO)) { SDL_Log("Couldn't initialize audio driver: %s\n", SDL_GetError()); return SDL_FALSE; @@ -1996,7 +1996,7 @@ static void SDLTest_CopyScreenShot(SDL_Renderer *renderer) return; } - if (SDL_SaveBMP(surface, SCREENSHOT_FILE) < 0) { + if (!SDL_SaveBMP(surface, SCREENSHOT_FILE)) { SDL_Log("Couldn't save %s: %s\n", SCREENSHOT_FILE, SDL_GetError()); SDL_DestroySurface(surface); return; @@ -2070,13 +2070,13 @@ static void FullscreenTo(SDLTest_CommonState *state, int index, int windowId) SDL_memcpy(&new_mode, mode, sizeof(new_mode)); new_mode.displayID = displays[index]; - if (SDL_SetWindowFullscreenMode(window, &new_mode) < 0) { + if (!SDL_SetWindowFullscreenMode(window, &new_mode)) { /* Try again with a default mode */ SDL_bool include_high_density_modes = SDL_FALSE; if (state->window_flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) { include_high_density_modes = SDL_TRUE; } - if (SDL_GetClosestFullscreenDisplayMode(displays[index], state->window_w, state->window_h, state->refresh_rate, include_high_density_modes, &new_mode) == 0) { + if (SDL_GetClosestFullscreenDisplayMode(displays[index], state->window_w, state->window_h, state->refresh_rate, include_high_density_modes, &new_mode)) { SDL_SetWindowFullscreenMode(window, &new_mode); } } @@ -2356,8 +2356,8 @@ SDL_AppResult SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Window *window = SDL_GetWindowFromEvent(event); if (window) { const SDL_bool shouldCapture = !(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_CAPTURE); - const int rc = SDL_CaptureMouse(shouldCapture); - SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", (rc == 0) ? "succeeded" : "failed"); + const SDL_bool rc = SDL_CaptureMouse(shouldCapture); + SDL_Log("%sapturing mouse %s!\n", shouldCapture ? "C" : "Unc", rc ? "succeeded" : "failed"); } } break; @@ -2570,13 +2570,13 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; - if (0 == SDL_GetRenderOutputSize(renderer, &w, &h)) { + if (SDL_GetRenderOutputSize(renderer, &w, &h)) { (void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderOutputSize: %dx%d", w, h); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; } - if (0 == SDL_GetCurrentRenderOutputSize(renderer, &w, &h)) { + if (SDL_GetCurrentRenderOutputSize(renderer, &w, &h)) { (void)SDL_snprintf(text, sizeof(text), "SDL_GetCurrentRenderOutputSize: %dx%d", w, h); SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; @@ -2654,7 +2654,7 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl SDLTest_DrawString(renderer, 0.0f, textY, text); textY += lineHeight; - if (0 == SDL_GetDisplayBounds(windowDisplayID, &rect)) { + if (SDL_GetDisplayBounds(windowDisplayID, &rect)) { (void)SDL_snprintf(text, sizeof(text), "SDL_GetDisplayBounds: %d,%d, %dx%d", rect.x, rect.y, rect.w, rect.h); SDLTest_DrawString(renderer, 0.0f, textY, text); diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c index 7da64666b3..f4a29912ba 100644 --- a/src/test/SDL_test_compare.c +++ b/src/test/SDL_test_compare.c @@ -79,14 +79,14 @@ int SDLTest_CompareSurfaces(SDL_Surface *surface, SDL_Surface *referenceSurface, int temp; temp = SDL_ReadSurfacePixel(surface, i, j, &R, &G, &B, &A); - if (temp != 0) { + if (!temp) { SDLTest_LogError("Failed to retrieve pixel (%d,%d): %s", i, j, SDL_GetError()); ret++; continue; } temp = SDL_ReadSurfacePixel(referenceSurface, i, j, &Rd, &Gd, &Bd, &Ad); - if (temp != 0) { + if (!temp) { SDLTest_LogError("Failed to retrieve reference pixel (%d,%d): %s", i, j, SDL_GetError()); ret++; continue; diff --git a/src/test/SDL_test_font.c b/src/test/SDL_test_font.c index 3c246d3a5b..92594423cb 100644 --- a/src/test/SDL_test_font.c +++ b/src/test/SDL_test_font.c @@ -3142,13 +3142,13 @@ static struct SDLTest_CharTextureCache *SDLTest_CharTextureCacheList; int FONT_CHARACTER_SIZE = 8; -int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c) +SDL_bool SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c) { const Uint32 charWidth = FONT_CHARACTER_SIZE; const Uint32 charHeight = FONT_CHARACTER_SIZE; SDL_FRect srect; SDL_FRect drect; - int result; + SDL_bool result; Uint32 ix, iy; const unsigned char *charpos; Uint32 *curpos; @@ -3246,15 +3246,15 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, float x, float y, Uint32 c) /* * Set color */ - result = 0; - result |= SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a); - result |= SDL_SetTextureColorMod(cache->charTextureCache[ci], r, g, b); - result |= SDL_SetTextureAlphaMod(cache->charTextureCache[ci], a); + result = SDL_TRUE; + result &= SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a); + result &= SDL_SetTextureColorMod(cache->charTextureCache[ci], r, g, b); + result &= SDL_SetTextureAlphaMod(cache->charTextureCache[ci], a); /* * Draw texture onto destination */ - result |= SDL_RenderTexture(renderer, cache->charTextureCache[ci], &srect, &drect); + result &= SDL_RenderTexture(renderer, cache->charTextureCache[ci], &srect, &drect); return result; } @@ -3348,10 +3348,10 @@ static Uint32 UTF8_getch(const char *src, size_t srclen, int *inc) #define UTF8_IsTrailingByte(c) ((c) >= 0x80 && (c) <= 0xBF) -int SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s) +SDL_bool SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s) { const Uint32 charWidth = FONT_CHARACTER_SIZE; - int result = 0; + SDL_bool result = SDL_TRUE; float curx = x; float cury = y; size_t len = SDL_strlen(s); @@ -3359,7 +3359,7 @@ int SDLTest_DrawString(SDL_Renderer *renderer, float x, float y, const char *s) while (len > 0 && !result) { int advance = 0; Uint32 ch = UTF8_getch(s, len, &advance); - result |= SDLTest_DrawCharacter(renderer, curx, cury, ch); + result &= SDLTest_DrawCharacter(renderer, curx, cury, ch); curx += charWidth; s += advance; len -= advance; diff --git a/src/test/SDL_test_harness.c b/src/test/SDL_test_harness.c index 518253a170..1347bbf547 100644 --- a/src/test/SDL_test_harness.c +++ b/src/test/SDL_test_harness.c @@ -191,8 +191,8 @@ static SDL_TimerID SDLTest_SetTestTimeout(int timeout, void(SDLCALL *callback)(v } /* Init SDL timer if not initialized before */ - if (SDL_WasInit(SDL_INIT_TIMER) == 0) { - if (SDL_InitSubSystem(SDL_INIT_TIMER)) { + if (!SDL_WasInit(SDL_INIT_TIMER)) { + if (!SDL_InitSubSystem(SDL_INIT_TIMER)) { SDLTest_LogError("Failed to init timer subsystem: %s", SDL_GetError()); return 0; } diff --git a/src/thread/SDL_systhread.h b/src/thread/SDL_systhread.h index a12a9754ff..c62176179f 100644 --- a/src/thread/SDL_systhread.h +++ b/src/thread/SDL_systhread.h @@ -36,15 +36,15 @@ extern "C" { saves a system-dependent thread id in thread->id, and returns 0 on success. */ -extern int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread); +extern bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread); // This function does any necessary setup in the child thread extern void SDL_SYS_SetupThread(const char *name); // This function sets the current thread priority -extern int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority); +extern bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority); /* This function waits for the thread to finish and frees any data allocated by SDL_SYS_CreateThread() @@ -61,7 +61,7 @@ extern void SDL_SYS_InitTLSData(void); extern SDL_TLSData *SDL_SYS_GetTLSData(void); // Set the thread local storage for this thread -extern int SDL_SYS_SetTLSData(SDL_TLSData *data); +extern bool SDL_SYS_SetTLSData(SDL_TLSData *data); // Quit the global TLS data extern void SDL_SYS_QuitTLSData(void); diff --git a/src/thread/SDL_thread.c b/src/thread/SDL_thread.c index 21b1db6d28..e673dddb44 100644 --- a/src/thread/SDL_thread.c +++ b/src/thread/SDL_thread.c @@ -54,7 +54,7 @@ void *SDL_GetTLS(SDL_TLSID *id) return storage->array[storage_index].data; } -int SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destructor) +SDL_bool SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destructor) { SDL_TLSData *storage; int storage_index; @@ -92,7 +92,7 @@ int SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destr newlimit = (storage_index + TLS_ALLOC_CHUNKSIZE); new_storage = (SDL_TLSData *)SDL_realloc(storage, sizeof(*storage) + (newlimit - 1) * sizeof(storage->array[0])); if (!new_storage) { - return -1; + return false; } storage = new_storage; storage->limit = newlimit; @@ -100,16 +100,16 @@ int SDL_SetTLS(SDL_TLSID *id, const void *value, SDL_TLSDestructorCallback destr storage->array[i].data = NULL; storage->array[i].destructor = NULL; } - if (SDL_SYS_SetTLSData(storage) != 0) { + if (!SDL_SYS_SetTLSData(storage)) { SDL_free(storage); - return -1; + return false; } SDL_AtomicIncRef(&SDL_tls_allocated); } storage->array[storage_index].data = SDL_const_cast(void *, value); storage->array[storage_index].destructor = destructor; - return 0; + return true; } void SDL_CleanupTLS(void) @@ -185,11 +185,11 @@ SDL_TLSData *SDL_Generic_GetTLSData(void) return storage; } -int SDL_Generic_SetTLSData(SDL_TLSData *data) +bool SDL_Generic_SetTLSData(SDL_TLSData *data) { SDL_ThreadID thread = SDL_GetCurrentThreadID(); SDL_TLSEntry *prev, *entry; - int retval = 0; + bool result = true; SDL_LockMutex(SDL_generic_TLS_mutex); prev = NULL; @@ -217,12 +217,12 @@ int SDL_Generic_SetTLSData(SDL_TLSData *data) entry->next = SDL_generic_TLS; SDL_generic_TLS = entry; } else { - retval = -1; + result = false; } } SDL_UnlockMutex(SDL_generic_TLS_mutex); - return retval; + return result; } void SDL_Generic_QuitTLSData(void) @@ -380,7 +380,7 @@ SDL_Thread *SDL_CreateThreadWithPropertiesRuntime(SDL_PropertiesID props, thread->stacksize = stacksize; // Create the thread and go! - if (SDL_SYS_CreateThread(thread, pfnBeginThread, pfnEndThread) < 0) { + if (!SDL_SYS_CreateThread(thread, pfnBeginThread, pfnEndThread)) { // Oops, failed. Gotta free everything SDL_free(thread->name); SDL_free(thread); @@ -439,7 +439,7 @@ const char *SDL_GetThreadName(SDL_Thread *thread) } } -int SDL_SetThreadPriority(SDL_ThreadPriority priority) +SDL_bool SDL_SetThreadPriority(SDL_ThreadPriority priority) { return SDL_SYS_SetThreadPriority(priority); } @@ -478,17 +478,17 @@ void SDL_DetachThread(SDL_Thread *thread) } } -int SDL_WaitSemaphore(SDL_Semaphore *sem) +void SDL_WaitSemaphore(SDL_Semaphore *sem) { - return SDL_WaitSemaphoreTimeoutNS(sem, -1); + SDL_WaitSemaphoreTimeoutNS(sem, -1); } -int SDL_TryWaitSemaphore(SDL_Semaphore *sem) +SDL_bool SDL_TryWaitSemaphore(SDL_Semaphore *sem) { return SDL_WaitSemaphoreTimeoutNS(sem, 0); } -int SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sint32 timeoutMS) +SDL_bool SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sint32 timeoutMS) { Sint64 timeoutNS; @@ -500,12 +500,12 @@ int SDL_WaitSemaphoreTimeout(SDL_Semaphore *sem, Sint32 timeoutMS) return SDL_WaitSemaphoreTimeoutNS(sem, timeoutNS); } -int SDL_WaitCondition(SDL_Condition *cond, SDL_Mutex *mutex) +void SDL_WaitCondition(SDL_Condition *cond, SDL_Mutex *mutex) { - return SDL_WaitConditionTimeoutNS(cond, mutex, -1); + SDL_WaitConditionTimeoutNS(cond, mutex, -1); } -int SDL_WaitConditionTimeout(SDL_Condition *cond, SDL_Mutex *mutex, Sint32 timeoutMS) +SDL_bool SDL_WaitConditionTimeout(SDL_Condition *cond, SDL_Mutex *mutex, Sint32 timeoutMS) { Sint64 timeoutNS; @@ -516,3 +516,4 @@ int SDL_WaitConditionTimeout(SDL_Condition *cond, SDL_Mutex *mutex, Sint32 timeo } return SDL_WaitConditionTimeoutNS(cond, mutex, timeoutNS); } + diff --git a/src/thread/SDL_thread_c.h b/src/thread/SDL_thread_c.h index 8c18b94a7f..9d96012ff8 100644 --- a/src/thread/SDL_thread_c.h +++ b/src/thread/SDL_thread_c.h @@ -98,7 +98,7 @@ extern void SDL_QuitTLSData(void); */ extern void SDL_Generic_InitTLSData(void); extern SDL_TLSData *SDL_Generic_GetTLSData(void); -extern int SDL_Generic_SetTLSData(SDL_TLSData *data); +extern bool SDL_Generic_SetTLSData(SDL_TLSData *data); extern void SDL_Generic_QuitTLSData(void); #endif // SDL_thread_c_h_ diff --git a/src/thread/generic/SDL_syscond.c b/src/thread/generic/SDL_syscond.c index a83f28235a..7af2f810b5 100644 --- a/src/thread/generic/SDL_syscond.c +++ b/src/thread/generic/SDL_syscond.c @@ -37,7 +37,6 @@ #define SDL_DestroyCondition_generic SDL_DestroyCondition #define SDL_SignalCondition_generic SDL_SignalCondition #define SDL_BroadcastCondition_generic SDL_BroadcastCondition -#define SDL_WaitConditionTimeoutNS_generic SDL_WaitConditionTimeoutNS #endif typedef struct SDL_cond_generic @@ -89,11 +88,11 @@ void SDL_DestroyCondition_generic(SDL_Condition *_cond) } // Restart one of the threads that are waiting on the condition variable -int SDL_SignalCondition_generic(SDL_Condition *_cond) +void SDL_SignalCondition_generic(SDL_Condition *_cond) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; if (!cond) { - return SDL_InvalidParamError("cond"); + return; } #ifndef SDL_THREADS_DISABLED @@ -110,16 +109,14 @@ int SDL_SignalCondition_generic(SDL_Condition *_cond) SDL_UnlockMutex(cond->lock); } #endif - - return 0; } // Restart all threads that are waiting on the condition variable -int SDL_BroadcastCondition_generic(SDL_Condition *_cond) +void SDL_BroadcastCondition_generic(SDL_Condition *_cond) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; if (!cond) { - return SDL_InvalidParamError("cond"); + return; } #ifndef SDL_THREADS_DISABLED @@ -146,8 +143,6 @@ int SDL_BroadcastCondition_generic(SDL_Condition *_cond) SDL_UnlockMutex(cond->lock); } #endif - - return 0; } /* Wait on the condition variable for at most 'timeoutNS' nanoseconds. @@ -171,13 +166,13 @@ Thread B: SDL_SignalCondition(cond); SDL_UnlockMutex(lock); */ -int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, Sint64 timeoutNS) +bool SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, Sint64 timeoutNS) { SDL_cond_generic *cond = (SDL_cond_generic *)_cond; - int retval = 0; + bool result = true; - if (!cond) { - return SDL_InvalidParamError("cond"); + if (!cond || !mutex) { + return true; } #ifndef SDL_THREADS_DISABLED @@ -193,7 +188,7 @@ int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, S SDL_UnlockMutex(mutex); // Wait for a signal - retval = SDL_WaitSemaphoreTimeoutNS(cond->wait_sem, timeoutNS); + result = SDL_WaitSemaphoreTimeoutNS(cond->wait_sem, timeoutNS); /* Let the signaler know we have completed the wait, otherwise the signaler can race ahead and get the condition semaphore @@ -204,7 +199,7 @@ int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, S SDL_LockMutex(cond->lock); if (cond->signals > 0) { // If we timed out, we need to eat a condition signal - if (retval > 0) { + if (!result) { SDL_WaitSemaphore(cond->wait_sem); } // We always notify the signal thread that we are done @@ -220,5 +215,12 @@ int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *_cond, SDL_Mutex *mutex, S SDL_LockMutex(mutex); #endif - return retval; + return result; } + +#ifndef SDL_THREAD_GENERIC_COND_SUFFIX +SDL_bool SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) +{ + return SDL_WaitConditionTimeoutNS_generic(cond, mutex, timeoutNS); +} +#endif diff --git a/src/thread/generic/SDL_syscond_c.h b/src/thread/generic/SDL_syscond_c.h index c4517c806a..c708663197 100644 --- a/src/thread/generic/SDL_syscond_c.h +++ b/src/thread/generic/SDL_syscond_c.h @@ -27,9 +27,9 @@ SDL_Condition *SDL_CreateCondition_generic(void); void SDL_DestroyCondition_generic(SDL_Condition *cond); -int SDL_SignalCondition_generic(SDL_Condition *cond); -int SDL_BroadcastCondition_generic(SDL_Condition *cond); -int SDL_WaitConditionTimeoutNS_generic(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS); +void SDL_SignalCondition_generic(SDL_Condition *cond); +void SDL_BroadcastCondition_generic(SDL_Condition *cond); +bool SDL_WaitConditionTimeoutNS_generic(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS); #endif // SDL_THREAD_GENERIC_COND_SUFFIX diff --git a/src/thread/generic/SDL_sysmutex.c b/src/thread/generic/SDL_sysmutex.c index f23fae69ab..12801f4a6c 100644 --- a/src/thread/generic/SDL_sysmutex.c +++ b/src/thread/generic/SDL_sysmutex.c @@ -81,9 +81,9 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doe #endif // SDL_THREADS_DISABLED } -int SDL_TryLockMutex(SDL_Mutex *mutex) +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { - int retval = 0; + bool result = true; #ifndef SDL_THREADS_DISABLED if (mutex) { SDL_ThreadID this_thread = SDL_GetCurrentThreadID(); @@ -91,18 +91,18 @@ int SDL_TryLockMutex(SDL_Mutex *mutex) ++mutex->recursive; } else { /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. */ - retval = SDL_TryWaitSemaphore(mutex->sem); - if (retval == 0) { + result = SDL_TryWaitSemaphore(mutex->sem); + if (result) { mutex->owner = this_thread; mutex->recursive = 0; } } } #endif // SDL_THREADS_DISABLED - return retval; + return result; } void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes diff --git a/src/thread/generic/SDL_sysrwlock.c b/src/thread/generic/SDL_sysrwlock.c index 29efccdfbd..9edcb249af 100644 --- a/src/thread/generic/SDL_sysrwlock.c +++ b/src/thread/generic/SDL_sysrwlock.c @@ -36,8 +36,6 @@ #define SDL_DestroyRWLock_generic SDL_DestroyRWLock #define SDL_LockRWLockForReading_generic SDL_LockRWLockForReading #define SDL_LockRWLockForWriting_generic SDL_LockRWLockForWriting -#define SDL_TryLockRWLockForReading_generic SDL_TryLockRWLockForReading -#define SDL_TryLockRWLockForWriting_generic SDL_TryLockRWLockForWriting #define SDL_UnlockRWLock_generic SDL_UnlockRWLock #endif @@ -122,14 +120,13 @@ void SDL_LockRWLockForWriting_generic(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_A #endif } -int SDL_TryLockRWLockForReading_generic(SDL_RWLock *rwlock) +bool SDL_TryLockRWLockForReading_generic(SDL_RWLock *rwlock) { #ifndef SDL_THREADS_DISABLED if (rwlock) { - const int rc = SDL_TryLockMutex(rwlock->lock); - if (rc != 0) { + if (!SDL_TryLockMutex(rwlock->lock)) { // !!! FIXME: there is a small window where a reader has to lock the mutex, and if we hit that, we will return SDL_RWLOCK_TIMEDOUT even though we could have shared the lock. - return rc; + return false; } SDL_assert(SDL_AtomicGet(&rwlock->writer_count) == 0); // shouldn't be able to grab lock if there's a writer! @@ -138,21 +135,27 @@ int SDL_TryLockRWLockForReading_generic(SDL_RWLock *rwlock) } #endif - return 0; + return true; } -int SDL_TryLockRWLockForWriting_generic(SDL_RWLock *rwlock) +#ifndef SDL_THREAD_GENERIC_RWLOCK_SUFFIX +SDL_bool SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) +{ + return SDL_TryLockRWLockForReading_generic(rwlock); +} +#endif + +bool SDL_TryLockRWLockForWriting_generic(SDL_RWLock *rwlock) { #ifndef SDL_THREADS_DISABLED if (rwlock) { - const int rc = SDL_TryLockMutex(rwlock->lock); - if (rc != 0) { - return rc; + if (!SDL_TryLockMutex(rwlock->lock)) { + return false; } if (SDL_AtomicGet(&rwlock->reader_count) > 0) { // a reader is using the shared lock, treat it as unavailable. SDL_UnlockMutex(rwlock->lock); - return SDL_RWLOCK_TIMEDOUT; + return false; } // we hold the lock! @@ -160,9 +163,16 @@ int SDL_TryLockRWLockForWriting_generic(SDL_RWLock *rwlock) } #endif - return 0; + return true; } +#ifndef SDL_THREAD_GENERIC_RWLOCK_SUFFIX +SDL_bool SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) +{ + return SDL_TryLockRWLockForWriting_generic(rwlock); +} +#endif + void SDL_UnlockRWLock_generic(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { #ifndef SDL_THREADS_DISABLED diff --git a/src/thread/generic/SDL_sysrwlock_c.h b/src/thread/generic/SDL_sysrwlock_c.h index 8264fa896d..1d8e72148d 100644 --- a/src/thread/generic/SDL_sysrwlock_c.h +++ b/src/thread/generic/SDL_sysrwlock_c.h @@ -29,8 +29,8 @@ SDL_RWLock *SDL_CreateRWLock_generic(void); void SDL_DestroyRWLock_generic(SDL_RWLock *rwlock); void SDL_LockRWLockForReading_generic(SDL_RWLock *rwlock); void SDL_LockRWLockForWriting_generic(SDL_RWLock *rwlock); -int SDL_TryLockRWLockForReading_generic(SDL_RWLock *rwlock); -int SDL_TryLockRWLockForWriting_generic(SDL_RWLock *rwlock); +bool SDL_TryLockRWLockForReading_generic(SDL_RWLock *rwlock); +bool SDL_TryLockRWLockForWriting_generic(SDL_RWLock *rwlock); void SDL_UnlockRWLock_generic(SDL_RWLock *rwlock); #endif // SDL_THREAD_GENERIC_RWLOCK_SUFFIX diff --git a/src/thread/generic/SDL_syssem.c b/src/thread/generic/SDL_syssem.c index 6e703b068c..bfb823cf38 100644 --- a/src/thread/generic/SDL_syssem.c +++ b/src/thread/generic/SDL_syssem.c @@ -29,16 +29,16 @@ SDL_Semaphore *SDL_CreateSemaphore(Uint32 initial_value) { SDL_SetError("SDL not built with thread support"); - return (SDL_Semaphore *)0; + return NULL; } void SDL_DestroySemaphore(SDL_Semaphore *sem) { } -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { - return SDL_SetError("SDL not built with thread support"); + return true; } Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) @@ -46,9 +46,9 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) return 0; } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { - return SDL_SetError("SDL not built with thread support"); + return; } #else @@ -103,41 +103,54 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) } } -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { - int retval; + bool result = false; if (!sem) { - return SDL_InvalidParamError("sem"); + return true; } - // A timeout of 0 is an easy case if (timeoutNS == 0) { - retval = SDL_MUTEX_TIMEDOUT; SDL_LockMutex(sem->count_lock); if (sem->count > 0) { --sem->count; - retval = 0; + result = true; } SDL_UnlockMutex(sem->count_lock); - - return retval; - } - - SDL_LockMutex(sem->count_lock); - ++sem->waiters_count; - retval = 0; - while ((sem->count == 0) && (retval != SDL_MUTEX_TIMEDOUT)) { - retval = SDL_WaitConditionTimeoutNS(sem->count_nonzero, - sem->count_lock, timeoutNS); - } - --sem->waiters_count; - if (retval == 0) { + } else if (timeoutNS < 0) { + SDL_LockMutex(sem->count_lock); + ++sem->waiters_count; + while (sem->count == 0) { + SDL_WaitConditionTimeoutNS(sem->count_nonzero, sem->count_lock, -1); + } + --sem->waiters_count; --sem->count; - } - SDL_UnlockMutex(sem->count_lock); + result = true; + SDL_UnlockMutex(sem->count_lock); + } else { + Uint64 stop_time = SDL_GetTicksNS() + timeoutNS; - return retval; + SDL_LockMutex(sem->count_lock); + ++sem->waiters_count; + while (sem->count == 0) { + Sint64 waitNS = (Sint64)(stop_time - SDL_GetTicksNS()); + if (waitNS > 0) { + SDL_WaitConditionTimeoutNS(sem->count_nonzero, sem->count_lock, waitNS); + } else { + break; + } + } + --sem->waiters_count; + + if (sem->count > 0) { + --sem->count; + result = true; + } + SDL_UnlockMutex(sem->count_lock); + } + + return result; } Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) @@ -153,10 +166,10 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) return value; } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { if (!sem) { - return SDL_InvalidParamError("sem"); + return; } SDL_LockMutex(sem->count_lock); @@ -165,8 +178,6 @@ int SDL_SignalSemaphore(SDL_Semaphore *sem) } ++sem->count; SDL_UnlockMutex(sem->count_lock); - - return 0; } #endif // SDL_THREADS_DISABLED diff --git a/src/thread/generic/SDL_systhread.c b/src/thread/generic/SDL_systhread.c index 2927bdf8d6..5c716e58a4 100644 --- a/src/thread/generic/SDL_systhread.c +++ b/src/thread/generic/SDL_systhread.c @@ -24,9 +24,9 @@ #include "../SDL_systhread.h" -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread) { return SDL_SetError("Threads are not supported on this platform"); } @@ -41,9 +41,9 @@ SDL_ThreadID SDL_GetCurrentThreadID(void) return 0; } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { - return 0; + return true; } void SDL_SYS_WaitThread(SDL_Thread *thread) diff --git a/src/thread/generic/SDL_systls.c b/src/thread/generic/SDL_systls.c index 9cd12efa46..8af5b7b9ac 100644 --- a/src/thread/generic/SDL_systls.c +++ b/src/thread/generic/SDL_systls.c @@ -32,7 +32,7 @@ SDL_TLSData *SDL_SYS_GetTLSData(void) return SDL_Generic_GetTLSData(); } -int SDL_SYS_SetTLSData(SDL_TLSData *data) +bool SDL_SYS_SetTLSData(SDL_TLSData *data) { return SDL_Generic_SetTLSData(data); } diff --git a/src/thread/n3ds/SDL_syscond.c b/src/thread/n3ds/SDL_syscond.c index 39625ca58d..97fa9f09d0 100644 --- a/src/thread/n3ds/SDL_syscond.c +++ b/src/thread/n3ds/SDL_syscond.c @@ -50,25 +50,23 @@ void SDL_DestroyCondition(SDL_Condition *cond) } // Restart one of the threads that are waiting on the condition variable -int SDL_SignalCondition(SDL_Condition *cond) +void SDL_SignalCondition(SDL_Condition *cond) { if (!cond) { - return SDL_InvalidParamError("cond"); + return; } CondVar_Signal(&cond->cond_variable); - return 0; } // Restart all threads that are waiting on the condition variable -int SDL_BroadcastCondition(SDL_Condition *cond) +void SDL_BroadcastCondition(SDL_Condition *cond) { if (!cond) { - return SDL_InvalidParamError("cond"); + return; } CondVar_Broadcast(&cond->cond_variable); - return 0; } /* Wait on the condition variable for at most 'timeoutNS' nanoseconds. @@ -92,15 +90,12 @@ Thread B: SDL_SignalCondition(cond); SDL_UnlockMutex(lock); */ -int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) +SDL_bool SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) { Result res; - if (!cond) { - return SDL_InvalidParamError("cond"); - } - if (!mutex) { - return SDL_InvalidParamError("mutex"); + if (!cond || !mutex) { + return true; } res = 0; @@ -110,7 +105,7 @@ int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 tim res = CondVar_WaitTimeout(&cond->cond_variable, &mutex->lock.lock, timeoutNS); } - return R_SUCCEEDED(res) ? 0 : SDL_MUTEX_TIMEDOUT; + return R_SUCCEEDED(res); } #endif // SDL_THREAD_N3DS diff --git a/src/thread/n3ds/SDL_sysmutex.c b/src/thread/n3ds/SDL_sysmutex.c index 0ca67a584a..6ed93d6f72 100644 --- a/src/thread/n3ds/SDL_sysmutex.c +++ b/src/thread/n3ds/SDL_sysmutex.c @@ -44,19 +44,22 @@ void SDL_DestroyMutex(SDL_Mutex *mutex) void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { RecursiveLock_Lock(&mutex->lock); } } -int SDL_TryLockMutex(SDL_Mutex *mutex) +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { - return (!mutex) ? 0 : RecursiveLock_TryLock(&mutex->lock); + if (mutex) { + return RecursiveLock_TryLock(&mutex->lock); + } + return true; } void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { RecursiveLock_Unlock(&mutex->lock); } } diff --git a/src/thread/n3ds/SDL_syssem.c b/src/thread/n3ds/SDL_syssem.c index 08994b672f..8b6b6d4ef5 100644 --- a/src/thread/n3ds/SDL_syssem.c +++ b/src/thread/n3ds/SDL_syssem.c @@ -26,8 +26,6 @@ #include <3ds.h> -int WaitOnSemaphoreFor(SDL_Semaphore *sem, Sint64 timeout); - struct SDL_Semaphore { LightSemaphore semaphore; @@ -60,58 +58,55 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) SDL_free(sem); } -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +static bool WaitOnSemaphoreFor(SDL_Semaphore *sem, Sint64 timeoutNS) { - if (!sem) { - return SDL_InvalidParamError("sem"); - } - - if (timeoutNS == -1) { // -1 == wait indefinitely. - LightSemaphore_Acquire(&sem->semaphore, 1); - return 0; - } - - if (LightSemaphore_TryAcquire(&sem->semaphore, 1) != 0) { - return WaitOnSemaphoreFor(sem, timeoutNS); - } - - return 0; -} - -int WaitOnSemaphoreFor(SDL_Semaphore *sem, Sint64 timeout) -{ - Uint64 stop_time = SDL_GetTicksNS() + timeout; - Uint64 current_time = SDL_GetTicksNS(); - while (current_time < stop_time) { + Uint64 stop_time = SDL_GetTicksNS() + timeoutNS; + while (SDL_GetTicksNS() < stop_time) { if (LightSemaphore_TryAcquire(&sem->semaphore, 1) == 0) { - return 0; + return true; } // 100 microseconds seems to be the sweet spot SDL_DelayNS(SDL_US_TO_NS(100)); - current_time = SDL_GetTicksNS(); } // If we failed, yield to avoid starvation on busy waits SDL_DelayNS(1); - return SDL_MUTEX_TIMEDOUT; + return false; +} + +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +{ + if (!sem) { + return true; + } + + if (timeoutNS < 0) { // -1 == wait indefinitely. + LightSemaphore_Acquire(&sem->semaphore, 1); + return true; + } + + if (LightSemaphore_TryAcquire(&sem->semaphore, 1) == 0) { + return true; + } + + return WaitOnSemaphoreFor(sem, timeoutNS); } Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) { if (!sem) { - SDL_InvalidParamError("sem"); return 0; } return sem->semaphore.current_count; } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { - if (!sem) { - return SDL_InvalidParamError("sem"); + if (sem) { + return; } + LightSemaphore_Release(&sem->semaphore, 1); - return 0; } #endif // SDL_THREAD_N3DS diff --git a/src/thread/n3ds/SDL_systhread.c b/src/thread/n3ds/SDL_systhread.c index cdce192886..fcda5d326e 100644 --- a/src/thread/n3ds/SDL_systhread.c +++ b/src/thread/n3ds/SDL_systhread.c @@ -43,9 +43,9 @@ static void ThreadEntry(void *arg) } -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread) { s32 priority = 0x30; int cpu = -1; @@ -69,7 +69,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, return SDL_SetError("Couldn't create thread"); } - return 0; + return true; } static size_t GetStackSize(size_t requested_size) @@ -93,7 +93,7 @@ SDL_ThreadID SDL_GetCurrentThreadID(void) return (SDL_ThreadID)thread_ID; } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority sdl_priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority sdl_priority) { s32 svc_priority; switch (sdl_priority) { @@ -112,7 +112,10 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority sdl_priority) default: svc_priority = N3DS_THREAD_PRIORITY_MEDIUM; } - return (int)svcSetThreadPriority(CUR_THREAD_HANDLE, svc_priority); + if (svcSetThreadPriority(CUR_THREAD_HANDLE, svc_priority) < 0) { + return SDL_SetError("svcSetThreadPriority failed"); + } + return true; } void SDL_SYS_WaitThread(SDL_Thread *thread) diff --git a/src/thread/ngage/SDL_sysmutex.cpp b/src/thread/ngage/SDL_sysmutex.cpp index df4de76a05..8e2cb4d8fc 100644 --- a/src/thread/ngage/SDL_sysmutex.cpp +++ b/src/thread/ngage/SDL_sysmutex.cpp @@ -69,7 +69,7 @@ void SDL_DestroyMutex(SDL_Mutex *mutex) // Lock the mutex void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { RMutex rmutex; rmutex.SetHandle(mutex->handle); rmutex.Wait(); @@ -78,22 +78,20 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang does // Try to lock the mutex #if 0 -int SDL_TryLockMutex(SDL_Mutex *mutex) +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { - if (mutex == NULL) - { - return 0; + if (mutex) { + // Not yet implemented. + return true; } - - // Not yet implemented. - return 0; + return true; } #endif // Unlock the mutex void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { RMutex rmutex; rmutex.SetHandle(mutex->handle); rmutex.Signal(); diff --git a/src/thread/ngage/SDL_syssem.cpp b/src/thread/ngage/SDL_syssem.cpp index f843592a71..01de3845f4 100644 --- a/src/thread/ngage/SDL_syssem.cpp +++ b/src/thread/ngage/SDL_syssem.cpp @@ -24,9 +24,6 @@ #include -// !!! FIXME: Should this be SDL_MUTEX_TIMEDOUT? -#define SDL_MUTEX_TIMEOUT -2 - struct SDL_Semaphore { TInt handle; @@ -35,10 +32,10 @@ struct SDL_Semaphore struct TInfo { - TInfo(TInt aTime, TInt aHandle) : iTime(aTime), iHandle(aHandle), iVal(0) {} + TInfo(TInt aTime, TInt aHandle) : iTime(aTime), iHandle(aHandle), iVal(true) {} TInt iTime; TInt iHandle; - TInt iVal; + bool iVal; }; extern TInt CreateUnique(TInt (*aFunc)(const TDesC &aName, TAny *, TAny *), TAny *, TAny *); @@ -50,7 +47,7 @@ static TBool RunThread(TAny *aInfo) RSemaphore sema; sema.SetHandle(info->iHandle); sema.Signal(); - info->iVal = SDL_MUTEX_TIMEOUT; + info->iVal = false; return 0; } @@ -100,23 +97,23 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) } } -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { if (!sem) { - return SDL_InvalidParamError("sem"); + return true; } if (timeoutNS == 0) { if (sem->count > 0) { --sem->count; - return 0; + return true; } - return SDL_MUTEX_TIMEOUT; + return false; } if (timeoutNS == -1) { // -1 == wait indefinitely. WaitAll(sem); - return 0; + return true; } RThread thread; @@ -124,14 +121,14 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) TInt status = CreateUnique(NewThread, &thread, info); if (status != KErrNone) { - return status; + return false; } thread.Resume(); WaitAll(sem); if (thread.ExitType() == EExitPending) { - thread.Kill(SDL_MUTEX_TIMEOUT); + thread.Kill(false); } thread.Close(); diff --git a/src/thread/ngage/SDL_systhread.cpp b/src/thread/ngage/SDL_systhread.cpp index 5a73a34b12..ff3e3e2f44 100644 --- a/src/thread/ngage/SDL_systhread.cpp +++ b/src/thread/ngage/SDL_systhread.cpp @@ -57,9 +57,9 @@ int CreateUnique(TInt (*aFunc)(const TDesC &aName, TAny *, TAny *), TAny *aPtr1, return status; } -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread) { RThread rthread; @@ -72,7 +72,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, rthread.Resume(); thread->handle = rthread.Handle(); - return 0; + return true; } void SDL_SYS_SetupThread(const char *name) @@ -87,9 +87,9 @@ SDL_ThreadID SDL_GetCurrentThreadID(void) return id; } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { - return 0; + return true; } void SDL_SYS_WaitThread(SDL_Thread *thread) diff --git a/src/thread/ps2/SDL_syssem.c b/src/thread/ps2/SDL_syssem.c index fe695f19f9..9b50219c5c 100644 --- a/src/thread/ps2/SDL_syssem.c +++ b/src/thread/ps2/SDL_syssem.c @@ -72,21 +72,17 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) } } -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { - int ret; u64 timeout_usec; u64 *timeout_ptr; if (!sem) { - return SDL_InvalidParamError("sem"); + return true; } if (timeoutNS == 0) { - if (PollSema(sem->semid) < 0) { - return SDL_MUTEX_TIMEDOUT; - } - return 0; + return (PollSema(sem->semid) == 0); } timeout_ptr = NULL; @@ -96,12 +92,7 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) timeout_ptr = &timeout_usec; } - ret = WaitSemaEx(sem->semid, 1, timeout_ptr); - - if (ret < 0) { - return SDL_MUTEX_TIMEDOUT; - } - return 0; // Wait condition satisfied. + return (WaitSemaEx(sem->semid, 1, timeout_ptr) == 0); } // Returns the current count of the semaphore @@ -110,31 +101,22 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) ee_sema_t info; if (!sem) { - SDL_InvalidParamError("sem"); return 0; } - if (ReferSemaStatus(sem->semid, &info) >= 0) { + if (ReferSemaStatus(sem->semid, &info) == 0) { return info.count; } - return 0; } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { - int res; - if (!sem) { - return SDL_InvalidParamError("sem"); + return; } - res = SignalSema(sem->semid); - if (res < 0) { - return SDL_SetError("sceKernelSignalSema() failed"); - } - - return 0; + SignalSema(sem->semid); } #endif // SDL_THREAD_PS2 diff --git a/src/thread/ps2/SDL_systhread.c b/src/thread/ps2/SDL_systhread.c index 469f669ee0..a6107cde60 100644 --- a/src/thread/ps2/SDL_systhread.c +++ b/src/thread/ps2/SDL_systhread.c @@ -54,9 +54,9 @@ static int childThread(void *arg) return res; } -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread) { ee_thread_status_t status; ee_thread_t eethread; @@ -92,7 +92,10 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, sema.option = 0; thread->endfunc = (void *)CreateSema(&sema); - return StartThread(thread->handle, thread); + if (StartThread(thread->handle, thread) < 0) { + return SDL_SetError("StartThread() failed"); + } + return true; } void SDL_SYS_SetupThread(const char *name) @@ -117,7 +120,7 @@ void SDL_SYS_DetachThread(SDL_Thread *thread) // Do nothing. } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int value; @@ -131,7 +134,10 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) value = 50; } - return ChangeThreadPriority(GetThreadId(), value); + if (ChangeThreadPriority(GetThreadId(), value) < 0) { + return SDL_SetError("ChangeThreadPriority() failed"); + } + return true; } #endif // SDL_THREAD_PS2 diff --git a/src/thread/psp/SDL_sysmutex.c b/src/thread/psp/SDL_sysmutex.c index 259f46a239..9012017b11 100644 --- a/src/thread/psp/SDL_sysmutex.c +++ b/src/thread/psp/SDL_sysmutex.c @@ -66,41 +66,35 @@ void SDL_DestroyMutex(SDL_Mutex *mutex) void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { -#ifndef SDL_THREADS_DISABLED - if (mutex != NULL) { + if (mutex) { const SceInt32 res = sceKernelLockLwMutex(&mutex->lock, 1, NULL); SDL_assert(res == SCE_KERNEL_ERROR_OK); // assume we're in a lot of trouble if this assert fails. } -#endif // SDL_THREADS_DISABLED } -int SDL_TryLockMutex(SDL_Mutex *mutex) +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { - int retval = 0; -#ifndef SDL_THREADS_DISABLED + bool result = true; if (mutex) { const SceInt32 res = sceKernelTryLockLwMutex(&mutex->lock, 1); if (res == SCE_KERNEL_ERROR_OK) { - retval = 0; + result = true; } else if (res == SCE_KERNEL_ERROR_WAIT_TIMEOUT) { - retval = SDL_MUTEX_TIMEDOUT; + result = false; } else { - SDL_assert(!"Error trying to lock mutex"); // assume we're in a lot of trouble if this assert fails. - retval = SDL_MUTEX_TIMEDOUT; + SDL_assert(res == SCE_KERNEL_ERROR_OK); // assume we're in a lot of trouble if this assert fails. + result = false; } } -#endif // SDL_THREADS_DISABLED - return retval; + return result; } void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { -#ifndef SDL_THREADS_DISABLED - if (mutex != NULL) { + if (mutex) { const SceInt32 res = sceKernelUnlockLwMutex(&mutex->lock, 1); - SDL_assert(res == 0); // assume we're in a lot of trouble if this assert fails. + SDL_assert(res == SCE_KERNEL_ERROR_OK); // assume we're in a lot of trouble if this assert fails. } -#endif // SDL_THREADS_DISABLED } #endif // SDL_THREAD_PSP diff --git a/src/thread/psp/SDL_syssem.c b/src/thread/psp/SDL_syssem.c index ce094e6639..8870457a6d 100644 --- a/src/thread/psp/SDL_syssem.c +++ b/src/thread/psp/SDL_syssem.c @@ -71,40 +71,25 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) * If the timeout is 0 then just poll the semaphore; if it's -1, pass * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout * is specified, convert it to microseconds. */ -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { SceUInt timeoutUS; - SceUInt *pTimeout; - int res; + SceUInt *pTimeout = NULL; if (!sem) { - return SDL_InvalidParamError("sem"); + return true; } if (timeoutNS == 0) { - res = sceKernelPollSema(sem->semid, 1); - if (res < 0) { - return SDL_MUTEX_TIMEDOUT; - } - return 0; + return (sceKernelPollSema(sem->semid, 1) == 0); } - if (timeoutNS < 0) { - pTimeout = NULL; - } else { + if (timeoutNS > 0) { timeoutUS = (SceUInt)SDL_NS_TO_US(timeoutNS); // Convert to microseconds. pTimeout = &timeoutUS; } - res = sceKernelWaitSema(sem->semid, 1, pTimeout); - switch (res) { - case SCE_KERNEL_ERROR_OK: - return 0; - case SCE_KERNEL_ERROR_WAIT_TIMEOUT: - return SDL_MUTEX_TIMEDOUT; - default: - return SDL_SetError("sceKernelWaitSema() failed"); - } + return (sceKernelWaitSema(sem->semid, 1, pTimeout) == 0); } // Returns the current count of the semaphore @@ -113,31 +98,22 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) SceKernelSemaInfo info; if (!sem) { - SDL_InvalidParamError("sem"); return 0; } - if (sceKernelReferSemaStatus(sem->semid, &info) >= 0) { + if (sceKernelReferSemaStatus(sem->semid, &info) == 0) { return info.currentCount; } - return 0; } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { - int res; - if (!sem) { - return SDL_InvalidParamError("sem"); + return; } - res = sceKernelSignalSema(sem->semid, 1); - if (res < 0) { - return SDL_SetError("sceKernelSignalSema() failed"); - } - - return 0; + sceKernelSignalSema(sem->semid, 1); } #endif // SDL_THREAD_PSP diff --git a/src/thread/psp/SDL_systhread.c b/src/thread/psp/SDL_systhread.c index 8e7d8e3791..cfba63ddd5 100644 --- a/src/thread/psp/SDL_systhread.c +++ b/src/thread/psp/SDL_systhread.c @@ -38,9 +38,9 @@ static int ThreadEntry(SceSize args, void *argp) return 0; } -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread) { SceKernelThreadInfo status; int priority = 32; @@ -59,7 +59,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, } sceKernelStartThread(thread->handle, 4, &thread); - return 0; + return true; } void SDL_SYS_SetupThread(const char *name) @@ -89,7 +89,7 @@ void SDL_SYS_KillThread(SDL_Thread *thread) sceKernelTerminateDeleteThread(thread->handle); } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int value; @@ -103,7 +103,10 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) value = 50; } - return sceKernelChangeThreadPriority(sceKernelGetThreadId(), value); + if (sceKernelChangeThreadPriority(sceKernelGetThreadId(), value) < 0) { + return SDL_SetError("sceKernelChangeThreadPriority() failed"); + } + return true; } #endif // SDL_THREAD_PSP diff --git a/src/thread/pthread/SDL_syscond.c b/src/thread/pthread/SDL_syscond.c index 2e804b4aa4..b06ba2c1fe 100644 --- a/src/thread/pthread/SDL_syscond.c +++ b/src/thread/pthread/SDL_syscond.c @@ -59,54 +59,38 @@ void SDL_DestroyCondition(SDL_Condition *cond) } // Restart one of the threads that are waiting on the condition variable -int SDL_SignalCondition(SDL_Condition *cond) +void SDL_SignalCondition(SDL_Condition *cond) { - int retval; - if (!cond) { - return SDL_InvalidParamError("cond"); + return; } - retval = 0; - if (pthread_cond_signal(&cond->cond) != 0) { - return SDL_SetError("pthread_cond_signal() failed"); - } - return retval; + pthread_cond_signal(&cond->cond); } // Restart all threads that are waiting on the condition variable -int SDL_BroadcastCondition(SDL_Condition *cond) +void SDL_BroadcastCondition(SDL_Condition *cond) { - int retval; - if (!cond) { - return SDL_InvalidParamError("cond"); + return; } - retval = 0; - if (pthread_cond_broadcast(&cond->cond) != 0) { - return SDL_SetError("pthread_cond_broadcast() failed"); - } - return retval; + pthread_cond_broadcast(&cond->cond); } -int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) +SDL_bool SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) { - int retval; #ifndef HAVE_CLOCK_GETTIME struct timeval delta; #endif struct timespec abstime; - if (!cond) { - return SDL_InvalidParamError("cond"); + if (!cond || !mutex) { + return true; } if (timeoutNS < 0) { - if (pthread_cond_wait(&cond->cond, &mutex->id) != 0) { - return SDL_SetError("pthread_cond_wait() failed"); - } - return 0; + return (pthread_cond_wait(&cond->cond, &mutex->id) == 0); } #ifdef HAVE_CLOCK_GETTIME @@ -125,19 +109,20 @@ int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 tim abstime.tv_nsec -= 1000000000; } + bool result; + int rc; tryagain: - retval = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime); - switch (retval) { + rc = pthread_cond_timedwait(&cond->cond, &mutex->id, &abstime); + switch (rc) { case EINTR: goto tryagain; // break; -Wunreachable-code-break case ETIMEDOUT: - retval = SDL_MUTEX_TIMEDOUT; - break; - case 0: + result = false; break; default: - retval = SDL_SetError("pthread_cond_timedwait() failed"); + result = false; + break; } - return retval; + return result; } diff --git a/src/thread/pthread/SDL_sysmutex.c b/src/thread/pthread/SDL_sysmutex.c index 79dba13312..16a9e66799 100644 --- a/src/thread/pthread/SDL_sysmutex.c +++ b/src/thread/pthread/SDL_sysmutex.c @@ -60,7 +60,7 @@ void SDL_DestroyMutex(SDL_Mutex *mutex) void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { #ifdef FAKE_RECURSIVE_MUTEX pthread_t this_thread = pthread_self(); if (mutex->owner == this_thread) { @@ -82,9 +82,9 @@ void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang does } } -int SDL_TryLockMutex(SDL_Mutex *mutex) +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { - int retval = 0; + bool result = true; if (mutex) { #ifdef FAKE_RECURSIVE_MUTEX @@ -93,39 +93,39 @@ int SDL_TryLockMutex(SDL_Mutex *mutex) ++mutex->recursive; } else { /* The order of operations is important. - We set the locking thread id after we obtain the lock - so unlocks from other threads will fail. + We set the locking thread id after we obtain the lock + so unlocks from other threads will fail. */ - const int result = pthread_mutex_trylock(&mutex->id); - if (result == 0) { + const int rc = pthread_mutex_trylock(&mutex->id); + if (rc == 0) { mutex->owner = this_thread; mutex->recursive = 0; - } else if (result == EBUSY) { - retval = SDL_MUTEX_TIMEDOUT; + } else if (rc == EBUSY) { + result = false; } else { SDL_assert(!"Error trying to lock mutex"); // assume we're in a lot of trouble if this assert fails. - retval = SDL_MUTEX_TIMEDOUT; + result = false; } } #else - const int result = pthread_mutex_trylock(&mutex->id); - if (result != 0) { - if (result == EBUSY) { - retval = SDL_MUTEX_TIMEDOUT; + const int rc = pthread_mutex_trylock(&mutex->id); + if (rc != 0) { + if (rc == EBUSY) { + result = false; } else { SDL_assert(!"Error trying to lock mutex"); // assume we're in a lot of trouble if this assert fails. - retval = SDL_MUTEX_TIMEDOUT; + result = false; } } #endif } - return retval; + return result; } void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { #ifdef FAKE_RECURSIVE_MUTEX // We can only unlock the mutex if we own it if (pthread_self() == mutex->owner) { diff --git a/src/thread/pthread/SDL_sysrwlock.c b/src/thread/pthread/SDL_sysrwlock.c index 7278a666cf..b0580037cf 100644 --- a/src/thread/pthread/SDL_sysrwlock.c +++ b/src/thread/pthread/SDL_sysrwlock.c @@ -69,38 +69,38 @@ void SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS } } -int SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) +SDL_bool SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) { - int retval = 0; + bool result = true; if (rwlock) { - const int result = pthread_rwlock_tryrdlock(&rwlock->id); - if (result != 0) { - retval = SDL_RWLOCK_TIMEDOUT; - if (result != EBUSY) { + const int rc = pthread_rwlock_tryrdlock(&rwlock->id); + if (rc != 0) { + result = false; + if (rc != EBUSY) { SDL_assert(!"Error trying to lock rwlock for reading"); // assume we're in a lot of trouble if this assert fails. } } } - return retval; + return result; } -int SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) +SDL_bool SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) { - int retval = 0; + bool result = true; if (rwlock) { - const int result = pthread_rwlock_trywrlock(&rwlock->id); - if (result != 0) { - retval = SDL_RWLOCK_TIMEDOUT; - if (result != EBUSY) { + const int rc = pthread_rwlock_trywrlock(&rwlock->id); + if (rc != 0) { + result = false; + if (rc != EBUSY) { SDL_assert(!"Error trying to lock rwlock for writing"); // assume we're in a lot of trouble if this assert fails. } } } - return retval; + return result; } void SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index d89f3fa9ed..0484518bc9 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -60,39 +60,33 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) } } -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { - int retval = 0; #ifdef HAVE_SEM_TIMEDWAIT #ifndef HAVE_CLOCK_GETTIME struct timeval now; #endif struct timespec ts_timeout; #else - Uint64 end; + Uint64 stop_time; #endif if (!sem) { - return SDL_InvalidParamError("sem"); + return true; } // Try the easy cases first if (timeoutNS == 0) { - retval = SDL_MUTEX_TIMEDOUT; - if (sem_trywait(&sem->sem) == 0) { - retval = 0; - } - return retval; + return (sem_trywait(&sem->sem) == 0); } - if (timeoutNS < 0) { - do { - retval = sem_wait(&sem->sem); - } while (retval < 0 && errno == EINTR); - if (retval < 0) { - retval = SDL_SetError("sem_wait() failed"); - } - return retval; + if (timeoutNS < 0) { + int rc; + do { + rc = sem_wait(&sem->sem); + } while (rc < 0 && errno == EINTR); + + return (rc == 0); } #ifdef HAVE_SEM_TIMEDWAIT @@ -121,29 +115,22 @@ int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) } // Wait. + int rc; do { - retval = sem_timedwait(&sem->sem, &ts_timeout); - } while (retval < 0 && errno == EINTR); + rc = sem_timedwait(&sem->sem, &ts_timeout); + } while (rc < 0 && errno == EINTR); - if (retval < 0) { - if (errno == ETIMEDOUT) { - retval = SDL_MUTEX_TIMEDOUT; - } else { - SDL_SetError("sem_timedwait returned an error: %s", strerror(errno)); - } - } + return (rc == 0); #else - end = SDL_GetTicksNS() + timeoutNS; + stop_time = SDL_GetTicksNS() + timeoutNS; while (sem_trywait(&sem->sem) != 0) { - if (SDL_GetTicksNS() >= end) { - retval = SDL_MUTEX_TIMEDOUT; - break; + if (SDL_GetTicksNS() >= stop_time) { + return false; } SDL_DelayNS(100); } + return true; #endif // HAVE_SEM_TIMEDWAIT - - return retval; } Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) @@ -151,7 +138,6 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) int ret = 0; if (!sem) { - SDL_InvalidParamError("sem"); return 0; } @@ -162,19 +148,13 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) return (Uint32)ret; } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { - int retval; - if (!sem) { - return SDL_InvalidParamError("sem"); + return; } - retval = sem_post(&sem->sem); - if (retval < 0) { - SDL_SetError("sem_post() failed"); - } - return retval; + sem_post(&sem->sem); } #endif // SDL_PLATFORM_MACOS diff --git a/src/thread/pthread/SDL_systhread.c b/src/thread/pthread/SDL_systhread.c index 331a370ee6..feaae3b965 100644 --- a/src/thread/pthread/SDL_systhread.c +++ b/src/thread/pthread/SDL_systhread.c @@ -77,9 +77,9 @@ static int (*ppthread_setname_np)(const char *) = NULL; static bool checked_setname = false; static int (*ppthread_setname_np)(pthread_t, const char *) = NULL; #endif -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread) { pthread_attr_t type; @@ -112,7 +112,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, return SDL_SetError("Not enough resources to create thread"); } - return 0; + return true; } void SDL_SYS_SetupThread(const char *name) @@ -175,11 +175,11 @@ SDL_ThreadID SDL_GetCurrentThreadID(void) return (SDL_ThreadID)pthread_self(); } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { #ifdef SDL_PLATFORM_RISCOS // FIXME: Setting thread priority does not seem to be supported - return 0; + return true; #else struct sched_param sched; int policy; @@ -269,7 +269,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) if (pthread_setschedparam(thread, policy, &sched) != 0) { return SDL_SetError("pthread_setschedparam() failed"); } - return 0; + return true; #endif // linux #endif // #if SDL_PLATFORM_RISCOS } diff --git a/src/thread/pthread/SDL_systls.c b/src/thread/pthread/SDL_systls.c index 114291fb89..cc7a0a5066 100644 --- a/src/thread/pthread/SDL_systls.c +++ b/src/thread/pthread/SDL_systls.c @@ -52,7 +52,7 @@ SDL_TLSData *SDL_SYS_GetTLSData(void) return NULL; } -int SDL_SYS_SetTLSData(SDL_TLSData *data) +bool SDL_SYS_SetTLSData(SDL_TLSData *data) { if (generic_local_storage) { return SDL_Generic_SetTLSData(data); @@ -61,7 +61,7 @@ int SDL_SYS_SetTLSData(SDL_TLSData *data) if (pthread_setspecific(thread_local_storage, data) != 0) { return SDL_SetError("pthread_setspecific() failed"); } - return 0; + return true; } void SDL_SYS_QuitTLSData(void) diff --git a/src/thread/stdcpp/SDL_syscond.cpp b/src/thread/stdcpp/SDL_syscond.cpp index c182ea60c4..592092e63d 100644 --- a/src/thread/stdcpp/SDL_syscond.cpp +++ b/src/thread/stdcpp/SDL_syscond.cpp @@ -36,8 +36,8 @@ struct SDL_Condition }; // Create a condition variable -extern "C" SDL_Condition * -SDL_CreateCondition(void) +extern "C" +SDL_Condition *SDL_CreateCondition(void) { // Allocate and initialize the condition variable try { @@ -53,8 +53,8 @@ SDL_CreateCondition(void) } // Destroy a condition variable -extern "C" void -SDL_DestroyCondition(SDL_Condition *cond) +extern "C" +void SDL_DestroyCondition(SDL_Condition *cond) { if (cond) { delete cond; @@ -62,80 +62,52 @@ SDL_DestroyCondition(SDL_Condition *cond) } // Restart one of the threads that are waiting on the condition variable -extern "C" int -SDL_SignalCondition(SDL_Condition *cond) +extern "C" +void SDL_SignalCondition(SDL_Condition *cond) { if (!cond) { - return SDL_InvalidParamError("cond"); + return; } cond->cpp_cond.notify_one(); - return 0; } // Restart all threads that are waiting on the condition variable -extern "C" int -SDL_BroadcastCondition(SDL_Condition *cond) +extern "C" +void SDL_BroadcastCondition(SDL_Condition *cond) { if (!cond) { - return SDL_InvalidParamError("cond"); + return; } cond->cpp_cond.notify_all(); - return 0; } -/* Wait on the condition variable for at most 'timeoutNS' nanoseconds. - The mutex must be locked before entering this function! - The mutex is unlocked during the wait, and locked again after the wait. - -Typical use: - -Thread A: - SDL_LockMutex(lock); - while ( ! condition ) { - SDL_WaitCondition(cond, lock); - } - SDL_UnlockMutex(lock); - -Thread B: - SDL_LockMutex(lock); - ... - condition = true; - ... - SDL_SignalCondition(cond); - SDL_UnlockMutex(lock); - */ -extern "C" int -SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) +extern "C" +SDL_bool SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) { - if (cond == NULL) { - return SDL_InvalidParamError("cond"); - } - - if (mutex == NULL) { - return SDL_InvalidParamError("mutex"); + if (!cond || !mutex) { + return true; } try { std::unique_lock cpp_lock(mutex->cpp_mutex, std::adopt_lock_t()); if (timeoutNS < 0) { - cond->cpp_cond.wait( - cpp_lock); + cond->cpp_cond.wait(cpp_lock); cpp_lock.release(); - return 0; + return true; } else { auto wait_result = cond->cpp_cond.wait_for( cpp_lock, std::chrono::duration(timeoutNS)); cpp_lock.release(); if (wait_result == std::cv_status::timeout) { - return SDL_MUTEX_TIMEDOUT; + return false; } else { - return 0; + return true; } } - } catch (std::system_error &ex) { - return SDL_SetError("Unable to wait on a C++ condition variable: code=%d; %s", ex.code(), ex.what()); + } catch (std::system_error &) { + return false; } } diff --git a/src/thread/stdcpp/SDL_sysmutex.cpp b/src/thread/stdcpp/SDL_sysmutex.cpp index 025957e030..7a489b8f7b 100644 --- a/src/thread/stdcpp/SDL_sysmutex.cpp +++ b/src/thread/stdcpp/SDL_sysmutex.cpp @@ -29,7 +29,8 @@ extern "C" { #include "SDL_sysmutex_c.h" #include -extern "C" SDL_Mutex * SDL_CreateMutex(void) +extern "C" +SDL_Mutex * SDL_CreateMutex(void) { // Allocate and initialize the mutex try { @@ -43,34 +44,41 @@ extern "C" SDL_Mutex * SDL_CreateMutex(void) return NULL; } -extern "C" void SDL_DestroyMutex(SDL_Mutex *mutex) +extern "C" +void SDL_DestroyMutex(SDL_Mutex *mutex) { if (mutex) { delete mutex; } } -extern "C" void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes +extern "C" +void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { try { mutex->cpp_mutex.lock(); } catch (std::system_error &/*ex*/) { SDL_assert(!"Error trying to lock mutex"); // assume we're in a lot of trouble if this assert fails. - //return SDL_SetError("unable to lock a C++ mutex: code=%d; %s", ex.code(), ex.what()); } } } -extern "C" int SDL_TryLockMutex(SDL_Mutex *mutex) +extern "C" +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { - return ((!mutex) || mutex->cpp_mutex.try_lock()) ? 0 : SDL_MUTEX_TIMEDOUT; + bool result = true; + if (mutex) { + result = mutex->cpp_mutex.try_lock(); + } + return result; } // Unlock the mutex -extern "C" void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes +extern "C" +void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (mutex != NULL) { + if (mutex) { mutex->cpp_mutex.unlock(); } } diff --git a/src/thread/stdcpp/SDL_sysrwlock.cpp b/src/thread/stdcpp/SDL_sysrwlock.cpp index 90bca25fbb..1327a88b9c 100644 --- a/src/thread/stdcpp/SDL_sysrwlock.cpp +++ b/src/thread/stdcpp/SDL_sysrwlock.cpp @@ -30,7 +30,8 @@ struct SDL_RWLock SDL_ThreadID write_owner; }; -extern "C" SDL_RWLock *SDL_CreateRWLock(void) +extern "C" +SDL_RWLock *SDL_CreateRWLock(void) { try { SDL_RWLock *rwlock = new SDL_RWLock; @@ -44,14 +45,16 @@ extern "C" SDL_RWLock *SDL_CreateRWLock(void) } } -extern "C" void SDL_DestroyRWLock(SDL_RWLock *rwlock) +extern "C" +void SDL_DestroyRWLock(SDL_RWLock *rwlock) { if (rwlock) { delete rwlock; } } -extern "C" void SDL_LockRWLockForReading(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes +extern "C" +void SDL_LockRWLockForReading(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { if (rwlock) { try { @@ -63,7 +66,8 @@ extern "C" void SDL_LockRWLockForReading(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFET } } -extern "C" void SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes +extern "C" +void SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { if (rwlock) { try { @@ -76,31 +80,31 @@ extern "C" void SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFET } } -extern "C" int SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) +extern "C" +SDL_bool SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) { - int retval = 0; + bool result = true; if (rwlock) { - if (rwlock->cpp_mutex.try_lock_shared() == false) { - retval = SDL_RWLOCK_TIMEDOUT; - } + result = rwlock->cpp_mutex.try_lock_shared(); } - return retval; + return result; } -extern "C" int SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) +extern "C" +SDL_bool SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) { - int retval = 0; + bool result = true; if (rwlock) { - if (rwlock->cpp_mutex.try_lock() == false) { - retval = SDL_RWLOCK_TIMEDOUT; - } else { + result = rwlock->cpp_mutex.try_lock(); + if (result) { rwlock->write_owner = SDL_GetCurrentThreadID(); } } - return retval; + return result; } -extern "C" void SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes +extern "C" +void SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { if (rwlock) { if (rwlock->write_owner == SDL_GetCurrentThreadID()) { diff --git a/src/thread/stdcpp/SDL_systhread.cpp b/src/thread/stdcpp/SDL_systhread.cpp index b71b52f156..c718d23dc3 100644 --- a/src/thread/stdcpp/SDL_systhread.cpp +++ b/src/thread/stdcpp/SDL_systhread.cpp @@ -39,15 +39,15 @@ static void RunThread(void *args) SDL_RunThread((SDL_Thread *)args); } -extern "C" int -SDL_SYS_CreateThread(SDL_Thread *thread, +extern "C" +bool SDL_SYS_CreateThread(SDL_Thread *thread, SDL_FunctionPointer pfnBeginThread, SDL_FunctionPointer pfnEndThread) { try { // !!! FIXME: no way to set a thread stack size here. thread->handle = (void *)new std::thread(RunThread, thread); - return 0; + return true; } catch (std::system_error &ex) { return SDL_SetError("unable to start a C++ thread: code=%d; %s", ex.code().value(), ex.what()); } catch (std::bad_alloc &) { @@ -55,14 +55,14 @@ SDL_SYS_CreateThread(SDL_Thread *thread, } } -extern "C" void -SDL_SYS_SetupThread(const char *name) +extern "C" +void SDL_SYS_SetupThread(const char *name) { // Do nothing. } -extern "C" SDL_ThreadID -SDL_GetCurrentThreadID(void) +extern "C" +SDL_ThreadID SDL_GetCurrentThreadID(void) { static_assert(sizeof(std::thread::id) <= sizeof(SDL_ThreadID), "std::thread::id must not be bigger than SDL_ThreadID"); SDL_ThreadID thread_id{}; @@ -71,8 +71,8 @@ SDL_GetCurrentThreadID(void) return thread_id; } -extern "C" int -SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +extern "C" +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { #ifdef SDL_PLATFORM_WINRT int value; @@ -91,14 +91,14 @@ SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) if (!SetThreadPriority(GetCurrentThread(), value)) { return WIN_SetError("SetThreadPriority()"); } - return 0; + return true; #else return SDL_Unsupported(); #endif } -extern "C" void -SDL_SYS_WaitThread(SDL_Thread *thread) +extern "C" +void SDL_SYS_WaitThread(SDL_Thread *thread) { if (!thread) { return; @@ -120,8 +120,8 @@ SDL_SYS_WaitThread(SDL_Thread *thread) } } -extern "C" void -SDL_SYS_DetachThread(SDL_Thread *thread) +extern "C" +void SDL_SYS_DetachThread(SDL_Thread *thread) { if (!thread) { return; @@ -157,10 +157,10 @@ SDL_TLSData * SDL_SYS_GetTLSData(void) } extern "C" -int SDL_SYS_SetTLSData(SDL_TLSData *data) +bool SDL_SYS_SetTLSData(SDL_TLSData *data) { thread_local_storage = data; - return 0; + return true; } extern "C" diff --git a/src/thread/vita/SDL_sysmutex.c b/src/thread/vita/SDL_sysmutex.c index c86508ffb5..f332902f72 100644 --- a/src/thread/vita/SDL_sysmutex.c +++ b/src/thread/vita/SDL_sysmutex.c @@ -62,45 +62,36 @@ void SDL_DestroyMutex(SDL_Mutex *mutex) void SDL_LockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { -#ifndef SDL_THREADS_DISABLED - if (mutex != NULL) { + if (mutex) { const SceInt32 res = sceKernelLockLwMutex(&mutex->lock, 1, NULL); SDL_assert(res == SCE_KERNEL_OK); // assume we're in a lot of trouble if this assert fails. } -#endif // SDL_THREADS_DISABLED } -int SDL_TryLockMutex(SDL_Mutex *mutex) +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { -#ifdef SDL_THREADS_DISABLED - return 0; -#else - SceInt32 res = 0; + bool result = true; - if (!mutex) { - return 0; + if (mutex) { + const SceInt32 res = sceKernelTryLockLwMutex(&mutex->lock, 1); + if (res == SCE_KERNEL_OK) { + result = true; + } else if (res == SCE_KERNEL_ERROR_MUTEX_FAILED_TO_OWN) { + result = false; + } else { + SDL_assert(res == SCE_KERNEL_OK); // assume we're in a lot of trouble if this assert fails. + result = false; + } } - - res = sceKernelTryLockLwMutex(&mutex->lock, 1); - switch (res) { - case SCE_KERNEL_OK: return 0; - case SCE_KERNEL_ERROR_MUTEX_FAILED_TO_OWN: return SDL_MUTEX_TIMEDOUT; - default: break; - } - - SDL_assert(!"Error trying to lock mutex"); // assume we're in a lot of trouble if this assert fails. - return SDL_MUTEX_TIMEDOUT; -#endif // SDL_THREADS_DISABLED + return result; } void SDL_UnlockMutex(SDL_Mutex *mutex) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { -#ifndef SDL_THREADS_DISABLED - if (mutex != NULL) { + if (mutex) { const SceInt32 res = sceKernelUnlockLwMutex(&mutex->lock, 1); SDL_assert(res == SCE_KERNEL_OK); // assume we're in a lot of trouble if this assert fails. } -#endif // SDL_THREADS_DISABLED } #endif // SDL_THREAD_VITA diff --git a/src/thread/vita/SDL_syssem.c b/src/thread/vita/SDL_syssem.c index fceeaaa460..3e3f27f810 100644 --- a/src/thread/vita/SDL_syssem.c +++ b/src/thread/vita/SDL_syssem.c @@ -72,40 +72,25 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) * If the timeout is 0 then just poll the semaphore; if it's -1, pass * NULL to sceKernelWaitSema() so that it waits indefinitely; and if the timeout * is specified, convert it to microseconds. */ -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { SceUInt timeoutUS; - SceUInt *pTimeout; - int res; + SceUInt *pTimeout = NULL; if (!sem) { - return SDL_InvalidParamError("sem"); + return true; } if (timeoutNS == 0) { - res = sceKernelPollSema(sem->semid, 1); - if (res < 0) { - return SDL_MUTEX_TIMEDOUT; - } - return 0; + return (sceKernelPollSema(sem->semid, 1) == 0); } - if (timeoutNS < 0) { - pTimeout = NULL; - } else { + if (timeoutNS > 0) { timeoutUS = (SceUInt)SDL_NS_TO_US(timeoutNS); // Convert to microseconds. pTimeout = &timeoutUS; } - res = sceKernelWaitSema(sem->semid, 1, pTimeout); - switch (res) { - case SCE_KERNEL_OK: - return 0; - case SCE_KERNEL_ERROR_WAIT_TIMEOUT: - return SDL_MUTEX_TIMEDOUT; - default: - return SDL_SetError("sceKernelWaitSema() failed"); - } + return (sceKernelWaitSema(sem->semid, 1, pTimeout) == 0); } // Returns the current count of the semaphore @@ -115,7 +100,6 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) info.size = sizeof(info); if (!sem) { - SDL_InvalidParamError("sem"); return 0; } @@ -126,20 +110,13 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) return 0; } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { - int res; - if (!sem) { - return SDL_InvalidParamError("sem"); + return; } - res = sceKernelSignalSema(sem->semid, 1); - if (res < 0) { - return SDL_SetError("sceKernelSignalSema() failed"); - } - - return 0; + sceKernelSignalSema(sem->semid, 1); } #endif // SDL_THREAD_VITA diff --git a/src/thread/vita/SDL_systhread.c b/src/thread/vita/SDL_systhread.c index 919863098b..78c780d112 100644 --- a/src/thread/vita/SDL_systhread.c +++ b/src/thread/vita/SDL_systhread.c @@ -48,9 +48,9 @@ static int ThreadEntry(SceSize args, void *argp) return 0; } -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer pfnBeginThread, + SDL_FunctionPointer pfnEndThread) { char thread_name[VITA_THREAD_NAME_MAX]; @@ -87,7 +87,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, } sceKernelStartThread(thread->handle, 4, &thread); - return 0; + return true; } void SDL_SYS_SetupThread(const char *name) @@ -111,7 +111,7 @@ void SDL_SYS_DetachThread(SDL_Thread *thread) // Do nothing. } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int value = VITA_THREAD_PRIORITY_NORMAL; @@ -130,7 +130,10 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) break; } - return sceKernelChangeThreadPriority(0, value); + if (sceKernelChangeThreadPriority(0, value) < 0) { + return SDL_SetError("sceKernelChangeThreadPriority() failed"); + } + return true; } #endif // SDL_THREAD_VITA diff --git a/src/thread/windows/SDL_syscond_cv.c b/src/thread/windows/SDL_syscond_cv.c index 9beca1abb5..7cd444e8e7 100644 --- a/src/thread/windows/SDL_syscond_cv.c +++ b/src/thread/windows/SDL_syscond_cv.c @@ -25,9 +25,9 @@ typedef SDL_Condition *(*pfnSDL_CreateCondition)(void); typedef void (*pfnSDL_DestroyCondition)(SDL_Condition *); -typedef int (*pfnSDL_SignalCondition)(SDL_Condition *); -typedef int (*pfnSDL_BroadcastCondition)(SDL_Condition *); -typedef int (*pfnSDL_WaitConditionTimeoutNS)(SDL_Condition *, SDL_Mutex *, Sint64); +typedef void (*pfnSDL_SignalCondition)(SDL_Condition *); +typedef void (*pfnSDL_BroadcastCondition)(SDL_Condition *); +typedef bool (*pfnSDL_WaitConditionTimeoutNS)(SDL_Condition *, SDL_Mutex *, Sint64); typedef struct SDL_cond_impl_t { @@ -90,42 +90,23 @@ static void SDL_DestroyCondition_cv(SDL_Condition *cond) SDL_free(cond); } -static int SDL_SignalCondition_cv(SDL_Condition *_cond) +static void SDL_SignalCondition_cv(SDL_Condition *_cond) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; - if (!cond) { - return SDL_InvalidParamError("cond"); - } - pWakeConditionVariable(&cond->cond); - - return 0; } -static int SDL_BroadcastCondition_cv(SDL_Condition *_cond) +static void SDL_BroadcastCondition_cv(SDL_Condition *_cond) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; - if (!cond) { - return SDL_InvalidParamError("cond"); - } - pWakeAllConditionVariable(&cond->cond); - - return 0; } -static int SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mutex, Sint64 timeoutNS) +static bool SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mutex, Sint64 timeoutNS) { SDL_cond_cv *cond = (SDL_cond_cv *)_cond; DWORD timeout; - int ret; - - if (!cond) { - return SDL_InvalidParamError("cond"); - } - if (!_mutex) { - return SDL_InvalidParamError("mutex"); - } + bool result; if (timeoutNS < 0) { timeout = INFINITE; @@ -137,22 +118,15 @@ static int SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mutex SDL_mutex_srw *mutex = (SDL_mutex_srw *)_mutex; if (mutex->count != 1 || mutex->owner != GetCurrentThreadId()) { - return SDL_SetError("Passed mutex is not locked or locked recursively"); + // Passed mutex is not locked or locked recursively" + return false; } // The mutex must be updated to the released state mutex->count = 0; mutex->owner = 0; - if (pSleepConditionVariableSRW(&cond->cond, &mutex->srw, timeout, 0) == FALSE) { - if (GetLastError() == ERROR_TIMEOUT) { - ret = SDL_MUTEX_TIMEDOUT; - } else { - ret = SDL_SetError("SleepConditionVariableSRW() failed"); - } - } else { - ret = 0; - } + result = pSleepConditionVariableSRW(&cond->cond, &mutex->srw, timeout, 0); // The mutex is owned by us again, regardless of status of the wait SDL_assert(mutex->count == 0 && mutex->owner == 0); @@ -163,18 +137,10 @@ static int SDL_WaitConditionTimeoutNS_cv(SDL_Condition *_cond, SDL_Mutex *_mutex SDL_assert(SDL_mutex_impl_active.Type == SDL_MUTEX_CS); - if (pSleepConditionVariableCS(&cond->cond, &mutex->cs, timeout) == FALSE) { - if (GetLastError() == ERROR_TIMEOUT) { - ret = SDL_MUTEX_TIMEDOUT; - } else { - ret = SDL_SetError("SleepConditionVariableCS() failed"); - } - } else { - ret = 0; - } + result = pSleepConditionVariableCS(&cond->cond, &mutex->cs, timeout); } - return ret; + return result; } static const SDL_cond_impl_t SDL_cond_impl_cv = { @@ -241,20 +207,34 @@ SDL_Condition *SDL_CreateCondition(void) void SDL_DestroyCondition(SDL_Condition *cond) { - SDL_cond_impl_active.Destroy(cond); + if (cond) { + SDL_cond_impl_active.Destroy(cond); + } } -int SDL_SignalCondition(SDL_Condition *cond) +void SDL_SignalCondition(SDL_Condition *cond) { - return SDL_cond_impl_active.Signal(cond); + if (!cond) { + return; + } + + SDL_cond_impl_active.Signal(cond); } -int SDL_BroadcastCondition(SDL_Condition *cond) +void SDL_BroadcastCondition(SDL_Condition *cond) { - return SDL_cond_impl_active.Broadcast(cond); + if (!cond) { + return; + } + + SDL_cond_impl_active.Broadcast(cond); } -int SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) +SDL_bool SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS) { + if (!cond || !mutex) { + return true; + } + return SDL_cond_impl_active.WaitTimeoutNS(cond, mutex, timeoutNS); } diff --git a/src/thread/windows/SDL_sysmutex.c b/src/thread/windows/SDL_sysmutex.c index 596e30d8bf..f1e1730764 100644 --- a/src/thread/windows/SDL_sysmutex.c +++ b/src/thread/windows/SDL_sysmutex.c @@ -90,11 +90,11 @@ static void SDL_LockMutex_srw(SDL_Mutex *_mutex) SDL_NO_THREAD_SAFETY_ANALYSIS } } -static int SDL_TryLockMutex_srw(SDL_Mutex *_mutex) +static bool SDL_TryLockMutex_srw(SDL_Mutex *_mutex) { SDL_mutex_srw *mutex = (SDL_mutex_srw *)_mutex; const DWORD this_thread = GetCurrentThreadId(); - int retval = 0; + bool retval = true; if (mutex->owner == this_thread) { ++mutex->count; @@ -104,7 +104,7 @@ static int SDL_TryLockMutex_srw(SDL_Mutex *_mutex) mutex->owner = this_thread; mutex->count = 1; } else { - retval = SDL_MUTEX_TIMEDOUT; + retval = false; } } return retval; @@ -166,10 +166,10 @@ static void SDL_LockMutex_cs(SDL_Mutex *mutex_) SDL_NO_THREAD_SAFETY_ANALYSIS / EnterCriticalSection(&mutex->cs); } -static int SDL_TryLockMutex_cs(SDL_Mutex *mutex_) +static bool SDL_TryLockMutex_cs(SDL_Mutex *mutex_) { SDL_mutex_cs *mutex = (SDL_mutex_cs *)mutex_; - return (TryEnterCriticalSection(&mutex->cs) == 0) ? SDL_MUTEX_TIMEDOUT : 0; + return TryEnterCriticalSection(&mutex->cs); } static void SDL_UnlockMutex_cs(SDL_Mutex *mutex_) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes @@ -234,9 +234,14 @@ void SDL_LockMutex(SDL_Mutex *mutex) } } -int SDL_TryLockMutex(SDL_Mutex *mutex) +SDL_bool SDL_TryLockMutex(SDL_Mutex *mutex) { - return mutex ? SDL_mutex_impl_active.TryLock(mutex) : 0; + bool result = true; + + if (mutex) { + result = SDL_mutex_impl_active.TryLock(mutex); + } + return result; } void SDL_UnlockMutex(SDL_Mutex *mutex) diff --git a/src/thread/windows/SDL_sysmutex_c.h b/src/thread/windows/SDL_sysmutex_c.h index 447e2cff65..cc6b2b3040 100644 --- a/src/thread/windows/SDL_sysmutex_c.h +++ b/src/thread/windows/SDL_sysmutex_c.h @@ -24,7 +24,7 @@ typedef SDL_Mutex *(*pfnSDL_CreateMutex)(void); typedef void (*pfnSDL_LockMutex)(SDL_Mutex *); -typedef int (*pfnSDL_TryLockMutex)(SDL_Mutex *); +typedef bool (*pfnSDL_TryLockMutex)(SDL_Mutex *); typedef void (*pfnSDL_UnlockMutex)(SDL_Mutex *); typedef void (*pfnSDL_DestroyMutex)(SDL_Mutex *); diff --git a/src/thread/windows/SDL_sysrwlock_srw.c b/src/thread/windows/SDL_sysrwlock_srw.c index ea47ec37be..8506d4cb07 100644 --- a/src/thread/windows/SDL_sysrwlock_srw.c +++ b/src/thread/windows/SDL_sysrwlock_srw.c @@ -59,8 +59,8 @@ typedef SDL_RWLock *(*pfnSDL_CreateRWLock)(void); typedef void (*pfnSDL_DestroyRWLock)(SDL_RWLock *); typedef void (*pfnSDL_LockRWLockForReading)(SDL_RWLock *); typedef void (*pfnSDL_LockRWLockForWriting)(SDL_RWLock *); -typedef int (*pfnSDL_TryLockRWLockForReading)(SDL_RWLock *); -typedef int (*pfnSDL_TryLockRWLockForWriting)(SDL_RWLock *); +typedef bool (*pfnSDL_TryLockRWLockForReading)(SDL_RWLock *); +typedef bool (*pfnSDL_TryLockRWLockForWriting)(SDL_RWLock *); typedef void (*pfnSDL_UnlockRWLock)(SDL_RWLock *); typedef struct SDL_rwlock_impl_t @@ -97,59 +97,48 @@ static SDL_RWLock *SDL_CreateRWLock_srw(void) static void SDL_DestroyRWLock_srw(SDL_RWLock *_rwlock) { SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; - if (rwlock) { - // There are no kernel allocated resources - SDL_free(rwlock); - } + // There are no kernel allocated resources + SDL_free(rwlock); } static void SDL_LockRWLockForReading_srw(SDL_RWLock *_rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; - if (rwlock != NULL) { - pAcquireSRWLockShared(&rwlock->srw); - } + pAcquireSRWLockShared(&rwlock->srw); } static void SDL_LockRWLockForWriting_srw(SDL_RWLock *_rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; - if (rwlock != NULL) { - pAcquireSRWLockExclusive(&rwlock->srw); + pAcquireSRWLockExclusive(&rwlock->srw); + rwlock->write_owner = SDL_GetCurrentThreadID(); +} + +static bool SDL_TryLockRWLockForReading_srw(SDL_RWLock *_rwlock) +{ + SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; + return pTryAcquireSRWLockShared(&rwlock->srw); +} + +static bool SDL_TryLockRWLockForWriting_srw(SDL_RWLock *_rwlock) +{ + SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; + if (pTryAcquireSRWLockExclusive(&rwlock->srw)) { rwlock->write_owner = SDL_GetCurrentThreadID(); + return true; + } else { + return false; } } -static int SDL_TryLockRWLockForReading_srw(SDL_RWLock *_rwlock) -{ - SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; - int retval = 0; - if (rwlock) { - retval = pTryAcquireSRWLockShared(&rwlock->srw) ? 0 : SDL_RWLOCK_TIMEDOUT; - } - return retval; -} - -static int SDL_TryLockRWLockForWriting_srw(SDL_RWLock *_rwlock) -{ - SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; - int retval = 0; - if (rwlock) { - retval = pTryAcquireSRWLockExclusive(&rwlock->srw) ? 0 : SDL_RWLOCK_TIMEDOUT; - } - return retval; -} - static void SDL_UnlockRWLock_srw(SDL_RWLock *_rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { SDL_rwlock_srw *rwlock = (SDL_rwlock_srw *) _rwlock; - if (rwlock != NULL) { - if (rwlock->write_owner == SDL_GetCurrentThreadID()) { - rwlock->write_owner = 0; - pReleaseSRWLockExclusive(&rwlock->srw); - } else { - pReleaseSRWLockShared(&rwlock->srw); - } + if (rwlock->write_owner == SDL_GetCurrentThreadID()) { + rwlock->write_owner = 0; + pReleaseSRWLockExclusive(&rwlock->srw); + } else { + pReleaseSRWLockShared(&rwlock->srw); } } @@ -224,31 +213,39 @@ void SDL_DestroyRWLock(SDL_RWLock *rwlock) void SDL_LockRWLockForReading(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (rwlock != NULL) { + if (rwlock) { SDL_rwlock_impl_active.LockForReading(rwlock); } } void SDL_LockRWLockForWriting(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (rwlock != NULL) { + if (rwlock) { SDL_rwlock_impl_active.LockForWriting(rwlock); } } -int SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) +SDL_bool SDL_TryLockRWLockForReading(SDL_RWLock *rwlock) { - return rwlock ? SDL_rwlock_impl_active.TryLockForReading(rwlock) : 0; + bool result = true; + if (rwlock) { + result = SDL_rwlock_impl_active.TryLockForReading(rwlock); + } + return result; } -int SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) +SDL_bool SDL_TryLockRWLockForWriting(SDL_RWLock *rwlock) { - return rwlock ? SDL_rwlock_impl_active.TryLockForWriting(rwlock) : 0; + bool result = true; + if (rwlock) { + result = SDL_rwlock_impl_active.TryLockForWriting(rwlock); + } + return result; } void SDL_UnlockRWLock(SDL_RWLock *rwlock) SDL_NO_THREAD_SAFETY_ANALYSIS // clang doesn't know about NULL mutexes { - if (rwlock != NULL) { + if (rwlock) { SDL_rwlock_impl_active.Unlock(rwlock); } } diff --git a/src/thread/windows/SDL_syssem.c b/src/thread/windows/SDL_syssem.c index 5e9c7766a7..a87fea961f 100644 --- a/src/thread/windows/SDL_syssem.c +++ b/src/thread/windows/SDL_syssem.c @@ -37,9 +37,9 @@ typedef SDL_Semaphore *(*pfnSDL_CreateSemaphore)(Uint32); typedef void (*pfnSDL_DestroySemaphore)(SDL_Semaphore *); -typedef int (*pfnSDL_WaitSemaphoreTimeoutNS)(SDL_Semaphore *, Sint64); +typedef bool (*pfnSDL_WaitSemaphoreTimeoutNS)(SDL_Semaphore *, Sint64); typedef Uint32 (*pfnSDL_GetSemaphoreValue)(SDL_Semaphore *); -typedef int (*pfnSDL_SignalSemaphore)(SDL_Semaphore *); +typedef void (*pfnSDL_SignalSemaphore)(SDL_Semaphore *); typedef struct SDL_semaphore_impl_t { @@ -47,7 +47,7 @@ typedef struct SDL_semaphore_impl_t pfnSDL_DestroySemaphore Destroy; pfnSDL_WaitSemaphoreTimeoutNS WaitTimeoutNS; pfnSDL_GetSemaphoreValue Value; - pfnSDL_SignalSemaphore Post; + pfnSDL_SignalSemaphore Signal; } SDL_sem_impl_t; // Implementation will be chosen at runtime based on available Kernel features @@ -94,7 +94,7 @@ static void SDL_DestroySemaphore_atom(SDL_Semaphore *sem) SDL_free(sem); } -static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS) +static bool SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS) { SDL_sem_atom *sem = (SDL_sem_atom *)_sem; LONG count; @@ -103,33 +103,34 @@ static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS DWORD timeout_eff; if (!sem) { - return SDL_InvalidParamError("sem"); + return true; } if (timeoutNS == 0) { count = sem->count; if (count == 0) { - return SDL_MUTEX_TIMEDOUT; + return false; } if (InterlockedCompareExchange(&sem->count, count - 1, count) == count) { - return 0; + return true; } - return SDL_MUTEX_TIMEDOUT; + return false; } + if (timeoutNS < 0) { for (;;) { count = sem->count; while (count == 0) { - if (pWaitOnAddress(&sem->count, &count, sizeof(sem->count), INFINITE) == FALSE) { - return SDL_SetError("WaitOnAddress() failed"); + if (!pWaitOnAddress(&sem->count, &count, sizeof(sem->count), INFINITE)) { + return false; } count = sem->count; } if (InterlockedCompareExchange(&sem->count, count - 1, count) == count) { - return 0; + return true; } } } @@ -149,13 +150,10 @@ static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS if (deadline > now) { timeout_eff = (DWORD)SDL_NS_TO_MS(deadline - now); } else { - return SDL_MUTEX_TIMEDOUT; + return false; } - if (pWaitOnAddress(&sem->count, &count, sizeof(count), timeout_eff) == FALSE) { - if (GetLastError() == ERROR_TIMEOUT) { - return SDL_MUTEX_TIMEDOUT; - } - return SDL_SetError("WaitOnAddress() failed"); + if (!pWaitOnAddress(&sem->count, &count, sizeof(count), timeout_eff)) { + return false; } count = sem->count; } @@ -163,7 +161,7 @@ static int SDL_WaitSemaphoreTimeoutNS_atom(SDL_Semaphore *_sem, Sint64 timeoutNS // Actually the semaphore is only consumed if this succeeds // If it doesn't we need to do everything again if (InterlockedCompareExchange(&sem->count, count - 1, count) == count) { - return 0; + return true; } } } @@ -173,25 +171,22 @@ static Uint32 SDL_GetSemaphoreValue_atom(SDL_Semaphore *_sem) SDL_sem_atom *sem = (SDL_sem_atom *)_sem; if (!sem) { - SDL_InvalidParamError("sem"); return 0; } return (Uint32)sem->count; } -static int SDL_SignalSemaphore_atom(SDL_Semaphore *_sem) +static void SDL_SignalSemaphore_atom(SDL_Semaphore *_sem) { SDL_sem_atom *sem = (SDL_sem_atom *)_sem; if (!sem) { - return SDL_InvalidParamError("sem"); + return; } InterlockedIncrement(&sem->count); pWakeByAddressSingle(&sem->count); - - return 0; } static const SDL_sem_impl_t SDL_sem_impl_atom = { @@ -251,14 +246,13 @@ static void SDL_DestroySemaphore_kern(SDL_Semaphore *_sem) } } -static int SDL_WaitSemaphoreTimeoutNS_kern(SDL_Semaphore *_sem, Sint64 timeoutNS) +static bool SDL_WaitSemaphoreTimeoutNS_kern(SDL_Semaphore *_sem, Sint64 timeoutNS) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; - int retval; DWORD dwMilliseconds; if (!sem) { - return SDL_InvalidParamError("sem"); + return SDL_TRUE; } if (timeoutNS < 0) { @@ -269,16 +263,10 @@ static int SDL_WaitSemaphoreTimeoutNS_kern(SDL_Semaphore *_sem, Sint64 timeoutNS switch (WaitForSingleObjectEx(sem->id, dwMilliseconds, FALSE)) { case WAIT_OBJECT_0: InterlockedDecrement(&sem->count); - retval = 0; - break; - case WAIT_TIMEOUT: - retval = SDL_MUTEX_TIMEDOUT; - break; + return true; default: - retval = SDL_SetError("WaitForSingleObject() failed"); - break; + return false; } - return retval; } // Returns the current count of the semaphore @@ -286,18 +274,19 @@ static Uint32 SDL_GetSemaphoreValue_kern(SDL_Semaphore *_sem) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; if (!sem) { - SDL_InvalidParamError("sem"); return 0; } return (Uint32)sem->count; } -static int SDL_SignalSemaphore_kern(SDL_Semaphore *_sem) +static void SDL_SignalSemaphore_kern(SDL_Semaphore *_sem) { SDL_sem_kern *sem = (SDL_sem_kern *)_sem; + if (!sem) { - return SDL_InvalidParamError("sem"); + return; } + /* Increase the counter in the first place, because * after a successful release the semaphore may * immediately get destroyed by another thread which @@ -306,9 +295,7 @@ static int SDL_SignalSemaphore_kern(SDL_Semaphore *_sem) InterlockedIncrement(&sem->count); if (ReleaseSemaphore(sem->id, 1, NULL) == FALSE) { InterlockedDecrement(&sem->count); // restore - return SDL_SetError("ReleaseSemaphore() failed"); } - return 0; } static const SDL_sem_impl_t SDL_sem_impl_kern = { @@ -366,7 +353,7 @@ void SDL_DestroySemaphore(SDL_Semaphore *sem) SDL_sem_impl_active.Destroy(sem); } -int SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) +SDL_bool SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS) { return SDL_sem_impl_active.WaitTimeoutNS(sem, timeoutNS); } @@ -376,9 +363,9 @@ Uint32 SDL_GetSemaphoreValue(SDL_Semaphore *sem) return SDL_sem_impl_active.Value(sem); } -int SDL_SignalSemaphore(SDL_Semaphore *sem) +void SDL_SignalSemaphore(SDL_Semaphore *sem) { - return SDL_sem_impl_active.Post(sem); + SDL_sem_impl_active.Signal(sem); } #endif // SDL_THREAD_WINDOWS diff --git a/src/thread/windows/SDL_systhread.c b/src/thread/windows/SDL_systhread.c index 446efc7d59..92cea5d780 100644 --- a/src/thread/windows/SDL_systhread.c +++ b/src/thread/windows/SDL_systhread.c @@ -58,9 +58,9 @@ static unsigned __stdcall MINGW32_FORCEALIGN RunThreadViaBeginThreadEx(void *dat return (unsigned)RunThread(data); } -int SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer vpfnBeginThread, - SDL_FunctionPointer vpfnEndThread) +bool SDL_SYS_CreateThread(SDL_Thread *thread, + SDL_FunctionPointer vpfnBeginThread, + SDL_FunctionPointer vpfnEndThread) { SDL_BeginThreadExCallback pfnBeginThread = (SDL_BeginThreadExCallback) vpfnBeginThread; @@ -84,7 +84,7 @@ int SDL_SYS_CreateThread(SDL_Thread *thread, if (!thread->handle) { return SDL_SetError("Not enough resources to create thread"); } - return 0; + return true; } #pragma pack(push, 8) @@ -161,7 +161,7 @@ SDL_ThreadID SDL_GetCurrentThreadID(void) return (SDL_ThreadID)GetCurrentThreadId(); } -int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) +bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) { int value; @@ -177,7 +177,7 @@ int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) if (!SetThreadPriority(GetCurrentThread(), value)) { return WIN_SetError("SetThreadPriority()"); } - return 0; + return true; } void SDL_SYS_WaitThread(SDL_Thread *thread) diff --git a/src/thread/windows/SDL_systls.c b/src/thread/windows/SDL_systls.c index 45514c004b..083008e52e 100644 --- a/src/thread/windows/SDL_systls.c +++ b/src/thread/windows/SDL_systls.c @@ -65,7 +65,7 @@ SDL_TLSData *SDL_SYS_GetTLSData(void) return NULL; } -int SDL_SYS_SetTLSData(SDL_TLSData *data) +bool SDL_SYS_SetTLSData(SDL_TLSData *data) { if (generic_local_storage) { return SDL_Generic_SetTLSData(data); @@ -74,7 +74,7 @@ int SDL_SYS_SetTLSData(SDL_TLSData *data) if (!TlsSetValue(thread_local_storage, data)) { return WIN_SetError("TlsSetValue()"); } - return 0; + return true; } void SDL_SYS_QuitTLSData(void) diff --git a/src/time/SDL_time.c b/src/time/SDL_time.c index 9ac252b11d..2e63efc26e 100644 --- a/src/time/SDL_time.c +++ b/src/time/SDL_time.c @@ -57,7 +57,7 @@ Sint64 SDL_CivilToDays(int year, int month, int day, int *day_of_week, int *day_ return z; } -int SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat) +SDL_bool SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat *timeFormat) { // Default to ISO 8061 date format, as it is unambiguous, and 24 hour time. if (dateFormat) { @@ -69,7 +69,7 @@ int SDL_GetDateTimeLocalePreferences(SDL_DateFormat *dateFormat, SDL_TimeFormat SDL_GetSystemTimeLocalePreferences(dateFormat, timeFormat); - return 0; + return true; } int SDL_GetDaysInMonth(int year, int month) @@ -79,7 +79,8 @@ int SDL_GetDaysInMonth(int year, int month) }; if (month < 1 || month > 12) { - return SDL_SetError("Month out of range [1-12], requested: %i", month); + SDL_SetError("Month out of range [1-12], requested: %i", month); + return -1; } int days = DAYS_IN_MONTH[month - 1]; @@ -100,10 +101,12 @@ int SDL_GetDayOfYear(int year, int month, int day) int dayOfYear; if (month < 1 || month > 12) { - return SDL_SetError("Month out of range [1-12], requested: %i", month); + SDL_SetError("Month out of range [1-12], requested: %i", month); + return -1; } if (day < 1 || day > SDL_GetDaysInMonth(year, month)) { - return SDL_SetError("Day out of range [1-%i], requested: %i", SDL_GetDaysInMonth(year, month), month); + SDL_SetError("Day out of range [1-%i], requested: %i", SDL_GetDaysInMonth(year, month), month); + return -1; } SDL_CivilToDays(year, month, day, NULL, &dayOfYear); @@ -115,10 +118,12 @@ int SDL_GetDayOfWeek(int year, int month, int day) int dayOfWeek; if (month < 1 || month > 12) { - return SDL_SetError("Month out of range [1-12], requested: %i", month); + SDL_SetError("Month out of range [1-12], requested: %i", month); + return -1; } if (day < 1 || day > SDL_GetDaysInMonth(year, month)) { - return SDL_SetError("Day out of range [1-%i], requested: %i", SDL_GetDaysInMonth(year, month), month); + SDL_SetError("Day out of range [1-%i], requested: %i", SDL_GetDaysInMonth(year, month), month); + return -1; } SDL_CivilToDays(year, month, day, &dayOfWeek, NULL); @@ -157,11 +162,11 @@ static bool SDL_DateTimeIsValid(const SDL_DateTime *dt) return true; } -int SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks) +SDL_bool SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks) { static const Sint64 max_seconds = SDL_NS_TO_SECONDS(SDL_MAX_TIME) - 1; static const Sint64 min_seconds = SDL_NS_TO_SECONDS(SDL_MIN_TIME) + 1; - int ret = 0; + bool result = true; if (!dt) { return SDL_InvalidParamError("dt"); @@ -171,18 +176,18 @@ int SDL_DateTimeToTime(const SDL_DateTime *dt, SDL_Time *ticks) } if (!SDL_DateTimeIsValid(dt)) { // The validation function sets the error string. - return -1; + return false; } *ticks = SDL_CivilToDays(dt->year, dt->month, dt->day, NULL, NULL) * SDL_SECONDS_PER_DAY; *ticks += (((dt->hour * 60) + dt->minute) * 60) + dt->second - dt->utc_offset; if (*ticks > max_seconds || *ticks < min_seconds) { *ticks = SDL_clamp(*ticks, min_seconds, max_seconds); - ret = SDL_SetError("Date out of range for SDL_Time representation; SDL_Time value clamped"); + result = SDL_SetError("Date out of range for SDL_Time representation; SDL_Time value clamped"); } *ticks = SDL_SECONDS_TO_NS(*ticks) + dt->nanosecond; - return ret; + return result; } #define DELTA_EPOCH_1601_100NS (11644473600ll * 10000000ll) // [100 ns] (100 ns units between 1601-01-01 and 1970-01-01, 11644473600 seconds) diff --git a/src/time/n3ds/SDL_systime.c b/src/time/n3ds/SDL_systime.c index 06d01e3cf3..19b50afa5d 100644 --- a/src/time/n3ds/SDL_systime.c +++ b/src/time/n3ds/SDL_systime.c @@ -106,7 +106,7 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf) } } -int SDL_GetCurrentTime(SDL_Time *ticks) +SDL_bool SDL_GetCurrentTime(SDL_Time *ticks) { if (!ticks) { return SDL_InvalidParamError("ticks"); @@ -118,10 +118,10 @@ int SDL_GetCurrentTime(SDL_Time *ticks) *ticks = SDL_MS_TO_NS(ndsTicks - DELTA_EPOCH_1900_OFFSET_MS); - return 0; + return true; } -int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) +SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) { if (!dt) { return SDL_InvalidParamError("dt"); @@ -141,7 +141,7 @@ int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) SDL_CivilToDays(dt->year, dt->month, dt->day, &dt->day_of_week, NULL); - return 0; + return true; } #endif // SDL_TIME_N3DS diff --git a/src/time/ps2/SDL_systime.c b/src/time/ps2/SDL_systime.c index 892229c7a8..e7786f9945 100644 --- a/src/time/ps2/SDL_systime.c +++ b/src/time/ps2/SDL_systime.c @@ -32,7 +32,7 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf) { } -int SDL_GetCurrentTime(SDL_Time *ticks) +SDL_bool SDL_GetCurrentTime(SDL_Time *ticks) { if (!ticks) { return SDL_InvalidParamError("ticks"); @@ -40,10 +40,10 @@ int SDL_GetCurrentTime(SDL_Time *ticks) *ticks = 0; - return 0; + return true; } -int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) +SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) { if (!dt) { return SDL_InvalidParamError("dt"); @@ -59,7 +59,7 @@ int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) dt->day_of_week = 4; dt->utc_offset = 0; - return 0; + return true; } #endif // SDL_TIME_PS2 diff --git a/src/time/psp/SDL_systime.c b/src/time/psp/SDL_systime.c index d76138bcf1..0b51ebb87a 100644 --- a/src/time/psp/SDL_systime.c +++ b/src/time/psp/SDL_systime.c @@ -65,7 +65,7 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf) } } -int SDL_GetCurrentTime(SDL_Time *ticks) +SDL_bool SDL_GetCurrentTime(SDL_Time *ticks) { u64 sceTicks; @@ -87,13 +87,13 @@ int SDL_GetCurrentTime(SDL_Time *ticks) *ticks = (SDL_Time)(sceTicks - epoch_offset) * div; - return 0; + return true; } return SDL_SetError("Failed to retrieve system time (%i)", ret); } -int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) +SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) { ScePspDateTime t; u64 local; @@ -127,7 +127,7 @@ int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) SDL_CivilToDays(dt->year, dt->month, dt->day, &dt->day_of_week, NULL); - return 0; + return true; } } diff --git a/src/time/unix/SDL_systime.c b/src/time/unix/SDL_systime.c index 09461d6403..0ed2107f56 100644 --- a/src/time/unix/SDL_systime.c +++ b/src/time/unix/SDL_systime.c @@ -98,7 +98,7 @@ found_date: #endif } -int SDL_GetCurrentTime(SDL_Time *ticks) +SDL_bool SDL_GetCurrentTime(SDL_Time *ticks) { if (!ticks) { return SDL_InvalidParamError("ticks"); @@ -109,7 +109,7 @@ int SDL_GetCurrentTime(SDL_Time *ticks) if (clock_gettime(CLOCK_REALTIME, &tp) == 0) { //tp.tv_sec = SDL_min(tp.tv_sec, SDL_NS_TO_SECONDS(SDL_MAX_TIME) - 1); *ticks = SDL_SECONDS_TO_NS(tp.tv_sec) + tp.tv_nsec; - return 0; + return true; } SDL_SetError("Failed to retrieve system time (%i)", errno); @@ -129,7 +129,7 @@ int SDL_GetCurrentTime(SDL_Time *ticks) mach_port_deallocate(mach_task_self(), cclock); if (!ret) { - return 0; + return true; } } @@ -141,16 +141,16 @@ int SDL_GetCurrentTime(SDL_Time *ticks) if (gettimeofday(&tv, NULL) == 0) { tv.tv_sec = SDL_min(tv.tv_sec, SDL_NS_TO_SECONDS(SDL_MAX_TIME) - 1); *ticks = SDL_SECONDS_TO_NS(tv.tv_sec) + SDL_US_TO_NS(tv.tv_usec); - return 0; + return true; } SDL_SetError("Failed to retrieve system time (%i)", errno); #endif - return -1; + return false; } -int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) +SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) { #if defined (HAVE_GMTIME_R) || defined(HAVE_LOCALTIME_R) struct tm tm_storage; @@ -188,7 +188,7 @@ int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) dt->day_of_week = tm->tm_wday; dt->utc_offset = (int)tm->tm_gmtoff; - return 0; + return true; } return SDL_SetError("SDL_DateTime conversion failed (%i)", errno); diff --git a/src/time/vita/SDL_systime.c b/src/time/vita/SDL_systime.c index 15886e1c39..c5ec2eff90 100644 --- a/src/time/vita/SDL_systime.c +++ b/src/time/vita/SDL_systime.c @@ -71,7 +71,7 @@ void SDL_GetSystemTimeLocalePreferences(SDL_DateFormat *df, SDL_TimeFormat *tf) sceAppUtilShutdown(); } -int SDL_GetCurrentTime(SDL_Time *ticks) +SDL_bool SDL_GetCurrentTime(SDL_Time *ticks) { SceRtcTick sceTicks; @@ -92,13 +92,13 @@ int SDL_GetCurrentTime(SDL_Time *ticks) sceTicks.tick = SDL_clamp(sceTicks.tick, scetime_min, scetime_max); *ticks = (SDL_Time)(sceTicks.tick - epoch_offset) * div; - return 0; + return true; } return SDL_SetError("Failed to retrieve system time (%i)", ret); } -int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) +SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) { SceDateTime t; SceRtcTick sceTicks, sceLocalTicks; @@ -132,7 +132,7 @@ int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) SDL_CivilToDays(dt->year, dt->month, dt->day, &dt->day_of_week, NULL); - return 0; + return true; } } diff --git a/src/time/windows/SDL_systime.c b/src/time/windows/SDL_systime.c index e889ca5c23..3070935e8b 100644 --- a/src/time/windows/SDL_systime.c +++ b/src/time/windows/SDL_systime.c @@ -75,7 +75,7 @@ found_date: } } -int SDL_GetCurrentTime(SDL_Time *ticks) +SDL_bool SDL_GetCurrentTime(SDL_Time *ticks) { FILETIME ft; @@ -109,10 +109,10 @@ int SDL_GetCurrentTime(SDL_Time *ticks) *ticks = SDL_TimeFromWindows(ft.dwLowDateTime, ft.dwHighDateTime); - return 0; + return true; } -int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) +SDL_bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) { FILETIME ft, local_ft; SYSTEMTIME utc_st, local_st; @@ -151,7 +151,7 @@ int SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, SDL_bool localTime) dt->nanosecond = ticks % SDL_NS_PER_SECOND; dt->day_of_week = st->wDayOfWeek; - return 0; + return true; } } diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 0423814d0c..5ff15ab554 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -205,7 +205,7 @@ static int SDLCALL SDL_TimerThread(void *_data) return 0; } -int SDL_InitTimers(void) +bool SDL_InitTimers(void) { SDL_TimerData *data = &SDL_timer_data; @@ -213,13 +213,13 @@ int SDL_InitTimers(void) const char *name = "SDLTimer"; data->timermap_lock = SDL_CreateMutex(); if (!data->timermap_lock) { - return -1; + return false; } data->sem = SDL_CreateSemaphore(0); if (!data->sem) { SDL_DestroyMutex(data->timermap_lock); - return -1; + return false; } SDL_AtomicSet(&data->active, 1); @@ -228,10 +228,10 @@ int SDL_InitTimers(void) data->thread = SDL_CreateThread(SDL_TimerThread, name, data); if (!data->thread) { SDL_QuitTimers(); - return -1; + return false; } } - return 0; + return true; } void SDL_QuitTimers(void) @@ -286,7 +286,7 @@ static SDL_TimerID SDL_CreateTimer(Uint64 interval, SDL_TimerCallback callback_m SDL_LockSpinlock(&data->lock); if (!SDL_AtomicGet(&data->active)) { - if (SDL_InitTimers() < 0) { + if (!SDL_InitTimers()) { SDL_UnlockSpinlock(&data->lock); return 0; } @@ -349,7 +349,7 @@ SDL_TimerID SDL_AddTimerNS(Uint64 interval, SDL_NSTimerCallback callback, void * return SDL_CreateTimer(interval, NULL, callback, userdata); } -int SDL_RemoveTimer(SDL_TimerID id) +SDL_bool SDL_RemoveTimer(SDL_TimerID id) { SDL_TimerData *data = &SDL_timer_data; SDL_TimerMap *prev, *entry; @@ -382,7 +382,7 @@ int SDL_RemoveTimer(SDL_TimerID id) SDL_free(entry); } if (canceled) { - return 0; + return true; } else { return SDL_SetError("Timer not found"); } @@ -426,9 +426,9 @@ static void SDL_Emscripten_TimerHelper(void *userdata) } } -int SDL_InitTimers(void) +bool SDL_InitTimers(void) { - return 0; + return true; } void SDL_QuitTimers(void) @@ -483,7 +483,7 @@ SDL_TimerID SDL_AddTimerNS(Uint64 interval, SDL_NSTimerCallback callback, void * return SDL_CreateTimer(interval, NULL, callback, userdata); } -int SDL_RemoveTimer(SDL_TimerID id) +SDL_bool SDL_RemoveTimer(SDL_TimerID id) { SDL_TimerData *data = &SDL_timer_data; SDL_TimerMap *prev, *entry; @@ -508,7 +508,7 @@ int SDL_RemoveTimer(SDL_TimerID id) if (entry) { emscripten_clear_timeout(entry->timeoutID); SDL_free(entry); - return 0; + return true; } else { return SDL_SetError("Timer not found"); } @@ -562,14 +562,6 @@ static void SDLCALL SDL_TimerResolutionChanged(void *userdata, const char *name, } } -static Uint32 CalculateGCD(Uint32 a, Uint32 b) -{ - if (b == 0) { - return a; - } - return CalculateGCD(b, (a % b)); -} - void SDL_InitTicks(void) { Uint64 tick_freq; @@ -587,11 +579,11 @@ void SDL_InitTicks(void) tick_freq = SDL_GetPerformanceFrequency(); SDL_assert(tick_freq > 0 && tick_freq <= (Uint64)SDL_MAX_UINT32); - gcd = CalculateGCD(SDL_NS_PER_SECOND, (Uint32)tick_freq); + gcd = SDL_CalculateGCD(SDL_NS_PER_SECOND, (Uint32)tick_freq); tick_numerator_ns = (SDL_NS_PER_SECOND / gcd); tick_denominator_ns = (Uint32)(tick_freq / gcd); - gcd = CalculateGCD(SDL_MS_PER_SECOND, (Uint32)tick_freq); + gcd = SDL_CalculateGCD(SDL_MS_PER_SECOND, (Uint32)tick_freq); tick_numerator_ms = (SDL_MS_PER_SECOND / gcd); tick_denominator_ms = (Uint32)(tick_freq / gcd); diff --git a/src/timer/SDL_timer_c.h b/src/timer/SDL_timer_c.h index 6a461d448e..252de76ecb 100644 --- a/src/timer/SDL_timer_c.h +++ b/src/timer/SDL_timer_c.h @@ -31,7 +31,7 @@ extern void SDL_InitTicks(void); extern void SDL_QuitTicks(void); -extern int SDL_InitTimers(void); +extern bool SDL_InitTimers(void); extern void SDL_QuitTimers(void); extern void SDL_SYS_DelayNS(Uint64 ns); diff --git a/src/video/SDL_RLEaccel.c b/src/video/SDL_RLEaccel.c index 78864f370a..904ca30d91 100644 --- a/src/video/SDL_RLEaccel.c +++ b/src/video/SDL_RLEaccel.c @@ -442,8 +442,8 @@ static void RLEClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, #undef RLECLIPBLIT // blit a colorkeyed RLE surface -static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect, - SDL_Surface *surf_dst, const SDL_Rect *dstrect) +static bool SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect, + SDL_Surface *surf_dst, const SDL_Rect *dstrect) { Uint8 *dstbuf; Uint8 *srcbuf; @@ -453,8 +453,8 @@ static int SDLCALL SDL_RLEBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect, // Lock the destination if necessary if (SDL_MUSTLOCK(surf_dst)) { - if (SDL_LockSurface(surf_dst) < 0) { - return -1; + if (!SDL_LockSurface(surf_dst)) { + return false; } } @@ -548,7 +548,7 @@ done: if (SDL_MUSTLOCK(surf_dst)) { SDL_UnlockSurface(surf_dst); } - return 0; + return true; } #undef OPAQUE_BLIT @@ -697,8 +697,8 @@ static void RLEAlphaClipBlit(int w, Uint8 *srcbuf, SDL_Surface *surf_dst, } // blit a pixel-alpha RLE surface -static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect, - SDL_Surface *surf_dst, const SDL_Rect *dstrect) +static bool SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcrect, + SDL_Surface *surf_dst, const SDL_Rect *dstrect) { int x, y; int w = surf_src->w; @@ -707,8 +707,8 @@ static int SDLCALL SDL_RLEAlphaBlit(SDL_Surface *surf_src, const SDL_Rect *srcre // Lock the destination if necessary if (SDL_MUSTLOCK(surf_dst)) { - if (SDL_LockSurface(surf_dst) < 0) { - return -1; + if (!SDL_LockSurface(surf_dst)) { + return false; } } @@ -849,7 +849,7 @@ done: if (SDL_MUSTLOCK(surf_dst)) { SDL_UnlockSurface(surf_dst); } - return 0; + return true; } /* @@ -988,7 +988,7 @@ static int uncopy_32(Uint32 *dst, const void *src, int n, ((unsigned)((((pixel)&fmt->Amask) >> fmt->Ashift) - 1U) < 254U) // convert surface to be quickly alpha-blittable onto dest, if possible -static int RLEAlphaSurface(SDL_Surface *surface) +static bool RLEAlphaSurface(SDL_Surface *surface) { SDL_Surface *dest; const SDL_PixelFormatDetails *df; @@ -1004,11 +1004,11 @@ static int RLEAlphaSurface(SDL_Surface *surface) dest = surface->internal->map.info.dst_surface; if (!dest) { - return -1; + return false; } df = dest->internal->format; if (surface->internal->format->bits_per_pixel != 32) { - return -1; // only 32bpp source supported + return false; // only 32bpp source supported } /* find out whether the destination is one we support, @@ -1023,7 +1023,7 @@ static int RLEAlphaSurface(SDL_Surface *surface) copy_opaque = copy_opaque_16; copy_transl = copy_transl_565; } else { - return -1; + return false; } break; case 0x7fff: @@ -1031,11 +1031,11 @@ static int RLEAlphaSurface(SDL_Surface *surface) copy_opaque = copy_opaque_16; copy_transl = copy_transl_555; } else { - return -1; + return false; } break; default: - return -1; + return false; } max_opaque_run = 255; // runs stored as bytes @@ -1045,7 +1045,7 @@ static int RLEAlphaSurface(SDL_Surface *surface) break; case 4: if (masksum != 0x00ffffff) { - return -1; // requires unused high byte + return false; // requires unused high byte } copy_opaque = copy_32; copy_transl = copy_32; @@ -1055,13 +1055,13 @@ static int RLEAlphaSurface(SDL_Surface *surface) maxsize = surface->h * 2 * 4 * (surface->w + 1) + 4; break; default: - return -1; // anything else unsupported right now + return false; // anything else unsupported right now } maxsize += sizeof(SDL_PixelFormat); rlebuf = (Uint8 *)SDL_malloc(maxsize); if (!rlebuf) { - return -1; + return false; } // save the destination format so we can undo the encoding later *(SDL_PixelFormat *)rlebuf = df->format; @@ -1197,7 +1197,7 @@ static int RLEAlphaSurface(SDL_Surface *surface) surface->internal->map.data = p; } - return 0; + return true; } static Uint32 getpix_8(const Uint8 *srcbuf) @@ -1230,7 +1230,7 @@ static const getpix_func getpixes[4] = { getpix_8, getpix_16, getpix_24, getpix_32 }; -static int RLEColorkeySurface(SDL_Surface *surface) +static bool RLEColorkeySurface(SDL_Surface *surface) { Uint8 *rlebuf, *dst; int maxn; @@ -1260,12 +1260,12 @@ static int RLEColorkeySurface(SDL_Surface *surface) break; default: - return -1; + return false; } rlebuf = (Uint8 *)SDL_malloc(maxsize); if (!rlebuf) { - return -1; + return false; } // Set up the conversion @@ -1365,10 +1365,10 @@ static int RLEColorkeySurface(SDL_Surface *surface) surface->internal->map.data = p; } - return 0; + return true; } -int SDL_RLESurface(SDL_Surface *surface) +bool SDL_RLESurface(SDL_Surface *surface) { int flags; @@ -1379,12 +1379,12 @@ int SDL_RLESurface(SDL_Surface *surface) // We don't support RLE encoding of bitmaps if (SDL_BITSPERPIXEL(surface->format) < 8) { - return -1; + return false; } // Make sure the pixels are available if (!surface->pixels) { - return -1; + return false; } flags = surface->internal->map.info.flags; @@ -1394,7 +1394,7 @@ int SDL_RLESurface(SDL_Surface *surface) // ok } else { // If we don't have colorkey or blending, nothing to do... - return -1; + return false; } // Pass on combinations not supported @@ -1402,22 +1402,22 @@ int SDL_RLESurface(SDL_Surface *surface) ((flags & SDL_COPY_MODULATE_ALPHA) && SDL_ISPIXELFORMAT_ALPHA(surface->format)) || (flags & (SDL_COPY_BLEND_PREMULTIPLIED | SDL_COPY_ADD | SDL_COPY_ADD_PREMULTIPLIED | SDL_COPY_MOD | SDL_COPY_MUL)) || (flags & SDL_COPY_NEAREST)) { - return -1; + return false; } // Encode and set up the blit if (!SDL_ISPIXELFORMAT_ALPHA(surface->format) || !(flags & SDL_COPY_BLEND)) { if (!surface->internal->map.identity) { - return -1; + return false; } - if (RLEColorkeySurface(surface) < 0) { - return -1; + if (!RLEColorkeySurface(surface)) { + return false; } surface->internal->map.blit = SDL_RLEBlit; surface->internal->map.info.flags |= SDL_COPY_RLE_COLORKEY; } else { - if (RLEAlphaSurface(surface) < 0) { - return -1; + if (!RLEAlphaSurface(surface)) { + return false; } surface->internal->map.blit = SDL_RLEAlphaBlit; surface->internal->map.info.flags |= SDL_COPY_RLE_ALPHAKEY; @@ -1426,7 +1426,7 @@ int SDL_RLESurface(SDL_Surface *surface) // The surface is now accelerated surface->internal->flags |= SDL_INTERNAL_SURFACE_RLEACCEL; - return 0; + return true; } /* diff --git a/src/video/SDL_RLEaccel_c.h b/src/video/SDL_RLEaccel_c.h index 7f4c8adfe9..8b9ff36dd8 100644 --- a/src/video/SDL_RLEaccel_c.h +++ b/src/video/SDL_RLEaccel_c.h @@ -26,7 +26,7 @@ // Useful functions and variables from SDL_RLEaccel.c -extern int SDL_RLESurface(SDL_Surface *surface); +extern bool SDL_RLESurface(SDL_Surface *surface); extern void SDL_UnRLESurface(SDL_Surface *surface, bool recode); #endif // SDL_RLEaccel_c_h_ diff --git a/src/video/SDL_blit.c b/src/video/SDL_blit.c index a90f571c20..c853accf91 100644 --- a/src/video/SDL_blit.c +++ b/src/video/SDL_blit.c @@ -29,21 +29,21 @@ #include "SDL_pixels_c.h" // The general purpose software blit routine -static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect, +static bool SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect) { - int okay; + bool okay; int src_locked; int dst_locked; // Everything is okay at the beginning... - okay = 1; + okay = true; // Lock the destination if it's in hardware dst_locked = 0; if (SDL_MUSTLOCK(dst)) { - if (SDL_LockSurface(dst) < 0) { - okay = 0; + if (!SDL_LockSurface(dst)) { + okay = false; } else { dst_locked = 1; } @@ -51,8 +51,8 @@ static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect, // Lock the source if it's in hardware src_locked = 0; if (SDL_MUSTLOCK(src)) { - if (SDL_LockSurface(src) < 0) { - okay = 0; + if (!SDL_LockSurface(src)) { + okay = false; } else { src_locked = 1; } @@ -94,7 +94,7 @@ static int SDLCALL SDL_SoftBlit(SDL_Surface *src, const SDL_Rect *srcrect, SDL_UnlockSurface(src); } // Blit is done! - return okay ? 0 : -1; + return okay; } #if SDL_HAVE_BLIT_AUTO @@ -176,7 +176,7 @@ static SDL_BlitFunc SDL_ChooseBlitFunc(SDL_PixelFormat src_format, SDL_PixelForm #endif // SDL_HAVE_BLIT_AUTO // Figure out which of many blit routines to set up on a surface -int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst) +bool SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst) { SDL_BlitFunc blit = NULL; SDL_BlitMap *map = &surface->internal->map; @@ -207,8 +207,8 @@ int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst) #if SDL_HAVE_RLE // See if we can do RLE acceleration if (map->info.flags & SDL_COPY_RLE_DESIRED) { - if (SDL_RLESurface(surface) == 0) { - return 0; + if (SDL_RLESurface(surface)) { + return true; } } #endif @@ -286,5 +286,5 @@ int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst) return SDL_SetError("Blit combination not supported"); } - return 0; + return true; } diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h index 7fd3f0aead..8da70f151e 100644 --- a/src/video/SDL_blit.h +++ b/src/video/SDL_blit.h @@ -89,7 +89,7 @@ typedef struct SDL_BlitFunc func; } SDL_BlitFuncEntry; -typedef int (SDLCALL *SDL_Blit) (struct SDL_Surface *src, const SDL_Rect *srcrect, struct SDL_Surface *dst, const SDL_Rect *dstrect); +typedef bool (SDLCALL *SDL_Blit) (struct SDL_Surface *src, const SDL_Rect *srcrect, struct SDL_Surface *dst, const SDL_Rect *dstrect); // Blit mapping definition typedef struct SDL_BlitMap @@ -106,7 +106,7 @@ typedef struct SDL_BlitMap } SDL_BlitMap; // Functions found in SDL_blit.c -extern int SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst); +extern bool SDL_CalculateBlit(SDL_Surface *surface, SDL_Surface *dst); /* Functions found in SDL_blit_*.c */ extern SDL_BlitFunc SDL_CalculateBlit0(SDL_Surface *surface); diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index da00528ae6..c7d66d7c2e 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -591,7 +591,7 @@ SDL_Surface *SDL_LoadBMP(const char *file) return SDL_LoadBMP_IO(SDL_IOFromFile(file, "rb"), 1); } -int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio) +SDL_bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio) { bool was_error = true; Sint64 fp_offset, new_offset; @@ -696,7 +696,7 @@ int SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, SDL_bool closeio) saveLegacyBMP = SDL_GetHintBoolean(SDL_HINT_BMP_SAVE_LEGACY_FORMAT, false); } - if (SDL_LockSurface(intermediate_surface) == 0) { + if (SDL_LockSurface(intermediate_surface)) { const size_t bw = intermediate_surface->w * intermediate_surface->internal->format->bytes_per_pixel; // Set the BMP file header values @@ -860,17 +860,17 @@ done: SDL_DestroySurface(intermediate_surface); } if (closeio && dst) { - if (SDL_CloseIO(dst) < 0) { + if (!SDL_CloseIO(dst)) { was_error = true; } } if (was_error) { - return -1; + return false; } - return 0; + return true; } -int SDL_SaveBMP(SDL_Surface *surface, const char *file) +SDL_bool SDL_SaveBMP(SDL_Surface *surface, const char *file) { - return SDL_SaveBMP_IO(surface, SDL_IOFromFile(file, "wb"), 1); + return SDL_SaveBMP_IO(surface, SDL_IOFromFile(file, "wb"), true); } diff --git a/src/video/SDL_clipboard.c b/src/video/SDL_clipboard.c index bd7a5ee0ac..b67bc51aa1 100644 --- a/src/video/SDL_clipboard.c +++ b/src/video/SDL_clipboard.c @@ -53,7 +53,7 @@ void SDL_CancelClipboardData(Uint32 sequence) _this->clipboard_userdata = NULL; } -int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types) +SDL_bool SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanupCallback cleanup, void *userdata, const char **mime_types, size_t num_mime_types) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); size_t i; @@ -70,7 +70,7 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu if (!callback && !_this->clipboard_callback) { // Nothing to do, don't modify the system clipboard - return 0; + return true; } SDL_CancelClipboardData(_this->clipboard_sequence); @@ -97,14 +97,14 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu } if (num_allocated < num_mime_types) { SDL_ClearClipboardData(); - return -1; + return false; } _this->num_clipboard_mime_types = num_mime_types; } if (_this->SetClipboardData) { - if (_this->SetClipboardData(_this) < 0) { - return -1; + if (!_this->SetClipboardData(_this)) { + return false; } } else if (_this->SetClipboardText) { char *text = NULL; @@ -118,9 +118,9 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu text = (char *)SDL_malloc(size + 1); SDL_memcpy(text, data, size); text[size] = '\0'; - if (_this->SetClipboardText(_this, text) < 0) { + if (!_this->SetClipboardText(_this, text)) { SDL_free(text); - return -1; + return false; } break; } @@ -129,17 +129,17 @@ int SDL_SetClipboardData(SDL_ClipboardDataCallback callback, SDL_ClipboardCleanu if (text) { SDL_free(text); } else { - if (_this->SetClipboardText(_this, "") < 0) { - return -1; + if (!_this->SetClipboardText(_this, "")) { + return false; } } } SDL_SendClipboardUpdate(); - return 0; + return true; } -int SDL_ClearClipboardData(void) +SDL_bool SDL_ClearClipboardData(void) { return SDL_SetClipboardData(NULL, NULL, NULL, NULL, 0); } @@ -264,7 +264,7 @@ const void * SDLCALL SDL_ClipboardTextCallback(void *userdata, const char *mime_ return text; } -int SDL_SetClipboardText(const char *text) +SDL_bool SDL_SetClipboardText(const char *text) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); size_t num_mime_types; @@ -332,7 +332,7 @@ SDL_bool SDL_HasClipboardText(void) // Primary selection text -int SDL_SetPrimarySelectionText(const char *text) +SDL_bool SDL_SetPrimarySelectionText(const char *text) { SDL_VideoDevice *_this = SDL_GetVideoDevice(); @@ -344,8 +344,8 @@ int SDL_SetPrimarySelectionText(const char *text) text = ""; } if (_this->SetPrimarySelectionText) { - if (_this->SetPrimarySelectionText(_this, text) < 0) { - return -1; + if (!_this->SetPrimarySelectionText(_this, text)) { + return false; } } else { SDL_free(_this->primary_selection_text); @@ -353,7 +353,7 @@ int SDL_SetPrimarySelectionText(const char *text) } SDL_SendClipboardUpdate(); - return 0; + return true; } char *SDL_GetPrimarySelectionText(void) diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c index 360fde584e..72e9728193 100644 --- a/src/video/SDL_egl.c +++ b/src/video/SDL_egl.c @@ -162,7 +162,7 @@ static const char *SDL_EGL_GetErrorName(EGLint eglErrorCode) return ""; } -int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode) +bool SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode) { const char *errorText = SDL_EGL_GetErrorName(eglErrorCode); char altErrorText[32]; @@ -250,29 +250,29 @@ bool SDL_EGL_HasExtension(SDL_VideoDevice *_this, SDL_EGL_ExtensionType type, co SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(SDL_VideoDevice *_this, const char *proc) { - SDL_FunctionPointer retval = NULL; + SDL_FunctionPointer result = NULL; if (_this->egl_data) { const Uint32 eglver = (((Uint32)_this->egl_data->egl_version_major) << 16) | ((Uint32)_this->egl_data->egl_version_minor); const bool is_egl_15_or_later = eglver >= ((((Uint32)1) << 16) | 5); // EGL 1.5 can use eglGetProcAddress() for any symbol. 1.4 and earlier can't use it for core entry points. - if (!retval && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { - retval = _this->egl_data->eglGetProcAddress(proc); + if (!result && is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { + result = _this->egl_data->eglGetProcAddress(proc); } #if !defined(SDL_PLATFORM_EMSCRIPTEN) && !defined(SDL_VIDEO_DRIVER_VITA) // LoadFunction isn't needed on Emscripten and will call dlsym(), causing other problems. // Try SDL_LoadFunction() first for EGL <= 1.4, or as a fallback for >= 1.5. - if (!retval) { - retval = SDL_LoadFunction(_this->egl_data->opengl_dll_handle, proc); + if (!result) { + result = SDL_LoadFunction(_this->egl_data->opengl_dll_handle, proc); } #endif // Try eglGetProcAddress if we're on <= 1.4 and still searching... - if (!retval && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { - retval = _this->egl_data->eglGetProcAddress(proc); + if (!result && !is_egl_15_or_later && _this->egl_data->eglGetProcAddress) { + result = _this->egl_data->eglGetProcAddress(proc); } } - return retval; + return result; } void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this) @@ -297,7 +297,7 @@ void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this) } } -static int SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_path) +static bool SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_path) { void *egl_dll_handle = NULL, *opengl_dll_handle = NULL; const char *path = NULL; @@ -465,10 +465,10 @@ static int SDL_EGL_LoadLibraryInternal(SDL_VideoDevice *_this, const char *egl_p *_this->gl_config.driver_path = '\0'; } - return 0; + return true; } -int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path) +bool SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path) { if (_this->egl_data) { return SDL_SetError("EGL context already created"); @@ -476,15 +476,15 @@ int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *egl_path) _this->egl_data = (struct SDL_EGL_VideoData *)SDL_calloc(1, sizeof(SDL_EGL_VideoData)); if (!_this->egl_data) { - return -1; + return false; } - if (SDL_EGL_LoadLibraryInternal(_this, egl_path) < 0) { + if (!SDL_EGL_LoadLibraryInternal(_this, egl_path)) { SDL_free(_this->egl_data); _this->egl_data = NULL; - return -1; + return false; } - return 0; + return true; } static void SDL_EGL_GetVersion(SDL_VideoDevice *_this) @@ -503,7 +503,7 @@ static void SDL_EGL_GetVersion(SDL_VideoDevice *_this) } } -int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisplayType native_display, EGLenum platform) +bool SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisplayType native_display, EGLenum platform) { int library_load_retcode = SDL_EGL_LoadLibraryOnly(_this, egl_path); if (library_load_retcode != 0) { @@ -572,7 +572,7 @@ int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisp _this->egl_data->is_offscreen = false; - return 0; + return true; } /** @@ -583,7 +583,7 @@ int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *egl_path, NativeDisp valid available GPU for EGL to use. */ -int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device) +bool SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device) { void *egl_devices[SDL_EGL_MAX_DEVICES]; EGLint num_egl_devices = 0; @@ -658,7 +658,7 @@ int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device) _this->egl_data->is_offscreen = true; - return 0; + return true; } void SDL_EGL_SetRequiredVisualId(SDL_VideoDevice *_this, int visual_id) @@ -727,7 +727,7 @@ static void dumpconfig(SDL_VideoDevice *_this, EGLConfig config) #endif // DUMP_EGL_CONFIG -static int SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_caveat_none) +static bool SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_caveat_none) { // 64 seems nice. EGLint attribs[64]; @@ -825,7 +825,7 @@ static int SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_c configs, SDL_arraysize(configs), &found_configs) == EGL_FALSE || found_configs == 0) { - return -1; + return false; } // first ensure that a found config has a matching format, or the function will fall through. @@ -922,10 +922,10 @@ static int SDL_EGL_PrivateChooseConfig(SDL_VideoDevice *_this, bool set_config_c dumpconfig(_this, _this->egl_data->egl_config); #endif - return 0; + return true; } -int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this) +bool SDL_EGL_ChooseConfig(SDL_VideoDevice *_this) { int ret; @@ -936,14 +936,14 @@ int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this) // Try with EGL_CONFIG_CAVEAT set to EGL_NONE, to avoid any EGL_SLOW_CONFIG or EGL_NON_CONFORMANT_CONFIG ret = SDL_EGL_PrivateChooseConfig(_this, true); if (ret == 0) { - return 0; + return true; } // Fallback with all configs ret = SDL_EGL_PrivateChooseConfig(_this, false); if (ret == 0) { SDL_Log("SDL_EGL_ChooseConfig: found a slow EGL config"); - return 0; + return true; } return SDL_EGL_SetError("Couldn't find matching EGL config", "eglChooseConfig"); @@ -1085,9 +1085,9 @@ SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surfa _this->egl_data->egl_swapinterval = 0; - if (SDL_EGL_MakeCurrent(_this, egl_surface, egl_context) < 0) { + if (!SDL_EGL_MakeCurrent(_this, egl_surface, egl_context)) { // Delete the context - SDL_EGL_DeleteContext(_this, egl_context); + SDL_EGL_DestroyContext(_this, egl_context); return NULL; } @@ -1122,7 +1122,7 @@ SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surfa return (SDL_GLContext)egl_context; } -int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context) +bool SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context) { EGLContext egl_context = (EGLContext)context; @@ -1133,7 +1133,7 @@ int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLCo if (!_this->egl_data->eglMakeCurrent) { if (!egl_surface && !context) { // Can't do the nothing there is to do? Probably trying to cleanup a failed startup, just return. - return 0; + return true; } else { return SDL_SetError("EGL not initialized"); // something clearly went wrong somewhere. } @@ -1156,10 +1156,10 @@ int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLCo } } - return 0; + return true; } -int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval) { EGLBoolean status; @@ -1177,43 +1177,43 @@ int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval) status = _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, interval); if (status == EGL_TRUE) { _this->egl_data->egl_swapinterval = interval; - return 0; + return true; } return SDL_EGL_SetError("Unable to set the EGL swap interval", "eglSwapInterval"); } -int SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { if (!_this->egl_data) { return SDL_SetError("EGL not initialized"); } *interval = _this->egl_data->egl_swapinterval; - return 0; + return true; } -int SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface) +bool SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface) { if (!_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, egl_surface)) { return SDL_EGL_SetError("unable to show color buffer in an OS-native window", "eglSwapBuffers"); } - return 0; + return true; } -int SDL_EGL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool SDL_EGL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { EGLContext egl_context = (EGLContext)context; // Clean up GLES and EGL if (!_this->egl_data) { - return 0; + return true; } if (egl_context != NULL && egl_context != EGL_NO_CONTEXT) { _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context); } - return 0; + return true; } EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, NativeWindowType nw) @@ -1228,7 +1228,7 @@ EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, Nat EGLSurface surface; - if (SDL_EGL_ChooseConfig(_this) < 0) { + if (!SDL_EGL_ChooseConfig(_this)) { return EGL_NO_SURFACE; } @@ -1319,7 +1319,7 @@ SDL_EGL_CreateOffscreenSurface(SDL_VideoDevice *_this, int width, int height) attributes[1] = width; attributes[3] = height; - if (SDL_EGL_ChooseConfig(_this) < 0) { + if (!SDL_EGL_ChooseConfig(_this)) { return EGL_NO_SURFACE; } diff --git a/src/video/SDL_egl_c.h b/src/video/SDL_egl_c.h index 187cb49b85..e330471c7d 100644 --- a/src/video/SDL_egl_c.h +++ b/src/video/SDL_egl_c.h @@ -116,53 +116,53 @@ typedef enum SDL_EGL_ExtensionType extern bool SDL_EGL_HasExtension(SDL_VideoDevice *_this, SDL_EGL_ExtensionType type, const char *ext); -extern int SDL_EGL_GetAttribute(SDL_VideoDevice *_this, SDL_GLattr attrib, int *value); +extern bool SDL_EGL_GetAttribute(SDL_VideoDevice *_this, SDL_GLattr attrib, int *value); /* SDL_EGL_LoadLibrary can get a display for a specific platform (EGL_PLATFORM_*) * or, if 0 is passed, let the implementation decide. */ -extern int SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *path); -extern int SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *path, NativeDisplayType native_display, EGLenum platform); +extern bool SDL_EGL_LoadLibraryOnly(SDL_VideoDevice *_this, const char *path); +extern bool SDL_EGL_LoadLibrary(SDL_VideoDevice *_this, const char *path, NativeDisplayType native_display, EGLenum platform); extern SDL_FunctionPointer SDL_EGL_GetProcAddressInternal(SDL_VideoDevice *_this, const char *proc); extern void SDL_EGL_UnloadLibrary(SDL_VideoDevice *_this); extern void SDL_EGL_SetRequiredVisualId(SDL_VideoDevice *_this, int visual_id); -extern int SDL_EGL_ChooseConfig(SDL_VideoDevice *_this); -extern int SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); -extern int SDL_EGL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool SDL_EGL_ChooseConfig(SDL_VideoDevice *_this); +extern bool SDL_EGL_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool SDL_EGL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool SDL_EGL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); extern EGLSurface SDL_EGL_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, NativeWindowType nw); extern void SDL_EGL_DestroySurface(SDL_VideoDevice *_this, EGLSurface egl_surface); extern EGLSurface SDL_EGL_CreateOffscreenSurface(SDL_VideoDevice *_this, int width, int height); // Assumes that LoadLibraryOnly() has succeeded -extern int SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device); +extern bool SDL_EGL_InitializeOffscreen(SDL_VideoDevice *_this, int device); // These need to be wrapped to get the surface for the window by the platform GLES implementation extern SDL_GLContext SDL_EGL_CreateContext(SDL_VideoDevice *_this, EGLSurface egl_surface); -extern int SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context); -extern int SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface); +extern bool SDL_EGL_MakeCurrent(SDL_VideoDevice *_this, EGLSurface egl_surface, SDL_GLContext context); +extern bool SDL_EGL_SwapBuffers(SDL_VideoDevice *_this, EGLSurface egl_surface); // SDL Error-reporting -extern int SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode); +extern bool SDL_EGL_SetErrorEx(const char *message, const char *eglFunctionName, EGLint eglErrorCode); #define SDL_EGL_SetError(message, eglFunctionName) SDL_EGL_SetErrorEx(message, eglFunctionName, _this->egl_data->eglGetError()) // A few of useful macros #define SDL_EGL_SwapWindow_impl(BACKEND) \ - int BACKEND##_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) \ + bool BACKEND##_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) \ { \ - return SDL_EGL_SwapBuffers(_this, window->internal->egl_surface); \ + return SDL_EGL_SwapBuffers(_this, window->internal->egl_surface); \ } -#define SDL_EGL_MakeCurrent_impl(BACKEND) \ - int BACKEND##_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) \ - { \ +#define SDL_EGL_MakeCurrent_impl(BACKEND) \ + bool BACKEND##_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) \ + { \ return SDL_EGL_MakeCurrent(_this, window ? window->internal->egl_surface : EGL_NO_SURFACE, context); \ } #define SDL_EGL_CreateContext_impl(BACKEND) \ - SDL_GLContext BACKEND##_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) \ + SDL_GLContext BACKEND##_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) \ { \ - return SDL_EGL_CreateContext(_this, window->internal->egl_surface); \ + return SDL_EGL_CreateContext(_this, window->internal->egl_surface); \ } #endif // SDL_VIDEO_OPENGL_EGL diff --git a/src/video/SDL_fillrect.c b/src/video/SDL_fillrect.c index 3f53a2fea8..93891d1cb4 100644 --- a/src/video/SDL_fillrect.c +++ b/src/video/SDL_fillrect.c @@ -229,7 +229,7 @@ static void SDL_FillSurfaceRect4(Uint8 *pixels, int pitch, Uint32 color, int w, /* * This function performs a fast fill of the given rectangle with 'color' */ -int SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color) +SDL_bool SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color) { if (!SDL_SurfaceValid(dst)) { return SDL_InvalidParamError("SDL_FillSurfaceRect(): dst"); @@ -240,15 +240,14 @@ int SDL_FillSurfaceRect(SDL_Surface *dst, const SDL_Rect *rect, Uint32 color) rect = &dst->internal->clip_rect; // Don't attempt to fill if the surface's clip_rect is empty if (SDL_RectEmpty(rect)) { - return 0; + return true; } } return SDL_FillSurfaceRects(dst, rect, 1, color); } -int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, - Uint32 color) +SDL_bool SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, Uint32 color) { SDL_Rect clipped; Uint8 *pixels; @@ -262,7 +261,7 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, // Nothing to do if (dst->w == 0 || dst->h == 0) { - return 0; + return true; } // Perform software fill @@ -284,7 +283,7 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, if (SDL_BITSPERPIXEL(dst->format) == 4) { Uint8 b = (((Uint8)color << 4) | (Uint8)color); SDL_memset(dst->pixels, b, (size_t)dst->h * dst->pitch); - return 1; + return true; } } } @@ -359,5 +358,5 @@ int SDL_FillSurfaceRects(SDL_Surface *dst, const SDL_Rect *rects, int count, } // We're done! - return 0; + return true; } diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 0455dd2ad5..ee5d189a03 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -165,7 +165,7 @@ const char *SDL_GetPixelFormatName(SDL_PixelFormat format) } #undef CASE -int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask) +SDL_bool SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, Uint32 *Gmask, Uint32 *Bmask, Uint32 *Amask) { Uint32 masks[4]; @@ -184,7 +184,7 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, default: *bpp = 0; // oh well. } - return 0; + return true; } #else if (SDL_ISPIXELFORMAT_FOURCC(format)) { @@ -210,7 +210,7 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, *Gmask = 0x0000FF00; *Bmask = 0x00FF0000; #endif - return 0; + return true; } if (format == SDL_PIXELFORMAT_BGR24) { @@ -223,14 +223,14 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, *Gmask = 0x0000FF00; *Bmask = 0x000000FF; #endif - return 0; + return true; } if (SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED8 && SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED16 && SDL_PIXELTYPE(format) != SDL_PIXELTYPE_PACKED32) { // Not a format that uses masks - return 0; + return true; } switch (SDL_PIXELLAYOUT(format)) { @@ -334,7 +334,7 @@ int SDL_GetMasksForPixelFormat(SDL_PixelFormat format, int *bpp, Uint32 *Rmask, default: return SDL_SetError("Unknown pixel format"); } - return 0; + return true; } SDL_PixelFormat SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) @@ -578,14 +578,14 @@ SDL_PixelFormat SDL_GetPixelFormatForMasks(int bpp, Uint32 Rmask, Uint32 Gmask, static SDL_HashTable *SDL_format_details; static SDL_Mutex *SDL_format_details_lock; -static int SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_PixelFormat format) +static SDL_bool SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_PixelFormat format) { int bpp; Uint32 Rmask, Gmask, Bmask, Amask; Uint32 mask; - if (SDL_GetMasksForPixelFormat(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask) < 0) { - return -1; + if (!SDL_GetMasksForPixelFormat(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { + return false; } // Set up the format @@ -642,7 +642,7 @@ static int SDL_InitPixelFormatDetails(SDL_PixelFormatDetails *details, SDL_Pixel } } - return 0; + return true; } const SDL_PixelFormatDetails *SDL_GetPixelFormatDetails(SDL_PixelFormat format) @@ -669,7 +669,7 @@ const SDL_PixelFormatDetails *SDL_GetPixelFormatDetails(SDL_PixelFormat format) goto done; } - if (SDL_InitPixelFormatDetails(details, format) < 0) { + if (!SDL_InitPixelFormatDetails(details, format)) { SDL_free(details); details = NULL; goto done; @@ -1035,18 +1035,17 @@ SDL_Palette *SDL_CreatePalette(int ncolors) return palette; } -int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, - int firstcolor, int ncolors) +SDL_bool SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, int firstcolor, int ncolors) { - int status = 0; + bool result = true; // Verify the parameters if (!palette) { - return -1; + return false; } if (ncolors > (palette->ncolors - firstcolor)) { ncolors = (palette->ncolors - firstcolor); - status = -1; + result = false; } if (colors != (palette->colors + firstcolor)) { @@ -1058,7 +1057,7 @@ int SDL_SetPaletteColors(SDL_Palette *palette, const SDL_Color *colors, palette->version = 1; } - return status; + return result; } void SDL_DestroyPalette(SDL_Palette *palette) @@ -1418,7 +1417,7 @@ static Uint8 *Map1toN(const SDL_Palette *pal, Uint8 Rmod, Uint8 Gmod, Uint8 Bmod return map; } -int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst) +bool SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst) { SDL_BlitMap *map = &src->internal->map; @@ -1428,8 +1427,8 @@ int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst) map->dst_palette_version != dst->internal->palette->version) || (src->internal->palette && map->src_palette_version != src->internal->palette->version)) { - if (SDL_MapSurface(src, dst) < 0) { - return -1; + if (!SDL_MapSurface(src, dst)) { + return false; } // just here for debugging // printf @@ -1439,7 +1438,7 @@ int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst) } else { map->info.dst_surface = dst; } - return 0; + return true; } void SDL_InvalidateMap(SDL_BlitMap *map) @@ -1458,7 +1457,7 @@ void SDL_InvalidateMap(SDL_BlitMap *map) } } -int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst) +bool SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst) { const SDL_PixelFormatDetails *srcfmt; const SDL_Palette *srcpal; @@ -1491,7 +1490,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst) } if (!map->identity) { if (!map->info.table) { - return -1; + return false; } } if (srcfmt->bits_per_pixel != dstfmt->bits_per_pixel) { @@ -1503,7 +1502,7 @@ int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst) Map1toN(srcpal, src->internal->map.info.r, src->internal->map.info.g, src->internal->map.info.b, src->internal->map.info.a, dstfmt); if (!map->info.table) { - return -1; + return false; } } } else { diff --git a/src/video/SDL_pixels_c.h b/src/video/SDL_pixels_c.h index 05da3ee457..754b0cd33a 100644 --- a/src/video/SDL_pixels_c.h +++ b/src/video/SDL_pixels_c.h @@ -29,7 +29,7 @@ // Pixel format functions -extern int SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, bool minimalPitch); +extern bool SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, bool minimalPitch); extern SDL_Colorspace SDL_GetDefaultColorspaceForFormat(SDL_PixelFormat pixel_format); extern void SDL_QuitPixelFormatDetails(void); @@ -43,9 +43,9 @@ extern const float *SDL_GetColorPrimariesConversionMatrix(SDL_ColorPrimaries src extern void SDL_ConvertColorPrimaries(float *fR, float *fG, float *fB, const float *matrix); // Blit mapping functions -extern int SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst); +extern bool SDL_ValidateMap(SDL_Surface *src, SDL_Surface *dst); extern void SDL_InvalidateMap(SDL_BlitMap *map); -extern int SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst); +extern bool SDL_MapSurface(SDL_Surface *src, SDL_Surface *dst); // Miscellaneous functions extern void SDL_DitherPalette(SDL_Palette *palette); diff --git a/src/video/SDL_rect_impl.h b/src/video/SDL_rect_impl.h index 76b7bf741a..9d024ef83e 100644 --- a/src/video/SDL_rect_impl.h +++ b/src/video/SDL_rect_impl.h @@ -137,7 +137,7 @@ SDL_bool SDL_INTERSECTRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *resul return !SDL_RECTEMPTY(result); } -int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result) +SDL_bool SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result) { SCALARTYPE Amin, Amax, Bmin, Bmax; @@ -156,10 +156,10 @@ int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result) } else { // A empty, B not empty *result = *B; } - return 0; + return true; } else if (SDL_RECTEMPTY(B)) { // A not empty, B empty *result = *A; - return 0; + return true; } // Horizontal union @@ -189,7 +189,7 @@ int SDL_UNIONRECT(const RECTTYPE *A, const RECTTYPE *B, RECTTYPE *result) Amax = Bmax; } result->h = Amax - Amin; - return 0; + return true; } SDL_bool SDL_ENCLOSEPOINTS(const POINTTYPE *points, int count, const RECTTYPE *clip, RECTTYPE *result) diff --git a/src/video/SDL_stretch.c b/src/video/SDL_stretch.c index 006b57ec31..e95aca31bd 100644 --- a/src/video/SDL_stretch.c +++ b/src/video/SDL_stretch.c @@ -22,14 +22,12 @@ #include "SDL_blit.h" -static int SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); -static int SDL_LowerSoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); +static bool SDL_LowerSoftStretchNearest(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); +static bool SDL_LowerSoftStretchLinear(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect); -int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, const SDL_Rect *dstrect, - SDL_ScaleMode scaleMode) +bool SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode) { - int ret; + bool result; int src_locked; int dst_locked; SDL_Rect full_src; @@ -46,11 +44,11 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, // Slow! SDL_Surface *src_tmp = SDL_ConvertSurfaceAndColorspace(src, dst->format, dst->internal->palette, dst->internal->colorspace, dst->internal->props); if (!src_tmp) { - return -1; + return false; } - ret = SDL_SoftStretch(src_tmp, srcrect, dst, dstrect, scaleMode); + result = SDL_SoftStretch(src_tmp, srcrect, dst, dstrect, scaleMode); SDL_DestroySurface(src_tmp); - return ret; + return result; } if (SDL_ISPIXELFORMAT_FOURCC(src->format)) { @@ -66,20 +64,20 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *src_tmp = SDL_ConvertSurface(src, SDL_PIXELFORMAT_XRGB8888); SDL_Surface *dst_tmp = SDL_CreateSurface(dstrect->w, dstrect->h, SDL_PIXELFORMAT_XRGB8888); if (src_tmp && dst_tmp) { - ret = SDL_SoftStretch(src_tmp, srcrect, dst_tmp, NULL, scaleMode); - if (ret == 0) { - SDL_ConvertPixelsAndColorspace(dstrect->w, dstrect->h, - dst_tmp->format, SDL_COLORSPACE_SRGB, 0, - dst_tmp->pixels, dst_tmp->pitch, - dst->format, dst->internal->colorspace, SDL_GetSurfaceProperties(dst), - (Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * SDL_BYTESPERPIXEL(dst->format), dst->pitch); + result = SDL_SoftStretch(src_tmp, srcrect, dst_tmp, NULL, scaleMode); + if (result) { + result = SDL_ConvertPixelsAndColorspace(dstrect->w, dstrect->h, + dst_tmp->format, SDL_COLORSPACE_SRGB, 0, + dst_tmp->pixels, dst_tmp->pitch, + dst->format, dst->internal->colorspace, SDL_GetSurfaceProperties(dst), + (Uint8 *)dst->pixels + dstrect->y * dst->pitch + dstrect->x * SDL_BYTESPERPIXEL(dst->format), dst->pitch); } } else { - ret = -1; + result = false; } SDL_DestroySurface(src_tmp); SDL_DestroySurface(dst_tmp); - return ret; + return result; } if (scaleMode != SDL_SCALEMODE_NEAREST && scaleMode != SDL_SCALEMODE_LINEAR && scaleMode != SDL_SCALEMODE_BEST) { @@ -125,7 +123,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, } if (dstrect->w <= 0 || dstrect->h <= 0) { - return 0; + return true; } if (srcrect->w > SDL_MAX_UINT16 || srcrect->h > SDL_MAX_UINT16 || @@ -136,7 +134,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, // Lock the destination if it's in hardware dst_locked = 0; if (SDL_MUSTLOCK(dst)) { - if (SDL_LockSurface(dst) < 0) { + if (!SDL_LockSurface(dst)) { return SDL_SetError("Unable to lock destination surface"); } dst_locked = 1; @@ -144,7 +142,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, // Lock the source if it's in hardware src_locked = 0; if (SDL_MUSTLOCK(src)) { - if (SDL_LockSurface(src) < 0) { + if (!SDL_LockSurface(src)) { if (dst_locked) { SDL_UnlockSurface(dst); } @@ -154,9 +152,9 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, } if (scaleMode == SDL_SCALEMODE_NEAREST) { - ret = SDL_LowerSoftStretchNearest(src, srcrect, dst, dstrect); + result = SDL_LowerSoftStretchNearest(src, srcrect, dst, dstrect); } else { - ret = SDL_LowerSoftStretchLinear(src, srcrect, dst, dstrect); + result = SDL_LowerSoftStretchLinear(src, srcrect, dst, dstrect); } // We need to unlock the surfaces if they're locked @@ -167,7 +165,7 @@ int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_UnlockSurface(src); } - return ret; + return result; } /* bilinear interpolation precision must be < 8 @@ -325,8 +323,7 @@ static SDL_INLINE void INTERPOL_BILINEAR(const Uint32 *s0, const Uint32 *s1, int INTERPOL(tmp, tmp + 1, frac_w0, frac_w1, dst); } -static int scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch, - Uint32 *dst, int dst_w, int dst_h, int dst_pitch) +static bool scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) { BILINEAR___START @@ -371,7 +368,7 @@ static int scale_mat(const Uint32 *src, int src_w, int src_h, int src_pitch, } dst = (Uint32 *)((Uint8 *)dst + dst_gap); } - return 0; + return true; } #ifdef SDL_NEON_INTRINSICS @@ -446,7 +443,7 @@ static SDL_INLINE void SDL_TARGETING("sse2") INTERPOL_BILINEAR_SSE(const Uint32 *dst = _mm_cvtsi128_si32(e0); } -static int SDL_TARGETING("sse2") scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) +static bool SDL_TARGETING("sse2") scale_mat_SSE(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) { BILINEAR___START @@ -562,7 +559,7 @@ static int SDL_TARGETING("sse2") scale_mat_SSE(const Uint32 *src, int src_w, int } dst = (Uint32 *)((Uint8 *)dst + dst_gap); } - return 0; + return true; } #endif @@ -610,7 +607,7 @@ static SDL_INLINE void INTERPOL_BILINEAR_NEON(const Uint32 *s0, const Uint32 *s1 *dst = vget_lane_u32(CAST_uint32x2_t e0, 0); } -static int scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) +static bool scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) { BILINEAR___START @@ -824,14 +821,13 @@ static int scale_mat_NEON(const Uint32 *src, int src_w, int src_h, int src_pitch dst = (Uint32 *)((Uint8 *)dst + dst_gap); } - return 0; + return true; } #endif -int SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect, - SDL_Surface *d, const SDL_Rect *dstrect) +bool SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect, SDL_Surface *d, const SDL_Rect *dstrect) { - int ret = -1; + bool result = false; int src_w = srcrect->w; int src_h = srcrect->h; int dst_w = dstrect->w; @@ -842,22 +838,22 @@ int SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect, Uint32 *dst = (Uint32 *)((Uint8 *)d->pixels + dstrect->x * 4 + dstrect->y * dst_pitch); #ifdef SDL_NEON_INTRINSICS - if (ret == -1 && hasNEON()) { - ret = scale_mat_NEON(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch); + if (!result && hasNEON()) { + result = scale_mat_NEON(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch); } #endif #ifdef SDL_SSE2_INTRINSICS - if (ret == -1 && hasSSE2()) { - ret = scale_mat_SSE(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch); + if (!result && hasSSE2()) { + result = scale_mat_SSE(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch); } #endif - if (ret == -1) { - ret = scale_mat(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch); + if (!result) { + result = scale_mat(src, src_w, src_h, src_pitch, dst, dst_w, dst_h, dst_pitch); } - return ret; + return result; } #define SDL_SCALE_NEAREST__START \ @@ -879,8 +875,7 @@ int SDL_LowerSoftStretchLinear(SDL_Surface *s, const SDL_Rect *srcrect, posx = incx / 2; \ n = dst_w; -static int scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, - Uint32 *dst, int dst_w, int dst_h, int dst_pitch) +static bool scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) { Uint32 bpp = 1; SDL_SCALE_NEAREST__START @@ -896,11 +891,10 @@ static int scale_mat_nearest_1(const Uint32 *src_ptr, int src_w, int src_h, int } dst = (Uint32 *)((Uint8 *)dst + dst_gap); } - return 0; + return true; } -static int scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, - Uint32 *dst, int dst_w, int dst_h, int dst_pitch) +static bool scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) { Uint32 bpp = 2; SDL_SCALE_NEAREST__START @@ -916,11 +910,10 @@ static int scale_mat_nearest_2(const Uint32 *src_ptr, int src_w, int src_h, int } dst = (Uint32 *)((Uint8 *)dst + dst_gap); } - return 0; + return true; } -static int scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, - Uint32 *dst, int dst_w, int dst_h, int dst_pitch) +static bool scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) { Uint32 bpp = 3; SDL_SCALE_NEAREST__START @@ -938,11 +931,10 @@ static int scale_mat_nearest_3(const Uint32 *src_ptr, int src_w, int src_h, int } dst = (Uint32 *)((Uint8 *)dst + dst_gap); } - return 0; + return true; } -static int scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, - Uint32 *dst, int dst_w, int dst_h, int dst_pitch) +static bool scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int src_pitch, Uint32 *dst, int dst_w, int dst_h, int dst_pitch) { Uint32 bpp = 4; SDL_SCALE_NEAREST__START @@ -958,11 +950,10 @@ static int scale_mat_nearest_4(const Uint32 *src_ptr, int src_w, int src_h, int } dst = (Uint32 *)((Uint8 *)dst + dst_gap); } - return 0; + return true; } -int SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect, - SDL_Surface *d, const SDL_Rect *dstrect) +bool SDL_LowerSoftStretchNearest(SDL_Surface *s, const SDL_Rect *srcrect, SDL_Surface *d, const SDL_Rect *dstrect) { int src_w = srcrect->w; int src_h = srcrect->h; diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index bbb5b6b4e1..293025c046 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -55,11 +55,10 @@ void SDL_UpdateSurfaceLockFlag(SDL_Surface *surface) /* * Calculate the pad-aligned scanline width of a surface. - * Return SDL_SIZE_MAX on overflow. * * for FOURCC, use SDL_CalculateYUVSize() */ -static int SDL_CalculateRGBSize(Uint32 format, size_t width, size_t height, size_t *size, size_t *pitch, bool minimal) +static bool SDL_CalculateRGBSize(Uint32 format, size_t width, size_t height, size_t *size, size_t *pitch, bool minimal) { if (SDL_BITSPERPIXEL(format) >= 8) { if (SDL_size_mul_overflow(width, SDL_BYTESPERPIXEL(format), pitch)) { @@ -86,10 +85,10 @@ static int SDL_CalculateRGBSize(Uint32 format, size_t width, size_t height, size return SDL_SetError("height * pitch would overflow"); } - return 0; + return true; } -int SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, bool minimalPitch) +bool SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size_t *size, size_t *pitch, bool minimalPitch) { size_t p = 0, sz = 0; @@ -102,14 +101,14 @@ int SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size } if (SDL_ISPIXELFORMAT_FOURCC(format)) { - if (SDL_CalculateYUVSize(format, width, height, &sz, &p) < 0) { + if (!SDL_CalculateYUVSize(format, width, height, &sz, &p)) { // Overflow... - return -1; + return false; } } else { - if (SDL_CalculateRGBSize(format, width, height, &sz, &p, minimalPitch) < 0) { + if (!SDL_CalculateRGBSize(format, width, height, &sz, &p, minimalPitch)) { // Overflow... - return -1; + return false; } } @@ -121,7 +120,7 @@ int SDL_CalculateSurfaceSize(SDL_PixelFormat format, int width, int height, size *pitch = p; } - return 0; + return true; } static SDL_Surface *SDL_InitializeSurface(SDL_InternalSurface *mem, int width, int height, SDL_PixelFormat format, SDL_Colorspace colorspace, SDL_PropertiesID props, void *pixels, int pitch, bool onstack) @@ -165,7 +164,7 @@ static SDL_Surface *SDL_InitializeSurface(SDL_InternalSurface *mem, int width, i } if (props) { - if (SDL_CopyProperties(props, SDL_GetSurfaceProperties(surface)) < 0) { + if (!SDL_CopyProperties(props, SDL_GetSurfaceProperties(surface))) { return NULL; } } @@ -199,7 +198,7 @@ SDL_Surface *SDL_CreateSurface(int width, int height, SDL_PixelFormat format) return NULL; } - if (SDL_CalculateSurfaceSize(format, width, height, &size, &pitch, false /* not minimal pitch */) < 0) { + if (!SDL_CalculateSurfaceSize(format, width, height, &size, &pitch, false /* not minimal pitch */)) { // Overflow... return NULL; } @@ -251,7 +250,7 @@ SDL_Surface *SDL_CreateSurfaceFrom(int width, int height, SDL_PixelFormat format } else { size_t minimalPitch; - if (SDL_CalculateSurfaceSize(format, width, height, NULL, &minimalPitch, true /* minimal pitch */) < 0) { + if (!SDL_CalculateSurfaceSize(format, width, height, NULL, &minimalPitch, true /* minimal pitch */)) { // Overflow... return NULL; } @@ -284,14 +283,14 @@ SDL_PropertiesID SDL_GetSurfaceProperties(SDL_Surface *surface) return surface->internal->props; } -int SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace) +SDL_bool SDL_SetSurfaceColorspace(SDL_Surface *surface, SDL_Colorspace colorspace) { if (!SDL_SurfaceValid(surface)) { return SDL_InvalidParamError("surface"); } surface->internal->colorspace = colorspace; - return 0; + return true; } SDL_Colorspace SDL_GetSurfaceColorspace(SDL_Surface *surface) @@ -389,7 +388,7 @@ SDL_Palette *SDL_CreateSurfacePalette(SDL_Surface *surface) palette->colors[1].b = 0x00; } - if (SDL_SetSurfacePalette(surface, palette) < 0) { + if (!SDL_SetSurfacePalette(surface, palette)) { SDL_DestroyPalette(palette); return NULL; } @@ -400,7 +399,7 @@ SDL_Palette *SDL_CreateSurfacePalette(SDL_Surface *surface) return palette; } -int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette) +SDL_bool SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette) { if (!SDL_SurfaceValid(surface)) { return SDL_InvalidParamError("surface"); @@ -424,7 +423,7 @@ int SDL_SetSurfacePalette(SDL_Surface *surface, SDL_Palette *palette) SDL_InvalidateMap(&surface->internal->map); - return 0; + return true; } SDL_Palette *SDL_GetSurfacePalette(SDL_Surface *surface) @@ -436,7 +435,7 @@ SDL_Palette *SDL_GetSurfacePalette(SDL_Surface *surface) return surface->internal->palette; } -int SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image) +SDL_bool SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image) { if (!SDL_SurfaceValid(surface)) { return SDL_InvalidParamError("surface"); @@ -448,13 +447,13 @@ int SDL_AddSurfaceAlternateImage(SDL_Surface *surface, SDL_Surface *image) SDL_Surface **images = (SDL_Surface **)SDL_realloc(surface->internal->images, (surface->internal->num_images + 1) * sizeof(*images)); if (!images) { - return -1; + return false; } images[surface->internal->num_images] = image; surface->internal->images = images; ++surface->internal->num_images; ++image->refcount; - return 0; + return true; } SDL_bool SDL_SurfaceHasAlternateImages(SDL_Surface *surface) @@ -580,7 +579,7 @@ void SDL_RemoveSurfaceAlternateImages(SDL_Surface *surface) } } -int SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled) +SDL_bool SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled) { int flags; @@ -598,7 +597,7 @@ int SDL_SetSurfaceRLE(SDL_Surface *surface, SDL_bool enabled) SDL_InvalidateMap(&surface->internal->map); } SDL_UpdateSurfaceLockFlag(surface); - return 0; + return true; } SDL_bool SDL_SurfaceHasRLE(SDL_Surface *surface) @@ -614,7 +613,7 @@ SDL_bool SDL_SurfaceHasRLE(SDL_Surface *surface) return true; } -int SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key) +SDL_bool SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key) { int flags; @@ -637,7 +636,7 @@ int SDL_SetSurfaceColorKey(SDL_Surface *surface, SDL_bool enabled, Uint32 key) SDL_InvalidateMap(&surface->internal->map); } - return 0; + return true; } SDL_bool SDL_SurfaceHasColorKey(SDL_Surface *surface) @@ -653,7 +652,7 @@ SDL_bool SDL_SurfaceHasColorKey(SDL_Surface *surface) return true; } -int SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key) +SDL_bool SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key) { if (key) { *key = 0; @@ -670,7 +669,7 @@ int SDL_GetSurfaceColorKey(SDL_Surface *surface, Uint32 *key) if (key) { *key = surface->internal->map.info.colorkey; } - return 0; + return true; } /* This is a fairly slow function to switch from colorkey to alpha @@ -764,7 +763,7 @@ static void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface, bool ignore_alpha) SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); } -int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b) +SDL_bool SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b) { int flags; @@ -785,10 +784,10 @@ int SDL_SetSurfaceColorMod(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b) if (surface->internal->map.info.flags != flags) { SDL_InvalidateMap(&surface->internal->map); } - return 0; + return true; } -int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b) +SDL_bool SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b) { if (!SDL_SurfaceValid(surface)) { if (r) { @@ -812,10 +811,10 @@ int SDL_GetSurfaceColorMod(SDL_Surface *surface, Uint8 *r, Uint8 *g, Uint8 *b) if (b) { *b = surface->internal->map.info.b; } - return 0; + return true; } -int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha) +SDL_bool SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha) { int flags; @@ -834,10 +833,10 @@ int SDL_SetSurfaceAlphaMod(SDL_Surface *surface, Uint8 alpha) if (surface->internal->map.info.flags != flags) { SDL_InvalidateMap(&surface->internal->map); } - return 0; + return true; } -int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha) +SDL_bool SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha) { if (!SDL_SurfaceValid(surface)) { if (alpha) { @@ -849,12 +848,13 @@ int SDL_GetSurfaceAlphaMod(SDL_Surface *surface, Uint8 *alpha) if (alpha) { *alpha = surface->internal->map.info.a; } - return 0; + return true; } -int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode) +SDL_bool SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode) { - int flags, status; + int flags; + bool result = true; if (!SDL_SurfaceValid(surface)) { return SDL_InvalidParamError("surface"); @@ -864,7 +864,6 @@ int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode) return SDL_InvalidParamError("blendMode"); } - status = 0; flags = surface->internal->map.info.flags; surface->internal->map.info.flags &= ~SDL_COPY_BLEND_MASK; switch (blendMode) { @@ -889,7 +888,7 @@ int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode) surface->internal->map.info.flags |= SDL_COPY_MUL; break; default: - status = SDL_Unsupported(); + result = SDL_Unsupported(); break; } @@ -897,10 +896,10 @@ int SDL_SetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode blendMode) SDL_InvalidateMap(&surface->internal->map); } - return status; + return result; } -int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode) +SDL_bool SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode) { if (blendMode) { *blendMode = SDL_BLENDMODE_INVALID; @@ -911,7 +910,7 @@ int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode) } if (!blendMode) { - return 0; + return true; } switch (surface->internal->map.info.flags & SDL_COPY_BLEND_MASK) { @@ -937,7 +936,7 @@ int SDL_GetSurfaceBlendMode(SDL_Surface *surface, SDL_BlendMode *blendMode) *blendMode = SDL_BLENDMODE_NONE; break; } - return 0; + return true; } SDL_bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect) @@ -963,7 +962,7 @@ SDL_bool SDL_SetSurfaceClipRect(SDL_Surface *surface, const SDL_Rect *rect) return SDL_GetRectIntersection(rect, &full_rect, &surface->internal->clip_rect); } -int SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect) +SDL_bool SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect) { if (!SDL_SurfaceValid(surface)) { if (rect) { @@ -975,7 +974,7 @@ int SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect) return SDL_InvalidParamError("rect"); } *rect = surface->internal->clip_rect; - return 0; + return true; } /* @@ -989,18 +988,17 @@ int SDL_GetSurfaceClipRect(SDL_Surface *surface, SDL_Rect *rect) * you know exactly what you are doing, you can optimize your code * by calling the one(s) you need. */ -int SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, +SDL_bool SDL_BlitSurfaceUnchecked(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect) { // Check to make sure the blit mapping is valid - if (SDL_ValidateMap(src, dst) < 0) { - return -1; + if (!SDL_ValidateMap(src, dst)) { + return false; } return src->internal->map.blit(src, srcrect, dst, dstrect); } -int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, const SDL_Rect *dstrect) +SDL_bool SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect) { SDL_Rect r_src, r_dst; @@ -1031,7 +1029,7 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, if (srcrect) { SDL_Rect tmp; if (SDL_GetRectIntersection(srcrect, &r_src, &tmp) == false) { - return 0; + return true; } // Shift dstrect, if srcrect origin has changed @@ -1050,7 +1048,7 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, { SDL_Rect tmp; if (SDL_GetRectIntersection(&r_dst, &dst->internal->clip_rect, &tmp) == false) { - return 0; + return true; } // Shift srcrect, if dstrect has changed @@ -1065,7 +1063,7 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, if (r_dst.w <= 0 || r_dst.h <= 0) { // No-op. - return 0; + return true; } // Switch back to a fast blit if we were previously stretching @@ -1077,9 +1075,7 @@ int SDL_BlitSurface(SDL_Surface *src, const SDL_Rect *srcrect, return SDL_BlitSurfaceUnchecked(src, &r_src, dst, &r_dst); } -int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, const SDL_Rect *dstrect, - SDL_ScaleMode scaleMode) +SDL_bool SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode) { SDL_Rect *clip_rect; double src_x0, src_y0, src_x1, src_y1; @@ -1233,7 +1229,7 @@ int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, if (final_dst.w == 0 || final_dst.h == 0 || final_src.w <= 0 || final_src.h <= 0) { // No-op. - return 0; + return true; } return SDL_BlitSurfaceUncheckedScaled(src, &final_src, dst, &final_dst, scaleMode); @@ -1243,9 +1239,7 @@ int SDL_BlitSurfaceScaled(SDL_Surface *src, const SDL_Rect *srcrect, * This is a semi-private blit function and it performs low-level surface * scaled blitting only. */ -int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, - SDL_Surface *dst, const SDL_Rect *dstrect, - SDL_ScaleMode scaleMode) +SDL_bool SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode) { static const Uint32 complex_copy_flags = (SDL_COPY_MODULATE_MASK | SDL_COPY_BLEND_MASK | SDL_COPY_COLORKEY); @@ -1266,13 +1260,13 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, return SDL_SoftStretch(src, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST); } else if (SDL_BITSPERPIXEL(src->format) < 8) { // Scaling bitmap not yet supported, convert to RGBA for blit - int retval = -1; + bool result = false; SDL_Surface *tmp = SDL_ConvertSurface(src, SDL_PIXELFORMAT_ARGB8888); if (tmp) { - retval = SDL_BlitSurfaceUncheckedScaled(tmp, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST); + result = SDL_BlitSurfaceUncheckedScaled(tmp, srcrect, dst, dstrect, SDL_SCALEMODE_NEAREST); SDL_DestroySurface(tmp); } - return retval; + return result; } else { return SDL_BlitSurfaceUnchecked(src, srcrect, dst, dstrect); } @@ -1286,17 +1280,17 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, return SDL_SoftStretch(src, srcrect, dst, dstrect, SDL_SCALEMODE_LINEAR); } else if (SDL_BITSPERPIXEL(src->format) < 8) { // Scaling bitmap not yet supported, convert to RGBA for blit - int retval = -1; + bool result = false; SDL_Surface *tmp = SDL_ConvertSurface(src, SDL_PIXELFORMAT_ARGB8888); if (tmp) { - retval = SDL_BlitSurfaceUncheckedScaled(tmp, srcrect, dst, dstrect, scaleMode); + result = SDL_BlitSurfaceUncheckedScaled(tmp, srcrect, dst, dstrect, scaleMode); SDL_DestroySurface(tmp); } - return retval; + return result; } else { // Use intermediate surface(s) SDL_Surface *tmp1 = NULL; - int ret; + bool result; SDL_Rect srcrect2; int is_complex_copy_flags = (src->internal->map.info.flags & complex_copy_flags); @@ -1352,19 +1346,19 @@ int SDL_BlitSurfaceUncheckedScaled(SDL_Surface *src, const SDL_Rect *srcrect, tmprect.y = 0; tmprect.w = dstrect->w; tmprect.h = dstrect->h; - ret = SDL_BlitSurfaceUnchecked(tmp2, &tmprect, dst, dstrect); + result = SDL_BlitSurfaceUnchecked(tmp2, &tmprect, dst, dstrect); SDL_DestroySurface(tmp2); } else { - ret = SDL_SoftStretch(src, &srcrect2, dst, dstrect, SDL_SCALEMODE_LINEAR); + result = SDL_SoftStretch(src, &srcrect2, dst, dstrect, SDL_SCALEMODE_LINEAR); } SDL_DestroySurface(tmp1); - return ret; + return result; } } } -int SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect) +SDL_bool SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect) { SDL_Rect r_src, r_dst; @@ -1398,7 +1392,7 @@ int SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface // clip the source rectangle to the source surface if (srcrect) { if (SDL_GetRectIntersection(srcrect, &r_src, &r_src) == false) { - return 0; + return true; } // For tiling we don't adjust the destination rectangle @@ -1407,7 +1401,7 @@ int SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface // clip the destination rectangle against the clip rectangle { if (SDL_GetRectIntersection(&r_dst, &dst->internal->clip_rect, &r_dst) == false) { - return 0; + return true; } // For tiling we don't adjust the source rectangle @@ -1432,16 +1426,16 @@ int SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface for (int y = 0; y < rows; ++y) { curr_dst.x = r_dst.x; for (int x = 0; x < cols; ++x) { - if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) { - return -1; + if (!SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst)) { + return false; } curr_dst.x += curr_dst.w; } if (remaining_w) { curr_src.w = remaining_w; curr_dst.w = remaining_w; - if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) { - return -1; + if (!SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst)) { + return false; } curr_src.w = r_src.w; curr_dst.w = r_src.w; @@ -1453,23 +1447,23 @@ int SDL_BlitSurfaceTiled(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface curr_dst.h = remaining_h; curr_dst.x = r_dst.x; for (int x = 0; x < cols; ++x) { - if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) { - return -1; + if (!SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst)) { + return false; } curr_dst.x += curr_dst.w; } if (remaining_w) { curr_src.w = remaining_w; curr_dst.w = remaining_w; - if (SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst) < 0) { - return -1; + if (!SDL_BlitSurfaceUnchecked(src, &curr_src, dst, &curr_dst)) { + return false; } } } - return 0; + return true; } -int SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect) +SDL_bool SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect) { SDL_Rect r_src, r_dst; @@ -1507,7 +1501,7 @@ int SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, flo // clip the source rectangle to the source surface if (srcrect) { if (SDL_GetRectIntersection(srcrect, &r_src, &r_src) == false) { - return 0; + return true; } // For tiling we don't adjust the destination rectangle @@ -1516,7 +1510,7 @@ int SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, flo // clip the destination rectangle against the clip rectangle { if (SDL_GetRectIntersection(&r_dst, &dst->internal->clip_rect, &r_dst) == false) { - return 0; + return true; } // For tiling we don't adjust the source rectangle @@ -1545,16 +1539,16 @@ int SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, flo for (int y = 0; y < rows; ++y) { curr_dst.x = r_dst.x; for (int x = 0; x < cols; ++x) { - if (SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } curr_dst.x += curr_dst.w; } if (remaining_dst_w > 0) { curr_src.w = remaining_src_w; curr_dst.w = remaining_dst_w; - if (SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } curr_src.w = r_src.w; curr_dst.w = tile_width; @@ -1566,23 +1560,23 @@ int SDL_BlitSurfaceTiledWithScale(SDL_Surface *src, const SDL_Rect *srcrect, flo curr_dst.h = remaining_dst_h; curr_dst.x = r_dst.x; for (int x = 0; x < cols; ++x) { - if (SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } curr_dst.x += curr_dst.w; } if (remaining_dst_w > 0) { curr_src.w = remaining_src_w; curr_dst.w = remaining_dst_w; - if (SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceUncheckedScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } } } - return 0; + return true; } -int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect) +SDL_bool SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_width, int right_width, int top_height, int bottom_height, float scale, SDL_ScaleMode scaleMode, SDL_Surface *dst, const SDL_Rect *dstrect) { SDL_Rect full_src, full_dst; SDL_Rect curr_src, curr_dst; @@ -1635,8 +1629,8 @@ int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wid curr_dst.y = dstrect->y; curr_dst.w = dst_left_width; curr_dst.h = dst_top_height; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Upper-right corner @@ -1644,16 +1638,16 @@ int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wid curr_src.w = right_width; curr_dst.x = dstrect->x + dstrect->w - dst_right_width; curr_dst.w = dst_right_width; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Lower-right corner curr_src.y = srcrect->y + srcrect->h - bottom_height; curr_dst.y = dstrect->y + dstrect->h - dst_bottom_height; curr_dst.h = dst_bottom_height; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Lower-left corner @@ -1661,8 +1655,8 @@ int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wid curr_src.w = left_width; curr_dst.x = dstrect->x; curr_dst.w = dst_left_width; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Left @@ -1670,8 +1664,8 @@ int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wid curr_src.h = srcrect->h - top_height - bottom_height; curr_dst.y = dstrect->y + dst_top_height; curr_dst.h = dstrect->h - dst_top_height - dst_bottom_height; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Right @@ -1679,8 +1673,8 @@ int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wid curr_src.w = right_width; curr_dst.x = dstrect->x + dstrect->w - dst_right_width; curr_dst.w = dst_right_width; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Top @@ -1692,16 +1686,16 @@ int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wid curr_dst.y = dstrect->y; curr_dst.w = dstrect->w - dst_left_width - dst_right_width; curr_dst.h = dst_top_height; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Bottom curr_src.y = srcrect->y + srcrect->h - bottom_height; curr_dst.y = dstrect->y + dstrect->h - dst_bottom_height; curr_dst.h = dst_bottom_height; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } // Center @@ -1713,17 +1707,17 @@ int SDL_BlitSurface9Grid(SDL_Surface *src, const SDL_Rect *srcrect, int left_wid curr_dst.y = dstrect->y + dst_top_height; curr_dst.w = dstrect->w - dst_left_width - dst_right_width; curr_dst.h = dstrect->h - dst_top_height - dst_bottom_height; - if (SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode) < 0) { - return -1; + if (!SDL_BlitSurfaceScaled(src, &curr_src, dst, &curr_dst, scaleMode)) { + return false; } - return 0; + return true; } /* * Lock a surface to directly access the pixels */ -int SDL_LockSurface(SDL_Surface *surface) +SDL_bool SDL_LockSurface(SDL_Surface *surface) { if (!SDL_SurfaceValid(surface)) { return SDL_InvalidParamError("surface"); @@ -1744,7 +1738,7 @@ int SDL_LockSurface(SDL_Surface *surface) surface->flags |= SDL_SURFACE_LOCKED; // Ready to go.. - return 0; + return true; } /* @@ -1772,7 +1766,7 @@ void SDL_UnlockSurface(SDL_Surface *surface) surface->flags &= ~SDL_SURFACE_LOCKED; } -static int SDL_FlipSurfaceHorizontal(SDL_Surface *surface) +static bool SDL_FlipSurfaceHorizontal(SDL_Surface *surface) { bool isstack; Uint8 *row, *a, *b, *tmp; @@ -1784,11 +1778,11 @@ static int SDL_FlipSurfaceHorizontal(SDL_Surface *surface) } if (surface->h <= 0) { - return 0; + return true; } if (surface->w <= 1) { - return 0; + return true; } bpp = SDL_BYTESPERPIXEL(surface->format); @@ -1807,17 +1801,17 @@ static int SDL_FlipSurfaceHorizontal(SDL_Surface *surface) row += surface->pitch; } SDL_small_free(tmp, isstack); - return 0; + return true; } -static int SDL_FlipSurfaceVertical(SDL_Surface *surface) +static bool SDL_FlipSurfaceVertical(SDL_Surface *surface) { bool isstack; Uint8 *a, *b, *tmp; int i; if (surface->h <= 1) { - return 0; + return true; } a = (Uint8 *)surface->pixels; @@ -1831,16 +1825,16 @@ static int SDL_FlipSurfaceVertical(SDL_Surface *surface) b -= surface->pitch; } SDL_small_free(tmp, isstack); - return 0; + return true; } -int SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip) +SDL_bool SDL_FlipSurface(SDL_Surface *surface, SDL_FlipMode flip) { if (!SDL_SurfaceValid(surface)) { return SDL_InvalidParamError("surface"); } if (!surface->pixels) { - return 0; + return true; } switch (flip) { @@ -1862,7 +1856,7 @@ SDL_Surface *SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelForm Uint32 copy_flags; SDL_Color copy_color; SDL_Rect bounds; - int ret; + bool result; bool palette_ck_transform = false; Uint8 palette_ck_value = 0; Uint8 *palette_saved_alpha = NULL; @@ -1917,7 +1911,7 @@ SDL_Surface *SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelForm SDL_SetSurfaceColorspace(convert, colorspace); if (SDL_ISPIXELFORMAT_FOURCC(format) || SDL_ISPIXELFORMAT_FOURCC(surface->format)) { - if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format, src_colorspace, src_properties, surface->pixels, surface->pitch, convert->format, colorspace, props, convert->pixels, convert->pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format, src_colorspace, src_properties, surface->pixels, surface->pitch, convert->format, colorspace, props, convert->pixels, convert->pitch)) { goto error; } @@ -1984,7 +1978,7 @@ SDL_Surface *SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelForm } } - ret = SDL_BlitSurfaceUnchecked(surface, &bounds, convert, &bounds); + result = SDL_BlitSurfaceUnchecked(surface, &bounds, convert, &bounds); // Restore colorkey alpha value if (palette_ck_transform) { @@ -2017,7 +2011,7 @@ SDL_Surface *SDL_ConvertSurfaceAndColorspace(SDL_Surface *surface, SDL_PixelForm SDL_InvalidateMap(&surface->internal->map); // SDL_BlitSurfaceUnchecked failed, and so the conversion - if (ret < 0) { + if (!result) { goto error; } @@ -2109,7 +2103,7 @@ end: // Copy alternate images for (int i = 0; i < surface->internal->num_images; ++i) { - if (SDL_AddSurfaceAlternateImage(convert, surface->internal->images[i]) < 0) { + if (!SDL_AddSurfaceAlternateImage(convert, surface->internal->images[i])) { goto error; } } @@ -2142,7 +2136,7 @@ SDL_Surface *SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_S SDL_Surface *convert = NULL; Uint32 copy_flags; SDL_Color copy_color; - int ret; + bool rc; if (!SDL_SurfaceValid(surface)) { SDL_InvalidParamError("surface"); @@ -2189,7 +2183,7 @@ SDL_Surface *SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_S surface->internal->map.info.flags = (copy_flags & (SDL_COPY_RLE_COLORKEY | SDL_COPY_RLE_ALPHAKEY)); SDL_InvalidateMap(&surface->internal->map); - ret = SDL_BlitSurfaceScaled(surface, NULL, convert, NULL, scaleMode); + rc = SDL_BlitSurfaceScaled(surface, NULL, convert, NULL, scaleMode); // Clean up the original surface, and update converted surface convert->internal->map.info.r = copy_color.r; @@ -2205,7 +2199,7 @@ SDL_Surface *SDL_ScaleSurface(SDL_Surface *surface, int width, int height, SDL_S SDL_InvalidateMap(&surface->internal->map); // SDL_BlitSurfaceScaled failed, and so the conversion - if (ret < 0) { + if (!rc) { goto error; } @@ -2248,7 +2242,7 @@ SDL_Surface *SDL_DuplicatePixels(int width, int height, SDL_PixelFormat format, return surface; } -int SDL_ConvertPixelsAndColorspace(int width, int height, +SDL_bool SDL_ConvertPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch) { @@ -2257,7 +2251,7 @@ int SDL_ConvertPixelsAndColorspace(int width, int height, SDL_Surface *dst_surface; SDL_Rect rect; void *nonconst_src = (void *)src; - int ret; + bool result; if (!src) { return SDL_InvalidParamError("src"); @@ -2303,18 +2297,18 @@ int SDL_ConvertPixelsAndColorspace(int width, int height, src = (const Uint8 *)src + src_pitch; dst = (Uint8 *)dst + dst_pitch; } - return 0; + return true; } src_surface = SDL_InitializeSurface(&src_data, width, height, src_format, src_colorspace, src_properties, nonconst_src, src_pitch, true); if (!src_surface) { - return -1; + return false; } SDL_SetSurfaceBlendMode(src_surface, SDL_BLENDMODE_NONE); dst_surface = SDL_InitializeSurface(&dst_data, width, height, dst_format, dst_colorspace, dst_properties, dst, dst_pitch, true); if (!dst_surface) { - return -1; + return false; } // Set up the rect and go! @@ -2322,17 +2316,15 @@ int SDL_ConvertPixelsAndColorspace(int width, int height, rect.y = 0; rect.w = width; rect.h = height; - ret = SDL_BlitSurfaceUnchecked(src_surface, &rect, dst_surface, &rect); + result = SDL_BlitSurfaceUnchecked(src_surface, &rect, dst_surface, &rect); SDL_DestroySurface(src_surface); SDL_DestroySurface(dst_surface); - return ret; + return result; } -int SDL_ConvertPixels(int width, int height, - SDL_PixelFormat src_format, const void *src, int src_pitch, - SDL_PixelFormat dst_format, void *dst, int dst_pitch) +SDL_bool SDL_ConvertPixels(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch) { return SDL_ConvertPixelsAndColorspace(width, height, src_format, SDL_COLORSPACE_UNKNOWN, 0, src, src_pitch, @@ -2438,14 +2430,14 @@ static void SDL_PremultiplyAlpha_AXYZ128(int width, int height, const void *src, } } -static int SDL_PremultiplyAlphaPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch, bool linear) +static bool SDL_PremultiplyAlphaPixelsAndColorspace(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch, bool linear) { SDL_Surface *convert = NULL; void *final_dst = dst; int final_dst_pitch = dst_pitch; SDL_PixelFormat format; SDL_Colorspace colorspace; - int result = -1; + bool result = false; if (!src) { return SDL_InvalidParamError("src"); @@ -2491,7 +2483,7 @@ static int SDL_PremultiplyAlphaPixelsAndColorspace(int width, int height, SDL_Pi if (!convert) { goto done; } - if (SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, format, colorspace, 0, convert->pixels, convert->pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, format, colorspace, 0, convert->pixels, convert->pitch)) { goto done; } @@ -2528,11 +2520,11 @@ static int SDL_PremultiplyAlphaPixelsAndColorspace(int width, int height, SDL_Pi } if (dst != final_dst) { - if (SDL_ConvertPixelsAndColorspace(width, height, format, colorspace, 0, convert->pixels, convert->pitch, dst_format, dst_colorspace, dst_properties, final_dst, final_dst_pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(width, height, format, colorspace, 0, convert->pixels, convert->pitch, dst_format, dst_colorspace, dst_properties, final_dst, final_dst_pitch)) { goto done; } } - result = 0; + result = true; done: if (convert) { @@ -2541,7 +2533,7 @@ done: return result; } -int SDL_PremultiplyAlpha(int width, int height, +SDL_bool SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, SDL_bool linear) { @@ -2551,7 +2543,7 @@ int SDL_PremultiplyAlpha(int width, int height, return SDL_PremultiplyAlphaPixelsAndColorspace(width, height, src_format, src_colorspace, 0, src, src_pitch, dst_format, dst_colorspace, 0, dst, dst_pitch, linear); } -int SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear) +SDL_bool SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear) { SDL_Colorspace colorspace; @@ -2564,10 +2556,10 @@ int SDL_PremultiplySurfaceAlpha(SDL_Surface *surface, SDL_bool linear) return SDL_PremultiplyAlphaPixelsAndColorspace(surface->w, surface->h, surface->format, colorspace, surface->internal->props, surface->pixels, surface->pitch, surface->format, colorspace, surface->internal->props, surface->pixels, surface->pitch, linear); } -int SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a) +SDL_bool SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a) { SDL_Rect clip_rect; - int result = -1; + bool result = false; if (!SDL_SurfaceValid(surface)) { return SDL_InvalidParamError("surface"); @@ -2593,7 +2585,7 @@ int SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a) goto done; } - if (SDL_ClearSurface(tmp, r, g, b, a) == 0) { + if (SDL_ClearSurface(tmp, r, g, b, a)) { result = SDL_ConvertPixelsAndColorspace(surface->w, surface->h, tmp->format, tmp->internal->colorspace, tmp->internal->props, tmp->pixels, tmp->pitch, surface->format, surface->internal->colorspace, surface->internal->props, surface->pixels, surface->pitch); } SDL_DestroySurface(tmp); @@ -2630,19 +2622,19 @@ Uint32 SDL_MapSurfaceRGBA(SDL_Surface *surface, Uint8 r, Uint8 g, Uint8 b, Uint8 { if (!SDL_SurfaceValid(surface)) { SDL_InvalidParamError("surface"); - return 0; + return true; } return SDL_MapRGBA(surface->internal->format, surface->internal->palette, r, g, b, a); } // This function Copyright 2023 Collabora Ltd., contributed to SDL under the ZLib license -int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) +SDL_bool SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a) { Uint32 pixel = 0; size_t bytes_per_pixel; Uint8 unused; Uint8 *p; - int result = -1; + bool result = false; if (r) { *r = 0; @@ -2683,8 +2675,8 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, bytes_per_pixel = SDL_BYTESPERPIXEL(surface->format); if (SDL_MUSTLOCK(surface)) { - if (SDL_LockSurface(surface) < 0) { - return -1; + if (!SDL_LockSurface(surface)) { + return false; } } @@ -2699,7 +2691,7 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, SDL_memcpy(&pixel, p, bytes_per_pixel); #endif SDL_GetRGBA(pixel, surface->internal->format, surface->internal->palette, r, g, b, a); - result = 0; + result = true; } else if (SDL_ISPIXELFORMAT_FOURCC(surface->format)) { // FIXME: We need code to extract a single macroblock from a YUV surface SDL_Surface *converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_ARGB8888); @@ -2711,12 +2703,12 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, // This is really slow, but it gets the job done Uint8 rgba[4]; - if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, surface->internal->colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba)) == 0) { + if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, surface->internal->colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA32, SDL_COLORSPACE_SRGB, 0, rgba, sizeof(rgba))) { *r = rgba[0]; *g = rgba[1]; *b = rgba[2]; *a = rgba[3]; - result = 0; + result = true; } } @@ -2726,10 +2718,10 @@ int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, return result; } -int SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a) +SDL_bool SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, float *g, float *b, float *a) { float unused; - int result = -1; + bool result = false; if (r) { *r = 0.0f; @@ -2770,12 +2762,12 @@ int SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, floa if (SDL_BYTESPERPIXEL(surface->format) <= sizeof(Uint32) && !SDL_ISPIXELFORMAT_FOURCC(surface->format)) { Uint8 r8, g8, b8, a8; - if (SDL_ReadSurfacePixel(surface, x, y, &r8, &g8, &b8, &a8) == 0) { + if (SDL_ReadSurfacePixel(surface, x, y, &r8, &g8, &b8, &a8)) { *r = (float)r8 / 255.0f; *g = (float)g8 / 255.0f; *b = (float)b8 / 255.0f; *a = (float)a8 / 255.0f; - result = 0; + result = true; } } else if (SDL_ISPIXELFORMAT_FOURCC(surface->format)) { // FIXME: We need code to extract a single macroblock from a YUV surface @@ -2790,8 +2782,8 @@ int SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, floa Uint8 *p; if (SDL_MUSTLOCK(surface)) { - if (SDL_LockSurface(surface) < 0) { - return -1; + if (!SDL_LockSurface(surface)) { + return false; } } @@ -2799,17 +2791,17 @@ int SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, floa if (surface->format == SDL_PIXELFORMAT_RGBA128_FLOAT) { SDL_memcpy(rgba, p, sizeof(rgba)); - result = 0; + result = true; } else { SDL_Colorspace src_colorspace = surface->internal->colorspace; SDL_Colorspace dst_colorspace = (src_colorspace == SDL_COLORSPACE_SRGB_LINEAR ? SDL_COLORSPACE_SRGB_LINEAR : SDL_COLORSPACE_SRGB); - if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, src_colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA128_FLOAT, dst_colorspace, 0, rgba, sizeof(rgba)) == 0) { - result = 0; + if (SDL_ConvertPixelsAndColorspace(1, 1, surface->format, src_colorspace, surface->internal->props, p, surface->pitch, SDL_PIXELFORMAT_RGBA128_FLOAT, dst_colorspace, 0, rgba, sizeof(rgba))) { + result = true; } } - if (result == 0) { + if (result) { *r = rgba[0]; *g = rgba[1]; *b = rgba[2]; @@ -2823,12 +2815,12 @@ int SDL_ReadSurfacePixelFloat(SDL_Surface *surface, int x, int y, float *r, floa return result; } -int SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +SDL_bool SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { Uint32 pixel = 0; size_t bytes_per_pixel; Uint8 *p; - int result = -1; + bool result = false; if (!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) { return SDL_InvalidParamError("surface"); @@ -2845,8 +2837,8 @@ int SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, bytes_per_pixel = SDL_BYTESPERPIXEL(surface->format); if (SDL_MUSTLOCK(surface)) { - if (SDL_LockSurface(surface) < 0) { - return -1; + if (!SDL_LockSurface(surface)) { + return false; } } @@ -2859,7 +2851,7 @@ int SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, #else SDL_memcpy(p, &pixel, bytes_per_pixel); #endif - result = 0; + result = true; } else if (SDL_ISPIXELFORMAT_FOURCC(surface->format)) { result = SDL_Unsupported(); } else { @@ -2879,9 +2871,9 @@ int SDL_WriteSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 r, Uint8 g, return result; } -int SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a) +SDL_bool SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, float g, float b, float a) { - int result = -1; + bool result = false; if (!SDL_SurfaceValid(surface) || !surface->format || !surface->pixels) { return SDL_InvalidParamError("surface"); @@ -2902,8 +2894,8 @@ int SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, floa g8 = (Uint8)SDL_round(SDL_clamp(g, 0.0f, 1.0f) * 255.0f); b8 = (Uint8)SDL_round(SDL_clamp(b, 0.0f, 1.0f) * 255.0f); a8 = (Uint8)SDL_round(SDL_clamp(a, 0.0f, 1.0f) * 255.0f); - if (SDL_WriteSurfacePixel(surface, x, y, r8, g8, b8, a8) == 0) { - result = 0; + if (SDL_WriteSurfacePixel(surface, x, y, r8, g8, b8, a8)) { + result = true; } } else if (SDL_ISPIXELFORMAT_FOURCC(surface->format)) { result = SDL_Unsupported(); @@ -2913,8 +2905,8 @@ int SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, floa Uint8 *p; if (SDL_MUSTLOCK(surface)) { - if (SDL_LockSurface(surface) < 0) { - return -1; + if (!SDL_LockSurface(surface)) { + return false; } } @@ -2927,7 +2919,7 @@ int SDL_WriteSurfacePixelFloat(SDL_Surface *surface, int x, int y, float r, floa if (surface->format == SDL_PIXELFORMAT_RGBA128_FLOAT) { SDL_memcpy(p, rgba, sizeof(rgba)); - result = 0; + result = true; } else { SDL_Colorspace dst_colorspace = surface->internal->colorspace; SDL_Colorspace src_colorspace = (dst_colorspace == SDL_COLORSPACE_SRGB_LINEAR ? SDL_COLORSPACE_SRGB_LINEAR : SDL_COLORSPACE_SRGB); diff --git a/src/video/SDL_surface_c.h b/src/video/SDL_surface_c.h index 3c4e4f9c07..ea8022a850 100644 --- a/src/video/SDL_surface_c.h +++ b/src/video/SDL_surface_c.h @@ -81,6 +81,6 @@ extern float SDL_GetSurfaceSDRWhitePoint(SDL_Surface *surface, SDL_Colorspace co extern float SDL_GetDefaultHDRHeadroom(SDL_Colorspace colorspace); extern float SDL_GetSurfaceHDRHeadroom(SDL_Surface *surface, SDL_Colorspace colorspace); extern SDL_Surface *SDL_GetSurfaceImage(SDL_Surface *surface, float display_scale); -extern int SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); +extern bool SDL_SoftStretch(SDL_Surface *src, const SDL_Rect *srcrect, SDL_Surface *dst, const SDL_Rect *dstrect, SDL_ScaleMode scaleMode); #endif // SDL_surface_c_h_ diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index ff17d2b7c5..862405e13b 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -183,6 +183,13 @@ typedef enum SDL_FULLSCREEN_OP_UPDATE } SDL_FullscreenOp; +typedef enum +{ + SDL_FULLSCREEN_FAILED, + SDL_FULLSCREEN_SUCCEEDED, + SDL_FULLSCREEN_PENDING +} SDL_FullscreenResult; + struct SDL_VideoDevice { /* * * */ @@ -196,7 +203,7 @@ struct SDL_VideoDevice * Initialize the native video subsystem, filling in the list of * displays for this driver, returning 0 or -1 if there's an error. */ - int (*VideoInit)(SDL_VideoDevice *_this); + bool (*VideoInit)(SDL_VideoDevice *_this); /* * Reverse the effects VideoInit() -- called if VideoInit() fails or @@ -222,17 +229,17 @@ struct SDL_VideoDevice /* * Get the bounds of a display */ - int (*GetDisplayBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); + bool (*GetDisplayBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); /* * Get the usable bounds of a display (bounds minus menubar or whatever) */ - int (*GetDisplayUsableBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); + bool (*GetDisplayUsableBounds)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); /* * Get a list of the available display modes for a display. */ - int (*GetDisplayModes)(SDL_VideoDevice *_this, SDL_VideoDisplay *display); + bool (*GetDisplayModes)(SDL_VideoDevice *_this, SDL_VideoDisplay *display); /* * Setting the display mode is independent of creating windows, so @@ -240,24 +247,24 @@ struct SDL_VideoDevice * their data updated accordingly, including the display surfaces * associated with them. */ - int (*SetDisplayMode)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); + bool (*SetDisplayMode)(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); /* * * */ /* * Window functions */ - int (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); + bool (*CreateSDLWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); void (*SetWindowTitle)(SDL_VideoDevice *_this, SDL_Window *window); - int (*SetWindowIcon)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); - int (*SetWindowPosition)(SDL_VideoDevice *_this, SDL_Window *window); + bool (*SetWindowIcon)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); + bool (*SetWindowPosition)(SDL_VideoDevice *_this, SDL_Window *window); void (*SetWindowSize)(SDL_VideoDevice *_this, SDL_Window *window); void (*SetWindowMinimumSize)(SDL_VideoDevice *_this, SDL_Window *window); void (*SetWindowMaximumSize)(SDL_VideoDevice *_this, SDL_Window *window); void (*SetWindowAspectRatio)(SDL_VideoDevice *_this, SDL_Window *window); - int (*GetWindowBordersSize)(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right); + bool (*GetWindowBordersSize)(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right); void (*GetWindowSizeInPixels)(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h); - int (*SetWindowOpacity)(SDL_VideoDevice *_this, SDL_Window *window, float opacity); - int (*SetWindowModalFor)(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); + bool (*SetWindowOpacity)(SDL_VideoDevice *_this, SDL_Window *window, float opacity); + bool (*SetWindowModalFor)(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); void (*ShowWindow)(SDL_VideoDevice *_this, SDL_Window *window); void (*HideWindow)(SDL_VideoDevice *_this, SDL_Window *window); void (*RaiseWindow)(SDL_VideoDevice *_this, SDL_Window *window); @@ -267,48 +274,48 @@ struct SDL_VideoDevice void (*SetWindowBordered)(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); void (*SetWindowResizable)(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); void (*SetWindowAlwaysOnTop)(SDL_VideoDevice *_this, SDL_Window *window, bool on_top); - int (*SetWindowFullscreen)(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); + SDL_FullscreenResult (*SetWindowFullscreen)(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); void *(*GetWindowICCProfile)(SDL_VideoDevice *_this, SDL_Window *window, size_t *size); SDL_DisplayID (*GetDisplayForWindow)(SDL_VideoDevice *_this, SDL_Window *window); - int (*SetWindowMouseRect)(SDL_VideoDevice *_this, SDL_Window *window); - int (*SetWindowMouseGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); - int (*SetWindowKeyboardGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); + bool (*SetWindowMouseRect)(SDL_VideoDevice *_this, SDL_Window *window); + bool (*SetWindowMouseGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); + bool (*SetWindowKeyboardGrab)(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); void (*DestroyWindow)(SDL_VideoDevice *_this, SDL_Window *window); - int (*CreateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); - int (*SetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int vsync); - int (*GetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int *vsync); - int (*UpdateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); + bool (*CreateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); + bool (*SetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int vsync); + bool (*GetWindowFramebufferVSync)(SDL_VideoDevice *_this, SDL_Window *window, int *vsync); + bool (*UpdateWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); void (*DestroyWindowFramebuffer)(SDL_VideoDevice *_this, SDL_Window *window); void (*OnWindowEnter)(SDL_VideoDevice *_this, SDL_Window *window); - int (*UpdateWindowShape)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); - int (*FlashWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); - int (*SetWindowFocusable)(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); - int (*SyncWindow)(SDL_VideoDevice *_this, SDL_Window *window); + bool (*UpdateWindowShape)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); + bool (*FlashWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); + bool (*SetWindowFocusable)(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); + bool (*SyncWindow)(SDL_VideoDevice *_this, SDL_Window *window); /* * * */ /* * OpenGL support */ - int (*GL_LoadLibrary)(SDL_VideoDevice *_this, const char *path); + bool (*GL_LoadLibrary)(SDL_VideoDevice *_this, const char *path); SDL_FunctionPointer (*GL_GetProcAddress)(SDL_VideoDevice *_this, const char *proc); void (*GL_UnloadLibrary)(SDL_VideoDevice *_this); SDL_GLContext (*GL_CreateContext)(SDL_VideoDevice *_this, SDL_Window *window); - int (*GL_MakeCurrent)(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); + bool (*GL_MakeCurrent)(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); SDL_EGLSurface (*GL_GetEGLSurface)(SDL_VideoDevice *_this, SDL_Window *window); - int (*GL_SetSwapInterval)(SDL_VideoDevice *_this, int interval); - int (*GL_GetSwapInterval)(SDL_VideoDevice *_this, int *interval); - int (*GL_SwapWindow)(SDL_VideoDevice *_this, SDL_Window *window); - int (*GL_DeleteContext)(SDL_VideoDevice *_this, SDL_GLContext context); + bool (*GL_SetSwapInterval)(SDL_VideoDevice *_this, int interval); + bool (*GL_GetSwapInterval)(SDL_VideoDevice *_this, int *interval); + bool (*GL_SwapWindow)(SDL_VideoDevice *_this, SDL_Window *window); + bool (*GL_DestroyContext)(SDL_VideoDevice *_this, SDL_GLContext context); void (*GL_DefaultProfileConfig)(SDL_VideoDevice *_this, int *mask, int *major, int *minor); /* * * */ /* * Vulkan support */ - int (*Vulkan_LoadLibrary)(SDL_VideoDevice *_this, const char *path); + bool (*Vulkan_LoadLibrary)(SDL_VideoDevice *_this, const char *path); void (*Vulkan_UnloadLibrary)(SDL_VideoDevice *_this); char const* const* (*Vulkan_GetInstanceExtensions)(SDL_VideoDevice *_this, Uint32 *count); - int (*Vulkan_CreateSurface)(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); + bool (*Vulkan_CreateSurface)(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); void (*Vulkan_DestroySurface)(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); bool (*Vulkan_GetPresentationSupport)(SDL_VideoDevice *_this, VkInstance instance, VkPhysicalDevice physicalDevice, Uint32 queueFamilyIndex); @@ -328,14 +335,14 @@ struct SDL_VideoDevice void (*SendWakeupEvent)(SDL_VideoDevice *_this, SDL_Window *window); void (*PumpEvents)(SDL_VideoDevice *_this); - // Suspend the screensaver - int (*SuspendScreenSaver)(SDL_VideoDevice *_this); + // Suspend/resume the screensaver + bool (*SuspendScreenSaver)(SDL_VideoDevice *_this); // Text input - int (*StartTextInput)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); - int (*StopTextInput)(SDL_VideoDevice *_this, SDL_Window *window); - int (*UpdateTextInputArea)(SDL_VideoDevice *_this, SDL_Window *window); - int (*ClearComposition)(SDL_VideoDevice *_this, SDL_Window *window); + bool (*StartTextInput)(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); + bool (*StopTextInput)(SDL_VideoDevice *_this, SDL_Window *window); + bool (*UpdateTextInputArea)(SDL_VideoDevice *_this, SDL_Window *window); + bool (*ClearComposition)(SDL_VideoDevice *_this, SDL_Window *window); // Screen keyboard bool (*HasScreenKeyboardSupport)(SDL_VideoDevice *_this); @@ -345,23 +352,23 @@ struct SDL_VideoDevice // Clipboard const char **(*GetTextMimeTypes)(SDL_VideoDevice *_this, size_t *num_mime_types); - int (*SetClipboardData)(SDL_VideoDevice *_this); + bool (*SetClipboardData)(SDL_VideoDevice *_this); void *(*GetClipboardData)(SDL_VideoDevice *_this, const char *mime_type, size_t *size); bool (*HasClipboardData)(SDL_VideoDevice *_this, const char *mime_type); /* If you implement *ClipboardData, you don't need to implement *ClipboardText */ - int (*SetClipboardText)(SDL_VideoDevice *_this, const char *text); + bool (*SetClipboardText)(SDL_VideoDevice *_this, const char *text); char *(*GetClipboardText)(SDL_VideoDevice *_this); bool (*HasClipboardText)(SDL_VideoDevice *_this); // These functions are only needed if the platform has a separate primary selection buffer - int (*SetPrimarySelectionText)(SDL_VideoDevice *_this, const char *text); + bool (*SetPrimarySelectionText)(SDL_VideoDevice *_this, const char *text); char *(*GetPrimarySelectionText)(SDL_VideoDevice *_this); bool (*HasPrimarySelectionText)(SDL_VideoDevice *_this); // MessageBox - int (*ShowMessageBox)(SDL_VideoDevice *_this, const SDL_MessageBoxData *messageboxdata, int *buttonID); + bool (*ShowMessageBox)(SDL_VideoDevice *_this, const SDL_MessageBoxData *messageboxdata, int *buttonID); // Hit-testing - int (*SetWindowHitTest)(SDL_Window *window, bool enabled); + bool (*SetWindowHitTest)(SDL_Window *window, bool enabled); // Tell window that app enabled drag'n'drop events void (*AcceptDragAndDrop)(SDL_Window *window, bool accept); @@ -483,7 +490,7 @@ typedef struct VideoBootStrap const char *name; const char *desc; SDL_VideoDevice *(*create)(void); - int (*ShowMessageBox)(const SDL_MessageBoxData *messageboxdata, int *buttonID); // can be done without initializing backend! + bool (*ShowMessageBox)(const SDL_MessageBoxData *messageboxdata, int *buttonID); // can be done without initializing backend! } VideoBootStrap; // Not all of these are available in a given build. Use #ifdefs, etc. @@ -524,7 +531,7 @@ extern void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_Displ extern void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode); extern void SDL_SetDisplayContentScale(SDL_VideoDisplay *display, float scale); extern void SDL_SetDisplayHDRProperties(SDL_VideoDisplay *display, const SDL_HDROutputProperties *HDR); -extern int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode); extern SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID display); extern SDL_DisplayID SDL_GetDisplayForWindowPosition(SDL_Window *window); extern SDL_VideoDisplay *SDL_GetVideoDisplayForWindow(SDL_Window *window); @@ -538,7 +545,7 @@ extern void SDL_SetWindowSafeAreaInsets(SDL_Window *window, int left, int right, extern void SDL_GL_DeduceMaxSupportedESProfile(int *major, int *minor); -extern int SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags); +extern bool SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags); extern bool SDL_HasWindows(void); extern void SDL_RelativeToGlobalForWindow(SDL_Window *window, int rel_x, int rel_y, int *abs_x, int *abs_y); extern void SDL_GlobalToRelativeForWindow(SDL_Window *window, int abs_x, int abs_y, int *rel_x, int *rel_y); @@ -560,7 +567,7 @@ extern void SDL_OnWindowFocusGained(SDL_Window *window); extern void SDL_OnWindowFocusLost(SDL_Window *window); extern void SDL_OnWindowDisplayChanged(SDL_Window *window); extern void SDL_UpdateWindowGrab(SDL_Window *window); -extern int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bool commit); +extern bool SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bool commit); extern SDL_Window *SDL_GetToplevelForKeyboardFocus(void); extern bool SDL_ShouldAllowTopmost(void); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 93666fb0db..e0c118f711 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -139,25 +139,25 @@ static VideoBootStrap *bootstrap[] = { NULL }; -#define CHECK_WINDOW_MAGIC(window, retval) \ +#define CHECK_WINDOW_MAGIC(window, result) \ if (!_this) { \ SDL_UninitializedVideo(); \ - return retval; \ + return result; \ } \ if (!SDL_ObjectValid(window, SDL_OBJECT_TYPE_WINDOW)) { \ SDL_SetError("Invalid window"); \ - return retval; \ + return result; \ } -#define CHECK_DISPLAY_MAGIC(display, retval) \ +#define CHECK_DISPLAY_MAGIC(display, result) \ if (!display) { \ - return retval; \ + return result; \ } \ -#define CHECK_WINDOW_NOT_POPUP(window, retval) \ +#define CHECK_WINDOW_NOT_POPUP(window, result) \ if (SDL_WINDOW_IS_POPUP(window)) { \ SDL_SetError("Operation invalid on popup windows"); \ - return retval; \ + return result; \ } #if defined(SDL_PLATFORM_MACOS) && defined(SDL_VIDEO_DRIVER_COCOA) @@ -288,7 +288,7 @@ static void SDLCALL SDL_CleanupWindowTextureData(void *userdata, void *value) SDL_free(data); } -static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +static bool SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_PropertiesID props = SDL_GetWindowProperties(window); SDL_WindowTextureData *data = (SDL_WindowTextureData *)SDL_GetPointerProperty(props, SDL_PROP_WINDOW_TEXTUREDATA_POINTER, NULL); @@ -325,7 +325,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S renderer = SDL_CreateRenderer(window, render_driver); if (!renderer) { // The error for this specific renderer has already been set - return -1; + return false; } } else { const int total = SDL_GetNumRenderDrivers(); @@ -349,11 +349,11 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S data = (SDL_WindowTextureData *)SDL_calloc(1, sizeof(*data)); if (!data) { SDL_DestroyRenderer(renderer); - return -1; + return false; } - if (SDL_SetPointerPropertyWithCleanup(props, SDL_PROP_WINDOW_TEXTUREDATA_POINTER, data, SDL_CleanupWindowTextureData, NULL) < 0) { + if (!SDL_SetPointerPropertyWithCleanup(props, SDL_PROP_WINDOW_TEXTUREDATA_POINTER, data, SDL_CleanupWindowTextureData, NULL)) { SDL_DestroyRenderer(renderer); - return -1; + return false; } data->renderer = renderer; @@ -361,7 +361,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S texture_formats = (const SDL_PixelFormat *)SDL_GetPointerProperty(SDL_GetRendererProperties(data->renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL); if (!texture_formats) { - return -1; + return false; } // Free any old texture and pixel data @@ -391,7 +391,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S w, h); if (!data->texture) { // codechecker_false_positive [Malloc] Static analyzer doesn't realize allocated `data` is saved to SDL_PROP_WINDOW_TEXTUREDATA_POINTER and not leaked here. - return -1; // NOLINT(clang-analyzer-unix.Malloc) + return false; // NOLINT(clang-analyzer-unix.Malloc) } // Create framebuffer data @@ -403,7 +403,7 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S const size_t allocsize = (size_t)h * data->pitch; data->pixels = SDL_malloc((allocsize > 0) ? allocsize : 1); if (!data->pixels) { - return -1; + return false; } } @@ -413,38 +413,38 @@ static int SDL_CreateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, S // Make sure we're not double-scaling the viewport SDL_SetRenderViewport(data->renderer, NULL); - return 0; + return true; } -int SDL_SetWindowTextureVSync(SDL_VideoDevice *_this, SDL_Window *window, int vsync) +bool SDL_SetWindowTextureVSync(SDL_VideoDevice *_this, SDL_Window *window, int vsync) { SDL_WindowTextureData *data; data = (SDL_WindowTextureData *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_TEXTUREDATA_POINTER, NULL); if (!data) { - return -1; + return false; } if (!data->renderer) { - return -1; + return false; } return SDL_SetRenderVSync(data->renderer, vsync); } -static int SDL_GetWindowTextureVSync(SDL_VideoDevice *_this, SDL_Window *window, int *vsync) +static bool SDL_GetWindowTextureVSync(SDL_VideoDevice *_this, SDL_Window *window, int *vsync) { SDL_WindowTextureData *data; data = (SDL_WindowTextureData *)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_TEXTUREDATA_POINTER, NULL); if (!data) { - return -1; + return false; } if (!data->renderer) { - return -1; + return false; } return SDL_GetRenderVSync(data->renderer, vsync); } -static int SDL_UpdateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +static bool SDL_UpdateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { SDL_WindowTextureData *data; SDL_Rect rect; @@ -463,17 +463,17 @@ static int SDL_UpdateWindowTexture(SDL_VideoDevice *_this, SDL_Window *window, c src = (void *)((Uint8 *)data->pixels + rect.y * data->pitch + rect.x * data->bytes_per_pixel); - if (SDL_UpdateTexture(data->texture, &rect, src, data->pitch) < 0) { - return -1; + if (!SDL_UpdateTexture(data->texture, &rect, src, data->pitch)) { + return false; } - if (SDL_RenderTexture(data->renderer, data->texture, NULL, NULL) < 0) { - return -1; + if (!SDL_RenderTexture(data->renderer, data->texture, NULL, NULL)) { + return false; } SDL_RenderPresent(data->renderer); } - return 0; + return true; } static void SDL_DestroyWindowTexture(SDL_VideoDevice *_this, SDL_Window *window) @@ -509,7 +509,7 @@ static int SDLCALL cmpmodes(const void *A, const void *B) return 0; } -static int SDL_UninitializedVideo(void) +static bool SDL_UninitializedVideo(void) { return SDL_SetError("Video subsystem has not been initialized"); } @@ -556,7 +556,7 @@ const char *SDL_GetVideoDriver(int index) /* * Initialize the video and event subsystems -- determine native pixel format */ -int SDL_VideoInit(const char *driver_name) +bool SDL_VideoInit(const char *driver_name) { SDL_VideoDevice *video; bool init_events = false; @@ -574,23 +574,23 @@ int SDL_VideoInit(const char *driver_name) SDL_InitTicks(); // Start the event loop - if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) { + if (!SDL_InitSubSystem(SDL_INIT_EVENTS)) { goto pre_driver_error; } init_events = true; - if (SDL_InitKeyboard() < 0) { + if (!SDL_InitKeyboard()) { goto pre_driver_error; } init_keyboard = true; - if (SDL_PreInitMouse() < 0) { + if (!SDL_PreInitMouse()) { goto pre_driver_error; } init_mouse = true; - if (SDL_InitTouch() < 0) { + if (!SDL_InitTouch()) { goto pre_driver_error; } init_touch = true; - if (SDL_InitPen() < 0) { + if (!SDL_InitPen()) { goto pre_driver_error; } init_pen = true; @@ -648,9 +648,9 @@ int SDL_VideoInit(const char *driver_name) SDL_GL_ResetAttributes(); // Initialize the video subsystem - if (_this->VideoInit(_this) < 0) { + if (!_this->VideoInit(_this)) { SDL_VideoQuit(); - return -1; + return false; } // Make sure some displays were added @@ -674,7 +674,7 @@ int SDL_VideoInit(const char *driver_name) SDL_PostInitMouse(); // We're ready to go! - return 0; + return true; pre_driver_error: SDL_assert(_this == NULL); @@ -693,7 +693,7 @@ pre_driver_error: if (init_events) { SDL_QuitSubSystem(SDL_INIT_EVENTS); } - return -1; + return false; } const char *SDL_GetCurrentVideoDriver(void) @@ -741,7 +741,7 @@ static void SDL_UpdateDesktopBounds(void) if (displays) { for (int i = 0; displays[i]; ++i) { SDL_Rect bounds; - if (SDL_GetDisplayBounds(displays[i], &bounds) == 0) { + if (SDL_GetDisplayBounds(displays[i], &bounds)) { if (i == 0) { SDL_copyp(&rect, &bounds); } else { @@ -792,13 +792,13 @@ SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, bool send_eve new_display = (SDL_VideoDisplay *)SDL_malloc(sizeof(*new_display)); if (!new_display) { - return 0; + return true; } displays = (SDL_VideoDisplay **)SDL_realloc(_this->displays, (_this->num_displays + 1) * sizeof(*displays)); if (!displays) { SDL_free(new_display); - return 0; + return true; } _this->displays = displays; _this->displays[_this->num_displays++] = new_display; @@ -940,7 +940,7 @@ SDL_DisplayID SDL_GetPrimaryDisplay(void) { if (!_this || _this->num_displays == 0) { SDL_UninitializedVideo(); - return 0; + return true; } return _this->displays[0]->id; } @@ -958,7 +958,8 @@ int SDL_GetDisplayIndex(SDL_DisplayID displayID) return display_index; } } - return SDL_SetError("Invalid display"); + SDL_SetError("Invalid display"); + return -1; } SDL_DisplayData *SDL_GetDisplayDriverData(SDL_DisplayID displayID) @@ -996,19 +997,19 @@ const char *SDL_GetDisplayName(SDL_DisplayID displayID) return display->name; } -int SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect) +SDL_bool SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect) { SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_MAGIC(display, -1); + CHECK_DISPLAY_MAGIC(display, false); if (!rect) { return SDL_InvalidParamError("rect"); } if (_this->GetDisplayBounds) { - if (_this->GetDisplayBounds(_this, display, rect) == 0) { - return 0; + if (_this->GetDisplayBounds(_this, display, rect)) { + return true; } } @@ -1022,7 +1023,7 @@ int SDL_GetDisplayBounds(SDL_DisplayID displayID, SDL_Rect *rect) } rect->w = display->current_mode->w; rect->h = display->current_mode->h; - return 0; + return true; } static int ParseDisplayUsableBoundsHint(SDL_Rect *rect) @@ -1031,23 +1032,23 @@ static int ParseDisplayUsableBoundsHint(SDL_Rect *rect) return hint && (SDL_sscanf(hint, "%d,%d,%d,%d", &rect->x, &rect->y, &rect->w, &rect->h) == 4); } -int SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect) +SDL_bool SDL_GetDisplayUsableBounds(SDL_DisplayID displayID, SDL_Rect *rect) { SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); - CHECK_DISPLAY_MAGIC(display, -1); + CHECK_DISPLAY_MAGIC(display, false); if (!rect) { return SDL_InvalidParamError("rect"); } if (displayID == SDL_GetPrimaryDisplay() && ParseDisplayUsableBoundsHint(rect)) { - return 0; + return true; } if (_this->GetDisplayUsableBounds) { - if (_this->GetDisplayUsableBounds(_this, display, rect) == 0) { - return 0; + if (_this->GetDisplayUsableBounds(_this, display, rect)) { + return true; } } @@ -1271,7 +1272,7 @@ SDL_DisplayMode **SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *co { int i; int num_modes; - SDL_DisplayMode **retval; + SDL_DisplayMode **result; SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); if (count) { @@ -1283,14 +1284,14 @@ SDL_DisplayMode **SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *co SDL_UpdateFullscreenDisplayModes(display); num_modes = display->num_fullscreen_modes; - retval = (SDL_DisplayMode **)SDL_malloc((num_modes + 1) * sizeof(*retval) + num_modes * sizeof(**retval)); - if (retval) { - SDL_DisplayMode *modes = (SDL_DisplayMode *)((Uint8 *)retval + ((num_modes + 1) * sizeof(*retval))); + result = (SDL_DisplayMode **)SDL_malloc((num_modes + 1) * sizeof(*result) + num_modes * sizeof(**result)); + if (result) { + SDL_DisplayMode *modes = (SDL_DisplayMode *)((Uint8 *)result + ((num_modes + 1) * sizeof(*result))); SDL_memcpy(modes, display->fullscreen_modes, num_modes * sizeof(*modes)); for (i = 0; i < num_modes; ++i) { - retval[i] = modes++; + result[i] = modes++; } - retval[i] = NULL; + result[i] = NULL; if (count) { *count = num_modes; @@ -1300,10 +1301,10 @@ SDL_DisplayMode **SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *co *count = 0; } } - return retval; + return result; } -int SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode *result) +SDL_bool SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode *result) { const SDL_DisplayMode *mode, *closest = NULL; float aspect_ratio; @@ -1314,7 +1315,7 @@ int SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, f SDL_zerop(result); } - CHECK_DISPLAY_MAGIC(display, -1); + CHECK_DISPLAY_MAGIC(display, false); if (h > 0) { aspect_ratio = (float)w / h; @@ -1367,7 +1368,7 @@ int SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, f if (result) { SDL_copyp(result, closest); } - return 0; + return true; } static bool DisplayModeChanged(const SDL_DisplayMode *old, const SDL_DisplayMode *new) @@ -1438,14 +1439,14 @@ const SDL_DisplayMode *SDL_GetCurrentDisplayMode(SDL_DisplayID displayID) return display->current_mode; } -int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode) +bool SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode) { /* Mode switching is being emulated per-window; nothing to do and cannot fail, * except for XWayland, which still needs the actual mode setting call since * it's emulated via the XRandR interface. */ if (SDL_ModeSwitchingEmulated(_this) && SDL_strcmp(_this->name, "x11") != 0) { - return 0; + return true; } if (!mode) { @@ -1453,24 +1454,24 @@ int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mod } if (mode == display->current_mode) { - return 0; + return true; } // Actually change the display mode if (_this->SetDisplayMode) { - int result; + bool result; _this->setting_display_mode = true; result = _this->SetDisplayMode(_this, display, mode); _this->setting_display_mode = false; - if (result < 0) { - return -1; + if (!result) { + return false; } } SDL_SetCurrentDisplayMode(display, mode); - return 0; + return true; } /** @@ -1721,8 +1722,8 @@ float SDL_GetWindowPixelDensity(SDL_Window *window) CHECK_WINDOW_MAGIC(window, 0.0f); - if (SDL_GetWindowSize(window, &window_w, &window_h) == 0 && - SDL_GetWindowSizeInPixels(window, &pixel_w, &pixel_h) == 0) { + if (SDL_GetWindowSize(window, &window_w, &window_h) && + SDL_GetWindowSizeInPixels(window, &pixel_w, &pixel_h)) { pixel_density = (float)pixel_w / window_w; } return pixel_density; @@ -1768,13 +1769,13 @@ static void SDL_RestoreMousePosition(SDL_Window *window) } } -int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bool commit) +bool SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bool commit) { SDL_VideoDisplay *display = NULL; SDL_DisplayMode *mode = NULL; int i; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); window->fullscreen_exclusive = false; @@ -1901,23 +1902,23 @@ int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bo SDL_MinimizeWindow(display->fullscreen_window); } - if (SDL_SetDisplayModeForDisplay(display, mode) < 0) { + if (!SDL_SetDisplayModeForDisplay(display, mode)) { goto error; } if (commit) { - int ret = 0; + SDL_FullscreenResult ret = SDL_FULLSCREEN_SUCCEEDED; if (_this->SetWindowFullscreen) { ret = _this->SetWindowFullscreen(_this, window, display, fullscreen); } else { resized = true; } - if (ret == 0) { + if (ret == SDL_FULLSCREEN_SUCCEEDED) { // Window is fullscreen immediately upon return. If the driver hasn't already sent the event, do so now. if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_ENTER_FULLSCREEN, 0, 0); } - } else if (ret < 0) { + } else if (ret == SDL_FULLSCREEN_FAILED) { goto error; } } @@ -1965,7 +1966,7 @@ int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bo SDL_SetDisplayModeForDisplay(display, NULL); } if (commit) { - int ret = 0; + SDL_FullscreenResult ret = SDL_FULLSCREEN_SUCCEEDED; if (_this->SetWindowFullscreen) { SDL_VideoDisplay *full_screen_display = display ? display : SDL_GetVideoDisplayForFullscreenWindow(window); if (full_screen_display) { @@ -1975,12 +1976,12 @@ int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bo resized = true; } - if (ret == 0) { + if (ret == SDL_FULLSCREEN_SUCCEEDED) { // Window left fullscreen immediately upon return. If the driver hasn't already sent the event, do so now. if (window->flags & SDL_WINDOW_FULLSCREEN) { SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_LEAVE_FULLSCREEN, 0, 0); } - } else if (ret < 0) { + } else if (ret == SDL_FULLSCREEN_FAILED) { goto error; } } @@ -2007,20 +2008,20 @@ int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, bo done: window->last_fullscreen_exclusive_display = display && (window->flags & SDL_WINDOW_FULLSCREEN) && window->fullscreen_exclusive ? display->id : 0; - return 0; + return true; error: if (fullscreen) { // Something went wrong and the window is no longer fullscreen. SDL_UpdateFullscreenMode(window, SDL_FULLSCREEN_OP_LEAVE, commit); } - return -1; + return false; } -int SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode) +SDL_bool SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (mode) { if (!SDL_GetFullscreenModeMatch(mode)) { @@ -2042,7 +2043,7 @@ int SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode) SDL_SyncIfRequired(window); } - return 0; + return true; } const SDL_DisplayMode *SDL_GetWindowFullscreenMode(SDL_Window *window) @@ -2190,7 +2191,7 @@ static void SDL_FinishWindowCreation(SDL_Window *window, SDL_WindowFlags flags) } } -static int SDL_ContextNotSupported(const char *name) +static bool SDL_ContextNotSupported(const char *name) { return SDL_SetError("%s support is either not configured in SDL " "or not available in current SDL video driver " @@ -2199,7 +2200,7 @@ static int SDL_ContextNotSupported(const char *name) _this->name); } -static int SDL_DllNotSupported(const char *name) +static bool SDL_DllNotSupported(const char *name) { return SDL_SetError("No dynamic %s support in current SDL video driver (%s)", name, _this->name); } @@ -2265,7 +2266,7 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props) if (!_this) { // Initialize the video system if needed - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { return NULL; } @@ -2367,7 +2368,7 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props) SDL_ContextNotSupported("OpenGL"); return NULL; } - if (SDL_GL_LoadLibrary(NULL) < 0) { + if (!SDL_GL_LoadLibrary(NULL)) { return NULL; } } @@ -2377,7 +2378,7 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props) SDL_ContextNotSupported("Vulkan"); return NULL; } - if (SDL_Vulkan_LoadLibrary(NULL) < 0) { + if (!SDL_Vulkan_LoadLibrary(NULL)) { return NULL; } } @@ -2435,7 +2436,7 @@ SDL_Window *SDL_CreateWindowWithProperties(SDL_PropertiesID props) SDL_SetWindowParent(window, parent); } - if (_this->CreateSDLWindow && _this->CreateSDLWindow(_this, window, props) < 0) { + if (_this->CreateSDLWindow && !_this->CreateSDLWindow(_this, window, props)) { SDL_DestroyWindow(window); return NULL; } @@ -2514,7 +2515,7 @@ SDL_Window *SDL_CreatePopupWindow(SDL_Window *parent, int offset_x, int offset_y return window; } -int SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags) +bool SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags) { bool loaded_opengl = false; bool need_gl_unload = false; @@ -2598,15 +2599,15 @@ int SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags) } if (need_gl_load) { - if (SDL_GL_LoadLibrary(NULL) < 0) { - return -1; + if (!SDL_GL_LoadLibrary(NULL)) { + return false; } loaded_opengl = true; } if (need_vulkan_load) { - if (SDL_Vulkan_LoadLibrary(NULL) < 0) { - return -1; + if (!SDL_Vulkan_LoadLibrary(NULL)) { + return false; } loaded_vulkan = true; } @@ -2623,7 +2624,7 @@ int SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags) window->w = window->windowed.w = window->floating.w; window->h = window->windowed.h = window->floating.h; - if (_this->CreateSDLWindow(_this, window, 0) < 0) { + if (!_this->CreateSDLWindow(_this, window, 0)) { if (loaded_opengl) { SDL_GL_UnloadLibrary(); window->flags &= ~SDL_WINDOW_OPENGL; @@ -2632,7 +2633,7 @@ int SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags) SDL_Vulkan_UnloadLibrary(); window->flags &= ~SDL_WINDOW_VULKAN; } - return -1; + return false; } } @@ -2670,7 +2671,7 @@ int SDL_RecreateWindow(SDL_Window *window, SDL_WindowFlags flags) SDL_FinishWindowCreation(window, flags); - return 0; + return true; } bool SDL_HasWindows(void) @@ -2728,13 +2729,13 @@ SDL_WindowFlags SDL_GetWindowFlags(SDL_Window *window) return window->flags | window->pending_flags; } -int SDL_SetWindowTitle(SDL_Window *window, const char *title) +SDL_bool SDL_SetWindowTitle(SDL_Window *window, const char *title) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (title == window->title) { - return 0; + return true; } SDL_free(window->title); @@ -2743,7 +2744,7 @@ int SDL_SetWindowTitle(SDL_Window *window, const char *title) if (_this->SetWindowTitle) { _this->SetWindowTitle(_this, window); } - return 0; + return true; } const char *SDL_GetWindowTitle(SDL_Window *window) @@ -2753,9 +2754,9 @@ const char *SDL_GetWindowTitle(SDL_Window *window) return window->title ? window->title : ""; } -int SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon) +SDL_bool SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!icon) { return SDL_InvalidParamError("icon"); @@ -2766,7 +2767,7 @@ int SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon) // Convert the icon into ARGB8888 window->icon = SDL_ConvertSurface(icon, SDL_PIXELFORMAT_ARGB8888); if (!window->icon) { - return -1; + return false; } if (!_this->SetWindowIcon) { @@ -2776,11 +2777,11 @@ int SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon) return _this->SetWindowIcon(_this, window, window->icon); } -int SDL_SetWindowPosition(SDL_Window *window, int x, int y) +SDL_bool SDL_SetWindowPosition(SDL_Window *window, int x, int y) { SDL_DisplayID original_displayID; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); original_displayID = SDL_GetDisplayForWindow(window); @@ -2804,11 +2805,11 @@ int SDL_SetWindowPosition(SDL_Window *window, int x, int y) } SDL_zero(bounds); - if (SDL_GetDisplayUsableBounds(displayID, &bounds) < 0 || + if (!SDL_GetDisplayUsableBounds(displayID, &bounds) || window->windowed.w > bounds.w || window->windowed.h > bounds.h) { - if (SDL_GetDisplayBounds(displayID, &bounds) < 0) { - return -1; + if (!SDL_GetDisplayBounds(displayID, &bounds)) { + return false; } } if (SDL_WINDOWPOS_ISCENTERED(x)) { @@ -2826,20 +2827,20 @@ int SDL_SetWindowPosition(SDL_Window *window, int x, int y) if (_this->SetWindowPosition) { window->is_repositioning = true; - const int ret = _this->SetWindowPosition(_this, window); + const bool result = _this->SetWindowPosition(_this, window); window->is_repositioning = false; - if (!ret) { + if (result) { SDL_SyncIfRequired(window); } - return ret; + return result; } return SDL_Unsupported(); } -int SDL_GetWindowPosition(SDL_Window *window, int *x, int *y) +SDL_bool SDL_GetWindowPosition(SDL_Window *window, int *x, int *y) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); // Fullscreen windows are always at their display's origin if (window->flags & SDL_WINDOW_FULLSCREEN) { @@ -2876,13 +2877,13 @@ int SDL_GetWindowPosition(SDL_Window *window, int *x, int *y) *y = window->y; } } - return 0; + return true; } -int SDL_SetWindowBordered(SDL_Window *window, SDL_bool bordered) +SDL_bool SDL_SetWindowBordered(SDL_Window *window, SDL_bool bordered) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); const bool want = (bordered != false); // normalize the flag. const bool have = !(window->flags & SDL_WINDOW_BORDERLESS); @@ -2895,13 +2896,13 @@ int SDL_SetWindowBordered(SDL_Window *window, SDL_bool bordered) _this->SetWindowBordered(_this, window, want); } - return 0; + return true; } -int SDL_SetWindowResizable(SDL_Window *window, SDL_bool resizable) +SDL_bool SDL_SetWindowResizable(SDL_Window *window, SDL_bool resizable) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); const bool want = (resizable != false); // normalize the flag. const bool have = ((window->flags & SDL_WINDOW_RESIZABLE) != 0); @@ -2915,13 +2916,13 @@ int SDL_SetWindowResizable(SDL_Window *window, SDL_bool resizable) _this->SetWindowResizable(_this, window, want); } - return 0; + return true; } -int SDL_SetWindowAlwaysOnTop(SDL_Window *window, SDL_bool on_top) +SDL_bool SDL_SetWindowAlwaysOnTop(SDL_Window *window, SDL_bool on_top) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); const bool want = (on_top != false); // normalize the flag. const bool have = ((window->flags & SDL_WINDOW_ALWAYS_ON_TOP) != 0); @@ -2934,12 +2935,12 @@ int SDL_SetWindowAlwaysOnTop(SDL_Window *window, SDL_bool on_top) _this->SetWindowAlwaysOnTop(_this, window, want); } - return 0; + return true; } -int SDL_SetWindowSize(SDL_Window *window, int w, int h) +SDL_bool SDL_SetWindowSize(SDL_Window *window, int w, int h) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (w <= 0) { return SDL_InvalidParamError("w"); @@ -2981,24 +2982,24 @@ int SDL_SetWindowSize(SDL_Window *window, int w, int h) } else { return SDL_Unsupported(); } - return 0; + return true; } -int SDL_GetWindowSize(SDL_Window *window, int *w, int *h) +SDL_bool SDL_GetWindowSize(SDL_Window *window, int *w, int *h) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (w) { *w = window->w; } if (h) { *h = window->h; } - return 0; + return true; } -int SDL_SetWindowAspectRatio(SDL_Window *window, float min_aspect, float max_aspect) +SDL_bool SDL_SetWindowAspectRatio(SDL_Window *window, float min_aspect, float max_aspect) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); window->min_aspect = min_aspect; window->max_aspect = max_aspect; @@ -3008,9 +3009,9 @@ int SDL_SetWindowAspectRatio(SDL_Window *window, float min_aspect, float max_asp return SDL_SetWindowSize(window, window->floating.w, window->floating.h); } -int SDL_GetWindowAspectRatio(SDL_Window *window, float *min_aspect, float *max_aspect) +SDL_bool SDL_GetWindowAspectRatio(SDL_Window *window, float *min_aspect, float *max_aspect) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (min_aspect) { *min_aspect = window->min_aspect; @@ -3018,10 +3019,10 @@ int SDL_GetWindowAspectRatio(SDL_Window *window, float *min_aspect, float *max_a if (max_aspect) { *max_aspect = window->max_aspect; } - return 0; + return true; } -int SDL_GetWindowBordersSize(SDL_Window *window, int *top, int *left, int *bottom, int *right) +SDL_bool SDL_GetWindowBordersSize(SDL_Window *window, int *top, int *left, int *bottom, int *right) { int dummy = 0; @@ -3041,7 +3042,7 @@ int SDL_GetWindowBordersSize(SDL_Window *window, int *top, int *left, int *botto // Always initialize, so applications don't have to care *top = *left = *bottom = *right = 0; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!_this->GetWindowBordersSize) { return SDL_Unsupported(); @@ -3050,11 +3051,11 @@ int SDL_GetWindowBordersSize(SDL_Window *window, int *top, int *left, int *botto return _this->GetWindowBordersSize(_this, window, top, left, bottom, right); } -int SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h) +SDL_bool SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h) { int filter; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!w) { w = &filter; @@ -3082,14 +3083,14 @@ int SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h) *h = (int)SDL_ceilf(*h * mode->pixel_density); } } - return 0; + return true; } -int SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h) +SDL_bool SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h) { int w, h; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (min_w < 0) { return SDL_InvalidParamError("min_w"); } @@ -3115,23 +3116,23 @@ int SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h) return SDL_SetWindowSize(window, w, h); } -int SDL_GetWindowMinimumSize(SDL_Window *window, int *min_w, int *min_h) +SDL_bool SDL_GetWindowMinimumSize(SDL_Window *window, int *min_w, int *min_h) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (min_w) { *min_w = window->min_w; } if (min_h) { *min_h = window->min_h; } - return 0; + return true; } -int SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h) +SDL_bool SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h) { int w, h; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (max_w < 0) { return SDL_InvalidParamError("max_w"); } @@ -3156,31 +3157,31 @@ int SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h) return SDL_SetWindowSize(window, w, h); } -int SDL_GetWindowMaximumSize(SDL_Window *window, int *max_w, int *max_h) +SDL_bool SDL_GetWindowMaximumSize(SDL_Window *window, int *max_w, int *max_h) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (max_w) { *max_w = window->max_w; } if (max_h) { *max_h = window->max_h; } - return 0; + return true; } -int SDL_ShowWindow(SDL_Window *window) +SDL_bool SDL_ShowWindow(SDL_Window *window) { SDL_Window *child; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!(window->flags & SDL_WINDOW_HIDDEN)) { - return 0; + return true; } // If the parent is hidden, set the flag to restore this when the parent is shown if (window->parent && (window->parent->flags & SDL_WINDOW_HIDDEN)) { window->restore_on_show = true; - return 0; + return true; } if (_this->ShowWindow) { @@ -3199,17 +3200,17 @@ int SDL_ShowWindow(SDL_Window *window) SDL_ShowWindow(child); child->restore_on_show = false; } - return 0; + return true; } -int SDL_HideWindow(SDL_Window *window) +SDL_bool SDL_HideWindow(SDL_Window *window) { SDL_Window *child; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (window->flags & SDL_WINDOW_HIDDEN) { window->restore_on_show = false; - return 0; + return true; } // Hide all child windows @@ -3233,26 +3234,26 @@ int SDL_HideWindow(SDL_Window *window) } window->is_hiding = false; SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_HIDDEN, 0, 0); - return 0; + return true; } -int SDL_RaiseWindow(SDL_Window *window) +SDL_bool SDL_RaiseWindow(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (window->flags & SDL_WINDOW_HIDDEN) { - return 0; + return true; } if (_this->RaiseWindow) { _this->RaiseWindow(_this, window); } - return 0; + return true; } -int SDL_MaximizeWindow(SDL_Window *window) +SDL_bool SDL_MaximizeWindow(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (!_this->MaximizeWindow) { return SDL_Unsupported(); @@ -3264,18 +3265,18 @@ int SDL_MaximizeWindow(SDL_Window *window) if (window->flags & SDL_WINDOW_HIDDEN) { window->pending_flags |= SDL_WINDOW_MAXIMIZED; - return 0; + return true; } _this->MaximizeWindow(_this, window); SDL_SyncIfRequired(window); - return 0; + return true; } -int SDL_MinimizeWindow(SDL_Window *window) +SDL_bool SDL_MinimizeWindow(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (!_this->MinimizeWindow) { return SDL_Unsupported(); @@ -3283,18 +3284,18 @@ int SDL_MinimizeWindow(SDL_Window *window) if (window->flags & SDL_WINDOW_HIDDEN) { window->pending_flags |= SDL_WINDOW_MINIMIZED; - return 0; + return true; } _this->MinimizeWindow(_this, window); SDL_SyncIfRequired(window); - return 0; + return true; } -int SDL_RestoreWindow(SDL_Window *window) +SDL_bool SDL_RestoreWindow(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (!_this->RestoreWindow) { return SDL_Unsupported(); @@ -3302,20 +3303,20 @@ int SDL_RestoreWindow(SDL_Window *window) if (window->flags & SDL_WINDOW_HIDDEN) { window->pending_flags &= ~(SDL_WINDOW_MAXIMIZED | SDL_WINDOW_MINIMIZED); - return 0; + return true; } _this->RestoreWindow(_this, window); SDL_SyncIfRequired(window); - return 0; + return true; } -int SDL_SetWindowFullscreen(SDL_Window *window, SDL_bool fullscreen) +SDL_bool SDL_SetWindowFullscreen(SDL_Window *window, SDL_bool fullscreen) { - int ret = 0; + bool result; - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (window->flags & SDL_WINDOW_HIDDEN) { if (fullscreen) { @@ -3323,7 +3324,7 @@ int SDL_SetWindowFullscreen(SDL_Window *window, SDL_bool fullscreen) } else { window->pending_flags &= ~SDL_WINDOW_FULLSCREEN; } - return 0; + return true; } if (fullscreen) { @@ -3331,29 +3332,29 @@ int SDL_SetWindowFullscreen(SDL_Window *window, SDL_bool fullscreen) SDL_copyp(&window->current_fullscreen_mode, &window->requested_fullscreen_mode); } - ret = SDL_UpdateFullscreenMode(window, fullscreen ? SDL_FULLSCREEN_OP_ENTER : SDL_FULLSCREEN_OP_LEAVE, true); + result = SDL_UpdateFullscreenMode(window, fullscreen ? SDL_FULLSCREEN_OP_ENTER : SDL_FULLSCREEN_OP_LEAVE, true); - if (!fullscreen || ret != 0) { + if (!fullscreen || !result) { // Clear the current fullscreen mode. SDL_zero(window->current_fullscreen_mode); } - if (ret == 0) { + if (result) { SDL_SyncIfRequired(window); } - return ret; + return result; } -int SDL_SyncWindow(SDL_Window *window) +SDL_bool SDL_SyncWindow(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1) + CHECK_WINDOW_MAGIC(window, false) if (_this->SyncWindow) { return _this->SyncWindow(_this, window); + } else { + return true; } - - return 0; } static bool ShouldAttemptTextureFramebuffer(void) @@ -3412,7 +3413,7 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window) be more efficient. This only checks once, on demand. */ if (!_this->checked_texture_framebuffer) { if (ShouldAttemptTextureFramebuffer()) { - if (SDL_CreateWindowTexture(_this, window, &format, &pixels, &pitch) < 0) { + if (!SDL_CreateWindowTexture(_this, window, &format, &pixels, &pitch)) { /* !!! FIXME: if this failed halfway (made renderer, failed to make texture, etc), !!! FIXME: we probably need to clean this up so it doesn't interfere with !!! FIXME: a software fallback at the system level (can we blit to an @@ -3440,7 +3441,7 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window) return NULL; } - if (_this->CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch) < 0) { + if (!_this->CreateWindowFramebuffer(_this, window, &format, &pixels, &pitch)) { return NULL; } } @@ -3480,9 +3481,9 @@ SDL_Surface *SDL_GetWindowSurface(SDL_Window *window) return window->surface; } -int SDL_SetWindowSurfaceVSync(SDL_Window *window, int vsync) +SDL_bool SDL_SetWindowSurfaceVSync(SDL_Window *window, int vsync) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!_this->SetWindowFramebufferVSync) { return SDL_Unsupported(); @@ -3490,9 +3491,9 @@ int SDL_SetWindowSurfaceVSync(SDL_Window *window, int vsync) return _this->SetWindowFramebufferVSync(_this, window, vsync); } -int SDL_GetWindowSurfaceVSync(SDL_Window *window, int *vsync) +SDL_bool SDL_GetWindowSurfaceVSync(SDL_Window *window, int *vsync) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!_this->GetWindowFramebufferVSync) { return SDL_Unsupported(); @@ -3500,11 +3501,11 @@ int SDL_GetWindowSurfaceVSync(SDL_Window *window, int *vsync) return _this->GetWindowFramebufferVSync(_this, window, vsync); } -int SDL_UpdateWindowSurface(SDL_Window *window) +SDL_bool SDL_UpdateWindowSurface(SDL_Window *window) { SDL_Rect full_rect; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); full_rect.x = 0; full_rect.y = 0; @@ -3513,10 +3514,10 @@ int SDL_UpdateWindowSurface(SDL_Window *window) return SDL_UpdateWindowSurfaceRects(window, &full_rect, 1); } -int SDL_UpdateWindowSurfaceRects(SDL_Window *window, const SDL_Rect *rects, +SDL_bool SDL_UpdateWindowSurfaceRects(SDL_Window *window, const SDL_Rect *rects, int numrects) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!window->surface_valid) { return SDL_SetError("Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface"); @@ -3527,9 +3528,9 @@ int SDL_UpdateWindowSurfaceRects(SDL_Window *window, const SDL_Rect *rects, return _this->UpdateWindowFramebuffer(_this, window, rects, numrects); } -int SDL_DestroyWindowSurface(SDL_Window *window) +SDL_bool SDL_DestroyWindowSurface(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (window->surface) { window->surface->internal->flags &= ~SDL_INTERNAL_SURFACE_DONTFREE; @@ -3543,13 +3544,14 @@ int SDL_DestroyWindowSurface(SDL_Window *window) _this->DestroyWindowFramebuffer(_this, window); } } - return 0; + return true; } -int SDL_SetWindowOpacity(SDL_Window *window, float opacity) +SDL_bool SDL_SetWindowOpacity(SDL_Window *window, float opacity) { - int retval; - CHECK_WINDOW_MAGIC(window, -1); + bool result; + + CHECK_WINDOW_MAGIC(window, false); if (!_this->SetWindowOpacity) { return SDL_Unsupported(); @@ -3561,12 +3563,12 @@ int SDL_SetWindowOpacity(SDL_Window *window, float opacity) opacity = 1.0f; } - retval = _this->SetWindowOpacity(_this, window, opacity); - if (retval == 0) { + result = _this->SetWindowOpacity(_this, window, opacity); + if (result == 0) { window->opacity = opacity; } - return retval; + return result; } float SDL_GetWindowOpacity(SDL_Window *window) @@ -3576,14 +3578,16 @@ float SDL_GetWindowOpacity(SDL_Window *window) return window->opacity; } -int SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window) +SDL_bool SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window) { - CHECK_WINDOW_MAGIC(modal_window, -1); - CHECK_WINDOW_NOT_POPUP(modal_window, -1); + bool result; + + CHECK_WINDOW_MAGIC(modal_window, false); + CHECK_WINDOW_NOT_POPUP(modal_window, false); if (parent_window) { - CHECK_WINDOW_MAGIC(parent_window, -1); - CHECK_WINDOW_NOT_POPUP(parent_window, -1); + CHECK_WINDOW_MAGIC(parent_window, false); + CHECK_WINDOW_NOT_POPUP(parent_window, false); } if (!_this->SetWindowModalFor) { @@ -3595,24 +3599,24 @@ int SDL_SetWindowModalFor(SDL_Window *modal_window, SDL_Window *parent_window) } else if (modal_window->flags & SDL_WINDOW_MODAL) { modal_window->flags &= ~SDL_WINDOW_MODAL; } else { - return 0; // Not modal; nothing to do. + return true; // Not modal; nothing to do. } - const int ret = _this->SetWindowModalFor(_this, modal_window, parent_window); + result = _this->SetWindowModalFor(_this, modal_window, parent_window); /* The existing parent might be needed when changing the modal status, * so don't change the hierarchy until after setting the new modal state. */ - if (!ret) { - SDL_SetWindowParent(modal_window, !ret ? parent_window : NULL); + if (result) { + SDL_SetWindowParent(modal_window, parent_window); } - return ret; + return result; } -int SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable) +SDL_bool SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); const bool want = (focusable != false); // normalize the flag. const bool have = !(window->flags & SDL_WINDOW_NOT_FOCUSABLE); @@ -3622,10 +3626,12 @@ int SDL_SetWindowFocusable(SDL_Window *window, SDL_bool focusable) } else { window->flags |= SDL_WINDOW_NOT_FOCUSABLE; } - _this->SetWindowFocusable(_this, window, want); + if (!_this->SetWindowFocusable(_this, window, want)) { + return false; + } } - return 0; + return true; } void SDL_UpdateWindowGrab(SDL_Window *window) @@ -3666,12 +3672,12 @@ void SDL_UpdateWindowGrab(SDL_Window *window) } if (_this->SetWindowMouseGrab) { - if (_this->SetWindowMouseGrab(_this, window, mouse_grabbed) < 0) { + if (!_this->SetWindowMouseGrab(_this, window, mouse_grabbed)) { window->flags &= ~SDL_WINDOW_MOUSE_GRABBED; } } if (_this->SetWindowKeyboardGrab) { - if (_this->SetWindowKeyboardGrab(_this, window, keyboard_grabbed) < 0) { + if (!_this->SetWindowKeyboardGrab(_this, window, keyboard_grabbed)) { window->flags &= ~SDL_WINDOW_KEYBOARD_GRABBED; } } @@ -3681,10 +3687,10 @@ void SDL_UpdateWindowGrab(SDL_Window *window) } } -int SDL_SetWindowKeyboardGrab(SDL_Window *window, SDL_bool grabbed) +SDL_bool SDL_SetWindowKeyboardGrab(SDL_Window *window, SDL_bool grabbed) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (window->flags & SDL_WINDOW_HIDDEN) { if (grabbed) { @@ -3692,11 +3698,11 @@ int SDL_SetWindowKeyboardGrab(SDL_Window *window, SDL_bool grabbed) } else { window->pending_flags &= ~SDL_WINDOW_KEYBOARD_GRABBED; } - return 0; + return true; } if (!!grabbed == !!(window->flags & SDL_WINDOW_KEYBOARD_GRABBED)) { - return 0; + return true; } if (grabbed) { window->flags |= SDL_WINDOW_KEYBOARD_GRABBED; @@ -3706,15 +3712,15 @@ int SDL_SetWindowKeyboardGrab(SDL_Window *window, SDL_bool grabbed) SDL_UpdateWindowGrab(window); if (grabbed && !(window->flags & SDL_WINDOW_KEYBOARD_GRABBED)) { - return -1; + return false; } - return 0; + return true; } -int SDL_SetWindowMouseGrab(SDL_Window *window, SDL_bool grabbed) +SDL_bool SDL_SetWindowMouseGrab(SDL_Window *window, SDL_bool grabbed) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (window->flags & SDL_WINDOW_HIDDEN) { if (grabbed) { @@ -3722,11 +3728,11 @@ int SDL_SetWindowMouseGrab(SDL_Window *window, SDL_bool grabbed) } else { window->pending_flags &= ~SDL_WINDOW_MOUSE_GRABBED; } - return 0; + return true; } if (!!grabbed == !!(window->flags & SDL_WINDOW_MOUSE_GRABBED)) { - return 0; + return true; } if (grabbed) { window->flags |= SDL_WINDOW_MOUSE_GRABBED; @@ -3736,9 +3742,9 @@ int SDL_SetWindowMouseGrab(SDL_Window *window, SDL_bool grabbed) SDL_UpdateWindowGrab(window); if (grabbed && !(window->flags & SDL_WINDOW_MOUSE_GRABBED)) { - return -1; + return false; } - return 0; + return true; } SDL_bool SDL_GetWindowKeyboardGrab(SDL_Window *window) @@ -3763,9 +3769,9 @@ SDL_Window *SDL_GetGrabbedWindow(void) } } -int SDL_SetWindowMouseRect(SDL_Window *window, const SDL_Rect *rect) +SDL_bool SDL_SetWindowMouseRect(SDL_Window *window, const SDL_Rect *rect) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (rect) { SDL_memcpy(&window->mouse_rect, rect, sizeof(*rect)); @@ -3776,7 +3782,7 @@ int SDL_SetWindowMouseRect(SDL_Window *window, const SDL_Rect *rect) if (_this->SetWindowMouseRect) { return _this->SetWindowMouseRect(_this, window); } - return 0; + return true; } const SDL_Rect *SDL_GetWindowMouseRect(SDL_Window *window) @@ -3790,9 +3796,9 @@ const SDL_Rect *SDL_GetWindowMouseRect(SDL_Window *window) } } -int SDL_SetWindowRelativeMouseMode(SDL_Window *window, SDL_bool enabled) +SDL_bool SDL_SetWindowRelativeMouseMode(SDL_Window *window, SDL_bool enabled) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); /* If the app toggles relative mode directly, it probably shouldn't * also be emulating it using repeated mouse warps, so disable @@ -3801,7 +3807,7 @@ int SDL_SetWindowRelativeMouseMode(SDL_Window *window, SDL_bool enabled) SDL_DisableMouseWarpEmulation(); if (enabled == SDL_GetWindowRelativeMouseMode(window)) { - return 0; + return true; } if (enabled) { @@ -3811,7 +3817,7 @@ int SDL_SetWindowRelativeMouseMode(SDL_Window *window, SDL_bool enabled) } SDL_UpdateRelativeMouseMode(); - return 0; + return true; } SDL_bool SDL_GetWindowRelativeMouseMode(SDL_Window *window) @@ -3825,10 +3831,10 @@ SDL_bool SDL_GetWindowRelativeMouseMode(SDL_Window *window) } } -int SDL_FlashWindow(SDL_Window *window, SDL_FlashOperation operation) +SDL_bool SDL_FlashWindow(SDL_Window *window, SDL_FlashOperation operation) { - CHECK_WINDOW_MAGIC(window, -1); - CHECK_WINDOW_NOT_POPUP(window, -1); + CHECK_WINDOW_MAGIC(window, false); + CHECK_WINDOW_NOT_POPUP(window, false); if (_this->FlashWindow) { return _this->FlashWindow(_this, window, operation); @@ -3937,13 +3943,13 @@ void SDL_SetWindowSafeAreaInsets(SDL_Window *window, int left, int right, int to SDL_CheckWindowSafeAreaChanged(window); } -int SDL_GetWindowSafeArea(SDL_Window *window, SDL_Rect *rect) +SDL_bool SDL_GetWindowSafeArea(SDL_Window *window, SDL_Rect *rect) { if (rect) { SDL_zerop(rect); } - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (rect) { if (SDL_RectEmpty(&window->safe_rect)) { @@ -3953,7 +3959,7 @@ int SDL_GetWindowSafeArea(SDL_Window *window, SDL_Rect *rect) SDL_copyp(rect, &window->safe_rect); } } - return 0; + return true; } void SDL_OnWindowMinimized(SDL_Window *window) @@ -4184,13 +4190,13 @@ SDL_bool SDL_ScreenSaverEnabled(void) return !_this->suspend_screensaver; } -int SDL_EnableScreenSaver(void) +SDL_bool SDL_EnableScreenSaver(void) { if (!_this) { return SDL_UninitializedVideo(); } if (!_this->suspend_screensaver) { - return 0; + return true; } _this->suspend_screensaver = false; if (_this->SuspendScreenSaver) { @@ -4200,13 +4206,13 @@ int SDL_EnableScreenSaver(void) return SDL_Unsupported(); } -int SDL_DisableScreenSaver(void) +SDL_bool SDL_DisableScreenSaver(void) { if (!_this) { return SDL_UninitializedVideo(); } if (_this->suspend_screensaver) { - return 0; + return true; } _this->suspend_screensaver = true; if (_this->SuspendScreenSaver) { @@ -4256,9 +4262,9 @@ void SDL_VideoQuit(void) _this = NULL; } -int SDL_GL_LoadLibrary(const char *path) +SDL_bool SDL_GL_LoadLibrary(const char *path) { - int retval; + bool result; if (!_this) { return SDL_UninitializedVideo(); @@ -4267,21 +4273,21 @@ int SDL_GL_LoadLibrary(const char *path) if (path && SDL_strcmp(path, _this->gl_config.driver_path) != 0) { return SDL_SetError("OpenGL library already loaded"); } - retval = 0; + result = true; } else { if (!_this->GL_LoadLibrary) { return SDL_DllNotSupported("OpenGL"); } - retval = _this->GL_LoadLibrary(_this, path); + result = _this->GL_LoadLibrary(_this, path); } - if (retval == 0) { + if (result) { ++_this->gl_config.driver_loaded; } else { if (_this->GL_UnloadLibrary) { _this->GL_UnloadLibrary(_this); } } - return retval; + return result; } SDL_FunctionPointer SDL_GL_GetProcAddress(const char *proc) @@ -4547,15 +4553,15 @@ void SDL_GL_ResetAttributes(void) _this->gl_config.egl_platform = 0; } -int SDL_GL_SetAttribute(SDL_GLattr attr, int value) +SDL_bool SDL_GL_SetAttribute(SDL_GLattr attr, int value) { #if defined(SDL_VIDEO_OPENGL) || defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2) - int retval; + bool result; if (!_this) { return SDL_UninitializedVideo(); } - retval = 0; + result = true; switch (attr) { case SDL_GL_RED_SIZE: _this->gl_config.red_size = value; @@ -4622,7 +4628,7 @@ int SDL_GL_SetAttribute(SDL_GLattr attr, int value) SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG | SDL_GL_CONTEXT_ROBUST_ACCESS_FLAG | SDL_GL_CONTEXT_RESET_ISOLATION_FLAG)) { - retval = SDL_SetError("Unknown OpenGL context flag %d", value); + result = SDL_SetError("Unknown OpenGL context flag %d", value); break; } _this->gl_config.flags = value; @@ -4632,7 +4638,7 @@ int SDL_GL_SetAttribute(SDL_GLattr attr, int value) value != SDL_GL_CONTEXT_PROFILE_CORE && value != SDL_GL_CONTEXT_PROFILE_COMPATIBILITY && value != SDL_GL_CONTEXT_PROFILE_ES) { - retval = SDL_SetError("Unknown OpenGL context profile %d", value); + result = SDL_SetError("Unknown OpenGL context profile %d", value); break; } _this->gl_config.profile_mask = value; @@ -4656,16 +4662,16 @@ int SDL_GL_SetAttribute(SDL_GLattr attr, int value) _this->gl_config.egl_platform = value; break; default: - retval = SDL_SetError("Unknown OpenGL attribute"); + result = SDL_SetError("Unknown OpenGL attribute"); break; } - return retval; + return result; #else return SDL_Unsupported(); #endif // SDL_VIDEO_OPENGL } -int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) +SDL_bool SDL_GL_GetAttribute(SDL_GLattr attr, int *value) { #if defined(SDL_VIDEO_OPENGL) || defined(SDL_VIDEO_OPENGL_ES) || defined(SDL_VIDEO_OPENGL_ES2) PFNGLGETERRORPROC glGetErrorFunc; @@ -4730,7 +4736,7 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) // parameter which switches double buffer to single buffer. OpenGL ES // SDL driver must set proper value after initialization *value = _this->gl_config.double_buffer; - return 0; + return true; #endif case SDL_GL_DEPTH_SIZE: #ifdef SDL_VIDEO_OPENGL @@ -4770,7 +4776,7 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) case SDL_GL_STEREO: // none of these are supported in OpenGL ES *value = 0; - return 0; + return true; #endif case SDL_GL_MULTISAMPLEBUFFERS: attrib = GL_SAMPLE_BUFFERS; @@ -4790,72 +4796,72 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) int rsize = 0, gsize = 0, bsize = 0, asize = 0; // There doesn't seem to be a single flag in OpenGL for this! - if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &rsize) < 0) { - return -1; + if (!SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &rsize)) { + return false; } - if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &gsize) < 0) { - return -1; + if (!SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &gsize)) { + return false; } - if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &bsize) < 0) { - return -1; + if (!SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &bsize)) { + return false; } - if (SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &asize) < 0) { - return -1; + if (!SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &asize)) { + return false; } *value = rsize + gsize + bsize + asize; - return 0; + return true; } case SDL_GL_ACCELERATED_VISUAL: { // FIXME: How do we get this information? *value = (_this->gl_config.accelerated != 0); - return 0; + return true; } case SDL_GL_RETAINED_BACKING: { *value = _this->gl_config.retained_backing; - return 0; + return true; } case SDL_GL_CONTEXT_MAJOR_VERSION: { *value = _this->gl_config.major_version; - return 0; + return true; } case SDL_GL_CONTEXT_MINOR_VERSION: { *value = _this->gl_config.minor_version; - return 0; + return true; } case SDL_GL_CONTEXT_FLAGS: { *value = _this->gl_config.flags; - return 0; + return true; } case SDL_GL_CONTEXT_PROFILE_MASK: { *value = _this->gl_config.profile_mask; - return 0; + return true; } case SDL_GL_SHARE_WITH_CURRENT_CONTEXT: { *value = _this->gl_config.share_with_current_context; - return 0; + return true; } case SDL_GL_FRAMEBUFFER_SRGB_CAPABLE: { *value = _this->gl_config.framebuffer_srgb_capable; - return 0; + return true; } case SDL_GL_CONTEXT_NO_ERROR: { *value = _this->gl_config.no_error; - return 0; + return true; } case SDL_GL_EGL_PLATFORM: { *value = _this->gl_config.egl_platform; - return 0; + return true; } default: return SDL_SetError("Unknown OpenGL attribute"); @@ -4864,7 +4870,7 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) #ifdef SDL_VIDEO_OPENGL glGetStringFunc = (PFNGLGETSTRINGPROC)SDL_GL_GetProcAddress("glGetString"); if (!glGetStringFunc) { - return -1; + return false; } if (attachmentattrib && isAtLeastGL3((const char *)glGetStringFunc(GL_VERSION))) { @@ -4886,7 +4892,7 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) glBindFramebufferFunc(GL_DRAW_FRAMEBUFFER, current_fbo); } } else { - return -1; + return false; } } else #endif @@ -4895,13 +4901,13 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) if (glGetIntegervFunc) { glGetIntegervFunc(attrib, (GLint *)value); } else { - return -1; + return false; } } glGetErrorFunc = (PFNGLGETERRORPROC)SDL_GL_GetProcAddress("glGetError"); if (!glGetErrorFunc) { - return -1; + return false; } error = glGetErrorFunc(); @@ -4913,7 +4919,7 @@ int SDL_GL_GetAttribute(SDL_GLattr attr, int *value) } return SDL_SetError("OpenGL error: %08X", error); } - return 0; + return true; #else return SDL_Unsupported(); #endif // SDL_VIDEO_OPENGL @@ -4943,9 +4949,9 @@ SDL_GLContext SDL_GL_CreateContext(SDL_Window *window) return ctx; } -int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context) +SDL_bool SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context) { - int retval; + bool result; if (!_this) { return SDL_UninitializedVideo(); @@ -4954,13 +4960,13 @@ int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context) if (window == SDL_GL_GetCurrentWindow() && context == SDL_GL_GetCurrentContext()) { // We're already current. - return 0; + return true; } if (!context) { window = NULL; } else if (window) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!(window->flags & SDL_WINDOW_OPENGL)) { return SDL_SetError(NOT_AN_OPENGL_WINDOW); @@ -4969,14 +4975,14 @@ int SDL_GL_MakeCurrent(SDL_Window *window, SDL_GLContext context) return SDL_SetError("Use of OpenGL without a window is not supported on this platform"); } - retval = _this->GL_MakeCurrent(_this, window, context); - if (retval == 0) { + result = _this->GL_MakeCurrent(_this, window, context); + if (result) { _this->current_glwin = window; _this->current_glctx = context; SDL_SetTLS(&_this->current_glwin_tls, window, NULL); SDL_SetTLS(&_this->current_glctx_tls, context, NULL); } - return retval; + return result; } SDL_Window *SDL_GL_GetCurrentWindow(void) @@ -5054,7 +5060,7 @@ SDL_EGLConfig SDL_EGL_GetWindowSurface(SDL_Window *window) #endif } -int SDL_GL_SetSwapInterval(int interval) +SDL_bool SDL_GL_SetSwapInterval(int interval) { if (!_this) { return SDL_UninitializedVideo(); @@ -5067,7 +5073,7 @@ int SDL_GL_SetSwapInterval(int interval) } } -int SDL_GL_GetSwapInterval(int *interval) +SDL_bool SDL_GL_GetSwapInterval(int *interval) { if (!interval) { return SDL_InvalidParamError("interval"); @@ -5086,9 +5092,9 @@ int SDL_GL_GetSwapInterval(int *interval) } } -int SDL_GL_SwapWindow(SDL_Window *window) +SDL_bool SDL_GL_SwapWindow(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!(window->flags & SDL_WINDOW_OPENGL)) { return SDL_SetError(NOT_AN_OPENGL_WINDOW); @@ -5101,7 +5107,7 @@ int SDL_GL_SwapWindow(SDL_Window *window) return _this->GL_SwapWindow(_this, window); } -int SDL_GL_DestroyContext(SDL_GLContext context) +SDL_bool SDL_GL_DestroyContext(SDL_GLContext context) { if (!_this) { return SDL_UninitializedVideo(); \ @@ -5114,7 +5120,7 @@ int SDL_GL_DestroyContext(SDL_GLContext context) SDL_GL_MakeCurrent(NULL, NULL); } - return _this->GL_DeleteContext(_this, context); + return _this->GL_DestroyContext(_this, context); } #if 0 // FIXME @@ -5264,14 +5270,14 @@ static bool AutoShowingScreenKeyboard(void) } } -int SDL_StartTextInput(SDL_Window *window) +SDL_bool SDL_StartTextInput(SDL_Window *window) { return SDL_StartTextInputWithProperties(window, 0); } -int SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props) +SDL_bool SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (window->text_input_props) { SDL_DestroyProperties(window->text_input_props); @@ -5281,10 +5287,10 @@ int SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props) if (props) { window->text_input_props = SDL_CreateProperties(); if (!window->text_input_props) { - return -1; + return false; } - if (SDL_CopyProperties(props, window->text_input_props) < 0) { - return -1; + if (!SDL_CopyProperties(props, window->text_input_props)) { + return false; } } @@ -5298,13 +5304,13 @@ int SDL_StartTextInputWithProperties(SDL_Window *window, SDL_PropertiesID props) if (!window->text_input_active) { // Finally start the text input system if (_this->StartTextInput) { - if (_this->StartTextInput(_this, window, props) < 0) { - return -1; + if (!_this->StartTextInput(_this, window, props)) { + return false; } } window->text_input_active = true; } - return 0; + return true; } SDL_bool SDL_TextInputActive(SDL_Window *window) @@ -5314,9 +5320,9 @@ SDL_bool SDL_TextInputActive(SDL_Window *window) return window->text_input_active; } -int SDL_StopTextInput(SDL_Window *window) +SDL_bool SDL_StopTextInput(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (window->text_input_active) { // Stop the text input system @@ -5332,12 +5338,12 @@ int SDL_StopTextInput(SDL_Window *window) _this->HideScreenKeyboard(_this, window); } } - return 0; + return true; } -int SDL_SetTextInputArea(SDL_Window *window, const SDL_Rect *rect, int cursor) +SDL_bool SDL_SetTextInputArea(SDL_Window *window, const SDL_Rect *rect, int cursor) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (rect) { SDL_copyp(&window->text_input_rect, rect); @@ -5348,16 +5354,16 @@ int SDL_SetTextInputArea(SDL_Window *window, const SDL_Rect *rect, int cursor) } if (_this && _this->UpdateTextInputArea) { - if (_this->UpdateTextInputArea(_this, window) < 0) { - return -1; + if (!_this->UpdateTextInputArea(_this, window)) { + return false; } } - return 0; + return true; } -int SDL_GetTextInputArea(SDL_Window *window, SDL_Rect *rect, int *cursor) +SDL_bool SDL_GetTextInputArea(SDL_Window *window, SDL_Rect *rect, int *cursor) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (rect) { SDL_copyp(rect, &window->text_input_rect); @@ -5365,19 +5371,17 @@ int SDL_GetTextInputArea(SDL_Window *window, SDL_Rect *rect, int *cursor) if (cursor) { *cursor = window->text_input_cursor; } - return 0; + return true; } -int SDL_ClearComposition(SDL_Window *window) +SDL_bool SDL_ClearComposition(SDL_Window *window) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (_this->ClearComposition) { - if (_this->ClearComposition(_this, window) < 0) { - return -1; - } + return _this->ClearComposition(_this, window); } - return 0; + return true; } SDL_bool SDL_HasScreenKeyboardSupport(void) @@ -5434,10 +5438,10 @@ int SDL_GetMessageBoxCount(void) #include "vita/SDL_vitamessagebox.h" #endif -int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +SDL_bool SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { int dummybutton; - int retval = -1; + bool result = false; bool show_cursor_prev; SDL_Window *current_window; SDL_MessageBoxData mbdata; @@ -5473,21 +5477,21 @@ int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) SDL_ClearError(); if (_this && _this->ShowMessageBox) { - retval = _this->ShowMessageBox(_this, messageboxdata, buttonID); + result = _this->ShowMessageBox(_this, messageboxdata, buttonID); } else { // It's completely fine to call this function before video is initialized const char *driver_name = SDL_GetHint(SDL_HINT_VIDEO_DRIVER); if (driver_name && *driver_name != 0) { const char *driver_attempt = driver_name; - while (driver_attempt && (*driver_attempt != 0) && (retval == -1)) { + while (driver_attempt && (*driver_attempt != 0) && !result) { const char *driver_attempt_end = SDL_strchr(driver_attempt, ','); size_t driver_attempt_len = (driver_attempt_end) ? (driver_attempt_end - driver_attempt) : SDL_strlen(driver_attempt); for (int i = 0; bootstrap[i]; ++i) { if (bootstrap[i]->ShowMessageBox && (driver_attempt_len == SDL_strlen(bootstrap[i]->name)) && (SDL_strncasecmp(bootstrap[i]->name, driver_attempt, driver_attempt_len) == 0)) { - if (bootstrap[i]->ShowMessageBox(messageboxdata, buttonID) == 0) { - retval = 0; + if (bootstrap[i]->ShowMessageBox(messageboxdata, buttonID)) { + result = true; } break; } @@ -5497,15 +5501,15 @@ int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) } } else { for (int i = 0; bootstrap[i]; ++i) { - if (bootstrap[i]->ShowMessageBox && bootstrap[i]->ShowMessageBox(messageboxdata, buttonID) == 0) { - retval = 0; + if (bootstrap[i]->ShowMessageBox && bootstrap[i]->ShowMessageBox(messageboxdata, buttonID)) { + result = true; break; } } } } - if (retval == -1) { + if (!result) { const char *error = SDL_GetError(); if (!*error) { @@ -5527,10 +5531,10 @@ int SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) SDL_UpdateRelativeMouseMode(); SDL_UpdateMouseCapture(false); - return retval; + return result; } -int SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window) +SDL_bool SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window) { #ifdef SDL_PLATFORM_EMSCRIPTEN // !!! FIXME: propose a browser API for this, get this #ifdef out of here? @@ -5547,7 +5551,7 @@ int SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const alert(UTF8ToString($0) + "\n\n" + UTF8ToString($1)); }, title, message); - return 0; + return true; #else SDL_MessageBoxData data; SDL_MessageBoxButtonData button; @@ -5574,22 +5578,22 @@ bool SDL_ShouldAllowTopmost(void) return SDL_GetHintBoolean(SDL_HINT_WINDOW_ALLOW_TOPMOST, true); } -int SDL_ShowWindowSystemMenu(SDL_Window *window, int x, int y) +SDL_bool SDL_ShowWindowSystemMenu(SDL_Window *window, int x, int y) { - CHECK_WINDOW_MAGIC(window, -1) - CHECK_WINDOW_NOT_POPUP(window, -1) + CHECK_WINDOW_MAGIC(window, false) + CHECK_WINDOW_NOT_POPUP(window, false) if (_this->ShowWindowSystemMenu) { _this->ShowWindowSystemMenu(window, x, y); - return 0; + return true; } return SDL_Unsupported(); } -int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callback_data) +SDL_bool SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callback_data) { - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!_this->SetWindowHitTest) { return SDL_Unsupported(); @@ -5601,12 +5605,12 @@ int SDL_SetWindowHitTest(SDL_Window *window, SDL_HitTest callback, void *callbac return _this->SetWindowHitTest(window, callback != NULL); } -int SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape) +SDL_bool SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape) { SDL_PropertiesID props; SDL_Surface *surface; - CHECK_WINDOW_MAGIC(window, -1); + CHECK_WINDOW_MAGIC(window, false); if (!(window->flags & SDL_WINDOW_TRANSPARENT)) { return SDL_SetError("Window must be created with SDL_WINDOW_TRANSPARENT"); @@ -5614,24 +5618,24 @@ int SDL_SetWindowShape(SDL_Window *window, SDL_Surface *shape) props = SDL_GetWindowProperties(window); if (!props) { - return -1; + return false; } surface = SDL_ConvertSurface(shape, SDL_PIXELFORMAT_ARGB32); if (!surface) { - return -1; + return false; } - if (SDL_SetSurfaceProperty(props, SDL_PROP_WINDOW_SHAPE_POINTER, surface) < 0) { - return -1; + if (!SDL_SetSurfaceProperty(props, SDL_PROP_WINDOW_SHAPE_POINTER, surface)) { + return false; } if (_this->UpdateWindowShape) { - if (_this->UpdateWindowShape(_this, window, surface) < 0) { - return -1; + if (!_this->UpdateWindowShape(_this, window, surface)) { + return false; } } - return 0; + return true; } /* @@ -5684,28 +5688,28 @@ void SDL_OnApplicationDidEnterForeground(void) #define NOT_A_VULKAN_WINDOW "The specified window isn't a Vulkan window" -int SDL_Vulkan_LoadLibrary(const char *path) +SDL_bool SDL_Vulkan_LoadLibrary(const char *path) { - int retval; + bool result; + if (!_this) { - SDL_UninitializedVideo(); - return -1; + return SDL_UninitializedVideo(); } if (_this->vulkan_config.loader_loaded) { if (path && SDL_strcmp(path, _this->vulkan_config.loader_path) != 0) { return SDL_SetError("Vulkan loader library already loaded"); } - retval = 0; + result = true; } else { if (!_this->Vulkan_LoadLibrary) { return SDL_DllNotSupported("Vulkan"); } - retval = _this->Vulkan_LoadLibrary(_this, path); + result = _this->Vulkan_LoadLibrary(_this, path); } - if (retval == 0) { + if (result) { _this->vulkan_config.loader_loaded++; } - return retval; + return result; } SDL_FunctionPointer SDL_Vulkan_GetVkGetInstanceProcAddr(void) @@ -5742,7 +5746,7 @@ char const* const* SDL_Vulkan_GetInstanceExtensions(Uint32 *count) return _this->Vulkan_GetInstanceExtensions(_this, count); } -int SDL_Vulkan_CreateSurface(SDL_Window *window, +SDL_bool SDL_Vulkan_CreateSurface(SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface) diff --git a/src/video/SDL_video_c.h b/src/video/SDL_video_c.h index 4dd5210dc7..f2da921770 100644 --- a/src/video/SDL_video_c.h +++ b/src/video/SDL_video_c.h @@ -45,10 +45,10 @@ struct SDL_VideoDevice; * * \param driver_name the name of a video driver to initialize, or NULL for * the default driver - * \returns 0 on success or a negative error code on failure; call + * \returns true on success or false on failure; call * SDL_GetError() for more information. */ -extern int SDL_VideoInit(const char *driver_name); +extern bool SDL_VideoInit(const char *driver_name); /** * Shut down the video subsystem, if initialized with SDL_VideoInit(). @@ -57,9 +57,7 @@ extern int SDL_VideoInit(const char *driver_name); */ extern void SDL_VideoQuit(void); -extern int SDL_SetWindowTextureVSync(struct SDL_VideoDevice *_this, SDL_Window *window, int vsync); - -extern int SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a); +extern bool SDL_SetWindowTextureVSync(struct SDL_VideoDevice *_this, SDL_Window *window, int vsync); #if defined(SDL_VIDEO_DRIVER_X11) || defined(SDL_VIDEO_DRIVER_WAYLAND) || defined(SDL_VIDEO_DRIVER_EMSCRIPTEN) const char *SDL_GetCSSCursorName(SDL_SystemCursor id, const char **fallback_name); diff --git a/src/video/SDL_video_unsupported.c b/src/video/SDL_video_unsupported.c index b101ec2215..5467b7986e 100644 --- a/src/video/SDL_video_unsupported.c +++ b/src/video/SDL_video_unsupported.c @@ -24,12 +24,12 @@ #if defined(SDL_PLATFORM_WIN32) || defined(SDL_PLATFORM_GDK) -int SDL_RegisterApp(const char *name, Uint32 style, void *hInst) +SDL_bool SDL_RegisterApp(const char *name, Uint32 style, void *hInst) { (void)name; (void)style; (void)hInst; - return 0; + return true; } void SDL_UnregisterApp(void) @@ -42,8 +42,8 @@ void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata) #endif // SDL_PLATFORM_WIN32 || SDL_PLATFORM_GDK -SDL_DECLSPEC int SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex); -int SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex) +SDL_DECLSPEC SDL_bool SDLCALL SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex); +SDL_bool SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex) { (void)displayID; (void)adapterIndex; @@ -55,7 +55,8 @@ SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID); int SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID) { (void)displayID; - return SDL_Unsupported(); + SDL_Unsupported(); + return -1; } #elif defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) @@ -64,15 +65,16 @@ SDL_DECLSPEC int SDLCALL SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID); int SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID) { (void)displayID; - return SDL_Unsupported(); + SDL_Unsupported(); + return -1; } #endif // !SDL_VIDEO_DRIVER_WINDOWS #ifndef SDL_PLATFORM_GDK -SDL_DECLSPEC int SDLCALL SDL_GetGDKTaskQueue(void *outTaskQueue); -int SDL_GetGDKTaskQueue(void *outTaskQueue) +SDL_DECLSPEC bool SDLCALL SDL_GetGDKTaskQueue(void *outTaskQueue); +bool SDL_GetGDKTaskQueue(void *outTaskQueue) { (void)outTaskQueue; return SDL_Unsupported(); @@ -93,8 +95,8 @@ void SDL_OnApplicationDidChangeStatusBarOrientation(void) #ifndef SDL_VIDEO_DRIVER_UIKIT typedef void (SDLCALL *SDL_iOSAnimationCallback)(void *userdata); -SDL_DECLSPEC int SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam); -int SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam) +SDL_DECLSPEC SDL_bool SDLCALL SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam); +SDL_bool SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam) { (void)window; (void)interval; diff --git a/src/video/SDL_vulkan_internal.h b/src/video/SDL_vulkan_internal.h index 787062a9ce..be462e89fb 100644 --- a/src/video/SDL_vulkan_internal.h +++ b/src/video/SDL_vulkan_internal.h @@ -63,10 +63,10 @@ extern VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList( * using the DisplayKHR extension. * This needs to be passed an instance that was created with the VK_KHR_DISPLAY_EXTENSION_NAME * extension. */ -extern int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr, - VkInstance instance, - const struct VkAllocationCallbacks *allocator, - VkSurfaceKHR *surface); +extern bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr, + VkInstance instance, + const struct VkAllocationCallbacks *allocator, + VkSurfaceKHR *surface); /* Platform independent base function for destroying the Vulkan surface. Unlike surface * creation, surface destruction doesn't require platform specific extensions like diff --git a/src/video/SDL_vulkan_utils.c b/src/video/SDL_vulkan_utils.c index c883bd20bd..9bcf1aba32 100644 --- a/src/video/SDL_vulkan_utils.c +++ b/src/video/SDL_vulkan_utils.c @@ -121,49 +121,49 @@ VkExtensionProperties *SDL_Vulkan_CreateInstanceExtensionsList( Uint32 *extensionCount) { Uint32 count = 0; - VkResult result = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); - VkExtensionProperties *retval; + VkResult rc = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); + VkExtensionProperties *result; - if (result == VK_ERROR_INCOMPATIBLE_DRIVER) { + if (rc == VK_ERROR_INCOMPATIBLE_DRIVER) { // Avoid the ERR_MAX_STRLEN limit by passing part of the message as a string argument. SDL_SetError( "You probably don't have a working Vulkan driver installed. %s %s %s(%d)", "Getting Vulkan extensions failed:", "vkEnumerateInstanceExtensionProperties returned", - SDL_Vulkan_GetResultString(result), - (int)result); + SDL_Vulkan_GetResultString(rc), + (int)rc); return NULL; - } else if (result != VK_SUCCESS) { + } else if (rc != VK_SUCCESS) { SDL_SetError( "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned " "%s(%d)", - SDL_Vulkan_GetResultString(result), - (int)result); + SDL_Vulkan_GetResultString(rc), + (int)rc); return NULL; } if (count == 0) { - retval = (VkExtensionProperties *)SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null + result = (VkExtensionProperties *)SDL_calloc(1, sizeof(VkExtensionProperties)); // so we can return non-null } else { - retval = (VkExtensionProperties *)SDL_calloc(count, sizeof(VkExtensionProperties)); + result = (VkExtensionProperties *)SDL_calloc(count, sizeof(VkExtensionProperties)); } - if (!retval) { + if (!result) { return NULL; } - result = vkEnumerateInstanceExtensionProperties(NULL, &count, retval); - if (result != VK_SUCCESS) { + rc = vkEnumerateInstanceExtensionProperties(NULL, &count, result); + if (rc != VK_SUCCESS) { SDL_SetError( "Getting Vulkan extensions failed: vkEnumerateInstanceExtensionProperties returned " "%s(%d)", - SDL_Vulkan_GetResultString(result), - (int)result); - SDL_free(retval); + SDL_Vulkan_GetResultString(rc), + (int)rc); + SDL_free(result); return NULL; } *extensionCount = count; - return retval; + return result; } // Alpha modes, in order of preference @@ -174,10 +174,10 @@ static const VkDisplayPlaneAlphaFlagBitsKHR alphaModes[4] = { VK_DISPLAY_PLANE_ALPHA_PER_PIXEL_PREMULTIPLIED_BIT_KHR, }; -int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, - VkInstance instance, - const struct VkAllocationCallbacks *allocator, - VkSurfaceKHR *surface) +bool SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, + VkInstance instance, + const struct VkAllocationCallbacks *allocator, + VkSurfaceKHR *surface) { PFN_vkGetInstanceProcAddr vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)vkGetInstanceProcAddr_; @@ -192,7 +192,7 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, VULKAN_INSTANCE_FUNCTION(vkCreateDisplayPlaneSurfaceKHR); #undef VULKAN_INSTANCE_FUNCTION VkDisplaySurfaceCreateInfoKHR createInfo; - VkResult result; + VkResult rc; uint32_t physicalDeviceCount = 0; VkPhysicalDevice *physicalDevices = NULL; uint32_t physicalDeviceIndex; @@ -215,8 +215,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, } // Enumerate physical devices - result = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, NULL); - if (result != VK_SUCCESS) { + rc = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, NULL); + if (rc != VK_SUCCESS) { SDL_SetError("Could not enumerate Vulkan physical devices"); goto error; } @@ -231,8 +231,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, goto error; } - result = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices); - if (result != VK_SUCCESS) { + rc = vkEnumeratePhysicalDevices(instance, &physicalDeviceCount, physicalDevices); + if (rc != VK_SUCCESS) { SDL_SetError("Error enumerating physical devices"); goto error; } @@ -254,8 +254,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, VkDisplayPlaneCapabilitiesKHR planeCaps = { 0 }; // Get information about the physical displays - result = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, NULL); - if (result != VK_SUCCESS || displayPropertiesCount == 0) { + rc = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, NULL); + if (rc != VK_SUCCESS || displayPropertiesCount == 0) { // This device has no physical device display properties, move on to next. continue; } @@ -273,8 +273,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, goto error; } - result = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, displayProperties); - if (result != VK_SUCCESS || displayPropertiesCount == 0) { + rc = vkGetPhysicalDeviceDisplayPropertiesKHR(physicalDevice, &displayPropertiesCount, displayProperties); + if (rc != VK_SUCCESS || displayPropertiesCount == 0) { SDL_free(displayProperties); SDL_SetError("Error enumerating physical device displays"); goto error; @@ -289,8 +289,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, displayProperties = NULL; // Get display mode properties for the chosen display - result = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, NULL); - if (result != VK_SUCCESS || displayModePropertiesCount == 0) { + rc = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, NULL); + if (rc != VK_SUCCESS || displayModePropertiesCount == 0) { SDL_SetError("Error enumerating display modes"); goto error; } @@ -301,8 +301,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, goto error; } - result = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, displayModeProperties); - if (result != VK_SUCCESS || displayModePropertiesCount == 0) { + rc = vkGetDisplayModePropertiesKHR(physicalDevice, display, &displayModePropertiesCount, displayModeProperties); + if (rc != VK_SUCCESS || displayModePropertiesCount == 0) { SDL_SetError("Error enumerating display modes"); SDL_free(displayModeProperties); goto error; @@ -335,8 +335,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, displayModeProperties = NULL; // Try to find a plane index that supports our display - result = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, NULL); - if (result != VK_SUCCESS || displayPlanePropertiesCount == 0) { + rc = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, NULL); + if (rc != VK_SUCCESS || displayPlanePropertiesCount == 0) { SDL_SetError("Error enumerating display planes"); goto error; } @@ -347,8 +347,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, goto error; } - result = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, displayPlaneProperties); - if (result != VK_SUCCESS || displayPlanePropertiesCount == 0) { + rc = vkGetPhysicalDeviceDisplayPlanePropertiesKHR(physicalDevice, &displayPlanePropertiesCount, displayPlaneProperties); + if (rc != VK_SUCCESS || displayPlanePropertiesCount == 0) { SDL_SetError("Error enumerating display plane properties"); SDL_free(displayPlaneProperties); goto error; @@ -365,8 +365,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, } // Check supported displays for this plane. - result = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, NULL); - if (result != VK_SUCCESS || planeSupportedDisplaysCount == 0) { + rc = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, NULL); + if (rc != VK_SUCCESS || planeSupportedDisplaysCount == 0) { continue; // No supported displays, on to next plane. } @@ -378,8 +378,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, goto error; } - result = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, planeSupportedDisplays); - if (result != VK_SUCCESS || planeSupportedDisplaysCount == 0) { + rc = vkGetDisplayPlaneSupportedDisplaysKHR(physicalDevice, i, &planeSupportedDisplaysCount, planeSupportedDisplays); + if (rc != VK_SUCCESS || planeSupportedDisplaysCount == 0) { SDL_SetError("Error enumerating supported displays, or no supported displays"); SDL_free(planeSupportedDisplays); SDL_free(displayPlaneProperties); @@ -397,8 +397,8 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, continue; } - result = vkGetDisplayPlaneCapabilitiesKHR(physicalDevice, createInfo.displayMode, i, &planeCaps); - if (result != VK_SUCCESS) { + rc = vkGetDisplayPlaneCapabilitiesKHR(physicalDevice, createInfo.displayMode, i, &planeCaps); + if (rc != VK_SUCCESS) { SDL_SetError("Error getting display plane capabilities"); SDL_free(displayPlaneProperties); goto error; @@ -454,17 +454,17 @@ int SDL_Vulkan_Display_CreateSurface(void *vkGetInstanceProcAddr_, createInfo.transform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; createInfo.globalAlpha = 1.0f; - result = vkCreateDisplayPlaneSurfaceKHR(instance, &createInfo, allocator, surface); - if (result != VK_SUCCESS) { - SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); + rc = vkCreateDisplayPlaneSurfaceKHR(instance, &createInfo, allocator, surface); + if (rc != VK_SUCCESS) { + SDL_SetError("vkCreateDisplayPlaneSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(rc)); goto error; } SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "vulkandisplay: Created surface"); - return 0; + return true; error: SDL_free(physicalDevices); - return -1; + return false; } void SDL_Vulkan_DestroySurface_Internal(void *vkGetInstanceProcAddr_, diff --git a/src/video/SDL_yuv.c b/src/video/SDL_yuv.c index 8bcb948a41..d7ddd0790f 100644 --- a/src/video/SDL_yuv.c +++ b/src/video/SDL_yuv.c @@ -33,10 +33,8 @@ static bool IsPlanar2x2Format(SDL_PixelFormat format); /* * Calculate YUV size and pitch. Check for overflow. * Output 'pitch' that can be used with SDL_ConvertPixels() - * - * return 0 on success, -1 on error */ -int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch) +bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch) { #if SDL_HAVE_YUV int sz_plane = 0, sz_plane_chroma = 0, sz_plane_packed = 0; @@ -151,7 +149,7 @@ int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, siz return SDL_Unsupported(); } - return 0; + return true; #else return SDL_Unsupported(); #endif @@ -159,7 +157,7 @@ int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, siz #if SDL_HAVE_YUV -static int GetYUVConversionType(SDL_Colorspace colorspace, YCbCrType *yuv_type) +static bool GetYUVConversionType(SDL_Colorspace colorspace, YCbCrType *yuv_type) { if (SDL_ISCOLORSPACE_MATRIX_BT601(colorspace)) { if (SDL_ISCOLORSPACE_LIMITED_RANGE(colorspace)) { @@ -167,20 +165,20 @@ static int GetYUVConversionType(SDL_Colorspace colorspace, YCbCrType *yuv_type) } else { *yuv_type = YCBCR_601_FULL; } - return 0; + return true; } if (SDL_ISCOLORSPACE_MATRIX_BT709(colorspace)) { if (SDL_ISCOLORSPACE_LIMITED_RANGE(colorspace)) { *yuv_type = YCBCR_709_LIMITED; - return 0; + return true; } } if (SDL_ISCOLORSPACE_MATRIX_BT2020_NCL(colorspace)) { if (SDL_ISCOLORSPACE_FULL_RANGE(colorspace)) { *yuv_type = YCBCR_2020_NCL_FULL; - return 0; + return true; } } @@ -197,8 +195,8 @@ static bool IsPacked4Format(Uint32 format) return format == SDL_PIXELFORMAT_YUY2 || format == SDL_PIXELFORMAT_UYVY || format == SDL_PIXELFORMAT_YVYU; } -static int GetYUVPlanes(int width, int height, SDL_PixelFormat format, const void *yuv, int yuv_pitch, - const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride) +static bool GetYUVPlanes(int width, int height, SDL_PixelFormat format, const void *yuv, int yuv_pitch, + const Uint8 **y, const Uint8 **u, const Uint8 **v, Uint32 *y_stride, Uint32 *uv_stride) { const Uint8 *planes[3] = { NULL, NULL, NULL }; int pitches[3] = { 0, 0, 0 }; @@ -299,7 +297,7 @@ static int GetYUVPlanes(int width, int height, SDL_PixelFormat format, const voi // Should have caught this above return SDL_SetError("GetYUVPlanes[2]: Unsupported YUV format: %s", SDL_GetPixelFormatName(format)); } - return 0; + return true; } #ifdef SDL_SSE2_INTRINSICS @@ -586,9 +584,9 @@ static bool yuv_rgb_std( return false; } -int SDL_ConvertPixels_YUV_to_RGB(int width, int height, - SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, - SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch) +bool SDL_ConvertPixels_YUV_to_RGB(int width, int height, + SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, + SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch) { const Uint8 *y = NULL; const Uint8 *u = NULL; @@ -596,75 +594,75 @@ int SDL_ConvertPixels_YUV_to_RGB(int width, int height, Uint32 y_stride = 0; Uint32 uv_stride = 0; - if (GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride) < 0) { - return -1; + if (!GetYUVPlanes(width, height, src_format, src, src_pitch, &y, &u, &v, &y_stride, &uv_stride)) { + return false; } if (SDL_COLORSPACEPRIMARIES(src_colorspace) == SDL_COLORSPACEPRIMARIES(dst_colorspace)) { YCbCrType yuv_type = YCBCR_601_LIMITED; - if (GetYUVConversionType(src_colorspace, &yuv_type) < 0) { - return -1; + if (!GetYUVConversionType(src_colorspace, &yuv_type)) { + return false; } if (yuv_rgb_sse(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) { - return 0; + return true; } if (yuv_rgb_lsx(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) { - return 0; + return true; } if (yuv_rgb_std(src_format, dst_format, width, height, y, u, v, y_stride, uv_stride, (Uint8 *)dst, dst_pitch, yuv_type)) { - return 0; + return true; } } // No fast path for the RGB format, instead convert using an intermediate buffer if (src_format == SDL_PIXELFORMAT_P010 && dst_format != SDL_PIXELFORMAT_XBGR2101010) { - int ret; + bool result; void *tmp; int tmp_pitch = (width * sizeof(Uint32)); tmp = SDL_malloc((size_t)tmp_pitch * height); if (!tmp) { - return -1; + return false; } // convert src/src_format to tmp/XBGR2101010 - ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch); - if (ret < 0) { + result = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch); + if (!result) { SDL_free(tmp); - return ret; + return false; } // convert tmp/XBGR2101010 to dst/RGB - ret = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch); + result = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_XBGR2101010, src_colorspace, src_properties, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch); SDL_free(tmp); - return ret; + return result; } if (dst_format != SDL_PIXELFORMAT_ARGB8888) { - int ret; + bool result; void *tmp; int tmp_pitch = (width * sizeof(Uint32)); tmp = SDL_malloc((size_t)tmp_pitch * height); if (!tmp) { - return -1; + return false; } // convert src/src_format to tmp/ARGB8888 - ret = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch); - if (ret < 0) { + result = SDL_ConvertPixels_YUV_to_RGB(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch); + if (!result) { SDL_free(tmp); - return ret; + return false; } // convert tmp/ARGB8888 to dst/RGB - ret = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch); + result = SDL_ConvertPixelsAndColorspace(width, height, SDL_PIXELFORMAT_ARGB8888, SDL_COLORSPACE_SRGB, 0, tmp, tmp_pitch, dst_format, dst_colorspace, dst_properties, dst, dst_pitch); SDL_free(tmp); - return ret; + return result; } return SDL_SetError("Unsupported YUV conversion"); @@ -709,7 +707,7 @@ static struct RGB2YUVFactors RGB2YUVFactorTables[] = { }, }; -static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type) +static bool SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type) { const int src_pitch_x_2 = src_pitch * 2; const int height_half = height / 2; @@ -782,10 +780,10 @@ static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void * Uint8 *plane_interleaved_uv; Uint32 y_stride, uv_stride, y_skip, uv_skip; - if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, - (const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v, - &y_stride, &uv_stride) != 0) { - return -1; + if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch, + (const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v, + &y_stride, &uv_stride)) { + return false; } plane_interleaved_uv = (plane_y + height * y_stride); @@ -997,10 +995,10 @@ static int SDL_ConvertPixels_ARGB8888_to_YUV(int width, int height, const void * #undef READ_1x1_PIXEL #undef READ_TWO_RGB_PIXELS #undef READ_ONE_RGB_PIXEL - return 0; + return true; } -static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type) +static bool SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, YCbCrType yuv_type) { const int src_pitch_x_2 = src_pitch * 2; const int height_half = height / 2; @@ -1052,10 +1050,10 @@ static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const vo Uint16 *plane_interleaved_uv; Uint32 y_stride, uv_stride, y_skip, uv_skip; - if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, - (const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v, - &y_stride, &uv_stride) != 0) { - return -1; + if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch, + (const Uint8 **)&plane_y, (const Uint8 **)&plane_u, (const Uint8 **)&plane_v, + &y_stride, &uv_stride)) { + return false; } y_stride /= sizeof(Uint16); @@ -1119,17 +1117,17 @@ static int SDL_ConvertPixels_XBGR2101010_to_P010(int width, int height, const vo #undef READ_2x1_PIXELS #undef READ_1x2_PIXELS #undef READ_1x1_PIXEL - return 0; + return true; } -int SDL_ConvertPixels_RGB_to_YUV(int width, int height, - SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, - SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch) +bool SDL_ConvertPixels_RGB_to_YUV(int width, int height, + SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, + SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch) { YCbCrType yuv_type = YCBCR_601_LIMITED; - if (GetYUVConversionType(dst_colorspace, &yuv_type) < 0) { - return -1; + if (!GetYUVConversionType(dst_colorspace, &yuv_type)) { + return false; } #if 0 // Doesn't handle odd widths @@ -1142,11 +1140,11 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height, Uint32 uv_stride; if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, (const Uint8 **)&y, (const Uint8 **)&u, (const Uint8 **)&v, &y_stride, &uv_stride) < 0) { - return -1; + return false; } rgb24_yuv420_std(width, height, src, src_pitch, y, u, v, y_stride, uv_stride, yuv_type); - return 0; + return true; } #endif @@ -1163,55 +1161,54 @@ int SDL_ConvertPixels_RGB_to_YUV(int width, int height, } // We currently only support converting from XBGR2101010 to P010 - int ret; + bool result; void *tmp; int tmp_pitch = (width * sizeof(Uint32)); tmp = SDL_malloc((size_t)tmp_pitch * height); if (!tmp) { - return -1; + return false; } // convert src/src_format to tmp/XBGR2101010 - ret = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, dst_colorspace, dst_properties, tmp, tmp_pitch); - if (ret < 0) { + result = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_XBGR2101010, dst_colorspace, dst_properties, tmp, tmp_pitch); + if (!result) { SDL_free(tmp); - return ret; + return false; } // convert tmp/XBGR2101010 to dst/P010 - ret = SDL_ConvertPixels_XBGR2101010_to_P010(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type); + result = SDL_ConvertPixels_XBGR2101010_to_P010(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type); SDL_free(tmp); - return ret; + return result; } // not ARGB8888 to FOURCC : need an intermediate conversion { - int ret; + bool result; void *tmp; int tmp_pitch = (width * sizeof(Uint32)); tmp = SDL_malloc((size_t)tmp_pitch * height); if (!tmp) { - return -1; + return false; } // convert src/src_format to tmp/ARGB8888 - ret = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, dst_colorspace, dst_properties, tmp, tmp_pitch); - if (ret < 0) { + result = SDL_ConvertPixelsAndColorspace(width, height, src_format, src_colorspace, src_properties, src, src_pitch, SDL_PIXELFORMAT_ARGB8888, dst_colorspace, dst_properties, tmp, tmp_pitch); + if (!result) { SDL_free(tmp); - return ret; + return false; } // convert tmp/ARGB8888 to dst/FOURCC - ret = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type); + result = SDL_ConvertPixels_ARGB8888_to_YUV(width, height, tmp, tmp_pitch, dst_format, dst, dst_pitch, yuv_type); SDL_free(tmp); - return ret; + return result; } } -static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFormat format, - const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFormat format, const void *src, int src_pitch, void *dst, int dst_pitch) { int i; @@ -1257,7 +1254,7 @@ static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFor dst = (Uint8 *)dst + dst_pitch; } } - return 0; + return true; } if (IsPacked4Format(format)) { @@ -1268,13 +1265,13 @@ static int SDL_ConvertPixels_YUV_to_YUV_Copy(int width, int height, SDL_PixelFor src = (const Uint8 *)src + src_pitch; dst = (Uint8 *)dst + dst_pitch; } - return 0; + return true; } return SDL_SetError("SDL_ConvertPixels_YUV_to_YUV_Copy: Unsupported YUV format: %s", SDL_GetPixelFormatName(format)); } -static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int y; const int UVwidth = (width + 1) / 2; @@ -1293,7 +1290,7 @@ static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src // Allocate a temporary row for the swap tmp = (Uint8 *)SDL_malloc(UVwidth); if (!tmp) { - return -1; + return false; } for (y = 0; y < UVheight; ++y) { SDL_memcpy(tmp, row1, UVwidth); @@ -1326,11 +1323,11 @@ static int SDL_ConvertPixels_SwapUVPlanes(int width, int height, const void *src dstUV += dstUVPitch; } } - return 0; + return true; } #ifdef SDL_SSE2_INTRINSICS -static int SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) { int x, y; const int UVwidth = (width + 1) / 2; @@ -1351,7 +1348,7 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int w // Need to make a copy of the buffer so we don't clobber it while converting tmp = (Uint8 *)SDL_malloc((size_t)2 * UVheight * srcUVPitch); if (tmp == NULL) { - return -1; + return false; } SDL_memcpy(tmp, src, (size_t)2 * UVheight * srcUVPitch); src = tmp; @@ -1393,10 +1390,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_PackUVPlanes_to_NV_SSE2(int w if (tmp) { SDL_free(tmp); } - return 0; + return true; } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) { int x, y; const int UVwidth = (width + 1) / 2; @@ -1417,7 +1414,7 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int // Need to make a copy of the buffer so we don't clobber it while converting tmp = (Uint8 *)SDL_malloc((size_t)UVheight * srcUVPitch); if (tmp == NULL) { - return -1; + return false; } SDL_memcpy(tmp, src, (size_t)UVheight * srcUVPitch); src = tmp; @@ -1464,10 +1461,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_SplitNV_to_UVPlanes_SSE2(int if (tmp) { SDL_free(tmp); } - return 0; + return true; } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_SwapNV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_SwapNV_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int UVwidth = (width + 1) / 2; @@ -1504,11 +1501,11 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_SwapNV_SSE2(int width, int he srcUV += srcUVPitchLeft; dstUV += dstUVPitchLeft; } - return 0; + return true; } #endif -static int SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) +static bool SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) { int x, y; const int UVwidth = (width + 1) / 2; @@ -1529,7 +1526,7 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const // Need to make a copy of the buffer so we don't clobber it while converting tmp = (Uint8 *)SDL_malloc((size_t)2 * UVheight * srcUVPitch); if (!tmp) { - return -1; + return false; } SDL_memcpy(tmp, src, (size_t)2 * UVheight * srcUVPitch); src = tmp; @@ -1559,10 +1556,10 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV_std(int width, int height, const if (tmp) { SDL_free(tmp); } - return 0; + return true; } -static int SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) +static bool SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) { int x, y; const int UVwidth = (width + 1) / 2; @@ -1583,7 +1580,7 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, cons // Need to make a copy of the buffer so we don't clobber it while converting tmp = (Uint8 *)SDL_malloc((size_t)UVheight * srcUVPitch); if (!tmp) { - return -1; + return false; } SDL_memcpy(tmp, src, (size_t)UVheight * srcUVPitch); src = tmp; @@ -1613,10 +1610,10 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes_std(int width, int height, cons if (tmp) { SDL_free(tmp); } - return 0; + return true; } -static int SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int UVwidth = (width + 1) / 2; @@ -1643,10 +1640,10 @@ static int SDL_ConvertPixels_SwapNV_std(int width, int height, const void *src, srcUV += srcUVPitchLeft; dstUV += dstUVPitchLeft; } - return 0; + return true; } -static int SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) +static bool SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -1656,7 +1653,7 @@ static int SDL_ConvertPixels_PackUVPlanes_to_NV(int width, int height, const voi return SDL_ConvertPixels_PackUVPlanes_to_NV_std(width, height, src, src_pitch, dst, dst_pitch, reverseUV); } -static int SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) +static bool SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch, bool reverseUV) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -1666,7 +1663,7 @@ static int SDL_ConvertPixels_SplitNV_to_UVPlanes(int width, int height, const vo return SDL_ConvertPixels_SplitNV_to_UVPlanes_std(width, height, src, src_pitch, dst, dst_pitch, reverseUV); } -static int SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -1676,9 +1673,9 @@ static int SDL_ConvertPixels_SwapNV(int width, int height, const void *src, int return SDL_ConvertPixels_SwapNV_std(width, height, src, src_pitch, dst, dst_pitch); } -static int SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height, - SDL_PixelFormat src_format, const void *src, int src_pitch, - SDL_PixelFormat dst_format, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height, + SDL_PixelFormat src_format, const void *src, int src_pitch, + SDL_PixelFormat dst_format, void *dst, int dst_pitch) { if (src != dst) { // Copy Y plane @@ -1765,7 +1762,7 @@ static int SDL_ConvertPixels_Planar2x2_to_Planar2x2(int width, int height, x -= 4; \ } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -1797,10 +1794,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_UYVY_SSE2(int width, dstYUV += dstYUVPitchLeft; x = YUVwidth; } - return 0; + return true; } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -1832,10 +1829,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YUY2_to_YVYU_SSE2(int width, dstYUV += dstYUVPitchLeft; x = YUVwidth; } - return 0; + return true; } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -1867,10 +1864,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YUY2_SSE2(int width, dstYUV += dstYUVPitchLeft; x = YUVwidth; } - return 0; + return true; } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YVYU_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -1902,10 +1899,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_UYVY_to_YVYU_SSE2(int width, dstYUV += dstYUVPitchLeft; x = YUVwidth; } - return 0; + return true; } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_YUY2_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -1937,10 +1934,10 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_YUY2_SSE2(int width, dstYUV += dstYUVPitchLeft; x = YUVwidth; } - return 0; + return true; } -static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_UYVY_SSE2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -1972,11 +1969,11 @@ static int SDL_TARGETING("sse2") SDL_ConvertPixels_YVYU_to_UYVY_SSE2(int width, dstYUV += dstYUVPitchLeft; x = YUVwidth; } - return 0; + return true; } #endif -static int SDL_ConvertPixels_YUY2_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YUY2_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -2006,10 +2003,10 @@ static int SDL_ConvertPixels_YUY2_to_UYVY_std(int width, int height, const void srcYUV += srcYUVPitchLeft; dstYUV += dstYUVPitchLeft; } - return 0; + return true; } -static int SDL_ConvertPixels_YUY2_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YUY2_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -2039,10 +2036,10 @@ static int SDL_ConvertPixels_YUY2_to_YVYU_std(int width, int height, const void srcYUV += srcYUVPitchLeft; dstYUV += dstYUVPitchLeft; } - return 0; + return true; } -static int SDL_ConvertPixels_UYVY_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_UYVY_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -2072,10 +2069,10 @@ static int SDL_ConvertPixels_UYVY_to_YUY2_std(int width, int height, const void srcYUV += srcYUVPitchLeft; dstYUV += dstYUVPitchLeft; } - return 0; + return true; } -static int SDL_ConvertPixels_UYVY_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_UYVY_to_YVYU_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -2105,10 +2102,10 @@ static int SDL_ConvertPixels_UYVY_to_YVYU_std(int width, int height, const void srcYUV += srcYUVPitchLeft; dstYUV += dstYUVPitchLeft; } - return 0; + return true; } -static int SDL_ConvertPixels_YVYU_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YVYU_to_YUY2_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -2138,10 +2135,10 @@ static int SDL_ConvertPixels_YVYU_to_YUY2_std(int width, int height, const void srcYUV += srcYUVPitchLeft; dstYUV += dstYUVPitchLeft; } - return 0; + return true; } -static int SDL_ConvertPixels_YVYU_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YVYU_to_UYVY_std(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { int x, y; const int YUVwidth = (width + 1) / 2; @@ -2171,10 +2168,10 @@ static int SDL_ConvertPixels_YVYU_to_UYVY_std(int width, int height, const void srcYUV += srcYUVPitchLeft; dstYUV += dstYUVPitchLeft; } - return 0; + return true; } -static int SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -2184,7 +2181,7 @@ static int SDL_ConvertPixels_YUY2_to_UYVY(int width, int height, const void *src return SDL_ConvertPixels_YUY2_to_UYVY_std(width, height, src, src_pitch, dst, dst_pitch); } -static int SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -2194,7 +2191,7 @@ static int SDL_ConvertPixels_YUY2_to_YVYU(int width, int height, const void *src return SDL_ConvertPixels_YUY2_to_YVYU_std(width, height, src, src_pitch, dst, dst_pitch); } -static int SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -2204,7 +2201,7 @@ static int SDL_ConvertPixels_UYVY_to_YUY2(int width, int height, const void *src return SDL_ConvertPixels_UYVY_to_YUY2_std(width, height, src, src_pitch, dst, dst_pitch); } -static int SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -2214,7 +2211,7 @@ static int SDL_ConvertPixels_UYVY_to_YVYU(int width, int height, const void *src return SDL_ConvertPixels_UYVY_to_YVYU_std(width, height, src, src_pitch, dst, dst_pitch); } -static int SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -2224,7 +2221,7 @@ static int SDL_ConvertPixels_YVYU_to_YUY2(int width, int height, const void *src return SDL_ConvertPixels_YVYU_to_YUY2_std(width, height, src, src_pitch, dst, dst_pitch); } -static int SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src, int src_pitch, void *dst, int dst_pitch) { #ifdef SDL_SSE2_INTRINSICS if (SDL_HasSSE2()) { @@ -2234,7 +2231,7 @@ static int SDL_ConvertPixels_YVYU_to_UYVY(int width, int height, const void *src return SDL_ConvertPixels_YVYU_to_UYVY_std(width, height, src, src_pitch, dst, dst_pitch); } -static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height, +static bool SDL_ConvertPixels_Packed4_to_Packed4(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch) { @@ -2276,9 +2273,9 @@ static int SDL_ConvertPixels_Packed4_to_Packed4(int width, int height, SDL_GetPixelFormatName(dst_format)); } -static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height, - SDL_PixelFormat src_format, const void *src, int src_pitch, - SDL_PixelFormat dst_format, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height, + SDL_PixelFormat src_format, const void *src, int src_pitch, + SDL_PixelFormat dst_format, void *dst, int dst_pitch) { int x, y; const Uint8 *srcY1, *srcY2, *srcU, *srcV; @@ -2292,9 +2289,9 @@ static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height, return SDL_SetError("Can't change YUV plane types in-place"); } - if (GetYUVPlanes(width, height, src_format, src, src_pitch, - &srcY1, &srcU, &srcV, &srcY_pitch, &srcUV_pitch) < 0) { - return -1; + if (!GetYUVPlanes(width, height, src_format, src, src_pitch, + &srcY1, &srcU, &srcV, &srcY_pitch, &srcUV_pitch)) { + return false; } srcY2 = srcY1 + srcY_pitch; srcY_pitch_left = (srcY_pitch - width); @@ -2307,10 +2304,10 @@ static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height, srcUV_pitch_left = (srcUV_pitch - ((width + 1) / 2)); } - if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, - (const Uint8 **)&dstY1, (const Uint8 **)&dstU1, (const Uint8 **)&dstV1, - &dstY_pitch, &dstUV_pitch) < 0) { - return -1; + if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch, + (const Uint8 **)&dstY1, (const Uint8 **)&dstU1, (const Uint8 **)&dstV1, + &dstY_pitch, &dstUV_pitch)) { + return false; } dstY2 = dstY1 + dstY_pitch; dstU2 = dstU1 + dstUV_pitch; @@ -2415,12 +2412,12 @@ static int SDL_ConvertPixels_Planar2x2_to_Packed4(int width, int height, dstV1 += 4; } } - return 0; + return true; } -static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height, - SDL_PixelFormat src_format, const void *src, int src_pitch, - SDL_PixelFormat dst_format, void *dst, int dst_pitch) +static bool SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height, + SDL_PixelFormat src_format, const void *src, int src_pitch, + SDL_PixelFormat dst_format, void *dst, int dst_pitch) { int x, y; const Uint8 *srcY1, *srcY2, *srcU1, *srcU2, *srcV1, *srcV2; @@ -2434,19 +2431,19 @@ static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height, return SDL_SetError("Can't change YUV plane types in-place"); } - if (GetYUVPlanes(width, height, src_format, src, src_pitch, - &srcY1, &srcU1, &srcV1, &srcY_pitch, &srcUV_pitch) < 0) { - return -1; + if (!GetYUVPlanes(width, height, src_format, src, src_pitch, + &srcY1, &srcU1, &srcV1, &srcY_pitch, &srcUV_pitch)) { + return false; } srcY2 = srcY1 + srcY_pitch; srcU2 = srcU1 + srcUV_pitch; srcV2 = srcV1 + srcUV_pitch; src_pitch_left = (srcY_pitch - 4 * ((width + 1) / 2)); - if (GetYUVPlanes(width, height, dst_format, dst, dst_pitch, - (const Uint8 **)&dstY1, (const Uint8 **)&dstU, (const Uint8 **)&dstV, - &dstY_pitch, &dstUV_pitch) < 0) { - return -1; + if (!GetYUVPlanes(width, height, dst_format, dst, dst_pitch, + (const Uint8 **)&dstY1, (const Uint8 **)&dstU, (const Uint8 **)&dstV, + &dstY_pitch, &dstUV_pitch)) { + return false; } dstY2 = dstY1 + dstY_pitch; dstY_pitch_left = (dstY_pitch - width); @@ -2546,14 +2543,14 @@ static int SDL_ConvertPixels_Packed4_to_Planar2x2(int width, int height, *dstV = *srcV1; } } - return 0; + return true; } #endif // SDL_HAVE_YUV -int SDL_ConvertPixels_YUV_to_YUV(int width, int height, - SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, - SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch) +bool SDL_ConvertPixels_YUV_to_YUV(int width, int height, + SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, + SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch) { #if SDL_HAVE_YUV if (src_colorspace != dst_colorspace) { @@ -2563,7 +2560,7 @@ int SDL_ConvertPixels_YUV_to_YUV(int width, int height, if (src_format == dst_format) { if (src == dst) { // Nothing to do - return 0; + return true; } return SDL_ConvertPixels_YUV_to_YUV_Copy(width, height, src_format, src, src_pitch, dst, dst_pitch); } diff --git a/src/video/SDL_yuv_c.h b/src/video/SDL_yuv_c.h index 7d3c6fdb2c..2e49337431 100644 --- a/src/video/SDL_yuv_c.h +++ b/src/video/SDL_yuv_c.h @@ -26,11 +26,11 @@ // YUV conversion functions -extern int SDL_ConvertPixels_YUV_to_RGB(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); -extern int SDL_ConvertPixels_RGB_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); -extern int SDL_ConvertPixels_YUV_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); +extern bool SDL_ConvertPixels_YUV_to_RGB(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); +extern bool SDL_ConvertPixels_RGB_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); +extern bool SDL_ConvertPixels_YUV_to_YUV(int width, int height, SDL_PixelFormat src_format, SDL_Colorspace src_colorspace, SDL_PropertiesID src_properties, const void *src, int src_pitch, SDL_PixelFormat dst_format, SDL_Colorspace dst_colorspace, SDL_PropertiesID dst_properties, void *dst, int dst_pitch); -extern int SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch); +extern bool SDL_CalculateYUVSize(SDL_PixelFormat format, int w, int h, size_t *size, size_t *pitch); #endif // SDL_yuv_c_h_ diff --git a/src/video/android/SDL_androidclipboard.c b/src/video/android/SDL_androidclipboard.c index bc01f435d7..2d108b933c 100644 --- a/src/video/android/SDL_androidclipboard.c +++ b/src/video/android/SDL_androidclipboard.c @@ -26,7 +26,7 @@ #include "SDL_androidclipboard.h" #include "../../core/android/SDL_android.h" -int Android_SetClipboardText(SDL_VideoDevice *_this, const char *text) +bool Android_SetClipboardText(SDL_VideoDevice *_this, const char *text) { return Android_JNI_SetClipboardText(text); } diff --git a/src/video/android/SDL_androidclipboard.h b/src/video/android/SDL_androidclipboard.h index 0355a2838b..9d6a60aac3 100644 --- a/src/video/android/SDL_androidclipboard.h +++ b/src/video/android/SDL_androidclipboard.h @@ -23,7 +23,7 @@ #ifndef SDL_androidclipboard_h_ #define SDL_androidclipboard_h_ -extern int Android_SetClipboardText(SDL_VideoDevice *_this, const char *text); +extern bool Android_SetClipboardText(SDL_VideoDevice *_this, const char *text); extern char *Android_GetClipboardText(SDL_VideoDevice *_this); extern bool Android_HasClipboardText(SDL_VideoDevice *_this); diff --git a/src/video/android/SDL_androidevents.c b/src/video/android/SDL_androidevents.c index cacf5df66a..0ffe38f6f8 100644 --- a/src/video/android/SDL_androidevents.c +++ b/src/video/android/SDL_androidevents.c @@ -39,7 +39,7 @@ static void android_egl_context_restore(SDL_Window *window) SDL_Event event; SDL_WindowData *data = window->internal; SDL_GL_MakeCurrent(window, NULL); - if (SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context) < 0) { + if (!SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context)) { // The context is no longer valid, create a new one data->egl_context = (EGLContext)SDL_GL_CreateContext(window); SDL_GL_MakeCurrent(window, (SDL_GLContext)data->egl_context); @@ -65,7 +65,7 @@ static void android_egl_context_backup(SDL_Window *window) data->egl_context = SDL_GL_GetCurrentContext(); // Save/Restore the swap interval / vsync - if (SDL_GL_GetSwapInterval(&interval) == 0) { + if (SDL_GL_GetSwapInterval(&interval)) { data->has_swap_interval = 1; data->swap_interval = interval; } @@ -245,7 +245,7 @@ void Android_PumpEvents(Sint64 timeoutNS) } } -int Android_WaitActiveAndLockActivity(void) +bool Android_WaitActiveAndLockActivity(void) { while (Android_Paused && !Android_Destroyed) { Android_PumpEvents(-1); @@ -253,11 +253,11 @@ int Android_WaitActiveAndLockActivity(void) if (Android_Destroyed) { SDL_SetError("Android activity has been destroyed"); - return -1; + return false; } Android_LockActivityMutex(); - return 0; + return true; } void Android_QuitEvents(void) diff --git a/src/video/android/SDL_androidevents.h b/src/video/android/SDL_androidevents.h index 283c6840e4..9d0de4b1f1 100644 --- a/src/video/android/SDL_androidevents.h +++ b/src/video/android/SDL_androidevents.h @@ -22,5 +22,5 @@ extern void Android_InitEvents(void); extern void Android_PumpEvents(Sint64 timeoutNS); -extern int Android_WaitActiveAndLockActivity(void); +extern bool Android_WaitActiveAndLockActivity(void); extern void Android_QuitEvents(void); diff --git a/src/video/android/SDL_androidgl.c b/src/video/android/SDL_androidgl.c index 74dddd0220..35bab7037e 100644 --- a/src/video/android/SDL_androidgl.c +++ b/src/video/android/SDL_androidgl.c @@ -36,7 +36,7 @@ #include -int Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { if (window && context) { return SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context); @@ -47,22 +47,22 @@ int Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLC SDL_GLContext Android_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) { - SDL_GLContext ret; + SDL_GLContext result; - if (Android_WaitActiveAndLockActivity() < 0) { + if (!Android_WaitActiveAndLockActivity()) { return NULL; } - ret = SDL_EGL_CreateContext(_this, window->internal->egl_surface); + result = SDL_EGL_CreateContext(_this, window->internal->egl_surface); Android_UnlockActivityMutex(); - return ret; + return result; } -int Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { - int retval; + bool result; Android_LockActivityMutex(); @@ -73,14 +73,14 @@ int Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) /*_this->egl_data->eglWaitNative(EGL_CORE_NATIVE_ENGINE); _this->egl_data->eglWaitGL();*/ - retval = SDL_EGL_SwapBuffers(_this, window->internal->egl_surface); + result = SDL_EGL_SwapBuffers(_this, window->internal->egl_surface); Android_UnlockActivityMutex(); - return retval; + return result; } -int Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { return SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)0, 0); } diff --git a/src/video/android/SDL_androidgl.h b/src/video/android/SDL_androidgl.h index eff2e59812..e58719dc7c 100644 --- a/src/video/android/SDL_androidgl.h +++ b/src/video/android/SDL_androidgl.h @@ -23,9 +23,9 @@ #ifndef SDL_androidgl_h_ #define SDL_androidgl_h_ -SDL_GLContext Android_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -int Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -int Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -int Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern SDL_GLContext Android_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Android_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool Android_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Android_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); #endif // SDL_androidgl_h_ diff --git a/src/video/android/SDL_androidkeyboard.c b/src/video/android/SDL_androidkeyboard.c index 37a8999b75..35dc172b63 100644 --- a/src/video/android/SDL_androidkeyboard.c +++ b/src/video/android/SDL_androidkeyboard.c @@ -368,14 +368,14 @@ static SDL_Scancode TranslateKeycode(int keycode) return scancode; } -int Android_OnKeyDown(int keycode) +void Android_OnKeyDown(int keycode) { - return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_PRESSED); + SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_PRESSED); } -int Android_OnKeyUp(int keycode) +void Android_OnKeyUp(int keycode) { - return SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_RELEASED); + SDL_SendKeyboardKey(0, SDL_DEFAULT_KEYBOARD_ID, keycode, TranslateKeycode(keycode), SDL_RELEASED); } bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this) diff --git a/src/video/android/SDL_androidkeyboard.h b/src/video/android/SDL_androidkeyboard.h index e0cafa18c8..67a7a6c51c 100644 --- a/src/video/android/SDL_androidkeyboard.h +++ b/src/video/android/SDL_androidkeyboard.h @@ -22,8 +22,8 @@ #include "SDL_androidvideo.h" -extern int Android_OnKeyDown(int keycode); -extern int Android_OnKeyUp(int keycode); +extern void Android_OnKeyDown(int keycode); +extern void Android_OnKeyUp(int keycode); extern bool Android_HasScreenKeyboardSupport(SDL_VideoDevice *_this); extern void Android_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); diff --git a/src/video/android/SDL_androidmessagebox.c b/src/video/android/SDL_androidmessagebox.c index 33c678c961..15d34234b9 100644 --- a/src/video/android/SDL_androidmessagebox.c +++ b/src/video/android/SDL_androidmessagebox.c @@ -25,7 +25,7 @@ #include "SDL_androidmessagebox.h" #include "../../core/android/SDL_android.h" -int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { return Android_JNI_ShowMessageBox(messageboxdata, buttonID); } diff --git a/src/video/android/SDL_androidmessagebox.h b/src/video/android/SDL_androidmessagebox.h index ece8e0764e..c3f270e03e 100644 --- a/src/video/android/SDL_androidmessagebox.h +++ b/src/video/android/SDL_androidmessagebox.h @@ -22,6 +22,6 @@ #ifdef SDL_VIDEO_DRIVER_ANDROID -extern int Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool Android_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_ANDROID diff --git a/src/video/android/SDL_androidmouse.c b/src/video/android/SDL_androidmouse.c index 813ce61764..9f55e81b16 100644 --- a/src/video/android/SDL_androidmouse.c +++ b/src/video/android/SDL_androidmouse.c @@ -132,7 +132,7 @@ static void Android_DestroyEmptyCursor(void) } } -static int Android_ShowCursor(SDL_Cursor *cursor) +static bool Android_ShowCursor(SDL_Cursor *cursor) { if (!cursor) { cursor = Android_CreateEmptyCursor(); @@ -148,14 +148,14 @@ static int Android_ShowCursor(SDL_Cursor *cursor) return SDL_Unsupported(); } } - return 0; + return true; } else { // SDL error set inside Android_CreateEmptyCursor() - return -1; + return false; } } -static int Android_SetRelativeMouseMode(bool enabled) +static bool Android_SetRelativeMouseMode(bool enabled) { if (!Android_JNI_SupportsRelativeMouse()) { return SDL_Unsupported(); @@ -165,7 +165,7 @@ static int Android_SetRelativeMouseMode(bool enabled) return SDL_Unsupported(); } - return 0; + return true; } void Android_InitMouse(void) diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c index 5e5a615db7..ee8d889394 100644 --- a/src/video/android/SDL_androidvideo.c +++ b/src/video/android/SDL_androidvideo.c @@ -43,7 +43,7 @@ #define ANDROID_VID_DRIVER_NAME "android" // Initialization/Query functions -static int Android_VideoInit(SDL_VideoDevice *_this); +static bool Android_VideoInit(SDL_VideoDevice *_this); static void Android_VideoQuit(SDL_VideoDevice *_this); #include "../SDL_egl_c.h" @@ -51,7 +51,7 @@ static void Android_VideoQuit(SDL_VideoDevice *_this); #define Android_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define Android_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define Android_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -#define Android_GLES_DeleteContext SDL_EGL_DeleteContext +#define Android_GLES_DestroyContext SDL_EGL_DestroyContext // Android driver bootstrap functions @@ -65,7 +65,7 @@ float Android_ScreenDensity = 1.0f; static float Android_ScreenRate = 0.0f; static SDL_SystemTheme Android_SystemTheme; -static int Android_SuspendScreenSaver(SDL_VideoDevice *_this) +static bool Android_SuspendScreenSaver(SDL_VideoDevice *_this) { return Android_JNI_SuspendScreenSaver(_this->suspend_screensaver); } @@ -119,7 +119,7 @@ static SDL_VideoDevice *Android_CreateDevice(void) device->GL_SetSwapInterval = Android_GLES_SetSwapInterval; device->GL_GetSwapInterval = Android_GLES_GetSwapInterval; device->GL_SwapWindow = Android_GLES_SwapWindow; - device->GL_DeleteContext = Android_GLES_DeleteContext; + device->GL_DestroyContext = Android_GLES_DestroyContext; #endif #ifdef SDL_VIDEO_VULKAN @@ -155,7 +155,7 @@ VideoBootStrap Android_bootstrap = { Android_ShowMessageBox }; -int Android_VideoInit(SDL_VideoDevice *_this) +bool Android_VideoInit(SDL_VideoDevice *_this) { SDL_VideoData *videodata = _this->internal; SDL_DisplayID displayID; @@ -173,7 +173,7 @@ int Android_VideoInit(SDL_VideoDevice *_this) displayID = SDL_AddBasicVideoDisplay(&mode); if (displayID == 0) { - return -1; + return false; } display = SDL_GetVideoDisplay(displayID); display->natural_orientation = Android_JNI_GetDisplayNaturalOrientation(); @@ -185,7 +185,7 @@ int Android_VideoInit(SDL_VideoDevice *_this) Android_InitMouse(); // We're done! - return 0; + return true; } void Android_VideoQuit(SDL_VideoDevice *_this) diff --git a/src/video/android/SDL_androidvulkan.c b/src/video/android/SDL_androidvulkan.c index c8e2685096..60a3f672a7 100644 --- a/src/video/android/SDL_androidvulkan.c +++ b/src/video/android/SDL_androidvulkan.c @@ -36,7 +36,7 @@ #include "SDL_androidvulkan.h" -int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 i, extensionCount = 0; @@ -56,7 +56,7 @@ int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) } _this->vulkan_config.loader_handle = SDL_LoadObject(path); if (!_this->vulkan_config.loader_handle) { - return -1; + return false; } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); @@ -94,12 +94,12 @@ int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_ANDROID_SURFACE_EXTENSION_NAME "extension"); goto fail; } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void Android_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -116,13 +116,13 @@ char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, static const char *const extensionsForAndroid[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME }; - if(count) { + if (count) { *count = SDL_arraysize(extensionsForAndroid); } return extensionsForAndroid; } -int Android_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool Android_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, @@ -155,7 +155,7 @@ int Android_Vulkan_CreateSurface(SDL_VideoDevice *_this, if (result != VK_SUCCESS) { return SDL_SetError("vkCreateAndroidSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); } - return 0; + return true; } void Android_Vulkan_DestroySurface(SDL_VideoDevice *_this, diff --git a/src/video/android/SDL_androidvulkan.h b/src/video/android/SDL_androidvulkan.h index 1ef42994e0..bcbe1e2370 100644 --- a/src/video/android/SDL_androidvulkan.h +++ b/src/video/android/SDL_androidvulkan.h @@ -34,19 +34,18 @@ #if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_ANDROID) -int Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void Android_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int Android_Vulkan_CreateSurface(SDL_VideoDevice *_this, - SDL_Window *window, - VkInstance instance, - const struct VkAllocationCallbacks *allocator, - VkSurfaceKHR *surface); -void Android_Vulkan_DestroySurface(SDL_VideoDevice *_this, - VkInstance instance, - VkSurfaceKHR surface, - const struct VkAllocationCallbacks *allocator); +extern bool Android_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void Android_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* Android_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool Android_Vulkan_CreateSurface(SDL_VideoDevice *_this, + SDL_Window *window, + VkInstance instance, + const struct VkAllocationCallbacks *allocator, + VkSurfaceKHR *surface); +extern void Android_Vulkan_DestroySurface(SDL_VideoDevice *_this, + VkInstance instance, + VkSurfaceKHR surface, + const struct VkAllocationCallbacks *allocator); #endif diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c index 5842c59c65..40ecf405ed 100644 --- a/src/video/android/SDL_androidwindow.c +++ b/src/video/android/SDL_androidwindow.c @@ -36,17 +36,17 @@ // Currently only one window SDL_Window *Android_Window = NULL; -int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *data; - int retval = 0; + bool result = true; - if (Android_WaitActiveAndLockActivity() < 0) { - return -1; + if (!Android_WaitActiveAndLockActivity()) { + return false; } if (Android_Window) { - retval = SDL_SetError("Android only supports one window"); + result = SDL_SetError("Android only supports one window"); goto endfunction; } @@ -65,14 +65,14 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { - retval = -1; + result = SDL_FALSE; goto endfunction; } data->native_window = Android_JNI_GetNativeWindow(); if (!data->native_window) { SDL_free(data); - retval = SDL_SetError("Could not fetch native window"); + result = SDL_SetError("Could not fetch native window"); goto endfunction; } SDL_SetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_ANDROID_WINDOW_POINTER, data->native_window); @@ -86,7 +86,7 @@ int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert if (data->egl_surface == EGL_NO_SURFACE) { ANativeWindow_release(data->native_window); SDL_free(data); - retval = -1; + result = SDL_FALSE; goto endfunction; } } @@ -100,7 +100,7 @@ endfunction: Android_UnlockActivityMutex(); - return retval; + return result; } void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) @@ -108,7 +108,7 @@ void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) Android_JNI_SetActivityTitle(window->title); } -int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) +SDL_FullscreenResult Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { Android_LockActivityMutex(); @@ -157,7 +157,8 @@ int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_ endfunction: Android_UnlockActivityMutex(); - return 0; + + return SDL_FULLSCREEN_SUCCEEDED; } void Android_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/android/SDL_androidwindow.h b/src/video/android/SDL_androidwindow.h index dfa12a00e5..1a53414635 100644 --- a/src/video/android/SDL_androidwindow.h +++ b/src/video/android/SDL_androidwindow.h @@ -26,9 +26,9 @@ #include "../../core/android/SDL_android.h" #include "../SDL_egl_c.h" -extern int Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool Android_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern void Android_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -extern int Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +extern SDL_FullscreenResult Android_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); extern void Android_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Android_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); diff --git a/src/video/cocoa/SDL_cocoaclipboard.h b/src/video/cocoa/SDL_cocoaclipboard.h index ff6f0b1f66..da2e612034 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.h +++ b/src/video/cocoa/SDL_cocoaclipboard.h @@ -26,11 +26,8 @@ // Forward declaration @class SDL_CocoaVideoData; -extern int Cocoa_SetClipboardText(SDL_VideoDevice *_this, const char *text); -extern char *Cocoa_GetClipboardText(SDL_VideoDevice *_this); -extern bool Cocoa_HasClipboardText(SDL_VideoDevice *_this); extern void Cocoa_CheckClipboardUpdate(SDL_CocoaVideoData *data); -extern int Cocoa_SetClipboardData(SDL_VideoDevice *_this); +extern bool Cocoa_SetClipboardData(SDL_VideoDevice *_this); extern void *Cocoa_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *size); extern bool Cocoa_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type); diff --git a/src/video/cocoa/SDL_cocoaclipboard.m b/src/video/cocoa/SDL_cocoaclipboard.m index b080a0ca37..9cfdd82908 100644 --- a/src/video/cocoa/SDL_cocoaclipboard.m +++ b/src/video/cocoa/SDL_cocoaclipboard.m @@ -90,7 +90,7 @@ void Cocoa_CheckClipboardUpdate(SDL_CocoaVideoData *data) } } -int Cocoa_SetClipboardData(SDL_VideoDevice *_this) +bool Cocoa_SetClipboardData(SDL_VideoDevice *_this) { @autoreleasepool { SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal; @@ -125,7 +125,7 @@ int Cocoa_SetClipboardData(SDL_VideoDevice *_this) } data.clipboard_count = [pasteboard changeCount]; } - return 0; + return true; } void *Cocoa_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *size) diff --git a/src/video/cocoa/SDL_cocoaevents.h b/src/video/cocoa/SDL_cocoaevents.h index 740fc4e1d1..49ecfbb79d 100644 --- a/src/video/cocoa/SDL_cocoaevents.h +++ b/src/video/cocoa/SDL_cocoaevents.h @@ -28,6 +28,6 @@ extern Uint64 Cocoa_GetEventTimestamp(NSTimeInterval nsTimestamp); extern void Cocoa_PumpEvents(SDL_VideoDevice *_this); extern int Cocoa_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS); extern void Cocoa_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this); +extern bool Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this); #endif // SDL_cocoaevents_h_ diff --git a/src/video/cocoa/SDL_cocoaevents.m b/src/video/cocoa/SDL_cocoaevents.m index 1a71a7a8e9..5f79be3b2b 100644 --- a/src/video/cocoa/SDL_cocoaevents.m +++ b/src/video/cocoa/SDL_cocoaevents.m @@ -641,7 +641,7 @@ void Cocoa_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window) } } -int Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this) +bool Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this) { @autoreleasepool { SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal; @@ -666,7 +666,7 @@ int Cocoa_SuspendScreenSaver(SDL_VideoDevice *_this) data.screensaver_assertion = assertion; } } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_COCOA diff --git a/src/video/cocoa/SDL_cocoakeyboard.h b/src/video/cocoa/SDL_cocoakeyboard.h index 39407fd82c..a8f35577d8 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.h +++ b/src/video/cocoa/SDL_cocoakeyboard.h @@ -27,10 +27,10 @@ extern void Cocoa_InitKeyboard(SDL_VideoDevice *_this); extern void Cocoa_HandleKeyEvent(SDL_VideoDevice *_this, NSEvent *event); extern void Cocoa_QuitKeyboard(SDL_VideoDevice *_this); -extern int Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -extern int Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +extern bool Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); #endif // SDL_cocoakeyboard_h_ diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index b0a331cd6e..86d9e659ce 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -381,7 +381,7 @@ void Cocoa_InitKeyboard(SDL_VideoDevice *_this) SDL_ToggleModState(SDL_KMOD_CAPS, (data.modifierFlags & NSEventModifierFlagCapsLock) ? true : false); } -int Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) +bool Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { @autoreleasepool { NSView *parentView; @@ -409,7 +409,7 @@ int Cocoa_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert return Cocoa_UpdateTextInputArea(_this, window); } -int Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) { @autoreleasepool { SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal; @@ -419,16 +419,16 @@ int Cocoa_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) data.fieldEdit = nil; } } - return 0; + return true; } -int Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) { SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal; if (data.fieldEdit) { [data.fieldEdit setInputRect:&window->text_input_rect]; } - return 0; + return true; } void Cocoa_HandleKeyEvent(SDL_VideoDevice *_this, NSEvent *event) @@ -509,12 +509,12 @@ typedef enum extern CGSConnection _CGSDefaultConnection(void); extern CGError CGSSetGlobalHotKeyOperatingMode(CGSConnection connection, CGSGlobalHotKeyOperatingMode mode); -int Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool Cocoa_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { #ifdef SDL_MAC_NO_SANDBOX CGSSetGlobalHotKeyOperatingMode(_CGSDefaultConnection(), grabbed ? CGSGlobalHotKeyDisable : CGSGlobalHotKeyEnable); #endif - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_COCOA diff --git a/src/video/cocoa/SDL_cocoamessagebox.h b/src/video/cocoa/SDL_cocoamessagebox.h index 96c64e010b..74dbde41d0 100644 --- a/src/video/cocoa/SDL_cocoamessagebox.h +++ b/src/video/cocoa/SDL_cocoamessagebox.h @@ -22,6 +22,6 @@ #ifdef SDL_VIDEO_DRIVER_COCOA -extern int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_COCOA diff --git a/src/video/cocoa/SDL_cocoamessagebox.m b/src/video/cocoa/SDL_cocoamessagebox.m index b33ec60401..689c47a714 100644 --- a/src/video/cocoa/SDL_cocoamessagebox.m +++ b/src/video/cocoa/SDL_cocoamessagebox.m @@ -66,7 +66,7 @@ } @end -static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, int *returnValue) +static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, bool *result) { NSAlert *alert; const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; @@ -119,26 +119,26 @@ static void Cocoa_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, i clicked = messageboxdata->numbuttons - 1 - clicked; } *buttonID = buttons[clicked].buttonID; - *returnValue = 0; + *result = true; } else { - *returnValue = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked); + *result = SDL_SetError("Did not get a valid `clicked button' id: %ld", (long)clicked); } } // Display a Cocoa message box -int Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { @autoreleasepool { - __block int returnValue = 0; + __block bool result = 0; if ([NSThread isMainThread]) { - Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &returnValue); + Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &result); } else { dispatch_sync(dispatch_get_main_queue(), ^{ - Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &returnValue); + Cocoa_ShowMessageBoxImpl(messageboxdata, buttonID, &result); }); } - return returnValue; + return result; } } diff --git a/src/video/cocoa/SDL_cocoamodes.h b/src/video/cocoa/SDL_cocoamodes.h index c29a473bf1..c4efd378f3 100644 --- a/src/video/cocoa/SDL_cocoamodes.h +++ b/src/video/cocoa/SDL_cocoamodes.h @@ -35,10 +35,10 @@ struct SDL_DisplayModeData extern void Cocoa_InitModes(SDL_VideoDevice *_this); extern void Cocoa_UpdateDisplays(SDL_VideoDevice *_this); -extern int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); -extern int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); -extern int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -extern int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +extern bool Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +extern bool Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); extern void Cocoa_QuitModes(SDL_VideoDevice *_this); #endif // SDL_cocoamodes_h_ diff --git a/src/video/cocoa/SDL_cocoamodes.m b/src/video/cocoa/SDL_cocoamodes.m index 19f1b8dfa4..533b37b354 100644 --- a/src/video/cocoa/SDL_cocoamodes.m +++ b/src/video/cocoa/SDL_cocoamodes.m @@ -41,7 +41,7 @@ #define kDisplayModeNativeFlag 0x02000000 #endif -static int CG_SetError(const char *prefix, CGDisplayErr result) +static bool CG_SetError(const char *prefix, CGDisplayErr result) { const char *error; @@ -409,7 +409,7 @@ void Cocoa_UpdateDisplays(SDL_VideoDevice *_this) } } -int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +bool Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal; CGRect cgrect; @@ -419,10 +419,10 @@ int Cocoa_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SD rect->y = (int)cgrect.origin.y; rect->w = (int)cgrect.size.width; rect->h = (int)cgrect.size.height; - return 0; + return true; } -int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +bool Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal; NSScreen *screen = GetNSScreenForDisplayID(displaydata->display); @@ -439,10 +439,10 @@ int Cocoa_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ rect->h = (int)frame.size.height; } - return 0; + return true; } -int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +bool Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { SDL_DisplayData *data = (SDL_DisplayData *)display->internal; CVDisplayLinkRef link = NULL; @@ -498,7 +498,7 @@ int Cocoa_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) } CVDisplayLinkRelease(link); - return 0; + return true; } static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayModeData *data) @@ -519,7 +519,7 @@ static CGError SetDisplayModeForDisplay(CGDirectDisplayID display, SDL_DisplayMo return result; } -int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +bool Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { SDL_DisplayData *displaydata = (SDL_DisplayData *)display->internal; SDL_DisplayModeData *data = mode->internal; @@ -550,10 +550,9 @@ int Cocoa_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_ b_inModeTransition = false; if (result != kCGErrorSuccess) { - CG_SetError("CGDisplaySwitchToMode()", result); - return -1; + return CG_SetError("CGDisplaySwitchToMode()", result); } - return 0; + return true; } void Cocoa_QuitModes(SDL_VideoDevice *_this) diff --git a/src/video/cocoa/SDL_cocoamouse.h b/src/video/cocoa/SDL_cocoamouse.h index b99d75b214..7dc257fd4b 100644 --- a/src/video/cocoa/SDL_cocoamouse.h +++ b/src/video/cocoa/SDL_cocoamouse.h @@ -25,7 +25,7 @@ #include "SDL_cocoavideo.h" -extern int Cocoa_InitMouse(SDL_VideoDevice *_this); +extern bool Cocoa_InitMouse(SDL_VideoDevice *_this); extern void Cocoa_HandleMouseEvent(SDL_VideoDevice *_this, NSEvent *event); extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event); extern void Cocoa_HandleMouseWarp(CGFloat x, CGFloat y); diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index c09b55d0ae..24d7863bed 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -237,7 +237,7 @@ static void Cocoa_FreeCursor(SDL_Cursor *cursor) } } -static int Cocoa_ShowCursor(SDL_Cursor *cursor) +static bool Cocoa_ShowCursor(SDL_Cursor *cursor) { @autoreleasepool { SDL_VideoDevice *device = SDL_GetVideoDevice(); @@ -250,7 +250,7 @@ static int Cocoa_ShowCursor(SDL_Cursor *cursor) waitUntilDone:NO]; } } - return 0; + return true; } } @@ -268,7 +268,7 @@ static SDL_Window *SDL_FindWindowAtPoint(const float x, const float y) return NULL; } -static int Cocoa_WarpMouseGlobal(float x, float y) +static bool Cocoa_WarpMouseGlobal(float x, float y) { CGPoint point; SDL_Mouse *mouse = SDL_GetMouse(); @@ -277,7 +277,7 @@ static int Cocoa_WarpMouseGlobal(float x, float y) if ([data.listener isMovingOrFocusClickPending]) { DLog("Postponing warp, window being moved or focused."); [data.listener setPendingMoveX:x Y:y]; - return 0; + return true; } } point = CGPointMake(x, y); @@ -306,15 +306,15 @@ static int Cocoa_WarpMouseGlobal(float x, float y) } } - return 0; + return true; } -static int Cocoa_WarpMouse(SDL_Window *window, float x, float y) +static bool Cocoa_WarpMouse(SDL_Window *window, float x, float y) { return Cocoa_WarpMouseGlobal(window->x + x, window->y + y); } -static int Cocoa_SetRelativeMouseMode(bool enabled) +static bool Cocoa_SetRelativeMouseMode(bool enabled) { CGError result; @@ -326,7 +326,7 @@ static int Cocoa_SetRelativeMouseMode(bool enabled) */ SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; if ([data.listener isMovingOrFocusClickPending]) { - return 0; + return true; } // make sure the mouse isn't at the corner of the window, as this can confuse things if macOS thinks a window resize is happening on the first click. @@ -352,41 +352,41 @@ static int Cocoa_SetRelativeMouseMode(bool enabled) } else { [NSCursor unhide]; } - return 0; + return true; } -static int Cocoa_CaptureMouse(SDL_Window *window) +static bool Cocoa_CaptureMouse(SDL_Window *window) { /* our Cocoa event code already tracks the mouse outside the window, so all we have to do here is say "okay" and do what we always do. */ - return 0; + return true; } static SDL_MouseButtonFlags Cocoa_GetGlobalMouseState(float *x, float *y) { const NSUInteger cocoaButtons = [NSEvent pressedMouseButtons]; const NSPoint cocoaLocation = [NSEvent mouseLocation]; - SDL_MouseButtonFlags retval = 0; + SDL_MouseButtonFlags result = 0; *x = cocoaLocation.x; *y = (CGDisplayPixelsHigh(kCGDirectMainDisplay) - cocoaLocation.y); - retval |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0; - retval |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0; - retval |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0; - retval |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0; - retval |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0; + result |= (cocoaButtons & (1 << 0)) ? SDL_BUTTON_LMASK : 0; + result |= (cocoaButtons & (1 << 1)) ? SDL_BUTTON_RMASK : 0; + result |= (cocoaButtons & (1 << 2)) ? SDL_BUTTON_MMASK : 0; + result |= (cocoaButtons & (1 << 3)) ? SDL_BUTTON_X1MASK : 0; + result |= (cocoaButtons & (1 << 4)) ? SDL_BUTTON_X2MASK : 0; - return retval; + return result; } -int Cocoa_InitMouse(SDL_VideoDevice *_this) +bool Cocoa_InitMouse(SDL_VideoDevice *_this) { NSPoint location; SDL_Mouse *mouse = SDL_GetMouse(); SDL_MouseData *internal = (SDL_MouseData *)SDL_calloc(1, sizeof(SDL_MouseData)); if (internal == NULL) { - return -1; + return false; } mouse->internal = internal; @@ -405,7 +405,7 @@ int Cocoa_InitMouse(SDL_VideoDevice *_this) location = [NSEvent mouseLocation]; internal->lastMoveX = location.x; internal->lastMoveY = location.y; - return 0; + return true; } static void Cocoa_HandleTitleButtonEvent(SDL_VideoDevice *_this, NSEvent *event) diff --git a/src/video/cocoa/SDL_cocoaopengl.h b/src/video/cocoa/SDL_cocoaopengl.h index 5ee8495962..747a3f9285 100644 --- a/src/video/cocoa/SDL_cocoaopengl.h +++ b/src/video/cocoa/SDL_cocoaopengl.h @@ -69,16 +69,15 @@ struct SDL_GLDriverData @end // OpenGL functions -extern int Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_FunctionPointer Cocoa_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); extern void Cocoa_GL_UnloadLibrary(SDL_VideoDevice *_this); extern SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, - SDL_GLContext context); -extern int Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); -extern int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); #ifdef __clang__ #pragma clang diagnostic pop diff --git a/src/video/cocoa/SDL_cocoaopengl.m b/src/video/cocoa/SDL_cocoaopengl.m index 0775f7aae2..b8e93ab55d 100644 --- a/src/video/cocoa/SDL_cocoaopengl.m +++ b/src/video/cocoa/SDL_cocoaopengl.m @@ -225,7 +225,7 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt @end -int Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) { // Load the OpenGL library if (path == NULL) { @@ -236,11 +236,11 @@ int Cocoa_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) } _this->gl_config.dll_handle = SDL_LoadObject(path); if (!_this->gl_config.dll_handle) { - return -1; + return false; } SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); - return 0; + return true; } SDL_FunctionPointer Cocoa_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc) @@ -284,7 +284,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) _this->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval; _this->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval; _this->GL_SwapWindow = Cocoa_GLES_SwapWindow; - _this->GL_DeleteContext = Cocoa_GLES_DeleteContext; + _this->GL_DestroyContext = Cocoa_GLES_DestroyContext; if (Cocoa_GLES_LoadLibrary(_this, NULL) != 0) { return NULL; @@ -385,7 +385,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) opaque = (window->flags & SDL_WINDOW_TRANSPARENT) ? 0 : 1; [context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity]; - if (Cocoa_GL_MakeCurrent(_this, window, sdlcontext) < 0) { + if (!Cocoa_GL_MakeCurrent(_this, window, sdlcontext)) { SDL_GL_DestroyContext(sdlcontext); SDL_SetError("Failed making OpenGL context current"); return NULL; @@ -435,7 +435,7 @@ SDL_GLContext Cocoa_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) } } -int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { @autoreleasepool { if (context) { @@ -449,44 +449,44 @@ int Cocoa_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLConte [NSOpenGLContext clearCurrentContext]; } - return 0; + return true; } } -int Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool Cocoa_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) { @autoreleasepool { SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext(); - int status; + bool result; if (nscontext == nil) { - status = SDL_SetError("No current OpenGL context"); + result = SDL_SetError("No current OpenGL context"); } else { SDL_LockMutex(nscontext->swapIntervalMutex); SDL_AtomicSet(&nscontext->swapIntervalsPassed, 0); SDL_AtomicSet(&nscontext->swapIntervalSetting, interval); SDL_UnlockMutex(nscontext->swapIntervalMutex); - status = 0; + result = true; } - return status; + return result; } } -int Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool Cocoa_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { @autoreleasepool { SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext(); if (nscontext) { *interval = SDL_AtomicGet(&nscontext->swapIntervalSetting); - return 0; + return true; } else { return SDL_SetError("no OpenGL context"); } } } -int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { @autoreleasepool { SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)SDL_GL_GetCurrentContext(); @@ -519,18 +519,18 @@ int Cocoa_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) [nscontext flushBuffer]; [nscontext updateIfNeeded]; SDL_UnlockMutex(videodata.swaplock); - return 0; + return true; } } -int Cocoa_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool Cocoa_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { @autoreleasepool { SDL3OpenGLContext *nscontext = (__bridge SDL3OpenGLContext *)context; [nscontext cleanup]; CFRelease(context); } - return 0; + return true; } // We still support OpenGL as long as Apple offers it, deprecated or not, so disable deprecation warnings about it. diff --git a/src/video/cocoa/SDL_cocoaopengles.h b/src/video/cocoa/SDL_cocoaopengles.h index 1b21b8a570..98ff00c68a 100644 --- a/src/video/cocoa/SDL_cocoaopengles.h +++ b/src/video/cocoa/SDL_cocoaopengles.h @@ -35,12 +35,12 @@ #define Cocoa_GLES_GetSwapInterval SDL_EGL_GetSwapInterval #define Cocoa_GLES_SetSwapInterval SDL_EGL_SetSwapInterval -extern int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int Cocoa_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); -extern int Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool Cocoa_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_EGLSurface Cocoa_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_VIDEO_OPENGL_EGL diff --git a/src/video/cocoa/SDL_cocoaopengles.m b/src/video/cocoa/SDL_cocoaopengles.m index aea4d0484e..6fb5e9ed9d 100644 --- a/src/video/cocoa/SDL_cocoaopengles.m +++ b/src/video/cocoa/SDL_cocoaopengles.m @@ -28,7 +28,7 @@ // EGL implementation of SDL OpenGL support -int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { // If the profile requested is not GL ES, switch over to WIN_GL functions if (_this->gl_config.profile_mask != SDL_GL_CONTEXT_PROFILE_ES) { @@ -42,7 +42,7 @@ int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval; _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval; _this->GL_SwapWindow = Cocoa_GL_SwapWindow; - _this->GL_DeleteContext = Cocoa_GL_DeleteContext; + _this->GL_DestroyContext = Cocoa_GL_DestroyContext; _this->GL_GetEGLSurface = NULL; return Cocoa_GL_LoadLibrary(_this, path); #else @@ -54,7 +54,7 @@ int Cocoa_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform); } - return 0; + return true; } SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) @@ -75,10 +75,10 @@ SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *windo _this->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval; _this->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval; _this->GL_SwapWindow = Cocoa_GL_SwapWindow; - _this->GL_DeleteContext = Cocoa_GL_DeleteContext; + _this->GL_DestroyContext = Cocoa_GL_DestroyContext; _this->GL_GetEGLSurface = NULL; - if (Cocoa_GL_LoadLibrary(_this, NULL) != 0) { + if (!Cocoa_GL_LoadLibrary(_this, NULL)) { return NULL; } @@ -91,29 +91,29 @@ SDL_GLContext Cocoa_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *windo } } -int Cocoa_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool Cocoa_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { @autoreleasepool { - SDL_EGL_DeleteContext(_this, context); + SDL_EGL_DestroyContext(_this, context); } - return 0; + return true; } -int Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { @autoreleasepool { return SDL_EGL_SwapBuffers(_this, ((__bridge SDL_CocoaWindowData *)window->internal).egl_surface); } } -int Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool Cocoa_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { @autoreleasepool { return SDL_EGL_MakeCurrent(_this, window ? ((__bridge SDL_CocoaWindowData *)window->internal).egl_surface : EGL_NO_SURFACE, context); } } -int Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) { @autoreleasepool { NSView *v; @@ -127,9 +127,9 @@ int Cocoa_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) #if 0 // When hint SDL_HINT_OPENGL_ES_DRIVER is set to "1" (e.g. for ANGLE support), _this->gl_config.driver_loaded can be 1, while the below lines function. SDL_assert(!_this->gl_config.driver_loaded); #endif - if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform) < 0) { + if (!SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform)) { SDL_EGL_UnloadLibrary(_this); - return -1; + return false; } _this->gl_config.driver_loaded = 1; } diff --git a/src/video/cocoa/SDL_cocoapen.h b/src/video/cocoa/SDL_cocoapen.h index a91531e1f2..140d0940ac 100644 --- a/src/video/cocoa/SDL_cocoapen.h +++ b/src/video/cocoa/SDL_cocoapen.h @@ -25,7 +25,7 @@ #include "SDL_cocoavideo.h" -extern int Cocoa_InitPen(SDL_VideoDevice *_this); +extern bool Cocoa_InitPen(SDL_VideoDevice *_this); extern bool Cocoa_HandlePenEvent(SDL_CocoaWindowData *_data, NSEvent *event); // return false if we didn't handle this event. extern void Cocoa_QuitPen(SDL_VideoDevice *_this); diff --git a/src/video/cocoa/SDL_cocoapen.m b/src/video/cocoa/SDL_cocoapen.m index 5d068fad15..c9ebcaca1f 100644 --- a/src/video/cocoa/SDL_cocoapen.m +++ b/src/video/cocoa/SDL_cocoapen.m @@ -27,9 +27,9 @@ #include "../../events/SDL_pen_c.h" -int Cocoa_InitPen(SDL_VideoDevice *_this) +bool Cocoa_InitPen(SDL_VideoDevice *_this) { - return 0; + return true; } typedef struct Cocoa_PenHandle diff --git a/src/video/cocoa/SDL_cocoashape.h b/src/video/cocoa/SDL_cocoashape.h index a16d9321f6..82d42e6737 100644 --- a/src/video/cocoa/SDL_cocoashape.h +++ b/src/video/cocoa/SDL_cocoashape.h @@ -23,6 +23,6 @@ #ifndef SDL_cocoashape_h_ #define SDL_cocoashape_h_ -extern int Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); +extern bool Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); #endif // SDL_cocoashape_h_ diff --git a/src/video/cocoa/SDL_cocoashape.m b/src/video/cocoa/SDL_cocoashape.m index ff9eaa355f..ab98aa5cbd 100644 --- a/src/video/cocoa/SDL_cocoashape.m +++ b/src/video/cocoa/SDL_cocoashape.m @@ -26,7 +26,7 @@ #include "SDL_cocoashape.h" -int Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape) +bool Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape) { SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; BOOL ignoresMouseEvents = NO; @@ -42,13 +42,13 @@ int Cocoa_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surf int y = (int)SDL_roundf((point.y / (window->h - 1)) * (shape->h - 1)); Uint8 a; - if (SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) < 0 || a == SDL_ALPHA_TRANSPARENT) { + if (!SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) || a == SDL_ALPHA_TRANSPARENT) { ignoresMouseEvents = YES; } } } data.nswindow.ignoresMouseEvents = ignoresMouseEvents; - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_COCOA diff --git a/src/video/cocoa/SDL_cocoavideo.m b/src/video/cocoa/SDL_cocoavideo.m index 5a50d13a08..85795e1410 100644 --- a/src/video/cocoa/SDL_cocoavideo.m +++ b/src/video/cocoa/SDL_cocoavideo.m @@ -41,7 +41,7 @@ @end // Initialization/Query functions -static int Cocoa_VideoInit(SDL_VideoDevice *_this); +static bool Cocoa_VideoInit(SDL_VideoDevice *_this); static void Cocoa_VideoQuit(SDL_VideoDevice *_this); // Cocoa driver bootstrap functions @@ -134,7 +134,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void) device->GL_SetSwapInterval = Cocoa_GL_SetSwapInterval; device->GL_GetSwapInterval = Cocoa_GL_GetSwapInterval; device->GL_SwapWindow = Cocoa_GL_SwapWindow; - device->GL_DeleteContext = Cocoa_GL_DeleteContext; + device->GL_DestroyContext = Cocoa_GL_DestroyContext; device->GL_GetEGLSurface = NULL; #endif #ifdef SDL_VIDEO_OPENGL_EGL @@ -149,7 +149,7 @@ static SDL_VideoDevice *Cocoa_CreateDevice(void) device->GL_SetSwapInterval = Cocoa_GLES_SetSwapInterval; device->GL_GetSwapInterval = Cocoa_GLES_GetSwapInterval; device->GL_SwapWindow = Cocoa_GLES_SwapWindow; - device->GL_DeleteContext = Cocoa_GLES_DeleteContext; + device->GL_DestroyContext = Cocoa_GLES_DestroyContext; device->GL_GetEGLSurface = Cocoa_GLES_GetEGLSurface; #ifdef SDL_VIDEO_OPENGL_CGL } @@ -192,17 +192,18 @@ VideoBootStrap COCOA_bootstrap = { Cocoa_ShowMessageBox }; -int Cocoa_VideoInit(SDL_VideoDevice *_this) +static bool Cocoa_VideoInit(SDL_VideoDevice *_this) { @autoreleasepool { SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal; Cocoa_InitModes(_this); Cocoa_InitKeyboard(_this); - if (Cocoa_InitMouse(_this) < 0) { - return -1; - } else if (Cocoa_InitPen(_this) < 0) { - return -1; + if (!Cocoa_InitMouse(_this)) { + return false; + } + if (!Cocoa_InitPen(_this)) { + return false; } // Assume we have a mouse and keyboard @@ -215,10 +216,10 @@ int Cocoa_VideoInit(SDL_VideoDevice *_this) data.swaplock = SDL_CreateMutex(); if (!data.swaplock) { - return -1; + return false; } - return 0; + return true; } } diff --git a/src/video/cocoa/SDL_cocoavulkan.h b/src/video/cocoa/SDL_cocoavulkan.h index 12e58f34ea..6b872bc4b3 100644 --- a/src/video/cocoa/SDL_cocoavulkan.h +++ b/src/video/cocoa/SDL_cocoavulkan.h @@ -34,16 +34,15 @@ #if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_COCOA) -int Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void Cocoa_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, +extern bool Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void Cocoa_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); -void Cocoa_Vulkan_DestroySurface(SDL_VideoDevice *_this, +extern void Cocoa_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); diff --git a/src/video/cocoa/SDL_cocoavulkan.m b/src/video/cocoa/SDL_cocoavulkan.m index 04dd93d2c6..d3f857dcf8 100644 --- a/src/video/cocoa/SDL_cocoavulkan.m +++ b/src/video/cocoa/SDL_cocoavulkan.m @@ -46,7 +46,7 @@ const char *defaultPaths[] = { // Since libSDL is most likely a .dylib, need RTLD_DEFAULT not RTLD_SELF. #define DEFAULT_HANDLE RTLD_DEFAULT -int Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 extensionCount = 0; @@ -143,12 +143,12 @@ int Cocoa_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) SDL_SetError("Installed Vulkan Portability library doesn't implement the " VK_EXT_METAL_SURFACE_EXTENSION_NAME " or " VK_MVK_MACOS_SURFACE_EXTENSION_NAME " extensions"); goto fail; } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void Cocoa_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -173,18 +173,18 @@ char const* const* Cocoa_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, return extensionsForCocoa; } -static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this, - SDL_Window *window, - VkInstance instance, - const struct VkAllocationCallbacks *allocator, - VkSurfaceKHR *surface, - PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT, - PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK) +static bool Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this, + SDL_Window *window, + VkInstance instance, + const struct VkAllocationCallbacks *allocator, + VkSurfaceKHR *surface, + PFN_vkCreateMetalSurfaceEXT vkCreateMetalSurfaceEXT, + PFN_vkCreateMacOSSurfaceMVK vkCreateMacOSSurfaceMVK) { - VkResult result; + VkResult rc; SDL_MetalView metalview = Cocoa_Metal_CreateView(_this, window); if (metalview == NULL) { - return -1; + return false; } if (vkCreateMetalSurfaceEXT) { @@ -194,10 +194,10 @@ static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this, createInfo.flags = 0; createInfo.pLayer = (__bridge const CAMetalLayer *) Cocoa_Metal_GetLayer(_this, metalview); - result = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface); - if (result != VK_SUCCESS) { + rc = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface); + if (rc != VK_SUCCESS) { Cocoa_Metal_DestroyView(_this, metalview); - return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(result));; + return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(rc)); } } else { VkMacOSSurfaceCreateInfoMVK createInfo = {}; @@ -205,11 +205,11 @@ static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this, createInfo.pNext = NULL; createInfo.flags = 0; createInfo.pView = (const void *)metalview; - result = vkCreateMacOSSurfaceMVK(instance, &createInfo, + rc = vkCreateMacOSSurfaceMVK(instance, &createInfo, NULL, surface); - if (result != VK_SUCCESS) { + if (rc != VK_SUCCESS) { Cocoa_Metal_DestroyView(_this, metalview); - return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(result)); + return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(rc)); } } @@ -223,10 +223,10 @@ static int Cocoa_Vulkan_CreateSurfaceViaMetalView(SDL_VideoDevice *_this, * knowledge of Metal can proceed. */ CFBridgingRelease(metalview); - return 0; // success! + return true; // success! } -int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, @@ -242,7 +242,7 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, (PFN_vkCreateMacOSSurfaceMVK)vkGetInstanceProcAddr( instance, "vkCreateMacOSSurfaceMVK"); - VkResult result; + VkResult rc; if (!_this->vulkan_config.loader_handle) { return SDL_SetError("Vulkan is not loaded"); @@ -266,9 +266,9 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, createInfo.pNext = NULL; createInfo.flags = 0; createInfo.pLayer = (CAMetalLayer *)data.sdlContentView.layer; - result = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface); - if (result != VK_SUCCESS) { - return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(result)); + rc = vkCreateMetalSurfaceEXT(instance, &createInfo, allocator, surface); + if (rc != VK_SUCCESS) { + return SDL_SetError("vkCreateMetalSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(rc)); } } else { VkMacOSSurfaceCreateInfoMVK createInfo = {}; @@ -276,10 +276,10 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, createInfo.pNext = NULL; createInfo.flags = 0; createInfo.pView = (__bridge const void *)data.sdlContentView; - result = vkCreateMacOSSurfaceMVK(instance, &createInfo, + rc = vkCreateMacOSSurfaceMVK(instance, &createInfo, allocator, surface); - if (result != VK_SUCCESS) { - return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(result)); + if (rc != VK_SUCCESS) { + return SDL_SetError("vkCreateMacOSSurfaceMVK failed: %s", SDL_Vulkan_GetResultString(rc)); } } } @@ -287,7 +287,7 @@ int Cocoa_Vulkan_CreateSurface(SDL_VideoDevice *_this, return Cocoa_Vulkan_CreateSurfaceViaMetalView(_this, window, instance, allocator, surface, vkCreateMetalSurfaceEXT, vkCreateMacOSSurfaceMVK); } - return 0; + return true; } void Cocoa_Vulkan_DestroySurface(SDL_VideoDevice *_this, diff --git a/src/video/cocoa/SDL_cocoawindow.h b/src/video/cocoa/SDL_cocoawindow.h index c77427e1b3..3e0413871b 100644 --- a/src/video/cocoa/SDL_cocoawindow.h +++ b/src/video/cocoa/SDL_cocoawindow.h @@ -155,15 +155,15 @@ typedef enum extern bool b_inModeTransition; -extern int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern void Cocoa_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); -extern int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); +extern bool Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); extern void Cocoa_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); extern void Cocoa_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window); extern void Cocoa_SetWindowMaximumSize(SDL_VideoDevice *_this, SDL_Window *window); extern void Cocoa_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h); -extern int Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); +extern bool Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); extern void Cocoa_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Cocoa_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Cocoa_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); @@ -173,17 +173,17 @@ extern void Cocoa_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Cocoa_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); extern void Cocoa_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); extern void Cocoa_SetWindowAlwaysOnTop(SDL_VideoDevice *_this, SDL_Window *window, bool on_top); -extern int Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +extern SDL_FullscreenResult Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); extern void *Cocoa_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t *size); extern SDL_DisplayID Cocoa_GetDisplayForWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); extern void Cocoa_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled); +extern bool Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled); extern void Cocoa_AcceptDragAndDrop(SDL_Window *window, bool accept); -extern int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); -extern int Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); -extern int Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); -extern int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); +extern bool Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); +extern bool Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); +extern bool Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_cocoawindow_h_ diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 668907e2ef..ba12e02f69 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -441,7 +441,7 @@ static void ScheduleContextUpdates(SDL_CocoaWindowData *data) } // !!! FIXME: this should use a hint callback. -static int GetHintCtrlClickEmulateRightClick(void) +static bool GetHintCtrlClickEmulateRightClick(void) { return SDL_GetHintBoolean(SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK, false); } @@ -925,7 +925,7 @@ static NSCursor *Cocoa_GetDesiredCursor(void) int y = (int)SDL_roundf(((window->h - point.y) / (window->h - 1)) * (shape->h - 1)); Uint8 a; - if (SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) < 0 || a == SDL_ALPHA_TRANSPARENT) { + if (!SDL_ReadSurfacePixel(shape, x, y, NULL, NULL, NULL, &a) || a == SDL_ALPHA_TRANSPARENT) { ignoresMouseEvents = YES; } } @@ -1538,12 +1538,11 @@ static NSCursor *Cocoa_GetDesiredCursor(void) return NO; // not a special area, carry on. } -static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, const Uint8 state, const Uint8 button) +static void Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_Window *window, const Uint8 state, const Uint8 button) { SDL_MouseID mouseID = SDL_DEFAULT_MOUSE_ID; const int clicks = (int)[theEvent clickCount]; SDL_Window *focus = SDL_GetKeyboardFocus(); - int rc; // macOS will send non-left clicks to background windows without raising them, so we need to // temporarily adjust the mouse position when this happens, as `mouse` will be tracking @@ -1551,19 +1550,17 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ // event for the background window, this just makes sure the button is reported at the // correct position in its own event. if (focus && ([theEvent window] == ((__bridge SDL_CocoaWindowData *)focus->internal).nswindow)) { - rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks); + SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks); } else { const float orig_x = mouse->x; const float orig_y = mouse->y; const NSPoint point = [theEvent locationInWindow]; mouse->x = (int)point.x; mouse->y = (int)(window->h - point.y); - rc = SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks); + SDL_SendMouseButtonClicks(Cocoa_GetEventTimestamp([theEvent timestamp]), window, mouseID, state, button, clicks); mouse->x = orig_x; mouse->y = orig_y; } - - return rc; } - (void)mouseDown:(NSEvent *)theEvent @@ -2005,7 +2002,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_ @end -static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow *nswindow, NSView *nsview) +static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow *nswindow, NSView *nsview) { @autoreleasepool { SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->internal; @@ -2137,11 +2134,11 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow // All done! window->internal = (SDL_WindowData *)CFBridgingRetain(data); - return 0; + return true; } } -int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { @autoreleasepool { SDL_CocoaVideoData *videodata = (__bridge SDL_CocoaVideoData *)_this->internal; @@ -2273,29 +2270,29 @@ int Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie #endif // SDL_VIDEO_OPENGL_ES2 [nswindow setContentView:nsview]; - if (SetupWindowData(_this, window, nswindow, nsview) < 0) { - return -1; + if (!SetupWindowData(_this, window, nswindow, nsview)) { + return false; } if (!(window->flags & SDL_WINDOW_OPENGL)) { - return 0; + return true; } // The rest of this macro mess is for OpenGL or OpenGL ES windows #ifdef SDL_VIDEO_OPENGL_ES2 if (_this->gl_config.profile_mask == SDL_GL_CONTEXT_PROFILE_ES) { #ifdef SDL_VIDEO_OPENGL_EGL - if (Cocoa_GLES_SetupWindow(_this, window) < 0) { + if (!Cocoa_GLES_SetupWindow(_this, window)) { Cocoa_DestroyWindow(_this, window); - return -1; + return false; } - return 0; + return true; #else return SDL_SetError("Could not create GLES window surface (EGL support not configured)"); #endif // SDL_VIDEO_OPENGL_EGL } #endif // SDL_VIDEO_OPENGL_ES2 - return 0; + return true; } } @@ -2309,7 +2306,7 @@ void Cocoa_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) } } -int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon) +bool Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon) { @autoreleasepool { NSImage *nsimage = Cocoa_CreateImage(icon); @@ -2317,14 +2314,14 @@ int Cocoa_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface if (nsimage) { [NSApp setApplicationIconImage:nsimage]; - return 0; + return true; } return SDL_SetError("Unable to set the window's icon"); } } -int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { @autoreleasepool { SDL_CocoaWindowData *windata = (__bridge SDL_CocoaWindowData *)window->internal; @@ -2374,7 +2371,7 @@ int Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) windata.send_floating_position = true; } } - return 0; + return true; } void Cocoa_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) @@ -2702,7 +2699,7 @@ void Cocoa_SetWindowAlwaysOnTop(SDL_VideoDevice *_this, SDL_Window *window, bool } } -int Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) +SDL_FullscreenResult Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { @autoreleasepool { SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; @@ -2821,7 +2818,7 @@ int Cocoa_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vi ScheduleContextUpdates(data); } - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } void *Cocoa_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t *size) @@ -2896,13 +2893,13 @@ SDL_DisplayID Cocoa_GetDisplayForWindow(SDL_VideoDevice *_this, SDL_Window *wind } } -int Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) { Cocoa_UpdateClipCursor(window); - return 0; + return true; } -int Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { @autoreleasepool { SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; @@ -2922,7 +2919,7 @@ int Cocoa_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool gr } } - return 0; + return true; } void Cocoa_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -3036,12 +3033,12 @@ bool Cocoa_SetWindowFullscreenSpace(SDL_Window *window, bool state, bool blockin } } -int Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled) +bool Cocoa_SetWindowHitTest(SDL_Window *window, bool enabled) { SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; [data.listener updateHitTest]; - return 0; + return true; } void Cocoa_AcceptDragAndDrop(SDL_Window *window, bool accept) @@ -3057,7 +3054,7 @@ void Cocoa_AcceptDragAndDrop(SDL_Window *window, bool accept) } } -int Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) +bool Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) { @autoreleasepool { SDL_CocoaWindowData *modal_data = (__bridge SDL_CocoaWindowData *)modal_window->internal; @@ -3072,10 +3069,10 @@ int Cocoa_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SD } } - return 0; + return true; } -int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) +bool Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) { @autoreleasepool { // Note that this is app-wide and not window-specific! @@ -3099,27 +3096,27 @@ int Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOpera default: return SDL_Unsupported(); } - return 0; + return true; } } -int Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable) +bool Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable) { - return 0; // just succeed, the real work is done elsewhere. + return true; // just succeed, the real work is done elsewhere. } -int Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) +bool Cocoa_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) { @autoreleasepool { SDL_CocoaWindowData *data = (__bridge SDL_CocoaWindowData *)window->internal; [data.nswindow setAlphaValue:opacity]; - return 0; + return true; } } -int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) { - int ret = 0; + bool result = true; @autoreleasepool { /* The timeout needs to be high enough that animated fullscreen @@ -3131,7 +3128,7 @@ int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) SDL_PumpEvents(); if (SDL_GetTicksNS() >= timeout) { - ret = 1; + result = false; break; } if (![data.listener hasPendingWindowOperation]) { @@ -3142,7 +3139,7 @@ int Cocoa_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) } } - return ret; + return result; } #endif // SDL_VIDEO_DRIVER_COCOA diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c index 38d6c0a955..6d1af9c5ed 100644 --- a/src/video/dummy/SDL_nullframebuffer.c +++ b/src/video/dummy/SDL_nullframebuffer.c @@ -29,7 +29,7 @@ #define DUMMY_SURFACE "SDL.internal.window.surface" -int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_Surface *surface; const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XRGB8888; @@ -39,7 +39,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window SDL_GetWindowSizeInPixels(window, &w, &h); surface = SDL_CreateSurface(w, h, surface_format); if (!surface) { - return -1; + return false; } // Save the info and return! @@ -47,10 +47,10 @@ int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window *format = surface_format; *pixels = surface->pixels; *pitch = surface->pitch; - return 0; + return true; } -int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { static int frame_number; SDL_Surface *surface; @@ -67,7 +67,7 @@ int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window SDL_GetWindowID(window), ++frame_number); SDL_SaveBMP(surface, file); } - return 0; + return true; } void SDL_DUMMY_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/dummy/SDL_nullframebuffer_c.h b/src/video/dummy/SDL_nullframebuffer_c.h index c946cc19a6..3f25ee405c 100644 --- a/src/video/dummy/SDL_nullframebuffer_c.h +++ b/src/video/dummy/SDL_nullframebuffer_c.h @@ -24,8 +24,8 @@ #include "SDL_internal.h" -extern int SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -extern int SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern bool SDL_DUMMY_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool SDL_DUMMY_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); extern void SDL_DUMMY_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_nullframebuffer_c_h_ diff --git a/src/video/dummy/SDL_nullvideo.c b/src/video/dummy/SDL_nullvideo.c index 52551268f1..98b485bedf 100644 --- a/src/video/dummy/SDL_nullvideo.c +++ b/src/video/dummy/SDL_nullvideo.c @@ -52,13 +52,13 @@ #define DUMMYVID_DRIVER_EVDEV_NAME "evdev" // Initialization/Query functions -static int DUMMY_VideoInit(SDL_VideoDevice *_this); +static bool DUMMY_VideoInit(SDL_VideoDevice *_this); static void DUMMY_VideoQuit(SDL_VideoDevice *_this); -static int DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +static bool DUMMY_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_MOVED, window->floating.x, window->floating.y); - return 0; + return true; } static void DUMMY_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) @@ -149,7 +149,7 @@ VideoBootStrap DUMMY_evdev_bootstrap = { #endif // SDL_INPUT_LINUXEV -int DUMMY_VideoInit(SDL_VideoDevice *_this) +bool DUMMY_VideoInit(SDL_VideoDevice *_this) { SDL_DisplayMode mode; @@ -159,7 +159,7 @@ int DUMMY_VideoInit(SDL_VideoDevice *_this) mode.w = 1024; mode.h = 768; if (SDL_AddBasicVideoDisplay(&mode) == 0) { - return -1; + return false; } #ifdef SDL_INPUT_LINUXEV @@ -167,7 +167,7 @@ int DUMMY_VideoInit(SDL_VideoDevice *_this) #endif // We're done! - return 0; + return true; } void DUMMY_VideoQuit(SDL_VideoDevice *_this) diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c index d2d3fb0217..50e945bc5f 100644 --- a/src/video/emscripten/SDL_emscriptenframebuffer.c +++ b/src/video/emscripten/SDL_emscriptenframebuffer.c @@ -27,7 +27,7 @@ #include -int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_Surface *surface; const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XBGR8888; @@ -43,7 +43,7 @@ int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo surface = SDL_CreateSurface(w, h, surface_format); if (!surface) { - return -1; + return false; } // Save the info and return! @@ -51,10 +51,10 @@ int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo *format = surface_format; *pixels = surface->pixels; *pitch = surface->pitch; - return 0; + return true; } -int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { SDL_Surface *surface; @@ -147,7 +147,7 @@ int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *windo emscripten_sleep(0); } - return 0; + return true; } void Emscripten_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.h b/src/video/emscripten/SDL_emscriptenframebuffer.h index c2406ecad1..43447013e8 100644 --- a/src/video/emscripten/SDL_emscriptenframebuffer.h +++ b/src/video/emscripten/SDL_emscriptenframebuffer.h @@ -23,8 +23,8 @@ #ifndef SDL_emscriptenframebuffer_h_ #define SDL_emscriptenframebuffer_h_ -extern int Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -extern int Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern bool Emscripten_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool Emscripten_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); extern void Emscripten_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_emscriptenframebuffer_h_ diff --git a/src/video/emscripten/SDL_emscriptenmouse.c b/src/video/emscripten/SDL_emscriptenmouse.c index eff5b07935..8ded04d10f 100644 --- a/src/video/emscripten/SDL_emscriptenmouse.c +++ b/src/video/emscripten/SDL_emscriptenmouse.c @@ -140,7 +140,7 @@ static void Emscripten_FreeCursor(SDL_Cursor *cursor) } } -static int Emscripten_ShowCursor(SDL_Cursor *cursor) +static bool Emscripten_ShowCursor(SDL_Cursor *cursor) { SDL_CursorData *curdata; if (SDL_GetMouseFocus() != NULL) { @@ -166,10 +166,10 @@ static int Emscripten_ShowCursor(SDL_Cursor *cursor) /* *INDENT-ON* */ // clang-format on } } - return 0; + return true; } -static int Emscripten_SetRelativeMouseMode(bool enabled) +static bool Emscripten_SetRelativeMouseMode(bool enabled) { SDL_Window *window; SDL_WindowData *window_data; @@ -178,20 +178,20 @@ static int Emscripten_SetRelativeMouseMode(bool enabled) if (enabled) { window = SDL_GetMouseFocus(); if (!window) { - return -1; + return false; } window_data = window->internal; if (emscripten_request_pointerlock(window_data->canvas_id, 1) >= EMSCRIPTEN_RESULT_SUCCESS) { - return 0; + return true; } } else { if (emscripten_exit_pointerlock() >= EMSCRIPTEN_RESULT_SUCCESS) { - return 0; + return true; } } - return -1; + return false; } void Emscripten_InitMouse(void) diff --git a/src/video/emscripten/SDL_emscriptenopengles.c b/src/video/emscripten/SDL_emscriptenopengles.c index e3be1b475c..a5140b8c5f 100644 --- a/src/video/emscripten/SDL_emscriptenopengles.c +++ b/src/video/emscripten/SDL_emscriptenopengles.c @@ -29,9 +29,9 @@ #include "SDL_emscriptenvideo.h" #include "SDL_emscriptenopengles.h" -int Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { - return 0; + return true; } void Emscripten_GLES_UnloadLibrary(SDL_VideoDevice *_this) @@ -43,7 +43,7 @@ SDL_FunctionPointer Emscripten_GLES_GetProcAddress(SDL_VideoDevice *_this, const return emscripten_webgl_get_proc_address(proc); } -int Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) { if (interval < 0) { return SDL_SetError("Late swap tearing currently unsupported"); @@ -53,10 +53,10 @@ int Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) emscripten_set_main_loop_timing(EM_TIMING_RAF, interval); } - return 0; + return true; } -int Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { int mode, value; @@ -64,10 +64,10 @@ int Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) if (mode == EM_TIMING_RAF) { *interval = value; - return 0; + return true; } else { *interval = 0; - return 0; + return true; } } @@ -112,7 +112,7 @@ SDL_GLContext Emscripten_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window * return (SDL_GLContext)context; } -int Emscripten_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool Emscripten_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { SDL_Window *window; @@ -126,19 +126,19 @@ int Emscripten_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) } emscripten_webgl_destroy_context((EMSCRIPTEN_WEBGL_CONTEXT_HANDLE)context); - return 0; + return true; } -int Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { if (emscripten_has_asyncify() && SDL_GetHintBoolean(SDL_HINT_EMSCRIPTEN_ASYNCIFY, true)) { // give back control to browser for screen refresh emscripten_sleep(0); } - return 0; + return true; } -int Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { // it isn't possible to reuse contexts across canvases if (window && context) { @@ -152,7 +152,7 @@ int Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_ if (emscripten_webgl_make_context_current((EMSCRIPTEN_WEBGL_CONTEXT_HANDLE)context) != EMSCRIPTEN_RESULT_SUCCESS) { return SDL_SetError("Unable to make context current"); } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_EMSCRIPTEN diff --git a/src/video/emscripten/SDL_emscriptenopengles.h b/src/video/emscripten/SDL_emscriptenopengles.h index 2515ef9af8..bd70ea474f 100644 --- a/src/video/emscripten/SDL_emscriptenopengles.h +++ b/src/video/emscripten/SDL_emscriptenopengles.h @@ -28,15 +28,15 @@ #include "../SDL_sysvideo.h" // OpenGLES functions -extern int Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool Emscripten_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern void Emscripten_GLES_UnloadLibrary(SDL_VideoDevice *_this); extern SDL_FunctionPointer Emscripten_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -extern int Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool Emscripten_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool Emscripten_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); extern SDL_GLContext Emscripten_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int Emscripten_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); -extern int Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool Emscripten_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool Emscripten_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Emscripten_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); #endif // SDL_VIDEO_DRIVER_EMSCRIPTEN diff --git a/src/video/emscripten/SDL_emscriptenvideo.c b/src/video/emscripten/SDL_emscriptenvideo.c index c07d370ebf..02b193c7f1 100644 --- a/src/video/emscripten/SDL_emscriptenvideo.c +++ b/src/video/emscripten/SDL_emscriptenvideo.c @@ -35,16 +35,16 @@ #define EMSCRIPTENVID_DRIVER_NAME "emscripten" // Initialization/Query functions -static int Emscripten_VideoInit(SDL_VideoDevice *_this); -static int Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +static bool Emscripten_VideoInit(SDL_VideoDevice *_this); +static bool Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); static void Emscripten_VideoQuit(SDL_VideoDevice *_this); -static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +static bool Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); -static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +static bool Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); static void Emscripten_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h); static void Emscripten_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); -static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +static SDL_FullscreenResult Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); static void Emscripten_PumpEvents(SDL_VideoDevice *_this); static void Emscripten_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); @@ -107,7 +107,7 @@ static SDL_VideoDevice *Emscripten_CreateDevice(void) device->GL_SetSwapInterval = Emscripten_GLES_SetSwapInterval; device->GL_GetSwapInterval = Emscripten_GLES_GetSwapInterval; device->GL_SwapWindow = Emscripten_GLES_SwapWindow; - device->GL_DeleteContext = Emscripten_GLES_DeleteContext; + device->GL_DestroyContext = Emscripten_GLES_DestroyContext; device->free = Emscripten_DeleteDevice; @@ -120,7 +120,7 @@ VideoBootStrap Emscripten_bootstrap = { NULL // no ShowMessageBox implementation }; -int Emscripten_VideoInit(SDL_VideoDevice *_this) +bool Emscripten_VideoInit(SDL_VideoDevice *_this) { SDL_DisplayMode mode; @@ -131,7 +131,7 @@ int Emscripten_VideoInit(SDL_VideoDevice *_this) mode.pixel_density = emscripten_get_device_pixel_ratio(); if (SDL_AddBasicVideoDisplay(&mode) == 0) { - return -1; + return false; } Emscripten_InitMouse(); @@ -141,13 +141,13 @@ int Emscripten_VideoInit(SDL_VideoDevice *_this) SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false); // We're done! - return 0; + return true; } -static int Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +static bool Emscripten_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { // can't do this - return 0; + return true; } static void Emscripten_VideoQuit(SDL_VideoDevice *_this) @@ -155,7 +155,7 @@ static void Emscripten_VideoQuit(SDL_VideoDevice *_this) Emscripten_QuitMouse(); } -static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +static bool Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { if (rect) { rect->x = 0; @@ -167,7 +167,7 @@ static int Emscripten_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDi return window.innerHeight; }); } - return 0; + return true; } static void Emscripten_PumpEvents(SDL_VideoDevice *_this) @@ -175,7 +175,7 @@ static void Emscripten_PumpEvents(SDL_VideoDevice *_this) // do nothing. } -static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) +static bool Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { SDL_WindowData *wdata; double scaled_w, scaled_h; @@ -185,7 +185,7 @@ static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, S // Allocate window internal data wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return -1; + return false; } selector = SDL_GetHint(SDL_HINT_EMSCRIPTEN_CANVAS_SELECTOR); @@ -239,7 +239,7 @@ static int Emscripten_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, S Emscripten_RegisterEventHandlers(wdata); // Window has been successfully created - return 0; + return true; } static void Emscripten_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) @@ -291,7 +291,7 @@ static void Emscripten_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) } } -static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) +static SDL_FullscreenResult Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { SDL_WindowData *data; int res = -1; @@ -329,11 +329,11 @@ static int Emscripten_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *wi } if (res == EMSCRIPTEN_RESULT_SUCCESS) { - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } else if (res == EMSCRIPTEN_RESULT_DEFERRED) { - return 1; + return SDL_FULLSCREEN_PENDING; } else { - return -1; + return SDL_FULLSCREEN_FAILED; } } diff --git a/src/video/gdk/SDL_gdktextinput.cpp b/src/video/gdk/SDL_gdktextinput.cpp index c7e1739982..dec725c1e8 100644 --- a/src/video/gdk/SDL_gdktextinput.cpp +++ b/src/video/gdk/SDL_gdktextinput.cpp @@ -97,16 +97,15 @@ static void SDLCALL GDK_InternalHintCallback( } } -static int GDK_InternalEnsureTaskQueue(void) +static bool GDK_InternalEnsureTaskQueue(void) { if (!g_TextTaskQueue) { - if (SDL_GetGDKTaskQueue(&g_TextTaskQueue) < 0) { + if (!SDL_GetGDKTaskQueue(&g_TextTaskQueue)) { // SetError will be done for us. - return -1; + return false; } } - - return 0; + return true; } static void CALLBACK GDK_InternalTextEntryCallback(XAsyncBlock *asyncBlock) @@ -178,7 +177,7 @@ void GDK_EnsureHints(void) } } -int GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) +bool GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { /* * Currently a stub, since all input is handled by the virtual keyboard, @@ -191,16 +190,16 @@ int GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie * Right now this function isn't implemented on Desktop * and seems to be present only in the docs? So I didn't bother. */ - return 0; + return true; } -int GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) +bool GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) { // See notice in GDK_StartTextInput - return 0; + return true; } -int GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) +bool GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) { /* * XGameUiShowTextEntryAsync does not allow you to set @@ -211,13 +210,13 @@ int GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) * * Right now it's a stub which may be useful later. */ - return 0; + return true; } -int GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window) +bool GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window) { // See notice in GDK_StartTextInput - return 0; + return true; } bool GDK_HasScreenKeyboardSupport(SDL_VideoDevice *_this) @@ -243,7 +242,7 @@ void GDK_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_Prop return; } - if (GDK_InternalEnsureTaskQueue() < 0) { + if (!GDK_InternalEnsureTaskQueue()) { // unable to obtain the SDL GDK queue return; } diff --git a/src/video/gdk/SDL_gdktextinput.h b/src/video/gdk/SDL_gdktextinput.h index 37a7ba18f1..471dbe3381 100644 --- a/src/video/gdk/SDL_gdktextinput.h +++ b/src/video/gdk/SDL_gdktextinput.h @@ -32,10 +32,10 @@ extern "C" { void GDK_EnsureHints(void); -int GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -int GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); -int GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); -int GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window); +bool GDK_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +bool GDK_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); +bool GDK_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); +bool GDK_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window); bool GDK_HasScreenKeyboardSupport(SDL_VideoDevice *_this); void GDK_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h index c0f137ba81..afe766cc11 100644 --- a/src/video/haiku/SDL_BWin.h +++ b/src/video/haiku/SDL_BWin.h @@ -127,7 +127,7 @@ class SDL_BWin : public BWindow if (_SDL_GLView == _cur_view) RemoveChild(_SDL_GLView); _SDL_GLView = NULL; - // _SDL_GLView deleted by HAIKU_GL_DeleteContext + // _SDL_GLView deleted by HAIKU_GL_DestroyContext } #endif @@ -213,7 +213,7 @@ class SDL_BWin : public BWindow SDL_Looper->SetCurrentContext(NULL); _SDL_GLView = NULL; UpdateCurrentView(); - // _SDL_GLView deleted by HAIKU_GL_DeleteContext + // _SDL_GLView deleted by HAIKU_GL_DestroyContext } Unlock(); } diff --git a/src/video/haiku/SDL_bclipboard.cc b/src/video/haiku/SDL_bclipboard.cc index bee65da48e..f0b84e08d3 100644 --- a/src/video/haiku/SDL_bclipboard.cc +++ b/src/video/haiku/SDL_bclipboard.cc @@ -34,7 +34,8 @@ extern "C" { #endif -int HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text) { +bool HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text) +{ BMessage *clip = NULL; if (be_clipboard->Lock()) { be_clipboard->Clear(); @@ -47,7 +48,7 @@ int HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text) { } be_clipboard->Unlock(); } - return 0; + return true; } char *HAIKU_GetClipboardText(SDL_VideoDevice *_this) { diff --git a/src/video/haiku/SDL_bclipboard.h b/src/video/haiku/SDL_bclipboard.h index aba0e0da98..0ecc59c09a 100644 --- a/src/video/haiku/SDL_bclipboard.h +++ b/src/video/haiku/SDL_bclipboard.h @@ -24,7 +24,7 @@ #ifndef SDL_BCLIPBOARD_H #define SDL_BCLIPBOARD_H -extern int HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text); +extern bool HAIKU_SetClipboardText(SDL_VideoDevice *_this, const char *text); extern char *HAIKU_GetClipboardText(SDL_VideoDevice *_this); extern bool HAIKU_HasClipboardText(SDL_VideoDevice *_this); diff --git a/src/video/haiku/SDL_bframebuffer.cc b/src/video/haiku/SDL_bframebuffer.cc index 85a4383db2..545433f202 100644 --- a/src/video/haiku/SDL_bframebuffer.cc +++ b/src/video/haiku/SDL_bframebuffer.cc @@ -35,21 +35,22 @@ extern "C" { #endif -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) +{ return (SDL_BWin *)(window->internal); } -static SDL_INLINE SDL_BLooper *_GetBeLooper() { +static SDL_INLINE SDL_BLooper *_GetBeLooper() +{ return SDL_Looper; } -int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, - SDL_PixelFormat * format, - void ** pixels, int *pitch) { +bool HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format, void ** pixels, int *pitch) +{ SDL_BWin *bwin = _ToBeWin(window); BScreen bscreen; if (!bscreen.IsValid()) { - return -1; + return false; } // Make sure we have exclusive access to frame buffer data @@ -87,22 +88,22 @@ int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, *pitch = bitmap->BytesPerRow(); bwin->UnlockBuffer(); - return 0; + return true; } -int HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, +bool HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, const SDL_Rect * rects, int numrects) { if (!window) { - return 0; + return true; } SDL_BWin *bwin = _ToBeWin(window); bwin->PostMessage(BWIN_UPDATE_FRAMEBUFFER); - return 0; + return true; } void HAIKU_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window) { diff --git a/src/video/haiku/SDL_bframebuffer.h b/src/video/haiku/SDL_bframebuffer.h index fcb6bcd811..d61619515a 100644 --- a/src/video/haiku/SDL_bframebuffer.h +++ b/src/video/haiku/SDL_bframebuffer.h @@ -30,11 +30,11 @@ extern "C" { #include "../SDL_sysvideo.h" -extern int HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, - SDL_PixelFormat *format, - void **pixels, int *pitch); -extern int HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, - const SDL_Rect *rects, int numrects); +extern bool HAIKU_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, + SDL_PixelFormat *format, + void **pixels, int *pitch); +extern bool HAIKU_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, + const SDL_Rect *rects, int numrects); extern void HAIKU_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); extern int32 HAIKU_DrawThread(void *data); diff --git a/src/video/haiku/SDL_bmessagebox.cc b/src/video/haiku/SDL_bmessagebox.cc index 25f6f3de51..a7001fa978 100644 --- a/src/video/haiku/SDL_bmessagebox.cc +++ b/src/video/haiku/SDL_bmessagebox.cc @@ -335,7 +335,7 @@ protected: extern "C" { #endif -int HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { // Initialize button by closed or error value first. *buttonID = G_CLOSE_BUTTON_ID; @@ -373,7 +373,7 @@ int HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID // Initialize button by real pushed value then. *buttonID = pushedButton; - return 0; + return true; } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bmessagebox.h b/src/video/haiku/SDL_bmessagebox.h index 07149c66f7..07d989a26e 100644 --- a/src/video/haiku/SDL_bmessagebox.h +++ b/src/video/haiku/SDL_bmessagebox.h @@ -31,8 +31,7 @@ extern "C" { #endif -extern int -HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool HAIKU_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #ifdef __cplusplus } diff --git a/src/video/haiku/SDL_bmodes.cc b/src/video/haiku/SDL_bmodes.cc index 39f0aa4b8b..871df88381 100644 --- a/src/video/haiku/SDL_bmodes.cc +++ b/src/video/haiku/SDL_bmodes.cc @@ -48,15 +48,18 @@ struct SDL_DisplayModeData { }; #endif -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) +{ return (SDL_BWin *)(window->internal); } -static SDL_INLINE SDL_BLooper *_GetBeLooper() { +static SDL_INLINE SDL_BLooper *_GetBeLooper() +{ return SDL_Looper; } -static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) { +static SDL_INLINE display_mode * _ExtractBMode(SDL_DisplayMode *mode) +{ #if WRAP_BMODE return mode->internal->bmode; #else @@ -76,7 +79,8 @@ static void get_refresh_rate(display_mode &mode, int *numerator, int *denominato /* TODO: * This is a useful debugging tool. Uncomment and insert into code as needed. */ -void _SpoutModeData(display_mode *bmode) { +void _SpoutModeData(display_mode *bmode) +{ printf("BMode:\n"); printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height); printf("\th,v = (%i,%i)\n", bmode->h_display_start, @@ -166,7 +170,8 @@ SDL_PixelFormat HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace) return SDL_PIXELFORMAT_UNKNOWN; } -static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) { +static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode *mode) +{ SDL_zerop(mode); mode->w = bmode->virtual_width; mode->h = bmode->virtual_height; @@ -186,7 +191,8 @@ static void _BDisplayModeToSdlDisplayMode(display_mode *bmode, SDL_DisplayMode * } // Later, there may be more than one monitor available -static void _AddDisplay(BScreen *screen) { +static void _AddDisplay(BScreen *screen) +{ SDL_DisplayMode mode; display_mode bmode; screen->GetMode(&bmode); @@ -200,32 +206,35 @@ static void _AddDisplay(BScreen *screen) { * Functions called by SDL */ -int HAIKU_InitModes(SDL_VideoDevice *_this) { +bool HAIKU_InitModes(SDL_VideoDevice *_this) +{ BScreen screen; /* TODO: When Haiku supports multiple display screens, call _AddDisplayScreen() for each of them. */ _AddDisplay(&screen); - return 0; + return true; } -int HAIKU_QuitModes(SDL_VideoDevice *_this) { - // FIXME: Nothing really needs to be done here at the moment? - return 0; +void HAIKU_QuitModes(SDL_VideoDevice *_this) +{ + return; } -int HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { +bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +{ BScreen bscreen; BRect rc = bscreen.Frame(); rect->x = (int)rc.left; rect->y = (int)rc.top; rect->w = (int)rc.Width() + 1; rect->h = (int)rc.Height() + 1; - return 0; + return true; } -int HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { +bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +{ // Get the current screen BScreen bscreen; @@ -247,11 +256,12 @@ int HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { } } free(bmodes); // This should not be SDL_free() - return 0; + return true; } -int HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { +bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +{ // Get the current screen BScreen bscreen; if (!bscreen.IsValid()) { @@ -287,7 +297,7 @@ int HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_ // HAIKU_GL_RebootContexts(_this); #endif - return 0; + return true; } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bmodes.h b/src/video/haiku/SDL_bmodes.h index bb57a06a24..2aab11d0c0 100644 --- a/src/video/haiku/SDL_bmodes.h +++ b/src/video/haiku/SDL_bmodes.h @@ -30,13 +30,11 @@ extern "C" { extern SDL_PixelFormat HAIKU_ColorSpaceToSDLPxFormat(uint32 colorspace); -extern int HAIKU_InitModes(SDL_VideoDevice *_this); -extern int HAIKU_QuitModes(SDL_VideoDevice *_this); -extern int HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, - SDL_Rect *rect); -extern int HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -extern int HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, - SDL_DisplayMode *mode); +extern bool HAIKU_InitModes(SDL_VideoDevice *_this); +extern void HAIKU_QuitModes(SDL_VideoDevice *_this); +extern bool HAIKU_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +extern bool HAIKU_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool HAIKU_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); #ifdef __cplusplus } diff --git a/src/video/haiku/SDL_bopengl.cc b/src/video/haiku/SDL_bopengl.cc index 55e303d457..e69e08c353 100644 --- a/src/video/haiku/SDL_bopengl.cc +++ b/src/video/haiku/SDL_bopengl.cc @@ -35,16 +35,18 @@ extern "C" { #endif -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) +{ return (SDL_BWin *)(window->internal); } -static SDL_INLINE SDL_BLooper *_GetBeLooper() { +static SDL_INLINE SDL_BLooper *_GetBeLooper() +{ return SDL_Looper; } // Passing a NULL path means load pointers from the application -int HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) { // FIXME: Is this working correctly? image_info info; @@ -60,7 +62,7 @@ int HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) SDL_arraysize(_this->gl_config.driver_path)); } } - return 0; + return true; } SDL_FunctionPointer HAIKU_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc) @@ -84,12 +86,14 @@ SDL_FunctionPointer HAIKU_GL_GetProcAddress(SDL_VideoDevice *_this, const char * } -int HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window * window) { +bool HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ _ToBeWin(window)->SwapBuffers(); - return 0; + return true; } -int HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context) { +bool HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context) +{ BGLView* glView = (BGLView*)context; // printf("HAIKU_GL_MakeCurrent(%llx), win = %llx, thread = %d\n", (uint64)context, (uint64)window, find_thread(NULL)); if (glView) { @@ -98,11 +102,12 @@ int HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLCont } } _GetBeLooper()->SetCurrentContext(glView); - return 0; + return true; } -SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window * window) { +SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window * window) +{ /* FIXME: Not sure what flags should be included here; may want to have most of them */ SDL_BWin *bwin = _ToBeWin(window); @@ -142,8 +147,9 @@ SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window * window return (SDL_GLContext)(bwin->GetGLView()); } -int HAIKU_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) { - // printf("HAIKU_GL_DeleteContext(%llx), thread = %d\n", (uint64)context, find_thread(NULL)); +bool HAIKU_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) +{ + // printf("HAIKU_GL_DestroyContext(%llx), thread = %d\n", (uint64)context, find_thread(NULL)); BGLView* glView = (BGLView*)context; SDL_BWin *bwin = (SDL_BWin*)glView->Window(); if (!bwin) { @@ -151,21 +157,24 @@ int HAIKU_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) { } else { bwin->RemoveGLView(); } - return 0; + return true; } -int HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) { +bool HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) +{ // TODO: Implement this, if necessary? return SDL_Unsupported(); } -int HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { +bool HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +{ return SDL_Unsupported(); } -void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this) { +void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this) +{ // TODO: Implement this, if necessary? } @@ -173,7 +182,8 @@ void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this) { /* FIXME: This function is meant to clear the OpenGL context when the video mode changes (see SDL_bmodes.cc), but it doesn't seem to help, and is not currently in use. */ -void HAIKU_GL_RebootContexts(SDL_VideoDevice *_this) { +void HAIKU_GL_RebootContexts(SDL_VideoDevice *_this) +{ SDL_Window *window = _this->windows; while (window) { SDL_BWin *bwin = _ToBeWin(window); diff --git a/src/video/haiku/SDL_bopengl.h b/src/video/haiku/SDL_bopengl.h index f8cc10228e..3b40c9b557 100644 --- a/src/video/haiku/SDL_bopengl.h +++ b/src/video/haiku/SDL_bopengl.h @@ -30,16 +30,16 @@ extern "C" { #include "../SDL_sysvideo.h" -extern int HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); // FIXME +extern bool HAIKU_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); // FIXME extern SDL_FunctionPointer HAIKU_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); // FIXME extern void HAIKU_GL_UnloadLibrary(SDL_VideoDevice *_this); // TODO -extern int HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, +extern bool HAIKU_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); // TODO -extern int HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); // TODO -extern int HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool HAIKU_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); // TODO +extern bool HAIKU_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); // TODO +extern bool HAIKU_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_GLContext HAIKU_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int HAIKU_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool HAIKU_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); extern void HAIKU_GL_RebootContexts(SDL_VideoDevice *_this); diff --git a/src/video/haiku/SDL_bvideo.cc b/src/video/haiku/SDL_bvideo.cc index b22b637ee6..942fc966c3 100644 --- a/src/video/haiku/SDL_bvideo.cc +++ b/src/video/haiku/SDL_bvideo.cc @@ -96,7 +96,7 @@ static SDL_VideoDevice * HAIKU_CreateDevice(void) device->GL_SetSwapInterval = HAIKU_GL_SetSwapInterval; device->GL_GetSwapInterval = HAIKU_GL_GetSwapInterval; device->GL_SwapWindow = HAIKU_GL_SwapWindow; - device->GL_DeleteContext = HAIKU_GL_DeleteContext; + device->GL_DestroyContext = HAIKU_GL_DestroyContext; #endif device->SetClipboardText = HAIKU_SetClipboardText; @@ -208,12 +208,12 @@ static SDL_Cursor * HAIKU_CreateCursor(SDL_Surface * surface, int hot_x, int hot return HAIKU_CreateCursorAndData(new BCursor(cursorBitmap, BPoint(hot_x, hot_y))); } -static int HAIKU_ShowCursor(SDL_Cursor *cursor) +static bool HAIKU_ShowCursor(SDL_Cursor *cursor) { SDL_Mouse *mouse = SDL_GetMouse(); if (!mouse) { - return 0; + return true; } if (cursor) { @@ -225,14 +225,14 @@ static int HAIKU_ShowCursor(SDL_Cursor *cursor) delete hCursor; } - return 0; + return true; } -static int HAIKU_SetRelativeMouseMode(bool enabled) +static bool HAIKU_SetRelativeMouseMode(bool enabled) { SDL_Window *window = SDL_GetMouseFocus(); if (!window) { - return 0; + return true; } SDL_BWin *bewin = _ToBeWin(window); @@ -245,7 +245,7 @@ static int HAIKU_SetRelativeMouseMode(bool enabled) _SDL_GLView->SetEventMask(0, 0); bewin->Unlock(); - return 0; + return true; } static void HAIKU_MouseInit(SDL_VideoDevice *_this) @@ -263,11 +263,11 @@ static void HAIKU_MouseInit(SDL_VideoDevice *_this) SDL_SetDefaultCursor(HAIKU_CreateDefaultCursor()); } -int HAIKU_VideoInit(SDL_VideoDevice *_this) +bool HAIKU_VideoInit(SDL_VideoDevice *_this) { // Initialize the Be Application for appserver interaction - if (SDL_InitBeApp() < 0) { - return -1; + if (!SDL_InitBeApp()) { + return false; } // Initialize video modes @@ -289,7 +289,7 @@ int HAIKU_VideoInit(SDL_VideoDevice *_this) #endif // We're done! - return 0; + return true; } void HAIKU_VideoQuit(SDL_VideoDevice *_this) @@ -301,12 +301,15 @@ void HAIKU_VideoQuit(SDL_VideoDevice *_this) } // just sticking this function in here so it's in a C++ source file. -extern "C" { int HAIKU_OpenURL(const char *url); } -int HAIKU_OpenURL(const char *url) +extern "C" +bool HAIKU_OpenURL(const char *url) { BUrl burl(url); const status_t rc = burl.OpenWithPreferredApplication(false); - return (rc == B_NO_ERROR) ? 0 : SDL_SetError("URL open failed (err=%d)", (int)rc); + if (rc != B_NO_ERROR) { + return SDL_SetError("URL open failed (err=%d)", (int)rc); + } + return true; } #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bvideo.h b/src/video/haiku/SDL_bvideo.h index 3c225c303a..1f0ceccf50 100644 --- a/src/video/haiku/SDL_bvideo.h +++ b/src/video/haiku/SDL_bvideo.h @@ -30,7 +30,7 @@ extern "C" { #include "../SDL_sysvideo.h" extern void HAIKU_VideoQuit(SDL_VideoDevice *_this); -extern int HAIKU_VideoInit(SDL_VideoDevice *_this); +extern bool HAIKU_VideoInit(SDL_VideoDevice *_this); extern void HAIKU_DeleteDevice(SDL_VideoDevice *_this); #ifdef __cplusplus diff --git a/src/video/haiku/SDL_bwindow.cc b/src/video/haiku/SDL_bwindow.cc index 2ec0e2ed9f..b6eca9db3d 100644 --- a/src/video/haiku/SDL_bwindow.cc +++ b/src/video/haiku/SDL_bwindow.cc @@ -31,15 +31,18 @@ extern "C" { #endif -static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) { +static SDL_INLINE SDL_BWin *_ToBeWin(SDL_Window *window) +{ return (SDL_BWin *)(window->internal); } -static SDL_INLINE SDL_BLooper *_GetBeLooper() { +static SDL_INLINE SDL_BLooper *_GetBeLooper() +{ return SDL_Looper; } -static int _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { +static bool _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +{ uint32 flags = 0; window_look look = B_TITLED_WINDOW_LOOK; @@ -66,112 +69,127 @@ static int _InitWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie SDL_BWin *bwin = new(std::nothrow) SDL_BWin(bounds, look, flags); if (!bwin) { - return -1; + return false; } window->internal = (SDL_WindowData *)bwin; int32 winID = _GetBeLooper()->GetID(window); bwin->SetID(winID); - return 0; + return true; } -int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { - if (_InitWindow(_this, window, create_props) < 0) { - return -1; +bool HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +{ + if (!_InitWindow(_this, window, create_props)) { + return false; } // Start window loop _ToBeWin(window)->Show(); - return 0; + return true; } -void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_SET_TITLE); msg.AddString("window-title", window->title); _ToBeWin(window)->PostMessage(&msg); } -int HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window) { +bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_MOVE_WINDOW); msg.AddInt32("window-x", window->floating.x); msg.AddInt32("window-y", window->floating.y); _ToBeWin(window)->PostMessage(&msg); - return 0; + return true; } -void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_RESIZE_WINDOW); msg.AddInt32("window-w", window->floating.w - 1); msg.AddInt32("window-h", window->floating.h - 1); _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window * window, bool bordered) { +void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window * window, bool bordered) +{ BMessage msg(BWIN_SET_BORDERED); msg.AddBool("window-border", bordered != false); _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window * window, bool resizable) { +void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window * window, bool resizable) +{ BMessage msg(BWIN_SET_RESIZABLE); msg.AddBool("window-resizable", resizable != false); _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_SHOW_WINDOW); _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_HideWindow(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_HideWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_HIDE_WINDOW); _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_RaiseWindow(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_RaiseWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_SHOW_WINDOW); // Activate this window and move to front _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_MAXIMIZE_WINDOW); _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_MINIMIZE_WINDOW); _ToBeWin(window)->PostMessage(&msg); } -void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_RESTORE_WINDOW); _ToBeWin(window)->PostMessage(&msg); } -int HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window * window, - SDL_VideoDisplay * display, SDL_FullscreenOp fullscreen) { +SDL_FullscreenResult HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay * display, SDL_FullscreenOp fullscreen) +{ // Haiku tracks all video display information BMessage msg(BWIN_FULLSCREEN); msg.AddBool("fullscreen", !!fullscreen); _ToBeWin(window)->PostMessage(&msg); - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } -void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window * window) +{ BMessage msg(BWIN_MINIMUM_SIZE_WINDOW); msg.AddInt32("window-w", window->w -1); msg.AddInt32("window-h", window->h -1); _ToBeWin(window)->PostMessage(&msg); } -int HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window * window, bool grabbed) { +bool HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window * window, bool grabbed) +{ // TODO: Implement this! return SDL_Unsupported(); } -int HAIKU_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) { +bool HAIKU_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) +{ if (modal_window->parent && modal_window->parent != parent_window) { // Remove from the subset of a previous parent. _ToBeWin(modal_window)->RemoveFromSubset(_ToBeWin(modal_window->parent)); @@ -187,10 +205,11 @@ int HAIKU_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SD _ToBeWin(modal_window)->SetFeel(B_NORMAL_WINDOW_FEEL); } - return 0; + return true; } -void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window * window) { +void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window * window) +{ _ToBeWin(window)->LockLooper(); // This MUST be locked _GetBeLooper()->ClearID(_ToBeWin(window)); _ToBeWin(window)->Quit(); diff --git a/src/video/haiku/SDL_bwindow.h b/src/video/haiku/SDL_bwindow.h index 82815322aa..98c88d77fd 100644 --- a/src/video/haiku/SDL_bwindow.h +++ b/src/video/haiku/SDL_bwindow.h @@ -24,9 +24,9 @@ #include "../SDL_sysvideo.h" -extern int HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool HAIKU_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern void HAIKU_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -extern int HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern bool HAIKU_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); extern void HAIKU_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); extern void HAIKU_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window); extern void HAIKU_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); @@ -37,8 +37,8 @@ extern void HAIKU_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void HAIKU_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void HAIKU_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); extern void HAIKU_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); -extern int HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); -extern int HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern SDL_FullscreenResult HAIKU_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +extern bool HAIKU_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); extern void HAIKU_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); #endif diff --git a/src/video/kmsdrm/SDL_kmsdrmdyn.c b/src/video/kmsdrm/SDL_kmsdrmdyn.c index 2be54e027e..0ffe3fb576 100644 --- a/src/video/kmsdrm/SDL_kmsdrmdyn.c +++ b/src/video/kmsdrm/SDL_kmsdrmdyn.c @@ -109,9 +109,9 @@ void SDL_KMSDRM_UnloadSymbols(void) } // returns non-zero if all needed symbols were loaded. -int SDL_KMSDRM_LoadSymbols(void) +bool SDL_KMSDRM_LoadSymbols(void) { - int rc = 1; // always succeed if not using Dynamic KMSDRM stuff. + bool result = true; // always succeed if not using Dynamic KMSDRM stuff. // deal with multiple modules needing these symbols... if (kmsdrm_load_refcount++ == 0) { @@ -138,7 +138,7 @@ int SDL_KMSDRM_LoadSymbols(void) } else { // in case something got loaded... SDL_KMSDRM_UnloadSymbols(); - rc = 0; + result = false; } #else // no dynamic KMSDRM @@ -151,7 +151,7 @@ int SDL_KMSDRM_LoadSymbols(void) #endif } - return rc; + return result; } #endif // SDL_VIDEO_DRIVER_KMSDRM diff --git a/src/video/kmsdrm/SDL_kmsdrmdyn.h b/src/video/kmsdrm/SDL_kmsdrmdyn.h index 4a52f6381a..fb1fc0e580 100644 --- a/src/video/kmsdrm/SDL_kmsdrmdyn.h +++ b/src/video/kmsdrm/SDL_kmsdrmdyn.h @@ -32,8 +32,8 @@ extern "C" { #endif -int SDL_KMSDRM_LoadSymbols(void); -void SDL_KMSDRM_UnloadSymbols(void); +extern bool SDL_KMSDRM_LoadSymbols(void); +extern void SDL_KMSDRM_UnloadSymbols(void); // Declare all the function pointers and wrappers... #define SDL_KMSDRM_SYM(rc, fn, params) \ diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.c b/src/video/kmsdrm/SDL_kmsdrmmouse.c index 0ce28d35d1..a4a5c24e2b 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.c +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.c @@ -34,8 +34,8 @@ static SDL_Cursor *KMSDRM_CreateDefaultCursor(void); static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y); -static int KMSDRM_ShowCursor(SDL_Cursor *cursor); -static int KMSDRM_MoveCursor(SDL_Cursor *cursor); +static bool KMSDRM_ShowCursor(SDL_Cursor *cursor); +static bool KMSDRM_MoveCursor(SDL_Cursor *cursor); static void KMSDRM_FreeCursor(SDL_Cursor *cursor); /**************************************************************************************/ @@ -76,7 +76,7 @@ void KMSDRM_DestroyCursorBO(SDL_VideoDevice *_this, SDL_VideoDisplay *display) /* Given a display's internal, create the cursor BO for it. To be called from KMSDRM_CreateWindow(), as that's where we build a window and assign a display to it. */ -int KMSDRM_CreateCursorBO(SDL_VideoDisplay *display) +bool KMSDRM_CreateCursorBO(SDL_VideoDisplay *display) { SDL_VideoDevice *dev = SDL_GetVideoDevice(); @@ -109,29 +109,27 @@ int KMSDRM_CreateCursorBO(SDL_VideoDisplay *display) } dispdata->cursor_bo_drm_fd = viddata->drm_fd; - return 0; + return true; } // Remove a cursor buffer from a display's DRM cursor BO. -static int KMSDRM_RemoveCursorFromBO(SDL_VideoDisplay *display) +static bool KMSDRM_RemoveCursorFromBO(SDL_VideoDisplay *display) { - int ret = 0; + bool result = true; + SDL_DisplayData *dispdata = display->internal; SDL_VideoDevice *video_device = SDL_GetVideoDevice(); SDL_VideoData *viddata = video_device->internal; - ret = KMSDRM_drmModeSetCursor(viddata->drm_fd, - dispdata->crtc->crtc_id, 0, 0, 0); - - if (ret) { - ret = SDL_SetError("Could not hide current cursor with drmModeSetCursor()."); + const int rc = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id, 0, 0, 0); + if (rc < 0) { + result = SDL_SetError("drmModeSetCursor() failed: %s", strerror(-rc)); } - - return ret; + return result; } // Dump a cursor buffer to a display's DRM cursor BO. -static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) +static bool KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) { SDL_DisplayData *dispdata = display->internal; SDL_CursorData *curdata = cursor->internal; @@ -144,8 +142,8 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) uint8_t *ready_buffer = NULL; uint8_t *src_row; - int i; - int ret; + int i, rc; + bool result = true; if (!curdata || !dispdata->cursor_bo) { return SDL_SetError("Cursor or display not initialized properly."); @@ -159,7 +157,7 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) ready_buffer = (uint8_t *)SDL_calloc(1, bufsize); if (!ready_buffer) { - ret = -1; + result = false; goto cleanup; } @@ -171,27 +169,21 @@ static int KMSDRM_DumpCursorToBO(SDL_VideoDisplay *display, SDL_Cursor *cursor) // Dump the cursor buffer to our GBM BO. if (KMSDRM_gbm_bo_write(dispdata->cursor_bo, ready_buffer, bufsize)) { - ret = SDL_SetError("Could not write to GBM cursor BO"); + result = SDL_SetError("Could not write to GBM cursor BO"); goto cleanup; } // Put the GBM BO buffer on screen using the DRM interface. bo_handle = KMSDRM_gbm_bo_get_handle(dispdata->cursor_bo).u32; if (curdata->hot_x == 0 && curdata->hot_y == 0) { - ret = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id, + rc = KMSDRM_drmModeSetCursor(viddata->drm_fd, dispdata->crtc->crtc_id, bo_handle, dispdata->cursor_w, dispdata->cursor_h); } else { - ret = KMSDRM_drmModeSetCursor2(viddata->drm_fd, dispdata->crtc->crtc_id, + rc = KMSDRM_drmModeSetCursor2(viddata->drm_fd, dispdata->crtc->crtc_id, bo_handle, dispdata->cursor_w, dispdata->cursor_h, curdata->hot_x, curdata->hot_y); } - - if (ret) { - ret = SDL_SetError("Failed to set DRM cursor."); - goto cleanup; - } - - if (ret) { - ret = SDL_SetError("Failed to reset cursor position."); + if (rc < 0) { + result = SDL_SetError("Failed to set DRM cursor: %s", strerror(-rc)); goto cleanup; } @@ -200,7 +192,7 @@ cleanup: if (ready_buffer) { SDL_free(ready_buffer); } - return ret; + return result; } // This is only for freeing the SDL_cursor. @@ -230,10 +222,10 @@ static void KMSDRM_FreeCursor(SDL_Cursor *cursor) static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) { SDL_CursorData *curdata; - SDL_Cursor *cursor, *ret; + SDL_Cursor *cursor, *result; curdata = NULL; - ret = NULL; + result = NULL; cursor = (SDL_Cursor *)SDL_calloc(1, sizeof(*cursor)); if (!cursor) { @@ -271,10 +263,10 @@ static SDL_Cursor *KMSDRM_CreateCursor(SDL_Surface *surface, int hot_x, int hot_ cursor->internal = curdata; - ret = cursor; + result = cursor; cleanup: - if (!ret) { + if (!result) { if (curdata) { if (curdata->buffer) { SDL_free(curdata->buffer); @@ -286,26 +278,20 @@ cleanup: } } - return ret; + return result; } // Show the specified cursor, or hide if cursor is NULL or has no focus. -static int KMSDRM_ShowCursor(SDL_Cursor *cursor) +static bool KMSDRM_ShowCursor(SDL_Cursor *cursor) { SDL_VideoDisplay *display; SDL_Window *window; - SDL_Mouse *mouse; + SDL_Mouse *mouse = SDL_GetMouse(); int i; - int ret = 0; + bool result = true; // Get the mouse focused window, if any. - - mouse = SDL_GetMouse(); - if (!mouse) { - return SDL_SetError("No mouse."); - } - window = mouse->focus; if (!window || !cursor) { @@ -320,7 +306,7 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor) // Iterate on the displays, hiding the cursor. for (i = 0; i < displays[i]; i++) { display = SDL_GetVideoDisplay(displays[i]); - ret = KMSDRM_RemoveCursorFromBO(display); + result = KMSDRM_RemoveCursorFromBO(display); } SDL_free(displays); } @@ -330,23 +316,22 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor) if (cursor) { /* Dump the cursor to the display DRM cursor BO so it becomes visible on that display. */ - ret = KMSDRM_DumpCursorToBO(display, cursor); + result = KMSDRM_DumpCursorToBO(display, cursor); } else { // Hide the cursor on that display. - ret = KMSDRM_RemoveCursorFromBO(display); + result = KMSDRM_RemoveCursorFromBO(display); } } } - return ret; + return result; } -static int KMSDRM_WarpMouseGlobal(float x, float y) +static bool KMSDRM_WarpMouseGlobal(float x, float y) { SDL_Mouse *mouse = SDL_GetMouse(); if (mouse && mouse->cur_cursor && mouse->focus) { - SDL_Window *window = mouse->focus; SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); @@ -355,26 +340,20 @@ static int KMSDRM_WarpMouseGlobal(float x, float y) // And now update the cursor graphic position on screen. if (dispdata->cursor_bo) { - int ret = 0; - - ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)x, (int)y); - - if (ret) { - SDL_SetError("drmModeMoveCursor() failed."); + const int rc = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)x, (int)y); + if (rc < 0) { + return SDL_SetError("drmModeMoveCursor() failed: %s", strerror(-rc)); } - - return ret; - + return true; } else { return SDL_SetError("Cursor not initialized properly."); } - } else { return SDL_SetError("No mouse or current cursor."); } } -static int KMSDRM_WarpMouse(SDL_Window *window, float x, float y) +static bool KMSDRM_WarpMouse(SDL_Window *window, float x, float y) { // Only one global/fullscreen window is supported return KMSDRM_WarpMouseGlobal(x, y); @@ -406,15 +385,13 @@ void KMSDRM_QuitMouse(SDL_VideoDevice *_this) } // This is called when a mouse motion event occurs -static int KMSDRM_MoveCursor(SDL_Cursor *cursor) +static bool KMSDRM_MoveCursor(SDL_Cursor *cursor) { SDL_Mouse *mouse = SDL_GetMouse(); - int ret = 0; /* We must NOT call SDL_SendMouseMotion() here or we will enter recursivity! That's why we move the cursor graphic ONLY. */ if (mouse && mouse->cur_cursor && mouse->focus) { - SDL_Window *window = mouse->focus; SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); @@ -422,13 +399,12 @@ static int KMSDRM_MoveCursor(SDL_Cursor *cursor) return SDL_SetError("Cursor not initialized properly."); } - ret = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)mouse->x, (int)mouse->y); - - if (ret) { - return SDL_SetError("drmModeMoveCursor() failed."); + const int rc = KMSDRM_drmModeMoveCursor(dispdata->cursor_bo_drm_fd, dispdata->crtc->crtc_id, (int)mouse->x, (int)mouse->y); + if (rc < 0) { + return SDL_SetError("drmModeMoveCursor() failed: %s", strerror(-rc)); } } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_KMSDRM diff --git a/src/video/kmsdrm/SDL_kmsdrmmouse.h b/src/video/kmsdrm/SDL_kmsdrmmouse.h index 925fea20a5..d9512cad63 100644 --- a/src/video/kmsdrm/SDL_kmsdrmmouse.h +++ b/src/video/kmsdrm/SDL_kmsdrmmouse.h @@ -46,7 +46,7 @@ struct SDL_CursorData extern void KMSDRM_InitMouse(SDL_VideoDevice *_this, SDL_VideoDisplay *display); extern void KMSDRM_QuitMouse(SDL_VideoDevice *_this); -extern int KMSDRM_CreateCursorBO(SDL_VideoDisplay *display); +extern bool KMSDRM_CreateCursorBO(SDL_VideoDisplay *display); extern void KMSDRM_DestroyCursorBO(SDL_VideoDevice *_this, SDL_VideoDisplay *display); extern void KMSDRM_InitCursor(void); diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.c b/src/video/kmsdrm/SDL_kmsdrmopengles.c index d46f9b21c8..8f15de86c2 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.c +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.c @@ -46,7 +46,7 @@ void KMSDRM_GLES_DefaultProfileConfig(SDL_VideoDevice *_this, int *mask, int *ma #endif } -int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { /* Just pretend you do this here, but don't do it until KMSDRM_CreateWindow(), where we do the same library load we would normally do here. @@ -57,7 +57,7 @@ int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) NativeDisplayType display = (NativeDisplayType)_this->internal->gbm_dev; return SDL_EGL_LoadLibrary(_this, path, display, EGL_PLATFORM_GBM_MESA); #endif - return 0; + return true; } void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this) @@ -68,9 +68,8 @@ void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this) SDL_EGL_CreateContext_impl(KMSDRM) - int KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) { - if (!_this->egl_data) { return SDL_SetError("EGL not initialized"); } @@ -81,10 +80,10 @@ SDL_EGL_CreateContext_impl(KMSDRM) return SDL_SetError("Only swap intervals of 0 or 1 are supported"); } - return 0; + return true; } -int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *windata = window->internal; SDL_DisplayData *dispdata = SDL_GetDisplayDriverDataForWindow(window); @@ -100,7 +99,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) if (windata->egl_surface == EGL_NO_SURFACE) { // Wait a bit, throttling to ~100 FPS SDL_Delay(10); - return 0; + return true; } // Recreate the GBM / EGL surfaces if the display mode has changed @@ -111,8 +110,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) /* Wait for confirmation that the next front buffer has been flipped, at which point the previous front buffer can be released */ if (!KMSDRM_WaitPageflip(_this, windata)) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Wait for previous pageflip failed"); - return 0; + return SDL_SetError("Wait for previous pageflip failed"); } // Release the previous front buffer @@ -127,8 +125,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) This won't happen until pagelip completes. */ if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, windata->egl_surface))) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed"); - return 0; + return SDL_SetError("eglSwapBuffers failed"); } /* From the GBM surface, get the next BO to become the next front buffer, @@ -136,15 +133,13 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) from drawing into it!) */ windata->next_bo = KMSDRM_gbm_surface_lock_front_buffer(windata->gs); if (!windata->next_bo) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not lock front buffer on GBM surface"); - return 0; + return SDL_SetError("Could not lock front buffer on GBM surface"); } // Get an actual usable fb for the next front buffer. fb_info = KMSDRM_FBFromBO(_this, windata->next_bo); if (!fb_info) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not get a framebuffer"); - return 0; + return SDL_SetError("Could not get a framebuffer"); } if (!windata->bo) { @@ -156,8 +151,7 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) &dispdata->connector->connector_id, 1, &dispdata->mode); if (ret) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not set videomode on CRTC."); - return 0; + return SDL_SetError("Could not set videomode on CRTC."); } } else { /* On subsequent swaps, queue the new front buffer to be flipped during @@ -196,13 +190,12 @@ int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) to enable this. */ if (windata->double_buffer) { if (!KMSDRM_WaitPageflip(_this, windata)) { - SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Immediate wait for previous pageflip failed"); - return 0; + return SDL_SetError("Immediate wait for previous pageflip failed"); } } } - return 1; + return true; } SDL_EGL_MakeCurrent_impl(KMSDRM) diff --git a/src/video/kmsdrm/SDL_kmsdrmopengles.h b/src/video/kmsdrm/SDL_kmsdrmopengles.h index 6ef8b9c154..69e6fb7d07 100644 --- a/src/video/kmsdrm/SDL_kmsdrmopengles.h +++ b/src/video/kmsdrm/SDL_kmsdrmopengles.h @@ -31,15 +31,15 @@ // OpenGLES functions #define KMSDRM_GLES_GetAttribute SDL_EGL_GetAttribute #define KMSDRM_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal -#define KMSDRM_GLES_DeleteContext SDL_EGL_DeleteContext +#define KMSDRM_GLES_DestroyContext SDL_EGL_DestroyContext #define KMSDRM_GLES_GetSwapInterval SDL_EGL_GetSwapInterval extern void KMSDRM_GLES_DefaultProfileConfig(SDL_VideoDevice *_this, int *mask, int *major, int *minor); -extern int KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_GLContext KMSDRM_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); #endif // SDL_VIDEO_DRIVER_KMSDRM diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.c b/src/video/kmsdrm/SDL_kmsdrmvideo.c index 0a64b6cadf..d57d5ee6af 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.c +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.c @@ -188,7 +188,7 @@ static void CalculateRefreshRate(drmModeModeInfo *mode, int *numerator, int *den } } -static int KMSDRM_Available(void) +static bool KMSDRM_Available(void) { #ifdef SDL_PLATFORM_OPENBSD struct utsname nameofsystem; @@ -220,10 +220,10 @@ static int KMSDRM_Available(void) ret = get_driindex(); if (ret >= 0) { - return 1; + return true; } - return ret; + return false; } static void KMSDRM_DeleteDevice(SDL_VideoDevice *device) @@ -298,7 +298,7 @@ static SDL_VideoDevice *KMSDRM_CreateDevice(void) device->GL_SetSwapInterval = KMSDRM_GLES_SetSwapInterval; device->GL_GetSwapInterval = KMSDRM_GLES_GetSwapInterval; device->GL_SwapWindow = KMSDRM_GLES_SwapWindow; - device->GL_DeleteContext = KMSDRM_GLES_DeleteContext; + device->GL_DestroyContext = KMSDRM_GLES_DestroyContext; device->GL_DefaultProfileConfig = KMSDRM_GLES_DefaultProfileConfig; #ifdef SDL_VIDEO_VULKAN @@ -464,14 +464,14 @@ bool KMSDRM_WaitPageflip(SDL_VideoDevice *_this, SDL_WindowData *windata) } else { // There was another error. Don't pull again or we could get into a busy loop. SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll error"); - return false; // Return number 1. + return false; } } if (pfd.revents & (POLLHUP | POLLERR)) { // An event arrived on the FD in time, but it's an error. SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "DRM poll hup or error"); - return false; // Return number 2. + return false; } if (pfd.revents & POLLIN) { @@ -511,7 +511,7 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display, SDL_DisplayMode closest; drmModeModeInfo *drm_mode; - if (SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, false, &closest) == 0) { + if (SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, false, &closest)) { const SDL_DisplayModeData *modedata = closest.internal; drm_mode = &connector->modes[modedata->mode_index]; return drm_mode; @@ -994,15 +994,14 @@ cleanup: closed when we get to the end of this function. This is to be called early, in VideoInit(), because it gets us the videomode information, which SDL needs immediately after VideoInit(). */ -static int KMSDRM_InitDisplays(SDL_VideoDevice *_this) +static bool KMSDRM_InitDisplays(SDL_VideoDevice *_this) { SDL_VideoData *viddata = _this->internal; drmModeRes *resources = NULL; - uint64_t async_pageflip = 0; - int ret = 0; int i; + bool result = true; // Open /dev/dri/cardNN (/dev/drmN if on OpenBSD version less than 6.9) (void)SDL_snprintf(viddata->devpath, sizeof(viddata->devpath), "%s%d", @@ -1012,7 +1011,7 @@ static int KMSDRM_InitDisplays(SDL_VideoDevice *_this) viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC); if (viddata->drm_fd < 0) { - ret = SDL_SetError("Could not open %s", viddata->devpath); + result = SDL_SetError("Could not open %s", viddata->devpath); goto cleanup; } @@ -1021,7 +1020,7 @@ static int KMSDRM_InitDisplays(SDL_VideoDevice *_this) // Get all of the available connectors / devices / crtcs resources = KMSDRM_drmModeGetResources(viddata->drm_fd); if (!resources) { - ret = SDL_SetError("drmModeGetResources(%d) failed", viddata->drm_fd); + result = SDL_SetError("drmModeGetResources(%d) failed", viddata->drm_fd); goto cleanup; } @@ -1049,13 +1048,12 @@ static int KMSDRM_InitDisplays(SDL_VideoDevice *_this) // Have we added any SDL displays? if (SDL_GetPrimaryDisplay() == 0) { - ret = SDL_SetError("No connected displays found."); + result = SDL_SetError("No connected displays found."); goto cleanup; } // Determine if video hardware supports async pageflips. - ret = KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_ASYNC_PAGE_FLIP, &async_pageflip); - if (ret) { + if (KMSDRM_drmGetCap(viddata->drm_fd, DRM_CAP_ASYNC_PAGE_FLIP, &async_pageflip) != 0) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "Could not determine async page flip capability."); } viddata->async_pageflip_support = async_pageflip ? true : false; @@ -1073,13 +1071,13 @@ cleanup: if (resources) { KMSDRM_drmModeFreeResources(resources); } - if (ret) { + if (!result) { if (viddata->drm_fd >= 0) { close(viddata->drm_fd); viddata->drm_fd = -1; } } - return ret; + return result; } /* Init the Vulkan-INCOMPATIBLE stuff: @@ -1090,10 +1088,10 @@ cleanup: These things are incompatible with Vulkan, which accesses the same resources internally so they must be free when trying to build a Vulkan surface. */ -static int KMSDRM_GBMInit(SDL_VideoDevice *_this, SDL_DisplayData *dispdata) +static bool KMSDRM_GBMInit(SDL_VideoDevice *_this, SDL_DisplayData *dispdata) { SDL_VideoData *viddata = _this->internal; - int ret = 0; + bool result = true; // Reopen the FD! viddata->drm_fd = open(viddata->devpath, O_RDWR | O_CLOEXEC); @@ -1104,12 +1102,12 @@ static int KMSDRM_GBMInit(SDL_VideoDevice *_this, SDL_DisplayData *dispdata) // Create the GBM device. viddata->gbm_dev = KMSDRM_gbm_create_device(viddata->drm_fd); if (!viddata->gbm_dev) { - ret = SDL_SetError("Couldn't create gbm device."); + result = SDL_SetError("Couldn't create gbm device."); } viddata->gbm_init = true; - return ret; + return result; } // Deinit the Vulkan-incompatible KMSDRM stuff. @@ -1235,7 +1233,7 @@ static void KMSDRM_DirtySurfaces(SDL_Window *window) /* This determines the size of the fb, which comes from the GBM surface that we create here. */ -int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window) +bool KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window) { SDL_VideoData *viddata = _this->internal; SDL_WindowData *windata = window->internal; @@ -1247,7 +1245,7 @@ int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window) EGLContext egl_context; - int ret = 0; + bool result = true; // If the current window already has surfaces, destroy them before creating other. if (windata->gs) { @@ -1283,14 +1281,14 @@ int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window) windata->egl_surface = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)windata->gs); if (windata->egl_surface == EGL_NO_SURFACE) { - ret = SDL_SetError("Could not create EGL window surface"); + result = SDL_SetError("Could not create EGL window surface"); goto cleanup; } /* Current context passing to EGL is now done here. If something fails, go back to delayed SDL_EGL_MakeCurrent() call in SwapWindow. */ egl_context = (EGLContext)SDL_GL_GetCurrentContext(); - ret = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context); + result = SDL_EGL_MakeCurrent(_this, windata->egl_surface, egl_context); SDL_SendWindowEvent(window, SDL_EVENT_WINDOW_RESIZED, dispdata->mode.hdisplay, dispdata->mode.vdisplay); @@ -1299,7 +1297,7 @@ int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window) cleanup: - if (ret) { + if (!result) { // Error (complete) cleanup. if (windata->gs) { KMSDRM_gbm_surface_destroy(windata->gs); @@ -1307,7 +1305,7 @@ cleanup: } } - return ret; + return result; } #ifdef SDL_INPUT_LINUXEV @@ -1342,9 +1340,9 @@ static void KMSDRM_AcquireVT(void *userdata) } #endif // defined SDL_INPUT_LINUXEV -int KMSDRM_VideoInit(SDL_VideoDevice *_this) +bool KMSDRM_VideoInit(SDL_VideoDevice *_this) { - int ret = 0; + bool result = true; SDL_VideoData *viddata = _this->internal; SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "KMSDRM_VideoInit()"); @@ -1356,8 +1354,8 @@ int KMSDRM_VideoInit(SDL_VideoDevice *_this) this info isn't a problem for VK compatibility. For VK-incompatible initializations we have KMSDRM_GBMInit(), which is called on window creation, and only when we know it's not a VK window. */ - if (KMSDRM_InitDisplays(_this)) { - ret = SDL_SetError("error getting KMSDRM displays information"); + if (!KMSDRM_InitDisplays(_this)) { + result = SDL_SetError("error getting KMSDRM displays information"); } #ifdef SDL_INPUT_LINUXEV @@ -1369,7 +1367,7 @@ int KMSDRM_VideoInit(SDL_VideoDevice *_this) viddata->video_init = true; - return ret; + return result; } /* The internal pointers, like dispdata, viddata, windata, etc... @@ -1396,7 +1394,7 @@ void KMSDRM_VideoQuit(SDL_VideoDevice *_this) } // Read modes from the connector modes, and store them in display->display_modes. -int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +bool KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { SDL_DisplayData *dispdata = display->internal; drmModeConnector *conn = dispdata->connector; @@ -1421,10 +1419,10 @@ int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) SDL_free(modedata); } } - return 0; + return true; } -int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +bool KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { /* Set the dispdata->mode to the new mode and leave actual modesetting pending to be done on SwapWindow() via drmModeSetCrtc() */ @@ -1437,7 +1435,7 @@ int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL // Don't do anything if we are in Vulkan mode. if (viddata->vulkan_mode) { - return 0; + return true; } if (!modedata) { @@ -1452,7 +1450,7 @@ int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL KMSDRM_DirtySurfaces(viddata->windows[i]); } - return 0; + return true; } void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -1533,7 +1531,7 @@ void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) // reflect it: if it's fullscreen, KMSDRM_SetWindwoFullscreen() will // be called by SDL later, and we can manage it there. /**********************************************************************/ -int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *windata = NULL; SDL_VideoData *viddata = _this->internal; @@ -1543,12 +1541,12 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti bool vulkan_mode = viddata->vulkan_mode; // Do we have any Vulkan windows? NativeDisplayType egl_display; drmModeModeInfo *mode; - int ret = 0; + bool result = true; // Allocate window internal data windata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!windata) { - return -1; + return false; } // Setup driver data for this window @@ -1590,8 +1588,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti /* Reopen FD, create gbm dev, setup display plane, etc,. but only when we come here for the first time, and only if it's not a VK window. */ - ret = KMSDRM_GBMInit(_this, dispdata); - if (ret != 0) { + if (!KMSDRM_GBMInit(_this, dispdata)) { return SDL_SetError("Can't init GBM on window creation."); } } @@ -1603,12 +1600,12 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti before we call KMSDRM_GBMInit(), causing all GLES programs to fail. */ if (!_this->egl_data) { egl_display = (NativeDisplayType)_this->internal->gbm_dev; - if (SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA) < 0) { + if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) { // Try again with OpenGL ES 2.0 _this->gl_config.profile_mask = SDL_GL_CONTEXT_PROFILE_ES; _this->gl_config.major_version = 2; _this->gl_config.minor_version = 0; - if (SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA) < 0) { + if (!SDL_EGL_LoadLibrary(_this, NULL, egl_display, EGL_PLATFORM_GBM_MESA)) { return SDL_SetError("Can't load EGL/GL library on window creation."); } } @@ -1639,8 +1636,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti /* Create the window surfaces with the size we have just chosen. Needs the window diverdata in place. */ - ret = KMSDRM_CreateSurfaces(_this, window); - if (ret != 0) { + if (!KMSDRM_CreateSurfaces(_this, window)) { return SDL_SetError("Can't window GBM/EGL surfaces on window creation."); } } // NON-Vulkan block ends. @@ -1653,7 +1649,7 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti SDL_Window **new_windows = (SDL_Window **)SDL_realloc(viddata->windows, new_max_windows * sizeof(SDL_Window *)); if (!new_windows) { - return -1; + return false; } viddata->windows = new_windows; viddata->max_windows = new_max_windows; @@ -1678,13 +1674,13 @@ int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti /* Allocated windata will be freed in KMSDRM_DestroyWindow, and KMSDRM_DestroyWindow() will be called by SDL_CreateWindow() if we return error on any of the previous returns of the function. */ - return ret; + return result; } void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } -int KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { return SDL_Unsupported(); } @@ -1695,13 +1691,13 @@ void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) KMSDRM_DirtySurfaces(window); } } -int KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) +SDL_FullscreenResult KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { SDL_VideoData *viddata = _this->internal; if (!viddata->vulkan_mode) { KMSDRM_DirtySurfaces(window); } - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } void KMSDRM_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window) { diff --git a/src/video/kmsdrm/SDL_kmsdrmvideo.h b/src/video/kmsdrm/SDL_kmsdrmvideo.h index 86de178c44..16571ecff2 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvideo.h +++ b/src/video/kmsdrm/SDL_kmsdrmvideo.h @@ -146,42 +146,42 @@ typedef struct KMSDRM_FBInfo } KMSDRM_FBInfo; // Helper functions -int KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window); -KMSDRM_FBInfo *KMSDRM_FBFromBO(SDL_VideoDevice *_this, struct gbm_bo *bo); -KMSDRM_FBInfo *KMSDRM_FBFromBO2(SDL_VideoDevice *_this, struct gbm_bo *bo, int w, int h); -bool KMSDRM_WaitPageflip(SDL_VideoDevice *_this, SDL_WindowData *windata); +extern bool KMSDRM_CreateSurfaces(SDL_VideoDevice *_this, SDL_Window *window); +extern KMSDRM_FBInfo *KMSDRM_FBFromBO(SDL_VideoDevice *_this, struct gbm_bo *bo); +extern KMSDRM_FBInfo *KMSDRM_FBFromBO2(SDL_VideoDevice *_this, struct gbm_bo *bo, int w, int h); +extern bool KMSDRM_WaitPageflip(SDL_VideoDevice *_this, SDL_WindowData *windata); /****************************************************************************/ // SDL_VideoDevice functions declaration /****************************************************************************/ // Display and window functions -int KMSDRM_VideoInit(SDL_VideoDevice *_this); -void KMSDRM_VideoQuit(SDL_VideoDevice *_this); -int KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -int KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); -int KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); -void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -int KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); -void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); -int KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen); -void KMSDRM_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); -void KMSDRM_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); -void KMSDRM_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); -void KMSDRM_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void KMSDRM_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void KMSDRM_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); -void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool KMSDRM_VideoInit(SDL_VideoDevice *_this); +extern void KMSDRM_VideoQuit(SDL_VideoDevice *_this); +extern bool KMSDRM_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool KMSDRM_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool KMSDRM_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern void KMSDRM_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); +extern bool KMSDRM_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern void KMSDRM_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); +extern SDL_FullscreenResult KMSDRM_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen); +extern void KMSDRM_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void KMSDRM_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void KMSDRM_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void KMSDRM_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void KMSDRM_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void KMSDRM_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void KMSDRM_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); // OpenGL/OpenGL ES functions -int KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); -SDL_FunctionPointer KMSDRM_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this); -SDL_GLContext KMSDRM_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -int KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -int KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); -int KMSDRM_GLES_GetSwapInterval(SDL_VideoDevice *_this); -int KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -int KMSDRM_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool KMSDRM_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern SDL_FunctionPointer KMSDRM_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); +extern void KMSDRM_GLES_UnloadLibrary(SDL_VideoDevice *_this); +extern SDL_GLContext KMSDRM_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); +extern bool KMSDRM_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool KMSDRM_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool KMSDRM_GLES_GetSwapInterval(SDL_VideoDevice *_this); +extern bool KMSDRM_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool KMSDRM_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); #endif // SDL_kmsdrmvideo_h diff --git a/src/video/kmsdrm/SDL_kmsdrmvulkan.c b/src/video/kmsdrm/SDL_kmsdrmvulkan.c index b55619174f..c32adad91b 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvulkan.c +++ b/src/video/kmsdrm/SDL_kmsdrmvulkan.c @@ -42,7 +42,7 @@ #define DEFAULT_VULKAN "libvulkan.so.1" #endif -int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 i, extensionCount = 0; @@ -65,7 +65,7 @@ int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) _this->vulkan_config.loader_handle = SDL_LoadObject(path); if (!_this->vulkan_config.loader_handle) { - return -1; + return false; } SDL_strlcpy(_this->vulkan_config.loader_path, path, @@ -114,12 +114,12 @@ int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) goto fail; } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void KMSDRM_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -146,7 +146,9 @@ char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, static const char *const extensionsForKMSDRM[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME }; - if(count) { *count = SDL_arraysize(extensionsForKMSDRM); } + if (count) { + *count = SDL_arraysize(extensionsForKMSDRM); + } return extensionsForKMSDRM; } @@ -158,7 +160,7 @@ char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, // KMSDRM_Vulkan_GetInstanceExtensions(), like we do with // VK_KHR_DISPLAY_EXTENSION_NAME, which is what we need for x-less VK. /***********************************************************************/ -int KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, diff --git a/src/video/kmsdrm/SDL_kmsdrmvulkan.h b/src/video/kmsdrm/SDL_kmsdrmvulkan.h index 7f0d2a98b0..41ca95a7f5 100644 --- a/src/video/kmsdrm/SDL_kmsdrmvulkan.h +++ b/src/video/kmsdrm/SDL_kmsdrmvulkan.h @@ -34,16 +34,15 @@ #if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_KMSDRM) -int KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void KMSDRM_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this, +extern bool KMSDRM_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void KMSDRM_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* KMSDRM_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool KMSDRM_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); -void KMSDRM_Vulkan_DestroySurface(SDL_VideoDevice *_this, +extern void KMSDRM_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); diff --git a/src/video/n3ds/SDL_n3dsframebuffer.c b/src/video/n3ds/SDL_n3dsframebuffer.c index b04cbb507c..f6a319dcf6 100644 --- a/src/video/n3ds/SDL_n3dsframebuffer.c +++ b/src/video/n3ds/SDL_n3dsframebuffer.c @@ -42,7 +42,7 @@ static int GetSourceOffset(int x, int y, int source_width); static void FlushN3DSBuffer(const void *buffer, u32 bufsize, gfxScreen_t screen); -int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_Surface *framebuffer; const SDL_DisplayMode *mode; @@ -55,17 +55,17 @@ int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, framebuffer = SDL_CreateSurface(w, h, mode->format); if (!framebuffer) { - return -1; + return false; } SDL_SetSurfaceProperty(SDL_GetWindowProperties(window), N3DS_SURFACE, framebuffer); *format = mode->format; *pixels = framebuffer->pixels; *pitch = framebuffer->pitch; - return 0; + return true; } -int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { SDL_WindowData *drv_data = window->internal; SDL_Surface *surface; @@ -93,7 +93,7 @@ int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, surface->pixels, (Dimensions){ surface->w, surface->h }); FlushN3DSBuffer(framebuffer, bufsize, drv_data->screen); - return 0; + return true; } static void CopyFramebuffertoN3DS_16(u16 *dest, const Dimensions dest_dim, const u16 *source, const Dimensions source_dim) diff --git a/src/video/n3ds/SDL_n3dsframebuffer_c.h b/src/video/n3ds/SDL_n3dsframebuffer_c.h index b2110e0fd6..ed77b7576d 100644 --- a/src/video/n3ds/SDL_n3dsframebuffer_c.h +++ b/src/video/n3ds/SDL_n3dsframebuffer_c.h @@ -24,8 +24,8 @@ #include "SDL_internal.h" -int SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -int SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); -void SDL_N3DS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); +extern bool SDL_N3DS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool SDL_N3DS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern void SDL_N3DS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_n3dsframebuffer_c_h_ diff --git a/src/video/n3ds/SDL_n3dsswkb.c b/src/video/n3ds/SDL_n3dsswkb.c index b4814640bb..5aa01300a5 100644 --- a/src/video/n3ds/SDL_n3dsswkb.c +++ b/src/video/n3ds/SDL_n3dsswkb.c @@ -50,7 +50,7 @@ bool N3DS_HasScreenKeyboardSupport(SDL_VideoDevice *_this) return true; } -int N3DS_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) +bool N3DS_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { char buffer[BUFFER_SIZE]; SwkbdButton button_pressed; @@ -58,12 +58,12 @@ int N3DS_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti if (button_pressed == SWKBD_BUTTON_CONFIRM) { SDL_SendKeyboardText(buffer); } - return 0; + return true; } -int N3DS_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) +bool N3DS_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) { - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_N3DS diff --git a/src/video/n3ds/SDL_n3dsswkb.h b/src/video/n3ds/SDL_n3dsswkb.h index ba9560d207..c4e039183e 100644 --- a/src/video/n3ds/SDL_n3dsswkb.h +++ b/src/video/n3ds/SDL_n3dsswkb.h @@ -30,7 +30,7 @@ void N3DS_SwkbQuit(); bool N3DS_HasScreenKeyboardSupport(SDL_VideoDevice *_this); -int N3DS_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -int N3DS_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); +bool N3DS_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +bool N3DS_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_n3dskeyboard_h_ diff --git a/src/video/n3ds/SDL_n3dsvideo.c b/src/video/n3ds/SDL_n3dsvideo.c index 8c1c7ea962..bdf19367c3 100644 --- a/src/video/n3ds/SDL_n3dsvideo.c +++ b/src/video/n3ds/SDL_n3dsvideo.c @@ -31,14 +31,14 @@ #define N3DSVID_DRIVER_NAME "n3ds" -static int AddN3DSDisplay(gfxScreen_t screen); +static bool AddN3DSDisplay(gfxScreen_t screen); -static int N3DS_VideoInit(SDL_VideoDevice *_this); +static bool N3DS_VideoInit(SDL_VideoDevice *_this); static void N3DS_VideoQuit(SDL_VideoDevice *_this); -static int N3DS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -static int N3DS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); -static int N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); -static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +static bool N3DS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +static bool N3DS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +static bool N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +static bool N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); static void N3DS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); struct SDL_DisplayData @@ -120,7 +120,7 @@ static SDL_VideoDevice *N3DS_CreateDevice(void) VideoBootStrap N3DS_bootstrap = { N3DSVID_DRIVER_NAME, "N3DS Video Driver", N3DS_CreateDevice, NULL /* no ShowMessageBox implementation */ }; -static int N3DS_VideoInit(SDL_VideoDevice *_this) +static bool N3DS_VideoInit(SDL_VideoDevice *_this) { SDL_VideoData *internal = (SDL_VideoData *)_this->internal; @@ -133,17 +133,17 @@ static int N3DS_VideoInit(SDL_VideoDevice *_this) N3DS_InitTouch(); N3DS_SwkbInit(); - return 0; + return true; } -static int AddN3DSDisplay(gfxScreen_t screen) +static bool AddN3DSDisplay(gfxScreen_t screen) { SDL_DisplayMode mode; SDL_DisplayModeData *modedata; SDL_VideoDisplay display; SDL_DisplayData *display_driver_data = SDL_calloc(1, sizeof(SDL_DisplayData)); if (!display_driver_data) { - return -1; + return false; } SDL_zero(mode); @@ -153,7 +153,7 @@ static int AddN3DSDisplay(gfxScreen_t screen) modedata = SDL_malloc(sizeof(SDL_DisplayModeData)); if (!modedata) { - return -1; + return false; } mode.w = (screen == GFX_TOP) ? GSP_SCREEN_HEIGHT_TOP : GSP_SCREEN_HEIGHT_BOTTOM; @@ -167,7 +167,10 @@ static int AddN3DSDisplay(gfxScreen_t screen) display.desktop_mode = mode; display.internal = display_driver_data; - return SDL_AddVideoDisplay(&display, false); + if (SDL_AddVideoDisplay(&display, false) == 0) { + return false; + } + return true; } static void N3DS_VideoQuit(SDL_VideoDevice *_this) @@ -179,7 +182,7 @@ static void N3DS_VideoQuit(SDL_VideoDevice *_this) gfxExit(); } -static int N3DS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +static bool N3DS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { SDL_DisplayData *displaydata = display->internal; SDL_DisplayModeData *modedata; @@ -204,45 +207,45 @@ static int N3DS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *displa } } - return 0; + return true; } -static int N3DS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +static bool N3DS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { SDL_DisplayData *displaydata = display->internal; SDL_DisplayModeData *modedata = mode->internal; gfxSetScreenFormat(displaydata->screen, modedata->fmt); - return 0; + return true; } -static int N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +static bool N3DS_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { SDL_DisplayData *driver_data = display->internal; if (!driver_data) { - return -1; + return false; } rect->x = 0; rect->y = (driver_data->screen == GFX_TOP) ? 0 : GSP_SCREEN_WIDTH; rect->w = display->current_mode->w; rect->h = display->current_mode->h; - return 0; + return true; } -static int N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +static bool N3DS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_DisplayData *display_data; SDL_WindowData *window_data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!window_data) { - return -1; + return false; } display_data = SDL_GetDisplayDriverDataForWindow(window); window_data->screen = display_data->screen; window->internal = window_data; SDL_SetKeyboardFocus(window); - return 0; + return true; } static void N3DS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/ngage/SDL_ngageevents.cpp b/src/video/ngage/SDL_ngageevents.cpp index 7b0ab82311..c92553adb0 100644 --- a/src/video/ngage/SDL_ngageevents.cpp +++ b/src/video/ngage/SDL_ngageevents.cpp @@ -40,7 +40,7 @@ extern "C" { #include "SDL_ngagevideo.h" #include "SDL_ngageevents_c.h" -int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent); +static void HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent); void NGAGE_PumpEvents(SDL_VideoDevice *_this) { @@ -147,10 +147,9 @@ static SDL_Scancode ConvertScancode(SDL_VideoDevice *_this, int key) return scancode; } -int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent) +static void HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent) { SDL_VideoData *data = _this->internal; - int posted = 0; switch (aWsEvent.Type()) { case EEventKeyDown: // Key events @@ -188,7 +187,6 @@ int HandleWsEvent(SDL_VideoDevice *_this, const TWsEvent &aWsEvent) default: break; } - return posted; } #endif // SDL_VIDEO_DRIVER_NGAGE diff --git a/src/video/ngage/SDL_ngageframebuffer.cpp b/src/video/ngage/SDL_ngageframebuffer.cpp index 5fe1dcab5a..b854c73add 100644 --- a/src/video/ngage/SDL_ngageframebuffer.cpp +++ b/src/video/ngage/SDL_ngageframebuffer.cpp @@ -38,13 +38,13 @@ */ static TUint32 NGAGE_HWPalette_256_to_Screen[256]; -int GetBpp(TDisplayMode displaymode); +bool GetBpp(TDisplayMode displaymode); void DirectUpdate(SDL_VideoDevice *_this, int numrects, SDL_Rect *rects); void DrawBackground(SDL_VideoDevice *_this); void DirectDraw(SDL_VideoDevice *_this, int numrects, SDL_Rect *rects, TUint16 *screenBuffer); void RedrawWindowL(SDL_VideoDevice *_this); -int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_VideoData *phdata = _this->internal; SDL_Surface *surface; @@ -58,7 +58,7 @@ int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window SDL_GetWindowSizeInPixels(window, &w, &h); surface = SDL_CreateSurface(w, h, surface_format); if (!surface) { - return -1; + return false; } // Save the info and return! @@ -140,13 +140,13 @@ int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window SDL_Log("SDL:DrawBackground"); DrawBackground(_this); // Clear screen - return 0; + return true; } -int SDL_NGAGE_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool SDL_NGAGE_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { DirectUpdate(_this, numrects, (SDL_Rect *)rects); - return 0; + return true; } void SDL_NGAGE_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) @@ -175,7 +175,7 @@ EXPORT_C void NGAGE_Runtime::GetScreenInfo(TScreenInfoV01 &screenInfo2) // Internal /*****************************************************************************/ -int GetBpp(TDisplayMode displaymode) +bool GetBpp(TDisplayMode displaymode) { return TDisplayModeUtils::NumDisplayModeBitsPerPixel(displaymode); } diff --git a/src/video/ngage/SDL_ngageframebuffer_c.h b/src/video/ngage/SDL_ngageframebuffer_c.h index ef80701e32..578cc5681c 100644 --- a/src/video/ngage/SDL_ngageframebuffer_c.h +++ b/src/video/ngage/SDL_ngageframebuffer_c.h @@ -21,8 +21,8 @@ #include "SDL_internal.h" -extern int SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -extern int SDL_NGAGE_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern bool SDL_NGAGE_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool SDL_NGAGE_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); extern void SDL_NGAGE_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); /****************************************************************************/ diff --git a/src/video/ngage/SDL_ngagevideo.cpp b/src/video/ngage/SDL_ngagevideo.cpp index 62e6961e86..1694a9d787 100644 --- a/src/video/ngage/SDL_ngagevideo.cpp +++ b/src/video/ngage/SDL_ngagevideo.cpp @@ -47,7 +47,7 @@ extern "C" { #define NGAGEVID_DRIVER_NAME "ngage" // Initialization/Query functions -static int NGAGE_VideoInit(SDL_VideoDevice *_this); +static bool NGAGE_VideoInit(SDL_VideoDevice *_this); static void NGAGE_VideoQuit(SDL_VideoDevice *_this); // NGAGE driver bootstrap functions @@ -140,7 +140,7 @@ VideoBootStrap NGAGE_bootstrap = { NULL // no ShowMessageBox implementation }; -int NGAGE_VideoInit(SDL_VideoDevice *_this) +static bool NGAGE_VideoInit(SDL_VideoDevice *_this) { SDL_DisplayMode mode; @@ -150,14 +150,14 @@ int NGAGE_VideoInit(SDL_VideoDevice *_this) mode.w = 176; mode.h = 208; if (SDL_AddBasicVideoDisplay(&mode) == 0) { - return -1; + return false; } // We're done! - return 0; + return true; } -void NGAGE_VideoQuit(SDL_VideoDevice *_this) +static void NGAGE_VideoQuit(SDL_VideoDevice *_this) { } diff --git a/src/video/ngage/SDL_ngagewindow.cpp b/src/video/ngage/SDL_ngagewindow.cpp index f136142556..f916e1fae7 100644 --- a/src/video/ngage/SDL_ngagewindow.cpp +++ b/src/video/ngage/SDL_ngagewindow.cpp @@ -32,12 +32,12 @@ const TUint32 WindowClientHandle = 9210; void DisableKeyBlocking(SDL_VideoDevice *_this); void ConstructWindowL(SDL_VideoDevice *_this); -int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { NGAGE_Window *ngage_window = (NGAGE_Window *)SDL_calloc(1, sizeof(NGAGE_Window)); if (!ngage_window) { - return -1; + return false; } window->internal = ngage_window; @@ -54,7 +54,7 @@ int NGAGE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie ConstructWindowL(_this); - return 0; + return true; } void NGAGE_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/offscreen/SDL_offscreenframebuffer.c b/src/video/offscreen/SDL_offscreenframebuffer.c index 0de27480dd..475f1dd4b4 100644 --- a/src/video/offscreen/SDL_offscreenframebuffer.c +++ b/src/video/offscreen/SDL_offscreenframebuffer.c @@ -29,7 +29,7 @@ #define OFFSCREEN_SURFACE "SDL.internal.window.surface" -int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_Surface *surface; const SDL_PixelFormat surface_format = SDL_PIXELFORMAT_XRGB8888; @@ -39,7 +39,7 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi SDL_GetWindowSizeInPixels(window, &w, &h); surface = SDL_CreateSurface(w, h, surface_format); if (!surface) { - return -1; + return false; } // Save the info and return! @@ -48,10 +48,10 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi *pixels = surface->pixels; *pitch = surface->pitch; - return 0; + return true; } -int SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { static int frame_number; SDL_Surface *surface; @@ -68,7 +68,7 @@ int SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *wi SDL_GetWindowID(window), ++frame_number); SDL_SaveBMP(surface, file); } - return 0; + return true; } void SDL_OFFSCREEN_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/offscreen/SDL_offscreenframebuffer_c.h b/src/video/offscreen/SDL_offscreenframebuffer_c.h index a45f9afe46..2afe5b7a18 100644 --- a/src/video/offscreen/SDL_offscreenframebuffer_c.h +++ b/src/video/offscreen/SDL_offscreenframebuffer_c.h @@ -20,6 +20,6 @@ */ #include "SDL_internal.h" -extern int SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -extern int SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern bool SDL_OFFSCREEN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool SDL_OFFSCREEN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); extern void SDL_OFFSCREEN_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/offscreen/SDL_offscreenopengles.c b/src/video/offscreen/SDL_offscreenopengles.c index cd05b5a5b5..c06f0b1490 100644 --- a/src/video/offscreen/SDL_offscreenopengles.c +++ b/src/video/offscreen/SDL_offscreenopengles.c @@ -28,30 +28,28 @@ // EGL implementation of SDL OpenGL support -int OFFSCREEN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool OFFSCREEN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { - int ret = SDL_EGL_LoadLibraryOnly(_this, path); - if (ret != 0) { - return ret; + if (!SDL_EGL_LoadLibraryOnly(_this, path)) { + return false; } /* driver_loaded gets incremented by SDL_GL_LoadLibrary when we return, but SDL_EGL_InitializeOffscreen checks that we're loaded before then, so temporarily bump it since we know that LoadLibraryOnly succeeded. */ - + bool result; _this->gl_config.driver_loaded++; - ret = SDL_EGL_InitializeOffscreen(_this, 0); + result = SDL_EGL_InitializeOffscreen(_this, 0); _this->gl_config.driver_loaded--; - if (ret != 0) { - return ret; + if (!result) { + return false; } - ret = SDL_EGL_ChooseConfig(_this); - if (ret != 0) { - return ret; + if (!SDL_EGL_ChooseConfig(_this)) { + return false; } - return 0; + return true; } SDL_GLContext OFFSCREEN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) @@ -64,7 +62,7 @@ SDL_GLContext OFFSCREEN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *w return context; } -int OFFSCREEN_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool OFFSCREEN_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { if (window) { EGLSurface egl_surface = window->internal->egl_surface; @@ -74,7 +72,7 @@ int OFFSCREEN_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_G } } -int OFFSCREEN_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool OFFSCREEN_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *offscreen_wind = window->internal; diff --git a/src/video/offscreen/SDL_offscreenopengles.h b/src/video/offscreen/SDL_offscreenopengles.h index e343519087..054135960e 100644 --- a/src/video/offscreen/SDL_offscreenopengles.h +++ b/src/video/offscreen/SDL_offscreenopengles.h @@ -32,12 +32,12 @@ #define OFFSCREEN_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define OFFSCREEN_GLES_GetSwapInterval SDL_EGL_GetSwapInterval #define OFFSCREEN_GLES_SetSwapInterval SDL_EGL_SetSwapInterval -#define OFFSCREEN_GLES_DeleteContext SDL_EGL_DeleteContext +#define OFFSCREEN_GLES_DestroyContext SDL_EGL_DestroyContext -extern int OFFSCREEN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool OFFSCREEN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_GLContext OFFSCREEN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int OFFSCREEN_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int OFFSCREEN_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool OFFSCREEN_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool OFFSCREEN_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_VIDEO_DRIVER_OFFSCREEN && SDL_VIDEO_OPENGL_EGL diff --git a/src/video/offscreen/SDL_offscreenvideo.c b/src/video/offscreen/SDL_offscreenvideo.c index 5bb36f6f41..7dddb2627b 100644 --- a/src/video/offscreen/SDL_offscreenvideo.c +++ b/src/video/offscreen/SDL_offscreenvideo.c @@ -40,8 +40,8 @@ #define OFFSCREENVID_DRIVER_NAME "offscreen" // Initialization/Query functions -static int OFFSCREEN_VideoInit(SDL_VideoDevice *_this); -static int OFFSCREEN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +static bool OFFSCREEN_VideoInit(SDL_VideoDevice *_this); +static bool OFFSCREEN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); static void OFFSCREEN_VideoQuit(SDL_VideoDevice *_this); // OFFSCREEN driver bootstrap functions @@ -91,7 +91,7 @@ static SDL_VideoDevice *OFFSCREEN_CreateDevice(void) device->GL_SwapWindow = OFFSCREEN_GLES_SwapWindow; device->GL_MakeCurrent = OFFSCREEN_GLES_MakeCurrent; device->GL_CreateContext = OFFSCREEN_GLES_CreateContext; - device->GL_DeleteContext = OFFSCREEN_GLES_DeleteContext; + device->GL_DestroyContext = OFFSCREEN_GLES_DestroyContext; device->GL_LoadLibrary = OFFSCREEN_GLES_LoadLibrary; device->GL_UnloadLibrary = OFFSCREEN_GLES_UnloadLibrary; device->GL_GetProcAddress = OFFSCREEN_GLES_GetProcAddress; @@ -121,7 +121,7 @@ VideoBootStrap OFFSCREEN_bootstrap = { NULL // no ShowMessageBox implementation }; -int OFFSCREEN_VideoInit(SDL_VideoDevice *_this) +static bool OFFSCREEN_VideoInit(SDL_VideoDevice *_this) { SDL_DisplayMode mode; @@ -131,16 +131,16 @@ int OFFSCREEN_VideoInit(SDL_VideoDevice *_this) mode.w = 1024; mode.h = 768; if (SDL_AddBasicVideoDisplay(&mode) == 0) { - return -1; + return false; } // We're done! - return 0; + return true; } -static int OFFSCREEN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +static bool OFFSCREEN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { - return 0; + return true; } void OFFSCREEN_VideoQuit(SDL_VideoDevice *_this) diff --git a/src/video/offscreen/SDL_offscreenvulkan.c b/src/video/offscreen/SDL_offscreenvulkan.c index 4222647549..3d861f0c3e 100644 --- a/src/video/offscreen/SDL_offscreenvulkan.c +++ b/src/video/offscreen/SDL_offscreenvulkan.c @@ -56,7 +56,7 @@ static const char *s_defaultPaths[] = { #define HEADLESS_SURFACE_EXTENSION_REQUIRED_TO_LOAD 0 -int OFFSCREEN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool OFFSCREEN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 extensionCount = 0; @@ -153,12 +153,12 @@ int OFFSCREEN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) SDL_Log("Installed Vulkan doesn't implement the " VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME " extension"); #endif } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void OFFSCREEN_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -214,7 +214,7 @@ char const *const *OFFSCREEN_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this return returnExtensions; } -int OFFSCREEN_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool OFFSCREEN_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, @@ -245,7 +245,7 @@ int OFFSCREEN_Vulkan_CreateSurface(SDL_VideoDevice *_this, if (result != VK_SUCCESS) { return SDL_SetError("vkCreateHeadlessSurfaceEXT failed: %s", SDL_Vulkan_GetResultString(result)); } - return 0; + return true; } void OFFSCREEN_Vulkan_DestroySurface(SDL_VideoDevice *_this, diff --git a/src/video/offscreen/SDL_offscreenvulkan.h b/src/video/offscreen/SDL_offscreenvulkan.h index 6f04ebf9db..45f9afed23 100644 --- a/src/video/offscreen/SDL_offscreenvulkan.h +++ b/src/video/offscreen/SDL_offscreenvulkan.h @@ -27,10 +27,10 @@ #include "../SDL_sysvideo.h" -extern int OFFSCREEN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool OFFSCREEN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern void OFFSCREEN_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); extern char const *const *OFFSCREEN_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); -extern int OFFSCREEN_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); +extern bool OFFSCREEN_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); extern void OFFSCREEN_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); #endif // SDL_VIDEO_DRIVER_OFFSCREEN && SDL_VIDEO_VULKAN diff --git a/src/video/offscreen/SDL_offscreenwindow.c b/src/video/offscreen/SDL_offscreenwindow.c index c8086e57f6..c76028e45d 100644 --- a/src/video/offscreen/SDL_offscreenwindow.c +++ b/src/video/offscreen/SDL_offscreenwindow.c @@ -28,12 +28,12 @@ #include "SDL_offscreenwindow.h" -int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *offscreen_window = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!offscreen_window) { - return -1; + return false; } window->internal = offscreen_window; @@ -66,7 +66,7 @@ int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Prope } #endif // SDL_VIDEO_OPENGL_EGL - return 0; + return true; } void OFFSCREEN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/offscreen/SDL_offscreenwindow.h b/src/video/offscreen/SDL_offscreenwindow.h index c273f5ccbf..eb87f9a370 100644 --- a/src/video/offscreen/SDL_offscreenwindow.h +++ b/src/video/offscreen/SDL_offscreenwindow.h @@ -33,7 +33,7 @@ struct SDL_WindowData #endif }; -extern int OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool OFFSCREEN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern void OFFSCREEN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void OFFSCREEN_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/ps2/SDL_ps2video.c b/src/video/ps2/SDL_ps2video.c index 7bcecf4579..027ba28330 100644 --- a/src/video/ps2/SDL_ps2video.c +++ b/src/video/ps2/SDL_ps2video.c @@ -45,9 +45,9 @@ // PS2 driver bootstrap functions -static int PS2_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +static bool PS2_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { - return 0; + return true; } static void PS2_DeleteDevice(SDL_VideoDevice *device) @@ -55,15 +55,15 @@ static void PS2_DeleteDevice(SDL_VideoDevice *device) SDL_free(device); } -static int PS2_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +static bool PS2_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_SetKeyboardFocus(window); // Window has been successfully created - return 0; + return true; } -static int PS2_VideoInit(SDL_VideoDevice *_this) +static bool PS2_VideoInit(SDL_VideoDevice *_this) { SDL_DisplayMode mode; @@ -77,7 +77,7 @@ static int PS2_VideoInit(SDL_VideoDevice *_this) SDL_AddBasicVideoDisplay(&mode); - return 1; + return true; } static void PS2_VideoQuit(SDL_VideoDevice *_this) diff --git a/src/video/psp/SDL_pspevents.c b/src/video/psp/SDL_pspevents.c index 6a72621297..8aea1a7dff 100644 --- a/src/video/psp/SDL_pspevents.c +++ b/src/video/psp/SDL_pspevents.c @@ -231,7 +231,7 @@ void PSP_InitOSKeymap(SDL_VideoDevice *_this) #endif } -int PSP_EventInit(SDL_VideoDevice *_this) +bool PSP_EventInit(SDL_VideoDevice *_this) { #ifdef PSPIRKEYB int outputmode = PSP_IRKBD_OUTPUT_MODE_SCANCODE; @@ -251,7 +251,7 @@ int PSP_EventInit(SDL_VideoDevice *_this) if ((thread = SDL_CreateThreadWithStackSize(EventUpdate, "PSPInputThread", 4096, NULL)) == NULL) { return SDL_SetError("Can't create input thread"); } - return 0; + return true; } void PSP_EventQuit(SDL_VideoDevice *_this) diff --git a/src/video/psp/SDL_pspevents_c.h b/src/video/psp/SDL_pspevents_c.h index c2b10baebd..e56b4cb3e3 100644 --- a/src/video/psp/SDL_pspevents_c.h +++ b/src/video/psp/SDL_pspevents_c.h @@ -23,7 +23,7 @@ extern void PSP_InitOSKeymap(SDL_VideoDevice *_this); extern void PSP_PumpEvents(SDL_VideoDevice *_this); -extern int PSP_EventInit(SDL_VideoDevice *_this); +extern bool PSP_EventInit(SDL_VideoDevice *_this); extern void PSP_EventQuit(SDL_VideoDevice *_this); // end of SDL_pspevents_c.h ... diff --git a/src/video/psp/SDL_pspgl.c b/src/video/psp/SDL_pspgl.c index 482bce6693..cba2e49d41 100644 --- a/src/video/psp/SDL_pspgl.c +++ b/src/video/psp/SDL_pspgl.c @@ -39,13 +39,13 @@ err = eglGetError(); \ if (err != EGL_SUCCESS) { \ SDL_SetError("EGL error %d", err); \ - return 0; \ + return NULL; \ } \ } while (0) -int PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) { - return 0; + return true; } /* pspgl doesn't provide this call, so stub it out since SDL requires it. @@ -112,7 +112,7 @@ SDL_GLContext PSP_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) if (num_configs == 0) { SDL_SetError("No valid EGL configs for requested mode"); - return 0; + return NULL; } EGLCHK(eglGetConfigAttrib(display, config, EGL_WIDTH, &width)); @@ -129,43 +129,43 @@ SDL_GLContext PSP_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) return context; } -int PSP_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool PSP_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface, _this->gl_data->surface, _this->gl_data->context)) { return SDL_SetError("Unable to make EGL context current"); } - return 0; + return true; } -int PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) { EGLBoolean status; status = eglSwapInterval(_this->gl_data->display, interval); if (status == EGL_TRUE) { // Return success to upper level _this->gl_data->swapinterval = interval; - return 0; + return true; } // Failed to set swap interval return SDL_SetError("Unable to set the EGL swap interval"); } -int PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { *interval = _this->gl_data->swapinterval; - return 0; + return true; } -int PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) { return SDL_SetError("eglSwapBuffers() failed"); } - return 0; + return true; } -int PSP_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool PSP_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { SDL_VideoData *phdata = _this->internal; EGLBoolean status; @@ -184,7 +184,7 @@ int PSP_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) } } } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_PSP diff --git a/src/video/psp/SDL_pspgl_c.h b/src/video/psp/SDL_pspgl_c.h index 6cf6f0966d..44b00b412f 100644 --- a/src/video/psp/SDL_pspgl_c.h +++ b/src/video/psp/SDL_pspgl_c.h @@ -36,15 +36,15 @@ typedef struct SDL_GLDriverData } SDL_GLDriverData; extern SDL_FunctionPointer PSP_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -extern int PSP_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool PSP_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); extern void PSP_GL_SwapBuffers(SDL_VideoDevice *_this); -extern int PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_GLContext PSP_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern void PSP_GL_UnloadLibrary(SDL_VideoDevice *_this); -extern int PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); #endif // SDL_pspgl_c_h_ diff --git a/src/video/psp/SDL_pspvideo.c b/src/video/psp/SDL_pspvideo.c index 7004b92743..9448da7b19 100644 --- a/src/video/psp/SDL_pspvideo.c +++ b/src/video/psp/SDL_pspvideo.c @@ -110,7 +110,7 @@ static SDL_VideoDevice *PSP_Create(void) device->GL_SetSwapInterval = PSP_GL_SetSwapInterval; device->GL_GetSwapInterval = PSP_GL_GetSwapInterval; device->GL_SwapWindow = PSP_GL_SwapWindow; - device->GL_DeleteContext = PSP_GL_DeleteContext; + device->GL_DestroyContext = PSP_GL_DestroyContext; device->HasScreenKeyboardSupport = PSP_HasScreenKeyboardSupport; device->ShowScreenKeyboard = PSP_ShowScreenKeyboard; device->HideScreenKeyboard = PSP_HideScreenKeyboard; @@ -181,7 +181,7 @@ static void term_temporal_gu(void *guBuffer) sceDisplayWaitVblankStart(); } -int PSP_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool PSP_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { unsigned char list[64] __attribute__((aligned(64))); pspUtilityMsgDialogParams dialog; @@ -243,7 +243,7 @@ int PSP_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) sceGuSwapBuffers(); } while (status != PSP_UTILITY_DIALOG_NONE); - + // cleanup if (guBuffer) { @@ -258,7 +258,7 @@ int PSP_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) else *buttonID = messageboxdata->buttons[0].buttonID; - return 0; + return true; } VideoBootStrap PSP_bootstrap = { @@ -271,12 +271,12 @@ VideoBootStrap PSP_bootstrap = { /*****************************************************************************/ // SDL Video and Display initialization/handling functions /*****************************************************************************/ -int PSP_VideoInit(SDL_VideoDevice *_this) +bool PSP_VideoInit(SDL_VideoDevice *_this) { SDL_DisplayMode mode; - if (PSP_EventInit(_this) == -1) { - return -1; // error string would already be set + if (!PSP_EventInit(_this)) { + return false; // error string would already be set } SDL_zero(mode); @@ -288,9 +288,9 @@ int PSP_VideoInit(SDL_VideoDevice *_this) mode.format = SDL_PIXELFORMAT_ABGR8888; if (SDL_AddBasicVideoDisplay(&mode) == 0) { - return -1; + return false; } - return 0; + return true; } void PSP_VideoQuit(SDL_VideoDevice *_this) @@ -298,7 +298,7 @@ void PSP_VideoQuit(SDL_VideoDevice *_this) PSP_EventQuit(_this); } -int PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +bool PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { SDL_DisplayMode mode; @@ -314,12 +314,12 @@ int PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) // 16 bpp secondary mode mode.format = SDL_PIXELFORMAT_BGR565; SDL_AddFullscreenDisplayMode(display, &mode); - return 0; + return true; } -int PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +bool PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { - return 0; + return true; } #define EGLCHK(stmt) \ @@ -330,18 +330,18 @@ int PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Di err = eglGetError(); \ if (err != EGL_SUCCESS) { \ SDL_SetError("EGL error %d", err); \ - return 0; \ + return true; \ } \ } while (0) -int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *wdata; // Allocate window internal data wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return -1; + return false; } // Setup driver data for this window @@ -350,13 +350,13 @@ int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI SDL_SetKeyboardFocus(window); // Window has been successfully created - return 0; + return true; } void PSP_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } -int PSP_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool PSP_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { return SDL_Unsupported(); } diff --git a/src/video/psp/SDL_pspvideo.h b/src/video/psp/SDL_pspvideo.h index 314ffe3856..7328dd8083 100644 --- a/src/video/psp/SDL_pspvideo.h +++ b/src/video/psp/SDL_pspvideo.h @@ -45,37 +45,37 @@ struct SDL_WindowData /****************************************************************************/ // Display and window functions -int PSP_VideoInit(SDL_VideoDevice *_this); -void PSP_VideoQuit(SDL_VideoDevice *_this); -int PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -int PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); -int PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); -void PSP_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -int PSP_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); -void PSP_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool PSP_VideoInit(SDL_VideoDevice *_this); +extern void PSP_VideoQuit(SDL_VideoDevice *_this); +extern bool PSP_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool PSP_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool PSP_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern void PSP_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); +extern bool PSP_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void PSP_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); // OpenGL/OpenGL ES functions -int PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); -SDL_FunctionPointer PSP_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -void PSP_GL_UnloadLibrary(SDL_VideoDevice *_this); -SDL_GLContext PSP_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -int PSP_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -int PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); -int PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); -int PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -int PSP_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool PSP_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern SDL_FunctionPointer PSP_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); +extern void PSP_GL_UnloadLibrary(SDL_VideoDevice *_this); +extern SDL_GLContext PSP_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); +extern bool PSP_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool PSP_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool PSP_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool PSP_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool PSP_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); // PSP on screen keyboard -bool PSP_HasScreenKeyboardSupport(SDL_VideoDevice *_this); -void PSP_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -void PSP_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window); -bool PSP_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window); +extern bool PSP_HasScreenKeyboardSupport(SDL_VideoDevice *_this); +extern void PSP_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +extern void PSP_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window); +extern bool PSP_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_pspvideo_h_ diff --git a/src/video/qnx/SDL_qnx.h b/src/video/qnx/SDL_qnx.h index 368f84000f..f8a50cfa73 100644 --- a/src/video/qnx/SDL_qnx.h +++ b/src/video/qnx/SDL_qnx.h @@ -35,13 +35,13 @@ typedef struct extern void handleKeyboardEvent(screen_event_t event); -extern int glGetConfig(EGLConfig *pconf, int *pformat); -extern int glLoadLibrary(SDL_VideoDevice *_this, const char *name); +extern bool glGetConfig(EGLConfig *pconf, int *pformat); +extern bool glLoadLibrary(SDL_VideoDevice *_this, const char *name); extern SDL_FunctionPointer glGetProcAddress(SDL_VideoDevice *_this, const char *proc); extern SDL_GLContext glCreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int glSetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int glSwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int glMakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context); +extern bool glSetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool glSwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool glMakeCurrent(SDL_VideoDevice *_this, SDL_Window * window, SDL_GLContext context); extern void glDeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); extern void glUnloadLibrary(SDL_VideoDevice *_this); diff --git a/src/video/qnx/SDL_qnxgl.c b/src/video/qnx/SDL_qnxgl.c index 9d27d45559..639e556900 100644 --- a/src/video/qnx/SDL_qnxgl.c +++ b/src/video/qnx/SDL_qnxgl.c @@ -61,9 +61,9 @@ static int chooseFormat(EGLConfig egl_conf) * Enumerates the supported EGL configurations and chooses a suitable one. * @param[out] pconf The chosen configuration * @param[out] pformat The chosen pixel format - * @return 0 if successful, -1 on error + * @return true if successful, -1 on error */ -int glGetConfig(EGLConfig *pconf, int *pformat) +bool glGetConfig(EGLConfig *pconf, int *pformat) { EGLConfig egl_conf = (EGLConfig)0; EGLConfig *egl_configs; @@ -75,17 +75,17 @@ int glGetConfig(EGLConfig *pconf, int *pformat) // Determine the numbfer of configurations. rc = eglGetConfigs(egl_disp, NULL, 0, &egl_num_configs); if (rc != EGL_TRUE) { - return -1; + return false; } if (egl_num_configs == 0) { - return -1; + return false; } // Allocate enough memory for all configurations. egl_configs = SDL_malloc(egl_num_configs * sizeof(*egl_configs)); if (!egl_configs) { - return -1; + return false; } // Get the list of configurations. @@ -93,7 +93,7 @@ int glGetConfig(EGLConfig *pconf, int *pformat) &egl_num_configs); if (rc != EGL_TRUE) { SDL_free(egl_configs); - return -1; + return false; } // Find a good configuration. @@ -121,7 +121,7 @@ int glGetConfig(EGLConfig *pconf, int *pformat) *pconf = egl_conf; *pformat = chooseFormat(egl_conf); - return 0; + return true; } /** @@ -130,20 +130,20 @@ int glGetConfig(EGLConfig *pconf, int *pformat) * @param name unused * @return 0 if successful, -1 on error */ -int glLoadLibrary(SDL_VideoDevice *_this, const char *name) +bool glLoadLibrary(SDL_VideoDevice *_this, const char *name) { EGLNativeDisplayType disp_id = EGL_DEFAULT_DISPLAY; egl_disp = eglGetDisplay(disp_id); if (egl_disp == EGL_NO_DISPLAY) { - return -1; + return false; } if (eglInitialize(egl_disp, NULL, NULL) == EGL_FALSE) { - return -1; + return false; } - return 0; + return true; } /** @@ -210,13 +210,13 @@ SDL_GLContext glCreateContext(SDL_VideoDevice *_this, SDL_Window *window) * @param interval New interval value * @return 0 if successful, -1 on error */ -int glSetSwapInterval(SDL_VideoDevice *_this, int interval) +bool glSetSwapInterval(SDL_VideoDevice *_this, int interval) { if (eglSwapInterval(egl_disp, interval) != EGL_TRUE) { - return -1; + return false; } - return 0; + return true; } /** @@ -225,7 +225,7 @@ int glSetSwapInterval(SDL_VideoDevice *_this, int interval) * @param window Window to swap buffers for * @return 0 if successful, -1 on error */ -int glSwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool glSwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { // !!! FIXME: should we migrate this all over to use SDL_egl.c? window_impl_t *impl = (window_impl_t *)window->internal; @@ -239,7 +239,7 @@ int glSwapWindow(SDL_VideoDevice *_this, SDL_Window *window) * @param context The context to activate * @return 0 if successful, -1 on error */ -int glMakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool glMakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { window_impl_t *impl; EGLSurface surface = NULL; @@ -250,10 +250,10 @@ int glMakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext cont } if (eglMakeCurrent(egl_disp, surface, surface, context) != EGL_TRUE) { - return -1; + return false; } - return 0; + return true; } /** @@ -261,9 +261,10 @@ int glMakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext cont * @param SDL_VideoDevice *_this * @param context The context to destroy */ -void glDeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool glDeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) { eglDestroyContext(egl_disp, context); + return true; } /** diff --git a/src/video/qnx/SDL_qnxvideo.c b/src/video/qnx/SDL_qnxvideo.c index 5831a96202..6e7d5dc80d 100644 --- a/src/video/qnx/SDL_qnxvideo.c +++ b/src/video/qnx/SDL_qnxvideo.c @@ -34,29 +34,29 @@ static screen_event_t event; * @param SDL_VideoDevice *_this * @return 0 if successful, -1 on error */ -static int videoInit(SDL_VideoDevice *_this) +static bool videoInit(SDL_VideoDevice *_this) { SDL_VideoDisplay display; if (screen_create_context(&context, 0) < 0) { - return -1; + return false; } if (screen_create_event(&event) < 0) { - return -1; + return false; } SDL_zero(display); - if (SDL_AddVideoDisplay(&display, false) < 0) { - return -1; + if (SDL_AddVideoDisplay(&display, false) == 0) { + return false; } // Assume we have a mouse and keyboard SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false); SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false); - return 0; + return true; } static void videoQuit(SDL_VideoDevice *_this) @@ -70,7 +70,7 @@ static void videoQuit(SDL_VideoDevice *_this) * @param window SDL window to initialize * @return 0 if successful, -1 on error */ -static int createWindow(SDL_VideoDevice *_this, SDL_Window *window) +static bool createWindow(SDL_VideoDevice *_this, SDL_Window *window) { window_impl_t *impl; int size[2]; @@ -80,7 +80,7 @@ static int createWindow(SDL_VideoDevice *_this, SDL_Window *window) impl = SDL_calloc(1, sizeof(*impl)); if (!impl) { - return -1; + return false; } // Create a native window. @@ -112,7 +112,7 @@ static int createWindow(SDL_VideoDevice *_this, SDL_Window *window) usage = SCREEN_USAGE_OPENGL_ES2; if (screen_set_window_property_iv(impl->window, SCREEN_PROPERTY_USAGE, &usage) < 0) { - return -1; + return false; } } else { format = SCREEN_FORMAT_RGBX8888; @@ -131,7 +131,7 @@ static int createWindow(SDL_VideoDevice *_this, SDL_Window *window) } window->internal = impl; - return 0; + return true; fail: if (impl->window) { @@ -139,7 +139,7 @@ fail: } SDL_free(impl); - return -1; + return false; } /** @@ -152,7 +152,7 @@ fail: * @param[out] pitch Holds the number of bytes per line * @return 0 if successful, -1 on error */ -static int createWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format, +static bool createWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, SDL_PixelFormat * format, void ** pixels, int *pitch) { window_impl_t *impl = (window_impl_t *)window->internal; @@ -161,22 +161,22 @@ static int createWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, // Get a pointer to the buffer's memory. if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS, (void **)&buffer) < 0) { - return -1; + return false; } if (screen_get_buffer_property_pv(buffer, SCREEN_PROPERTY_POINTER, pixels) < 0) { - return -1; + return false; } // Set format and pitch. if (screen_get_buffer_property_iv(buffer, SCREEN_PROPERTY_STRIDE, pitch) < 0) { - return -1; + return false; } *format = SDL_PIXELFORMAT_XRGB8888; - return 0; + return true; } /** @@ -187,7 +187,7 @@ static int createWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window * window, * @param numrects Rect array length * @return 0 if successful, -1 on error */ -static int updateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, +static bool updateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { window_impl_t *impl = (window_impl_t *)window->internal; @@ -195,12 +195,12 @@ static int updateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, c if (screen_get_window_property_pv(impl->window, SCREEN_PROPERTY_BUFFERS, (void **)&buffer) < 0) { - return -1; + return false; } screen_post_window(impl->window, buffer, numrects, (int *)rects, 0); screen_flush_context(context, 0); - return 0; + return true; } /** @@ -336,7 +336,7 @@ static SDL_VideoDevice *createDevice(void) device->GL_SetSwapInterval = glSetSwapInterval; device->GL_SwapWindow = glSwapWindow; device->GL_MakeCurrent = glMakeCurrent; - device->GL_DeleteContext = glDeleteContext; + device->GL_DestroyContext = glDeleteContext; device->GL_UnloadLibrary = glUnloadLibrary; device->free = deleteDevice; diff --git a/src/video/raspberry/SDL_rpimouse.c b/src/video/raspberry/SDL_rpimouse.c index 6cccafadc5..6da89ed1e7 100644 --- a/src/video/raspberry/SDL_rpimouse.c +++ b/src/video/raspberry/SDL_rpimouse.c @@ -41,8 +41,8 @@ static SDL_Cursor *RPI_CreateDefaultCursor(void); static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y); -static int RPI_ShowCursor(SDL_Cursor *cursor); -static int RPI_MoveCursor(SDL_Cursor *cursor); +static bool RPI_ShowCursor(SDL_Cursor *cursor); +static bool RPI_MoveCursor(SDL_Cursor *cursor); static void RPI_FreeCursor(SDL_Cursor *cursor); static SDL_Cursor *global_cursor; @@ -55,9 +55,9 @@ static SDL_Cursor *RPI_CreateDefaultCursor(void) // Create a cursor from a surface static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) { + int rc; SDL_CursorData *curdata; SDL_Cursor *cursor; - int ret; VC_RECT_T dst_rect; Uint32 dummy; @@ -89,8 +89,8 @@ static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) * the size of the transfer as rect.height * stride. * Therefore we can only write rows starting at x=0. */ - ret = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect); - SDL_assert(ret == DISPMANX_SUCCESS); + rc = vc_dispmanx_resource_write_data(curdata->resource, VC_IMAGE_ARGB8888, surface->pitch, surface->pixels, &dst_rect); + SDL_assert(rc == DISPMANX_SUCCESS); cursor->internal = curdata; @@ -98,22 +98,18 @@ static SDL_Cursor *RPI_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) } // Show the specified cursor, or hide if cursor is NULL -static int RPI_ShowCursor(SDL_Cursor *cursor) +static bool RPI_ShowCursor(SDL_Cursor *cursor) { - int ret; + int rc; DISPMANX_UPDATE_HANDLE_T update; SDL_CursorData *curdata; VC_RECT_T src_rect, dst_rect; - SDL_Mouse *mouse; + SDL_Mouse *mouse = SDL_GetMouse(); SDL_DisplayData *data; VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE /* flags */, 255 /*opacity 0->255*/, 0 /* mask */ }; uint32_t layer = SDL_RPI_MOUSELAYER; - const char *env; - - mouse = SDL_GetMouse(); - if (!mouse) { - return -1; - } + const char *int; + bool result; if (cursor != global_cursor) { if (global_cursor) { @@ -121,10 +117,10 @@ static int RPI_ShowCursor(SDL_Cursor *cursor) if (curdata && curdata->element > DISPMANX_NO_HANDLE) { update = vc_dispmanx_update_start(0); SDL_assert(update); - ret = vc_dispmanx_element_remove(update, curdata->element); - SDL_assert(ret == DISPMANX_SUCCESS); - ret = vc_dispmanx_update_submit_sync(update); - SDL_assert(ret == DISPMANX_SUCCESS); + rc = vc_dispmanx_element_remove(update, curdata->element); + SDL_assert(rc == DISPMANX_SUCCESS); + rc = vc_dispmanx_update_submit_sync(update); + SDL_assert(rc == DISPMANX_SUCCESS); curdata->element = DISPMANX_NO_HANDLE; } } @@ -132,21 +128,21 @@ static int RPI_ShowCursor(SDL_Cursor *cursor) } if (!cursor) { - return 0; + return true; } curdata = cursor->internal; if (!curdata) { - return -1; + return false; } if (!mouse->focus) { - return -1; + return false; } data = SDL_GetDisplayDriverDataForWindow(mouse->focus); if (!data) { - return -1; + return false; } if (curdata->element == DISPMANX_NO_HANDLE) { @@ -156,9 +152,9 @@ static int RPI_ShowCursor(SDL_Cursor *cursor) update = vc_dispmanx_update_start(0); SDL_assert(update); - env = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER); - if (env) { - layer = SDL_atoi(env) + 1; + hint = SDL_GetHint(SDL_HINT_RPI_VIDEO_LAYER); + if (hint) { + layer = SDL_atoi(hint) + 1; } curdata->element = vc_dispmanx_element_add(update, @@ -172,17 +168,17 @@ static int RPI_ShowCursor(SDL_Cursor *cursor) DISPMANX_NO_HANDLE, // clamp DISPMANX_NO_ROTATE); SDL_assert(curdata->element > DISPMANX_NO_HANDLE); - ret = vc_dispmanx_update_submit_sync(update); - SDL_assert(ret == DISPMANX_SUCCESS); + rc = vc_dispmanx_update_submit_sync(update); + SDL_assert(rc == DISPMANX_SUCCESS); } - return 0; + return true; } // Free a window manager cursor static void RPI_FreeCursor(SDL_Cursor *cursor) { - int ret; + int rc; DISPMANX_UPDATE_HANDLE_T update; SDL_CursorData *curdata; @@ -193,15 +189,15 @@ static void RPI_FreeCursor(SDL_Cursor *cursor) if (curdata->element != DISPMANX_NO_HANDLE) { update = vc_dispmanx_update_start(0); SDL_assert(update); - ret = vc_dispmanx_element_remove(update, curdata->element); - SDL_assert(ret == DISPMANX_SUCCESS); - ret = vc_dispmanx_update_submit_sync(update); - SDL_assert(ret == DISPMANX_SUCCESS); + rc = vc_dispmanx_element_remove(update, curdata->element); + SDL_assert(rc == DISPMANX_SUCCESS); + rc = vc_dispmanx_update_submit_sync(update); + SDL_assert(rc == DISPMANX_SUCCESS); } if (curdata->resource != DISPMANX_NO_HANDLE) { - ret = vc_dispmanx_resource_delete(curdata->resource); - SDL_assert(ret == DISPMANX_SUCCESS); + rc = vc_dispmanx_resource_delete(curdata->resource); + SDL_assert(rc == DISPMANX_SUCCESS); } SDL_free(cursor->internal); @@ -213,27 +209,27 @@ static void RPI_FreeCursor(SDL_Cursor *cursor) } } -static int RPI_WarpMouseGlobalGraphically(float x, float y) +static bool RPI_WarpMouseGlobalGraphically(float x, float y) { + int rc; SDL_CursorData *curdata; DISPMANX_UPDATE_HANDLE_T update; - int ret; VC_RECT_T dst_rect; VC_RECT_T src_rect; SDL_Mouse *mouse = SDL_GetMouse(); if (!mouse || !mouse->cur_cursor || !mouse->cur_cursor->internal) { - return 0; + return true; } curdata = mouse->cur_cursor->internal; if (curdata->element == DISPMANX_NO_HANDLE) { - return 0; + return true; } update = vc_dispmanx_update_start(0); if (!update) { - return 0; + return true; } src_rect.x = 0; @@ -245,7 +241,7 @@ static int RPI_WarpMouseGlobalGraphically(float x, float y) dst_rect.width = curdata->w; dst_rect.height = curdata->h; - ret = vc_dispmanx_element_change_attributes( + rc = vc_dispmanx_element_change_attributes( update, curdata->element, 0, @@ -255,24 +251,24 @@ static int RPI_WarpMouseGlobalGraphically(float x, float y) &src_rect, DISPMANX_NO_HANDLE, DISPMANX_NO_ROTATE); - if (ret != DISPMANX_SUCCESS) { + if (rc != DISPMANX_SUCCESS) { return SDL_SetError("vc_dispmanx_element_change_attributes() failed"); } // Submit asynchronously, otherwise the performance suffers a lot - ret = vc_dispmanx_update_submit(update, 0, NULL); - if (ret != DISPMANX_SUCCESS) { + rc = vc_dispmanx_update_submit(update, 0, NULL); + if (rc != DISPMANX_SUCCESS) { return SDL_SetError("vc_dispmanx_update_submit() failed"); } - return 0; + return true; } -static int RPI_WarpMouseGlobal(float x, float y) +static bool RPI_WarpMouseGlobal(float x, float y) { SDL_Mouse *mouse = SDL_GetMouse(); if (!mouse || !mouse->cur_cursor || !mouse->cur_cursor->internal) { - return 0; + return true; } // Update internal mouse position. @@ -281,7 +277,7 @@ static int RPI_WarpMouseGlobal(float x, float y) return RPI_WarpMouseGlobalGraphically(x, y); } -static int RPI_WarpMouse(SDL_Window *window, float x, float y) +static bool RPI_WarpMouse(SDL_Window *window, float x, float y) { return RPI_WarpMouseGlobal(x, y); } @@ -308,7 +304,7 @@ void RPI_QuitMouse(SDL_VideoDevice *_this) } // This is called when a mouse motion event occurs -static int RPI_MoveCursor(SDL_Cursor *cursor) +static bool RPI_MoveCursor(SDL_Cursor *cursor) { SDL_Mouse *mouse = SDL_GetMouse(); /* We must NOT call SDL_SendMouseMotion() on the next call or we will enter recursivity, diff --git a/src/video/raspberry/SDL_rpiopengles.c b/src/video/raspberry/SDL_rpiopengles.c index 69c1f7e131..969f9ced25 100644 --- a/src/video/raspberry/SDL_rpiopengles.c +++ b/src/video/raspberry/SDL_rpiopengles.c @@ -34,18 +34,18 @@ void RPI_GLES_DefaultProfileConfig(SDL_VideoDevice *_this, int *mask, int *major *minor = 0; } -int RPI_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool RPI_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { return SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0); } -int RPI_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool RPI_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *wdata = window->internal; if (!(_this->egl_data->eglSwapBuffers(_this->egl_data->egl_display, wdata->egl_surface))) { SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "eglSwapBuffers failed."); - return 0; + return true; } /* Wait immediately for vsync (as if we only had two buffers), for low input-lag scenarios. @@ -56,10 +56,10 @@ int RPI_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) SDL_UnlockMutex(wdata->vsync_cond_mutex); } - return 0; + return true; } SDL_EGL_CreateContext_impl(RPI) - SDL_EGL_MakeCurrent_impl(RPI) +SDL_EGL_MakeCurrent_impl(RPI) #endif // SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL diff --git a/src/video/raspberry/SDL_rpiopengles.h b/src/video/raspberry/SDL_rpiopengles.h index 0cc5b00f80..5836111f7f 100644 --- a/src/video/raspberry/SDL_rpiopengles.h +++ b/src/video/raspberry/SDL_rpiopengles.h @@ -34,12 +34,12 @@ #define RPI_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define RPI_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define RPI_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -#define RPI_GLES_DeleteContext SDL_EGL_DeleteContext +#define RPI_GLES_DestroyContext SDL_EGL_DestroyContext -extern int RPI_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool RPI_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_GLContext RPI_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int RPI_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int RPI_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool RPI_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool RPI_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); extern void RPI_GLES_DefaultProfileConfig(SDL_VideoDevice *_this, int *mask, int *major, int *minor); #endif // SDL_VIDEO_DRIVER_RPI && SDL_VIDEO_OPENGL_EGL diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c index 30473d7c41..73b29bcd21 100644 --- a/src/video/raspberry/SDL_rpivideo.c +++ b/src/video/raspberry/SDL_rpivideo.c @@ -123,7 +123,7 @@ static SDL_VideoDevice *RPI_Create(void) device->GL_SetSwapInterval = RPI_GLES_SetSwapInterval; device->GL_GetSwapInterval = RPI_GLES_GetSwapInterval; device->GL_SwapWindow = RPI_GLES_SwapWindow; - device->GL_DeleteContext = RPI_GLES_DeleteContext; + device->GL_DestroyContext = RPI_GLES_DestroyContext; device->GL_DefaultProfileConfig = RPI_GLES_DefaultProfileConfig; device->PumpEvents = RPI_PumpEvents; @@ -186,7 +186,7 @@ static void AddDispManXDisplay(const int display_id) SDL_AddVideoDisplay(&display, false); } -int RPI_VideoInit(SDL_VideoDevice *_this) +bool RPI_VideoInit(SDL_VideoDevice *_this) { // Initialize BCM Host bcm_host_init(); @@ -195,14 +195,14 @@ int RPI_VideoInit(SDL_VideoDevice *_this) AddDispManXDisplay(DISPMANX_ID_FORCE_OTHER); // an "other" display...maybe DSI-connected screen while HDMI is your main #ifdef SDL_INPUT_LINUXEV - if (SDL_EVDEV_Init() < 0) { - return -1; + if (!SDL_EVDEV_Init()) { + return false; } #endif RPI_InitMouse(_this); - return 1; + return true; } void RPI_VideoQuit(SDL_VideoDevice *_this) @@ -221,7 +221,7 @@ static void RPI_vsync_callback(DISPMANX_UPDATE_HANDLE_T u, void *data) SDL_UnlockMutex(wdata->vsync_cond_mutex); } -int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *wdata; SDL_VideoDisplay *display; @@ -241,7 +241,7 @@ int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI // Allocate window internal data wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return -1; + return false; } display = SDL_GetVideoDisplayForWindow(window); displaydata = display->internal; @@ -285,8 +285,8 @@ int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI vc_dispmanx_update_submit_sync(dispman_update); if (!_this->egl_data) { - if (SDL_GL_LoadLibrary(NULL) < 0) { - return -1; + if (!SDL_GL_LoadLibrary(NULL)) { + return false; } } wdata->egl_surface = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)&wdata->dispman_window); @@ -312,7 +312,7 @@ int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI SDL_SetKeyboardFocus(window); // Window has been successfully created - return 0; + return true; } void RPI_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -346,7 +346,7 @@ void RPI_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) void RPI_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } -int RPI_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool RPI_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { return SDL_Unsupported(); } diff --git a/src/video/raspberry/SDL_rpivideo.h b/src/video/raspberry/SDL_rpivideo.h index af922cb1b3..e379fa2afa 100644 --- a/src/video/raspberry/SDL_rpivideo.h +++ b/src/video/raspberry/SDL_rpivideo.h @@ -59,31 +59,31 @@ struct SDL_WindowData /****************************************************************************/ // Display and window functions -int RPI_VideoInit(SDL_VideoDevice *_this); -void RPI_VideoQuit(SDL_VideoDevice *_this); -int RPI_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -int RPI_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); -int RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); -void RPI_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -int RPI_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); -void RPI_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool RPI_VideoInit(SDL_VideoDevice *_this); +extern void RPI_VideoQuit(SDL_VideoDevice *_this); +extern bool RPI_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool RPI_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool RPI_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern void RPI_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); +extern bool RPI_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void RPI_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); // OpenGL/OpenGL ES functions -int RPI_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); -SDL_FunctionPointer RPI_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -void RPI_GLES_UnloadLibrary(SDL_VideoDevice *_this); -SDL_GLContext RPI_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -int RPI_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -int RPI_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); -int RPI_GLES_GetSwapInterval(SDL_VideoDevice *_this); -int RPI_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -int RPI_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool RPI_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern SDL_FunctionPointer RPI_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); +extern void RPI_GLES_UnloadLibrary(SDL_VideoDevice *_this); +extern SDL_GLContext RPI_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); +extern bool RPI_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool RPI_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool RPI_GLES_GetSwapInterval(SDL_VideoDevice *_this); +extern bool RPI_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool RPI_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); #endif // SDL_rpivideo_h diff --git a/src/video/riscos/SDL_riscosevents.c b/src/video/riscos/SDL_riscosevents.c index 5042a8c31b..857128801d 100644 --- a/src/video/riscos/SDL_riscosevents.c +++ b/src/video/riscos/SDL_riscosevents.c @@ -116,7 +116,7 @@ void RISCOS_PollMouse(SDL_VideoDevice *_this) _kernel_swi_regs regs; int i, x, y, buttons; - if (SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &rect) < 0) { + if (!SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &rect)) { return; } @@ -137,7 +137,7 @@ void RISCOS_PollMouse(SDL_VideoDevice *_this) } } -int RISCOS_InitEvents(SDL_VideoDevice *_this) +bool RISCOS_InitEvents(SDL_VideoDevice *_this) { SDL_VideoData *internal = _this->internal; _kernel_swi_regs regs; @@ -158,7 +158,7 @@ int RISCOS_InitEvents(SDL_VideoDevice *_this) // Disable escape. _kernel_osbyte(229, 1, 0); - return 0; + return true; } void RISCOS_PumpEvents(SDL_VideoDevice *_this) diff --git a/src/video/riscos/SDL_riscosevents_c.h b/src/video/riscos/SDL_riscosevents_c.h index 1db55c753b..b0f345d491 100644 --- a/src/video/riscos/SDL_riscosevents_c.h +++ b/src/video/riscos/SDL_riscosevents_c.h @@ -26,7 +26,7 @@ #include "SDL_riscosvideo.h" -extern int RISCOS_InitEvents(SDL_VideoDevice *_this); +extern bool RISCOS_InitEvents(SDL_VideoDevice *_this); extern void RISCOS_PumpEvents(SDL_VideoDevice *_this); extern void RISCOS_QuitEvents(SDL_VideoDevice *_this); diff --git a/src/video/riscos/SDL_riscosframebuffer.c b/src/video/riscos/SDL_riscosframebuffer.c index 6f10634a94..4e1192e1b1 100644 --- a/src/video/riscos/SDL_riscosframebuffer.c +++ b/src/video/riscos/SDL_riscosframebuffer.c @@ -30,7 +30,7 @@ #include #include -int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_WindowData *internal = window->internal; const char *sprite_name = "display"; @@ -63,7 +63,7 @@ int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, S size = sizeof(sprite_area) + sizeof(sprite_header) + ((*pitch) * h); internal->fb_area = SDL_malloc(size); if (!internal->fb_area) { - return -1; + return false; } internal->fb_area->size = size; @@ -88,10 +88,10 @@ int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, S internal->fb_sprite = (sprite_header *)(((Uint8 *)internal->fb_area) + internal->fb_area->start); *pixels = ((Uint8 *)internal->fb_sprite) + internal->fb_sprite->image_offset; - return 0; + return true; } -int RISCOS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool RISCOS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { SDL_WindowData *internal = window->internal; _kernel_swi_regs regs; @@ -110,7 +110,7 @@ int RISCOS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, c return SDL_SetError("OS_SpriteOp 52 failed: %s (%i)", error->errmess, error->errnum); } - return 0; + return true; } void RISCOS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/riscos/SDL_riscosframebuffer_c.h b/src/video/riscos/SDL_riscosframebuffer_c.h index 0c746fdc2c..944e9321ef 100644 --- a/src/video/riscos/SDL_riscosframebuffer_c.h +++ b/src/video/riscos/SDL_riscosframebuffer_c.h @@ -24,8 +24,8 @@ #include "SDL_internal.h" -extern int RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -extern int RISCOS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern bool RISCOS_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool RISCOS_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); extern void RISCOS_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_riscosframebuffer_c_h_ diff --git a/src/video/riscos/SDL_riscosmessagebox.c b/src/video/riscos/SDL_riscosmessagebox.c index 1186ca5946..bc2fddce6e 100644 --- a/src/video/riscos/SDL_riscosmessagebox.c +++ b/src/video/riscos/SDL_riscosmessagebox.c @@ -27,7 +27,7 @@ #include #include -int RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { _kernel_swi_regs regs; _kernel_oserror error; @@ -61,7 +61,7 @@ int RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonI _kernel_swi(Wimp_ReportError, ®s, ®s); *buttonID = (regs.r[1] == 0) ? -1 : messageboxdata->buttons[regs.r[1] - 3].buttonID; - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_RISCOS diff --git a/src/video/riscos/SDL_riscosmessagebox.h b/src/video/riscos/SDL_riscosmessagebox.h index 87fce5a102..e05e063b18 100644 --- a/src/video/riscos/SDL_riscosmessagebox.h +++ b/src/video/riscos/SDL_riscosmessagebox.h @@ -22,6 +22,6 @@ #ifdef SDL_VIDEO_DRIVER_RISCOS -extern int RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool RISCOS_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_RISCOS diff --git a/src/video/riscos/SDL_riscosmodes.c b/src/video/riscos/SDL_riscosmodes.c index 1bb0506614..b36e7c3593 100644 --- a/src/video/riscos/SDL_riscosmodes.c +++ b/src/video/riscos/SDL_riscosmodes.c @@ -96,7 +96,7 @@ static size_t measure_mode_block(const int *block) return blockSize * 4; } -static int read_mode_variable(int *block, int var) +static bool read_mode_variable(int *block, int var) { _kernel_swi_regs regs; regs.r[0] = (int)block; @@ -198,7 +198,7 @@ static void *copy_memory(const void *src, size_t size, size_t alloc) return dst; } -int RISCOS_InitModes(SDL_VideoDevice *_this) +bool RISCOS_InitModes(SDL_VideoDevice *_this) { SDL_DisplayMode mode; int *current_mode; @@ -220,16 +220,16 @@ int RISCOS_InitModes(SDL_VideoDevice *_this) size = measure_mode_block(current_mode); mode.internal = copy_memory(current_mode, size, size); if (!mode.internal) { - return -1; + return false; } if (SDL_AddBasicVideoDisplay(&mode) == 0) { - return -1; + return false; } - return 0; + return true; } -int RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +bool RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { SDL_DisplayMode mode; _kernel_swi_regs regs; @@ -247,7 +247,7 @@ int RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) block = SDL_malloc(-regs.r[7]); if (!block) { - return -1; + return false; } regs.r[6] = (int)block; @@ -270,7 +270,7 @@ int RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) mode.internal = convert_mode_block(pos + 4); if (!mode.internal) { SDL_free(block); - return -1; + return false; } if (!SDL_AddFullscreenDisplayMode(display, &mode)) { @@ -279,10 +279,10 @@ int RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) } SDL_free(block); - return 0; + return true; } -int RISCOS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +bool RISCOS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { const char disable_cursor[] = { 23, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; _kernel_swi_regs regs; @@ -304,7 +304,7 @@ int RISCOS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL // Update cursor visibility, since it may have been disabled by the mode change. SDL_SetCursor(NULL); - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_RISCOS diff --git a/src/video/riscos/SDL_riscosmodes.h b/src/video/riscos/SDL_riscosmodes.h index 4c8ed7d4e6..2d17dbdb10 100644 --- a/src/video/riscos/SDL_riscosmodes.h +++ b/src/video/riscos/SDL_riscosmodes.h @@ -23,9 +23,8 @@ #ifndef SDL_riscosmodes_h_ #define SDL_riscosmodes_h_ -extern int RISCOS_InitModes(SDL_VideoDevice *_this); -extern int RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -extern int RISCOS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, - SDL_DisplayMode *mode); +extern bool RISCOS_InitModes(SDL_VideoDevice *_this); +extern bool RISCOS_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool RISCOS_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); #endif // SDL_riscosmodes_h_ diff --git a/src/video/riscos/SDL_riscosmouse.c b/src/video/riscos/SDL_riscosmouse.c index 3101a0f0cf..16b0a550ca 100644 --- a/src/video/riscos/SDL_riscosmouse.c +++ b/src/video/riscos/SDL_riscosmouse.c @@ -44,7 +44,7 @@ static void RISCOS_FreeCursor(SDL_Cursor *cursor) SDL_free(cursor); } -static int RISCOS_ShowCursor(SDL_Cursor *cursor) +static bool RISCOS_ShowCursor(SDL_Cursor *cursor) { if (cursor) { // Turn the mouse pointer on @@ -54,10 +54,10 @@ static int RISCOS_ShowCursor(SDL_Cursor *cursor) _kernel_osbyte(106, 0, 0); } - return 0; + return true; } -int RISCOS_InitMouse(SDL_VideoDevice *_this) +bool RISCOS_InitMouse(SDL_VideoDevice *_this) { SDL_Mouse *mouse = SDL_GetMouse(); @@ -73,7 +73,7 @@ int RISCOS_InitMouse(SDL_VideoDevice *_this) SDL_SetDefaultCursor(RISCOS_CreateDefaultCursor()); - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_RISCOS diff --git a/src/video/riscos/SDL_riscosmouse.h b/src/video/riscos/SDL_riscosmouse.h index 29d7c24469..9f09dd6e1a 100644 --- a/src/video/riscos/SDL_riscosmouse.h +++ b/src/video/riscos/SDL_riscosmouse.h @@ -23,6 +23,6 @@ #ifndef SDL_riscosmouse_h_ #define SDL_riscosmouse_h_ -extern int RISCOS_InitMouse(SDL_VideoDevice *_this); +extern bool RISCOS_InitMouse(SDL_VideoDevice *_this); #endif // SDL_riscosmouse_h_ diff --git a/src/video/riscos/SDL_riscosvideo.c b/src/video/riscos/SDL_riscosvideo.c index f81cbd19cc..6fc6508b9e 100644 --- a/src/video/riscos/SDL_riscosvideo.c +++ b/src/video/riscos/SDL_riscosvideo.c @@ -39,7 +39,7 @@ #define RISCOSVID_DRIVER_NAME "riscos" // Initialization/Query functions -static int RISCOS_VideoInit(SDL_VideoDevice *_this); +static bool RISCOS_VideoInit(SDL_VideoDevice *_this); static void RISCOS_VideoQuit(SDL_VideoDevice *_this); // RISC OS driver bootstrap functions @@ -99,26 +99,26 @@ VideoBootStrap RISCOS_bootstrap = { RISCOS_ShowMessageBox }; -static int RISCOS_VideoInit(SDL_VideoDevice *_this) +static bool RISCOS_VideoInit(SDL_VideoDevice *_this) { - if (RISCOS_InitEvents(_this) < 0) { - return -1; + if (!RISCOS_InitEvents(_this)) { + return false; } - if (RISCOS_InitMouse(_this) < 0) { - return -1; + if (!RISCOS_InitMouse(_this)) { + return false; } // Assume we have a mouse and keyboard SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false); SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false); - if (RISCOS_InitModes(_this) < 0) { - return -1; + if (!RISCOS_InitModes(_this)) { + return false; } // We're done! - return 0; + return true; } static void RISCOS_VideoQuit(SDL_VideoDevice *_this) diff --git a/src/video/riscos/SDL_riscoswindow.c b/src/video/riscos/SDL_riscoswindow.c index 992ae8c267..7eb1c25c55 100644 --- a/src/video/riscos/SDL_riscoswindow.c +++ b/src/video/riscos/SDL_riscoswindow.c @@ -28,13 +28,13 @@ #include "SDL_riscosvideo.h" #include "SDL_riscoswindow.h" -int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *data; data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } data->window = window; @@ -42,7 +42,7 @@ int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti // All done! window->internal = data; - return 0; + return true; } void RISCOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/riscos/SDL_riscoswindow.h b/src/video/riscos/SDL_riscoswindow.h index 794faea31f..35179110b7 100644 --- a/src/video/riscos/SDL_riscoswindow.h +++ b/src/video/riscos/SDL_riscoswindow.h @@ -32,7 +32,7 @@ struct SDL_WindowData sprite_header *fb_sprite; }; -extern int RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool RISCOS_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern void RISCOS_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_riscoswindow_h_ diff --git a/src/video/uikit/SDL_uikitclipboard.h b/src/video/uikit/SDL_uikitclipboard.h index aac728f17c..ce126fd96a 100644 --- a/src/video/uikit/SDL_uikitclipboard.h +++ b/src/video/uikit/SDL_uikitclipboard.h @@ -23,7 +23,7 @@ #include "../SDL_sysvideo.h" -extern int UIKit_SetClipboardText(SDL_VideoDevice *_this, const char *text); +extern bool UIKit_SetClipboardText(SDL_VideoDevice *_this, const char *text); extern char *UIKit_GetClipboardText(SDL_VideoDevice *_this); extern bool UIKit_HasClipboardText(SDL_VideoDevice *_this); diff --git a/src/video/uikit/SDL_uikitclipboard.m b/src/video/uikit/SDL_uikitclipboard.m index 836d3ee735..1ba0eca29f 100644 --- a/src/video/uikit/SDL_uikitclipboard.m +++ b/src/video/uikit/SDL_uikitclipboard.m @@ -27,14 +27,14 @@ #import -int UIKit_SetClipboardText(SDL_VideoDevice *_this, const char *text) +bool UIKit_SetClipboardText(SDL_VideoDevice *_this, const char *text) { #ifdef SDL_PLATFORM_TVOS return SDL_SetError("The clipboard is not available on tvOS"); #else @autoreleasepool { [UIPasteboard generalPasteboard].string = @(text); - return 0; + return true; } #endif } diff --git a/src/video/uikit/SDL_uikitevents.m b/src/video/uikit/SDL_uikitevents.m index 1be24d0f4a..994914811e 100644 --- a/src/video/uikit/SDL_uikitevents.m +++ b/src/video/uikit/SDL_uikitevents.m @@ -309,11 +309,11 @@ static void UpdatePointerLock(void) } } -static int SetGCMouseRelativeMode(bool enabled) +static bool SetGCMouseRelativeMode(bool enabled) { mouse_relative_mode = enabled; UpdatePointerLock(); - return 0; + return true; } static void OnGCMouseButtonChanged(SDL_MouseID mouseID, Uint8 button, BOOL pressed) diff --git a/src/video/uikit/SDL_uikitmessagebox.h b/src/video/uikit/SDL_uikitmessagebox.h index a93e891958..ca207052be 100644 --- a/src/video/uikit/SDL_uikitmessagebox.h +++ b/src/video/uikit/SDL_uikitmessagebox.h @@ -23,7 +23,6 @@ #ifdef SDL_VIDEO_DRIVER_UIKIT extern bool UIKit_ShowingMessageBox(void); - -extern int UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_UIKIT diff --git a/src/video/uikit/SDL_uikitmessagebox.m b/src/video/uikit/SDL_uikitmessagebox.m index 0c930242e9..2f2094aa59 100644 --- a/src/video/uikit/SDL_uikitmessagebox.m +++ b/src/video/uikit/SDL_uikitmessagebox.m @@ -124,30 +124,30 @@ static BOOL UIKit_ShowMessageBoxAlertController(const SDL_MessageBoxData *messag return YES; } -static void UIKit_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, int *returnValue) +static void UIKit_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID, int *result) { @autoreleasepool { if (UIKit_ShowMessageBoxAlertController(messageboxdata, buttonID)) { - *returnValue = 0; + *result = true; } else { - *returnValue = SDL_SetError("Could not show message box."); + *result = SDL_SetError("Could not show message box."); } } } -int UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool UIKit_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { @autoreleasepool { - __block int returnValue = 0; + __block int result = true; if ([NSThread isMainThread]) { - UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &returnValue); + UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result); } else { dispatch_sync(dispatch_get_main_queue(), ^{ - UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &returnValue); + UIKit_ShowMessageBoxImpl(messageboxdata, buttonID, &result); }); } - return returnValue; + return result; } } diff --git a/src/video/uikit/SDL_uikitmodes.h b/src/video/uikit/SDL_uikitmodes.h index cbb98d5912..ee3d48eba3 100644 --- a/src/video/uikit/SDL_uikitmodes.h +++ b/src/video/uikit/SDL_uikitmodes.h @@ -45,15 +45,15 @@ extern bool UIKit_IsDisplayLandscape(UIScreen *uiscreen); #endif -extern int UIKit_InitModes(SDL_VideoDevice *_this); +extern bool UIKit_InitModes(SDL_VideoDevice *_this); #ifndef SDL_PLATFORM_VISIONOS -extern int UIKit_AddDisplay(UIScreen *uiscreen, bool send_event); +extern bool UIKit_AddDisplay(UIScreen *uiscreen, bool send_event); extern void UIKit_DelDisplay(UIScreen *uiscreen, bool send_event); #endif -extern int UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -extern int UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); extern void UIKit_QuitModes(SDL_VideoDevice *_this); -extern int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +extern bool UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); // because visionOS does not have a screen // we create a fake display to maintain compatibility. diff --git a/src/video/uikit/SDL_uikitmodes.m b/src/video/uikit/SDL_uikitmodes.m index 57b8dcac8d..8688dac1b3 100644 --- a/src/video/uikit/SDL_uikitmodes.m +++ b/src/video/uikit/SDL_uikitmodes.m @@ -99,7 +99,7 @@ #endif #ifndef SDL_PLATFORM_VISIONOS -static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode, +static bool UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode, UIScreenMode *uiscreenmode) { SDL_UIKitDisplayModeData *data = nil; @@ -116,7 +116,7 @@ static int UIKit_AllocateDisplayModeData(SDL_DisplayMode *mode, mode->internal = (void *)CFBridgingRetain(data); - return 0; + return true; } #endif @@ -139,14 +139,14 @@ static float UIKit_GetDisplayModeRefreshRate(UIScreen *uiscreen) return 0.0f; } -static int UIKit_AddSingleDisplayMode(SDL_VideoDisplay *display, int w, int h, +static bool UIKit_AddSingleDisplayMode(SDL_VideoDisplay *display, int w, int h, UIScreen *uiscreen, UIScreenMode *uiscreenmode) { SDL_DisplayMode mode; SDL_zero(mode); - if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) { - return -1; + if (!UIKit_AllocateDisplayModeData(&mode, uiscreenmode)) { + return false; } mode.w = w; @@ -156,28 +156,28 @@ static int UIKit_AddSingleDisplayMode(SDL_VideoDisplay *display, int w, int h, mode.format = SDL_PIXELFORMAT_ABGR8888; if (SDL_AddFullscreenDisplayMode(display, &mode)) { - return 0; + return true; } else { UIKit_FreeDisplayModeData(&mode); - return -1; + return false; } } -static int UIKit_AddDisplayMode(SDL_VideoDisplay *display, int w, int h, +static bool UIKit_AddDisplayMode(SDL_VideoDisplay *display, int w, int h, UIScreen *uiscreen, UIScreenMode *uiscreenmode, bool addRotation) { - if (UIKit_AddSingleDisplayMode(display, w, h, uiscreen, uiscreenmode) < 0) { - return -1; + if (!UIKit_AddSingleDisplayMode(display, w, h, uiscreen, uiscreenmode)) { + return false; } if (addRotation) { // Add the rotated version - if (UIKit_AddSingleDisplayMode(display, h, w, uiscreen, uiscreenmode) < 0) { - return -1; + if (!UIKit_AddSingleDisplayMode(display, h, w, uiscreen, uiscreenmode)) { + return false; } } - return 0; + return true; } static CGSize GetUIScreenModeSize(UIScreen *uiscreen, UIScreenMode *mode) @@ -203,7 +203,7 @@ static CGSize GetUIScreenModeSize(UIScreen *uiscreen, UIScreenMode *mode) return size; } -int UIKit_AddDisplay(UIScreen *uiscreen, bool send_event) +bool UIKit_AddDisplay(UIScreen *uiscreen, bool send_event) { UIScreenMode *uiscreenmode = uiscreen.currentMode; CGSize size = GetUIScreenModeSize(uiscreen, uiscreenmode); @@ -224,8 +224,8 @@ int UIKit_AddDisplay(UIScreen *uiscreen, bool send_event) mode.format = SDL_PIXELFORMAT_ABGR8888; mode.refresh_rate = UIKit_GetDisplayModeRefreshRate(uiscreen); - if (UIKit_AllocateDisplayModeData(&mode, uiscreenmode) < 0) { - return -1; + if (!UIKit_AllocateDisplayModeData(&mode, uiscreenmode)) { + return false; } SDL_zero(display); @@ -268,14 +268,14 @@ int UIKit_AddDisplay(UIScreen *uiscreen, bool send_event) display.internal = (SDL_DisplayData *)CFBridgingRetain(data); if (SDL_AddVideoDisplay(&display, send_event) == 0) { - return -1; + return false; } - return 0; + return true; } #endif #ifdef SDL_PLATFORM_VISIONOS -int UIKit_AddDisplay(bool send_event){ +bool UIKit_AddDisplay(bool send_event){ CGSize size = CGSizeMake(SDL_XR_SCREENWIDTH, SDL_XR_SCREENHEIGHT); SDL_VideoDisplay display; SDL_DisplayMode mode; @@ -300,9 +300,9 @@ int UIKit_AddDisplay(bool send_event){ display.internal = (SDL_DisplayData *)CFBridgingRetain(data); if (SDL_AddVideoDisplay(&display, send_event) == 0) { - return -1; + return false; } - return 0; + return true; } #endif @@ -343,15 +343,15 @@ bool UIKit_IsDisplayLandscape(UIScreen *uiscreen) } } #endif -int UIKit_InitModes(SDL_VideoDevice *_this) +bool UIKit_InitModes(SDL_VideoDevice *_this) { @autoreleasepool { #ifdef SDL_PLATFORM_VISIONOS UIKit_AddDisplay(false); #else for (UIScreen *uiscreen in [UIScreen screens]) { - if (UIKit_AddDisplay(uiscreen, false) < 0) { - return -1; + if (!UIKit_AddDisplay(uiscreen, false)) { + return false; } } #endif @@ -365,10 +365,10 @@ int UIKit_InitModes(SDL_VideoDevice *_this) #endif } - return 0; + return true; } -int UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +bool UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { #ifndef SDL_PLATFORM_VISIONOS @autoreleasepool { @@ -401,10 +401,10 @@ int UIKit_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) } } #endif - return 0; + return true; } -int UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +bool UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { #ifndef SDL_PLATFORM_VISIONOS @autoreleasepool { @@ -431,10 +431,10 @@ int UIKit_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_ } } #endif - return 0; + return true; } -int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +bool UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { @autoreleasepool { SDL_UIKitDisplayData *data = (__bridge SDL_UIKitDisplayData *)display->internal; @@ -446,8 +446,8 @@ int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ /* the default function iterates displays to make a fake offset, as if all the displays were side-by-side, which is fine for iOS. */ - if (SDL_GetDisplayBounds(display->id, rect) < 0) { - return -1; + if (!SDL_GetDisplayBounds(display->id, rect)) { + return false; } rect->x += (int)frame.origin.x; @@ -456,7 +456,7 @@ int UIKit_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *displ rect->h = (int)frame.size.height; } - return 0; + return true; } void UIKit_QuitModes(SDL_VideoDevice *_this) diff --git a/src/video/uikit/SDL_uikitopengles.h b/src/video/uikit/SDL_uikitopengles.h index 3fd3328693..686ab715b1 100644 --- a/src/video/uikit/SDL_uikitopengles.h +++ b/src/video/uikit/SDL_uikitopengles.h @@ -25,13 +25,13 @@ #include "../SDL_sysvideo.h" -extern int UIKit_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, +extern bool UIKit_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int UIKit_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool UIKit_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_GLContext UIKit_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int UIKit_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool UIKit_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); extern SDL_FunctionPointer UIKit_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -extern int UIKit_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool UIKit_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern void UIKit_GL_RestoreCurrentContext(void); diff --git a/src/video/uikit/SDL_uikitopengles.m b/src/video/uikit/SDL_uikitopengles.m index 8ede945a0c..7385ef6cdd 100644 --- a/src/video/uikit/SDL_uikitopengles.m +++ b/src/video/uikit/SDL_uikitopengles.m @@ -62,7 +62,7 @@ SDL_FunctionPointer UIKit_GL_GetProcAddress(SDL_VideoDevice *_this, const char * /* note that SDL_GL_DestroyContext makes it current without passing the window */ -int UIKit_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool UIKit_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { @autoreleasepool { SDLEAGLContext *eaglcontext = (__bridge SDLEAGLContext *)context; @@ -76,20 +76,20 @@ int UIKit_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLConte } } - return 0; + return true; } -int UIKit_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool UIKit_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) { /* We shouldn't pass a path to this function, since we've already loaded the * library. */ if (path != NULL) { return SDL_SetError("iOS GL Load Library just here for compatibility"); } - return 0; + return true; } -int UIKit_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool UIKit_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { @autoreleasepool { SDLEAGLContext *context = (__bridge SDLEAGLContext *)SDL_GL_GetCurrentContext(); @@ -105,7 +105,7 @@ int UIKit_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) * We don't pump events here because we don't want iOS application events * (low memory, terminate, etc.) to happen inside low level rendering. */ } - return 0; + return true; } SDL_GLContext UIKit_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) @@ -179,8 +179,8 @@ SDL_GLContext UIKit_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) // The context owns the view / drawable. context.sdlView = view; - if (UIKit_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext)context) < 0) { - UIKit_GL_DeleteContext(_this, (SDL_GLContext)CFBridgingRetain(context)); + if (!UIKit_GL_MakeCurrent(_this, window, (__bridge SDL_GLContext)context)) { + UIKit_GL_DestroyContext(_this, (SDL_GLContext)CFBridgingRetain(context)); return NULL; } @@ -190,7 +190,7 @@ SDL_GLContext UIKit_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) } } -int UIKit_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool UIKit_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { @autoreleasepool { /* The context was retained in SDL_GL_CreateContext, so we release it @@ -198,7 +198,7 @@ int UIKit_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) * context is deallocated. */ CFRelease(context); } - return 0; + return true; } void UIKit_GL_RestoreCurrentContext(void) diff --git a/src/video/uikit/SDL_uikitvideo.h b/src/video/uikit/SDL_uikitvideo.h index 899fc193ad..66c30c73dc 100644 --- a/src/video/uikit/SDL_uikitvideo.h +++ b/src/video/uikit/SDL_uikitvideo.h @@ -41,7 +41,7 @@ CGRect UIKit_ComputeViewFrame(SDL_Window *window, UIScreen *screen); #endif // __OBJC__ -int UIKit_SuspendScreenSaver(SDL_VideoDevice *_this); +bool UIKit_SuspendScreenSaver(SDL_VideoDevice *_this); void UIKit_ForceUpdateHomeIndicator(void); diff --git a/src/video/uikit/SDL_uikitvideo.m b/src/video/uikit/SDL_uikitvideo.m index 4d0ca3bd39..02f903edfe 100644 --- a/src/video/uikit/SDL_uikitvideo.m +++ b/src/video/uikit/SDL_uikitvideo.m @@ -45,7 +45,7 @@ @end // Initialization/Query functions -static int UIKit_VideoInit(SDL_VideoDevice *_this); +static bool UIKit_VideoInit(SDL_VideoDevice *_this); static void UIKit_VideoQuit(SDL_VideoDevice *_this); // DUMMY driver bootstrap functions @@ -112,7 +112,7 @@ static SDL_VideoDevice *UIKit_CreateDevice(void) device->GL_MakeCurrent = UIKit_GL_MakeCurrent; device->GL_SwapWindow = UIKit_GL_SwapWindow; device->GL_CreateContext = UIKit_GL_CreateContext; - device->GL_DeleteContext = UIKit_GL_DeleteContext; + device->GL_DestroyContext = UIKit_GL_DestroyContext; device->GL_GetProcAddress = UIKit_GL_GetProcAddress; device->GL_LoadLibrary = UIKit_GL_LoadLibrary; #endif @@ -146,12 +146,12 @@ VideoBootStrap UIKIT_bootstrap = { UIKit_ShowMessageBox }; -int UIKit_VideoInit(SDL_VideoDevice *_this) +static bool UIKit_VideoInit(SDL_VideoDevice *_this) { _this->gl_config.driver_loaded = 1; - if (UIKit_InitModes(_this) < 0) { - return -1; + if (!UIKit_InitModes(_this)) { + return false; } SDL_InitGCKeyboard(); @@ -159,10 +159,10 @@ int UIKit_VideoInit(SDL_VideoDevice *_this) UIKit_InitClipboard(_this); - return 0; + return true; } -void UIKit_VideoQuit(SDL_VideoDevice *_this) +static void UIKit_VideoQuit(SDL_VideoDevice *_this) { UIKit_QuitClipboard(_this); @@ -172,7 +172,7 @@ void UIKit_VideoQuit(SDL_VideoDevice *_this) UIKit_QuitModes(_this); } -int UIKit_SuspendScreenSaver(SDL_VideoDevice *_this) +bool UIKit_SuspendScreenSaver(SDL_VideoDevice *_this) { @autoreleasepool { UIApplication *app = [UIApplication sharedApplication]; @@ -180,7 +180,7 @@ int UIKit_SuspendScreenSaver(SDL_VideoDevice *_this) // Prevent the display from dimming and going to sleep. app.idleTimerDisabled = (_this->suspend_screensaver != false); } - return 0; + return true; } bool UIKit_IsSystemVersionAtLeast(double version) diff --git a/src/video/uikit/SDL_uikitviewcontroller.h b/src/video/uikit/SDL_uikitviewcontroller.h index 66ee9f404a..b66258c1f0 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.h +++ b/src/video/uikit/SDL_uikitviewcontroller.h @@ -91,5 +91,5 @@ bool UIKit_HasScreenKeyboardSupport(SDL_VideoDevice *_this); void UIKit_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); void UIKit_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window); bool UIKit_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window); -int UIKit_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); +bool UIKit_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); #endif diff --git a/src/video/uikit/SDL_uikitviewcontroller.m b/src/video/uikit/SDL_uikitviewcontroller.m index 2f2711073b..4ebe9d15e4 100644 --- a/src/video/uikit/SDL_uikitviewcontroller.m +++ b/src/video/uikit/SDL_uikitviewcontroller.m @@ -712,7 +712,7 @@ bool UIKit_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window) } } -int UIKit_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) +bool UIKit_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) { @autoreleasepool { SDL_uikitviewcontroller *vc = GetWindowViewController(window); @@ -724,7 +724,7 @@ int UIKit_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) } } } - return 0; + return true; } #endif // SDL_IPHONE_KEYBOARD diff --git a/src/video/uikit/SDL_uikitvulkan.h b/src/video/uikit/SDL_uikitvulkan.h index 506fc14096..3162eb851d 100644 --- a/src/video/uikit/SDL_uikitvulkan.h +++ b/src/video/uikit/SDL_uikitvulkan.h @@ -34,16 +34,15 @@ #if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_UIKIT) -int UIKit_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void UIKit_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* UIKit_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int UIKit_Vulkan_CreateSurface(SDL_VideoDevice *_this, +extern bool UIKit_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void UIKit_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* UIKit_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool UIKit_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); -void UIKit_Vulkan_DestroySurface(SDL_VideoDevice *_this, +extern void UIKit_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); diff --git a/src/video/uikit/SDL_uikitvulkan.m b/src/video/uikit/SDL_uikitvulkan.m index f89a995000..b010cb4484 100644 --- a/src/video/uikit/SDL_uikitvulkan.m +++ b/src/video/uikit/SDL_uikitvulkan.m @@ -44,7 +44,7 @@ const char *defaultPaths[] = { * proofing. */ #define DEFAULT_HANDLE RTLD_DEFAULT -int UIKit_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool UIKit_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 extensionCount = 0; @@ -150,11 +150,11 @@ int UIKit_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) goto fail; } - return 0; + return true; fail: _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void UIKit_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -179,7 +179,7 @@ char const* const* UIKit_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, return extensionsForUIKit; } -int UIKit_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool UIKit_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, @@ -209,7 +209,7 @@ int UIKit_Vulkan_CreateSurface(SDL_VideoDevice *_this, metalview = UIKit_Metal_CreateView(_this, window); if (metalview == NULL) { - return -1; + return false; } if (vkCreateMetalSurfaceEXT) { @@ -248,7 +248,7 @@ int UIKit_Vulkan_CreateSurface(SDL_VideoDevice *_this, * knowledge of Metal can proceed. */ CFBridgingRelease(metalview); - return 0; + return true; } void UIKit_Vulkan_DestroySurface(SDL_VideoDevice *_this, diff --git a/src/video/uikit/SDL_uikitwindow.h b/src/video/uikit/SDL_uikitwindow.h index dc34f76deb..d11a702a86 100644 --- a/src/video/uikit/SDL_uikitwindow.h +++ b/src/video/uikit/SDL_uikitwindow.h @@ -26,13 +26,13 @@ #import "SDL_uikitview.h" #import "SDL_uikitviewcontroller.h" -extern int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern void UIKit_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); extern void UIKit_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void UIKit_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void UIKit_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void UIKit_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); -extern int UIKit_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +extern SDL_FullscreenResult UIKit_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); extern void UIKit_UpdatePointerLock(SDL_VideoDevice *_this, SDL_Window *window); extern void UIKit_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void UIKit_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h); diff --git a/src/video/uikit/SDL_uikitwindow.m b/src/video/uikit/SDL_uikitwindow.m index 057b43b29d..00563f0d4f 100644 --- a/src/video/uikit/SDL_uikitwindow.m +++ b/src/video/uikit/SDL_uikitwindow.m @@ -79,7 +79,7 @@ @end -static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, UIWindow *uiwindow, bool created) +static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, UIWindow *uiwindow, bool created) { SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); SDL_UIKitDisplayData *displaydata = (__bridge SDL_UIKitDisplayData *)display->internal; @@ -149,10 +149,10 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, UIWindow SDL_SetPointerProperty(props, SDL_PROP_WINDOW_UIKIT_WINDOW_POINTER, (__bridge void *)data.uiwindow); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_UIKIT_METAL_VIEW_TAG_NUMBER, SDL_METALVIEW_TAG); - return 0; + return true; } -int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { @autoreleasepool { SDL_VideoDisplay *display = SDL_GetVideoDisplayForWindow(window); @@ -177,7 +177,7 @@ int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) { include_high_density_modes = true; } - if (SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f, include_high_density_modes, &bestmode) == 0) { + if (SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f, include_high_density_modes, &bestmode)) { SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)bestmode.internal; [data.uiscreen setCurrentMode:modedata.uiscreenmode]; @@ -212,12 +212,12 @@ int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie } #endif - if (SetupWindowData(_this, window, uiwindow, true) < 0) { - return -1; + if (!SetupWindowData(_this, window, uiwindow, true)) { + return false; } } - return 1; + return true; } void UIKit_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) @@ -305,13 +305,13 @@ void UIKit_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bo } } -int UIKit_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) +SDL_FullscreenResult UIKit_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { @autoreleasepool { SDL_SendWindowEvent(window, fullscreen ? SDL_EVENT_WINDOW_ENTER_FULLSCREEN : SDL_EVENT_WINDOW_LEAVE_FULLSCREEN, 0, 0); UIKit_UpdateWindowBorder(_this, window); } - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } void UIKit_UpdatePointerLock(SDL_VideoDevice *_this, SDL_Window *window) @@ -452,7 +452,7 @@ UIKit_GetSupportedOrientations(SDL_Window *window) } #endif // !SDL_PLATFORM_TVOS -int SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam) +SDL_bool SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimationCallback callback, void *callbackParam) { if (!window || !window->internal) { return SDL_SetError("Invalid window"); @@ -465,7 +465,7 @@ int SDL_SetiOSAnimationCallback(SDL_Window *window, int interval, SDL_iOSAnimati callbackParam:callbackParam]; } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_UIKIT diff --git a/src/video/vita/SDL_vitaframebuffer.c b/src/video/vita/SDL_vitaframebuffer.c index 6ceda93b54..970f38026e 100644 --- a/src/video/vita/SDL_vitaframebuffer.c +++ b/src/video/vita/SDL_vitaframebuffer.c @@ -63,7 +63,7 @@ void vita_gpu_free(SceUID uid) sceKernelFreeMemBlock(uid); } -int VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_WindowData *data = window->internal; SceDisplayFrameBuf framebuf; @@ -90,13 +90,13 @@ int VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL *pixels = data->buffer; - return 0; + return true; } -int VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { // do nothing - return 0; + return true; } void VITA_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/vita/SDL_vitaframebuffer.h b/src/video/vita/SDL_vitaframebuffer.h index 29c10970f0..0703b71ec8 100644 --- a/src/video/vita/SDL_vitaframebuffer.h +++ b/src/video/vita/SDL_vitaframebuffer.h @@ -20,6 +20,6 @@ */ #include "SDL_internal.h" -extern int VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -extern int VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern bool VITA_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool VITA_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); extern void VITA_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/vita/SDL_vitagl_pvr.c b/src/video/vita/SDL_vitagl_pvr.c index 95bf465202..fbd675b6ed 100644 --- a/src/video/vita/SDL_vitagl_pvr.c +++ b/src/video/vita/SDL_vitagl_pvr.c @@ -43,7 +43,7 @@ static void getFBSize(int *width, int *height) *height = FB_HEIGHT; } -int VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) { PVRSRV_PSP2_APPHINT hint; char *default_path = "app0:module"; diff --git a/src/video/vita/SDL_vitagles.c b/src/video/vita/SDL_vitagles.c index 953a7a31f0..d26ab67754 100644 --- a/src/video/vita/SDL_vitagles.c +++ b/src/video/vita/SDL_vitagles.c @@ -38,7 +38,7 @@ err = eglGetError(); \ if (err != EGL_SUCCESS) { \ SDL_SetError("EGL error %d", err); \ - return 0; \ + return NULL; \ } \ } while (0) @@ -58,10 +58,10 @@ void VITA_GLES_KeyboardCallback(ScePigletPreSwapData *data) sceCommonDialogUpdate(&commonDialogParam); } -int VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { pibInit(PIB_SHACCCG | PIB_GET_PROC_ADDR_CORE); - return 0; + return true; } SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc) @@ -133,7 +133,7 @@ SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window if (num_configs == 0) { SDL_SetError("No valid EGL configs for requested mode"); - return 0; + return NULL; } EGLCHK(surface = eglCreateWindowSurface(display, config, VITA_WINDOW_960X544, NULL)); @@ -155,43 +155,43 @@ SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window return context; } -int VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { if (!eglMakeCurrent(_this->gl_data->display, _this->gl_data->surface, _this->gl_data->surface, _this->gl_data->context)) { return SDL_SetError("Unable to make EGL context current"); } - return 0; + return true; } -int VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) { EGLBoolean status; status = eglSwapInterval(_this->gl_data->display, interval); if (status == EGL_TRUE) { // Return success to upper level _this->gl_data->swapinterval = interval; - return 0; + return true; } // Failed to set swap interval return SDL_SetError("Unable to set the EGL swap interval"); } -int VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { *interval = _this->gl_data->swapinterval; - return 0; + return true; } -int VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { if (!eglSwapBuffers(_this->gl_data->display, _this->gl_data->surface)) { return SDL_SetError("eglSwapBuffers() failed"); } - return 0; + return true; } -int VITA_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool VITA_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { SDL_VideoData *phdata = _this->internal; EGLBoolean status; @@ -211,7 +211,7 @@ int VITA_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) } } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_VITA diff --git a/src/video/vita/SDL_vitagles_c.h b/src/video/vita/SDL_vitagles_c.h index 750d2bbf7a..c6c43dda2d 100644 --- a/src/video/vita/SDL_vitagles_c.h +++ b/src/video/vita/SDL_vitagles_c.h @@ -39,15 +39,15 @@ typedef struct SDL_GLDriverData } SDL_GLDriverData; extern SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -extern int VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); extern void VITA_GLES_SwapBuffers(SDL_VideoDevice *_this); -extern int VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern void VITA_GLES_UnloadLibrary(SDL_VideoDevice *_this); -extern int VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); #endif // SDL_vitagles_c_h_ diff --git a/src/video/vita/SDL_vitagles_pvr.c b/src/video/vita/SDL_vitagles_pvr.c index bf2d46196e..e178b21bd0 100644 --- a/src/video/vita/SDL_vitagles_pvr.c +++ b/src/video/vita/SDL_vitagles_pvr.c @@ -32,7 +32,7 @@ #define MAX_PATH 256 // vita limits are somehow wrong -int VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { PVRSRV_PSP2_APPHINT hint; const char *default_path = "app0:module"; @@ -71,7 +71,7 @@ SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window return SDL_EGL_CreateContext(_this, window->internal->egl_surface); } -int VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { if (window && context) { return SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context); @@ -80,7 +80,7 @@ int VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLCont } } -int VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_VideoData *videodata = _this->internal; if (videodata->ime_active) { diff --git a/src/video/vita/SDL_vitagles_pvr_c.h b/src/video/vita/SDL_vitagles_pvr_c.h index 9023966eaf..93532870a4 100644 --- a/src/video/vita/SDL_vitagles_pvr_c.h +++ b/src/video/vita/SDL_vitagles_pvr_c.h @@ -24,9 +24,9 @@ #include "SDL_vitavideo.h" -extern int VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); #endif // SDL_vitagles_pvr_c_h_ diff --git a/src/video/vita/SDL_vitamessagebox.c b/src/video/vita/SDL_vitamessagebox.c index c01d497289..d81861750e 100644 --- a/src/video/vita/SDL_vitamessagebox.c +++ b/src/video/vita/SDL_vitamessagebox.c @@ -30,7 +30,7 @@ #include "../../render/vitagxm/SDL_render_vita_gxm_tools.h" #endif // SDL_VIDEO_RENDER_VITA_GXM -int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { #if SDL_VIDEO_RENDER_VITA_GXM SceMsgDialogParam param; @@ -44,7 +44,7 @@ int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) bool setup_minimal_gxm = false; if (messageboxdata->numbuttons > 3) { - return -1; + return false; } SDL_zero(param); @@ -105,7 +105,7 @@ int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) } sceMsgDialogTerm(); } else { - return -1; + return false; } gxm_term_for_common_dialog(); @@ -114,11 +114,11 @@ int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) gxm_minimal_term_for_common_dialog(); } - return 0; + return true; #else (void)messageboxdata; (void)buttonID; - return -1; + return SDL_Unsupported(); #endif } diff --git a/src/video/vita/SDL_vitamessagebox.h b/src/video/vita/SDL_vitamessagebox.h index 7f23cb5b1c..99b190e2d2 100644 --- a/src/video/vita/SDL_vitamessagebox.h +++ b/src/video/vita/SDL_vitamessagebox.h @@ -24,7 +24,7 @@ #ifdef SDL_VIDEO_DRIVER_VITA -extern int VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool VITA_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_VITA diff --git a/src/video/vita/SDL_vitavideo.c b/src/video/vita/SDL_vitavideo.c index 01b2a8fcd8..3e72f1d641 100644 --- a/src/video/vita/SDL_vitavideo.c +++ b/src/video/vita/SDL_vitavideo.c @@ -48,7 +48,7 @@ #define VITA_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define VITA_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define VITA_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -#define VITA_GLES_DeleteContext SDL_EGL_DeleteContext +#define VITA_GLES_DestroyContext SDL_EGL_DestroyContext #endif SDL_Window *Vita_Window; @@ -143,7 +143,7 @@ static SDL_VideoDevice *VITA_Create(void) device->GL_SetSwapInterval = VITA_GLES_SetSwapInterval; device->GL_GetSwapInterval = VITA_GLES_GetSwapInterval; device->GL_SwapWindow = VITA_GLES_SwapWindow; - device->GL_DeleteContext = VITA_GLES_DeleteContext; + device->GL_DestroyContext = VITA_GLES_DestroyContext; #endif device->HasScreenKeyboardSupport = VITA_HasScreenKeyboardSupport; @@ -166,7 +166,7 @@ VideoBootStrap VITA_bootstrap = { /*****************************************************************************/ // SDL Video and Display initialization/handling functions /*****************************************************************************/ -int VITA_VideoInit(SDL_VideoDevice *_this) +bool VITA_VideoInit(SDL_VideoDevice *_this) { SDL_DisplayMode mode; #ifdef SDL_VIDEO_VITA_PVR @@ -202,14 +202,14 @@ int VITA_VideoInit(SDL_VideoDevice *_this) mode.format = SDL_PIXELFORMAT_ABGR8888; if (SDL_AddBasicVideoDisplay(&mode) == 0) { - return -1; + return false; } VITA_InitTouch(); VITA_InitKeyboard(); VITA_InitMouse(); - return 1; + return true; } void VITA_VideoQuit(SDL_VideoDevice *_this) @@ -217,7 +217,7 @@ void VITA_VideoQuit(SDL_VideoDevice *_this) VITA_QuitTouch(); } -int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *wdata; #ifdef SDL_VIDEO_VITA_PVR @@ -230,7 +230,7 @@ int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties // Allocate window internal data wdata = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!wdata) { - return -1; + return false; } // Setup driver data for this window @@ -289,13 +289,13 @@ int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properties SDL_SetKeyboardFocus(window); // Window has been successfully created - return 0; + return true; } void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) { } -int VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { return SDL_Unsupported(); } @@ -320,9 +320,9 @@ void VITA_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window) void VITA_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window) { } -int VITA_SetWindowGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool VITA_SetWindowGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { - return 0; + return true; } void VITA_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/vita/SDL_vitavideo.h b/src/video/vita/SDL_vitavideo.h index 54f1bb844d..f52969dae0 100644 --- a/src/video/vita/SDL_vitavideo.h +++ b/src/video/vita/SDL_vitavideo.h @@ -58,49 +58,49 @@ extern SDL_Window *Vita_Window; /****************************************************************************/ // Display and window functions -int VITA_VideoInit(SDL_VideoDevice *_this); -void VITA_VideoQuit(SDL_VideoDevice *_this); -int VITA_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -int VITA_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); -int VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); -void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -int VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); -int VITA_SetWindowGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); -void VITA_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_VideoInit(SDL_VideoDevice *_this); +extern void VITA_VideoQuit(SDL_VideoDevice *_this); +extern bool VITA_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool VITA_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool VITA_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern void VITA_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern void VITA_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); +extern void VITA_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void VITA_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void VITA_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void VITA_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void VITA_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern void VITA_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_SetWindowGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern void VITA_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); #ifdef SDL_VIDEO_DRIVER_VITA #ifdef SDL_VIDEO_VITA_PVR_OGL // OpenGL functions -int VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); -SDL_GLContext VITA_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -SDL_FunctionPointer VITA_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); +extern bool VITA_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern SDL_GLContext VITA_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); +extern SDL_FunctionPointer VITA_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); #endif // OpenGLES functions -int VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); -SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); -void VITA_GLES_UnloadLibrary(SDL_VideoDevice *_this); -SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -int VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -int VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); -int VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); -int VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -int VITA_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool VITA_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern SDL_FunctionPointer VITA_GLES_GetProcAddress(SDL_VideoDevice *_this, const char *proc); +extern void VITA_GLES_UnloadLibrary(SDL_VideoDevice *_this); +extern SDL_GLContext VITA_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool VITA_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool VITA_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool VITA_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); #endif // VITA on screen keyboard -bool VITA_HasScreenKeyboardSupport(SDL_VideoDevice *_this); -void VITA_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -void VITA_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window); -bool VITA_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_HasScreenKeyboardSupport(SDL_VideoDevice *_this); +extern void VITA_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +extern void VITA_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VITA_IsScreenKeyboardShown(SDL_VideoDevice *_this, SDL_Window *window); -void VITA_PumpEvents(SDL_VideoDevice *_this); +extern void VITA_PumpEvents(SDL_VideoDevice *_this); #endif // SDL_pspvideo_h diff --git a/src/video/vivante/SDL_vivanteopengles.c b/src/video/vivante/SDL_vivanteopengles.c index 03592a5857..fc4b990733 100644 --- a/src/video/vivante/SDL_vivanteopengles.c +++ b/src/video/vivante/SDL_vivanteopengles.c @@ -27,7 +27,7 @@ // EGL implementation of SDL OpenGL support -int VIVANTE_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool VIVANTE_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { SDL_DisplayData *displaydata = SDL_GetDisplayDriverData(SDL_GetPrimaryDisplay()); @@ -35,7 +35,7 @@ int VIVANTE_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) } SDL_EGL_CreateContext_impl(VIVANTE) - SDL_EGL_SwapWindow_impl(VIVANTE) - SDL_EGL_MakeCurrent_impl(VIVANTE) +SDL_EGL_SwapWindow_impl(VIVANTE) +SDL_EGL_MakeCurrent_impl(VIVANTE) #endif // SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL diff --git a/src/video/vivante/SDL_vivanteopengles.h b/src/video/vivante/SDL_vivanteopengles.h index 14a87019d9..e47de3e375 100644 --- a/src/video/vivante/SDL_vivanteopengles.h +++ b/src/video/vivante/SDL_vivanteopengles.h @@ -34,12 +34,12 @@ #define VIVANTE_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define VIVANTE_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define VIVANTE_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -#define VIVANTE_GLES_DeleteContext SDL_EGL_DeleteContext +#define VIVANTE_GLES_DestroyContext SDL_EGL_DestroyContext -extern int VIVANTE_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool VIVANTE_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_GLContext VIVANTE_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int VIVANTE_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int VIVANTE_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool VIVANTE_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool VIVANTE_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); #endif // SDL_VIDEO_DRIVER_VIVANTE && SDL_VIDEO_OPENGL_EGL diff --git a/src/video/vivante/SDL_vivanteplatform.c b/src/video/vivante/SDL_vivanteplatform.c index cce23a874f..b5ad4182fc 100644 --- a/src/video/vivante/SDL_vivanteplatform.c +++ b/src/video/vivante/SDL_vivanteplatform.c @@ -26,9 +26,9 @@ #ifdef VIVANTE_PLATFORM_GENERIC -int VIVANTE_SetupPlatform(SDL_VideoDevice *_this) +bool VIVANTE_SetupPlatform(SDL_VideoDevice *_this) { - return 0; + return true; } char *VIVANTE_GetDisplayName(SDL_VideoDevice *_this) diff --git a/src/video/vivante/SDL_vivanteplatform.h b/src/video/vivante/SDL_vivanteplatform.h index 8422583594..2d9b485597 100644 --- a/src/video/vivante/SDL_vivanteplatform.h +++ b/src/video/vivante/SDL_vivanteplatform.h @@ -35,7 +35,7 @@ #define VIVANTE_PLATFORM_GENERIC #endif -extern int VIVANTE_SetupPlatform(SDL_VideoDevice *_this); +extern bool VIVANTE_SetupPlatform(SDL_VideoDevice *_this); extern char *VIVANTE_GetDisplayName(SDL_VideoDevice *_this); extern void VIVANTE_UpdateDisplayScale(SDL_VideoDevice *_this); extern void VIVANTE_CleanupPlatform(SDL_VideoDevice *_this); diff --git a/src/video/vivante/SDL_vivantevideo.c b/src/video/vivante/SDL_vivantevideo.c index 081f980afe..52aaafcf89 100644 --- a/src/video/vivante/SDL_vivantevideo.c +++ b/src/video/vivante/SDL_vivantevideo.c @@ -87,7 +87,7 @@ static SDL_VideoDevice *VIVANTE_Create(void) device->GL_SetSwapInterval = VIVANTE_GLES_SetSwapInterval; device->GL_GetSwapInterval = VIVANTE_GLES_GetSwapInterval; device->GL_SwapWindow = VIVANTE_GLES_SwapWindow; - device->GL_DeleteContext = VIVANTE_GLES_DeleteContext; + device->GL_DestroyContext = VIVANTE_GLES_DestroyContext; #endif #ifdef SDL_VIDEO_VULKAN @@ -114,7 +114,7 @@ VideoBootStrap VIVANTE_bootstrap = { // SDL Video and Display initialization/handling functions /*****************************************************************************/ -static int VIVANTE_AddVideoDisplays(SDL_VideoDevice *_this) +static bool VIVANTE_AddVideoDisplays(SDL_VideoDevice *_this) { SDL_VideoData *videodata = _this->internal; SDL_VideoDisplay display; @@ -125,7 +125,7 @@ static int VIVANTE_AddVideoDisplays(SDL_VideoDevice *_this) data = (SDL_DisplayData *)SDL_calloc(1, sizeof(SDL_DisplayData)); if (!data) { - return -1; + return false; } SDL_zero(mode); @@ -158,12 +158,12 @@ static int VIVANTE_AddVideoDisplays(SDL_VideoDevice *_this) display.desktop_mode = mode; display.internal = data; if (SDL_AddVideoDisplay(&display, false) == 0) { - return -1; + return false; } - return 0; + return true; } -int VIVANTE_VideoInit(SDL_VideoDevice *_this) +bool VIVANTE_VideoInit(SDL_VideoDevice *_this) { SDL_VideoData *videodata = _this->internal; @@ -177,13 +177,13 @@ int VIVANTE_VideoInit(SDL_VideoDevice *_this) if (!videodata->egl_handle) { videodata->egl_handle = SDL_LoadObject("libEGL.so"); if (!videodata->egl_handle) { - return -1; + return false; } } #define LOAD_FUNC(TYPE, NAME) \ videodata->NAME = (TYPE)SDL_LoadFunction(videodata->egl_handle, #NAME); \ if (!videodata->NAME) \ - return -1; + return false; LOAD_FUNC(EGLNativeDisplayType (EGLAPIENTRY *)(void *), fbGetDisplay); LOAD_FUNC(EGLNativeDisplayType (EGLAPIENTRY *)(int), fbGetDisplayByIndex); @@ -196,23 +196,23 @@ int VIVANTE_VideoInit(SDL_VideoDevice *_this) LOAD_FUNC(void (EGLAPIENTRY *)(EGLNativeWindowType), fbDestroyWindow); #endif - if (VIVANTE_SetupPlatform(_this) < 0) { - return -1; + if (!VIVANTE_SetupPlatform(_this)) { + return false; } - if (VIVANTE_AddVideoDisplays(_this) < 0) { - return -1; + if (!VIVANTE_AddVideoDisplays(_this)) { + return false; } VIVANTE_UpdateDisplayScale(_this); #ifdef SDL_INPUT_LINUXEV - if (SDL_EVDEV_Init() < 0) { - return -1; + if (!SDL_EVDEV_Init()) { + return false; } #endif - return 0; + return true; } void VIVANTE_VideoQuit(SDL_VideoDevice *_this) @@ -238,7 +238,7 @@ void VIVANTE_VideoQuit(SDL_VideoDevice *_this) #endif } -int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_VideoData *videodata = _this->internal; SDL_DisplayData *displaydata; @@ -249,7 +249,7 @@ int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert // Allocate window internal data data = (SDL_WindowData *)SDL_calloc(1, sizeof(SDL_WindowData)); if (!data) { - return -1; + return false; } // Setup driver data for this window @@ -281,7 +281,7 @@ int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert #endif // Window has been successfully created - return 0; + return true; } void VIVANTE_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -318,7 +318,7 @@ void VIVANTE_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) #endif } -int VIVANTE_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool VIVANTE_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { // FIXME return SDL_Unsupported(); diff --git a/src/video/vivante/SDL_vivantevideo.h b/src/video/vivante/SDL_vivantevideo.h index adc9e8ab36..e4bd0c9e92 100644 --- a/src/video/vivante/SDL_vivantevideo.h +++ b/src/video/vivante/SDL_vivantevideo.h @@ -68,13 +68,13 @@ struct SDL_WindowData /****************************************************************************/ // Display and window functions -int VIVANTE_VideoInit(SDL_VideoDevice *_this); +bool VIVANTE_VideoInit(SDL_VideoDevice *_this); void VIVANTE_VideoQuit(SDL_VideoDevice *_this); -int VIVANTE_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -int VIVANTE_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); -int VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +bool VIVANTE_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +bool VIVANTE_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +bool VIVANTE_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); void VIVANTE_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -int VIVANTE_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +bool VIVANTE_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); void VIVANTE_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); void VIVANTE_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); void VIVANTE_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/vivante/SDL_vivantevulkan.c b/src/video/vivante/SDL_vivantevulkan.c index 24dfe64ab6..c182153930 100644 --- a/src/video/vivante/SDL_vivantevulkan.c +++ b/src/video/vivante/SDL_vivantevulkan.c @@ -34,7 +34,7 @@ #include "SDL_vivantevulkan.h" -int VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 i, extensionCount = 0; @@ -62,7 +62,7 @@ int VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) _this->vulkan_config.loader_handle = SDL_LoadObject(path); } if (!_this->vulkan_config.loader_handle) { - return -1; + return false; } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); @@ -101,12 +101,12 @@ int VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_DISPLAY_EXTENSION_NAME "extension"); goto fail; } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void VIVANTE_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -123,13 +123,13 @@ char const* const* VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, static const char *const extensionsForVivante[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_DISPLAY_EXTENSION_NAME }; - if(count) { + if (count) { *count = SDL_arraysize(extensionsForVivante); } return extensionsForVivante; } -int VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, diff --git a/src/video/vivante/SDL_vivantevulkan.h b/src/video/vivante/SDL_vivantevulkan.h index 84ad4de43e..cc698792b9 100644 --- a/src/video/vivante/SDL_vivantevulkan.h +++ b/src/video/vivante/SDL_vivantevulkan.h @@ -33,16 +33,15 @@ #if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_VIVANTE) -int VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void VIVANTE_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this, +extern bool VIVANTE_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void VIVANTE_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* VIVANTE_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool VIVANTE_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); -void VIVANTE_Vulkan_DestroySurface(SDL_VideoDevice *_this, +extern void VIVANTE_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); diff --git a/src/video/wayland/SDL_waylandclipboard.c b/src/video/wayland/SDL_waylandclipboard.c index 2d92089477..9f0c238310 100644 --- a/src/video/wayland/SDL_waylandclipboard.c +++ b/src/video/wayland/SDL_waylandclipboard.c @@ -29,11 +29,11 @@ #include "../../events/SDL_events_c.h" -int Wayland_SetClipboardData(SDL_VideoDevice *_this) +bool Wayland_SetClipboardData(SDL_VideoDevice *_this) { SDL_VideoData *video_data = _this->internal; SDL_WaylandDataDevice *data_device = NULL; - int status = 0; + bool result = true; if (video_data->input && video_data->input->data_device) { data_device = video_data->input->data_device; @@ -42,16 +42,16 @@ int Wayland_SetClipboardData(SDL_VideoDevice *_this) SDL_WaylandDataSource *source = Wayland_data_source_create(_this); Wayland_data_source_set_callback(source, _this->clipboard_callback, _this->clipboard_userdata, _this->clipboard_sequence); - status = Wayland_data_device_set_selection(data_device, source, (const char **)_this->clipboard_mime_types, _this->num_clipboard_mime_types); - if (status != 0) { + result = Wayland_data_device_set_selection(data_device, source, (const char **)_this->clipboard_mime_types, _this->num_clipboard_mime_types); + if (!result) { Wayland_data_source_destroy(source); } } else { - status = Wayland_data_device_clear_selection(data_device); + result = Wayland_data_device_clear_selection(data_device); } } - return status; + return result; } void *Wayland_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length) @@ -103,11 +103,11 @@ const char **Wayland_GetTextMimeTypes(SDL_VideoDevice *_this, size_t *num_mime_t return text_mime_types; } -int Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text) +bool Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text) { SDL_VideoData *video_data = _this->internal; SDL_WaylandPrimarySelectionDevice *primary_selection_device = NULL; - int status = -1; + bool result; if (video_data->input && video_data->input->primary_selection_device) { primary_selection_device = video_data->input->primary_selection_device; @@ -115,19 +115,20 @@ int Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text) SDL_WaylandPrimarySelectionSource *source = Wayland_primary_selection_source_create(_this); Wayland_primary_selection_source_set_callback(source, SDL_ClipboardTextCallback, SDL_strdup(text)); - status = Wayland_primary_selection_device_set_selection(primary_selection_device, + result = Wayland_primary_selection_device_set_selection(primary_selection_device, source, text_mime_types, SDL_arraysize(text_mime_types)); - if (status != 0) { + if (!result) { Wayland_primary_selection_source_destroy(source); } } else { - status = Wayland_primary_selection_device_clear_selection(primary_selection_device); + result = Wayland_primary_selection_device_clear_selection(primary_selection_device); } + } else { + result = SDL_SetError("Primary selection not supported"); } - - return status; + return result; } char *Wayland_GetPrimarySelectionText(SDL_VideoDevice *_this) diff --git a/src/video/wayland/SDL_waylandclipboard.h b/src/video/wayland/SDL_waylandclipboard.h index d2a12ce31d..ccc6252a6c 100644 --- a/src/video/wayland/SDL_waylandclipboard.h +++ b/src/video/wayland/SDL_waylandclipboard.h @@ -24,10 +24,10 @@ #define SDL_waylandclipboard_h_ extern const char **Wayland_GetTextMimeTypes(SDL_VideoDevice *_this, size_t *num_mime_types); -extern int Wayland_SetClipboardData(SDL_VideoDevice *_this); +extern bool Wayland_SetClipboardData(SDL_VideoDevice *_this); extern void *Wayland_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length); extern bool Wayland_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type); -extern int Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text); +extern bool Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text); extern char *Wayland_GetPrimarySelectionText(SDL_VideoDevice *_this); extern bool Wayland_HasPrimarySelectionText(SDL_VideoDevice *_this); diff --git a/src/video/wayland/SDL_waylanddatamanager.c b/src/video/wayland/SDL_waylanddatamanager.c index c6a1a8bbd9..dc04af5b5c 100644 --- a/src/video/wayland/SDL_waylanddatamanager.c +++ b/src/video/wayland/SDL_waylanddatamanager.c @@ -146,11 +146,11 @@ static SDL_MimeDataList *mime_data_list_find(struct wl_list *list, return found; } -static int mime_data_list_add(struct wl_list *list, +static bool mime_data_list_add(struct wl_list *list, const char *mime_type, const void *buffer, size_t length) { - int status = 0; + bool result = true; size_t mime_type_length = 0; SDL_MimeDataList *mime_data = NULL; void *internal_buffer = NULL; @@ -158,7 +158,7 @@ static int mime_data_list_add(struct wl_list *list, if (buffer) { internal_buffer = SDL_malloc(length); if (!internal_buffer) { - return -1; + return false; } SDL_memcpy(internal_buffer, buffer, length); } @@ -168,14 +168,14 @@ static int mime_data_list_add(struct wl_list *list, if (!mime_data) { mime_data = SDL_calloc(1, sizeof(*mime_data)); if (!mime_data) { - status = -1; + result = false; } else { WAYLAND_wl_list_insert(list, &(mime_data->link)); mime_type_length = SDL_strlen(mime_type) + 1; mime_data->mime_type = SDL_malloc(mime_type_length); if (!mime_data->mime_type) { - status = -1; + result = false; } else { SDL_memcpy(mime_data->mime_type, mime_type, mime_type_length); } @@ -192,7 +192,7 @@ static int mime_data_list_add(struct wl_list *list, SDL_free(internal_buffer); } - return status; + return result; } static void mime_data_list_free(struct wl_list *list) @@ -423,13 +423,13 @@ void *Wayland_primary_selection_offer_receive(SDL_WaylandPrimarySelectionOffer * return buffer; } -int Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, +bool Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, const char *mime_type) { return mime_data_list_add(&offer->mimes, mime_type, NULL, 0); } -int Wayland_primary_selection_offer_add_mime(SDL_WaylandPrimarySelectionOffer *offer, +bool Wayland_primary_selection_offer_add_mime(SDL_WaylandPrimarySelectionOffer *offer, const char *mime_type) { return mime_data_list_add(&offer->mimes, mime_type, NULL, 0); @@ -475,46 +475,46 @@ void Wayland_primary_selection_offer_destroy(SDL_WaylandPrimarySelectionOffer *o } } -int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *data_device) +bool Wayland_data_device_clear_selection(SDL_WaylandDataDevice *data_device) { - int status = 0; + bool result = true; if (!data_device || !data_device->data_device) { - status = SDL_SetError("Invalid Data Device"); + result = SDL_SetError("Invalid Data Device"); } else if (data_device->selection_source) { wl_data_device_set_selection(data_device->data_device, NULL, 0); Wayland_data_source_destroy(data_device->selection_source); data_device->selection_source = NULL; } - return status; + return result; } -int Wayland_primary_selection_device_clear_selection(SDL_WaylandPrimarySelectionDevice *primary_selection_device) +bool Wayland_primary_selection_device_clear_selection(SDL_WaylandPrimarySelectionDevice *primary_selection_device) { - int status = 0; + bool result = true; if (!primary_selection_device || !primary_selection_device->primary_selection_device) { - status = SDL_SetError("Invalid Primary Selection Device"); + result = SDL_SetError("Invalid Primary Selection Device"); } else if (primary_selection_device->selection_source) { zwp_primary_selection_device_v1_set_selection(primary_selection_device->primary_selection_device, NULL, 0); Wayland_primary_selection_source_destroy(primary_selection_device->selection_source); primary_selection_device->selection_source = NULL; } - return status; + return result; } -int Wayland_data_device_set_selection(SDL_WaylandDataDevice *data_device, - SDL_WaylandDataSource *source, - const char **mime_types, - size_t mime_count) +bool Wayland_data_device_set_selection(SDL_WaylandDataDevice *data_device, + SDL_WaylandDataSource *source, + const char **mime_types, + size_t mime_count) { - int status = 0; + bool result = true; if (!data_device) { - status = SDL_SetError("Invalid Data Device"); + result = SDL_SetError("Invalid Data Device"); } else if (!source) { - status = SDL_SetError("Invalid source"); + result = SDL_SetError("Invalid source"); } else { size_t index = 0; const char *mime_type; @@ -527,7 +527,7 @@ int Wayland_data_device_set_selection(SDL_WaylandDataDevice *data_device, if (index == 0) { Wayland_data_device_clear_selection(data_device); - status = SDL_SetError("No mime data"); + result = SDL_SetError("No mime data"); } else { // Only set if there is a valid serial if not set it later if (data_device->selection_serial != 0) { @@ -543,20 +543,20 @@ int Wayland_data_device_set_selection(SDL_WaylandDataDevice *data_device, } } - return status; + return result; } -int Wayland_primary_selection_device_set_selection(SDL_WaylandPrimarySelectionDevice *primary_selection_device, +bool Wayland_primary_selection_device_set_selection(SDL_WaylandPrimarySelectionDevice *primary_selection_device, SDL_WaylandPrimarySelectionSource *source, const char **mime_types, size_t mime_count) { - int status = 0; + bool result = true; if (!primary_selection_device) { - status = SDL_SetError("Invalid Primary Selection Device"); + result = SDL_SetError("Invalid Primary Selection Device"); } else if (!source) { - status = SDL_SetError("Invalid source"); + result = SDL_SetError("Invalid source"); } else { size_t index = 0; const char *mime_type = mime_types[index]; @@ -568,7 +568,7 @@ int Wayland_primary_selection_device_set_selection(SDL_WaylandPrimarySelectionDe if (index == 0) { Wayland_primary_selection_device_clear_selection(primary_selection_device); - status = SDL_SetError("No mime data"); + result = SDL_SetError("No mime data"); } else { // Only set if there is a valid serial if not set it later if (primary_selection_device->selection_serial != 0) { @@ -584,16 +584,12 @@ int Wayland_primary_selection_device_set_selection(SDL_WaylandPrimarySelectionDe } } - return status; + return result; } -int Wayland_data_device_set_serial(SDL_WaylandDataDevice *data_device, - uint32_t serial) +void Wayland_data_device_set_serial(SDL_WaylandDataDevice *data_device, uint32_t serial) { - int status = -1; if (data_device) { - status = 0; - // If there was no serial and there is a pending selection set it now. if (data_device->selection_serial == 0 && data_device->selection_source) { wl_data_device_set_selection(data_device->data_device, @@ -603,17 +599,12 @@ int Wayland_data_device_set_serial(SDL_WaylandDataDevice *data_device, data_device->selection_serial = serial; } - - return status; } -int Wayland_primary_selection_device_set_serial(SDL_WaylandPrimarySelectionDevice *primary_selection_device, - uint32_t serial) +void Wayland_primary_selection_device_set_serial(SDL_WaylandPrimarySelectionDevice *primary_selection_device, + uint32_t serial) { - int status = -1; if (primary_selection_device) { - status = 0; - // If there was no serial and there is a pending selection set it now. if (primary_selection_device->selection_serial == 0 && primary_selection_device->selection_source) { zwp_primary_selection_device_v1_set_selection(primary_selection_device->primary_selection_device, @@ -623,8 +614,6 @@ int Wayland_primary_selection_device_set_serial(SDL_WaylandPrimarySelectionDevic primary_selection_device->selection_serial = serial; } - - return status; } #endif // SDL_VIDEO_DRIVER_WAYLAND diff --git a/src/video/wayland/SDL_waylanddatamanager.h b/src/video/wayland/SDL_waylanddatamanager.h index 7686875701..7aea8d5691 100644 --- a/src/video/wayland/SDL_waylanddatamanager.h +++ b/src/video/wayland/SDL_waylanddatamanager.h @@ -137,26 +137,26 @@ extern bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer, const char *mime_type); extern bool Wayland_primary_selection_offer_has_mime(SDL_WaylandPrimarySelectionOffer *offer, const char *mime_type); -extern int Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, +extern bool Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer, const char *mime_type); -extern int Wayland_primary_selection_offer_add_mime(SDL_WaylandPrimarySelectionOffer *offer, +extern bool Wayland_primary_selection_offer_add_mime(SDL_WaylandPrimarySelectionOffer *offer, const char *mime_type); extern void Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer); extern void Wayland_primary_selection_offer_destroy(SDL_WaylandPrimarySelectionOffer *offer); // Clipboard / Primary Selection -extern int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device); -extern int Wayland_primary_selection_device_clear_selection(SDL_WaylandPrimarySelectionDevice *device); -extern int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, - SDL_WaylandDataSource *source, - const char **mime_types, - size_t mime_count); -extern int Wayland_primary_selection_device_set_selection(SDL_WaylandPrimarySelectionDevice *device, - SDL_WaylandPrimarySelectionSource *source, - const char **mime_types, - size_t mime_count); -extern int Wayland_data_device_set_serial(SDL_WaylandDataDevice *device, - uint32_t serial); -extern int Wayland_primary_selection_device_set_serial(SDL_WaylandPrimarySelectionDevice *device, - uint32_t serial); +extern bool Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device); +extern bool Wayland_primary_selection_device_clear_selection(SDL_WaylandPrimarySelectionDevice *device); +extern bool Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, + SDL_WaylandDataSource *source, + const char **mime_types, + size_t mime_count); +extern bool Wayland_primary_selection_device_set_selection(SDL_WaylandPrimarySelectionDevice *device, + SDL_WaylandPrimarySelectionSource *source, + const char **mime_types, + size_t mime_count); +extern void Wayland_data_device_set_serial(SDL_WaylandDataDevice *device, + uint32_t serial); +extern void Wayland_primary_selection_device_set_serial(SDL_WaylandPrimarySelectionDevice *device, + uint32_t serial); #endif // SDL_waylanddatamanager_h_ diff --git a/src/video/wayland/SDL_waylanddyn.c b/src/video/wayland/SDL_waylanddyn.c index 6a60e9d8f7..bee980f06b 100644 --- a/src/video/wayland/SDL_waylanddyn.c +++ b/src/video/wayland/SDL_waylanddyn.c @@ -123,9 +123,9 @@ void SDL_WAYLAND_UnloadSymbols(void) } // returns non-zero if all needed symbols were loaded. -int SDL_WAYLAND_LoadSymbols(void) +bool SDL_WAYLAND_LoadSymbols(void) { - int rc = 1; // always succeed if not using Dynamic WAYLAND stuff. + bool result = true; // always succeed if not using Dynamic WAYLAND stuff. // deal with multiple modules (dga, wayland, etc) needing these symbols... if (wayland_load_refcount++ == 0) { @@ -156,7 +156,7 @@ int SDL_WAYLAND_LoadSymbols(void) } else { // in case something got loaded... SDL_WAYLAND_UnloadSymbols(); - rc = 0; + result = false; } #else // no dynamic WAYLAND @@ -170,7 +170,7 @@ int SDL_WAYLAND_LoadSymbols(void) #endif } - return rc; + return result; } #endif // SDL_VIDEO_DRIVER_WAYLAND diff --git a/src/video/wayland/SDL_waylanddyn.h b/src/video/wayland/SDL_waylanddyn.h index b7ff68dab4..eb14368b73 100644 --- a/src/video/wayland/SDL_waylanddyn.h +++ b/src/video/wayland/SDL_waylanddyn.h @@ -71,8 +71,8 @@ enum libdecor_window_state; extern "C" { #endif -int SDL_WAYLAND_LoadSymbols(void); -void SDL_WAYLAND_UnloadSymbols(void); +extern bool SDL_WAYLAND_LoadSymbols(void); +extern void SDL_WAYLAND_UnloadSymbols(void); #define SDL_WAYLAND_MODULE(modname) extern int SDL_WAYLAND_HAVE_##modname; #define SDL_WAYLAND_SYM(rc, fn, params) \ diff --git a/src/video/wayland/SDL_waylandevents.c b/src/video/wayland/SDL_waylandevents.c index a4806da4eb..38dc41918f 100644 --- a/src/video/wayland/SDL_waylandevents.c +++ b/src/video/wayland/SDL_waylandevents.c @@ -357,7 +357,7 @@ void Wayland_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window) static int dispatch_queued_events(SDL_VideoData *viddata) { - int ret; + int rc; /* * NOTE: When reconnection is implemented, check if libdecor needs to be @@ -369,8 +369,8 @@ static int dispatch_queued_events(SDL_VideoData *viddata) } #endif - ret = WAYLAND_wl_display_dispatch_pending(viddata->display); - return ret >= 0 ? 1 : ret; + rc = WAYLAND_wl_display_dispatch_pending(viddata->display); + return rc >= 0 ? 1 : rc; } int Wayland_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS) @@ -3007,13 +3007,13 @@ static const struct zwp_locked_pointer_v1_listener locked_pointer_listener = { locked_pointer_unlocked, }; -int Wayland_input_lock_pointer(struct SDL_WaylandInput *input, SDL_Window *window) +bool Wayland_input_lock_pointer(struct SDL_WaylandInput *input, SDL_Window *window) { SDL_WindowData *w = window->internal; SDL_VideoData *d = input->display; if (!d->pointer_constraints || !input->pointer) { - return -1; + return false; } if (!w->locked_pointer) { @@ -3032,10 +3032,10 @@ int Wayland_input_lock_pointer(struct SDL_WaylandInput *input, SDL_Window *windo window); } - return 0; + return true; } -int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input, SDL_Window *window) +bool Wayland_input_unlock_pointer(struct SDL_WaylandInput *input, SDL_Window *window) { SDL_WindowData *w = window->internal; @@ -3047,7 +3047,7 @@ int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input, SDL_Window *win // Restore existing pointer confinement. Wayland_input_confine_pointer(input, window); - return 0; + return true; } static void pointer_confine_destroy(SDL_Window *window) @@ -3059,7 +3059,7 @@ static void pointer_confine_destroy(SDL_Window *window) } } -int Wayland_input_enable_relative_pointer(struct SDL_WaylandInput *input) +bool Wayland_input_enable_relative_pointer(struct SDL_WaylandInput *input) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *d = input->display; @@ -3067,15 +3067,15 @@ int Wayland_input_enable_relative_pointer(struct SDL_WaylandInput *input) struct zwp_relative_pointer_v1 *relative_pointer; if (!d->relative_pointer_manager) { - return -1; + return false; } if (!d->pointer_constraints) { - return -1; + return false; } if (!input->pointer) { - return -1; + return false; } /* If we have a pointer confine active, we must destroy it here because @@ -3099,10 +3099,10 @@ int Wayland_input_enable_relative_pointer(struct SDL_WaylandInput *input) d->relative_mouse_mode = 1; - return 0; + return true; } -int Wayland_input_disable_relative_pointer(struct SDL_WaylandInput *input) +bool Wayland_input_disable_relative_pointer(struct SDL_WaylandInput *input) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *d = input->display; @@ -3123,7 +3123,7 @@ int Wayland_input_disable_relative_pointer(struct SDL_WaylandInput *input) Wayland_input_confine_pointer(input, window); } - return 0; + return true; } static void confined_pointer_confined(void *data, @@ -3141,7 +3141,7 @@ static const struct zwp_confined_pointer_v1_listener confined_pointer_listener = confined_pointer_unconfined, }; -int Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *window) +bool Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *window) { SDL_WindowData *w = window->internal; SDL_VideoData *d = input->display; @@ -3165,12 +3165,12 @@ int Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *wi * the pointer is unlocked. */ if (d->relative_mouse_mode) { - return 0; + return true; } // Don't confine the pointer if it shouldn't be confined. if (SDL_RectEmpty(&window->mouse_rect) && !(window->flags & SDL_WINDOW_MOUSE_GRABBED)) { - return 0; + return true; } if (SDL_RectEmpty(&window->mouse_rect)) { @@ -3206,16 +3206,16 @@ int Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *wi } w->confined_pointer = confined_pointer; - return 0; + return true; } -int Wayland_input_unconfine_pointer(struct SDL_WaylandInput *input, SDL_Window *window) +bool Wayland_input_unconfine_pointer(struct SDL_WaylandInput *input, SDL_Window *window) { pointer_confine_destroy(window); - return 0; + return true; } -int Wayland_input_grab_keyboard(SDL_Window *window, struct SDL_WaylandInput *input) +bool Wayland_input_grab_keyboard(SDL_Window *window, struct SDL_WaylandInput *input) { SDL_WindowData *w = window->internal; SDL_VideoData *d = input->display; @@ -3225,7 +3225,7 @@ int Wayland_input_grab_keyboard(SDL_Window *window, struct SDL_WaylandInput *inp } if (w->key_inhibitor) { - return 0; + return true; } w->key_inhibitor = @@ -3233,10 +3233,10 @@ int Wayland_input_grab_keyboard(SDL_Window *window, struct SDL_WaylandInput *inp w->surface, input->seat); - return 0; + return true; } -int Wayland_input_ungrab_keyboard(SDL_Window *window) +bool Wayland_input_ungrab_keyboard(SDL_Window *window) { SDL_WindowData *w = window->internal; @@ -3245,7 +3245,7 @@ int Wayland_input_ungrab_keyboard(SDL_Window *window) w->key_inhibitor = NULL; } - return 0; + return true; } void Wayland_UpdateImplicitGrabSerial(struct SDL_WaylandInput *input, Uint32 serial) diff --git a/src/video/wayland/SDL_waylandevents_c.h b/src/video/wayland/SDL_waylandevents_c.h index 36b2e377f1..c5741a5e20 100644 --- a/src/video/wayland/SDL_waylandevents_c.h +++ b/src/video/wayland/SDL_waylandevents_c.h @@ -162,17 +162,17 @@ extern void Wayland_create_text_input(SDL_VideoData *d); extern void Wayland_input_initialize_seat(SDL_VideoData *d); extern void Wayland_display_destroy_input(SDL_VideoData *d); -extern int Wayland_input_enable_relative_pointer(struct SDL_WaylandInput *input); -extern int Wayland_input_disable_relative_pointer(struct SDL_WaylandInput *input); +extern bool Wayland_input_enable_relative_pointer(struct SDL_WaylandInput *input); +extern bool Wayland_input_disable_relative_pointer(struct SDL_WaylandInput *input); -extern int Wayland_input_lock_pointer(struct SDL_WaylandInput *input, SDL_Window *window); -extern int Wayland_input_unlock_pointer(struct SDL_WaylandInput *input, SDL_Window *window); +extern bool Wayland_input_lock_pointer(struct SDL_WaylandInput *input, SDL_Window *window); +extern bool Wayland_input_unlock_pointer(struct SDL_WaylandInput *input, SDL_Window *window); -extern int Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *window); -extern int Wayland_input_unconfine_pointer(struct SDL_WaylandInput *input, SDL_Window *window); +extern bool Wayland_input_confine_pointer(struct SDL_WaylandInput *input, SDL_Window *window); +extern bool Wayland_input_unconfine_pointer(struct SDL_WaylandInput *input, SDL_Window *window); -extern int Wayland_input_grab_keyboard(SDL_Window *window, struct SDL_WaylandInput *input); -extern int Wayland_input_ungrab_keyboard(SDL_Window *window); +extern bool Wayland_input_grab_keyboard(SDL_Window *window, struct SDL_WaylandInput *input); +extern bool Wayland_input_ungrab_keyboard(SDL_Window *window); extern void Wayland_input_init_tablet_support(struct SDL_WaylandInput *input, struct zwp_tablet_manager_v2 *tablet_manager); extern void Wayland_input_quit_tablet_support(struct SDL_WaylandInput *input); diff --git a/src/video/wayland/SDL_waylandkeyboard.c b/src/video/wayland/SDL_waylandkeyboard.c index 797d83d62e..bb7be9b525 100644 --- a/src/video/wayland/SDL_waylandkeyboard.c +++ b/src/video/wayland/SDL_waylandkeyboard.c @@ -28,7 +28,7 @@ #include "../../events/SDL_keyboard_c.h" #include "text-input-unstable-v3-client-protocol.h" -int Wayland_InitKeyboard(SDL_VideoDevice *_this) +bool Wayland_InitKeyboard(SDL_VideoDevice *_this) { #ifdef SDL_USE_IME SDL_VideoData *internal = _this->internal; @@ -38,7 +38,7 @@ int Wayland_InitKeyboard(SDL_VideoDevice *_this) #endif SDL_SetScancodeName(SDL_SCANCODE_APPLICATION, "Menu"); - return 0; + return true; } void Wayland_QuitKeyboard(SDL_VideoDevice *_this) @@ -51,7 +51,7 @@ void Wayland_QuitKeyboard(SDL_VideoDevice *_this) #endif } -int Wayland_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) +bool Wayland_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { SDL_VideoData *internal = _this->internal; struct SDL_WaylandInput *input = internal->input; @@ -144,7 +144,7 @@ int Wayland_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Prope return Wayland_UpdateTextInputArea(_this, window); } -int Wayland_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) +bool Wayland_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) { SDL_VideoData *internal = _this->internal; struct SDL_WaylandInput *input = internal->input; @@ -165,10 +165,10 @@ int Wayland_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) // Reset compose state so composite and dead keys don't carry over WAYLAND_xkb_compose_state_reset(input->xkb.compose_state); } - return 0; + return true; } -int Wayland_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) +bool Wayland_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) { SDL_VideoData *internal = _this->internal; if (internal->text_input_manager) { @@ -191,7 +191,7 @@ int Wayland_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) SDL_IME_UpdateTextInputArea(window); } #endif - return 0; + return true; } bool Wayland_HasScreenKeyboardSupport(SDL_VideoDevice *_this) diff --git a/src/video/wayland/SDL_waylandkeyboard.h b/src/video/wayland/SDL_waylandkeyboard.h index c34ca0a509..d148cf1f33 100644 --- a/src/video/wayland/SDL_waylandkeyboard.h +++ b/src/video/wayland/SDL_waylandkeyboard.h @@ -30,11 +30,11 @@ typedef struct SDL_WaylandTextInput bool has_preedit; } SDL_WaylandTextInput; -extern int Wayland_InitKeyboard(SDL_VideoDevice *_this); +extern bool Wayland_InitKeyboard(SDL_VideoDevice *_this); extern void Wayland_QuitKeyboard(SDL_VideoDevice *_this); -extern int Wayland_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -extern int Wayland_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Wayland_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +extern bool Wayland_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Wayland_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); extern bool Wayland_HasScreenKeyboardSupport(SDL_VideoDevice *_this); #endif // SDL_waylandkeyboard_h_ diff --git a/src/video/wayland/SDL_waylandmessagebox.c b/src/video/wayland/SDL_waylandmessagebox.c index 5e5fc01e70..7507f3a884 100644 --- a/src/video/wayland/SDL_waylandmessagebox.c +++ b/src/video/wayland/SDL_waylandmessagebox.c @@ -36,7 +36,7 @@ #define MAX_BUTTONS 8 // Maximum number of buttons supported -static int run_zenity(const char **args, int fd_pipe[2]) +static bool run_zenity(const char **args, int fd_pipe[2]) { int status; pid_t pid1; @@ -70,11 +70,11 @@ static int run_zenity(const char **args, int fd_pipe[2]) return SDL_SetError("zenity reported error or failed to launch: %d", WEXITSTATUS(status)); } - return 0; // success! + return true; // success! } } -static int get_zenity_version(int *major, int *minor) +static bool get_zenity_version(int *major, int *minor) { int fd_pipe[2]; // fd_pipe[0]: read end of pipe, fd_pipe[1]: write end of pipe const char *argv[] = { "zenity", "--version", NULL }; @@ -123,15 +123,15 @@ static int get_zenity_version(int *major, int *minor) *minor = 0; } - return 0; // success + return true; // success } close(fd_pipe[0]); close(fd_pipe[1]); - return -1; // run_zenity should've called SDL_SetError() + return false; // run_zenity should've called SDL_SetError() } -int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { int fd_pipe[2]; // fd_pipe[0]: read end of pipe, fd_pipe[1]: write end of pipe int zenity_major = 0, zenity_minor = 0, output_len = 0; @@ -153,8 +153,8 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button } // get zenity version so we know which arg to use - if (get_zenity_version(&zenity_major, &zenity_minor) != 0) { - return -1; // get_zenity_version() calls SDL_SetError(), so message is already set + if (!get_zenity_version(&zenity_major, &zenity_minor)) { + return false; // get_zenity_version() calls SDL_SetError(), so message is already set } if (pipe(fd_pipe) != 0) { // create a pipe @@ -208,7 +208,7 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button } argv[argc] = NULL; - if (run_zenity(argv, fd_pipe) == 0) { + if (run_zenity(argv, fd_pipe)) { FILE *outputfp = NULL; char *output = NULL; char *tmp = NULL; @@ -217,14 +217,14 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button if (!buttonID) { // if we don't need buttonID, we can return immediately close(fd_pipe[0]); - return 0; // success + return true; // success } *buttonID = -1; output = SDL_malloc(output_len + 1); if (!output) { close(fd_pipe[0]); - return -1; + return false; } output[0] = '\0'; @@ -239,7 +239,7 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button if ((!tmp) || (*tmp == '\0') || (*tmp == '\n')) { SDL_free(output); - return 0; // User simply closed the dialog + return true; // User simply closed the dialog } // It likes to add a newline... @@ -259,12 +259,12 @@ int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *button } SDL_free(output); - return 0; // success! + return true; // success! } close(fd_pipe[0]); close(fd_pipe[1]); - return -1; // run_zenity() calls SDL_SetError(), so message is already set + return false; // run_zenity() calls SDL_SetError(), so message is already set } #endif // SDL_VIDEO_DRIVER_WAYLAND diff --git a/src/video/wayland/SDL_waylandmessagebox.h b/src/video/wayland/SDL_waylandmessagebox.h index ad844066de..43992285dd 100644 --- a/src/video/wayland/SDL_waylandmessagebox.h +++ b/src/video/wayland/SDL_waylandmessagebox.h @@ -24,7 +24,7 @@ #ifdef SDL_VIDEO_DRIVER_WAYLAND -extern int Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool Wayland_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_WAYLAND diff --git a/src/video/wayland/SDL_waylandmouse.c b/src/video/wayland/SDL_waylandmouse.c index 3780b2c97a..39506ef51d 100644 --- a/src/video/wayland/SDL_waylandmouse.c +++ b/src/video/wayland/SDL_waylandmouse.c @@ -43,7 +43,7 @@ static SDL_Cursor *sys_cursors[SDL_HITTEST_RESIZE_LEFT + 1]; -static int Wayland_SetRelativeMouseMode(bool enabled); +static bool Wayland_SetRelativeMouseMode(bool enabled); typedef struct { @@ -465,7 +465,7 @@ static Wayland_CachedCustomCursor *Wayland_GetCachedCustomCursor(SDL_Cursor *cur } // Allocate shared memory buffer for this cursor - if (Wayland_AllocSHMBuffer(surface->w, surface->h, &cache->shmBuffer) != 0) { + if (!Wayland_AllocSHMBuffer(surface->w, surface->h, &cache->shmBuffer)) { SDL_free(cache); SDL_DestroySurface(surface); return NULL; @@ -669,7 +669,7 @@ static void Wayland_SetSystemCursorShape(struct SDL_WaylandInput *input, SDL_Sys wp_cursor_shape_device_v1_set_shape(input->cursor_shape, input->pointer_enter_serial, shape); } -static int Wayland_ShowCursor(SDL_Cursor *cursor) +static bool Wayland_ShowCursor(SDL_Cursor *cursor) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *d = vd->internal; @@ -680,7 +680,7 @@ static int Wayland_ShowCursor(SDL_Cursor *cursor) int dst_height = 0; if (!pointer) { - return -1; + return false; } // Stop the frame callback for old animated cursors. @@ -698,11 +698,11 @@ static int Wayland_ShowCursor(SDL_Cursor *cursor) Wayland_SetSystemCursorShape(input, data->cursor_data.system.id); input->current_cursor = data; - return 0; + return true; } if (!wayland_get_system_cursor(d, data, &scale)) { - return -1; + return false; } } @@ -719,7 +719,7 @@ static int Wayland_ShowCursor(SDL_Cursor *cursor) } else { Wayland_CachedCustomCursor *cached = Wayland_GetCachedCustomCursor(cursor); if (!cached) { - return -1; + return false; } dst_width = cached->dst_width; dst_height = cached->dst_height; @@ -758,10 +758,10 @@ static int Wayland_ShowCursor(SDL_Cursor *cursor) wl_pointer_set_cursor(pointer, input->pointer_enter_serial, NULL, 0, 0); } - return 0; + return true; } -static int Wayland_WarpMouse(SDL_Window *window, float x, float y) +static bool Wayland_WarpMouse(SDL_Window *window, float x, float y) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *d = vd->internal; @@ -797,10 +797,10 @@ static int Wayland_WarpMouse(SDL_Window *window, float x, float y) return SDL_SetError("wayland: mouse warp failed; compositor lacks support for the required zwp_pointer_confinement_v1 protocol"); } - return 0; + return true; } -static int Wayland_WarpMouseGlobal(float x, float y) +static bool Wayland_WarpMouseGlobal(float x, float y) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *d = vd->internal; @@ -816,7 +816,7 @@ static int Wayland_WarpMouseGlobal(float x, float y) return SDL_SetError("wayland: can't warp the mouse when a window does not have focus"); } -static int Wayland_SetRelativeMouseMode(bool enabled) +static bool Wayland_SetRelativeMouseMode(bool enabled) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *data = vd->internal; @@ -843,18 +843,18 @@ static int Wayland_SetRelativeMouseMode(bool enabled) static SDL_MouseButtonFlags SDLCALL Wayland_GetGlobalMouseState(float *x, float *y) { SDL_Window *focus = SDL_GetMouseFocus(); - SDL_MouseButtonFlags ret = 0; + SDL_MouseButtonFlags result = 0; if (focus) { int off_x, off_y; - ret = SDL_GetMouseState(x, y); + result = SDL_GetMouseState(x, y); SDL_RelativeToGlobalForWindow(focus, focus->x, focus->y, &off_x, &off_y); *x += off_x; *y += off_y; } - return ret; + return result; } #if 0 // TODO RECONNECT: See waylandvideo.c for more information! diff --git a/src/video/wayland/SDL_waylandopengles.c b/src/video/wayland/SDL_waylandopengles.c index 3b99edbbda..17aefd66c6 100644 --- a/src/video/wayland/SDL_waylandopengles.c +++ b/src/video/wayland/SDL_waylandopengles.c @@ -34,17 +34,17 @@ // EGL implementation of SDL OpenGL ES support -int Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { - int ret; + bool result; SDL_VideoData *data = _this->internal; - ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)data->display, _this->gl_config.egl_platform); + result = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType)data->display, _this->gl_config.egl_platform); Wayland_PumpEvents(_this); WAYLAND_wl_display_flush(data->display); - return ret; + return result; } SDL_GLContext Wayland_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) @@ -70,7 +70,7 @@ SDL_GLContext Wayland_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *win libretro, Wayland, probably others...it feels like we're eventually going to have to give in with a future SDL API revision, since we can bend the other APIs to this style, but this style is much harder to bend the other way. :/ */ -int Wayland_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool Wayland_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) { if (!_this->egl_data) { return SDL_SetError("EGL not initialized"); @@ -89,20 +89,20 @@ int Wayland_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval) // !!! FIXME: technically, this should be per-context, right? _this->egl_data->egl_swapinterval = interval; _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, 0); - return 0; + return true; } -int Wayland_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool Wayland_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { if (!_this->egl_data) { return SDL_SetError("EGL not initialized"); } *interval =_this->egl_data->egl_swapinterval; - return 0; + return true; } -int Wayland_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Wayland_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *data = window->internal; const int swap_interval = _this->egl_data->egl_swapinterval; @@ -117,7 +117,7 @@ int Wayland_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) */ if (data->surface_status != WAYLAND_SURFACE_STATUS_SHOWN && data->surface_status != WAYLAND_SURFACE_STATUS_WAITING_FOR_FRAME) { - return 0; + return true; } /* By default, we wait for the Wayland frame callback and then issue the pageflip (eglSwapBuffers), @@ -144,7 +144,7 @@ int Wayland_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) WAYLAND_wl_display_flush(display); - /* wl_display_prepare_read_queue() will return -1 if the event queue is not empty. + /* wl_display_prepare_read_queue() will return false if the event queue is not empty. * If the event queue is empty, it will prepare us for our SDL_IOReady() call. */ if (WAYLAND_wl_display_prepare_read_queue(display, data->gles_swap_frame_event_queue) != 0) { // We have some pending events. Check if the frame callback happened. @@ -183,31 +183,31 @@ int Wayland_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) WAYLAND_wl_display_flush(data->waylandData->display); } - return 0; + return true; } -int Wayland_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool Wayland_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { - int ret; + bool result; if (window && context) { - ret = SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context); + result = SDL_EGL_MakeCurrent(_this, window->internal->egl_surface, context); } else { - ret = SDL_EGL_MakeCurrent(_this, NULL, NULL); + result = SDL_EGL_MakeCurrent(_this, NULL, NULL); } WAYLAND_wl_display_flush(_this->internal->display); _this->egl_data->eglSwapInterval(_this->egl_data->egl_display, 0); // see comments on Wayland_GLES_SetSwapInterval. - return ret; + return result; } -int Wayland_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool Wayland_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { - SDL_EGL_DeleteContext(_this, context); + bool result = SDL_EGL_DestroyContext(_this, context); WAYLAND_wl_display_flush(_this->internal->display); - return 0; + return result; } EGLSurface Wayland_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/wayland/SDL_waylandopengles.h b/src/video/wayland/SDL_waylandopengles.h index fc2e69ac00..364277f20a 100644 --- a/src/video/wayland/SDL_waylandopengles.h +++ b/src/video/wayland/SDL_waylandopengles.h @@ -36,13 +36,13 @@ typedef struct SDL_PrivateGLESData #define Wayland_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal #define Wayland_GLES_UnloadLibrary SDL_EGL_UnloadLibrary -extern int Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool Wayland_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_GLContext Wayland_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int Wayland_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); -extern int Wayland_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int Wayland_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool Wayland_GLES_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool Wayland_GLES_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool Wayland_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Wayland_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool Wayland_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); extern SDL_EGLSurface Wayland_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_waylandopengles_h_ diff --git a/src/video/wayland/SDL_waylandshmbuffer.c b/src/video/wayland/SDL_waylandshmbuffer.c index 030bf0cc64..40ff2bd901 100644 --- a/src/video/wayland/SDL_waylandshmbuffer.c +++ b/src/video/wayland/SDL_waylandshmbuffer.c @@ -33,7 +33,7 @@ #include "SDL_waylandshmbuffer.h" #include "SDL_waylandvideo.h" -static int SetTempFileSize(int fd, off_t size) +static bool SetTempFileSize(int fd, off_t size) { #ifdef HAVE_POSIX_FALLOCATE sigset_t set, old_set; @@ -53,16 +53,16 @@ static int SetTempFileSize(int fd, off_t size) sigprocmask(SIG_SETMASK, &old_set, NULL); if (ret == 0) { - return 0; + return true; } else if (ret != EINVAL && errno != EOPNOTSUPP) { - return -1; + return false; } #endif if (ftruncate(fd, size) < 0) { - return -1; + return false; } - return 0; + return true; } static int CreateTempFD(off_t size) @@ -97,7 +97,7 @@ static int CreateTempFD(off_t size) unlink(tmp_path); } - if (SetTempFileSize(fd, size) < 0) { + if (!SetTempFileSize(fd, size)) { close(fd); return -1; } @@ -114,7 +114,7 @@ static struct wl_buffer_listener buffer_listener = { buffer_handle_release }; -int Wayland_AllocSHMBuffer(int width, int height, struct Wayland_SHMBuffer *shmBuffer) +bool Wayland_AllocSHMBuffer(int width, int height, struct Wayland_SHMBuffer *shmBuffer) { SDL_VideoDevice *vd = SDL_GetVideoDevice(); SDL_VideoData *data = vd->internal; @@ -149,7 +149,7 @@ int Wayland_AllocSHMBuffer(int width, int height, struct Wayland_SHMBuffer *shmB wl_shm_pool_destroy(shm_pool); close(shm_fd); - return 0; + return true; } void Wayland_ReleaseSHMBuffer(struct Wayland_SHMBuffer *shmBuffer) diff --git a/src/video/wayland/SDL_waylandshmbuffer.h b/src/video/wayland/SDL_waylandshmbuffer.h index 2ec02e3eb7..fcb6ebd368 100644 --- a/src/video/wayland/SDL_waylandshmbuffer.h +++ b/src/video/wayland/SDL_waylandshmbuffer.h @@ -32,7 +32,7 @@ struct Wayland_SHMBuffer }; // Allocates an SHM buffer with the format WL_SHM_FORMAT_ARGB8888 -extern int Wayland_AllocSHMBuffer(int width, int height, struct Wayland_SHMBuffer *shmBuffer); +extern bool Wayland_AllocSHMBuffer(int width, int height, struct Wayland_SHMBuffer *shmBuffer); extern void Wayland_ReleaseSHMBuffer(struct Wayland_SHMBuffer *shmBuffer); #endif diff --git a/src/video/wayland/SDL_waylandvideo.c b/src/video/wayland/SDL_waylandvideo.c index 43500d6b90..dfa045e40d 100644 --- a/src/video/wayland/SDL_waylandvideo.c +++ b/src/video/wayland/SDL_waylandvideo.c @@ -296,9 +296,8 @@ static void Wayland_SortOutputs(SDL_VideoData *vid) static void display_handle_done(void *data, struct wl_output *output); // Initialization/Query functions -static int Wayland_VideoInit(SDL_VideoDevice *_this); - -static int Wayland_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +static bool Wayland_VideoInit(SDL_VideoDevice *_this); +static bool Wayland_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); static void Wayland_VideoQuit(SDL_VideoDevice *_this); static const char *SDL_WAYLAND_surface_tag = "sdl-window"; @@ -526,7 +525,7 @@ static SDL_VideoDevice *Wayland_CreateDevice(bool require_preferred_protocols) device->GL_LoadLibrary = Wayland_GLES_LoadLibrary; device->GL_UnloadLibrary = Wayland_GLES_UnloadLibrary; device->GL_GetProcAddress = Wayland_GLES_GetProcAddress; - device->GL_DeleteContext = Wayland_GLES_DeleteContext; + device->GL_DestroyContext = Wayland_GLES_DestroyContext; device->GL_GetEGLSurface = Wayland_GLES_GetEGLSurface; #endif @@ -1023,7 +1022,7 @@ static const struct wl_output_listener output_listener = { display_handle_description // Version 4 }; -static int Wayland_add_display(SDL_VideoData *d, uint32_t id, uint32_t version) +static bool Wayland_add_display(SDL_VideoData *d, uint32_t id, uint32_t version) { struct wl_output *output; SDL_DisplayData *data; @@ -1048,7 +1047,7 @@ static int Wayland_add_display(SDL_VideoData *d, uint32_t id, uint32_t version) data->xdg_output = zxdg_output_manager_v1_get_xdg_output(data->videodata->xdg_output_manager, output); zxdg_output_v1_add_listener(data->xdg_output, &xdg_output_listener, data); } - return 0; + return true; } static void Wayland_free_display(SDL_VideoDisplay *display) @@ -1260,7 +1259,7 @@ bool Wayland_LoadLibdecor(SDL_VideoData *data, bool ignore_xdg) return false; } -int Wayland_VideoInit(SDL_VideoDevice *_this) +bool Wayland_VideoInit(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; @@ -1307,10 +1306,10 @@ int Wayland_VideoInit(SDL_VideoDevice *_this) data->initializing = false; - return 0; + return true; } -static int Wayland_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +static bool Wayland_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { SDL_VideoData *viddata = _this->internal; SDL_DisplayData *internal = display->internal; @@ -1337,7 +1336,7 @@ static int Wayland_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *di rect->h = internal->pixel_height; } } - return 0; + return true; } static void Wayland_VideoCleanup(SDL_VideoDevice *_this) diff --git a/src/video/wayland/SDL_waylandvulkan.c b/src/video/wayland/SDL_waylandvulkan.c index 8f6407c485..d927a4eb5e 100644 --- a/src/video/wayland/SDL_waylandvulkan.c +++ b/src/video/wayland/SDL_waylandvulkan.c @@ -41,7 +41,7 @@ #define DEFAULT_VULKAN "libvulkan.so.1" #endif -int Wayland_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool Wayland_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 i, extensionCount = 0; @@ -61,7 +61,7 @@ int Wayland_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) } _this->vulkan_config.loader_handle = SDL_LoadObject(path); if (!_this->vulkan_config.loader_handle) { - return -1; + return false; } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); @@ -99,12 +99,12 @@ int Wayland_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "extension"); goto fail; } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void Wayland_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -128,7 +128,7 @@ char const* const* Wayland_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, return extensionsForWayland; } -int Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, @@ -162,7 +162,7 @@ int Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this, if (result != VK_SUCCESS) { return SDL_SetError("vkCreateWaylandSurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); } - return 0; + return true; } void Wayland_Vulkan_DestroySurface(SDL_VideoDevice *_this, @@ -188,14 +188,11 @@ bool Wayland_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, "vkGetPhysicalDeviceWaylandPresentationSupportKHR"); if (!_this->vulkan_config.loader_handle) { - SDL_SetError("Vulkan is not loaded"); - return false; + return SDL_SetError("Vulkan is not loaded"); } if (!vkGetPhysicalDeviceWaylandPresentationSupportKHR) { - SDL_SetError(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME - " extension is not enabled in the Vulkan instance."); - return false; + return SDL_SetError(VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); } return vkGetPhysicalDeviceWaylandPresentationSupportKHR(physicalDevice, diff --git a/src/video/wayland/SDL_waylandvulkan.h b/src/video/wayland/SDL_waylandvulkan.h index 6c35d2c0a8..db58589c9d 100644 --- a/src/video/wayland/SDL_waylandvulkan.h +++ b/src/video/wayland/SDL_waylandvulkan.h @@ -33,20 +33,19 @@ #if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_WAYLAND) -int Wayland_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void Wayland_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* Wayland_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this, +extern bool Wayland_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void Wayland_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* Wayland_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool Wayland_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); -void Wayland_Vulkan_DestroySurface(SDL_VideoDevice *_this, +extern void Wayland_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); -bool Wayland_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, +extern bool Wayland_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, VkInstance instance, VkPhysicalDevice physicalDevice, Uint32 queueFamilyIndex); diff --git a/src/video/wayland/SDL_waylandwindow.c b/src/video/wayland/SDL_waylandwindow.c index fc6c7bb0db..8c766722b5 100644 --- a/src/video/wayland/SDL_waylandwindow.c +++ b/src/video/wayland/SDL_waylandwindow.c @@ -1558,12 +1558,12 @@ static void SetKeyboardFocus(SDL_Window *window) SDL_SetKeyboardFocus(window); } -int Wayland_SetWindowHitTest(SDL_Window *window, bool enabled) +bool Wayland_SetWindowHitTest(SDL_Window *window, bool enabled) { - return 0; // just succeed, the real work is done elsewhere. + return true; // just succeed, the real work is done elsewhere. } -int Wayland_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) +bool Wayland_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) { SDL_VideoData *viddata = _this->internal; SDL_WindowData *modal_data = modal_window->internal; @@ -1576,7 +1576,7 @@ int Wayland_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, if (parent_data && parent_data->surface_status != WAYLAND_SURFACE_STATUS_SHOWN) { // Need to wait for the parent to become mapped, or it's the same as setting a null parent. modal_data->modal_reparenting_required = true; - return 0; + return true; } /* Libdecor crashes on attempts to unset the parent by passing null, which is allowed by the @@ -1619,7 +1619,7 @@ int Wayland_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, } } - return 0; + return true; } static void show_hide_sync_handler(void *data, struct wl_callback *callback, uint32_t callback_data) @@ -2097,16 +2097,16 @@ void Wayland_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window) Wayland_activate_window(_this->internal, window->internal, true); } -int Wayland_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) +bool Wayland_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) { /* Not setting the serial will specify 'urgency' without switching focus as per * https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/9#note_854977 */ Wayland_activate_window(_this->internal, window->internal, false); - return 0; + return true; } -int Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, +SDL_FullscreenResult Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { SDL_WindowData *wind = window->internal; @@ -2114,7 +2114,7 @@ int Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, // Custom surfaces have no toplevel to make fullscreen. if (wind->shell_surface_type == WAYLAND_SURFACE_CUSTOM) { - return -1; + return SDL_FULLSCREEN_FAILED; } if (wind->show_hide_sync_required) { @@ -2123,7 +2123,7 @@ int Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, // Flushing old events pending a new one, ignore this request. if (wind->drop_fullscreen_requests) { - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } wind->drop_fullscreen_requests = true; @@ -2133,11 +2133,11 @@ int Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, // Nothing to do if the window is not fullscreen, and this isn't an explicit enter request. if (!wind->is_fullscreen) { if (fullscreen == SDL_FULLSCREEN_OP_UPDATE) { - // Request was out of date; return 1 to signal the video core not to update any state. - return 1; + // Request was out of date; signal the video core not to update any state. + return SDL_FULLSCREEN_PENDING; } else if (fullscreen == SDL_FULLSCREEN_OP_LEAVE) { // Already not fullscreen; nothing to do. - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } } @@ -2160,11 +2160,11 @@ int Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, ConfigureWindowGeometry(window); CommitLibdecorFrame(window); - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } } - return 1; + return SDL_FULLSCREEN_PENDING; } void Wayland_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -2292,7 +2292,7 @@ void Wayland_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window) } } -int Wayland_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) +bool Wayland_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) { SDL_VideoData *data = _this->internal; @@ -2311,7 +2311,7 @@ int Wayland_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) } } -int Wayland_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool Wayland_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { SDL_VideoData *data = _this->internal; @@ -2321,10 +2321,10 @@ int Wayland_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool return Wayland_input_unconfine_pointer(data->input, window); } - return 0; + return true; } -int Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { SDL_VideoData *data = _this->internal; @@ -2335,7 +2335,7 @@ int Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bo } } -int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { SDL_WindowData *data; SDL_VideoData *c = _this->internal; @@ -2347,7 +2347,7 @@ int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert data = SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } window->internal = data; @@ -2477,7 +2477,7 @@ int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert data->egl_surface = SDL_EGL_CreateSurface(_this, window, (NativeWindowType)data->egl_window); if (data->egl_surface == EGL_NO_SURFACE) { - return -1; // SDL_EGL_CreateSurface should have set error + return false; // SDL_EGL_CreateSurface should have set error } } #endif @@ -2519,7 +2519,7 @@ int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propert data->hit_test_result = SDL_HITTEST_NORMAL; - return 0; + return true; } void Wayland_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window) @@ -2534,7 +2534,7 @@ void Wayland_SetWindowMaximumSize(SDL_VideoDevice *_this, SDL_Window *window) SetMinMaxDimensions(window); } -int Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *wind = window->internal; @@ -2546,7 +2546,7 @@ int Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) } RepositionPopup(window, false); - return 0; + return true; } else if (wind->shell_surface_type == WAYLAND_SURFACE_LIBDECOR || wind->shell_surface_type == WAYLAND_SURFACE_XDG_TOPLEVEL) { const int x = window->floating.x; const int y = window->floating.y; @@ -2577,7 +2577,7 @@ int Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) struct wl_output *output = display->internal->output; SetFullscreen(window, output); - return 0; + return true; } } } @@ -2637,7 +2637,7 @@ SDL_DisplayID Wayland_GetDisplayForWindow(SDL_VideoDevice *_this, SDL_Window *wi return 0; } -int Wayland_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) +bool Wayland_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) { SDL_WindowData *wind = window->internal; @@ -2645,7 +2645,7 @@ int Wayland_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float o SetSurfaceOpaqueRegion(wind, !(window->flags & SDL_WINDOW_TRANSPARENT) && opacity == 1.0f); wp_alpha_modifier_surface_v1_set_multiplier(wind->wp_alpha_modifier_surface_v1, (Uint32)((double)SDL_MAX_UINT32 * (double)opacity)); - return 0; + return true; } return SDL_SetError("wayland: set window opacity failed; compositor lacks support for the required wp_alpha_modifier_v1 protocol"); @@ -2666,7 +2666,7 @@ void Wayland_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) } } -int Wayland_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool Wayland_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *wind = window->internal; @@ -2674,7 +2674,7 @@ int Wayland_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) WAYLAND_wl_display_roundtrip(_this->internal->display); } while (wind->fullscreen_deadline_count || wind->maximized_deadline_count); - return 0; + return true; } void Wayland_ShowWindowSystemMenu(SDL_Window *window, int x, int y) @@ -2700,13 +2700,13 @@ void Wayland_ShowWindowSystemMenu(SDL_Window *window, int x, int y) } } -int Wayland_SuspendScreenSaver(SDL_VideoDevice *_this) +bool Wayland_SuspendScreenSaver(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; #ifdef SDL_USE_LIBDBUS if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) { - return 0; + return true; } #endif @@ -2736,7 +2736,7 @@ int Wayland_SuspendScreenSaver(SDL_VideoDevice *_this) } } - return 0; + return true; } void Wayland_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/wayland/SDL_waylandwindow.h b/src/video/wayland/SDL_waylandwindow.h index 813eea335f..38494a9b8a 100644 --- a/src/video/wayland/SDL_waylandwindow.h +++ b/src/video/wayland/SDL_waylandwindow.h @@ -180,34 +180,32 @@ struct SDL_WindowData extern void Wayland_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, - SDL_VideoDisplay *_display, - SDL_FullscreenOp fullscreen); +extern SDL_FullscreenResult Wayland_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen); extern void Wayland_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_MinimizeWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); -extern int Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool Wayland_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Wayland_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool Wayland_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); extern void Wayland_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); extern void Wayland_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); -extern int Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); -extern int Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Wayland_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool Wayland_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_SetWindowMaximumSize(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *w, int *h); extern SDL_DisplayID Wayland_GetDisplayForWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); -extern int Wayland_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); +extern bool Wayland_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); +extern bool Wayland_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); extern void Wayland_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_ShowWindowSystemMenu(SDL_Window *window, int x, int y); extern void Wayland_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int Wayland_SuspendScreenSaver(SDL_VideoDevice *_this); +extern bool Wayland_SuspendScreenSaver(SDL_VideoDevice *_this); -extern int Wayland_SetWindowHitTest(SDL_Window *window, bool enabled); -extern int Wayland_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); -extern int Wayland_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool Wayland_SetWindowHitTest(SDL_Window *window, bool enabled); +extern bool Wayland_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); +extern bool Wayland_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void Wayland_RemoveOutputFromWindow(SDL_WindowData *window, SDL_DisplayData *display_data); diff --git a/src/video/windows/SDL_windowsclipboard.c b/src/video/windows/SDL_windowsclipboard.c index 5cbbf346f2..98d8b87cc8 100644 --- a/src/video/windows/SDL_windowsclipboard.c +++ b/src/video/windows/SDL_windowsclipboard.c @@ -139,12 +139,12 @@ static void *WIN_ConvertDIBtoBMP(HANDLE hMem, size_t *size) return bmp; } -static int WIN_SetClipboardImage(SDL_VideoDevice *_this) +static bool WIN_SetClipboardImage(SDL_VideoDevice *_this) { HANDLE hMem; size_t clipboard_data_size; const void *clipboard_data; - int result = 0; + bool result = true; clipboard_data = _this->clipboard_callback(_this->clipboard_userdata, IMAGE_MIME_TYPE, &clipboard_data_size); hMem = WIN_ConvertBMPtoDIB(clipboard_data, clipboard_data_size); @@ -155,17 +155,17 @@ static int WIN_SetClipboardImage(SDL_VideoDevice *_this) } } else { // WIN_ConvertBMPtoDIB() set the error - result = -1; + result = false; } return result; } -static int WIN_SetClipboardText(SDL_VideoDevice *_this, const char *mime_type) +static bool WIN_SetClipboardText(SDL_VideoDevice *_this, const char *mime_type) { HANDLE hMem; size_t clipboard_data_size; const void *clipboard_data; - int result = 0; + bool result = true; clipboard_data = _this->clipboard_callback(_this->clipboard_userdata, mime_type, &clipboard_data_size); if (clipboard_data && clipboard_data_size > 0) { @@ -211,11 +211,11 @@ static int WIN_SetClipboardText(SDL_VideoDevice *_this, const char *mime_type) return result; } -int WIN_SetClipboardData(SDL_VideoDevice *_this) +bool WIN_SetClipboardData(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; size_t i; - int result = 0; + bool result = true; /* I investigated delayed clipboard rendering, and at least with text and image * formats you have to use an output window, not SDL_HelperWindow, and the system @@ -230,8 +230,8 @@ int WIN_SetClipboardData(SDL_VideoDevice *_this) const char *mime_type = _this->clipboard_mime_types[i]; if (SDL_IsTextMimeType(mime_type)) { - if (WIN_SetClipboardText(_this, mime_type) < 0) { - result = -1; + if (!WIN_SetClipboardText(_this, mime_type)) { + result = false; } // Only set the first clipboard text break; @@ -243,8 +243,8 @@ int WIN_SetClipboardData(SDL_VideoDevice *_this) const char *mime_type = _this->clipboard_mime_types[i]; if (SDL_strcmp(mime_type, IMAGE_MIME_TYPE) == 0) { - if (WIN_SetClipboardImage(_this) < 0) { - result = -1; + if (!WIN_SetClipboardImage(_this)) { + result = false; } break; } diff --git a/src/video/windows/SDL_windowsclipboard.h b/src/video/windows/SDL_windowsclipboard.h index a719cf3313..0547555eca 100644 --- a/src/video/windows/SDL_windowsclipboard.h +++ b/src/video/windows/SDL_windowsclipboard.h @@ -26,7 +26,7 @@ // Forward declaration struct SDL_VideoData; -extern int WIN_SetClipboardData(SDL_VideoDevice *_this); +extern bool WIN_SetClipboardData(SDL_VideoDevice *_this); extern void *WIN_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *size); extern bool WIN_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type); extern void WIN_CheckClipboardUpdate(struct SDL_VideoData *data); diff --git a/src/video/windows/SDL_windowsevents.c b/src/video/windows/SDL_windowsevents.c index e4c53481ad..bbd51e1419 100644 --- a/src/video/windows/SDL_windowsevents.c +++ b/src/video/windows/SDL_windowsevents.c @@ -2363,7 +2363,7 @@ static BOOL CALLBACK WIN_ResourceNameCallback(HMODULE hModule, LPCTSTR lpType, L #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) // Register the class for this application -int SDL_RegisterApp(const char *name, Uint32 style, void *hInst) +SDL_bool SDL_RegisterApp(const char *name, Uint32 style, void *hInst) { WNDCLASSEX wcex; #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) @@ -2373,7 +2373,7 @@ int SDL_RegisterApp(const char *name, Uint32 style, void *hInst) // Only do this once... if (app_registered) { ++app_registered; - return 0; + return true; } SDL_assert(!SDL_Appname); if (!name) { @@ -2421,7 +2421,7 @@ int SDL_RegisterApp(const char *name, Uint32 style, void *hInst) } app_registered = 1; - return 0; + return true; } // Unregisters the windowclass registered in SDL_RegisterApp above. diff --git a/src/video/windows/SDL_windowsframebuffer.c b/src/video/windows/SDL_windowsframebuffer.c index fc75a803d7..d21f06c635 100644 --- a/src/video/windows/SDL_windowsframebuffer.c +++ b/src/video/windows/SDL_windowsframebuffer.c @@ -24,7 +24,7 @@ #include "SDL_windowsvideo.h" -int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) +bool WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_WindowData *data = window->internal; bool isstack; @@ -47,7 +47,7 @@ int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_ size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD); info = (LPBITMAPINFO)SDL_small_alloc(Uint8, size, &isstack); if (!info) { - return -1; + return false; } SDL_memset(info, 0, size); @@ -95,10 +95,10 @@ int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_ } SelectObject(data->mdc, data->hbm); - return 0; + return true; } -int WIN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) +bool WIN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { SDL_WindowData *data = window->internal; int i; @@ -107,7 +107,7 @@ int WIN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, cons BitBlt(data->hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, data->mdc, rects[i].x, rects[i].y, SRCCOPY); } - return 0; + return true; } void WIN_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/windows/SDL_windowsframebuffer.h b/src/video/windows/SDL_windowsframebuffer.h index e4ab869c69..1acd0a8144 100644 --- a/src/video/windows/SDL_windowsframebuffer.h +++ b/src/video/windows/SDL_windowsframebuffer.h @@ -20,6 +20,6 @@ */ #include "SDL_internal.h" -extern int WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); -extern int WIN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); +extern bool WIN_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch); +extern bool WIN_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects); extern void WIN_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/windows/SDL_windowsgameinput.c b/src/video/windows/SDL_windowsgameinput.c index 6be1587fb0..ce613fb6a7 100644 --- a/src/video/windows/SDL_windowsgameinput.c +++ b/src/video/windows/SDL_windowsgameinput.c @@ -69,12 +69,12 @@ struct WIN_GameInputData uint64_t timestamp_offset; }; -static int GAMEINPUT_InternalAddOrFind(WIN_GameInputData *data, IGameInputDevice *pDevice) +static bool GAMEINPUT_InternalAddOrFind(WIN_GameInputData *data, IGameInputDevice *pDevice) { GAMEINPUT_Device **devicelist = NULL; GAMEINPUT_Device *device = NULL; const GameInputDeviceInfo *info; - int retval = -1; + bool result = false; info = IGameInputDevice_GetDeviceInfo(pDevice); @@ -85,7 +85,7 @@ static int GAMEINPUT_InternalAddOrFind(WIN_GameInputData *data, IGameInputDevice if (device && device->pDevice == pDevice) { // we're already added device->delete_requested = false; - retval = 0; + result = true; goto done; } } @@ -117,24 +117,24 @@ static int GAMEINPUT_InternalAddOrFind(WIN_GameInputData *data, IGameInputDevice data->devices = devicelist; data->devices[data->num_devices++] = device; - retval = 0; + result = true; } done: SDL_UnlockMutex(data->lock); - return retval; + return result; } -static int GAMEINPUT_InternalRemoveByIndex(WIN_GameInputData *data, int idx) +static bool GAMEINPUT_InternalRemoveByIndex(WIN_GameInputData *data, int idx) { GAMEINPUT_Device **devicelist = NULL; GAMEINPUT_Device *device; - int retval = -1; + bool result = false; SDL_LockMutex(data->lock); { if (idx < 0 || idx >= data->num_devices) { - retval = SDL_SetError("GAMEINPUT_InternalRemoveByIndex argument idx %d is out of range", idx); + result = SDL_SetError("GAMEINPUT_InternalRemoveByIndex argument idx %d is out of range", idx); goto done; } @@ -168,18 +168,19 @@ static int GAMEINPUT_InternalRemoveByIndex(WIN_GameInputData *data, int idx) data->devices = NULL; } else { if (idx != data->num_devices - 1) { - size_t bytes = sizeof(*devicelist) * (data->num_devices - idx); + size_t bytes = sizeof(*devicelist) * (data->num_devices - idx - 1); SDL_memmove(&data->devices[idx], &data->devices[idx + 1], bytes); } } // decrement the count and return - retval = data->num_devices--; + --data->num_devices; + result = true; } done: SDL_UnlockMutex(data->lock); - return retval; + return result; } static void CALLBACK GAMEINPUT_InternalDeviceCallback( @@ -213,14 +214,14 @@ static void CALLBACK GAMEINPUT_InternalDeviceCallback( } } -int WIN_InitGameInput(SDL_VideoDevice *_this) +bool WIN_InitGameInput(SDL_VideoDevice *_this) { WIN_GameInputData *data; HRESULT hr; - int retval = -1; + bool result = false; if (_this->internal->gameinput_context) { - return 0; + return true; } data = (WIN_GameInputData *)SDL_calloc(1, sizeof(*data)); @@ -269,13 +270,13 @@ int WIN_InitGameInput(SDL_VideoDevice *_this) uint64_t timestampUS = IGameInput_GetCurrentTimestamp(data->pGameInput); data->timestamp_offset = (SDL_NS_TO_US(now) - timestampUS); - retval = 0; + result = true; done: - if (retval < 0) { + if (!result) { WIN_QuitGameInput(_this); } - return retval; + return result; } static void GAMEINPUT_InitialMouseReading(WIN_GameInputData *data, SDL_Window *window, GAMEINPUT_Device *device, IGameInputReading *reading) @@ -527,7 +528,7 @@ void WIN_UpdateGameInput(SDL_VideoDevice *_this) SDL_UnlockMutex(data->lock); } -int WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this) +bool WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this) { WIN_GameInputData *data = _this->internal->gameinput_context; bool raw_mouse_enabled = _this->internal->raw_mouse_enabled; @@ -555,7 +556,7 @@ int WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this) } SDL_UnlockMutex(data->lock); - return 0; + return true; } void WIN_QuitGameInput(SDL_VideoDevice *_this) @@ -598,12 +599,12 @@ void WIN_QuitGameInput(SDL_VideoDevice *_this) #else // !HAVE_GAMEINPUT_H -int WIN_InitGameInput(SDL_VideoDevice* _this) +bool WIN_InitGameInput(SDL_VideoDevice* _this) { return SDL_Unsupported(); } -int WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this) +bool WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this) { return SDL_Unsupported(); } diff --git a/src/video/windows/SDL_windowsgameinput.h b/src/video/windows/SDL_windowsgameinput.h index 58ef19a367..eb72103b91 100644 --- a/src/video/windows/SDL_windowsgameinput.h +++ b/src/video/windows/SDL_windowsgameinput.h @@ -22,8 +22,8 @@ typedef struct WIN_GameInputData WIN_GameInputData; -extern int WIN_InitGameInput(SDL_VideoDevice *_this); -extern int WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this); +extern bool WIN_InitGameInput(SDL_VideoDevice *_this); +extern bool WIN_UpdateGameInputEnabled(SDL_VideoDevice *_this); extern void WIN_UpdateGameInput(SDL_VideoDevice *_this); extern void WIN_QuitGameInput(SDL_VideoDevice *_this); diff --git a/src/video/windows/SDL_windowskeyboard.c b/src/video/windows/SDL_windowskeyboard.c index f98c438dc5..e494e45022 100644 --- a/src/video/windows/SDL_windowskeyboard.c +++ b/src/video/windows/SDL_windowskeyboard.c @@ -36,7 +36,7 @@ #else #define SDL_DebugIMELog(...) #endif -static int IME_Init(SDL_VideoData *videodata, SDL_Window *window); +static bool IME_Init(SDL_VideoData *videodata, SDL_Window *window); static void IME_Enable(SDL_VideoData *videodata, HWND hwnd); static void IME_Disable(SDL_VideoData *videodata, HWND hwnd); static void IME_SetTextInputArea(SDL_VideoData *videodata, HWND hwnd, const SDL_Rect *rect, int cursor); @@ -208,7 +208,7 @@ void WIN_ResetDeadKeys(void) } } -int WIN_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) +bool WIN_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { WIN_ResetDeadKeys(); @@ -221,10 +221,10 @@ int WIN_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie WIN_UpdateTextInputArea(_this, window); #endif // !SDL_DISABLE_WINDOWS_IME - return 0; + return true; } -int WIN_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) { WIN_ResetDeadKeys(); @@ -235,26 +235,26 @@ int WIN_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) IME_Disable(videodata, hwnd); #endif // !SDL_DISABLE_WINDOWS_IME - return 0; + return true; } -int WIN_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) { SDL_VideoData *videodata = _this->internal; SDL_WindowData *data = window->internal; IME_SetTextInputArea(videodata, data->hwnd, &window->text_input_rect, window->text_input_cursor); - return 0; + return true; } -int WIN_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window) { #ifndef SDL_DISABLE_WINDOWS_IME SDL_VideoData *videodata = _this->internal; IME_ClearComposition(videodata); #endif - return 0; + return true; } #ifdef SDL_DISABLE_WINDOWS_IME @@ -313,12 +313,12 @@ static DWORD IME_GetId(SDL_VideoData *videodata, UINT uIndex); static void IME_SendEditingEvent(SDL_VideoData *videodata); static void IME_SendClearComposition(SDL_VideoData *videodata); -static int IME_Init(SDL_VideoData *videodata, SDL_Window *window) +static bool IME_Init(SDL_VideoData *videodata, SDL_Window *window) { HWND hwnd = window->internal->hwnd; if (videodata->ime_initialized) { - return 0; + return true; } const char *hint = SDL_GetHint(SDL_HINT_IME_IMPLEMENTED_UI); @@ -335,7 +335,7 @@ static int IME_Init(SDL_VideoData *videodata, SDL_Window *window) if (!videodata->ime_himm32) { videodata->ime_available = false; SDL_ClearError(); - return 0; + return true; } /* *INDENT-OFF* */ // clang-format off videodata->ImmLockIMC = (LPINPUTCONTEXT2 (WINAPI *)(HIMC))SDL_LoadFunction(videodata->ime_himm32, "ImmLockIMC"); @@ -350,14 +350,14 @@ static int IME_Init(SDL_VideoData *videodata, SDL_Window *window) if (!videodata->ime_himc) { videodata->ime_available = false; IME_Disable(videodata, hwnd); - return 0; + return true; } videodata->ime_available = true; IME_UpdateInputLocale(videodata); IME_SetupAPI(videodata); IME_UpdateInputLocale(videodata); IME_Disable(videodata, hwnd); - return 0; + return true; } static void IME_Enable(SDL_VideoData *videodata, HWND hwnd) @@ -875,11 +875,11 @@ static void IME_SendClearComposition(SDL_VideoData *videodata) } } -static int IME_OpenCandidateList(SDL_VideoData *videodata) +static bool IME_OpenCandidateList(SDL_VideoData *videodata) { videodata->ime_candidates_open = true; videodata->ime_candcount = 0; - return 0; + return true; } static void IME_AddCandidate(SDL_VideoData *videodata, UINT i, LPCWSTR candidate) @@ -932,7 +932,7 @@ static void IME_GetCandidateList(SDL_VideoData *videodata, HWND hwnd) if (cand_list != NULL) { size = ImmGetCandidateListW(himc, 0, cand_list, size); if (size != 0) { - if (IME_OpenCandidateList(videodata) == 0) { + if (IME_OpenCandidateList(videodata)) { UINT i, j; UINT page_start = 0; UINT page_size = 0; diff --git a/src/video/windows/SDL_windowskeyboard.h b/src/video/windows/SDL_windowskeyboard.h index 6b84e16247..65f7942e4e 100644 --- a/src/video/windows/SDL_windowskeyboard.h +++ b/src/video/windows/SDL_windowskeyboard.h @@ -29,10 +29,10 @@ extern void WIN_QuitKeyboard(SDL_VideoDevice *_this); extern void WIN_ResetDeadKeys(void); -extern int WIN_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -extern int WIN_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +extern bool WIN_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_ClearComposition(SDL_VideoDevice *_this, SDL_Window *window); extern bool WIN_HandleIMEMessage(HWND hwnd, UINT msg, WPARAM wParam, LPARAM *lParam, struct SDL_VideoData *videodata); extern void WIN_UpdateIMECandidates(SDL_VideoDevice *_this); diff --git a/src/video/windows/SDL_windowsmessagebox.c b/src/video/windows/SDL_windowsmessagebox.c index f259edb5d7..be96da9e08 100644 --- a/src/video/windows/SDL_windowsmessagebox.c +++ b/src/video/windows/SDL_windowsmessagebox.c @@ -671,21 +671,22 @@ static const char *EscapeAmpersands(char **dst, size_t *dstlen, const char *src) } // This function is called if a Task Dialog is unsupported. -static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +static bool WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { WIN_DialogData *dialog; - int i, x, y, retval; + int i, x, y; HFONT DialogFont; SIZE Size; RECT TextSize; wchar_t *wmessage; TEXTMETRIC TM; HDC FontDC; - INT_PTR result; + INT_PTR rc; char *ampescape = NULL; size_t ampescapesize = 0; Uint16 defbuttoncount = 0; Uint16 icon = 0; + bool result; HWND ParentWindow = NULL; @@ -817,17 +818,17 @@ static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int * dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title); if (!dialog) { - return -1; + return false; } if (icon && !AddDialogStaticIcon(dialog, IconMargin, IconMargin, IconWidth, IconHeight, icon)) { FreeDialogData(dialog); - return -1; + return false; } if (!AddDialogStaticText(dialog, TextSize.left, TextSize.top, TextSize.right - TextSize.left, TextSize.bottom - TextSize.top, messageboxdata->message)) { FreeDialogData(dialog); - return -1; + return false; } // Align the buttons to the right/bottom. @@ -860,7 +861,7 @@ static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int * if (!buttontext || !AddDialogButton(dialog, x, y, ButtonWidth, ButtonHeight, buttontext, IDBUTTONINDEX0 + (int)(sdlButton - messageboxdata->buttons), isdefault)) { FreeDialogData(dialog); SDL_free(ampescape); - return -1; + return false; } x += ButtonWidth + ButtonMargin; @@ -873,32 +874,32 @@ static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int * ParentWindow = messageboxdata->window->internal->hwnd; } - result = DialogBoxIndirectParam(NULL, (DLGTEMPLATE *)dialog->lpDialog, ParentWindow, MessageBoxDialogProc, (LPARAM)messageboxdata); - if (result >= IDBUTTONINDEX0 && result - IDBUTTONINDEX0 < messageboxdata->numbuttons) { - *buttonID = messageboxdata->buttons[result - IDBUTTONINDEX0].buttonID; - retval = 0; - } else if (result == IDCLOSED) { + rc = DialogBoxIndirectParam(NULL, (DLGTEMPLATE *)dialog->lpDialog, ParentWindow, MessageBoxDialogProc, (LPARAM)messageboxdata); + if (rc >= IDBUTTONINDEX0 && rc - IDBUTTONINDEX0 < messageboxdata->numbuttons) { + *buttonID = messageboxdata->buttons[rc - IDBUTTONINDEX0].buttonID; + result = true; + } else if (rc == IDCLOSED) { // Dialog window closed by user or system. // This could use a special return code. - retval = 0; + result = true; *buttonID = -1; } else { - if (result == 0) { + if (rc == 0) { SDL_SetError("Invalid parent window handle"); - } else if (result == -1) { + } else if (rc == -1) { SDL_SetError("The message box encountered an error."); - } else if (result == IDINVALPTRINIT || result == IDINVALPTRSETFOCUS || result == IDINVALPTRCOMMAND) { + } else if (rc == IDINVALPTRINIT || rc == IDINVALPTRSETFOCUS || rc == IDINVALPTRCOMMAND) { SDL_SetError("Invalid message box pointer in dialog procedure"); - } else if (result == IDINVALPTRDLGITEM) { + } else if (rc == IDINVALPTRDLGITEM) { SDL_SetError("Couldn't find dialog control of the default enter-key button"); } else { SDL_SetError("An unknown error occurred"); } - retval = -1; + result = false; } FreeDialogData(dialog); - return retval; + return result; } /* TaskDialogIndirect procedure @@ -908,7 +909,7 @@ static int WIN_ShowOldMessageBox(const SDL_MessageBoxData *messageboxdata, int * typedef HRESULT (FAR WINAPI *TASKDIALOGINDIRECTPROC)(const TASKDIALOGCONFIG *pTaskConfig, int *pnButton, int *pnRadioButton, BOOL *pfVerificationFlagChecked); /* *INDENT-ON* */ // clang-format on -int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { HWND ParentWindow = NULL; wchar_t *wmessage; @@ -1001,7 +1002,7 @@ int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) SDL_free((wchar_t *)pButtons[j].pszButtonText); } SDL_free(pButtons); - return -1; + return false; } pButton->pszButtonText = WIN_UTF8ToStringW(buttontext); if (messageboxdata->buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) { @@ -1032,7 +1033,7 @@ int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) } else { *buttonID = -1; } - return 0; + return true; } // We failed showing the Task Dialog, use the old message box! diff --git a/src/video/windows/SDL_windowsmessagebox.h b/src/video/windows/SDL_windowsmessagebox.h index 25eeed72fc..3b475530af 100644 --- a/src/video/windows/SDL_windowsmessagebox.h +++ b/src/video/windows/SDL_windowsmessagebox.h @@ -22,6 +22,6 @@ #ifdef SDL_VIDEO_DRIVER_WINDOWS -extern int WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_WINDOWS diff --git a/src/video/windows/SDL_windowsmodes.c b/src/video/windows/SDL_windowsmodes.c index 8ec9c26fa1..220304917e 100644 --- a/src/video/windows/SDL_windowsmodes.c +++ b/src/video/windows/SDL_windowsmodes.c @@ -113,7 +113,7 @@ static void WIN_UpdateDisplayMode(SDL_VideoDevice *_this, LPCWSTR deviceName, DW static void *WIN_GetDXGIOutput(SDL_VideoDevice *_this, const WCHAR *DeviceName) { - void *retval = NULL; + void *result = NULL; #ifdef HAVE_DXGI_H const SDL_VideoData *videodata = (const SDL_VideoData *)_this->internal; @@ -126,16 +126,16 @@ static void *WIN_GetDXGIOutput(SDL_VideoDevice *_this, const WCHAR *DeviceName) } nAdapter = 0; - while (!retval && SUCCEEDED(IDXGIFactory_EnumAdapters(videodata->pDXGIFactory, nAdapter, &pDXGIAdapter))) { + while (!result && SUCCEEDED(IDXGIFactory_EnumAdapters(videodata->pDXGIFactory, nAdapter, &pDXGIAdapter))) { nOutput = 0; - while (!retval && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) { + while (!result && SUCCEEDED(IDXGIAdapter_EnumOutputs(pDXGIAdapter, nOutput, &pDXGIOutput))) { DXGI_OUTPUT_DESC outputDesc; if (SUCCEEDED(IDXGIOutput_GetDesc(pDXGIOutput, &outputDesc))) { if (SDL_wcscmp(outputDesc.DeviceName, DeviceName) == 0) { - retval = pDXGIOutput; + result = pDXGIOutput; } } - if (pDXGIOutput != retval) { + if (pDXGIOutput != result) { IDXGIOutput_Release(pDXGIOutput); } nOutput++; @@ -144,7 +144,7 @@ static void *WIN_GetDXGIOutput(SDL_VideoDevice *_this, const WCHAR *DeviceName) nAdapter++; } #endif - return retval; + return result; } static void WIN_ReleaseDXGIOutput(void *dxgi_output) @@ -313,7 +313,7 @@ static char *WIN_GetDisplayNameVista(SDL_VideoData *videodata, const WCHAR *devi { DISPLAYCONFIG_PATH_INFO *paths = NULL; DISPLAYCONFIG_MODE_INFO *modes = NULL; - char *retval = NULL; + char *result = NULL; UINT32 pathCount = 0; UINT32 modeCount = 0; UINT32 i; @@ -365,12 +365,12 @@ static char *WIN_GetDisplayNameVista(SDL_VideoData *videodata, const WCHAR *devi targetName.header.size = sizeof(targetName); rc = videodata->DisplayConfigGetDeviceInfo(&targetName.header); if (rc == ERROR_SUCCESS) { - retval = WIN_StringToUTF8W(targetName.monitorFriendlyDeviceName); + result = WIN_StringToUTF8W(targetName.monitorFriendlyDeviceName); /* if we got an empty string, treat it as failure so we'll fallback to getting the generic name. */ - if (retval && (*retval == '\0')) { - SDL_free(retval); - retval = NULL; + if (result && (*result == '\0')) { + SDL_free(result); + result = NULL; } } break; @@ -379,10 +379,10 @@ static char *WIN_GetDisplayNameVista(SDL_VideoData *videodata, const WCHAR *devi SDL_free(paths); SDL_free(modes); - return retval; + return result; WIN_GetDisplayNameVista_failed: - SDL_free(retval); + SDL_free(result); SDL_free(paths); SDL_free(modes); return NULL; @@ -607,7 +607,7 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI SDL_ResetFullscreenDisplayModes(existing_display); SDL_SetDesktopDisplayMode(existing_display, &mode); - if (WIN_GetDisplayBounds(_this, existing_display, &bounds) == 0 && + if (WIN_GetDisplayBounds(_this, existing_display, &bounds) && SDL_memcmp(&internal->bounds, &bounds, sizeof(bounds)) != 0) { changed_bounds = true; SDL_copyp(&internal->bounds, &bounds); @@ -706,17 +706,17 @@ static void WIN_AddDisplays(SDL_VideoDevice *_this) EnumDisplayMonitors(NULL, NULL, WIN_AddDisplaysCallback, (LPARAM)&callback_data); } -int WIN_InitModes(SDL_VideoDevice *_this) +bool WIN_InitModes(SDL_VideoDevice *_this) { WIN_AddDisplays(_this); if (_this->num_displays == 0) { return SDL_SetError("No displays available"); } - return 0; + return true; } -int WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +bool WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { const SDL_DisplayData *data = display->internal; MONITORINFO minfo; @@ -735,10 +735,10 @@ int WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_ rect->w = minfo.rcMonitor.right - minfo.rcMonitor.left; rect->h = minfo.rcMonitor.bottom - minfo.rcMonitor.top; - return 0; + return true; } -int WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) +bool WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect) { const SDL_DisplayData *data = display->internal; MONITORINFO minfo; @@ -757,10 +757,10 @@ int WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display rect->w = minfo.rcWork.right - minfo.rcWork.left; rect->h = minfo.rcWork.bottom - minfo.rcWork.top; - return 0; + return true; } -int WIN_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) +bool WIN_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) { SDL_DisplayData *data = display->internal; void *dxgi_output; @@ -789,7 +789,7 @@ int WIN_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display) WIN_ReleaseDXGIOutput(dxgi_output); - return 0; + return true; } #ifdef DEBUG_MODES @@ -822,7 +822,7 @@ static void WIN_LogMonitor(SDL_VideoDevice *_this, HMONITOR mon) } #endif -int WIN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +bool WIN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { SDL_DisplayData *displaydata = display->internal; SDL_DisplayModeData *data = (SDL_DisplayModeData *)mode->internal; @@ -880,7 +880,7 @@ int WIN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Di EnumDisplaySettingsW(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode); WIN_UpdateDisplayMode(_this, displaydata->DeviceName, ENUM_CURRENT_SETTINGS, mode); - return 0; + return true; } void WIN_RefreshDisplays(SDL_VideoDevice *_this) diff --git a/src/video/windows/SDL_windowsmodes.h b/src/video/windows/SDL_windowsmodes.h index 6b8062848c..4b7742aca1 100644 --- a/src/video/windows/SDL_windowsmodes.h +++ b/src/video/windows/SDL_windowsmodes.h @@ -44,11 +44,11 @@ struct SDL_DisplayModeData DEVMODE DeviceMode; }; -extern int WIN_InitModes(SDL_VideoDevice *_this); -extern int WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); -extern int WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); -extern int WIN_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -extern int WIN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool WIN_InitModes(SDL_VideoDevice *_this); +extern bool WIN_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +extern bool WIN_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_Rect *rect); +extern bool WIN_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool WIN_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); extern void WIN_RefreshDisplays(SDL_VideoDevice *_this); extern void WIN_QuitModes(SDL_VideoDevice *_this); diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index f22194eebc..a1723c37b8 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -406,7 +406,7 @@ error: return NULL; } -static int WIN_ShowCursor(SDL_Cursor *cursor) +static bool WIN_ShowCursor(SDL_Cursor *cursor) { if (!cursor) { cursor = SDL_blank_cursor; @@ -423,7 +423,7 @@ static int WIN_ShowCursor(SDL_Cursor *cursor) if (SDL_GetMouseFocus() != NULL) { SetCursor(SDL_cursor); } - return 0; + return true; } void WIN_SetCursorPos(int x, int y) @@ -447,7 +447,7 @@ void WIN_SetCursorPos(int x, int y) #endif } -static int WIN_WarpMouse(SDL_Window *window, float x, float y) +static bool WIN_WarpMouse(SDL_Window *window, float x, float y) { SDL_WindowData *data = window->internal; HWND hwnd = data->hwnd; @@ -455,7 +455,7 @@ static int WIN_WarpMouse(SDL_Window *window, float x, float y) // Don't warp the mouse while we're doing a modal interaction if (data->in_title_click || data->focus_click_pending) { - return 0; + return true; } pt.x = (int)SDL_roundf(x); @@ -465,25 +465,25 @@ static int WIN_WarpMouse(SDL_Window *window, float x, float y) // Send the exact mouse motion associated with this warp SDL_SendMouseMotion(0, window, SDL_GLOBAL_MOUSE_ID, false, x, y); - return 0; + return true; } -static int WIN_WarpMouseGlobal(float x, float y) +static bool WIN_WarpMouseGlobal(float x, float y) { POINT pt; pt.x = (int)SDL_roundf(x); pt.y = (int)SDL_roundf(y); SetCursorPos(pt.x, pt.y); - return 0; + return true; } -static int WIN_SetRelativeMouseMode(bool enabled) +static bool WIN_SetRelativeMouseMode(bool enabled) { return WIN_SetRawMouseEnabled(SDL_GetVideoDevice(), enabled); } -static int WIN_CaptureMouse(SDL_Window *window) +static bool WIN_CaptureMouse(SDL_Window *window) { if (window) { SDL_WindowData *data = window->internal; @@ -500,12 +500,12 @@ static int WIN_CaptureMouse(SDL_Window *window) ReleaseCapture(); } - return 0; + return true; } static SDL_MouseButtonFlags WIN_GetGlobalMouseState(float *x, float *y) { - SDL_MouseButtonFlags retval = 0; + SDL_MouseButtonFlags result = 0; POINT pt = { 0, 0 }; bool swapButtons = GetSystemMetrics(SM_SWAPBUTTON) != 0; @@ -513,13 +513,13 @@ static SDL_MouseButtonFlags WIN_GetGlobalMouseState(float *x, float *y) *x = (float)pt.x; *y = (float)pt.y; - retval |= GetAsyncKeyState(!swapButtons ? VK_LBUTTON : VK_RBUTTON) & 0x8000 ? SDL_BUTTON_LMASK : 0; - retval |= GetAsyncKeyState(!swapButtons ? VK_RBUTTON : VK_LBUTTON) & 0x8000 ? SDL_BUTTON_RMASK : 0; - retval |= GetAsyncKeyState(VK_MBUTTON) & 0x8000 ? SDL_BUTTON_MMASK : 0; - retval |= GetAsyncKeyState(VK_XBUTTON1) & 0x8000 ? SDL_BUTTON_X1MASK : 0; - retval |= GetAsyncKeyState(VK_XBUTTON2) & 0x8000 ? SDL_BUTTON_X2MASK : 0; + result |= GetAsyncKeyState(!swapButtons ? VK_LBUTTON : VK_RBUTTON) & 0x8000 ? SDL_BUTTON_LMASK : 0; + result |= GetAsyncKeyState(!swapButtons ? VK_RBUTTON : VK_LBUTTON) & 0x8000 ? SDL_BUTTON_RMASK : 0; + result |= GetAsyncKeyState(VK_MBUTTON) & 0x8000 ? SDL_BUTTON_MMASK : 0; + result |= GetAsyncKeyState(VK_XBUTTON1) & 0x8000 ? SDL_BUTTON_X1MASK : 0; + result |= GetAsyncKeyState(VK_XBUTTON2) & 0x8000 ? SDL_BUTTON_X2MASK : 0; - return retval; + return result; } void WIN_InitMouse(SDL_VideoDevice *_this) diff --git a/src/video/windows/SDL_windowsopengl.c b/src/video/windows/SDL_windowsopengl.c index 5518716b14..37d8abaa65 100644 --- a/src/video/windows/SDL_windowsopengl.c +++ b/src/video/windows/SDL_windowsopengl.c @@ -105,7 +105,7 @@ typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC hDC, #define SetPixelFormat _this->gl_data->wglSetPixelFormat #endif -int WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) { void *handle; @@ -117,7 +117,7 @@ int WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) } _this->gl_config.dll_handle = SDL_LoadObject(path); if (!_this->gl_config.dll_handle) { - return -1; + return false; } SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); @@ -125,7 +125,7 @@ int WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) // Allocate OpenGL memory _this->gl_data = (struct SDL_GLDriverData *)SDL_calloc(1, sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - return -1; + return false; } // Load function pointers @@ -209,7 +209,7 @@ int WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) WIN_GL_InitExtensions(_this); --_this->gl_config.driver_loaded; - return 0; + return true; } SDL_FunctionPointer WIN_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc) @@ -272,7 +272,7 @@ static void WIN_GL_SetupPixelFormat(SDL_VideoDevice *_this, PIXELFORMATDESCRIPTO /* Choose the closest pixel format that meets or exceeds the target. FIXME: Should we weight any particular attribute over any other? */ -static int WIN_GL_ChoosePixelFormat(SDL_VideoDevice *_this, HDC hdc, PIXELFORMATDESCRIPTOR *target) +static bool WIN_GL_ChoosePixelFormat(SDL_VideoDevice *_this, HDC hdc, PIXELFORMATDESCRIPTOR *target) { PIXELFORMATDESCRIPTOR pfd; int count, index, best = 0; @@ -565,7 +565,7 @@ static int WIN_GL_ChoosePixelFormatARB(SDL_VideoDevice *_this, int *iAttribs, fl } // actual work of WIN_GL_SetupWindow() happens here. -static int WIN_GL_SetupWindowInternal(SDL_VideoDevice *_this, SDL_Window *window) +static bool WIN_GL_SetupWindowInternal(SDL_VideoDevice *_this, SDL_Window *window) { HDC hdc = window->internal->hdc; PIXELFORMATDESCRIPTOR pfd; @@ -682,17 +682,17 @@ static int WIN_GL_SetupWindowInternal(SDL_VideoDevice *_this, SDL_Window *window if (!SetPixelFormat(hdc, pixel_format, &pfd)) { return WIN_SetError("SetPixelFormat()"); } - return 0; + return true; } -int WIN_GL_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_GL_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) { // The current context is lost in here; save it and reset it. SDL_Window *current_win = SDL_GL_GetCurrentWindow(); SDL_GLContext current_ctx = SDL_GL_GetCurrentContext(); - const int retval = WIN_GL_SetupWindowInternal(_this, window); + const int result = WIN_GL_SetupWindowInternal(_this, window); WIN_GL_MakeCurrent(_this, current_win, current_ctx); - return retval; + return result; } bool WIN_GL_UseEGL(SDL_VideoDevice *_this) @@ -720,10 +720,10 @@ SDL_GLContext WIN_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) _this->GL_SetSwapInterval = WIN_GLES_SetSwapInterval; _this->GL_GetSwapInterval = WIN_GLES_GetSwapInterval; _this->GL_SwapWindow = WIN_GLES_SwapWindow; - _this->GL_DeleteContext = WIN_GLES_DeleteContext; + _this->GL_DestroyContext = WIN_GLES_DestroyContext; _this->GL_GetEGLSurface = WIN_GLES_GetEGLSurface; - if (WIN_GLES_LoadLibrary(_this, NULL) != 0) { + if (!WIN_GLES_LoadLibrary(_this, NULL)) { return NULL; } @@ -757,8 +757,8 @@ SDL_GLContext WIN_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) } // Make the context current - if (WIN_GL_MakeCurrent(_this, window, (SDL_GLContext)temp_context) < 0) { - WIN_GL_DeleteContext(_this, (SDL_GLContext)temp_context); + if (!WIN_GL_MakeCurrent(_this, window, (SDL_GLContext)temp_context)) { + WIN_GL_DestroyContext(_this, (SDL_GLContext)temp_context); return NULL; } @@ -820,15 +820,15 @@ SDL_GLContext WIN_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) return NULL; } - if (WIN_GL_MakeCurrent(_this, window, (SDL_GLContext)context) < 0) { - WIN_GL_DeleteContext(_this, (SDL_GLContext)context); + if (!WIN_GL_MakeCurrent(_this, window, (SDL_GLContext)context)) { + WIN_GL_DestroyContext(_this, (SDL_GLContext)context); return NULL; } return (SDL_GLContext)context; } -int WIN_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool WIN_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { HDC hdc; @@ -847,7 +847,7 @@ int WIN_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext window = SDL_GL_GetCurrentWindow(); if (!window) { SDL_assert(SDL_GL_GetCurrentContext() == NULL); - return 0; // already done. + return true; // already done. } } @@ -855,50 +855,50 @@ int WIN_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext if (!_this->gl_data->wglMakeCurrent(hdc, (HGLRC)context)) { return WIN_SetError("wglMakeCurrent()"); } - return 0; + return true; } -int WIN_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool WIN_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) { if ((interval < 0) && (!_this->gl_data->HAS_WGL_EXT_swap_control_tear)) { return SDL_SetError("Negative swap interval unsupported in this GL"); } else if (_this->gl_data->wglSwapIntervalEXT) { - if (_this->gl_data->wglSwapIntervalEXT(interval) != TRUE) { + if (!_this->gl_data->wglSwapIntervalEXT(interval)) { return WIN_SetError("wglSwapIntervalEXT()"); } } else { return SDL_Unsupported(); } - return 0; + return true; } -int WIN_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool WIN_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { if (_this->gl_data->wglGetSwapIntervalEXT) { *interval = _this->gl_data->wglGetSwapIntervalEXT(); - return 0; + return true; } else { - return -1; + return false; } } -int WIN_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { HDC hdc = window->internal->hdc; if (!SwapBuffers(hdc)) { return WIN_SetError("SwapBuffers()"); } - return 0; + return true; } -int WIN_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool WIN_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { if (!_this->gl_data) { - return 0; + return true; } _this->gl_data->wglDeleteContext((HGLRC)context); - return 0; + return true; } #endif // SDL_VIDEO_OPENGL_WGL diff --git a/src/video/windows/SDL_windowsopengl.h b/src/video/windows/SDL_windowsopengl.h index 0296296484..aefa5d73be 100644 --- a/src/video/windows/SDL_windowsopengl.h +++ b/src/video/windows/SDL_windowsopengl.h @@ -102,18 +102,18 @@ struct SDL_GLDriverData }; // OpenGL functions -extern int WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_FunctionPointer WIN_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); extern void WIN_GL_UnloadLibrary(SDL_VideoDevice *_this); extern bool WIN_GL_UseEGL(SDL_VideoDevice *_this); -extern int WIN_GL_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_GL_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_GLContext WIN_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, +extern bool WIN_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int WIN_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int WIN_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); -extern int WIN_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool WIN_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool WIN_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool WIN_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); extern void WIN_GL_InitExtensions(SDL_VideoDevice *_this); #ifndef WGL_ARB_pixel_format diff --git a/src/video/windows/SDL_windowsopengles.c b/src/video/windows/SDL_windowsopengles.c index 846376403b..29a4c5fc25 100644 --- a/src/video/windows/SDL_windowsopengles.c +++ b/src/video/windows/SDL_windowsopengles.c @@ -29,7 +29,7 @@ // EGL implementation of SDL OpenGL support -int WIN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool WIN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { // If the profile requested is not GL ES, switch over to WIN_GL functions @@ -45,7 +45,7 @@ int WIN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval; _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval; _this->GL_SwapWindow = WIN_GL_SwapWindow; - _this->GL_DeleteContext = WIN_GL_DeleteContext; + _this->GL_DestroyContext = WIN_GL_DestroyContext; _this->GL_GetEGLSurface = NULL; return WIN_GL_LoadLibrary(_this, path); #else @@ -57,7 +57,7 @@ int WIN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) return SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform); } - return 0; + return true; } SDL_GLContext WIN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) @@ -78,10 +78,10 @@ SDL_GLContext WIN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) _this->GL_SetSwapInterval = WIN_GL_SetSwapInterval; _this->GL_GetSwapInterval = WIN_GL_GetSwapInterval; _this->GL_SwapWindow = WIN_GL_SwapWindow; - _this->GL_DeleteContext = WIN_GL_DeleteContext; + _this->GL_DestroyContext = WIN_GL_DestroyContext; _this->GL_GetEGLSurface = NULL; - if (WIN_GL_LoadLibrary(_this, NULL) != 0) { + if (!WIN_GL_LoadLibrary(_this, NULL)) { return NULL; } @@ -93,10 +93,9 @@ SDL_GLContext WIN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) return context; } -int WIN_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool WIN_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { - SDL_EGL_DeleteContext(_this, context); - return 0; + return SDL_EGL_DestroyContext(_this, context); } /* *INDENT-OFF* */ // clang-format off @@ -104,7 +103,7 @@ SDL_EGL_SwapWindow_impl(WIN) SDL_EGL_MakeCurrent_impl(WIN) /* *INDENT-ON* */ // clang-format on -int WIN_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) { // The current context is lost in here; save it and reset it. SDL_WindowData *windowdata = window->internal; @@ -116,9 +115,9 @@ int WIN_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) #if 0 // When hint SDL_HINT_OPENGL_ES_DRIVER is set to "1" (e.g. for ANGLE support), _this->gl_config.driver_loaded can be 1, while the below lines function. SDL_assert(!_this->gl_config.driver_loaded); #endif - if (SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform) < 0) { + if (!SDL_EGL_LoadLibrary(_this, NULL, EGL_DEFAULT_DISPLAY, _this->gl_config.egl_platform)) { SDL_EGL_UnloadLibrary(_this); - return -1; + return false; } _this->gl_config.driver_loaded = 1; } @@ -133,8 +132,7 @@ int WIN_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window) return WIN_GLES_MakeCurrent(_this, current_win, current_ctx); } -EGLSurface -WIN_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window) +EGLSurface WIN_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *windowdata = window->internal; diff --git a/src/video/windows/SDL_windowsopengles.h b/src/video/windows/SDL_windowsopengles.h index 3c28064bc0..92ae899c2f 100644 --- a/src/video/windows/SDL_windowsopengles.h +++ b/src/video/windows/SDL_windowsopengles.h @@ -35,12 +35,12 @@ #define WIN_GLES_GetSwapInterval SDL_EGL_GetSwapInterval #define WIN_GLES_SetSwapInterval SDL_EGL_SetSwapInterval -extern int WIN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool WIN_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_GLContext WIN_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int WIN_GLES_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); -extern int WIN_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool WIN_GLES_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool WIN_GLES_SetupWindow(SDL_VideoDevice *_this, SDL_Window *window); extern SDL_EGLSurface WIN_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_VIDEO_OPENGL_EGL diff --git a/src/video/windows/SDL_windowsrawinput.c b/src/video/windows/SDL_windowsrawinput.c index 116a615c61..77c226f12f 100644 --- a/src/video/windows/SDL_windowsrawinput.c +++ b/src/video/windows/SDL_windowsrawinput.c @@ -131,9 +131,9 @@ static void CleanupRawInputThreadData(RawInputThreadData *data) } } -static int WIN_SetRawInputEnabled(SDL_VideoDevice *_this, Uint32 flags) +static bool WIN_SetRawInputEnabled(SDL_VideoDevice *_this, Uint32 flags) { - int result = -1; + bool result = false; CleanupRawInputThreadData(&thread_data); @@ -167,19 +167,19 @@ static int WIN_SetRawInputEnabled(SDL_VideoDevice *_this, Uint32 flags) SDL_SetError("Couldn't set up raw input handling"); goto done; } - result = 0; + result = true; } else { - result = 0; + result = true; } done: - if (result < 0) { + if (!result) { CleanupRawInputThreadData(&thread_data); } return result; } -static int WIN_UpdateRawInputEnabled(SDL_VideoDevice *_this) +static bool WIN_UpdateRawInputEnabled(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; Uint32 flags = 0; @@ -190,59 +190,59 @@ static int WIN_UpdateRawInputEnabled(SDL_VideoDevice *_this) flags |= ENABLE_RAW_KEYBOARD_INPUT; } if (flags != data->raw_input_enabled) { - if (WIN_SetRawInputEnabled(_this, flags) == 0) { + if (WIN_SetRawInputEnabled(_this, flags)) { data->raw_input_enabled = flags; } else { - return -1; + return false; } } - return 0; + return true; } -int WIN_SetRawMouseEnabled(SDL_VideoDevice *_this, bool enabled) +bool WIN_SetRawMouseEnabled(SDL_VideoDevice *_this, bool enabled) { SDL_VideoData *data = _this->internal; data->raw_mouse_enabled = enabled; if (data->gameinput_context) { - if (WIN_UpdateGameInputEnabled(_this) < 0) { + if (!WIN_UpdateGameInputEnabled(_this)) { data->raw_mouse_enabled = !enabled; - return -1; + return false; } } else { - if (WIN_UpdateRawInputEnabled(_this) < 0) { + if (!WIN_UpdateRawInputEnabled(_this)) { data->raw_mouse_enabled = !enabled; - return -1; + return false; } } - return 0; + return true; } -int WIN_SetRawKeyboardEnabled(SDL_VideoDevice *_this, bool enabled) +bool WIN_SetRawKeyboardEnabled(SDL_VideoDevice *_this, bool enabled) { SDL_VideoData *data = _this->internal; data->raw_keyboard_enabled = enabled; if (data->gameinput_context) { - if (WIN_UpdateGameInputEnabled(_this) < 0) { + if (!WIN_UpdateGameInputEnabled(_this)) { data->raw_keyboard_enabled = !enabled; - return -1; + return false; } } else { - if (WIN_UpdateRawInputEnabled(_this) < 0) { + if (!WIN_UpdateRawInputEnabled(_this)) { data->raw_keyboard_enabled = !enabled; - return -1; + return false; } } - return 0; + return true; } #else -int WIN_SetRawMouseEnabled(SDL_VideoDevice *_this, bool enabled) +bool WIN_SetRawMouseEnabled(SDL_VideoDevice *_this, bool enabled) { return SDL_Unsupported(); } -int WIN_SetRawKeyboardEnabled(SDL_VideoDevice *_this, bool enabled) +bool WIN_SetRawKeyboardEnabled(SDL_VideoDevice *_this, bool enabled) { return SDL_Unsupported(); } diff --git a/src/video/windows/SDL_windowsrawinput.h b/src/video/windows/SDL_windowsrawinput.h index ddef47fbc5..a3f56c09ed 100644 --- a/src/video/windows/SDL_windowsrawinput.h +++ b/src/video/windows/SDL_windowsrawinput.h @@ -23,7 +23,7 @@ #ifndef SDL_windowsrawinput_h_ #define SDL_windowsrawinput_h_ -extern int WIN_SetRawMouseEnabled(SDL_VideoDevice *_this, bool enabled); -extern int WIN_SetRawKeyboardEnabled(SDL_VideoDevice *_this, bool enabled); +extern bool WIN_SetRawMouseEnabled(SDL_VideoDevice *_this, bool enabled); +extern bool WIN_SetRawKeyboardEnabled(SDL_VideoDevice *_this, bool enabled); #endif // SDL_windowsrawinput_h_ diff --git a/src/video/windows/SDL_windowsshape.c b/src/video/windows/SDL_windowsshape.c index 7a11e5909b..7585655d4b 100644 --- a/src/video/windows/SDL_windowsshape.c +++ b/src/video/windows/SDL_windowsshape.c @@ -69,7 +69,7 @@ static HRGN GenerateSpanListRegion(SDL_Surface *shape, int offset_x, int offset_ return mask; } -int WIN_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape) +bool WIN_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape) { SDL_WindowData *data = window->internal; HRGN mask = NULL; @@ -82,11 +82,11 @@ int WIN_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfac if (shape->w != window->w || shape->h != window->h) { stretched = SDL_CreateSurface(window->w, window->h, SDL_PIXELFORMAT_ARGB32); if (!stretched) { - return -1; + return false; } - if (SDL_SoftStretch(shape, NULL, stretched, NULL, SDL_SCALEMODE_LINEAR) < 0) { + if (!SDL_SoftStretch(shape, NULL, stretched, NULL, SDL_SCALEMODE_LINEAR)) { SDL_DestroySurface(stretched); - return -1; + return false; } shape = stretched; } @@ -120,7 +120,7 @@ int WIN_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfac if (!SetWindowRgn(data->hwnd, mask, TRUE)) { return WIN_SetError("SetWindowRgn failed"); } - return 0; + return true; } #endif // defined(SDL_VIDEO_DRIVER_WINDOWS) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) diff --git a/src/video/windows/SDL_windowsshape.h b/src/video/windows/SDL_windowsshape.h index 7bffbc4833..cc9955f3dc 100644 --- a/src/video/windows/SDL_windowsshape.h +++ b/src/video/windows/SDL_windowsshape.h @@ -23,6 +23,6 @@ #ifndef SDL_windowsshape_h_ #define SDL_windowsshape_h_ -extern int WIN_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); +extern bool WIN_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); #endif // SDL_windowsshape_h_ diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 0eac38b50d..e2004d9682 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -43,7 +43,7 @@ // #define HIGHDPI_DEBUG // Initialization/Query functions -static int WIN_VideoInit(SDL_VideoDevice *_this); +static bool WIN_VideoInit(SDL_VideoDevice *_this); static void WIN_VideoQuit(SDL_VideoDevice *_this); // Hints @@ -74,14 +74,14 @@ static void SDLCALL UpdateWindowFrameUsableWhileCursorHidden(void *userdata, con } #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) -static int WIN_SuspendScreenSaver(SDL_VideoDevice *_this) +static bool WIN_SuspendScreenSaver(SDL_VideoDevice *_this) { if (_this->suspend_screensaver) { SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED); } else { SetThreadExecutionState(ES_CONTINUOUS); } - return 0; + return true; } #endif @@ -259,7 +259,7 @@ static SDL_VideoDevice *WIN_CreateDevice(void) device->GL_SetSwapInterval = WIN_GL_SetSwapInterval; device->GL_GetSwapInterval = WIN_GL_GetSwapInterval; device->GL_SwapWindow = WIN_GL_SwapWindow; - device->GL_DeleteContext = WIN_GL_DeleteContext; + device->GL_DestroyContext = WIN_GL_DestroyContext; device->GL_GetEGLSurface = NULL; #endif #ifdef SDL_VIDEO_OPENGL_EGL @@ -275,7 +275,7 @@ static SDL_VideoDevice *WIN_CreateDevice(void) device->GL_SetSwapInterval = WIN_GLES_SetSwapInterval; device->GL_GetSwapInterval = WIN_GLES_GetSwapInterval; device->GL_SwapWindow = WIN_GLES_SwapWindow; - device->GL_DeleteContext = WIN_GLES_DeleteContext; + device->GL_DestroyContext = WIN_GLES_DestroyContext; device->GL_GetEGLSurface = WIN_GLES_GetEGLSurface; #ifdef SDL_VIDEO_OPENGL_WGL } @@ -464,7 +464,7 @@ static void WIN_InitDPIAwareness(SDL_VideoDevice *_this) } } -int WIN_VideoInit(SDL_VideoDevice *_this) +static bool WIN_VideoInit(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; HRESULT hr; @@ -508,8 +508,8 @@ int WIN_VideoInit(SDL_VideoDevice *_this) SDL_AddBasicVideoDisplay(&mode); } #else // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) - if (WIN_InitModes(_this) < 0) { - return -1; + if (!WIN_InitModes(_this)) { + return false; } WIN_InitKeyboard(_this); @@ -529,7 +529,7 @@ int WIN_VideoInit(SDL_VideoDevice *_this) data->_SDL_WAKEUP = RegisterWindowMessageA("_SDL_WAKEUP"); #endif - return 0; + return true; } void WIN_VideoQuit(SDL_VideoDevice *_this) @@ -632,7 +632,7 @@ int SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID) IDirect3D9 *pD3D; if (!D3D_LoadDLL(&pD3DDLL, &pD3D)) { SDL_SetError("Unable to create Direct3D interface"); - return D3DADAPTER_DEFAULT; + return -1; } else { SDL_DisplayData *pData = SDL_GetDisplayDriverData(displayID); int adapterIndex = D3DADAPTER_DEFAULT; @@ -665,7 +665,7 @@ int SDL_GetDirect3D9AdapterIndex(SDL_DisplayID displayID) } #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) -int SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex) +SDL_bool SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outputIndex) { #ifndef HAVE_DXGI_H if (adapterIndex) { @@ -723,7 +723,7 @@ int SDL_GetDXGIOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int *outpu if (*adapterIndex == -1) { return SDL_SetError("Couldn't find matching adapter"); } - return 0; + return true; #endif } diff --git a/src/video/windows/SDL_windowsvulkan.c b/src/video/windows/SDL_windowsvulkan.c index 7ab469aa97..ad2a147668 100644 --- a/src/video/windows/SDL_windowsvulkan.c +++ b/src/video/windows/SDL_windowsvulkan.c @@ -35,7 +35,7 @@ #include "SDL_windowsvulkan.h" -int WIN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool WIN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { VkExtensionProperties *extensions = NULL; Uint32 extensionCount = 0; @@ -56,7 +56,7 @@ int WIN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) } _this->vulkan_config.loader_handle = SDL_LoadObject(path); if (!_this->vulkan_config.loader_handle) { - return -1; + return false; } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); @@ -94,12 +94,12 @@ int WIN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) SDL_SetError("Installed Vulkan doesn't implement the " VK_KHR_WIN32_SURFACE_EXTENSION_NAME "extension"); goto fail; } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void WIN_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -116,11 +116,13 @@ char const* const* WIN_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, static const char *const extensionsForWin32[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME }; - if(count) { *count = SDL_arraysize(extensionsForWin32); } + if (count) { + *count = SDL_arraysize(extensionsForWin32); + } return extensionsForWin32; } -int WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, @@ -153,7 +155,7 @@ int WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this, if (result != VK_SUCCESS) { return SDL_SetError("vkCreateWin32SurfaceKHR failed: %s", SDL_Vulkan_GetResultString(result)); } - return 0; + return true; } void WIN_Vulkan_DestroySurface(SDL_VideoDevice *_this, @@ -179,14 +181,11 @@ bool WIN_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, "vkGetPhysicalDeviceWin32PresentationSupportKHR"); if (!_this->vulkan_config.loader_handle) { - SDL_SetError("Vulkan is not loaded"); - return false; + return SDL_SetError("Vulkan is not loaded"); } if (!vkGetPhysicalDeviceWin32PresentationSupportKHR) { - SDL_SetError(VK_KHR_WIN32_SURFACE_EXTENSION_NAME - " extension is not enabled in the Vulkan instance."); - return false; + return SDL_SetError(VK_KHR_WIN32_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); } return vkGetPhysicalDeviceWin32PresentationSupportKHR(physicalDevice, diff --git a/src/video/windows/SDL_windowsvulkan.h b/src/video/windows/SDL_windowsvulkan.h index cd28d75d35..4b90b8da49 100644 --- a/src/video/windows/SDL_windowsvulkan.h +++ b/src/video/windows/SDL_windowsvulkan.h @@ -33,16 +33,15 @@ #if defined(SDL_VIDEO_VULKAN) && defined(SDL_VIDEO_DRIVER_WINDOWS) -int WIN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void WIN_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* WIN_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this, +extern bool WIN_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void WIN_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* WIN_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool WIN_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); -void WIN_Vulkan_DestroySurface(SDL_VideoDevice *_this, +extern void WIN_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 7d929f5a0d..ffbfb70ad4 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -182,7 +182,7 @@ static DWORD GetWindowStyleEx(SDL_Window *window) * Returns arguments to pass to SetWindowPos - the window rect, including frame, in Windows coordinates. * Can be called before we have a HWND. */ -static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, DWORD styleEx, BOOL menu, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type) +static bool WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, DWORD styleEx, BOOL menu, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type) { SDL_VideoData *videodata = SDL_GetVideoDevice() ? SDL_GetVideoDevice()->internal : NULL; RECT rect; @@ -259,10 +259,10 @@ static int WIN_AdjustWindowRectWithStyle(SDL_Window *window, DWORD style, DWORD (rect_type == SDL_WINDOWRECT_FLOATING ? window->floating.h : rect_type == SDL_WINDOWRECT_WINDOWED ? window->windowed.h : window->h), *x, *y, *width, *height, frame_dpi); #endif - return 0; + return true; } -int WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type) +bool WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type) { SDL_WindowData *data = window->internal; HWND hwnd = data->hwnd; @@ -279,7 +279,7 @@ int WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *he return WIN_AdjustWindowRectWithStyle(window, style, styleEx, menu, x, y, width, height, rect_type); } -int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi) +bool WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi) { SDL_VideoDevice *videodevice = SDL_GetVideoDevice(); SDL_VideoData *videodata = videodevice ? videodevice->internal : NULL; @@ -311,10 +311,10 @@ int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi) } } #endif - return 0; + return true; } -int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect rect_type) +bool WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect rect_type) { SDL_Window *child_window; SDL_WindowData *data = window->internal; @@ -322,7 +322,7 @@ int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect HWND top; int x, y; int w, h; - int result = 0; + bool result = true; // Figure out what the window area will be if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_ALWAYS_ON_TOP)) { @@ -341,8 +341,8 @@ int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect // Update any child windows for (child_window = window->first_child; child_window; child_window = child_window->next_sibling) { - if (WIN_SetWindowPositionInternal(child_window, flags, SDL_WINDOWRECT_CURRENT) < 0) { - result = -1; + if (!WIN_SetWindowPositionInternal(child_window, flags, SDL_WINDOWRECT_CURRENT)) { + result = false; } } return result; @@ -378,7 +378,7 @@ static SDL_WindowEraseBackgroundMode GetEraseBackgroundModeHint(void) return mode; } -static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd, HWND parent) +static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd, HWND parent) { SDL_VideoData *videodata = _this->internal; SDL_WindowData *data; @@ -386,7 +386,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd // Allocate the window data data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } data->window = window; data->hwnd = hwnd; @@ -580,7 +580,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, HWND hwnd SDL_SetPointerProperty(props, SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER, data->hinstance); // All done! - return 0; + return true; } static void CleanupWindowData(SDL_VideoDevice *_this, SDL_Window *window) @@ -677,15 +677,15 @@ static void WIN_SetKeyboardFocus(SDL_Window *window) SDL_SetKeyboardFocus(window); } -int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { HWND hwnd = (HWND)SDL_GetPointerProperty(create_props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, SDL_GetPointerProperty(create_props, "sdl2-compat.external_window", NULL)); HWND parent = NULL; if (hwnd) { window->flags |= SDL_WINDOW_EXTERNAL; - if (SetupWindowData(_this, window, hwnd, parent) < 0) { - return -1; + if (!SetupWindowData(_this, window, hwnd, parent)) { + return false; } } else { DWORD style = STYLE_BASIC; @@ -716,12 +716,12 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI WIN_PumpEvents(_this); - if (SetupWindowData(_this, window, hwnd, parent) < 0) { + if (!SetupWindowData(_this, window, hwnd, parent)) { DestroyWindow(hwnd); if (parent) { DestroyWindow(parent); } - return -1; + return false; } // Inform Windows of the frame change so we can respond to WM_NCCALCSIZE @@ -777,7 +777,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI } } else { if (!(window->flags & SDL_WINDOW_OPENGL)) { - return 0; + return true; } // The rest of this macro mess is for OpenGL or OpenGL ES windows @@ -789,11 +789,11 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI #endif // SDL_VIDEO_OPENGL_WGL ) { #ifdef SDL_VIDEO_OPENGL_EGL - if (WIN_GLES_SetupWindow(_this, window) < 0) { + if (!WIN_GLES_SetupWindow(_this, window)) { WIN_DestroyWindow(_this, window); - return -1; + return false; } - return 0; + return true; #else return SDL_SetError("Could not create GLES window surface (EGL support not configured)"); #endif // SDL_VIDEO_OPENGL_EGL @@ -801,9 +801,9 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI #endif // SDL_VIDEO_OPENGL_ES2 #ifdef SDL_VIDEO_OPENGL_WGL - if (WIN_GL_SetupWindow(_this, window) < 0) { + if (!WIN_GL_SetupWindow(_this, window)) { WIN_DestroyWindow(_this, window); - return -1; + return false; } #else return SDL_SetError("Could not create GL window (WGL support not configured)"); @@ -811,7 +811,7 @@ int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI } #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) - return 0; + return true; } void WIN_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) @@ -824,7 +824,7 @@ void WIN_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window) #endif } -int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon) +bool WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon) { #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) HWND hwnd = window->internal->hwnd; @@ -834,7 +834,7 @@ int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i BITMAPINFOHEADER *bmi; Uint8 *dst; bool isstack; - int retval = 0; + bool result = true; // Create temporary buffer for ICONIMAGE structure SDL_COMPILE_TIME_ASSERT(WIN_SetWindowIcon_uses_BITMAPINFOHEADER_to_prepare_an_ICONIMAGE, sizeof(BITMAPINFOHEADER) == 40); @@ -875,7 +875,7 @@ int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i SDL_small_free(icon_bmp, isstack); if (!hicon) { - retval = SDL_SetError("SetWindowIcon() failed, error %08X", (unsigned int)GetLastError()); + result = SDL_SetError("SetWindowIcon() failed, error %08X", (unsigned int)GetLastError()); } // Set the icon for the window @@ -883,13 +883,13 @@ int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i // Set the icon in the task manager (should we do this?) SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hicon); - return retval; + return result; #else return SDL_Unsupported(); #endif } -int WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { /* HighDPI support: removed SWP_NOSIZE. If the move results in a DPI change, we need to allow * the window to resize (e.g. AdjustWindowRectExForDpi frame sizes are different). @@ -907,7 +907,7 @@ int WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) return SDL_UpdateFullscreenMode(window, true, true); } - return 0; + return true; } void WIN_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) @@ -919,7 +919,7 @@ void WIN_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) } } -int WIN_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right) +bool WIN_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right) { #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) HWND hwnd = window->internal->hwnd; @@ -934,7 +934,7 @@ int WIN_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *to *bottom = rcClient.bottom; *right = rcClient.right; - return 0; + return true; #else // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) HWND hwnd = window->internal->hwnd; RECT rcClient, rcWindow; @@ -982,7 +982,7 @@ int WIN_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *to *bottom = rcWindow.bottom - rcClient.bottom; *right = rcWindow.right - rcClient.right; - return 0; + return true; #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) } @@ -1241,7 +1241,7 @@ static COLORREF WIN_UpdateBorderColorForHWND(HWND hwnd, COLORREF colorRef) /** * Reconfigures the window to fill the given display, if fullscreen is true, otherwise restores the window. */ -int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) +SDL_FullscreenResult WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) SDL_DisplayData *displaydata = display->internal; @@ -1262,7 +1262,7 @@ int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vide * external windows may end up being overridden. */ if (!(window->flags & SDL_WINDOW_FULLSCREEN) && !fullscreen) { - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } if (SDL_ShouldAllowTopmost() && (window->flags & SDL_WINDOW_ALWAYS_ON_TOP)) { @@ -1277,7 +1277,7 @@ int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vide minfo.cbSize = sizeof(MONITORINFO); if (!GetMonitorInfo(displaydata->MonitorHandle, &minfo)) { SDL_SetError("GetMonitorInfo failed"); - return -1; + return SDL_FULLSCREEN_FAILED; } SDL_SendWindowEvent(window, fullscreen ? SDL_EVENT_WINDOW_ENTER_FULLSCREEN : SDL_EVENT_WINDOW_LEAVE_FULLSCREEN, 0, 0); @@ -1343,7 +1343,7 @@ int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vide #endif #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) @@ -1436,19 +1436,19 @@ void WIN_UngrabKeyboard(SDL_Window *window) } } -int WIN_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) +bool WIN_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) { WIN_UpdateClipCursor(window); - return 0; + return true; } -int WIN_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool WIN_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { WIN_UpdateClipCursor(window); - return 0; + return true; } -int WIN_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool WIN_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { if (grabbed) { WIN_GrabKeyboard(window); @@ -1456,7 +1456,7 @@ int WIN_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool g WIN_UngrabKeyboard(window); } - return 0; + return true; } #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) @@ -1468,14 +1468,14 @@ void WIN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) /* * Creates a HelperWindow used for DirectInput. */ -int SDL_HelperWindowCreate(void) +bool SDL_HelperWindowCreate(void) { HINSTANCE hInstance = GetModuleHandle(NULL); WNDCLASS wce; // Make sure window isn't created twice. if (SDL_HelperWindow != NULL) { - return 0; + return true; } // Create the class. @@ -1502,7 +1502,7 @@ int SDL_HelperWindowCreate(void) return WIN_SetError("Unable to create Helper Window"); } - return 0; + return true; } /* @@ -1656,16 +1656,16 @@ void WIN_UpdateClipCursor(SDL_Window *window) data->last_updated_clipcursor = SDL_GetTicks(); } -int WIN_SetWindowHitTest(SDL_Window *window, bool enabled) +bool WIN_SetWindowHitTest(SDL_Window *window, bool enabled) { - return 0; // just succeed, the real work is done elsewhere. + return true; // just succeed, the real work is done elsewhere. } #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) -int WIN_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) +bool WIN_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) { #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES) - return -1; + return false; #else const SDL_WindowData *data = window->internal; HWND hwnd = data->hwnd; @@ -1694,7 +1694,7 @@ int WIN_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opaci } } - return 0; + return true; #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) } @@ -2162,7 +2162,7 @@ void WIN_AcceptDragAndDrop(SDL_Window *window, bool accept) } } -int WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) +bool WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) { FLASHWINFO desc; @@ -2186,7 +2186,7 @@ int WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperati FlashWindowEx(&desc); - return 0; + return true; } void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y) @@ -2200,7 +2200,7 @@ void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y) SendMessage(data->hwnd, WM_POPUPSYSTEMMENU, 0, MAKELPARAM(pt.x, pt.y)); } -int WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable) +bool WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable) { SDL_WindowData *data = window->internal; HWND hwnd = data->hwnd; @@ -2222,7 +2222,7 @@ int WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focu } } - return 0; + return true; } #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) @@ -2240,7 +2240,7 @@ void WIN_UpdateDarkModeForHWND(HWND hwnd) } } -int WIN_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) +bool WIN_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) { #if !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) SDL_WindowData *modal_data = modal_window->internal; @@ -2249,7 +2249,7 @@ int WIN_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_ const DWORD style = GetWindowLong(modal_data->hwnd, GWL_STYLE); if (old_ptr == parent_hwnd) { - return 0; + return true; } // Reenable the old parent window. @@ -2274,7 +2274,7 @@ int WIN_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_ } #endif // !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_WINDOWS diff --git a/src/video/windows/SDL_windowswindow.h b/src/video/windows/SDL_windowswindow.h index d78537bcb1..84b57dc9d1 100644 --- a/src/video/windows/SDL_windowswindow.h +++ b/src/video/windows/SDL_windowswindow.h @@ -102,14 +102,14 @@ struct SDL_WindowData SDLDropTarget *drop_target; }; -extern int WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool WIN_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern void WIN_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); -extern int WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); +extern bool WIN_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); extern void WIN_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right); +extern bool WIN_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right); extern void WIN_GetWindowSizeInPixels(SDL_VideoDevice *_this, SDL_Window *window, int *width, int *height); -extern int WIN_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); +extern bool WIN_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); extern void WIN_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void WIN_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void WIN_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window); @@ -119,25 +119,25 @@ extern void WIN_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void WIN_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); extern void WIN_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); extern void WIN_SetWindowAlwaysOnTop(SDL_VideoDevice *_this, SDL_Window *window, bool on_top); -extern int WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +extern SDL_FullscreenResult WIN_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); extern void WIN_UpdateWindowICCProfile(SDL_Window *window, bool send_event); extern void *WIN_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t *size); -extern int WIN_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); -extern int WIN_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); -extern int WIN_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool WIN_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WIN_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool WIN_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); extern void WIN_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void WIN_OnWindowEnter(SDL_VideoDevice *_this, SDL_Window *window); extern void WIN_UpdateClipCursor(SDL_Window *window); -extern int WIN_SetWindowHitTest(SDL_Window *window, bool enabled); +extern bool WIN_SetWindowHitTest(SDL_Window *window, bool enabled); extern void WIN_AcceptDragAndDrop(SDL_Window *window, bool accept); -extern int WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); +extern bool WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); extern void WIN_UpdateDarkModeForHWND(HWND hwnd); -extern int WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect rect_type); +extern bool WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect rect_type); extern void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y); -extern int WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); -extern int WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type); -extern int WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi); -extern int WIN_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); +extern bool WIN_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); +extern bool WIN_AdjustWindowRect(SDL_Window *window, int *x, int *y, int *width, int *height, SDL_WindowRect rect_type); +extern bool WIN_AdjustWindowRectForHWND(HWND hwnd, LPRECT lpRect, UINT frame_dpi); +extern bool WIN_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); // Ends C function definitions when using C++ #ifdef __cplusplus diff --git a/src/video/winrt/SDL_winrtmessagebox.cpp b/src/video/winrt/SDL_winrtmessagebox.cpp index 0e5abc84d5..59c025c452 100644 --- a/src/video/winrt/SDL_winrtmessagebox.cpp +++ b/src/video/winrt/SDL_winrtmessagebox.cpp @@ -40,7 +40,8 @@ static String ^ WINRT_UTF8ToPlatformString(const char *str) { return rtstr; } -extern "C" int WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +extern "C" +bool WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { #if SDL_WINAPI_FAMILY_PHONE && NTDDI_VERSION == NTDDI_WIN8 /* Sadly, Windows Phone 8 doesn't include the MessageDialog class that @@ -104,7 +105,7 @@ extern "C" int WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, in int clicked_index = results.ToInt32(); *buttonID = messageboxdata->buttons[clicked_index].buttonID; } - return 0; + return true; #endif // if SDL_WINAPI_FAMILY_PHONE / else } diff --git a/src/video/winrt/SDL_winrtmessagebox.h b/src/video/winrt/SDL_winrtmessagebox.h index c53667d1e4..c34707f47c 100644 --- a/src/video/winrt/SDL_winrtmessagebox.h +++ b/src/video/winrt/SDL_winrtmessagebox.h @@ -22,6 +22,6 @@ #ifdef SDL_VIDEO_DRIVER_WINRT -extern int WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool WINRT_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_WINRT diff --git a/src/video/winrt/SDL_winrtmouse.cpp b/src/video/winrt/SDL_winrtmouse.cpp index ce89a41357..a6e5adda46 100644 --- a/src/video/winrt/SDL_winrtmouse.cpp +++ b/src/video/winrt/SDL_winrtmouse.cpp @@ -146,11 +146,11 @@ static void WINRT_FreeCursor(SDL_Cursor *cursor) SDL_free(cursor); } -static int WINRT_ShowCursor(SDL_Cursor *cursor) +static bool WINRT_ShowCursor(SDL_Cursor *cursor) { // TODO, WinRT, XAML: make WINRT_ShowCursor work when XAML support is enabled. if (!CoreWindow::GetForCurrentThread()) { - return 0; + return true; } CoreWindow ^ coreWindow = CoreWindow::GetForCurrentThread(); @@ -217,13 +217,13 @@ static int WINRT_ShowCursor(SDL_Cursor *cursor) coreWindow->PointerCursor = nullptr; } } - return 0; + return true; } -static int WINRT_SetRelativeMouseMode(bool enabled) +static bool WINRT_SetRelativeMouseMode(bool enabled) { WINRT_UsingRelativeMouseMode = enabled; - return 0; + return true; } void WINRT_InitMouse(SDL_VideoDevice *_this) diff --git a/src/video/winrt/SDL_winrtopengles.cpp b/src/video/winrt/SDL_winrtopengles.cpp index 1a6b7dca71..442014c9b8 100644 --- a/src/video/winrt/SDL_winrtopengles.cpp +++ b/src/video/winrt/SDL_winrtopengles.cpp @@ -51,13 +51,13 @@ static const int ANGLE_D3D_FEATURE_LEVEL_ANY = 0; * SDL/EGL top-level implementation */ -extern "C" int -WINRT_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +extern "C" +bool WINRT_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { SDL_VideoData *video_data = _this->internal; - if (SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0) != 0) { - return -1; + if (!SDL_EGL_LoadLibrary(_this, path, EGL_DEFAULT_DISPLAY, 0)) { + return false; } // Load ANGLE/WinRT-specific functions @@ -74,7 +74,7 @@ WINRT_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) Microsoft::WRL::ComPtr cpp_win = reinterpret_cast(native_win); HRESULT result = CreateWinrtEglWindow(cpp_win, ANGLE_D3D_FEATURE_LEVEL_ANY, &(video_data->winrtEglWindow)); if (FAILED(result)) { - return -1; + return false; } /* Call eglGetDisplay and eglInitialize as appropriate. On other @@ -180,11 +180,11 @@ WINRT_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) } } - return 0; + return true; } -extern "C" void -WINRT_GLES_UnloadLibrary(SDL_VideoDevice *_this) +extern "C" +void WINRT_GLES_UnloadLibrary(SDL_VideoDevice *_this) { SDL_VideoData *video_data = _this->internal; @@ -200,8 +200,8 @@ WINRT_GLES_UnloadLibrary(SDL_VideoDevice *_this) extern "C" { SDL_EGL_CreateContext_impl(WINRT) - SDL_EGL_SwapWindow_impl(WINRT) - SDL_EGL_MakeCurrent_impl(WINRT) +SDL_EGL_SwapWindow_impl(WINRT) +SDL_EGL_MakeCurrent_impl(WINRT) } #endif // SDL_VIDEO_DRIVER_WINRT && SDL_VIDEO_OPENGL_EGL diff --git a/src/video/winrt/SDL_winrtopengles.h b/src/video/winrt/SDL_winrtopengles.h index d7336dd328..33fb8c49a1 100644 --- a/src/video/winrt/SDL_winrtopengles.h +++ b/src/video/winrt/SDL_winrtopengles.h @@ -33,13 +33,13 @@ #define WINRT_GLES_GetProcAddress SDL_EGL_GetProcAddressInternal #define WINRT_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define WINRT_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -#define WINRT_GLES_DeleteContext SDL_EGL_DeleteContext +#define WINRT_GLES_DestroyContext SDL_EGL_DestroyContext -extern int WINRT_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool WINRT_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern void WINRT_GLES_UnloadLibrary(SDL_VideoDevice *_this); extern SDL_GLContext WINRT_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int WINRT_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int WINRT_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool WINRT_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool WINRT_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); #ifdef __cplusplus diff --git a/src/video/winrt/SDL_winrtvideo.cpp b/src/video/winrt/SDL_winrtvideo.cpp index aff8ae57e5..7b551c76c0 100644 --- a/src/video/winrt/SDL_winrtvideo.cpp +++ b/src/video/winrt/SDL_winrtvideo.cpp @@ -67,20 +67,20 @@ extern "C" { #include "SDL_winrtvideo_cpp.h" // Initialization/Query functions -static int WINRT_VideoInit(SDL_VideoDevice *_this); -static int WINRT_InitModes(SDL_VideoDevice *_this); -static int WINRT_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +static bool WINRT_VideoInit(SDL_VideoDevice *_this); +static bool WINRT_InitModes(SDL_VideoDevice *_this); +static bool WINRT_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); static void WINRT_VideoQuit(SDL_VideoDevice *_this); // Window functions -static int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +static bool WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); static void WINRT_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); -static int WINRT_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +static SDL_FullscreenResult WINRT_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); static void WINRT_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); // Misc functions static ABI::Windows::System::Display::IDisplayRequest *WINRT_CreateDisplayRequest(SDL_VideoDevice *_this); -extern int WINRT_SuspendScreenSaver(SDL_VideoDevice *_this); +extern bool WINRT_SuspendScreenSaver(SDL_VideoDevice *_this); // SDL-internal globals: SDL_Window *WINRT_GlobalSDLWindow = NULL; @@ -147,7 +147,7 @@ static SDL_VideoDevice *WINRT_CreateDevice(void) device->GL_SetSwapInterval = WINRT_GLES_SetSwapInterval; device->GL_GetSwapInterval = WINRT_GLES_GetSwapInterval; device->GL_SwapWindow = WINRT_GLES_SwapWindow; - device->GL_DeleteContext = WINRT_GLES_DeleteContext; + device->GL_DestroyContext = WINRT_GLES_DestroyContext; #endif device->free = WINRT_DeleteDevice; @@ -220,11 +220,11 @@ static void SDLCALL WINRT_SetDisplayOrientationsPreference(void *userdata, const WINRT_DISPLAY_PROPERTY(AutoRotationPreferences) = (DisplayOrientations)orientationFlags; } -int WINRT_VideoInit(SDL_VideoDevice *_this) +bool WINRT_VideoInit(SDL_VideoDevice *_this) { SDL_VideoData *internal = _this->internal; - if (WINRT_InitModes(_this) < 0) { - return -1; + if (!WINRT_InitModes(_this)) { + return false; } // Register the hint, SDL_HINT_ORIENTATIONS, with SDL. @@ -243,7 +243,7 @@ int WINRT_VideoInit(SDL_VideoDevice *_this) SDL_AddKeyboard(SDL_DEFAULT_KEYBOARD_ID, NULL, false); SDL_AddMouse(SDL_DEFAULT_MOUSE_ID, NULL, false); - return 0; + return true; } extern "C" SDL_PixelFormat D3D11_DXGIFormatToSDLPixelFormat(DXGI_FORMAT dxgiFormat); @@ -258,7 +258,7 @@ static void WINRT_DXGIModeToSDLDisplayMode(const DXGI_MODE_DESC *dxgiMode, SDL_D sdlMode->format = D3D11_DXGIFormatToSDLPixelFormat(dxgiMode->Format); } -static int WINRT_AddDisplaysForOutput(SDL_VideoDevice *_this, IDXGIAdapter1 *dxgiAdapter1, int outputIndex) +static bool WINRT_AddDisplaysForOutput(SDL_VideoDevice *_this, IDXGIAdapter1 *dxgiAdapter1, int outputIndex) { HRESULT hr; IDXGIOutput *dxgiOutput = NULL; @@ -266,7 +266,7 @@ static int WINRT_AddDisplaysForOutput(SDL_VideoDevice *_this, IDXGIAdapter1 *dxg SDL_VideoDisplay display; UINT numModes; DXGI_MODE_DESC *dxgiModes = NULL; - int functionResult = -1; // -1 for failure, 0 for success + bool result = false; DXGI_MODE_DESC modeToMatch, closestMatch; SDL_zero(display); @@ -341,7 +341,8 @@ static int WINRT_AddDisplaysForOutput(SDL_VideoDevice *_this, IDXGIAdapter1 *dxg goto done; } - functionResult = 0; // 0 for Success! + result = true; + done: if (dxgiModes) { SDL_free(dxgiModes); @@ -352,10 +353,10 @@ done: if (display.name) { SDL_free(display.name); } - return functionResult; + return result; } -static int WINRT_AddDisplaysForAdapter(SDL_VideoDevice *_this, IDXGIFactory2 *dxgiFactory2, int adapterIndex) +static bool WINRT_AddDisplaysForAdapter(SDL_VideoDevice *_this, IDXGIFactory2 *dxgiFactory2, int adapterIndex) { HRESULT hr; IDXGIAdapter1 *dxgiAdapter1; @@ -365,11 +366,11 @@ static int WINRT_AddDisplaysForAdapter(SDL_VideoDevice *_this, IDXGIFactory2 *dx if (hr != DXGI_ERROR_NOT_FOUND) { WIN_SetErrorFromHRESULT(__FUNCTION__ ", IDXGIFactory1::EnumAdapters1() failed", hr); } - return -1; + return false; } for (int outputIndex = 0;; ++outputIndex) { - if (WINRT_AddDisplaysForOutput(_this, dxgiAdapter1, outputIndex) < 0) { + if (!WINRT_AddDisplaysForOutput(_this, dxgiAdapter1, outputIndex)) { /* HACK: The Windows App Certification Kit 10.0 can fail, when running the Store Apps' test, "Direct3D Feature Test". The certification kit's error is: @@ -431,10 +432,10 @@ static int WINRT_AddDisplaysForAdapter(SDL_VideoDevice *_this, IDXGIFactory2 *dx } dxgiAdapter1->Release(); - return 0; + return true; } -int WINRT_InitModes(SDL_VideoDevice *_this) +bool WINRT_InitModes(SDL_VideoDevice *_this) { /* HACK: Initialize a single display, for whatever screen the app's CoreApplicationView is on. @@ -451,17 +452,17 @@ int WINRT_InitModes(SDL_VideoDevice *_this) } for (int adapterIndex = 0;; ++adapterIndex) { - if (WINRT_AddDisplaysForAdapter(_this, dxgiFactory2, adapterIndex) < 0) { + if (!WINRT_AddDisplaysForAdapter(_this, dxgiFactory2, adapterIndex)) { break; } } - return 0; + return true; } -static int WINRT_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) +static bool WINRT_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode) { - return 0; + return true; } void WINRT_VideoQuit(SDL_VideoDevice *_this) @@ -580,7 +581,7 @@ static bool WINRT_IsCoreWindowActive(CoreWindow ^ coreWindow) return true; } -int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { // Make sure that only one window gets created, at least until multimonitor // support is added. @@ -627,9 +628,9 @@ int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie * ANGLE/WinRT may require that a C++ object, ComPtr, * be passed into eglCreateWindowSurface. */ - if (SDL_EGL_ChooseConfig(_this) != 0) { + if (!SDL_EGL_ChooseConfig(_this)) { // SDL_EGL_ChooseConfig failed, SDL_GetError() should have info - return -1; + return false; } if (video_data->winrtEglWindow) { // ... is the 'old' version of ANGLE/WinRT being used? @@ -729,7 +730,7 @@ int WINRT_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie WINRT_GlobalSDLWindow = window; // All done! - return 0; + return true; } void WINRT_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) @@ -743,7 +744,7 @@ void WINRT_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) #endif } -int WINRT_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) +SDL_FullscreenResult WINRT_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen) { #if NTDDI_VERSION >= NTDDI_WIN10 SDL_WindowData *data = window->internal; @@ -751,7 +752,11 @@ int WINRT_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vi if (isWindowActive) { if (fullscreen) { if (!data->appView->IsFullScreenMode) { - return data->appView->TryEnterFullScreenMode() ? 0 : -1; + if (data->appView->TryEnterFullScreenMode()) { + return SDL_FULLSCREEN_SUCCEEDED; + } else { + return SDL_FULLSCREEN_FAILED; + } } } else { if (data->appView->IsFullScreenMode) { @@ -761,7 +766,7 @@ int WINRT_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_Vi } #endif - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } void WINRT_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -824,7 +829,7 @@ done: return pDisplayRequest; } -int WINRT_SuspendScreenSaver(SDL_VideoDevice *_this) +bool WINRT_SuspendScreenSaver(SDL_VideoDevice *_this) { SDL_VideoData *internal = _this->internal; if (internal && internal->displayRequest) { @@ -835,7 +840,7 @@ int WINRT_SuspendScreenSaver(SDL_VideoDevice *_this) displayRequest->RequestRelease(); } } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_WINRT diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c index d115582bc7..93b0debe34 100644 --- a/src/video/x11/SDL_x11clipboard.c +++ b/src/video/x11/SDL_x11clipboard.c @@ -61,7 +61,7 @@ static Window GetWindow(SDL_VideoDevice *_this) return data->clipboard_window; } -static int SetSelectionData(SDL_VideoDevice *_this, Atom selection, SDL_ClipboardDataCallback callback, +static bool SetSelectionData(SDL_VideoDevice *_this, Atom selection, SDL_ClipboardDataCallback callback, void *userdata, const char **mime_types, size_t mime_count, Uint32 sequence) { SDL_VideoData *videodata = _this->internal; @@ -83,7 +83,7 @@ static int SetSelectionData(SDL_VideoDevice *_this, Atom selection, SDL_Clipboar clipboard_owner = X11_XGetSelectionOwner(display, selection) == window; - // If we are cancelling our own data we need to clean it up + // If we are canceling our own data we need to clean it up if (clipboard_owner && clipboard->sequence == 0) { SDL_free(clipboard->userdata); } @@ -95,7 +95,7 @@ static int SetSelectionData(SDL_VideoDevice *_this, Atom selection, SDL_Clipboar clipboard->sequence = sequence; X11_XSetSelectionOwner(display, selection, window, CurrentTime); - return 0; + return true; } static void *CloneDataBuffer(const void *buffer, const size_t len) @@ -265,7 +265,7 @@ const char **X11_GetTextMimeTypes(SDL_VideoDevice *_this, size_t *num_mime_types return text_mime_types; } -int X11_SetClipboardData(SDL_VideoDevice *_this) +bool X11_SetClipboardData(SDL_VideoDevice *_this) { SDL_VideoData *videodata = _this->internal; Atom XA_CLIPBOARD = X11_XInternAtom(videodata->display, "CLIPBOARD", 0); @@ -298,7 +298,7 @@ bool X11_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type) return length > 0; } -int X11_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text) +bool X11_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text) { return SetSelectionData(_this, XA_PRIMARY, SDL_ClipboardTextCallback, SDL_strdup(text), text_mime_types, SDL_arraysize(text_mime_types), 0); } diff --git a/src/video/x11/SDL_x11clipboard.h b/src/video/x11/SDL_x11clipboard.h index b6c6fa42c9..cf9d07e705 100644 --- a/src/video/x11/SDL_x11clipboard.h +++ b/src/video/x11/SDL_x11clipboard.h @@ -34,10 +34,10 @@ typedef struct X11_ClipboardData { } SDLX11_ClipboardData; extern const char **X11_GetTextMimeTypes(SDL_VideoDevice *_this, size_t *num_mime_types); -extern int X11_SetClipboardData(SDL_VideoDevice *_this); +extern bool X11_SetClipboardData(SDL_VideoDevice *_this); extern void *X11_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length); extern bool X11_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type); -extern int X11_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text); +extern bool X11_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text); extern char *X11_GetPrimarySelectionText(SDL_VideoDevice *_this); extern bool X11_HasPrimarySelectionText(SDL_VideoDevice *_this); extern void X11_QuitClipboard(SDL_VideoDevice *_this); diff --git a/src/video/x11/SDL_x11dyn.c b/src/video/x11/SDL_x11dyn.c index d6152f91fc..e2220e526e 100644 --- a/src/video/x11/SDL_x11dyn.c +++ b/src/video/x11/SDL_x11dyn.c @@ -144,9 +144,9 @@ void SDL_X11_UnloadSymbols(void) } // returns non-zero if all needed symbols were loaded. -int SDL_X11_LoadSymbols(void) +bool SDL_X11_LoadSymbols(void) { - int rc = 1; // always succeed if not using Dynamic X11 stuff. + bool result = true; // always succeed if not using Dynamic X11 stuff. // deal with multiple modules (dga, x11, etc) needing these symbols... if (x11_load_refcount++ == 0) { @@ -179,7 +179,7 @@ int SDL_X11_LoadSymbols(void) } else { // in case something got loaded... SDL_X11_UnloadSymbols(); - rc = 0; + result = false; } #else // no dynamic X11 @@ -195,7 +195,7 @@ int SDL_X11_LoadSymbols(void) #endif } - return rc; + return result; } #endif // SDL_VIDEO_DRIVER_X11 diff --git a/src/video/x11/SDL_x11dyn.h b/src/video/x11/SDL_x11dyn.h index 2b95c40dbc..8c9757be6b 100644 --- a/src/video/x11/SDL_x11dyn.h +++ b/src/video/x11/SDL_x11dyn.h @@ -78,8 +78,8 @@ typedef Bool (*SDL_X11_XESetWireToEventRetType)(Display *, XEvent *, xEvent *); typedef int (*SDL_X11_XSynchronizeRetType)(Display *); typedef Status (*SDL_X11_XESetEventToWireRetType)(Display *, XEvent *, xEvent *); -int SDL_X11_LoadSymbols(void); -void SDL_X11_UnloadSymbols(void); +extern bool SDL_X11_LoadSymbols(void); +extern void SDL_X11_UnloadSymbols(void); // Declare all the function pointers and wrappers... #define SDL_X11_SYM(rc, fn, params, args, ret) \ diff --git a/src/video/x11/SDL_x11events.c b/src/video/x11/SDL_x11events.c index 8769a1c711..95d6d9bb34 100644 --- a/src/video/x11/SDL_x11events.c +++ b/src/video/x11/SDL_x11events.c @@ -2001,7 +2001,7 @@ void X11_PumpEvents(SDL_VideoDevice *_this) } } -int X11_SuspendScreenSaver(SDL_VideoDevice *_this) +bool X11_SuspendScreenSaver(SDL_VideoDevice *_this) { #ifdef SDL_VIDEO_DRIVER_X11_XSCRNSAVER SDL_VideoData *data = _this->internal; @@ -2011,7 +2011,7 @@ int X11_SuspendScreenSaver(SDL_VideoDevice *_this) #ifdef SDL_USE_LIBDBUS if (SDL_DBus_ScreensaverInhibit(_this->suspend_screensaver)) { - return 0; + return true; } if (_this->suspend_screensaver) { @@ -2031,7 +2031,7 @@ int X11_SuspendScreenSaver(SDL_VideoDevice *_this) X11_XScreenSaverSuspend(data->display, _this->suspend_screensaver); X11_XResetScreenSaver(data->display); - return 0; + return true; } #endif return SDL_Unsupported(); diff --git a/src/video/x11/SDL_x11events.h b/src/video/x11/SDL_x11events.h index fa30688bba..af3fe83f9a 100644 --- a/src/video/x11/SDL_x11events.h +++ b/src/video/x11/SDL_x11events.h @@ -26,7 +26,7 @@ extern void X11_PumpEvents(SDL_VideoDevice *_this); extern int X11_WaitEventTimeout(SDL_VideoDevice *_this, Sint64 timeoutNS); extern void X11_SendWakeupEvent(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_SuspendScreenSaver(SDL_VideoDevice *_this); +extern bool X11_SuspendScreenSaver(SDL_VideoDevice *_this); extern void X11_ReconcileKeyboardState(SDL_VideoDevice *_this); extern void X11_GetBorderValues(SDL_WindowData *data); extern void X11_HandleKeyEvent(SDL_VideoDevice *_this, SDL_WindowData *windowdata, SDL_KeyboardID keyboardID, XEvent *xevent); diff --git a/src/video/x11/SDL_x11framebuffer.c b/src/video/x11/SDL_x11framebuffer.c index 48d2a18f1d..948694af64 100644 --- a/src/video/x11/SDL_x11framebuffer.c +++ b/src/video/x11/SDL_x11framebuffer.c @@ -47,7 +47,7 @@ static bool have_mitshm(Display *dpy) #endif // !NO_SHARED_MEMORY -int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, +bool X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_PixelFormat *format, void **pixels, int *pitch) { SDL_WindowData *data = window->internal; @@ -69,7 +69,7 @@ int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_ } // Find out the pixel format and depth - if (X11_GetVisualInfoFromVisual(display, data->visual, &vinfo) < 0) { + if (!X11_GetVisualInfoFromVisual(display, data->visual, &vinfo)) { return SDL_SetError("Couldn't get window visual information"); } @@ -120,7 +120,7 @@ int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_ data->ximage->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN) ? MSBFirst : LSBFirst; data->use_mitshm = true; *pixels = shminfo->shmaddr; - return 0; + return true; } } } @@ -128,7 +128,7 @@ int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_ *pixels = SDL_malloc((size_t)h * (*pitch)); if (!*pixels) { - return -1; + return false; } data->ximage = X11_XCreateImage(display, data->visual, @@ -139,10 +139,10 @@ int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, SDL_ return SDL_SetError("Couldn't create XImage"); } data->ximage->byte_order = (SDL_BYTEORDER == SDL_BIG_ENDIAN) ? MSBFirst : LSBFirst; - return 0; + return true; } -int X11_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, +bool X11_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rects, int numrects) { SDL_WindowData *data = window->internal; @@ -218,7 +218,7 @@ int X11_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, cons X11_XSync(display, False); - return 0; + return true; } void X11_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/x11/SDL_x11framebuffer.h b/src/video/x11/SDL_x11framebuffer.h index 62bed1f24d..ea4bf34936 100644 --- a/src/video/x11/SDL_x11framebuffer.h +++ b/src/video/x11/SDL_x11framebuffer.h @@ -24,11 +24,11 @@ #include "SDL_internal.h" -extern int X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, - SDL_PixelFormat *format, - void **pixels, int *pitch); -extern int X11_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, - const SDL_Rect *rects, int numrects); +extern bool X11_CreateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, + SDL_PixelFormat *format, + void **pixels, int *pitch); +extern bool X11_UpdateWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window, + const SDL_Rect *rects, int numrects); extern void X11_DestroyWindowFramebuffer(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_x11framebuffer_h_ diff --git a/src/video/x11/SDL_x11keyboard.c b/src/video/x11/SDL_x11keyboard.c index fd178b79ce..1ec1df1d8c 100644 --- a/src/video/x11/SDL_x11keyboard.c +++ b/src/video/x11/SDL_x11keyboard.c @@ -123,7 +123,7 @@ KeySym X11_KeyCodeToSym(SDL_VideoDevice *_this, KeyCode keycode, unsigned char g return keysym; } -int X11_InitKeyboard(SDL_VideoDevice *_this) +bool X11_InitKeyboard(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; int i = 0; @@ -323,7 +323,7 @@ int X11_InitKeyboard(SDL_VideoDevice *_this) X11_ReconcileKeyboardState(_this); - return 0; + return true; } void X11_UpdateKeymap(SDL_VideoDevice *_this, bool send_event) @@ -421,28 +421,28 @@ static void X11_ResetXIM(SDL_VideoDevice *_this, SDL_Window *window) #endif } -int X11_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) +bool X11_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props) { X11_ResetXIM(_this, window); return X11_UpdateTextInputArea(_this, window); } -int X11_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) +bool X11_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window) { X11_ResetXIM(_this, window); #ifdef SDL_USE_IME SDL_IME_Reset(); #endif - return 0; + return true; } -int X11_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) +bool X11_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window) { #ifdef SDL_USE_IME SDL_IME_UpdateTextInputArea(window); #endif - return 0; + return true; } bool X11_HasScreenKeyboardSupport(SDL_VideoDevice *_this) diff --git a/src/video/x11/SDL_x11keyboard.h b/src/video/x11/SDL_x11keyboard.h index 5de4fd44ac..8c57b6d0a2 100644 --- a/src/video/x11/SDL_x11keyboard.h +++ b/src/video/x11/SDL_x11keyboard.h @@ -23,12 +23,12 @@ #ifndef SDL_x11keyboard_h_ #define SDL_x11keyboard_h_ -extern int X11_InitKeyboard(SDL_VideoDevice *_this); +extern bool X11_InitKeyboard(SDL_VideoDevice *_this); extern void X11_UpdateKeymap(SDL_VideoDevice *_this, bool send_event); extern void X11_QuitKeyboard(SDL_VideoDevice *_this); -extern int X11_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); -extern int X11_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); +extern bool X11_StartTextInput(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); +extern bool X11_StopTextInput(SDL_VideoDevice *_this, SDL_Window *window); +extern bool X11_UpdateTextInputArea(SDL_VideoDevice *_this, SDL_Window *window); extern bool X11_HasScreenKeyboardSupport(SDL_VideoDevice *_this); extern void X11_ShowScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID props); extern void X11_HideScreenKeyboard(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/src/video/x11/SDL_x11messagebox.c b/src/video/x11/SDL_x11messagebox.c index 1073d2ddbe..ae5d61c728 100644 --- a/src/video/x11/SDL_x11messagebox.c +++ b/src/video/x11/SDL_x11messagebox.c @@ -165,7 +165,7 @@ static int GetHitButtonIndex(SDL_MessageBoxDataX11 *data, int x, int y) } // Initialize SDL_MessageBoxData structure and Display, etc. -static int X11_MessageBoxInit(SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData *messageboxdata, int *pbuttonid) +static bool X11_MessageBoxInit(SDL_MessageBoxDataX11 *data, const SDL_MessageBoxData *messageboxdata, int *pbuttonid) { int i; int numbuttons = messageboxdata->numbuttons; @@ -220,22 +220,22 @@ static int X11_MessageBoxInit(SDL_MessageBoxDataX11 *data, const SDL_MessageBoxD data->color[i] = SDL_MAKE_RGB(colorhints[i].r, colorhints[i].g, colorhints[i].b); } - return 0; + return true; } static int CountLinesOfText(const char *text) { - int retval = 0; + int result = 0; while (text && *text) { const char *lf = SDL_strchr(text, '\n'); - retval++; // even without an endline, this counts as a line. + result++; // even without an endline, this counts as a line. text = lf ? lf + 1 : NULL; } - return retval; + return result; } // Calculate and initialize text and button locations. -static int X11_MessageBoxInitPositions(SDL_MessageBoxDataX11 *data) +static bool X11_MessageBoxInitPositions(SDL_MessageBoxDataX11 *data) { int i; int ybuttons; @@ -251,7 +251,7 @@ static int X11_MessageBoxInitPositions(SDL_MessageBoxDataX11 *data) TextLineData *plinedata = (TextLineData *)SDL_malloc(sizeof(TextLineData) * linecount); if (!plinedata) { - return -1; + return false; } data->linedata = plinedata; @@ -361,7 +361,7 @@ static int X11_MessageBoxInitPositions(SDL_MessageBoxDataX11 *data) } } - return 0; + return true; } // Free SDL_MessageBoxData data. @@ -398,7 +398,7 @@ static void X11_MessageBoxShutdown(SDL_MessageBoxDataX11 *data) } // Create and set up our X11 dialog box indow. -static int X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data) +static bool X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data) { int x, y; XSizeHints *sizehints; @@ -516,7 +516,7 @@ static int X11_MessageBoxCreateWindow(SDL_MessageBoxDataX11 *data) } #endif - return 0; + return true; } // Draw our message box. @@ -606,7 +606,7 @@ static Bool X11_MessageBoxEventTest(Display *display, XEvent *event, XPointer ar } // Loop and handle message box event messages until something kills it. -static int X11_MessageBoxLoop(SDL_MessageBoxDataX11 *data) +static bool X11_MessageBoxLoop(SDL_MessageBoxDataX11 *data) { GC ctx; XGCValues ctx_vals; @@ -758,12 +758,12 @@ static int X11_MessageBoxLoop(SDL_MessageBoxDataX11 *data) } X11_XFreeGC(data->display, ctx); - return 0; + return true; } -static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID) +static bool X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID) { - int ret; + bool result = false; SDL_MessageBoxDataX11 data; #if SDL_SET_LOCALE char *origlocale; @@ -772,7 +772,7 @@ static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int SDL_zero(data); if (!SDL_X11_LoadSymbols()) { - return -1; + return false; } #if SDL_SET_LOCALE @@ -780,7 +780,7 @@ static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int if (origlocale) { origlocale = SDL_strdup(origlocale); if (!origlocale) { - return -1; + return false; } (void)setlocale(LC_ALL, ""); } @@ -793,15 +793,10 @@ static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int *buttonID = -1; // Init and display the message box. - ret = X11_MessageBoxInit(&data, messageboxdata, buttonID); - if (ret != -1) { - ret = X11_MessageBoxInitPositions(&data); - if (ret != -1) { - ret = X11_MessageBoxCreateWindow(&data); - if (ret != -1) { - ret = X11_MessageBoxLoop(&data); - } - } + if (X11_MessageBoxInit(&data, messageboxdata, buttonID) && + X11_MessageBoxInitPositions(&data) && + X11_MessageBoxCreateWindow(&data)) { + result = X11_MessageBoxLoop(&data); } X11_MessageBoxShutdown(&data); @@ -813,17 +808,18 @@ static int X11_ShowMessageBoxImpl(const SDL_MessageBoxData *messageboxdata, int } #endif - return ret; + return result; } // Display an x11 message box. -int X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) +bool X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) { #if SDL_FORK_MESSAGEBOX // Use a child process to protect against setlocale(). Annoying. pid_t pid; int fds[2]; int status = 0; + bool result = true; if (pipe(fds) == -1) { return X11_ShowMessageBoxImpl(messageboxdata, buttonID); // oh well. @@ -837,10 +833,10 @@ int X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) } else if (pid == 0) { // we're the child int exitcode = 0; close(fds[0]); - status = X11_ShowMessageBoxImpl(messageboxdata, buttonID); - if (write(fds[1], &status, sizeof(int)) != sizeof(int)) { + result = X11_ShowMessageBoxImpl(messageboxdata, buttonID); + if (write(fds[1], &result, sizeof(result)) != sizeof(result)) { exitcode = 1; - } else if (write(fds[1], buttonID, sizeof(int)) != sizeof(int)) { + } else if (write(fds[1], buttonID, sizeof(*buttonID)) != sizeof(*buttonID)) { exitcode = 1; } close(fds[1]); @@ -855,15 +851,15 @@ int X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID) SDL_assert(rc == pid); // not sure what to do if this fails. if ((rc == -1) || (!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) { - status = SDL_SetError("msgbox child process failed"); - } else if ((read(fds[0], &status, sizeof(int)) != sizeof(int)) || - (read(fds[0], buttonID, sizeof(int)) != sizeof(int))) { - status = SDL_SetError("read from msgbox child process failed"); + result = SDL_SetError("msgbox child process failed"); + } else if ((read(fds[0], &result, sizeof(result)) != sizeof(result)) || + (read(fds[0], buttonID, sizeof(*buttonID)) != sizeof(*buttonID))) { + result = SDL_SetError("read from msgbox child process failed"); *buttonID = 0; } close(fds[0]); - return status; + return result; } #else return X11_ShowMessageBoxImpl(messageboxdata, buttonID); diff --git a/src/video/x11/SDL_x11messagebox.h b/src/video/x11/SDL_x11messagebox.h index 25459e470e..3168625386 100644 --- a/src/video/x11/SDL_x11messagebox.h +++ b/src/video/x11/SDL_x11messagebox.h @@ -24,7 +24,7 @@ #ifdef SDL_VIDEO_DRIVER_X11 -extern int X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); +extern bool X11_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonID); #endif // SDL_VIDEO_DRIVER_X11 diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index 7d6100e033..1194af2c0e 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -263,7 +263,7 @@ static float GetGlobalContentScale(SDL_VideoDevice *_this) return (float)scale_factor; } -static int get_visualinfo(Display *display, int screen, XVisualInfo *vinfo) +static bool get_visualinfo(Display *display, int screen, XVisualInfo *vinfo) { const char *visual_id = SDL_GetHint(SDL_HINT_VIDEO_X11_VISUALID); int depth; @@ -279,7 +279,7 @@ static int get_visualinfo(Display *display, int screen, XVisualInfo *vinfo) if (vi) { *vinfo = *vi; X11_XFree(vi); - return 0; + return true; } } @@ -289,12 +289,12 @@ static int get_visualinfo(Display *display, int screen, XVisualInfo *vinfo) X11_XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) || X11_XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) || X11_XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) { - return 0; + return true; } - return -1; + return false; } -int X11_GetVisualInfoFromVisual(Display *display, Visual *visual, XVisualInfo *vinfo) +bool X11_GetVisualInfoFromVisual(Display *display, Visual *visual, XVisualInfo *vinfo) { XVisualInfo *vi; int nvis; @@ -304,9 +304,9 @@ int X11_GetVisualInfoFromVisual(Display *display, Visual *visual, XVisualInfo *v if (vi) { *vinfo = *vi; X11_XFree(vi); - return 0; + return true; } - return -1; + return false; } SDL_PixelFormat X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo) @@ -530,7 +530,7 @@ static void SetXRandRDisplayName(Display *dpy, Atom EDID, char *name, const size #endif } -static int X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int screen, RROutput outputid, XRRScreenResources *res, SDL_VideoDisplay *display, char *display_name, size_t display_name_size) +static bool X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int screen, RROutput outputid, XRRScreenResources *res, SDL_VideoDisplay *display, char *display_name, size_t display_name_size) { Atom EDID = X11_XInternAtom(dpy, "EDID", False); XRROutputInfo *output_info; @@ -549,16 +549,16 @@ static int X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int s int i, n; if (!display || !display_name) { - return -1; // invalid parameters + return false; // invalid parameters } - if (get_visualinfo(dpy, screen, &vinfo) < 0) { - return -1; // uh, skip this screen? + if (!get_visualinfo(dpy, screen, &vinfo)) { + return false; // uh, skip this screen? } pixelformat = X11_GetPixelFormatFromVisualInfo(dpy, &vinfo); if (SDL_ISPIXELFORMAT_INDEXED(pixelformat)) { - return -1; // Palettized video modes are no longer supported, ignore this one. + return false; // Palettized video modes are no longer supported, ignore this one. } scanline_pad = SDL_BYTESPERPIXEL(pixelformat) * 8; @@ -576,7 +576,7 @@ static int X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int s output_info = X11_XRRGetOutputInfo(dpy, res, outputid); if (!output_info || !output_info->crtc || output_info->connection == RR_Disconnected) { X11_XRRFreeOutputInfo(output_info); - return -1; // ignore this one. + return false; // ignore this one. } SDL_strlcpy(display_name, output_info->name, display_name_size); @@ -587,7 +587,7 @@ static int X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int s crtc = X11_XRRGetCrtcInfo(dpy, res, output_crtc); if (!crtc) { - return -1; // oh well, ignore it. + return false; // oh well, ignore it. } SDL_zero(mode); @@ -603,13 +603,13 @@ static int X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int s displaydata = (SDL_DisplayData *)SDL_calloc(1, sizeof(*displaydata)); if (!displaydata) { - return -1; + return false; } modedata = (SDL_DisplayModeData *)SDL_calloc(1, sizeof(SDL_DisplayModeData)); if (!modedata) { SDL_free(displaydata); - return -1; + return false; } modedata->xrandr_mode = modeID; @@ -635,33 +635,33 @@ static int X11_FillXRandRDisplayInfo(SDL_VideoDevice *_this, Display *dpy, int s display->content_scale = GetGlobalContentScale(_this); display->internal = displaydata; - return 0; + return true; } -static int X11_AddXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int screen, RROutput outputid, XRRScreenResources *res, bool send_event) +static bool X11_AddXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int screen, RROutput outputid, XRRScreenResources *res, bool send_event) { SDL_VideoDisplay display; char display_name[128]; - if (X11_FillXRandRDisplayInfo(_this, dpy, screen, outputid, res, &display, display_name, sizeof(display_name)) == -1) { - return 0; // failed to query data, skip this display + if (!X11_FillXRandRDisplayInfo(_this, dpy, screen, outputid, res, &display, display_name, sizeof(display_name))) { + return true; // failed to query data, skip this display } if (SDL_AddVideoDisplay(&display, send_event) == 0) { - return -1; + return false; } - return 0; + return true; } -static int X11_UpdateXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int screen, RROutput outputid, XRRScreenResources *res, SDL_VideoDisplay *existing_display) +static bool X11_UpdateXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int screen, RROutput outputid, XRRScreenResources *res, SDL_VideoDisplay *existing_display) { SDL_VideoDisplay display; char display_name[128]; - if (X11_FillXRandRDisplayInfo(_this, dpy, screen, outputid, res, &display, display_name, sizeof(display_name)) == -1) { - return -1; // failed to query current display state + if (!X11_FillXRandRDisplayInfo(_this, dpy, screen, outputid, res, &display, display_name, sizeof(display_name))) { + return false; // failed to query current display state } // update mode - this call takes ownership of display.desktop_mode.internal @@ -681,7 +681,7 @@ static int X11_UpdateXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int scr // SDL_DisplayData is updated piece-meal above, free our local copy of this data SDL_free( display.internal ); - return 0; + return true; } static void X11_HandleXRandROutputChange(SDL_VideoDevice *_this, const XRROutputChangeNotifyEvent *ev) @@ -715,7 +715,7 @@ static void X11_HandleXRandROutputChange(SDL_VideoDevice *_this, const XRROutput Display *dpy = ev->display; const int screen = DefaultScreen(dpy); XVisualInfo vinfo; - if (get_visualinfo(dpy, screen, &vinfo) == 0) { + if (get_visualinfo(dpy, screen, &vinfo)) { XRRScreenResources *res = X11_XRRGetScreenResourcesCurrent(dpy, RootWindow(dpy, screen)); if (!res || res->noutput == 0) { if (res) { @@ -727,8 +727,7 @@ static void X11_HandleXRandROutputChange(SDL_VideoDevice *_this, const XRROutput if (res) { if (display) { X11_UpdateXRandRDisplay(_this, dpy, screen, ev->output, res, display); - } - else { + } else { X11_AddXRandRDisplay(_this, dpy, screen, ev->output, res, true); } @@ -752,7 +751,7 @@ void X11_HandleXRandREvent(SDL_VideoDevice *_this, const XEvent *xevent) } } -static int X11_InitModes_XRandR(SDL_VideoDevice *_this) +static bool X11_InitModes_XRandR(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; Display *dpy = data->display; @@ -795,7 +794,7 @@ static int X11_InitModes_XRandR(SDL_VideoDevice *_this) (!looking_for_primary && (screen == default_screen) && (res->outputs[output] == primary))) { continue; } - if (X11_AddXRandRDisplay(_this, dpy, screen, res->outputs[output], res, false) == -1) { + if (!X11_AddXRandRDisplay(_this, dpy, screen, res->outputs[output], res, false)) { break; } } @@ -811,14 +810,14 @@ static int X11_InitModes_XRandR(SDL_VideoDevice *_this) return SDL_SetError("No available displays"); } - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_X11_XRANDR /* This is used if there's no better functionality--like XRandR--to use. It won't attempt to supply different display modes at all, but it can enumerate the current displays and their current sizes. */ -static int X11_InitModes_StdXlib(SDL_VideoDevice *_this) +static bool X11_InitModes_StdXlib(SDL_VideoDevice *_this) { // !!! FIXME: a lot of copy/paste from X11_InitModes_XRandR in this function. SDL_VideoData *data = _this->internal; @@ -836,7 +835,7 @@ static int X11_InitModes_StdXlib(SDL_VideoDevice *_this) // note that generally even if you have a multiple physical monitors, ScreenCount(dpy) still only reports ONE screen. - if (get_visualinfo(dpy, default_screen, &vinfo) < 0) { + if (!get_visualinfo(dpy, default_screen, &vinfo)) { return SDL_SetError("Failed to find an X11 visual for the primary display"); } @@ -852,13 +851,13 @@ static int X11_InitModes_StdXlib(SDL_VideoDevice *_this) displaydata = (SDL_DisplayData *)SDL_calloc(1, sizeof(*displaydata)); if (!displaydata) { - return -1; + return false; } modedata = (SDL_DisplayModeData *)SDL_calloc(1, sizeof(SDL_DisplayModeData)); if (!modedata) { SDL_free(displaydata); - return -1; + return false; } mode.internal = modedata; @@ -889,12 +888,12 @@ static int X11_InitModes_StdXlib(SDL_VideoDevice *_this) display.internal = displaydata; display.content_scale = GetGlobalContentScale(_this); if (SDL_AddVideoDisplay(&display, true) == 0) { - return -1; + return false; } - return 0; + return true; } -int X11_InitModes(SDL_VideoDevice *_this) +bool X11_InitModes(SDL_VideoDevice *_this) { /* XRandR is the One True Modern Way to do this on X11. If this fails, we just won't report any display modes except the current @@ -906,8 +905,8 @@ int X11_InitModes(SDL_VideoDevice *_this) // require at least XRandR v1.3 if (CheckXRandR(data->display, &xrandr_major, &xrandr_minor) && (xrandr_major >= 2 || (xrandr_major == 1 && xrandr_minor >= 3)) && - X11_InitModes_XRandR(_this) == 0) { - return 0; + X11_InitModes_XRandR(_this)) { + return true; } } #endif // SDL_VIDEO_DRIVER_X11_XRANDR @@ -916,7 +915,7 @@ int X11_InitModes(SDL_VideoDevice *_this) return X11_InitModes_StdXlib(_this); } -int X11_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display) +bool X11_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display) { #ifdef SDL_VIDEO_DRIVER_X11_XRANDR SDL_DisplayData *data = sdl_display->internal; @@ -961,7 +960,7 @@ int X11_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display) } } #endif // SDL_VIDEO_DRIVER_X11_XRANDR - return 0; + return true; } #ifdef SDL_VIDEO_DRIVER_X11_XRANDR @@ -980,7 +979,7 @@ static int SDL_XRRSetScreenSizeErrHandler(Display *d, XErrorEvent *e) } #endif -int X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_DisplayMode *mode) +bool X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_DisplayMode *mode) { SDL_VideoData *viddata = _this->internal; SDL_DisplayData *data = sdl_display->internal; @@ -1076,14 +1075,14 @@ int X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SD (void)data; #endif // SDL_VIDEO_DRIVER_X11_XRANDR - return 0; + return true; } void X11_QuitModes(SDL_VideoDevice *_this) { } -int X11_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect) +bool X11_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect) { SDL_DisplayData *data = sdl_display->internal; @@ -1091,33 +1090,33 @@ int X11_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, rect->y = data->y; rect->w = sdl_display->current_mode->w; rect->h = sdl_display->current_mode->h; - return 0; + return true; } -int X11_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect) +bool X11_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect) { SDL_VideoData *data = _this->internal; Display *display = data->display; Atom _NET_WORKAREA; - int status, real_format; - int retval = -1; + int real_format; Atom real_type; unsigned long items_read = 0, items_left = 0; unsigned char *propdata = NULL; + bool result = false; - if (X11_GetDisplayBounds(_this, sdl_display, rect) < 0) { - return -1; + if (!X11_GetDisplayBounds(_this, sdl_display, rect)) { + return false; } _NET_WORKAREA = X11_XInternAtom(display, "_NET_WORKAREA", False); - status = X11_XGetWindowProperty(display, DefaultRootWindow(display), + int status = X11_XGetWindowProperty(display, DefaultRootWindow(display), _NET_WORKAREA, 0L, 4L, False, XA_CARDINAL, &real_type, &real_format, &items_read, &items_left, &propdata); if ((status == Success) && (items_read >= 4)) { const long *p = (long *)propdata; const SDL_Rect usable = { (int)p[0], (int)p[1], (int)p[2], (int)p[3] }; - retval = 0; + result = true; if (!SDL_GetRectIntersection(rect, &usable, rect)) { SDL_zerop(rect); } @@ -1127,7 +1126,7 @@ int X11_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_dis X11_XFree(propdata); } - return retval; + return result; } #endif // SDL_VIDEO_DRIVER_X11 diff --git a/src/video/x11/SDL_x11modes.h b/src/video/x11/SDL_x11modes.h index f595289508..4c250b6a72 100644 --- a/src/video/x11/SDL_x11modes.h +++ b/src/video/x11/SDL_x11modes.h @@ -50,16 +50,16 @@ struct SDL_DisplayModeData #endif }; -extern int X11_InitModes(SDL_VideoDevice *_this); -extern int X11_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); -extern int X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); +extern bool X11_InitModes(SDL_VideoDevice *_this); +extern bool X11_GetDisplayModes(SDL_VideoDevice *_this, SDL_VideoDisplay *display); +extern bool X11_SetDisplayMode(SDL_VideoDevice *_this, SDL_VideoDisplay *display, SDL_DisplayMode *mode); extern void X11_QuitModes(SDL_VideoDevice *_this); // Some utility functions for working with visuals -extern int X11_GetVisualInfoFromVisual(Display *display, Visual *visual, XVisualInfo *vinfo); +extern bool X11_GetVisualInfoFromVisual(Display *display, Visual *visual, XVisualInfo *vinfo); extern SDL_PixelFormat X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo); -extern int X11_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect); -extern int X11_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect); +extern bool X11_GetDisplayBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect); +extern bool X11_GetDisplayUsableBounds(SDL_VideoDevice *_this, SDL_VideoDisplay *sdl_display, SDL_Rect *rect); #ifdef SDL_VIDEO_DRIVER_X11_XRANDR extern void X11_HandleXRandREvent(SDL_VideoDevice *_this, const XEvent *xevent); diff --git a/src/video/x11/SDL_x11mouse.c b/src/video/x11/SDL_x11mouse.c index 8e1ebb6c68..05b81210d5 100644 --- a/src/video/x11/SDL_x11mouse.c +++ b/src/video/x11/SDL_x11mouse.c @@ -290,7 +290,7 @@ static void X11_FreeCursor(SDL_Cursor *cursor) SDL_free(cursor); } -static int X11_ShowCursor(SDL_Cursor *cursor) +static bool X11_ShowCursor(SDL_Cursor *cursor) { Cursor x11_cursor = 0; @@ -320,7 +320,7 @@ static int X11_ShowCursor(SDL_Cursor *cursor) } X11_XFlush(display); } - return 0; + return true; } static void X11_WarpMouseInternal(Window xwindow, float x, float y) @@ -363,7 +363,7 @@ static void X11_WarpMouseInternal(Window xwindow, float x, float y) videodata->global_mouse_changed = true; } -static int X11_WarpMouse(SDL_Window *window, float x, float y) +static bool X11_WarpMouse(SDL_Window *window, float x, float y) { SDL_WindowData *data = window->internal; @@ -375,24 +375,24 @@ static int X11_WarpMouse(SDL_Window *window, float x, float y) #else X11_WarpMouseInternal(data->xwindow, x, y); #endif - return 0; + return true; } -static int X11_WarpMouseGlobal(float x, float y) +static bool X11_WarpMouseGlobal(float x, float y) { X11_WarpMouseInternal(DefaultRootWindow(GetDisplay()), x, y); - return 0; + return true; } -static int X11_SetRelativeMouseMode(bool enabled) +static bool X11_SetRelativeMouseMode(bool enabled) { if (!X11_Xinput2IsInitialized()) { return SDL_Unsupported(); } - return 0; + return true; } -static int X11_CaptureMouse(SDL_Window *window) +static bool X11_CaptureMouse(SDL_Window *window) { Display *display = GetDisplay(); SDL_Window *mouse_focus = SDL_GetMouseFocus(); @@ -421,7 +421,7 @@ static int X11_CaptureMouse(SDL_Window *window) X11_XSync(display, False); - return 0; + return true; } static SDL_MouseButtonFlags X11_GetGlobalMouseState(float *x, float *y) diff --git a/src/video/x11/SDL_x11opengl.c b/src/video/x11/SDL_x11opengl.c index d2a6c56ac1..8230c8d24e 100644 --- a/src/video/x11/SDL_x11opengl.c +++ b/src/video/x11/SDL_x11opengl.c @@ -161,7 +161,7 @@ typedef GLXContext (*PFNGLXCREATECONTEXTATTRIBSARBPROC)(Display *dpy, static void X11_GL_InitExtensions(SDL_VideoDevice *_this); -int X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) { Display *display; void *handle; @@ -182,7 +182,7 @@ int X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) #if defined(OPENGL_REQUIRES_DLOPEN) && defined(HAVE_DLOPEN) SDL_SetError("Failed loading %s: %s", path, dlerror()); #endif - return -1; + return false; } SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); @@ -193,7 +193,7 @@ int X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) sizeof(struct SDL_GLDriverData)); if (!_this->gl_data) { - return -1; + return false; } // Load function pointers @@ -262,14 +262,14 @@ int X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path) _this->GL_SetSwapInterval = X11_GLES_SetSwapInterval; _this->GL_GetSwapInterval = X11_GLES_GetSwapInterval; _this->GL_SwapWindow = X11_GLES_SwapWindow; - _this->GL_DeleteContext = X11_GLES_DeleteContext; + _this->GL_DestroyContext = X11_GLES_DestroyContext; return X11_GLES_LoadLibrary(_this, NULL); #else return SDL_SetError("SDL not configured with EGL support"); #endif } - return 0; + return true; } SDL_FunctionPointer X11_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc) @@ -693,7 +693,7 @@ static int X11_GL_ErrorHandler(Display *d, XErrorEvent *e) SDL_SetError("Could not %s: %i (Base %i)", errorHandlerOperation, errorCode, errorBase); } - return (0); + return 0; } bool X11_GL_UseEGL(SDL_VideoDevice *_this) @@ -835,15 +835,15 @@ SDL_GLContext X11_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window) return NULL; } - if (X11_GL_MakeCurrent(_this, window, context) < 0) { - X11_GL_DeleteContext(_this, context); + if (!X11_GL_MakeCurrent(_this, window, context)) { + X11_GL_DestroyContext(_this, context); return NULL; } return context; } -int X11_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) +bool X11_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context) { Display *display = _this->internal->display; Window drawable = @@ -865,12 +865,12 @@ int X11_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext X11_XSetErrorHandler(handler); if (errorCode != Success) { // uhoh, an X error was thrown! - return -1; // the error handler called SDL_SetError() already. + return false; // the error handler called SDL_SetError() already. } else if (!rc) { // glXMakeCurrent() failed without throwing an X error return SDL_SetError("Unable to make GL context current"); } - return 0; + return true; } /* @@ -882,9 +882,9 @@ int X11_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext */ static int swapinterval = 0; -int X11_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) +bool X11_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) { - int status = -1; + bool result = false; if ((interval < 0) && (!_this->gl_data->HAS_GLX_EXT_swap_control_tear)) { return SDL_SetError("Negative swap interval unsupported in this GL"); @@ -906,26 +906,28 @@ int X11_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval) X11_GL_GetSwapInterval(_this, ¤tInterval); _this->gl_data->glXSwapIntervalEXT(display, drawable, currentInterval); _this->gl_data->glXSwapIntervalEXT(display, drawable, interval); - status = 0; + result = true; swapinterval = interval; } else if (_this->gl_data->glXSwapIntervalMESA) { - status = _this->gl_data->glXSwapIntervalMESA(interval); - if (status != 0) { - SDL_SetError("glXSwapIntervalMESA failed"); - } else { + const int rc = _this->gl_data->glXSwapIntervalMESA(interval); + if (rc == 0) { swapinterval = interval; + result = true; + } else { + result = SDL_SetError("glXSwapIntervalMESA failed"); } } else if (_this->gl_data->glXSwapIntervalSGI) { - status = _this->gl_data->glXSwapIntervalSGI(interval); - if (status != 0) { - SDL_SetError("glXSwapIntervalSGI failed"); - } else { + const int rc = _this->gl_data->glXSwapIntervalSGI(interval); + if (rc == 0) { swapinterval = interval; + result = true; + } else { + result = SDL_SetError("glXSwapIntervalSGI failed"); } } else { return SDL_Unsupported(); } - return status; + return result; } static SDL_GLSwapIntervalTearBehavior CheckSwapIntervalTearBehavior(SDL_VideoDevice *_this, Window drawable, unsigned int current_val, unsigned int current_allow_late) @@ -975,7 +977,7 @@ static SDL_GLSwapIntervalTearBehavior CheckSwapIntervalTearBehavior(SDL_VideoDev } -int X11_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) +bool X11_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) { if (_this->gl_data->glXSwapIntervalEXT) { Display *display = _this->internal->display; @@ -1009,40 +1011,40 @@ int X11_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval) break; } - return 0; + return true; } else if (_this->gl_data->glXGetSwapIntervalMESA) { int val = _this->gl_data->glXGetSwapIntervalMESA(); if (val == GLX_BAD_CONTEXT) { return SDL_SetError("GLX_BAD_CONTEXT"); } *interval = val; - return 0; + return true; } else { *interval = swapinterval; - return 0; + return true; } } -int X11_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool X11_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window) { SDL_WindowData *data = window->internal; Display *display = data->videodata->display; _this->gl_data->glXSwapBuffers(display, data->xwindow); - return 0; + return true; } -int X11_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context) +bool X11_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context) { Display *display = _this->internal->display; GLXContext glx_context = (GLXContext)context; if (!_this->gl_data) { - return 0; + return true; } _this->gl_data->glXDestroyContext(display, glx_context); X11_XSync(display, False); - return 0; + return true; } #endif // SDL_VIDEO_OPENGL_GLX diff --git a/src/video/x11/SDL_x11opengl.h b/src/video/x11/SDL_x11opengl.h index 8810837f7c..7f13defd19 100644 --- a/src/video/x11/SDL_x11opengl.h +++ b/src/video/x11/SDL_x11opengl.h @@ -78,18 +78,18 @@ struct SDL_GLDriverData }; // OpenGL functions -extern int X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool X11_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern SDL_FunctionPointer X11_GL_GetProcAddress(SDL_VideoDevice *_this, const char *proc); extern void X11_GL_UnloadLibrary(SDL_VideoDevice *_this); extern bool X11_GL_UseEGL(SDL_VideoDevice *_this); extern XVisualInfo *X11_GL_GetVisual(SDL_VideoDevice *_this, Display *display, int screen, bool transparent); extern SDL_GLContext X11_GL_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, +extern bool X11_GL_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); -extern int X11_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); -extern int X11_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); -extern int X11_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_GL_DeleteContext(SDL_VideoDevice *_this, SDL_GLContext context); +extern bool X11_GL_SetSwapInterval(SDL_VideoDevice *_this, int interval); +extern bool X11_GL_GetSwapInterval(SDL_VideoDevice *_this, int *interval); +extern bool X11_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool X11_GL_DestroyContext(SDL_VideoDevice *_this, SDL_GLContext context); #endif // SDL_VIDEO_OPENGL_GLX diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c index 3c15ef4dea..ebb455c372 100644 --- a/src/video/x11/SDL_x11opengles.c +++ b/src/video/x11/SDL_x11opengles.c @@ -28,7 +28,7 @@ // EGL implementation of SDL OpenGL support -int X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) { SDL_VideoData *data = _this->internal; @@ -45,7 +45,7 @@ int X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path) _this->GL_SetSwapInterval = X11_GL_SetSwapInterval; _this->GL_GetSwapInterval = X11_GL_GetSwapInterval; _this->GL_SwapWindow = X11_GL_SwapWindow; - _this->GL_DeleteContext = X11_GL_DeleteContext; + _this->GL_DestroyContext = X11_GL_DestroyContext; return X11_GL_LoadLibrary(_this, path); #else return SDL_SetError("SDL not configured with OpenGL/GLX support"); @@ -124,6 +124,6 @@ SDL_EGLSurface X11_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window } SDL_EGL_SwapWindow_impl(X11) - SDL_EGL_MakeCurrent_impl(X11) +SDL_EGL_MakeCurrent_impl(X11) #endif // SDL_VIDEO_DRIVER_X11 && SDL_VIDEO_OPENGL_EGL diff --git a/src/video/x11/SDL_x11opengles.h b/src/video/x11/SDL_x11opengles.h index 25e152afa8..7c8e0df185 100644 --- a/src/video/x11/SDL_x11opengles.h +++ b/src/video/x11/SDL_x11opengles.h @@ -41,13 +41,13 @@ typedef struct SDL_PrivateGLESData #define X11_GLES_UnloadLibrary SDL_EGL_UnloadLibrary #define X11_GLES_SetSwapInterval SDL_EGL_SetSwapInterval #define X11_GLES_GetSwapInterval SDL_EGL_GetSwapInterval -#define X11_GLES_DeleteContext SDL_EGL_DeleteContext +#define X11_GLES_DestroyContext SDL_EGL_DestroyContext -extern int X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern bool X11_GLES_LoadLibrary(SDL_VideoDevice *_this, const char *path); extern XVisualInfo *X11_GLES_GetVisual(SDL_VideoDevice *_this, Display *display, int screen, bool transparent); extern SDL_GLContext X11_GLES_CreateContext(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); +extern bool X11_GLES_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool X11_GLES_MakeCurrent(SDL_VideoDevice *_this, SDL_Window *window, SDL_GLContext context); extern SDL_EGLSurface X11_GLES_GetEGLSurface(SDL_VideoDevice *_this, SDL_Window *window); #endif // SDL_VIDEO_OPENGL_EGL diff --git a/src/video/x11/SDL_x11shape.c b/src/video/x11/SDL_x11shape.c index 2d4be12045..af85c3b606 100644 --- a/src/video/x11/SDL_x11shape.c +++ b/src/video/x11/SDL_x11shape.c @@ -55,9 +55,9 @@ static Uint8 *GenerateShapeMask(SDL_Surface *shape) } #endif // SDL_VIDEO_DRIVER_X11_XSHAPE -int X11_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape) +bool X11_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape) { - int result = -1; + bool result = false; #ifdef SDL_VIDEO_DRIVER_X11_XSHAPE SDL_WindowData *windowdata = window->internal; @@ -71,11 +71,11 @@ int X11_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfac if (shape->w != window->w || shape->h != window->h) { stretched = SDL_CreateSurface(window->w, window->h, SDL_PIXELFORMAT_ARGB32); if (!stretched) { - return -1; + return false; } - if (SDL_SoftStretch(shape, NULL, stretched, NULL, SDL_SCALEMODE_LINEAR) < 0) { + if (!SDL_SoftStretch(shape, NULL, stretched, NULL, SDL_SCALEMODE_LINEAR)) { SDL_DestroySurface(stretched); - return -1; + return false; } shape = stretched; } @@ -86,7 +86,7 @@ int X11_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfac X11_XShapeCombineMask(windowdata->videodata->display, windowdata->xwindow, ShapeInput, 0, 0, pixmap, ShapeSet); SDL_free(mask); - result = 0; + result = true; } if (stretched) { @@ -103,7 +103,7 @@ int X11_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surfac X11_XUnionRectWithRegion(&rect, region, region); X11_XShapeCombineRegion(windowdata->videodata->display, windowdata->xwindow, ShapeInput, 0, 0, region, ShapeSet); X11_XDestroyRegion(region); - result = 0; + result = true; } #endif // SDL_VIDEO_DRIVER_X11_XSHAPE diff --git a/src/video/x11/SDL_x11shape.h b/src/video/x11/SDL_x11shape.h index 784a3ef9ab..69d92ca59a 100644 --- a/src/video/x11/SDL_x11shape.h +++ b/src/video/x11/SDL_x11shape.h @@ -23,6 +23,6 @@ #ifndef SDL_x11shape_h_ #define SDL_x11shape_h_ -extern int X11_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); +extern bool X11_UpdateWindowShape(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape); #endif // SDL_x11shape_h_ diff --git a/src/video/x11/SDL_x11video.c b/src/video/x11/SDL_x11video.c index b9b755729a..39eba0ff9f 100644 --- a/src/video/x11/SDL_x11video.c +++ b/src/video/x11/SDL_x11video.c @@ -44,7 +44,7 @@ #endif // Initialization/Query functions -static int X11_VideoInit(SDL_VideoDevice *_this); +static bool X11_VideoInit(SDL_VideoDevice *_this); static void X11_VideoQuit(SDL_VideoDevice *_this); // X11 driver bootstrap functions @@ -235,7 +235,7 @@ static SDL_VideoDevice *X11_CreateDevice(void) device->GL_SetSwapInterval = X11_GL_SetSwapInterval; device->GL_GetSwapInterval = X11_GL_GetSwapInterval; device->GL_SwapWindow = X11_GL_SwapWindow; - device->GL_DeleteContext = X11_GL_DeleteContext; + device->GL_DestroyContext = X11_GL_DestroyContext; device->GL_GetEGLSurface = NULL; #endif #ifdef SDL_VIDEO_OPENGL_EGL @@ -250,7 +250,7 @@ static SDL_VideoDevice *X11_CreateDevice(void) device->GL_SetSwapInterval = X11_GLES_SetSwapInterval; device->GL_GetSwapInterval = X11_GLES_GetSwapInterval; device->GL_SwapWindow = X11_GLES_SwapWindow; - device->GL_DeleteContext = X11_GLES_DeleteContext; + device->GL_DestroyContext = X11_GLES_DestroyContext; device->GL_GetEGLSurface = X11_GLES_GetEGLSurface; #ifdef SDL_VIDEO_OPENGL_GLX } @@ -376,7 +376,7 @@ static void X11_CheckWindowManager(SDL_VideoDevice *_this) #endif } -int X11_VideoInit(SDL_VideoDevice *_this) +static bool X11_VideoInit(SDL_VideoDevice *_this) { SDL_VideoData *data = _this->internal; @@ -429,8 +429,8 @@ int X11_VideoInit(SDL_VideoDevice *_this) // Detect the window manager X11_CheckWindowManager(_this); - if (X11_InitModes(_this) < 0) { - return -1; + if (!X11_InitModes(_this)) { + return false; } if (!X11_InitXinput2(_this)) { @@ -449,8 +449,8 @@ int X11_VideoInit(SDL_VideoDevice *_this) #warning X server does not support UTF8_STRING, a feature introduced in 2000! This is likely to become a hard error in a future libSDL3. #endif - if (X11_InitKeyboard(_this) != 0) { - return -1; + if (!X11_InitKeyboard(_this)) { + return false; } X11_InitMouse(_this); @@ -458,7 +458,7 @@ int X11_VideoInit(SDL_VideoDevice *_this) X11_InitPen(_this); - return 0; + return true; } void X11_VideoQuit(SDL_VideoDevice *_this) diff --git a/src/video/x11/SDL_x11vulkan.c b/src/video/x11/SDL_x11vulkan.c index d7821ddd59..f87b3db240 100644 --- a/src/video/x11/SDL_x11vulkan.c +++ b/src/video/x11/SDL_x11vulkan.c @@ -42,7 +42,7 @@ typedef uint32_t xcb_window_t; typedef uint32_t xcb_visualid_t; */ -int X11_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) +bool X11_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) { SDL_VideoData *videoData = _this->internal; VkExtensionProperties *extensions = NULL; @@ -65,7 +65,7 @@ int X11_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) } _this->vulkan_config.loader_handle = SDL_LoadObject(path); if (!_this->vulkan_config.loader_handle) { - return -1; + return false; } SDL_strlcpy(_this->vulkan_config.loader_path, path, SDL_arraysize(_this->vulkan_config.loader_path)); vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)SDL_LoadFunction( @@ -122,12 +122,12 @@ int X11_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path) goto fail; } } - return 0; + return true; fail: SDL_UnloadObject(_this->vulkan_config.loader_handle); _this->vulkan_config.loader_handle = NULL; - return -1; + return false; } void X11_Vulkan_UnloadLibrary(SDL_VideoDevice *_this) @@ -167,7 +167,7 @@ char const* const* X11_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, } } -int X11_Vulkan_CreateSurface(SDL_VideoDevice *_this, +bool X11_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, @@ -219,7 +219,7 @@ int X11_Vulkan_CreateSurface(SDL_VideoDevice *_this, } } - return 0; // success! + return true; // success! } void X11_Vulkan_DestroySurface(SDL_VideoDevice *_this, @@ -243,8 +243,7 @@ bool X11_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, VisualID visualid; if (!_this->vulkan_config.loader_handle) { - SDL_SetError("Vulkan is not loaded"); - return false; + return SDL_SetError("Vulkan is not loaded"); } vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)_this->vulkan_config.vkGetInstanceProcAddr; @@ -262,8 +261,7 @@ bool X11_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, "vkGetPhysicalDeviceXcbPresentationSupportKHR"); if (!vkGetPhysicalDeviceXcbPresentationSupportKHR) { - SDL_SetError(VK_KHR_XCB_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); - return false; + return SDL_SetError(VK_KHR_XCB_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); } return vkGetPhysicalDeviceXcbPresentationSupportKHR(physicalDevice, @@ -277,8 +275,7 @@ bool X11_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, "vkGetPhysicalDeviceXlibPresentationSupportKHR"); if (!vkGetPhysicalDeviceXlibPresentationSupportKHR) { - SDL_SetError(VK_KHR_XLIB_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); - return false; + return SDL_SetError(VK_KHR_XLIB_SURFACE_EXTENSION_NAME " extension is not enabled in the Vulkan instance."); } return vkGetPhysicalDeviceXlibPresentationSupportKHR(physicalDevice, diff --git a/src/video/x11/SDL_x11vulkan.h b/src/video/x11/SDL_x11vulkan.h index 9816ae6323..d5f4ca63d2 100644 --- a/src/video/x11/SDL_x11vulkan.h +++ b/src/video/x11/SDL_x11vulkan.h @@ -30,20 +30,19 @@ typedef struct xcb_connection_t xcb_connection_t; typedef xcb_connection_t *(*PFN_XGetXCBConnection)(Display *dpy); -int X11_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); -void X11_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); -char const* const* X11_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, - Uint32 *count); -int X11_Vulkan_CreateSurface(SDL_VideoDevice *_this, +extern bool X11_Vulkan_LoadLibrary(SDL_VideoDevice *_this, const char *path); +extern void X11_Vulkan_UnloadLibrary(SDL_VideoDevice *_this); +extern char const* const* X11_Vulkan_GetInstanceExtensions(SDL_VideoDevice *_this, Uint32 *count); +extern bool X11_Vulkan_CreateSurface(SDL_VideoDevice *_this, SDL_Window *window, VkInstance instance, const struct VkAllocationCallbacks *allocator, VkSurfaceKHR *surface); -void X11_Vulkan_DestroySurface(SDL_VideoDevice *_this, +extern void X11_Vulkan_DestroySurface(SDL_VideoDevice *_this, VkInstance instance, VkSurfaceKHR surface, const struct VkAllocationCallbacks *allocator); -bool X11_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, +extern bool X11_Vulkan_GetPresentationSupport(SDL_VideoDevice *_this, VkInstance instance, VkPhysicalDevice physicalDevice, Uint32 queueFamilyIndex); diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c index 9a50314373..1989144927 100644 --- a/src/video/x11/SDL_x11window.c +++ b/src/video/x11/SDL_x11window.c @@ -320,7 +320,7 @@ Uint32 X11_GetNetWMState(SDL_VideoDevice *_this, SDL_Window *window, Window xwin return flags; } -static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w) +static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w) { SDL_VideoData *videodata = _this->internal; SDL_DisplayData *displaydata = SDL_GetDisplayDriverDataForWindow(window); @@ -332,7 +332,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w) // Allocate the window data data = (SDL_WindowData *)SDL_calloc(1, sizeof(*data)); if (!data) { - return -1; + return false; } data->window = window; data->xwindow = w; @@ -357,7 +357,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w) SDL_WindowData ** new_windowlist = (SDL_WindowData **)SDL_realloc(windowlist, (numwindows + 1) * sizeof(*windowlist)); if (!new_windowlist) { SDL_free(data); - return -1; + return false; } windowlist = new_windowlist; windowlist[numwindows] = data; @@ -418,7 +418,7 @@ static int SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, Window w) // All done! window->internal = data; - return 0; + return true; } static void SetupWindowInput(SDL_VideoDevice *_this, SDL_Window *window) @@ -487,19 +487,19 @@ static void SetWindowBordered(Display *display, int screen, Window window, bool } } -int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) +bool X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props) { Window w = (Window)SDL_GetNumberProperty(create_props, SDL_PROP_WINDOW_CREATE_X11_WINDOW_NUMBER, (Window)SDL_GetPointerProperty(create_props, "sdl2-compat.external_window", NULL)); if (w) { window->flags |= SDL_WINDOW_EXTERNAL; - if (SetupWindowData(_this, window, w) < 0) { - return -1; + if (!SetupWindowData(_this, window, w)) { + return false; } SetupWindowInput(_this, window); - return 0; + return true; } SDL_VideoData *data = _this->internal; @@ -545,7 +545,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI depth = vi->depth; X11_XFree(vi); } else { - return -1; + return false; } } else if ((window->flags & SDL_WINDOW_OPENGL) && (!display_visual_id || !*display_visual_id)) { @@ -568,7 +568,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI } if (!vinfo) { - return -1; + return false; } visual = vinfo->visual; depth = vinfo->depth; @@ -605,7 +605,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI // OK, we got a colormap, now fill it in as best as we can colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); if (!colorcells) { - return -1; + return false; } ncolors = visual->map_entries; rmax = 0xffff; @@ -786,9 +786,9 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI X11_XSetWMProtocols(display, w, protocols, proto_count); } - if (SetupWindowData(_this, window, w) < 0) { + if (!SetupWindowData(_this, window, w)) { X11_XDestroyWindow(display, w); - return -1; + return false; } windowdata = window->internal; @@ -806,7 +806,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI ) { #ifdef SDL_VIDEO_OPENGL_EGL if (!_this->egl_data) { - return -1; + return false; } // Create the GLES window surface @@ -837,7 +837,7 @@ int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesI X11_XFlush(display); - return 0; + return true; } char *X11_GetWindowTitle(SDL_VideoDevice *_this, Window xwindow) @@ -893,14 +893,14 @@ static int X11_CatchAnyError(Display *d, XErrorEvent *e) /* Wait a brief time, or not, to see if the window manager decided to move/resize the window. * Send MOVED and RESIZED window events */ -static int X11_SyncWindowTimeout(SDL_VideoDevice *_this, SDL_Window *window, Uint64 param_timeout) +static bool X11_SyncWindowTimeout(SDL_VideoDevice *_this, SDL_Window *window, Uint64 param_timeout) { SDL_WindowData *data = window->internal; Display *display = data->videodata->display; int (*prev_handler)(Display *, XErrorEvent *); Uint64 timeout = 0; - int ret = 0; bool force_exit = false; + bool result = true; X11_XSync(display, False); prev_handler = X11_XSetErrorHandler(X11_CatchAnyError); @@ -941,7 +941,7 @@ static int X11_SyncWindowTimeout(SDL_VideoDevice *_this, SDL_Window *window, Uin data->expected.w = window->w; data->expected.h = window->h; - ret = 1; + result = false; break; } @@ -953,22 +953,22 @@ static int X11_SyncWindowTimeout(SDL_VideoDevice *_this, SDL_Window *window, Uin if (!caught_x11_error) { X11_PumpEvents(_this); } else { - ret = -1; + result = false; } X11_XSetErrorHandler(prev_handler); caught_x11_error = false; - return ret; + return result; } -int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon) +bool X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon) { SDL_WindowData *data = window->internal; Display *display = data->videodata->display; Atom _NET_WM_ICON = data->videodata->_NET_WM_ICON; - int rc = 0; int (*prevHandler)(Display *, XErrorEvent *) = NULL; + bool result = true; if (icon) { int x, y; @@ -983,7 +983,7 @@ int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i propdata = SDL_malloc(propsize * sizeof(long)); if (!propdata) { - return -1; + return false; } X11_XSync(display, False); @@ -1006,7 +1006,7 @@ int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i SDL_free(propdata); if (caught_x11_error) { - rc = SDL_SetError("An error occurred while trying to set the window's icon"); + result = SDL_SetError("An error occurred while trying to set the window's icon"); } } @@ -1017,7 +1017,7 @@ int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *i caught_x11_error = false; } - return rc; + return result; } void X11_UpdateWindowPosition(SDL_Window *window, bool use_current_position) @@ -1036,7 +1036,7 @@ void X11_UpdateWindowPosition(SDL_Window *window, bool use_current_position) X11_XMoveWindow(display, data->xwindow, data->expected.x, data->expected.y); } -int X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) +bool X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) { // Sync any pending fullscreen or maximize events. if (window->internal->pending_operation & (X11_PENDING_OP_FULLSCREEN | X11_PENDING_OP_MAXIMIZE)) { @@ -1045,7 +1045,7 @@ int X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) // Position will be set when window is de-maximized if (window->flags & SDL_WINDOW_MAXIMIZED) { - return 0; + return true; } if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { @@ -1056,7 +1056,7 @@ int X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window) } else { SDL_UpdateFullscreenMode(window, SDL_FULLSCREEN_OP_UPDATE, true); } - return 0; + return true; } static void X11_SetWMNormalHints(SDL_VideoDevice *_this, SDL_Window *window, XSizeHints *sizehints) @@ -1205,7 +1205,7 @@ void X11_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window) } } -int X11_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right) +bool X11_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right) { SDL_WindowData *data = window->internal; @@ -1214,10 +1214,10 @@ int X11_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *to *top = data->border_top; *bottom = data->border_bottom; - return 0; + return true; } -int X11_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) +bool X11_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity) { SDL_WindowData *data = window->internal; Display *display = data->videodata->display; @@ -1232,10 +1232,10 @@ int X11_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opaci PropModeReplace, (unsigned char *)&alpha, 1); } - return 0; + return true; } -int X11_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) +bool X11_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window) { SDL_WindowData *data = modal_window->internal; SDL_WindowData *parent_data = parent_window ? parent_window->internal : NULL; @@ -1275,7 +1275,7 @@ int X11_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_ X11_XFlush(display); - return 0; + return true; } void X11_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered) @@ -1479,7 +1479,7 @@ void X11_HideWindow(SDL_VideoDevice *_this, SDL_Window *window) X11_PumpEvents(_this); } -static int X11_SetWindowActive(SDL_VideoDevice *_this, SDL_Window *window) +static bool X11_SetWindowActive(SDL_VideoDevice *_this, SDL_Window *window) { CHECK_WINDOW_DATA(window); @@ -1507,7 +1507,7 @@ static int X11_SetWindowActive(SDL_VideoDevice *_this, SDL_Window *window) X11_XFlush(display); } - return 0; + return true; } void X11_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -1523,7 +1523,7 @@ void X11_RaiseWindow(SDL_VideoDevice *_this, SDL_Window *window) X11_XFlush(display); } -static int X11_SetWindowMaximized(SDL_VideoDevice *_this, SDL_Window *window, bool maximized) +static bool X11_SetWindowMaximized(SDL_VideoDevice *_this, SDL_Window *window, bool maximized) { CHECK_WINDOW_DATA(window); @@ -1539,7 +1539,7 @@ static int X11_SetWindowMaximized(SDL_VideoDevice *_this, SDL_Window *window, bo and this is functional behavior, so don't remove that state now, we'll take care of it when we leave fullscreen mode. */ - return 0; + return true; } if (X11_IsWindowMapped(_this, window)) { @@ -1581,7 +1581,7 @@ static int X11_SetWindowMaximized(SDL_VideoDevice *_this, SDL_Window *window, bo } X11_XFlush(display); - return 0; + return true; } void X11_MaximizeWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -1628,7 +1628,7 @@ void X11_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window) } // This asks the Window Manager to handle fullscreen for us. This is the modern way. -static int X11_SetWindowFullscreenViaWM(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen) +static SDL_FullscreenResult X11_SetWindowFullscreenViaWM(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen) { CHECK_WINDOW_DATA(window); CHECK_DISPLAY_DATA(_display); @@ -1650,10 +1650,10 @@ static int X11_SetWindowFullscreenViaWM(SDL_VideoDevice *_this, SDL_Window *wind if (!(window->flags & SDL_WINDOW_FULLSCREEN)) { if (fullscreen == SDL_FULLSCREEN_OP_UPDATE) { // Request was out of date; set -1 to signal the video core to undo a mode switch. - return -1; + return SDL_FULLSCREEN_FAILED; } else if (fullscreen == SDL_FULLSCREEN_OP_LEAVE) { // Nothing to do. - return 0; + return SDL_FULLSCREEN_SUCCEEDED; } } @@ -1745,10 +1745,10 @@ static int X11_SetWindowFullscreenViaWM(SDL_VideoDevice *_this, SDL_Window *wind } } - return 1; + return SDL_FULLSCREEN_PENDING; } -int X11_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen) +SDL_FullscreenResult X11_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *_display, SDL_FullscreenOp fullscreen) { return X11_SetWindowFullscreenViaWM(_this, window, _display, fullscreen); } @@ -1834,7 +1834,7 @@ void *X11_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t return ret_icc_profile_data; } -int X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { SDL_WindowData *data = window->internal; Display *display; @@ -1851,7 +1851,7 @@ int X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grab so when we get a MapNotify later, we'll try to update the grab as appropriate. */ if (window->flags & SDL_WINDOW_HIDDEN) { - return 0; + return true; } /* If XInput2 is enabled, it will grab the pointer on button presses, @@ -1897,13 +1897,13 @@ int X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grab X11_XSync(display, False); if (!data->videodata->broken_pointer_grab) { - return 0; + return true; } else { return SDL_SetError("The X server refused to let us grab the mouse. You might experience input bugs."); } } -int X11_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) +bool X11_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed) { SDL_WindowData *data = window->internal; Display *display; @@ -1919,7 +1919,7 @@ int X11_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool g so when we get a MapNotify later, we'll try to update the grab as appropriate. */ if (window->flags & SDL_WINDOW_HIDDEN) { - return 0; + return true; } X11_XGrabKeyboard(display, data->xwindow, True, GrabModeAsync, @@ -1929,7 +1929,7 @@ int X11_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool g } X11_XSync(display, False); - return 0; + return true; } void X11_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) @@ -1974,9 +1974,9 @@ void X11_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window) window->internal = NULL; } -int X11_SetWindowHitTest(SDL_Window *window, bool enabled) +bool X11_SetWindowHitTest(SDL_Window *window, bool enabled) { - return 0; // just succeed, the real work is done elsewhere. + return true; // just succeed, the real work is done elsewhere. } void X11_AcceptDragAndDrop(SDL_Window *window, bool accept) @@ -1994,7 +1994,7 @@ void X11_AcceptDragAndDrop(SDL_Window *window, bool accept) } } -int X11_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) +bool X11_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation) { SDL_WindowData *data = window->internal; Display *display = data->videodata->display; @@ -2033,10 +2033,10 @@ int X11_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperati X11_XSetWMHints(display, data->xwindow, wmhints); X11_XFree(wmhints); - return 0; + return true; } -int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title) +bool SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title) { Atom _NET_WM_NAME = X11_XInternAtom(display, "_NET_WM_NAME", False); XTextProperty titleprop; @@ -2055,7 +2055,7 @@ int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title) return SDL_OutOfMemory(); } else { // conv > 0 SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "%d characters were not convertible to the current locale!", conv); - return 0; + return true; } #ifdef X_HAVE_UTF8_STRING @@ -2069,7 +2069,7 @@ int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title) #endif X11_XFlush(display); - return 0; + return true; } void X11_ShowWindowSystemMenu(SDL_Window *window, int x, int y) @@ -2097,7 +2097,7 @@ void X11_ShowWindowSystemMenu(SDL_Window *window, int x, int y) X11_XFlush(display); } -int X11_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) +bool X11_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) { const Uint64 current_time = SDL_GetTicksNS(); Uint64 timeout = 0; @@ -2118,7 +2118,7 @@ int X11_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window) return X11_SyncWindowTimeout(_this, window, timeout); } -int X11_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable) +bool X11_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable) { SDL_WindowData *data = window->internal; Display *display = data->videodata->display; @@ -2135,7 +2135,7 @@ int X11_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focu X11_XSetWMHints(display, data->xwindow, wmhints); X11_XFree(wmhints); - return 0; + return true; } #endif // SDL_VIDEO_DRIVER_X11 diff --git a/src/video/x11/SDL_x11window.h b/src/video/x11/SDL_x11window.h index 031287df39..4bf7e8a208 100644 --- a/src/video/x11/SDL_x11window.h +++ b/src/video/x11/SDL_x11window.h @@ -108,17 +108,17 @@ struct SDL_WindowData extern void X11_SetNetWMState(SDL_VideoDevice *_this, Window xwindow, SDL_WindowFlags flags); extern Uint32 X11_GetNetWMState(SDL_VideoDevice *_this, SDL_Window *window, Window xwindow); -extern int X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); +extern bool X11_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_PropertiesID create_props); extern char *X11_GetWindowTitle(SDL_VideoDevice *_this, Window xwindow); extern void X11_SetWindowTitle(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); -extern int X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); +extern bool X11_SetWindowIcon(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *icon); +extern bool X11_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_SetWindowMinimumSize(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_SetWindowMaximumSize(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_SetWindowAspectRatio(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right); -extern int X11_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); -extern int X11_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); +extern bool X11_GetWindowBordersSize(SDL_VideoDevice *_this, SDL_Window *window, int *top, int *left, int *bottom, int *right); +extern bool X11_SetWindowOpacity(SDL_VideoDevice *_this, SDL_Window *window, float opacity); +extern bool X11_SetWindowModalFor(SDL_VideoDevice *_this, SDL_Window *modal_window, SDL_Window *parent_window); extern void X11_SetWindowSize(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_HideWindow(SDL_VideoDevice *_this, SDL_Window *window); @@ -129,20 +129,20 @@ extern void X11_RestoreWindow(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_SetWindowBordered(SDL_VideoDevice *_this, SDL_Window *window, bool bordered); extern void X11_SetWindowResizable(SDL_VideoDevice *_this, SDL_Window *window, bool resizable); extern void X11_SetWindowAlwaysOnTop(SDL_VideoDevice *_this, SDL_Window *window, bool on_top); -extern int X11_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); +extern SDL_FullscreenResult X11_SetWindowFullscreen(SDL_VideoDevice *_this, SDL_Window *window, SDL_VideoDisplay *display, SDL_FullscreenOp fullscreen); extern void *X11_GetWindowICCProfile(SDL_VideoDevice *_this, SDL_Window *window, size_t *size); -extern int X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); -extern int X11_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool X11_SetWindowMouseGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); +extern bool X11_SetWindowKeyboardGrab(SDL_VideoDevice *_this, SDL_Window *window, bool grabbed); extern void X11_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_SetWindowHitTest(SDL_Window *window, bool enabled); +extern bool X11_SetWindowHitTest(SDL_Window *window, bool enabled); extern void X11_AcceptDragAndDrop(SDL_Window *window, bool accept); -extern int X11_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); +extern bool X11_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation); extern void X11_ShowWindowSystemMenu(SDL_Window *window, int x, int y); -extern int X11_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); +extern bool X11_SyncWindow(SDL_VideoDevice *_this, SDL_Window *window); +extern bool X11_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable); -int SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title); -void X11_UpdateWindowPosition(SDL_Window *window, bool use_current_position); -void X11_SetWindowMinMax(SDL_Window *window, bool use_current); +extern bool SDL_X11_SetWindowTitle(Display *display, Window xwindow, char *title); +extern void X11_UpdateWindowPosition(SDL_Window *window, bool use_current_position); +extern void X11_SetWindowMinMax(SDL_Window *window, bool use_current); #endif // SDL_x11window_h_ diff --git a/src/video/x11/SDL_x11xfixes.c b/src/video/x11/SDL_x11xfixes.c index 0cfca0a185..417a864a84 100644 --- a/src/video/x11/SDL_x11xfixes.c +++ b/src/video/x11/SDL_x11xfixes.c @@ -28,7 +28,7 @@ #include "../../events/SDL_mouse_c.h" #include "../../events/SDL_touch_c.h" -static int xfixes_initialized = 0; +static bool xfixes_initialized = true; static int xfixes_selection_notify_event = 0; static int query_xfixes_version(Display *display, int major, int minor) @@ -74,7 +74,7 @@ void X11_InitXfixes(SDL_VideoDevice *_this) xfixes_initialized = 1; } -int X11_XfixesIsInitialized(void) +bool X11_XfixesIsInitialized(void) { return xfixes_initialized; } @@ -84,7 +84,7 @@ int X11_GetXFixesSelectionNotifyEvent(void) return xfixes_selection_notify_event; } -int X11_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) +bool X11_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) { if (SDL_RectEmpty(&window->mouse_rect)) { X11_ConfineCursorWithFlags(_this, window, NULL, 0); @@ -101,10 +101,10 @@ int X11_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window) } } - return 0; + return true; } -int X11_ConfineCursorWithFlags(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rect, int flags) +bool X11_ConfineCursorWithFlags(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rect, int flags) { /* Yaakuro: For some reason Xfixes when confining inside a rect where the * edges exactly match, a rectangle the cursor 'slips' out of the barrier. @@ -190,7 +190,7 @@ int X11_ConfineCursorWithFlags(SDL_VideoDevice *_this, SDL_Window *window, const wdata->pointer_barrier_active = false; } } - return 0; + return true; } void X11_DestroyPointerBarrier(SDL_VideoDevice *_this, SDL_Window *window) diff --git a/src/video/x11/SDL_x11xfixes.h b/src/video/x11/SDL_x11xfixes.h index 098b97ad65..3a0eb510e8 100644 --- a/src/video/x11/SDL_x11xfixes.h +++ b/src/video/x11/SDL_x11xfixes.h @@ -29,9 +29,9 @@ #define X11_BARRIER_HANDLED_BY_EVENT 1 extern void X11_InitXfixes(SDL_VideoDevice *_this); -extern int X11_XfixesIsInitialized(void); -extern int X11_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); -extern int X11_ConfineCursorWithFlags(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rect, int flags); +extern bool X11_XfixesIsInitialized(void); +extern bool X11_SetWindowMouseRect(SDL_VideoDevice *_this, SDL_Window *window); +extern bool X11_ConfineCursorWithFlags(SDL_VideoDevice *_this, SDL_Window *window, const SDL_Rect *rect, int flags); extern void X11_DestroyPointerBarrier(SDL_VideoDevice *_this, SDL_Window *window); extern int X11_GetXFixesSelectionNotifyEvent(void); #endif // SDL_VIDEO_DRIVER_X11_XFIXES diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index 61798123ac..8431503193 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -33,10 +33,10 @@ #define MAX_AXIS 16 #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2 -static int xinput2_initialized = 0; +static bool xinput2_initialized; #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH -static int xinput2_multitouch_supported = 0; +static bool xinput2_multitouch_supported; #endif /* Opcode returned X11_XQueryExtension @@ -149,7 +149,7 @@ bool X11_InitXinput2(SDL_VideoDevice *_this) return false; // X server does not support the version we want at all. } - xinput2_initialized = 1; + xinput2_initialized = true; #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH // Multitouch needs XInput 2.2 xinput2_multitouch_supported = xinput2_version_atleast(version, 2, 2); @@ -542,12 +542,12 @@ void X11_Xinput2SelectTouch(SDL_VideoDevice *_this, SDL_Window *window) #endif } -int X11_Xinput2IsInitialized(void) +bool X11_Xinput2IsInitialized(void) { #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2 return xinput2_initialized; #else - return 0; + return false; #endif } @@ -600,12 +600,12 @@ bool X11_Xinput2SelectMouseAndKeyboard(SDL_VideoDevice *_this, SDL_Window *windo return false; } -int X11_Xinput2IsMultitouchSupported(void) +bool X11_Xinput2IsMultitouchSupported(void) { #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH return xinput2_initialized && xinput2_multitouch_supported; #else - return 0; + return true; #endif } diff --git a/src/video/x11/SDL_x11xinput2.h b/src/video/x11/SDL_x11xinput2.h index a658a504c3..43172267b1 100644 --- a/src/video/x11/SDL_x11xinput2.h +++ b/src/video/x11/SDL_x11xinput2.h @@ -33,8 +33,8 @@ typedef struct XGenericEventCookie XGenericEventCookie; extern bool X11_InitXinput2(SDL_VideoDevice *_this); extern void X11_InitXinput2Multitouch(SDL_VideoDevice *_this); extern void X11_HandleXinput2Event(SDL_VideoDevice *_this, XGenericEventCookie *cookie); -extern int X11_Xinput2IsInitialized(void); -extern int X11_Xinput2IsMultitouchSupported(void); +extern bool X11_Xinput2IsInitialized(void); +extern bool X11_Xinput2IsMultitouchSupported(void); extern void X11_Xinput2SelectTouch(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_Xinput2GrabTouch(SDL_VideoDevice *_this, SDL_Window *window); extern void X11_Xinput2UngrabTouch(SDL_VideoDevice *_this, SDL_Window *window); diff --git a/test/gamepadutils.c b/test/gamepadutils.c index 562a9e0cb5..56aa086d4b 100644 --- a/test/gamepadutils.c +++ b/test/gamepadutils.c @@ -1223,7 +1223,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad) Uint8 state; float finger_x, finger_y, finger_pressure; - if (SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &state, &finger_x, &finger_y, &finger_pressure) < 0) { + if (!SDL_GetGamepadTouchpadFinger(gamepad, 0, i, &state, &finger_x, &finger_y, &finger_pressure)) { continue; } @@ -2688,12 +2688,12 @@ SDL_bool MappingHasBindings(const char *mapping) SDL_bool MappingHasName(const char *mapping) { MappingParts parts; - SDL_bool retval; + SDL_bool result; SplitMapping(mapping, &parts); - retval = parts.name ? SDL_TRUE : SDL_FALSE; + result = parts.name ? SDL_TRUE : SDL_FALSE; FreeMappingParts(&parts); - return retval; + return result; } char *GetMappingName(const char *mapping) diff --git a/test/loopwave.c b/test/loopwave.c index d148ef4499..0379b6847c 100644 --- a/test/loopwave.c +++ b/test/loopwave.c @@ -80,7 +80,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) } /* Load the SDL library */ - if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS) < 0) { + if (!SDL_Init(SDL_INIT_AUDIO | SDL_INIT_EVENTS)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return SDL_APP_FAILURE; } @@ -93,7 +93,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) } /* Load the wave file into memory */ - if (SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen) < 0) { + if (!SDL_LoadWAV(filename, &wave.spec, &wave.sound, &wave.soundlen)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); SDL_free(filename); return SDL_APP_FAILURE; diff --git a/test/testaudio.c b/test/testaudio.c index eab00a281b..62f6aa9acb 100644 --- a/test/testaudio.c +++ b/test/testaudio.c @@ -152,14 +152,14 @@ static void SetDefaultTitleBar(void) static Thing *FindThingAtPoint(const float x, const float y) { const SDL_FPoint pt = { x, y }; - Thing *retval = NULL; + Thing *result = NULL; Thing *i; for (i = things; i; i = i->next) { if ((i != dragging_thing) && SDL_PointInRectFloat(&pt, &i->rect)) { - retval = i; /* keep going, though, because things drawn on top are later in the list. */ + result = i; /* keep going, though, because things drawn on top are later in the list. */ } } - return retval; + return result; } static Thing *UpdateMouseOver(const float x, const float y) @@ -667,7 +667,7 @@ static Thing *LoadWavThing(const char *fname, float x, float y) fname = path; } - if (SDL_LoadWAV(fname, &spec, &buf, &buflen) == 0) { + if (SDL_LoadWAV(fname, &spec, &buf, &buflen)) { static const ThingType can_be_dropped_onto[] = { THING_TRASHCAN, THING_NULL }; char *titlebar = NULL; const char *nodirs = SDL_strrchr(fname, '/'); diff --git a/test/testaudiohotplug.c b/test/testaudiohotplug.c index e3f208dd2b..50e4a3f48d 100644 --- a/test/testaudiohotplug.c +++ b/test/testaudiohotplug.c @@ -88,7 +88,7 @@ static void iteration(void) /* !!! FIXME: laziness, this used to loop the audio, but we'll just play it once for now on each connect. */ SDL_PutAudioStreamData(stream, sound, soundlen); SDL_FlushAudioStream(stream); - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); + SDL_ResumeAudioStreamDevice(stream); /* !!! FIXME: this is leaking the stream for now. We'll wire it up to a dictionary or whatever later. */ } } @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) } /* Load the SDL library */ - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } @@ -167,7 +167,7 @@ int main(int argc, char *argv[]) } /* Load the wave file into memory */ - if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) < 0) { + if (!SDL_LoadWAV(filename, &spec, &sound, &soundlen)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, SDL_GetError()); quit(1); } diff --git a/test/testaudioinfo.c b/test/testaudioinfo.c index a32268761b..15b124bfb3 100644 --- a/test/testaudioinfo.c +++ b/test/testaudioinfo.c @@ -37,7 +37,7 @@ print_devices(SDL_bool recording) SDL_Log(" %d Error: %s\n", i, SDL_GetError()); } - if (SDL_GetAudioDeviceFormat(devices[i], &spec, &frames) == 0) { + if (SDL_GetAudioDeviceFormat(devices[i], &spec, &frames)) { SDL_Log(" Sample Rate: %d\n", spec.freq); SDL_Log(" Channels: %d\n", spec.channels); SDL_Log(" SDL_AudioFormat: %X\n", spec.format); @@ -72,7 +72,7 @@ int main(int argc, char **argv) } /* Load the SDL library */ - if (SDL_Init(SDL_INIT_AUDIO) < 0) { + if (!SDL_Init(SDL_INIT_AUDIO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } @@ -94,24 +94,24 @@ int main(int argc, char **argv) print_devices(SDL_FALSE); print_devices(SDL_TRUE); - if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &frames) < 0) { - SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default playback): %s\n", SDL_GetError()); - } else { + if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, &frames)) { SDL_Log("Default Playback Device:\n"); SDL_Log("Sample Rate: %d\n", spec.freq); SDL_Log("Channels: %d\n", spec.channels); SDL_Log("SDL_AudioFormat: %X\n", spec.format); SDL_Log("Buffer Size: %d frames\n", frames); + } else { + SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default playback): %s\n", SDL_GetError()); } - if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &spec, &frames) < 0) { - SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default recording): %s\n", SDL_GetError()); - } else { + if (SDL_GetAudioDeviceFormat(SDL_AUDIO_DEVICE_DEFAULT_RECORDING, &spec, &frames)) { SDL_Log("Default Recording Device:\n"); SDL_Log("Sample Rate: %d\n", spec.freq); SDL_Log("Channels: %d\n", spec.channels); SDL_Log("SDL_AudioFormat: %X\n", spec.format); SDL_Log("Buffer Size: %d frames\n", frames); + } else { + SDL_Log("Error when calling SDL_GetAudioDeviceFormat(default recording): %s\n", SDL_GetError()); } SDL_Quit(); diff --git a/test/testaudiorecording.c b/test/testaudiorecording.c index c5f7821545..302f3fdfa7 100644 --- a/test/testaudiorecording.c +++ b/test/testaudiorecording.c @@ -64,12 +64,12 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) } /* Load the SDL library */ - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return SDL_APP_SUCCESS; } - if (SDL_CreateWindowAndRenderer("testaudiorecording", 320, 240, 0, &window, &renderer) < 0) { + if (!SDL_CreateWindowAndRenderer("testaudiorecording", 320, 240, 0, &window, &renderer)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create SDL window and renderer: %s\n", SDL_GetError()); return SDL_APP_SUCCESS; } @@ -113,7 +113,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError()); SDL_free(devices); return SDL_APP_FAILURE; - } else if (SDL_BindAudioStream(device, stream_out) < 0) { + } else if (!SDL_BindAudioStream(device, stream_out)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError()); SDL_free(devices); return SDL_APP_FAILURE; @@ -137,7 +137,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) if (!stream_in) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for recording: %s!\n", SDL_GetError()); return SDL_APP_FAILURE; - } else if (SDL_BindAudioStream(device, stream_in) < 0) { + } else if (!SDL_BindAudioStream(device, stream_in)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for recording: %s!\n", SDL_GetError()); return SDL_APP_FAILURE; } @@ -159,15 +159,15 @@ SDL_AppResult SDL_AppEvent(void *appstate, const SDL_Event *event) } } else if (event->type == SDL_EVENT_MOUSE_BUTTON_DOWN) { if (event->button.button == 1) { - SDL_PauseAudioDevice(SDL_GetAudioStreamDevice(stream_out)); + SDL_PauseAudioStreamDevice(stream_out); SDL_FlushAudioStream(stream_out); /* so no samples are held back for resampling purposes. */ - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream_in)); + SDL_ResumeAudioStreamDevice(stream_in); } } else if (event->type == SDL_EVENT_MOUSE_BUTTON_UP) { if (event->button.button == 1) { - SDL_PauseAudioDevice(SDL_GetAudioStreamDevice(stream_in)); + SDL_PauseAudioStreamDevice(stream_in); SDL_FlushAudioStream(stream_in); /* so no samples are held back for resampling purposes. */ - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream_out)); + SDL_ResumeAudioStreamDevice(stream_out); } } return SDL_APP_CONTINUE; @@ -190,7 +190,7 @@ SDL_AppResult SDL_AppIterate(void *appstate) if (br < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to read from input audio stream: %s\n", SDL_GetError()); return SDL_APP_FAILURE; - } else if (SDL_PutAudioStreamData(stream_out, buf, br) < 0) { + } else if (!SDL_PutAudioStreamData(stream_out, buf, br)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to write to output audio stream: %s\n", SDL_GetError()); return SDL_APP_FAILURE; } diff --git a/test/testaudiostreamdynamicresample.c b/test/testaudiostreamdynamicresample.c index f01ca2505d..5d5c7f1c85 100644 --- a/test/testaudiostreamdynamicresample.c +++ b/test/testaudiostreamdynamicresample.c @@ -106,7 +106,7 @@ static void queue_audio(void) { Uint8* new_data = NULL; int new_len = 0; - int retval = 0; + SDL_bool result = SDL_TRUE; SDL_AudioSpec new_spec; SDL_zero(new_spec); @@ -117,20 +117,20 @@ static void queue_audio(void) SDL_Log("Converting audio from %i to %i", spec.freq, new_spec.freq); /* You shouldn't actually use SDL_ConvertAudioSamples like this (just put the data straight into the stream and let it handle conversion) */ - retval = retval ? retval : SDL_ConvertAudioSamples(&spec, audio_buf, audio_len, &new_spec, &new_data, &new_len); - retval = retval ? retval : SDL_SetAudioStreamFormat(stream, &new_spec, NULL); - retval = retval ? retval : SDL_PutAudioStreamData(stream, new_data, new_len); + result = result && SDL_ConvertAudioSamples(&spec, audio_buf, audio_len, &new_spec, &new_data, &new_len); + result = result && SDL_SetAudioStreamFormat(stream, &new_spec, NULL); + result = result && SDL_PutAudioStreamData(stream, new_data, new_len); if (auto_flush) { - retval = retval ? retval : SDL_FlushAudioStream(stream); + result = result && SDL_FlushAudioStream(stream); } SDL_free(new_data); - if (retval) { - SDL_Log("Failed to queue audio: %s", SDL_GetError()); - } else { + if (result) { SDL_Log("Queued audio"); + } else { + SDL_Log("Failed to queue audio: %s", SDL_GetError()); } } @@ -139,7 +139,7 @@ static void skip_audio(float amount) float speed; SDL_AudioSpec dst_spec; int num_bytes; - int retval = 0; + int result = 0; void* buf = NULL; SDL_LockAudioStream(stream); @@ -153,7 +153,7 @@ static void skip_audio(float amount) buf = SDL_malloc(num_bytes); if (buf) { - retval = SDL_GetAudioStreamData(stream, buf, num_bytes); + result = SDL_GetAudioStreamData(stream, buf, num_bytes); SDL_free(buf); } @@ -161,7 +161,7 @@ static void skip_audio(float amount) SDL_UnlockAudioStream(stream); - if (retval >= 0) { + if (result >= 0) { SDL_Log("Skipped %.2f seconds", amount); } else { SDL_Log("Failed to skip: %s", SDL_GetError()); @@ -285,7 +285,7 @@ static void loop(void) SDL_SetAudioStreamFrequencyRatio(stream, sliders[0].value); } - if (SDL_GetAudioStreamFormat(stream, &src_spec, &dst_spec) == 0) { + if (SDL_GetAudioStreamFormat(stream, &src_spec, &dst_spec)) { available_bytes = SDL_GetAudioStreamAvailable(stream); available_seconds = (float)available_bytes / (float)(SDL_AUDIO_FRAMESIZE(dst_spec) * dst_spec.freq); @@ -369,7 +369,6 @@ int main(int argc, char *argv[]) { char *filename = NULL; int i; - int rc; /* Initialize test framework */ state = SDLTest_CommonCreateState(argv, SDL_INIT_AUDIO | SDL_INIT_VIDEO); @@ -409,9 +408,7 @@ int main(int argc, char *argv[]) FONT_CHARACTER_SIZE = 16; filename = GetResourceFilename(filename, "sample.wav"); - rc = SDL_LoadWAV(filename, &spec, &audio_buf, &audio_len); - - if (rc < 0) { + if (!SDL_LoadWAV(filename, &spec, &audio_buf, &audio_len)) { SDL_Log("Failed to load '%s': %s", filename, SDL_GetError()); SDL_free(filename); SDL_Quit(); diff --git a/test/testautomation_audio.c b/test/testautomation_audio.c index 3b09c68ae2..bc2b07ba2e 100644 --- a/test/testautomation_audio.c +++ b/test/testautomation_audio.c @@ -22,10 +22,10 @@ static void audioSetUp(void *arg) { /* Start SDL audio subsystem */ - int ret = SDL_InitSubSystem(SDL_INIT_AUDIO); + SDL_bool ret = SDL_InitSubSystem(SDL_INIT_AUDIO); SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO)"); - SDLTest_AssertCheck(ret == 0, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)"); - if (ret != 0) { + SDLTest_AssertCheck(ret == SDL_TRUE, "Check result from SDL_InitSubSystem(SDL_INIT_AUDIO)"); + if (!ret) { SDLTest_LogError("%s", SDL_GetError()); } } @@ -111,7 +111,7 @@ static int audio_initQuitAudio(void *arg) SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver); result = SDL_InitSubSystem(SDL_INIT_AUDIO); SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result value; expected: SDL_TRUE got: %d", result); /* Call Quit */ SDL_QuitSubSystem(SDL_INIT_AUDIO); @@ -125,7 +125,7 @@ static int audio_initQuitAudio(void *arg) SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver); result = SDL_InitSubSystem(SDL_INIT_AUDIO); SDLTest_AssertPass("Call to SDL_AudioInit(NULL)"); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result value; expected: SDL_TRUE got: %d", result); /* Call Quit */ SDL_QuitSubSystem(SDL_INIT_AUDIO); @@ -178,7 +178,7 @@ static int audio_initOpenCloseQuitAudio(void *arg) SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver); result = SDL_InitSubSystem(SDL_INIT_AUDIO); SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result value; expected: SDL_TRUE got: %d", result); /* Set spec */ SDL_zero(desired); @@ -269,7 +269,7 @@ static int audio_pauseUnpauseAudio(void *arg) SDL_SetHint(SDL_HINT_AUDIO_DRIVER, audioDriver); result = SDL_InitSubSystem(SDL_INIT_AUDIO); SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_AUDIO) with driver='%s'", audioDriver); - SDLTest_AssertCheck(result == 0, "Validate result value; expected: 0 got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result value; expected: SDL_TRUE got: %d", result); /* Set spec */ SDL_zero(desired); @@ -826,8 +826,8 @@ static int audio_convertAudio(void *arg) SDLTest_AssertCheck(0 == real_dst_len, "Verify available (pre-put); expected: %i; got: %i", 0, real_dst_len); /* Run the audio converter */ - if (SDL_PutAudioStreamData(stream, src_buf, src_len) < 0 || - SDL_FlushAudioStream(stream) < 0) { + if (!SDL_PutAudioStreamData(stream, src_buf, src_len) || + !SDL_FlushAudioStream(stream)) { return TEST_ABORTED; } @@ -894,8 +894,8 @@ static int put_audio_data_split(SDL_AudioStream* stream, const void* buf, int le int frame_size; int ret = SDL_GetAudioStreamFormat(stream, &spec, NULL); - if (ret != 0) { - return ret; + if (!ret) { + return -1; } frame_size = SDL_AUDIO_FRAMESIZE(spec); @@ -905,8 +905,8 @@ static int put_audio_data_split(SDL_AudioStream* stream, const void* buf, int le n = SDL_min(n, len); ret = SDL_PutAudioStreamData(stream, buf, n); - if (ret != 0) { - return ret; + if (!ret) { + return -1; } buf = ((const Uint8*) buf) + n; @@ -923,8 +923,8 @@ static int get_audio_data_split(SDL_AudioStream* stream, void* buf, int len) { int ret = SDL_GetAudioStreamFormat(stream, NULL, &spec); int total = 0; - if (ret != 0) { - return ret; + if (!ret) { + return -1; } frame_size = SDL_AUDIO_FRAMESIZE(spec); @@ -936,7 +936,7 @@ static int get_audio_data_split(SDL_AudioStream* stream, void* buf, int len) { ret = SDL_GetAudioStreamData(stream, buf, n); if (ret <= 0) { - return total ? total : ret; + return total ? total : -1; } buf = ((Uint8*) buf) + ret; @@ -955,8 +955,8 @@ static int convert_audio_chunks(SDL_AudioStream* stream, const void* src, int sr int total_in = 0, total_out = 0; int ret = SDL_GetAudioStreamFormat(stream, &src_spec, &dst_spec); - if (ret) { - return ret; + if (!ret) { + return -1; } src_frame_size = SDL_AUDIO_FRAMESIZE(src_spec); @@ -981,8 +981,8 @@ static int convert_audio_chunks(SDL_AudioStream* stream, const void* src, int sr if (total_in == srclen) { ret = SDL_FlushAudioStream(stream); - if (ret) { - return total_out ? total_out : ret; + if (!ret) { + return total_out ? total_out : -1; } } } @@ -1245,8 +1245,8 @@ static int audio_convertAccuracy(void *arg) tmp_data = NULL; tmp_len = 0; ret = SDL_ConvertAudioSamples(&src_spec, (const Uint8*) src_data, src_len, &tmp_spec, &tmp_data, &tmp_len); - SDLTest_AssertCheck(ret == 0, "Expected SDL_ConvertAudioSamples(F32->%s) to succeed", format_name); - if (ret != 0) { + SDLTest_AssertCheck(ret == SDL_TRUE, "Expected SDL_ConvertAudioSamples(F32->%s) to succeed", format_name); + if (!ret) { SDL_free(src_data); return TEST_ABORTED; } @@ -1254,8 +1254,8 @@ static int audio_convertAccuracy(void *arg) dst_data = NULL; dst_len = 0; ret = SDL_ConvertAudioSamples(&tmp_spec, tmp_data, tmp_len, &src_spec, &dst_data, &dst_len); - SDLTest_AssertCheck(ret == 0, "Expected SDL_ConvertAudioSamples(%s->F32) to succeed", format_name); - if (ret != 0) { + SDLTest_AssertCheck(ret == SDL_TRUE, "Expected SDL_ConvertAudioSamples(%s->F32) to succeed", format_name); + if (!ret) { SDL_free(tmp_data); SDL_free(src_data); return TEST_ABORTED; @@ -1297,7 +1297,7 @@ static int audio_formatChange(void *arg) SDL_AudioSpec spec1, spec2, spec3; int frames_1, frames_2, frames_3; int length_1, length_2, length_3; - int retval = 0; + int result = 0; int status = TEST_ABORTED; float* buffer_1 = NULL; float* buffer_2 = NULL; @@ -1362,53 +1362,53 @@ static int audio_formatChange(void *arg) goto cleanup; } - retval = SDL_SetAudioStreamFormat(stream, &spec1, &spec3); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_SetAudioStreamFormat(spec1, spec3) to succeed")) { + result = SDL_SetAudioStreamFormat(stream, &spec1, &spec3); + if (!SDLTest_AssertCheck(result == SDL_TRUE, "Expected SDL_SetAudioStreamFormat(spec1, spec3) to succeed")) { goto cleanup; } - retval = SDL_GetAudioStreamAvailable(stream); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_GetAudioStreamAvailable return 0")) { + result = SDL_GetAudioStreamAvailable(stream); + if (!SDLTest_AssertCheck(result == 0, "Expected SDL_GetAudioStreamAvailable return 0")) { goto cleanup; } - retval = SDL_PutAudioStreamData(stream, buffer_1, length_1); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) { + result = SDL_PutAudioStreamData(stream, buffer_1, length_1); + if (!SDLTest_AssertCheck(result == SDL_TRUE, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) { goto cleanup; } - retval = SDL_FlushAudioStream(stream); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_FlushAudioStream to succeed")) { + result = SDL_FlushAudioStream(stream); + if (!SDLTest_AssertCheck(result == SDL_TRUE, "Expected SDL_FlushAudioStream to succeed")) { goto cleanup; } - retval = SDL_SetAudioStreamFormat(stream, &spec2, &spec3); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_SetAudioStreamFormat(spec2, spec3) to succeed")) { + result = SDL_SetAudioStreamFormat(stream, &spec2, &spec3); + if (!SDLTest_AssertCheck(result == SDL_TRUE, "Expected SDL_SetAudioStreamFormat(spec2, spec3) to succeed")) { goto cleanup; } - retval = SDL_PutAudioStreamData(stream, buffer_2, length_2); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) { + result = SDL_PutAudioStreamData(stream, buffer_2, length_2); + if (!SDLTest_AssertCheck(result == SDL_TRUE, "Expected SDL_PutAudioStreamData(buffer_1) to succeed")) { goto cleanup; } - retval = SDL_FlushAudioStream(stream); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_FlushAudioStream to succeed")) { + result = SDL_FlushAudioStream(stream); + if (!SDLTest_AssertCheck(result == SDL_TRUE, "Expected SDL_FlushAudioStream to succeed")) { goto cleanup; } - retval = SDL_GetAudioStreamAvailable(stream); - if (!SDLTest_AssertCheck(retval == length_3, "Expected SDL_GetAudioStreamAvailable to return %i, got %i", length_3, retval)) { + result = SDL_GetAudioStreamAvailable(stream); + if (!SDLTest_AssertCheck(result == length_3, "Expected SDL_GetAudioStreamAvailable to return %i, got %i", length_3, result)) { goto cleanup; } - retval = SDL_GetAudioStreamData(stream, buffer_3, length_3); - if (!SDLTest_AssertCheck(retval == length_3, "Expected SDL_GetAudioStreamData to return %i, got %i", length_3, retval)) { + result = SDL_GetAudioStreamData(stream, buffer_3, length_3); + if (!SDLTest_AssertCheck(result == length_3, "Expected SDL_GetAudioStreamData to return %i, got %i", length_3, result)) { goto cleanup; } - retval = SDL_GetAudioStreamAvailable(stream); - if (!SDLTest_AssertCheck(retval == 0, "Expected SDL_GetAudioStreamAvailable to return 0")) { + result = SDL_GetAudioStreamAvailable(stream); + if (!SDLTest_AssertCheck(result == 0, "Expected SDL_GetAudioStreamAvailable to return 0")) { goto cleanup; } diff --git a/test/testautomation_clipboard.c b/test/testautomation_clipboard.c index 7e1ae3a9a5..81d448eee4 100644 --- a/test/testautomation_clipboard.c +++ b/test/testautomation_clipboard.c @@ -105,16 +105,16 @@ static int clipboard_testClipboardDataFunctions(void *arg) /* Test clearing clipboard data */ result = SDL_ClearClipboardData(); SDLTest_AssertCheck( - result == 0, - "Validate SDL_ClearClipboardData result, expected 0, got %i", + result == SDL_TRUE, + "Validate SDL_ClearClipboardData result, expected SDL_TRUE, got %i", result); /* Test clearing clipboard data when it's already clear */ last_clipboard_update_count = clipboard_update_count; result = SDL_ClearClipboardData(); SDLTest_AssertCheck( - result == 0, - "Validate SDL_ClearClipboardData result, expected 0, got %i", + result == SDL_TRUE, + "Validate SDL_ClearClipboardData result, expected SDL_TRUE, got %i", result); SDLTest_AssertCheck( clipboard_update_count == last_clipboard_update_count, @@ -125,8 +125,8 @@ static int clipboard_testClipboardDataFunctions(void *arg) last_clipboard_update_count = clipboard_update_count; result = SDL_SetClipboardData(NULL, NULL, NULL, test_mime_types, SDL_arraysize(test_mime_types)); SDLTest_AssertCheck( - result == -1, - "Validate SDL_SetClipboardData(invalid) result, expected -1, got %i", + result == SDL_FALSE, + "Validate SDL_SetClipboardData(invalid) result, expected SDL_FALSE, got %i", result); SDLTest_AssertCheck( clipboard_update_count == last_clipboard_update_count, @@ -136,8 +136,8 @@ static int clipboard_testClipboardDataFunctions(void *arg) last_clipboard_update_count = clipboard_update_count; result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, NULL, NULL, 0); SDLTest_AssertCheck( - result == -1, - "Validate SDL_SetClipboardData(invalid) result, expected -1, got %i", + result == SDL_FALSE, + "Validate SDL_SetClipboardData(invalid) result, expected SDL_FALSE, got %i", result); SDLTest_AssertCheck( clipboard_update_count == last_clipboard_update_count, @@ -150,8 +150,8 @@ static int clipboard_testClipboardDataFunctions(void *arg) last_clipboard_cleanup_count = clipboard_cleanup_count; result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, &test_data1, test_mime_types, SDL_arraysize(test_mime_types)); SDLTest_AssertCheck( - result == 0, - "Validate SDL_SetClipboardData(test_data1) result, expected 0, got %i", + result == SDL_TRUE, + "Validate SDL_SetClipboardData(test_data1) result, expected SDL_TRUE, got %i", result); SDLTest_AssertCheck( clipboard_update_count == last_clipboard_update_count + 1, @@ -262,8 +262,8 @@ static int clipboard_testClipboardDataFunctions(void *arg) last_clipboard_cleanup_count = clipboard_cleanup_count; result = SDL_SetClipboardData(ClipboardDataCallback, ClipboardCleanupCallback, &test_data2, test_mime_types, SDL_arraysize(test_mime_types)); SDLTest_AssertCheck( - result == 0, - "Validate SDL_SetClipboardData(test_data2) result, expected 0, got %i", + result == SDL_TRUE, + "Validate SDL_SetClipboardData(test_data2) result, expected SDL_TRUE, got %i", result); SDLTest_AssertCheck( clipboard_update_count == last_clipboard_update_count + 1, @@ -365,8 +365,8 @@ static int clipboard_testClipboardDataFunctions(void *arg) last_clipboard_cleanup_count = clipboard_cleanup_count; result = SDL_ClearClipboardData(); SDLTest_AssertCheck( - result == 0, - "Validate SDL_ClearClipboardData result, expected 0, got %i", + result == SDL_TRUE, + "Validate SDL_ClearClipboardData result, expected SDL_TRUE, got %i", result); SDLTest_AssertCheck( clipboard_update_count == last_clipboard_update_count + 1, @@ -415,8 +415,8 @@ static int clipboard_testClipboardTextFunctions(void *arg) last_clipboard_update_count = clipboard_update_count; intResult = SDL_SetClipboardText(NULL); SDLTest_AssertCheck( - intResult == 0, - "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i", + intResult == SDL_TRUE, + "Verify result from SDL_SetClipboardText(NULL), expected SDL_TRUE, got %i", intResult); charResult = SDL_GetClipboardText(); SDLTest_AssertCheck( @@ -439,8 +439,8 @@ static int clipboard_testClipboardTextFunctions(void *arg) last_clipboard_update_count = clipboard_update_count; intResult = SDL_SetClipboardText(text); SDLTest_AssertCheck( - intResult == 0, - "Verify result from SDL_SetClipboardText(%s), expected 0, got %i", text, + intResult == SDL_TRUE, + "Verify result from SDL_SetClipboardText(%s), expected SDL_TRUE, got %i", text, intResult); SDLTest_AssertCheck( SDL_strcmp(textRef, text) == 0, @@ -465,8 +465,8 @@ static int clipboard_testClipboardTextFunctions(void *arg) /* Reset clipboard text */ intResult = SDL_SetClipboardText(NULL); SDLTest_AssertCheck( - intResult == 0, - "Verify result from SDL_SetClipboardText(NULL), expected 0, got %i", + intResult == SDL_TRUE, + "Verify result from SDL_SetClipboardText(NULL), expected SDL_TRUE, got %i", intResult); /* Cleanup */ @@ -499,8 +499,8 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg) last_clipboard_update_count = clipboard_update_count; intResult = SDL_SetPrimarySelectionText(NULL); SDLTest_AssertCheck( - intResult == 0, - "Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i", + intResult == SDL_TRUE, + "Verify result from SDL_SetPrimarySelectionText(NULL), expected SDL_TRUE, got %i", intResult); charResult = SDL_GetPrimarySelectionText(); SDLTest_AssertCheck( @@ -522,8 +522,8 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg) last_clipboard_update_count = clipboard_update_count; intResult = SDL_SetPrimarySelectionText(text); SDLTest_AssertCheck( - intResult == 0, - "Verify result from SDL_SetPrimarySelectionText(%s), expected 0, got %i", text, + intResult == SDL_TRUE, + "Verify result from SDL_SetPrimarySelectionText(%s), expected SDL_TRUE, got %i", text, intResult); SDLTest_AssertCheck( SDL_strcmp(textRef, text) == 0, @@ -548,8 +548,8 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg) /* Reset primary selection */ intResult = SDL_SetPrimarySelectionText(NULL); SDLTest_AssertCheck( - intResult == 0, - "Verify result from SDL_SetPrimarySelectionText(NULL), expected 0, got %i", + intResult == SDL_TRUE, + "Verify result from SDL_SetPrimarySelectionText(NULL), expected SDL_TRUE, got %i", intResult); /* Cleanup */ diff --git a/test/testautomation_iostream.c b/test/testautomation_iostream.c index 3caa7e2bed..23ac85061d 100644 --- a/test/testautomation_iostream.c +++ b/test/testautomation_iostream.c @@ -275,7 +275,7 @@ static int iostrm_testMem(void *arg) /* Close */ result = SDL_CloseIO(rw); SDLTest_AssertPass("Call to SDL_CloseIO() succeeded"); - SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", result); return TEST_COMPLETED; } @@ -307,7 +307,7 @@ static int iostrm_testConstMem(void *arg) /* Close handle */ result = SDL_CloseIO(rw); SDLTest_AssertPass("Call to SDL_CloseIO() succeeded"); - SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", result); return TEST_COMPLETED; } @@ -356,7 +356,7 @@ static int iostrm_testDynamicMem(void *arg) /* Close */ result = SDL_CloseIO(rw); SDLTest_AssertPass("Call to SDL_CloseIO() succeeded"); - SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", result); return TEST_COMPLETED; } @@ -388,7 +388,7 @@ static int iostrm_testFileRead(void *arg) /* Close handle */ result = SDL_CloseIO(rw); SDLTest_AssertPass("Call to SDL_CloseIO() succeeded"); - SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", result); return TEST_COMPLETED; } @@ -420,7 +420,7 @@ static int iostrm_testFileWrite(void *arg) /* Close handle */ result = SDL_CloseIO(rw); SDLTest_AssertPass("Call to SDL_CloseIO() succeeded"); - SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", result); return TEST_COMPLETED; } @@ -486,7 +486,7 @@ static int iostrm_testCompareRWFromMemWithRWFromFile(void *arg) SDLTest_AssertPass("Call to SDL_SeekIO(mem,SEEK_END)"); result = SDL_CloseIO(iostrm_mem); SDLTest_AssertPass("Call to SDL_CloseIO(mem)"); - SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", result); /* Read/see from file */ iostrm_file = SDL_IOFromFile(IOStreamAlphabetFilename, "r"); @@ -497,7 +497,7 @@ static int iostrm_testCompareRWFromMemWithRWFromFile(void *arg) SDLTest_AssertPass("Call to SDL_SeekIO(file,SEEK_END)"); result = SDL_CloseIO(iostrm_file); SDLTest_AssertPass("Call to SDL_CloseIO(file)"); - SDLTest_AssertCheck(result == 0, "Verify result value is 0; got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", result); /* Compare */ SDLTest_AssertCheck(rv_mem == rv_file, "Verify returned read blocks matches for mem and file reads; got: rv_mem=%d rv_file=%d", (int)rv_mem, (int)rv_file); @@ -641,7 +641,7 @@ static int iostrm_testFileWriteReadEndian(void *arg) /* Close handle */ cresult = SDL_CloseIO(rw); SDLTest_AssertPass("Call to SDL_CloseIO() succeeded"); - SDLTest_AssertCheck(cresult == 0, "Verify result value is 0; got: %d", cresult); + SDLTest_AssertCheck(cresult == SDL_TRUE, "Verify result value is SDL_TRUE; got: %d", cresult); } return TEST_COMPLETED; diff --git a/test/testautomation_joystick.c b/test/testautomation_joystick.c index f04b8599c8..a063570509 100644 --- a/test/testautomation_joystick.c +++ b/test/testautomation_joystick.c @@ -23,7 +23,7 @@ static int TestVirtualJoystick(void *arg) SDL_Gamepad *gamepad = NULL; SDL_JoystickID device_id; - SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD) == 0, "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); + SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD), "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); @@ -86,11 +86,11 @@ static int TestVirtualJoystick(void *arg) SDLTest_AssertCheck(nbuttons == desc.nbuttons, "SDL_GetNumJoystickButtons() -> %d (expected %d)", nbuttons, desc.nbuttons); } - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED"); - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetJoystickButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetJoystickButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED"); @@ -124,11 +124,11 @@ static int TestVirtualJoystick(void *arg) SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A"); /* Set the south button and verify that the gamepad responds */ - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED"); - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED"); @@ -141,11 +141,11 @@ static int TestVirtualJoystick(void *arg) SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B"); /* Set the south button and verify that the gamepad responds */ - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED"); - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED"); @@ -158,11 +158,11 @@ static int TestVirtualJoystick(void *arg) SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS"); /* Set the south button and verify that the gamepad responds */ - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED) == 0"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_PRESSED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_PRESSED"); - SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0, "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED) == 0"); + SDLTest_AssertCheck(SDL_SetJoystickVirtualButton(joystick, SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED), "SDL_SetJoystickVirtualButton(SDL_GAMEPAD_BUTTON_SOUTH, SDL_RELEASED)"); SDL_UpdateJoysticks(); SDLTest_AssertCheck(SDL_GetGamepadButton(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED, "SDL_GetGamepadButton(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_RELEASED"); @@ -171,7 +171,7 @@ static int TestVirtualJoystick(void *arg) SDL_CloseJoystick(joystick); } - SDLTest_AssertCheck(SDL_DetachVirtualJoystick(device_id) == 0, "SDL_DetachVirtualJoystick()"); + SDLTest_AssertCheck(SDL_DetachVirtualJoystick(device_id), "SDL_DetachVirtualJoystick()"); } SDLTest_AssertCheck(!SDL_IsJoystickVirtual(device_id), "!SDL_IsJoystickVirtual()"); diff --git a/test/testautomation_main.c b/test/testautomation_main.c index 40b56ee53a..6fb6bcdf8c 100644 --- a/test/testautomation_main.c +++ b/test/testautomation_main.c @@ -26,7 +26,7 @@ static int main_testInitQuitSubSystem(void *arg) int subsystem = subsystems[i]; SDLTest_AssertCheck((SDL_WasInit(subsystem) & subsystem) == 0, "SDL_WasInit(%x) before init should be false", subsystem); - SDLTest_AssertCheck(SDL_InitSubSystem(subsystem) == 0, "SDL_InitSubSystem(%x)", subsystem); + SDLTest_AssertCheck(SDL_InitSubSystem(subsystem), "SDL_InitSubSystem(%x)", subsystem); initialized_system = SDL_WasInit(subsystem); SDLTest_AssertCheck((initialized_system & subsystem) != 0, "SDL_WasInit(%x) should be true (%x)", subsystem, initialized_system); @@ -46,7 +46,7 @@ static int main_testImpliedJoystickInit(void *arg) /* First initialize the controller */ SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller"); - SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD) == 0, "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); + SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD), "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); /* Then make sure this implicitly initialized the joystick subsystem */ initialized_system = SDL_WasInit(joy_and_controller); @@ -67,8 +67,8 @@ static int main_testImpliedJoystickQuit(void *arg) /* First initialize the controller and the joystick (explicitly) */ SDLTest_AssertCheck((SDL_WasInit(joy_and_controller) & joy_and_controller) == 0, "SDL_WasInit() before init should be false for joystick & controller"); - SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0, "SDL_InitSubSystem(SDL_INIT_JOYSTICK)"); - SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD) == 0, "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); + SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_JOYSTICK), "SDL_InitSubSystem(SDL_INIT_JOYSTICK)"); + SDLTest_AssertCheck(SDL_InitSubSystem(SDL_INIT_GAMEPAD), "SDL_InitSubSystem(SDL_INIT_GAMEPAD)"); /* Then make sure they're both initialized properly */ initialized_system = SDL_WasInit(joy_and_controller); @@ -101,13 +101,13 @@ main_testSetError(void *arg) SDLTest_AssertPass("SDL_SetError(NULL)"); result = SDL_SetError(NULL); - SDLTest_AssertCheck(result == -1, "SDL_SetError(NULL) -> %d (expected %d)", result, -1); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError(NULL) -> %d (expected %d)", result, SDL_FALSE); error = SDL_GetError(); SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, ""); SDLTest_AssertPass("SDL_SetError(\"\")"); result = SDL_SetError(""); - SDLTest_AssertCheck(result == -1, "SDL_SetError(\"\") -> %d (expected %d)", result, -1); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError(\"\") -> %d (expected %d)", result, SDL_FALSE); error = SDL_GetError(); SDLTest_AssertCheck(SDL_strcmp(error, "") == 0, "SDL_GetError() -> \"%s\" (expected \"%s\")", error, ""); @@ -118,7 +118,7 @@ main_testSetError(void *arg) error_input[i] = '\0'; SDLTest_AssertPass("SDL_SetError(\"abc...\")"); result = SDL_SetError("%s", error_input); - SDLTest_AssertCheck(result == -1, "SDL_SetError(\"abc...\") -> %d (expected %d)", result, -1); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError(\"abc...\") -> %d (expected %d)", result, SDL_FALSE); error = SDL_GetError(); #ifdef SDL_THREADS_DISABLED diff --git a/test/testautomation_mouse.c b/test/testautomation_mouse.c index ef2f4c047f..1b90da0dc0 100644 --- a/test/testautomation_mouse.c +++ b/test/testautomation_mouse.c @@ -402,7 +402,7 @@ static int mouse_getSetRelativeMouseMode(void *arg) /* Disable - should always be supported */ result = SDL_SetWindowRelativeMouseMode(window, SDL_FALSE); SDLTest_AssertPass("Call to SDL_SetWindowRelativeMouseMode(window, FALSE)"); - SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: SDL_TRUE, got: %i", result); currentState = SDL_GetWindowRelativeMouseMode(window); SDLTest_AssertPass("Call to SDL_GetWindowRelativeMouseMode(window)"); SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); @@ -414,7 +414,7 @@ static int mouse_getSetRelativeMouseMode(void *arg) result = SDL_SetWindowRelativeMouseMode(window, SDL_TRUE); SDLTest_AssertPass("Call to SDL_SetWindowRelativeMouseMode(window, TRUE)"); if (result != -1) { - SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: SDL_TRUE, got: %i", result); currentState = SDL_GetWindowRelativeMouseMode(window); SDLTest_AssertPass("Call to SDL_GetWindowRelativeMouseMode(window)"); SDLTest_AssertCheck(currentState == SDL_TRUE, "Validate current state is TRUE, got: %i", currentState); @@ -424,7 +424,7 @@ static int mouse_getSetRelativeMouseMode(void *arg) /* Disable to check E->D transition */ result = SDL_SetWindowRelativeMouseMode(window, SDL_FALSE); SDLTest_AssertPass("Call to SDL_SetWindowRelativeMouseMode(window, FALSE)"); - SDLTest_AssertCheck(result == 0, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result value from SDL_SetWindowRelativeMouseMode, expected: SDL_TRUE, got: %i", result); currentState = SDL_GetWindowRelativeMouseMode(window); SDLTest_AssertPass("Call to SDL_GetWindowRelativeMouseMode(window)"); SDLTest_AssertCheck(currentState == SDL_FALSE, "Validate current state is FALSE, got: %i", currentState); diff --git a/test/testautomation_platform.c b/test/testautomation_platform.c index d2513c8b85..3bdbff6911 100644 --- a/test/testautomation_platform.c +++ b/test/testautomation_platform.c @@ -223,7 +223,7 @@ static int platform_testGetVersion(void *arg) */ static int platform_testDefaultInit(void *arg) { - int ret; + SDL_bool ret; int subsystem; subsystem = SDL_WasInit(0); @@ -232,8 +232,8 @@ static int platform_testDefaultInit(void *arg) subsystem); ret = SDL_Init(0); - SDLTest_AssertCheck(ret == 0, - "SDL_Init(0): returned %i, expected 0, error: %s", + SDLTest_AssertCheck(ret == SDL_TRUE, + "SDL_Init(0): returned %i, expected SDL_TRUE, error: %s", ret, SDL_GetError()); @@ -268,7 +268,7 @@ static int platform_testGetSetClearError(void *arg) result = SDL_SetError("%s", testError); SDLTest_AssertPass("SDL_SetError()"); - SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError: expected SDL_FALSE, got: %i", result); lastError = SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); @@ -304,7 +304,7 @@ static int platform_testSetErrorEmptyInput(void *arg) result = SDL_SetError("%s", testError); SDLTest_AssertPass("SDL_SetError()"); - SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError: expected SDL_FALSE, got: %i", result); lastError = SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); @@ -351,7 +351,7 @@ static int platform_testSetErrorInvalidInput(void *arg) /* Check for no-op */ result = SDL_SetError("%s", invalidError); SDLTest_AssertPass("SDL_SetError()"); - SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError: expected SDL_FALSE, got: %i", result); lastError = SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); @@ -365,12 +365,12 @@ static int platform_testSetErrorInvalidInput(void *arg) /* Set */ result = SDL_SetError("%s", probeError); SDLTest_AssertPass("SDL_SetError('%s')", probeError); - SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError: expected SDL_FALSE, got: %i", result); /* Check for no-op */ result = SDL_SetError("%s", invalidError); SDLTest_AssertPass("SDL_SetError(NULL)"); - SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError: expected SDL_FALSE, got: %i", result); lastError = SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); @@ -388,7 +388,7 @@ static int platform_testSetErrorInvalidInput(void *arg) /* Set and check */ result = SDL_SetError("%s", probeError); SDLTest_AssertPass("SDL_SetError()"); - SDLTest_AssertCheck(result == -1, "SDL_SetError: expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "SDL_SetError: expected SDL_FALSE, got: %i", result); lastError = SDL_GetError(); SDLTest_AssertCheck(lastError != NULL, "SDL_GetError() != NULL"); diff --git a/test/testautomation_properties.c b/test/testautomation_properties.c index 1d1ea4f59c..c893cddaec 100644 --- a/test/testautomation_properties.c +++ b/test/testautomation_properties.c @@ -45,7 +45,7 @@ static int properties_testBasic(void *arg) SDL_snprintf(expected_value, SDL_arraysize(expected_value), "%c", 'a' + i); result = SDL_SetPointerProperty(props, key, expected_value); SDLTest_AssertPass("Call to SDL_SetPointerProperty()"); - SDLTest_AssertCheck(result == 0, + SDLTest_AssertCheck(result == SDL_TRUE, "Verify property value was set, got: %d", result); value = SDL_GetPointerProperty(props, key, NULL); SDLTest_AssertPass("Call to SDL_GetPointerProperty()"); @@ -62,7 +62,7 @@ static int properties_testBasic(void *arg) SDL_snprintf(key, SDL_arraysize(key), "%c", 'a' + i); result = SDL_SetPointerProperty(props, key, NULL); SDLTest_AssertPass("Call to SDL_SetPointerProperty(NULL)"); - SDLTest_AssertCheck(result == 0, + SDLTest_AssertCheck(result == SDL_TRUE, "Verify property value was set, got: %d", result); value = SDL_GetPointerProperty(props, key, NULL); SDLTest_AssertPass("Call to SDL_GetPointerProperty()"); @@ -238,18 +238,18 @@ static int properties_testCopy(void *arg) SDLTest_AssertPass("Call to SDL_CopyProperties(a, 0)"); result = SDL_CopyProperties(a, 0); - SDLTest_AssertCheck(result == -1, - "SDL_CopyProperties() result, got %d, expected -1", result); + SDLTest_AssertCheck(result == SDL_FALSE, + "SDL_CopyProperties() result, got %d, expected SDL_FALSE", result); SDLTest_AssertPass("Call to SDL_CopyProperties(0, b)"); result = SDL_CopyProperties(0, b); - SDLTest_AssertCheck(result == -1, - "SDL_CopyProperties() result, got %d, expected -1", result); + SDLTest_AssertCheck(result == SDL_FALSE, + "SDL_CopyProperties() result, got %d, expected SDL_FALSE", result); SDLTest_AssertPass("Call to SDL_CopyProperties(a, b)"); result = SDL_CopyProperties(a, b); - SDLTest_AssertCheck(result == 0, - "SDL_CopyProperties() result, got %d, expected 0", result); + SDLTest_AssertCheck(result == SDL_TRUE, + "SDL_CopyProperties() result, got %d, expected SDL_TRUE", result); SDL_DestroyProperties(a); diff --git a/test/testautomation_render.c b/test/testautomation_render.c index 640e6705bb..809a7ae918 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -22,9 +22,9 @@ #define CHECK_FUNC(FUNC, PARAMS) \ { \ - int result = FUNC PARAMS; \ - if (result != 0) { \ - SDLTest_AssertCheck(result == 0, "Validate result from %s, expected: 0, got: %i, %s", #FUNC, result, SDL_GetError()); \ + SDL_bool result = FUNC PARAMS; \ + if (!result) { \ + SDLTest_AssertCheck(result, "Validate result from %s, expected: SDL_TRUE, got: SDL_FALSE, %s", #FUNC, SDL_GetError()); \ } \ } @@ -38,8 +38,8 @@ static int clearScreen(void); static void compare(SDL_Surface *reference, int allowable_error); static void compare2x(SDL_Surface *reference, int allowable_error); static SDL_Texture *loadTestFace(void); -static int hasDrawColor(void); -static int isSupported(int code); +static SDL_bool isSupported(int code); +static SDL_bool hasDrawColor(void); /** * Create software renderer for tests @@ -145,12 +145,12 @@ static int render_testPrimitives(void *arg) for (y = 0; y < 3; y++) { for (x = y % 2; x < TESTRENDER_SCREEN_W; x += 2) { ret = SDL_SetRenderDrawColor(renderer, (Uint8)(x * y), (Uint8)(x * y / 2), (Uint8)(x * y / 3), SDL_ALPHA_OPAQUE); - if (ret != 0) { + if (!ret) { checkFailCount1++; } ret = SDL_RenderPoint(renderer, (float)x, (float)y); - if (ret != 0) { + if (!ret) { checkFailCount2++; } } @@ -271,7 +271,7 @@ static int render_testBlit(void *arg) rect.x = i; rect.y = j; ret = SDL_RenderTexture(renderer, tface, NULL, &rect); - if (ret != 0) { + if (!ret) { checkFailCount1++; } } @@ -323,7 +323,7 @@ static int render_testBlitTiled(void *arg) rect.w = (float)TESTRENDER_SCREEN_W; rect.h = (float)TESTRENDER_SCREEN_H; ret = SDL_RenderTextureTiled(renderer, tface, NULL, 1.0f, &rect); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_RenderTextureTiled, expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ referenceSurface = SDLTest_ImageBlitTiled(); @@ -344,12 +344,12 @@ static int render_testBlitTiled(void *arg) rect.w = (float)TESTRENDER_SCREEN_W * 2; rect.h = (float)TESTRENDER_SCREEN_H * 2; ret = SDL_RenderTextureTiled(renderer, tface, NULL, 2.0f, &rect); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_RenderTextureTiled, expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format); SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret); compare2x(referenceSurface2x, ALLOWABLE_ERROR_OPAQUE); /* Make current */ @@ -458,7 +458,7 @@ static int render_testBlit9Grid(void *arg) texture = SDL_CreateTextureFromSurface(renderer, source); SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL"); ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_SetTextureScaleMode, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_SetTextureScaleMode, expected: SDL_TRUE, got: %i", ret); /* 9-grid blit - 1.0 scale */ { @@ -478,7 +478,7 @@ static int render_testBlit9Grid(void *arg) rect.w = (float)TESTRENDER_SCREEN_W; rect.h = (float)TESTRENDER_SCREEN_H; ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_RenderTexture9Grid, expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); @@ -505,7 +505,7 @@ static int render_testBlit9Grid(void *arg) rect.w = (float)TESTRENDER_SCREEN_W; rect.h = (float)TESTRENDER_SCREEN_H; ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_RenderTexture9Grid, expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); @@ -554,7 +554,7 @@ static int render_testBlit9Grid(void *arg) texture = SDL_CreateTextureFromSurface(renderer, source); SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL"); ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_SetTextureScaleMode, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_SetTextureScaleMode, expected: SDL_TRUE, got: %i", ret); /* complex 9-grid blit - 1.0 scale */ { @@ -574,7 +574,7 @@ static int render_testBlit9Grid(void *arg) rect.w = (float)TESTRENDER_SCREEN_W; rect.h = (float)TESTRENDER_SCREEN_H; ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_RenderTexture9Grid, expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); @@ -601,7 +601,7 @@ static int render_testBlit9Grid(void *arg) rect.w = (float)TESTRENDER_SCREEN_W; rect.h = (float)TESTRENDER_SCREEN_H; ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_RenderTexture9Grid, expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); @@ -660,7 +660,7 @@ static int render_testBlitColor(void *arg) for (i = 0; i <= ni; i += 4) { /* Set color mod. */ ret = SDL_SetTextureColorMod(tface, (Uint8)((255 / nj) * j), (Uint8)((255 / ni) * i), (Uint8)((255 / nj) * j)); - if (ret != 0) { + if (!ret) { checkFailCount1++; } @@ -668,7 +668,7 @@ static int render_testBlitColor(void *arg) rect.x = (float)i; rect.y = (float)j; ret = SDL_RenderTexture(renderer, tface, NULL, &rect); - if (ret != 0) { + if (!ret) { checkFailCount2++; } } @@ -730,7 +730,7 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) { SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; ret = SDL_GetTextureBlendMode(dst, &blendMode); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_GetTextureBlendMode(), expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_GetTextureBlendMode(), expected: SDL_TRUE, got: %i", ret); SDLTest_AssertCheck(blendMode == SDL_BLENDMODE_BLEND, "Verify alpha texture blend mode, expected %d, got %" SDL_PRIu32, SDL_BLENDMODE_BLEND, blendMode); } @@ -742,10 +742,10 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo dstA = 255; } ret = SDL_SetRenderDrawColor(renderer, dstR, dstG, dstB, dstA); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawColor(), expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetRenderDrawColor(), expected: SDL_TRUE, got: %i", ret); ret = SDL_RenderClear(renderer); SDLTest_AssertPass("Call to SDL_RenderClear()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_RenderClear, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_RenderClear, expected: SDL_TRUE, got: %i", ret); if (op == TEST_RENDER_COPY_XRGB || op == TEST_RENDER_COPY_ARGB) { Uint8 pixels[4]; @@ -771,26 +771,26 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo if (mode >= 0) { ret = SDL_SetTextureBlendMode(src, (SDL_BlendMode)mode); SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: 0, got: %i", mode, ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret); } else { ret = SDL_SetTextureBlendMode(src, SDL_BLENDMODE_BLEND); SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: 0, got: %i", mode, ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret); } } else { /* Set draw color */ ret = SDL_SetRenderDrawColor(renderer, srcR, srcG, srcB, srcA); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawColor(), expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetRenderDrawColor(), expected: SDL_TRUE, got: %i", ret); /* Set blend mode. */ if (mode >= 0) { ret = SDL_SetRenderDrawBlendMode(renderer, (SDL_BlendMode)mode); SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: 0, got: %i", mode, ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret); } else { ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: 0, got: %i", mode, ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret); } } @@ -800,7 +800,7 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo case -1: mode_name = "color modulation"; ret = SDL_SetTextureColorMod(src, srcR, srcG, srcB); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_SetTextureColorMod, expected: SDL_TRUE, got: %i", ret); expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); @@ -809,7 +809,7 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo case -2: mode_name = "alpha modulation"; ret = SDL_SetTextureAlphaMod(src, srcA); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_SetTextureAlphaMod, expected: SDL_TRUE, got: %i", ret); expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstR) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f); expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstG) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f); expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstB) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f); @@ -873,23 +873,23 @@ static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFo case TEST_RENDER_POINT: operation = "render point"; ret = SDL_RenderPoint(renderer, 0.0f, 0.0f); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", ret); break; case TEST_RENDER_LINE: operation = "render line"; ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 2.0f, 2.0f); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderLine, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_RenderLine, expected: SDL_TRUE, got: %i", ret); break; case TEST_RENDER_RECT: operation = "render rect"; ret = SDL_RenderFillRect(renderer, NULL); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i", ret); break; case TEST_RENDER_COPY_XRGB: case TEST_RENDER_COPY_ARGB: operation = (op == TEST_RENDER_COPY_XRGB) ? "render XRGB" : "render ARGB"; ret = SDL_RenderTexture(renderer, src, NULL, NULL); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_RenderTexture, expected: SDL_TRUE, got: %i", ret); break; default: SDLTest_LogError("Invalid blending operation: %d", op); @@ -1251,10 +1251,9 @@ static int render_testLogicalSize(void *arg) /** * Checks to see if functionality is supported. Helper function. */ -static int -isSupported(int code) +static SDL_bool isSupported(int code) { - return code == 0; + return (code != SDL_FALSE); } /** @@ -1263,8 +1262,7 @@ isSupported(int code) * \sa SDL_SetRenderDrawColor * \sa SDL_GetRenderDrawColor */ -static int -hasDrawColor(void) +static SDL_bool hasDrawColor(void) { int ret, fail; Uint8 r, g, b, a; @@ -1289,13 +1287,13 @@ hasDrawColor(void) /* Something failed, consider not available. */ if (fail) { - return 0; + return SDL_FALSE; } /* Not set properly, consider failed. */ else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) { - return 0; + return SDL_FALSE; } - return 1; + return SDL_TRUE; } /** @@ -1417,18 +1415,18 @@ clearScreen(void) /* Set color. */ ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_SetRenderDrawColor, expected: SDL_TRUE, got: %i", ret); /* Clear screen. */ ret = SDL_RenderClear(renderer); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderClear, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_RenderClear, expected: SDL_TRUE, got: %i", ret); /* Set defaults. */ ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_SetRenderDrawBlendMode, expected: SDL_TRUE, got: %i", ret); ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_SetRenderDrawColor, expected: SDL_TRUE, got: %i", ret); return 0; } diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c index 9c4ce0de36..de1ce38a17 100644 --- a/test/testautomation_surface.c +++ b/test/testautomation_surface.c @@ -25,9 +25,9 @@ #define CHECK_FUNC(FUNC, PARAMS) \ { \ - int result = FUNC PARAMS; \ - if (result != 0) { \ - SDLTest_AssertCheck(result == 0, "Validate result from %s, expected: 0, got: %i, %s", #FUNC, result, SDL_GetError()); \ + SDL_bool result = FUNC PARAMS; \ + if (!result) { \ + SDLTest_AssertCheck(result, "Validate result from %s, expected: SDL_TRUE, got: SDL_FALSE, %s", #FUNC, SDL_GetError()); \ } \ } @@ -53,14 +53,14 @@ static void surfaceSetUp(void *arg) if (testSurface != NULL) { /* Disable blend mode for target surface */ result = SDL_SetSurfaceBlendMode(testSurface, blendMode); - SDLTest_AssertCheck(result == 0, "Validate result from SDL_SetSurfaceBlendMode, expected: 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result from SDL_SetSurfaceBlendMode, expected: SDL_TRUE, got: %i", result); result = SDL_GetSurfaceBlendMode(testSurface, ¤tBlendMode); - SDLTest_AssertCheck(result == 0, "Validate result from SDL_GetSurfaceBlendMode, expected: 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result from SDL_GetSurfaceBlendMode, expected: SDL_TRUE, got: %i", result); SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, blendMode, currentBlendMode); /* Clear the target surface */ result = SDL_FillSurfaceRect(testSurface, NULL, SDL_MapSurfaceRGBA(testSurface, 0, 0, 0, 255)); - SDLTest_AssertCheck(result == 0, "Validate result from SDL_FillSurfaceRect, expected: 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Validate result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", result); } } @@ -133,7 +133,7 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S } ret = SDL_FillSurfaceRect(dst, NULL, color); SDLTest_AssertPass("Call to SDL_FillSurfaceRect()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillSurfaceRect, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", ret); SDL_GetRGBA(color, SDL_GetPixelFormatDetails(dst->format), SDL_GetSurfacePalette(dst), &dstR, &dstG, &dstB, &dstA); /* Create src surface */ @@ -153,35 +153,35 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S /* Reset alpha modulation */ ret = SDL_SetSurfaceAlphaMod(src, 255); SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceAlphaMod(), expected: SDL_TRUE, got: %i", ret); /* Reset color modulation */ ret = SDL_SetSurfaceColorMod(src, 255, 255, 255); SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorMod(), expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorMod(), expected: SDL_TRUE, got: %i", ret); /* Reset color key */ ret = SDL_SetSurfaceColorKey(src, SDL_FALSE, 0); SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey(), expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorKey(), expected: SDL_TRUE, got: %i", ret); /* Clear surface. */ color = SDL_MapSurfaceRGBA(src, srcR, srcG, srcB, srcA); SDLTest_AssertPass("Call to SDL_MapSurfaceRGBA()"); ret = SDL_FillSurfaceRect(src, NULL, color); SDLTest_AssertPass("Call to SDL_FillSurfaceRect()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_FillSurfaceRect, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", ret); SDL_GetRGBA(color, SDL_GetPixelFormatDetails(src->format), SDL_GetSurfacePalette(src), &srcR, &srcG, &srcB, &srcA); /* Set blend mode. */ if (mode >= 0) { ret = SDL_SetSurfaceBlendMode(src, (SDL_BlendMode)mode); SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret); } else { ret = SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND); SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 0, got: %i", mode, ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret); } /* Test blend mode. */ @@ -190,7 +190,7 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S case -1: /* Set color mod. */ ret = SDL_SetSurfaceColorMod(src, srcR, srcG, srcB); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_SetSurfaceColorMod, expected: SDL_TRUE, got: %i", ret); expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); @@ -199,7 +199,7 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S case -2: /* Set alpha mod. */ ret = SDL_SetSurfaceAlphaMod(src, srcA); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: SDL_TRUE, got: %i", ret); expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstR) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f); expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstG) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f); expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstB) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f); @@ -262,8 +262,8 @@ static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, S /* Blitting. */ ret = SDL_BlitSurface(src, NULL, dst, NULL); - SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_BlitSurface, expected: 0, got: %i: %s", ret, (ret < 0) ? SDL_GetError() : "success"); - if (ret == 0) { + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_BlitSurface, expected: SDL_TRUE, got: %i: %s", ret, !ret ? SDL_GetError() : "success"); + if (ret) { SDL_ReadSurfacePixel(dst, 0, 0, &actualR, &actualG, &actualB, &actualA); deltaR = SDL_abs((int)actualR - expectedR); deltaG = SDL_abs((int)actualG - expectedG); @@ -336,7 +336,7 @@ static int surface_testSaveLoadBitmap(void *arg) /* Save a surface */ ret = SDL_SaveBMP(face, sampleFilename); SDLTest_AssertPass("Call to SDL_SaveBMP()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SaveBMP, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SaveBMP, expected: SDL_TRUE, got: %i", ret); AssertFileExist(sampleFilename); /* Load a surface */ @@ -380,7 +380,7 @@ static int surface_testBlitTiled(void *arg) /* Tiled blit - 1.0 scale */ { ret = SDL_BlitSurfaceTiled(face, NULL, testSurface, NULL); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_BlitSurfaceTiled expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_BlitSurfaceTiled expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ SDL_DestroySurface(referenceSurface); @@ -394,15 +394,15 @@ static int surface_testBlitTiled(void *arg) testSurface2x = SDL_CreateSurface(testSurface->w * 2, testSurface->h * 2, testSurface->format); SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface2x is not NULL"); ret = SDL_FillSurfaceRect(testSurface2x, NULL, SDL_MapSurfaceRGBA(testSurface2x, 0, 0, 0, 255)); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_FillSurfaceRect, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", ret); ret = SDL_BlitSurfaceTiledWithScale(face, NULL, 2.0f, SDL_SCALEMODE_NEAREST, testSurface2x, NULL); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_BlitSurfaceTiledWithScale, expected: SDL_TRUE, got: %i", ret); /* See if it's the same */ referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format); SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST); - SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_BlitSurfaceScaled, expected: SDL_TRUE, got: %i", ret); ret = SDLTest_CompareSurfaces(testSurface2x, referenceSurface2x, 0); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); } @@ -512,7 +512,7 @@ static int surface_testBlit9Grid(void *arg) Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1); ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_BlitSurface9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret); ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); @@ -527,7 +527,7 @@ static int surface_testBlit9Grid(void *arg) Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2); ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_BlitSurface9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret); ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); @@ -579,7 +579,7 @@ static int surface_testBlit9Grid(void *arg) Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2); ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_BlitSurface9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret); ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); @@ -595,7 +595,7 @@ static int surface_testBlit9Grid(void *arg) Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4); ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL); - SDLTest_AssertCheck(ret == 0, "Validate result from SDL_BlitSurface9Grid, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret); ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0); SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); @@ -691,7 +691,7 @@ static int surface_testSurfaceConversion(void *arg) if (SDL_GetSurfacePalette(face)) { ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels); SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorKey, expected: SDL_TRUE, got: %i", ret); } /* Convert to 32 bit to compare. */ @@ -766,7 +766,7 @@ static int surface_testCompleteSurfaceConversion(void *arg) if (SDL_GetSurfacePalette(face)) { ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels); SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()"); - SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetSurfaceColorKey, expected: 0, got: %i", ret); + SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorKey, expected: SDL_TRUE, got: %i", ret); } for (i = 0; i < SDL_arraysize(pixel_formats); ++i) { @@ -1312,7 +1312,7 @@ static int surface_testPalettization(void *arg) SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()"); result = SDL_SetPaletteColors(palette, palette_colors, 0, SDL_arraysize(palette_colors)); - SDLTest_AssertCheck(result >= 0, "SDL_SetPaletteColors()"); + SDLTest_AssertCheck(result, "SDL_SetPaletteColors()"); source = SDL_CreateSurface(SDL_arraysize(palette_colors) + SDL_arraysize(colors), 1, SDL_PIXELFORMAT_RGBA8888); SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()"); @@ -1321,11 +1321,11 @@ static int surface_testPalettization(void *arg) SDLTest_AssertCheck(source->format == SDL_PIXELFORMAT_RGBA8888, "Expected source->format == SDL_PIXELFORMAT_RGBA8888, got 0x%x (%s)", source->format, SDL_GetPixelFormatName(source->format)); for (i = 0; i < SDL_arraysize(colors); i++) { result = SDL_WriteSurfacePixel(source, i, 0, colors[i].c.r, colors[i].c.g, colors[i].c.b, colors[i].c.a); - SDLTest_AssertCheck(result >= 0, "SDL_WriteSurfacePixel"); + SDLTest_AssertCheck(result == SDL_TRUE, "SDL_WriteSurfacePixel"); } for (i = 0; i < SDL_arraysize(palette_colors); i++) { result = SDL_WriteSurfacePixel(source, SDL_arraysize(colors) + i, 0, palette_colors[i].r, palette_colors[i].g, palette_colors[i].b, palette_colors[i].a); - SDLTest_AssertCheck(result >= 0, "SDL_WriteSurfacePixel"); + SDLTest_AssertCheck(result == SDL_TRUE, "SDL_WriteSurfacePixel"); } output = SDL_ConvertSurfaceAndColorspace(source, SDL_PIXELFORMAT_INDEX8, palette, SDL_COLORSPACE_UNKNOWN, 0); @@ -1383,9 +1383,9 @@ static int surface_testClearSurface(void *arg) surface = SDL_CreateSurface(1, 1, format); SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()"); ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA); - SDLTest_AssertCheck(ret == 0, "SDL_ClearSurface()"); + SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ClearSurface()"); ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, &actualA); - SDLTest_AssertCheck(ret == 0, "SDL_ReadSurfacePixelFloat()"); + SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ReadSurfacePixelFloat()"); deltaR = SDL_fabsf(actualR - srcR); deltaG = SDL_fabsf(actualG - srcG); deltaB = SDL_fabsf(actualB - srcB); @@ -1433,13 +1433,13 @@ static int surface_testPremultiplyAlpha(void *arg) surface = SDL_CreateSurface(1, 1, format); SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()"); ret = SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB); - SDLTest_AssertCheck(ret == 0, "SDL_SetSurfaceColorspace()"); + SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_SetSurfaceColorspace()"); ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA); - SDLTest_AssertCheck(ret == 0, "SDL_ClearSurface()"); + SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ClearSurface()"); ret = SDL_PremultiplySurfaceAlpha(surface, SDL_FALSE); - SDLTest_AssertCheck(ret == 0, "SDL_PremultiplySurfaceAlpha()"); + SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_PremultiplySurfaceAlpha()"); ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, NULL); - SDLTest_AssertCheck(ret == 0, "SDL_ReadSurfacePixelFloat()"); + SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ReadSurfacePixelFloat()"); deltaR = SDL_fabsf(actualR - expectedR); deltaG = SDL_fabsf(actualG - expectedG); deltaB = SDL_fabsf(actualB - expectedB); diff --git a/test/testautomation_time.c b/test/testautomation_time.c index eaac52a411..11a40a87d0 100644 --- a/test/testautomation_time.c +++ b/test/testautomation_time.c @@ -20,7 +20,7 @@ static int time_getRealtimeClock(void *arg) result = SDL_GetCurrentTime(&ticks); SDLTest_AssertPass("Call to SDL_GetRealtimeClockTicks()"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); return TEST_COMPLETED; } @@ -38,7 +38,7 @@ static int time_dateTimeConversion(void *arg) result = SDL_TimeToDateTime(ticks[0], &dt, SDL_FALSE); SDLTest_AssertPass("Call to SDL_TimeToUTCDateTime()"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); SDLTest_AssertCheck(dt.year == 2000, "Check year value, expected 2000, got: %i", dt.year); SDLTest_AssertCheck(dt.month == 1, "Check month value, expected 1, got: %i", dt.month); SDLTest_AssertCheck(dt.day == 1, "Check day value, expected 1, got: %i", dt.day); @@ -48,7 +48,7 @@ static int time_dateTimeConversion(void *arg) result = SDL_DateTimeToTime(&dt, &ticks[1]); SDLTest_AssertPass("Call to SDL_DateTimeToTime()"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); result = ticks[0] == ticks[1]; SDLTest_AssertCheck(result, "Check that original and converted SDL_Time values match: ticks0 = %" SDL_PRIs64 ", ticks1 = %" SDL_PRIs64, ticks[0], ticks[1]); @@ -56,12 +56,12 @@ static int time_dateTimeConversion(void *arg) /* Local time unknown, so just verify success. */ result = SDL_TimeToDateTime(ticks[0], &dt, SDL_TRUE); SDLTest_AssertPass("Call to SDL_TimeToLocalDateTime()"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); /* Convert back and verify result. */ result = SDL_DateTimeToTime(&dt, &ticks[1]); SDLTest_AssertPass("Call to SDL_DateTimeToTime()"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); result = ticks[0] == ticks[1]; SDLTest_AssertCheck(result, "Check that original and converted SDL_Time values match: ticks0 = %" SDL_PRIs64 ", ticks1 = %" SDL_PRIs64, ticks[0], ticks[1]); @@ -79,7 +79,7 @@ static int time_dateTimeConversion(void *arg) result = SDL_DateTimeToTime(&dt, &ticks[1]); SDLTest_AssertPass("Call to SDL_DateTimeToTime() (one day advanced)"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); result = (ticks[0] + (Sint64)SDL_SECONDS_TO_NS(86400)) == ticks[1]; SDLTest_AssertCheck(result, "Check that the difference is exactly 86400 seconds, got: %" SDL_PRIs64, (Sint64)SDL_NS_TO_SECONDS(ticks[1] - ticks[0])); @@ -90,12 +90,12 @@ static int time_dateTimeConversion(void *arg) dt.day = 1; result = SDL_DateTimeToTime(&dt, &ticks[0]); SDLTest_AssertPass("Call to SDL_DateTimeToTime() (year overflows an SDL_Time)"); - SDLTest_AssertCheck(result == -1, "Check result value, expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected SDL_FALSE, got: %i", result); dt.year = 1601; result = SDL_DateTimeToTime(&dt, &ticks[0]); SDLTest_AssertPass("Call to SDL_DateTimeToTime() (year underflows an SDL_Time)"); - SDLTest_AssertCheck(result == -1, "Check result value, expected -1, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected SDL_FALSE, got: %i", result); return TEST_COMPLETED; } @@ -175,19 +175,19 @@ static int time_dateTimeUtilities(void *arg) result = SDL_GetDateTimeLocalePreferences(&dateFormat, &timeFormat); SDLTest_AssertPass("Call to SDL_GetDateTimeLocalePreferences(&dateFormat, &timeFormat)"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); result = SDL_GetDateTimeLocalePreferences(&dateFormat, NULL); SDLTest_AssertPass("Call to SDL_GetDateTimeLocalePreferences(&dateFormat, NULL)"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); result = SDL_GetDateTimeLocalePreferences(NULL, &timeFormat); SDLTest_AssertPass("Call to SDL_GetDateTimeLocalePreferences(NULL, &timeFormat)"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); result = SDL_GetDateTimeLocalePreferences(NULL, NULL); SDLTest_AssertPass("Call to SDL_GetDateTimeLocalePreferences(NULL, NULL)"); - SDLTest_AssertCheck(result == 0, "Check result value, expected 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected SDL_TRUE, got: %i", result); return TEST_COMPLETED; } diff --git a/test/testautomation_timer.c b/test/testautomation_timer.c index e58e23d255..d04979efad 100644 --- a/test/testautomation_timer.c +++ b/test/testautomation_timer.c @@ -23,10 +23,10 @@ static int g_timerCallbackCalled = 0; static void timerSetUp(void *arg) { /* Start SDL timer subsystem */ - int ret = SDL_InitSubSystem(SDL_INIT_TIMER); + SDL_bool ret = SDL_InitSubSystem(SDL_INIT_TIMER); SDLTest_AssertPass("Call to SDL_InitSubSystem(SDL_INIT_TIMER)"); - SDLTest_AssertCheck(ret == 0, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)"); - if (ret != 0) { + SDLTest_AssertCheck(ret == SDL_TRUE, "Check result from SDL_InitSubSystem(SDL_INIT_TIMER)"); + if (!ret) { SDLTest_LogError("%s", SDL_GetError()); } } @@ -148,13 +148,13 @@ static int timer_addRemoveTimer(void *arg) /* Remove timer again and check that callback was not called */ result = SDL_RemoveTimer(id); SDLTest_AssertPass("Call to SDL_RemoveTimer()"); - SDLTest_AssertCheck(result == 0, "Check result value, expected: 0, got: %i", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Check result value, expected: SDL_TRUE, got: %i", result); SDLTest_AssertCheck(g_timerCallbackCalled == 0, "Check callback WAS NOT called, expected: 0, got: %i", g_timerCallbackCalled); /* Try to remove timer again (should be a NOOP) */ result = SDL_RemoveTimer(id); SDLTest_AssertPass("Call to SDL_RemoveTimer()"); - SDLTest_AssertCheck(result < 0, "Check result value, expected: <0, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: SDL_FALSE, got: %i", result); /* Reset state */ param = SDLTest_RandomIntegerInRange(-1024, 1024); @@ -174,7 +174,7 @@ static int timer_addRemoveTimer(void *arg) /* Remove timer again and check that callback was called */ result = SDL_RemoveTimer(id); SDLTest_AssertPass("Call to SDL_RemoveTimer()"); - SDLTest_AssertCheck(result < 0, "Check result value, expected: <0, got: %i", result); + SDLTest_AssertCheck(result == SDL_FALSE, "Check result value, expected: SDL_FALSE, got: %i", result); SDLTest_AssertCheck(g_timerCallbackCalled == 1, "Check callback WAS called, expected: 1, got: %i", g_timerCallbackCalled); return TEST_COMPLETED; diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 7074dd294c..b06d609e1c 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -360,7 +360,7 @@ static int video_getClosestDisplayModeCurrentResolution(void *arg) /* Make call */ result = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, SDL_FALSE, &closest); SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); /* Check that one gets the current resolution back again */ if (result == 0) { @@ -815,7 +815,7 @@ static int video_getSetWindowPosition(void *arg) /* Sanity check */ SDL_GetWindowPosition(window, ¤tX, ¤tY); - if (SDL_SetWindowPosition(window, currentX, currentY) < 0) { + if (!SDL_SetWindowPosition(window, currentX, currentY)) { SDLTest_Log("Skipping window positioning tests: %s reports window positioning as unsupported", SDL_GetCurrentVideoDriver()); goto null_tests; } @@ -891,7 +891,7 @@ static int video_getSetWindowPosition(void *arg) result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); /* Get position */ currentX = desiredX + 1; @@ -1013,9 +1013,9 @@ static int video_getSetWindowSize(void *arg) /* Get display bounds for size range */ result = SDL_GetDisplayUsableBounds(SDL_GetPrimaryDisplay(), &display); - SDLTest_AssertPass("SDL_GetDisplayBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) { + SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); + if (!result) { return TEST_ABORTED; } @@ -1098,7 +1098,7 @@ static int video_getSetWindowSize(void *arg) result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); /* Get size */ currentW = desiredW + 1; @@ -1213,8 +1213,8 @@ static int video_getSetWindowMinimumSize(void *arg) /* Get display bounds for size range */ result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) { + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); + if (!result) { return TEST_ABORTED; } @@ -1355,8 +1355,8 @@ static int video_getSetWindowMaximumSize(void *arg) /* Get display bounds for size range */ result = SDL_GetDisplayBounds(SDL_GetPrimaryDisplay(), &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) { + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); + if (!result) { return TEST_ABORTED; } @@ -1693,15 +1693,15 @@ static int video_setWindowCenteredOnDisplay(void *arg) /* Get display bounds */ result = SDL_GetDisplayUsableBounds(displays[0 % displayNum], &display0); SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) { + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); + if (!result) { return TEST_ABORTED; } result = SDL_GetDisplayUsableBounds(displays[1 % displayNum], &display1); SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); - if (result != 0) { + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); + if (!result) { return TEST_ABORTED; } @@ -1781,11 +1781,11 @@ static int video_setWindowCenteredOnDisplay(void *arg) /* Enter fullscreen desktop */ SDL_SetWindowPosition(window, x, y); result = SDL_SetWindowFullscreen(window, SDL_TRUE); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); /* Check we are filling the full display */ currentDisplay = SDL_GetDisplayForWindow(window); @@ -1798,7 +1798,7 @@ static int video_setWindowCenteredOnDisplay(void *arg) */ result = SDL_GetDisplayBounds(expectedDisplay, &expectedFullscreenRect); SDLTest_AssertPass("SDL_GetDisplayBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); if (video_driver_is_wayland) { SDLTest_Log("Skipping display ID validation: Wayland driver does not support window positioning"); @@ -1821,11 +1821,11 @@ static int video_setWindowCenteredOnDisplay(void *arg) /* Leave fullscreen desktop */ result = SDL_SetWindowFullscreen(window, SDL_FALSE); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); /* Check window was restored correctly */ currentDisplay = SDL_GetDisplayForWindow(window); @@ -1862,7 +1862,7 @@ static int video_setWindowCenteredOnDisplay(void *arg) result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); currentDisplay = SDL_GetDisplayForWindow(window); SDL_GetWindowSize(window, ¤tW, ¤tH); @@ -1958,16 +1958,15 @@ static int video_getSetWindowState(void *arg) /* Maximize and check the dimensions */ result = SDL_MaximizeWindow(window); SDLTest_AssertPass("SDL_MaximizeWindow()"); - if (result < 0) { + if (!result) { SDLTest_Log("Skipping state transition tests: %s reports window maximizing as unsupported", SDL_GetCurrentVideoDriver()); skipFlags |= SDL_WINDOW_MAXIMIZED; goto minimize_test; } - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -1980,7 +1979,7 @@ static int video_getSetWindowState(void *arg) if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "windows") != 0) { result = SDL_GetDisplayUsableBounds(SDL_GetDisplayForWindow(window), &display); SDLTest_AssertPass("SDL_GetDisplayUsableBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); desiredW = display.w; desiredH = display.h; @@ -1997,11 +1996,11 @@ static int video_getSetWindowState(void *arg) /* Restore and check the dimensions */ result = SDL_RestoreWindow(window); SDLTest_AssertPass("SDL_RestoreWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -2026,15 +2025,15 @@ static int video_getSetWindowState(void *arg) /* Maximize, then immediately restore */ result = SDL_MaximizeWindow(window); SDLTest_AssertPass("SDL_MaximizeWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_RestoreWindow(window); SDLTest_AssertPass("SDL_RestoreWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -2060,15 +2059,15 @@ static int video_getSetWindowState(void *arg) /* Maximize, then enter fullscreen */ result = SDL_MaximizeWindow(window); SDLTest_AssertPass("SDL_MaximizeWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SetWindowFullscreen(window, SDL_TRUE); SDLTest_AssertPass("SDL_SetWindowFullscreen(SDL_TRUE)"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -2078,7 +2077,7 @@ static int video_getSetWindowState(void *arg) /* Verify the fullscreen size and position */ result = SDL_GetDisplayBounds(SDL_GetDisplayForWindow(window), &display); SDLTest_AssertPass("SDL_GetDisplayBounds()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); if (!skipPos) { desiredX = display.x; @@ -2103,15 +2102,15 @@ static int video_getSetWindowState(void *arg) /* Leave fullscreen and restore the window */ result = SDL_SetWindowFullscreen(window, SDL_FALSE); SDLTest_AssertPass("SDL_SetWindowFullscreen(SDL_FALSE)"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_RestoreWindow(window); SDLTest_AssertPass("SDL_RestoreWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -2137,29 +2136,29 @@ static int video_getSetWindowState(void *arg) /* Maximize, change size, and restore */ result = SDL_MaximizeWindow(window); SDLTest_AssertPass("SDL_MaximizeWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); desiredW = windowedW + 10; desiredH = windowedH + 10; result = SDL_SetWindowSize(window, desiredW, desiredH); SDLTest_AssertPass("SDL_SetWindowSize()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); if (!skipPos) { desiredX = windowedX + 10; desiredY = windowedY + 10; result = SDL_SetWindowPosition(window, desiredX, desiredY); SDLTest_AssertPass("SDL_SetWindowPosition()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); } result = SDL_RestoreWindow(window); SDLTest_AssertPass("SDL_RestoreWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -2186,27 +2185,27 @@ static int video_getSetWindowState(void *arg) desiredH = windowedH - 5; result = SDL_SetWindowSize(window, desiredW, desiredH); SDLTest_AssertPass("SDL_SetWindowSize()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); if (!skipPos) { desiredX = windowedX + 5; desiredY = windowedY + 5; result = SDL_SetWindowPosition(window, desiredX, desiredY); SDLTest_AssertPass("SDL_SetWindowPosition()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); } result = SDL_MaximizeWindow(window); SDLTest_AssertPass("SDL_MaximizeWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_RestoreWindow(window); SDLTest_AssertPass("SDL_RestoreWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -2232,13 +2231,13 @@ minimize_test: /* Minimize */ result = SDL_MinimizeWindow(window); - if (result == 0) { + if (result) { SDLTest_AssertPass("SDL_MinimizeWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); result = SDL_SyncWindow(window); SDLTest_AssertPass("SDL_SyncWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); flags = SDL_GetWindowFlags(window); SDLTest_AssertPass("SDL_GetWindowFlags()"); @@ -2286,7 +2285,7 @@ static int video_createMinimized(void *arg) if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) { result = SDL_RestoreWindow(window); SDLTest_AssertPass("SDL_RestoreWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); } else { SDLTest_Log("Requested minimized window on creation, but that isn't supported on this platform."); } @@ -2325,7 +2324,7 @@ static int video_createMaximized(void *arg) if (SDL_GetWindowFlags(window) & SDL_WINDOW_MAXIMIZED) { result = SDL_RestoreWindow(window); SDLTest_AssertPass("SDL_RestoreWindow()"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); } else { SDLTest_Log("Requested maximized window on creation, but that isn't supported on this platform."); } @@ -2365,7 +2364,7 @@ static int video_getWindowSurface(void *arg) result = SDL_UpdateWindowSurface(window); SDLTest_AssertPass("Call to SDL_UpdateWindowSurface(window)"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); /* We shouldn't be able to create a renderer on a window with a surface */ renderer = SDL_CreateRenderer(window, renderer_name); @@ -2374,7 +2373,7 @@ static int video_getWindowSurface(void *arg) result = SDL_DestroyWindowSurface(window); SDLTest_AssertPass("Call to SDL_DestroyWindowSurface(window)"); - SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); + SDLTest_AssertCheck(result == SDL_TRUE, "Verify return value; expected: SDL_TRUE, got: %d", result); SDLTest_AssertCheck(!SDL_WindowHasSurface(window), "Validate that window does not have a surface"); /* We should be able to create a renderer on the window now */ diff --git a/test/testbounds.c b/test/testbounds.c index 143f74c6dc..bb0fb8215a 100644 --- a/test/testbounds.c +++ b/test/testbounds.c @@ -31,7 +31,7 @@ int main(int argc, char **argv) return 1; } - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_Log("SDL_Init(SDL_INIT_VIDEO) failed: %s", SDL_GetError()); return 1; } diff --git a/test/testcamera.c b/test/testcamera.c index 21641a1f02..01107049e0 100644 --- a/test/testcamera.c +++ b/test/testcamera.c @@ -298,9 +298,7 @@ SDL_AppResult SDL_AppIterate(void *appstate) frame_count++; if (frame_current) { - if (SDL_ReleaseCameraFrame(camera, frame_current) < 0) { - SDL_Log("err SDL_ReleaseCameraFrame: %s", SDL_GetError()); - } + SDL_ReleaseCameraFrame(camera, frame_current); } /* It's not needed to keep the frame once updated the texture is updated. @@ -312,7 +310,7 @@ SDL_AppResult SDL_AppIterate(void *appstate) if (frame_current) { if (!texture || - SDL_GetTextureSize(texture, &tw, &th) < 0 || + !SDL_GetTextureSize(texture, &tw, &th) || (int)tw != frame_current->w || (int)th != frame_current->h) { /* Resize the window to match */ SDL_SetWindowSize(window, frame_current->w, frame_current->h); diff --git a/test/testcolorspace.c b/test/testcolorspace.c index 159049f564..d027e011f0 100644 --- a/test/testcolorspace.c +++ b/test/testcolorspace.c @@ -155,7 +155,7 @@ static SDL_bool ReadPixel(int x, int y, SDL_Color *c) surface = SDL_RenderReadPixels(renderer, &r); if (surface) { - if (SDL_ReadSurfacePixel(surface, 0, 0, &c->r, &c->g, &c->b, &c->a) == 0) { + if (SDL_ReadSurfacePixel(surface, 0, 0, &c->r, &c->g, &c->b, &c->a)) { result = SDL_TRUE; } else { SDL_Log("Couldn't read pixel: %s\n", SDL_GetError()); diff --git a/test/testcontroller.c b/test/testcontroller.c index dd1311f4c8..2da043ae1f 100644 --- a/test/testcontroller.c +++ b/test/testcontroller.c @@ -1130,22 +1130,22 @@ static void SDLCALL VirtualGamepadSetPlayerIndex(void *userdata, int player_inde SDL_Log("Virtual Gamepad: player index set to %d\n", player_index); } -static int SDLCALL VirtualGamepadRumble(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) +static SDL_bool SDLCALL VirtualGamepadRumble(void *userdata, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble) { SDL_Log("Virtual Gamepad: rumble set to %d/%d\n", low_frequency_rumble, high_frequency_rumble); - return 0; + return SDL_TRUE; } -static int SDLCALL VirtualGamepadRumbleTriggers(void *userdata, Uint16 left_rumble, Uint16 right_rumble) +static SDL_bool SDLCALL VirtualGamepadRumbleTriggers(void *userdata, Uint16 left_rumble, Uint16 right_rumble) { SDL_Log("Virtual Gamepad: trigger rumble set to %d/%d\n", left_rumble, right_rumble); - return 0; + return SDL_TRUE; } -static int SDLCALL VirtualGamepadSetLED(void *userdata, Uint8 red, Uint8 green, Uint8 blue) +static SDL_bool SDLCALL VirtualGamepadSetLED(void *userdata, Uint8 red, Uint8 green, Uint8 blue) { SDL_Log("Virtual Gamepad: LED set to RGB %d,%d,%d\n", red, green, blue); - return 0; + return SDL_TRUE; } static void OpenVirtualGamepad(void) @@ -2044,7 +2044,7 @@ int main(int argc, char *argv[]) } /* Initialize SDL (Note: video is required to start event loop) */ - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMEPAD)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/test/testdialog.c b/test/testdialog.c index c298d7fe83..64c1148f7a 100644 --- a/test/testdialog.c +++ b/test/testdialog.c @@ -80,11 +80,11 @@ int main(int argc, char *argv[]) i += consumed; } - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_Log("SDL_Init failed (%s)", SDL_GetError()); return 1; } - if (SDL_CreateWindowAndRenderer("testdialog", 640, 480, 0, &w, &r) < 0) { + if (!SDL_CreateWindowAndRenderer("testdialog", 640, 480, 0, &w, &r)) { SDL_Log("Failed to create window and/or renderer: %s\n", SDL_GetError()); SDL_Quit(); return 1; diff --git a/test/testdisplayinfo.c b/test/testdisplayinfo.c index afb9e8ac38..be3157cd41 100644 --- a/test/testdisplayinfo.c +++ b/test/testdisplayinfo.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) } /* Load the SDL library */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/test/testdrawchessboard.c b/test/testdrawchessboard.c index 52c1ec23d1..5aa23dc67e 100644 --- a/test/testdrawchessboard.c +++ b/test/testdrawchessboard.c @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) } /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO) != 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init fail : %s\n", SDL_GetError()); return 1; } diff --git a/test/testerror.c b/test/testerror.c index 780369b8d3..ba372be97c 100644 --- a/test/testerror.c +++ b/test/testerror.c @@ -85,7 +85,7 @@ int main(int argc, char *argv[]) } /* Load the SDL library */ - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/test/testffmpeg.c b/test/testffmpeg.c index 953be47df1..15fff8fc8e 100644 --- a/test/testffmpeg.c +++ b/test/testffmpeg.c @@ -623,7 +623,7 @@ static SDL_bool GetTextureForMemoryFrame(AVFrame *frame, SDL_Texture **texture) if (sws_container->context) { uint8_t *pixels[4]; int pitch[4]; - if (SDL_LockTexture(*texture, NULL, (void **)&pixels[0], &pitch[0]) == 0) { + if (SDL_LockTexture(*texture, NULL, (void **)&pixels[0], &pitch[0])) { sws_scale(sws_container->context, (const uint8_t *const *)frame->data, frame->linesize, 0, frame->height, pixels, pitch); SDL_UnlockTexture(*texture); } @@ -1166,7 +1166,7 @@ static AVCodecContext *OpenAudioStream(AVFormatContext *ic, int stream, const AV SDL_AudioSpec spec = { SDL_AUDIO_F32, codecpar->ch_layout.nb_channels, codecpar->sample_rate }; audio = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL); if (audio) { - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(audio)); + SDL_ResumeAudioStreamDevice(audio); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s", SDL_GetError()); } @@ -1366,7 +1366,7 @@ int main(int argc, char *argv[]) goto quit; } - if (SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_AUDIO | SDL_INIT_VIDEO)) { return_code = 2; goto quit; } @@ -1403,7 +1403,7 @@ int main(int argc, char *argv[]) } } - if (SDL_SetWindowTitle(window, file) < 0) { + if (!SDL_SetWindowTitle(window, file)) { SDL_Log("SDL_SetWindowTitle: %s", SDL_GetError()); } diff --git a/test/testffmpeg_vulkan.c b/test/testffmpeg_vulkan.c index 3085733ce0..268e82c599 100644 --- a/test/testffmpeg_vulkan.c +++ b/test/testffmpeg_vulkan.c @@ -253,7 +253,7 @@ static int createInstance(VulkanVideoContext *context) static int createSurface(VulkanVideoContext *context, SDL_Window *window) { - if (SDL_Vulkan_CreateSurface(window, context->instance, NULL, &context->surface) < 0) { + if (!SDL_Vulkan_CreateSurface(window, context->instance, NULL, &context->surface)) { context->surface = VK_NULL_HANDLE; return -1; } diff --git a/test/testfilesystem.c b/test/testfilesystem.c index dbb16809c3..1ae548e5a4 100644 --- a/test/testfilesystem.c +++ b/test/testfilesystem.c @@ -32,7 +32,7 @@ static int SDLCALL enum_callback(void *userdata, const char *origdir, const char return -1; } - if (SDL_GetPathInfo(fullpath, &info) < 0) { + if (!SDL_GetPathInfo(fullpath, &info)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't stat '%s': %s", fullpath, SDL_GetError()); } else { const char *type; @@ -47,7 +47,7 @@ static int SDLCALL enum_callback(void *userdata, const char *origdir, const char fullpath, type, info.size, info.modify_time, info.create_time, info.access_time); if (info.type == SDL_PATHTYPE_DIRECTORY) { - if (SDL_EnumerateDirectory(fullpath, enum_callback, userdata) < 0) { + if (!SDL_EnumerateDirectory(fullpath, enum_callback, userdata)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Enumeration failed!"); } } @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) return 1; } - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError()); return 1; } @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) SDL_IOStream *stream; const char *text = "foo\n"; - if (SDL_EnumerateDirectory(base_path, enum_callback, NULL) < 0) { + if (!SDL_EnumerateDirectory(base_path, enum_callback, NULL)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Base path enumeration failed!"); } @@ -130,19 +130,19 @@ int main(int argc, char *argv[]) } /* !!! FIXME: put this in a subroutine and make it test more thoroughly (and put it in testautomation). */ - if (SDL_CreateDirectory("testfilesystem-test") < 0) { + if (!SDL_CreateDirectory("testfilesystem-test")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateDirectory('testfilesystem-test') failed: %s", SDL_GetError()); - } else if (SDL_CreateDirectory("testfilesystem-test/1") < 0) { + } else if (!SDL_CreateDirectory("testfilesystem-test/1")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateDirectory('testfilesystem-test/1') failed: %s", SDL_GetError()); - } else if (SDL_CreateDirectory("testfilesystem-test/1") < 0) { /* THIS SHOULD NOT FAIL! Making a directory that already exists should succeed here. */ + } else if (!SDL_CreateDirectory("testfilesystem-test/1")) { /* THIS SHOULD NOT FAIL! Making a directory that already exists should succeed here. */ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CreateDirectory('testfilesystem-test/1') failed: %s", SDL_GetError()); - } else if (SDL_RenamePath("testfilesystem-test/1", "testfilesystem-test/2") < 0) { + } else if (!SDL_RenamePath("testfilesystem-test/1", "testfilesystem-test/2")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RenamePath('testfilesystem-test/1', 'testfilesystem-test/2') failed: %s", SDL_GetError()); - } else if (SDL_RemovePath("testfilesystem-test/2") < 0) { + } else if (!SDL_RemovePath("testfilesystem-test/2")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-test/2') failed: %s", SDL_GetError()); - } else if (SDL_RemovePath("testfilesystem-test") < 0) { + } else if (!SDL_RemovePath("testfilesystem-test")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-test') failed: %s", SDL_GetError()); - } else if (SDL_RemovePath("testfilesystem-test") < 0) { /* THIS SHOULD NOT FAIL! Removing a directory that is already gone should succeed here. */ + } else if (!SDL_RemovePath("testfilesystem-test")) { /* THIS SHOULD NOT FAIL! Removing a directory that is already gone should succeed here. */ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-test') failed: %s", SDL_GetError()); } @@ -151,9 +151,9 @@ int main(int argc, char *argv[]) SDL_WriteIO(stream, text, SDL_strlen(text)); SDL_CloseIO(stream); - if (SDL_RenamePath("testfilesystem-A", "testfilesystem-B") < 0) { + if (!SDL_RenamePath("testfilesystem-A", "testfilesystem-B")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RenamePath('testfilesystem-A', 'testfilesystem-B') failed: %s", SDL_GetError()); - } else if (SDL_CopyFile("testfilesystem-B", "testfilesystem-A") < 0) { + } else if (!SDL_CopyFile("testfilesystem-B", "testfilesystem-A")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_CopyFile('testfilesystem-B', 'testfilesystem-A') failed: %s", SDL_GetError()); } else { size_t sizeA, sizeB; @@ -172,10 +172,10 @@ int main(int argc, char *argv[]) SDL_free(textB); } - if (SDL_RemovePath("testfilesystem-A") < 0) { + if (!SDL_RemovePath("testfilesystem-A")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-A') failed: %s", SDL_GetError()); } - if (SDL_RemovePath("testfilesystem-B") < 0) { + if (!SDL_RemovePath("testfilesystem-B")) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_RemovePath('testfilesystem-B') failed: %s", SDL_GetError()); } } else { diff --git a/test/testgeometry.c b/test/testgeometry.c index cd2083ef32..9de8a48aea 100644 --- a/test/testgeometry.c +++ b/test/testgeometry.c @@ -56,7 +56,7 @@ static int LoadSprite(const char *file) if (!sprites[i]) { return -1; } - if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) { + if (!SDL_SetTextureBlendMode(sprites[i], blendMode)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError()); SDL_DestroyTexture(sprites[i]); return -1; diff --git a/test/testgl.c b/test/testgl.c index cbf44ae02a..686f4edc43 100644 --- a/test/testgl.c +++ b/test/testgl.c @@ -202,11 +202,10 @@ static void Render(void) static void LogSwapInterval(void) { int interval = 0; - const int ret_interval = SDL_GL_GetSwapInterval(&interval); - if (ret_interval < 0) { - SDL_Log("Swap Interval : %d error: %s\n", interval, SDL_GetError()); - } else { + if (SDL_GL_GetSwapInterval(&interval)) { SDL_Log("Swap Interval : %d\n", interval); + } else { + SDL_Log("Swap Interval : %d error: %s\n", interval, SDL_GetError()); } } @@ -219,7 +218,6 @@ int main(int argc, char *argv[]) SDL_Event event; Uint64 then, now; Uint32 frames; - int status; int dw, dh; int swap_interval = 0; @@ -316,40 +314,34 @@ int main(int argc, char *argv[]) SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS)); SDL_Log("\n"); - status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value)) { SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value)) { SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value)) { SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value)) { SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); } if (fsaa) { - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value)) { SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value)) { SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } else { @@ -358,8 +350,7 @@ int main(int argc, char *argv[]) } } if (accel >= 0) { - status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value)) { SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested %d, got %d\n", accel, value); } else { diff --git a/test/testgles.c b/test/testgles.c index a69bde8c2f..c3902630e3 100644 --- a/test/testgles.c +++ b/test/testgles.c @@ -104,7 +104,6 @@ int main(int argc, char *argv[]) const SDL_DisplayMode *mode; SDL_Event event; Uint32 then, now, frames; - int status; /* Initialize parameters */ fsaa = 0; @@ -203,44 +202,38 @@ int main(int argc, char *argv[]) SDL_Log("Extensions : %s\n", glGetString(GL_EXTENSIONS)); SDL_Log("\n"); - status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value)) { SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value)) { SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value)) { SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value)) { SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); } if (fsaa) { - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value)) { SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value)) { SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } else { @@ -249,8 +242,7 @@ int main(int argc, char *argv[]) } } if (accel) { - status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value)) { SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); } else { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", @@ -262,8 +254,7 @@ int main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { float aspectAdjust; - status = SDL_GL_MakeCurrent(state->windows[i], context[i]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[i], context[i])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ @@ -293,8 +284,7 @@ int main(int argc, char *argv[]) if (event.type == SDL_EVENT_WINDOW_RESIZED) { for (i = 0; i < state->num_windows; ++i) { if (event.window.windowID == SDL_GetWindowID(state->windows[i])) { - status = SDL_GL_MakeCurrent(state->windows[i], context[i]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[i], context[i])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); break; } @@ -313,8 +303,7 @@ int main(int argc, char *argv[]) if (state->windows[i] == NULL) { continue; } - status = SDL_GL_MakeCurrent(state->windows[i], context[i]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[i], context[i])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ diff --git a/test/testgles2.c b/test/testgles2.c index 6426dc9074..865fc3a05f 100644 --- a/test/testgles2.c +++ b/test/testgles2.c @@ -544,14 +544,13 @@ static thread_data *threads; static void render_window(int index) { - int w, h, status; + int w, h; if (!state->windows[index]) { return; } - status = SDL_GL_MakeCurrent(state->windows[index], context[index]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[index], context[index])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); return; } @@ -673,7 +672,6 @@ int main(int argc, char *argv[]) int i; const SDL_DisplayMode *mode; Uint64 then, now; - int status; shader_data *data; /* Initialize parameters */ @@ -786,44 +784,38 @@ int main(int argc, char *argv[]) SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS)); SDL_Log("\n"); - status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value)) { SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); } else { SDL_Log("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value)) { SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); } else { SDL_Log("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value)) { SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); } else { SDL_Log("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value)) { SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value); } else { SDL_Log("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); } if (fsaa) { - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value)) { SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); } else { SDL_Log("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value)) { SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } else { @@ -832,8 +824,7 @@ int main(int argc, char *argv[]) } } if (accel) { - status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value)) { SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); } else { SDL_Log("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", @@ -847,8 +838,7 @@ int main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { int w, h; - status = SDL_GL_MakeCurrent(state->windows[i], context[i]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[i], context[i])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ diff --git a/test/testgles2_sdf.c b/test/testgles2_sdf.c index da8935b591..09e2b6c40a 100644 --- a/test/testgles2_sdf.c +++ b/test/testgles2_sdf.c @@ -329,7 +329,6 @@ static void loop(void) { SDL_Event event; int i; - int status; /* Check for events */ ++frames; @@ -363,8 +362,7 @@ static void loop(void) for (i = 0; i < state->num_windows; ++i) { if (event.window.windowID == SDL_GetWindowID(state->windows[i])) { int w, h; - status = SDL_GL_MakeCurrent(state->windows[i], context[i]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[i], context[i])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); break; } @@ -415,8 +413,7 @@ static void loop(void) if (!done) { for (i = 0; i < state->num_windows; ++i) { - status = SDL_GL_MakeCurrent(state->windows[i], context[i]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[i], context[i])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ @@ -440,7 +437,6 @@ int main(int argc, char *argv[]) int i; const SDL_DisplayMode *mode; Uint64 then, now; - int status; shader_data *data; char *path = NULL; @@ -618,44 +614,38 @@ int main(int argc, char *argv[]) SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS)); SDL_Log("\n"); - status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value)) { SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); } else { SDL_Log("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value)) { SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); } else { SDL_Log("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value)) { SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); } else { SDL_Log("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value)) { SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value); } else { SDL_Log("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); } if (fsaa) { - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value)) { SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); } else { SDL_Log("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); } - status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value)) { SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); } else { @@ -664,8 +654,7 @@ int main(int argc, char *argv[]) } } if (accel) { - status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); - if (!status) { + if (SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value)) { SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); } else { SDL_Log("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", @@ -679,8 +668,7 @@ int main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { int w, h; - status = SDL_GL_MakeCurrent(state->windows[i], context[i]); - if (status) { + if (!SDL_GL_MakeCurrent(state->windows[i], context[i])) { SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); /* Continue for next window */ diff --git a/test/testhaptic.c b/test/testhaptic.c index 0406a871a8..889d4264b3 100644 --- a/test/testhaptic.c +++ b/test/testhaptic.c @@ -81,8 +81,7 @@ int main(int argc, char **argv) } /* Initialize the force feedbackness */ - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | - SDL_INIT_HAPTIC); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC); haptics = SDL_GetHaptics(&num_haptics); SDL_Log("%d Haptic devices detected.\n", num_haptics); for (i = 0; i < num_haptics; ++i) { diff --git a/test/testhittesting.c b/test/testhittesting.c index 739dcd7495..098931f339 100644 --- a/test/testhittesting.c +++ b/test/testhittesting.c @@ -99,7 +99,7 @@ int main(int argc, char **argv) } for (i = 0; i < state->num_windows; i++) { - if (SDL_SetWindowHitTest(state->windows[i], hitTest, NULL) < 0) { + if (!SDL_SetWindowHitTest(state->windows[i], hitTest, NULL)) { SDL_Log("Enabling hit-testing failed for window %d: %s", i, SDL_GetError()); SDL_Quit(); return 1; diff --git a/test/testhotplug.c b/test/testhotplug.c index 2333bd3000..5dc5665a6b 100644 --- a/test/testhotplug.c +++ b/test/testhotplug.c @@ -71,7 +71,7 @@ int main(int argc, char *argv[]) SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1"); /* Initialize SDL (Note: video is required to start event loop) */ - if (SDL_Init(init_subsystems) < 0) { + if (!SDL_Init(init_subsystems)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } @@ -126,7 +126,7 @@ int main(int argc, char *argv[]) haptic = SDL_OpenHapticFromJoystick(joystick); if (haptic) { SDL_Log("Joy Haptic Opened\n"); - if (SDL_InitHapticRumble(haptic) < 0) { + if (!SDL_InitHapticRumble(haptic)) { SDL_Log("Could not init Rumble!: %s\n", SDL_GetError()); SDL_CloseHaptic(haptic); haptic = NULL; diff --git a/test/testiconv.c b/test/testiconv.c index e631f8bb5d..09f7886518 100644 --- a/test/testiconv.c +++ b/test/testiconv.c @@ -28,7 +28,7 @@ widelen(char *data) static char *get_next_line(Uint8 **fdataptr, size_t *fdatalen) { - char *retval = (char *) *fdataptr; + char *result = (char *) *fdataptr; Uint8 *ptr = *fdataptr; size_t len = *fdatalen; @@ -51,7 +51,7 @@ static char *get_next_line(Uint8 **fdataptr, size_t *fdatalen) *fdataptr = ptr; *fdatalen = len; - return retval; + return result; } int main(int argc, char *argv[]) diff --git a/test/testime.c b/test/testime.c index a688b4d6d3..9176cb40be 100644 --- a/test/testime.c +++ b/test/testime.c @@ -361,14 +361,14 @@ static int unifont_load_texture(Uint32 textureID) } unifontTexture[UNIFONT_NUM_TEXTURES * i + textureID] = tex; SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_BLEND); - if (SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH) < 0) { + if (!SDL_UpdateTexture(tex, NULL, textureRGBA, UNIFONT_TEXTURE_PITCH)) { SDL_Log("unifont error: Failed to update texture %" SDL_PRIu32 " data for renderer %d.\n", textureID, i); } } SDL_free(textureRGBA); unifontTextureLoaded[textureID] = 1; - return 0; + return -1; } static int unifont_glyph_width(Uint32 codepoint) diff --git a/test/testkeys.c b/test/testkeys.c index cfc8a96d17..f8a006b12e 100644 --- a/test/testkeys.c +++ b/test/testkeys.c @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) return 1; } - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } diff --git a/test/testloadso.c b/test/testloadso.c index ca89691c9f..3a5a5280cd 100644 --- a/test/testloadso.c +++ b/test/testloadso.c @@ -31,7 +31,7 @@ static void log_usage(char *progname, SDLTest_CommonState *state) { int main(int argc, char *argv[]) { int i; - int retval = 0; + int result = 0; int hello = 0; const char *libname = NULL; const char *symname = NULL; @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) } /* Initialize SDL */ - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 2; } @@ -91,13 +91,13 @@ int main(int argc, char *argv[]) if (!lib) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadObject('%s') failed: %s\n", libname, SDL_GetError()); - retval = 3; + result = 3; } else { fn = (fntype)SDL_LoadFunction(lib, symname); if (!fn) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_LoadFunction('%s') failed: %s\n", symname, SDL_GetError()); - retval = 4; + result = 4; } else { SDL_Log("Found %s in %s at %p\n", symname, libname, fn); if (hello) { @@ -111,5 +111,5 @@ int main(int argc, char *argv[]) } SDL_Quit(); SDLTest_CommonDestroyState(state); - return retval; + return result; } diff --git a/test/testlock.c b/test/testlock.c index f645802b4a..bee8781f02 100644 --- a/test/testlock.c +++ b/test/testlock.c @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) threads = SDL_malloc(nb_threads * sizeof(SDL_Thread*)); /* Load the SDL library */ - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError()); exit(1); } diff --git a/test/testmessage.c b/test/testmessage.c index 6bd4254e0b..138a24dcab 100644 --- a/test/testmessage.c +++ b/test/testmessage.c @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) "Simple MessageBox", "This is a simple error MessageBox", NULL); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -114,7 +114,7 @@ int main(int argc, char *argv[]) "Simple MessageBox", "This is a simple MessageBox with a newline:\r\nHello world!", NULL); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -123,7 +123,7 @@ int main(int argc, char *argv[]) NULL, "NULL Title", NULL); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -132,7 +132,7 @@ int main(int argc, char *argv[]) "NULL Message", NULL, NULL); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -142,7 +142,7 @@ int main(int argc, char *argv[]) "UTF-8 Simple MessageBox", "Unicode text: '牛肉西蘭花' ...", NULL); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) "UTF-8 Simple MessageBox", "Unicode text and newline:\r\n'牛肉西蘭花'\n'牛肉西蘭花'", NULL); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -162,7 +162,7 @@ int main(int argc, char *argv[]) "牛肉西蘭花", "Unicode text in the title.", NULL); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } @@ -175,7 +175,7 @@ int main(int argc, char *argv[]) to work, since the message box events are dispatched by the Cocoa subsystem on the main thread. */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video subsystem: %s\n", SDL_GetError()); return 1; } @@ -211,7 +211,7 @@ int main(int argc, char *argv[]) "Simple MessageBox", "This is a simple error MessageBox with a parent window. Press a key or close the window after dismissing this messagebox.", window); - if (success == -1) { + if (!success) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError()); quit(1); } diff --git a/test/testmodal.c b/test/testmodal.c index f4e2fc4bbe..608d9176e0 100644 --- a/test/testmodal.c +++ b/test/testmodal.c @@ -49,19 +49,18 @@ int main(int argc, char *argv[]) i += consumed; } - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_Log("SDL_Init failed (%s)", SDL_GetError()); return 1; } - if (SDL_CreateWindowAndRenderer("Parent Window", 640, 480, 0, &w1, &r1)) { + if (!SDL_CreateWindowAndRenderer("Parent Window", 640, 480, 0, &w1, &r1)) { SDL_Log("Failed to create parent window and/or renderer: %s\n", SDL_GetError()); exit_code = 1; goto sdl_quit; } - SDL_CreateWindowAndRenderer("Non-Modal Window", 320, 200, 0, &w2, &r2); - if (!w2) { + if (!SDL_CreateWindowAndRenderer("Non-Modal Window", 320, 200, 0, &w2, &r2)) { SDL_Log("Failed to create parent window and/or renderer: %s\n", SDL_GetError()); exit_code = 1; goto sdl_quit; @@ -92,7 +91,7 @@ int main(int argc, char *argv[]) } } else if (e.type == SDL_EVENT_KEY_DOWN) { if ((e.key.key == SDLK_M || e.key.key == SDLK_N) && !w2) { - if (SDL_CreateWindowAndRenderer("Non-Modal Window", 320, 200, SDL_WINDOW_HIDDEN, &w2, &r2) < 0) { + if (!SDL_CreateWindowAndRenderer("Non-Modal Window", 320, 200, SDL_WINDOW_HIDDEN, &w2, &r2)) { SDL_Log("Failed to create modal window and/or renderer: %s\n", SDL_GetError()); exit_code = 1; goto sdl_quit; diff --git a/test/testmouse.c b/test/testmouse.c index b26e7bad9a..67b3de71a6 100644 --- a/test/testmouse.c +++ b/test/testmouse.c @@ -297,7 +297,7 @@ int main(int argc, char *argv[]) } /* Initialize SDL (Note: video is required to start event loop) */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } diff --git a/test/testmultiaudio.c b/test/testmultiaudio.c index da44212a18..2b60b6c9e7 100644 --- a/test/testmultiaudio.c +++ b/test/testmultiaudio.c @@ -64,7 +64,7 @@ test_multi_audio(const SDL_AudioDeviceID *devices, int devcount) if ((stream = SDL_OpenAudioDeviceStream(devices[i], &spec, NULL, NULL)) == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Audio stream creation failed: %s", SDL_GetError()); } else { - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); + SDL_ResumeAudioStreamDevice(stream); SDL_PutAudioStreamData(stream, sound, soundlen); SDL_FlushAudioStream(stream); #ifdef SDL_PLATFORM_EMSCRIPTEN @@ -104,7 +104,7 @@ test_multi_audio(const SDL_AudioDeviceID *devices, int devcount) /* try to start all the devices about the same time. SDL does not guarantee sync across physical devices. */ for (i = 0; i < devcount; i++) { if (streams[i]) { - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(streams[i])); + SDL_ResumeAudioStreamDevice(streams[i]); } } @@ -171,7 +171,7 @@ int main(int argc, char **argv) } /* Load the SDL library */ - if (SDL_Init(SDL_INIT_AUDIO) < 0) { + if (!SDL_Init(SDL_INIT_AUDIO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } @@ -185,12 +185,12 @@ int main(int argc, char **argv) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio playback devices!"); } else { /* Load the wave file into memory */ - if (SDL_LoadWAV(filename, &spec, &sound, &soundlen) < 0) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, - SDL_GetError()); - } else { + if (SDL_LoadWAV(filename, &spec, &sound, &soundlen)) { test_multi_audio(devices, devcount); SDL_free(sound); + } else { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", filename, + SDL_GetError()); } SDL_free(devices); } diff --git a/test/testnative.c b/test/testnative.c index 449bff3748..8e8db6a4cf 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) return 1; } - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL video: %s\n", SDL_GetError()); exit(1); diff --git a/test/testoffscreen.c b/test/testoffscreen.c index 8b03228fca..9943ace8ab 100644 --- a/test/testoffscreen.c +++ b/test/testoffscreen.c @@ -110,7 +110,7 @@ int main(int argc, char *argv[]) /* Force the offscreen renderer, if it cannot be created then fail out */ SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "offscreen"); - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + if (!SDL_InitSubSystem(SDL_INIT_VIDEO)) { SDL_Log("Couldn't initialize the offscreen video driver: %s\n", SDL_GetError()); return SDL_FALSE; diff --git a/test/testpower.c b/test/testpower.c index 2dcf33f556..190e3ae889 100644 --- a/test/testpower.c +++ b/test/testpower.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) return 1; } - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError()); return 1; } diff --git a/test/testrendertarget.c b/test/testrendertarget.c index 2c4b6dc0ca..74b742c10f 100644 --- a/test/testrendertarget.c +++ b/test/testrendertarget.c @@ -78,7 +78,7 @@ DrawComposite(DrawState *s) surface = SDL_RenderReadPixels(s->renderer, NULL); if (surface) { Uint8 r, g, b, a; - if (SDL_ReadSurfacePixel(surface, 0, 0, &r, &g, &b, &a) == 0) { + if (SDL_ReadSurfacePixel(surface, 0, 0, &r, &g, &b, &a)) { SDL_Log("Blended pixel: 0x%.2x%.2x%.2x%.2x\n", r, g, b, a); } SDL_DestroySurface(surface); diff --git a/test/testresample.c b/test/testresample.c index 687e5fbd64..0d1c5dcf83 100644 --- a/test/testresample.c +++ b/test/testresample.c @@ -95,20 +95,20 @@ int main(int argc, char **argv) goto end; } - if (SDL_Init(SDL_INIT_AUDIO) < 0) { + if (!SDL_Init(SDL_INIT_AUDIO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Init() failed: %s\n", SDL_GetError()); ret = 2; goto end; } - if (SDL_LoadWAV(file_in, &spec, &data, &len) < 0) { + if (!SDL_LoadWAV(file_in, &spec, &data, &len)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to load %s: %s\n", file_in, SDL_GetError()); ret = 3; goto end; } cvtspec.format = spec.format; - if (SDL_ConvertAudioSamples(&spec, data, len, &cvtspec, &dst_buf, &dst_len) < 0) { + if (!SDL_ConvertAudioSamples(&spec, data, len, &cvtspec, &dst_buf, &dst_len)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "failed to convert samples: %s\n", SDL_GetError()); ret = 4; goto end; @@ -141,7 +141,7 @@ int main(int argc, char **argv) SDL_WriteU32LE(io, dst_len); /* size */ SDL_WriteIO(io, dst_buf, dst_len); - if (SDL_CloseIO(io) < 0) { + if (!SDL_CloseIO(io)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "closing '%s' failed: %s\n", file_out, SDL_GetError()); ret = 6; goto end; diff --git a/test/testrumble.c b/test/testrumble.c index ba1201ce36..e46c73ca8c 100644 --- a/test/testrumble.c +++ b/test/testrumble.c @@ -85,8 +85,7 @@ int main(int argc, char **argv) } /* Initialize the force feedbackness */ - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | - SDL_INIT_HAPTIC); + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC); haptics = SDL_GetHaptics(&num_haptics); SDL_Log("%d Haptic devices detected.\n", num_haptics); if (num_haptics == 0) { @@ -132,16 +131,16 @@ int main(int argc, char **argv) /* We only want force feedback errors. */ SDL_ClearError(); - if (SDL_HapticRumbleSupported(haptic) == SDL_FALSE) { + if (!SDL_HapticRumbleSupported(haptic)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Rumble not supported!\n"); return 1; } - if (SDL_InitHapticRumble(haptic) < 0) { + if (!SDL_InitHapticRumble(haptic)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to initialize rumble: %s\n", SDL_GetError()); return 1; } SDL_Log("Playing 2 second rumble at 0.5 magnitude.\n"); - if (SDL_PlayHapticRumble(haptic, 0.5, 5000) < 0) { + if (!SDL_PlayHapticRumble(haptic, 0.5, 5000)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError()); return 1; } @@ -150,7 +149,7 @@ int main(int argc, char **argv) SDL_StopHapticRumble(haptic); SDL_Delay(2000); SDL_Log("Playing 2 second rumble at 0.3 magnitude.\n"); - if (SDL_PlayHapticRumble(haptic, 0.3f, 5000) < 0) { + if (!SDL_PlayHapticRumble(haptic, 0.3f, 5000)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to play rumble: %s\n", SDL_GetError()); return 1; } diff --git a/test/testrwlock.c b/test/testrwlock.c index 328aa6886d..762693ab04 100644 --- a/test/testrwlock.c +++ b/test/testrwlock.c @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) threads = SDL_malloc(nb_threads * sizeof(SDL_Thread*)); /* Load the SDL library */ - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError()); return 1; } diff --git a/test/testsem.c b/test/testsem.c index 359c532a3e..30485dc8ac 100644 --- a/test/testsem.c +++ b/test/testsem.c @@ -108,13 +108,13 @@ TestWaitTimeout(void) Uint64 start_ticks; Uint64 end_ticks; Uint64 duration; - int retval; + SDL_bool result; sem = SDL_CreateSemaphore(0); SDL_Log("Waiting 2 seconds on semaphore\n"); start_ticks = SDL_GetTicks(); - retval = SDL_WaitSemaphoreTimeout(sem, 2000); + result = SDL_WaitSemaphoreTimeout(sem, 2000); end_ticks = SDL_GetTicks(); duration = end_ticks - start_ticks; @@ -124,8 +124,8 @@ TestWaitTimeout(void) SDL_assert(duration > 1900 && duration < 2050); /* Check to make sure the return value indicates timed out */ - if (retval != SDL_MUTEX_TIMEDOUT) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_WaitSemaphoreTimeout returned: %d; expected: %d\n\n", retval, SDL_MUTEX_TIMEDOUT); + if (result) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_WaitSemaphoreTimeout returned: %d; expected: SDL_FALSE\n\n", result); } SDL_DestroySemaphore(sem); @@ -166,7 +166,7 @@ ThreadFuncOverheadContended(void *data) if (state->flag) { while (alive) { - if (SDL_TryWaitSemaphore(sem) == SDL_MUTEX_TIMEDOUT) { + if (!SDL_TryWaitSemaphore(sem)) { ++state->content_count; } ++state->loop_count; @@ -174,7 +174,7 @@ ThreadFuncOverheadContended(void *data) } else { while (alive) { /* Timeout needed to allow check on alive flag */ - if (SDL_WaitSemaphoreTimeout(sem, 50) == SDL_MUTEX_TIMEDOUT) { + if (!SDL_WaitSemaphoreTimeout(sem, 50)) { ++state->content_count; } ++state->loop_count; @@ -302,7 +302,7 @@ int main(int argc, char **argv) } /* Load the SDL library */ - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/test/testsensor.c b/test/testsensor.c index 1e35fba65c..57566f4f8a 100644 --- a/test/testsensor.c +++ b/test/testsensor.c @@ -78,7 +78,7 @@ int main(int argc, char **argv) } /* Load the SDL library */ - if (SDL_Init(SDL_INIT_SENSOR) < 0) { + if (!SDL_Init(SDL_INIT_SENSOR)) { SDL_Log("Couldn't initialize SDL: %s\n", SDL_GetError()); SDL_Quit(); SDLTest_CommonDestroyState(state); diff --git a/test/testshader.c b/test/testshader.c index aa299077ab..71df993bb8 100644 --- a/test/testshader.c +++ b/test/testshader.c @@ -482,7 +482,7 @@ int main(int argc, char **argv) } /* Initialize SDL for video output */ - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize SDL: %s\n", SDL_GetError()); exit(1); } diff --git a/test/testshape.c b/test/testshape.c index c80d1f0173..c55b2c9ef2 100644 --- a/test/testshape.c +++ b/test/testshape.c @@ -20,7 +20,7 @@ static SDL_HitTestResult SDLCALL ShapeHitTest(SDL_Window *window, const SDL_Poin SDL_Surface *shape = (SDL_Surface *)userdata; Uint8 r, g, b, a; - if (SDL_ReadSurfacePixel(shape, area->x, area->y, &r, &g, &b, &a) == 0) { + if (SDL_ReadSurfacePixel(shape, area->x, area->y, &r, &g, &b, &a)) { if (a != SDL_ALPHA_TRANSPARENT) { /* We'll just make everything draggable */ return SDL_HITTEST_DRAGGABLE; @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) if (!resizable) { /* Set the hit test callback so we can drag the window */ - if (SDL_SetWindowHitTest(window, ShapeHitTest, shape) < 0) { + if (!SDL_SetWindowHitTest(window, ShapeHitTest, shape)) { SDL_Log("Couldn't set hit test callback: %s\n", SDL_GetError()); goto quit; } diff --git a/test/testsprite.c b/test/testsprite.c index 0d1c348286..1af2dc2e7a 100644 --- a/test/testsprite.c +++ b/test/testsprite.c @@ -62,7 +62,7 @@ static int LoadSprite(const char *file) if (!sprites[i]) { return -1; } - if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) { + if (!SDL_SetTextureBlendMode(sprites[i], blendMode)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError()); SDL_DestroyTexture(sprites[i]); return -1; diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c index 4e7de36b88..16a41a4c4f 100644 --- a/test/testspriteminimal.c +++ b/test/testspriteminimal.c @@ -120,7 +120,7 @@ int main(int argc, char *argv[]) goto quit; } - if (SDL_CreateWindowAndRenderer("testspriteminimal", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) { + if (!SDL_CreateWindowAndRenderer("testspriteminimal", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) { return_code = 2; goto quit; } diff --git a/test/teststreaming.c b/test/teststreaming.c index 148ca04cd5..8cc7b4ecfc 100644 --- a/test/teststreaming.c +++ b/test/teststreaming.c @@ -85,7 +85,7 @@ static void UpdateTexture(SDL_Texture *texture) void *pixels; int pitch; - if (SDL_LockTexture(texture, NULL, &pixels, &pitch) < 0) { + if (!SDL_LockTexture(texture, NULL, &pixels, &pitch)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError()); quit(5); } @@ -154,7 +154,7 @@ int main(int argc, char **argv) return 1; } - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/test/testsurround.c b/test/testsurround.c index be1911fe7e..d0d8ff8a87 100644 --- a/test/testsurround.c +++ b/test/testsurround.c @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) return 1; } - if (SDL_Init(SDL_INIT_AUDIO) < 0) { + if (!SDL_Init(SDL_INIT_AUDIO)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } @@ -196,7 +196,7 @@ int main(int argc, char *argv[]) SDL_Log("Testing audio device: %s\n", devname); - if (SDL_GetAudioDeviceFormat(devices[i], &spec, NULL) < 0) { + if (!SDL_GetAudioDeviceFormat(devices[i], &spec, NULL)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioDeviceFormat() failed: %s\n", SDL_GetError()); continue; } @@ -215,7 +215,7 @@ int main(int argc, char *argv[]) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_OpenAudioDeviceStream() failed: %s\n", SDL_GetError()); continue; } - SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(stream)); + SDL_ResumeAudioStreamDevice(stream); for (j = 0; j < total_channels; j++) { const int sine_freq = is_lfe_channel(j, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ; diff --git a/test/testthread.c b/test/testthread.c index 4dd8d9c223..06b0871253 100644 --- a/test/testthread.c +++ b/test/testthread.c @@ -122,7 +122,7 @@ int main(int argc, char *argv[]) } /* Load the SDL library */ - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/test/testtimer.c b/test/testtimer.c index ab797c2f5a..3b9473cdf6 100644 --- a/test/testtimer.c +++ b/test/testtimer.c @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) i += consumed; } - if (SDL_Init(SDL_INIT_TIMER) < 0) { + if (!SDL_Init(SDL_INIT_TIMER)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } diff --git a/test/testurl.c b/test/testurl.c index 7898de38a6..17d6305206 100644 --- a/test/testurl.c +++ b/test/testurl.c @@ -15,7 +15,7 @@ static void tryOpenURL(const char *url) { SDL_Log("Opening '%s' ...", url); - if (SDL_OpenURL(url) == 0) { + if (SDL_OpenURL(url)) { SDL_Log(" success!"); } else { SDL_Log(" failed! %s", SDL_GetError()); @@ -25,7 +25,7 @@ static void tryOpenURL(const char *url) int main(int argc, char **argv) { int i; - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_Log("SDL_Init failed: %s\n", SDL_GetError()); return 1; } diff --git a/test/testvulkan.c b/test/testvulkan.c index 4b07a58711..3f0afb59b4 100644 --- a/test/testvulkan.c +++ b/test/testvulkan.c @@ -262,7 +262,7 @@ static void loadInstanceFunctions(void) static void createSurface(void) { - if (SDL_Vulkan_CreateSurface(vulkanContext->window, vulkanContext->instance, NULL, &vulkanContext->surface) < 0) { + if (!SDL_Vulkan_CreateSurface(vulkanContext->window, vulkanContext->instance, NULL, &vulkanContext->surface)) { vulkanContext->surface = VK_NULL_HANDLE; SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_Vulkan_CreateSurface(): %s\n", SDL_GetError()); quit(2); @@ -1007,7 +1007,7 @@ static void shutdownVulkan(SDL_bool doDestroySwapchain) static SDL_bool render(void) { uint32_t frameIndex; - VkResult result; + VkResult rc; double currentTime; VkClearColorValue clearColor = { { 0 } }; VkPipelineStageFlags waitDestStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; @@ -1016,36 +1016,36 @@ static SDL_bool render(void) int w, h; if (!vulkanContext->swapchain) { - SDL_bool retval = createNewSwapchainAndSwapchainSpecificStuff(); - if (!retval) { + SDL_bool result = createNewSwapchainAndSwapchainSpecificStuff(); + if (!result) { SDL_Delay(100); } - return retval; + return result; } - result = vkAcquireNextImageKHR(vulkanContext->device, - vulkanContext->swapchain, - UINT64_MAX, - vulkanContext->imageAvailableSemaphore, - VK_NULL_HANDLE, - &frameIndex); - if (result == VK_ERROR_OUT_OF_DATE_KHR) { + rc = vkAcquireNextImageKHR(vulkanContext->device, + vulkanContext->swapchain, + UINT64_MAX, + vulkanContext->imageAvailableSemaphore, + VK_NULL_HANDLE, + &frameIndex); + if (rc == VK_ERROR_OUT_OF_DATE_KHR) { return createNewSwapchainAndSwapchainSpecificStuff(); } - if ((result != VK_SUBOPTIMAL_KHR) && (result != VK_SUCCESS)) { + if ((rc != VK_SUBOPTIMAL_KHR) && (rc != VK_SUCCESS)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkAcquireNextImageKHR(): %s\n", - getVulkanResultString(result)); + getVulkanResultString(rc)); quit(2); } - result = vkWaitForFences(vulkanContext->device, 1, &vulkanContext->fences[frameIndex], VK_FALSE, UINT64_MAX); - if (result != VK_SUCCESS) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkWaitForFences(): %s\n", getVulkanResultString(result)); + rc = vkWaitForFences(vulkanContext->device, 1, &vulkanContext->fences[frameIndex], VK_FALSE, UINT64_MAX); + if (rc != VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkWaitForFences(): %s\n", getVulkanResultString(rc)); quit(2); } - result = vkResetFences(vulkanContext->device, 1, &vulkanContext->fences[frameIndex]); - if (result != VK_SUCCESS) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkResetFences(): %s\n", getVulkanResultString(result)); + rc = vkResetFences(vulkanContext->device, 1, &vulkanContext->fences[frameIndex]); + if (rc != VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkResetFences(): %s\n", getVulkanResultString(rc)); quit(2); } currentTime = (double)SDL_GetPerformanceCounter() / SDL_GetPerformanceFrequency(); @@ -1062,10 +1062,10 @@ static SDL_bool render(void) submitInfo.pCommandBuffers = &vulkanContext->commandBuffers[frameIndex]; submitInfo.signalSemaphoreCount = 1; submitInfo.pSignalSemaphores = &vulkanContext->renderingFinishedSemaphore; - result = vkQueueSubmit(vulkanContext->graphicsQueue, 1, &submitInfo, vulkanContext->fences[frameIndex]); + rc = vkQueueSubmit(vulkanContext->graphicsQueue, 1, &submitInfo, vulkanContext->fences[frameIndex]); - if (result != VK_SUCCESS) { - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkQueueSubmit(): %s\n", getVulkanResultString(result)); + if (rc != VK_SUCCESS) { + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkQueueSubmit(): %s\n", getVulkanResultString(rc)); quit(2); } presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; @@ -1074,15 +1074,15 @@ static SDL_bool render(void) presentInfo.swapchainCount = 1; presentInfo.pSwapchains = &vulkanContext->swapchain; presentInfo.pImageIndices = &frameIndex; - result = vkQueuePresentKHR(vulkanContext->presentQueue, &presentInfo); - if ((result == VK_ERROR_OUT_OF_DATE_KHR) || (result == VK_SUBOPTIMAL_KHR)) { + rc = vkQueuePresentKHR(vulkanContext->presentQueue, &presentInfo); + if ((rc == VK_ERROR_OUT_OF_DATE_KHR) || (rc == VK_SUBOPTIMAL_KHR)) { return createNewSwapchainAndSwapchainSpecificStuff(); } - if (result != VK_SUCCESS) { + if (rc != VK_SUCCESS) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "vkQueuePresentKHR(): %s\n", - getVulkanResultString(result)); + getVulkanResultString(rc)); quit(2); } SDL_GetWindowSizeInPixels(vulkanContext->window, &w, &h); diff --git a/test/testwaylandcustom.c b/test/testwaylandcustom.c index 6e6bd37c7c..22e1bdead2 100644 --- a/test/testwaylandcustom.c +++ b/test/testwaylandcustom.c @@ -194,7 +194,7 @@ int main(int argc, char **argv) int ret = -1; SDL_PropertiesID props; - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) != 0) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { return -1; } diff --git a/test/testyuv.c b/test/testyuv.c index 822d3f157e..30adeb34e2 100644 --- a/test/testyuv.c +++ b/test/testyuv.c @@ -77,7 +77,7 @@ static SDL_bool verify_yuv_data(Uint32 format, SDL_Colorspace colorspace, const return SDL_FALSE; } - if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, format, colorspace, 0, yuv, yuv_pitch, surface->format, SDL_COLORSPACE_SRGB, 0, rgb, surface->pitch) == 0) { + if (SDL_ConvertPixelsAndColorspace(surface->w, surface->h, format, colorspace, 0, yuv, yuv_pitch, surface->format, SDL_COLORSPACE_SRGB, 0, rgb, surface->pitch)) { int x, y; result = SDL_TRUE; for (y = 0; y < surface->h; ++y) { @@ -151,7 +151,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch) /* Verify conversion to YUV formats */ for (i = 0; i < SDL_arraysize(formats); ++i) { yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch; - if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError()); goto done; } @@ -166,11 +166,11 @@ static int run_automated_tests(int pattern_size, int extra_pitch) for (j = 0; j < SDL_arraysize(formats); ++j) { yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch; yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch; - if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError()); goto done; } - if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv2, yuv2_pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv2, yuv2_pitch)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]), SDL_GetError()); goto done; } @@ -191,11 +191,11 @@ static int run_automated_tests(int pattern_size, int extra_pitch) yuv1_pitch = CalculateYUVPitch(formats[i], pattern->w) + extra_pitch; yuv2_pitch = CalculateYUVPitch(formats[j], pattern->w) + extra_pitch; - if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, formats[i], colorspace, 0, yuv1, yuv1_pitch)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(formats[i]), SDL_GetError()); goto done; } - if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv1, yuv2_pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, formats[i], colorspace, 0, yuv1, yuv1_pitch, formats[j], colorspace, 0, yuv1, yuv2_pitch)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(formats[i]), SDL_GetPixelFormatName(formats[j]), SDL_GetError()); goto done; } @@ -220,7 +220,7 @@ static int run_automated_tests(int pattern_size, int extra_pitch) /* The pitch needs to be Uint16 aligned for P010 pixels */ yuv1_pitch = CalculateYUVPitch(SDL_PIXELFORMAT_P010, pattern->w) + ((extra_pitch + 1) & ~1); - if (SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, SDL_PIXELFORMAT_P010, colorspace, 0, yuv1, yuv1_pitch) < 0) { + if (!SDL_ConvertPixelsAndColorspace(pattern->w, pattern->h, pattern->format, SDL_COLORSPACE_SRGB, 0, pattern->pixels, pattern->pitch, SDL_PIXELFORMAT_P010, colorspace, 0, yuv1, yuv1_pitch)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't convert %s to %s: %s\n", SDL_GetPixelFormatName(pattern->format), SDL_GetPixelFormatName(SDL_PIXELFORMAT_P010), SDL_GetError()); goto done; } diff --git a/test/torturethread.c b/test/torturethread.c index c45f89c9c6..2c6e562b0c 100644 --- a/test/torturethread.c +++ b/test/torturethread.c @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ - if (SDL_Init(0) < 0) { + if (!SDL_Init(0)) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; }