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

David Riley davidriley at chromium.org
Thu Jun 7 17:47:23 UTC 2018


Allow resources created externally (eg gbm created buffers as
dma bufs) to be used.

v2: Handle missing extension better. 

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.17.1.1185.g55be947832-goog



More information about the virglrenderer-devel mailing list