[Mesa-dev] [PATCH 2/6] egl/dri: factor out egl_error_from_dri_image_error

Nicolai Hähnle nhaehnle at gmail.com
Fri Oct 6 20:16:04 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/egl/drivers/dri2/egl_dri2.c | 54 ++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 28 deletions(-)

diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 0db80a091f8..1407c96352e 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1840,20 +1840,43 @@ dri2_create_image_from_dri(_EGLDisplay *disp, __DRIimage *dri_image)
       return NULL;
    }
 
    _eglInitImage(&dri2_img->base, disp);
 
    dri2_img->dri_image = dri_image;
 
    return &dri2_img->base;
 }
 
+/**
+ * Translate a DRI Image extension error code into an EGL error code.
+ */
+static EGLint
+egl_error_from_dri_image_error(int dri_error)
+{
+   switch (dri_error) {
+   case __DRI_IMAGE_ERROR_SUCCESS:
+      return EGL_SUCCESS;
+   case __DRI_IMAGE_ERROR_BAD_ALLOC:
+      return EGL_BAD_ALLOC;
+   case __DRI_IMAGE_ERROR_BAD_MATCH:
+      return EGL_BAD_MATCH;
+   case __DRI_IMAGE_ERROR_BAD_PARAMETER:
+      return EGL_BAD_PARAMETER;
+   case __DRI_IMAGE_ERROR_BAD_ACCESS:
+      return EGL_BAD_ACCESS;
+   default:
+      assert(0);
+      return EGL_BAD_ALLOC;
+   }
+}
+
 static _EGLImage *
 dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx,
                                    EGLClientBuffer buffer,
                                    const EGLint *attr_list)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
    GLuint renderbuffer = (GLuint) (uintptr_t) buffer;
    __DRIimage *dri_image;
 
@@ -1942,49 +1965,24 @@ dri2_get_sync_values_chromium(_EGLDisplay *dpy, _EGLSurface *surf,
    return dri2_dpy->vtbl->get_sync_values(dpy, surf, ust, msc, sbc);
 }
 
 /**
  * Set the error code after a call to
  * dri2_egl_image::dri_image::createImageFromTexture.
  */
 static void
 dri2_create_image_khr_texture_error(int dri_error)
 {
-   EGLint egl_error;
-
-   switch (dri_error) {
-   case __DRI_IMAGE_ERROR_SUCCESS:
-      return;
-
-   case __DRI_IMAGE_ERROR_BAD_ALLOC:
-      egl_error = EGL_BAD_ALLOC;
-      break;
-
-   case __DRI_IMAGE_ERROR_BAD_MATCH:
-      egl_error = EGL_BAD_MATCH;
-      break;
-
-   case __DRI_IMAGE_ERROR_BAD_PARAMETER:
-      egl_error = EGL_BAD_PARAMETER;
-      break;
-
-   case __DRI_IMAGE_ERROR_BAD_ACCESS:
-      egl_error = EGL_BAD_ACCESS;
-      break;
-
-   default:
-      assert(0);
-      egl_error = EGL_BAD_MATCH;
-      break;
-   }
+   EGLint egl_error = egl_error_from_dri_image_error(dri_error);
 
-   _eglError(egl_error, "dri2_create_image_khr_texture");
+   if (egl_error != EGL_SUCCESS)
+      _eglError(egl_error, "dri2_create_image_khr_texture");
 }
 
 static _EGLImage *
 dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
                                    EGLenum target,
                                    EGLClientBuffer buffer,
                                    const EGLint *attr_list)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
-- 
2.11.0



More information about the mesa-dev mailing list