summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-01-05 17:56:04 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-01-17 14:35:29 +0900
commit93965db815d7ca1e3951b7cda9f74e821975d648 (patch)
tree5df9f929c30af74f97f4f5f24f4d071f2a732137
parent1512741b488e212c825ccc78d626d8f666ab1344 (diff)
evas: Implement filter sources support for textblock
-rw-r--r--src/bin/elementary/test_gfx_filters.c24
-rw-r--r--src/lib/evas/canvas/efl_canvas_text.eo1
-rw-r--r--src/lib/evas/canvas/evas_filter_mixin.c6
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c65
-rw-r--r--src/lib/evas/include/evas_filter.h3
5 files changed, 92 insertions, 7 deletions
diff --git a/src/bin/elementary/test_gfx_filters.c b/src/bin/elementary/test_gfx_filters.c
index 1fc2cfd410..755405ecfd 100644
--- a/src/bin/elementary/test_gfx_filters.c
+++ b/src/bin/elementary/test_gfx_filters.c
@@ -25,7 +25,7 @@ static const Filter_Image images[] = {
25 { "sky_01.jpg", "sky" }, 25 { "sky_01.jpg", "sky" },
26 { "sky_04.jpg", "cloud" }, 26 { "sky_04.jpg", "cloud" },
27 { "wood_01.jpg", "wood" }, 27 { "wood_01.jpg", "wood" },
28 { "icon_00.png", "love" }, 28 { "animated_logo.gif", "logo" },
29 { NULL, NULL } 29 { NULL, NULL }
30}; 30};
31 31
@@ -39,6 +39,11 @@ static const Filter_Image images_cloud[] = {
39 { NULL, NULL }, 39 { NULL, NULL },
40}; 40};
41 41
42static const Filter_Image images_anim[] = {
43 { "animated_logo.gif", "logo" },
44 { NULL, NULL },
45};
46
42/* builtin filter examples */ 47/* builtin filter examples */
43static const Filter templates[] = { 48static const Filter templates[] = {
44 { "Custom", NULL, NULL }, 49 { "Custom", NULL, NULL },
@@ -104,6 +109,13 @@ static const Filter templates[] = {
104 { "Displaced cloud", 109 { "Displaced cloud",
105 "cloud = buffer { src = 'cloud' }\n" 110 "cloud = buffer { src = 'cloud' }\n"
106 "displace { cloud, intensity = 10, fillmode = 'stretch' }", images_cloud }, 111 "displace { cloud, intensity = 10, fillmode = 'stretch' }", images_cloud },
112 { "Animated ugliness",
113 "logo = buffer { src = 'logo' }\n"
114 "blend { logo, fillmode = 'repeat' }\n"
115 "a = buffer {}\n"
116 "grow { 5, dst = a }\n"
117 "blur { 5, src = a, color = 'darkblue' }\n"
118 "blend { color = 'yellow' }", images_anim }
107}; 119};
108 120
109 121
@@ -139,10 +151,11 @@ static void
139_spinner_cb(void *data, const Efl_Event *ev EINA_UNUSED) 151_spinner_cb(void *data, const Efl_Event *ev EINA_UNUSED)
140{ 152{
141 Eo *win = data; 153 Eo *win = data;
142 Eo *text, *code, *spinner; 154 Eo *text, *code, *spinner, *tb;
143 int k; 155 int k;
144 156
145 text = efl_key_wref_get(win, "text"); 157 text = efl_key_wref_get(win, "text");
158 tb = efl_key_wref_get(win, "textblock");
146 code = efl_key_wref_get(win, "code"); 159 code = efl_key_wref_get(win, "code");
147 spinner = efl_key_wref_get(win, "spinner"); 160 spinner = efl_key_wref_get(win, "spinner");
148 k = (int) round(elm_spinner_value_get(spinner)); 161 k = (int) round(elm_spinner_value_get(spinner));
@@ -160,6 +173,7 @@ _spinner_cb(void *data, const Efl_Event *ev EINA_UNUSED)
160 const char *name = f->images[j].src_name; 173 const char *name = f->images[j].src_name;
161 Eo *source_obj = efl_name_find(win, name); 174 Eo *source_obj = efl_name_find(win, name);
162 efl_gfx_filter_source_set(text, name, source_obj); 175 efl_gfx_filter_source_set(text, name, source_obj);
176 efl_gfx_filter_source_set(tb, name, source_obj);
163 } 177 }
164 } 178 }
165 } 179 }
@@ -228,7 +242,7 @@ _img_click(void *data, const Efl_Event *ev)
228 Eina_Strbuf *buf; 242 Eina_Strbuf *buf;
229 Eo *win = data; 243 Eo *win = data;
230 Eo *img = ev->object; 244 Eo *img = ev->object;
231 Eo *code, *text; 245 Eo *code, *text, *tb;
232 const char *name; 246 const char *name;
233 247
234 name = efl_name_get(img); 248 name = efl_name_get(img);
@@ -236,6 +250,7 @@ _img_click(void *data, const Efl_Event *ev)
236 250
237 code = efl_key_wref_get(win, "code"); 251 code = efl_key_wref_get(win, "code");
238 text = efl_key_wref_get(win, "text"); 252 text = efl_key_wref_get(win, "text");
253 tb = efl_key_wref_get(win, "textblock");
239 254
240 buf = eina_strbuf_new(); 255 buf = eina_strbuf_new();
241 eina_strbuf_append_printf(buf, "%s = buffer { src = '%s' }\n", name, name); 256 eina_strbuf_append_printf(buf, "%s = buffer { src = '%s' }\n", name, name);
@@ -245,6 +260,7 @@ _img_click(void *data, const Efl_Event *ev)
245 eina_strbuf_free(buf); 260 eina_strbuf_free(buf);
246 261
247 efl_gfx_filter_source_set(text, name, ev->object); 262 efl_gfx_filter_source_set(text, name, ev->object);
263 efl_gfx_filter_source_set(tb, name, ev->object);
248} 264}
249 265
250static void 266static void
@@ -369,6 +385,8 @@ test_gfx_filters(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *eve
369 efl_name_set(efl_added, images[k].src_name), 385 efl_name_set(efl_added, images[k].src_name),
370 elm_object_tooltip_text_set(efl_added, images[k].src_name), 386 elm_object_tooltip_text_set(efl_added, images[k].src_name),
371 efl_gfx_visible_set(efl_added, 1)); 387 efl_gfx_visible_set(efl_added, 1));
388 if (efl_player_playable_get(o))
389 efl_player_play_set(o, 1);
372 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _img_click, win); 390 efl_event_callback_add(o, EFL_UI_EVENT_CLICKED, _img_click, win);
373 efl_pack(box2, o); 391 efl_pack(box2, o);
374 } 392 }
diff --git a/src/lib/evas/canvas/efl_canvas_text.eo b/src/lib/evas/canvas/efl_canvas_text.eo
index e39544ee54..c018d11fca 100644
--- a/src/lib/evas/canvas/efl_canvas_text.eo
+++ b/src/lib/evas/canvas/efl_canvas_text.eo
@@ -369,6 +369,7 @@ class Efl.Canvas.Text (Efl.Canvas.Object, Efl.Text, Efl.Canvas.Filter.Internal)
369 Efl.Text.text { get; set; } 369 Efl.Text.text { get; set; }
370 Efl.Gfx.Filter.filter_program { get; set; } 370 Efl.Gfx.Filter.filter_program { get; set; }
371 Efl.Gfx.Filter.filter_data { get; set; } 371 Efl.Gfx.Filter.filter_data { get; set; }
372 Efl.Gfx.Filter.filter_source { get; set; }
372 Efl.Canvas.Filter.Internal.filter_dirty; 373 Efl.Canvas.Filter.Internal.filter_dirty;
373 Efl.Canvas.Filter.Internal.filter_input_render; 374 Efl.Canvas.Filter.Internal.filter_input_render;
374 Efl.Canvas.Filter.Internal.filter_state_prepare; 375 Efl.Canvas.Filter.Internal.filter_state_prepare;
diff --git a/src/lib/evas/canvas/evas_filter_mixin.c b/src/lib/evas/canvas/evas_filter_mixin.c
index 1f6ea23216..d28280b7bb 100644
--- a/src/lib/evas/canvas/evas_filter_mixin.c
+++ b/src/lib/evas/canvas/evas_filter_mixin.c
@@ -107,8 +107,8 @@ _filter_cb(Evas_Filter_Context *ctx, void *data, Eina_Bool success)
107 evas_post_render_job_add(obj->layer->evas, _filter_async_post_render_cb, post_data); 107 evas_post_render_job_add(obj->layer->evas, _filter_async_post_render_cb, post_data);
108} 108}
109 109
110static void 110void
111_filter_source_hash_free_cb(void *data) 111_evas_filter_source_hash_free_cb(void *data)
112{ 112{
113 Evas_Filter_Proxy_Binding *pb = data; 113 Evas_Filter_Proxy_Binding *pb = data;
114 Evas_Object_Protected_Data *proxy, *source; 114 Evas_Object_Protected_Data *proxy, *source;
@@ -423,7 +423,7 @@ _efl_canvas_filter_internal_efl_gfx_filter_filter_source_set(Eo *eo_obj, Evas_Fi
423 423
424 fcow = FCOW_BEGIN(pd); 424 fcow = FCOW_BEGIN(pd);
425 if (!fcow->sources) 425 if (!fcow->sources)
426 fcow->sources = eina_hash_string_small_new(EINA_FREE_CB(_filter_source_hash_free_cb)); 426 fcow->sources = eina_hash_string_small_new(_evas_filter_source_hash_free_cb);
427 else if (pb_old) 427 else if (pb_old)
428 eina_hash_del(fcow->sources, name, pb_old); 428 eina_hash_del(fcow->sources, name, pb_old);
429 429
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index bec6c8857c..ca0ef1a00b 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -598,6 +598,7 @@ struct _Evas_Object_Textblock
598 struct { 598 struct {
599 Efl_Canvas_Text_Filter_Program *programs; 599 Efl_Canvas_Text_Filter_Program *programs;
600 Evas_Filter_Data_Binding *data_bindings; 600 Evas_Filter_Data_Binding *data_bindings;
601 Eina_Hash *sources;
601 } gfx_filter; 602 } gfx_filter;
602 Eina_Bool redraw : 1; 603 Eina_Bool redraw : 1;
603 Eina_Bool changed : 1; 604 Eina_Bool changed : 1;
@@ -4378,6 +4379,7 @@ _format_filter_program_get(Efl_Canvas_Text_Data *o, Evas_Object_Textblock_Format
4378 { 4379 {
4379 pgm = evas_filter_program_new(program->name, EINA_FALSE); 4380 pgm = evas_filter_program_new(program->name, EINA_FALSE);
4380 evas_filter_program_data_set_all(pgm, EINA_INLIST_GET(o->gfx_filter.data_bindings)); 4381 evas_filter_program_data_set_all(pgm, EINA_INLIST_GET(o->gfx_filter.data_bindings));
4382 evas_filter_program_source_set_all(pgm, o->gfx_filter.sources);
4381 if (!evas_filter_program_parse(pgm, program->code)) 4383 if (!evas_filter_program_parse(pgm, program->code))
4382 { 4384 {
4383 evas_filter_program_del(pgm); 4385 evas_filter_program_del(pgm);
@@ -12875,6 +12877,7 @@ evas_object_textblock_free(Evas_Object *eo_obj)
12875 eina_stringshare_del(db->value); 12877 eina_stringshare_del(db->value);
12876 free(db); 12878 free(db);
12877 } 12879 }
12880 eina_hash_free(o->gfx_filter.sources);
12878 12881
12879 while (evas_object_textblock_style_user_peek(eo_obj)) 12882 while (evas_object_textblock_style_user_peek(eo_obj))
12880 { 12883 {
@@ -13285,7 +13288,6 @@ evas_object_textblock_render(Evas_Object *eo_obj EINA_UNUSED,
13285 filter->contexts = eina_array_new(8); 13288 filter->contexts = eina_array_new(8);
13286 filter_id = eina_array_count(filter->contexts); 13289 filter_id = eina_array_count(filter->contexts);
13287 13290
13288 // TODO: sources set
13289 ctx = evas_filter_context_new(obj->layer->evas, do_async, filter_id); 13291 ctx = evas_filter_context_new(obj->layer->evas, do_async, filter_id);
13290 evas_filter_state_prepare(eo_obj, &state, ti); 13292 evas_filter_state_prepare(eo_obj, &state, ti);
13291 evas_filter_program_state_set(pgm, &state); 13293 evas_filter_program_state_set(pgm, &state);
@@ -13309,6 +13311,7 @@ evas_object_textblock_render(Evas_Object *eo_obj EINA_UNUSED,
13309 evas_filter_program_padding_get(pgm, 13311 evas_filter_program_padding_get(pgm,
13310 &filter->pad.l, &filter->pad.r, 13312 &filter->pad.l, &filter->pad.r,
13311 &filter->pad.t, &filter->pad.b); 13313 &filter->pad.t, &filter->pad.b);
13314 evas_filter_context_proxy_render_all(ctx, eo_obj, EINA_FALSE);
13312 evas_filter_context_buffers_allocate_all(ctx); 13315 evas_filter_context_buffers_allocate_all(ctx);
13313 evas_filter_target_set(ctx, context, surface, 13316 evas_filter_target_set(ctx, context, surface,
13314 obj->cur->geometry.x + ln->x + ti->parent.x + x - filter->pad.l, 13317 obj->cur->geometry.x + ln->x + ti->parent.x + x - filter->pad.l,
@@ -13776,6 +13779,66 @@ _efl_canvas_text_efl_gfx_filter_filter_data_get(Eo *obj EINA_UNUSED, Efl_Canvas_
13776 if (execute) *execute = db->execute; 13779 if (execute) *execute = db->execute;
13777} 13780}
13778 13781
13782EOLIAN static void
13783_efl_canvas_text_efl_gfx_filter_filter_source_set(Eo *eo_obj, Efl_Canvas_Text_Data *pd, const char *name, Efl_Gfx *eo_source)
13784{
13785 Evas_Object_Protected_Data *obj, *source;
13786 Evas_Filter_Proxy_Binding *pb;
13787
13788 if (!name) return;
13789
13790 obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
13791 source = efl_data_scope_get(eo_source, EFL_CANVAS_OBJECT_CLASS);
13792 evas_object_async_block(obj);
13793
13794 pb = eina_hash_find(pd->gfx_filter.sources, name);
13795 if (pb)
13796 {
13797 if (pb->eo_source == eo_source) return;
13798 eina_hash_del(pd->gfx_filter.sources, name, pb);
13799 }
13800 else if (!eo_source)
13801 {
13802 return;
13803 }
13804 else
13805 {
13806 pb = calloc(1, sizeof(*pb));
13807 pb->eo_proxy = eo_obj;
13808 pb->eo_source = eo_source;
13809 pb->name = eina_stringshare_add(name);
13810 }
13811
13812 if (!pd->gfx_filter.sources)
13813 pd->gfx_filter.sources = eina_hash_string_small_new(_evas_filter_source_hash_free_cb);
13814 eina_hash_set(pd->gfx_filter.sources, name, pb);
13815
13816 if (!eina_list_data_find(source->proxy->proxies, eo_obj))
13817 {
13818 EINA_COW_WRITE_BEGIN(evas_object_proxy_cow, source->proxy, Evas_Object_Proxy_Data, source_write)
13819 source_write->proxies = eina_list_append(source_write->proxies, eo_obj);
13820 EINA_COW_WRITE_END(evas_object_proxy_cow, source->proxy, source_write)
13821 }
13822
13823 if (!obj->proxy->is_proxy)
13824 {
13825 EINA_COW_WRITE_BEGIN(evas_object_proxy_cow, obj->proxy, Evas_Object_Proxy_Data, proxy_write)
13826 proxy_write->is_proxy = EINA_TRUE;
13827 EINA_COW_WRITE_END(evas_object_proxy_cow, obj->proxy, proxy_write)
13828 }
13829
13830 pd->format_changed = EINA_TRUE;
13831 _evas_textblock_invalidate_all(pd);
13832 _evas_textblock_changed(pd, eo_obj);
13833 evas_object_change(eo_obj, obj);
13834}
13835
13836EOLIAN static Efl_Gfx *
13837_efl_canvas_text_efl_gfx_filter_filter_source_get(Eo *obj EINA_UNUSED, Efl_Canvas_Text_Data *pd, const char *name)
13838{
13839 return eina_hash_find(pd->gfx_filter.sources, name);
13840}
13841
13779static void 13842static void
13780evas_object_textblock_coords_recalc(Evas_Object *eo_obj, 13843evas_object_textblock_coords_recalc(Evas_Object *eo_obj,
13781 Evas_Object_Protected_Data *obj, 13844 Evas_Object_Protected_Data *obj,
diff --git a/src/lib/evas/include/evas_filter.h b/src/lib/evas/include/evas_filter.h
index 75a80a92d7..0ee3f30e9d 100644
--- a/src/lib/evas/include/evas_filter.h
+++ b/src/lib/evas/include/evas_filter.h
@@ -157,6 +157,9 @@ Eina_Bool evas_filter_font_draw(Evas_Filter_Context *ctx, void *d
157Eina_Bool evas_filter_image_draw(Evas_Filter_Context *ctx, void *draw_context, int bufid, void *image, Eina_Bool do_async); 157Eina_Bool evas_filter_image_draw(Evas_Filter_Context *ctx, void *draw_context, int bufid, void *image, Eina_Bool do_async);
158Eina_Bool evas_filter_target_set(Evas_Filter_Context *ctx, void *draw_context, void *surface, int x, int y); 158Eina_Bool evas_filter_target_set(Evas_Filter_Context *ctx, void *draw_context, void *surface, int x, int y);
159 159
160// utility function
161void _evas_filter_source_hash_free_cb(void *data);
162
160/** 163/**
161 * @brief Blend a source buffer into a destination buffer, allowing X,Y offsets, Alpha to RGBA conversion with color 164 * @brief Blend a source buffer into a destination buffer, allowing X,Y offsets, Alpha to RGBA conversion with color
162 * @param ctx Current filter chain 165 * @param ctx Current filter chain