virgl: add virgl_resource_export_fd

This is useful when we need an fd from 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 7594f3030e
commit d257fbf7f2
  1. 22
      src/virgl_resource.c
  2. 7
      src/virgl_resource.h
  3. 19
      src/vrend_renderer.c

@ -26,6 +26,7 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
@ -212,3 +213,24 @@ virgl_resource_detach_iov(struct virgl_resource *res)
res->iov = NULL;
res->iov_count = 0;
}
enum virgl_resource_fd_type
virgl_resource_export_fd(struct virgl_resource *res, int *fd)
{
if (res->fd_type != VIRGL_RESOURCE_FD_INVALID) {
#ifdef F_DUPFD_CLOEXEC
*fd = fcntl(res->fd, F_DUPFD_CLOEXEC, 0);
if (*fd < 0)
*fd = dup(res->fd);
#else
*fd = dup(res->fd);
#endif
return *fd >= 0 ? res->fd_type : VIRGL_RESOURCE_FD_INVALID;
} else if (res->pipe_resource) {
return pipe_callbacks.export_fd(res->pipe_resource,
fd,
pipe_callbacks.data);
}
return VIRGL_RESOURCE_FD_INVALID;
}

@ -69,6 +69,10 @@ struct virgl_resource_pipe_callbacks {
int iov_count,
void *data);
void (*detach_iov)(struct pipe_resource *pres, void *data);
enum virgl_resource_fd_type (*export_fd)(struct pipe_resource *pres,
int *fd,
void *data);
};
int
@ -112,4 +116,7 @@ virgl_resource_attach_iov(struct virgl_resource *res,
void
virgl_resource_detach_iov(struct virgl_resource *res);
enum virgl_resource_fd_type
virgl_resource_export_fd(struct virgl_resource *res, int *fd);
#endif /* VIRGL_RESOURCE_H */

@ -5862,6 +5862,24 @@ static void vrend_pipe_resource_detach_iov(struct pipe_resource *pres,
res->num_iovs = 0;
}
static enum virgl_resource_fd_type vrend_pipe_resource_export_fd(UNUSED struct pipe_resource *pres,
UNUSED int *fd,
UNUSED void *data)
{
#ifdef ENABLE_MINIGBM_ALLOCATION
struct vrend_resource *res = (struct vrend_resource *)pres;
if (res->storage_bits & VREND_STORAGE_GBM_BUFFER) {
int ret = virgl_gbm_export_fd(gbm->device,
gbm_bo_get_handle(res->gbm_bo).u32, fd);
if (!ret)
return VIRGL_RESOURCE_FD_DMABUF;
}
#endif
return VIRGL_RESOURCE_FD_INVALID;
}
static const struct virgl_resource_pipe_callbacks *
vrend_renderer_get_pipe_callbacks(void)
{
@ -5869,6 +5887,7 @@ vrend_renderer_get_pipe_callbacks(void)
.unref = vrend_pipe_resource_unref,
.attach_iov = vrend_pipe_resource_attach_iov,
.detach_iov = vrend_pipe_resource_detach_iov,
.export_fd = vrend_pipe_resource_export_fd,
};
return &callbacks;

Loading…
Cancel
Save