[PATCH weston 8/8] gl-renderer: Clean up EGL image and GL texture destruction.
John Kåre Alsaker
john.kare.alsaker at gmail.com
Thu Feb 21 10:19:34 PST 2013
This also ensures we destroy all EGL images if a plane fails to be created.
---
src/gl-renderer.c | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index 778fedd..c2d2490 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -1149,6 +1149,24 @@ ensure_textures(struct gl_surface_state *gs, int num_textures)
}
static void
+destroy_images(struct gl_renderer *gr, struct gl_surface_state *gs)
+{
+ int i;
+
+ for (i = 0; i < gs->num_images; i++)
+ gr->destroy_image(gr->egl_display, gs->images[i]);
+
+ gs->num_images = 0;
+}
+
+static void
+destroy_textures(struct gl_surface_state *gs)
+{
+ glDeleteTextures(gs->num_textures, gs->textures);
+ gs->num_textures = 0;
+}
+
+static void
gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
{
struct weston_compositor *ec = es->compositor;
@@ -1158,15 +1176,10 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
int i, num_planes;
weston_buffer_reference(&gs->buffer_ref, buffer);
+ destroy_images(gr, gs);
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;
+ destroy_textures(gs);
return;
}
@@ -1185,8 +1198,6 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
gs->input = INPUT_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) {
@@ -1230,10 +1241,11 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
EGL_WAYLAND_BUFFER_WL,
buffer, attribs);
if (!gs->images[i]) {
+ gs->num_images = i;
+ destroy_images(gr, gs);
weston_log("failed to create img for plane %d\n", i);
- continue;
+ return;
}
- gs->num_images++;
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(gs->target, gs->textures[i]);
@@ -1242,6 +1254,7 @@ gl_renderer_attach(struct weston_surface *es, struct wl_buffer *buffer)
}
gs->pitch = buffer->width;
+ gs->num_images = num_planes;
} else {
weston_log("unhandled buffer type!\n");
weston_buffer_reference(&gs->buffer_ref, NULL);
@@ -1294,12 +1307,9 @@ gl_renderer_destroy_surface(struct weston_surface *surface)
{
struct gl_surface_state *gs = get_surface_state(surface);
struct gl_renderer *gr = get_renderer(surface->compositor);
- int i;
-
- glDeleteTextures(gs->num_textures, gs->textures);
- for (i = 0; i < gs->num_images; i++)
- gr->destroy_image(gr->egl_display, gs->images[i]);
+ destroy_textures(gs);
+ destroy_images(gr, gs);
weston_buffer_reference(&gs->buffer_ref, NULL);
pixman_region32_fini(&gs->texture_damage);
--
1.8.1.3
More information about the wayland-devel
mailing list