[Mesa-dev] [PATCH v2 3/3] egl_dri2: add new EGL_MESA_drm_image attributes.

Gwenole Beauchesne gb.devel at gmail.com
Fri Apr 27 06:40:53 PDT 2012


Add EGL_DRM_BUFFER_OFFSET_MESA to specify an offset (in bytes) relative
to the start of the DRM buffer. Likewise, add an EGL_DRM_BUFFER_PLANE_ID_MESA
attribute to specify (name) a plane identifier associated with the generated
image.

Add new image formats:
- EGL_DRM_BUFFER_FORMAT_R8_MESA: 8-bit red
- EGL_DRM_BUFFER_FORMAT_RG8_MESA: 8-bit red + green

Add picture structure information:
- EGL_DRM_BUFFER_STRUCTURE_TOP_FIELD: interlaced picture, top field
- EGL_DRM_BUFFER_STRUCTURE_BOTTOM_FIELD: interlaced picture, bottom field
- EGL_DRM_BUFFER_STRUCTURE_FRAME: whole picture
---
 docs/MESA_drm_image.spec        |   11 +++++++++++
 include/EGL/eglmesaext.h        |   26 ++++++++++++++++++++++++++
 src/egl/drivers/dri2/egl_dri2.c |   37 ++++++++++++++++++++++++++++++++-----
 src/egl/main/eglimage.c         |   10 ++++++++++
 src/egl/main/eglimage.h         |    3 +++
 5 files changed, 82 insertions(+), 5 deletions(-)

diff --git a/docs/MESA_drm_image.spec b/docs/MESA_drm_image.spec
index 1150a4c..a54476a 100644
--- a/docs/MESA_drm_image.spec
+++ b/docs/MESA_drm_image.spec
@@ -61,6 +61,8 @@ New Tokens
     Accepted as values for the EGL_IMAGE_FORMAT_MESA attribute:
 
         EGL_DRM_BUFFER_FORMAT_ARGB32_MESA	0x31D2
+        EGL_DRM_BUFFER_FORMAT_R8_MESA		0x8229
+        EGL_DRM_BUFFER_FORMAT_RG8_MESA		0x822B
 
     Bits accepted in EGL_DRM_BUFFER_USE_MESA:
 
@@ -76,6 +78,15 @@ New Tokens
 
         EGL_DRM_BUFFER_STRIDE_MESA		0x31D4
         EGL_DRM_BUFFER_FORMAT_MESA		0x31D0
+        EGL_DRM_BUFFER_PLANE_ID_MESA		0x31D5
+        EGL_DRM_BUFFER_OFFSET_MESA		0x31D6
+        EGL_DRM_BUFFER_STRUCTURE_MESA		0x31D7
+
+    Accepted as values for the EGL_DRM_BUFFER_STRUCTURE_MESA attribute:
+
+        EGL_DRM_BUFFER_STRUCTURE_TOP_FIELD	0x0001
+        EGL_DRM_BUFFER_STRUCTURE_BOTTOM_FIELD	0x0002
+        EGL_DRM_BUFFER_STRUCTURE_FRAME		0x0003
 
 Additions to the EGL 1.4 Specification:
 
diff --git a/include/EGL/eglmesaext.h b/include/EGL/eglmesaext.h
index 52dd5b1..202c3fc 100644
--- a/include/EGL/eglmesaext.h
+++ b/include/EGL/eglmesaext.h
@@ -104,6 +104,32 @@ typedef EGLDisplay (EGLAPIENTRYP PFNEGLGETDRMDISPLAYMESA) (int fd);
 
 #ifdef EGL_MESA_drm_image
 /* Mesa's extension to EGL_MESA_drm_image... */
+#ifndef EGL_DRM_BUFFER_PLANE_ID_MESA
+#define EGL_DRM_BUFFER_PLANE_ID_MESA		0x31D6
+#endif
+#ifndef EGL_DRM_BUFFER_OFFSET_MESA
+#define EGL_DRM_BUFFER_OFFSET_MESA		0x31D7
+#endif
+#ifndef EGL_DRM_BUFFER_STRUCTURE_MESA
+#define EGL_DRM_BUFFER_STRUCTURE_MESA		0x31D8
+#endif
+/* EGL_DRM_BUFFER_FORMAT_MESA attribute values */
+#ifndef EGL_DRM_BUFFER_FORMAT_R8_MESA
+#define EGL_DRM_BUFFER_FORMAT_R8_MESA		0x8229	/* 8-bit red */
+#endif
+#ifndef EGL_DRM_BUFFER_FORMAT_RG8_MESA
+#define EGL_DRM_BUFFER_FORMAT_RG8_MESA		0x822B	/* 8-bit red + green */
+#endif
+/* EGL_DRM_BUFFER_STRUCTURE_MESA attribute values */
+#ifndef EGL_DRM_BUFFER_STRUCTURE_TOP_FIELD
+#define EGL_DRM_BUFFER_STRUCTURE_TOP_FIELD	0x0001	/* Interlaced, top field */
+#endif
+#ifndef EGL_DRM_BUFFER_STRUCTURE_BOTTOM_FIELD
+#define EGL_DRM_BUFFER_STRUCTURE_BOTTOM_FIELD	0x0002	/* Interlaced, bottom field */
+#endif
+#ifndef EGL_DRM_BUFFER_STRUCTURE_FRAME
+#define EGL_DRM_BUFFER_STRUCTURE_FRAME		0x0003	/* Whole Picture */
+#endif
 #ifndef EGL_DRM_BUFFER_USE_CURSOR_MESA
 #define EGL_DRM_BUFFER_USE_CURSOR_MESA		0x0004
 #endif
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index c4d4f2f..755fb49 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1010,6 +1010,25 @@ dri2_invoke_create_image_from_name(struct dri2_egl_display *dpy,
                attrs->pitch, user_data);
 }
 
+static unsigned int
+dri2_image_get_picture_structure(uint32_t egl_picture_structure)
+{
+    unsigned int picture_structure;
+
+    switch (egl_picture_structure) {
+    case EGL_DRM_BUFFER_STRUCTURE_TOP_FIELD:
+        picture_structure = __DRI_IMAGE_STRUCTURE_TOP_FIELD;
+        break;
+    case EGL_DRM_BUFFER_STRUCTURE_BOTTOM_FIELD:
+        picture_structure = __DRI_IMAGE_STRUCTURE_BOTTOM_FIELD;
+        break;
+    default:
+        picture_structure = __DRI_IMAGE_STRUCTURE_FRAME;
+        break;
+    }
+    return picture_structure;
+}
+
 static _EGLImage *
 dri2_create_image_drm_name(_EGLDisplay *disp, _EGLContext *ctx,
 			   EGLint name,
@@ -1034,15 +1053,15 @@ dri2_create_image_drm_name(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
    }
 
-   imageAttrs.plane_id  = 0;
+   imageAttrs.plane_id  = attrs->PlaneId;
    imageAttrs.format    = format;
    imageAttrs.width     = attrs->Width;
    imageAttrs.height    = attrs->Height;
    imageAttrs.pitch     = pitch;
-   imageAttrs.structure = __DRI_IMAGE_STRUCTURE_FRAME;
+   imageAttrs.structure = dri2_image_get_picture_structure(attrs->DRMBufferStructureMESA);
    dri2_img->dri_image  = dri2_invoke_create_image_from_name(
        dri2_dpy,
-       name, 0,
+       name, attrs->DRMBufferOffsetMESA,
        &imageAttrs, dri2_img
    );
    if (dri2_img->dri_image == NULL) {
@@ -1067,9 +1086,10 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
 
    if (attrs.Width <= 0 || attrs.Height <= 0 ||
-       attrs.DRMBufferStrideMESA <= 0) {
+       attrs.DRMBufferStrideMESA <= 0 ||
+       attrs.DRMBufferOffsetMESA < 0) {
       _eglError(EGL_BAD_PARAMETER,
-		"bad width, height or stride");
+		"bad width, height, stride or offset");
       return NULL;
    }
 
@@ -1079,6 +1099,13 @@ dri2_create_image_mesa_drm_buffer(_EGLDisplay *disp, _EGLContext *ctx,
       format = __DRI_IMAGE_FORMAT_ARGB8888;
       pitch /= 4;
       break;
+   case EGL_DRM_BUFFER_FORMAT_R8_MESA:
+      format = __DRI_IMAGE_FORMAT_R8;
+      break;
+   case EGL_DRM_BUFFER_FORMAT_RG8_MESA:
+      format = __DRI_IMAGE_FORMAT_RG88;
+      pitch /= 2;
+      break;
    default:
       _eglError(EGL_BAD_PARAMETER,
 		"dri2_create_image_khr: unsupported pixmap depth");
diff --git a/src/egl/main/eglimage.c b/src/egl/main/eglimage.c
index 1174d0a..96d5bee 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->DRMBufferStructureMESA = EGL_DRM_BUFFER_STRUCTURE_FRAME;
 
    if (!attrib_list)
       return err;
@@ -87,6 +88,15 @@ _eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
       case EGL_DRM_BUFFER_STRIDE_MESA:
          attrs->DRMBufferStrideMESA = val;
          break;
+      case EGL_DRM_BUFFER_PLANE_ID_MESA:
+         attrs->PlaneId = val;
+         break;
+      case EGL_DRM_BUFFER_OFFSET_MESA:
+         attrs->DRMBufferOffsetMESA = val;
+         break;
+      case EGL_DRM_BUFFER_STRUCTURE_MESA:
+         attrs->DRMBufferStructureMESA = val;
+         break;
 
       default:
          /* unknown attrs are ignored */
diff --git a/src/egl/main/eglimage.h b/src/egl/main/eglimage.h
index acb36aa..646e499 100644
--- a/src/egl/main/eglimage.h
+++ b/src/egl/main/eglimage.h
@@ -47,9 +47,12 @@ struct _egl_image_attribs
    /* EGL_MESA_drm_image */
    EGLint Width;
    EGLint Height;
+   EGLint PlaneId;
    EGLint DRMBufferFormatMESA;
    EGLint DRMBufferUseMESA;
    EGLint DRMBufferStrideMESA;
+   EGLint DRMBufferOffsetMESA;
+   EGLint DRMBufferStructureMESA;
 };
 
 /**
-- 
1.7.5.4



More information about the mesa-dev mailing list