SDL_system.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2021 Sam Lantinga <[email protected]>
  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. #endif /* __LINUX__ */
  123. /* Platform specific functions for iOS */
  124. #ifdef __IPHONEOS__
  125. #define SDL_iOSSetAnimationCallback(window, interval, callback, callbackParam) SDL_iPhoneSetAnimationCallback(window, interval, callback, callbackParam)
  126. /**
  127. * Use this function to set the animation callback on Apple iOS.
  128. *
  129. * The function prototype for `callback` is:
  130. *
  131. * ```c
  132. * void callback(void* callbackParam);
  133. * ```
  134. *
  135. * Where its parameter, `callbackParam`, is what was passed as `callbackParam`
  136. * to SDL_iPhoneSetAnimationCallback().
  137. *
  138. * This function is only available on Apple iOS.
  139. *
  140. * For more information see:
  141. * [README-ios.md](https://hg.libsdl.org/SDL/file/default/docs/README-ios.md)
  142. *
  143. * This functions is also accessible using the macro
  144. * SDL_iOSSetAnimationCallback() since SDL 2.0.4.
  145. *
  146. * \param window the window for which the animation callback should be set
  147. * \param interval the number of frames after which **callback** will be
  148. * called
  149. * \param callback the function to call for every frame.
  150. * \param callbackParam a pointer that is passed to `callback`.
  151. * \returns 0 on success or a negative error code on failure; call
  152. * SDL_GetError() for more information.
  153. *
  154. * \since This function is available since SDL 2.0.0.
  155. *
  156. * \sa SDL_iPhoneSetEventPump
  157. */
  158. extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
  159. #define SDL_iOSSetEventPump(enabled) SDL_iPhoneSetEventPump(enabled)
  160. /**
  161. * Use this function to enable or disable the SDL event pump on Apple iOS.
  162. *
  163. * This function is only available on Apple iOS.
  164. *
  165. * This functions is also accessible using the macro SDL_iOSSetEventPump()
  166. * since SDL 2.0.4.
  167. *
  168. * \param enabled SDL_TRUE to enable the event pump, SDL_FALSE to disable it
  169. *
  170. * \since This function is available since SDL 2.0.0.
  171. *
  172. * \sa SDL_iPhoneSetAnimationCallback
  173. */
  174. extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
  175. #endif /* __IPHONEOS__ */
  176. /* Platform specific functions for Android */
  177. #ifdef __ANDROID__
  178. /**
  179. * Get the Android Java Native Interface Environment of the current thread.
  180. *
  181. * This is the JNIEnv one needs to access the Java virtual machine from native
  182. * code, and is needed for many Android APIs to be usable from C.
  183. *
  184. * The prototype of the function in SDL's code actually declare a void* return
  185. * type, even if the implementation returns a pointer to a JNIEnv. The
  186. * rationale being that the SDL headers can avoid including jni.h.
  187. *
  188. * \returns a pointer to Java native interface object (JNIEnv) to which the
  189. * current thread is attached, or 0 on error.
  190. *
  191. * \since This function is available since SDL 2.0.0.
  192. *
  193. * \sa SDL_AndroidGetActivity
  194. */
  195. extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(void);
  196. /**
  197. * Retrieve the Java instance of the Android activity class.
  198. *
  199. * The prototype of the function in SDL's code actually declares a void*
  200. * return type, even if the implementation returns a jobject. The rationale
  201. * being that the SDL headers can avoid including jni.h.
  202. *
  203. * The jobject returned by the function is a local reference and must be
  204. * released by the caller. See the PushLocalFrame() and PopLocalFrame() or
  205. * DeleteLocalRef() functions of the Java native interface:
  206. *
  207. * https://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/functions.html
  208. *
  209. * \returns the jobject representing the instance of the Activity class of the
  210. * Android application, or NULL on error.
  211. *
  212. * \since This function is available since SDL 2.0.0.
  213. *
  214. * \sa SDL_AndroidGetJNIEnv
  215. */
  216. extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void);
  217. /**
  218. * Query Android API level of the current device.
  219. *
  220. * - API level 30: Android 11
  221. * - API level 29: Android 10
  222. * - API level 28: Android 9
  223. * - API level 27: Android 8.1
  224. * - API level 26: Android 8.0
  225. * - API level 25: Android 7.1
  226. * - API level 24: Android 7.0
  227. * - API level 23: Android 6.0
  228. * - API level 22: Android 5.1
  229. * - API level 21: Android 5.0
  230. * - API level 20: Android 4.4W
  231. * - API level 19: Android 4.4
  232. * - API level 18: Android 4.3
  233. * - API level 17: Android 4.2
  234. * - API level 16: Android 4.1
  235. * - API level 15: Android 4.0.3
  236. * - API level 14: Android 4.0
  237. * - API level 13: Android 3.2
  238. * - API level 12: Android 3.1
  239. * - API level 11: Android 3.0
  240. * - API level 10: Android 2.3.3
  241. *
  242. * \returns the Android API level.
  243. *
  244. * \since This function is available since SDL 2.0.12.
  245. */
  246. extern DECLSPEC int SDLCALL SDL_GetAndroidSDKVersion(void);
  247. /**
  248. * Query if the application is running on Android TV.
  249. *
  250. * \returns SDL_TRUE if this is Android TV, SDL_FALSE otherwise.
  251. *
  252. * \since This function is available since SDL 2.0.8.
  253. */
  254. extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
  255. /**
  256. * Query if the application is running on a Chromebook.
  257. *
  258. * \returns SDL_TRUE if this is a Chromebook, SDL_FALSE otherwise.
  259. *
  260. * \since This function is available since SDL 2.0.9.
  261. */
  262. extern DECLSPEC SDL_bool SDLCALL SDL_IsChromebook(void);
  263. /**
  264. * Query if the application is running on a Samsung DeX docking station.
  265. *
  266. * \returns SDL_TRUE if this is a DeX docking station, SDL_FALSE otherwise.
  267. *
  268. * \since This function is available since SDL 2.0.9.
  269. */
  270. extern DECLSPEC SDL_bool SDLCALL SDL_IsDeXMode(void);
  271. /**
  272. * Trigger the Android system back button behavior.
  273. *
  274. * \since This function is available since SDL 2.0.9.
  275. */
  276. extern DECLSPEC void SDLCALL SDL_AndroidBackButton(void);
  277. /**
  278. See the official Android developer guide for more information:
  279. http://developer.android.com/guide/topics/data/data-storage.html
  280. */
  281. #define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
  282. #define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
  283. /**
  284. * Get the path used for internal storage for this application.
  285. *
  286. * This path is unique to your application and cannot be written to by other
  287. * applications.
  288. *
  289. * Your internal storage path is typically:
  290. * `/data/data/your.app.package/files`.
  291. *
  292. * \returns the path used for internal storage or NULL on failure; call
  293. * SDL_GetError() for more information.
  294. *
  295. * \since This function is available since SDL 2.0.0.
  296. *
  297. * \sa SDL_AndroidGetExternalStorageState
  298. */
  299. extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath(void);
  300. /**
  301. * Get the current state of external storage.
  302. *
  303. * The current state of external storage, a bitmask of these values:
  304. * `SDL_ANDROID_EXTERNAL_STORAGE_READ`, `SDL_ANDROID_EXTERNAL_STORAGE_WRITE`.
  305. *
  306. * If external storage is currently unavailable, this will return 0.
  307. *
  308. * \returns the current state of external storage on success or 0 on failure;
  309. * call SDL_GetError() for more information.
  310. *
  311. * \since This function is available since SDL 2.0.0.
  312. *
  313. * \sa SDL_AndroidGetExternalStoragePath
  314. */
  315. extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState(void);
  316. /**
  317. * Get the path used for external storage for this application.
  318. *
  319. * This path is unique to your application, but is public and can be written
  320. * to by other applications.
  321. *
  322. * Your external storage path is typically:
  323. * `/storage/sdcard0/Android/data/your.app.package/files`.
  324. *
  325. * \returns the path used for external storage for this application on success
  326. * or NULL on failure; call SDL_GetError() for more information.
  327. *
  328. * \since This function is available since SDL 2.0.0.
  329. *
  330. * \sa SDL_AndroidGetExternalStorageState
  331. */
  332. extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
  333. /**
  334. * Request permissions at runtime.
  335. *
  336. * This blocks the calling thread until the permission is granted or denied.
  337. *
  338. * \param permission The permission to request.
  339. * \returns SDL_TRUE if the permission was granted, SDL_FALSE otherwise.
  340. *
  341. * \since This function is available since SDL 2.0.14.
  342. */
  343. extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permission);
  344. /**
  345. * Shows an Android toast notification.
  346. *
  347. * Toasts are a sort of lightweight notification that are unique to Android.
  348. *
  349. * https://developer.android.com/guide/topics/ui/notifiers/toasts
  350. *
  351. * Shows toast in UI thread.
  352. *
  353. * For the `gravity` parameter, choose a value from here, or -1 if you don't
  354. * have a preference:
  355. *
  356. * https://developer.android.com/reference/android/view/Gravity
  357. *
  358. * \param message text message to be shown
  359. * \param duration 0=short, 1=long
  360. * \param gravity where the notification should appear on the screen.
  361. * \param xoffset set this parameter only when gravity >=0
  362. * \param yoffset set this parameter only when gravity >=0
  363. * \returns 0 if success, -1 if any error occurs.
  364. *
  365. * \since This function is available since SDL 2.0.16.
  366. */
  367. extern DECLSPEC int SDLCALL SDL_AndroidShowToast(const char* message, int duration, int gravity, int xoffset, int yoffset);
  368. #endif /* __ANDROID__ */
  369. /* Platform specific functions for WinRT */
  370. #ifdef __WINRT__
  371. /**
  372. * \brief WinRT / Windows Phone path types
  373. */
  374. typedef enum
  375. {
  376. /** \brief The installed app's root directory.
  377. Files here are likely to be read-only. */
  378. SDL_WINRT_PATH_INSTALLED_LOCATION,
  379. /** \brief The app's local data store. Files may be written here */
  380. SDL_WINRT_PATH_LOCAL_FOLDER,
  381. /** \brief The app's roaming data store. Unsupported on Windows Phone.
  382. Files written here may be copied to other machines via a network
  383. connection.
  384. */
  385. SDL_WINRT_PATH_ROAMING_FOLDER,
  386. /** \brief The app's temporary data store. Unsupported on Windows Phone.
  387. Files written here may be deleted at any time. */
  388. SDL_WINRT_PATH_TEMP_FOLDER
  389. } SDL_WinRT_Path;
  390. /**
  391. * \brief WinRT Device Family
  392. */
  393. typedef enum
  394. {
  395. /** \brief Unknown family */
  396. SDL_WINRT_DEVICEFAMILY_UNKNOWN,
  397. /** \brief Desktop family*/
  398. SDL_WINRT_DEVICEFAMILY_DESKTOP,
  399. /** \brief Mobile family (for example smartphone) */
  400. SDL_WINRT_DEVICEFAMILY_MOBILE,
  401. /** \brief XBox family */
  402. SDL_WINRT_DEVICEFAMILY_XBOX,
  403. } SDL_WinRT_DeviceFamily;
  404. /**
  405. * Retrieve a WinRT defined path on the local file system.
  406. *
  407. * Not all paths are available on all versions of Windows. This is especially
  408. * true on Windows Phone. Check the documentation for the given SDL_WinRT_Path
  409. * for more information on which path types are supported where.
  410. *
  411. * Documentation on most app-specific path types on WinRT can be found on
  412. * MSDN, at the URL:
  413. *
  414. * https://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
  415. *
  416. * \param pathType the type of path to retrieve, one of SDL_WinRT_Path
  417. * \returns a UCS-2 string (16-bit, wide-char) containing the path, or NULL if
  418. * the path is not available for any reason; call SDL_GetError() for
  419. * more information.
  420. *
  421. * \since This function is available since SDL 2.0.3.
  422. *
  423. * \sa SDL_WinRTGetFSPathUTF8
  424. */
  425. extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
  426. /**
  427. * Retrieve a WinRT defined path on the local file system.
  428. *
  429. * Not all paths are available on all versions of Windows. This is especially
  430. * true on Windows Phone. Check the documentation for the given SDL_WinRT_Path
  431. * for more information on which path types are supported where.
  432. *
  433. * Documentation on most app-specific path types on WinRT can be found on
  434. * MSDN, at the URL:
  435. *
  436. * https://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
  437. *
  438. * \param pathType the type of path to retrieve, one of SDL_WinRT_Path
  439. * \returns a UTF-8 string (8-bit, multi-byte) containing the path, or NULL if
  440. * the path is not available for any reason; call SDL_GetError() for
  441. * more information.
  442. *
  443. * \since This function is available since SDL 2.0.3.
  444. *
  445. * \sa SDL_WinRTGetFSPathUNICODE
  446. */
  447. extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
  448. /**
  449. * Detects the device family of WinRT plattform at runtime.
  450. *
  451. * \returns a value from the SDL_WinRT_DeviceFamily enum.
  452. *
  453. * \since This function is available since SDL 2.0.8.
  454. */
  455. extern DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_WinRTGetDeviceFamily();
  456. #endif /* __WINRT__ */
  457. /**
  458. * Query if the current device is a tablet.
  459. *
  460. * If SDL can't determine this, it will return SDL_FALSE.
  461. *
  462. * \returns SDL_TRUE if the device is a tablet, SDL_FALSE otherwise.
  463. *
  464. * \since This function is available since SDL 2.0.9.
  465. */
  466. extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
  467. /* Functions used by iOS application delegates to notify SDL about state changes */
  468. extern DECLSPEC void SDLCALL SDL_OnApplicationWillTerminate(void);
  469. extern DECLSPEC void SDLCALL SDL_OnApplicationDidReceiveMemoryWarning(void);
  470. extern DECLSPEC void SDLCALL SDL_OnApplicationWillResignActive(void);
  471. extern DECLSPEC void SDLCALL SDL_OnApplicationDidEnterBackground(void);
  472. extern DECLSPEC void SDLCALL SDL_OnApplicationWillEnterForeground(void);
  473. extern DECLSPEC void SDLCALL SDL_OnApplicationDidBecomeActive(void);
  474. #ifdef __IPHONEOS__
  475. extern DECLSPEC void SDLCALL SDL_OnApplicationDidChangeStatusBarOrientation(void);
  476. #endif
  477. /* Ends C function definitions when using C++ */
  478. #ifdef __cplusplus
  479. }
  480. #endif
  481. #include "close_code.h"
  482. #endif /* SDL_system_h_ */
  483. /* vi: set ts=4 sw=4 expandtab: */