src/SDL.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 19 Nov 2018 21:17:00 -0800
changeset 12422 9091b20040cf
parent 12201 8bdc4d340419
child 12503 806492103856
permissions -rw-r--r--
Fixed bug 4391 - hid_enumerate() sometimes causes game to freeze for a few seconds

Daniel Gibson

Even though my game (dhewm3) doesn't use SDL_INIT_JOYSTICK, SDL_PumpEvent() calls SDL_JoystickUpdate() which ends up calling hid_enumerate() every three seconds, and sometimes on my Win7 box hid_enumerate() takes about 5 seconds, which causes the whole game to freeze for that time.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
icculus@8093
    21
#include "./SDL_internal.h"
slouken@0
    22
slouken@7828
    23
#if defined(__WIN32__)
slouken@7828
    24
#include "core/windows/SDL_windows.h"
slouken@7828
    25
#endif
slouken@7828
    26
slouken@0
    27
/* Initialization code for SDL */
slouken@0
    28
slouken@1361
    29
#include "SDL.h"
jorgen@6866
    30
#include "SDL_bits.h"
slouken@5310
    31
#include "SDL_revision.h"
slouken@4472
    32
#include "SDL_assert_c.h"
slouken@7360
    33
#include "events/SDL_events_c.h"
slouken@4472
    34
#include "haptic/SDL_haptic_c.h"
slouken@4472
    35
#include "joystick/SDL_joystick_c.h"
slouken@12130
    36
#include "sensor/SDL_sensor_c.h"
slouken@3647
    37
slouken@0
    38
/* Initialization/Cleanup routines */
slouken@1361
    39
#if !SDL_TIMERS_DISABLED
slouken@10609
    40
# include "timer/SDL_timer_c.h"
slouken@0
    41
#endif
slouken@7110
    42
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@2713
    43
extern int SDL_HelperWindowCreate(void);
slouken@2713
    44
extern int SDL_HelperWindowDestroy(void);
slouken@2713
    45
#endif
slouken@0
    46
slouken@3647
    47
slouken@0
    48
/* The initialized subsystems */
slouken@7281
    49
#ifdef SDL_MAIN_NEEDED
slouken@7281
    50
static SDL_bool SDL_MainIsReady = SDL_FALSE;
slouken@7281
    51
#else
slouken@7281
    52
static SDL_bool SDL_MainIsReady = SDL_TRUE;
slouken@7281
    53
#endif
slouken@6690
    54
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
jorgen@6866
    55
static Uint8 SDL_SubsystemRefCount[ 32 ];
slouken@0
    56
jorgen@6866
    57
/* Private helper to increment a subsystem's ref counter. */
jorgen@6867
    58
static void
jorgen@6867
    59
SDL_PrivateSubsystemRefCountIncr(Uint32 subsystem)
slouken@6690
    60
{
jorgen@6866
    61
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
    62
    SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
jorgen@6866
    63
    ++SDL_SubsystemRefCount[subsystem_index];
jorgen@6866
    64
}
slouken@6690
    65
jorgen@6866
    66
/* Private helper to decrement a subsystem's ref counter. */
jorgen@6867
    67
static void
jorgen@6867
    68
SDL_PrivateSubsystemRefCountDecr(Uint32 subsystem)
jorgen@6866
    69
{
jorgen@6866
    70
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
    71
    if (SDL_SubsystemRefCount[subsystem_index] > 0) {
jorgen@6866
    72
        --SDL_SubsystemRefCount[subsystem_index];
jorgen@6866
    73
    }
jorgen@6866
    74
}
jorgen@6866
    75
jorgen@6866
    76
/* Private helper to check if a system needs init. */
jorgen@6866
    77
static SDL_bool
jorgen@6927
    78
SDL_PrivateShouldInitSubsystem(Uint32 subsystem)
jorgen@6866
    79
{
jorgen@6927
    80
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
    81
    SDL_assert(SDL_SubsystemRefCount[subsystem_index] < 255);
icculus@10925
    82
    return (SDL_SubsystemRefCount[subsystem_index] == 0) ? SDL_TRUE : SDL_FALSE;
jorgen@6866
    83
}
jorgen@6866
    84
jorgen@6866
    85
/* Private helper to check if a system needs to be quit. */
jorgen@6866
    86
static SDL_bool
jorgen@6866
    87
SDL_PrivateShouldQuitSubsystem(Uint32 subsystem) {
jorgen@6866
    88
    int subsystem_index = SDL_MostSignificantBitIndex32(subsystem);
jorgen@6866
    89
    if (SDL_SubsystemRefCount[subsystem_index] == 0) {
jorgen@6866
    90
      return SDL_FALSE;
jorgen@6866
    91
    }
jorgen@6866
    92
jorgen@6866
    93
    /* If we're in SDL_Quit, we shut down every subsystem, even if refcount
jorgen@6866
    94
     * isn't zero.
jorgen@6866
    95
     */
icculus@10925
    96
    return (SDL_SubsystemRefCount[subsystem_index] == 1 || SDL_bInMainQuit) ? SDL_TRUE : SDL_FALSE;
slouken@6690
    97
}
slouken@0
    98
slouken@7281
    99
void
slouken@7281
   100
SDL_SetMainReady(void)
slouken@7281
   101
{
slouken@7281
   102
    SDL_MainIsReady = SDL_TRUE;
slouken@7281
   103
}
slouken@7281
   104
slouken@1895
   105
int
slouken@1895
   106
SDL_InitSubSystem(Uint32 flags)
slouken@0
   107
{
slouken@7281
   108
    if (!SDL_MainIsReady) {
slouken@7281
   109
        SDL_SetError("Application didn't initialize properly, did you include SDL_main.h in the file containing your main() function?");
slouken@7281
   110
        return -1;
slouken@7281
   111
    }
slouken@7281
   112
icculus@7590
   113
    /* Clear the error message */
icculus@7590
   114
    SDL_ClearError();
icculus@7590
   115
slouken@10549
   116
    if ((flags & SDL_INIT_GAMECONTROLLER)) {
slouken@10549
   117
        /* game controller implies joystick */
slouken@10549
   118
        flags |= SDL_INIT_JOYSTICK;
slouken@10549
   119
    }
slouken@10549
   120
slouken@10549
   121
    if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
slouken@10549
   122
        /* video or joystick implies events */
slouken@10549
   123
        flags |= SDL_INIT_EVENTS;
slouken@10549
   124
    }
slouken@10549
   125
icculus@7590
   126
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@12201
   127
    if ((flags & (SDL_INIT_HAPTIC|SDL_INIT_JOYSTICK))) {
slouken@12201
   128
        if (SDL_HelperWindowCreate() < 0) {
slouken@12201
   129
            return -1;
slouken@12201
   130
        }
slouken@12201
   131
    }
icculus@7590
   132
#endif
icculus@7590
   133
slouken@6128
   134
#if !SDL_TIMERS_DISABLED
slouken@8268
   135
    SDL_TicksInit();
jorgen@6866
   136
#endif
slouken@6690
   137
slouken@7360
   138
    /* Initialize the event subsystem */
slouken@7360
   139
    if ((flags & SDL_INIT_EVENTS)) {
slouken@7360
   140
#if !SDL_EVENTS_DISABLED
slouken@7360
   141
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
slouken@7360
   142
            if (SDL_StartEventLoop() < 0) {
slouken@7360
   143
                return (-1);
slouken@7360
   144
            }
slouken@7360
   145
            SDL_QuitInit();
slouken@7360
   146
        }
slouken@7360
   147
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
slouken@7360
   148
#else
slouken@7360
   149
        return SDL_SetError("SDL not built with events support");
slouken@7360
   150
#endif
slouken@7360
   151
    }
slouken@7360
   152
jorgen@6866
   153
    /* Initialize the timer subsystem */
slouken@7360
   154
    if ((flags & SDL_INIT_TIMER)){
jorgen@6866
   155
#if !SDL_TIMERS_DISABLED
jorgen@6927
   156
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
jorgen@6924
   157
            if (SDL_TimerInit() < 0) {
jorgen@6924
   158
                return (-1);
jorgen@6924
   159
            }
jorgen@6866
   160
        }
jorgen@6866
   161
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
slouken@6128
   162
#else
icculus@7037
   163
        return SDL_SetError("SDL not built with timer support");
jorgen@6866
   164
#endif
slouken@6128
   165
    }
slouken@6128
   166
slouken@7360
   167
    /* Initialize the video subsystem */
slouken@7360
   168
    if ((flags & SDL_INIT_VIDEO)){
slouken@1361
   169
#if !SDL_VIDEO_DISABLED
jorgen@6927
   170
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
jorgen@6924
   171
            if (SDL_VideoInit(NULL) < 0) {
jorgen@6924
   172
                return (-1);
jorgen@6924
   173
            }
jorgen@6866
   174
        }
jorgen@6866
   175
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
slouken@0
   176
#else
icculus@7037
   177
        return SDL_SetError("SDL not built with video support");
jorgen@6866
   178
#endif
slouken@1895
   179
    }
slouken@0
   180
jorgen@6866
   181
    /* Initialize the audio subsystem */
slouken@7360
   182
    if ((flags & SDL_INIT_AUDIO)){
slouken@1361
   183
#if !SDL_AUDIO_DISABLED
jorgen@6927
   184
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
jorgen@6924
   185
            if (SDL_AudioInit(NULL) < 0) {
jorgen@6924
   186
                return (-1);
jorgen@6924
   187
            }
jorgen@6866
   188
        }
jorgen@6866
   189
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
slouken@0
   190
#else
icculus@7037
   191
        return SDL_SetError("SDL not built with audio support");
jorgen@6866
   192
#endif
slouken@1895
   193
    }
slouken@0
   194
jorgen@6866
   195
    /* Initialize the joystick subsystem */
slouken@7360
   196
    if ((flags & SDL_INIT_JOYSTICK)){
slouken@1361
   197
#if !SDL_JOYSTICK_DISABLED
jorgen@6927
   198
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
jorgen@6924
   199
           if (SDL_JoystickInit() < 0) {
jorgen@6924
   200
               return (-1);
jorgen@6924
   201
           }
slouken@1895
   202
        }
jorgen@6866
   203
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
slouken@0
   204
#else
icculus@7037
   205
        return SDL_SetError("SDL not built with joystick support");
jorgen@6866
   206
#endif
slouken@1895
   207
    }
jorgen@6866
   208
slouken@7360
   209
    if ((flags & SDL_INIT_GAMECONTROLLER)){
jorgen@6866
   210
#if !SDL_JOYSTICK_DISABLED
jorgen@6927
   211
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
jorgen@6924
   212
            if (SDL_GameControllerInit() < 0) {
jorgen@6924
   213
                return (-1);
jorgen@6924
   214
            }
jorgen@6866
   215
        }
jorgen@6866
   216
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   217
#else
icculus@7037
   218
        return SDL_SetError("SDL not built with joystick support");
slouken@0
   219
#endif
jorgen@6866
   220
    }
slouken@0
   221
jorgen@6866
   222
    /* Initialize the haptic subsystem */
slouken@7360
   223
    if ((flags & SDL_INIT_HAPTIC)){
slouken@2713
   224
#if !SDL_HAPTIC_DISABLED
jorgen@6927
   225
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
jorgen@6924
   226
            if (SDL_HapticInit() < 0) {
jorgen@6927
   227
                return (-1);
jorgen@6927
   228
            }
jorgen@6866
   229
        }
jorgen@6866
   230
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
slouken@2713
   231
#else
icculus@7037
   232
        return SDL_SetError("SDL not built with haptic (force feedback) support");
jorgen@6866
   233
#endif
slouken@2713
   234
    }
jorgen@6866
   235
slouken@12130
   236
    /* Initialize the sensor subsystem */
slouken@12130
   237
    if ((flags & SDL_INIT_SENSOR)){
slouken@12130
   238
#if !SDL_SENSOR_DISABLED
slouken@12130
   239
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
slouken@12130
   240
            if (SDL_SensorInit() < 0) {
slouken@12130
   241
                return (-1);
slouken@12130
   242
            }
slouken@12130
   243
        }
slouken@12130
   244
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR);
slouken@12130
   245
#else
slouken@12130
   246
        return SDL_SetError("SDL not built with sensor support");
slouken@12130
   247
#endif
slouken@12130
   248
    }
slouken@12130
   249
slouken@1895
   250
    return (0);
slouken@0
   251
}
slouken@0
   252
slouken@1895
   253
int
slouken@1895
   254
SDL_Init(Uint32 flags)
slouken@0
   255
{
icculus@7590
   256
    return SDL_InitSubSystem(flags);
slouken@0
   257
}
slouken@0
   258
slouken@1895
   259
void
slouken@1895
   260
SDL_QuitSubSystem(Uint32 flags)
slouken@0
   261
{
slouken@1895
   262
    /* Shut down requested initialized subsystems */
slouken@12130
   263
#if !SDL_SENSOR_DISABLED
slouken@12130
   264
    if ((flags & SDL_INIT_SENSOR)) {
slouken@12130
   265
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) {
slouken@12201
   266
            SDL_SensorQuit();
slouken@12201
   267
        }
slouken@12130
   268
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR);
slouken@12130
   269
    }
slouken@12130
   270
#endif
slouken@12130
   271
slouken@1361
   272
#if !SDL_JOYSTICK_DISABLED
jorgen@6866
   273
    if ((flags & SDL_INIT_GAMECONTROLLER)) {
slouken@7360
   274
        /* game controller implies joystick */
jorgen@6866
   275
        flags |= SDL_INIT_JOYSTICK;
jorgen@6866
   276
jorgen@6866
   277
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
jorgen@6866
   278
            SDL_GameControllerQuit();
slouken@7191
   279
        }
jorgen@6866
   280
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   281
    }
slouken@6690
   282
jorgen@6866
   283
    if ((flags & SDL_INIT_JOYSTICK)) {
slouken@7360
   284
        /* joystick implies events */
slouken@7360
   285
        flags |= SDL_INIT_EVENTS;
slouken@7360
   286
jorgen@6866
   287
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
slouken@7191
   288
            SDL_JoystickQuit();
slouken@7191
   289
        }
jorgen@6866
   290
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
slouken@1895
   291
    }
slouken@0
   292
#endif
jorgen@6866
   293
slouken@2713
   294
#if !SDL_HAPTIC_DISABLED
jorgen@6866
   295
    if ((flags & SDL_INIT_HAPTIC)) {
jorgen@6866
   296
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
slouken@7191
   297
            SDL_HapticQuit();
slouken@7191
   298
        }
jorgen@6866
   299
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
slouken@2713
   300
    }
slouken@2713
   301
#endif
jorgen@6866
   302
slouken@1361
   303
#if !SDL_AUDIO_DISABLED
jorgen@6866
   304
    if ((flags & SDL_INIT_AUDIO)) {
jorgen@6866
   305
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
slouken@7191
   306
            SDL_AudioQuit();
slouken@7191
   307
        }
jorgen@6866
   308
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
slouken@1895
   309
    }
slouken@0
   310
#endif
jorgen@6866
   311
slouken@1361
   312
#if !SDL_VIDEO_DISABLED
jorgen@6866
   313
    if ((flags & SDL_INIT_VIDEO)) {
slouken@7360
   314
        /* video implies events */
slouken@7360
   315
        flags |= SDL_INIT_EVENTS;
slouken@7360
   316
jorgen@6866
   317
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
slouken@7191
   318
            SDL_VideoQuit();
slouken@7191
   319
        }
jorgen@6866
   320
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
slouken@1895
   321
    }
slouken@0
   322
#endif
jorgen@6866
   323
slouken@6128
   324
#if !SDL_TIMERS_DISABLED
jorgen@6866
   325
    if ((flags & SDL_INIT_TIMER)) {
jorgen@6866
   326
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
slouken@7191
   327
            SDL_TimerQuit();
slouken@7191
   328
        }
jorgen@6866
   329
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
slouken@6128
   330
    }
slouken@6128
   331
#endif
slouken@7360
   332
slouken@7360
   333
#if !SDL_EVENTS_DISABLED
slouken@7360
   334
    if ((flags & SDL_INIT_EVENTS)) {
slouken@7360
   335
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
slouken@7360
   336
            SDL_QuitQuit();
slouken@7360
   337
            SDL_StopEventLoop();
slouken@7360
   338
        }
slouken@7360
   339
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
slouken@7360
   340
    }
slouken@7360
   341
#endif
slouken@0
   342
}
slouken@0
   343
slouken@1895
   344
Uint32
slouken@1895
   345
SDL_WasInit(Uint32 flags)
slouken@0
   346
{
jorgen@6866
   347
    int i;
jorgen@6866
   348
    int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
jorgen@6866
   349
    Uint32 initialized = 0;
jorgen@6866
   350
slouken@12422
   351
    /* Fast path for checking one flag */
slouken@12422
   352
    if (SDL_HasExactlyOneBitSet32(flags)) {
slouken@12422
   353
        int subsystem_index = SDL_MostSignificantBitIndex32(flags);
slouken@12422
   354
        return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
slouken@12422
   355
    }
slouken@12422
   356
slouken@1895
   357
    if (!flags) {
slouken@1895
   358
        flags = SDL_INIT_EVERYTHING;
slouken@1895
   359
    }
jorgen@6866
   360
jorgen@6866
   361
    num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
jorgen@6866
   362
jorgen@6866
   363
    /* Iterate over each bit in flags, and check the matching subsystem. */
jorgen@6866
   364
    for (i = 0; i < num_subsystems; ++i) {
jorgen@6866
   365
        if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
jorgen@6866
   366
            initialized |= (1 << i);
jorgen@6866
   367
        }
jorgen@6866
   368
jorgen@6866
   369
        flags >>= 1;
jorgen@6866
   370
    }
jorgen@6866
   371
jorgen@6866
   372
    return initialized;
slouken@0
   373
}
slouken@0
   374
slouken@1895
   375
void
slouken@1895
   376
SDL_Quit(void)
slouken@0
   377
{
jorgen@6866
   378
    SDL_bInMainQuit = SDL_TRUE;
jorgen@6866
   379
slouken@1895
   380
    /* Quit all subsystems */
slouken@7110
   381
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@2713
   382
    SDL_HelperWindowDestroy();
slouken@2713
   383
#endif
slouken@1895
   384
    SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
slouken@0
   385
slouken@8268
   386
#if !SDL_TIMERS_DISABLED
slouken@8268
   387
    SDL_TicksQuit();
slouken@8268
   388
#endif
slouken@8268
   389
slouken@5189
   390
    SDL_ClearHints();
slouken@3647
   391
    SDL_AssertionsQuit();
slouken@5221
   392
    SDL_LogResetPriorities();
slouken@6690
   393
jorgen@6866
   394
    /* Now that every subsystem has been quit, we reset the subsystem refcount
jorgen@6866
   395
     * and the list of initialized subsystems.
jorgen@6866
   396
     */
jorgen@6866
   397
    SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
jorgen@6866
   398
jorgen@6866
   399
    SDL_bInMainQuit = SDL_FALSE;
slouken@0
   400
}
slouken@0
   401
slouken@1895
   402
/* Get the library version number */
slouken@1895
   403
void
slouken@1895
   404
SDL_GetVersion(SDL_version * ver)
slouken@0
   405
{
slouken@1895
   406
    SDL_VERSION(ver);
slouken@0
   407
}
slouken@0
   408
slouken@2982
   409
/* Get the library source revision */
icculus@4419
   410
const char *
slouken@2996
   411
SDL_GetRevision(void)
slouken@2982
   412
{
slouken@2983
   413
    return SDL_REVISION;
slouken@2982
   414
}
slouken@2982
   415
slouken@5359
   416
/* Get the library source revision number */
slouken@5359
   417
int
slouken@5359
   418
SDL_GetRevisionNumber(void)
slouken@5359
   419
{
slouken@5359
   420
    return SDL_REVISION_NUMBER;
slouken@5359
   421
}
slouken@5359
   422
slouken@3319
   423
/* Get the name of the platform */
slouken@3319
   424
const char *
slouken@3319
   425
SDL_GetPlatform()
slouken@3319
   426
{
slouken@3319
   427
#if __AIX__
slouken@3319
   428
    return "AIX";
slouken@6441
   429
#elif __ANDROID__
slouken@6441
   430
    return "Android";
slouken@3319
   431
#elif __BSDI__
slouken@3319
   432
    return "BSDI";
slouken@3319
   433
#elif __DREAMCAST__
slouken@3319
   434
    return "Dreamcast";
philipp@9341
   435
#elif __EMSCRIPTEN__
philipp@9341
   436
    return "Emscripten";
slouken@3319
   437
#elif __FREEBSD__
slouken@3319
   438
    return "FreeBSD";
icculus@7346
   439
#elif __HAIKU__
icculus@7346
   440
    return "Haiku";
slouken@3319
   441
#elif __HPUX__
slouken@3319
   442
    return "HP-UX";
slouken@3319
   443
#elif __IRIX__
slouken@3319
   444
    return "Irix";
slouken@3319
   445
#elif __LINUX__
slouken@3319
   446
    return "Linux";
slouken@3319
   447
#elif __MINT__
slouken@3319
   448
    return "Atari MiNT";
slouken@3319
   449
#elif __MACOS__
slouken@3319
   450
    return "MacOS Classic";
slouken@3319
   451
#elif __MACOSX__
slouken@3319
   452
    return "Mac OS X";
slouken@8886
   453
#elif __NACL__
slouken@8886
   454
    return "NaCl";
slouken@3319
   455
#elif __NETBSD__
slouken@3319
   456
    return "NetBSD";
slouken@3319
   457
#elif __OPENBSD__
slouken@3319
   458
    return "OpenBSD";
slouken@3319
   459
#elif __OS2__
slouken@3319
   460
    return "OS/2";
slouken@3319
   461
#elif __OSF__
slouken@3319
   462
    return "OSF/1";
slouken@3319
   463
#elif __QNXNTO__
slouken@3319
   464
    return "QNX Neutrino";
slouken@3319
   465
#elif __RISCOS__
slouken@3319
   466
    return "RISC OS";
slouken@3319
   467
#elif __SOLARIS__
slouken@3319
   468
    return "Solaris";
slouken@5086
   469
#elif __WIN32__
slouken@3319
   470
    return "Windows";
dludwig@9223
   471
#elif __WINRT__
dludwig@9223
   472
    return "WinRT";
slime73@10340
   473
#elif __TVOS__
slime73@10340
   474
    return "tvOS";
slouken@3319
   475
#elif __IPHONEOS__
slouken@7592
   476
    return "iOS";
kimonline@7009
   477
#elif __PSP__
kimonline@7009
   478
    return "PlayStation Portable";
slouken@3319
   479
#else
slouken@3319
   480
    return "Unknown (see SDL_platform.h)";
slouken@3319
   481
#endif
slouken@3319
   482
}
slouken@3319
   483
slouken@12137
   484
SDL_bool
slouken@12137
   485
SDL_IsTablet()
slouken@12137
   486
{
slouken@12137
   487
#if __ANDROID__
slouken@12137
   488
    extern SDL_bool SDL_IsAndroidTablet(void);
slouken@12137
   489
    return SDL_IsAndroidTablet();
slouken@12137
   490
#elif __IPHONEOS__
slouken@12137
   491
    extern SDL_bool SDL_IsIPad(void);
slouken@12137
   492
    return SDL_IsIPad();
slouken@12137
   493
#else
slouken@12137
   494
    return SDL_FALSE;
slouken@12137
   495
#endif
slouken@12137
   496
}
slouken@12137
   497
slouken@11883
   498
#if defined(__WIN32__)
slouken@11883
   499
slouken@11885
   500
#if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
slouken@1465
   501
/* Need to include DllMain() on Watcom C for some reason.. */
slouken@1330
   502
slouken@1895
   503
BOOL APIENTRY
slouken@1895
   504
_DllMainCRTStartup(HANDLE hModule,
slouken@1895
   505
                   DWORD ul_reason_for_call, LPVOID lpReserved)
slouken@1330
   506
{
slouken@1895
   507
    switch (ul_reason_for_call) {
slouken@1895
   508
    case DLL_PROCESS_ATTACH:
slouken@1895
   509
    case DLL_THREAD_ATTACH:
slouken@1895
   510
    case DLL_THREAD_DETACH:
slouken@1895
   511
    case DLL_PROCESS_DETACH:
slouken@1895
   512
        break;
slouken@1895
   513
    }
slouken@1895
   514
    return TRUE;
slouken@1330
   515
}
slouken@11885
   516
#endif /* Building DLL */
slouken@1330
   517
slouken@11883
   518
#endif /* __WIN32__ */
slouken@11883
   519
jorgen@6927
   520
/* vi: set sts=4 ts=4 sw=4 expandtab: */