summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHermet Park <hermetpark@gmail.com>2019-03-12 12:53:35 +0900
committerHermet Park <hermetpark@gmail.com>2019-03-12 12:58:31 +0900
commitd45e3df689d39c572786385a79e8fceded2dfdc6 (patch)
tree36ca873537b3ef8ea06452f7d6438bdda6018368
parent305749f049ceb73071febe2ac723dadff7b69dbc (diff)
evas vg: replace to eina_file instance caching by vg.
Here is a replacement to use eina_file from a vg obj instance to map file data by vg loaders. This brings a benefit that integrated access to load data between vg object and vg loaders.
-rw-r--r--src/lib/evas/canvas/efl_canvas_vg_object.c58
-rw-r--r--src/lib/evas/canvas/efl_canvas_vg_object.eo1
-rw-r--r--src/lib/evas/canvas/evas_vg_private.h7
-rw-r--r--src/lib/evas/include/evas_private.h2
-rw-r--r--src/lib/evas/vg/evas_vg_cache.c25
-rw-r--r--src/modules/evas/vg_loaders/eet/evas_vg_load_eet.c6
-rw-r--r--src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c20
7 files changed, 69 insertions, 50 deletions
diff --git a/src/lib/evas/canvas/efl_canvas_vg_object.c b/src/lib/evas/canvas/efl_canvas_vg_object.c
index abff8069aa..9fc2d5e6f8 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_object.c
+++ b/src/lib/evas/canvas/efl_canvas_vg_object.c
@@ -245,25 +245,54 @@ _efl_canvas_vg_object_viewbox_align_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Vg
245} 245}
246 246
247EOLIAN static Eina_Error 247EOLIAN static Eina_Error
248_efl_canvas_vg_object_efl_file_load(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd) 248_efl_canvas_vg_object_efl_file_file_set(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd EINA_UNUSED, const char *file)
249{ 249{
250 Vg_Cache_Entry *old_entry; 250 /* Careful: delete previous vg entry.
251 const char *file; 251 When a new efl file is set, ex-file will be invalid.
252 Since vg cache hashes all file entries,
253 we must remove it from vg cache before we lost file handle. */
254 if (efl_file_loaded_get(eo_obj))
255 {
256 const char *pname = efl_file_get(eo_obj);
257 int pl = pname ? strlen(pname) : 0;
258 int cl = file ? strlen(file) : 0;
259
260 if ((pl != cl) || strcmp(pname, file))
261 {
262 Evas_Object_Protected_Data *obj;
263 obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
264 evas_cache_vg_entry_del(pd->vg_entry);
265 evas_object_change(eo_obj, obj);
266 pd->vg_entry = NULL;
267 evas_object_change(eo_obj, obj);
268 }
269 }
252 270
253 file = efl_file_get(eo_obj); 271 Eina_Error err;
254 if (!file) return ENOENT; 272 err = efl_file_set(efl_super(eo_obj, MY_CLASS), file);
273 if (err) return err;
255 274
256 old_entry = pd->vg_entry; 275 return 0;
276}
257 277
278EOLIAN static Eina_Error
279_efl_canvas_vg_object_efl_file_load(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd)
280{
281 Eina_Error err;
282 if (efl_file_loaded_get(eo_obj)) return 0;
283
284 err = efl_file_load(efl_super(eo_obj, MY_CLASS));
285 if (err) return err;
286
287 const Eina_File *file = efl_file_mmap_get(eo_obj);
288 const char *key = efl_file_key_get(eo_obj);
258 Evas_Object_Protected_Data *obj; 289 Evas_Object_Protected_Data *obj;
259 obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
260 290
261 pd->vg_entry = evas_cache_vg_entry_create(file, efl_file_key_get(eo_obj), 291 obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
292 pd->vg_entry = evas_cache_vg_entry_create(file, key,
262 obj->cur->geometry.w, 293 obj->cur->geometry.w,
263 obj->cur->geometry.h); 294 obj->cur->geometry.h);
264
265 evas_object_change(eo_obj, obj); 295 evas_object_change(eo_obj, obj);
266 evas_cache_vg_entry_del(old_entry);
267 296
268 return 0; 297 return 0;
269} 298}
@@ -271,18 +300,13 @@ _efl_canvas_vg_object_efl_file_load(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd)
271EOLIAN static void 300EOLIAN static void
272_efl_canvas_vg_object_efl_file_unload(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd) 301_efl_canvas_vg_object_efl_file_unload(Eo *eo_obj, Efl_Canvas_Vg_Object_Data *pd)
273{ 302{
274 Vg_Cache_Entry *old_entry;
275
276 if (!efl_file_loaded_get(eo_obj)) return; 303 if (!efl_file_loaded_get(eo_obj)) return;
277 old_entry = pd->vg_entry;
278 304
279 Evas_Object_Protected_Data *obj; 305 Evas_Object_Protected_Data *obj;
280 obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); 306 obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
281 307 evas_cache_vg_entry_del(pd->vg_entry);
282 pd->vg_entry = NULL;
283
284 evas_object_change(eo_obj, obj); 308 evas_object_change(eo_obj, obj);
285 evas_cache_vg_entry_del(old_entry); 309 pd->vg_entry = NULL;
286} 310}
287 311
288EOLIAN static Eina_Bool 312EOLIAN static Eina_Bool
diff --git a/src/lib/evas/canvas/efl_canvas_vg_object.eo b/src/lib/evas/canvas/efl_canvas_vg_object.eo
index f46f32e20c..02562a4f56 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_object.eo
+++ b/src/lib/evas/canvas/efl_canvas_vg_object.eo
@@ -74,6 +74,7 @@ class @beta Efl.Canvas.Vg.Object extends Efl.Canvas.Object implements Efl.File,
74 Efl.Object.destructor; 74 Efl.Object.destructor;
75 Efl.File.load; 75 Efl.File.load;
76 Efl.File.unload; 76 Efl.File.unload;
77 Efl.File.file { set; }
77 Efl.File_Save.save; 78 Efl.File_Save.save;
78 } 79 }
79} 80}
diff --git a/src/lib/evas/canvas/evas_vg_private.h b/src/lib/evas/canvas/evas_vg_private.h
index 7fb62d4827..f4c47de4bb 100644
--- a/src/lib/evas/canvas/evas_vg_private.h
+++ b/src/lib/evas/canvas/evas_vg_private.h
@@ -19,14 +19,13 @@ typedef struct _Vg_Cache
19typedef struct _Vg_Cache_Entry 19typedef struct _Vg_Cache_Entry
20{ 20{
21 char *hash_key; 21 char *hash_key;
22 Eina_Stringshare *file; 22 const Eina_File *file;
23 Eina_Stringshare *key; 23 Eina_Stringshare *key;
24 int w; 24 int w;
25 int h; 25 int h;
26 Efl_VG *root; 26 Efl_VG *root;
27 int ref; 27 int ref;
28 Vg_File_Data *vfd; 28 Vg_File_Data *vfd;
29
30} Vg_Cache_Entry; 29} Vg_Cache_Entry;
31 30
32// holds the vg tree info set by the user 31// holds the vg tree info set by the user
@@ -119,10 +118,10 @@ struct _Efl_Canvas_Vg_Interpolation
119void evas_cache_vg_init(void); 118void evas_cache_vg_init(void);
120void evas_cache_vg_shutdown(void); 119void evas_cache_vg_shutdown(void);
121Vg_Cache_Entry* evas_cache_vg_entry_resize(Vg_Cache_Entry *entry, int w, int h); 120Vg_Cache_Entry* evas_cache_vg_entry_resize(Vg_Cache_Entry *entry, int w, int h);
122Vg_Cache_Entry* evas_cache_vg_entry_create(const char *file, const char *key, int w, int h); 121Vg_Cache_Entry* evas_cache_vg_entry_create(const Eina_File *file, const char *key, int w, int h);
123Efl_VG* evas_cache_vg_tree_get(Vg_Cache_Entry *vg_entry); 122Efl_VG* evas_cache_vg_tree_get(Vg_Cache_Entry *vg_entry);
124void evas_cache_vg_entry_del(Vg_Cache_Entry *vg_entry); 123void evas_cache_vg_entry_del(Vg_Cache_Entry *vg_entry);
125Vg_File_Data * evas_cache_vg_file_open(const char *file, const char *key); 124Vg_File_Data * evas_cache_vg_file_open(const Eina_File *file, const char *key);
126Eina_Bool evas_cache_vg_file_save(Efl_VG *root, int w, int h, const char *file, const char *key, const Efl_File_Save_Info *info); 125Eina_Bool evas_cache_vg_file_save(Efl_VG *root, int w, int h, const char *file, const char *key, const Efl_File_Save_Info *info);
127Eina_Bool evas_cache_vg_entry_file_save(Vg_Cache_Entry *vg_entry, const char *file, const char *key, const Efl_File_Save_Info *info); 126Eina_Bool evas_cache_vg_entry_file_save(Vg_Cache_Entry *vg_entry, const char *file, const char *key, const Efl_File_Save_Info *info);
128void efl_canvas_vg_node_vg_obj_set(Efl_VG *node, Efl_VG *vg_obj, Efl_Canvas_Vg_Object_Data *vd); 127void efl_canvas_vg_node_vg_obj_set(Efl_VG *node, Efl_VG *vg_obj, Efl_Canvas_Vg_Object_Data *vd);
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index e9b9dc0c57..5a4bd9cc5e 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -1523,7 +1523,7 @@ struct _Vg_File_Data
1523 1523
1524struct _Evas_Vg_Load_Func 1524struct _Evas_Vg_Load_Func
1525{ 1525{
1526 Vg_File_Data *(*file_open) (const char *file, const char *key, int *error); 1526 Vg_File_Data *(*file_open) (Eina_File *file, const char *key, int *error);
1527 Eina_Bool (*file_close) (Vg_File_Data *vfd); 1527 Eina_Bool (*file_close) (Vg_File_Data *vfd);
1528 Eina_Bool (*file_data) (Vg_File_Data *vfd); 1528 Eina_Bool (*file_data) (Vg_File_Data *vfd);
1529}; 1529};
diff --git a/src/lib/evas/vg/evas_vg_cache.c b/src/lib/evas/vg/evas_vg_cache.c
index 6022982557..534dca2748 100644
--- a/src/lib/evas/vg/evas_vg_cache.c
+++ b/src/lib/evas/vg/evas_vg_cache.c
@@ -70,7 +70,7 @@ _find_loader_module(const char *file)
70} 70}
71 71
72static Vg_File_Data * 72static Vg_File_Data *
73_vg_load_from_file(const char *file, const char *key) 73_vg_load_from_file(const Eina_File *file, const char *key)
74{ 74{
75 Evas_Module *em; 75 Evas_Module *em;
76 Evas_Vg_Load_Func *loader; 76 Evas_Vg_Load_Func *loader;
@@ -78,11 +78,12 @@ _vg_load_from_file(const char *file, const char *key)
78 Vg_File_Data *vfd; 78 Vg_File_Data *vfd;
79 unsigned int i; 79 unsigned int i;
80 80
81 em = _find_loader_module(file); 81 const char *file_name = eina_file_filename_get(file);
82 em = _find_loader_module(file_name);
82 if (em) 83 if (em)
83 { 84 {
84 loader = em->functions; 85 loader = em->functions;
85 vfd = loader->file_open(file, key, &error); 86 vfd = loader->file_open((Eina_File *) file, key, &error);
86 if (vfd) 87 if (vfd)
87 { 88 {
88 vfd->loader = loader; 89 vfd->loader = loader;
@@ -97,7 +98,8 @@ _vg_load_from_file(const char *file, const char *key)
97 if (em) 98 if (em)
98 { 99 {
99 loader = em->functions; 100 loader = em->functions;
100 vfd = loader->file_open(file, key, &error); 101 vfd = loader->file_open((Eina_File *) file, key, &error);
102 if (vfd)
101 { 103 {
102 vfd->loader = loader; 104 vfd->loader = loader;
103 return vfd; 105 return vfd;
@@ -105,7 +107,7 @@ _vg_load_from_file(const char *file, const char *key)
105 } 107 }
106 } 108 }
107 } 109 }
108 WRN("Exhausted all means to load vector file = %s", file); 110 WRN("Exhausted all means to load vector file = %s", file_name);
109 return NULL; 111 return NULL;
110} 112}
111 113
@@ -148,11 +150,12 @@ _evas_cache_vg_entry_free_cb(void *data)
148 if (vg_entry->vfd) 150 if (vg_entry->vfd)
149 { 151 {
150 vg_entry->vfd->ref--; 152 vg_entry->vfd->ref--;
153
151 if (vg_entry->vfd->ref <= 0) 154 if (vg_entry->vfd->ref <= 0)
152 { 155 {
153 Eina_Strbuf *hash_key = eina_strbuf_new(); 156 Eina_Strbuf *hash_key = eina_strbuf_new();
154 eina_strbuf_append_printf(hash_key, "%s/%s", 157 eina_strbuf_append_printf(hash_key, "%s/%s",
155 vg_entry->file, 158 eina_file_filename_get(vg_entry->file),
156 vg_entry->key); 159 vg_entry->key);
157 if (!eina_hash_del(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key), vg_entry->vfd)) 160 if (!eina_hash_del(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key), vg_entry->vfd))
158 ERR("Failed to delete vfd = (%p) from hash", vg_entry->vfd); 161 ERR("Failed to delete vfd = (%p) from hash", vg_entry->vfd);
@@ -283,13 +286,13 @@ evas_cache_vg_shutdown(void)
283} 286}
284 287
285Vg_File_Data * 288Vg_File_Data *
286evas_cache_vg_file_open(const char *file, const char *key) 289evas_cache_vg_file_open(const Eina_File *file, const char *key)
287{ 290{
288 Vg_File_Data *vfd; 291 Vg_File_Data *vfd;
289 Eina_Strbuf *hash_key; 292 Eina_Strbuf *hash_key;
290 293
291 hash_key = eina_strbuf_new(); 294 hash_key = eina_strbuf_new();
292 eina_strbuf_append_printf(hash_key, "%s/%s", file, key); 295 eina_strbuf_append_printf(hash_key, "%s/%s", eina_file_filename_get(file), key);
293 vfd = eina_hash_find(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key)); 296 vfd = eina_hash_find(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key));
294 if (!vfd) 297 if (!vfd)
295 { 298 {
@@ -308,7 +311,7 @@ evas_cache_vg_entry_resize(Vg_Cache_Entry *vg_entry, int w, int h)
308} 311}
309 312
310Vg_Cache_Entry* 313Vg_Cache_Entry*
311evas_cache_vg_entry_create(const char *file, 314evas_cache_vg_entry_create(const Eina_File *file,
312 const char *key, 315 const char *key,
313 int w, int h) 316 int w, int h)
314{ 317{
@@ -320,7 +323,7 @@ evas_cache_vg_entry_create(const char *file,
320 //TODO: zero-sized entry is useless. how to skip it? 323 //TODO: zero-sized entry is useless. how to skip it?
321 324
322 hash_key = eina_strbuf_new(); 325 hash_key = eina_strbuf_new();
323 eina_strbuf_append_printf(hash_key, "%s/%s/%d/%d", file, key, w, h); 326 eina_strbuf_append_printf(hash_key, "%p/%s/%d/%d", file, key, w, h);
324 vg_entry = eina_hash_find(vg_cache->vg_entry_hash, eina_strbuf_string_get(hash_key)); 327 vg_entry = eina_hash_find(vg_cache->vg_entry_hash, eina_strbuf_string_get(hash_key));
325 if (!vg_entry) 328 if (!vg_entry)
326 { 329 {
@@ -331,7 +334,7 @@ evas_cache_vg_entry_create(const char *file,
331 eina_strbuf_free(hash_key); 334 eina_strbuf_free(hash_key);
332 return NULL; 335 return NULL;
333 } 336 }
334 vg_entry->file = eina_stringshare_add(file); 337 vg_entry->file = file;
335 vg_entry->key = eina_stringshare_add(key); 338 vg_entry->key = eina_stringshare_add(key);
336 vg_entry->w = w; 339 vg_entry->w = w;
337 vg_entry->h = h; 340 vg_entry->h = h;
diff --git a/src/modules/evas/vg_loaders/eet/evas_vg_load_eet.c b/src/modules/evas/vg_loaders/eet/evas_vg_load_eet.c
index 3b83b2f541..f0bde2e5ca 100644
--- a/src/modules/evas/vg_loaders/eet/evas_vg_load_eet.c
+++ b/src/modules/evas/vg_loaders/eet/evas_vg_load_eet.c
@@ -13,13 +13,11 @@ static int _evas_vg_loader_eet_log_dom = -1;
13#define INF(...) EINA_LOG_DOM_INFO(_evas_vg_loader_eet_log_dom, __VA_ARGS__) 13#define INF(...) EINA_LOG_DOM_INFO(_evas_vg_loader_eet_log_dom, __VA_ARGS__)
14 14
15static Vg_File_Data* 15static Vg_File_Data*
16evas_vg_load_file_open_eet(const char *file, const char *key, int *error EINA_UNUSED) 16evas_vg_load_file_open_eet(Eina_File *file, const char *key, int *error EINA_UNUSED)
17{ 17{
18 Eet_Data_Descriptor *svg_node_eet; 18 Eet_Data_Descriptor *svg_node_eet;
19 Svg_Node *node; 19 Svg_Node *node;
20 Eet_File *ef; 20 Eet_File *ef = eet_mmap(file);
21
22 ef = eet_open(file, EET_FILE_MODE_READ);
23 if (!ef) 21 if (!ef)
24 { 22 {
25 *error = EVAS_LOAD_ERROR_CORRUPT_FILE; 23 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
diff --git a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
index 25e72feb87..243eb548de 100644
--- a/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
+++ b/src/modules/evas/vg_loaders/svg/evas_vg_load_svg.c
@@ -2339,7 +2339,9 @@ evas_vg_load_file_close_svg(Vg_File_Data *vfd)
2339} 2339}
2340 2340
2341static Vg_File_Data* 2341static Vg_File_Data*
2342evas_vg_load_file_open_svg(const char *file, const char *key EINA_UNUSED, int *error EINA_UNUSED) 2342evas_vg_load_file_open_svg(Eina_File *file,
2343 const char *key EINA_UNUSED,
2344 int *error EINA_UNUSED)
2343{ 2345{
2344 Evas_SVG_Loader loader = { 2346 Evas_SVG_Loader loader = {
2345 NULL, NULL, NULL, NULL, NULL, 0, EINA_FALSE 2347 NULL, NULL, NULL, NULL, NULL, 0, EINA_FALSE
@@ -2347,18 +2349,10 @@ evas_vg_load_file_open_svg(const char *file, const char *key EINA_UNUSED, int *e
2347 const char *content; 2349 const char *content;
2348 unsigned int length; 2350 unsigned int length;
2349 Svg_Node *defs; 2351 Svg_Node *defs;
2350 Eina_File *f;
2351
2352 f = eina_file_open(file, EINA_FALSE);
2353 if (!f)
2354 {
2355 *error = EVAS_LOAD_ERROR_CORRUPT_FILE;
2356 return NULL;
2357 }
2358 2352
2359 loader.svg_parse = calloc(1, sizeof(Evas_SVG_Parser)); 2353 loader.svg_parse = calloc(1, sizeof(Evas_SVG_Parser));
2360 length = eina_file_size_get(f); 2354 length = eina_file_size_get(file);
2361 content = eina_file_map_all(f, EINA_FILE_SEQUENTIAL); 2355 content = eina_file_map_all(file, EINA_FILE_SEQUENTIAL);
2362 if (content) 2356 if (content)
2363 { 2357 {
2364 loader.stack = eina_array_new(8); 2358 loader.stack = eina_array_new(8);
@@ -2366,7 +2360,7 @@ evas_vg_load_file_open_svg(const char *file, const char *key EINA_UNUSED, int *e
2366 _evas_svg_loader_parser, &loader); 2360 _evas_svg_loader_parser, &loader);
2367 2361
2368 eina_array_free(loader.stack); 2362 eina_array_free(loader.stack);
2369 eina_file_map_free(f, (void*) content); 2363 eina_file_map_free(file, (void*) content);
2370 } 2364 }
2371 2365
2372 if (loader.doc) 2366 if (loader.doc)
@@ -2383,7 +2377,7 @@ evas_vg_load_file_open_svg(const char *file, const char *key EINA_UNUSED, int *e
2383 *error = EVAS_LOAD_ERROR_GENERIC; 2377 *error = EVAS_LOAD_ERROR_GENERIC;
2384 } 2378 }
2385 free(loader.svg_parse); 2379 free(loader.svg_parse);
2386 eina_file_close(f); 2380
2387 return vg_common_svg_create_vg_node(loader.doc); 2381 return vg_common_svg_create_vg_node(loader.doc);
2388} 2382}
2389 2383