src/SDL.c
author Ryan C. Gordon <icculus@icculus.org>
Fri, 15 Mar 2019 14:08:30 -0400
changeset 12630 a26e3c61e35f
parent 12503 806492103856
permissions -rw-r--r--
events: Make debug logging of the event queue a hint instead of an #ifdef.

This makes it easy to toggle it on when debugging a new platform (or just
getting more visibility into an app) without having to rebuild SDL.
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 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)) {
icculus@12630
   142
            if (SDL_EventsInit() < 0) {
slouken@7360
   143
                return (-1);
slouken@7360
   144
            }
slouken@7360
   145
        }
slouken@7360
   146
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
slouken@7360
   147
#else
slouken@7360
   148
        return SDL_SetError("SDL not built with events support");
slouken@7360
   149
#endif
slouken@7360
   150
    }
slouken@7360
   151
jorgen@6866
   152
    /* Initialize the timer subsystem */
slouken@7360
   153
    if ((flags & SDL_INIT_TIMER)){
jorgen@6866
   154
#if !SDL_TIMERS_DISABLED
jorgen@6927
   155
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
jorgen@6924
   156
            if (SDL_TimerInit() < 0) {
jorgen@6924
   157
                return (-1);
jorgen@6924
   158
            }
jorgen@6866
   159
        }
jorgen@6866
   160
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_TIMER);
slouken@6128
   161
#else
icculus@7037
   162
        return SDL_SetError("SDL not built with timer support");
jorgen@6866
   163
#endif
slouken@6128
   164
    }
slouken@6128
   165
slouken@7360
   166
    /* Initialize the video subsystem */
slouken@7360
   167
    if ((flags & SDL_INIT_VIDEO)){
slouken@1361
   168
#if !SDL_VIDEO_DISABLED
jorgen@6927
   169
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
jorgen@6924
   170
            if (SDL_VideoInit(NULL) < 0) {
jorgen@6924
   171
                return (-1);
jorgen@6924
   172
            }
jorgen@6866
   173
        }
jorgen@6866
   174
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_VIDEO);
slouken@0
   175
#else
icculus@7037
   176
        return SDL_SetError("SDL not built with video support");
jorgen@6866
   177
#endif
slouken@1895
   178
    }
slouken@0
   179
jorgen@6866
   180
    /* Initialize the audio subsystem */
slouken@7360
   181
    if ((flags & SDL_INIT_AUDIO)){
slouken@1361
   182
#if !SDL_AUDIO_DISABLED
jorgen@6927
   183
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
jorgen@6924
   184
            if (SDL_AudioInit(NULL) < 0) {
jorgen@6924
   185
                return (-1);
jorgen@6924
   186
            }
jorgen@6866
   187
        }
jorgen@6866
   188
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_AUDIO);
slouken@0
   189
#else
icculus@7037
   190
        return SDL_SetError("SDL not built with audio support");
jorgen@6866
   191
#endif
slouken@1895
   192
    }
slouken@0
   193
jorgen@6866
   194
    /* Initialize the joystick subsystem */
slouken@7360
   195
    if ((flags & SDL_INIT_JOYSTICK)){
slouken@1361
   196
#if !SDL_JOYSTICK_DISABLED
jorgen@6927
   197
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
jorgen@6924
   198
           if (SDL_JoystickInit() < 0) {
jorgen@6924
   199
               return (-1);
jorgen@6924
   200
           }
slouken@1895
   201
        }
jorgen@6866
   202
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_JOYSTICK);
slouken@0
   203
#else
icculus@7037
   204
        return SDL_SetError("SDL not built with joystick support");
jorgen@6866
   205
#endif
slouken@1895
   206
    }
jorgen@6866
   207
slouken@7360
   208
    if ((flags & SDL_INIT_GAMECONTROLLER)){
jorgen@6866
   209
#if !SDL_JOYSTICK_DISABLED
jorgen@6927
   210
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
jorgen@6924
   211
            if (SDL_GameControllerInit() < 0) {
jorgen@6924
   212
                return (-1);
jorgen@6924
   213
            }
jorgen@6866
   214
        }
jorgen@6866
   215
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   216
#else
icculus@7037
   217
        return SDL_SetError("SDL not built with joystick support");
slouken@0
   218
#endif
jorgen@6866
   219
    }
slouken@0
   220
jorgen@6866
   221
    /* Initialize the haptic subsystem */
slouken@7360
   222
    if ((flags & SDL_INIT_HAPTIC)){
slouken@2713
   223
#if !SDL_HAPTIC_DISABLED
jorgen@6927
   224
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
jorgen@6924
   225
            if (SDL_HapticInit() < 0) {
jorgen@6927
   226
                return (-1);
jorgen@6927
   227
            }
jorgen@6866
   228
        }
jorgen@6866
   229
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_HAPTIC);
slouken@2713
   230
#else
icculus@7037
   231
        return SDL_SetError("SDL not built with haptic (force feedback) support");
jorgen@6866
   232
#endif
slouken@2713
   233
    }
jorgen@6866
   234
slouken@12130
   235
    /* Initialize the sensor subsystem */
slouken@12130
   236
    if ((flags & SDL_INIT_SENSOR)){
slouken@12130
   237
#if !SDL_SENSOR_DISABLED
slouken@12130
   238
        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_SENSOR)) {
slouken@12130
   239
            if (SDL_SensorInit() < 0) {
slouken@12130
   240
                return (-1);
slouken@12130
   241
            }
slouken@12130
   242
        }
slouken@12130
   243
        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_SENSOR);
slouken@12130
   244
#else
slouken@12130
   245
        return SDL_SetError("SDL not built with sensor support");
slouken@12130
   246
#endif
slouken@12130
   247
    }
slouken@12130
   248
slouken@1895
   249
    return (0);
slouken@0
   250
}
slouken@0
   251
slouken@1895
   252
int
slouken@1895
   253
SDL_Init(Uint32 flags)
slouken@0
   254
{
icculus@7590
   255
    return SDL_InitSubSystem(flags);
slouken@0
   256
}
slouken@0
   257
slouken@1895
   258
void
slouken@1895
   259
SDL_QuitSubSystem(Uint32 flags)
slouken@0
   260
{
slouken@1895
   261
    /* Shut down requested initialized subsystems */
slouken@12130
   262
#if !SDL_SENSOR_DISABLED
slouken@12130
   263
    if ((flags & SDL_INIT_SENSOR)) {
slouken@12130
   264
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_SENSOR)) {
slouken@12201
   265
            SDL_SensorQuit();
slouken@12201
   266
        }
slouken@12130
   267
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_SENSOR);
slouken@12130
   268
    }
slouken@12130
   269
#endif
slouken@12130
   270
slouken@1361
   271
#if !SDL_JOYSTICK_DISABLED
jorgen@6866
   272
    if ((flags & SDL_INIT_GAMECONTROLLER)) {
slouken@7360
   273
        /* game controller implies joystick */
jorgen@6866
   274
        flags |= SDL_INIT_JOYSTICK;
jorgen@6866
   275
jorgen@6866
   276
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
jorgen@6866
   277
            SDL_GameControllerQuit();
slouken@7191
   278
        }
jorgen@6866
   279
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_GAMECONTROLLER);
jorgen@6866
   280
    }
slouken@6690
   281
jorgen@6866
   282
    if ((flags & SDL_INIT_JOYSTICK)) {
slouken@7360
   283
        /* joystick implies events */
slouken@7360
   284
        flags |= SDL_INIT_EVENTS;
slouken@7360
   285
jorgen@6866
   286
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
slouken@7191
   287
            SDL_JoystickQuit();
slouken@7191
   288
        }
jorgen@6866
   289
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_JOYSTICK);
slouken@1895
   290
    }
slouken@0
   291
#endif
jorgen@6866
   292
slouken@2713
   293
#if !SDL_HAPTIC_DISABLED
jorgen@6866
   294
    if ((flags & SDL_INIT_HAPTIC)) {
jorgen@6866
   295
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_HAPTIC)) {
slouken@7191
   296
            SDL_HapticQuit();
slouken@7191
   297
        }
jorgen@6866
   298
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_HAPTIC);
slouken@2713
   299
    }
slouken@2713
   300
#endif
jorgen@6866
   301
slouken@1361
   302
#if !SDL_AUDIO_DISABLED
jorgen@6866
   303
    if ((flags & SDL_INIT_AUDIO)) {
jorgen@6866
   304
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_AUDIO)) {
slouken@7191
   305
            SDL_AudioQuit();
slouken@7191
   306
        }
jorgen@6866
   307
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_AUDIO);
slouken@1895
   308
    }
slouken@0
   309
#endif
jorgen@6866
   310
slouken@1361
   311
#if !SDL_VIDEO_DISABLED
jorgen@6866
   312
    if ((flags & SDL_INIT_VIDEO)) {
slouken@7360
   313
        /* video implies events */
slouken@7360
   314
        flags |= SDL_INIT_EVENTS;
slouken@7360
   315
jorgen@6866
   316
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
slouken@7191
   317
            SDL_VideoQuit();
slouken@7191
   318
        }
jorgen@6866
   319
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_VIDEO);
slouken@1895
   320
    }
slouken@0
   321
#endif
jorgen@6866
   322
slouken@6128
   323
#if !SDL_TIMERS_DISABLED
jorgen@6866
   324
    if ((flags & SDL_INIT_TIMER)) {
jorgen@6866
   325
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_TIMER)) {
slouken@7191
   326
            SDL_TimerQuit();
slouken@7191
   327
        }
jorgen@6866
   328
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
slouken@6128
   329
    }
slouken@6128
   330
#endif
slouken@7360
   331
slouken@7360
   332
#if !SDL_EVENTS_DISABLED
slouken@7360
   333
    if ((flags & SDL_INIT_EVENTS)) {
slouken@7360
   334
        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
icculus@12630
   335
            SDL_EventsQuit();
slouken@7360
   336
        }
slouken@7360
   337
        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
slouken@7360
   338
    }
slouken@7360
   339
#endif
slouken@0
   340
}
slouken@0
   341
slouken@1895
   342
Uint32
slouken@1895
   343
SDL_WasInit(Uint32 flags)
slouken@0
   344
{
jorgen@6866
   345
    int i;
jorgen@6866
   346
    int num_subsystems = SDL_arraysize(SDL_SubsystemRefCount);
jorgen@6866
   347
    Uint32 initialized = 0;
jorgen@6866
   348
slouken@12422
   349
    /* Fast path for checking one flag */
slouken@12422
   350
    if (SDL_HasExactlyOneBitSet32(flags)) {
slouken@12422
   351
        int subsystem_index = SDL_MostSignificantBitIndex32(flags);
slouken@12422
   352
        return SDL_SubsystemRefCount[subsystem_index] ? flags : 0;
slouken@12422
   353
    }
slouken@12422
   354
slouken@1895
   355
    if (!flags) {
slouken@1895
   356
        flags = SDL_INIT_EVERYTHING;
slouken@1895
   357
    }
jorgen@6866
   358
jorgen@6866
   359
    num_subsystems = SDL_min(num_subsystems, SDL_MostSignificantBitIndex32(flags) + 1);
jorgen@6866
   360
jorgen@6866
   361
    /* Iterate over each bit in flags, and check the matching subsystem. */
jorgen@6866
   362
    for (i = 0; i < num_subsystems; ++i) {
jorgen@6866
   363
        if ((flags & 1) && SDL_SubsystemRefCount[i] > 0) {
jorgen@6866
   364
            initialized |= (1 << i);
jorgen@6866
   365
        }
jorgen@6866
   366
jorgen@6866
   367
        flags >>= 1;
jorgen@6866
   368
    }
jorgen@6866
   369
jorgen@6866
   370
    return initialized;
slouken@0
   371
}
slouken@0
   372
slouken@1895
   373
void
slouken@1895
   374
SDL_Quit(void)
slouken@0
   375
{
jorgen@6866
   376
    SDL_bInMainQuit = SDL_TRUE;
jorgen@6866
   377
slouken@1895
   378
    /* Quit all subsystems */
slouken@7110
   379
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@2713
   380
    SDL_HelperWindowDestroy();
slouken@2713
   381
#endif
slouken@1895
   382
    SDL_QuitSubSystem(SDL_INIT_EVERYTHING);
slouken@0
   383
slouken@8268
   384
#if !SDL_TIMERS_DISABLED
slouken@8268
   385
    SDL_TicksQuit();
slouken@8268
   386
#endif
slouken@8268
   387
slouken@5189
   388
    SDL_ClearHints();
slouken@3647
   389
    SDL_AssertionsQuit();
slouken@5221
   390
    SDL_LogResetPriorities();
slouken@6690
   391
jorgen@6866
   392
    /* Now that every subsystem has been quit, we reset the subsystem refcount
jorgen@6866
   393
     * and the list of initialized subsystems.
jorgen@6866
   394
     */
jorgen@6866
   395
    SDL_memset( SDL_SubsystemRefCount, 0x0, sizeof(SDL_SubsystemRefCount) );
jorgen@6866
   396
jorgen@6866
   397
    SDL_bInMainQuit = SDL_FALSE;
slouken@0
   398
}
slouken@0
   399
slouken@1895
   400
/* Get the library version number */
slouken@1895
   401
void
slouken@1895
   402
SDL_GetVersion(SDL_version * ver)
slouken@0
   403
{
slouken@1895
   404
    SDL_VERSION(ver);
slouken@0
   405
}
slouken@0
   406
slouken@2982
   407
/* Get the library source revision */
icculus@4419
   408
const char *
slouken@2996
   409
SDL_GetRevision(void)
slouken@2982
   410
{
slouken@2983
   411
    return SDL_REVISION;
slouken@2982
   412
}
slouken@2982
   413
slouken@5359
   414
/* Get the library source revision number */
slouken@5359
   415
int
slouken@5359
   416
SDL_GetRevisionNumber(void)
slouken@5359
   417
{
slouken@5359
   418
    return SDL_REVISION_NUMBER;
slouken@5359
   419
}
slouken@5359
   420
slouken@3319
   421
/* Get the name of the platform */
slouken@3319
   422
const char *
slouken@3319
   423
SDL_GetPlatform()
slouken@3319
   424
{
slouken@3319
   425
#if __AIX__
slouken@3319
   426
    return "AIX";
slouken@6441
   427
#elif __ANDROID__
slouken@6441
   428
    return "Android";
slouken@3319
   429
#elif __BSDI__
slouken@3319
   430
    return "BSDI";
slouken@3319
   431
#elif __DREAMCAST__
slouken@3319
   432
    return "Dreamcast";
philipp@9341
   433
#elif __EMSCRIPTEN__
philipp@9341
   434
    return "Emscripten";
slouken@3319
   435
#elif __FREEBSD__
slouken@3319
   436
    return "FreeBSD";
icculus@7346
   437
#elif __HAIKU__
icculus@7346
   438
    return "Haiku";
slouken@3319
   439
#elif __HPUX__
slouken@3319
   440
    return "HP-UX";
slouken@3319
   441
#elif __IRIX__
slouken@3319
   442
    return "Irix";
slouken@3319
   443
#elif __LINUX__
slouken@3319
   444
    return "Linux";
slouken@3319
   445
#elif __MINT__
slouken@3319
   446
    return "Atari MiNT";
slouken@3319
   447
#elif __MACOS__
slouken@3319
   448
    return "MacOS Classic";
slouken@3319
   449
#elif __MACOSX__
slouken@3319
   450
    return "Mac OS X";
slouken@8886
   451
#elif __NACL__
slouken@8886
   452
    return "NaCl";
slouken@3319
   453
#elif __NETBSD__
slouken@3319
   454
    return "NetBSD";
slouken@3319
   455
#elif __OPENBSD__
slouken@3319
   456
    return "OpenBSD";
slouken@3319
   457
#elif __OS2__
slouken@3319
   458
    return "OS/2";
slouken@3319
   459
#elif __OSF__
slouken@3319
   460
    return "OSF/1";
slouken@3319
   461
#elif __QNXNTO__
slouken@3319
   462
    return "QNX Neutrino";
slouken@3319
   463
#elif __RISCOS__
slouken@3319
   464
    return "RISC OS";
slouken@3319
   465
#elif __SOLARIS__
slouken@3319
   466
    return "Solaris";
slouken@5086
   467
#elif __WIN32__
slouken@3319
   468
    return "Windows";
dludwig@9223
   469
#elif __WINRT__
dludwig@9223
   470
    return "WinRT";
slime73@10340
   471
#elif __TVOS__
slime73@10340
   472
    return "tvOS";
slouken@3319
   473
#elif __IPHONEOS__
slouken@7592
   474
    return "iOS";
kimonline@7009
   475
#elif __PSP__
kimonline@7009
   476
    return "PlayStation Portable";
slouken@3319
   477
#else
slouken@3319
   478
    return "Unknown (see SDL_platform.h)";
slouken@3319
   479
#endif
slouken@3319
   480
}
slouken@3319
   481
slouken@12137
   482
SDL_bool
slouken@12137
   483
SDL_IsTablet()
slouken@12137
   484
{
slouken@12137
   485
#if __ANDROID__
slouken@12137
   486
    extern SDL_bool SDL_IsAndroidTablet(void);
slouken@12137
   487
    return SDL_IsAndroidTablet();
slouken@12137
   488
#elif __IPHONEOS__
slouken@12137
   489
    extern SDL_bool SDL_IsIPad(void);
slouken@12137
   490
    return SDL_IsIPad();
slouken@12137
   491
#else
slouken@12137
   492
    return SDL_FALSE;
slouken@12137
   493
#endif
slouken@12137
   494
}
slouken@12137
   495
slouken@11883
   496
#if defined(__WIN32__)
slouken@11883
   497
slouken@11885
   498
#if (!defined(HAVE_LIBC) || defined(__WATCOMC__)) && !defined(SDL_STATIC_LIB)
slouken@1465
   499
/* Need to include DllMain() on Watcom C for some reason.. */
slouken@1330
   500
slouken@1895
   501
BOOL APIENTRY
slouken@1895
   502
_DllMainCRTStartup(HANDLE hModule,
slouken@1895
   503
                   DWORD ul_reason_for_call, LPVOID lpReserved)
slouken@1330
   504
{
slouken@1895
   505
    switch (ul_reason_for_call) {
slouken@1895
   506
    case DLL_PROCESS_ATTACH:
slouken@1895
   507
    case DLL_THREAD_ATTACH:
slouken@1895
   508
    case DLL_THREAD_DETACH:
slouken@1895
   509
    case DLL_PROCESS_DETACH:
slouken@1895
   510
        break;
slouken@1895
   511
    }
slouken@1895
   512
    return TRUE;
slouken@1330
   513
}
slouken@11885
   514
#endif /* Building DLL */
slouken@1330
   515
slouken@11883
   516
#endif /* __WIN32__ */
slouken@11883
   517
jorgen@6927
   518
/* vi: set sts=4 ts=4 sw=4 expandtab: */