compositor: Generalize output previous damage into per buffer damage

This is a more generic fix for the issue solved in 4f521731 where
damage obscured by overlays could be lost in one of the output buffers
due to rapid move of a surface in an overlay plane.

This changes the renderer so it keeps track of the damage in each
buffer. Every time a new frame is drawn, the damage of the frame is
added to all the buffers and the rendered regions are cleared from
the current buffer's damage.
diff --git a/src/gles2-renderer.c b/src/gles2-renderer.c
index 0e8b8ce..761f4fe 100644
--- a/src/gles2-renderer.c
+++ b/src/gles2-renderer.c
@@ -612,6 +612,7 @@
 	pixman_region32_t repaint;
 	/* non-opaque region in surface coordinates: */
 	pixman_region32_t surface_blend;
+	pixman_region32_t *buffer_damage;
 	GLint filter;
 	int i;
 
@@ -623,8 +624,8 @@
 	if (!pixman_region32_not_empty(&repaint))
 		goto out;
 
-	pixman_region32_subtract(&ec->primary_plane.damage,
-				 &ec->primary_plane.damage, &repaint);
+	buffer_damage = &output->buffer_damage[output->current_buffer];
+	pixman_region32_subtract(buffer_damage, buffer_damage, &repaint);
 
 	glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
@@ -702,7 +703,7 @@
 	struct weston_compositor *compositor = output->compositor;
 	EGLBoolean ret;
 	static int errored;
-	int32_t width, height;
+	int32_t width, height, i;
 
 	width = output->current->width +
 		output->border.left + output->border.right;
@@ -736,6 +737,14 @@
 		pixman_region32_fini(&undamaged);
 	}
 
+	for (i = 0; i < 2; i++)
+		pixman_region32_union(&output->buffer_damage[i],
+				      &output->buffer_damage[i],
+				      output_damage);
+
+	pixman_region32_union(output_damage, output_damage,
+			      &output->buffer_damage[output->current_buffer]);
+
 	repaint_surfaces(output, output_damage);
 
 	wl_signal_emit(&output->frame_signal, output);
@@ -747,6 +756,8 @@
 		print_egl_error_state();
 	}
 
+	output->current_buffer ^= 1;
+
 }
 
 static void