SDL.c 17 KB

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