From cea0f063855fc7e64b418facd66d1a2204fdca2e Mon Sep 17 00:00:00 2001
From: Kevin Mihelich <kevin@archlinuxarm.org>
Date: Thu, 27 Feb 2014 14:30:13 +0000
Subject: [PATCH] community/weston to 1.4.0-2.1, fixes #631

---
 community/weston/PKGBUILD  | 12 ++++--
 community/weston/rpi.patch | 75 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+), 4 deletions(-)
 create mode 100644 community/weston/rpi.patch

diff --git a/community/weston/PKGBUILD b/community/weston/PKGBUILD
index 33c066fec..ab27acd38 100644
--- a/community/weston/PKGBUILD
+++ b/community/weston/PKGBUILD
@@ -4,18 +4,21 @@
 
 # ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
 #  - export flags for rpi
+#  - patch to not call vc_dispmanx_set_wl_buffer_in_use
 
 pkgname=weston
 pkgver=1.4.0
-pkgrel=2
+pkgrel=2.1
 pkgdesc='Reference implementation of a Wayland compositor'
 arch=('i686' 'x86_64')
 url='http://wayland.freedesktop.org'
 license=('MIT')
 depends=('libxkbcommon' 'libunwind' 'poppler-glib' 'mtdev' 'libxcursor' 'glu' 'pango' 'colord')
 [ "$CARCH" == 'armv6h' ] && makedepends=('raspberrypi-firmware')
-source=("http://wayland.freedesktop.org/releases/$pkgname-$pkgver.tar.xz")
-sha1sums=('49b0b6d5e2366a7bad5158b29998213e5ca7f254')
+source=("http://wayland.freedesktop.org/releases/$pkgname-$pkgver.tar.xz"
+        'rpi.patch')
+sha1sums=('49b0b6d5e2366a7bad5158b29998213e5ca7f254'
+          'ed01b8367eef82a6d168b00dfd61193f2e6aabb5')
 
 build() {
 	cd $pkgname-$pkgver
@@ -23,11 +26,12 @@ build() {
 		export RPI_BCM_HOST_LIBS="-L/opt/vc/lib"
 		export RPI_BCM_HOST_CFLAGS="-I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads -I/opt/vc/include/interface/vmcs_host/linux"
 		export WESTON_NATIVE_BACKEND="rpi-backend.so"
+		CONFIG='--disable-egl'
 	fi
 	./configure \
 		--prefix=/usr \
 		--libexecdir=/usr/lib/weston \
-		--enable-demo-clients-install
+		--enable-demo-clients-install $CONFIG
 	make
 }
 
diff --git a/community/weston/rpi.patch b/community/weston/rpi.patch
new file mode 100644
index 000000000..045b39b15
--- /dev/null
+++ b/community/weston/rpi.patch
@@ -0,0 +1,75 @@
+From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
+
+The symbol is needed only for the EGL buffer path. If --disable-egl is
+given to ./configure, there is no need for it, so fix it to actually not
+look for that symbol needlessly.
+
+This should fix the runtime error:
+
+	Failed to load module: .../rpi-backend.so: undefined symbol:
+	vc_dispmanx_set_wl_buffer_in_use
+
+when you use --disable-egl and do not have a recent enough
+libraspberrypi package (/opt/vc, a.k.a userland.git) that would provide
+vc_dispmanx_set_wl_buffer_in_use. Apparently no released version of
+userland yet provides this.
+
+The calls are organized into two helper functions to avoid a boolean
+argument, and put the #ifdefs away from the main parts of the code.
+
+Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
+Cc: Tomeu Vizoso <tomeu at tomeuvizoso.net>
+---
+
+Tomeu, would this be ok with you?
+---
+ src/rpi-renderer.c | 20 ++++++++++++++++++--
+ 1 file changed, 18 insertions(+), 2 deletions(-)
+
+diff --git a/src/rpi-renderer.c b/src/rpi-renderer.c
+index 1940db7..2b6d12c 100644
+--- a/src/rpi-renderer.c
++++ b/src/rpi-renderer.c
+@@ -385,6 +385,22 @@ rpi_resource_update(struct rpi_resource *resource, struct weston_buffer *buffer,
+ 	return ret ? -1 : 0;
+ }
+ 
++static inline void
++rpi_buffer_egl_lock(struct weston_buffer *buffer)
++{
++#ifdef ENABLE_EGL
++	vc_dispmanx_set_wl_buffer_in_use(buffer->resource, 1);
++#endif
++}
++
++static inline void
++rpi_buffer_egl_unlock(struct weston_buffer *buffer)
++{
++#ifdef ENABLE_EGL
++	vc_dispmanx_set_wl_buffer_in_use(buffer->resource, 0);
++#endif
++}
++
+ static void
+ rpir_egl_buffer_destroy(struct rpir_egl_buffer *egl_buffer)
+ {
+@@ -400,7 +416,7 @@ rpir_egl_buffer_destroy(struct rpir_egl_buffer *egl_buffer)
+ 		 */
+ 		vc_dispmanx_resource_delete(egl_buffer->resource_handle);
+ 	} else {
+-		vc_dispmanx_set_wl_buffer_in_use(buffer->resource, 0);
++		rpi_buffer_egl_unlock(buffer);
+ 		weston_buffer_reference(&egl_buffer->buffer_ref, NULL);
+ 	}
+ 
+@@ -1294,7 +1310,7 @@ rpi_renderer_repaint_output(struct weston_output *base,
+ 			struct weston_buffer *buffer;
+ 			buffer = view->surface->egl_front->buffer_ref.buffer;
+ 			if (buffer != NULL) {
+-				vc_dispmanx_set_wl_buffer_in_use(buffer->resource, 1);
++				rpi_buffer_egl_lock(buffer);
+ 			} else {
+ 				weston_log("warning: client destroyed current front buffer\n");
+ 
+-- 
+1.8.1.5