[Spice-devel] [PATCH RFC 05/12] Import function to get dma buffer from a texture

Frediano Ziglio fziglio at redhat.com
Fri Jul 15 13:49:30 UTC 2016


This to allow to support local clients using unix sockets and
passing buffer to client.

This function is mainly a copy of Qemu function.
I don't know if is a problem of licensing but I think
that Gerd won't mind the usage of it.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/egl.c | 31 +++++++++++++++++++++++++++++++
 server/egl.h |  3 +++
 2 files changed, 34 insertions(+)

diff --git a/server/egl.c b/server/egl.c
index 85f7264..9bfa413 100644
--- a/server/egl.c
+++ b/server/egl.c
@@ -24,6 +24,8 @@
 #include <gbm.h>
 #include <common/log.h>
 
+#include <common/verify.h>
+
 #include "egl.h"
 
 void *egl_own_context(void *egl_display, void *egl_context)
@@ -61,3 +63,32 @@ void *egl_own_context(void *egl_display, void *egl_context)
 
     return ectx;
 }
+
+int egl_get_fd_for_texture(void *egl_display, void *egl_context,
+                           uint32_t tex_id,
+                           uint32_t *stride, uint32_t *fourcc)
+{
+    EGLImageKHR image;
+    EGLint num_planes, fd;
+
+    image = eglCreateImageKHR(egl_display, egl_context,
+                              EGL_GL_TEXTURE_2D_KHR,
+                              (EGLClientBuffer)(unsigned long)tex_id,
+                              NULL);
+    if (!image) {
+        return -1;
+    }
+
+    verify(sizeof(int) == sizeof(*fourcc));
+    eglExportDMABUFImageQueryMESA(egl_display, image, (int*) fourcc,
+                                  &num_planes, NULL);
+    if (num_planes != 1) {
+        eglDestroyImageKHR(egl_display, image);
+        return -1;
+    }
+    verify(sizeof(int) == sizeof(*stride));
+    eglExportDMABUFImageMESA(egl_display, image, &fd, (int*) stride, NULL);
+    eglDestroyImageKHR(egl_display, image);
+
+    return fd;
+}
diff --git a/server/egl.h b/server/egl.h
index c2ab722..6360a8a 100644
--- a/server/egl.h
+++ b/server/egl.h
@@ -18,6 +18,9 @@
 #ifndef EGL_H_
 #define EGL_H_
 
+int egl_get_fd_for_texture(void *egl_display, void *egl_context,
+                           uint32_t tex_id,
+                           uint32_t *stride, uint32_t *fourcc);
 void *egl_own_context(void *egl_display, void *egl_context);
 
 #endif /* EGL_H_ */
-- 
2.7.4



More information about the Spice-devel mailing list