comparison src/video/x11/SDL_x11window.c @ 5248:3a8a452b49f0

Removed gamma support since it wasn't widely used and not well supported.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 10 Feb 2011 11:39:08 -0800
parents 227d81a4b66c
children 58265e606e4e
comparison
equal deleted inserted replaced
5247:78ce7bfd0faf 5248:3a8a452b49f0
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"
32 #include "SDL_x11shape.h" 31 #include "SDL_x11shape.h"
33 32
34 #ifdef SDL_VIDEO_DRIVER_PANDORA 33 #ifdef SDL_VIDEO_DRIVER_PANDORA
35 #include "SDL_x11opengles.h" 34 #include "SDL_x11opengles.h"
36 #endif 35 #endif
324 } else { 323 } else {
325 xattr.override_redirect = False; 324 xattr.override_redirect = False;
326 } 325 }
327 xattr.background_pixel = 0; 326 xattr.background_pixel = 0;
328 xattr.border_pixel = 0; 327 xattr.border_pixel = 0;
329 328 xattr.colormap = XCreateColormap(display, RootWindow(display, screen), visual, AllocNone);
330 if (visual->class == PseudoColor) {
331 printf("asking for PseudoColor\n");
332
333 /* Status status; */
334 XColor *colorcells;
335 Colormap colormap;
336 Sint32 pix;
337 Sint32 ncolors;
338 Sint32 nbits;
339 Sint32 rmax, gmax, bmax;
340 Sint32 rwidth, gwidth, bwidth;
341 Sint32 rmask, gmask, bmask;
342 Sint32 rshift, gshift, bshift;
343 Sint32 r, g, b;
344
345 /* Is the colormap we need already registered in SDL? */
346 if ((colormap =
347 X11_LookupColormap(display, screen, visual->visualid))) {
348 xattr.colormap = colormap;
349 /* printf("found existing colormap\n"); */
350 } else {
351 /* The colormap is not known to SDL so we will create it */
352 colormap = XCreateColormap(display, RootWindow(display, screen),
353 visual, AllocAll);
354 /* printf("colormap = %x\n", colormap); */
355
356 /* If we can't create a colormap, then we must die */
357 if (!colormap) {
358 SDL_SetError
359 ("Couldn't create window: Could not create writable colormap");
360 return -1;
361 }
362
363 /* OK, we got a colormap, now fill it in as best as we can */
364
365 colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
366 if (NULL == colorcells) {
367 SDL_SetError("out of memory in X11_CreateWindow");
368 return -1;
369 }
370
371 ncolors = visual->map_entries;
372 nbits = visual->bits_per_rgb;
373
374 /* printf("ncolors = %d nbits = %d\n", ncolors, nbits); */
375
376 /* what if ncolors != (1 << nbits)? That can happen on a
377 true PseudoColor display. I'm assuming that we will
378 always have ncolors == (1 << nbits) */
379
380 /* I'm making a lot of assumptions here. */
381
382 /* Compute the width of each field. If there is one extra
383 bit, give it to green. If there are two extra bits give
384 them to red and greed. We can get extra bits when the
385 number of bits per pixel is not a multiple of 3. For
386 example when we have 16 bits per pixel and need a 5/6/5
387 layout for the RGB fields */
388
389 rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0);
390 gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0);
391 bwidth = (nbits / 3);
392
393 rshift = gwidth + bwidth;
394 gshift = bwidth;
395 bshift = 0;
396
397 rmax = 1 << rwidth;
398 gmax = 1 << gwidth;
399 bmax = 1 << bwidth;
400
401 rmask = rmax - 1;
402 gmask = gmax - 1;
403 bmask = bmax - 1;
404
405 /* printf("red mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */
406 /* printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */
407 /* printf("blue mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */
408
409 /* build the color table pixel values */
410 pix = 0;
411 for (r = 0; r < rmax; r++) {
412 for (g = 0; g < gmax; g++) {
413 for (b = 0; b < bmax; b++) {
414 colorcells[pix].pixel =
415 (r << rshift) | (g << gshift) | (b << bshift);
416 colorcells[pix].red = (0xffff * r) / rmask;
417 colorcells[pix].green = (0xffff * g) / gmask;
418 colorcells[pix].blue = (0xffff * b) / bmask;
419 /* printf("%4x:%4x [%4x %4x %4x]\n", */
420 /* pix, */
421 /* colorcells[pix].pixel, */
422 /* colorcells[pix].red, */
423 /* colorcells[pix].green, */
424 /* colorcells[pix].blue); */
425 pix++;
426 }
427 }
428 }
429
430 /* status = */
431 /* XStoreColors(display, colormap, colorcells, ncolors); */
432
433 xattr.colormap = colormap;
434 X11_TrackColormap(display, screen, colormap, visual, NULL);
435
436 SDL_free(colorcells);
437 }
438 } else if (visual->class == DirectColor) {
439 Status status;
440 XColor *colorcells;
441 Colormap colormap;
442 int i;
443 int ncolors;
444 int rmax, gmax, bmax;
445 int rmask, gmask, bmask;
446 int rshift, gshift, bshift;
447
448 /* Is the colormap we need already registered in SDL? */
449 if ((colormap =
450 X11_LookupColormap(display, screen, visual->visualid))) {
451 xattr.colormap = colormap;
452 /* printf("found existing colormap\n"); */
453 } else {
454 /* The colormap is not known to SDL so we will create it */
455 colormap = XCreateColormap(display, RootWindow(display, screen),
456 visual, AllocAll);
457 /* printf("colormap = %x\n", colormap); */
458
459 /* If we can't create a colormap, then we must die */
460 if (!colormap) {
461 SDL_SetError
462 ("Couldn't create window: Could not create writable colormap");
463 return -1;
464 }
465
466 /* OK, we got a colormap, now fill it in as best as we can */
467 colorcells = SDL_malloc(visual->map_entries * sizeof(XColor));
468 if (NULL == colorcells) {
469 SDL_SetError("out of memory in X11_CreateWindow");
470 return -1;
471 }
472 ncolors = visual->map_entries;
473 rmax = 0xffff;
474 gmax = 0xffff;
475 bmax = 0xffff;
476
477 rshift = 0;
478 rmask = visual->red_mask;
479 while (0 == (rmask & 1)) {
480 rshift++;
481 rmask >>= 1;
482 }
483
484 /* printf("rmask = %4x rshift = %4d\n", rmask, rshift); */
485
486 gshift = 0;
487 gmask = visual->green_mask;
488 while (0 == (gmask & 1)) {
489 gshift++;
490 gmask >>= 1;
491 }
492
493 /* printf("gmask = %4x gshift = %4d\n", gmask, gshift); */
494
495 bshift = 0;
496 bmask = visual->blue_mask;
497 while (0 == (bmask & 1)) {
498 bshift++;
499 bmask >>= 1;
500 }
501
502 /* printf("bmask = %4x bshift = %4d\n", bmask, bshift); */
503
504 /* build the color table pixel values */
505 for (i = 0; i < ncolors; i++) {
506 Uint32 red = (rmax * i) / (ncolors - 1);
507 Uint32 green = (gmax * i) / (ncolors - 1);
508 Uint32 blue = (bmax * i) / (ncolors - 1);
509
510 Uint32 rbits = (rmask * i) / (ncolors - 1);
511 Uint32 gbits = (gmask * i) / (ncolors - 1);
512 Uint32 bbits = (bmask * i) / (ncolors - 1);
513
514 Uint32 pix =
515 (rbits << rshift) | (gbits << gshift) | (bbits << bshift);
516
517 colorcells[i].pixel = pix;
518
519 colorcells[i].red = red;
520 colorcells[i].green = green;
521 colorcells[i].blue = blue;
522
523 colorcells[i].flags = DoRed | DoGreen | DoBlue;
524 /* printf("%2d:%4x [%4x %4x %4x]\n", i, pix, red, green, blue); */
525 }
526
527 status =
528 XStoreColors(display, colormap, colorcells, ncolors);
529
530 xattr.colormap = colormap;
531 X11_TrackColormap(display, screen, colormap, visual, colorcells);
532
533 SDL_free(colorcells);
534 }
535 } else {
536 xattr.colormap =
537 XCreateColormap(display, RootWindow(display, screen),
538 visual, AllocNone);
539 }
540 329
541 if (oldstyle_fullscreen 330 if (oldstyle_fullscreen
542 || window->x == SDL_WINDOWPOS_CENTERED) { 331 || window->x == SDL_WINDOWPOS_CENTERED) {
543 X11_GetDisplaySize(_this, window, &x, NULL); 332 X11_GetDisplaySize(_this, window, &x, NULL);
544 x = (x - window->w) / 2; 333 x = (x - window->w) / 2;