[PATCH wayland] shm: add getters for the fd and offset
Derek Foreman
derekf at osg.samsung.com
Mon Oct 5 11:39:32 PDT 2015
Sigh, realized this is still in patchwork and I never actually gave it a
proper look.
Sorry.
On 01/07/15 03:25 AM, Giulio Camuffo wrote:
> This allows to share the buffer data by mmapping the fd again.
> ---
> 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 7d03789..938cdf7 100644
> --- a/src/wayland-server-core.h
> +++ b/src/wayland-server-core.h
> @@ -396,6 +396,12 @@ wl_shm_buffer_create(struct wl_client *client,
> uint32_t id, int32_t width, int32_t height,
> int32_t stride, uint32_t format);
>
> +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 b6b31d6..c85e839 100644
> --- a/src/wayland-shm.c
> +++ b/src/wayland-shm.c
> @@ -52,6 +52,7 @@ struct wl_shm_pool {
> int refcount;
> char *data;
> int32_t size;
> + int fd;
> };
>
> struct wl_shm_buffer {
> @@ -77,6 +78,7 @@ shm_pool_unref(struct wl_shm_pool *pool)
> return;
>
> munmap(pool->data, pool->size);
> + close(pool->fd);
> free(pool);
> }
>
> @@ -250,7 +252,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;
I'm a little concerned that we now end up keeping an fd open for every
active shm_pool. That could conceivably be every surface, subsurface,
and mouse cursor set an app is using?
Why do we need a second mapping? Can't we just re-use the existing data
pointer? (and do all the horrific refcounting required to make that
viable, I guess)
>
> pool->resource =
> wl_resource_create(client, &wl_shm_pool_interface, 1, id);
> @@ -409,6 +411,18 @@ wl_shm_buffer_get_height(struct wl_shm_buffer *buffer)
> return buffer->height;
> }
I guess we should have doxygen for the new APIs...
> +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)
> {
>
More information about the wayland-devel
mailing list