From: Joonbum Ko Date: Tue, 21 May 2024 10:05:50 +0000 (+0900) Subject: wayland-egl-tizen: add new API to set pre_commit callback. X-Git-Tag: accepted/tizen/unified/20240701.055759~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3d06027ce9fc682db85dce9a7de170aa1ca968e7;p=platform%2Fcore%2Fuifw%2Flibtpl-egl.git wayland-egl-tizen: add new API to set pre_commit callback. Set pre-commit callback with data to wl_egl_window. The registered callback function will be called with the data immedately before the frame's wl_surface_commit. The callback registered before calling eglSwapBuffers will be called at the time the swap requested buffer is attached. * Important * - Since the callback may be called from a separate thread that performs wl_surface_commit, protection is required if there is a critical section inside the callback function. - To avoid poor performance or complicated lifecycle issues, it is recommended that the behavior inside the callback function be concise. - This API should be called from one thread. - If it is called multiple times in a frame, the previously registered ones are overwritten. * Callback Options * - ONCE : The registered callback and data are stored in the buffer requested for swap when calling eglSwapBuffers and then initialized. The callback function is called only once when the buffer requested for swap is committed, and is not called after that. - CONTINUOUS : Once the callback and data are registered, the callback function is called continuously until it is released. To release the callback, simply pass NULL to func. Change-Id: Ic08c6dd1aeafe88d4059760f6bbffbd9d0da8c05 Signed-off-by: Joonbum Ko --- diff --git a/src/wayland-egl-tizen/wayland-egl-tizen-priv.h b/src/wayland-egl-tizen/wayland-egl-tizen-priv.h index 4b850f7..9420145 100644 --- a/src/wayland-egl-tizen/wayland-egl-tizen-priv.h +++ b/src/wayland-egl-tizen/wayland-egl-tizen-priv.h @@ -13,6 +13,12 @@ extern "C" { #define WL_EGL_TIZEN_MAGIC 0xDEF00123 #endif +struct pre_commit_cb { + pre_commit_cb_func_t func; + void *data; + callback_option option; +}; + struct tizen_private { unsigned int magic; int rotation; @@ -21,6 +27,8 @@ struct tizen_private { int window_transform; unsigned int serial; + struct pre_commit_cb pre_commit_cb; + void *data; void (*rotate_callback)(struct wl_egl_window *, void *); diff --git a/src/wayland-egl-tizen/wayland-egl-tizen.c b/src/wayland-egl-tizen/wayland-egl-tizen.c index 966ef7d..97e33c4 100644 --- a/src/wayland-egl-tizen/wayland-egl-tizen.c +++ b/src/wayland-egl-tizen/wayland-egl-tizen.c @@ -219,3 +219,28 @@ wl_egl_window_tizen_merge_sync_fds(struct wl_egl_window *egl_window, return -1; } + +void +wl_egl_window_tizen_set_pre_commit_callback(struct wl_egl_window *egl_window, + pre_commit_cb_func_t func, void *data, + callback_option option) +{ + struct tizen_private *private = wl_egl_tizen_get_tizen_private(egl_window); + + if (!private) return; + + struct pre_commit_cb *pre_commit_cb = &private->pre_commit_cb; + + if (pre_commit_cb->func && + (pre_commit_cb->func != func || pre_commit_cb->data != data)) { + WL_EGL_WARN("overwrite pre_commit_cb_func(%p)->(%p) | data(%p)->(%p)", + pre_commit_cb->func, func, + pre_commit_cb->data, data); + } + + pre_commit_cb->func = func; + pre_commit_cb->data = data; + pre_commit_cb->option = option; + WL_EGL_INFO("[SET_PRE_COMMIT_CB]", "wl_egl_window(%p) func(%p) data(%p)", + egl_window, pre_commit_cb->func, pre_commit_cb->data); +} diff --git a/src/wayland-egl-tizen/wayland-egl-tizen.h b/src/wayland-egl-tizen/wayland-egl-tizen.h index 2cb0d25..cdab123 100644 --- a/src/wayland-egl-tizen/wayland-egl-tizen.h +++ b/src/wayland-egl-tizen/wayland-egl-tizen.h @@ -47,6 +47,13 @@ typedef enum { WL_EGL_WINDOW_TIZEN_ROTATION_270 = 270 } wl_egl_window_tizen_rotation; +typedef void (*pre_commit_cb_func_t)(void *data); + +typedef enum { + ONCE, + CONTINUOUS, +} callback_option; + void wl_egl_window_tizen_set_rotation(struct wl_egl_window *egl_window, int rotation); @@ -166,6 +173,44 @@ int wl_egl_window_tizen_merge_sync_fds(struct wl_egl_window *egl_window, int sync_fd1, int sync_fd2); +/** + * Set pre-commit callback with data to wl_egl_window. + * + * The registered callback function will be called with the data + * immedately before the frame's wl_surface_commit. + * The callback registered before calling eglSwapBuffers will be called + * at the time the swap requested buffer is attached. + * + * Important * + * - Since the callback may be called from a separate thread that performs + * wl_surface_commit, protection is required if there is a critical section + * inside the callback function. + * - To avoid poor performance or complicated lifecycle issues, + * it is recommended that the behavior inside the callback function be concise. + * - This API should be called from one thread. + * - If it is called multiple times in a frame, the previously registered ones + * are overwritten. + * + * Callback Options * + * - ONCE : The registered callback and data are stored in the buffer requested + * for swap when calling eglSwapBuffers and then initialized. + * The callback function is called only once when the buffer requested + * for swap is committed, and is not called after that. + * - CONTINUOUS : Once the callback and data are registered, the callback function + * is called continuously until it is released. + * To release the callback, simply pass NULL to func. + * + * @param egl_window handle to wl_egl_window to which the callback is to be registered. + * @param option callback_option to determine the lifecycle of func. + * @param func callback function that will be called just before wl_surface_commit. + * @param data data to be passed to the callback function. +*/ +void +wl_egl_window_tizen_set_pre_commit_callback(struct wl_egl_window *egl_window, + pre_commit_cb_func_t func, + void *data, + callback_option option); + #ifdef __cplusplus } #endif