ecore_evas: optimize triggering of animator to happen only when someone is listening.

This commit is contained in:
Cedric BAIL 2016-01-25 15:44:54 -08:00
parent bb1a1eef65
commit 0812fc8f6c
2 changed files with 78 additions and 11 deletions

View File

@ -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;

View File

@ -299,6 +299,7 @@ struct _Ecore_Evas
// Animator code
Ecore_Animator *anim;
unsigned int anim_count;
struct {
unsigned char avoid_damage;