summaryrefslogtreecommitdiff
path: root/src/lib/ecore_wl2/ecore_wl2_surface.c
diff options
context:
space:
mode:
authorDerek Foreman <derekf@osg.samsung.com>2018-01-26 14:32:10 -0600
committerDerek Foreman <derekf@osg.samsung.com>2018-01-26 15:54:00 -0600
commit376d8d1e36f903082212ffa0ce1bc0178b323ac2 (patch)
tree0d40df971edb8cc6731167dc5d766398495221be /src/lib/ecore_wl2/ecore_wl2_surface.c
parent3e230693e62696f32bc8ab64619843f2507ed393 (diff)
ecore_wl2: Make surface managers modular
This allows loading modules to handle wayland surfaces, and makes the existing dmabuf manager a module.
Diffstat (limited to 'src/lib/ecore_wl2/ecore_wl2_surface.c')
-rw-r--r--src/lib/ecore_wl2/ecore_wl2_surface.c214
1 files changed, 0 insertions, 214 deletions
diff --git a/src/lib/ecore_wl2/ecore_wl2_surface.c b/src/lib/ecore_wl2/ecore_wl2_surface.c
index 255188207b..c3a791f7c8 100644
--- a/src/lib/ecore_wl2/ecore_wl2_surface.c
+++ b/src/lib/ecore_wl2/ecore_wl2_surface.c
@@ -7,199 +7,9 @@
7#include <sys/types.h> 7#include <sys/types.h>
8#include <sys/stat.h> 8#include <sys/stat.h>
9 9
10#include "linux-dmabuf-unstable-v1-client-protocol.h"
11
12#define MAX_BUFFERS 4
13
14static Eina_List *_smanagers = NULL; 10static Eina_List *_smanagers = NULL;
15static int _smanager_count = 0; 11static int _smanager_count = 0;
16 12
17int ECORE_WL2_SURFACE_DMABUF = 0;
18
19typedef struct _Ecore_Wl2_Dmabuf_Private
20{
21 Ecore_Wl2_Buffer *current;
22 Eina_List *buffers;
23} Ecore_Wl2_Dmabuf_Private;
24
25static void *
26_evas_dmabuf_surface_setup(Ecore_Wl2_Window *win)
27{
28 Ecore_Wl2_Dmabuf_Private *priv;
29 Ecore_Wl2_Display *ewd;
30 Ecore_Wl2_Buffer_Type types = 0;
31
32 priv = calloc(1, sizeof(*priv));
33 if (!priv) return NULL;
34
35 ewd = ecore_wl2_window_display_get(win);
36 if (ecore_wl2_display_shm_get(ewd))
37 types |= ECORE_WL2_BUFFER_SHM;
38 if (ecore_wl2_display_dmabuf_get(ewd))
39 types |= ECORE_WL2_BUFFER_DMABUF;
40
41 if (!ecore_wl2_buffer_init(ewd, types))
42 {
43 free(priv);
44 return NULL;
45 }
46
47 return priv;
48}
49
50static void
51_evas_dmabuf_surface_reconfigure(Ecore_Wl2_Surface *s EINA_UNUSED, void *priv_data, int w, int h, uint32_t flags EINA_UNUSED)
52{
53 Ecore_Wl2_Dmabuf_Private *p;
54 Ecore_Wl2_Buffer *b;
55 Eina_List *l, *tmp;
56
57 p = priv_data;
58
59 if ((!w) || (!h)) return;
60 EINA_LIST_FOREACH_SAFE(p->buffers, l, tmp, b)
61 {
62 if (ecore_wl2_buffer_fit(b, w, h))
63 continue;
64
65 ecore_wl2_buffer_destroy(b);
66 p->buffers = eina_list_remove_list(p->buffers, l);
67 }
68}
69
70static void *
71_evas_dmabuf_surface_data_get(Ecore_Wl2_Surface *s EINA_UNUSED, void *priv_data, int *w, int *h)
72{
73 Ecore_Wl2_Dmabuf_Private *p;
74 Ecore_Wl2_Buffer *b;
75 void *ptr;
76 int stride;
77
78 p = priv_data;
79
80 b = p->current;
81 if (!b) return NULL;
82
83 ptr = ecore_wl2_buffer_map(b, NULL, h, &stride);
84 if (!ptr) return NULL;
85
86 /* We return stride/bpp because it may not match the allocated
87 * width. evas will figure out the clipping
88 */
89 if (w) *w = stride / 4;
90
91 return ptr;
92}
93
94static Ecore_Wl2_Buffer *
95_evas_dmabuf_surface_wait(Ecore_Wl2_Surface *s, Ecore_Wl2_Dmabuf_Private *p)
96{
97 Ecore_Wl2_Buffer *b, *best = NULL;
98 Eina_List *l;
99 int best_age = -1;
100 int age;
101
102 EINA_LIST_FOREACH(p->buffers, l, b)
103 {
104 if (ecore_wl2_buffer_busy_get(b)) continue;
105 age = ecore_wl2_buffer_age_get(b);
106 if (age > best_age)
107 {
108 best = b;
109 best_age = age;
110 }
111 }
112
113 if (!best && (eina_list_count(p->buffers) < MAX_BUFFERS))
114 {
115 best = ecore_wl2_surface_buffer_create(s);
116 /* Start at -1 so it's age is incremented to 0 for first draw */
117 ecore_wl2_buffer_age_set(best, -1);
118 p->buffers = eina_list_append(p->buffers, best);
119 }
120 return best;
121}
122
123static int
124_evas_dmabuf_surface_assign(Ecore_Wl2_Surface *s, void *priv_data)
125{
126 Ecore_Wl2_Dmabuf_Private *p;
127 Ecore_Wl2_Buffer *b;
128 Eina_List *l;
129
130 p = priv_data;
131 p->current = _evas_dmabuf_surface_wait(s, p);
132 if (!p->current)
133 {
134 /* Should be unreachable and will result in graphical
135 * anomalies - we should probably blow away all the
136 * existing buffers and start over if we actually
137 * see this happen...
138 */
139 WRN("No free DMAbuf buffers, dropping a frame");
140 EINA_LIST_FOREACH(p->buffers, l, b)
141 ecore_wl2_buffer_age_set(b, 0);
142 return 0;
143 }
144 EINA_LIST_FOREACH(p->buffers, l, b)
145 ecore_wl2_buffer_age_inc(b);
146
147 return ecore_wl2_buffer_age_get(p->current);
148}
149
150static void
151_evas_dmabuf_surface_post(Ecore_Wl2_Surface *s, void *priv_data, Eina_Rectangle *rects, unsigned int count)
152{
153 Ecore_Wl2_Dmabuf_Private *p;
154 Ecore_Wl2_Buffer *b;
155 Ecore_Wl2_Window *win;
156 struct wl_buffer *wlb;
157
158 p = priv_data;
159
160 b = p->current;
161 if (!b) return;
162
163 ecore_wl2_buffer_unlock(b);
164
165 p->current = NULL;
166 ecore_wl2_buffer_busy_set(b);
167 ecore_wl2_buffer_age_set(b, 0);
168
169 win = ecore_wl2_surface_window_get(s);
170
171 wlb = ecore_wl2_buffer_wl_buffer_get(b);
172 ecore_wl2_window_buffer_attach(win, wlb, 0, 0, EINA_FALSE);
173 ecore_wl2_window_damage(win, rects, count);
174
175 ecore_wl2_window_commit(win, EINA_TRUE);
176}
177
178static void
179_evas_dmabuf_surface_destroy(Ecore_Wl2_Surface *s EINA_UNUSED, void *priv_data)
180{
181 Ecore_Wl2_Dmabuf_Private *p;
182 Ecore_Wl2_Buffer *b;
183
184 p = priv_data;
185
186 EINA_LIST_FREE(p->buffers, b)
187 ecore_wl2_buffer_destroy(b);
188}
189
190static void
191_evas_dmabuf_surface_flush(Ecore_Wl2_Surface *surface EINA_UNUSED, void *priv_data)
192{
193 Ecore_Wl2_Dmabuf_Private *p;
194 Ecore_Wl2_Buffer *b;
195
196 p = priv_data;
197
198 EINA_LIST_FREE(p->buffers, b)
199 ecore_wl2_buffer_destroy(b);
200}
201
202
203EAPI void 13EAPI void
204ecore_wl2_surface_destroy(Ecore_Wl2_Surface *surface) 14ecore_wl2_surface_destroy(Ecore_Wl2_Surface *surface)
205{ 15{
@@ -253,18 +63,6 @@ ecore_wl2_surface_flush(Ecore_Wl2_Surface *surface)
253 surface->funcs->flush(surface, surface->private_data); 63 surface->funcs->flush(surface, surface->private_data);
254} 64}
255 65
256static Ecore_Wl2_Surface_Interface dmabuf_smanager =
257{
258 .version = 1,
259 .setup = _evas_dmabuf_surface_setup,
260 .destroy = _evas_dmabuf_surface_destroy,
261 .reconfigure = _evas_dmabuf_surface_reconfigure,
262 .data_get = _evas_dmabuf_surface_data_get,
263 .assign = _evas_dmabuf_surface_assign,
264 .post = _evas_dmabuf_surface_post,
265 .flush = _evas_dmabuf_surface_flush
266};
267
268EAPI Ecore_Wl2_Surface * 66EAPI Ecore_Wl2_Surface *
269ecore_wl2_surface_create(Ecore_Wl2_Window *win, Eina_Bool alpha) 67ecore_wl2_surface_create(Ecore_Wl2_Window *win, Eina_Bool alpha)
270{ 68{
@@ -337,15 +135,3 @@ ecore_wl2_surface_window_get(Ecore_Wl2_Surface *surface)
337 135
338 return surface->wl2_win; 136 return surface->wl2_win;
339} 137}
340
341/* TEMPORARY HACK FOR TESTING */
342Eina_Bool
343ecore_wl2_surface_manager_dmabuf_add(void)
344{
345 ECORE_WL2_SURFACE_DMABUF = ecore_wl2_surface_manager_add(&dmabuf_smanager);
346
347 if (ECORE_WL2_SURFACE_DMABUF < 1)
348 return EINA_FALSE;
349
350 return EINA_TRUE;
351}