evas: add logic to duplicate recursively an Efl_VG_Node tree.
authorCedric BAIL <cedric@osg.samsung.com>
Fri, 19 Jun 2015 09:26:46 +0000 (11:26 +0200)
committerCedric BAIL <cedric@osg.samsung.com>
Fri, 21 Aug 2015 14:40:31 +0000 (16:40 +0200)
13 files changed:
src/lib/evas/canvas/efl_vg_base.eo
src/lib/evas/canvas/efl_vg_container.eo
src/lib/evas/canvas/efl_vg_gradient.eo
src/lib/evas/canvas/efl_vg_gradient_linear.eo
src/lib/evas/canvas/efl_vg_gradient_radial.eo
src/lib/evas/canvas/efl_vg_shape.eo
src/lib/evas/canvas/evas_vg_container.c
src/lib/evas/canvas/evas_vg_gradient.c
src/lib/evas/canvas/evas_vg_gradient_linear.c
src/lib/evas/canvas/evas_vg_gradient_radial.c
src/lib/evas/canvas/evas_vg_node.c
src/lib/evas/canvas/evas_vg_private.h
src/lib/evas/canvas/evas_vg_shape.c

index 7ddfce5..15a8913 100644 (file)
@@ -96,6 +96,11 @@ abstract Efl.VG.Base (Eo.Base, Efl.Gfx.Base, Efl.Gfx.Stack)
           @in pos_map: double;
         }
       }
+      dup {
+        params {
+          @in from: const(Efl.VG.Base)*;
+        }
+      }
    }
    implements {
       Eo.Base.parent.set;
index b3a6ec4..21bb5e7 100644 (file)
@@ -17,5 +17,6 @@ class Efl.VG.Container (Efl.VG.Base)
       Eo.Base.destructor;
       Efl.VG.Base.bounds_get;
       Efl.VG.Base.interpolate;
+      Efl.VG.Base.dup;
    }
 }
index 959da5b..7f794cb 100644 (file)
@@ -7,5 +7,6 @@ abstract Efl.VG.Gradient (Efl.VG.Base, Efl.Gfx.Gradient.Base)
       Efl.Gfx.Gradient.Base.spread.set;
       Efl.Gfx.Gradient.Base.spread.get;
       Efl.VG.Base.interpolate;
+      Efl.VG.Base.dup;
    }
 }
index aecfe4e..381ddb6 100644 (file)
@@ -8,6 +8,7 @@ class Efl.VG.Gradient_Linear (Efl.VG.Gradient, Efl.Gfx.Gradient.Linear)
       Efl.Gfx.Gradient.Linear.end.get;
       Efl.VG.Base.bounds_get;
       Efl.VG.Base.interpolate;
+      Efl.VG.Base.dup;
       Eo.Base.constructor;
       Eo.Base.destructor;
    }
index bd99848..860c4f7 100644 (file)
@@ -10,6 +10,7 @@ class Efl.VG.Gradient_Radial (Efl.VG.Gradient, Efl.Gfx.Gradient.Radial)
       Efl.Gfx.Gradient.Radial.focal.get;     
       Efl.VG.Base.bounds_get;
       Efl.VG.Base.interpolate;
+      Efl.VG.Base.dup;
       Eo.Base.constructor;
       Eo.Base.destructor;
    }
index e2d5c27..053a374 100644 (file)
@@ -42,6 +42,7 @@ class Efl.VG.Shape (Efl.VG.Base, Efl.Gfx.Shape)
       Efl.Gfx.Base.color_part.get;
       Efl.VG.Base.bounds_get;
       Efl.VG.Base.interpolate;
+      Efl.VG.Base.dup;
       Eo.Base.constructor;
       Eo.Base.destructor;
    }
index 683f5ce..32ffbfa 100644 (file)
@@ -135,6 +135,32 @@ _efl_vg_container_efl_vg_base_interpolate(Eo *obj,
    return r;
 }
 
+static void
+_efl_vg_container_efl_vg_base_dup(Eo *obj,
+                                  Efl_VG_Container_Data *pd,
+                                  const Efl_VG_Base *from)
+{
+   Efl_VG_Container_Data *fromd;
+   Eina_List *l;
+   Eo *child;
+
+   eo_do_super(obj, EFL_VG_CONTAINER_CLASS, efl_vg_dup(from));
+
+   fromd = eo_data_scope_get(from, EFL_VG_CONTAINER_CLASS);
+
+   EINA_LIST_FREE(pd->children, child)
+     eo_unref(child);
+
+   EINA_LIST_FOREACH(fromd->children, l, child)
+     {
+        // By setting parent, we automatically reference
+        // this new object as a child of obj. Magic at work !
+        eo_add_ref(eo_class_get(child),
+                   obj,
+                   efl_vg_dup(child));
+     }
+}
+
 EAPI Efl_VG*
 evas_vg_container_add(Efl_VG *parent)
 {
index 495a493..dff4738 100644 (file)
@@ -94,6 +94,22 @@ _efl_vg_gradient_efl_vg_base_interpolate(Eo *obj,
    return EINA_TRUE;
 }
 
+static void
+_efl_vg_gradient_efl_vg_base_dup(Eo *obj,
+                                 Efl_VG_Gradient_Data *pd EINA_UNUSED,
+                                 const Efl_VG_Base *from)
+{
+   Efl_VG_Gradient_Data *fromd;
+
+   eo_do_super(obj, EFL_VG_GRADIENT_CLASS, efl_vg_dup(from));
+
+   fromd = eo_data_scope_get(from, EFL_VG_GRADIENT_CLASS);
+
+   eo_do(obj,
+         efl_gfx_gradient_stop_set(fromd->colors, fromd->colors_count),
+         efl_gfx_gradient_spread_set(fromd->s));
+}
+
 EAPI void
 evas_vg_gradient_stop_set(Eo *obj, const Efl_Gfx_Gradient_Stop *colors, unsigned int length)
 {
index 609dc7a..7234d4b 100644 (file)
@@ -151,6 +151,22 @@ _efl_vg_gradient_linear_efl_vg_base_interpolate(Eo *obj,
    return EINA_TRUE;
 }
 
+static void
+_efl_vg_gradient_linear_efl_vg_base_dup(Eo *obj,
+                                        Efl_VG_Gradient_Linear_Data *pd EINA_UNUSED,
+                                        const Efl_VG_Base *from)
+{
+   Efl_VG_Gradient_Linear_Data *fromd;
+
+   eo_do_super(obj, EFL_VG_GRADIENT_LINEAR_CLASS, efl_vg_dup(from));
+
+   fromd = eo_data_scope_get(from, EFL_VG_GRADIENT_LINEAR_CLASS);
+
+   eo_do(obj,
+         efl_gfx_gradient_linear_start_set(fromd->start.x, fromd->start.y),
+         efl_gfx_gradient_linear_end_set(fromd->end.x, fromd->end.y));
+}
+
 EAPI void
 evas_vg_gradient_linear_start_set(Eo *obj, double x, double y)
 {
index 52ed957..d6d62c5 100644 (file)
@@ -170,6 +170,23 @@ _efl_vg_gradient_radial_efl_vg_base_interpolate(Eo *obj,
    return EINA_TRUE;
 }
 
+static void
+_efl_vg_gradient_radial_efl_vg_base_dup(Eo *obj,
+                                        Efl_VG_Gradient_Radial_Data *pd EINA_UNUSED,
+                                        const Efl_VG_Base *from)
+{
+   Efl_VG_Gradient_Radial_Data *fromd;
+
+   eo_do_super(obj, EFL_VG_GRADIENT_RADIAL_CLASS, efl_vg_dup(from));
+
+   fromd = eo_data_scope_get(from, EFL_VG_GRADIENT_RADIAL_CLASS);
+
+   eo_do(obj,
+         efl_gfx_gradient_radial_focal_set(fromd->focal.x, fromd->focal.y),
+         efl_gfx_gradient_radial_center_set(fromd->center.x, fromd->center.y),
+         efl_gfx_gradient_radial_radius_set(fromd->radius));
+}
+
 EAPI void
 evas_vg_gradient_radial_center_set(Eo *obj, double x, double y)
 {
index 901e550..d160b45 100644 (file)
@@ -744,7 +744,11 @@ _efl_vg_base_dup(Eo *obj, Efl_VG_Base_Data *pd, const Efl_VG_Base *from)
    Eo *parent = NULL;
 
    fromd = eo_data_scope_get(from, EFL_VG_BASE_CLASS);
-   pd->name = eina_stringshare_ref(fromd->name);
+   if (pd->name != fromd->name)
+     {
+        eina_stringshare_del(pd->name);
+        pd->name = eina_stringshare_ref(fromd->name);
+     }
 
    _efl_vg_base_parent_checked_get(obj, &parent, &cd);
    if (cd) _efl_vg_base_name_insert(obj, pd, cd);
@@ -755,6 +759,12 @@ _efl_vg_base_dup(Eo *obj, Efl_VG_Base_Data *pd, const Efl_VG_Base *from)
         pd->intp = NULL;
      }
 
+   if (pd->renderer)
+     {
+        eo_del(pd->renderer);
+        pd->renderer = NULL;
+     }
+
    if (fromd->m)
      {
         pd->m = pd->m ? pd->m : malloc(sizeof (Eina_Matrix3)) ;
index 8ee62b6..102de5b 100644 (file)
@@ -73,6 +73,24 @@ _efl_vg_base_changed(Eo *obj)
    eo_do(obj, eo_event_callback_call(EFL_GFX_CHANGED, NULL));
 }
 
+static inline void *
+_efl_vg_realloc(void *from, unsigned int sz)
+{
+   void *result;
+
+   result = sz > 0 ? realloc(from, sz) : NULL;
+   if (!result) free(from);
+
+   return result;
+}
+
+static inline void
+_efl_vg_clean_object(Eo **obj)
+{
+   if (*obj) eo_unref(*obj);
+   *obj = NULL;
+}
+
 #define EFL_VG_COMPUTE_MATRIX(Current, Parent, Nd)                      \
   Eina_Matrix3 *Current = Nd->m;                                        \
   Eina_Matrix3 _matrix_tmp;                                             \
index d17268d..520c684 100644 (file)
@@ -375,6 +375,47 @@ _efl_vg_shape_efl_vg_base_interpolate(Eo *obj,
    return r;
 }
 
+static void
+_efl_vg_shape_efl_vg_base_dup(Eo *obj, Efl_VG_Shape_Data *pd EINA_UNUSED, const Efl_VG_Base *from)
+{
+   Efl_VG_Shape_Data *fromd;
+   Eo *parent;
+   Eo *fill = NULL, *stroke_fill = NULL, *stroke_marker = NULL;
+
+   eo_do_super(obj, MY_CLASS, efl_vg_dup(from));
+
+   eo_do(obj, parent = eo_parent_get());
+
+   fromd = eo_data_scope_get(from, MY_CLASS);
+
+   if (fromd->fill)
+     {
+        fill = eo_add(eo_class_get(fromd->fill),
+                      parent,
+                      efl_vg_dup(fromd->fill));
+     }
+
+   if (fromd->stroke.fill)
+     {
+        stroke_fill = eo_add(eo_class_get(fromd->stroke.fill),
+                             parent,
+                             efl_vg_dup(fromd->stroke.fill));
+     }
+
+   if (fromd->stroke.marker)
+     {
+        stroke_marker = eo_add(eo_class_get(fromd->stroke.marker),
+                               parent,
+                               efl_vg_dup(fromd->stroke.marker));
+     }
+
+   eo_do(obj,
+         efl_vg_shape_fill_set(fill),
+         efl_vg_shape_stroke_fill_set(stroke_fill),
+         efl_vg_shape_stroke_marker_set(stroke_marker),
+         efl_gfx_shape_dup(from));
+}
+
 EAPI double
 evas_vg_shape_stroke_scale_get(Eo *obj)
 {