tpl_wayland_egl_thread: Added twe_surface_set_damage_region. 84/134984/3
authorjoonbum.ko <joonbum.ko@samsung.com>
Thu, 27 Apr 2017 07:25:14 +0000 (16:25 +0900)
committerjoonbum.ko <joonbum.ko@samsung.com>
Wed, 21 Jun 2017 07:04:26 +0000 (16:04 +0900)
 - NEW API : twe_surface_set_damage_region(tbm_surface_h, int num_rects, const int* rects)
 - I expect it to be called before tbm_surface_queue_enqueue() inside tpl_surface_enqueue_buffer().

 - The input parameter tbm_surface_h must be a dequeued buffer from tbm_surface_queue.

 - Operation :
   * Get twe_wl_buffer_info from tbm_surface user_data.
   * If buf_info->rects already exists, free this old one and re allocate new rects.

Change-Id: Ib9e552dab4450caad3aa9c1e941f9190abe79252
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl_wayland_egl_thread.c
src/tpl_wayland_egl_thread.h

index eee1b5c..c1bc32a 100644 (file)
@@ -83,6 +83,9 @@ struct _twe_wl_buffer_info {
        int dx, dy;
        int width, height;
        int rotation;
+       /* for damage region */
+       int num_rects;
+       int *rects;
        twe_wl_surf_source *surf_source;
 };
 
@@ -795,6 +798,11 @@ twe_surface_set_buffer(twe_surface_h twe_surface, tbm_surface_h tbm_surface)
                buf_info->dx = wl_egl_window->dx;
                buf_info->dy = wl_egl_window->dy;
 
+               if (buf_info->rects) {
+                       free(buf_info->rects);
+                       buf_info->rects = NULL;
+                       buf_info->num_rects = 0;
+               }
                return TPL_ERROR_NONE;
        } else {
                buf_info = (twe_wl_buffer_info *)calloc(1, sizeof(twe_wl_buffer_info));
@@ -816,6 +824,14 @@ twe_surface_set_buffer(twe_surface_h twe_surface, tbm_surface_h tbm_surface)
                return TPL_ERROR_INVALID_OPERATION;
        }
 
+       buf_info->rotation = wl_egl_window->rotation;
+       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;
+
        wl_buffer_add_listener((void *)buf_info->wl_buffer,
                                                   &wl_buffer_release_listener, tbm_surface);
        wl_display_flush(source->disp_source->disp);
@@ -834,9 +850,58 @@ twe_surface_set_buffer(twe_surface_h twe_surface, tbm_surface_h tbm_surface)
                return TPL_ERROR_INVALID_OPERATION;
        }
 
+       TPL_LOG_T("WL_EGL",
+                         "[NEW_BUF] buf_info(%p) tbm_surface(%p) bo(%d) (%dx%d) rot(%d)",
+                         buf_info, tbm_surface,
+                         tbm_bo_export(tbm_surface_internal_get_bo(tbm_surface, 0)),
+                         buf_info->width, buf_info->height, buf_info->rotation);
+
        return TPL_ERROR_NONE;
 }
 
+tpl_result_t
+twe_surface_set_damage_region(tbm_surface_h tbm_surface,
+                                                         int num_rects,
+                                                         const int *rects)
+{
+       twe_wl_buffer_info *buf_info = NULL;
+
+       if (!tbm_surface || !tbm_surface_internal_is_valid(tbm_surface)) {
+               TPL_ERR("Invalid parameter. tbm_surface(%p)", tbm_surface);
+               return TPL_ERROR_INVALID_PARAMETER;
+       }
+
+       if (num_rects == 0 || rects == NULL) {
+               return TPL_ERROR_NONE;
+       }
+
+       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 TPL_ERROR_INVALID_OPERATION;
+       }
+
+       /* Destroy old region if there are old region info. */
+       if (buf_info->rects != NULL) {
+               free(buf_info->rects);
+               buf_info->rects = NULL;
+               buf_info->num_rects = 0;
+       }
+
+       buf_info->rects = (int *)calloc(1, (sizeof(int) * 4 * num_rects));
+       buf_info->num_rects = num_rects;
+
+       if (!buf_info->rects) {
+               TPL_ERR("Failed to allocate memory fo damage rects info.");
+               return TPL_ERROR_INVALID_OPERATION;
+       }
+
+       memcpy((char *)buf_info->rects, (char *)rects, sizeof(int) * 4 * num_rects);
+
+       return TPL_ERROR_NONE;
+}
 
 #ifdef WORKER_TEST_ONLY
 static void reg_global(void *data,
index 337d80d..1173aa2 100644 (file)
@@ -43,3 +43,7 @@ twe_surface_set_rotation_capablity(twe_surface_h twe_surface, tpl_bool_t set);
 tpl_result_t
 twe_surface_set_buffer(twe_surface_h twe_surface, tbm_surface_h tbm_surface);
 
+tpl_result_t
+twe_surface_set_damage_region(tbm_surface_h tbm_surface,
+                                                         int num_rects, const int *rects);
+