summaryrefslogtreecommitdiff
path: root/src/lib/ecore_buffer/shared_buffer.c
diff options
context:
space:
mode:
authorSeunghun Lee <beauty.positive3@gmail.com>2015-06-22 10:23:54 -0400
committerChris Michael <cp.michael@samsung.com>2015-06-22 10:31:42 -0400
commit8b621775619b9959fe952b095b3baaa7aaa99572 (patch)
tree99059a841a79729cac4687ea41f3abf672e6e455 /src/lib/ecore_buffer/shared_buffer.c
parent3671506ad39d2a956e388e151bd20f1b9ffd62a5 (diff)
ecore-buffer: Add ecore_buffer library to EFL.
Summary: Ecore_Buffer is abstraction of graphic buffer. it supports backend of shm, x11_dri2 and x11_dri3 for now, and this library also provides method to share buffers between processes. Ecore_Buffer_Provider and Ecore_Buffer_Consumer is for this, sharing buffer. provider draws something in to Ecore_Buffer, and consumer receives and displays it. the binary, bq_mgr is a connection maker for buffer provider and consumer. it can be included Enlightenment as a deamon later. @feature Test Plan: 1. Configure with --enable-ecore-buffer and --enable-always-build-examples to build examples. 2. Run bq_mgr, it connects consumer and provider. 3. Run ecore_buffer_provider_example and ecore_buffer_consumer_example Reviewers: lsj119, gwanglim, cedric, zmike, jpeg, raster, devilhorns Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2197
Diffstat (limited to 'src/lib/ecore_buffer/shared_buffer.c')
-rw-r--r--src/lib/ecore_buffer/shared_buffer.c148
1 files changed, 148 insertions, 0 deletions
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}