Mercurial > sdl-ios-xcode
annotate src/video/windib/SDL_dibvideo.c @ 340:b9f1ce709960
Fixed a minor memory leak in the SDL thread subsystem
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Thu, 11 Apr 2002 21:08:44 +0000 |
parents | 518ffd98a8f6 |
children | 3fc4e71f7714 |
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 | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
169
diff
changeset
|
20 slouken@libsdl.org |
0 | 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); | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
64 void DIB_SwapGamma(_THIS); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
65 void DIB_QuitGamma(_THIS); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
66 int DIB_SetGammaRamp(_THIS, Uint16 *ramp); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
67 int DIB_GetGammaRamp(_THIS, Uint16 *ramp); |
0 | 68 static void DIB_VideoQuit(_THIS); |
69 | |
70 /* Hardware surface functions */ | |
71 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface); | |
72 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface); | |
73 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
74 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface); | |
75 | |
76 /* Windows message handling functions */ | |
77 static void DIB_RealizePalette(_THIS); | |
78 static void DIB_PaletteChanged(_THIS, HWND window); | |
79 static void DIB_WinPAINT(_THIS, HDC hdc); | |
80 | |
81 /* helper fn */ | |
82 static int DIB_SussScreenDepth(); | |
83 | |
84 /* DIB driver bootstrap functions */ | |
85 | |
86 static int DIB_Available(void) | |
87 { | |
88 return(1); | |
89 } | |
90 | |
91 static void DIB_DeleteDevice(SDL_VideoDevice *device) | |
92 { | |
93 if ( device ) { | |
94 if ( device->hidden ) { | |
95 free(device->hidden); | |
96 } | |
97 if ( device->gl_data ) { | |
98 free(device->gl_data); | |
99 } | |
100 free(device); | |
101 } | |
102 } | |
103 | |
104 static SDL_VideoDevice *DIB_CreateDevice(int devindex) | |
105 { | |
106 SDL_VideoDevice *device; | |
107 | |
108 /* Initialize all variables that we clean on shutdown */ | |
109 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
110 if ( device ) { | |
111 memset(device, 0, (sizeof *device)); | |
112 device->hidden = (struct SDL_PrivateVideoData *) | |
113 malloc((sizeof *device->hidden)); | |
114 device->gl_data = (struct SDL_PrivateGLData *) | |
115 malloc((sizeof *device->gl_data)); | |
116 } | |
117 if ( (device == NULL) || (device->hidden == NULL) || | |
118 (device->gl_data == NULL) ) { | |
119 SDL_OutOfMemory(); | |
120 DIB_DeleteDevice(device); | |
121 return(NULL); | |
122 } | |
123 memset(device->hidden, 0, (sizeof *device->hidden)); | |
124 memset(device->gl_data, 0, (sizeof *device->gl_data)); | |
125 | |
126 /* Set the function pointers */ | |
127 device->VideoInit = DIB_VideoInit; | |
128 device->ListModes = DIB_ListModes; | |
129 device->SetVideoMode = DIB_SetVideoMode; | |
130 device->UpdateMouse = WIN_UpdateMouse; | |
131 device->SetColors = DIB_SetColors; | |
132 device->UpdateRects = NULL; | |
133 device->VideoQuit = DIB_VideoQuit; | |
134 device->AllocHWSurface = DIB_AllocHWSurface; | |
135 device->CheckHWBlit = NULL; | |
136 device->FillHWRect = NULL; | |
137 device->SetHWColorKey = NULL; | |
138 device->SetHWAlpha = NULL; | |
139 device->LockHWSurface = DIB_LockHWSurface; | |
140 device->UnlockHWSurface = DIB_UnlockHWSurface; | |
141 device->FlipHWSurface = NULL; | |
142 device->FreeHWSurface = DIB_FreeHWSurface; | |
143 device->SetGammaRamp = DIB_SetGammaRamp; | |
144 device->GetGammaRamp = DIB_GetGammaRamp; | |
145 #ifdef HAVE_OPENGL | |
146 device->GL_LoadLibrary = WIN_GL_LoadLibrary; | |
147 device->GL_GetProcAddress = WIN_GL_GetProcAddress; | |
148 device->GL_GetAttribute = WIN_GL_GetAttribute; | |
149 device->GL_MakeCurrent = WIN_GL_MakeCurrent; | |
150 device->GL_SwapBuffers = WIN_GL_SwapBuffers; | |
151 #endif | |
152 device->SetCaption = WIN_SetWMCaption; | |
153 device->SetIcon = WIN_SetWMIcon; | |
154 device->IconifyWindow = WIN_IconifyWindow; | |
155 device->GrabInput = WIN_GrabInput; | |
156 device->GetWMInfo = WIN_GetWMInfo; | |
157 device->FreeWMCursor = WIN_FreeWMCursor; | |
158 device->CreateWMCursor = WIN_CreateWMCursor; | |
159 device->ShowWMCursor = WIN_ShowWMCursor; | |
160 device->WarpWMCursor = WIN_WarpWMCursor; | |
161 device->CheckMouseMode = WIN_CheckMouseMode; | |
162 device->InitOSKeymap = DIB_InitOSKeymap; | |
163 device->PumpEvents = DIB_PumpEvents; | |
164 | |
165 /* Set up the windows message handling functions */ | |
166 WIN_RealizePalette = DIB_RealizePalette; | |
167 WIN_PaletteChanged = DIB_PaletteChanged; | |
168 WIN_WinPAINT = DIB_WinPAINT; | |
169 HandleMessage = DIB_HandleMessage; | |
170 | |
171 device->free = DIB_DeleteDevice; | |
172 | |
173 /* We're finally ready */ | |
174 return device; | |
175 } | |
176 | |
177 VideoBootStrap WINDIB_bootstrap = { | |
178 "windib", "Win95/98/NT/2000 GDI", | |
179 DIB_Available, DIB_CreateDevice | |
180 }; | |
181 | |
182 #ifndef NO_CHANGEDISPLAYSETTINGS | |
183 | |
184 static int cmpmodes(const void *va, const void *vb) | |
185 { | |
186 SDL_Rect *a = *(SDL_Rect **)va; | |
187 SDL_Rect *b = *(SDL_Rect **)vb; | |
188 if(a->w > b->w) | |
189 return -1; | |
190 return b->h - a->h; | |
191 } | |
192 | |
193 static int DIB_AddMode(_THIS, int bpp, int w, int h) | |
194 { | |
195 SDL_Rect *mode; | |
196 int i, index; | |
197 int next_mode; | |
198 | |
199 /* Check to see if we already have this mode */ | |
200 if ( bpp < 8 ) { /* Not supported */ | |
201 return(0); | |
202 } | |
203 index = ((bpp+7)/8)-1; | |
204 for ( i=0; i<SDL_nummodes[index]; ++i ) { | |
205 mode = SDL_modelist[index][i]; | |
206 if ( (mode->w == w) && (mode->h == h) ) { | |
207 return(0); | |
208 } | |
209 } | |
210 | |
211 /* Set up the new video mode rectangle */ | |
212 mode = (SDL_Rect *)malloc(sizeof *mode); | |
213 if ( mode == NULL ) { | |
214 SDL_OutOfMemory(); | |
215 return(-1); | |
216 } | |
217 mode->x = 0; | |
218 mode->y = 0; | |
219 mode->w = w; | |
220 mode->h = h; | |
221 | |
222 /* Allocate the new list of modes, and fill in the new mode */ | |
223 next_mode = SDL_nummodes[index]; | |
224 SDL_modelist[index] = (SDL_Rect **) | |
225 realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); | |
226 if ( SDL_modelist[index] == NULL ) { | |
227 SDL_OutOfMemory(); | |
228 SDL_nummodes[index] = 0; | |
229 free(mode); | |
230 return(-1); | |
231 } | |
232 SDL_modelist[index][next_mode] = mode; | |
233 SDL_modelist[index][next_mode+1] = NULL; | |
234 SDL_nummodes[index]++; | |
235 | |
236 return(0); | |
237 } | |
238 | |
239 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
240 | |
241 static HPALETTE DIB_CreatePalette(int bpp) | |
242 { | |
243 /* RJR: March 28, 2000 | |
244 moved palette creation here from "DIB_VideoInit" */ | |
245 | |
246 HPALETTE handle = NULL; | |
247 | |
248 if ( bpp <= 8 ) | |
249 { | |
250 LOGPALETTE *palette; | |
251 HDC hdc; | |
252 int ncolors; | |
253 int i; | |
254 | |
255 ncolors = 1; | |
256 for ( i=0; i<bpp; ++i ) { | |
257 ncolors *= 2; | |
258 } | |
259 palette = (LOGPALETTE *)malloc(sizeof(*palette)+ | |
260 ncolors*sizeof(PALETTEENTRY)); | |
261 palette->palVersion = 0x300; | |
262 palette->palNumEntries = ncolors; | |
263 hdc = GetDC(SDL_Window); | |
264 GetSystemPaletteEntries(hdc, 0, ncolors, palette->palPalEntry); | |
265 ReleaseDC(SDL_Window, hdc); | |
266 handle = CreatePalette(palette); | |
267 free(palette); | |
268 } | |
269 | |
270 return handle; | |
271 } | |
272 | |
273 int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
274 { | |
275 #ifndef NO_CHANGEDISPLAYSETTINGS | |
276 int i; | |
277 DEVMODE settings; | |
278 #endif | |
279 | |
280 /* Create the window */ | |
281 if ( DIB_CreateWindow(this) < 0 ) { | |
282 return(-1); | |
283 } | |
169
8039a5b760b9
Allow building SDL on Windows without audio support
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
284 #ifndef DISABLE_AUDIO |
0 | 285 DX5_SoundFocus(SDL_Window); |
169
8039a5b760b9
Allow building SDL on Windows without audio support
Sam Lantinga <slouken@libsdl.org>
parents:
145
diff
changeset
|
286 #endif |
0 | 287 |
288 /* Determine the screen depth */ | |
289 vformat->BitsPerPixel = DIB_SussScreenDepth(); | |
290 switch (vformat->BitsPerPixel) { | |
291 case 15: | |
292 vformat->Rmask = 0x00007c00; | |
293 vformat->Gmask = 0x000003e0; | |
294 vformat->Bmask = 0x0000001f; | |
295 vformat->BitsPerPixel = 16; | |
296 break; | |
297 case 16: | |
298 vformat->Rmask = 0x0000f800; | |
299 vformat->Gmask = 0x000007e0; | |
300 vformat->Bmask = 0x0000001f; | |
301 break; | |
302 case 24: | |
303 case 32: | |
304 /* GDI defined as 8-8-8 */ | |
305 vformat->Rmask = 0x00ff0000; | |
306 vformat->Gmask = 0x0000ff00; | |
307 vformat->Bmask = 0x000000ff; | |
308 break; | |
309 default: | |
310 break; | |
311 } | |
312 | |
313 /* See if gamma is supported on this screen */ | |
314 DIB_CheckGamma(this); | |
315 | |
316 #ifndef NO_CHANGEDISPLAYSETTINGS | |
317 /* Query for the list of available video modes */ | |
318 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { | |
319 DIB_AddMode(this, settings.dmBitsPerPel, | |
320 settings.dmPelsWidth, settings.dmPelsHeight); | |
321 } | |
322 /* Sort the mode lists */ | |
323 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
324 if ( SDL_nummodes[i] > 0 ) { | |
325 qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); | |
326 } | |
327 } | |
328 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
329 | |
330 /* Grab an identity palette if we are in a palettized mode */ | |
331 if ( vformat->BitsPerPixel <= 8 ) { | |
332 /* RJR: March 28, 2000 | |
333 moved palette creation to "DIB_CreatePalette" */ | |
334 screen_pal = DIB_CreatePalette(vformat->BitsPerPixel); | |
335 } | |
336 | |
337 /* Fill in some window manager capabilities */ | |
338 this->info.wm_available = 1; | |
339 | |
340 /* We're done! */ | |
341 return(0); | |
342 } | |
343 | |
344 /* We support any format at any dimension */ | |
345 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
346 { | |
347 #ifdef NO_CHANGEDISPLAYSETTINGS | |
348 return((SDL_Rect **)-1); | |
349 #else | |
350 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
351 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
352 } else { | |
353 return((SDL_Rect **)-1); | |
354 } | |
355 #endif | |
356 } | |
357 | |
358 | |
359 /* | |
360 Helper fn to work out which screen depth windows is currently using. | |
361 15 bit mode is considered 555 format, 16 bit is 565. | |
362 returns 0 for unknown mode. | |
363 (Derived from code in sept 1999 Windows Developer Journal | |
364 http://www.wdj.com/code/archive.html) | |
365 */ | |
366 static int DIB_SussScreenDepth() | |
367 { | |
368 #ifdef NO_GETDIBITS | |
369 int depth; | |
370 HDC hdc; | |
371 | |
372 hdc = GetDC(SDL_Window); | |
373 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL); | |
374 ReleaseDC(SDL_Window, hdc); | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
46
diff
changeset
|
375 #ifndef _WIN32_WCE |
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
46
diff
changeset
|
376 // AFAIK 16 bit CE devices have indeed RGB 565 |
0 | 377 if ( depth == 16 ) { |
378 depth = 15; /* GDI defined as RGB 555 */ | |
379 } | |
112
9ef74357a5fb
Incorporated slightly modified version of Rainer's WinCE patch
Sam Lantinga <slouken@lokigames.com>
parents:
46
diff
changeset
|
380 #endif |
0 | 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; | |
304
ec53caed9fb2
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
525 SDL_fullscreen_mode = settings; |
0 | 526 } |
527 } | |
528 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
529 | |
45
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
530 /* Reset the palette and create a new one if necessary */ |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
531 if ( screen_pal != NULL ) { |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
532 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
533 delete identity palette if switching from a palettized mode */ |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
534 DeleteObject(screen_pal); |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
535 screen_pal = NULL; |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
536 } |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
537 if ( bpp <= 8 ) |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
538 { |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
539 /* RJR: March 28, 2000 |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
540 create identity palette switching to a palettized mode */ |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
541 screen_pal = DIB_CreatePalette(bpp); |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
542 } |
60a6e045808e
Fix palette creation in windowed mode at 8 bpp
Sam Lantinga <slouken@lokigames.com>
parents:
36
diff
changeset
|
543 |
0 | 544 style = GetWindowLong(SDL_Window, GWL_STYLE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
545 #ifndef _WIN32_WCE |
0 | 546 style &= ~(resizestyle|WS_MAXIMIZE); |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
547 #endif |
0 | 548 if ( (video->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { |
549 style &= ~windowstyle; | |
550 style |= directstyle; | |
551 } else { | |
552 #ifndef NO_CHANGEDISPLAYSETTINGS | |
553 if ( (prev_flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
554 ChangeDisplaySettings(NULL, 0); | |
555 } | |
556 #endif | |
557 if ( flags & SDL_NOFRAME ) { | |
558 style &= ~windowstyle; | |
559 style |= directstyle; | |
560 video->flags |= SDL_NOFRAME; | |
561 } else { | |
562 style &= ~directstyle; | |
563 style |= windowstyle; | |
564 if ( flags & SDL_RESIZABLE ) { | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
565 #ifndef _WIN32_WCE |
0 | 566 style |= resizestyle; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
567 #endif |
0 | 568 video->flags |= SDL_RESIZABLE; |
569 } | |
570 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
571 #ifndef _WIN32_WCE |
0 | 572 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
|
573 #endif |
0 | 574 } |
145
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
575 |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
576 /* DJM: Don't piss of anyone who has setup his own window */ |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
577 if (!SDL_windowid) |
29a638dc26db
Applied David MacCormack's patch to fix SDL_WINDOWID on Windows,
Sam Lantinga <slouken@libsdl.org>
parents:
112
diff
changeset
|
578 SetWindowLong(SDL_Window, GWL_STYLE, style); |
0 | 579 |
580 /* Delete the old bitmap if necessary */ | |
581 if ( screen_bmp != NULL ) { | |
582 DeleteObject(screen_bmp); | |
583 } | |
584 if ( ! (flags & SDL_OPENGL) ) { | |
585 BOOL is16bitmode = (video->format->BytesPerPixel == 2); | |
586 | |
587 /* Suss out the bitmap info header */ | |
588 binfo_size = sizeof(*binfo); | |
589 if( is16bitmode ) { | |
590 /* 16bit modes, palette area used for rgb bitmasks */ | |
591 binfo_size += 3*sizeof(DWORD); | |
592 } else if ( video->format->palette ) { | |
593 binfo_size += video->format->palette->ncolors * | |
594 sizeof(RGBQUAD); | |
595 } | |
596 binfo = (BITMAPINFO *)malloc(binfo_size); | |
597 if ( ! binfo ) { | |
598 if ( video != current ) { | |
599 SDL_FreeSurface(video); | |
600 } | |
601 SDL_OutOfMemory(); | |
602 return(NULL); | |
603 } | |
604 | |
605 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); | |
606 binfo->bmiHeader.biWidth = video->w; | |
607 binfo->bmiHeader.biHeight = -video->h; /* -ve for topdown bitmap */ | |
608 binfo->bmiHeader.biPlanes = 1; | |
609 binfo->bmiHeader.biSizeImage = video->h * video->pitch; | |
610 binfo->bmiHeader.biXPelsPerMeter = 0; | |
611 binfo->bmiHeader.biYPelsPerMeter = 0; | |
612 binfo->bmiHeader.biClrUsed = 0; | |
613 binfo->bmiHeader.biClrImportant = 0; | |
614 binfo->bmiHeader.biBitCount = video->format->BitsPerPixel; | |
615 | |
616 if ( is16bitmode ) { | |
617 /* BI_BITFIELDS tells CreateDIBSection about the rgb masks in the palette */ | |
618 binfo->bmiHeader.biCompression = BI_BITFIELDS; | |
619 ((Uint32*)binfo->bmiColors)[0] = video->format->Rmask; | |
620 ((Uint32*)binfo->bmiColors)[1] = video->format->Gmask; | |
621 ((Uint32*)binfo->bmiColors)[2] = video->format->Bmask; | |
622 } else { | |
623 binfo->bmiHeader.biCompression = BI_RGB; /* BI_BITFIELDS for 565 vs 555 */ | |
624 if ( video->format->palette ) { | |
625 memset(binfo->bmiColors, 0, | |
626 video->format->palette->ncolors*sizeof(RGBQUAD)); | |
627 } | |
628 } | |
629 | |
630 /* Create the offscreen bitmap buffer */ | |
631 hdc = GetDC(SDL_Window); | |
632 screen_bmp = CreateDIBSection(hdc, binfo, DIB_RGB_COLORS, | |
633 (void **)(&video->pixels), NULL, 0); | |
634 ReleaseDC(SDL_Window, hdc); | |
635 free(binfo); | |
636 if ( screen_bmp == NULL ) { | |
637 if ( video != current ) { | |
638 SDL_FreeSurface(video); | |
639 } | |
640 SDL_SetError("Couldn't create DIB section"); | |
641 return(NULL); | |
642 } | |
643 this->UpdateRects = DIB_NormalUpdate; | |
644 | |
645 /* Set video surface flags */ | |
646 if ( bpp <= 8 ) { | |
647 /* BitBlt() maps colors for us */ | |
648 video->flags |= SDL_HWPALETTE; | |
649 } | |
650 } | |
651 | |
652 /* Resize the window */ | |
653 if ( SDL_windowid == NULL ) { | |
654 UINT swp_flags; | |
655 | |
656 SDL_resizing = 1; | |
657 bounds.left = 0; | |
658 bounds.top = 0; | |
659 bounds.right = video->w; | |
660 bounds.bottom = video->h; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
661 #ifndef _WIN32_WCE |
0 | 662 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
|
663 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
664 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
|
665 #endif |
0 | 666 width = bounds.right-bounds.left; |
667 height = bounds.bottom-bounds.top; | |
668 x = (GetSystemMetrics(SM_CXSCREEN)-width)/2; | |
669 y = (GetSystemMetrics(SM_CYSCREEN)-height)/2; | |
670 if ( y < 0 ) { /* Cover up title bar for more client area */ | |
671 y -= GetSystemMetrics(SM_CYCAPTION)/2; | |
672 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
673 #ifndef _WIN32_WCE |
0 | 674 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
|
675 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
676 swp_flags = (SWP_NOZORDER | SWP_SHOWWINDOW); |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
677 #endif |
0 | 678 if ( was_visible && !(flags & SDL_FULLSCREEN) ) { |
679 swp_flags |= SWP_NOMOVE; | |
680 } | |
681 SetWindowPos(SDL_Window, NULL, x, y, width, height, swp_flags); | |
682 SDL_resizing = 0; | |
683 SetForegroundWindow(SDL_Window); | |
684 } | |
685 | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
686 #ifdef HAVE_OPENGL |
0 | 687 /* Set up for OpenGL */ |
688 if ( flags & SDL_OPENGL ) { | |
689 if ( WIN_GL_SetupWindow(this) < 0 ) { | |
690 return(NULL); | |
691 } | |
692 video->flags |= SDL_OPENGL; | |
693 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
694 #endif /* HAVE_OPENGL */ |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
695 |
0 | 696 /* We're live! */ |
697 return(video); | |
698 } | |
699 | |
700 /* We don't actually allow hardware surfaces in the DIB driver */ | |
701 static int DIB_AllocHWSurface(_THIS, SDL_Surface *surface) | |
702 { | |
703 return(-1); | |
704 } | |
705 static void DIB_FreeHWSurface(_THIS, SDL_Surface *surface) | |
706 { | |
707 return; | |
708 } | |
709 static int DIB_LockHWSurface(_THIS, SDL_Surface *surface) | |
710 { | |
711 return(0); | |
712 } | |
713 static void DIB_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
714 { | |
715 return; | |
716 } | |
717 | |
718 static void DIB_NormalUpdate(_THIS, int numrects, SDL_Rect *rects) | |
719 { | |
720 HDC hdc, mdc; | |
721 int i; | |
722 | |
723 hdc = GetDC(SDL_Window); | |
724 if ( screen_pal ) { | |
725 SelectPalette(hdc, screen_pal, FALSE); | |
726 } | |
727 mdc = CreateCompatibleDC(hdc); | |
728 SelectObject(mdc, screen_bmp); | |
729 for ( i=0; i<numrects; ++i ) { | |
730 BitBlt(hdc, rects[i].x, rects[i].y, rects[i].w, rects[i].h, | |
731 mdc, rects[i].x, rects[i].y, SRCCOPY); | |
732 } | |
733 DeleteDC(mdc); | |
734 ReleaseDC(SDL_Window, hdc); | |
735 } | |
736 | |
737 int DIB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
738 { | |
739 RGBQUAD *pal; | |
740 int i; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
741 #ifndef _WIN32_WCE |
0 | 742 HDC hdc, mdc; |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
743 #else |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
744 HDC hdc; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
745 #endif |
0 | 746 |
747 /* Update the display palette */ | |
748 hdc = GetDC(SDL_Window); | |
749 if ( screen_pal ) { | |
750 PALETTEENTRY *entries; | |
751 | |
752 entries = (PALETTEENTRY *)alloca(ncolors*sizeof(PALETTEENTRY)); | |
753 for ( i=0; i<ncolors; ++i ) { | |
754 entries[i].peRed = colors[i].r; | |
755 entries[i].peGreen = colors[i].g; | |
756 entries[i].peBlue = colors[i].b; | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
757 #ifndef _WIN32_WCE |
0 | 758 entries[i].peFlags = PC_NOCOLLAPSE; |
46
3dcf26fa9d15
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
45
diff
changeset
|
759 #else |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
760 entries[i].peFlags = 0; |
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
761 #endif |
0 | 762 } |
763 SetPaletteEntries(screen_pal, firstcolor, ncolors, entries); | |
764 SelectPalette(hdc, screen_pal, FALSE); | |
765 RealizePalette(hdc); | |
766 } | |
767 | |
768 /* Copy palette colors into DIB palette */ | |
769 pal = (RGBQUAD *)alloca(ncolors*sizeof(RGBQUAD)); | |
770 for ( i=0; i<ncolors; ++i ) { | |
771 pal[i].rgbRed = colors[i].r; | |
772 pal[i].rgbGreen = colors[i].g; | |
773 pal[i].rgbBlue = colors[i].b; | |
774 pal[i].rgbReserved = 0; | |
775 } | |
776 | |
777 /* 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
|
778 #ifndef _WIN32_WCE |
0 | 779 mdc = CreateCompatibleDC(hdc); |
780 SelectObject(mdc, screen_bmp); | |
781 SetDIBColorTable(mdc, firstcolor, ncolors, pal); | |
782 BitBlt(hdc, 0, 0, this->screen->w, this->screen->h, | |
783 mdc, 0, 0, SRCCOPY); | |
784 DeleteDC(mdc); | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
785 #endif |
0 | 786 ReleaseDC(SDL_Window, hdc); |
787 return(1); | |
788 } | |
789 | |
790 static void DIB_CheckGamma(_THIS) | |
791 { | |
792 #ifndef NO_GAMMA_SUPPORT | |
793 HDC hdc; | |
794 WORD ramp[3*256]; | |
795 | |
796 /* If we fail to get gamma, disable gamma control */ | |
797 hdc = GetDC(SDL_Window); | |
798 if ( ! GetDeviceGammaRamp(hdc, ramp) ) { | |
799 this->GetGammaRamp = NULL; | |
800 this->SetGammaRamp = NULL; | |
801 } | |
802 ReleaseDC(SDL_Window, hdc); | |
803 #endif /* !NO_GAMMA_SUPPORT */ | |
804 } | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
805 void DIB_SwapGamma(_THIS) |
0 | 806 { |
807 #ifndef NO_GAMMA_SUPPORT | |
808 HDC hdc; | |
809 | |
810 if ( gamma_saved ) { | |
811 hdc = GetDC(SDL_Window); | |
812 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
813 /* About to leave active state, restore gamma */ | |
814 SetDeviceGammaRamp(hdc, gamma_saved); | |
815 } else { | |
816 /* About to enter active state, set game gamma */ | |
817 GetDeviceGammaRamp(hdc, gamma_saved); | |
818 SetDeviceGammaRamp(hdc, this->gamma); | |
819 } | |
820 ReleaseDC(SDL_Window, hdc); | |
821 } | |
822 #endif /* !NO_GAMMA_SUPPORT */ | |
823 } | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
824 void DIB_QuitGamma(_THIS) |
0 | 825 { |
826 #ifndef NO_GAMMA_SUPPORT | |
827 if ( gamma_saved ) { | |
828 /* Restore the original gamma if necessary */ | |
829 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
830 HDC hdc; | |
831 | |
832 hdc = GetDC(SDL_Window); | |
833 SetDeviceGammaRamp(hdc, gamma_saved); | |
834 ReleaseDC(SDL_Window, hdc); | |
835 } | |
836 | |
837 /* Free the saved gamma memory */ | |
838 free(gamma_saved); | |
839 gamma_saved = 0; | |
840 } | |
841 #endif /* !NO_GAMMA_SUPPORT */ | |
842 } | |
843 | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
844 int DIB_SetGammaRamp(_THIS, Uint16 *ramp) |
0 | 845 { |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
846 #ifdef NO_GAMMA_SUPPORT |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
847 SDL_SetError("SDL compiled without gamma ramp support"); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
848 return -1; |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
849 #else |
0 | 850 HDC hdc; |
851 BOOL succeeded; | |
852 | |
853 /* Set the ramp for the display */ | |
854 if ( ! gamma_saved ) { | |
855 gamma_saved = (WORD *)malloc(3*256*sizeof(*gamma_saved)); | |
856 if ( ! gamma_saved ) { | |
857 SDL_OutOfMemory(); | |
858 return -1; | |
859 } | |
860 hdc = GetDC(SDL_Window); | |
861 GetDeviceGammaRamp(hdc, gamma_saved); | |
862 ReleaseDC(SDL_Window, hdc); | |
863 } | |
864 if ( SDL_GetAppState() & SDL_APPINPUTFOCUS ) { | |
865 hdc = GetDC(SDL_Window); | |
866 succeeded = SetDeviceGammaRamp(hdc, ramp); | |
867 ReleaseDC(SDL_Window, hdc); | |
868 } else { | |
869 succeeded = TRUE; | |
870 } | |
871 return succeeded ? 0 : -1; | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
872 #endif /* !NO_GAMMA_SUPPORT */ |
0 | 873 } |
874 | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
875 int DIB_GetGammaRamp(_THIS, Uint16 *ramp) |
0 | 876 { |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
877 #ifdef NO_GAMMA_SUPPORT |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
878 SDL_SetError("SDL compiled without gamma ramp support"); |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
879 return -1; |
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
880 #else |
0 | 881 HDC hdc; |
882 BOOL succeeded; | |
883 | |
884 /* Get the ramp from the display */ | |
885 hdc = GetDC(SDL_Window); | |
886 succeeded = GetDeviceGammaRamp(hdc, ramp); | |
887 ReleaseDC(SDL_Window, hdc); | |
888 return succeeded ? 0 : -1; | |
338
518ffd98a8f6
Fixed gamma ramps in DirectX windowed and OpenGL modes
Sam Lantinga <slouken@libsdl.org>
parents:
304
diff
changeset
|
889 #endif /* !NO_GAMMA_SUPPORT */ |
0 | 890 } |
891 | |
892 void DIB_VideoQuit(_THIS) | |
893 { | |
894 /* Destroy the window and everything associated with it */ | |
895 if ( SDL_Window ) { | |
896 /* Delete the screen bitmap (also frees screen->pixels) */ | |
897 if ( this->screen ) { | |
898 #ifndef NO_CHANGEDISPLAYSETTINGS | |
899 if ( this->screen->flags & SDL_FULLSCREEN ) { | |
900 ChangeDisplaySettings(NULL, 0); | |
901 } | |
902 #endif | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
903 #ifdef HAVE_OPENGL |
0 | 904 if ( this->screen->flags & SDL_OPENGL ) { |
905 WIN_GL_ShutDown(this); | |
906 } | |
36
13ee9f4834ea
Windows CE patches contributed by Rainer Loritz
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
907 #endif /* HAVE_OPENGL */ |
0 | 908 this->screen->pixels = NULL; |
909 } | |
910 if ( screen_bmp ) { | |
911 DeleteObject(screen_bmp); | |
912 screen_bmp = NULL; | |
913 } | |
914 if ( screen_icn ) { | |
915 DestroyIcon(screen_icn); | |
916 screen_icn = NULL; | |
917 } | |
918 DIB_QuitGamma(this); | |
919 DIB_DestroyWindow(this); | |
920 | |
921 SDL_Window = NULL; | |
922 } | |
923 } | |
924 | |
925 /* Exported for the windows message loop only */ | |
926 static void DIB_FocusPalette(_THIS, int foreground) | |
927 { | |
928 if ( screen_pal != NULL ) { | |
929 HDC hdc; | |
930 | |
931 hdc = GetDC(SDL_Window); | |
932 SelectPalette(hdc, screen_pal, FALSE); | |
933 if ( RealizePalette(hdc) ) | |
934 InvalidateRect(SDL_Window, NULL, FALSE); | |
935 ReleaseDC(SDL_Window, hdc); | |
936 } | |
937 } | |
938 static void DIB_RealizePalette(_THIS) | |
939 { | |
940 DIB_FocusPalette(this, 1); | |
941 } | |
942 static void DIB_PaletteChanged(_THIS, HWND window) | |
943 { | |
944 if ( window != SDL_Window ) { | |
945 DIB_FocusPalette(this, 0); | |
946 } | |
947 } | |
948 | |
949 /* Exported for the windows message loop only */ | |
950 static void DIB_WinPAINT(_THIS, HDC hdc) | |
951 { | |
952 HDC mdc; | |
953 | |
954 if ( screen_pal ) { | |
955 SelectPalette(hdc, screen_pal, FALSE); | |
956 } | |
957 mdc = CreateCompatibleDC(hdc); | |
958 SelectObject(mdc, screen_bmp); | |
959 BitBlt(hdc, 0, 0, SDL_VideoSurface->w, SDL_VideoSurface->h, | |
960 mdc, 0, 0, SRCCOPY); | |
961 DeleteDC(mdc); | |
962 } | |
963 | |
964 /* Stub in case DirectX isn't available */ | |
965 #ifndef ENABLE_DIRECTX | |
966 void DX5_SoundFocus(HWND hwnd) | |
967 { | |
968 return; | |
969 } | |
970 #endif |