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 12:06:40 -0600
committerDerek Foreman <derekf@osg.samsung.com>2018-01-26 15:54:00 -0600
commit044106c8a28f03b63bac55b3bbd8db968f781e8f (patch)
tree8b53576b26f8665df91f93516e9e51286a972916 /src/lib/ecore_wl2/ecore_wl2_surface.c
parent7c026c52ccb057ec843ec2f917c82f0ec8f8d0cc (diff)
ecore_wl2: Move backend specific members into a private data struct
buffers and current buffers are really specific to the dmabuf backend, another plug-in might not need them.
Diffstat (limited to 'src/lib/ecore_wl2/ecore_wl2_surface.c')
-rw-r--r--src/lib/ecore_wl2/ecore_wl2_surface.c80
1 files changed, 50 insertions, 30 deletions
diff --git a/src/lib/ecore_wl2/ecore_wl2_surface.c b/src/lib/ecore_wl2/ecore_wl2_surface.c
index cfc7792b86..bfabd9172d 100644
--- a/src/lib/ecore_wl2/ecore_wl2_surface.c
+++ b/src/lib/ecore_wl2/ecore_wl2_surface.c
@@ -10,6 +10,11 @@
10#include "linux-dmabuf-unstable-v1-client-protocol.h" 10#include "linux-dmabuf-unstable-v1-client-protocol.h"
11 11
12#define MAX_BUFFERS 4 12#define MAX_BUFFERS 4
13typedef struct _Ecore_Wl2_Dmabuf_Private
14{
15 Ecore_Wl2_Buffer *current;
16 Eina_List *buffers;
17} Ecore_Wl2_Dmabuf_Private;
13 18
14static Eina_Bool 19static Eina_Bool
15_evas_dmabuf_surface_check(Ecore_Wl2_Window *win) 20_evas_dmabuf_surface_check(Ecore_Wl2_Window *win)
@@ -30,30 +35,36 @@ _evas_dmabuf_surface_check(Ecore_Wl2_Window *win)
30} 35}
31 36
32static void 37static void
33_evas_dmabuf_surface_reconfigure(Ecore_Wl2_Surface *s, int w, int h, uint32_t flags EINA_UNUSED) 38_evas_dmabuf_surface_reconfigure(Ecore_Wl2_Surface *s EINA_UNUSED, void *priv_data, int w, int h, uint32_t flags EINA_UNUSED)
34{ 39{
40 Ecore_Wl2_Dmabuf_Private *p;
35 Ecore_Wl2_Buffer *b; 41 Ecore_Wl2_Buffer *b;
36 Eina_List *l, *tmp; 42 Eina_List *l, *tmp;
37 43
44 p = priv_data;
45
38 if ((!w) || (!h)) return; 46 if ((!w) || (!h)) return;
39 EINA_LIST_FOREACH_SAFE(s->buffers, l, tmp, b) 47 EINA_LIST_FOREACH_SAFE(p->buffers, l, tmp, b)
40 { 48 {
41 if (ecore_wl2_buffer_fit(b, w, h)) 49 if (ecore_wl2_buffer_fit(b, w, h))
42 continue; 50 continue;
43 51
44 ecore_wl2_buffer_destroy(b); 52 ecore_wl2_buffer_destroy(b);
45 s->buffers = eina_list_remove_list(s->buffers, l); 53 p->buffers = eina_list_remove_list(p->buffers, l);
46 } 54 }
47} 55}
48 56
49static void * 57static void *
50_evas_dmabuf_surface_data_get(Ecore_Wl2_Surface *s, int *w, int *h) 58_evas_dmabuf_surface_data_get(Ecore_Wl2_Surface *s EINA_UNUSED, void *priv_data, int *w, int *h)
51{ 59{
60 Ecore_Wl2_Dmabuf_Private *p;
52 Ecore_Wl2_Buffer *b; 61 Ecore_Wl2_Buffer *b;
53 void *ptr; 62 void *ptr;
54 int stride; 63 int stride;
55 64
56 b = s->current; 65 p = priv_data;
66
67 b = p->current;
57 if (!b) return NULL; 68 if (!b) return NULL;
58 69
59 ptr = ecore_wl2_buffer_map(b, NULL, h, &stride); 70 ptr = ecore_wl2_buffer_map(b, NULL, h, &stride);
@@ -68,14 +79,14 @@ _evas_dmabuf_surface_data_get(Ecore_Wl2_Surface *s, int *w, int *h)
68} 79}
69 80
70static Ecore_Wl2_Buffer * 81static Ecore_Wl2_Buffer *
71_evas_dmabuf_surface_wait(Ecore_Wl2_Surface *s) 82_evas_dmabuf_surface_wait(Ecore_Wl2_Surface *s, Ecore_Wl2_Dmabuf_Private *p)
72{ 83{
73 Ecore_Wl2_Buffer *b, *best = NULL; 84 Ecore_Wl2_Buffer *b, *best = NULL;
74 Eina_List *l; 85 Eina_List *l;
75 int best_age = -1; 86 int best_age = -1;
76 int age; 87 int age;
77 88
78 EINA_LIST_FOREACH(s->buffers, l, b) 89 EINA_LIST_FOREACH(p->buffers, l, b)
79 { 90 {
80 if (ecore_wl2_buffer_busy_get(b)) continue; 91 if (ecore_wl2_buffer_busy_get(b)) continue;
81 age = ecore_wl2_buffer_age_get(b); 92 age = ecore_wl2_buffer_age_get(b);
@@ -86,24 +97,26 @@ _evas_dmabuf_surface_wait(Ecore_Wl2_Surface *s)
86 } 97 }
87 } 98 }
88 99
89 if (!best && (eina_list_count(s->buffers) < MAX_BUFFERS)) 100 if (!best && (eina_list_count(p->buffers) < MAX_BUFFERS))
90 { 101 {
91 best = ecore_wl2_surface_buffer_create(s); 102 best = ecore_wl2_surface_buffer_create(s);
92 /* Start at -1 so it's age is incremented to 0 for first draw */ 103 /* Start at -1 so it's age is incremented to 0 for first draw */
93 ecore_wl2_buffer_age_set(best, -1); 104 ecore_wl2_buffer_age_set(best, -1);
94 s->buffers = eina_list_append(s->buffers, best); 105 p->buffers = eina_list_append(p->buffers, best);
95 } 106 }
96 return best; 107 return best;
97} 108}
98 109
99static int 110static int
100_evas_dmabuf_surface_assign(Ecore_Wl2_Surface *s) 111_evas_dmabuf_surface_assign(Ecore_Wl2_Surface *s, void *priv_data)
101{ 112{
113 Ecore_Wl2_Dmabuf_Private *p;
102 Ecore_Wl2_Buffer *b; 114 Ecore_Wl2_Buffer *b;
103 Eina_List *l; 115 Eina_List *l;
104 116
105 s->current = _evas_dmabuf_surface_wait(s); 117 p = priv_data;
106 if (!s->current) 118 p->current = _evas_dmabuf_surface_wait(s, p);
119 if (!p->current)
107 { 120 {
108 /* Should be unreachable and will result in graphical 121 /* Should be unreachable and will result in graphical
109 * anomalies - we should probably blow away all the 122 * anomalies - we should probably blow away all the
@@ -111,27 +124,30 @@ _evas_dmabuf_surface_assign(Ecore_Wl2_Surface *s)
111 * see this happen... 124 * see this happen...
112 */ 125 */
113 WRN("No free DMAbuf buffers, dropping a frame"); 126 WRN("No free DMAbuf buffers, dropping a frame");
114 EINA_LIST_FOREACH(s->buffers, l, b) 127 EINA_LIST_FOREACH(p->buffers, l, b)
115 ecore_wl2_buffer_age_set(b, 0); 128 ecore_wl2_buffer_age_set(b, 0);
116 return 0; 129 return 0;
117 } 130 }
118 EINA_LIST_FOREACH(s->buffers, l, b) 131 EINA_LIST_FOREACH(p->buffers, l, b)
119 ecore_wl2_buffer_age_inc(b); 132 ecore_wl2_buffer_age_inc(b);
120 133
121 return ecore_wl2_buffer_age_get(s->current); 134 return ecore_wl2_buffer_age_get(p->current);
122} 135}
123 136
124static void 137static void
125_evas_dmabuf_surface_post(Ecore_Wl2_Surface *s, Eina_Rectangle *rects, unsigned int count) 138_evas_dmabuf_surface_post(Ecore_Wl2_Surface *s, void *priv_data, Eina_Rectangle *rects, unsigned int count)
126{ 139{
140 Ecore_Wl2_Dmabuf_Private *p;
127 Ecore_Wl2_Buffer *b; 141 Ecore_Wl2_Buffer *b;
128 142
129 b = s->current; 143 p = priv_data;
144
145 b = p->current;
130 if (!b) return; 146 if (!b) return;
131 147
132 ecore_wl2_buffer_unlock(b); 148 ecore_wl2_buffer_unlock(b);
133 149
134 s->current = NULL; 150 p->current = NULL;
135 ecore_wl2_buffer_busy_set(b); 151 ecore_wl2_buffer_busy_set(b);
136 ecore_wl2_buffer_age_set(b, 0); 152 ecore_wl2_buffer_age_set(b, 0);
137 153
@@ -142,24 +158,26 @@ _evas_dmabuf_surface_post(Ecore_Wl2_Surface *s, Eina_Rectangle *rects, unsigned
142} 158}
143 159
144static void 160static void
145_evas_dmabuf_surface_destroy(Ecore_Wl2_Surface *s) 161_evas_dmabuf_surface_destroy(Ecore_Wl2_Surface *s EINA_UNUSED, void *priv_data)
146{ 162{
163 Ecore_Wl2_Dmabuf_Private *p;
147 Ecore_Wl2_Buffer *b; 164 Ecore_Wl2_Buffer *b;
148 165
149 if (!s) return; 166 p = priv_data;
150 167
151 EINA_LIST_FREE(s->buffers, b) 168 EINA_LIST_FREE(p->buffers, b)
152 ecore_wl2_buffer_destroy(b); 169 ecore_wl2_buffer_destroy(b);
153} 170}
154 171
155static void 172static void
156_surface_flush(Ecore_Wl2_Surface *surface) 173_surface_flush(Ecore_Wl2_Surface *surface EINA_UNUSED, void *priv_data)
157{ 174{
175 Ecore_Wl2_Dmabuf_Private *p;
158 Ecore_Wl2_Buffer *b; 176 Ecore_Wl2_Buffer *b;
159 177
160 EINA_SAFETY_ON_NULL_RETURN(surface); 178 p = priv_data;
161 179
162 EINA_LIST_FREE(surface->buffers, b) 180 EINA_LIST_FREE(p->buffers, b)
163 ecore_wl2_buffer_destroy(b); 181 ecore_wl2_buffer_destroy(b);
164} 182}
165 183
@@ -169,7 +187,7 @@ ecore_wl2_surface_destroy(Ecore_Wl2_Surface *surface)
169{ 187{
170 EINA_SAFETY_ON_NULL_RETURN(surface); 188 EINA_SAFETY_ON_NULL_RETURN(surface);
171 189
172 surface->funcs->destroy(surface); 190 surface->funcs->destroy(surface, surface->private_data);
173 surface->wl2_win = NULL; 191 surface->wl2_win = NULL;
174 192
175 free(surface); 193 free(surface);
@@ -180,7 +198,7 @@ ecore_wl2_surface_reconfigure(Ecore_Wl2_Surface *surface, int w, int h, uint32_t
180{ 198{
181 EINA_SAFETY_ON_NULL_RETURN(surface); 199 EINA_SAFETY_ON_NULL_RETURN(surface);
182 200
183 surface->funcs->reconfigure(surface, w, h, flags); 201 surface->funcs->reconfigure(surface, surface->private_data, w, h, flags);
184 surface->w = w; 202 surface->w = w;
185 surface->h = h; 203 surface->h = h;
186} 204}
@@ -190,7 +208,7 @@ ecore_wl2_surface_data_get(Ecore_Wl2_Surface *surface, int *w, int *h)
190{ 208{
191 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, NULL); 209 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, NULL);
192 210
193 return surface->funcs->data_get(surface, w, h); 211 return surface->funcs->data_get(surface, surface->private_data, w, h);
194} 212}
195 213
196EAPI int 214EAPI int
@@ -198,7 +216,7 @@ ecore_wl2_surface_assign(Ecore_Wl2_Surface *surface)
198{ 216{
199 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0); 217 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0);
200 218
201 return surface->funcs->assign(surface); 219 return surface->funcs->assign(surface, surface->private_data);
202} 220}
203 221
204EAPI void 222EAPI void
@@ -206,7 +224,7 @@ ecore_wl2_surface_post(Ecore_Wl2_Surface *surface, Eina_Rectangle *rects, unsign
206{ 224{
207 EINA_SAFETY_ON_NULL_RETURN(surface); 225 EINA_SAFETY_ON_NULL_RETURN(surface);
208 226
209 surface->funcs->post(surface, rects, count); 227 surface->funcs->post(surface, surface->private_data, rects, count);
210} 228}
211 229
212EAPI void 230EAPI void
@@ -214,7 +232,7 @@ ecore_wl2_surface_flush(Ecore_Wl2_Surface *surface)
214{ 232{
215 EINA_SAFETY_ON_NULL_RETURN(surface); 233 EINA_SAFETY_ON_NULL_RETURN(surface);
216 234
217 surface->funcs->flush(surface); 235 surface->funcs->flush(surface, surface->private_data);
218} 236}
219 237
220static Ecore_Wl2_Surface_Interface dmabuf_smanager = 238static Ecore_Wl2_Surface_Interface dmabuf_smanager =
@@ -239,6 +257,8 @@ ecore_wl2_surface_create(Ecore_Wl2_Window *win, Eina_Bool alpha)
239 257
240 out = calloc(1, sizeof(*out)); 258 out = calloc(1, sizeof(*out));
241 if (!out) return NULL; 259 if (!out) return NULL;
260 out->private_data = calloc(1, sizeof(Ecore_Wl2_Dmabuf_Private));
261 if (!out->private_data) return NULL;
242 out->wl2_win = win; 262 out->wl2_win = win;
243 out->alpha = alpha; 263 out->alpha = alpha;
244 out->w = 0; 264 out->w = 0;