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