summaryrefslogtreecommitdiff
path: root/src/lib/ecore_buffer
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
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')
-rw-r--r--src/lib/ecore_buffer/Ecore_Buffer.h629
-rw-r--r--src/lib/ecore_buffer/Ecore_Buffer_Queue.h449
-rw-r--r--src/lib/ecore_buffer/bq_mgr_protocol.c131
-rw-r--r--src/lib/ecore_buffer/bq_mgr_protocol.h329
-rw-r--r--src/lib/ecore_buffer/buffer_queue.c153
-rw-r--r--src/lib/ecore_buffer/buffer_queue.h23
-rw-r--r--src/lib/ecore_buffer/ecore_buffer.c491
-rw-r--r--src/lib/ecore_buffer/ecore_buffer_con.c253
-rw-r--r--src/lib/ecore_buffer/ecore_buffer_con.h20
-rw-r--r--src/lib/ecore_buffer/ecore_buffer_consumer.c417
-rw-r--r--src/lib/ecore_buffer/ecore_buffer_private.h31
-rw-r--r--src/lib/ecore_buffer/ecore_buffer_provider.c391
-rw-r--r--src/lib/ecore_buffer/ecore_buffer_queue_main.c54
-rw-r--r--src/lib/ecore_buffer/shared_buffer.c148
-rw-r--r--src/lib/ecore_buffer/shared_buffer.h41
15 files changed, 3560 insertions, 0 deletions
diff --git a/src/lib/ecore_buffer/Ecore_Buffer.h b/src/lib/ecore_buffer/Ecore_Buffer.h
new file mode 100644
index 0000000000..36c82daad7
--- /dev/null
+++ b/src/lib/ecore_buffer/Ecore_Buffer.h
@@ -0,0 +1,629 @@
1#ifndef _ECORE_BUFFER_H_
2# define _ECORE_BUFFER_H_
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef _WIN32
9# ifdef EFL_ECORE_BUFFER_BUILD
10# ifdef DLL_EXPORT
11# define EAPI __declspec(dllexport)
12# else
13# define EAPI
14# endif /* ! DLL_EXPORT */
15# else
16# define EAPI __declspec(dllimport)
17# endif /* ! EFL_ECORE_BUFFER_BUILD */
18#else
19# ifdef __GNUC__
20# if __GNUC__ >= 4
21# define EAPI __attribute__ ((visibility("default")))
22# else
23# define EAPI
24# endif
25# else
26# define EAPI
27# endif
28#endif /* ! _WIN32 */
29
30/**
31 * @defgroup Ecore_Buffer_Group Ecore_Buffer - Graphics buffer functions
32 * @ingroup Ecore
33 *
34 * The Ecore Buffer is an abstraction of graphic buffer.
35 *
36 * This library also provides simple mechanisms for sharing graphic buffer bet-
37 * ween processes using wayland socket. Ecore Buffer Queue is for this
38 * function, and it consists of two main object,
39 * The Ecore_Buffer_Consumer and the Ecore_Buffer_Provider.
40 */
41
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#define __ecore_buffer_fourcc_code(a,b,c,d) ((unsigned int)(a) | ((unsigned int)(b) << 8) | \
47 ((unsigned int)(c) << 16) | ((unsigned int)(d) << 24))
48
49/* color index */
50/**
51 * @brief Definition for the Ecore_Buffer format C8 ([7:0] C).
52 * @since 1.15
53 */
54#define ECORE_BUFFER_FORMAT_C8 __ecore_buffer_fourcc_code('C', '8', ' ', ' ')
55/* 8 bpp RGB */
56/**
57 * @brief Definition for the Ecore_Buffer format RGB332 ([7:0] R:G:B 3:3:2).
58 * @since 1.15
59 */
60#define ECORE_BUFFER_FORMAT_RGB332 __ecore_buffer_fourcc_code('R', 'G', 'B', '8')
61/**
62 * @brief Definition for the Ecore_Buffer format RGB233 ([7:0] B:G:R 2:3:3).
63 * @since 1.15
64 */
65#define ECORE_BUFFER_FORMAT_BGR233 __ecore_buffer_fourcc_code('B', 'G', 'R', '8')
66/* 16 bpp RGB */
67/**
68 * @brief Definition for the Ecore_Buffer format XRGB4444 ([15:0] x:R:G:B 4:4:4:4 little endian).
69 * @since 1.15
70 */
71#define ECORE_BUFFER_FORMAT_XRGB4444 __ecore_buffer_fourcc_code('X', 'R', '1', '2')
72/**
73 * @brief Definition for the Ecore_Buffer format XBRG4444 ([15:0] x:B:G:R 4:4:4:4 little endian).
74 * @since 1.15
75 */
76#define ECORE_BUFFER_FORMAT_XBGR4444 __ecore_buffer_fourcc_code('X', 'B', '1', '2')
77/**
78 * @brief Definition for the Ecore_Buffer format RGBX4444 ([15:0] R:G:B:x 4:4:4:4 little endian).
79 * @since 1.15
80 */
81#define ECORE_BUFFER_FORMAT_RGBX4444 __ecore_buffer_fourcc_code('R', 'X', '1', '2')
82/**
83 * @brief Definition for the Ecore_Buffer format BGRX4444 ([15:0] B:G:R:x 4:4:4:4 little endian).
84 * @since 1.15
85 */
86#define ECORE_BUFFER_FORMAT_BGRX4444 __ecore_buffer_fourcc_code('B', 'X', '1', '2')
87/**
88 * @brief Definition for the Ecore_Buffer format ARGB4444 ([15:0] A:R:G:B 4:4:4:4 little endian).
89 * @since 1.15
90 */
91#define ECORE_BUFFER_FORMAT_ARGB4444 __ecore_buffer_fourcc_code('A', 'R', '1', '2')
92/**
93 * @brief Definition for the Ecore_Buffer format ABGR4444 ([15:0] A:B:G:R 4:4:4:4 little endian).
94 * @since 1.15
95 */
96#define ECORE_BUFFER_FORMAT_ABGR4444 __ecore_buffer_fourcc_code('A', 'B', '1', '2')
97/**
98 * @brief Definition for the Ecore_Buffer format RGBA4444 ([15:0] R:G:B:A 4:4:4:4 little endian).
99 * @since 1.15
100 */
101#define ECORE_BUFFER_FORMAT_RGBA4444 __ecore_buffer_fourcc_code('R', 'A', '1', '2')
102/**
103 * @brief Definition for the Ecore_Buffer format BGRA4444 ([15:0] B:G:R:A 4:4:4:4 little endian).
104 * @since 1.15
105 */
106#define ECORE_BUFFER_FORMAT_BGRA4444 __ecore_buffer_fourcc_code('B', 'A', '1', '2')
107/**
108 * @brief Definition for the Ecore_Buffer format XRGB1555 ([15:0] x:R:G:B 1:5:5:5 little endian).
109 * @since 1.15
110 */
111#define ECORE_BUFFER_FORMAT_XRGB1555 __ecore_buffer_fourcc_code('X', 'R', '1', '5')
112/**
113 * @brief Definition for the Ecore_Buffer format XBGR1555 ([15:0] x:B:G:R 1:5:5:5 little endian).
114 * @since 1.15
115 */
116#define ECORE_BUFFER_FORMAT_XBGR1555 __ecore_buffer_fourcc_code('X', 'B', '1', '5')
117/**
118 * @brief Definition for the Ecore_Buffer format RGBX5551 ([15:0] R:G:B:x 5:5:5:1 little endian).
119 * @since 1.15
120 */
121#define ECORE_BUFFER_FORMAT_RGBX5551 __ecore_buffer_fourcc_code('R', 'X', '1', '5')
122/**
123 * @brief Definition for the Ecore_Buffer format BGRX5551 ([15:0] B:G:R:x 5:5:5:1 little endian).
124 * @since 1.15
125 */
126#define ECORE_BUFFER_FORMAT_BGRX5551 __ecore_buffer_fourcc_code('B', 'X', '1', '5')
127/**
128 * @brief Definition for the Ecore_Buffer format ARGB1555 ([15:0] A:R:G:B 1:5:5:5 little endian).
129 * @since 1.15
130 */
131#define ECORE_BUFFER_FORMAT_ARGB1555 __ecore_buffer_fourcc_code('A', 'R', '1', '5')
132/**
133 * @brief Definition for the Ecore_Buffer format ABGR1555 ([15:0] A:B:G:R 1:5:5:5 little endian).
134 * @since 1.15
135 */
136#define ECORE_BUFFER_FORMAT_ABGR1555 __ecore_buffer_fourcc_code('A', 'B', '1', '5')
137/**
138 * @brief Definition for the Ecore_Buffer format RGBA5551 ([15:0] R:G:B:A 5:5:5:1 little endian).
139 * @since 1.15
140 */
141#define ECORE_BUFFER_FORMAT_RGBA5551 __ecore_buffer_fourcc_code('R', 'A', '1', '5')
142/**
143 * @brief Definition for the Ecore_Buffer format BGRA5551 ([15:0] B:G:R:A 5:5:5:1 little endian).
144 * @since 1.15
145 */
146#define ECORE_BUFFER_FORMAT_BGRA5551 __ecore_buffer_fourcc_code('B', 'A', '1', '5')
147/**
148 * @brief Definition for the Ecore_Buffer format RGB565 ([15:0] R:G:B 5:6:5 little endian).
149 * @since 1.15
150 */
151#define ECORE_BUFFER_FORMAT_RGB565 __ecore_buffer_fourcc_code('R', 'G', '1', '6')
152/**
153 * @brief Definition for the Ecore_Buffer format BGR565 ([15:0] B:G:R 5:6:5 little endian).
154 * @since 1.15
155 */
156#define ECORE_BUFFER_FORMAT_BGR565 __ecore_buffer_fourcc_code('B', 'G', '1', '6')
157/* 24 bpp RGB */
158/**
159 * @brief Definition for the Ecore_Buffer format RGB888 ([23:0] R:G:B little endian).
160 * @since 1.15
161 */
162#define ECORE_BUFFER_FORMAT_RGB888 __ecore_buffer_fourcc_code('R', 'G', '2', '4')
163/**
164 * @brief Definition for the Ecore_Buffer format BGR888 ([23:0] B:G:R little endian).
165 * @since 1.15
166 */
167#define ECORE_BUFFER_FORMAT_BGR888 __ecore_buffer_fourcc_code('B', 'G', '2', '4')
168/* 32 bpp RGB */
169/**
170 * @brief Definition for the Ecore_Buffer format XRGB8888 ([31:0] x:R:G:B 8:8:8:8 little endian).
171 * @since 1.15
172 */
173#define ECORE_BUFFER_FORMAT_XRGB8888 __ecore_buffer_fourcc_code('X', 'R', '2', '4')
174/**
175 * @brief Definition for the Ecore_Buffer format XBGR8888 ([31:0] x:B:G:R 8:8:8:8 little endian).
176 * @since 1.15
177 */
178#define ECORE_BUFFER_FORMAT_XBGR8888 __ecore_buffer_fourcc_code('X', 'B', '2', '4')
179/**
180 * @brief Definition for the Ecore_Buffer format RGBX8888 ([31:0] R:G:B:x 8:8:8:8 little endian).
181 * @since 1.15
182 */
183#define ECORE_BUFFER_FORMAT_RGBX8888 __ecore_buffer_fourcc_code('R', 'X', '2', '4')
184/**
185 * @brief Definition for the Ecore_Buffer format BGRX8888 ([31:0] B:G:R:x 8:8:8:8 little endian).
186 * @since 1.15
187 */
188#define ECORE_BUFFER_FORMAT_BGRX8888 __ecore_buffer_fourcc_code('B', 'X', '2', '4')
189/**
190 * @brief Definition for the Ecore_Buffer format ARGB8888 ([31:0] A:R:G:B 8:8:8:8 little endian).
191 * @since 1.15
192 */
193#define ECORE_BUFFER_FORMAT_ARGB8888 __ecore_buffer_fourcc_code('A', 'R', '2', '4')
194/**
195 * @brief Definition for the Ecore_Buffer format ABGR8888 ([31:0] [31:0] A:B:G:R 8:8:8:8 little endian).
196 * @since 1.15
197 */
198#define ECORE_BUFFER_FORMAT_ABGR8888 __ecore_buffer_fourcc_code('A', 'B', '2', '4')
199/**
200 * @brief Definition for the Ecore_Buffer format RGBA8888 ([31:0] R:G:B:A 8:8:8:8 little endian).
201 * @since 1.15
202 */
203#define ECORE_BUFFER_FORMAT_RGBA8888 __ecore_buffer_fourcc_code('R', 'A', '2', '4')
204/**
205 * @brief Definition for the Ecore_Buffer format BGRA8888 ([31:0] B:G:R:A 8:8:8:8 little endian).
206 * @since 1.15
207 */
208#define ECORE_BUFFER_FORMAT_BGRA8888 __ecore_buffer_fourcc_code('B', 'A', '2', '4')
209/**
210 * @brief Definition for the Ecore_Buffer format XRGB2101010 ([31:0] x:R:G:B 2:10:10:10 little endian).
211 * @since 1.15
212 */
213#define ECORE_BUFFER_FORMAT_XRGB2101010 __ecore_buffer_fourcc_code('X', 'R', '3', '0')
214/**
215 * @brief Definition for the Ecore_Buffer format XBGR2101010 ([31:0] x:B:G:R 2:10:10:10 little endian).
216 * @since 1.15
217 */
218#define ECORE_BUFFER_FORMAT_XBGR2101010 __ecore_buffer_fourcc_code('X', 'B', '3', '0')
219/**
220 * @brief Definition for the Ecore_Buffer format RGBX1010102 ([31:0] R:G:B:x 10:10:10:2 little endian).
221 * @since 1.15
222 */
223#define ECORE_BUFFER_FORMAT_RGBX1010102 __ecore_buffer_fourcc_code('R', 'X', '3', '0')
224/**
225 * @brief Definition for the Ecore_Buffer format BGRX1010102 ([31:0] B:G:R:x 10:10:10:2 little endian).
226 * @since 1.15
227 */
228#define ECORE_BUFFER_FORMAT_BGRX1010102 __ecore_buffer_fourcc_code('B', 'X', '3', '0')
229/**
230 * @brief Definition for the Ecore_Buffer format ARGB2101010 ([31:0] A:R:G:B 2:10:10:10 little endian).
231 * @since 1.15
232 */
233#define ECORE_BUFFER_FORMAT_ARGB2101010 __ecore_buffer_fourcc_code('A', 'R', '3', '0')
234/**
235 * @brief Definition for the Ecore_Buffer format ABGR2101010 ([31:0] A:B:G:R 2:10:10:10 little endian).
236 * @since 1.15
237 */
238#define ECORE_BUFFER_FORMAT_ABGR2101010 __ecore_buffer_fourcc_code('A', 'B', '3', '0')
239/**
240 * @brief Definition for the Ecore_Buffer format RGBA1010102 ([31:0] R:G:B:A 10:10:10:2 little endian).
241 * @since 1.15
242 */
243#define ECORE_BUFFER_FORMAT_RGBA1010102 __ecore_buffer_fourcc_code('R', 'A', '3', '0')
244/**
245 * @brief Definition for the Ecore_Buffer format BGRA1010102 ([31:0] B:G:R:A 10:10:10:2 little endian).
246 * @since 1.15
247 */
248#define ECORE_BUFFER_FORMAT_BGRA1010102 __ecore_buffer_fourcc_code('B', 'A', '3', '0')
249/* packed YCbCr */
250/**
251 * @brief Definition for the Ecore_Buffer format YUYV ([31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian).
252 * @since 1.15
253 */
254#define ECORE_BUFFER_FORMAT_YUYV __ecore_buffer_fourcc_code('Y', 'U', 'Y', 'V')
255/**
256 * @brief Definition for the Ecore_Buffer format YVYU ([31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian).
257 * @since 1.15
258 */
259#define ECORE_BUFFER_FORMAT_YVYU __ecore_buffer_fourcc_code('Y', 'V', 'Y', 'U')
260/**
261 * @brief Definition for the Ecore_Buffer format UYVY ([31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian).
262 * @since 1.15
263 */
264#define ECORE_BUFFER_FORMAT_UYVY __ecore_buffer_fourcc_code('U', 'Y', 'V', 'Y')
265/**
266 * @brief Definition for the Ecore_Buffer format VYUY ([31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian).
267 * @since 1.15
268 */
269#define ECORE_BUFFER_FORMAT_VYUY __ecore_buffer_fourcc_code('V', 'Y', 'U', 'Y')
270/**
271 * @brief Definition for the Ecore_Buffer format AYUV ([31:0] A:Y:Cb:Cr 8:8:8:8 little endian).
272 * @since 1.15
273 */
274#define ECORE_BUFFER_FORMAT_AYUV __ecore_buffer_fourcc_code('A', 'Y', 'U', 'V')
275/*
276 * 2 plane YCbCr
277 * index 0 = Y plane, [7:0] Y
278 * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
279 * or
280 * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
281 */
282/**
283 * @brief Definition for the Ecore_Buffer format NV12 (2x2 subsampled Cr:Cb plane).
284 * @since 1.15
285 */
286#define ECORE_BUFFER_FORMAT_NV12 __ecore_buffer_fourcc_code('N', 'V', '1', '2')
287/**
288 * @brief Definition for the Ecore_Buffer format NV21 (2x2 subsampled Cb:Cr plane).
289 * @since 1.15
290 */
291#define ECORE_BUFFER_FORMAT_NV21 __ecore_buffer_fourcc_code('N', 'V', '2', '1')
292/**
293 * @brief Definition for the Ecore_Buffer format NV16 (2x1 subsampled Cr:Cb plane).
294 * @since 1.15
295 */
296#define ECORE_BUFFER_FORMAT_NV16 __ecore_buffer_fourcc_code('N', 'V', '1', '6')
297/**
298 * @brief Definition for the Ecore_Buffer format NV61 (2x1 subsampled Cb:Cr plane).
299 * @since 1.15
300 */
301#define ECORE_BUFFER_FORMAT_NV61 __ecore_buffer_fourcc_code('N', 'V', '6', '1')
302/*
303 * 3 plane YCbCr
304 * index 0: Y plane, [7:0] Y
305 * index 1: Cb plane, [7:0] Cb
306 * index 2: Cr plane, [7:0] Cr
307 * or
308 * index 1: Cr plane, [7:0] Cr
309 * index 2: Cb plane, [7:0] Cb
310 */
311/**
312 * @brief Definition for the Ecore_Buffer format YUV410 (4x4 subsampled Cb (1) and Cr (2) planes).
313 */
314#define ECORE_BUFFER_FORMAT_YUV410 __ecore_buffer_fourcc_code('Y', 'U', 'V', '9')
315/**
316 * @brief Definition for the Ecore_Buffer format YVU410 (4x4 subsampled Cr (1) and Cb (2) planes).
317 * @since 1.15
318 */
319#define ECORE_BUFFER_FORMAT_YVU410 __ecore_buffer_fourcc_code('Y', 'V', 'U', '9')
320/**
321 * @brief Definition for the Ecore_Buffer format YUV411 (4x1 subsampled Cb (1) and Cr (2) planes).
322 * @since 1.15
323 */
324#define ECORE_BUFFER_FORMAT_YUV411 __ecore_buffer_fourcc_code('Y', 'U', '1', '1')
325/**
326 * @brief Definition for the Ecore_Buffer format YVU411 (4x1 subsampled Cr (1) and Cb (2) planes).
327 * @since 1.15
328 */
329#define ECORE_BUFFER_FORMAT_YVU411 __ecore_buffer_fourcc_code('Y', 'V', '1', '1')
330/**
331 * @brief Definition for the Ecore_Buffer format YUV420 (2x2 subsampled Cb (1) and Cr (2) planes).
332 * @since 1.15
333 */
334#define ECORE_BUFFER_FORMAT_YUV420 __ecore_buffer_fourcc_code('Y', 'U', '1', '2')
335/**
336 * @brief Definition for the Ecore_Buffer format YVU420 (2x2 subsampled Cr (1) and Cb (2) planes).
337 * @since 1.15
338 */
339#define ECORE_BUFFER_FORMAT_YVU420 __ecore_buffer_fourcc_code('Y', 'V', '1', '2')
340/**
341 * @brief Definition for the Ecore_Buffer format YUV422 (2x1 subsampled Cb (1) and Cr (2) planes).
342 * @since 1.15
343 */
344#define ECORE_BUFFER_FORMAT_YUV422 __ecore_buffer_fourcc_code('Y', 'U', '1', '6')
345/**
346 * @brief Definition for the Ecore_Buffer format YVU422 (2x1 subsampled Cr (1) and Cb (2) planes).
347 * @since 1.15
348 */
349#define ECORE_BUFFER_FORMAT_YVU422 __ecore_buffer_fourcc_code('Y', 'V', '1', '6')
350/**
351 * @brief Definition for the Ecore_Buffer format YUV444 (non-subsampled Cb (1) and Cr (2) planes).
352 * @since 1.15
353 */
354#define ECORE_BUFFER_FORMAT_YUV444 __ecore_buffer_fourcc_code('Y', 'U', '2', '4')
355/**
356 * @brief Definition for the Ecore_Buffer format YVU444 (non-subsampled Cr (1) and Cb (2) planes).
357 * @since 1.15
358 */
359#define ECORE_BUFFER_FORMAT_YVU444 __ecore_buffer_fourcc_code('Y', 'V', '2', '4')
360
361/**
362 * @defgroup Ecore_Buffer_Lib_Group Ecore Buffer Library Functions
363 * @ingroup Ecore_Buffer_Group
364 *
365 * Utility functions that set up and shut down the Ecore Buffer library.
366 * This group of functions is applied to an Ecore_Buffer object.
367 *
368 * @{
369 */
370
371/**
372 * @typedef Ecore_Buffer
373 * An object representing a graphic buffer.
374 * @since 1.15
375 */
376typedef struct _Ecore_Buffer Ecore_Buffer;
377/**
378 * @typedef Ecore_Buffer_Backend
379 * The interfaces for backend of buffer.
380 * @since 1.15
381 */
382typedef struct _Ecore_Buffer_Backend Ecore_Buffer_Backend;
383/**
384 * @typedef Ecore_Export_Type
385 * Types for export buffer.
386 * @since 1.15
387 */
388typedef enum _Ecore_Export_Type Ecore_Export_Type;
389/**
390 * @typedef Ecore_Buffer_Format
391 * The format of Ecore_Buffer.
392 * @since 1.15
393 */
394typedef unsigned int Ecore_Buffer_Format;
395/**
396 * @typedef Ecore_Buffer_Pixmap
397 * An Id of Pixmap.
398 * @since 1.15
399 */
400typedef unsigned long Ecore_Pixmap;
401/**
402 * @typedef Ecore_Buffer_Module_Data
403 * The data of module.
404 * @since 1.15
405 */
406typedef void* Ecore_Buffer_Module_Data;
407/**
408 * @typedef Ecore_Buffer_Data
409 * The data of Ecore_Buffer.
410 * @since 1.15
411 */
412typedef void* Ecore_Buffer_Data;
413/**
414 * @typedef Ecore_Buffer_Cb
415 * Called whenever Ecore_Buffer is freed.
416 * @since 1.15
417 */
418typedef void (*Ecore_Buffer_Cb)(Ecore_Buffer* buf, void* data);
419
420/**
421 * @enum _Ecore_Export_Type
422 * Types for export buffer.
423 * @since 1.15
424 */
425enum _Ecore_Export_Type
426{
427 EXPORT_TYPE_INVALID,
428 EXPORT_TYPE_ID,
429 EXPORT_TYPE_FD
430};
431
432/**
433 * @struct _Ecore_Buffer_Backend
434 * @brief Structure used when initializing Ecore Buffer Backend. This structure
435 * is mainly used by modules implementing the Ecore Buffer Backend interface.
436 * @since 1.15
437 */
438struct _Ecore_Buffer_Backend
439{
440 const char *name; /**< The name of backend */
441
442 Ecore_Buffer_Module_Data (*init)(const char *context, const char *options); /**< Initialize the backend */
443 void (*shutdown)(Ecore_Buffer_Module_Data bmdata); /**< Shut down the backend */
444 Ecore_Buffer_Data (*buffer_alloc)(Ecore_Buffer_Module_Data bmdata,
445 int width, int height,
446 Ecore_Buffer_Format format,
447 unsigned int flags); /**< Newly allocate memory for buffer */
448 void (*buffer_free)(Ecore_Buffer_Module_Data bmdata,
449 Ecore_Buffer_Data bdata); /**< Free allocated memory */
450 Ecore_Export_Type (*buffer_export)(Ecore_Buffer_Module_Data bmdata,
451 Ecore_Buffer_Data bdata, int *id); /**< Get the id or fd of Ecore_Buffer for exporting it */
452 Ecore_Buffer_Data (*buffer_import)(Ecore_Buffer_Module_Data bmdata,
453 int w, int h,
454 Ecore_Buffer_Format format,
455 Ecore_Export_Type type,
456 int export_id,
457 unsigned int flags); /**< Import and create Ecore_Buffer from id or fd */
458 void *(*data_get)(Ecore_Buffer_Module_Data bmdata,
459 Ecore_Buffer_Data bdata);
460 Ecore_Pixmap (*pixmap_get)(Ecore_Buffer_Module_Data bmdata,
461 Ecore_Buffer_Data bdata); /**< Get the pixmap handle */
462 void *(*tbm_surface_get)(Ecore_Buffer_Module_Data bmdata,
463 Ecore_Buffer_Data bdata); /**< Get the tbm_surface_h handle */
464};
465
466/**
467 * @brief Initialize the Ecore_Buffer system.
468 *
469 * @since 1.15
470 *
471 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
472 *
473 * @see ecore_buffer_shutdown()
474 */
475EAPI Eina_Bool ecore_buffer_init(void);
476/**
477 * @brief Shut down the Ecore_Buffer system.
478 *
479 * @since 1.15
480 *
481 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
482 *
483 * @see ecore_buffer_init()
484 */
485EAPI Eina_Bool ecore_buffer_shutdown(void);
486/**
487 * @brief Registers the given buffer backend.
488 *
489 * @since 1.15
490 *
491 * @param[in] be The backend
492 *
493 * @return @c EINA_TRUE if backend has been correctly registered, @c EINA_FALSE otherwise.
494 */
495EAPI Eina_Bool ecore_buffer_register(Ecore_Buffer_Backend *be);
496/**
497 * @brief Unregisters the given buffer backend.
498 *
499 * @since 1.15
500 *
501 * @param[in] be The backend
502 */
503EAPI void ecore_buffer_unregister(Ecore_Buffer_Backend *be);
504/**
505 * @brief Creates a new Ecore_Buffer given type
506 *
507 * @since 1.15
508 *
509 * @param[in] engine the name of backend
510 * @param[in] width width for Ecore_Buffer
511 * @param[in] height height for Ecore_Buffer
512 * @param[in] format format for Ecore_Buffer
513 * @param[in] flags flags for Ecore_Buffer
514 *
515 * @return Newly allocated Ecore_Buffer instance, NULL otherwise.
516 */
517EAPI Ecore_Buffer *ecore_buffer_new(const char *engine, unsigned int width, unsigned int height, Ecore_Buffer_Format format, unsigned int flags);
518/**
519 * @brief Free the given Ecore_Buffer.
520 *
521 * @since 1.15
522 *
523 * @param[in] buf The Ecore_Buffer to free
524 */
525EAPI void ecore_buffer_free(Ecore_Buffer *buf);
526/**
527 * @brief Set a callback for Ecore_Buffer free events.
528 *
529 * @since 1.15
530 *
531 * @param[in] buf The Ecore_Buffer to set callbacks on
532 * @param[in] func The function to call
533 * @param[in] data A pointer to the user data to store.
534 *
535 * A call to this function will set a callback on an Ecore_Buffer, causing
536 * @p func to be called whenever @p buf is freed.
537 *
538 * @see ecore_buffer_free_callback_remove()
539 */
540EAPI void ecore_buffer_free_callback_add(Ecore_Buffer *buf, Ecore_Buffer_Cb func, void *data);
541/**
542 * @brief Remove a callback for Ecore_Buffer free events.
543 *
544 * @since 1.15
545 *
546 * @param[in] buf The Ecore_Buffer to remove callbacks on
547 * @param[in] func The function to remove
548 * @param[in] data A pointer to the user data to remove
549 *
550 * @see ecore_buffer_free_callback_add()
551 */
552EAPI void ecore_buffer_free_callback_remove(Ecore_Buffer *buf, Ecore_Buffer_Cb func, void *data);
553/**
554 * @brief Get a pointer to the raw data of the given Ecore_Buffer.
555 *
556 * @param[in] buf The Ecore_Buffer.
557 *
558 * @return The pointer of raw data.
559 */
560EAPI void *ecore_buffer_data_get(Ecore_Buffer *buf);
561/**
562 * @brief Return the Pixmap of given Ecore_Buffer.
563 *
564 * @since 1.15
565 *
566 * @param[in] buf The Ecore_Buffer
567 *
568 * @return The Pixmap instance, 0 otherwise.
569 */
570EAPI Ecore_Pixmap ecore_buffer_pixmap_get(Ecore_Buffer *buf);
571/**
572 * @brief Return the tbm surface handle of given Ecore_Buffer.
573 *
574 * @since 1.15
575 *
576 * @param[in] buf The Ecore_Buffer
577 *
578 * @return The tbm surface handle, NULL otherwise.
579 *
580 * The tbm surface handle will be used for the API of libtbm.
581 * The API is described in tbm_surface.h in libtbm.
582 */
583EAPI void *ecore_buffer_tbm_surface_get(Ecore_Buffer *buf);
584/**
585 * @brief Return size of given Ecore_Buffer.
586 *
587 * @since 1.15
588 *
589 * @param[in] buf The Ecore_Buffer
590 * @param[out] width where to return the width value. May be @c NULL.
591 * @param[out] height where to return the height value. May be @c NULL.
592 *
593 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
594 */
595EAPI Eina_Bool ecore_buffer_size_get(Ecore_Buffer *buf, unsigned int *width, unsigned int *height);
596/**
597 * @brief Return format of given Ecore_Buffer.
598 *
599 * @since 1.15
600 *
601 * @param[in] buf The Ecore_Buffer
602 *
603 * @return The format of given Ecore_Buffer.
604 *
605 * return value can be one of those pre-defined value such as ECORE_BUFFER_FORMAT_XRGB8888.
606 */
607EAPI Ecore_Buffer_Format ecore_buffer_format_get(Ecore_Buffer *buf);
608/**
609 * @brief Return flags of given Ecore_Buffer.
610 *
611 * @since 1.15
612 *
613 * @param[in] buf The Ecore_Buffer
614 *
615 * @return The flags of given Ecore_Buffer.
616 *
617 * NOTE: Not Defined yet.
618 */
619EAPI unsigned int ecore_buffer_flags_get(Ecore_Buffer *buf);
620
621/**
622 * @}
623 */
624
625#ifdef __cplusplus
626}
627#endif
628
629#endif
diff --git a/src/lib/ecore_buffer/Ecore_Buffer_Queue.h b/src/lib/ecore_buffer/Ecore_Buffer_Queue.h
new file mode 100644
index 0000000000..81dad17976
--- /dev/null
+++ b/src/lib/ecore_buffer/Ecore_Buffer_Queue.h
@@ -0,0 +1,449 @@
1#ifndef _ECORE_BUFFER_QUEUE_H_
2#define _ECORE_BUFFER_QUEUE_H_
3
4#ifdef EAPI
5# undef EAPI
6#endif
7
8#ifdef _WIN32
9# ifdef EFL_ECORE_BUFFER_BUILD
10# ifdef DLL_EXPORT
11# define EAPI __declspec(dllexport)
12# else
13# define EAPI
14# endif /* ! DLL_EXPORT */
15# else
16# define EAPI __declspec(dllimport)
17# endif /* ! EFL_ECORE_BUFFER_BUILD */
18#else
19# ifdef __GNUC__
20# if __GNUC__ >= 4
21# define EAPI __attribute__ ((visibility("default")))
22# else
23# define EAPI
24# endif
25# else
26# define EAPI
27# endif
28#endif /* ! _WIN32 */
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include <Eina.h>
35#include "Ecore_Buffer.h"
36
37/**
38 * @defgroup Ecore_Buffer_Queue_Group Ecore Buffer Queue functions
39 * @ingroup Ecore_Buffer_Group
40 *
41 * Ecore Buffer Queue is a queue which conntects processes for sharing
42 * Ecore_Buffer.
43 * one process (related object is Ecore_Buffer_Provider) has rear terminal
44 * position of Ecore_Buffer Queue which can enqueue the Ecore_Buffer,
45 * and the other process (related object is Ecore_Buffer_Consumer) has front
46 * terminal position of Ecore_Buffer_Queue which can dequeue the Ecore_Buffer.
47 */
48
49/**
50 * @defgroup Ecore_Buffer_Provider_Group Ecore Buffer Provider functions
51 * @ingroup Ecore_Buffer_Queue_Group
52 *
53 * This group of functions is applied to an Ecore_Buffer_Provider object.
54 * Ecore_Buffer_Provider provides Ecore_Buffer to Ecore_Buffer_Consumer(usally
55 * different process or thread from Ecore_Buffer_Provider).
56 * Ecore_Buffer_Provider should creates Ecore_Buffer as a provider.
57 */
58
59/**
60 * @defgroup Ecore_Buffer_Consumer_Group Ecore Buffer Consumer functions
61 * @ingroup Ecore_Buffer_Queue_Group
62 *
63 * This group of functions is applied to an Ecore_Buffer_Consumer object.
64 * Ecore_Buffer_Consumer receives Ecore_Buffer enqueued by Ecore_Buffer_Provider.
65 * Consumer must release Ecore_Buffer when it's no longer used.
66 * Thus, the Ecore_Buffer_Provider is now free to re-use or destroy Ecore_Buffer.
67 */
68
69/**
70 * @typedef Ecore_Buffer_Return
71 * @enum _Ecore_Buffer_Return
72 * types for an buffer queue state on provider side.
73 * @ingroup Ecore_Buffer_Provider_Group
74 * @see ecore_buffer_provider_buffer_acquire()
75 * @see ecore_buffer_provider_buffer_acquirable_check()
76 */
77typedef enum _Ecore_Buffer_Return
78{
79 ECORE_BUFFER_RETURN_ERROR, /**< on error @since 1.15 */
80 ECORE_BUFFER_RETURN_SUCCESS, /**< success to dequeue a buffer @since 1.15 */
81 ECORE_BUFFER_RETURN_EMPTY, /**< Empty queue @since 1.15 */
82 ECORE_BUFFER_RETURN_NOT_EMPTY, /**< Not empty queue @since 1.15 */
83 ECORE_BUFFER_RETURN_NEED_ALLOC, /**< need to create Ecore_Buffer @since 1.15 */
84} Ecore_Buffer_Return;
85/**
86 * @typedef Ecore_Buffer_Consumer
87 * An object representing a consumer of Ecore_Buffer.
88 *
89 * @since 1.15
90 *
91 * @ingroup Ecore_Buffer_Consumer_Group
92 */
93typedef struct _Ecore_Buffer_Consumer Ecore_Buffer_Consumer;
94/**
95 * @typedef Ecore_Buffer_Provider
96 * An object representing a provider of Ecore_Buffer.
97 *
98 * @since 1.15
99 *
100 * @ingroup Ecore_Buffer_Provider_Group
101 */
102typedef struct _Ecore_Buffer_Provider Ecore_Buffer_Provider;
103/**
104 * @typedef Ecore_Buffer_Consumer_Provider_Add_Cb
105 *
106 * @brief Called whenever a Ecore_Buffer_Provider connected.
107 *
108 * @since 1.15
109 *
110 * @see ecore_buffer_consumer_provider_add_cb_set()
111 * @ingroup Ecore_Buffer_Consumer_Group
112 */
113typedef void (*Ecore_Buffer_Consumer_Provider_Add_Cb) (Ecore_Buffer_Consumer *consumer, void *data);
114/**
115 * @typedef Ecore_Buffer_Consumer_Provider_Del_Cb
116 *
117 * @brief Called whenever a Ecore_Buffer_Provider disonnected.
118 *
119 * @since 1.15
120 *
121 * @see ecore_buffer_consumer_provider_del_cb_set()
122 * @ingroup Ecore_Buffer_Consumer_Group
123 */
124typedef void (*Ecore_Buffer_Consumer_Provider_Del_Cb) (Ecore_Buffer_Consumer *consumer, void *data);
125/**
126 * @typedef Ecore_Buffer_Consumer_Enqueue_Cb
127 *
128 * @brief Called whenever a Ecore_Buffer enqueued in buffer queue.
129 *
130 * @since 1.15
131 *
132 * @see ecore_buffer_consumer_buffer_enqueued_cb_set()
133 * @ingroup Ecore_Buffer_Consumer_Group
134 */
135typedef void (*Ecore_Buffer_Consumer_Enqueue_Cb) (Ecore_Buffer_Consumer *consumer, void *data);
136/**
137 * @typedef Ecore_Buffer_Provider_Consumer_Add_Cb
138 *
139 * @brief Called whenever a Ecore_Buffer_Consumer connected.
140 *
141 * @since 1.15
142 *
143 * @see ecore_buffer_provider_consumer_add_cb_set()
144 * @ingroup Ecore_Buffer_Provider_Group
145 */
146typedef void (*Ecore_Buffer_Provider_Consumer_Add_Cb) (Ecore_Buffer_Provider *provider, int queue_size, int w, int h, void *data);
147/**
148 * @typedef Ecore_Buffer_Provider_Consumer_Del_Cb
149 *
150 * @brief Called whenever a Ecore_Buffer_Consumer disconnected.
151 *
152 * @since 1.15
153 *
154 * @see ecore_buffer_provider_consumer_del_cb_set()
155 * @ingroup Ecore_Buffer_Provider_Group
156 */
157typedef void (*Ecore_Buffer_Provider_Consumer_Del_Cb) (Ecore_Buffer_Provider *provider, void *data);
158/**
159 * @typedef Ecore_Buffer_Provider_Enqueue_Cb
160 *
161 * @brief Called whenever a Ecore_Buffer is released.
162 *
163 * @since 1.15
164 *
165 * @see ecore_buffer_provider_buffer_released_cb_set()
166 * @ingroup Ecore_Buffer_Provider_Group
167 */
168typedef void (*Ecore_Buffer_Provider_Enqueue_Cb) (Ecore_Buffer_Provider *provider, void *data);
169
170/**
171 * @addtogroup Ecore_Buffer_Queue_Group
172 * @{
173 */
174
175/**
176 * @brief Init the Ecore_Buffer_Queue system.
177 *
178 * @since 1.15
179 *
180 * @return How many times the lib has been initialized, 0 indicates failure.
181 *
182 * Set up the connection of Buffer Queue deamon, and Init Ecore_Buffer_Queue libraries.
183 *
184 * @see ecore_buffer_queue_shutdown()
185 */
186EAPI int ecore_buffer_queue_init(void);
187/**
188 * @brief Shut down the Ecore_Buffer_Queue system.
189 *
190 * @since 1.15
191 *
192 * this closes the connection of Buffer Queue deamon, and Shut down Ecore_Buffer_Queue libraries.
193 *
194 * @see ecore_buffer_queue_init()
195 */
196EAPI int ecore_buffer_queue_shutdown(void);
197
198/**
199 * @}
200 */
201
202/**
203 * @addtogroup Ecore_Buffer_Consumer_Group
204 * @{
205 */
206
207/**
208 * @brief Creates a new Buffer Consumer based on name and common parameters.
209 *
210 * @since 1.15
211 *
212 * @param[in] name the name of Buffer_Queue, this is needed by Consumer and Provider to connect each other.
213 * @param[in] queue_size size of Queue (If you pass this 0, then default size two(2) is appied)
214 * @param[in] w width of buffer recommeneded to provider.
215 * @param[in] h height of buffer recommended to provider.
216 *
217 * @return Ecore_Buffer_Consumer instance or @c NULL if creation failed.
218 */
219EAPI Ecore_Buffer_Consumer *ecore_buffer_consumer_new(const char *name, int32_t queue_size, int32_t w, int32_t h);
220/**
221 * @brief Free an Ecore_Buffer_Consumer
222 *
223 * @since 1.15
224 *
225 * @param[in] consumer The Ecore_Buffer_Consumer to free
226 *
227 * This frees up any memory used by the Ecore_Buffer_Consumer.
228 */
229EAPI void ecore_buffer_consumer_free(Ecore_Buffer_Consumer *consumer);
230/**
231 * @brief Return the latest Ecore_Buffer submitted by provider.
232 *
233 * @since 1.15
234 *
235 * @param[in] consumer The Ecore_Buffer_Consumer to request for buffer
236 *
237 * @return Ecore_Buffer handle or NULL if acquirement failed.
238 *
239 * @see ecore_buffer_consumer_buffer_release()
240 *
241 * Consumer can store Ecore_Buffer submitted by Provider as much as size of queue
242 * which is passed as a argument of ecore_buffer_consumer_new().
243 */
244EAPI Ecore_Buffer *ecore_buffer_consumer_buffer_dequeue(Ecore_Buffer_Consumer *consumer);
245/**
246 * @brief Release the acquired Ecore_Buffer.
247 *
248 * @since 1.15
249 *
250 * @param[in] consumer The Ecore_Buffer_Consumer to request release buffer
251 * @param[in] buffer The Ecore_Buffer to release
252 *
253 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
254 *
255 * @see ecore_buffer_consumer_buffer_dequeue()
256 *
257 * Consumer should release the Ecore_Buffer after acquiring and using it.
258 * By doing release, Ecore_Buffer will be used by provider again,
259 * or freed internally if Ecore_Buffer is not necessary anymore.
260 * If not, the resource of Ecore_Buffer is continually owned by consumer until released.
261 */
262EAPI Eina_Bool ecore_buffer_consumer_buffer_release(Ecore_Buffer_Consumer *consumer, Ecore_Buffer *buffer);
263/**
264 * @brief Check if Queue of Ecore_Buffer is empty.
265 *
266 * @since 1.15
267 *
268 * @param[in] consumer The Ecore_Buffer_Consumer to query
269 *
270 * @return @c EINA_TRUE means queue is empty, @c EINA_FALSE otherwise.
271 */
272EAPI Eina_Bool ecore_buffer_consumer_queue_is_empty(Ecore_Buffer_Consumer *consumer);
273/**
274 * @brief Set a callback for provider connection events.
275 *
276 * @since 1.15
277 *
278 * @param[in] consumer The Ecore_Buffer_Consumer to set callbacks on
279 * @param[in] func The function to call
280 * @param[in] data A pointer to the user data to store.
281 *
282 * A call to this function will set a callback on an Ecore_Buffer_Consumer, causing
283 * @p func to be called whenever @p consumer is connected with provider.
284 */
285EAPI void ecore_buffer_consumer_provider_add_cb_set(Ecore_Buffer_Consumer *consumer, Ecore_Buffer_Consumer_Provider_Add_Cb func, void *data);
286/**
287 * @brief Set a callback for provider disconnection events.
288 *
289 * @since 1.15
290 *
291 * @param[in] consumer The Ecore_Buffer_Consumer to set callbacks on
292 * @param[in] func The function to call
293 * @param[in] data A pointer to the user data to store.
294 *
295 * A call to this function will set a callback on an Ecore_Buffer_Consumer, causing
296 * @p func to be called whenever @p consumer is disconnected with provider.
297 */
298EAPI void ecore_buffer_consumer_provider_del_cb_set(Ecore_Buffer_Consumer *consumer, Ecore_Buffer_Consumer_Provider_Del_Cb func, void *data);
299/**
300 * @brief Set a callback for enqueued buffer events.
301 *
302 * @since 1.15
303 *
304 * @param[in] consumer The Ecore_Buffer_Consumer to set callbacks on
305 * @param[in] func The function to call
306 * @param[in] data A pointer to the user data to store.
307 *
308 * A call to this function will set a callback on an Ecore_Buffer_Consumer, causing
309 * @p func to be called whenever @p consumer has received buffer submitted from provider.
310 *
311 * You may success acuiqre Ecore_Buffer after this callback called.
312 */
313EAPI void ecore_buffer_consumer_buffer_enqueued_cb_set(Ecore_Buffer_Consumer *consumer, Ecore_Buffer_Consumer_Enqueue_Cb func, void *data);
314
315/**
316 * @}
317 */
318
319/**
320 * @addtogroup Ecore_Buffer_Provider_Group
321 * @{
322 */
323
324/**
325 * @brief Creates a new Buffer Provider based on name.
326 *
327 * @since 1.15
328 *
329 * @param[in] name the name of Buffer_Queue.
330 *
331 * @return Ecore_Buffer_Provider instance or @c NULL if creation failed.
332 */
333EAPI Ecore_Buffer_Provider *ecore_buffer_provider_new(const char *name);
334/**
335 * @brief Free an Ecore_Buffer_Provider
336 *
337 * @since 1.15
338 *
339 * @param[in] provider The Ecore_Buffer_Provider to free
340 *
341 * This frees up any memory used by the Ecore_Buffer_Provider.
342 */
343EAPI void ecore_buffer_provider_free(Ecore_Buffer_Provider *provider);
344/**
345 * @brief Return the Ecore_Buffer released by consumer or State of Queue.
346 *
347 * @since 1.15
348 *
349 * @param[in] provider The Ecore_Buffer_Provider to request for buffer
350 * @param[out] ret_buf A Pointer to the Ecore_Buffer
351 *
352 * @return The enumeration of Ecore_Buffer_Return to indicate result of Dequeueing.
353 *
354 * This function gives you drawable buffer and inform you the state of Queue.
355 * Each return value of enumeration has meaning as below.
356 * @li ECORE_BUFFER_RETURN_ERROR, means error occured.
357 * @li ECORE_BUFFER_RETURN_SUCCESS, means success to dequeue, therefore ret_buf is valid.
358 * @li ECORE_BUFFER_RETURN_EMPTY, means queue is empty, not available slot in Queue.
359 * in other words, there is no free drawable buffer in Queue.
360 * @li ECORE_BUFFER_RETURN_NEED_ALLOC, means that there is available slot, but not allocated.
361 * so, You may create new Ecore_Buffer, and then just enqueue the Ecore_Buffer.
362 *
363 * @see ecore_buffer_new(), ecore_buffer_provider_buffer_enqueue()
364 */
365EAPI Ecore_Buffer_Return ecore_buffer_provider_buffer_acquire(Ecore_Buffer_Provider *provider, Ecore_Buffer **ret_buf);
366/**
367 * @brief Submit the Ecore_Buffer to Consumer to request compositing.
368 *
369 * @since 1.15
370 *
371 * @param[in] provider The Ecore_Buffer_Provider connected with consumer.
372 * @param[in] buffer The Ecore_Buffer to submit
373 *
374 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
375 *
376 * This function allow you to submit the Ecore_Buffer to consumer to request compositing.
377 * And this will be success, in case only you submit dequeued Ecore_Buffer,
378 * and new Ecore_Buffer after received return value of ECORE_BUFFER_RETURN_NEED_ALLOC by ecore_buffer_provider_buffer_acquire().
379 *
380 * @see ecore_buffer_new(), ecore_buffer_provider_buffer_dequeue()
381 */
382EAPI Eina_Bool ecore_buffer_provider_buffer_enqueue(Ecore_Buffer_Provider *provider, Ecore_Buffer *buffer);
383/**
384 * @brief Check if state of queue.
385 *
386 * @since 1.15
387 *
388 * @param[in] provider The Ecore_Buffer_Provider to query
389 *
390 * @li ECORE_BUFFER_RETURN_NOT_EMPTY, means there is a dequeueable Ecore_Buffer at least one.
391 * @li ECORE_BUFFER_RETURN_EMPTY, means queue is empty, not available slot in Queue.
392 * in other words, there is no free drawable buffer in Queue.
393 * @li ECORE_BUFFER_RETURN_NEED_ALLOC, means that there is available slot, but not allocated.
394 * so, You may create new Ecore_Buffer, and then just enqueue the Ecore_Buffer.
395 *
396 * @return @c EINA_TRUE means queue is empty, @c EINA_FALSE otherwise.
397 */
398EAPI Ecore_Buffer_Return ecore_buffer_provider_buffer_acquirable_check(Ecore_Buffer_Provider *provider);
399/**
400 * @brief Set a callback for consumer connection events.
401 *
402 * @since 1.15
403 *
404 * @param[in] provider The Ecore_Buffer_Provider to set callbacks on
405 * @param[in] func The function to call
406 * @param[in] data A pointer to the user data to store.
407 *
408 * A call to this function will set a callback on an Ecore_Buffer_Provider, causing
409 * @p func to be called whenever @p provider is connected with consumer.
410 */
411EAPI void ecore_buffer_provider_consumer_add_cb_set(Ecore_Buffer_Provider *provider, Ecore_Buffer_Provider_Consumer_Add_Cb func, void *data);
412/**
413 * @brief Set a callback for consumer disconnection events.
414 *
415 * @since 1.15
416 *
417 * @param[in] provider The Ecore_Buffer_Provider to set callbacks on
418 * @param[in] func The function to call
419 * @param[in] data A pointer to the user data to store.
420 *
421 * A call to this function will set a callback on an Ecore_Buffer_Provider, causing
422 * @p func to be called whenever @p provider is disconnected with consumer.
423 */
424EAPI void ecore_buffer_provider_consumer_del_cb_set(Ecore_Buffer_Provider *provider, Ecore_Buffer_Provider_Consumer_Del_Cb func, void *data);
425/**
426 * @brief Set a callback for released buffer events.
427 *
428 * @since 1.15
429 *
430 * @param[in] provider The Ecore_Buffer_Provider to set callbacks on
431 * @param[in] func The function to call
432 * @param[in] data A pointer to the user data to store.
433 *
434 * A call to this function will set a callback on an Ecore_Buffer_Provider, causing
435 * @p func to be called whenever @p provider has received Ecore_Buffer released from provider.
436 *
437 * You may success dequeue the Ecore_Buffer after this callback called.
438 */
439EAPI void ecore_buffer_provider_buffer_released_cb_set(Ecore_Buffer_Provider *provider, Ecore_Buffer_Provider_Enqueue_Cb func, void *data);
440
441/**
442 * @}
443 */
444
445#ifdef __cplusplus
446}
447#endif
448
449#endif /* _ECORE_BUFFER_QUEUE_H_ */
diff --git a/src/lib/ecore_buffer/bq_mgr_protocol.c b/src/lib/ecore_buffer/bq_mgr_protocol.c
new file mode 100644
index 0000000000..fe8b98c9bc
--- /dev/null
+++ b/src/lib/ecore_buffer/bq_mgr_protocol.c
@@ -0,0 +1,131 @@
1#include <stdlib.h>
2#include <stdint.h>
3#include "wayland-util.h"
4
5extern const struct wl_interface bq_buffer_interface;
6extern const struct wl_interface bq_consumer_interface;
7extern const struct wl_interface bq_provider_interface;
8
9static const struct wl_interface *types[] = {
10 NULL,
11 NULL,
12 NULL,
13 &bq_consumer_interface,
14 NULL,
15 NULL,
16 NULL,
17 NULL,
18 &bq_provider_interface,
19 NULL,
20 &bq_buffer_interface,
21 &bq_buffer_interface,
22 NULL,
23 NULL,
24 NULL,
25 NULL,
26 NULL,
27 &bq_buffer_interface,
28 NULL,
29 NULL,
30 NULL,
31 NULL,
32 NULL,
33 NULL,
34 NULL,
35 &bq_buffer_interface,
36 NULL,
37 NULL,
38 NULL,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
43 &bq_buffer_interface,
44 &bq_buffer_interface,
45 NULL,
46 &bq_buffer_interface,
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL,
52 &bq_buffer_interface,
53 NULL,
54 NULL,
55 NULL,
56 NULL,
57 NULL,
58 NULL,
59 NULL,
60 &bq_buffer_interface,
61 NULL,
62 NULL,
63 NULL,
64 NULL,
65 NULL,
66 NULL,
67 NULL,
68 &bq_buffer_interface,
69 &bq_buffer_interface,
70 NULL,
71 &bq_buffer_interface,
72 NULL,
73};
74
75static const struct wl_message bq_mgr_requests[] = {
76 { "create_consumer", "nsiii", types + 3 },
77 { "create_provider", "ns", types + 8 },
78};
79
80WL_EXPORT const struct wl_interface bq_mgr_interface = {
81 "bq_mgr", 1,
82 2, bq_mgr_requests,
83 0, NULL,
84};
85
86static const struct wl_message bq_consumer_requests[] = {
87 { "release_buffer", "o", types + 10 },
88};
89
90static const struct wl_message bq_consumer_events[] = {
91 { "connected", "", types + 0 },
92 { "disconnected", "", types + 0 },
93 { "buffer_attached", "nsiiiu", types + 11 },
94 { "set_buffer_id", "oiiiiiii", types + 17 },
95 { "set_buffer_fd", "ohiiiiii", types + 25 },
96 { "buffer_detached", "o", types + 33 },
97 { "add_buffer", "ou", types + 34 },
98};
99
100WL_EXPORT const struct wl_interface bq_consumer_interface = {
101 "bq_consumer", 1,
102 1, bq_consumer_requests,
103 7, bq_consumer_events,
104};
105
106static const struct wl_message bq_provider_requests[] = {
107 { "attach_buffer", "nsiiiu", types + 36 },
108 { "set_buffer_id", "oiiiiiii", types + 42 },
109 { "set_buffer_fd", "ohiiiiii", types + 50 },
110 { "detach_buffer", "o", types + 58 },
111 { "enqueue_buffer", "ou", types + 59 },
112};
113
114static const struct wl_message bq_provider_events[] = {
115 { "connected", "iii", types + 0 },
116 { "disconnected", "", types + 0 },
117 { "add_buffer", "ou", types + 61 },
118};
119
120WL_EXPORT const struct wl_interface bq_provider_interface = {
121 "bq_provider", 1,
122 5, bq_provider_requests,
123 3, bq_provider_events,
124};
125
126WL_EXPORT const struct wl_interface bq_buffer_interface = {
127 "bq_buffer", 1,
128 0, NULL,
129 0, NULL,
130};
131
diff --git a/src/lib/ecore_buffer/bq_mgr_protocol.h b/src/lib/ecore_buffer/bq_mgr_protocol.h
new file mode 100644
index 0000000000..7cf9ad9380
--- /dev/null
+++ b/src/lib/ecore_buffer/bq_mgr_protocol.h
@@ -0,0 +1,329 @@
1#ifndef BQ_MGR_CLIENT_PROTOCOL_H
2#define BQ_MGR_CLIENT_PROTOCOL_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdint.h>
9#include <stddef.h>
10#include "wayland-client.h"
11
12struct wl_client;
13struct wl_resource;
14
15struct bq_mgr;
16struct bq_consumer;
17struct bq_provider;
18struct bq_buffer;
19
20extern const struct wl_interface bq_mgr_interface;
21extern const struct wl_interface bq_consumer_interface;
22extern const struct wl_interface bq_provider_interface;
23extern const struct wl_interface bq_buffer_interface;
24
25#ifndef BQ_MGR_ERROR_ENUM
26#define BQ_MGR_ERROR_ENUM
27enum bq_mgr_error {
28 BQ_MGR_ERROR_INVALID_PERMISSION = 0,
29 BQ_MGR_ERROR_INVALID_NAME = 1,
30 BQ_MGR_ERROR_ALREADY_USED = 2,
31};
32#endif /* BQ_MGR_ERROR_ENUM */
33
34#define BQ_MGR_CREATE_CONSUMER 0
35#define BQ_MGR_CREATE_PROVIDER 1
36
37static inline void
38bq_mgr_set_user_data(struct bq_mgr *bq_mgr, void *user_data)
39{
40 wl_proxy_set_user_data((struct wl_proxy *) bq_mgr, user_data);
41}
42
43static inline void *
44bq_mgr_get_user_data(struct bq_mgr *bq_mgr)
45{
46 return wl_proxy_get_user_data((struct wl_proxy *) bq_mgr);
47}
48
49static inline void
50bq_mgr_destroy(struct bq_mgr *bq_mgr)
51{
52 wl_proxy_destroy((struct wl_proxy *) bq_mgr);
53}
54
55static inline struct bq_consumer *
56bq_mgr_create_consumer(struct bq_mgr *bq_mgr, const char *name, int32_t queue_size, int32_t width, int32_t height)
57{
58 struct wl_proxy *id;
59
60 id = wl_proxy_marshal_constructor((struct wl_proxy *) bq_mgr,
61 BQ_MGR_CREATE_CONSUMER, &bq_consumer_interface, NULL, name, queue_size, width, height);
62
63 return (struct bq_consumer *) id;
64}
65
66static inline struct bq_provider *
67bq_mgr_create_provider(struct bq_mgr *bq_mgr, const char *name)
68{
69 struct wl_proxy *id;
70
71 id = wl_proxy_marshal_constructor((struct wl_proxy *) bq_mgr,
72 BQ_MGR_CREATE_PROVIDER, &bq_provider_interface, NULL, name);
73
74 return (struct bq_provider *) id;
75}
76
77struct bq_consumer_listener {
78 /**
79 * connected - (none)
80 */
81 void (*connected)(void *data,
82 struct bq_consumer *bq_consumer);
83 /**
84 * disconnected - (none)
85 */
86 void (*disconnected)(void *data,
87 struct bq_consumer *bq_consumer);
88 /**
89 * buffer_attached - (none)
90 * @buffer: (none)
91 * @engine: (none)
92 * @width: (none)
93 * @height: (none)
94 * @format: (none)
95 * @flags: (none)
96 */
97 void (*buffer_attached)(void *data,
98 struct bq_consumer *bq_consumer,
99 struct bq_buffer *buffer,
100 const char *engine,
101 int32_t width,
102 int32_t height,
103 int32_t format,
104 uint32_t flags);
105 /**
106 * set_buffer_id - (none)
107 * @buffer: (none)
108 * @id: (none)
109 * @offset0: (none)
110 * @stride0: (none)
111 * @offset1: (none)
112 * @stride1: (none)
113 * @offset2: (none)
114 * @stride2: (none)
115 */
116 void (*set_buffer_id)(void *data,
117 struct bq_consumer *bq_consumer,
118 struct bq_buffer *buffer,
119 int32_t id,
120 int32_t offset0,
121 int32_t stride0,
122 int32_t offset1,
123 int32_t stride1,
124 int32_t offset2,
125 int32_t stride2);
126 /**
127 * set_buffer_fd - (none)
128 * @buffer: (none)
129 * @fd: (none)
130 * @offset0: (none)
131 * @stride0: (none)
132 * @offset1: (none)
133 * @stride1: (none)
134 * @offset2: (none)
135 * @stride2: (none)
136 */
137 void (*set_buffer_fd)(void *data,
138 struct bq_consumer *bq_consumer,
139 struct bq_buffer *buffer,
140 int32_t fd,
141 int32_t offset0,
142 int32_t stride0,
143 int32_t offset1,
144 int32_t stride1,
145 int32_t offset2,
146 int32_t stride2);
147 /**
148 * buffer_detached - (none)
149 * @buffer: (none)
150 */
151 void (*buffer_detached)(void *data,
152 struct bq_consumer *bq_consumer,
153 struct bq_buffer *buffer);
154 /**
155 * add_buffer - (none)
156 * @buffer: (none)
157 * @serial: (none)
158 */
159 void (*add_buffer)(void *data,
160 struct bq_consumer *bq_consumer,
161 struct bq_buffer *buffer,
162 uint32_t serial);
163};
164
165static inline int
166bq_consumer_add_listener(struct bq_consumer *bq_consumer,
167 const struct bq_consumer_listener *listener, void *data)
168{
169 return wl_proxy_add_listener((struct wl_proxy *) bq_consumer,
170 (void (**)(void)) listener, data);
171}
172
173#define BQ_CONSUMER_RELEASE_BUFFER 0
174
175static inline void
176bq_consumer_set_user_data(struct bq_consumer *bq_consumer, void *user_data)
177{
178 wl_proxy_set_user_data((struct wl_proxy *) bq_consumer, user_data);
179}
180
181static inline void *
182bq_consumer_get_user_data(struct bq_consumer *bq_consumer)
183{
184 return wl_proxy_get_user_data((struct wl_proxy *) bq_consumer);
185}
186
187static inline void
188bq_consumer_destroy(struct bq_consumer *bq_consumer)
189{
190 wl_proxy_destroy((struct wl_proxy *) bq_consumer);
191}
192
193static inline void
194bq_consumer_release_buffer(struct bq_consumer *bq_consumer, struct bq_buffer *buffer)
195{
196 wl_proxy_marshal((struct wl_proxy *) bq_consumer,
197 BQ_CONSUMER_RELEASE_BUFFER, buffer);
198}
199
200#ifndef BQ_PROVIDER_ERROR_ENUM
201#define BQ_PROVIDER_ERROR_ENUM
202enum bq_provider_error {
203 BQ_PROVIDER_ERROR_OVERFLOW_QUEUE_SIZE = 0,
204 BQ_PROVIDER_ERROR_CONNECTION = 1,
205};
206#endif /* BQ_PROVIDER_ERROR_ENUM */
207
208struct bq_provider_listener {
209 /**
210 * connected - (none)
211 * @queue_size: (none)
212 * @width: (none)
213 * @height: (none)
214 */
215 void (*connected)(void *data,
216 struct bq_provider *bq_provider,
217 int32_t queue_size,
218 int32_t width,
219 int32_t height);
220 /**
221 * disconnected - (none)
222 */
223 void (*disconnected)(void *data,
224 struct bq_provider *bq_provider);
225 /**
226 * add_buffer - (none)
227 * @buffer: (none)
228 * @serial: (none)
229 */
230 void (*add_buffer)(void *data,
231 struct bq_provider *bq_provider,
232 struct bq_buffer *buffer,
233 uint32_t serial);
234};
235
236static inline int
237bq_provider_add_listener(struct bq_provider *bq_provider,
238 const struct bq_provider_listener *listener, void *data)
239{
240 return wl_proxy_add_listener((struct wl_proxy *) bq_provider,
241 (void (**)(void)) listener, data);
242}
243
244#define BQ_PROVIDER_ATTACH_BUFFER 0
245#define BQ_PROVIDER_SET_BUFFER_ID 1
246#define BQ_PROVIDER_SET_BUFFER_FD 2
247#define BQ_PROVIDER_DETACH_BUFFER 3
248#define BQ_PROVIDER_ENQUEUE_BUFFER 4
249
250static inline void
251bq_provider_set_user_data(struct bq_provider *bq_provider, void *user_data)
252{
253 wl_proxy_set_user_data((struct wl_proxy *) bq_provider, user_data);
254}
255
256static inline void *
257bq_provider_get_user_data(struct bq_provider *bq_provider)
258{
259 return wl_proxy_get_user_data((struct wl_proxy *) bq_provider);
260}
261
262static inline void
263bq_provider_destroy(struct bq_provider *bq_provider)
264{
265 wl_proxy_destroy((struct wl_proxy *) bq_provider);
266}
267
268static inline struct bq_buffer *
269bq_provider_attach_buffer(struct bq_provider *bq_provider, const char *engine, int32_t width, int32_t height, int32_t format, uint32_t flags)
270{
271 struct wl_proxy *buffer;
272
273 buffer = wl_proxy_marshal_constructor((struct wl_proxy *) bq_provider,
274 BQ_PROVIDER_ATTACH_BUFFER, &bq_buffer_interface, NULL, engine, width, height, format, flags);
275
276 return (struct bq_buffer *) buffer;
277}
278
279static inline void
280bq_provider_set_buffer_id(struct bq_provider *bq_provider, struct bq_buffer *buffer, int32_t id, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2)
281{
282 wl_proxy_marshal((struct wl_proxy *) bq_provider,
283 BQ_PROVIDER_SET_BUFFER_ID, buffer, id, offset0, stride0, offset1, stride1, offset2, stride2);
284}
285
286static inline void
287bq_provider_set_buffer_fd(struct bq_provider *bq_provider, struct bq_buffer *buffer, int32_t fd, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2)
288{
289 wl_proxy_marshal((struct wl_proxy *) bq_provider,
290 BQ_PROVIDER_SET_BUFFER_FD, buffer, fd, offset0, stride0, offset1, stride1, offset2, stride2);
291}
292
293static inline void
294bq_provider_detach_buffer(struct bq_provider *bq_provider, struct bq_buffer *buffer)
295{
296 wl_proxy_marshal((struct wl_proxy *) bq_provider,
297 BQ_PROVIDER_DETACH_BUFFER, buffer);
298}
299
300static inline void
301bq_provider_enqueue_buffer(struct bq_provider *bq_provider, struct bq_buffer *buffer, uint32_t serial)
302{
303 wl_proxy_marshal((struct wl_proxy *) bq_provider,
304 BQ_PROVIDER_ENQUEUE_BUFFER, buffer, serial);
305}
306
307static inline void
308bq_buffer_set_user_data(struct bq_buffer *bq_buffer, void *user_data)
309{
310 wl_proxy_set_user_data((struct wl_proxy *) bq_buffer, user_data);
311}
312
313static inline void *
314bq_buffer_get_user_data(struct bq_buffer *bq_buffer)
315{
316 return wl_proxy_get_user_data((struct wl_proxy *) bq_buffer);
317}
318
319static inline void
320bq_buffer_destroy(struct bq_buffer *bq_buffer)
321{
322 wl_proxy_destroy((struct wl_proxy *) bq_buffer);
323}
324
325#ifdef __cplusplus
326}
327#endif
328
329#endif
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}
diff --git a/src/lib/ecore_buffer/buffer_queue.h b/src/lib/ecore_buffer/buffer_queue.h
new file mode 100644
index 0000000000..f4f551fb6b
--- /dev/null
+++ b/src/lib/ecore_buffer/buffer_queue.h
@@ -0,0 +1,23 @@
1#ifndef _BUFFER_QUEUE_H_
2#define _BUFFER_QUEUE_H_
3
4#include <stdio.h>
5#include <Eina.h>
6
7#include "shared_buffer.h"
8
9typedef struct _Ecore_Buffer_Queue Ecore_Buffer_Queue;
10
11Ecore_Buffer_Queue *_ecore_buffer_queue_new(int w, int h, int queue_size);
12void _ecore_buffer_queue_free(Ecore_Buffer_Queue *ebq);
13void _ecore_buffer_queue_enqueue(Ecore_Buffer_Queue *ebq, Shared_Buffer *sb);
14Eina_Bool _ecore_buffer_queue_dequeue(Ecore_Buffer_Queue *ebq, Shared_Buffer **ret_sb);
15Eina_Bool _ecore_buffer_queue_is_empty(Ecore_Buffer_Queue *ebq);
16void _ecore_buffer_queue_shared_buffer_add(Ecore_Buffer_Queue *ebq, Shared_Buffer *sb);
17void _ecore_buffer_queue_shared_buffer_remove(Ecore_Buffer_Queue *ebq, Shared_Buffer *sb);
18Shared_Buffer *_ecore_buffer_queue_shared_buffer_find(Ecore_Buffer_Queue *ebq, Ecore_Buffer *buffer);
19Eina_List *_ecore_buffer_queue_shared_buffer_list_get(Ecore_Buffer_Queue *ebq);
20void _ecore_buffer_queue_connection_state_set(Ecore_Buffer_Queue *ebq, Eina_Bool connect);
21Eina_Bool _ecore_buffer_queue_connection_state_get(Ecore_Buffer_Queue *ebq);
22
23#endif
diff --git a/src/lib/ecore_buffer/ecore_buffer.c b/src/lib/ecore_buffer/ecore_buffer.c
new file mode 100644
index 0000000000..caa8f87659
--- /dev/null
+++ b/src/lib/ecore_buffer/ecore_buffer.c
@@ -0,0 +1,491 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8
9#include "Eina.h"
10#include "Ecore.h"
11
12#include "Ecore_Buffer.h"
13#include "ecore_buffer_private.h"
14
15typedef struct _Ecore_Buffer_Module Ecore_Buffer_Module;
16typedef struct _Ecore_Buffer_Cb_Data Ecore_Buffer_Cb_Data;
17
18struct _Ecore_Buffer_Module
19{
20 Ecore_Buffer_Backend *be;
21 Ecore_Buffer_Module_Data data;
22};
23
24struct _Ecore_Buffer
25{
26 unsigned int width;
27 unsigned int height;
28 int format;
29 unsigned int flags;
30
31 Ecore_Buffer_Data buffer_data;
32 Ecore_Buffer_Module *bm;
33
34 Eina_Hash *data;
35 Eina_Inlist *free_callbacks;
36};
37
38struct _Ecore_Buffer_Cb_Data
39{
40 EINA_INLIST;
41 Ecore_Buffer_Cb cb;
42 void *data;
43};
44
45static Eina_Hash *_backends;
46static Eina_Array *_modules;
47static int _ecore_buffer_init_count = 0;
48static int _ecore_buffer_log_dom = -1;
49
50#ifdef ERR
51#undef ERR
52#endif
53#define ERR(...) EINA_LOG_DOM_ERR(_ecore_buffer_log_dom, __VA_ARGS__)
54
55#ifdef DBG
56#undef DBG
57#endif
58#define DBG(...) EINA_LOG_DOM_DBG(_ecore_buffer_log_dom, __VA_ARGS__)
59
60#ifndef PACKAGE_LIB_DIR
61#define PACKAGE_LIB_DIR ""
62#endif
63#ifndef MODULE_ARCH
64#define MODULE_ARCH ""
65#endif
66
67static Ecore_Buffer_Module *
68_ecore_buffer_get_backend(const char *name)
69{
70 Ecore_Buffer_Module *bm = NULL;
71 Eina_Iterator *backend_name_itr;
72 const char *backend_name = NULL;
73
74 backend_name = name;
75
76 if (backend_name == NULL)
77 {
78 backend_name = (const char*)getenv("ECORE_BUFFER_ENGINE");
79 if (!backend_name)
80 {
81 backend_name_itr = eina_hash_iterator_data_new(_backends);
82 while((!bm) &&
83 (eina_iterator_next(backend_name_itr, (void **)&bm)));
84 eina_iterator_free(backend_name_itr);
85 }
86 }
87 else
88 bm = eina_hash_find(_backends, backend_name);
89
90 if ((!bm) || (!bm->be))
91 return NULL;
92
93 if (bm->be->init)
94 bm->data = bm->be->init(NULL, NULL);
95
96 return bm;
97}
98
99static Eina_Bool
100_ecore_buffer_backends_free(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED)
101{
102 Ecore_Buffer_Module *bm = data;
103
104 if (!bm)
105 return EINA_FALSE;
106
107 if (bm->data)
108 bm->be->shutdown(bm->data);
109
110 return EINA_TRUE;
111}
112
113EAPI Eina_Bool
114ecore_buffer_register(Ecore_Buffer_Backend *be)
115{
116 Ecore_Buffer_Module *bm;
117
118 EINA_SAFETY_ON_NULL_RETURN_VAL(be, 0);
119
120 bm = calloc(1, sizeof(Ecore_Buffer_Module));
121 if (!bm)
122 return EINA_FALSE;
123
124 bm->be = be;
125 bm->data = NULL;
126
127 return eina_hash_add(_backends, be->name, bm);
128}
129
130EAPI void
131ecore_buffer_unregister(Ecore_Buffer_Backend *be)
132{
133 Ecore_Buffer_Module *bm;
134
135 EINA_SAFETY_ON_NULL_RETURN(be);
136
137 bm = eina_hash_find(_backends, be->name);
138 if (!bm)
139 return;
140
141 eina_hash_del(_backends, be->name, bm);
142 free(bm);
143}
144
145EAPI Eina_Bool
146ecore_buffer_init(void)
147{
148 char *path;
149
150 if (++_ecore_buffer_init_count > 1)
151 return EINA_TRUE;
152
153 _ecore_buffer_log_dom = eina_log_domain_register("ecore_buffer", EINA_COLOR_BLUE);
154 if (_ecore_buffer_log_dom < 0)
155 {
156 EINA_LOG_ERR("Could not register log domain: ecore_buffer");
157 goto err;
158 }
159
160 _backends = eina_hash_string_superfast_new(NULL);
161
162 /* dynamic backends */
163 _modules = eina_module_arch_list_get(NULL,
164 PACKAGE_LIB_DIR "/ecore_buffer/modules",
165 MODULE_ARCH);
166
167 path = eina_module_symbol_path_get((const void *)ecore_buffer_init,
168 "/ecore_buffer/modules");
169
170 _modules = eina_module_arch_list_get(_modules, path, MODULE_ARCH);
171 if (path)
172 free(path);
173
174 /* fallback using module where in build directory */
175 if ((!_modules) ||
176 (eina_array_count(_modules) == 0))
177 {
178 ERR("No available module in library directy: %s",
179 PACKAGE_LIB_DIR "/ecore_buffer/modules");
180 ERR("Fallback to load module where in build directory :%s",
181 PACKAGE_BUILD_DIR "/src/modules/");
182 _modules = eina_module_list_get(NULL,
183 PACKAGE_BUILD_DIR "/src/modules/",
184 EINA_TRUE, NULL, NULL);
185 }
186
187 if ((!_modules) ||
188 (eina_array_count(_modules) == 0))
189 {
190 ERR("no ecore_buffer modules able to be loaded.");
191 eina_hash_free(_backends);
192 eina_log_domain_unregister(_ecore_buffer_log_dom);
193 _ecore_buffer_log_dom = -1;
194 goto err;
195 }
196
197 // XXX: MODFIX: do not list ALL modules and load them ALL! this is
198 // wrong. load the module we need WHEN we need it (by name etc. etc.
199 // from api).
200 eina_module_list_load(_modules);
201
202 return EINA_TRUE;
203
204err:
205 _ecore_buffer_init_count--;
206 return EINA_FALSE;
207}
208
209EAPI Eina_Bool
210ecore_buffer_shutdown(void)
211{
212 if (_ecore_buffer_init_count < 1)
213 {
214 WARN("Ecore_Buffer shut down called without init");
215 return EINA_FALSE;
216 }
217
218 if (--_ecore_buffer_init_count != 0)
219 return EINA_FALSE;
220
221 /* dynamic backends */
222 eina_hash_foreach(_backends, _ecore_buffer_backends_free, NULL);
223
224 eina_module_list_free(_modules);
225 if (_modules)
226 eina_array_free(_modules);
227
228 if (_backends)
229 eina_hash_free(_backends);
230
231 eina_log_domain_unregister(_ecore_buffer_log_dom);
232 _ecore_buffer_log_dom = -1;
233
234 return EINA_TRUE;
235}
236
237EAPI Ecore_Buffer*
238ecore_buffer_new(const char *engine, unsigned int width, unsigned int height, Ecore_Buffer_Format format, unsigned int flags)
239{
240 Ecore_Buffer_Module *bm;
241 Ecore_Buffer *bo;
242 void *bo_data;
243
244 bm = _ecore_buffer_get_backend(engine);
245 if (!bm)
246 {
247 ERR("Failed to get backend: %s", engine);
248 return NULL;
249 }
250
251 EINA_SAFETY_ON_NULL_RETURN_VAL(bm->be, NULL);
252
253 if (!bm->be->buffer_alloc)
254 {
255 ERR("Not supported create buffer");
256 return NULL;
257 }
258
259 bo = calloc(1, sizeof(Ecore_Buffer));
260 if (!bo)
261 return NULL;
262
263 bo_data = bm->be->buffer_alloc(bm->data, width, height, format, flags);
264 if (!bo_data)
265 {
266 free(bo);
267 return NULL;
268 }
269
270 bo->bm = bm;
271 bo->width = width;
272 bo->height = height;
273 bo->format = format;
274 bo->flags = flags;
275 bo->buffer_data = bo_data;
276
277 return bo;
278}
279
280EAPI void
281ecore_buffer_free(Ecore_Buffer *buf)
282{
283 Ecore_Buffer_Cb_Data *free_cb;
284
285 EINA_SAFETY_ON_NULL_RETURN(buf);
286
287 //Call free_cb
288 while (buf->free_callbacks)
289 {
290 free_cb = EINA_INLIST_CONTAINER_GET(buf->free_callbacks, Ecore_Buffer_Cb_Data);
291 buf->free_callbacks = eina_inlist_remove(buf->free_callbacks, buf->free_callbacks);
292
293 free_cb->cb(buf, free_cb->data);
294 free(free_cb);
295 }
296
297 EINA_SAFETY_ON_NULL_RETURN(buf->bm);
298 EINA_SAFETY_ON_NULL_RETURN(buf->bm->be);
299 EINA_SAFETY_ON_NULL_RETURN(buf->bm->be->buffer_free);
300
301 buf->bm->be->buffer_free(buf->bm->data, buf->buffer_data);
302
303 //Free User Data
304 if (buf->data)
305 eina_hash_free(buf->data);
306
307 free(buf);
308}
309
310EAPI void *
311ecore_buffer_data_get(Ecore_Buffer *buf)
312{
313 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, NULL);
314 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm, NULL);
315 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm->be, NULL);
316
317 if (!buf->bm->be->data_get)
318 return NULL;
319
320 return buf->bm->be->data_get(buf->bm->data, buf->buffer_data);
321}
322
323EAPI Ecore_Pixmap
324ecore_buffer_pixmap_get(Ecore_Buffer *buf)
325{
326 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0);
327 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm, 0);
328 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm->be, 0);
329
330 if (!buf->bm->be->pixmap_get)
331 return 0;
332
333 return buf->bm->be->pixmap_get(buf->bm->data, buf->buffer_data);
334}
335
336EAPI void *
337ecore_buffer_tbm_surface_get(Ecore_Buffer *buf)
338{
339 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, NULL);
340 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm, NULL);
341 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm->be, NULL);
342
343 if (!buf->bm->be->tbm_surface_get)
344 {
345 ERR("TBM is not supported\n");
346 return NULL;
347 }
348
349 return buf->bm->be->tbm_surface_get(buf->bm->data, buf->buffer_data);
350}
351
352EAPI Eina_Bool
353ecore_buffer_size_get(Ecore_Buffer *buf, unsigned int *width, unsigned int *height)
354{
355 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, EINA_FALSE);
356
357 if (width) *width = buf->width;
358 if (height) *height = buf->height;
359
360 return EINA_TRUE;
361}
362
363EAPI unsigned int
364ecore_buffer_format_get(Ecore_Buffer *buf)
365{
366 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0);
367
368 return buf->format;
369}
370
371EAPI unsigned int
372ecore_buffer_flags_get(Ecore_Buffer *buf)
373{
374 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0);
375
376 return buf->flags;
377}
378
379EAPI void
380ecore_buffer_free_callback_add(Ecore_Buffer *buf, Ecore_Buffer_Cb func, void *data)
381{
382 EINA_SAFETY_ON_NULL_RETURN(buf);
383 EINA_SAFETY_ON_NULL_RETURN(func);
384
385 Ecore_Buffer_Cb_Data *free_cb;
386
387 free_cb = calloc(1, sizeof(Ecore_Buffer_Cb_Data));
388 if (!free_cb)
389 return;
390
391 free_cb->cb = func;
392 free_cb->data = data;
393 buf->free_callbacks = eina_inlist_append(buf->free_callbacks, EINA_INLIST_GET(free_cb));
394}
395
396EAPI void
397ecore_buffer_free_callback_remove(Ecore_Buffer *buf, Ecore_Buffer_Cb func, void *data)
398{
399 Ecore_Buffer_Cb_Data *free_cb;
400
401 EINA_SAFETY_ON_NULL_RETURN(buf);
402 EINA_SAFETY_ON_NULL_RETURN(func);
403
404 if (buf->free_callbacks)
405 {
406 Eina_Inlist *itrn;
407 EINA_INLIST_FOREACH_SAFE(buf->free_callbacks, itrn, free_cb)
408 {
409 if (free_cb->cb == func && free_cb->data == data)
410 {
411 buf->free_callbacks =
412 eina_inlist_remove(buf->free_callbacks,
413 EINA_INLIST_GET(free_cb));
414 free(free_cb);
415 }
416 }
417 }
418}
419
420const char *
421_ecore_buffer_engine_name_get(Ecore_Buffer *buf)
422{
423 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, 0);
424 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm, 0);
425 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm->be, 0);
426
427 return buf->bm->be->name;
428}
429
430Ecore_Export_Type
431_ecore_buffer_export(Ecore_Buffer *buf, int *id)
432{
433 Ecore_Export_Type type = EXPORT_TYPE_INVALID;
434 int ret_id;
435
436 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, type);
437 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm, type);
438 EINA_SAFETY_ON_NULL_RETURN_VAL(buf->bm->be, type);
439
440 if (!buf->bm->be->buffer_export)
441 return type;
442
443 type = buf->bm->be->buffer_export(buf->bm->data, buf->buffer_data, &ret_id);
444
445 if (id) *id = ret_id;
446
447 return type;
448}
449
450Ecore_Buffer *
451_ecore_buffer_import(const char *engine, int width, int height, Ecore_Buffer_Format format, Ecore_Export_Type type, int export_id, unsigned int flags)
452{
453 Ecore_Buffer_Module *bm;
454 Ecore_Buffer *bo;
455 void *bo_data;
456
457 bm = _ecore_buffer_get_backend(engine);
458 if (!bm)
459 {
460 ERR("Filed to get Backend: %s", engine);
461 return NULL;
462 }
463
464 EINA_SAFETY_ON_NULL_RETURN_VAL(bm->be, NULL);
465
466 if (!bm->be->buffer_import)
467 {
468 ERR("Not supported import buffer");
469 return NULL;
470 }
471
472 bo = calloc(1, sizeof(Ecore_Buffer));
473 if (!bo)
474 return NULL;
475
476 bo_data = bm->be->buffer_import(bm->data, width, height, format, type, export_id, flags);
477 if (!bo_data)
478 {
479 free(bo);
480 return NULL;
481 }
482
483 bo->bm = bm;
484 bo->width = width;
485 bo->height = height;
486 bo->format = format;
487 bo->flags = flags;
488 bo->buffer_data = bo_data;
489
490 return bo;
491}
diff --git a/src/lib/ecore_buffer/ecore_buffer_con.c b/src/lib/ecore_buffer/ecore_buffer_con.c
new file mode 100644
index 0000000000..7cc4bc5103
--- /dev/null
+++ b/src/lib/ecore_buffer/ecore_buffer_con.c
@@ -0,0 +1,253 @@
1#include "ecore_buffer_con.h"
2
3#define DEBUG 1
4
5typedef struct _Ecore_Buffer_Con Ecore_Buffer_Con;
6
7struct _Ecore_Buffer_Con
8{
9 struct wl_display *display;
10 struct wl_registry *registry;
11 struct bq_mgr *bq_mgr;
12 Ecore_Fd_Handler *fd_hdl;
13 Ecore_Idle_Enterer *idle_enterer;
14 int fd;
15 Eina_Bool init_done;
16};
17
18static Eina_Bool _connection_fatal_error = EINA_FALSE;
19Ecore_Buffer_Con *_connection = NULL;
20
21static void
22_ecore_buffer_con_cb_registry_global(void *data, struct wl_registry *wl_registry, uint32_t id, const char *interface, uint32_t version)
23{
24 Ecore_Buffer_Con *conn = data;
25
26 DBG("Added Wl Global Registry - name %d interface %s version %d",
27 id, interface, version);
28
29 if (!strncmp(interface, "bq_mgr", strlen("bq_mgr")))
30 {
31 conn->bq_mgr =
32 wl_registry_bind(wl_registry, id, &bq_mgr_interface, 1);
33 }
34}
35
36static void
37_ecore_buffer_con_cb_registry_global_remove(void *data EINA_UNUSED, struct wl_registry *wl_registry EINA_UNUSED, uint32_t name EINA_UNUSED)
38{
39 DBG("Removed Wl Global Registry - name %d", name);
40}
41
42static void
43_ecore_buffer_con_signal_exit_free(void *data EINA_UNUSED, void *event)
44{
45 free(event);
46}
47
48static void
49_ecore_buffer_con_signal_exit(void)
50{
51 Ecore_Event_Signal_Exit *ev;
52
53 if (!(ev = calloc(1, sizeof(Ecore_Event_Signal_Exit))))
54 return;
55
56 ev->quit = 1;
57 ecore_event_add(ECORE_EVENT_SIGNAL_EXIT, ev,
58 _ecore_buffer_con_signal_exit_free, NULL);
59}
60
61static Eina_Bool
62_ecore_buffer_con_cb_idle_enterer(void *data)
63{
64 Ecore_Buffer_Con *conn;
65 int ret = 0;
66
67 if (_connection_fatal_error) return ECORE_CALLBACK_CANCEL;
68
69 if (!(conn = data)) return ECORE_CALLBACK_RENEW;
70
71 ret = wl_display_get_error(conn->display);
72 if (ret < 0) goto err;
73
74 ret = wl_display_flush(conn->display);
75 if ((ret < 0) && (errno == EAGAIN))
76 ecore_main_fd_handler_active_set(conn->fd_hdl,
77 (ECORE_FD_READ | ECORE_FD_WRITE));
78
79 ret = wl_display_dispatch_pending(conn->display);
80 if (ret < 0) goto err;
81
82 return ECORE_CALLBACK_RENEW;
83
84err:
85 if ((ret < 0) && ((errno != EAGAIN) && (errno != EINVAL)))
86 {
87 _connection_fatal_error = EINA_TRUE;
88
89 /* raise exit signal */
90 _ecore_buffer_con_signal_exit();
91
92 return ECORE_CALLBACK_CANCEL;
93 }
94
95 return ECORE_CALLBACK_RENEW;
96}
97
98static Eina_Bool
99_ecore_buffer_con_cb_fd_handle(void *data, Ecore_Fd_Handler *hdl)
100{
101 Ecore_Buffer_Con *conn = data;
102 int ret = 0;
103
104 if (_connection_fatal_error) return ECORE_CALLBACK_CANCEL;
105 if (!conn) return ECORE_CALLBACK_RENEW;
106
107 if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_ERROR))
108 {
109 ERR("Received error on wayland display fd");
110 _connection_fatal_error = EINA_TRUE;
111 _ecore_buffer_con_signal_exit();
112
113 return ECORE_CALLBACK_CANCEL;
114 }
115
116 if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_READ))
117 ret = wl_display_dispatch(conn->display);
118 else if (ecore_main_fd_handler_active_get(hdl, ECORE_FD_WRITE))
119 {
120 ret = wl_display_flush(conn->display);
121 if (ret == 0)
122 ecore_main_fd_handler_active_set(hdl, ECORE_FD_READ);
123 }
124
125 if ((ret < 0) && ((errno != EAGAIN) && (errno != EINVAL)))
126 {
127 _connection_fatal_error = EINA_TRUE;
128
129 /* raise exit signal */
130 _ecore_buffer_con_signal_exit();
131
132 return ECORE_CALLBACK_CANCEL;
133 }
134
135 return ECORE_CALLBACK_RENEW;
136}
137
138static void
139_ecore_buffer_con_init_callback(void *data, struct wl_callback *callback, uint32_t serial EINA_UNUSED)
140{
141 Ecore_Buffer_Con *conn = data;
142
143 DBG("Queue Server Connected");
144
145 if (!conn)
146 return;
147
148 wl_callback_destroy(callback);
149 conn->init_done = EINA_TRUE;
150}
151
152static const struct wl_callback_listener _ecore_buffer_con_init_sync_listener =
153{
154 _ecore_buffer_con_init_callback
155};
156
157struct wl_registry_listener _ecore_buffer_registry_listener =
158{
159 _ecore_buffer_con_cb_registry_global,
160 _ecore_buffer_con_cb_registry_global_remove
161};
162
163Eina_Bool
164_ecore_buffer_con_init(void)
165{
166 struct wl_callback *callback;
167 const char *name = "bq_mgr_daemon";
168
169 DBG("Ecore_Buffer_Con Init - name %s", name);
170
171 _connection = calloc(1, sizeof(Ecore_Buffer_Con));
172 if (!_connection)
173 {
174 ERR("Failed to allocation");
175 return EINA_FALSE;
176 }
177
178 if (!(_connection->display = wl_display_connect(name)))
179 {
180 ERR("Failed to connect to Queue Server");
181 goto err_connect;
182 }
183
184 _connection->fd = wl_display_get_fd(_connection->display);
185 _connection->fd_hdl =
186 ecore_main_fd_handler_add(_connection->fd,
187 ECORE_FD_READ | ECORE_FD_WRITE | ECORE_FD_ERROR,
188 _ecore_buffer_con_cb_fd_handle,
189 _connection, NULL, NULL);
190
191 _connection->idle_enterer =
192 ecore_idle_enterer_add(_ecore_buffer_con_cb_idle_enterer, _connection);
193
194 if (!(_connection->registry = wl_display_get_registry(_connection->display)))
195 goto err_get_registry;
196
197 wl_registry_add_listener(_connection->registry,
198 &_ecore_buffer_registry_listener, _connection);
199
200 _connection->init_done = EINA_FALSE;
201 callback = wl_display_sync(_connection->display);
202 wl_callback_add_listener(callback, &_ecore_buffer_con_init_sync_listener,
203 _connection);
204
205 return EINA_TRUE;;
206err_get_registry:
207 wl_display_disconnect(_connection->display);
208err_connect:
209 free(_connection);
210 return EINA_FALSE;
211}
212
213void
214_ecore_buffer_con_shutdown(void)
215{
216 if (!_connection) return;
217
218 DBG("Ecore_Buffer_Con Shutdown");
219
220 if (_connection->fd_hdl)
221 ecore_main_fd_handler_del(_connection->fd_hdl);
222
223 if (_connection->idle_enterer)
224 ecore_idle_enterer_del(_connection->idle_enterer);
225
226 if (_connection->bq_mgr)
227 bq_mgr_destroy(_connection->bq_mgr);
228
229 if (_connection->display)
230 wl_display_disconnect(_connection->display);
231
232 free(_connection);
233 _connection = NULL;
234}
235
236struct bq_provider *
237_ecore_buffer_con_provider_create(const char *name)
238{
239 return bq_mgr_create_provider(_connection->bq_mgr, name);
240}
241
242struct bq_consumer *
243_ecore_buffer_con_consumer_create(const char *name, int queue_size, int w, int h)
244{
245 return bq_mgr_create_consumer(_connection->bq_mgr, name, queue_size, w, h);
246}
247
248void
249_ecore_buffer_con_init_wait(void)
250{
251 while (!_connection->init_done)
252 wl_display_dispatch(_connection->display);
253}
diff --git a/src/lib/ecore_buffer/ecore_buffer_con.h b/src/lib/ecore_buffer/ecore_buffer_con.h
new file mode 100644
index 0000000000..f38d4e0a38
--- /dev/null
+++ b/src/lib/ecore_buffer/ecore_buffer_con.h
@@ -0,0 +1,20 @@
1#ifndef _ECORE_BUFFER_con_H_
2#define _ECORE_BUFFER_con_H_
3
4#include <stdio.h>
5#include <wayland-client.h>
6
7#include <Eina.h>
8#include <Ecore.h>
9#include <Ecore_Buffer.h>
10
11#include "bq_mgr_protocol.h"
12#include "ecore_buffer_private.h"
13
14Eina_Bool _ecore_buffer_con_init(void);
15void _ecore_buffer_con_shutdown(void);
16void _ecore_buffer_con_init_wait(void);
17struct bq_provider *_ecore_buffer_con_provider_create(const char *name);
18struct bq_consumer *_ecore_buffer_con_consumer_create(const char *name, int queue_size, int w, int h);
19
20#endif
diff --git a/src/lib/ecore_buffer/ecore_buffer_consumer.c b/src/lib/ecore_buffer/ecore_buffer_consumer.c
new file mode 100644
index 0000000000..59a4a046cf
--- /dev/null
+++ b/src/lib/ecore_buffer/ecore_buffer_consumer.c
@@ -0,0 +1,417 @@
1#include <stdio.h>
2#include <unistd.h>
3
4#include <Eina.h>
5#include <Ecore_Buffer.h>
6#include <Ecore_Buffer_Queue.h>
7
8#include "bq_mgr_protocol.h"
9#include "shared_buffer.h"
10#include "buffer_queue.h"
11#include "ecore_buffer_private.h"
12#include "ecore_buffer_con.h"
13
14struct _Ecore_Buffer_Consumer
15{
16 struct bq_consumer *resource;
17 Ecore_Buffer_Queue *ebq;
18 struct
19 {
20 void (*provider_add) (Ecore_Buffer_Consumer *consumer, void *data);
21 void (*provider_del) (Ecore_Buffer_Consumer *consumer, void *data);
22 void (*enqueue) (Ecore_Buffer_Consumer *consumer, void *data);
23 void *data;
24 } cb;
25};
26
27static void _ecore_buffer_consumer_cb_provider_connected(void *data, struct bq_consumer *bq_consumer);
28static void _ecore_buffer_consumer_cb_provider_disconnected(void *data, struct bq_consumer *bq_consumer);
29static void _ecore_buffer_consumer_cb_buffer_attached(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *id, const char *engine, int32_t width, int32_t height, int32_t format, uint32_t flags);
30static void _ecore_buffer_consumer_cb_buffer_id_set(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *buffer, int32_t id, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2);
31static void _ecore_buffer_consumer_cb_buffer_fd_set(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *buffer, int32_t fd, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2);
32static void _ecore_buffer_consumer_cb_buffer_detached(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *id);
33static void _ecore_buffer_consumer_cb_add_buffer(void *data, struct bq_consumer *bq_consumer, struct bq_buffer *buffer, uint32_t serial);
34static void _ecore_buffer_consumer_cb_buffer_free(Ecore_Buffer *buf, void *data);
35static Eina_Bool _ecore_buffer_consumer_buffer_import(Ecore_Buffer_Consumer *consumer, Shared_Buffer *sb, int32_t seed, Ecore_Export_Type export_type);
36
37struct bq_consumer_listener _ecore_buffer_consumer_listener =
38{
39 _ecore_buffer_consumer_cb_provider_connected,
40 _ecore_buffer_consumer_cb_provider_disconnected,
41 _ecore_buffer_consumer_cb_buffer_attached,
42 _ecore_buffer_consumer_cb_buffer_id_set,
43 _ecore_buffer_consumer_cb_buffer_fd_set,
44 _ecore_buffer_consumer_cb_buffer_detached,
45 _ecore_buffer_consumer_cb_add_buffer
46};
47
48EAPI Ecore_Buffer_Consumer *
49ecore_buffer_consumer_new(const char *name, int32_t queue_size, int32_t w, int32_t h)
50{
51 Ecore_Buffer_Consumer *consumer;
52 const int default_queue_size = 2;
53
54 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
55
56 DBG("Consumer New - name %s, queue size %d, size (%dx%d)",
57 name, queue_size, w, h);
58
59 if ((w < 1) || (h < 1))
60 return NULL;
61
62 if (queue_size < default_queue_size)
63 queue_size = default_queue_size;
64
65 _ecore_buffer_con_init_wait();
66
67 consumer = calloc(1, sizeof(Ecore_Buffer_Consumer));
68 if (!consumer)
69 return NULL;
70
71 consumer->ebq = _ecore_buffer_queue_new(w, h, queue_size);
72 if (!consumer->ebq)
73 {
74 free(consumer);
75 return NULL;
76 }
77
78 consumer->resource = _ecore_buffer_con_consumer_create(name, queue_size, w, h);
79 if (!consumer->resource)
80 {
81 _ecore_buffer_queue_free(consumer->ebq);
82 free(consumer);
83 return NULL;
84 }
85
86 bq_consumer_add_listener(consumer->resource,
87 &_ecore_buffer_consumer_listener,
88 consumer);
89
90 return consumer;
91}
92
93EAPI void
94ecore_buffer_consumer_free(Ecore_Buffer_Consumer *consumer)
95{
96 EINA_SAFETY_ON_NULL_RETURN(consumer);
97
98 DBG("Consumer Free");
99
100 if (consumer->ebq)
101 _ecore_buffer_queue_free(consumer->ebq);
102
103 if (consumer->resource)
104 bq_consumer_destroy(consumer->resource);
105
106 free(consumer);
107}
108
109EAPI Eina_Bool
110ecore_buffer_consumer_buffer_release(Ecore_Buffer_Consumer *consumer, Ecore_Buffer *buffer)
111{
112 Shared_Buffer *sb;
113
114 EINA_SAFETY_ON_NULL_RETURN_VAL(consumer, EINA_FALSE);
115 EINA_SAFETY_ON_NULL_RETURN_VAL(buffer, EINA_FALSE);
116
117 DBG("Buffer Release");
118
119 if (!_ecore_buffer_queue_connection_state_get(consumer->ebq))
120 {
121 WARN("NOT Connected with provider yet");
122 return EINA_FALSE;
123 }
124
125 if (!(sb = _ecore_buffer_queue_shared_buffer_find(consumer->ebq, buffer)))
126 {
127 WARN("NOT shared - buffer %p", buffer);
128 return EINA_FALSE;
129 }
130
131 // already detached buffer, free buffer by deputy.
132 if (_shared_buffer_state_get(sb) == SHARED_BUFFER_STATE_DETACH)
133 {
134 DBG("Free buffer - buffer %p", sb);
135 ecore_buffer_free(buffer);
136 }
137 else
138 {
139 if (_shared_buffer_state_get(sb) != SHARED_BUFFER_STATE_DEQUEUE)
140 {
141 WARN("Failed to Release Buffer -"
142 "DO NOT Release buffer which is not Dequeued: buffer %p state %s",
143 sb, _shared_buffer_state_string_get(sb));
144 return EINA_FALSE;
145 }
146
147 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_RELEASE);
148 bq_consumer_release_buffer(consumer->resource, _shared_buffer_resource_get(sb));
149 }
150
151 return EINA_TRUE;
152}
153
154EAPI Ecore_Buffer *
155ecore_buffer_consumer_buffer_dequeue(Ecore_Buffer_Consumer *consumer)
156{
157 Shared_Buffer *sb;
158
159 EINA_SAFETY_ON_NULL_RETURN_VAL(consumer, EINA_FALSE);
160
161 DBG("Buffer Acquire");
162
163 if (!_ecore_buffer_queue_dequeue(consumer->ebq, &sb))
164 {
165 DBG("No Available Buffer in Queue");
166 return NULL;
167 }
168
169 // This should not happen.
170 if (_shared_buffer_state_get(sb) != SHARED_BUFFER_STATE_ENQUEUE)
171 {
172 ERR("Unknown error occured - Not on Enqueued State: buffer %p, state %s",
173 sb, _shared_buffer_state_string_get(sb));
174 return NULL;
175 }
176
177 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_DEQUEUE);
178
179 return _shared_buffer_buffer_get(sb);
180}
181
182EAPI Eina_Bool
183ecore_buffer_consumer_queue_is_empty(Ecore_Buffer_Consumer *consumer)
184{
185 EINA_SAFETY_ON_NULL_RETURN_VAL(consumer, EINA_FALSE);
186
187 return _ecore_buffer_queue_is_empty(consumer->ebq);
188}
189
190EAPI void
191ecore_buffer_consumer_provider_add_cb_set(Ecore_Buffer_Consumer *consumer, Ecore_Buffer_Consumer_Provider_Add_Cb func, void *data)
192{
193 EINA_SAFETY_ON_NULL_RETURN(consumer);
194
195 consumer->cb.provider_add = func;
196 consumer->cb.data = data;
197}
198
199EAPI void
200ecore_buffer_consumer_provider_del_cb_set(Ecore_Buffer_Consumer *consumer, Ecore_Buffer_Consumer_Provider_Del_Cb func, void *data)
201{
202 EINA_SAFETY_ON_NULL_RETURN(consumer);
203
204 consumer->cb.provider_del = func;
205 consumer->cb.data = data;
206}
207
208EAPI void
209ecore_buffer_consumer_buffer_enqueued_cb_set(Ecore_Buffer_Consumer *consumer, Ecore_Buffer_Consumer_Enqueue_Cb func, void *data)
210{
211 EINA_SAFETY_ON_NULL_RETURN(consumer);
212
213 consumer->cb.enqueue = func;
214 consumer->cb.data = data;
215}
216
217static void
218_ecore_buffer_consumer_cb_provider_connected(void *data, struct bq_consumer *bq_consumer EINA_UNUSED)
219{
220 Ecore_Buffer_Consumer *consumer = data;
221
222 EINA_SAFETY_ON_NULL_RETURN(consumer);
223
224 DBG("Provider Connected");
225
226 _ecore_buffer_queue_connection_state_set(consumer->ebq, EINA_TRUE);
227
228 CALLBACK_CALL(consumer, provider_add);
229}
230
231static void
232_ecore_buffer_consumer_cb_provider_disconnected(void *data, struct bq_consumer *bq_consumer EINA_UNUSED)
233{
234 Ecore_Buffer_Consumer *consumer = data;
235 Eina_List *clone, *shared_buffers, *l;
236 Shared_Buffer *sb;
237
238 EINA_SAFETY_ON_NULL_RETURN(consumer);
239
240 DBG("Provider Disconnected");
241
242 _ecore_buffer_queue_connection_state_set(consumer->ebq, EINA_FALSE);
243
244 CALLBACK_CALL(consumer, provider_del);
245
246 shared_buffers = _ecore_buffer_queue_shared_buffer_list_get(consumer->ebq);
247 clone = eina_list_clone(shared_buffers);
248
249 EINA_LIST_FOREACH(clone, l, sb)
250 ecore_buffer_free(_shared_buffer_buffer_get(sb));
251
252 eina_list_free(clone);
253}
254
255static void
256_ecore_buffer_consumer_cb_buffer_attached(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *id, const char *engine, int32_t width, int32_t height, int32_t format, uint32_t flags)
257{
258 Ecore_Buffer_Consumer *consumer = data;
259 Shared_Buffer *sb;
260
261 EINA_SAFETY_ON_NULL_RETURN(consumer);
262 EINA_SAFETY_ON_NULL_RETURN(consumer->ebq);
263
264 DBG("Buffer Attached - engine %s, size (%dx%d), format %d, flags %d",
265 engine, width, height, format, flags);
266
267 sb = _shared_buffer_new(engine, id, width, height, format, flags);
268 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_ATTACH);
269 _ecore_buffer_queue_shared_buffer_add(consumer->ebq, sb);
270 bq_buffer_set_user_data(id, sb);
271}
272
273static void
274_ecore_buffer_consumer_cb_buffer_free(Ecore_Buffer *buf, void *data)
275{
276 Ecore_Buffer_Consumer *consumer = data;
277 Shared_Buffer *sb;
278
279 EINA_SAFETY_ON_NULL_RETURN(buf);
280 EINA_SAFETY_ON_NULL_RETURN(consumer);
281
282 sb = _ecore_buffer_queue_shared_buffer_find(consumer->ebq, buf);
283 if (!sb)
284 return;
285
286 _ecore_buffer_queue_shared_buffer_remove(consumer->ebq, sb);
287 bq_buffer_destroy(_shared_buffer_resource_get(sb));
288 _shared_buffer_free(sb);
289}
290
291static void
292_ecore_buffer_consumer_cb_buffer_id_set(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *buffer, int32_t id, int32_t offset0 EINA_UNUSED, int32_t stride0 EINA_UNUSED, int32_t offset1 EINA_UNUSED, int32_t stride1 EINA_UNUSED, int32_t offset2 EINA_UNUSED, int32_t stride2 EINA_UNUSED)
293{
294 Ecore_Buffer_Consumer *consumer = data;
295 Shared_Buffer *sb = bq_buffer_get_user_data(buffer);
296
297 EINA_SAFETY_ON_NULL_RETURN(consumer);
298 EINA_SAFETY_ON_NULL_RETURN(sb);
299
300 if (_ecore_buffer_consumer_buffer_import(consumer, sb, id, EXPORT_TYPE_ID))
301 bq_buffer_set_user_data(buffer, sb);
302 else
303 ERR("Failed to import buffer - buffer resource %p", buffer);
304}
305
306static void
307_ecore_buffer_consumer_cb_buffer_fd_set(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *buffer, int32_t fd, int32_t offset0 EINA_UNUSED, int32_t stride0 EINA_UNUSED, int32_t offset1 EINA_UNUSED, int32_t stride1 EINA_UNUSED, int32_t offset2 EINA_UNUSED, int32_t stride2 EINA_UNUSED)
308{
309 Ecore_Buffer_Consumer *consumer = data;
310 Shared_Buffer *sb = bq_buffer_get_user_data(buffer);
311
312 EINA_SAFETY_ON_NULL_RETURN(consumer);
313 EINA_SAFETY_ON_NULL_RETURN(sb);
314
315 if (_ecore_buffer_consumer_buffer_import(consumer, sb, fd, EXPORT_TYPE_FD))
316 bq_buffer_set_user_data(buffer, sb);
317 else
318 ERR("Failed to import buffer - buffer resource %p", buffer);
319}
320
321static void
322_ecore_buffer_consumer_cb_buffer_detached(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *id)
323{
324 Ecore_Buffer_Consumer *consumer = data;
325 Shared_Buffer *sb = bq_buffer_get_user_data(id);
326
327 EINA_SAFETY_ON_NULL_RETURN(consumer);
328 EINA_SAFETY_ON_NULL_RETURN(sb);
329
330 DBG("Buffer Detached");
331
332 // buffer is owned by consumer. free right now.
333 if (_shared_buffer_state_get(sb) != SHARED_BUFFER_STATE_DEQUEUE)
334 {
335 DBG("Free buffer - buffer %p, state %s",
336 sb, _shared_buffer_state_string_get(sb));
337 ecore_buffer_free(_shared_buffer_buffer_get(sb));
338 return;
339 }
340
341 // mark it as a detached buffer, and then free on buffer release time.
342 DBG("Just mark this buffer to free it when released - buffer %p, state %s",
343 sb, "SHARED_BUFFER_STATE_DEQUEUE");
344 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_DETACH);
345}
346
347static void
348_ecore_buffer_consumer_cb_add_buffer(void *data, struct bq_consumer *bq_consumer EINA_UNUSED, struct bq_buffer *buffer, uint32_t serial EINA_UNUSED)
349{
350 Ecore_Buffer_Consumer *consumer = data;
351 Shared_Buffer *sb = bq_buffer_get_user_data(buffer);
352 Shared_Buffer_State state;
353
354 EINA_SAFETY_ON_NULL_RETURN(consumer);
355
356 DBG("Buffer Enqueued");
357
358 if (!sb)
359 {
360 ERR("Unknown Error occured - maybe this buffer is not shared yet");
361 return;
362 }
363
364 state = _shared_buffer_state_get(sb);
365 if ((state != SHARED_BUFFER_STATE_IMPORT) &&
366 (state != SHARED_BUFFER_STATE_RELEASE))
367 {
368 ERR("Unknown Error occured - Could not enqueued this state of buffer: buffer %p, state %s",
369 sb, _shared_buffer_state_string_get(sb));
370 return;
371 }
372
373 _ecore_buffer_queue_enqueue(consumer->ebq, sb);
374 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_ENQUEUE);
375
376 CALLBACK_CALL(consumer, enqueue);
377}
378
379static Eina_Bool
380_ecore_buffer_consumer_buffer_import(Ecore_Buffer_Consumer *consumer, Shared_Buffer *sb, int32_t seed, Ecore_Export_Type export_type)
381{
382 Ecore_Buffer *buffer;
383 const char *engine = NULL;
384 int w, h, format;
385 unsigned int flags;
386
387 if ((!sb) ||
388 (!_shared_buffer_info_get(sb, &engine, &w, &h, &format, &flags)))
389 {
390 ERR("Failed to Get Shared Buffer");
391 return EINA_FALSE;
392 }
393
394 if (_shared_buffer_state_get(sb) != SHARED_BUFFER_STATE_ATTACH)
395 {
396 ERR("Not Attached Buffer - buffer %p state %s",
397 sb, _shared_buffer_state_string_get(sb));
398 return EINA_FALSE;
399 }
400
401 if (!(buffer = _ecore_buffer_import(engine, w, h, format, export_type, seed, flags)))
402 {
403 ERR("Failed to Import Buffer - size (%dx%d), foramt %d, seed %d, export_type %d",
404 w, h, format, seed, export_type);
405 return EINA_FALSE;
406 }
407
408 if (export_type == EXPORT_TYPE_FD)
409 close(seed);
410
411 _shared_buffer_buffer_set(sb, buffer);
412 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_IMPORT);
413
414 ecore_buffer_free_callback_add(buffer, _ecore_buffer_consumer_cb_buffer_free, consumer);
415
416 return EINA_TRUE;
417}
diff --git a/src/lib/ecore_buffer/ecore_buffer_private.h b/src/lib/ecore_buffer/ecore_buffer_private.h
new file mode 100644
index 0000000000..4e33772ed6
--- /dev/null
+++ b/src/lib/ecore_buffer/ecore_buffer_private.h
@@ -0,0 +1,31 @@
1#ifndef _ECORE_BUFFER_PRIVATE_H_
2# define _ECORE_BUFFER_PRIVATE_H_
3
4#ifdef ERR
5#undef ERR
6#endif
7#ifdef WARN
8#undef WARN
9#endif
10#ifdef DBG
11#undef DBG
12#endif
13
14#define ERR(...) EINA_LOG_DOM_ERR(_ecore_buffer_queue_log_dom, __VA_ARGS__)
15#define DBG(...) EINA_LOG_DOM_DBG(_ecore_buffer_queue_log_dom, __VA_ARGS__)
16#define WARN(...) EINA_LOG_DOM_WARN(_ecore_buffer_queue_log_dom, __VA_ARGS__)
17
18#define CALLBACK_CALL(obj, cbname) \
19do { \
20 if (obj->cb.cbname) \
21 obj->cb.cbname(obj, obj->cb.data); \
22} while(0)
23
24extern int _ecore_buffer_queue_log_dom;
25
26const char *_ecore_buffer_engine_name_get(Ecore_Buffer *buf);
27/* NOTE: if Ecore_Export_Type as a return value is EXPORT_TYPE_FD,
28 * then caller should close the fd after using it. */
29Ecore_Export_Type _ecore_buffer_export(Ecore_Buffer *buf, int *id);
30Ecore_Buffer *_ecore_buffer_import(const char *engine, int width, int height, Ecore_Buffer_Format format, Ecore_Export_Type type, int export_id, unsigned int flags);
31#endif /* _ECORE_BUFFER_PRIVATE_H_ */
diff --git a/src/lib/ecore_buffer/ecore_buffer_provider.c b/src/lib/ecore_buffer/ecore_buffer_provider.c
new file mode 100644
index 0000000000..53380fac84
--- /dev/null
+++ b/src/lib/ecore_buffer/ecore_buffer_provider.c
@@ -0,0 +1,391 @@
1#include <stdio.h>
2#include <unistd.h>
3
4#include <Eina.h>
5#include <Ecore_Buffer.h>
6#include <Ecore_Buffer_Queue.h>
7
8#include "bq_mgr_protocol.h"
9#include "shared_buffer.h"
10#include "buffer_queue.h"
11#include "ecore_buffer_private.h"
12#include "ecore_buffer_con.h"
13
14struct _Ecore_Buffer_Provider
15{
16 struct bq_provider *resource;
17 Ecore_Buffer_Queue *ebq;
18 int free_slot;
19 struct
20 {
21 void (*consumer_add) (Ecore_Buffer_Provider *provider, int queue_size, int w, int h, void *data);
22 void (*consumer_del) (Ecore_Buffer_Provider *provider, void *data);
23 void (*enqueue) (Ecore_Buffer_Provider *provider, void *data);
24 void *data;
25 } cb;
26};
27
28static void _ecore_buffer_provider_cb_consumer_connected(void *data, struct bq_provider *bq_provider, int32_t queue_size, int32_t width, int32_t height);
29static void _ecore_buffer_provider_cb_consumer_disconnected(void *data, struct bq_provider *bq_provider);
30static void _ecore_buffer_provider_cb_add_buffer(void *data, struct bq_provider *bq_provider, struct bq_buffer *buffer, uint32_t serial);
31static Shared_Buffer *_ecore_buffer_provider_shared_buffer_new(Ecore_Buffer_Provider *provider, Ecore_Buffer *buffer);
32static void _ecore_buffer_provider_shared_buffer_free(Ecore_Buffer_Provider *provider, Shared_Buffer *sb);
33static void _ecore_buffer_provider_cb_buffer_free(Ecore_Buffer *buf, void *data);
34
35struct bq_provider_listener _ecore_buffer_provider_listener =
36{
37 _ecore_buffer_provider_cb_consumer_connected,
38 _ecore_buffer_provider_cb_consumer_disconnected,
39 _ecore_buffer_provider_cb_add_buffer
40};
41
42EAPI Ecore_Buffer_Provider *
43ecore_buffer_provider_new(const char *name)
44{
45 Ecore_Buffer_Provider *provider;
46
47 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
48
49 DBG("Provider New - name %s", name);
50
51 _ecore_buffer_con_init_wait();
52
53 provider = calloc(1, sizeof(Ecore_Buffer_Provider));
54 if (!provider)
55 {
56 ERR("Failed to allocate Ecore_Buffer_Provider");
57 return NULL;
58 }
59
60 provider->resource = _ecore_buffer_con_provider_create(name);
61 if (!provider->resource)
62 {
63 ERR("Failed to get provider connection");
64 free(provider);
65 return NULL;
66 }
67
68 bq_provider_add_listener(provider->resource, &_ecore_buffer_provider_listener, provider);
69 bq_provider_set_user_data(provider->resource, provider);
70
71 return provider;
72}
73
74EAPI void
75ecore_buffer_provider_free(Ecore_Buffer_Provider *provider)
76{
77 Eina_List *shared_buffers, *l;
78 Shared_Buffer *sb;
79
80 EINA_SAFETY_ON_NULL_RETURN(provider);
81
82 DBG("Provider Free");
83
84 if (provider->ebq)
85 {
86 shared_buffers = _ecore_buffer_queue_shared_buffer_list_get(provider->ebq);
87 EINA_LIST_FOREACH(shared_buffers, l, sb)
88 _ecore_buffer_provider_shared_buffer_free(provider, sb);
89
90 _ecore_buffer_queue_free(provider->ebq);
91 }
92
93 bq_provider_destroy(provider->resource);
94 free(provider);
95}
96
97EAPI Ecore_Buffer_Return
98ecore_buffer_provider_buffer_acquire(Ecore_Buffer_Provider *provider, Ecore_Buffer **ret_buf)
99{
100 Shared_Buffer *sb;
101 Ecore_Buffer_Return ret_flag = ECORE_BUFFER_RETURN_ERROR;
102
103 EINA_SAFETY_ON_NULL_RETURN_VAL(provider, ret_flag);
104
105 if (!provider->ebq)
106 return ret_flag;
107
108 DBG("Buffer Acquire");
109
110 if (!_ecore_buffer_queue_dequeue(provider->ebq, &sb))
111 {
112 ret_flag = ECORE_BUFFER_RETURN_EMPTY;
113
114 // Check if exist free slot.
115 if (provider->free_slot > 0)
116 ret_flag = ECORE_BUFFER_RETURN_NEED_ALLOC;
117 }
118 else
119 {
120 // This should not happen.
121 if (_shared_buffer_state_get(sb) != SHARED_BUFFER_STATE_RELEASE)
122 {
123 ERR("Unknown error occured - Not on Released State: buffer %p state %s",
124 sb, _shared_buffer_state_string_get(sb));
125 return ECORE_BUFFER_RETURN_ERROR;
126 }
127
128 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_ACQUIRE);
129
130 ret_flag = ECORE_BUFFER_RETURN_SUCCESS;
131 if (ret_buf) *ret_buf = _shared_buffer_buffer_get(sb);
132 }
133
134 return ret_flag;
135}
136
137EAPI Eina_Bool
138ecore_buffer_provider_buffer_enqueue(Ecore_Buffer_Provider *provider, Ecore_Buffer *buffer)
139{
140 Shared_Buffer *sb;
141 Shared_Buffer_State state;
142
143 EINA_SAFETY_ON_NULL_RETURN_VAL(provider, EINA_FALSE);
144 EINA_SAFETY_ON_NULL_RETURN_VAL(buffer, EINA_FALSE);
145
146 DBG("Buffer Enqueue");
147
148 if (!provider->ebq)
149 {
150 WARN("Not connected with consumer yet.");
151 return EINA_FALSE;
152 }
153
154 if (!(sb = _ecore_buffer_queue_shared_buffer_find(provider->ebq, buffer)))
155 {
156 // this buffer was never attached before.
157 if (provider->free_slot > 0)
158 {
159 sb = _ecore_buffer_provider_shared_buffer_new(provider, buffer);
160 if (!sb)
161 {
162 ERR("Unkown error occured -"
163 "Failed to attach buffer: buffer %p", buffer);
164 return EINA_FALSE;
165 }
166 provider->free_slot--;
167 }
168 else
169 {
170 WARN("No Free slot in Queue."
171 "Need to ecore_buffer_free of enqueueed buffer first.");
172 return EINA_FALSE;
173 }
174 }
175
176 state = _shared_buffer_state_get(sb);
177 if ((state != SHARED_BUFFER_STATE_NEW) &&
178 (state != SHARED_BUFFER_STATE_ACQUIRE))
179 {
180 ERR("Failed to enqueue buffer - Not on acquired state: buffer %p state %s",
181 sb, _shared_buffer_state_string_get(sb));
182 return EINA_FALSE;
183 }
184
185 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_ENQUEUE);
186 bq_provider_enqueue_buffer(provider->resource, _shared_buffer_resource_get(sb), 0);
187
188 return EINA_TRUE;
189}
190
191EAPI Ecore_Buffer_Return
192ecore_buffer_provider_buffer_acquirable_check(Ecore_Buffer_Provider *provider)
193{
194 EINA_SAFETY_ON_NULL_RETURN_VAL(provider, EINA_FALSE);
195
196 if (_ecore_buffer_queue_is_empty(provider->ebq))
197 {
198 if (provider->free_slot > 0)
199 return ECORE_BUFFER_RETURN_NEED_ALLOC;
200
201 return ECORE_BUFFER_RETURN_EMPTY;
202 }
203
204 return ECORE_BUFFER_RETURN_NOT_EMPTY;
205}
206
207EAPI void
208ecore_buffer_provider_consumer_add_cb_set(Ecore_Buffer_Provider *provider, Ecore_Buffer_Provider_Consumer_Add_Cb func, void *data)
209{
210 EINA_SAFETY_ON_NULL_RETURN(provider);
211
212 provider->cb.consumer_add = func;
213 provider->cb.data = data;
214}
215
216EAPI void
217ecore_buffer_provider_consumer_del_cb_set(Ecore_Buffer_Provider *provider, Ecore_Buffer_Provider_Consumer_Del_Cb func, void *data)
218{
219 EINA_SAFETY_ON_NULL_RETURN(provider);
220
221 provider->cb.consumer_del = func;
222 provider->cb.data = data;
223}
224
225EAPI void
226ecore_buffer_provider_buffer_released_cb_set(Ecore_Buffer_Provider *provider, Ecore_Buffer_Provider_Enqueue_Cb func, void *data)
227{
228 EINA_SAFETY_ON_NULL_RETURN(provider);
229
230 provider->cb.enqueue = func;
231 provider->cb.data = data;
232}
233
234static void
235_ecore_buffer_provider_cb_consumer_connected(void *data, struct bq_provider *bq_provider EINA_UNUSED, int32_t queue_size, int32_t width, int32_t height)
236{
237 Ecore_Buffer_Provider *provider = data;
238
239 EINA_SAFETY_ON_NULL_RETURN(provider);
240
241 DBG("Consumer Connected - queue_size %d, size (%dx%d)",
242 queue_size, width, height);
243
244 if (!(provider->ebq = _ecore_buffer_queue_new(width, height, queue_size)))
245 {
246 ERR("Failed to create Ecore_Buffer_Queue - queue_size %d, size (%dx%d)",
247 queue_size, width, height);
248 return;
249 }
250
251 _ecore_buffer_queue_connection_state_set(provider->ebq, EINA_TRUE);
252
253 // set the number of free slot which means allocatable buffer number.
254 provider->free_slot = queue_size;
255
256 // CALLBACK_CALL
257 if (provider->cb.consumer_add)
258 provider->cb.consumer_add(provider, queue_size, width, height, provider->cb.data);
259}
260
261static void
262_ecore_buffer_provider_cb_consumer_disconnected(void *data, struct bq_provider *bq_provider EINA_UNUSED)
263{
264 Ecore_Buffer_Provider *provider = data;
265
266 EINA_SAFETY_ON_NULL_RETURN(provider);
267
268 DBG("Consumer Disconnected");
269
270 _ecore_buffer_queue_connection_state_set(provider->ebq, EINA_FALSE);
271
272 _ecore_buffer_queue_free(provider->ebq);
273 provider->ebq = NULL;
274
275 CALLBACK_CALL(provider, consumer_del);
276}
277
278static void
279_ecore_buffer_provider_cb_add_buffer(void *data, struct bq_provider *bq_provider EINA_UNUSED, struct bq_buffer *buffer, uint32_t serial EINA_UNUSED)
280{
281 Ecore_Buffer_Provider *provider = data;
282 Shared_Buffer *sb = bq_buffer_get_user_data(buffer);
283
284 EINA_SAFETY_ON_NULL_RETURN(provider);
285
286 if (!sb) return;
287
288 DBG("Buffer Enqueued");
289
290 // Mark it as a released buffer.
291 _shared_buffer_state_set(sb, SHARED_BUFFER_STATE_RELEASE);
292 _ecore_buffer_queue_enqueue(provider->ebq, sb);
293
294 CALLBACK_CALL(provider, enqueue);
295}
296
297static void
298_ecore_buffer_provider_cb_buffer_free(Ecore_Buffer *buffer, void *data)
299{
300 Ecore_Buffer_Provider *provider = data;
301 Shared_Buffer *sb = _ecore_buffer_queue_shared_buffer_find(provider->ebq, buffer);
302
303 EINA_SAFETY_ON_NULL_RETURN(provider);
304
305 if (!sb) return;
306
307 _ecore_buffer_provider_shared_buffer_free(provider, sb);
308}
309
310static Shared_Buffer *
311_ecore_buffer_provider_shared_buffer_new(Ecore_Buffer_Provider *provider, Ecore_Buffer *buffer)
312{
313 Shared_Buffer *sb;
314 struct bq_buffer *buf_resource;
315 unsigned int w = 0, h = 0, format = 0;
316 Ecore_Export_Type export_type;
317 int export_id;
318 const char *engine;
319 unsigned int flags;
320
321 EINA_SAFETY_ON_NULL_RETURN_VAL(provider, NULL);
322
323 DBG("Create Shared Buffer - buffer %p", buffer);
324
325 if (!provider->ebq)
326 {
327 WARN("Not connected with consumer yet.");
328 return NULL;
329 }
330
331 ecore_buffer_size_get(buffer, &w, &h);
332 format = ecore_buffer_format_get(buffer);
333 export_type = _ecore_buffer_export(buffer, &export_id);
334 engine = _ecore_buffer_engine_name_get(buffer);
335 flags = ecore_buffer_flags_get(buffer);
336
337 buf_resource = bq_provider_attach_buffer(provider->resource, engine, w, h, format, flags);
338 if (!buf_resource)
339 {
340 ERR("Fail to attach buffer - engine %s, size (%dx%d), format %d, flags %d",
341 engine, w, h, format, flags);
342 return NULL;
343 }
344
345 switch (export_type)
346 {
347 case EXPORT_TYPE_ID:
348 bq_provider_set_buffer_id(provider->resource, buf_resource,
349 export_id, 0, 0, 0, 0, 0, 0);
350 break;
351 case EXPORT_TYPE_FD:
352 bq_provider_set_buffer_fd(provider->resource, buf_resource,
353 export_id, 0, 0, 0, 0, 0, 0);
354 close(export_id);
355 break;
356 default:
357 break;
358 }
359
360 sb = _shared_buffer_new(engine, buf_resource, w, h, format, flags);
361 _shared_buffer_buffer_set(sb, buffer);
362 _ecore_buffer_queue_shared_buffer_add(provider->ebq, sb);
363 bq_buffer_set_user_data(buf_resource, sb);
364
365 ecore_buffer_free_callback_add(buffer, _ecore_buffer_provider_cb_buffer_free, provider);
366
367 return sb;
368}
369
370static void
371_ecore_buffer_provider_shared_buffer_free(Ecore_Buffer_Provider *provider, Shared_Buffer *sb)
372{
373 struct bq_buffer *buf_resource;
374
375 EINA_SAFETY_ON_NULL_RETURN(provider);
376 EINA_SAFETY_ON_NULL_RETURN(sb);
377
378 buf_resource = _shared_buffer_resource_get(sb);
379 if (!buf_resource)
380 return;
381
382 DBG("Free Shared Buffer");
383
384 bq_provider_detach_buffer(provider->resource, buf_resource);
385 bq_buffer_destroy(buf_resource);
386
387 _ecore_buffer_queue_shared_buffer_remove(provider->ebq, sb);
388 _shared_buffer_free(sb);
389
390 provider->free_slot++;
391}
diff --git a/src/lib/ecore_buffer/ecore_buffer_queue_main.c b/src/lib/ecore_buffer/ecore_buffer_queue_main.c
new file mode 100644
index 0000000000..a1883bb3fe
--- /dev/null
+++ b/src/lib/ecore_buffer/ecore_buffer_queue_main.c
@@ -0,0 +1,54 @@
1#include <Ecore_Buffer_Queue.h>
2#include "ecore_buffer_private.h"
3#include "ecore_buffer_con.h"
4
5int _ecore_buffer_queue_log_dom = -1;
6static int _ecore_buffer_queue_init_count = 0;
7
8EAPI int
9ecore_buffer_queue_init(void)
10{
11 if (++_ecore_buffer_queue_init_count != 1)
12 return _ecore_buffer_queue_init_count;
13
14 _ecore_buffer_queue_log_dom =
15 eina_log_domain_register("ecore_buffer_queue", EINA_COLOR_GREEN);
16
17 if (_ecore_buffer_queue_log_dom < 0)
18 {
19 EINA_LOG_ERR("Could not register log domain: ecore_buffer_queue");
20 goto err;
21 }
22
23#ifdef DEBUG
24 eina_log_abort_on_critical_level_set(EINA_LOG_LEVEL_ERR);
25 eina_log_abort_on_critical_set(EINA_TRUE);
26#endif
27
28 DBG("Ecore_Buffer_Queue Init");
29
30 if (!_ecore_buffer_con_init())
31 {
32 eina_log_domain_unregister(_ecore_buffer_queue_log_dom);
33 _ecore_buffer_queue_log_dom = -1;
34 goto err;
35 }
36
37 return _ecore_buffer_queue_init_count;
38err:
39 return --_ecore_buffer_queue_init_count;
40}
41
42EAPI int
43ecore_buffer_queue_shutdown(void)
44{
45 if (--_ecore_buffer_queue_init_count != 0)
46 return _ecore_buffer_queue_init_count;
47
48 DBG("Ecore_Buffer_Queue Shutdown");
49 _ecore_buffer_con_shutdown();
50 eina_log_domain_unregister(_ecore_buffer_queue_log_dom);
51 _ecore_buffer_queue_log_dom = -1;
52
53 return _ecore_buffer_queue_init_count;
54}
diff --git a/src/lib/ecore_buffer/shared_buffer.c b/src/lib/ecore_buffer/shared_buffer.c
new file mode 100644
index 0000000000..82b4836b52
--- /dev/null
+++ b/src/lib/ecore_buffer/shared_buffer.c
@@ -0,0 +1,148 @@
1#include "shared_buffer.h"
2
3struct _Shared_Buffer
4{
5 Ecore_Buffer *buffer;
6 struct bq_buffer *resource;
7 const char *engine;
8 int w, h;
9 int format;
10 unsigned int flags;
11 Shared_Buffer_State state;
12};
13
14Shared_Buffer *
15_shared_buffer_new(const char *engine, struct bq_buffer *resource, int w, int h, int format, unsigned int flags)
16{
17 Shared_Buffer *sb;
18
19 sb = calloc(1, sizeof(Shared_Buffer));
20 if (!sb)
21 return NULL;
22
23 sb->engine = eina_stringshare_add(engine);
24 sb->resource = resource;
25 sb->w = w;
26 sb->h = h;
27 sb->format = format;
28 sb->flags = flags;
29 sb->state = SHARED_BUFFER_STATE_NEW;
30
31 return sb;
32}
33
34void
35_shared_buffer_free(Shared_Buffer *sb)
36{
37 EINA_SAFETY_ON_NULL_RETURN(sb);
38
39 if (sb->engine) eina_stringshare_del(sb->engine);
40 free(sb);
41}
42
43Eina_Bool
44_shared_buffer_info_get(Shared_Buffer *sb, const char **engine, int *w, int *h, int *format, unsigned int *flags)
45{
46 EINA_SAFETY_ON_NULL_RETURN_VAL(sb, EINA_FALSE);
47
48 if (engine) *engine = sb->engine;
49 if (w) *w = sb->w;
50 if (h) *h = sb->h;
51 if (format) *format = sb->format;
52 if (flags) *flags = sb->flags;
53
54 return EINA_TRUE;
55}
56
57Eina_Bool
58_shared_buffer_buffer_set(Shared_Buffer *sb, Ecore_Buffer *buffer)
59{
60 EINA_SAFETY_ON_NULL_RETURN_VAL(sb, EINA_FALSE);
61
62 if (sb->buffer)
63 {
64 ERR("Already exist buffer");
65 return EINA_FALSE;
66 }
67
68 sb->buffer = buffer;
69
70 return EINA_TRUE;
71}
72
73Ecore_Buffer *
74_shared_buffer_buffer_get(Shared_Buffer *sb)
75{
76 EINA_SAFETY_ON_NULL_RETURN_VAL(sb, NULL);
77
78 return sb->buffer;
79}
80
81Eina_Bool
82_shared_buffer_resource_set(Shared_Buffer *sb, struct bq_buffer *resource)
83{
84 EINA_SAFETY_ON_NULL_RETURN_VAL(sb, EINA_FALSE);
85
86 if (sb->resource)
87 {
88 ERR("Already exist resource");
89 return EINA_FALSE;
90 }
91
92 sb->resource = resource;
93
94 return EINA_TRUE;
95}
96
97struct bq_buffer *
98_shared_buffer_resource_get(Shared_Buffer *sb)
99{
100 EINA_SAFETY_ON_NULL_RETURN_VAL(sb, NULL);
101
102 return sb->resource;
103}
104
105void
106_shared_buffer_state_set(Shared_Buffer *sb, Shared_Buffer_State state)
107{
108 EINA_SAFETY_ON_NULL_RETURN(sb);
109
110 sb->state = state;
111}
112
113Shared_Buffer_State
114_shared_buffer_state_get(Shared_Buffer *sb)
115{
116 EINA_SAFETY_ON_NULL_RETURN_VAL(sb, SHARED_BUFFER_STATE_UNKNOWN);
117
118 return sb->state;
119}
120
121const char *
122_shared_buffer_state_string_get(Shared_Buffer *sb)
123{
124 EINA_SAFETY_ON_NULL_RETURN_VAL(sb, "INVAILD OBJECT");
125
126 switch (sb->state)
127 {
128 case SHARED_BUFFER_STATE_ENQUEUE:
129 return "SHARED_BUFFER_STATE_ENQUEUE";
130 case SHARED_BUFFER_STATE_SUBMIT:
131 return "SHARED_BUFFER_STATE_SUBMIT";
132 case SHARED_BUFFER_STATE_DEQUEUE:
133 return "SHARED_BUFFER_STATE_DEQUEUE";
134 case SHARED_BUFFER_STATE_ATTACH:
135 return "SHARED_BUFFER_STATE_ATTACH";
136 case SHARED_BUFFER_STATE_IMPORT:
137 return "SHARED_BUFFER_STATE_IMPORT";
138 case SHARED_BUFFER_STATE_DETACH:
139 return "SHARED_BUFFER_STATE_DETACH";
140 case SHARED_BUFFER_STATE_ACQUIRE:
141 return "SHARED_BUFFER_STATE_ACQUIRE";
142 case SHARED_BUFFER_STATE_RELEASE:
143 return "SHARED_BUFFER_STATE_RELEASE";
144 default:
145 case SHARED_BUFFER_STATE_UNKNOWN:
146 return "SHARED_BUFFER_STATE_UNKNOWN";
147 }
148}
diff --git a/src/lib/ecore_buffer/shared_buffer.h b/src/lib/ecore_buffer/shared_buffer.h
new file mode 100644
index 0000000000..ce168de3dd
--- /dev/null
+++ b/src/lib/ecore_buffer/shared_buffer.h
@@ -0,0 +1,41 @@
1#ifndef _SHARED_BUFFER_H_
2# define _SHARED_BUFFER_H_
3
4#include <stdio.h>
5#include <Eina.h>
6#include <Ecore_Buffer.h>
7
8#include "bq_mgr_protocol.h"
9#include "ecore_buffer_private.h"
10
11typedef struct _Shared_Buffer Shared_Buffer;
12
13typedef enum _Shared_Buffer_State
14{
15 // common
16 SHARED_BUFFER_STATE_UNKNOWN,
17 SHARED_BUFFER_STATE_ENQUEUE,
18 // provider side type
19 SHARED_BUFFER_STATE_NEW,
20 SHARED_BUFFER_STATE_SUBMIT,
21 SHARED_BUFFER_STATE_DEQUEUE,
22 // consumer side type
23 SHARED_BUFFER_STATE_ATTACH,
24 SHARED_BUFFER_STATE_IMPORT,
25 SHARED_BUFFER_STATE_DETACH,
26 SHARED_BUFFER_STATE_ACQUIRE,
27 SHARED_BUFFER_STATE_RELEASE,
28} Shared_Buffer_State;
29
30Shared_Buffer *_shared_buffer_new(const char *engine, struct bq_buffer *resource, int w, int h, int format, unsigned int flags);
31void _shared_buffer_free(Shared_Buffer *sb);
32Eina_Bool _shared_buffer_info_get(Shared_Buffer *sb, const char **engine, int *w, int *h, int *format, unsigned int *flags);
33Eina_Bool _shared_buffer_buffer_set(Shared_Buffer *sb, Ecore_Buffer *buffer);
34Ecore_Buffer *_shared_buffer_buffer_get(Shared_Buffer *sb);
35Eina_Bool _shared_buffer_resource_set(Shared_Buffer *sb, struct bq_buffer *resource);
36struct bq_buffer *_shared_buffer_resource_get(Shared_Buffer *sb);
37void _shared_buffer_state_set(Shared_Buffer *sb, Shared_Buffer_State state);
38Shared_Buffer_State _shared_buffer_state_get(Shared_Buffer *sb);
39const char *_shared_buffer_state_string_get(Shared_Buffer *sb);
40
41#endif /* _SHARED_BUFFER_H_ */