(plist-put (cdr image) :animate-tardiness
(+ (* (plist-get (cdr image) :animate-tardiness) 0.9)
(float-time (time-since target-time))))
- (let ((buffer (plist-get (cdr image) :animate-buffer))
- (position (plist-get (cdr image) :animate-position)))
- (when (and (buffer-live-p buffer)
+ (let* ((buffer (plist-get (cdr image) :animate-buffer))
+ (position (plist-get (cdr image) :animate-position))
+ (continue-animation
+ (and (buffer-live-p buffer)
;; If we have a :animate-position setting, the caller
;; has requested that the animation be stopped if the
;; image is no longer displayed in the buffer.
(or (< (plist-get (cdr image) :animate-tardiness) 2)
(progn
(message "Stopping animation; animation possibly too big")
- nil)))
+ nil)))))
+ (if (not continue-animation)
+ ;; Eject from the animation cache since we've decided not to
+ ;; keep updating it. This helps stop unbounded RAM usage when
+ ;; doing, for instance, `g' in an eww buffer with animated
+ ;; images.
+ (clear-image-cache nil image)
(let* ((time (prog1 (current-time)
(image-show-frame image n t)))
(speed (image-animate-get-speed image))
static unsigned long *colors_in_color_table (int *n);
#endif
+#if defined (HAVE_WEBP) || defined (HAVE_GIF)
+static void anim_prune_animation_cache (Lisp_Object);
+#endif
+
#ifdef USE_CAIRO
static Emacs_Pix_Container
}
DEFUN ("clear-image-cache", Fclear_image_cache, Sclear_image_cache,
- 0, 1, 0,
+ 0, 2, 0,
doc: /* Clear the image cache.
FILTER nil or a frame means clear all images in the selected frame.
FILTER t means clear the image caches of all frames.
Anything else means clear only those images that refer to FILTER,
-which is then usually a filename. */)
- (Lisp_Object filter)
+which is then usually a filename.
+
+This function also clears the image animation cache. If
+ANIMATION-CACHE is non-nil, only the image spec `eq' with
+ANIMATION-CACHE is removed, and other image cache entries are not
+evicted. */)
+ (Lisp_Object filter, Lisp_Object animation_cache)
{
+ if (!NILP (animation_cache))
+ {
+#if defined (HAVE_WEBP) || defined (HAVE_GIF)
+ anim_prune_animation_cache (XCDR (animation_cache));
+#endif
+ return Qnil;
+ }
+
if (! (NILP (filter) || FRAMEP (filter)))
clear_image_caches (filter);
else
}
/* Discard cached images that haven't been used for a minute. If
- CLEAR, remove all animation cache entries. */
+ CLEAR is t, remove all animation cache entries. If CLEAR is
+ anything other than nil or t, only remove the entries that have a
+ spec `eq' to CLEAR. */
static void
-anim_prune_animation_cache (bool clear)
+anim_prune_animation_cache (Lisp_Object clear)
{
struct anim_cache **pcache = &anim_cache;
struct timespec old = timespec_sub (current_timespec (),
while (*pcache)
{
struct anim_cache *cache = *pcache;
- if (clear || timespec_cmp (old, cache->update_time) > 0)
+ if (EQ (clear, Qt)
+ || (EQ (clear, Qnil) && timespec_cmp (old, cache->update_time) > 0)
+ || EQ (clear, cache->spec))
{
if (cache->handle)
cache->destructor (cache);
struct anim_cache *cache;
struct anim_cache **pcache = &anim_cache;
- anim_prune_animation_cache (false);
+ anim_prune_animation_cache (Qnil);
while (1)
{
if (!NILP (image_number))
{
/* If this is an animated image, create a cache for it. */
- cache = anim_get_animation_cache (img->spec);
+ cache = anim_get_animation_cache (XCDR (img->spec));
/* We have an old cache entry, so use it. */
if (cache->handle)
{
/* Animated image. */
int timestamp;
- struct anim_cache* cache = anim_get_animation_cache (img->spec);
+ struct anim_cache* cache = anim_get_animation_cache (XCDR (img->spec));
/* Get the next frame from the animation cache. */
if (cache->handle && cache->index == idx - 1)
{
image_prune_animation_caches (bool clear)
{
#if defined (HAVE_WEBP) || defined (HAVE_GIF)
- anim_prune_animation_cache (clear);
+ anim_prune_animation_cache (clear? Qt: Qnil);
#endif
#ifdef HAVE_IMAGEMAGICK
imagemagick_prune_animation_cache (clear);