summaryrefslogtreecommitdiff
path: root/cogl
diff options
context:
space:
mode:
Diffstat (limited to 'cogl')
-rw-r--r--cogl/cogl/cogl-dma-buf-handle.c51
-rw-r--r--cogl/cogl/cogl-dma-buf-handle.h8
-rw-r--r--cogl/meson.build1
3 files changed, 60 insertions, 0 deletions
diff --git a/cogl/cogl/cogl-dma-buf-handle.c b/cogl/cogl/cogl-dma-buf-handle.c
index d8b4e57c5..7e86e2267 100644
--- a/cogl/cogl/cogl-dma-buf-handle.c
+++ b/cogl/cogl/cogl-dma-buf-handle.c
@@ -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)
{
diff --git a/cogl/cogl/cogl-dma-buf-handle.h b/cogl/cogl/cogl-dma-buf-handle.h
index b00c5f36b..a329de668 100644
--- a/cogl/cogl/cogl-dma-buf-handle.h
+++ b/cogl/cogl/cogl-dma-buf-handle.h
@@ -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)
*
diff --git a/cogl/meson.build b/cogl/meson.build
index e0ea1ed97..a3c61cfb7 100644
--- a/cogl/meson.build
+++ b/cogl/meson.build
@@ -17,6 +17,7 @@ cogl_config_h = configure_file(
cogl_pkg_deps = [
glib_dep,
+ gio_dep,
gobject_dep,
graphene_dep,
]