🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

575 lines
19 KiB

  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. /**
  19. * \file SDL_system.h
  20. *
  21. * Include file for platform specific SDL API functions
  22. */
  23. #ifndef SDL_system_h_
  24. #define SDL_system_h_
  25. #include "SDL_stdinc.h"
  26. #include "SDL_keyboard.h"
  27. #include "SDL_render.h"
  28. #include "SDL_video.h"
  29. #include "begin_code.h"
  30. /* Set up for C function definitions, even when using C++ */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Platform specific functions for Windows */
  35. #ifdef __WIN32__
  36. typedef void (SDLCALL * SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
  37. /**
  38. * Set a callback for every Windows message, run before TranslateMessage().
  39. *
  40. * \param callback The SDL_WindowsMessageHook function to call.
  41. * \param userdata a pointer to pass to every iteration of `callback`
  42. *
  43. * \since This function is available since SDL 2.0.4.
  44. */
  45. extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);
  46. /**
  47. * Get the D3D9 adapter index that matches the specified display index.
  48. *
  49. * The returned adapter index can be passed to `IDirect3D9::CreateDevice` and
  50. * controls on which monitor a full screen application will appear.
  51. *
  52. * \param displayIndex the display index for which to get the D3D9 adapter
  53. * index
  54. * \returns the D3D9 adapter index on success or a negative error code on
  55. * failure; call SDL_GetError() for more information.
  56. *
  57. * \since This function is available since SDL 2.0.1.
  58. */
  59. extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
  60. typedef struct IDirect3DDevice9 IDirect3DDevice9;
  61. /**
  62. * Get the D3D9 device associated with a renderer.
  63. *
  64. * Once you are done using the device, you should release it to avoid a
  65. * resource leak.
  66. *
  67. * \param renderer the renderer from which to get the associated D3D device
  68. * \returns the D3D9 device associated with given renderer or NULL if it is
  69. * not a D3D9 renderer; call SDL_GetError() for more information.
  70. *
  71. * \since This function is available since SDL 2.0.1.
  72. */
  73. extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
  74. typedef struct ID3D11Device ID3D11Device;
  75. /**
  76. * Get the D3D11 device associated with a renderer.
  77. *
  78. * Once you are done using the device, you should release it to avoid a
  79. * resource leak.
  80. *
  81. * \param renderer the renderer from which to get the associated D3D11 device
  82. * \returns the D3D11 device associated with given renderer or NULL if it is
  83. * not a D3D11 renderer; call SDL_GetError() for more information.
  84. *
  85. * \since This function is available since SDL 2.0.16.
  86. */
  87. extern DECLSPEC ID3D11Device* SDLCALL SDL_RenderGetD3D11Device(SDL_Renderer * renderer);
  88. /**
  89. * Get the DXGI Adapter and Output indices for the specified display index.
  90. *
  91. * The DXGI Adapter and Output indices can be passed to `EnumAdapters` and
  92. * `EnumOutputs` respectively to get the objects required to create a DX10 or
  93. * DX11 device and swap chain.
  94. *
  95. * Before SDL 2.0.4 this function did not return a value. Since SDL 2.0.4 it
  96. * returns an SDL_bool.
  97. *
  98. * \param displayIndex the display index for which to get both indices
  99. * \param adapterIndex a pointer to be filled in with the adapter index
  100. * \param outputIndex a pointer to be filled in with the output index
  101. * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError()
  102. * for more information.
  103. *
  104. * \since This function is available since SDL 2.0.2.
  105. */
  106. extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
  107. #endif /* __WIN32__ */
  108. /* Platform specific functions for Linux */
  109. #ifdef __LINUX__
  110. /**
  111. * Sets the UNIX nice value for a thread.
  112. *
  113. * This uses setpriority() if possible, and RealtimeKit if available.
  114. *
  115. * \param threadID the Unix thread ID to change priority of.
  116. * \param priority The new, Unix-specific, priority value.
  117. * \returns 0 on success, or -1 on error.
  118. *
  119. * \since This function is available since SDL 2.0.9.
  120. */
  121. extern DECLSPEC int SDLCALL SDL_LinuxSetThreadPriority(Sint64 threadID, int priority);
  122. /**
  123. * Sets the priority (not nice level) and scheduling policy for a thread.
  124. *
  125. * This uses setpriority() if possible, and RealtimeKit if available.
  126. *
  127. * \param threadID The Unix thread ID to change priority of.
  128. * \param sdlPriority The new SDL_ThreadPriority value.
  129. * \param schedPolicy The new scheduling policy (SCHED_FIFO, SCHED_RR,
  130. * SCHED_OTHER, etc...)
  131. * \returns 0 on success, or -1 on error.
  132. *
  133. * \since This function is available since SDL 2.0.18.
  134. */
  135. extern DECLSPEC int SDLCALL SDL_LinuxSetThreadPriorityAndPolicy(Sint64 threadID, int sdlPriority, int schedPolicy);
  136. #endif /* __LINUX__ */
  137. /* Platform specific functions for iOS */
  138. #ifdef __IPHONEOS__
  139. #define SDL_iOSSetAnimationCallback(window, interval, callback, callbackParam) SDL_iPhoneSetAnimationCallback(window, interval, callback, callbackParam)
  140. /**
  141. * Use this function to set the animation callback on Apple iOS.
  142. *
  143. * The function prototype for `callback` is:
  144. *
  145. * ```c
  146. * void callback(void* callbackParam);
  147. * ```
  148. *
  149. * Where its parameter, `callbackParam`, is what was passed as `callbackParam`
  150. * to SDL_iPhoneSetAnimationCallback().
  151. *
  152. * This function is only available on Apple iOS.
  153. *
  154. * For more information see:
  155. * [README-ios.md](https://hg.libsdl.org/SDL/file/default/docs/README-ios.md)
  156. *
  157. * This functions is also accessible using the macro
  158. * SDL_iOSSetAnimationCallback() since SDL 2.0.4.
  159. *
  160. * \param window the window for which the animation callback should be set
  161. * \param interval the number of frames after which **callback** will be
  162. * called
  163. * \param callback the function to call for every frame.
  164. * \param callbackParam a pointer that is passed to `callback`.
  165. * \returns 0 on success or a negative error code on failure; call
  166. * SDL_GetError() for more information.
  167. *
  168. * \since This function is available since SDL 2.0.0.
  169. *
  170. * \sa SDL_iPhoneSetEventPump
  171. */
  172. extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
  173. #define SDL_iOSSetEventPump(enabled) SDL_iPhoneSetEventPump(enabled)
  174. /**
  175. * Use this function to enable or disable the SDL event pump on Apple iOS.
  176. *
  177. * This function is only available on Apple iOS.
  178. *
  179. * This functions is also accessible using the macro SDL_iOSSetEventPump()
  180. * since SDL 2.0.4.
  181. *
  182. * \param enabled SDL_TRUE to enable the event pump, SDL_FALSE to disable it
  183. *
  184. * \since This function is available since SDL 2.0.0.
  185. *
  186. * \sa SDL_iPhoneSetAnimationCallback
  187. */
  188. extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
  189. #endif /* __IPHONEOS__ */
  190. /* Platform specific functions for Android */
  191. #ifdef __ANDROID__
  192. /**
  193. * Get the Android Java Native Interface Environment of the current thread.
  194. *
  195. * This is the JNIEnv one needs to access the Java virtual machine from native
  196. * code, and is needed for many Android APIs to be usable from C.
  197. *
  198. * The prototype of the function in SDL's code actually declare a void* return
  199. * type, even if the implementation returns a pointer to a JNIEnv. The
  200. * rationale being that the SDL headers can avoid including jni.h.
  201. *
  202. * \returns a pointer to Java native interface object (JNIEnv) to which the
  203. * current thread is attached, or 0 on error.
  204. *
  205. * \since This function is available since SDL 2.0.0.
  206. *
  207. * \sa SDL_AndroidGetActivity
  208. */
  209. extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(void);
  210. /**
  211. * Retrieve the Java instance of the Android activity class.
  212. *
  213. * The prototype of the function in SDL's code actually declares a void*
  214. * return type, even if the implementation returns a jobject. The rationale
  215. * being that the SDL headers can avoid including jni.h.
  216. *
  217. * The jobject returned by the function is a local reference and must be
  218. * released by the caller. See the PushLocalFrame() and PopLocalFrame() or
  219. * DeleteLocalRef() functions of the Java native interface:
  220. *
  221. * https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html
  222. *
  223. * \returns the jobject representing the instance of the Activity class of the
  224. * Android application, or NULL on error.
  225. *
  226. * \since This function is available since SDL 2.0.0.
  227. *
  228. * \sa SDL_AndroidGetJNIEnv
  229. */
  230. extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void);
  231. /**
  232. * Query Android API level of the current device.
  233. *
  234. * - API level 31: Android 12
  235. * - API level 30: Android 11
  236. * - API level 29: Android 10
  237. * - API level 28: Android 9
  238. * - API level 27: Android 8.1
  239. * - API level 26: Android 8.0
  240. * - API level 25: Android 7.1
  241. * - API level 24: Android 7.0
  242. * - API level 23: Android 6.0
  243. * - API level 22: Android 5.1
  244. * - API level 21: Android 5.0
  245. * - API level 20: Android 4.4W
  246. * - API level 19: Android 4.4
  247. * - API level 18: Android 4.3
  248. * - API level 17: Android 4.2
  249. * - API level 16: Android 4.1
  250. * - API level 15: Android 4.0.3
  251. * - API level 14: Android 4.0
  252. * - API level 13: Android 3.2
  253. * - API level 12: Android 3.1
  254. * - API level 11: Android 3.0
  255. * - API level 10: Android 2.3.3
  256. *
  257. * \returns the Android API level.
  258. *
  259. * \since This function is available since SDL 2.0.12.
  260. */
  261. extern DECLSPEC int SDLCALL SDL_GetAndroidSDKVersion(void);
  262. /**
  263. * Query if the application is running on Android TV.
  264. *
  265. * \returns SDL_TRUE if this is Android TV, SDL_FALSE otherwise.
  266. *
  267. * \since This function is available since SDL 2.0.8.
  268. */
  269. extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
  270. /**
  271. * Query if the application is running on a Chromebook.
  272. *
  273. * \returns SDL_TRUE if this is a Chromebook, SDL_FALSE otherwise.
  274. *
  275. * \since This function is available since SDL 2.0.9.
  276. */
  277. extern DECLSPEC SDL_bool SDLCALL SDL_IsChromebook(void);
  278. /**
  279. * Query if the application is running on a Samsung DeX docking station.
  280. *
  281. * \returns SDL_TRUE if this is a DeX docking station, SDL_FALSE otherwise.
  282. *
  283. * \since This function is available since SDL 2.0.9.
  284. */
  285. extern DECLSPEC SDL_bool SDLCALL SDL_IsDeXMode(void);
  286. /**
  287. * Trigger the Android system back button behavior.
  288. *
  289. * \since This function is available since SDL 2.0.9.
  290. */
  291. extern DECLSPEC void SDLCALL SDL_AndroidBackButton(void);
  292. /**
  293. See the official Android developer guide for more information:
  294. http://developer.android.com/guide/topics/data/data-storage.html
  295. */
  296. #define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
  297. #define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
  298. /**
  299. * Get the path used for internal storage for this application.
  300. *
  301. * This path is unique to your application and cannot be written to by other
  302. * applications.
  303. *
  304. * Your internal storage path is typically:
  305. * `/data/data/your.app.package/files`.
  306. *
  307. * \returns the path used for internal storage or NULL on failure; call
  308. * SDL_GetError() for more information.
  309. *
  310. * \since This function is available since SDL 2.0.0.
  311. *
  312. * \sa SDL_AndroidGetExternalStorageState
  313. */
  314. extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath(void);
  315. /**
  316. * Get the current state of external storage.
  317. *
  318. * The current state of external storage, a bitmask of these values:
  319. * `SDL_ANDROID_EXTERNAL_STORAGE_READ`, `SDL_ANDROID_EXTERNAL_STORAGE_WRITE`.
  320. *
  321. * If external storage is currently unavailable, this will return 0.
  322. *
  323. * \returns the current state of external storage on success or 0 on failure;
  324. * call SDL_GetError() for more information.
  325. *
  326. * \since This function is available since SDL 2.0.0.
  327. *
  328. * \sa SDL_AndroidGetExternalStoragePath
  329. */
  330. extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState(void);
  331. /**
  332. * Get the path used for external storage for this application.
  333. *
  334. * This path is unique to your application, but is public and can be written
  335. * to by other applications.
  336. *
  337. * Your external storage path is typically:
  338. * `/storage/sdcard0/Android/data/your.app.package/files`.
  339. *
  340. * \returns the path used for external storage for this application on success
  341. * or NULL on failure; call SDL_GetError() for more information.
  342. *
  343. * \since This function is available since SDL 2.0.0.
  344. *
  345. * \sa SDL_AndroidGetExternalStorageState
  346. */
  347. extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
  348. /**
  349. * Request permissions at runtime.
  350. *
  351. * This blocks the calling thread until the permission is granted or denied.
  352. *
  353. * \param permission The permission to request.
  354. * \returns SDL_TRUE if the permission was granted, SDL_FALSE otherwise.
  355. *
  356. * \since This function is available since SDL 2.0.14.
  357. */
  358. extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permission);
  359. /**
  360. * Shows an Android toast notification.
  361. *
  362. * Toasts are a sort of lightweight notification that are unique to Android.
  363. *
  364. * https://developer.android.com/guide/topics/ui/notifiers/toasts
  365. *
  366. * Shows toast in UI thread.
  367. *
  368. * For the `gravity` parameter, choose a value from here, or -1 if you don't
  369. * have a preference:
  370. *
  371. * https://developer.android.com/reference/android/view/Gravity
  372. *
  373. * \param message text message to be shown
  374. * \param duration 0=short, 1=long
  375. * \param gravity where the notification should appear on the screen.
  376. * \param xoffset set this parameter only when gravity >=0
  377. * \param yoffset set this parameter only when gravity >=0
  378. * \returns 0 if success, -1 if any error occurs.
  379. *
  380. * \since This function is available since SDL 2.0.16.
  381. */
  382. extern DECLSPEC int SDLCALL SDL_AndroidShowToast(const char* message, int duration, int gravity, int xoffset, int yoffset);
  383. /**
  384. * Send a user command to SDLActivity.
  385. *
  386. * Override "boolean onUnhandledMessage(Message msg)" to handle the message.
  387. *
  388. * \param command user command that must be greater or equal to 0x8000
  389. * \param param user parameter
  390. *
  391. * \since This function is available since SDL 2.0.22.
  392. */
  393. extern DECLSPEC int SDLCALL SDL_AndroidSendMessage(Uint32 command, int param);
  394. #endif /* __ANDROID__ */
  395. /* Platform specific functions for WinRT */
  396. #ifdef __WINRT__
  397. /**
  398. * \brief WinRT / Windows Phone path types
  399. */
  400. typedef enum
  401. {
  402. /** \brief The installed app's root directory.
  403. Files here are likely to be read-only. */
  404. SDL_WINRT_PATH_INSTALLED_LOCATION,
  405. /** \brief The app's local data store. Files may be written here */
  406. SDL_WINRT_PATH_LOCAL_FOLDER,
  407. /** \brief The app's roaming data store. Unsupported on Windows Phone.
  408. Files written here may be copied to other machines via a network
  409. connection.
  410. */
  411. SDL_WINRT_PATH_ROAMING_FOLDER,
  412. /** \brief The app's temporary data store. Unsupported on Windows Phone.
  413. Files written here may be deleted at any time. */
  414. SDL_WINRT_PATH_TEMP_FOLDER
  415. } SDL_WinRT_Path;
  416. /**
  417. * \brief WinRT Device Family
  418. */
  419. typedef enum
  420. {
  421. /** \brief Unknown family */
  422. SDL_WINRT_DEVICEFAMILY_UNKNOWN,
  423. /** \brief Desktop family*/
  424. SDL_WINRT_DEVICEFAMILY_DESKTOP,
  425. /** \brief Mobile family (for example smartphone) */
  426. SDL_WINRT_DEVICEFAMILY_MOBILE,
  427. /** \brief XBox family */
  428. SDL_WINRT_DEVICEFAMILY_XBOX,
  429. } SDL_WinRT_DeviceFamily;
  430. /**
  431. * Retrieve a WinRT defined path on the local file system.
  432. *
  433. * Not all paths are available on all versions of Windows. This is especially
  434. * true on Windows Phone. Check the documentation for the given SDL_WinRT_Path
  435. * for more information on which path types are supported where.
  436. *
  437. * Documentation on most app-specific path types on WinRT can be found on
  438. * MSDN, at the URL:
  439. *
  440. * https://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
  441. *
  442. * \param pathType the type of path to retrieve, one of SDL_WinRT_Path
  443. * \returns a UCS-2 string (16-bit, wide-char) containing the path, or NULL if
  444. * the path is not available for any reason; call SDL_GetError() for
  445. * more information.
  446. *
  447. * \since This function is available since SDL 2.0.3.
  448. *
  449. * \sa SDL_WinRTGetFSPathUTF8
  450. */
  451. extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
  452. /**
  453. * Retrieve a WinRT defined path on the local file system.
  454. *
  455. * Not all paths are available on all versions of Windows. This is especially
  456. * true on Windows Phone. Check the documentation for the given SDL_WinRT_Path
  457. * for more information on which path types are supported where.
  458. *
  459. * Documentation on most app-specific path types on WinRT can be found on
  460. * MSDN, at the URL:
  461. *
  462. * https://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
  463. *
  464. * \param pathType the type of path to retrieve, one of SDL_WinRT_Path
  465. * \returns a UTF-8 string (8-bit, multi-byte) containing the path, or NULL if
  466. * the path is not available for any reason; call SDL_GetError() for
  467. * more information.
  468. *
  469. * \since This function is available since SDL 2.0.3.
  470. *
  471. * \sa SDL_WinRTGetFSPathUNICODE
  472. */
  473. extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
  474. /**
  475. * Detects the device family of WinRT plattform at runtime.
  476. *
  477. * \returns a value from the SDL_WinRT_DeviceFamily enum.
  478. *
  479. * \since This function is available since SDL 2.0.8.
  480. */
  481. extern DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_WinRTGetDeviceFamily();
  482. #endif /* __WINRT__ */
  483. /**
  484. * Query if the current device is a tablet.
  485. *
  486. * If SDL can't determine this, it will return SDL_FALSE.
  487. *
  488. * \returns SDL_TRUE if the device is a tablet, SDL_FALSE otherwise.
  489. *
  490. * \since This function is available since SDL 2.0.9.
  491. */
  492. extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
  493. /* Functions used by iOS application delegates to notify SDL about state changes */
  494. extern DECLSPEC void SDLCALL SDL_OnApplicationWillTerminate(void);
  495. extern DECLSPEC void SDLCALL SDL_OnApplicationDidReceiveMemoryWarning(void);
  496. extern DECLSPEC void SDLCALL SDL_OnApplicationWillResignActive(void);
  497. extern DECLSPEC void SDLCALL SDL_OnApplicationDidEnterBackground(void);
  498. extern DECLSPEC void SDLCALL SDL_OnApplicationWillEnterForeground(void);
  499. extern DECLSPEC void SDLCALL SDL_OnApplicationDidBecomeActive(void);
  500. #ifdef __IPHONEOS__
  501. extern DECLSPEC void SDLCALL SDL_OnApplicationDidChangeStatusBarOrientation(void);
  502. #endif
  503. /* Ends C function definitions when using C++ */
  504. #ifdef __cplusplus
  505. }
  506. #endif
  507. #include "close_code.h"
  508. #endif /* SDL_system_h_ */
  509. /* vi: set ts=4 sw=4 expandtab: */