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