[Mesa-dev] [PATCH v2 4/5] egl: Add MESA_image_sRGB extension.

John Kåre Alsaker john.kare.alsaker at gmail.com
Sat Mar 2 22:03:41 PST 2013


This gives applications access to use DRIimage.duplicateImage to create
sRGB and linear views from EGL images.
---
 include/EGL/eglmesaext.h                |   7 ++
 src/egl/drivers/dri2/egl_dri2.c         | 168 ++++++++++++++++++++------------
 src/egl/drivers/dri2/egl_dri2.h         |   6 +-
 src/egl/drivers/dri2/platform_android.c |  36 +++----
 src/egl/drivers/dri2/platform_drm.c     |  36 +++----
 src/egl/drivers/dri2/platform_x11.c     |  37 +++----
 src/egl/main/eglcurrent.c               |   3 +
 src/egl/main/egldisplay.h               |   1 +
 src/egl/main/eglimage.c                 |   6 ++
 src/egl/main/eglimage.h                 |   3 +
 src/egl/main/eglmisc.c                  |   1 +
 11 files changed, 173 insertions(+), 131 deletions(-)

diff --git a/include/EGL/eglmesaext.h b/include/EGL/eglmesaext.h
index d476d18..59f903a 100644
--- a/include/EGL/eglmesaext.h
+++ b/include/EGL/eglmesaext.h
@@ -109,6 +109,13 @@ typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETDRMDISPLAYMESA) (int fd);
 #endif
 #endif
 
+#ifndef EGL_MESA_image_sRGB
+#define EGL_MESA_image_sRGB 1
+#define EGL_GAMMA_MESA 0x3290 /* eglCreateImageKHR attribute */
+#define EGL_DEFAULT_MESA 0x3291
+#define EGL_BAD_VIEW_MESA 0x3292
+#endif
+
 #ifndef EGL_WL_bind_wayland_display
 #define EGL_WL_bind_wayland_display 1
 
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index b774919..9e0658f 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -507,6 +507,10 @@ dri2_setup_screen(_EGLDisplay *disp)
          disp->Extensions.KHR_gl_texture_2D_image = EGL_TRUE;
          disp->Extensions.KHR_gl_texture_cubemap_image = EGL_TRUE;
       }
+      if (dri2_dpy->image->base.version >= 7 &&
+          dri2_dpy->image->duplicateImage) {
+         disp->Extensions.MESA_image_sRGB = EGL_TRUE;
+      }
    }
 }
 
@@ -1077,9 +1081,52 @@ dri2_release_tex_image(_EGLDriver *drv,
    return EGL_TRUE;
 }
 
-static _EGLImage *
-dri2_create_image(_EGLDisplay *disp, __DRIimage *dri_image)
+static EGLBoolean
+dri2_process_dri_image(_EGLDisplay *disp, __DRIimage **dri_image,
+                  const _EGLImageAttribs *attrs)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+   __DRIimage *result;
+
+   if (attrs->GammaMESA == EGL_DEFAULT_MESA) {
+      return EGL_TRUE;
+   }
+
+   if(!disp->Extensions.MESA_image_sRGB) {
+      goto bad_view;
+   }
+
+   if (attrs->GammaMESA != EGL_COLORSPACE_sRGB &&
+       attrs->GammaMESA != EGL_COLORSPACE_LINEAR) {
+      goto bad_view;
+   }
+
+   result = dri2_dpy->image->duplicateImage(dri2_dpy->dri_screen,
+                  *dri_image,
+                  attrs->GammaMESA == EGL_COLORSPACE_sRGB ?
+                     __DRI_IMAGE_FLAG_SRGB_VIEW :
+                     __DRI_IMAGE_FLAG_LINEAR_VIEW, NULL);
+
+   if (result == NULL) {
+      goto bad_view;
+   }
+
+   dri2_dpy->image->destroyImage(*dri_image);
+
+   *dri_image = result;
+
+   return EGL_TRUE;
+
+bad_view:
+   _eglError(EGL_BAD_VIEW_MESA, "dri2_create_image");
+   return EGL_FALSE;
+}
+
+_EGLImage *
+dri2_create_image(_EGLDisplay *disp, __DRIimage *dri_image,
+                  const _EGLImageAttribs *attrs)
 {
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_image *dri2_img;
 
    if (dri_image == NULL) {
@@ -1087,26 +1134,35 @@ dri2_create_image(_EGLDisplay *disp, __DRIimage *dri_image)
       return NULL;
    }
 
+   if (!dri2_process_dri_image(disp, &dri_image, attrs)) {
+      goto error;
+   }
+
    dri2_img = malloc(sizeof *dri2_img);
    if (!dri2_img) {
       _eglError(EGL_BAD_ALLOC, "dri2_create_image");
-      return NULL;
+      goto error;
    }
 
    if (!_eglInitImage(&dri2_img->base, disp)) {
+      _eglError(EGL_BAD_ALLOC, "dri2_create_image");
       free(dri2_img);
-      return NULL;
+      goto error;
    }
 
    dri2_img->dri_image = dri_image;
 
    return &dri2_img->base;
+
+error:
+   dri2_dpy->image->destroyImage(dri_image);
+   return NULL;
 }
 
 static _EGLImage *
 dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx,
 				   EGLClientBuffer buffer,
-				   const EGLint *attr_list)
+				   const _EGLImageAttribs *attrs)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
@@ -1122,35 +1178,31 @@ dri2_create_image_khr_renderbuffer(_EGLDisplay *disp, _EGLContext *ctx,
       dri2_dpy->image->createImageFromRenderbuffer(dri2_ctx->dri_context,
                                                    renderbuffer, NULL);
 
-   return dri2_create_image(disp, dri_image);
+   return dri2_create_image(disp, dri_image, attrs);
 }
 
 static _EGLImage *
 dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx,
-				  EGLClientBuffer buffer, const EGLint *attr_list)
+				  EGLClientBuffer buffer,
+				  const _EGLImageAttribs *attrs)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
-   EGLint format, name, pitch, err;
-   _EGLImageAttribs attrs;
+   EGLint format, name, pitch;
    __DRIimage *dri_image;
 
    name = (EGLint) (uintptr_t) buffer;
 
-   err = _eglParseImageAttribList(&attrs, disp, attr_list);
-   if (err != EGL_SUCCESS)
-      return NULL;
-
-   if (attrs.Width <= 0 || attrs.Height <= 0 ||
-       attrs.DRMBufferStrideMESA <= 0) {
+   if (attrs->Width <= 0 || attrs->Height <= 0 ||
+       attrs->DRMBufferStrideMESA <= 0) {
       _eglError(EGL_BAD_PARAMETER,
 		"bad width, height or stride");
       return NULL;
    }
 
-   switch (attrs.DRMBufferFormatMESA) {
+   switch (attrs->DRMBufferFormatMESA) {
    case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA:
       format = __DRI_IMAGE_FORMAT_ARGB8888;
-      pitch = attrs.DRMBufferStrideMESA;
+      pitch = attrs->DRMBufferStrideMESA;
       break;
    default:
       _eglError(EGL_BAD_PARAMETER,
@@ -1160,14 +1212,14 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx,
 
    dri_image =
       dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
-					   attrs.Width,
-					   attrs.Height,
+					   attrs->Width,
+					   attrs->Height,
 					   format,
 					   name,
 					   pitch,
 					   NULL);
 
-   return dri2_create_image(disp, dri_image);
+   return dri2_create_image(disp, dri_image, attrs);
 }
 
 #ifdef HAVE_WAYLAND_PLATFORM
@@ -1193,26 +1245,18 @@ static const struct wl_drm_components_descriptor {
 static _EGLImage *
 dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx,
 				    EGLClientBuffer _buffer,
-				    const EGLint *attr_list)
+				    const _EGLImageAttribs *attrs)
 {
    struct wl_drm_buffer *buffer = (struct wl_drm_buffer *) _buffer;
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    const struct wl_drm_components_descriptor *f;
    __DRIimage *dri_image;
-   _EGLImageAttribs attrs;
-   EGLint err;
    int32_t plane;
 
    if (!wayland_buffer_is_drm(&buffer->buffer))
        return NULL;
 
-   err = _eglParseImageAttribList(&attrs, disp, attr_list);
-   plane = attrs.PlaneWL;
-   if (err != EGL_SUCCESS) {
-      _eglError(EGL_BAD_PARAMETER, "dri2_create_image_wayland_wl_buffer");
-      return NULL;
-   }
-
+   plane = attrs->PlaneWL;
    f = buffer->driver_format;
    if (plane < 0 || plane >= f->nplanes) {
       _eglError(EGL_BAD_PARAMETER,
@@ -1227,7 +1271,7 @@ dri2_create_image_wayland_wl_buffer(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
    }
 
-   return dri2_create_image(disp, dri_image);
+   return dri2_create_image(disp, dri_image, attrs);
 }
 #endif
 
@@ -1269,13 +1313,12 @@ static _EGLImage *
 dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
 				   EGLenum target,
 				   EGLClientBuffer buffer,
-				   const EGLint *attr_list)
+				   const _EGLImageAttribs *attrs)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
-   struct dri2_egl_image *dri2_img;
+   __DRIimage *dri_image;
    GLuint texture = (GLuint) (uintptr_t) buffer;
-   _EGLImageAttribs attrs;
    GLuint depth;
    GLenum gl_target;
    unsigned error;
@@ -1285,16 +1328,13 @@ dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
       return EGL_NO_IMAGE_KHR;
    }
 
-   if (_eglParseImageAttribList(&attrs, disp, attr_list) != EGL_SUCCESS)
-      return EGL_NO_IMAGE_KHR;
-
    switch (target) {
    case EGL_GL_TEXTURE_2D_KHR:
       depth = 0;
       gl_target = GL_TEXTURE_2D;
       break;
    case EGL_GL_TEXTURE_3D_KHR:
-      depth = attrs.GLTextureZOffset;
+      depth = attrs->GLTextureZOffset;
       gl_target = GL_TEXTURE_3D;
       break;
    case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR:
@@ -1311,39 +1351,23 @@ dri2_create_image_khr_texture(_EGLDisplay *disp, _EGLContext *ctx,
       return EGL_NO_IMAGE_KHR;
    }
 
-   dri2_img = malloc(sizeof *dri2_img);
-   if (!dri2_img) {
-      _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr");
-      return EGL_NO_IMAGE_KHR;
-   }
-
-   if (!_eglInitImage(&dri2_img->base, disp)) {
-      _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr");
-      free(dri2_img);
-      return EGL_NO_IMAGE_KHR;
-   }
-
-   dri2_img->dri_image =
+   dri_image =
       dri2_dpy->image->createImageFromTexture(dri2_ctx->dri_context,
                                               gl_target,
                                               texture,
                                               depth,
-                                              attrs.GLTextureLevel,
+                                              attrs->GLTextureLevel,
                                               &error,
-                                              dri2_img);
+                                              NULL);
    dri2_create_image_khr_texture_error(error);
 
-   if (!dri2_img->dri_image) {
-      free(dri2_img);
-      return EGL_NO_IMAGE_KHR;
-   }
-   return &dri2_img->base;
+   return dri2_create_image(disp, dri_image, attrs);
 }
 
 _EGLImage *
 dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
 		      _EGLContext *ctx, EGLenum target,
-		      EGLClientBuffer buffer, const EGLint *attr_list)
+		      EGLClientBuffer buffer, const _EGLImageAttribs *attrs)
 {
    (void) drv;
 
@@ -1355,14 +1379,14 @@ dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
    case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_KHR:
    case EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_Z_KHR:
    case EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR:
-      return dri2_create_image_khr_texture(disp, ctx, target, buffer, attr_list);
+      return dri2_create_image_khr_texture(disp, ctx, target, buffer, attrs);
    case EGL_GL_RENDERBUFFER_KHR:
-      return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attr_list);
+      return dri2_create_image_khr_renderbuffer(disp, ctx, buffer, attrs);
    case EGL_DRM_BUFFER_MESA:
-      return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attr_list);
+      return dri2_create_image_mesa_drm_buffer(disp, ctx, buffer, attrs);
 #ifdef HAVE_WAYLAND_PLATFORM
    case EGL_WAYLAND_BUFFER_WL:
-      return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attr_list);
+      return dri2_create_image_wayland_wl_buffer(disp, ctx, buffer, attrs);
 #endif
    default:
       _eglError(EGL_BAD_PARAMETER, "dri2_create_image_khr");
@@ -1370,6 +1394,22 @@ dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
    }
 }
 
+static _EGLImage *
+dri2_create_image_khr_default(_EGLDriver *drv, _EGLDisplay *disp,
+                          _EGLContext *ctx, EGLenum target,
+                          EGLClientBuffer buffer, const EGLint *attr_list)
+{
+   EGLint err;
+   _EGLImageAttribs attrs;
+
+   err = _eglParseImageAttribList(&attrs, disp, attr_list);
+   if (err != EGL_SUCCESS) {
+      return NULL;
+   }
+
+   return dri2_create_image_khr(drv, disp, ctx, target, buffer, &attrs);
+}
+
 static EGLBoolean
 dri2_destroy_image_khr(_EGLDriver *drv, _EGLDisplay *disp, _EGLImage *image)
 {
@@ -1700,7 +1740,7 @@ _eglBuiltInDriverDRI2(const char *args)
    dri2_drv->base.API.WaitNative = dri2_wait_native;
    dri2_drv->base.API.BindTexImage = dri2_bind_tex_image;
    dri2_drv->base.API.ReleaseTexImage = dri2_release_tex_image;
-   dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr;
+   dri2_drv->base.API.CreateImageKHR = dri2_create_image_khr_default;
    dri2_drv->base.API.DestroyImageKHR = dri2_destroy_image_khr;
    dri2_drv->base.API.CreateDRMImageMESA = dri2_create_drm_image_mesa;
    dri2_drv->base.API.ExportDRMImageMESA = dri2_export_drm_image_mesa;
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 84ea2a6..87e8ade 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -249,9 +249,13 @@ dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
 		const unsigned int *rgba_masks);
 
 _EGLImage *
+dri2_create_image(_EGLDisplay *disp, __DRIimage *dri_image,
+                  const _EGLImageAttribs *attrs);
+
+_EGLImage *
 dri2_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
 		      _EGLContext *ctx, EGLenum target,
-		      EGLClientBuffer buffer, const EGLint *attr_list);
+		      EGLClientBuffer buffer, const _EGLImageAttribs *attrs);
 
 EGLBoolean
 dri2_initialize_x11(_EGLDriver *drv, _EGLDisplay *disp);
diff --git a/src/egl/drivers/dri2/platform_android.c b/src/egl/drivers/dri2/platform_android.c
index 3432f18..c3222f2 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -335,10 +335,11 @@ droid_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
 
 static _EGLImage *
 dri2_create_image_android_native_buffer(_EGLDisplay *disp,
-                                        struct ANativeWindowBuffer *buf)
+                                        struct ANativeWindowBuffer *buf,
+                                        const _EGLImageAttribs *attrs)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
-   struct dri2_egl_image *dri2_img;
+   __DRIimage *dri_image;
    int name;
    EGLint format;
 
@@ -378,18 +379,7 @@ dri2_create_image_android_native_buffer(_EGLDisplay *disp,
       break;
    }
 
-   dri2_img = calloc(1, sizeof(*dri2_img));
-   if (!dri2_img) {
-      _eglError(EGL_BAD_ALLOC, "droid_create_image_mesa_drm");
-      return NULL;
-   }
-
-   if (!_eglInitImage(&dri2_img->base, disp)) {
-      free(dri2_img);
-      return NULL;
-   }
-
-   dri2_img->dri_image =
+   dri_image =
       dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
 					   buf->width,
 					   buf->height,
@@ -397,13 +387,8 @@ dri2_create_image_android_native_buffer(_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;
+   return dri2_create_image(disp, dri_image, attrs);
 }
 
 static _EGLImage *
@@ -411,12 +396,19 @@ droid_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
 		       _EGLContext *ctx, EGLenum target,
 		       EGLClientBuffer buffer, const EGLint *attr_list)
 {
+   EGLint err;
+   _EGLImageAttribs attrs;
+
+   err = _eglParseImageAttribList(&attrs, disp, attr_list);
+   if (err != EGL_SUCCESS)
+      return NULL;
+
    switch (target) {
    case EGL_NATIVE_BUFFER_ANDROID:
       return dri2_create_image_android_native_buffer(disp,
-            (struct ANativeWindowBuffer *) buffer);
+            (struct ANativeWindowBuffer *) buffer, &attrs);
    default:
-      return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list);
+      return dri2_create_image_khr(drv, disp, ctx, target, buffer, &attrs);
    }
 }
 
diff --git a/src/egl/drivers/dri2/platform_drm.c b/src/egl/drivers/dri2/platform_drm.c
index 615648b..02c57ac 100644
--- a/src/egl/drivers/dri2/platform_drm.c
+++ b/src/egl/drivers/dri2/platform_drm.c
@@ -360,31 +360,16 @@ dri2_query_buffer_age(_EGLDriver *drv,
 
 static _EGLImage *
 dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
-			     EGLClientBuffer buffer, const EGLint *attr_list)
+			     EGLClientBuffer buffer,
+			     const _EGLImageAttribs *attrs)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct gbm_dri_bo *dri_bo = gbm_dri_bo((struct gbm_bo *) buffer);
-   struct dri2_egl_image *dri2_img;
+   __DRIimage *dri_image;
 
-   dri2_img = malloc(sizeof *dri2_img);
-   if (!dri2_img) {
-      _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap");
-      return NULL;
-   }
-
-   if (!_eglInitImage(&dri2_img->base, disp)) {
-      free(dri2_img);
-      return NULL;
-   }
+   dri_image = dri2_dpy->image->dupImage(dri_bo->image, NULL);
 
-   dri2_img->dri_image = dri2_dpy->image->dupImage(dri_bo->image, dri2_img);
-   if (dri2_img->dri_image == NULL) {
-      free(dri2_img);
-      _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr_pixmap");
-      return NULL;
-   }
-
-   return &dri2_img->base;
+   return dri2_create_image(disp, dri_image, attrs);
 }
 
 static _EGLImage *
@@ -392,13 +377,20 @@ dri2_drm_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
                           _EGLContext *ctx, EGLenum target,
                           EGLClientBuffer buffer, const EGLint *attr_list)
 {
+   EGLint err;
+   _EGLImageAttribs attrs;
+
    (void) drv;
 
+   err = _eglParseImageAttribList(&attrs, disp, attr_list);
+   if (err != EGL_SUCCESS)
+      return NULL;
+
    switch (target) {
    case EGL_NATIVE_PIXMAP_KHR:
-      return dri2_create_image_khr_pixmap(disp, ctx, buffer, attr_list);
+      return dri2_create_image_khr_pixmap(disp, ctx, buffer, &attrs);
    default:
-      return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list);
+      return dri2_create_image_khr(drv, disp, ctx, target, buffer, &attrs);
    }
 }
 
diff --git a/src/egl/drivers/dri2/platform_x11.c b/src/egl/drivers/dri2/platform_x11.c
index da61cfc..9e97ac7 100644
--- a/src/egl/drivers/dri2/platform_x11.c
+++ b/src/egl/drivers/dri2/platform_x11.c
@@ -851,10 +851,11 @@ dri2_copy_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf,
 
 static _EGLImage *
 dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
-			     EGLClientBuffer buffer, const EGLint *attr_list)
+			     EGLClientBuffer buffer,
+			     const _EGLImageAttribs *attrs)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
-   struct dri2_egl_image *dri2_img;
+   __DRIimage *dri_image;
    unsigned int attachments[1];
    xcb_drawable_t drawable;
    xcb_dri2_get_buffers_cookie_t buffers_cookie;
@@ -908,35 +909,20 @@ dri2_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
    }
 
-   dri2_img = malloc(sizeof *dri2_img);
-   if (!dri2_img) {
-      free(buffers_reply);
-      free(geometry_reply);
-      _eglError(EGL_BAD_ALLOC, "dri2_create_image_khr");
-      return EGL_NO_IMAGE_KHR;
-   }
-
-   if (!_eglInitImage(&dri2_img->base, disp)) {
-      free(buffers_reply);
-      free(geometry_reply);
-      free(dri2_img);
-      return EGL_NO_IMAGE_KHR;
-   }
-
    stride = buffers[0].pitch / buffers[0].cpp;
-   dri2_img->dri_image =
+   dri_image =
       dri2_dpy->image->createImageFromName(dri2_dpy->dri_screen,
 					   buffers_reply->width,
 					   buffers_reply->height,
 					   format,
 					   buffers[0].name,
 					   stride,
-					   dri2_img);
+					   NULL);
 
    free(buffers_reply);
    free(geometry_reply);
 
-   return &dri2_img->base;
+   return dri2_create_image(disp, dri_image, attrs);
 }
 
 static _EGLImage *
@@ -944,13 +930,20 @@ dri2_x11_create_image_khr(_EGLDriver *drv, _EGLDisplay *disp,
 			  _EGLContext *ctx, EGLenum target,
 			  EGLClientBuffer buffer, const EGLint *attr_list)
 {
+   EGLint err;
+   _EGLImageAttribs attrs;
+
    (void) drv;
 
+   err = _eglParseImageAttribList(&attrs, disp, attr_list);
+   if (err != EGL_SUCCESS)
+      return NULL;
+
    switch (target) {
    case EGL_NATIVE_PIXMAP_KHR:
-      return dri2_create_image_khr_pixmap(disp, ctx, buffer, attr_list);
+      return dri2_create_image_khr_pixmap(disp, ctx, buffer, &attrs);
    default:
-      return dri2_create_image_khr(drv, disp, ctx, target, buffer, attr_list);
+      return dri2_create_image_khr(drv, disp, ctx, target, buffer, &attrs);
    }
 }
 
diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c
index 5b09a48..dcdffe3 100644
--- a/src/egl/main/eglcurrent.c
+++ b/src/egl/main/eglcurrent.c
@@ -325,6 +325,9 @@ _eglError(EGLint errCode, const char *msg)
          s = "EGL_BAD_MODE_MESA";
          break;
 #endif
+      case EGL_BAD_VIEW_MESA:
+         s = "EGL_BAD_VIEW_MESA";
+         break;
       default:
          s = "other EGL error";
       }
diff --git a/src/egl/main/egldisplay.h b/src/egl/main/egldisplay.h
index 4b33470..8ecd5d8 100644
--- a/src/egl/main/egldisplay.h
+++ b/src/egl/main/egldisplay.h
@@ -89,6 +89,7 @@ struct _egl_extensions
    EGLBoolean MESA_copy_context;
    EGLBoolean MESA_drm_display;
    EGLBoolean MESA_drm_image;
+   EGLBoolean MESA_image_sRGB;
 
    EGLBoolean WL_bind_wayland_display;
 
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index bfae709..1119947 100644
--- a/src/egl/main/eglimage.c
+++ b/src/egl/main/eglimage.c
@@ -49,6 +49,7 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
    attrs->ImagePreserved = EGL_FALSE;
    attrs->GLTextureLevel = 0;
    attrs->GLTextureZOffset = 0;
+   attrs->GammaMESA = EGL_DEFAULT_MESA;
 
    if (!attrib_list)
       return err;
@@ -88,6 +89,11 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
          attrs->DRMBufferStrideMESA = val;
          break;
 
+      /* EGL_MESA_image_sRGB */
+      case EGL_GAMMA_MESA:
+         attrs->GammaMESA = val;
+         break;
+
       /* EGL_WL_bind_wayland_display */
       case EGL_WAYLAND_PLANE_WL:
          attrs->PlaneWL = val;
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index 9cc86d5..4c500d0 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -53,6 +53,9 @@ struct _egl_image_attribs
 
    /* EGL_WL_bind_wayland_display */
    EGLint PlaneWL;
+
+   /* EGL_MESA_image_sRGB */
+   EGLint GammaMESA;
 };
 
 /**
diff --git a/src/egl/main/eglmisc.c b/src/egl/main/eglmisc.c
index 92b0eae..f2cc2e3 100644
--- a/src/egl/main/eglmisc.c
+++ b/src/egl/main/eglmisc.c
@@ -90,6 +90,7 @@ _eglUpdateExtensionsString(_EGLDisplay *dpy)
    _EGL_CHECK_EXTENSION(MESA_copy_context);
    _EGL_CHECK_EXTENSION(MESA_drm_display);
    _EGL_CHECK_EXTENSION(MESA_drm_image);
+   _EGL_CHECK_EXTENSION(MESA_image_sRGB);
 
    _EGL_CHECK_EXTENSION(WL_bind_wayland_display);
 
-- 
1.8.1.4



More information about the mesa-dev mailing list