mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
render/dmabuf: add wlr_dmabuf_attributes_copy
This commit is contained in:
parent
5c78f1b0d5
commit
6dbdf5db34
2 changed files with 25 additions and 1 deletions
|
@ -9,6 +9,7 @@
|
||||||
#ifndef WLR_RENDER_DMABUF_H
|
#ifndef WLR_RENDER_DMABUF_H
|
||||||
#define WLR_RENDER_DMABUF_H
|
#define WLR_RENDER_DMABUF_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define WLR_DMABUF_MAX_PLANES 4
|
#define WLR_DMABUF_MAX_PLANES 4
|
||||||
|
@ -35,5 +36,10 @@ struct wlr_dmabuf_attributes {
|
||||||
* Closes all file descriptors in the DMA-BUF attributes.
|
* Closes all file descriptors in the DMA-BUF attributes.
|
||||||
*/
|
*/
|
||||||
void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs);
|
void wlr_dmabuf_attributes_finish(struct wlr_dmabuf_attributes *attribs);
|
||||||
|
/**
|
||||||
|
* Clones the DMA-BUF attributes.
|
||||||
|
*/
|
||||||
|
bool wlr_dmabuf_attributes_copy(struct wlr_dmabuf_attributes *dst,
|
||||||
|
struct wlr_dmabuf_attributes *src);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,10 +1,28 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wlr/render/dmabuf.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) {
|
for (int i = 0; i < attribs->n_planes; ++i) {
|
||||||
close(attribs->fd[i]);
|
close(attribs->fd[i]);
|
||||||
attribs->fd[i] = -1;
|
attribs->fd[i] = -1;
|
||||||
}
|
}
|
||||||
attribs->n_planes = 0;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue