cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=05fdfcc76a7eb57d00ae52d3ab2b9a1eb3ee0db9

commit 05fdfcc76a7eb57d00ae52d3ab2b9a1eb3ee0db9
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Fri Jun 19 11:26:46 2015 +0200

    evas: add logic to duplicate recursively an Efl_VG_Node tree.
---
 src/lib/evas/canvas/efl_vg_base.eo            |  5 ++++
 src/lib/evas/canvas/efl_vg_container.eo       |  1 +
 src/lib/evas/canvas/efl_vg_gradient.eo        |  1 +
 src/lib/evas/canvas/efl_vg_gradient_linear.eo |  1 +
 src/lib/evas/canvas/efl_vg_gradient_radial.eo |  1 +
 src/lib/evas/canvas/efl_vg_shape.eo           |  1 +
 src/lib/evas/canvas/evas_vg_container.c       | 26 +++++++++++++++++
 src/lib/evas/canvas/evas_vg_gradient.c        | 16 +++++++++++
 src/lib/evas/canvas/evas_vg_gradient_linear.c | 16 +++++++++++
 src/lib/evas/canvas/evas_vg_gradient_radial.c | 17 +++++++++++
 src/lib/evas/canvas/evas_vg_node.c            | 12 +++++++-
 src/lib/evas/canvas/evas_vg_private.h         | 18 ++++++++++++
 src/lib/evas/canvas/evas_vg_shape.c           | 41 +++++++++++++++++++++++++++
 13 files changed, 155 insertions(+), 1 deletion(-)

diff --git a/src/lib/evas/canvas/efl_vg_base.eo 
b/src/lib/evas/canvas/efl_vg_base.eo
index 7ddfce5..15a8913 100644
--- a/src/lib/evas/canvas/efl_vg_base.eo
+++ b/src/lib/evas/canvas/efl_vg_base.eo
@@ -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;
diff --git a/src/lib/evas/canvas/efl_vg_container.eo 
b/src/lib/evas/canvas/efl_vg_container.eo
index b3a6ec4..21bb5e7 100644
--- a/src/lib/evas/canvas/efl_vg_container.eo
+++ b/src/lib/evas/canvas/efl_vg_container.eo
@@ -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;
    }
 }
diff --git a/src/lib/evas/canvas/efl_vg_gradient.eo 
b/src/lib/evas/canvas/efl_vg_gradient.eo
index 959da5b..7f794cb 100644
--- a/src/lib/evas/canvas/efl_vg_gradient.eo
+++ b/src/lib/evas/canvas/efl_vg_gradient.eo
@@ -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;
    }
 }
diff --git a/src/lib/evas/canvas/efl_vg_gradient_linear.eo 
b/src/lib/evas/canvas/efl_vg_gradient_linear.eo
index aecfe4e..381ddb6 100644
--- a/src/lib/evas/canvas/efl_vg_gradient_linear.eo
+++ b/src/lib/evas/canvas/efl_vg_gradient_linear.eo
@@ -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;
    }
diff --git a/src/lib/evas/canvas/efl_vg_gradient_radial.eo 
b/src/lib/evas/canvas/efl_vg_gradient_radial.eo
index bd99848..860c4f7 100644
--- a/src/lib/evas/canvas/efl_vg_gradient_radial.eo
+++ b/src/lib/evas/canvas/efl_vg_gradient_radial.eo
@@ -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;
    }
diff --git a/src/lib/evas/canvas/efl_vg_shape.eo 
b/src/lib/evas/canvas/efl_vg_shape.eo
index e2d5c27..053a374 100644
--- a/src/lib/evas/canvas/efl_vg_shape.eo
+++ b/src/lib/evas/canvas/efl_vg_shape.eo
@@ -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;
    }
diff --git a/src/lib/evas/canvas/evas_vg_container.c 
b/src/lib/evas/canvas/evas_vg_container.c
index 683f5ce..32ffbfa 100644
--- a/src/lib/evas/canvas/evas_vg_container.c
+++ b/src/lib/evas/canvas/evas_vg_container.c
@@ -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)
 {
diff --git a/src/lib/evas/canvas/evas_vg_gradient.c 
b/src/lib/evas/canvas/evas_vg_gradient.c
index 495a493..dff4738 100644
--- a/src/lib/evas/canvas/evas_vg_gradient.c
+++ b/src/lib/evas/canvas/evas_vg_gradient.c
@@ -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)
 {
diff --git a/src/lib/evas/canvas/evas_vg_gradient_linear.c 
b/src/lib/evas/canvas/evas_vg_gradient_linear.c
index 609dc7a..7234d4b 100644
--- a/src/lib/evas/canvas/evas_vg_gradient_linear.c
+++ b/src/lib/evas/canvas/evas_vg_gradient_linear.c
@@ -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)
 {
diff --git a/src/lib/evas/canvas/evas_vg_gradient_radial.c 
b/src/lib/evas/canvas/evas_vg_gradient_radial.c
index 52ed957..d6d62c5 100644
--- a/src/lib/evas/canvas/evas_vg_gradient_radial.c
+++ b/src/lib/evas/canvas/evas_vg_gradient_radial.c
@@ -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)
 {
diff --git a/src/lib/evas/canvas/evas_vg_node.c 
b/src/lib/evas/canvas/evas_vg_node.c
index 901e550..d160b45 100644
--- a/src/lib/evas/canvas/evas_vg_node.c
+++ b/src/lib/evas/canvas/evas_vg_node.c
@@ -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)) ;
diff --git a/src/lib/evas/canvas/evas_vg_private.h 
b/src/lib/evas/canvas/evas_vg_private.h
index 8ee62b6..102de5b 100644
--- a/src/lib/evas/canvas/evas_vg_private.h
+++ b/src/lib/evas/canvas/evas_vg_private.h
@@ -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;                                             \
diff --git a/src/lib/evas/canvas/evas_vg_shape.c 
b/src/lib/evas/canvas/evas_vg_shape.c
index d17268d..520c684 100644
--- a/src/lib/evas/canvas/evas_vg_shape.c
+++ b/src/lib/evas/canvas/evas_vg_shape.c
@@ -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)
 {

-- 


Reply via email to