src/video/x11/SDL_x11modes.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 08 Dec 2008 00:27:32 +0000
changeset 2859 99210400e8b9
parent 1951 7177581dc9fa
child 2870 b801df19835f
permissions -rw-r--r--
Updated copyright date
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 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         displaydata->depth = vinfo.depth;
   110 
   111         SDL_zero(display);
   112         display.desktop_mode = mode;
   113         display.current_mode = mode;
   114         display.driverdata = displaydata;
   115         SDL_AddVideoDisplay(&display);
   116     }
   117     XFree(p);
   118 }
   119 
   120 void
   121 X11_GetDisplayModes(_THIS)
   122 {
   123     SDL_DisplayData *data = (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
   124     SDL_DisplayMode mode;
   125     //SDL_AddDisplayMode(_this->current_display, &mode);
   126 }
   127 
   128 int
   129 X11_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
   130 {
   131     //SDL_DisplayModeData *data = (SDL_DisplayModeData *) mode->driverdata;
   132     return -1;
   133 }
   134 
   135 void
   136 X11_QuitModes(_THIS)
   137 {
   138 }
   139 
   140 /* vi: set ts=4 sw=4 expandtab: */