diff options
author | Kim Woelders <kim@woelders.dk> | 2018-02-05 17:10:17 +0100 |
---|---|---|
committer | Kim Woelders <kim@woelders.dk> | 2018-02-17 13:23:13 +0100 |
commit | 63103ae48ce2666f59153cd738f459ed94ba87c3 (patch) | |
tree | 5fc7b1f200db6393317379916a18974e9f14dd77 | |
parent | 5cf3e34ff169b50b87f5f6e39c0d50db94c136b6 (diff) | |
download | imlib2-63103ae48ce2666f59153cd738f459ed94ba87c3.tar.gz |
Expose XImage cache control functions
-rw-r--r-- | src/lib/Imlib2.h | 7 | ||||
-rw-r--r-- | src/lib/api.c | 82 | ||||
-rw-r--r-- | src/lib/ximage.c | 20 | ||||
-rw-r--r-- | src/lib/ximage.h | 10 |
4 files changed, 109 insertions, 10 deletions
diff --git a/src/lib/Imlib2.h b/src/lib/Imlib2.h index e2124b6..4291951 100644 --- a/src/lib/Imlib2.h +++ b/src/lib/Imlib2.h @@ -316,6 +316,13 @@ EAPI char imlib_copy_drawable_to_image(Pixmap mask, int x, int y, int destination_x, int destination_y, char need_to_grab_x); + +EAPI int imlib_get_ximage_cache_count_used(void); +EAPI int imlib_get_ximage_cache_count_max(void); +EAPI void imlib_set_ximage_cache_count_max(int count); +EAPI int imlib_get_ximage_cache_size_used(void); +EAPI int imlib_get_ximage_cache_size_max(void); +EAPI void imlib_set_ximage_cache_size_max(int bytes); #endif EAPI Imlib_Image imlib_clone_image(void); EAPI Imlib_Image imlib_create_cropped_image(int x, int y, int width, diff --git a/src/lib/api.c b/src/lib/api.c index a226206..92f059b 100644 --- a/src/lib/api.c +++ b/src/lib/api.c @@ -462,6 +462,80 @@ imlib_context_get_mask(void) CHECK_CONTEXT(ctx); return ctx->mask; } + +/** + * @return The current number of cached XImages. + */ +EAPI int +imlib_get_ximage_cache_count_used(void) +{ + CHECK_CONTEXT(ctx); + return __imlib_GetXImageCacheCountUsed(ctx->display); +} + +/** + * @return The current XImage cache max count. + */ +EAPI int +imlib_get_ximage_cache_count_max(void) +{ + CHECK_CONTEXT(ctx); + return __imlib_GetXImageCacheCountMax(ctx->display); +} + +/** + * @param count XImage cache max count. + * + * Sets the maximum number of XImages to cache. + * Setting the cache size to 0 effectively flushes the cache and keeps + * the cached XImage count at 0 until set to another value. + * Whenever you set the max count Imlib2 will flush as many old XImages + * from the cache as possible until the current cached XImage count is + * less than or equal to the cache max count. + */ +EAPI void +imlib_set_ximage_cache_count_max(int count) +{ + CHECK_CONTEXT(ctx); + __imlib_SetXImageCacheCountMax(ctx->display, count); +} + +/** + * @return The current XImage cache memory usage. + */ +EAPI int +imlib_get_ximage_cache_size_used(void) +{ + CHECK_CONTEXT(ctx); + return __imlib_GetXImageCacheSizeUsed(ctx->display); +} + +/** + * @return The current XImage cache max size. + */ +EAPI int +imlib_get_ximage_cache_size_max(void) +{ + CHECK_CONTEXT(ctx); + return __imlib_GetXImageCacheSizeMax(ctx->display); +} + +/** + * @param bytes XImage cache max size. + * + * Sets the XImage cache maximum size. The size is in bytes. + * Setting the cache size to 0 effectively flushes the cache and keeps + * the cache size at 0 until set to another value. + * Whenever you set the max size Imlib2 will flush as many old XImages + * from the cache as possible until the current XImage cache usage is + * less than or equal to the cache max size. + */ +EAPI void +imlib_set_ximage_cache_size_max(int bytes) +{ + CHECK_CONTEXT(ctx); + __imlib_SetXImageCacheSizeMax(ctx->display, bytes); +} #endif /** @@ -2730,6 +2804,7 @@ imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x, int y) { ImlibUpdate *u; ImlibImage *im; + int ximcs; CHECK_CONTEXT(ctx); CHECK_PARAM_POINTER("imlib_render_image_updates_on_drawable", "image", @@ -2740,7 +2815,9 @@ imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x, int y) return; if (__imlib_LoadImageData(im)) return; - __imlib_SetMaxXImageCount(ctx->display, 10); + ximcs = __imlib_GetXImageCacheCountMax(ctx->display); /* Save */ + if (ximcs == 0) /* Only if we don't set this up elsewhere */ + __imlib_SetXImageCacheCountMax(ctx->display, 10); for (; u; u = u->next) { __imlib_RenderImage(ctx->display, im, ctx->drawable, 0, ctx->visual, @@ -2748,7 +2825,8 @@ imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x, int y) x + u->x, y + u->y, u->w, u->h, 0, ctx->dither, 0, 0, 0, ctx->color_modifier, OP_COPY); } - __imlib_SetMaxXImageCount(ctx->display, 0); + if (ximcs == 0) + __imlib_SetXImageCacheCountMax(ctx->display, ximcs); } #endif diff --git a/src/lib/ximage.c b/src/lib/ximage.c index 54430a6..b0a6635 100644 --- a/src/lib/ximage.c +++ b/src/lib/ximage.c @@ -248,31 +248,43 @@ __imlib_ShmDestroyXImage(Display * d, XImage * xim, XShmSegmentInfo * si) } void -__imlib_SetMaxXImageCount(Display * d, int num) +__imlib_SetXImageCacheCountMax(Display * d, int num) { list_max_count = num; __imlib_FlushXImage(d); } int -__imlib_GetMaxXImageCount(Display * d) +__imlib_GetXImageCacheCountMax(Display * d) { return list_max_count; } +int +__imlib_GetXImageCacheCountUsed(Display * d) +{ + return list_num; +} + void -__imlib_SetMaxXImageTotalSize(Display * d, int num) +__imlib_SetXImageCacheSizeMax(Display * d, int num) { list_max_mem = num; __imlib_FlushXImage(d); } int -__imlib_GetMaxXImageTotalSize(Display * d) +__imlib_GetXImageCacheSizeMax(Display * d) { return list_max_mem; } +int +__imlib_GetXImageCacheSizeUsed(Display * d) +{ + return list_mem_use; +} + void __imlib_FlushXImage(Display * d) { diff --git a/src/lib/ximage.h b/src/lib/ximage.h index f12757c..e6fe8b6 100644 --- a/src/lib/ximage.h +++ b/src/lib/ximage.h @@ -6,10 +6,12 @@ #include "common.h" -void __imlib_SetMaxXImageCount(Display * d, int num); -int __imlib_GetMaxXImageCount(Display * d); -void __imlib_SetMaxXImageTotalSize(Display * d, int num); -int __imlib_GetMaxXImageTotalSize(Display * d); +void __imlib_SetXImageCacheCountMax(Display * d, int num); +int __imlib_GetXImageCacheCountMax(Display * d); +int __imlib_GetXImageCacheCountUsed(Display * d); +void __imlib_SetXImageCacheSizeMax(Display * d, int num); +int __imlib_GetXImageCacheSizeMax(Display * d); +int __imlib_GetXImageCacheSizeUsed(Display * d); void __imlib_FlushXImage(Display * d); void __imlib_ConsumeXImage(Display * d, XImage * xim); XImage *__imlib_ProduceXImage(Display * d, Visual * v, int depth, |