compositor: migrate to stable viewporter.xml

Migrate from wl_scaler to wp_viewporter extension. The viewporter.xml
file is provided by wayland-protocols.

This stops Weston from advertising wl_scaler, and advertises
wp_viewporter instead.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
[Pekka: fix wayland-protocols requirement]
diff --git a/Makefile.am b/Makefile.am
index d1d2178..67c8f4b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -130,8 +130,8 @@
 	protocol/input-method-unstable-v1-server-protocol.h		\
 	protocol/presentation-time-protocol.c		\
 	protocol/presentation-time-server-protocol.h	\
-	protocol/scaler-protocol.c			\
-	protocol/scaler-server-protocol.h		\
+	protocol/viewporter-protocol.c			\
+	protocol/viewporter-server-protocol.h		\
 	protocol/linux-dmabuf-unstable-v1-protocol.c	\
 	protocol/linux-dmabuf-unstable-v1-server-protocol.h
 
diff --git a/configure.ac b/configure.ac
index 2be2277..241c722 100644
--- a/configure.ac
+++ b/configure.ac
@@ -186,7 +186,7 @@
 PKG_CHECK_MODULES(LIBINPUT_BACKEND, [libinput >= 0.8.0])
 PKG_CHECK_MODULES(COMPOSITOR, [$COMPOSITOR_MODULES])
 
-PKG_CHECK_MODULES(WAYLAND_PROTOCOLS, [wayland-protocols >= 1.2],
+PKG_CHECK_MODULES(WAYLAND_PROTOCOLS, [wayland-protocols >= 1.4],
 		  [ac_wayland_protocols_pkgdatadir=`$PKG_CONFIG --variable=pkgdatadir wayland-protocols`])
 AC_SUBST(WAYLAND_PROTOCOLS_DATADIR, $ac_wayland_protocols_pkgdatadir)
 
diff --git a/src/compositor.c b/src/compositor.c
index c6feae2..4e560be 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -54,7 +54,7 @@
 #include "timeline.h"
 
 #include "compositor.h"
-#include "scaler-server-protocol.h"
+#include "viewporter-server-protocol.h"
 #include "presentation-time-server-protocol.h"
 #include "shared/helpers.h"
 #include "shared/os-compatibility.h"
@@ -791,7 +791,7 @@
 
 /** Transform a rectangle from surface coordinates to buffer coordinates
  *
- * \param surface The surface to fetch wl_viewport and buffer transformation
+ * \param surface The surface to fetch wp_viewport and buffer transformation
  * from.
  * \param rect The rectangle to transform.
  * \return The transformed rectangle.
@@ -831,7 +831,7 @@
 
 /** Transform a region from surface coordinates to buffer coordinates
  *
- * \param surface The surface to fetch wl_viewport and buffer transformation
+ * \param surface The surface to fetch wp_viewport and buffer transformation
  * from.
  * \param surface_region[in] The region in surface coordinates.
  * \param buffer_region[out] The region converted to buffer coordinates.
@@ -2709,7 +2709,8 @@
 
 	/* wl_surface.set_buffer_transform */
 	/* wl_surface.set_buffer_scale */
-	/* wl_viewport.set */
+	/* wp_viewport.set_source */
+	/* wp_viewport.set_destination */
 	surface->buffer_viewport = state->buffer_viewport;
 
 	/* wl_surface.attach */
@@ -4233,48 +4234,6 @@
 }
 
 static void
-viewport_set(struct wl_client *client,
-	     struct wl_resource *resource,
-	     wl_fixed_t src_x,
-	     wl_fixed_t src_y,
-	     wl_fixed_t src_width,
-	     wl_fixed_t src_height,
-	     int32_t dst_width,
-	     int32_t dst_height)
-{
-	struct weston_surface *surface =
-		wl_resource_get_user_data(resource);
-
-	assert(surface->viewport_resource != NULL);
-
-	if (wl_fixed_to_double(src_width) < 0 ||
-	    wl_fixed_to_double(src_height) < 0) {
-		wl_resource_post_error(resource,
-			WL_VIEWPORT_ERROR_BAD_VALUE,
-			"source dimensions must be non-negative (%fx%f)",
-			wl_fixed_to_double(src_width),
-			wl_fixed_to_double(src_height));
-		return;
-	}
-
-	if (dst_width <= 0 || dst_height <= 0) {
-		wl_resource_post_error(resource,
-			WL_VIEWPORT_ERROR_BAD_VALUE,
-			"destination dimensions must be positive (%dx%d)",
-			dst_width, dst_height);
-		return;
-	}
-
-	surface->pending.buffer_viewport.buffer.src_x = src_x;
-	surface->pending.buffer_viewport.buffer.src_y = src_y;
-	surface->pending.buffer_viewport.buffer.src_width = src_width;
-	surface->pending.buffer_viewport.buffer.src_height = src_height;
-	surface->pending.buffer_viewport.surface.width = dst_width;
-	surface->pending.buffer_viewport.surface.height = dst_height;
-	surface->pending.buffer_viewport.changed = 1;
-}
-
-static void
 viewport_set_source(struct wl_client *client,
 		    struct wl_resource *resource,
 		    wl_fixed_t src_x,
@@ -4298,7 +4257,7 @@
 
 	if (src_width <= 0 || src_height <= 0) {
 		wl_resource_post_error(resource,
-			WL_VIEWPORT_ERROR_BAD_VALUE,
+			WP_VIEWPORT_ERROR_BAD_VALUE,
 			"source size must be positive (%fx%f)",
 			wl_fixed_to_double(src_width),
 			wl_fixed_to_double(src_height));
@@ -4332,7 +4291,7 @@
 
 	if (dst_width <= 0 || dst_height <= 0) {
 		wl_resource_post_error(resource,
-			WL_VIEWPORT_ERROR_BAD_VALUE,
+			WP_VIEWPORT_ERROR_BAD_VALUE,
 			"destination size must be positive (%dx%d)",
 			dst_width, dst_height);
 		return;
@@ -4343,9 +4302,8 @@
 	surface->pending.buffer_viewport.changed = 1;
 }
 
-static const struct wl_viewport_interface viewport_interface = {
+static const struct wp_viewport_interface viewport_interface = {
 	viewport_destroy,
-	viewport_set,
 	viewport_set_source,
 	viewport_set_destination
 };
@@ -4370,12 +4328,12 @@
 
 	if (surface->viewport_resource) {
 		wl_resource_post_error(scaler,
-			WL_SCALER_ERROR_VIEWPORT_EXISTS,
+			WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS,
 			"a viewport for that surface already exists");
 		return;
 	}
 
-	resource = wl_resource_create(client, &wl_viewport_interface,
+	resource = wl_resource_create(client, &wp_viewport_interface,
 				      version, id);
 	if (resource == NULL) {
 		wl_client_post_no_memory(client);
@@ -4388,7 +4346,7 @@
 	surface->viewport_resource = resource;
 }
 
-static const struct wl_scaler_interface scaler_interface = {
+static const struct wp_viewporter_interface scaler_interface = {
 	scaler_destroy,
 	scaler_get_viewport
 };
@@ -4399,7 +4357,7 @@
 {
 	struct wl_resource *resource;
 
-	resource = wl_resource_create(client, &wl_scaler_interface,
+	resource = wl_resource_create(client, &wp_viewporter_interface,
 				      version, id);
 	if (resource == NULL) {
 		wl_client_post_no_memory(client);
@@ -4589,7 +4547,7 @@
 			      ec, bind_subcompositor))
 		goto fail;
 
-	if (!wl_global_create(ec->wl_display, &wl_scaler_interface, 2,
+	if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1,
 			      ec, bind_scaler))
 		goto fail;
 
diff --git a/src/compositor.h b/src/compositor.h
index f2a0e4c..9e5155c 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -993,7 +993,8 @@
 
 	/* wl_surface.set_buffer_transform */
 	/* wl_surface.set_scaling_factor */
-	/* wl_viewport.set */
+	/* wp_viewport.set_source */
+	/* wp_viewport.set_destination */
 	struct weston_buffer_viewport buffer_viewport;
 };
 
@@ -1042,7 +1043,7 @@
 	int32_t height_from_buffer;
 	bool keep_buffer; /* for backends to prevent early release */
 
-	/* wl_viewport resource for this surface */
+	/* wp_viewport resource for this surface */
 	struct wl_resource *viewport_resource;
 
 	/* All the pending state, that wl_surface.commit will apply. */