Evas filters: Start implementing stretch for blend
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 3 Jan 2014 06:51:17 +0000 (15:51 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Fri, 7 Feb 2014 08:33:17 +0000 (17:33 +0900)
The fillmode is ignored when blending... for now.
First, implement none and stretch options for RGBA.

src/lib/evas/filters/evas_filter.c
src/lib/evas/filters/evas_filter_blend.c
src/lib/evas/filters/evas_filter_private.h

index d55bdb9a66ae6bb7259e5aa05e7da04b48a76f2b..aa8c26a9a788638b957a557f336086e8fee44a03 100644 (file)
@@ -161,6 +161,7 @@ _proxy_subrender(Evas *eo_e, Evas_Object *eo_source, Evas_Object *eo_proxy,
 
         ctx = e->engine.func->context_new(e->engine.data.output);
 
+        // FIXME: Not implemented for class Evas_Text.
         Eina_Bool source_clip;
         eo_do(eo_proxy, evas_obj_image_source_clip_get(&source_clip));
 
@@ -796,8 +797,10 @@ evas_filter_command_blend_add(Evas_Filter_Context *ctx, void *drawctx,
    cmd->draw.ox = ox;
    cmd->draw.oy = oy;
    cmd->draw.render_op = ENFN->context_render_op_get(ENDT, drawctx);
-   ENFN->context_clip_get(ENDT, drawctx, &cmd->draw.clip.x, &cmd->draw.clip.y,
-                          &cmd->draw.clip.w, &cmd->draw.clip.h);
+   cmd->draw.clip_use =
+         ENFN->context_clip_get(ENDT, drawctx,
+                                &cmd->draw.clip.x, &cmd->draw.clip.y,
+                                &cmd->draw.clip.w, &cmd->draw.clip.h);
 
    return cmd->id;
 }
index ec988439c658b52bd73a3b82daaf8947ac748cc7..9cf1a9e49db39079f59941a687bd0c36031e7553 100644 (file)
@@ -76,7 +76,8 @@ _filter_blend_cpu_rgba(Evas_Filter_Command *cmd)
 {
    RGBA_Image *in, *out;
    RGBA_Draw_Context *drawctx;
-   int w, h;
+   int sw, sh, dx, dy, dw, dh, sx, sy;
+   Eina_Bool repeat_x = EINA_FALSE, repeat_y = EINA_FALSE;
 
    if (!evas_filter_buffer_alloc(cmd->output, cmd->output->w, cmd->output->h))
      return EINA_FALSE;
@@ -85,21 +86,66 @@ _filter_blend_cpu_rgba(Evas_Filter_Command *cmd)
    out = cmd->output->backing;
    EINA_SAFETY_ON_NULL_RETURN_VAL(in, EINA_FALSE);
    EINA_SAFETY_ON_NULL_RETURN_VAL(out, EINA_FALSE);
-   w = in->cache_entry.w;
-   h = in->cache_entry.h;
+
+   sx = 0;
+   sy = 0;
+   sw = in->cache_entry.w;
+   sh = in->cache_entry.h;
+
+   dx = cmd->draw.ox;
+   dy = cmd->draw.oy;
+   dw = MIN(out->cache_entry.w - dx, out->cache_entry.w);
+   dh = MIN(out->cache_entry.h - dy, out->cache_entry.h);
 
    drawctx = cmd->ENFN->context_new(cmd->ENDT);
    cmd->ENFN->context_color_set(cmd->ENDT, drawctx, cmd->draw.R, cmd->draw.G,
                                 cmd->draw.B, cmd->draw.A);
    cmd->ENFN->context_render_op_set(cmd->ENDT, drawctx, cmd->draw.render_op);
-   cmd->ENFN->context_clip_set(cmd->ENDT, drawctx, cmd->draw.clip.x,
-                               cmd->draw.clip.y, cmd->draw.clip.w, cmd->draw.clip.h);
-
-   cmd->ENFN->image_draw(cmd->ENDT, drawctx, out, in,
-                         0, 0, w, h, // src
-                         cmd->draw.ox, cmd->draw.oy, w, h, // dst
-                         EINA_FALSE, // smooth
-                         EINA_FALSE); // Not async
+
+   if (cmd->draw.clip_use)
+     cmd->ENFN->context_clip_set(cmd->ENDT, drawctx,
+                                 cmd->draw.clip.x, cmd->draw.clip.y,
+                                 cmd->draw.clip.w, cmd->draw.clip.h);
+   else
+     cmd->ENFN->context_clip_set(cmd->ENDT, drawctx, dx, dy, dw, dh);
+
+   if (((dw != sw) || (dh != sh)) && cmd->draw.fillmode)
+     {
+        if (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_STRETCH_X)
+          dw = out->cache_entry.w - dx;
+        else if (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_REPEAT_X)
+          repeat_x = EINA_TRUE;
+        if (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_STRETCH_Y)
+          dh = out->cache_entry.h - dy;
+        else if (cmd->draw.fillmode & EVAS_FILTER_FILL_MODE_REPEAT_Y)
+          repeat_y = EINA_TRUE;
+     }
+   else if (cmd->draw.fillmode == EVAS_FILTER_FILL_MODE_NONE)
+     {
+        int src_w = dw;
+        int src_h = dh;
+        _clip_to_target(&sx, &sy, sw, sh, dx, dy, out->cache_entry.w, out->cache_entry.h, &dx, &dy, &dh, &dw);
+        if (src_w < sw) sw = src_w;
+        if (src_h < sh) sh = src_h;
+     }
+
+   if (!repeat_x && !repeat_y)
+     {
+        DBG("blend: %d,%d,%d,%d --> %d,%d,%d,%d (from %dx%d to %dx%d +%d,%d)",
+            0, 0, sw, sh, dx, dy, dw, dh,
+            in->cache_entry.w, in->cache_entry.h,
+            out->cache_entry.w, out->cache_entry.h,
+            dx, dy);
+        cmd->ENFN->image_draw(cmd->ENDT, drawctx, out, in,
+                              sx, sy, sw, sh, // src
+                              dx, dy, dw, dh, // dst
+                              EINA_TRUE, // smooth
+                              EINA_FALSE); // Not async
+     }
+   else
+     {
+        CRI("repeat not implemented yet");
+     }
 
    cmd->ENFN->context_free(cmd->ENDT, drawctx);
 
index 1357a3f786e95672f51ee2dfae9a25defbd672ed..c84edbdec1637000cff63f6bbbaff912ebb21eba 100644 (file)
@@ -115,6 +115,7 @@ struct _Evas_Filter_Command
          };
       } clip;
       Evas_Filter_Fill_Mode fillmode;
+      Eina_Bool clip_use : 1;
       Eina_Bool clip_mode_lrtb : 1;
    } draw;
 };