summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHermet Park <hermetpark@gmail.com>2019-11-18 11:48:40 +0900
committerHermet Park <hermetpark@gmail.com>2019-11-18 13:08:29 +0900
commit618bce8038b6362c0de232498566ecf97dc2d17e (patch)
tree2ad84932aa737f65b611772daa7d7fa622db6864
parent98a3dcd94e43e7d172d1609523467edcaed02c1c (diff)
evas vg: improve caching methods for better precise behaviors.
Previously, json file data won't be shared between instances. Now, objects can share the json data if they use the same file resource.
-rw-r--r--src/lib/evas/canvas/efl_canvas_vg_object.c19
-rw-r--r--src/lib/evas/canvas/evas_vg_private.h1
-rw-r--r--src/lib/evas/include/evas_private.h1
-rw-r--r--src/lib/evas/vg/evas_vg_cache.c76
-rw-r--r--src/modules/evas/vg_loaders/json/evas_vg_load_json.c1
5 files changed, 41 insertions, 57 deletions
diff --git a/src/lib/evas/canvas/efl_canvas_vg_object.c b/src/lib/evas/canvas/efl_canvas_vg_object.c
index 3c3c0d81d6..52215200a7 100644
--- a/src/lib/evas/canvas/efl_canvas_vg_object.c
+++ b/src/lib/evas/canvas/efl_canvas_vg_object.c
@@ -524,7 +524,6 @@ _render_to_buffer(Evas_Object_Protected_Data *obj, Efl_Canvas_Vg_Object_Data *pd
524 { 524 {
525 //Use root as a cache key. 525 //Use root as a cache key.
526 ENFN->ector_surface_cache_set(engine, root, buffer); 526 ENFN->ector_surface_cache_set(engine, root, buffer);
527 pd->cached_frame_idx = pd->frame_idx;
528 } 527 }
529 528
530 return buffer; 529 return buffer;
@@ -566,7 +565,6 @@ _cache_vg_entry_render(Evas_Object_Protected_Data *obj,
566 Vg_Cache_Entry *vg_entry = pd->vg_entry; 565 Vg_Cache_Entry *vg_entry = pd->vg_entry;
567 Efl_VG *root; 566 Efl_VG *root;
568 Eina_Position2D offset = {0, 0}; //Offset after keeping aspect ratio. 567 Eina_Position2D offset = {0, 0}; //Offset after keeping aspect ratio.
569 Eina_Bool drop_cache = EINA_FALSE;
570 void *buffer = NULL; 568 void *buffer = NULL;
571 569
572 evas_cache_vg_entry_value_provider_update(pd->vg_entry, efl_key_data_get(obj->object, "_vg_value_providers")); 570 evas_cache_vg_entry_value_provider_update(pd->vg_entry, efl_key_data_get(obj->object, "_vg_value_providers"));
@@ -603,7 +601,10 @@ _cache_vg_entry_render(Evas_Object_Protected_Data *obj,
603 //Size is changed, cached data is invalid. 601 //Size is changed, cached data is invalid.
604 if ((size.w != vg_entry->w) || (size.h != vg_entry->h)) 602 if ((size.w != vg_entry->w) || (size.h != vg_entry->h))
605 { 603 {
606 drop_cache = EINA_TRUE; 604 //if the size doesn't match, drop previous cache surfaces.
605 ENFN->ector_surface_cache_drop(engine, (void *) vg_entry->root[1]);
606 ENFN->ector_surface_cache_drop(engine, (void *) vg_entry->root[2]);
607
607 vg_entry = evas_cache_vg_entry_resize(vg_entry, size.w, size.h); 608 vg_entry = evas_cache_vg_entry_resize(vg_entry, size.w, size.h);
608 evas_cache_vg_entry_del(pd->vg_entry); 609 evas_cache_vg_entry_del(pd->vg_entry);
609 pd->vg_entry = vg_entry; 610 pd->vg_entry = vg_entry;
@@ -623,20 +624,12 @@ _cache_vg_entry_render(Evas_Object_Protected_Data *obj,
623 624
624 if (cacheable) 625 if (cacheable)
625 { 626 {
626 //if the size doesn't match, drop previous cache surface.
627 if (drop_cache)
628 ENFN->ector_surface_cache_drop(engine, (void *) root);
629 //Cache Hit! 627 //Cache Hit!
630 else if (pd->frame_idx == pd->cached_frame_idx) 628 buffer = ENFN->ector_surface_cache_get(engine, (void *) root);
631 buffer = ENFN->ector_surface_cache_get(engine, (void *) root);
632 //Drop invalid one.
633 else
634 ENFN->ector_surface_cache_drop(engine, (void *) root);
635 } 629 }
636 630
637 if (!buffer) 631 if (!buffer)
638 buffer = _render_to_buffer(obj, pd, engine, root, w, h, NULL, 632 buffer = _render_to_buffer(obj, pd, engine, root, w, h, NULL, do_async, cacheable);
639 do_async, cacheable);
640 else 633 else
641 //cache reference was increased when we get the cache. 634 //cache reference was increased when we get the cache.
642 ENFN->ector_surface_cache_drop(engine, (void *) root); 635 ENFN->ector_surface_cache_drop(engine, (void *) root);
diff --git a/src/lib/evas/canvas/evas_vg_private.h b/src/lib/evas/canvas/evas_vg_private.h
index f5600f9757..8a36fd826d 100644
--- a/src/lib/evas/canvas/evas_vg_private.h
+++ b/src/lib/evas/canvas/evas_vg_private.h
@@ -52,7 +52,6 @@ struct _Efl_Canvas_Vg_Object_Data
52 double align_x, align_y; 52 double align_x, align_y;
53 Efl_Canvas_Vg_Fill_Mode fill_mode; 53 Efl_Canvas_Vg_Fill_Mode fill_mode;
54 int frame_idx; 54 int frame_idx;
55 int cached_frame_idx;
56 55
57 Eina_Bool changed : 1; 56 Eina_Bool changed : 1;
58}; 57};
diff --git a/src/lib/evas/include/evas_private.h b/src/lib/evas/include/evas_private.h
index 838174a3f2..1f514d205c 100644
--- a/src/lib/evas/include/evas_private.h
+++ b/src/lib/evas/include/evas_private.h
@@ -1561,7 +1561,6 @@ struct _Vg_File_Data
1561 1561
1562 void *loader_data; //loader specific local data 1562 void *loader_data; //loader specific local data
1563 1563
1564 Eina_Bool no_share : 1; //Shareable VFD through multiple file open requests.
1565 Eina_Bool static_viewbox: 1; 1564 Eina_Bool static_viewbox: 1;
1566 Eina_Bool preserve_aspect : 1; //Used in SVG 1565 Eina_Bool preserve_aspect : 1; //Used in SVG
1567}; 1566};
diff --git a/src/lib/evas/vg/evas_vg_cache.c b/src/lib/evas/vg/evas_vg_cache.c
index 8ffdfab3f8..68d4e7a634 100644
--- a/src/lib/evas/vg/evas_vg_cache.c
+++ b/src/lib/evas/vg/evas_vg_cache.c
@@ -83,7 +83,9 @@ _vg_load_from_file(const Eina_File *file, const char *key)
83 if (em) 83 if (em)
84 { 84 {
85 loader = em->functions; 85 loader = em->functions;
86 vfd = loader->file_open((Eina_File *) file, key, &error); 86 {
87 vfd = loader->file_open((Eina_File *) file, key, &error);
88 }
87 if (vfd) 89 if (vfd)
88 { 90 {
89 vfd->loader = loader; 91 vfd->loader = loader;
@@ -153,18 +155,13 @@ _evas_cache_vg_entry_free_cb(void *data)
153 155
154 if (vg_entry->vfd->ref <= 0) 156 if (vg_entry->vfd->ref <= 0)
155 { 157 {
156 if (vg_entry->vfd->no_share) 158 Eina_Strbuf *hash_key = eina_strbuf_new();
157 vg_entry->vfd->loader->file_close(vg_entry->vfd); 159 eina_strbuf_append_printf(hash_key, "%s/%s",
158 else 160 eina_file_filename_get(vg_entry->file),
159 { 161 vg_entry->key);
160 Eina_Strbuf *hash_key = eina_strbuf_new(); 162 if (!eina_hash_del(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key), vg_entry->vfd))
161 eina_strbuf_append_printf(hash_key, "%s/%s", 163 ERR("Failed to delete vfd = (%p) from hash", vg_entry->vfd);
162 eina_file_filename_get(vg_entry->file), 164 eina_strbuf_free(hash_key);
163 vg_entry->key);
164 if (!eina_hash_del(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key), vg_entry->vfd))
165 ERR("Failed to delete vfd = (%p) from hash", vg_entry->vfd);
166 eina_strbuf_free(hash_key);
167 }
168 } 165 }
169 } 166 }
170 167
@@ -235,7 +232,7 @@ _cached_root_get(Vg_Cache_Entry *vg_entry, unsigned int frame_num)
235 return NULL; 232 return NULL;
236} 233}
237 234
238static void 235static Efl_VG *
239_caching_root_update(Vg_Cache_Entry *vg_entry) 236_caching_root_update(Vg_Cache_Entry *vg_entry)
240{ 237{
241 Vg_File_Data *vfd = vg_entry->vfd; 238 Vg_File_Data *vfd = vg_entry->vfd;
@@ -251,33 +248,31 @@ _caching_root_update(Vg_Cache_Entry *vg_entry)
251 to this root pointer. */ 248 to this root pointer. */
252 vg_entry->root[0] = efl_duplicate(vfd->root); 249 vg_entry->root[0] = efl_duplicate(vfd->root);
253 } 250 }
254 else if (vg_entry->root[0] != vfd->root) 251 else
255 { 252 {
256 if (vg_entry->root[0]) efl_unref(vg_entry->root[0]); 253 if (vg_entry->root[0]) efl_unref(vg_entry->root[0]);
257 vg_entry->root[0] = efl_ref(vfd->root); 254 vg_entry->root[0] = efl_duplicate(vfd->root);
258 }
259
260 //Animatable?
261 if (!vfd->anim_data) return;
262 255
263 //Start frame 256 //Animatable?
264 if (vfd->anim_data->frame_num == 0) 257 if (vfd->anim_data)
265 {
266 if (vg_entry->root[1] != vfd->root)
267 { 258 {
268 if (vg_entry->root[1]) efl_unref(vg_entry->root[1]); 259 //Start frame
269 vg_entry->root[1] = efl_ref(vfd->root); 260 if (vfd->anim_data->frame_num == 0)
270 } 261 {
271 } 262 if (vg_entry->root[1]) efl_unref(vg_entry->root[1]);
272 //End frame 263 vg_entry->root[1] = efl_duplicate(vfd->root);
273 else if (vfd->anim_data->frame_num == (vfd->anim_data->frame_cnt - 1)) 264 return vg_entry->root[1];
274 { 265 }
275 if (vg_entry->root[2] != vfd->root) 266 //End frame
276 { 267 else if (vfd->anim_data->frame_num == (vfd->anim_data->frame_cnt - 1))
277 if (vg_entry->root[2]) efl_unref(vg_entry->root[2]); 268 {
278 vg_entry->root[2] = efl_ref(vfd->root); 269 if (vg_entry->root[2]) efl_unref(vg_entry->root[2]);
270 vg_entry->root[2] = efl_duplicate(vfd->root);
271 return vg_entry->root[2];
272 }
279 } 273 }
280 } 274 }
275 return vg_entry->root[0];
281} 276}
282 277
283static void 278static void
@@ -351,12 +346,11 @@ evas_cache_vg_file_open(const Eina_File *file, const char *key)
351 hash_key = eina_strbuf_new(); 346 hash_key = eina_strbuf_new();
352 eina_strbuf_append_printf(hash_key, "%s/%s", eina_file_filename_get(file), key); 347 eina_strbuf_append_printf(hash_key, "%s/%s", eina_file_filename_get(file), key);
353 vfd = eina_hash_find(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key)); 348 vfd = eina_hash_find(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key));
354 if (!vfd || vfd->no_share) 349 if (!vfd)
355 { 350 {
356 vfd = _vg_load_from_file(file, key); 351 vfd = _vg_load_from_file(file, key);
357 //File exists. 352 //File exists.
358 if (vfd && !vfd->no_share) 353 if (vfd) eina_hash_add(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key), vfd);
359 eina_hash_add(vg_cache->vfd_hash, eina_strbuf_string_get(hash_key), vfd);
360 } 354 }
361 eina_strbuf_free(hash_key); 355 eina_strbuf_free(hash_key);
362 return vfd; 356 return vfd;
@@ -507,11 +501,11 @@ evas_cache_vg_tree_get(Vg_Cache_Entry *vg_entry, unsigned int frame_num)
507 501
508 if (!vfd->loader->file_data(vfd)) return NULL; 502 if (!vfd->loader->file_data(vfd)) return NULL;
509 503
510 _caching_root_update(vg_entry); 504 root = _caching_root_update(vg_entry);
511 505
512 _local_transform(vg_entry->root[0], vg_entry->w, vg_entry->h, vfd); 506 _local_transform(root, vg_entry->w, vg_entry->h, vfd);
513 507
514 return vg_entry->root[0]; 508 return root;
515} 509}
516 510
517void 511void
diff --git a/src/modules/evas/vg_loaders/json/evas_vg_load_json.c b/src/modules/evas/vg_loaders/json/evas_vg_load_json.c
index e7f2754dd9..60a0d06916 100644
--- a/src/modules/evas/vg_loaders/json/evas_vg_load_json.c
+++ b/src/modules/evas/vg_loaders/json/evas_vg_load_json.c
@@ -103,7 +103,6 @@ evas_vg_load_file_open_json(Eina_File *file,
103 vfd->h = (int) h; 103 vfd->h = (int) h;
104 104
105 vfd->loader_data = (void *) lot_anim; 105 vfd->loader_data = (void *) lot_anim;
106 vfd->no_share = EINA_TRUE;
107 106
108 return vfd; 107 return vfd;
109 108