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

Giulio Camuffo giuliocamuffo at gmail.com
Sat Jul 18 02:51:45 PDT 2015


2015-07-18 0:27 GMT+03:00 Derek Foreman <derekf at osg.samsung.com>:
> 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...

Uhm no... i wasn't trying to fix a bug, this patch is for implementing
this: https://github.com/giucam/weston/commit/63ee1aa3fa5c27f3fa3fbc22e9c285e6e75aa860

>
>
>> ---
>>  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