summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-08-07 18:48:00 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:14 +0900
commit7ebda2d123ec53bad84dc7eabc08530477d50e80 (patch)
tree0cf81fd9471e37e7c6dcc48560247ea9a57449ef /src/bin
parent28a5c6f587992b5cf5506129c86cdde95253d525 (diff)
evas/cserve2: Store glyphs in shared arrays
Also, change the internal structure of glyph listing: - Use lists instead of inlists Switch to use Glyph_Data instead of Glyph_Entry
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/evas/evas_cserve2_cache.c175
1 files changed, 108 insertions, 67 deletions
diff --git a/src/bin/evas/evas_cserve2_cache.c b/src/bin/evas/evas_cserve2_cache.c
index 3a66988767..efe90be849 100644
--- a/src/bin/evas/evas_cserve2_cache.c
+++ b/src/bin/evas/evas_cserve2_cache.c
@@ -75,7 +75,7 @@ struct _Font_Entry {
75 void *ft; 75 void *ft;
76 Fash_Glyph2 *glyphs; 76 Fash_Glyph2 *glyphs;
77 unsigned int nglyphs; 77 unsigned int nglyphs;
78 Eina_Inlist *caches; 78 Eina_List *caches;
79 Font_Cache *last_cache; 79 Font_Cache *last_cache;
80 Eina_Bool unused : 1; 80 Eina_Bool unused : 1;
81#ifdef DEBUG_LOAD_TIME 81#ifdef DEBUG_LOAD_TIME
@@ -90,27 +90,18 @@ struct _Font_Entry {
90}; 90};
91 91
92struct _Font_Cache { 92struct _Font_Cache {
93 EINA_INLIST;
94 Font_Entry *fe; 93 Font_Entry *fe;
95 Shm_Handle *shm; 94 Shm_Handle *shm;
96 unsigned int usage; 95 unsigned int usage;
97 int inuse; 96 int inuse;
98 Eina_Inlist *glyphs; 97 Shared_Array *glyphs; // Contains gldata_id only
99 unsigned int nglyphs; 98 unsigned int nglyphs;
100}; 99};
101 100
102struct _Glyph_Entry { 101struct _Glyph_Entry {
103 EINA_INLIST; 102 unsigned int gldata_id;
104 Font_Entry *fe; 103 Font_Entry *fe;
105 Font_Cache *fc; 104 Font_Cache *fc;
106 unsigned int index;
107 unsigned int offset;
108 unsigned int size;
109 unsigned int rows;
110 unsigned int width;
111 unsigned int pitch;
112 unsigned int num_grays;
113 unsigned int pixel_mode;
114}; 105};
115 106
116struct _Glyphs_Request { 107struct _Glyphs_Request {
@@ -148,11 +139,13 @@ struct _File_Watch {
148}; 139};
149 140
150static unsigned int _entry_id = 0; 141static unsigned int _entry_id = 0;
142static unsigned int _glyph_id = 0;
151static unsigned int _freed_file_entry_count = 0; 143static unsigned int _freed_file_entry_count = 0;
152static unsigned int _freed_image_entry_count = 0; 144static unsigned int _freed_image_entry_count = 0;
153 145
154static Shared_Array *_file_data_array = NULL; 146static Shared_Array *_file_data_array = NULL;
155static Shared_Array *_image_data_array = NULL; 147static Shared_Array *_image_data_array = NULL;
148static Shared_Array *_glyph_data_array = NULL;
156 149
157static Eina_Hash *file_ids = NULL; // maps path + key --> file_id 150static Eina_Hash *file_ids = NULL; // maps path + key --> file_id
158static Eina_Hash *file_entries = NULL; // maps file_id --> entry 151static Eina_Hash *file_entries = NULL; // maps file_id --> entry
@@ -303,6 +296,22 @@ _image_entry_find(unsigned int entry_id)
303 return (Image_Entry *) e; 296 return (Image_Entry *) e;
304} 297}
305 298
299static Glyph_Data *
300_glyph_data_find(unsigned int glyph_id)
301{
302 Glyph_Data *gldata;
303
304 gldata = cserve2_shared_array_item_data_find(_glyph_data_array, &glyph_id,
305 _shm_object_id_cmp_cb);
306 if (!gldata)
307 {
308 ERR("Could not find glyph %u", glyph_id);
309 return NULL;
310 }
311
312 return gldata;
313}
314
306static Eina_Bool 315static Eina_Bool
307_repack_skip_cb(Shared_Array *sa EINA_UNUSED, const void *elem, 316_repack_skip_cb(Shared_Array *sa EINA_UNUSED, const void *elem,
308 void *user_data EINA_UNUSED) 317 void *user_data EINA_UNUSED)
@@ -1061,6 +1070,12 @@ static void
1061_glyph_free_cb(void *data) 1070_glyph_free_cb(void *data)
1062{ 1071{
1063 Glyph_Entry *gl = data; 1072 Glyph_Entry *gl = data;
1073 Glyph_Data *gldata;
1074
1075 if (!gl) return;
1076 gldata = _glyph_data_find(gl->gldata_id);
1077 cserve2_shared_string_del(gldata->shm_id);
1078 gldata->refcount--;
1064 free(gl); 1079 free(gl);
1065} 1080}
1066 1081
@@ -1096,18 +1111,22 @@ _font_shm_size_get(Font_Cache *fc)
1096static void 1111static void
1097_font_shm_free(Font_Cache *fc) 1112_font_shm_free(Font_Cache *fc)
1098{ 1113{
1114 Glyph_Data *gd;
1099 Font_Entry *fe = fc->fe; 1115 Font_Entry *fe = fc->fe;
1100 fe->caches = eina_inlist_remove(fe->caches, EINA_INLIST_GET(fc)); 1116 unsigned int k;
1117
1118 fe->caches = eina_list_remove(fe->caches, fc);
1101 if (fc == fe->last_cache) 1119 if (fc == fe->last_cache)
1102 fe->last_cache = NULL; 1120 fe->last_cache = NULL;
1103 1121
1104 while (fc->glyphs) 1122 for (k = 0; k < fc->nglyphs; k++)
1105 { 1123 {
1106 Glyph_Entry *gl = EINA_INLIST_CONTAINER_GET(fc->glyphs, Glyph_Entry); 1124 int *gldata_id = cserve2_shared_array_item_data_get(fc->glyphs, k);
1107 fc->glyphs = eina_inlist_remove(fc->glyphs, fc->glyphs); 1125 gd = _glyph_data_find(*gldata_id);
1108 fash_gl_del(fe->glyphs, gl->index); 1126 fash_gl_del(fe->glyphs, gd->index);
1109 } 1127 }
1110 1128
1129 cserve2_shared_array_del(fc->glyphs);
1111 cserve2_shm_unref(fc->shm); 1130 cserve2_shm_unref(fc->shm);
1112 free(fc); 1131 free(fc);
1113 1132
@@ -1161,6 +1180,7 @@ cserve2_cache_init(void)
1161 1180
1162 _file_data_array = cserve2_shared_array_new(1, sizeof(File_Data), 0); 1181 _file_data_array = cserve2_shared_array_new(1, sizeof(File_Data), 0);
1163 _image_data_array = cserve2_shared_array_new(1, sizeof(Image_Data), 0); 1182 _image_data_array = cserve2_shared_array_new(1, sizeof(Image_Data), 0);
1183 _glyph_data_array = cserve2_shared_array_new(1, sizeof(Glyph_Data), 0);
1164} 1184}
1165 1185
1166void 1186void
@@ -1182,6 +1202,7 @@ cserve2_cache_shutdown(void)
1182 1202
1183 cserve2_shared_array_del(_file_data_array); 1203 cserve2_shared_array_del(_file_data_array);
1184 cserve2_shared_array_del(_image_data_array); 1204 cserve2_shared_array_del(_image_data_array);
1205 cserve2_shared_array_del(_glyph_data_array);
1185} 1206}
1186 1207
1187static Reference * 1208static Reference *
@@ -1716,7 +1737,7 @@ _glyphs_loaded_msg_create(Glyphs_Request *req, int *resp_size)
1716 size += sizeof(int); 1737 size += sizeof(int);
1717 // nglyphs * (index + offset + size + rows + width + pitch + 1738 // nglyphs * (index + offset + size + rows + width + pitch +
1718 // num_grays + pixel_mode) 1739 // num_grays + pixel_mode)
1719 size += eina_list_count(iter->glyphs) * 8 * sizeof(int); 1740 size += eina_list_count(iter->glyphs) * 9 * sizeof(int);
1720 } 1741 }
1721 1742
1722 resp = malloc(size); 1743 resp = malloc(size);
@@ -1743,21 +1764,27 @@ _glyphs_loaded_msg_create(Glyphs_Request *req, int *resp_size)
1743 1764
1744 EINA_LIST_FREE(iter->glyphs, gl) 1765 EINA_LIST_FREE(iter->glyphs, gl)
1745 { 1766 {
1746 memcpy(buf, &gl->index, sizeof(int)); 1767 // TODO: Factorize memcpy
1768 Glyph_Data *gldata;
1769
1770 gldata = _glyph_data_find(gl->gldata_id);
1771 memcpy(buf, &gldata->index, sizeof(int));
1747 buf += sizeof(int); 1772 buf += sizeof(int);
1748 memcpy(buf, &gl->offset, sizeof(int)); 1773 memcpy(buf, &gldata->shm_id, sizeof(string_t));
1774 buf += sizeof(string_t);
1775 memcpy(buf, &gldata->offset, sizeof(int));
1749 buf += sizeof(int); 1776 buf += sizeof(int);
1750 memcpy(buf, &gl->size, sizeof(int)); 1777 memcpy(buf, &gldata->size, sizeof(int));
1751 buf += sizeof(int); 1778 buf += sizeof(int);
1752 memcpy(buf, &gl->rows, sizeof(int)); 1779 memcpy(buf, &gldata->rows, sizeof(int));
1753 buf += sizeof(int); 1780 buf += sizeof(int);
1754 memcpy(buf, &gl->width, sizeof(int)); 1781 memcpy(buf, &gldata->width, sizeof(int));
1755 buf += sizeof(int); 1782 buf += sizeof(int);
1756 memcpy(buf, &gl->pitch, sizeof(int)); 1783 memcpy(buf, &gldata->pitch, sizeof(int));
1757 buf += sizeof(int); 1784 buf += sizeof(int);
1758 memcpy(buf, &gl->num_grays, sizeof(int)); 1785 memcpy(buf, &gldata->num_grays, sizeof(int));
1759 buf += sizeof(int); 1786 buf += sizeof(int);
1760 memcpy(buf, &gl->pixel_mode, sizeof(int)); 1787 memcpy(buf, &gldata->pixel_mode, sizeof(int));
1761 buf += sizeof(int); 1788 buf += sizeof(int);
1762 } 1789 }
1763 1790
@@ -1955,21 +1982,23 @@ _glyphs_load_request_response(Glyphs_Request *req,
1955 { 1982 {
1956 unsigned int j; 1983 unsigned int j;
1957 Slave_Msg_Font_Cache *c = msg->caches[i]; 1984 Slave_Msg_Font_Cache *c = msg->caches[i];
1985 string_t shm_id;
1958 1986
1959 if (!fc) 1987 if (!fc)
1960 { 1988 {
1961 fc = calloc(1, sizeof(*fc)); 1989 fc = calloc(1, sizeof(*fc));
1962 fe->caches = eina_inlist_append(fe->caches, EINA_INLIST_GET(fc)); 1990 fe->caches = eina_list_append(fe->caches, fc);
1963 fe->last_cache = fc; 1991 fe->last_cache = fc;
1964 fc->fe = fe; 1992 fc->fe = fe;
1965 fc->shm = c->shm; 1993 fc->shm = c->shm;
1966 fc->glyphs = NULL; 1994 fc->glyphs = cserve2_shared_array_new(1, sizeof(int), 0);
1967 fc->nglyphs = 0; 1995 fc->nglyphs = 0;
1968 fc->inuse = 0; 1996 fc->inuse = 0;
1969 font_shm_lru = eina_list_append(font_shm_lru, fc); 1997 font_shm_lru = eina_list_append(font_shm_lru, fc);
1970 font_mem_usage += _font_shm_size_get(fc); 1998 font_mem_usage += _font_shm_size_get(fc);
1971 } 1999 }
1972 fc->usage = c->usage; 2000 fc->usage = c->usage;
2001 shm_id = cserve2_shared_string_add(cserve2_shm_name_get(fc->shm));
1973 for (j = 0; j < c->nglyphs; j++) 2002 for (j = 0; j < c->nglyphs; j++)
1974 { 2003 {
1975 Glyph_Entry *gl; 2004 Glyph_Entry *gl;
@@ -1977,27 +2006,41 @@ _glyphs_load_request_response(Glyphs_Request *req,
1977 gl = fash_gl_find(fe->glyphs, c->glyphs[j].index); 2006 gl = fash_gl_find(fe->glyphs, c->glyphs[j].index);
1978 if (!gl) 2007 if (!gl)
1979 { 2008 {
2009 int glyph_id, idx, *gldata_id;
2010 Glyph_Data *gldata;
2011
1980 gl = calloc(1, sizeof(*gl)); 2012 gl = calloc(1, sizeof(*gl));
1981 gl->fe = fe; 2013 gl->fe = fe;
1982 gl->fc = fc; 2014 gl->fc = fc;
1983 gl->index = c->glyphs[j].index; 2015 gl->gldata_id = ++_glyph_id;
1984 gl->offset = c->glyphs[j].offset; 2016
1985 gl->size = c->glyphs[j].size; 2017 glyph_id = cserve2_shared_array_item_new(_glyph_data_array);
1986 gl->rows = c->glyphs[j].rows; 2018 gldata = cserve2_shared_array_item_data_get(_glyph_data_array,
1987 gl->width = c->glyphs[j].width; 2019 glyph_id);
1988 gl->pitch = c->glyphs[j].pitch; 2020 gldata->refcount = 1;
1989 gl->num_grays = c->glyphs[j].num_grays; 2021 gldata->id = gl->gldata_id;
1990 gl->pixel_mode = c->glyphs[j].pixel_mode; 2022 gldata->index = c->glyphs[j].index;
1991 font_mem_usage += sizeof(*gl); 2023 gldata->shm_id = cserve2_shared_string_ref(shm_id);
1992 fc->glyphs = eina_inlist_append(fc->glyphs, EINA_INLIST_GET(gl)); 2024 gldata->offset = c->glyphs[j].offset;
2025 gldata->size = c->glyphs[j].size;
2026 gldata->rows = c->glyphs[j].rows;
2027 gldata->width = c->glyphs[j].width;
2028 gldata->pitch = c->glyphs[j].pitch;
2029 gldata->num_grays = c->glyphs[j].num_grays;
2030 gldata->pixel_mode = c->glyphs[j].pixel_mode;
2031 font_mem_usage += sizeof(*gl) + sizeof(*gldata);
2032 idx = cserve2_shared_array_item_new(fc->glyphs);
2033 gldata_id = cserve2_shared_array_item_data_get(fc->glyphs, idx);
2034 *gldata_id = gldata->id;
1993 fc->nglyphs++; 2035 fc->nglyphs++;
1994 fe->nglyphs++; 2036 fe->nglyphs++;
1995 fash_gl_add(fe->glyphs, gl->index, gl); 2037 fash_gl_add(fe->glyphs, gldata->index, gl);
1996 } 2038 }
1997 req->answer[req->nanswer++] = gl; 2039 req->answer[req->nanswer++] = gl;
1998 gl->fc->inuse++; 2040 gl->fc->inuse++;
1999 } 2041 }
2000 2042
2043 cserve2_shared_string_del(shm_id);
2001 free(c); // FIXME: We are freeing this here because we only do a 2044 free(c); // FIXME: We are freeing this here because we only do a
2002 // simple free on the response message. Later we need to 2045 // simple free on the response message. Later we need to
2003 // setup a free callback for the slave response. 2046 // setup a free callback for the slave response.
@@ -2034,6 +2077,7 @@ _font_entry_stats_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNU
2034{ 2077{
2035 Font_Entry *fe = data; 2078 Font_Entry *fe = data;
2036 Msg_Stats *msg = fdata; 2079 Msg_Stats *msg = fdata;
2080 Eina_List *iter;
2037 Font_Cache *fc; 2081 Font_Cache *fc;
2038 int nrefs = eina_list_count(fe->base.references); 2082 int nrefs = eina_list_count(fe->base.references);
2039 2083
@@ -2041,7 +2085,7 @@ _font_entry_stats_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNU
2041 if (fe->unused) msg->fonts.fonts_unused++; 2085 if (fe->unused) msg->fonts.fonts_unused++;
2042 2086
2043 // accounting size 2087 // accounting size
2044 EINA_INLIST_FOREACH(fe->caches, fc) 2088 EINA_LIST_FOREACH(fe->caches, iter, fc)
2045 { 2089 {
2046 unsigned int fc_usage, shmsize; 2090 unsigned int fc_usage, shmsize;
2047 /* This is not real requested usage, but an approximation. We don't 2091 /* This is not real requested usage, but an approximation. We don't
@@ -2164,6 +2208,7 @@ _font_entry_debug_size_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EIN
2164 unsigned int size = di->size; 2208 unsigned int size = di->size;
2165 Font_Entry *fe = data; 2209 Font_Entry *fe = data;
2166 Font_Cache *fc; 2210 Font_Cache *fc;
2211 Eina_List *iter;
2167 const char *str; 2212 const char *str;
2168 2213
2169 // filelen 2214 // filelen
@@ -2195,10 +2240,8 @@ _font_entry_debug_size_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EIN
2195 // ncaches 2240 // ncaches
2196 size += sizeof(int); 2241 size += sizeof(int);
2197 2242
2198 EINA_INLIST_FOREACH(fe->caches, fc) 2243 EINA_LIST_FOREACH(fe->caches, iter, fc)
2199 { 2244 {
2200 Glyph_Entry *gl;
2201
2202 // shmnamelen + shmname 2245 // shmnamelen + shmname
2203 size += sizeof(int); 2246 size += sizeof(int);
2204 size += strlen(cserve2_shm_name_get(fc->shm)) + 1; 2247 size += strlen(cserve2_shm_name_get(fc->shm)) + 1;
@@ -2209,17 +2252,7 @@ _font_entry_debug_size_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EIN
2209 // nglyphs 2252 // nglyphs
2210 size += sizeof(int); 2253 size += sizeof(int);
2211 2254
2212 EINA_INLIST_FOREACH(fc->glyphs, gl) 2255 size += (4 + 3 + 2) * sizeof(int) * fc->nglyphs;
2213 {
2214 // index, offset, size
2215 size += 3 * sizeof(int);
2216
2217 // rows, width, pitch
2218 size += 3 * sizeof(int);
2219
2220 // num_grays, pixel_mode
2221 size += 2 * sizeof(int);
2222 }
2223 } 2256 }
2224 2257
2225 di->size = size; 2258 di->size = size;
@@ -2235,6 +2268,7 @@ _font_entry_debug_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNU
2235 char *buf = *pos; 2268 char *buf = *pos;
2236 Font_Entry *fe = data; 2269 Font_Entry *fe = data;
2237 Font_Cache *fc; 2270 Font_Cache *fc;
2271 Eina_List *iter;
2238 unsigned int len; 2272 unsigned int len;
2239 unsigned int unused; 2273 unsigned int unused;
2240 unsigned int ncaches; 2274 unsigned int ncaches;
@@ -2278,15 +2312,16 @@ _font_entry_debug_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNU
2278 buf += sizeof(int); 2312 buf += sizeof(int);
2279 2313
2280 // ncaches 2314 // ncaches
2281 ncaches = eina_inlist_count(fe->caches); 2315 ncaches = eina_list_count(fe->caches);
2282 memcpy(buf, &ncaches, sizeof(int)); 2316 memcpy(buf, &ncaches, sizeof(int));
2283 buf += sizeof(int); 2317 buf += sizeof(int);
2284 2318
2285 EINA_INLIST_FOREACH(fe->caches, fc) 2319 EINA_LIST_FOREACH(fe->caches, iter, fc)
2286 { 2320 {
2287 Glyph_Entry *gl; 2321 Glyph_Data *gldata;
2288 const char *shmname; 2322 const char *shmname;
2289 unsigned int shmsize; 2323 unsigned int shmsize;
2324 unsigned int k;
2290 2325
2291 // shmnamelen + shmname 2326 // shmnamelen + shmname
2292 shmname = cserve2_shm_name_get(fc->shm); 2327 shmname = cserve2_shm_name_get(fc->shm);
@@ -2307,28 +2342,34 @@ _font_entry_debug_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNU
2307 memcpy(buf, &fc->nglyphs, sizeof(int)); 2342 memcpy(buf, &fc->nglyphs, sizeof(int));
2308 buf += sizeof(int); 2343 buf += sizeof(int);
2309 2344
2310 EINA_INLIST_FOREACH(fc->glyphs, gl) 2345 for (k = 0; k < fc->nglyphs; k++)
2311 { 2346 {
2312 // index, offset, size 2347 int *gldata_id = cserve2_shared_array_item_data_get(
2313 memcpy(buf, &gl->index, sizeof(int)); 2348 fc->glyphs, fc->nglyphs);
2349 gldata = _glyph_data_find(*gldata_id);
2350
2351 // index, shm_id, offset, size
2352 memcpy(buf, &gldata->index, sizeof(int));
2314 buf += sizeof(int); 2353 buf += sizeof(int);
2315 memcpy(buf, &gl->offset, sizeof(int)); 2354 memcpy(buf, &gldata->shm_id, sizeof(string_t));
2355 buf += sizeof(string_t);
2356 memcpy(buf, &gldata->offset, sizeof(int));
2316 buf += sizeof(int); 2357 buf += sizeof(int);
2317 memcpy(buf, &gl->size, sizeof(int)); 2358 memcpy(buf, &gldata->size, sizeof(int));
2318 buf += sizeof(int); 2359 buf += sizeof(int);
2319 2360
2320 // rows, width, pitch 2361 // rows, width, pitch
2321 memcpy(buf, &gl->rows, sizeof(int)); 2362 memcpy(buf, &gldata->rows, sizeof(int));
2322 buf += sizeof(int); 2363 buf += sizeof(int);
2323 memcpy(buf, &gl->width, sizeof(int)); 2364 memcpy(buf, &gldata->width, sizeof(int));
2324 buf += sizeof(int); 2365 buf += sizeof(int);
2325 memcpy(buf, &gl->pitch, sizeof(int)); 2366 memcpy(buf, &gldata->pitch, sizeof(int));
2326 buf += sizeof(int); 2367 buf += sizeof(int);
2327 2368
2328 // num_grays, pixel_mode 2369 // num_grays, pixel_mode
2329 memcpy(buf, &gl->num_grays, sizeof(int)); 2370 memcpy(buf, &gldata->num_grays, sizeof(int));
2330 buf += sizeof(int); 2371 buf += sizeof(int);
2331 memcpy(buf, &gl->pixel_mode, sizeof(int)); 2372 memcpy(buf, &gldata->pixel_mode, sizeof(int));
2332 buf += sizeof(int); 2373 buf += sizeof(int);
2333 } 2374 }
2334 } 2375 }