summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2010-12-23 21:48:55 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-08-09 13:52:27 +0200
commitd2320b7226c2832c0b085168bdd9ccda38e22f4b (patch)
tree8184f28b305209919f67a9ebad6495d1c48ec5fb
parent82c3f7411bb67c94756d60a86cef8428614c3702 (diff)
egl/eglut: Add wayland backendegl-wayland
Also build eglut based demos against eglut_wayland.
-rw-r--r--configure.ac6
-rw-r--r--src/egl/eglut/Makefile.am14
-rw-r--r--src/egl/eglut/eglut_wayland.c241
-rw-r--r--src/egl/eglut/eglutint.h2
-rw-r--r--src/egl/opengl/Makefile.am15
-rw-r--r--src/egl/opengles1/Makefile.am17
-rw-r--r--src/egl/opengles2/Makefile.am6
-rw-r--r--src/egl/openvg/Makefile.am15
8 files changed, 313 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index e17fbcfd..91814f96 100644
--- a/configure.ac
+++ b/configure.ac
@@ -159,6 +159,9 @@ PKG_CHECK_MODULES(X11, [x11 xext], [x11_enabled=yes], [enable_x11=no])
PKG_CHECK_MODULES(FREETYPE2, [freetype2],
[freetype2_enabled=yes], [freetype2_enabled=no])
+PKG_CHECK_MODULES(WAYLAND, [wayland-client wayland-egl],
+ [wayland_enabled=yes], wayland_enabled=no])
+
mesa_source_enabled=no
AC_ARG_WITH([mesa-source],
[AS_HELP_STRING([--with-mesa-source=DIR],
@@ -211,6 +214,8 @@ AC_SUBST([GLUT_CFLAGS])
AC_SUBST([GLUT_LIBS])
AC_SUBST([X11_CFLAGS])
AC_SUBST([X11_LIBS])
+AC_SUBST([WAYLAND_CFLAGS])
+AC_SUBST([WAYLAND_LIBS])
AC_SUBST([OSMESA_CFLAGS])
AC_SUBST([OSMESA_LIBS])
AC_SUBST([OSMESA16_LIBS])
@@ -228,6 +233,7 @@ AM_CONDITIONAL(HAVE_OSMESA, test "x$osmesa_enabled" = "xyes")
AM_CONDITIONAL(HAVE_DRM, test "x$drm_enabled" = "xyes")
AM_CONDITIONAL(BUILD_GLTRACE, false)
AM_CONDITIONAL(HAVE_MESA_SOURCE, test "x$mesa_source_enabled" = "xyes")
+AM_CONDITIONAL(HAVE_WAYLAND, test "x$wayland_enabled" = "xyes")
AC_OUTPUT([
Makefile
diff --git a/src/egl/eglut/Makefile.am b/src/egl/eglut/Makefile.am
index f0ab2832..213f8925 100644
--- a/src/egl/eglut/Makefile.am
+++ b/src/egl/eglut/Makefile.am
@@ -29,8 +29,20 @@ if HAVE_EGL
if HAVE_X11
eglut_x11 = libeglut_x11.la
endif
-noinst_LTLIBRARIES = libeglut_screen.la $(eglut_x11)
+if HAVE_WAYLAND
+eglut_wayland = libeglut_wayland.la
endif
+noinst_LTLIBRARIES = libeglut_screen.la $(eglut_x11) $(eglut_wayland)
+endif
+
+libeglut_wayland_la_SOURCES= \
+ eglut.c \
+ eglut.h \
+ eglutint.h \
+ eglut_wayland.c
+
+libeglut_wayland_la_CFLAGS = $(WAYLAND_CFLAGS) $(EGL_CFLAGS)
+libeglut_wayland_la_LIBADD = $(WAYLAND_LIBS) $(EGL_LIBS)
libeglut_screen_la_SOURCES = \
eglut.c \
diff --git a/src/egl/eglut/eglut_wayland.c b/src/egl/eglut/eglut_wayland.c
new file mode 100644
index 00000000..3de86e2e
--- /dev/null
+++ b/src/egl/eglut/eglut_wayland.c
@@ -0,0 +1,241 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/select.h>
+
+#include <wayland-client.h>
+#include <wayland-egl.h>
+
+#include "eglutint.h"
+
+struct display {
+ struct wl_display *display;
+ struct wl_compositor *compositor;
+ struct wl_shell *shell;
+
+ struct wl_visual *rgb_visual;
+
+ int event_fd;
+ unsigned event_mask;
+};
+
+struct window {
+ struct eglut_window *eglut_window;
+ struct wl_surface *surface;
+ struct wl_egl_window *egl_window;
+};
+
+static void
+handle_configure(void *data, struct wl_shell *shell,
+ uint32_t time, uint32_t edges,
+ struct wl_surface *surface,
+ int32_t width, int32_t height)
+{
+ struct window *window = wl_surface_get_user_data(surface);
+ struct eglut_window *win = window->eglut_window;
+ int a_width, a_height;
+ int dx = 0, dy = 0;
+
+ wl_egl_window_get_attached_size(window->egl_window, &a_width, &a_height);
+
+ if (width <= 0)
+ width = a_width;
+ if (height <= 0)
+ height = a_height;
+
+ if (width == a_width && height == a_height)
+ return;
+
+ if (edges & WL_SHELL_RESIZE_LEFT)
+ dx = a_width - width;
+
+ if (edges & WL_SHELL_RESIZE_TOP)
+ dy = a_height - height;
+
+ win->native.width = width;
+ win->native.height = height;
+
+ wl_egl_window_resize(window->egl_window,
+ win->native.width, win->native.height, dx, dy);
+ if (win->reshape_cb)
+ win->reshape_cb(win->native.width, win->native.height);
+
+}
+
+static const struct wl_shell_listener wayland_shell_listener = {
+ handle_configure,
+};
+
+static void
+compositor_handle_visual(void *data,
+ struct wl_compositor *compositor,
+ uint32_t id, uint32_t token)
+{
+ struct display *d = data;
+
+ switch (token) {
+ case WL_COMPOSITOR_VISUAL_XRGB32:
+ d->rgb_visual = wl_visual_create(d->display, id, 1);
+ break;
+ }
+}
+
+static const struct wl_compositor_listener compositor_listener = {
+ compositor_handle_visual,
+};
+
+static void
+display_handle_global(struct wl_display *display, uint32_t id,
+ const char *interface, uint32_t version, void *data)
+{
+ struct display *d = data;
+
+ if (strcmp(interface, "wl_compositor") == 0) {
+ d->compositor = wl_compositor_create(display, id, 1);
+ wl_compositor_add_listener(d->compositor, &compositor_listener, d);
+ } else if (strcmp(interface, "wl_shell") == 0) {
+ d->shell = wl_shell_create(display, id, 1);
+ wl_shell_add_listener(d->shell, &wayland_shell_listener, d);
+ }
+}
+
+static int
+event_mask_update(uint32_t mask, void *data)
+{
+ struct display *d = data;
+
+ d->event_mask = mask;
+
+ return 0;
+}
+
+void
+_eglutNativeInitDisplay(void)
+{
+ struct display *d;
+
+ d = calloc(1, sizeof *d);
+ if (!d)
+ _eglutFatal("failed to alloc display data");
+
+ d->display = wl_display_connect(NULL);
+ if (!d->display)
+ _eglutFatal("failed to initialize native display");
+
+ wl_display_set_user_data(d->display, d);
+
+ wl_display_add_global_listener(d->display, display_handle_global, d);
+ wl_display_iterate(d->display, WL_DISPLAY_READABLE);
+
+ d->event_fd = wl_display_get_fd(d->display, event_mask_update, d);
+
+ _eglut->native_dpy = d->display;
+ _eglut->surface_type = EGL_WINDOW_BIT;
+}
+
+void
+_eglutNativeFiniDisplay(void)
+{
+ struct wl_display *display = _eglut->native_dpy;
+ struct display *d = wl_display_get_user_data(display);
+
+ wl_display_destroy(display);
+ free(d);
+ _eglut->native_dpy = NULL;
+}
+
+static void
+sync_callback(void *data)
+{
+ int *done = data;
+
+ *done = 1;
+}
+
+void
+_eglutNativeInitWindow(struct eglut_window *win, const char *title,
+ int x, int y, int w, int h)
+{
+ struct wl_display *display = _eglut->native_dpy;
+ struct display *d = wl_display_get_user_data(display);
+ struct window *window;
+ int done = 0;
+
+ if (!d->rgb_visual) {
+ wl_display_sync_callback(display, sync_callback, &done);
+ while (!done)
+ wl_display_iterate(display, d->event_mask);
+ if (!d->rgb_visual)
+ _eglutFatal("eglut_wayland: xrgb visual missing: %m");
+ }
+
+ window = malloc(sizeof *window);
+ if (!window)
+ return;
+
+ window->eglut_window = win;
+ window->surface = wl_compositor_create_surface(d->compositor);
+ wl_surface_set_user_data(window->surface, window);
+ window->egl_window =
+ wl_egl_window_create(window->surface, w, h, d->rgb_visual);
+
+ wl_shell_set_toplevel(d->shell, window->surface);
+
+ _eglut->redisplay = 1;
+
+ win->platform_private = window;
+ win->native.u.window = window->egl_window;
+ win->native.width = w;
+ win->native.height = h;
+}
+
+void
+_eglutNativeFiniWindow(struct eglut_window *win)
+{
+ struct window *window = win->platform_private;
+
+ wl_egl_window_destroy(window->egl_window);
+ wl_surface_destroy(window->surface);
+ free(window);
+}
+
+static void
+redisplay(struct eglut_window *win)
+{
+ if (!_eglut->redisplay)
+ return;
+
+ if (win->display_cb)
+ win->display_cb();
+
+ eglSwapBuffers(_eglut->dpy, win->surface);
+}
+
+void
+_eglutNativeEventLoop(void)
+{
+ struct display *d = wl_display_get_user_data(_eglut->native_dpy);
+ struct timeval tv = { 0, 0 };
+ fd_set rfds;
+ int retval;
+
+ while (1) {
+ if (d->event_mask & WL_DISPLAY_WRITABLE)
+ wl_display_iterate(d->display, WL_DISPLAY_WRITABLE);
+
+ FD_ZERO(&rfds);
+ FD_SET(d->event_fd, &rfds);
+
+ retval = select(d->event_fd + 1, &rfds, NULL, NULL, &tv);
+ if (retval < 0)
+ _eglutFatal("select failed: %m");
+
+ if (retval == 1)
+ wl_display_iterate(d->display, WL_DISPLAY_READABLE);
+ else if (_eglut->idle_cb)
+ _eglut->idle_cb();
+
+ redisplay(_eglut->current);
+ }
+}
diff --git a/src/egl/eglut/eglutint.h b/src/egl/eglut/eglutint.h
index a4520b0e..3edb2bdd 100644
--- a/src/egl/eglut/eglutint.h
+++ b/src/egl/eglut/eglutint.h
@@ -45,6 +45,8 @@ struct eglut_window {
EGLSurface surface;
+ void *platform_private;
+
int index;
EGLUTreshapeCB reshape_cb;
diff --git a/src/egl/opengl/Makefile.am b/src/egl/opengl/Makefile.am
index 2c9956fa..48a727a9 100644
--- a/src/egl/opengl/Makefile.am
+++ b/src/egl/opengl/Makefile.am
@@ -47,6 +47,12 @@ EGL_DRM_DEMOS = \
eglkms
endif
+if HAVE_WAYLAND
+EGL_WAYLAND_DEMOS = \
+ eglgears_wayland \
+ egltri_wayland
+endif
+
if HAVE_EGL
noinst_PROGRAMS = \
demo1 \
@@ -57,7 +63,8 @@ noinst_PROGRAMS = \
egltri_screen \
peglgears \
$(EGL_DRM_DEMOS) \
- $(EGL_X11_DEMOS)
+ $(EGL_X11_DEMOS) \
+ $(EGL_WAYLAND_DEMOS)
endif
egltri_screen_SOURCES = egltri.c
@@ -66,6 +73,9 @@ eglgears_screen_SOURCES = eglgears.c
egltri_x11_SOURCES = egltri.c
eglgears_x11_SOURCES = eglgears.c
+egltri_wayland_SOURCES = egltri.c
+eglgears_wayland_SOURCES = eglgears.c
+
eglgears_x11_LDFLAGS = $(AM_LDFLAGS) $(X11_LIBS)
egltri_x11_LDFLAGS = $(AM_LDFLAGS) $(X11_LIBS)
xeglgears_LDFLAGS = $(AM_LDFLAGS) $(X11_LIBS)
@@ -77,6 +87,9 @@ egltri_screen_LDADD = ../eglut/libeglut_screen.la
eglgears_x11_LDADD = ../eglut/libeglut_x11.la
egltri_x11_LDADD = ../eglut/libeglut_x11.la
+eglgears_wayland_LDADD = ../eglut/libeglut_wayland.la
+egltri_wayland_LDADD = ../eglut/libeglut_wayland.la
+
eglkms_SOURCES = eglkms.c
eglkms_CFLAGS = $(AM_CFLAGS) $(DRM_CFLAGS)
eglkms_LDADD = $(AM_LDFLAGS) $(DRM_LIBS)
diff --git a/src/egl/opengles1/Makefile.am b/src/egl/opengles1/Makefile.am
index 7a9828d3..b38368d6 100644
--- a/src/egl/opengles1/Makefile.am
+++ b/src/egl/opengles1/Makefile.am
@@ -56,6 +56,13 @@ noinst_PROGRAMS = \
tri_screen \
tri_x11 \
two_win
+if HAVE_WAYLAND
+noinst_PROGRAMS += \
+ drawtex_wayland \
+ gears_wayland \
+ torus_wayland \
+ tri_wayland
+endif
endif
endif
@@ -90,3 +97,13 @@ drawtex_x11_LDADD = ../eglut/libeglut_x11.la
gears_x11_LDADD = ../eglut/libeglut_x11.la
torus_x11_LDADD = ../eglut/libeglut_x11.la
tri_x11_LDADD = ../eglut/libeglut_x11.la
+
+drawtex_wayland_SOURCES = drawtex.c
+gears_wayland_SOURCES = gears.c
+torus_wayland_SOURCES = torus.c
+tri_wayland_SOURCES = tri.c
+
+drawtex_wayland_LDADD = ../eglut/libeglut_wayland.la
+gears_wayland_LDADD = ../eglut/libeglut_wayland.la
+torus_wayland_LDADD = ../eglut/libeglut_wayland.la
+tri_wayland_LDADD = ../eglut/libeglut_wayland.la
diff --git a/src/egl/opengles2/Makefile.am b/src/egl/opengles2/Makefile.am
index 8d85c06f..1821d126 100644
--- a/src/egl/opengles2/Makefile.am
+++ b/src/egl/opengles2/Makefile.am
@@ -39,6 +39,9 @@ bin_PROGRAMS = \
es2_info \
es2gears \
es2tri
+if HAVE_WAYLAND
+bin_PROGRAMS += es2gears_wayland
+endif
endif
endif
@@ -46,3 +49,6 @@ es2_info_LDADD = $(X11_LIBS)
es2tri_LDADD = $(X11_LIBS)
es2gears_LDADD = ../eglut/libeglut_x11.la
+
+es2gears_wayland_SOURCES = es2gears.c
+es2gears_wayland_LDADD = ../eglut/libeglut_wayland.la
diff --git a/src/egl/openvg/Makefile.am b/src/egl/openvg/Makefile.am
index 7318a436..337150b2 100644
--- a/src/egl/openvg/Makefile.am
+++ b/src/egl/openvg/Makefile.am
@@ -47,12 +47,19 @@ EGL_X11_DEMOS += \
endif
endif
+if HAVE_WAYLAND
+EGL_WAYLAND_DEMOS = \
+ lion_wayland \
+ sp_wayland
+endif
+
if HAVE_EGL
if HAVE_VG
noinst_PROGRAMS = \
lion_screen \
sp_screen \
- $(EGL_X11_DEMOS)
+ $(EGL_X11_DEMOS) \
+ $(EGL_WAYLAND_DEMOS)
endif
endif
@@ -62,12 +69,18 @@ sp_screen_SOURCES = sp.c
lion_x11_SOURCES = lion.c lion-render.c lion-render.h
sp_x11_SOURCES = sp.c
+lion_wayland_SOURCES = lion.c lion-render.c lion-render.h
+sp_wayland_SOURCES = sp.c
+
lion_screen_LDADD = ../eglut/libeglut_screen.la
sp_screen_LDADD = ../eglut/libeglut_screen.la
lion_x11_LDADD = ../eglut/libeglut_x11.la
sp_x11_LDADD = ../eglut/libeglut_x11.la
+lion_wayland_LDADD = ../eglut/libeglut_wayland.la
+sp_wayland_LDADD = ../eglut/libeglut_wayland.la
+
text_SOURCES = text.c
text_CFLAGS = $(AM_CFLAGS) @FREETYPE2_CFLAGS@
text_LDADD = @FREETYPE2_LIBS@ ../eglut/libeglut_x11.la