From: Hwankyu Jhun Date: Thu, 18 Jun 2020 04:28:12 +0000 (+0900) Subject: [Frame-Broker] Fix calling pause callback function X-Git-Tag: submit/tizen/20200619.035856~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F46%2F236546%2F1;p=platform%2Fcore%2Fappfw%2Fwidget-viewer.git [Frame-Broker] Fix calling pause callback function The frame broker calls the frame_context_pause_cb callback function, when the direction of the frame is "FRAME_DIRECTION_FORWARD" and the window is invisible state. Change-Id: If2fe792fc5ec277eab4b1a5400a0b33f204ec17d Signed-off-by: Hwankyu Jhun --- diff --git a/frame-broker/src/frame_broker.c b/frame-broker/src/frame_broker.c index ce3156b..36d4a06 100644 --- a/frame-broker/src/frame_broker.c +++ b/frame-broker/src/frame_broker.c @@ -32,6 +32,7 @@ #include "frame_private.h" #include "log_private.h" #include "private.h" +#include "window_context.h" struct frame_broker_s { char *name; @@ -41,6 +42,7 @@ struct frame_broker_s { aul_launcher_service_h als; screen_connector_launcher_service_h scls; frame_context_h context; + window_context_h window_context; }; struct request_s { @@ -241,6 +243,32 @@ static void __scls_reset_cb(uint32_t serial, void *user_data) frame_context_set_frame(context, NULL); } +static void __window_context_resume_cb(void *user_data) +{ + frame_broker_h broker = user_data; + frame_context_h context = broker->context; + + _W("[__RESUME__] context(%p)", context); +} + +static void __window_context_pause_cb(void *user_data) +{ + frame_broker_h broker = user_data; + frame_context_h context = broker->context; + frame_h frame = NULL; + frame_direction_e direction; + + _W("[__PAUSE__] context(%p)", context); + + if (!context) + return; + + frame_context_get_frame(context, &frame); + frame_get_direction(frame, &direction); + if (direction == FRAME_DIRECTION_FORWARD) + frame_context_on_pause(context); +} + API int frame_broker_create(void *wl2_win, frame_context_lifecycle_callback_s *callback, void *user_data, @@ -254,7 +282,12 @@ API int frame_broker_create(void *wl2_win, .cleanup = __scls_cleanup_cb, .reset = __scls_reset_cb }; + window_context_event_callback_s we_callback = { + .resume = __window_context_resume_cb, + .pause = __window_context_pause_cb + }; struct frame_broker_s *broker; + unsigned int win; int ret; if (!wl2_win || !callback || !handle) { @@ -313,6 +346,15 @@ API int frame_broker_create(void *wl2_win, screen_connector_launcher_service_set_ops(scls, &ops, broker); + win = ecore_wl2_window_id_get((Ecore_Wl2_Window *)wl2_win); + ret = window_context_create(win, &we_callback, broker, + &broker->window_context); + if (ret != 0) { + _E("Failed to create window context. error(%d)", ret); + frame_broker_destroy(broker); + return ret; + } + broker->scls = scls; broker->wl2_win = wl2_win; broker->callback = *callback; @@ -337,6 +379,7 @@ API int frame_broker_destroy(frame_broker_h handle) if (handle->context) frame_context_destroy(handle->context); + window_context_destroy(handle->window_context); screen_connector_launcher_service_destroy(handle->scls); aul_launcher_service_destroy(handle->als); free(handle->name); diff --git a/frame-broker/src/frame_context.c b/frame-broker/src/frame_context.c index 44de447..eb44901 100644 --- a/frame-broker/src/frame_context.c +++ b/frame-broker/src/frame_context.c @@ -165,8 +165,6 @@ static gboolean __context_pause_cb(gpointer data) frame_direction_e direction; context->idle_tag = 0; - frame_context_on_pause(context); - _W("frame(%p)", context->frame); frame_get_direction(context->frame, &direction); if (direction == FRAME_DIRECTION_BACKWARD) { diff --git a/frame-broker/src/window_context.c b/frame-broker/src/window_context.c new file mode 100644 index 0000000..57ec616 --- /dev/null +++ b/frame-broker/src/window_context.c @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include +#include + +#include "frame_types.h" +#include "log_private.h" +#include "window_context.h" + +struct window_context_s { + unsigned int win; + bool fully_obscured; + Ecore_Event_Handler *hide; + Ecore_Event_Handler *visibility_change; + Ecore_Event_Handler *pre_visibility_change; + window_context_event_callback_s callback; + void *user_data; +}; + +static Eina_Bool __window_hide_cb(void *data, int type, void *event) +{ + Ecore_Wl2_Event_Window_Hide *ev = event; + window_context_h context = data; + + _D("[__HIDE__] win(%u)", ev->win); + if (context->win == ev->win) { + if (!context->fully_obscured) { + context->callback.pause(context->user_data); + context->fully_obscured = true; + } + } + + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __window_visibility_change_cb(void *data, int type, + void *event) +{ + Ecore_Wl2_Event_Window_Visibility_Change *ev = event; + window_context_h context = data; + + _D("[__VISIBILITY_CHANGE__] win(%u), fully_obscured(%d)", + ev->win, ev->fully_obscured); + if (context->win == ev->win) { + if (ev->fully_obscured && !context->fully_obscured) { + context->callback.pause(context->user_data); + context->fully_obscured = true; + } else if (!ev->fully_obscured && context->fully_obscured) { + context->callback.resume(context->user_data); + context->fully_obscured = false; + } + } + + return ECORE_CALLBACK_RENEW; +} + +static Eina_Bool __window_pre_visibility_change_cb(void *data, int type, + void *event) +{ + Ecore_Wl2_Event_Window_Pre_Visibility_Change *ev = event; + window_context_h context = data; + + _D("[__PRE_VISIBILITY_CHANGE__] win(%u)", ev->win); + if (ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED) { + if (context->win == ev->win && context->fully_obscured) { + context->callback.resume(context->user_data); + context->fully_obscured = false; + } + } + + return ECORE_CALLBACK_RENEW; +} + +int window_context_create(unsigned int win, + window_context_event_callback_s *callback, + void *user_data, + window_context_h *handle) +{ + struct window_context_s *context; + + if (!win || !callback || !callback->resume || !callback->pause || + !handle) { + _E("Invalid parameter"); + return FRAME_BROKER_ERROR_INVALID_PARAMETER; + } + + context = calloc(1, sizeof(struct window_context_s)); + if (!context) { + _E("Out of memory"); + return FRAME_BROKER_ERROR_OUT_OF_MEMORY; + } + + context->hide = ecore_event_handler_add( + ECORE_WL2_EVENT_WINDOW_HIDE, + __window_hide_cb, context); + + context->visibility_change = ecore_event_handler_add( + ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE, + __window_visibility_change_cb, context); + + context->pre_visibility_change = ecore_event_handler_add( + ECORE_WL2_EVENT_WINDOW_PRE_VISIBILITY_CHANGE, + __window_pre_visibility_change_cb, context); + + context->win = win; + context->callback = *callback; + context->user_data = user_data; + + *handle = context; + + return FRAME_BROKER_ERROR_NONE; +} + +int window_context_destroy(window_context_h handle) +{ + if (!handle) { + _E("Invalid parameter"); + return FRAME_BROKER_ERROR_INVALID_PARAMETER; + } + + if (handle->pre_visibility_change) + ecore_event_handler_del(handle->pre_visibility_change); + if (handle->visibility_change) + ecore_event_handler_del(handle->visibility_change); + if (handle->hide) + ecore_event_handler_del(handle->hide); + + free(handle); + + return FRAME_BROKER_ERROR_NONE; +} diff --git a/frame-broker/src/window_context.h b/frame-broker/src/window_context.h new file mode 100644 index 0000000..7323d1a --- /dev/null +++ b/frame-broker/src/window_context.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __WINDOW_CONTEXT_H__ +#define __WINDOW_CONTEXT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct window_context_s *window_context_h; + +typedef void (*window_context_resume_cb)(void *user_data); + +typedef void (*window_context_pause_cb)(void *user_data); + +typedef struct { + window_context_resume_cb resume; + window_context_pause_cb pause; +} window_context_event_callback_s; + +int window_context_create(unsigned int win, + window_context_event_callback_s *callback, + void *user_data, + window_context_h *handle); + +int window_context_destroy(window_context_h handle); + +#ifdef __cplusplus +} +#endif + +#endif /* __WINDOW_CONTEXT_H__ */