comparison src/video/x11/SDL_x11modes.c @ 2870:b801df19835f

The X11 window and all pixmaps and images share the same visual and depth.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 14 Dec 2008 04:36:32 +0000
parents 99210400e8b9
children b33e38aaa027
comparison
equal deleted inserted replaced
2869:2fe507a2ef7d 2870:b801df19835f
55 return 0; 55 return 0;
56 } 56 }
57 return -1; 57 return -1;
58 } 58 }
59 59
60 static Uint32
61 X11_GetPixelFormatFromVisualInfo(Display *display, XVisualInfo *vinfo)
62 {
63 if (vinfo->class == DirectColor || vinfo->class == TrueColor) {
64 int bpp;
65 Uint32 Rmask, Gmask, Bmask, Amask;
66
67 Rmask = vinfo->visual->red_mask;
68 Gmask = vinfo->visual->green_mask;
69 Bmask = vinfo->visual->blue_mask;
70 if (vinfo->depth == 32) {
71 Amask = (0xFFFFFFFF & ~(Rmask | Gmask | Bmask));
72 } else {
73 Amask = 0;
74 }
75
76 bpp = vinfo->depth;
77 if (bpp == 24) {
78 int i, n;
79 XPixmapFormatValues *p = XListPixmapFormats(display, &n);
80 if (p) {
81 for (i = 0; i < n; ++i) {
82 if (p[i].depth == 24) {
83 bpp = p[i].bits_per_pixel;
84 break;
85 }
86 }
87 XFree(p);
88 }
89 }
90
91 return SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
92 }
93
94 if (vinfo->class == PseudoColor || vinfo->class == StaticColor) {
95 switch (vinfo->depth) {
96 case 8:
97 return SDL_PIXELTYPE_INDEX8;
98 case 4:
99 if (BitmapBitOrder(display) == LSBFirst) {
100 return SDL_PIXELFORMAT_INDEX4LSB;
101 } else {
102 return SDL_PIXELFORMAT_INDEX4MSB;
103 }
104 break;
105 case 1:
106 if (BitmapBitOrder(display) == LSBFirst) {
107 return SDL_PIXELFORMAT_INDEX1LSB;
108 } else {
109 return SDL_PIXELFORMAT_INDEX1MSB;
110 }
111 break;
112 }
113 }
114
115 return SDL_PIXELFORMAT_UNKNOWN;
116 }
117
60 void 118 void
61 X11_InitModes(_THIS) 119 X11_InitModes(_THIS)
62 { 120 {
63 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; 121 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
64 int screen; 122 int screen;
65 int n;
66 XPixmapFormatValues *p;
67 123
68 p = XListPixmapFormats(data->display, &n);
69 for (screen = 0; screen < ScreenCount(data->display); ++screen) { 124 for (screen = 0; screen < ScreenCount(data->display); ++screen) {
70 XVisualInfo vinfo; 125 XVisualInfo vinfo;
71 int i, bpp;
72 Uint32 Rmask, Gmask, Bmask, Amask;
73 SDL_VideoDisplay display; 126 SDL_VideoDisplay display;
74 SDL_DisplayData *displaydata; 127 SDL_DisplayData *displaydata;
75 SDL_DisplayMode mode; 128 SDL_DisplayMode mode;
76 129
77 if (get_visualinfo(data->display, screen, &vinfo) < 0) { 130 if (get_visualinfo(data->display, screen, &vinfo) < 0) {
78 continue; 131 continue;
79 } 132 }
80 133
81 bpp = vinfo.depth; 134 mode.format = X11_GetPixelFormatFromVisualInfo(data->display, &vinfo);
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); 135 mode.w = DisplayWidth(data->display, screen);
99 mode.h = DisplayHeight(data->display, screen); 136 mode.h = DisplayHeight(data->display, screen);
100 mode.refresh_rate = 0; 137 mode.refresh_rate = 0;
101 mode.driverdata = NULL; 138 mode.driverdata = NULL;
102 139
112 display.desktop_mode = mode; 149 display.desktop_mode = mode;
113 display.current_mode = mode; 150 display.current_mode = mode;
114 display.driverdata = displaydata; 151 display.driverdata = displaydata;
115 SDL_AddVideoDisplay(&display); 152 SDL_AddVideoDisplay(&display);
116 } 153 }
117 XFree(p);
118 } 154 }
119 155
120 void 156 void
121 X11_GetDisplayModes(_THIS) 157 X11_GetDisplayModes(_THIS)
122 { 158 {
159 Display *display = ((SDL_VideoData *) _this->driverdata)->display;
123 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata; 160 SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
124 SDL_DisplayMode mode; 161 SDL_DisplayMode mode;
125 //SDL_AddDisplayMode(_this->current_display, &mode); 162
126 } 163 }
127 164
128 int 165 int
129 X11_SetDisplayMode(_THIS, SDL_DisplayMode * mode) 166 X11_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
130 { 167 {