comparison src/video/windib/SDL_dibvideo.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 339d733e3699
children
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
41 #include "../wincommon/SDL_wingl_c.h" 41 #include "../wincommon/SDL_wingl_c.h"
42 42
43 #ifdef _WIN32_WCE 43 #ifdef _WIN32_WCE
44 #define NO_GETDIBITS 44 #define NO_GETDIBITS
45 #define NO_GAMMA_SUPPORT 45 #define NO_GAMMA_SUPPORT
46 #if _WIN32_WCE < 420 46 #if _WIN32_WCE < 420
47 #define NO_CHANGEDISPLAYSETTINGS 47 #define NO_CHANGEDISPLAYSETTINGS
48 #else 48 #else
49 #define ChangeDisplaySettings(lpDevMode, dwFlags) ChangeDisplaySettingsEx(NULL, (lpDevMode), 0, (dwFlags), 0) 49 #define ChangeDisplaySettings(lpDevMode, dwFlags) ChangeDisplaySettingsEx(NULL, (lpDevMode), 0, (dwFlags), 0)
50 #endif 50 #endif
51 #endif 51 #endif
52 #ifndef WS_MAXIMIZE 52 #ifndef WS_MAXIMIZE
53 #define WS_MAXIMIZE 0 53 #define WS_MAXIMIZE 0
54 #endif 54 #endif
55 #ifndef WS_THICKFRAME 55 #ifndef WS_THICKFRAME
66 // defined and used in SDL_sysevents.c 66 // defined and used in SDL_sysevents.c
67 extern HINSTANCE aygshell; 67 extern HINSTANCE aygshell;
68 #endif 68 #endif
69 69
70 /* Initialization/Query functions */ 70 /* Initialization/Query functions */
71 static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat); 71 static int DIB_VideoInit(_THIS, SDL_PixelFormat * vformat);
72 static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 72 static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat * format,
73 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 73 Uint32 flags);
74 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface * current, int width,
75 int height, int bpp, Uint32 flags);
74 static int DIB_SetColors(_THIS, int firstcolor, int ncolors, 76 static int DIB_SetColors(_THIS, int firstcolor, int ncolors,
75 SDL_Color *colors); 77 SDL_Color * colors);
76 static void DIB_CheckGamma(_THIS); 78 static void DIB_CheckGamma(_THIS);
77 void DIB_SwapGamma(_THIS); 79 void DIB_SwapGamma(_THIS);
78 void DIB_QuitGamma(_THIS); 80 void DIB_QuitGamma(_THIS);
79 int DIB_SetGammaRamp(_THIS, Uint16 *ramp); 81 int DIB_SetGammaRamp(_THIS, Uint16 * ramp);
80 int DIB_GetGammaRamp(_THIS, Uint16 *ramp); 82 int DIB_GetGammaRamp(_THIS, Uint16 * ramp);
81 static void DIB_VideoQuit(_THIS); 83 static void DIB_VideoQuit(_THIS);
82 84
83 /* Hardware surface functions */ 85 /* Hardware surface functions */
84 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface); 86 static int DIB_AllocHWSurface(_THIS, SDL_Surface * surface);
85 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface); 87 static int DIB_LockHWSurface(_THIS, SDL_Surface * surface);
86 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface); 88 static void DIB_UnlockHWSurface(_THIS, SDL_Surface * surface);
87 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface); 89 static void DIB_FreeHWSurface(_THIS, SDL_Surface * surface);
88 90
89 /* Windows message handling functions */ 91 /* Windows message handling functions */
90 static void DIB_RealizePalette(_THIS); 92 static void DIB_RealizePalette(_THIS);
91 static void DIB_PaletteChanged(_THIS, HWND window); 93 static void DIB_PaletteChanged(_THIS, HWND window);
92 static void DIB_WinPAINT(_THIS, HDC hdc); 94 static void DIB_WinPAINT(_THIS, HDC hdc);
94 /* helper fn */ 96 /* helper fn */
95 static int DIB_SussScreenDepth(); 97 static int DIB_SussScreenDepth();
96 98
97 /* DIB driver bootstrap functions */ 99 /* DIB driver bootstrap functions */
98 100
99 static int DIB_Available(void) 101 static int
100 { 102 DIB_Available(void)
101 return(1); 103 {
102 } 104 return (1);
103 105 }
104 static void DIB_DeleteDevice(SDL_VideoDevice *device) 106
105 { 107 static void
106 if ( device ) { 108 DIB_DeleteDevice(SDL_VideoDevice * device)
107 if ( device->hidden ) { 109 {
108 SDL_free(device->hidden); 110 if (device) {
109 } 111 if (device->hidden) {
110 if ( device->gl_data ) { 112 SDL_free(device->hidden);
111 SDL_free(device->gl_data); 113 }
112 } 114 if (device->gl_data) {
113 SDL_free(device); 115 SDL_free(device->gl_data);
114 } 116 }
115 } 117 SDL_free(device);
116 118 }
117 static SDL_VideoDevice *DIB_CreateDevice(int devindex) 119 }
118 { 120
119 SDL_VideoDevice *device; 121 static SDL_VideoDevice *
120 122 DIB_CreateDevice(int devindex)
121 /* Initialize all variables that we clean on shutdown */ 123 {
122 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 124 SDL_VideoDevice *device;
123 if ( device ) { 125
124 SDL_memset(device, 0, (sizeof *device)); 126 /* Initialize all variables that we clean on shutdown */
125 device->hidden = (struct SDL_PrivateVideoData *) 127 device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
126 SDL_malloc((sizeof *device->hidden)); 128 if (device) {
127 device->gl_data = (struct SDL_PrivateGLData *) 129 SDL_memset(device, 0, (sizeof *device));
128 SDL_malloc((sizeof *device->gl_data)); 130 device->hidden = (struct SDL_PrivateVideoData *)
129 } 131 SDL_malloc((sizeof *device->hidden));
130 if ( (device == NULL) || (device->hidden == NULL) || 132 device->gl_data = (struct SDL_PrivateGLData *)
131 (device->gl_data == NULL) ) { 133 SDL_malloc((sizeof *device->gl_data));
132 SDL_OutOfMemory(); 134 }
133 DIB_DeleteDevice(device); 135 if ((device == NULL) || (device->hidden == NULL) ||
134 return(NULL); 136 (device->gl_data == NULL)) {
135 } 137 SDL_OutOfMemory();
136 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 138 DIB_DeleteDevice(device);
137 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data)); 139 return (NULL);
138 140 }
139 /* Set the function pointers */ 141 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
140 device->VideoInit = DIB_VideoInit; 142 SDL_memset(device->gl_data, 0, (sizeof *device->gl_data));
141 device->ListModes = DIB_ListModes; 143
142 device->SetVideoMode = DIB_SetVideoMode; 144 /* Set the function pointers */
143 device->UpdateMouse = WIN_UpdateMouse; 145 device->VideoInit = DIB_VideoInit;
144 device->SetColors = DIB_SetColors; 146 device->ListModes = DIB_ListModes;
145 device->UpdateRects = NULL; 147 device->SetVideoMode = DIB_SetVideoMode;
146 device->VideoQuit = DIB_VideoQuit; 148 device->UpdateMouse = WIN_UpdateMouse;
147 device->AllocHWSurface = DIB_AllocHWSurface; 149 device->SetColors = DIB_SetColors;
148 device->CheckHWBlit = NULL; 150 device->UpdateRects = NULL;
149 device->FillHWRect = NULL; 151 device->VideoQuit = DIB_VideoQuit;
150 device->SetHWColorKey = NULL; 152 device->AllocHWSurface = DIB_AllocHWSurface;
151 device->SetHWAlpha = NULL; 153 device->CheckHWBlit = NULL;
152 device->LockHWSurface = DIB_LockHWSurface; 154 device->FillHWRect = NULL;
153 device->UnlockHWSurface = DIB_UnlockHWSurface; 155 device->SetHWColorKey = NULL;
154 device->FlipHWSurface = NULL; 156 device->SetHWAlpha = NULL;
155 device->FreeHWSurface = DIB_FreeHWSurface; 157 device->LockHWSurface = DIB_LockHWSurface;
156 device->SetGammaRamp = DIB_SetGammaRamp; 158 device->UnlockHWSurface = DIB_UnlockHWSurface;
157 device->GetGammaRamp = DIB_GetGammaRamp; 159 device->FlipHWSurface = NULL;
160 device->FreeHWSurface = DIB_FreeHWSurface;
161 device->SetGammaRamp = DIB_SetGammaRamp;
162 device->GetGammaRamp = DIB_GetGammaRamp;
158 #if SDL_VIDEO_OPENGL 163 #if SDL_VIDEO_OPENGL
159 device->GL_LoadLibrary = WIN_GL_LoadLibrary; 164 device->GL_LoadLibrary = WIN_GL_LoadLibrary;
160 device->GL_GetProcAddress = WIN_GL_GetProcAddress; 165 device->GL_GetProcAddress = WIN_GL_GetProcAddress;
161 device->GL_GetAttribute = WIN_GL_GetAttribute; 166 device->GL_GetAttribute = WIN_GL_GetAttribute;
162 device->GL_MakeCurrent = WIN_GL_MakeCurrent; 167 device->GL_MakeCurrent = WIN_GL_MakeCurrent;
163 device->GL_SwapBuffers = WIN_GL_SwapBuffers; 168 device->GL_SwapBuffers = WIN_GL_SwapBuffers;
164 #endif 169 #endif
165 device->SetCaption = WIN_SetWMCaption; 170 device->SetCaption = WIN_SetWMCaption;
166 device->SetIcon = WIN_SetWMIcon; 171 device->SetIcon = WIN_SetWMIcon;
167 device->IconifyWindow = WIN_IconifyWindow; 172 device->IconifyWindow = WIN_IconifyWindow;
168 device->GrabInput = WIN_GrabInput; 173 device->GrabInput = WIN_GrabInput;
169 device->GetWMInfo = WIN_GetWMInfo; 174 device->GetWMInfo = WIN_GetWMInfo;
170 device->FreeWMCursor = WIN_FreeWMCursor; 175 device->FreeWMCursor = WIN_FreeWMCursor;
171 device->CreateWMCursor = WIN_CreateWMCursor; 176 device->CreateWMCursor = WIN_CreateWMCursor;
172 device->ShowWMCursor = WIN_ShowWMCursor; 177 device->ShowWMCursor = WIN_ShowWMCursor;
173 device->WarpWMCursor = WIN_WarpWMCursor; 178 device->WarpWMCursor = WIN_WarpWMCursor;
174 device->CheckMouseMode = WIN_CheckMouseMode; 179 device->CheckMouseMode = WIN_CheckMouseMode;
175 device->InitOSKeymap = DIB_InitOSKeymap; 180 device->InitOSKeymap = DIB_InitOSKeymap;
176 device->PumpEvents = DIB_PumpEvents; 181 device->PumpEvents = DIB_PumpEvents;
177 182
178 /* Set up the windows message handling functions */ 183 /* Set up the windows message handling functions */
179 WIN_RealizePalette = DIB_RealizePalette; 184 WIN_RealizePalette = DIB_RealizePalette;
180 WIN_PaletteChanged = DIB_PaletteChanged; 185 WIN_PaletteChanged = DIB_PaletteChanged;
181 WIN_WinPAINT = DIB_WinPAINT; 186 WIN_WinPAINT = DIB_WinPAINT;
182 HandleMessage = DIB_HandleMessage; 187 HandleMessage = DIB_HandleMessage;
183 188
184 device->free = DIB_DeleteDevice; 189 device->free = DIB_DeleteDevice;
185 190
186 /* We're finally ready */ 191 /* We're finally ready */
187 return device; 192 return device;
188 } 193 }
189 194
190 VideoBootStrap WINDIB_bootstrap = { 195 VideoBootStrap WINDIB_bootstrap = {
191 "windib", "Win95/98/NT/2000/CE GDI", 196 "windib", "Win95/98/NT/2000/CE GDI",
192 DIB_Available, DIB_CreateDevice 197 DIB_Available, DIB_CreateDevice
193 }; 198 };
194 199
195 static int cmpmodes(const void *va, const void *vb) 200 static int
196 { 201 cmpmodes(const void *va, const void *vb)
197 SDL_Rect *a = *(SDL_Rect **)va; 202 {
198 SDL_Rect *b = *(SDL_Rect **)vb; 203 SDL_Rect *a = *(SDL_Rect **) va;
199 if ( a->w == b->w ) 204 SDL_Rect *b = *(SDL_Rect **) vb;
205 if (a->w == b->w)
200 return b->h - a->h; 206 return b->h - a->h;
201 else 207 else
202 return b->w - a->w; 208 return b->w - a->w;
203 } 209 }
204 210
205 static int DIB_AddMode(_THIS, int bpp, int w, int h) 211 static int
206 { 212 DIB_AddMode(_THIS, int bpp, int w, int h)
207 SDL_Rect *mode; 213 {
208 int i, index; 214 SDL_Rect *mode;
209 int next_mode; 215 int i, index;
210 216 int next_mode;
211 /* Check to see if we already have this mode */ 217
212 if ( bpp < 8 ) { /* Not supported */ 218 /* Check to see if we already have this mode */
213 return(0); 219 if (bpp < 8) { /* Not supported */
214 } 220 return (0);
215 index = ((bpp+7)/8)-1; 221 }
216 for ( i=0; i<SDL_nummodes[index]; ++i ) { 222 index = ((bpp + 7) / 8) - 1;
217 mode = SDL_modelist[index][i]; 223 for (i = 0; i < SDL_nummodes[index]; ++i) {
218 if ( (mode->w == w) && (mode->h == h) ) { 224 mode = SDL_modelist[index][i];
219 return(0); 225 if ((mode->w == w) && (mode->h == h)) {
220 } 226 return (0);
221 } 227 }
222 228 }
223 /* Set up the new video mode rectangle */ 229
224 mode = (SDL_Rect *)SDL_malloc(sizeof *mode); 230 /* Set up the new video mode rectangle */
225 if ( mode == NULL ) { 231 mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
226 SDL_OutOfMemory(); 232 if (mode == NULL) {
227 return(-1); 233 SDL_OutOfMemory();
228 } 234 return (-1);
229 mode->x = 0; 235 }
230 mode->y = 0; 236 mode->x = 0;
231 mode->w = w; 237 mode->y = 0;
232 mode->h = h; 238 mode->w = w;
233 239 mode->h = h;
234 /* Allocate the new list of modes, and fill in the new mode */ 240
235 next_mode = SDL_nummodes[index]; 241 /* Allocate the new list of modes, and fill in the new mode */
236 SDL_modelist[index] = (SDL_Rect **) 242 next_mode = SDL_nummodes[index];
237 SDL_realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); 243 SDL_modelist[index] = (SDL_Rect **)
238 if ( SDL_modelist[index] == NULL ) { 244 SDL_realloc(SDL_modelist[index],
239 SDL_OutOfMemory(); 245 (1 + next_mode + 1) * sizeof(SDL_Rect *));
240 SDL_nummodes[index] = 0; 246 if (SDL_modelist[index] == NULL) {
241 SDL_free(mode); 247 SDL_OutOfMemory();
242 return(-1); 248 SDL_nummodes[index] = 0;
243 } 249 SDL_free(mode);
244 SDL_modelist[index][next_mode] = mode; 250 return (-1);
245 SDL_modelist[index][next_mode+1] = NULL; 251 }
246 SDL_nummodes[index]++; 252 SDL_modelist[index][next_mode] = mode;
247 253 SDL_modelist[index][next_mode + 1] = NULL;
248 return(0); 254 SDL_nummodes[index]++;
249 } 255
250 256 return (0);
251 static HPALETTE DIB_CreatePalette(int bpp) 257 }
258
259 static HPALETTE
260 DIB_CreatePalette(int bpp)
252 { 261 {
253 /* RJR: March 28, 2000 262 /* RJR: March 28, 2000
254 moved palette creation here from "DIB_VideoInit" */ 263 moved palette creation here from "DIB_VideoInit" */
255 264
256 HPALETTE handle = NULL; 265 HPALETTE handle = NULL;
257 266
258 if ( bpp <= 8 ) 267 if (bpp <= 8) {
259 { 268 LOGPALETTE *palette;
260 LOGPALETTE *palette; 269 HDC hdc;
261 HDC hdc; 270 int ncolors;
262 int ncolors; 271 int i;
263 int i; 272
264 273 ncolors = 1;
265 ncolors = 1; 274 for (i = 0; i < bpp; ++i) {
266 for ( i=0; i<bpp; ++i ) { 275 ncolors *= 2;
267 ncolors *= 2; 276 }
268 } 277 palette = (LOGPALETTE *) SDL_malloc(sizeof(*palette) +
269 palette = (LOGPALETTE *)SDL_malloc(sizeof(*palette)+ 278 ncolors * sizeof(PALETTEENTRY));
270 ncolors*sizeof(PALETTEENTRY)); 279 palette->palVersion = 0x300;
271 palette->palVersion = 0x300; 280 palette->palNumEntries = ncolors;
272 palette->palNumEntries = ncolors; 281 hdc = GetDC(SDL_Window);
273 hdc = GetDC(SDL_Window); 282 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry);
274 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry); 283 ReleaseDC(SDL_Window, hdc);
275 ReleaseDC(SDL_Window, hdc); 284 handle = CreatePalette(palette);
276 handle = CreatePalette(palette); 285 SDL_free(palette);
277 SDL_free(palette); 286 }
278 } 287
279 288 return handle;
280 return handle; 289 }
281 } 290
282 291 int
283 int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat) 292 DIB_VideoInit(_THIS, SDL_PixelFormat * vformat)
284 { 293 {
285 #ifndef NO_CHANGEDISPLAYSETTINGS 294 #ifndef NO_CHANGEDISPLAYSETTINGS
286 int i; 295 int i;
287 DEVMODE settings; 296 DEVMODE settings;
288 #endif 297 #endif
289 298
290 /* Create the window */ 299 /* Create the window */
291 if ( DIB_CreateWindow(this) < 0 ) { 300 if (DIB_CreateWindow(this) < 0) {
292 return(-1); 301 return (-1);
293 } 302 }
294
295 #if !SDL_AUDIO_DISABLED 303 #if !SDL_AUDIO_DISABLED
296 DX5_SoundFocus(SDL_Window); 304 DX5_SoundFocus(SDL_Window);
297 #endif 305 #endif
298 306
299 /* Determine the screen depth */ 307 /* Determine the screen depth */
300 vformat->BitsPerPixel = DIB_SussScreenDepth(); 308 vformat->BitsPerPixel = DIB_SussScreenDepth();
301 switch (vformat->BitsPerPixel) { 309 switch (vformat->BitsPerPixel) {
302 case 15: 310 case 15:
303 vformat->Rmask = 0x00007c00; 311 vformat->Rmask = 0x00007c00;
304 vformat->Gmask = 0x000003e0; 312 vformat->Gmask = 0x000003e0;
305 vformat->Bmask = 0x0000001f; 313 vformat->Bmask = 0x0000001f;
306 vformat->BitsPerPixel = 16; 314 vformat->BitsPerPixel = 16;
307 break; 315 break;
308 case 16: 316 case 16:
309 vformat->Rmask = 0x0000f800; 317 vformat->Rmask = 0x0000f800;
310 vformat->Gmask = 0x000007e0; 318 vformat->Gmask = 0x000007e0;
311 vformat->Bmask = 0x0000001f; 319 vformat->Bmask = 0x0000001f;
312 break; 320 break;
313 case 24: 321 case 24:
314 case 32: 322 case 32:
315 /* GDI defined as 8-8-8 */ 323 /* GDI defined as 8-8-8 */
316 vformat->Rmask = 0x00ff0000; 324 vformat->Rmask = 0x00ff0000;
317 vformat->Gmask = 0x0000ff00; 325 vformat->Gmask = 0x0000ff00;
318 vformat->Bmask = 0x000000ff; 326 vformat->Bmask = 0x000000ff;
319 break; 327 break;
320 default: 328 default:
321 break; 329 break;
322 } 330 }
323 331
324 /* See if gamma is supported on this screen */ 332 /* See if gamma is supported on this screen */
325 DIB_CheckGamma(this); 333 DIB_CheckGamma(this);
326 334
327 #ifndef NO_CHANGEDISPLAYSETTINGS 335 #ifndef NO_CHANGEDISPLAYSETTINGS
328 336
329 settings.dmSize = sizeof(DEVMODE); 337 settings.dmSize = sizeof(DEVMODE);
330 settings.dmDriverExtra = 0; 338 settings.dmDriverExtra = 0;
331 #ifdef _WIN32_WCE 339 #ifdef _WIN32_WCE
332 settings.dmFields = DM_DISPLAYQUERYORIENTATION; 340 settings.dmFields = DM_DISPLAYQUERYORIENTATION;
333 this->hidden->supportRotation = ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL; 341 this->hidden->supportRotation =
334 #endif 342 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST,
335 /* Query for the desktop resolution */ 343 NULL) == DISP_CHANGE_SUCCESSFUL;
336 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); 344 #endif
337 this->info.current_w = SDL_desktop_mode.dmPelsWidth; 345 /* Query for the desktop resolution */
338 this->info.current_h = SDL_desktop_mode.dmPelsHeight; 346 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode);
339 347 this->info.current_w = SDL_desktop_mode.dmPelsWidth;
340 /* Query for the list of available video modes */ 348 this->info.current_h = SDL_desktop_mode.dmPelsHeight;
341 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { 349
342 DIB_AddMode(this, settings.dmBitsPerPel, 350 /* Query for the list of available video modes */
343 settings.dmPelsWidth, settings.dmPelsHeight); 351 for (i = 0; EnumDisplaySettings(NULL, i, &settings); ++i) {
344 #ifdef _WIN32_WCE 352 DIB_AddMode(this, settings.dmBitsPerPel,
345 if( this->hidden->supportRotation ) 353 settings.dmPelsWidth, settings.dmPelsHeight);
346 DIB_AddMode(this, settings.dmBitsPerPel, 354 #ifdef _WIN32_WCE
347 settings.dmPelsHeight, settings.dmPelsWidth); 355 if (this->hidden->supportRotation)
348 #endif 356 DIB_AddMode(this, settings.dmBitsPerPel,
349 } 357 settings.dmPelsHeight, settings.dmPelsWidth);
350 /* Sort the mode lists */ 358 #endif
351 for ( i=0; i<NUM_MODELISTS; ++i ) { 359 }
352 if ( SDL_nummodes[i] > 0 ) { 360 /* Sort the mode lists */
353 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); 361 for (i = 0; i < NUM_MODELISTS; ++i) {
354 } 362 if (SDL_nummodes[i] > 0) {
355 } 363 SDL_qsort(SDL_modelist[i], SDL_nummodes[i],
364 sizeof *SDL_modelist[i], cmpmodes);
365 }
366 }
356 #else 367 #else
357 // WinCE and fullscreen mode: 368 // WinCE and fullscreen mode:
358 // We use only vformat->BitsPerPixel that allow SDL to 369 // We use only vformat->BitsPerPixel that allow SDL to
359 // emulate other bpp (8, 32) and use triple buffer, 370 // emulate other bpp (8, 32) and use triple buffer,
360 // because SDL surface conversion is much faster than the WinCE one. 371 // because SDL surface conversion is much faster than the WinCE one.
361 // Although it should be tested on devices with graphics accelerator. 372 // Although it should be tested on devices with graphics accelerator.
362 373
363 DIB_AddMode(this, vformat->BitsPerPixel, 374 DIB_AddMode(this, vformat->BitsPerPixel,
364 GetDeviceCaps(GetDC(NULL), HORZRES), 375 GetDeviceCaps(GetDC(NULL), HORZRES),
365 GetDeviceCaps(GetDC(NULL), VERTRES)); 376 GetDeviceCaps(GetDC(NULL), VERTRES));
366 377
367 #endif /* !NO_CHANGEDISPLAYSETTINGS */ 378 #endif /* !NO_CHANGEDISPLAYSETTINGS */
368 379
369 /* Grab an identity palette if we are in a palettized mode */ 380 /* Grab an identity palette if we are in a palettized mode */
370 if ( vformat->BitsPerPixel <= 8 ) { 381 if (vformat->BitsPerPixel <= 8) {
371 /* RJR: March 28, 2000 382 /* RJR: March 28, 2000
372 moved palette creation to "DIB_CreatePalette" */ 383 moved palette creation to "DIB_CreatePalette" */
373 screen_pal = DIB_CreatePalette(vformat->BitsPerPixel); 384 screen_pal = DIB_CreatePalette(vformat->BitsPerPixel);
374 } 385 }
375 386
376 /* Fill in some window manager capabilities */ 387 /* Fill in some window manager capabilities */
377 this->info.wm_available = 1; 388 this->info.wm_available = 1;
378 389
379 #ifdef _WIN32_WCE 390 #ifdef _WIN32_WCE
380 this->hidden->origRotation = -1; 391 this->hidden->origRotation = -1;
381 #endif 392 #endif
382 393
383 /* We're done! */ 394 /* We're done! */
384 return(0); 395 return (0);
385 } 396 }
386 397
387 /* We support any format at any dimension */ 398 /* We support any format at any dimension */
388 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 399 SDL_Rect **
389 { 400 DIB_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
390 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 401 {
391 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); 402 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
392 } else { 403 return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
393 return((SDL_Rect **)-1); 404 } else {
394 } 405 return ((SDL_Rect **) - 1);
406 }
395 } 407 }
396 408
397 409
398 /* 410 /*
399 Helper fn to work out which screen depth windows is currently using. 411 Helper fn to work out which screen depth windows is currently using.
400 15 bit mode is considered 555 format, 16 bit is 565. 412 15 bit mode is considered 555 format, 16 bit is 565.
401 returns 0 for unknown mode. 413 returns 0 for unknown mode.
402 (Derived from code in sept 1999 Windows Developer Journal 414 (Derived from code in sept 1999 Windows Developer Journal
403 http://www.wdj.com/code/archive.html) 415 http://www.wdj.com/code/archive.html)
404 */ 416 */
405 static int DIB_SussScreenDepth() 417 static int
418 DIB_SussScreenDepth()
406 { 419 {
407 #ifdef NO_GETDIBITS 420 #ifdef NO_GETDIBITS
408 int depth; 421 int depth;
409 HDC hdc; 422 HDC hdc;
410 423
411 hdc = GetDC(SDL_Window); 424 hdc = GetDC(SDL_Window);
412 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); 425 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
413 ReleaseDC(SDL_Window, hdc); 426 ReleaseDC(SDL_Window, hdc);
414 return(depth); 427 return (depth);
415 #else 428 #else
416 int depth; 429 int depth;
417 int dib_size; 430 int dib_size;
418 LPBITMAPINFOHEADER dib_hdr; 431 LPBITMAPINFOHEADER dib_hdr;
419 HDC hdc; 432 HDC hdc;
420 HBITMAP hbm; 433 HBITMAP hbm;
421 434
422 /* Allocate enough space for a DIB header plus palette (for 435 /* Allocate enough space for a DIB header plus palette (for
423 * 8-bit modes) or bitfields (for 16- and 32-bit modes) 436 * 8-bit modes) or bitfields (for 16- and 32-bit modes)
424 */ 437 */
425 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); 438 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD);
426 dib_hdr = (LPBITMAPINFOHEADER) SDL_malloc(dib_size); 439 dib_hdr = (LPBITMAPINFOHEADER) SDL_malloc(dib_size);
427 SDL_memset(dib_hdr, 0, dib_size); 440 SDL_memset(dib_hdr, 0, dib_size);
428 dib_hdr->biSize = sizeof(BITMAPINFOHEADER); 441 dib_hdr->biSize = sizeof(BITMAPINFOHEADER);
429 442
430 /* Get a device-dependent bitmap that's compatible with the 443 /* Get a device-dependent bitmap that's compatible with the
431 screen. 444 screen.
432 */ 445 */
433 hdc = GetDC(NULL); 446 hdc = GetDC(NULL);
434 hbm = CreateCompatibleBitmap( hdc, 1, 1 ); 447 hbm = CreateCompatibleBitmap(hdc, 1, 1);
435 448
436 /* Convert the DDB to a DIB. We need to call GetDIBits twice: 449 /* Convert the DDB to a DIB. We need to call GetDIBits twice:
437 * the first call just fills in the BITMAPINFOHEADER; the 450 * the first call just fills in the BITMAPINFOHEADER; the
438 * second fills in the bitfields or palette. 451 * second fills in the bitfields or palette.
439 */ 452 */
441 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); 454 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS);
442 DeleteObject(hbm); 455 DeleteObject(hbm);
443 ReleaseDC(NULL, hdc); 456 ReleaseDC(NULL, hdc);
444 457
445 depth = 0; 458 depth = 0;
446 switch( dib_hdr->biBitCount ) 459 switch (dib_hdr->biBitCount) {
447 { 460 case 8:
448 case 8: depth = 8; break; 461 depth = 8;
449 case 24: depth = 24; break; 462 break;
450 case 32: depth = 32; break; 463 case 24:
464 depth = 24;
465 break;
466 case 32:
467 depth = 32;
468 break;
451 case 16: 469 case 16:
452 if( dib_hdr->biCompression == BI_BITFIELDS ) { 470 if (dib_hdr->biCompression == BI_BITFIELDS) {
453 /* check the red mask */ 471 /* check the red mask */
454 switch( ((DWORD*)((char*)dib_hdr + dib_hdr->biSize))[0] ) { 472 switch (((DWORD *) ((char *) dib_hdr + dib_hdr->biSize))[0]) {
455 case 0xf800: depth = 16; break; /* 565 */ 473 case 0xf800:
456 case 0x7c00: depth = 15; break; /* 555 */ 474 depth = 16;
475 break; /* 565 */
476 case 0x7c00:
477 depth = 15;
478 break; /* 555 */
457 } 479 }
458 } 480 }
459 } 481 }
460 SDL_free(dib_hdr); 482 SDL_free(dib_hdr);
461 return depth; 483 return depth;
462 #endif /* NO_GETDIBITS */ 484 #endif /* NO_GETDIBITS */
463 } 485 }
464 486
465 487
466 /* Various screen update functions available */ 488 /* Various screen update functions available */
467 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); 489 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect * rects);
468 490
469 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, 491 SDL_Surface *
470 int width, int height, int bpp, Uint32 flags) 492 DIB_SetVideoMode(_THIS, SDL_Surface * current,
471 { 493 int width, int height, int bpp, Uint32 flags)
472 SDL_Surface *video; 494 {
473 Uint32 prev_flags; 495 SDL_Surface *video;
474 DWORD style; 496 Uint32 prev_flags;
475 const DWORD directstyle = 497 DWORD style;
476 (WS_POPUP); 498 const DWORD directstyle = (WS_POPUP);
477 const DWORD windowstyle = 499 const DWORD windowstyle =
478 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); 500 (WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
479 const DWORD resizestyle = 501 const DWORD resizestyle = (WS_THICKFRAME | WS_MAXIMIZEBOX);
480 (WS_THICKFRAME|WS_MAXIMIZEBOX); 502 int binfo_size;
481 int binfo_size; 503 BITMAPINFO *binfo;
482 BITMAPINFO *binfo; 504 HDC hdc;
483 HDC hdc; 505 RECT bounds;
484 RECT bounds; 506 int x, y;
485 int x, y; 507 Uint32 Rmask, Gmask, Bmask;
486 Uint32 Rmask, Gmask, Bmask; 508
487 509 /* Clean up any GL context that may be hanging around */
488 /* Clean up any GL context that may be hanging around */ 510 if (current->flags & SDL_INTERNALOPENGL) {
489 if ( current->flags & SDL_OPENGL ) { 511 WIN_GL_ShutDown(this);
490 WIN_GL_ShutDown(this); 512 }
491 } 513 SDL_resizing = 1;
492 SDL_resizing = 1; 514
493 515 /* Recalculate the bitmasks if necessary */
494 /* Recalculate the bitmasks if necessary */ 516 if (bpp == current->format->BitsPerPixel) {
495 if ( bpp == current->format->BitsPerPixel ) { 517 video = current;
496 video = current; 518 } else {
497 } else { 519 switch (bpp) {
498 switch (bpp) { 520 case 15:
499 case 15: 521 case 16:
500 case 16: 522 if (DIB_SussScreenDepth() == 15) {
501 if ( DIB_SussScreenDepth() == 15 ) { 523 /* 5-5-5 */
502 /* 5-5-5 */ 524 Rmask = 0x00007c00;
503 Rmask = 0x00007c00; 525 Gmask = 0x000003e0;
504 Gmask = 0x000003e0; 526 Bmask = 0x0000001f;
505 Bmask = 0x0000001f; 527 } else {
506 } else { 528 /* 5-6-5 */
507 /* 5-6-5 */ 529 Rmask = 0x0000f800;
508 Rmask = 0x0000f800; 530 Gmask = 0x000007e0;
509 Gmask = 0x000007e0; 531 Bmask = 0x0000001f;
510 Bmask = 0x0000001f; 532 }
511 } 533 break;
512 break; 534 case 24:
513 case 24: 535 case 32:
514 case 32: 536 /* GDI defined as 8-8-8 */
515 /* GDI defined as 8-8-8 */ 537 Rmask = 0x00ff0000;
516 Rmask = 0x00ff0000; 538 Gmask = 0x0000ff00;
517 Gmask = 0x0000ff00; 539 Bmask = 0x000000ff;
518 Bmask = 0x000000ff; 540 break;
519 break; 541 default:
520 default: 542 Rmask = 0x00000000;
521 Rmask = 0x00000000; 543 Gmask = 0x00000000;
522 Gmask = 0x00000000; 544 Bmask = 0x00000000;
523 Bmask = 0x00000000; 545 break;
524 break; 546 }
525 } 547 video = SDL_CreateRGBSurface(SDL_SWSURFACE,
526 video = SDL_CreateRGBSurface(SDL_SWSURFACE, 548 0, 0, bpp, Rmask, Gmask, Bmask, 0);
527 0, 0, bpp, Rmask, Gmask, Bmask, 0); 549 if (video == NULL) {
528 if ( video == NULL ) { 550 SDL_OutOfMemory();
529 SDL_OutOfMemory(); 551 return (NULL);
530 return(NULL); 552 }
531 } 553 }
532 } 554
533 555 /* Fill in part of the video surface */
534 /* Fill in part of the video surface */ 556 prev_flags = video->flags;
535 prev_flags = video->flags; 557 video->flags = 0; /* Clear flags */
536 video->flags = 0; /* Clear flags */ 558 video->w = width;
537 video->w = width; 559 video->h = height;
538 video->h = height; 560 video->pitch = SDL_CalculatePitch(video);
539 video->pitch = SDL_CalculatePitch(video); 561
540 562 /* Small fix for WinCE/Win32 - when activating window
541 /* Small fix for WinCE/Win32 - when activating window 563 SDL_VideoSurface is equal to zero, so activating code
542 SDL_VideoSurface is equal to zero, so activating code 564 is not called properly for fullscreen windows because
543 is not called properly for fullscreen windows because 565 macros WINDIB_FULLSCREEN uses SDL_VideoSurface
544 macros WINDIB_FULLSCREEN uses SDL_VideoSurface 566 */
545 */ 567 SDL_VideoSurface = video;
546 SDL_VideoSurface = video;
547 568
548 #if defined(_WIN32_WCE) 569 #if defined(_WIN32_WCE)
549 if ( flags & SDL_FULLSCREEN ) 570 if (flags & SDL_FULLSCREEN)
550 video->flags |= SDL_FULLSCREEN; 571 video->flags |= SDL_FULLSCREEN;
551 #endif 572 #endif
552 573
553 #ifndef NO_CHANGEDISPLAYSETTINGS 574 #ifndef NO_CHANGEDISPLAYSETTINGS
554 /* Set fullscreen mode if appropriate */ 575 /* Set fullscreen mode if appropriate */
555 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 576 if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
556 DEVMODE settings; 577 DEVMODE settings;
557 BOOL changed; 578 BOOL changed;
558 579
559 SDL_memset(&settings, 0, sizeof(DEVMODE)); 580 SDL_memset(&settings, 0, sizeof(DEVMODE));
560 settings.dmSize = sizeof(DEVMODE); 581 settings.dmSize = sizeof(DEVMODE);
561 582
562 #ifdef _WIN32_WCE 583 #ifdef _WIN32_WCE
563 // try to rotate screen to fit requested resolution 584 // try to rotate screen to fit requested resolution
564 if( this->hidden->supportRotation ) 585 if (this->hidden->supportRotation) {
565 { 586 DWORD rotation;
566 DWORD rotation; 587
567 588 // ask current mode
568 // ask current mode 589 settings.dmFields = DM_DISPLAYORIENTATION;
569 settings.dmFields = DM_DISPLAYORIENTATION; 590 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL);
570 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL); 591 rotation = settings.dmDisplayOrientation;
571 rotation = settings.dmDisplayOrientation; 592
572 593 if ((width > GetDeviceCaps(GetDC(NULL), HORZRES))
573 if( (width > GetDeviceCaps(GetDC(NULL), HORZRES)) 594 && (height < GetDeviceCaps(GetDC(NULL), VERTRES))) {
574 && (height < GetDeviceCaps(GetDC(NULL), VERTRES))) 595 switch (rotation) {
575 { 596 case DMDO_0:
576 switch( rotation ) 597 settings.dmDisplayOrientation = DMDO_90;
577 { 598 break;
578 case DMDO_0: 599 case DMDO_270:
579 settings.dmDisplayOrientation = DMDO_90; 600 settings.dmDisplayOrientation = DMDO_180;
580 break; 601 break;
581 case DMDO_270: 602 }
582 settings.dmDisplayOrientation = DMDO_180; 603 if (settings.dmDisplayOrientation != rotation) {
583 break; 604 // go to landscape
584 } 605 this->hidden->origRotation = rotation;
585 if( settings.dmDisplayOrientation != rotation ) 606 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_RESET,
586 { 607 NULL);
587 // go to landscape 608 }
588 this->hidden->origRotation = rotation; 609 }
589 ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); 610 if ((width < GetDeviceCaps(GetDC(NULL), HORZRES))
590 } 611 && (height > GetDeviceCaps(GetDC(NULL), VERTRES))) {
591 } 612 switch (rotation) {
592 if( (width < GetDeviceCaps(GetDC(NULL), HORZRES)) 613 case DMDO_90:
593 && (height > GetDeviceCaps(GetDC(NULL), VERTRES))) 614 settings.dmDisplayOrientation = DMDO_0;
594 { 615 break;
595 switch( rotation ) 616 case DMDO_180:
596 { 617 settings.dmDisplayOrientation = DMDO_270;
597 case DMDO_90: 618 break;
598 settings.dmDisplayOrientation = DMDO_0; 619 }
599 break; 620 if (settings.dmDisplayOrientation != rotation) {
600 case DMDO_180: 621 // go to portrait
601 settings.dmDisplayOrientation = DMDO_270; 622 this->hidden->origRotation = rotation;
602 break; 623 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_RESET,
603 } 624 NULL);
604 if( settings.dmDisplayOrientation != rotation ) 625 }
605 { 626 }
606 // go to portrait 627
607 this->hidden->origRotation = rotation; 628 }
608 ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL);
609 }
610 }
611
612 }
613 #endif 629 #endif
614 630
615 #ifndef _WIN32_WCE 631 #ifndef _WIN32_WCE
616 settings.dmBitsPerPel = video->format->BitsPerPixel; 632 settings.dmBitsPerPel = video->format->BitsPerPixel;
617 settings.dmPelsWidth = width; 633 settings.dmPelsWidth = width;
618 settings.dmPelsHeight = height; 634 settings.dmPelsHeight = height;
619 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; 635 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
620 if ( width <= (int)SDL_desktop_mode.dmPelsWidth && 636 if (width <= (int) SDL_desktop_mode.dmPelsWidth &&
621 height <= (int)SDL_desktop_mode.dmPelsHeight ) { 637 height <= (int) SDL_desktop_mode.dmPelsHeight) {
622 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency; 638 settings.dmDisplayFrequency = SDL_desktop_mode.dmDisplayFrequency;
623 settings.dmFields |= DM_DISPLAYFREQUENCY; 639 settings.dmFields |= DM_DISPLAYFREQUENCY;
624 } 640 }
625 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); 641 changed =
626 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { 642 (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) ==
627 settings.dmFields &= ~DM_DISPLAYFREQUENCY; 643 DISP_CHANGE_SUCCESSFUL);
628 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); 644 if (!changed && (settings.dmFields & DM_DISPLAYFREQUENCY)) {
629 } 645 settings.dmFields &= ~DM_DISPLAYFREQUENCY;
646 changed =
647 (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) ==
648 DISP_CHANGE_SUCCESSFUL);
649 }
630 #else 650 #else
631 changed = 1; 651 changed = 1;
632 #endif 652 #endif
633 if ( changed ) { 653 if (changed) {
634 video->flags |= SDL_FULLSCREEN; 654 video->flags |= SDL_FULLSCREEN;
635 SDL_fullscreen_mode = settings; 655 SDL_fullscreen_mode = settings;
636 } 656 }
637 657
638 } 658 }
639 #endif /* !NO_CHANGEDISPLAYSETTINGS */ 659 #endif /* !NO_CHANGEDISPLAYSETTINGS */
640 660
641 /* Reset the palette and create a new one if necessary */ 661 /* Reset the palette and create a new one if necessary */
642 if ( screen_pal != NULL ) { 662 if (screen_pal != NULL) {
643 /* RJR: March 28, 2000 663 /* RJR: March 28, 2000
644 delete identity palette if switching from a palettized mode */ 664 delete identity palette if switching from a palettized mode */
645 DeleteObject(screen_pal); 665 DeleteObject(screen_pal);
646 screen_pal = NULL; 666 screen_pal = NULL;
647 } 667 }
648 if ( bpp <= 8 ) 668 if (bpp <= 8) {
649 { 669 /* RJR: March 28, 2000
650 /* RJR: March 28, 2000 670 create identity palette switching to a palettized mode */
651 create identity palette switching to a palettized mode */ 671 screen_pal = DIB_CreatePalette(bpp);
652 screen_pal = DIB_CreatePalette(bpp); 672 }
653 } 673
654 674 style = GetWindowLong(SDL_Window, GWL_STYLE);
655 style = GetWindowLong(SDL_Window, GWL_STYLE); 675 style &= ~(resizestyle | WS_MAXIMIZE);
656 style &= ~(resizestyle|WS_MAXIMIZE); 676 if ((video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
657 if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 677 style &= ~windowstyle;
658 style &= ~windowstyle; 678 style |= directstyle;
659 style |= directstyle; 679 } else {
660 } else {
661 #ifndef NO_CHANGEDISPLAYSETTINGS 680 #ifndef NO_CHANGEDISPLAYSETTINGS
662 if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { 681 if ((prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) {
663 ChangeDisplaySettings(NULL, 0); 682 ChangeDisplaySettings(NULL, 0);
664 } 683 }
665 #endif 684 #endif
666 if ( flags & SDL_NOFRAME ) { 685 if (flags & SDL_NOFRAME) {
667 style &= ~windowstyle; 686 style &= ~windowstyle;
668 style |= directstyle; 687 style |= directstyle;
669 video->flags |= SDL_NOFRAME; 688 video->flags |= SDL_NOFRAME;
670 } else { 689 } else {
671 style &= ~directstyle; 690 style &= ~directstyle;
672 style |= windowstyle; 691 style |= windowstyle;
673 if ( flags & SDL_RESIZABLE ) { 692 if (flags & SDL_RESIZABLE) {
674 style |= resizestyle; 693 style |= resizestyle;
675 video->flags |= SDL_RESIZABLE; 694 video->flags |= SDL_RESIZABLE;
676 } 695 }
677 } 696 }
678 #if WS_MAXIMIZE 697 #if WS_MAXIMIZE
679 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; 698 if (IsZoomed(SDL_Window))
680 #endif 699 style |= WS_MAXIMIZE;
681 } 700 #endif
682 701 }
683 /* DJM: Don't piss of anyone who has setup his own window */ 702
684 if ( !SDL_windowid ) 703 /* DJM: Don't piss of anyone who has setup his own window */
685 SetWindowLong(SDL_Window, GWL_STYLE, style); 704 if (!SDL_windowid)
686 705 SetWindowLong(SDL_Window, GWL_STYLE, style);
687 /* Delete the old bitmap if necessary */ 706
688 if ( screen_bmp != NULL ) { 707 /* Delete the old bitmap if necessary */
689 DeleteObject(screen_bmp); 708 if (screen_bmp != NULL) {
690 } 709 DeleteObject(screen_bmp);
691 if ( ! (flags & SDL_OPENGL) ) { 710 }
692 BOOL is16bitmode = (video->format->BytesPerPixel == 2); 711 if (!(flags & SDL_INTERNALOPENGL)) {
693 712 BOOL is16bitmode = (video->format->BytesPerPixel == 2);
694 /* Suss out the bitmap info header */ 713
695 binfo_size = sizeof(*binfo); 714 /* Suss out the bitmap info header */
696 if( is16bitmode ) { 715 binfo_size = sizeof(*binfo);
697 /* 16bit modes, palette area used for rgb bitmasks */ 716 if (is16bitmode) {
698 binfo_size += 3*sizeof(DWORD); 717 /* 16bit modes, palette area used for rgb bitmasks */
699 } else if ( video->format->palette ) { 718 binfo_size += 3 * sizeof(DWORD);
700 binfo_size += video->format->palette->ncolors * 719 } else if (video->format->palette) {
701 sizeof(RGBQUAD); 720 binfo_size += video->format->palette->ncolors * sizeof(RGBQUAD);
702 } 721 }
703 binfo = (BITMAPINFO *)SDL_malloc(binfo_size); 722 binfo = (BITMAPINFO *) SDL_malloc(binfo_size);
704 if ( ! binfo ) { 723 if (!binfo) {
705 if ( video != current ) { 724 if (video != current) {
706 SDL_FreeSurface(video); 725 SDL_FreeSurface(video);
707 } 726 }
708 SDL_OutOfMemory(); 727 SDL_OutOfMemory();
709 return(NULL); 728 return (NULL);
710 } 729 }
711 730
712 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 731 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
713 binfo->bmiHeader.biWidth = video->w; 732 binfo->bmiHeader.biWidth = video->w;
714 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ 733 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */
715 binfo->bmiHeader.biPlanes = 1; 734 binfo->bmiHeader.biPlanes = 1;
716 binfo->bmiHeader.biSizeImage = video->h * video->pitch; 735 binfo->bmiHeader.biSizeImage = video->h * video->pitch;
717 binfo->bmiHeader.biXPelsPerMeter = 0; 736 binfo->bmiHeader.biXPelsPerMeter = 0;
718 binfo->bmiHeader.biYPelsPerMeter = 0; 737 binfo->bmiHeader.biYPelsPerMeter = 0;
719 binfo->bmiHeader.biClrUsed = 0; 738 binfo->bmiHeader.biClrUsed = 0;
720 binfo->bmiHeader.biClrImportant = 0; 739 binfo->bmiHeader.biClrImportant = 0;
721 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; 740 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel;
722 741
723 if ( is16bitmode ) { 742 if (is16bitmode) {
724 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ 743 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */
725 binfo->bmiHeader.biCompression = BI_BITFIELDS; 744 binfo->bmiHeader.biCompression = BI_BITFIELDS;
726 ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; 745 ((Uint32 *) binfo->bmiColors)[0] = video->format->Rmask;
727 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; 746 ((Uint32 *) binfo->bmiColors)[1] = video->format->Gmask;
728 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; 747 ((Uint32 *) binfo->bmiColors)[2] = video->format->Bmask;
729 } else { 748 } else {
730 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ 749 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */
731 if ( video->format->palette ) { 750 if (video->format->palette) {
732 SDL_memset(binfo->bmiColors, 0, 751 SDL_memset(binfo->bmiColors, 0,
733 video->format->palette->ncolors*sizeof(RGBQUAD)); 752 video->format->palette->ncolors * sizeof(RGBQUAD));
734 } 753 }
735 } 754 }
736 755
737 /* Create the offscreen bitmap buffer */ 756 /* Create the offscreen bitmap buffer */
738 hdc = GetDC(SDL_Window); 757 hdc = GetDC(SDL_Window);
739 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, 758 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS,
740 (void **)(&video->pixels), NULL, 0); 759 (void **) (&video->pixels), NULL, 0);
741 ReleaseDC(SDL_Window, hdc); 760 ReleaseDC(SDL_Window, hdc);
742 SDL_free(binfo); 761 SDL_free(binfo);
743 if ( screen_bmp == NULL ) { 762 if (screen_bmp == NULL) {
744 if ( video != current ) { 763 if (video != current) {
745 SDL_FreeSurface(video); 764 SDL_FreeSurface(video);
746 } 765 }
747 SDL_SetError("Couldn't create DIB section"); 766 SDL_SetError("Couldn't create DIB section");
748 return(NULL); 767 return (NULL);
749 } 768 }
750 this->UpdateRects = DIB_NormalUpdate; 769 this->UpdateRects = DIB_NormalUpdate;
751 770
752 /* Set video surface flags */ 771 /* Set video surface flags */
753 if ( bpp <= 8 ) { 772 if (bpp <= 8) {
754 /* BitBlt() maps colors for us */ 773 /* BitBlt() maps colors for us */
755 video->flags |= SDL_HWPALETTE; 774 video->flags |= SDL_HWPALETTE;
756 } 775 }
757 } 776 }
758 #ifndef _WIN32_WCE 777 #ifndef _WIN32_WCE
759 /* Resize the window */ 778 /* Resize the window */
760 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { 779 if (!SDL_windowid && !IsZoomed(SDL_Window)) {
761 #else 780 #else
762 if ( !SDL_windowid ) { 781 if (!SDL_windowid) {
763 #endif 782 #endif
764 HWND top; 783 HWND top;
765 UINT swp_flags; 784 UINT swp_flags;
766 const char *window = NULL; 785 const char *window = NULL;
767 const char *center = NULL; 786 const char *center = NULL;
768 787
769 if ( !SDL_windowX && !SDL_windowY ) { 788 if (!SDL_windowX && !SDL_windowY) {
770 window = SDL_getenv("SDL_VIDEO_WINDOW_POS"); 789 window = SDL_getenv("SDL_VIDEO_WINDOW_POS");
771 center = SDL_getenv("SDL_VIDEO_CENTERED"); 790 center = SDL_getenv("SDL_VIDEO_CENTERED");
772 if ( window ) { 791 if (window) {
773 if ( SDL_sscanf(window, "%d,%d", &x, &y) == 2 ) { 792 if (SDL_sscanf(window, "%d,%d", &x, &y) == 2) {
774 SDL_windowX = x; 793 SDL_windowX = x;
775 SDL_windowY = y; 794 SDL_windowY = y;
776 } 795 }
777 if ( SDL_strcmp(window, "center") == 0 ) { 796 if (SDL_strcmp(window, "center") == 0) {
778 center = window; 797 center = window;
779 } 798 }
780 } 799 }
781 } 800 }
782 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW); 801 swp_flags = (SWP_NOCOPYBITS | SWP_SHOWWINDOW);
783 802
784 bounds.left = SDL_windowX; 803 bounds.left = SDL_windowX;
785 bounds.top = SDL_windowY; 804 bounds.top = SDL_windowY;
786 bounds.right = SDL_windowX+video->w; 805 bounds.right = SDL_windowX + video->w;
787 bounds.bottom = SDL_windowY+video->h; 806 bounds.bottom = SDL_windowY + video->h;
788 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), (GetMenu(SDL_Window) != NULL), 0); 807 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE),
789 width = bounds.right-bounds.left; 808 (GetMenu(SDL_Window) != NULL), 0);
790 height = bounds.bottom-bounds.top; 809 width = bounds.right - bounds.left;
791 if ( (flags & SDL_FULLSCREEN) ) { 810 height = bounds.bottom - bounds.top;
792 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 811 if ((flags & SDL_FULLSCREEN)) {
793 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 812 x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
794 } else if ( center ) { 813 y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
795 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; 814 } else if (center) {
796 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; 815 x = (GetSystemMetrics(SM_CXSCREEN) - width) / 2;
797 } else if ( SDL_windowX || SDL_windowY || window ) { 816 y = (GetSystemMetrics(SM_CYSCREEN) - height) / 2;
798 x = bounds.left; 817 } else if (SDL_windowX || SDL_windowY || window) {
799 y = bounds.top; 818 x = bounds.left;
800 } else { 819 y = bounds.top;
801 x = y = -1; 820 } else {
802 swp_flags |= SWP_NOMOVE; 821 x = y = -1;
803 } 822 swp_flags |= SWP_NOMOVE;
804 if ( flags & SDL_FULLSCREEN ) { 823 }
805 top = HWND_TOPMOST; 824 if (flags & SDL_FULLSCREEN) {
806 } else { 825 top = HWND_TOPMOST;
807 top = HWND_NOTOPMOST; 826 } else {
808 } 827 top = HWND_NOTOPMOST;
809 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags); 828 }
810 if ( !(flags & SDL_FULLSCREEN) ) { 829 SetWindowPos(SDL_Window, top, x, y, width, height, swp_flags);
811 SDL_windowX = SDL_bounds.left; 830 if (!(flags & SDL_FULLSCREEN)) {
812 SDL_windowY = SDL_bounds.top; 831 SDL_windowX = SDL_bounds.left;
813 } 832 SDL_windowY = SDL_bounds.top;
814 SetForegroundWindow(SDL_Window); 833 }
815 } 834 SetForegroundWindow(SDL_Window);
816 SDL_resizing = 0; 835 }
817 836 SDL_resizing = 0;
818 /* Set up for OpenGL */ 837
819 if ( flags & SDL_OPENGL ) { 838 /* Set up for OpenGL */
820 if ( WIN_GL_SetupWindow(this) < 0 ) { 839 if (flags & SDL_INTERNALOPENGL) {
821 return(NULL); 840 if (WIN_GL_SetupWindow(this) < 0) {
822 } 841 return (NULL);
823 video->flags |= SDL_OPENGL; 842 }
824 } 843 video->flags |= SDL_INTERNALOPENGL;
825 844 }
826 /* JC 14 Mar 2006 845
827 Flush the message loop or this can cause big problems later 846 /* JC 14 Mar 2006
828 Especially if the user decides to use dialog boxes or assert()! 847 Flush the message loop or this can cause big problems later
829 */ 848 Especially if the user decides to use dialog boxes or assert()!
830 WIN_FlushMessageQueue(); 849 */
831 850 WIN_FlushMessageQueue();
832 /* We're live! */ 851
833 return(video); 852 /* We're live! */
853 return (video);
834 } 854 }
835 855
836 /* We don't actually allow hardware surfaces in the DIB driver */ 856 /* We don't actually allow hardware surfaces in the DIB driver */
837 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) 857 static int
838 { 858 DIB_AllocHWSurface(_THIS, SDL_Surface * surface)
839 return(-1); 859 {
840 } 860 return (-1);
841 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) 861 }
842 { 862 static void
843 return; 863 DIB_FreeHWSurface(_THIS, SDL_Surface * surface)
844 } 864 {
845 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) 865 return;
846 { 866 }
847 return(0); 867 static int
848 } 868 DIB_LockHWSurface(_THIS, SDL_Surface * surface)
849 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) 869 {
850 { 870 return (0);
851 return; 871 }
852 } 872 static void
853 873 DIB_UnlockHWSurface(_THIS, SDL_Surface * surface)
854 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) 874 {
855 { 875 return;
856 HDC hdc, mdc; 876 }
857 int i; 877
858 878 static void
859 hdc = GetDC(SDL_Window); 879 DIB_NormalUpdate(_THIS, int numrects, SDL_Rect * rects)
860 if ( screen_pal ) { 880 {
861 SelectPalette(hdc, screen_pal, FALSE); 881 HDC hdc, mdc;
862 } 882 int i;
863 mdc = CreateCompatibleDC(hdc); 883
864 SelectObject(mdc, screen_bmp); 884 hdc = GetDC(SDL_Window);
865 for ( i=0; i<numrects; ++i ) { 885 if (screen_pal) {
866 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, 886 SelectPalette(hdc, screen_pal, FALSE);
867 mdc, rects[i].x, rects[i].y, SRCCOPY); 887 }
868 } 888 mdc = CreateCompatibleDC(hdc);
869 DeleteDC(mdc); 889 SelectObject(mdc, screen_bmp);
870 ReleaseDC(SDL_Window, hdc); 890 for (i = 0; i < numrects; ++i) {
871 } 891 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h,
872 892 mdc, rects[i].x, rects[i].y, SRCCOPY);
873 893 }
874 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 894 DeleteDC(mdc);
895 ReleaseDC(SDL_Window, hdc);
896 }
897
898
899 int
900 DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
875 { 901 {
876 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) 902 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
877 HDC hdc, mdc; 903 HDC hdc, mdc;
878 RGBQUAD *pal; 904 RGBQUAD *pal;
879 #else 905 #else
880 HDC hdc; 906 HDC hdc;
881 #endif 907 #endif
882 int i; 908 int i;
883 909
884 /* Update the display palette */ 910 /* Update the display palette */
885 hdc = GetDC(SDL_Window); 911 hdc = GetDC(SDL_Window);
886 if ( screen_pal ) { 912 if (screen_pal) {
887 PALETTEENTRY *entries; 913 PALETTEENTRY *entries;
888 914
889 entries = SDL_stack_alloc(PALETTEENTRY, ncolors); 915 entries = SDL_stack_alloc(PALETTEENTRY, ncolors);
890 for ( i=0; i<ncolors; ++i ) { 916 for (i = 0; i < ncolors; ++i) {
891 entries[i].peRed = colors[i].r; 917 entries[i].peRed = colors[i].r;
892 entries[i].peGreen = colors[i].g; 918 entries[i].peGreen = colors[i].g;
893 entries[i].peBlue = colors[i].b; 919 entries[i].peBlue = colors[i].b;
894 entries[i].peFlags = PC_NOCOLLAPSE; 920 entries[i].peFlags = PC_NOCOLLAPSE;
895 } 921 }
896 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries); 922 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries);
897 SelectPalette(hdc, screen_pal, FALSE); 923 SelectPalette(hdc, screen_pal, FALSE);
898 RealizePalette(hdc); 924 RealizePalette(hdc);
899 SDL_stack_free(entries); 925 SDL_stack_free(entries);
900 } 926 }
901
902 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) 927 #if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400)
903 /* Copy palette colors into DIB palette */ 928 /* Copy palette colors into DIB palette */
904 pal = SDL_stack_alloc(RGBQUAD, ncolors); 929 pal = SDL_stack_alloc(RGBQUAD, ncolors);
905 for ( i=0; i<ncolors; ++i ) { 930 for (i = 0; i < ncolors; ++i) {
906 pal[i].rgbRed = colors[i].r; 931 pal[i].rgbRed = colors[i].r;
907 pal[i].rgbGreen = colors[i].g; 932 pal[i].rgbGreen = colors[i].g;
908 pal[i].rgbBlue = colors[i].b; 933 pal[i].rgbBlue = colors[i].b;
909 pal[i].rgbReserved = 0; 934 pal[i].rgbReserved = 0;
910 } 935 }
911 936
912 /* Set the DIB palette and update the display */ 937 /* Set the DIB palette and update the display */
913 mdc = CreateCompatibleDC(hdc); 938 mdc = CreateCompatibleDC(hdc);
914 SelectObject(mdc, screen_bmp); 939 SelectObject(mdc, screen_bmp);
915 SetDIBColorTable(mdc, firstcolor, ncolors, pal); 940 SetDIBColorTable(mdc, firstcolor, ncolors, pal);
916 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, 941 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, mdc, 0, 0, SRCCOPY);
917 mdc, 0, 0, SRCCOPY); 942 DeleteDC(mdc);
918 DeleteDC(mdc); 943 SDL_stack_free(pal);
919 SDL_stack_free(pal); 944 #endif
920 #endif 945 ReleaseDC(SDL_Window, hdc);
921 ReleaseDC(SDL_Window, hdc); 946 return (1);
922 return(1); 947 }
923 } 948
924 949
925 950 static void
926 static void DIB_CheckGamma(_THIS) 951 DIB_CheckGamma(_THIS)
927 { 952 {
928 #ifndef NO_GAMMA_SUPPORT 953 #ifndef NO_GAMMA_SUPPORT
929 HDC hdc; 954 HDC hdc;
930 WORD ramp[3*256]; 955 WORD ramp[3 * 256];
931 956
932 /* If we fail to get gamma, disable gamma control */ 957 /* If we fail to get gamma, disable gamma control */
933 hdc = GetDC(SDL_Window); 958 hdc = GetDC(SDL_Window);
934 if ( ! GetDeviceGammaRamp(hdc, ramp) ) { 959 if (!GetDeviceGammaRamp(hdc, ramp)) {
935 this->GetGammaRamp = NULL; 960 this->GetGammaRamp = NULL;
936 this->SetGammaRamp = NULL; 961 this->SetGammaRamp = NULL;
937 } 962 }
938 ReleaseDC(SDL_Window, hdc); 963 ReleaseDC(SDL_Window, hdc);
939 #endif /* !NO_GAMMA_SUPPORT */ 964 #endif /* !NO_GAMMA_SUPPORT */
940 } 965 }
941 void DIB_SwapGamma(_THIS) 966
967 void
968 DIB_SwapGamma(_THIS)
942 { 969 {
943 #ifndef NO_GAMMA_SUPPORT 970 #ifndef NO_GAMMA_SUPPORT
944 HDC hdc; 971 HDC hdc;
945 972
946 if ( gamma_saved ) { 973 if (gamma_saved) {
947 hdc = GetDC(SDL_Window); 974 hdc = GetDC(SDL_Window);
948 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 975 if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
949 /* About to leave active state, restore gamma */ 976 /* About to leave active state, restore gamma */
950 SetDeviceGammaRamp(hdc, gamma_saved); 977 SetDeviceGammaRamp(hdc, gamma_saved);
951 } else { 978 } else {
952 /* About to enter active state, set game gamma */ 979 /* About to enter active state, set game gamma */
953 GetDeviceGammaRamp(hdc, gamma_saved); 980 GetDeviceGammaRamp(hdc, gamma_saved);
954 SetDeviceGammaRamp(hdc, this->gamma); 981 SetDeviceGammaRamp(hdc, this->gamma);
955 } 982 }
956 ReleaseDC(SDL_Window, hdc); 983 ReleaseDC(SDL_Window, hdc);
957 } 984 }
958 #endif /* !NO_GAMMA_SUPPORT */ 985 #endif /* !NO_GAMMA_SUPPORT */
959 } 986 }
960 void DIB_QuitGamma(_THIS) 987 void
988 DIB_QuitGamma(_THIS)
961 { 989 {
962 #ifndef NO_GAMMA_SUPPORT 990 #ifndef NO_GAMMA_SUPPORT
963 if ( gamma_saved ) { 991 if (gamma_saved) {
964 /* Restore the original gamma if necessary */ 992 /* Restore the original gamma if necessary */
965 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 993 if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
966 HDC hdc; 994 HDC hdc;
967 995
968 hdc = GetDC(SDL_Window); 996 hdc = GetDC(SDL_Window);
969 SetDeviceGammaRamp(hdc, gamma_saved); 997 SetDeviceGammaRamp(hdc, gamma_saved);
970 ReleaseDC(SDL_Window, hdc); 998 ReleaseDC(SDL_Window, hdc);
971 } 999 }
972 1000
973 /* Free the saved gamma memory */ 1001 /* Free the saved gamma memory */
974 SDL_free(gamma_saved); 1002 SDL_free(gamma_saved);
975 gamma_saved = 0; 1003 gamma_saved = 0;
976 } 1004 }
977 #endif /* !NO_GAMMA_SUPPORT */ 1005 #endif /* !NO_GAMMA_SUPPORT */
978 } 1006 }
979 1007
980 int DIB_SetGammaRamp(_THIS, Uint16 *ramp) 1008 int
1009 DIB_SetGammaRamp(_THIS, Uint16 * ramp)
981 { 1010 {
982 #ifdef NO_GAMMA_SUPPORT 1011 #ifdef NO_GAMMA_SUPPORT
983 SDL_SetError("SDL compiled without gamma ramp support"); 1012 SDL_SetError("SDL compiled without gamma ramp support");
984 return -1; 1013 return -1;
985 #else 1014 #else
986 HDC hdc; 1015 HDC hdc;
987 BOOL succeeded; 1016 BOOL succeeded;
988 1017
989 /* Set the ramp for the display */ 1018 /* Set the ramp for the display */
990 if ( ! gamma_saved ) { 1019 if (!gamma_saved) {
991 gamma_saved = (WORD *)SDL_malloc(3*256*sizeof(*gamma_saved)); 1020 gamma_saved = (WORD *) SDL_malloc(3 * 256 * sizeof(*gamma_saved));
992 if ( ! gamma_saved ) { 1021 if (!gamma_saved) {
993 SDL_OutOfMemory(); 1022 SDL_OutOfMemory();
994 return -1; 1023 return -1;
995 } 1024 }
996 hdc = GetDC(SDL_Window); 1025 hdc = GetDC(SDL_Window);
997 GetDeviceGammaRamp(hdc, gamma_saved); 1026 GetDeviceGammaRamp(hdc, gamma_saved);
998 ReleaseDC(SDL_Window, hdc); 1027 ReleaseDC(SDL_Window, hdc);
999 } 1028 }
1000 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { 1029 if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
1001 hdc = GetDC(SDL_Window); 1030 hdc = GetDC(SDL_Window);
1002 succeeded = SetDeviceGammaRamp(hdc, ramp); 1031 succeeded = SetDeviceGammaRamp(hdc, ramp);
1003 ReleaseDC(SDL_Window, hdc); 1032 ReleaseDC(SDL_Window, hdc);
1004 } else { 1033 } else {
1005 succeeded = TRUE; 1034 succeeded = TRUE;
1006 } 1035 }
1007 return succeeded ? 0 : -1; 1036 return succeeded ? 0 : -1;
1008 #endif /* !NO_GAMMA_SUPPORT */ 1037 #endif /* !NO_GAMMA_SUPPORT */
1009 } 1038 }
1010 1039
1011 int DIB_GetGammaRamp(_THIS, Uint16 *ramp) 1040 int
1041 DIB_GetGammaRamp(_THIS, Uint16 * ramp)
1012 { 1042 {
1013 #ifdef NO_GAMMA_SUPPORT 1043 #ifdef NO_GAMMA_SUPPORT
1014 SDL_SetError("SDL compiled without gamma ramp support"); 1044 SDL_SetError("SDL compiled without gamma ramp support");
1015 return -1; 1045 return -1;
1016 #else 1046 #else
1017 HDC hdc; 1047 HDC hdc;
1018 BOOL succeeded; 1048 BOOL succeeded;
1019 1049
1020 /* Get the ramp from the display */ 1050 /* Get the ramp from the display */
1021 hdc = GetDC(SDL_Window); 1051 hdc = GetDC(SDL_Window);
1022 succeeded = GetDeviceGammaRamp(hdc, ramp); 1052 succeeded = GetDeviceGammaRamp(hdc, ramp);
1023 ReleaseDC(SDL_Window, hdc); 1053 ReleaseDC(SDL_Window, hdc);
1024 return succeeded ? 0 : -1; 1054 return succeeded ? 0 : -1;
1025 #endif /* !NO_GAMMA_SUPPORT */ 1055 #endif /* !NO_GAMMA_SUPPORT */
1026 } 1056 }
1027 1057
1028 void DIB_VideoQuit(_THIS) 1058 void
1029 { 1059 DIB_VideoQuit(_THIS)
1030 int i, j; 1060 {
1031 1061 int i, j;
1032 /* Destroy the window and everything associated with it */ 1062
1033 if ( SDL_Window ) { 1063 /* Destroy the window and everything associated with it */
1034 /* Delete the screen bitmap (also frees screen->pixels) */ 1064 if (SDL_Window) {
1035 if ( this->screen ) { 1065 /* Delete the screen bitmap (also frees screen->pixels) */
1066 if (this->screen) {
1036 #ifndef NO_CHANGEDISPLAYSETTINGS 1067 #ifndef NO_CHANGEDISPLAYSETTINGS
1037 if ( this->screen->flags & SDL_FULLSCREEN ) { 1068 if (this->screen->flags & SDL_FULLSCREEN) {
1038 ChangeDisplaySettings(NULL, 0); 1069 ChangeDisplaySettings(NULL, 0);
1039 ShowWindow(SDL_Window, SW_HIDE); 1070 ShowWindow(SDL_Window, SW_HIDE);
1040 } 1071 }
1041 #endif 1072 #endif
1042 if ( this->screen->flags & SDL_OPENGL ) { 1073 if (this->screen->flags & SDL_OPENGL) {
1043 WIN_GL_ShutDown(this); 1074 WIN_GL_ShutDown(this);
1044 } 1075 }
1045 this->screen->pixels = NULL; 1076 this->screen->pixels = NULL;
1046 } 1077 }
1047 if ( screen_bmp ) { 1078 if (screen_bmp) {
1048 DeleteObject(screen_bmp); 1079 DeleteObject(screen_bmp);
1049 screen_bmp = NULL; 1080 screen_bmp = NULL;
1050 } 1081 }
1051 if ( screen_icn ) { 1082 if (screen_icn) {
1052 DestroyIcon(screen_icn); 1083 DestroyIcon(screen_icn);
1053 screen_icn = NULL; 1084 screen_icn = NULL;
1054 } 1085 }
1055 DIB_QuitGamma(this); 1086 DIB_QuitGamma(this);
1056 DIB_DestroyWindow(this); 1087 DIB_DestroyWindow(this);
1057 1088
1058 SDL_Window = NULL; 1089 SDL_Window = NULL;
1059 1090
1060 #if defined(_WIN32_WCE) 1091 #if defined(_WIN32_WCE)
1061 1092
1062 // Unload wince aygshell library to prevent leak 1093 // Unload wince aygshell library to prevent leak
1063 if( aygshell ) 1094 if (aygshell) {
1064 { 1095 FreeLibrary(aygshell);
1065 FreeLibrary(aygshell); 1096 aygshell = NULL;
1066 aygshell = NULL; 1097 }
1067 } 1098 #endif
1068 #endif 1099 }
1069 } 1100
1070 1101 for (i = 0; i < SDL_arraysize(SDL_modelist); ++i) {
1071 for ( i=0; i < SDL_arraysize(SDL_modelist); ++i ) { 1102 if (!SDL_modelist[i]) {
1072 if ( !SDL_modelist[i] ) { 1103 continue;
1073 continue; 1104 }
1074 } 1105 for (j = 0; SDL_modelist[i][j]; ++j) {
1075 for ( j=0; SDL_modelist[i][j]; ++j ) { 1106 SDL_free(SDL_modelist[i][j]);
1076 SDL_free(SDL_modelist[i][j]); 1107 }
1077 } 1108 SDL_free(SDL_modelist[i]);
1078 SDL_free(SDL_modelist[i]); 1109 SDL_modelist[i] = NULL;
1079 SDL_modelist[i] = NULL; 1110 SDL_nummodes[i] = 0;
1080 SDL_nummodes[i] = 0; 1111 }
1081 }
1082 } 1112 }
1083 1113
1084 /* Exported for the windows message loop only */ 1114 /* Exported for the windows message loop only */
1085 static void DIB_FocusPalette(_THIS, int foreground) 1115 static void
1086 { 1116 DIB_FocusPalette(_THIS, int foreground)
1087 if ( screen_pal != NULL ) { 1117 {
1088 HDC hdc; 1118 if (screen_pal != NULL) {
1089 1119 HDC hdc;
1090 hdc = GetDC(SDL_Window); 1120
1091 SelectPalette(hdc, screen_pal, FALSE); 1121 hdc = GetDC(SDL_Window);
1092 if ( RealizePalette(hdc) ) 1122 SelectPalette(hdc, screen_pal, FALSE);
1093 InvalidateRect(SDL_Window, NULL, FALSE); 1123 if (RealizePalette(hdc))
1094 ReleaseDC(SDL_Window, hdc); 1124 InvalidateRect(SDL_Window, NULL, FALSE);
1095 } 1125 ReleaseDC(SDL_Window, hdc);
1096 } 1126 }
1097 static void DIB_RealizePalette(_THIS) 1127 }
1098 { 1128 static void
1099 DIB_FocusPalette(this, 1); 1129 DIB_RealizePalette(_THIS)
1100 } 1130 {
1101 static void DIB_PaletteChanged(_THIS, HWND window) 1131 DIB_FocusPalette(this, 1);
1102 { 1132 }
1103 if ( window != SDL_Window ) { 1133 static void
1104 DIB_FocusPalette(this, 0); 1134 DIB_PaletteChanged(_THIS, HWND window)
1105 } 1135 {
1136 if (window != SDL_Window) {
1137 DIB_FocusPalette(this, 0);
1138 }
1106 } 1139 }
1107 1140
1108 /* Exported for the windows message loop only */ 1141 /* Exported for the windows message loop only */
1109 static void DIB_WinPAINT(_THIS, HDC hdc) 1142 static void
1110 { 1143 DIB_WinPAINT(_THIS, HDC hdc)
1111 HDC mdc; 1144 {
1112 1145 HDC mdc;
1113 if ( screen_pal ) { 1146
1114 SelectPalette(hdc, screen_pal, FALSE); 1147 if (screen_pal) {
1115 } 1148 SelectPalette(hdc, screen_pal, FALSE);
1116 mdc = CreateCompatibleDC(hdc); 1149 }
1117 SelectObject(mdc, screen_bmp); 1150 mdc = CreateCompatibleDC(hdc);
1118 BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h, 1151 SelectObject(mdc, screen_bmp);
1119 mdc, 0, 0, SRCCOPY); 1152 BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h,
1120 DeleteDC(mdc); 1153 mdc, 0, 0, SRCCOPY);
1154 DeleteDC(mdc);
1121 } 1155 }
1122 1156
1123 /* Stub in case DirectX isn't available */ 1157 /* Stub in case DirectX isn't available */
1124 #if !SDL_AUDIO_DRIVER_DSOUND 1158 #if !SDL_AUDIO_DRIVER_DSOUND
1125 void DX5_SoundFocus(HWND hwnd) 1159 void
1126 { 1160 DX5_SoundFocus(HWND hwnd)
1127 return; 1161 {
1128 } 1162 return;
1129 #endif 1163 }
1164 #endif
1165 /* vi: set ts=4 sw=4 expandtab: */