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 31e46bbf37fcd10dc693ae19ed5494994cac9e47
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 14:55:01 2026 -0600

    evas/filters: fade and clip a filtered object once
    
    The color of the object, which holds the clipper's, was used to draw
    the input of the filter, and the clipper's alone to draw the result.
    
    A software alpha input keeps no color, so a translucent filtered Text
    was opaque, while on GL it was translucent and its clipper applied
    twice. Filtered images ignored the alpha of their color on both.
    
    The input is now drawn at full strength, so that thresholds as those
    of grow work on the whole coverage, and the result is faded by the
    object's alpha and clipped as one. state.color is given without its
    alpha, or programs drawing with it would apply it a second time.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/evas/canvas/evas_filter_mixin.c  |  48 +++++++---
 src/lib/evas/canvas/evas_object_text.c   |  16 +---
 src/lib/evas/filters/evas_filter.c       |  16 ----
 src/lib/evas/include/evas_filter.h       |   1 -
 src/tests/evas/evas_test_filter_values.c | 152 +++++++++++++++++++++++++++++++
 5 files changed, 188 insertions(+), 45 deletions(-)

diff --git a/src/lib/evas/canvas/evas_filter_mixin.c b/src/lib/evas/canvas/evas_filter_mixin.c
index d363c4dd34..402382e759 100644
--- a/src/lib/evas/canvas/evas_filter_mixin.c
+++ b/src/lib/evas/canvas/evas_filter_mixin.c
@@ -210,6 +210,16 @@ _evas_filter_state_set_internal(Evas_Filter_Program *pgm, Evas_Filter_Data *pd)
    Efl_Canvas_Filter_State state = EFL_CANVAS_FILTER_STATE_DEFAULT;
 
    evas_filter_state_prepare(pd->data->obj->object, &state, NULL);
+   /* The result of the filter is faded by the alpha of the object, so its
+    * color is given without it: a program using it would apply it twice.
+    * Colors are premultiplied. */
+   if (state.color.a && (state.color.a < 255))
+     {
+        state.color.r = MIN(255, state.color.r * 255 / state.color.a);
+        state.color.g = MIN(255, state.color.g * 255 / state.color.a);
+        state.color.b = MIN(255, state.color.b * 255 / state.color.a);
+        state.color.a = 255;
+     }
    state.cur.name = pd->data->state.cur.name;
    state.cur.value = pd->data->state.cur.value;
    state.next.name = pd->data->state.next.name;
@@ -266,14 +276,29 @@ evas_filter_object_render(Eo *eo_obj, Evas_Object_Protected_Data *obj,
                            obj->cur->cache.clip.g,
                            obj->cur->cache.clip.b,
                            obj->cur->cache.clip.a);
-   if (obj->cur->clipper)
-     ENFN->context_multiplier_set(engine, context,
-                                  obj->cur->clipper->cur->cache.clip.r,
-                                  obj->cur->clipper->cur->cache.clip.g,
-                                  obj->cur->clipper->cur->cache.clip.b,
-                                  obj->cur->clipper->cur->cache.clip.a);
-   else
-      ENFN->context_multiplier_unset(engine, context);
+   /* The filter works on the object at full strength: its result is then
+    * clipped, and faded by the alpha of the object, as a whole and once. */
+   {
+      const int alpha = obj->cur->color.a;
+      int r = 255, g = 255, b = 255, a = 255;
+
+      if (obj->cur->clipper)
+        {
+           r = obj->cur->clipper->cur->cache.clip.r;
+           g = obj->cur->clipper->cur->cache.clip.g;
+           b = obj->cur->clipper->cur->cache.clip.b;
+           a = obj->cur->clipper->cur->cache.clip.a;
+        }
+      r = r * alpha / 255;
+      g = g * alpha / 255;
+      b = b * alpha / 255;
+      a = a * alpha / 255;
+
+      if ((r & g & b & a) != 255)
+        ENFN->context_multiplier_set(engine, context, r, g, b, a);
+      else
+        ENFN->context_multiplier_unset(engine, context);
+   }
 
    if (obj->map->cur.usemap && obj->map->cur.map && (obj->map->cur.map->count >= 4))
      {
@@ -429,11 +454,8 @@ evas_filter_object_render(Eo *eo_obj, Evas_Object_Protected_Data *obj,
 
    // Draw Context
    drawctx = ENFN->context_new(engine);
-   ENFN->context_color_set(engine, drawctx,
-                           obj->cur->cache.clip.r,
-                           obj->cur->cache.clip.g,
-                           obj->cur->cache.clip.b,
-                           obj->cur->cache.clip.a);
+   /* glyphs leave their coverage, or their own colors, in the input */
+   ENFN->context_color_set(engine, drawctx, 255, 255, 255, 255);
 
    // Set obscured region
    evas_filter_context_obscured_region_set(filter, pd->data->obscured);
diff --git a/src/lib/evas/canvas/evas_object_text.c b/src/lib/evas/canvas/evas_object_text.c
index 1004a49900..a66cab900c 100644
--- a/src/lib/evas/canvas/evas_object_text.c
+++ b/src/lib/evas/canvas/evas_object_text.c
@@ -1757,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, Evas_Text_Data *o,
+_evas_text_efl_canvas_filter_internal_filter_input_render(Eo *eo_obj EINA_UNUSED, 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,
@@ -1765,20 +1765,6 @@ _evas_text_efl_canvas_filter_internal_filter_input_render(Eo *eo_obj, Evas_Text_
 {
    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))
diff --git a/src/lib/evas/filters/evas_filter.c b/src/lib/evas/filters/evas_filter.c
index 2278b8eaf0..20cada3df5 100644
--- a/src/lib/evas/filters/evas_filter.c
+++ b/src/lib/evas/filters/evas_filter.c
@@ -95,12 +95,6 @@ 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)
@@ -1849,7 +1843,6 @@ evas_filter_font_draw(Evas_Filter_Context *ctx,
    Eina_Bool async_unref;
    Evas_Filter_Buffer *fb;
    void *surface = NULL;
-   int R, G, B, A;
 
    fb = _filter_buffer_get(ctx, bufid);
    /* nothing to draw for a program which does not read its input */
@@ -1859,19 +1852,10 @@ evas_filter_font_draw(Evas_Filter_Context *ctx,
    surface = evas_filter_buffer_backing_get(ctx, bufid, EINA_TRUE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EINA_FALSE);
 
-   // An alpha buffer holds coverage only, the filter brings the color. The
-   // GL engine backs it with an RGBA texture though, so draw the glyphs in
-   // white or the object's color would tint every filter reading it.
-   ENFN->context_color_get(engine, draw_context, &R, &G, &B, &A);
-   if (fb->alpha_only)
-     ENFN->context_color_set(engine, draw_context, A, A, A, A);
-
    // Copied from evas_font_draw_async_check
    async_unref = ENFN->font_draw(engine, output, draw_context, surface,
                                  font, x, y, fb->w, fb->h, fb->w, fb->h,
                                  text_props, do_async);
-   if (fb->alpha_only)
-     ENFN->context_color_set(engine, draw_context, R, G, B, A);
    if (do_async && async_unref)
      {
         evas_common_font_glyphs_ref(text_props->glyphs);
diff --git a/src/lib/evas/include/evas_filter.h b/src/lib/evas/include/evas_filter.h
index 3cd50f94d2..7d4a360ed9 100644
--- a/src/lib/evas/include/evas_filter.h
+++ b/src/lib/evas/include/evas_filter.h
@@ -129,7 +129,6 @@ 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);
 Eina_Bool                    evas_filter_context_input_used(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);
diff --git a/src/tests/evas/evas_test_filter_values.c b/src/tests/evas/evas_test_filter_values.c
index 8877a725c6..98dd63bd7e 100644
--- a/src/tests/evas/evas_test_filter_values.c
+++ b/src/tests/evas/evas_test_filter_values.c
@@ -732,8 +732,160 @@ EFL_START_TEST(evas_filter_gl_quiet)
 }
 EFL_END_TEST
 
+/* A translucent or clipped object is so once, filtered or not. Colors given to
+ * Evas are premultiplied. */
+typedef struct _Alpha_Case Alpha_Case;
+struct _Alpha_Case
+{
+   const char *name;
+   Eina_Bool image;
+   int red, alpha, clip_alpha;
+   const char *code;
+   Probe darkest;
+};
+
+static void
+_alpha_check(const char *engine)
+{
+#define BLACK "blend { color = 'black' }"
+#define GROWN "a = buffer { 'alpha' } grow { 2, dst = a } " \
+              "blend { a, color = 'black' }"
+#define GREY(v) { 0, 0, v, v, v }
+   static const Alpha_Case cases[] = {
+      { "opaque text", 0, 0, 255, 255, BLACK, GREY(0) },
+      { "translucent text", 0, 0, 64, 255, BLACK, GREY(191) },
+      { "clipped text", 0, 0, 255, 64, BLACK, GREY(191) },
+      { "translucent clipped text", 0, 0, 128, 128, BLACK, GREY(191) },
+      { "translucent text grown", 0, 0, 64, 255, GROWN, GREY(191) },
+      { "translucent text in its color", 0, 64, 64, 255,
+        "blend { color = state.color }", { 0, 0, 255, 191, 191 } },
+      { "opaque text in its color", 0, 255, 255, 255,
+        "blend { color = state.color }", { 0, 0, 255, 0, 0 } },
+      { "opaque image", 1, 0, 255, 255, "blend { }", GREY(0) },
+      { "translucent image", 1, 0, 64, 255, "blend { }", GREY(191) },
+      { "clipped image", 1, 0, 255, 64, "blend { }", GREY(191) },
+      { "translucent clipped image", 1, 0, 128, 128, "blend { }", GREY(191) },
+   };
+   int failed = 0;
+
+   for (unsigned n = 0; n < EINA_C_ARRAY_LENGTH(cases); n++)
+     {
+        const Alpha_Case *t = &cases[n];
+        Ecore_Evas *ee;
+        Evas_Object *bg, *clip, *o, *snap;
+        Eina_Tmpstr *file = NULL;
+        Snapshot shot;
+        Ecore_Evas *loader;
+        Evas_Object *im;
+        uint32_t *pixels, darkest = 0xffffffff;
+        int fd, best = 1000, r, g, b;
+        Evas *evas;
+
+        ee = ecore_evas_new(engine, 0, 0, W, H, NULL);
+        if (!ee) return;
+        ecore_evas_show(ee);
+        ecore_evas_manual_render_set(ee, EINA_TRUE);
+        evas = ecore_evas_get(ee);
+
+        bg = evas_object_rectangle_add(evas);
+        evas_object_resize(bg, W, H);
+        evas_object_show(bg);
+        clip = evas_object_rectangle_add(evas);
+        evas_object_color_set(clip, t->clip_alpha, t->clip_alpha,
+                              t->clip_alpha, t->clip_alpha);
+        evas_object_resize(clip, W, H);
+        evas_object_show(clip);
+
+        if (!t->image)
+          {
+             o = evas_object_text_add(evas);
+             evas_object_text_font_set(o, "DejaVuSans:style=Bold", 48);
+             evas_object_text_text_set(o, "MMM");
+          }
+        else
+          {
+             o = evas_object_image_filled_add(evas);
+             evas_object_image_size_set(o, W, H);
+             pixels = evas_object_image_data_get(o, EINA_TRUE);
+             for (int k = 0; k < W * H; k++) pixels[k] = 0xff000000;
+             evas_object_image_data_set(o, pixels);
+             evas_object_image_data_update_add(o, 0, 0, W, H);
+             evas_object_resize(o, W, H);
+          }
+        evas_object_color_set(o, t->red, 0, 0, t->alpha);
+        evas_object_clip_set(o, clip);
+        efl_gfx_filter_program_set(o, t->code, "alpha");
+        evas_object_show(o);
+
+        snap = evas_object_image_filled_add(evas);
+        evas_object_image_snapshot_set(snap, EINA_TRUE);
+        evas_object_resize(snap, W, H);
+        evas_object_show(snap);
+
+        fd = eina_file_mkstemp("evas_test_filter_XXXXXX.png", &file);
+        fail_if(fd < 0);
+        close(fd);
+        shot.snap = snap;
+        shot.file = file;
+        evas_event_callback_add(evas, EVAS_CALLBACK_RENDER_POST,
+                                _snapshot_save, &shot);
+        ecore_evas_manual_render(ee);
+
+        loader = ecore_evas_buffer_new(1, 1);
+        im = evas_object_image_add(ecore_evas_get(loader));
+        evas_object_image_file_set(im, file, NULL);
+        pixels = evas_object_image_data_get(im, EINA_FALSE);
+        fail_if(!pixels);
+        for (int k = 0; k < W * H; k++)
+          {
+             const int sum = ((pixels[k] >> 16) & 0xff) +
+               ((pixels[k] >> 8) & 0xff) + (pixels[k] & 0xff);
+
+             if (sum < best)
+               {
+                  best = sum;
+                  darkest = pixels[k];
+               }
+          }
+        evas_object_image_data_set(im, pixels);
+        ecore_evas_free(loader);
+        unlink(file);
+        eina_tmpstr_del(file);
+        ecore_evas_free(ee);
+
+        r = (darkest >> 16) & 0xff;
+        g = (darkest >> 8) & 0xff;
+        b = darkest & 0xff;
+        if ((abs(r - t->darkest.r) <= 8) && (abs(g - t->darkest.g) <= 8) &&
+            (abs(b - t->darkest.b) <= 8))
+          continue;
+        fprintf(stderr, "VALUE %s: %s: got %d,%d,%d expected %d,%d,%d\n",
+                engine, t->name, r, g, b,
+                t->darkest.r, t->darkest.g, t->darkest.b);
+        failed++;
+     }
+   ck_assert_int_eq(failed, 0);
+#undef BLACK
+#undef GROWN
+#undef GREY
+}
+
+EFL_START_TEST(evas_filter_alpha)
+{
+   _alpha_check("buffer");
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_filter_gl_alpha)
+{
+   _alpha_check("opengl_x11");
+}
+EFL_END_TEST
+
 void evas_test_filter_values(TCase *tc)
 {
+   tcase_add_test(tc, evas_filter_alpha);
+   if (getenv("DISPLAY")) tcase_add_test(tc, evas_filter_gl_alpha);
    tcase_add_test(tc, evas_filter_quiet);
    if (getenv("DISPLAY")) tcase_add_test(tc, evas_filter_gl_quiet);
 

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

Reply via email to