From: Eli Zaretskii Date: Sat, 12 Dec 2020 11:12:57 +0000 (+0200) Subject: Improve support for 'memory-report' on MS-Windows X-Git-Tag: emacs-28.0.90~4767 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=61b6cc401a9adf7f718c1c9c4350181ecd413f1c;p=emacs.git Improve support for 'memory-report' on MS-Windows * src/w32term.c (w32_image_size): New function. * src/image.c (image_frame_cache_size) [HAVE_NTGUI]: Support reporting the size of frame image cache. (image_frame_cache_size, Fimage_cache_size): The total size is now of the type 'size_t', not 'int'. --- diff --git a/src/image.c b/src/image.c index 79b275cba94..63033572ed4 100644 --- a/src/image.c +++ b/src/image.c @@ -1792,11 +1792,11 @@ which is then usually a filename. */) return Qnil; } -static int +static size_t image_frame_cache_size (struct frame *f) { - int total = 0; -#ifdef USE_CAIRO + size_t total = 0; +#if defined USE_CAIRO struct image_cache *c = FRAME_IMAGE_CACHE (f); if (!c) @@ -1810,6 +1810,19 @@ image_frame_cache_size (struct frame *f) total += img->pixmap->width * img->pixmap->height * img->pixmap->bits_per_pixel / 8; } +#elif defined HAVE_NTGUI + struct image_cache *c = FRAME_IMAGE_CACHE (f); + + if (!c) + return 0; + + for (ptrdiff_t i = 0; i < c->used; ++i) + { + struct image *img = c->images[i]; + + if (img && img->pixmap && img->pixmap != NO_PIXMAP) + total += w32_image_size (img); + } #endif return total; } @@ -1819,7 +1832,7 @@ DEFUN ("image-cache-size", Fimage_cache_size, Simage_cache_size, 0, 0, 0, (void) { Lisp_Object tail, frame; - int total = 0; + size_t total = 0; FOR_EACH_FRAME (tail, frame) if (FRAME_WINDOW_P (XFRAME (frame))) diff --git a/src/w32gui.h b/src/w32gui.h index dfec1f08617..fc8131130fb 100644 --- a/src/w32gui.h +++ b/src/w32gui.h @@ -46,6 +46,7 @@ extern int w32_load_image (struct frame *f, struct image *img, Lisp_Object spec_file, Lisp_Object spec_data); extern bool w32_can_use_native_image_api (Lisp_Object); extern void w32_gdiplus_shutdown (void); +extern size_t w32_image_size (struct image *); #define FACE_DEFAULT (~0) diff --git a/src/w32term.c b/src/w32term.c index 23cb380040b..dc5cd1f6997 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -1991,6 +1991,17 @@ w32_draw_image_foreground (struct glyph_string *s) RestoreDC (s->hdc ,-1); } +size_t +w32_image_size (struct image *img) +{ + BITMAP bm_info; + size_t rv = 0; + + if (GetObject (img->pixmap, sizeof (BITMAP), &bm_info)) + rv = bm_info.bmWidth * bm_info.bmHeight * bm_info.bmBitsPixel / 8; + return rv; +} + /* Draw a relief around the image glyph string S. */