evas/cserve2: Drop pre-emptive load of large images

When the image is too large, let's not preload it unless
specifically requested by the application.

Value 320x320 is completely arbitrary.
This commit is contained in:
Jean-Philippe Andre 2013-09-05 17:44:10 +09:00
parent 97d9fab704
commit 85cd382725
4 changed files with 59 additions and 3 deletions

View File

@ -331,6 +331,8 @@ void cserve2_request_cancel(Slave_Request *req, Client *client, Error_Type err);
void cserve2_request_cancel_all(Slave_Request *req, Error_Type err);
void cserve2_requests_init(void);
void cserve2_requests_shutdown(void);
void cserve2_request_dependents_drop(Slave_Request *req, Slave_Request_Type type);
void cserve2_entry_request_drop(void *data, Slave_Request_Type type);
void cserve2_font_init(void);
void cserve2_font_shutdown(void);

View File

@ -154,6 +154,8 @@ static int unused_mem_usage = 0;
static int max_font_usage = 10 * 4 * 1024; /* in kbytes */
static int font_mem_usage = 0;
#define MAX_PREEMPTIVE_LOAD_SIZE (320*320*4)
#ifdef DEBUG_LOAD_TIME
static int
_timeval_sub(const struct timeval *tv2, const struct timeval *tv1)
@ -603,8 +605,10 @@ static Msg_Opened *
_open_request_response(Entry *entry, Slave_Msg_Image_Opened *resp, int *size)
{
File_Data *fd;
Slave_Request *req;
_entry_load_finish(entry);
req = entry->request;
entry->request = NULL;
fd = _file_data_find(entry->id);
@ -629,9 +633,26 @@ _open_request_response(Entry *entry, Slave_Msg_Image_Opened *resp, int *size)
}
fd->valid = EINA_TRUE;
// If the image is too large, cancel pre-emptive load.
if (fd->w * fd->h * 4 >= MAX_PREEMPTIVE_LOAD_SIZE)
{
DBG("Not pre-loading this image ");
cserve2_request_dependents_drop(req, CSERVE2_REQ_IMAGE_SPEC_LOAD);
}
return _image_opened_msg_create(fd, size);
}
void
cserve2_entry_request_drop(void *data, Slave_Request_Type type EINA_UNUSED)
{
Entry *e = data;
if (!e) return;
e->request = NULL;
}
static void
_request_failed(Entry *e, Error_Type type EINA_UNUSED)
{

View File

@ -288,6 +288,38 @@ cserve2_request_cancel_all(Slave_Request *req, Error_Type err)
free(req);
}
void
cserve2_request_dependents_drop(Slave_Request *req, Slave_Request_Type type)
{
Slave_Request *dep;
Eina_List *l, *l_next;
if (type != CSERVE2_REQ_IMAGE_SPEC_LOAD)
{
CRIT("Only CSERVE2_REQ_IMAGE_SPEC_LOAD is supported.");
return;
}
EINA_LIST_FOREACH_SAFE(req->dependents, l, l_next, dep)
{
if (dep->type == type)
{
req->dependents = eina_list_remove_list(req->dependents, l);
if (dep->processing)
dep->cancelled = EINA_TRUE;
else
{
cserve2_entry_request_drop(dep->data, type);
requests[type].waiting = eina_inlist_remove(
requests[type].waiting, EINA_INLIST_GET(dep));
dep->funcs->msg_free(dep->msg, dep->data);
free(dep);
}
}
}
}
void
cserve2_requests_init(void)
{

View File

@ -467,13 +467,14 @@ _images_all_print_full(void)
printf("Refcount %d\n", id->refcount);
printf("Sparse alpha %s\n"
"Unused: %s\n"
"Load requested: %s\n",
"Load requested: %s\n"
"Valid: %s\n",
id->alpha_sparse ? "YES" : "NO",
id->unused ? "YES" : "NO",
id->doload ? "YES" : "NO");
id->doload ? "YES" : "NO",
id->valid ? "YES" : "NO");
printf("Shm Path: '%s'\n",
id->shm_id ? _shared_string_get(id->shm_id) : "");
printf("LoadOpts: width %d\n", id->opts.w);
printf(" height %d\n", id->opts.h);
printf(" degree %d\n", id->opts.degree);