]>
Commit | Line | Data |
---|---|---|
e63c03ea AM |
1 | diff -urN SDL-1.2.5.old/src/video/x11/SDL_x11modes.c SDL-1.2.5/src/video/x11/SDL_x11modes.c |
2 | --- SDL-1.2.5.old/src/video/x11/SDL_x11modes.c 2002-09-29 17:35:25.000000000 -0700 | |
3 | +++ SDL-1.2.5/src/video/x11/SDL_x11modes.c 2003-04-13 22:03:43.000000000 -0700 | |
4 | @@ -44,6 +44,8 @@ | |
5 | #endif | |
6 | ||
7 | #define MAX(a, b) (a > b ? a : b) | |
8 | +#define V_INTERLACE 0x010 | |
9 | +#define V_DBLSCAN 0x020 | |
10 | ||
11 | #ifdef XFREE86_VM | |
12 | Bool SDL_NAME(XF86VidModeGetModeInfo)(Display *dpy, int scr, SDL_NAME(XF86VidModeModeInfo) *info) | |
13 | @@ -91,6 +93,77 @@ | |
14 | } | |
15 | #endif | |
16 | ||
17 | +#ifdef XFREE86_VM | |
18 | +static int get_vidmode_filter(SDL_NAME(XF86VidModeModeInfo) **modes, int nmodes, char **bitmap) | |
19 | +{ | |
20 | + int i, result = 0; | |
21 | + int use_all_modes, use_specific_mode; | |
22 | + const char *variable; | |
23 | + char *temp; | |
24 | + | |
25 | + if (!nmodes) | |
26 | + return 0; | |
27 | + | |
28 | + temp = (char *)malloc((nmodes)*sizeof(char)); | |
29 | + if (!temp) | |
30 | + return 0; | |
31 | + | |
32 | + for ( i = 0; i < nmodes; ++i ) | |
33 | + temp[i] = 0; | |
34 | + | |
35 | + variable = getenv("SDL_VIDEO_X11_USE_ALL_MODES"); | |
36 | + use_all_modes = variable ? atoi(variable) : 0; | |
37 | + variable = getenv("SDL_VIDEO_X11_USE_SPECIFIC_MODE"); | |
38 | + use_specific_mode = variable ? atoi(variable) : 0; | |
39 | + | |
40 | + qsort(modes, nmodes, sizeof *modes, cmpmodes); | |
41 | + | |
42 | + if ( use_all_modes ) { | |
43 | + for ( i = 0; i < nmodes; ++i ) | |
44 | + temp[i] = 1; | |
45 | + result = 1; | |
46 | +/* } else if ( use_specific_mode ) { ... */ | |
47 | + } else { | |
48 | + int previous_refresh, current_refresh; | |
49 | + SDL_NAME(XF86VidModeModeInfo) *previous, *current; | |
50 | + | |
51 | + previous = modes[0]; | |
52 | + previous_refresh = (int)(previous->dotclock * 1000.0 / | |
53 | + (previous->htotal * previous->vtotal)); | |
54 | + if ( previous->flags & V_INTERLACE ) previous_refresh *= 2; | |
55 | + else if ( previous->flags & V_DBLSCAN ) previous_refresh /= 2; | |
56 | + | |
57 | + temp[0] = 1; | |
58 | + for ( i = 1; i < nmodes; ++i ) { | |
59 | + current = modes[i]; | |
60 | + current_refresh = (int)(current->dotclock * 1000.0 / | |
61 | + (current->htotal * current->vtotal)); | |
62 | + if ( current->flags & V_INTERLACE ) current_refresh *= 2; | |
63 | + else if ( current->flags & V_DBLSCAN ) current_refresh /= 2; | |
64 | + | |
65 | + /* Compare this mode to the previous one */ | |
66 | + if ( current->hdisplay == previous->hdisplay && | |
67 | + current->vdisplay == previous->vdisplay ) { | |
68 | + if ( current_refresh > previous_refresh ) { | |
69 | + temp[i-1] = 0; | |
70 | + temp[i] = 1; | |
71 | + } | |
72 | + else | |
73 | + temp[i] = 0; | |
74 | + } | |
75 | + else | |
76 | + temp[i] = 1; | |
77 | + | |
78 | + previous = current; | |
79 | + previous_refresh = current_refresh; | |
80 | + } | |
81 | + result = 1; | |
82 | + } | |
83 | + *bitmap = temp; | |
84 | + return result; | |
85 | +} | |
86 | +#endif | |
87 | + | |
88 | static void get_real_resolution(_THIS, int* w, int* h); | |
89 | ||
90 | static void set_best_resolution(_THIS, int width, int height) | |
91 | @@ -101,10 +174,11 @@ | |
92 | SDL_NAME(XF86VidModeModeInfo) **modes; | |
93 | int i; | |
94 | int nmodes; | |
95 | + char *bitmap; | |
96 | ||
97 | if ( SDL_NAME(XF86VidModeGetModeLine)(SDL_Display, SDL_Screen, &i, &mode) && | |
98 | - SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes)){ | |
99 | - qsort(modes, nmodes, sizeof *modes, cmpmodes); | |
100 | + SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display,SDL_Screen,&nmodes,&modes) && | |
101 | + get_vidmode_filter(modes, nmodes, &bitmap) ) { | |
102 | #ifdef XFREE86_DEBUG | |
103 | printf("Available modes:\n"); | |
104 | for ( i = 0; i < nmodes; ++i ) { | |
105 | @@ -114,7 +188,8 @@ | |
106 | #endif | |
107 | for ( i = nmodes-1; i > 0 ; --i ) { | |
108 | if ( (modes[i]->hdisplay >= width) && | |
109 | - (modes[i]->vdisplay >= height) ) | |
110 | + (modes[i]->vdisplay >= height) && | |
111 | + (bitmap[i] == 1) ) | |
112 | break; | |
113 | } | |
114 | if ( (modes[i]->hdisplay != mode.hdisplay) || | |
115 | @@ -122,6 +197,7 @@ | |
116 | SDL_NAME(XF86VidModeSwitchToMode)(SDL_Display, SDL_Screen, modes[i]); | |
117 | } | |
118 | XFree(modes); | |
119 | + if (bitmap) free(bitmap); | |
120 | } | |
121 | } | |
122 | #endif /* XFREE86_VM */ | |
123 | @@ -269,6 +345,7 @@ | |
124 | int vm_major, vm_minor; | |
125 | int nmodes; | |
126 | SDL_NAME(XF86VidModeModeInfo) **modes; | |
127 | + char *bitmap = (char*)0; | |
128 | #endif | |
129 | #ifdef HAVE_XIGXME | |
130 | int xme_major, xme_minor; | |
131 | @@ -330,15 +407,18 @@ | |
132 | } | |
133 | } | |
134 | if ( ! buggy_X11 && | |
135 | - SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) ) { | |
136 | + SDL_NAME(XF86VidModeGetAllModeLines)(SDL_Display, SDL_Screen,&nmodes,&modes) && | |
137 | + get_vidmode_filter(modes, nmodes, &bitmap) ) { | |
138 | ||
139 | - qsort(modes, nmodes, sizeof *modes, cmpmodes); | |
140 | SDL_modelist = (SDL_Rect **)malloc((nmodes+2)*sizeof(SDL_Rect *)); | |
141 | if ( SDL_modelist ) { | |
142 | n = 0; | |
143 | for ( i=0; i<nmodes; ++i ) { | |
144 | int w, h; | |
145 | ||
146 | + /* Exclude those vidmodes that have been filtered out */ | |
147 | + if (!bitmap[i]) continue; | |
148 | + | |
149 | /* Check to see if we should add the screen size (Xinerama) */ | |
150 | w = modes[i]->hdisplay; | |
151 | h = modes[i]->vdisplay; | |
152 | @@ -371,6 +451,7 @@ | |
153 | SDL_modelist[n] = NULL; | |
154 | } | |
155 | XFree(modes); | |
156 | + if (bitmap) free(bitmap); | |
157 | ||
158 | use_vidmode = vm_major * 100 + vm_minor; | |
159 | save_mode(this); |