diff options
| author | Mattias EngdegÄrd | 2020-12-19 16:47:32 +0100 |
|---|---|---|
| committer | Mattias EngdegÄrd | 2020-12-20 18:17:17 +0100 |
| commit | 409a9dbe9da64b4d75fec1f511e168c94e60e35b (patch) | |
| tree | 467c1432c21840d47d1eaa1574585d931bf0b62c /src | |
| parent | 87b82a1969edf80d3bd4781454ec9fc968773a6d (diff) | |
| download | emacs-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')
| -rw-r--r-- | src/image.c | 58 | ||||
| -rw-r--r-- | src/nsimage.m | 22 | ||||
| -rw-r--r-- | src/nsterm.h | 2 | ||||
| -rw-r--r-- | src/w32gui.h | 2 | ||||
| -rw-r--r-- | src/w32term.c | 4 |
5 files changed, 68 insertions, 20 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 | ||
| 1795 | static size_t | 1795 | static size_t |
| 1796 | image_frame_cache_size (struct frame *f) | 1796 | image_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 | ||
| 1838 | static size_t | ||
| 1839 | image_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 | ||
diff --git a/src/nsimage.m b/src/nsimage.m index da6f01cf6a3..f9fb368ba80 100644 --- a/src/nsimage.m +++ b/src/nsimage.m | |||
| @@ -235,6 +235,11 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 235 | [(EmacsImage *)img setAlphaAtX: x Y: y to: a]; | 235 | [(EmacsImage *)img setAlphaAtX: x Y: y to: a]; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | size_t | ||
| 239 | ns_image_size_in_bytes (void *img) | ||
| 240 | { | ||
| 241 | return [(EmacsImage *)img sizeInBytes]; | ||
| 242 | } | ||
| 238 | 243 | ||
| 239 | /* ========================================================================== | 244 | /* ========================================================================== |
| 240 | 245 | ||
| @@ -610,5 +615,22 @@ ns_set_alpha (void *img, int x, int y, unsigned char a) | |||
| 610 | smoothing = s; | 615 | smoothing = s; |
| 611 | } | 616 | } |
| 612 | 617 | ||
| 618 | /* Approximate allocated size of image in bytes. */ | ||
| 619 | - (size_t) sizeInBytes | ||
| 620 | { | ||
| 621 | size_t bytes = 0; | ||
| 622 | NSImageRep *rep; | ||
| 623 | NSEnumerator *reps = [[self representations] objectEnumerator]; | ||
| 624 | while ((rep = (NSImageRep *) [reps nextObject])) | ||
| 625 | { | ||
| 626 | if ([rep respondsToSelector: @selector (bytesPerRow)]) | ||
| 627 | { | ||
| 628 | NSBitmapImageRep *bmr = (NSBitmapImageRep *) rep; | ||
| 629 | bytes += [bmr bytesPerRow] * [bmr numberOfPlanes] * [bmr pixelsHigh]; | ||
| 630 | } | ||
| 631 | } | ||
| 632 | return bytes; | ||
| 633 | } | ||
| 634 | |||
| 613 | 635 | ||
| 614 | @end | 636 | @end |
diff --git a/src/nsterm.h b/src/nsterm.h index f292993d8f7..94472ec1070 100644 --- a/src/nsterm.h +++ b/src/nsterm.h | |||
| @@ -666,6 +666,7 @@ typedef id instancetype; | |||
| 666 | - (BOOL)setFrame: (unsigned int) index; | 666 | - (BOOL)setFrame: (unsigned int) index; |
| 667 | - (void)setTransform: (double[3][3]) m; | 667 | - (void)setTransform: (double[3][3]) m; |
| 668 | - (void)setSmoothing: (BOOL)s; | 668 | - (void)setSmoothing: (BOOL)s; |
| 669 | - (size_t)sizeInBytes; | ||
| 669 | @end | 670 | @end |
| 670 | 671 | ||
| 671 | 672 | ||
| @@ -1195,6 +1196,7 @@ extern void ns_set_alpha (void *img, int x, int y, unsigned char a); | |||
| 1195 | 1196 | ||
| 1196 | extern int ns_display_pixel_height (struct ns_display_info *); | 1197 | extern int ns_display_pixel_height (struct ns_display_info *); |
| 1197 | extern int ns_display_pixel_width (struct ns_display_info *); | 1198 | extern int ns_display_pixel_width (struct ns_display_info *); |
| 1199 | extern size_t ns_image_size_in_bytes (void *img); | ||
| 1198 | 1200 | ||
| 1199 | /* This in nsterm.m */ | 1201 | /* This in nsterm.m */ |
| 1200 | extern float ns_antialias_threshold; | 1202 | extern float ns_antialias_threshold; |
diff --git a/src/w32gui.h b/src/w32gui.h index fc8131130fb..f6cfa9fb87e 100644 --- a/src/w32gui.h +++ b/src/w32gui.h | |||
| @@ -46,7 +46,7 @@ extern int w32_load_image (struct frame *f, struct image *img, | |||
| 46 | Lisp_Object spec_file, Lisp_Object spec_data); | 46 | Lisp_Object spec_file, Lisp_Object spec_data); |
| 47 | extern bool w32_can_use_native_image_api (Lisp_Object); | 47 | extern bool w32_can_use_native_image_api (Lisp_Object); |
| 48 | extern void w32_gdiplus_shutdown (void); | 48 | extern void w32_gdiplus_shutdown (void); |
| 49 | extern size_t w32_image_size (struct image *); | 49 | extern size_t w32_image_size (Emacs_Pixmap); |
| 50 | 50 | ||
| 51 | #define FACE_DEFAULT (~0) | 51 | #define FACE_DEFAULT (~0) |
| 52 | 52 | ||
diff --git a/src/w32term.c b/src/w32term.c index a038e4593f4..989b056ff2e 100644 --- a/src/w32term.c +++ b/src/w32term.c | |||
| @@ -1992,12 +1992,12 @@ w32_draw_image_foreground (struct glyph_string *s) | |||
| 1992 | } | 1992 | } |
| 1993 | 1993 | ||
| 1994 | size_t | 1994 | size_t |
| 1995 | w32_image_size (struct image *img) | 1995 | w32_image_size (Emacs_Pixmap pixmap) |
| 1996 | { | 1996 | { |
| 1997 | BITMAP bm_info; | 1997 | BITMAP bm_info; |
| 1998 | size_t rv = 0; | 1998 | size_t rv = 0; |
| 1999 | 1999 | ||
| 2000 | if (GetObject (img->pixmap, sizeof (BITMAP), &bm_info)) | 2000 | if (GetObject (pixmap, sizeof (BITMAP), &bm_info)) |
| 2001 | rv = bm_info.bmWidth * bm_info.bmHeight * bm_info.bmBitsPixel / 8; | 2001 | rv = bm_info.bmWidth * bm_info.bmHeight * bm_info.bmBitsPixel / 8; |
| 2002 | return rv; | 2002 | return rv; |
| 2003 | } | 2003 | } |