diff --git a/cogl/cogl/cogl-dma-buf-handle.c b/cogl/cogl/cogl-dma-buf-handle.c index 7e86e2267..9724ac9c9 100644 --- a/cogl/cogl/cogl-dma-buf-handle.c +++ b/cogl/cogl/cogl-dma-buf-handle.c @@ -38,6 +38,7 @@ #include #include #include +#include #include struct _CoglDmaBufHandle @@ -147,6 +148,46 @@ cogl_dma_buf_handle_sync_read_end (CoglDmaBufHandle *dmabuf_handle, return sync_read (dmabuf_handle, DMA_BUF_SYNC_END, error); } +gpointer +cogl_dma_buf_handle_mmap (CoglDmaBufHandle *dmabuf_handle, + GError **error) +{ + size_t size; + gpointer data; + + size = dmabuf_handle->height * dmabuf_handle->stride; + + data = mmap (NULL, size, PROT_READ, MAP_PRIVATE, + dmabuf_handle->dmabuf_fd, + dmabuf_handle->offset); + if (data == MAP_FAILED) + { + g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), + "mmap failed: %s", g_strerror (errno)); + return NULL; + } + + return data; +} + +gboolean +cogl_dma_buf_handle_munmap (CoglDmaBufHandle *dmabuf_handle, + gpointer data, + GError **error) +{ + size_t size; + + size = dmabuf_handle->height * dmabuf_handle->stride; + if (munmap (data, size) != 0) + { + g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errno), + "munmap failed: %s", g_strerror (errno)); + return FALSE; + } + + return TRUE; +} + 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 a329de668..c505ff76c 100644 --- a/cogl/cogl/cogl-dma-buf-handle.h +++ b/cogl/cogl/cogl-dma-buf-handle.h @@ -71,6 +71,15 @@ COGL_EXPORT gboolean cogl_dma_buf_handle_sync_read_end (CoglDmaBufHandle *dmabuf_handle, GError **error); +COGL_EXPORT gpointer +cogl_dma_buf_handle_mmap (CoglDmaBufHandle *dmabuf_handle, + GError **error); + +COGL_EXPORT gboolean +cogl_dma_buf_handle_munmap (CoglDmaBufHandle *dmabuf_handle, + gpointer data, + GError **error); + /** * cogl_dma_buf_handle_get_framebuffer: (skip) *