[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9d598ef 2/4: Add new function 'image-cache-size'
From: |
Lars Ingebrigtsen |
Subject: |
master 9d598ef 2/4: Add new function 'image-cache-size' |
Date: |
Fri, 11 Dec 2020 08:53:21 -0500 (EST) |
branch: master
commit 9d598ef93cbebe59f1d3a91f4fda35d3e00f36a9
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Add new function 'image-cache-size'
* src/image.c (Fimage_cache_size): New defun.
(image_frame_cache_size): New function.
---
doc/lispref/display.texi | 6 ++++++
etc/NEWS | 4 ++++
src/image.c | 35 +++++++++++++++++++++++++++++++++++
3 files changed, 45 insertions(+)
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 590b546..b9b05a2 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -6577,6 +6577,12 @@ except when you explicitly clear it. This mode can be
useful for
debugging.
@end defvar
+@defun image-cache-size
+This function returns the total size of the current image cache, in
+bytes. An image of size 200x100 with 24 bits per color will have a
+cache size of 60000 bytes, for instance.
+@end defun
+
@node Xwidgets
@section Embedded Native Widgets
@cindex xwidget
diff --git a/etc/NEWS b/etc/NEWS
index f277284..befcf08 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1089,6 +1089,10 @@ If 'shr-width' is non-nil, it overrides this variable.
** Images
++++
+*** New function 'image-cache-size'.
+This function returns the size of the current image cache, in bytes.
+
---
*** Animated images stop automatically under high CPU pressure sooner.
Previously, an animated image would stop animating if any single image
diff --git a/src/image.c b/src/image.c
index 522a4cf..38887ce 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1792,6 +1792,40 @@ which is then usually a filename. */)
return Qnil;
}
+static int
+image_frame_cache_size (struct frame *f)
+{
+ struct image_cache *c = FRAME_IMAGE_CACHE (f);
+ int total = 0;
+
+ if (!c)
+ return 0;
+
+ for (ptrdiff_t i = 0; i < c->used; ++i)
+ {
+ struct image *img = c->images[i];
+
+ if (img)
+ total += img->pixmap->width * img->pixmap->height *
+ img->pixmap->bits_per_pixel / 8;
+ }
+ return total;
+}
+
+DEFUN ("image-cache-size", Fimage_cache_size, Simage_cache_size, 0, 0, 0,
+ doc: /* Return the size of the image cache. */)
+ (void)
+{
+ Lisp_Object tail, frame;
+ int total = 0;
+
+ FOR_EACH_FRAME (tail, frame)
+ if (FRAME_WINDOW_P (XFRAME (frame)))
+ total += image_frame_cache_size (XFRAME (frame));
+
+ return make_int (total);
+}
+
DEFUN ("image-flush", Fimage_flush, Simage_flush,
1, 2, 0,
@@ -10703,6 +10737,7 @@ non-numeric, there is no explicit limit on the size of
images. */);
defsubr (&Simage_size);
defsubr (&Simage_mask_p);
defsubr (&Simage_metadata);
+ defsubr (&Simage_cache_size);
#ifdef GLYPH_DEBUG
defsubr (&Simagep);