aboutsummaryrefslogtreecommitdiffstats
path: root/src/image.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd2020-12-19 16:47:32 +0100
committerMattias EngdegÄrd2020-12-20 18:17:17 +0100
commit409a9dbe9da64b4d75fec1f511e168c94e60e35b (patch)
tree467c1432c21840d47d1eaa1574585d931bf0b62c /src/image.c
parent87b82a1969edf80d3bd4781454ec9fc968773a6d (diff)
downloademacs-409a9dbe9da64b4d75fec1f511e168c94e60e35b.tar.gz
emacs-409a9dbe9da64b4d75fec1f511e168c94e60e35b.zip
image-cache-size improvements
Implement for non-Cairo X11 and NS. Count masks as well, and XImage objects on X11. * src/image.c (image_size_in_bytes): New. (image_frame_cache_size): Use image_size_in_bytes. * src/nsterm.h: * src/nsimage.m (ns_image_size_in_bytes, [EmacsImage sizeInBytes]): New function and method. * src/w32gui.h: * src/w32term.c (w32_image_size): Update signature.
Diffstat (limited to 'src/image.c')
-rw-r--r--src/image.c58
1 files changed, 41 insertions, 17 deletions
diff --git a/src/image.c b/src/image.c
index dc06e9ce208..d0ae44e7df7 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1793,37 +1793,61 @@ which is then usually a filename. */)
1793} 1793}
1794 1794
1795static size_t 1795static size_t
1796image_frame_cache_size (struct frame *f) 1796image_size_in_bytes (struct image *img)
1797{ 1797{
1798 size_t total = 0; 1798 size_t size = 0;
1799
1799#if defined USE_CAIRO 1800#if defined USE_CAIRO
1800 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1801 Emacs_Pixmap pm = img->pixmap;
1802 if (pm)
1803 size += pm->height * pm->bytes_per_line;
1804 Emacs_Pixmap msk = img->mask;
1805 if (msk)
1806 size += msk->height * msk->bytes_per_line;
1801 1807
1802 if (!c) 1808#elif defined HAVE_X_WINDOWS
1803 return 0; 1809 /* Use a nominal depth of 24 bpp for pixmap and 1 bpp for mask,
1810 to avoid having to query the server. */
1811 if (img->pixmap != NO_PIXMAP)
1812 size += img->width * img->height * 3;
1813 if (img->mask != NO_PIXMAP)
1814 size += img->width * img->height / 8;
1815
1816 if (img->ximg && img->ximg->data)
1817 size += img->ximg->bytes_per_line * img->ximg->height;
1818 if (img->mask_img && img->mask_img->data)
1819 size += img->mask_img->bytes_per_line * img->mask_img->height;
1804 1820
1805 for (ptrdiff_t i = 0; i < c->used; ++i) 1821#elif defined HAVE_NS
1806 { 1822 if (img->pixmap)
1807 struct image *img = c->images[i]; 1823 size += ns_image_size_in_bytes (img->pixmap);
1824 if (img->mask)
1825 size += ns_image_size_in_bytes (img->mask);
1808 1826
1809 if (img && img->pixmap && img->pixmap != NO_PIXMAP)
1810 total += img->pixmap->width * img->pixmap->height *
1811 img->pixmap->bits_per_pixel / 8;
1812 }
1813#elif defined HAVE_NTGUI 1827#elif defined HAVE_NTGUI
1814 struct image_cache *c = FRAME_IMAGE_CACHE (f); 1828 if (img->pixmap)
1829 size += w32_image_size (img->pixmap);
1830 if (img->mask)
1831 size += w32_image_size (img->mask);
1832
1833#endif
1834
1835 return size;
1836}
1815 1837
1838static size_t
1839image_frame_cache_size (struct frame *f)
1840{
1841 struct image_cache *c = FRAME_IMAGE_CACHE (f);
1816 if (!c) 1842 if (!c)
1817 return 0; 1843 return 0;
1818 1844
1845 size_t total = 0;
1819 for (ptrdiff_t i = 0; i < c->used; ++i) 1846 for (ptrdiff_t i = 0; i < c->used; ++i)
1820 { 1847 {
1821 struct image *img = c->images[i]; 1848 struct image *img = c->images[i];
1822 1849 total += img ? image_size_in_bytes (img) : 0;
1823 if (img && img->pixmap && img->pixmap != NO_PIXMAP)
1824 total += w32_image_size (img);
1825 } 1850 }
1826#endif
1827 return total; 1851 return total;
1828} 1852}
1829 1853