meta-agl-profile-telematics: recipes-core: systemd: change canbus systemd match regex
[AGL/meta-agl.git] / meta-agl-bsp / meta-ti / recipes-arago / gstreamer / gstreamer1.0-plugins-bad / 0004-gstwaylandsink-Add-DRM-support-on-waylandsink.patch
1 From 78ddc83ebfe7cf69c62610e1f7d14e7f49bf65c9 Mon Sep 17 00:00:00 2001
2 From: Pooja Prajod <a0132412@ti.com>
3 Date: Wed, 25 Jan 2017 17:09:35 +0530
4 Subject: [gst-bad-1.8] gstwaylandsink: Add DRM support on waylandsink
5
6 Add wl_drm interface on waylandsink.
7 The following features are supported:
8 1. Support for mouse drag and drop.
9 2. Support for video cropping
10
11 The following bug fixes identified earlier have been picked:
12 1. Consolidate header files to avoid circular dependency
13 2. Fix bug reported on waylandsink incase of same process looping
14
15 Signed-off-by: Pooja Prajod <a0132412@ti.com>
16 ---
17  configure.ac                              |   4 +-
18  ext/wayland/Makefile.am                   |  17 +-
19  ext/wayland/gstwaylandsink.c              |  82 ++++++-
20  ext/wayland/gstwaylandsink.h              |   4 +-
21  ext/wayland/wayland-drm-client-protocol.h | 213 ++++++++++++++++++
22  ext/wayland/wayland-drm-protocol.c        |  74 +++++++
23  ext/wayland/wlbuffer.c                    |   2 +-
24  ext/wayland/wlbuffer.h                    |  67 ------
25  ext/wayland/wldisplay-wlwindow-wlbuffer.h | 216 ++++++++++++++++++
26  ext/wayland/wldisplay.c                   | 350 +++++++++++++++++++++++++++++-
27  ext/wayland/wldisplay.h                   |  84 -------
28  ext/wayland/wldrm.c                       |  69 ++++++
29  ext/wayland/wldrm.h                       |   3 +
30  ext/wayland/wlshmallocator.h              |   2 +-
31  ext/wayland/wlvideoformat.c               |   8 +-
32  ext/wayland/wlwindow.c                    |  47 +++-
33  ext/wayland/wlwindow.h                    |  84 -------
34  17 files changed, 1056 insertions(+), 270 deletions(-)
35  create mode 100644 ext/wayland/wayland-drm-client-protocol.h
36  create mode 100644 ext/wayland/wayland-drm-protocol.c
37  delete mode 100644 ext/wayland/wlbuffer.h
38  create mode 100644 ext/wayland/wldisplay-wlwindow-wlbuffer.h
39  delete mode 100644 ext/wayland/wldisplay.h
40  create mode 100644 ext/wayland/wldrm.c
41  create mode 100644 ext/wayland/wldrm.h
42  delete mode 100644 ext/wayland/wlwindow.h
43
44 diff --git a/configure.ac b/configure.ac
45 index 9fdfbc7..76166cb 100644
46 --- a/configure.ac
47 +++ b/configure.ac
48 @@ -2172,8 +2172,10 @@ AG_GST_CHECK_FEATURE(DIRECTFB, [directfb], dfbvideosink , [
49  dnl **** Wayland ****
50  translit(dnm, m, l) AM_CONDITIONAL(USE_WAYLAND, true)
51  AC_PATH_PROG([wayland_scanner], [wayland-scanner])
52 -AG_GST_CHECK_FEATURE(WAYLAND, [wayland sink], wayland , [
53 +AG_GST_CHECK_FEATURE(WAYLAND, [wayland sink], wayland libdrm libdrm_omap, [
54    PKG_CHECK_MODULES(WAYLAND, wayland-client >= 1.4.0, [
55 +    AC_SUBST(DRM_CFLAGS)
56 +    AC_SUBST(DRM_LIBS)
57      if test "x$wayland_scanner" != "x"; then
58        HAVE_WAYLAND="yes"
59      else
60 diff --git a/ext/wayland/Makefile.am b/ext/wayland/Makefile.am
61 index c742bfc..eb6e326 100644
62 --- a/ext/wayland/Makefile.am
63 +++ b/ext/wayland/Makefile.am
64 @@ -3,31 +3,34 @@ plugin_LTLIBRARIES = libgstwaylandsink.la
65  libgstwaylandsink_la_SOURCES =  \
66         gstwaylandsink.c \
67         wlshmallocator.c \
68 +        wldrm.c \
69         wlbuffer.c \
70         wldisplay.c \
71         wlwindow.c \
72         wlvideoformat.c \
73 -       scaler-protocol.c
74 +       scaler-protocol.c \
75 +        wayland-drm-protocol.c
76  
77  libgstwaylandsink_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) \
78 -                               $(WAYLAND_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS)
79 +                               $(WAYLAND_CFLAGS) $(GST_PLUGINS_BAD_CFLAGS) $(DRM_CFLAGS)
80  libgstwaylandsink_la_LIBADD = \
81         $(GST_PLUGINS_BASE_LIBS) \
82         -lgstvideo-$(GST_API_VERSION) \
83         -lgstallocators-$(GST_API_VERSION) \
84         $(WAYLAND_LIBS) \
85 -       $(top_builddir)/gst-libs/gst/wayland/libgstwayland-$(GST_API_VERSION).la
86 +       $(top_builddir)/gst-libs/gst/wayland/libgstwayland-$(GST_API_VERSION).la \
87 +        $(top_builddir)/gst-libs/gst/drm/libgstdrm-$(GST_API_VERSION).la
88  libgstwaylandsink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
89  libgstwaylandsink_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
90  
91  noinst_HEADERS = \
92         gstwaylandsink.h \
93         wlshmallocator.h \
94 -       wlbuffer.h \
95 -       wldisplay.h \
96 -       wlwindow.h \
97 +        wldisplay-wlwindow-wlbuffer.h \
98 +        wldrm.h \
99         wlvideoformat.h \
100 -       scaler-client-protocol.h
101 +       scaler-client-protocol.h \
102 +        wayland-drm-client-protocol.h
103  
104  EXTRA_DIST = scaler.xml
105  CLEANFILES = scaler-protocol.c scaler-client-protocol.h
106 diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c
107 index f4f34a8..3e8ff19 100644
108 --- a/ext/wayland/gstwaylandsink.c
109 +++ b/ext/wayland/gstwaylandsink.c
110 @@ -43,8 +43,14 @@
111  
112  #include "gstwaylandsink.h"
113  #include "wlvideoformat.h"
114 -#include "wlbuffer.h"
115  #include "wlshmallocator.h"
116 +#include "wldrm.h"
117 +
118 +#include <gst/drm/gstdrmallocator.h>
119 +#include "wayland-drm-client-protocol.h"
120 +#include <omap_drm.h>
121 +#include <omap_drmif.h>
122 +#include <wayland-client.h>
123  
124  #include <gst/wayland/wayland.h>
125  #include <gst/video/videooverlay.h>
126 @@ -60,7 +66,8 @@ enum
127  enum
128  {
129    PROP_0,
130 -  PROP_DISPLAY
131 +  PROP_DISPLAY,
132 +  PROP_ALLOCATION
133  };
134  
135  GST_DEBUG_CATEGORY (gstwayland_debug);
136 @@ -75,6 +82,7 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
137              "YUV9, YVU9, Y41B, I420, YV12, Y42B, v308 }"))
138      );
139  
140 +
141  static void gst_wayland_sink_get_property (GObject * object,
142      guint prop_id, GValue * value, GParamSpec * pspec);
143  static void gst_wayland_sink_set_property (GObject * object,
144 @@ -158,6 +166,11 @@ gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
145        g_param_spec_string ("display", "Wayland Display name", "Wayland "
146            "display name to connect to, if not supplied via the GstContext",
147            NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
148 +  
149 +  g_object_class_install_property (gobject_class, PROP_ALLOCATION,
150 +      g_param_spec_boolean ("use-drm", "Wayland Allocation name", "Wayland "
151 +          "Use DRM based memory for allocation",
152 +          FALSE, G_PARAM_WRITABLE));
153  }
154  
155  static void
156 @@ -197,6 +210,11 @@ gst_wayland_sink_set_property (GObject * object,
157        sink->display_name = g_value_dup_string (value);
158        GST_OBJECT_UNLOCK (sink);
159        break;
160 +   case PROP_ALLOCATION:
161 +      GST_OBJECT_LOCK (sink);
162 +      sink->use_drm = g_value_get_boolean (value);
163 +      GST_OBJECT_UNLOCK (sink);
164 +      break;     
165      default:
166        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
167        break;
168 @@ -281,6 +299,7 @@ gst_wayland_sink_find_display (GstWaylandSink * sink)
169          /* if the application didn't set a display, let's create it ourselves */
170          GST_OBJECT_LOCK (sink);
171          sink->display = gst_wl_display_new (sink->display_name, &error);
172 +        sink->display->use_drm = sink->use_drm;
173          GST_OBJECT_UNLOCK (sink);
174  
175          if (error) {
176 @@ -408,7 +427,6 @@ gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
177  
178      caps = gst_caps_make_writable (caps);
179      gst_structure_set_value (gst_caps_get_structure (caps, 0), "format", &list);
180 -
181      GST_DEBUG_OBJECT (sink, "display caps: %" GST_PTR_FORMAT, caps);
182    }
183  
184 @@ -426,6 +444,18 @@ gst_wayland_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
185    return caps;
186  }
187  
188 +static void
189 +wait_authentication (GstWaylandSink * sink)
190 +{
191 +  GST_DEBUG_OBJECT (sink, "Before wait aunthenticated value is %d : \n", sink->display->authenticated );
192 +  while (!sink->display->authenticated) {
193 +    GST_DEBUG_OBJECT (sink, "waiting for authentication");
194 +    wl_display_roundtrip (sink->display->display);
195 +  }
196 +  GST_DEBUG_OBJECT (sink, "After wait aunthenticated value is %d : \n", sink->display->authenticated );
197 +}
198 +
199 +
200  static gboolean
201  gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
202  {
203 @@ -436,11 +466,20 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
204    GArray *formats;
205    gint i;
206    GstStructure *structure;
207 +  GstStructure *s;
208 +  gboolean use_drm = 0;
209 +  int num_buffers = 0;
210  
211    sink = GST_WAYLAND_SINK (bsink);
212  
213    GST_DEBUG_OBJECT (sink, "set caps %" GST_PTR_FORMAT, caps);
214  
215 +  wait_authentication (sink);
216 +
217 +  while (!sink->display->authenticated) {
218 +    GST_DEBUG_OBJECT (sink, "not authenticated yet");
219 +  } 
220 +
221    /* extract info from caps */
222    if (!gst_video_info_from_caps (&info, caps))
223      goto invalid_format;
224 @@ -460,14 +499,27 @@ gst_wayland_sink_set_caps (GstBaseSink * bsink, GstCaps * caps)
225      goto unsupported_format;
226  
227    /* create a new pool for the new configuration */
228 -  newpool = gst_video_buffer_pool_new ();
229 +
230 +  s = gst_caps_get_structure (caps, 0);
231 +  gst_structure_get_boolean (s, "drm_mem", &use_drm);
232 +  gst_structure_get_int (s, "max-ref-frames", &num_buffers);
233 +  if (num_buffers )
234 +    num_buffers = num_buffers + 2;
235 +
236 +  newpool = gst_buffer_pool_new ();
237    if (!newpool)
238      goto pool_failed;
239  
240    structure = gst_buffer_pool_get_config (newpool);
241 -  gst_buffer_pool_config_set_params (structure, caps, info.size, 2, 0);
242 -  gst_buffer_pool_config_set_allocator (structure, gst_wl_shm_allocator_get (),
243 -      NULL);
244 +  gst_buffer_pool_config_set_params (structure, caps, info.size, 2, num_buffers);
245 +  if ( use_drm ) {
246 +    gst_buffer_pool_config_set_allocator (structure, gst_drm_allocator_get (),
247 +        NULL);
248 +    sink->display->use_drm = TRUE;
249 +  } else {
250 +    gst_buffer_pool_config_set_allocator (structure, gst_wl_shm_allocator_get (),
251 +        NULL);
252 +  }
253    if (!gst_buffer_pool_set_config (newpool, structure))
254      goto config_failed;
255  
256 @@ -518,8 +570,11 @@ gst_wayland_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
257    /* we do have a pool for sure (created in set_caps),
258     * so let's propose it anyway, but also propose the allocator on its own */
259    gst_query_add_allocation_pool (query, sink->pool, size, min_bufs, max_bufs);
260 -  gst_query_add_allocation_param (query, gst_wl_shm_allocator_get (), NULL);
261 -
262 +  if (sink->display->use_drm) {
263 +    gst_query_add_allocation_param (query, gst_drm_allocator_get (), NULL);
264 +  } else {
265 +    gst_query_add_allocation_param (query, gst_wl_shm_allocator_get (), NULL);
266 +  }
267    gst_structure_free (config);
268  
269    return TRUE;
270 @@ -582,6 +637,10 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
271  
272    GST_LOG_OBJECT (sink, "render buffer %p", buffer);
273  
274 +  if (sink->display) {
275 +    sink->display->crop = gst_buffer_get_video_crop_meta (buffer); 
276 +  }
277 +
278    if (G_UNLIKELY (!sink->window)) {
279      /* ask for window handle. Unlock render_lock while doing that because
280       * set_window_handle & friends will lock it in this context */
281 @@ -623,6 +682,11 @@ gst_wayland_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
282        wbuf = gst_wl_shm_memory_construct_wl_buffer (mem, sink->display,
283            &sink->video_info);
284      }
285 +    
286 +    if (gst_is_drm_memory (mem)) {
287 +      wbuf = gst_wl_drm_memory_construct_wl_buffer (mem, sink->display,
288 +          &sink->video_info);      
289 +    }
290  
291      if (wbuf) {
292        gst_buffer_add_wl_buffer (buffer, wbuf, sink->display);
293 diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h
294 index afbed40..c1092ce 100644
295 --- a/ext/wayland/gstwaylandsink.h
296 +++ b/ext/wayland/gstwaylandsink.h
297 @@ -27,8 +27,7 @@
298  
299  #include <wayland-client.h>
300  
301 -#include "wldisplay.h"
302 -#include "wlwindow.h"
303 +#include "wldisplay-wlwindow-wlbuffer.h"
304  
305  G_BEGIN_DECLS
306  
307 @@ -61,6 +60,7 @@ struct _GstWaylandSink
308    GstVideoInfo video_info;
309  
310    gchar *display_name;
311 +  gboolean use_drm;  
312  
313    gboolean redraw_pending;
314    GMutex render_lock;
315 diff --git a/ext/wayland/wayland-drm-client-protocol.h b/ext/wayland/wayland-drm-client-protocol.h
316 new file mode 100644
317 index 0000000..7ddb614
318 --- /dev/null
319 +++ b/ext/wayland/wayland-drm-client-protocol.h
320 @@ -0,0 +1,213 @@
321 +/* 
322 + * Copyright Â© 2008-2011 Kristian Høgsberg
323 + * Copyright Â© 2010-2011 Intel Corporation
324 + * 
325 + * Permission to use, copy, modify, distribute, and sell this
326 + * software and its documentation for any purpose is hereby granted
327 + * without fee, provided that\n the above copyright notice appear in
328 + * all copies and that both that copyright notice and this permission
329 + * notice appear in supporting documentation, and that the name of
330 + * the copyright holders not be used in advertising or publicity
331 + * pertaining to distribution of the software without specific,
332 + * written prior permission.  The copyright holders make no
333 + * representations about the suitability of this software for any
334 + * purpose.  It is provided "as is" without express or implied
335 + * warranty.
336 + * 
337 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
338 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
339 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
340 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
341 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
342 + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
343 + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
344 + * THIS SOFTWARE.
345 + */
346 +
347 +#ifndef DRM_CLIENT_PROTOCOL_H
348 +#define DRM_CLIENT_PROTOCOL_H
349 +
350 +#ifdef  __cplusplus
351 +extern "C" {
352 +#endif
353 +
354 +#include <stdint.h>
355 +#include <stddef.h>
356 +#include "wayland-util.h"
357 +
358 +struct wl_client;
359 +struct wl_resource;
360 +
361 +struct wl_drm;
362 +
363 +extern const struct wl_interface wl_drm_interface;
364 +
365 +#ifndef WL_DRM_ERROR_ENUM
366 +#define WL_DRM_ERROR_ENUM
367 +enum wl_drm_error {
368 +       WL_DRM_ERROR_AUTHENTICATE_FAIL = 0,
369 +       WL_DRM_ERROR_INVALID_FORMAT = 1,
370 +       WL_DRM_ERROR_INVALID_NAME = 2,
371 +};
372 +#endif /* WL_DRM_ERROR_ENUM */
373 +
374 +#ifndef WL_DRM_FORMAT_ENUM
375 +#define WL_DRM_FORMAT_ENUM
376 +enum wl_drm_format {
377 +       WL_DRM_FORMAT_C8 = 0x20203843,
378 +       WL_DRM_FORMAT_RGB332 = 0x38424752,
379 +       WL_DRM_FORMAT_BGR233 = 0x38524742,
380 +       WL_DRM_FORMAT_XRGB4444 = 0x32315258,
381 +       WL_DRM_FORMAT_XBGR4444 = 0x32314258,
382 +       WL_DRM_FORMAT_RGBX4444 = 0x32315852,
383 +       WL_DRM_FORMAT_BGRX4444 = 0x32315842,
384 +       WL_DRM_FORMAT_ARGB4444 = 0x32315241,
385 +       WL_DRM_FORMAT_ABGR4444 = 0x32314241,
386 +       WL_DRM_FORMAT_RGBA4444 = 0x32314152,
387 +       WL_DRM_FORMAT_BGRA4444 = 0x32314142,
388 +       WL_DRM_FORMAT_XRGB1555 = 0x35315258,
389 +       WL_DRM_FORMAT_XBGR1555 = 0x35314258,
390 +       WL_DRM_FORMAT_RGBX5551 = 0x35315852,
391 +       WL_DRM_FORMAT_BGRX5551 = 0x35315842,
392 +       WL_DRM_FORMAT_ARGB1555 = 0x35315241,
393 +       WL_DRM_FORMAT_ABGR1555 = 0x35314241,
394 +       WL_DRM_FORMAT_RGBA5551 = 0x35314152,
395 +       WL_DRM_FORMAT_BGRA5551 = 0x35314142,
396 +       WL_DRM_FORMAT_RGB565 = 0x36314752,
397 +       WL_DRM_FORMAT_BGR565 = 0x36314742,
398 +       WL_DRM_FORMAT_RGB888 = 0x34324752,
399 +       WL_DRM_FORMAT_BGR888 = 0x34324742,
400 +       WL_DRM_FORMAT_XRGB8888 = 0x34325258,
401 +       WL_DRM_FORMAT_XBGR8888 = 0x34324258,
402 +       WL_DRM_FORMAT_RGBX8888 = 0x34325852,
403 +       WL_DRM_FORMAT_BGRX8888 = 0x34325842,
404 +       WL_DRM_FORMAT_ARGB8888 = 0x34325241,
405 +       WL_DRM_FORMAT_ABGR8888 = 0x34324241,
406 +       WL_DRM_FORMAT_RGBA8888 = 0x34324152,
407 +       WL_DRM_FORMAT_BGRA8888 = 0x34324142,
408 +       WL_DRM_FORMAT_XRGB2101010 = 0x30335258,
409 +       WL_DRM_FORMAT_XBGR2101010 = 0x30334258,
410 +       WL_DRM_FORMAT_RGBX1010102 = 0x30335852,
411 +       WL_DRM_FORMAT_BGRX1010102 = 0x30335842,
412 +       WL_DRM_FORMAT_ARGB2101010 = 0x30335241,
413 +       WL_DRM_FORMAT_ABGR2101010 = 0x30334241,
414 +       WL_DRM_FORMAT_RGBA1010102 = 0x30334152,
415 +       WL_DRM_FORMAT_BGRA1010102 = 0x30334142,
416 +       WL_DRM_FORMAT_YUYV = 0x56595559,
417 +       WL_DRM_FORMAT_YVYU = 0x55595659,
418 +       WL_DRM_FORMAT_UYVY = 0x59565955,
419 +       WL_DRM_FORMAT_VYUY = 0x59555956,
420 +       WL_DRM_FORMAT_AYUV = 0x56555941,
421 +       WL_DRM_FORMAT_NV12 = 0x3231564e,
422 +       WL_DRM_FORMAT_NV21 = 0x3132564e,
423 +       WL_DRM_FORMAT_NV16 = 0x3631564e,
424 +       WL_DRM_FORMAT_NV61 = 0x3136564e,
425 +       WL_DRM_FORMAT_YUV410 = 0x39565559,
426 +       WL_DRM_FORMAT_YVU410 = 0x39555659,
427 +       WL_DRM_FORMAT_YUV411 = 0x31315559,
428 +       WL_DRM_FORMAT_YVU411 = 0x31315659,
429 +       WL_DRM_FORMAT_YUV420 = 0x32315559,
430 +       WL_DRM_FORMAT_YVU420 = 0x32315659,
431 +       WL_DRM_FORMAT_YUV422 = 0x36315559,
432 +       WL_DRM_FORMAT_YVU422 = 0x36315659,
433 +       WL_DRM_FORMAT_YUV444 = 0x34325559,
434 +       WL_DRM_FORMAT_YVU444 = 0x34325659,
435 +};
436 +#endif /* WL_DRM_FORMAT_ENUM */
437 +
438 +struct wl_drm_listener {
439 +       /**
440 +        * device - (none)
441 +        * @name: (none)
442 +        */
443 +       void (*device)(void *data,
444 +                      struct wl_drm *wl_drm,
445 +                      const char *name);
446 +       /**
447 +        * format - (none)
448 +        * @format: (none)
449 +        */
450 +       void (*format)(void *data,
451 +                      struct wl_drm *wl_drm,
452 +                      uint32_t format);
453 +       /**
454 +        * authenticated - (none)
455 +        */
456 +       void (*authenticated)(void *data,
457 +                             struct wl_drm *wl_drm);
458 +};
459 +
460 +static inline int
461 +wl_drm_add_listener(struct wl_drm *wl_drm,
462 +                   const struct wl_drm_listener *listener, void *data)
463 +{
464 +       return wl_proxy_add_listener((struct wl_proxy *) wl_drm,
465 +                                    (void (**)(void)) listener, data);
466 +}
467 +
468 +#define WL_DRM_AUTHENTICATE    0
469 +#define WL_DRM_CREATE_BUFFER   1
470 +#define WL_DRM_CREATE_PLANAR_BUFFER    2
471 +
472 +static inline void
473 +wl_drm_set_user_data(struct wl_drm *wl_drm, void *user_data)
474 +{
475 +       wl_proxy_set_user_data((struct wl_proxy *) wl_drm, user_data);
476 +}
477 +
478 +static inline void *
479 +wl_drm_get_user_data(struct wl_drm *wl_drm)
480 +{
481 +       return wl_proxy_get_user_data((struct wl_proxy *) wl_drm);
482 +}
483 +
484 +static inline void
485 +wl_drm_destroy(struct wl_drm *wl_drm)
486 +{
487 +       wl_proxy_destroy((struct wl_proxy *) wl_drm);
488 +}
489 +
490 +static inline void
491 +wl_drm_authenticate(struct wl_drm *wl_drm, uint32_t id)
492 +{
493 +       wl_proxy_marshal((struct wl_proxy *) wl_drm,
494 +                        WL_DRM_AUTHENTICATE, id);
495 +}
496 +
497 +static inline struct wl_buffer *
498 +wl_drm_create_buffer(struct wl_drm *wl_drm, uint32_t name, int32_t width, int32_t height, uint32_t stride, uint32_t format)
499 +{
500 +       struct wl_proxy *id;
501 +
502 +       id = wl_proxy_create((struct wl_proxy *) wl_drm,
503 +                            &wl_buffer_interface);
504 +       if (!id)
505 +               return NULL;
506 +
507 +       wl_proxy_marshal((struct wl_proxy *) wl_drm,
508 +                        WL_DRM_CREATE_BUFFER, id, name, width, height, stride, format);
509 +
510 +       return (struct wl_buffer *) id;
511 +}
512 +
513 +static inline struct wl_buffer *
514 +wl_drm_create_planar_buffer(struct wl_drm *wl_drm, uint32_t name, int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2)
515 +{
516 +       struct wl_proxy *id;
517 +
518 +       id = wl_proxy_create((struct wl_proxy *) wl_drm,
519 +                            &wl_buffer_interface);
520 +       if (!id)
521 +               return NULL;
522 +
523 +       wl_proxy_marshal((struct wl_proxy *) wl_drm,
524 +                        WL_DRM_CREATE_PLANAR_BUFFER, id, name, width, height, format, offset0, stride0, offset1, stride1, offset2, stride2);
525 +
526 +       return (struct wl_buffer *) id;
527 +}
528 +
529 +#ifdef  __cplusplus
530 +}
531 +#endif
532 +
533 +#endif
534 diff --git a/ext/wayland/wayland-drm-protocol.c b/ext/wayland/wayland-drm-protocol.c
535 new file mode 100644
536 index 0000000..939af53
537 --- /dev/null
538 +++ b/ext/wayland/wayland-drm-protocol.c
539 @@ -0,0 +1,74 @@
540 +/* 
541 + * Copyright Â© 2008-2011 Kristian Høgsberg
542 + * Copyright Â© 2010-2011 Intel Corporation
543 + * 
544 + * Permission to use, copy, modify, distribute, and sell this
545 + * software and its documentation for any purpose is hereby granted
546 + * without fee, provided that\n the above copyright notice appear in
547 + * all copies and that both that copyright notice and this permission
548 + * notice appear in supporting documentation, and that the name of
549 + * the copyright holders not be used in advertising or publicity
550 + * pertaining to distribution of the software without specific,
551 + * written prior permission.  The copyright holders make no
552 + * representations about the suitability of this software for any
553 + * purpose.  It is provided "as is" without express or implied
554 + * warranty.
555 + * 
556 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
557 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
558 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
559 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
560 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
561 + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
562 + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
563 + * THIS SOFTWARE.
564 + */
565 +
566 +#include <stdlib.h>
567 +#include <stdint.h>
568 +#include "wayland-util.h"
569 +
570 +#define ARRAY_LENGTH(a) (sizeof (a) /sizeof (a)[0])
571 +
572 +extern const struct wl_interface wl_buffer_interface;
573 +extern const struct wl_interface wl_buffer_interface;
574 +
575 +static const struct wl_interface *types[] = {
576 +       NULL,
577 +       &wl_buffer_interface,
578 +       NULL,
579 +       NULL,
580 +       NULL,
581 +       NULL,
582 +       NULL,
583 +       &wl_buffer_interface,
584 +       NULL,
585 +       NULL,
586 +       NULL,
587 +       NULL,
588 +       NULL,
589 +       NULL,
590 +       NULL,
591 +       NULL,
592 +       NULL,
593 +       NULL,
594 +};
595 +
596 +static const struct wl_message wl_drm_requests[] = {
597 +       { "authenticate", "u", types + 0 },
598 +       { "create_buffer", "nuiiuu", types + 1 },
599 +       { "create_planar_buffer", "nuiiuiiiiii", types + 7 },
600 +};
601 +
602 +static const struct wl_message wl_drm_events[] = {
603 +       { "device", "s", types + 0 },
604 +       { "format", "u", types + 0 },
605 +       { "authenticated", "", types + 0 },
606 +};
607 +
608 +WL_EXPORT const struct wl_interface wl_drm_interface = {
609 +       "wl_drm", 1,
610 +       ARRAY_LENGTH(wl_drm_requests), wl_drm_requests,
611 +       ARRAY_LENGTH(wl_drm_events), wl_drm_events,
612 +};
613 +
614 diff --git a/ext/wayland/wlbuffer.c b/ext/wayland/wlbuffer.c
615 index 4ac99ef..0e38d2e 100644
616 --- a/ext/wayland/wlbuffer.c
617 +++ b/ext/wayland/wlbuffer.c
618 @@ -76,7 +76,7 @@
619   * as soon as we remove the reference that GstWlDisplay holds.
620   */
621  
622 -#include "wlbuffer.h"
623 +#include "wldisplay-wlwindow-wlbuffer.h"
624  
625  GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
626  #define GST_CAT_DEFAULT gstwayland_debug
627 diff --git a/ext/wayland/wlbuffer.h b/ext/wayland/wlbuffer.h
628 deleted file mode 100644
629 index cbb50f7..0000000
630 --- a/ext/wayland/wlbuffer.h
631 +++ /dev/null
632 @@ -1,67 +0,0 @@
633 -/* GStreamer Wayland video sink
634 - *
635 - * Copyright (C) 2014 Collabora Ltd.
636 - *
637 - * This library is free software; you can redistribute it and/or
638 - * modify it under the terms of the GNU Library General Public
639 - * License as published by the Free Software Foundation; either
640 - * version 2 of the License, or (at your option) any later version.
641 - *
642 - * This library is distributed in the hope that it will be useful,
643 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
644 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
645 - * Library General Public License for more details.
646 - *
647 - * You should have received a copy of the GNU Library General Public
648 - * License along with this library; if not, write to the Free
649 - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
650 - * Boston, MA 02110-1301 USA.
651 - */
652 -
653 -#ifndef __GST_WL_BUFFER_H__
654 -#define __GST_WL_BUFFER_H__
655 -
656 -#include "wldisplay.h"
657 -
658 -G_BEGIN_DECLS
659 -
660 -#define GST_TYPE_WL_BUFFER                  (gst_wl_buffer_get_type ())
661 -#define GST_WL_BUFFER(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_BUFFER, GstWlBuffer))
662 -#define GST_IS_WL_BUFFER(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_BUFFER))
663 -#define GST_WL_BUFFER_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_BUFFER, GstWlBufferClass))
664 -#define GST_IS_WL_BUFFER_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_BUFFER))
665 -#define GST_WL_BUFFER_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_BUFFER, GstWlBufferClass))
666 -
667 -typedef struct _GstWlBuffer GstWlBuffer;
668 -typedef struct _GstWlBufferClass GstWlBufferClass;
669 -
670 -struct _GstWlBuffer
671 -{
672 -  GObject parent_instance;
673 -
674 -  struct wl_buffer * wlbuffer;
675 -  GstBuffer *gstbuffer;
676 -
677 -  GstWlDisplay *display;
678 -
679 -  gboolean used_by_compositor;
680 -};
681 -
682 -struct _GstWlBufferClass
683 -{
684 -  GObjectClass parent_class;
685 -};
686 -
687 -GType gst_wl_buffer_get_type (void);
688 -
689 -GstWlBuffer * gst_buffer_add_wl_buffer (GstBuffer * gstbuffer,
690 -    struct wl_buffer * wlbuffer, GstWlDisplay * display);
691 -GstWlBuffer * gst_buffer_get_wl_buffer (GstBuffer * gstbuffer);
692 -
693 -void gst_wl_buffer_force_release_and_unref (GstWlBuffer * self);
694 -
695 -void gst_wl_buffer_attach (GstWlBuffer * self, struct wl_surface *surface);
696 -
697 -G_END_DECLS
698 -
699 -#endif /* __GST_WL_BUFFER_H__ */
700 diff --git a/ext/wayland/wldisplay-wlwindow-wlbuffer.h b/ext/wayland/wldisplay-wlwindow-wlbuffer.h
701 new file mode 100644
702 index 0000000..684d145
703 --- /dev/null
704 +++ b/ext/wayland/wldisplay-wlwindow-wlbuffer.h
705 @@ -0,0 +1,216 @@
706 +/* GStreamer Wayland video sink
707 + *
708 + * Copyright (C) 2014 Collabora Ltd.
709 + *
710 + * This library is free software; you can redistribute it and/or
711 + * modify it under the terms of the GNU Library General Public
712 + * License as published by the Free Software Foundation; either
713 + * version 2 of the License, or (at your option) any later version.
714 + *
715 + * This library is distributed in the hope that it will be useful,
716 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
717 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
718 + * Library General Public License for more details.
719 + *
720 + * You should have received a copy of the GNU Library General Public
721 + * License along with this library; if not, write to the Free
722 + * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
723 + * Boston, MA 02110-1301 USA.
724 + */
725 +
726 +#ifndef __GST_WL_DISPLAY_WL_WINDOW_H__
727 +#define __GST_WL_DISPLAY_WL_WINDOW_H__
728 +
729 +#include <gst/gst.h>
730 +#include <stdlib.h>
731 +#include <stdio.h>
732 +#include <wayland-client.h>
733 +#include "scaler-client-protocol.h"
734 +#include <gst/video/video.h>
735 +#include <gst/video/gstvideometa.h>
736 +
737 +G_BEGIN_DECLS
738 +
739 +#define GST_TYPE_WL_DISPLAY                  (gst_wl_display_get_type ())
740 +#define GST_WL_DISPLAY(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplay))
741 +#define GST_IS_WL_DISPLAY(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_DISPLAY))
742 +#define GST_WL_DISPLAY_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
743 +#define GST_IS_WL_DISPLAY_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_DISPLAY))
744 +#define GST_WL_DISPLAY_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
745 +
746 +#define GST_TYPE_WL_WINDOW                  (gst_wl_window_get_type ())
747 +#define GST_WL_WINDOW(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_WINDOW, GstWlWindow))
748 +#define GST_IS_WL_WINDOW(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_WINDOW))
749 +#define GST_WL_WINDOW_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_WINDOW, GstWlWindowClass))
750 +#define GST_IS_WL_WINDOW_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_WINDOW))
751 +#define GST_WL_WINDOW_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_WINDOW, GstWlWindowClass))
752 +
753 +#define GST_TYPE_WL_BUFFER                  (gst_wl_buffer_get_type ())
754 +#define GST_WL_BUFFER(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_BUFFER, GstWlBuffer))
755 +#define GST_IS_WL_BUFFER(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_BUFFER))
756 +#define GST_WL_BUFFER_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_BUFFER, GstWlBufferClass))
757 +#define GST_IS_WL_BUFFER_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_BUFFER))
758 +#define GST_WL_BUFFER_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_BUFFER, GstWlBufferClass))
759 +
760 +typedef struct _GstWlBuffer GstWlBuffer;
761 +typedef struct _GstWlBufferClass GstWlBufferClass;
762 +
763 +typedef struct _GstWlWindow GstWlWindow;
764 +typedef struct _GstWlWindowClass GstWlWindowClass;
765 +
766 +typedef struct _GstWlDisplay GstWlDisplay;
767 +typedef struct _GstWlDisplayClass GstWlDisplayClass;
768 +
769 +struct _GstWlBuffer
770 +{
771 +  GObject parent_instance;
772 +
773 +  struct wl_buffer * wlbuffer;
774 +  GstBuffer *gstbuffer;
775 +
776 +  GstWlDisplay *display;
777 +
778 +  gboolean used_by_compositor;
779 +};
780 +
781 +struct _GstWlBufferClass
782 +{
783 +  GObjectClass parent_class;
784 +};
785 +
786 +GType gst_wl_buffer_get_type (void);
787 +
788 +GstWlBuffer * gst_buffer_add_wl_buffer (GstBuffer * gstbuffer,
789 +    struct wl_buffer * wlbuffer, GstWlDisplay * display);
790 +GstWlBuffer * gst_buffer_get_wl_buffer (GstBuffer * gstbuffer);
791 +
792 +void gst_wl_buffer_force_release_and_unref (GstWlBuffer * self);
793 +
794 +void gst_wl_buffer_attach (GstWlBuffer * self, struct wl_surface *surface);
795 +
796 +
797 +struct touch_point
798 +{
799 +  int32_t id;
800 +  struct wl_list link;
801 +};
802 +       
803 +struct input
804 +{
805 +  GstWlDisplay *display;
806 +  struct wl_seat *seat;
807 +  struct wl_pointer *pointer;
808 +  struct wl_touch *touch;
809 +  struct wl_list touch_point_list;
810 +  GstWlWindow *pointer_focus;
811 +  GstWlWindow *touch_focus;
812 +  struct wl_list link; 
813 +  GstWlWindow *grab;      
814 +};
815 +
816 +
817 +struct _GstWlWindow
818 +{
819 +  GObject parent_instance;
820 +
821 +  GstWlDisplay *display;
822 +  struct wl_surface *area_surface;
823 +  struct wl_subsurface *area_subsurface;
824 +  struct wl_viewport *area_viewport;
825 +  struct wl_surface *video_surface;
826 +  struct wl_subsurface *video_subsurface;
827 +  struct wl_viewport *video_viewport;
828 +  struct wl_shell_surface *shell_surface;
829 +
830 +  /* the size and position of the area_(sub)surface */
831 +  GstVideoRectangle render_rectangle;
832 +  /* the size of the video in the buffers */
833 +  gint video_width, video_height;
834 +  /* the size of the video_(sub)surface */
835 +  gint surface_width, surface_height;
836 +};
837 +
838 +struct _GstWlWindowClass
839 +{
840 +  GObjectClass parent_class;
841 +};
842 +
843 +GType gst_wl_window_get_type (void);
844 +
845 +GstWlWindow *gst_wl_window_new_toplevel (GstWlDisplay * display,
846 +        const GstVideoInfo * info);
847 +GstWlWindow *gst_wl_window_new_in_surface (GstWlDisplay * display,
848 +        struct wl_surface * parent);
849 +
850 +GstWlDisplay *gst_wl_window_get_display (GstWlWindow * window);
851 +struct wl_surface *gst_wl_window_get_wl_surface (GstWlWindow * window);
852 +gboolean gst_wl_window_is_toplevel (GstWlWindow *window);
853 +
854 +void gst_wl_window_render (GstWlWindow * window, GstWlBuffer * buffer,
855 +        const GstVideoInfo * info);
856 +void gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y,
857 +        gint w, gint h);
858 +
859 +
860 +struct _GstWlDisplay
861 +{
862 +  GObject parent_instance;
863 +
864 +  /* public objects */
865 +  struct wl_display *display;
866 +  struct wl_event_queue *queue;
867 +
868 +  /* globals */
869 +  struct wl_registry *registry;
870 +  struct wl_compositor *compositor;
871 +  struct wl_subcompositor *subcompositor;
872 +  struct wl_shell *shell;
873 +  struct wl_shm *shm;
874 +  struct wl_drm *drm;
875 +  struct wl_scaler *scaler;
876 +  GArray *shm_formats;
877 +
878 +  /* private */
879 +  gboolean own_display;
880 +  GThread *thread;
881 +  GstPoll *wl_fd_poll;
882 +
883 +  GMutex buffers_mutex;
884 +  GHashTable *buffers;
885 +  gboolean shutting_down;
886 +
887 +  /* the drm device.. needed for sharing direct-render buffers..
888 +   * TODO nothing about this should really be omapdrm specific.  But some
889 +   * of the code, like hashtable of imported buffers in libdrm_omap should
890 +   * be refactored out into some generic libdrm code..
891 +   */
892 +  struct omap_device *dev;
893 +  int fd;
894 +  int authenticated;
895 +  gboolean use_drm;
896 +
897 +  struct wl_list input_list;
898 +  int seat_version;
899 +  uint32_t serial;
900 +
901 +  GstVideoCropMeta *crop;
902 +};
903 +
904 +struct _GstWlDisplayClass
905 +{
906 +  GObjectClass parent_class;
907 +};
908 +
909 +GType gst_wl_display_get_type (void);
910 +
911 +GstWlDisplay *gst_wl_display_new (const gchar * name, GError ** error);
912 +GstWlDisplay *gst_wl_display_new_existing (struct wl_display * display,
913 +    gboolean take_ownership, GError ** error);
914 +
915 +/* see wlbuffer.c for explanation */
916 +void gst_wl_display_register_buffer (GstWlDisplay * self, gpointer buf);
917 +void gst_wl_display_unregister_buffer (GstWlDisplay * self, gpointer buf);
918 +
919 +G_END_DECLS
920 +
921 +#endif /* __GST_WL_DISPLAY_WL_WINDOW_H__ */
922 diff --git a/ext/wayland/wldisplay.c b/ext/wayland/wldisplay.c
923 index 3318095..2f58fd2 100644
924 --- a/ext/wayland/wldisplay.c
925 +++ b/ext/wayland/wldisplay.c
926 @@ -22,9 +22,15 @@
927  #include <config.h>
928  #endif
929  
930 -#include "wldisplay.h"
931 -#include "wlbuffer.h"
932 -
933 +#include "wldisplay-wlwindow-wlbuffer.h"
934 +
935 +#include <wayland-client-protocol.h>
936 +#include "wayland-drm-client-protocol.h"
937 +#include <linux/input.h>
938 +#include <omap_drm.h>
939 +#include <omap_drmif.h>
940 +#include <fcntl.h>
941 +#include <unistd.h>
942  #include <errno.h>
943  
944  GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
945 @@ -33,6 +39,8 @@ GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
946  G_DEFINE_TYPE (GstWlDisplay, gst_wl_display, G_TYPE_OBJECT);
947  
948  static void gst_wl_display_finalize (GObject * gobject);
949 +static void input_grab (struct input *input, GstWlWindow *window);
950 +static void input_ungrab (struct input *input);
951  
952  static void
953  gst_wl_display_class_init (GstWlDisplayClass * klass)
954 @@ -45,12 +53,62 @@ static void
955  gst_wl_display_init (GstWlDisplay * self)
956  {
957    self->shm_formats = g_array_new (FALSE, FALSE, sizeof (uint32_t));
958 +  self->fd = -1;
959 +  self->use_drm = FALSE;
960    self->wl_fd_poll = gst_poll_new (TRUE);
961    self->buffers = g_hash_table_new (g_direct_hash, g_direct_equal);
962    g_mutex_init (&self->buffers_mutex);
963  }
964  
965  static void
966 +input_grab (struct input *input, GstWlWindow *window)
967 +{
968 +  input->grab = window;
969 +}
970 +
971 +static void
972 +input_ungrab (struct input *input)
973 +{
974 +  input->grab = NULL;
975 +}
976 +
977 +static void
978 +input_remove_pointer_focus (struct input *input)
979 +{
980 +  GstWlWindow *window = input->pointer_focus;
981 +
982 +  if (!window)
983 +    return;
984 +
985 +  input->pointer_focus = NULL;
986 +}
987 +
988 +static void
989 +input_destroy (struct input *input)
990 +{
991 +  input_remove_pointer_focus (input);
992 +
993 +  if (input->display->seat_version >= 3) {
994 +    if (input->pointer)
995 +      wl_pointer_release (input->pointer);
996 +  }
997 +
998 +  wl_list_remove (&input->link);
999 +  wl_seat_destroy (input->seat);
1000 +  free (input);
1001 +}
1002 +
1003 +static void
1004 +display_destroy_inputs (GstWlDisplay *display)
1005 +{
1006 +  struct input *tmp;
1007 +  struct input *input;
1008 +
1009 +  wl_list_for_each_safe (input, tmp, &display->input_list, link)
1010 +      input_destroy (input);
1011 +}
1012 +
1013 +static void
1014  gst_wl_display_finalize (GObject * gobject)
1015  {
1016    GstWlDisplay *self = GST_WL_DISPLAY (gobject);
1017 @@ -71,13 +129,26 @@ gst_wl_display_finalize (GObject * gobject)
1018    g_hash_table_remove_all (self->buffers);
1019  
1020    g_array_unref (self->shm_formats);
1021 +
1022 +  if (self->dev) {
1023 +    omap_device_del (self->dev);
1024 +    self->dev = NULL;
1025 +  }
1026 +  if (self->fd !=-1)
1027 +    close (self->fd);
1028 +
1029    gst_poll_free (self->wl_fd_poll);
1030    g_hash_table_unref (self->buffers);
1031    g_mutex_clear (&self->buffers_mutex);
1032  
1033 +  display_destroy_inputs (self);
1034 +
1035    if (self->shm)
1036      wl_shm_destroy (self->shm);
1037  
1038 +  if (self->drm)
1039 +    wl_drm_destroy (self->drm);
1040 +
1041    if (self->shell)
1042      wl_shell_destroy (self->shell);
1043  
1044 @@ -138,12 +209,277 @@ shm_format (void *data, struct wl_shm *wl_shm, uint32_t format)
1045    GstWlDisplay *self = data;
1046  
1047    g_array_append_val (self->shm_formats, format);
1048 +  GST_DEBUG ("shm got format: %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (format));
1049  }
1050  
1051  static const struct wl_shm_listener shm_listener = {
1052    shm_format
1053  };
1054  
1055 +/* For wl_drm_listener */
1056 +
1057 +static void
1058 +drm_handle_device (void *data, struct wl_drm *drm, const char *device)
1059 +{
1060 +  GstWlDisplay *d = data;
1061 +  drm_magic_t magic;
1062 +  d->fd = open (device, O_RDWR | O_CLOEXEC);
1063 +  if (d->fd == -1) {
1064 +    GST_ERROR ("could not open %s: %m", device);
1065 +    return;
1066 +  }
1067 +  drmGetMagic (d->fd, &magic);
1068 +  wl_drm_authenticate (d->drm, magic);
1069 +}
1070 +
1071 +static void
1072 +drm_handle_format (void *data, struct wl_drm *drm, uint32_t format)
1073 +{
1074 +  GstWlDisplay *self = data;
1075 +  g_array_append_val (self->shm_formats, format);
1076 +  GST_DEBUG ("drm got format: %" GST_FOURCC_FORMAT, GST_FOURCC_ARGS (format));
1077 +}
1078 +
1079 +static void
1080 +drm_handle_authenticated (void *data, struct wl_drm *drm)
1081 +{
1082 +  GstWlDisplay *d = data;
1083 +  GST_DEBUG ("authenticated");
1084 +  d->dev = omap_device_new (d->fd);
1085 +  d->authenticated = 1;
1086 +  GST_DEBUG ("drm_handle_authenticated: dev: %p, d->authenticated: %d\n",
1087 +      d->dev, d->authenticated);
1088 +}
1089 +
1090 +static const struct wl_drm_listener drm_listener = {
1091 +  drm_handle_device,
1092 +  drm_handle_format,
1093 +  drm_handle_authenticated
1094 +};
1095 +
1096 +
1097 +static void
1098 +pointer_handle_enter (void *data, struct wl_pointer *pointer,
1099 +    uint32_t serial, struct wl_surface *surface,
1100 +    wl_fixed_t sx_w, wl_fixed_t sy_w)
1101 +{
1102 +  struct input *input = data;
1103 +
1104 +  if (!surface) {
1105 +    /* enter event for a window we've just destroyed */
1106 +    return;
1107 +  }
1108 +
1109 +  input->display->serial = serial;
1110 +  input->pointer_focus = wl_surface_get_user_data (surface);
1111 +}
1112 +
1113 +static void
1114 +pointer_handle_leave (void *data, struct wl_pointer *pointer,
1115 +    uint32_t serial, struct wl_surface *surface)
1116 +{
1117 +  struct input *input = data;
1118 +
1119 +  input_remove_pointer_focus (input);
1120 +}
1121 +
1122 +static void
1123 +pointer_handle_motion (void *data, struct wl_pointer *pointer,
1124 +    uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
1125 +{
1126 +  struct input *input = data;
1127 +  GstWlWindow *window = input->pointer_focus;
1128 +
1129 +  if (!window)
1130 +    return;
1131 +
1132 +  if (input->grab)
1133 +    wl_shell_surface_move (input->grab->shell_surface, input->seat,
1134 +        input->display->serial);
1135 +
1136 +}
1137 +
1138 +static void
1139 +pointer_handle_button (void *data, struct wl_pointer *pointer, uint32_t serial,
1140 +    uint32_t time, uint32_t button, uint32_t state_w)
1141 +{
1142 +  struct input *input = data;
1143 +  enum wl_pointer_button_state state = state_w;
1144 +  input->display->serial = serial;
1145 +
1146 +  if (button == BTN_LEFT) {
1147 +    if (state == WL_POINTER_BUTTON_STATE_PRESSED)
1148 +      input_grab (input, input->pointer_focus);
1149 +
1150 +    if (input->grab && state == WL_POINTER_BUTTON_STATE_RELEASED)
1151 +      input_ungrab (input);
1152 +  }
1153 +
1154 +  if (input->grab)
1155 +    wl_shell_surface_move (input->grab->shell_surface, input->seat,
1156 +        input->display->serial);
1157 +}
1158 +
1159 +static void
1160 +pointer_handle_axis (void *data, struct wl_pointer *pointer,
1161 +    uint32_t time, uint32_t axis, wl_fixed_t value)
1162 +{
1163 +}
1164 +
1165 +static const struct wl_pointer_listener pointer_listener = {
1166 +  pointer_handle_enter,
1167 +  pointer_handle_leave,
1168 +  pointer_handle_motion,
1169 +  pointer_handle_button,
1170 +  pointer_handle_axis,
1171 +};
1172 +
1173 +static void
1174 +touch_handle_down (void *data, struct wl_touch *wl_touch,
1175 +    uint32_t serial, uint32_t time, struct wl_surface *surface,
1176 +    int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
1177 +{
1178 +  struct input *input = data;
1179 +  struct touch_point *tp;
1180 +
1181 +  input->display->serial = serial;
1182 +  input->touch_focus = wl_surface_get_user_data (surface);
1183 +  if (!input->touch_focus) {
1184 +    return;
1185 +  }
1186 +
1187 +  tp = malloc (sizeof *tp);
1188 +  if (tp) {
1189 +    tp->id = id;
1190 +    wl_list_insert (&input->touch_point_list, &tp->link);
1191 +    wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
1192 +        serial);
1193 +  }
1194 +}
1195 +
1196 +static void
1197 +touch_handle_motion (void *data, struct wl_touch *wl_touch,
1198 +    uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
1199 +{
1200 +  struct input *input = data;
1201 +  struct touch_point *tp;
1202 +
1203 +
1204 +  if (!input->touch_focus) {
1205 +    return;
1206 +  }
1207 +  wl_list_for_each (tp, &input->touch_point_list, link) {
1208 +    if (tp->id != id)
1209 +      continue;
1210 +
1211 +    wl_shell_surface_move (input->touch_focus->shell_surface, input->seat,
1212 +        input->display->serial);
1213 +
1214 +    return;
1215 +  }
1216 +}
1217 +
1218 +static void
1219 +touch_handle_frame (void *data, struct wl_touch *wl_touch)
1220 +{
1221 +}
1222 +
1223 +static void
1224 +touch_handle_cancel (void *data, struct wl_touch *wl_touch)
1225 +{
1226 +}
1227 +
1228 +static void
1229 +touch_handle_up (void *data, struct wl_touch *wl_touch,
1230 +    uint32_t serial, uint32_t time, int32_t id)
1231 +{
1232 +  struct input *input = data;
1233 +  struct touch_point *tp, *tmp;
1234 +
1235 +  if (!input->touch_focus) {
1236 +    return;
1237 +  }
1238 +
1239 +  wl_list_for_each_safe (tp, tmp, &input->touch_point_list, link) {
1240 +    if (tp->id != id)
1241 +      continue;
1242 +
1243 +    wl_list_remove (&tp->link);
1244 +    free (tp);
1245 +
1246 +    return;
1247 +  }
1248 +}
1249 +
1250 +static const struct wl_touch_listener touch_listener = {
1251 +  touch_handle_down,
1252 +  touch_handle_up,
1253 +  touch_handle_motion,
1254 +  touch_handle_frame,
1255 +  touch_handle_cancel,
1256 +};
1257 +
1258 +
1259 +static void
1260 +seat_handle_capabilities (void *data, struct wl_seat *seat,
1261 +    enum wl_seat_capability caps)
1262 +{
1263 +  struct input *input = data;
1264 +
1265 +  if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
1266 +    input->pointer = wl_seat_get_pointer (seat);
1267 +    wl_pointer_set_user_data (input->pointer, input);
1268 +    wl_pointer_add_listener (input->pointer, &pointer_listener, input);
1269 +  } else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
1270 +    wl_pointer_destroy (input->pointer);
1271 +    input->pointer = NULL;
1272 +  }
1273 +
1274 +  if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
1275 +    input->touch = wl_seat_get_touch (seat);
1276 +    wl_touch_set_user_data (input->touch, input);
1277 +    wl_touch_add_listener (input->touch, &touch_listener, input);
1278 +  } else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
1279 +    wl_touch_destroy (input->touch);
1280 +    input->touch = NULL;
1281 +  }
1282 +}
1283 +
1284 +static void
1285 +seat_handle_name (void *data, struct wl_seat *seat, const char *name)
1286 +{
1287
1288 +}
1289 +
1290 +static const struct wl_seat_listener seat_listener = {
1291 +  seat_handle_capabilities,
1292 +  seat_handle_name
1293 +};
1294 +
1295 +static void
1296 +display_add_input (GstWlDisplay *d, uint32_t id)
1297 +{
1298 +  struct input *input;
1299 +
1300 +  input = calloc (1, sizeof (*input));
1301 +  if (input == NULL) {
1302 +    fprintf (stderr, "%s: out of memory\n", "gst-wayland-sink");
1303 +    exit (EXIT_FAILURE);
1304 +  }
1305 +  input->display = d;
1306 +  input->seat = wl_registry_bind (d->registry, id, &wl_seat_interface,
1307 +      MAX (d->seat_version, 3));
1308 +  input->touch_focus = NULL;
1309 +  input->pointer_focus = NULL;
1310 +  wl_list_init (&input->touch_point_list);
1311 +  wl_list_insert (d->input_list.prev, &input->link);
1312 +
1313 +  wl_seat_add_listener (input->seat, &seat_listener, input);
1314 +  wl_seat_set_user_data (input->seat, input);
1315 +
1316 +}
1317 +
1318 +
1319  static void
1320  registry_handle_global (void *data, struct wl_registry *registry,
1321      uint32_t id, const char *interface, uint32_t version)
1322 @@ -161,6 +497,12 @@ registry_handle_global (void *data, struct wl_registry *registry,
1323    } else if (g_strcmp0 (interface, "wl_shm") == 0) {
1324      self->shm = wl_registry_bind (registry, id, &wl_shm_interface, 1);
1325      wl_shm_add_listener (self->shm, &shm_listener, self);
1326 +  } else if (g_strcmp0 (interface, "wl_drm") == 0) {
1327 +    self->drm = wl_registry_bind (registry, id, &wl_drm_interface, 1);
1328 +    wl_drm_add_listener (self->drm, &drm_listener, self);
1329 +  } else if (g_strcmp0 (interface, "wl_seat") == 0) {
1330 +    self->seat_version = version;
1331 +    display_add_input (self, id);
1332    } else if (g_strcmp0 (interface, "wl_scaler") == 0) {
1333      self->scaler = wl_registry_bind (registry, id, &wl_scaler_interface, 2);
1334    }
1335 @@ -238,6 +580,7 @@ gst_wl_display_new_existing (struct wl_display * display,
1336    self->own_display = take_ownership;
1337  
1338    self->queue = wl_display_create_queue (self->display);
1339 +  wl_list_init (&self->input_list);
1340    self->registry = wl_display_get_registry (self->display);
1341    wl_proxy_set_queue ((struct wl_proxy *) self->registry, self->queue);
1342    wl_registry_add_listener (self->registry, &registry_listener, self);
1343 @@ -266,6 +609,7 @@ gst_wl_display_new_existing (struct wl_display * display,
1344    VERIFY_INTERFACE_EXISTS (subcompositor, "wl_subcompositor");
1345    VERIFY_INTERFACE_EXISTS (shell, "wl_shell");
1346    VERIFY_INTERFACE_EXISTS (shm, "wl_shm");
1347 +  VERIFY_INTERFACE_EXISTS (drm, "wl_drm");
1348    VERIFY_INTERFACE_EXISTS (scaler, "wl_scaler");
1349  
1350  #undef VERIFY_INTERFACE_EXISTS
1351 diff --git a/ext/wayland/wldisplay.h b/ext/wayland/wldisplay.h
1352 deleted file mode 100644
1353 index e9df749..0000000
1354 --- a/ext/wayland/wldisplay.h
1355 +++ /dev/null
1356 @@ -1,84 +0,0 @@
1357 -/* GStreamer Wayland video sink
1358 - *
1359 - * Copyright (C) 2014 Collabora Ltd.
1360 - *
1361 - * This library is free software; you can redistribute it and/or
1362 - * modify it under the terms of the GNU Library General Public
1363 - * License as published by the Free Software Foundation; either
1364 - * version 2 of the License, or (at your option) any later version.
1365 - *
1366 - * This library is distributed in the hope that it will be useful,
1367 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1368 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1369 - * Library General Public License for more details.
1370 - *
1371 - * You should have received a copy of the GNU Library General Public
1372 - * License along with this library; if not, write to the Free
1373 - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1374 - * Boston, MA 02110-1301 USA.
1375 - */
1376 -
1377 -#ifndef __GST_WL_DISPLAY_H__
1378 -#define __GST_WL_DISPLAY_H__
1379 -
1380 -#include <gst/gst.h>
1381 -#include <wayland-client.h>
1382 -#include "scaler-client-protocol.h"
1383 -
1384 -G_BEGIN_DECLS
1385 -
1386 -#define GST_TYPE_WL_DISPLAY                  (gst_wl_display_get_type ())
1387 -#define GST_WL_DISPLAY(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplay))
1388 -#define GST_IS_WL_DISPLAY(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_DISPLAY))
1389 -#define GST_WL_DISPLAY_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
1390 -#define GST_IS_WL_DISPLAY_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_DISPLAY))
1391 -#define GST_WL_DISPLAY_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_DISPLAY, GstWlDisplayClass))
1392 -
1393 -typedef struct _GstWlDisplay GstWlDisplay;
1394 -typedef struct _GstWlDisplayClass GstWlDisplayClass;
1395 -
1396 -struct _GstWlDisplay
1397 -{
1398 -  GObject parent_instance;
1399 -
1400 -  /* public objects */
1401 -  struct wl_display *display;
1402 -  struct wl_event_queue *queue;
1403 -
1404 -  /* globals */
1405 -  struct wl_registry *registry;
1406 -  struct wl_compositor *compositor;
1407 -  struct wl_subcompositor *subcompositor;
1408 -  struct wl_shell *shell;
1409 -  struct wl_shm *shm;
1410 -  struct wl_scaler *scaler;
1411 -  GArray *shm_formats;
1412 -
1413 -  /* private */
1414 -  gboolean own_display;
1415 -  GThread *thread;
1416 -  GstPoll *wl_fd_poll;
1417 -
1418 -  GMutex buffers_mutex;
1419 -  GHashTable *buffers;
1420 -  gboolean shutting_down;
1421 -};
1422 -
1423 -struct _GstWlDisplayClass
1424 -{
1425 -  GObjectClass parent_class;
1426 -};
1427 -
1428 -GType gst_wl_display_get_type (void);
1429 -
1430 -GstWlDisplay *gst_wl_display_new (const gchar * name, GError ** error);
1431 -GstWlDisplay *gst_wl_display_new_existing (struct wl_display * display,
1432 -    gboolean take_ownership, GError ** error);
1433 -
1434 -/* see wlbuffer.c for explanation */
1435 -void gst_wl_display_register_buffer (GstWlDisplay * self, gpointer buf);
1436 -void gst_wl_display_unregister_buffer (GstWlDisplay * self, gpointer buf);
1437 -
1438 -G_END_DECLS
1439 -
1440 -#endif /* __GST_WL_DISPLAY_H__ */
1441 diff --git a/ext/wayland/wldrm.c b/ext/wayland/wldrm.c
1442 new file mode 100644
1443 index 0000000..3dc9c21
1444 --- /dev/null
1445 +++ b/ext/wayland/wldrm.c
1446 @@ -0,0 +1,69 @@
1447 +#include "wldisplay-wlwindow-wlbuffer.h"
1448 +#include <gst/drm/gstdrmallocator.h>
1449 +#include "wayland-drm-client-protocol.h"
1450 +#include <omap_drm.h>
1451 +#include <omap_drmif.h>
1452 +#include <wayland-client.h>
1453 +
1454 +struct wl_buffer *
1455 +gst_wl_drm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
1456 +    const GstVideoInfo * info)
1457 +{
1458 +  gint video_width = GST_VIDEO_INFO_WIDTH (info);
1459 +  gint video_height = GST_VIDEO_INFO_HEIGHT (info);
1460 +  int fd = -1;
1461 +  struct omap_bo *bo;
1462 +  struct wl_buffer *buffer;
1463 +
1464 +  /* TODO get format, etc from caps.. and query device for
1465 +   * supported formats, and make this all more flexible to
1466 +   * cope with various formats:
1467 +   */
1468 +  uint32_t fourcc = GST_MAKE_FOURCC ('N', 'V', '1', '2');
1469 +  uint32_t name;
1470 +  /* note: wayland and mesa use the terminology:
1471 +   *    stride - rowstride in bytes
1472 +   *    pitch  - rowstride in pixels
1473 +   */
1474 +  uint32_t strides[3] = {
1475 +    GST_ROUND_UP_4 (video_width), GST_ROUND_UP_4 (video_width), 0,
1476 +  };
1477 +  uint32_t offsets[3] = {
1478 +    0, strides[0] * video_height, 0
1479 +  };
1480 +
1481 +  fd = gst_fd_memory_get_fd (mem);
1482 +
1483 +  if (fd < 0 ) {
1484 +    GST_DEBUG ("Invalid fd");
1485 +    return NULL;
1486 +  }
1487 +
1488 +  bo = omap_bo_from_dmabuf (display->dev, fd);
1489 +
1490 +  struct drm_gem_flink req = {
1491 +                  .handle = omap_bo_handle(bo),
1492 +  };
1493 +
1494 +  int ret;
1495 +  ret = drmIoctl(display->fd, DRM_IOCTL_GEM_FLINK, &req);
1496 +  if (ret) {
1497 +    GST_DEBUG ("could not get name, DRM_IOCTL_GEM_FLINK returned %d", ret);
1498 +    return NULL;
1499 +  }
1500 +
1501 +  name = req.name;
1502 +
1503 + GST_LOG ("width = %d , height = %d , fourcc = %d ",  video_width, video_height, fourcc );
1504 + buffer = wl_drm_create_planar_buffer (display->drm, name,
1505 +      video_width, video_height, fourcc,
1506 +      offsets[0], strides[0],
1507 +      offsets[1], strides[1],
1508 +      offsets[2], strides[2]);
1509 +
1510 +  GST_DEBUG ("create planar buffer: %p (name=%d)",
1511 +      buffer, name);
1512 +
1513 +  return buffer;
1514 +}
1515 +
1516 diff --git a/ext/wayland/wldrm.h b/ext/wayland/wldrm.h
1517 new file mode 100644
1518 index 0000000..9751029
1519 --- /dev/null
1520 +++ b/ext/wayland/wldrm.h
1521 @@ -0,0 +1,3 @@
1522 +struct wl_buffer *
1523 +gst_wl_drm_memory_construct_wl_buffer (GstMemory * mem, GstWlDisplay * display,
1524 +    const GstVideoInfo * info);
1525 diff --git a/ext/wayland/wlshmallocator.h b/ext/wayland/wlshmallocator.h
1526 index 07ae17f..2860fc3 100644
1527 --- a/ext/wayland/wlshmallocator.h
1528 +++ b/ext/wayland/wlshmallocator.h
1529 @@ -26,7 +26,7 @@
1530  #include <gst/video/video.h>
1531  #include <gst/allocators/allocators.h>
1532  #include <wayland-client-protocol.h>
1533 -#include "wldisplay.h"
1534 +#include "wldisplay-wlwindow-wlbuffer.h"
1535  
1536  G_BEGIN_DECLS
1537  
1538 diff --git a/ext/wayland/wlvideoformat.c b/ext/wayland/wlvideoformat.c
1539 index 1302da6..aa336aa 100644
1540 --- a/ext/wayland/wlvideoformat.c
1541 +++ b/ext/wayland/wlvideoformat.c
1542 @@ -106,6 +106,10 @@ gst_wl_shm_format_to_video_format (enum wl_shm_format wl_format)
1543  const gchar *
1544  gst_wl_shm_format_to_string (enum wl_shm_format wl_format)
1545  {
1546 -  return gst_video_format_to_string
1547 -      (gst_wl_shm_format_to_video_format (wl_format));
1548 +  GstVideoFormat fmt = gst_wl_shm_format_to_video_format (wl_format);
1549 +  if (fmt != GST_VIDEO_FORMAT_UNKNOWN) {
1550 +    return gst_video_format_to_string (fmt);
1551 +  } else {
1552 +    return NULL;
1553 +  }
1554  }
1555 diff --git a/ext/wayland/wlwindow.c b/ext/wayland/wlwindow.c
1556 index 79000ae..f7e3324 100644
1557 --- a/ext/wayland/wlwindow.c
1558 +++ b/ext/wayland/wlwindow.c
1559 @@ -24,9 +24,10 @@
1560  #include <config.h>
1561  #endif
1562  
1563 -#include "wlwindow.h"
1564 +#include "wldisplay-wlwindow-wlbuffer.h"
1565  #include "wlshmallocator.h"
1566 -#include "wlbuffer.h"
1567 +#include "wldrm.h"
1568 +#include <gst/drm/gstdrmallocator.h>
1569  
1570  GST_DEBUG_CATEGORY_EXTERN (gstwayland_debug);
1571  #define GST_CAT_DEFAULT gstwayland_debug
1572 @@ -111,6 +112,8 @@ gst_wl_window_new_internal (GstWlDisplay * display)
1573  
1574    window->area_surface = wl_compositor_create_surface (display->compositor);
1575    window->video_surface = wl_compositor_create_surface (display->compositor);
1576 +  wl_surface_set_user_data (window->area_surface, window);
1577 +  wl_surface_set_user_data (window->video_surface, window);
1578  
1579    wl_proxy_set_queue ((struct wl_proxy *) window->area_surface, display->queue);
1580    wl_proxy_set_queue ((struct wl_proxy *) window->video_surface,
1581 @@ -126,6 +129,21 @@ gst_wl_window_new_internal (GstWlDisplay * display)
1582        window->area_surface);
1583    window->video_viewport = wl_scaler_get_viewport (display->scaler,
1584        window->video_surface);
1585 +  if (display->crop) {
1586 +    GST_DEBUG ("Setting source crop : %d %d %d %d",display->crop->x, display->crop->y,
1587 +                    display->crop->width, display->crop->height);
1588 +    wl_viewport_set_source (window->area_viewport,
1589 +                                        wl_fixed_from_int(display->crop->x),
1590 +                                        wl_fixed_from_int(display->crop->y),
1591 +                                        wl_fixed_from_int(display->crop->width),
1592 +                                        wl_fixed_from_int(display->crop->height));
1593 +    wl_viewport_set_source (window->video_viewport,
1594 +                                        wl_fixed_from_int(display->crop->x),
1595 +                                        wl_fixed_from_int(display->crop->y),
1596 +                                        wl_fixed_from_int(display->crop->width),
1597 +                                        wl_fixed_from_int(display->crop->height));
1598 +
1599 +  }
1600  
1601    /* draw the area_subsurface */
1602    gst_video_info_set_format (&info,
1603 @@ -136,14 +154,25 @@ gst_wl_window_new_internal (GstWlDisplay * display)
1604        GST_VIDEO_FORMAT_BGRx,
1605  #endif
1606        1, 1);
1607 -
1608 -  buf = gst_buffer_new_allocate (gst_wl_shm_allocator_get (), info.size, NULL);
1609 +  if (display->use_drm) {
1610 +    buf = gst_buffer_new_allocate (gst_drm_allocator_get (), info.size, NULL);
1611 +  } else {
1612 +    buf = gst_buffer_new_allocate (gst_wl_shm_allocator_get (), info.size, NULL);
1613 +  } 
1614    gst_buffer_map (buf, &mapinfo, GST_MAP_WRITE);
1615 -  *((guint32 *) mapinfo.data) = 0;      /* paint it black */
1616 -  gst_buffer_unmap (buf, &mapinfo);
1617 -  wlbuf =
1618 -      gst_wl_shm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
1619 -      display, &info);
1620 +   *((guint32 *) mapinfo.data) = 0;      /* paint it black */
1621 +   gst_buffer_unmap (buf, &mapinfo);
1622 +   
1623 +  if (display->use_drm) {
1624 +     wlbuf =
1625 +       gst_wl_drm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
1626 +       display, &info);
1627 +   } else {
1628 +     wlbuf =
1629 +       gst_wl_shm_memory_construct_wl_buffer (gst_buffer_peek_memory (buf, 0),
1630 +       display, &info);
1631 +   }
1632 +
1633    gwlbuf = gst_buffer_add_wl_buffer (buf, wlbuf, display);
1634    gst_wl_buffer_attach (gwlbuf, window->area_surface);
1635  
1636 diff --git a/ext/wayland/wlwindow.h b/ext/wayland/wlwindow.h
1637 deleted file mode 100644
1638 index e22cb26..0000000
1639 --- a/ext/wayland/wlwindow.h
1640 +++ /dev/null
1641 @@ -1,84 +0,0 @@
1642 -/* GStreamer Wayland video sink
1643 - *
1644 - * Copyright (C) 2014 Collabora Ltd.
1645 - *
1646 - * This library is free software; you can redistribute it and/or
1647 - * modify it under the terms of the GNU Library General Public
1648 - * License as published by the Free Software Foundation; either
1649 - * version 2 of the License, or (at your option) any later version.
1650 - *
1651 - * This library is distributed in the hope that it will be useful,
1652 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1653 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1654 - * Library General Public License for more details.
1655 - *
1656 - * You should have received a copy of the GNU Library General Public
1657 - * License along with this library; if not, write to the Free
1658 - * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
1659 - * Boston, MA 02110-1301 USA.
1660 - */
1661 -
1662 -#ifndef __GST_WL_WINDOW_H__
1663 -#define __GST_WL_WINDOW_H__
1664 -
1665 -#include "wldisplay.h"
1666 -#include "wlbuffer.h"
1667 -#include <gst/video/video.h>
1668 -
1669 -G_BEGIN_DECLS
1670 -
1671 -#define GST_TYPE_WL_WINDOW                  (gst_wl_window_get_type ())
1672 -#define GST_WL_WINDOW(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_WL_WINDOW, GstWlWindow))
1673 -#define GST_IS_WL_WINDOW(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_WL_WINDOW))
1674 -#define GST_WL_WINDOW_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_WL_WINDOW, GstWlWindowClass))
1675 -#define GST_IS_WL_WINDOW_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_WL_WINDOW))
1676 -#define GST_WL_WINDOW_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_WL_WINDOW, GstWlWindowClass))
1677 -
1678 -typedef struct _GstWlWindow GstWlWindow;
1679 -typedef struct _GstWlWindowClass GstWlWindowClass;
1680 -
1681 -struct _GstWlWindow
1682 -{
1683 -  GObject parent_instance;
1684 -
1685 -  GstWlDisplay *display;
1686 -  struct wl_surface *area_surface;
1687 -  struct wl_subsurface *area_subsurface;
1688 -  struct wl_viewport *area_viewport;
1689 -  struct wl_surface *video_surface;
1690 -  struct wl_subsurface *video_subsurface;
1691 -  struct wl_viewport *video_viewport;
1692 -  struct wl_shell_surface *shell_surface;
1693 -
1694 -  /* the size and position of the area_(sub)surface */
1695 -  GstVideoRectangle render_rectangle;
1696 -  /* the size of the video in the buffers */
1697 -  gint video_width, video_height;
1698 -  /* the size of the video_(sub)surface */
1699 -  gint surface_width, surface_height;
1700 -};
1701 -
1702 -struct _GstWlWindowClass
1703 -{
1704 -  GObjectClass parent_class;
1705 -};
1706 -
1707 -GType gst_wl_window_get_type (void);
1708 -
1709 -GstWlWindow *gst_wl_window_new_toplevel (GstWlDisplay * display,
1710 -        const GstVideoInfo * info);
1711 -GstWlWindow *gst_wl_window_new_in_surface (GstWlDisplay * display,
1712 -        struct wl_surface * parent);
1713 -
1714 -GstWlDisplay *gst_wl_window_get_display (GstWlWindow * window);
1715 -struct wl_surface *gst_wl_window_get_wl_surface (GstWlWindow * window);
1716 -gboolean gst_wl_window_is_toplevel (GstWlWindow *window);
1717 -
1718 -void gst_wl_window_render (GstWlWindow * window, GstWlBuffer * buffer,
1719 -        const GstVideoInfo * info);
1720 -void gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y,
1721 -        gint w, gint h);
1722 -
1723 -G_END_DECLS
1724 -
1725 -#endif /* __GST_WL_WINDOW_H__ */
1726 -- 
1727 2.7.4
1728