fix the cache code - it was basically broken and wouldnt free things from

cache. it also didnt account cache USAGE (cache is ref == 0 count images
speculatively hanging around in case theyare needed).


SVN revision: 31227
This commit is contained in:
Carsten Haitzler 2007-08-08 23:41:31 +00:00
parent 4a4a0b0f4c
commit 287d8779fb
4 changed files with 28 additions and 27 deletions

View File

@ -164,6 +164,7 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
cache->lru = evas_object_list_remove(cache->lru, im);
cache->inactiv = evas_hash_del(cache->inactiv, hkey, im);
cache->activ = evas_hash_add(cache->activ, hkey, im);
cache->usage -= cache->func.mem_size_get(im);
goto on_ok;
}
@ -199,11 +200,10 @@ evas_cache_image_request(Evas_Cache_Image *cache, const char *file, const char *
im->cache_key = strdup(hkey);
im->cache = cache;
cache->usage += strlen(im->cache_key) + 1 + cache->func.mem_size_get(im);
on_ok:
*error = 0;
im->references++;
// printf("IM++ %s, cache = %i\n", im->cache_key, cache->usage);
return im;
}
@ -219,12 +219,11 @@ evas_cache_image_drop(RGBA_Image *im)
im->references--;
cache = im->cache;
// if (im->cache_key) printf("DROP %s -> ref = %i\n", im->cache_key, im->references);
if ((im->flags & RGBA_IMAGE_IS_DIRTY) == RGBA_IMAGE_IS_DIRTY)
{
int size;
size = cache->func.mem_size_get(im);
cache->usage -= size;
cache->usage = cache->func.mem_size_get(im);
// if (im->cache_key) printf("IM-- %s, cache = %i\n", im->cache_key, cache->usage);
cache->dirty = evas_object_list_remove(cache->dirty, im);
if (cache->func.debug)
cache->func.debug("drop", im);
@ -243,7 +242,9 @@ evas_cache_image_drop(RGBA_Image *im)
cache->inactiv = evas_hash_add(cache->inactiv, hkey, im);
cache->lru = evas_object_list_prepend(cache->lru, im);
/* FIXME: Enforce cache limit. */
cache->usage += cache->func.mem_size_get(im);
// printf("FLUSH!\n");
evas_cache_image_flush(cache);
}
}
@ -265,8 +266,6 @@ evas_cache_image_dirty(RGBA_Image *im, int x, int y, int w, int h)
hkey = im->cache_key;
cache->activ = evas_hash_del(cache->activ, hkey, im);
cache->usage -= strlen(hkey) + 1;
free(hkey);
im_dirty = im;
@ -293,7 +292,7 @@ evas_cache_image_dirty(RGBA_Image *im, int x, int y, int w, int h)
im_dirty->cache = cache;
im_dirty->references = 1;
cache->usage += cache->func.mem_size_get(im_dirty);
// cache->usage += cache->func.mem_size_get(im_dirty);
evas_cache_image_drop(im);
}
@ -335,7 +334,6 @@ evas_cache_image_alone(RGBA_Image *im)
hkey = im->cache_key;
cache->activ = evas_hash_del(cache->activ, hkey, im);
cache->usage -= strlen(hkey) + 1;
free(hkey);
im_dirty->cache_key = NULL;
@ -399,7 +397,8 @@ evas_cache_image_copied_data(Evas_Cache_Image *cache, int w, int h, DATA32 *imag
assert(cache);
if (cspace != EVAS_COLORSPACE_ARGB8888)
if ((cspace == EVAS_COLORSPACE_YCBCR422P601_PL) ||
(cspace == EVAS_COLORSPACE_YCBCR422P709_PL))
w &= ~0x1;
im = evas_common_image_create(w, h);
@ -476,7 +475,7 @@ evas_cache_image_size_set(RGBA_Image *im, int w, int h)
new->cache_key = NULL;
new->references = 1;
cache->usage += cache->func.mem_size_get(new);
// cache->usage += cache->func.mem_size_get(new);
if ((im->flags & RGBA_IMAGE_IS_DIRTY) == RGBA_IMAGE_IS_DIRTY
|| im->references > 1)
@ -492,7 +491,6 @@ evas_cache_image_size_set(RGBA_Image *im, int w, int h)
new->cache_key = cache_key;
cache->activ = evas_hash_add(cache->activ, cache_key, new);
cache->usage += strlen(new->cache_key) + 1;
}
evas_cache_image_drop(im);
@ -521,9 +519,9 @@ evas_cache_image_load_data(RGBA_Image *im)
if (cache->func.debug)
cache->func.debug("load", im);
size = cache->func.mem_size_get(im);
// size = cache->func.mem_size_get(im);
cache->func.load(im);
cache->usage += cache->func.mem_size_get(im) - size;
// cache->usage += cache->func.mem_size_get(im) - size;
im->flags |= RGBA_IMAGE_LOADED;
@ -538,15 +536,17 @@ evas_cache_image_flush(Evas_Cache_Image *cache)
if (cache->limit == -1)
return -1;
while (cache->lru && cache->limit < cache->usage)
// printf("cache->limit = %i\n", cache->limit);
// printf("cache->usage = %i\n", cache->usage);
while ((cache->lru) && (cache->limit < cache->usage))
{
RGBA_Image* im;
im = (RGBA_Image*) cache->lru->last;
// printf("IM-- [flush] %s, cache = %i\n", im->cache_key, cache->usage);
cache->lru = evas_object_list_remove(cache->lru, im);
cache->inactiv = evas_hash_del(cache->inactiv, im->cache_key, im);
cache->usage -= strlen(im->cache_key) + 1;
cache->usage -= cache->func.mem_size_get(im);
free(im->cache_key);

View File

@ -63,14 +63,14 @@ evas_common_array_hash_add(Evas_Array_Hash *hash, int key, int data)
if (!el)
{
el = malloc(sizeof(Evas_Array_Hash_El));
el->data_max = 1 << 5;
el->data_max = 4;
el->data = malloc(sizeof(int) * el->data_max);
el->data_count = 0;
hash->buckets[hash_val] = el;
}
else if (el->data_count == el->data_max)
{
el->data_max = el->data_max << 1;
el->data_max = el->data_max *= 2;
el->data = realloc(el->data, sizeof(int) * el->data_max);
}

View File

@ -84,7 +84,7 @@ evas_common_font_glyph_search(RGBA_Font *fn, RGBA_Font_Int **fi_ret, int gl)
{
if (evas_common_font_source_load_complete(fi->src))
return 0;
#if 0 /* FIXME: disable this. this can eat a LOT of memory and in my tests with expedite at any rate shows no visible improvements */
index = FT_Get_Char_Index(fi->src->ft.face, gl);
if (index == 0)
{
@ -93,11 +93,11 @@ evas_common_font_glyph_search(RGBA_Font *fn, RGBA_Font_Int **fi_ret, int gl)
FT_UInt gindex;
fi->src->charmap = evas_common_array_hash_new();
charcode = FT_Get_First_Char(fi->src->ft.face, &gindex );
while ( gindex != 0 )
charcode = FT_Get_First_Char(fi->src->ft.face, &gindex);
while (gindex != 0)
{
evas_common_array_hash_add(fi->src->charmap, charcode, gindex);
charcode = FT_Get_Next_Char(fi->src->ft.face, charcode, &gindex );
charcode = FT_Get_Next_Char(fi->src->ft.face, charcode, &gindex);
}
/* Free face */
@ -111,6 +111,7 @@ evas_common_font_glyph_search(RGBA_Font *fn, RGBA_Font_Int **fi_ret, int gl)
*fi_ret = fi;
return index;
}
#endif
}
else /* Charmap not loaded, FS loaded */
{

View File

@ -380,10 +380,10 @@ evas_common_image_ram_usage(RGBA_Image *im)
{
int ram = 0;
ram += sizeof(struct _RGBA_Image);
if (im->info.file) ram += strlen(im->info.file);
// ram += sizeof(struct _RGBA_Image);
// if (im->info.file) ram += strlen(im->info.file);
// if (im->info.real_file) ram += strlen(im->info.real_file);
if (im->info.key) ram += strlen(im->info.key);
// if (im->info.key) ram += strlen(im->info.key);
// if (im->info.comment) ram += strlen(im->info.comment);
if ((im->image) && (im->image->data) && (!im->image->no_free))
ram += im->image->w * im->image->h * sizeof(DATA32);