summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHermet Park <hermetpark@gmail.com>2019-12-10 19:20:49 +0900
committerHermet Park <hermetpark@gmail.com>2019-12-10 19:20:49 +0900
commit3329beef660f4722548e22a854a74b8572ebaee3 (patch)
treef3db4da6510cb76ba265957f0f1b679f6d8edaa9
parent31a8f10418733a3b3998f878e8d0a19347ce132d (diff)
evas ector: applied some memory buffer cache mechanism.
This is a local memory pool mechanism to optimize the filter performance. I observed there are a lot of volatile memory allocations each frames, By using memory pool we can avoid huge memory allocations that brings filter performance up to about 30%.
-rw-r--r--src/lib/evas/canvas/evas_render.c4
-rw-r--r--src/modules/evas/engines/gl_generic/evas_ector_gl.h3
-rw-r--r--src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c159
-rw-r--r--src/modules/evas/engines/gl_generic/evas_engine.c5
4 files changed, 99 insertions, 72 deletions
diff --git a/src/lib/evas/canvas/evas_render.c b/src/lib/evas/canvas/evas_render.c
index 5a627a3..0aea827 100644
--- a/src/lib/evas/canvas/evas_render.c
+++ b/src/lib/evas/canvas/evas_render.c
@@ -3289,7 +3289,6 @@ evas_render_updates_internal(Evas *eo_e,
3289#ifdef EVAS_RENDER_DEBUG_TIMING 3289#ifdef EVAS_RENDER_DEBUG_TIMING
3290 double start_time = _time_get(); 3290 double start_time = _time_get();
3291#endif 3291#endif
3292
3293 double time1, time2; 3292 double time1, time2;
3294 double taccum = 0.06; 3293 double taccum = 0.06;
3295 time1 = _ttime_get(); 3294 time1 = _ttime_get();
@@ -3806,8 +3805,7 @@ evas_render_updates_internal(Evas *eo_e,
3806#endif 3805#endif
3807 3806
3808 time2 = _ttime_get(); 3807 time2 = _ttime_get();
3809 taccum = (taccum + (time2 - time1)) * 0.5; 3808 ERR("elapsed = %f", time2 - time1);
3810 ERR("elapsed = %f", taccum);
3811 3809
3812 if (!do_async) _evas_render_cleanup(); 3810 if (!do_async) _evas_render_cleanup();
3813 eina_evlog("-render_end", eo_e, 0.0, NULL); 3811 eina_evlog("-render_end", eo_e, 0.0, NULL);
diff --git a/src/modules/evas/engines/gl_generic/evas_ector_gl.h b/src/modules/evas/engines/gl_generic/evas_ector_gl.h
index 6e4c46e..5a48292 100644
--- a/src/modules/evas/engines/gl_generic/evas_ector_gl.h
+++ b/src/modules/evas/engines/gl_generic/evas_ector_gl.h
@@ -29,6 +29,9 @@
29#include "evas_ector_gl_buffer.eo.h" 29#include "evas_ector_gl_buffer.eo.h"
30#include "evas_ector_gl_image_buffer.eo.h" 30#include "evas_ector_gl_image_buffer.eo.h"
31 31
32void tizen_vd_ecache_init();
33void tizen_vd_ecache_term();
34
32#undef EAPI 35#undef EAPI
33#define EAPI 36#define EAPI
34 37
diff --git a/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c b/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c
index 2c6c745..638bc94 100644
--- a/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c
+++ b/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c
@@ -20,82 +20,110 @@ typedef struct _Evas_Ector_GL_Buffer_Data Evas_Ector_GL_Buffer_Data;
20 20
21static int _map_id = 0; 21static int _map_id = 0;
22 22
23typedef struct _Buffer_Cache 23////////////////////////////////////////////////////////////////////////
24/* OPTIMIZATION: A Basic Cache Buffer to save memory allocations. */
25/* This first-aid method is applied for VD caption text filter effect */
26////////////////////////////////////////////////////////////////////////
27typedef struct _Ector_Cache_Buffer
24{ 28{
25 char *buffer; 29 void *buffer;
26 int len; 30 int len;
27 Eina_Bool use; 31 Eina_Bool use : 1;
28} Buffer_Cache; 32} Ector_Cache_Buffer;
29 33
30//////////////////////////////////////////////////////////////////////////////////////////////// 34#define BUFFER_CNT 40
31Buffer_Cache _buffer_cache[20]; 35static Eina_Inarray *_ecache_list;
32static int _ector_cnt = 0;
33 36
34char * _ector_buffer_get(int len) 37void
38tizen_vd_ecache_init()
35{ 39{
36 for (int i = 0; i < 10; i++) 40 _ecache_list = eina_inarray_new(sizeof(Ector_Cache_Buffer), 10);
41
42 //Why 40? a experimental number of text filters.
43 eina_inarray_resize(_ecache_list, 40);
44}
45
46void
47tizen_vd_ecache_term()
48{
49 Ector_Cache_Buffer *ecb;
50 EINA_INARRAY_FOREACH(_ecache_list, ecb)
51 free(ecb->buffer);
52
53 eina_inarray_free(_ecache_list);
54 _ecache_list = NULL;
55}
56
57static void *
58_ecache_buffer_request(int len, Eina_Bool clear)
59{
60 //Get Requested size
61 Ector_Cache_Buffer *ecb;
62 EINA_INARRAY_FOREACH(_ecache_list, ecb)
37 { 63 {
38 if (_buffer_cache[i].use) continue; 64 if (ecb->use) continue;
39 if (_buffer_cache[i].len == 0) 65
66 //Get a new buffer
67 if (ecb->len == 0)
40 { 68 {
41 _buffer_cache[i].use = 1; 69 len = (int)(((float) len) * 1.25f);
42 _buffer_cache[i].buffer = malloc(len); 70 ecb->use = EINA_TRUE;
43 _buffer_cache[i].len = len; 71 ecb->buffer = malloc(len);
44 printf("malloc = %d\n", len); 72 ecb->len = len;
45 return _buffer_cache[i].buffer; 73 if (clear) memset(ecb->buffer, 0x0, len);
74 return ecb->buffer;
46 } 75 }
47 76
48 if (_buffer_cache[i].len >= len) 77 //Get an idle buffer
78 if (ecb->len >= len)
49 { 79 {
50 _buffer_cache[i].use = 1; 80 ecb->use = EINA_TRUE;
51 return _buffer_cache[i].buffer; 81 if (clear) memset(ecb->buffer, 0x0, ecb->len);
82 return ecb->buffer;
52 } 83 }
53 else
54 {
55 free(_buffer_cache[i].buffer);
56 _buffer_cache[i].use = 1;
57 _buffer_cache[i].buffer = malloc(len);
58 _buffer_cache[i].len = len;
59 printf("malloc = %d\n", len);
60 84
61 return _buffer_cache[i].buffer; 85 //Get an idle buffer after resizing
62 } 86 len = (int)(((float) len) * 1.25f);
63 printf("What?!\n"); 87 ecb->buffer = realloc(ecb->buffer, len);
88 ecb->use = EINA_TRUE;
89 ecb->len = len;
90 if (clear) memset(ecb->buffer, 0x0, len);
91 return ecb->buffer;
64 } 92 }
65 93
66 return NULL; 94 //Need to push a new item
95 Ector_Cache_Buffer necb;
96 len = (int)(((float) len) * 1.25f);
97 necb.use = EINA_TRUE;
98 necb.buffer = malloc(len);
99 if (clear) memset(necb.buffer, 0x0, len);
100 necb.len = len;
101 eina_inarray_push(_ecache_list, &necb);
102
103 return necb.buffer;
67} 104}
68 105
69void _ector_buffer_return(char *buffer) 106static Eina_Bool
107_ecache_buffer_return(void *buffer)
70{ 108{
71 for (int i = 0; i < 10; i++) 109 //Get Requested size
110 Ector_Cache_Buffer *ecb;
111
112 EINA_INARRAY_FOREACH(_ecache_list, ecb)
72 { 113 {
73 if (_buffer_cache[i].buffer == buffer) 114 if (ecb->buffer == buffer)
74 { 115 {
75 _buffer_cache[i].use = 0; 116 ecb->use = EINA_FALSE;
76 return; 117 return EINA_TRUE;
77 } 118 }
78 } 119 }
79 printf("What?!\n");
80}
81 120
82static void _ector_buffer_term() 121 printf("what?!\n");
83{ 122 return EINA_FALSE;
84 for (int i = 0; i < 10; i++)
85 {
86 free(_buffer_cache[i].buffer);
87 _buffer_cache[i].buffer = NULL;
88 _buffer_cache[i].use = 0;
89 _buffer_cache[i].len = 0;
90 }
91} 123}
92 124////////////////////////////////////////////////////////////////////////
93static void _ector_buffer_init() 125/* End of OPTIMIZATION */
94{ 126////////////////////////////////////////////////////////////////////////
95}
96///////////////////////////////////////////////////////////////////////////////////////////////
97
98
99 127
100 128
101struct _Ector_GL_Buffer_Map 129struct _Ector_GL_Buffer_Map
@@ -231,7 +259,7 @@ on_fail:
231 evas_gl_common_image_free(pd->glim); 259 evas_gl_common_image_free(pd->glim);
232 pd->glim = NULL; 260 pd->glim = NULL;
233 */ 261 */
234 pd->image_data = calloc(1, w * h * 4); 262 pd->image_data = _ecache_buffer_request((w * h * 4), EINA_TRUE);
235 pd->w = w; 263 pd->w = w;
236 pd->h = h; 264 pd->h = h;
237 pd->re = re; 265 pd->re = re;
@@ -271,7 +299,7 @@ _image_get(Evas_Ector_GL_Buffer_Data *pd, Eina_Bool render)
271 if (tofree) 299 if (tofree)
272 evas_gl_common_image_free(old_glim); 300 evas_gl_common_image_free(old_glim);
273 301
274 free(pd->image_data); 302 _ecache_buffer_return(pd->image_data);
275 pd->image_data = NULL; 303 pd->image_data = NULL;
276 } 304 }
277 else 305 else
@@ -433,8 +461,7 @@ _evas_ector_gl_buffer_ector_buffer_map(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buffer
433 len = W * H; 461 len = W * H;
434 if (cspace == EFL_GFX_COLORSPACE_GRY8) 462 if (cspace == EFL_GFX_COLORSPACE_GRY8)
435 { 463 {
436// uint8_t *data8 = _ector_buffer_get(len); 464 uint8_t *data8 = _ecache_buffer_request(len, EINA_FALSE);
437 uint8_t *data8 = malloc(len);
438 if (!data8) goto on_fail; 465 if (!data8) goto on_fail;
439 _pixels_argb_to_gry8_convert(data8, data, len); 466 _pixels_argb_to_gry8_convert(data8, data, len);
440 map->allocated = EINA_TRUE; 467 map->allocated = EINA_TRUE;
@@ -532,7 +559,7 @@ _evas_ector_gl_buffer_ector_buffer_unmap(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buff
532 559
533 if (pd->image_data != map->image_data) 560 if (pd->image_data != map->image_data)
534 { 561 {
535 free(pd->image_data); 562 _ecache_buffer_return(pd->image_data);
536 pd->image_data = map->image_data; 563 pd->image_data = map->image_data;
537 } 564 }
538 565
@@ -547,7 +574,7 @@ _evas_ector_gl_buffer_ector_buffer_unmap(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buff
547 574
548 if (pd->image_data != map->image_data) 575 if (pd->image_data != map->image_data)
549 { 576 {
550 free(pd->image_data); 577 _ecache_buffer_return(pd->image_data);
551 pd->image_data = map->image_data; 578 pd->image_data = map->image_data;
552 } 579 }
553 580
@@ -601,7 +628,7 @@ _evas_ector_gl_buffer_ector_buffer_unmap(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buff
601 628
602 if (pd->image_data != map->image_data) 629 if (pd->image_data != map->image_data)
603 { 630 {
604 free(pd->image_data); 631 _ecache_buffer_return(pd->image_data);
605 pd->image_data = map->image_data; 632 pd->image_data = map->image_data;
606 } 633 }
607 634
@@ -614,7 +641,7 @@ _evas_ector_gl_buffer_ector_buffer_unmap(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buff
614 } 641 }
615 if (map->allocated) 642 if (map->allocated)
616 { 643 {
617 free(map->base_data); 644 _ecache_buffer_return(map->base_data);
618 } 645 }
619 free(map); 646 free(map);
620 return; 647 return;
@@ -625,13 +652,8 @@ _evas_ector_gl_buffer_ector_buffer_unmap(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buff
625} 652}
626 653
627EOLIAN static Efl_Object * 654EOLIAN static Efl_Object *
628_evas_ector_gl_buffer_efl_object_finalize(Eo *obj, Evas_Ector_GL_Buffer_Data *pd) 655_evas_ector_gl_buffer_efl_object_finalize(Eo *obj, Evas_Ector_GL_Buffer_Data *pd EINA_UNUSED)
629{ 656{
630 if (_ector_cnt == 0)
631 _ector_buffer_init();
632
633 ++_ector_cnt;
634// printf("ector_cnt = %d", _ector_cnt);
635 /* TIZEN_ONLY(20181130): evas ector - create a gl image when only it is going to be used 657 /* TIZEN_ONLY(20181130): evas ector - create a gl image when only it is going to be used
636 if (!pd->glim) 658 if (!pd->glim)
637 { 659 {
@@ -646,10 +668,9 @@ _evas_ector_gl_buffer_efl_object_finalize(Eo *obj, Evas_Ector_GL_Buffer_Data *pd
646EOLIAN static void 668EOLIAN static void
647_evas_ector_gl_buffer_efl_object_destructor(Eo *obj, Evas_Ector_GL_Buffer_Data *pd) 669_evas_ector_gl_buffer_efl_object_destructor(Eo *obj, Evas_Ector_GL_Buffer_Data *pd)
648{ 670{
649 --_ector_cnt;
650 evas_gl_common_image_free(pd->glim); 671 evas_gl_common_image_free(pd->glim);
651 /* TIZEN_ONLY(20181130): evas ector - create a gl image when only it is going to be used */ 672 /* TIZEN_ONLY(20181130): evas ector - create a gl image when only it is going to be used */
652 free(pd->image_data); 673 _ecache_buffer_return(pd->image_data);
653 pd->image_data = NULL; 674 pd->image_data = NULL;
654 /* END */ 675 /* END */
655 efl_destructor(efl_super(obj, MY_CLASS)); 676 efl_destructor(efl_super(obj, MY_CLASS));
diff --git a/src/modules/evas/engines/gl_generic/evas_engine.c b/src/modules/evas/engines/gl_generic/evas_engine.c
index 202ce6a..6ff9413 100644
--- a/src/modules/evas/engines/gl_generic/evas_engine.c
+++ b/src/modules/evas/engines/gl_generic/evas_engine.c
@@ -3340,12 +3340,17 @@ module_open(Evas_Module *em)
3340 3340
3341 /* now advertise out own api */ 3341 /* now advertise out own api */
3342 em->functions = (void *)(&func); 3342 em->functions = (void *)(&func);
3343
3344 tizen_vd_ecache_init();
3345
3343 return 1; 3346 return 1;
3344} 3347}
3345 3348
3346static void 3349static void
3347module_close(Evas_Module *em EINA_UNUSED) 3350module_close(Evas_Module *em EINA_UNUSED)
3348{ 3351{
3352 tizen_vd_ecache_term();
3353
3349 ector_shutdown(); 3354 ector_shutdown();
3350 if (_evas_engine_GL_log_dom >= 0) 3355 if (_evas_engine_GL_log_dom >= 0)
3351 { 3356 {