summaryrefslogtreecommitdiff
path: root/src/lib/ecore_buffer/buffer_queue.c
diff options
context:
space:
mode:
authorSeunghun Lee <beauty.positive3@gmail.com>2015-06-22 10:23:54 -0400
committerChris Michael <cp.michael@samsung.com>2015-06-22 10:31:42 -0400
commit8b621775619b9959fe952b095b3baaa7aaa99572 (patch)
tree99059a841a79729cac4687ea41f3abf672e6e455 /src/lib/ecore_buffer/buffer_queue.c
parent3671506ad39d2a956e388e151bd20f1b9ffd62a5 (diff)
ecore-buffer: Add ecore_buffer library to EFL.
Summary: Ecore_Buffer is abstraction of graphic buffer. it supports backend of shm, x11_dri2 and x11_dri3 for now, and this library also provides method to share buffers between processes. Ecore_Buffer_Provider and Ecore_Buffer_Consumer is for this, sharing buffer. provider draws something in to Ecore_Buffer, and consumer receives and displays it. the binary, bq_mgr is a connection maker for buffer provider and consumer. it can be included Enlightenment as a deamon later. @feature Test Plan: 1. Configure with --enable-ecore-buffer and --enable-always-build-examples to build examples. 2. Run bq_mgr, it connects consumer and provider. 3. Run ecore_buffer_provider_example and ecore_buffer_consumer_example Reviewers: lsj119, gwanglim, cedric, zmike, jpeg, raster, devilhorns Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2197
Diffstat (limited to 'src/lib/ecore_buffer/buffer_queue.c')
-rw-r--r--src/lib/ecore_buffer/buffer_queue.c153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/lib/ecore_buffer/buffer_queue.c b/src/lib/ecore_buffer/buffer_queue.c
new file mode 100644
index 0000000000..241c8396c8
--- /dev/null
+++ b/src/lib/ecore_buffer/buffer_queue.c
@@ -0,0 +1,153 @@
1#include "buffer_queue.h"
2
3struct _Ecore_Buffer_Queue
4{
5 int w, h;
6 Eina_List *shared_buffers;
7 Eina_Bool connected;
8 struct
9 {
10 unsigned int capacity;
11 Eina_List *list;
12 } queue;
13};
14
15static Eina_Bool
16_queue_is_full(Ecore_Buffer_Queue *ebq)
17{
18 return (eina_list_count(ebq->queue.list) == ebq->queue.capacity);
19}
20
21static Eina_Bool
22_queue_is_empty(Ecore_Buffer_Queue *ebq)
23{
24 return (eina_list_count(ebq->queue.list) == 0);
25}
26
27Ecore_Buffer_Queue *
28_ecore_buffer_queue_new(int w, int h, int queue_size)
29{
30 Ecore_Buffer_Queue *ebq;
31
32 if (queue_size < 1) return NULL;
33
34 ebq = calloc(1, sizeof(Ecore_Buffer_Queue));
35 if (!ebq)
36 return NULL;
37
38 ebq->w = w;
39 ebq->h = h;
40 ebq->queue.capacity = queue_size;
41
42 return ebq;
43}
44
45void
46_ecore_buffer_queue_free(Ecore_Buffer_Queue *ebq)
47{
48 if (!ebq) return;
49
50 if (ebq->shared_buffers) eina_list_free(ebq->shared_buffers);
51 if (ebq->queue.list) eina_list_free(ebq->queue.list);
52 free(ebq);
53}
54
55void
56_ecore_buffer_queue_enqueue(Ecore_Buffer_Queue *ebq, Shared_Buffer *sb)
57{
58 if (!ebq) return;
59 if (_queue_is_full(ebq)) return;
60
61 if (!eina_list_data_find(ebq->shared_buffers, sb))
62 {
63 WARN("Couldn't enqueue not shared buffer.");
64 return;
65 }
66
67 ebq->queue.list = eina_list_prepend(ebq->queue.list, sb);
68}
69
70Eina_Bool
71_ecore_buffer_queue_dequeue(Ecore_Buffer_Queue *ebq, Shared_Buffer **ret_sb)
72{
73 Eina_List *last;
74 Shared_Buffer *sb;
75
76 if (!ebq) return EINA_FALSE;
77 if (_queue_is_empty(ebq)) return EINA_FALSE;
78
79 sb = eina_list_last_data_get(ebq->queue.list);
80 last = eina_list_last(ebq->queue.list);
81 ebq->queue.list = eina_list_remove_list(ebq->queue.list, last);
82
83 if (ret_sb) *ret_sb = sb;
84
85 return EINA_TRUE;
86}
87
88Eina_Bool
89_ecore_buffer_queue_is_empty(Ecore_Buffer_Queue *ebq)
90{
91 if (!ebq) return EINA_FALSE;
92
93 return _queue_is_empty(ebq);
94}
95
96void
97_ecore_buffer_queue_shared_buffer_add(Ecore_Buffer_Queue *ebq, Shared_Buffer *sb)
98{
99 if (!ebq) return;
100
101 ebq->shared_buffers = eina_list_append(ebq->shared_buffers, sb);
102}
103
104void
105_ecore_buffer_queue_shared_buffer_remove(Ecore_Buffer_Queue *ebq, Shared_Buffer *sb)
106{
107 if (!ebq) return;
108
109 ebq->shared_buffers = eina_list_remove(ebq->shared_buffers, sb);
110 while (eina_list_data_find(ebq->queue.list, sb) != NULL)
111 ebq->queue.list = eina_list_remove(ebq->queue.list, sb);
112}
113
114Shared_Buffer *
115_ecore_buffer_queue_shared_buffer_find(Ecore_Buffer_Queue *ebq, Ecore_Buffer *buffer)
116{
117 Eina_List *l;
118 Shared_Buffer *sb;
119
120 if (!ebq) return NULL;
121
122 EINA_LIST_FOREACH(ebq->shared_buffers, l, sb)
123 {
124 if (_shared_buffer_buffer_get(sb) == buffer)
125 return sb;
126 }
127
128 return NULL;
129}
130
131Eina_List *
132_ecore_buffer_queue_shared_buffer_list_get(Ecore_Buffer_Queue *ebq)
133{
134 if (!ebq) return NULL;
135
136 return ebq->shared_buffers;
137}
138
139void
140_ecore_buffer_queue_connection_state_set(Ecore_Buffer_Queue *ebq, Eina_Bool connect)
141{
142 if (!ebq) return;
143
144 ebq->connected = connect;
145}
146
147Eina_Bool
148_ecore_buffer_queue_connection_state_get(Ecore_Buffer_Queue *ebq)
149{
150 if (!ebq) return EINA_FALSE;
151
152 return ebq->connected;
153}