wcap: Transform damage rectangles according to output tranform

https://bugs.freedesktop.org/show_bug.cgi?id=56697
diff --git a/src/screenshooter.c b/src/screenshooter.c
index 23181a2..46f65ed 100644
--- a/src/screenshooter.c
+++ b/src/screenshooter.c
@@ -254,6 +254,55 @@
 }
 
 static void
+transform_rect(struct weston_output *output, pixman_box32_t *r)
+{
+	pixman_box32_t s = *r;
+
+	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:
+		s.x1 = output->width - r->x2;
+		s.x2 = output->width - r->x1;
+		break;
+	default:
+		break;
+	}
+
+        switch(output->transform) {
+        case WL_OUTPUT_TRANSFORM_NORMAL:
+        case WL_OUTPUT_TRANSFORM_FLIPPED:
+		r->x1 = s.x1;
+		r->x2 = s.x2;
+                break;
+        case WL_OUTPUT_TRANSFORM_90:
+        case WL_OUTPUT_TRANSFORM_FLIPPED_90:
+		r->x1 = output->current->width - s.y2;
+		r->y1 = s.x1;
+		r->x2 = output->current->width - s.y1;
+		r->y2 = s.x2;
+                break;
+        case WL_OUTPUT_TRANSFORM_180:
+        case WL_OUTPUT_TRANSFORM_FLIPPED_180:
+		r->x1 = output->current->width - s.x2;
+		r->y1 = output->current->height - s.y2;
+		r->x2 = output->current->width - s.x1;
+		r->y2 = output->current->height - s.y1;
+                break;
+        case WL_OUTPUT_TRANSFORM_270:
+        case WL_OUTPUT_TRANSFORM_FLIPPED_270:
+		r->x1 = s.y1; 
+		r->y1 = output->current->height - s.x2;
+		r->x2 = s.y2; 
+		r->y2 = output->current->height - s.x1;
+                break;
+        default:
+                break;
+        }
+}
+
+static void
 weston_recorder_frame_notify(struct wl_listener *listener, void *data)
 {
 	struct weston_recorder *recorder =
@@ -287,6 +336,9 @@
 	if (n == 0)
 		return;
 
+	for (i = 0; i < n; i++)
+		transform_rect(output, &r[i]);
+
 	header.msecs = msecs;
 	header.nrects = n;
 	v[0].iov_base = &header;