comparison src/video/x11/SDL_x11modes.c @ 1950:a344e42bce3b

Started work on the new X11 driver.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 26 Jul 2006 06:34:54 +0000
parents
children 7177581dc9fa
comparison
equal deleted inserted replaced
1949:44b6f09a07d8 1950:a344e42bce3b
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 #include "SDL_x11video.h"
25
26
27 static int
28 get_visualinfo(Display * display, int screen, XVisualInfo * vinfo)
29 {
30 const char *visual_id = SDL_getenv("SDL_VIDEO_X11_VISUALID");
31 int use_directcolor = 1;
32 int depth;
33
34 /* Look for an exact visual, if requested */
35 if (visual_id) {
36 XVisualInfo *vi, template;
37 int nvis;
38
39 SDL_zero(template);
40 template.visualid = SDL_strtol(visual_id, NULL, 0);
41 vi = XGetVisualInfo(display, VisualIDMask, &template, &nvis);
42 if (vi) {
43 *vinfo = *vi;
44 XFree(vi);
45 return 0;
46 }
47 }
48
49 depth = DefaultDepth(display, screen);
50 if ((use_directcolor &&
51 XMatchVisualInfo(display, screen, depth, DirectColor, vinfo)) ||
52 XMatchVisualInfo(display, screen, depth, TrueColor, vinfo) ||
53 XMatchVisualInfo(display, screen, depth, PseudoColor, vinfo) ||
54 XMatchVisualInfo(display, screen, depth, StaticColor, vinfo)) {
55 return 0;
56 }
57 return -1;
58 }
59
60 void
61 X11_InitModes(_THIS)
62 {
63 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
64 int screen;
65 int n;
66 XPixmapFormatValues *p;
67
68 p = XListPixmapFormats(data->display, &n);
69 for (screen = 0; screen < ScreenCount(data->display); ++screen) {
70 XVisualInfo vinfo;
71 int i, bpp;
72 Uint32 Rmask, Gmask, Bmask, Amask;
73 SDL_VideoDisplay display;
74 SDL_DisplayData *displaydata;
75 SDL_DisplayMode mode;
76
77 if (get_visualinfo(data->display, screen, &vinfo) < 0) {
78 continue;
79 }
80
81 bpp = vinfo.depth;
82 for (i = 0; i < n; ++i) {
83 if (p[i].depth == vinfo.depth) {
84 bpp = p[i].bits_per_pixel;
85 break;
86 }
87 }
88 Rmask = vinfo.visual->red_mask;
89 Gmask = vinfo.visual->green_mask;
90 Bmask = vinfo.visual->blue_mask;
91 if (vinfo.depth == 32) {
92 Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
93 } else {
94 Amask = 0;
95 }
96 mode.format =
97 SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
98 mode.w = DisplayWidth(data->display, screen);
99 mode.h = DisplayHeight(data->display, screen);
100 mode.refresh_rate = 0;
101 mode.driverdata = NULL;
102
103 displaydata = (SDL_DisplayData *) SDL_malloc(sizeof(*displaydata));
104 if (!displaydata) {
105 continue;
106 }
107 displaydata->screen = screen;
108 displaydata->visual = vinfo.visual;
109
110 SDL_zero(display);
111 display.desktop_mode = mode;
112 display.current_mode = mode;
113 display.driverdata = displaydata;
114 SDL_AddVideoDisplay(&display);
115 }
116 XFree(p);
117 }
118
119 void
120 X11_GetDisplayModes(_THIS)
121 {
122 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
123 SDL_DisplayMode mode;
124 //SDL_AddDisplayMode(_this->current_display, &mode);
125 }
126
127 int
128 X11_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
129 {
130 //SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
131 return -1;
132 }
133
134 void
135 X11_QuitModes(_THIS)
136 {
137 }
138
139 /* vi: set ts=4 sw=4 expandtab: */