On Tue, Aug 06, 2013 at 08:05:53PM +0200, Tomeu Vizoso wrote:
> ---
>  src/wayland-private.h |  4 ++++
>  src/wayland-server.c  | 19 +++++++++++++++++++
>  src/wayland-server.h  |  3 +++
>  src/wayland-shm.c     | 45 ++++++++++++++++++++++++++++++++-------------
>  4 files changed, 58 insertions(+), 13 deletions(-)

These all look good now, thanks Tomeu.  All applied.

Kristian

> diff --git a/src/wayland-private.h b/src/wayland-private.h
> index a7d68c1..0126694 100644
> --- a/src/wayland-private.h
> +++ b/src/wayland-private.h
> @@ -29,6 +29,7 @@
>  
>  #define WL_HIDE_DEPRECATED 1
>  
> +#include "wayland-server.h"
>  #include "wayland-util.h"
>  
>  #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
> @@ -176,4 +177,7 @@ extern wl_log_func_t wl_log_handler;
>  
>  void wl_log(const char *fmt, ...);
>  
> +struct wl_array *
> +wl_display_get_additional_shm_formats(struct wl_display *display);
> +
>  #endif
> diff --git a/src/wayland-server.c b/src/wayland-server.c
> index 0a6e112..f3395df 100644
> --- a/src/wayland-server.c
> +++ b/src/wayland-server.c
> @@ -92,6 +92,8 @@ struct wl_display {
>       struct wl_list client_list;
>  
>       struct wl_signal destroy_signal;
> +
> +     struct wl_array additional_shm_formats;
>  };
>  
>  struct wl_global {
> @@ -717,6 +719,8 @@ wl_display_create(void)
>       display->id = 1;
>       display->serial = 0;
>  
> +     wl_array_init(&display->additional_shm_formats);
> +
>       if (!wl_global_create(display, &wl_display_interface, 1,
>                             display, bind_display)) {
>               wl_event_loop_destroy(display->loop);
> @@ -1174,3 +1178,18 @@ wl_display_remove_global(struct wl_display *display, 
> struct wl_global *global)
>  {
>       wl_global_destroy(global);
>  }
> +
> +WL_EXPORT void
> +wl_display_add_shm_format(struct wl_display *display, uint32_t format)
> +{
> +     uint32_t *p;
> +
> +     p = wl_array_add(&display->additional_shm_formats, sizeof *p);
> +     *p = format;
> +}
> +
> +struct wl_array *
> +wl_display_get_additional_shm_formats(struct wl_display *display)
> +{
> +     return &display->additional_shm_formats;
> +}
> diff --git a/src/wayland-server.h b/src/wayland-server.h
> index 9e16d0e..de389ea 100644
> --- a/src/wayland-server.h
> +++ b/src/wayland-server.h
> @@ -321,6 +321,9 @@ wl_shm_buffer_get_height(struct wl_shm_buffer *buffer);
>  int
>  wl_display_init_shm(struct wl_display *display);
>  
> +void
> +wl_display_add_shm_format(struct wl_display *display, uint32_t format);
> +
>  struct wl_shm_buffer *
>  wl_shm_buffer_create(struct wl_client *client,
>                    uint32_t id, int32_t width, int32_t height,
> diff --git a/src/wayland-shm.c b/src/wayland-shm.c
> index 1699058..eff29c3 100644
> --- a/src/wayland-shm.c
> +++ b/src/wayland-shm.c
> @@ -83,6 +83,27 @@ static const struct wl_buffer_interface 
> shm_buffer_interface = {
>       shm_buffer_destroy
>  };
>  
> +static int
> +format_is_supported(struct wl_client *client, uint32_t format)
> +{
> +     struct wl_display *display = wl_client_get_display(client);
> +     struct wl_array *formats;
> +     uint32_t *p;
> +
> +     switch (format) {
> +     case WL_SHM_FORMAT_ARGB8888:
> +     case WL_SHM_FORMAT_XRGB8888:
> +             return 1;
> +     default:
> +             formats = wl_display_get_additional_shm_formats(display);
> +             wl_array_for_each(p, formats)
> +                     if(*p == format)
> +                             return 1;
> +     }
> +
> +     return 0;
> +}
> +
>  static void
>  shm_pool_create_buffer(struct wl_client *client, struct wl_resource 
> *resource,
>                      uint32_t id, int32_t offset,
> @@ -92,14 +113,10 @@ shm_pool_create_buffer(struct wl_client *client, struct 
> wl_resource *resource,
>       struct wl_shm_pool *pool = wl_resource_get_user_data(resource);
>       struct wl_shm_buffer *buffer;
>  
> -     switch (format) {
> -     case WL_SHM_FORMAT_ARGB8888:
> -     case WL_SHM_FORMAT_XRGB8888:
> -             break;
> -     default:
> +     if (!format_is_supported(client, format)) {
>               wl_resource_post_error(resource,
>                                      WL_SHM_ERROR_INVALID_FORMAT,
> -                                    "invalid format");
> +                                    "invalid format 0x%x", format);
>               return;
>       }
>  
> @@ -242,6 +259,9 @@ bind_shm(struct wl_client *client,
>        void *data, uint32_t version, uint32_t id)
>  {
>       struct wl_resource *resource;
> +     struct wl_display *display = wl_client_get_display(client);
> +     struct wl_array *additional_formats;
> +     uint32_t *p;
>  
>       resource = wl_resource_create(client, &wl_shm_interface, 1, id);
>       if (!resource) {
> @@ -253,6 +273,10 @@ bind_shm(struct wl_client *client,
>  
>       wl_shm_send_format(resource, WL_SHM_FORMAT_ARGB8888);
>       wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);
> +
> +     additional_formats = wl_display_get_additional_shm_formats(display);
> +     wl_array_for_each(p, additional_formats)
> +             wl_shm_send_format(resource, *p);
>  }
>  
>  WL_EXPORT int
> @@ -270,14 +294,9 @@ wl_shm_buffer_create(struct wl_client *client,
>                    int32_t stride, uint32_t format)
>  {
>       struct wl_shm_buffer *buffer;
> -                          
> -     switch (format) {
> -     case WL_SHM_FORMAT_ARGB8888:
> -     case WL_SHM_FORMAT_XRGB8888:
> -             break;
> -     default:
> +
> +     if (!format_is_supported(client, format))
>               return NULL;
> -     }
>  
>       buffer = malloc(sizeof *buffer + stride * height);
>       if (buffer == NULL)
> -- 
> 1.8.3.1
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to