[PATCH 02/15] transformed: Rely on transformation in widget_cairo_create

alexl at redhat.com alexl at redhat.com
Wed May 22 05:41:26 PDT 2013


From: Alexander Larsson <alexl at redhat.com>

Rather than doing our own transformation handling when drawing we
just rely on the generic code in widget_cairo_create
---
 clients/transformed.c | 69 ++++++---------------------------------------------
 1 file changed, 8 insertions(+), 61 deletions(-)

diff --git a/clients/transformed.c b/clients/transformed.c
index 8983bb5..560ddf3 100644
--- a/clients/transformed.c
+++ b/clients/transformed.c
@@ -42,67 +42,14 @@ struct transformed {
 };
 
 static void
-update_transform(cairo_t *cr, enum wl_output_transform transform)
+draw_stuff(cairo_t *cr, int width, int height)
 {
-	double angle;
-
 	cairo_matrix_t m;
+	cairo_get_matrix (cr, &m);
 
-	switch(transform) {
-	case WL_OUTPUT_TRANSFORM_FLIPPED:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_270:
-		cairo_matrix_init(&m, -1, 0, 0, 1, 0, 0);
-		break;
-	default:
-		cairo_matrix_init_identity(&m);
-		break;
-	}
-	switch (transform) {
-	case WL_OUTPUT_TRANSFORM_NORMAL:
-	case WL_OUTPUT_TRANSFORM_FLIPPED:
-	default:
-		angle = 0;
-		break;
-	case WL_OUTPUT_TRANSFORM_90:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_90:
-		angle = M_PI_2;
-		break;
-	case WL_OUTPUT_TRANSFORM_180:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_180:
-		angle = M_PI;
-		break;
-	case WL_OUTPUT_TRANSFORM_270:
-	case WL_OUTPUT_TRANSFORM_FLIPPED_270:
-		angle = M_PI + M_PI_2;
-		break;
-	}
-
-	cairo_rotate(cr, angle);
-	cairo_transform(cr, &m);
-}
-
-static void
-draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
-{
-	cairo_t *cr;
-	int tmp;
-
-	if (transform & 1) {
-		tmp = width;
-		width = height;
-		height = tmp;
-	}
-
-	cr = cairo_create(surface);
-
-	cairo_identity_matrix(cr);
 	cairo_translate(cr, width / 2, height / 2);
 	cairo_scale(cr, width / 2, height / 2);
 
-	update_transform(cr, transform);
-
 	cairo_set_source_rgba(cr, 0, 0, 0.3, 1.0);
 	cairo_set_source_rgba(cr, 0, 0, 0, 1.0);
 	cairo_rectangle(cr, -1, -1, 2, 2);
@@ -113,7 +60,7 @@ draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
 	cairo_line_to(cr, 0, -1);
 
 	cairo_save(cr);
-	cairo_identity_matrix(cr);
+	cairo_set_matrix(cr, &m);
 	cairo_set_line_width(cr, 2.0);
 	cairo_stroke(cr);
 	cairo_restore(cr);
@@ -123,7 +70,7 @@ draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
 	cairo_line_to(cr, 1, 0);
 
 	cairo_save(cr);
-	cairo_identity_matrix(cr);
+	cairo_set_matrix(cr, &m);
 	cairo_set_line_width(cr, 2.0);
 	cairo_stroke(cr);
 	cairo_restore(cr);
@@ -135,7 +82,7 @@ draw_stuff(cairo_surface_t *surface, int width, int height, int transform)
 	cairo_line_to(cr, -1, 0);
 
 	cairo_save(cr);
-	cairo_identity_matrix(cr);
+	cairo_set_matrix(cr, &m);
 	cairo_set_line_width(cr, 2.0);
 	cairo_stroke(cr);
 	cairo_restore(cr);
@@ -168,7 +115,7 @@ redraw_handler(struct widget *widget, void *data)
 	struct transformed *transformed = data;
 	struct rectangle allocation;
 	cairo_surface_t *surface;
-	int transform;
+	cairo_t *cr;
 
 	surface = window_get_surface(transformed->window);
 	if (surface == NULL ||
@@ -178,9 +125,9 @@ redraw_handler(struct widget *widget, void *data)
 	}
 
 	widget_get_allocation(transformed->widget, &allocation);
-	transform = window_get_buffer_transform(transformed->window);
 
-	draw_stuff(surface, allocation.width, allocation.height, transform);
+	cr = widget_cairo_create(widget);
+	draw_stuff(cr, allocation.width, allocation.height);
 
 	cairo_surface_destroy(surface);
 }
-- 
1.8.1.4



More information about the wayland-devel mailing list