diff options
| author | Kenichi Handa | 2010-05-25 09:35:50 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2010-05-25 09:35:50 +0900 |
| commit | 8a2b8c4f7c2a18254fc0b34f236d7487fc7917d4 (patch) | |
| tree | 48e379874bd0bf796a12a5f43b369e0d6691a125 /src/image.c | |
| parent | 10f72a3793087770f131a0dc729f29ff50f08ad9 (diff) | |
| parent | 7eca871a82d582b986c638343f74d16b819a0f14 (diff) | |
| download | emacs-8a2b8c4f7c2a18254fc0b34f236d7487fc7917d4.tar.gz emacs-8a2b8c4f7c2a18254fc0b34f236d7487fc7917d4.zip | |
merge trunk
Diffstat (limited to 'src/image.c')
| -rw-r--r-- | src/image.c | 82 |
1 files changed, 57 insertions, 25 deletions
diff --git a/src/image.c b/src/image.c index 030e06ad77a..b9620e10948 100644 --- a/src/image.c +++ b/src/image.c | |||
| @@ -1582,29 +1582,56 @@ clear_image_cache (struct frame *f, Lisp_Object filter) | |||
| 1582 | { | 1582 | { |
| 1583 | struct image_cache *c = FRAME_IMAGE_CACHE (f); | 1583 | struct image_cache *c = FRAME_IMAGE_CACHE (f); |
| 1584 | 1584 | ||
| 1585 | if (c && (!NILP (filter) || INTEGERP (Vimage_cache_eviction_delay))) | 1585 | if (c) |
| 1586 | { | 1586 | { |
| 1587 | EMACS_TIME t; | 1587 | int i, nfreed = 0; |
| 1588 | unsigned long old; | ||
| 1589 | int i, nfreed; | ||
| 1590 | |||
| 1591 | EMACS_GET_TIME (t); | ||
| 1592 | old = EMACS_SECS (t) - XFASTINT (Vimage_cache_eviction_delay); | ||
| 1593 | 1588 | ||
| 1594 | /* Block input so that we won't be interrupted by a SIGIO | 1589 | /* Block input so that we won't be interrupted by a SIGIO |
| 1595 | while being in an inconsistent state. */ | 1590 | while being in an inconsistent state. */ |
| 1596 | BLOCK_INPUT; | 1591 | BLOCK_INPUT; |
| 1597 | 1592 | ||
| 1598 | for (i = nfreed = 0; i < c->used; ++i) | 1593 | if (!NILP (filter)) |
| 1599 | { | 1594 | { |
| 1600 | struct image *img = c->images[i]; | 1595 | /* Filter image cache. */ |
| 1601 | if (img != NULL | 1596 | for (i = 0; i < c->used; ++i) |
| 1602 | && (NILP (filter) ? img->timestamp < old | ||
| 1603 | : (EQ (Qt, filter) | ||
| 1604 | || !NILP (Fmember (filter, img->dependencies))))) | ||
| 1605 | { | 1597 | { |
| 1606 | free_image (f, img); | 1598 | struct image *img = c->images[i]; |
| 1607 | ++nfreed; | 1599 | if (img && (EQ (Qt, filter) |
| 1600 | || !NILP (Fmember (filter, img->dependencies)))) | ||
| 1601 | { | ||
| 1602 | free_image (f, img); | ||
| 1603 | ++nfreed; | ||
| 1604 | } | ||
| 1605 | } | ||
| 1606 | } | ||
| 1607 | else if (INTEGERP (Vimage_cache_eviction_delay)) | ||
| 1608 | { | ||
| 1609 | /* Free cache based on timestamp. */ | ||
| 1610 | EMACS_TIME t; | ||
| 1611 | unsigned long old; | ||
| 1612 | int delay, nimages = 0; | ||
| 1613 | |||
| 1614 | for (i = 0; i < c->used; ++i) | ||
| 1615 | if (c->images[i]) | ||
| 1616 | nimages++; | ||
| 1617 | |||
| 1618 | /* If the number of cached images has grown unusually large, | ||
| 1619 | decrease the cache eviction delay (Bug#6230). */ | ||
| 1620 | delay = XFASTINT (Vimage_cache_eviction_delay); | ||
| 1621 | if (nimages > 40) | ||
| 1622 | delay = max (1, 1600 * delay / (nimages*nimages)); | ||
| 1623 | |||
| 1624 | EMACS_GET_TIME (t); | ||
| 1625 | old = EMACS_SECS (t) - delay; | ||
| 1626 | |||
| 1627 | for (i = 0; i < c->used; ++i) | ||
| 1628 | { | ||
| 1629 | struct image *img = c->images[i]; | ||
| 1630 | if (img && img->timestamp < old) | ||
| 1631 | { | ||
| 1632 | free_image (f, img); | ||
| 1633 | ++nfreed; | ||
| 1634 | } | ||
| 1608 | } | 1635 | } |
| 1609 | } | 1636 | } |
| 1610 | 1637 | ||
| @@ -1662,11 +1689,13 @@ which is then usually a filename. */) | |||
| 1662 | } | 1689 | } |
| 1663 | 1690 | ||
| 1664 | 1691 | ||
| 1665 | DEFUN ("image-refresh", Fimage_refresh, Simage_refresh, | 1692 | DEFUN ("image-flush", Fimage_flush, Simage_flush, |
| 1666 | 1, 2, 0, | 1693 | 1, 2, 0, |
| 1667 | doc: /* Refresh the image with specification SPEC on frame FRAME. | 1694 | doc: /* Fush the image with specification SPEC on frame FRAME. |
| 1668 | If SPEC specifies an image file, the displayed image is updated with | 1695 | This removes the image from the Emacs image cache. If SPEC specifies |
| 1669 | the current contents of that file. | 1696 | an image file, the next redisplay of this image will read from the |
| 1697 | current contents of that file. | ||
| 1698 | |||
| 1670 | FRAME nil or omitted means use the selected frame. | 1699 | FRAME nil or omitted means use the selected frame. |
| 1671 | FRAME t means refresh the image on all frames. */) | 1700 | FRAME t means refresh the image on all frames. */) |
| 1672 | (spec, frame) | 1701 | (spec, frame) |
| @@ -8499,7 +8528,7 @@ non-numeric, there is no explicit limit on the size of images. */); | |||
| 8499 | 8528 | ||
| 8500 | defsubr (&Sinit_image_library); | 8529 | defsubr (&Sinit_image_library); |
| 8501 | defsubr (&Sclear_image_cache); | 8530 | defsubr (&Sclear_image_cache); |
| 8502 | defsubr (&Simage_refresh); | 8531 | defsubr (&Simage_flush); |
| 8503 | defsubr (&Simage_size); | 8532 | defsubr (&Simage_size); |
| 8504 | defsubr (&Simage_mask_p); | 8533 | defsubr (&Simage_mask_p); |
| 8505 | defsubr (&Simage_metadata); | 8534 | defsubr (&Simage_metadata); |
| @@ -8520,11 +8549,14 @@ A cross is always drawn on black & white displays. */); | |||
| 8520 | Vx_bitmap_file_path = decode_env_path ((char *) 0, PATH_BITMAPS); | 8549 | Vx_bitmap_file_path = decode_env_path ((char *) 0, PATH_BITMAPS); |
| 8521 | 8550 | ||
| 8522 | DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay, | 8551 | DEFVAR_LISP ("image-cache-eviction-delay", &Vimage_cache_eviction_delay, |
| 8523 | doc: /* Time after which cached images are removed from the cache. | 8552 | doc: /* Maximum time after which images are removed from the cache. |
| 8524 | When an image has not been displayed this many seconds, remove it | 8553 | When an image has not been displayed this many seconds, Emacs |
| 8525 | from the image cache. Value must be an integer or nil with nil | 8554 | automatically removes it from the image cache. If the cache contains |
| 8526 | meaning don't clear the cache. */); | 8555 | a large number of images, the actual eviction time may be shorter. |
| 8527 | Vimage_cache_eviction_delay = make_number (30 * 60); | 8556 | The value can also be nil, meaning the cache is never cleared. |
| 8557 | |||
| 8558 | The function `clear-image-cache' disregards this variable. */); | ||
| 8559 | Vimage_cache_eviction_delay = make_number (300); | ||
| 8528 | } | 8560 | } |
| 8529 | 8561 | ||
| 8530 | void | 8562 | void |