Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
721 lines (640 loc) · 21.7 KB

SDL_x11modes.c

File metadata and controls

721 lines (640 loc) · 21.7 KB
 
Jul 26, 2006
Jul 26, 2006
1
/*
Apr 8, 2011
Apr 8, 2011
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Simple DirectMedia Layer
Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jul 26, 2006
Jul 26, 2006
20
21
22
*/
#include "SDL_config.h"
Mar 12, 2011
Mar 12, 2011
23
24
#if SDL_VIDEO_DRIVER_X11
Jul 26, 2006
Jul 26, 2006
25
26
#include "SDL_x11video.h"
Jul 14, 2010
Jul 14, 2010
27
/*#define X11MODES_DEBUG*/
Jul 26, 2006
Jul 26, 2006
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
static int
get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
{
const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
int depth;
/* Look for an exact visual, if requested */
if (visual_id) {
XVisualInfo *vi, template;
int nvis;
SDL_zero(template);
template.visualid = SDL_strtol(visual_id, NULL, 0);
vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis);
if (vi) {
*vinfo = *vi;
XFree(vi);
return 0;
}
}
depth = DefaultDepth(display, screen);
Mar 11, 2011
Mar 11, 2011
51
52
53
if ((X11_UseDirectColorVisuals() &&
XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
Jul 26, 2006
Jul 26, 2006
54
55
56
57
58
59
60
XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
return 0;
}
return -1;
}
Feb 5, 2011
Feb 5, 2011
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
int
X11_GetVisualInfoFromVisual(Display * display, Visual * visual, XVisualInfo * vinfo)
{
XVisualInfo *vi;
int nvis;
vinfo->visualid = XVisualIDFromVisual(visual);
vi = XGetVisualInfo(display, VisualIDMask, vinfo, &nvis);
if (vi) {
*vinfo = *vi;
XFree(vi);
return 0;
}
return -1;
}
Uint32
Dec 16, 2008
Dec 16, 2008
78
X11_GetPixelFormatFromVisualInfo(Display * display, XVisualInfo * vinfo)
Dec 14, 2008
Dec 14, 2008
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
{
if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
Rmask = vinfo->visual->red_mask;
Gmask = vinfo->visual->green_mask;
Bmask = vinfo->visual->blue_mask;
if (vinfo->depth == 32) {
Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
} else {
Amask = 0;
}
bpp = vinfo->depth;
if (bpp == 24) {
int i, n;
XPixmapFormatValues *p = XListPixmapFormats(display, &n);
if (p) {
for (i = 0; i < n; ++i) {
if (p[i].depth == 24) {
bpp = p[i].bits_per_pixel;
break;
}
}
XFree(p);
}
}
return SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
}
if (vinfo->class == PseudoColor || vinfo->class == StaticColor) {
switch (vinfo->depth) {
case 8:
return SDL_PIXELTYPE_INDEX8;
case 4:
if (BitmapBitOrder(display) == LSBFirst) {
return SDL_PIXELFORMAT_INDEX4LSB;
} else {
return SDL_PIXELFORMAT_INDEX4MSB;
}
break;
case 1:
if (BitmapBitOrder(display) == LSBFirst) {
return SDL_PIXELFORMAT_INDEX1LSB;
} else {
return SDL_PIXELFORMAT_INDEX1MSB;
}
break;
}
}
return SDL_PIXELFORMAT_UNKNOWN;
}
Dec 4, 2009
Dec 4, 2009
135
int
Jul 26, 2006
Jul 26, 2006
136
137
138
139
140
141
142
143
144
145
X11_InitModes(_THIS)
{
SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
int screen;
for (screen = 0; screen < ScreenCount(data->display); ++screen) {
XVisualInfo vinfo;
SDL_VideoDisplay display;
SDL_DisplayData *displaydata;
SDL_DisplayMode mode;
Dec 25, 2008
Dec 25, 2008
146
147
XPixmapFormatValues *pixmapFormats;
int i, n;
Jul 26, 2006
Jul 26, 2006
148
149
150
151
152
if (get_visualinfo(data->display, screen, &vinfo) < 0) {
continue;
}
Dec 14, 2008
Dec 14, 2008
153
mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
Feb 2, 2011
Feb 2, 2011
154
155
156
157
if (SDL_ISPIXELFORMAT_INDEXED(mode.format)) {
/* We don't support palettized modes now */
continue;
}
Jul 26, 2006
Jul 26, 2006
158
159
160
161
162
163
164
165
166
167
168
mode.w = DisplayWidth(data->display, screen);
mode.h = DisplayHeight(data->display, screen);
mode.refresh_rate = 0;
mode.driverdata = NULL;
displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
if (!displaydata) {
continue;
}
displaydata->screen = screen;
displaydata->visual = vinfo.visual;
Jul 27, 2006
Jul 27, 2006
169
displaydata->depth = vinfo.depth;
Jul 26, 2006
Jul 26, 2006
170
Dec 25, 2008
Dec 25, 2008
171
displaydata->scanline_pad = SDL_BYTESPERPIXEL(mode.format) * 8;
Dec 25, 2008
Dec 25, 2008
172
173
174
175
176
177
178
179
180
181
182
pixmapFormats = XListPixmapFormats(data->display, &n);
if (pixmapFormats) {
for (i = 0; i < n; ++i) {
if (pixmapFormats[i].depth == displaydata->depth) {
displaydata->scanline_pad = pixmapFormats[i].scanline_pad;
break;
}
}
XFree(pixmapFormats);
}
Jul 26, 2006
Jul 26, 2006
183
184
185
186
187
188
SDL_zero(display);
display.desktop_mode = mode;
display.current_mode = mode;
display.driverdata = displaydata;
SDL_AddVideoDisplay(&display);
}
Dec 4, 2009
Dec 4, 2009
189
190
191
192
193
if (_this->num_displays == 0) {
SDL_SetError("No available displays");
return -1;
}
return 0;
Jul 26, 2006
Jul 26, 2006
194
195
}
Dec 16, 2008
Dec 16, 2008
196
197
198
199
200
/* Global for the error handler */
int vm_event, vm_error = -1;
#if SDL_VIDEO_DRIVER_X11_XINERAMA
static SDL_bool
Dec 16, 2008
Dec 16, 2008
201
CheckXinerama(Display * display, int *major, int *minor)
Dec 16, 2008
Dec 16, 2008
202
203
204
205
206
207
208
209
210
211
212
213
{
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
env = getenv("SDL_VIDEO_X11_XINERAMA");
if (env && !SDL_atoi(env)) {
return SDL_FALSE;
}
Feb 28, 2011
Feb 28, 2011
214
215
216
217
if (!SDL_X11_HAVE_XINERAMA) {
return SDL_FALSE;
}
Dec 16, 2008
Dec 16, 2008
218
/* Query the extension version */
Feb 28, 2011
Feb 28, 2011
219
220
if (!XineramaQueryExtension(display, major, minor) ||
!XineramaIsActive(display)) {
Dec 16, 2008
Dec 16, 2008
221
222
223
224
225
226
227
228
return SDL_FALSE;
}
return SDL_TRUE;
}
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
#if SDL_VIDEO_DRIVER_X11_XRANDR
static SDL_bool
Dec 16, 2008
Dec 16, 2008
229
CheckXRandR(Display * display, int *major, int *minor)
Dec 16, 2008
Dec 16, 2008
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
{
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
env = getenv("SDL_VIDEO_X11_XRANDR");
if (env && !SDL_atoi(env)) {
return SDL_FALSE;
}
if (!SDL_X11_HAVE_XRANDR) {
return SDL_FALSE;
}
/* Query the extension version */
if (!XRRQueryVersion(display, major, minor)) {
return SDL_FALSE;
}
return SDL_TRUE;
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Feb 28, 2011
Feb 28, 2011
254
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
Dec 16, 2008
Dec 16, 2008
255
static SDL_bool
Dec 16, 2008
Dec 16, 2008
256
CheckVidMode(Display * display, int *major, int *minor)
Dec 16, 2008
Dec 16, 2008
257
258
259
260
261
262
263
{
const char *env;
/* Default the extension not available */
*major = *minor = 0;
/* Allow environment override */
Feb 28, 2011
Feb 28, 2011
264
env = getenv("SDL_VIDEO_X11_XVIDMODE");
Dec 16, 2008
Dec 16, 2008
265
266
267
if (env && !SDL_atoi(env)) {
return SDL_FALSE;
}
Dec 16, 2008
Dec 16, 2008
268
Feb 28, 2011
Feb 28, 2011
269
270
271
272
if (!SDL_X11_HAVE_XVIDMODE) {
return SDL_FALSE;
}
Dec 16, 2008
Dec 16, 2008
273
274
/* Query the extension version */
vm_error = -1;
Feb 28, 2011
Feb 28, 2011
275
276
if (!XF86VidModeQueryExtension(display, &vm_event, &vm_error)
|| !XF86VidModeQueryVersion(display, major, minor)) {
Dec 16, 2008
Dec 16, 2008
277
278
279
280
281
return SDL_FALSE;
}
return SDL_TRUE;
}
Jul 14, 2010
Jul 14, 2010
282
static
Feb 28, 2011
Feb 28, 2011
283
284
Bool XF86VidModeGetModeInfo(Display * dpy, int scr,
XF86VidModeModeInfo* info)
Dec 16, 2008
Dec 16, 2008
285
286
287
{
Bool retval;
int dotclock;
Feb 28, 2011
Feb 28, 2011
288
XF86VidModeModeLine l;
Dec 16, 2008
Dec 16, 2008
289
290
SDL_zerop(info);
SDL_zero(l);
Feb 28, 2011
Feb 28, 2011
291
retval = XF86VidModeGetModeLine(dpy, scr, &dotclock, &l);
Dec 16, 2008
Dec 16, 2008
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
info->dotclock = dotclock;
info->hdisplay = l.hdisplay;
info->hsyncstart = l.hsyncstart;
info->hsyncend = l.hsyncend;
info->htotal = l.htotal;
info->hskew = l.hskew;
info->vdisplay = l.vdisplay;
info->vsyncstart = l.vsyncstart;
info->vsyncend = l.vsyncend;
info->vtotal = l.vtotal;
info->flags = l.flags;
info->privsize = l.privsize;
info->private = l.private;
return retval;
}
static int
Feb 28, 2011
Feb 28, 2011
309
calculate_rate(XF86VidModeModeInfo * info)
Dec 16, 2008
Dec 16, 2008
310
{
Dec 16, 2008
Dec 16, 2008
311
312
313
return (info->htotal
&& info->vtotal) ? (1000 * info->dotclock / (info->htotal *
info->vtotal)) : 0;
Dec 16, 2008
Dec 16, 2008
314
315
316
}
static void
Dec 16, 2008
Dec 16, 2008
317
save_mode(Display * display, SDL_DisplayData * data)
Dec 16, 2008
Dec 16, 2008
318
{
Feb 28, 2011
Feb 28, 2011
319
320
321
322
323
XF86VidModeGetModeInfo(display, data->screen,
&data->saved_mode);
XF86VidModeGetViewPort(display, data->screen,
&data->saved_view.x,
&data->saved_view.y);
Dec 16, 2008
Dec 16, 2008
324
325
}
Jul 14, 2010
Jul 14, 2010
326
/*
Dec 16, 2008
Dec 16, 2008
327
static void
Dec 16, 2008
Dec 16, 2008
328
restore_mode(Display * display, SDL_DisplayData * data)
Dec 16, 2008
Dec 16, 2008
329
{
Feb 28, 2011
Feb 28, 2011
330
XF86VidModeModeInfo mode;
Dec 16, 2008
Dec 16, 2008
331
Feb 28, 2011
Feb 28, 2011
332
if (XF86VidModeGetModeInfo(display, data->screen, &mode)) {
Dec 16, 2008
Dec 16, 2008
333
if (SDL_memcmp(&mode, &data->saved_mode, sizeof(mode)) != 0) {
Feb 28, 2011
Feb 28, 2011
334
XF86VidModeSwitchToMode(display, data->screen, &data->saved_mode);
Dec 16, 2008
Dec 16, 2008
335
336
337
}
}
if ((data->saved_view.x != 0) || (data->saved_view.y != 0)) {
Feb 28, 2011
Feb 28, 2011
338
339
340
XF86VidModeSetViewPort(display, data->screen,
data->saved_view.x,
data->saved_view.y);
Dec 16, 2008
Dec 16, 2008
341
342
}
}
Jul 14, 2010
Jul 14, 2010
343
*/
Feb 28, 2011
Feb 28, 2011
344
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
Dec 16, 2008
Dec 16, 2008
345
Jul 26, 2006
Jul 26, 2006
346
void
Dec 1, 2009
Dec 1, 2009
347
X11_GetDisplayModes(_THIS, SDL_VideoDisplay * sdl_display)
Jul 26, 2006
Jul 26, 2006
348
{
Dec 14, 2008
Dec 14, 2008
349
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
Dec 1, 2009
Dec 1, 2009
350
SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
Dec 16, 2008
Dec 16, 2008
351
352
353
#if SDL_VIDEO_DRIVER_X11_XINERAMA
int xinerama_major, xinerama_minor;
int screens;
Feb 28, 2011
Feb 28, 2011
354
XineramaScreenInfo * xinerama;
Dec 16, 2008
Dec 16, 2008
355
356
357
358
359
360
361
#endif
#if SDL_VIDEO_DRIVER_X11_XRANDR
int xrandr_major, xrandr_minor;
int nsizes, nrates;
XRRScreenSize *sizes;
short *rates;
#endif
Feb 28, 2011
Feb 28, 2011
362
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
Dec 16, 2008
Dec 16, 2008
363
364
int vm_major, vm_minor;
int nmodes;
Feb 28, 2011
Feb 28, 2011
365
XF86VidModeModeInfo ** modes;
Dec 16, 2008
Dec 16, 2008
366
367
368
#endif
int screen_w;
int screen_h;
Jul 26, 2006
Jul 26, 2006
369
SDL_DisplayMode mode;
Dec 14, 2008
Dec 14, 2008
370
Dec 16, 2008
Dec 16, 2008
371
372
373
374
375
376
/* Unfortunately X11 requires the window to be created with the correct
* visual and depth ahead of time, but the SDL API allows you to create
* a window before setting the fullscreen display mode. This means that
* we have to use the same format for all windows and all display modes.
* (or support recreating the window with a new visual behind the scenes)
*/
Dec 1, 2009
Dec 1, 2009
377
mode.format = sdl_display->current_mode.format;
Dec 16, 2008
Dec 16, 2008
378
379
380
381
382
383
384
385
386
387
388
389
390
391
mode.driverdata = NULL;
data->use_xinerama = 0;
data->use_xrandr = 0;
data->use_vidmode = 0;
screen_w = DisplayWidth(display, data->screen);
screen_h = DisplayHeight(display, data->screen);
#if SDL_VIDEO_DRIVER_X11_XINERAMA
/* Query Xinerama extention */
if (CheckXinerama(display, &xinerama_major, &xinerama_minor)) {
#ifdef X11MODES_DEBUG
printf("X11 detected Xinerama:\n");
#endif
Feb 28, 2011
Feb 28, 2011
392
xinerama = XineramaQueryScreens(display, &screens);
Dec 16, 2008
Dec 16, 2008
393
394
395
396
397
if (xinerama) {
int i;
for (i = 0; i < screens; i++) {
#ifdef X11MODES_DEBUG
printf("xinerama %d: %dx%d+%d+%d\n",
Dec 16, 2008
Dec 16, 2008
398
399
400
xinerama[i].screen_number,
xinerama[i].width, xinerama[i].height,
xinerama[i].x_org, xinerama[i].y_org);
Dec 16, 2008
Dec 16, 2008
401
402
#endif
if (xinerama[i].screen_number == data->screen) {
Dec 16, 2008
Dec 16, 2008
403
404
data->use_xinerama =
xinerama_major * 100 + xinerama_minor;
Dec 16, 2008
Dec 16, 2008
405
406
407
408
409
410
411
412
413
414
415
416
417
data->xinerama_info = xinerama[i];
}
}
XFree(xinerama);
}
if (data->use_xinerama) {
/* Add the full xinerama mode */
if (screen_w > data->xinerama_info.width ||
screen_h > data->xinerama_info.height) {
mode.w = screen_w;
mode.h = screen_h;
mode.refresh_rate = 0;
Dec 1, 2009
Dec 1, 2009
418
SDL_AddDisplayMode(sdl_display, &mode);
Dec 16, 2008
Dec 16, 2008
419
420
421
422
423
424
}
/* Add the head xinerama mode */
mode.w = data->xinerama_info.width;
mode.h = data->xinerama_info.height;
mode.refresh_rate = 0;
Dec 1, 2009
Dec 1, 2009
425
SDL_AddDisplayMode(sdl_display, &mode);
Dec 16, 2008
Dec 16, 2008
426
427
428
429
430
431
432
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
#if SDL_VIDEO_DRIVER_X11_XRANDR
/* XRandR */
/* require at least XRandR v1.0 (arbitrary) */
Dec 16, 2008
Dec 16, 2008
433
434
if (CheckXRandR(display, &xrandr_major, &xrandr_minor)
&& xrandr_major >= 1) {
Dec 16, 2008
Dec 16, 2008
435
436
437
438
439
440
441
#ifdef X11MODES_DEBUG
fprintf(stderr, "XRANDR: XRRQueryVersion: V%d.%d\n",
xrandr_major, xrandr_minor);
#endif
/* save the screen configuration since we must reference it
each time we toggle modes.
Dec 16, 2008
Dec 16, 2008
442
443
444
*/
data->screen_config =
XRRGetScreenInfo(display, RootWindow(display, data->screen));
Dec 16, 2008
Dec 16, 2008
445
446
447
448
449
/* retrieve the list of resolution */
sizes = XRRConfigSizes(data->screen_config, &nsizes);
if (nsizes > 0) {
int i, j;
Dec 16, 2008
Dec 16, 2008
450
for (i = 0; i < nsizes; i++) {
Dec 16, 2008
Dec 16, 2008
451
452
453
454
455
456
457
mode.w = sizes[i].width;
mode.h = sizes[i].height;
rates = XRRConfigRates(data->screen_config, i, &nrates);
for (j = 0; j < nrates; ++j) {
mode.refresh_rate = rates[j];
#ifdef X11MODES_DEBUG
Dec 16, 2008
Dec 16, 2008
458
459
fprintf(stderr,
"XRANDR: mode = %4d[%d], w = %4d, h = %4d, rate = %4d\n",
Dec 16, 2008
Dec 16, 2008
460
461
i, j, mode.w, mode.h, mode.refresh_rate);
#endif
Dec 1, 2009
Dec 1, 2009
462
SDL_AddDisplayMode(sdl_display, &mode);
Dec 16, 2008
Dec 16, 2008
463
464
465
466
}
}
data->use_xrandr = xrandr_major * 100 + xrandr_minor;
Dec 16, 2008
Dec 16, 2008
467
468
469
data->saved_size =
XRRConfigCurrentConfiguration(data->screen_config,
&data->saved_rotation);
Dec 16, 2008
Dec 16, 2008
470
471
472
473
474
data->saved_rate = XRRConfigCurrentRate(data->screen_config);
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Feb 28, 2011
Feb 28, 2011
475
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
Dec 16, 2008
Dec 16, 2008
476
477
478
479
480
481
/* XVidMode */
if (!data->use_xrandr &&
#if SDL_VIDEO_DRIVER_X11_XINERAMA
(!data->use_xinerama || data->xinerama_info.screen_number == 0) &&
#endif
CheckVidMode(display, &vm_major, &vm_minor) &&
Feb 28, 2011
Feb 28, 2011
482
XF86VidModeGetAllModeLines(display, data->screen, &nmodes, &modes)) {
Dec 16, 2008
Dec 16, 2008
483
484
485
486
487
488
int i;
#ifdef X11MODES_DEBUG
printf("VidMode modes: (unsorted)\n");
for (i = 0; i < nmodes; ++i) {
printf("Mode %d: %d x %d @ %d\n", i,
Dec 16, 2008
Dec 16, 2008
489
490
modes[i]->hdisplay, modes[i]->vdisplay,
calculate_rate(modes[i]));
Dec 16, 2008
Dec 16, 2008
491
492
493
494
495
496
}
#endif
for (i = 0; i < nmodes; ++i) {
mode.w = modes[i]->hdisplay;
mode.h = modes[i]->vdisplay;
mode.refresh_rate = calculate_rate(modes[i]);
Dec 1, 2009
Dec 1, 2009
497
SDL_AddDisplayMode(sdl_display, &mode);
Dec 16, 2008
Dec 16, 2008
498
499
500
501
502
503
}
XFree(modes);
data->use_vidmode = vm_major * 100 + vm_minor;
save_mode(display, data);
}
Feb 28, 2011
Feb 28, 2011
504
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
Dec 16, 2008
Dec 16, 2008
505
506
507
508
509
if (!data->use_xrandr && !data->use_vidmode) {
mode.w = screen_w;
mode.h = screen_h;
mode.refresh_rate = 0;
Dec 1, 2009
Dec 1, 2009
510
SDL_AddDisplayMode(sdl_display, &mode);
Dec 16, 2008
Dec 16, 2008
511
}
Dec 16, 2008
Dec 16, 2008
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
#ifdef X11MODES_DEBUG
if (data->use_xinerama) {
printf("Xinerama is enabled\n");
}
if (data->use_xrandr) {
printf("XRandR is enabled\n");
}
if (data->use_vidmode) {
printf("VidMode is enabled\n");
}
#endif /* X11MODES_DEBUG */
}
static void
Dec 16, 2008
Dec 16, 2008
528
529
get_real_resolution(Display * display, SDL_DisplayData * data, int *w, int *h,
int *rate)
Dec 16, 2008
Dec 16, 2008
530
531
532
533
534
{
#if SDL_VIDEO_DRIVER_X11_XRANDR
if (data->use_xrandr) {
int nsizes;
XRRScreenSize *sizes;
Dec 16, 2008
Dec 16, 2008
535
Dec 16, 2008
Dec 16, 2008
536
537
538
539
540
sizes = XRRConfigSizes(data->screen_config, &nsizes);
if (nsizes > 0) {
int cur_size;
Rotation cur_rotation;
Dec 16, 2008
Dec 16, 2008
541
542
543
cur_size =
XRRConfigCurrentConfiguration(data->screen_config,
&cur_rotation);
Dec 16, 2008
Dec 16, 2008
544
545
546
547
*w = sizes[cur_size].width;
*h = sizes[cur_size].height;
*rate = XRRConfigCurrentRate(data->screen_config);
#ifdef X11MODES_DEBUG
Dec 16, 2008
Dec 16, 2008
548
549
550
fprintf(stderr,
"XRANDR: get_real_resolution: w = %d, h = %d, rate = %d\n",
*w, *h, *rate);
Dec 16, 2008
Dec 16, 2008
551
552
553
554
555
556
#endif
return;
}
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Feb 28, 2011
Feb 28, 2011
557
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
Dec 16, 2008
Dec 16, 2008
558
if (data->use_vidmode) {
Feb 28, 2011
Feb 28, 2011
559
XF86VidModeModeInfo mode;
Dec 16, 2008
Dec 16, 2008
560
Feb 28, 2011
Feb 28, 2011
561
if (XF86VidModeGetModeInfo(display, data->screen, &mode)) {
Dec 16, 2008
Dec 16, 2008
562
563
564
565
566
567
*w = mode.hdisplay;
*h = mode.vdisplay;
*rate = calculate_rate(&mode);
return;
}
}
Feb 28, 2011
Feb 28, 2011
568
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
Dec 16, 2008
Dec 16, 2008
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
#if SDL_VIDEO_DRIVER_X11_XINERAMA
if (data->use_xinerama) {
*w = data->xinerama_info.width;
*h = data->xinerama_info.height;
*rate = 0;
return;
}
#endif /* SDL_VIDEO_DRIVER_X11_XINERAMA */
*w = DisplayWidth(display, data->screen);
*h = DisplayHeight(display, data->screen);
*rate = 0;
}
static void
Dec 16, 2008
Dec 16, 2008
585
586
set_best_resolution(Display * display, SDL_DisplayData * data, int w, int h,
int rate)
Dec 16, 2008
Dec 16, 2008
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
{
int real_w, real_h, real_rate;
/* check current mode so we can avoid uneccessary mode changes */
get_real_resolution(display, data, &real_w, &real_h, &real_rate);
if (w == real_w && h == real_h && (!rate || rate == real_rate)) {
return;
}
#if SDL_VIDEO_DRIVER_X11_XRANDR
if (data->use_xrandr) {
#ifdef X11MODES_DEBUG
fprintf(stderr, "XRANDR: set_best_resolution(): w = %d, h = %d\n",
w, h);
#endif
int i, nsizes, nrates;
int best;
int best_rate;
XRRScreenSize *sizes;
short *rates;
/* find the smallest resolution that is at least as big as the user requested */
best = -1;
sizes = XRRConfigSizes(data->screen_config, &nsizes);
for (i = 0; i < nsizes; ++i) {
if (sizes[i].width < w || sizes[i].height < h) {
continue;
}
if (sizes[i].width == w && sizes[i].height == h) {
best = i;
break;
}
if (best == -1 ||
(sizes[i].width < sizes[best].width) ||
Dec 16, 2008
Dec 16, 2008
620
621
(sizes[i].width == sizes[best].width
&& sizes[i].height < sizes[best].height)) {
Dec 16, 2008
Dec 16, 2008
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
best = i;
}
}
if (best >= 0) {
best_rate = 0;
rates = XRRConfigRates(data->screen_config, best, &nrates);
for (i = 0; i < nrates; ++i) {
if (rates[i] == rate) {
best_rate = rate;
break;
}
if (!rate) {
/* Higher is better, right? */
if (rates[i] > best_rate) {
best_rate = rates[i];
}
} else {
Dec 16, 2008
Dec 16, 2008
640
if (SDL_abs(rates[i] - rate) < SDL_abs(best_rate - rate)) {
Dec 16, 2008
Dec 16, 2008
641
642
643
644
best_rate = rates[i];
}
}
}
Dec 16, 2008
Dec 16, 2008
645
646
647
648
XRRSetScreenConfigAndRate(display, data->screen_config,
RootWindow(display, data->screen), best,
data->saved_rotation, best_rate,
CurrentTime);
Dec 16, 2008
Dec 16, 2008
649
650
651
652
653
}
return;
}
#endif /* SDL_VIDEO_DRIVER_X11_XRANDR */
Feb 28, 2011
Feb 28, 2011
654
#if SDL_VIDEO_DRIVER_X11_XVIDMODE
Dec 16, 2008
Dec 16, 2008
655
if (data->use_vidmode) {
Feb 28, 2011
Feb 28, 2011
656
XF86VidModeModeInfo ** modes;
Dec 16, 2008
Dec 16, 2008
657
658
659
int i, nmodes;
int best;
Feb 28, 2011
Feb 28, 2011
660
if (XF86VidModeGetAllModeLines(display, data->screen, &nmodes, &modes)) {
Dec 16, 2008
Dec 16, 2008
661
662
663
664
665
666
667
best = -1;
for (i = 0; i < nmodes; ++i) {
if (modes[i]->hdisplay < w || modes[i]->vdisplay < h) {
continue;
}
if (best == -1 ||
(modes[i]->hdisplay < modes[best]->hdisplay) ||
Dec 16, 2008
Dec 16, 2008
668
669
(modes[i]->hdisplay == modes[best]->hdisplay
&& modes[i]->vdisplay < modes[best]->vdisplay)) {
Dec 16, 2008
Dec 16, 2008
670
671
672
673
674
675
676
best = i;
continue;
}
if ((modes[i]->hdisplay == modes[best]->hdisplay) &&
(modes[i]->vdisplay == modes[best]->vdisplay)) {
if (!rate) {
/* Higher is better, right? */
Dec 16, 2008
Dec 16, 2008
677
678
if (calculate_rate(modes[i]) >
calculate_rate(modes[best])) {
Dec 16, 2008
Dec 16, 2008
679
680
681
best = i;
}
} else {
Dec 16, 2008
Dec 16, 2008
682
683
if (SDL_abs(calculate_rate(modes[i]) - rate) <
SDL_abs(calculate_rate(modes[best]) - rate)) {
Dec 16, 2008
Dec 16, 2008
684
685
686
687
688
689
690
691
best = i;
}
}
}
}
if (best >= 0) {
#ifdef X11MODES_DEBUG
printf("Best Mode %d: %d x %d @ %d\n", best,
Dec 16, 2008
Dec 16, 2008
692
693
modes[best]->hdisplay, modes[best]->vdisplay,
calculate_rate(modes[best]));
Dec 16, 2008
Dec 16, 2008
694
#endif
Feb 28, 2011
Feb 28, 2011
695
XF86VidModeSwitchToMode(display, data->screen, modes[best]);
Dec 16, 2008
Dec 16, 2008
696
697
698
699
700
}
XFree(modes);
}
return;
}
Feb 28, 2011
Feb 28, 2011
701
#endif /* SDL_VIDEO_DRIVER_X11_XVIDMODE */
Jul 26, 2006
Jul 26, 2006
702
703
704
}
int
Dec 1, 2009
Dec 1, 2009
705
X11_SetDisplayMode(_THIS, SDL_VideoDisplay * sdl_display, SDL_DisplayMode * mode)
Jul 26, 2006
Jul 26, 2006
706
{
Dec 16, 2008
Dec 16, 2008
707
Display *display = ((SDL_VideoData *) _this->driverdata)->display;
Dec 1, 2009
Dec 1, 2009
708
SDL_DisplayData *data = (SDL_DisplayData *) sdl_display->driverdata;
Dec 16, 2008
Dec 16, 2008
709
710
711
set_best_resolution(display, data, mode->w, mode->h, mode->refresh_rate);
return 0;
Jul 26, 2006
Jul 26, 2006
712
713
714
715
716
717
718
}
void
X11_QuitModes(_THIS)
{
}
Mar 12, 2011
Mar 12, 2011
719
720
#endif /* SDL_VIDEO_DRIVER_X11 */
Jul 26, 2006
Jul 26, 2006
721
/* vi: set ts=4 sw=4 expandtab: */