te: 27 Jun 2003 21:16:01 +0100
authorSam Lantinga
Sat, 28 Jun 2003 17:16:52 +0000
changeset 6376862d4294870
parent 636 d9c2ab142f2f
child 638 b0108e9dea53
te: 27 Jun 2003 21:16:01 +0100
From: Alan Swanson
Subject: [SDL] New XFree 4.3 Video Mode Patch

The current patch to fix the issues with XFree 4.3 it is a bit of
overkill to a simple problem. Default screen settings should be set in
X, not selected by SDL with environment variables. Any program or user
using non-standard or unset display modes get what they deserve :-)

If you look at the unsorted list of modes returned by X, here's mine;

1280 x 1024 @ 85.0 >
1024 x 768 @ 100.3 > USER
800 x 600 @ 125.5 > SET
640 x 480 @ 124.9 >
1280 x 1024 @ 75.0 ]
1280 x 1024 @ 60.0 ]
1280 x 960 @ 85.0 ] X11
1280 x 960 @ 60.0 ] AUTO
1152 x 864 @ 75.0 ]
1152 x 768 @ 54.8 ]
960 x 720 @ 120.0 ]
...
640 x 400 @ 85.1 ] 256k
576 x 432 @ 150.0 ] 249k PIXEL
640 x 350 @ 85.1 ] 224k COUNT
576 x 384 @ 109.6 ] 221k
...

The user set modes come first followed by X set modes which are ordered
by decreasing number of pixels and refresh.

The reason why every other library or program not using SDL was working
is due to SDL scanning the modes in reverse getting X11 provided modes
modes with the lowest refresh.

The solution is to scan forward for the first user set mode or highest X
mode. The qsort still keeps user set modes above higher refresh modes
added by X.

For the best match we still reverse search for the nearest larger size
and then try to find a higher version of it.
src/video/x11/SDL_x11modes.c
     1.1 --- a/src/video/x11/SDL_x11modes.c	Sat Jun 28 17:03:57 2003 +0000
     1.2 +++ b/src/video/x11/SDL_x11modes.c	Sat Jun 28 17:16:52 2003 +0000
     1.3 @@ -44,8 +44,6 @@
     1.4  #endif 
     1.5  
     1.6  #define MAX(a, b)        (a > b ? a : b)
     1.7 -#define V_INTERLACE      0x010
     1.8 -#define V_DBLSCAN        0x020
     1.9  
    1.10  #ifdef XFREE86_VM
    1.11  Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info)
    1.12 @@ -93,82 +91,6 @@
    1.13  }
    1.14  #endif
    1.15  
    1.16 -#ifdef XFREE86_VM
    1.17 -static int get_vidmode_filter(SDL_NAME(XF86VidModeModeInfo) **modes, int nmodes, char **bitmap)
    1.18 -{
    1.19 -    int i, result = 0;
    1.20 -    int use_all_modes, use_specific_mode;
    1.21 -    const char *variable;
    1.22 -    char *temp;
    1.23 -
    1.24 -    if (!nmodes)
    1.25 -        return 0;
    1.26 -
    1.27 -    temp = (char *)malloc((nmodes)*sizeof(char));
    1.28 -    if (!temp)
    1.29 -        return 0;
    1.30 -
    1.31 -    for ( i = 0; i < nmodes; ++i )
    1.32 -        temp[i] = 0;
    1.33 -
    1.34 -    variable = getenv("SDL_VIDEO_X11_USE_ALL_MODES");
    1.35 -    use_all_modes = variable ? atoi(variable) : 0;
    1.36 -    variable = getenv("SDL_VIDEO_X11_USE_SPECIFIC_MODE");
    1.37 -    use_specific_mode = variable ? atoi(variable) : 0;
    1.38 -
    1.39 -    qsort(modes, nmodes, sizeof *modes, cmpmodes);
    1.40 -
    1.41 -    if ( use_all_modes ) {
    1.42 -        for ( i = 0; i < nmodes; ++i )
    1.43 -            temp[i] = 1;
    1.44 -        result  = 1;
    1.45 -/*    } else if ( use_specific_mode ) { ... */
    1.46 -    } else {
    1.47 -        int previous_refresh, current_refresh;
    1.48 -        SDL_NAME(XF86VidModeModeInfo) *previous, *current;
    1.49 -
    1.50 -        previous = modes[0];
    1.51 -        previous_refresh = (int)(previous->dotclock * 1000.0 /
    1.52 -          (previous->htotal * previous->vtotal));
    1.53 -        if ( previous->flags & V_INTERLACE ) previous_refresh *= 2;
    1.54 -        else if ( previous->flags & V_DBLSCAN ) previous_refresh /= 2;
    1.55 -
    1.56 -        temp[0] = 1;
    1.57 -        for ( i = 1; i < nmodes; ++i ) {
    1.58 -            current = modes[i];
    1.59 -            current_refresh = (int)(current->dotclock * 1000.0 /
    1.60 -              (current->htotal * current->vtotal));
    1.61 -            if ( current->flags & V_INTERLACE ) current_refresh *= 2;
    1.62 -            else if ( current->flags & V_DBLSCAN ) current_refresh /= 2;
    1.63 -
    1.64 -            /* Compare this mode to the previous one */
    1.65 -            if ( current->hdisplay == previous->hdisplay &&
    1.66 -                 current->vdisplay == previous->vdisplay ) {
    1.67 -#ifdef XFREE86_DEBUG
    1.68 -		printf("Comparing %dx%d at %d Hz and %d Hz\n",
    1.69 -			current->hdisplay, current->vdisplay,
    1.70 -			current_refresh, previous_refresh);
    1.71 -#endif
    1.72 -                if ( current_refresh > previous_refresh ) {
    1.73 -                    temp[i-1] = 0;
    1.74 -                    temp[i]   = 1;
    1.75 -                }
    1.76 -                else
    1.77 -                    temp[i] = 0;
    1.78 -            }
    1.79 -            else
    1.80 -                temp[i] = 1;
    1.81 -
    1.82 -            previous = current;
    1.83 -            previous_refresh = current_refresh;
    1.84 -        }
    1.85 -        result = 1;
    1.86 -    }
    1.87 -    *bitmap = temp;
    1.88 -    return result;
    1.89 -}
    1.90 -#endif
    1.91 -
    1.92  static void get_real_resolution(_THIS, int* w, int* h);
    1.93  
    1.94  static void set_best_resolution(_THIS, int width, int height)
    1.95 @@ -178,30 +100,40 @@
    1.96          SDL_NAME(XF86VidModeModeLine) mode;
    1.97          SDL_NAME(XF86VidModeModeInfo) **modes;
    1.98          int i;
    1.99 +        int best_width = 0, best_height = 0;
   1.100          int nmodes;
   1.101 -        char *bitmap;
   1.102  
   1.103          if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) &&
   1.104 -             SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) &&
   1.105 -             get_vidmode_filter(modes, nmodes, &bitmap) ) {
   1.106 +             SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){
   1.107 +            qsort(modes, nmodes, sizeof *modes, cmpmodes);
   1.108  #ifdef XFREE86_DEBUG
   1.109 -            printf("Available modes:\n");
   1.110 +            printf("Available modes (sdl):\n");
   1.111              for ( i = 0; i < nmodes; ++i ) {
   1.112 -                printf("Mode %d: %dx%d\n", i,
   1.113 -                        modes[i]->hdisplay, modes[i]->vdisplay);
   1.114 +                printf("Mode %d: %d x %d @ %d\n", i,
   1.115 +                        modes[i]->hdisplay, modes[i]->vdisplay,
   1.116 +                        1000 * modes[i]->dotclock / (modes[i]->htotal *
   1.117 +                        modes[i]->vtotal) );
   1.118              }
   1.119  #endif
   1.120 -            for ( i = nmodes-1; i > 0 ; --i ) {
   1.121 +            for ( i = 0; i < nmodes ; i++ ) {
   1.122                  if ( (modes[i]->hdisplay == width) &&
   1.123 -                     (modes[i]->vdisplay == height) &&
   1.124 -                     (bitmap[i] == 1) )
   1.125 +                     (modes[i]->vdisplay == height) )
   1.126                      goto match;
   1.127              }
   1.128 -            for ( i = nmodes-1; i > 0 ; --i ) {
   1.129 -                if ( (modes[i]->hdisplay >= width) &&
   1.130 -                     (modes[i]->vdisplay >= height) &&
   1.131 -                     (bitmap[i] == 1) )
   1.132 -                    break;
   1.133 +            for ( i = nmodes-1; i >= 0 ; i-- ) {
   1.134 +		if ( ! best_width ) {
   1.135 +                    if ( (modes[i]->hdisplay >= width) &&
   1.136 +                         (modes[i]->vdisplay >= height) ) {
   1.137 +                        best_width = modes[i]->hdisplay;
   1.138 +                        best_height = modes[i]->vdisplay;
   1.139 +                    }
   1.140 +                } else {
   1.141 +                    if ( (modes[i]->hdisplay != best_width) ||
   1.142 +                         (modes[i]->vdisplay != best_height) ) {
   1.143 +                        i++;
   1.144 +                        break;
   1.145 +                    }
   1.146 +                }
   1.147              }
   1.148         match:
   1.149              if ( (modes[i]->hdisplay != mode.hdisplay) ||
   1.150 @@ -209,7 +141,6 @@
   1.151                  SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]);
   1.152              }
   1.153              XFree(modes);
   1.154 -            if (bitmap) free(bitmap);
   1.155          }
   1.156      }
   1.157  #endif /* XFREE86_VM */
   1.158 @@ -357,7 +288,6 @@
   1.159      int vm_major, vm_minor;
   1.160      int nmodes;
   1.161      SDL_NAME(XF86VidModeModeInfo) **modes;
   1.162 -    char *bitmap = (char*)0;
   1.163  #endif
   1.164  #ifdef HAVE_XIGXME
   1.165      int xme_major, xme_minor;
   1.166 @@ -419,18 +349,25 @@
   1.167          }
   1.168      }
   1.169      if ( ! buggy_X11 &&
   1.170 -         SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) &&
   1.171 -         get_vidmode_filter(modes, nmodes, &bitmap) ) {
   1.172 +         SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) {
   1.173  
   1.174 +#ifdef XFREE86_DEBUG
   1.175 +        printf("Available modes (x11):\n");
   1.176 +        for ( i = 0; i < nmodes; ++i ) {
   1.177 +            printf("Mode %d: %d x %d @ %d\n", i,
   1.178 +                    modes[i]->hdisplay, modes[i]->vdisplay,
   1.179 +                    1000 * modes[i]->dotclock / (modes[i]->htotal *
   1.180 +                    modes[i]->vtotal) );
   1.181 +        }
   1.182 +#endif
   1.183 +
   1.184 +        qsort(modes, nmodes, sizeof *modes, cmpmodes);
   1.185          SDL_modelist = (SDL_Rect **)malloc((nmodes+2)*sizeof(SDL_Rect *));
   1.186          if ( SDL_modelist ) {
   1.187              n = 0;
   1.188              for ( i=0; i<nmodes; ++i ) {
   1.189                  int w, h;
   1.190  
   1.191 -                /* Exclude those vidmodes that have been filtered out */
   1.192 -                if (!bitmap[i]) continue;
   1.193 -
   1.194                  /* Check to see if we should add the screen size (Xinerama) */
   1.195                  w = modes[i]->hdisplay;
   1.196                  h = modes[i]->vdisplay;
   1.197 @@ -463,7 +400,6 @@
   1.198              SDL_modelist[n] = NULL;
   1.199          }
   1.200          XFree(modes);
   1.201 -        if (bitmap) free(bitmap);
   1.202  
   1.203          use_vidmode = vm_major * 100 + vm_minor;
   1.204          save_mode(this);