src/video/x11/SDL_x11window.c
changeset 3009 546c022a9ae5
parent 2990 502adab079a4
child 3044 b36579172f27
equal deleted inserted replaced
3008:786a48f8309c 3009:546c022a9ae5
    26 #include "../../events/SDL_keyboard_c.h"
    26 #include "../../events/SDL_keyboard_c.h"
    27 #include "../../events/SDL_mouse_c.h"
    27 #include "../../events/SDL_mouse_c.h"
    28 
    28 
    29 #include "SDL_x11video.h"
    29 #include "SDL_x11video.h"
    30 #include "SDL_x11mouse.h"
    30 #include "SDL_x11mouse.h"
       
    31 #include "SDL_x11gamma.h"
    31 #include "../Xext/extensions/StdCmap.h"
    32 #include "../Xext/extensions/StdCmap.h"
    32 
    33 
    33 static void
    34 static void
    34 X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
    35 X11_GetDisplaySize(_THIS, SDL_Window * window, int *w, int *h)
    35 {
    36 {
   211     }
   212     }
   212     xattr.background_pixel = 0;
   213     xattr.background_pixel = 0;
   213     xattr.border_pixel = 0;
   214     xattr.border_pixel = 0;
   214 
   215 
   215     if (visual->class == PseudoColor) {
   216     if (visual->class == PseudoColor) {
       
   217 /*         printf("asking for PseudoColor\n"); */
   216         int nmaps;
   218         int nmaps;
   217         XStandardColormap cmap;
   219         XStandardColormap cmap;
   218         XStandardColormap *stdmaps;
   220         XStandardColormap *stdmaps;
   219         XColor *colorcells;
   221         XColor *colorcells;
   220         Colormap colormap;
   222         Colormap colormap;
   291             colormap = XCreateColormap(data->display,
   293             colormap = XCreateColormap(data->display,
   292                                        RootWindow(data->display,
   294                                        RootWindow(data->display,
   293                                                   displaydata->screen),
   295                                                   displaydata->screen),
   294                                        visual, AllocAll);
   296                                        visual, AllocAll);
   295             XStoreColors(data->display, colormap, colorcells, ncolors);
   297             XStoreColors(data->display, colormap, colorcells, ncolors);
   296             SDL_free(colorcells);
       
   297 
   298 
   298             xattr.colormap = colormap;
   299             xattr.colormap = colormap;
   299             X11_TrackColormap(data->display, displaydata->screen, colormap,
   300             X11_TrackColormap(data->display, displaydata->screen, colormap,
   300                               &cmap, visual);
   301                               visual, colorcells);
       
   302             SDL_free(colorcells);
   301         }
   303         }
   302     } else if (visual->class == DirectColor) {
   304     } else if (visual->class == DirectColor) {
   303         /* FIXME: Allocate a read-write colormap for gamma fading someday */
   305         Status status;
   304         xattr.colormap =
   306         XStandardColormap cmap;
   305             XCreateColormap(data->display,
   307         XColor *colorcells;
   306                             RootWindow(data->display, displaydata->screen),
   308         Colormap colormap;
   307                             visual, AllocNone);
   309         int i;
       
   310         int ncolors;
       
   311         int rmax, gmax, bmax;
       
   312         int rmask, gmask, bmask;
       
   313         int rshift, gshift, bshift;
       
   314 
       
   315         /* Is the colormap we need already registered in SDL? */
       
   316         if (colormap =
       
   317             X11_LookupColormap(data->display,
       
   318                                displaydata->screen, visual->visualid)) {
       
   319             xattr.colormap = colormap;
       
   320 /*             printf("found existing colormap\n"); */
       
   321         } else {
       
   322             /* The colormap is not known to SDL so we will create it */
       
   323             colormap = XCreateColormap(data->display,
       
   324                                        RootWindow(data->display,
       
   325                                                   displaydata->screen),
       
   326                                        visual, AllocAll);
       
   327 /*             printf("colormap = %x\n", colormap); */
       
   328 
       
   329             /* If we can't create a colormap, then we must die */
       
   330             if (!colormap) {
       
   331                 SDL_SetError
       
   332                     ("Couldn't create window: Could not create wriatable colormap");
       
   333                 return -1;
       
   334             }
       
   335 
       
   336             /* OK, we got a colormap, now fill it in as best as we can */
       
   337 
       
   338             colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
       
   339             if (NULL == colorcells) {
       
   340                 SDL_SetError("out of memory in X11_CreateWindow");
       
   341                 return -1;
       
   342             }
       
   343             ncolors = visual->map_entries;
       
   344             rmax = 0xffff;
       
   345             gmax = 0xffff;
       
   346             bmax = 0xffff;
       
   347 
       
   348             rshift = 0;
       
   349             rmask = visual->red_mask;
       
   350             while (0 == (rmask & 1)) {
       
   351                 rshift++;
       
   352                 rmask >>= 1;
       
   353             }
       
   354 
       
   355 /*             printf("rmask = %4x rshift = %4d\n", rmask, rshift); */
       
   356 
       
   357             gshift = 0;
       
   358             gmask = visual->green_mask;
       
   359             while (0 == (gmask & 1)) {
       
   360                 gshift++;
       
   361                 gmask >>= 1;
       
   362             }
       
   363 
       
   364 /*             printf("gmask = %4x gshift = %4d\n", gmask, gshift); */
       
   365 
       
   366             bshift = 0;
       
   367             bmask = visual->blue_mask;
       
   368             while (0 == (bmask & 1)) {
       
   369                 bshift++;
       
   370                 bmask >>= 1;
       
   371             }
       
   372 
       
   373 /*             printf("bmask = %4x bshift = %4d\n", bmask, bshift); */
       
   374 
       
   375             /* build the color table pixel values */
       
   376             for (i = 0; i < ncolors; i++) {
       
   377                 Uint32 red = (rmax * i) / (ncolors - 1);
       
   378                 Uint32 green = (gmax * i) / (ncolors - 1);
       
   379                 Uint32 blue = (bmax * i) / (ncolors - 1);
       
   380 
       
   381                 Uint32 rbits = (rmask * i) / (ncolors - 1);
       
   382                 Uint32 gbits = (gmask * i) / (ncolors - 1);
       
   383                 Uint32 bbits = (bmask * i) / (ncolors - 1);
       
   384 
       
   385                 Uint32 pix =
       
   386                     (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
       
   387 
       
   388                 colorcells[i].pixel = pix;
       
   389 
       
   390                 colorcells[i].red = red;
       
   391                 colorcells[i].green = green;
       
   392                 colorcells[i].blue = blue;
       
   393 
       
   394                 colorcells[i].flags = DoRed | DoGreen | DoBlue;
       
   395 /* 		printf("%2d:%4x [%4x %4x %4x]\n", i, pix, red, green, blue); */
       
   396 
       
   397             }
       
   398 
       
   399             status =
       
   400                 XStoreColors(data->display, colormap, colorcells, ncolors);
       
   401 
       
   402             xattr.colormap = colormap;
       
   403             X11_TrackColormap(data->display, displaydata->screen,
       
   404                               colormap, visual, colorcells);
       
   405 
       
   406             SDL_free(colorcells);
       
   407         }
   308     } else {
   408     } else {
   309         xattr.colormap =
   409         xattr.colormap =
   310             XCreateColormap(data->display,
   410             XCreateColormap(data->display,
   311                             RootWindow(data->display, displaydata->screen),
   411                             RootWindow(data->display, displaydata->screen),
   312                             visual, AllocNone);
   412                             visual, AllocNone);