surface_queue: Add new apis for reset queue 79/52679/1 accepted/tizen/mobile/20151201.230123 accepted/tizen/tv/20151201.230143 accepted/tizen/wearable/20151201.230158 submit/tizen/20151201.105445
authorSangjin Lee <lsj119@samsung.com>
Wed, 25 Nov 2015 14:24:07 +0000 (23:24 +0900)
committerSangjin Lee <lsj119@samsung.com>
Wed, 25 Nov 2015 14:24:07 +0000 (23:24 +0900)
The surface_queue allow change width, height and format.
If changed information, all tbm_surfaces destroyed in core.
and send reset notify.

Change-Id: I0d5378899f94e19f83dd0201f83fec7fbdf8a084
Signed-off-by: Sangjin Lee <lsj119@samsung.com>
src/tbm_surface_queue.c
src/tbm_surface_queue.h

index 24782fe..1ee649a 100644 (file)
@@ -69,6 +69,9 @@ struct _tbm_surface_queue
     tbm_surface_queue_notify_cb acquirable_cb;
     void *acquirable_cb_data;
 
+    tbm_surface_queue_notify_cb reset_cb;
+    void *reset_cb_data;
+
     pthread_mutex_t lock;
     pthread_cond_t free_cond;
     pthread_cond_t duty_cond;
@@ -86,7 +89,8 @@ _queue_node_create (void)
 static void
 _queue_node_delete (queue_node *node)
 {
-    tbm_surface_destroy (node->surface);
+    if (node->surface)
+        tbm_surface_destroy (node->surface);
     LIST_DEL (&node->item_link);
     free (node);
 }
@@ -512,3 +516,63 @@ tbm_surface_queue_get_format(tbm_surface_queue_h surface_queue)
 {
     return surface_queue->format;
 }
+
+tbm_surface_queue_error_e
+tbm_surface_queue_reset(tbm_surface_queue_h surface_queue, int width, int height, int format)
+{
+    TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE);
+
+    int i;
+    queue_node *node = NULL;
+
+    if (width == surface_queue->width &&
+        height == surface_queue->height &&
+        format == surface_queue->format)
+        return TBM_SURFACE_QUEUE_ERROR_NONE;
+
+    pthread_mutex_lock (&surface_queue->lock);
+
+    surface_queue->width = width;
+    surface_queue->height = height;
+    surface_queue->format = format;
+
+    //Reset queue
+    _queue_init(&surface_queue->free_queue);
+    _queue_init(&surface_queue->duty_queue);
+
+    //Destory surface and Push to free_queue
+    for (i = 0 ; i < surface_queue->size; i++)
+    {
+        node = surface_queue->node_list[i];
+        if (node->surface)
+        {
+            tbm_surface_destroy(node->surface);
+            node->surface = NULL;
+        }
+
+        _queue_node_push_back(&surface_queue->free_queue, node);
+    }
+
+    pthread_mutex_unlock (&surface_queue->lock);
+    pthread_cond_signal(&surface_queue->free_cond);
+
+    if (surface_queue->reset_cb)
+        surface_queue->reset_cb (surface_queue, surface_queue->reset_cb_data);
+
+    return TBM_SURFACE_QUEUE_ERROR_NONE;
+}
+
+tbm_surface_queue_error_e
+tbm_surface_queue_set_reset_cb (tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, void *data)
+{
+    TBM_RETURN_VAL_IF_FAIL (surface_queue != NULL, TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE);
+
+    pthread_mutex_lock (&surface_queue->lock);
+
+    surface_queue->reset_cb = reset_cb;
+    surface_queue->reset_cb_data = data;
+
+    pthread_mutex_unlock (&surface_queue->lock);
+
+    return TBM_SURFACE_QUEUE_ERROR_NONE;
+}
index 71d725b..28824ef 100644 (file)
@@ -81,6 +81,12 @@ int tbm_surface_queue_get_width(tbm_surface_queue_h surface_queue);
 int tbm_surface_queue_get_height(tbm_surface_queue_h surface_queue);
 
 int tbm_surface_queue_get_format(tbm_surface_queue_h surface_queue);
+
+tbm_surface_queue_error_e tbm_surface_queue_reset(tbm_surface_queue_h surface_queue, int width, int height, int format);
+
+tbm_surface_queue_error_e tbm_surface_queue_set_reset_cb (tbm_surface_queue_h surface_queue, tbm_surface_queue_notify_cb reset_cb, void *data);
+
+
 #ifdef __cplusplus
 }
 #endif