From 4c9a0ee04e12794c0b900bab5a474d97b29e70ea Mon Sep 17 00:00:00 2001 From: raster Date: Fri, 27 Mar 2009 06:06:45 +0000 Subject: [PATCH] also be able to free orig data now (and reload) git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/evas@39743 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/engines/common/evas_image.h | 1 + src/lib/engines/common/evas_image_load.c | 4 +- src/lib/engines/common/evas_image_main.c | 32 ++++++ src/lib/engines/common/evas_image_scalecache.c | 109 ++++++++++++--------- src/modules/engines/software_generic/evas_engine.c | 6 +- 5 files changed, 103 insertions(+), 49 deletions(-) diff --git a/src/lib/engines/common/evas_image.h b/src/lib/engines/common/evas_image.h index 1881f15..4addd77 100644 --- a/src/lib/engines/common/evas_image.h +++ b/src/lib/engines/common/evas_image.h @@ -6,6 +6,7 @@ EAPI void evas_common_image_init (void); EAPI void evas_common_image_shutdown (void); EAPI void evas_common_rgba_image_free (Image_Entry *ie); +EAPI void evas_common_rgba_image_unload (Image_Entry *ie); EAPI void evas_common_image_colorspace_normalize (RGBA_Image *im); EAPI void evas_common_image_colorspace_dirty (RGBA_Image *im); EAPI void evas_common_image_cache_free (void); /*2*/ diff --git a/src/lib/engines/common/evas_image_load.c b/src/lib/engines/common/evas_image_load.c index 01aae46..9a6a86b 100644 --- a/src/lib/engines/common/evas_image_load.c +++ b/src/lib/engines/common/evas_image_load.c @@ -109,8 +109,8 @@ evas_common_load_rgba_image_data_from_file(Image_Entry *ie) if (!evas_image_load_func->file_data(ie, ie->file, ie->key)) return -1; - evas_module_unref((Evas_Module*) ie->info.module); - ie->info.module = NULL; +// evas_module_unref((Evas_Module*) ie->info.module); +// ie->info.module = NULL; return 0; } diff --git a/src/lib/engines/common/evas_image_main.c b/src/lib/engines/common/evas_image_main.c index a07f7d7..1c0fb4f 100644 --- a/src/lib/engines/common/evas_image_main.c +++ b/src/lib/engines/common/evas_image_main.c @@ -162,6 +162,38 @@ evas_common_rgba_image_free(Image_Entry *ie) _evas_common_rgba_image_delete(ie); } +EAPI void +evas_common_rgba_image_unload(Image_Entry *ie) +{ + RGBA_Image *im = (RGBA_Image *) ie; + + evas_cache_image_preload_cancel(ie, NULL); + + if (!ie->flags.loaded) return; + if (!ie->info.module) return; + if (!ie->file) return; + ie->flags.loaded = 0; + + if ((im->cs.data) && (im->image.data)) + { + if (im->cs.data != im->image.data) + { + if (!im->cs.no_free) free(im->cs.data); + } + } + else if (im->cs.data) + { + if (!im->cs.no_free) free(im->cs.data); + } + im->cs.data = NULL; + + if (im->image.data && !im->image.no_free) + free(im->image.data); + im->image.data = NULL; + ie->allocated.w = 0; + ie->allocated.h = 0; +} + static int _evas_common_rgba_image_surface_alloc(Image_Entry *ie, int w, int h) { diff --git a/src/lib/engines/common/evas_image_scalecache.c b/src/lib/engines/common/evas_image_scalecache.c index eeea79a..f90e25f 100644 --- a/src/lib/engines/common/evas_image_scalecache.c +++ b/src/lib/engines/common/evas_image_scalecache.c @@ -264,6 +264,7 @@ evas_common_rgba_image_scalecache_prepare(Image_Entry *ie, RGBA_Image *dst, #ifdef SCALECACHE RGBA_Image *im = (RGBA_Image *)ie; Scaleitem *sci; + if (!im->image.data) return; if ((dst_region_w == 0) || (dst_region_h == 0) || (src_region_w == 0) || (src_region_h == 0)) return; LKL(im->cache.lock); @@ -350,19 +351,25 @@ evas_common_rgba_image_scalecache_do(Image_Entry *ie, RGBA_Image *dst, LKL(im->cache.lock); if ((src_region_w == dst_region_w) && (src_region_h == dst_region_h)) { + if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888) + evas_cache_image_load_data(&im->cache_entry); + evas_common_image_colorspace_normalize(im); noscales++; - 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); + 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); + } LKU(im->cache.lock); return; } @@ -395,21 +402,24 @@ evas_common_rgba_image_scalecache_do(Image_Entry *ie, RGBA_Image *dst, if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888) evas_cache_image_load_data(&im->cache_entry); evas_common_image_colorspace_normalize(im); - 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; + 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; + } cache_size += sci->dst_w * sci->dst_h * 4; // printf(" + %i @ flop: %i (%ix%i)\n", // sci->dst_w * sci->dst_h * 4, sci->flop, @@ -442,17 +452,42 @@ evas_common_rgba_image_scalecache_do(Image_Entry *ie, RGBA_Image *dst, // im, // (int)im->cache.orig_usage, // (int)im->cache.newest_usage); - if (im->cache.orig_usage < - (im->cache.newest_usage / 20)) + if ((im->cache_entry.flags.loaded) && (!im->cs.no_free) && + (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888)) { -// printf("nuke orig %s\n", im->cache_entry.file); + if (im->cache.orig_usage < + (im->cache.newest_usage / 20)) + evas_common_rgba_image_unload(&im->cache_entry); } LKU(im->cache.lock); } else { + if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888) + evas_cache_image_load_data(&im->cache_entry); + evas_common_image_colorspace_normalize(im); misses++; LKU(im->cache.lock); + 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; + if (im->image.data) + { if (smooth) evas_common_scale_rgba_in_to_out_clip_smooth(im, dst, dc, src_region_x, src_region_y, @@ -466,20 +501,6 @@ evas_common_rgba_image_scalecache_do(Image_Entry *ie, RGBA_Image *dst, dst_region_x, dst_region_y, dst_region_w, dst_region_h); } -#else - RGBA_Image *im = (RGBA_Image *)ie; - 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 } diff --git a/src/modules/engines/software_generic/evas_engine.c b/src/modules/engines/software_generic/evas_engine.c index df0da5f..75d97b1 100644 --- a/src/modules/engines/software_generic/evas_engine.c +++ b/src/modules/engines/software_generic/evas_engine.c @@ -754,9 +754,9 @@ eng_image_draw(void *data __UNUSED__, void *context, void *surface, void *image, else #endif { - if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888) - evas_cache_image_load_data(&im->cache_entry); - evas_common_image_colorspace_normalize(im); +// if (im->cache_entry.space == EVAS_COLORSPACE_ARGB8888) +// evas_cache_image_load_data(&im->cache_entry); +// evas_common_image_colorspace_normalize(im); evas_common_rgba_image_scalecache_prepare(im, surface, context, smooth, src_x, src_y, src_w, src_h, dst_x, dst_y, dst_w, dst_h); -- 2.7.4