Implemented Win32 video mode support SDL-1.3
authorSam Lantinga <slouken@libsdl.org>
Fri, 07 Jul 2006 08:05:39 +0000
branchSDL-1.3
changeset 172598a3207ddde8
parent 1724 6c63fc2bd986
child 1726 18223b2ec68c
Implemented Win32 video mode support
include/SDL_video.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/dummy/SDL_nullvideo.c
src/video/win32/SDL_win32keyboard.c
src/video/win32/SDL_win32keyboard.h
src/video/win32/SDL_win32modes.c
src/video/win32/SDL_win32modes.h
src/video/win32/SDL_win32mouse.c
src/video/win32/SDL_win32mouse.h
src/video/win32/SDL_win32video.c
src/video/win32/SDL_win32video.h
test/testsprite2.c
test/testvidinfo.c
test/testwm2.c
     1.1 --- a/include/SDL_video.h	Thu Jul 06 07:17:11 2006 +0000
     1.2 +++ b/include/SDL_video.h	Fri Jul 07 08:05:39 2006 +0000
     1.3 @@ -75,6 +75,7 @@
     1.4      int w;                      /**< width */
     1.5      int h;                      /**< height */
     1.6      int refresh_rate;           /**< refresh rate (or zero for unspecified) */
     1.7 +    void *driverdata;           /**< driver-specific data, initialize to 0 */
     1.8  } SDL_DisplayMode;
     1.9  
    1.10  /**
     2.1 --- a/src/video/SDL_sysvideo.h	Thu Jul 06 07:17:11 2006 +0000
     2.2 +++ b/src/video/SDL_sysvideo.h	Fri Jul 07 08:05:39 2006 +0000
     2.3 @@ -131,6 +131,7 @@
     2.4   */
     2.5  struct SDL_VideoDisplay
     2.6  {
     2.7 +    int max_display_modes;
     2.8      int num_display_modes;
     2.9      SDL_DisplayMode *display_modes;
    2.10      SDL_DisplayMode desktop_mode;
    2.11 @@ -178,7 +179,7 @@
    2.12       * should have their data updated accordingly, including the
    2.13       * display surfaces associated with them.
    2.14       */
    2.15 -    int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
    2.16 +    int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
    2.17  
    2.18      /* Sets the color entries of the display palette to those in 'colors'.
    2.19         The return value is 0 if all entries could be set properly or -1
    2.20 @@ -410,8 +411,8 @@
    2.21  extern SDL_VideoDevice *SDL_GetVideoDevice();
    2.22  extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
    2.23  extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
    2.24 -extern void SDL_AddDisplayMode(int displayIndex,
    2.25 -                               const SDL_DisplayMode * mode);
    2.26 +extern SDL_bool SDL_AddDisplayMode(int displayIndex,
    2.27 +                                   const SDL_DisplayMode * mode);
    2.28  extern void SDL_AddRenderDriver(int displayIndex,
    2.29                                  const SDL_RenderDriver * driver);
    2.30  
     3.1 --- a/src/video/SDL_video.c	Thu Jul 06 07:17:11 2006 +0000
     3.2 +++ b/src/video/SDL_video.c	Fri Jul 07 08:05:39 2006 +0000
     3.3 @@ -362,7 +362,7 @@
     3.4      return _this->current_display;
     3.5  }
     3.6  
     3.7 -void
     3.8 +SDL_bool
     3.9  SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
    3.10  {
    3.11      SDL_VideoDisplay *display = &_this->displays[displayIndex];
    3.12 @@ -372,19 +372,27 @@
    3.13      /* Make sure we don't already have the mode in the list */
    3.14      modes = display->display_modes;
    3.15      nmodes = display->num_display_modes;
    3.16 -    for (i = 0; i < nmodes; ++i) {
    3.17 +    for (i = nmodes; i--;) {
    3.18          if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
    3.19 -            return;
    3.20 +            return SDL_FALSE;
    3.21          }
    3.22      }
    3.23  
    3.24      /* Go ahead and add the new mode */
    3.25 -    modes = SDL_realloc(modes, (nmodes + 1) * sizeof(*mode));
    3.26 -    if (modes) {
    3.27 +    if (nmodes == display->max_display_modes) {
    3.28 +        modes =
    3.29 +            SDL_realloc(modes,
    3.30 +                        (display->max_display_modes + 32) * sizeof(*modes));
    3.31 +        if (!modes) {
    3.32 +            return SDL_FALSE;
    3.33 +        }
    3.34          display->display_modes = modes;
    3.35 -        modes[nmodes] = *mode;
    3.36 -        display->num_display_modes++;
    3.37 +        display->max_display_modes += 32;
    3.38      }
    3.39 +    modes[nmodes] = *mode;
    3.40 +    display->num_display_modes++;
    3.41 +
    3.42 +    return SDL_TRUE;
    3.43  }
    3.44  
    3.45  int
    3.46 @@ -501,6 +509,8 @@
    3.47          } else {
    3.48              closest->refresh_rate = mode->refresh_rate;
    3.49          }
    3.50 +        closest->driverdata = match->driverdata;
    3.51 +
    3.52          /* Pick some reasonable defaults if the app and driver don't care */
    3.53          if (!closest->format) {
    3.54              closest->format = SDL_PixelFormat_RGB888;
    3.55 @@ -521,7 +531,7 @@
    3.56  {
    3.57      SDL_VideoDisplay *display;
    3.58      SDL_DisplayMode display_mode;
    3.59 -    int ncolors;
    3.60 +    int i, ncolors;
    3.61  
    3.62      if (!_this) {
    3.63          SDL_SetError("Video subsystem has not been initialized");
    3.64 @@ -562,6 +572,12 @@
    3.65          return 0;
    3.66      }
    3.67  
    3.68 +    /* Actually change the display mode */
    3.69 +    if (_this->SetDisplayMode(_this, &display_mode) < 0) {
    3.70 +        return -1;
    3.71 +    }
    3.72 +    display->current_mode = display_mode;
    3.73 +
    3.74      /* Set up a palette, if necessary */
    3.75      if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
    3.76          ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
    3.77 @@ -584,7 +600,17 @@
    3.78          }
    3.79      }
    3.80  
    3.81 -    return _this->SetDisplayMode(_this, &display_mode);
    3.82 +    /* Move any fullscreen windows into position */
    3.83 +    for (i = 0; i < display->num_windows; ++i) {
    3.84 +        SDL_Window *window = &display->windows[i];
    3.85 +        if (window->flags & SDL_WINDOW_FULLSCREEN) {
    3.86 +            SDL_SetWindowPosition(window->id,
    3.87 +                                  ((display_mode.w - window->w) / 2),
    3.88 +                                  ((display_mode.h - window->h) / 2));
    3.89 +        }
    3.90 +    }
    3.91 +
    3.92 +    return 0;
    3.93  }
    3.94  
    3.95  int
    3.96 @@ -662,8 +688,14 @@
    3.97      SDL_zero(window);
    3.98      window.id = _this->next_object_id++;
    3.99      window.title = title ? SDL_strdup(title) : NULL;
   3.100 -    window.x = x;
   3.101 -    window.y = y;
   3.102 +    if (flags & SDL_WINDOW_FULLSCREEN) {
   3.103 +        const SDL_DisplayMode *mode = &SDL_CurrentDisplay.current_mode;
   3.104 +        window.x = (mode->w - w) / 2;
   3.105 +        window.y = (mode->h - h) / 2;
   3.106 +    } else {
   3.107 +        window.x = x;
   3.108 +        window.y = y;
   3.109 +    }
   3.110      window.w = w;
   3.111      window.h = h;
   3.112      window.flags = (flags & allowed_flags);
   3.113 @@ -1813,14 +1845,34 @@
   3.114              SDL_free(display->windows);
   3.115              display->windows = NULL;
   3.116          }
   3.117 +        display->num_windows = 0;
   3.118 +    }
   3.119 +    _this->VideoQuit(_this);
   3.120 +
   3.121 +    for (i = _this->num_displays; i--;) {
   3.122 +        SDL_VideoDisplay *display = &_this->displays[i];
   3.123 +        for (j = display->num_display_modes; j--;) {
   3.124 +            if (display->display_modes[j].driverdata) {
   3.125 +                SDL_free(display->display_modes[j].driverdata);
   3.126 +                display->display_modes[j].driverdata = NULL;
   3.127 +            }
   3.128 +        }
   3.129 +        if (display->display_modes) {
   3.130 +            SDL_free(display->display_modes);
   3.131 +            display->display_modes = NULL;
   3.132 +        }
   3.133 +        if (display->desktop_mode.driverdata) {
   3.134 +            SDL_free(display->desktop_mode.driverdata);
   3.135 +            display->desktop_mode.driverdata = NULL;
   3.136 +        }
   3.137          if (display->palette) {
   3.138              SDL_FreePalette(display->palette);
   3.139              display->palette = NULL;
   3.140          }
   3.141      }
   3.142 -    _this->VideoQuit(_this);
   3.143      if (_this->displays) {
   3.144          SDL_free(_this->displays);
   3.145 +        _this->displays = NULL;
   3.146      }
   3.147      _this->free(_this);
   3.148      _this = NULL;
     4.1 --- a/src/video/dummy/SDL_nullvideo.c	Thu Jul 06 07:17:11 2006 +0000
     4.2 +++ b/src/video/dummy/SDL_nullvideo.c	Fri Jul 07 08:05:39 2006 +0000
     4.3 @@ -50,7 +50,7 @@
     4.4  
     4.5  /* Initialization/Query functions */
     4.6  static int DUMMY_VideoInit(_THIS);
     4.7 -static int DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
     4.8 +static int DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
     4.9  static void DUMMY_VideoQuit(_THIS);
    4.10  
    4.11  /* DUMMY driver bootstrap functions */
    4.12 @@ -120,9 +120,8 @@
    4.13  }
    4.14  
    4.15  static int
    4.16 -DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
    4.17 +DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
    4.18  {
    4.19 -    SDL_CurrentDisplay.current_mode = *mode;
    4.20      return 0;
    4.21  }
    4.22  
     5.1 --- a/src/video/win32/SDL_win32keyboard.c	Thu Jul 06 07:17:11 2006 +0000
     5.2 +++ b/src/video/win32/SDL_win32keyboard.c	Fri Jul 07 08:05:39 2006 +0000
     5.3 @@ -26,7 +26,7 @@
     5.4  #include "../../events/SDL_keyboard_c.h"
     5.5  
     5.6  void
     5.7 -WIN_AddKeyboard(_THIS)
     5.8 +WIN_InitKeyboard(_THIS)
     5.9  {
    5.10      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    5.11      SDL_Keyboard keyboard;
    5.12 @@ -36,7 +36,7 @@
    5.13  }
    5.14  
    5.15  void
    5.16 -WIN_DelKeyboard(_THIS)
    5.17 +WIN_QuitKeyboard(_THIS)
    5.18  {
    5.19      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    5.20  
     6.1 --- a/src/video/win32/SDL_win32keyboard.h	Thu Jul 06 07:17:11 2006 +0000
     6.2 +++ b/src/video/win32/SDL_win32keyboard.h	Fri Jul 07 08:05:39 2006 +0000
     6.3 @@ -24,8 +24,8 @@
     6.4  #ifndef _SDL_win32keyboard_h
     6.5  #define _SDL_win32keyboard_h
     6.6  
     6.7 -extern void WIN_AddKeyboard(_THIS);
     6.8 -extern void WIN_DelKeyboard(_THIS);
     6.9 +extern void WIN_InitKeyboard(_THIS);
    6.10 +extern void WIN_QuitKeyboard(_THIS);
    6.11  
    6.12  #endif /* _SDL_win32keyboard_h */
    6.13  
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/video/win32/SDL_win32modes.c	Fri Jul 07 08:05:39 2006 +0000
     7.3 @@ -0,0 +1,215 @@
     7.4 +/*
     7.5 +    SDL - Simple DirectMedia Layer
     7.6 +    Copyright (C) 1997-2006 Sam Lantinga
     7.7 +
     7.8 +    This library is free software; you can redistribute it and/or
     7.9 +    modify it under the terms of the GNU Lesser General Public
    7.10 +    License as published by the Free Software Foundation; either
    7.11 +    version 2.1 of the License, or (at your option) any later version.
    7.12 +
    7.13 +    This library is distributed in the hope that it will be useful,
    7.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +    Lesser General Public License for more details.
    7.17 +
    7.18 +    You should have received a copy of the GNU Lesser General Public
    7.19 +    License along with this library; if not, write to the Free Software
    7.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    7.21 +
    7.22 +    Sam Lantinga
    7.23 +    slouken@libsdl.org
    7.24 +*/
    7.25 +#include "SDL_config.h"
    7.26 +
    7.27 +#include "SDL_win32video.h"
    7.28 +
    7.29 +
    7.30 +typedef struct
    7.31 +{
    7.32 +    TCHAR DeviceName[32];
    7.33 +    DEVMODE DeviceMode;
    7.34 +} SDL_DisplayModeData;
    7.35 +
    7.36 +/* FIXME: Each call to EnumDisplaySettings() takes about 6 ms on my laptop.
    7.37 +          With 500 or so modes, this takes almost 3 seconds to run!
    7.38 +*/
    7.39 +
    7.40 +static SDL_bool
    7.41 +WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
    7.42 +{
    7.43 +    SDL_DisplayModeData *data;
    7.44 +    DEVMODE devmode;
    7.45 +    HDC hdc;
    7.46 +
    7.47 +    devmode.dmSize = sizeof(devmode);
    7.48 +    devmode.dmDriverExtra = 0;
    7.49 +    if (!EnumDisplaySettings(deviceName, index, &devmode)) {
    7.50 +        return SDL_FALSE;
    7.51 +    }
    7.52 +
    7.53 +    data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
    7.54 +    if (!data) {
    7.55 +        return SDL_FALSE;
    7.56 +    }
    7.57 +    SDL_memcpy(data->DeviceName, deviceName, sizeof(data->DeviceName));
    7.58 +    data->DeviceMode = devmode;
    7.59 +    data->DeviceMode.dmFields =
    7.60 +        (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
    7.61 +         DM_DISPLAYFLAGS);
    7.62 +
    7.63 +    /* Fill in the mode information */
    7.64 +    mode->format = SDL_PixelFormat_Unknown;
    7.65 +    mode->w = devmode.dmPelsWidth;
    7.66 +    mode->h = devmode.dmPelsHeight;
    7.67 +    mode->refresh_rate = devmode.dmDisplayFrequency;
    7.68 +    mode->driverdata = data;
    7.69 +
    7.70 +    hdc = CreateDC(deviceName, NULL, NULL, &devmode);
    7.71 +    if (hdc) {
    7.72 +        char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
    7.73 +        LPBITMAPINFO bmi;
    7.74 +        HBITMAP hbm;
    7.75 +
    7.76 +        SDL_zero(bmi_data);
    7.77 +        bmi = (LPBITMAPINFO) bmi_data;
    7.78 +        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    7.79 +
    7.80 +        hbm = CreateCompatibleBitmap(hdc, 1, 1);
    7.81 +        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
    7.82 +        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
    7.83 +        DeleteObject(hbm);
    7.84 +        DeleteDC(hdc);
    7.85 +        if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
    7.86 +            switch (*(Uint32 *) bmi->bmiColors) {
    7.87 +            case 0x00FF0000:
    7.88 +                mode->format = SDL_PixelFormat_RGB888;
    7.89 +                break;
    7.90 +            case 0x000000FF:
    7.91 +                mode->format = SDL_PixelFormat_BGR888;
    7.92 +                break;
    7.93 +            case 0xF800:
    7.94 +                mode->format = SDL_PixelFormat_RGB565;
    7.95 +                break;
    7.96 +            case 0x7C00:
    7.97 +                mode->format = SDL_PixelFormat_RGB555;
    7.98 +                break;
    7.99 +            }
   7.100 +        } else if (bmi->bmiHeader.biBitCount == 8) {
   7.101 +            mode->format = SDL_PixelFormat_Index8;
   7.102 +        }
   7.103 +    } else {
   7.104 +        switch (devmode.dmBitsPerPel) {
   7.105 +        case 32:
   7.106 +            mode->format = SDL_PixelFormat_RGB888;
   7.107 +            break;
   7.108 +        case 24:
   7.109 +            mode->format = SDL_PixelFormat_RGB24;
   7.110 +            break;
   7.111 +        case 16:
   7.112 +            mode->format = SDL_PixelFormat_RGB565;
   7.113 +            break;
   7.114 +        case 15:
   7.115 +            mode->format = SDL_PixelFormat_RGB555;
   7.116 +            break;
   7.117 +        case 8:
   7.118 +            mode->format = SDL_PixelFormat_Index8;
   7.119 +            break;
   7.120 +        }
   7.121 +    }
   7.122 +    return SDL_TRUE;
   7.123 +}
   7.124 +
   7.125 +void
   7.126 +WIN_InitModes(_THIS)
   7.127 +{
   7.128 +    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
   7.129 +    DWORD i, j, k;
   7.130 +    DISPLAY_DEVICE device;
   7.131 +
   7.132 +    device.cb = sizeof(device);
   7.133 +    for (i = 0;; ++i) {
   7.134 +        TCHAR DeviceName[32];
   7.135 +
   7.136 +        if (!EnumDisplayDevices(NULL, i, &device, 0)) {
   7.137 +            break;
   7.138 +        }
   7.139 +        if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
   7.140 +            continue;
   7.141 +        }
   7.142 +        SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
   7.143 +#ifdef DEBUG_MODES
   7.144 +        printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
   7.145 +#endif
   7.146 +        for (j = 0;; ++j) {
   7.147 +            int index;
   7.148 +            SDL_VideoDisplay display;
   7.149 +            SDL_DisplayMode mode;
   7.150 +
   7.151 +            if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
   7.152 +                break;
   7.153 +            }
   7.154 +            if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
   7.155 +                continue;
   7.156 +            }
   7.157 +#ifdef DEBUG_MODES
   7.158 +            printf("Monitor: %s\n", WIN_StringToUTF8(device.DeviceName));
   7.159 +#endif
   7.160 +            if (!WIN_GetDisplayMode(DeviceName, ENUM_CURRENT_SETTINGS, &mode)) {
   7.161 +                break;
   7.162 +            }
   7.163 +            SDL_zero(display);
   7.164 +            display.desktop_mode = mode;
   7.165 +            display.current_mode = mode;
   7.166 +            index = SDL_AddVideoDisplay(&display);
   7.167 +
   7.168 +            for (k = 0;; ++k) {
   7.169 +                if (!WIN_GetDisplayMode(DeviceName, k, &mode)) {
   7.170 +                    break;
   7.171 +                }
   7.172 +                if (!SDL_AddDisplayMode(index, &mode)) {
   7.173 +                    SDL_free(mode.driverdata);
   7.174 +                }
   7.175 +            }
   7.176 +        }
   7.177 +    }
   7.178 +}
   7.179 +
   7.180 +int
   7.181 +WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   7.182 +{
   7.183 +    SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
   7.184 +    LONG status;
   7.185 +
   7.186 +    status =
   7.187 +        ChangeDisplaySettingsEx(data->DeviceName, &data->DeviceMode, NULL,
   7.188 +                                CDS_FULLSCREEN, NULL);
   7.189 +    if (status == DISP_CHANGE_SUCCESSFUL) {
   7.190 +        return 0;
   7.191 +    } else {
   7.192 +        const char *reason = "Unknown reason";
   7.193 +        switch (status) {
   7.194 +        case DISP_CHANGE_BADFLAGS:
   7.195 +            reason = "DISP_CHANGE_BADFLAGS";
   7.196 +            break;
   7.197 +        case DISP_CHANGE_BADMODE:
   7.198 +            reason = "DISP_CHANGE_BADMODE";
   7.199 +            break;
   7.200 +        case DISP_CHANGE_BADPARAM:
   7.201 +            reason = "DISP_CHANGE_BADPARAM";
   7.202 +            break;
   7.203 +        case DISP_CHANGE_FAILED:
   7.204 +            reason = "DISP_CHANGE_FAILED";
   7.205 +            break;
   7.206 +        }
   7.207 +        SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
   7.208 +        return -1;
   7.209 +    }
   7.210 +}
   7.211 +
   7.212 +void
   7.213 +WIN_QuitModes(_THIS)
   7.214 +{
   7.215 +    ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
   7.216 +}
   7.217 +
   7.218 +/* vi: set ts=4 sw=4 expandtab: */
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/video/win32/SDL_win32modes.h	Fri Jul 07 08:05:39 2006 +0000
     8.3 @@ -0,0 +1,33 @@
     8.4 +/*
     8.5 +    SDL - Simple DirectMedia Layer
     8.6 +    Copyright (C) 1997-2006 Sam Lantinga
     8.7 +
     8.8 +    This library is free software; you can redistribute it and/or
     8.9 +    modify it under the terms of the GNU Lesser General Public
    8.10 +    License as published by the Free Software Foundation; either
    8.11 +    version 2.1 of the License, or (at your option) any later version.
    8.12 +
    8.13 +    This library is distributed in the hope that it will be useful,
    8.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    8.16 +    Lesser General Public License for more details.
    8.17 +
    8.18 +    You should have received a copy of the GNU Lesser General Public
    8.19 +    License along with this library; if not, write to the Free Software
    8.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    8.21 +
    8.22 +    Sam Lantinga
    8.23 +    slouken@libsdl.org
    8.24 +*/
    8.25 +#include "SDL_config.h"
    8.26 +
    8.27 +#ifndef _SDL_win32modes_h
    8.28 +#define _SDL_win32modes_h
    8.29 +
    8.30 +extern void WIN_InitModes(_THIS);
    8.31 +extern int WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
    8.32 +extern void WIN_QuitModes(_THIS);
    8.33 +
    8.34 +#endif /* _SDL_win32modes_h */
    8.35 +
    8.36 +/* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/video/win32/SDL_win32mouse.c	Thu Jul 06 07:17:11 2006 +0000
     9.2 +++ b/src/video/win32/SDL_win32mouse.c	Fri Jul 07 08:05:39 2006 +0000
     9.3 @@ -26,7 +26,7 @@
     9.4  #include "../../events/SDL_mouse_c.h"
     9.5  
     9.6  void
     9.7 -WIN_AddMouse(_THIS)
     9.8 +WIN_InitMouse(_THIS)
     9.9  {
    9.10      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    9.11      SDL_Mouse mouse;
    9.12 @@ -36,7 +36,7 @@
    9.13  }
    9.14  
    9.15  void
    9.16 -WIN_DelMouse(_THIS)
    9.17 +WIN_QuitMouse(_THIS)
    9.18  {
    9.19      SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
    9.20  
    10.1 --- a/src/video/win32/SDL_win32mouse.h	Thu Jul 06 07:17:11 2006 +0000
    10.2 +++ b/src/video/win32/SDL_win32mouse.h	Fri Jul 07 08:05:39 2006 +0000
    10.3 @@ -24,8 +24,8 @@
    10.4  #ifndef _SDL_win32mouse_h
    10.5  #define _SDL_win32mouse_h
    10.6  
    10.7 -extern void WIN_AddMouse(_THIS);
    10.8 -extern void WIN_DelMouse(_THIS);
    10.9 +extern void WIN_InitMouse(_THIS);
   10.10 +extern void WIN_QuitMouse(_THIS);
   10.11  
   10.12  #endif /* _SDL_win32mouse_h */
   10.13  
    11.1 --- a/src/video/win32/SDL_win32video.c	Thu Jul 06 07:17:11 2006 +0000
    11.2 +++ b/src/video/win32/SDL_win32video.c	Fri Jul 07 08:05:39 2006 +0000
    11.3 @@ -32,7 +32,6 @@
    11.4  
    11.5  /* Initialization/Query functions */
    11.6  static int WIN_VideoInit(_THIS);
    11.7 -static int WIN_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
    11.8  static void WIN_VideoQuit(_THIS);
    11.9  
   11.10  /* WIN32 driver bootstrap functions */
   11.11 @@ -108,74 +107,21 @@
   11.12  int
   11.13  WIN_VideoInit(_THIS)
   11.14  {
   11.15 -    int bmi_size;
   11.16 -    LPBITMAPINFO bmi;
   11.17 -    SDL_DisplayMode mode;
   11.18 -
   11.19 -    /* Find out the desktop mode */
   11.20 -    mode.format = SDL_PixelFormat_Unknown;
   11.21 -    mode.w = GetSystemMetrics(SM_CXSCREEN);
   11.22 -    mode.h = GetSystemMetrics(SM_CYSCREEN);
   11.23 -    mode.refresh_rate = 0;
   11.24 -
   11.25 -    bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
   11.26 -    bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
   11.27 -    if (bmi) {
   11.28 -        HDC hdc;
   11.29 -        HBITMAP hbm;
   11.30 -
   11.31 -        SDL_memset(bmi, 0, bmi_size);
   11.32 -        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
   11.33 -        hdc = GetDC(NULL);
   11.34 -        hbm = CreateCompatibleBitmap(hdc, 1, 1);
   11.35 -        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
   11.36 -        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
   11.37 -        DeleteObject(hbm);
   11.38 -        ReleaseDC(NULL, hdc);
   11.39 -        if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
   11.40 -            switch (*(Uint32 *) bmi->bmiColors) {
   11.41 -            case 0x00FF0000:
   11.42 -                mode.format = SDL_PixelFormat_RGB888;
   11.43 -                break;
   11.44 -            case 0x000000FF:
   11.45 -                mode.format = SDL_PixelFormat_BGR888;
   11.46 -                break;
   11.47 -            case 0xF800:
   11.48 -                mode.format = SDL_PixelFormat_RGB565;
   11.49 -                break;
   11.50 -            case 0x7C00:
   11.51 -                mode.format = SDL_PixelFormat_RGB555;
   11.52 -                break;
   11.53 -            }
   11.54 -        } else if (bmi->bmiHeader.biBitCount == 8) {
   11.55 -            mode.format = SDL_PixelFormat_Index8;
   11.56 -        }
   11.57 -    }
   11.58 -    SDL_AddBasicVideoDisplay(&mode);
   11.59 +    WIN_InitModes(_this);
   11.60      SDL_AddRenderDriver(0, &SDL_DIB_RenderDriver);
   11.61  
   11.62 -    SDL_zero(mode);
   11.63 -    SDL_AddDisplayMode(0, &mode);
   11.64 +    WIN_InitKeyboard(_this);
   11.65 +    WIN_InitMouse(_this);
   11.66  
   11.67 -    WIN_AddKeyboard(_this);
   11.68 -    WIN_AddMouse(_this);
   11.69 -
   11.70 -    /* We're done! */
   11.71 -    return 0;
   11.72 -}
   11.73 -
   11.74 -static int
   11.75 -WIN_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
   11.76 -{
   11.77 -    SDL_CurrentDisplay.current_mode = *mode;
   11.78      return 0;
   11.79  }
   11.80  
   11.81  void
   11.82  WIN_VideoQuit(_THIS)
   11.83  {
   11.84 -    WIN_DelKeyboard(_this);
   11.85 -    WIN_DelMouse(_this);
   11.86 +    WIN_QuitModes(_this);
   11.87 +    WIN_QuitKeyboard(_this);
   11.88 +    WIN_QuitMouse(_this);
   11.89  }
   11.90  
   11.91  /* vim: set ts=4 sw=4 expandtab: */
    12.1 --- a/src/video/win32/SDL_win32video.h	Thu Jul 06 07:17:11 2006 +0000
    12.2 +++ b/src/video/win32/SDL_win32video.h	Fri Jul 07 08:05:39 2006 +0000
    12.3 @@ -28,11 +28,12 @@
    12.4  
    12.5  #define WIN32_LEAN_AND_MEAN
    12.6  #define UNICODE
    12.7 -#define WINVER  0x0410          // 0x0410 needed for AlphaBlend()
    12.8 +#define WINVER  0x500           // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices()
    12.9  #include <windows.h>
   12.10  
   12.11  #include "SDL_win32events.h"
   12.12  #include "SDL_win32keyboard.h"
   12.13 +#include "SDL_win32modes.h"
   12.14  #include "SDL_win32mouse.h"
   12.15  #include "SDL_win32window.h"
   12.16  
    13.1 --- a/test/testsprite2.c	Thu Jul 06 07:17:11 2006 +0000
    13.2 +++ b/test/testsprite2.c	Fri Jul 07 08:05:39 2006 +0000
    13.3 @@ -122,6 +122,8 @@
    13.4  main(int argc, char *argv[])
    13.5  {
    13.6      int window_w, window_h;
    13.7 +    Uint32 window_flags = SDL_WINDOW_SHOWN;
    13.8 +    SDL_DisplayMode *mode, fullscreen_mode;
    13.9      int i, done;
   13.10      SDL_Event event;
   13.11      Uint32 then, now, frames;
   13.12 @@ -137,13 +139,16 @@
   13.13      window_w = WINDOW_W;
   13.14      window_h = WINDOW_H;
   13.15      while (argc > 1) {
   13.16 -        --argc;
   13.17          if (strcmp(argv[argc - 1], "-width") == 0) {
   13.18              window_w = atoi(argv[argc]);
   13.19              --argc;
   13.20          } else if (strcmp(argv[argc - 1], "-height") == 0) {
   13.21              window_h = atoi(argv[argc]);
   13.22              --argc;
   13.23 +        } else if (strcmp(argv[argc - 1], "-fullscreen") == 0) {
   13.24 +            num_windows = 1;
   13.25 +            window_flags |= SDL_WINDOW_FULLSCREEN;
   13.26 +            --argc;
   13.27          } else if (isdigit(argv[argc][0])) {
   13.28              num_sprites = atoi(argv[argc]);
   13.29          } else {
   13.30 @@ -153,8 +158,16 @@
   13.31          }
   13.32      }
   13.33  
   13.34 -    /* Set the desktop mode, we don't care what it is */
   13.35 -    if (SDL_SetDisplayMode(NULL) < 0) {
   13.36 +    if (window_flags & SDL_WINDOW_FULLSCREEN) {
   13.37 +        SDL_zero(fullscreen_mode);
   13.38 +        fullscreen_mode.w = window_w;
   13.39 +        fullscreen_mode.h = window_h;
   13.40 +        mode = &fullscreen_mode;
   13.41 +    } else {
   13.42 +        /* Set the desktop mode, we don't care what it is */
   13.43 +        mode = NULL;
   13.44 +    }
   13.45 +    if (SDL_SetDisplayMode(mode) < 0) {
   13.46          fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError());
   13.47          quit(2);
   13.48      }
   13.49 @@ -173,7 +186,7 @@
   13.50          windows[i] =
   13.51              SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED,
   13.52                               SDL_WINDOWPOS_UNDEFINED, window_w, window_h,
   13.53 -                             SDL_WINDOW_SHOWN);
   13.54 +                             window_flags);
   13.55          if (!windows[i]) {
   13.56              fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
   13.57              quit(2);
    14.1 --- a/test/testvidinfo.c	Thu Jul 06 07:17:11 2006 +0000
    14.2 +++ b/test/testvidinfo.c	Fri Jul 07 08:05:39 2006 +0000
    14.3 @@ -417,7 +417,7 @@
    14.4  main(int argc, char *argv[])
    14.5  {
    14.6      const SDL_VideoInfo *info;
    14.7 -    int i, n;
    14.8 +    int i, d, n;
    14.9      const char *driver;
   14.10      const SDL_DisplayMode *mode;
   14.11      int bpp;
   14.12 @@ -448,39 +448,46 @@
   14.13          printf("Video driver: %s\n", driver);
   14.14      }
   14.15      printf("Number of displays: %d\n", SDL_GetNumVideoDisplays());
   14.16 -    mode = SDL_GetDesktopDisplayMode();
   14.17 -    SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask,
   14.18 -                               &Amask);
   14.19 -    printf("Current display: %dx%d@%dHz, %d bits-per-pixel\n", mode->w,
   14.20 -           mode->h, mode->refresh_rate, bpp);
   14.21 -    if (Rmask || Gmask || Bmask) {
   14.22 -        printf("	Red Mask = 0x%.8x\n", Rmask);
   14.23 -        printf("	Green Mask = 0x%.8x\n", Gmask);
   14.24 -        printf("	Blue Mask = 0x%.8x\n", Bmask);
   14.25 -        if (Amask)
   14.26 -            printf("	Alpha Mask = 0x%.8x\n", Amask);
   14.27 -    }
   14.28 -    /* Print available fullscreen video modes */
   14.29 -    nmodes = SDL_GetNumDisplayModes();
   14.30 -    if (nmodes == 0) {
   14.31 -        printf("No available fullscreen video modes\n");
   14.32 -    } else {
   14.33 -        printf("Fullscreen video modes:\n");
   14.34 -        for (i = 0; i < nmodes; ++i) {
   14.35 -            mode = SDL_GetDisplayMode(i);
   14.36 -            SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
   14.37 -                                       &Gmask, &Bmask, &Amask);
   14.38 -            printf("Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i,
   14.39 -                   mode->w, mode->h, mode->refresh_rate, bpp);
   14.40 -            if (Rmask || Gmask || Bmask) {
   14.41 -                printf("	Red Mask = 0x%.8x\n", Rmask);
   14.42 -                printf("	Green Mask = 0x%.8x\n", Gmask);
   14.43 -                printf("	Blue Mask = 0x%.8x\n", Bmask);
   14.44 -                if (Amask)
   14.45 -                    printf("	Alpha Mask = 0x%.8x\n", Amask);
   14.46 +    for (d = 0; d < SDL_GetNumVideoDisplays(); ++d) {
   14.47 +        printf("Display %d:\n", d);
   14.48 +        SDL_SelectVideoDisplay(d);
   14.49 +
   14.50 +        mode = SDL_GetDesktopDisplayMode();
   14.51 +        SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask,
   14.52 +                                   &Amask);
   14.53 +        printf("  Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode->w,
   14.54 +               mode->h, mode->refresh_rate, bpp);
   14.55 +        if (Rmask || Gmask || Bmask) {
   14.56 +            printf("      Red Mask = 0x%.8x\n", Rmask);
   14.57 +            printf("      Green Mask = 0x%.8x\n", Gmask);
   14.58 +            printf("      Blue Mask = 0x%.8x\n", Bmask);
   14.59 +            if (Amask)
   14.60 +                printf("      Alpha Mask = 0x%.8x\n", Amask);
   14.61 +        }
   14.62 +
   14.63 +        /* Print available fullscreen video modes */
   14.64 +        nmodes = SDL_GetNumDisplayModes();
   14.65 +        if (nmodes == 0) {
   14.66 +            printf("No available fullscreen video modes\n");
   14.67 +        } else {
   14.68 +            printf("  Fullscreen video modes:\n");
   14.69 +            for (i = 0; i < nmodes; ++i) {
   14.70 +                mode = SDL_GetDisplayMode(i);
   14.71 +                SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
   14.72 +                                           &Gmask, &Bmask, &Amask);
   14.73 +                printf("    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i,
   14.74 +                       mode->w, mode->h, mode->refresh_rate, bpp);
   14.75 +                if (Rmask || Gmask || Bmask) {
   14.76 +                    printf("        Red Mask = 0x%.8x\n", Rmask);
   14.77 +                    printf("        Green Mask = 0x%.8x\n", Gmask);
   14.78 +                    printf("        Blue Mask = 0x%.8x\n", Bmask);
   14.79 +                    if (Amask)
   14.80 +                        printf("        Alpha Mask = 0x%.8x\n", Amask);
   14.81 +                }
   14.82              }
   14.83          }
   14.84      }
   14.85 +
   14.86      info = SDL_GetVideoInfo();
   14.87      if (info->wm_available) {
   14.88          printf("A window manager is available\n");
    15.1 --- a/test/testwm2.c	Thu Jul 06 07:17:11 2006 +0000
    15.2 +++ b/test/testwm2.c	Fri Jul 07 08:05:39 2006 +0000
    15.3 @@ -37,7 +37,6 @@
    15.4      window_w = WINDOW_W;
    15.5      window_h = WINDOW_H;
    15.6      while (argc > 1) {
    15.7 -        --argc;
    15.8          if (strcmp(argv[argc - 1], "-width") == 0) {
    15.9              window_w = atoi(argv[argc]);
   15.10              --argc;