diff options
| author | Gerd Moellmann | 2000-06-12 19:08:37 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 2000-06-12 19:08:37 +0000 |
| commit | 08dc08dc4d678b8585a4c95fa6396fb64fb40211 (patch) | |
| tree | a5a2490057887123f32e4760181178ffe7b88511 /src | |
| parent | 0bd5914bed0b23287c70686d8f5bb7325d53cfe5 (diff) | |
| download | emacs-08dc08dc4d678b8585a4c95fa6396fb64fb40211.tar.gz emacs-08dc08dc4d678b8585a4c95fa6396fb64fb40211.zip | |
(Fdump_colors) [DEBUG_X_COLORS]: New function.
(syms_of_xfaces): Defsubr Sdump_colors.
(x_free_colors): Don't treat b&w specially on default visual.
(x_free_dpy_colors): New function.
(free_face_colors): Don't check visual class; it's done
in x_free_colors.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xfaces.c | 191 |
1 files changed, 108 insertions, 83 deletions
diff --git a/src/xfaces.c b/src/xfaces.c index 7dd4e5ba7e1..b8db4c03612 100644 --- a/src/xfaces.c +++ b/src/xfaces.c | |||
| @@ -586,6 +586,32 @@ unregister_colors (pixels, n) | |||
| 586 | unregister_color (pixels[i]); | 586 | unregister_color (pixels[i]); |
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | |||
| 590 | DEFUN ("dump-colors", Fdump_colors, Sdump_colors, 0, 0, 0, | ||
| 591 | "Dump currently allocated colors and their reference counts to stderr.") | ||
| 592 | () | ||
| 593 | { | ||
| 594 | int i, n; | ||
| 595 | |||
| 596 | fputc ('\n', stderr); | ||
| 597 | |||
| 598 | for (i = n = 0; i < sizeof color_count / sizeof color_count[0]; ++i) | ||
| 599 | if (color_count[i]) | ||
| 600 | { | ||
| 601 | fprintf (stderr, "%3d: %5d", i, color_count[i]); | ||
| 602 | ++n; | ||
| 603 | if (n % 5 == 0) | ||
| 604 | fputc ('\n', stderr); | ||
| 605 | else | ||
| 606 | fputc ('\t', stderr); | ||
| 607 | } | ||
| 608 | |||
| 609 | if (n % 5 != 0) | ||
| 610 | fputc ('\n', stderr); | ||
| 611 | return Qnil; | ||
| 612 | } | ||
| 613 | |||
| 614 | |||
| 589 | #endif /* DEBUG_X_COLORS */ | 615 | #endif /* DEBUG_X_COLORS */ |
| 590 | 616 | ||
| 591 | /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel | 617 | /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel |
| @@ -604,44 +630,42 @@ x_free_colors (f, pixels, npixels) | |||
| 604 | necessary and some servers don't allow it. So don't do it. */ | 630 | necessary and some servers don't allow it. So don't do it. */ |
| 605 | if (class != StaticColor && class != StaticGray && class != TrueColor) | 631 | if (class != StaticColor && class != StaticGray && class != TrueColor) |
| 606 | { | 632 | { |
| 607 | Display *dpy = FRAME_X_DISPLAY (f); | 633 | XFreeColors (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), |
| 608 | Colormap cmap = FRAME_X_COLORMAP (f); | 634 | pixels, npixels, 0); |
| 609 | Screen *screen = FRAME_X_SCREEN (f); | ||
| 610 | int default_cmap_p = cmap == DefaultColormapOfScreen (screen); | ||
| 611 | |||
| 612 | if (default_cmap_p) | ||
| 613 | { | ||
| 614 | /* Be paranoid. If using the default color map, don't ever | ||
| 615 | try to free the default black and white colors. */ | ||
| 616 | int screen_no = XScreenNumberOfScreen (screen); | ||
| 617 | unsigned long black = BlackPixel (dpy, screen_no); | ||
| 618 | unsigned long white = WhitePixel (dpy, screen_no); | ||
| 619 | unsigned long *px; | ||
| 620 | int i, j; | ||
| 621 | |||
| 622 | px = (unsigned long *) alloca (npixels * sizeof *px); | ||
| 623 | for (i = j = 0; i < npixels; ++i) | ||
| 624 | if (pixels[i] != black && pixels[i] != white) | ||
| 625 | px[j++] = pixels[i]; | ||
| 626 | |||
| 627 | if (j) | ||
| 628 | { | ||
| 629 | XFreeColors (dpy, cmap, px, j, 0); | ||
| 630 | #ifdef DEBUG_X_COLORS | 635 | #ifdef DEBUG_X_COLORS |
| 631 | unregister_colors (px, j); | 636 | unregister_colors (pixels, npixels); |
| 632 | #endif | 637 | #endif |
| 633 | } | 638 | } |
| 634 | } | 639 | } |
| 635 | else | 640 | |
| 636 | { | 641 | |
| 637 | XFreeColors (dpy, cmap, pixels, npixels, 0); | 642 | /* Free colors used on frame F. PIXELS is an array of NPIXELS pixel |
| 643 | color values. Interrupt input must be blocked when this function | ||
| 644 | is called. */ | ||
| 645 | |||
| 646 | void | ||
| 647 | x_free_dpy_colors (dpy, screen, cmap, pixels, npixels) | ||
| 648 | Display *dpy; | ||
| 649 | Screen *screen; | ||
| 650 | Colormap cmap; | ||
| 651 | unsigned long *pixels; | ||
| 652 | int npixels; | ||
| 653 | { | ||
| 654 | struct x_display_info *dpyinfo = x_display_info_for_display (dpy); | ||
| 655 | int class = dpyinfo->visual->class; | ||
| 656 | |||
| 657 | /* If display has an immutable color map, freeing colors is not | ||
| 658 | necessary and some servers don't allow it. So don't do it. */ | ||
| 659 | if (class != StaticColor && class != StaticGray && class != TrueColor) | ||
| 660 | { | ||
| 661 | XFreeColors (dpy, cmap, pixels, npixels, 0); | ||
| 638 | #ifdef DEBUG_X_COLORS | 662 | #ifdef DEBUG_X_COLORS |
| 639 | unregister_colors (pixels, npixels); | 663 | unregister_colors (pixels, npixels); |
| 640 | #endif | 664 | #endif |
| 641 | } | ||
| 642 | } | 665 | } |
| 643 | } | 666 | } |
| 644 | 667 | ||
| 668 | |||
| 645 | /* Create and return a GC for use on frame F. GC values and mask | 669 | /* Create and return a GC for use on frame F. GC values and mask |
| 646 | are given by XGCV and MASK. */ | 670 | are given by XGCV and MASK. */ |
| 647 | 671 | ||
| @@ -930,7 +954,6 @@ clear_font_table (f) | |||
| 930 | struct frame *f; | 954 | struct frame *f; |
| 931 | { | 955 | { |
| 932 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); | 956 | struct x_display_info *dpyinfo = FRAME_X_DISPLAY_INFO (f); |
| 933 | Lisp_Object rest, frame; | ||
| 934 | int i; | 957 | int i; |
| 935 | 958 | ||
| 936 | xassert (FRAME_WINDOW_P (f)); | 959 | xassert (FRAME_WINDOW_P (f)); |
| @@ -1179,6 +1202,7 @@ load_face_font (f, face, c) | |||
| 1179 | ***********************************************************************/ | 1202 | ***********************************************************************/ |
| 1180 | 1203 | ||
| 1181 | /* A version of defined_color for non-X frames. */ | 1204 | /* A version of defined_color for non-X frames. */ |
| 1205 | |||
| 1182 | int | 1206 | int |
| 1183 | tty_defined_color (f, color_name, color_def, alloc) | 1207 | tty_defined_color (f, color_name, color_def, alloc) |
| 1184 | struct frame *f; | 1208 | struct frame *f; |
| @@ -1235,11 +1259,13 @@ tty_defined_color (f, color_name, color_def, alloc) | |||
| 1235 | return status; | 1259 | return status; |
| 1236 | } | 1260 | } |
| 1237 | 1261 | ||
| 1238 | /* Decide if color named COLOR is valid for the display associated | 1262 | |
| 1239 | with the frame F; if so, return the rgb values in COLOR_DEF. If | 1263 | /* Decide if color named COLOR_NAME is valid for the display |
| 1240 | ALLOC is nonzero, allocate a new colormap cell. | 1264 | associated with the frame F; if so, return the rgb values in |
| 1265 | COLOR_DEF. If ALLOC is nonzero, allocate a new colormap cell. | ||
| 1241 | 1266 | ||
| 1242 | This does the right thing for any type of frame. */ | 1267 | This does the right thing for any type of frame. */ |
| 1268 | |||
| 1243 | int | 1269 | int |
| 1244 | defined_color (f, color_name, color_def, alloc) | 1270 | defined_color (f, color_name, color_def, alloc) |
| 1245 | struct frame *f; | 1271 | struct frame *f; |
| @@ -1266,15 +1292,15 @@ defined_color (f, color_name, color_def, alloc) | |||
| 1266 | abort (); | 1292 | abort (); |
| 1267 | } | 1293 | } |
| 1268 | 1294 | ||
| 1269 | /* Given the index of the tty color, return its name, a Lisp string. */ | 1295 | |
| 1296 | /* Given the index IDX of a tty color on frame F, return its name, a | ||
| 1297 | Lisp string. */ | ||
| 1270 | 1298 | ||
| 1271 | Lisp_Object | 1299 | Lisp_Object |
| 1272 | tty_color_name (f, idx) | 1300 | tty_color_name (f, idx) |
| 1273 | struct frame *f; | 1301 | struct frame *f; |
| 1274 | int idx; | 1302 | int idx; |
| 1275 | { | 1303 | { |
| 1276 | char *color; | ||
| 1277 | |||
| 1278 | if (idx >= 0 && !NILP (Ffboundp (Qtty_color_by_index))) | 1304 | if (idx >= 0 && !NILP (Ffboundp (Qtty_color_by_index))) |
| 1279 | { | 1305 | { |
| 1280 | Lisp_Object frame; | 1306 | Lisp_Object frame; |
| @@ -1305,6 +1331,7 @@ tty_color_name (f, idx) | |||
| 1305 | return Qunspecified; | 1331 | return Qunspecified; |
| 1306 | } | 1332 | } |
| 1307 | 1333 | ||
| 1334 | |||
| 1308 | /* Return non-zero if COLOR_NAME is a shade of gray (or white or | 1335 | /* Return non-zero if COLOR_NAME is a shade of gray (or white or |
| 1309 | black) on frame F. The algorithm is taken from 20.2 faces.el. */ | 1336 | black) on frame F. The algorithm is taken from 20.2 faces.el. */ |
| 1310 | 1337 | ||
| @@ -1391,6 +1418,7 @@ COLOR must be a valid color name.") | |||
| 1391 | return Qnil; | 1418 | return Qnil; |
| 1392 | } | 1419 | } |
| 1393 | 1420 | ||
| 1421 | |||
| 1394 | /* Load color with name NAME for use by face FACE on frame F. | 1422 | /* Load color with name NAME for use by face FACE on frame F. |
| 1395 | TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX, | 1423 | TARGET_INDEX must be one of LFACE_FOREGROUND_INDEX, |
| 1396 | LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX, | 1424 | LFACE_BACKGROUND_INDEX, LFACE_UNDERLINE_INDEX, LFACE_OVERLINE_INDEX, |
| @@ -1467,6 +1495,7 @@ load_color (f, face, name, target_index) | |||
| 1467 | return color.pixel; | 1495 | return color.pixel; |
| 1468 | } | 1496 | } |
| 1469 | 1497 | ||
| 1498 | |||
| 1470 | #ifdef HAVE_WINDOW_SYSTEM | 1499 | #ifdef HAVE_WINDOW_SYSTEM |
| 1471 | 1500 | ||
| 1472 | /* Load colors for face FACE which is used on frame F. Colors are | 1501 | /* Load colors for face FACE which is used on frame F. Colors are |
| @@ -1534,60 +1563,52 @@ free_face_colors (f, face) | |||
| 1534 | struct face *face; | 1563 | struct face *face; |
| 1535 | { | 1564 | { |
| 1536 | #ifdef HAVE_X_WINDOWS | 1565 | #ifdef HAVE_X_WINDOWS |
| 1537 | int class = FRAME_X_DISPLAY_INFO (f)->visual->class; | 1566 | BLOCK_INPUT; |
| 1538 | |||
| 1539 | /* If display has an immutable color map, freeing colors is not | ||
| 1540 | necessary and some servers don't allow it. So don't do it. */ | ||
| 1541 | if (class != StaticColor | ||
| 1542 | && class != StaticGray | ||
| 1543 | && class != TrueColor) | ||
| 1544 | { | ||
| 1545 | BLOCK_INPUT; | ||
| 1546 | 1567 | ||
| 1547 | if (!face->foreground_defaulted_p) | 1568 | if (!face->foreground_defaulted_p) |
| 1548 | { | 1569 | { |
| 1549 | x_free_colors (f, &face->foreground, 1); | 1570 | x_free_colors (f, &face->foreground, 1); |
| 1550 | IF_DEBUG (--ncolors_allocated); | 1571 | IF_DEBUG (--ncolors_allocated); |
| 1551 | } | 1572 | } |
| 1552 | 1573 | ||
| 1553 | if (!face->background_defaulted_p) | 1574 | if (!face->background_defaulted_p) |
| 1554 | { | 1575 | { |
| 1555 | x_free_colors (f, &face->background, 1); | 1576 | x_free_colors (f, &face->background, 1); |
| 1556 | IF_DEBUG (--ncolors_allocated); | 1577 | IF_DEBUG (--ncolors_allocated); |
| 1557 | } | 1578 | } |
| 1558 | |||
| 1559 | if (face->underline_p | ||
| 1560 | && !face->underline_defaulted_p) | ||
| 1561 | { | ||
| 1562 | x_free_colors (f, &face->underline_color, 1); | ||
| 1563 | IF_DEBUG (--ncolors_allocated); | ||
| 1564 | } | ||
| 1565 | 1579 | ||
| 1566 | if (face->overline_p | 1580 | if (face->underline_p |
| 1567 | && !face->overline_color_defaulted_p) | 1581 | && !face->underline_defaulted_p) |
| 1568 | { | 1582 | { |
| 1569 | x_free_colors (f, &face->overline_color, 1); | 1583 | x_free_colors (f, &face->underline_color, 1); |
| 1570 | IF_DEBUG (--ncolors_allocated); | 1584 | IF_DEBUG (--ncolors_allocated); |
| 1571 | } | 1585 | } |
| 1572 | 1586 | ||
| 1573 | if (face->strike_through_p | 1587 | if (face->overline_p |
| 1574 | && !face->strike_through_color_defaulted_p) | 1588 | && !face->overline_color_defaulted_p) |
| 1575 | { | 1589 | { |
| 1576 | x_free_colors (f, &face->strike_through_color, 1); | 1590 | x_free_colors (f, &face->overline_color, 1); |
| 1577 | IF_DEBUG (--ncolors_allocated); | 1591 | IF_DEBUG (--ncolors_allocated); |
| 1578 | } | 1592 | } |
| 1579 | 1593 | ||
| 1580 | if (face->box != FACE_NO_BOX | 1594 | if (face->strike_through_p |
| 1581 | && !face->box_color_defaulted_p) | 1595 | && !face->strike_through_color_defaulted_p) |
| 1582 | { | 1596 | { |
| 1583 | x_free_colors (f, &face->box_color, 1); | 1597 | x_free_colors (f, &face->strike_through_color, 1); |
| 1584 | IF_DEBUG (--ncolors_allocated); | 1598 | IF_DEBUG (--ncolors_allocated); |
| 1585 | } | 1599 | } |
| 1586 | 1600 | ||
| 1587 | UNBLOCK_INPUT; | 1601 | if (face->box != FACE_NO_BOX |
| 1602 | && !face->box_color_defaulted_p) | ||
| 1603 | { | ||
| 1604 | x_free_colors (f, &face->box_color, 1); | ||
| 1605 | IF_DEBUG (--ncolors_allocated); | ||
| 1588 | } | 1606 | } |
| 1607 | |||
| 1608 | UNBLOCK_INPUT; | ||
| 1589 | #endif /* HAVE_X_WINDOWS */ | 1609 | #endif /* HAVE_X_WINDOWS */ |
| 1590 | } | 1610 | } |
| 1611 | |||
| 1591 | #endif /* HAVE_WINDOW_SYSTEM */ | 1612 | #endif /* HAVE_WINDOW_SYSTEM */ |
| 1592 | 1613 | ||
| 1593 | 1614 | ||
| @@ -6731,6 +6752,10 @@ syms_of_xfaces () | |||
| 6731 | defsubr (&Sclear_face_cache); | 6752 | defsubr (&Sclear_face_cache); |
| 6732 | defsubr (&Stty_suppress_bold_inverse_default_colors); | 6753 | defsubr (&Stty_suppress_bold_inverse_default_colors); |
| 6733 | 6754 | ||
| 6755 | #ifdef DEBUG_X_COLORS | ||
| 6756 | defsubr (&Sdump_colors); | ||
| 6757 | #endif | ||
| 6758 | |||
| 6734 | DEFVAR_LISP ("font-list-limit", &Vfont_list_limit, | 6759 | DEFVAR_LISP ("font-list-limit", &Vfont_list_limit, |
| 6735 | "*Limit for font matching.\n\ | 6760 | "*Limit for font matching.\n\ |
| 6736 | If an integer > 0, font matching functions won't load more than\n\ | 6761 | If an integer > 0, font matching functions won't load more than\n\ |