Mercurial > emacs
comparison src/xfaces.c @ 28354:d6ae8188fa58
(register_color, unregister_colors, unregister_colors)
[DEBUG_X_COLORS]: New functions.
(x_free_colors) [DEBUG_X_COLORS]: Unregister colors.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 27 Mar 2000 14:47:42 +0000 |
parents | 26f2a2e9a2b5 |
children | 6ff20b891ec1 |
comparison
equal
deleted
inserted
replaced
28353:5246aef1c8e1 | 28354:d6ae8188fa58 |
---|---|
525 Utilities | 525 Utilities |
526 ***********************************************************************/ | 526 ***********************************************************************/ |
527 | 527 |
528 #ifdef HAVE_X_WINDOWS | 528 #ifdef HAVE_X_WINDOWS |
529 | 529 |
530 #ifdef DEBUG_X_COLORS | |
531 | |
532 /* The following is a poor mans infrastructure for debugging X color | |
533 allocation problems on displays with PseudoColor-8. Some X servers | |
534 like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement | |
535 color reference counts completely so that they don't signal an | |
536 error when a color is freed whose reference count is already 0. | |
537 Other X servers do. To help me debug this, the following code | |
538 implements a simple reference counting schema of its own, for a | |
539 single display/screen. --gerd. */ | |
540 | |
541 /* Reference counts for pixel colors. */ | |
542 | |
543 int color_count[256]; | |
544 | |
545 /* Register color PIXEL as allocated. */ | |
546 | |
547 void | |
548 register_color (pixel) | |
549 unsigned long pixel; | |
550 { | |
551 xassert (pixel < 256); | |
552 ++color_count[pixel]; | |
553 } | |
554 | |
555 | |
556 /* Register color PIXEL as deallocated. */ | |
557 | |
558 void | |
559 unregister_color (pixel) | |
560 unsigned long pixel; | |
561 { | |
562 xassert (pixel < 256); | |
563 if (color_count[pixel] > 0) | |
564 --color_count[pixel]; | |
565 else | |
566 abort (); | |
567 } | |
568 | |
569 | |
570 /* Register N colors from PIXELS as deallocated. */ | |
571 | |
572 void | |
573 unregister_colors (pixels, n) | |
574 unsigned long *pixels; | |
575 int n; | |
576 { | |
577 int i; | |
578 for (i = 0; i < n; ++i) | |
579 unregister_color (pixels[i]); | |
580 } | |
581 | |
582 #endif /* DEBUG_X_COLORS */ | |
583 | |
530 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel | 584 /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel |
531 color values. Interrupt input must be blocked when this function | 585 color values. Interrupt input must be blocked when this function |
532 is called. */ | 586 is called. */ |
533 | 587 |
534 void | 588 void |
562 for (i = j = 0; i < npixels; ++i) | 616 for (i = j = 0; i < npixels; ++i) |
563 if (pixels[i] != black && pixels[i] != white) | 617 if (pixels[i] != black && pixels[i] != white) |
564 px[j++] = pixels[i]; | 618 px[j++] = pixels[i]; |
565 | 619 |
566 if (j) | 620 if (j) |
567 XFreeColors (dpy, cmap, px, j, 0); | 621 { |
622 XFreeColors (dpy, cmap, px, j, 0); | |
623 #ifdef DEBUG_X_COLORS | |
624 unregister_colors (px, j); | |
625 #endif | |
626 } | |
568 } | 627 } |
569 else | 628 else |
570 XFreeColors (dpy, cmap, pixels, npixels, 0); | 629 { |
630 XFreeColors (dpy, cmap, pixels, npixels, 0); | |
631 #ifdef DEBUG_X_COLORS | |
632 unregister_colors (pixels, npixels); | |
633 #endif | |
634 } | |
571 } | 635 } |
572 } | 636 } |
573 | 637 |
574 /* Create and return a GC for use on frame F. GC values and mask | 638 /* Create and return a GC for use on frame F. GC values and mask |
575 are given by XGCV and MASK. */ | 639 are given by XGCV and MASK. */ |