summaryrefslogtreecommitdiff
path: root/src/lib/evas/cserve2/evas_cs2_client.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-08-26 15:31:52 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:14 +0900
commit22009a3f644094816e2ae649dd3ad48b04825a5f (patch)
tree405e44fb7b9a6a5415eb1d4f4ffe24993e71066a /src/lib/evas/cserve2/evas_cs2_client.c
parent3f30fae818cde5d0f9d2159e7461d53493f295b8 (diff)
evas/cserve2: Use only one Glyph_Map per font
In the new cs2 model, only one shared buffer is allocated for a font, and it resizes on demand.
Diffstat (limited to 'src/lib/evas/cserve2/evas_cs2_client.c')
-rw-r--r--src/lib/evas/cserve2/evas_cs2_client.c105
1 files changed, 59 insertions, 46 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c
index 16e1ebbf1b..d6cedcc658 100644
--- a/src/lib/evas/cserve2/evas_cs2_client.c
+++ b/src/lib/evas/cserve2/evas_cs2_client.c
@@ -55,6 +55,7 @@ static const Shm_Object *_shared_index_item_get_by_id(Shared_Index *si, int elem
55static const File_Data *_shared_image_entry_file_data_find(Image_Entry *ie); 55static const File_Data *_shared_image_entry_file_data_find(Image_Entry *ie);
56static const Image_Data *_shared_image_entry_image_data_find(Image_Entry *ie); 56static const Image_Data *_shared_image_entry_image_data_find(Image_Entry *ie);
57static const Font_Data *_shared_font_entry_data_find(Font_Entry *fe); 57static const Font_Data *_shared_font_entry_data_find(Font_Entry *fe);
58static Eina_Bool _shared_index_remap_check(Shared_Index *si, int elemsize);
58 59
59#ifndef UNIX_PATH_MAX 60#ifndef UNIX_PATH_MAX
60#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path) 61#define UNIX_PATH_MAX sizeof(((struct sockaddr_un *)NULL)->sun_path)
@@ -1100,7 +1101,7 @@ struct _Font_Entry
1100 1101
1101 unsigned int rid; // open 1102 unsigned int rid; // open
1102 1103
1103 Eina_Hash *glyphs_maps; 1104 Glyph_Map *map;
1104 Fash_Glyph2 *fash[3]; // one per hinting value 1105 Fash_Glyph2 *fash[3]; // one per hinting value
1105 1106
1106 Eina_Clist glyphs_queue; 1107 Eina_Clist glyphs_queue;
@@ -1114,10 +1115,8 @@ struct _Font_Entry
1114struct _Glyph_Map 1115struct _Glyph_Map
1115{ 1116{
1116 Font_Entry *fe; 1117 Font_Entry *fe;
1117 const char *name; 1118 Shared_Index index;
1118 unsigned int size; 1119 Shared_Buffer mempool;
1119 Eina_File *map;
1120 unsigned char *data;
1121 Eina_Clist glyphs; 1120 Eina_Clist glyphs;
1122}; 1121};
1123 1122
@@ -1135,12 +1134,15 @@ struct _CS_Glyph_Out
1135}; 1134};
1136 1135
1137static void 1136static void
1138_glyphs_map_free(Glyph_Map *m) 1137_glyphs_map_free(Glyph_Map *map)
1139{ 1138{
1140 eina_file_map_free(m->map, m->data); 1139 if (!map) return;
1141 eina_file_close(m->map); 1140 eina_file_map_free(map->mempool.f, map->mempool.data);
1142 eina_stringshare_del(m->name); 1141 eina_file_close(map->mempool.f);
1143 free(m); 1142 eina_file_map_free(map->index.f, map->index.data);
1143 eina_file_close(map->index.f);
1144 map->fe->map = NULL;
1145 free(map);
1144} 1146}
1145 1147
1146static void 1148static void
@@ -1150,28 +1152,14 @@ _glyph_out_free(void *gl)
1150 1152
1151 if (glout->map) 1153 if (glout->map)
1152 { 1154 {
1153 // FIXME: Invalid write of size 8 here (64 bit machine)
1154 eina_clist_remove(&glout->map_entry); 1155 eina_clist_remove(&glout->map_entry);
1155 if (eina_clist_empty(&glout->map->glyphs)) 1156 if (eina_clist_empty(&glout->map->glyphs))
1156 { 1157 _glyphs_map_free(glout->map);
1157 eina_hash_del(glout->map->fe->glyphs_maps, &glout->map->name,
1158 NULL);
1159 _glyphs_map_free(glout->map);
1160 }
1161 } 1158 }
1162 1159
1163 free(glout); 1160 free(glout);
1164} 1161}
1165 1162
1166static Eina_Bool
1167_glyphs_maps_foreach_free(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED)
1168{
1169 Glyph_Map *m = data;
1170
1171 _glyphs_map_free(m);
1172 return EINA_TRUE;
1173}
1174
1175static void 1163static void
1176_font_entry_free(Font_Entry *fe) 1164_font_entry_free(Font_Entry *fe)
1177{ 1165{
@@ -1185,8 +1173,7 @@ _font_entry_free(Font_Entry *fe)
1185 free(fe->hkey); 1173 free(fe->hkey);
1186 eina_stringshare_del(fe->source); 1174 eina_stringshare_del(fe->source);
1187 eina_stringshare_del(fe->name); 1175 eina_stringshare_del(fe->name);
1188 eina_hash_foreach(fe->glyphs_maps, _glyphs_maps_foreach_free, NULL); 1176 _glyphs_map_free(fe->map);
1189 eina_hash_free(fe->glyphs_maps);
1190 free(fe); 1177 free(fe);
1191} 1178}
1192 1179
@@ -1269,7 +1256,6 @@ evas_cserve2_font_load(const char *source, const char *name, int size, int dpi,
1269 return NULL; 1256 return NULL;
1270 } 1257 }
1271 1258
1272 fe->glyphs_maps = eina_hash_stringshared_new(NULL);
1273 eina_clist_init(&fe->glyphs_queue); 1259 eina_clist_init(&fe->glyphs_queue);
1274 eina_clist_init(&fe->glyphs_used); 1260 eina_clist_init(&fe->glyphs_used);
1275 1261
@@ -1339,6 +1325,33 @@ typedef struct
1339 unsigned int rid; 1325 unsigned int rid;
1340} Glyph_Request_Data; 1326} Glyph_Request_Data;
1341 1327
1328static Glyph_Map *
1329_glyph_map_open(Font_Entry *fe, const char *indexpath, const char *datapath)
1330{
1331 Glyph_Map *map;
1332
1333 if (!fe) return NULL;
1334 if (fe->map) return fe->map;
1335
1336 map = calloc(1, sizeof(*map));
1337 if (!map) return NULL;
1338
1339 map->fe = fe;
1340 eina_clist_init(&map->glyphs);
1341 eina_strlcpy(map->index.path, indexpath, SHARED_BUFFER_PATH_MAX);
1342 eina_strlcpy(map->mempool.path, datapath, SHARED_BUFFER_PATH_MAX);
1343
1344 map->index.generation_id = _index.generation_id;
1345 _shared_index_remap_check(&map->index, sizeof(Glyph_Data));
1346
1347 map->mempool.f = eina_file_open(map->mempool.path, EINA_TRUE);
1348 map->mempool.size = eina_file_size_get(map->mempool.f);
1349 map->mempool.data = eina_file_map_all(map->mempool.f, EINA_FILE_RANDOM);
1350
1351 fe->map = map;
1352 return map;
1353}
1354
1342static void 1355static void
1343_glyph_request_cb(void *data, const void *msg, int size) 1356_glyph_request_cb(void *data, const void *msg, int size)
1344{ 1357{
@@ -1349,7 +1362,6 @@ _glyph_request_cb(void *data, const void *msg, int size)
1349 int i, nglyphs; 1362 int i, nglyphs;
1350 int namelen; 1363 int namelen;
1351 const char *name; 1364 const char *name;
1352 Glyph_Map *map;
1353 int pos; 1365 int pos;
1354 1366
1355 if (resp->base.type == CSERVE2_ERROR) 1367 if (resp->base.type == CSERVE2_ERROR)
@@ -1372,25 +1384,27 @@ _glyph_request_cb(void *data, const void *msg, int size)
1372 pos += namelen + sizeof(int); 1384 pos += namelen + sizeof(int);
1373 if (pos > size) goto end; 1385 if (pos > size) goto end;
1374 1386
1375 name = eina_stringshare_add_length(buf, namelen); 1387 name = buf; //eina_stringshare_add_length(buf, namelen);
1376 buf += namelen; 1388 buf += namelen;
1377 1389
1378 memcpy(&nglyphs, buf, sizeof(int)); 1390 memcpy(&nglyphs, buf, sizeof(int));
1379 buf += sizeof(int); 1391 buf += sizeof(int);
1380 1392
1381 map = eina_hash_find(fe->glyphs_maps, name); 1393 if (!fe->map)
1382 if (!map)
1383 { 1394 {
1384 map = calloc(1, sizeof(*map)); 1395 const Font_Data *fd;
1385 map->fe = fe; 1396 const char *idxpath = NULL, *datapath;
1386 map->name = name; 1397
1387 map->map = eina_file_open(name, EINA_TRUE); 1398 fd = _shared_font_entry_data_find(fe);
1388 map->data = eina_file_map_all(map->map, EINA_FILE_WILLNEED); 1399 if (fd)
1389 eina_clist_init(&map->glyphs); 1400 {
1390 eina_hash_direct_add(fe->glyphs_maps, &map->name, map); 1401 idxpath = _shared_string_get(fd->glyph_index_shm);
1402 datapath = _shared_string_get(fd->mempool_shm);
1403 }
1404 else
1405 datapath = name;
1406 fe->map = _glyph_map_open(fe, idxpath, datapath);
1391 } 1407 }
1392 else
1393 eina_stringshare_del(name);
1394 1408
1395 for (i = 0; i < nglyphs; i++) 1409 for (i = 0; i < nglyphs; i++)
1396 { 1410 {
@@ -1425,18 +1439,19 @@ _glyph_request_cb(void *data, const void *msg, int size)
1425 gl = fash_gl_find(fe->fash[grd->hints], idx); 1439 gl = fash_gl_find(fe->fash[grd->hints], idx);
1426 if (gl) 1440 if (gl)
1427 { 1441 {
1428 gl->map = map; 1442 gl->map = fe->map;
1429 gl->offset = offset; 1443 gl->offset = offset;
1430 gl->size = glsize; 1444 gl->size = glsize;
1431 gl->base.bitmap.rows = rows; 1445 gl->base.bitmap.rows = rows;
1432 gl->base.bitmap.width = width; 1446 gl->base.bitmap.width = width;
1433 gl->base.bitmap.pitch = pitch; 1447 gl->base.bitmap.pitch = pitch;
1434 gl->base.bitmap.buffer = map->data + gl->offset; 1448 gl->base.bitmap.buffer = (unsigned char *)
1449 fe->map->mempool.data + gl->offset;
1435 gl->base.bitmap.num_grays = num_grays; 1450 gl->base.bitmap.num_grays = num_grays;
1436 gl->base.bitmap.pixel_mode = pixel_mode; 1451 gl->base.bitmap.pixel_mode = pixel_mode;
1437 gl->rid = 0; 1452 gl->rid = 0;
1438 1453
1439 eina_clist_add_head(&map->glyphs, &gl->map_entry); 1454 eina_clist_add_head(&fe->map->glyphs, &gl->map_entry);
1440 } 1455 }
1441 } 1456 }
1442 1457
@@ -1668,8 +1683,6 @@ evas_cserve2_font_glyph_bitmap_get(Font_Entry *fe, unsigned int idx, Font_Hint_F
1668 1683
1669// Fast access to shared index tables 1684// Fast access to shared index tables
1670 1685
1671static Eina_Bool _shared_index_remap_check(Shared_Index *si, int elemsize);
1672
1673static Eina_Bool 1686static Eina_Bool
1674_string_index_refresh(void) 1687_string_index_refresh(void)
1675{ 1688{