tbm_surface_queue: added tbm_surface_queue_mode 44/139444/2
authorChangyeon Lee <cyeon.lee@samsung.com>
Tue, 18 Jul 2017 08:14:28 +0000 (17:14 +0900)
committerChangyeon Lee <cyeon.lee@samsung.com>
Wed, 19 Jul 2017 05:12:52 +0000 (14:12 +0900)
if user set queue mode to GUARANTEE_CYCLE, user must do enqueue/acquire/release
or cancel_dequeue for tbm_surface which is dequeued before
tbm_surface_queue is reset

Change-Id: Ia26ae79ca376ad69d9714500bd4dfb48ae61da79

src/tbm_surface_queue.c
src/tbm_surface_queue.h

index 48fe3b290f595032b44c073903a58e04f569eee1..a118bd3fe334f9e5904d31150edf02a26a68ea10 100644 (file)
@@ -160,6 +160,8 @@ struct _tbm_surface_queue {
        void *alloc_cb_data;
 
        struct list_head item_link; /* link of surface queue */
+
+       int modes;
 };
 
 /* LCOV_EXCL_START */
@@ -619,6 +621,7 @@ _tbm_surface_queue_init(tbm_surface_queue_h surface_queue,
        surface_queue->format = format;
        surface_queue->impl = impl;
        surface_queue->impl_data = data;
+       surface_queue->modes = TBM_SURFACE_QUEUE_MODE_NONE;
 
        _queue_init(&surface_queue->free_queue);
        _queue_init(&surface_queue->dirty_queue);
@@ -1620,12 +1623,20 @@ tbm_surface_queue_reset(tbm_surface_queue_h
        surface_queue->height = height;
        surface_queue->format = format;
 
-       /* Destory surface and Push to free_queue */
-       LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->free_queue.head, link)
-               _queue_delete_node(surface_queue, node);
+       if (surface_queue->modes & TBM_SURFACE_QUEUE_MODE_GUARANTEE_CYCLE) {
+               /* Destory surface and Push to free_queue */
+               LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->free_queue.head, link)
+                       _queue_delete_node(surface_queue, node);
 
-       LIST_FOR_EACH_ENTRY(node, &surface_queue->list, link)
-               node->delete_pending = 1;
+               LIST_FOR_EACH_ENTRY(node, &surface_queue->list, link)
+                       node->delete_pending = 1;
+       } else {
+               LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->list, link)
+                       _queue_delete_node(surface_queue, node);
+
+               _queue_init(&surface_queue->dirty_queue);
+               LIST_INITHEAD(&surface_queue->list);
+       }
 
        /* Reset queue */
        _queue_init(&surface_queue->free_queue);
@@ -1683,12 +1694,20 @@ tbm_surface_queue_set_size(tbm_surface_queue_h
        pthread_mutex_lock(&surface_queue->lock);
 
        if (flush) {
-               /* Destory surface and Push to free_queue */
-               LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->free_queue.head, item_link)
-                       _queue_delete_node(surface_queue, node);
-
-               LIST_FOR_EACH_ENTRY(node, &surface_queue->list, link)
-                       node->delete_pending = 1;
+               if (surface_queue->modes & TBM_SURFACE_QUEUE_MODE_GUARANTEE_CYCLE) {
+                       /* Destory surface and Push to free_queue */
+                       LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->free_queue.head, link)
+                               _queue_delete_node(surface_queue, node);
+
+                       LIST_FOR_EACH_ENTRY(node, &surface_queue->list, link)
+                               node->delete_pending = 1;
+               } else {
+                       LIST_FOR_EACH_ENTRY_SAFE(node, tmp, &surface_queue->list, link)
+                               _queue_delete_node(surface_queue, node);
+
+                       _queue_init(&surface_queue->dirty_queue);
+                       LIST_INITHEAD(&surface_queue->list);
+               }
 
                /* Reset queue */
                _queue_init(&surface_queue->free_queue);
@@ -1993,6 +2012,15 @@ __tbm_queue_sequence_init(tbm_surface_queue_h surface_queue)
        _queue_init(&data->dequeue_list);
 }
 
+static void
+__tbm_queue_sequence_reset(tbm_surface_queue_h surface_queue)
+{
+       tbm_queue_sequence *data = (tbm_queue_sequence *)surface_queue->impl_data;
+
+       if (surface_queue->modes & TBM_SURFACE_QUEUE_MODE_GUARANTEE_CYCLE)
+               _queue_init(&data->dequeue_list);
+}
+
 static void
 __tbm_queue_sequence_destroy(tbm_surface_queue_h surface_queue)
 {
@@ -2081,7 +2109,7 @@ __tbm_queue_sequence_dequeue(tbm_surface_queue_h
 
 static const tbm_surface_queue_interface tbm_queue_sequence_impl = {
        __tbm_queue_sequence_init,
-       NULL,
+       __tbm_queue_sequence_reset,
        __tbm_queue_sequence_destroy,
        __tbm_queue_sequence_need_attach,
        __tbm_queue_sequence_enqueue,
@@ -2127,4 +2155,27 @@ tbm_surface_queue_sequence_create(int queue_size, int width,
 
        return surface_queue;
 }
+
+tbm_surface_queue_error_e
+tbm_surface_queue_set_modes(tbm_surface_queue_h surface_queue,
+                                 int modes)
+{
+       _tbm_surf_queue_mutex_lock();
+
+       TBM_SURF_QUEUE_RETURN_VAL_IF_FAIL(_tbm_surface_queue_is_valid(surface_queue),
+                              TBM_SURFACE_QUEUE_ERROR_INVALID_QUEUE);
+
+       pthread_mutex_lock(&surface_queue->lock);
+
+       if (modes == TBM_SURFACE_QUEUE_MODE_NONE)
+               modes = TBM_SURFACE_QUEUE_MODE_NONE;
+       else
+               surface_queue->modes |= modes;
+
+       pthread_mutex_unlock(&surface_queue->lock);
+
+       _tbm_surf_queue_mutex_unlock();
+
+       return TBM_SURFACE_QUEUE_ERROR_NONE;
+}
 /* LCOV_EXCL_STOP */
index 1db62667faacba493d4d8c46fa94ab2f9900b59b..691f7742d808ade3fef81209243553ebb6b5592d 100644 (file)
@@ -55,6 +55,15 @@ typedef enum {
        TBM_SURFACE_QUEUE_TRACE_CANCEL_ACQUIRE = 6,
 } tbm_surface_queue_trace;
 
+typedef enum {
+       TBM_SURFACE_QUEUE_MODE_NONE = 0,
+       /**
+        * GUARANTEE_CYCLE mode must do enqueue/aquire/release or cancel_dequeue
+        * for the tbm_surface which is dequeued before tbm_surface_queue is reset.
+        */
+       TBM_SURFACE_QUEUE_MODE_GUARANTEE_CYCLE = (1 << 0),
+} tbm_surface_queue_mode;
+
 typedef struct _tbm_surface_queue *tbm_surface_queue_h;
 
 typedef void (*tbm_surface_queue_notify_cb)(tbm_surface_queue_h surface_queue,
@@ -185,6 +194,9 @@ tbm_surface_queue_error_e tbm_surface_queue_get_surfaces(
 tbm_surface_queue_error_e tbm_surface_queue_get_trace_surface_num(
                        tbm_surface_queue_h surface_queue, tbm_surface_queue_trace trace, int *num);
 
+tbm_surface_queue_error_e tbm_surface_queue_set_modes(
+                       tbm_surface_queue_h surface_queue, int modes);
+
 /*The functions of queue factory*/
 tbm_surface_queue_h tbm_surface_queue_create(int queue_size, int width,
                int height, int format, int flags);