wayland-egl-tizen: add new API to set pre_commit callback. 56/311456/2
authorJoonbum Ko <joonbum.ko@samsung.com>
Tue, 21 May 2024 10:05:50 +0000 (19:05 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Thu, 27 Jun 2024 06:36:30 +0000 (15:36 +0900)
 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 <joonbum.ko@samsung.com>
src/wayland-egl-tizen/wayland-egl-tizen-priv.h
src/wayland-egl-tizen/wayland-egl-tizen.c
src/wayland-egl-tizen/wayland-egl-tizen.h

index 4b850f7b4ecfa801924a2465d4b3712aad33ff5e..94201454d54d71f78b1d7447753c55081cf1fcda 100644 (file)
@@ -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 *);
index 966ef7d9a381990e8d79efedc61e9d1dfbd822db..97e33c403095223303e7876e3ebb9133ca7b47d3 100644 (file)
@@ -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);
+}
index 2cb0d25df773eea64e5f302d6bbdda1a05711f5a..cdab12352752ae7669aa05a48bedb6582e986d9e 100644 (file)
@@ -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