From: Giulio Camuffo <[email protected]>

This allows to share the buffer data by mmapping the fd again.
Reviewed-by: David FORT <[email protected]>

Signed-off-by: Derek Foreman <[email protected]>
---
 src/wayland-server-core.h |  6 ++++++
 src/wayland-shm.c         | 16 +++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/wayland-server-core.h b/src/wayland-server-core.h
index e8e1e9c..3316022 100644
--- a/src/wayland-server-core.h
+++ b/src/wayland-server-core.h
@@ -480,6 +480,12 @@ wl_shm_buffer_create(struct wl_client *client,
                     uint32_t id, int32_t width, int32_t height,
                     int32_t stride, uint32_t format) WL_DEPRECATED;
 
+int
+wl_shm_buffer_get_offset(struct wl_shm_buffer *buffer);
+
+int
+wl_shm_buffer_get_fd(struct wl_shm_buffer *buffer);
+
 void wl_log_set_handler_server(wl_log_func_t handler);
 
 #ifdef  __cplusplus
diff --git a/src/wayland-shm.c b/src/wayland-shm.c
index a4343a4..911165d 100644
--- a/src/wayland-shm.c
+++ b/src/wayland-shm.c
@@ -55,6 +55,7 @@ struct wl_shm_pool {
        int refcount;
        char *data;
        int32_t size;
+       int fd;
 };
 
 struct wl_shm_buffer {
@@ -80,6 +81,7 @@ shm_pool_unref(struct wl_shm_pool *pool)
                return;
 
        munmap(pool->data, pool->size);
+       close(pool->fd);
        free(pool);
 }
 
@@ -253,7 +255,7 @@ shm_create_pool(struct wl_client *client, struct 
wl_resource *resource,
                                       "failed mmap fd %d", fd);
                goto err_close;
        }
-       close(fd);
+       pool->fd = fd;
 
        pool->resource =
                wl_resource_create(client, &wl_shm_pool_interface, 1, id);
@@ -421,6 +423,18 @@ wl_shm_pool_unref(struct wl_shm_pool *pool)
        shm_pool_unref(pool);
 }
 
+WL_EXPORT int
+wl_shm_buffer_get_offset(struct wl_shm_buffer *buffer)
+{
+       return buffer->offset;
+}
+
+WL_EXPORT int
+wl_shm_buffer_get_fd(struct wl_shm_buffer *buffer)
+{
+       return buffer->pool->fd;
+}
+
 static void
 reraise_sigbus(void)
 {
-- 
2.7.0

_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to