annotate src/video/win32/SDL_win32modes.c @ 1735:8dd28c4ef746 SDL-1.3

SDL_Rect now uses int for position and size. Added a few more rectangle functions. Added a dirty rectangle list implementation.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 07:34:50 +0000
parents 0b1070f2f94d
children
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 /* 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
28 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
29 */
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 static SDL_bool
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 SDL_DisplayModeData *data;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 DEVMODE devmode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 HDC hdc;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 devmode.dmSize = sizeof(devmode);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 devmode.dmDriverExtra = 0;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 if (!EnumDisplaySettings(deviceName, index, &devmode)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 return SDL_FALSE;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 }
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 data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 if (!data) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 return SDL_FALSE;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 SDL_memcpy(data->DeviceName, deviceName, sizeof(data->DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 data->DeviceMode = devmode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 data->DeviceMode.dmFields =
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 DM_DISPLAYFLAGS);
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 /* Fill in the mode information */
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 mode->format = SDL_PixelFormat_Unknown;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 mode->w = devmode.dmPelsWidth;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 mode->h = devmode.dmPelsHeight;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 mode->refresh_rate = devmode.dmDisplayFrequency;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 mode->driverdata = data;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 hdc = CreateDC(deviceName, NULL, NULL, &devmode);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 if (hdc) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 LPBITMAPINFO bmi;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 HBITMAP hbm;
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 SDL_zero(bmi_data);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 bmi = (LPBITMAPINFO) bmi_data;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 hbm = CreateCompatibleBitmap(hdc, 1, 1);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 DeleteObject(hbm);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 DeleteDC(hdc);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 switch (*(Uint32 *) bmi->bmiColors) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 case 0x00FF0000:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 mode->format = SDL_PixelFormat_RGB888;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 case 0x000000FF:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 mode->format = SDL_PixelFormat_BGR888;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 case 0xF800:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 mode->format = SDL_PixelFormat_RGB565;
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 0x7C00:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 mode->format = SDL_PixelFormat_RGB555;
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 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 } else if (bmi->bmiHeader.biBitCount == 8) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 mode->format = SDL_PixelFormat_Index8;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 } else {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 switch (devmode.dmBitsPerPel) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 case 32:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 mode->format = SDL_PixelFormat_RGB888;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 case 24:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 mode->format = SDL_PixelFormat_RGB24;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 case 16:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 mode->format = SDL_PixelFormat_RGB565;
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 15:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 mode->format = SDL_PixelFormat_RGB555;
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 8:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 mode->format = SDL_PixelFormat_Index8;
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 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 return SDL_TRUE;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 void
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 WIN_InitModes(_THIS)
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 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
1733
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
120 DWORD i, j;
1725
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 DISPLAY_DEVICE device;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 device.cb = sizeof(device);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 for (i = 0;; ++i) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 TCHAR DeviceName[32];
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 if (!EnumDisplayDevices(NULL, i, &device, 0)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 continue;
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 SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 #ifdef DEBUG_MODES
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 #endif
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 for (j = 0;; ++j) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 SDL_VideoDisplay display;
1733
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
139 SDL_DisplayData *displaydata;
1725
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 SDL_DisplayMode mode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 continue;
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 #ifdef DEBUG_MODES
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 printf("Monitor: %s\n", WIN_StringToUTF8(device.DeviceName));
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 #endif
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 if (!WIN_GetDisplayMode(DeviceName, ENUM_CURRENT_SETTINGS, &mode)) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
1733
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
154
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
155 displaydata =
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
156 (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
157 if (!displaydata) {
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
158 continue;
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
159 }
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
160 SDL_memcpy(displaydata->DeviceName, DeviceName,
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
161 sizeof(DeviceName));
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
162
1725
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 SDL_zero(display);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 display.desktop_mode = mode;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 display.current_mode = mode;
1733
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
166 display.driverdata = displaydata;
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
167 SDL_AddVideoDisplay(&display);
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
168 }
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
169 }
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
170 }
1725
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171
1733
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
172 void
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
173 WIN_GetDisplayModes(_THIS)
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
174 {
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
175 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
176 DWORD i;
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
177 SDL_DisplayMode mode;
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
178
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
179 for (i = 0;; ++i) {
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
180 if (!WIN_GetDisplayMode(data->DeviceName, i, &mode)) {
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
181 break;
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
182 }
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
183 if (!SDL_AddDisplayMode(_this->current_display, &mode)) {
0b1070f2f94d Implemented gamma correction on Windows.
Sam Lantinga <slouken@libsdl.org>
parents: 1725
diff changeset
184 SDL_free(mode.driverdata);
1725
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 int
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 LONG status;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 status =
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 ChangeDisplaySettingsEx(data->DeviceName, &data->DeviceMode, NULL,
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 CDS_FULLSCREEN, NULL);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 if (status == DISP_CHANGE_SUCCESSFUL) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 return 0;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 } else {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 const char *reason = "Unknown reason";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 switch (status) {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 case DISP_CHANGE_BADFLAGS:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 reason = "DISP_CHANGE_BADFLAGS";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 case DISP_CHANGE_BADMODE:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 reason = "DISP_CHANGE_BADMODE";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 case DISP_CHANGE_BADPARAM:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 reason = "DISP_CHANGE_BADPARAM";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 case DISP_CHANGE_FAILED:
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 reason = "DISP_CHANGE_FAILED";
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 break;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 return -1;
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 void
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 WIN_QuitModes(_THIS)
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 {
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 }
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226
98a3207ddde8 Implemented Win32 video mode support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 /* vi: set ts=4 sw=4 expandtab: */