Enlightenment CVS committal Author : raster Project : e17 Module : libs/evas
Dir : e17/libs/evas/src/lib/canvas Modified Files: evas_font_dir.c evas_object_text.c evas_object_textblock.c Log Message: dont realod ye demons of evil slowness! FIX FIX! cache you biotch! cache! =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/canvas/evas_font_dir.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- evas_font_dir.c 20 Mar 2005 16:41:49 -0000 1.5 +++ evas_font_dir.c 1 Apr 2005 07:14:15 -0000 1.6 @@ -7,6 +7,19 @@ /* font dir cache */ static Evas_Hash *font_dirs = NULL; +static Evas_List *fonts_cache = NULL; +static Evas_List *fonts_zero = NULL; + +typedef struct _Fndat Fndat; + +struct _Fndat +{ + char *name; + char *source; + int size; + void *font; + int ref; +}; /* private methods for font dir cache */ static Evas_Bool font_cache_dir_free(Evas_Hash *hash, const char *key, void *data, void *fdata); @@ -27,6 +40,30 @@ evas_hash_foreach (font_dirs, font_cache_dir_free, NULL); evas_hash_free (font_dirs); font_dirs = NULL; +/* + while (fonts_cache) + { + Fndat *fd; + + fd = evas_list_data(fonts_cache); + fonts_cache = evas_list_remove_list(fonts_cache, fonts_cache); + if (fd->name) free(fd->name); + if (fd->source) free(fd->source); + evas->engine.func->font_free(evas->engine.data.output, fd->font); + free(fd); + } + while (fonts_zero) + { + Fndat *fd; + + fd = evas_list_data(fonts_zero); + fonts_zero = evas_list_remove_list(fonts_zero, fonts_zero); + if (fd->name) free(fd->name); + if (fd->source) free(fd->source); + evas->engine.func->font_free(evas->engine.data.output, fd->font); + free(fd); + } + */ } char * @@ -41,7 +78,10 @@ Evas_Font *fn; fn = object_text_font_cache_font_find(fd, font); - if (fn) return fn->path; + if (fn) + { + return fn->path; + } } return NULL; } @@ -76,12 +116,85 @@ return fonts; } +void +evas_font_free(Evas *evas, void *font) +{ + Evas_List *l; + + for (l = fonts_cache; l; l = l->next) + { + Fndat *fd; + + fd = l->data; + if (fd->font == font) + { + fd->ref--; + if (fd->ref == 0) + { + fonts_cache = evas_list_remove_list(fonts_cache, l); + fonts_zero = evas_list_append(fonts_zero, fd); + } + break; + } + } + while ((fonts_zero) && + (evas_list_count(fonts_zero) > 4)) /* 4 is arbitrary */ + { + Fndat *fd; + + fd = evas_list_data(fonts_zero); + if (fd->ref != 0) break; + fonts_zero = evas_list_remove_list(fonts_zero, fonts_zero); + if (fd->name) free(fd->name); + if (fd->source) free(fd->source); + evas->engine.func->font_free(evas->engine.data.output, fd->font); + free(fd); + } +} + void * evas_font_load(Evas *evas, char *name, char *source, int size) { void *font = NULL; Evas_List *fonts, *l; - + Fndat *fd; + + for (l = fonts_cache; l; l = l->next) + { + fd = l->data; + if (!strcmp(name, fd->name)) + { + if (((!source) && (!fd->source)) || + ((source) && (fd->source) && (!strcmp(source, fd->source)))) + { + if (size == fd->size) + { + fonts_cache = evas_list_remove_list(fonts_cache, l); + fonts_cache = evas_list_prepend(fonts_cache, fd); + fd->ref++; + return fd->font; + } + } + } + } + for (l = fonts_zero; l; l = l->next) + { + fd = l->data; + if (!strcmp(name, fd->name)) + { + if (((!source) && (!fd->source)) || + ((source) && (fd->source) && (!strcmp(source, fd->source)))) + { + if (size == fd->size) + { + fonts_zero = evas_list_remove_list(fonts_zero, l); + fonts_cache = evas_list_prepend(fonts_cache, fd); + fd->ref++; + return fd->font; + } + } + } + } fonts = evas_font_set_get(name); for (l = fonts; l; l = l->next) { @@ -211,6 +324,16 @@ free(nm); } evas_list_free(fonts); + fd = calloc(1, sizeof(Fndat)); + if (fd) + { + fd->name = strdup(name); + if (source) fd->source = strdup(source); + fd->size = size; + fd->font = font; + fd->ref = 1; + fonts_cache = evas_list_prepend(fonts_cache, fd); + } return font; } @@ -220,7 +343,6 @@ font_cache_dir_free(Evas_Hash *hash, const char *key, void *data, void *fdata) { object_text_font_cache_dir_del((char *) key, data); - return 1; } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/canvas/evas_object_text.c,v retrieving revision 1.34 retrieving revision 1.35 diff -u -3 -r1.34 -r1.35 --- evas_object_text.c 7 Feb 2005 02:25:27 -0000 1.34 +++ evas_object_text.c 1 Apr 2005 07:14:15 -0000 1.35 @@ -160,8 +160,7 @@ /* DO IT */ if (o->engine_data) { - obj->layer->evas->engine.func->font_free(obj->layer->evas->engine.data.output, - o->engine_data); + evas_font_free(obj->layer->evas, o->engine_data); o->engine_data = NULL; } o->engine_data = evas_font_load(obj->layer->evas, font, o->cur.source, size); @@ -826,9 +825,7 @@ if (o->cur.text) free(o->cur.text); if (o->cur.font) free(o->cur.font); if (o->cur.source) free(o->cur.source); - if (o->engine_data) - obj->layer->evas->engine.func->font_free(obj->layer->evas->engine.data.output, - o->engine_data); + if (o->engine_data) evas_font_free(obj->layer->evas, o->engine_data); o->magic = 0; free(o); } =================================================================== RCS file: /cvsroot/enlightenment/e17/libs/evas/src/lib/canvas/evas_object_textblock.c,v retrieving revision 1.52 retrieving revision 1.53 diff -u -3 -r1.52 -r1.53 --- evas_object_textblock.c 30 Mar 2005 16:55:10 -0000 1.52 +++ evas_object_textblock.c 1 Apr 2005 07:14:15 -0000 1.53 @@ -842,7 +842,7 @@ { if (layout->font.name) free(layout->font.name); if (layout->font.source) free(layout->font.source); - if (layout->font.font) ENFN->font_free(ENDT, layout->font.font); + if (layout->font.font) evas_font_free(obj->layer->evas, layout->font.font); memset(layout, 0, sizeof(Layout)); } @@ -876,7 +876,7 @@ while (o->font_hold) { - ENFN->font_free(ENDT, o->font_hold->data); + evas_font_free(obj->layer->evas, o->font_hold->data); o->font_hold = evas_list_remove_list(o->font_hold, o->font_hold); } } @@ -1086,7 +1086,7 @@ if (layout.line.mdescent < layout.line.descent) layout.line.mdescent = layout.line.descent; if (layout.font.font) - ENFN->font_free(ENDT, layout.font.font); + evas_font_free(obj->layer->evas, layout.font.font); layout.font.font = NULL; } if ((layout.line.y + layout.line.mascent + layout.line.mdescent) > hh) ------------------------------------------------------- This SF.net email is sponsored by Demarc: A global provider of Threat Management Solutions. Download our HomeAdmin security software for free today! http://www.demarc.com/info/Sentarus/hamr30 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs