]>
Commit | Line | Data |
---|---|---|
4469c4e7 AF |
1 | From 6a973189d22ae1fef08e90ab6a8f6ee18ad4f33e Mon Sep 17 00:00:00 2001 |
2 | From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com> | |
3 | Date: Thu, 18 Jul 2013 15:11:23 +0300 | |
4 | Subject: [PATCH 1/4] gallium-egl: Simplify native_wayland_drm_bufmgr_helper | |
5 | interface | |
6 | ||
7 | The helper provides a series of functions to easy the implementation | |
8 | of the WL_bind_wayland_display extension on different platforms. But | |
9 | even with the helpers there was still a bit of duplicated code between | |
10 | platforms, with the drm authentication being the only part that | |
11 | differs. | |
12 | ||
13 | This patch changes the bufmgr interface to provide a self contained | |
14 | object with a create function that takes a drm authentication callback | |
15 | as an argument. That way all the helper functions are made static and | |
16 | the "_helper" suffix was removed from the sources file name. | |
17 | ||
18 | This change also removes the mix of Wayland client and server code in | |
19 | the wayland drm platform source file. All the uses of libwayland-server | |
20 | are now contained in native_wayland_drm_bufmgr.c. | |
21 | ||
22 | Changes to the drm platform are only compile tested. | |
23 | ||
24 | Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com> | |
25 | --- | |
26 | src/gallium/state_trackers/egl/Makefile.am | 2 +- | |
27 | src/gallium/state_trackers/egl/common/native.h | 2 +- | |
28 | .../egl/common/native_wayland_drm_bufmgr.c | 214 +++++++++++++++++++++ | |
29 | ...bufmgr_helper.h => native_wayland_drm_bufmgr.h} | 26 +-- | |
30 | .../egl/common/native_wayland_drm_bufmgr_helper.c | 106 ---------- | |
31 | src/gallium/state_trackers/egl/drm/native_drm.c | 52 +---- | |
32 | src/gallium/state_trackers/egl/drm/native_drm.h | 2 +- | |
33 | .../state_trackers/egl/wayland/native_drm.c | 93 +++------ | |
34 | src/gallium/state_trackers/egl/x11/native_dri2.c | 87 +++------ | |
35 | 9 files changed, 276 insertions(+), 308 deletions(-) | |
36 | create mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c | |
37 | rename src/gallium/state_trackers/egl/common/{native_wayland_drm_bufmgr_helper.h => native_wayland_drm_bufmgr.h} (59%) | |
38 | delete mode 100644 src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c | |
39 | ||
40 | diff --git a/src/gallium/state_trackers/egl/Makefile.am b/src/gallium/state_trackers/egl/Makefile.am | |
41 | index f78b36e..126fafc 100644 | |
42 | --- a/src/gallium/state_trackers/egl/Makefile.am | |
43 | +++ b/src/gallium/state_trackers/egl/Makefile.am | |
44 | @@ -38,7 +38,7 @@ libegl_la_SOURCES = \ | |
45 | common/egl_g3d_st.c \ | |
46 | common/egl_g3d_sync.c \ | |
47 | common/native_helper.c \ | |
48 | - common/native_wayland_drm_bufmgr_helper.c | |
49 | + common/native_wayland_drm_bufmgr.c | |
50 | ||
51 | if HAVE_EGL_PLATFORM_X11 | |
52 | libegl_la_SOURCES += \ | |
53 | diff --git a/src/gallium/state_trackers/egl/common/native.h b/src/gallium/state_trackers/egl/common/native.h | |
54 | index 431bd3f..797933d 100644 | |
55 | --- a/src/gallium/state_trackers/egl/common/native.h | |
56 | +++ b/src/gallium/state_trackers/egl/common/native.h | |
57 | @@ -245,7 +245,7 @@ struct native_display { | |
58 | ||
59 | const struct native_display_buffer *buffer; | |
60 | const struct native_display_modeset *modeset; | |
61 | - const struct native_display_wayland_bufmgr *wayland_bufmgr; | |
62 | + struct native_display_wayland_bufmgr *wayland_bufmgr; | |
4469c4e7 | 63 | |
68738647 JB |
64 | #ifdef HAVE_WAYLAND_BACKEND |
65 | struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */ | |
4469c4e7 AF |
66 | diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c |
67 | new file mode 100644 | |
68 | index 0000000..1603a3a | |
69 | --- /dev/null | |
70 | +++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.c | |
71 | @@ -0,0 +1,214 @@ | |
72 | +#include <stdint.h> | |
73 | +#include <string.h> | |
74 | + | |
75 | +#include "native.h" | |
76 | +#include "util/u_inlines.h" | |
77 | +#include "state_tracker/drm_driver.h" | |
78 | + | |
79 | +#ifdef HAVE_WAYLAND_BACKEND | |
80 | + | |
81 | +#include <wayland-server.h> | |
82 | +#include <wayland-drm-server-protocol.h> | |
83 | + | |
84 | +#include "native_wayland_drm_bufmgr.h" | |
85 | + | |
86 | +#include "wayland-drm.h" | |
87 | + | |
88 | +struct wayland_drm_bufmgr { | |
89 | + struct native_display_wayland_bufmgr base; | |
90 | + | |
91 | + struct wl_drm *wl_server_drm; | |
92 | + char *device_name; | |
93 | + | |
94 | + void *user_data; | |
95 | + | |
96 | + wayland_drm_bufmgr_authenticate_func authenticate; | |
97 | +}; | |
98 | + | |
99 | +static INLINE struct wayland_drm_bufmgr * | |
100 | +wayland_drm_bufmgr(const struct native_display_wayland_bufmgr *base) | |
101 | +{ | |
102 | + return (struct wayland_drm_bufmgr *) base; | |
103 | +} | |
104 | + | |
105 | +static int | |
106 | +wayland_drm_bufmgr_authenticate(void *user_data, uint32_t magic) | |
107 | +{ | |
108 | + struct native_display *ndpy = user_data; | |
109 | + struct wayland_drm_bufmgr *bufmgr; | |
110 | + | |
111 | + bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr); | |
112 | + | |
113 | + return bufmgr->authenticate(user_data, magic); | |
114 | +} | |
115 | + | |
116 | +static void | |
117 | +wayland_drm_bufmgr_reference_buffer(void *user_data, uint32_t name, int fd, | |
118 | + struct wl_drm_buffer *buffer) | |
119 | +{ | |
120 | + struct native_display *ndpy = user_data; | |
121 | + struct pipe_resource templ; | |
122 | + struct winsys_handle wsh; | |
123 | + enum pipe_format pf; | |
124 | + | |
125 | + switch (buffer->format) { | |
126 | + case WL_DRM_FORMAT_ARGB8888: | |
127 | + pf = PIPE_FORMAT_B8G8R8A8_UNORM; | |
128 | + break; | |
129 | + case WL_DRM_FORMAT_XRGB8888: | |
130 | + pf = PIPE_FORMAT_B8G8R8X8_UNORM; | |
131 | + break; | |
132 | + default: | |
133 | + pf = PIPE_FORMAT_NONE; | |
134 | + break; | |
135 | + } | |
136 | + | |
137 | + if (pf == PIPE_FORMAT_NONE) | |
138 | + return; | |
139 | + | |
140 | + memset(&templ, 0, sizeof(templ)); | |
141 | + templ.target = PIPE_TEXTURE_2D; | |
142 | + templ.format = pf; | |
143 | + templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; | |
144 | + templ.width0 = buffer->buffer.width; | |
145 | + templ.height0 = buffer->buffer.height; | |
146 | + templ.depth0 = 1; | |
147 | + templ.array_size = 1; | |
148 | + | |
149 | + memset(&wsh, 0, sizeof(wsh)); | |
150 | + wsh.handle = name; | |
151 | + wsh.stride = buffer->stride[0]; | |
152 | + | |
153 | + buffer->driver_buffer = | |
154 | + ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh); | |
155 | +} | |
156 | + | |
157 | +static void | |
158 | +wayland_drm_bufmgr_unreference_buffer(void *user_data, | |
159 | + struct wl_drm_buffer *buffer) | |
160 | +{ | |
161 | + struct pipe_resource *resource = buffer->driver_buffer; | |
162 | + | |
163 | + pipe_resource_reference(&resource, NULL); | |
164 | +} | |
165 | + | |
166 | +static struct wayland_drm_callbacks wl_drm_callbacks = { | |
167 | + wayland_drm_bufmgr_authenticate, | |
168 | + wayland_drm_bufmgr_reference_buffer, | |
169 | + wayland_drm_bufmgr_unreference_buffer | |
170 | +}; | |
171 | + | |
172 | +static boolean | |
173 | +wayland_drm_bufmgr_bind_display(struct native_display *ndpy, | |
174 | + struct wl_display *wl_dpy) | |
175 | +{ | |
176 | + struct wayland_drm_bufmgr *bufmgr; | |
177 | + | |
178 | + bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr); | |
179 | + | |
180 | + if (bufmgr->wl_server_drm) | |
181 | + return FALSE; | |
182 | + | |
183 | + bufmgr->wl_server_drm = wayland_drm_init(wl_dpy, bufmgr->device_name, | |
184 | + &wl_drm_callbacks, ndpy, 0); | |
185 | + | |
186 | + if (!bufmgr->wl_server_drm) | |
187 | + return FALSE; | |
188 | + | |
189 | + return TRUE; | |
190 | +} | |
191 | + | |
192 | +static boolean | |
193 | +wayland_drm_bufmgr_unbind_display(struct native_display *ndpy, | |
194 | + struct wl_display *wl_dpy) | |
195 | +{ | |
196 | + struct wayland_drm_bufmgr *bufmgr; | |
197 | + | |
198 | + bufmgr = wayland_drm_bufmgr(ndpy->wayland_bufmgr); | |
199 | + | |
200 | + if (!bufmgr->wl_server_drm) | |
201 | + return FALSE; | |
202 | + | |
203 | + wayland_drm_uninit(bufmgr->wl_server_drm); | |
204 | + bufmgr->wl_server_drm = NULL; | |
205 | + | |
206 | + return TRUE; | |
207 | +} | |
208 | + | |
209 | +static struct pipe_resource * | |
210 | +wayland_drm_bufmgr_wl_buffer_get_resource(struct native_display *ndpy, | |
211 | + struct wl_buffer *buffer) | |
212 | +{ | |
213 | + return wayland_drm_buffer_get_buffer(buffer); | |
214 | +} | |
215 | + | |
216 | +static EGLBoolean | |
217 | +wayland_drm_bufmgr_query_buffer(struct native_display *ndpy, | |
218 | + struct wl_buffer *_buffer, | |
219 | + EGLint attribute, EGLint *value) | |
220 | +{ | |
221 | + struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; | |
222 | + struct pipe_resource *resource = buffer->driver_buffer; | |
223 | + | |
68738647 | 224 | + if (!wayland_buffer_is_drm(wayland_drm_bufmgr(ndpy->wayland_bufmgr)->wl_server_drm, &buffer->buffer)) |
4469c4e7 AF |
225 | + return EGL_FALSE; |
226 | + | |
227 | + switch (attribute) { | |
228 | + case EGL_TEXTURE_FORMAT: | |
229 | + switch (resource->format) { | |
230 | + case PIPE_FORMAT_B8G8R8A8_UNORM: | |
231 | + *value = EGL_TEXTURE_RGBA; | |
232 | + return EGL_TRUE; | |
233 | + case PIPE_FORMAT_B8G8R8X8_UNORM: | |
234 | + *value = EGL_TEXTURE_RGB; | |
235 | + return EGL_TRUE; | |
236 | + default: | |
237 | + return EGL_FALSE; | |
238 | + } | |
239 | + case EGL_WIDTH: | |
240 | + *value = buffer->buffer.width; | |
241 | + return EGL_TRUE; | |
242 | + case EGL_HEIGHT: | |
243 | + *value = buffer->buffer.height; | |
244 | + return EGL_TRUE; | |
245 | + default: | |
246 | + return EGL_FALSE; | |
247 | + } | |
248 | +} | |
249 | + | |
250 | + | |
251 | +struct native_display_wayland_bufmgr * | |
252 | +wayland_drm_bufmgr_create(wayland_drm_bufmgr_authenticate_func authenticate, | |
253 | + void *user_data, char *device_name) | |
254 | +{ | |
255 | + struct wayland_drm_bufmgr *bufmgr; | |
256 | + | |
257 | + bufmgr = calloc(1, sizeof *bufmgr); | |
258 | + if (!bufmgr) | |
259 | + return NULL; | |
260 | + | |
261 | + bufmgr->user_data = user_data; | |
262 | + bufmgr->authenticate = authenticate; | |
263 | + bufmgr->device_name = strdup(device_name); | |
264 | + | |
265 | + bufmgr->base.bind_display = wayland_drm_bufmgr_bind_display; | |
266 | + bufmgr->base.unbind_display = wayland_drm_bufmgr_unbind_display; | |
267 | + bufmgr->base.buffer_get_resource = wayland_drm_bufmgr_wl_buffer_get_resource; | |
268 | + bufmgr->base.query_buffer = wayland_drm_bufmgr_query_buffer; | |
269 | + | |
270 | + return &bufmgr->base; | |
271 | +} | |
272 | + | |
273 | +void | |
274 | +wayland_drm_bufmgr_destroy(struct native_display_wayland_bufmgr *_bufmgr) | |
275 | +{ | |
276 | + struct wayland_drm_bufmgr *bufmgr = wayland_drm_bufmgr(_bufmgr); | |
277 | + | |
278 | + if (!bufmgr) | |
279 | + return; | |
280 | + | |
281 | + free(bufmgr->device_name); | |
282 | + free(bufmgr); | |
283 | +} | |
284 | + | |
285 | +#endif | |
286 | diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h | |
287 | similarity index 59% | |
288 | rename from src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h | |
289 | rename to src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h | |
290 | index 543dc6f..7bf6513 100644 | |
291 | --- a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.h | |
292 | +++ b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr.h | |
293 | @@ -22,26 +22,16 @@ | |
294 | * DEALINGS IN THE SOFTWARE. | |
295 | */ | |
296 | ||
297 | -#ifndef _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ | |
298 | -#define _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ | |
299 | +#ifndef _NATIVE_WAYLAND_DRM_BUFMGR_H_ | |
300 | +#define _NATIVE_WAYLAND_DRM_BUFMGR_H_ | |
301 | ||
302 | -#include "wayland-drm.h" | |
303 | +typedef int (*wayland_drm_bufmgr_authenticate_func)(void *, uint32_t); | |
304 | ||
305 | -void | |
306 | -egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, int fd, | |
307 | - struct wl_drm_buffer *buffer); | |
308 | +struct native_display_wayland_bufmgr * | |
309 | +wayland_drm_bufmgr_create(wayland_drm_bufmgr_authenticate_func authenticate, | |
310 | + void *user_data, char *device_name); | |
311 | ||
312 | void | |
313 | -egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, | |
314 | - struct wl_drm_buffer *buffer); | |
315 | - | |
316 | -struct pipe_resource * | |
317 | -egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy, | |
318 | - struct wl_buffer *buffer); | |
319 | - | |
320 | -EGLBoolean | |
321 | -egl_g3d_wl_drm_common_query_buffer(struct native_display *ndpy, | |
322 | - struct wl_buffer *buffer, | |
323 | - EGLint attribute, EGLint *value); | |
324 | +wayland_drm_bufmgr_destroy(struct native_display_wayland_bufmgr *bufmgr); | |
325 | ||
326 | -#endif /* _NATIVE_WAYLAND_DRM_BUFMGR_HELPER_H_ */ | |
327 | +#endif /* _NATIVE_WAYLAND_DRM_BUFMGR_H_ */ | |
328 | diff --git a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c b/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c | |
329 | deleted file mode 100644 | |
330 | index a9e7342..0000000 | |
331 | --- a/src/gallium/state_trackers/egl/common/native_wayland_drm_bufmgr_helper.c | |
332 | +++ /dev/null | |
333 | @@ -1,106 +0,0 @@ | |
334 | -#include <stdint.h> | |
335 | -#include <string.h> | |
336 | - | |
337 | -#include "native.h" | |
338 | -#include "util/u_inlines.h" | |
339 | -#include "state_tracker/drm_driver.h" | |
340 | - | |
341 | -#ifdef HAVE_WAYLAND_BACKEND | |
342 | - | |
343 | -#include <wayland-server.h> | |
344 | -#include <wayland-drm-server-protocol.h> | |
345 | - | |
346 | -#include "native_wayland_drm_bufmgr_helper.h" | |
347 | - | |
348 | -void | |
349 | -egl_g3d_wl_drm_helper_reference_buffer(void *user_data, uint32_t name, int fd, | |
350 | - struct wl_drm_buffer *buffer) | |
351 | -{ | |
352 | - struct native_display *ndpy = user_data; | |
353 | - struct pipe_resource templ; | |
354 | - struct winsys_handle wsh; | |
355 | - enum pipe_format pf; | |
356 | - | |
357 | - switch (buffer->format) { | |
358 | - case WL_DRM_FORMAT_ARGB8888: | |
359 | - pf = PIPE_FORMAT_B8G8R8A8_UNORM; | |
360 | - break; | |
361 | - case WL_DRM_FORMAT_XRGB8888: | |
362 | - pf = PIPE_FORMAT_B8G8R8X8_UNORM; | |
363 | - break; | |
364 | - default: | |
365 | - pf = PIPE_FORMAT_NONE; | |
366 | - break; | |
367 | - } | |
368 | - | |
369 | - if (pf == PIPE_FORMAT_NONE) | |
370 | - return; | |
371 | - | |
372 | - memset(&templ, 0, sizeof(templ)); | |
373 | - templ.target = PIPE_TEXTURE_2D; | |
374 | - templ.format = pf; | |
375 | - templ.bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW; | |
376 | - templ.width0 = buffer->buffer.width; | |
377 | - templ.height0 = buffer->buffer.height; | |
378 | - templ.depth0 = 1; | |
379 | - templ.array_size = 1; | |
380 | - | |
381 | - memset(&wsh, 0, sizeof(wsh)); | |
382 | - wsh.handle = name; | |
383 | - wsh.stride = buffer->stride[0]; | |
384 | - | |
385 | - buffer->driver_buffer = | |
386 | - ndpy->screen->resource_from_handle(ndpy->screen, &templ, &wsh); | |
387 | -} | |
388 | - | |
389 | -void | |
390 | -egl_g3d_wl_drm_helper_unreference_buffer(void *user_data, | |
391 | - struct wl_drm_buffer *buffer) | |
392 | -{ | |
393 | - struct pipe_resource *resource = buffer->driver_buffer; | |
394 | - | |
395 | - pipe_resource_reference(&resource, NULL); | |
396 | -} | |
397 | - | |
398 | -struct pipe_resource * | |
399 | -egl_g3d_wl_drm_common_wl_buffer_get_resource(struct native_display *ndpy, | |
400 | - struct wl_buffer *buffer) | |
401 | -{ | |
402 | - return wayland_drm_buffer_get_buffer(buffer); | |
403 | -} | |
404 | - | |
405 | -EGLBoolean | |
406 | -egl_g3d_wl_drm_common_query_buffer(struct native_display *ndpy, | |
407 | - struct wl_buffer *_buffer, | |
408 | - EGLint attribute, EGLint *value) | |
409 | -{ | |
410 | - struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer; | |
411 | - struct pipe_resource *resource = buffer->driver_buffer; | |
412 | - | |
68738647 | 413 | - if (!wayland_buffer_is_drm(ndpy->wl_server_drm, &buffer->buffer)) |
4469c4e7 AF |
414 | - return EGL_FALSE; |
415 | - | |
416 | - switch (attribute) { | |
417 | - case EGL_TEXTURE_FORMAT: | |
418 | - switch (resource->format) { | |
419 | - case PIPE_FORMAT_B8G8R8A8_UNORM: | |
420 | - *value = EGL_TEXTURE_RGBA; | |
421 | - return EGL_TRUE; | |
422 | - case PIPE_FORMAT_B8G8R8X8_UNORM: | |
423 | - *value = EGL_TEXTURE_RGB; | |
424 | - return EGL_TRUE; | |
425 | - default: | |
426 | - return EGL_FALSE; | |
427 | - } | |
428 | - case EGL_WIDTH: | |
429 | - *value = buffer->buffer.width; | |
430 | - return EGL_TRUE; | |
431 | - case EGL_HEIGHT: | |
432 | - *value = buffer->buffer.height; | |
433 | - return EGL_TRUE; | |
434 | - default: | |
435 | - return EGL_FALSE; | |
436 | - } | |
437 | -} | |
438 | - | |
439 | -#endif | |
440 | diff --git a/src/gallium/state_trackers/egl/drm/native_drm.c b/src/gallium/state_trackers/egl/drm/native_drm.c | |
441 | index 03bfdda..88ac490 100644 | |
442 | --- a/src/gallium/state_trackers/egl/drm/native_drm.c | |
443 | +++ b/src/gallium/state_trackers/egl/drm/native_drm.c | |
68738647 JB |
444 | @@ -40,7 +40,7 @@ |
445 | #endif | |
446 | ||
447 | #ifdef HAVE_WAYLAND_BACKEND | |
448 | -#include "common/native_wayland_drm_bufmgr_helper.h" | |
449 | +#include "common/native_wayland_drm_bufmgr.h" | |
450 | #endif | |
451 | ||
452 | static boolean | |
4469c4e7 AF |
453 | @@ -132,6 +132,8 @@ drm_display_destroy(struct native_display *ndpy) |
454 | ||
455 | FREE(drmdpy->device_name); | |
456 | ||
457 | + wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr); | |
458 | + | |
459 | if (drmdpy->own_gbm) { | |
460 | gbm_device_destroy(&drmdpy->gbmdrm->base.base); | |
461 | if (drmdpy->fd >= 0) | |
68738647 | 462 | @@ -195,51 +197,6 @@ drm_display_authenticate(void *user_data, uint32_t magic) |
4469c4e7 AF |
463 | return drmAuthMagic(drmdpy->fd, magic); |
464 | } | |
465 | ||
466 | -static struct wayland_drm_callbacks wl_drm_callbacks = { | |
467 | - drm_display_authenticate, | |
468 | - egl_g3d_wl_drm_helper_reference_buffer, | |
469 | - egl_g3d_wl_drm_helper_unreference_buffer | |
470 | -}; | |
471 | - | |
472 | -static boolean | |
473 | -drm_display_bind_wayland_display(struct native_display *ndpy, | |
474 | - struct wl_display *wl_dpy) | |
475 | -{ | |
476 | - struct drm_display *drmdpy = drm_display(ndpy); | |
477 | - | |
68738647 | 478 | - if (ndpy->wl_server_drm) |
4469c4e7 AF |
479 | - return FALSE; |
480 | - | |
68738647 | 481 | - ndpy->wl_server_drm = wayland_drm_init(wl_dpy, |
4469c4e7 AF |
482 | - drmdpy->device_name, |
483 | - &wl_drm_callbacks, ndpy, 0); | |
484 | - | |
68738647 | 485 | - if (!ndpy->wl_server_drm) |
4469c4e7 AF |
486 | - return FALSE; |
487 | - | |
488 | - return TRUE; | |
489 | -} | |
490 | - | |
491 | -static boolean | |
492 | -drm_display_unbind_wayland_display(struct native_display *ndpy, | |
493 | - struct wl_display *wl_dpy) | |
494 | -{ | |
68738647 | 495 | - if (!ndpy->wl_server_drm) |
4469c4e7 AF |
496 | - return FALSE; |
497 | - | |
68738647 JB |
498 | - wayland_drm_uninit(ndpy->wl_server_drm); |
499 | - ndpy->wl_server_drm = NULL; | |
4469c4e7 AF |
500 | - |
501 | - return TRUE; | |
502 | -} | |
503 | - | |
504 | -static struct native_display_wayland_bufmgr drm_display_wayland_bufmgr = { | |
505 | - drm_display_bind_wayland_display, | |
506 | - drm_display_unbind_wayland_display, | |
507 | - egl_g3d_wl_drm_common_wl_buffer_get_resource, | |
508 | - egl_g3d_wl_drm_common_query_buffer | |
509 | -}; | |
510 | - | |
511 | #endif /* HAVE_WAYLAND_BACKEND */ | |
512 | ||
513 | static struct native_surface * | |
514 | @@ -293,7 +248,8 @@ drm_create_display(struct gbm_gallium_drm_device *gbmdrm, int own_gbm, | |
515 | drmdpy->base.buffer = &drm_display_buffer; | |
516 | #ifdef HAVE_WAYLAND_BACKEND | |
517 | if (drmdpy->device_name) | |
518 | - drmdpy->base.wayland_bufmgr = &drm_display_wayland_bufmgr; | |
519 | + drmdpy->base.wayland_bufmgr = wayland_drm_bufmgr_create( | |
520 | + drm_display_authenticate, drmdpy, drmdpy->device_name); | |
521 | #endif | |
522 | drm_display_init_modeset(&drmdpy->base); | |
523 | ||
68738647 JB |
524 | #diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h |
525 | #index 16a4251..2c015b2 100644 | |
526 | #--- a/src/gallium/state_trackers/egl/drm/native_drm.h | |
527 | #+++ b/src/gallium/state_trackers/egl/drm/native_drm.h | |
528 | #@@ -37,7 +37,7 @@ | |
529 | # #include "common/native_helper.h" | |
530 | # | |
531 | # #ifdef HAVE_WAYLAND_BACKEND | |
532 | #-#include "common/native_wayland_drm_bufmgr_helper.h" | |
533 | #+#include "common/native_wayland_drm_bufmgr.h" | |
534 | # #endif | |
535 | # | |
536 | # #include "gbm_gallium_drmint.h" | |
4469c4e7 AF |
537 | diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c |
538 | index fc8aac7..a4bcdd8 100644 | |
539 | --- a/src/gallium/state_trackers/egl/wayland/native_drm.c | |
540 | +++ b/src/gallium/state_trackers/egl/wayland/native_drm.c | |
541 | @@ -40,7 +40,7 @@ | |
542 | #include "wayland-drm-client-protocol.h" | |
543 | #include "wayland-egl-priv.h" | |
544 | ||
545 | -#include "common/native_wayland_drm_bufmgr_helper.h" | |
546 | +#include "common/native_wayland_drm_bufmgr.h" | |
547 | ||
548 | #include <xf86drm.h> | |
549 | #include <sys/types.h> | |
550 | @@ -53,7 +53,6 @@ struct wayland_drm_display { | |
551 | const struct native_event_handler *event_handler; | |
552 | ||
553 | struct wl_drm *wl_drm; | |
554 | - struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */ | |
555 | int fd; | |
556 | char *device_name; | |
557 | boolean authenticated; | |
558 | @@ -77,6 +76,8 @@ wayland_drm_display_destroy(struct native_display *ndpy) | |
559 | if (drmdpy->base.own_dpy) | |
560 | wl_display_disconnect(drmdpy->base.dpy); | |
561 | ||
562 | + wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr); | |
563 | + | |
564 | ndpy_uninit(ndpy); | |
565 | ||
566 | if (drmdpy->fd) | |
567 | @@ -195,6 +196,24 @@ static const struct wl_registry_listener registry_listener = { | |
568 | registry_handle_global | |
569 | }; | |
570 | ||
571 | +static int | |
572 | +wayland_drm_display_authenticate(void *user_data, uint32_t magic) | |
573 | +{ | |
574 | + struct native_display *ndpy = user_data; | |
575 | + struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy); | |
576 | + boolean current_authenticate, authenticated; | |
577 | + | |
578 | + current_authenticate = drmdpy->authenticated; | |
579 | + | |
580 | + wl_drm_authenticate(drmdpy->wl_drm, magic); | |
581 | + wl_display_roundtrip(drmdpy->base.dpy); | |
582 | + authenticated = drmdpy->authenticated; | |
583 | + | |
584 | + drmdpy->authenticated = current_authenticate; | |
585 | + | |
586 | + return authenticated ? 0 : -1; | |
587 | +} | |
588 | + | |
589 | static boolean | |
590 | wayland_drm_display_init_screen(struct native_display *ndpy) | |
591 | { | |
592 | @@ -226,6 +245,9 @@ wayland_drm_display_init_screen(struct native_display *ndpy) | |
593 | return FALSE; | |
594 | } | |
595 | ||
596 | + drmdpy->base.base.wayland_bufmgr = wayland_drm_bufmgr_create( | |
597 | + wayland_drm_display_authenticate, drmdpy, drmdpy->device_name); | |
598 | + | |
599 | return TRUE; | |
600 | } | |
601 | ||
602 | @@ -235,72 +257,6 @@ static struct native_display_buffer wayland_drm_display_buffer = { | |
603 | drm_display_export_native_buffer | |
604 | }; | |
605 | ||
606 | -static int | |
607 | -wayland_drm_display_authenticate(void *user_data, uint32_t magic) | |
608 | -{ | |
609 | - struct native_display *ndpy = user_data; | |
610 | - struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy); | |
611 | - boolean current_authenticate, authenticated; | |
612 | - | |
613 | - current_authenticate = drmdpy->authenticated; | |
614 | - | |
615 | - wl_drm_authenticate(drmdpy->wl_drm, magic); | |
616 | - wl_display_roundtrip(drmdpy->base.dpy); | |
617 | - authenticated = drmdpy->authenticated; | |
618 | - | |
619 | - drmdpy->authenticated = current_authenticate; | |
620 | - | |
621 | - return authenticated ? 0 : -1; | |
622 | -} | |
623 | - | |
624 | -static struct wayland_drm_callbacks wl_drm_callbacks = { | |
625 | - wayland_drm_display_authenticate, | |
626 | - egl_g3d_wl_drm_helper_reference_buffer, | |
627 | - egl_g3d_wl_drm_helper_unreference_buffer | |
628 | -}; | |
629 | - | |
630 | -static boolean | |
631 | -wayland_drm_display_bind_wayland_display(struct native_display *ndpy, | |
632 | - struct wl_display *wl_dpy) | |
633 | -{ | |
634 | - struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy); | |
635 | - | |
636 | - if (drmdpy->wl_server_drm) | |
637 | - return FALSE; | |
638 | - | |
68738647 | 639 | - ndpy->wl_server_drm = |
4469c4e7 AF |
640 | - wayland_drm_init(wl_dpy, drmdpy->device_name, |
641 | - &wl_drm_callbacks, ndpy, 0); | |
642 | - | |
643 | - if (!drmdpy->wl_server_drm) | |
644 | - return FALSE; | |
645 | - | |
646 | - return TRUE; | |
647 | -} | |
648 | - | |
649 | -static boolean | |
650 | -wayland_drm_display_unbind_wayland_display(struct native_display *ndpy, | |
651 | - struct wl_display *wl_dpy) | |
652 | -{ | |
653 | - struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy); | |
654 | - | |
655 | - if (!drmdpy->wl_server_drm) | |
656 | - return FALSE; | |
657 | - | |
658 | - wayland_drm_uninit(drmdpy->wl_server_drm); | |
659 | - drmdpy->wl_server_drm = NULL; | |
660 | - | |
661 | - return TRUE; | |
662 | -} | |
663 | - | |
664 | -static struct native_display_wayland_bufmgr wayland_drm_display_wayland_bufmgr = { | |
665 | - wayland_drm_display_bind_wayland_display, | |
666 | - wayland_drm_display_unbind_wayland_display, | |
667 | - egl_g3d_wl_drm_common_wl_buffer_get_resource, | |
668 | - egl_g3d_wl_drm_common_query_buffer | |
669 | -}; | |
670 | - | |
671 | - | |
672 | struct wayland_display * | |
673 | wayland_create_drm_display(struct wl_display *dpy, | |
674 | const struct native_event_handler *event_handler) | |
675 | @@ -322,7 +278,6 @@ wayland_create_drm_display(struct wl_display *dpy, | |
676 | drmdpy->base.base.init_screen = wayland_drm_display_init_screen; | |
677 | drmdpy->base.base.destroy = wayland_drm_display_destroy; | |
678 | drmdpy->base.base.buffer = &wayland_drm_display_buffer; | |
679 | - drmdpy->base.base.wayland_bufmgr = &wayland_drm_display_wayland_bufmgr; | |
680 | ||
681 | drmdpy->base.create_buffer = wayland_create_drm_buffer; | |
682 | ||
683 | diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c | |
684 | index 053044a..3d08863 100644 | |
685 | --- a/src/gallium/state_trackers/egl/x11/native_dri2.c | |
686 | +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c | |
687 | @@ -39,7 +39,7 @@ | |
688 | ||
689 | #include "common/native_helper.h" | |
690 | #ifdef HAVE_WAYLAND_BACKEND | |
691 | -#include "common/native_wayland_drm_bufmgr_helper.h" | |
692 | +#include "common/native_wayland_drm_bufmgr.h" | |
693 | #endif | |
694 | ||
695 | #ifdef GLX_DIRECT_RENDERING | |
696 | @@ -757,6 +757,8 @@ dri2_display_destroy(struct native_display *ndpy) | |
697 | if (dri2dpy->surfaces) | |
698 | util_hash_table_destroy(dri2dpy->surfaces); | |
699 | ||
700 | + wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr); | |
701 | + | |
702 | if (dri2dpy->xscr) | |
703 | x11_screen_destroy(dri2dpy->xscr); | |
704 | if (dri2dpy->own_dpy) | |
705 | @@ -785,6 +787,19 @@ dri2_display_invalidate_buffers(struct x11_screen *xscr, Drawable drawable, | |
706 | &dri2surf->base, dri2surf->server_stamp); | |
707 | } | |
708 | ||
709 | +#ifdef HAVE_WAYLAND_BACKEND | |
710 | + | |
711 | +static int | |
712 | +dri2_display_authenticate(void *user_data, uint32_t magic) | |
713 | +{ | |
714 | + struct native_display *ndpy = user_data; | |
715 | + struct dri2_display *dri2dpy = dri2_display(ndpy); | |
716 | + | |
717 | + return x11_screen_authenticate(dri2dpy->xscr, magic); | |
718 | +} | |
719 | + | |
720 | +#endif /* HAVE_WAYLAND_BACKEND */ | |
721 | + | |
722 | /** | |
723 | * Initialize DRI2 and pipe screen. | |
724 | */ | |
725 | @@ -816,6 +831,13 @@ dri2_display_init_screen(struct native_display *ndpy) | |
726 | return FALSE; | |
727 | } | |
728 | ||
729 | +#ifdef HAVE_WAYLAND_BACKEND | |
730 | + dri2dpy->base.wayland_bufmgr = wayland_drm_bufmgr_create( | |
731 | + dri2_display_authenticate, dri2dpy, | |
732 | + x11_screen_get_device_name(dri2dpy->xscr)); | |
733 | + | |
734 | +#endif | |
735 | + | |
736 | return TRUE; | |
737 | } | |
738 | ||
739 | @@ -832,66 +854,6 @@ dri2_display_hash_table_compare(void *key1, void *key2) | |
740 | return ((char *) key1 - (char *) key2); | |
741 | } | |
742 | ||
743 | -#ifdef HAVE_WAYLAND_BACKEND | |
744 | - | |
745 | -static int | |
746 | -dri2_display_authenticate(void *user_data, uint32_t magic) | |
747 | -{ | |
748 | - struct native_display *ndpy = user_data; | |
749 | - struct dri2_display *dri2dpy = dri2_display(ndpy); | |
750 | - | |
751 | - return x11_screen_authenticate(dri2dpy->xscr, magic); | |
752 | -} | |
753 | - | |
754 | -static struct wayland_drm_callbacks wl_drm_callbacks = { | |
755 | - dri2_display_authenticate, | |
756 | - egl_g3d_wl_drm_helper_reference_buffer, | |
757 | - egl_g3d_wl_drm_helper_unreference_buffer | |
758 | -}; | |
759 | - | |
760 | -static boolean | |
761 | -dri2_display_bind_wayland_display(struct native_display *ndpy, | |
762 | - struct wl_display *wl_dpy) | |
763 | -{ | |
764 | - struct dri2_display *dri2dpy = dri2_display(ndpy); | |
765 | - | |
766 | - if (dri2dpy->wl_server_drm) | |
767 | - return FALSE; | |
768 | - | |
68738647 | 769 | - ndpy->wl_server_drm = wayland_drm_init(wl_dpy, |
4469c4e7 AF |
770 | - x11_screen_get_device_name(dri2dpy->xscr), |
771 | - &wl_drm_callbacks, ndpy, 0); | |
772 | - | |
773 | - if (!dri2dpy->wl_server_drm) | |
774 | - return FALSE; | |
775 | - | |
776 | - return TRUE; | |
777 | -} | |
778 | - | |
779 | -static boolean | |
780 | -dri2_display_unbind_wayland_display(struct native_display *ndpy, | |
781 | - struct wl_display *wl_dpy) | |
782 | -{ | |
783 | - struct dri2_display *dri2dpy = dri2_display(ndpy); | |
784 | - | |
785 | - if (!dri2dpy->wl_server_drm) | |
786 | - return FALSE; | |
787 | - | |
788 | - wayland_drm_uninit(dri2dpy->wl_server_drm); | |
789 | - dri2dpy->wl_server_drm = NULL; | |
790 | - | |
791 | - return TRUE; | |
792 | -} | |
793 | - | |
794 | -static struct native_display_wayland_bufmgr dri2_display_wayland_bufmgr = { | |
795 | - dri2_display_bind_wayland_display, | |
796 | - dri2_display_unbind_wayland_display, | |
797 | - egl_g3d_wl_drm_common_wl_buffer_get_resource, | |
798 | - egl_g3d_wl_drm_common_query_buffer | |
799 | -}; | |
800 | - | |
801 | -#endif /* HAVE_WAYLAND_BACKEND */ | |
802 | - | |
803 | struct native_display * | |
804 | x11_create_dri2_display(Display *dpy, | |
805 | const struct native_event_handler *event_handler) | |
806 | @@ -936,9 +898,6 @@ x11_create_dri2_display(Display *dpy, | |
807 | dri2dpy->base.copy_to_pixmap = native_display_copy_to_pixmap; | |
808 | dri2dpy->base.create_window_surface = dri2_display_create_window_surface; | |
809 | dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface; | |
810 | -#ifdef HAVE_WAYLAND_BACKEND | |
811 | - dri2dpy->base.wayland_bufmgr = &dri2_display_wayland_bufmgr; | |
812 | -#endif | |
813 | ||
814 | return &dri2dpy->base; | |
815 | } | |
816 | -- | |
817 | 1.8.4 | |
818 |