cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=0812fc8f6c3ff4a815a4ef19875aabf064b68367

commit 0812fc8f6c3ff4a815a4ef19875aabf064b68367
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Mon Jan 25 15:44:54 2016 -0800

    ecore_evas: optimize triggering of animator to happen only when someone is 
listening.
---
 src/lib/ecore_evas/ecore_evas.c         | 88 ++++++++++++++++++++++++++++-----
 src/lib/ecore_evas/ecore_evas_private.h |  1 +
 2 files changed, 78 insertions(+), 11 deletions(-)

diff --git a/src/lib/ecore_evas/ecore_evas.c b/src/lib/ecore_evas/ecore_evas.c
index fa0c8eb..d61f75f 100644
--- a/src/lib/ecore_evas/ecore_evas.c
+++ b/src/lib/ecore_evas/ecore_evas.c
@@ -3104,6 +3104,82 @@ _ecore_evas_animator_fallback(void *data)
    return EINA_TRUE;
 }
 
+static Eina_Bool
+_check_animator_event_catcher_add(void *data,
+                                  Eo *obj EINA_UNUSED,
+                                  const Eo_Event_Description2 *desc 
EINA_UNUSED,
+                                  void *event_info)
+{
+   const Eo_Callback_Array_Item *array = event_info;
+   Ecore_Evas *ee = data;
+   int i;
+
+   for (i = 0; array[i].desc != NULL; i++)
+     {
+        if (array[i].desc == EFL_CORE_ANIMATOR_EVENT_ANIMATOR_TICK)
+          {
+             if (ee->anim_count++ > 0) return EO_CALLBACK_CONTINUE;
+
+             if (ee->engine.func->fn_animator_register &&
+                 ee->engine.func->fn_animator_unregister)
+               {
+                  // Backend support per window vsync
+                  ee->engine.func->fn_animator_register(ee);
+               }
+             else
+               {
+                  // Backend doesn't support per window vsync, fallback to 
generic support
+                  ee->anim = ecore_animator_add(_ecore_evas_animator_fallback, 
ee);
+               }
+
+             // No need to walk more than once per array as you can not del
+             // a partial array
+             return EO_CALLBACK_CONTINUE;
+          }
+     }
+
+   return EO_CALLBACK_CONTINUE;
+}
+
+static Eina_Bool
+_check_animator_event_catcher_del(void *data,
+                                  Eo *obj EINA_UNUSED,
+                                  const Eo_Event_Description2 *desc 
EINA_UNUSED,
+                                  void *event_info)
+{
+   const Eo_Callback_Array_Item *array = event_info;
+   Ecore_Evas *ee = data;
+   int i;
+
+   for (i = 0; array[i].desc != NULL; i++)
+     {
+        if (array[i].desc == EFL_CORE_ANIMATOR_EVENT_ANIMATOR_TICK)
+          {
+             if ((--ee->anim_count) > 0) return EO_CALLBACK_CONTINUE;
+
+             if (ee->engine.func->fn_animator_register &&
+                 ee->engine.func->fn_animator_unregister)
+               {
+                  // Backend support per window vsync
+                  ee->engine.func->fn_animator_unregister(ee);
+               }
+             else
+               {
+                  // Backend doesn't support per window vsync, fallback to 
generic support
+                  ecore_animator_del(ee->anim);
+                  ee->anim = NULL;
+               }
+             return EO_CALLBACK_CONTINUE;
+          }
+     }
+
+   return EO_CALLBACK_CONTINUE;
+}
+
+EO_CALLBACKS_ARRAY_DEFINE(animator_watch,
+                          { EO_BASE_EVENT_CALLBACK_ADD, 
_check_animator_event_catcher_add },
+                          { EO_BASE_EVENT_CALLBACK_DEL, 
_check_animator_event_catcher_del });
+
 EAPI void
 _ecore_evas_register(Ecore_Evas *ee)
 {
@@ -3111,17 +3187,7 @@ _ecore_evas_register(Ecore_Evas *ee)
    ecore_evases = (Ecore_Evas *)eina_inlist_prepend
      (EINA_INLIST_GET(ecore_evases), EINA_INLIST_GET(ee));
 
-   if (ee->engine.func->fn_animator_register &&
-       ee->engine.func->fn_animator_unregister)
-     {
-        // Backend support per window vsync
-        ee->engine.func->fn_animator_register(ee);
-     }
-   else
-     {
-        // Backend doesn't support per window vsync, fallback to generic 
support
-        ee->anim = ecore_animator_add(_ecore_evas_animator_fallback, ee);
-     }
+   eo_do(ee->evas, eo_event_callback_array_add(animator_watch(), ee));
 
 #ifdef RENDER_SYNC
    ecore_evas_first = EINA_TRUE;
diff --git a/src/lib/ecore_evas/ecore_evas_private.h 
b/src/lib/ecore_evas/ecore_evas_private.h
index 62e5545..a179733 100644
--- a/src/lib/ecore_evas/ecore_evas_private.h
+++ b/src/lib/ecore_evas/ecore_evas_private.h
@@ -299,6 +299,7 @@ struct _Ecore_Evas
 
    // Animator code
    Ecore_Animator *anim;
+   unsigned int anim_count;
 
    struct {
       unsigned char avoid_damage;

-- 


Reply via email to