evas/cserve2: Drop pre-emptive load of large images
authorJean-Philippe Andre <jp.andre@samsung.com>
Thu, 5 Sep 2013 08:44:10 +0000 (17:44 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 28 Oct 2013 06:47:15 +0000 (15:47 +0900)
When the image is too large, let's not preload it unless
specifically requested by the application.

Value 320x320 is completely arbitrary.

src/bin/evas/evas_cserve2.h
src/bin/evas/evas_cserve2_cache.c
src/bin/evas/evas_cserve2_requests.c
src/bin/evas/evas_cserve2_shm_debug.c

index fda088f..3b0ec15 100644 (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);
index 83923d4..30f4cf5 100644 (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)
 {
index ab63db8..9a8eb2f 100644 (file)
@@ -289,6 +289,38 @@ cserve2_request_cancel_all(Slave_Request *req, Error_Type err)
 }
 
 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)
 {
    DBG("Initializing requests.");
index 49bae20..8828646 100644 (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);