pixman-renderer: share region_global_to_output()

Converting a region from global coordinates to output pixel coordinates
will become useful in GL-renderer soon, so move this function to be
shared. It is tricky to reinvent.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
diff --git a/libweston/compositor.c b/libweston/compositor.c
index 89fa7c4..22a3a89 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -5844,6 +5844,36 @@
 	}
 }
 
+/** Transform a region in-place from global to output coordinates
+ *
+ * \param output The output that defines the transformation.
+ * \param region The region to be transformed in-place.
+ *
+ * This takes a region in the global coordinate system, and takes into account
+ * output position, transform and scale, and the zoom, and converts the region
+ * into output pixel coordinates in the framebuffer.
+ *
+ * Uses floating-point operations if zoom is active, which may round to expand
+ * the region.
+ *
+ * \internal
+ * \ingroup output
+ */
+WL_EXPORT void
+weston_output_region_from_global(struct weston_output *output,
+				 pixman_region32_t *region)
+{
+	if (output->zoom.active) {
+		weston_matrix_transform_region(region, &output->matrix, region);
+	} else {
+		pixman_region32_translate(region, -output->x, -output->y);
+		weston_transformed_region(output->width, output->height,
+					  output->transform,
+					  output->current_scale,
+					  region, region);
+	}
+}
+
 static void
 weston_output_update_matrix(struct weston_output *output)
 {