src/SDL_compat.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 18 Jun 2006 13:47:19 +0000
branchSDL-1.3
changeset 1686 8d7fecceb9ef
parent 1685 66267c6a0b12
child 1687 d36048e8e302
permissions -rw-r--r--
Added the unicode keysym memory again for backwards compatibility.
slouken@1667
     1
/*
slouken@1667
     2
    SDL - Simple DirectMedia Layer
slouken@1667
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1667
     4
slouken@1667
     5
    This library is free software; you can redistribute it and/or
slouken@1667
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1667
     7
    License as published by the Free Software Foundation; either
slouken@1667
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1667
     9
slouken@1667
    10
    This library is distributed in the hope that it will be useful,
slouken@1667
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1667
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1667
    13
    Lesser General Public License for more details.
slouken@1667
    14
slouken@1667
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1667
    16
    License along with this library; if not, write to the Free Software
slouken@1667
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1667
    18
slouken@1667
    19
    Sam Lantinga
slouken@1667
    20
    slouken@libsdl.org
slouken@1667
    21
*/
slouken@1667
    22
#include "SDL_config.h"
slouken@1667
    23
slouken@1667
    24
/* This file contains functions for backwards compatibility with SDL 1.2 */
slouken@1667
    25
slouken@1667
    26
#include "SDL.h"
slouken@1667
    27
slouken@1678
    28
#include "video/SDL_pixels_c.h"
slouken@1667
    29
slouken@1667
    30
slouken@1678
    31
static SDL_WindowID SDL_VideoWindow;
slouken@1678
    32
static SDL_TextureID SDL_VideoTexture;
slouken@1678
    33
static SDL_Surface *SDL_VideoSurface;
slouken@1678
    34
static SDL_Surface *SDL_ShadowSurface;
slouken@1678
    35
static SDL_Surface *SDL_PublicSurface;
slouken@1667
    36
static char *wm_title;
slouken@1667
    37
slouken@1667
    38
char *
slouken@1668
    39
SDL_AudioDriverName(char *namebuf, int maxlen)
slouken@1667
    40
{
slouken@1668
    41
    const char *name = SDL_GetCurrentAudioDriver();
slouken@1667
    42
    if (name) {
slouken@1668
    43
        SDL_strlcpy(namebuf, name, maxlen);
slouken@1667
    44
        return namebuf;
slouken@1667
    45
    }
slouken@1667
    46
    return NULL;
slouken@1667
    47
}
slouken@1667
    48
slouken@1667
    49
char *
slouken@1668
    50
SDL_VideoDriverName(char *namebuf, int maxlen)
slouken@1667
    51
{
slouken@1668
    52
    const char *name = SDL_GetCurrentVideoDriver();
slouken@1667
    53
    if (name) {
slouken@1668
    54
        SDL_strlcpy(namebuf, name, maxlen);
slouken@1667
    55
        return namebuf;
slouken@1667
    56
    }
slouken@1667
    57
    return NULL;
slouken@1667
    58
}
slouken@1667
    59
slouken@1670
    60
const SDL_VideoInfo *
slouken@1670
    61
SDL_GetVideoInfo(void)
slouken@1670
    62
{
slouken@1670
    63
    static SDL_VideoInfo info;
slouken@1670
    64
slouken@1670
    65
    /* Memory leak, compatibility code, who cares? */
slouken@1670
    66
    if (!info.vfmt && SDL_GetDesktopDisplayMode()) {
slouken@1670
    67
        int bpp;
slouken@1670
    68
        Uint32 Rmask, Gmask, Bmask, Amask;
slouken@1670
    69
slouken@1670
    70
        SDL_PixelFormatEnumToMasks(SDL_GetDesktopDisplayMode()->format, &bpp,
slouken@1670
    71
                                   &Rmask, &Gmask, &Bmask, &Amask);
slouken@1670
    72
        info.vfmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
slouken@1670
    73
    }
slouken@1670
    74
    return &info;
slouken@1670
    75
}
slouken@1670
    76
slouken@1667
    77
int
slouken@1668
    78
SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags)
slouken@1667
    79
{
slouken@1667
    80
    int i, actual_bpp = 0;
slouken@1667
    81
slouken@1668
    82
    if (!SDL_GetVideoDevice()) {
slouken@1667
    83
        return 0;
slouken@1667
    84
    }
slouken@1667
    85
slouken@1667
    86
    if (!(flags & SDL_FULLSCREEN)) {
slouken@1668
    87
        return SDL_BITSPERPIXEL(SDL_GetDesktopDisplayMode()->format);
slouken@1667
    88
    }
slouken@1667
    89
slouken@1668
    90
    for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
slouken@1668
    91
        const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
slouken@1667
    92
        if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) {
slouken@1667
    93
            if (!mode->format) {
slouken@1667
    94
                return bpp;
slouken@1667
    95
            }
slouken@1668
    96
            if (SDL_BITSPERPIXEL(mode->format) >= bpp) {
slouken@1668
    97
                actual_bpp = SDL_BITSPERPIXEL(mode->format);
slouken@1667
    98
            }
slouken@1667
    99
        }
slouken@1667
   100
    }
slouken@1667
   101
    return actual_bpp;
slouken@1667
   102
}
slouken@1667
   103
slouken@1667
   104
SDL_Rect **
slouken@1668
   105
SDL_ListModes(SDL_PixelFormat * format, Uint32 flags)
slouken@1667
   106
{
slouken@1667
   107
    int i, nmodes;
slouken@1667
   108
    SDL_Rect **modes;
slouken@1667
   109
slouken@1668
   110
    if (!SDL_GetVideoDevice()) {
slouken@1667
   111
        return NULL;
slouken@1667
   112
    }
slouken@1667
   113
slouken@1667
   114
    if (!(flags & SDL_FULLSCREEN)) {
slouken@1667
   115
        return (SDL_Rect **) (-1);
slouken@1667
   116
    }
slouken@1667
   117
slouken@1667
   118
    /* Memory leak, but this is a compatibility function, who cares? */
slouken@1667
   119
    nmodes = 0;
slouken@1668
   120
    for (i = 0; i < SDL_GetNumDisplayModes(); ++i) {
slouken@1668
   121
        const SDL_DisplayMode *mode = SDL_GetDisplayMode(i);
slouken@1667
   122
        if (!mode->w || !mode->h) {
slouken@1667
   123
            return (SDL_Rect **) (-1);
slouken@1667
   124
        }
slouken@1668
   125
        if (SDL_BITSPERPIXEL(mode->format) != format->BitsPerPixel) {
slouken@1667
   126
            continue;
slouken@1667
   127
        }
slouken@1667
   128
        if (nmodes > 0 && modes[nmodes - 1]->w == mode->w
slouken@1667
   129
            && modes[nmodes - 1]->h == mode->h) {
slouken@1667
   130
            continue;
slouken@1667
   131
        }
slouken@1667
   132
slouken@1668
   133
        modes = SDL_realloc(modes, (nmodes + 2) * sizeof(*modes));
slouken@1667
   134
        if (!modes) {
slouken@1667
   135
            return NULL;
slouken@1667
   136
        }
slouken@1668
   137
        modes[nmodes] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
slouken@1667
   138
        if (!modes[nmodes]) {
slouken@1667
   139
            return NULL;
slouken@1667
   140
        }
slouken@1667
   141
        modes[nmodes]->x = 0;
slouken@1667
   142
        modes[nmodes]->y = 0;
slouken@1667
   143
        modes[nmodes]->w = mode->w;
slouken@1667
   144
        modes[nmodes]->h = mode->h;
slouken@1667
   145
        ++nmodes;
slouken@1667
   146
    }
slouken@1667
   147
    if (modes) {
slouken@1667
   148
        modes[nmodes] = NULL;
slouken@1667
   149
    }
slouken@1667
   150
    return modes;
slouken@1667
   151
}
slouken@1667
   152
slouken@1686
   153
static int (*orig_eventfilter) (SDL_Event * event);
slouken@1669
   154
slouken@1669
   155
static int
slouken@1686
   156
SDL_CompatEventFilter(SDL_Event * event)
slouken@1669
   157
{
slouken@1669
   158
    SDL_Event fake;
slouken@1669
   159
slouken@1669
   160
    switch (event->type) {
slouken@1669
   161
    case SDL_WINDOWEVENT:
slouken@1669
   162
        switch (event->window.event) {
slouken@1669
   163
        case SDL_WINDOWEVENT_RESIZED:
slouken@1669
   164
            fake.type = SDL_VIDEORESIZE;
slouken@1669
   165
            fake.resize.w = event->window.data1;
slouken@1669
   166
            fake.resize.h = event->window.data2;
slouken@1669
   167
            SDL_PushEvent(&fake);
slouken@1669
   168
            break;
slouken@1669
   169
        case SDL_WINDOWEVENT_MINIMIZED:
slouken@1669
   170
            fake.type = SDL_ACTIVEEVENT;
slouken@1669
   171
            fake.active.gain = 0;
slouken@1669
   172
            fake.active.state = SDL_APPACTIVE;
slouken@1669
   173
            SDL_PushEvent(&fake);
slouken@1669
   174
            break;
slouken@1669
   175
        case SDL_WINDOWEVENT_RESTORED:
slouken@1669
   176
            fake.type = SDL_ACTIVEEVENT;
slouken@1669
   177
            fake.active.gain = 1;
slouken@1669
   178
            fake.active.state = SDL_APPACTIVE;
slouken@1669
   179
            SDL_PushEvent(&fake);
slouken@1669
   180
            break;
slouken@1669
   181
        case SDL_WINDOWEVENT_ENTER:
slouken@1669
   182
            fake.type = SDL_ACTIVEEVENT;
slouken@1669
   183
            fake.active.gain = 1;
slouken@1669
   184
            fake.active.state = SDL_APPMOUSEFOCUS;
slouken@1669
   185
            SDL_PushEvent(&fake);
slouken@1669
   186
            break;
slouken@1669
   187
        case SDL_WINDOWEVENT_LEAVE:
slouken@1669
   188
            fake.type = SDL_ACTIVEEVENT;
slouken@1669
   189
            fake.active.gain = 0;
slouken@1669
   190
            fake.active.state = SDL_APPMOUSEFOCUS;
slouken@1669
   191
            SDL_PushEvent(&fake);
slouken@1669
   192
            break;
slouken@1669
   193
        case SDL_WINDOWEVENT_FOCUS_GAINED:
slouken@1669
   194
            fake.type = SDL_ACTIVEEVENT;
slouken@1669
   195
            fake.active.gain = 1;
slouken@1669
   196
            fake.active.state = SDL_APPINPUTFOCUS;
slouken@1669
   197
            SDL_PushEvent(&fake);
slouken@1669
   198
            break;
slouken@1669
   199
        case SDL_WINDOWEVENT_FOCUS_LOST:
slouken@1669
   200
            fake.type = SDL_ACTIVEEVENT;
slouken@1669
   201
            fake.active.gain = 1;
slouken@1669
   202
            fake.active.state = SDL_APPINPUTFOCUS;
slouken@1669
   203
            SDL_PushEvent(&fake);
slouken@1669
   204
            break;
slouken@1669
   205
        }
slouken@1686
   206
    case SDL_KEYDOWN:
slouken@1686
   207
    case SDL_KEYUP:
slouken@1686
   208
        {
slouken@1686
   209
            Uint32 unicode = 0;
slouken@1686
   210
            if (event->key.type == SDL_KEYDOWN && event->key.keysym.sym < 256) {
slouken@1686
   211
                int shifted = !!(event->key.keysym.mod & KMOD_SHIFT);
slouken@1686
   212
                int capslock = !!(event->key.keysym.mod & KMOD_CAPS);
slouken@1686
   213
                if ((shifted ^ capslock) != 0) {
slouken@1686
   214
                    unicode = SDL_toupper(event->key.keysym.sym);
slouken@1686
   215
                } else {
slouken@1686
   216
                    unicode = event->key.keysym.sym;
slouken@1686
   217
                }
slouken@1686
   218
            }
slouken@1686
   219
            if (unicode) {
slouken@1686
   220
                event->key.keysym.unicode = unicode;
slouken@1686
   221
            }
slouken@1686
   222
            break;
slouken@1686
   223
        }
slouken@1669
   224
    }
slouken@1683
   225
    if (orig_eventfilter) {
slouken@1683
   226
        return orig_eventfilter(event);
slouken@1683
   227
    } else {
slouken@1683
   228
        return 1;
slouken@1683
   229
    }
slouken@1683
   230
}
slouken@1683
   231
slouken@1683
   232
static int
slouken@1683
   233
SDL_VideoPaletteChanged(void *userdata, SDL_Palette * palette)
slouken@1683
   234
{
slouken@1683
   235
    if (userdata == SDL_ShadowSurface) {
slouken@1683
   236
        /* If the shadow palette changed, make the changes visible */
slouken@1683
   237
        if (!SDL_VideoSurface->format->palette) {
slouken@1683
   238
            SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
slouken@1683
   239
        }
slouken@1683
   240
    }
slouken@1683
   241
    if (userdata == SDL_VideoSurface) {
slouken@1683
   242
        return SDL_SetDisplayPalette(palette->colors, 0, palette->ncolors);
slouken@1683
   243
    }
slouken@1669
   244
}
slouken@1669
   245
slouken@1667
   246
SDL_Surface *
slouken@1668
   247
SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
slouken@1667
   248
{
slouken@1686
   249
    int (*filter) (SDL_Event * event);
slouken@1669
   250
    const SDL_DisplayMode *desktop_mode;
slouken@1667
   251
    SDL_DisplayMode mode;
slouken@1667
   252
    int i;
slouken@1667
   253
    Uint32 window_flags;
slouken@1667
   254
    Uint32 desktop_format;
slouken@1667
   255
    Uint32 desired_format;
slouken@1678
   256
    Uint32 texture_format;
slouken@1682
   257
    Uint32 surface_flags;
slouken@1667
   258
slouken@1668
   259
    if (!SDL_GetVideoDevice()) {
slouken@1668
   260
        if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
slouken@1667
   261
            return NULL;
slouken@1667
   262
        }
slouken@1667
   263
    }
slouken@1667
   264
slouken@1667
   265
    /* Destroy existing window */
slouken@1678
   266
    SDL_PublicSurface = NULL;
slouken@1678
   267
    if (SDL_ShadowSurface) {
slouken@1678
   268
        SDL_FreeSurface(SDL_ShadowSurface);
slouken@1678
   269
        SDL_ShadowSurface = NULL;
slouken@1678
   270
    }
slouken@1678
   271
    if (SDL_VideoSurface) {
slouken@1683
   272
        SDL_DelPaletteWatch(SDL_VideoSurface->format->palette,
slouken@1683
   273
                            SDL_VideoPaletteChanged, NULL);
slouken@1683
   274
        SDL_FreeSurface(SDL_VideoSurface);
slouken@1678
   275
        SDL_VideoSurface = NULL;
slouken@1678
   276
    }
slouken@1678
   277
    SDL_DestroyWindow(SDL_VideoWindow);
slouken@1667
   278
slouken@1669
   279
    /* Set up the event filter */
slouken@1669
   280
    filter = SDL_GetEventFilter();
slouken@1669
   281
    if (filter != SDL_CompatEventFilter) {
slouken@1669
   282
        orig_eventfilter = filter;
slouken@1669
   283
    }
slouken@1669
   284
    SDL_SetEventFilter(SDL_CompatEventFilter);
slouken@1669
   285
slouken@1667
   286
    /* Create a new window */
slouken@1667
   287
    window_flags = SDL_WINDOW_SHOWN;
slouken@1667
   288
    if (flags & SDL_FULLSCREEN) {
slouken@1667
   289
        window_flags |= SDL_WINDOW_FULLSCREEN;
slouken@1667
   290
    }
slouken@1667
   291
    if (flags & SDL_OPENGL) {
slouken@1667
   292
        window_flags |= SDL_WINDOW_OPENGL;
slouken@1667
   293
    }
slouken@1667
   294
    if (flags & SDL_RESIZABLE) {
slouken@1667
   295
        window_flags |= SDL_WINDOW_RESIZABLE;
slouken@1667
   296
    }
slouken@1667
   297
    if (flags & SDL_NOFRAME) {
slouken@1667
   298
        window_flags |= SDL_WINDOW_BORDERLESS;
slouken@1667
   299
    }
slouken@1678
   300
    SDL_VideoWindow =
slouken@1678
   301
        SDL_CreateWindow(wm_title, 0, 0, width, height, window_flags);
slouken@1678
   302
    if (!SDL_VideoWindow) {
slouken@1667
   303
        return NULL;
slouken@1667
   304
    }
slouken@1667
   305
slouken@1682
   306
    window_flags = SDL_GetWindowFlags(SDL_VideoWindow);
slouken@1682
   307
    surface_flags = SDL_SCREEN_SURFACE;
slouken@1682
   308
    if (window_flags & SDL_WINDOW_FULLSCREEN) {
slouken@1682
   309
        surface_flags |= SDL_FULLSCREEN;
slouken@1682
   310
    }
slouken@1682
   311
    if (window_flags & SDL_WINDOW_OPENGL) {
slouken@1682
   312
        surface_flags |= SDL_OPENGL;
slouken@1682
   313
    }
slouken@1682
   314
    if (window_flags & SDL_WINDOW_RESIZABLE) {
slouken@1682
   315
        surface_flags |= SDL_RESIZABLE;
slouken@1682
   316
    }
slouken@1682
   317
    if (window_flags & SDL_WINDOW_BORDERLESS) {
slouken@1682
   318
        surface_flags |= SDL_NOFRAME;
slouken@1682
   319
    }
slouken@1682
   320
slouken@1667
   321
    /* Set up the desired display mode */
slouken@1669
   322
    desktop_mode = SDL_GetDesktopDisplayMode();
slouken@1669
   323
    desktop_format = desktop_mode->format;
slouken@1669
   324
    if (desktop_format && ((flags & SDL_ANYFORMAT)
slouken@1669
   325
                           || (bpp == SDL_BITSPERPIXEL(desktop_format)))) {
slouken@1667
   326
        desired_format = desktop_format;
slouken@1667
   327
    } else {
slouken@1667
   328
        switch (bpp) {
slouken@1669
   329
        case 0:
slouken@1669
   330
            if (desktop_format) {
slouken@1669
   331
                desired_format = desktop_format;
slouken@1669
   332
            } else {
slouken@1669
   333
                desired_format = SDL_PixelFormat_RGB888;
slouken@1669
   334
            }
slouken@1669
   335
            break;
slouken@1667
   336
        case 8:
slouken@1667
   337
            desired_format = SDL_PixelFormat_Index8;
slouken@1667
   338
            break;
slouken@1667
   339
        case 15:
slouken@1667
   340
            desired_format = SDL_PixelFormat_RGB555;
slouken@1667
   341
            break;
slouken@1667
   342
        case 16:
slouken@1667
   343
            desired_format = SDL_PixelFormat_RGB565;
slouken@1667
   344
            break;
slouken@1667
   345
        case 24:
slouken@1667
   346
            desired_format = SDL_PixelFormat_RGB24;
slouken@1667
   347
            break;
slouken@1667
   348
        case 32:
slouken@1667
   349
            desired_format = SDL_PixelFormat_RGB888;
slouken@1667
   350
            break;
slouken@1667
   351
        default:
slouken@1668
   352
            SDL_SetError("Unsupported bpp in SDL_SetVideoMode()");
slouken@1667
   353
            return NULL;
slouken@1667
   354
        }
slouken@1667
   355
    }
slouken@1667
   356
    mode.format = desired_format;
slouken@1667
   357
    mode.w = width;
slouken@1667
   358
    mode.h = height;
slouken@1667
   359
    mode.refresh_rate = 0;
slouken@1667
   360
slouken@1667
   361
    /* Set the desired display mode */
slouken@1667
   362
    if (flags & SDL_FULLSCREEN) {
slouken@1668
   363
        if (!SDL_GetClosestDisplayMode(&mode, &mode)) {
slouken@1667
   364
            return NULL;
slouken@1667
   365
        }
slouken@1667
   366
    } else {
slouken@1669
   367
        if (desktop_format) {
slouken@1669
   368
            mode.format = desktop_format;
slouken@1669
   369
        }
slouken@1669
   370
        if (desktop_mode->w && desktop_mode->h) {
slouken@1669
   371
            mode.w = desktop_mode->w;
slouken@1669
   372
            mode.h = desktop_mode->h;
slouken@1669
   373
        }
slouken@1669
   374
        mode.refresh_rate = desktop_mode->refresh_rate;
slouken@1667
   375
    }
slouken@1668
   376
    if (SDL_SetDisplayMode(&mode) < 0) {
slouken@1667
   377
        return NULL;
slouken@1667
   378
    }
slouken@1667
   379
slouken@1682
   380
    /* If we're in OpenGL mode, just create a stub surface and we're done! */
slouken@1682
   381
    if (flags & SDL_OPENGL) {
slouken@1682
   382
        SDL_VideoSurface =
slouken@1682
   383
            SDL_CreateRGBSurfaceFrom(NULL, width, height, bpp, 0, 0, 0, 0, 0);
slouken@1682
   384
        if (!SDL_VideoSurface) {
slouken@1682
   385
            return NULL;
slouken@1682
   386
        }
slouken@1682
   387
        SDL_VideoSurface->flags |= surface_flags;
slouken@1682
   388
        SDL_PublicSurface = SDL_VideoSurface;
slouken@1682
   389
        return SDL_PublicSurface;
slouken@1682
   390
    }
slouken@1682
   391
slouken@1678
   392
    /* Create a renderer for the window */
slouken@1678
   393
    if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
slouken@1670
   394
        return NULL;
slouken@1670
   395
    }
slouken@1670
   396
slouken@1678
   397
    /* Create a texture for the screen surface */
slouken@1678
   398
    SDL_VideoTexture =
slouken@1678
   399
        SDL_CreateTexture(desired_format, SDL_TextureAccess_Local, width,
slouken@1678
   400
                          height);
slouken@1678
   401
    if (!SDL_VideoTexture) {
slouken@1678
   402
        SDL_VideoTexture =
slouken@1678
   403
            SDL_CreateTexture(0, SDL_TextureAccess_Local, width, height);
slouken@1678
   404
    }
slouken@1678
   405
    if (!SDL_VideoTexture) {
slouken@1670
   406
        return NULL;
slouken@1670
   407
    }
slouken@1670
   408
slouken@1678
   409
    /* Create the screen surface */
slouken@1678
   410
    SDL_VideoSurface = SDL_CreateRGBSurfaceFromTexture(SDL_VideoTexture);
slouken@1678
   411
    if (!SDL_VideoSurface) {
slouken@1678
   412
        return NULL;
slouken@1678
   413
    }
slouken@1682
   414
    SDL_VideoSurface->flags |= surface_flags;
slouken@1670
   415
slouken@1678
   416
    /* Set a default screen palette */
slouken@1678
   417
    if (SDL_VideoSurface->format->palette) {
slouken@1678
   418
        SDL_VideoSurface->flags |= SDL_HWPALETTE;
slouken@1678
   419
        SDL_DitherColors(SDL_VideoSurface->format->palette->colors,
slouken@1678
   420
                         SDL_VideoSurface->format->BitsPerPixel);
slouken@1683
   421
        SDL_AddPaletteWatch(SDL_VideoSurface->format->palette,
slouken@1683
   422
                            SDL_VideoPaletteChanged, NULL);
slouken@1683
   423
        SDL_SetPaletteColors(SDL_VideoSurface->format->palette,
slouken@1683
   424
                             SDL_VideoSurface->format->palette->colors, 0,
slouken@1683
   425
                             SDL_VideoSurface->format->palette->ncolors);
slouken@1670
   426
    }
slouken@1670
   427
slouken@1670
   428
    /* Create a shadow surface if necessary */
slouken@1678
   429
    if (((bpp != SDL_VideoSurface->format->BitsPerPixel)
slouken@1678
   430
         && !(flags & SDL_ANYFORMAT))
slouken@1678
   431
        || ((SDL_VideoSurface->flags & SDL_HWSURFACE)
slouken@1678
   432
            && !(flags & SDL_HWSURFACE))) {
slouken@1678
   433
        if ((bpp == SDL_VideoSurface->format->BitsPerPixel)
slouken@1678
   434
            || (flags & SDL_ANYFORMAT)) {
slouken@1678
   435
            SDL_ShadowSurface =
slouken@1678
   436
                SDL_CreateRGBSurface(0, width, height,
slouken@1678
   437
                                     SDL_VideoSurface->format->BitsPerPixel,
slouken@1678
   438
                                     SDL_VideoSurface->format->Rmask,
slouken@1678
   439
                                     SDL_VideoSurface->format->Gmask,
slouken@1678
   440
                                     SDL_VideoSurface->format->Bmask,
slouken@1678
   441
                                     SDL_VideoSurface->format->Amask);
slouken@1678
   442
        } else {
slouken@1678
   443
            SDL_ShadowSurface =
slouken@1678
   444
                SDL_CreateRGBSurface(0, width, height, bpp, 0, 0, 0, 0);
slouken@1678
   445
        }
slouken@1678
   446
        if (!SDL_ShadowSurface) {
slouken@1670
   447
            return NULL;
slouken@1670
   448
        }
slouken@1682
   449
        surface_flags &= ~SDL_SCREEN_SURFACE;
slouken@1682
   450
        surface_flags |= SDL_SHADOW_SURFACE;
slouken@1682
   451
        SDL_ShadowSurface->flags |= surface_flags;
slouken@1670
   452
slouken@1678
   453
        /* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
slouken@1678
   454
        if (SDL_ShadowSurface->format->palette) {
slouken@1678
   455
            SDL_ShadowSurface->flags |= SDL_HWPALETTE;
slouken@1683
   456
            if (SDL_VideoSurface->format->palette) {
slouken@1683
   457
                SDL_SetSurfacePalette(SDL_ShadowSurface,
slouken@1683
   458
                                      SDL_VideoSurface->format->palette);
slouken@1683
   459
            } else {
slouken@1683
   460
                SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
slouken@1683
   461
                                 SDL_ShadowSurface->format->BitsPerPixel);
slouken@1683
   462
            }
slouken@1670
   463
        }
slouken@1670
   464
    }
slouken@1678
   465
    SDL_PublicSurface =
slouken@1678
   466
        (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface);
slouken@1670
   467
slouken@1670
   468
    /* Clear the surface for display */
slouken@1678
   469
    SDL_FillRect(SDL_PublicSurface, NULL, 0);
slouken@1670
   470
slouken@1678
   471
    /* We're finally done! */
slouken@1678
   472
    return SDL_PublicSurface;
slouken@1670
   473
}
slouken@1670
   474
slouken@1670
   475
SDL_Surface *
slouken@1668
   476
SDL_GetVideoSurface(void)
slouken@1667
   477
{
slouken@1678
   478
    return SDL_PublicSurface;
slouken@1667
   479
}
slouken@1667
   480
slouken@1670
   481
SDL_Surface *
slouken@1670
   482
SDL_DisplayFormat(SDL_Surface * surface)
slouken@1670
   483
{
slouken@1670
   484
    Uint32 flags;
slouken@1670
   485
slouken@1670
   486
    if (!SDL_PublicSurface) {
slouken@1670
   487
        SDL_SetError("No video mode has been set");
slouken@1678
   488
        return NULL;
slouken@1670
   489
    }
slouken@1678
   490
slouken@1670
   491
    /* Set the flags appropriate for copying to display surface */
slouken@1678
   492
    flags = SDL_SWSURFACE;
slouken@1670
   493
#ifdef AUTORLE_DISPLAYFORMAT
slouken@1670
   494
    flags |= (surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA));
slouken@1670
   495
    flags |= SDL_RLEACCELOK;
slouken@1670
   496
#else
slouken@1670
   497
    flags |=
slouken@1670
   498
        surface->flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_RLEACCELOK);
slouken@1670
   499
#endif
slouken@1678
   500
    return SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags);
slouken@1670
   501
}
slouken@1670
   502
slouken@1670
   503
SDL_Surface *
slouken@1670
   504
SDL_DisplayFormatAlpha(SDL_Surface * surface)
slouken@1670
   505
{
slouken@1670
   506
    SDL_PixelFormat *vf;
slouken@1670
   507
    SDL_PixelFormat *format;
slouken@1670
   508
    SDL_Surface *converted;
slouken@1670
   509
    Uint32 flags;
slouken@1670
   510
    /* default to ARGB8888 */
slouken@1670
   511
    Uint32 amask = 0xff000000;
slouken@1670
   512
    Uint32 rmask = 0x00ff0000;
slouken@1670
   513
    Uint32 gmask = 0x0000ff00;
slouken@1670
   514
    Uint32 bmask = 0x000000ff;
slouken@1670
   515
slouken@1670
   516
    if (!SDL_PublicSurface) {
slouken@1670
   517
        SDL_SetError("No video mode has been set");
slouken@1678
   518
        return NULL;
slouken@1670
   519
    }
slouken@1670
   520
    vf = SDL_PublicSurface->format;
slouken@1670
   521
slouken@1670
   522
    switch (vf->BytesPerPixel) {
slouken@1670
   523
    case 2:
slouken@1670
   524
        /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}.
slouken@1670
   525
           For anything else (like ARGB4444) it doesn't matter
slouken@1670
   526
           since we have no special code for it anyway */
slouken@1670
   527
        if ((vf->Rmask == 0x1f) &&
slouken@1670
   528
            (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) {
slouken@1670
   529
            rmask = 0xff;
slouken@1670
   530
            bmask = 0xff0000;
slouken@1670
   531
        }
slouken@1670
   532
        break;
slouken@1670
   533
slouken@1670
   534
    case 3:
slouken@1670
   535
    case 4:
slouken@1670
   536
        /* Keep the video format, as long as the high 8 bits are
slouken@1670
   537
           unused or alpha */
slouken@1670
   538
        if ((vf->Rmask == 0xff) && (vf->Bmask == 0xff0000)) {
slouken@1670
   539
            rmask = 0xff;
slouken@1670
   540
            bmask = 0xff0000;
slouken@1670
   541
        }
slouken@1670
   542
        break;
slouken@1670
   543
slouken@1670
   544
    default:
slouken@1670
   545
        /* We have no other optimised formats right now. When/if a new
slouken@1670
   546
           optimised alpha format is written, add the converter here */
slouken@1670
   547
        break;
slouken@1670
   548
    }
slouken@1670
   549
    format = SDL_AllocFormat(32, rmask, gmask, bmask, amask);
slouken@1670
   550
    flags = SDL_PublicSurface->flags & SDL_HWSURFACE;
slouken@1670
   551
    flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK);
slouken@1670
   552
    converted = SDL_ConvertSurface(surface, format, flags);
slouken@1670
   553
    SDL_FreeFormat(format);
slouken@1678
   554
    return converted;
slouken@1678
   555
}
slouken@1678
   556
slouken@1678
   557
int
slouken@1678
   558
SDL_Flip(SDL_Surface * screen)
slouken@1678
   559
{
slouken@1678
   560
    SDL_UpdateRect(screen, 0, 0, 0, 0);
slouken@1678
   561
    return 0;
slouken@1670
   562
}
slouken@1670
   563
slouken@1670
   564
void
slouken@1670
   565
SDL_UpdateRect(SDL_Surface * screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h)
slouken@1670
   566
{
slouken@1670
   567
    if (screen) {
slouken@1670
   568
        SDL_Rect rect;
slouken@1670
   569
slouken@1670
   570
        /* Perform some checking */
slouken@1670
   571
        if (w == 0)
slouken@1670
   572
            w = screen->w;
slouken@1670
   573
        if (h == 0)
slouken@1670
   574
            h = screen->h;
slouken@1670
   575
        if ((int) (x + w) > screen->w)
slouken@1670
   576
            return;
slouken@1670
   577
        if ((int) (y + h) > screen->h)
slouken@1670
   578
            return;
slouken@1670
   579
slouken@1670
   580
        /* Fill the rectangle */
slouken@1670
   581
        rect.x = (Sint16) x;
slouken@1670
   582
        rect.y = (Sint16) y;
slouken@1670
   583
        rect.w = (Uint16) w;
slouken@1670
   584
        rect.h = (Uint16) h;
slouken@1670
   585
        SDL_UpdateRects(screen, 1, &rect);
slouken@1670
   586
    }
slouken@1670
   587
}
slouken@1670
   588
void
slouken@1670
   589
SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
slouken@1670
   590
{
slouken@1670
   591
    int i;
slouken@1670
   592
slouken@1678
   593
    if (screen == SDL_ShadowSurface) {
slouken@1678
   594
        for (i = 0; i < numrects; ++i) {
slouken@1678
   595
            SDL_LowerBlit(SDL_ShadowSurface, &rects[i], SDL_VideoSurface,
slouken@1678
   596
                          &rects[i]);
slouken@1670
   597
        }
slouken@1670
   598
slouken@1670
   599
        /* Fall through to video surface update */
slouken@1678
   600
        screen = SDL_VideoSurface;
slouken@1670
   601
    }
slouken@1678
   602
    if (screen == SDL_VideoSurface) {
slouken@1678
   603
        for (i = 0; i < numrects; ++i) {
slouken@1678
   604
            SDL_RenderCopy(SDL_VideoTexture, &rects[i], &rects[i],
slouken@1678
   605
                           SDL_TextureBlendMode_None,
slouken@1678
   606
                           SDL_TextureScaleMode_None);
slouken@1670
   607
        }
slouken@1678
   608
        SDL_RenderPresent();
slouken@1670
   609
    }
slouken@1670
   610
}
slouken@1670
   611
slouken@1667
   612
void
slouken@1668
   613
SDL_WM_SetCaption(const char *title, const char *icon)
slouken@1667
   614
{
slouken@1667
   615
    if (wm_title) {
slouken@1668
   616
        SDL_free(wm_title);
slouken@1667
   617
    } else {
slouken@1668
   618
        wm_title = SDL_strdup(title);
slouken@1667
   619
    }
slouken@1678
   620
    SDL_SetWindowTitle(SDL_VideoWindow, wm_title);
slouken@1667
   621
}
slouken@1667
   622
slouken@1667
   623
void
slouken@1668
   624
SDL_WM_GetCaption(char **title, char **icon)
slouken@1667
   625
{
slouken@1667
   626
    if (title) {
slouken@1667
   627
        *title = wm_title;
slouken@1667
   628
    }
slouken@1667
   629
    if (icon) {
slouken@1667
   630
        *icon = "";
slouken@1667
   631
    }
slouken@1667
   632
}
slouken@1667
   633
slouken@1667
   634
void
slouken@1668
   635
SDL_WM_SetIcon(SDL_Surface * icon, Uint8 * mask)
slouken@1667
   636
{
slouken@1667
   637
    /* FIXME */
slouken@1667
   638
}
slouken@1667
   639
slouken@1667
   640
int
slouken@1668
   641
SDL_WM_IconifyWindow(void)
slouken@1667
   642
{
slouken@1678
   643
    SDL_MinimizeWindow(SDL_VideoWindow);
slouken@1667
   644
}
slouken@1667
   645
slouken@1667
   646
int
slouken@1668
   647
SDL_WM_ToggleFullScreen(SDL_Surface * surface)
slouken@1667
   648
{
slouken@1667
   649
    return 0;
slouken@1667
   650
}
slouken@1667
   651
slouken@1667
   652
SDL_GrabMode
slouken@1668
   653
SDL_WM_GrabInput(SDL_GrabMode mode)
slouken@1667
   654
{
slouken@1667
   655
    if (mode != SDL_GRAB_QUERY) {
slouken@1678
   656
        SDL_SetWindowGrab(SDL_VideoWindow, mode);
slouken@1667
   657
    }
slouken@1678
   658
    return (SDL_GrabMode) SDL_GetWindowGrab(SDL_VideoWindow);
slouken@1667
   659
}
slouken@1667
   660
slouken@1680
   661
void
slouken@1680
   662
SDL_WarpMouse(Uint16 x, Uint16 y)
slouken@1680
   663
{
slouken@1680
   664
    SDL_WarpMouseInWindow(SDL_VideoWindow, x, y);
slouken@1680
   665
}
slouken@1680
   666
slouken@1667
   667
Uint8
slouken@1668
   668
SDL_GetAppState(void)
slouken@1667
   669
{
slouken@1667
   670
    Uint8 state = 0;
slouken@1667
   671
    Uint32 flags = 0;
slouken@1667
   672
slouken@1678
   673
    flags = SDL_GetWindowFlags(SDL_VideoWindow);
slouken@1667
   674
    if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
slouken@1667
   675
        state |= SDL_APPACTIVE;
slouken@1667
   676
    }
slouken@1667
   677
    if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
slouken@1667
   678
        state |= SDL_APPINPUTFOCUS;
slouken@1667
   679
    }
slouken@1667
   680
    if (flags & SDL_WINDOW_MOUSE_FOCUS) {
slouken@1667
   681
        state |= SDL_APPMOUSEFOCUS;
slouken@1667
   682
    }
slouken@1667
   683
    return state;
slouken@1667
   684
}
slouken@1667
   685
slouken@1667
   686
const SDL_version *
slouken@1668
   687
SDL_Linked_Version(void)
slouken@1667
   688
{
slouken@1667
   689
    static SDL_version version;
slouken@1668
   690
    SDL_VERSION(&version);
slouken@1667
   691
    return &version;
slouken@1667
   692
}
slouken@1667
   693
slouken@1667
   694
int
slouken@1682
   695
SDL_SetPalette(SDL_Surface * surface, int flags, const SDL_Color * colors,
slouken@1668
   696
               int firstcolor, int ncolors)
slouken@1667
   697
{
slouken@1668
   698
    SDL_SetColors(surface, colors, firstcolor, ncolors);
slouken@1667
   699
}
slouken@1667
   700
slouken@1667
   701
int
slouken@1683
   702
SDL_SetColors(SDL_Surface * surface, const SDL_Color * colors, int firstcolor,
slouken@1683
   703
              int ncolors)
slouken@1670
   704
{
slouken@1683
   705
    if (SDL_SetPaletteColors
slouken@1683
   706
        (surface->format->palette, colors, firstcolor, ncolors) == 0) {
slouken@1683
   707
        return 1;
slouken@1683
   708
    } else {
slouken@1683
   709
        return 0;
slouken@1670
   710
    }
slouken@1670
   711
}
slouken@1670
   712
slouken@1670
   713
int
slouken@1668
   714
SDL_GetWMInfo(SDL_SysWMinfo * info)
slouken@1667
   715
{
slouken@1678
   716
    return SDL_GetWindowWMInfo(SDL_VideoWindow, info);
slouken@1667
   717
}
slouken@1667
   718
slouken@1678
   719
#if 0
slouken@1670
   720
void
slouken@1670
   721
SDL_MoveCursor(int x, int y)
slouken@1670
   722
{
slouken@1670
   723
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1670
   724
slouken@1670
   725
    /* Erase and update the current mouse position */
slouken@1670
   726
    if (SHOULD_DRAWCURSOR(SDL_cursorstate)) {
slouken@1670
   727
        /* Erase and redraw mouse cursor in new position */
slouken@1670
   728
        SDL_LockCursor();
slouken@1670
   729
        SDL_EraseCursor(SDL_VideoSurface);
slouken@1670
   730
        SDL_cursor->area.x = (x - SDL_cursor->hot_x);
slouken@1670
   731
        SDL_cursor->area.y = (y - SDL_cursor->hot_y);
slouken@1670
   732
        SDL_DrawCursor(SDL_VideoSurface);
slouken@1670
   733
        SDL_UnlockCursor();
slouken@1670
   734
    } else if (_this->MoveWMCursor) {
slouken@1670
   735
        _this->MoveWMCursor(_this, x, y);
slouken@1670
   736
    }
slouken@1670
   737
}
slouken@1670
   738
slouken@1670
   739
/* Keep track of the current cursor colors */
slouken@1670
   740
static int palette_changed = 1;
slouken@1670
   741
static Uint8 pixels8[2];
slouken@1670
   742
slouken@1670
   743
void
slouken@1670
   744
SDL_CursorPaletteChanged(void)
slouken@1670
   745
{
slouken@1670
   746
    palette_changed = 1;
slouken@1670
   747
}
slouken@1670
   748
slouken@1670
   749
void
slouken@1670
   750
SDL_MouseRect(SDL_Rect * area)
slouken@1670
   751
{
slouken@1670
   752
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1670
   753
    int clip_diff;
slouken@1670
   754
slouken@1670
   755
    *area = SDL_cursor->area;
slouken@1670
   756
    if (area->x < 0) {
slouken@1670
   757
        area->w += area->x;
slouken@1670
   758
        area->x = 0;
slouken@1670
   759
    }
slouken@1670
   760
    if (area->y < 0) {
slouken@1670
   761
        area->h += area->y;
slouken@1670
   762
        area->y = 0;
slouken@1670
   763
    }
slouken@1670
   764
    clip_diff = (area->x + area->w) - SDL_VideoSurface->w;
slouken@1670
   765
    if (clip_diff > 0) {
slouken@1670
   766
        area->w = area->w < clip_diff ? 0 : area->w - clip_diff;
slouken@1670
   767
    }
slouken@1670
   768
    clip_diff = (area->y + area->h) - SDL_VideoSurface->h;
slouken@1670
   769
    if (clip_diff > 0) {
slouken@1670
   770
        area->h = area->h < clip_diff ? 0 : area->h - clip_diff;
slouken@1670
   771
    }
slouken@1670
   772
}
slouken@1670
   773
slouken@1670
   774
static void
slouken@1670
   775
SDL_DrawCursorFast(SDL_Surface * screen, SDL_Rect * area)
slouken@1670
   776
{
slouken@1670
   777
    const Uint32 pixels[2] = { 0xFFFFFFFF, 0x00000000 };
slouken@1670
   778
    int i, w, h;
slouken@1670
   779
    Uint8 *data, datab;
slouken@1670
   780
    Uint8 *mask, maskb;
slouken@1670
   781
slouken@1670
   782
    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
slouken@1670
   783
    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
slouken@1670
   784
    switch (screen->format->BytesPerPixel) {
slouken@1670
   785
slouken@1670
   786
    case 1:
slouken@1670
   787
        {
slouken@1670
   788
            Uint8 *dst;
slouken@1670
   789
            int dstskip;
slouken@1670
   790
slouken@1670
   791
            if (palette_changed) {
slouken@1670
   792
                pixels8[0] =
slouken@1670
   793
                    (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
slouken@1670
   794
                pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
slouken@1670
   795
                palette_changed = 0;
slouken@1670
   796
            }
slouken@1670
   797
            dst = (Uint8 *) screen->pixels +
slouken@1670
   798
                (SDL_cursor->area.y + area->y) * screen->pitch +
slouken@1670
   799
                SDL_cursor->area.x;
slouken@1670
   800
            dstskip = screen->pitch - area->w;
slouken@1670
   801
slouken@1670
   802
            for (h = area->h; h; h--) {
slouken@1670
   803
                for (w = area->w / 8; w; w--) {
slouken@1670
   804
                    maskb = *mask++;
slouken@1670
   805
                    datab = *data++;
slouken@1670
   806
                    for (i = 0; i < 8; ++i) {
slouken@1670
   807
                        if (maskb & 0x80) {
slouken@1670
   808
                            *dst = pixels8[datab >> 7];
slouken@1670
   809
                        }
slouken@1670
   810
                        maskb <<= 1;
slouken@1670
   811
                        datab <<= 1;
slouken@1670
   812
                        dst++;
slouken@1670
   813
                    }
slouken@1670
   814
                }
slouken@1670
   815
                dst += dstskip;
slouken@1670
   816
            }
slouken@1670
   817
        }
slouken@1670
   818
        break;
slouken@1670
   819
slouken@1670
   820
    case 2:
slouken@1670
   821
        {
slouken@1670
   822
            Uint16 *dst;
slouken@1670
   823
            int dstskip;
slouken@1670
   824
slouken@1670
   825
            dst = (Uint16 *) screen->pixels +
slouken@1670
   826
                (SDL_cursor->area.y + area->y) * screen->pitch / 2 +
slouken@1670
   827
                SDL_cursor->area.x;
slouken@1670
   828
            dstskip = (screen->pitch / 2) - area->w;
slouken@1670
   829
slouken@1670
   830
            for (h = area->h; h; h--) {
slouken@1670
   831
                for (w = area->w / 8; w; w--) {
slouken@1670
   832
                    maskb = *mask++;
slouken@1670
   833
                    datab = *data++;
slouken@1670
   834
                    for (i = 0; i < 8; ++i) {
slouken@1670
   835
                        if (maskb & 0x80) {
slouken@1670
   836
                            *dst = (Uint16) pixels[datab >> 7];
slouken@1670
   837
                        }
slouken@1670
   838
                        maskb <<= 1;
slouken@1670
   839
                        datab <<= 1;
slouken@1670
   840
                        dst++;
slouken@1670
   841
                    }
slouken@1670
   842
                }
slouken@1670
   843
                dst += dstskip;
slouken@1670
   844
            }
slouken@1670
   845
        }
slouken@1670
   846
        break;
slouken@1670
   847
slouken@1670
   848
    case 3:
slouken@1670
   849
        {
slouken@1670
   850
            Uint8 *dst;
slouken@1670
   851
            int dstskip;
slouken@1670
   852
slouken@1670
   853
            dst = (Uint8 *) screen->pixels +
slouken@1670
   854
                (SDL_cursor->area.y + area->y) * screen->pitch +
slouken@1670
   855
                SDL_cursor->area.x * 3;
slouken@1670
   856
            dstskip = screen->pitch - area->w * 3;
slouken@1670
   857
slouken@1670
   858
            for (h = area->h; h; h--) {
slouken@1670
   859
                for (w = area->w / 8; w; w--) {
slouken@1670
   860
                    maskb = *mask++;
slouken@1670
   861
                    datab = *data++;
slouken@1670
   862
                    for (i = 0; i < 8; ++i) {
slouken@1670
   863
                        if (maskb & 0x80) {
slouken@1670
   864
                            SDL_memset(dst, pixels[datab >> 7], 3);
slouken@1670
   865
                        }
slouken@1670
   866
                        maskb <<= 1;
slouken@1670
   867
                        datab <<= 1;
slouken@1670
   868
                        dst += 3;
slouken@1670
   869
                    }
slouken@1670
   870
                }
slouken@1670
   871
                dst += dstskip;
slouken@1670
   872
            }
slouken@1670
   873
        }
slouken@1670
   874
        break;
slouken@1670
   875
slouken@1670
   876
    case 4:
slouken@1670
   877
        {
slouken@1670
   878
            Uint32 *dst;
slouken@1670
   879
            int dstskip;
slouken@1670
   880
slouken@1670
   881
            dst = (Uint32 *) screen->pixels +
slouken@1670
   882
                (SDL_cursor->area.y + area->y) * screen->pitch / 4 +
slouken@1670
   883
                SDL_cursor->area.x;
slouken@1670
   884
            dstskip = (screen->pitch / 4) - area->w;
slouken@1670
   885
slouken@1670
   886
            for (h = area->h; h; h--) {
slouken@1670
   887
                for (w = area->w / 8; w; w--) {
slouken@1670
   888
                    maskb = *mask++;
slouken@1670
   889
                    datab = *data++;
slouken@1670
   890
                    for (i = 0; i < 8; ++i) {
slouken@1670
   891
                        if (maskb & 0x80) {
slouken@1670
   892
                            *dst = pixels[datab >> 7];
slouken@1670
   893
                        }
slouken@1670
   894
                        maskb <<= 1;
slouken@1670
   895
                        datab <<= 1;
slouken@1670
   896
                        dst++;
slouken@1670
   897
                    }
slouken@1670
   898
                }
slouken@1670
   899
                dst += dstskip;
slouken@1670
   900
            }
slouken@1670
   901
        }
slouken@1670
   902
        break;
slouken@1670
   903
    }
slouken@1670
   904
}
slouken@1670
   905
slouken@1670
   906
static void
slouken@1670
   907
SDL_DrawCursorSlow(SDL_Surface * screen, SDL_Rect * area)
slouken@1670
   908
{
slouken@1670
   909
    const Uint32 pixels[2] = { 0xFFFFFF, 0x000000 };
slouken@1670
   910
    int h;
slouken@1670
   911
    int x, minx, maxx;
slouken@1670
   912
    Uint8 *data, datab = 0;
slouken@1670
   913
    Uint8 *mask, maskb = 0;
slouken@1670
   914
    Uint8 *dst;
slouken@1670
   915
    int dstbpp, dstskip;
slouken@1670
   916
slouken@1670
   917
    data = SDL_cursor->data + area->y * SDL_cursor->area.w / 8;
slouken@1670
   918
    mask = SDL_cursor->mask + area->y * SDL_cursor->area.w / 8;
slouken@1670
   919
    dstbpp = screen->format->BytesPerPixel;
slouken@1670
   920
    dst = (Uint8 *) screen->pixels +
slouken@1670
   921
        (SDL_cursor->area.y + area->y) * screen->pitch +
slouken@1670
   922
        SDL_cursor->area.x * dstbpp;
slouken@1670
   923
    dstskip = screen->pitch - SDL_cursor->area.w * dstbpp;
slouken@1670
   924
slouken@1670
   925
    minx = area->x;
slouken@1670
   926
    maxx = area->x + area->w;
slouken@1670
   927
    if (screen->format->BytesPerPixel == 1) {
slouken@1670
   928
        if (palette_changed) {
slouken@1670
   929
            pixels8[0] = (Uint8) SDL_MapRGB(screen->format, 255, 255, 255);
slouken@1670
   930
            pixels8[1] = (Uint8) SDL_MapRGB(screen->format, 0, 0, 0);
slouken@1670
   931
            palette_changed = 0;
slouken@1670
   932
        }
slouken@1670
   933
        for (h = area->h; h; h--) {
slouken@1670
   934
            for (x = 0; x < SDL_cursor->area.w; ++x) {
slouken@1670
   935
                if ((x % 8) == 0) {
slouken@1670
   936
                    maskb = *mask++;
slouken@1670
   937
                    datab = *data++;
slouken@1670
   938
                }
slouken@1670
   939
                if ((x >= minx) && (x < maxx)) {
slouken@1670
   940
                    if (maskb & 0x80) {
slouken@1670
   941
                        SDL_memset(dst, pixels8[datab >> 7], dstbpp);
slouken@1670
   942
                    }
slouken@1670
   943
                }
slouken@1670
   944
                maskb <<= 1;
slouken@1670
   945
                datab <<= 1;
slouken@1670
   946
                dst += dstbpp;
slouken@1670
   947
            }
slouken@1670
   948
            dst += dstskip;
slouken@1670
   949
        }
slouken@1670
   950
    } else {
slouken@1670
   951
        for (h = area->h; h; h--) {
slouken@1670
   952
            for (x = 0; x < SDL_cursor->area.w; ++x) {
slouken@1670
   953
                if ((x % 8) == 0) {
slouken@1670
   954
                    maskb = *mask++;
slouken@1670
   955
                    datab = *data++;
slouken@1670
   956
                }
slouken@1670
   957
                if ((x >= minx) && (x < maxx)) {
slouken@1670
   958
                    if (maskb & 0x80) {
slouken@1670
   959
                        SDL_memset(dst, pixels[datab >> 7], dstbpp);
slouken@1670
   960
                    }
slouken@1670
   961
                }
slouken@1670
   962
                maskb <<= 1;
slouken@1670
   963
                datab <<= 1;
slouken@1670
   964
                dst += dstbpp;
slouken@1670
   965
            }
slouken@1670
   966
            dst += dstskip;
slouken@1670
   967
        }
slouken@1670
   968
    }
slouken@1670
   969
}
slouken@1670
   970
slouken@1670
   971
/* This handles the ugly work of converting the saved cursor background from
slouken@1670
   972
   the pixel format of the shadow surface to that of the video surface.
slouken@1670
   973
   This is only necessary when blitting from a shadow surface of a different
slouken@1670
   974
   pixel format than the video surface, and using a software rendered cursor.
slouken@1670
   975
*/
slouken@1670
   976
static void
slouken@1670
   977
SDL_ConvertCursorSave(SDL_Surface * screen, int w, int h)
slouken@1670
   978
{
slouken@1670
   979
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1670
   980
    SDL_BlitInfo info;
slouken@1670
   981
    SDL_loblit RunBlit;
slouken@1670
   982
slouken@1670
   983
    /* Make sure we can steal the blit mapping */
slouken@1670
   984
    if (screen->map->dst != SDL_VideoSurface) {
slouken@1670
   985
        return;
slouken@1670
   986
    }
slouken@1670
   987
slouken@1670
   988
    /* Set up the blit information */
slouken@1670
   989
    info.s_pixels = SDL_cursor->save[1];
slouken@1670
   990
    info.s_width = w;
slouken@1670
   991
    info.s_height = h;
slouken@1670
   992
    info.s_skip = 0;
slouken@1670
   993
    info.d_pixels = SDL_cursor->save[0];
slouken@1670
   994
    info.d_width = w;
slouken@1670
   995
    info.d_height = h;
slouken@1670
   996
    info.d_skip = 0;
slouken@1670
   997
    info.aux_data = screen->map->sw_data->aux_data;
slouken@1670
   998
    info.src = screen->format;
slouken@1670
   999
    info.table = screen->map->table;
slouken@1670
  1000
    info.dst = SDL_VideoSurface->format;
slouken@1670
  1001
    RunBlit = screen->map->sw_data->blit;
slouken@1670
  1002
slouken@1670
  1003
    /* Run the actual software blit */
slouken@1670
  1004
    RunBlit(&info);
slouken@1670
  1005
}
slouken@1670
  1006
slouken@1670
  1007
void
slouken@1670
  1008
SDL_DrawCursorNoLock(SDL_Surface * screen)
slouken@1670
  1009
{
slouken@1670
  1010
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1670
  1011
    SDL_Rect area;
slouken@1670
  1012
slouken@1670
  1013
    /* Get the mouse rectangle, clipped to the screen */
slouken@1670
  1014
    SDL_MouseRect(&area);
slouken@1670
  1015
    if ((area.w == 0) || (area.h == 0)) {
slouken@1670
  1016
        return;
slouken@1670
  1017
    }
slouken@1670
  1018
slouken@1670
  1019
    /* Copy mouse background */
slouken@1670
  1020
    {
slouken@1670
  1021
        int w, h, screenbpp;
slouken@1670
  1022
        Uint8 *src, *dst;
slouken@1670
  1023
slouken@1670
  1024
        /* Set up the copy pointers */
slouken@1670
  1025
        screenbpp = screen->format->BytesPerPixel;
slouken@1670
  1026
        if ((screen == SDL_VideoSurface) ||
slouken@1670
  1027
            FORMAT_EQUAL(screen->format, SDL_VideoSurface->format)) {
slouken@1670
  1028
            dst = SDL_cursor->save[0];
slouken@1670
  1029
        } else {
slouken@1670
  1030
            dst = SDL_cursor->save[1];
slouken@1670
  1031
        }
slouken@1670
  1032
        src = (Uint8 *) screen->pixels + area.y * screen->pitch +
slouken@1670
  1033
            area.x * screenbpp;
slouken@1670
  1034
slouken@1670
  1035
        /* Perform the copy */
slouken@1670
  1036
        w = area.w * screenbpp;
slouken@1670
  1037
        h = area.h;
slouken@1670
  1038
        while (h--) {
slouken@1670
  1039
            SDL_memcpy(dst, src, w);
slouken@1670
  1040
            dst += w;
slouken@1670
  1041
            src += screen->pitch;
slouken@1670
  1042
        }
slouken@1670
  1043
    }
slouken@1670
  1044
slouken@1670
  1045
    /* Draw the mouse cursor */
slouken@1670
  1046
    area.x -= SDL_cursor->area.x;
slouken@1670
  1047
    area.y -= SDL_cursor->area.y;
slouken@1670
  1048
    if ((area.x == 0) && (area.w == SDL_cursor->area.w)) {
slouken@1670
  1049
        SDL_DrawCursorFast(screen, &area);
slouken@1670
  1050
    } else {
slouken@1670
  1051
        SDL_DrawCursorSlow(screen, &area);
slouken@1670
  1052
    }
slouken@1670
  1053
}
slouken@1670
  1054
slouken@1670
  1055
void
slouken@1670
  1056
SDL_DrawCursor(SDL_Surface * screen)
slouken@1670
  1057
{
slouken@1670
  1058
    /* Lock the screen if necessary */
slouken@1670
  1059
    if (screen == NULL) {
slouken@1670
  1060
        return;
slouken@1670
  1061
    }
slouken@1670
  1062
    if (SDL_MUSTLOCK(screen)) {
slouken@1670
  1063
        if (SDL_LockSurface(screen) < 0) {
slouken@1670
  1064
            return;
slouken@1670
  1065
        }
slouken@1670
  1066
    }
slouken@1670
  1067
slouken@1670
  1068
    SDL_DrawCursorNoLock(screen);
slouken@1670
  1069
slouken@1670
  1070
    /* Unlock the screen and update if necessary */
slouken@1670
  1071
    if (SDL_MUSTLOCK(screen)) {
slouken@1670
  1072
        SDL_UnlockSurface(screen);
slouken@1670
  1073
    }
slouken@1670
  1074
    if ((screen->flags & SDL_SCREEN_SURFACE) &&
slouken@1670
  1075
        !(screen->flags & SDL_HWSURFACE)) {
slouken@1670
  1076
        SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1670
  1077
        SDL_Window *window;
slouken@1670
  1078
        SDL_Rect area;
slouken@1670
  1079
slouken@1670
  1080
        window = SDL_GetWindowFromSurface(screen);
slouken@1670
  1081
        if (!window) {
slouken@1670
  1082
            return;
slouken@1670
  1083
        }
slouken@1670
  1084
slouken@1670
  1085
        SDL_MouseRect(&area);
slouken@1670
  1086
slouken@1670
  1087
        if (_this->UpdateWindowSurface) {
slouken@1670
  1088
            _this->UpdateWindowSurface(_this, window, 1, &area);
slouken@1670
  1089
        }
slouken@1670
  1090
    }
slouken@1670
  1091
}
slouken@1670
  1092
slouken@1670
  1093
void
slouken@1670
  1094
SDL_EraseCursorNoLock(SDL_Surface * screen)
slouken@1670
  1095
{
slouken@1670
  1096
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1670
  1097
    SDL_Window *window;
slouken@1670
  1098
    SDL_Rect area;
slouken@1670
  1099
slouken@1670
  1100
    /* Get the window associated with the surface */
slouken@1670
  1101
    window = SDL_GetWindowFromSurface(screen);
slouken@1670
  1102
    if (!window || !window->surface) {
slouken@1670
  1103
        return;
slouken@1670
  1104
    }
slouken@1670
  1105
slouken@1670
  1106
    /* Get the mouse rectangle, clipped to the screen */
slouken@1670
  1107
    SDL_MouseRect(&area);
slouken@1670
  1108
    if ((area.w == 0) || (area.h == 0)) {
slouken@1670
  1109
        return;
slouken@1670
  1110
    }
slouken@1670
  1111
slouken@1670
  1112
    /* Copy mouse background */
slouken@1670
  1113
    {
slouken@1670
  1114
        int w, h, screenbpp;
slouken@1670
  1115
        Uint8 *src, *dst;
slouken@1670
  1116
slouken@1670
  1117
        /* Set up the copy pointers */
slouken@1670
  1118
        screenbpp = screen->format->BytesPerPixel;
slouken@1670
  1119
        if ((screen->flags & SDL_SCREEN_SURFACE) ||
slouken@1670
  1120
            FORMAT_EQUAL(screen->format, window->surface->format)) {
slouken@1670
  1121
            src = SDL_cursor->save[0];
slouken@1670
  1122
        } else {
slouken@1670
  1123
            src = SDL_cursor->save[1];
slouken@1670
  1124
        }
slouken@1670
  1125
        dst = (Uint8 *) screen->pixels + area.y * screen->pitch +
slouken@1670
  1126
            area.x * screenbpp;
slouken@1670
  1127
slouken@1670
  1128
        /* Perform the copy */
slouken@1670
  1129
        w = area.w * screenbpp;
slouken@1670
  1130
        h = area.h;
slouken@1670
  1131
        while (h--) {
slouken@1670
  1132
            SDL_memcpy(dst, src, w);
slouken@1670
  1133
            src += w;
slouken@1670
  1134
            dst += screen->pitch;
slouken@1670
  1135
        }
slouken@1670
  1136
slouken@1670
  1137
        /* Perform pixel conversion on cursor background */
slouken@1670
  1138
        if (src > SDL_cursor->save[1]) {
slouken@1670
  1139
            SDL_ConvertCursorSave(screen, area.w, area.h);
slouken@1670
  1140
        }
slouken@1670
  1141
    }
slouken@1670
  1142
}
slouken@1670
  1143
slouken@1670
  1144
void
slouken@1670
  1145
SDL_EraseCursor(SDL_Surface * screen)
slouken@1670
  1146
{
slouken@1670
  1147
    /* Lock the screen if necessary */
slouken@1670
  1148
    if (screen == NULL) {
slouken@1670
  1149
        return;
slouken@1670
  1150
    }
slouken@1670
  1151
    if (SDL_MUSTLOCK(screen)) {
slouken@1670
  1152
        if (SDL_LockSurface(screen) < 0) {
slouken@1670
  1153
            return;
slouken@1670
  1154
        }
slouken@1670
  1155
    }
slouken@1670
  1156
slouken@1670
  1157
    SDL_EraseCursorNoLock(screen);
slouken@1670
  1158
slouken@1670
  1159
    /* Unlock the screen and update if necessary */
slouken@1670
  1160
    if (SDL_MUSTLOCK(screen)) {
slouken@1670
  1161
        SDL_UnlockSurface(screen);
slouken@1670
  1162
    }
slouken@1670
  1163
    if ((screen->flags & SDL_SCREEN_SURFACE) &&
slouken@1670
  1164
        !(screen->flags & SDL_HWSURFACE)) {
slouken@1670
  1165
        SDL_VideoDevice *_this = SDL_GetVideoDevice();
slouken@1670
  1166
        SDL_Window *window;
slouken@1670
  1167
        SDL_Rect area;
slouken@1670
  1168
slouken@1670
  1169
        window = SDL_GetWindowFromSurface(screen);
slouken@1670
  1170
        if (!window) {
slouken@1670
  1171
            return;
slouken@1670
  1172
        }
slouken@1670
  1173
slouken@1670
  1174
        SDL_MouseRect(&area);
slouken@1670
  1175
slouken@1670
  1176
        if (_this->UpdateWindowSurface) {
slouken@1670
  1177
            _this->UpdateWindowSurface(_this, window, 1, &area);
slouken@1670
  1178
        }
slouken@1670
  1179
    }
slouken@1670
  1180
}
slouken@1670
  1181
slouken@1670
  1182
/* Reset the cursor on video mode change
slouken@1670
  1183
   FIXME:  Keep track of all cursors, and reset them all.
slouken@1670
  1184
 */
slouken@1670
  1185
void
slouken@1670
  1186
SDL_ResetCursor(void)
slouken@1670
  1187
{
slouken@1670
  1188
    int savelen;
slouken@1670
  1189
slouken@1670
  1190
    if (SDL_cursor) {
slouken@1670
  1191
        savelen = SDL_cursor->area.w * 4 * SDL_cursor->area.h;
slouken@1670
  1192
        SDL_cursor->area.x = 0;
slouken@1670
  1193
        SDL_cursor->area.y = 0;
slouken@1670
  1194
        SDL_memset(SDL_cursor->save[0], 0, savelen);
slouken@1670
  1195
    }
slouken@1670
  1196
}
slouken@1684
  1197
#endif
slouken@1684
  1198
slouken@1684
  1199
struct private_yuvhwdata
slouken@1684
  1200
{
slouken@1684
  1201
    Uint16 pitches[3];
slouken@1684
  1202
    Uint8 *planes[3];
slouken@1684
  1203
slouken@1684
  1204
    SDL_TextureID textureID;
slouken@1684
  1205
};
slouken@1670
  1206
slouken@1675
  1207
SDL_Overlay *
slouken@1675
  1208
SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display)
slouken@1675
  1209
{
slouken@1675
  1210
    SDL_Overlay *overlay;
slouken@1684
  1211
    Uint32 texture_format;
slouken@1675
  1212
slouken@1684
  1213
    if ((display->flags & SDL_OPENGL) == SDL_OPENGL) {
slouken@1675
  1214
        SDL_SetError("YUV overlays are not supported in OpenGL mode");
slouken@1675
  1215
        return NULL;
slouken@1675
  1216
    }
slouken@1675
  1217
slouken@1684
  1218
    if (display != SDL_PublicSurface) {
slouken@1684
  1219
        SDL_SetError("YUV display is only supported on the screen surface");
slouken@1684
  1220
        return NULL;
slouken@1675
  1221
    }
slouken@1684
  1222
slouken@1684
  1223
    switch (format) {
slouken@1684
  1224
    case SDL_YV12_OVERLAY:
slouken@1684
  1225
        texture_format = SDL_PixelFormat_YV12;
slouken@1684
  1226
        break;
slouken@1684
  1227
    case SDL_IYUV_OVERLAY:
slouken@1684
  1228
        texture_format = SDL_PixelFormat_IYUV;
slouken@1684
  1229
        break;
slouken@1684
  1230
    case SDL_YUY2_OVERLAY:
slouken@1684
  1231
        texture_format = SDL_PixelFormat_YUY2;
slouken@1684
  1232
        break;
slouken@1684
  1233
    case SDL_UYVY_OVERLAY:
slouken@1684
  1234
        texture_format = SDL_PixelFormat_UYVY;
slouken@1684
  1235
        break;
slouken@1684
  1236
    case SDL_YVYU_OVERLAY:
slouken@1684
  1237
        texture_format = SDL_PixelFormat_YVYU;
slouken@1684
  1238
        break;
slouken@1684
  1239
    default:
slouken@1684
  1240
        SDL_SetError("Unknown YUV format");
slouken@1684
  1241
        return NULL;
slouken@1675
  1242
    }
slouken@1684
  1243
slouken@1684
  1244
    overlay = (SDL_Overlay *) SDL_malloc(sizeof(*overlay));
slouken@1684
  1245
    if (!overlay) {
slouken@1684
  1246
        SDL_OutOfMemory();
slouken@1684
  1247
        return NULL;
slouken@1675
  1248
    }
slouken@1684
  1249
    SDL_zerop(overlay);
slouken@1684
  1250
slouken@1684
  1251
    overlay->hwdata =
slouken@1684
  1252
        (struct private_yuvhwdata *) SDL_malloc(sizeof(*overlay->hwdata));
slouken@1684
  1253
    if (!overlay->hwdata) {
slouken@1684
  1254
        SDL_free(overlay);
slouken@1684
  1255
        SDL_OutOfMemory();
slouken@1684
  1256
        return NULL;
slouken@1684
  1257
    }
slouken@1684
  1258
slouken@1684
  1259
    overlay->format = format;
slouken@1684
  1260
    overlay->w = w;
slouken@1684
  1261
    overlay->h = h;
slouken@1684
  1262
    if (format == SDL_YV12_OVERLAY || format == SDL_IYUV_OVERLAY) {
slouken@1684
  1263
        overlay->planes = 3;
slouken@1684
  1264
    } else {
slouken@1684
  1265
        overlay->planes = 1;
slouken@1684
  1266
    }
slouken@1684
  1267
    overlay->pitches = overlay->hwdata->pitches;
slouken@1684
  1268
    overlay->pixels = overlay->hwdata->planes;
slouken@1684
  1269
slouken@1684
  1270
    switch (format) {
slouken@1684
  1271
    case SDL_YV12_OVERLAY:
slouken@1684
  1272
    case SDL_IYUV_OVERLAY:
slouken@1684
  1273
        overlay->pitches[0] = overlay->w;
slouken@1684
  1274
        overlay->pitches[1] = overlay->w / 2;
slouken@1684
  1275
        overlay->pitches[2] = overlay->w / 2;
slouken@1684
  1276
        break;
slouken@1684
  1277
    case SDL_YUY2_OVERLAY:
slouken@1684
  1278
    case SDL_UYVY_OVERLAY:
slouken@1684
  1279
    case SDL_YVYU_OVERLAY:
slouken@1685
  1280
        overlay->pitches[0] = overlay->w * 2;
slouken@1684
  1281
        break;
slouken@1684
  1282
    }
slouken@1684
  1283
slouken@1684
  1284
    overlay->hwdata->textureID =
slouken@1684
  1285
        SDL_CreateTexture(texture_format, SDL_TextureAccess_Local, w, h);
slouken@1684
  1286
    if (!overlay->hwdata->textureID) {
slouken@1684
  1287
        SDL_FreeYUVOverlay(overlay);
slouken@1684
  1288
        return NULL;
slouken@1684
  1289
    }
slouken@1684
  1290
slouken@1675
  1291
    return overlay;
slouken@1675
  1292
}
slouken@1675
  1293
slouken@1675
  1294
int
slouken@1675
  1295
SDL_LockYUVOverlay(SDL_Overlay * overlay)
slouken@1675
  1296
{
slouken@1684
  1297
    void *pixels;
slouken@1684
  1298
    int pitch;
slouken@1684
  1299
    if (SDL_LockTexture(overlay->hwdata->textureID, NULL, 1, &pixels, &pitch)
slouken@1684
  1300
        < 0) {
slouken@1684
  1301
        return -1;
slouken@1684
  1302
    }
slouken@1684
  1303
    switch (overlay->format) {
slouken@1684
  1304
    case SDL_YV12_OVERLAY:
slouken@1684
  1305
    case SDL_IYUV_OVERLAY:
slouken@1684
  1306
        overlay->pixels[0] = (Uint8 *) pixels;
slouken@1684
  1307
        overlay->pixels[1] =
slouken@1684
  1308
            overlay->pixels[0] + overlay->pitches[0] * overlay->h;
slouken@1684
  1309
        overlay->pixels[2] =
slouken@1684
  1310
            overlay->pixels[1] + overlay->pitches[1] * overlay->h;
slouken@1684
  1311
        break;
slouken@1684
  1312
    case SDL_YUY2_OVERLAY:
slouken@1684
  1313
    case SDL_UYVY_OVERLAY:
slouken@1684
  1314
    case SDL_YVYU_OVERLAY:
slouken@1684
  1315
        overlay->pixels[0] = (Uint8 *) pixels;
slouken@1684
  1316
        break;
slouken@1684
  1317
    }
slouken@1684
  1318
    return 0;
slouken@1675
  1319
}
slouken@1675
  1320
slouken@1675
  1321
void
slouken@1675
  1322
SDL_UnlockYUVOverlay(SDL_Overlay * overlay)
slouken@1675
  1323
{
slouken@1684
  1324
    SDL_UnlockTexture(overlay->hwdata->textureID);
slouken@1675
  1325
}
slouken@1675
  1326
slouken@1675
  1327
int
slouken@1675
  1328
SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect)
slouken@1675
  1329
{
slouken@1684
  1330
    if (SDL_RenderCopy(overlay->hwdata->textureID, NULL, dstrect,
slouken@1684
  1331
                       SDL_TextureBlendMode_None,
slouken@1684
  1332
                       SDL_TextureScaleMode_Fast) < 0) {
slouken@1684
  1333
        return -1;
slouken@1675
  1334
    }
slouken@1684
  1335
    SDL_RenderPresent();
slouken@1675
  1336
}
slouken@1675
  1337
slouken@1675
  1338
void
slouken@1675
  1339
SDL_FreeYUVOverlay(SDL_Overlay * overlay)
slouken@1675
  1340
{
slouken@1675
  1341
    if (overlay) {
slouken@1684
  1342
        if (overlay->hwdata) {
slouken@1684
  1343
            if (overlay->hwdata->textureID) {
slouken@1684
  1344
                SDL_DestroyTexture(overlay->hwdata->textureID);
slouken@1684
  1345
            }
slouken@1684
  1346
            SDL_free(overlay->hwdata);
slouken@1675
  1347
        }
slouken@1675
  1348
        SDL_free(overlay);
slouken@1675
  1349
    }
slouken@1675
  1350
}
slouken@1675
  1351
slouken@1667
  1352
/* vi: set ts=4 sw=4 expandtab: */