Enlightenment CVS committal Author : barbieri Project : e17 Module : libs/evas
Dir : e17/libs/evas/src/modules/engines/software_16 Modified Files: Makefile.am evas_engine.c evas_soft16.h evas_soft16_main.c Added Files: evas_soft16_image_cache.c Log Message: Add software_16 cache. =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_16/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- Makefile.am 25 Oct 2007 16:17:18 -0000 1.7 +++ Makefile.am 26 Oct 2007 18:53:39 -0000 1.8 @@ -14,6 +14,7 @@ evas_soft16.h \ evas_soft16_dither_mask.c \ evas_soft16_main.c \ +evas_soft16_image_cache.c \ evas_soft16_image_unscaled.c \ evas_soft16_image_scaled_sampled.c \ evas_soft16_font.c \ @@ -32,6 +33,7 @@ evas_soft16.h \ evas_soft16_dither_mask.c \ evas_soft16_main.c \ +evas_soft16_image_cache.c \ evas_soft16_image_unscaled.c \ evas_soft16_image_scaled_sampled.c \ evas_soft16_font.c \ =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_16/evas_engine.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- evas_engine.c 25 Oct 2007 22:09:49 -0000 1.10 +++ evas_engine.c 26 Oct 2007 18:53:39 -0000 1.11 @@ -491,16 +491,23 @@ { Soft16_Image *im_new; - im_new = soft16_image_new(im->w, im->h, im->stride, im->have_alpha, im->pixels, 1); - if (!im_new) return im; + im_new = soft16_image_new(im->w, im->h, im->stride, im->have_alpha, + im->pixels, 1); + if (!im_new) + { + if (image_data) *image_data = NULL; + return im; + } soft16_image_free(im); im = im_new; } + if (im->cache_key) + soft16_image_cache_del(im); } if (image_data) *image_data = (DATA32 *) im->pixels; - return image; + return im; } static void * @@ -532,23 +539,19 @@ static void eng_image_cache_flush(void *data) { - int tmp_size; - - tmp_size = evas_common_image_get_cache(); - evas_common_image_set_cache(0); - evas_common_image_set_cache(tmp_size); + soft16_image_cache_flush(); } static void eng_image_cache_set(void *data, int bytes) { - evas_common_image_set_cache(bytes); + soft16_image_cache_size_set(bytes); } static int eng_image_cache_get(void *data) { - return evas_common_image_get_cache(); + return soft16_image_cache_size_get(); } static void * =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_16/evas_soft16.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- evas_soft16.h 25 Oct 2007 22:09:49 -0000 1.11 +++ evas_soft16.h 26 Oct 2007 18:53:39 -0000 1.12 @@ -58,6 +58,9 @@ #define pld(addr, off) #endif /* __ARMEL__ */ +#define IMG_BYTE_SIZE(stride, height, has_alpha) \ + ((stride) * (height) * (!(has_alpha) ? 2 : 3)) + typedef struct _Soft16_Image Soft16_Image; struct _Soft16_Image @@ -75,9 +78,10 @@ Evas_Image_Load_Opts lo; // load options + const char *cache_key; + unsigned char have_alpha : 1; // 1 if we have halpha unsigned char free_pixels : 1; // 1 if pixels should be freed - unsigned char free_alpha : 1; // 1 if alpha mask should be freed }; /** @@ -85,6 +89,7 @@ */ Soft16_Image *soft16_image_new(int w, int h, int stride, int have_alpha, DATA16 *pixels, int copy); void soft16_image_free(Soft16_Image *im); +void soft16_image_destroy(Soft16_Image *im); Soft16_Image *soft16_image_load(const char *file, const char *key, int *error, Evas_Image_Load_Opts *lo); void soft16_image_load_data(Soft16_Image *im); void soft16_image_draw(Soft16_Image *src, Soft16_Image *dst, RGBA_Draw_Context *dc, 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, int smooth); @@ -99,6 +104,17 @@ void soft16_image_convert_from_rgb(Soft16_Image *im, const DATA32 *src); void soft16_image_convert_from_rgba(Soft16_Image *im, const DATA32 *src); +/** + * Image cache (evas_soft16_image_cache.c) + */ +void soft16_image_cache_flush(void); +int soft16_image_cache_size_get(void); +void soft16_image_cache_size_set(int limit); + +Soft16_Image *soft16_image_cache_get(const char *cache_key); +void soft16_image_cache_put(Soft16_Image *im); +void soft16_image_cache_add(Soft16_Image *im, const char *cache_key); +void soft16_image_cache_del(Soft16_Image *im); /** * Rectangle (evas_soft16_rectangle.c) =================================================================== RCS file: /cvs/e/e17/libs/evas/src/modules/engines/software_16/evas_soft16_main.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -3 -r1.16 -r1.17 --- evas_soft16_main.c 25 Oct 2007 22:09:49 -0000 1.16 +++ evas_soft16_main.c 26 Oct 2007 18:53:39 -0000 1.17 @@ -1,10 +1,5 @@ #include "evas_soft16.h" -#define IMG_BYTE_SIZE(stride, height, has_alpha) \ - ((stride) * (height) * (!(has_alpha) ? 2 : 3)) - -static Evas_Hash *_soft16_image_cache_hash = NULL; - static inline int _calc_stride(int w) { @@ -109,50 +104,28 @@ void soft16_image_free(Soft16_Image *im) { - if (!im) return; + if (!im) + return; + im->references--; - if (im->references > 0) return; - if (im->file) - { - char buf[4096 + 1024]; - soft16_image_cache_key_from_img(im, buf, sizeof(buf)); - _soft16_image_cache_hash = evas_hash_del(_soft16_image_cache_hash, - buf, im); - } + if (im->references > 0) + return; + + if (im->cache_key) + soft16_image_cache_put(im); + else + soft16_image_destroy(im); +} + +void +soft16_image_destroy(Soft16_Image *im) +{ if (im->file) evas_stringshare_del(im->file); if (im->key) evas_stringshare_del(im->key); if (im->free_pixels) free(im->pixels); free(im); } -#define STAT_GAP 2 - -static Soft16_Image * -soft16_image_cache_get(const char *cache_key) -{ - Soft16_Image *im; - - im = evas_hash_find(_soft16_image_cache_hash, cache_key); - if (im) - { - time_t t; - - t = time(NULL); - if ((t - im->laststat) > STAT_GAP) - { - struct stat st; - - if (stat(im->file, &st) < 0) return NULL; - if (st.st_mtime != im->timestamp) return NULL; - - im->laststat = t; - } - im->references++; - } - - return im; -} - static Soft16_Image * soft16_image_load_new(const char *file, const char *key, Evas_Image_Load_Opts *lo) @@ -192,13 +165,17 @@ char buf[4096 + 1024]; *error = 0; - if (!file) return NULL; + if (!file) + return NULL; + soft16_image_cache_key(lo, key, file, buf, sizeof(buf)); im = soft16_image_cache_get(buf); - if (im) return im; + if (im) + return im; im = soft16_image_load_new(file, key, lo); - if (im) _soft16_image_cache_hash = evas_hash_add(_soft16_image_cache_hash, buf, im); + if (im) + soft16_image_cache_add(im, buf); return im; } @@ -453,7 +430,7 @@ if (im->have_alpha == have_alpha) return im; im->have_alpha = have_alpha; - if ((im->pixels) && (im->free_pixels)) + if ((im->pixels) && (im->free_pixels) && (im->references == 1)) { int size; @@ -469,6 +446,9 @@ im->alpha = (DATA8*)(im->pixels + size); memset(im->alpha, 0x1f, size); } + + if (im->cache_key) + soft16_image_cache_remove(im); return im; } else ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs