From 9e5445489e2f581a7ba658df81b46bca856102ca Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Tue, 27 Aug 2019 20:40:13 +0900 Subject: [PATCH] PUI: fix pui_ani_control, pui_ani_status_update and so on - pui_ani_control stop the animation being played before start playing a new animation - pui_ani_status_update when the status of a animation has been changed, create/send PUI_EVENT_ANI_XXX event to notify it to the application - events removal remove events regarding buffer release, frame done - handle visibility changes when the window is fully-obscured and an animation is being played, the animation must be stopped when the window is unobscured, we must notify application to have the opportunity to start again Change-Id: Icb2b54abaaf4d33a4b337ac477553608e5275aa1 Signed-off-by: Sung-Jin Park --- include/PUI.h | 7 +-- src/PUI.c | 11 +--- src/PUI_ani.c | 178 +++++++++++++++++++++++++++++++++++++++++++---------- src/PUI_common.h | 1 - src/PUI_internal.h | 1 + 5 files changed, 151 insertions(+), 47 deletions(-) diff --git a/include/PUI.h b/include/PUI.h index 8299ee7..159f65c 100644 --- a/include/PUI.h +++ b/include/PUI.h @@ -38,13 +38,12 @@ extern PUI_API int PUI_EVENT_ANI_STOPPED; extern PUI_API int PUI_EVENT_ANI_PAUSED; extern PUI_API int PUI_EVENT_ANI_READY_TO_START; extern PUI_API int PUI_EVENT_ANI_READY_TO_RESUME; -extern PUI_API int PUI_EVENT_ANI_FRAME_DONE; -extern PUI_API int PUI_EVENT_ANI_BUFFER_RELEASED; struct _PUI_Event_Animation_Status { - unsigned int win; - pui_ani_status status; + pui_ani_h ani_h; + unsigned int win; + pui_ani_status status; }; #ifdef __cplusplus diff --git a/src/PUI.c b/src/PUI.c index 37343c8..d6ebd31 100644 --- a/src/PUI.c +++ b/src/PUI.c @@ -44,8 +44,6 @@ int PUI_EVENT_ANI_STOPPED = 0; int PUI_EVENT_ANI_PAUSED = 0; int PUI_EVENT_ANI_READY_TO_START = 0; int PUI_EVENT_ANI_READY_TO_RESUME = 0; -int PUI_EVENT_ANI_FRAME_DONE = 0; -int PUI_EVENT_ANI_BUFFER_RELEASED = 0; pui_error_string pui_error_to_string(pui_error e) @@ -108,6 +106,7 @@ pui_create(Ecore_Wl2_Window *win) handle->visibility = 0; handle->wl_tbm_client = wl_tbm_client; handle->ani_handles = NULL; + handle->current_ani_h = NULL; handle->backend_module_data = pui_module->backend_module_data; handle->tbm_queue = wayland_tbm_client_create_surface_queue(handle->wl_tbm_client, @@ -291,8 +290,6 @@ _pui_event_init(void) PUI_EVENT_ANI_PAUSED = ecore_event_type_new(); PUI_EVENT_ANI_READY_TO_START = ecore_event_type_new(); PUI_EVENT_ANI_READY_TO_RESUME = ecore_event_type_new(); - PUI_EVENT_ANI_FRAME_DONE = ecore_event_type_new(); - PUI_EVENT_ANI_BUFFER_RELEASED = ecore_event_type_new(); } static void @@ -302,17 +299,13 @@ _pui_event_shutdown(void) PUI_EVENT_ANI_STOPPED, PUI_EVENT_ANI_PAUSED, PUI_EVENT_ANI_READY_TO_START, - PUI_EVENT_ANI_READY_TO_RESUME, - PUI_EVENT_ANI_FRAME_DONE, - PUI_EVENT_ANI_BUFFER_RELEASED); + PUI_EVENT_ANI_READY_TO_RESUME); PUI_EVENT_ANI_STARTED = -1; PUI_EVENT_ANI_STOPPED = -1; PUI_EVENT_ANI_PAUSED = -1; PUI_EVENT_ANI_READY_TO_START = -1; PUI_EVENT_ANI_READY_TO_RESUME = -1; - PUI_EVENT_ANI_FRAME_DONE = -1; - PUI_EVENT_ANI_BUFFER_RELEASED = -1; } int diff --git a/src/PUI_ani.c b/src/PUI_ani.c index 808adaa..9aa69f4 100644 --- a/src/PUI_ani.c +++ b/src/PUI_ani.c @@ -88,17 +88,24 @@ _cb_visibility_change(void *data, int type EINA_UNUSED, void *event) ev = event; - pui_info("Visibility change (window=0x%x, fully_obscured=%d)\n", ev->win, ev->fully_obscured); + 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) { - ani->status = PUI_ANI_STATUS_STOPPED; - + 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) @@ -107,29 +114,19 @@ _cb_visibility_change(void *data, int type EINA_UNUSED, void *event) return ECORE_CALLBACK_PASS_ON; } + e->ani_h = ani_h; e->win = ev->win; - e->status = PUI_ANI_STATUS_FORCE_STOPPED; + e->status = ani->status; - ecore_event_add(PUI_EVENT_ANI_STOPPED, e, NULL, ani_h); - } - } - else - { - 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; + 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); + } } - - 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; @@ -409,7 +406,16 @@ _pui_ani_frame_cb(void *data) ret = (Eina_Bool)ani->backend_frame_cb(ani, ++ani->serial); - pui_ani_status_update(ani, PUI_ANI_STATUS_RUNNING); + 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); + + if (ret && PUI_ANI_STATUS_STARTED == ani->status) + pui_ani_status_update(ani, PUI_ANI_STATUS_RUNNING); return ret; } @@ -425,6 +431,15 @@ 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); + return 0; + } + ani->frame_cb = _pui_ani_frame_cb; ani->backend_frame_cb = frame_cb; ani->frame_interval = frame_interval; @@ -453,6 +468,9 @@ pui_ani_remove_frame_cb(pui_ani_t *ani) if (!ani) return; + pui_info("ani->id=%s\n", ani->id); + + if (ani->frame_cb_timer) { ecore_timer_del(ani->frame_cb_timer); @@ -504,9 +522,62 @@ pui_ani_get_ani_data(pui_ani_t *ani) void pui_ani_status_update(pui_ani_t *ani, pui_ani_status status) { - //TODO : add PUI EVENT + int ev_type = -1; + pui_ani_h ani_h; + PUI_Event_Animation_Status *e = NULL; + + if (!ani) + { + pui_err("Invalid pui ani !\n"); + return; + } + + if (ani->status == status) + return; + + ani_h = ani->ani_h; + + 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; + } ani->status = status; + e->ani_h = ani_h; + 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; + break; + + case PUI_ANI_STATUS_RUNNING: + break; + + case PUI_ANI_STATUS_PAUSED: + ev_type = PUI_EVENT_ANI_PAUSED; + break; + + case PUI_ANI_STATUS_STOPPED: + ev_type = PUI_EVENT_ANI_STOPPED; + break; + + default: + pui_err("Unknown status !(ani status=%d, id=%s) !\n", status, ani->id); + return; + } + + if (ev_type > 0) + { + ecore_event_add(ev_type, e, NULL, ani_h); + } } pui_ani_status @@ -526,6 +597,7 @@ pui_ani_status_get(pui_ani_t *ani) pui_error pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat) { + pui_int_error ei = PUI_INT_ERROR_NONE; pui_ani_t *ani = NULL; pui_h handle = NULL; pui_backend_ani_func *ani_func = NULL; @@ -535,7 +607,7 @@ pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat) if (cmd < PUI_ANI_CMD_START || cmd >= PUI_ANI_CMD_LAST) { - pui_err("Invalid cmd ! (repeat=%d)\n", repeat); + pui_err("Invalid cmd ! (cmd=%d)\n", cmd); return PUI_ERROR_INVALID_ANI_CMD; } @@ -545,9 +617,6 @@ pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat) return PUI_ERROR_INVALID_ANI_REPEAT; } - //TODO : check if there is any animation being played already - //NOTE : the id of the animation being played can be different from ani_h->id - handle = ani_h->pui_handle; ani = ani_h->ani; @@ -564,11 +633,56 @@ pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat) if (cmd == PUI_ANI_CMD_START) { - ani_func->ani_start(ani, repeat); + if (handle->current_ani_h && handle->current_ani_h != ani_h) + { + pui_ani_t *current_ani = handle->current_ani_h->ani; + + if (current_ani->status >= PUI_ANI_STATUS_STARTED && + current_ani->status <= PUI_ANI_STATUS_RUNNING) + { + 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); + + if (ei != PUI_INT_ERROR_NONE) + pui_info("Failed to stop running previous animation ! (id:%s)\n", current_ani->id); + + current_ani = NULL; + handle->current_ani_h = NULL; + } + } + + ei = ani_func->ani_start(ani, repeat); + + if (ei != PUI_INT_ERROR_NONE) + { + 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); + + return PUI_ERROR_INTERNAL; + } + + handle->current_ani_h = ani_h; } else//cmd == PUI_ANI_CMD_STOP { - ani_func->ani_stop(ani); + ei = ani_func->ani_stop(ani); + + if (ei != PUI_INT_ERROR_NONE) + { + pui_err("Failied on stopping animation ! (id:%s)\n", ani->id); + + if (ani->status != PUI_ANI_STATUS_STOPPED) + pui_ani_status_update(ani, PUI_ANI_STATUS_STOPPED); + + if (ani->frame_cb_timer) + pui_ani_remove_frame_cb(ani); + + return PUI_ERROR_INTERNAL; + } + return PUI_ERROR_NONE; } @@ -580,8 +694,6 @@ pui_ani_control(pui_ani_h ani_h, pui_ani_cmd cmd, int repeat) goto err; } - //TODO - return PUI_ERROR_NONE; err: diff --git a/src/PUI_common.h b/src/PUI_common.h index af997c6..eb587be 100644 --- a/src/PUI_common.h +++ b/src/PUI_common.h @@ -41,7 +41,6 @@ typedef enum { PUI_ANI_STATUS_RUNNING, PUI_ANI_STATUS_PAUSED, PUI_ANI_STATUS_STOPPED, - PUI_ANI_STATUS_FORCE_STOPPED, } pui_ani_status; typedef enum { diff --git a/src/PUI_internal.h b/src/PUI_internal.h index 7c57a18..2f4b7aa 100644 --- a/src/PUI_internal.h +++ b/src/PUI_internal.h @@ -80,6 +80,7 @@ struct _pui struct wayland_tbm_client *wl_tbm_client; tbm_surface_queue_h tbm_queue; + pui_ani_h current_ani_h; tbm_surface_info_s current_sinfo; tbm_surface_h current_surface; int is_buffer_set; -- 2.7.4