gl-renderer: Assume num images the same as the no of planes
Potential failures when creating the EGL image could cause an incorrect number of num images (num_planes > num_images). With this change egl_image_unref() requires an additional check to avoid any potential NULL derefs when cleaning up. We do it straight in egl_image_unref() instead of adding guards all over the necessary parts. Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
@@ -388,8 +388,18 @@ egl_image_ref(struct egl_image *image)
|
|||||||
static int
|
static int
|
||||||
egl_image_unref(struct egl_image *image)
|
egl_image_unref(struct egl_image *image)
|
||||||
{
|
{
|
||||||
struct gl_renderer *gr = image->renderer;
|
struct gl_renderer *gr;
|
||||||
|
|
||||||
|
/* in multi-planar cases, egl_image_create() might fail on an
|
||||||
|
* intermediary step resulting in egl_image being NULL. In order to go
|
||||||
|
* over all successful ones, and avoid leaking one of them (the last
|
||||||
|
* one), we'll have to guard against it -- until we'll have a correct
|
||||||
|
* way of disposing of any previous created images.
|
||||||
|
*/
|
||||||
|
if (!image)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
gr = image->renderer;
|
||||||
assert(image->refcount > 0);
|
assert(image->refcount > 0);
|
||||||
|
|
||||||
image->refcount--;
|
image->refcount--;
|
||||||
@@ -2107,7 +2117,6 @@ gl_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer,
|
|||||||
egl_image_unref(gs->images[i]);
|
egl_image_unref(gs->images[i]);
|
||||||
gs->images[i] = NULL;
|
gs->images[i] = NULL;
|
||||||
}
|
}
|
||||||
gs->num_images = 0;
|
|
||||||
es->is_opaque = false;
|
es->is_opaque = false;
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case EGL_TEXTURE_RGB:
|
case EGL_TEXTURE_RGB:
|
||||||
@@ -2139,6 +2148,7 @@ gl_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gs->num_images = num_planes;
|
||||||
target = gl_shader_texture_variant_get_target(gs->shader_variant);
|
target = gl_shader_texture_variant_get_target(gs->shader_variant);
|
||||||
ensure_textures(gs, target, num_planes);
|
ensure_textures(gs, target, num_planes);
|
||||||
for (i = 0; i < num_planes; i++) {
|
for (i = 0; i < num_planes; i++) {
|
||||||
@@ -2153,7 +2163,6 @@ gl_renderer_attach_egl(struct weston_surface *es, struct weston_buffer *buffer,
|
|||||||
weston_log("failed to create img for plane %d\n", i);
|
weston_log("failed to create img for plane %d\n", i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
gs->num_images++;
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0 + i);
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
glBindTexture(target, gs->textures[i]);
|
glBindTexture(target, gs->textures[i]);
|
||||||
|
|||||||
Reference in New Issue
Block a user