[RFCv3 weston 04/15] compositor: reorganize struct weston_buffer_viewport

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


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

Queueing in the Presentation extension requires splitting the viewport
state into buffer state and surface state. To conveniently allow
assigning only one, the other, or both, reorganize the
weston_buffer_viewport structure.

Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 desktop-shell/shell.c |  6 ++---
 src/compositor-drm.c  | 12 +++++----
 src/compositor.c      | 70 ++++++++++++++++++++++++++-------------------------
 src/compositor.h      | 27 ++++++++++++--------
 src/gl-renderer.c     |  2 +-
 src/pixman-renderer.c | 25 +++++++++---------
 6 files changed, 76 insertions(+), 66 deletions(-)

diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index fd9ead0..7f28f07 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -2659,11 +2659,11 @@ shell_configure_fullscreen(struct shell_surface *shsurf)
 	case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
 		if (shell_surface_is_top_fullscreen(shsurf)) {
 			struct weston_mode mode = {0,
-				surf_width * surface->buffer_viewport.scale,
-				surf_height * surface->buffer_viewport.scale,
+				surf_width * surface->buffer_viewport.buffer.scale,
+				surf_height * surface->buffer_viewport.buffer.scale,
 				shsurf->fullscreen.framerate};
 
-			if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale,
+			if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.buffer.scale,
 					WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) {
 				weston_view_set_position(shsurf->view,
 							 output->x - surf_x,
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index e45f47d..71c4812 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -456,6 +456,7 @@ drm_output_prepare_scanout_view(struct weston_output *_output,
 	struct drm_compositor *c =
 		(struct drm_compositor *) output->base.compositor;
 	struct weston_buffer *buffer = ev->surface->buffer_ref.buffer;
+	struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
 	struct gbm_bo *bo;
 	uint32_t format;
 
@@ -464,7 +465,7 @@ drm_output_prepare_scanout_view(struct weston_output *_output,
 	    buffer == NULL || c->gbm == NULL ||
 	    buffer->width != output->base.current_mode->width ||
 	    buffer->height != output->base.current_mode->height ||
-	    output->base.transform != ev->surface->buffer_viewport.transform ||
+	    output->base.transform != viewport->buffer.transform ||
 	    ev->transform.enabled)
 		return NULL;
 
@@ -809,6 +810,7 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 {
 	struct weston_compositor *ec = output_base->compositor;
 	struct drm_compositor *c =(struct drm_compositor *) ec;
+	struct weston_buffer_viewport *viewport = &ev->surface->buffer_viewport;
 	struct drm_sprite *s;
 	int found = 0;
 	struct gbm_bo *bo;
@@ -820,10 +822,10 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 	if (c->gbm == NULL)
 		return NULL;
 
-	if (ev->surface->buffer_viewport.transform != output_base->transform)
+	if (viewport->buffer.transform != output_base->transform)
 		return NULL;
 
-	if (ev->surface->buffer_viewport.scale != output_base->current_scale)
+	if (viewport->buffer.scale != output_base->current_scale)
 		return NULL;
 
 	if (c->sprites_are_broken)
@@ -933,8 +935,8 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 
 	tbox = weston_transformed_rect(wl_fixed_from_int(ev->surface->width),
 				       wl_fixed_from_int(ev->surface->height),
-				       ev->surface->buffer_viewport.transform,
-				       ev->surface->buffer_viewport.scale,
+				       viewport->buffer.transform,
+				       viewport->buffer.scale,
 				       tbox);
 
 	s->src_x = tbox.x1 << 8;
diff --git a/src/compositor.c b/src/compositor.c
index e1d6df1..f204a6d 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -400,9 +400,9 @@ weston_surface_create(struct weston_compositor *compositor)
 	surface->compositor = compositor;
 	surface->ref_count = 1;
 
-	surface->buffer_viewport.transform = WL_OUTPUT_TRANSFORM_NORMAL;
-	surface->buffer_viewport.scale = 1;
-	surface->buffer_viewport.viewport_set = 0;
+	surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL;
+	surface->buffer_viewport.buffer.scale = 1;
+	surface->buffer_viewport.buffer.viewport_set = 0;
 	surface->pending.buffer_viewport = surface->buffer_viewport;
 	surface->output = NULL;
 	surface->pending.newly_attached = 0;
@@ -639,16 +639,18 @@ static void
 scaler_surface_to_buffer(struct weston_surface *surface,
 			 float sx, float sy, float *bx, float *by)
 {
-	if (surface->buffer_viewport.viewport_set) {
+	struct weston_buffer_viewport *vp = &surface->buffer_viewport;
+
+	if (vp->buffer.viewport_set) {
 		double a, b;
 
-		a = sx / surface->buffer_viewport.dst_width;
-		b = a * wl_fixed_to_double(surface->buffer_viewport.src_width);
-		*bx = b + wl_fixed_to_double(surface->buffer_viewport.src_x);
+		a = sx / vp->surface.width;
+		b = a * wl_fixed_to_double(vp->buffer.src_width);
+		*bx = b + wl_fixed_to_double(vp->buffer.src_x);
 
-		a = sy / surface->buffer_viewport.dst_height;
-		b = a * wl_fixed_to_double(surface->buffer_viewport.src_height);
-		*by = b + wl_fixed_to_double(surface->buffer_viewport.src_y);
+		a = sy / vp->surface.height;
+		b = a * wl_fixed_to_double(vp->buffer.src_height);
+		*by = b + wl_fixed_to_double(vp->buffer.src_y);
 	} else {
 		*bx = sx;
 		*by = sy;
@@ -659,13 +661,13 @@ WL_EXPORT void
 weston_surface_to_buffer_float(struct weston_surface *surface,
 			       float sx, float sy, float *bx, float *by)
 {
+	struct weston_buffer_viewport *vp = &surface->buffer_viewport;
+
 	/* first transform coordinates if the scaler is set */
 	scaler_surface_to_buffer(surface, sx, sy, bx, by);
 
-	weston_transformed_coord(surface->width,
-				 surface->height,
-				 surface->buffer_viewport.transform,
-				 surface->buffer_viewport.scale,
+	weston_transformed_coord(surface->width, surface->height,
+				 vp->buffer.transform, vp->buffer.scale,
 				 *bx, *by, bx, by);
 }
 
@@ -686,6 +688,7 @@ WL_EXPORT pixman_box32_t
 weston_surface_to_buffer_rect(struct weston_surface *surface,
 			      pixman_box32_t rect)
 {
+	struct weston_buffer_viewport *vp = &surface->buffer_viewport;
 	float xf, yf;
 
 	/* first transform box coordinates if the scaler is set */
@@ -697,10 +700,8 @@ weston_surface_to_buffer_rect(struct weston_surface *surface,
 	rect.x2 = floorf(xf);
 	rect.y2 = floorf(yf);
 
-	return weston_transformed_rect(surface->width,
-				       surface->height,
-				       surface->buffer_viewport.transform,
-				       surface->buffer_viewport.scale,
+	return weston_transformed_rect(surface->width, surface->height,
+				       vp->buffer.transform, vp->buffer.scale,
 				       rect);
 }
 
@@ -1195,6 +1196,7 @@ weston_surface_set_size(struct weston_surface *surface,
 static void
 weston_surface_set_size_from_buffer(struct weston_surface *surface)
 {
+	struct weston_buffer_viewport *vp = &surface->buffer_viewport;
 	int32_t width, height;
 
 	if (!surface->buffer_ref.buffer) {
@@ -1202,13 +1204,13 @@ weston_surface_set_size_from_buffer(struct weston_surface *surface)
 		return;
 	}
 
-	if (surface->buffer_viewport.viewport_set) {
-		surface->width = surface->buffer_viewport.dst_width;
-		surface->height = surface->buffer_viewport.dst_height;
+	if (vp->buffer.viewport_set) {
+		surface->width = vp->surface.width;
+		surface->height = vp->surface.height;
 		return;
 	}
 
-	switch (surface->buffer_viewport.transform) {
+	switch (vp->buffer.transform) {
 	case WL_OUTPUT_TRANSFORM_90:
 	case WL_OUTPUT_TRANSFORM_270:
 	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
@@ -1222,8 +1224,8 @@ weston_surface_set_size_from_buffer(struct weston_surface *surface)
 		break;
 	}
 
-	width = width / surface->buffer_viewport.scale;
-	height = height / surface->buffer_viewport.scale;
+	width = width / vp->buffer.scale;
+	height = height / vp->buffer.scale;
 	surface_set_size(surface, width, height);
 }
 
@@ -2108,7 +2110,7 @@ surface_set_buffer_transform(struct wl_client *client,
 {
 	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
-	surface->pending.buffer_viewport.transform = transform;
+	surface->pending.buffer_viewport.buffer.transform = transform;
 }
 
 static void
@@ -2118,7 +2120,7 @@ surface_set_buffer_scale(struct wl_client *client,
 {
 	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
-	surface->pending.buffer_viewport.scale = scale;
+	surface->pending.buffer_viewport.buffer.scale = scale;
 }
 
 static const struct wl_surface_interface surface_interface = {
@@ -3353,7 +3355,7 @@ destroy_viewport(struct wl_resource *resource)
 		wl_resource_get_user_data(resource);
 
 	surface->viewport_resource = NULL;
-	surface->pending.buffer_viewport.viewport_set = 0;
+	surface->pending.buffer_viewport.buffer.viewport_set = 0;
 }
 
 static void
@@ -3396,14 +3398,14 @@ viewport_set(struct wl_client *client,
 		return;
 	}
 
-	surface->pending.buffer_viewport.viewport_set = 1;
+	surface->pending.buffer_viewport.buffer.viewport_set = 1;
 
-	surface->pending.buffer_viewport.src_x = src_x;
-	surface->pending.buffer_viewport.src_y = src_y;
-	surface->pending.buffer_viewport.src_width = src_width;
-	surface->pending.buffer_viewport.src_height = src_height;
-	surface->pending.buffer_viewport.dst_width = dst_width;
-	surface->pending.buffer_viewport.dst_height = dst_height;
+	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;
 }
 
 static const struct wl_viewport_interface viewport_interface = {
diff --git a/src/compositor.h b/src/compositor.h
index 8fb8afb..f1f126b 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -655,20 +655,25 @@ struct weston_buffer_reference {
 };
 
 struct weston_buffer_viewport {
-	/* wl_surface.set_buffer_transform */
-	uint32_t transform;
+	struct {
+		/* wl_surface.set_buffer_transform */
+		uint32_t transform;
 
-	/* wl_surface.set_scaling_factor */
-	int32_t scale;
+		/* 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 */
 
-	/* 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 */
+		wl_fixed_t src_x, src_y;
+		wl_fixed_t src_width, src_height;
+	} buffer;
 
-	wl_fixed_t src_x, src_y;
-	wl_fixed_t src_width, src_height;
-	int32_t dst_width, dst_height;
+	struct {
+		int32_t width, height;
+	} surface;
 };
 
 struct weston_region {
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 76325f4..531c405 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -551,7 +551,7 @@ draw_view(struct weston_view *ev, struct weston_output *output,
 	shader_uniforms(gs->shader, ev, output);
 
 	if (ev->transform.enabled || output->zoom.active ||
-	    output->current_scale != ev->surface->buffer_viewport.scale)
+	    output->current_scale != ev->surface->buffer_viewport.buffer.scale)
 		filter = GL_LINEAR;
 	else
 		filter = GL_NEAREST;
diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c
index 26f6f27..4849155 100644
--- a/src/pixman-renderer.c
+++ b/src/pixman-renderer.c
@@ -147,6 +147,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 		(struct pixman_renderer *) output->compositor->renderer;
 	struct pixman_surface_state *ps = get_surface_state(ev->surface);
 	struct pixman_output_state *po = get_output_state(output);
+	struct weston_buffer_viewport *vp = &ev->surface->buffer_viewport;
 	pixman_region32_t final_region;
 	float view_x, view_y;
 	pixman_transform_t transform;
@@ -257,17 +258,17 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 					   pixman_double_to_fixed ((double)-ev->geometry.y));
 	}
 
-	if (ev->surface->buffer_viewport.viewport_set) {
+	if (vp->buffer.viewport_set) {
 		double viewport_x, viewport_y, viewport_width, viewport_height;
 		double ratio_x, ratio_y;
 
-		viewport_x = wl_fixed_to_double(ev->surface->buffer_viewport.src_x);
-		viewport_y = wl_fixed_to_double(ev->surface->buffer_viewport.src_y);
-		viewport_width = wl_fixed_to_double(ev->surface->buffer_viewport.src_width);
-		viewport_height = wl_fixed_to_double(ev->surface->buffer_viewport.src_height);
+		viewport_x = wl_fixed_to_double(vp->buffer.src_x);
+		viewport_y = wl_fixed_to_double(vp->buffer.src_y);
+		viewport_width = wl_fixed_to_double(vp->buffer.src_width);
+		viewport_height = wl_fixed_to_double(vp->buffer.src_height);
 
-		ratio_x = viewport_width / ev->surface->buffer_viewport.dst_width;
-		ratio_y = viewport_height / ev->surface->buffer_viewport.dst_height;
+		ratio_x = viewport_width / vp->surface.width;
+		ratio_y = viewport_height / vp->surface.height;
 
 		pixman_transform_scale(&transform, NULL,
 				       pixman_double_to_fixed(ratio_x),
@@ -277,13 +278,13 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 	}
 
 	pixman_transform_scale(&transform, NULL,
-			       pixman_double_to_fixed(ev->surface->buffer_viewport.scale),
-			       pixman_double_to_fixed(ev->surface->buffer_viewport.scale));
+			       pixman_double_to_fixed(vp->buffer.scale),
+			       pixman_double_to_fixed(vp->buffer.scale));
 
 	fw = pixman_int_to_fixed(pixman_image_get_width(ps->image));
 	fh = pixman_int_to_fixed(pixman_image_get_height(ps->image));
 
-	switch (ev->surface->buffer_viewport.transform) {
+	switch (vp->buffer.transform) {
 	case WL_OUTPUT_TRANSFORM_FLIPPED:
 	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
 	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
@@ -295,7 +296,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 		break;
 	}
 
-	switch (ev->surface->buffer_viewport.transform) {
+	switch (vp->buffer.transform) {
 	default:
 	case WL_OUTPUT_TRANSFORM_NORMAL:
 	case WL_OUTPUT_TRANSFORM_FLIPPED:
@@ -319,7 +320,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 
 	pixman_image_set_transform(ps->image, &transform);
 
-	if (ev->transform.enabled || output->current_scale != ev->surface->buffer_viewport.scale)
+	if (ev->transform.enabled || output->current_scale != vp->buffer.scale)
 		pixman_image_set_filter(ps->image, PIXMAN_FILTER_BILINEAR, NULL, 0);
 	else
 		pixman_image_set_filter(ps->image, PIXMAN_FILTER_NEAREST, NULL, 0);
-- 
1.8.3.2



More information about the wayland-devel mailing list