SDL.c 17 KB

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