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