SDL.c 17 KB

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