[PATCH weston v2 03/16] Use pixel coordinates for weston_output.matrix

Pekka Paalanen ppaalanen at gmail.com
Tue Mar 10 06:01:34 PDT 2015


From: Jason Ekstrand <jason at jlekstrand.net>

Previously, weston_output.matrix was in GL coordinates and therefore only
really useful for the GL backend.

This breaks zoom, which will be fixed by the following patch:
	zoom: Use pixels instead of GL coordinates

[Pekka: added a comment to compositor.h, message]
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
 src/compositor.c  | 106 ++++++++++++++++++++----------------------------------
 src/compositor.h  |   3 ++
 src/gl-renderer.c |  14 +++++++-
 3 files changed, 55 insertions(+), 68 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 45e8f5c..5a75c7e 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3773,88 +3773,60 @@ weston_output_destroy(struct weston_output *output)
 	wl_global_destroy(output->global);
 }
 
-static void
-weston_output_compute_transform(struct weston_output *output)
-{
-	struct weston_matrix transform;
-	int flip;
-
-	weston_matrix_init(&transform);
-	transform.type = WESTON_MATRIX_TRANSFORM_ROTATE;
-
-	switch(output->transform) {
-	case WL_OUTPUT_TRANSFORM_FLIPPED:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_270:
-		transform.type |= WESTON_MATRIX_TRANSFORM_OTHER;
-		flip = -1;
-		break;
-	default:
-		flip = 1;
-		break;
-	}
-
-        switch(output->transform) {
-        case WL_OUTPUT_TRANSFORM_NORMAL:
-        case WL_OUTPUT_TRANSFORM_FLIPPED:
-                transform.d[0] = flip;
-                transform.d[1] = 0;
-                transform.d[4] = 0;
-                transform.d[5] = 1;
-                break;
-        case WL_OUTPUT_TRANSFORM_90:
-        case WL_OUTPUT_TRANSFORM_FLIPPED_90:
-                transform.d[0] = 0;
-                transform.d[1] = -flip;
-                transform.d[4] = 1;
-                transform.d[5] = 0;
-                break;
-        case WL_OUTPUT_TRANSFORM_180:
-        case WL_OUTPUT_TRANSFORM_FLIPPED_180:
-                transform.d[0] = -flip;
-                transform.d[1] = 0;
-                transform.d[4] = 0;
-                transform.d[5] = -1;
-                break;
-        case WL_OUTPUT_TRANSFORM_270:
-        case WL_OUTPUT_TRANSFORM_FLIPPED_270:
-                transform.d[0] = 0;
-                transform.d[1] = flip;
-                transform.d[4] = -1;
-                transform.d[5] = 0;
-                break;
-        default:
-                break;
-        }
-
-	weston_matrix_multiply(&output->matrix, &transform);
-}
-
 WL_EXPORT void
 weston_output_update_matrix(struct weston_output *output)
 {
 	float magnification;
 
 	weston_matrix_init(&output->matrix);
-	weston_matrix_translate(&output->matrix,
-				-(output->x + output->width / 2.0),
-				-(output->y + output->height / 2.0), 0);
-
-	weston_matrix_scale(&output->matrix,
-			    2.0 / output->width,
-			    -2.0 / output->height, 1);
+	weston_matrix_translate(&output->matrix, -output->x, -output->y, 0);
 
 	if (output->zoom.active) {
 		magnification = 1 / (1 - output->zoom.spring_z.current);
 		weston_output_update_zoom(output);
 		weston_matrix_translate(&output->matrix, -output->zoom.trans_x,
-					output->zoom.trans_y, 0);
+					-output->zoom.trans_y, 0);
 		weston_matrix_scale(&output->matrix, magnification,
 				    magnification, 1.0);
 	}
 
-	weston_output_compute_transform(output);
+	switch (output->transform) {
+	case WL_OUTPUT_TRANSFORM_FLIPPED:
+	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+	case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+		weston_matrix_translate(&output->matrix, -output->width, 0, 0);
+		weston_matrix_scale(&output->matrix, -1, 1, 1);
+		break;
+	}
+
+	switch (output->transform) {
+	default:
+	case WL_OUTPUT_TRANSFORM_NORMAL:
+	case WL_OUTPUT_TRANSFORM_FLIPPED:
+		break;
+	case WL_OUTPUT_TRANSFORM_90:
+	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+		weston_matrix_translate(&output->matrix, 0, -output->height, 0);
+		weston_matrix_rotate_xy(&output->matrix, 0, 1);
+		break;
+	case WL_OUTPUT_TRANSFORM_180:
+	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+		weston_matrix_translate(&output->matrix,
+					-output->width, -output->height, 0);
+		weston_matrix_rotate_xy(&output->matrix, -1, 0);
+		break;
+	case WL_OUTPUT_TRANSFORM_270:
+	case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+		weston_matrix_translate(&output->matrix, -output->width, 0, 0);
+		weston_matrix_rotate_xy(&output->matrix, 0, -1);
+		break;
+	}
+
+	if (output->current_scale != 1)
+		weston_matrix_scale(&output->matrix,
+				    output->current_scale,
+				    output->current_scale, 1);
 
 	output->dirty = 0;
 }
diff --git a/src/compositor.h b/src/compositor.h
index bb7562f..207767e 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -182,7 +182,10 @@ struct weston_output {
 	struct wl_list resource_list;
 	struct wl_global *global;
 	struct weston_compositor *compositor;
+
+	/** From global to output buffer coordinates. */
 	struct weston_matrix matrix;
+
 	struct wl_list animation_list;
 	int32_t x, y, width, height;
 	int32_t mm_width, mm_height;
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 11f7ca6..10d7d71 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -76,6 +76,8 @@ struct gl_output_state {
 	enum gl_border_status border_damage[BUFFER_DAMAGE_COUNT];
 	struct gl_border_image borders[4];
 	enum gl_border_status border_status;
+
+	struct weston_matrix output_matrix;
 };
 
 enum buffer_type {
@@ -574,9 +576,10 @@ shader_uniforms(struct gl_shader *shader,
 {
 	int i;
 	struct gl_surface_state *gs = get_surface_state(view->surface);
+	struct gl_output_state *go = get_output_state(output);
 
 	glUniformMatrix4fv(shader->proj_uniform,
-			   1, GL_FALSE, output->matrix.d);
+			   1, GL_FALSE, go->output_matrix.d);
 	glUniform4fv(shader->color_uniform, 1, gs->color);
 	glUniform1f(shader->alpha_uniform, view->alpha);
 
@@ -954,6 +957,15 @@ gl_renderer_repaint_output(struct weston_output *output,
 		   output->current_mode->width,
 		   output->current_mode->height);
 
+	/* Calculate the global GL matrix */
+	go->output_matrix = output->matrix;
+	weston_matrix_translate(&go->output_matrix,
+				-(output->current_mode->width / 2.0),
+				-(output->current_mode->height / 2.0), 0);
+	weston_matrix_scale(&go->output_matrix,
+			    2.0 / output->current_mode->width,
+			    -2.0 / output->current_mode->height, 1);
+
 	/* if debugging, redraw everything outside the damage to clean up
 	 * debug lines from the previous draw on this buffer:
 	 */
-- 
2.0.5



More information about the wayland-devel mailing list