src/video/x11/SDL_x11window.c
changeset 5243 3a8a452b49f0
parent 5183 227d81a4b66c
child 5246 58265e606e4e
     1.1 --- a/src/video/x11/SDL_x11window.c	Thu Feb 10 10:37:35 2011 -0800
     1.2 +++ b/src/video/x11/SDL_x11window.c	Thu Feb 10 11:39:08 2011 -0800
     1.3 @@ -28,7 +28,6 @@
     1.4  
     1.5  #include "SDL_x11video.h"
     1.6  #include "SDL_x11mouse.h"
     1.7 -#include "SDL_x11gamma.h"
     1.8  #include "SDL_x11shape.h"
     1.9  
    1.10  #ifdef SDL_VIDEO_DRIVER_PANDORA
    1.11 @@ -326,217 +325,7 @@
    1.12      }
    1.13      xattr.background_pixel = 0;
    1.14      xattr.border_pixel = 0;
    1.15 -
    1.16 -    if (visual->class == PseudoColor) {
    1.17 -        printf("asking for PseudoColor\n");
    1.18 -
    1.19 -/*      Status status; */
    1.20 -        XColor *colorcells;
    1.21 -        Colormap colormap;
    1.22 -        Sint32 pix;
    1.23 -        Sint32 ncolors;
    1.24 -        Sint32 nbits;
    1.25 -        Sint32 rmax, gmax, bmax;
    1.26 -        Sint32 rwidth, gwidth, bwidth;
    1.27 -        Sint32 rmask, gmask, bmask;
    1.28 -        Sint32 rshift, gshift, bshift;
    1.29 -        Sint32 r, g, b;
    1.30 -
    1.31 -        /* Is the colormap we need already registered in SDL? */
    1.32 -        if ((colormap =
    1.33 -            X11_LookupColormap(display, screen, visual->visualid))) {
    1.34 -            xattr.colormap = colormap;
    1.35 -/*             printf("found existing colormap\n"); */
    1.36 -        } else {
    1.37 -            /* The colormap is not known to SDL so we will create it */
    1.38 -            colormap = XCreateColormap(display, RootWindow(display, screen),
    1.39 -                                       visual, AllocAll);
    1.40 -/*             printf("colormap = %x\n", colormap); */
    1.41 -
    1.42 -            /* If we can't create a colormap, then we must die */
    1.43 -            if (!colormap) {
    1.44 -                SDL_SetError
    1.45 -                    ("Couldn't create window: Could not create writable colormap");
    1.46 -                return -1;
    1.47 -            }
    1.48 -
    1.49 -            /* OK, we got a colormap, now fill it in as best as we can */
    1.50 -
    1.51 -            colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
    1.52 -            if (NULL == colorcells) {
    1.53 -                SDL_SetError("out of memory in X11_CreateWindow");
    1.54 -                return -1;
    1.55 -            }
    1.56 -
    1.57 -            ncolors = visual->map_entries;
    1.58 -            nbits = visual->bits_per_rgb;
    1.59 -
    1.60 -/* 	    printf("ncolors = %d nbits = %d\n", ncolors, nbits); */
    1.61 -
    1.62 -            /* what if ncolors != (1 << nbits)? That can happen on a
    1.63 -               true PseudoColor display.  I'm assuming that we will
    1.64 -               always have ncolors == (1 << nbits) */
    1.65 -
    1.66 -            /* I'm making a lot of assumptions here. */
    1.67 -
    1.68 -            /* Compute the width of each field. If there is one extra
    1.69 -               bit, give it to green. If there are two extra bits give
    1.70 -               them to red and greed.  We can get extra bits when the
    1.71 -               number of bits per pixel is not a multiple of 3. For
    1.72 -               example when we have 16 bits per pixel and need a 5/6/5
    1.73 -               layout for the RGB fields */
    1.74 -
    1.75 -            rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0);
    1.76 -            gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0);
    1.77 -            bwidth = (nbits / 3);
    1.78 -
    1.79 -            rshift = gwidth + bwidth;
    1.80 -            gshift = bwidth;
    1.81 -            bshift = 0;
    1.82 -
    1.83 -            rmax = 1 << rwidth;
    1.84 -            gmax = 1 << gwidth;
    1.85 -            bmax = 1 << bwidth;
    1.86 -
    1.87 -            rmask = rmax - 1;
    1.88 -            gmask = gmax - 1;
    1.89 -            bmask = bmax - 1;
    1.90 -
    1.91 -/*             printf("red   mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */
    1.92 -/*             printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */
    1.93 -/*             printf("blue  mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */
    1.94 -
    1.95 -            /* build the color table pixel values */
    1.96 -            pix = 0;
    1.97 -            for (r = 0; r < rmax; r++) {
    1.98 -                for (g = 0; g < gmax; g++) {
    1.99 -                    for (b = 0; b < bmax; b++) {
   1.100 -                        colorcells[pix].pixel =
   1.101 -                            (r << rshift) | (g << gshift) | (b << bshift);
   1.102 -                        colorcells[pix].red = (0xffff * r) / rmask;
   1.103 -                        colorcells[pix].green = (0xffff * g) / gmask;
   1.104 -                        colorcells[pix].blue = (0xffff * b) / bmask;
   1.105 -/* 		  printf("%4x:%4x [%4x %4x %4x]\n",  */
   1.106 -/* 			 pix,  */
   1.107 -/* 			 colorcells[pix].pixel, */
   1.108 -/* 			 colorcells[pix].red, */
   1.109 -/* 			 colorcells[pix].green, */
   1.110 -/* 			 colorcells[pix].blue); */
   1.111 -                        pix++;
   1.112 -                    }
   1.113 -                }
   1.114 -            }
   1.115 -
   1.116 -/*             status = */
   1.117 -/*                 XStoreColors(display, colormap, colorcells, ncolors); */
   1.118 -
   1.119 -            xattr.colormap = colormap;
   1.120 -            X11_TrackColormap(display, screen, colormap, visual, NULL);
   1.121 -
   1.122 -            SDL_free(colorcells);
   1.123 -        }
   1.124 -    } else if (visual->class == DirectColor) {
   1.125 -        Status status;
   1.126 -        XColor *colorcells;
   1.127 -        Colormap colormap;
   1.128 -        int i;
   1.129 -        int ncolors;
   1.130 -        int rmax, gmax, bmax;
   1.131 -        int rmask, gmask, bmask;
   1.132 -        int rshift, gshift, bshift;
   1.133 -
   1.134 -        /* Is the colormap we need already registered in SDL? */
   1.135 -        if ((colormap =
   1.136 -             X11_LookupColormap(display, screen, visual->visualid))) {
   1.137 -            xattr.colormap = colormap;
   1.138 -/*             printf("found existing colormap\n"); */
   1.139 -        } else {
   1.140 -            /* The colormap is not known to SDL so we will create it */
   1.141 -            colormap = XCreateColormap(display, RootWindow(display, screen),
   1.142 -                                       visual, AllocAll);
   1.143 -/*             printf("colormap = %x\n", colormap); */
   1.144 -
   1.145 -            /* If we can't create a colormap, then we must die */
   1.146 -            if (!colormap) {
   1.147 -                SDL_SetError
   1.148 -                    ("Couldn't create window: Could not create writable colormap");
   1.149 -                return -1;
   1.150 -            }
   1.151 -
   1.152 -            /* OK, we got a colormap, now fill it in as best as we can */
   1.153 -            colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
   1.154 -            if (NULL == colorcells) {
   1.155 -                SDL_SetError("out of memory in X11_CreateWindow");
   1.156 -                return -1;
   1.157 -            }
   1.158 -            ncolors = visual->map_entries;
   1.159 -            rmax = 0xffff;
   1.160 -            gmax = 0xffff;
   1.161 -            bmax = 0xffff;
   1.162 -
   1.163 -            rshift = 0;
   1.164 -            rmask = visual->red_mask;
   1.165 -            while (0 == (rmask & 1)) {
   1.166 -                rshift++;
   1.167 -                rmask >>= 1;
   1.168 -            }
   1.169 -
   1.170 -/*             printf("rmask = %4x rshift = %4d\n", rmask, rshift); */
   1.171 -
   1.172 -            gshift = 0;
   1.173 -            gmask = visual->green_mask;
   1.174 -            while (0 == (gmask & 1)) {
   1.175 -                gshift++;
   1.176 -                gmask >>= 1;
   1.177 -            }
   1.178 -
   1.179 -/*             printf("gmask = %4x gshift = %4d\n", gmask, gshift); */
   1.180 -
   1.181 -            bshift = 0;
   1.182 -            bmask = visual->blue_mask;
   1.183 -            while (0 == (bmask & 1)) {
   1.184 -                bshift++;
   1.185 -                bmask >>= 1;
   1.186 -            }
   1.187 -
   1.188 -/*             printf("bmask = %4x bshift = %4d\n", bmask, bshift); */
   1.189 -
   1.190 -            /* build the color table pixel values */
   1.191 -            for (i = 0; i < ncolors; i++) {
   1.192 -                Uint32 red = (rmax * i) / (ncolors - 1);
   1.193 -                Uint32 green = (gmax * i) / (ncolors - 1);
   1.194 -                Uint32 blue = (bmax * i) / (ncolors - 1);
   1.195 -
   1.196 -                Uint32 rbits = (rmask * i) / (ncolors - 1);
   1.197 -                Uint32 gbits = (gmask * i) / (ncolors - 1);
   1.198 -                Uint32 bbits = (bmask * i) / (ncolors - 1);
   1.199 -
   1.200 -                Uint32 pix =
   1.201 -                    (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
   1.202 -
   1.203 -                colorcells[i].pixel = pix;
   1.204 -
   1.205 -                colorcells[i].red = red;
   1.206 -                colorcells[i].green = green;
   1.207 -                colorcells[i].blue = blue;
   1.208 -
   1.209 -                colorcells[i].flags = DoRed | DoGreen | DoBlue;
   1.210 -/* 		printf("%2d:%4x [%4x %4x %4x]\n", i, pix, red, green, blue); */
   1.211 -            }
   1.212 -
   1.213 -            status =
   1.214 -                XStoreColors(display, colormap, colorcells, ncolors);
   1.215 -
   1.216 -            xattr.colormap = colormap;
   1.217 -            X11_TrackColormap(display, screen, colormap, visual, colorcells);
   1.218 -
   1.219 -            SDL_free(colorcells);
   1.220 -        }
   1.221 -    } else {
   1.222 -        xattr.colormap =
   1.223 -            XCreateColormap(display, RootWindow(display, screen),
   1.224 -                            visual, AllocNone);
   1.225 -    }
   1.226 +    xattr.colormap = XCreateColormap(display, RootWindow(display, screen), visual, AllocNone);
   1.227  
   1.228      if (oldstyle_fullscreen
   1.229          || window->x == SDL_WINDOWPOS_CENTERED) {