PUI & default-backend: add force argument to the control function of animation
[platform/core/uifw/libpui.git] / src / PUI_ani.c
index f229a1a..9ef7c0f 100644 (file)
 static int KEY_WL_BUFFER = 0xabcdbeaf;
 static int KEY_CLIENT = 0xdcbabeaf;
 
-static Eina_Bool
-_cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
-{
-       pui_ani_h ani_h =  (pui_ani_h)data;
-       pui_ani_t *ani = ani_h->ani;
-       pui_h ph = ani_h->pui_handle;
-
-       Ecore_Wl2_Event_Window_Visibility_Change *ev;
-       PUI_Event_Animation_Status *e = NULL;
-
-       ev = event;
-
-       /* check if this is needed */
-       ph->visibility = !(ev->fully_obscured);
-
-       if (ev->fully_obscured)
-       {
-               if (ani->status == PUI_ANI_STATUS_RUNNING)
-               {
-                       pui_info("animation(%s) will be stopped as it lost its priority !\n", ani->id);
-
-                       pui_ani_control(ani_h, PUI_ANI_CMD_STOP, 0);
-               }
-       }
-       else
-       {
-               if (ani->status == PUI_ANI_STATUS_STOPPED || ani->status == PUI_ANI_STATUS_PAUSED)
-               {
-                       e = (PUI_Event_Animation_Status *)calloc(1, sizeof(PUI_Event_Animation_Status));
-
-                       if (!e)
-                       {
-                               pui_err("Failed to allocate memory for PUI Event !\n");
-                               return ECORE_CALLBACK_PASS_ON;
-                       }
-                       
-                       e->ani_h = ani_h;
-                       e->win = ev->win;
-                       e->status = ani->status;
-                       
-                       if (ani->status == PUI_ANI_STATUS_STOPPED)
-                       {
-                               pui_info("[Event added][ani id:%s] PUI_EVENT_ANI_READY_TO_START event has been added.\n", ani_h->id);
-                               ecore_event_add(PUI_EVENT_ANI_READY_TO_START, e, NULL, ani_h);
-                       }
-                       else if(ani->status == PUI_ANI_STATUS_PAUSED)
-                       {
-                               pui_info("[Event added][ani id:%s] PUI_EVENT_ANI_READY_TO_RESUME event has been added.\n", ani_h->id);
-                               ecore_event_add(PUI_EVENT_ANI_READY_TO_RESUME, e, NULL, ani_h);
-                       }
-               }
-       }
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-
 static void
 _pui_ani_cb_frame_done(Ecore_Wl2_Window *win, uint32_t timestamp EINA_UNUSED, void *data)
 {
@@ -285,44 +229,6 @@ pui_ani_update(pui_ani_h ani_h)
        return PUI_INT_ERROR_NONE;
 }
 
-static void
-_pui_ani_event_handlers_init(pui_ani_h ani_h)
-{
-       Ecore_Event_Handler *h = NULL;
-
-       if (!ani_h)
-       {
-               pui_err("Invalid handle !\n");
-               return;
-       }
-
-       if (!ani_h->ecore_event_hdls)
-               ani_h->ecore_event_hdls = eina_array_new(1);
-
-       h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, ani_h);
-       eina_array_push(ani_h->ecore_event_hdls, h);
-
-}
-
-static void
-_pui_ani_event_handlers_shutdown(pui_ani_h ani_h)
-{
-       if (!ani_h)
-       {
-               pui_err("Invalid handle !\n");
-               return;
-       }
-
-       if (ani_h->ecore_event_hdls)
-       {
-               while (eina_array_count(ani_h->ecore_event_hdls))
-                       ecore_event_handler_del(eina_array_pop(ani_h->ecore_event_hdls));
-
-               eina_array_free(ani_h->ecore_event_hdls);
-               ani_h->ecore_event_hdls = NULL;
-       }
-}
-
 static Eina_Bool
 _pui_ani_frame_cb(void *data)
 {
@@ -544,8 +450,8 @@ pui_ani_status_get(pui_ani_t *ani)
        return ani->status;
 }
 
-pui_error
-pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat)
+static pui_error
+_pui_ani_control_with_force(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat, pui_bool force)
 {
        pui_int_error ei = PUI_INT_ERROR_NONE;
        pui_ani_t *ani = NULL;
@@ -592,7 +498,7 @@ pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat)
                        {
                                pui_info("current_ani id=%s, status=%d\n", current_ani->id, current_ani->status);
 
-                               ei = pui_ani_control(handle->current_ani_h, PUI_ANI_CMD_STOP, 0);
+                               ei = _pui_ani_control_with_force(handle->current_ani_h, PUI_ANI_CMD_STOP, 0, force);
 
                                if (ei != PUI_INT_ERROR_NONE)
                                        pui_info("Failed to stop running previous animation ! (id:%s)\n", current_ani->id);
@@ -609,7 +515,7 @@ pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat)
                        pui_err("Error on starting animation ! (id:%s, repeat:%d, status=%d))\n", ani->id, repeat, ani->status);
 
                        if (ani->status != PUI_ANI_STATUS_RUNNING)
-                               pui_ani_control(ani_h, PUI_ANI_CMD_STOP, 0);
+                               _pui_ani_control_with_force(ani_h, PUI_ANI_CMD_STOP, 0, 0);
 
                        return PUI_ERROR_INTERNAL;
                }
@@ -618,7 +524,7 @@ pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat)
        }
        else//cmd == PUI_ANI_CMD_STOP
        {
-               ei = ani_func->ani_stop(ani);
+               ei = ani_func->ani_stop(ani, force);
 
                if (ei != PUI_INT_ERROR_NONE)
                {
@@ -650,6 +556,101 @@ err:
        return PUI_ERROR_INTERNAL;
 }
 
+pui_error
+pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat)
+{
+       return _pui_ani_control_with_force(ani_h, cmd, repeat, 0);
+}
+
+static Eina_Bool
+_cb_visibility_change(void *data, int type EINA_UNUSED, void *event)
+{
+       pui_ani_h ani_h =  (pui_ani_h)data;
+       pui_ani_t *ani = ani_h->ani;
+       pui_h ph = ani_h->pui_handle;
+
+       Ecore_Wl2_Event_Window_Visibility_Change *ev;
+       PUI_Event_Animation_Status *e = NULL;
+
+       ev = event;
+
+       /* check if this is needed */
+       ph->visibility = !(ev->fully_obscured);
+
+       if (ev->fully_obscured)
+       {
+               if (ani->status == PUI_ANI_STATUS_RUNNING)
+               {
+                       pui_info("animation(%s) will be stopped as it lost its priority !\n", ani->id);
+
+                       _pui_ani_control_with_force(ani_h, PUI_ANI_CMD_STOP, 0, 1);
+               }
+       }
+       else
+       {
+               if (ani->status == PUI_ANI_STATUS_PAUSED)
+               {
+                       e = (PUI_Event_Animation_Status *)calloc(1, sizeof(PUI_Event_Animation_Status));
+
+                       if (!e)
+                       {
+                               pui_err("Failed to allocate memory for PUI Event !\n");
+                               return ECORE_CALLBACK_PASS_ON;
+                       }
+
+                       e->ani_h = ani_h;
+                       e->win = ev->win;
+                       e->status = ani->status;
+
+                       if(ani->status == PUI_ANI_STATUS_PAUSED)
+                       {
+                               pui_info("[Event added][ani id:%s] PUI_EVENT_ANI_READY_TO_RESUME event has been added.\n", ani_h->id);
+                               ecore_event_add(PUI_EVENT_ANI_READY_TO_RESUME, e, NULL, ani_h);
+                       }
+               }
+       }
+
+       return ECORE_CALLBACK_PASS_ON;
+}
+
+static void
+_pui_ani_event_handlers_init(pui_ani_h ani_h)
+{
+       Ecore_Event_Handler *h = NULL;
+
+       if (!ani_h)
+       {
+               pui_err("Invalid handle !\n");
+               return;
+       }
+
+       if (!ani_h->ecore_event_hdls)
+               ani_h->ecore_event_hdls = eina_array_new(1);
+
+       h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, _cb_visibility_change, ani_h);
+       eina_array_push(ani_h->ecore_event_hdls, h);
+
+}
+
+static void
+_pui_ani_event_handlers_shutdown(pui_ani_h ani_h)
+{
+       if (!ani_h)
+       {
+               pui_err("Invalid handle !\n");
+               return;
+       }
+
+       if (ani_h->ecore_event_hdls)
+       {
+               while (eina_array_count(ani_h->ecore_event_hdls))
+                       ecore_event_handler_del(eina_array_pop(ani_h->ecore_event_hdls));
+
+               eina_array_free(ani_h->ecore_event_hdls);
+               ani_h->ecore_event_hdls = NULL;
+       }
+}
+
 pui_ani_h
 pui_ani_create(pui_h handle, pui_id id)
 {