Implemented many compatibility functions SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Mon, 29 May 2006 03:53:21 +0000
branchSDL-1.3
changeset 16671fddae038bc8
parent 1666 6e7ec5cb83c3
child 1668 4da1ee79c9af
Implemented many compatibility functions
.indent.pro
include/SDL_compat.h
src/SDL_compat.c
src/video/SDL_video.c
src/video/dummy/SDL_nullvideo.c
     1.1 --- a/.indent.pro	Sun May 28 21:56:07 2006 +0000
     1.2 +++ b/.indent.pro	Mon May 29 03:53:21 2006 +0000
     1.3 @@ -1,1 +1,1 @@
     1.4 --i4 -nut -nsc -br -ce
     1.5 +-i4 -nut -nsc -br -ce -cdw -npcs
     2.1 --- a/include/SDL_compat.h	Sun May 28 21:56:07 2006 +0000
     2.2 +++ b/include/SDL_compat.h	Mon May 29 03:53:21 2006 +0000
     2.3 @@ -30,54 +30,52 @@
     2.4  #include "begin_code.h"
     2.5  /* Set up for C function definitions, even when using C++ */
     2.6  #ifdef __cplusplus
     2.7 -extern "C"
     2.8 -{
     2.9 +/* *INDENT-OFF* */
    2.10 +extern "C" {
    2.11 +/* *INDENT-ON* */
    2.12  #endif
    2.13  
    2.14 -    extern DECLSPEC char *SDLCALL SDL_AudioDriverName (char *namebuf,
    2.15 -                                                       int maxlen);
    2.16 -    extern DECLSPEC char *SDLCALL SDL_VideoDriverName (char *namebuf,
    2.17 -                                                       int maxlen);
    2.18 -    extern DECLSPEC int SDLCALL SDL_VideoModeOK (int width, int height,
    2.19 -                                                 int bpp, Uint32 flags);
    2.20 -    extern DECLSPEC SDL_Rect **SDLCALL SDL_ListModes (SDL_PixelFormat *
    2.21 -                                                      format, Uint32 flags);
    2.22 -    extern DECLSPEC SDL_Surface *SDLCALL SDL_SetVideoMode (int width,
    2.23 -                                                           int height,
    2.24 -                                                           int bpp,
    2.25 -                                                           Uint32 flags);
    2.26 +#define SDL_SWSURFACE	0x00000000
    2.27 +#define SDL_HWSURFACE	0x00000001
    2.28 +#define SDL_ASYNCBLIT	0x00000004
    2.29 +#define SDL_ANYFORMAT	0x10000000
    2.30 +#define SDL_HWPALETTE	0x20000000
    2.31 +#define SDL_DOUBLEBUF	0x40000000
    2.32 +#define SDL_FULLSCREEN	0x80000000
    2.33 +#define SDL_OPENGL      0x00000002
    2.34 +#define SDL_INTERNALOPENGL 0x00000008
    2.35 +#define SDL_RESIZABLE	0x00000010
    2.36 +#define SDL_NOFRAME	0x00000020
    2.37 +#define SDL_HWACCEL	0x00000100
    2.38 +#define SDL_SRCCOLORKEY	0x00001000
    2.39 +#define SDL_RLEACCELOK	0x00002000
    2.40 +#define SDL_RLEACCEL	0x00004000
    2.41 +#define SDL_SRCALPHA	0x00010000
    2.42  
    2.43 -/* Ends C function definitions when using C++ */
    2.44 -#ifdef __cplusplus
    2.45 -}
    2.46 -#endif
    2.47 -#include "close_code.h"
    2.48 +#define SDL_APPMOUSEFOCUS	0x01
    2.49 +#define SDL_APPINPUTFOCUS	0x02
    2.50 +#define SDL_APPACTIVE		0x04
    2.51  
    2.52 -#endif                          /* _SDL_compat_h */
    2.53 +#define SDL_LOGPAL 0x01
    2.54 +#define SDL_PHYSPAL 0x02
    2.55  
    2.56 +typedef enum
    2.57 +{
    2.58 +    SDL_GRAB_QUERY = -1,
    2.59 +    SDL_GRAB_OFF = 0,
    2.60 +    SDL_GRAB_ON = 1
    2.61 +} SDL_GrabMode;
    2.62 +
    2.63 +extern DECLSPEC const SDL_version *SDLCALL SDL_Linked_Version (void);
    2.64 +extern DECLSPEC char *SDLCALL SDL_AudioDriverName (char *namebuf, int maxlen);
    2.65 +extern DECLSPEC char *SDLCALL SDL_VideoDriverName (char *namebuf, int maxlen);
    2.66 +extern DECLSPEC int SDLCALL SDL_VideoModeOK (int width, int height, int bpp,
    2.67 +                                             Uint32 flags);
    2.68 +extern DECLSPEC SDL_Rect **SDLCALL SDL_ListModes (SDL_PixelFormat * format,
    2.69 +                                                  Uint32 flags);
    2.70 +extern DECLSPEC SDL_Surface *SDLCALL SDL_SetVideoMode (int width, int height,
    2.71 +                                                       int bpp, Uint32 flags);
    2.72  extern DECLSPEC SDL_Surface *SDLCALL SDL_GetVideoSurface (void);
    2.73 -
    2.74 -/* These are the currently supported flags for the SDL_surface */
    2.75 -/* Available for SDL_CreateRGBSurface() or SDL_SetVideoMode() */
    2.76 -#define SDL_SWSURFACE	0x00000000      /* Surface is in system memory */
    2.77 -#define SDL_HWSURFACE	0x00000001      /* Surface is in video memory */
    2.78 -#define SDL_ASYNCBLIT	0x00000004      /* Use asynchronous blits if possible */
    2.79 -/* Available for SDL_SetVideoMode() */
    2.80 -#define SDL_ANYFORMAT	0x10000000      /* Allow any video depth/pixel-format */
    2.81 -#define SDL_HWPALETTE	0x20000000      /* Surface has exclusive palette */
    2.82 -#define SDL_DOUBLEBUF	0x40000000      /* Set up double-buffered video mode */
    2.83 -#define SDL_FULLSCREEN	0x80000000      /* Surface is a full screen display */
    2.84 -#define SDL_OPENGL      0x00000002      /* Create an OpenGL rendering context */
    2.85 -#define SDL_INTERNALOPENGL 0x00000008   /* SDL uses OpenGL internally for this window */
    2.86 -#define SDL_RESIZABLE	0x00000010      /* This video mode may be resized */
    2.87 -#define SDL_NOFRAME	0x00000020      /* No window caption or edge frame */
    2.88 -/* Used internally (read-only) */
    2.89 -#define SDL_HWACCEL	0x00000100      /* Blit uses hardware acceleration */
    2.90 -#define SDL_SRCCOLORKEY	0x00001000      /* Blit uses a source color key */
    2.91 -#define SDL_RLEACCELOK	0x00002000      /* Private flag */
    2.92 -#define SDL_RLEACCEL	0x00004000      /* Surface is RLE encoded */
    2.93 -#define SDL_SRCALPHA	0x00010000      /* Blit uses source alpha blending */
    2.94 -
    2.95  extern DECLSPEC void SDLCALL SDL_WM_SetCaption (const char *title,
    2.96                                                  const char *icon);
    2.97  extern DECLSPEC void SDLCALL SDL_WM_GetCaption (char **title, char **icon);
    2.98 @@ -85,42 +83,19 @@
    2.99                                               Uint8 * mask);
   2.100  extern DECLSPEC int SDLCALL SDL_WM_IconifyWindow (void);
   2.101  extern DECLSPEC int SDLCALL SDL_WM_ToggleFullScreen (SDL_Surface * surface);
   2.102 -typedef enum
   2.103 -{
   2.104 -    SDL_GRAB_QUERY = -1,
   2.105 -    SDL_GRAB_OFF = 0,
   2.106 -    SDL_GRAB_ON = 1
   2.107 -} SDL_GrabMode;
   2.108  extern DECLSPEC SDL_GrabMode SDLCALL SDL_WM_GrabInput (SDL_GrabMode mode);
   2.109 -
   2.110 -/* The available application states */
   2.111 -#define SDL_APPMOUSEFOCUS	0x01    /* The app has mouse coverage */
   2.112 -#define SDL_APPINPUTFOCUS	0x02    /* The app has input focus */
   2.113 -#define SDL_APPACTIVE		0x04    /* The application is active */
   2.114 -
   2.115  extern DECLSPEC Uint8 SDLCALL SDL_GetAppState (void);
   2.116 -extern DECLSPEC const SDL_version *SDLCALL SDL_Linked_Version (void);
   2.117 -/* flags for SDL_SetPalette() */
   2.118 -#define SDL_LOGPAL 0x01
   2.119 -#define SDL_PHYSPAL 0x02
   2.120 -
   2.121 -/*
   2.122 - * Sets a portion of the colormap for a given 8-bit surface.
   2.123 - * 'flags' is one or both of:
   2.124 - * SDL_LOGPAL  -- set logical palette, which controls how blits are mapped
   2.125 - *                to/from the surface,
   2.126 - * SDL_PHYSPAL -- set physical palette, which controls how pixels look on
   2.127 - *                the screen
   2.128 - * Only screens have physical palettes. Separate change of physical/logical
   2.129 - * palettes is only possible if the screen has SDL_HWPALETTE set.
   2.130 - *
   2.131 - * The return value is 1 if all colours could be set as requested, and 0
   2.132 - * otherwise.
   2.133 - *
   2.134 - * SDL_SetColors() is equivalent to calling this function with
   2.135 - *     flags = (SDL_LOGPAL|SDL_PHYSPAL).
   2.136 - */
   2.137  extern DECLSPEC int SDLCALL SDL_SetPalette (SDL_Surface * surface, int flags,
   2.138                                              SDL_Color * colors,
   2.139                                              int firstcolor, int ncolors);
   2.140  extern DECLSPEC int SDLCALL SDL_GetWMInfo (SDL_SysWMinfo * info);
   2.141 +
   2.142 +/* Ends C function definitions when using C++ */
   2.143 +#ifdef __cplusplus
   2.144 +/* *INDENT-OFF* */
   2.145 +}
   2.146 +/* *INDENT-ON* */
   2.147 +#endif
   2.148 +#include "close_code.h"
   2.149 +
   2.150 +#endif /* _SDL_compat_h */
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/SDL_compat.c	Mon May 29 03:53:21 2006 +0000
     3.3 @@ -0,0 +1,314 @@
     3.4 +/*
     3.5 +    SDL - Simple DirectMedia Layer
     3.6 +    Copyright (C) 1997-2006 Sam Lantinga
     3.7 +
     3.8 +    This library is free software; you can redistribute it and/or
     3.9 +    modify it under the terms of the GNU Lesser General Public
    3.10 +    License as published by the Free Software Foundation; either
    3.11 +    version 2.1 of the License, or (at your option) any later version.
    3.12 +
    3.13 +    This library is distributed in the hope that it will be useful,
    3.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    3.16 +    Lesser General Public License for more details.
    3.17 +
    3.18 +    You should have received a copy of the GNU Lesser General Public
    3.19 +    License along with this library; if not, write to the Free Software
    3.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    3.21 +
    3.22 +    Sam Lantinga
    3.23 +    slouken@libsdl.org
    3.24 +*/
    3.25 +#include "SDL_config.h"
    3.26 +
    3.27 +/* This file contains functions for backwards compatibility with SDL 1.2 */
    3.28 +
    3.29 +#include "SDL.h"
    3.30 +
    3.31 +#include "video/SDL_sysvideo.h"
    3.32 +
    3.33 +
    3.34 +static SDL_WindowID window;
    3.35 +static char *wm_title;
    3.36 +
    3.37 +char *
    3.38 +SDL_AudioDriverName (char *namebuf, int maxlen)
    3.39 +{
    3.40 +    const char *name = SDL_GetCurrentAudioDriver ();
    3.41 +    if (name) {
    3.42 +        SDL_strlcpy (namebuf, name, maxlen);
    3.43 +        return namebuf;
    3.44 +    }
    3.45 +    return NULL;
    3.46 +}
    3.47 +
    3.48 +char *
    3.49 +SDL_VideoDriverName (char *namebuf, int maxlen)
    3.50 +{
    3.51 +    const char *name = SDL_GetCurrentVideoDriver ();
    3.52 +    if (name) {
    3.53 +        SDL_strlcpy (namebuf, name, maxlen);
    3.54 +        return namebuf;
    3.55 +    }
    3.56 +    return NULL;
    3.57 +}
    3.58 +
    3.59 +int
    3.60 +SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags)
    3.61 +{
    3.62 +    int i, actual_bpp = 0;
    3.63 +
    3.64 +    if (!SDL_GetVideoDevice ()) {
    3.65 +        return 0;
    3.66 +    }
    3.67 +
    3.68 +    if (!(flags & SDL_FULLSCREEN)) {
    3.69 +        return SDL_BITSPERPIXEL (SDL_GetDesktopDisplayMode ()->format);
    3.70 +    }
    3.71 +
    3.72 +    for (i = 0; i < SDL_GetNumDisplayModes (); ++i) {
    3.73 +        const SDL_DisplayMode *mode = SDL_GetDisplayMode (i);
    3.74 +        if (!mode->w || !mode->h || (width == mode->w && height == mode->h)) {
    3.75 +            if (!mode->format) {
    3.76 +                return bpp;
    3.77 +            }
    3.78 +            if (SDL_BITSPERPIXEL (mode->format) >= bpp) {
    3.79 +                actual_bpp = SDL_BITSPERPIXEL (mode->format);
    3.80 +            }
    3.81 +        }
    3.82 +    }
    3.83 +    return actual_bpp;
    3.84 +}
    3.85 +
    3.86 +SDL_Rect **
    3.87 +SDL_ListModes (SDL_PixelFormat * format, Uint32 flags)
    3.88 +{
    3.89 +    int i, nmodes;
    3.90 +    SDL_Rect **modes;
    3.91 +
    3.92 +    if (!SDL_GetVideoDevice ()) {
    3.93 +        return NULL;
    3.94 +    }
    3.95 +
    3.96 +    if (!(flags & SDL_FULLSCREEN)) {
    3.97 +        return (SDL_Rect **) (-1);
    3.98 +    }
    3.99 +
   3.100 +    /* Memory leak, but this is a compatibility function, who cares? */
   3.101 +    nmodes = 0;
   3.102 +    for (i = 0; i < SDL_GetNumDisplayModes (); ++i) {
   3.103 +        const SDL_DisplayMode *mode = SDL_GetDisplayMode (i);
   3.104 +        if (!mode->w || !mode->h) {
   3.105 +            return (SDL_Rect **) (-1);
   3.106 +        }
   3.107 +        if (SDL_BITSPERPIXEL (mode->format) != format->BitsPerPixel) {
   3.108 +            continue;
   3.109 +        }
   3.110 +        if (nmodes > 0 && modes[nmodes - 1]->w == mode->w
   3.111 +            && modes[nmodes - 1]->h == mode->h) {
   3.112 +            continue;
   3.113 +        }
   3.114 +
   3.115 +        modes = SDL_realloc (modes, (nmodes + 2) * sizeof (*modes));
   3.116 +        if (!modes) {
   3.117 +            return NULL;
   3.118 +        }
   3.119 +        modes[nmodes] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
   3.120 +        if (!modes[nmodes]) {
   3.121 +            return NULL;
   3.122 +        }
   3.123 +        modes[nmodes]->x = 0;
   3.124 +        modes[nmodes]->y = 0;
   3.125 +        modes[nmodes]->w = mode->w;
   3.126 +        modes[nmodes]->h = mode->h;
   3.127 +        ++nmodes;
   3.128 +    }
   3.129 +    if (modes) {
   3.130 +        modes[nmodes] = NULL;
   3.131 +    }
   3.132 +    return modes;
   3.133 +}
   3.134 +
   3.135 +SDL_Surface *
   3.136 +SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags)
   3.137 +{
   3.138 +    SDL_DisplayMode mode;
   3.139 +    int i;
   3.140 +    Uint32 window_flags;
   3.141 +    Uint32 desktop_format;
   3.142 +    Uint32 desired_format;
   3.143 +
   3.144 +    if (!SDL_GetVideoDevice ()) {
   3.145 +        if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) {
   3.146 +            return NULL;
   3.147 +        }
   3.148 +    }
   3.149 +
   3.150 +    /* Destroy existing window */
   3.151 +    SDL_DestroyWindow (window);
   3.152 +
   3.153 +    /* Create a new window */
   3.154 +    window_flags = SDL_WINDOW_SHOWN;
   3.155 +    if (flags & SDL_FULLSCREEN) {
   3.156 +        window_flags |= SDL_WINDOW_FULLSCREEN;
   3.157 +    }
   3.158 +    if (flags & SDL_OPENGL) {
   3.159 +        window_flags |= SDL_WINDOW_OPENGL;
   3.160 +    }
   3.161 +    if (flags & SDL_RESIZABLE) {
   3.162 +        window_flags |= SDL_WINDOW_RESIZABLE;
   3.163 +    }
   3.164 +    if (flags & SDL_NOFRAME) {
   3.165 +        window_flags |= SDL_WINDOW_BORDERLESS;
   3.166 +    }
   3.167 +    window = SDL_CreateWindow (wm_title, 0, 0, width, height, window_flags);
   3.168 +    if (!window) {
   3.169 +        return NULL;
   3.170 +    }
   3.171 +
   3.172 +    /* Set up the desired display mode */
   3.173 +    desktop_format = SDL_GetDesktopDisplayMode ()->format;
   3.174 +    if ((bpp == SDL_BITSPERPIXEL(desktop_format)) ||
   3.175 +        (desktop_format && (flags & SDL_ANYFORMAT))) {
   3.176 +        desired_format = desktop_format;
   3.177 +    } else {
   3.178 +        switch (bpp) {
   3.179 +        case 8:
   3.180 +            desired_format = SDL_PixelFormat_Index8;
   3.181 +            break;
   3.182 +        case 15:
   3.183 +            desired_format = SDL_PixelFormat_RGB555;
   3.184 +            break;
   3.185 +        case 16:
   3.186 +            desired_format = SDL_PixelFormat_RGB565;
   3.187 +            break;
   3.188 +        case 24:
   3.189 +            desired_format = SDL_PixelFormat_RGB24;
   3.190 +            break;
   3.191 +        case 32:
   3.192 +            desired_format = SDL_PixelFormat_RGB888;
   3.193 +            break;
   3.194 +        default:
   3.195 +            SDL_SetError ("Unsupported bpp in SDL_SetVideoMode()");
   3.196 +            return NULL;
   3.197 +        }
   3.198 +    }
   3.199 +    mode.format = desired_format;
   3.200 +    mode.w = width;
   3.201 +    mode.h = height;
   3.202 +    mode.refresh_rate = 0;
   3.203 +
   3.204 +    /* Set the desired display mode */
   3.205 +    if (flags & SDL_FULLSCREEN) {
   3.206 +        if (!SDL_GetClosestDisplayMode (&mode, &mode)) {
   3.207 +            return NULL;
   3.208 +        }
   3.209 +    } else {
   3.210 +        mode = *SDL_GetDesktopDisplayMode ();
   3.211 +    }
   3.212 +    if (SDL_SetDisplayMode (&mode) < 0) {
   3.213 +        return NULL;
   3.214 +    }
   3.215 +
   3.216 +    /* Create the display surface */
   3.217 +    return SDL_CreateWindowSurface (window, desired_format, flags);
   3.218 +}
   3.219 +
   3.220 +SDL_Surface *
   3.221 +SDL_GetVideoSurface (void)
   3.222 +{
   3.223 +    SDL_VideoDevice *_this = SDL_GetVideoDevice ();
   3.224 +
   3.225 +    return SDL_VideoSurface;
   3.226 +}
   3.227 +
   3.228 +void
   3.229 +SDL_WM_SetCaption (const char *title, const char *icon)
   3.230 +{
   3.231 +    if (wm_title) {
   3.232 +        SDL_free (wm_title);
   3.233 +    } else {
   3.234 +        wm_title = SDL_strdup (title);
   3.235 +    }
   3.236 +    SDL_SetWindowTitle (window, wm_title);
   3.237 +}
   3.238 +
   3.239 +void
   3.240 +SDL_WM_GetCaption (char **title, char **icon)
   3.241 +{
   3.242 +    if (title) {
   3.243 +        *title = wm_title;
   3.244 +    }
   3.245 +    if (icon) {
   3.246 +        *icon = "";
   3.247 +    }
   3.248 +}
   3.249 +
   3.250 +void
   3.251 +SDL_WM_SetIcon (SDL_Surface * icon, Uint8 * mask)
   3.252 +{
   3.253 +    /* FIXME */
   3.254 +}
   3.255 +
   3.256 +int
   3.257 +SDL_WM_IconifyWindow (void)
   3.258 +{
   3.259 +    SDL_MinimizeWindow (window);
   3.260 +}
   3.261 +
   3.262 +int
   3.263 +SDL_WM_ToggleFullScreen (SDL_Surface * surface)
   3.264 +{
   3.265 +    return 0;
   3.266 +}
   3.267 +
   3.268 +SDL_GrabMode
   3.269 +SDL_WM_GrabInput (SDL_GrabMode mode)
   3.270 +{
   3.271 +    if (mode != SDL_GRAB_QUERY) {
   3.272 +        SDL_SetWindowGrab (window, mode);
   3.273 +    }
   3.274 +    return (SDL_GrabMode) SDL_GetWindowGrab (window);
   3.275 +}
   3.276 +
   3.277 +Uint8
   3.278 +SDL_GetAppState (void)
   3.279 +{
   3.280 +    Uint8 state = 0;
   3.281 +    Uint32 flags = 0;
   3.282 +
   3.283 +    flags = SDL_GetWindowFlags (window);
   3.284 +    if ((flags & SDL_WINDOW_SHOWN) && !(flags & SDL_WINDOW_MINIMIZED)) {
   3.285 +        state |= SDL_APPACTIVE;
   3.286 +    }
   3.287 +    if (flags & SDL_WINDOW_KEYBOARD_FOCUS) {
   3.288 +        state |= SDL_APPINPUTFOCUS;
   3.289 +    }
   3.290 +    if (flags & SDL_WINDOW_MOUSE_FOCUS) {
   3.291 +        state |= SDL_APPMOUSEFOCUS;
   3.292 +    }
   3.293 +    return state;
   3.294 +}
   3.295 +
   3.296 +const SDL_version *
   3.297 +SDL_Linked_Version (void)
   3.298 +{
   3.299 +    static SDL_version version;
   3.300 +    SDL_VERSION (&version);
   3.301 +    return &version;
   3.302 +}
   3.303 +
   3.304 +int
   3.305 +SDL_SetPalette (SDL_Surface * surface, int flags, SDL_Color * colors,
   3.306 +                int firstcolor, int ncolors)
   3.307 +{
   3.308 +    SDL_SetColors (surface, colors, firstcolor, ncolors);
   3.309 +}
   3.310 +
   3.311 +int
   3.312 +SDL_GetWMInfo (SDL_SysWMinfo * info)
   3.313 +{
   3.314 +    return SDL_GetWindowWMInfo (window, info);
   3.315 +}
   3.316 +
   3.317 +/* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/video/SDL_video.c	Sun May 28 21:56:07 2006 +0000
     4.2 +++ b/src/video/SDL_video.c	Mon May 29 03:53:21 2006 +0000
     4.3 @@ -512,7 +512,9 @@
     4.4  int
     4.5  SDL_SetDisplayMode (const SDL_DisplayMode * mode)
     4.6  {
     4.7 +    SDL_VideoDisplay *display;
     4.8      SDL_DisplayMode display_mode;
     4.9 +    int i;
    4.10  
    4.11      if (!_this) {
    4.12          SDL_SetError ("Video subsystem has not been initialized");
    4.13 @@ -524,21 +526,21 @@
    4.14          SDL_SetError ("No mode passed to SDL_SetDisplayMode");
    4.15          return -1;
    4.16      }
    4.17 +    display = &SDL_CurrentDisplay;
    4.18      display_mode = *mode;
    4.19  
    4.20      /* Default to the current mode */
    4.21      if (!display_mode.format) {
    4.22 -        display_mode.format = SDL_CurrentDisplay.current_mode.format;
    4.23 +        display_mode.format = display->current_mode.format;
    4.24      }
    4.25      if (!display_mode.w) {
    4.26 -        display_mode.w = SDL_CurrentDisplay.current_mode.w;
    4.27 +        display_mode.w = display->current_mode.w;
    4.28      }
    4.29      if (!display_mode.h) {
    4.30 -        display_mode.h = SDL_CurrentDisplay.current_mode.h;
    4.31 +        display_mode.h = display->current_mode.h;
    4.32      }
    4.33      if (!display_mode.refresh_rate) {
    4.34 -        display_mode.refresh_rate =
    4.35 -            SDL_CurrentDisplay.current_mode.refresh_rate;
    4.36 +        display_mode.refresh_rate = display->current_mode.refresh_rate;
    4.37      }
    4.38  
    4.39      /* Get a good video mode, the closest one possible */
    4.40 @@ -555,6 +557,19 @@
    4.41          return 0;
    4.42      }
    4.43  
    4.44 +    /* Free any previous window surfaces */
    4.45 +    for (i = 0; i < display->num_windows; ++i) {
    4.46 +        SDL_Window *window = &display->windows[i];
    4.47 +        if (window->shadow) {
    4.48 +            SDL_FreeSurface (window->shadow);
    4.49 +            window->shadow = NULL;
    4.50 +        }
    4.51 +        if (window->surface) {
    4.52 +            SDL_FreeSurface (window->surface);
    4.53 +            window->surface = NULL;
    4.54 +        }
    4.55 +    }
    4.56 +
    4.57      return _this->SetDisplayMode (_this, &display_mode);
    4.58  }
    4.59  
    4.60 @@ -580,7 +595,7 @@
    4.61  
    4.62      SDL_zero (window);
    4.63      window.id = _this->next_window_id++;
    4.64 -    window.title = SDL_strdup (title);
    4.65 +    window.title = title ? SDL_strdup (title) : NULL;
    4.66      window.x = x;
    4.67      window.y = y;
    4.68      window.w = w;
    4.69 @@ -588,7 +603,9 @@
    4.70      window.flags = (flags & allowed_flags);
    4.71  
    4.72      if (_this->CreateWindow && _this->CreateWindow (_this, &window) < 0) {
    4.73 -        SDL_free (window.title);
    4.74 +        if (window.title) {
    4.75 +            SDL_free (window.title);
    4.76 +        }
    4.77          return 0;
    4.78      }
    4.79  
    4.80 @@ -600,7 +617,9 @@
    4.81          if (_this->DestroyWindow) {
    4.82              _this->DestroyWindow (_this, &window);
    4.83          }
    4.84 -        SDL_free (window.title);
    4.85 +        if (window.title) {
    4.86 +            SDL_free (window.title);
    4.87 +        }
    4.88          return 0;
    4.89      }
    4.90      windows[num_windows] = window;
    4.91 @@ -638,7 +657,9 @@
    4.92          if (_this->DestroyWindow) {
    4.93              _this->DestroyWindow (_this, &window);
    4.94          }
    4.95 -        SDL_free (window.title);
    4.96 +        if (window.title) {
    4.97 +            SDL_free (window.title);
    4.98 +        }
    4.99          return 0;
   4.100      }
   4.101      windows[num_windows] = window;
   4.102 @@ -674,7 +695,7 @@
   4.103  {
   4.104      int i, j;
   4.105  
   4.106 -    if (!_this) {
   4.107 +    if (!_this || !surface) {
   4.108          return NULL;
   4.109      }
   4.110  
     5.1 --- a/src/video/dummy/SDL_nullvideo.c	Sun May 28 21:56:07 2006 +0000
     5.2 +++ b/src/video/dummy/SDL_nullvideo.c	Mon May 29 03:53:21 2006 +0000
     5.3 @@ -118,8 +118,13 @@
     5.4  int
     5.5  DUMMY_VideoInit (_THIS)
     5.6  {
     5.7 +    SDL_DisplayMode mode;
     5.8 +
     5.9      SDL_AddBasicVideoDisplay (NULL);
    5.10  
    5.11 +    SDL_zero(mode);
    5.12 +    SDL_AddDisplayMode(0, &mode);
    5.13 +
    5.14      /* We're done! */
    5.15      return 0;
    5.16  }