[weston,v2,03/20] Use pixel coordinates for weston_output.matrix

Submitted by Derek Foreman on Oct. 16, 2014, 3:55 p.m.

Details

Message ID 1413474938-2407-4-git-send-email-derekf@osg.samsung.com
State Superseded
Delegated to: Pekka Paalanen
Headers show

Not browsing as part of any series.

Commit Message

Derek Foreman Oct. 16, 2014, 3:55 p.m.
From: Jason Ekstrand <jason@jlekstrand.net>

Previously, weston_output.matrix was in GL coordinates and therefore only
really useful for the GL backend.
---
 src/compositor.c  | 106 ++++++++++++++++++++----------------------------------
 src/gl-renderer.c |  14 +++++++-
 2 files changed, 52 insertions(+), 68 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/compositor.c b/src/compositor.c
index c85cf2e..5d8bd5e 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3480,88 +3480,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/gl-renderer.c b/src/gl-renderer.c
index d54928b..28b3b75 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -74,6 +74,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 {
@@ -511,9 +513,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);
 
@@ -876,6 +879,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:
 	 */