summaryrefslogtreecommitdiff
path: root/src/lib/evas/common/evas_draw_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-01-31 14:50:52 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2017-01-31 23:01:50 +0900
commita909ca1f68e178f54c5cc047ddff79d25b2c34c6 (patch)
treeb4f604ded3a6d03f115b42aa62640a261f045401 /src/lib/evas/common/evas_draw_main.c
parentb38c610c7e60cbdcb45fd6d27450e39e3a9c9dd1 (diff)
evas draw context - reduce size and allocations and frees
so a little perf fun shows malloc/free/realloc/etc. are, combined a reasonable overhead. this reduced malloc overhead for draw contexts so whne we duplicate them or create new ones, we re-use a small cache of 8 of them to avoid re-allocation. just take the first one from the list as it really is that simple. mempool would not have helped more here and cost more overhead. @optimize
Diffstat (limited to 'src/lib/evas/common/evas_draw_main.c')
-rw-r--r--src/lib/evas/common/evas_draw_main.c117
1 files changed, 81 insertions, 36 deletions
diff --git a/src/lib/evas/common/evas_draw_main.c b/src/lib/evas/common/evas_draw_main.c
index 60ab694..6a7c0f7 100644
--- a/src/lib/evas/common/evas_draw_main.c
+++ b/src/lib/evas/common/evas_draw_main.c
@@ -18,13 +18,14 @@ evas_common_draw_context_cutouts_dup(Cutout_Rects *rects2, const Cutout_Rects *r
18 rects2->active = rects->active; 18 rects2->active = rects->active;
19 rects2->max = rects->active; 19 rects2->max = rects->active;
20 rects2->last_add = rects->last_add; 20 rects2->last_add = rects->last_add;
21 rects2->rects = NULL;
22 if (rects2->max > 0) 21 if (rects2->max > 0)
23 { 22 {
24 const size_t sz = sizeof(Cutout_Rect) * rects2->max; 23 const size_t sz = sizeof(Cutout_Rect) * rects2->max;
25 rects2->rects = malloc(sz); 24 rects2->rects = malloc(sz);
26 memcpy(rects2->rects, rects->rects, sz); 25 memcpy(rects2->rects, rects->rects, sz);
26 return;
27 } 27 }
28 else rects2->rects = NULL;
28} 29}
29 30
30EAPI void 31EAPI void
@@ -59,12 +60,73 @@ evas_common_draw_context_cutouts_del(Cutout_Rects* rects, int idx)
59} 60}
60 61
61static int _init_count = 0; 62static int _init_count = 0;
63static int _ctxt_spares_count = 0;
64static Eina_List *_ctxt_spares = NULL;
65static SLK(_ctx_spares_lock);
66
67static void
68_evas_common_draw_context_real_free(RGBA_Draw_Context *dc)
69{
70#ifdef HAVE_PIXMAN
71# if defined(PIXMAN_FONT) || defined(PIXMAN_RECT) || defined(PIXMAN_LINE) || defined(PIXMAN_POLY)
72 if (dc->col.pixman_color_image)
73 pixman_image_unref(dc->col.pixman_color_image);
74# endif
75#endif
76 evas_common_draw_context_apply_clean_cutouts(&dc->cutout);
77 evas_common_draw_context_cutouts_real_free(dc->cache.rects);
78 free(dc);
79}
80
81static void
82_evas_common_draw_context_stash(RGBA_Draw_Context *dc)
83{
84 if (_ctxt_spares_count < 8)
85 {
86#ifdef HAVE_PIXMAN
87# if defined(PIXMAN_FONT) || defined(PIXMAN_RECT) || defined(PIXMAN_LINE) || defined(PIXMAN_POLY)
88 if (dc->col.pixman_color_image)
89 {
90 pixman_image_unref(dc->col.pixman_color_image);
91 dc->col.pixman_color_image = NULL;
92 }
93# endif
94#endif
95 evas_common_draw_context_apply_clean_cutouts(&dc->cutout);
96 evas_common_draw_context_cutouts_real_free(dc->cache.rects);
97 SLKL(_ctx_spares_lock);
98 _ctxt_spares = eina_list_prepend(_ctxt_spares, dc);
99 _ctxt_spares_count++;
100 SLKU(_ctx_spares_lock);
101 return;
102 }
103 _evas_common_draw_context_real_free(dc);
104}
105
106static RGBA_Draw_Context *
107_evas_common_draw_context_find(void)
108{
109 RGBA_Draw_Context *dc;
110
111 if (_ctxt_spares)
112 {
113 SLKL(_ctx_spares_lock);
114 dc = _ctxt_spares->data;
115 _ctxt_spares = eina_list_remove_list(_ctxt_spares, _ctxt_spares);
116 _ctxt_spares_count--;
117 SLKU(_ctx_spares_lock);
118 return dc;
119 }
120 dc = malloc(sizeof(RGBA_Draw_Context));
121 return dc;
122}
62 123
63EAPI void 124EAPI void
64evas_common_init(void) 125evas_common_init(void)
65{ 126{
66 if (_init_count++) return ; 127 if (_init_count++) return;
67 128
129 SLKI(_ctx_spares_lock);
68 evas_common_cpu_init(); 130 evas_common_cpu_init();
69 131
70 evas_common_blend_init(); 132 evas_common_blend_init();
@@ -83,13 +145,20 @@ evas_common_init(void)
83EAPI void 145EAPI void
84evas_common_shutdown(void) 146evas_common_shutdown(void)
85{ 147{
86 if (--_init_count) return ; 148 if (--_init_count) return;
87 149
88 evas_font_dir_cache_free(); 150 evas_font_dir_cache_free();
89 evas_common_font_shutdown(); 151 evas_common_font_shutdown();
90 evas_common_image_shutdown(); 152 evas_common_image_shutdown();
91 evas_common_image_cache_free(); 153 evas_common_image_cache_free();
92 evas_common_scale_sample_shutdown(); 154 evas_common_scale_sample_shutdown();
155// just in case any thread is still doing things... don't del this here
156// RGBA_Draw_Context *dc;
157// SLKL(_ctx_spares_lock);
158// EINA_LIST_FREE(_ctxt_spares, dc) _evas_common_draw_context_real_free(dc);
159// _ctxt_spares_count = 0;
160// SLKU(_ctx_spares_lock);
161// SLKD(_ctx_spares_lock);
93} 162}
94 163
95EAPI void 164EAPI void
@@ -101,31 +170,27 @@ EAPI RGBA_Draw_Context *
101evas_common_draw_context_new(void) 170evas_common_draw_context_new(void)
102{ 171{
103 RGBA_Draw_Context *dc; 172 RGBA_Draw_Context *dc;
104 173 dc = _evas_common_draw_context_find();
105 dc = calloc(1, sizeof(RGBA_Draw_Context)); 174 if (!dc) return NULL;
106 dc->sli.h = 1; 175 memset(dc, 0, sizeof(RGBA_Draw_Context));
107 return dc; 176 return dc;
108} 177}
109 178
110EAPI RGBA_Draw_Context * 179EAPI RGBA_Draw_Context *
111evas_common_draw_context_dup(RGBA_Draw_Context *dc) 180evas_common_draw_context_dup(RGBA_Draw_Context *dc)
112{ 181{
113 RGBA_Draw_Context *dc2; 182 RGBA_Draw_Context *dc2 = _evas_common_draw_context_find();
114 183
115 if (!dc) return evas_common_draw_context_new(); 184 if (!dc) return dc2;
116 dc2 = malloc(sizeof(RGBA_Draw_Context));
117 memcpy(dc2, dc, sizeof(RGBA_Draw_Context)); 185 memcpy(dc2, dc, sizeof(RGBA_Draw_Context));
118 evas_common_draw_context_cutouts_dup(&dc2->cutout, &dc->cutout); 186 evas_common_draw_context_cutouts_dup(&dc2->cutout, &dc->cutout);
119#ifdef HAVE_PIXMAN 187#ifdef HAVE_PIXMAN
120#if defined(PIXMAN_FONT) || defined(PIXMAN_RECT) || defined(PIXMAN_LINE) || defined(PIXMAN_POLY) 188# if defined(PIXMAN_FONT) || defined(PIXMAN_RECT) || defined(PIXMAN_LINE) || defined(PIXMAN_POLY)
121 if (dc2->col.pixman_color_image) 189 dc2->col.pixman_color_image = NULL;
122 pixman_image_ref(dc2->col.pixman_color_image); 190# endif
123#endif
124#endif 191#endif
125
126 dc2->cache.rects = NULL; 192 dc2->cache.rects = NULL;
127 dc2->cache.used = 0; 193 dc2->cache.used = 0;
128
129 return dc2; 194 return dc2;
130} 195}
131 196
@@ -133,20 +198,7 @@ EAPI void
133evas_common_draw_context_free(RGBA_Draw_Context *dc) 198evas_common_draw_context_free(RGBA_Draw_Context *dc)
134{ 199{
135 if (!dc) return; 200 if (!dc) return;
136 201 _evas_common_draw_context_stash(dc);
137#ifdef HAVE_PIXMAN
138#if defined(PIXMAN_FONT) || defined(PIXMAN_RECT) || defined(PIXMAN_LINE) || defined(PIXMAN_POLY)
139 if (dc->col.pixman_color_image)
140 {
141 pixman_image_unref(dc->col.pixman_color_image);
142 dc->col.pixman_color_image = NULL;
143 }
144#endif
145#endif
146
147 evas_common_draw_context_apply_clean_cutouts(&dc->cutout);
148 evas_common_draw_context_cutouts_real_free(dc->cache.rects);
149 free(dc);
150} 202}
151 203
152EAPI void 204EAPI void
@@ -814,10 +866,3 @@ evas_common_draw_context_set_render_op(RGBA_Draw_Context *dc , int op)
814{ 866{
815 dc->render_op = op; 867 dc->render_op = op;
816} 868}
817
818EAPI void
819evas_common_draw_context_set_sli(RGBA_Draw_Context *dc, int y, int h)
820{
821 dc->sli.y = y;
822 dc->sli.h = h;
823}