raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=76244d89a75c0a465c3b4eb63d642b6ad14a3d74

commit 76244d89a75c0a465c3b4eb63d642b6ad14a3d74
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Mon Feb 13 15:29:09 2017 +0900

    vpath file - add a keey property to know if obj should be kept around
    
    if its a file downloading (to a tmp location) or a zip/tar/whatever
    file being extracted also to a tmp location and that tmp file needs to
    be removed after ...you need to keep the obj around to know when to
    delete the file. this makes the keeping optional and you query if the
    vpath obj is meant to be kept or not. if it's not it's safe to del
    immediately.
    
    this cuts down 1 obj per image obj/edje obj when generally unused.
    save some mem.
---
 src/lib/edje/edje_smart.c                |  5 ++++
 src/lib/efl/interfaces/efl_vpath_core.c  |  5 ++++
 src/lib/efl/interfaces/efl_vpath_file.c  | 13 +++++++++++
 src/lib/efl/interfaces/efl_vpath_file.eo |  8 +++++++
 src/lib/emotion/emotion_smart.c          | 39 +++++++++++++++++++++++++-------
 src/lib/evas/canvas/efl_canvas_image.c   |  8 ++++++-
 src/lib/evas/canvas/evas_object_image.c  |  7 ++++++
 7 files changed, 76 insertions(+), 9 deletions(-)

diff --git a/src/lib/edje/edje_smart.c b/src/lib/edje/edje_smart.c
index b769f59..583e714 100644
--- a/src/lib/edje/edje_smart.c
+++ b/src/lib/edje/edje_smart.c
@@ -395,6 +395,11 @@ _edje_object_efl_file_file_set(Eo *obj, Edje *ed, const 
char *file, const char *
         file2 = efl_vpath_file_result_get(ed->file_obj);
 
         f = eina_file_open(file2, EINA_FALSE);
+        if ((ed->file_obj) && (!efl_vpath_file_keep_get(ed->file_obj)))
+          {
+             efl_del(ed->file_obj);
+             ed->file_obj = NULL;
+          }
         if (!f)
           {
              efl_del(ed->file_obj);
diff --git a/src/lib/efl/interfaces/efl_vpath_core.c 
b/src/lib/efl/interfaces/efl_vpath_core.c
index 0e34378..f3bff42 100644
--- a/src/lib/efl/interfaces/efl_vpath_core.c
+++ b/src/lib/efl/interfaces/efl_vpath_core.c
@@ -404,6 +404,11 @@ _efl_vpath_core_efl_vpath_fetch(Eo *obj, 
Efl_Vpath_Core_Data *pd EINA_UNUSED, co
                     }
                }
           }
+        // XXX: handle file:// urls locally...
+        // XXX: if its a remote url or zip file etc. where we need to
+        // keep tmp file around then we need to set keep to true
+        // efl_vpath_file_keept_set(file, EINA_TRUE);
+
         // file:/// <- local file path uri
         // file://localhost/ <- local file path uri
         // file://hostname/ <- remove file path uri
diff --git a/src/lib/efl/interfaces/efl_vpath_file.c 
b/src/lib/efl/interfaces/efl_vpath_file.c
index 37613fc..3e09882 100644
--- a/src/lib/efl/interfaces/efl_vpath_file.c
+++ b/src/lib/efl/interfaces/efl_vpath_file.c
@@ -10,6 +10,7 @@ struct _Efl_Vpath_File_Data
    const char *path;
    const char *result;
    Eina_Bool called : 1;
+   Eina_Bool keep : 1;
 };
 
 EOLIAN static void
@@ -36,6 +37,18 @@ _efl_vpath_file_result_get(Eo *obj EINA_UNUSED, 
Efl_Vpath_File_Data *pd)
    return pd->result;
 }
 
+EOLIAN static void
+_efl_vpath_file_keep_set(Eo *obj EINA_UNUSED, Efl_Vpath_File_Data *pd, 
Eina_Bool keep)
+{
+   pd->keep = keep;
+}
+
+EOLIAN static Eina_Bool
+_efl_vpath_file_keep_get(Eo *obj EINA_UNUSED, Efl_Vpath_File_Data *pd)
+{
+   return pd->keep;
+}
+
 EOLIAN static Eina_Bool
 _efl_vpath_file_do(Eo *obj EINA_UNUSED, Efl_Vpath_File_Data *pd)
 {
diff --git a/src/lib/efl/interfaces/efl_vpath_file.eo 
b/src/lib/efl/interfaces/efl_vpath_file.eo
index e061a78..1568a3e 100644
--- a/src/lib/efl/interfaces/efl_vpath_file.eo
+++ b/src/lib/efl/interfaces/efl_vpath_file.eo
@@ -32,6 +32,14 @@ class Efl.Vpath.File (Efl.Object)
              path: string; [[ The resulting destination file ]]
          }
       }
+      @property keep {
+         [[ If this object has to be kept for the usage of the result ]]
+         set {}
+         get {}
+         values {
+             keep: bool; [[ If the object neerds tobe kept around ]]
+         }
+      }
       do {
         [[ Actually begin the resolving here - emit event now or do later ]]
         return: bool; [[ Result callback already called ]]
diff --git a/src/lib/emotion/emotion_smart.c b/src/lib/emotion/emotion_smart.c
index 93cf197..96f14da 100644
--- a/src/lib/emotion/emotion_smart.c
+++ b/src/lib/emotion/emotion_smart.c
@@ -68,6 +68,8 @@ struct _Efl_Canvas_Video_Data
 
    Ecore_Job     *job;
 
+   Efl_Vpath_File *file_obj;
+
    const char *title;
 
 #ifdef HAVE_EIO
@@ -169,6 +171,11 @@ _smart_data_free(Efl_Canvas_Video_Data *sd)
    sd->save_xattr = NULL;
 #endif
 
+   if (sd->file_obj)
+     {
+        efl_del(sd->file_obj);
+        sd->file_obj = NULL;
+     }
    if (sd->engine_instance)
      {
         emotion_engine_instance_file_close(sd->engine_instance);
@@ -374,7 +381,7 @@ _efl_canvas_video_efl_file_file_set(Eo *obj EINA_UNUSED, 
Efl_Canvas_Video_Data *
    sd->video.h = 0;
    if ((file) && (file[0] != 0))
      {
-        const char *file2;
+        const char *file2 = NULL;
 
         eina_stringshare_replace(&sd->file, file);
         emotion_engine_instance_file_close(sd->engine_instance);
@@ -383,19 +390,35 @@ _efl_canvas_video_efl_file_file_set(Eo *obj EINA_UNUSED, 
Efl_Canvas_Video_Data *
         _emotion_image_data_zero(sd->obj);
         sd->open = 0;
 
-        Efl_Vpath_File *file_obj = 
efl_vpath_manager_fetch(EFL_VPATH_MANAGER_CLASS, file);
-        efl_vpath_file_do(file_obj);
-        // XXX:FIXME: allow this to be async
-        efl_vpath_file_wait(file_obj);
-        file2 = efl_vpath_file_result_get(file_obj);
+        if (sd->file_obj)
+          {
+             efl_del(sd->file_obj);
+             sd->file_obj = NULL;
+          }
+        if (file)
+          {
+             sd->file_obj = efl_vpath_manager_fetch(EFL_VPATH_MANAGER_CLASS, 
file);
+             efl_vpath_file_do(sd->file_obj);
+             // XXX:FIXME: allow this to be async
+             efl_vpath_file_wait(sd->file_obj);
+             file2 = efl_vpath_file_result_get(sd->file_obj);
+          }
 
         if (!emotion_engine_instance_file_open(sd->engine_instance, file2))
           {
              WRN("Couldn't open file=%s", sd->file);
-             efl_del(file_obj);
+             if (sd->file_obj)
+               {
+                  efl_del(sd->file_obj);
+                  sd->file_obj = NULL;
+               }
              return EINA_FALSE;
           }
-        efl_del(file_obj);
+        if ((sd->file_obj) && (!efl_vpath_file_keep_get(sd->file_obj)))
+          {
+             efl_del(sd->file_obj);
+             sd->file_obj = NULL;
+          }
         DBG("successfully opened file=%s", sd->file);
         sd->pos = 0.0;
         if (sd->play) emotion_engine_instance_play(sd->engine_instance, 0.0);
diff --git a/src/lib/evas/canvas/efl_canvas_image.c 
b/src/lib/evas/canvas/efl_canvas_image.c
index 3ebb2c9..b03808e 100644
--- a/src/lib/evas/canvas/efl_canvas_image.c
+++ b/src/lib/evas/canvas/efl_canvas_image.c
@@ -70,6 +70,8 @@ _evas_image_file_set(Eo *eo_obj, const char *file, const char 
*key)
 
    evas_object_async_block(obj);
    _evas_image_init_set(NULL, file, key, eo_obj, obj, o, &lo);
+   if (o->file_obj) efl_del(o->file_obj);
+   o->file_obj = NULL;
    file2 = o->cur->u.file;
    if (file2)
      {
@@ -82,7 +84,11 @@ _evas_image_file_set(Eo *eo_obj, const char *file, const 
char *key)
    o->engine_data = ENFN->image_load(ENDT, file2, o->cur->key, &o->load_error, 
&lo);
    o->buffer_data_set = EINA_FALSE;
    _evas_image_done_set(eo_obj, obj, o);
-
+   if ((o->file_obj) && (!efl_vpath_file_keep_get(o->file_obj)))
+     {
+        efl_del(o->file_obj);
+        o->file_obj = NULL;
+     }
    return EINA_TRUE;
 }
 
diff --git a/src/lib/evas/canvas/evas_object_image.c 
b/src/lib/evas/canvas/evas_object_image.c
index fb878c0..641e8a4 100644
--- a/src/lib/evas/canvas/evas_object_image.c
+++ b/src/lib/evas/canvas/evas_object_image.c
@@ -1312,6 +1312,8 @@ _evas_image_load(Evas_Object *eo_obj, 
Evas_Object_Protected_Data *obj, Evas_Imag
      {
         const char *file2 = o->cur->u.file;
 
+        if (o->file_obj) efl_del(o->file_obj);
+        o->file_obj = NULL;
         if (file2)
           {
              o->file_obj = efl_vpath_manager_fetch(EFL_VPATH_MANAGER_CLASS, 
file2);
@@ -1321,6 +1323,11 @@ _evas_image_load(Evas_Object *eo_obj, 
Evas_Object_Protected_Data *obj, Evas_Imag
              file2 = efl_vpath_file_result_get(o->file_obj);
           }
         o->engine_data = ENFN->image_load(ENDT, file2, o->cur->key, 
&o->load_error, &lo);
+        if ((o->file_obj) && (!efl_vpath_file_keep_get(o->file_obj)))
+          {
+             efl_del(o->file_obj);
+             o->file_obj = NULL;
+          }
      }
 
    if (o->engine_data)

-- 


Reply via email to