SDL.c 17 KB

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