SDL_system.h 19 KB

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