SDL.c 19 KB

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