diff options
| author | Lars Ingebrigtsen | 2020-12-11 14:30:44 +0100 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2020-12-11 14:30:44 +0100 |
| commit | 9d598ef93cbebe59f1d3a91f4fda35d3e00f36a9 (patch) | |
| tree | 7263ecbe937978a293dd9e3fe405d3b8941da6ba | |
| parent | 14ffab8263eb219fe0c49ad4e0a3476316c542c0 (diff) | |
| download | emacs-9d598ef93cbebe59f1d3a91f4fda35d3e00f36a9.tar.gz emacs-9d598ef93cbebe59f1d3a91f4fda35d3e00f36a9.zip | |
Add new function 'image-cache-size'
* src/image.c (Fimage_cache_size): New defun.
(image_frame_cache_size): New function.
| -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 | |||
| 6577 | debugging. | 6577 | debugging. |
| 6578 | @end defvar | 6578 | @end defvar |
| 6579 | 6579 | ||
| 6580 | @defun image-cache-size | ||
| 6581 | This function returns the total size of the current image cache, in | ||
| 6582 | bytes. An image of size 200x100 with 24 bits per color will have a | ||
| 6583 | cache size of 60000 bytes, for instance. | ||
| 6584 | @end defun | ||
| 6585 | |||
| 6580 | @node Xwidgets | 6586 | @node Xwidgets |
| 6581 | @section Embedded Native Widgets | 6587 | @section Embedded Native Widgets |
| 6582 | @cindex xwidget | 6588 | @cindex xwidget |
| @@ -1089,6 +1089,10 @@ If 'shr-width' is non-nil, it overrides this variable. | |||
| 1089 | 1089 | ||
| 1090 | ** Images | 1090 | ** Images |
| 1091 | 1091 | ||
| 1092 | +++ | ||
| 1093 | *** New function 'image-cache-size'. | ||
| 1094 | This function returns the size of the current image cache, in bytes. | ||
| 1095 | |||
| 1092 | --- | 1096 | --- |
| 1093 | *** Animated images stop automatically under high CPU pressure sooner. | 1097 | *** Animated images stop automatically under high CPU pressure sooner. |
| 1094 | Previously, an animated image would stop animating if any single image | 1098 | 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. */) | |||
| 1792 | return Qnil; | 1792 | return Qnil; |
| 1793 | } | 1793 | } |
| 1794 | 1794 | ||
| 1795 | static int | ||
| 1796 | image_frame_cache_size (struct frame *f) | ||
| 1797 | { | ||
| 1798 | struct image_cache *c = FRAME_IMAGE_CACHE (f); | ||
| 1799 | int total = 0; | ||
| 1800 | |||
| 1801 | if (!c) | ||
| 1802 | return 0; | ||
| 1803 | |||
| 1804 | for (ptrdiff_t i = 0; i < c->used; ++i) | ||
| 1805 | { | ||
| 1806 | struct image *img = c->images[i]; | ||
| 1807 | |||
| 1808 | if (img) | ||
| 1809 | total += img->pixmap->width * img->pixmap->height * | ||
| 1810 | img->pixmap->bits_per_pixel / 8; | ||
| 1811 | } | ||
| 1812 | return total; | ||
| 1813 | } | ||
| 1814 | |||
| 1815 | DEFUN ("image-cache-size", Fimage_cache_size, Simage_cache_size, 0, 0, 0, | ||
| 1816 | doc: /* Return the size of the image cache. */) | ||
| 1817 | (void) | ||
| 1818 | { | ||
| 1819 | Lisp_Object tail, frame; | ||
| 1820 | int total = 0; | ||
| 1821 | |||
| 1822 | FOR_EACH_FRAME (tail, frame) | ||
| 1823 | if (FRAME_WINDOW_P (XFRAME (frame))) | ||
| 1824 | total += image_frame_cache_size (XFRAME (frame)); | ||
| 1825 | |||
| 1826 | return make_int (total); | ||
| 1827 | } | ||
| 1828 | |||
| 1795 | 1829 | ||
| 1796 | DEFUN ("image-flush", Fimage_flush, Simage_flush, | 1830 | DEFUN ("image-flush", Fimage_flush, Simage_flush, |
| 1797 | 1, 2, 0, | 1831 | 1, 2, 0, |
| @@ -10703,6 +10737,7 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 10703 | defsubr (&Simage_size); | 10737 | defsubr (&Simage_size); |
| 10704 | defsubr (&Simage_mask_p); | 10738 | defsubr (&Simage_mask_p); |
| 10705 | defsubr (&Simage_metadata); | 10739 | defsubr (&Simage_metadata); |
| 10740 | defsubr (&Simage_cache_size); | ||
| 10706 | 10741 | ||
| 10707 | #ifdef GLYPH_DEBUG | 10742 | #ifdef GLYPH_DEBUG |
| 10708 | defsubr (&Simagep); | 10743 | defsubr (&Simagep); |