src/SDL_compat.c
author Sam Lantinga <slouken@libsdl.org>
Wed, 16 Feb 2011 01:40:44 -0800
changeset 5309 da080d3247c9
parent 5308 50ceebd6e12f
child 5312 035797f48321
permissions -rw-r--r--
Needed to allocate memory for the shadow surface if we needed to create one.
slouken@1895
     1
/*
slouken@1895
     2
    SDL - Simple DirectMedia Layer
slouken@5262
     3
    Copyright (C) 1997-2011 Sam Lantinga
slouken@1895
     4
slouken@1895
     5
    This library is free software; you can redistribute it and/or
slouken@1895
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1895
     7
    License as published by the Free Software Foundation; either
slouken@1895
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1895
     9
slouken@1895
    10
    This library is distributed in the hope that it will be useful,
slouken@1895
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1895
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1895
    13
    Lesser General Public License for more details.
slouken@1895
    14
slouken@1895
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1895
    16
    License along with this library; if not, write to the Free Software
slouken@1895
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1895
    18
slouken@1895
    19
    Sam Lantinga
slouken@1895
    20
    slouken@libsdl.org
slouken@1895
    21
*/
slouken@1895
    22
#include "SDL_config.h"
slouken@1895
    23
slouken@1895
    24
/* This file contains functions for backwards compatibility with SDL 1.2 */
slouken@1895
    25
slouken@1895
    26
#include "SDL.h"
slouken@1895
    27
#include "SDL_syswm.h"
slouken@1895
    28
slouken@1895
    29
#include "video/SDL_sysvideo.h"
slouken@1895
    30
#include "video/SDL_pixels_c.h"
slouken@5169
    31
#include "render/SDL_yuv_sw_c.h"
slouken@5169
    32
slouken@1895
    33
slouken@3685
    34
static SDL_Window *SDL_VideoWindow = NULL;
slouken@5294
    35
static SDL_Surface *SDL_WindowSurface = NULL;
bob@2328
    36
static SDL_Surface *SDL_VideoSurface = NULL;
bob@2328
    37
static SDL_Surface *SDL_ShadowSurface = NULL;
bob@2328
    38
static SDL_Surface *SDL_PublicSurface = NULL;
bob@2328
    39
static SDL_GLContext *SDL_VideoContext = NULL;
slouken@2829
    40
static Uint32 SDL_VideoFlags = 0;
slouken@5294
    41
static SDL_Rect SDL_VideoViewport;
bob@2328
    42
static char *wm_title = NULL;
slouken@2967
    43
static SDL_Surface *SDL_VideoIcon;
slouken@3280
    44
static int SDL_enabled_UNICODE = 0;
slouken@1895
    45
slouken@5169
    46
const char *
slouken@1895
    47
SDL_AudioDriverName(char *namebuf, int maxlen)
slouken@1895
    48
{
slouken@1895
    49
    const char *name = SDL_GetCurrentAudioDriver();
slouken@1895
    50
    if (name) {
slouken@5169
    51
        if (namebuf) {
slouken@5169
    52
            SDL_strlcpy(namebuf, name, maxlen);
slouken@5169
    53
            return namebuf;
slouken@5169
    54
        } else {
slouken@5169
    55
            return name;
slouken@5169
    56
        }
slouken@1895
    57
    }
slouken@1895
    58
    return NULL;
slouken@1895
    59
}
slouken@1895
    60
slouken@5169
    61
const char *
slouken@1895
    62
SDL_VideoDriverName(char *namebuf, int maxlen)
slouken@1895
    63
{
slouken@1895
    64
    const char *name = SDL_GetCurrentVideoDriver();
slouken@1895
    65
    if (name) {
slouken@5167
    66
        if (namebuf) {
slouken@5167
    67
            SDL_strlcpy(namebuf, name, maxlen);
slouken@5167
    68
            return namebuf;
slouken@5167
    69
        } else {
slouken@5167
    70
            return name;
slouken@5167
    71
        }
slouken@1895
    72
    }
slouken@1895
    73
    return NULL;
slouken@1895
    74
}
slouken@1895
    75
slouken@5244
    76
static int
slouken@5244
    77
GetVideoDisplay()
slouken@3518
    78
{
slouken@3518
    79
    const char *variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_DISPLAY");
slouken@3518
    80
    if ( !variable ) {
slouken@3518
    81
        variable = SDL_getenv("SDL_VIDEO_FULLSCREEN_HEAD");
slouken@3518
    82
    }
slouken@3518
    83
    if ( variable ) {
slouken@5250
    84
        return SDL_atoi(variable);
slouken@5244
    85
    } else {
slouken@5244
    86
        return 0;
slouken@3518
    87
    }
slouken@3518
    88
}
slouken@3518
    89
slouken@1895
    90
const SDL_VideoInfo *
slouken@1895
    91
SDL_GetVideoInfo(void)
slouken@1895
    92
{
slouken@1895
    93
    static SDL_VideoInfo info;
slouken@1967
    94
    SDL_DisplayMode mode;
slouken@1895
    95
slouken@1895
    96
    /* Memory leak, compatibility code, who cares? */
slouken@5244
    97
    if (!info.vfmt && SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode) == 0) {
slouken@5288
    98
        info.vfmt = SDL_AllocFormat(mode.format);
slouken@2862
    99
        info.current_w = mode.w;
slouken@2862
   100
        info.current_h = mode.h;
slouken@1895
   101
    }
slouken@1895
   102
    return &info;
slouken@1895
   103
}
slouken@1895
   104
slouken@1895
   105
int
slouken@1895
   106
SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
slouken@1895
   107
{
slouken@1895
   108
    int i, actual_bpp = 0;
slouken@1895
   109
slouken@1895
   110
    if (!SDL_GetVideoDevice()) {
slouken@1895
   111
        return 0;
slouken@1895
   112
    }
slouken@1895
   113
slouken@1895
   114
    if (!(flags & SDL_FULLSCREEN)) {
slouken@1967
   115
        SDL_DisplayMode mode;
slouken@5244
   116
        SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode);
slouken@1967
   117
        return SDL_BITSPERPIXEL(mode.format);
slouken@1895
   118
    }
slouken@1895
   119
slouken@5244
   120
    for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
slouken@1967
   121
        SDL_DisplayMode mode;
slouken@5244
   122
        SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
slouken@1967
   123
        if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) {
slouken@1967
   124
            if (!mode.format) {
slouken@1895
   125
                return bpp;
slouken@1895
   126
            }
slouken@1967
   127
            if (SDL_BITSPERPIXEL(mode.format) >= (Uint32) bpp) {
slouken@1967
   128
                actual_bpp = SDL_BITSPERPIXEL(mode.format);
slouken@1895
   129
            }
slouken@1895
   130
        }
slouken@1895
   131
    }
slouken@1895
   132
    return actual_bpp;
slouken@1895
   133
}
slouken@1895
   134
slouken@1895
   135
SDL_Rect **
slouken@3034
   136
SDL_ListModes(const SDL_PixelFormat * format, Uint32 flags)
slouken@1895
   137
{
slouken@1895
   138
    int i, nmodes;
slouken@1895
   139
    SDL_Rect **modes;
slouken@1895
   140
slouken@1895
   141
    if (!SDL_GetVideoDevice()) {
slouken@1895
   142
        return NULL;
slouken@1895
   143
    }
slouken@1895
   144
slouken@1895
   145
    if (!(flags & SDL_FULLSCREEN)) {
slouken@1895
   146
        return (SDL_Rect **) (-1);
slouken@1895
   147
    }
slouken@1895
   148
slouken@3034
   149
    if (!format) {
slouken@3034
   150
        format = SDL_GetVideoInfo()->vfmt;
slouken@3034
   151
    }
slouken@3034
   152
slouken@1895
   153
    /* Memory leak, but this is a compatibility function, who cares? */
slouken@1895
   154
    nmodes = 0;
slouken@1895
   155
    modes = NULL;
slouken@5244
   156
    for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) {
slouken@1967
   157
        SDL_DisplayMode mode;
slouken@5043
   158
        int bpp;
slouken@5043
   159
slouken@5244
   160
        SDL_GetDisplayMode(GetVideoDisplay(), i, &mode);
slouken@1967
   161
        if (!mode.w || !mode.h) {
slouken@1895
   162
            return (SDL_Rect **) (-1);
slouken@1895
   163
        }
slouken@5043
   164
        
slouken@5043
   165
        /* Copied from src/video/SDL_pixels.c:SDL_PixelFormatEnumToMasks */
slouken@5043
   166
        if (SDL_BYTESPERPIXEL(mode.format) <= 2) {
slouken@5043
   167
            bpp = SDL_BITSPERPIXEL(mode.format);
slouken@5043
   168
        } else {
slouken@5043
   169
            bpp = SDL_BYTESPERPIXEL(mode.format) * 8;
slouken@5043
   170
        }
slouken@5043
   171
slouken@5043
   172
        if (bpp != format->BitsPerPixel) {
slouken@1895
   173
            continue;
slouken@1895
   174
        }
slouken@1967
   175
        if (nmodes > 0 && modes[nmodes - 1]->w == mode.w
slouken@1967
   176
            && modes[nmodes - 1]->h == mode.h) {
slouken@1895
   177
            continue;
slouken@1895
   178
        }
slouken@1895
   179
slouken@1895
   180
        modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
slouken@1895
   181
        if (!modes) {
slouken@1895
   182
            return NULL;
slouken@1895
   183
        }
slouken@1895
   184
        modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
slouken@1895
   185
        if (!modes[nmodes]) {
slouken@1895
   186
            return NULL;
slouken@1895
   187
        }
slouken@1895
   188
        modes[nmodes]->x = 0;
slouken@1895
   189
        modes[nmodes]->y = 0;
slouken@1967
   190
        modes[nmodes]->w = mode.w;
slouken@1967
   191
        modes[nmodes]->h = mode.h;
slouken@1895
   192
        ++nmodes;
slouken@1895
   193
    }
slouken@1895
   194
    if (modes) {
slouken@1895
   195
        modes[nmodes] = NULL;
slouken@1895
   196
    }
slouken@1895
   197
    return modes;
slouken@1895
   198
}
slouken@1895
   199
slouken@1895
   200
static int
slouken@1895
   201
SDL_CompatEventFilter(void *userdata, SDL_Event * event)
slouken@1895
   202
{
slouken@1895
   203
    SDL_Event fake;
slouken@1895
   204
slouken@1895
   205
    switch (event->type) {
slouken@1895
   206
    case SDL_WINDOWEVENT:
slouken@1895
   207
        switch (event->window.event) {
slouken@1895
   208
        case SDL_WINDOWEVENT_EXPOSED:
slouken@4429
   209
            if (!SDL_HasEvent(SDL_VIDEOEXPOSE)) {
slouken@1895
   210
                fake.type = SDL_VIDEOEXPOSE;
slouken@1895
   211
                SDL_PushEvent(&fake);
slouken@1895
   212
            }
slouken@1895
   213
            break;
slouken@1895
   214
        case SDL_WINDOWEVENT_RESIZED:
slouken@4429
   215
            SDL_FlushEvent(SDL_VIDEORESIZE);
slouken@5294
   216
            /* We don't want to expose that the window width and height will
slouken@5294
   217
               be different if we don't get the desired fullscreen mode.
slouken@5294
   218
            */
slouken@5294
   219
            if (SDL_VideoWindow && !(SDL_GetWindowFlags(SDL_VideoWindow) & SDL_WINDOW_FULLSCREEN)) {
slouken@5294
   220
                fake.type = SDL_VIDEORESIZE;
slouken@5294
   221
                fake.resize.w = event->window.data1;
slouken@5294
   222
                fake.resize.h = event->window.data2;
slouken@5294
   223
                SDL_PushEvent(&fake);
slouken@5294
   224
            }
slouken@1895
   225
            break;
slouken@1895
   226
        case SDL_WINDOWEVENT_MINIMIZED:
slouken@1895
   227
            fake.type = SDL_ACTIVEEVENT;
slouken@1895
   228
            fake.active.gain = 0;
slouken@1895
   229
            fake.active.state = SDL_APPACTIVE;
slouken@1895
   230
            SDL_PushEvent(&fake);
slouken@1895
   231
            break;
slouken@1895
   232
        case SDL_WINDOWEVENT_RESTORED:
slouken@1895
   233
            fake.type = SDL_ACTIVEEVENT;
slouken@1895
   234
            fake.active.gain = 1;
slouken@1895
   235
            fake.active.state = SDL_APPACTIVE;
slouken@1895
   236
            SDL_PushEvent(&fake);
slouken@1895
   237
            break;
slouken@1895
   238
        case SDL_WINDOWEVENT_ENTER:
slouken@1895
   239
            fake.type = SDL_ACTIVEEVENT;
slouken@1895
   240
            fake.active.gain = 1;
slouken@1895
   241
            fake.active.state = SDL_APPMOUSEFOCUS;
slouken@1895
   242
            SDL_PushEvent(&fake);
slouken@1895
   243
            break;
slouken@1895
   244
        case SDL_WINDOWEVENT_LEAVE:
slouken@1895
   245
            fake.type = SDL_ACTIVEEVENT;
slouken@1895
   246
            fake.active.gain = 0;
slouken@1895
   247
            fake.active.state = SDL_APPMOUSEFOCUS;
slouken@1895
   248
            SDL_PushEvent(&fake);
slouken@1895
   249
            break;
slouken@1895
   250
        case SDL_WINDOWEVENT_FOCUS_GAINED:
slouken@1895
   251
            fake.type = SDL_ACTIVEEVENT;
slouken@1895
   252
            fake.active.gain = 1;
slouken@1895
   253
            fake.active.state = SDL_APPINPUTFOCUS;
slouken@1895
   254
            SDL_PushEvent(&fake);
slouken@1895
   255
            break;
slouken@1895
   256
        case SDL_WINDOWEVENT_FOCUS_LOST:
slouken@1895
   257
            fake.type = SDL_ACTIVEEVENT;
slouken@2058
   258
            fake.active.gain = 0;
slouken@1895
   259
            fake.active.state = SDL_APPINPUTFOCUS;
slouken@1895
   260
            SDL_PushEvent(&fake);
slouken@1895
   261
            break;
slouken@1895
   262
        case SDL_WINDOWEVENT_CLOSE:
slouken@1895
   263
            fake.type = SDL_QUIT;
slouken@1895
   264
            SDL_PushEvent(&fake);
slouken@1895
   265
            break;
slouken@1895
   266
        }
slouken@1895
   267
    case SDL_KEYDOWN:
slouken@1895
   268
    case SDL_KEYUP:
slouken@1895
   269
        {
slouken@1895
   270
            Uint32 unicode = 0;
slouken@1895
   271
            if (event->key.type == SDL_KEYDOWN && event->key.keysym.sym < 256) {
slouken@1895
   272
                unicode = event->key.keysym.sym;
slouken@1895
   273
                if (unicode >= 'a' && unicode <= 'z') {
slouken@1895
   274
                    int shifted = !!(event->key.keysym.mod & KMOD_SHIFT);
slouken@1895
   275
                    int capslock = !!(event->key.keysym.mod & KMOD_CAPS);
slouken@1895
   276
                    if ((shifted ^ capslock) != 0) {
slouken@1895
   277
                        unicode = SDL_toupper(unicode);
slouken@1895
   278
                    }
slouken@1895
   279
                }
slouken@1895
   280
            }
slouken@1895
   281
            if (unicode) {
slouken@1895
   282
                event->key.keysym.unicode = unicode;
slouken@1895
   283
            }
slouken@1895
   284
            break;
slouken@1895
   285
        }
slouken@2129
   286
    case SDL_TEXTINPUT:
slouken@2129
   287
        {
slouken@2129
   288
            /* FIXME: Generate an old style key repeat event if needed */
slouken@2130
   289
            //printf("TEXTINPUT: '%s'\n", event->text.text);
slouken@2129
   290
            break;
slouken@2129
   291
        }
slouken@5294
   292
    case SDL_MOUSEMOTION:
slouken@5294
   293
        {
slouken@5294
   294
            event->motion.x -= SDL_VideoViewport.x;
slouken@5294
   295
            event->motion.y -= SDL_VideoViewport.y;
slouken@5294
   296
            break;
slouken@5294
   297
        }
slouken@5294
   298
    case SDL_MOUSEBUTTONDOWN:
slouken@5294
   299
    case SDL_MOUSEBUTTONUP:
slouken@5294
   300
        {
slouken@5294
   301
            event->button.x -= SDL_VideoViewport.x;
slouken@5294
   302
            event->button.y -= SDL_VideoViewport.y;
slouken@5294
   303
            break;
slouken@5294
   304
        }
slouken@1895
   305
    case SDL_MOUSEWHEEL:
slouken@1895
   306
        {
slouken@1895
   307
            Uint8 button;
slouken@1895
   308
            int x, y;
slouken@1895
   309
slouken@2153
   310
            if (event->wheel.y == 0) {
slouken@2153
   311
                break;
slouken@2153
   312
            }
slouken@2153
   313
icculus@3585
   314
            SDL_GetMouseState(&x, &y);
slouken@1895
   315
slouken@2153
   316
            if (event->wheel.y > 0) {
slouken@2153
   317
                button = SDL_BUTTON_WHEELUP;
slouken@2153
   318
            } else {
slouken@2153
   319
                button = SDL_BUTTON_WHEELDOWN;
slouken@2153
   320
            }
slouken@2153
   321
slouken@2153
   322
            fake.button.button = button;
slouken@1895
   323
            fake.button.x = x;
slouken@1895
   324
            fake.button.y = y;
slouken@1895
   325
            fake.button.windowID = event->wheel.windowID;
slouken@1895
   326
slouken@2153
   327
            fake.type = SDL_MOUSEBUTTONDOWN;
slouken@2153
   328
            fake.button.state = SDL_PRESSED;
slouken@2153
   329
            SDL_PushEvent(&fake);
slouken@1895
   330
slouken@2153
   331
            fake.type = SDL_MOUSEBUTTONUP;
slouken@2153
   332
            fake.button.state = SDL_RELEASED;
slouken@2153
   333
            SDL_PushEvent(&fake);
slouken@1895
   334
            break;
slouken@1895
   335
        }
slouken@1895
   336
slouken@1895
   337
    }
slouken@1895
   338
    return 1;
slouken@1895
   339
}
slouken@1895
   340
slouken@1895
   341
static void
slouken@1895
   342
GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
slouken@1895
   343
{
slouken@5294
   344
    int display = GetVideoDisplay();
slouken@1895
   345
    const char *window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
slouken@1895
   346
    const char *center = SDL_getenv("SDL_VIDEO_CENTERED");
slouken@1895
   347
    if (window) {
slouken@1895
   348
        if (SDL_sscanf(window, "%d,%d", x, y) == 2) {
slouken@1895
   349
            return;
slouken@1895
   350
        }
slouken@1895
   351
        if (SDL_strcmp(window, "center") == 0) {
slouken@1895
   352
            center = window;
slouken@1895
   353
        }
slouken@1895
   354
    }
slouken@1895
   355
    if (center) {
slouken@5294
   356
        *x = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
slouken@5294
   357
        *y = SDL_WINDOWPOS_CENTERED_DISPLAY(display);
slouken@1895
   358
    }
slouken@1895
   359
}
slouken@1895
   360
slouken@2829
   361
static void
slouken@2829
   362
ClearVideoSurface()
slouken@2829
   363
{
slouken@5294
   364
    if (SDL_ShadowSurface) {
slouken@5294
   365
        SDL_FillRect(SDL_ShadowSurface, NULL,
slouken@5294
   366
            SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0));
slouken@5294
   367
    }
slouken@5294
   368
    SDL_FillRect(SDL_WindowSurface, NULL, 0);
slouken@5294
   369
    SDL_UpdateWindowSurface(SDL_VideoWindow);
slouken@2829
   370
}
slouken@2829
   371
slouken@3025
   372
static void
slouken@3028
   373
SetupScreenSaver(int flags)
slouken@3025
   374
{
slouken@3025
   375
    const char *env;
slouken@3025
   376
    SDL_bool allow_screensaver;
slouken@3025
   377
slouken@3028
   378
    /* Allow environment override of screensaver disable */
slouken@3028
   379
    env = SDL_getenv("SDL_VIDEO_ALLOW_SCREENSAVER");
slouken@3028
   380
    if (env) {
slouken@3028
   381
        allow_screensaver = SDL_atoi(env) ? SDL_TRUE : SDL_FALSE;
slouken@3028
   382
    } else if (flags & SDL_FULLSCREEN) {
slouken@3028
   383
        allow_screensaver = SDL_FALSE;
slouken@3028
   384
    } else {
slouken@3028
   385
        allow_screensaver = SDL_TRUE;
slouken@3028
   386
    }
slouken@3025
   387
    if (allow_screensaver) {
slouken@3025
   388
        SDL_EnableScreenSaver();
slouken@3025
   389
    } else {
slouken@3025
   390
        SDL_DisableScreenSaver();
slouken@3025
   391
    }
slouken@3025
   392
}
slouken@3025
   393
slouken@4472
   394
static int
slouken@2829
   395
SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
slouken@2829
   396
{
slouken@2829
   397
    int w, h;
slouken@2829
   398
slouken@2829
   399
    /* We can't resize something we don't have... */
slouken@5288
   400
    if (!SDL_VideoSurface) {
slouken@2829
   401
        return -1;
slouken@2829
   402
    }
slouken@2829
   403
slouken@2829
   404
    /* We probably have to recreate the window in fullscreen mode */
slouken@2829
   405
    if (flags & SDL_FULLSCREEN) {
slouken@2829
   406
        return -1;
slouken@2829
   407
    }
slouken@2829
   408
slouken@2829
   409
    /* I don't think there's any change we can gracefully make in flags */
slouken@2829
   410
    if (flags != SDL_VideoFlags) {
slouken@2829
   411
        return -1;
slouken@2829
   412
    }
slouken@5288
   413
    if (bpp != SDL_VideoSurface->format->BitsPerPixel) {
slouken@5288
   414
        return -1;
slouken@5288
   415
    }
slouken@2829
   416
slouken@2829
   417
    /* Resize the window */
slouken@2829
   418
    SDL_GetWindowSize(SDL_VideoWindow, &w, &h);
slouken@2829
   419
    if (w != width || h != height) {
slouken@2829
   420
        SDL_SetWindowSize(SDL_VideoWindow, width, height);
slouken@2829
   421
    }
slouken@2829
   422
slouken@2829
   423
    /* If we're in OpenGL mode, just resize the stub surface and we're done! */
slouken@2829
   424
    if (flags & SDL_OPENGL) {
slouken@2829
   425
        SDL_VideoSurface->w = width;
slouken@2829
   426
        SDL_VideoSurface->h = height;
slouken@2829
   427
        return 0;
slouken@2829
   428
    }
slouken@2829
   429
slouken@5294
   430
    SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow);
slouken@5294
   431
    if (!SDL_WindowSurface) {
slouken@2829
   432
        return -1;
slouken@2829
   433
    }
slouken@5294
   434
    if (SDL_VideoSurface->format != SDL_WindowSurface->format) {
slouken@5294
   435
        return -1;
slouken@5294
   436
    }
slouken@5294
   437
    SDL_VideoSurface->w = width;
slouken@5294
   438
    SDL_VideoSurface->h = height;
slouken@5294
   439
    SDL_VideoSurface->pixels = SDL_WindowSurface->pixels;
slouken@5294
   440
    SDL_VideoSurface->pitch = SDL_WindowSurface->pitch;
slouken@5294
   441
    SDL_SetClipRect(SDL_VideoSurface, NULL);
slouken@2829
   442
slouken@2829
   443
    if (SDL_ShadowSurface) {
slouken@2829
   444
        SDL_ShadowSurface->w = width;
slouken@2829
   445
        SDL_ShadowSurface->h = height;
slouken@2831
   446
        SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface);
slouken@2829
   447
        SDL_ShadowSurface->pixels =
slouken@2829
   448
            SDL_realloc(SDL_ShadowSurface->pixels,
slouken@2829
   449
                        SDL_ShadowSurface->h * SDL_ShadowSurface->pitch);
slouken@2829
   450
        SDL_SetClipRect(SDL_ShadowSurface, NULL);
slouken@2831
   451
        SDL_InvalidateMap(SDL_ShadowSurface->map);
slouken@5169
   452
    } else {
slouken@5169
   453
        SDL_PublicSurface = SDL_VideoSurface;
slouken@2829
   454
    }
slouken@2829
   455
slouken@2829
   456
    ClearVideoSurface();
slouken@2829
   457
slouken@2829
   458
    return 0;
slouken@2829
   459
}
slouken@2829
   460
slouken@1895
   461
SDL_Surface *
slouken@1895
   462
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
slouken@1895
   463
{
slouken@1967
   464
    SDL_DisplayMode desktop_mode;
slouken@5294
   465
    int display = GetVideoDisplay();
slouken@5294
   466
    int window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display);
slouken@5294
   467
    int window_y = SDL_WINDOWPOS_UNDEFINED_DISPLAY(display);
slouken@5294
   468
    int window_w;
slouken@5294
   469
    int window_h;
slouken@1895
   470
    Uint32 window_flags;
slouken@5159
   471
    Uint32 surface_flags;
slouken@1895
   472
slouken@1895
   473
    if (!SDL_GetVideoDevice()) {
slouken@1895
   474
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
slouken@1895
   475
            return NULL;
slouken@1895
   476
        }
slouken@1895
   477
    }
slouken@3139
   478
slouken@5294
   479
    SDL_GetDesktopDisplayMode(display, &desktop_mode);
slouken@3098
   480
slouken@3098
   481
    if (width == 0) {
slouken@3098
   482
        width = desktop_mode.w;
slouken@3098
   483
    }
slouken@3098
   484
    if (height == 0) {
slouken@3098
   485
        height = desktop_mode.h;
slouken@3098
   486
    }
slouken@5159
   487
    if (bpp == 0) {
slouken@5159
   488
        bpp = SDL_BITSPERPIXEL(desktop_mode.format);
slouken@5159
   489
    }
slouken@1895
   490
slouken@2829
   491
    /* See if we can simply resize the existing window and surface */
slouken@2829
   492
    if (SDL_ResizeVideoMode(width, height, bpp, flags) == 0) {
slouken@2829
   493
        return SDL_PublicSurface;
slouken@2829
   494
    }
slouken@2829
   495
slouken@1895
   496
    /* Destroy existing window */
slouken@1895
   497
    SDL_PublicSurface = NULL;
slouken@1895
   498
    if (SDL_ShadowSurface) {
slouken@5288
   499
        SDL_ShadowSurface->flags &= ~SDL_DONTFREE;
slouken@1895
   500
        SDL_FreeSurface(SDL_ShadowSurface);
slouken@1895
   501
        SDL_ShadowSurface = NULL;
slouken@1895
   502
    }
slouken@1895
   503
    if (SDL_VideoSurface) {
slouken@5294
   504
        SDL_VideoSurface->flags &= ~SDL_DONTFREE;
slouken@1895
   505
        SDL_FreeSurface(SDL_VideoSurface);
slouken@1895
   506
        SDL_VideoSurface = NULL;
slouken@1895
   507
    }
slouken@1912
   508
    if (SDL_VideoContext) {
bob@2328
   509
        /* SDL_GL_MakeCurrent(0, NULL); *//* Doesn't do anything */
slouken@1912
   510
        SDL_GL_DeleteContext(SDL_VideoContext);
slouken@1912
   511
        SDL_VideoContext = NULL;
slouken@1912
   512
    }
slouken@1895
   513
    if (SDL_VideoWindow) {
slouken@1895
   514
        SDL_GetWindowPosition(SDL_VideoWindow, &window_x, &window_y);
bob@2322
   515
        SDL_DestroyWindow(SDL_VideoWindow);
slouken@1895
   516
    }
slouken@1895
   517
slouken@1895
   518
    /* Set up the event filter */
slouken@1895
   519
    if (!SDL_GetEventFilter(NULL, NULL)) {
slouken@1895
   520
        SDL_SetEventFilter(SDL_CompatEventFilter, NULL);
slouken@1895
   521
    }
slouken@1895
   522
slouken@1895
   523
    /* Create a new window */
slouken@1895
   524
    window_flags = SDL_WINDOW_SHOWN;
slouken@1895
   525
    if (flags & SDL_FULLSCREEN) {
slouken@1895
   526
        window_flags |= SDL_WINDOW_FULLSCREEN;
slouken@1895
   527
    }
slouken@1895
   528
    if (flags & SDL_OPENGL) {
slouken@1895
   529
        window_flags |= SDL_WINDOW_OPENGL;
slouken@1895
   530
    }
slouken@1895
   531
    if (flags & SDL_RESIZABLE) {
slouken@1895
   532
        window_flags |= SDL_WINDOW_RESIZABLE;
slouken@1895
   533
    }
slouken@1895
   534
    if (flags & SDL_NOFRAME) {
slouken@1895
   535
        window_flags |= SDL_WINDOW_BORDERLESS;
slouken@1895
   536
    }
slouken@1895
   537
    GetEnvironmentWindowPosition(width, height, &window_x, &window_y);
slouken@1895
   538
    SDL_VideoWindow =
slouken@1895
   539
        SDL_CreateWindow(wm_title, window_x, window_y, width, height,
slouken@1895
   540
                         window_flags);
slouken@1895
   541
    if (!SDL_VideoWindow) {
slouken@1895
   542
        return NULL;
slouken@1895
   543
    }
slouken@2967
   544
    SDL_SetWindowIcon(SDL_VideoWindow, SDL_VideoIcon);
slouken@1895
   545
slouken@1895
   546
    window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
slouken@1895
   547
    surface_flags = 0;
slouken@1895
   548
    if (window_flags & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   549
        surface_flags |= SDL_FULLSCREEN;
slouken@1895
   550
    }
slouken@5267
   551
    if ((window_flags & SDL_WINDOW_OPENGL) && (flags & SDL_OPENGL)) {
slouken@1895
   552
        surface_flags |= SDL_OPENGL;
slouken@1895
   553
    }
slouken@1895
   554
    if (window_flags & SDL_WINDOW_RESIZABLE) {
slouken@1895
   555
        surface_flags |= SDL_RESIZABLE;
slouken@1895
   556
    }
slouken@1895
   557
    if (window_flags & SDL_WINDOW_BORDERLESS) {
slouken@1895
   558
        surface_flags |= SDL_NOFRAME;
slouken@1895
   559
    }
slouken@1895
   560
slouken@1895
   561
    /* If we're in OpenGL mode, just create a stub surface and we're done! */
slouken@1895
   562
    if (flags & SDL_OPENGL) {
slouken@1912
   563
        SDL_VideoContext = SDL_GL_CreateContext(SDL_VideoWindow);
slouken@1912
   564
        if (!SDL_VideoContext) {
slouken@1912
   565
            return NULL;
slouken@1912
   566
        }
slouken@1912
   567
        if (SDL_GL_MakeCurrent(SDL_VideoWindow, SDL_VideoContext) < 0) {
slouken@1912
   568
            return NULL;
slouken@1912
   569
        }
slouken@1895
   570
        SDL_VideoSurface =
slouken@1895
   571
            SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
slouken@1895
   572
        if (!SDL_VideoSurface) {
slouken@1895
   573
            return NULL;
slouken@1895
   574
        }
slouken@1895
   575
        SDL_VideoSurface->flags |= surface_flags;
slouken@1895
   576
        SDL_PublicSurface = SDL_VideoSurface;
slouken@1895
   577
        return SDL_PublicSurface;
slouken@1895
   578
    }
slouken@1895
   579
slouken@1895
   580
    /* Create the screen surface */
slouken@5294
   581
    SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow);
slouken@5294
   582
    if (!SDL_WindowSurface) {
slouken@1895
   583
        return NULL;
slouken@1895
   584
    }
slouken@5294
   585
slouken@5294
   586
    /* Center the public surface in the window surface */
slouken@5294
   587
    SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h);
slouken@5294
   588
    SDL_VideoViewport.x = (window_w - width)/2;
slouken@5294
   589
    SDL_VideoViewport.y = (window_h - height)/2;
slouken@5294
   590
    SDL_VideoViewport.w = width;
slouken@5294
   591
    SDL_VideoViewport.h = height;
slouken@5294
   592
slouken@5294
   593
    SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0);
slouken@1895
   594
    SDL_VideoSurface->flags |= surface_flags;
slouken@5294
   595
    SDL_VideoSurface->flags |= SDL_DONTFREE;
slouken@5294
   596
    SDL_FreeFormat(SDL_VideoSurface->format);
slouken@5294
   597
    SDL_VideoSurface->format = SDL_WindowSurface->format;
slouken@5294
   598
    SDL_VideoSurface->format->refcount++;
slouken@5294
   599
    SDL_VideoSurface->w = width;
slouken@5294
   600
    SDL_VideoSurface->h = height;
slouken@5294
   601
    SDL_VideoSurface->pitch = SDL_WindowSurface->pitch;
slouken@5294
   602
    SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels +
slouken@5294
   603
        SDL_VideoViewport.y * SDL_VideoSurface->pitch +
slouken@5294
   604
        SDL_VideoViewport.x  * SDL_VideoSurface->format->BytesPerPixel);
slouken@5294
   605
    SDL_SetClipRect(SDL_VideoSurface, NULL);
slouken@1895
   606
slouken@1895
   607
    /* Create a shadow surface if necessary */
slouken@2222
   608
    if ((bpp != SDL_VideoSurface->format->BitsPerPixel)
slouken@2222
   609
        && !(flags & SDL_ANYFORMAT)) {
slouken@2222
   610
        SDL_ShadowSurface =
slouken@2222
   611
            SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0);
slouken@1895
   612
        if (!SDL_ShadowSurface) {
slouken@1895
   613
            return NULL;
slouken@1895
   614
        }
slouken@1895
   615
        SDL_ShadowSurface->flags |= surface_flags;
slouken@5288
   616
        SDL_ShadowSurface->flags |= SDL_DONTFREE;
slouken@1895
   617
slouken@1895
   618
        /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
slouken@1895
   619
        if (SDL_ShadowSurface->format->palette) {
slouken@1895
   620
            SDL_ShadowSurface->flags |= SDL_HWPALETTE;
slouken@5149
   621
            SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
slouken@5149
   622
                             SDL_ShadowSurface->format->BitsPerPixel);
slouken@1895
   623
        }
slouken@5294
   624
        SDL_FillRect(SDL_ShadowSurface, NULL,
slouken@5294
   625
            SDL_MapRGB(SDL_ShadowSurface->format, 0, 0, 0));
slouken@1895
   626
    }
slouken@1895
   627
    SDL_PublicSurface =
slouken@1895
   628
        (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface);
slouken@1895
   629
slouken@2829
   630
    SDL_VideoFlags = flags;
slouken@2829
   631
slouken@2829
   632
    ClearVideoSurface();
slouken@1895
   633
slouken@3028
   634
    SetupScreenSaver(flags);
slouken@3025
   635
slouken@1895
   636
    /* We're finally done! */
slouken@1895
   637
    return SDL_PublicSurface;
slouken@1895
   638
}
slouken@1895
   639
slouken@1895
   640
SDL_Surface *
slouken@1895
   641
SDL_GetVideoSurface(void)
slouken@1895
   642
{
slouken@1895
   643
    return SDL_PublicSurface;
slouken@1895
   644
}
slouken@1895
   645
slouken@2266
   646
int
slouken@2266
   647
SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
slouken@2266
   648
{
slouken@2838
   649
    if (flag & SDL_SRCALPHA) {
slouken@2838
   650
        /* According to the docs, value is ignored for alpha surfaces */
slouken@2838
   651
        if (surface->format->Amask) {
slouken@2838
   652
            value = 0xFF;
slouken@2838
   653
        }
slouken@2266
   654
        SDL_SetSurfaceAlphaMod(surface, value);
slouken@2884
   655
        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
slouken@2266
   656
    } else {
slouken@2266
   657
        SDL_SetSurfaceAlphaMod(surface, 0xFF);
slouken@2884
   658
        SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
slouken@2266
   659
    }
slouken@2838
   660
    SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL));
slouken@2838
   661
slouken@2266
   662
    return 0;
slouken@2266
   663
}
slouken@2266
   664
slouken@1895
   665
SDL_Surface *
slouken@1895
   666
SDL_DisplayFormat(SDL_Surface * surface)
slouken@1895
   667
{
slouken@2807
   668
    SDL_PixelFormat *format;
slouken@1895
   669
slouken@1895
   670
    if (!SDL_PublicSurface) {
slouken@1895
   671
        SDL_SetError("No video mode has been set");
slouken@1895
   672
        return NULL;
slouken@1895
   673
    }
slouken@2807
   674
    format = SDL_PublicSurface->format;
slouken@1895
   675
slouken@1895
   676
    /* Set the flags appropriate for copying to display surface */
slouken@2807
   677
    return SDL_ConvertSurface(surface, format, SDL_RLEACCEL);
slouken@1895
   678
}
slouken@1895
   679
slouken@1895
   680
SDL_Surface *
slouken@1895
   681
SDL_DisplayFormatAlpha(SDL_Surface * surface)
slouken@1895
   682
{
slouken@1895
   683
    SDL_PixelFormat *vf;
slouken@1895
   684
    SDL_PixelFormat *format;
slouken@1895
   685
    SDL_Surface *converted;
slouken@1895
   686
    /* default to ARGB8888 */
slouken@1895
   687
    Uint32 amask = 0xff000000;
slouken@1895
   688
    Uint32 rmask = 0x00ff0000;
slouken@1895
   689
    Uint32 gmask = 0x0000ff00;
slouken@1895
   690
    Uint32 bmask = 0x000000ff;
slouken@1895
   691
slouken@1895
   692
    if (!SDL_PublicSurface) {
slouken@1895
   693
        SDL_SetError("No video mode has been set");
slouken@1895
   694
        return NULL;
slouken@1895
   695
    }
slouken@1895
   696
    vf = SDL_PublicSurface->format;
slouken@1895
   697
slouken@1895
   698
    switch (vf->BytesPerPixel) {
slouken@1895
   699
    case 2:
slouken@1895
   700
        /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
slouken@1895
   701
           For anything else (like ARGB4444) it doesn't matter
slouken@1895
   702
           since we have no special code for it anyway */
slouken@1895
   703
        if ((vf->Rmask == 0x1f) &&
slouken@1895
   704
            (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
slouken@1895
   705
            rmask = 0xff;
slouken@1895
   706
            bmask = 0xff0000;
slouken@1895
   707
        }
slouken@1895
   708
        break;
slouken@1895
   709
slouken@1895
   710
    case 3:
slouken@1895
   711
    case 4:
slouken@1895
   712
        /* Keep the video format, as long as the high 8 bits are
slouken@1895
   713
           unused or alpha */
slouken@1895
   714
        if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) {
slouken@1895
   715
            rmask = 0xff;
slouken@1895
   716
            bmask = 0xff0000;
slouken@1895
   717
        }
slouken@1895
   718
        break;
slouken@1895
   719
slouken@1895
   720
    default:
slouken@1895
   721
        /* We have no other optimised formats right now. When/if a new
slouken@1895
   722
           optimised alpha format is written, add the converter here */
slouken@1895
   723
        break;
slouken@1895
   724
    }
slouken@5288
   725
    format = SDL_AllocFormat(SDL_MasksToPixelFormatEnum(32, rmask,
slouken@5288
   726
                                                            gmask,
slouken@5288
   727
                                                            bmask,
slouken@5288
   728
                                                            amask));
slouken@5288
   729
    if (!format) {
slouken@5288
   730
        return NULL;
slouken@5288
   731
    }
slouken@2807
   732
    converted = SDL_ConvertSurface(surface, format, SDL_RLEACCEL);
slouken@1895
   733
    SDL_FreeFormat(format);
slouken@1895
   734
    return converted;
slouken@1895
   735
}
slouken@1895
   736
slouken@1895
   737
int
slouken@1895
   738
SDL_Flip(SDL_Surface * screen)
slouken@1895
   739
{
slouken@1895
   740
    SDL_UpdateRect(screen, 0, 0, 0, 0);
slouken@1895
   741
    return 0;
slouken@1895
   742
}
slouken@1895
   743
slouken@1895
   744
void
slouken@1895
   745
SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
slouken@1895
   746
{
slouken@1895
   747
    if (screen) {
slouken@1895
   748
        SDL_Rect rect;
slouken@1895
   749
slouken@1895
   750
        /* Fill the rectangle */
slouken@1897
   751
        rect.x = (int) x;
slouken@1897
   752
        rect.y = (int) y;
slouken@1897
   753
        rect.w = (int) (w ? w : screen->w);
slouken@1897
   754
        rect.h = (int) (h ? h : screen->h);
slouken@1895
   755
        SDL_UpdateRects(screen, 1, &rect);
slouken@1895
   756
    }
slouken@1895
   757
}
slouken@2735
   758
slouken@1895
   759
void
slouken@1895
   760
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
slouken@1895
   761
{
slouken@1895
   762
    int i;
slouken@1895
   763
slouken@1895
   764
    if (screen == SDL_ShadowSurface) {
slouken@1895
   765
        for (i = 0; i < numrects; ++i) {
slouken@1895
   766
            SDL_LowerBlit(SDL_ShadowSurface, &rects[i], SDL_VideoSurface,
slouken@1895
   767
                          &rects[i]);
slouken@1895
   768
        }
slouken@1895
   769
slouken@1895
   770
        /* Fall through to video surface update */
slouken@1895
   771
        screen = SDL_VideoSurface;
slouken@1895
   772
    }
slouken@1895
   773
    if (screen == SDL_VideoSurface) {
slouken@5294
   774
        if (SDL_VideoViewport.x || SDL_VideoViewport.y) {
slouken@5294
   775
            SDL_Rect *stackrects = SDL_stack_alloc(SDL_Rect, numrects);
slouken@5294
   776
            SDL_Rect *stackrect;
slouken@5294
   777
            const SDL_Rect *rect;
slouken@5294
   778
            
slouken@5294
   779
            /* Offset all the rectangles before updating */
slouken@5294
   780
            for (i = 0; i < numrects; ++i) {
slouken@5294
   781
                rect = &rects[i];
slouken@5294
   782
                stackrect = &stackrects[i];
slouken@5294
   783
                stackrect->x = SDL_VideoViewport.x + rect->x;
slouken@5294
   784
                stackrect->y = SDL_VideoViewport.y + rect->y;
slouken@5294
   785
                stackrect->w = rect->w;
slouken@5294
   786
                stackrect->h = rect->h;
slouken@5294
   787
            }
slouken@5297
   788
            SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, stackrects, numrects);
slouken@5294
   789
            SDL_stack_free(stackrects);
slouken@5294
   790
        } else {
slouken@5297
   791
            SDL_UpdateWindowSurfaceRects(SDL_VideoWindow, rects, numrects);
slouken@5294
   792
        }
slouken@1895
   793
    }
slouken@1895
   794
}
slouken@1895
   795
slouken@1895
   796
void
slouken@1895
   797
SDL_WM_SetCaption(const char *title, const char *icon)
slouken@1895
   798
{
slouken@1895
   799
    if (wm_title) {
slouken@1895
   800
        SDL_free(wm_title);
slouken@2037
   801
    }
slouken@2037
   802
    if (title) {
slouken@2037
   803
        wm_title = SDL_strdup(title);
slouken@1895
   804
    } else {
slouken@2037
   805
        wm_title = NULL;
slouken@1895
   806
    }
slouken@1895
   807
    SDL_SetWindowTitle(SDL_VideoWindow, wm_title);
slouken@1895
   808
}
slouken@1895
   809
slouken@1895
   810
void
slouken@2037
   811
SDL_WM_GetCaption(const char **title, const char **icon)
slouken@1895
   812
{
slouken@1895
   813
    if (title) {
slouken@1895
   814
        *title = wm_title;
slouken@1895
   815
    }
slouken@1895
   816
    if (icon) {
slouken@1895
   817
        *icon = "";
slouken@1895
   818
    }
slouken@1895
   819
}
slouken@1895
   820
slouken@1895
   821
void
slouken@1895
   822
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
slouken@1895
   823
{
slouken@2967
   824
    SDL_VideoIcon = icon;
slouken@1895
   825
}
slouken@1895
   826
slouken@1895
   827
int
slouken@1895
   828
SDL_WM_IconifyWindow(void)
slouken@1895
   829
{
slouken@1895
   830
    SDL_MinimizeWindow(SDL_VideoWindow);
slouken@1895
   831
    return 0;
slouken@1895
   832
}
slouken@1895
   833
slouken@1895
   834
int
slouken@1895
   835
SDL_WM_ToggleFullScreen(SDL_Surface * surface)
slouken@1895
   836
{
slouken@5308
   837
    int length;
slouken@5308
   838
    void *pixels;
slouken@5308
   839
    Uint8 *src, *dst;
slouken@5308
   840
    int row;
slouken@5308
   841
    int window_w;
slouken@5308
   842
    int window_h;
slouken@5308
   843
slouken@5308
   844
    if (!SDL_PublicSurface) {
slouken@5308
   845
        SDL_SetError("SDL_SetVideoMode() hasn't been called");
slouken@5308
   846
        return 0;
slouken@5308
   847
    }
slouken@5308
   848
slouken@5308
   849
    /* Copy the old bits out */
slouken@5309
   850
    length = SDL_PublicSurface->w * SDL_PublicSurface->format->BytesPerPixel;
slouken@5309
   851
    pixels = SDL_malloc(SDL_PublicSurface->h * length);
slouken@5308
   852
    if (pixels) {
slouken@5309
   853
        src = (Uint8*)SDL_PublicSurface->pixels;
slouken@5308
   854
        dst = (Uint8*)pixels;
slouken@5309
   855
        for (row = 0; row < SDL_PublicSurface->h; ++row) {
slouken@5308
   856
            SDL_memcpy(dst, src, length);
slouken@5309
   857
            src += SDL_PublicSurface->pitch;
slouken@5308
   858
            dst += length;
slouken@5308
   859
        }
slouken@5308
   860
    }
slouken@5308
   861
slouken@5308
   862
    /* Do the physical mode switch */
slouken@1895
   863
    if (SDL_GetWindowFlags(SDL_VideoWindow) & SDL_WINDOW_FULLSCREEN) {
slouken@1895
   864
        if (SDL_SetWindowFullscreen(SDL_VideoWindow, 0) < 0) {
slouken@1895
   865
            return 0;
slouken@1895
   866
        }
slouken@1895
   867
        SDL_PublicSurface->flags &= ~SDL_FULLSCREEN;
slouken@1895
   868
    } else {
slouken@1895
   869
        if (SDL_SetWindowFullscreen(SDL_VideoWindow, 1) < 0) {
slouken@1895
   870
            return 0;
slouken@1895
   871
        }
slouken@1895
   872
        SDL_PublicSurface->flags |= SDL_FULLSCREEN;
slouken@1895
   873
    }
slouken@5308
   874
slouken@5308
   875
    /* Recreate the screen surface */
slouken@5308
   876
    SDL_WindowSurface = SDL_GetWindowSurface(SDL_VideoWindow);
slouken@5308
   877
    if (!SDL_WindowSurface) {
slouken@5308
   878
        /* We're totally hosed... */
slouken@5308
   879
        return 0;
slouken@5308
   880
    }
slouken@5308
   881
slouken@5308
   882
    /* Center the public surface in the window surface */
slouken@5308
   883
    SDL_GetWindowSize(SDL_VideoWindow, &window_w, &window_h);
slouken@5308
   884
    SDL_VideoViewport.x = (window_w - SDL_VideoSurface->w)/2;
slouken@5308
   885
    SDL_VideoViewport.y = (window_h - SDL_VideoSurface->h)/2;
slouken@5308
   886
    SDL_VideoViewport.w = SDL_VideoSurface->w;
slouken@5308
   887
    SDL_VideoViewport.h = SDL_VideoSurface->h;
slouken@5308
   888
slouken@5308
   889
    /* Do some shuffling behind the application's back if format changes */
slouken@5308
   890
    if (SDL_VideoSurface->format->format != SDL_WindowSurface->format->format) {
slouken@5308
   891
        if (SDL_ShadowSurface) {
slouken@5308
   892
            if (SDL_ShadowSurface->format->format == SDL_WindowSurface->format->format) {
slouken@5308
   893
                /* Whee!  We don't need a shadow surface anymore! */
slouken@5308
   894
                SDL_VideoSurface->flags &= ~SDL_DONTFREE;
slouken@5308
   895
                SDL_FreeSurface(SDL_VideoSurface);
slouken@5308
   896
                SDL_free(SDL_ShadowSurface->pixels);
slouken@5308
   897
                SDL_VideoSurface = SDL_ShadowSurface;
slouken@5309
   898
                SDL_VideoSurface->flags |= SDL_PREALLOC;
slouken@5308
   899
                SDL_ShadowSurface = NULL;
slouken@5308
   900
            } else {
slouken@5308
   901
                /* No problem, just change the video surface format */
slouken@5308
   902
                SDL_FreeFormat(SDL_VideoSurface->format);
slouken@5308
   903
                SDL_VideoSurface->format = SDL_WindowSurface->format;
slouken@5308
   904
                SDL_VideoSurface->format->refcount++;
slouken@5308
   905
                SDL_InvalidateMap(SDL_ShadowSurface->map);
slouken@5308
   906
            }
slouken@5308
   907
        } else {
slouken@5308
   908
            /* We can make the video surface the shadow surface */
slouken@5308
   909
            SDL_ShadowSurface = SDL_VideoSurface;
slouken@5309
   910
            SDL_ShadowSurface->pitch = SDL_CalculatePitch(SDL_ShadowSurface);
slouken@5309
   911
            SDL_ShadowSurface->pixels = SDL_malloc(SDL_ShadowSurface->h * SDL_ShadowSurface->pitch);
slouken@5309
   912
            if (!SDL_ShadowSurface->pixels) {
slouken@5309
   913
                /* Uh oh, we're hosed */
slouken@5309
   914
                SDL_ShadowSurface = NULL;
slouken@5309
   915
                return 0;
slouken@5309
   916
            }
slouken@5309
   917
            SDL_ShadowSurface->flags &= ~SDL_PREALLOC;
slouken@5308
   918
slouken@5308
   919
            SDL_VideoSurface = SDL_CreateRGBSurfaceFrom(NULL, 0, 0, 32, 0, 0, 0, 0, 0);
slouken@5308
   920
            SDL_VideoSurface->flags = SDL_ShadowSurface->flags;
slouken@5309
   921
            SDL_VideoSurface->flags |= SDL_PREALLOC;
slouken@5308
   922
            SDL_FreeFormat(SDL_VideoSurface->format);
slouken@5308
   923
            SDL_VideoSurface->format = SDL_WindowSurface->format;
slouken@5308
   924
            SDL_VideoSurface->format->refcount++;
slouken@5308
   925
            SDL_VideoSurface->w = SDL_ShadowSurface->w;
slouken@5308
   926
            SDL_VideoSurface->h = SDL_ShadowSurface->h;
slouken@5308
   927
        }
slouken@5308
   928
    }
slouken@5308
   929
slouken@5308
   930
    /* Update the video surface */
slouken@5308
   931
    SDL_VideoSurface->pitch = SDL_WindowSurface->pitch;
slouken@5308
   932
    SDL_VideoSurface->pixels = (void *)((Uint8 *)SDL_WindowSurface->pixels +
slouken@5308
   933
        SDL_VideoViewport.y * SDL_VideoSurface->pitch +
slouken@5308
   934
        SDL_VideoViewport.x  * SDL_VideoSurface->format->BytesPerPixel);
slouken@5308
   935
    SDL_SetClipRect(SDL_VideoSurface, NULL);
slouken@5308
   936
slouken@5308
   937
    /* Copy the old bits back */
slouken@5308
   938
    if (pixels) {
slouken@5308
   939
        src = (Uint8*)pixels;
slouken@5309
   940
        dst = (Uint8*)SDL_PublicSurface->pixels;
slouken@5309
   941
        for (row = 0; row < SDL_PublicSurface->h; ++row) {
slouken@5308
   942
            SDL_memcpy(dst, src, length);
slouken@5308
   943
            src += length;
slouken@5309
   944
            dst += SDL_PublicSurface->pitch;
slouken@5308
   945
        }
slouken@5309
   946
        SDL_Flip(SDL_PublicSurface);
slouken@5308
   947
        SDL_free(pixels);
slouken@5308
   948
    }
slouken@5308
   949
slouken@5308
   950
    /* We're done! */
slouken@1895
   951
    return 1;
slouken@1895
   952
}
slouken@1895
   953
slouken@1895
   954
SDL_GrabMode
slouken@1895
   955
SDL_WM_GrabInput(SDL_GrabMode mode)
slouken@1895
   956
{
slouken@1895
   957
    if (mode != SDL_GRAB_QUERY) {
slouken@1895
   958
        SDL_SetWindowGrab(SDL_VideoWindow, mode);
slouken@1895
   959
    }
slouken@1895
   960
    return (SDL_GrabMode) SDL_GetWindowGrab(SDL_VideoWindow);
slouken@1895
   961
}
slouken@1895
   962
slouken@1895
   963
void
slouken@1895
   964
SDL_WarpMouse(Uint16 x, Uint16 y)
slouken@1895
   965
{
slouken@1895
   966
    SDL_WarpMouseInWindow(SDL_VideoWindow, x, y);
slouken@1895
   967
}
slouken@1895
   968
slouken@1895
   969
Uint8
slouken@1895
   970
SDL_GetAppState(void)
slouken@1895
   971
{
slouken@1895
   972
    Uint8 state = 0;
slouken@1895
   973
    Uint32 flags = 0;
slouken@1895
   974
slouken@1895
   975
    flags = SDL_GetWindowFlags(SDL_VideoWindow);
slouken@1895
   976
    if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
slouken@1895
   977
        state |= SDL_APPACTIVE;
slouken@1895
   978
    }
slouken@1895
   979
    if (flags & SDL_WINDOW_INPUT_FOCUS) {
slouken@1895
   980
        state |= SDL_APPINPUTFOCUS;
slouken@1895
   981
    }
slouken@1895
   982
    if (flags & SDL_WINDOW_MOUSE_FOCUS) {
slouken@1895
   983
        state |= SDL_APPMOUSEFOCUS;
slouken@1895
   984
    }
slouken@1895
   985
    return state;
slouken@1895
   986
}
slouken@1895
   987
slouken@1895
   988
const SDL_version *
slouken@1895
   989
SDL_Linked_Version(void)
slouken@1895
   990
{
slouken@1895
   991
    static SDL_version version;
slouken@1895
   992
    SDL_VERSION(&version);
slouken@1895
   993
    return &version;
slouken@1895
   994
}
slouken@1895
   995
slouken@1895
   996
int
slouken@1895
   997
SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
slouken@1895
   998
               int firstcolor, int ncolors)
slouken@1895
   999
{
slouken@1895
  1000
    return SDL_SetColors(surface, colors, firstcolor, ncolors);
slouken@1895
  1001
}
slouken@1895
  1002
slouken@1895
  1003
int
slouken@1895
  1004
SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
slouken@1895
  1005
              int ncolors)
slouken@1895
  1006
{
slouken@1895
  1007
    if (SDL_SetPaletteColors
slouken@1895
  1008
        (surface->format->palette, colors, firstcolor, ncolors) == 0) {
slouken@1895
  1009
        return 1;
slouken@1895
  1010
    } else {
slouken@1895
  1011
        return 0;
slouken@1895
  1012
    }
slouken@1895
  1013
}
slouken@1895
  1014
slouken@1895
  1015
int
slouken@1895
  1016
SDL_GetWMInfo(SDL_SysWMinfo * info)
slouken@1895
  1017
{
slouken@1895
  1018
    return SDL_GetWindowWMInfo(SDL_VideoWindow, info);
slouken@1895
  1019
}
slouken@1895
  1020
slouken@1895
  1021
#if 0
slouken@1895
  1022
void
slouken@1895
  1023
SDL_MoveCursor(int x, int y)
slouken@1895
  1024
{
slouken@1895
  1025
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1895
  1026
slouken@1895
  1027
    /* Erase and update the current mouse position */
slouken@1895
  1028
    if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
slouken@1895
  1029
        /* Erase and redraw mouse cursor in new position */
slouken@1895
  1030
        SDL_LockCursor();
slouken@1895
  1031
        SDL_EraseCursor(SDL_VideoSurface);
slouken@1895
  1032
        SDL_cursor->area.x = (x - SDL_cursor->hot_x);
slouken@1895
  1033
        SDL_cursor->area.y = (y - SDL_cursor->hot_y);
slouken@1895
  1034
        SDL_DrawCursor(SDL_VideoSurface);
slouken@1895
  1035
        SDL_UnlockCursor();
slouken@1895
  1036
    } else if (_this->MoveWMCursor) {
slouken@1895
  1037
        _this->MoveWMCursor(_this, x, y);
slouken@1895
  1038
    }
slouken@1895
  1039
}
slouken@1895
  1040
slouken@1895
  1041
/* Keep track of the current cursor colors */
slouken@1895
  1042
static int palette_changed = 1;
slouken@1895
  1043
static Uint8 pixels8[2];
slouken@1895
  1044
slouken@1895
  1045
void
slouken@1895
  1046
SDL_CursorPaletteChanged(void)
slouken@1895
  1047
{
slouken@1895
  1048
    palette_changed = 1;
slouken@1895
  1049
}
slouken@1895
  1050
slouken@1895
  1051
void
slouken@1895
  1052
SDL_MouseRect(SDL_Rect * area)
slouken@1895
  1053
{
slouken@1895
  1054
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1895
  1055
    int clip_diff;
slouken@1895
  1056
slouken@1895
  1057
    *area = SDL_cursor->area;
slouken@1895
  1058
    if (area->x < 0) {
slouken@1895
  1059
        area->w += area->x;
slouken@1895
  1060
        area->x = 0;
slouken@1895
  1061
    }
slouken@1895
  1062
    if (area->y < 0) {
slouken@1895
  1063
        area->h += area->y;
slouken@1895
  1064
        area->y = 0;
slouken@1895
  1065
    }
slouken@1895
  1066
    clip_diff = (area->x + area->w) - SDL_VideoSurface->w;
slouken@1895
  1067
    if (clip_diff > 0) {
slouken@1895
  1068
        area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
slouken@1895
  1069
    }
slouken@1895
  1070
    clip_diff = (area->y + area->h) - SDL_VideoSurface->h;
slouken@1895
  1071
    if (clip_diff > 0) {
slouken@1895
  1072
        area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
slouken@1895
  1073
    }
slouken@1895
  1074
}
slouken@1895
  1075
slouken@1895
  1076
static void
slouken@1895
  1077
SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
slouken@1895
  1078
{
slouken@1895
  1079
    const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
slouken@1895
  1080
    int i, w, h;
slouken@1895
  1081
    Uint8 *data, datab;
slouken@1895
  1082
    Uint8 *mask, maskb;
slouken@1895
  1083
slouken@1895
  1084
    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
slouken@1895
  1085
    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
slouken@1895
  1086
    switch (screen->format->BytesPerPixel) {
slouken@1895
  1087
slouken@1895
  1088
    case 1:
slouken@1895
  1089
        {
slouken@1895
  1090
            Uint8 *dst;
slouken@1895
  1091
            int dstskip;
slouken@1895
  1092
slouken@1895
  1093
            if (palette_changed) {
slouken@1895
  1094
                pixels8[0] =
slouken@1895
  1095
                    (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
slouken@1895
  1096
                pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
slouken@1895
  1097
                palette_changed = 0;
slouken@1895
  1098
            }
slouken@1895
  1099
            dst = (Uint8 *) screen->pixels +
slouken@1895
  1100
                (SDL_cursor->area.y + area->y) * screen->pitch +
slouken@1895
  1101
                SDL_cursor->area.x;
slouken@1895
  1102
            dstskip = screen->pitch - area->w;
slouken@1895
  1103
slouken@1895
  1104
            for (h = area->h; h; h--) {
slouken@1895
  1105
                for (w = area->w / 8; w; w--) {
slouken@1895
  1106
                    maskb = *mask++;
slouken@1895
  1107
                    datab = *data++;
slouken@1895
  1108
                    for (i = 0; i < 8; ++i) {
slouken@1895
  1109
                        if (maskb & 0x80) {
slouken@1895
  1110
                            *dst = pixels8[datab >> 7];
slouken@1895
  1111
                        }
slouken@1895
  1112
                        maskb <<= 1;
slouken@1895
  1113
                        datab <<= 1;
slouken@1895
  1114
                        dst++;
slouken@1895
  1115
                    }
slouken@1895
  1116
                }
slouken@1895
  1117
                dst += dstskip;
slouken@1895
  1118
            }
slouken@1895
  1119
        }
slouken@1895
  1120
        break;
slouken@1895
  1121
slouken@1895
  1122
    case 2:
slouken@1895
  1123
        {
slouken@1895
  1124
            Uint16 *dst;
slouken@1895
  1125
            int dstskip;
slouken@1895
  1126
slouken@1895
  1127
            dst = (Uint16 *) screen->pixels +
slouken@1895
  1128
                (SDL_cursor->area.y + area->y) * screen->pitch / 2 +
slouken@1895
  1129
                SDL_cursor->area.x;
slouken@1895
  1130
            dstskip = (screen->pitch / 2) - area->w;
slouken@1895
  1131
slouken@1895
  1132
            for (h = area->h; h; h--) {
slouken@1895
  1133
                for (w = area->w / 8; w; w--) {
slouken@1895
  1134
                    maskb = *mask++;
slouken@1895
  1135
                    datab = *data++;
slouken@1895
  1136
                    for (i = 0; i < 8; ++i) {
slouken@1895
  1137
                        if (maskb & 0x80) {
slouken@1895
  1138
                            *dst = (Uint16) pixels[datab >> 7];
slouken@1895
  1139
                        }
slouken@1895
  1140
                        maskb <<= 1;
slouken@1895
  1141
                        datab <<= 1;
slouken@1895
  1142
                        dst++;
slouken@1895
  1143
                    }
slouken@1895
  1144
                }
slouken@1895
  1145
                dst += dstskip;
slouken@1895
  1146
            }
slouken@1895
  1147
        }
slouken@1895
  1148
        break;
slouken@1895
  1149
slouken@1895
  1150
    case 3:
slouken@1895
  1151
        {
slouken@1895
  1152
            Uint8 *dst;
slouken@1895
  1153
            int dstskip;
slouken@1895
  1154
slouken@1895
  1155
            dst = (Uint8 *) screen->pixels +
slouken@1895
  1156
                (SDL_cursor->area.y + area->y) * screen->pitch +
slouken@1895
  1157
                SDL_cursor->area.x * 3;
slouken@1895
  1158
            dstskip = screen->pitch - area->w * 3;
slouken@1895
  1159
slouken@1895
  1160
            for (h = area->h; h; h--) {
slouken@1895
  1161
                for (w = area->w / 8; w; w--) {
slouken@1895
  1162
                    maskb = *mask++;
slouken@1895
  1163
                    datab = *data++;
slouken@1895
  1164
                    for (i = 0; i < 8; ++i) {
slouken@1895
  1165
                        if (maskb & 0x80) {
slouken@1895
  1166
                            SDL_memset(dst, pixels[datab >> 7], 3);
slouken@1895
  1167
                        }
slouken@1895
  1168
                        maskb <<= 1;
slouken@1895
  1169
                        datab <<= 1;
slouken@1895
  1170
                        dst += 3;
slouken@1895
  1171
                    }
slouken@1895
  1172
                }
slouken@1895
  1173
                dst += dstskip;
slouken@1895
  1174
            }
slouken@1895
  1175
        }
slouken@1895
  1176
        break;
slouken@1895
  1177
slouken@1895
  1178
    case 4:
slouken@1895
  1179
        {
slouken@1895
  1180
            Uint32 *dst;
slouken@1895
  1181
            int dstskip;
slouken@1895
  1182
slouken@1895
  1183
            dst = (Uint32 *) screen->pixels +
slouken@1895
  1184
                (SDL_cursor->area.y + area->y) * screen->pitch / 4 +
slouken@1895
  1185
                SDL_cursor->area.x;
slouken@1895
  1186
            dstskip = (screen->pitch / 4) - area->w;
slouken@1895
  1187
slouken@1895
  1188
            for (h = area->h; h; h--) {
slouken@1895
  1189
                for (w = area->w / 8; w; w--) {
slouken@1895
  1190
                    maskb = *mask++;
slouken@1895
  1191
                    datab = *data++;
slouken@1895
  1192
                    for (i = 0; i < 8; ++i) {
slouken@1895
  1193
                        if (maskb & 0x80) {
slouken@1895
  1194
                            *dst = pixels[datab >> 7];
slouken@1895
  1195
                        }
slouken@1895
  1196
                        maskb <<= 1;
slouken@1895
  1197
                        datab <<= 1;
slouken@1895
  1198
                        dst++;
slouken@1895
  1199
                    }
slouken@1895
  1200
                }
slouken@1895
  1201
                dst += dstskip;
slouken@1895
  1202
            }
slouken@1895
  1203
        }
slouken@1895
  1204
        break;
slouken@1895
  1205
    }
slouken@1895
  1206
}
slouken@1895
  1207
slouken@1895
  1208
static void
slouken@1895
  1209
SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
slouken@1895
  1210
{
slouken@1895
  1211
    const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
slouken@1895
  1212
    int h;
slouken@1895
  1213
    int x, minx, maxx;
slouken@1895
  1214
    Uint8 *data, datab = 0;
slouken@1895
  1215
    Uint8 *mask, maskb = 0;
slouken@1895
  1216
    Uint8 *dst;
slouken@1895
  1217
    int dstbpp, dstskip;
slouken@1895
  1218
slouken@1895
  1219
    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
slouken@1895
  1220
    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
slouken@1895
  1221
    dstbpp = screen->format->BytesPerPixel;
slouken@1895
  1222
    dst = (Uint8 *) screen->pixels +
slouken@1895
  1223
        (SDL_cursor->area.y + area->y) * screen->pitch +
slouken@1895
  1224
        SDL_cursor->area.x * dstbpp;
slouken@1895
  1225
    dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
slouken@1895
  1226
slouken@1895
  1227
    minx = area->x;
slouken@1895
  1228
    maxx = area->x + area->w;
slouken@1895
  1229
    if (screen->format->BytesPerPixel == 1) {
slouken@1895
  1230
        if (palette_changed) {
slouken@1895
  1231
            pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
slouken@1895
  1232
            pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
slouken@1895
  1233
            palette_changed = 0;
slouken@1895
  1234
        }
slouken@1895
  1235
        for (h = area->h; h; h--) {
slouken@1895
  1236
            for (x = 0; x < SDL_cursor->area.w; ++x) {
slouken@1895
  1237
                if ((x % 8) == 0) {
slouken@1895
  1238
                    maskb = *mask++;
slouken@1895
  1239
                    datab = *data++;
slouken@1895
  1240
                }
slouken@1895
  1241
                if ((x >= minx) && (x < maxx)) {
slouken@1895
  1242
                    if (maskb & 0x80) {
slouken@1895
  1243
                        SDL_memset(dst, pixels8[datab >> 7], dstbpp);
slouken@1895
  1244
                    }
slouken@1895
  1245
                }
slouken@1895
  1246
                maskb <<= 1;
slouken@1895
  1247
                datab <<= 1;
slouken@1895
  1248
                dst += dstbpp;
slouken@1895
  1249
            }
slouken@1895
  1250
            dst += dstskip;
slouken@1895
  1251
        }
slouken@1895
  1252
    } else {
slouken@1895
  1253
        for (h = area->h; h; h--) {
slouken@1895
  1254
            for (x = 0; x < SDL_cursor->area.w; ++x) {
slouken@1895
  1255
                if ((x % 8) == 0) {
slouken@1895
  1256
                    maskb = *mask++;
slouken@1895
  1257
                    datab = *data++;
slouken@1895
  1258
                }
slouken@1895
  1259
                if ((x >= minx) && (x < maxx)) {
slouken@1895
  1260
                    if (maskb & 0x80) {
slouken@1895
  1261
                        SDL_memset(dst, pixels[datab >> 7], dstbpp);
slouken@1895
  1262
                    }
slouken@1895
  1263
                }
slouken@1895
  1264
                maskb <<= 1;
slouken@1895
  1265
                datab <<= 1;
slouken@1895
  1266
                dst += dstbpp;
slouken@1895
  1267
            }
slouken@1895
  1268
            dst += dstskip;
slouken@1895
  1269
        }
slouken@1895
  1270
    }
slouken@1895
  1271
}
slouken@1895
  1272
slouken@1895
  1273
/* This handles the ugly work of converting the saved cursor background from
slouken@1895
  1274
   the pixel format of the shadow surface to that of the video surface.
slouken@1895
  1275
   This is only necessary when blitting from a shadow surface of a different
slouken@1895
  1276
   pixel format than the video surface, and using a software rendered cursor.
slouken@1895
  1277
*/
slouken@1895
  1278
static void
slouken@1895
  1279
SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
slouken@1895
  1280
{
slouken@1895
  1281
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1895
  1282
    SDL_BlitInfo info;
slouken@1895
  1283
    SDL_loblit RunBlit;
slouken@1895
  1284
slouken@1895
  1285
    /* Make sure we can steal the blit mapping */
slouken@1895
  1286
    if (screen->map->dst != SDL_VideoSurface) {
slouken@1895
  1287
        return;
slouken@1895
  1288
    }
slouken@1895
  1289
slouken@1895
  1290
    /* Set up the blit information */
slouken@1895
  1291
    info.s_pixels = SDL_cursor->save[1];
slouken@1895
  1292
    info.s_width = w;
slouken@1895
  1293
    info.s_height = h;
slouken@1895
  1294
    info.s_skip = 0;
slouken@1895
  1295
    info.d_pixels = SDL_cursor->save[0];
slouken@1895
  1296
    info.d_width = w;
slouken@1895
  1297
    info.d_height = h;
slouken@1895
  1298
    info.d_skip = 0;
slouken@1895
  1299
    info.aux_data = screen->map->sw_data->aux_data;
slouken@1895
  1300
    info.src = screen->format;
slouken@1895
  1301
    info.table = screen->map->table;
slouken@1895
  1302
    info.dst = SDL_VideoSurface->format;
slouken@1895
  1303
    RunBlit = screen->map->sw_data->blit;
slouken@1895
  1304
slouken@1895
  1305
    /* Run the actual software blit */
slouken@1895
  1306
    RunBlit(&info);
slouken@1895
  1307
}
slouken@1895
  1308
slouken@1895
  1309
void
slouken@1895
  1310
SDL_DrawCursorNoLock(SDL_Surface * screen)
slouken@1895
  1311
{
slouken@1895
  1312
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1895
  1313
    SDL_Rect area;
slouken@1895
  1314
slouken@1895
  1315
    /* Get the mouse rectangle, clipped to the screen */
slouken@1895
  1316
    SDL_MouseRect(&area);
slouken@1895
  1317
    if ((area.w == 0) || (area.h == 0)) {
slouken@1895
  1318
        return;
slouken@1895
  1319
    }
slouken@1895
  1320
slouken@1895
  1321
    /* Copy mouse background */
slouken@1895
  1322
    {
slouken@1895
  1323
        int w, h, screenbpp;
slouken@1895
  1324
        Uint8 *src, *dst;
slouken@1895
  1325
slouken@1895
  1326
        /* Set up the copy pointers */
slouken@1895
  1327
        screenbpp = screen->format->BytesPerPixel;
slouken@1895
  1328
        if ((screen == SDL_VideoSurface) ||
slouken@1895
  1329
            FORMAT_EQUAL(screen->format, SDL_VideoSurface->format)) {
slouken@1895
  1330
            dst = SDL_cursor->save[0];
slouken@1895
  1331
        } else {
slouken@1895
  1332
            dst = SDL_cursor->save[1];
slouken@1895
  1333
        }
slouken@1895
  1334
        src = (Uint8 *) screen->pixels + area.y * screen->pitch +
slouken@1895
  1335
            area.x * screenbpp;
slouken@1895
  1336
slouken@1895
  1337
        /* Perform the copy */
slouken@1895
  1338
        w = area.w * screenbpp;
slouken@1895
  1339
        h = area.h;
slouken@1895
  1340
        while (h--) {
slouken@1895
  1341
            SDL_memcpy(dst, src, w);
slouken@1895
  1342
            dst += w;
slouken@1895
  1343
            src += screen->pitch;
slouken@1895
  1344
        }
slouken@1895
  1345
    }
slouken@1895
  1346
slouken@1895
  1347
    /* Draw the mouse cursor */
slouken@1895
  1348
    area.x -= SDL_cursor->area.x;
slouken@1895
  1349
    area.y -= SDL_cursor->area.y;
slouken@1895
  1350
    if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
slouken@1895
  1351
        SDL_DrawCursorFast(screen, &area);
slouken@1895
  1352
    } else {
slouken@1895
  1353
        SDL_DrawCursorSlow(screen, &area);
slouken@1895
  1354
    }
slouken@1895
  1355
}
slouken@1895
  1356
slouken@1895
  1357
void
slouken@1895
  1358
SDL_DrawCursor(SDL_Surface * screen)
slouken@1895
  1359
{
slouken@1895
  1360
    /* Lock the screen if necessary */
slouken@1895
  1361
    if (screen == NULL) {
slouken@1895
  1362
        return;
slouken@1895
  1363
    }
slouken@1895
  1364
    if (SDL_MUSTLOCK(screen)) {
slouken@1895
  1365
        if (SDL_LockSurface(screen) < 0) {
slouken@1895
  1366
            return;
slouken@1895
  1367
        }
slouken@1895
  1368
    }
slouken@1895
  1369
slouken@1895
  1370
    SDL_DrawCursorNoLock(screen);
slouken@1895
  1371
slouken@1895
  1372
    /* Unlock the screen and update if necessary */
slouken@1895
  1373
    if (SDL_MUSTLOCK(screen)) {
slouken@1895
  1374
        SDL_UnlockSurface(screen);
slouken@1895
  1375
    }
slouken@2222
  1376
    if (screen->flags & SDL_SCREEN_SURFACE) {
slouken@1895
  1377
        SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1895
  1378
        SDL_Window *window;
slouken@1895
  1379
        SDL_Rect area;
slouken@1895
  1380
slouken@1895
  1381
        window = SDL_GetWindowFromSurface(screen);
slouken@1895
  1382
        if (!window) {
slouken@1895
  1383
            return;
slouken@1895
  1384
        }
slouken@1895
  1385
slouken@1895
  1386
        SDL_MouseRect(&area);
slouken@1895
  1387
slouken@1895
  1388
        if (_this->UpdateWindowSurface) {
slouken@1895
  1389
            _this->UpdateWindowSurface(_this, window, 1, &area);
slouken@1895
  1390
        }
slouken@1895
  1391
    }
slouken@1895
  1392
}
slouken@1895
  1393
slouken@1895
  1394
void
slouken@1895
  1395
SDL_EraseCursorNoLock(SDL_Surface * screen)
slouken@1895
  1396
{
slouken@1895
  1397
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1895
  1398
    SDL_Window *window;
slouken@1895
  1399
    SDL_Rect area;
slouken@1895
  1400
slouken@1895
  1401
    /* Get the window associated with the surface */
slouken@1895
  1402
    window = SDL_GetWindowFromSurface(screen);
slouken@1895
  1403
    if (!window || !window->surface) {
slouken@1895
  1404
        return;
slouken@1895
  1405
    }
slouken@1895
  1406
slouken@1895
  1407
    /* Get the mouse rectangle, clipped to the screen */
slouken@1895
  1408
    SDL_MouseRect(&area);
slouken@1895
  1409
    if ((area.w == 0) || (area.h == 0)) {
slouken@1895
  1410
        return;
slouken@1895
  1411
    }
slouken@1895
  1412
slouken@1895
  1413
    /* Copy mouse background */
slouken@1895
  1414
    {
slouken@1895
  1415
        int w, h, screenbpp;
slouken@1895
  1416
        Uint8 *src, *dst;
slouken@1895
  1417
slouken@1895
  1418
        /* Set up the copy pointers */
slouken@1895
  1419
        screenbpp = screen->format->BytesPerPixel;
slouken@1895
  1420
        if ((screen->flags & SDL_SCREEN_SURFACE) ||
slouken@1895
  1421
            FORMAT_EQUAL(screen->format, window->surface->format)) {
slouken@1895
  1422
            src = SDL_cursor->save[0];
slouken@1895
  1423
        } else {
slouken@1895
  1424
            src = SDL_cursor->save[1];
slouken@1895
  1425
        }
slouken@1895
  1426
        dst = (Uint8 *) screen->pixels + area.y * screen->pitch +
slouken@1895
  1427
            area.x * screenbpp;
slouken@1895
  1428
slouken@1895
  1429
        /* Perform the copy */
slouken@1895
  1430
        w = area.w * screenbpp;
slouken@1895
  1431
        h = area.h;
slouken@1895
  1432
        while (h--) {
slouken@1895
  1433
            SDL_memcpy(dst, src, w);
slouken@1895
  1434
            src += w;
slouken@1895
  1435
            dst += screen->pitch;
slouken@1895
  1436
        }
slouken@1895
  1437
slouken@1895
  1438
        /* Perform pixel conversion on cursor background */
slouken@1895
  1439
        if (src > SDL_cursor->save[1]) {
slouken@1895
  1440
            SDL_ConvertCursorSave(screen, area.w, area.h);
slouken@1895
  1441
        }
slouken@1895
  1442
    }
slouken@1895
  1443
}
slouken@1895
  1444
slouken@1895
  1445
void
slouken@1895
  1446
SDL_EraseCursor(SDL_Surface * screen)
slouken@1895
  1447
{
slouken@1895
  1448
    /* Lock the screen if necessary */
slouken@1895
  1449
    if (screen == NULL) {
slouken@1895
  1450
        return;
slouken@1895
  1451
    }
slouken@1895
  1452
    if (SDL_MUSTLOCK(screen)) {
slouken@1895
  1453
        if (SDL_LockSurface(screen) < 0) {
slouken@1895
  1454
            return;
slouken@1895
  1455
        }
slouken@1895
  1456
    }
slouken@1895
  1457
slouken@1895
  1458
    SDL_EraseCursorNoLock(screen);
slouken@1895
  1459
slouken@1895
  1460
    /* Unlock the screen and update if necessary */
slouken@1895
  1461
    if (SDL_MUSTLOCK(screen)) {
slouken@1895
  1462
        SDL_UnlockSurface(screen);
slouken@1895
  1463
    }
slouken@2222
  1464
    if (screen->flags & SDL_SCREEN_SURFACE) {
slouken@1895
  1465
        SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1895
  1466
        SDL_Window *window;
slouken@1895
  1467
        SDL_Rect area;
slouken@1895
  1468
slouken@1895
  1469
        window = SDL_GetWindowFromSurface(screen);
slouken@1895
  1470
        if (!window) {
slouken@1895
  1471
            return;
slouken@1895
  1472
        }
slouken@1895
  1473
slouken@1895
  1474
        SDL_MouseRect(&area);
slouken@1895
  1475
slouken@1895
  1476
        if (_this->UpdateWindowSurface) {
slouken@1895
  1477
            _this->UpdateWindowSurface(_this, window, 1, &area);
slouken@1895
  1478
        }
slouken@1895
  1479
    }
slouken@1895
  1480
}
slouken@1895
  1481
slouken@1895
  1482
/* Reset the cursor on video mode change
slouken@1895
  1483
   FIXME:  Keep track of all cursors, and reset them all.
slouken@1895
  1484
 */
slouken@1895
  1485
void
slouken@1895
  1486
SDL_ResetCursor(void)
slouken@1895
  1487
{
slouken@1895
  1488
    int savelen;
slouken@1895
  1489
slouken@1895
  1490
    if (SDL_cursor) {
slouken@1895
  1491
        savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h;
slouken@1895
  1492
        SDL_cursor->area.x = 0;
slouken@1895
  1493
        SDL_cursor->area.y = 0;
slouken@1895
  1494
        SDL_memset(SDL_cursor->save[0], 0, savelen);
slouken@1895
  1495
    }
slouken@1895
  1496
}
slouken@1895
  1497
#endif
slouken@1895
  1498
slouken@1895
  1499
struct private_yuvhwdata
slouken@1895
  1500
{
slouken@5169
  1501
    SDL_SW_YUVTexture *texture;
slouken@5169
  1502
    SDL_Surface *display;
slouken@5169
  1503
    Uint32 display_format;
slouken@1895
  1504
};
slouken@1895
  1505
slouken@1895
  1506
SDL_Overlay *
slouken@1895
  1507
SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display)
slouken@1895
  1508
{
slouken@1895
  1509
    SDL_Overlay *overlay;
slouken@1895
  1510
    Uint32 texture_format;
slouken@5169
  1511
    SDL_SW_YUVTexture *texture;
slouken@1895
  1512
slouken@1895
  1513
    if ((display->flags & SDL_OPENGL) == SDL_OPENGL) {
slouken@1895
  1514
        SDL_SetError("YUV overlays are not supported in OpenGL mode");
slouken@1895
  1515
        return NULL;
slouken@1895
  1516
    }
slouken@1895
  1517
slouken@1895
  1518
    if (display != SDL_PublicSurface) {
slouken@1895
  1519
        SDL_SetError("YUV display is only supported on the screen surface");
slouken@1895
  1520
        return NULL;
slouken@1895
  1521
    }
slouken@1895
  1522
slouken@1895
  1523
    switch (format) {
slouken@1895
  1524
    case SDL_YV12_OVERLAY:
slouken@1965
  1525
        texture_format = SDL_PIXELFORMAT_YV12;
slouken@1895
  1526
        break;
slouken@1895
  1527
    case SDL_IYUV_OVERLAY:
slouken@1965
  1528
        texture_format = SDL_PIXELFORMAT_IYUV;
slouken@1895
  1529
        break;
slouken@1895
  1530
    case SDL_YUY2_OVERLAY:
slouken@1965
  1531
        texture_format = SDL_PIXELFORMAT_YUY2;
slouken@1895
  1532
        break;
slouken@1895
  1533
    case SDL_UYVY_OVERLAY:
slouken@1965
  1534
        texture_format = SDL_PIXELFORMAT_UYVY;
slouken@1895
  1535
        break;
slouken@1895
  1536
    case SDL_YVYU_OVERLAY:
slouken@1965
  1537
        texture_format = SDL_PIXELFORMAT_YVYU;
slouken@1895
  1538
        break;
slouken@1895
  1539
    default:
slouken@1895
  1540
        SDL_SetError("Unknown YUV format");
slouken@1895
  1541
        return NULL;
slouken@1895
  1542
    }
slouken@1895
  1543
slouken@1895
  1544
    overlay = (SDL_Overlay *) SDL_malloc(sizeof(*overlay));
slouken@1895
  1545
    if (!overlay) {
slouken@1895
  1546
        SDL_OutOfMemory();
slouken@1895
  1547
        return NULL;
slouken@1895
  1548
    }
slouken@1895
  1549
    SDL_zerop(overlay);
slouken@1895
  1550
slouken@1895
  1551
    overlay->hwdata =
slouken@1895
  1552
        (struct private_yuvhwdata *) SDL_malloc(sizeof(*overlay->hwdata));
slouken@1895
  1553
    if (!overlay->hwdata) {
slouken@1895
  1554
        SDL_free(overlay);
slouken@1895
  1555
        SDL_OutOfMemory();
slouken@1895
  1556
        return NULL;
slouken@1895
  1557
    }
slouken@1895
  1558
slouken@5169
  1559
    texture = SDL_SW_CreateYUVTexture(texture_format, w, h);
slouken@5169
  1560
    if (!texture) {
slouken@5169
  1561
        SDL_free(overlay->hwdata);
slouken@5169
  1562
        SDL_free(overlay);
slouken@5169
  1563
        return NULL;
slouken@5169
  1564
    }
slouken@5169
  1565
    overlay->hwdata->texture = texture;
slouken@5169
  1566
    overlay->hwdata->display = NULL;
slouken@5169
  1567
    overlay->hwdata->display_format = SDL_PIXELFORMAT_UNKNOWN;
slouken@5169
  1568
slouken@1895
  1569
    overlay->format = format;
slouken@1895
  1570
    overlay->w = w;
slouken@1895
  1571
    overlay->h = h;
slouken@1895
  1572
    if (format == SDL_YV12_OVERLAY || format == SDL_IYUV_OVERLAY) {
slouken@1895
  1573
        overlay->planes = 3;
slouken@1895
  1574
    } else {
slouken@1895
  1575
        overlay->planes = 1;
slouken@1895
  1576
    }
slouken@5169
  1577
    overlay->pitches = texture->pitches;
slouken@5169
  1578
    overlay->pixels = texture->planes;
slouken@1895
  1579
slouken@1895
  1580
    return overlay;
slouken@1895
  1581
}
slouken@1895
  1582
slouken@1895
  1583
int
slouken@1895
  1584
SDL_LockYUVOverlay(SDL_Overlay * overlay)
slouken@1895
  1585
{
slouken@5169
  1586
    SDL_Rect rect;
slouken@1895
  1587
    void *pixels;
slouken@1895
  1588
    int pitch;
slouken@2202
  1589
slouken@2202
  1590
    if (!overlay) {
slouken@2202
  1591
        SDL_SetError("Passed a NULL overlay");
slouken@2202
  1592
        return -1;
slouken@2202
  1593
    }
slouken@5169
  1594
slouken@5169
  1595
    rect.x = 0;
slouken@5169
  1596
    rect.y = 0;
slouken@5169
  1597
    rect.w = overlay->w;
slouken@5169
  1598
    rect.h = overlay->h;
slouken@5169
  1599
slouken@5169
  1600
    if (SDL_SW_LockYUVTexture(overlay->hwdata->texture, &rect, &pixels, &pitch) < 0) {
slouken@5156
  1601
        return -1;
slouken@2786
  1602
    }
slouken@5169
  1603
slouken@2226
  1604
    overlay->pixels[0] = (Uint8 *) pixels;
slouken@2226
  1605
    overlay->pitches[0] = pitch;
slouken@1895
  1606
    switch (overlay->format) {
slouken@1895
  1607
    case SDL_YV12_OVERLAY:
slouken@1895
  1608
    case SDL_IYUV_OVERLAY:
slouken@2226
  1609
        overlay->pitches[1] = pitch / 2;
slouken@2226
  1610
        overlay->pitches[2] = pitch / 2;
slouken@1895
  1611
        overlay->pixels[1] =
slouken@1895
  1612
            overlay->pixels[0] + overlay->pitches[0] * overlay->h;
slouken@1895
  1613
        overlay->pixels[2] =
slouken@2226
  1614
            overlay->pixels[1] + overlay->pitches[1] * overlay->h / 2;
slouken@1895
  1615
        break;
slouken@1895
  1616
    case SDL_YUY2_OVERLAY:
slouken@1895
  1617
    case SDL_UYVY_OVERLAY:
slouken@1895
  1618
    case SDL_YVYU_OVERLAY:
slouken@1895
  1619
        break;
slouken@1895
  1620
    }
slouken@1895
  1621
    return 0;
slouken@1895
  1622
}
slouken@1895
  1623
slouken@1895
  1624
void
slouken@1895
  1625
SDL_UnlockYUVOverlay(SDL_Overlay * overlay)
slouken@1895
  1626
{
slouken@2202
  1627
    if (!overlay) {
slouken@2202
  1628
        return;
slouken@2202
  1629
    }
slouken@5169
  1630
slouken@5169
  1631
    SDL_SW_UnlockYUVTexture(overlay->hwdata->texture);
slouken@1895
  1632
}
slouken@1895
  1633
slouken@1895
  1634
int
slouken@1895
  1635
SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect)
slouken@1895
  1636
{
slouken@5169
  1637
    SDL_Surface *display;
slouken@5169
  1638
    SDL_Rect src_rect;
slouken@5169
  1639
    SDL_Rect dst_rect;
slouken@5169
  1640
    void *pixels;
slouken@5169
  1641
slouken@2202
  1642
    if (!overlay || !dstrect) {
slouken@2202
  1643
        SDL_SetError("Passed a NULL overlay or dstrect");
slouken@2202
  1644
        return -1;
slouken@2202
  1645
    }
slouken@5169
  1646
slouken@5169
  1647
    display = overlay->hwdata->display;
slouken@5169
  1648
    if (display != SDL_VideoSurface) {
slouken@5169
  1649
        overlay->hwdata->display = display = SDL_VideoSurface;
slouken@5169
  1650
        overlay->hwdata->display_format = SDL_MasksToPixelFormatEnum(
slouken@5169
  1651
                                                display->format->BitsPerPixel,
slouken@5169
  1652
                                                display->format->Rmask,
slouken@5169
  1653
                                                display->format->Gmask,
slouken@5169
  1654
                                                display->format->Bmask,
slouken@5169
  1655
                                                display->format->Amask);
slouken@5169
  1656
    }
slouken@5169
  1657
slouken@5169
  1658
    src_rect.x = 0;
slouken@5169
  1659
    src_rect.y = 0;
slouken@5169
  1660
    src_rect.w = overlay->w;
slouken@5169
  1661
    src_rect.h = overlay->h;
slouken@5169
  1662
slouken@5169
  1663
    if (!SDL_IntersectRect(&display->clip_rect, dstrect, &dst_rect)) {
slouken@5169
  1664
        return 0;
slouken@5169
  1665
    }
slouken@5169
  1666
     
slouken@5169
  1667
    pixels = (void *)((Uint8 *)display->pixels +
slouken@5169
  1668
                        dst_rect.y * display->pitch +
slouken@5169
  1669
                        dst_rect.x * display->format->BytesPerPixel);
slouken@5169
  1670
slouken@5169
  1671
    if (SDL_SW_CopyYUVToRGB(overlay->hwdata->texture, &src_rect,
slouken@5169
  1672
                            overlay->hwdata->display_format,
slouken@5169
  1673
                            dst_rect.w, dst_rect.h,
slouken@5169
  1674
                            pixels, display->pitch) < 0) {
slouken@1895
  1675
        return -1;
slouken@1895
  1676
    }
slouken@5169
  1677
    SDL_UpdateWindowSurface(SDL_VideoWindow);
slouken@1895
  1678
    return 0;
slouken@1895
  1679
}
slouken@1895
  1680
slouken@1895
  1681
void
slouken@1895
  1682
SDL_FreeYUVOverlay(SDL_Overlay * overlay)
slouken@1895
  1683
{
slouken@2202
  1684
    if (!overlay) {
slouken@2202
  1685
        return;
slouken@2202
  1686
    }
slouken@2202
  1687
    if (overlay->hwdata) {
slouken@3685
  1688
        if (overlay->hwdata->texture) {
slouken@5169
  1689
            SDL_SW_DestroyYUVTexture(overlay->hwdata->texture);
slouken@1895
  1690
        }
slouken@2202
  1691
        SDL_free(overlay->hwdata);
slouken@1895
  1692
    }
slouken@2202
  1693
    SDL_free(overlay);
slouken@1895
  1694
}
slouken@1895
  1695
slouken@1912
  1696
void
slouken@1912
  1697
SDL_GL_SwapBuffers(void)
slouken@1912
  1698
{
slouken@1912
  1699
    SDL_GL_SwapWindow(SDL_VideoWindow);
slouken@1912
  1700
}
slouken@1912
  1701
slouken@5243
  1702
int
slouken@5243
  1703
SDL_SetGamma(float red, float green, float blue)
slouken@5243
  1704
{
slouken@5243
  1705
    SDL_Unsupported();
slouken@5243
  1706
    return -1;
slouken@5243
  1707
}
slouken@5243
  1708
slouken@5243
  1709
int
slouken@5243
  1710
SDL_SetGammaRamp(const Uint16 * red, const Uint16 * green, const Uint16 * blue)
slouken@5243
  1711
{
slouken@5243
  1712
    SDL_Unsupported();
slouken@5243
  1713
    return -1;
slouken@5243
  1714
}
slouken@5243
  1715
slouken@5243
  1716
int
slouken@5243
  1717
SDL_GetGammaRamp(Uint16 * red, Uint16 * green, Uint16 * blue)
slouken@5243
  1718
{
slouken@5243
  1719
    SDL_Unsupported();
slouken@5243
  1720
    return -1;
slouken@5243
  1721
}
slouken@2129
  1722
slouken@2129
  1723
int
slouken@2129
  1724
SDL_EnableKeyRepeat(int delay, int interval)
slouken@2129
  1725
{
slouken@2129
  1726
    return 0;
slouken@2129
  1727
}
slouken@2129
  1728
slouken@2129
  1729
void
slouken@2129
  1730
SDL_GetKeyRepeat(int *delay, int *interval)
slouken@2129
  1731
{
slouken@2129
  1732
    if (delay) {
slouken@2129
  1733
        *delay = SDL_DEFAULT_REPEAT_DELAY;
slouken@2129
  1734
    }
slouken@2129
  1735
    if (interval) {
slouken@2129
  1736
        *interval = SDL_DEFAULT_REPEAT_INTERVAL;
slouken@2129
  1737
    }
slouken@2129
  1738
}
slouken@2129
  1739
slouken@2303
  1740
int
slouken@2303
  1741
SDL_EnableUNICODE(int enable)
slouken@2303
  1742
{
slouken@3280
  1743
    int previous = SDL_enabled_UNICODE;
slouken@3280
  1744
slouken@3280
  1745
    switch (enable) {
slouken@3280
  1746
    case 1:
slouken@3280
  1747
        SDL_enabled_UNICODE = 1;
dewyatt@4753
  1748
        SDL_StartTextInput();
slouken@3280
  1749
        break;
slouken@3280
  1750
    case 0:
slouken@3280
  1751
        SDL_enabled_UNICODE = 0;
dewyatt@4753
  1752
        SDL_StopTextInput();
slouken@3280
  1753
        break;
slouken@3280
  1754
    }
slouken@3280
  1755
    return previous;
slouken@2303
  1756
}
slouken@2303
  1757
slouken@5111
  1758
static Uint32
slouken@5111
  1759
SDL_SetTimerCallback(Uint32 interval, void* param)
slouken@5111
  1760
{
slouken@5111
  1761
    return ((SDL_OldTimerCallback)param)(interval);
slouken@5111
  1762
}
slouken@5111
  1763
slouken@5111
  1764
int
slouken@5111
  1765
SDL_SetTimer(Uint32 interval, SDL_OldTimerCallback callback)
slouken@5111
  1766
{
slouken@5111
  1767
    static SDL_TimerID compat_timer;
slouken@5111
  1768
slouken@5111
  1769
    if (compat_timer) {
slouken@5111
  1770
        SDL_RemoveTimer(compat_timer);
slouken@5111
  1771
        compat_timer = 0;
slouken@5111
  1772
    }
slouken@5111
  1773
slouken@5111
  1774
    if (interval && callback) {
slouken@5111
  1775
        compat_timer = SDL_AddTimer(interval, SDL_SetTimerCallback, callback);
slouken@5111
  1776
        if (!compat_timer) {
slouken@5111
  1777
            return -1;
slouken@5111
  1778
        }
slouken@5111
  1779
    }
slouken@5111
  1780
    return 0;
slouken@5111
  1781
}
slouken@5111
  1782
icculus@3581
  1783
int
icculus@3581
  1784
SDL_putenv(const char *_var)
icculus@3581
  1785
{
icculus@3581
  1786
    char *ptr = NULL;
icculus@3581
  1787
    char *var = SDL_strdup(_var);
icculus@3581
  1788
    if (var == NULL) {
icculus@3581
  1789
        return -1;  /* we don't set errno. */
icculus@3581
  1790
    }
icculus@3581
  1791
slouken@3592
  1792
    ptr = SDL_strchr(var, '=');
icculus@3581
  1793
    if (ptr == NULL) {
icculus@3581
  1794
        SDL_free(var);
icculus@3581
  1795
        return -1;
icculus@3581
  1796
    }
icculus@3581
  1797
icculus@3581
  1798
    *ptr = '\0';  /* split the string into name and value. */
icculus@3581
  1799
    SDL_setenv(var, ptr + 1, 1);
icculus@3581
  1800
    SDL_free(var);
icculus@3581
  1801
    return 0;
icculus@3581
  1802
}
icculus@3581
  1803
slouken@1895
  1804
/* vi: set ts=4 sw=4 expandtab: */