evas vg: Added gradients interpolation. 18/258018/3
authorMichal Szczecinski <m.szczecinsk@partner.samsung.com>
Fri, 7 May 2021 10:35:03 +0000 (12:35 +0200)
committerHermet Park <chuneon.park@samsung.com>
Mon, 10 May 2021 04:35:42 +0000 (04:35 +0000)
Added gradients interpolation in thorvg mode. In next commits cleanup
removing ector dependency will be performed.

Change-Id: Ie210f59b8403907c3e06dcb6b7985decf4dbc2a7

src/lib/evas/canvas/efl_canvas_vg_gradient.c
src/lib/evas/canvas/efl_canvas_vg_gradient_linear.c
src/lib/evas/canvas/efl_canvas_vg_gradient_radial.c
src/lib/evas/canvas/efl_canvas_vg_shape.c

index 869fa6a..41d112b 100644 (file)
@@ -17,7 +17,7 @@ _gradient_stop_set(Evas_Vg_Gradient *obj, const Efl_Gfx_Gradient_Stop *colors, u
    Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(obj, MY_CLASS);
    if (!gd) return;
 
-  Tvg_Color_Stop *color_stops = malloc(sizeof(Tvg_Color_Stop) * length);
+   Tvg_Color_Stop *color_stops = malloc(sizeof(Tvg_Color_Stop) * length);
    if (!color_stops) return;
 
    unsigned int i = 0;
@@ -121,7 +121,7 @@ _efl_canvas_vg_gradient_efl_gfx_gradient_spread_get(const Eo *obj EINA_UNUSED,
 
 static Eina_Bool
 _efl_canvas_vg_gradient_efl_gfx_path_interpolate(Eo *obj,
-                                         Efl_Canvas_Vg_Gradient_Data *pd,
+                                         Efl_Canvas_Vg_Gradient_Data *pd EINA_UNUSED,
                                          const Efl_VG *from, const Efl_VG *to,
                                          double pos_map)
 {
@@ -140,9 +140,9 @@ _efl_canvas_vg_gradient_efl_gfx_path_interpolate(Eo *obj,
    if (!r) return EINA_FALSE;
    if (fromd->colors_count != tod->colors_count) return EINA_FALSE;
 
+#ifndef HAVE_THORVG
    colors = realloc(pd->colors, sizeof (Efl_Gfx_Gradient_Stop) * tod->colors_count);
    if (!colors) return EINA_FALSE;
-
    pd->colors = colors;
 
 #define INTP(Pd, From, To, I, Member, From_Map, Pos_Map)                \
@@ -159,14 +159,39 @@ _efl_canvas_vg_gradient_efl_gfx_path_interpolate(Eo *obj,
 
 #undef INTP
 
+#else
+   unsigned len = 0, from_len = 0, to_len = 0;
+
+   Efl_Gfx_Gradient_Stop *fcolors, *tcolors;
+
+   _gradient_stop_get(obj, &colors, &len);
+   _gradient_stop_get((Efl_VG*) from, &fcolors, &from_len);
+   _gradient_stop_get((Efl_VG*) to, &tcolors, &to_len);
+
+   if (from_len != to_len) return EINA_FALSE;
+
+#define INTP(destination, f, t, I, Member, From_Map, Pos_Map)                \
+   destination[I].Member = f[I].Member * From_Map + t[I].Member * Pos_Map
+
+   for (i = 0; i < len; i++)
+     {
+        INTP(colors, fcolors, tcolors, i, offset, from_map, pos_map);
+        INTP(colors, fcolors, tcolors, i, r, from_map, pos_map);
+        INTP(colors, fcolors, tcolors, i, g, from_map, pos_map);
+        INTP(colors, fcolors, tcolors, i, b, from_map, pos_map);
+        INTP(colors, fcolors, tcolors, i, a, from_map, pos_map);
+     }
+
+#undef INTP
+
+   _gradient_stop_set(obj, colors, len);
+#endif
    return EINA_TRUE;
 }
 
 static void
 _efl_canvas_vg_gradient_efl_object_destructor(Eo *obj, Efl_Canvas_Vg_Gradient_Data *pd)
 {
-#ifdef HAVE_THORVG
-#endif
    if (pd->colors) free(pd->colors);
    efl_destructor(efl_super(obj, MY_CLASS));
 }
index 993c5ac..a015bd4 100644 (file)
@@ -158,6 +158,8 @@ _efl_canvas_vg_gradient_linear_efl_gfx_path_interpolate(Eo *obj,
                                                 double pos_map)
 {
    Efl_Canvas_Vg_Gradient_Linear_Data *fromd, *tod;
+   Efl_Canvas_Vg_Gradient_Data *gd;
+
    double from_map;
    Eina_Bool r;
 
@@ -179,6 +181,12 @@ _efl_canvas_vg_gradient_linear_efl_gfx_path_interpolate(Eo *obj,
 
 #undef INTP
 
+#ifdef HAVE_THORVG
+   gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
+   if (!gd) return EINA_FALSE;
+
+   tvg_linear_gradient_set(gd->gradient, pd->start.x, pd->start.y, pd->end.x, pd->end.y);
+#endif
    return EINA_TRUE;
 }
 
@@ -197,9 +205,18 @@ EAPI void
 evas_vg_gradient_linear_start_set(Evas_Vg_Gradient_Linear *obj, double x, double y)
 {
 #ifdef HAVE_THORVG
+   Efl_Canvas_Vg_Gradient_Linear_Data *lgd = NULL;
+   Efl_Canvas_Vg_Gradient_Data *gd = NULL;
+
    if (!obj) return;
 
-   Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
+   lgd = efl_data_scope_get(obj, MY_CLASS);
+   if (!lgd) return;
+
+   lgd->start.x = x;
+   lgd->start.y = y;
+
+   gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
    if (!gd) return;
 
    float x2 = 0.f, y2 = 0.f;
@@ -235,9 +252,18 @@ EAPI void
 evas_vg_gradient_linear_end_set(Evas_Vg_Gradient_Linear *obj, double x, double y)
 {
 #ifdef HAVE_THORVG
+   Efl_Canvas_Vg_Gradient_Linear_Data *lgd = NULL;
+   Efl_Canvas_Vg_Gradient_Data *gd = NULL;
+
    if (!obj) return;
 
-   Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
+   lgd = efl_data_scope_get(obj, MY_CLASS);
+   if (!lgd) return;
+
+   lgd->end.x = x;
+   lgd->end.y = y;
+
+   gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
    if (!gd) return;
 
    float x1 = 0.f, y1 = 0.f;
index 643e792..827f053 100644 (file)
@@ -198,6 +198,11 @@ _efl_canvas_vg_gradient_radial_efl_gfx_path_interpolate(Eo *obj,
 
 #undef INTP
 
+#ifdef HAVE_THORVG
+   Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
+   tvg_radial_gradient_set(gd->gradient, pd->center.x, pd->center.y, pd->radius);
+#endif
+
    return EINA_TRUE;
 }
 
@@ -222,12 +227,16 @@ evas_vg_gradient_radial_center_set(Evas_Vg_Gradient_Radial *obj, double x, doubl
    if (!obj) return;
 
    Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
-   if (!gd) return;
+   Efl_Canvas_Vg_Gradient_Radial_Data *rgd = efl_data_scope_get(obj, MY_CLASS);
+   if (!gd || !rgd) return;
 
    float r = 0.0f;
    tvg_radial_gradient_get(gd->gradient, NULL, NULL, &r);
    tvg_radial_gradient_set(gd->gradient, x, y, r);
 
+   rgd->center.x = x;
+   rgd->center.y = y;
+
    if (gd->shape) efl_canvas_vg_node_change(gd->shape);
 #else
    efl_gfx_gradient_radial_center_set(obj, x, y);
@@ -260,11 +269,13 @@ evas_vg_gradient_radial_radius_set(Evas_Vg_Gradient_Radial *obj, double r)
    if (!obj) return;
 
    Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(obj, EFL_CANVAS_VG_GRADIENT_CLASS);
-   if (!gd) return;
+   Efl_Canvas_Vg_Gradient_Radial_Data *rgd = efl_data_scope_get(obj, MY_CLASS);
+   if (!gd || !rgd) return;
 
    float x = 0.0f, y = 0.0f;
    tvg_radial_gradient_get(gd->gradient, &x, &y, NULL);
    tvg_radial_gradient_set(gd->gradient, x, y, r);
+   rgd->radius = r;
 
    if (gd->shape) efl_canvas_vg_node_change(gd->shape);
 #else
index 4c0aea6..5b9ac8d 100644 (file)
@@ -485,6 +485,18 @@ _shape_properties_interpolate(Evas_Vg_Shape *obj,
    sd->curr_ctrl.x = _interpolate(sd_from->curr_ctrl.x, sd_to->curr_ctrl.x, pos_map);
    sd->curr_ctrl.y = _interpolate(sd_from->curr_ctrl.y, sd_to->curr_ctrl.y, pos_map);
 
+   //Fill
+   if (sd_from->fill && sd_to->fill && sd->fill)
+      r &= efl_gfx_path_interpolate(sd->fill, sd_from->fill, sd_to->fill, pos_map);
+
+   //Stroke Fill
+   if (sd_from->stroke.fill && sd_to->stroke.fill && sd->stroke.fill)
+     r &= efl_gfx_path_interpolate(sd->stroke.fill, sd_from->stroke.fill, sd_to->stroke.fill, pos_map);
+
+   //Stroke Marker
+   if (sd_from->stroke.marker && sd_to->stroke.marker && sd->stroke.marker)
+     r &= efl_gfx_path_interpolate(sd->stroke.marker, sd_from->stroke.marker, sd_to->stroke.marker, pos_map);
+
    return EINA_TRUE;
 }