Mercurial > sdl-ios-xcode
comparison src/video/windib/SDL_dibvideo.c @ 1465:8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Converted the disk audio driver to SDL_RWops for portability
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 04 Mar 2006 08:24:35 +0000 |
parents | bb6839704ed6 |
children | 4aac8563c296 |
comparison
equal
deleted
inserted
replaced
1464:af30090c0330 | 1465:8dfa9a6d69a5 |
---|---|
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 | 23 |
24 #define WIN32_LEAN_AND_MEAN | 24 #define WIN32_LEAN_AND_MEAN |
25 #include <windows.h> | 25 #include <windows.h> |
26 | |
27 #if defined(_WIN32_WCE) | |
28 | |
29 // defined and used in SDL_sysevents.c | |
30 extern HINSTANCE aygshell; | |
31 | |
32 #endif | |
33 | 26 |
34 /* Not yet in the mingw32 cross-compile headers */ | 27 /* Not yet in the mingw32 cross-compile headers */ |
35 #ifndef CDS_FULLSCREEN | 28 #ifndef CDS_FULLSCREEN |
36 #define CDS_FULLSCREEN 4 | 29 #define CDS_FULLSCREEN 4 |
37 #endif | 30 #endif |
47 #include "SDL_dibevents_c.h" | 40 #include "SDL_dibevents_c.h" |
48 #include "../wincommon/SDL_wingl_c.h" | 41 #include "../wincommon/SDL_wingl_c.h" |
49 | 42 |
50 #ifdef _WIN32_WCE | 43 #ifdef _WIN32_WCE |
51 #define NO_GETDIBITS | 44 #define NO_GETDIBITS |
52 #define NO_CHANGEDISPLAYSETTINGS | |
53 #define NO_GAMMA_SUPPORT | 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 | |
54 #endif | 51 #endif |
55 #ifndef WS_MAXIMIZE | 52 #ifndef WS_MAXIMIZE |
56 #define WS_MAXIMIZE 0 | 53 #define WS_MAXIMIZE 0 |
57 #endif | 54 #endif |
58 #ifndef WS_THICKFRAME | 55 #ifndef WS_THICKFRAME |
61 #ifndef SWP_NOCOPYBITS | 58 #ifndef SWP_NOCOPYBITS |
62 #define SWP_NOCOPYBITS 0 | 59 #define SWP_NOCOPYBITS 0 |
63 #endif | 60 #endif |
64 #ifndef PC_NOCOLLAPSE | 61 #ifndef PC_NOCOLLAPSE |
65 #define PC_NOCOLLAPSE 0 | 62 #define PC_NOCOLLAPSE 0 |
63 #endif | |
64 | |
65 #ifdef _WIN32_WCE | |
66 // defined and used in SDL_sysevents.c | |
67 extern HINSTANCE aygshell; | |
66 #endif | 68 #endif |
67 | 69 |
68 /* Initialization/Query functions */ | 70 /* Initialization/Query functions */ |
69 static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat); | 71 static int DIB_VideoInit(_THIS, SDL_PixelFormat *vformat); |
70 static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | 72 static SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); |
188 VideoBootStrap WINDIB_bootstrap = { | 190 VideoBootStrap WINDIB_bootstrap = { |
189 "windib", "Win95/98/NT/2000/CE GDI", | 191 "windib", "Win95/98/NT/2000/CE GDI", |
190 DIB_Available, DIB_CreateDevice | 192 DIB_Available, DIB_CreateDevice |
191 }; | 193 }; |
192 | 194 |
193 #ifndef NO_CHANGEDISPLAYSETTINGS | |
194 | |
195 static int cmpmodes(const void *va, const void *vb) | 195 static int cmpmodes(const void *va, const void *vb) |
196 { | 196 { |
197 SDL_Rect *a = *(SDL_Rect **)va; | 197 SDL_Rect *a = *(SDL_Rect **)va; |
198 SDL_Rect *b = *(SDL_Rect **)vb; | 198 SDL_Rect *b = *(SDL_Rect **)vb; |
199 if ( a->w == b->w ) | 199 if ( a->w == b->w ) |
245 SDL_modelist[index][next_mode+1] = NULL; | 245 SDL_modelist[index][next_mode+1] = NULL; |
246 SDL_nummodes[index]++; | 246 SDL_nummodes[index]++; |
247 | 247 |
248 return(0); | 248 return(0); |
249 } | 249 } |
250 | |
251 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | |
252 | 250 |
253 static HPALETTE DIB_CreatePalette(int bpp) | 251 static HPALETTE DIB_CreatePalette(int bpp) |
254 { | 252 { |
255 /* RJR: March 28, 2000 | 253 /* RJR: March 28, 2000 |
256 moved palette creation here from "DIB_VideoInit" */ | 254 moved palette creation here from "DIB_VideoInit" */ |
324 | 322 |
325 /* See if gamma is supported on this screen */ | 323 /* See if gamma is supported on this screen */ |
326 DIB_CheckGamma(this); | 324 DIB_CheckGamma(this); |
327 | 325 |
328 #ifndef NO_CHANGEDISPLAYSETTINGS | 326 #ifndef NO_CHANGEDISPLAYSETTINGS |
327 | |
328 settings.dmSize = sizeof(DEVMODE); | |
329 settings.dmDriverExtra = 0; | |
330 #ifdef _WIN32_WCE | |
331 settings.dmFields = DM_DISPLAYQUERYORIENTATION; | |
332 this->hidden->supportRotation = ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL) == DISP_CHANGE_SUCCESSFUL; | |
333 #endif | |
329 /* Query for the desktop resolution */ | 334 /* Query for the desktop resolution */ |
330 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); | 335 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &SDL_desktop_mode); |
331 | 336 |
332 /* Query for the list of available video modes */ | 337 /* Query for the list of available video modes */ |
333 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { | 338 for ( i=0; EnumDisplaySettings(NULL, i, &settings); ++i ) { |
334 DIB_AddMode(this, settings.dmBitsPerPel, | 339 DIB_AddMode(this, settings.dmBitsPerPel, |
335 settings.dmPelsWidth, settings.dmPelsHeight); | 340 settings.dmPelsWidth, settings.dmPelsHeight); |
341 #ifdef _WIN32_WCE | |
342 if( this->hidden->supportRotation ) | |
343 DIB_AddMode(this, settings.dmBitsPerPel, | |
344 settings.dmPelsHeight, settings.dmPelsWidth); | |
345 #endif | |
336 } | 346 } |
337 /* Sort the mode lists */ | 347 /* Sort the mode lists */ |
348 if( i > 1 ) | |
338 for ( i=0; i<NUM_MODELISTS; ++i ) { | 349 for ( i=0; i<NUM_MODELISTS; ++i ) { |
339 if ( SDL_nummodes[i] > 0 ) { | 350 if ( SDL_nummodes[i] > 0 ) { |
340 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); | 351 SDL_qsort(SDL_modelist[i], SDL_nummodes[i], sizeof *SDL_modelist[i], cmpmodes); |
341 } | 352 } |
342 } | 353 } |
354 #else | |
355 // WinCE and fullscreen mode: | |
356 // We use only vformat->BitsPerPixel that allow SDL to | |
357 // emulate other bpp (8, 32) and use triple buffer, | |
358 // because SDL surface conversion is much faster than the WinCE one. | |
359 // Although it should be tested on devices with graphics accelerator. | |
360 | |
361 DIB_AddMode(this, vformat->BitsPerPixel, | |
362 GetDeviceCaps(GetDC(NULL), HORZRES), | |
363 GetDeviceCaps(GetDC(NULL), VERTRES)); | |
364 | |
343 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | 365 #endif /* !NO_CHANGEDISPLAYSETTINGS */ |
344 | 366 |
345 /* Grab an identity palette if we are in a palettized mode */ | 367 /* Grab an identity palette if we are in a palettized mode */ |
346 if ( vformat->BitsPerPixel <= 8 ) { | 368 if ( vformat->BitsPerPixel <= 8 ) { |
347 /* RJR: March 28, 2000 | 369 /* RJR: March 28, 2000 |
350 } | 372 } |
351 | 373 |
352 /* Fill in some window manager capabilities */ | 374 /* Fill in some window manager capabilities */ |
353 this->info.wm_available = 1; | 375 this->info.wm_available = 1; |
354 | 376 |
377 #ifdef _WIN32_WCE | |
378 this->hidden->origRotation = -1; | |
379 #endif | |
380 | |
355 /* We're done! */ | 381 /* We're done! */ |
356 return(0); | 382 return(0); |
357 } | 383 } |
358 | 384 |
359 /* We support any format at any dimension */ | 385 /* We support any format at any dimension */ |
360 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | 386 SDL_Rect **DIB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) |
361 { | 387 { |
362 #ifdef NO_CHANGEDISPLAYSETTINGS | |
363 return((SDL_Rect **)-1); | |
364 #else | |
365 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | 388 if ( (flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { |
366 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | 389 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); |
367 } else { | 390 } else { |
368 return((SDL_Rect **)-1); | 391 return((SDL_Rect **)-1); |
369 } | 392 } |
370 #endif | |
371 } | 393 } |
372 | 394 |
373 | 395 |
374 /* | 396 /* |
375 Helper fn to work out which screen depth windows is currently using. | 397 Helper fn to work out which screen depth windows is currently using. |
529 DEVMODE settings; | 551 DEVMODE settings; |
530 BOOL changed; | 552 BOOL changed; |
531 | 553 |
532 SDL_memset(&settings, 0, sizeof(DEVMODE)); | 554 SDL_memset(&settings, 0, sizeof(DEVMODE)); |
533 settings.dmSize = sizeof(DEVMODE); | 555 settings.dmSize = sizeof(DEVMODE); |
556 | |
557 #ifdef _WIN32_WCE | |
558 // try to rotate screen to fit requested resolution | |
559 if( this->hidden->supportRotation ) | |
560 { | |
561 DWORD rotation; | |
562 | |
563 // ask current mode | |
564 settings.dmFields = DM_DISPLAYORIENTATION; | |
565 ChangeDisplaySettingsEx(NULL, &settings, NULL, CDS_TEST, NULL); | |
566 rotation = settings.dmDisplayOrientation; | |
567 | |
568 if( (width > GetDeviceCaps(GetDC(NULL), HORZRES)) | |
569 && (height < GetDeviceCaps(GetDC(NULL), VERTRES))) | |
570 { | |
571 switch( rotation ) | |
572 { | |
573 case DMDO_0: | |
574 settings.dmDisplayOrientation = DMDO_90; | |
575 break; | |
576 case DMDO_270: | |
577 settings.dmDisplayOrientation = DMDO_180; | |
578 break; | |
579 } | |
580 if( settings.dmDisplayOrientation != rotation ) | |
581 { | |
582 // go to landscape | |
583 this->hidden->origRotation = rotation; | |
584 ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); | |
585 } | |
586 } | |
587 if( (width < GetDeviceCaps(GetDC(NULL), HORZRES)) | |
588 && (height > GetDeviceCaps(GetDC(NULL), VERTRES))) | |
589 { | |
590 switch( rotation ) | |
591 { | |
592 case DMDO_90: | |
593 settings.dmDisplayOrientation = DMDO_0; | |
594 break; | |
595 case DMDO_180: | |
596 settings.dmDisplayOrientation = DMDO_270; | |
597 break; | |
598 } | |
599 if( settings.dmDisplayOrientation != rotation ) | |
600 { | |
601 // go to portrait | |
602 this->hidden->origRotation = rotation; | |
603 ChangeDisplaySettingsEx(NULL,&settings,NULL,CDS_RESET,NULL); | |
604 } | |
605 } | |
606 | |
607 } | |
608 #endif | |
609 | |
610 #ifndef _WIN32_WCE | |
534 settings.dmBitsPerPel = video->format->BitsPerPixel; | 611 settings.dmBitsPerPel = video->format->BitsPerPixel; |
535 settings.dmPelsWidth = width; | 612 settings.dmPelsWidth = width; |
536 settings.dmPelsHeight = height; | 613 settings.dmPelsHeight = height; |
537 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; | 614 settings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; |
538 if ( width <= (int)SDL_desktop_mode.dmPelsWidth && | 615 if ( width <= (int)SDL_desktop_mode.dmPelsWidth && |
543 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); | 620 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); |
544 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { | 621 if ( ! changed && (settings.dmFields & DM_DISPLAYFREQUENCY) ) { |
545 settings.dmFields &= ~DM_DISPLAYFREQUENCY; | 622 settings.dmFields &= ~DM_DISPLAYFREQUENCY; |
546 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); | 623 changed = (ChangeDisplaySettings(&settings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL); |
547 } | 624 } |
625 #else | |
626 changed = 1; | |
627 #endif | |
548 if ( changed ) { | 628 if ( changed ) { |
549 video->flags |= SDL_FULLSCREEN; | 629 video->flags |= SDL_FULLSCREEN; |
550 SDL_fullscreen_mode = settings; | 630 SDL_fullscreen_mode = settings; |
551 } | 631 } |
632 | |
552 } | 633 } |
553 #endif /* !NO_CHANGEDISPLAYSETTINGS */ | 634 #endif /* !NO_CHANGEDISPLAYSETTINGS */ |
554 | 635 |
555 /* Reset the palette and create a new one if necessary */ | 636 /* Reset the palette and create a new one if necessary */ |
556 if ( screen_pal != NULL ) { | 637 if ( screen_pal != NULL ) { |
667 if ( bpp <= 8 ) { | 748 if ( bpp <= 8 ) { |
668 /* BitBlt() maps colors for us */ | 749 /* BitBlt() maps colors for us */ |
669 video->flags |= SDL_HWPALETTE; | 750 video->flags |= SDL_HWPALETTE; |
670 } | 751 } |
671 } | 752 } |
672 | 753 #ifndef _WIN32_WCE |
673 /* Resize the window */ | 754 /* Resize the window */ |
674 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { | 755 if ( !SDL_windowid && !IsZoomed(SDL_Window) ) { |
756 #else | |
757 if ( !SDL_windowid ) { | |
758 #endif | |
675 HWND top; | 759 HWND top; |
676 UINT swp_flags; | 760 UINT swp_flags; |
677 const char *window = NULL; | 761 const char *window = NULL; |
678 const char *center = NULL; | 762 const char *center = NULL; |
679 | 763 |