comparison src/video/dga/SDL_dgavideo.c @ 1659:14717b52abc0 SDL-1.3

Merge trunk-1.3-3
author Sam Lantinga <slouken@libsdl.org>
date Wed, 17 May 2006 08:18:28 +0000
parents 3ba88cb7eb1b
children 782fd950bd46
comparison
equal deleted inserted replaced
1658:e49147870aac 1659:14717b52abc0
38 #include "SDL_dgamouse_c.h" 38 #include "SDL_dgamouse_c.h"
39 #include "SDL_dgaevents_c.h" 39 #include "SDL_dgaevents_c.h"
40 40
41 /* get function pointers... */ 41 /* get function pointers... */
42 #include "../x11/SDL_x11dyn.h" 42 #include "../x11/SDL_x11dyn.h"
43
44 /*#define DGA_DEBUG*/
45
46 /* Heheh we're using X11 event code */
47 extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
48 extern void X11_DisableScreenSaver(Display *display);
49 extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
43 50
44 /* Initialization/Query functions */ 51 /* Initialization/Query functions */
45 static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat); 52 static int DGA_VideoInit(_THIS, SDL_PixelFormat *vformat);
46 static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 53 static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
47 static SDL_Surface *DGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 54 static SDL_Surface *DGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
167 }; 174 };
168 175
169 static int DGA_AddMode(_THIS, int bpp, int w, int h) 176 static int DGA_AddMode(_THIS, int bpp, int w, int h)
170 { 177 {
171 SDL_Rect *mode; 178 SDL_Rect *mode;
172 int i, index; 179 int index;
173 int next_mode; 180 int next_mode;
174 181
175 /* Check to see if we already have this mode */ 182 /* Check to see if we already have this mode */
176 if ( bpp < 8 ) { /* Not supported */ 183 if ( bpp < 8 ) { /* Not supported */
177 return(0); 184 return(0);
178 } 185 }
179 index = ((bpp+7)/8)-1; 186 index = ((bpp+7)/8)-1;
180 for ( i=0; i<SDL_nummodes[index]; ++i ) { 187 if ( SDL_nummodes[index] > 0 ) {
181 mode = SDL_modelist[index][i]; 188 mode = SDL_modelist[index][SDL_nummodes[index]-1];
182 if ( (mode->w == w) && (mode->h == h) ) { 189 if ( (mode->w == w) && (mode->h == h) ) {
183 return(0); 190 return(0);
184 } 191 }
185 } 192 }
186 193
279 static int cmpmodes(const void *va, const void *vb) 286 static int cmpmodes(const void *va, const void *vb)
280 { 287 {
281 const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va; 288 const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va;
282 const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb; 289 const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb;
283 290
284 /* Prefer DirectColor visuals for otherwise equal modes */
285 if ( (a->viewportWidth == b->viewportWidth) && 291 if ( (a->viewportWidth == b->viewportWidth) &&
286 (b->viewportHeight == a->viewportHeight) ) { 292 (b->viewportHeight == a->viewportHeight) ) {
287 if ( a->visualClass == DirectColor ) 293 /* Prefer 32 bpp over 24 bpp, 16 bpp over 15 bpp */
294 int a_bpp = a->depth == 24 ? a->bitsPerPixel : a->depth;
295 int b_bpp = b->depth == 24 ? b->bitsPerPixel : b->depth;
296 if ( a_bpp != b_bpp ) {
297 return b_bpp - a_bpp;
298 }
299 /* Prefer DirectColor visuals, for gamma support */
300 if ( a->visualClass == DirectColor && b->visualClass != DirectColor )
288 return -1; 301 return -1;
289 if ( b->visualClass == DirectColor ) 302 if ( b->visualClass == DirectColor && a->visualClass != DirectColor )
290 return 1; 303 return 1;
291 return 0; 304 /* Maintain server refresh rate sorting */
305 return a->num - b->num;
292 } else if ( a->viewportWidth == b->viewportWidth ) { 306 } else if ( a->viewportWidth == b->viewportWidth ) {
293 return b->viewportHeight - a->viewportHeight; 307 return b->viewportHeight - a->viewportHeight;
294 } else { 308 } else {
295 return b->viewportWidth - a->viewportWidth; 309 return b->viewportWidth - a->viewportWidth;
296 } 310 }
385 SDL_SetError("Unable to map the video memory"); 399 SDL_SetError("Unable to map the video memory");
386 XCloseDisplay(DGA_Display); 400 XCloseDisplay(DGA_Display);
387 return(-1); 401 return(-1);
388 } 402 }
389 403
404 /* Save DPMS and screensaver settings */
405 X11_SaveScreenSaver(DGA_Display, &screensaver_timeout, &dpms_enabled);
406 X11_DisableScreenSaver(DGA_Display);
407
390 /* Query for the list of available video modes */ 408 /* Query for the list of available video modes */
391 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes); 409 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
392 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes); 410 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
393 for ( i=0; i<num_modes; ++i ) { 411 for ( i=0; i<num_modes; ++i ) {
412 if ( ((modes[i].visualClass == PseudoColor) ||
413 (modes[i].visualClass == DirectColor) ||
414 (modes[i].visualClass == TrueColor)) &&
415 !(modes[i].flags & (XDGAInterlaced|XDGADoublescan)) ) {
394 #ifdef DGA_DEBUG 416 #ifdef DGA_DEBUG
395 PrintMode(&modes[i]); 417 PrintMode(&modes[i]);
396 #endif 418 #endif
397 if ( (modes[i].visualClass == PseudoColor) ||
398 (modes[i].visualClass == DirectColor) ||
399 (modes[i].visualClass == TrueColor) ) {
400 DGA_AddMode(this, modes[i].bitsPerPixel, 419 DGA_AddMode(this, modes[i].bitsPerPixel,
401 modes[i].viewportWidth, 420 modes[i].viewportWidth,
402 modes[i].viewportHeight); 421 modes[i].viewportHeight);
403 } 422 }
404 } 423 }
450 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes); 469 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
451 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes); 470 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
452 for ( i=0; i<num_modes; ++i ) { 471 for ( i=0; i<num_modes; ++i ) {
453 int depth; 472 int depth;
454 473
455
456 depth = modes[i].depth; 474 depth = modes[i].depth;
457 if ( depth == 24 ) { /* Distinguish between 24 and 32 bpp */ 475 if ( depth == 24 ) { /* Distinguish between 24 and 32 bpp */
458 depth = modes[i].bitsPerPixel; 476 depth = modes[i].bitsPerPixel;
459 } 477 }
460 if ( (depth == bpp) && 478 if ( (depth == bpp) &&
461 (modes[i].viewportWidth == width) && 479 (modes[i].viewportWidth == width) &&
462 (modes[i].viewportHeight == height) && 480 (modes[i].viewportHeight == height) &&
463 ((modes[i].visualClass == PseudoColor) || 481 ((modes[i].visualClass == PseudoColor) ||
464 (modes[i].visualClass == DirectColor) || 482 (modes[i].visualClass == DirectColor) ||
465 (modes[i].visualClass == TrueColor)) ) { 483 (modes[i].visualClass == TrueColor)) &&
484 !(modes[i].flags & (XDGAInterlaced|XDGADoublescan)) ) {
466 break; 485 break;
467 } 486 }
468 } 487 }
469 if ( i == num_modes ) { 488 if ( i == num_modes ) {
470 SDL_SetError("No matching video mode found"); 489 SDL_SetError("No matching video mode found");
471 return(NULL); 490 return(NULL);
472 } 491 }
492 #ifdef DGA_DEBUG
493 PrintMode(&modes[i]);
494 #endif
473 495
474 /* Set the video mode */ 496 /* Set the video mode */
475 mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num); 497 mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num);
476 XFree(modes); 498 XFree(modes);
477 if ( mode == NULL ) { 499 if ( mode == NULL ) {
746 return(retval); 768 return(retval);
747 } 769 }
748 static void DGA_FreeHWSurface(_THIS, SDL_Surface *surface) 770 static void DGA_FreeHWSurface(_THIS, SDL_Surface *surface)
749 { 771 {
750 vidmem_bucket *bucket, *freeable; 772 vidmem_bucket *bucket, *freeable;
773
774 /* Wait for any pending operations involving this surface */
775 if ( DGA_IsSurfaceBusy(surface) ) {
776 LOCK_DISPLAY();
777 DGA_WaitBusySurfaces(this);
778 UNLOCK_DISPLAY();
779 }
751 780
752 /* Look for the bucket in the current list */ 781 /* Look for the bucket in the current list */
753 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { 782 for ( bucket=&surfaces; bucket; bucket=bucket->next ) {
754 if ( bucket == (vidmem_bucket *)surface->hwdata ) { 783 if ( bucket == (vidmem_bucket *)surface->hwdata ) {
755 break; 784 break;
1030 1059
1031 /* Unmap memory and reset video mode */ 1060 /* Unmap memory and reset video mode */
1032 SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen); 1061 SDL_NAME(XDGACloseFramebuffer)(DGA_Display, DGA_Screen);
1033 if ( this->screen ) { 1062 if ( this->screen ) {
1034 /* Tell SDL not to free the pixels */ 1063 /* Tell SDL not to free the pixels */
1035 this->screen->pixels = NULL; 1064 DGA_FreeHWSurface(this, this->screen);
1036 } 1065 }
1037 SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, 0); 1066 SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, 0);
1038 1067
1039 /* Clear the lock mutex */ 1068 /* Clear the lock mutex */
1040 if ( hw_lock != NULL ) { 1069 if ( hw_lock != NULL ) {
1045 if ( event_lock != NULL ) { 1074 if ( event_lock != NULL ) {
1046 SDL_DestroyMutex(event_lock); 1075 SDL_DestroyMutex(event_lock);
1047 event_lock = NULL; 1076 event_lock = NULL;
1048 } 1077 }
1049 #endif /* LOCK_DGA_DISPLAY */ 1078 #endif /* LOCK_DGA_DISPLAY */
1050
1051 1079
1052 /* Clean up defined video modes */ 1080 /* Clean up defined video modes */
1053 for ( i=0; i<NUM_MODELISTS; ++i ) { 1081 for ( i=0; i<NUM_MODELISTS; ++i ) {
1054 if ( SDL_modelist[i] != NULL ) { 1082 if ( SDL_modelist[i] != NULL ) {
1055 for ( j=0; SDL_modelist[i][j]; ++j ) { 1083 for ( j=0; SDL_modelist[i][j]; ++j ) {
1061 } 1089 }
1062 1090
1063 /* Clean up the memory bucket list */ 1091 /* Clean up the memory bucket list */
1064 DGA_FreeHWSurfaces(this); 1092 DGA_FreeHWSurfaces(this);
1065 1093
1094 /* Restore DPMS and screensaver settings */
1095 X11_RestoreScreenSaver(DGA_Display, screensaver_timeout, dpms_enabled);
1096
1066 /* Close up the display */ 1097 /* Close up the display */
1067 XCloseDisplay(DGA_Display); 1098 XCloseDisplay(DGA_Display);
1068 } 1099 }
1069 } 1100 }