summaryrefslogtreecommitdiff
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
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
-rw-r--r--src/bin/evas/evas_cserve2_scale.c1
-rw-r--r--src/lib/evas/common/evas_draw.h1
-rw-r--r--src/lib/evas/common/evas_draw_main.c117
-rw-r--r--src/lib/evas/filters/evas_filter_utils.c1
-rw-r--r--src/lib/evas/include/evas_common_private.h55
5 files changed, 107 insertions, 68 deletions
diff --git a/src/bin/evas/evas_cserve2_scale.c b/src/bin/evas/evas_cserve2_scale.c
index bf6e9400dc..4a877d88d9 100644
--- a/src/bin/evas/evas_cserve2_scale.c
+++ b/src/bin/evas/evas_cserve2_scale.c
@@ -47,7 +47,6 @@ cserve2_rgba_image_scale_do(void *src_data, int src_full_w, int src_full_h,
47 dst.flags = RGBA_IMAGE_NOTHING; 47 dst.flags = RGBA_IMAGE_NOTHING;
48 48
49 memset(&ct, 0, sizeof(ct)); 49 memset(&ct, 0, sizeof(ct));
50 ct.sli.h = 1;
51 ct.render_op = _EVAS_RENDER_COPY; 50 ct.render_op = _EVAS_RENDER_COPY;
52 51
53 if (smooth) 52 if (smooth)
diff --git a/src/lib/evas/common/evas_draw.h b/src/lib/evas/common/evas_draw.h
index 374b2c799a..6323e8d674 100644
--- a/src/lib/evas/common/evas_draw.h
+++ b/src/lib/evas/common/evas_draw.h
@@ -33,7 +33,6 @@ EAPI void evas_common_draw_context_apply_clean_cutouts (Cutout
33EAPI void evas_common_draw_context_set_anti_alias (RGBA_Draw_Context *dc, unsigned char aa); 33EAPI void evas_common_draw_context_set_anti_alias (RGBA_Draw_Context *dc, unsigned char aa);
34EAPI void evas_common_draw_context_set_color_interpolation (RGBA_Draw_Context *dc, int color_space); 34EAPI void evas_common_draw_context_set_color_interpolation (RGBA_Draw_Context *dc, int color_space);
35EAPI void evas_common_draw_context_set_render_op (RGBA_Draw_Context *dc, int op); 35EAPI void evas_common_draw_context_set_render_op (RGBA_Draw_Context *dc, int op);
36EAPI void evas_common_draw_context_set_sli (RGBA_Draw_Context *dc, int y, int h);
37EAPI void evas_common_draw_context_target_set (RGBA_Draw_Context *dc, int x, int y, int w, int h); 36EAPI void evas_common_draw_context_target_set (RGBA_Draw_Context *dc, int x, int y, int w, int h);
38 37
39#endif /* _EVAS_DRAW_H */ 38#endif /* _EVAS_DRAW_H */
diff --git a/src/lib/evas/common/evas_draw_main.c b/src/lib/evas/common/evas_draw_main.c
index 60ab694e90..6a7c0f75da 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}
diff --git a/src/lib/evas/filters/evas_filter_utils.c b/src/lib/evas/filters/evas_filter_utils.c
index 486532ea9f..1f0869820f 100644
--- a/src/lib/evas/filters/evas_filter_utils.c
+++ b/src/lib/evas/filters/evas_filter_utils.c
@@ -48,7 +48,6 @@ evas_filter_buffer_scaled_get(Evas_Filter_Context *ctx,
48 48
49 // Basic draw context 49 // Basic draw context
50 memset(&dc, 0, sizeof(dc)); 50 memset(&dc, 0, sizeof(dc));
51 dc.sli.h = 1;
52 dc.render_op = EVAS_RENDER_COPY; 51 dc.render_op = EVAS_RENDER_COPY;
53 52
54 // Do the scale 53 // Do the scale
diff --git a/src/lib/evas/include/evas_common_private.h b/src/lib/evas/include/evas_common_private.h
index d52dec5fb3..b256318dbd 100644
--- a/src/lib/evas/include/evas_common_private.h
+++ b/src/lib/evas/include/evas_common_private.h
@@ -744,50 +744,47 @@ struct _Evas_Common_Transform
744struct _RGBA_Draw_Context 744struct _RGBA_Draw_Context
745{ 745{
746 struct { 746 struct {
747 Eina_Bool use : 1; 747 struct {
748 DATA32 col; 748 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg);
749 } mul; 749 void (*gl_free) (void *ext_dat);
750 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y);
751 void *(*gl_image_new_from_data) (void *gc, unsigned int w, unsigned int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace);
752 void (*gl_image_free) (void *image);
753 void (*gl_image_draw) (void *gc, void *im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int smooth);
754 } func;
755 void *data;
756 } font_ext;
750 struct { 757 struct {
751#ifdef HAVE_PIXMAN 758 int x, y, w, h;
752 pixman_image_t *pixman_color_image; 759 } cutout_target;
753#endif
754 DATA32 col;
755 } col;
756 struct RGBA_Draw_Context_clip { 760 struct RGBA_Draw_Context_clip {
757 int x, y, w, h;
758 Evas_Public_Data *evas; // for async unref 761 Evas_Public_Data *evas; // for async unref
759 void *mask; // RGBA_Image (SW) or Evas_GL_Image (GL) 762 void *mask; // RGBA_Image (SW) or Evas_GL_Image (GL)
763 int x, y, w, h;
760 int mask_x, mask_y; 764 int mask_x, mask_y;
761 Eina_Bool use : 1; 765 Eina_Bool use : 1;
762 Eina_Bool async : 1; 766 Eina_Bool async : 1;
763 } clip; 767 } clip;
768 struct {
769#ifdef HAVE_PIXMAN
770 pixman_image_t *pixman_color_image;
771#endif
772 DATA32 col;
773 } col;
764 Cutout_Rects cutout; 774 Cutout_Rects cutout;
765 struct { 775 struct {
766 int x, y, w, h; 776 DATA32 col;
767 } cutout_target; 777 Eina_Bool use : 1;
778 } mul;
768 struct { 779 struct {
769 Cutout_Rects *rects; 780 Cutout_Rects *rects;
770 int used; 781 unsigned int used;
771 } cache; 782 } cache;
772 struct { 783 struct {
773 struct { 784 unsigned char color_space;
774 void *(*gl_new) (void *data, RGBA_Font_Glyph *fg);
775 void (*gl_free) (void *ext_dat);
776 void (*gl_draw) (void *data, void *dest, void *context, RGBA_Font_Glyph *fg, int x, int y);
777 void *(*gl_image_new_from_data) (void *gc, unsigned int w, unsigned int h, DATA32 *image_data, int alpha, Evas_Colorspace cspace);
778 void (*gl_image_free) (void *image);
779 void (*gl_image_draw) (void *gc, void *im, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int smooth);
780 } func;
781 void *data;
782 } font_ext;
783 struct {
784 int color_space;
785 } interpolation; 785 } interpolation;
786 struct { 786 unsigned char render_op;
787 int y, h; 787 unsigned char anti_alias : 1;
788 } sli;
789 int render_op;
790 Eina_Bool anti_alias : 1;
791}; 788};
792 789
793#ifdef BUILD_PIPE_RENDER 790#ifdef BUILD_PIPE_RENDER