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