kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=3e5398789b2647b5b381820a61275db3f3d5b8c1

commit 3e5398789b2647b5b381820a61275db3f3d5b8c1
Author: Kim Woelders <[email protected]>
Date:   Sun Feb 11 15:17:12 2018 +0100

    Add some image cache control
    
    Most of this requires imlib2-1.5.0.
    
    - Enable showing setup and usage.
    - Store regular image cache size in configuration.
    - Add control for XImage cache item count.
---
 configure.ac   |  4 ++++
 src/E.h        |  1 +
 src/eimage.c   | 39 +++++++++++++++++++++++++++++++++------
 src/eimage.h   | 19 +++++++++++++++++--
 src/ipc.c      | 14 ++++++++++++++
 src/mod-misc.c | 14 ++++++++++----
 6 files changed, 79 insertions(+), 12 deletions(-)

diff --git a/configure.ac b/configure.ac
index 8c4de94d..420f9fb9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -153,6 +153,10 @@ AC_CHECK_LIB(Imlib2, imlib_context_disconnect_display,
   AC_DEFINE(HAVE_IMLIB_CONTEXT_DISCONNECT_DISPLAY, 1,
             [Imlib2 has imlib_context_disconnect_display]),,
   $IMLIB2_LIBS)
+AC_CHECK_LIB(Imlib2, imlib_set_ximage_cache_count_max,
+  AC_DEFINE(HAVE_IMLIB_XIMAGE_CACHE_CONTROL, 1,
+            [Imlib2 has XImage cache control functions]),,
+  $IMLIB2_LIBS)
 
 AC_ARG_ENABLE(sm,
   AC_HELP_STRING([--enable-sm], [compile with session management support 
@<:@default=yes@:>@]),,
diff --git a/src/E.h b/src/E.h
index 28bf4365..c8263c2d 100644
--- a/src/E.h
+++ b/src/E.h
@@ -301,6 +301,7 @@ typedef struct {
       char                argb_clients;
       char                argb_clients_inherit_attr;
       int                 image_cache_size;
+      int                 ximage_cache_count;
       int                 mask_alpha_threshold;
       char                enable_startup_id;
       char                use_render_for_scaling;
diff --git a/src/eimage.c b/src/eimage.c
index 4345c900..4d8ca53f 100644
--- a/src/eimage.c
+++ b/src/eimage.c
@@ -32,10 +32,14 @@
 #include "eimage.h"
 #include "xwin.h"
 
+#define IMG_CACHE_DEFAULT_SIZE          (2 * 1024 * 1024)
+#define XIM_CACHE_DEFAULT_COUNT         0
+
 void
 EImageInit(void)
 {
-   imlib_set_cache_size(2048 * 1024);
+   EImageSetCacheSize(Conf.testing.image_cache_size);
+   EImageSetXImageCacheSize(Conf.testing.ximage_cache_count, -1);
    imlib_set_font_cache_size(512 * 1024);
 
    imlib_set_color_usage(128);
@@ -60,15 +64,38 @@ EImageExit(int quit __UNUSED__)
 #endif
 }
 
-int
+void
 EImageSetCacheSize(int size)
 {
-   int                 size_old;
-
-   size_old = imlib_get_cache_size();
+   Conf.testing.image_cache_size = size;
+   if (size < 0)
+      size = IMG_CACHE_DEFAULT_SIZE;
    imlib_set_cache_size(size);
+}
+
+void
+EImageSetXImageCacheSize(int count, int size __UNUSED__)
+{
+   Conf.testing.ximage_cache_count = count;
+#if HAVE_IMLIB_XIMAGE_CACHE_CONTROL
+   if (count < 0)
+      count = XIM_CACHE_DEFAULT_COUNT;
+   imlib_set_ximage_cache_count_max(count);
+#endif
+}
 
-   return size_old;
+void
+EImageGetCacheInfo(ECacheInfo * ci)
+{
+   memset(ci, 0, sizeof(ECacheInfo));
+   ci->img.max_mem = imlib_get_cache_size();
+#if HAVE_IMLIB_XIMAGE_CACHE_CONTROL
+   ci->img.used_mem = imlib_get_cache_used();
+   ci->xim.max_mem = imlib_get_ximage_cache_size_max();
+   ci->xim.used_mem = imlib_get_ximage_cache_size_used();
+   ci->xim.max_cnt = imlib_get_ximage_cache_count_max();
+   ci->xim.used_cnt = imlib_get_ximage_cache_count_used();
+#endif
 }
 
 static void
diff --git a/src/eimage.h b/src/eimage.h
index bf23d63b..ae760318 100644
--- a/src/eimage.h
+++ b/src/eimage.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2004-2014 Kim Woelders
+ * Copyright (C) 2004-2018 Kim Woelders
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to
@@ -32,6 +32,19 @@ typedef struct {
    int                 left, right, top, bottom;
 } EImageBorder;
 
+typedef struct {
+   struct {
+      int                 max_mem;
+      int                 used_mem;
+   } img;
+   struct {
+      int                 max_mem;
+      int                 used_mem;
+      int                 max_cnt;
+      int                 used_cnt;
+   } xim;
+} ECacheInfo;
+
 #define EIMAGE_BLEND            0x0001
 #define EIMAGE_ANTI_ALIAS       0x0002
 #define EIMAGE_HIGH_MASK_THR    0x0004
@@ -39,7 +52,9 @@ typedef struct {
 
 void                EImageInit(void);
 void                EImageExit(int quit);
-int                 EImageSetCacheSize(int size);
+void                EImageSetCacheSize(int size);
+void                EImageSetXImageCacheSize(int count, int size);
+void                EImageGetCacheInfo(ECacheInfo * ci);
 
 EImage             *EImageCreate(int w, int h);
 EImage             *EImageCreateFromData(int w, int h, unsigned int *data);
diff --git a/src/ipc.c b/src/ipc.c
index ba345789..3e09edc6 100644
--- a/src/ipc.c
+++ b/src/ipc.c
@@ -1061,6 +1061,20 @@ IPC_Debug(const char *params)
             IpcPrintf("Sync off\n");
          }
      }
+   else if (!strncmp(param, "cache", 2))
+     {
+       ECacheInfo          ci;
+
+       EImageGetCacheInfo(&ci);
+       IpcPrintf("Cache         %10s %10s\n"
+                 "Image  bytes: %10d %10d\n"
+                 "Ximage bytes: %10d %10d\n"
+                 "Ximage count: %10d %10d\n",
+                 "Max", "Used",
+                 ci.img.max_mem, ci.img.used_mem,
+                 ci.xim.max_mem, ci.xim.used_mem,
+                 ci.xim.max_cnt, ci.xim.used_cnt);
+     }
 #if 0
    else if (!strncmp(param, "dump", 2))
      {
diff --git a/src/mod-misc.c b/src/mod-misc.c
index 0cb05e52..0a8b8478 100644
--- a/src/mod-misc.c
+++ b/src/mod-misc.c
@@ -117,14 +117,19 @@ MiscSighan(int sig, void *prm __UNUSED__)
 static void
 _CfgImageCacheSize(void *item __UNUSED__, const char *value)
 {
-   int                 size_old, size_new;
+   if (!value || !value[0])
+      return;
+
+   EImageSetCacheSize(atoi(value));
+}
 
+static void
+_CfgXImageCacheCount(void *item __UNUSED__, const char *value)
+{
    if (!value || !value[0])
       return;
 
-   size_new = atoi(value);
-   size_old = EImageSetCacheSize(size_new);
-   IpcPrintf("Image cache size %u->%u byte\n", size_old, size_new);
+   EImageSetXImageCacheSize(atoi(value), -1);
 }
 
 static const CfgItem MiscCfgItems[] = {
@@ -203,6 +208,7 @@ static const CfgItem MiscCfgItems[] = {
    CFG_ITEM_BOOL(Conf, testing.argb_clients, 0),
    CFG_ITEM_BOOL(Conf, testing.argb_clients_inherit_attr, 0),
    CFG_FUNC_INT(Conf, testing.image_cache_size, -1, _CfgImageCacheSize),
+   CFG_FUNC_INT(Conf, testing.ximage_cache_count, -1, _CfgXImageCacheCount),
    CFG_ITEM_INT(Conf, testing.mask_alpha_threshold, 8),
    CFG_ITEM_BOOL(Conf, testing.enable_startup_id, 1),
    CFG_ITEM_BOOL(Conf, testing.use_render_for_scaling, 0),

-- 


Reply via email to