summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAli Alzyod <ali198724@gmail.com>2020-05-04 15:25:07 -0400
committerMike Blumenkrantz <zmike@samsung.com>2020-05-04 15:25:07 -0400
commit3dff471826e815429c2cdc9b22df848bfad26e6c (patch)
treebdaa18feba5cceba447255146cc3f4946be00601
parent3c619b96fc8b9e68c0ba4c7f191465ea7f1a428e (diff)
evas_textblock: optimize calculate main format once in layout setup stage
Summary: This change based on discussion on D9533 , where @smohanty example shows that unnecessary calculation happened on textblock related to lay-outing Where now _layout_setup will not calculate main format using (_format_fill) unless style has been changed. expedite commit: https://git.enlightenment.org/tools/expedite.git/commit/?id=dc6c931dc2e6c240d3e240f24578980c689ab7fc src/bin/textblock_text_fill_format.c Test Plan: ``` #define EFL_EO_API_SUPPORT 1 #define EFL_BETA_API_SUPPORT 1 #include <Eina.h> #include <Efl.h> #include <Elementary.h> EAPI_MAIN int elm_main(int argc, char **argv) { Evas_Object *win, *textblock; elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); win = elm_win_util_standard_add("Main", "App"); elm_win_autodel_set(win, EINA_TRUE); int l, r, t, b; textblock = evas_object_textblock_add(evas_object_evas_get(win)); Evas_Textblock_Style *st = evas_textblock_style_new(); evas_textblock_style_set (st, "DEFAULT='font=Sans font_size=10 color=#000000 wrap=word align=left outline_color=#000 shadow_color=#fff8 shadow_color=#0002 glow2_color=#fe87 glow_color=#f214 underline_color=#00f linesize=40'"); evas_object_textblock_style_set(textblock, st); int sizes[] = {600, 700}; evas_object_textblock_text_markup_set(textblock, "This test resize text block and keep style (style parsed only once)"); clock_t start, end; start = clock(); for (int i = 0; i < 10000; i++) { evas_object_resize(textblock, sizes[i % 2], sizes[i % 2]); evas_object_textblock_style_insets_get(textblock, &l, &r, &t, &b); } end = clock(); double total_Time1 = ((double)(end - start)) / CLOCKS_PER_SEC; printf("total time = %f\n", total_Time1); evas_object_size_hint_weight_set(textblock, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(textblock, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(textblock); evas_object_move(textblock, 0, 0); evas_object_resize(textblock, 640, 800); evas_object_resize(win, 640, 800); evas_object_show(win); elm_run(); return 0; } ELM_MAIN() ``` **Old Code output : total time = 0.096900 New Code output : total time = 0.045580** Reviewers: smohanty, woohyun, Hermet, bowonryu, cedric, bu5hm4n, zmike Reviewed By: zmike Subscribers: zmike, segfaultxavi, bu5hm4n, smohanty, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D9536
-rw-r--r--src/lib/evas/canvas/evas_object_textblock.c35
-rw-r--r--src/tests/evas/evas_test_textblock.c10
2 files changed, 42 insertions, 3 deletions
diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c
index 78ccec4d41..932e4dd41a 100644
--- a/src/lib/evas/canvas/evas_object_textblock.c
+++ b/src/lib/evas/canvas/evas_object_textblock.c
@@ -500,6 +500,7 @@ struct _Evas_Object_Textblock
500 } default_format; 500 } default_format;
501 double valign; 501 double valign;
502 Eina_Stringshare *markup_text; 502 Eina_Stringshare *markup_text;
503 Evas_Object_Textblock_Format *main_fmt;
503 char *utf8; 504 char *utf8;
504 void *engine_data; 505 void *engine_data;
505 const char *repch; 506 const char *repch;
@@ -7631,6 +7632,7 @@ _layout_setup(Ctxt *c, const Eo *eo_obj, Evas_Coord w, Evas_Coord h)
7631 7632
7632 /* Start of logical layout creation */ 7633 /* Start of logical layout creation */
7633 /* setup default base style */ 7634 /* setup default base style */
7635 if (!o->main_fmt) /* no main format */
7634 { 7636 {
7635 Eina_List *itr; 7637 Eina_List *itr;
7636 User_Style_Entry *use; 7638 User_Style_Entry *use;
@@ -7662,6 +7664,11 @@ _layout_setup(Ctxt *c, const Eo *eo_obj, Evas_Coord w, Evas_Coord h)
7662 7664
7663 if (finalize) 7665 if (finalize)
7664 _format_finalize(c->obj, c->fmt); 7666 _format_finalize(c->obj, c->fmt);
7667 o->main_fmt = _format_dup(c->obj, c->fmt);
7668 }
7669 else
7670 {
7671 c->fmt = _layout_format_push(c, o->main_fmt, NULL);
7665 } 7672 }
7666 if (!c->fmt) 7673 if (!c->fmt)
7667 { 7674 {
@@ -7948,7 +7955,17 @@ evas_textblock_style_free(Evas_Textblock_Style *ts)
7948} 7955}
7949 7956
7950static void 7957static void
7951_evas_textblock_update_format_nodes_from_style_tag(Efl_Canvas_Textblock_Data *o) 7958_evas_clear_main_format(Evas_Object *eo_obj, Efl_Canvas_Textblock_Data *o)
7959{
7960 if (o->main_fmt)
7961 {
7962 _format_unref_free(efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS), o->main_fmt);
7963 o->main_fmt = NULL;
7964 }
7965}
7966
7967static void
7968_evas_textblock_update_format_nodes_from_style_tag(Evas_Object *eo_obj, Efl_Canvas_Textblock_Data *o)
7952{ 7969{
7953 if (!o) 7970 if (!o)
7954 { 7971 {
@@ -7956,6 +7973,8 @@ _evas_textblock_update_format_nodes_from_style_tag(Efl_Canvas_Textblock_Data *o)
7956 return; 7973 return;
7957 } 7974 }
7958 7975
7976 _evas_clear_main_format(eo_obj, o);
7977
7959 Evas_Object_Textblock_Node_Format *fnode = o->format_nodes; 7978 Evas_Object_Textblock_Node_Format *fnode = o->format_nodes;
7960 7979
7961 while (fnode) 7980 while (fnode)
@@ -8110,7 +8129,7 @@ evas_textblock_style_set(Evas_Textblock_Style *ts, const char *text)
8110 EINA_LIST_FOREACH(ts->objects, l, eo_obj) 8129 EINA_LIST_FOREACH(ts->objects, l, eo_obj)
8111 { 8130 {
8112 Efl_Canvas_Textblock_Data *o = efl_data_scope_get(eo_obj, MY_CLASS); 8131 Efl_Canvas_Textblock_Data *o = efl_data_scope_get(eo_obj, MY_CLASS);
8113 _evas_textblock_update_format_nodes_from_style_tag(o); 8132 _evas_textblock_update_format_nodes_from_style_tag(eo_obj, o);
8114 _evas_textblock_invalidate_all(o); 8133 _evas_textblock_invalidate_all(o);
8115 _evas_textblock_changed(o, eo_obj); 8134 _evas_textblock_changed(o, eo_obj);
8116 } 8135 }
@@ -8167,6 +8186,8 @@ _textblock_style_generic_set(Evas_Object *eo_obj, Evas_Textblock_Style *ts,
8167 Eina_List *itr; 8186 Eina_List *itr;
8168 Evas_Textblock_Style *old_ts = NULL; 8187 Evas_Textblock_Style *old_ts = NULL;
8169 8188
8189 _evas_clear_main_format(eo_obj, o);
8190
8170 if (!key) 8191 if (!key)
8171 { 8192 {
8172 old_ts = o->style; 8193 old_ts = o->style;
@@ -8234,7 +8255,7 @@ _textblock_style_generic_set(Evas_Object *eo_obj, Evas_Textblock_Style *ts,
8234 ts->objects = eina_list_append(ts->objects, eo_obj); 8255 ts->objects = eina_list_append(ts->objects, eo_obj);
8235 } 8256 }
8236 8257
8237 _evas_textblock_update_format_nodes_from_style_tag(o); 8258 _evas_textblock_update_format_nodes_from_style_tag(eo_obj, o);
8238 8259
8239 o->format_changed = EINA_TRUE; 8260 o->format_changed = EINA_TRUE;
8240 _evas_textblock_invalidate_all(o); 8261 _evas_textblock_invalidate_all(o);
@@ -8273,6 +8294,7 @@ _efl_canvas_textblock_style_apply(Eo *eo_obj, Efl_Canvas_Textblock_Data *o, cons
8273{ 8294{
8274 Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); 8295 Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
8275 evas_object_async_block(obj); 8296 evas_object_async_block(obj);
8297 _evas_clear_main_format(eo_obj, o);
8276 _format_fill(eo_obj, &(o->default_format.format), style, EINA_TRUE); 8298 _format_fill(eo_obj, &(o->default_format.format), style, EINA_TRUE);
8277} 8299}
8278 8300
@@ -11645,6 +11667,10 @@ _evas_textblock_changed(Efl_Canvas_Textblock_Data *o, Evas_Object *eo_obj)
11645 o->markup_text = NULL; 11667 o->markup_text = NULL;
11646 } 11668 }
11647 } 11669 }
11670 else
11671 {
11672 _evas_clear_main_format(eo_obj, o);
11673 }
11648 11674
11649 // FIXME: emit ONCE after this following checks 11675 // FIXME: emit ONCE after this following checks
11650 _cursor_emit_if_changed(o->cursor); 11676 _cursor_emit_if_changed(o->cursor);
@@ -14616,6 +14642,8 @@ evas_object_textblock_free(Evas_Object *eo_obj)
14616 o->fit_content_config.p_size_array = NULL; 14642 o->fit_content_config.p_size_array = NULL;
14617 } 14643 }
14618 14644
14645 _evas_clear_main_format(eo_obj, o);
14646
14619#ifdef HAVE_HYPHEN 14647#ifdef HAVE_HYPHEN
14620 /* Hyphenation */ 14648 /* Hyphenation */
14621 if (o->hyphenating) 14649 if (o->hyphenating)
@@ -16393,6 +16421,7 @@ static void
16393_canvas_text_format_changed(Eo *eo_obj, Efl_Canvas_Textblock_Data *o) 16421_canvas_text_format_changed(Eo *eo_obj, Efl_Canvas_Textblock_Data *o)
16394{ 16422{
16395 o->format_changed = EINA_TRUE; 16423 o->format_changed = EINA_TRUE;
16424 _evas_clear_main_format(eo_obj, o);
16396 _evas_textblock_invalidate_all(o); 16425 _evas_textblock_invalidate_all(o);
16397 _evas_textblock_changed(o, eo_obj); 16426 _evas_textblock_changed(o, eo_obj);
16398 efl_event_callback_call(eo_obj, EFL_CANVAS_TEXTBLOCK_EVENT_CHANGED, NULL); 16427 efl_event_callback_call(eo_obj, EFL_CANVAS_TEXTBLOCK_EVENT_CHANGED, NULL);
diff --git a/src/tests/evas/evas_test_textblock.c b/src/tests/evas/evas_test_textblock.c
index d26b8fc7b9..620ce70b7b 100644
--- a/src/tests/evas/evas_test_textblock.c
+++ b/src/tests/evas/evas_test_textblock.c
@@ -4925,6 +4925,7 @@ EFL_START_TEST(efl_canvas_textblock_style)
4925 START_EFL_CANVAS_TEXTBLOCK_TEST(); 4925 START_EFL_CANVAS_TEXTBLOCK_TEST();
4926 unsigned char r, g, b, a; 4926 unsigned char r, g, b, a;
4927 const char *style; 4927 const char *style;
4928 Eina_Size2D size1, size2;
4928 4929
4929 efl_text_password_set(txt, EINA_FALSE); 4930 efl_text_password_set(txt, EINA_FALSE);
4930 efl_text_underline_type_set(txt, EFL_TEXT_STYLE_UNDERLINE_TYPE_DOUBLE); 4931 efl_text_underline_type_set(txt, EFL_TEXT_STYLE_UNDERLINE_TYPE_DOUBLE);
@@ -4995,6 +4996,15 @@ EFL_START_TEST(efl_canvas_textblock_style)
4995 ck_assert_int_eq(b, 0x6C); 4996 ck_assert_int_eq(b, 0x6C);
4996 ck_assert_int_eq(a, 0xFF); 4997 ck_assert_int_eq(a, 0xFF);
4997 4998
4999 // Style Apply taking
5000 efl_text_set(txt,"A");
5001 efl_canvas_textblock_style_apply(txt,"font_size=2");
5002 size1 = efl_canvas_textblock_size_native_get(txt);
5003 efl_canvas_textblock_style_apply(txt,"font_size=20");
5004 size2 = efl_canvas_textblock_size_native_get(txt);
5005 ck_assert(size1.w < size2.w);
5006 ck_assert(size1.h < size2.h);
5007
4998 END_EFL_CANVAS_TEXTBLOCK_TEST(); 5008 END_EFL_CANVAS_TEXTBLOCK_TEST();
4999} 5009}
5000EFL_END_TEST 5010EFL_END_TEST