AtlatestRepositorysigil-ui
1
/* CLOSEFB retires ownership without disabling an active scanout plane. */2
#ifndef SIGIL_UI_SURFACE_CLOSE_H3
#define SIGIL_UI_SURFACE_CLOSE_H5
#include <errno.h>6
#include <stdint.h>7
#include <sys/ioctl.h>8
#include <sys/mman.h>9
#include <unistd.h>10
#include <drm/drm.h>11
#include <drm/drm_mode.h>13
/* Linux 6.8 UAPI, also usable with older libdrm headers. */14
#ifndef DRM_IOCTL_MODE_CLOSEFB15
struct drm_mode_closefb { uint32_t fb_id, pad; };16
#define DRM_IOCTL_MODE_CLOSEFB DRM_IOWR(0xD0, struct drm_mode_closefb)17
#endif19
static int preserve_frame(int fd, uint32_t framebuffer)20
{21
if (!framebuffer) return 0;22
struct drm_mode_closefb request = { .fb_id = framebuffer };23
int result;24
do {25
result = ioctl(fd, DRM_IOCTL_MODE_CLOSEFB, &request);26
} while (result < 0 && errno == EINTR);27
return result;28
}30
static int close_surface(int *fd, uint32_t *framebuffer, uint8_t **map, size_t size, int keep_frame)31
{32
if (*fd >= 0 && keep_frame && preserve_frame(*fd, *framebuffer) < 0) return -1;33
if (*map) { munmap(*map, size); *map = NULL; }34
if (*fd >= 0) { close(*fd); *fd = -1; }35
*framebuffer = 0;36
return 0;37
}38
#endif