SDL.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "./SDL_internal.h"
  19. #if defined(__WIN32__) || defined(__GDK__)
  20. #include "core/windows/SDL_windows.h"
  21. #elif defined(__OS2__)
  22. #include <stdlib.h> /* _exit() */
  23. #elif !defined(__WINRT__)
  24. #include <unistd.h> /* _exit(), etc. */
  25. #endif
  26. #if defined(__OS2__)
  27. #include "core/os2/SDL_os2.h"
  28. #ifdef SDL_THREAD_OS2
  29. #include "thread/os2/SDL_systls_c.h"
  30. #endif
  31. #endif
  32. /* this checks for HAVE_DBUS_DBUS_H internally. */
  33. #include "core/linux/SDL_dbus.h"
  34. #if defined(__EMSCRIPTEN__)
  35. #include <emscripten.h>
  36. #endif
  37. /* Initialization code for SDL */
  38. #include "SDL.h"
  39. #include "SDL_bits.h"
  40. #include "SDL_revision.h"
  41. #include "SDL_assert_c.h"
  42. #include "SDL_log_c.h"
  43. #include "events/SDL_events_c.h"
  44. #include "haptic/SDL_haptic_c.h"
  45. #include "joystick/SDL_joystick_c.h"
  46. #include "sensor/SDL_sensor_c.h"
  47. /* Initialization/Cleanup routines */
  48. #ifndef SDL_TIMERS_DISABLED
  49. #include "timer/SDL_timer_c.h"
  50. #endif
  51. #ifdef SDL_VIDEO_DRIVER_WINDOWS
  52. extern int SDL_HelperWindowCreate(void);
  53. extern int SDL_HelperWindowDestroy(void);
  54. #endif
  55. #ifdef SDL_BUILD_MAJOR_VERSION
  56. SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MAJOR_VERSION,
  57. SDL_MAJOR_VERSION == SDL_BUILD_MAJOR_VERSION);
  58. SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MINOR_VERSION,
  59. SDL_MINOR_VERSION == SDL_BUILD_MINOR_VERSION);
  60. SDL_COMPILE_TIME_ASSERT(SDL_BUILD_MICRO_VERSION,
  61. SDL_PATCHLEVEL == SDL_BUILD_MICRO_VERSION);
  62. #endif
  63. SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_min, SDL_MAJOR_VERSION >= 0);
  64. /* Limited only by the need to fit in SDL_version */
  65. SDL_COMPILE_TIME_ASSERT(SDL_MAJOR_VERSION_max, SDL_MAJOR_VERSION <= 255);
  66. SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_min, SDL_MINOR_VERSION >= 0);
  67. /* Limited only by the need to fit in SDL_version */
  68. SDL_COMPILE_TIME_ASSERT(SDL_MINOR_VERSION_max, SDL_MINOR_VERSION <= 255);
  69. SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_min, SDL_PATCHLEVEL >= 0);
  70. /* Limited by its encoding in SDL_VERSIONNUM and in the ABI versions */
  71. SDL_COMPILE_TIME_ASSERT(SDL_PATCHLEVEL_max, SDL_PATCHLEVEL <= 99);
  72. /* This is not declared in any header, although it is shared between some
  73. parts of SDL, because we don't want anything calling it without an
  74. extremely good reason. */
  75. extern SDL_NORETURN void SDL_ExitProcess(int exitcode);
  76. SDL_NORETURN void SDL_ExitProcess(int exitcode)
  77. {
  78. #if defined(__WIN32__) || defined(__GDK__)
  79. /* "if you do not know the state of all threads in your process, it is
  80. better to call TerminateProcess than ExitProcess"
  81. https://msdn.microsoft.com/en-us/library/windows/desktop/ms682658(v=vs.85).aspx */
  82. TerminateProcess(GetCurrentProcess(), exitcode);
  83. /* MingW doesn't have TerminateProcess marked as noreturn, so add an
  84. ExitProcess here that will never be reached but make MingW happy. */
  85. ExitProcess(exitcode);
  86. #elif defined(__EMSCRIPTEN__)
  87. emscripten_cancel_main_loop(); /* this should "kill" the app. */
  88. emscripten_force_exit(exitcode); /* this should "kill" the app. */
  89. exit(exitcode);
  90. #elif defined(__HAIKU__) /* Haiku has _Exit, but it's not marked noreturn. */
  91. _exit(exitcode);
  92. #elif defined(HAVE__EXIT) /* Upper case _Exit() */
  93. _Exit(exitcode);
  94. #else
  95. _exit(exitcode);
  96. #endif
  97. }
  98. /* The initialized subsystems */
  99. #ifdef SDL_MAIN_NEEDED
  100. static SDL_bool SDL_MainIsReady = SDL_FALSE;
  101. #else
  102. static SDL_bool SDL_MainIsReady = SDL_TRUE;
  103. #endif
  104. static SDL_bool SDL_bInMainQuit = SDL_FALSE;
  105. static Uint8 SDL_SubsystemRefCount[32];
  106. /* Private helper to increment a subsystem's ref counter. */
  107. static void SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
  108. {
  109. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  110. SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
  111. if (subsystem_index >= 0) {
  112. ++SDL_SubsystemRefCount[subsystem_index];
  113. }
  114. }
  115. /* Private helper to decrement a subsystem's ref counter. */
  116. static void SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
  117. {
  118. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  119. if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] > 0)) {
  120. --SDL_SubsystemRefCount[subsystem_index];
  121. }
  122. }
  123. /* Private helper to check if a system needs init. */
  124. static SDL_bool SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
  125. {
  126. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  127. SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
  128. return ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) ? SDL_TRUE : SDL_FALSE;
  129. }
  130. /* Private helper to check if a system needs to be quit. */
  131. static SDL_bool SDL_PrivateShouldQuitSubsystem(Uint32 subsystem)
  132. {
  133. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  134. if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) {
  135. return SDL_FALSE;
  136. }
  137. /* If we're in SDL_Quit, we shut down every subsystem, even if refcount
  138. * isn't zero.
  139. */
  140. return (((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 1)) || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
  141. }
  142. /* Private helper to either increment's existing ref counter,
  143. * or fully init a new subsystem. */
  144. static SDL_bool SDL_PrivateInitOrIncrSubsystem(Uint32 subsystem)
  145. {
  146. int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  147. SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
  148. if (subsystem_index < 0) {
  149. return SDL_FALSE;
  150. }
  151. if (SDL_SubsystemRefCount[subsystem_index] > 0) {
  152. ++SDL_SubsystemRefCount[subsystem_index];
  153. return SDL_TRUE;
  154. }
  155. return SDL_InitSubSystem(subsystem) == 0;
  156. }
  157. void SDL_SetMainReady(void)
  158. {
  159. SDL_MainIsReady = SDL_TRUE;
  160. }
  161. int SDL_InitSubSystem(Uint32 flags)
  162. {
  163. Uint32 flags_initialized = 0;
  164. if (!SDL_MainIsReady) {
  165. return SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
  166. }
  167. SDL_LogInit();
  168. /* Clear the error message */
  169. SDL_ClearError();
  170. #ifdef SDL_USE_LIBDBUS
  171. SDL_DBus_Init();
  172. #endif
  173. #ifdef SDL_THREAD_OS2
  174. SDL_OS2TLSAlloc(); /* thread/os2/SDL_systls.c */
  175. #endif
  176. #ifdef SDL_VIDEO_DRIVER_WINDOWS
  177. if (flags & (SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK)) {
  178. if (SDL_HelperWindowCreate() < 0) {
  179. goto quit_and_error;
  180. }
  181. }
  182. #endif
  183. #ifndef SDL_TIMERS_DISABLED
  184. SDL_TicksInit();
  185. #endif
  186. /* Initialize the event subsystem */
  187. if (flags & SDL_INIT_EVENTS) {
  188. #ifndef SDL_EVENTS_DISABLED
  189. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
  190. if (SDL_EventsInit() < 0) {
  191. goto quit_and_error;
  192. }
  193. }
  194. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
  195. flags_initialized |= SDL_INIT_EVENTS;
  196. #else
  197. SDL_SetError("SDL not built with events support");
  198. goto quit_and_error;
  199. #endif
  200. }
  201. /* Initialize the timer subsystem */
  202. if (flags & SDL_INIT_TIMER) {
  203. #if !defined(SDL_TIMERS_DISABLED) && !defined(SDL_TIMER_DUMMY)
  204. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
  205. if (SDL_TimerInit() < 0) {
  206. goto quit_and_error;
  207. }
  208. }
  209. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
  210. flags_initialized |= SDL_INIT_TIMER;
  211. #else
  212. SDL_SetError("SDL not built with timer support");
  213. goto quit_and_error;
  214. #endif
  215. }
  216. /* Initialize the video subsystem */
  217. if (flags & SDL_INIT_VIDEO) {
  218. #ifndef SDL_VIDEO_DISABLED
  219. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
  220. /* video implies events */
  221. if (!SDL_PrivateInitOrIncrSubsystem(SDL_INIT_EVENTS)) {
  222. goto quit_and_error;
  223. }
  224. if (SDL_VideoInit(NULL) < 0) {
  225. goto quit_and_error;
  226. }
  227. }
  228. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
  229. flags_initialized |= SDL_INIT_VIDEO;
  230. #else
  231. SDL_SetError("SDL not built with video support");
  232. goto quit_and_error;
  233. #endif
  234. }
  235. /* Initialize the audio subsystem */
  236. if (flags & SDL_INIT_AUDIO) {
  237. #ifndef SDL_AUDIO_DISABLED
  238. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
  239. /* audio implies events */
  240. if (!SDL_PrivateInitOrIncrSubsystem(SDL_INIT_EVENTS)) {
  241. goto quit_and_error;
  242. }
  243. if (SDL_AudioInit(NULL) < 0) {
  244. goto quit_and_error;
  245. }
  246. }
  247. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
  248. flags_initialized |= SDL_INIT_AUDIO;
  249. #else
  250. SDL_SetError("SDL not built with audio support");
  251. goto quit_and_error;
  252. #endif
  253. }
  254. /* Initialize the joystick subsystem */
  255. if (flags & SDL_INIT_JOYSTICK) {
  256. #ifndef SDL_JOYSTICK_DISABLED
  257. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
  258. /* joystick implies events */
  259. if (!SDL_PrivateInitOrIncrSubsystem(SDL_INIT_EVENTS)) {
  260. goto quit_and_error;
  261. }
  262. if (SDL_JoystickInit() < 0) {
  263. goto quit_and_error;
  264. }
  265. }
  266. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
  267. flags_initialized |= SDL_INIT_JOYSTICK;
  268. #else
  269. SDL_SetError("SDL not built with joystick support");
  270. goto quit_and_error;
  271. #endif
  272. }
  273. if (flags & SDL_INIT_GAMECONTROLLER) {
  274. #ifndef SDL_JOYSTICK_DISABLED
  275. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
  276. /* game controller implies joystick */
  277. if (!SDL_PrivateInitOrIncrSubsystem(SDL_INIT_JOYSTICK)) {
  278. goto quit_and_error;
  279. }
  280. if (SDL_GameControllerInit() < 0) {
  281. goto quit_and_error;
  282. }
  283. }
  284. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
  285. flags_initialized |= SDL_INIT_GAMECONTROLLER;
  286. #else
  287. SDL_SetError("SDL not built with joystick support");
  288. goto quit_and_error;
  289. #endif
  290. }
  291. /* Initialize the haptic subsystem */
  292. if (flags & SDL_INIT_HAPTIC) {
  293. #ifndef SDL_HAPTIC_DISABLED
  294. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
  295. if (SDL_HapticInit() < 0) {
  296. goto quit_and_error;
  297. }
  298. }
  299. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
  300. flags_initialized |= SDL_INIT_HAPTIC;
  301. #else
  302. SDL_SetError("SDL not built with haptic (force feedback) support");
  303. goto quit_and_error;
  304. #endif
  305. }
  306. /* Initialize the sensor subsystem */
  307. if (flags & SDL_INIT_SENSOR) {
  308. #ifndef SDL_SENSOR_DISABLED
  309. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
  310. if (SDL_SensorInit() < 0) {
  311. goto quit_and_error;
  312. }
  313. }
  314. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR);
  315. flags_initialized |= SDL_INIT_SENSOR;
  316. #else
  317. SDL_SetError("SDL not built with sensor support");
  318. goto quit_and_error;
  319. #endif
  320. }
  321. (void)flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
  322. return 0;
  323. quit_and_error:
  324. SDL_QuitSubSystem(flags_initialized);
  325. return -1;
  326. }
  327. int SDL_Init(Uint32 flags)
  328. {
  329. return SDL_InitSubSystem(flags);
  330. }
  331. void SDL_QuitSubSystem(Uint32 flags)
  332. {
  333. #if defined(__OS2__)
  334. #ifdef SDL_THREAD_OS2
  335. SDL_OS2TLSFree(); /* thread/os2/SDL_systls.c */
  336. #endif
  337. SDL_OS2Quit();
  338. #endif
  339. /* Shut down requested initialized subsystems */
  340. #ifndef SDL_SENSOR_DISABLED
  341. if (flags & SDL_INIT_SENSOR) {
  342. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) {
  343. SDL_SensorQuit();
  344. }
  345. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR);
  346. }
  347. #endif
  348. #ifndef SDL_JOYSTICK_DISABLED
  349. if (flags & SDL_INIT_GAMECONTROLLER) {
  350. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
  351. SDL_GameControllerQuit();
  352. /* game controller implies joystick */
  353. SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
  354. }
  355. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
  356. }
  357. if (flags & SDL_INIT_JOYSTICK) {
  358. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
  359. SDL_JoystickQuit();
  360. /* joystick implies events */
  361. SDL_QuitSubSystem(SDL_INIT_EVENTS);
  362. }
  363. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
  364. }
  365. #endif
  366. #ifndef SDL_HAPTIC_DISABLED
  367. if (flags & SDL_INIT_HAPTIC) {
  368. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
  369. SDL_HapticQuit();
  370. }
  371. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
  372. }
  373. #endif
  374. #ifndef SDL_AUDIO_DISABLED
  375. if (flags & SDL_INIT_AUDIO) {
  376. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
  377. SDL_AudioQuit();
  378. /* audio implies events */
  379. SDL_QuitSubSystem(SDL_INIT_EVENTS);
  380. }
  381. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
  382. }
  383. #endif
  384. #ifndef SDL_VIDEO_DISABLED
  385. if (flags & SDL_INIT_VIDEO) {
  386. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
  387. SDL_VideoQuit();
  388. /* video implies events */
  389. SDL_QuitSubSystem(SDL_INIT_EVENTS);
  390. }
  391. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
  392. }
  393. #endif
  394. #if !defined(SDL_TIMERS_DISABLED) && !defined(SDL_TIMER_DUMMY)
  395. if (flags & SDL_INIT_TIMER) {
  396. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
  397. SDL_TimerQuit();
  398. }
  399. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
  400. }
  401. #endif
  402. #ifndef SDL_EVENTS_DISABLED
  403. if (flags & SDL_INIT_EVENTS) {
  404. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
  405. SDL_EventsQuit();
  406. }
  407. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
  408. }
  409. #endif
  410. }
  411. Uint32 SDL_WasInit(Uint32 flags)
  412. {
  413. int i;
  414. int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
  415. Uint32 initialized = 0;
  416. /* Fast path for checking one flag */
  417. if (SDL_HasExactlyOneBitSet32(flags)) {
  418. int subsystem_index = SDL_MostSignificantBitIndex32(flags);
  419. return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
  420. }
  421. if (!flags) {
  422. flags = SDL_INIT_EVERYTHING;
  423. }
  424. num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
  425. /* Iterate over each bit in flags, and check the matching subsystem. */
  426. for (i = 0; i < num_subsystems; ++i) {
  427. if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
  428. initialized |= (1 << i);
  429. }
  430. flags >>= 1;
  431. }
  432. return initialized;
  433. }
  434. void SDL_Quit(void)
  435. {
  436. SDL_bInMainQuit = SDL_TRUE;
  437. /* Quit all subsystems */
  438. #ifdef SDL_VIDEO_DRIVER_WINDOWS
  439. SDL_HelperWindowDestroy();
  440. #endif
  441. SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
  442. #ifndef SDL_TIMERS_DISABLED
  443. SDL_TicksQuit();
  444. #endif
  445. #ifdef SDL_USE_LIBDBUS
  446. SDL_DBus_Quit();
  447. #endif
  448. SDL_ClearHints();
  449. SDL_AssertionsQuit();
  450. SDL_LogQuit();
  451. /* Now that every subsystem has been quit, we reset the subsystem refcount
  452. * and the list of initialized subsystems.
  453. */
  454. SDL_memset(SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount));
  455. SDL_TLSCleanup();
  456. SDL_bInMainQuit = SDL_FALSE;
  457. }
  458. /* Get the library version number */
  459. void SDL_GetVersion(SDL_version *ver)
  460. {
  461. static SDL_bool check_hint = SDL_TRUE;
  462. static SDL_bool legacy_version = SDL_FALSE;
  463. if (!ver) {
  464. return;
  465. }
  466. SDL_VERSION(ver);
  467. if (check_hint) {
  468. check_hint = SDL_FALSE;
  469. legacy_version = SDL_GetHintBoolean("SDL_LEGACY_VERSION", SDL_FALSE);
  470. }
  471. if (legacy_version) {
  472. /* Prior to SDL 2.24.0, the patch version was incremented with every release */
  473. ver->patch = ver->minor;
  474. ver->minor = 0;
  475. }
  476. }
  477. /* Get the library source revision */
  478. const char *SDL_GetRevision(void)
  479. {
  480. return SDL_REVISION;
  481. }
  482. /* Get the library source revision number */
  483. int SDL_GetRevisionNumber(void)
  484. {
  485. return 0; /* doesn't make sense without Mercurial. */
  486. }
  487. /* Get the name of the platform */
  488. const char *SDL_GetPlatform(void)
  489. {
  490. #if defined(__AIX__)
  491. return "AIX";
  492. #elif defined(__ANDROID__)
  493. return "Android";
  494. #elif defined(__BSDI__)
  495. return "BSDI";
  496. #elif defined(__DREAMCAST__)
  497. return "Dreamcast";
  498. #elif defined(__EMSCRIPTEN__)
  499. return "Emscripten";
  500. #elif defined(__FREEBSD__)
  501. return "FreeBSD";
  502. #elif defined(__HAIKU__)
  503. return "Haiku";
  504. #elif defined(__HPUX__)
  505. return "HP-UX";
  506. #elif defined(__IRIX__)
  507. return "Irix";
  508. #elif defined(__LINUX__)
  509. return "Linux";
  510. #elif defined(__MINT__)
  511. return "Atari MiNT";
  512. #elif defined(__MACOS__)
  513. return "MacOS Classic";
  514. #elif defined(__MACOSX__)
  515. return "Mac OS X";
  516. #elif defined(__NACL__)
  517. return "NaCl";
  518. #elif defined(__NETBSD__)
  519. return "NetBSD";
  520. #elif defined(__OPENBSD__)
  521. return "OpenBSD";
  522. #elif defined(__OS2__)
  523. return "OS/2";
  524. #elif defined(__OSF__)
  525. return "OSF/1";
  526. #elif defined(__QNXNTO__)
  527. return "QNX Neutrino";
  528. #elif defined(__RISCOS__)
  529. return "RISC OS";
  530. #elif defined(__SOLARIS__)
  531. return "Solaris";
  532. #elif defined(__WIN32__)
  533. return "Windows";
  534. #elif defined(__WINRT__)
  535. return "WinRT";
  536. #elif defined(__WINGDK__)
  537. return "WinGDK";
  538. #elif defined(__XBOXONE__)
  539. return "Xbox One";
  540. #elif defined(__XBOXSERIES__)
  541. return "Xbox Series X|S";
  542. #elif defined(__TVOS__)
  543. return "tvOS";
  544. #elif defined(__IPHONEOS__)
  545. return "iOS";
  546. #elif defined(__PS2__)
  547. return "PlayStation 2";
  548. #elif defined(__PSP__)
  549. return "PlayStation Portable";
  550. #elif defined(__VITA__)
  551. return "PlayStation Vita";
  552. #elif defined(__NGAGE__)
  553. return "Nokia N-Gage";
  554. #elif defined(__3DS__)
  555. return "Nintendo 3DS";
  556. #else
  557. return "Unknown (see SDL_platform.h)";
  558. #endif
  559. }
  560. SDL_bool SDL_IsTablet(void)
  561. {
  562. #if defined(__ANDROID__)
  563. extern SDL_bool SDL_IsAndroidTablet(void);
  564. return SDL_IsAndroidTablet();
  565. #elif defined(__IPHONEOS__)
  566. extern SDL_bool SDL_IsIPad(void);
  567. return SDL_IsIPad();
  568. #else
  569. return SDL_FALSE;
  570. #endif
  571. }
  572. #if defined(__WIN32__)
  573. #if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
  574. /* FIXME: Still need to include DllMain() on Watcom C ? */
  575. BOOL APIENTRY MINGW32_FORCEALIGN _DllMainCRTStartup(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
  576. {
  577. switch (ul_reason_for_call) {
  578. case DLL_PROCESS_ATTACH:
  579. case DLL_THREAD_ATTACH:
  580. case DLL_THREAD_DETACH:
  581. case DLL_PROCESS_DETACH:
  582. break;
  583. }
  584. return TRUE;
  585. }
  586. #endif /* Building DLL */
  587. #endif /* defined(__WIN32__) || defined(__GDK__) */
  588. /* vi: set sts=4 ts=4 sw=4 expandtab: */