Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11modes.c @ 637:6862d4294870
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.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 28 Jun 2003 17:16:52 +0000 |
parents | 0b4c3f5ff63d |
children | df178851293b |
comparison
equal
deleted
inserted
replaced
636:d9c2ab142f2f | 637:6862d4294870 |
---|---|
42 #ifdef HAVE_XINERAMA | 42 #ifdef HAVE_XINERAMA |
43 #include <XFree86/extensions/Xinerama.h> | 43 #include <XFree86/extensions/Xinerama.h> |
44 #endif | 44 #endif |
45 | 45 |
46 #define MAX(a, b) (a > b ? a : b) | 46 #define MAX(a, b) (a > b ? a : b) |
47 #define V_INTERLACE 0x010 | |
48 #define V_DBLSCAN 0x020 | |
49 | 47 |
50 #ifdef XFREE86_VM | 48 #ifdef XFREE86_VM |
51 Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info) | 49 Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info) |
52 { | 50 { |
53 SDL_NAME(XF86VidModeModeLine) *l = (SDL_NAME(XF86VidModeModeLine)*)((char*)info + sizeof info->dotclock); | 51 SDL_NAME(XF86VidModeModeLine) *l = (SDL_NAME(XF86VidModeModeLine)*)((char*)info + sizeof info->dotclock); |
91 return -1; | 89 return -1; |
92 return b->vdisplay - a->vdisplay; | 90 return b->vdisplay - a->vdisplay; |
93 } | 91 } |
94 #endif | 92 #endif |
95 | 93 |
96 #ifdef XFREE86_VM | |
97 static int get_vidmode_filter(SDL_NAME(XF86VidModeModeInfo) **modes, int nmodes, char **bitmap) | |
98 { | |
99 int i, result = 0; | |
100 int use_all_modes, use_specific_mode; | |
101 const char *variable; | |
102 char *temp; | |
103 | |
104 if (!nmodes) | |
105 return 0; | |
106 | |
107 temp = (char *)malloc((nmodes)*sizeof(char)); | |
108 if (!temp) | |
109 return 0; | |
110 | |
111 for ( i = 0; i < nmodes; ++i ) | |
112 temp[i] = 0; | |
113 | |
114 variable = getenv("SDL_VIDEO_X11_USE_ALL_MODES"); | |
115 use_all_modes = variable ? atoi(variable) : 0; | |
116 variable = getenv("SDL_VIDEO_X11_USE_SPECIFIC_MODE"); | |
117 use_specific_mode = variable ? atoi(variable) : 0; | |
118 | |
119 qsort(modes, nmodes, sizeof *modes, cmpmodes); | |
120 | |
121 if ( use_all_modes ) { | |
122 for ( i = 0; i < nmodes; ++i ) | |
123 temp[i] = 1; | |
124 result = 1; | |
125 /* } else if ( use_specific_mode ) { ... */ | |
126 } else { | |
127 int previous_refresh, current_refresh; | |
128 SDL_NAME(XF86VidModeModeInfo) *previous, *current; | |
129 | |
130 previous = modes[0]; | |
131 previous_refresh = (int)(previous->dotclock * 1000.0 / | |
132 (previous->htotal * previous->vtotal)); | |
133 if ( previous->flags & V_INTERLACE ) previous_refresh *= 2; | |
134 else if ( previous->flags & V_DBLSCAN ) previous_refresh /= 2; | |
135 | |
136 temp[0] = 1; | |
137 for ( i = 1; i < nmodes; ++i ) { | |
138 current = modes[i]; | |
139 current_refresh = (int)(current->dotclock * 1000.0 / | |
140 (current->htotal * current->vtotal)); | |
141 if ( current->flags & V_INTERLACE ) current_refresh *= 2; | |
142 else if ( current->flags & V_DBLSCAN ) current_refresh /= 2; | |
143 | |
144 /* Compare this mode to the previous one */ | |
145 if ( current->hdisplay == previous->hdisplay && | |
146 current->vdisplay == previous->vdisplay ) { | |
147 #ifdef XFREE86_DEBUG | |
148 printf("Comparing %dx%d at %d Hz and %d Hz\n", | |
149 current->hdisplay, current->vdisplay, | |
150 current_refresh, previous_refresh); | |
151 #endif | |
152 if ( current_refresh > previous_refresh ) { | |
153 temp[i-1] = 0; | |
154 temp[i] = 1; | |
155 } | |
156 else | |
157 temp[i] = 0; | |
158 } | |
159 else | |
160 temp[i] = 1; | |
161 | |
162 previous = current; | |
163 previous_refresh = current_refresh; | |
164 } | |
165 result = 1; | |
166 } | |
167 *bitmap = temp; | |
168 return result; | |
169 } | |
170 #endif | |
171 | |
172 static void get_real_resolution(_THIS, int* w, int* h); | 94 static void get_real_resolution(_THIS, int* w, int* h); |
173 | 95 |
174 static void set_best_resolution(_THIS, int width, int height) | 96 static void set_best_resolution(_THIS, int width, int height) |
175 { | 97 { |
176 #ifdef XFREE86_VM | 98 #ifdef XFREE86_VM |
177 if ( use_vidmode ) { | 99 if ( use_vidmode ) { |
178 SDL_NAME(XF86VidModeModeLine) mode; | 100 SDL_NAME(XF86VidModeModeLine) mode; |
179 SDL_NAME(XF86VidModeModeInfo) **modes; | 101 SDL_NAME(XF86VidModeModeInfo) **modes; |
180 int i; | 102 int i; |
103 int best_width = 0, best_height = 0; | |
181 int nmodes; | 104 int nmodes; |
182 char *bitmap; | |
183 | 105 |
184 if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) && | 106 if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) && |
185 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) && | 107 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){ |
186 get_vidmode_filter(modes, nmodes, &bitmap) ) { | 108 qsort(modes, nmodes, sizeof *modes, cmpmodes); |
187 #ifdef XFREE86_DEBUG | 109 #ifdef XFREE86_DEBUG |
188 printf("Available modes:\n"); | 110 printf("Available modes (sdl):\n"); |
189 for ( i = 0; i < nmodes; ++i ) { | 111 for ( i = 0; i < nmodes; ++i ) { |
190 printf("Mode %d: %dx%d\n", i, | 112 printf("Mode %d: %d x %d @ %d\n", i, |
191 modes[i]->hdisplay, modes[i]->vdisplay); | 113 modes[i]->hdisplay, modes[i]->vdisplay, |
192 } | 114 1000 * modes[i]->dotclock / (modes[i]->htotal * |
193 #endif | 115 modes[i]->vtotal) ); |
194 for ( i = nmodes-1; i > 0 ; --i ) { | 116 } |
117 #endif | |
118 for ( i = 0; i < nmodes ; i++ ) { | |
195 if ( (modes[i]->hdisplay == width) && | 119 if ( (modes[i]->hdisplay == width) && |
196 (modes[i]->vdisplay == height) && | 120 (modes[i]->vdisplay == height) ) |
197 (bitmap[i] == 1) ) | |
198 goto match; | 121 goto match; |
199 } | 122 } |
200 for ( i = nmodes-1; i > 0 ; --i ) { | 123 for ( i = nmodes-1; i >= 0 ; i-- ) { |
201 if ( (modes[i]->hdisplay >= width) && | 124 if ( ! best_width ) { |
202 (modes[i]->vdisplay >= height) && | 125 if ( (modes[i]->hdisplay >= width) && |
203 (bitmap[i] == 1) ) | 126 (modes[i]->vdisplay >= height) ) { |
204 break; | 127 best_width = modes[i]->hdisplay; |
128 best_height = modes[i]->vdisplay; | |
129 } | |
130 } else { | |
131 if ( (modes[i]->hdisplay != best_width) || | |
132 (modes[i]->vdisplay != best_height) ) { | |
133 i++; | |
134 break; | |
135 } | |
136 } | |
205 } | 137 } |
206 match: | 138 match: |
207 if ( (modes[i]->hdisplay != mode.hdisplay) || | 139 if ( (modes[i]->hdisplay != mode.hdisplay) || |
208 (modes[i]->vdisplay != mode.vdisplay) ) { | 140 (modes[i]->vdisplay != mode.vdisplay) ) { |
209 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]); | 141 SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]); |
210 } | 142 } |
211 XFree(modes); | 143 XFree(modes); |
212 if (bitmap) free(bitmap); | |
213 } | 144 } |
214 } | 145 } |
215 #endif /* XFREE86_VM */ | 146 #endif /* XFREE86_VM */ |
216 | 147 |
217 /* XiG */ | 148 /* XiG */ |
355 #ifdef XFREE86_VM | 286 #ifdef XFREE86_VM |
356 int buggy_X11; | 287 int buggy_X11; |
357 int vm_major, vm_minor; | 288 int vm_major, vm_minor; |
358 int nmodes; | 289 int nmodes; |
359 SDL_NAME(XF86VidModeModeInfo) **modes; | 290 SDL_NAME(XF86VidModeModeInfo) **modes; |
360 char *bitmap = (char*)0; | |
361 #endif | 291 #endif |
362 #ifdef HAVE_XIGXME | 292 #ifdef HAVE_XIGXME |
363 int xme_major, xme_minor; | 293 int xme_major, xme_minor; |
364 int ractive, nummodes; | 294 int ractive, nummodes; |
365 XiGMiscResolutionInfo *modelist; | 295 XiGMiscResolutionInfo *modelist; |
417 } else { | 347 } else { |
418 buggy_X11 = 1; | 348 buggy_X11 = 1; |
419 } | 349 } |
420 } | 350 } |
421 if ( ! buggy_X11 && | 351 if ( ! buggy_X11 && |
422 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) && | 352 SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) { |
423 get_vidmode_filter(modes, nmodes, &bitmap) ) { | 353 |
424 | 354 #ifdef XFREE86_DEBUG |
355 printf("Available modes (x11):\n"); | |
356 for ( i = 0; i < nmodes; ++i ) { | |
357 printf("Mode %d: %d x %d @ %d\n", i, | |
358 modes[i]->hdisplay, modes[i]->vdisplay, | |
359 1000 * modes[i]->dotclock / (modes[i]->htotal * | |
360 modes[i]->vtotal) ); | |
361 } | |
362 #endif | |
363 | |
364 qsort(modes, nmodes, sizeof *modes, cmpmodes); | |
425 SDL_modelist = (SDL_Rect **)malloc((nmodes+2)*sizeof(SDL_Rect *)); | 365 SDL_modelist = (SDL_Rect **)malloc((nmodes+2)*sizeof(SDL_Rect *)); |
426 if ( SDL_modelist ) { | 366 if ( SDL_modelist ) { |
427 n = 0; | 367 n = 0; |
428 for ( i=0; i<nmodes; ++i ) { | 368 for ( i=0; i<nmodes; ++i ) { |
429 int w, h; | 369 int w, h; |
430 | |
431 /* Exclude those vidmodes that have been filtered out */ | |
432 if (!bitmap[i]) continue; | |
433 | 370 |
434 /* Check to see if we should add the screen size (Xinerama) */ | 371 /* Check to see if we should add the screen size (Xinerama) */ |
435 w = modes[i]->hdisplay; | 372 w = modes[i]->hdisplay; |
436 h = modes[i]->vdisplay; | 373 h = modes[i]->vdisplay; |
437 if ( (screen_w * screen_h) >= (w * h) ) { | 374 if ( (screen_w * screen_h) >= (w * h) ) { |
461 ++n; | 398 ++n; |
462 } | 399 } |
463 SDL_modelist[n] = NULL; | 400 SDL_modelist[n] = NULL; |
464 } | 401 } |
465 XFree(modes); | 402 XFree(modes); |
466 if (bitmap) free(bitmap); | |
467 | 403 |
468 use_vidmode = vm_major * 100 + vm_minor; | 404 use_vidmode = vm_major * 100 + vm_minor; |
469 save_mode(this); | 405 save_mode(this); |
470 } | 406 } |
471 #endif /* XFREE86_VM */ | 407 #endif /* XFREE86_VM */ |