SDL.c 17 KB

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