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 1725 98a3207ddde8
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
--- a/include/SDL_video.h	Thu Jul 06 07:17:11 2006 +0000
+++ b/include/SDL_video.h	Fri Jul 07 08:05:39 2006 +0000
@@ -75,6 +75,7 @@
     int w;                      /**< width */
     int h;                      /**< height */
     int refresh_rate;           /**< refresh rate (or zero for unspecified) */
+    void *driverdata;           /**< driver-specific data, initialize to 0 */
 } SDL_DisplayMode;
 
 /**
--- a/src/video/SDL_sysvideo.h	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/SDL_sysvideo.h	Fri Jul 07 08:05:39 2006 +0000
@@ -131,6 +131,7 @@
  */
 struct SDL_VideoDisplay
 {
+    int max_display_modes;
     int num_display_modes;
     SDL_DisplayMode *display_modes;
     SDL_DisplayMode desktop_mode;
@@ -178,7 +179,7 @@
      * should have their data updated accordingly, including the
      * display surfaces associated with them.
      */
-    int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
+    int (*SetDisplayMode) (_THIS, SDL_DisplayMode * mode);
 
     /* Sets the color entries of the display palette to those in 'colors'.
        The return value is 0 if all entries could be set properly or -1
@@ -410,8 +411,8 @@
 extern SDL_VideoDevice *SDL_GetVideoDevice();
 extern int SDL_AddBasicVideoDisplay(const SDL_DisplayMode * desktop_mode);
 extern int SDL_AddVideoDisplay(const SDL_VideoDisplay * display);
-extern void SDL_AddDisplayMode(int displayIndex,
-                               const SDL_DisplayMode * mode);
+extern SDL_bool SDL_AddDisplayMode(int displayIndex,
+                                   const SDL_DisplayMode * mode);
 extern void SDL_AddRenderDriver(int displayIndex,
                                 const SDL_RenderDriver * driver);
 
--- a/src/video/SDL_video.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/SDL_video.c	Fri Jul 07 08:05:39 2006 +0000
@@ -362,7 +362,7 @@
     return _this->current_display;
 }
 
-void
+SDL_bool
 SDL_AddDisplayMode(int displayIndex, const SDL_DisplayMode * mode)
 {
     SDL_VideoDisplay *display = &_this->displays[displayIndex];
@@ -372,19 +372,27 @@
     /* Make sure we don't already have the mode in the list */
     modes = display->display_modes;
     nmodes = display->num_display_modes;
-    for (i = 0; i < nmodes; ++i) {
+    for (i = nmodes; i--;) {
         if (SDL_memcmp(mode, &modes[i], sizeof(*mode)) == 0) {
-            return;
+            return SDL_FALSE;
         }
     }
 
     /* Go ahead and add the new mode */
-    modes = SDL_realloc(modes, (nmodes + 1) * sizeof(*mode));
-    if (modes) {
+    if (nmodes == display->max_display_modes) {
+        modes =
+            SDL_realloc(modes,
+                        (display->max_display_modes + 32) * sizeof(*modes));
+        if (!modes) {
+            return SDL_FALSE;
+        }
         display->display_modes = modes;
-        modes[nmodes] = *mode;
-        display->num_display_modes++;
+        display->max_display_modes += 32;
     }
+    modes[nmodes] = *mode;
+    display->num_display_modes++;
+
+    return SDL_TRUE;
 }
 
 int
@@ -501,6 +509,8 @@
         } else {
             closest->refresh_rate = mode->refresh_rate;
         }
+        closest->driverdata = match->driverdata;
+
         /* Pick some reasonable defaults if the app and driver don't care */
         if (!closest->format) {
             closest->format = SDL_PixelFormat_RGB888;
@@ -521,7 +531,7 @@
 {
     SDL_VideoDisplay *display;
     SDL_DisplayMode display_mode;
-    int ncolors;
+    int i, ncolors;
 
     if (!_this) {
         SDL_SetError("Video subsystem has not been initialized");
@@ -562,6 +572,12 @@
         return 0;
     }
 
+    /* Actually change the display mode */
+    if (_this->SetDisplayMode(_this, &display_mode) < 0) {
+        return -1;
+    }
+    display->current_mode = display_mode;
+
     /* Set up a palette, if necessary */
     if (SDL_ISPIXELFORMAT_INDEXED(display_mode.format)) {
         ncolors = (1 << SDL_BITSPERPIXEL(display_mode.format));
@@ -584,7 +600,17 @@
         }
     }
 
-    return _this->SetDisplayMode(_this, &display_mode);
+    /* Move any fullscreen windows into position */
+    for (i = 0; i < display->num_windows; ++i) {
+        SDL_Window *window = &display->windows[i];
+        if (window->flags & SDL_WINDOW_FULLSCREEN) {
+            SDL_SetWindowPosition(window->id,
+                                  ((display_mode.w - window->w) / 2),
+                                  ((display_mode.h - window->h) / 2));
+        }
+    }
+
+    return 0;
 }
 
 int
@@ -662,8 +688,14 @@
     SDL_zero(window);
     window.id = _this->next_object_id++;
     window.title = title ? SDL_strdup(title) : NULL;
-    window.x = x;
-    window.y = y;
+    if (flags & SDL_WINDOW_FULLSCREEN) {
+        const SDL_DisplayMode *mode = &SDL_CurrentDisplay.current_mode;
+        window.x = (mode->w - w) / 2;
+        window.y = (mode->h - h) / 2;
+    } else {
+        window.x = x;
+        window.y = y;
+    }
     window.w = w;
     window.h = h;
     window.flags = (flags & allowed_flags);
@@ -1813,14 +1845,34 @@
             SDL_free(display->windows);
             display->windows = NULL;
         }
+        display->num_windows = 0;
+    }
+    _this->VideoQuit(_this);
+
+    for (i = _this->num_displays; i--;) {
+        SDL_VideoDisplay *display = &_this->displays[i];
+        for (j = display->num_display_modes; j--;) {
+            if (display->display_modes[j].driverdata) {
+                SDL_free(display->display_modes[j].driverdata);
+                display->display_modes[j].driverdata = NULL;
+            }
+        }
+        if (display->display_modes) {
+            SDL_free(display->display_modes);
+            display->display_modes = NULL;
+        }
+        if (display->desktop_mode.driverdata) {
+            SDL_free(display->desktop_mode.driverdata);
+            display->desktop_mode.driverdata = NULL;
+        }
         if (display->palette) {
             SDL_FreePalette(display->palette);
             display->palette = NULL;
         }
     }
-    _this->VideoQuit(_this);
     if (_this->displays) {
         SDL_free(_this->displays);
+        _this->displays = NULL;
     }
     _this->free(_this);
     _this = NULL;
--- a/src/video/dummy/SDL_nullvideo.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/dummy/SDL_nullvideo.c	Fri Jul 07 08:05:39 2006 +0000
@@ -50,7 +50,7 @@
 
 /* Initialization/Query functions */
 static int DUMMY_VideoInit(_THIS);
-static int DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
+static int DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
 static void DUMMY_VideoQuit(_THIS);
 
 /* DUMMY driver bootstrap functions */
@@ -120,9 +120,8 @@
 }
 
 static int
-DUMMY_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
+DUMMY_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
 {
-    SDL_CurrentDisplay.current_mode = *mode;
     return 0;
 }
 
--- a/src/video/win32/SDL_win32keyboard.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/win32/SDL_win32keyboard.c	Fri Jul 07 08:05:39 2006 +0000
@@ -26,7 +26,7 @@
 #include "../../events/SDL_keyboard_c.h"
 
 void
-WIN_AddKeyboard(_THIS)
+WIN_InitKeyboard(_THIS)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_Keyboard keyboard;
@@ -36,7 +36,7 @@
 }
 
 void
-WIN_DelKeyboard(_THIS)
+WIN_QuitKeyboard(_THIS)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
 
--- a/src/video/win32/SDL_win32keyboard.h	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/win32/SDL_win32keyboard.h	Fri Jul 07 08:05:39 2006 +0000
@@ -24,8 +24,8 @@
 #ifndef _SDL_win32keyboard_h
 #define _SDL_win32keyboard_h
 
-extern void WIN_AddKeyboard(_THIS);
-extern void WIN_DelKeyboard(_THIS);
+extern void WIN_InitKeyboard(_THIS);
+extern void WIN_QuitKeyboard(_THIS);
 
 #endif /* _SDL_win32keyboard_h */
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/win32/SDL_win32modes.c	Fri Jul 07 08:05:39 2006 +0000
@@ -0,0 +1,215 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2006 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+#include "SDL_win32video.h"
+
+
+typedef struct
+{
+    TCHAR DeviceName[32];
+    DEVMODE DeviceMode;
+} SDL_DisplayModeData;
+
+/* FIXME: Each call to EnumDisplaySettings() takes about 6 ms on my laptop.
+          With 500 or so modes, this takes almost 3 seconds to run!
+*/
+
+static SDL_bool
+WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
+{
+    SDL_DisplayModeData *data;
+    DEVMODE devmode;
+    HDC hdc;
+
+    devmode.dmSize = sizeof(devmode);
+    devmode.dmDriverExtra = 0;
+    if (!EnumDisplaySettings(deviceName, index, &devmode)) {
+        return SDL_FALSE;
+    }
+
+    data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
+    if (!data) {
+        return SDL_FALSE;
+    }
+    SDL_memcpy(data->DeviceName, deviceName, sizeof(data->DeviceName));
+    data->DeviceMode = devmode;
+    data->DeviceMode.dmFields =
+        (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
+         DM_DISPLAYFLAGS);
+
+    /* Fill in the mode information */
+    mode->format = SDL_PixelFormat_Unknown;
+    mode->w = devmode.dmPelsWidth;
+    mode->h = devmode.dmPelsHeight;
+    mode->refresh_rate = devmode.dmDisplayFrequency;
+    mode->driverdata = data;
+
+    hdc = CreateDC(deviceName, NULL, NULL, &devmode);
+    if (hdc) {
+        char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
+        LPBITMAPINFO bmi;
+        HBITMAP hbm;
+
+        SDL_zero(bmi_data);
+        bmi = (LPBITMAPINFO) bmi_data;
+        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+
+        hbm = CreateCompatibleBitmap(hdc, 1, 1);
+        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
+        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
+        DeleteObject(hbm);
+        DeleteDC(hdc);
+        if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
+            switch (*(Uint32 *) bmi->bmiColors) {
+            case 0x00FF0000:
+                mode->format = SDL_PixelFormat_RGB888;
+                break;
+            case 0x000000FF:
+                mode->format = SDL_PixelFormat_BGR888;
+                break;
+            case 0xF800:
+                mode->format = SDL_PixelFormat_RGB565;
+                break;
+            case 0x7C00:
+                mode->format = SDL_PixelFormat_RGB555;
+                break;
+            }
+        } else if (bmi->bmiHeader.biBitCount == 8) {
+            mode->format = SDL_PixelFormat_Index8;
+        }
+    } else {
+        switch (devmode.dmBitsPerPel) {
+        case 32:
+            mode->format = SDL_PixelFormat_RGB888;
+            break;
+        case 24:
+            mode->format = SDL_PixelFormat_RGB24;
+            break;
+        case 16:
+            mode->format = SDL_PixelFormat_RGB565;
+            break;
+        case 15:
+            mode->format = SDL_PixelFormat_RGB555;
+            break;
+        case 8:
+            mode->format = SDL_PixelFormat_Index8;
+            break;
+        }
+    }
+    return SDL_TRUE;
+}
+
+void
+WIN_InitModes(_THIS)
+{
+    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
+    DWORD i, j, k;
+    DISPLAY_DEVICE device;
+
+    device.cb = sizeof(device);
+    for (i = 0;; ++i) {
+        TCHAR DeviceName[32];
+
+        if (!EnumDisplayDevices(NULL, i, &device, 0)) {
+            break;
+        }
+        if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
+            continue;
+        }
+        SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
+#ifdef DEBUG_MODES
+        printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
+#endif
+        for (j = 0;; ++j) {
+            int index;
+            SDL_VideoDisplay display;
+            SDL_DisplayMode mode;
+
+            if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
+                break;
+            }
+            if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
+                continue;
+            }
+#ifdef DEBUG_MODES
+            printf("Monitor: %s\n", WIN_StringToUTF8(device.DeviceName));
+#endif
+            if (!WIN_GetDisplayMode(DeviceName, ENUM_CURRENT_SETTINGS, &mode)) {
+                break;
+            }
+            SDL_zero(display);
+            display.desktop_mode = mode;
+            display.current_mode = mode;
+            index = SDL_AddVideoDisplay(&display);
+
+            for (k = 0;; ++k) {
+                if (!WIN_GetDisplayMode(DeviceName, k, &mode)) {
+                    break;
+                }
+                if (!SDL_AddDisplayMode(index, &mode)) {
+                    SDL_free(mode.driverdata);
+                }
+            }
+        }
+    }
+}
+
+int
+WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
+{
+    SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
+    LONG status;
+
+    status =
+        ChangeDisplaySettingsEx(data->DeviceName, &data->DeviceMode, NULL,
+                                CDS_FULLSCREEN, NULL);
+    if (status == DISP_CHANGE_SUCCESSFUL) {
+        return 0;
+    } else {
+        const char *reason = "Unknown reason";
+        switch (status) {
+        case DISP_CHANGE_BADFLAGS:
+            reason = "DISP_CHANGE_BADFLAGS";
+            break;
+        case DISP_CHANGE_BADMODE:
+            reason = "DISP_CHANGE_BADMODE";
+            break;
+        case DISP_CHANGE_BADPARAM:
+            reason = "DISP_CHANGE_BADPARAM";
+            break;
+        case DISP_CHANGE_FAILED:
+            reason = "DISP_CHANGE_FAILED";
+            break;
+        }
+        SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
+        return -1;
+    }
+}
+
+void
+WIN_QuitModes(_THIS)
+{
+    ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
+}
+
+/* vi: set ts=4 sw=4 expandtab: */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/video/win32/SDL_win32modes.h	Fri Jul 07 08:05:39 2006 +0000
@@ -0,0 +1,33 @@
+/*
+    SDL - Simple DirectMedia Layer
+    Copyright (C) 1997-2006 Sam Lantinga
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+    Sam Lantinga
+    slouken@libsdl.org
+*/
+#include "SDL_config.h"
+
+#ifndef _SDL_win32modes_h
+#define _SDL_win32modes_h
+
+extern void WIN_InitModes(_THIS);
+extern int WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
+extern void WIN_QuitModes(_THIS);
+
+#endif /* _SDL_win32modes_h */
+
+/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/win32/SDL_win32mouse.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/win32/SDL_win32mouse.c	Fri Jul 07 08:05:39 2006 +0000
@@ -26,7 +26,7 @@
 #include "../../events/SDL_mouse_c.h"
 
 void
-WIN_AddMouse(_THIS)
+WIN_InitMouse(_THIS)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
     SDL_Mouse mouse;
@@ -36,7 +36,7 @@
 }
 
 void
-WIN_DelMouse(_THIS)
+WIN_QuitMouse(_THIS)
 {
     SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
 
--- a/src/video/win32/SDL_win32mouse.h	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/win32/SDL_win32mouse.h	Fri Jul 07 08:05:39 2006 +0000
@@ -24,8 +24,8 @@
 #ifndef _SDL_win32mouse_h
 #define _SDL_win32mouse_h
 
-extern void WIN_AddMouse(_THIS);
-extern void WIN_DelMouse(_THIS);
+extern void WIN_InitMouse(_THIS);
+extern void WIN_QuitMouse(_THIS);
 
 #endif /* _SDL_win32mouse_h */
 
--- a/src/video/win32/SDL_win32video.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/win32/SDL_win32video.c	Fri Jul 07 08:05:39 2006 +0000
@@ -32,7 +32,6 @@
 
 /* Initialization/Query functions */
 static int WIN_VideoInit(_THIS);
-static int WIN_SetDisplayMode(_THIS, const SDL_DisplayMode * mode);
 static void WIN_VideoQuit(_THIS);
 
 /* WIN32 driver bootstrap functions */
@@ -108,74 +107,21 @@
 int
 WIN_VideoInit(_THIS)
 {
-    int bmi_size;
-    LPBITMAPINFO bmi;
-    SDL_DisplayMode mode;
-
-    /* Find out the desktop mode */
-    mode.format = SDL_PixelFormat_Unknown;
-    mode.w = GetSystemMetrics(SM_CXSCREEN);
-    mode.h = GetSystemMetrics(SM_CYSCREEN);
-    mode.refresh_rate = 0;
-
-    bmi_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
-    bmi = (LPBITMAPINFO) SDL_malloc(bmi_size);
-    if (bmi) {
-        HDC hdc;
-        HBITMAP hbm;
-
-        SDL_memset(bmi, 0, bmi_size);
-        bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-        hdc = GetDC(NULL);
-        hbm = CreateCompatibleBitmap(hdc, 1, 1);
-        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
-        GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
-        DeleteObject(hbm);
-        ReleaseDC(NULL, hdc);
-        if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
-            switch (*(Uint32 *) bmi->bmiColors) {
-            case 0x00FF0000:
-                mode.format = SDL_PixelFormat_RGB888;
-                break;
-            case 0x000000FF:
-                mode.format = SDL_PixelFormat_BGR888;
-                break;
-            case 0xF800:
-                mode.format = SDL_PixelFormat_RGB565;
-                break;
-            case 0x7C00:
-                mode.format = SDL_PixelFormat_RGB555;
-                break;
-            }
-        } else if (bmi->bmiHeader.biBitCount == 8) {
-            mode.format = SDL_PixelFormat_Index8;
-        }
-    }
-    SDL_AddBasicVideoDisplay(&mode);
+    WIN_InitModes(_this);
     SDL_AddRenderDriver(0, &SDL_DIB_RenderDriver);
 
-    SDL_zero(mode);
-    SDL_AddDisplayMode(0, &mode);
-
-    WIN_AddKeyboard(_this);
-    WIN_AddMouse(_this);
+    WIN_InitKeyboard(_this);
+    WIN_InitMouse(_this);
 
-    /* We're done! */
-    return 0;
-}
-
-static int
-WIN_SetDisplayMode(_THIS, const SDL_DisplayMode * mode)
-{
-    SDL_CurrentDisplay.current_mode = *mode;
     return 0;
 }
 
 void
 WIN_VideoQuit(_THIS)
 {
-    WIN_DelKeyboard(_this);
-    WIN_DelMouse(_this);
+    WIN_QuitModes(_this);
+    WIN_QuitKeyboard(_this);
+    WIN_QuitMouse(_this);
 }
 
 /* vim: set ts=4 sw=4 expandtab: */
--- a/src/video/win32/SDL_win32video.h	Thu Jul 06 07:17:11 2006 +0000
+++ b/src/video/win32/SDL_win32video.h	Fri Jul 07 08:05:39 2006 +0000
@@ -28,11 +28,12 @@
 
 #define WIN32_LEAN_AND_MEAN
 #define UNICODE
-#define WINVER  0x0410          // 0x0410 needed for AlphaBlend()
+#define WINVER  0x500           // Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices()
 #include <windows.h>
 
 #include "SDL_win32events.h"
 #include "SDL_win32keyboard.h"
+#include "SDL_win32modes.h"
 #include "SDL_win32mouse.h"
 #include "SDL_win32window.h"
 
--- a/test/testsprite2.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/test/testsprite2.c	Fri Jul 07 08:05:39 2006 +0000
@@ -122,6 +122,8 @@
 main(int argc, char *argv[])
 {
     int window_w, window_h;
+    Uint32 window_flags = SDL_WINDOW_SHOWN;
+    SDL_DisplayMode *mode, fullscreen_mode;
     int i, done;
     SDL_Event event;
     Uint32 then, now, frames;
@@ -137,13 +139,16 @@
     window_w = WINDOW_W;
     window_h = WINDOW_H;
     while (argc > 1) {
-        --argc;
         if (strcmp(argv[argc - 1], "-width") == 0) {
             window_w = atoi(argv[argc]);
             --argc;
         } else if (strcmp(argv[argc - 1], "-height") == 0) {
             window_h = atoi(argv[argc]);
             --argc;
+        } else if (strcmp(argv[argc - 1], "-fullscreen") == 0) {
+            num_windows = 1;
+            window_flags |= SDL_WINDOW_FULLSCREEN;
+            --argc;
         } else if (isdigit(argv[argc][0])) {
             num_sprites = atoi(argv[argc]);
         } else {
@@ -153,8 +158,16 @@
         }
     }
 
-    /* Set the desktop mode, we don't care what it is */
-    if (SDL_SetDisplayMode(NULL) < 0) {
+    if (window_flags & SDL_WINDOW_FULLSCREEN) {
+        SDL_zero(fullscreen_mode);
+        fullscreen_mode.w = window_w;
+        fullscreen_mode.h = window_h;
+        mode = &fullscreen_mode;
+    } else {
+        /* Set the desktop mode, we don't care what it is */
+        mode = NULL;
+    }
+    if (SDL_SetDisplayMode(mode) < 0) {
         fprintf(stderr, "Couldn't set display mode: %s\n", SDL_GetError());
         quit(2);
     }
@@ -173,7 +186,7 @@
         windows[i] =
             SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED,
                              SDL_WINDOWPOS_UNDEFINED, window_w, window_h,
-                             SDL_WINDOW_SHOWN);
+                             window_flags);
         if (!windows[i]) {
             fprintf(stderr, "Couldn't create window: %s\n", SDL_GetError());
             quit(2);
--- a/test/testvidinfo.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/test/testvidinfo.c	Fri Jul 07 08:05:39 2006 +0000
@@ -417,7 +417,7 @@
 main(int argc, char *argv[])
 {
     const SDL_VideoInfo *info;
-    int i, n;
+    int i, d, n;
     const char *driver;
     const SDL_DisplayMode *mode;
     int bpp;
@@ -448,39 +448,46 @@
         printf("Video driver: %s\n", driver);
     }
     printf("Number of displays: %d\n", SDL_GetNumVideoDisplays());
-    mode = SDL_GetDesktopDisplayMode();
-    SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask,
-                               &Amask);
-    printf("Current display: %dx%d@%dHz, %d bits-per-pixel\n", mode->w,
-           mode->h, mode->refresh_rate, bpp);
-    if (Rmask || Gmask || Bmask) {
-        printf("	Red Mask = 0x%.8x\n", Rmask);
-        printf("	Green Mask = 0x%.8x\n", Gmask);
-        printf("	Blue Mask = 0x%.8x\n", Bmask);
-        if (Amask)
-            printf("	Alpha Mask = 0x%.8x\n", Amask);
-    }
-    /* Print available fullscreen video modes */
-    nmodes = SDL_GetNumDisplayModes();
-    if (nmodes == 0) {
-        printf("No available fullscreen video modes\n");
-    } else {
-        printf("Fullscreen video modes:\n");
-        for (i = 0; i < nmodes; ++i) {
-            mode = SDL_GetDisplayMode(i);
-            SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
-                                       &Gmask, &Bmask, &Amask);
-            printf("Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i,
-                   mode->w, mode->h, mode->refresh_rate, bpp);
-            if (Rmask || Gmask || Bmask) {
-                printf("	Red Mask = 0x%.8x\n", Rmask);
-                printf("	Green Mask = 0x%.8x\n", Gmask);
-                printf("	Blue Mask = 0x%.8x\n", Bmask);
-                if (Amask)
-                    printf("	Alpha Mask = 0x%.8x\n", Amask);
+    for (d = 0; d < SDL_GetNumVideoDisplays(); ++d) {
+        printf("Display %d:\n", d);
+        SDL_SelectVideoDisplay(d);
+
+        mode = SDL_GetDesktopDisplayMode();
+        SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask, &Gmask, &Bmask,
+                                   &Amask);
+        printf("  Current mode: %dx%d@%dHz, %d bits-per-pixel\n", mode->w,
+               mode->h, mode->refresh_rate, bpp);
+        if (Rmask || Gmask || Bmask) {
+            printf("      Red Mask = 0x%.8x\n", Rmask);
+            printf("      Green Mask = 0x%.8x\n", Gmask);
+            printf("      Blue Mask = 0x%.8x\n", Bmask);
+            if (Amask)
+                printf("      Alpha Mask = 0x%.8x\n", Amask);
+        }
+
+        /* Print available fullscreen video modes */
+        nmodes = SDL_GetNumDisplayModes();
+        if (nmodes == 0) {
+            printf("No available fullscreen video modes\n");
+        } else {
+            printf("  Fullscreen video modes:\n");
+            for (i = 0; i < nmodes; ++i) {
+                mode = SDL_GetDisplayMode(i);
+                SDL_PixelFormatEnumToMasks(mode->format, &bpp, &Rmask,
+                                           &Gmask, &Bmask, &Amask);
+                printf("    Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", i,
+                       mode->w, mode->h, mode->refresh_rate, bpp);
+                if (Rmask || Gmask || Bmask) {
+                    printf("        Red Mask = 0x%.8x\n", Rmask);
+                    printf("        Green Mask = 0x%.8x\n", Gmask);
+                    printf("        Blue Mask = 0x%.8x\n", Bmask);
+                    if (Amask)
+                        printf("        Alpha Mask = 0x%.8x\n", Amask);
+                }
             }
         }
     }
+
     info = SDL_GetVideoInfo();
     if (info->wm_available) {
         printf("A window manager is available\n");
--- a/test/testwm2.c	Thu Jul 06 07:17:11 2006 +0000
+++ b/test/testwm2.c	Fri Jul 07 08:05:39 2006 +0000
@@ -37,7 +37,6 @@
     window_w = WINDOW_W;
     window_h = WINDOW_H;
     while (argc > 1) {
-        --argc;
         if (strcmp(argv[argc - 1], "-width") == 0) {
             window_w = atoi(argv[argc]);
             --argc;