From 1a54debea08e41d30286327db41b1a061422a801 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Mon, 20 Apr 2020 13:27:41 -0700 Subject: [PATCH] virgl: add virgl_resource_create_from_fd Another way to create a virgl_resource. Signed-off-by: Chia-I Wu Reviewed-by: Gurchetan Singh --- src/virgl_resource.c | 30 ++++++++++++++++++++++++++++++ src/virgl_resource.h | 17 +++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/virgl_resource.c b/src/virgl_resource.c index 89224c7..c9788d4 100644 --- a/src/virgl_resource.c +++ b/src/virgl_resource.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "util/u_hash_table.h" #include "util/u_pointer.h" @@ -42,6 +43,8 @@ virgl_resource_destroy_func(void *val) if (res->pipe_resource) pipe_callbacks.unref(res->pipe_resource, pipe_callbacks.data); + if (res->fd_type != VIRGL_RESOURCE_FD_INVALID) + close(res->fd); free(res); } @@ -92,6 +95,8 @@ virgl_resource_create(uint32_t res_id) } res->res_id = res_id; + res->fd_type = VIRGL_RESOURCE_FD_INVALID; + res->fd = -1; return res; } @@ -117,6 +122,31 @@ virgl_resource_create_from_pipe(uint32_t res_id, return 0; } +int +virgl_resource_create_from_fd(uint32_t res_id, + enum virgl_resource_fd_type fd_type, + int fd, + const struct iovec *iov, + int iov_count) +{ + struct virgl_resource *res; + + assert(fd_type != VIRGL_RESOURCE_FD_INVALID && fd >= 0); + + res = virgl_resource_create(res_id); + if (!res) + return ENOMEM; + + res->fd_type = fd_type; + /* take ownership */ + res->fd = fd; + + res->iov = iov; + res->iov_count = iov_count; + + return 0; +} + int virgl_resource_create_from_iov(uint32_t res_id, const struct iovec *iov, diff --git a/src/virgl_resource.h b/src/virgl_resource.h index 3b165da..6b83d6b 100644 --- a/src/virgl_resource.h +++ b/src/virgl_resource.h @@ -30,6 +30,13 @@ struct iovec; struct pipe_resource; +enum virgl_resource_fd_type { + VIRGL_RESOURCE_FD_DMABUF, + VIRGL_RESOURCE_FD_OPAQUE, + + VIRGL_RESOURCE_FD_INVALID = -1, +}; + /** * A global cross-context resource. A virgl_resource is not directly usable * by renderer contexts, but must be attached and imported into renderer @@ -43,6 +50,9 @@ struct virgl_resource { struct pipe_resource *pipe_resource; + enum virgl_resource_fd_type fd_type; + int fd; + const struct iovec *iov; int iov_count; @@ -76,6 +86,13 @@ virgl_resource_create_from_pipe(uint32_t res_id, const struct iovec *iov, int iov_count); +int +virgl_resource_create_from_fd(uint32_t res_id, + enum virgl_resource_fd_type fd_type, + int fd, + const struct iovec *iov, + int iov_count); + int virgl_resource_create_from_iov(uint32_t res_id, const struct iovec *iov,