[PATCH wayland] shm: add getters for the fd and offset

Derek Foreman derekf at osg.samsung.com
Fri Jul 17 14:27:00 PDT 2015


On 01/07/15 03:25 AM, Giulio Camuffo wrote:
> This allows to share the buffer data by mmapping the fd again.

Does it really?  If the client's closed its mapping then it's gone,
isn't it?

Also, if we might need it later it would be better not unmapping in the
first place.

I think I've got a patch that targets the same problem, I'll send in a
moment...


> ---
>  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;
>  
>  	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;
>  }
>  
> +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