mirror of
https://github.com/brl/mutter.git
synced 2024-11-23 08:30:42 -05:00
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:
parent
ae4d299499
commit
5b07ccd0a7
@ -34,6 +34,10 @@
|
|||||||
#include "cogl-dma-buf-handle.h"
|
#include "cogl-dma-buf-handle.h"
|
||||||
#include "cogl-object.h"
|
#include "cogl-object.h"
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <gio/gio.h>
|
||||||
|
#include <linux/dma-buf.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
struct _CoglDmaBufHandle
|
struct _CoglDmaBufHandle
|
||||||
@ -96,6 +100,53 @@ cogl_dma_buf_handle_free (CoglDmaBufHandle *dmabuf_handle)
|
|||||||
g_free (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 *
|
CoglFramebuffer *
|
||||||
cogl_dma_buf_handle_get_framebuffer (CoglDmaBufHandle *dmabuf_handle)
|
cogl_dma_buf_handle_get_framebuffer (CoglDmaBufHandle *dmabuf_handle)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +63,14 @@ cogl_dma_buf_handle_new (CoglFramebuffer *framebuffer,
|
|||||||
COGL_EXPORT void
|
COGL_EXPORT void
|
||||||
cogl_dma_buf_handle_free (CoglDmaBufHandle *dmabuf_handle);
|
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)
|
* cogl_dma_buf_handle_get_framebuffer: (skip)
|
||||||
*
|
*
|
||||||
|
@ -17,6 +17,7 @@ cogl_config_h = configure_file(
|
|||||||
|
|
||||||
cogl_pkg_deps = [
|
cogl_pkg_deps = [
|
||||||
glib_dep,
|
glib_dep,
|
||||||
|
gio_dep,
|
||||||
gobject_dep,
|
gobject_dep,
|
||||||
graphene_dep,
|
graphene_dep,
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user