annotate src/video/win32/SDL_win32modes.c @ 1725:98a3207ddde8 SDL-1.3

Implemented Win32 video mode support
author Sam Lantinga <slouken@libsdl.org>
date Fri, 07 Jul 2006 08:05:39 +0000
parents
children 0b1070f2f94d
rev   line source
1725
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_win32video.h"
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 typedef struct
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 TCHAR DeviceName[32];
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 DEVMODE DeviceMode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 } SDL_DisplayModeData;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 /* FIXME: Each call to EnumDisplaySettings() takes about 6 ms on my laptop.
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 With 500 or so modes, this takes almost 3 seconds to run!
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 */
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 static SDL_bool
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 SDL_DisplayModeData *data;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 DEVMODE devmode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 HDC hdc;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 devmode.dmSize = sizeof(devmode);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 devmode.dmDriverExtra = 0;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 if (!EnumDisplaySettings(deviceName, index, &devmode)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 return SDL_FALSE;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 if (!data) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 return SDL_FALSE;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 SDL_memcpy(data->DeviceName, deviceName, sizeof(data->DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 data->DeviceMode = devmode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 data->DeviceMode.dmFields =
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 DM_DISPLAYFLAGS);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 /* Fill in the mode information */
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 mode->format = SDL_PixelFormat_Unknown;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 mode->w = devmode.dmPelsWidth;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 mode->h = devmode.dmPelsHeight;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 mode->refresh_rate = devmode.dmDisplayFrequency;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 mode->driverdata = data;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 hdc = CreateDC(deviceName, NULL, NULL, &devmode);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 if (hdc) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 LPBITMAPINFO bmi;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 HBITMAP hbm;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 SDL_zero(bmi_data);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 bmi = (LPBITMAPINFO) bmi_data;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 hbm = CreateCompatibleBitmap(hdc, 1, 1);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 DeleteObject(hbm);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 DeleteDC(hdc);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 switch (*(Uint32 *) bmi->bmiColors) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 case 0x00FF0000:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 mode->format = SDL_PixelFormat_RGB888;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 case 0x000000FF:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 mode->format = SDL_PixelFormat_BGR888;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 case 0xF800:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 mode->format = SDL_PixelFormat_RGB565;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 case 0x7C00:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 mode->format = SDL_PixelFormat_RGB555;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 } else if (bmi->bmiHeader.biBitCount == 8) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 mode->format = SDL_PixelFormat_Index8;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 } else {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 switch (devmode.dmBitsPerPel) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 case 32:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 mode->format = SDL_PixelFormat_RGB888;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 case 24:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 mode->format = SDL_PixelFormat_RGB24;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 case 16:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 mode->format = SDL_PixelFormat_RGB565;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 case 15:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 mode->format = SDL_PixelFormat_RGB555;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 case 8:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 mode->format = SDL_PixelFormat_Index8;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 return SDL_TRUE;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 void
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 WIN_InitModes(_THIS)
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 DWORD i, j, k;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 DISPLAY_DEVICE device;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 device.cb = sizeof(device);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 for (i = 0;; ++i) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 TCHAR DeviceName[32];
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 if (!EnumDisplayDevices(NULL, i, &device, 0)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 continue;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 #ifdef DEBUG_MODES
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 #endif
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 for (j = 0;; ++j) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 int index;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 SDL_VideoDisplay display;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 SDL_DisplayMode mode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 continue;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 #ifdef DEBUG_MODES
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 printf("Monitor: %s\n", WIN_StringToUTF8(device.DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 #endif
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 if (!WIN_GetDisplayMode(DeviceName, ENUM_CURRENT_SETTINGS, &mode)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 SDL_zero(display);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 display.desktop_mode = mode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 display.current_mode = mode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 index = SDL_AddVideoDisplay(&display);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 for (k = 0;; ++k) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 if (!WIN_GetDisplayMode(DeviceName, k, &mode)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 if (!SDL_AddDisplayMode(index, &mode)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 SDL_free(mode.driverdata);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 int
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 LONG status;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 status =
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 ChangeDisplaySettingsEx(data->DeviceName, &data->DeviceMode, NULL,
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 CDS_FULLSCREEN, NULL);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 if (status == DISP_CHANGE_SUCCESSFUL) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 return 0;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 } else {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 const char *reason = "Unknown reason";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 switch (status) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 case DISP_CHANGE_BADFLAGS:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 reason = "DISP_CHANGE_BADFLAGS";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 case DISP_CHANGE_BADMODE:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 reason = "DISP_CHANGE_BADMODE";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 case DISP_CHANGE_BADPARAM:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 reason = "DISP_CHANGE_BADPARAM";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 case DISP_CHANGE_FAILED:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 reason = "DISP_CHANGE_FAILED";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 return -1;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 void
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 WIN_QuitModes(_THIS)
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 /* vi: set ts=4 sw=4 expandtab: */