[PATCH weston 1/8] compositor: gather buffer_transform and _scale into a struct

Jonny Lamb jonny.lamb at collabora.co.uk
Tue Nov 26 09:19:41 PST 2013


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

Gather the variables affecting the coordinate transformations between
buffer and local coordinates into a new struct weston_buffer_viewport.

This will be more useful later, when the crop & scale extension is
implemented.
---
 src/compositor-drm.c  | 11 ++++++-----
 src/compositor.c      | 42 ++++++++++++++++++------------------------
 src/compositor.h      | 19 +++++++++++--------
 src/gl-renderer.c     |  2 +-
 src/pixman-renderer.c | 10 +++++-----
 src/shell.c           |  6 +++---
 6 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index a1d9d59..c34fc1c 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -463,7 +463,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_transform ||
+	    output->base.transform != ev->surface->buffer_viewport.transform ||
 	    ev->transform.enabled)
 		return NULL;
 
@@ -818,10 +818,10 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 	if (c->gbm == NULL)
 		return NULL;
 
-	if (ev->surface->buffer_transform != output_base->transform)
+	if (ev->surface->buffer_viewport.transform != output_base->transform)
 		return NULL;
 
-	if (ev->surface->buffer_scale != output_base->current_scale)
+	if (ev->surface->buffer_viewport.scale != output_base->current_scale)
 		return NULL;
 
 	if (c->sprites_are_broken)
@@ -931,8 +931,9 @@ drm_output_prepare_overlay_view(struct weston_output *output_base,
 
 	tbox = weston_transformed_rect(wl_fixed_from_int(ev->geometry.width),
 				       wl_fixed_from_int(ev->geometry.height),
-				       ev->surface->buffer_transform,
-				       ev->surface->buffer_scale, tbox);
+				       ev->surface->buffer_viewport.transform,
+				       ev->surface->buffer_viewport.scale,
+				       tbox);
 
 	s->src_x = tbox.x1 << 8;
 	s->src_y = tbox.y1 << 8;
diff --git a/src/compositor.c b/src/compositor.c
index cfcb273..b6f2966 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -400,10 +400,9 @@ weston_surface_create(struct weston_compositor *compositor)
 	surface->compositor = compositor;
 	surface->ref_count = 1;
 
-	surface->buffer_transform = WL_OUTPUT_TRANSFORM_NORMAL;
-	surface->buffer_scale = 1;
-	surface->pending.buffer_transform = surface->buffer_transform;
-	surface->pending.buffer_scale = surface->buffer_scale;
+	surface->buffer_viewport.transform = WL_OUTPUT_TRANSFORM_NORMAL;
+	surface->buffer_viewport.scale = 1;
+	surface->pending.buffer_viewport = surface->buffer_viewport;
 	surface->output = NULL;
 	surface->pending.newly_attached = 0;
 
@@ -639,8 +638,8 @@ weston_surface_to_buffer_float(struct weston_surface *surface,
 {
 	weston_transformed_coord(surface->width,
 				 surface->height,
-				 surface->buffer_transform,
-				 surface->buffer_scale,
+				 surface->buffer_viewport.transform,
+				 surface->buffer_viewport.scale,
 				 sx, sy, bx, by);
 }
 
@@ -652,8 +651,8 @@ weston_surface_to_buffer(struct weston_surface *surface,
 
 	weston_transformed_coord(surface->width,
 				 surface->height,
-				 surface->buffer_transform,
-				 surface->buffer_scale,
+				 surface->buffer_viewport.transform,
+				 surface->buffer_viewport.scale,
 				 sx, sy, &bxf, &byf);
 	*bx = floorf(bxf);
 	*by = floorf(byf);
@@ -665,8 +664,8 @@ weston_surface_to_buffer_rect(struct weston_surface *surface,
 {
 	return weston_transformed_rect(surface->width,
 				       surface->height,
-				       surface->buffer_transform,
-				       surface->buffer_scale,
+				       surface->buffer_viewport.transform,
+				       surface->buffer_viewport.scale,
 				       rect);
 }
 
@@ -1146,7 +1145,7 @@ WL_EXPORT int32_t
 weston_surface_buffer_width(struct weston_surface *surface)
 {
 	int32_t width;
-	switch (surface->buffer_transform) {
+	switch (surface->buffer_viewport.transform) {
 	case WL_OUTPUT_TRANSFORM_90:
 	case WL_OUTPUT_TRANSFORM_270:
 	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
@@ -1157,14 +1156,14 @@ weston_surface_buffer_width(struct weston_surface *surface)
 		width = surface->buffer_ref.buffer->width;
                 break;
 	}
-	return width / surface->buffer_scale;
+	return width / surface->buffer_viewport.scale;
 }
 
 WL_EXPORT int32_t
 weston_surface_buffer_height(struct weston_surface *surface)
 {
 	int32_t height;
-	switch (surface->buffer_transform) {
+	switch (surface->buffer_viewport.transform) {
 	case WL_OUTPUT_TRANSFORM_90:
 	case WL_OUTPUT_TRANSFORM_270:
 	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
@@ -1175,7 +1174,7 @@ weston_surface_buffer_height(struct weston_surface *surface)
 		height = surface->buffer_ref.buffer->height;
                 break;
 	}
-	return height / surface->buffer_scale;
+	return height / surface->buffer_viewport.scale;
 }
 
 WL_EXPORT uint32_t
@@ -1964,10 +1963,8 @@ weston_surface_commit(struct weston_surface *surface)
 	pixman_region32_t opaque;
 
 	/* wl_surface.set_buffer_transform */
-	surface->buffer_transform = surface->pending.buffer_transform;
-
 	/* wl_surface.set_buffer_scale */
-	surface->buffer_scale = surface->pending.buffer_scale;
+	surface->buffer_viewport = surface->pending.buffer_viewport;
 
 	/* wl_surface.attach */
 	if (surface->pending.buffer || surface->pending.newly_attached)
@@ -2067,7 +2064,7 @@ surface_set_buffer_transform(struct wl_client *client,
 {
 	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
-	surface->pending.buffer_transform = transform;
+	surface->pending.buffer_viewport.transform = transform;
 }
 
 static void
@@ -2077,7 +2074,7 @@ surface_set_buffer_scale(struct wl_client *client,
 {
 	struct weston_surface *surface = wl_resource_get_user_data(resource);
 
-	surface->pending.buffer_scale = scale;
+	surface->pending.buffer_viewport.scale = scale;
 }
 
 static const struct wl_surface_interface surface_interface = {
@@ -2198,10 +2195,8 @@ weston_subsurface_commit_from_cache(struct weston_subsurface *sub)
 	pixman_region32_t opaque;
 
 	/* wl_surface.set_buffer_transform */
-	surface->buffer_transform = sub->cached.buffer_transform;
-
 	/* wl_surface.set_buffer_scale */
-	surface->buffer_scale = sub->cached.buffer_scale;
+	surface->buffer_viewport = sub->cached.buffer_viewport;
 
 	/* wl_surface.attach */
 	if (sub->cached.buffer_ref.buffer || sub->cached.newly_attached)
@@ -2294,8 +2289,7 @@ weston_subsurface_commit_to_cache(struct weston_subsurface *sub)
 	surface->pending.sy = 0;
 	surface->pending.newly_attached = 0;
 
-	sub->cached.buffer_transform = surface->pending.buffer_transform;
-	sub->cached.buffer_scale = surface->pending.buffer_scale;
+	sub->cached.buffer_viewport = surface->pending.buffer_viewport;
 
 	pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque);
 
diff --git a/src/compositor.h b/src/compositor.h
index 8c19619..e445dc3 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -647,6 +647,14 @@ struct weston_buffer_reference {
 	struct wl_listener destroy_listener;
 };
 
+struct weston_buffer_viewport {
+	/* wl_surface.set_buffer_transform */
+	uint32_t transform;
+
+	/* wl_surface.set_scaling_factor */
+	int32_t scale;
+};
+
 struct weston_region {
 	struct wl_resource *resource;
 	pixman_region32_t region;
@@ -693,10 +701,8 @@ struct weston_subsurface {
 		struct wl_list frame_callback_list;
 
 		/* wl_surface.set_buffer_transform */
-		uint32_t buffer_transform;
-
 		/* wl_surface.set_buffer_scale */
-		int32_t buffer_scale;
+		struct weston_buffer_viewport buffer_viewport;
 	} cached;
 
 	int synchronized;
@@ -835,8 +841,7 @@ struct weston_surface {
 	struct wl_list frame_callback_list;
 
 	struct weston_buffer_reference buffer_ref;
-	uint32_t buffer_transform;
-	int32_t buffer_scale;
+	struct weston_buffer_viewport buffer_viewport;
 	int keep_buffer; /* bool for backends to prevent early release */
 
 	/* All the pending state, that wl_surface.commit will apply. */
@@ -861,10 +866,8 @@ struct weston_surface {
 		struct wl_list frame_callback_list;
 
 		/* wl_surface.set_buffer_transform */
-		uint32_t buffer_transform;
-
 		/* wl_surface.set_scaling_factor */
-		int32_t buffer_scale;
+		struct weston_buffer_viewport buffer_viewport;
 	} pending;
 
 	/*
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 218fca4..799fba1 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -536,7 +536,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_scale)
+	    output->current_scale != ev->surface->buffer_viewport.scale)
 		filter = GL_LINEAR;
 	else
 		filter = GL_NEAREST;
diff --git a/src/pixman-renderer.c b/src/pixman-renderer.c
index b719829..5961965 100644
--- a/src/pixman-renderer.c
+++ b/src/pixman-renderer.c
@@ -260,7 +260,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 	fw = pixman_int_to_fixed(ev->geometry.width);
 	fh = pixman_int_to_fixed(ev->geometry.height);
 
-	switch (ev->surface->buffer_transform) {
+	switch (ev->surface->buffer_viewport.transform) {
 	case WL_OUTPUT_TRANSFORM_FLIPPED:
 	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
 	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
@@ -272,7 +272,7 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 		break;
 	}
 
-	switch (ev->surface->buffer_transform) {
+	switch (ev->surface->buffer_viewport.transform) {
 	default:
 	case WL_OUTPUT_TRANSFORM_NORMAL:
 	case WL_OUTPUT_TRANSFORM_FLIPPED:
@@ -295,12 +295,12 @@ repaint_region(struct weston_view *ev, struct weston_output *output,
 	}
 
 	pixman_transform_scale(&transform, NULL,
-			       pixman_double_to_fixed ((double)ev->surface->buffer_scale),
-			       pixman_double_to_fixed ((double)ev->surface->buffer_scale));
+			       pixman_double_to_fixed ((double)ev->surface->buffer_viewport.scale),
+			       pixman_double_to_fixed ((double)ev->surface->buffer_viewport.scale));
 
 	pixman_image_set_transform(ps->image, &transform);
 
-	if (ev->transform.enabled || output->current_scale != ev->surface->buffer_scale)
+	if (ev->transform.enabled || output->current_scale != ev->surface->buffer_viewport.scale)
 		pixman_image_set_filter(ps->image, PIXMAN_FILTER_BILINEAR, NULL, 0);
 	else
 		pixman_image_set_filter(ps->image, PIXMAN_FILTER_NEAREST, NULL, 0);
diff --git a/src/shell.c b/src/shell.c
index f102e9a..5227cbe 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -2330,11 +2330,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_scale,
-				surf_height * surface->buffer_scale,
+				surf_width * surface->buffer_viewport.scale,
+				surf_height * surface->buffer_viewport.scale,
 				shsurf->fullscreen.framerate};
 
-			if (weston_output_switch_mode(output, &mode, surface->buffer_scale,
+			if (weston_output_switch_mode(output, &mode, surface->buffer_viewport.scale,
 					WESTON_MODE_SWITCH_SET_TEMPORARY) == 0) {
 				weston_view_set_position(shsurf->view,
 							 output->x - surf_x,
-- 
1.8.4.2



More information about the wayland-devel mailing list