Font_Source *src;
void *ft; // Font_Info
Fash_Glyph2 *glyph_entries[3]; // Fast access to the Glyph_Entry objects
- Shared_Array *glyph_datas; // Contains the Glyph_Data objects
unsigned int nglyphs;
Eina_Bool unused : 1;
Shared_Mempool *mempool; // Contains the rendered glyphs
static unsigned int _generation_id = 0;
static unsigned int _entry_id = 0;
-static unsigned int _glyph_id = 0;
static unsigned int _font_data_id = 0;
static unsigned int _freed_file_entry_count = 0;
static unsigned int _freed_image_entry_count = 0;
}
static Glyph_Data *
-_glyph_data_find(Shared_Array *sa, unsigned int glyph_id)
+_glyph_data_find(Shared_Mempool *sm, unsigned int glyph_id)
{
Glyph_Data *gldata;
+ Shared_Array *sa;
+ sa = cserve2_shared_mempool_index_get(sm);
gldata = cserve2_shared_array_item_data_find(sa, &glyph_id,
_shm_object_id_cmp_cb);
if (!gldata)
static int
_font_entry_memory_usage_get(Font_Entry *fe)
{
- int size;
+ int size = sizeof(Font_Entry);
if (!fe) return 0;
- if (!fe->mempool && !fe->glyph_datas)
- return 0;
+ if (!fe->mempool)
+ return size;
- size = cserve2_shared_mempool_size_get(fe->mempool);
- size += cserve2_shared_array_map_size_get(fe->glyph_datas);
+ size += cserve2_shared_mempool_size_get(fe->mempool);
size += fe->nglyphs * sizeof(Glyph_Entry);
return size;
for (k = 0; k < 3; k++)
fash_gl_free(fe->glyph_entries[k]);
- cserve2_shared_array_del(fe->glyph_datas);
cserve2_shared_mempool_del(fe->mempool);
cserve2_font_ft_free(fe->ft);
fe->src->refcount--;
if (!gl || !gl->fe) return;
- gldata = _glyph_data_find(gl->fe->glyph_datas, gl->gldata_id);
+ gldata = _glyph_data_find(gl->fe->mempool, gl->gldata_id);
if (gldata)
{
- cserve2_shared_string_del(gldata->shm_id);
+ cserve2_shared_string_del(gldata->mempool_id);
gldata->refcount--;
}
free(gl);
_glyphs_loaded_msg_create(Glyphs_Request *req, int *resp_size)
{
Msg_Font_Glyphs_Loaded *msg;
+ Shared_Array *sa;
unsigned int size;
const char *shmname, *idxname;
unsigned int shmname_size, idxname_size;
char *response, *buf;
shmname = cserve2_shared_mempool_name_get(req->fe->mempool);
+ if (!shmname) return NULL;
shmname_size = strlen(shmname) + 1;
- idxname = cserve2_shared_array_name_get(req->fe->glyph_datas);
+ sa = cserve2_shared_mempool_index_get(req->fe->mempool);
+ idxname = cserve2_shared_array_name_get(sa);
+ if (!idxname) return NULL;
idxname_size = strlen(idxname) + 1;
size = sizeof(Msg_Font_Glyphs_Loaded);
Glyph_Data *gldata;
ge = req->answer[k];
- gldata = _glyph_data_find(ge->fe->glyph_datas, ge->gldata_id);
+ gldata = _glyph_data_find(ge->fe->mempool, ge->gldata_id);
if (!gldata)
{
ERR("Glyph data not found for %d", ge->gldata_id);
memcpy(buf, &gldata->index, sizeof(int));
buf += sizeof(int);
- memcpy(buf, &gldata->shm_id, sizeof(string_t));
+ memcpy(buf, &gldata->mempool_id, sizeof(string_t));
buf += sizeof(string_t);
memcpy(buf, &gldata->offset, sizeof(int));
buf += sizeof(int);
{
Font_Entry *fe = req->fe;
Shared_Mempool *mempool = msg->mempool;
+ Shared_Array *index;
unsigned int j, hint;
- string_t shm_id = 0;
+ string_t shm_id;
Font_Data *fd;
if (!msg->nglyphs)
DBG("Font memory usage [begin]: %d / %d", font_mem_usage, max_font_usage);
cserve2_shared_mempool_generation_id_set(mempool, _generation_id);
- if (!fe->glyph_datas)
+ index = cserve2_shared_mempool_index_get(mempool);
+
+ if (!fd->glyph_index_shm)
{
- fe->glyph_datas = cserve2_shared_array_new(GLYPH_INDEX_ARRAY_TAG,
- _generation_id,
- sizeof(Glyph_Data), 0);
- font_mem_usage += cserve2_shared_array_map_size_get(fe->glyph_datas);
- fd->glyph_index_shm = cserve2_shared_string_add(
- cserve2_shared_array_name_get(fe->glyph_datas));
+ fd->glyph_index_shm = cserve2_shared_string_add
+ (cserve2_shared_array_name_get(index));
}
shm_id = cserve2_shared_string_add(cserve2_shared_mempool_name_get(mempool));
gl = fash_gl_find(fe->glyph_entries[hint], msg->glyphs[j].index);
if (!gl)
{
- int glyph_id, orig_mapsize, new_mapsize;
Glyph_Data *gldata;
- orig_mapsize = cserve2_shared_array_map_size_get(fe->glyph_datas);
-
- glyph_id = cserve2_shared_array_item_new(fe->glyph_datas);
- gldata = cserve2_shared_array_item_data_get(fe->glyph_datas,
- glyph_id);
+ gldata = _glyph_data_find(mempool, msg->glyphs[j].buffer_id);
if (!gldata)
{
- ERR("Could not create new Glyph_Data!");
+ ERR("Could not find Glyph_Data %d", msg->glyphs[j].buffer_id);
// TODO: Return error?
continue;
}
gl = calloc(1, sizeof(*gl));
gl->fe = fe;
- gl->gldata_id = ++_glyph_id;
+ gl->gldata_id = gldata->id;
- gldata->refcount = 1;
- gldata->id = gl->gldata_id;
+ gldata->mempool_id = cserve2_shared_string_ref(shm_id);
gldata->index = msg->glyphs[j].index;
- gldata->shm_id = cserve2_shared_string_ref(shm_id);
- gldata->buffer_id = msg->glyphs[j].buffer_id;
- gldata->offset = msg->glyphs[j].offset; // TODO: Remove?
+ gldata->offset = msg->glyphs[j].offset;
gldata->size = msg->glyphs[j].size;
gldata->rows = msg->glyphs[j].rows;
gldata->width = msg->glyphs[j].width;
fe->nglyphs++;
fash_gl_add(fe->glyph_entries[hint], gldata->index, gl);
- new_mapsize = cserve2_shared_array_map_size_get(fe->glyph_datas);
- font_mem_usage += new_mapsize - orig_mapsize;
font_mem_usage += sizeof(*gl);
}
req->answer[req->nanswer++] = gl;
}
-
cserve2_shared_string_del(shm_id);
#ifdef DEBUG_LOAD_TIME
Font_Entry *fe = data;
Msg_Stats *msg = fdata;
unsigned int shmsize;
+ Shared_Array *sa;
msg->fonts.fonts_loaded++;
if (fe->unused) msg->fonts.fonts_unused++;
msg->fonts.real_size += shmsize;
if (fe->unused) msg->fonts.unused_size += shmsize;
- cserve2_shared_array_foreach(fe->glyph_datas,
- EINA_EACH_CB(_font_requested_size_cb), msg);
+ sa = cserve2_shared_mempool_index_get(fe->mempool);
+ if (sa)
+ {
+ cserve2_shared_array_foreach
+ (sa, EINA_EACH_CB(_font_requested_size_cb), msg);
+ }
#ifdef DEBUG_LOAD_TIME
// accounting fonts load time
unsigned int len, k, nglyphs;
const char *str;
char *nglyphs_pos;
+ Shared_Array *index = NULL;
// file
str = cserve2_shared_string_get(fe->src->file);
buf += sizeof(int);
// glyph shared index and mempool
- if (fe->glyph_datas)
- eina_strlcpy(buf, cserve2_shared_array_name_get(fe->glyph_datas), 64);
- else
- memset(buf, 0, 64);
- buf += 64;
-
if (fe->mempool)
- eina_strlcpy(buf, cserve2_shared_mempool_name_get(fe->mempool), 64);
+ {
+ index = cserve2_shared_mempool_index_get(fe->mempool);
+ eina_strlcpy(buf, cserve2_shared_mempool_name_get(fe->mempool), 64);
+ buf += 64;
+ eina_strlcpy(buf, cserve2_shared_array_name_get(index), 64);
+ buf += 64;
+ }
else
- memset(buf, 0, 64);
- buf += 64;
+ {
+ memset(buf, 0, 128);
+ buf += 128;
+ }
// skip nglyphs for now...
nglyphs_pos = buf;
buf += sizeof(int);
nglyphs = 0;
- for (k = 0; k < fe->nglyphs; k++)
+ if (index)
{
- Glyph_Data *gd = cserve2_shared_array_item_data_get(fe->glyph_datas, k);
- if (!gd || !gd->id) break;
+ for (k = 0; k < fe->nglyphs; k++)
+ {
+ Glyph_Data *gd = cserve2_shared_array_item_data_get(index, k);
+ if (!gd || !gd->id) break;
- nglyphs++;
- memcpy(buf, gd, sizeof(*gd));
- buf += sizeof(*gd);
+ nglyphs++;
+ memcpy(buf, gd, sizeof(*gd));
+ buf += sizeof(*gd);
+ }
}
// write real value of nglyphs
}
static Shared_Index *
-_shared_index_new(int tag, int generation_id)
+_shared_index_new(int tag, int index_elemsize, int generation_id)
{
Shared_Index *si;
Index_Entry *ie;
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(index_elemsize >= 0, NULL);
+
si = calloc(1, sizeof(Shared_Index));
if (!si) return NULL;
- si->sa = cserve2_shared_array_new(tag, generation_id, sizeof(Index_Entry), 0);
+ if (!index_elemsize)
+ index_elemsize = sizeof(Index_Entry);
+
+ si->sa = cserve2_shared_array_new(tag, generation_id, index_elemsize, 0);
if (!si->sa)
{
free(si);
// Shared memory pool
Shared_Mempool *
-cserve2_shared_mempool_new(int indextag, int generation_id, int initsize)
+cserve2_shared_mempool_new(int indextag, int index_elemsize,
+ int generation_id, int initsize)
{
Shared_Mempool *sm;
size_t mapping_size;
- if (initsize < 0) return NULL;
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(initsize >= 0, NULL);
+ EINA_SAFETY_ON_FALSE_RETURN_VAL(index_elemsize >= 0, NULL);
sm = calloc(1, sizeof(Shared_Mempool));
if (!sm) return NULL;
return NULL;
}
- sm->index = _shared_index_new(indextag, generation_id);
+ sm->index = _shared_index_new(indextag, index_elemsize, generation_id);
if (!sm->index)
{
_shared_data_shm_del(sm->ds);
return sm;
}
+Shared_Array *
+cserve2_shared_mempool_index_get(Shared_Mempool *sm)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(sm, NULL);
+ return sm->index->sa;
+}
+
static void
_shared_mempool_block_del(Eina_Rbtree *node, void *data EINA_UNUSED)
{
int ifaketag = STRING_MEMPOOL_FAKETAG;
DBG("Initializing shared index");
- _string_mempool = cserve2_shared_mempool_new(STRING_INDEX_ARRAY_TAG, 0, 0);
+ _string_mempool = cserve2_shared_mempool_new(STRING_INDEX_ARRAY_TAG, 0, 0, 0);
_string_entries = eina_hash_string_djb2_new(NULL);
memcpy(faketag, &ifaketag, sizeof(int));