PUI & default-backend: add force argument to the control function of animation
[platform/core/uifw/libpui.git] / src / PUI_ani.c
index 9aa69f4..9ef7c0f 100644 (file)
 static int KEY_WL_BUFFER = 0xabcdbeaf;
 static int KEY_CLIENT = 0xdcbabeaf;
 
-static Eina_Bool
-_cb_window_show(void *data, int type EINA_UNUSED, void *event)
-{
-       pui_ani_h handle =  (pui_ani_h)data;
-       Ecore_Wl2_Event_Window_Show *ev = (Ecore_Wl2_Event_Window_Show *)event;
-
-       pui_info("...\n");
-
-       /* TODO */
-       (void) handle;
-       (void) ev;
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool
-_cb_focus_in(void *data, int type EINA_UNUSED, void *event)
-{
-       pui_ani_h handle =  (pui_ani_h)data;
-       Ecore_Wl2_Event_Focus_In *ev = (Ecore_Wl2_Event_Focus_In *)event;
-
-       pui_info("...\n");
-
-       /* TODO */
-       (void) handle;
-       (void) ev;
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-
-static Eina_Bool
-_cb_focus_out(void *data, int type EINA_UNUSED, void *event)
-{
-       pui_ani_h handle =  (pui_ani_h)data;
-       Ecore_Wl2_Event_Focus_Out *ev = (Ecore_Wl2_Event_Focus_Out *)event;
-
-       pui_info("...\n");
-
-       /* TODO */
-       (void) handle;
-       (void) ev;
-
-       return ECORE_CALLBACK_PASS_ON;
-}
-
-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;
-
-       pui_info("[pui_ani] Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured);
-
-       /* check if this is needed */
-       ph->visibility = !(ev->fully_obscured);
-
-       if (ev->fully_obscured)
-       {
-               pui_info("ani->id=%s, ani->status=%d\n", ani->id, ani->status);
-
-               if (ani->status == PUI_ANI_STATUS_RUNNING)
-               {
-                       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)
-                       {
-                               ecore_event_add(PUI_EVENT_ANI_READY_TO_START, e, NULL, ani_h);
-                       }
-                       else if(ani->status == PUI_ANI_STATUS_PAUSED)
-                       {
-                               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)
 {
        pui_h handle = (pui_h) data;
 
-       pui_info("Frame done ! (window=%p)\n", win);
+       pui_info("Frame done ! (window=0x%x)\n", ecore_wl2_window_id_get(win));
 
-       // TODO
+       /* TODO : make use of handle */
        (void) handle;
 
        return;
@@ -330,53 +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(5);
-
-       h = ecore_event_handler_add(ECORE_WL2_EVENT_WINDOW_SHOW, _cb_window_show, ani_h);
-       eina_array_push(ani_h->ecore_event_hdls, h);
-
-       h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_IN, _cb_focus_in, ani_h);
-       eina_array_push(ani_h->ecore_event_hdls, h);
-
-       h = ecore_event_handler_add(ECORE_WL2_EVENT_FOCUS_OUT, _cb_focus_out, ani_h);
-       eina_array_push(ani_h->ecore_event_hdls, h);
-
-       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)
 {
@@ -402,22 +254,23 @@ _pui_ani_frame_cb(void *data)
                return ECORE_CALLBACK_CANCEL;
        }
 
-       pui_info("frame_cb !\n");
+       pui_info("...\n");
 
        ret = (Eina_Bool)ani->backend_frame_cb(ani, ++ani->serial);
 
        if (!ret)
        {
                pui_err("Failed on backend's frame_cb !Frame_cb will be removed forcefuly !\n");
+
                pui_ani_remove_frame_cb(ani);
-       }
 
-       pui_info("ret from ani->backend_frame_cb = %d, ani->status=%d\n", ret, ani->status);
+               return EINA_FALSE;
+       }
 
        if (ret && PUI_ANI_STATUS_STARTED == ani->status)
                pui_ani_status_update(ani, PUI_ANI_STATUS_RUNNING);
 
-       return ret;
+       return EINA_TRUE;
 }
 
 pui_bool
@@ -431,9 +284,6 @@ pui_ani_add_frame_cb(pui_ani_t *ani, pui_bool (*frame_cb)(void *data, int serial
                return 0;
        }
 
-       pui_info("ani->id=%s, frame_interval=%.2f\n", ani->id, frame_interval);
-
-
        if (frame_interval <= 0.0f)
        {
                pui_err("Invalid frame interval (%.2f) ! frame interval must be larger than 0.\n", frame_interval);
@@ -456,6 +306,8 @@ pui_ani_add_frame_cb(pui_ani_t *ani, pui_bool (*frame_cb)(void *data, int serial
 
        ani->frame_cb_timer = timer;
 
+       pui_info("[Frame callback added][ani id=%s] frame_interval=%.2f\n", ani->id, frame_interval);
+
        /* call frame_cb for starting the first frame */
        _pui_ani_frame_cb(ani);
 
@@ -466,10 +318,10 @@ void
 pui_ani_remove_frame_cb(pui_ani_t *ani)
 {
        if (!ani)
+       {
+               pui_err("Invalid put ani !\n");
                return;
-
-       pui_info("ani->id=%s\n", ani->id);
-
+       }
 
        if (ani->frame_cb_timer)
        {
@@ -481,6 +333,8 @@ pui_ani_remove_frame_cb(pui_ani_t *ani)
        ani->backend_frame_cb = NULL;
        ani->frame_interval = 0;
        ani->frame_cb_data = NULL;
+
+       pui_info("[Frame callback removed][ani id=%s]\n", ani->id);
 }
 
 pui_id
@@ -550,23 +404,25 @@ pui_ani_status_update(pui_ani_t *ani, pui_ani_status status)
        e->win = ecore_wl2_window_id_get(ani_h->pui_handle->win);
        e->status = status;
 
-       pui_info("ani->id=%s, status=%d\n", ani->id, status);
-
        switch (status)
        {
                case PUI_ANI_STATUS_STARTED:
                        ev_type = PUI_EVENT_ANI_STARTED;
+                       pui_info("[Status update][ani id:%s] PUI_EVENT_ANI_STARTED event has been added.\n", ani->id);
                        break;
 
                case PUI_ANI_STATUS_RUNNING:
+                       pui_info("[Status update][ani id:%s] PUI_ANI_STATUS_RUNNING !\n", ani->id);
                        break;
 
                case PUI_ANI_STATUS_PAUSED:
                        ev_type = PUI_EVENT_ANI_PAUSED;
+                       pui_info("[Status update][ani id:%s] PUI_EVENT_ANI_PAUSED event has been added.\n", ani->id);
                        break;
 
                case PUI_ANI_STATUS_STOPPED:
                        ev_type = PUI_EVENT_ANI_STOPPED;
+                       pui_info("[Status update][ani id:%s] PUI_EVENT_ANI_STOPPED event has been added.\n", ani->id);
                        break;
 
                default:
@@ -594,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;
@@ -642,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);
@@ -659,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;
                }
@@ -668,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)
                {
@@ -700,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)
 {
@@ -782,7 +733,7 @@ pui_ani_destroy(pui_ani_h ani_h)
        ani = ani_h->ani;
 
        /* stop the animation being played already if any */
-       if (ani->status != PUI_ANI_STATUS_STOPPED)
+       if (ani->status == PUI_ANI_STATUS_STARTED || ani->status == PUI_ANI_STATUS_RUNNING)
                pui_ani_control(ani_h, PUI_ANI_CMD_STOP, 0);
 
        backend_module_data = handle->backend_module_data;