protocol: unify wl_viewport src and dst size rules
Let's make the source and destination size rules consistent: neither can
have zero, {-1, -1} disables it, and other negatives are not allowed.
The sanity of allowing zero sized source rectangle as debatable. Now the
minimum becomes 1/256x1/256, and with output_scale the actual samples
may be even smaller. That should be enough.
On not allowed values, raise a protocol error. This should help catch
bugs in clients that accidentally send garbage values.
The old wl_viewport.set request remains the same, and can still produce
zero sized source rectangle.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
diff --git a/src/compositor.c b/src/compositor.c
index ea27be4..a076291 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3452,16 +3452,27 @@
assert(surface->viewport_resource != NULL);
- if (wl_fixed_to_double(src_width) < 0 ||
- wl_fixed_to_double(src_height) < 0) {
+ if (src_width == wl_fixed_from_int(-1) &&
+ src_height == wl_fixed_from_int(-1)) {
+ /* unset source size */
surface->pending.buffer_viewport.buffer.src_width =
wl_fixed_from_int(-1);
- } else {
- 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;
+ return;
}
+
+ if (src_width <= 0 || src_height <= 0) {
+ wl_resource_post_error(resource,
+ WL_VIEWPORT_ERROR_BAD_VALUE,
+ "source size must be positive (%fx%f)",
+ wl_fixed_to_double(src_width),
+ wl_fixed_to_double(src_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;
}
static void
@@ -3475,12 +3486,22 @@
assert(surface->viewport_resource != NULL);
- if (dst_width <= 0 || dst_height <= 0) {
+ if (dst_width == -1 && dst_height == -1) {
+ /* unset destination size */
surface->pending.buffer_viewport.surface.width = -1;
- } else {
- surface->pending.buffer_viewport.surface.width = dst_width;
- surface->pending.buffer_viewport.surface.height = dst_height;
+ return;
}
+
+ if (dst_width <= 0 || dst_height <= 0) {
+ wl_resource_post_error(resource,
+ WL_VIEWPORT_ERROR_BAD_VALUE,
+ "destination size must be positive (%dx%d)",
+ dst_width, dst_height);
+ return;
+ }
+
+ surface->pending.buffer_viewport.surface.width = dst_width;
+ surface->pending.buffer_viewport.surface.height = dst_height;
}
static const struct wl_viewport_interface viewport_interface = {