SDL_system.h 16 KB

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