diff options
author | Simon Ser <contact@emersion.fr> | 2019-04-29 22:32:35 +0300 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-07 09:06:11 -0400 |
commit | 6dbdf5db345c47ac6edf92161cb7b521c8284e39 (patch) | |
tree | 0188bfbc3eb26f9dcb65b6f15f2417950faff0f1 /render/dmabuf.c | |
parent | 5c78f1b0d5d6572dd9035e2d43e2a7bddd466a58 (diff) |
render/dmabuf: add wlr_dmabuf_attributes_copy
Diffstat (limited to 'render/dmabuf.c')
-rw-r--r-- | render/dmabuf.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/render/dmabuf.c b/render/dmabuf.c index 6b500748..bed609dd 100644 --- a/render/dmabuf.c +++ b/render/dmabuf.c @@ -1,10 +1,28 @@ +#define _POSIX_C_SOURCE 200809L +#include <fcntl.h> #include <unistd.h> #include <wlr/render/dmabuf.h> +#include <wlr/util/log.h> -void wlr_dmabuf_attributes_finish( struct wlr_dmabuf_attributes *attribs) { +void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs) { for (int i = 0; i < attribs->n_planes; ++i) { close(attribs->fd[i]); attribs->fd[i] = -1; } attribs->n_planes = 0; } + +bool wlr_dmabuf_attributes_copy(struct wlr_dmabuf_attributes *dst, + struct wlr_dmabuf_attributes *src) { + memcpy(dst, src, sizeof(struct wlr_dmabuf_attributes)); + + for (int i = 0; i < src->n_planes; ++i) { + dst->fd[i] = fcntl(src->fd[i], F_DUPFD_CLOEXEC, 0); + if (dst->fd[i] < 0) { + wlr_log_errno(WLR_ERROR, "fcntl(F_DUPFD_CLOEXEC) failed"); + return false; + } + } + + return true; +} |