SDL  2.0
SDL.c File Reference
#include "./SDL_internal.h"
#include "SDL.h"
#include "SDL_bits.h"
#include "SDL_revision.h"
#include "SDL_assert_c.h"
#include "events/SDL_events_c.h"
#include "haptic/SDL_haptic_c.h"
#include "joystick/SDL_joystick_c.h"
#include "sensor/SDL_sensor_c.h"
#include "timer/SDL_timer_c.h"
+ Include dependency graph for SDL.c:

Go to the source code of this file.

Functions

static void SDL_PrivateSubsystemRefCountIncr (Uint32 subsystem)
static void SDL_PrivateSubsystemRefCountDecr (Uint32 subsystem)
static SDL_bool SDL_PrivateShouldInitSubsystem (Uint32 subsystem)
static SDL_bool SDL_PrivateShouldQuitSubsystem (Uint32 subsystem)
void SDL_SetMainReady (void)
int SDL_InitSubSystem (Uint32 flags)
int SDL_Init (Uint32 flags)
void SDL_QuitSubSystem (Uint32 flags)
Uint32 SDL_WasInit (Uint32 flags)
void SDL_Quit (void)
void SDL_GetVersion (SDL_version *ver)
 Get the version of SDL that is linked against your program.
const char * SDL_GetRevision (void)
 Get the code revision of SDL that is linked against your program.
int SDL_GetRevisionNumber (void)
 Get the revision number of SDL that is linked against your program.
const char * SDL_GetPlatform ()
 Gets the name of the platform.
SDL_bool SDL_IsTablet ()
 Return true if the current device is a tablet.

Variables

static SDL_bool SDL_MainIsReady = SDL_TRUE
static SDL_bool SDL_bInMainQuit = SDL_FALSE
static Uint8 SDL_SubsystemRefCount [32]

Function Documentation

const char* SDL_GetPlatform ( void  )

Gets the name of the platform.

Definition at line 419 of file SDL.c.

{
#if __AIX__
return "AIX";
#elif __ANDROID__
return "Android";
#elif __BSDI__
return "BSDI";
#elif __DREAMCAST__
return "Dreamcast";
#elif __EMSCRIPTEN__
return "Emscripten";
#elif __FREEBSD__
return "FreeBSD";
#elif __HAIKU__
return "Haiku";
#elif __HPUX__
return "HP-UX";
#elif __IRIX__
return "Irix";
#elif __LINUX__
return "Linux";
#elif __MINT__
return "Atari MiNT";
#elif __MACOS__
return "MacOS Classic";
#elif __MACOSX__
return "Mac OS X";
#elif __NACL__
return "NaCl";
#elif __NETBSD__
return "NetBSD";
#elif __OPENBSD__
return "OpenBSD";
#elif __OS2__
return "OS/2";
#elif __OSF__
return "OSF/1";
#elif __QNXNTO__
return "QNX Neutrino";
#elif __RISCOS__
return "RISC OS";
#elif __SOLARIS__
return "Solaris";
#elif __WIN32__
return "Windows";
#elif __WINRT__
return "WinRT";
#elif __TVOS__
return "tvOS";
#elif __IPHONEOS__
return "iOS";
#elif __PSP__
return "PlayStation Portable";
#else
return "Unknown (see SDL_platform.h)";
#endif
}
const char* SDL_GetRevision ( void  )

Get the code revision of SDL that is linked against your program.

Returns an arbitrary string (a hash value) uniquely identifying the exact revision of the SDL library in use, and is only useful in comparing against other revisions. It is NOT an incrementing number.

Definition at line 405 of file SDL.c.

References SDL_REVISION.

{
return SDL_REVISION;
}
int SDL_GetRevisionNumber ( void  )

Get the revision number of SDL that is linked against your program.

Returns a number uniquely identifying the exact revision of the SDL library in use. It is an incrementing number based on commits to hg.libsdl.org.

Definition at line 412 of file SDL.c.

References SDL_REVISION_NUMBER.

{
}
void SDL_GetVersion ( SDL_version ver)

Get the version of SDL that is linked against your program.

If you are linking to SDL dynamically, then it is possible that the current version will be different than the version you compiled against. This function returns the current version, while SDL_VERSION() is a macro that tells you what version you compiled with.

SDL_version compiled;
SDL_version linked;
SDL_VERSION(&compiled);
SDL_GetVersion(&linked);
printf("We compiled against SDL version %d.%d.%d ...\n",
compiled.major, compiled.minor, compiled.patch);
printf("But we linked against SDL version %d.%d.%d.\n",
linked.major, linked.minor, linked.patch);

This function may be called safely at any time, even before SDL_Init().

See Also
SDL_VERSION

Definition at line 398 of file SDL.c.

References SDL_VERSION.

{
}
int SDL_Init ( Uint32  flags)

This function initializes the subsystems specified by flags

Definition at line 254 of file SDL.c.

References SDL_InitSubSystem.

{
}
int SDL_InitSubSystem ( Uint32  flags)

This function initializes specific SDL subsystems

Subsystem initialization is ref-counted, you must call SDL_QuitSubSystem() for each SDL_InitSubSystem() to correctly shutdown a subsystem manually (or call SDL_Quit() to force shutdown). If a subsystem is already loaded then this call will increase the ref-count and return.

Definition at line 106 of file SDL.c.

References NULL, SDL_AudioInit, SDL_ClearError, SDL_GameControllerInit(), SDL_HapticInit(), SDL_INIT_AUDIO, SDL_INIT_EVENTS, SDL_INIT_GAMECONTROLLER, SDL_INIT_HAPTIC, SDL_INIT_JOYSTICK, SDL_INIT_SENSOR, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickInit(), SDL_MainIsReady, SDL_PrivateShouldInitSubsystem(), SDL_PrivateSubsystemRefCountIncr(), SDL_QuitInit(), SDL_SensorInit(), SDL_SetError, SDL_StartEventLoop(), SDL_TicksInit(), SDL_TimerInit(), and SDL_VideoInit.

{
SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
return -1;
}
/* Clear the error message */
/* game controller implies joystick */
}
/* video or joystick implies events */
}
#if SDL_VIDEO_DRIVER_WINDOWS
if (SDL_HelperWindowCreate() < 0) {
return -1;
}
}
#endif
#if !SDL_TIMERS_DISABLED
#endif
/* Initialize the event subsystem */
#if !SDL_EVENTS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
if (SDL_StartEventLoop() < 0) {
return (-1);
}
}
#else
return SDL_SetError("SDL not built with events support");
#endif
}
/* Initialize the timer subsystem */
#if !SDL_TIMERS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) {
return (-1);
}
}
#else
return SDL_SetError("SDL not built with timer support");
#endif
}
/* Initialize the video subsystem */
#if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) {
return (-1);
}
}
#else
return SDL_SetError("SDL not built with video support");
#endif
}
/* Initialize the audio subsystem */
#if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) {
return (-1);
}
}
#else
return SDL_SetError("SDL not built with audio support");
#endif
}
/* Initialize the joystick subsystem */
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) {
return (-1);
}
}
#else
return SDL_SetError("SDL not built with joystick support");
#endif
}
if ((flags & SDL_INIT_GAMECONTROLLER)){
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
return (-1);
}
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
#else
return SDL_SetError("SDL not built with joystick support");
#endif
}
/* Initialize the haptic subsystem */
#if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) {
return (-1);
}
}
#else
return SDL_SetError("SDL not built with haptic (force feedback) support");
#endif
}
/* Initialize the sensor subsystem */
#if !SDL_SENSOR_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
if (SDL_SensorInit() < 0) {
return (-1);
}
}
#else
return SDL_SetError("SDL not built with sensor support");
#endif
}
return (0);
}
SDL_bool SDL_IsTablet ( void  )

Return true if the current device is a tablet.

Definition at line 479 of file SDL.c.

References SDL_FALSE, and SDL_IsAndroidTablet().

{
#if __ANDROID__
#elif __IPHONEOS__
extern SDL_bool SDL_IsIPad(void);
return SDL_IsIPad();
#else
return SDL_FALSE;
#endif
}
static SDL_bool SDL_PrivateShouldInitSubsystem ( Uint32  subsystem)
static

Definition at line 78 of file SDL.c.

References SDL_assert, SDL_FALSE, SDL_MostSignificantBitIndex32(), SDL_SubsystemRefCount, and SDL_TRUE.

Referenced by SDL_InitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
return (SDL_SubsystemRefCount[subsystem_index] == 0) ? SDL_TRUE : SDL_FALSE;
}
static SDL_bool SDL_PrivateShouldQuitSubsystem ( Uint32  subsystem)
static

Definition at line 87 of file SDL.c.

References SDL_bInMainQuit, SDL_FALSE, SDL_MostSignificantBitIndex32(), SDL_SubsystemRefCount, and SDL_TRUE.

Referenced by SDL_QuitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
if (SDL_SubsystemRefCount[subsystem_index] == 0) {
return SDL_FALSE;
}
/* If we're in SDL_Quit, we shut down every subsystem, even if refcount
* isn't zero.
*/
return (SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
}
static void SDL_PrivateSubsystemRefCountDecr ( Uint32  subsystem)
static

Definition at line 68 of file SDL.c.

References SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

Referenced by SDL_QuitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
if (SDL_SubsystemRefCount[subsystem_index] > 0) {
--SDL_SubsystemRefCount[subsystem_index];
}
}
static void SDL_PrivateSubsystemRefCountIncr ( Uint32  subsystem)
static

Definition at line 59 of file SDL.c.

References SDL_assert, SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

Referenced by SDL_InitSubSystem().

{
int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
++SDL_SubsystemRefCount[subsystem_index];
}
void SDL_Quit ( void  )

This function cleans up all initialized subsystems. You should call it upon all exit conditions.

Definition at line 370 of file SDL.c.

References SDL_AssertionsQuit(), SDL_bInMainQuit, SDL_ClearHints, SDL_FALSE, SDL_INIT_EVERYTHING, SDL_LogResetPriorities, SDL_memset, SDL_QuitSubSystem, SDL_SubsystemRefCount, SDL_TicksQuit(), and SDL_TRUE.

{
/* Quit all subsystems */
#if SDL_VIDEO_DRIVER_WINDOWS
SDL_HelperWindowDestroy();
#endif
#if !SDL_TIMERS_DISABLED
#endif
/* Now that every subsystem has been quit, we reset the subsystem refcount
* and the list of initialized subsystems.
*/
}
void SDL_QuitSubSystem ( Uint32  flags)

This function cleans up specific SDL subsystems

Definition at line 260 of file SDL.c.

References SDL_AudioQuit, SDL_GameControllerQuit(), SDL_HapticQuit(), SDL_INIT_AUDIO, SDL_INIT_EVENTS, SDL_INIT_GAMECONTROLLER, SDL_INIT_HAPTIC, SDL_INIT_JOYSTICK, SDL_INIT_SENSOR, SDL_INIT_TIMER, SDL_INIT_VIDEO, SDL_JoystickQuit(), SDL_PrivateShouldQuitSubsystem(), SDL_PrivateSubsystemRefCountDecr(), SDL_QuitQuit(), SDL_SensorQuit(), SDL_StopEventLoop(), SDL_TimerQuit(), and SDL_VideoQuit.

{
/* Shut down requested initialized subsystems */
#if !SDL_SENSOR_DISABLED
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) {
}
}
#endif
#if !SDL_JOYSTICK_DISABLED
/* game controller implies joystick */
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
}
/* joystick implies events */
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
}
}
#endif
#if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
}
}
#endif
#if !SDL_AUDIO_DISABLED
if ((flags & SDL_INIT_AUDIO)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
}
}
#endif
#if !SDL_VIDEO_DISABLED
if ((flags & SDL_INIT_VIDEO)) {
/* video implies events */
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
}
}
#endif
#if !SDL_TIMERS_DISABLED
if ((flags & SDL_INIT_TIMER)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
}
}
#endif
#if !SDL_EVENTS_DISABLED
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
}
}
#endif
}
void SDL_SetMainReady ( void  )

This is called by the real SDL main function to let the rest of the library know that initialization was done properly.

Calling this yourself without knowing what you're doing can cause crashes and hard to diagnose problems with your application.

Definition at line 100 of file SDL.c.

References SDL_MainIsReady, and SDL_TRUE.

Uint32 SDL_WasInit ( Uint32  flags)

This function returns a mask of the specified subsystems which have previously been initialized.

If flags is 0, it returns a mask of all initialized subsystems.

Definition at line 345 of file SDL.c.

References i, SDL_arraysize, SDL_INIT_EVERYTHING, SDL_min, SDL_MostSignificantBitIndex32(), and SDL_SubsystemRefCount.

{
int i;
int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
Uint32 initialized = 0;
if (!flags) {
}
num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
/* Iterate over each bit in flags, and check the matching subsystem. */
for (i = 0; i < num_subsystems; ++i) {
if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
initialized |= (1 << i);
}
flags >>= 1;
}
return initialized;
}

Variable Documentation

SDL_bool SDL_bInMainQuit = SDL_FALSE
static

Definition at line 54 of file SDL.c.

Referenced by SDL_PrivateShouldQuitSubsystem(), and SDL_Quit().

SDL_bool SDL_MainIsReady = SDL_TRUE
static

Definition at line 52 of file SDL.c.

Referenced by SDL_InitSubSystem(), and SDL_SetMainReady().