evas: make evas object an animator provider.
authorCedric BAIL <cedric@osg.samsung.com>
Fri, 29 Jan 2016 00:15:20 +0000 (16:15 -0800)
committerCedric BAIL <cedric@osg.samsung.com>
Tue, 2 Feb 2016 18:47:01 +0000 (10:47 -0800)
src/lib/evas/canvas/evas_object.eo
src/lib/evas/canvas/evas_object_main.c
src/lib/evas/include/evas_private.h

index 8baa965..5f9bb56 100644 (file)
@@ -1,6 +1,6 @@
 import evas_types;
 
-abstract Evas.Object (Eo.Base, Evas.Common_Interface, Efl.Gfx.Base, Efl.Gfx.Stack)
+abstract Evas.Object (Eo.Base, Evas.Common_Interface, Efl.Gfx.Base, Efl.Gfx.Stack, Efl.Core.Animator)
 {
    eo_prefix: evas_obj;
    data: Evas_Object_Protected_Data;
index 9f83689..3c986a7 100644 (file)
@@ -82,6 +82,83 @@ _init_cow(void)
    return EINA_TRUE;
 }
 
+static Eina_Bool
+_animator_repeater(void *data,
+                   Eo *eo_obj EINA_UNUSED,
+                   const Eo_Event_Description2 *desc EINA_UNUSED,
+                   void *event_info)
+{
+   Evas_Object_Protected_Data *obj = data;
+
+   eo_do(obj->object,
+         eo_event_callback_call(EFL_CORE_ANIMATOR_EVENT_ANIMATOR_TICK, event_info));
+   DBG("Emitting animator tick on %p.", obj->object);
+
+   return EO_CALLBACK_CONTINUE;
+}
+
+static Eina_Bool
+_check_event_catcher_add(void *data,
+                         Eo *eo_obj EINA_UNUSED,
+                         const Eo_Event_Description2 *desc EINA_UNUSED,
+                         void *event_info)
+{
+   const Eo_Callback_Array_Item *array = event_info;
+   Evas_Object_Protected_Data *obj = data;
+   int i;
+
+   for (i = 0; array[i].desc != NULL; i++)
+     {
+        if (array[i].desc == EFL_CORE_ANIMATOR_EVENT_ANIMATOR_TICK)
+          {
+             if (obj->animator_ref++ > 0) break;
+
+             eo_do(evas_object_evas_get(obj->object),
+                   eo_event_callback_add(EFL_CORE_ANIMATOR_EVENT_ANIMATOR_TICK, _animator_repeater, obj));
+             INF("Registering an animator tick on canvas %p for object %p.",
+                 evas_object_evas_get(obj->object), obj->object);
+
+             // No need to walk more than once per array as you can not del
+             // a partial array
+             break;
+          }
+     }
+
+   return EO_CALLBACK_CONTINUE;
+}
+
+static Eina_Bool
+_check_event_catcher_del(void *data,
+                         Eo *eo_obj EINA_UNUSED,
+                         const Eo_Event_Description2 *desc EINA_UNUSED,
+                         void *event_info)
+{
+   const Eo_Callback_Array_Item *array = event_info;
+   Evas_Object_Protected_Data *obj = data;
+   int i;
+
+   for (i = 0; array[i].desc != NULL; i++)
+     {
+        if (array[i].desc == EFL_CORE_ANIMATOR_EVENT_ANIMATOR_TICK)
+          {
+             if ((--obj->animator_ref) > 0) break;
+
+             eo_do(evas_object_evas_get(obj->object),
+                   eo_event_callback_del(EFL_CORE_ANIMATOR_EVENT_ANIMATOR_TICK, _animator_repeater, obj));
+             INF("Unregistering an animator tick on canvas %p for object %p.",
+                 evas_object_evas_get(obj->object), obj->object);
+
+             break;
+          }
+     }
+
+   return EO_CALLBACK_CONTINUE;
+}
+
+EO_CALLBACKS_ARRAY_DEFINE(event_catcher_watch,
+                          { EO_BASE_EVENT_CALLBACK_ADD, _check_event_catcher_add },
+                          { EO_BASE_EVENT_CALLBACK_DEL, _check_event_catcher_del });
+
 EOLIAN static Eo *
 _evas_object_eo_base_constructor(Eo *eo_obj, Evas_Object_Protected_Data *obj)
 {
@@ -110,6 +187,8 @@ _evas_object_eo_base_constructor(Eo *eo_obj, Evas_Object_Protected_Data *obj)
 
    evas_object_inject(eo_obj, obj, evas_object_evas_get(parent));
 
+   eo_do(eo_obj, eo_event_callback_array_add(event_catcher_watch(), obj));
+
    return eo_obj;
 }
 
index 664c144..28f890b 100644 (file)
@@ -1072,6 +1072,8 @@ struct _Evas_Object_Protected_Data
 
    unsigned int                ref;
 
+   unsigned int                animator_ref;
+
    unsigned char               delete_me;
 
    struct  {