2019-04-29 21:32:35 +02:00
|
|
|
#include <fcntl.h>
|
2018-05-31 13:33:27 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <wlr/render/dmabuf.h>
|
2019-04-29 21:32:35 +02:00
|
|
|
#include <wlr/util/log.h>
|
2022-05-26 14:44:02 +02:00
|
|
|
#include "render/dmabuf.h"
|
2018-05-31 13:33:27 +02:00
|
|
|
|
2019-04-29 21:32:35 +02:00
|
|
|
void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs) {
|
2018-05-31 13:33:27 +02:00
|
|
|
for (int i = 0; i < attribs->n_planes; ++i) {
|
|
|
|
close(attribs->fd[i]);
|
|
|
|
attribs->fd[i] = -1;
|
|
|
|
}
|
|
|
|
attribs->n_planes = 0;
|
|
|
|
}
|
2019-04-29 21:32:35 +02:00
|
|
|
|
|
|
|
bool wlr_dmabuf_attributes_copy(struct wlr_dmabuf_attributes *dst,
|
2021-02-02 19:53:16 +01:00
|
|
|
const struct wlr_dmabuf_attributes *src) {
|
2023-08-03 12:07:27 +02:00
|
|
|
*dst = *src;
|
2019-04-29 21:32:35 +02:00
|
|
|
|
2021-02-02 19:52:20 +01:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < src->n_planes; ++i) {
|
2019-04-29 21:32:35 +02:00
|
|
|
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");
|
2021-02-02 19:52:20 +01:00
|
|
|
goto error;
|
2019-04-29 21:32:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2021-02-02 19:52:20 +01:00
|
|
|
|
|
|
|
error:
|
|
|
|
for (int j = 0; j < i; j++) {
|
2022-06-06 06:50:41 +02:00
|
|
|
close(dst->fd[j]);
|
2021-02-02 19:52:20 +01:00
|
|
|
dst->fd[j] = -1;
|
|
|
|
}
|
|
|
|
dst->n_planes = 0;
|
|
|
|
return false;
|
2019-04-29 21:32:35 +02:00
|
|
|
}
|