From c2e75544e1b8f41353cc66715e9772184c036973 Mon Sep 17 00:00:00 2001 From: Cedric BAIL Date: Fri, 3 Apr 2015 16:23:13 +0200 Subject: [PATCH] efl: move mmap API to be part of Efl_File class. --- src/lib/edje/Edje_Legacy.h | 37 ++++++++++++++++++++ src/lib/edje/edje_object.eo | 39 ++------------------- src/lib/edje/edje_smart.c | 22 ++++++++++-- src/lib/efl/interfaces/efl_file.eo | 31 +++++++++++++++++ src/lib/evas/Evas_Legacy.h | 34 ++++++++++++++++++ src/lib/evas/canvas/evas_3d_mesh.c | 33 +++++++++++++++--- src/lib/evas/canvas/evas_3d_mesh.eo | 18 ++-------- src/lib/evas/canvas/evas_image.eo | 31 ++--------------- src/lib/evas/canvas/evas_object_image.c | 29 ++++++++++++---- src/lib/evas/common/evas_model_load.c | 2 +- src/lib/evas/include/evas_private.h | 2 +- src/tests/evas/evas_test_mesh.c | 46 ++++++++++++------------- 12 files changed, 204 insertions(+), 120 deletions(-) diff --git a/src/lib/edje/Edje_Legacy.h b/src/lib/edje/Edje_Legacy.h index 0525120763..e5e980045a 100644 --- a/src/lib/edje/Edje_Legacy.h +++ b/src/lib/edje/Edje_Legacy.h @@ -212,5 +212,42 @@ Edje object */ EAPI void edje_object_file_get(const Eo *obj, const char **file, const char **group); + +/** + * + * @brief Sets the @b EDJ file (and group within it) to load an Edje + * object's contents from + * + * @return @c EINA_TRUE, on success or @c EINA_FALSE, on errors (check + * edje_object_load_error_get() after this call to get errors causes) + * + * Edje expects EDJ files, which are theming objects' descriptions and + * resources packed together in an EET file, to read Edje object + * definitions from. They usually are created with the @c .edj + * extension. EDJ files, in turn, are assembled from @b textual object + * description files, where one describes Edje objects declaratively + * -- the EDC files (see @ref edcref "the syntax" for those files). + * + * Those description files were designed so that many Edje object + * definitions -- also called @b groups (or collections) -- could be + * packed together in the same EDJ file, so that a whole + * application's theme could be packed in one file only. This is the + * reason for the @p group argument. + * + * Use this function after you instantiate a new Edje object, so that + * you can "give him life", telling where to get its contents from. + * + * @see edje_object_add() + * @see edje_object_file_get() + * @see edje_object_mmap_set() + * @since 1.8 + * + * @param[in] file The Eina.File pointing to the EDJ file to load @p from + * @param[in] group The name of the group, in @p file, which implements an +Edje object + */ +EAPI Eina_Bool edje_object_mmap_set(Eo *obj, const Eina_File *file, const char *group); + + #include "edje_object.eo.legacy.h" #include "edje_edit.eo.legacy.h" diff --git a/src/lib/edje/edje_object.eo b/src/lib/edje/edje_object.eo index ba8d9764a5..2653d72f65 100644 --- a/src/lib/edje/edje_object.eo +++ b/src/lib/edje/edje_object.eo @@ -182,43 +182,6 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File) that means the edc file is made based on scale 1.0. */ } } - mmap { - set { - /*@ - @brief Sets the @b EDJ file (and group within it) to load an Edje - object's contents from - - @return @c EINA_TRUE, on success or @c EINA_FALSE, on errors (check - edje_object_load_error_get() after this call to get errors causes) - - Edje expects EDJ files, which are theming objects' descriptions and - resources packed together in an EET file, to read Edje object - definitions from. They usually are created with the @c .edj - extension. EDJ files, in turn, are assembled from @b textual object - description files, where one describes Edje objects declaratively - -- the EDC files (see @ref edcref "the syntax" for those files). - - Those description files were designed so that many Edje object - definitions -- also called @b groups (or collections) -- could be - packed together in the same EDJ file, so that a whole - application's theme could be packed in one file only. This is the - reason for the @p group argument. - - Use this function after you instantiate a new Edje object, so that - you can "give him life", telling where to get its contents from. - - @see edje_object_add() - @see edje_object_file_get() - @see edje_object_mmap_set() - @since 1.8 */ - return: bool; - } - values { - const(Eina.File)* file; /*@ The Eina.File pointing to the EDJ file to load @p from */ - const(char)* group; /*@ The name of the group, in @p file, which implements an - Edje object */ - } - } text_change_cb { set { /*@ @@ -2414,5 +2377,7 @@ class Edje.Object (Evas.Smart_Clipped, Efl.File) Evas.Object_Smart.resize; Efl.File.file.set; Efl.File.file.get; + Efl.File.mmap.set; + Efl.File.mmap.get; } } diff --git a/src/lib/edje/edje_smart.c b/src/lib/edje/edje_smart.c index 332b9586c9..0bf8399598 100644 --- a/src/lib/edje/edje_smart.c +++ b/src/lib/edje/edje_smart.c @@ -337,7 +337,8 @@ _edje_object_efl_file_file_set(Eo *obj, Edje *_pd EINA_UNUSED, const char *file, } EOLIAN static Eina_Bool -_edje_object_mmap_set(Eo *obj, Edje *_pd EINA_UNUSED, const Eina_File *f, const char *group) +_edje_object_efl_file_mmap_set(Eo *obj, Edje *pd EINA_UNUSED, + const Eina_File *f, const char *key) { Eina_Bool ret; Eina_Array *nested; @@ -346,7 +347,7 @@ _edje_object_mmap_set(Eo *obj, Edje *_pd EINA_UNUSED, const Eina_File *f, const nested = eina_array_new(8); - if (_edje_object_file_set_internal(obj, f, group, NULL, NULL, nested)) + if (_edje_object_file_set_internal(obj, f, key, NULL, NULL, nested)) ret = EINA_TRUE; eina_array_free(nested); @@ -355,6 +356,22 @@ _edje_object_mmap_set(Eo *obj, Edje *_pd EINA_UNUSED, const Eina_File *f, const return ret; } +EOLIAN static void +_edje_object_efl_file_mmap_get(Eo *obj EINA_UNUSED, Edje *pd, + const Eina_File **f, const char **key) +{ + if (f) *f = pd->file->f; + if (key) *key = pd->group; +} + +EAPI Eina_Bool +edje_object_mmap_set(Edje_Object *obj, const Eina_File *file, const char *group) +{ + Eina_Bool ret; + + return eo_do_ret((Edje_Object *)obj, ret, efl_file_mmap_set(file, group)); +} + EAPI Eina_Bool edje_object_file_set(Eo *obj, const char *file, const char *group) { @@ -370,4 +387,3 @@ edje_object_file_get(const Eo *obj, const char **file, const char **group) } #include "edje_object.eo.c" - diff --git a/src/lib/efl/interfaces/efl_file.eo b/src/lib/efl/interfaces/efl_file.eo index 0265344c8d..887d96f408 100644 --- a/src/lib/efl/interfaces/efl_file.eo +++ b/src/lib/efl/interfaces/efl_file.eo @@ -1,6 +1,37 @@ interface Efl.File { legacy_prefix: null; properties { + mmap { + set { + /*@ + Set the source mmaped file from where an image object must fetch the real + image data (it must be an Eina_File). + + If the file supports multiple data stored in it (as Eet files do), + you can specify the key to be used as the index of the image in + this file. + + @since 1.8 */ + + return: bool; + } + get { + /*@ + Get the source mmaped file from where an image object must fetch the real + image data (it must be an Eina_File). + + If the file supports multiple data stored in it (as Eet files do), + you can get the key to be used as the index of the image in + this file. + + @since 1.10 */ + } + values { + const(Eina.File)* f; /*@ The mmaped file */ + const(char)* key; /*@ The image key in @p file (if its an Eet one), or @c + NULL, otherwise. */ + } + } file { set { /*@ diff --git a/src/lib/evas/Evas_Legacy.h b/src/lib/evas/Evas_Legacy.h index ca746f8209..e23e2ae774 100644 --- a/src/lib/evas/Evas_Legacy.h +++ b/src/lib/evas/Evas_Legacy.h @@ -1576,6 +1576,40 @@ NULL, otherwise. */ EAPI void evas_object_image_file_get(const Eo *obj, const char **file, const char **key); +/** + * + * Set the source mmaped file from where an image object must fetch the real + * image data (it must be an Eina_File). + * + * If the file supports multiple data stored in it (as Eet files do), + * you can specify the key to be used as the index of the image in + * this file. + * + * @since 1.8 + * + * @param[in] f The mmaped file + * @param[in] key The image key in @p file (if its an Eet one), or @c +NULL, otherwise. + */ +EAPI void evas_object_image_mmap_set(Eo *obj, const Eina_File *f, const char *key); + +/** + * + * Get the source mmaped file from where an image object must fetch the real + * image data (it must be an Eina_File). + * + * If the file supports multiple data stored in it (as Eet files do), + * you can get the key to be used as the index of the image in + * this file. + * + * @since 1.10 + * + * @param[out] f The mmaped file + * @param[out] key The image key in @p file (if its an Eet one), or @c +NULL, otherwise. + */ +EAPI void evas_object_image_mmap_get(const Eo *obj, const Eina_File **f, const char **key); + /** * * Save the given image object's contents to an (image) file. diff --git a/src/lib/evas/canvas/evas_3d_mesh.c b/src/lib/evas/canvas/evas_3d_mesh.c index 52a71f2d66..f055da1317 100644 --- a/src/lib/evas/canvas/evas_3d_mesh.c +++ b/src/lib/evas/canvas/evas_3d_mesh.c @@ -840,16 +840,39 @@ _evas_3d_mesh_alpha_test_enable_get(Eo *obj EINA_UNUSED, Evas_3D_Mesh_Data *pd) return pd->alpha_test_enabled; } -EOLIAN static void -_evas_3d_mesh_mmap_set(Eo *obj, Evas_3D_Mesh_Data *pd, - Eina_File *file, const char *key EINA_UNUSED) +EOLIAN static Eina_Bool +_evas_3d_mesh_efl_file_mmap_set(Eo *obj, + Evas_3D_Mesh_Data *pd, + const Eina_File *f, const char *key EINA_UNUSED) { _mesh_fini(pd); _mesh_init(pd); - if (file == NULL) return; + if (f == NULL) return EINA_FALSE; - evas_common_load_model_from_eina_file(obj, file); + evas_common_load_model_from_eina_file(obj, f); + + return EINA_TRUE; +} + +EOLIAN static void +_evas_3d_mesh_efl_file_mmap_get(Eo *obj EINA_UNUSED, + Evas_3D_Mesh_Data *pd EINA_UNUSED, + const Eina_File **f EINA_UNUSED, + const char **key EINA_UNUSED) +{ + #warning "mmap get is not implemented on Evas_3D_Mesh." + ERR("mmap get is not implemented !"); +} + +EOLIAN static void +_evas_3d_mesh_efl_file_file_get(Eo *obj EINA_UNUSED, + Evas_3D_Mesh_Data *pd EINA_UNUSED, + const char **file EINA_UNUSED, + const char **key EINA_UNUSED) +{ + #warning "file get is not implemented on Evas_3D_Mesh." + ERR("file get is not implemented !"); } EOLIAN static Eina_Bool diff --git a/src/lib/evas/canvas/evas_3d_mesh.eo b/src/lib/evas/canvas/evas_3d_mesh.eo index 784f91a257..28022ee07f 100644 --- a/src/lib/evas/canvas/evas_3d_mesh.eo +++ b/src/lib/evas/canvas/evas_3d_mesh.eo @@ -4,21 +4,6 @@ class Evas_3D_Mesh (Evas_3D_Object, Evas.Common_Interface, Efl.File) data: Evas_3D_Mesh_Data; methods { - mmap_set { - /** - * Load mesh data from Eina_File. - * - * Loading a mesh from existing Eina_File is supported. Currently, only MD2, OBJ, - * PLY and EET file formats are supported. - * - * @ingroup Evas_3D_Mesh - */ - params { - @in Eina_File* file; /*@ Eina_File with mesh data. */ - @in const(char)* key; /*@ Key in the mesh file. */ - } - } - frame_vertex_data_set { /*@ Set the vertex data of the key frame of the given mesh. @@ -540,6 +525,9 @@ class Evas_3D_Mesh (Evas_3D_Object, Evas.Common_Interface, Efl.File) Evas_3D_Object.update_notify; Evas_3D_Object.change_notify; Efl.File.file.set; + Efl.File.file.get; + Efl.File.mmap.set; + Efl.File.mmap.get; Efl.File.save; } diff --git a/src/lib/evas/canvas/evas_image.eo b/src/lib/evas/canvas/evas_image.eo index df97e32525..7071d834e2 100644 --- a/src/lib/evas/canvas/evas_image.eo +++ b/src/lib/evas/canvas/evas_image.eo @@ -663,35 +663,6 @@ class Evas.Image (Evas.Object, Efl.File, Efl.Image) void *data; /*@ The data pointer to be passed to @a func. */ } } - mmap { - set { - /*@ - Set the source mmaped file from where an image object must fetch the real - image data (it must be an Eina_File). - - If the file supports multiple data stored in it (as Eet files do), - you can specify the key to be used as the index of the image in - this file. - - @since 1.8 */ - } - get { - /*@ - Get the source mmaped file from where an image object must fetch the real - image data (it must be an Eina_File). - - If the file supports multiple data stored in it (as Eet files do), - you can get the key to be used as the index of the image in - this file. - - @since 1.10 */ - } - values { - const(Eina.File)* f; /*@ The mmaped file */ - const(char)* key; /*@ The image key in @p file (if its an Eet one), or @c - NULL, otherwise. */ - } - } data_copy { set { /*@ @@ -1094,6 +1065,8 @@ class Evas.Image (Evas.Object, Efl.File, Efl.Image) Eo.Base.dbg_info_get; Efl.File.file.set; Efl.File.file.get; + Efl.File.mmap.set; + Efl.File.mmap.get; Efl.File.save; Efl.Image.animated.get; Efl.Image.load_size.set; diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c index 90b3c49aa2..eaf17d6fd4 100644 --- a/src/lib/evas/canvas/evas_object_image.c +++ b/src/lib/evas/canvas/evas_object_image.c @@ -412,7 +412,7 @@ evas_object_image_memfile_set(Evas_Object *eo_obj, void *data, int size, char *f f = eina_file_virtualize(NULL, data, size, EINA_TRUE); if (!f) return ; - eo_do(eo_obj, evas_obj_image_mmap_set(f, key)); + eo_do(eo_obj, efl_file_mmap_set(f, key)); eina_file_close(f); } @@ -544,8 +544,10 @@ _image_done_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Evas_Image_Data *o) evas_object_change(eo_obj, obj); } -EOLIAN static void -_evas_image_mmap_set(Eo *eo_obj, Evas_Image_Data *o, const Eina_File *f, const char *key) +EOLIAN static Eina_Bool +_evas_image_efl_file_mmap_set(Eo *eo_obj, + Evas_Image_Data *o, + const Eina_File *f, const char *key) { Evas_Object_Protected_Data *obj = eo_data_scope_get(eo_obj, EVAS_OBJECT_CLASS); Evas_Image_Load_Opts lo; @@ -553,18 +555,22 @@ _evas_image_mmap_set(Eo *eo_obj, Evas_Image_Data *o, const Eina_File *f, const c if (o->cur->u.f == f) { if ((!o->cur->key) && (!key)) - return; + return EINA_FALSE; if ((o->cur->key) && (key) && (!strcmp(o->cur->key, key))) - return; + return EINA_FALSE; } evas_object_async_block(obj); _image_init_set(f, NULL, key, eo_obj, obj, o, &lo); o->engine_data = ENFN->image_mmap(ENDT, o->cur->u.f, o->cur->key, &o->load_error, &lo); _image_done_set(eo_obj, obj, o); + + return EINA_TRUE; } EOLIAN static void -_evas_image_mmap_get(Eo *eo_obj EINA_UNUSED, Evas_Image_Data *o, const Eina_File **f, const char **key) +_evas_image_efl_file_mmap_get(Eo *eo_obj EINA_UNUSED, + Evas_Image_Data *o, + const Eina_File **f, const char **key) { if (f) *f = o->cur->mmaped_source ? o->cur->u.f : NULL; @@ -4915,6 +4921,17 @@ evas_object_image_file_get(const Eo *obj, const char **file, const char **key) eo_do((Eo *) obj, efl_file_get(file, key)); } +EAPI void +evas_object_image_mmap_set(Evas_Image *obj, const Eina_File *f, const char *key) +{ + eo_do((Evas_Image *)obj, efl_file_mmap_set(f, key)); +} + +EAPI void +evas_object_image_mmap_get(const Evas_Image *obj, const Eina_File **f, const char **key) +{ + eo_do((Evas_Image *)obj, efl_file_mmap_get(f, key)); +} EAPI Eina_Bool evas_object_image_save(const Eo *obj, const char *file, const char *key, const char *flags) diff --git a/src/lib/evas/common/evas_model_load.c b/src/lib/evas/common/evas_model_load.c index bef10ba28c..959cd71bc8 100644 --- a/src/lib/evas/common/evas_model_load.c +++ b/src/lib/evas/common/evas_model_load.c @@ -65,7 +65,7 @@ evas_common_load_model_from_file(Evas_3D_Mesh *model, const char *file) } void -evas_common_load_model_from_eina_file(Evas_3D_Mesh *model, Eina_File *file) +evas_common_load_model_from_eina_file(Evas_3D_Mesh *model, const Eina_File *file) { Eina_File *e_file = eina_file_dup(file); diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h index 15b4c4bd40..a2a8093e44 100644 --- a/src/lib/evas/include/evas_private.h +++ b/src/lib/evas/include/evas_private.h @@ -1703,7 +1703,7 @@ void _evas_3d_eet_file_free(void); /* Temporary save/load functions */ void evas_common_load_model_from_file(Evas_3D_Mesh *model, const char *file); -void evas_common_load_model_from_eina_file(Evas_3D_Mesh *model, Eina_File *file); +void evas_common_load_model_from_eina_file(Evas_3D_Mesh *model, const Eina_File *file); void evas_common_save_model_to_file(Evas_3D_Mesh *model, const char *file, Evas_3D_Mesh_Frame *f); void evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file); void evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file); diff --git a/src/tests/evas/evas_test_mesh.c b/src/tests/evas/evas_test_mesh.c index 558dcfad20..440c31b28a 100644 --- a/src/tests/evas/evas_test_mesh.c +++ b/src/tests/evas/evas_test_mesh.c @@ -34,29 +34,29 @@ src2 += f2->vertices[a].element_count; \ } -#define CHECK_MESHES_IN_FOLDER(folder, ext) \ - it = eina_file_direct_ls(folder); \ - EINA_ITERATOR_FOREACH(it, file) \ - { \ - mesh = eo_add(EVAS_3D_MESH_CLASS, e); \ - mesh2 = eo_add(EVAS_3D_MESH_CLASS, e); \ - fail_if(mesh == NULL); \ - fail_if(mesh2 == NULL); \ - snprintf(buffer, PATH_MAX, "%s", ext); \ - eo_do(mesh, efl_file_set(file->path, NULL), \ - efl_file_save(buffer, NULL, NULL)); \ - eo_do(mesh2, efl_file_set(buffer, NULL)); \ - res = _compare_meshes(mesh, mesh2); \ - fail_if(res == 1); \ - eo_do(mesh, evas_3d_mesh_mmap_set(eina_file_open(file->path, 0), NULL), \ - efl_file_save(buffer, NULL, NULL)); \ - eo_do(mesh2, evas_3d_mesh_mmap_set(eina_file_open(buffer, 0), NULL)); \ - res = _compare_meshes(mesh, mesh2); \ - fail_if(res == 1); \ - eo_del(mesh2); \ - eo_del(mesh); \ - unlink(buffer); \ - } +#define CHECK_MESHES_IN_FOLDER(folder, ext) \ + it = eina_file_direct_ls(folder); \ + EINA_ITERATOR_FOREACH(it, file) \ + { \ + mesh = eo_add(EVAS_3D_MESH_CLASS, e); \ + mesh2 = eo_add(EVAS_3D_MESH_CLASS, e); \ + fail_if(mesh == NULL); \ + fail_if(mesh2 == NULL); \ + snprintf(buffer, PATH_MAX, "%s", ext); \ + eo_do(mesh, efl_file_set(file->path, NULL), \ + efl_file_save(buffer, NULL, NULL)); \ + eo_do(mesh2, efl_file_set(buffer, NULL)); \ + res = _compare_meshes(mesh, mesh2); \ + fail_if(res == 1); \ + eo_do(mesh, efl_file_mmap_set(eina_file_open(file->path, 0), NULL), \ + efl_file_save(buffer, NULL, NULL)); \ + eo_do(mesh2, efl_file_mmap_set(eina_file_open(buffer, 0), NULL)); \ + res = _compare_meshes(mesh, mesh2); \ + fail_if(res == 1); \ + eo_del(mesh2); \ + eo_del(mesh); \ + unlink(buffer); \ + } static Evas_3D_Mesh_Frame * return_zero_frame(Evas_3D_Mesh_Data *pd)