egl: implement EGL part of interop interface (v2)
authorMarek Olšák <marek.olsak@amd.com>
Thu, 3 Mar 2016 14:59:48 +0000 (15:59 +0100)
committerMarek Olšák <marek.olsak@amd.com>
Wed, 20 Apr 2016 10:18:47 +0000 (12:18 +0200)
v2: - use const

src/egl/drivers/dri2/egl_dri2.c
src/egl/drivers/dri2/egl_dri2.h
src/egl/main/eglapi.c
src/egl/main/eglapi.h

index 490b0409c98e91122f1ee41d3ea992c7887505c5..d8448f4fc0f9ec577a66fb71a19b49e7a0ec8327 100644 (file)
@@ -46,6 +46,7 @@
 #endif
 #include <GL/gl.h>
 #include <GL/internal/dri_interface.h>
+#include "GL/mesa_glinterop.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 
@@ -740,6 +741,8 @@ dri2_create_screen(_EGLDisplay *disp)
       if (strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) {
          dri2_dpy->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i];
       }
+      if (strcmp(extensions[i]->name, __DRI2_INTEROP) == 0)
+         dri2_dpy->interop = (__DRI2interopExtension *) extensions[i];
    }
 
    dri2_setup_screen(disp);
@@ -2691,6 +2694,33 @@ dri2_server_wait_sync(_EGLDriver *drv, _EGLDisplay *dpy, _EGLSync *sync)
    return EGL_TRUE;
 }
 
+static int
+dri2_interop_query_device_info(_EGLDisplay *dpy, _EGLContext *ctx,
+                               mesa_glinterop_device_info *out)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+
+   if (!dri2_dpy->interop)
+      return MESA_GLINTEROP_UNSUPPORTED;
+
+   return dri2_dpy->interop->query_device_info(dri2_ctx->dri_context, out);
+}
+
+static int
+dri2_interop_export_object(_EGLDisplay *dpy, _EGLContext *ctx,
+                           const mesa_glinterop_export_in *in,
+                           mesa_glinterop_export_out *out)
+{
+   struct dri2_egl_display *dri2_dpy = dri2_egl_display(dpy);
+   struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
+
+   if (!dri2_dpy->interop)
+      return MESA_GLINTEROP_UNSUPPORTED;
+
+   return dri2_dpy->interop->export_object(dri2_ctx->dri_context, in, out);
+}
+
 static void
 dri2_unload(_EGLDriver *drv)
 {
@@ -2802,6 +2832,8 @@ _eglBuiltInDriverDRI2(const char *args)
    dri2_drv->base.API.SignalSyncKHR = dri2_signal_sync;
    dri2_drv->base.API.WaitSyncKHR = dri2_server_wait_sync;
    dri2_drv->base.API.DestroySyncKHR = dri2_destroy_sync;
+   dri2_drv->base.API.GLInteropQueryDeviceInfo = dri2_interop_query_device_info;
+   dri2_drv->base.API.GLInteropExportObject = dri2_interop_export_object;
 
    dri2_drv->base.Name = "DRI2";
    dri2_drv->base.Unload = dri2_unload;
index ef799398474368f0ba73d8efb11e1e40cfebdd03..3e9f9911d24265946dd31378523e387c7c8f1373 100644 (file)
@@ -174,6 +174,7 @@ struct dri2_egl_display
    const __DRI2configQueryExtension *config;
    const __DRI2fenceExtension *fence;
    const __DRI2rendererQueryExtension *rendererQuery;
+   const __DRI2interopExtension *interop;
    int                       fd;
 
    int                       own_device;
index 64ffe92be430b8524431f6c28e22c366dd8907d5..eb612c00f64d1d990a28fe4749abe9bf7c226556 100644 (file)
@@ -88,6 +88,7 @@
 #include <string.h>
 #include "c99_compat.h"
 #include "c11/threads.h"
+#include "GL/mesa_glinterop.h"
 #include "eglcompiler.h"
 
 #include "eglglobals.h"
@@ -1912,3 +1913,74 @@ eglGetProcAddress(const char *procname)
 
    RETURN_EGL_SUCCESS(NULL, ret);
 }
+
+static int
+_eglLockDisplayInterop(EGLDisplay dpy, EGLContext context,
+                       _EGLDisplay **disp, _EGLDriver **drv,
+                       _EGLContext **ctx)
+{
+
+   *disp = _eglLockDisplay(dpy);
+   if (!*disp || !(*disp)->Initialized || !(*disp)->Driver) {
+      if (*disp)
+         _eglUnlockDisplay(*disp);
+      return MESA_GLINTEROP_INVALID_DISPLAY;
+   }
+
+   *drv = (*disp)->Driver;
+
+   *ctx = _eglLookupContext(context, *disp);
+   if (!*ctx ||
+       ((*ctx)->ClientAPI != EGL_OPENGL_API &&
+        (*ctx)->ClientAPI != EGL_OPENGL_ES_API)) {
+      _eglUnlockDisplay(*disp);
+      return MESA_GLINTEROP_INVALID_CONTEXT;
+   }
+
+   return MESA_GLINTEROP_SUCCESS;
+}
+
+GLAPI int GLAPIENTRY
+MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
+                                mesa_glinterop_device_info *out)
+{
+   _EGLDisplay *disp;
+   _EGLDriver *drv;
+   _EGLContext *ctx;
+   int ret;
+
+   ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
+   if (ret != MESA_GLINTEROP_SUCCESS)
+      return ret;
+
+   if (drv->API.GLInteropQueryDeviceInfo)
+      ret = drv->API.GLInteropQueryDeviceInfo(disp, ctx, out);
+   else
+      ret = MESA_GLINTEROP_UNSUPPORTED;
+
+   _eglUnlockDisplay(disp);
+   return ret;
+}
+
+GLAPI int GLAPIENTRY
+MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
+                             const mesa_glinterop_export_in *in,
+                             mesa_glinterop_export_out *out)
+{
+   _EGLDisplay *disp;
+   _EGLDriver *drv;
+   _EGLContext *ctx;
+   int ret;
+
+   ret = _eglLockDisplayInterop(dpy, context, &disp, &drv, &ctx);
+   if (ret != MESA_GLINTEROP_SUCCESS)
+      return ret;
+
+   if (drv->API.GLInteropExportObject)
+      ret = drv->API.GLInteropExportObject(disp, ctx, in, out);
+   else
+      ret = MESA_GLINTEROP_UNSUPPORTED;
+
+   _eglUnlockDisplay(disp);
+   return ret;
+}
index 3f6d3c27a5288fc93fc255deb066ca9f3c9c5f2f..58327fd1015c1583fb36634a65f0515e64c45158 100644 (file)
@@ -42,6 +42,9 @@ extern "C" {
 typedef void (*_EGLProc)(void);
 
 struct wl_display;
+typedef struct _mesa_glinterop_device_info mesa_glinterop_device_info;
+typedef struct _mesa_glinterop_export_in mesa_glinterop_export_in;
+typedef struct _mesa_glinterop_export_out mesa_glinterop_export_out;
 
 /**
  * The API dispatcher jumps through these functions
@@ -188,6 +191,12 @@ struct _egl_api
    EGLBoolean (*ExportDMABUFImageMESA)(_EGLDriver *drv, _EGLDisplay *disp,
                                        _EGLImage *img, EGLint *fds,
                                        EGLint *strides, EGLint *offsets);
+
+   int (*GLInteropQueryDeviceInfo)(_EGLDisplay *dpy, _EGLContext *ctx,
+                                   mesa_glinterop_device_info *out);
+   int (*GLInteropExportObject)(_EGLDisplay *dpy, _EGLContext *ctx,
+                                const mesa_glinterop_export_in *in,
+                                mesa_glinterop_export_out *out);
 };