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.h b/src/compositor.h
index a0ccb72..d2e121b 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -410,6 +410,7 @@
 	struct weston_compositor *compositor;
 	GLuint textures[3];
 	int num_textures;
+	pixman_region32_t texture_damage;
 	pixman_region32_t clip;
 	pixman_region32_t damage;
 	pixman_region32_t opaque;