tpl_wayland_egl_thread: Implemented the content related to wayland vk buffer. 67/161967/2
authorjoonbum.ko <joonbum.ko@samsung.com>
Wed, 11 Oct 2017 07:33:03 +0000 (16:33 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Tue, 28 Nov 2017 10:46:02 +0000 (19:46 +0900)
Change-Id: I530e02d978dd703fef700274ca6290d15ed50151
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c

index 6b66c2c..91d25f4 100644 (file)
@@ -126,9 +126,20 @@ struct _twe_wl_buffer_info {
        int num_rects;
        int *rects;
        tpl_bool_t need_to_commit;
+
+       GThread *fence_waiting_thread;
+
+       tpl_bool_t draw_done;
+       tbm_fd draw_done_fence;
+       tbm_fd sync_timeline;
+       unsigned int sync_timestamp;
+
+       tbm_surface_h tbm_surface;
+
        twe_wl_surf_source *surf_source;
 };
 
+
 static twe_thread_context *_twe_ctx;
 static twe_tdm_source *
 _twe_thread_tdm_source_create(void);
@@ -138,6 +149,8 @@ twe_del_source *
 _twe_del_source_init(twe_thread_context *ctx, void *target_source);
 void
 _twe_del_source_fini(twe_del_source *source);
+static void
+_twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source);
 
 static gpointer
 _twe_thread_loop(gpointer data)
@@ -1224,16 +1237,33 @@ __cb_twe_buffer_free_callback(twe_wl_buffer_info *buf_info)
 
        wl_display_flush(disp_source->disp);
 
+       if (buf_info->fence_waiting_thread) {
+               g_thread_join(buf_info->fence_waiting_thread);
+               buf_info->fence_waiting_thread = NULL;
+       }
+
+       if (buf_info->draw_done_fence != -1) {
+               close(buf_info->draw_done_fence);
+               buf_info->draw_done_fence = -1;
+       }
+
        if (buf_info->wl_buffer)
                wayland_tbm_client_destroy_buffer(disp_source->wl_tbm_client,
                                                                                  (void *)buf_info->wl_buffer);
 
+       if (buf_info->sync_timeline != -1) {
+               close(buf_info->sync_timeline);
+               buf_info->sync_timeline = -1;
+       }
+
        if (buf_info->rects) {
                free(buf_info->rects);
                buf_info->rects = NULL;
                buf_info->num_rects = 0;
        }
 
+       buf_info->tbm_surface = NULL;
+
        free(buf_info);
 }
 
@@ -1285,7 +1315,7 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source,
        twe_wl_buffer_info *buf_info = NULL;
        struct wl_egl_window *wl_egl_window = NULL;
 
-       if (!surf_source) {
+       if (!surf_source || g_source_is_destroyed(&surf_source->gsource)) {
                TPL_ERR("Invalid parameter. twe_surface(%p)", surf_source);
                return;
        }
@@ -1301,19 +1331,21 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source,
                                                                           (void **)&buf_info);
        /* If buf_info is already existed, reuse it. */
        if (buf_info) {
-               if (buf_info->w_transform != wl_egl_window->window_transform) {
-                       buf_info->w_transform = wl_egl_window->window_transform;
-                       buf_info->w_rotated = TPL_TRUE;
-               }
+               if (wl_egl_window) {
+                       if (buf_info->w_transform != wl_egl_window->window_transform) {
+                               buf_info->w_transform = wl_egl_window->window_transform;
+                               buf_info->w_rotated = TPL_TRUE;
+                       }
 
-               if (surf_source->latest_transform != wl_egl_window->transform) {
-                       surf_source->latest_transform = wl_egl_window->transform;
-                       buf_info->rotated = TPL_TRUE;
-               }
+                       if (surf_source->latest_transform != wl_egl_window->transform) {
+                               surf_source->latest_transform = wl_egl_window->transform;
+                               buf_info->rotated = TPL_TRUE;
+                       }
 
-               buf_info->transform = wl_egl_window->transform;
-               buf_info->dx = wl_egl_window->dx;
-               buf_info->dy = wl_egl_window->dy;
+                       buf_info->transform = wl_egl_window->transform;
+                       buf_info->dx = wl_egl_window->dx;
+                       buf_info->dy = wl_egl_window->dy;
+               }
 
                if (buf_info->rects) {
                        free(buf_info->rects);
@@ -1322,6 +1354,7 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source,
                }
 
                buf_info->need_to_commit = TPL_TRUE;
+               buf_info->draw_done = TPL_FALSE;
 
                if (surf_source->in_use_buffers) {
                        TPL_OBJECT_LOCK(&surf_source->obj);
@@ -1336,10 +1369,9 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source,
                                  tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)),
                                  buf_info->width, buf_info->height, buf_info->transform);
                return;
-       } else {
-               buf_info = (twe_wl_buffer_info *)calloc(1, sizeof(twe_wl_buffer_info));
        }
 
+       buf_info = (twe_wl_buffer_info *)calloc(1, sizeof(twe_wl_buffer_info));
        if (!buf_info) {
                TPL_ERR("Failed to allocate memory for twe_wl_buffer_info.");
                return;
@@ -1356,26 +1388,47 @@ _twe_surface_set_wl_buffer_info(twe_wl_surf_source *surf_source,
                return;
        }
 
-       buf_info->surf_source = surf_source;
-       buf_info->dx = wl_egl_window->dx;
-       buf_info->dy = wl_egl_window->dy;
-       buf_info->width = wl_egl_window->width;
-       buf_info->height = wl_egl_window->height;
-       buf_info->num_rects = 0;
-       buf_info->rects = NULL;
-       buf_info->need_to_commit = TPL_TRUE;
+       if (wl_egl_window) {
+               buf_info->dx = wl_egl_window->dx;
+               buf_info->dy = wl_egl_window->dy;
+               buf_info->width = wl_egl_window->width;
+               buf_info->height = wl_egl_window->height;
 
-       if (buf_info->w_transform != wl_egl_window->window_transform) {
-               buf_info->w_transform = wl_egl_window->window_transform;
-               buf_info->w_rotated = TPL_TRUE;
+               if (buf_info->w_transform != wl_egl_window->window_transform) {
+                       buf_info->w_transform = wl_egl_window->window_transform;
+                       buf_info->w_rotated = TPL_TRUE;
+               }
+
+               if (surf_source->latest_transform != wl_egl_window->transform) {
+                       surf_source->latest_transform = wl_egl_window->transform;
+                       buf_info->rotated = TPL_TRUE;
+               }
+
+               buf_info->transform = wl_egl_window->transform;
+       } else {
+               buf_info->dx = 0;
+               buf_info->dy = 0;
+               buf_info->width = surf_source->swapchain_properties.width;
+               buf_info->height = surf_source->swapchain_properties.height;
+               buf_info->w_transform = 0;
+               buf_info->w_rotated = TPL_FALSE;
+               buf_info->rotated = TPL_FALSE;
        }
 
-       if (surf_source->latest_transform != wl_egl_window->transform) {
-               surf_source->latest_transform = wl_egl_window->transform;
-               buf_info->rotated = TPL_TRUE;
+       buf_info->sync_timeline = tbm_sync_timeline_create();
+       if (buf_info->sync_timeline == -1) {
+               char buf[1024];
+               strerror_r(errno, buf, sizeof(buf));
+               TPL_WARN("Failed to create TBM sync timeline: %d(%s)", errno, buf);
        }
 
-       buf_info->transform = wl_egl_window->transform;
+       buf_info->sync_timestamp = 0;
+       buf_info->surf_source = surf_source;
+       buf_info->num_rects = 0;
+       buf_info->rects = NULL;
+       buf_info->need_to_commit = TPL_TRUE;
+       buf_info->draw_done = TPL_FALSE;
+       buf_info->tbm_surface = tbm_surface;
 
        wl_buffer_add_listener((void *)buf_info->wl_buffer,
                                                   &wl_buffer_release_listener, tbm_surface);
@@ -1475,9 +1528,6 @@ static void __cb_tbm_queue_trace_callback(tbm_surface_queue_h tbm_queue,
 }
 
 static void
-_twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source);
-
-static void
 __cb_tdm_client_wait_vblank(tdm_client_vblank *vblank, tdm_error error,
                                                        unsigned int sequence, unsigned int tv_sec,
                                                        unsigned int tv_usec, void *user_data)