[virglrenderer-devel] [PATCH virglrenderer] egl: add virgl_renderer_get_fd_for_texture2()

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Tue Jun 12 12:47:59 UTC 2018


From: Marc-André Lureau <marcandre.lureau at redhat.com>

virgl_renderer_resource_get_info() doesn't return the underlying image
stride. eglExportDMABUFImageMESA() does. This fixes imports failing
due to a stride mismatch under certain resolutions. (note that qemu
uses its own export methods, perhaps because Gerd noticed the problem
with virgl egl export functions)

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 src/virgl_egl.h         |  1 +
 src/virgl_egl_context.c | 23 +++++++++++++++++++++++
 src/virglrenderer.c     |  9 +++++++++
 src/virglrenderer.h     |  1 +
 4 files changed, 34 insertions(+)

diff --git a/src/virgl_egl.h b/src/virgl_egl.h
index 3038f21..1a651a0 100644
--- a/src/virgl_egl.h
+++ b/src/virgl_egl.h
@@ -37,5 +37,6 @@ virgl_renderer_gl_context virgl_egl_get_current_context(struct virgl_egl *ve);
 
 int virgl_egl_get_fourcc_for_texture(struct virgl_egl *ve, uint32_t tex_id, uint32_t format, int *fourcc);
 int virgl_egl_get_fd_for_texture(struct virgl_egl *ve, uint32_t tex_id, int *fd);
+int virgl_egl_get_fd_for_texture2(struct virgl_egl *ve, uint32_t tex_id, int *fd, int *stride, int *offset);
 uint32_t virgl_egl_get_gbm_format(uint32_t format);
 #endif
diff --git a/src/virgl_egl_context.c b/src/virgl_egl_context.c
index e850d23..6195394 100644
--- a/src/virgl_egl_context.c
+++ b/src/virgl_egl_context.c
@@ -315,6 +315,29 @@ int virgl_egl_get_fourcc_for_texture(struct virgl_egl *ve, uint32_t tex_id, uint
    return ret;
 }
 
+int virgl_egl_get_fd_for_texture2(struct virgl_egl *ve, uint32_t tex_id, int *fd,
+                                  int *stride, int *offset)
+{
+   int ret = EINVAL;
+   EGLImageKHR image = eglCreateImageKHR(ve->egl_display, eglGetCurrentContext(),
+                                         EGL_GL_TEXTURE_2D_KHR,
+                                         (EGLClientBuffer)(unsigned long)tex_id, NULL);
+   if (!image)
+      return EINVAL;
+   if (!ve->have_mesa_dma_buf_img_export)
+      goto out_destroy;
+
+   if (!eglExportDMABUFImageMESA(ve->egl_display, image, fd,
+                                 stride, offset))
+      goto out_destroy;
+
+   ret = 0;
+
+out_destroy:
+   eglDestroyImageKHR(ve->egl_display, image);
+   return ret;
+}
+
 int virgl_egl_get_fd_for_texture(struct virgl_egl *ve, uint32_t tex_id, int *fd)
 {
    EGLImageKHR image;
diff --git a/src/virglrenderer.c b/src/virglrenderer.c
index c2ef019..562ff83 100644
--- a/src/virglrenderer.c
+++ b/src/virglrenderer.c
@@ -337,6 +337,15 @@ int virgl_renderer_get_fd_for_texture(uint32_t tex_id, int *fd)
 #endif
 }
 
+int virgl_renderer_get_fd_for_texture2(uint32_t tex_id, int *fd, int *stride, int *offset)
+{
+#ifdef HAVE_EPOXY_EGL_H
+   return virgl_egl_get_fd_for_texture2(egl_info, tex_id, fd, stride, offset);
+#else
+   return -1;
+#endif
+}
+
 void virgl_renderer_reset(void)
 {
    vrend_renderer_reset();
diff --git a/src/virglrenderer.h b/src/virglrenderer.h
index 9596dce..a095210 100644
--- a/src/virglrenderer.h
+++ b/src/virglrenderer.h
@@ -73,6 +73,7 @@ VIRGL_EXPORT void virgl_renderer_get_rect(int resource_id, struct iovec *iov, un
                                           uint32_t offset, int x, int y, int width, int height);
 
 VIRGL_EXPORT int virgl_renderer_get_fd_for_texture(uint32_t tex_id, int *fd);
+VIRGL_EXPORT int virgl_renderer_get_fd_for_texture2(uint32_t tex_id, int *fd, int *stride, int *offset);
 
 /* virgl bind flags - these are compatible with mesa 10.5 gallium.
    but are fixed, no other should be passed to virgl either. */
-- 
2.18.0.rc1



More information about the virglrenderer-devel mailing list