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