[virglrenderer-devel] [PATCH v3] virglrenderer: Add method to import EGLImageKHRs as resources.

David Riley davidriley at chromium.org
Fri Jun 8 19:54:35 UTC 2018


Allow resources created externally (eg gbm created buffers as
dma bufs) to be used.  As an example, crosvm
(https://chromium.googlesource.com/chromiumos/platform/crosvm/)
will intercept resource creation to use minigbm to allocate
buffers that its compositor is able to properly handle since it
only supports compositing with buffers allocated via minigbm.
This patch allows direct rendering to those buffers without
requiring an extra copy.

v2: Handle missing extension better.
v3: Update commit message with more details on usage.

Signed-off-by: David Riley <davidriley at chromium.org>
---
 src/virglrenderer.c  | 11 ++++++++++-
 src/virglrenderer.h  |  1 +
 src/vrend_renderer.c | 12 ++++++++++--
 src/vrend_renderer.h |  2 +-
 4 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/virglrenderer.c b/src/virglrenderer.c
index c89cb60..7397cfa 100644
--- a/src/virglrenderer.c
+++ b/src/virglrenderer.c
@@ -60,7 +60,16 @@ static int use_context = CONTEXT_NONE;
 
 int virgl_renderer_resource_create(struct virgl_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs)
 {
-   return vrend_renderer_resource_create((struct vrend_renderer_resource_create_args *)args, iov, num_iovs);
+   return vrend_renderer_resource_create((struct vrend_renderer_resource_create_args *)args, iov, num_iovs, NULL);
+}
+
+int virgl_renderer_resource_import_eglimage(struct virgl_renderer_resource_create_args *args, void *image)
+{
+#ifdef HAVE_EPOXY_EGL_H
+   return vrend_renderer_resource_create((struct vrend_renderer_resource_create_args *)args, 0, 0, image);
+#else
+   return EINVAL;
+#endif
 }
 
 void virgl_renderer_resource_unref(uint32_t res_handle)
diff --git a/src/virglrenderer.h b/src/virglrenderer.h
index 9596dce..dc9036f 100644
--- a/src/virglrenderer.h
+++ b/src/virglrenderer.h
@@ -103,6 +103,7 @@ struct virgl_renderer_resource_create_args {
 /* new API */
 
 VIRGL_EXPORT int virgl_renderer_resource_create(struct virgl_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs);
+VIRGL_EXPORT int virgl_renderer_resource_import_eglimage(struct virgl_renderer_resource_create_args *args, void *image);
 VIRGL_EXPORT void virgl_renderer_resource_unref(uint32_t res_handle);
 
 VIRGL_EXPORT int virgl_renderer_context_create(uint32_t handle, uint32_t nlen, const char *name);
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 5ef3555..236687c 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4595,7 +4595,7 @@ static void vrend_create_buffer(struct vrend_resource *gr, uint32_t width)
    gr->is_buffer = true;
 }
 
-int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs)
+int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs, void *image_oes)
 {
    struct vrend_resource *gr;
    int level;
@@ -4700,7 +4700,15 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
          return EINVAL;
       }
 
-      if (args->nr_samples > 1) {
+      if (image_oes) {
+	 if (epoxy_has_gl_extension("GL_OES_EGL_image_external")) {
+	    glEGLImageTargetTexture2DOES(gr->target, (GLeglImageOES) image_oes);
+	 } else {
+	    fprintf(stderr, "missing GL_OES_EGL_image_external extension\n");
+	    FREE(gr);
+	    return EINVAL;
+	 }
+      } else if (args->nr_samples > 1) {
          if (vrend_state.use_gles || vrend_state.have_texture_storage) {
             if (gr->target == GL_TEXTURE_2D_MULTISAMPLE) {
                glTexStorage2DMultisample(gr->target, args->nr_samples,
diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h
index 5554edb..e23f78f 100644
--- a/src/vrend_renderer.h
+++ b/src/vrend_renderer.h
@@ -164,7 +164,7 @@ struct vrend_renderer_resource_create_args {
    uint32_t flags;
 };
 
-int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs);
+int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs, void *image_eos);
 
 void vrend_renderer_resource_unref(uint32_t handle);
 
-- 
2.18.0.rc1.242.g61856ae69a-goog



More information about the virglrenderer-devel mailing list