wl_egl: implement set_pre_commit_callback 57/311457/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Tue, 21 May 2024 10:10:31 +0000 (19:10 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Tue, 21 May 2024 10:10:31 +0000 (19:10 +0900)
Change-Id: I223fd84d00c9e951d04d4149d3851c6c57c38610
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_wl_egl_thread.c

index e9604c1..bbe530f 100755 (executable)
@@ -141,6 +141,12 @@ struct _tpl_wl_egl_surface {
                int                       fd;
        } presentation_sync;
 
+       struct {
+               pre_commit_cb_func_t func;
+               void *data;
+               callback_option option;
+       } pre_commit_cb;
+
        tpl_gmutex                    surf_mutex;
        tpl_gcond                     surf_cond;
 
@@ -250,6 +256,11 @@ struct _tpl_wl_egl_buffer {
         * presentation feedback from display server */
        int32_t                       presentation_sync_fd;
 
+       struct {
+               pre_commit_cb_func_t func;
+               void *data;
+       } pre_commit_cb;
+
        tpl_gsource                  *waiting_source;
 
        tpl_gmutex                    mutex;
@@ -407,6 +418,7 @@ tizen_private_create()
                private->create_commit_sync_fd = NULL;
                private->create_presentation_sync_fd = NULL;
                private->merge_sync_fds = NULL;
+               private->set_pre_commit_callback = NULL;
        }
 
        return private;
@@ -1582,6 +1594,23 @@ __cb_create_presentation_sync_fd(struct wl_egl_window *wl_egl_window, void *priv
 
        return presentation_sync_fd;
 }
+
+static void
+__set_pre_commit_callback(void *private,
+                                                 pre_commit_cb_func_t func, void *data, callback_option option)
+{
+       struct tizen_private tizen_private(private);
+       tpl_wl_egl_surface_t wl_egl_surface(tizen_private->data);
+
+       if (wl_egl_surface) {
+               wl_egl_surface->pre_commit_cb.func = func;
+               wl_egl_surface->pre_commit_cb.data = data;
+               wl_egl_surface->pre_commit_cb.option = option;
+
+               TPL_LOG_D("[SET_PRE_COMMIT_CALLBACK]", "wl_egl_surface(%p) option(%d)",
+                                 wl_egl_surface, option);
+       }
+}
 /* -- END -- wl_egl_window tizen private callback functions */
 
 /* -- BEGIN -- tizen_surface_shm_flusher_listener */
@@ -1930,6 +1959,7 @@ __tpl_wl_egl_surface_init(tpl_surface_t *surface)
 #else
                        tizen_private->create_presentation_sync_fd = NULL;
 #endif
+                       tizen_private->set_pre_commit_callback = (void *)__set_pre_commit_callback;
 
                        wl_egl_window->destroy_window_callback = (void *)__cb_destroy_callback;
                        wl_egl_window->resize_callback = (void *)__cb_resize_callback;
@@ -2443,6 +2473,7 @@ __tpl_wl_egl_surface_fini(tpl_surface_t *surface)
                        tizen_private->set_frontbuffer_callback = NULL;
                        tizen_private->merge_sync_fds = NULL;
                        tizen_private->data = NULL;
+                       tizen_private->set_pre_commit_callback = NULL;
                        free(tizen_private);
 
                        wl_egl_window->driver_private = NULL;
@@ -2656,6 +2687,9 @@ _wl_egl_buffer_init(tpl_wl_egl_buffer_t *wl_egl_buffer,
                wl_egl_buffer->rects                = NULL;
                wl_egl_buffer->num_rects            = 0;
        }
+
+       wl_egl_buffer->pre_commit_cb.func = NULL;
+       wl_egl_buffer->pre_commit_cb.data = NULL;
 }
 
 static tpl_wl_egl_buffer_t *
@@ -3122,6 +3156,16 @@ __tpl_wl_egl_surface_enqueue_buffer(tpl_surface_t *surface,
                wl_egl_surface->serial_updated = TPL_FALSE;
        }
 
+       if (wl_egl_surface->pre_commit_cb.func) {
+               wl_egl_buffer->pre_commit_cb.func = wl_egl_surface->pre_commit_cb.func;
+               wl_egl_buffer->pre_commit_cb.data = wl_egl_surface->pre_commit_cb.data;
+
+               if (wl_egl_surface->pre_commit_cb.option == ONCE) {
+                       wl_egl_surface->pre_commit_cb.func = NULL;
+                       wl_egl_surface->pre_commit_cb.data = NULL;
+               }
+       }
+
        tpl_gmutex_lock(&wl_egl_surface->presentation_sync.mutex);
        if (wl_egl_surface->presentation_sync.fd != -1) {
                wl_egl_buffer->presentation_sync_fd  = wl_egl_surface->presentation_sync.fd;
@@ -3756,6 +3800,12 @@ _thread_wl_surface_commit(tpl_wl_egl_surface_t *wl_egl_surface,
                wl_egl_window->attached_height = wl_egl_buffer->height;
        }
 
+       if (wl_egl_buffer->pre_commit_cb.func) {
+               wl_egl_buffer->pre_commit_cb.func(wl_egl_buffer->pre_commit_cb.data);
+               wl_egl_buffer->pre_commit_cb.func = NULL;
+               wl_egl_buffer->pre_commit_cb.data = NULL;
+       }
+
        wl_surface_attach(wl_surface, (void *)wl_egl_buffer->wl_buffer,
                                          wl_egl_buffer->dx, wl_egl_buffer->dy);