dmabuf: Add gdk_dmabuf_ioctl()

The function is a copy of libdrm's drmIoctl() and handles EINTR and
EAGAIN error.s

Use it for the sync ioctls in the dmabuf mmaping calls.
This commit is contained in:
Benjamin Otte
2023-11-26 05:28:34 +01:00
parent c414889cfa
commit a37b3fb691
2 changed files with 20 additions and 2 deletions

View File

@@ -741,7 +741,7 @@ gdk_dmabuf_direct_downloader_do_download (const GdkDmabufDownloader *downloader,
/* be a good citizen and seek back to the start, as the docs recommend */
lseek (dmabuf->planes[i].fd, 0, SEEK_SET);
if (ioctl (dmabuf->planes[i].fd, DMA_BUF_IOCTL_SYNC, &(struct dma_buf_sync) { DMA_BUF_SYNC_START|DMA_BUF_SYNC_READ }) < 0)
if (gdk_dmabuf_ioctl (dmabuf->planes[i].fd, DMA_BUF_IOCTL_SYNC, &(struct dma_buf_sync) { DMA_BUF_SYNC_START|DMA_BUF_SYNC_READ }) < 0)
g_warning ("Failed to sync dmabuf: %s", g_strerror (errno));
src_data[i] = mmap (NULL, sizes[i], PROT_READ, MAP_SHARED, dmabuf->planes[i].fd, dmabuf->planes[i].offset);
@@ -770,7 +770,7 @@ out:
munmap ((void *)src_data[i], sizes[i]);
if (ioctl (dmabuf->planes[i].fd, DMA_BUF_IOCTL_SYNC, &(struct dma_buf_sync) { DMA_BUF_SYNC_END|DMA_BUF_SYNC_READ }) < 0)
if (gdk_dmabuf_ioctl (dmabuf->planes[i].fd, DMA_BUF_IOCTL_SYNC, &(struct dma_buf_sync) { DMA_BUF_SYNC_END|DMA_BUF_SYNC_READ }) < 0)
g_warning ("Failed to sync dmabuf: %s", g_strerror (errno));
}
}
@@ -821,6 +821,20 @@ gdk_dmabuf_get_direct_downloader (void)
return &downloader;
}
int
gdk_dmabuf_ioctl (int fd,
unsigned long request,
void *arg)
{
int ret;
do {
ret = ioctl (fd, request, arg);
} while (ret == -1 && (errno == EINTR || errno == EAGAIN));
return ret;
}
/*
* Tries to sanitize the dmabuf to conform to the values expected
* by Vulkan/EGL which should also be the values expected by

View File

@@ -43,6 +43,10 @@ struct _GdkDmabufDownloader
const GdkDmabufDownloader * gdk_dmabuf_get_direct_downloader (void) G_GNUC_CONST;
const GdkDmabufDownloader * gdk_dmabuf_get_egl_downloader (void) G_GNUC_CONST;
int gdk_dmabuf_ioctl (int fd,
unsigned long request,
void *arg);
gboolean gdk_dmabuf_sanitize (GdkDmabuf *dest,
gsize width,
gsize height,