src/video/windib/SDL_dibvideo.c
author Ryan C. Gordon
Tue, 26 Jun 2007 20:02:40 +0000
branchSDL-1.2
changeset 3981 b0d021cf41b6
parent 3976 8582c6a5ca16
child 3992 c75679dce60c
permissions -rw-r--r--
windib target can now control screensaver with SDL_VIDEO_ALLOW_SCREENSAVER.

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