Mercurial > sdl-ios-xcode
annotate src/video/windib/SDL_dibvideo.c @ 36:13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Wed, 23 May 2001 23:35:10 +0000 |
parents | 74212992fb08 |
children | 60a6e045808e |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 #include <stdio.h> | |
29 #include <stdlib.h> | |
30 #include <malloc.h> | |
31 #include <windows.h> | |
32 | |
33 /* Not yet in the mingw32 cross-compile headers */ | |
34 #ifndef CDS_FULLSCREEN | |
35 #define CDS_FULLSCREEN 4 | |
36 #endif | |
37 | |
38 #include "SDL.h" | |
39 #include "SDL_mutex.h" | |
40 #include "SDL_syswm.h" | |
41 #include "SDL_sysvideo.h" | |
42 #include "SDL_sysevents.h" | |
43 #include "SDL_events_c.h" | |
44 #include "SDL_pixels_c.h" | |
45 #include "SDL_dibvideo.h" | |
46 #include "SDL_syswm_c.h" | |
47 #include "SDL_sysmouse_c.h" | |
48 #include "SDL_dibevents_c.h" | |
49 #include "SDL_wingl_c.h" | |
50 | |
51 #ifdef _WIN32_WCE | |
52 #define NO_GETDIBITS | |
53 #define NO_CHANGEDISPLAYSETTINGS | |
54 #define NO_GAMMA_SUPPORT | |
55 #endif | |
56 | |
57 /* Initialization/Query functions */ | |
58 static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
59 static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
60 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
61 static int DIB_SetColors(_THIS, int firstcolor, int ncolors, | |
62 SDL_Color *colors); | |
63 static void DIB_CheckGamma(_THIS); | |
64 static void DIB_SwapGamma(_THIS); | |
65 static void DIB_QuitGamma(_THIS); | |
66 #ifndef NO_GAMMA_SUPPORT | |
67 static int DIB_SetGammaRamp(_THIS, Uint16 *ramp); | |
68 static int DIB_GetGammaRamp(_THIS, Uint16 *ramp); | |
69 #endif | |
70 static void DIB_VideoQuit(_THIS); | |
71 | |
72 /* Hardware surface functions */ | |
73 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface); | |
74 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface); | |
75 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
76 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface); | |
77 | |
78 /* Windows message handling functions */ | |
79 static void DIB_RealizePalette(_THIS); | |
80 static void DIB_PaletteChanged(_THIS, HWND window); | |
81 static void DIB_WinPAINT(_THIS, HDC hdc); | |
82 | |
83 /* helper fn */ | |
84 static int DIB_SussScreenDepth(); | |
85 | |
86 /* DIB driver bootstrap functions */ | |
87 | |
88 static int DIB_Available(void) | |
89 { | |
90 return(1); | |
91 } | |
92 | |
93 static void DIB_DeleteDevice(SDL_VideoDevice *device) | |
94 { | |
95 if ( device ) { | |
96 if ( device->hidden ) { | |
97 free(device->hidden); | |
98 } | |
99 if ( device->gl_data ) { | |
100 free(device->gl_data); | |
101 } | |
102 free(device); | |
103 } | |
104 } | |
105 | |
106 static SDL_VideoDevice *DIB_CreateDevice(int devindex) | |
107 { | |
108 SDL_VideoDevice *device; | |
109 | |
110 /* Initialize all variables that we clean on shutdown */ | |
111 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
112 if ( device ) { | |
113 memset(device, 0, (sizeof *device)); | |
114 device->hidden = (struct SDL_PrivateVideoData *) | |
115 malloc((sizeof *device->hidden)); | |
116 device->gl_data = (struct SDL_PrivateGLData *) | |
117 malloc((sizeof *device->gl_data)); | |
118 } | |
119 if ( (device == NULL) || (device->hidden == NULL) || | |
120 (device->gl_data == NULL) ) { | |
121 SDL_OutOfMemory(); | |
122 DIB_DeleteDevice(device); | |
123 return(NULL); | |
124 } | |
125 memset(device->hidden, 0, (sizeof *device->hidden)); | |
126 memset(device->gl_data, 0, (sizeof *device->gl_data)); | |
127 | |
128 /* Set the function pointers */ | |
129 device->VideoInit = DIB_VideoInit; | |
130 device->ListModes = DIB_ListModes; | |
131 device->SetVideoMode = DIB_SetVideoMode; | |
132 device->UpdateMouse = WIN_UpdateMouse; | |
133 device->SetColors = DIB_SetColors; | |
134 device->UpdateRects = NULL; | |
135 device->VideoQuit = DIB_VideoQuit; | |
136 device->AllocHWSurface = DIB_AllocHWSurface; | |
137 device->CheckHWBlit = NULL; | |
138 device->FillHWRect = NULL; | |
139 device->SetHWColorKey = NULL; | |
140 device->SetHWAlpha = NULL; | |
141 device->LockHWSurface = DIB_LockHWSurface; | |
142 device->UnlockHWSurface = DIB_UnlockHWSurface; | |
143 device->FlipHWSurface = NULL; | |
144 device->FreeHWSurface = DIB_FreeHWSurface; | |
145 #ifndef NO_GAMMA_SUPPORT | |
146 device->SetGammaRamp = DIB_SetGammaRamp; | |
147 device->GetGammaRamp = DIB_GetGammaRamp; | |
148 #endif | |
149 #ifdef HAVE_OPENGL | |
150 device->GL_LoadLibrary = WIN_GL_LoadLibrary; | |
151 device->GL_GetProcAddress = WIN_GL_GetProcAddress; | |
152 device->GL_GetAttribute = WIN_GL_GetAttribute; | |
153 device->GL_MakeCurrent = WIN_GL_MakeCurrent; | |
154 device->GL_SwapBuffers = WIN_GL_SwapBuffers; | |
155 #endif | |
156 device->SetCaption = WIN_SetWMCaption; | |
157 device->SetIcon = WIN_SetWMIcon; | |
158 device->IconifyWindow = WIN_IconifyWindow; | |
159 device->GrabInput = WIN_GrabInput; | |
160 device->GetWMInfo = WIN_GetWMInfo; | |
161 device->FreeWMCursor = WIN_FreeWMCursor; | |
162 device->CreateWMCursor = WIN_CreateWMCursor; | |
163 device->ShowWMCursor = WIN_ShowWMCursor; | |
164 device->WarpWMCursor = WIN_WarpWMCursor; | |
165 device->CheckMouseMode = WIN_CheckMouseMode; | |
166 device->InitOSKeymap = DIB_InitOSKeymap; | |
167 device->PumpEvents = DIB_PumpEvents; | |
168 | |
169 /* Set up the windows message handling functions */ | |
170 WIN_RealizePalette = DIB_RealizePalette; | |
171 WIN_PaletteChanged = DIB_PaletteChanged; | |
172 WIN_SwapGamma = DIB_SwapGamma; | |
173 WIN_WinPAINT = DIB_WinPAINT; | |
174 HandleMessage = DIB_HandleMessage; | |
175 | |
176 device->free = DIB_DeleteDevice; | |
177 | |
178 /* We're finally ready */ | |
179 return device; | |
180 } | |
181 | |
182 VideoBootStrap WINDIB_bootstrap = { | |
183 "windib", "Win95/98/NT/2000 GDI", | |
184 DIB_Available, DIB_CreateDevice | |
185 }; | |
186 | |
187 #ifndef NO_CHANGEDISPLAYSETTINGS | |
188 | |
189 static int cmpmodes(const void *va, const void *vb) | |
190 { | |
191 SDL_Rect *a = *(SDL_Rect **)va; | |
192 SDL_Rect *b = *(SDL_Rect **)vb; | |
193 if(a->w > b->w) | |
194 return -1; | |
195 return b->h - a->h; | |
196 } | |
197 | |
198 static int DIB_AddMode(_THIS, int bpp, int w, int h) | |
199 { | |
200 SDL_Rect *mode; | |
201 int i, index; | |
202 int next_mode; | |
203 | |
204 /* Check to see if we already have this mode */ | |
205 if ( bpp < 8 ) { /* Not supported */ | |
206 return(0); | |
207 } | |
208 index = ((bpp+7)/8)-1; | |
209 for ( i=0; i<SDL_nummodes[index]; ++i ) { | |
210 mode = SDL_modelist[index][i]; | |
211 if ( (mode->w == w) && (mode->h == h) ) { | |
212 return(0); | |
213 } | |
214 } | |
215 | |
216 /* Set up the new video mode rectangle */ | |
217 mode = (SDL_Rect *)malloc(sizeof *mode); | |
218 if ( mode == NULL ) { | |
219 SDL_OutOfMemory(); | |
220 return(-1); | |
221 } | |
222 mode->x = 0; | |
223 mode->y = 0; | |
224 mode->w = w; | |
225 mode->h = h; | |
226 | |
227 /* Allocate the new list of modes, and fill in the new mode */ | |
228 next_mode = SDL_nummodes[index]; | |
229 SDL_modelist[index] = (SDL_Rect **) | |
230 realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); | |
231 if ( SDL_modelist[index] == NULL ) { | |
232 SDL_OutOfMemory(); | |
233 SDL_nummodes[index] = 0; | |
234 free(mode); | |
235 return(-1); | |
236 } | |
237 SDL_modelist[index][next_mode] = mode; | |
238 SDL_modelist[index][next_mode+1] = NULL; | |
239 SDL_nummodes[index]++; | |
240 | |
241 return(0); | |
242 } | |
243 | |
244 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
245 | |
246 static HPALETTE DIB_CreatePalette(int bpp) | |
247 { | |
248 /* RJR: March 28, 2000 | |
249 moved palette creation here from "DIB_VideoInit" */ | |
250 | |
251 HPALETTE handle = NULL; | |
252 | |
253 if ( bpp <= 8 ) | |
254 { | |
255 LOGPALETTE *palette; | |
256 HDC hdc; | |
257 int ncolors; | |
258 int i; | |
259 | |
260 ncolors = 1; | |
261 for ( i=0; i<bpp; ++i ) { | |
262 ncolors *= 2; | |
263 } | |
264 palette = (LOGPALETTE *)malloc(sizeof(*palette)+ | |
265 ncolors*sizeof(PALETTEENTRY)); | |
266 palette->palVersion = 0x300; | |
267 palette->palNumEntries = ncolors; | |
268 hdc = GetDC(SDL_Window); | |
269 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry); | |
270 ReleaseDC(SDL_Window, hdc); | |
271 handle = CreatePalette(palette); | |
272 free(palette); | |
273 } | |
274 | |
275 return handle; | |
276 } | |
277 | |
278 int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
279 { | |
280 #ifndef NO_CHANGEDISPLAYSETTINGS | |
281 int i; | |
282 DEVMODE settings; | |
283 #endif | |
284 | |
285 /* Create the window */ | |
286 if ( DIB_CreateWindow(this) < 0 ) { | |
287 return(-1); | |
288 } | |
289 DX5_SoundFocus(SDL_Window); | |
290 | |
291 /* Determine the screen depth */ | |
292 vformat->BitsPerPixel = DIB_SussScreenDepth(); | |
293 switch (vformat->BitsPerPixel) { | |
294 case 15: | |
295 vformat->Rmask = 0x00007c00; | |
296 vformat->Gmask = 0x000003e0; | |
297 vformat->Bmask = 0x0000001f; | |
298 vformat->BitsPerPixel = 16; | |
299 break; | |
300 case 16: | |
301 vformat->Rmask = 0x0000f800; | |
302 vformat->Gmask = 0x000007e0; | |
303 vformat->Bmask = 0x0000001f; | |
304 break; | |
305 case 24: | |
306 case 32: | |
307 /* GDI defined as 8-8-8 */ | |
308 vformat->Rmask = 0x00ff0000; | |
309 vformat->Gmask = 0x0000ff00; | |
310 vformat->Bmask = 0x000000ff; | |
311 break; | |
312 default: | |
313 break; | |
314 } | |
315 | |
316 /* See if gamma is supported on this screen */ | |
317 DIB_CheckGamma(this); | |
318 | |
319 #ifndef NO_CHANGEDISPLAYSETTINGS | |
320 /* Query for the list of available video modes */ | |
321 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { | |
322 DIB_AddMode(this, settings.dmBitsPerPel, | |
323 settings.dmPelsWidth, settings.dmPelsHeight); | |
324 } | |
325 /* Sort the mode lists */ | |
326 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
327 if ( SDL_nummodes[i] > 0 ) { | |
328 qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); | |
329 } | |
330 } | |
331 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
332 | |
333 /* Grab an identity palette if we are in a palettized mode */ | |
334 if ( vformat->BitsPerPixel <= 8 ) { | |
335 /* RJR: March 28, 2000 | |
336 moved palette creation to "DIB_CreatePalette" */ | |
337 screen_pal = DIB_CreatePalette(vformat->BitsPerPixel); | |
338 } | |
339 | |
340 /* Fill in some window manager capabilities */ | |
341 this->info.wm_available = 1; | |
342 | |
343 /* We're done! */ | |
344 return(0); | |
345 } | |
346 | |
347 /* We support any format at any dimension */ | |
348 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
349 { | |
350 #ifdef NO_CHANGEDISPLAYSETTINGS | |
351 return((SDL_Rect **)-1); | |
352 #else | |
353 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
354 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
355 } else { | |
356 return((SDL_Rect **)-1); | |
357 } | |
358 #endif | |
359 } | |
360 | |
361 | |
362 /* | |
363 Helper fn to work out which screen depth windows is currently using. | |
364 15 bit mode is considered 555 format, 16 bit is 565. | |
365 returns 0 for unknown mode. | |
366 (Derived from code in sept 1999 Windows Developer Journal | |
367 http://www.wdj.com/code/archive.html) | |
368 */ | |
369 static int DIB_SussScreenDepth() | |
370 { | |
371 #ifdef NO_GETDIBITS | |
372 int depth; | |
373 HDC hdc; | |
374 | |
375 hdc = GetDC(SDL_Window); | |
376 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); | |
377 ReleaseDC(SDL_Window, hdc); | |
378 if ( depth == 16 ) { | |
379 depth = 15; /* GDI defined as RGB 555 */ | |
380 } | |
381 return(depth); | |
382 #else | |
383 int dib_size; | |
384 LPBITMAPINFOHEADER dib_hdr; | |
385 HDC hdc; | |
386 HBITMAP hbm; | |
387 | |
388 /* Allocate enough space for a DIB header plus palette (for | |
389 * 8-bit modes) or bitfields (for 16- and 32-bit modes) | |
390 */ | |
391 dib_size = sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD); | |
392 dib_hdr = (LPBITMAPINFOHEADER) malloc(dib_size); | |
393 memset(dib_hdr, 0, dib_size); | |
394 dib_hdr->biSize = sizeof(BITMAPINFOHEADER); | |
395 | |
396 /* Get a device-dependent bitmap that's compatible with the | |
397 screen. | |
398 */ | |
399 hdc = GetDC(NULL); | |
400 hbm = CreateCompatibleBitmap( hdc, 1, 1 ); | |
401 | |
402 /* Convert the DDB to a DIB. We need to call GetDIBits twice: | |
403 * the first call just fills in the BITMAPINFOHEADER; the | |
404 * second fills in the bitfields or palette. | |
405 */ | |
406 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); | |
407 GetDIBits(hdc, hbm, 0, 1, NULL, (LPBITMAPINFO) dib_hdr, DIB_RGB_COLORS); | |
408 DeleteObject(hbm); | |
409 ReleaseDC(NULL, hdc); | |
410 | |
411 switch( dib_hdr->biBitCount ) | |
412 { | |
413 case 8: return 8; | |
414 case 24: return 24; | |
415 case 32: return 32; | |
416 case 16: | |
417 if( dib_hdr->biCompression == BI_BITFIELDS ) { | |
418 /* check the red mask */ | |
419 switch( ((DWORD*)((char*)dib_hdr + dib_hdr->biSize))[0] ) { | |
420 case 0xf800: return 16; /* 565 */ | |
421 case 0x7c00: return 15; /* 555 */ | |
422 } | |
423 } | |
424 } | |
425 return 0; /* poo. */ | |
426 #endif /* NO_GETDIBITS */ | |
427 } | |
428 | |
429 | |
430 /* Various screen update functions available */ | |
431 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects); | |
432 | |
433 SDL_Surface *DIB_SetVideoMode(_THIS, SDL_Surface *current, | |
434 int width, int height, int bpp, Uint32 flags) | |
435 { | |
436 SDL_Surface *video; | |
437 Uint32 prev_flags; | |
438 DWORD style; | |
439 const DWORD directstyle = | |
440 (WS_POPUP); | |
441 const DWORD windowstyle = | |
442 (WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
443 #ifndef _WIN32_WCE |
0 | 444 const DWORD resizestyle = |
445 (WS_THICKFRAME|WS_MAXIMIZEBOX); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
446 #endif |
0 | 447 int binfo_size; |
448 BITMAPINFO *binfo; | |
449 HDC hdc; | |
450 RECT bounds; | |
451 int x, y; | |
452 BOOL was_visible; | |
453 Uint32 Rmask, Gmask, Bmask; | |
454 | |
455 /* See whether or not we should center the window */ | |
456 was_visible = IsWindowVisible(SDL_Window); | |
457 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
458 #ifdef HAVE_OPENGL |
0 | 459 /* Clean up any GL context that may be hanging around */ |
460 if ( current->flags & SDL_OPENGL ) { | |
461 WIN_GL_ShutDown(this); | |
462 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
463 #endif /* HAVE_OPENGL */ |
0 | 464 |
465 /* Recalculate the bitmasks if necessary */ | |
466 if ( bpp == current->format->BitsPerPixel ) { | |
467 video = current; | |
468 } else { | |
469 switch (bpp) { | |
470 case 15: | |
471 case 16: | |
472 if ( DIB_SussScreenDepth() == 15 ) { | |
473 /* 5-5-5 */ | |
474 Rmask = 0x00007c00; | |
475 Gmask = 0x000003e0; | |
476 Bmask = 0x0000001f; | |
477 } else { | |
478 /* 5-6-5 */ | |
479 Rmask = 0x0000f800; | |
480 Gmask = 0x000007e0; | |
481 Bmask = 0x0000001f; | |
482 } | |
483 break; | |
484 case 24: | |
485 case 32: | |
486 /* GDI defined as 8-8-8 */ | |
487 Rmask = 0x00ff0000; | |
488 Gmask = 0x0000ff00; | |
489 Bmask = 0x000000ff; | |
490 break; | |
491 default: | |
492 Rmask = 0x00000000; | |
493 Gmask = 0x00000000; | |
494 Bmask = 0x00000000; | |
495 break; | |
496 } | |
497 video = SDL_CreateRGBSurface(SDL_SWSURFACE, | |
498 0, 0, bpp, Rmask, Gmask, Bmask, 0); | |
499 if ( video == NULL ) { | |
500 SDL_OutOfMemory(); | |
501 return(NULL); | |
502 } | |
503 } | |
504 | |
505 /* Fill in part of the video surface */ | |
506 prev_flags = video->flags; | |
507 video->flags = 0; /* Clear flags */ | |
508 video->w = width; | |
509 video->h = height; | |
510 video->pitch = SDL_CalculatePitch(video); | |
511 | |
512 #ifndef NO_CHANGEDISPLAYSETTINGS | |
513 /* Set fullscreen mode if appropriate */ | |
514 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
515 DEVMODE settings; | |
516 | |
517 memset(&settings, 0, sizeof(DEVMODE)); | |
518 settings.dmSize = sizeof(DEVMODE); | |
519 settings.dmBitsPerPel = video->format->BitsPerPixel; | |
520 settings.dmPelsWidth = width; | |
521 settings.dmPelsHeight = height; | |
522 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; | |
523 if ( ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL ) { | |
524 video->flags |= SDL_FULLSCREEN; | |
525 if ( screen_pal != NULL ) { | |
526 /* RJR: March 28, 2000 | |
527 delete identity palette if switching from a palettized mode */ | |
528 DeleteObject(screen_pal); | |
529 screen_pal = NULL; | |
530 } | |
531 if ( bpp <= 8 ) | |
532 { | |
533 /* RJR: March 28, 2000 | |
534 create identity palette switching to a palettized mode */ | |
535 screen_pal = DIB_CreatePalette(bpp); | |
536 } | |
537 } | |
538 } | |
539 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
540 | |
541 style = GetWindowLong(SDL_Window, GWL_STYLE); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
542 #ifndef _WIN32_WCE |
0 | 543 style &= ~(resizestyle|WS_MAXIMIZE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
544 #endif |
0 | 545 if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { |
546 style &= ~windowstyle; | |
547 style |= directstyle; | |
548 } else { | |
549 #ifndef NO_CHANGEDISPLAYSETTINGS | |
550 if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
551 ChangeDisplaySettings(NULL, 0); | |
552 } | |
553 #endif | |
554 if ( flags & SDL_NOFRAME ) { | |
555 style &= ~windowstyle; | |
556 style |= directstyle; | |
557 video->flags |= SDL_NOFRAME; | |
558 } else { | |
559 style &= ~directstyle; | |
560 style |= windowstyle; | |
561 if ( flags & SDL_RESIZABLE ) { | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
562 #ifndef _WIN32_WCE |
0 | 563 style |= resizestyle; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
564 #endif |
0 | 565 video->flags |= SDL_RESIZABLE; |
566 } | |
567 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
568 #ifndef _WIN32_WCE |
0 | 569 if (IsZoomed(SDL_Window)) style |= WS_MAXIMIZE; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
570 #endif |
0 | 571 } |
572 SetWindowLong(SDL_Window, GWL_STYLE, style); | |
573 | |
574 /* Delete the old bitmap if necessary */ | |
575 if ( screen_bmp != NULL ) { | |
576 DeleteObject(screen_bmp); | |
577 } | |
578 if ( ! (flags & SDL_OPENGL) ) { | |
579 BOOL is16bitmode = (video->format->BytesPerPixel == 2); | |
580 | |
581 /* Suss out the bitmap info header */ | |
582 binfo_size = sizeof(*binfo); | |
583 if( is16bitmode ) { | |
584 /* 16bit modes, palette area used for rgb bitmasks */ | |
585 binfo_size += 3*sizeof(DWORD); | |
586 } else if ( video->format->palette ) { | |
587 binfo_size += video->format->palette->ncolors * | |
588 sizeof(RGBQUAD); | |
589 } | |
590 binfo = (BITMAPINFO *)malloc(binfo_size); | |
591 if ( ! binfo ) { | |
592 if ( video != current ) { | |
593 SDL_FreeSurface(video); | |
594 } | |
595 SDL_OutOfMemory(); | |
596 return(NULL); | |
597 } | |
598 | |
599 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
600 binfo->bmiHeader.biWidth = video->w; | |
601 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ | |
602 binfo->bmiHeader.biPlanes = 1; | |
603 binfo->bmiHeader.biSizeImage = video->h * video->pitch; | |
604 binfo->bmiHeader.biXPelsPerMeter = 0; | |
605 binfo->bmiHeader.biYPelsPerMeter = 0; | |
606 binfo->bmiHeader.biClrUsed = 0; | |
607 binfo->bmiHeader.biClrImportant = 0; | |
608 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; | |
609 | |
610 if ( is16bitmode ) { | |
611 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ | |
612 binfo->bmiHeader.biCompression = BI_BITFIELDS; | |
613 ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; | |
614 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; | |
615 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; | |
616 } else { | |
617 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ | |
618 if ( video->format->palette ) { | |
619 memset(binfo->bmiColors, 0, | |
620 video->format->palette->ncolors*sizeof(RGBQUAD)); | |
621 } | |
622 } | |
623 | |
624 /* Create the offscreen bitmap buffer */ | |
625 hdc = GetDC(SDL_Window); | |
626 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, | |
627 (void **)(&video->pixels), NULL, 0); | |
628 ReleaseDC(SDL_Window, hdc); | |
629 free(binfo); | |
630 if ( screen_bmp == NULL ) { | |
631 if ( video != current ) { | |
632 SDL_FreeSurface(video); | |
633 } | |
634 SDL_SetError("Couldn't create DIB section"); | |
635 return(NULL); | |
636 } | |
637 this->UpdateRects = DIB_NormalUpdate; | |
638 | |
639 /* Set video surface flags */ | |
640 if ( bpp <= 8 ) { | |
641 /* BitBlt() maps colors for us */ | |
642 video->flags |= SDL_HWPALETTE; | |
643 } | |
644 } | |
645 | |
646 /* Resize the window */ | |
647 if ( SDL_windowid == NULL ) { | |
648 UINT swp_flags; | |
649 | |
650 SDL_resizing = 1; | |
651 bounds.left = 0; | |
652 bounds.top = 0; | |
653 bounds.right = video->w; | |
654 bounds.bottom = video->h; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
655 #ifndef _WIN32_WCE |
0 | 656 AdjustWindowRect(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
657 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
658 AdjustWindowRectEx(&bounds, GetWindowLong(SDL_Window, GWL_STYLE), FALSE,0); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
659 #endif |
0 | 660 width = bounds.right-bounds.left; |
661 height = bounds.bottom-bounds.top; | |
662 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; | |
663 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; | |
664 if ( y < 0 ) { /* Cover up title bar for more client area */ | |
665 y -= GetSystemMetrics(SM_CYCAPTION)/2; | |
666 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
667 #ifndef _WIN32_WCE |
0 | 668 swp_flags = (SWP_NOCOPYBITS | SWP_NOZORDER | SWP_SHOWWINDOW); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
669 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
670 swp_flags = (SWP_NOZORDER | SWP_SHOWWINDOW); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
671 #endif |
0 | 672 if ( was_visible && !(flags & SDL_FULLSCREEN) ) { |
673 swp_flags |= SWP_NOMOVE; | |
674 } | |
675 SetWindowPos(SDL_Window, NULL, x, y, width, height, swp_flags); | |
676 SDL_resizing = 0; | |
677 SetForegroundWindow(SDL_Window); | |
678 } | |
679 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
680 #ifdef HAVE_OPENGL |
0 | 681 /* Set up for OpenGL */ |
682 if ( flags & SDL_OPENGL ) { | |
683 if ( WIN_GL_SetupWindow(this) < 0 ) { | |
684 return(NULL); | |
685 } | |
686 video->flags |= SDL_OPENGL; | |
687 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
688 #endif /* HAVE_OPENGL */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
689 |
0 | 690 /* We're live! */ |
691 return(video); | |
692 } | |
693 | |
694 /* We don't actually allow hardware surfaces in the DIB driver */ | |
695 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) | |
696 { | |
697 return(-1); | |
698 } | |
699 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) | |
700 { | |
701 return; | |
702 } | |
703 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) | |
704 { | |
705 return(0); | |
706 } | |
707 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
708 { | |
709 return; | |
710 } | |
711 | |
712 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
713 { | |
714 HDC hdc, mdc; | |
715 int i; | |
716 | |
717 hdc = GetDC(SDL_Window); | |
718 if ( screen_pal ) { | |
719 SelectPalette(hdc, screen_pal, FALSE); | |
720 } | |
721 mdc = CreateCompatibleDC(hdc); | |
722 SelectObject(mdc, screen_bmp); | |
723 for ( i=0; i<numrects; ++i ) { | |
724 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, | |
725 mdc, rects[i].x, rects[i].y, SRCCOPY); | |
726 } | |
727 DeleteDC(mdc); | |
728 ReleaseDC(SDL_Window, hdc); | |
729 } | |
730 | |
731 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
732 { | |
733 RGBQUAD *pal; | |
734 int i; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
735 #ifndef _WIN32_WCE |
0 | 736 HDC hdc, mdc; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
737 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
738 HDC hdc; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
739 #endif |
0 | 740 |
741 /* Update the display palette */ | |
742 hdc = GetDC(SDL_Window); | |
743 if ( screen_pal ) { | |
744 PALETTEENTRY *entries; | |
745 | |
746 entries = (PALETTEENTRY *)alloca(ncolors*sizeof(PALETTEENTRY)); | |
747 for ( i=0; i<ncolors; ++i ) { | |
748 entries[i].peRed = colors[i].r; | |
749 entries[i].peGreen = colors[i].g; | |
750 entries[i].peBlue = colors[i].b; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
751 #ifndef _WIN32_WCE |
0 | 752 entries[i].peFlags = PC_NOCOLLAPSE; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
753 else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
754 entries[i].peFlags = 0; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
755 #endif |
0 | 756 } |
757 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries); | |
758 SelectPalette(hdc, screen_pal, FALSE); | |
759 RealizePalette(hdc); | |
760 } | |
761 | |
762 /* Copy palette colors into DIB palette */ | |
763 pal = (RGBQUAD *)alloca(ncolors*sizeof(RGBQUAD)); | |
764 for ( i=0; i<ncolors; ++i ) { | |
765 pal[i].rgbRed = colors[i].r; | |
766 pal[i].rgbGreen = colors[i].g; | |
767 pal[i].rgbBlue = colors[i].b; | |
768 pal[i].rgbReserved = 0; | |
769 } | |
770 | |
771 /* Set the DIB palette and update the display */ | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
772 #ifndef _WIN32_WCE |
0 | 773 mdc = CreateCompatibleDC(hdc); |
774 SelectObject(mdc, screen_bmp); | |
775 SetDIBColorTable(mdc, firstcolor, ncolors, pal); | |
776 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, | |
777 mdc, 0, 0, SRCCOPY); | |
778 DeleteDC(mdc); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
779 #endif |
0 | 780 ReleaseDC(SDL_Window, hdc); |
781 return(1); | |
782 } | |
783 | |
784 static void DIB_CheckGamma(_THIS) | |
785 { | |
786 #ifndef NO_GAMMA_SUPPORT | |
787 HDC hdc; | |
788 WORD ramp[3*256]; | |
789 | |
790 /* If we fail to get gamma, disable gamma control */ | |
791 hdc = GetDC(SDL_Window); | |
792 if ( ! GetDeviceGammaRamp(hdc, ramp) ) { | |
793 this->GetGammaRamp = NULL; | |
794 this->SetGammaRamp = NULL; | |
795 } | |
796 ReleaseDC(SDL_Window, hdc); | |
797 #endif /* !NO_GAMMA_SUPPORT */ | |
798 } | |
799 static void DIB_SwapGamma(_THIS) | |
800 { | |
801 #ifndef NO_GAMMA_SUPPORT | |
802 HDC hdc; | |
803 | |
804 if ( gamma_saved ) { | |
805 hdc = GetDC(SDL_Window); | |
806 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
807 /* About to leave active state, restore gamma */ | |
808 SetDeviceGammaRamp(hdc, gamma_saved); | |
809 } else { | |
810 /* About to enter active state, set game gamma */ | |
811 GetDeviceGammaRamp(hdc, gamma_saved); | |
812 SetDeviceGammaRamp(hdc, this->gamma); | |
813 } | |
814 ReleaseDC(SDL_Window, hdc); | |
815 } | |
816 #endif /* !NO_GAMMA_SUPPORT */ | |
817 } | |
818 static void DIB_QuitGamma(_THIS) | |
819 { | |
820 #ifndef NO_GAMMA_SUPPORT | |
821 if ( gamma_saved ) { | |
822 /* Restore the original gamma if necessary */ | |
823 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
824 HDC hdc; | |
825 | |
826 hdc = GetDC(SDL_Window); | |
827 SetDeviceGammaRamp(hdc, gamma_saved); | |
828 ReleaseDC(SDL_Window, hdc); | |
829 } | |
830 | |
831 /* Free the saved gamma memory */ | |
832 free(gamma_saved); | |
833 gamma_saved = 0; | |
834 } | |
835 #endif /* !NO_GAMMA_SUPPORT */ | |
836 } | |
837 | |
838 #ifndef NO_GAMMA_SUPPORT | |
839 | |
840 static int DIB_SetGammaRamp(_THIS, Uint16 *ramp) | |
841 { | |
842 HDC hdc; | |
843 BOOL succeeded; | |
844 | |
845 /* Set the ramp for the display */ | |
846 if ( ! gamma_saved ) { | |
847 gamma_saved = (WORD *)malloc(3*256*sizeof(*gamma_saved)); | |
848 if ( ! gamma_saved ) { | |
849 SDL_OutOfMemory(); | |
850 return -1; | |
851 } | |
852 hdc = GetDC(SDL_Window); | |
853 GetDeviceGammaRamp(hdc, gamma_saved); | |
854 ReleaseDC(SDL_Window, hdc); | |
855 } | |
856 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
857 hdc = GetDC(SDL_Window); | |
858 succeeded = SetDeviceGammaRamp(hdc, ramp); | |
859 ReleaseDC(SDL_Window, hdc); | |
860 } else { | |
861 succeeded = TRUE; | |
862 } | |
863 return succeeded ? 0 : -1; | |
864 } | |
865 | |
866 static int DIB_GetGammaRamp(_THIS, Uint16 *ramp) | |
867 { | |
868 HDC hdc; | |
869 BOOL succeeded; | |
870 | |
871 /* Get the ramp from the display */ | |
872 hdc = GetDC(SDL_Window); | |
873 succeeded = GetDeviceGammaRamp(hdc, ramp); | |
874 ReleaseDC(SDL_Window, hdc); | |
875 return succeeded ? 0 : -1; | |
876 } | |
877 | |
878 #endif /* !NO_GAMMA_SUPPORT */ | |
879 | |
880 void DIB_VideoQuit(_THIS) | |
881 { | |
882 /* Destroy the window and everything associated with it */ | |
883 if ( SDL_Window ) { | |
884 /* Delete the screen bitmap (also frees screen->pixels) */ | |
885 if ( this->screen ) { | |
886 #ifndef NO_CHANGEDISPLAYSETTINGS | |
887 if ( this->screen->flags & SDL_FULLSCREEN ) { | |
888 ChangeDisplaySettings(NULL, 0); | |
889 } | |
890 #endif | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
891 #ifdef HAVE_OPENGL |
0 | 892 if ( this->screen->flags & SDL_OPENGL ) { |
893 WIN_GL_ShutDown(this); | |
894 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
895 #endif /* HAVE_OPENGL */ |
0 | 896 this->screen->pixels = NULL; |
897 } | |
898 if ( screen_bmp ) { | |
899 DeleteObject(screen_bmp); | |
900 screen_bmp = NULL; | |
901 } | |
902 if ( screen_icn ) { | |
903 DestroyIcon(screen_icn); | |
904 screen_icn = NULL; | |
905 } | |
906 DIB_QuitGamma(this); | |
907 DIB_DestroyWindow(this); | |
908 | |
909 SDL_Window = NULL; | |
910 } | |
911 } | |
912 | |
913 /* Exported for the windows message loop only */ | |
914 static void DIB_FocusPalette(_THIS, int foreground) | |
915 { | |
916 if ( screen_pal != NULL ) { | |
917 HDC hdc; | |
918 | |
919 hdc = GetDC(SDL_Window); | |
920 SelectPalette(hdc, screen_pal, FALSE); | |
921 if ( RealizePalette(hdc) ) | |
922 InvalidateRect(SDL_Window, NULL, FALSE); | |
923 ReleaseDC(SDL_Window, hdc); | |
924 } | |
925 } | |
926 static void DIB_RealizePalette(_THIS) | |
927 { | |
928 DIB_FocusPalette(this, 1); | |
929 } | |
930 static void DIB_PaletteChanged(_THIS, HWND window) | |
931 { | |
932 if ( window != SDL_Window ) { | |
933 DIB_FocusPalette(this, 0); | |
934 } | |
935 } | |
936 | |
937 /* Exported for the windows message loop only */ | |
938 static void DIB_WinPAINT(_THIS, HDC hdc) | |
939 { | |
940 HDC mdc; | |
941 | |
942 if ( screen_pal ) { | |
943 SelectPalette(hdc, screen_pal, FALSE); | |
944 } | |
945 mdc = CreateCompatibleDC(hdc); | |
946 SelectObject(mdc, screen_bmp); | |
947 BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h, | |
948 mdc, 0, 0, SRCCOPY); | |
949 DeleteDC(mdc); | |
950 } | |
951 | |
952 /* Stub in case DirectX isn't available */ | |
953 #ifndef ENABLE_DIRECTX | |
954 void DX5_SoundFocus(HWND hwnd) | |
955 { | |
956 return; | |
957 } | |
958 #endif |