evas vg: integrating gradient stroke into Evas with ThorVG 56/256256/3
authorMira Grudzinska <m.grudzinska@samsung.com>
Tue, 30 Mar 2021 23:47:10 +0000 (01:47 +0200)
committerHermet Park <chuneon.park@samsung.com>
Wed, 7 Apr 2021 07:34:27 +0000 (07:34 +0000)
Change-Id: I3306fafeacc78b7e9b773bc4d9bfe63967c3f4cd

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
src/lib/evas/canvas/evas_vg_private.h

index ce8690a..993c5ac 100644 (file)
@@ -100,12 +100,16 @@ _efl_canvas_vg_gradient_linear_render_pre(Evas_Object_Protected_Data *vg_pd EINA
 #else
 static void
 _gradient_linear_render_pre_tvg(Efl_Canvas_Vg_Gradient_Data *gd,
-                                Tvg_Paint *shape)
+                                Tvg_Paint *shape,
+                                Evas_Vg_Gradient_Owner_Type owner)
 {
    if (!gd || !shape) return;
 
    //FIX_TVG: ignore the flag.... if nothing changed, do it needs to call again?
-   tvg_shape_set_linear_gradient(shape, gd->gradient);
+   if (owner == EVAS_VG_GRADIENT_OWNER_TYPE_SHAPE)
+     tvg_shape_set_linear_gradient(shape, gd->gradient);
+   else if (owner == EVAS_VG_GRADIENT_OWNER_TYPE_STROKE)
+     tvg_shape_set_stroke_linear_gradient(shape, gd->gradient);
 }
 #endif
 
index da736c0..643e792 100644 (file)
@@ -118,10 +118,15 @@ _efl_canvas_vg_gradient_radial_render_pre(Evas_Object_Protected_Data *vg_pd EINA
 #else
 static void
 _gradient_radial_render_pre_tvg(Efl_Canvas_Vg_Gradient_Data *gd,
-                                Tvg_Paint *shape)
+                                Tvg_Paint *shape,
+                                Evas_Vg_Gradient_Owner_Type owner)
 {
    if (!gd || !gd->gradient || !shape) return;
-   tvg_shape_set_radial_gradient(shape, gd->gradient);
+
+   if (owner == EVAS_VG_GRADIENT_OWNER_TYPE_SHAPE)
+     tvg_shape_set_radial_gradient(shape, gd->gradient);
+   else if (owner == EVAS_VG_GRADIENT_OWNER_TYPE_STROKE)
+     tvg_shape_set_stroke_radial_gradient(shape, gd->gradient);
 }
 #endif
 
index e44a4e0..820f201 100644 (file)
@@ -368,6 +368,16 @@ _shape_dup(Evas_Vg_Shape *obj, Evas_Vg_Shape *dup_from)
         if (gd) gd->gradient = grad;
      }
 
+   if (sd_from->stroke.fill)
+     {
+        Efl_Canvas_Vg_Gradient_Data *gd = NULL;
+        Tvg_Gradient *grad = NULL;
+        sd->stroke.fill = efl_duplicate(sd_from->stroke.fill);
+        tvg_shape_get_stroke_gradient(sd_from->shape, &grad);
+        gd = efl_data_scope_get(sd->stroke.fill, EFL_CANVAS_VG_GRADIENT_CLASS);
+        if (gd) gd->gradient = grad;
+     }
+
    sd->curr_ctrl.x = sd_from->curr_ctrl.x;
    sd->curr_ctrl.y = sd_from->curr_ctrl.y;
 
@@ -554,7 +564,7 @@ _efl_canvas_vg_shape_fill_set(Eo *obj EINA_UNUSED,
 
 #ifdef HAVE_THORVG
    Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(pd->fill, EFL_CANVAS_VG_GRADIENT_CLASS);
-   if (gd) gd->gradient_render_pre_tvg(gd, pd->shape);
+   if (gd) gd->gradient_render_pre_tvg(gd, pd->shape, EVAS_VG_GRADIENT_OWNER_TYPE_SHAPE);
 #endif
 }
 
@@ -571,9 +581,20 @@ _efl_canvas_vg_shape_stroke_fill_set(Eo *obj EINA_UNUSED,
 {
    if (pd->stroke.fill == f) return;
 
+   if (efl_isa(pd->stroke.fill, EFL_CANVAS_VG_GRADIENT_CLASS))
+     {
+        efl_del(pd->stroke.fill);
+        pd->stroke.fill = NULL;
+     }
+
    Efl_Canvas_Vg_Node *tmp = pd->stroke.fill;
    pd->stroke.fill = efl_ref(f);
    efl_unref(tmp);
+
+#ifdef HAVE_THORVG
+   Efl_Canvas_Vg_Gradient_Data *gd = efl_data_scope_get(pd->stroke.fill, EFL_CANVAS_VG_GRADIENT_CLASS);
+   if (gd) gd->gradient_render_pre_tvg(gd, pd->shape, EVAS_VG_GRADIENT_OWNER_TYPE_STROKE);
+#endif
 }
 
 static Efl_Canvas_Vg_Node *
@@ -694,7 +715,7 @@ _efl_canvas_vg_shape_render_pre_tvg(EINA_UNUSED Evas_Object_Protected_Data *vg_p
         if (gd)
            {
               gd->shape = obj;
-              gd->gradient_render_pre_tvg(gd, sd->shape);
+              gd->gradient_render_pre_tvg(gd, sd->shape, EVAS_VG_GRADIENT_OWNER_TYPE_SHAPE);
            }
      }
 
@@ -875,6 +896,17 @@ _efl_canvas_vg_shape_efl_duplicate_duplicate(const Eo *obj, Efl_Canvas_Vg_Shape_
         if (gd) gd->gradient = grad;
      }
 
+   if (pd->stroke.fill)
+     {
+        Tvg_Gradient *grad = NULL;
+        Efl_Canvas_Vg_Gradient_Data *gd = NULL;
+
+        sd->stroke.fill = efl_duplicate(pd->stroke.fill);
+        tvg_shape_get_stroke_gradient(sd->shape, &grad);
+        gd = efl_data_scope_get(sd->stroke.fill, EFL_CANVAS_VG_GRADIENT_CLASS);
+        if (gd) gd->gradient = grad;
+     }
+
    sd->curr_ctrl = pd->curr_ctrl;
    sd->curr = pd->curr;
    sd->start = pd->start;
index baf7528..49f571a 100644 (file)
@@ -7,6 +7,14 @@
 #include <Ector.h>
 #endif
 
+#ifdef HAVE_THORVG
+typedef enum
+{
+  EVAS_VG_GRADIENT_OWNER_TYPE_SHAPE = 0,   /**< Gradient set as the fill of the shape */
+  EVAS_VG_GRADIENT_OWNER_TYPE_STROKE       /**< Gradient set as the fill of the shape's stroke */
+} Evas_Vg_Gradient_Owner_Type;
+#endif
+
 typedef struct _Efl_Canvas_Vg_Node_Data             Efl_Canvas_Vg_Node_Data;
 typedef struct _Efl_Canvas_Vg_Container_Data        Efl_Canvas_Vg_Container_Data;
 typedef struct _Efl_Canvas_Vg_Gradient_Data         Efl_Canvas_Vg_Gradient_Data;
@@ -142,7 +150,7 @@ struct _Efl_Canvas_Vg_Gradient_Data
 #ifdef HAVE_THORVG
    Tvg_Gradient *gradient;
    Evas_Vg_Shape *shape;
-   void (*gradient_render_pre_tvg)(Efl_Canvas_Vg_Gradient_Data *gd, Tvg_Paint *shape);
+   void (*gradient_render_pre_tvg)(Efl_Canvas_Vg_Gradient_Data *gd, Tvg_Paint *shape, Evas_Vg_Gradient_Owner_Type owner);
 #endif
 };