wayland-egl-tizen: add a new API to increase serial and obtain it sandbox/jbko/serial
authorJoonbum Ko <joonbum.ko@samsung.com>
Thu, 23 May 2024 04:57:21 +0000 (13:57 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Thu, 23 May 2024 06:27:35 +0000 (15:27 +0900)
 Increment the window serial and then returns it.

  The updated serial is copied to the buffer at the next eglSwapBuffers
 and delivered to the server when wl_surface_commit.

 * Important *
 - This API should be called only from the thread that calls eglSwapBuffers
 because it is not thread safe.
 - It is recommended not to use it with wl_egl_window_tizen_set_window_serial
 because set_window_seriaal can overwrite serial with a completely different value.
 - If caller want to obtain the current serial without increasing it,
 need to call get_window_serial

Change-Id: I780cccc175d2ef7d080805bc301ec92da1445e7c
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_wl_egl_thread.c
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 47ad811..a03c314 100755 (executable)
@@ -409,6 +409,7 @@ tizen_private_create()
                private->transform = 0;
                private->window_transform = 0;
                private->serial = 0;
+               private->serial_updated = false;
 
                private->data = NULL;
                private->rotate_callback = NULL;
@@ -1450,25 +1451,6 @@ __cb_get_rotation_capability(struct wl_egl_window *wl_egl_window,
        return rotation_capability;
 }
 
-static void
-__cb_set_window_serial_callback(struct wl_egl_window *wl_egl_window,
-                                                               void *private, unsigned int serial)
-{
-       TPL_ASSERT(private);
-
-       struct tizen_private tizen_private(private);
-       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
-
-       if (!wl_egl_surface) {
-               TPL_ERR("Invalid wl_egl_window(%p) tizen_private->data is null.",
-                               wl_egl_window);
-               return;
-       }
-
-       wl_egl_surface->serial = serial;
-       wl_egl_surface->serial_updated = TPL_TRUE;
-}
-
 static int
 __cb_create_commit_sync_fd(struct wl_egl_window *wl_egl_window, void *private)
 {
@@ -1905,7 +1887,6 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface)
        wl_egl_surface->need_to_enqueue        = TPL_TRUE;
        wl_egl_surface->prerotation_capability = TPL_FALSE;
        wl_egl_surface->vblank_done            = TPL_TRUE;
-       wl_egl_surface->serial_updated         = TPL_FALSE;
        wl_egl_surface->gsource_finalized      = TPL_FALSE;
        wl_egl_surface->initialized_in_thread  = TPL_FALSE;
        wl_egl_surface->frontbuffer_activated  = TPL_FALSE;
@@ -1913,7 +1894,6 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface)
        wl_egl_surface->reset_result           = TPL_ERROR_NONE;
 
        wl_egl_surface->latest_transform       = -1;
-       wl_egl_surface->serial                 = 0;
 
        wl_egl_surface->vblank                 = NULL;
 #if TIZEN_FEATURE_ENABLE
@@ -1948,8 +1928,6 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface)
                        tizen_private->rotate_callback = (void *)__cb_rotate_callback;
                        tizen_private->get_rotation_capability = (void *)
                                __cb_get_rotation_capability;
-                       tizen_private->set_window_serial_callback = (void *)
-                               __cb_set_window_serial_callback;
                        tizen_private->create_commit_sync_fd = (void *)__cb_create_commit_sync_fd;
                        tizen_private->set_frontbuffer_callback = (void *)__cb_client_window_set_frontbuffer_mode;
 #if TIZEN_FEATURE_ENABLE
@@ -3074,8 +3052,10 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
 
        tpl_wl_egl_surface_t wl_egl_surface(surface->backend.data);
        tpl_wl_egl_buffer_t *wl_egl_buffer      = NULL;
+       struct wl_egl_window *wl_egl_window     = wl_egl_surface->wl_egl_window;
        tbm_surface_queue_error_e tsq_err       = TBM_SURFACE_QUEUE_ERROR_NONE;
        int bo_name                             = -1;
+       struct tizen_private *tizen_private = wl_egl_tizen_get_tizen_private(wl_egl_window);
 
        if (!tbm_surface_internal_is_valid(tbm_surface)) {
                TPL_ERR("Failed to enqueue tbm_surface(%p) Invalid value.",
@@ -3148,10 +3128,10 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
 
        wl_egl_buffer->acquire_fence_fd = acquire_fence;
 
-       if (wl_egl_surface->serial_updated) {
-               wl_egl_buffer->serial = wl_egl_surface->serial;
+       if (tizen_private && tizen_private->serial_updated) {
+               wl_egl_buffer->serial = tizen_private->serial;
                wl_egl_buffer->serial_updated = TPL_TRUE;
-               wl_egl_surface->serial_updated = TPL_FALSE;
+               tizen_private->serial_updated = false;
        }
 
        if (wl_egl_surface->pre_commit_cb.func) {
index 219d05b..c358245 100644 (file)
@@ -5,7 +5,8 @@
 extern "C" {
 #endif
 
-#include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
 #include <wayland-client.h>
 #include <wayland-egl.h>
 
@@ -20,6 +21,7 @@ struct tizen_private {
        int transform;
        int window_transform;
        unsigned int serial;
+       bool serial_updated;
 
        void *data;
 
index f53b7f4..d5d131d 100644 (file)
@@ -3,7 +3,7 @@
 #include "wayland-egl-tizen.h"
 #include "wayland-egl-tizen-priv.h"
 
-#include <stdio.h>
+
 #include <stdlib.h>
 #include <unistd.h>
 #include <sys/syscall.h>
@@ -178,6 +178,9 @@ wl_egl_window_tizen_set_window_serial(struct wl_egl_window *egl_window,
        struct tizen_private *private = wl_egl_tizen_get_tizen_private(egl_window);
        if (!private) return;
 
+       private->serial = serial;
+       private->serial_updated = true;
+
        if (private->set_window_serial_callback)
                private->set_window_serial_callback(egl_window, egl_window->driver_private,
                                                                                        serial);
@@ -230,3 +233,16 @@ wl_egl_window_tizen_set_pre_commit_callback(struct wl_egl_window *egl_window,
        if (private && private->set_pre_commit_callback)
                private->set_pre_commit_callback(egl_window->driver_private, func, data, option);
 }
+
+unsigned int
+wl_egl_window_tizen_increment_window_serial(struct wl_egl_window *egl_window)
+{
+       struct tizen_private *private = wl_egl_tizen_get_tizen_private(egl_window);
+
+       if (private) {
+               private->serial_updated = true;
+               return ++private->serial;
+       }
+
+       return 0;
+}
index cdab123..1c5849f 100644 (file)
@@ -211,6 +211,27 @@ wl_egl_window_tizen_set_pre_commit_callback(struct wl_egl_window *egl_window,
                                                                                        void *data,
                                                                                        callback_option option);
 
+/**
+ * Increment the window serial and then returns it.
+ *
+ *  The updated serial is copied to the buffer at the next eglSwapBuffers
+ * and delivered to the server when wl_surface_commit.
+ *
+ * Important *
+ * - This API should be called only from the thread that calls eglSwapBuffers
+ * because it is not thread safe.
+ * - It is recommended not to use it with wl_egl_window_tizen_set_window_serial
+ * because set_window_seriaal can overwrite serial with a completely different value.
+ * - If caller want to obtain the current serial without increasing it,
+ * need to call get_window_serial
+ *
+ * @param egl_window handle to wl_egl_window to increase serial.
+ *
+ * @see wl_egl_window_tizen_get_window_serial
+*/
+unsigned int
+wl_egl_window_tizen_increment_window_serial(struct wl_egl_window *egl_window);
+
 #ifdef  __cplusplus
 }
 #endif