comparison src/video/windib/SDL_dibvideo.c @ 1668:4da1ee79c9af SDL-1.3

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