[vlc-devel] [PATCH 4/6] wl_egl_window: Wayland EGL window provider

Rémi Denis-Courmont remi at remlab.net
Wed Aug 27 23:31:30 CEST 2014


---
 configure.ac                         |  11 +++
 modules/video_output/Modules.am      |   7 ++
 modules/video_output/wl/egl_window.c | 128 +++++++++++++++++++++++++++++++++++
 3 files changed, 146 insertions(+)
 create mode 100644 modules/video_output/wl/egl_window.c

diff --git a/configure.ac b/configure.ac
index 35a81b7..c1de6f9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3224,8 +3224,19 @@ AS_IF([test "${enable_wayland}" != "no"], [
       AC_MSG_ERROR([${WAYLAND_CLIENT_PKG_ERRORS}.])
     ])
   ])
+
+  AS_IF([test "${have_egl}" = "yes"], [
+    PKG_CHECK_MODULES([WAYLAND_EGL], [wayland-egl], [
+      have_wayland_egl="yes"
+    ], [
+      AS_IF([test -n "${enable_wayland}"], [
+        AC_MSG_ERROR([${WAYLAND_EGL_PKG_ERRORS}.])
+      ])
+    ])
+  ])
 ])
 AM_CONDITIONAL([HAVE_WAYLAND], [test "${have_wayland}" = "yes"])
+AM_CONDITIONAL([HAVE_WAYLAND_EGL], [test "${have_wayland_egl}" = "yes"])
 
 
 dnl
diff --git a/modules/video_output/Modules.am b/modules/video_output/Modules.am
index 91ca304..65cfb60 100644
--- a/modules/video_output/Modules.am
+++ b/modules/video_output/Modules.am
@@ -136,6 +136,13 @@ if HAVE_WAYLAND
 vout_LTLIBRARIES += libwl_shell_surface_plugin.la
 endif
 
+libwl_egl_window_plugin_la_SOURCES = wl/egl_window.c
+libwl_egl_window_plugin_la_CFLAGS = $(WAYLAND_EGL_CFLAGS)
+libwl_egl_window_plugin_la_LIBADD = $(WAYLAND_EGL_LIBS)
+if HAVE_WAYLAND_EGL
+vout_LTLIBRARIES += libwl_egl_window_plugin.la
+endif
+
 
 ### Win32 ###
 libdirect2d_plugin_la_SOURCES = msw/direct2d.c \
diff --git a/modules/video_output/wl/egl_window.c b/modules/video_output/wl/egl_window.c
new file mode 100644
index 0000000..0060696
--- /dev/null
+++ b/modules/video_output/wl/egl_window.c
@@ -0,0 +1,128 @@
+/**
+ * @file egl_window.c
+ * @brief Wayland EGL window provider module for VLC media player
+ */
+/*****************************************************************************
+ * Copyright © 2014 Rémi Denis-Courmont
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <assert.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <wayland-egl.h>
+
+#include <vlc_common.h>
+#include <vlc_plugin.h>
+#include <vlc_vout_window.h>
+
+struct vout_window_sys_t
+{
+    vout_window_t *surface;
+    struct wl_egl_window *window;
+};
+
+static int Control(vout_window_t *wnd, int cmd, va_list ap)
+{
+    vout_window_sys_t *sys = wnd->sys;
+    struct wl_display *display = wnd->display.wl;
+
+    switch (cmd)
+    {
+        case VOUT_WINDOW_SET_SIZE:
+        {
+            unsigned width = va_arg(ap, unsigned);
+            unsigned height = va_arg(ap, unsigned);
+
+            wl_egl_window_resize(sys->window, width, height, 0, 0);
+            break;
+        }
+        default:
+            return vout_window_Control(sys->surface, cmd, ap);
+    }
+
+    wl_display_flush(display);
+    return VLC_SUCCESS;
+}
+
+/**
+ * Creates a Wayland EGL window.
+ */
+static int Open(vout_window_t *wnd, const vout_window_cfg_t *cfg)
+{
+    vout_window_sys_t *sys = malloc(sizeof (*sys));
+    if (unlikely(sys == NULL))
+        return VLC_ENOMEM;
+
+    vout_window_cfg_t surface_cfg = *cfg;
+
+    surface_cfg.type = VOUT_WINDOW_TYPE_WAYLAND;
+
+    sys->surface = vout_window_New(VLC_OBJECT(wnd), NULL, &surface_cfg);
+    if (sys->surface == NULL)
+        goto error;
+
+    struct wl_surface *surface = sys->surface->handle.wl;
+    struct wl_display *display = sys->surface->display.wl;
+    struct wl_egl_window *window;
+
+    window = wl_egl_window_create(surface, cfg->width, cfg->height);
+    if (window == NULL)
+    {
+        vout_window_Delete(sys->surface);
+        goto error;
+    }
+    sys->window = window;
+
+    wl_display_flush(display);
+
+    wnd->handle.wl = window;
+    wnd->display.wl = display;
+    wnd->sys = sys;
+    wnd->control = Control;
+    return VLC_SUCCESS;
+
+error:
+    free(sys);
+    return VLC_EGENERIC;
+}
+
+/**
+ * Destroys a Wayland EGL window.
+ */
+static void Close(vout_window_t *wnd)
+{
+    vout_window_sys_t *sys = wnd->sys;
+
+    wl_egl_window_destroy(sys->window);
+    vout_window_Delete(sys->surface);
+    free(sys);
+}
+
+vlc_module_begin ()
+    set_shortname (N_("WL EGL"))
+    set_description (N_("Wayland EGL window"))
+    set_category (CAT_VIDEO)
+    set_subcategory (SUBCAT_VIDEO_VOUT)
+    set_capability ("vout window wl egl", 10)
+    set_callbacks (Open, Close)
+vlc_module_end ()
-- 
2.1.0




More information about the vlc-devel mailing list