2015-06-21 17:33:46 +02:00
|
|
|
/*
|
|
|
|
|
Simple DirectMedia Layer
|
2024-01-01 13:15:26 -08:00
|
|
|
Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
|
arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
|
appreciated but is not required.
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
misrepresented as being the original software.
|
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
|
*/
|
2022-11-29 18:34:15 -08:00
|
|
|
#include "SDL_internal.h"
|
2022-10-20 18:47:17 +02:00
|
|
|
#include "SDL3/SDL_revision.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2022-06-27 17:19:39 +00:00
|
|
|
#if defined(__WIN32__) || defined(__GDK__)
|
2015-06-21 17:33:46 +02:00
|
|
|
#include "core/windows/SDL_windows.h"
|
2022-11-23 10:41:43 -08:00
|
|
|
#elif !defined(__WINRT__)
|
2021-11-20 21:51:10 +03:00
|
|
|
#include <unistd.h> /* _exit(), etc. */
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
2021-04-02 14:35:11 -04:00
|
|
|
/* this checks for HAVE_DBUS_DBUS_H internally. */
|
|
|
|
|
#include "core/linux/SDL_dbus.h"
|
|
|
|
|
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef __EMSCRIPTEN__
|
2019-10-16 13:54:35 -04:00
|
|
|
#include <emscripten.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
/* Initialization code for SDL */
|
|
|
|
|
|
|
|
|
|
#include "SDL_assert_c.h"
|
2022-04-28 15:01:34 -07:00
|
|
|
#include "SDL_log_c.h"
|
2023-10-10 12:38:22 -07:00
|
|
|
#include "SDL_properties_c.h"
|
2023-10-18 15:46:07 -04:00
|
|
|
#include "audio/SDL_sysaudio.h"
|
2022-12-27 14:42:48 +01:00
|
|
|
#include "video/SDL_video_c.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
#include "events/SDL_events_c.h"
|
|
|
|
|
#include "haptic/SDL_haptic_c.h"
|
2022-12-27 10:23:28 -08:00
|
|
|
#include "joystick/SDL_gamepad_c.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
#include "joystick/SDL_joystick_c.h"
|
2018-08-21 12:11:34 -07:00
|
|
|
#include "sensor/SDL_sensor_c.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
/* Initialization/Cleanup routines */
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_TIMERS_DISABLED
|
2022-11-30 12:51:59 -08:00
|
|
|
#include "timer/SDL_timer_c.h"
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_WINDOWS
|
2015-06-21 17:33:46 +02:00
|
|
|
extern int SDL_HelperWindowCreate(void);
|
|
|
|
|
extern int SDL_HelperWindowDestroy(void);
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-05-03 14:39:00 +01:00
|
|
|
#ifdef SDL_BUILD_MAJOR_VERSION
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MAJOR_VERSION,
|
|
|
|
|
SDL_MAJOR_VERSION == SDL_BUILD_MAJOR_VERSION);
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MINOR_VERSION,
|
|
|
|
|
SDL_MINOR_VERSION == SDL_BUILD_MINOR_VERSION);
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MICRO_VERSION,
|
|
|
|
|
SDL_PATCHLEVEL == SDL_BUILD_MICRO_VERSION);
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-05-03 13:17:59 +01:00
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_min, SDL_MAJOR_VERSION >= 0);
|
|
|
|
|
/* Limited only by the need to fit in SDL_version */
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_max, SDL_MAJOR_VERSION <= 255);
|
|
|
|
|
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_min, SDL_MINOR_VERSION >= 0);
|
|
|
|
|
/* Limited only by the need to fit in SDL_version */
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_max, SDL_MINOR_VERSION <= 255);
|
|
|
|
|
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_min, SDL_PATCHLEVEL >= 0);
|
2022-05-04 16:40:11 +01:00
|
|
|
/* Limited by its encoding in SDL_VERSIONNUM and in the ABI versions */
|
2022-05-03 13:17:59 +01:00
|
|
|
SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_max, SDL_PATCHLEVEL <= 99);
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2019-10-14 12:41:06 -04:00
|
|
|
/* This is not declared in any header, although it is shared between some
|
|
|
|
|
parts of SDL, because we don't want anything calling it without an
|
|
|
|
|
extremely good reason. */
|
2019-10-30 15:43:49 +01:00
|
|
|
extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
|
2019-11-20 02:47:40 +03:00
|
|
|
SDL_NORETURN void SDL_ExitProcess(int exitcode)
|
2019-10-14 12:41:06 -04:00
|
|
|
{
|
2022-06-27 17:19:39 +00:00
|
|
|
#if defined(__WIN32__) || defined(__GDK__)
|
2019-10-14 12:41:06 -04:00
|
|
|
/* "if you do not know the state of all threads in your process, it is
|
|
|
|
|
better to call TerminateProcess than ExitProcess"
|
|
|
|
|
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx */
|
|
|
|
|
TerminateProcess(GetCurrentProcess(), exitcode);
|
|
|
|
|
/* MingW doesn't have TerminateProcess marked as noreturn, so add an
|
|
|
|
|
ExitProcess here that will never be reached but make MingW happy. */
|
|
|
|
|
ExitProcess(exitcode);
|
|
|
|
|
#elif defined(__EMSCRIPTEN__)
|
2022-11-30 12:51:59 -08:00
|
|
|
emscripten_cancel_main_loop(); /* this should "kill" the app. */
|
|
|
|
|
emscripten_force_exit(exitcode); /* this should "kill" the app. */
|
2019-10-14 12:41:06 -04:00
|
|
|
exit(exitcode);
|
|
|
|
|
#elif defined(__HAIKU__) /* Haiku has _Exit, but it's not marked noreturn. */
|
|
|
|
|
_exit(exitcode);
|
|
|
|
|
#elif defined(HAVE__EXIT) /* Upper case _Exit() */
|
|
|
|
|
_Exit(exitcode);
|
|
|
|
|
#else
|
|
|
|
|
_exit(exitcode);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
/* The initialized subsystems */
|
|
|
|
|
#ifdef SDL_MAIN_NEEDED
|
|
|
|
|
static SDL_bool SDL_MainIsReady = SDL_FALSE;
|
|
|
|
|
#else
|
|
|
|
|
static SDL_bool SDL_MainIsReady = SDL_TRUE;
|
|
|
|
|
#endif
|
|
|
|
|
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
|
2022-11-30 12:51:59 -08:00
|
|
|
static Uint8 SDL_SubsystemRefCount[32];
|
2015-06-21 17:33:46 +02:00
|
|
|
|
|
|
|
|
/* Private helper to increment a subsystem's ref counter. */
|
2022-12-27 15:05:51 -08:00
|
|
|
static void SDL_IncrementSubsystemRefCount(Uint32 subsystem)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2022-11-16 12:53:48 -05:00
|
|
|
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
|
|
|
|
|
SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
|
|
|
|
|
if (subsystem_index >= 0) {
|
Fixes made in response to running a static code analyzer under MS Windows.
Most of these are probably harmless, but the changes to SDL_immdevice.c and SDL_pixels.c appear to have fixed genuine bugs.
SDL_audiocvt.c: By separating the calculation of the divisor, I got rid of the suspicion that dividing a double by an integer led to loss of precision.
SDL_immdevice.c: Added a missing test, one that could have otherwise led to dereferencing a null pointer.
SDL_events.c, SDL_gamecontroller.c, SDL_joystick.c, SDL_malloc.c, SDL_video.c: Made it clear the return values weren't used.
SDL_hidapi_shield.c: The size is zero, so nothing bad would have happened, but the SDL_memset() was still being given an address outside of the array's range.
SDL_dinputjoystick.c: Initialize local data, just in case IDirectInputDevice8_GetProperty() isn't guaranteed to write to it.
SDL_render_sw.c: drawstate.viewport could be null (as seen on line 691).
SDL.c: SDL_MostSignificantBitIndex32() could return -1, though I don't know if you want to cope with that (what I did) or SDL_assert() that it can't happen.
SDL_hints.c: Replaced boolean tests on pointer values with comparisons to NULL.
SDL_pixels.c: Looks like the switch is genuinely missing a break!
SDL_rect_impl.h: The MacOS static checker pointed out issues with the X comparisons that were handled by assertions; I added assertions for the Y comparisons.
SDL_yuv.c, SDL_windowskeyboard.c, SDL_windowswindow.c: Checked error-result returns.
2022-10-05 19:26:09 -07:00
|
|
|
++SDL_SubsystemRefCount[subsystem_index];
|
2022-11-16 12:53:48 -05:00
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Private helper to decrement a subsystem's ref counter. */
|
2022-12-27 15:05:51 -08:00
|
|
|
static void SDL_DecrementSubsystemRefCount(Uint32 subsystem)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2022-11-16 12:53:48 -05:00
|
|
|
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
|
|
|
|
|
if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] > 0)) {
|
2015-06-21 17:33:46 +02:00
|
|
|
--SDL_SubsystemRefCount[subsystem_index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Private helper to check if a system needs init. */
|
2022-12-27 15:05:51 -08:00
|
|
|
static SDL_bool SDL_ShouldInitSubsystem(Uint32 subsystem)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2022-11-16 12:53:48 -05:00
|
|
|
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
|
|
|
|
|
SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
|
2023-11-03 09:27:29 -07:00
|
|
|
return ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0));
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Private helper to check if a system needs to be quit. */
|
2022-12-27 15:05:51 -08:00
|
|
|
static SDL_bool SDL_ShouldQuitSubsystem(Uint32 subsystem)
|
2022-11-30 12:51:59 -08:00
|
|
|
{
|
2022-11-16 12:53:48 -05:00
|
|
|
const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
|
|
|
|
|
if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) {
|
|
|
|
|
return SDL_FALSE;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we're in SDL_Quit, we shut down every subsystem, even if refcount
|
|
|
|
|
* isn't zero.
|
|
|
|
|
*/
|
2023-11-03 09:27:29 -07:00
|
|
|
return (((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 1)) || SDL_bInMainQuit);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2023-10-12 12:37:35 +03:00
|
|
|
/* Private helper to either increment's existing ref counter,
|
|
|
|
|
* or fully init a new subsystem. */
|
|
|
|
|
static SDL_bool SDL_InitOrIncrementSubsystem(Uint32 subsystem)
|
|
|
|
|
{
|
|
|
|
|
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
|
|
|
|
|
SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
|
|
|
|
|
if (subsystem_index < 0) {
|
|
|
|
|
return SDL_FALSE;
|
|
|
|
|
}
|
|
|
|
|
if (SDL_SubsystemRefCount[subsystem_index] > 0) {
|
|
|
|
|
++SDL_SubsystemRefCount[subsystem_index];
|
|
|
|
|
return SDL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
return SDL_InitSubSystem(subsystem) == 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
void SDL_SetMainReady(void)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
SDL_MainIsReady = SDL_TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
int SDL_InitSubSystem(Uint32 flags)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2021-10-12 18:55:31 -04:00
|
|
|
Uint32 flags_initialized = 0;
|
2021-11-20 21:51:10 +03:00
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
if (!SDL_MainIsReady) {
|
2022-01-17 17:22:30 +01:00
|
|
|
return SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_InitLog();
|
2023-10-10 12:38:22 -07:00
|
|
|
SDL_InitProperties();
|
2023-11-08 12:38:04 -08:00
|
|
|
SDL_GetGlobalProperties();
|
2022-04-27 09:39:24 -04:00
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
/* Clear the error message */
|
|
|
|
|
SDL_ClearError();
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_USE_LIBDBUS
|
2021-04-02 14:35:11 -04:00
|
|
|
SDL_DBus_Init();
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_WINDOWS
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & (SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK)) {
|
2018-09-24 11:49:25 -07:00
|
|
|
if (SDL_HelperWindowCreate() < 0) {
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2018-09-24 11:49:25 -07:00
|
|
|
}
|
|
|
|
|
}
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_TIMERS_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_InitTicks();
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Initialize the event subsystem */
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_EVENTS) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_EVENTS_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_EVENTS)) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_EVENTS);
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_InitEvents() < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_EVENTS);
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_EVENTS);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2021-10-12 18:55:31 -04:00
|
|
|
flags_initialized |= SDL_INIT_EVENTS;
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with events support");
|
|
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the timer subsystem */
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_TIMER) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#if !defined(SDL_TIMERS_DISABLED) && !defined(SDL_TIMER_DUMMY)
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_TIMER)) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_TIMER);
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_InitTimers() < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_TIMER);
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_TIMER);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2021-10-12 18:55:31 -04:00
|
|
|
flags_initialized |= SDL_INIT_TIMER;
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with timer support");
|
|
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the video subsystem */
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_VIDEO) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_VIDEO_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_VIDEO)) {
|
2023-10-12 12:37:35 +03:00
|
|
|
/* video implies events */
|
|
|
|
|
if (!SDL_InitOrIncrementSubsystem(SDL_INIT_EVENTS)) {
|
|
|
|
|
goto quit_and_error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO);
|
2015-06-21 17:33:46 +02:00
|
|
|
if (SDL_VideoInit(NULL) < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_VIDEO);
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_VIDEO);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2021-10-12 18:55:31 -04:00
|
|
|
flags_initialized |= SDL_INIT_VIDEO;
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with video support");
|
|
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the audio subsystem */
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_AUDIO) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_AUDIO_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_AUDIO)) {
|
2023-10-12 12:37:35 +03:00
|
|
|
/* audio implies events */
|
|
|
|
|
if (!SDL_InitOrIncrementSubsystem(SDL_INIT_EVENTS)) {
|
|
|
|
|
goto quit_and_error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_AUDIO);
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_InitAudio(NULL) < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_AUDIO);
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_AUDIO);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2021-10-12 18:55:31 -04:00
|
|
|
flags_initialized |= SDL_INIT_AUDIO;
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with audio support");
|
|
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the joystick subsystem */
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_JOYSTICK) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_JOYSTICK_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
|
2023-10-12 12:37:35 +03:00
|
|
|
/* joystick implies events */
|
|
|
|
|
if (!SDL_InitOrIncrementSubsystem(SDL_INIT_EVENTS)) {
|
|
|
|
|
goto quit_and_error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_InitJoysticks() < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
2022-11-30 12:51:59 -08:00
|
|
|
goto quit_and_error;
|
|
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2021-10-12 18:55:31 -04:00
|
|
|
flags_initialized |= SDL_INIT_JOYSTICK;
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with joystick support");
|
|
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_GAMEPAD) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_JOYSTICK_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_GAMEPAD)) {
|
2023-10-12 12:37:35 +03:00
|
|
|
/* game controller implies joystick */
|
|
|
|
|
if (!SDL_InitOrIncrementSubsystem(SDL_INIT_JOYSTICK)) {
|
|
|
|
|
goto quit_and_error;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_InitGamepads() < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 09:46:24 -08:00
|
|
|
flags_initialized |= SDL_INIT_GAMEPAD;
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with joystick support");
|
|
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Initialize the haptic subsystem */
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_HAPTIC) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_HAPTIC_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_HAPTIC)) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_HAPTIC);
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_InitHaptics() < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_HAPTIC);
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_HAPTIC);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2021-10-12 18:55:31 -04:00
|
|
|
flags_initialized |= SDL_INIT_HAPTIC;
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with haptic (force feedback) support");
|
|
|
|
|
goto quit_and_error;
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-21 12:11:34 -07:00
|
|
|
/* Initialize the sensor subsystem */
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_SENSOR) {
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_SENSOR_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldInitSubsystem(SDL_INIT_SENSOR)) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_SENSOR);
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_InitSensors() < 0) {
|
2023-01-20 17:06:49 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_SENSOR);
|
2021-10-12 18:55:31 -04:00
|
|
|
goto quit_and_error;
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2023-01-20 17:06:49 -08:00
|
|
|
} else {
|
|
|
|
|
SDL_IncrementSubsystemRefCount(SDL_INIT_SENSOR);
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
2021-10-12 18:55:31 -04:00
|
|
|
flags_initialized |= SDL_INIT_SENSOR;
|
2018-08-21 12:11:34 -07:00
|
|
|
#else
|
2021-10-12 18:55:31 -04:00
|
|
|
SDL_SetError("SDL not built with sensor support");
|
|
|
|
|
goto quit_and_error;
|
2018-08-21 12:11:34 -07:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
(void)flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
|
2022-03-24 11:00:43 -04:00
|
|
|
|
2022-11-27 17:38:43 +01:00
|
|
|
return 0;
|
2021-11-20 21:51:10 +03:00
|
|
|
|
2021-10-12 18:55:31 -04:00
|
|
|
quit_and_error:
|
|
|
|
|
SDL_QuitSubSystem(flags_initialized);
|
2022-11-27 17:38:43 +01:00
|
|
|
return -1;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
int SDL_Init(Uint32 flags)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
return SDL_InitSubSystem(flags);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
void SDL_QuitSubSystem(Uint32 flags)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
/* Shut down requested initialized subsystems */
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_SENSOR_DISABLED
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_SENSOR) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_SENSOR)) {
|
|
|
|
|
SDL_QuitSensors();
|
2018-09-24 11:49:25 -07:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_SENSOR);
|
2018-08-21 12:11:34 -07:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_JOYSTICK_DISABLED
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_GAMEPAD) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_GAMEPAD)) {
|
|
|
|
|
SDL_QuitGamepads();
|
2023-10-12 12:37:35 +03:00
|
|
|
/* game controller implies joystick */
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_GAMEPAD);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_JOYSTICK) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
|
|
|
|
|
SDL_QuitJoysticks();
|
2023-10-12 12:37:35 +03:00
|
|
|
/* joystick implies events */
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_JOYSTICK);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_HAPTIC_DISABLED
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_HAPTIC) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
|
|
|
|
|
SDL_QuitHaptics();
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_HAPTIC);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_AUDIO_DISABLED
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_AUDIO) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_AUDIO)) {
|
|
|
|
|
SDL_QuitAudio();
|
2023-10-12 12:37:35 +03:00
|
|
|
/* audio implies events */
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_AUDIO);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_VIDEO_DISABLED
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_VIDEO) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_VIDEO)) {
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_VideoQuit();
|
2023-10-12 12:37:35 +03:00
|
|
|
/* video implies events */
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVENTS);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_VIDEO);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#if !defined(SDL_TIMERS_DISABLED) && !defined(SDL_TIMER_DUMMY)
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_TIMER) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_TIMER)) {
|
|
|
|
|
SDL_QuitTimers();
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_TIMER);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_EVENTS_DISABLED
|
2023-02-03 22:08:42 +01:00
|
|
|
if (flags & SDL_INIT_EVENTS) {
|
2022-12-27 15:05:51 -08:00
|
|
|
if (SDL_ShouldQuitSubsystem(SDL_INIT_EVENTS)) {
|
|
|
|
|
SDL_QuitEvents();
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_DecrementSubsystemRefCount(SDL_INIT_EVENTS);
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 09:37:07 -07:00
|
|
|
Uint32 SDL_WasInit(Uint32 flags)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
|
|
|
|
|
Uint32 initialized = 0;
|
|
|
|
|
|
2018-11-19 21:17:00 -08:00
|
|
|
/* Fast path for checking one flag */
|
|
|
|
|
if (SDL_HasExactlyOneBitSet32(flags)) {
|
|
|
|
|
int subsystem_index = SDL_MostSignificantBitIndex32(flags);
|
|
|
|
|
return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
if (!flags) {
|
|
|
|
|
flags = SDL_INIT_EVERYTHING;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
|
|
|
|
|
|
|
|
|
|
/* Iterate over each bit in flags, and check the matching subsystem. */
|
|
|
|
|
for (i = 0; i < num_subsystems; ++i) {
|
|
|
|
|
if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
|
|
|
|
|
initialized |= (1 << i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
flags >>= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return initialized;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-30 12:51:59 -08:00
|
|
|
void SDL_Quit(void)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
SDL_bInMainQuit = SDL_TRUE;
|
|
|
|
|
|
|
|
|
|
/* Quit all subsystems */
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_VIDEO_DRIVER_WINDOWS
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_HelperWindowDestroy();
|
|
|
|
|
#endif
|
|
|
|
|
SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifndef SDL_TIMERS_DISABLED
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_QuitTicks();
|
2015-06-21 17:33:46 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
SDL_ClearHints();
|
|
|
|
|
SDL_AssertionsQuit();
|
|
|
|
|
|
2023-03-29 21:49:01 +00:00
|
|
|
#ifdef SDL_USE_LIBDBUS
|
2021-04-02 14:35:11 -04:00
|
|
|
SDL_DBus_Quit();
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-10-10 12:38:22 -07:00
|
|
|
SDL_QuitProperties();
|
2022-12-27 15:05:51 -08:00
|
|
|
SDL_QuitLog();
|
2022-04-27 09:39:24 -04:00
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
/* Now that every subsystem has been quit, we reset the subsystem refcount
|
|
|
|
|
* and the list of initialized subsystems.
|
|
|
|
|
*/
|
2022-11-30 12:51:59 -08:00
|
|
|
SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2023-05-26 08:32:31 -07:00
|
|
|
SDL_CleanupTLS();
|
2022-09-08 20:08:20 -07:00
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_bInMainQuit = SDL_FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-23 09:46:09 -07:00
|
|
|
/* Assume we can wrap SDL_AtomicInt values and cast to Uint32 */
|
|
|
|
|
SDL_COMPILE_TIME_ASSERT(sizeof_object_id, sizeof(int) == sizeof(Uint32));
|
|
|
|
|
|
|
|
|
|
Uint32 SDL_GetNextObjectID(void)
|
|
|
|
|
{
|
|
|
|
|
static SDL_AtomicInt last_id;
|
|
|
|
|
|
|
|
|
|
Uint32 id = (Uint32)SDL_AtomicIncRef(&last_id) + 1;
|
|
|
|
|
if (id == 0) {
|
|
|
|
|
id = (Uint32)SDL_AtomicIncRef(&last_id) + 1;
|
|
|
|
|
}
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
/* Get the library version number */
|
2023-02-08 20:43:52 +01:00
|
|
|
int SDL_GetVersion(SDL_version *ver)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2022-11-26 13:09:50 -08:00
|
|
|
static SDL_bool check_hint = SDL_TRUE;
|
|
|
|
|
static SDL_bool legacy_version = SDL_FALSE;
|
|
|
|
|
|
2023-11-09 22:29:15 +01:00
|
|
|
if (!ver) {
|
2023-02-08 20:43:52 +01:00
|
|
|
return SDL_InvalidParamError("ver");
|
2022-09-26 17:06:18 -07:00
|
|
|
}
|
|
|
|
|
|
2015-06-21 17:33:46 +02:00
|
|
|
SDL_VERSION(ver);
|
2022-09-26 17:06:18 -07:00
|
|
|
|
2022-11-26 13:09:50 -08:00
|
|
|
if (check_hint) {
|
|
|
|
|
check_hint = SDL_FALSE;
|
|
|
|
|
legacy_version = SDL_GetHintBoolean("SDL_LEGACY_VERSION", SDL_FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (legacy_version) {
|
2022-09-26 17:06:18 -07:00
|
|
|
/* Prior to SDL 2.24.0, the patch version was incremented with every release */
|
|
|
|
|
ver->patch = ver->minor;
|
|
|
|
|
ver->minor = 0;
|
|
|
|
|
}
|
2023-02-08 20:43:52 +01:00
|
|
|
return 0;
|
2015-06-21 17:33:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the library source revision */
|
2023-05-23 11:29:41 -07:00
|
|
|
const char *SDL_GetRevision(void)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
return SDL_REVISION;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the name of the platform */
|
2023-05-23 11:29:41 -07:00
|
|
|
const char *SDL_GetPlatform(void)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef __AIX__
|
2015-06-21 17:33:46 +02:00
|
|
|
return "AIX";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__ANDROID__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Android";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__BSDI__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "BSDI";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__DREAMCAST__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Dreamcast";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__EMSCRIPTEN__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Emscripten";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__FREEBSD__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "FreeBSD";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__HAIKU__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Haiku";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__HPUX__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "HP-UX";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__IRIX__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Irix";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__LINUX__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Linux";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__MINT__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Atari MiNT";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__MACOS__)
|
|
|
|
|
return "macOS";
|
|
|
|
|
#elif defined(__NACL__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "NaCl";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__NETBSD__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "NetBSD";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__OPENBSD__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "OpenBSD";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__OS2__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "OS/2";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__OSF__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "OSF/1";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__QNXNTO__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "QNX Neutrino";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__RISCOS__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "RISC OS";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__SOLARIS__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Solaris";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__WIN32__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "Windows";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__WINRT__)
|
2022-11-23 10:41:43 -08:00
|
|
|
return "WinRT";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__WINGDK__)
|
2022-06-27 17:19:39 +00:00
|
|
|
return "WinGDK";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__XBOXONE__)
|
2022-07-01 13:59:14 -07:00
|
|
|
return "Xbox One";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__XBOXSERIES__)
|
2022-09-21 14:22:38 -07:00
|
|
|
return "Xbox Series X|S";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__IOS__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "iOS";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__TVOS__)
|
|
|
|
|
return "tvOS";
|
|
|
|
|
#elif defined(__PS2__)
|
2022-06-06 00:04:56 +02:00
|
|
|
return "PlayStation 2";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__PSP__)
|
2015-06-21 17:33:46 +02:00
|
|
|
return "PlayStation Portable";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__VITA__)
|
2020-11-02 18:09:43 +03:00
|
|
|
return "PlayStation Vita";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__NGAGE__)
|
2022-05-03 17:51:49 +02:00
|
|
|
return "Nokia N-Gage";
|
2022-11-25 16:00:06 -08:00
|
|
|
#elif defined(__3DS__)
|
2021-03-30 04:32:39 -04:00
|
|
|
return "Nintendo 3DS";
|
2023-07-21 21:01:37 +02:00
|
|
|
#elif defined(__managarm__)
|
|
|
|
|
return "Managarm";
|
2015-06-21 17:33:46 +02:00
|
|
|
#else
|
|
|
|
|
return "Unknown (see SDL_platform.h)";
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-23 11:29:41 -07:00
|
|
|
SDL_bool SDL_IsTablet(void)
|
2018-08-21 20:03:54 -07:00
|
|
|
{
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef __ANDROID__
|
2018-08-21 20:03:54 -07:00
|
|
|
extern SDL_bool SDL_IsAndroidTablet(void);
|
|
|
|
|
return SDL_IsAndroidTablet();
|
2023-03-29 21:49:01 +00:00
|
|
|
#elif defined(__IOS__)
|
2018-08-21 20:03:54 -07:00
|
|
|
extern SDL_bool SDL_IsIPad(void);
|
|
|
|
|
return SDL_IsIPad();
|
|
|
|
|
#else
|
|
|
|
|
return SDL_FALSE;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 20:26:31 +02:00
|
|
|
#ifdef __WIN32__
|
2018-02-18 09:09:56 -08:00
|
|
|
|
2018-02-21 09:40:47 -08:00
|
|
|
#if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
|
2023-08-04 10:23:20 +03:00
|
|
|
/* FIXME: Still need to include DllMain() on Watcom C ? */
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2023-08-04 10:23:20 +03:00
|
|
|
BOOL APIENTRY MINGW32_FORCEALIGN _DllMainCRTStartup(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
|
2015-06-21 17:33:46 +02:00
|
|
|
{
|
|
|
|
|
switch (ul_reason_for_call) {
|
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
|
case DLL_THREAD_ATTACH:
|
|
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
|
case DLL_PROCESS_DETACH:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2018-02-21 09:40:47 -08:00
|
|
|
#endif /* Building DLL */
|
2015-06-21 17:33:46 +02:00
|
|
|
|
2022-06-27 17:19:39 +00:00
|
|
|
#endif /* defined(__WIN32__) || defined(__GDK__) */
|