evas/cserve2: Add basic font search when a font load is

requested.
This will only look for fonts already loaded before, no new fonts will
be loaded.



SVN revision: 71365
This commit is contained in:
Rafael Antognolli 2012-05-23 18:10:39 +00:00
parent c0f46df5d3
commit 44ba936c9c
3 changed files with 91 additions and 3 deletions

View File

@ -47,6 +47,9 @@ struct _Client {
struct {
Eina_Hash *referencing; // indexed by client image id
} images;
struct {
Eina_List *referencing;
} fonts;
};
typedef struct _Client Client;
@ -171,6 +174,8 @@ void cserve2_cache_image_load(Client *client, unsigned int client_image_id, unsi
void cserve2_cache_image_preload(Client *client, unsigned int client_image_id, unsigned int rid);
void cserve2_cache_image_unload(Client *client, unsigned int client_image_id);
int cserve2_cache_font_load(Client *client, const char *name, unsigned int namelen, unsigned int rend_flags, unsigned int hint, unsigned int size, unsigned int dpi, unsigned int rid);
void cserve2_cache_requests_process(void);
void cserve2_cache_requests_response(Slave_Command type, void *msg, void *data);

View File

@ -233,6 +233,22 @@ _image_preloaded_send(Client *client, unsigned int rid)
cserve2_client_send(client, &msg, size);
}
static void
_font_loaded_send(Client *client, Font_Entry *fe __UNUSED__, unsigned int rid)
{
int size;
Msg_Font_Loaded msg;
DBG("Sending FONT_LOADED reply for RID: %d.", rid);
memset(&msg, 0, sizeof(msg));
msg.base.rid = rid;
msg.base.type = CSERVE2_FONT_LOADED;
size = sizeof(msg);
cserve2_client_send(client, &size, sizeof(size));
cserve2_client_send(client, &msg, size);
}
static void *
_open_request_build(File_Data *f, int *bufsize)
{
@ -893,6 +909,11 @@ _entry_reference_del(Entry *entry, Reference *ref)
else
_entry_unused_push(ientry);
}
else if (entry->type == CSERVE2_FONT_ENTRY)
{
Font_Entry *fe = (Font_Entry *)entry;
eina_hash_del_by_key(font_entries, fe);
}
else
ERR("Wrong type of entry.");
@ -930,20 +951,36 @@ _entry_free_cb(void *data)
_entry_reference_del(entry, ref);
}
static void
_font_entry_reference_del(Client *client, Reference *ref)
{
Entry *entry = ref->entry;
_entry_reference_del(entry, ref);
}
void
cserve2_cache_client_new(Client *client)
{
client->files.referencing = eina_hash_int32_new(_entry_free_cb);
client->images.referencing = eina_hash_int32_new(_entry_free_cb);
client->fonts.referencing = NULL;
}
void
cserve2_cache_client_del(Client *client)
{
Reference *ref;
// will call _entry_free_cb() for every entry
eina_hash_free(client->images.referencing);
// will call _entry_free_cb() for every entry
eina_hash_free(client->files.referencing);
EINA_LIST_FREE(client->fonts.referencing, ref)
{
_font_entry_reference_del(client, ref);
}
}
static Image_Data *
@ -1031,6 +1068,26 @@ _file_changed_cb(const char *path __UNUSED__, Eina_Bool deleted __UNUSED__, void
eina_hash_del_by_key(file_watch, fw->path);
}
static Font_Entry *
_cserve2_font_entry_find(const char *name, unsigned int namelen, unsigned int size, unsigned int rend_flags, unsigned int hint, unsigned int dpi)
{
Font_Entry tmp_fe;
Font_Source tmp_fs;
Font_Entry *fe;
tmp_fs.name = eina_stringshare_add_length(name, namelen);
tmp_fe.src = &tmp_fs;
tmp_fe.size = size;
tmp_fe.rend_flags = rend_flags;
tmp_fe.hint = hint;
tmp_fe.dpi = dpi;
fe = eina_hash_find(font_entries, &tmp_fe);
eina_stringshare_del(tmp_fs.name);
return fe;
}
int
cserve2_cache_file_open(Client *client, unsigned int client_file_id, const char *path, const char *key, unsigned int rid)
{
@ -1321,6 +1378,29 @@ cserve2_cache_image_unload(Client *client, unsigned int client_image_id)
eina_hash_del_by_key(client->images.referencing, &client_image_id);
}
int
cserve2_cache_font_load(Client *client, const char *name, unsigned int namelen, unsigned int rend_flags, unsigned int hint, unsigned int size, unsigned int dpi, unsigned int rid)
{
Reference *ref;
Font_Entry *fe = _cserve2_font_entry_find(name, namelen, size,
rend_flags, hint, dpi);
if (fe)
{
DBG("found font entry %s, rendflags: %d, hint: %d, size: %d, dpi: %d",
name, rend_flags, hint, size, dpi);
ref = _entry_reference_add((Entry *)fe, client, 0);
client->fonts.referencing = eina_list_append(
client->fonts.referencing, ref);
_font_loaded_send(client, fe, rid);
return 0;
}
return -1;
}
void
cserve2_cache_requests_response(Slave_Command type, void *msg, void *data)
{

View File

@ -270,15 +270,18 @@ static void
_cserve2_client_font_load(Client *client)
{
Msg_Font_Load *msg = (Msg_Font_Load *)client->msg.buf;
char fontpath[PATH_MAX];
char name[PATH_MAX];
memcpy(fontpath, msg + 1, msg->pathlen);
memcpy(name, msg + 1, msg->pathlen);
INF("Received %s command: RID=%d",
(msg->base.type == CSERVE2_FONT_LOAD) ? "FONT_LOAD" : "FONT_UNLOAD",
msg->base.rid);
INF("Font: %s, rend_flags: %d, hint: %d, size: %d, dpi: %d",
fontpath, msg->rend_flags, msg->hint, msg->size, msg->dpi);
name, msg->rend_flags, msg->hint, msg->size, msg->dpi);
cserve2_cache_font_load(client, name, msg->pathlen, msg->rend_flags,
msg->hint, msg->size, msg->dpi, msg->base.rid);
}
static void