From: Richard M. Stallman Date: Fri, 10 Nov 1995 16:19:51 +0000 (+0000) Subject: (unload_font): Invalidate computed faces. X-Git-Tag: emacs-19.34~2400 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=195f798edb7664c1e04e5a115e14e94e5565b1d6;p=emacs.git (unload_font): Invalidate computed faces. (unload_color): Likewise. (new_computed_face): Reuse invalidated computed faces. --- diff --git a/src/xfaces.c b/src/xfaces.c index dc7f4188863..254aaf275f1 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -121,6 +121,9 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ This is done from time to time so that we don't hold on to lots of GCs that are no longer needed. + If a computed face has 0 as its font, + it is unused, and can be reused by new_computed_face. + Constraints: Symbols naming faces must have associations on all frames; for any @@ -327,10 +330,28 @@ unload_font (f, font) struct frame *f; XFontStruct *font; { + int len = FRAME_N_COMPUTED_FACES (f); + int i; + if (!font || font == ((XFontStruct *) FACE_DEFAULT)) return; BLOCK_INPUT; + /* Invalidate any computed faces which use this font, + and free their GC's if they have any. */ + for (i = 0; i < len; i++) + { + struct face *face = FRAME_COMPUTED_FACES (f)[i]; + if (face->font == font) + { + Display *dpy = FRAME_X_DISPLAY (f); + if (face->gc) + XFreeGC (dpy, face->gc); + face->gc = 0; + face->font = 0; + } + } + XFreeFont (FRAME_X_DISPLAY (f), font); UNBLOCK_INPUT; } @@ -375,7 +396,26 @@ unload_color (f, pixel) necessary and some servers don't allow it. So don't do it. */ if (! (class == StaticColor || class == StaticGray || class == TrueColor)) { + int len = FRAME_N_COMPUTED_FACES (f); + int i; + BLOCK_INPUT; + /* Invalidate any computed faces which use this color, + and free their GC's if they have any. */ + for (i = 0; i < len; i++) + { + struct face *face = FRAME_COMPUTED_FACES (f)[i]; + if (face->foreground == pixel + || face->background == pixel) + { + Display *dpy = FRAME_X_DISPLAY (f); + if (face->gc) + XFreeGC (dpy, face->gc); + face->gc = 0; + face->font = 0; + } + } + XFreeColors (dpy, cmap, &pixel, 1, (unsigned long)0); UNBLOCK_INPUT; } @@ -604,7 +644,19 @@ new_computed_face (f, new_face) struct frame *f; struct face *new_face; { - int i = FRAME_N_COMPUTED_FACES (f); + int len = FRAME_N_COMPUTED_FACES (f); + int i; + + /* Search for an unused computed face in the middle of the table. */ + for (i = 0; i < len; i++) + { + struct face *face = FRAME_COMPUTED_FACES (f)[i]; + if (face->font == 0) + { + FRAME_COMPUTED_FACES (f)[i] = copy_face (new_face); + return i; + } + } if (i >= FRAME_SIZE_COMPUTED_FACES (f)) {