virgl: add virgl_resource_create_from_fd

Another way to create a virgl_resource.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 4 years ago
parent 8ad994b199
commit 1a54debea0
  1. 30
      src/virgl_resource.c
  2. 17
      src/virgl_resource.h

@ -27,6 +27,7 @@
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#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,

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

Loading…
Cancel
Save