[PATCH] gl-renderer: Always release previous EGL images on attach

Kristian Høgsberg hoegsberg at gmail.com
Thu Jun 6 21:27:05 PDT 2013


On Wed, Jun 05, 2013 at 12:21:05PM +0300, Ander Conselvan de Oliveira wrote:
> From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
> 
> When attaching a new buffer, the EGL images created for the previous one
> would be released if this new buffer was an EGL or NULL buffer, but not
> if is was an SHM buffer. This wouldn't cause the resources to be leaked
> becaused they are free()'d when the surface is destroyed, but they
> would linger around for longer than necessary.
> 
> Note that this change the behaviour when attaching an unknow buffer
> type. Before the EGL images would still be around, but now that would
> cause them to be destroyed.
> ---
>  src/gl-renderer.c |   14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/src/gl-renderer.c b/src/gl-renderer.c
> index d783a0b..13c0fa9 100644
> --- a/src/gl-renderer.c
> +++ b/src/gl-renderer.c
> @@ -1192,12 +1192,13 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
>  
>  	weston_buffer_reference(&gs->buffer_ref, buffer);
>  
> +	for (i = 0; i < gs->num_images; i++) {
> +		gr->destroy_image(gr->egl_display, gs->images[i]);
> +		gs->images[i] = NULL;
> +	}
> +	gs->num_images = 0;
> +

We look at gs->num_images below in the shm case to determine if the
previous buffer was a drm buffer.  Freeing the buffers here means that
num_images is always NULL and that we fail to damage the entire
texture.

Kristian

>  	if (!buffer) {
> -		for (i = 0; i < gs->num_images; i++) {
> -			gr->destroy_image(gr->egl_display, gs->images[i]);
> -			gs->images[i] = NULL;
> -		}
> -		gs->num_images = 0;
>  		glDeleteTextures(gs->num_textures, gs->textures);
>  		gs->num_textures = 0;
>  		return;
> @@ -1219,9 +1220,6 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
>  			gs->shader = &gr->texture_shader_rgba;
>  	} else if (gr->query_buffer(gr->egl_display, buffer,
>  				    EGL_TEXTURE_FORMAT, &format)) {
> -		for (i = 0; i < gs->num_images; i++)
> -			gr->destroy_image(gr->egl_display, gs->images[i]);
> -		gs->num_images = 0;
>  		gs->target = GL_TEXTURE_2D;
>  		switch (format) {
>  		case EGL_TEXTURE_RGB:
> -- 
> 1.7.9.5
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list