SDL.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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
  97. SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
  98. {
  99. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  100. SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
  101. if (subsystem_index >= 0) {
  102. ++SDL_SubsystemRefCount[subsystem_index];
  103. }
  104. }
  105. /* Private helper to decrement a subsystem's ref counter. */
  106. static void
  107. SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
  108. {
  109. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  110. if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] > 0)) {
  111. --SDL_SubsystemRefCount[subsystem_index];
  112. }
  113. }
  114. /* Private helper to check if a system needs init. */
  115. static SDL_bool
  116. SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
  117. {
  118. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  119. SDL_assert((subsystem_index < 0) || (SDL_SubsystemRefCount[subsystem_index] < 255));
  120. return ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) ? SDL_TRUE : SDL_FALSE;
  121. }
  122. /* Private helper to check if a system needs to be quit. */
  123. static SDL_bool
  124. SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
  125. const int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
  126. if ((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 0)) {
  127. return SDL_FALSE;
  128. }
  129. /* If we're in SDL_Quit, we shut down every subsystem, even if refcount
  130. * isn't zero.
  131. */
  132. return (((subsystem_index >= 0) && (SDL_SubsystemRefCount[subsystem_index] == 1)) || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
  133. }
  134. void
  135. SDL_SetMainReady(void)
  136. {
  137. SDL_MainIsReady = SDL_TRUE;
  138. }
  139. int
  140. 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_LogInit();
  147. /* Clear the error message */
  148. SDL_ClearError();
  149. #if SDL_USE_LIBDBUS
  150. SDL_DBus_Init();
  151. #endif
  152. if ((flags & SDL_INIT_GAMECONTROLLER)) {
  153. /* game controller implies joystick */
  154. flags |= SDL_INIT_JOYSTICK;
  155. }
  156. if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK|SDL_INIT_AUDIO))) {
  157. /* video or joystick or audio implies events */
  158. flags |= SDL_INIT_EVENTS;
  159. }
  160. #if SDL_VIDEO_DRIVER_WINDOWS
  161. if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
  162. if (SDL_HelperWindowCreate() < 0) {
  163. goto quit_and_error;
  164. }
  165. }
  166. #endif
  167. #if !SDL_TIMERS_DISABLED
  168. SDL_TicksInit();
  169. #endif
  170. /* Initialize the event subsystem */
  171. if ((flags & SDL_INIT_EVENTS)) {
  172. #if !SDL_EVENTS_DISABLED
  173. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
  174. if (SDL_EventsInit() < 0) {
  175. goto quit_and_error;
  176. }
  177. }
  178. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
  179. flags_initialized |= SDL_INIT_EVENTS;
  180. #else
  181. SDL_SetError("SDL not built with events support");
  182. goto quit_and_error;
  183. #endif
  184. }
  185. /* Initialize the timer subsystem */
  186. if ((flags & SDL_INIT_TIMER)) {
  187. #if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY
  188. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
  189. if (SDL_TimerInit() < 0) {
  190. goto quit_and_error;
  191. }
  192. }
  193. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
  194. flags_initialized |= SDL_INIT_TIMER;
  195. #else
  196. SDL_SetError("SDL not built with timer support");
  197. goto quit_and_error;
  198. #endif
  199. }
  200. /* Initialize the video subsystem */
  201. if ((flags & SDL_INIT_VIDEO)) {
  202. #if !SDL_VIDEO_DISABLED
  203. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
  204. if (SDL_VideoInit(NULL) < 0) {
  205. goto quit_and_error;
  206. }
  207. }
  208. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
  209. flags_initialized |= SDL_INIT_VIDEO;
  210. #else
  211. SDL_SetError("SDL not built with video support");
  212. goto quit_and_error;
  213. #endif
  214. }
  215. /* Initialize the audio subsystem */
  216. if ((flags & SDL_INIT_AUDIO)) {
  217. #if !SDL_AUDIO_DISABLED
  218. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
  219. if (SDL_AudioInit(NULL) < 0) {
  220. goto quit_and_error;
  221. }
  222. }
  223. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
  224. flags_initialized |= SDL_INIT_AUDIO;
  225. #else
  226. SDL_SetError("SDL not built with audio support");
  227. goto quit_and_error;
  228. #endif
  229. }
  230. /* Initialize the joystick subsystem */
  231. if ((flags & SDL_INIT_JOYSTICK)) {
  232. #if !SDL_JOYSTICK_DISABLED
  233. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
  234. if (SDL_JoystickInit() < 0) {
  235. goto quit_and_error;
  236. }
  237. }
  238. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
  239. flags_initialized |= SDL_INIT_JOYSTICK;
  240. #else
  241. SDL_SetError("SDL not built with joystick support");
  242. goto quit_and_error;
  243. #endif
  244. }
  245. if ((flags & SDL_INIT_GAMECONTROLLER)) {
  246. #if !SDL_JOYSTICK_DISABLED
  247. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
  248. if (SDL_GameControllerInit() < 0) {
  249. goto quit_and_error;
  250. }
  251. }
  252. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
  253. flags_initialized |= SDL_INIT_GAMECONTROLLER;
  254. #else
  255. SDL_SetError("SDL not built with joystick support");
  256. goto quit_and_error;
  257. #endif
  258. }
  259. /* Initialize the haptic subsystem */
  260. if ((flags & SDL_INIT_HAPTIC)) {
  261. #if !SDL_HAPTIC_DISABLED
  262. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
  263. if (SDL_HapticInit() < 0) {
  264. goto quit_and_error;
  265. }
  266. }
  267. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
  268. flags_initialized |= SDL_INIT_HAPTIC;
  269. #else
  270. SDL_SetError("SDL not built with haptic (force feedback) support");
  271. goto quit_and_error;
  272. #endif
  273. }
  274. /* Initialize the sensor subsystem */
  275. if ((flags & SDL_INIT_SENSOR)) {
  276. #if !SDL_SENSOR_DISABLED
  277. if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
  278. if (SDL_SensorInit() < 0) {
  279. goto quit_and_error;
  280. }
  281. }
  282. SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR);
  283. flags_initialized |= SDL_INIT_SENSOR;
  284. #else
  285. SDL_SetError("SDL not built with sensor support");
  286. goto quit_and_error;
  287. #endif
  288. }
  289. (void) flags_initialized; /* make static analysis happy, since this only gets used in error cases. */
  290. return 0;
  291. quit_and_error:
  292. SDL_QuitSubSystem(flags_initialized);
  293. return -1;
  294. }
  295. int
  296. SDL_Init(Uint32 flags)
  297. {
  298. return SDL_InitSubSystem(flags);
  299. }
  300. void
  301. SDL_QuitSubSystem(Uint32 flags)
  302. {
  303. /* Shut down requested initialized subsystems */
  304. #if !SDL_SENSOR_DISABLED
  305. if ((flags & SDL_INIT_SENSOR)) {
  306. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) {
  307. SDL_SensorQuit();
  308. }
  309. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR);
  310. }
  311. #endif
  312. #if !SDL_JOYSTICK_DISABLED
  313. if ((flags & SDL_INIT_GAMECONTROLLER)) {
  314. /* game controller implies joystick */
  315. flags |= SDL_INIT_JOYSTICK;
  316. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
  317. SDL_GameControllerQuit();
  318. }
  319. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
  320. }
  321. if ((flags & SDL_INIT_JOYSTICK)) {
  322. /* joystick implies events */
  323. flags |= SDL_INIT_EVENTS;
  324. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
  325. SDL_JoystickQuit();
  326. }
  327. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
  328. }
  329. #endif
  330. #if !SDL_HAPTIC_DISABLED
  331. if ((flags & SDL_INIT_HAPTIC)) {
  332. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
  333. SDL_HapticQuit();
  334. }
  335. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
  336. }
  337. #endif
  338. #if !SDL_AUDIO_DISABLED
  339. if ((flags & SDL_INIT_AUDIO)) {
  340. /* audio implies events */
  341. flags |= SDL_INIT_EVENTS;
  342. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
  343. SDL_AudioQuit();
  344. }
  345. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
  346. }
  347. #endif
  348. #if !SDL_VIDEO_DISABLED
  349. if ((flags & SDL_INIT_VIDEO)) {
  350. /* video implies events */
  351. flags |= SDL_INIT_EVENTS;
  352. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
  353. SDL_VideoQuit();
  354. }
  355. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
  356. }
  357. #endif
  358. #if !SDL_TIMERS_DISABLED && !SDL_TIMER_DUMMY
  359. if ((flags & SDL_INIT_TIMER)) {
  360. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
  361. SDL_TimerQuit();
  362. }
  363. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
  364. }
  365. #endif
  366. #if !SDL_EVENTS_DISABLED
  367. if ((flags & SDL_INIT_EVENTS)) {
  368. if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
  369. SDL_EventsQuit();
  370. }
  371. SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
  372. }
  373. #endif
  374. }
  375. Uint32
  376. SDL_WasInit(Uint32 flags)
  377. {
  378. int i;
  379. int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
  380. Uint32 initialized = 0;
  381. /* Fast path for checking one flag */
  382. if (SDL_HasExactlyOneBitSet32(flags)) {
  383. int subsystem_index = SDL_MostSignificantBitIndex32(flags);
  384. return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
  385. }
  386. if (!flags) {
  387. flags = SDL_INIT_EVERYTHING;
  388. }
  389. num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
  390. /* Iterate over each bit in flags, and check the matching subsystem. */
  391. for (i = 0; i < num_subsystems; ++i) {
  392. if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
  393. initialized |= (1 << i);
  394. }
  395. flags >>= 1;
  396. }
  397. return initialized;
  398. }
  399. void
  400. SDL_Quit(void)
  401. {
  402. SDL_bInMainQuit = SDL_TRUE;
  403. /* Quit all subsystems */
  404. #if SDL_VIDEO_DRIVER_WINDOWS
  405. SDL_HelperWindowDestroy();
  406. #endif
  407. SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
  408. #if !SDL_TIMERS_DISABLED
  409. SDL_TicksQuit();
  410. #endif
  411. SDL_ClearHints();
  412. SDL_AssertionsQuit();
  413. #if SDL_USE_LIBDBUS
  414. SDL_DBus_Quit();
  415. #endif
  416. SDL_LogQuit();
  417. /* Now that every subsystem has been quit, we reset the subsystem refcount
  418. * and the list of initialized subsystems.
  419. */
  420. SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
  421. SDL_TLSCleanup();
  422. SDL_bInMainQuit = SDL_FALSE;
  423. }
  424. /* Get the library version number */
  425. void
  426. SDL_GetVersion(SDL_version * ver)
  427. {
  428. static SDL_bool check_hint = SDL_TRUE;
  429. static SDL_bool legacy_version = SDL_FALSE;
  430. if (ver == NULL) { return;
  431. }
  432. SDL_VERSION(ver);
  433. if (check_hint) {
  434. check_hint = SDL_FALSE;
  435. legacy_version = SDL_GetHintBoolean("SDL_LEGACY_VERSION", SDL_FALSE);
  436. }
  437. if (legacy_version) {
  438. /* Prior to SDL 2.24.0, the patch version was incremented with every release */
  439. ver->patch = ver->minor;
  440. ver->minor = 0;
  441. }
  442. }
  443. /* Get the library source revision */
  444. const char *
  445. SDL_GetRevision(void)
  446. {
  447. return SDL_REVISION;
  448. }
  449. /* Get the name of the platform */
  450. const char *
  451. SDL_GetPlatform(void)
  452. {
  453. #if defined(__AIX__)
  454. return "AIX";
  455. #elif defined(__ANDROID__)
  456. return "Android";
  457. #elif defined(__BSDI__)
  458. return "BSDI";
  459. #elif defined(__DREAMCAST__)
  460. return "Dreamcast";
  461. #elif defined(__EMSCRIPTEN__)
  462. return "Emscripten";
  463. #elif defined(__FREEBSD__)
  464. return "FreeBSD";
  465. #elif defined(__HAIKU__)
  466. return "Haiku";
  467. #elif defined(__HPUX__)
  468. return "HP-UX";
  469. #elif defined(__IRIX__)
  470. return "Irix";
  471. #elif defined(__LINUX__)
  472. return "Linux";
  473. #elif defined(__MINT__)
  474. return "Atari MiNT";
  475. #elif defined(__MACOS__)
  476. return "macOS";
  477. #elif defined(__NACL__)
  478. return "NaCl";
  479. #elif defined(__NETBSD__)
  480. return "NetBSD";
  481. #elif defined(__OPENBSD__)
  482. return "OpenBSD";
  483. #elif defined(__OS2__)
  484. return "OS/2";
  485. #elif defined(__OSF__)
  486. return "OSF/1";
  487. #elif defined(__QNXNTO__)
  488. return "QNX Neutrino";
  489. #elif defined(__RISCOS__)
  490. return "RISC OS";
  491. #elif defined(__SOLARIS__)
  492. return "Solaris";
  493. #elif defined(__WIN32__)
  494. return "Windows";
  495. #elif defined(__WINRT__)
  496. return "WinRT";
  497. #elif defined(__WINGDK__)
  498. return "WinGDK";
  499. #elif defined(__XBOXONE__)
  500. return "Xbox One";
  501. #elif defined(__XBOXSERIES__)
  502. return "Xbox Series X|S";
  503. #elif defined(__IOS__)
  504. return "iOS";
  505. #elif defined(__TVOS__)
  506. return "tvOS";
  507. #elif defined(__PS2__)
  508. return "PlayStation 2";
  509. #elif defined(__PSP__)
  510. return "PlayStation Portable";
  511. #elif defined(__VITA__)
  512. return "PlayStation Vita";
  513. #elif defined(__NGAGE__)
  514. return "Nokia N-Gage";
  515. #elif defined(__3DS__)
  516. return "Nintendo 3DS";
  517. #else
  518. return "Unknown (see SDL_platform.h)";
  519. #endif
  520. }
  521. SDL_bool
  522. SDL_IsTablet(void)
  523. {
  524. #if __ANDROID__
  525. extern SDL_bool SDL_IsAndroidTablet(void);
  526. return SDL_IsAndroidTablet();
  527. #elif __IOS__
  528. extern SDL_bool SDL_IsIPad(void);
  529. return SDL_IsIPad();
  530. #else
  531. return SDL_FALSE;
  532. #endif
  533. }
  534. #if defined(__WIN32__)
  535. #if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
  536. /* Need to include DllMain() on Watcom C for some reason.. */
  537. BOOL APIENTRY
  538. _DllMainCRTStartup(HANDLE hModule,
  539. DWORD ul_reason_for_call, LPVOID lpReserved)
  540. {
  541. switch (ul_reason_for_call) {
  542. case DLL_PROCESS_ATTACH:
  543. case DLL_THREAD_ATTACH:
  544. case DLL_THREAD_DETACH:
  545. case DLL_PROCESS_DETACH:
  546. break;
  547. }
  548. return TRUE;
  549. }
  550. #endif /* Building DLL */
  551. #endif /* defined(__WIN32__) || defined(__GDK__) */
  552. /* vi: set sts=4 ts=4 sw=4 expandtab: */