diff options
| author | Gerd Moellmann | 2000-03-27 14:47:42 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-03-27 14:47:42 +0000 |
| commit | a435fc2a6d3d1e9a83b75cc8650b1fb68bd50d08 (patch) | |
| tree | 26212aae0303a74f7816dff0bcf2ec9905f01767 /src | |
| parent | 5c14c2b9df03bfe67eee38254e440c6dea2ba747 (diff) | |
| download | emacs-a435fc2a6d3d1e9a83b75cc8650b1fb68bd50d08.tar.gz emacs-a435fc2a6d3d1e9a83b75cc8650b1fb68bd50d08.zip | |
(register_color, unregister_colors, unregister_colors)
[DEBUG_X_COLORS]: New functions.
(x_free_colors) [DEBUG_X_COLORS]: Unregister colors.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfaces.c | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/src/xfaces.c b/src/xfaces.c index 84721a84497..c2fe41f3c8b 100644 --- a/src/xfaces.c +++ b/src/xfaces.c | |||
| @@ -527,6 +527,60 @@ extern Lisp_Object w32_list_fonts P_ ((struct frame *, Lisp_Object, int, int)); | |||
| 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. */ |
| @@ -564,10 +618,20 @@ x_free_colors (f, pixels, npixels) | |||
| 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 | ||