This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 984ff80a589ca91b53a401592bf6b5722def896e
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 22 14:47:47 2026 -0600

    evas:textgrid: remember the font and script of a single cell codepoint
    
    A cell drawn on its own walked the font set and the script tables before
    the text_props cache lookup.  Keep both per codepoint and style in a
    small direct mapped table, valid for one generation of the font sets.
    The generation moves on when the font sets change, so dropping the table
    is O(1), and no font set address is kept that a new set could reuse.
    Runs of several cells are unchanged.
    
    Textgrid tests of expedite, callgrind instructions per frame, base to
    this commit: GL truecolor fire 28.0M to 20.8M (-26%), terminal scroll
    23.6M to 19.7M (-17%), change 6.8M to 6.4M (-6%), partial and one row
    -2% and -4%; software fire -14%, scroll -15%, change -7%, partial and
    one row -2%.  fps medians, same machine, interleaved: GL fire +12%,
    scroll +10% (ranges do not overlap); other tests are within noise.
    Software fire +3% and scroll +5% are at the edge of the noise.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/evas/canvas/evas_object_textgrid.c |  77 +++++++++++++-
 src/tests/evas/evas_test_textgrid.c        | 164 +++++++++++++++++++++++++++++
 2 files changed, 236 insertions(+), 5 deletions(-)

diff --git a/src/lib/evas/canvas/evas_object_textgrid.c b/src/lib/evas/canvas/evas_object_textgrid.c
index f7c49c1371..176cfee67c 100644
--- a/src/lib/evas/canvas/evas_object_textgrid.c
+++ b/src/lib/evas/canvas/evas_object_textgrid.c
@@ -42,6 +42,24 @@ struct _Evas_Textgrid_Cache_Key
 static Evas_Text_Props _textgrid_run_rejected;
 #define TEXTGRID_RUN_REJECTED (&_textgrid_run_rejected)
 
+/* Script and font instance of a single codepoint in a style, so that a
+ * cell does not walk the font set and the script tables every time it is
+ * drawn.  Direct mapped.  An entry is valid while its generation is the
+ * grid's: the generation moves on when the font sets change (see
+ * _textgrid_cache_invalidate()), which drops every entry at once.  The
+ * font set itself is not kept: its address can be reused by another set. */
+#define TEXTGRID_RUN_MEMO_SIZE 256
+
+typedef struct _Evas_Textgrid_Run_Memo Evas_Textgrid_Run_Memo;
+struct _Evas_Textgrid_Run_Memo
+{
+   Evas_Font_Instance *fi;
+   Eina_Unicode        cp;
+   Evas_Script_Type    script;
+   unsigned int        generation; /* 0: unused */
+   unsigned char       style; /* bold | italic << 1 */
+};
+
 /* Ligature state, allocated only while ligatures are enabled */
 typedef struct _Evas_Textgrid_Liga Evas_Textgrid_Liga;
 struct _Evas_Textgrid_Liga
@@ -91,6 +109,9 @@ struct _Evas_Textgrid_Data
     * takes its own independent ref via evas_common_text_props_content_copy_and_ref. */
    Eina_Hash                     *text_props_cache;
 
+   Evas_Textgrid_Run_Memo        *run_memo; /* TEXTGRID_RUN_MEMO_SIZE, lazy */
+   unsigned int                   run_memo_generation; /* never 0 */
+
    Evas_Textgrid_Liga            *liga; /* NULL when ligatures are off */
 
    /* Cell backgrounds: one premultiplied ARGB pixel per cell, drawn as a
@@ -297,6 +318,14 @@ _textgrid_cache_invalidate(Evas_Textgrid_Data *o)
 {
    if (o->text_props_cache)
      eina_hash_free_buckets(o->text_props_cache);
+   if (++o->run_memo_generation == 0)
+     {
+        /* wrapped: entries of an old generation could look valid again */
+        if (o->run_memo)
+          memset(o->run_memo, 0,
+                 TEXTGRID_RUN_MEMO_SIZE * sizeof(Evas_Textgrid_Run_Memo));
+        o->run_memo_generation = 1;
+     }
 }
 
 static Eina_Bool
@@ -421,6 +450,7 @@ evas_object_textgrid_init(Evas_Object *eo_obj)
    memset(o->palette_standard, 0, sizeof(o->palette_standard));
    memset(o->palette_extended, 0, sizeof(o->palette_extended));
    o->text_props_cache = _textgrid_cache_new();
+   o->run_memo_generation = 1;
    o->bg.rects = EINA_TRUE;
 }
 
@@ -566,6 +596,8 @@ evas_object_textgrid_free(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj)
         eina_hash_free(o->text_props_cache);
         o->text_props_cache = NULL;
      }
+   free(o->run_memo);
+   o->run_memo = NULL;
    _textgrid_liga_free(o);
 }
 
@@ -695,15 +727,50 @@ evas_object_textgrid_row_text_append(Evas_Object_Textgrid_Row *row,
         row->texts = t;
      }
 
-   script = evas_common_language_script_type_get(cps, len);
    text = &row->texts[row->texts_num - 1];
    text->bold = is_bold;
    text->italic = is_italic;
    font = _textgrid_font_get(o, is_bold, is_italic);
-   run_end = ENFN->font_run_end_get(ENC, font, &script_fi, &cur_fi,
-                                    script, cps, len);
-   /* Never shape across a font-instance boundary. */
-   if ((run_end > 0) && (run_end < len)) len = run_end;
+   if (len == 1)
+     {
+        Evas_Textgrid_Run_Memo *memo = NULL;
+        unsigned char style = (is_bold ? 1 : 0) | (is_italic ? 2 : 0);
+
+        if (!o->run_memo)
+          o->run_memo = calloc(TEXTGRID_RUN_MEMO_SIZE,
+                               sizeof(Evas_Textgrid_Run_Memo));
+        if (o->run_memo)
+          memo = &o->run_memo[(((cps[0] * 0x9E3779B1u) >> 24) +
+                               (style * 85)) % TEXTGRID_RUN_MEMO_SIZE];
+        if ((memo) && (memo->generation == o->run_memo_generation) &&
+            (memo->cp == cps[0]) && (memo->style == style))
+          {
+             script = memo->script;
+             cur_fi = memo->fi;
+          }
+        else
+          {
+             script = evas_common_language_script_type_get(cps, 1);
+             ENFN->font_run_end_get(ENC, font, &script_fi, &cur_fi,
+                                    script, cps, 1);
+             if ((memo) && (cur_fi))
+               {
+                  memo->generation = o->run_memo_generation;
+                  memo->style = style;
+                  memo->cp = cps[0];
+                  memo->script = script;
+                  memo->fi = cur_fi;
+               }
+          }
+     }
+   else
+     {
+        script = evas_common_language_script_type_get(cps, len);
+        run_end = ENFN->font_run_end_get(ENC, font, &script_fi, &cur_fi,
+                                         script, cps, len);
+        /* Never shape across a font-instance boundary. */
+        if ((run_end > 0) && (run_end < len)) len = run_end;
+     }
    n = len;
 
    /* At most two passes: a rejected run retries as a single cell. */
diff --git a/src/tests/evas/evas_test_textgrid.c b/src/tests/evas/evas_test_textgrid.c
index f973b4d96e..7fb79de411 100644
--- a/src/tests/evas/evas_test_textgrid.c
+++ b/src/tests/evas/evas_test_textgrid.c
@@ -1006,6 +1006,167 @@ EFL_START_TEST(evas_textgrid_test_text_after_font_cache_flush)
 }
 EFL_END_TEST
 
+/* The script and font of a codepoint are remembered by the grid.  Every
+ * style, and a codepoint the font does not have, must show what a grid
+ * that has remembered nothing shows. */
+static const Eina_Unicode _memo_cps[] =
+  { 'A', 'A', 'A', 'A', 'b', 'b', 0x2588, 0x2588, 0x4e2d, 0x4e2d, 0x1f, 'a', ' ',
+    'A', 'b', 0x4e2d };
+
+static void
+_memo_cells_fill(Evas_Object *tg, int rot)
+{
+   int x, y;
+
+   for (y = 0; y < GRID_H; y++)
+     {
+        Evas_Textgrid_Cell *cells = evas_object_textgrid_cellrow_get(tg, y);
+
+        for (x = 0; x < GRID_W; x++)
+          {
+             int k = (y * GRID_W + x + rot) %
+               (int)(sizeof(_memo_cps) / sizeof(_memo_cps[0]));
+
+             cells[x].codepoint = _memo_cps[k];
+             cells[x].bold = (k >> 1) & 1;
+             cells[x].italic = (k >> 2) & 1;
+             cells[x].fg = 0;
+             cells[x].bg = 1;
+          }
+     }
+   evas_object_textgrid_update_add(tg, 0, 0, GRID_W, GRID_H);
+}
+
+static void
+_memo_palette_set(Evas_Object *tg)
+{
+   _palette_std_set(tg, 0, ARGB(255, 250, 250, 250));
+   _palette_std_set(tg, 1, ARGB(255, 20, 40, 160));
+}
+
+/* A grid shown several times must match a grid shown once.  The grid
+ * shown once also remembers codepoints it has already drawn, so this
+ * checks that the outcome does not depend on the order of drawing and on
+ * what the slots held before; it does not compare with a path that
+ * remembers nothing.  Stale entries are covered by the font change test. */
+EFL_START_TEST(evas_textgrid_test_text_remembered_matches_fresh)
+{
+   START_TG_TEST();
+   Evas_Object *tg = _textgrid_new(e);
+   unsigned int *warm, *fresh;
+   int pass;
+
+   _memo_palette_set(tg);
+   for (pass = 0; pass < 4; pass++)
+     {
+        /* a different layout each time, the same characters */
+        _memo_cells_fill(tg, pass * 3);
+        free(_snapshot(ee));
+     }
+   _memo_cells_fill(tg, 5);
+   warm = _snapshot(ee);
+
+   evas_object_del(tg);
+   tg = _textgrid_new(e);
+   _memo_palette_set(tg);
+   _memo_cells_fill(tg, 5);
+   fresh = _snapshot(ee);
+
+   fail_if(!_pixels_equal(warm, fresh));
+   free(warm);
+   free(fresh);
+   END_TG_TEST();
+}
+EFL_END_TEST
+
+/* After a change of size or of font, what was remembered about the old
+ * font must not be used.  Entries are valid for one generation of the font
+ * sets, so this fails whenever a change leaves them valid, whatever the
+ * allocator does. */
+EFL_START_TEST(evas_textgrid_test_text_remembered_font_change)
+{
+   START_TG_TEST();
+   Evas_Object *tg = _textgrid_new(e);
+   unsigned int *changed, *fresh;
+   int variant;
+
+   for (variant = 0; variant < 3; variant++)
+     {
+        _memo_palette_set(tg);
+        _memo_cells_fill(tg, 0);
+        free(_snapshot(ee));
+        _memo_cells_fill(tg, 0);
+        free(_snapshot(ee));
+
+        if (variant == 0)
+          evas_object_textgrid_font_set(tg, TEST_FONT_NAME, 12);
+        else if (variant == 1)
+          {
+             evas_object_textgrid_font_source_set(tg, NULL);
+             evas_object_textgrid_font_set(tg, "Sans", 13);
+          }
+        else
+          {
+             evas_object_textgrid_font_source_set(tg, TEST_FONT_SOURCE);
+             evas_object_textgrid_font_set(tg, TEST_FONT_NAME, 16);
+          }
+        evas_object_textgrid_cell_size_get(tg, &cw, &ch);
+        evas_object_resize(tg, cw * GRID_W, ch * GRID_H);
+        _memo_cells_fill(tg, 2);
+        changed = _snapshot(ee);
+
+        {
+           Evas_Object *ref = evas_object_textgrid_add(e);
+           const char *src, *name;
+           Evas_Font_Size size;
+
+           evas_object_textgrid_font_get(tg, &name, &size);
+           src = ""
+           evas_object_textgrid_font_source_set(ref, src);
+           evas_object_textgrid_font_set(ref, name, size);
+           evas_object_textgrid_size_set(ref, GRID_W, GRID_H);
+           evas_object_geometry_set(ref, 0, 0, cw * GRID_W, ch * GRID_H);
+           _memo_palette_set(ref);
+           _memo_cells_fill(ref, 2);
+           evas_object_hide(tg);
+           evas_object_show(ref);
+           fresh = _snapshot(ee);
+           evas_object_del(ref);
+           evas_object_show(tg);
+        }
+        fail_if(!_pixels_equal(changed, fresh));
+        free(changed);
+        free(fresh);
+     }
+   END_TG_TEST();
+}
+EFL_END_TEST
+
+/* Dropping what the engine keeps in its font cache must not change what
+ * the grid shows for characters it remembers. */
+EFL_START_TEST(evas_textgrid_test_text_remembered_after_cache_flush)
+{
+   START_TG_TEST();
+   Evas_Object *tg = _textgrid_new(e);
+   unsigned int *before, *after;
+   int pass;
+
+   _memo_palette_set(tg);
+   _memo_cells_fill(tg, 0);
+   before = _snapshot(ee);
+   for (pass = 0; pass < 3; pass++)
+     {
+        evas_font_cache_flush(e);
+        _memo_cells_fill(tg, 0);
+        after = _snapshot(ee);
+        fail_if(!_pixels_equal(before, after));
+        free(after);
+     }
+   free(before);
+   END_TG_TEST();
+}
+EFL_END_TEST
+
 void evas_test_textgrid(TCase *tc)
 {
    tcase_add_test(tc, evas_textgrid_test_truecolor_setget);
@@ -1027,6 +1188,9 @@ void evas_test_textgrid(TCase *tc)
    tcase_add_test(tc, evas_textgrid_test_text_cells_independent);
    tcase_add_test(tc, evas_textgrid_test_bg_form_switch);
    tcase_add_test(tc, evas_textgrid_test_text_after_font_cache_flush);
+   tcase_add_test(tc, evas_textgrid_test_text_remembered_matches_fresh);
+   tcase_add_test(tc, evas_textgrid_test_text_remembered_font_change);
+   tcase_add_test(tc, evas_textgrid_test_text_remembered_after_cache_flush);
 }
 
 #endif // BUILD_ENGINE_BUFFER

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to