dri: fromPlanar() can return NULL as a valid result
authorLouis-Francis Ratté-Boulianne <lfrb@collabora.com>
Thu, 28 Sep 2017 07:18:33 +0000 (03:18 -0400)
committerDaniel Stone <daniels@collabora.com>
Thu, 15 Feb 2018 11:58:17 +0000 (11:58 +0000)
It was assumed that fromPlanar() could return NULL to mean
that the planar image is the same as the parent DRI image.
That assumption wasn't made everywhere though.

Let's fix things and make sure that all callers understand
a NULL result

Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Reviewed-by: Daniel Stone <daniels@collabora.com>
src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/platform_wayland.c
src/gbm/backends/dri/gbm_dri.c
src/loader/loader_dri3_helper.c

index e9b556ec5f7ac77b27ef5f61de8171ef019fe0b3..17b646e7ede6c907074a4fad232f4f90cf52202a 100644 (file)
@@ -1966,7 +1966,8 @@ dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx,
    }
 
    dri_image = dri2_dpy->image->fromPlanar(buffer->driver_buffer, plane, NULL);
-
+   if (dri_image == NULL && plane == 0)
+      dri_image = dri2_dpy->image->dupImage(buffer->driver_buffer, NULL);
    if (dri_image == NULL) {
       _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer");
       return NULL;
index f91baded8776b2733a890ed40ae2698902fa70d6..5b8bec901b076799ee6e762ac5c31b178acfe41d 100644 (file)
@@ -814,13 +814,10 @@ create_wl_buffer(struct dri2_egl_display *dri2_dpy,
          int stride, offset;
          int fd = -1;
 
-         if (i == 0)
-            p_image = image;
-         else
-            p_image = dri2_dpy->image->fromPlanar(image, i, NULL);
+         p_image = dri2_dpy->image->fromPlanar(image, i, NULL);
          if (!p_image) {
-            zwp_linux_buffer_params_v1_destroy(params);
-            return NULL;
+            assert(i == 0);
+            p_image = image;
          }
 
          query = dri2_dpy->image->queryImage(p_image,
index 0d088bd62b629b543ee15f80ecff881c6077df4e..ed64ad61bf026a9107e0e1e118303a222a8b6923 100644 (file)
@@ -849,6 +849,7 @@ gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
       dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_OFFSET, &offset);
       dri->image->destroyImage(image);
    } else {
+      assert(plane == 0);
       dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_OFFSET, &offset);
    }
 
index fbda3d635c75e4a3fc6e928a9885494b0b1267f1..2912bb6749b76a916da40af616cf5eb1643d67e4 100644 (file)
@@ -1288,7 +1288,10 @@ loader_dri3_create_image(xcb_connection_t *c,
 
    ret = image->fromPlanar(image_planar, 0, loaderPrivate);
 
-   image->destroyImage(image_planar);
+   if (!ret)
+      ret = image_planar;
+   else
+      image->destroyImage(image_planar);
 
    return ret;
 }