Added fence_waiting_sources list to trace fence_wait_sources. 54/228754/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Wed, 25 Mar 2020 07:35:30 +0000 (16:35 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Wed, 25 Mar 2020 07:35:30 +0000 (16:35 +0900)
Change-Id: Ib70a80a94be9f507adea71e13957adca87e41f9e
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c

index 38374176bad1ebb7b713df5dd6d6cf75eab6ded5..ce46b070d0ee07b5b0086be799ccb510ac0713b8 100755 (executable)
@@ -111,6 +111,7 @@ struct _twe_wl_surf_source {
        tpl_bool_t rotation_capability;
        tpl_list_t *committed_buffers; /* Trace tbm_surface from wl_surface_commit() to RELEASE */
        tpl_list_t *in_use_buffers; /* Trace tbm_surface from DEQUEUE to ENQUEUE */
+       tpl_list_t *fence_waiting_sources; /* Trace fence_wait_source from ENQUEUE to fence signaled */
        tpl_list_t *vblank_waiting_buffers; /* for FIFO/FIFO_RELAXED modes */
        tbm_surface_h draw_done_buffer; /* for MAILBOX mode */
        int render_done_cnt;
@@ -2595,6 +2596,25 @@ _twe_thread_wl_surf_source_destroy(void *source)
                surf_source->vblank_waiting_buffers = NULL;
        }
 
+       if (surf_source->use_sync_fence && surf_source->fence_waiting_sources) {
+               while (!__tpl_list_is_empty(surf_source->fence_waiting_sources)) {
+                       twe_fence_wait_source *wait_source =
+                               __tpl_list_pop_front(surf_source->fence_waiting_sources,
+                                                                        NULL);
+                       if (!g_source_is_destroyed(&wait_source->gsource)) {
+                               tbm_surface_internal_unref(wait_source->tbm_surface);
+                               wait_source->tbm_surface = NULL;
+
+                               close(wait_source->fence_fd);
+                               wait_source->fence_fd = -1;
+
+                               g_source_remove_unix_fd(&wait_source->gsource, wait_source->tag);
+                               g_source_destroy(&wait_source->gsource);
+                               g_source_unref(&wait_source->gsource);
+                       }
+               }
+       }
+
        _twe_surface_buffer_flusher_fini(surf_source);
 
        if (surf_source->tbm_queue) {
@@ -2700,6 +2720,7 @@ twe_surface_add(twe_thread* thread,
        source->is_destroying = TPL_FALSE;
        source->committed_buffers = __tpl_list_alloc();
        source->in_use_buffers = __tpl_list_alloc();
+       source->fence_waiting_sources = __tpl_list_alloc();
        source->render_done_cnt = 0;
 
        source->cb_data = NULL;
@@ -3228,6 +3249,11 @@ _twe_thread_fence_wait_source_dispatch(GSource *source, GSourceFunc cb, gpointer
        _twe_thread_wl_surface_acquire_and_commit(surf_source);
        tbm_surface_internal_unref(tbm_surface);
 
+       g_mutex_lock(&surf_source->surf_mutex);
+       __tpl_list_remove_data(surf_source->fence_waiting_sources,
+                                                  (void *)wait_source, TPL_FIRST, NULL);
+       g_mutex_unlock(&surf_source->surf_mutex);
+
        /* This source is used only once and does not allow reuse.
         * So finalize will be executed immediately. */
        g_source_remove_unix_fd(&wait_source->gsource, wait_source->tag);
@@ -3284,6 +3310,12 @@ _twe_thread_fence_wait_source_attach(twe_wl_surf_source *surf_source,
        wait_source->tag = g_source_add_unix_fd(&wait_source->gsource,
                                                                                        wait_source->fence_fd,
                                                                                        G_IO_IN);
+
+       /* When waiting is over, it will be removed from the list. */
+       g_mutex_lock(&surf_source->surf_mutex);
+       __tpl_list_push_back(surf_source->fence_waiting_sources, (void *)wait_source);
+       g_mutex_unlock(&surf_source->surf_mutex);
+
        g_source_attach(&wait_source->gsource, g_main_loop_get_context(_twe_ctx->twe_loop));
 
        return TPL_ERROR_NONE;