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

git pushed a commit to reference refs/pull/285/head
in repository efl.

View the commit online.

commit ed9b5f73425f4337281b7cc0e03224c8126cc2f5
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 13:03:01 2026 -0600

    evas/gl: back alpha filter buffers with one channel textures
    
    Alpha buffers took four bytes per pixel to hold one value. Now that
    every channel of them is the same, they can be GL_R8 render targets,
    with a swizzle giving that value to all channels when sampled, so that
    shaders reading them see what they did before. A swizzle does not
    apply to glReadPixels, so mapping a buffer for a software operation
    takes the red channel.
    
    Whether GL can render to and swizzle such a texture is probed when the
    context is created, and the RGBA textures stay where it can not, as on
    GLES 2. EVAS_GL_COVERAGE_TARGET=0 forces them, to compare. Color
    glyphs drawn into an alpha buffer now go through the alpha shader to
    keep storing their alpha.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../evas/engines/gl_common/evas_gl_common.h        |  7 ++
 .../evas/engines/gl_common/evas_gl_context.c       |  4 +-
 src/modules/evas/engines/gl_common/evas_gl_image.c | 39 +++++++++++
 .../evas/engines/gl_common/evas_gl_texture.c       | 80 ++++++++++++++++++++++
 .../evas/engines/gl_generic/evas_ector_gl_buffer.c | 12 +++-
 src/modules/evas/engines/gl_generic/evas_engine.c  |  3 +
 src/tests/evas/evas_test_filters.c                 |  7 ++
 7 files changed, 150 insertions(+), 2 deletions(-)

diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h
index 9e1dab8a5f..3cd605e8b4 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -162,6 +162,8 @@ struct _Evas_GL_Shared
       Eina_Bool etc2              : 1;
       Eina_Bool etc1_subimage     : 1;
       Eina_Bool s3tc              : 1;
+      /* a one channel texture can be rendered to, and sampled as four */
+      Eina_Bool coverage_target   : 1;
       // tuning params - per gpu/cpu combo?
 #define DEF_CUTOUT                   64
 #define DEF_CUTOUT_SIZE_MIN     (64*64)
@@ -553,6 +555,8 @@ struct _Evas_GL_Image
    Eina_Bool          direct        : 1; // evas gl direct renderable
    /*Disable generate atlas for texture unit, EINA_FALSE by default*/
    Eina_Bool          disable_atlas : 1;
+   /* a surface keeping one value per pixel, which reads as all channels */
+   Eina_Bool          coverage      : 1;
 };
 
 struct _Evas_GL_Font_Texture
@@ -774,6 +778,8 @@ void              evas_gl_texture_pool_empty(Evas_GL_Texture_Pool *pt);
 Evas_GL_Texture  *evas_gl_common_texture_new(Evas_Engine_GL_Context *gc, RGBA_Image *im, Eina_Bool disable_atlas);
 Evas_GL_Texture  *evas_gl_common_texture_native_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha, Evas_GL_Image *im);
 Evas_GL_Texture  *evas_gl_common_texture_render_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha, int stencil);
+void              evas_gl_common_texture_coverage_probe(Evas_GL_Shared *shared);
+Evas_GL_Texture  *evas_gl_common_texture_render_coverage_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h);
 Evas_GL_Texture  *evas_gl_common_texture_render_noscale_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha);
 Evas_GL_Texture  *evas_gl_common_texture_render_noscale_noatlas_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha);
 Evas_GL_Texture  *evas_gl_common_texture_dynamic_new(Evas_Engine_GL_Context *gc, Evas_GL_Image *im);
@@ -806,6 +812,7 @@ Evas_GL_Image    *evas_gl_common_image_alpha_set(Evas_GL_Image *im, int alpha);
 void              evas_gl_common_image_scale_hint_set(Evas_GL_Image *im, int hint);
 void              evas_gl_common_image_content_hint_set(Evas_GL_Image *im, int hint);
 void              evas_gl_common_image_cache_flush(Evas_Engine_GL_Context *gc);
+Evas_GL_Image    *evas_gl_common_image_surface_coverage_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h);
 Evas_GL_Image    *evas_gl_common_image_surface_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha, int stencil);
 Evas_GL_Image    *evas_gl_common_image_surface_noscale_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha);
 Evas_GL_Image    *evas_gl_common_image_surface_noscale_noatlas_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha);
diff --git a/src/modules/evas/engines/gl_common/evas_gl_context.c b/src/modules/evas/engines/gl_common/evas_gl_context.c
index 5c5cf6455c..8b15793e5e 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_context.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_context.c
@@ -1037,6 +1037,7 @@ evas_gl_common_context_new(void)
         GETENVOPT("EVAS_GL_ATLAS_ALLOC_ALPHA_SIZE", atlas.max_alloc_alpha_size, MIN_ATLAS_ALLOC_ALPHA, MAX_ATLAS_ALLOC_ALPHA);
         GETENVOPT("EVAS_GL_ATLAS_MAX_W", atlas.max_w, 0, MAX_ATLAS_W);
         GETENVOPT("EVAS_GL_ATLAS_MAX_H", atlas.max_h, 0, MAX_ATLAS_H);
+        evas_gl_common_texture_coverage_probe(shared);
         s = (const char *)getenv("EVAS_GL_GET_PROGRAM_BINARY");
         if (s)
           {
@@ -2588,7 +2589,8 @@ evas_gl_common_context_font_push(Evas_Engine_GL_Context *gc,
                                                  sw, sh, w, h, EINA_FALSE, tex, EINA_FALSE,
                                                  mtex, mask_smooth, mask_color, mw, mh,
                                                  EINA_FALSE, NULL, NULL, &masksam);
-        if (!mtex) gc->shared->font_prog = prog;
+        /* not the program of a coverage surface, which differs */
+        if (!mtex && !gc->filter_alpha) gc->shared->font_prog = prog;
      }
 
    pn = _evas_gl_common_context_push(SHD_FONT,
diff --git a/src/modules/evas/engines/gl_common/evas_gl_image.c b/src/modules/evas/engines/gl_common/evas_gl_image.c
index 55cf2ea6fe..a31ba9928a 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_image.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_image.c
@@ -762,6 +762,45 @@ evas_gl_common_image_surface_new(Evas_Engine_GL_Context *gc, unsigned int w, uns
    return im;
 }
 
+/* A surface for coverage: one byte per pixel where GL allows it, else the
+ * RGBA of other surfaces. Shaders write the same value to every channel, so
+ * that both read alike when sampled. */
+Evas_GL_Image *
+evas_gl_common_image_surface_coverage_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h)
+{
+   Evas_GL_Image *im;
+   Evas_GL_Texture *tex = NULL;
+
+   if (((int)w > gc->shared->info.max_texture_size) ||
+       ((int)h > gc->shared->info.max_texture_size))
+     return NULL;
+
+   if (gc->shared->info.coverage_target)
+     tex = evas_gl_common_texture_render_coverage_new(gc, w, h);
+
+   if (!tex)
+     im = evas_gl_common_image_surface_new(gc, w, h, EINA_TRUE, EINA_FALSE);
+   else
+     {
+        im = calloc(1, sizeof(Evas_GL_Image));
+        if (!im)
+          {
+             evas_gl_common_texture_free(tex, EINA_TRUE);
+             return NULL;
+          }
+        im->references = 1;
+        im->gc = gc;
+        im->cs.space = EVAS_COLORSPACE_ARGB8888;
+        im->alpha = 1;
+        im->w = w;
+        im->h = h;
+        im->tex = tex;
+        im->tex_only = 1;
+     }
+   if (im) im->coverage = 1;
+   return im;
+}
+
 Evas_GL_Image *
 evas_gl_common_image_surface_noscale_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha)
 {
diff --git a/src/modules/evas/engines/gl_common/evas_gl_texture.c b/src/modules/evas/engines/gl_common/evas_gl_texture.c
index 76ea5f8b2e..1ec10e8931 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_texture.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_texture.c
@@ -1,5 +1,18 @@
 #include "evas_gl_private.h"
 
+/* not in the headers of GLES 2 and of old desktop GL */
+#ifndef GL_R8
+# define GL_R8 0x8229
+#endif
+#ifndef GL_RED
+# define GL_RED 0x1903
+#endif
+#ifndef GL_TEXTURE_SWIZZLE_G
+# define GL_TEXTURE_SWIZZLE_G 0x8E43
+# define GL_TEXTURE_SWIZZLE_B 0x8E44
+# define GL_TEXTURE_SWIZZLE_A 0x8E45
+#endif
+
 static const GLenum rgba_fmt   = GL_RGBA;
 static const GLenum rgba_ifmt  = GL_RGBA;
 
@@ -294,6 +307,7 @@ _evas_gl_texture_size_get(int w, int h, int intfmt, Eina_Bool *comp)
       case GL_RGB:
         return w * h * 4;
       case GL_ALPHA:
+      case GL_R8:
         return w * h * 1;
       case GL_ALPHA4:
         return w * h / 2; // TODO: Check this
@@ -1120,6 +1134,72 @@ evas_gl_common_texture_render_new(Evas_Engine_GL_Context *gc, unsigned int w, un
    return tex;
 }
 
+/* Sampling a one channel texture gives (r, 0, 0, 1): give its value to every
+ * channel, as a white premultiplied texel of that coverage would. */
+static void
+_tex_coverage_swizzle(GLuint texture)
+{
+   glBindTexture(GL_TEXTURE_2D, texture);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_RED);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
+   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED);
+}
+
+/* Rendering to GL_R8 and swizzling come from GL 3.3, GLES 3 or extensions:
+ * rather than sorting those out, try it. */
+void
+evas_gl_common_texture_coverage_probe(Evas_GL_Shared *shared)
+{
+   GLuint texture = 0, fb = 0;
+   GLint previous_fb = 0, previous_tex = 0;
+   const char *s;
+
+   shared->info.coverage_target = 0;
+   s = getenv("EVAS_GL_COVERAGE_TARGET");
+   if (s && !atoi(s)) return;
+
+   while (glGetError() != GL_NO_ERROR);
+
+   glGetIntegerv(GL_FRAMEBUFFER_BINDING, &previous_fb);
+   glGetIntegerv(GL_TEXTURE_BINDING_2D, &previous_tex);
+   glGenTextures(1, &texture);
+   glBindTexture(GL_TEXTURE_2D, texture);
+   glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 4, 4, 0, GL_RED, GL_UNSIGNED_BYTE, NULL);
+   _tex_coverage_swizzle(texture);
+   glsym_glGenFramebuffers(1, &fb);
+   glsym_glBindFramebuffer(GL_FRAMEBUFFER, fb);
+   glsym_glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+                                GL_TEXTURE_2D, texture, 0);
+   if ((glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE) &&
+       (glGetError() == GL_NO_ERROR))
+     shared->info.coverage_target = 1;
+
+   glsym_glBindFramebuffer(GL_FRAMEBUFFER, previous_fb);
+   glsym_glDeleteFramebuffers(1, &fb);
+   glBindTexture(GL_TEXTURE_2D, previous_tex);
+   glDeleteTextures(1, &texture);
+   while (glGetError() != GL_NO_ERROR);
+}
+
+Evas_GL_Texture *
+evas_gl_common_texture_render_coverage_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h)
+{
+   Evas_GL_Texture *tex;
+
+   tex = evas_gl_common_texture_alloc(gc, w, h, EINA_TRUE);
+   if (!tex) return NULL;
+   tex->pt = _pool_tex_render_new(gc, w, h, GL_R8, GL_RED, 0);
+   if (!tex->pt)
+     {
+        evas_gl_common_texture_light_free(tex);
+        return NULL;
+     }
+   _tex_coverage_swizzle(tex->pt->texture);
+   glBindTexture(gc->state.current.tex_target, gc->state.current.cur_tex);
+   tex->pt->references++;
+   return tex;
+}
+
 Evas_GL_Texture *
 evas_gl_common_texture_render_noscale_new(Evas_Engine_GL_Context *gc, unsigned int w, unsigned int h, int alpha)
 {
diff --git a/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c b/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c
index fc48ea6dd7..e9cd24d534 100644
--- a/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c
+++ b/src/modules/evas/engines/gl_generic/evas_ector_gl_buffer.c
@@ -144,7 +144,10 @@ _evas_ector_gl_buffer_gl_buffer_prepare(Eo *obj, Evas_Ector_GL_Buffer_Data *pd,
 
    pd->re = re;
    gc = gl_generic_context_find(re, 1);
-   im = evas_gl_common_image_surface_new(gc, w, h, EINA_TRUE, EINA_FALSE);
+   if (pd->alpha_only)
+     im = evas_gl_common_image_surface_coverage_new(gc, w, h);
+   else
+     im = evas_gl_common_image_surface_new(gc, w, h, EINA_TRUE, EINA_FALSE);
    if (!im) fail("Failed to create GL surface!");
    _surface_clear(gc, im);
 
@@ -280,6 +283,12 @@ _evas_ector_gl_buffer_ector_buffer_map(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buffer
    map->im = tofree ? im : NULL;
 
    len = W * H;
+
+   /* Red holds the value of a coverage surface: reading one back gives
+    * nothing else, a one channel texture having no other. */
+   if (pd->alpha_only)
+     for (int k = 0; k < len; k++)
+       data[k] = (uint32_t) R_VAL(&data[k]) * 0x01010101u;
    if (cspace == EFL_GFX_COLORSPACE_GRY8)
      {
         uint8_t *data8 = malloc(len);
@@ -349,6 +358,7 @@ _evas_ector_gl_buffer_ector_buffer_unmap(Eo *obj EINA_UNUSED, Evas_Ector_GL_Buff
                        MAP_DUMP(old_glim, "out_w_nofree");
                        pd->glim = evas_gl_common_image_surface_update(old_glim);
                     }
+                  if (pd->glim) pd->glim->coverage = pd->alpha_only;
                }
              else
                {
diff --git a/src/modules/evas/engines/gl_generic/evas_engine.c b/src/modules/evas/engines/gl_generic/evas_engine.c
index ce25effd0a..abd82266e4 100644
--- a/src/modules/evas/engines/gl_generic/evas_engine.c
+++ b/src/modules/evas/engines/gl_generic/evas_engine.c
@@ -1583,8 +1583,11 @@ eng_font_draw(void *engine EINA_UNUSED, void *data, void *context, void *surface
    Evas_Engine_GL_Context *gl_context;
 
    gl_context = _font_ext_set(data, context, surface);
+   /* color glyphs leave their alpha in a coverage surface */
+   gl_context->filter_alpha = ((Evas_GL_Image *) surface)->coverage;
    evas_common_font_draw_prepare(intl_props);
    evas_common_font_draw(gl_context->font_surface, context, x, y, intl_props->glyphs);
+   gl_context->filter_alpha = EINA_FALSE;
    _font_ext_clear(context);
 
    return EINA_FALSE;
diff --git a/src/tests/evas/evas_test_filters.c b/src/tests/evas/evas_test_filters.c
index 6c9db2c40a..8e41441a2a 100644
--- a/src/tests/evas/evas_test_filters.c
+++ b/src/tests/evas/evas_test_filters.c
@@ -848,6 +848,13 @@ EFL_START_TEST(evas_filter_gl_alpha_writes)
         A "displace { m, src = "" dst = a, intensity = 4 }" SHOW, NULL },
       { C "m = buffer { 'rgba' } fill { dst = m, color = '#808080' } "
         A "displace { m, src = "" dst = a, intensity = 4 }" SHOW, NULL },
+      /* transform runs in software: alpha buffers are read back and written */
+      { A "b = buffer { 'alpha' } blend { dst = a } "
+        "transform { op = 'vflip', src = "" dst = b } "
+        "blend { b, color = 'blue' }", NULL },
+      { A "b = buffer { 'alpha' } blend { dst = a } "
+        "transform { op = 'vflip', src = "" dst = b } "
+        "blur { 2, src = "" dst = a }" SHOW, NULL },
       /* Software unites the mask with the source instead of masking when the
        * destination is an alpha buffer: compare with what a full mask leaves. */
       { "m = buffer { 'alpha' } fill { dst = m, color = 'white' } "

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

Reply via email to