aboutsummaryrefslogtreecommitdiff
path: root/render/dmabuf.c
blob: bed609dd08e50988560bfc64067a6d18291e56d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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) {
	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;
}