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 843a266282806aa485cda4ca3fb48caff569afbb
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 14:09:41 2026 -0600

    evas/filters: tile repeated blends inside the destination
    
    The repeat fill modes placed a last partial tile past the end of the
    destination when the blend had an offset: the software engine wrote out
    of bounds, and could crash. The axis which was not repeated also
    counted its offset twice, drawing nothing past half the buffer.
    
    Each axis is now stepped through and cut to the destination, in both
    engines, which share the arithmetic.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../engines/gl_generic/filters/gl_filter_blend.c   | 194 +++++++--------------
 .../software_generic/filters/evas_filter_blend.c   | 167 ++++--------------
 2 files changed, 99 insertions(+), 262 deletions(-)

diff --git a/src/modules/evas/engines/gl_generic/filters/gl_filter_blend.c b/src/modules/evas/engines/gl_generic/filters/gl_filter_blend.c
index f2666ae31d..3de9fd17ce 100644
--- a/src/modules/evas/engines/gl_generic/filters/gl_filter_blend.c
+++ b/src/modules/evas/engines/gl_generic/filters/gl_filter_blend.c
@@ -1,6 +1,55 @@
 #include "gl_engine_filter.h"
 
-// Copied logic from SW engine
+/* The pieces of the source along one axis, as the software engine tiles it:
+ * a stretched axis has one, a repeated one as many as needed, else there is
+ * one at the offset. Those two are cut to the destination. */
+typedef struct _Blend_Axis Blend_Axis;
+struct _Blend_Axis
+{
+   int pos;
+   Eina_Bool repeat, stretch;
+};
+
+static void
+_axis_init(Blend_Axis *axis, int offset, int slen, Eina_Bool repeat, Eina_Bool stretch)
+{
+   axis->repeat = repeat;
+   axis->stretch = stretch;
+   axis->pos = offset;
+   if (repeat)
+     {
+        offset %= slen;
+        axis->pos = (offset > 0) ? offset - slen : offset;
+     }
+}
+
+static Eina_Bool
+_axis_next(Blend_Axis *axis, int s, int slen, int d, int dlen,
+           int *src, int *src_len, int *dst, int *dst_len)
+{
+   while (axis->pos < dlen)
+     {
+        const int pos = axis->pos;
+        const int cut = MAX(0, -pos);
+        const int len = MIN(slen - cut, dlen - MAX(0, pos));
+
+        if (axis->stretch)
+          {
+             *src = "" *src_len = slen; *dst = d; *dst_len = dlen;
+             axis->pos = dlen;
+             return EINA_TRUE;
+          }
+        axis->pos = axis->repeat ? pos + slen : dlen;
+        if (len > 0)
+          {
+             *src = "" *src_len = len; *dst = MAX(0, pos); *dst_len = len;
+             return EINA_TRUE;
+          }
+     }
+
+   return EINA_FALSE;
+}
+
 static Eina_Bool
 _mapped_blend(Evas_Engine_GL_Context *gc,
               Evas_GL_Image *image,
@@ -9,9 +58,8 @@ _mapped_blend(Evas_Engine_GL_Context *gc,
               int dx, int dy, int dw, int dh,
               Eina_Bool alphaonly)
 {
-   int right = 0, bottom = 0, left = 0, top = 0;
-   int row, col, rows, cols;
-   Eina_Bool ret = EINA_TRUE;
+   Blend_Axis rows, cols;
+   int src_x, src_y, src_w, src_h, dst_x, dst_y, dst_w, dst_h;
 
    if (fillmode == EVAS_FILTER_FILL_MODE_NONE)
      {
@@ -20,140 +68,24 @@ _mapped_blend(Evas_Engine_GL_Context *gc,
         return EINA_TRUE;
      }
 
-   if (fillmode & EVAS_FILTER_FILL_MODE_REPEAT_X)
-     {
-        if (dx > 0) left = dx % sw;
-        else if (dx < 0) left = sw + (dx % sw);
-        cols = (dw  /*- left*/) / sw;
-        if (left > 0)
-          right = dw - (sw * (cols - 1)) - left;
-        else
-          right = dw - (sw * cols);
-        dx = 0;
-     }
-   else if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X)
-     {
-        cols = 0;
-     }
-   else
-     {
-        // FIXME: Probably wrong if dx != 0
-        cols = 0;
-        dw -= dx;
-     }
+   if ((sw <= 0) || (sh <= 0)) return EINA_TRUE;
 
-   if (fillmode & EVAS_FILTER_FILL_MODE_REPEAT_Y)
+   _axis_init(&rows, dy, sh, !!(fillmode & EVAS_FILTER_FILL_MODE_REPEAT_Y),
+              !!(fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y));
+   while (_axis_next(&rows, sy, sh, dy, dh, &src_y, &src_h, &dst_y, &dst_h))
      {
-        if (dy > 0) top = dy % sh;
-        else if (dy < 0) top = sh + (dy % sh);
-        rows = (dh /*- top*/) / sh;
-        if (top > 0)
-          bottom = dh - (sh * (rows - 1)) - top;
-        else
-          bottom = dh - (sh * rows);
-        dy = 0;
-     }
-   else if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y)
-     {
-        rows = 0;
-     }
-   else
-     {
-        // FIXME: Probably wrong if dy != 0
-        rows = 0;
-        dh -= dy;
-     }
-
-   if (top > 0) row = -1;
-   else row = 0;
-   for (; row <= rows; row++)
-     {
-        int src_x, src_y, src_w, src_h;
-        int dst_x, dst_y, dst_w, dst_h;
-
-        if (row == -1 && top > 0)
+        _axis_init(&cols, dx, sw, !!(fillmode & EVAS_FILTER_FILL_MODE_REPEAT_X),
+                   !!(fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X));
+        while (_axis_next(&cols, sx, sw, dx, dw, &src_x, &src_w, &dst_x, &dst_w))
           {
-             // repeat only
-             src_h = top;
-             src_y = sh - top;
-             dst_y = dy;
-             dst_h = src_h;
-          }
-        else if (row == rows && bottom > 0)
-          {
-             // repeat only
-             src_h = bottom;
-             src_y = 0;
-             dst_y = top + dy + row * sh;
-             dst_h = src_h;
-          }
-        else
-          {
-             src_y = 0;
-             if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y)
-               {
-                  src_y = sy;
-                  src_h = sh;
-                  dst_y = dy;
-                  dst_h = dh;
-               }
-             else
-               {
-                  dst_y = top + dy + row * sh;
-                  src_h = MIN(dh - dst_y, sh);
-                  dst_h = src_h;
-               }
-          }
-        if (src_h <= 0 || dst_h <= 0) break;
-
-        if (left > 0) col = -1;
-        else col = 0;
-        for (; col <= cols; col++)
-          {
-             if (col == -1 && left > 0)
-               {
-                  // repeat only
-                  src_w = left;
-                  src_x = sw - left;
-                  dst_x = dx;
-                  dst_w = src_w;
-               }
-             else if (col == cols && right > 0)
-               {
-                  // repeat only
-                  src_w = right;
-                  src_x = 0;
-                  dst_x = left + dx + col * sw;
-                  dst_w = src_w;
-               }
-             else
-               {
-                  src_x = 0;
-                  if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X)
-                    {
-                       src_x = sx;
-                       src_w = sw;
-                       dst_x = dx;
-                       dst_w = dw;
-                    }
-                  else
-                    {
-                       dst_x = left + dx + col * sw;
-                       src_w = MIN(dw - dst_x, sw);
-                       dst_w = src_w;
-                    }
-               }
-             if (src_w <= 0 || dst_w <= 0) break;
-
-             DBG("blend: [%d,%d] %d,%d,%dx%d --> %d,%d,%dx%d "
-                 "(src %dx%d, dst %dx%d)",
-                 col, row, src_x, src_y, src_w, src_h,
-                 dst_x, dst_y, dst_w, dst_h, sw, sh, dw, dh);
+             DBG("blend: %d,%d,%dx%d --> %d,%d,%dx%d",
+                 src_x, src_y, src_w, src_h, dst_x, dst_y, dst_w, dst_h);
              evas_gl_common_filter_blend_push(gc, image->tex, src_x, src_y, src_w, src_h,
                                               dst_x, dst_y, dst_w, dst_h, alphaonly);
           }
      }
-   return ret;
+
+   return EINA_TRUE;
 }
 
 static Eina_Bool
diff --git a/src/modules/evas/engines/software_generic/filters/evas_filter_blend.c b/src/modules/evas/engines/software_generic/filters/evas_filter_blend.c
index 12745c4037..ee08f8af74 100644
--- a/src/modules/evas/engines/software_generic/filters/evas_filter_blend.c
+++ b/src/modules/evas/engines/software_generic/filters/evas_filter_blend.c
@@ -275,6 +275,17 @@ _filter_blend_cpu_rgba(Evas_Filter_Command *cmd)
    return _filter_blend_cpu_generic_do(cmd, _image_draw_cpu_rgba_rgba);
 }
 
+/* The first position of the source along an axis: repeated tiles start
+ * before the destination, a stretched source covers it. */
+static int
+_axis_start(int offset, int slen, Eina_Bool repeat, Eina_Bool stretch)
+{
+   if (stretch) return 0;
+   if (!repeat) return offset;
+   offset %= slen;
+   return (offset > 0) ? offset - slen : offset;
+}
+
 static Eina_Bool
 _mapped_blend(void *drawctx,
               const void *src_map, unsigned int src_stride,
@@ -286,9 +297,10 @@ _mapped_blend(void *drawctx,
               int dw, int dh,
               draw_func image_draw)
 {
-   int right = 0, bottom = 0, left = 0, top = 0;
-   int row, col, rows, cols;
+   const Eina_Bool repeat_x = !!(fillmode & EVAS_FILTER_FILL_MODE_REPEAT_X);
+   const Eina_Bool repeat_y = !!(fillmode & EVAS_FILTER_FILL_MODE_REPEAT_Y);
    Eina_Bool ret = EINA_TRUE;
+   int x0, y0, x, y, rows, cols;
 
    EINA_SAFETY_ON_FALSE_RETURN_VAL((sx == 0) && (sy == 0), EINA_FALSE);
 
@@ -306,143 +318,36 @@ _mapped_blend(void *drawctx,
         return EINA_TRUE;
      }
 
-   if (fillmode & EVAS_FILTER_FILL_MODE_REPEAT_X)
-     {
-        if (dx > 0) left = dx % sw;
-        else if (dx < 0) left = sw + (dx % sw);
-        cols = (dw  /*- left*/) / sw;
-        if (left > 0)
-          right = dw - (sw * (cols - 1)) - left;
-        else
-          right = dw - (sw * cols);
-        dx = 0;
-     }
-   else if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X)
-     {
-        cols = 0;
-        dx = 0;
-     }
-   else
-     {
-        // FIXME: Probably wrong if dx != 0
-        cols = 0;
-        dw -= dx;
-     }
+   if ((sw <= 0) || (sh <= 0)) return EINA_TRUE;
 
-   if (fillmode & EVAS_FILTER_FILL_MODE_REPEAT_Y)
-     {
-        if (dy > 0) top = dy % sh;
-        else if (dy < 0) top = sh + (dy % sh);
-        rows = (dh /*- top*/) / sh;
-        if (top > 0)
-          bottom = dh - (sh * (rows - 1)) - top;
-        else
-          bottom = dh - (sh * rows);
-        dy = 0;
-     }
-   else if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y)
-     {
-        rows = 0;
-        dy = 0;
-     }
-   else
-     {
-        // FIXME: Probably wrong if dy != 0
-        rows = 0;
-        dh -= dy;
-     }
+   x0 = _axis_start(dx, sw, repeat_x,
+                    !!(fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X));
+   y0 = _axis_start(dy, sh, repeat_y,
+                    !!(fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y));
 
-   if (top > 0) row = -1;
-   else row = 0;
-   for (; row <= rows; row++)
+   for (y = y0; y < dh; y += sh)
      {
-        int src_x, src_y, src_w, src_h;
-        int dst_x, dst_y, dst_w, dst_h;
+        const int src_y = MAX(0, -y);
+        const int dst_y = MAX(0, y);
+        const int h = MIN(sh - src_y, dh - dst_y);
 
-        if (row == -1 && top > 0)
+        for (x = x0; (h > 0) && (x < dw); x += sw)
           {
-             // repeat only
-             src_h = top;
-             src_y = sh - top;
-             dst_y = dy;
-             dst_h = src_h;
-          }
-        else if (row == rows && bottom > 0)
-          {
-             // repeat only
-             src_h = bottom;
-             src_y = 0;
-             dst_y = top + dy + row * sh;
-             dst_h = src_h;
-          }
-        else
-          {
-             src_y = 0;
-             if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y)
-               {
-                  src_h = sh;
-                  dst_h = dh;
-                  dst_y = 0;
-               }
-             else
-               {
-                  dst_y = top + dy + row * sh;
-                  src_h = MIN(dh - dst_y, sh);
-                  dst_h = src_h;
-               }
-          }
-        if (src_h <= 0 || dst_h <= 0) break;
+             const int src_x = MAX(0, -x);
+             const int dst_x = MAX(0, x);
+             const int w = MIN(sw - src_x, dw - dst_x);
 
-        if (left > 0) col = -1;
-        else col = 0;
-        for (; col <= cols; col++)
-          {
-             if (col == -1 && left > 0)
-               {
-                  // repeat only
-                  src_w = left;
-                  src_x = sw - left;
-                  dst_x = dx;
-                  dst_w = src_w;
-               }
-             else if (col == cols && right > 0)
-               {
-                  // repeat only
-                  src_w = right;
-                  src_x = 0;
-                  dst_x = left + dx + col * sw;
-                  dst_w = src_w;
-               }
-             else
-               {
-                  src_x = 0;
-                  if (fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X)
-                    {
-                       src_w = sw;
-                       dst_w = dw;
-                       dst_x = 0;
-                    }
-                  else
-                    {
-                       dst_x = left + dx + col * sw;
-                       src_w = MIN(dw - dst_x, sw);
-                       dst_w = src_w;
-                    }
-               }
-             if (src_w <= 0 || dst_w <= 0) break;
-
-             XDBG("blend: [%d,%d] %d,%d,%dx%d --> %d,%d,%dx%d "
-                  "(src %dx%d, dst %dx%d)",
-                  col, row, src_x, src_y, src_w, src_h,
-                  dst_x, dst_y, dst_w, dst_h,
-                  sw, sh, dw, dh);
-             image_draw(drawctx,
-                        src_map, src_stride, dst_map, dst_stride,
-                        src_x, src_y, src_w, src_h,
-                        dst_x, dst_y, dst_w, dst_h,
-                        EINA_TRUE, EINA_FALSE);
+             if (w > 0)
+               image_draw(drawctx,
+                          src_map, src_stride, dst_map, dst_stride,
+                          src_x, src_y, w, h,
+                          dst_x, dst_y, w, h,
+                          EINA_TRUE, EINA_FALSE);
+             if (!repeat_x) break;
           }
+        if (!repeat_y) break;
      }
+
    return ret;
 }
 

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

Reply via email to