egl/android: Simplify droid_create_image_from_name() path
authorKristian H. Kristensen <hoegsberg@google.com>
Fri, 7 Aug 2020 00:39:47 +0000 (17:39 -0700)
committerMarge Bot <eric+marge@anholt.net>
Tue, 18 Aug 2020 17:20:16 +0000 (17:20 +0000)
This can now return an __DRIimage which we'll wrap in the shared code
in dri2_create_image_android_native_buffer().

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6055>

src/egl/drivers/dri2/platform_android.c

index f12ac4f6302b2993f11d51518ef22f05e841b4e8..dad942abb7257b84dc6c41f7386ef979a646771a 100644 (file)
@@ -941,7 +941,7 @@ droid_create_image_from_name(_EGLDisplay *disp,
                              struct ANativeWindowBuffer *buf)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
-   struct dri2_egl_image *dri2_img;
+   __DRIimage *dri_image;
    int name;
    int format;
 
@@ -955,15 +955,7 @@ droid_create_image_from_name(_EGLDisplay *disp,
    if (format == -1)
        return NULL;
 
-   dri2_img = calloc(1, sizeof(*dri2_img));
-   if (!dri2_img) {
-      _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
-      return NULL;
-   }
-
-   _eglInitImage(&dri2_img->base, disp);
-
-   dri2_img->dri_image =
+   return
       dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
                                           buf->width,
                                           buf->height,
@@ -971,13 +963,6 @@ droid_create_image_from_name(_EGLDisplay *disp,
                                           name,
                                           buf->stride,
                                           dri2_img);
-   if (!dri2_img->dri_image) {
-      free(dri2_img);
-      _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
-      return NULL;
-   }
-
-   return &dri2_img->base;
 }
 #endif /* HAVE_DRM_GRALLOC */
 
@@ -1032,14 +1017,16 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp,
 
    __DRIimage *dri_image =
       droid_create_image_from_prime_fds(disp, buf);
+
+#ifdef HAVE_DRM_GRALLOC
+   if (dri_image == NULL)
+      dri_image = droid_create_image_from_name(disp, buf);
+#endif
+
    if (dri_image)
       return dri2_create_image_from_dri(disp, dri_image);
 
-#ifdef HAVE_DRM_GRALLOC
-   return droid_create_image_from_name(disp, buf);
-#else
    return NULL;
-#endif
 }
 
 static _EGLImage *