src/video/x11/SDL_x11modes.c
changeset 641 df178851293b
parent 637 6862d4294870
child 713 7c8deec1659c
equal deleted inserted replaced
640:3b31ef60ccbd 641:df178851293b
    83 #ifdef XFREE86_VM
    83 #ifdef XFREE86_VM
    84 static int cmpmodes(const void *va, const void *vb)
    84 static int cmpmodes(const void *va, const void *vb)
    85 {
    85 {
    86     const SDL_NAME(XF86VidModeModeInfo) *a = *(const SDL_NAME(XF86VidModeModeInfo)**)va;
    86     const SDL_NAME(XF86VidModeModeInfo) *a = *(const SDL_NAME(XF86VidModeModeInfo)**)va;
    87     const SDL_NAME(XF86VidModeModeInfo) *b = *(const SDL_NAME(XF86VidModeModeInfo)**)vb;
    87     const SDL_NAME(XF86VidModeModeInfo) *b = *(const SDL_NAME(XF86VidModeModeInfo)**)vb;
    88     if(a->hdisplay > b->hdisplay)
    88     if( (a->vdisplay > b->vdisplay) && (a->hdisplay >= b->hdisplay) )
    89         return -1;
    89         return -1;
    90     return b->vdisplay - a->vdisplay;
    90     return b->hdisplay - a->hdisplay;
    91 }
    91 }
    92 #endif
    92 #endif
    93 
    93 
    94 static void get_real_resolution(_THIS, int* w, int* h);
    94 static void get_real_resolution(_THIS, int* w, int* h);
    95 
    95 
   103         int best_width = 0, best_height = 0;
   103         int best_width = 0, best_height = 0;
   104         int nmodes;
   104         int nmodes;
   105 
   105 
   106         if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
   106         if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
   107              SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
   107              SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
   108             qsort(modes, nmodes, sizeof *modes, cmpmodes);
       
   109 #ifdef XFREE86_DEBUG
   108 #ifdef XFREE86_DEBUG
   110             printf("Available modes (sdl):\n");
   109             printf("Available modes (unsorted):\n");
   111             for ( i = 0; i < nmodes; ++i ) {
   110             for ( i = 0; i < nmodes; ++i ) {
   112                 printf("Mode %d: %d x %d @ %d\n", i,
   111                 printf("Mode %d: %d x %d @ %d\n", i,
   113                         modes[i]->hdisplay, modes[i]->vdisplay,
   112                         modes[i]->hdisplay, modes[i]->vdisplay,
   114                         1000 * modes[i]->dotclock / (modes[i]->htotal *
   113                         1000 * modes[i]->dotclock / (modes[i]->htotal *
   115                         modes[i]->vtotal) );
   114                         modes[i]->vtotal) );
   118             for ( i = 0; i < nmodes ; i++ ) {
   117             for ( i = 0; i < nmodes ; i++ ) {
   119                 if ( (modes[i]->hdisplay == width) &&
   118                 if ( (modes[i]->hdisplay == width) &&
   120                      (modes[i]->vdisplay == height) )
   119                      (modes[i]->vdisplay == height) )
   121                     goto match;
   120                     goto match;
   122             }
   121             }
       
   122             qsort(modes, nmodes, sizeof *modes, cmpmodes);
   123             for ( i = nmodes-1; i >= 0 ; i-- ) {
   123             for ( i = nmodes-1; i >= 0 ; i-- ) {
   124 		if ( ! best_width ) {
   124 		if ( ! best_width ) {
   125                     if ( (modes[i]->hdisplay >= width) &&
   125                     if ( (modes[i]->hdisplay >= width) &&
   126                          (modes[i]->vdisplay >= height) ) {
   126                          (modes[i]->vdisplay >= height) ) {
   127                         best_width = modes[i]->hdisplay;
   127                         best_width = modes[i]->hdisplay;
   350     }
   350     }
   351     if ( ! buggy_X11 &&
   351     if ( ! buggy_X11 &&
   352          SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
   352          SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
   353 
   353 
   354 #ifdef XFREE86_DEBUG
   354 #ifdef XFREE86_DEBUG
   355         printf("Available modes (x11):\n");
   355         printf("Available modes: (sorted)\n");
   356         for ( i = 0; i < nmodes; ++i ) {
   356         for ( i = 0; i < nmodes; ++i ) {
   357             printf("Mode %d: %d x %d @ %d\n", i,
   357             printf("Mode %d: %d x %d @ %d\n", i,
   358                     modes[i]->hdisplay, modes[i]->vdisplay,
   358                     modes[i]->hdisplay, modes[i]->vdisplay,
   359                     1000 * modes[i]->dotclock / (modes[i]->htotal *
   359                     1000 * modes[i]->dotclock / (modes[i]->htotal *
   360                     modes[i]->vtotal) );
   360                     modes[i]->vtotal) );