SDL_system.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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. /**
  37. \brief Set a function that is called for every windows message, before TranslateMessage()
  38. */
  39. typedef void (SDLCALL * SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
  40. extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);
  41. /**
  42. \brief Returns the D3D9 adapter index that matches the specified display index.
  43. This adapter index can be passed to IDirect3D9::CreateDevice and controls
  44. on which monitor a full screen application will appear.
  45. */
  46. extern DECLSPEC int SDLCALL SDL_Direct3D9GetAdapterIndex( int displayIndex );
  47. typedef struct IDirect3DDevice9 IDirect3DDevice9;
  48. /**
  49. \brief Returns the D3D9 device associated with a renderer, or NULL if it's not a D3D9 renderer.
  50. Once you are done using the device, you should release it to avoid a resource leak.
  51. */
  52. extern DECLSPEC IDirect3DDevice9* SDLCALL SDL_RenderGetD3D9Device(SDL_Renderer * renderer);
  53. typedef struct ID3D11Device ID3D11Device;
  54. /**
  55. \brief Returns the D3D11 device associated with a renderer, or NULL if it's not a D3D11 renderer.
  56. Once you are done using the device, you should release it to avoid a resource leak.
  57. */
  58. extern DECLSPEC ID3D11Device* SDLCALL SDL_RenderGetD3D11Device(SDL_Renderer * renderer);
  59. /**
  60. \brief Returns the DXGI Adapter and Output indices for the specified display index.
  61. These can be passed to EnumAdapters and EnumOutputs respectively to get the objects
  62. required to create a DX10 or DX11 device and swap chain.
  63. */
  64. extern DECLSPEC SDL_bool SDLCALL SDL_DXGIGetOutputInfo( int displayIndex, int *adapterIndex, int *outputIndex );
  65. #endif /* __WIN32__ */
  66. /* Platform specific functions for Linux */
  67. #ifdef __LINUX__
  68. /**
  69. \brief Sets the UNIX nice value for a thread, using setpriority() if possible, and RealtimeKit if available.
  70. \return 0 on success, or -1 on error.
  71. */
  72. extern DECLSPEC int SDLCALL SDL_LinuxSetThreadPriority(Sint64 threadID, int priority);
  73. #endif /* __LINUX__ */
  74. /* Platform specific functions for iOS */
  75. #ifdef __IPHONEOS__
  76. #define SDL_iOSSetAnimationCallback(window, interval, callback, callbackParam) SDL_iPhoneSetAnimationCallback(window, interval, callback, callbackParam)
  77. extern DECLSPEC int SDLCALL SDL_iPhoneSetAnimationCallback(SDL_Window * window, int interval, void (*callback)(void*), void *callbackParam);
  78. #define SDL_iOSSetEventPump(enabled) SDL_iPhoneSetEventPump(enabled)
  79. extern DECLSPEC void SDLCALL SDL_iPhoneSetEventPump(SDL_bool enabled);
  80. #endif /* __IPHONEOS__ */
  81. /* Platform specific functions for Android */
  82. #ifdef __ANDROID__
  83. /**
  84. \brief Get the JNI environment for the current thread
  85. This returns JNIEnv*, but the prototype is void* so we don't need jni.h
  86. */
  87. extern DECLSPEC void * SDLCALL SDL_AndroidGetJNIEnv(void);
  88. /**
  89. \brief Get the SDL Activity object for the application
  90. This returns jobject, but the prototype is void* so we don't need jni.h
  91. The jobject returned by SDL_AndroidGetActivity is a local reference.
  92. It is the caller's responsibility to properly release it
  93. (using env->Push/PopLocalFrame or manually with env->DeleteLocalRef)
  94. */
  95. extern DECLSPEC void * SDLCALL SDL_AndroidGetActivity(void);
  96. /**
  97. \brief Return API level of the current device
  98. API level 30: Android 11
  99. API level 29: Android 10
  100. API level 28: Android 9
  101. API level 27: Android 8.1
  102. API level 26: Android 8.0
  103. API level 25: Android 7.1
  104. API level 24: Android 7.0
  105. API level 23: Android 6.0
  106. API level 22: Android 5.1
  107. API level 21: Android 5.0
  108. API level 20: Android 4.4W
  109. API level 19: Android 4.4
  110. API level 18: Android 4.3
  111. API level 17: Android 4.2
  112. API level 16: Android 4.1
  113. API level 15: Android 4.0.3
  114. API level 14: Android 4.0
  115. API level 13: Android 3.2
  116. API level 12: Android 3.1
  117. API level 11: Android 3.0
  118. API level 10: Android 2.3.3
  119. */
  120. extern DECLSPEC int SDLCALL SDL_GetAndroidSDKVersion(void);
  121. /**
  122. \brief Return true if the application is running on Android TV
  123. */
  124. extern DECLSPEC SDL_bool SDLCALL SDL_IsAndroidTV(void);
  125. /**
  126. \brief Return true if the application is running on a Chromebook
  127. */
  128. extern DECLSPEC SDL_bool SDLCALL SDL_IsChromebook(void);
  129. /**
  130. \brief Return true is the application is running on a Samsung DeX docking station
  131. */
  132. extern DECLSPEC SDL_bool SDLCALL SDL_IsDeXMode(void);
  133. /**
  134. \brief Trigger the Android system back button behavior.
  135. */
  136. extern DECLSPEC void SDLCALL SDL_AndroidBackButton(void);
  137. /**
  138. See the official Android developer guide for more information:
  139. http://developer.android.com/guide/topics/data/data-storage.html
  140. */
  141. #define SDL_ANDROID_EXTERNAL_STORAGE_READ 0x01
  142. #define SDL_ANDROID_EXTERNAL_STORAGE_WRITE 0x02
  143. /**
  144. \brief Get the path used for internal storage for this application.
  145. This path is unique to your application and cannot be written to
  146. by other applications.
  147. */
  148. extern DECLSPEC const char * SDLCALL SDL_AndroidGetInternalStoragePath(void);
  149. /**
  150. \brief Get the current state of external storage, a bitmask of these values:
  151. SDL_ANDROID_EXTERNAL_STORAGE_READ
  152. SDL_ANDROID_EXTERNAL_STORAGE_WRITE
  153. If external storage is currently unavailable, this will return 0.
  154. */
  155. extern DECLSPEC int SDLCALL SDL_AndroidGetExternalStorageState(void);
  156. /**
  157. \brief Get the path used for external storage for this application.
  158. This path is unique to your application, but is public and can be
  159. written to by other applications.
  160. */
  161. extern DECLSPEC const char * SDLCALL SDL_AndroidGetExternalStoragePath(void);
  162. /**
  163. \brief Request permissions at runtime.
  164. This blocks the calling thread until the permission is granted or
  165. denied. Returns SDL_TRUE if the permission was granted.
  166. */
  167. extern DECLSPEC SDL_bool SDLCALL SDL_AndroidRequestPermission(const char *permission);
  168. /**
  169. \brief Shows android toast notification
  170. \note Shows toast in UI thread [https://developer.android.com/guide/topics/ui/notifiers/toasts]
  171. \param message : text message to be shown
  172. duration : 0 - short [https://developer.android.com/reference/android/widget/Toast#LENGTH_SHORT],
  173. 1 - long [https://developer.android.com/reference/android/widget/Toast#LENGTH_LONG]
  174. gravity : the location at which the notification should appear on the screen.
  175. It's an optional parameter. Set -1 if you don't want specify any gravity or
  176. choose some value from https://developer.android.com/reference/android/view/Gravity
  177. xOffset : set this parameter only when gravity >=0
  178. yOffset : set this parameter only when gravity >=0
  179. \return 0 if success, -1 if any error occurs.
  180. */
  181. extern DECLSPEC int SDLCALL SDL_AndroidShowToast(const char* message, int duration, int gravity, int xOffset, int yOffset);
  182. #endif /* __ANDROID__ */
  183. /* Platform specific functions for WinRT */
  184. #ifdef __WINRT__
  185. /**
  186. * \brief WinRT / Windows Phone path types
  187. */
  188. typedef enum
  189. {
  190. /** \brief The installed app's root directory.
  191. Files here are likely to be read-only. */
  192. SDL_WINRT_PATH_INSTALLED_LOCATION,
  193. /** \brief The app's local data store. Files may be written here */
  194. SDL_WINRT_PATH_LOCAL_FOLDER,
  195. /** \brief The app's roaming data store. Unsupported on Windows Phone.
  196. Files written here may be copied to other machines via a network
  197. connection.
  198. */
  199. SDL_WINRT_PATH_ROAMING_FOLDER,
  200. /** \brief The app's temporary data store. Unsupported on Windows Phone.
  201. Files written here may be deleted at any time. */
  202. SDL_WINRT_PATH_TEMP_FOLDER
  203. } SDL_WinRT_Path;
  204. /**
  205. * \brief WinRT Device Family
  206. */
  207. typedef enum
  208. {
  209. /** \brief Unknown family */
  210. SDL_WINRT_DEVICEFAMILY_UNKNOWN,
  211. /** \brief Desktop family*/
  212. SDL_WINRT_DEVICEFAMILY_DESKTOP,
  213. /** \brief Mobile family (for example smartphone) */
  214. SDL_WINRT_DEVICEFAMILY_MOBILE,
  215. /** \brief XBox family */
  216. SDL_WINRT_DEVICEFAMILY_XBOX,
  217. } SDL_WinRT_DeviceFamily;
  218. /**
  219. * \brief Retrieves a WinRT defined path on the local file system
  220. *
  221. * \note Documentation on most app-specific path types on WinRT
  222. * can be found on MSDN, at the URL:
  223. * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
  224. *
  225. * \param pathType The type of path to retrieve.
  226. * \return A UCS-2 string (16-bit, wide-char) containing the path, or NULL
  227. * if the path is not available for any reason. Not all paths are
  228. * available on all versions of Windows. This is especially true on
  229. * Windows Phone. Check the documentation for the given
  230. * SDL_WinRT_Path for more information on which path types are
  231. * supported where.
  232. */
  233. extern DECLSPEC const wchar_t * SDLCALL SDL_WinRTGetFSPathUNICODE(SDL_WinRT_Path pathType);
  234. /**
  235. * \brief Retrieves a WinRT defined path on the local file system
  236. *
  237. * \note Documentation on most app-specific path types on WinRT
  238. * can be found on MSDN, at the URL:
  239. * http://msdn.microsoft.com/en-us/library/windows/apps/hh464917.aspx
  240. *
  241. * \param pathType The type of path to retrieve.
  242. * \return A UTF-8 string (8-bit, multi-byte) containing the path, or NULL
  243. * if the path is not available for any reason. Not all paths are
  244. * available on all versions of Windows. This is especially true on
  245. * Windows Phone. Check the documentation for the given
  246. * SDL_WinRT_Path for more information on which path types are
  247. * supported where.
  248. */
  249. extern DECLSPEC const char * SDLCALL SDL_WinRTGetFSPathUTF8(SDL_WinRT_Path pathType);
  250. /**
  251. * \brief Detects the device family of WinRT plattform on runtime
  252. *
  253. * \return Device family
  254. */
  255. extern DECLSPEC SDL_WinRT_DeviceFamily SDLCALL SDL_WinRTGetDeviceFamily();
  256. #endif /* __WINRT__ */
  257. /**
  258. \brief Return true if the current device is a tablet.
  259. */
  260. extern DECLSPEC SDL_bool SDLCALL SDL_IsTablet(void);
  261. /* Functions used by iOS application delegates to notify SDL about state changes */
  262. extern DECLSPEC void SDLCALL SDL_OnApplicationWillTerminate(void);
  263. extern DECLSPEC void SDLCALL SDL_OnApplicationDidReceiveMemoryWarning(void);
  264. extern DECLSPEC void SDLCALL SDL_OnApplicationWillResignActive(void);
  265. extern DECLSPEC void SDLCALL SDL_OnApplicationDidEnterBackground(void);
  266. extern DECLSPEC void SDLCALL SDL_OnApplicationWillEnterForeground(void);
  267. extern DECLSPEC void SDLCALL SDL_OnApplicationDidBecomeActive(void);
  268. #ifdef __IPHONEOS__
  269. extern DECLSPEC void SDLCALL SDL_OnApplicationDidChangeStatusBarOrientation(void);
  270. #endif
  271. /* Ends C function definitions when using C++ */
  272. #ifdef __cplusplus
  273. }
  274. #endif
  275. #include "close_code.h"
  276. #endif /* SDL_system_h_ */
  277. /* vi: set ts=4 sw=4 expandtab: */