2009-03-26 00:14:08 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
|
2009-12-19 02:58:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
# include <Evil.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-26 00:14:08 -07:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
#include "evas_image_private.h"
|
|
|
|
|
2009-03-27 00:34:45 -07:00
|
|
|
#define SCALECACHE 1
|
2009-03-26 00:14:08 -07:00
|
|
|
|
2009-03-30 21:12:09 -07:00
|
|
|
#define MAX_SCALEITEMS 32
|
2009-03-26 00:14:08 -07:00
|
|
|
#define MIN_SCALE_USES 3
|
2009-05-06 05:36:06 -07:00
|
|
|
//#define MIN_SCALE_AGE_GAP 5000
|
|
|
|
#define MAX_SCALECACHE_DIM 3200
|
2009-03-26 20:50:03 -07:00
|
|
|
#define FLOP_ADD 4
|
|
|
|
#define MAX_FLOP_COUNT 16
|
|
|
|
#define FLOP_DEL 1
|
2009-05-06 05:36:06 -07:00
|
|
|
#define SCALE_CACHE_SIZE 4 * 1024 * 1024
|
|
|
|
//#define SCALE_CACHE_SIZE 0
|
2009-03-26 00:14:08 -07:00
|
|
|
|
|
|
|
typedef struct _Scaleitem Scaleitem;
|
|
|
|
|
|
|
|
struct _Scaleitem
|
|
|
|
{
|
2009-03-26 05:47:44 -07:00
|
|
|
EINA_INLIST;
|
2009-03-26 00:14:08 -07:00
|
|
|
unsigned long long usage;
|
|
|
|
unsigned long long usage_count;
|
2009-03-26 05:47:44 -07:00
|
|
|
RGBA_Image *im, *parent_im;
|
2009-03-26 00:14:08 -07:00
|
|
|
int src_x, src_y, src_w, src_h;
|
|
|
|
int dst_w, dst_h;
|
2009-05-06 05:36:06 -07:00
|
|
|
int flop;
|
|
|
|
int size_adjust;
|
|
|
|
Eina_Bool forced_unload : 1;
|
|
|
|
Eina_Bool smooth : 1;
|
|
|
|
Eina_Bool populate_me : 1;
|
2009-03-26 00:14:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
static unsigned long long use_counter = 0;
|
|
|
|
|
|
|
|
#ifdef BUILD_PTHREAD
|
|
|
|
static LK(cache_lock);
|
|
|
|
#endif
|
2009-03-26 05:47:44 -07:00
|
|
|
static Eina_Inlist *cache_list = NULL;
|
|
|
|
static int cache_size = 0;
|
2009-05-08 04:26:25 -07:00
|
|
|
static int init = 0;
|
|
|
|
|
2009-03-26 20:50:03 -07:00
|
|
|
static int max_cache_size = SCALE_CACHE_SIZE;
|
2009-05-08 04:26:25 -07:00
|
|
|
static int max_dimension = MAX_SCALECACHE_DIM;
|
|
|
|
static int max_flop_count = MAX_FLOP_COUNT;
|
|
|
|
static int max_scale_items = MAX_SCALEITEMS;
|
|
|
|
static int min_scale_uses = MIN_SCALE_USES;
|
2009-03-26 00:14:08 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_common_scalecache_init(void)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
2009-05-08 04:26:25 -07:00
|
|
|
const char *s;
|
|
|
|
|
|
|
|
init++;
|
|
|
|
if (init > 1) return;
|
2009-03-26 00:14:08 -07:00
|
|
|
use_counter = 0;
|
|
|
|
LKI(cache_lock);
|
2009-05-08 04:26:25 -07:00
|
|
|
s = getenv("EVAS_SCALECACHE_SIZE");
|
|
|
|
if (s) max_cache_size = atoi(s) * 1024;
|
|
|
|
s = getenv("EVAS_SCALECACHE_MAX_DIMENSION");
|
|
|
|
if (s) max_dimension = atoi(s);
|
|
|
|
s = getenv("EVAS_SCALECACHE_MAX_FLOP_COUNT");
|
|
|
|
if (s) max_flop_count = atoi(s);
|
|
|
|
s = getenv("EVAS_SCALECACHE_MAX_ITEMS");
|
|
|
|
if (s) max_scale_items = atoi(s);
|
|
|
|
s = getenv("EVAS_SCALECACHE_MIN_USES");
|
|
|
|
if (s) min_scale_uses = atoi(s);
|
2009-03-26 00:14:08 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_common_scalecache_shutdown(void)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
2009-05-08 04:26:25 -07:00
|
|
|
init--;
|
2009-03-26 00:14:08 -07:00
|
|
|
LKD(cache_lock);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_common_rgba_image_scalecache_init(Image_Entry *ie)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
LKI(im->cache.lock);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_common_rgba_image_scalecache_shutdown(Image_Entry *ie)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
evas_common_rgba_image_scalecache_dirty(ie);
|
|
|
|
LKD(im->cache.lock);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_common_rgba_image_scalecache_dirty(Image_Entry *ie)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
LKL(im->cache.lock);
|
|
|
|
while (im->cache.list)
|
|
|
|
{
|
|
|
|
Scaleitem *sci;
|
|
|
|
sci = im->cache.list->data;
|
2009-03-26 05:47:44 -07:00
|
|
|
im->cache.list = eina_list_remove(im->cache.list, sci);
|
|
|
|
if (sci->im)
|
|
|
|
{
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF(" 0- %i", sci->dst_w * sci->dst_h * 4);
|
2009-04-09 06:20:00 -07:00
|
|
|
LKL(cache_lock);
|
2009-03-26 05:47:44 -07:00
|
|
|
evas_common_rgba_image_free(&sci->im->cache_entry);
|
2009-05-06 05:36:06 -07:00
|
|
|
if (!sci->forced_unload)
|
|
|
|
cache_size -= sci->dst_w * sci->dst_h * 4;
|
|
|
|
else
|
|
|
|
cache_size -= sci->size_adjust;
|
2009-03-26 05:47:44 -07:00
|
|
|
cache_list = eina_inlist_remove(cache_list, (Eina_Inlist *)sci);
|
2009-04-09 06:20:00 -07:00
|
|
|
LKU(cache_lock);
|
2009-03-26 05:47:44 -07:00
|
|
|
}
|
2009-03-26 00:14:08 -07:00
|
|
|
free(sci);
|
|
|
|
}
|
|
|
|
LKU(im->cache.lock);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evas_common_rgba_image_scalecache_orig_use(Image_Entry *ie)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
LKL(im->cache.lock);
|
|
|
|
use_counter++;
|
|
|
|
// FIXME: if orig not loaded, reload
|
|
|
|
// FIXME: mark orig with current used counter
|
2009-03-26 05:47:44 -07:00
|
|
|
im->cache.orig_usage++;
|
|
|
|
im->cache.usage_count = use_counter;
|
2009-03-26 00:14:08 -07:00
|
|
|
LKU(im->cache.lock);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
evas_common_rgba_image_scalecache_usage_get(Image_Entry *ie)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
int size = 0;
|
|
|
|
Eina_List *l;
|
|
|
|
Scaleitem *sci;
|
|
|
|
LKL(im->cache.lock);
|
|
|
|
EINA_LIST_FOREACH(im->cache.list, l, sci)
|
|
|
|
{
|
|
|
|
if (sci->im) size += sci->dst_w * sci->dst_h * 4;
|
|
|
|
}
|
|
|
|
LKU(im->cache.lock);
|
|
|
|
return size;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SCALECACHE
|
2009-03-26 20:50:03 -07:00
|
|
|
static void
|
|
|
|
_sci_fix_newest(RGBA_Image *im)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Scaleitem *sci;
|
|
|
|
|
|
|
|
im->cache.newest_usage = 0;
|
|
|
|
im->cache.newest_usage_count = 0;
|
|
|
|
EINA_LIST_FOREACH(im->cache.list, l, sci)
|
|
|
|
{
|
|
|
|
if (sci->usage > im->cache.newest_usage)
|
|
|
|
im->cache.newest_usage = sci->usage;
|
|
|
|
if (sci->usage_count > im->cache.newest_usage_count)
|
|
|
|
im->cache.newest_usage_count = sci->usage_count;
|
|
|
|
}
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF("_sci_fix_newest! -> %i", im->cache.newest_usage);
|
2009-03-26 20:50:03 -07:00
|
|
|
}
|
|
|
|
|
2009-03-26 00:14:08 -07:00
|
|
|
static Scaleitem *
|
|
|
|
_sci_find(RGBA_Image *im,
|
2009-10-22 15:22:10 -07:00
|
|
|
RGBA_Draw_Context *dc __UNUSED__, int smooth,
|
2009-03-26 00:14:08 -07:00
|
|
|
int src_region_x, int src_region_y,
|
|
|
|
int src_region_w, int src_region_h,
|
|
|
|
int dst_region_w, int dst_region_h)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Scaleitem *sci;
|
2009-05-13 05:20:14 -07:00
|
|
|
|
2009-03-26 00:14:08 -07:00
|
|
|
EINA_LIST_FOREACH(im->cache.list, l, sci)
|
|
|
|
{
|
|
|
|
if (
|
|
|
|
(sci->src_w == src_region_w) &&
|
|
|
|
(sci->src_h == src_region_h) &&
|
|
|
|
(sci->dst_w == dst_region_w) &&
|
|
|
|
(sci->dst_h == dst_region_h) &&
|
|
|
|
(sci->src_x == src_region_x) &&
|
|
|
|
(sci->src_y == src_region_y) &&
|
|
|
|
(sci->smooth == smooth)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if (im->cache.list != l)
|
|
|
|
{
|
|
|
|
im->cache.list = eina_list_remove_list(im->cache.list, l);
|
|
|
|
im->cache.list = eina_list_prepend(im->cache.list, sci);
|
|
|
|
}
|
|
|
|
return sci;
|
|
|
|
}
|
|
|
|
}
|
2009-05-08 04:26:25 -07:00
|
|
|
if (eina_list_count(im->cache.list) > max_scale_items)
|
2009-03-26 00:14:08 -07:00
|
|
|
{
|
|
|
|
l = eina_list_last(im->cache.list);
|
|
|
|
sci = l->data;
|
|
|
|
im->cache.list = eina_list_remove_list(im->cache.list, l);
|
2009-03-26 20:50:03 -07:00
|
|
|
if ((sci->usage == im->cache.newest_usage) ||
|
|
|
|
(sci->usage_count == im->cache.newest_usage_count))
|
|
|
|
_sci_fix_newest(im);
|
2009-03-26 05:47:44 -07:00
|
|
|
if (sci->im)
|
|
|
|
{
|
|
|
|
evas_common_rgba_image_free(&sci->im->cache_entry);
|
2009-05-06 05:36:06 -07:00
|
|
|
if (!sci->forced_unload)
|
|
|
|
cache_size -= sci->dst_w * sci->dst_h * 4;
|
|
|
|
else
|
|
|
|
cache_size -= sci->size_adjust;
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF(" 1- %i", sci->dst_w * sci->dst_h * 4);
|
2009-03-26 05:47:44 -07:00
|
|
|
cache_list = eina_inlist_remove(cache_list, (Eina_Inlist *)sci);
|
|
|
|
}
|
2009-05-13 05:20:14 -07:00
|
|
|
if (max_scale_items < 1) return NULL;
|
2009-03-26 00:14:08 -07:00
|
|
|
}
|
|
|
|
else
|
2009-03-26 05:47:44 -07:00
|
|
|
{
|
2009-05-13 05:20:14 -07:00
|
|
|
if (max_scale_items < 1) return NULL;
|
|
|
|
|
|
|
|
if (eina_list_count(im->cache.list) > (max_scale_items - 1))
|
|
|
|
return NULL;
|
2009-03-26 05:47:44 -07:00
|
|
|
sci = malloc(sizeof(Scaleitem));
|
|
|
|
memset(sci, 0, sizeof(Eina_Inlist));
|
|
|
|
sci->parent_im = im;
|
|
|
|
}
|
2009-03-26 00:14:08 -07:00
|
|
|
sci->usage = 0;
|
|
|
|
sci->usage_count = 0;
|
|
|
|
sci->populate_me = 0;
|
2009-05-09 20:06:49 -07:00
|
|
|
sci->smooth = smooth;
|
|
|
|
sci->forced_unload = 0;
|
2009-03-26 05:47:44 -07:00
|
|
|
sci->flop = 0;
|
2009-03-26 00:14:08 -07:00
|
|
|
sci->im = NULL;
|
|
|
|
sci->src_x = src_region_x;
|
|
|
|
sci->src_y = src_region_y;
|
|
|
|
sci->src_w = src_region_w;
|
|
|
|
sci->src_h = src_region_h;
|
|
|
|
sci->dst_w = dst_region_w;
|
|
|
|
sci->dst_h = dst_region_h;
|
|
|
|
im->cache.list = eina_list_prepend(im->cache.list, sci);
|
|
|
|
return sci;
|
|
|
|
}
|
2009-03-26 05:47:44 -07:00
|
|
|
|
|
|
|
static void
|
2009-06-17 03:01:52 -07:00
|
|
|
_cache_prune(Scaleitem *notsci, Eina_Bool copies_only)
|
2009-03-26 05:47:44 -07:00
|
|
|
{
|
|
|
|
Scaleitem *sci;
|
|
|
|
while (cache_size > max_cache_size)
|
|
|
|
{
|
|
|
|
if (!cache_list) break;
|
|
|
|
sci = (Scaleitem *)(cache_list);
|
2009-04-09 06:20:00 -07:00
|
|
|
if (copies_only)
|
|
|
|
{
|
|
|
|
while ((sci) && (!sci->parent_im->image.data))
|
2009-05-07 06:29:56 -07:00
|
|
|
sci = (Scaleitem *)(((Eina_Inlist *)sci)->next);
|
2009-04-09 06:20:00 -07:00
|
|
|
if (!sci) return;
|
|
|
|
}
|
2009-03-26 05:47:44 -07:00
|
|
|
if (sci == notsci) return;
|
|
|
|
if (sci->im)
|
|
|
|
{
|
|
|
|
evas_common_rgba_image_free(&sci->im->cache_entry);
|
|
|
|
sci->im = NULL;
|
|
|
|
sci->usage = 0;
|
2009-03-26 20:50:03 -07:00
|
|
|
sci->usage_count = 0;
|
|
|
|
sci->flop += FLOP_ADD;
|
2009-05-06 05:36:06 -07:00
|
|
|
if (!sci->forced_unload)
|
|
|
|
cache_size -= sci->dst_w * sci->dst_h * 4;
|
|
|
|
else
|
|
|
|
cache_size -= sci->size_adjust;
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF(" 2- %i", sci->dst_w * sci->dst_h * 4);
|
2009-03-26 05:47:44 -07:00
|
|
|
cache_list = eina_inlist_remove(cache_list, (Eina_Inlist *)sci);
|
|
|
|
memset(sci, 0, sizeof(Eina_Inlist));
|
|
|
|
}
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF("FLUSH %i > %i", cache_size, max_cache_size);
|
2009-03-26 05:47:44 -07:00
|
|
|
}
|
|
|
|
}
|
2009-03-26 00:14:08 -07:00
|
|
|
#endif
|
|
|
|
|
2009-04-09 06:20:00 -07:00
|
|
|
EAPI void
|
|
|
|
evas_common_rgba_image_scalecache_size_set(int size)
|
|
|
|
{
|
2009-05-09 20:06:49 -07:00
|
|
|
#ifdef SCALECACHE
|
2009-04-09 06:20:00 -07:00
|
|
|
LKL(cache_lock);
|
|
|
|
if (size != max_cache_size)
|
|
|
|
{
|
|
|
|
max_cache_size = size;
|
|
|
|
_cache_prune(NULL, 1);
|
|
|
|
}
|
|
|
|
LKU(cache_lock);
|
2009-05-09 20:06:49 -07:00
|
|
|
#endif
|
2009-04-09 06:20:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
evas_common_rgba_image_scalecache_size_get(void)
|
|
|
|
{
|
2009-05-09 20:06:49 -07:00
|
|
|
#ifdef SCALECACHE
|
2009-04-09 06:20:00 -07:00
|
|
|
int t;
|
|
|
|
LKL(cache_lock);
|
|
|
|
t = max_cache_size;
|
|
|
|
LKU(cache_lock);
|
|
|
|
return t;
|
2009-05-09 20:06:49 -07:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
2009-04-09 06:20:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
evas_common_rgba_image_scalecache_flush(void)
|
|
|
|
{
|
2009-05-09 20:06:49 -07:00
|
|
|
#ifdef SCALECACHE
|
2009-04-09 06:20:00 -07:00
|
|
|
int t;
|
|
|
|
LKL(cache_lock);
|
|
|
|
t = max_cache_size;
|
|
|
|
max_cache_size = 0;
|
|
|
|
_cache_prune(NULL, 1);
|
|
|
|
max_cache_size = t;
|
|
|
|
LKU(cache_lock);
|
2009-05-09 20:06:49 -07:00
|
|
|
#endif
|
2009-04-09 06:20:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-26 00:14:08 -07:00
|
|
|
EAPI void
|
2009-10-22 15:22:10 -07:00
|
|
|
evas_common_rgba_image_scalecache_prepare(Image_Entry *ie, RGBA_Image *dst __UNUSED__,
|
2009-03-26 00:14:08 -07:00
|
|
|
RGBA_Draw_Context *dc, int smooth,
|
|
|
|
int src_region_x, int src_region_y,
|
|
|
|
int src_region_w, int src_region_h,
|
2009-10-22 15:22:10 -07:00
|
|
|
int dst_region_x __UNUSED__, int dst_region_y __UNUSED__,
|
2009-03-26 00:14:08 -07:00
|
|
|
int dst_region_w, int dst_region_h)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
Scaleitem *sci;
|
2009-03-26 23:06:45 -07:00
|
|
|
if (!im->image.data) return;
|
2009-03-26 05:47:44 -07:00
|
|
|
if ((dst_region_w == 0) || (dst_region_h == 0) ||
|
|
|
|
(src_region_w == 0) || (src_region_h == 0)) return;
|
2009-03-26 17:30:41 -07:00
|
|
|
LKL(im->cache.lock);
|
|
|
|
use_counter++;
|
2009-03-26 00:14:08 -07:00
|
|
|
if ((src_region_w == dst_region_w) && (src_region_h == dst_region_h))
|
|
|
|
{
|
2009-03-27 06:46:53 -07:00
|
|
|
// 1:1 scale.
|
|
|
|
im->cache.orig_usage++;
|
|
|
|
im->cache.usage_count = use_counter;
|
|
|
|
LKU(im->cache.lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ((!im->cache_entry.flags.alpha) && (!smooth))
|
|
|
|
{
|
|
|
|
// solid nearest scaling - it's actually the same speed cached or not,
|
|
|
|
// or in some cases faster not cached
|
2009-03-26 00:14:08 -07:00
|
|
|
im->cache.orig_usage++;
|
|
|
|
im->cache.usage_count = use_counter;
|
|
|
|
LKU(im->cache.lock);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-09 06:20:00 -07:00
|
|
|
LKL(cache_lock);
|
2009-03-26 00:14:08 -07:00
|
|
|
sci = _sci_find(im, dc, smooth,
|
|
|
|
src_region_x, src_region_y, src_region_w, src_region_h,
|
|
|
|
dst_region_w, dst_region_h);
|
2009-05-13 05:20:14 -07:00
|
|
|
if (!sci)
|
|
|
|
{
|
|
|
|
LKU(cache_lock);
|
|
|
|
LKU(im->cache.lock);
|
|
|
|
return;
|
|
|
|
}
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF("%10i | %4i %4i %4ix%4i -> %4i %4i %4ix%4i | %i",
|
2009-03-26 00:14:08 -07:00
|
|
|
// (int)use_counter,
|
|
|
|
// src_region_x, src_region_y, src_region_w, src_region_h,
|
|
|
|
// dst_region_x, dst_region_y, dst_region_w, dst_region_h,
|
|
|
|
// smooth);
|
2009-05-08 04:26:25 -07:00
|
|
|
if ((sci->usage >= min_scale_uses)
|
2009-05-07 06:29:56 -07:00
|
|
|
&& (ie->scale_hint != EVAS_IMAGE_SCALE_HINT_DYNAMIC)
|
2009-03-26 20:50:03 -07:00
|
|
|
// && (sci->usage_count > (use_counter - MIN_SCALE_AGE_GAP))
|
|
|
|
)
|
2009-03-26 00:14:08 -07:00
|
|
|
{
|
|
|
|
if (!sci->im)
|
|
|
|
{
|
2009-05-08 04:26:25 -07:00
|
|
|
if ((sci->dst_w < max_dimension) &&
|
|
|
|
(sci->dst_h < max_dimension))
|
2009-03-26 05:47:44 -07:00
|
|
|
{
|
2009-05-08 04:26:25 -07:00
|
|
|
if (sci->flop <= max_flop_count)
|
2009-03-26 05:47:44 -07:00
|
|
|
{
|
|
|
|
sci->populate_me = 1;
|
|
|
|
im->cache.populate_count++;
|
|
|
|
}
|
|
|
|
}
|
2009-03-26 00:14:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sci->usage++;
|
|
|
|
sci->usage_count = use_counter;
|
2009-04-09 06:20:00 -07:00
|
|
|
LKU(cache_lock);
|
2009-03-26 20:50:03 -07:00
|
|
|
if (sci->usage > im->cache.newest_usage)
|
|
|
|
im->cache.newest_usage = sci->usage;
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF("newset? %p %i > %i", im,
|
2009-03-26 20:50:03 -07:00
|
|
|
// (int)sci->usage,
|
|
|
|
// (int)im->cache.newest_usage);
|
|
|
|
if (sci->usage_count > im->cache.newest_usage_count)
|
|
|
|
im->cache.newest_usage_count = sci->usage_count;
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF(" -------------- used %8i#, %8i@", (int)sci->usage, (int)sci->usage_count);
|
2009-03-26 00:14:08 -07:00
|
|
|
LKU(im->cache.lock);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SCALECACHE
|
2009-03-27 19:50:19 -07:00
|
|
|
//static int pops = 0;
|
|
|
|
//static int hits = 0;
|
|
|
|
//static int misses = 0;
|
|
|
|
//static int noscales = 0;
|
2009-03-26 00:14:08 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
evas_common_rgba_image_scalecache_do(Image_Entry *ie, RGBA_Image *dst,
|
|
|
|
RGBA_Draw_Context *dc, int smooth,
|
|
|
|
int src_region_x, int src_region_y,
|
|
|
|
int src_region_w, int src_region_h,
|
|
|
|
int dst_region_x, int dst_region_y,
|
|
|
|
int dst_region_w, int dst_region_h)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
Scaleitem *sci;
|
2009-03-26 05:47:44 -07:00
|
|
|
int didpop = 0;
|
2009-05-06 05:36:06 -07:00
|
|
|
int dounload = 0;
|
2009-03-26 05:47:44 -07:00
|
|
|
/*
|
2009-03-26 00:14:08 -07:00
|
|
|
static int i = 0;
|
|
|
|
|
|
|
|
i++;
|
|
|
|
if (i > 2000)
|
|
|
|
{
|
2009-10-22 08:22:22 -07:00
|
|
|
INF("p: %6i, h: %6i, m: %6i, n: %6i",
|
2009-03-26 00:14:08 -07:00
|
|
|
pops, hits, misses, noscales);
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
*/
|
2009-03-26 05:47:44 -07:00
|
|
|
if ((dst_region_w == 0) || (dst_region_h == 0) ||
|
|
|
|
(src_region_w == 0) || (src_region_h == 0)) return;
|
2009-03-26 20:50:03 -07:00
|
|
|
LKL(im->cache.lock);
|
2009-03-26 00:14:08 -07:00
|
|
|
if ((src_region_w == dst_region_w) && (src_region_h == dst_region_h))
|
|
|
|
{
|
2009-03-26 23:06:45 -07:00
|
|
|
if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
|
|
|
|
evas_cache_image_load_data(&im->cache_entry);
|
|
|
|
evas_common_image_colorspace_normalize(im);
|
2009-03-27 19:50:19 -07:00
|
|
|
// noscales++;
|
2009-03-26 23:06:45 -07:00
|
|
|
if (im->image.data)
|
|
|
|
{
|
|
|
|
if (smooth)
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_smooth(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
else
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_sample(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
}
|
2009-03-26 20:50:03 -07:00
|
|
|
LKU(im->cache.lock);
|
2009-03-26 00:14:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-04-09 06:20:00 -07:00
|
|
|
LKL(cache_lock);
|
2009-03-26 00:14:08 -07:00
|
|
|
sci = _sci_find(im, dc, smooth,
|
|
|
|
src_region_x, src_region_y, src_region_w, src_region_h,
|
|
|
|
dst_region_w, dst_region_h);
|
2009-04-09 06:20:00 -07:00
|
|
|
LKU(cache_lock);
|
2009-03-26 17:30:41 -07:00
|
|
|
if (!sci)
|
|
|
|
{
|
2009-03-27 07:11:27 -07:00
|
|
|
if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
|
|
|
|
evas_cache_image_load_data(&im->cache_entry);
|
|
|
|
evas_common_image_colorspace_normalize(im);
|
2009-03-27 19:50:19 -07:00
|
|
|
// misses++;
|
2009-03-26 17:30:41 -07:00
|
|
|
LKU(im->cache.lock);
|
2009-03-27 07:11:27 -07:00
|
|
|
if (im->image.data)
|
|
|
|
{
|
|
|
|
if (smooth)
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_smooth(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
else
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_sample(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
}
|
2009-03-26 17:30:41 -07:00
|
|
|
return;
|
|
|
|
}
|
2009-05-06 05:36:06 -07:00
|
|
|
if (sci->populate_me)
|
|
|
|
{
|
|
|
|
int size, osize, used;
|
|
|
|
|
|
|
|
size = dst_region_w * dst_region_h;
|
2009-05-07 06:29:56 -07:00
|
|
|
if (((((dst_region_w > 640) || (dst_region_h > 640)) &&
|
|
|
|
(size > (480 * 480))) ||
|
|
|
|
(ie->scale_hint == EVAS_IMAGE_SCALE_HINT_STATIC)) &&
|
|
|
|
(ie->scale_hint != EVAS_IMAGE_SCALE_HINT_DYNAMIC))
|
2009-05-06 05:36:06 -07:00
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
Scaleitem *sci2;
|
|
|
|
|
|
|
|
dounload = 1;
|
|
|
|
osize = sci->parent_im->cache_entry.w * sci->parent_im->cache_entry.h;
|
|
|
|
used = 0;
|
|
|
|
EINA_LIST_FOREACH(im->cache.list, l, sci2)
|
|
|
|
{
|
|
|
|
if (sci2->im) used += sci2->dst_w * sci2->dst_h;
|
|
|
|
}
|
|
|
|
if ((size < osize) && (used == 0))
|
|
|
|
sci->size_adjust = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osize -= used;
|
|
|
|
if (osize < 0) osize = 0;
|
|
|
|
size -= osize;
|
|
|
|
sci->size_adjust = size * 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
size *= sizeof(DATA32);
|
|
|
|
if ((cache_size + size) > max_cache_size)
|
|
|
|
{
|
|
|
|
sci->populate_me = 0;
|
|
|
|
im->cache.populate_count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-03-26 00:14:08 -07:00
|
|
|
if (sci->populate_me)
|
|
|
|
{
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF("##! populate!");
|
2009-03-26 00:14:08 -07:00
|
|
|
sci->im = evas_common_image_new
|
2009-03-27 06:46:53 -07:00
|
|
|
(dst_region_w, dst_region_h, im->cache_entry.flags.alpha);
|
2009-03-26 00:14:08 -07:00
|
|
|
if (sci->im)
|
|
|
|
{
|
|
|
|
static RGBA_Draw_Context *ct = NULL;
|
|
|
|
|
2009-04-09 06:20:00 -07:00
|
|
|
LKL(cache_lock);
|
2009-03-26 20:50:03 -07:00
|
|
|
im->cache.orig_usage++;
|
|
|
|
im->cache.usage_count = use_counter;
|
2009-03-26 05:47:44 -07:00
|
|
|
im->cache.populate_count--;
|
2009-03-27 19:50:19 -07:00
|
|
|
// pops++;
|
2009-03-26 00:14:08 -07:00
|
|
|
if (!ct)
|
|
|
|
{
|
2009-10-31 08:18:19 -07:00
|
|
|
// FIXME: static ct - never can free on shutdown? not a leak
|
2009-04-19 13:40:41 -07:00
|
|
|
// or real harm - just annoying valgrind bitch
|
2009-03-26 00:14:08 -07:00
|
|
|
ct = evas_common_draw_context_new();
|
|
|
|
evas_common_draw_context_set_render_op(ct, _EVAS_RENDER_COPY);
|
|
|
|
}
|
2009-03-26 20:50:03 -07:00
|
|
|
if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
|
|
|
|
evas_cache_image_load_data(&im->cache_entry);
|
|
|
|
evas_common_image_colorspace_normalize(im);
|
2009-03-26 23:06:45 -07:00
|
|
|
if (im->image.data)
|
|
|
|
{
|
|
|
|
if (smooth)
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_smooth
|
|
|
|
(im, sci->im, ct,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
0, 0,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
else
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_sample
|
|
|
|
(im, sci->im, ct,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
0, 0,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
sci->populate_me = 0;
|
2009-04-19 13:40:41 -07:00
|
|
|
#if 0 // visual debug of cached images
|
|
|
|
{
|
|
|
|
int xx, yy;
|
|
|
|
DATA32 *pp;
|
|
|
|
|
|
|
|
pp = sci->im->image.data;
|
|
|
|
for (yy = 0; yy < dst_region_h; yy++)
|
|
|
|
{
|
|
|
|
|
|
|
|
for (xx = 0; xx < dst_region_w; xx++)
|
|
|
|
{
|
|
|
|
if (yy & 0x1)
|
|
|
|
{
|
2009-05-06 05:36:06 -07:00
|
|
|
if (xx & 0x1) *pp = 0x882288ff;
|
2009-04-19 13:40:41 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-05-06 05:36:06 -07:00
|
|
|
if (!(xx & 0x1)) *pp = 0x882288ff;
|
2009-04-19 13:40:41 -07:00
|
|
|
}
|
|
|
|
pp++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2009-03-26 23:06:45 -07:00
|
|
|
}
|
2009-05-06 05:36:06 -07:00
|
|
|
if (dounload)
|
|
|
|
{
|
|
|
|
sci->forced_unload = 1;
|
|
|
|
cache_size += sci->size_adjust;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cache_size += sci->dst_w * sci->dst_h * 4;
|
|
|
|
}
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF(" + %i @ flop: %i (%ix%i)",
|
2009-03-26 05:47:44 -07:00
|
|
|
// sci->dst_w * sci->dst_h * 4, sci->flop,
|
|
|
|
// sci->dst_w, sci->dst_h);
|
|
|
|
cache_list = eina_inlist_append(cache_list, (Eina_Inlist *)sci);
|
2009-04-09 06:20:00 -07:00
|
|
|
_cache_prune(sci, 0);
|
|
|
|
LKU(cache_lock);
|
2009-03-26 05:47:44 -07:00
|
|
|
didpop = 1;
|
2009-03-26 00:14:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sci->im)
|
|
|
|
{
|
2009-03-26 05:47:44 -07:00
|
|
|
if (!didpop)
|
|
|
|
{
|
2010-03-24 04:06:02 -07:00
|
|
|
LKL(cache_lock);
|
2009-03-26 05:47:44 -07:00
|
|
|
cache_list = eina_inlist_remove(cache_list, (Eina_Inlist *)sci);
|
|
|
|
cache_list = eina_inlist_append(cache_list, (Eina_Inlist *)sci);
|
2010-03-24 04:06:02 -07:00
|
|
|
LKU(cache_lock);
|
2009-03-26 05:47:44 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-26 20:50:03 -07:00
|
|
|
if (sci->flop > 0) sci->flop -= FLOP_DEL;
|
2009-03-26 05:47:44 -07:00
|
|
|
}
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF("use cached!");
|
2009-03-26 00:14:08 -07:00
|
|
|
evas_common_scale_rgba_in_to_out_clip_sample
|
|
|
|
(sci->im, dst, dc,
|
|
|
|
0, 0,
|
|
|
|
dst_region_w, dst_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
2009-03-27 19:50:19 -07:00
|
|
|
// hits++;
|
2009-10-22 08:22:22 -07:00
|
|
|
// INF("check %p %i < %i",
|
2009-03-26 20:50:03 -07:00
|
|
|
// im,
|
|
|
|
// (int)im->cache.orig_usage,
|
|
|
|
// (int)im->cache.newest_usage);
|
2009-05-06 05:36:06 -07:00
|
|
|
if ((dounload) ||
|
|
|
|
((im->cache_entry.flags.loaded) &&
|
|
|
|
((!im->cs.no_free)
|
|
|
|
#ifdef EVAS_CSERVE
|
|
|
|
|| (ie->data1)
|
|
|
|
#endif
|
|
|
|
) &&
|
|
|
|
(im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)))
|
2009-03-26 20:50:03 -07:00
|
|
|
{
|
2009-05-06 05:36:06 -07:00
|
|
|
if ((dounload) || (im->cache.orig_usage <
|
|
|
|
(im->cache.newest_usage / 20)))
|
|
|
|
{
|
|
|
|
evas_common_rgba_image_unload(&im->cache_entry);
|
|
|
|
}
|
2009-03-26 20:50:03 -07:00
|
|
|
}
|
2009-03-26 00:14:08 -07:00
|
|
|
LKU(im->cache.lock);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-03-26 23:06:45 -07:00
|
|
|
if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
|
|
|
|
evas_cache_image_load_data(&im->cache_entry);
|
|
|
|
evas_common_image_colorspace_normalize(im);
|
2009-03-27 19:50:19 -07:00
|
|
|
// misses++;
|
2009-03-26 00:14:08 -07:00
|
|
|
LKU(im->cache.lock);
|
2009-03-26 23:06:45 -07:00
|
|
|
if (im->image.data)
|
|
|
|
{
|
|
|
|
if (smooth)
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_smooth(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
else
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_sample(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
2009-03-27 00:22:46 -07:00
|
|
|
if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)
|
|
|
|
evas_cache_image_load_data(&im->cache_entry);
|
|
|
|
evas_common_image_colorspace_normalize(im);
|
2009-03-26 23:06:45 -07:00
|
|
|
if (im->image.data)
|
|
|
|
{
|
2009-03-26 00:14:08 -07:00
|
|
|
if (smooth)
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_smooth(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
else
|
|
|
|
evas_common_scale_rgba_in_to_out_clip_sample(im, dst, dc,
|
|
|
|
src_region_x, src_region_y,
|
|
|
|
src_region_w, src_region_h,
|
|
|
|
dst_region_x, dst_region_y,
|
|
|
|
dst_region_w, dst_region_h);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-03-26 20:50:03 -07:00
|
|
|
#if 0
|
2009-03-26 05:47:44 -07:00
|
|
|
// to be done
|
2009-03-26 00:14:08 -07:00
|
|
|
void
|
|
|
|
evas_common_rgba_image_scalecache_XXX(Image_Entry *ie)
|
|
|
|
{
|
|
|
|
#ifdef SCALECACHE
|
|
|
|
RGBA_Image *im = (RGBA_Image *)ie;
|
|
|
|
LKL(im->cache.lock);
|
|
|
|
// FIXME: XXX
|
|
|
|
LKU(im->cache.lock);
|
|
|
|
#endif
|
|
|
|
}
|
2009-03-26 20:50:03 -07:00
|
|
|
#endif
|