Allow fine-grained image-cache flushing.
[bpt/emacs.git] / src / xfaces.c
index 65e70bd..897d838 100644 (file)
@@ -1,6 +1,6 @@
 /* xfaces.c -- "Face" primitives.
    Copyright (C) 1993, 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
-                 2005, 2006, 2007 Free Software Foundation, Inc.
+                 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -250,9 +250,7 @@ Boston, MA 02110-1301, USA.  */
 #include "termchar.h"
 
 #ifdef HAVE_WINDOW_SYSTEM
-#ifdef USE_FONT_BACKEND
 #include "font.h"
-#endif /* USE_FONT_BACKEND */
 #endif /* HAVE_WINDOW_SYSTEM */
 
 #ifdef HAVE_X_WINDOWS
@@ -896,9 +894,10 @@ init_frame_faces (f)
   /* Make the image cache.  */
   if (FRAME_WINDOW_P (f))
     {
-      if (FRAME_X_IMAGE_CACHE (f) == NULL)
-       FRAME_X_IMAGE_CACHE (f) = make_image_cache ();
-      ++FRAME_X_IMAGE_CACHE (f)->refcount;
+      if (FRAME_IMAGE_CACHE (f) == NULL)
+       /* Is that ever possible??  --Stef  */
+       FRAME_IMAGE_CACHE (f) = make_image_cache ();
+      ++FRAME_IMAGE_CACHE (f)->refcount;
     }
 #endif /* HAVE_WINDOW_SYSTEM */
 
@@ -935,7 +934,7 @@ free_frame_faces (f)
 #ifdef HAVE_WINDOW_SYSTEM
   if (FRAME_WINDOW_P (f))
     {
-      struct image_cache *image_cache = FRAME_X_IMAGE_CACHE (f);
+      struct image_cache *image_cache = FRAME_IMAGE_CACHE (f);
       if (image_cache)
        {
          --image_cache->refcount;
@@ -1010,11 +1009,9 @@ clear_face_cache (clear_fonts_p)
        {
          f = XFRAME (frame);
          if (FRAME_WINDOW_P (f))
-           {
              clear_face_gcs (FRAME_FACE_CACHE (f));
-             clear_image_cache (f, 0);
-           }
        }
+      clear_image_caches (Qnil);
     }
 #endif /* HAVE_WINDOW_SYSTEM */
 }
@@ -1476,10 +1473,6 @@ tty_color_name (f, idx)
   if (idx == FACE_TTY_DEFAULT_BG_COLOR)
     return build_string (unspecified_bg);
 
-#ifdef WINDOWSNT
-  return vga_stdcolor_name (idx);
-#endif
-
   return Qunspecified;
 }
 
@@ -3700,7 +3693,8 @@ set_lface_from_font_and_fontset (f, lface, font_object, fontset, force_p)
       LFACE_SWIDTH (lface) = ! NILP (val) ? val : width;
     }
 
-  LFACE_FONT (lface) = font_object;
+  LFACE_FONT (lface) = make_unibyte_string (font->font.full_name,
+                                           strlen (font->font.full_name));
   LFACE_FONTSET (lface) = fontset_name (fontset);
 }
 #endif /* USE_FONT_BACKEND */
@@ -4106,7 +4100,7 @@ Value is a vector of face attributes.  */)
     {
       global_lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE),
                                   Qunspecified);
-      AREF (global_lface, 0) = Qface;
+      ASET (global_lface, 0, Qface);
       Vface_new_frame_defaults = Fcons (Fcons (face, global_lface),
                                        Vface_new_frame_defaults);
 
@@ -4128,7 +4122,7 @@ Value is a vector of face attributes.  */)
     }
   else if (f == NULL)
     for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
-      AREF (global_lface, i) = Qunspecified;
+      ASET (global_lface, i, Qunspecified);
 
   /* Add a frame-local definition.  */
   if (f)
@@ -4137,12 +4131,12 @@ Value is a vector of face attributes.  */)
        {
          lface = Fmake_vector (make_number (LFACE_VECTOR_SIZE),
                                Qunspecified);
-         AREF (lface, 0) = Qface;
+         ASET (lface, 0, Qface);
          f->face_alist = Fcons (Fcons (face, lface), f->face_alist);
        }
       else
        for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
-         AREF (lface, i) = Qunspecified;
+         ASET (lface, i, Qunspecified);
     }
   else
     lface = global_lface;
@@ -4548,38 +4542,30 @@ FRAME 0 means change the face on all frames, and change the default
          if (enable_font_backend
              && !UNSPECIFIEDP (value) && !IGNORE_DEFFACE_P (value))
            {
-             int fontset;
-
+             tmp = Fquery_fontset (value, Qnil);
              if (EQ (attr, QCfontset))
                {
-                 Lisp_Object fontset_name = Fquery_fontset (value, Qnil);
-
-                 if (NILP (fontset_name))
+                 if (NILP (tmp))
                    signal_error ("Invalid fontset name", value);
-                 LFACE_FONTSET (lface) = value;
+                 LFACE_FONTSET (lface) = tmp;
                }
              else
                {
+                 int fontset;
                  Lisp_Object font_object;
 
-                 if (FONT_OBJECT_P (value))
+                 if (! NILP (tmp))
                    {
-                     font_object = value;
-                     fontset = FRAME_FONTSET (f);
+                     fontset = fs_query_fontset (tmp, 0);
+                     value = fontset_ascii (fontset);
                    }
                  else
                    {
-                     CHECK_STRING (value);
-
-                     fontset = fs_query_fontset (value, 0);
-                     if (fontset >= 0)
-                       value = fontset_ascii (fontset);
-                     else
-                       fontset = FRAME_FONTSET (f);
-                     font_object = font_open_by_name (f, SDATA (value));
-                     if (NILP (font_object))
-                       signal_error ("Invalid font", value);
+                     fontset = FRAME_FONTSET (f);
                    }
+                 font_object = font_open_by_name (f, SDATA (value));
+                 if (NILP (font_object))
+                   signal_error ("Invalid font", value);
                  set_lface_from_font_and_fontset (f, lface, font_object,
                                                   fontset, 1);
                }
@@ -5495,10 +5481,10 @@ lface_hash (v)
   return (hash_string_case_insensitive (v[LFACE_FAMILY_INDEX])
          ^ hash_string_case_insensitive (v[LFACE_FOREGROUND_INDEX])
          ^ hash_string_case_insensitive (v[LFACE_BACKGROUND_INDEX])
-         ^ XFASTINT (v[LFACE_WEIGHT_INDEX])
-         ^ XFASTINT (v[LFACE_SLANT_INDEX])
-         ^ XFASTINT (v[LFACE_SWIDTH_INDEX])
-         ^ XFASTINT (v[LFACE_HEIGHT_INDEX]));
+         ^ XHASH (v[LFACE_WEIGHT_INDEX])
+         ^ XHASH (v[LFACE_SLANT_INDEX])
+         ^ XHASH (v[LFACE_SWIDTH_INDEX])
+         ^ XHASH (v[LFACE_HEIGHT_INDEX]));
 }
 
 
@@ -5618,6 +5604,11 @@ prepare_face_for_display (f, face)
       if (face->font)
        {
 #ifdef HAVE_X_WINDOWS
+#ifdef USE_FONT_BACKEND
+         if (enable_font_backend)
+           xgcv.font = FRAME_X_DISPLAY_INFO (f)->font->fid;
+         else
+#endif
          xgcv.font = face->font->fid;
 #endif
 #ifdef WINDOWSNT
@@ -6723,7 +6714,8 @@ Value is ORDER.  */)
     }
 
 #ifdef USE_FONT_BACKEND
-  font_update_sort_order (font_sort_order);
+  if (enable_font_backend)
+    font_update_sort_order (font_sort_order);
 #endif /* USE_FONT_BACKEND */
 
   return Qnil;
@@ -7277,9 +7269,8 @@ face_fontset (attrs)
    (if specified).
 
    When we are choosing a font for ASCII characters, FONT-SPEC is
-   always nil.  Otherwise FONT-SPEC is a list
-       [ FAMILY WEIGHT SLANT SWIDTH ADSTYLE REGISTRY ]
-   or a string specifying a font name pattern.
+   always nil.  Otherwise FONT-SPEC is an object created by
+   `font-spec' or a string specifying a font name pattern.
 
    If NEEDS_OVERSTRIKE is not NULL, a boolean is returned in it to
    indicate whether the resulting font should be drawn using
@@ -7318,10 +7309,12 @@ choose_face_font (f, attrs, font_spec, needs_overstrike)
   if (VECTORP (font_spec))
     {
       pattern = Qnil;
-      if (STRINGP (AREF (font_spec, FONT_SPEC_FAMILY_INDEX)))
-       family = Fcons (AREF (font_spec, FONT_SPEC_FAMILY_INDEX), family);
-      adstyle = AREF (font_spec, FONT_SPEC_ADSTYLE_INDEX);
-      registry = Fcons (AREF (font_spec, FONT_SPEC_REGISTRY_INDEX), Qnil);
+      if (! NILP (AREF (font_spec, FONT_FAMILY_INDEX)))
+       family = Fcons (SYMBOL_NAME (AREF (font_spec, FONT_FAMILY_INDEX)),
+                       family);
+      adstyle = AREF (font_spec, FONT_ADSTYLE_INDEX);
+      registry = Fcons (SYMBOL_NAME (AREF (font_spec, FONT_REGISTRY_INDEX)),
+                       Qnil);
     }
   else if (STRINGP (font_spec))
     {
@@ -7670,7 +7663,7 @@ realize_non_ascii_face (f, font_id, base_face)
   face->gc = 0;
 #ifdef USE_FONT_BACKEND
   face->extra = NULL;
-#endif
+#endif /* USE_FONT_BACKEND */
 
   /* Don't try to free the colors copied bitwise from BASE_FACE.  */
   face->colors_copied_bitwise_p = 1;
@@ -7732,7 +7725,8 @@ realize_x_face (cache, attrs)
       face->font = default_face->font;
       face->font_info_id = default_face->font_info_id;
 #ifdef USE_FONT_BACKEND
-      face->font_info = default_face->font_info;
+      if (enable_font_backend)
+       face->font_info = default_face->font_info;
 #endif /* USE_FONT_BACKEND */
       face->font_name = default_face->font_name;
       face->fontset
@@ -7761,7 +7755,7 @@ realize_x_face (cache, attrs)
        font_load_for_face (f, face);
       else
 #endif /* USE_FONT_BACKEND */
-      load_face_font (f, face);
+       load_face_font (f, face);
       if (face->font)
        face->fontset = make_fontset_for_ascii_face (f, fontset, face);
       else
@@ -7949,13 +7943,11 @@ map_tty_color (f, face, idx, defaulted)
     {
       pixel = load_color (f, face, color, idx);
 
-#if defined (MSDOS) || defined (WINDOWSNT)
+#ifdef MSDOS
       /* If the foreground of the default face is the default color,
         use the foreground color defined by the frame.  */
-#ifdef MSDOS
       if (FRAME_MSDOS_P (f))
        {
-#endif /* MSDOS */
          if (pixel == default_pixel
              || pixel == FACE_TTY_DEFAULT_COLOR)
            {
@@ -7975,10 +7967,8 @@ map_tty_color (f, face, idx, defaulted)
              face->lface[idx] = tty_color_name (f, pixel);
              *defaulted = 1;
            }
-#ifdef MSDOS
-       }
-#endif
-#endif /* MSDOS or WINDOWSNT */
+        }
+#endif /* MSDOS */
     }
 
   if (foreground_p)
@@ -8159,7 +8149,7 @@ face_at_buffer_position (w, pos, region_beg, region_end,
 
   /* Look at properties from overlays.  */
   {
-    int next_overlay;
+    EMACS_INT next_overlay;
 
     GET_OVERLAYS_AT (pos, overlay_vec, noverlays, &next_overlay, 0);
     if (next_overlay < endpos)
@@ -8236,8 +8226,6 @@ face_for_overlay_string (w, pos, region_beg, region_end,
   struct frame *f = XFRAME (w->frame);
   Lisp_Object attrs[LFACE_VECTOR_SIZE];
   Lisp_Object prop, position;
-  int i, noverlays;
-  Lisp_Object *overlay_vec;
   Lisp_Object frame;
   int endpos;
   Lisp_Object propname = mouse ? Qmouse_face : Qface;