tpl_wayland_egl_thread: Added internal function for acquire and commit. 85/134985/3
authorjoonbum.ko <joonbum.ko@samsung.com>
Fri, 28 Apr 2017 01:53:21 +0000 (10:53 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Wed, 21 Jun 2017 07:04:26 +0000 (16:04 +0900)
Change-Id: Ifb322ae2623d69906c0c44ee2f6de46a807a3022
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c

index c1bc32a..5cd4159 100644 (file)
@@ -468,6 +468,80 @@ __cb_tbm_queue_acquirable_callback(tbm_surface_queue_h surface_queue,
        }
 }
 
+static void
+_twe_thread_wl_surface_commit(twe_wl_surf_source *surf_source,
+                                                         tbm_surface_h tbm_surface)
+{
+       twe_wl_buffer_info *buf_info = NULL;
+       struct wl_surface *wl_surface = surf_source->surf;
+       struct wl_egl_window *wl_egl_window = surf_source->wl_egl_window;
+
+       tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO,
+                                                                          (void **)&buf_info);
+       if (!buf_info) {
+               TPL_ERR("Failed to get twe_wl_buffer_info from tbm_surface(%p)",
+                               tbm_surface);
+               return;
+       }
+
+       wl_egl_window->attached_width = buf_info->width;
+       wl_egl_window->attached_height = buf_info->height;
+
+       wl_surface_attach(wl_surface, (struct wl_buffer *)buf_info->wl_buffer,
+                                         buf_info->dx, buf_info->dy);
+
+       if (buf_info->num_rects < 1 || buf_info->rects == NULL) {
+               wl_surface_damage_buffer(wl_surface,
+                                                                buf_info->dx, buf_info->dy,
+                                                                buf_info->width, buf_info->height);
+       } else {
+               int i;
+               for (i = 0; i < buf_info->num_rects; i++) {
+                       int inverted_y =
+                               buf_info->height - (buf_info->rects[i * 4 + 1] +
+                                               buf_info->rects[i * 4 + 3]);
+                       wl_surface_damage_buffer(wl_surface,
+                                                                        buf_info->rects[i * 4 + 0],
+                                                                        inverted_y,
+                                                                        buf_info->rects[i * 4 + 2],
+                                                                        buf_info->rects[i * 4 + 3]);
+               }
+       }
+
+       wl_surface_commit(wl_surface);
+
+       TPL_LOG_T("WL_EGL", "[COMMIT] wl_buffer(%p) tbm_surface(%p) bo(%d)",
+                         buf_info->wl_buffer, tbm_surface,
+                         tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)));
+}
+
+static void
+_twe_thread_wl_surface_acquire_and_commit(twe_wl_surf_source *surf_source)
+{
+       tbm_surface_h tbm_surface = NULL;
+       tbm_surface_queue_error_e tsq_err = TBM_SURFACE_QUEUE_ERROR_NONE;
+
+       if (!tbm_surface_queue_can_acquire(surf_source->tbm_queue, 0)) {
+               TPL_ERR("Received acquirable event, but nothing to commit.");
+               return;
+       }
+
+       tsq_err = tbm_surface_queue_acquire(surf_source->tbm_queue, &tbm_surface);
+       if (!tbm_surface || tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE) {
+               TPL_ERR("Failed to acquire from tbm_queue(%p)",
+                               surf_source->tbm_queue);
+               return;
+       }
+
+       tbm_surface_internal_ref(tbm_surface);
+
+       TPL_LOG_T("WL_EGL", "[ACQ] tbm_surface(%p) bo(%d)",
+                         tbm_surface,
+                         tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)));
+
+       _twe_thread_wl_surface_commit(surf_source, tbm_surface);
+}
+
 static gboolean
 _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer date)
 {
@@ -486,6 +560,8 @@ _twe_thread_wl_surface_dispatch(GSource *source, GSourceFunc cb, gpointer date)
                if (s != sizeof(uint64_t))
                        TPL_ERR("Failed to read from event_fd(%d)",
                                        wl_surf_source->event_fd);
+
+               _twe_thread_wl_surface_acquire_and_commit(wl_surf_source);
        }
 
        return G_SOURCE_CONTINUE;
@@ -743,9 +819,6 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer)
        twe_wl_buffer_info *buf_info = NULL;
        tbm_surface_h tbm_surface = (tbm_surface_h)data;
 
-       TPL_LOG_T("WL_EGL", "[RELEASE_CB] wl_buffer(%p) tbm_surface(%p)",
-                         wl_buffer, tbm_surface);
-
        if (tbm_surface_internal_is_valid(tbm_surface)) {
                tbm_surface_internal_get_user_data(tbm_surface, KEY_BUFFER_INFO,
                                                                                   (void **)&buf_info);
@@ -758,6 +831,9 @@ __cb_buffer_release_callback(void *data, struct wl_proxy *wl_buffer)
                        if (tsq_err != TBM_SURFACE_QUEUE_ERROR_NONE)
                                TPL_ERR("tbm_surface(%p) tsq_err(%d)", tbm_surface, tsq_err);
 
+                       TPL_LOG_T("WL_EGL", "[REL] wl_buffer(%p) tbm_surface(%p) bo(%d)",
+                                         buf_info->wl_buffer, tbm_surface,
+                                         tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)));
                        tbm_surface_internal_unref(tbm_surface);
                }