diff options
-rw-r--r-- | doc/lispref/display.texi | 6 | ||||
-rw-r--r-- | etc/NEWS | 4 | ||||
-rw-r--r-- | src/image.c | 35 |
3 files changed, 45 insertions, 0 deletions
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 590b54668f7..b9b05a2a422 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 @@ -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 522a4cf7c0f..38887ced25b 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); |