[RFCv3 weston 05/15] compositor: replace weston_buffer_viewport::viewport_set

Pekka Paalanen ppaalanen at gmail.com
Fri Mar 7 04:03:53 PST 2014


From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>

Remove the explicit boolean variable, and use illegal width to denote
"not set".

Split the boolean into two, so we can later start having buffer.src_*
and surface.* set or not set independently. This may become useful when
the wl_viewport interface is changed to allow modifying them separately.

At the moment, both buffer.src_width and surface.width conditions are
always in sync.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 src/compositor.c      | 15 +++++++++------
 src/compositor.h      | 12 +++++++-----
 src/pixman-renderer.c |  3 ++-
 3 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index f204a6d..16b9b57 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -402,7 +402,8 @@ weston_surface_create(struct weston_compositor *compositor)
 
 	surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL;
 	surface->buffer_viewport.buffer.scale = 1;
-	surface->buffer_viewport.buffer.viewport_set = 0;
+	surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1);
+	surface->buffer_viewport.surface.width = -1;
 	surface->pending.buffer_viewport = surface->buffer_viewport;
 	surface->output = NULL;
 	surface->pending.newly_attached = 0;
@@ -641,7 +642,8 @@ scaler_surface_to_buffer(struct weston_surface *surface,
 {
 	struct weston_buffer_viewport *vp = &surface->buffer_viewport;
 
-	if (vp->buffer.viewport_set) {
+	if (vp->buffer.src_width != wl_fixed_from_int(-1) &&
+	    vp->surface.width != -1) {
 		double a, b;
 
 		a = sx / vp->surface.width;
@@ -1204,7 +1206,8 @@ weston_surface_set_size_from_buffer(struct weston_surface *surface)
 		return;
 	}
 
-	if (vp->buffer.viewport_set) {
+	if (vp->buffer.src_width != wl_fixed_from_int(-1) &&
+	    vp->surface.width != -1) {
 		surface->width = vp->surface.width;
 		surface->height = vp->surface.height;
 		return;
@@ -3355,7 +3358,9 @@ destroy_viewport(struct wl_resource *resource)
 		wl_resource_get_user_data(resource);
 
 	surface->viewport_resource = NULL;
-	surface->pending.buffer_viewport.buffer.viewport_set = 0;
+	surface->pending.buffer_viewport.buffer.src_width =
+		wl_fixed_from_int(-1);
+	surface->pending.buffer_viewport.surface.width = -1;
 }
 
 static void
@@ -3398,8 +3403,6 @@ viewport_set(struct wl_client *client,
 		return;
 	}
 
-	surface->pending.buffer_viewport.buffer.viewport_set = 1;
-
 	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;
diff --git a/src/compositor.h b/src/compositor.h
index f1f126b..d2afacd 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -662,16 +662,18 @@ struct weston_buffer_viewport {
 		/* wl_surface.set_scaling_factor */
 		int32_t scale;
 
-		/* bool for whether wl_viewport.set has been
-		 * called yet (before this is called there is no
-		 * cropping or scaling on the surface) */
-		int viewport_set; /* bool */
-
+		/*
+		 * If src_width != wl_fixed_from_int(-1),
+		 * then and only then src_* are used.
+		 */
 		wl_fixed_t src_x, src_y;
 		wl_fixed_t src_width, src_height;
 	} buffer;
 
 	struct {
+		/*
+		 * If width == -1, the size is inferred from the buffer.
+		 */
 		int32_t width, height;
 	} surface;
 };
diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c
index 4849155..ee28e45 100644
--- a/src/pixman-renderer.c
+++ b/src/pixman-renderer.c
@@ -258,7 +258,8 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 					   pixman_double_to_fixed ((double)-ev->geometry.y));
 	}
 
-	if (vp->buffer.viewport_set) {
+	if (vp->buffer.src_width != wl_fixed_from_int(-1) &&
+	    vp->surface.width != -1) {
 		double viewport_x, viewport_y, viewport_width, viewport_height;
 		double ratio_x, ratio_y;
 
-- 
1.8.3.2



More information about the wayland-devel mailing list