From: raster Date: Tue, 8 Mar 2011 12:23:37 +0000 (+0000) Subject: i cannot believe evas has lasted this long without this. obj ref & X-Git-Tag: submit/trunk/20120815.174732~1843 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f3b98437dbbea35c437987d199b2f1caa1f5a94b;p=profile%2Fivi%2Fevas.git i cannot believe evas has lasted this long without this. obj ref & unref. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@57582 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/ChangeLog b/ChangeLog index 6c9cd16..437395c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -143,5 +143,6 @@ 2011-03-08 Carsten Haitzler (The Rasterman) * Fix problem with different x vsync api between SGI and EXT flavor - as they have the same base name, but different prototypes. - + as they have the same base name, but different prototypes + * Add evas_object_ref() and evas_object_unref() to defer + deletion of objects until all references are removed diff --git a/src/lib/Evas.h b/src/lib/Evas.h index c9f9f71..f3d19b6 100644 --- a/src/lib/Evas.h +++ b/src/lib/Evas.h @@ -898,6 +898,9 @@ typedef void (*Evas_Async_Events_Put_Cb)(void *target, Evas_Callback_Type t EAPI void evas_object_name_set (Evas_Object *obj, const char *name) EINA_ARG_NONNULL(1); EAPI const char *evas_object_name_get (const Evas_Object *obj) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE; + EAPI void evas_object_ref (Evas_Object *obj); + EAPI void evas_object_unref (Evas_Object *obj); + EAPI void evas_object_del (Evas_Object *obj) EINA_ARG_NONNULL(1); EAPI void evas_object_move (Evas_Object *obj, Evas_Coord x, Evas_Coord y) EINA_ARG_NONNULL(1); EAPI void evas_object_resize (Evas_Object *obj, Evas_Coord w, Evas_Coord h) EINA_ARG_NONNULL(1); diff --git a/src/lib/canvas/evas_object_main.c b/src/lib/canvas/evas_object_main.c index 57c36e0..4b949e6 100644 --- a/src/lib/canvas/evas_object_main.c +++ b/src/lib/canvas/evas_object_main.c @@ -356,6 +356,53 @@ evas_object_was_inside(Evas_Object *obj, Evas_Coord x, Evas_Coord y) /* routines apps will call */ /** + * Increments object reference count to defer deletion + * + * This increments the reference count of an object, which if greater than + * 0 will defer deletion by evas_object_del() until all references are + * released back to 0. References cannot go below 0 and unreferencing more + * times that referencing will result in the reference count being limited + * to 0. References are limited to 2^32 - 1 for an object. Referencing it more + * than this will result in it being limited to this value. + * + * @param obj The given evas object to reference + * @ingroup Evas_Object_Group_Basic + * @since 1.1.0 + */ +EAPI void +evas_object_ref(Evas_Object *obj) +{ + MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); + return; + MAGIC_CHECK_END(); + obj->ref++; + if (obj->ref == 0) obj->ref--; +} + +/** + * Decrements object reference count to defer deletion + * + * This decrements the reference count of an object. If the object has had + * evas_object_del() called on it while references were more than 0, it will + * be deleted at the time this function is called as it normally would have + * been. See evas_object_ref() for more information. + * + * @param obj The given evas object to unreference + * @ingroup Evas_Object_Group_Basic + * @since 1.1.0 + */ +EAPI void +evas_object_unref(Evas_Object *obj) +{ + MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); + return; + MAGIC_CHECK_END(); + if (obj->ref == 0) return; + obj->ref--; + if ((obj->del_ref) && (obj->ref == 0)) evas_object_del(obj); +} + +/** * Deletes the given evas object and frees its memory. * * The object's 'free' callback is called when this function is called. @@ -374,6 +421,11 @@ evas_object_del(Evas_Object *obj) if (obj->delete_me) return; + if (obj->ref > 0) + { + obj->del_ref = 1; + return; + } #ifdef EVAS_FRAME_QUEUING evas_common_frameq_flush(); #endif diff --git a/src/lib/include/evas_private.h b/src/lib/include/evas_private.h index 88487fd..a8dbf4b 100644 --- a/src/lib/include/evas_private.h +++ b/src/lib/include/evas_private.h @@ -459,6 +459,8 @@ struct _Evas_Object struct { int in_move, in_resize; } doing; + + unsigned int ref; unsigned char delete_me; @@ -487,6 +489,7 @@ struct _Evas_Object Eina_Bool changed_move : 1; Eina_Bool changed_move_only : 1; Eina_Bool changed_nomove : 1; + Eina_Bool del_ref : 1; }; struct _Evas_Func_Node