cogl/dma-buf: Add API to synchronize reading

Used before and after accessing DMA buffer content using mmap().

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1237
This commit is contained in:
Jonas Ådahl 2020-05-06 21:40:40 +02:00 committed by Georges Basile Stavracas Neto
parent ae4d299499
commit 5b07ccd0a7
3 changed files with 60 additions and 0 deletions

View File

@ -34,6 +34,10 @@
#include "cogl-dma-buf-handle.h"
#include "cogl-object.h"
#include <errno.h>
#include <gio/gio.h>
#include <linux/dma-buf.h>
#include <sys/ioctl.h>
#include <unistd.h>
struct _CoglDmaBufHandle
@ -96,6 +100,53 @@ cogl_dma_buf_handle_free (CoglDmaBufHandle *dmabuf_handle)
g_free (dmabuf_handle);
}
static gboolean
sync_read (CoglDmaBufHandle *dmabuf_handle,
uint64_t start_or_end,
GError **error)
{
struct dma_buf_sync sync = { 0 };
sync.flags = start_or_end | DMA_BUF_SYNC_READ;
while (TRUE)
{
int ret;
ret = ioctl (dmabuf_handle->dmabuf_fd, DMA_BUF_IOCTL_SYNC, &sync);
if (ret == -1 && errno == EINTR)
{
continue;
}
else if (ret == -1)
{
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno),
"ioctl: %s", g_strerror (errno));
return FALSE;
}
else
{
break;
}
}
return TRUE;
}
gboolean
cogl_dma_buf_handle_sync_read_start (CoglDmaBufHandle *dmabuf_handle,
GError **error)
{
return sync_read (dmabuf_handle, DMA_BUF_SYNC_START, error);
}
gboolean
cogl_dma_buf_handle_sync_read_end (CoglDmaBufHandle *dmabuf_handle,
GError **error)
{
return sync_read (dmabuf_handle, DMA_BUF_SYNC_END, error);
}
CoglFramebuffer *
cogl_dma_buf_handle_get_framebuffer (CoglDmaBufHandle *dmabuf_handle)
{

View File

@ -63,6 +63,14 @@ cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer,
COGL_EXPORT void
cogl_dma_buf_handle_free (CoglDmaBufHandle *dmabuf_handle);
COGL_EXPORT gboolean
cogl_dma_buf_handle_sync_read_start (CoglDmaBufHandle *dmabuf_handle,
GError **error);
COGL_EXPORT gboolean
cogl_dma_buf_handle_sync_read_end (CoglDmaBufHandle *dmabuf_handle,
GError **error);
/**
* cogl_dma_buf_handle_get_framebuffer: (skip)
*

View File

@ -17,6 +17,7 @@ cogl_config_h = configure_file(
cogl_pkg_deps = [
glib_dep,
gio_dep,
gobject_dep,
graphene_dep,
]