From 52dbed7516b79459d1c8f2ed3ea4a5e71734c969 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/i915/intel_screen.c | 5 +++++
 src/mesa/drivers/dri/i965/intel_screen.c | 5 +++++
 5 files changed, 19 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 5c99d55..565f1fb 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -964,6 +964,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_R8           0x1006 /* Since version 5 */
 #define __DRI_IMAGE_FORMAT_GR88         0x1007
 #define __DRI_IMAGE_FORMAT_NONE         0x1008
+#define __DRI_IMAGE_FORMAT_A8           0x1009 /* Patch */
 
 #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 a8584b7..1cb6967 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1152,6 +1152,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");
@@ -1427,6 +1431,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/i915/intel_screen.c b/src/mesa/drivers/dri/i915/intel_screen.c
index 30a867e..3e1909b 100644
--- a/src/mesa/drivers/dri/i915/intel_screen.c
+++ b/src/mesa/drivers/dri/i915/intel_screen.c
@@ -261,6 +261,9 @@ intel_allocate_image(int dri_format, void *loaderPrivate)
     case __DRI_IMAGE_FORMAT_R8:
        image->format = MESA_FORMAT_R8;
        break;
+    case __DRI_IMAGE_FORMAT_A8:
+       image->format = MESA_FORMAT_A8;
+       break;
     case __DRI_IMAGE_FORMAT_GR88:
        image->format = MESA_FORMAT_GR88;
        break;
@@ -330,6 +333,8 @@ intel_dri_format(GLuint format)
       return __DRI_IMAGE_FORMAT_ABGR8888;
    case MESA_FORMAT_R8:
       return __DRI_IMAGE_FORMAT_R8;
+   case MESA_FORMAT_A8:
+      return __DRI_IMAGE_FORMAT_A8;
    case MESA_FORMAT_RG88:
       return __DRI_IMAGE_FORMAT_GR88;
    }
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index f913c42..68ee33b 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -262,6 +262,9 @@ intel_allocate_image(int dri_format, void *loaderPrivate)
     case __DRI_IMAGE_FORMAT_R8:
        image->format = MESA_FORMAT_R8;
        break;
+    case __DRI_IMAGE_FORMAT_A8:
+       image->format = MESA_FORMAT_A8;
+       break;
     case __DRI_IMAGE_FORMAT_GR88:
        image->format = MESA_FORMAT_GR88;
        break;
@@ -334,6 +337,8 @@ intel_dri_format(GLuint format)
       return __DRI_IMAGE_FORMAT_ABGR8888;
    case MESA_FORMAT_R8:
       return __DRI_IMAGE_FORMAT_R8;
+   case MESA_FORMAT_A8:
+      return __DRI_IMAGE_FORMAT_A8;
    case MESA_FORMAT_RG88:
       return __DRI_IMAGE_FORMAT_GR88;
    }
-- 
1.8.5.1

