gles2: update texture only if needed

When a surface is on a non-primary plane (overlay), we do not need to
keep the GL texture up-to-date, since we are not using it. Avoid calling
glTex(Sub)Image2D in that case, and accumulate the texture damage
separately.

This is especially useful for backends, that can put wl_shm buffers into
overlays.

The empty damage check has to be moved from surface_accumulate_damage()
into gles2_renderer_flush_damage(), because it really needs to check the
accumulated damage, not only the current damage. Otherwise, if a surface
migrates from a plane to the primary plane, and does not have new
damage, the texture would not be updated even for accumulated damage.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
diff --git a/src/compositor.c b/src/compositor.c
index f8b9b96..83bd244 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -239,6 +239,7 @@
 
 	surface->num_textures = 0;
 	surface->num_images = 0;
+	pixman_region32_init(&surface->texture_damage);
 
 	surface->buffer = NULL;
 	surface->output = NULL;
@@ -782,6 +783,7 @@
 	if (surface->buffer)
 		wl_list_remove(&surface->buffer_destroy_listener.link);
 
+	pixman_region32_fini(&surface->texture_damage);
 	compositor->renderer->destroy_surface(surface);
 
 	pixman_region32_fini(&surface->transform.boundingbox);
@@ -905,8 +907,7 @@
 surface_accumulate_damage(struct weston_surface *surface,
 			  pixman_region32_t *opaque)
 {
-	if (pixman_region32_not_empty(&surface->damage) &&
-	    surface->buffer && wl_buffer_is_shm(surface->buffer))
+	if (surface->buffer && wl_buffer_is_shm(surface->buffer))
 		surface->compositor->renderer->flush_damage(surface);
 
 	if (surface->transform.enabled) {