[PATCH weston 1/3] gl-renderer: Track the buffer type in gl_surface_state

Ander Conselvan de Oliveira ander.conselvan.de.oliveira at intel.com
Fri Jun 7 06:52:44 PDT 2013


Checking for gs->num_images for determining the previous buffer type
when attaching is not reliable. The number of images is never cleared
in the SHM path, so after a switch from an EGL buffer to SHM, every
following attach of an SHM buffer will happen with gs->num_images > 0,
and the code will assume the previous buffer was an EGL one.

Fix this by adding a buffer_type field to gl_surface_state.
---
 src/gl-renderer.c |   21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 7d27a97..b869856 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -54,6 +54,12 @@ struct gl_output_state {
 	pixman_region32_t buffer_damage[BUFFER_DAMAGE_COUNT];
 };
 
+enum buffer_type {
+	BUFFER_TYPE_NULL,
+	BUFFER_TYPE_SHM,
+	BUFFER_TYPE_EGL
+};
+
 struct gl_surface_state {
 	GLfloat color[4];
 	struct gl_shader *shader;
@@ -67,6 +73,7 @@ struct gl_surface_state {
 	int num_images;
 
 	struct weston_buffer_reference buffer_ref;
+	enum buffer_type buffer_type;
 	int pitch; /* in pixels */
 	int height; /* in pixels */
 };
@@ -1200,17 +1207,17 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 		gs->num_images = 0;
 		glDeleteTextures(gs->num_textures, gs->textures);
 		gs->num_textures = 0;
+		gs->buffer_type = BUFFER_TYPE_NULL;
 		return;
 	}
 
 	if (wl_buffer_is_shm(buffer)) {
 		/* Only allocate a texture if it doesn't match existing one.
-		 * If gs->num_images is not 0, then a switch from DRM allocated
-		 * buffer to a SHM buffer is happening, and we need to allocate
-		 * a new texture buffer. */
+		 * If a switch from DRM allocated buffer to a SHM buffer is
+		 * happening, we need to allocate a new texture buffer. */
 		if (wl_shm_buffer_get_stride(buffer) / 4 != gs->pitch ||
 		    wl_shm_buffer_get_height(buffer) != gs->height ||
-		    gs->num_images > 0) {
+		    gs->buffer_type != BUFFER_TYPE_SHM) {
 			gs->pitch = wl_shm_buffer_get_stride(buffer) / 4;
 			gs->height = wl_shm_buffer_get_height(buffer);
 			gs->target = GL_TEXTURE_2D;
@@ -1231,6 +1238,8 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 			gs->shader = &gr->texture_shader_rgbx;
 		else
 			gs->shader = &gr->texture_shader_rgba;
+
+		gs->buffer_type = BUFFER_TYPE_SHM;
 	} else if (gr->query_buffer(gr->egl_display, buffer,
 				    EGL_TEXTURE_FORMAT, &format)) {
 		for (i = 0; i < gs->num_images; i++)
@@ -1286,9 +1295,13 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
 
 		gs->pitch = buffer->width;
 		gs->height = buffer->height;
+
+		gs->buffer_type = BUFFER_TYPE_EGL;
 	} else {
 		weston_log("unhandled buffer type!\n");
 		weston_buffer_reference(&gs->buffer_ref, NULL);
+
+		gs->buffer_type = BUFFER_TYPE_NULL;
 	}
 }
 
-- 
1.7.10.4



More information about the wayland-devel mailing list