summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBogdan Devichev <b.devichev@samsung.com>2014-12-10 18:31:20 +0200
committerCedric BAIL <cedric@osg.samsung.com>2014-12-23 21:20:20 +0100
commit61aab62be0e17fd58405debbc0f6befae66e64c8 (patch)
tree04b0b3ed39562f702fc0686a3e9d044ab5977579 /src
parent17baa3fa6f87227fdba4caaea5e5c2a39257f5bb (diff)
evas: entry points to modules is Eina_File. Model_Common_Loader is deleted.
Diffstat (limited to 'src')
-rw-r--r--src/lib/evas/common/evas_model_load.c69
-rw-r--r--src/lib/evas/include/evas_private.h16
-rw-r--r--src/modules/evas/model_loaders/eet/evas_model_load_eet.c4
-rw-r--r--src/modules/evas/model_loaders/md2/evas_model_load_md2.c33
-rw-r--r--src/modules/evas/model_loaders/obj/evas_model_load_obj.c28
-rw-r--r--src/modules/evas/model_loaders/ply/evas_model_load_ply.c22
6 files changed, 82 insertions, 90 deletions
diff --git a/src/lib/evas/common/evas_model_load.c b/src/lib/evas/common/evas_model_load.c
index 4ccb30c..0598d31 100644
--- a/src/lib/evas/common/evas_model_load.c
+++ b/src/lib/evas/common/evas_model_load.c
@@ -7,68 +7,28 @@
7#include "evas_common_private.h" 7#include "evas_common_private.h"
8#include "evas_private.h" 8#include "evas_private.h"
9 9
10static inline void
11_model_common_loader_fini(Model_Common_Loader *loader)
12{
13 if (loader->map)
14 {
15 eina_file_map_free(loader->file, loader->map);
16 loader->map = NULL;
17 }
18
19 if (loader->file)
20 {
21 eina_file_close(loader->file);
22 loader->file = NULL;
23 }
24}
25
26static inline Eina_Bool
27_model_common_loader_init(Model_Common_Loader *loader, const char *file)
28{
29 Eina_File *tmp_file = eina_file_open(file, 0);
30 memset(loader, 0x00, sizeof(Model_Common_Loader));
31
32 /* Open given file. */
33 loader->file = eina_file_dup(tmp_file);
34
35 if (loader->file == NULL)
36 {
37 ERR("Failed to open file %s\n", file);
38 goto error;
39 }
40
41 /* Map the file. */
42 loader->map = eina_file_map_all(loader->file, EINA_FILE_SEQUENTIAL);
43
44 if (loader->map == NULL)
45 {
46 ERR("Failed to create map from file %s\n", file);
47 goto error;
48 }
49
50 eina_file_close(tmp_file);
51 return EINA_TRUE;
52
53error:
54 eina_file_close(tmp_file);
55 _model_common_loader_fini(loader);
56 return EINA_FALSE;
57}
58
59void 10void
60evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file) 11evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
61{ 12{
62 char *p; 13 char *p;
63 char *loader_type = NULL; 14 char *loader_type = NULL;
64 Model_Common_Loader *loader = malloc(sizeof(Model_Common_Loader));
65 15
66 if (!_model_common_loader_init(loader, file)) 16 Eina_File *tmp_file = eina_file_open(file, 0);
17 Eina_File *e_file = eina_file_dup(tmp_file);
18
19 if (e_file == NULL)
67 { 20 {
21 ERR("Failed to open file %s\n", file);
22 eina_file_close(tmp_file);
23 eina_file_close(e_file);
24 e_file = NULL;
25 file = NULL;
68 ERR("Failed to initialize loader."); 26 ERR("Failed to initialize loader.");
69 return; 27 return;
70 } 28 }
71 29
30 eina_file_close(tmp_file);
31
72 p = strrchr(file, '.'); 32 p = strrchr(file, '.');
73 if (p) 33 if (p)
74 { 34 {
@@ -76,7 +36,7 @@ evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
76#define CHECK_EXTENTION_BY_FILE_NAME(extention) \ 36#define CHECK_EXTENTION_BY_FILE_NAME(extention) \
77 if (!strcasecmp(p, #extention)) \ 37 if (!strcasecmp(p, #extention)) \
78 { \ 38 { \
79 evas_model_load_file_##extention(model, loader); \ 39 evas_model_load_file_##extention(model, e_file); \
80 loader_type = #extention; \ 40 loader_type = #extention; \
81 } 41 }
82 CHECK_EXTENTION_BY_FILE_NAME(eet) 42 CHECK_EXTENTION_BY_FILE_NAME(eet)
@@ -87,7 +47,6 @@ evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file)
87 } 47 }
88 if (!loader_type) ERR("Invalid mesh file type."); 48 if (!loader_type) ERR("Invalid mesh file type.");
89 49
90 _model_common_loader_fini(loader); 50 eina_file_close(e_file);
91 free(loader); 51 e_file = NULL;
92} 52}
93
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index 729f647..a0b0f54 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -158,14 +158,6 @@ struct _Evas_3D_File_Eet
158 Evas_3D_Header_Eet *header; 158 Evas_3D_Header_Eet *header;
159};//contain mesh data and information about mesh size 159};//contain mesh data and information about mesh size
160 160
161typedef struct _Model_Common_Loader Model_Common_Loader;
162
163struct _Model_Common_Loader
164{
165 Eina_File *file;
166 char *map;
167};
168
169typedef Eina_Bool (*Evas_3D_Node_Func)(Evas_3D_Node *, void *data); 161typedef Eina_Bool (*Evas_3D_Node_Func)(Evas_3D_Node *, void *data);
170 162
171 163
@@ -1657,10 +1649,10 @@ void _evas_3d_eet_file_free(void);
1657/* Temporary save/load functions */ 1649/* Temporary save/load functions */
1658void evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file); 1650void evas_common_load_model_to_file(Evas_3D_Mesh *model, const char *file);
1659void evas_common_save_model_to_file(Evas_3D_Mesh *model, const char *file, Evas_3D_Mesh_Frame *f); 1651void evas_common_save_model_to_file(Evas_3D_Mesh *model, const char *file, Evas_3D_Mesh_Frame *f);
1660void evas_model_load_file_eet(Evas_3D_Mesh *mesh, Model_Common_Loader *loader); 1652void evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file);
1661void evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *loader); 1653void evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file);
1662void evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader); 1654void evas_model_load_file_obj(Evas_3D_Mesh *mesh, Eina_File *file);
1663void evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader); 1655void evas_model_load_file_ply(Evas_3D_Mesh *mesh, Eina_File *file);
1664void evas_model_save_file_eet(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f); 1656void evas_model_save_file_eet(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f);
1665void evas_model_save_file_obj(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f); 1657void evas_model_save_file_obj(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f);
1666void evas_model_save_file_ply(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f); 1658void evas_model_save_file_ply(Evas_3D_Mesh *mesh, const char *file, Evas_3D_Mesh_Frame *f);
diff --git a/src/modules/evas/model_loaders/eet/evas_model_load_eet.c b/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
index 572e085..b393787 100644
--- a/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
+++ b/src/modules/evas/model_loaders/eet/evas_model_load_eet.c
@@ -104,12 +104,12 @@ _set_material_to_mesh_from_eet_file(Evas_3D_Mesh *mesh,
104} 104}
105 105
106void 106void
107evas_model_load_file_eet(Evas_3D_Mesh *mesh, Model_Common_Loader *loader) 107evas_model_load_file_eet(Evas_3D_Mesh *mesh, Eina_File *file)
108{ 108{
109 Eet_File *ef; 109 Eet_File *ef;
110 110
111 _evas_3d_eet_file_init(); 111 _evas_3d_eet_file_init();
112 ef = eet_open(eina_file_filename_get(loader->file), EET_FILE_MODE_READ); 112 ef = eet_open(eina_file_filename_get(file), EET_FILE_MODE_READ);
113 eet_file = eet_data_read(ef, 113 eet_file = eet_data_read(ef,
114 _file_descriptor, 114 _file_descriptor,
115 EVAS_3D_FILE_CACHE_FILE_ENTRY); 115 EVAS_3D_FILE_CACHE_FILE_ENTRY);
diff --git a/src/modules/evas/model_loaders/md2/evas_model_load_md2.c b/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
index a7fddc7..98989ab 100644
--- a/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
+++ b/src/modules/evas/model_loaders/md2/evas_model_load_md2.c
@@ -67,7 +67,7 @@ struct PACKED _MD2_Texcoord
67 67
68typedef struct _MD2_Loader 68typedef struct _MD2_Loader
69{ 69{
70 Model_Common_Loader *common_loader; 70 char *map;
71 int size; 71 int size;
72 72
73 int skin_width; 73 int skin_width;
@@ -252,21 +252,28 @@ static const float normal_table[162][3] =
252}; 252};
253 253
254static inline Eina_Bool 254static inline Eina_Bool
255_md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader) 255_md2_loader_init(MD2_Loader *loader, Eina_File *file)
256{ 256{
257 MD2_Header header; 257 MD2_Header header;
258 258
259 memset(loader, 0x00, sizeof(MD2_Loader)); 259 memset(loader, 0x00, sizeof(MD2_Loader));
260 loader->common_loader = common_loader; 260
261 loader->map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
262
263 if (loader->map == NULL)
264 {
265 ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
266 goto error;
267 }
261 268
262 /* Check file size. We require a file larger than MD2 header size. */ 269 /* Check file size. We require a file larger than MD2 header size. */
263 loader->size = eina_file_size_get(loader->common_loader->file); 270 loader->size = eina_file_size_get(file);
264 271
265 if (loader->size < (int)sizeof(MD2_Header)) 272 if (loader->size < (int)sizeof(MD2_Header))
266 goto error; 273 goto error;
267 274
268 /* Read header. */ 275 /* Read header. */
269 memcpy(&header, loader->common_loader->map, sizeof(MD2_Header)); 276 memcpy(&header, loader->map, sizeof(MD2_Header));
270 277
271 /* Check identity */ 278 /* Check identity */
272 if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION) 279 if (header.magic != MD2_MAGIC_NUMBER || header.version != MD2_VERSION)
@@ -296,14 +303,14 @@ _md2_loader_init(MD2_Loader *loader, Model_Common_Loader *common_loader)
296 303
297 loader->frame_count = header.frame_count; 304 loader->frame_count = header.frame_count;
298 loader->frame_size = header.frame_size; 305 loader->frame_size = header.frame_size;
299 loader->frames = loader->common_loader->map + header.offset_frames; 306 loader->frames = loader->map + header.offset_frames;
300 307
301 loader->vertex_count = header.vertex_count; 308 loader->vertex_count = header.vertex_count;
302 loader->triangle_count = header.triangle_count; 309 loader->triangle_count = header.triangle_count;
303 loader->texcoord_count = header.texcoord_count; 310 loader->texcoord_count = header.texcoord_count;
304 311
305 loader->triangles = (MD2_Triangle *)(loader->common_loader->map + header.offset_triangles); 312 loader->triangles = (MD2_Triangle *)(loader->map + header.offset_triangles);
306 loader->texcoords = (MD2_Texcoord *)(loader->common_loader->map + header.offset_texcoords); 313 loader->texcoords = (MD2_Texcoord *)(loader->map + header.offset_texcoords);
307 return EINA_TRUE; 314 return EINA_TRUE;
308 315
309error: 316error:
@@ -311,7 +318,7 @@ error:
311} 318}
312 319
313void 320void
314evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader) 321evas_model_load_file_md2(Evas_3D_Mesh *mesh, Eina_File *file)
315{ 322{
316 MD2_Loader loader; 323 MD2_Loader loader;
317 int i, j, k; 324 int i, j, k;
@@ -321,7 +328,7 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
321 Evas_3D_Mesh_Data *pd; 328 Evas_3D_Mesh_Data *pd;
322 329
323 /* Initialize MD2 loader (Open file and read MD2 head ant etc) */ 330 /* Initialize MD2 loader (Open file and read MD2 head ant etc) */
324 if (!_md2_loader_init(&loader, common_loader)) 331 if (!_md2_loader_init(&loader, file))
325 { 332 {
326 ERR("Failed to initialize MD2 loader."); 333 ERR("Failed to initialize MD2 loader.");
327 return; 334 return;
@@ -409,5 +416,11 @@ evas_model_load_file_md2(Evas_3D_Mesh *mesh, Model_Common_Loader *common_loader)
409 ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f); 416 ERR("Axis-Aligned Bounding Box wasn't added in frame %d ", f);
410 } 417 }
411 } 418 }
419
420 if (loader.map)
421 {
422 eina_file_map_free(file, loader.map);
423 loader.map = NULL;
424 }
412} 425}
413 426
diff --git a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
index 7c6869e..64c4eb9 100644
--- a/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
+++ b/src/modules/evas/model_loaders/obj/evas_model_load_obj.c
@@ -83,11 +83,11 @@ _analyze_face_line(char * face_analyzer,
83} 83}
84 84
85static inline OBJ_Counts 85static inline OBJ_Counts
86_count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj 86_count_elements(char *map)//count elements of mesh in .obj
87{ 87{
88 OBJ_Counts counts = _new_count_elements(); 88 OBJ_Counts counts = _new_count_elements();
89 89
90 char * current = loader->map; 90 char *current = map;
91 int polygon_checker = -2;//polygons with n vertices can be represented as n-2 triangles 91 int polygon_checker = -2;//polygons with n vertices can be represented as n-2 triangles
92 Eina_Bool will_check_next_char = EINA_FALSE; 92 Eina_Bool will_check_next_char = EINA_FALSE;
93 Eina_Bool first_char_is_v = EINA_FALSE; 93 Eina_Bool first_char_is_v = EINA_FALSE;
@@ -178,7 +178,7 @@ _count_elements(Model_Common_Loader *loader)//count elements of mesh in .obj
178} 178}
179 179
180void 180void
181evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader) 181evas_model_load_file_obj(Evas_3D_Mesh *mesh, Eina_File *file)
182{ 182{
183 long i; 183 long i;
184 OBJ_Counts counts;//count elements of mesh in .obj 184 OBJ_Counts counts;//count elements of mesh in .obj
@@ -188,9 +188,17 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
188 float *pos, *nor, *tex; 188 float *pos, *nor, *tex;
189 int stride_pos, stride_nor, stride_tex; 189 int stride_pos, stride_nor, stride_tex;
190 int j, k; 190 int j, k;
191 char * current; 191 char *current, *map;
192 192
193 counts = _count_elements(loader); 193 map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
194
195 if (map == NULL)
196 {
197 ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
198 return;
199 }
200
201 counts = _count_elements(map);
194 202
195 float *_vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float)); 203 float *_vertices_obj = malloc(counts._vertex_counter * 3 * sizeof(float));
196 float *_normales_obj = malloc(counts._normal_counter * 3 * sizeof(float)); 204 float *_normales_obj = malloc(counts._normal_counter * 3 * sizeof(float));
@@ -198,7 +206,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
198 /* triangle has 3 points, every point has 3(vertix, texture and normal) coord */ 206 /* triangle has 3 points, every point has 3(vertix, texture and normal) coord */
199 int *_triangles = malloc(counts._triangles_counter * 9 * sizeof(int)); 207 int *_triangles = malloc(counts._triangles_counter * 9 * sizeof(int));
200 208
201 if ((loader->map == NULL) || (_vertices_obj == NULL) || 209 if ((map == NULL) || (_vertices_obj == NULL) ||
202 (_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL)) 210 (_normales_obj == NULL) || (_tex_coords_obj == NULL) || (_triangles == NULL))
203 { 211 {
204 ERR("Allocate memory is failed."); 212 ERR("Allocate memory is failed.");
@@ -209,7 +217,7 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
209 return; 217 return;
210 } 218 }
211 219
212 current = loader->map; 220 current = map;
213 i = 0; 221 i = 0;
214 222
215 /* put data to arrays */ 223 /* put data to arrays */
@@ -373,5 +381,11 @@ evas_model_load_file_obj(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
373 { 381 {
374 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0); 382 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
375 } 383 }
384
385 if (map)
386 {
387 eina_file_map_free(file, map);
388 map = NULL;
389 }
376} 390}
377 391
diff --git a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
index 246f7cd..0eac908 100644
--- a/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
+++ b/src/modules/evas/model_loaders/ply/evas_model_load_ply.c
@@ -178,19 +178,27 @@ _read_header(char *map)//Check properties of mesh in .ply file.
178} 178}
179 179
180void 180void
181evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader) 181evas_model_load_file_ply(Evas_3D_Mesh *mesh, Eina_File *file)
182{ 182{
183 Evas_3D_Mesh_Data *pd; 183 Evas_3D_Mesh_Data *pd;
184 int i = 0, j = 0, k = 0, count_of_triangles_in_line = 0; 184 int i = 0, j = 0, k = 0, count_of_triangles_in_line = 0;
185 float *pos, *nor, *tex, *col; 185 float *pos, *nor, *tex, *col;
186 int stride_pos, stride_nor, stride_tex, stride_col; 186 int stride_pos, stride_nor, stride_tex, stride_col;
187 char *current; 187 char *current, *map;
188 PLY_Header header; 188 PLY_Header header;
189 float *_vertices_ply = NULL, *_normals_ply = NULL; 189 float *_vertices_ply = NULL, *_normals_ply = NULL;
190 float *_tex_coords_ply = NULL, *_colors_ply = NULL; 190 float *_tex_coords_ply = NULL, *_colors_ply = NULL;
191 char **helping_pointer; 191 char **helping_pointer;
192 192
193 header = _read_header(loader->map); 193 map = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
194
195 if (map == NULL)
196 {
197 ERR("Failed to create map from file %s\n", eina_file_filename_get(file));
198 return;
199 }
200
201 header = _read_header(map);
194 202
195 if (!header.existence_of_geometries) 203 if (!header.existence_of_geometries)
196 { 204 {
@@ -198,7 +206,7 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
198 return; 206 return;
199 } 207 }
200 208
201 helping_pointer = eina_str_split(loader->map, "end_header\n", 0); 209 helping_pointer = eina_str_split(map, "end_header\n", 0);
202 210
203 if (helping_pointer == NULL) 211 if (helping_pointer == NULL)
204 { 212 {
@@ -369,5 +377,11 @@ evas_model_load_file_ply(Evas_3D_Mesh *mesh, Model_Common_Loader *loader)
369 { 377 {
370 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0); 378 ERR("Axis-Aligned Bounding Box wan't added in frame %d ", 0);
371 } 379 }
380
381 if (map)
382 {
383 eina_file_map_free(file, map);
384 map = NULL;
385 }
372} 386}
373 387