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.
This commit is contained in:
Kim Woelders 2018-02-11 15:17:12 +01:00
parent db6a869b42
commit 3e5398789b
6 changed files with 80 additions and 13 deletions

View File

@ -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@:>@]),,

View File

@ -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;

View File

@ -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);
}
return size_old;
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
}
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

View File

@ -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);

View File

@ -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))
{

View File

@ -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;
size_new = atoi(value);
size_old = EImageSetCacheSize(size_new);
IpcPrintf("Image cache size %u->%u byte\n", size_old, size_new);
EImageSetCacheSize(atoi(value));
}
static void
_CfgXImageCacheCount(void *item __UNUSED__, const char *value)
{
if (!value || !value[0])
return;
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),