zenilib: zenilib/jni/external/sdl/src/video/windows/SDL_windowsmodes.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_windowsmodes.c
Go to the documentation of this file.
1 /*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22
23 #if SDL_VIDEO_DRIVER_WINDOWS
24
25 #include "SDL_windowsvideo.h"
26
27 /* Windows CE compatibility */
28 #ifndef CDS_FULLSCREEN
29 #define CDS_FULLSCREEN 0
30 #endif
31
32 static SDL_bool
33 WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
34 {
35 SDL_DisplayModeData *data;
36 DEVMODE devmode;
37 HDC hdc;
38
39 devmode.dmSize = sizeof(devmode);
40 devmode.dmDriverExtra = 0;
41 if (!EnumDisplaySettings(deviceName, index, &devmode)) {
42 return SDL_FALSE;
43 }
44
45 data = (SDL_DisplayModeData *) SDL_malloc(sizeof(*data));
46 if (!data) {
47 return SDL_FALSE;
48 }
49 data->DeviceMode = devmode;
50 data->DeviceMode.dmFields =
51 (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY |
52 DM_DISPLAYFLAGS);
53
54 /* Fill in the mode information */
55 mode->format = SDL_PIXELFORMAT_UNKNOWN;
56 mode->w = devmode.dmPelsWidth;
57 mode->h = devmode.dmPelsHeight;
58 mode->refresh_rate = devmode.dmDisplayFrequency;
59 mode->driverdata = data;
60
61 if (index == ENUM_CURRENT_SETTINGS
62 && (hdc = CreateDC(deviceName, NULL, NULL, NULL)) != NULL) {
63 char bmi_data[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)];
64 LPBITMAPINFO bmi;
65 HBITMAP hbm;
66
67 SDL_zero(bmi_data);
68 bmi = (LPBITMAPINFO) bmi_data;
69 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
70
71 hbm = CreateCompatibleBitmap(hdc, 1, 1);
72 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
73 GetDIBits(hdc, hbm, 0, 1, NULL, bmi, DIB_RGB_COLORS);
74 DeleteObject(hbm);
75 DeleteDC(hdc);
76 if (bmi->bmiHeader.biCompression == BI_BITFIELDS) {
77 switch (*(Uint32 *) bmi->bmiColors) {
78 case 0x00FF0000:
79 mode->format = SDL_PIXELFORMAT_RGB888;
80 break;
81 case 0x000000FF:
82 mode->format = SDL_PIXELFORMAT_BGR888;
83 break;
84 case 0xF800:
85 mode->format = SDL_PIXELFORMAT_RGB565;
86 break;
87 case 0x7C00:
88 mode->format = SDL_PIXELFORMAT_RGB555;
89 break;
90 }
91 } else if (bmi->bmiHeader.biBitCount == 8) {
92 mode->format = SDL_PIXELFORMAT_INDEX8;
93 } else if (bmi->bmiHeader.biBitCount == 4) {
94 mode->format = SDL_PIXELFORMAT_INDEX4LSB;
95 }
96 } else {
97 /* FIXME: Can we tell what this will be? */
98 if ((devmode.dmFields & DM_BITSPERPEL) == DM_BITSPERPEL) {
99 switch (devmode.dmBitsPerPel) {
100 case 32:
101 mode->format = SDL_PIXELFORMAT_RGB888;
102 break;
103 case 24:
104 mode->format = SDL_PIXELFORMAT_RGB24;
105 break;
106 case 16:
107 mode->format = SDL_PIXELFORMAT_RGB565;
108 break;
109 case 15:
110 mode->format = SDL_PIXELFORMAT_RGB555;
111 break;
112 case 8:
113 mode->format = SDL_PIXELFORMAT_INDEX8;
114 break;
115 case 4:
116 mode->format = SDL_PIXELFORMAT_INDEX4LSB;
117 break;
118 }
119 }
120 }
121 return SDL_TRUE;
122 }
123
124 static SDL_bool
125 WIN_AddDisplay(LPTSTR DeviceName)
126 {
127 SDL_VideoDisplay display;
128 SDL_DisplayData *displaydata;
129 SDL_DisplayMode mode;
130 DISPLAY_DEVICE device;
131
132 #ifdef DEBUG_MODES
133 printf("Display: %s\n", WIN_StringToUTF8(DeviceName));
134 #endif
135 if (!WIN_GetDisplayMode(DeviceName, ENUM_CURRENT_SETTINGS, &mode)) {
136 return SDL_FALSE;
137 }
138
139 displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
140 if (!displaydata) {
141 return SDL_FALSE;
142 }
143 SDL_memcpy(displaydata->DeviceName, DeviceName,
144 sizeof(displaydata->DeviceName));
145
146 SDL_zero(display);
147 device.cb = sizeof(device);
148 if (EnumDisplayDevices(DeviceName, 0, &device, 0)) {
149 display.name = WIN_StringToUTF8(device.DeviceString);
150 }
151 display.desktop_mode = mode;
152 display.current_mode = mode;
153 display.driverdata = displaydata;
154 SDL_AddVideoDisplay(&display);
155 SDL_free(display.name);
156 return SDL_TRUE;
157 }
158
159 int
160 WIN_InitModes(_THIS)
161 {
162 int pass;
163 DWORD i, j, count;
164 DISPLAY_DEVICE device;
165
166 device.cb = sizeof(device);
167
168 /* Get the primary display in the first pass */
169 for (pass = 0; pass < 2; ++pass) {
170 for (i = 0; ; ++i) {
171 TCHAR DeviceName[32];
172
173 if (!EnumDisplayDevices(NULL, i, &device, 0)) {
174 break;
175 }
176 if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
177 continue;
178 }
179 if (pass == 0) {
180 if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
181 continue;
182 }
183 } else {
184 if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
185 continue;
186 }
187 }
188 SDL_memcpy(DeviceName, device.DeviceName, sizeof(DeviceName));
189 #ifdef DEBUG_MODES
190 printf("Device: %s\n", WIN_StringToUTF8(DeviceName));
191 #endif
192 count = 0;
193 for (j = 0; ; ++j) {
194 if (!EnumDisplayDevices(DeviceName, j, &device, 0)) {
195 break;
196 }
197 if (!(device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP)) {
198 continue;
199 }
200 if (pass == 0) {
201 if (!(device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)) {
202 continue;
203 }
204 } else {
205 if (device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) {
206 continue;
207 }
208 }
209 count += WIN_AddDisplay(device.DeviceName);
210 }
211 if (count == 0) {
212 WIN_AddDisplay(DeviceName);
213 }
214 }
215 }
216 if (_this->num_displays == 0) {
217 return SDL_SetError("No displays available");
218 }
219 return 0;
220 }
221
222 int
223 WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay * display, SDL_Rect * rect)
224 {
225 SDL_DisplayModeData *data = (SDL_DisplayModeData *) display->current_mode.driverdata;
226
227 rect->x = (int)data->DeviceMode.dmPosition.x;
228 rect->y = (int)data->DeviceMode.dmPosition.y;
229 rect->w = data->DeviceMode.dmPelsWidth;
230 rect->h = data->DeviceMode.dmPelsHeight;
231
232 return 0;
233 }
234
235 void
236 WIN_GetDisplayModes(_THIS, SDL_VideoDisplay * display)
237 {
238 SDL_DisplayData *data = (SDL_DisplayData *) display->driverdata;
239 DWORD i;
240 SDL_DisplayMode mode;
241
242 for (i = 0;; ++i) {
243 if (!WIN_GetDisplayMode(data->DeviceName, i, &mode)) {
244 break;
245 }
246 if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
247 /* We don't support palettized modes now */
248 SDL_free(mode.driverdata);
249 continue;
250 }
251 if (mode.format != SDL_PIXELFORMAT_UNKNOWN) {
252 if (!SDL_AddDisplayMode(display, &mode)) {
253 SDL_free(mode.driverdata);
254 }
255 }
256 else {
257 SDL_free(mode.driverdata);
258 }
259 }
260 }
261
262 int
263 WIN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
264 {
265 SDL_DisplayData *displaydata = (SDL_DisplayData *) display->driverdata;
266 SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
267 LONG status;
268
269 status =
270 ChangeDisplaySettingsEx(displaydata->DeviceName, &data->DeviceMode,
271 NULL, CDS_FULLSCREEN, NULL);
272 if (status != DISP_CHANGE_SUCCESSFUL) {
273 const char *reason = "Unknown reason";
274 switch (status) {
275 case DISP_CHANGE_BADFLAGS:
276 reason = "DISP_CHANGE_BADFLAGS";
277 break;
278 case DISP_CHANGE_BADMODE:
279 reason = "DISP_CHANGE_BADMODE";
280 break;
281 case DISP_CHANGE_BADPARAM:
282 reason = "DISP_CHANGE_BADPARAM";
283 break;
284 case DISP_CHANGE_FAILED:
285 reason = "DISP_CHANGE_FAILED";
286 break;
287 }
288 return SDL_SetError("ChangeDisplaySettingsEx() failed: %s", reason);
289 }
290 EnumDisplaySettings(displaydata->DeviceName, ENUM_CURRENT_SETTINGS, &data->DeviceMode);
291 return 0;
292 }
293
294 void
295 WIN_QuitModes(_THIS)
296 {
297 /* All fullscreen windows should have restored modes by now */
298 }
299
300 #endif /* SDL_VIDEO_DRIVER_WINDOWS */
301
302 /* vi: set ts=4 sw=4 expandtab: */
SDL_PIXELFORMAT_INDEX8
Definition: SDL_pixels.h:162
WIN_QuitModes
void WIN_QuitModes(_THIS)
NULL
#define NULL
Definition: ftobjs.h:61
SDL_DisplayMode::w
int w
Definition: SDL_video.h:56
SDL_DisplayModeData::DeviceMode
DEVMODE DeviceMode
Definition: SDL_windowsmodes.h:33
SDL_ISPIXELFORMAT_INDEXED
#define SDL_ISPIXELFORMAT_INDEXED(format)
Definition: SDL_pixels.h:129
SDL_PIXELFORMAT_RGB24
Definition: SDL_pixels.h:206
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:116
SDL_PIXELFORMAT_RGB565
Definition: SDL_pixels.h:200
SDL_VideoDisplay::name
char * name
Definition: SDL_sysvideo.h:115
SDL_TRUE
Definition: SDL_stdinc.h:119
SDL_free
DECLSPEC void SDLCALL SDL_free(void *mem)
SDL_DisplayMode
The structure that defines a display mode.
Definition: SDL_video.h:53
j
int32_t j
Definition: e_log.c:102
SDL_PIXELFORMAT_UNKNOWN
Definition: SDL_pixels.h:149
SDL_DisplayMode::refresh_rate
int refresh_rate
Definition: SDL_video.h:58
display
char * display
Definition: visualinfo.c:85
SDL_FALSE
Definition: SDL_stdinc.h:118
WIN_InitModes
int WIN_InitModes(_THIS)
SDL_config.h
SDL_AddVideoDisplay
int SDL_AddVideoDisplay(const SDL_VideoDisplay *display)
Definition: SDL_video.c:568
SDL_DisplayData
Definition: SDL_cocoamodes.h:26
HDC
typedef HDC(WINAPI *PFNWGLGETCURRENTREADDCARBPROC)(VOID)
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:92
Uint32
uint32_t Uint32
An unsigned 32-bit integer type.
Definition: SDL_stdinc.h:145
WIN_GetDisplayModes
void WIN_GetDisplayModes(_THIS, SDL_VideoDisplay *display)
SDL_DisplayModeData
Definition: SDL_cocoamodes.h:31
SDL_DisplayData::DeviceName
TCHAR DeviceName[32]
Definition: SDL_windowsmodes.h:28
WIN_GetDisplayBounds
int WIN_GetDisplayBounds(_THIS, SDL_VideoDisplay *display, SDL_Rect *rect)
int
int
Definition: SDL_systhread.c:37
for
for(;;)
Definition: glslang_tab.cpp:4773
data
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
SDL_DisplayMode::driverdata
void * driverdata
Definition: SDL_video.h:59
count
GLint GLsizei count
Definition: gl2ext.h:1011
SDL_PIXELFORMAT_INDEX4LSB
Definition: SDL_pixels.h:156
SDL_VideoDevice::num_displays
int num_displays
Definition: SDL_sysvideo.h:264
WIN_SetDisplayMode
int WIN_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode)
SDL_VideoDisplay::current_mode
SDL_DisplayMode current_mode
Definition: SDL_sysvideo.h:120
WIN_StringToUTF8
#define WIN_StringToUTF8(S)
Definition: SDL_windows.h:41
SDL_SetError
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
SDL_malloc
DECLSPEC void *SDLCALL SDL_malloc(size_t size)
index
GLuint index
Definition: glew.h:1800
SDL_DisplayMode::h
int h
Definition: SDL_video.h:57
SDL_Rect::x
int x
Definition: SDL_rect.h:65
SDL_Rect::w
int w
Definition: SDL_rect.h:66
BI_BITFIELDS
#define BI_BITFIELDS
Definition: SDL_bmp.c:46
SDL_VideoDisplay
Definition: SDL_sysvideo.h:113
SDL_VideoDisplay::desktop_mode
SDL_DisplayMode desktop_mode
Definition: SDL_sysvideo.h:119
SDL_memcpy
DECLSPEC void *SDLCALL SDL_memcpy(void *dst, const void *src, size_t len)
Definition: SDL_string.c:293
SDL_Rect::h
int h
Definition: SDL_rect.h:66
SDL_PIXELFORMAT_RGB555
Definition: SDL_pixels.h:170
DWORD
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
SDL_AddDisplayMode
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:666
SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:212
SDL_PIXELFORMAT_BGR888
Definition: SDL_pixels.h:218
SDL_zero
#define SDL_zero(x)
Definition: SDL_stdinc.h:254
SDL_DisplayMode::format
Uint32 format
Definition: SDL_video.h:55
i
int i
Definition: pngrutil.c:1377
SDL_windowsvideo.h
SDL_Rect::y
int y
Definition: SDL_rect.h:65
mode
GLenum mode
Definition: glew.h:2394
SDL_Rect
A rectangle, with the origin at the upper left.
Definition: SDL_rect.h:63
SDL_VideoDisplay::driverdata
void * driverdata
Definition: SDL_sysvideo.h:126