edje: edje_cc will now only store and encore needed image.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 25 Jan 2012 09:07:36 +0000 (09:07 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 25 Jan 2012 09:07:36 +0000 (09:07 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@67524 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
NEWS
src/bin/edje_cc.h
src/bin/edje_cc_handlers.c
src/bin/edje_cc_out.c

index 7a862f1..59f4566 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2012-01-24  Cedric Bail
 
        * Filter should only be valid once all program affecting there part are done.
+
+2012-01-25  Cedric Bail
+
+       * Only store the image used by active group.
diff --git a/NEWS b/NEWS
index bf529dc..018ab72 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Improvements:
     * reduce number of call to stat during edje_object_file_set.
     * unswallow object about to be swallowed if necessary.
     * Lua scripts now more resilient against API changes.
+    * edje_cc only store the image activelly used in an edje file.
 
 Changes since Edje 1.0.0:
 -------------------------
index d0c6d22..94fe90e 100644 (file)
@@ -147,6 +147,7 @@ void    data_queue_anonymous_lookup(Edje_Part_Collection *pc, Edje_Program *ep,
 void    data_queue_copied_anonymous_lookup(Edje_Part_Collection *pc, int *src, int *dest);
 void    data_queue_image_lookup(char *name, int *dest, Eina_Bool *set);
 void    data_queue_copied_image_lookup(int *src, int *dest, Eina_Bool *set);
+void    data_queue_image_remove(int *dest, Eina_Bool *set);
 void    data_queue_part_slave_lookup(int *master, int *slave);
 void    data_queue_image_slave_lookup(int *master, int *slave);
 void    data_queue_spectrum_lookup(char *name, int *dest);
index 2f0fada..679dfdb 100644 (file)
@@ -2156,7 +2156,7 @@ st_collections_group_name(void)
        Edje_Part_Collection *pc;
        Eina_List *l;
        Code *cd;
-       int i = 0;
+       unsigned int i = 0;
 
        pc = eina_list_nth(edje_collections, older->id);
        cd = eina_list_nth(codes, older->id);
@@ -2173,6 +2173,23 @@ st_collections_group_name(void)
             if (older) older->id = pc->id;
             else if (pc->part == current_pc->part) current_de->id = pc->id;
          }
+
+       for (i = 0; i < pc->parts_count; ++i)
+         {
+             Edje_Part_Description_Image *ed;
+             unsigned int j;
+
+             if (pc->parts[i]->type != EDJE_PART_TYPE_IMAGE)
+               continue ;
+
+             ed = (Edje_Part_Description_Image*) &pc->parts[i];
+
+             data_queue_image_remove(&(ed->image.id), &(ed->image.set));
+
+             for (j = 0; j < ed->image.tweens_count; ++j)
+               data_queue_image_remove(&(ed->image.tweens[ed->image.tweens_count - 1]->id),
+                                       &(ed->image.tweens[ed->image.tweens_count - 1]->set));
+         }
      }
 
    eina_hash_direct_add(edje_file->collection, current_de->entry, current_de);
index 5050ad4..f994af3 100644 (file)
@@ -102,7 +102,7 @@ struct _Code_Lookup
    Eina_Bool set;
 };
 
-static void data_process_string(Edje_Part_Collection *pc, const char *prefix, char *s, void (*func)(Edje_Part_Collection *pc, char *name, char *ptr, int len));
+static void data_process_string(Edje_Part_Collection *pc, const char *prefix, char *s, void (*func)(Edje_Part_Collection *pc, char *name, charptr, int len));
 
 Edje_File *edje_file = NULL;
 Eina_List *edje_collections = NULL;
@@ -500,7 +500,8 @@ data_write_images(Eet_File *ef, int *image_num, int *input_bytes, int *input_raw
          {
             img = &edje_file->image_dir->entries[i];
 
-            if (img->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL)
+            if (img->source_type == EDJE_IMAGE_SOURCE_TYPE_EXTERNAL
+                 || img->entry == NULL)
               {
               }
             else
@@ -1550,6 +1551,22 @@ data_queue_image_lookup(char *name, int *dest, Eina_Bool *set)
 }
 
 void
+data_queue_image_remove(int *dest, Eina_Bool *set)
+{
+   Eina_List *l;
+   Image_Lookup *il;
+
+   EINA_LIST_FOREACH(image_lookups, l, il)
+     {
+        if (il->dest == dest && il->set == set)
+          {
+             image_lookups = eina_list_remove_list(image_lookups, l);
+             return ;
+          }
+     }
+}
+
+void
 data_queue_copied_image_lookup(int *src, int *dest, Eina_Bool *set)
 {
    Eina_List *l;
@@ -1603,6 +1620,7 @@ data_process_lookups(void)
    Group_Lookup *group;
    Image_Lookup *image;
    Eina_List *l;
+   Eina_Hash *images_in_use;
    void *data;
 
    EINA_LIST_FOREACH(edje_collections, l, pc)
@@ -1738,13 +1756,15 @@ data_process_lookups(void)
         free(group);
      }
 
+   images_in_use = eina_hash_string_superfast_new(NULL);
+
    EINA_LIST_FREE(image_lookups, image)
      {
-       Edje_Image_Directory_Entry *de;
        Eina_Bool find = EINA_FALSE;
 
        if (edje_file->image_dir)
          {
+             Edje_Image_Directory_Entry *de;
             unsigned int i;
 
             for (i = 0; i < edje_file->image_dir->entries_count; ++i)
@@ -1760,6 +1780,9 @@ data_process_lookups(void)
                         *(image->dest) = de->id;
                       *(image->set) = EINA_FALSE;
                       find = EINA_TRUE;
+
+                       if (!eina_hash_find(images_in_use, image->name))
+                         eina_hash_direct_add(images_in_use, de->entry, de);
                       break;
                    }
               }
@@ -1778,6 +1801,9 @@ data_process_lookups(void)
                           *(image->dest) = set->id;
                           *(image->set) = EINA_TRUE;
                           find = EINA_TRUE;
+
+                           if (!eina_hash_find(images_in_use, image->name))
+                             eina_hash_direct_add(images_in_use, set->name, set);
                           break;
                        }
                   }
@@ -1795,6 +1821,54 @@ data_process_lookups(void)
        free(image);
      }
 
+   if (edje_file->image_dir)
+     {
+       Edje_Image_Directory_Entry *de;
+        Edje_Image_Directory_Set *set;
+        unsigned int i;
+
+        for (i = 0; i < edje_file->image_dir->entries_count; ++i)
+          {
+             de = edje_file->image_dir->entries + i;
+
+             if (de->entry && eina_hash_find(images_in_use, de->entry))
+               continue ;
+
+             if (verbose)
+               {
+                  printf("%s: Image '%s' in ressource 'edje/image/%i' will not be included as it is unused.\n", progname, de->entry, de->id);
+               }
+             else
+               {
+                  INF("Image '%s' in ressource 'edje/image/%i' will not be included as it is unused.", de->entry, de->id);
+               }
+
+             de->entry = NULL;
+          }
+
+        for (i = 0; i < edje_file->image_dir->sets_count; ++i)
+          {
+             set = edje_file->image_dir->sets + i;
+
+             if (set->name && eina_hash_find(images_in_use, set->name))
+               continue ;
+
+             if (verbose)
+               {
+                  printf("%s: Set '%s' will not be included as it is unused.\n", progname, set->name);
+               }
+             else
+               {
+                  INF("Set '%s' will not be included as it is unused.", set->name);
+               }
+
+             set->name = NULL;
+             set->entries = NULL;
+          }
+     }
+
+   eina_hash_free(images_in_use);
+
    EINA_LIST_FREE(part_slave_lookups, data)
      free(data);