[Mesa-dev] [PATCH v2 2/4] EGL: Implement the new extension MESA_EGL_extension_sharing.

Zhigang Gong zhigang.gong at linux.intel.com
Tue Jul 16 01:04:18 PDT 2013


OpenCL has some extension can create CL memory object from GL
textures/buffer objects/render buffers. The existing extension
can't satisfied this requirement. As we need to pass the resource
handler directly to the dri driver layer and get some low level
information back which may include the low level buffer object
handler/name, the internal color format and the layout and tiling
information. Then the external library, say Open CL's driver module,
could use this information to create an shared CL memory object.

As Open CL defines a strict usage model of GL-CL interoperations,
it simplfy the requirement of this extension. We just need to provide
two functions,
1. The acquireResource method to get those information and increase
the underlying reference counter of the buffer object at dri driver layer.
2. The releaseResource method to decrease the underlying reference counter
at dri driver layer.

Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
 include/EGL/eglext.h                |   19 ++++
 include/GL/internal/dri_interface.h |   19 ++++
 src/egl/drivers/dri2/egl_dri2.c     |  167 +++++++++++++++++++++++++++++++++++
 src/egl/drivers/dri2/egl_dri2.h     |    2 +
 src/egl/main/Makefile.am            |    4 +-
 src/egl/main/eglapi.c               |   33 +++++++
 src/egl/main/eglapi.h               |    9 ++
 src/egl/main/eglresshare.c          |  139 +++++++++++++++++++++++++++++
 src/egl/main/eglresshare.h          |   47 ++++++++++
 9 files changed, 438 insertions(+), 1 deletion(-)
 create mode 100644 src/egl/main/eglresshare.c
 create mode 100644 src/egl/main/eglresshare.h

diff --git a/include/EGL/eglext.h b/include/EGL/eglext.h
index 1d68178..74040bc 100644
--- a/include/EGL/eglext.h
+++ b/include/EGL/eglext.h
@@ -283,6 +283,25 @@ typedef EGLImageKHR (EGLAPIENTRYP PFNEGLCREATEDRMIMAGEMESAPROC) (EGLDisplay dpy,
 typedef EGLBoolean (EGLAPIENTRYP PFNEGLEXPORTDRMIMAGEMESAPROC) (EGLDisplay dpy, EGLImageKHR image, EGLint *name, EGLint *handle, EGLint *stride);
 #endif
 
+#ifndef EGL_MESA_resource_sharing
+#define EGL_MESA_resource_sharing 1
+#define EGL_GL_TEXTURE_MESA             0x3300  /* eglAcuireResource target */
+#define EGL_GL_BUFFER_OBJECT_MESA       0x3301  /* eglAcuireResource target */
+#define EGL_GL_RENDER_BUFFER_MESA       0x3302  /* eglAcuireResource target */
+#define EGL_GL_TEXTURE_ID_MESA          0x3303  /* eglAcuireResource attribute */
+#define EGL_GL_TEXTURE_LEVEL_MESA       0x3304  /* eglAcuireResource attribute */
+#define EGL_GL_TEXTURE_TARGET_MESA      0x3305  /* eglAcuireResource attribute */
+#define EGL_GL_BUFFER_OBJECT_ID_MESA    0x3306  /* eglAcuireResource attribute */
+#define EGL_GL_RENDER_BUFFER_ID_MESA    0x3307  /* eglAcuireResource attribute */
+
+#ifdef EGL_EGLEXT_PROTOTYPES
+EGLAPI EGLBoolean EGLAPIENTRY eglAcquireResourceMESA(EGLDisplay dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list, void * user_data);
+EGLAPI EGLBoolean EGLAPIENTRY eglReleaseResourceMESA(EGLDisplay dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list);
+#endif
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLACQUIRERESOURCEMESAPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list, void * user_data);
+typedef EGLBoolean (EGLAPIENTRYP PFNEGLRELEASERESOURCEMESAPROC) (EGLDisplay dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list);
+#endif
+
 #ifndef EGL_NV_post_sub_buffer
 #define EGL_NV_post_sub_buffer 1
 #define EGL_POST_SUB_BUFFER_SUPPORTED_NV	0x30BE
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 30ce175..21ee61e 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1169,6 +1169,25 @@ struct __DRI2configQueryExtensionRec {
 };
 
 /**
+ * This extension allows to share GL resources with OpenCL.
+ */
+#define __DRI_RESOURCE_SHARING "DRI_RESOURCE_SHARING"
+#define __DRI_RESOURCE_SHARING_VERSION 1
+typedef struct __DRIResourceShareExtensionRec __DRIResourceShareExtension;
+struct __DRIResourceShareExtensionRec {
+   __DRIextension base;
+
+   GLboolean (*acquireTexture)(__DRIcontext *context, GLenum target,
+                                  GLint level, GLuint texture, void *user_data);
+   GLboolean (*releaseTexture)(__DRIcontext *context, GLenum target,
+                                  GLint level, GLuint texture);
+   GLboolean (*acquireBufferObj)(__DRIcontext *context, GLuint bufobj, void *user_data);
+   GLboolean (*releaseBufferObj)(__DRIcontext *context, GLuint bufobj);
+   GLboolean (*acquireRenderBuffer)(__DRIcontext *context, GLuint rb, void *user_data);
+   GLboolean (*releaseRenderBuffer)(__DRIcontext *context, GLuint rb);
+};
+
+/**
  * Robust context driver extension.
  *
  * Existence of this extension means the driver can accept the
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 1bce314..d8cccb4 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -551,6 +551,9 @@ dri2_create_screen(_EGLDisplay *disp)
 	 if (strcmp(extensions[i]->name, __DRI2_CONFIG_QUERY) == 0) {
 	    dri2_dpy->config = (__DRI2configQueryExtension *) extensions[i];
 	 }
+         if (strcmp(extensions[i]->name, __DRI_RESOURCE_SHARING) == 0) {
+            dri2_dpy->resource_share = (__DRIResourceShareExtension *) extensions[i];
+         }
       }
    } else {
       assert(dri2_dpy->swrast);
@@ -1688,6 +1691,168 @@ dri2_load(_EGLDriver *drv)
    return EGL_TRUE;
 }
 
+#define CHECK_RESOURCE_SHARING(disp) \
+  do {\
+        if (disp->resource_share == NULL) {\
+           _eglLog(_EGL_WARNING, "driver doesn't support DRI resource share extension.");\
+           return EGL_FALSE;\
+        }\
+  } while(0)
+
+static EGLBoolean
+dri2_acquire_texture(_EGLDriver *drv, _EGLDisplay *dpy,
+                     _EGLContext *ctx, const EGLint *attr_list,
+                     void *user_data)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   GLuint texture = 0;
+   GLenum gl_target = 0;
+   GLint level = 0;
+   GLboolean ret;
+
+   CHECK_RESOURCE_SHARING(dri2_dpy);
+   if (_eglParseTextureAttribList(&texture, &gl_target, &level, dpy, attr_list) != EGL_SUCCESS)
+      return EGL_FALSE;
+
+   ret = dri2_dpy->resource_share->acquireTexture(dri2_ctx->dri_context,
+                                                  gl_target, level, texture,
+                                                  user_data);
+   return ret;
+}
+
+static EGLBoolean
+dri2_release_texture(_EGLDriver *drv, _EGLDisplay *dpy,
+                     _EGLContext *ctx, const EGLint *attr_list)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   GLuint texture = 0;
+   GLenum gl_target = 0;
+   GLint level = 0;
+   GLboolean ret;
+
+   CHECK_RESOURCE_SHARING(dri2_dpy);
+   if (_eglParseTextureAttribList(&texture, &gl_target, &level, dpy, attr_list) != EGL_SUCCESS)
+      return EGL_FALSE;
+
+   ret = dri2_dpy->resource_share->releaseTexture(dri2_ctx->dri_context,
+                                                  gl_target, level, texture);
+   return ret;
+}
+
+static EGLBoolean
+dri2_acquire_buffer_object(_EGLDriver *drv, _EGLDisplay *dpy,
+                           _EGLContext *ctx, const EGLint *attr_list,
+                           void *user_data)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   GLuint bufobj = 0;
+   GLboolean ret;
+
+   CHECK_RESOURCE_SHARING(dri2_dpy);
+   if (_eglParseBufferObjAttribList(&bufobj, dpy, attr_list) != EGL_SUCCESS)
+      return EGL_FALSE;
+
+   ret = dri2_dpy->resource_share->acquireBufferObj(dri2_ctx->dri_context,
+                                                    bufobj, user_data);
+   return ret;
+}
+
+static EGLBoolean
+dri2_release_buffer_object(_EGLDriver *drv, _EGLDisplay *dpy,
+                           _EGLContext *ctx, const EGLint *attr_list)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   GLuint bufobj = 0;
+   GLboolean ret;
+
+   CHECK_RESOURCE_SHARING(dri2_dpy);
+   if (_eglParseBufferObjAttribList(&bufobj, dpy, attr_list) != EGL_SUCCESS)
+      return EGL_FALSE;
+
+   ret = dri2_dpy->resource_share->releaseBufferObj(dri2_ctx->dri_context,
+                                                    bufobj);
+   return ret;
+}
+
+static EGLBoolean
+dri2_acquire_render_buffer(_EGLDriver *drv, _EGLDisplay *dpy,
+                           _EGLContext *ctx, const EGLint *attr_list,
+                           void *user_data)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   GLuint rb = 0;
+   GLboolean ret;
+
+   CHECK_RESOURCE_SHARING(dri2_dpy);
+   if (_eglParseBufferObjAttribList(&rb, dpy, attr_list) != EGL_SUCCESS)
+      return EGL_FALSE;
+
+   ret = dri2_dpy->resource_share->acquireRenderBuffer(dri2_ctx->dri_context,
+                                                       rb, user_data);
+   return ret;
+}
+
+static EGLBoolean
+dri2_release_render_buffer(_EGLDriver *drv, _EGLDisplay *dpy,
+                           _EGLContext *ctx, const EGLint *attr_list)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+   GLuint rb = 0;
+   GLboolean ret;
+
+   CHECK_RESOURCE_SHARING(dri2_dpy);
+   if (_eglParseBufferObjAttribList(&rb, dpy, attr_list) != EGL_SUCCESS)
+      return EGL_FALSE;
+
+   ret = dri2_dpy->resource_share->releaseRenderBuffer(dri2_ctx->dri_context,
+                                                       rb);
+   return ret;
+}
+
+static EGLBoolean
+dri2_acquire_resource_mesa(_EGLDriver *drv, _EGLDisplay *dpy,
+                           _EGLContext *ctx, const EGLenum target,
+                           const EGLint *attrib_list, void *user_data)
+{
+   switch (target) {
+   case EGL_GL_TEXTURE_MESA:
+     return dri2_acquire_texture(drv, dpy, ctx, attrib_list, user_data);
+   case EGL_GL_BUFFER_OBJECT_MESA:
+     return dri2_acquire_buffer_object(drv, dpy, ctx, attrib_list, user_data);
+   case EGL_GL_RENDER_BUFFER_MESA:
+     return dri2_acquire_render_buffer(drv, dpy, ctx, attrib_list, user_data);
+   default:
+      _eglLog(_EGL_WARNING, "bad resource target value 0x%04x",
+              target);
+   }
+   return EGL_FALSE;
+}
+
+static EGLBoolean
+dri2_release_resource_mesa(_EGLDriver *drv, _EGLDisplay *dpy,
+                           _EGLContext *ctx, const EGLenum target,
+                           const EGLint *attrib_list)
+{
+   switch (target) {
+   case EGL_GL_TEXTURE_MESA:
+     return dri2_release_texture(drv, dpy, ctx, attrib_list);
+   case EGL_GL_BUFFER_OBJECT_MESA:
+     return dri2_release_buffer_object(drv, dpy, ctx, attrib_list);
+   case EGL_GL_RENDER_BUFFER_MESA:
+     return dri2_release_render_buffer(drv, dpy, ctx, attrib_list);
+   default:
+      _eglLog(_EGL_WARNING, "bad resource target value 0x%04x",
+              target);
+   }
+   return EGL_FALSE;
+}
+
 /**
  * This is the main entrypoint into the driver, called by libEGL.
  * Create a new _EGLDriver object and init its dispatch table.
@@ -1723,6 +1888,8 @@ _eglBuiltInDriverDRI2(const char *args)
    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;
+   dri2_drv->base.API.AcquireResourceMESA = dri2_acquire_resource_mesa;
+   dri2_drv->base.API.ReleaseResourceMESA = dri2_release_resource_mesa;
 #ifdef HAVE_WAYLAND_PLATFORM
    dri2_drv->base.API.BindWaylandDisplayWL = dri2_bind_wayland_display_wl;
    dri2_drv->base.API.UnbindWaylandDisplayWL = dri2_unbind_wayland_display_wl;
diff --git a/src/egl/drivers/dri2/egl_dri2.h b/src/egl/drivers/dri2/egl_dri2.h
index 6dfdf94..ff3bf92 100644
--- a/src/egl/drivers/dri2/egl_dri2.h
+++ b/src/egl/drivers/dri2/egl_dri2.h
@@ -73,6 +73,7 @@
 #include "egllog.h"
 #include "eglsurface.h"
 #include "eglimage.h"
+#include "eglresshare.h"
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
@@ -101,6 +102,7 @@ struct dri2_egl_display
    __DRIimageExtension      *image;
    __DRIrobustnessExtension *robustness;
    __DRI2configQueryExtension *config;
+   __DRIResourceShareExtension *resource_share;
    int                       fd;
 
    int                       own_device;
diff --git a/src/egl/main/Makefile.am b/src/egl/main/Makefile.am
index ca5257a..43cd275 100644
--- a/src/egl/main/Makefile.am
+++ b/src/egl/main/Makefile.am
@@ -54,6 +54,7 @@ libEGL_la_SOURCES = \
 	eglstring.c \
 	eglsurface.c \
 	eglsync.c \
+        eglresshare.c \
 	eglcompiler.h \
 	eglconfig.h \
 	eglcontext.h \
@@ -70,7 +71,8 @@ libEGL_la_SOURCES = \
 	eglscreen.h \
 	eglstring.h \
 	eglsurface.h \
-	eglsync.h
+	eglsync.h \
+        eglresshare.h
 
 libEGL_la_LIBADD = \
 	$(EGL_LIB_DEPS)
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 4a9831b..3012106 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -945,6 +945,10 @@ eglGetProcAddress(const char *procname)
       { "eglQueryScreenModeMESA", (_EGLProc) eglQueryScreenModeMESA },
       { "eglQueryModeStringMESA", (_EGLProc) eglQueryModeStringMESA },
 #endif /* EGL_MESA_screen_surface */
+#ifdef EGL_MESA_resource_sharing
+      { "eglAcquireResourceMESA", (_EGLProc) eglAcquireResourceMESA },
+      { "eglReleaseResourceMESA", (_EGLProc) eglReleaseResourceMESA },
+#endif /* EGL_MESA_resource_sharing */
 #ifdef EGL_MESA_drm_display
       { "eglGetDRMDisplayMESA", (_EGLProc) eglGetDRMDisplayMESA },
 #endif
@@ -1215,6 +1219,35 @@ eglQueryModeStringMESA(EGLDisplay dpy, EGLModeMESA mode)
 
 #endif /* EGL_MESA_screen_surface */
 
+#ifdef EGL_MESA_resource_sharing
+EGLBoolean EGLAPIENTRY
+eglAcquireResourceMESA(EGLDisplay dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list, void *user)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   _EGLContext *context = _eglLookupContext(ctx, disp);
+   EGLBoolean ret;
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+   ret = drv->API.AcquireResourceMESA(drv, disp, context, target, attrib_list, user);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+
+EGLBoolean EGLAPIENTRY
+eglReleaseResourceMESA(EGLDisplay dpy, EGLContext ctx, EGLenum target, const EGLint *attrib_list)
+{
+   _EGLDisplay *disp = _eglLockDisplay(dpy);
+   _EGLDriver *drv;
+   _EGLContext *context = _eglLookupContext(ctx, disp);
+   EGLBoolean ret;
+
+   _EGL_CHECK_DISPLAY(disp, EGL_FALSE, drv);
+   ret = drv->API.ReleaseResourceMESA(drv, disp, context, target, attrib_list);
+
+   RETURN_EGL_EVAL(disp, ret);
+}
+#endif
 
 #ifdef EGL_MESA_drm_display
 
diff --git a/src/egl/main/eglapi.h b/src/egl/main/eglapi.h
index ee382d0..a33084b 100644
--- a/src/egl/main/eglapi.h
+++ b/src/egl/main/eglapi.h
@@ -95,6 +95,10 @@ typedef EGLBoolean (*QueryScreenModeMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _
 typedef const char * (*QueryModeStringMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLMode *mode);
 #endif /* EGL_MESA_screen_surface */
 
+#ifdef EGL_MESA_resource_sharing
+typedef EGLBoolean (*AcquireResourceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLenum target, const EGLint *attrib_list, void *user_data);
+typedef EGLBoolean (*ReleaseResourceMESA_t)(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx, EGLenum target, const EGLint *attrib_list);
+#endif
 
 typedef _EGLSurface *(*CreatePbufferFromClientBuffer_t)(_EGLDriver *drv, _EGLDisplay *dpy, EGLenum buftype, EGLClientBuffer buffer, _EGLConfig *config, const EGLint *attrib_list);
 
@@ -184,6 +188,11 @@ struct _egl_api
    QueryModeStringMESA_t QueryModeStringMESA;
 #endif /* EGL_MESA_screen_surface */
 
+#ifdef EGL_MESA_resource_sharing
+   AcquireResourceMESA_t AcquireResourceMESA;
+   ReleaseResourceMESA_t ReleaseResourceMESA;
+#endif
+
    CreatePbufferFromClientBuffer_t CreatePbufferFromClientBuffer;
 
    CreateImageKHR_t CreateImageKHR;
diff --git a/src/egl/main/eglresshare.c b/src/egl/main/eglresshare.c
new file mode 100644
index 0000000..ee8cb31
--- /dev/null
+++ b/src/egl/main/eglresshare.c
@@ -0,0 +1,139 @@
+/**************************************************************************
+ *
+ * Copyright 2013-2014 Zhigang Gong <zhigang.gong at linux.intel.com>
+ * Copyright 2013-2014 Intel, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#include <assert.h>
+#include <string.h>
+
+#include "eglresshare.h"
+
+/**
+ * Parse the list of share texture attributes and return the proper error code.
+ */
+EGLint
+_eglParseTextureAttribList(unsigned int *texture, EGLenum *gl_target, EGLint *level,
+                           _EGLDisplay *dpy, const EGLint *attrib_list)
+{
+   EGLint i, err = EGL_SUCCESS;
+
+   (void) dpy;
+
+
+   *texture = 0;
+   *gl_target = 0;
+   *level = 0;
+
+   if (!attrib_list)
+      return EGL_BAD_ATTRIBUTE;
+
+   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
+      EGLint attr = attrib_list[i++];
+      EGLint val = attrib_list[i];
+
+      switch (attr) {
+      case EGL_GL_TEXTURE_LEVEL_MESA:
+         *level = val;
+         break;
+      case EGL_GL_TEXTURE_ID_MESA:
+         *texture = val;
+         break;
+      case EGL_GL_TEXTURE_TARGET_MESA:
+         *gl_target = val;
+         break;
+      default:
+         /* unknown attrs are ignored */
+         break;
+      }
+   }
+
+   return err;
+}
+
+/**
+ * Parse the list of share texture attributes and return the proper error code.
+ */
+EGLint
+_eglParseBufferObjAttribList(unsigned int *bufobj, _EGLDisplay *dpy, const EGLint *attrib_list)
+{
+   EGLint i, err = EGL_SUCCESS;
+   *bufobj = 0;
+   (void) dpy;
+
+   if (!attrib_list)
+      return EGL_BAD_ATTRIBUTE;
+
+   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
+      EGLint attr = attrib_list[i++];
+      EGLint val = attrib_list[i];
+
+      switch (attr) {
+      case EGL_GL_BUFFER_OBJECT_ID_MESA:
+         *bufobj = val;
+         break;
+      default:
+         /* unknown attrs are ignored */
+         break;
+      }
+   }
+   if (*bufobj == 0)
+      err = EGL_BAD_ATTRIBUTE;
+
+   return err;
+}
+
+/**
+ * Parse the list of share texture attributes and return the proper error code.
+ */
+EGLint
+_eglParseRenderBufferAttribList(unsigned int *rb, _EGLDisplay *dpy, const EGLint *attrib_list)
+{
+   EGLint i, err = EGL_SUCCESS;
+   *rb = 0;
+   (void) dpy;
+
+   if (!attrib_list)
+      return EGL_BAD_ATTRIBUTE;
+
+   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
+      EGLint attr = attrib_list[i++];
+      EGLint val = attrib_list[i];
+
+      switch (attr) {
+      case EGL_GL_RENDER_BUFFER_ID_MESA:
+         *rb = val;
+         break;
+      default:
+         /* unknown attrs are ignored */
+         break;
+      }
+   }
+   if (*rb == 0)
+      err = EGL_BAD_ATTRIBUTE;
+
+   return err;
+}
diff --git a/src/egl/main/eglresshare.h b/src/egl/main/eglresshare.h
new file mode 100644
index 0000000..56710cf
--- /dev/null
+++ b/src/egl/main/eglresshare.h
@@ -0,0 +1,47 @@
+/**************************************************************************
+ *
+ * Copyright 2013-2014 Zhigang Gong <zhigang.gong at linux.intel.com>
+ * Copyright 2013-2014 Intel, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+
+
+#ifndef EGLRESSHARE_INCLUDED
+#define EGLRESSHARE_INCLUDED
+
+#include "egltypedefs.h"
+#include "egldisplay.h"
+
+EGLint
+_eglParseTextureAttribList(unsigned int *texture, EGLenum *gl_target,
+                           EGLint *level, _EGLDisplay *dpy,
+                           const EGLint *attrib_list);
+EGLint
+_eglParseBufferObjAttribList(unsigned int *bufobj, _EGLDisplay *dpy,
+                             const EGLint *attrib_list);
+
+EGLint
+_eglParseRenderBufferAttribList(unsigned int *rb, _EGLDisplay *dpy,
+                                const EGLint *attrib_list);
+#endif
-- 
1.7.9.5



More information about the mesa-dev mailing list