comparison src/video/dga/SDL_dgavideo.c @ 1785:dcec47a019e2

Fixed DGA mode sorting and eliminated doublescan and interlaced modes
author Sam Lantinga <slouken@libsdl.org>
date Tue, 09 May 2006 06:14:11 +0000
parents 45669d4efd02
children 473abd216edb
comparison
equal deleted inserted replaced
1784:45669d4efd02 1785:dcec47a019e2
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*/
43 45
44 /* Heheh we're using X11 event code */ 46 /* Heheh we're using X11 event code */
45 extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms); 47 extern void X11_SaveScreenSaver(Display *display, int *saved_timeout, BOOL *dpms);
46 extern void X11_DisableScreenSaver(Display *display); 48 extern void X11_DisableScreenSaver(Display *display);
47 extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms); 49 extern void X11_RestoreScreenSaver(Display *display, int saved_timeout, BOOL dpms);
180 /* Check to see if we already have this mode */ 182 /* Check to see if we already have this mode */
181 if ( bpp < 8 ) { /* Not supported */ 183 if ( bpp < 8 ) { /* Not supported */
182 return(0); 184 return(0);
183 } 185 }
184 index = ((bpp+7)/8)-1; 186 index = ((bpp+7)/8)-1;
185 for ( i=0; i<SDL_nummodes[index]; ++i ) { 187 if ( SDL_nummodes[index] > 0 ) {
186 mode = SDL_modelist[index][i]; 188 mode = SDL_modelist[index][SDL_nummodes[index]-1];
187 if ( (mode->w == w) && (mode->h == h) ) { 189 if ( (mode->w == w) && (mode->h == h) ) {
188 return(0); 190 return(0);
189 } 191 }
190 } 192 }
191 193
284 static int cmpmodes(const void *va, const void *vb) 286 static int cmpmodes(const void *va, const void *vb)
285 { 287 {
286 const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va; 288 const SDL_NAME(XDGAMode) *a = (const SDL_NAME(XDGAMode) *)va;
287 const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb; 289 const SDL_NAME(XDGAMode) *b = (const SDL_NAME(XDGAMode) *)vb;
288 290
289 /* Prefer DirectColor visuals for otherwise equal modes */
290 if ( (a->viewportWidth == b->viewportWidth) && 291 if ( (a->viewportWidth == b->viewportWidth) &&
291 (b->viewportHeight == a->viewportHeight) ) { 292 (b->viewportHeight == a->viewportHeight) ) {
292 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 )
293 return -1; 301 return -1;
294 if ( b->visualClass == DirectColor ) 302 if ( b->visualClass == DirectColor && a->visualClass != DirectColor )
295 return 1; 303 return 1;
296 return 0; 304 /* Maintain server refresh rate sorting */
305 return a->num - b->num;
297 } else if ( a->viewportWidth == b->viewportWidth ) { 306 } else if ( a->viewportWidth == b->viewportWidth ) {
298 return b->viewportHeight - a->viewportHeight; 307 return b->viewportHeight - a->viewportHeight;
299 } else { 308 } else {
300 return b->viewportWidth - a->viewportWidth; 309 return b->viewportWidth - a->viewportWidth;
301 } 310 }
398 407
399 /* Query for the list of available video modes */ 408 /* Query for the list of available video modes */
400 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes); 409 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
401 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes); 410 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
402 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)) ) {
403 #ifdef DGA_DEBUG 416 #ifdef DGA_DEBUG
404 PrintMode(&modes[i]); 417 PrintMode(&modes[i]);
405 #endif 418 #endif
406 if ( (modes[i].visualClass == PseudoColor) ||
407 (modes[i].visualClass == DirectColor) ||
408 (modes[i].visualClass == TrueColor) ) {
409 DGA_AddMode(this, modes[i].bitsPerPixel, 419 DGA_AddMode(this, modes[i].bitsPerPixel,
410 modes[i].viewportWidth, 420 modes[i].viewportWidth,
411 modes[i].viewportHeight); 421 modes[i].viewportHeight);
412 } 422 }
413 } 423 }
459 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes); 469 modes = SDL_NAME(XDGAQueryModes)(DGA_Display, DGA_Screen, &num_modes);
460 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes); 470 SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
461 for ( i=0; i<num_modes; ++i ) { 471 for ( i=0; i<num_modes; ++i ) {
462 int depth; 472 int depth;
463 473
464
465 depth = modes[i].depth; 474 depth = modes[i].depth;
466 if ( depth == 24 ) { /* Distinguish between 24 and 32 bpp */ 475 if ( depth == 24 ) { /* Distinguish between 24 and 32 bpp */
467 depth = modes[i].bitsPerPixel; 476 depth = modes[i].bitsPerPixel;
468 } 477 }
469 if ( (depth == bpp) && 478 if ( (depth == bpp) &&
470 (modes[i].viewportWidth == width) && 479 (modes[i].viewportWidth == width) &&
471 (modes[i].viewportHeight == height) && 480 (modes[i].viewportHeight == height) &&
472 ((modes[i].visualClass == PseudoColor) || 481 ((modes[i].visualClass == PseudoColor) ||
473 (modes[i].visualClass == DirectColor) || 482 (modes[i].visualClass == DirectColor) ||
474 (modes[i].visualClass == TrueColor)) ) { 483 (modes[i].visualClass == TrueColor)) &&
484 !(modes[i].flags & (XDGAInterlaced|XDGADoublescan)) ) {
475 break; 485 break;
476 } 486 }
477 } 487 }
478 if ( i == num_modes ) { 488 if ( i == num_modes ) {
479 SDL_SetError("No matching video mode found"); 489 SDL_SetError("No matching video mode found");
480 return(NULL); 490 return(NULL);
481 } 491 }
492 #ifdef DGA_DEBUG
493 PrintMode(&modes[i]);
494 #endif
482 495
483 /* Set the video mode */ 496 /* Set the video mode */
484 mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num); 497 mode = SDL_NAME(XDGASetMode)(DGA_Display, DGA_Screen, modes[i].num);
485 XFree(modes); 498 XFree(modes);
486 if ( mode == NULL ) { 499 if ( mode == NULL ) {