mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 01:20:42 -05:00
cogl/dma-buf: Add mmap/munmap helpers
Avoids dealing directly with mmap() and munmap(). https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1237
This commit is contained in:
parent
5b07ccd0a7
commit
f8daa6bc70
@ -38,6 +38,7 @@
|
||||
#include <gio/gio.h>
|
||||
#include <linux/dma-buf.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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)
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user