tpl: Added frontend API "tpl_surface_set_reset_cb" 71/90471/4 accepted/tizen/common/20161005.165649 submit/tizen/20161005.133318
authorjoonbum.ko <joonbum.ko@samsung.com>
Tue, 27 Sep 2016 09:41:29 +0000 (18:41 +0900)
committerGwan-gyeong Mun <kk.moon@samsung.com>
Wed, 5 Oct 2016 12:55:06 +0000 (05:55 -0700)
 - This API can set function of reset_cb to tpl_surface.
 - When the tbm_surface_queue_reset is occured, if there is reset_cb which is registered by frontend, tpl_surface calls that function of reset_cb with reset_data.

 - tpl_surface_validate() also can notify info of surface's "reset/resized states" to frontend  as before.
  But if you want to know the surface reset state without render call, it is better that registers callback of reset, using above API.

Change-Id: Ib762856ad1db306c435013218c1a4be2b24ef1c9
Signed-off-by: joonbum.ko <joonbum.ko@samsung.com>
src/tpl.h
src/tpl_internal.h
src/tpl_surface.c
src/tpl_wayland_egl.c

index cb48da9..76a3ad4 100644 (file)
--- a/src/tpl.h
+++ b/src/tpl.h
@@ -124,6 +124,11 @@ typedef struct _tpl_surface tpl_surface_t;
 typedef void (*tpl_free_func_t)(void *data);
 
 /**
+ * Function type used for registering callback function.
+ */
+typedef void (*tpl_surface_cb_func_t)(void *data);
+
+/**
  * Object types.
  *
  * @see tpl_object_get_type()
@@ -695,6 +700,29 @@ tbm_surface_h
 tpl_display_get_buffer_from_native_pixmap(tpl_display_t *display,
                                                                                  tpl_handle_t pixmap);
 
+/**
+ * Set frontbuffer mode to render to only frontbuffer.
+ *
+ * @param surface surface to set mode.
+ * @param set TPL_TRUE if user want to set tpl_surface to frontbuffer mode.
+ * @return TPL_ERROR_NONE if tpl_surface is valid.
+ */
 tpl_result_t
 tpl_surface_set_frontbuffer_mode(tpl_surface_t *surface, tpl_bool_t set);
+
+/**
+ * Set callback function to tpl_surface for receiving reset information.
+ *
+ * This function should be called when after tpl_surface_create() if
+ * frontend surface want to know that if surface reset or not.
+ *
+ * @param surface surface to set callback. It has to be not NULL.
+ * @param data data to be delivered to callback function.
+ * @param reset_cb pointer value of callback funtion.
+ *  - It can be NULL if frontend wants to delete callback function.
+ * @return TPL_ERROR_NONE if tpl_surface is valid.
+ */
+tpl_result_t
+tpl_surface_set_reset_cb(tpl_surface_t *surface,
+                                                void* data, tpl_surface_cb_func_t reset_cb);
 #endif /* TPL_H */
index 6231c87..41da0a4 100644 (file)
@@ -132,6 +132,10 @@ struct _tpl_surface {
        /*For frontbuffer extension*/
        tpl_bool_t is_frontbuffer_mode;
        tbm_surface_h frontbuffer;
+
+       /* Surface reset callback */
+       tpl_surface_cb_func_t reset_cb;
+       void* reset_data;
 };
 
 /*******************************************************************************
index d6ad51d..762a597 100644 (file)
@@ -405,3 +405,20 @@ tpl_surface_set_frontbuffer_mode(tpl_surface_t *surface, tpl_bool_t set)
                          surface, set ? "ACTIVATED" : "DEACTIVATED");
        return ret;
 }
+
+tpl_result_t
+tpl_surface_set_reset_cb(tpl_surface_t *surface, void *data, tpl_surface_cb_func_t reset_cb)
+{
+       tpl_result_t ret = TPL_ERROR_NONE;
+
+       if (!surface)
+       {
+               TPL_ERR("Invalid surface!");
+               return TPL_ERROR_INVALID_PARAMETER;
+       }
+
+       surface->reset_data = data;
+       surface->reset_cb = reset_cb;
+
+       return ret;
+}
index 7119bf2..35c8556 100644 (file)
@@ -47,7 +47,7 @@ struct _tpl_wayland_egl_surface {
        tbm_surface_queue_h tbm_queue;
        tbm_surface_h current_buffer;
        tpl_bool_t resized;
-       tpl_bool_t reset;          /* TRUE if queue reseted by external */
+       tpl_bool_t reset;       /* TRUE if queue reseted by external  */
        tdm_client_vblank *tdm_vblank; /* vblank object for each wl_surface */
        tpl_bool_t vblank_done;
        tpl_list_t *attached_buffers; /* list for tracking [ACQ]~[REL] buffers */
@@ -400,8 +400,14 @@ static void
 __cb_tbm_surface_queue_reset_callback(tbm_surface_queue_h surface_queue,
                                                                          void *data)
 {
-       tpl_wayland_egl_surface_t *wayland_egl_surface =
-               (tpl_wayland_egl_surface_t *)data;
+       tpl_surface_t *surface = NULL;
+       tpl_wayland_egl_surface_t *wayland_egl_surface = NULL;
+
+       surface = (tpl_surface_t *)data;
+       TPL_CHECK_ON_NULL_RETURN(surface);
+
+       wayland_egl_surface = (tpl_wayland_egl_surface_t *)surface->backend.data;
+       TPL_CHECK_ON_NULL_RETURN(wayland_egl_surface);
 
        if (!wayland_egl_surface) return;
 
@@ -409,10 +415,10 @@ __cb_tbm_surface_queue_reset_callback(tbm_surface_queue_h surface_queue,
                          "[QUEUE_RESET_CB] tpl_wayland_egl_surface_t(%p) surface_queue(%p)",
                          data, surface_queue);
 
-       wayland_egl_surface->reset = TPL_TRUE;
-
        TPL_OBJECT_LOCK(&wayland_egl_surface->base);
 
+       wayland_egl_surface->reset = TPL_TRUE;
+
        /* Set the reset flag of the buffers which attached but not released to TPL_TRUE. */
        __tpl_wayland_egl_buffer_set_reset_flag(wayland_egl_surface->attached_buffers);
 
@@ -420,6 +426,9 @@ __cb_tbm_surface_queue_reset_callback(tbm_surface_queue_h surface_queue,
        __tpl_wayland_egl_buffer_set_reset_flag(wayland_egl_surface->dequeued_buffers);
 
        TPL_OBJECT_UNLOCK(&wayland_egl_surface->base);
+
+       if (surface->reset_cb)
+               surface->reset_cb(surface->reset_data);
 }
 
 static tpl_result_t
@@ -487,6 +496,7 @@ __tpl_wayland_egl_surface_init(tpl_surface_t *surface)
        surface->backend.data = (void *)wayland_egl_surface;
        wayland_egl_surface->tbm_queue = NULL;
        wayland_egl_surface->resized = TPL_FALSE;
+       wayland_egl_surface->reset = TPL_FALSE;
        wayland_egl_surface->vblank_done = TPL_TRUE;
        wayland_egl_surface->current_buffer = NULL;
 
@@ -526,7 +536,7 @@ __tpl_wayland_egl_surface_init(tpl_surface_t *surface)
        /* Set reset_callback to tbm_queue */
        tbm_surface_queue_add_reset_cb(wayland_egl_surface->tbm_queue,
                                                                   __cb_tbm_surface_queue_reset_callback,
-                                                                  (void *)wayland_egl_surface);
+                                                                  (void *)surface);
 
 
        surface->width = wl_egl_window->width;
@@ -875,20 +885,7 @@ __tpl_wayland_egl_surface_validate(tpl_surface_t *surface)
        tpl_wayland_egl_surface_t *wayland_egl_surface =
                (tpl_wayland_egl_surface_t *)surface->backend.data;
 
-       retval = !(wayland_egl_surface->reset || wayland_egl_surface->resized);
-
-       /* TODO */
-       /* Be planning to revise below line in future commits.
-          - It is under development so that EGL can realize tbm_surface_queue_reset
-            immediately.
-        */
-
-       /* The tbm_surface_queue_flush (which is occured by ACTIVE, DEACTIVE events)
-        * only occured in __tpl_wayland_egl_surface_wait_dequeable.
-        * After tpl_surface_dequeue_buffer(), tpl_surface has to inform to frontend
-        * surface was reset. (retval)
-        * The reset flag will be set to TPL_FALSE only here after inform it. */
-       wayland_egl_surface->reset = TPL_FALSE;
+       retval = !(wayland_egl_surface->resized || wayland_egl_surface->reset);
 
        return retval;
 }
@@ -1006,6 +1003,7 @@ __tpl_wayland_egl_surface_dequeue_buffer(tpl_surface_t *surface,
                                  tbm_surface, tbm_bo_export(wayland_egl_buffer->bo));
 
                wayland_egl_buffer->reset = TPL_FALSE;
+               wayland_egl_surface->reset = TPL_FALSE;
 
                if (wayland_egl_surface->dequeued_buffers) {
                        TPL_OBJECT_LOCK(&wayland_egl_surface->base);
@@ -1050,6 +1048,7 @@ __tpl_wayland_egl_surface_dequeue_buffer(tpl_surface_t *surface,
        wayland_egl_buffer->reset = TPL_FALSE;
 
        wayland_egl_surface->current_buffer = tbm_surface;
+       wayland_egl_surface->reset = TPL_FALSE;
 
        __tpl_wayland_egl_set_wayland_buffer_to_tbm_surface(tbm_surface,
                        wayland_egl_buffer);