]> git.pld-linux.org Git - packages/Mesa.git/blob - 0001-gallium-egl-Simplify-native_wayland_drm_bufmgr_helpe.patch
Added Wayland 1.2 compatibility patches, release 22
[packages/Mesa.git] / 0001-gallium-egl-Simplify-native_wayland_drm_bufmgr_helpe.patch
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;
63  };
64  
65  /**
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 +
224 +   if (!wayland_buffer_is_drm(&buffer->buffer))
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 -
413 -   if (!wayland_buffer_is_drm(&buffer->buffer))
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
444 @@ -132,6 +132,8 @@ drm_display_destroy(struct native_display *ndpy)
445  
446     FREE(drmdpy->device_name);
447  
448 +   wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr);
449 +
450     if (drmdpy->own_gbm) {
451        gbm_device_destroy(&drmdpy->gbmdrm->base.base);
452        if (drmdpy->fd >= 0)
453 @@ -195,53 +197,6 @@ drm_display_authenticate(void *user_data, uint32_t magic)
454     return drmAuthMagic(drmdpy->fd, magic);
455  }
456  
457 -static struct wayland_drm_callbacks wl_drm_callbacks = {
458 -   drm_display_authenticate,
459 -   egl_g3d_wl_drm_helper_reference_buffer,
460 -   egl_g3d_wl_drm_helper_unreference_buffer
461 -};
462 -
463 -static boolean
464 -drm_display_bind_wayland_display(struct native_display *ndpy,
465 -                                  struct wl_display *wl_dpy)
466 -{
467 -   struct drm_display *drmdpy = drm_display(ndpy);
468 -
469 -   if (drmdpy->wl_server_drm)
470 -      return FALSE;
471 -
472 -   drmdpy->wl_server_drm = wayland_drm_init(wl_dpy,
473 -         drmdpy->device_name,
474 -         &wl_drm_callbacks, ndpy, 0);
475 -
476 -   if (!drmdpy->wl_server_drm)
477 -      return FALSE;
478 -   
479 -   return TRUE;
480 -}
481 -
482 -static boolean
483 -drm_display_unbind_wayland_display(struct native_display *ndpy,
484 -                                    struct wl_display *wl_dpy)
485 -{
486 -   struct drm_display *drmdpy = drm_display(ndpy);
487 -
488 -   if (!drmdpy->wl_server_drm)
489 -      return FALSE;
490 -
491 -   wayland_drm_uninit(drmdpy->wl_server_drm);
492 -   drmdpy->wl_server_drm = NULL;
493 -
494 -   return TRUE;
495 -}
496 -
497 -static struct native_display_wayland_bufmgr drm_display_wayland_bufmgr = {
498 -   drm_display_bind_wayland_display,
499 -   drm_display_unbind_wayland_display,
500 -   egl_g3d_wl_drm_common_wl_buffer_get_resource,
501 -   egl_g3d_wl_drm_common_query_buffer
502 -};
503 -
504  #endif /* HAVE_WAYLAND_BACKEND */
505  
506  static struct native_surface *
507 @@ -293,7 +248,8 @@ drm_create_display(struct gbm_gallium_drm_device *gbmdrm, int own_gbm,
508     drmdpy->base.buffer = &drm_display_buffer;
509  #ifdef HAVE_WAYLAND_BACKEND
510     if (drmdpy->device_name)
511 -      drmdpy->base.wayland_bufmgr = &drm_display_wayland_bufmgr;
512 +      drmdpy->base.wayland_bufmgr = wayland_drm_bufmgr_create(
513 +             drm_display_authenticate, drmdpy, drmdpy->device_name);
514  #endif
515     drm_display_init_modeset(&drmdpy->base);
516  
517 diff --git a/src/gallium/state_trackers/egl/drm/native_drm.h b/src/gallium/state_trackers/egl/drm/native_drm.h
518 index 16a4251..2c015b2 100644
519 --- a/src/gallium/state_trackers/egl/drm/native_drm.h
520 +++ b/src/gallium/state_trackers/egl/drm/native_drm.h
521 @@ -37,7 +37,7 @@
522  #include "common/native_helper.h"
523  
524  #ifdef HAVE_WAYLAND_BACKEND
525 -#include "common/native_wayland_drm_bufmgr_helper.h"
526 +#include "common/native_wayland_drm_bufmgr.h"
527  #endif
528  
529  #include "gbm_gallium_drmint.h"
530 diff --git a/src/gallium/state_trackers/egl/wayland/native_drm.c b/src/gallium/state_trackers/egl/wayland/native_drm.c
531 index fc8aac7..a4bcdd8 100644
532 --- a/src/gallium/state_trackers/egl/wayland/native_drm.c
533 +++ b/src/gallium/state_trackers/egl/wayland/native_drm.c
534 @@ -40,7 +40,7 @@
535  #include "wayland-drm-client-protocol.h"
536  #include "wayland-egl-priv.h"
537  
538 -#include "common/native_wayland_drm_bufmgr_helper.h"
539 +#include "common/native_wayland_drm_bufmgr.h"
540  
541  #include <xf86drm.h>
542  #include <sys/types.h>
543 @@ -53,7 +53,6 @@ struct wayland_drm_display {
544     const struct native_event_handler *event_handler;
545  
546     struct wl_drm *wl_drm;
547 -   struct wl_drm *wl_server_drm; /* for EGL_WL_bind_wayland_display */
548     int fd;
549     char *device_name;
550     boolean authenticated;
551 @@ -77,6 +76,8 @@ wayland_drm_display_destroy(struct native_display *ndpy)
552     if (drmdpy->base.own_dpy)
553        wl_display_disconnect(drmdpy->base.dpy);
554  
555 +   wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr);
556 +
557     ndpy_uninit(ndpy);
558  
559     if (drmdpy->fd)
560 @@ -195,6 +196,24 @@ static const struct wl_registry_listener registry_listener = {
561         registry_handle_global
562  };
563  
564 +static int
565 +wayland_drm_display_authenticate(void *user_data, uint32_t magic)
566 +{
567 +   struct native_display *ndpy = user_data;
568 +   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
569 +   boolean current_authenticate, authenticated;
570 +
571 +   current_authenticate = drmdpy->authenticated;
572 +
573 +   wl_drm_authenticate(drmdpy->wl_drm, magic);
574 +   wl_display_roundtrip(drmdpy->base.dpy);
575 +   authenticated = drmdpy->authenticated;
576 +
577 +   drmdpy->authenticated = current_authenticate;
578 +
579 +   return authenticated ? 0 : -1;
580 +}
581 +
582  static boolean
583  wayland_drm_display_init_screen(struct native_display *ndpy)
584  {
585 @@ -226,6 +245,9 @@ wayland_drm_display_init_screen(struct native_display *ndpy)
586        return FALSE;
587     }
588  
589 +   drmdpy->base.base.wayland_bufmgr = wayland_drm_bufmgr_create(
590 +          wayland_drm_display_authenticate, drmdpy, drmdpy->device_name);
591 +
592     return TRUE;
593  }
594  
595 @@ -235,72 +257,6 @@ static struct native_display_buffer wayland_drm_display_buffer = {
596     drm_display_export_native_buffer
597  };
598  
599 -static int
600 -wayland_drm_display_authenticate(void *user_data, uint32_t magic)
601 -{
602 -   struct native_display *ndpy = user_data;
603 -   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
604 -   boolean current_authenticate, authenticated;
605 -
606 -   current_authenticate = drmdpy->authenticated;
607 -
608 -   wl_drm_authenticate(drmdpy->wl_drm, magic);
609 -   wl_display_roundtrip(drmdpy->base.dpy);
610 -   authenticated = drmdpy->authenticated;
611 -
612 -   drmdpy->authenticated = current_authenticate;
613 -
614 -   return authenticated ? 0 : -1;
615 -}
616 -
617 -static struct wayland_drm_callbacks wl_drm_callbacks = {
618 -   wayland_drm_display_authenticate,
619 -   egl_g3d_wl_drm_helper_reference_buffer,
620 -   egl_g3d_wl_drm_helper_unreference_buffer
621 -};
622 -
623 -static boolean
624 -wayland_drm_display_bind_wayland_display(struct native_display *ndpy,
625 -                                         struct wl_display *wl_dpy)
626 -{
627 -   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
628 -
629 -   if (drmdpy->wl_server_drm)
630 -      return FALSE;
631 -
632 -   drmdpy->wl_server_drm =
633 -      wayland_drm_init(wl_dpy, drmdpy->device_name,
634 -                       &wl_drm_callbacks, ndpy, 0);
635 -
636 -   if (!drmdpy->wl_server_drm)
637 -      return FALSE;
638 -   
639 -   return TRUE;
640 -}
641 -
642 -static boolean
643 -wayland_drm_display_unbind_wayland_display(struct native_display *ndpy,
644 -                                           struct wl_display *wl_dpy)
645 -{
646 -   struct wayland_drm_display *drmdpy = wayland_drm_display(ndpy);
647 -
648 -   if (!drmdpy->wl_server_drm)
649 -      return FALSE;
650 -
651 -   wayland_drm_uninit(drmdpy->wl_server_drm);
652 -   drmdpy->wl_server_drm = NULL;
653 -
654 -   return TRUE;
655 -}
656 -
657 -static struct native_display_wayland_bufmgr wayland_drm_display_wayland_bufmgr = {
658 -   wayland_drm_display_bind_wayland_display,
659 -   wayland_drm_display_unbind_wayland_display,
660 -   egl_g3d_wl_drm_common_wl_buffer_get_resource,
661 -   egl_g3d_wl_drm_common_query_buffer
662 -};
663 -
664 -
665  struct wayland_display *
666  wayland_create_drm_display(struct wl_display *dpy,
667                             const struct native_event_handler *event_handler)
668 @@ -322,7 +278,6 @@ wayland_create_drm_display(struct wl_display *dpy,
669     drmdpy->base.base.init_screen = wayland_drm_display_init_screen;
670     drmdpy->base.base.destroy = wayland_drm_display_destroy;
671     drmdpy->base.base.buffer = &wayland_drm_display_buffer;
672 -   drmdpy->base.base.wayland_bufmgr = &wayland_drm_display_wayland_bufmgr;
673  
674     drmdpy->base.create_buffer = wayland_create_drm_buffer;
675  
676 diff --git a/src/gallium/state_trackers/egl/x11/native_dri2.c b/src/gallium/state_trackers/egl/x11/native_dri2.c
677 index 053044a..3d08863 100644
678 --- a/src/gallium/state_trackers/egl/x11/native_dri2.c
679 +++ b/src/gallium/state_trackers/egl/x11/native_dri2.c
680 @@ -39,7 +39,7 @@
681  
682  #include "common/native_helper.h"
683  #ifdef HAVE_WAYLAND_BACKEND
684 -#include "common/native_wayland_drm_bufmgr_helper.h"
685 +#include "common/native_wayland_drm_bufmgr.h"
686  #endif
687  
688  #ifdef GLX_DIRECT_RENDERING
689 @@ -757,6 +757,8 @@ dri2_display_destroy(struct native_display *ndpy)
690     if (dri2dpy->surfaces)
691        util_hash_table_destroy(dri2dpy->surfaces);
692  
693 +   wayland_drm_bufmgr_destroy(ndpy->wayland_bufmgr);
694 +
695     if (dri2dpy->xscr)
696        x11_screen_destroy(dri2dpy->xscr);
697     if (dri2dpy->own_dpy)
698 @@ -785,6 +787,19 @@ dri2_display_invalidate_buffers(struct x11_screen *xscr, Drawable drawable,
699           &dri2surf->base, dri2surf->server_stamp);
700  }
701  
702 +#ifdef HAVE_WAYLAND_BACKEND
703 +
704 +static int
705 +dri2_display_authenticate(void *user_data, uint32_t magic)
706 +{
707 +   struct native_display *ndpy = user_data;
708 +   struct dri2_display *dri2dpy = dri2_display(ndpy);
709 +
710 +   return x11_screen_authenticate(dri2dpy->xscr, magic);
711 +}
712 +
713 +#endif /* HAVE_WAYLAND_BACKEND */
714 +
715  /**
716   * Initialize DRI2 and pipe screen.
717   */
718 @@ -816,6 +831,13 @@ dri2_display_init_screen(struct native_display *ndpy)
719        return FALSE;
720     }
721  
722 +#ifdef HAVE_WAYLAND_BACKEND
723 +   dri2dpy->base.wayland_bufmgr = wayland_drm_bufmgr_create(
724 +         dri2_display_authenticate, dri2dpy,
725 +         x11_screen_get_device_name(dri2dpy->xscr));
726 +
727 +#endif
728 +
729     return TRUE;
730  }
731  
732 @@ -832,66 +854,6 @@ dri2_display_hash_table_compare(void *key1, void *key2)
733     return ((char *) key1 - (char *) key2);
734  }
735  
736 -#ifdef HAVE_WAYLAND_BACKEND
737 -
738 -static int
739 -dri2_display_authenticate(void *user_data, uint32_t magic)
740 -{
741 -   struct native_display *ndpy = user_data;
742 -   struct dri2_display *dri2dpy = dri2_display(ndpy);
743 -
744 -   return x11_screen_authenticate(dri2dpy->xscr, magic);
745 -}
746 -
747 -static struct wayland_drm_callbacks wl_drm_callbacks = {
748 -   dri2_display_authenticate,
749 -   egl_g3d_wl_drm_helper_reference_buffer,
750 -   egl_g3d_wl_drm_helper_unreference_buffer
751 -};
752 -
753 -static boolean
754 -dri2_display_bind_wayland_display(struct native_display *ndpy,
755 -                                  struct wl_display *wl_dpy)
756 -{
757 -   struct dri2_display *dri2dpy = dri2_display(ndpy);
758 -
759 -   if (dri2dpy->wl_server_drm)
760 -      return FALSE;
761 -
762 -   dri2dpy->wl_server_drm = wayland_drm_init(wl_dpy,
763 -         x11_screen_get_device_name(dri2dpy->xscr),
764 -         &wl_drm_callbacks, ndpy, 0);
765 -
766 -   if (!dri2dpy->wl_server_drm)
767 -      return FALSE;
768 -   
769 -   return TRUE;
770 -}
771 -
772 -static boolean
773 -dri2_display_unbind_wayland_display(struct native_display *ndpy,
774 -                                    struct wl_display *wl_dpy)
775 -{
776 -   struct dri2_display *dri2dpy = dri2_display(ndpy);
777 -
778 -   if (!dri2dpy->wl_server_drm)
779 -      return FALSE;
780 -
781 -   wayland_drm_uninit(dri2dpy->wl_server_drm);
782 -   dri2dpy->wl_server_drm = NULL;
783 -
784 -   return TRUE;
785 -}
786 -
787 -static struct native_display_wayland_bufmgr dri2_display_wayland_bufmgr = {
788 -   dri2_display_bind_wayland_display,
789 -   dri2_display_unbind_wayland_display,
790 -   egl_g3d_wl_drm_common_wl_buffer_get_resource,
791 -   egl_g3d_wl_drm_common_query_buffer
792 -};
793 -
794 -#endif /* HAVE_WAYLAND_BACKEND */
795 -
796  struct native_display *
797  x11_create_dri2_display(Display *dpy,
798                          const struct native_event_handler *event_handler)
799 @@ -936,9 +898,6 @@ x11_create_dri2_display(Display *dpy,
800     dri2dpy->base.copy_to_pixmap = native_display_copy_to_pixmap;
801     dri2dpy->base.create_window_surface = dri2_display_create_window_surface;
802     dri2dpy->base.create_pixmap_surface = dri2_display_create_pixmap_surface;
803 -#ifdef HAVE_WAYLAND_BACKEND
804 -   dri2dpy->base.wayland_bufmgr = &dri2_display_wayland_bufmgr;
805 -#endif
806  
807     return &dri2dpy->base;
808  }
809 -- 
810 1.8.4
811
This page took 0.126181 seconds and 3 git commands to generate.