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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]