Commit 354884c4 authored by Stefan Monnier's avatar Stefan Monnier

Consolidate the image_cache to the terminal struct.

* termhooks.h (P_): Remove redundant def.
(struct terminal): New field `image_cache'.
* frame.h (FRAME_IMAGE_CACHE): New macro.  Use it everywhere in place
of FRAME_X_IMAGE_CACHE.
* xterm.h (struct x_display_info): Remove image_cache field.
(FRAME_X_IMAGE_CACHE): Remove.  Use FRAME_IMAGE_CACHE instead.
* w32term.h (struct w32_display_info): Remove image_cache field.
(FRAME_X_IMAGE_CACHE): Remove.  Use FRAME_IMAGE_CACHE instead.
* macterm.h (struct mac_display_info): Remove image_cache field.
(FRAME_X_IMAGE_CACHE): Remove.  Use FRAME_IMAGE_CACHE instead.
* xterm.c (x_term_init):
* w32term.c (w32_term_init):
* macterm.c (mac_term_init): Set the image_cache in the terminal.
* dispextern.h (clear_image_cache, forall_images_in_image_cache):
Remove declarations.
(clear_image_caches, mark_image_cache): New declarations.
* xfaces.c (clear_face_cache):
* xdisp.c (redisplay_internal): Use clear_image_caches.
* image.c (clear_image_cache): Don't check that a frame is on
a window-system before checking if it shares the same cache.
(clear_image_caches): New function.
(Fclear_image_cache): Use it.
(mark_image): Move from allo.c.
(mark_image_cache): Move from alloc.c and forall_images_in_image_cache.
* alloc.c (mark_image, mark_image_cache): Move to image.c.
(mark_object): Don't call mark_image_cache for frames.
(mark_terminals): Call mark_image_cache.
parent c2e42690
2008-02-22 Stefan Monnier <monnier@iro.umontreal.ca>
Consolidate the image_cache to the terminal struct.
* termhooks.h (P_): Remove redundant def.
(struct terminal): New field `image_cache'.
* frame.h (FRAME_IMAGE_CACHE): New macro. Use it everywhere in place
of FRAME_X_IMAGE_CACHE.
* xterm.h (struct x_display_info): Remove image_cache field.
(FRAME_X_IMAGE_CACHE): Remove. Use FRAME_IMAGE_CACHE instead.
* w32term.h (struct w32_display_info): Remove image_cache field.
(FRAME_X_IMAGE_CACHE): Remove. Use FRAME_IMAGE_CACHE instead.
* macterm.h (struct mac_display_info): Remove image_cache field.
(FRAME_X_IMAGE_CACHE): Remove. Use FRAME_IMAGE_CACHE instead.
* xterm.c (x_term_init):
* w32term.c (w32_term_init):
* macterm.c (mac_term_init): Set the image_cache in the terminal.
* dispextern.h (clear_image_cache, forall_images_in_image_cache):
Remove declarations.
(clear_image_caches, mark_image_cache): New declarations.
* xfaces.c (clear_face_cache):
* xdisp.c (redisplay_internal): Use clear_image_caches.
* image.c (clear_image_cache): Don't check that a frame is on
a window-system before checking if it shares the same cache.
(clear_image_caches): New function.
(Fclear_image_cache): Use it.
(mark_image): Move from allo.c.
(mark_image_cache): Move from alloc.c and forall_images_in_image_cache.
* alloc.c (mark_image, mark_image_cache): Move to image.c.
(mark_object): Don't call mark_image_cache for frames.
(mark_terminals): Call mark_image_cache.
* lisp.h (Fdelete_terminal): Declare.
* charset.h (CHECK_CHARSET, CHECK_CHARSET_GET_ID)
......
......@@ -353,8 +353,6 @@ static void mark_face_cache P_ ((struct face_cache *));
#ifdef HAVE_WINDOW_SYSTEM
extern void mark_fringe_data P_ ((void));
static void mark_image P_ ((struct image *));
static void mark_image_cache P_ ((struct frame *));
#endif /* HAVE_WINDOW_SYSTEM */
static struct Lisp_String *allocate_string P_ ((void));
......@@ -5324,34 +5322,6 @@ mark_face_cache (c)
}
#ifdef HAVE_WINDOW_SYSTEM
/* Mark Lisp objects in image IMG. */
static void
mark_image (img)
struct image *img;
{
mark_object (img->spec);
if (!NILP (img->data.lisp_val))
mark_object (img->data.lisp_val);
}
/* Mark Lisp objects in image cache of frame F. It's done this way so
that we don't have to include xterm.h here. */
static void
mark_image_cache (f)
struct frame *f;
{
forall_images_in_image_cache (f, mark_image);
}
#endif /* HAVE_X_WINDOWS */
/* Mark reference to a Lisp_Object.
If the object referred to has not been seen yet, recursively mark
......@@ -5520,12 +5490,7 @@ mark_object (arg)
{
register struct frame *ptr = XFRAME (obj);
if (mark_vectorlike (XVECTOR (obj)))
{
mark_face_cache (ptr->face_cache);
#ifdef HAVE_WINDOW_SYSTEM
mark_image_cache (ptr);
#endif /* HAVE_WINDOW_SYSTEM */
}
mark_face_cache (ptr->face_cache);
}
else if (WINDOWP (obj))
{
......@@ -5760,6 +5725,9 @@ mark_terminals (void)
for (t = terminal_list; t; t = t->next_terminal)
{
eassert (t->name != NULL);
#ifdef HAVE_WINDOW_SYSTEM
mark_image_cache (t->image_cache);
#endif /* HAVE_WINDOW_SYSTEM */
mark_vectorlike ((struct Lisp_Vector *)t);
}
}
......
......@@ -2547,8 +2547,8 @@ struct image_cache
no image with that id exists. */
#define IMAGE_FROM_ID(F, ID) \
(((ID) >= 0 && (ID) < (FRAME_X_IMAGE_CACHE (F)->used)) \
? FRAME_X_IMAGE_CACHE (F)->images[ID] \
(((ID) >= 0 && (ID) < (FRAME_IMAGE_CACHE (F)->used)) \
? FRAME_IMAGE_CACHE (F)->images[ID] \
: NULL)
/* Size of bucket vector of image caches. Should be prime. */
......@@ -2818,9 +2818,8 @@ extern Lisp_Object x_find_image_file P_ ((Lisp_Object));
void x_kill_gs_process P_ ((Pixmap, struct frame *));
struct image_cache *make_image_cache P_ ((void));
void free_image_cache P_ ((struct frame *));
void clear_image_cache P_ ((struct frame *, int));
void forall_images_in_image_cache P_ ((struct frame *,
void (*) P_ ((struct image *))));
void clear_image_caches P_ ((int));
void mark_image_cache P_ ((struct image_cache *));
int valid_image_p P_ ((Lisp_Object));
void prepare_image_for_display P_ ((struct frame *, struct image *));
int lookup_image P_ ((struct frame *, Lisp_Object));
......
......@@ -484,6 +484,9 @@ struct frame
#define FRAME_KBOARD(f) (&the_only_kboard)
#endif
/* Return a pointer to the image cache of frame F. */
#define FRAME_IMAGE_CACHE(F) ((F)->terminal->image_cache)
typedef struct frame *FRAME_PTR;
#define XFRAME(p) (eassert (FRAMEP(p)),(struct frame *) XPNTR (p))
......
......@@ -1207,7 +1207,7 @@ free_image (f, img)
{
if (img)
{
struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
struct image_cache *c = FRAME_IMAGE_CACHE (f);
/* Remove IMG from the hash table of its cache. */
if (img->prev)
......@@ -1642,7 +1642,7 @@ search_image_cache (f, spec, hash)
unsigned hash;
{
struct image *img;
struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
struct image_cache *c = FRAME_IMAGE_CACHE (f);
int i = hash % IMAGE_CACHE_BUCKETS_SIZE;
if (!c) return NULL;
......@@ -1689,7 +1689,7 @@ void
free_image_cache (f)
struct frame *f;
{
struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
struct image_cache *c = FRAME_IMAGE_CACHE (f);
if (c)
{
int i;
......@@ -1702,7 +1702,7 @@ free_image_cache (f)
xfree (c->images);
xfree (c->buckets);
xfree (c);
FRAME_X_IMAGE_CACHE (f) = NULL;
FRAME_IMAGE_CACHE (f) = NULL;
}
}
......@@ -1719,7 +1719,7 @@ clear_image_cache (f, force_p)
struct frame *f;
int force_p;
{
struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
struct image_cache *c = FRAME_IMAGE_CACHE (f);
if (c && INTEGERP (Vimage_cache_eviction_delay))
{
......@@ -1756,8 +1756,7 @@ clear_image_cache (f, force_p)
FOR_EACH_FRAME (tail, frame)
{
struct frame *f = XFRAME (frame);
if (FRAME_WINDOW_P (f)
&& FRAME_X_IMAGE_CACHE (f) == c)
if (FRAME_IMAGE_CACHE (f) == c)
clear_current_matrices (f);
}
......@@ -1768,6 +1767,18 @@ clear_image_cache (f, force_p)
}
}
void
clear_image_caches (int force_p)
{
/* FIXME: We want to do
* struct terminal *t;
* for (t = terminal_list; t; t = t->next_terminal)
* clear_image_cache (t, filter); */
Lisp_Object tail, frame;
FOR_EACH_FRAME (tail, frame)
if (FRAME_WINDOW_P (XFRAME (frame)))
clear_image_cache (XFRAME (frame), force_p);
}
DEFUN ("clear-image-cache", Fclear_image_cache, Sclear_image_cache,
0, 1, 0,
......@@ -1778,13 +1789,7 @@ FRAME t means clear the image caches of all frames. */)
Lisp_Object frame;
{
if (EQ (frame, Qt))
{
Lisp_Object tail;
FOR_EACH_FRAME (tail, frame)
if (FRAME_WINDOW_P (XFRAME (frame)))
clear_image_cache (XFRAME (frame), 1);
}
clear_image_caches (1);
else
clear_image_cache (check_x_frame (frame), 1);
......@@ -1916,7 +1921,7 @@ lookup_image (f, spec)
xassert (FRAME_WINDOW_P (f));
xassert (valid_image_p (spec));
c = FRAME_X_IMAGE_CACHE (f);
c = FRAME_IMAGE_CACHE (f);
GCPRO1 (spec);
......@@ -2027,7 +2032,7 @@ cache_image (f, img)
struct frame *f;
struct image *img;
{
struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
struct image_cache *c = FRAME_IMAGE_CACHE (f);
int i;
/* Find a free slot in c->images. */
......@@ -2062,21 +2067,28 @@ cache_image (f, img)
/* Call FN on every image in the image cache of frame F. Used to mark
Lisp Objects in the image cache. */
/* Mark Lisp objects in image IMG. */
static void
mark_image (img)
struct image *img;
{
mark_object (img->spec);
if (!NILP (img->data.lisp_val))
mark_object (img->data.lisp_val);
}
void
forall_images_in_image_cache (f, fn)
struct frame *f;
void (*fn) P_ ((struct image *img));
mark_image_cache (struct image_cache *c)
{
if (FRAME_LIVE_P (f) && FRAME_WINDOW_P (f))
if (c)
{
struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
if (c)
{
int i;
for (i = 0; i < c->used; ++i)
if (c->images[i])
fn (c->images[i]);
}
int i;
for (i = 0; i < c->used; ++i)
if (c->images[i])
mark_image (c->images[i]);
}
}
......@@ -8856,7 +8868,7 @@ x_kill_gs_process (pixmap, f)
Pixmap pixmap;
struct frame *f;
{
struct image_cache *c = FRAME_X_IMAGE_CACHE (f);
struct image_cache *c = FRAME_IMAGE_CACHE (f);
int class, i;
struct image *img;
......
......@@ -2608,7 +2608,7 @@ This function is an internal primitive--use `make-frame' instead. */)
/* With FRAME_MAC_DISPLAY_INFO set up, this unwind-protect is safe. */
#if GLYPH_DEBUG
image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
FRAME_KBOARD (f) = kb;
......@@ -3846,7 +3846,7 @@ x_create_tip_frame (dpyinfo, parms, text)
f->icon_name = Qnil;
/* FRAME_X_DISPLAY_INFO (f) = dpyinfo; */
#if GLYPH_DEBUG
image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
FRAME_KBOARD (f) = kb;
......
......@@ -12624,7 +12624,7 @@ mac_term_init (display_name, xrm_option, resource_name)
dpyinfo->grabbed = 0;
dpyinfo->root_window = NULL;
dpyinfo->image_cache = make_image_cache ();
dpyinfo->terminal->image_cache = make_image_cache ();
dpyinfo->mouse_face_beg_row = dpyinfo->mouse_face_beg_col = -1;
dpyinfo->mouse_face_end_row = dpyinfo->mouse_face_end_col = -1;
......
......@@ -185,9 +185,6 @@ struct mac_display_info
frame. It differs from x_focus_frame when we're using a global
minibuffer. */
struct frame *x_highlight_frame;
/* Cache of images. */
struct image_cache *image_cache;
};
/* This checks to make sure we have a display. */
......@@ -394,11 +391,6 @@ typedef struct mac_output mac_output;
#define FRAME_SMALLEST_FONT_HEIGHT(F) \
FRAME_MAC_DISPLAY_INFO(F)->smallest_font_height
/* Return a pointer to the image cache of frame F. */
#define FRAME_X_IMAGE_CACHE(F) FRAME_MAC_DISPLAY_INFO ((F))->image_cache
/* Mac-specific scroll bar stuff. */
......
......@@ -24,11 +24,6 @@ Boston, MA 02110-1301, USA. */
struct glyph;
struct frame;
/* Only use prototypes when lisp.h has been included. */
#ifndef P_
#define P_(X) ()
#endif
enum scroll_bar_part {
......@@ -363,6 +358,11 @@ struct terminal
struct kboard *kboard;
#endif
#ifdef HAVE_WINDOW_SYSTEM
/* Cache of images. */
struct image_cache *image_cache;
#endif /* HAVE_WINDOW_SYSTEM */
/* Device-type dependent data shared amongst all frames on this terminal. */
union display_info
{
......
......@@ -7476,7 +7476,7 @@ x_create_tip_frame (dpyinfo, parms, text)
f->icon_name = Qnil;
#if 0 /* GLYPH_DEBUG TODO: image support. */
image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
#ifdef MULTI_KBOARD
......
......@@ -7033,7 +7033,7 @@ w32_term_init (display_name, xrm_option, resource_name)
dpyinfo->resx = GetDeviceCaps (hdc, LOGPIXELSX);
dpyinfo->resy = GetDeviceCaps (hdc, LOGPIXELSY);
dpyinfo->has_palette = GetDeviceCaps (hdc, RASTERCAPS) & RC_PALETTE;
dpyinfo->image_cache = make_image_cache ();
dpyinfo->terminal->image_cache = make_image_cache ();
dpyinfo->height_in = dpyinfo->height / dpyinfo->resx;
dpyinfo->width_in = dpyinfo->width / dpyinfo->resy;
ReleaseDC (GetDesktopWindow (), hdc);
......
......@@ -233,9 +233,6 @@ struct w32_display_info
frame. It differs from w32_focus_frame when we're using a global
minibuffer. */
struct frame *x_highlight_frame;
/* Cache of images. */
struct image_cache *image_cache;
};
/* This is a chain of structures for all the displays currently in use. */
......@@ -443,11 +440,6 @@ extern struct w32_output w32term_display;
#define FRAME_SMALLEST_FONT_HEIGHT(F) \
FRAME_W32_DISPLAY_INFO(F)->smallest_font_height
/* Return a pointer to the image cache of frame F. */
#define FRAME_X_IMAGE_CACHE(F) FRAME_W32_DISPLAY_INFO ((F))->image_cache
/* W32-specific scroll bar stuff. */
......
......@@ -11797,13 +11797,7 @@ redisplay_internal (preserve_echo_area)
#ifdef HAVE_WINDOW_SYSTEM
if (clear_image_cache_count > CLEAR_IMAGE_CACHE_COUNT)
{
Lisp_Object tail, frame;
FOR_EACH_FRAME (tail, frame)
{
struct frame *f = XFRAME (frame);
if (FRAME_WINDOW_P (f))
clear_image_cache (f, 0);
}
clear_image_caches (0);
clear_image_cache_count = 0;
}
#endif /* HAVE_WINDOW_SYSTEM */
......
......@@ -894,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 */
......@@ -933,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;
......@@ -1008,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 (0);
}
#endif /* HAVE_WINDOW_SYSTEM */
}
......
......@@ -3326,7 +3326,7 @@ This function is an internal primitive--use `make-frame' instead. */)
/* With FRAME_X_DISPLAY_INFO set up, this unwind-protect is safe. */
record_unwind_protect (unwind_create_frame, frame);
#if GLYPH_DEBUG
image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
......@@ -4930,7 +4930,7 @@ x_create_tip_frame (dpyinfo, parms, text)
f->icon_name = Qnil;
FRAME_X_DISPLAY_INFO (f) = dpyinfo;
#if GLYPH_DEBUG
image_cache_refcount = FRAME_X_IMAGE_CACHE (f)->refcount;
image_cache_refcount = FRAME_IMAGE_CACHE (f)->refcount;
dpyinfo_refcount = dpyinfo->reference_count;
#endif /* GLYPH_DEBUG */
f->output_data.x->parent_desc = FRAME_X_DISPLAY_INFO (f)->root_window;
......
......@@ -11395,7 +11395,7 @@ x_term_init (display_name, xrm_option, resource_name)
dpyinfo->x_focus_frame = 0;
dpyinfo->x_focus_event_frame = 0;
dpyinfo->x_highlight_frame = 0;
dpyinfo->image_cache = make_image_cache ();
dpyinfo->terminal->image_cache = make_image_cache ();
dpyinfo->wm_type = X_WMTYPE_UNKNOWN;
/* See if we can construct pixel values from RGB values. */
......
......@@ -330,9 +330,6 @@ struct x_display_info
/* The gray pixmap. */
Pixmap gray;
/* Cache of images. */
struct image_cache *image_cache;
#ifdef HAVE_X_I18N
/* XIM (X Input method). */
XIM xim;
......@@ -737,11 +734,6 @@ enum
#define FRAME_SMALLEST_FONT_HEIGHT(F) \
FRAME_X_DISPLAY_INFO(F)->smallest_font_height
/* Return a pointer to the image cache of frame F. */
#define FRAME_X_IMAGE_CACHE(F) FRAME_X_DISPLAY_INFO ((F))->image_cache
/* X-specific scroll bar stuff. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment