From be72a2ae7d14e57c423ce0885b153abf56eefca4 Mon Sep 17 00:00:00 2001
From: Jorgen Lind <jorgen.lind@digia.com>
Date: Thu, 2 Jan 2014 12:28:54 +0100
Subject: [PATCH] Add a EGL_DRM_BUFFER_FORMAT_A8_MESA

This is to allow us to share A8 DRM buffers between processes
---
 include/EGL/eglext.h                   | 1 +
 include/GL/internal/dri_interface.h    | 1 +
 src/egl/drivers/dri2/egl_dri2.c        | 7 +++++++
 src/mesa/drivers/dri/common/dri_util.c | 4 ++++
 4 files changed, 13 insertions(+)

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 1d68178..6c4fb7e 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -271,6 +271,7 @@ typedef EGLSurface (EGLAPIENTRYP PFNEGLCREATEPIXMAPSURFACEHIPROC) (EGLDisplay dp
 #define EGL_DRM_BUFFER_FORMAT_MESA		0x31D0	    /* CreateDRMImageMESA attribute */
 #define EGL_DRM_BUFFER_USE_MESA			0x31D1	    /* CreateDRMImageMESA attribute */
 #define EGL_DRM_BUFFER_FORMAT_ARGB32_MESA	0x31D2	    /* EGL_IMAGE_FORMAT_MESA attribute value */
+#define EGL_DRM_BUFFER_FORMAT_A8_MESA	        0x31D5	    /* EGL_IMAGE_FORMAT_MESA attribute value */
 #define EGL_DRM_BUFFER_MESA			0x31D3	    /* eglCreateImageKHR target */
 #define EGL_DRM_BUFFER_STRIDE_MESA		0x31D4
 #define EGL_DRM_BUFFER_USE_SCANOUT_MESA		0x00000001  /* EGL_DRM_BUFFER_USE_MESA bits */
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index b012570..c0ba605 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1015,6 +1015,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_XRGB2101010  0x1009
 #define __DRI_IMAGE_FORMAT_ARGB2101010  0x100a
 #define __DRI_IMAGE_FORMAT_SARGB8       0x100b
+#define __DRI_IMAGE_FORMAT_A8           0x100c
 
 #define __DRI_IMAGE_USE_SHARE		0x0001
 #define __DRI_IMAGE_USE_SCANOUT		0x0002
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index a64f4e8..a8253e1 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1185,6 +1185,10 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx,
       format = __DRI_IMAGE_FORMAT_ARGB8888;
       pitch = attrs.DRMBufferStrideMESA;
       break;
+   case EGL_DRM_BUFFER_FORMAT_A8_MESA:
+      format = __DRI_IMAGE_FORMAT_A8;
+      pitch = attrs.DRMBufferStrideMESA;
+      break;
    default:
       _eglError(EGL_BAD_PARAMETER,
 		"dri2_create_image_khr: unsupported pixmap depth");
@@ -1719,6 +1723,9 @@ dri2_create_drm_image_mesa(_EGLDriver *drv, _EGLDisplay *disp,
    case EGL_DRM_BUFFER_FORMAT_ARGB32_MESA:
       format = __DRI_IMAGE_FORMAT_ARGB8888;
       break;
+   case EGL_DRM_BUFFER_FORMAT_A8_MESA:
+      format = __DRI_IMAGE_FORMAT_A8;
+      break;
    default:
       _eglLog(_EGL_WARNING, "bad image format value 0x%04x",
             attrs.DRMBufferFormatMESA);
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index 9134a94..5fb55a2 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -831,6 +831,8 @@ driGLFormatToImageFormat(gl_format format)
       return __DRI_IMAGE_FORMAT_NONE;
    case MESA_FORMAT_SARGB8:
       return __DRI_IMAGE_FORMAT_SARGB8;
+   case MESA_FORMAT_A8:
+      return __DRI_IMAGE_FORMAT_A8;
    default:
       return 0;
    }
@@ -860,6 +862,8 @@ driImageFormatToGLFormat(uint32_t image_format)
       return MESA_FORMAT_GR88;
    case __DRI_IMAGE_FORMAT_SARGB8:
       return MESA_FORMAT_SARGB8;
+   case __DRI_IMAGE_FORMAT_A8:
+      return MESA_FORMAT_A8;
    case __DRI_IMAGE_FORMAT_NONE:
       return MESA_FORMAT_NONE;
    default:
-- 
1.8.5.2

