This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch fix/gl-filter-buffers
in repository efl.
View the commit online.
commit 994f515ead21f05f5ace63549283cac5b8afbac0
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 13:32:14 2026 -0600
evas/filters: keep the colors of color glyphs
The input of a filtered Text object was always an alpha buffer, which
color glyphs can not be drawn into. The software engine scaled their
ARGB pixels into the one byte per pixel buffer, writing past its end:
any filtered text with an emoji crashed it, color bitmap scaling being
on by default. The GL engine kept their silhouette only.
The input is now RGBA when a font of the text has color glyphs, as the
input of a Textblock already is. Its letters are drawn white, so that
filters color them as before, while color glyphs keep their colors,
multiplied by the color of a filter. The program is built again when
the text changes from one case to the other. Letters keep the object's
alpha only where an alpha input does, on GL.
The tests use a small color font made by the script next to it, and
check colors, that letters filter alike with or without a color glyph,
and text changes, on both engines.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/evas/canvas/evas_filter_mixin.c | 14 ++
src/lib/evas/canvas/evas_object_text.c | 38 +++++-
src/lib/evas/common/evas_font.h | 1 +
src/lib/evas/common/evas_font_main.c | 8 ++
src/lib/evas/filters/evas_filter.c | 6 +
src/lib/evas/filters/evas_filter_parser.c | 8 +-
src/lib/evas/include/evas_filter.h | 2 +
src/tests/evas/evas_test_filters.c | 165 +++++++++++++++++++++++
src/tests/evas/fonts/evas_test_color.ttf | Bin 0 -> 868 bytes
src/tests/evas/fonts/generate_color_test_font.py | 92 +++++++++++++
10 files changed, 329 insertions(+), 5 deletions(-)
diff --git a/src/lib/evas/canvas/evas_filter_mixin.c b/src/lib/evas/canvas/evas_filter_mixin.c
index 11a3fe45b5..1ed6d9940a 100644
--- a/src/lib/evas/canvas/evas_filter_mixin.c
+++ b/src/lib/evas/canvas/evas_filter_mixin.c
@@ -284,6 +284,20 @@ evas_filter_object_render(Eo *eo_obj, Evas_Object_Protected_Data *obj,
evas_object_map_update(eo_obj, x, y, iw, ih, iw, ih);
}
+ /* The program was built for one format of input, the object may need the
+ * other now: build it again. */
+ if (pd->data->chain &&
+ (evas_filter_program_input_alpha_get(pd->data->chain) != alpha))
+ {
+ fcow = FCOW_BEGIN(pd);
+ evas_filter_context_unref(fcow->context);
+ fcow->context = NULL;
+ evas_filter_program_del(fcow->chain);
+ fcow->chain = NULL;
+ fcow->changed = EINA_TRUE;
+ FCOW_END(fcow, pd);
+ }
+
if (!pd->data->chain)
{
Evas_Filter_Program *pgm;
diff --git a/src/lib/evas/canvas/evas_object_text.c b/src/lib/evas/canvas/evas_object_text.c
index a0b7dd26d7..1004a49900 100644
--- a/src/lib/evas/canvas/evas_object_text.c
+++ b/src/lib/evas/canvas/evas_object_text.c
@@ -1705,6 +1705,21 @@ evas_font_draw_async_check(Evas_Object_Protected_Data *obj,
/* ugly binding between evas_fitler_mixin.c and this object */
+/* A filter's input is the coverage of the text, unless a font of it has color
+ * glyphs: those need an RGBA input, which keeps their colors. */
+static Eina_Bool
+_evas_object_text_color_glyphs_get(const Evas_Text_Data *o)
+{
+ Evas_Object_Text_Item *it;
+
+ EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
+ if (it->text_props.font_instance && (it->text_props.len > 0) &&
+ evas_common_font_instance_color_get(it->text_props.font_instance))
+ return EINA_TRUE;
+
+ return EINA_FALSE;
+}
+
EOLIAN static void
_evas_text_efl_canvas_filter_internal_filter_dirty(Eo *eo_obj, Evas_Text_Data *o)
{
@@ -1717,9 +1732,9 @@ _evas_text_efl_canvas_filter_internal_filter_dirty(Eo *eo_obj, Evas_Text_Data *o
}
EOLIAN static Eina_Bool
-_evas_text_efl_canvas_filter_internal_filter_input_alpha(Eo *eo_obj EINA_UNUSED, Evas_Text_Data *o EINA_UNUSED)
+_evas_text_efl_canvas_filter_internal_filter_input_alpha(Eo *eo_obj EINA_UNUSED, Evas_Text_Data *o)
{
- return EINA_TRUE;
+ return !_evas_object_text_color_glyphs_get(o);
}
EOLIAN static void
@@ -1742,7 +1757,7 @@ _evas_text_efl_canvas_filter_internal_filter_state_prepare(Eo *eo_obj, Evas_Text
}
EOLIAN static Eina_Bool
-_evas_text_efl_canvas_filter_internal_filter_input_render(Eo *eo_obj EINA_UNUSED, Evas_Text_Data *o,
+_evas_text_efl_canvas_filter_internal_filter_input_render(Eo *eo_obj, Evas_Text_Data *o,
void *_filter, void *engine, void *output, void *drawctx, void *draw EINA_UNUSED,
int l, int r EINA_UNUSED, int t, int b EINA_UNUSED,
int x, int y,
@@ -1750,6 +1765,20 @@ _evas_text_efl_canvas_filter_internal_filter_input_render(Eo *eo_obj EINA_UNUSED
{
Evas_Filter_Context *filter = _filter;
Evas_Object_Text_Item *it;
+ Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
+
+ /* In an RGBA input, letters are white so that the colors of the filter
+ * apply to them as they do to the coverage of an alpha one. The alpha of
+ * the object is kept where drawing that coverage keeps it: on GL, while
+ * the software engine ignores it. */
+ if (_evas_object_text_color_glyphs_get(o))
+ {
+ int r_, g_, b_, a;
+
+ ENFN->context_color_get(engine, drawctx, &r_, &g_, &b_, &a);
+ if (!evas_filter_context_gl_get(filter)) a = 255;
+ ENFN->context_color_set(engine, drawctx, a, a, a, a);
+ }
EINA_INLIST_FOREACH(EINA_INLIST_GET(o->items), it)
if ((o->font) && (it->text_props.len > 0))
@@ -1875,7 +1904,8 @@ evas_object_text_render(Evas_Object *eo_obj,
{
if (evas_filter_object_render(eo_obj, obj,
engine, output, context, surface,
- x, y, do_async, EINA_TRUE))
+ x, y, do_async,
+ !_evas_object_text_color_glyphs_get(o)))
return;
}
diff --git a/src/lib/evas/common/evas_font.h b/src/lib/evas/common/evas_font.h
index 24e3f771e1..ea28aa4024 100644
--- a/src/lib/evas/common/evas_font.h
+++ b/src/lib/evas/common/evas_font.h
@@ -361,6 +361,7 @@ EVAS_API int evas_common_font_ascent_get (RGBA_Font *fn)
EVAS_API int evas_common_font_descent_get (RGBA_Font *fn);
EVAS_API int evas_common_font_max_ascent_get (RGBA_Font *fn);
EVAS_API int evas_common_font_max_descent_get (RGBA_Font *fn);
+EVAS_API Eina_Bool evas_common_font_instance_color_get (RGBA_Font_Int *fi);
EVAS_API int evas_common_font_instance_ascent_get (RGBA_Font_Int *fi);
EVAS_API int evas_common_font_instance_descent_get (RGBA_Font_Int *fi);
EVAS_API int evas_common_font_instance_max_ascent_get (RGBA_Font_Int *fi);
diff --git a/src/lib/evas/common/evas_font_main.c b/src/lib/evas/common/evas_font_main.c
index 1af8fd2862..b8e5ca0844 100644
--- a/src/lib/evas/common/evas_font_main.c
+++ b/src/lib/evas/common/evas_font_main.c
@@ -99,6 +99,14 @@ evas_common_font_freetype_face_get(RGBA_Font *font)
return fi->src->ft.face;
}
+/* Whether glyphs of this font are color images rather than coverage */
+EVAS_API Eina_Bool
+evas_common_font_instance_color_get(RGBA_Font_Int *fi)
+{
+ evas_common_font_int_reload(fi);
+ return fi->src->ft.face && FT_HAS_COLOR(fi->src->ft.face);
+}
+
EVAS_API int
evas_common_font_instance_ascent_get(RGBA_Font_Int *fi)
{
diff --git a/src/lib/evas/filters/evas_filter.c b/src/lib/evas/filters/evas_filter.c
index 82ce48aa3a..43f8656bc5 100644
--- a/src/lib/evas/filters/evas_filter.c
+++ b/src/lib/evas/filters/evas_filter.c
@@ -95,6 +95,12 @@ evas_filter_context_size_get(Evas_Filter_Context *ctx, int *w, int *h)
if (h) *h = ctx->h;
}
+Eina_Bool
+evas_filter_context_gl_get(const Evas_Filter_Context *ctx)
+{
+ return ctx->gl;
+}
+
/* Private function to reset the filter context. Used from parser.c */
void
evas_filter_context_clear(Evas_Filter_Context *ctx, Eina_Bool keep_buffers)
diff --git a/src/lib/evas/filters/evas_filter_parser.c b/src/lib/evas/filters/evas_filter_parser.c
index 39c61f4cdb..6fd05f7652 100644
--- a/src/lib/evas/filters/evas_filter_parser.c
+++ b/src/lib/evas/filters/evas_filter_parser.c
@@ -3037,7 +3037,13 @@ evas_filter_program_padding_get(Evas_Filter_Program *pgm,
/** Create an empty filter program for style parsing */
-EVAS_API Evas_Filter_Program *
+EVAS_API Eina_Bool
+evas_filter_program_input_alpha_get(const Evas_Filter_Program *pgm)
+{
+ return pgm->input_alpha;
+}
+
+Evas_Filter_Program *
evas_filter_program_new(const char *name, Eina_Bool input_alpha)
{
Evas_Filter_Program *pgm;
diff --git a/src/lib/evas/include/evas_filter.h b/src/lib/evas/include/evas_filter.h
index 3567911837..e70e664fd0 100644
--- a/src/lib/evas/include/evas_filter.h
+++ b/src/lib/evas/include/evas_filter.h
@@ -120,6 +120,7 @@ EVAS_API Evas_Filter_Program *evas_filter_program_new(const char *name, Eina_Boo
EVAS_API Eina_Bool evas_filter_program_state_set(Evas_Filter_Program *pgm, const Efl_Canvas_Filter_State *state);
EVAS_API Eina_Bool evas_filter_program_parse(Evas_Filter_Program *pgm, const char *str);
EVAS_API void evas_filter_program_del(Evas_Filter_Program *pgm);
+Eina_Bool evas_filter_program_input_alpha_get(const Evas_Filter_Program *pgm);
EVAS_API Eina_Bool evas_filter_program_padding_get(Evas_Filter_Program *pgm, Evas_Filter_Padding *final, Evas_Filter_Padding *calc);
EVAS_API void evas_filter_program_source_set_all(Evas_Filter_Program *pgm, Eina_Hash *sources);
void evas_filter_program_data_set_all(Evas_Filter_Program *pgm, Eina_Inlist *data);
@@ -128,6 +129,7 @@ void evas_filter_program_data_set_all(Evas_Filter_Program *p
Evas_Filter_Context *evas_filter_context_new(Evas_Public_Data *evas, Eina_Bool async, void *user_data);
void *evas_filter_context_data_get(Evas_Filter_Context *ctx);
Eina_Bool evas_filter_context_async_get(Evas_Filter_Context *ctx);
+Eina_Bool evas_filter_context_gl_get(const Evas_Filter_Context *ctx);
void evas_filter_context_size_get(Evas_Filter_Context *ctx, int *w, int *H);
int evas_filter_context_ref(Evas_Filter_Context *ctx);
void evas_filter_context_unref(Evas_Filter_Context *ctx);
diff --git a/src/tests/evas/evas_test_filters.c b/src/tests/evas/evas_test_filters.c
index 6a967f789d..490565f70f 100644
--- a/src/tests/evas/evas_test_filters.c
+++ b/src/tests/evas/evas_test_filters.c
@@ -910,6 +910,169 @@ EFL_START_TEST(evas_filter_gl_blur_width)
}
EFL_END_TEST
+/* Color glyphs, from a font with one: U+F0000, a square red on the left and
+ * green on the right (see fonts/generate_color_test_font.py). */
+#define COLOR_FONT "DejaVuSans," TESTS_SRC_DIR "/fonts/evas_test_color.ttf"
+#define SQUARE "\xf3\xb0\x80\x80"
+
+static void
+_color_text_set(Gl_Canvas *c, const char *text)
+{
+ evas_object_color_set(c->text, 0, 0, 0, 255);
+ evas_object_text_font_set(c->text, COLOR_FONT, 64);
+ evas_object_text_text_set(c->text, text);
+}
+
+static DATA32 *
+_color_render_alpha(const char *engine, const char *text, const char *code,
+ int alpha)
+{
+ Gl_Canvas c;
+ DATA32 *pixels;
+
+ if (!_engine_canvas_new(&c, engine)) return NULL;
+ _color_text_set(&c, text);
+ evas_object_color_set(c.text, 0, 0, 0, alpha);
+ pixels = _gl_filter_render(&c, code);
+ _gl_canvas_free(&c);
+
+ return pixels;
+}
+
+static DATA32 *
+_color_render(const char *engine, const char *text, const char *code)
+{
+ return _color_render_alpha(engine, text, code, 255);
+}
+
+/* pixels close to a color */
+static int
+_color_count(const DATA32 *pixels, int r, int g, int b)
+{
+ int count = 0;
+
+ for (int k = 0; k < GL_W * GL_H; k++)
+ if ((abs((int) ((pixels[k] >> 16) & 0xff) - r) < 24) &&
+ (abs((int) ((pixels[k] >> 8) & 0xff) - g) < 24) &&
+ (abs((int) (pixels[k] & 0xff) - b) < 24))
+ count++;
+
+ return count;
+}
+
+static void
+_color_glyphs_check(const char *engine)
+{
+ DATA32 *plain, *filtered, *tinted;
+ int red, green;
+
+ plain = _color_render(engine, SQUARE, NULL);
+ if (!plain) return;
+ red = _color_count(plain, 255, 0, 0);
+ green = _color_count(plain, 0, 255, 0);
+ fail_if((red < 500) || (green < 500));
+
+ filtered = _color_render(engine, SQUARE, "blend { }");
+ ck_assert_int_lt(abs(_color_count(filtered, 255, 0, 0) - red), red / 10);
+ ck_assert_int_lt(abs(_color_count(filtered, 0, 255, 0) - green), green / 10);
+
+ /* a filter color multiplies the glyph's: red stays, green turns black */
+ tinted = _color_render(engine, SQUARE, "blend { color = '#ff0000' }");
+ ck_assert_int_lt(abs(_color_count(tinted, 255, 0, 0) - red), red / 10);
+ ck_assert_int_lt(abs(_color_count(tinted, 0, 0, 0) - green), green / 10);
+ ck_assert_int_eq(_color_count(tinted, 0, 255, 0), 0);
+
+ free(plain);
+ free(filtered);
+ free(tinted);
+}
+
+/* Other letters must filter alike with or without a color glyph after them. */
+static void
+_color_letters_check(const char *engine)
+{
+ static const char *programs[] = {
+ "blend { color = '#ff0000' }",
+ "blur { 3, color = '#0000ff' }",
+ "a = buffer { 'alpha' } blur { 3, dst = a } blend { a, color = 'red' }",
+ "a = buffer { 'alpha' } blend { dst = a } blend { a, color = 'red' }",
+ "grow { 3, color = 'blue' } blend { color = 'red' }",
+ };
+ int failed = 0;
+
+ /* each program with an opaque text, then with a translucent one */
+ for (unsigned n = 0; n < 2 * EINA_C_ARRAY_LENGTH(programs); n++)
+ {
+ const char *code = programs[n % EINA_C_ARRAY_LENGTH(programs)];
+ const int alpha = (n < EINA_C_ARRAY_LENGTH(programs)) ? 255 : 64;
+ DATA32 *alone, *with;
+ int differ = 0;
+
+ alone = _color_render_alpha(engine, "AbAb", code, alpha);
+ if (!alone) return;
+ with = _color_render_alpha(engine, "AbAb" SQUARE, code, alpha);
+ /* the letters, short of where the square and its blur begin */
+ for (int y = 0; y < GL_H; y++)
+ for (int x = 0; x < 150; x++)
+ {
+ const DATA32 p = alone[(y * GL_W) + x], q = with[(y * GL_W) + x];
+
+ if ((abs((int) ((p >> 16) & 0xff) - (int) ((q >> 16) & 0xff)) > 32) ||
+ (abs((int) (p & 0xff) - (int) (q & 0xff)) > 32))
+ differ++;
+ }
+ free(alone);
+ free(with);
+ if (differ <= 50) continue;
+ fprintf(stderr, "%s: %d letter pixels change with a color glyph, "
+ "alpha %d: %s\n", engine, differ, alpha, code);
+ failed++;
+ }
+ ck_assert_int_eq(failed, 0);
+}
+
+/* The filter follows the text as color glyphs come and go. */
+static void
+_color_text_change_check(const char *engine)
+{
+ static const char *code = "blend { }";
+ static const char *texts[] = { "AbAb", "Ab" SQUARE, "AbAb", SQUARE };
+ Gl_Canvas c;
+
+ if (!_engine_canvas_new(&c, engine)) return;
+ _color_text_set(&c, "x");
+ free(_gl_filter_render(&c, code));
+ for (unsigned n = 0; n < EINA_C_ARRAY_LENGTH(texts); n++)
+ {
+ DATA32 *changed, *fresh;
+
+ evas_object_text_text_set(c.text, texts[n]);
+ changed = _gl_filter_render(&c, code);
+ fresh = _color_render(engine, texts[n], code);
+ ck_assert_int_eq(memcmp(changed, fresh,
+ GL_W * GL_H * sizeof(DATA32)), 0);
+ free(changed);
+ free(fresh);
+ }
+ _gl_canvas_free(&c);
+}
+
+EFL_START_TEST(evas_filter_color_glyphs)
+{
+ _color_glyphs_check("buffer");
+ _color_letters_check("buffer");
+ _color_text_change_check("buffer");
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_filter_gl_color_glyphs)
+{
+ _color_glyphs_check("opengl_x11");
+ _color_letters_check("opengl_x11");
+ _color_text_change_check("opengl_x11");
+}
+EFL_END_TEST
+
void evas_test_filters(TCase *tc)
{
tcase_add_test(tc, evas_filter_parser);
@@ -918,8 +1081,10 @@ void evas_test_filters(TCase *tc)
tcase_add_test(tc, evas_filter_state_test);
tcase_add_test(tc, evas_filter_parser_missing_lua_classes);
tcase_add_test(tc, evas_filter_group_forwards_test);
+ tcase_add_test(tc, evas_filter_color_glyphs);
if (getenv("DISPLAY"))
{
+ tcase_add_test(tc, evas_filter_gl_color_glyphs);
tcase_add_test(tc, evas_filter_gl_text_color);
tcase_add_test(tc, evas_filter_gl_buffers_start_empty);
tcase_add_test(tc, evas_filter_gl_inverse_color);
diff --git a/src/tests/evas/fonts/evas_test_color.ttf b/src/tests/evas/fonts/evas_test_color.ttf
new file mode 100644
index 0000000000..221dc4b0fe
Binary files /dev/null and b/src/tests/evas/fonts/evas_test_color.ttf differ
diff --git a/src/tests/evas/fonts/generate_color_test_font.py b/src/tests/evas/fonts/generate_color_test_font.py
new file mode 100644
index 0000000000..291dd3c561
--- /dev/null
+++ b/src/tests/evas/fonts/generate_color_test_font.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python3
+"""Writes evas_test_color.ttf, a color bitmap font for the tests.
+
+It has the CBDT/CBLC tables of color emoji fonts and a single glyph, at the
+private use codepoint U+F0000: a square, red on its left half and green on its
+right half, with a transparent border. Needs fontTools.
+"""
+import io
+import struct
+import zlib
+
+from fontTools.fontBuilder import FontBuilder
+from fontTools.ttLib import newTable
+from fontTools.ttLib.tables.DefaultTable import DefaultTable
+
+SIZE = 64 # pixels of the only strike, also its ppem
+BORDER = 4
+UPEM = 1024
+
+
+def png():
+ rows = bytearray()
+ for y in range(SIZE):
+ rows.append(0)
+ for x in range(SIZE):
+ inside = BORDER <= x < SIZE - BORDER and BORDER <= y < SIZE - BORDER
+ if not inside:
+ rows += bytes((0, 0, 0, 0))
+ elif x < SIZE // 2:
+ rows += bytes((255, 0, 0, 255))
+ else:
+ rows += bytes((0, 255, 0, 255))
+
+ def chunk(kind, data):
+ return (struct.pack(">I", len(data)) + kind + data +
+ struct.pack(">I", zlib.crc32(kind + data)))
+
+ return (b"\x89PNG\r\n\x1a\n" +
+ chunk(b"IHDR", struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0)) +
+ chunk(b"IDAT", zlib.compress(bytes(rows), 9)) +
+ chunk(b"IEND", b""))
+
+
+def bitmap_tables():
+ image = png()
+ ascent = SIZE - 12
+ # format 17: small metrics (height, width, bearing x, bearing y, advance)
+ glyph = struct.pack(">BBbbBI", SIZE, SIZE, 0, ascent, SIZE, len(image)) + image
+ cbdt = struct.pack(">HH", 3, 0) + glyph
+
+ # one index subtable, format 1, for glyph 1 only
+ subtable = struct.pack(">HHI", 1, 17, 4) + struct.pack(">II", 0, len(glyph))
+ array = struct.pack(">HHI", 1, 1, 8)
+ line = struct.pack(">bbBbbbbbbbbb", ascent, -12, SIZE, 1, 0, 0, 0, 0, 0, 0, 0, 0)
+ size = (struct.pack(">IIII", 8 + 48, len(array) + len(subtable), 1, 0) +
+ line + line +
+ struct.pack(">HHBBBb", 1, 1, SIZE, SIZE, 32, 1))
+ cblc = struct.pack(">HHI", 3, 0, 1) + size + array + subtable
+ return cbdt, cblc
+
+
+def main():
+ fb = FontBuilder(UPEM, isTTF=True)
+ fb.setupGlyphOrder([".notdef", "square"])
+ fb.setupCharacterMap({0xF0000: "square"})
+ fb.setupHorizontalMetrics({".notdef": (UPEM, 0), "square": (UPEM, 0)})
+ ascent = UPEM * (SIZE - 12) // SIZE
+ fb.setupHorizontalHeader(ascent=ascent, descent=ascent - UPEM)
+ fb.setupNameTable({"familyName": "EvasTestColor", "styleName": "Regular"})
+ fb.setupOS2(sTypoAscender=ascent, sTypoDescender=ascent - UPEM,
+ usWinAscent=ascent, usWinDescent=UPEM - ascent)
+ fb.setupPost()
+ # a bitmap only font has no outlines, and the short maxp table
+ maxp = newTable("maxp")
+ maxp.tableVersion = 0x00005000
+ maxp.numGlyphs = 2
+ fb.font["maxp"] = maxp
+ for tag, data in zip(("CBDT", "CBLC"), bitmap_tables()):
+ table = DefaultTable(tag)
+ table.data = ""
+ fb.font[tag] = table
+ # reproducible output
+ fb.font.recalcTimestamp = False
+ fb.font["head"].created = fb.font["head"].modified = 0
+ out = io.BytesIO()
+ fb.font.save(out)
+ with open(__file__.rsplit("/", 1)[0] + "/evas_test_color.ttf", "wb") as f:
+ f.write(out.getvalue())
+
+
+if __name__ == "__main__":
+ main()
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.