[PATCH wayland 1/4] server: Make wl_object and wl_resource opaque structs

Kristian Høgsberg hoegsberg at gmail.com
Mon Jul 1 22:13:20 PDT 2013


On Thu, Jun 27, 2013 at 08:09:18PM -0500, Jason Ekstrand wrote:
> From: Kristian Høgsberg <krh at bitplanet.net>
> 
> With the work to add wl_resource accessors and port weston to use them,
> we're ready to make wl_resource and wl_object opaque structs.  We keep
> wl_buffer in the header for EGL stacks to use, but don't expose it by
> default.  In time we'll remove it completely, but for now it provides a
> transition paths for code that still uses wl_buffer.
> 
> Reviewed-by: Jason Ekstrand<jason at jlekstrand.net>
> ---
>  src/scanner.c         |  2 +-
>  src/wayland-client.c  |  4 ++--
>  src/wayland-private.h |  6 ++++++
>  src/wayland-server.c  | 23 +++++++++++++++++++++--
>  src/wayland-server.h  | 42 +++++++++++++++---------------------------
>  src/wayland-shm.c     |  3 +++
>  src/wayland-util.h    |  6 ------
>  7 files changed, 48 insertions(+), 38 deletions(-)
> 
> diff --git a/src/scanner.c b/src/scanner.c
> index 9c14ad3..6ed93f0 100644
> --- a/src/scanner.c
> +++ b/src/scanner.c
> @@ -829,7 +829,7 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
>  			else if (is_interface && a->type == NEW_ID && a->interface_name == NULL)
>  				printf("const char *interface, uint32_t version, uint32_t ");
>  			else if (!is_interface && a->type == OBJECT && a->interface_name == NULL)
> -				printf("struct wl_object *");
> +				printf("struct wl_proxy *");

I made a similar tweak locally, but I went with void * over struct
wl_proxy *, since this could potentally also be used for code
generated for server side.

>  			else if (!is_interface && a->type == NEW_ID)
>  				printf("struct %s *", a->interface_name);
> diff --git a/src/wayland-client.c b/src/wayland-client.c
> index ec01cdd..838229d 100644
> --- a/src/wayland-client.c
> +++ b/src/wayland-client.c
> @@ -388,13 +388,13 @@ wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...)
>  
>  static void
>  display_handle_error(void *data,
> -		     struct wl_display *display, struct wl_object *object,
> +		     struct wl_display *display, struct wl_proxy *proxy,
>  		     uint32_t code, const char *message)
>  {
>  	int err;
>  
>  	wl_log("%s@%u: error %d: %s\n",
> -	       object->interface->name, object->id, code, message);
> +	       proxy->object.interface->name, proxy->object.id, code, message);
>  
>  	switch (code) {
>  	case WL_DISPLAY_ERROR_INVALID_OBJECT:
> diff --git a/src/wayland-private.h b/src/wayland-private.h
> index 71066b5..eec7dff 100644
> --- a/src/wayland-private.h
> +++ b/src/wayland-private.h
> @@ -39,6 +39,12 @@
>  #define WL_SERVER_ID_START 0xff000000
>  #define WL_CLOSURE_MAX_ARGS 20
>  
> +struct wl_object {
> +	const struct wl_interface *interface;
> +	const void *implementation;
> +	uint32_t id;
> +};
> +
>  extern struct wl_object global_zombie_object;
>  #define WL_ZOMBIE_OBJECT ((void*)&global_zombie_object)
>  
> diff --git a/src/wayland-server.c b/src/wayland-server.c
> index 7907283..0c3fbc9 100644
> --- a/src/wayland-server.c
> +++ b/src/wayland-server.c
> @@ -102,6 +102,15 @@ struct wl_global {
>  	struct wl_list link;
>  };
>  
> +struct wl_resource {
> +	struct wl_object object;
> +	wl_resource_destroy_func_t destroy;
> +	struct wl_list link;
> +	struct wl_signal destroy_signal;
> +	struct wl_client *client;
> +	void *data;
> +};
> +
>  static int wl_debug = 0;
>  
>  static void
> @@ -373,6 +382,10 @@ wl_client_get_credentials(struct wl_client *client,
>  		*gid = client->ucred.gid;
>  }
>  
> +uint32_t
> +wl_client_add_resource(struct wl_client *client,
> +		       struct wl_resource *resource) WL_DEPRECATED;
> +
>  WL_EXPORT uint32_t
>  wl_client_add_resource(struct wl_client *client,
>  		       struct wl_resource *resource)
> @@ -996,9 +1009,15 @@ wl_client_add_object(struct wl_client *client,
>  		return NULL;
>  	}
>  
> -	wl_resource_init(resource, interface, implementation, id, data);
> -	resource->client = client;
> +	resource->object.id = id;
> +	resource->object.interface = interface;
> +	resource->object.implementation = implementation;
> +
> +	wl_signal_init(&resource->destroy_signal);
> +
>  	resource->destroy = NULL;
> +	resource->client = client;
> +	resource->data = data;
>  
>  	if (wl_map_insert_at(&client->objects, 0, resource->object.id, resource) < 0) {
>  		wl_resource_post_error(client->display_resource,
> diff --git a/src/wayland-server.h b/src/wayland-server.h
> index 515efe5..7c53cfc 100644
> --- a/src/wayland-server.h
> +++ b/src/wayland-server.h
> @@ -181,12 +181,14 @@ wl_signal_emit(struct wl_signal *signal, void *data)
>  
>  typedef void (*wl_resource_destroy_func_t)(struct wl_resource *resource);
>  
> -/* The wl_resource structure has be deprecated as a transparent structure.
> - * While wl_resource will still exist, it will, in the future, be an opaque
> - * pointer.  Instead of accessing wl_resource directly, it should be created by
> - * wl_client_add_object and wl_client_new_object and only accessed by the
> - * accessor functions provided.
> - */
> +#ifdef WL_USE_LEGACY_WL_BUFFER

I ended up reversing the sense of this conditional and made it #ifndef
WL_HIDE_DEPRECATED instead.  We don't break ABI, but break the API is
bad enough.  Let's at least keep it like this for now and wait for a
mesa release that #defines WL_HIDE_DEPRECATED and compiles like that.

> +struct wl_object {
> +	const struct wl_interface *interface;
> +	const void *implementation;
> +	uint32_t id;
> +};
> +
>  struct wl_resource {
>  	struct wl_object object;
>  	wl_resource_destroy_func_t destroy;
> @@ -196,27 +198,17 @@ struct wl_resource {
>  	void *data;
>  };
>  
> -static inline void
> -wl_resource_init(struct wl_resource *resource,
> -		 const struct wl_interface *interface,
> -		 const void *implementation, uint32_t id, void *data)
> -{
> -	resource->object.id = id;
> -	resource->object.interface = interface;
> -	resource->object.implementation = implementation;
> -
> -	wl_signal_init(&resource->destroy_signal);
> -
> -	resource->destroy = NULL;
> -	resource->client = NULL;
> -	resource->data = data;
> -}
> -
>  struct wl_buffer {
>  	struct wl_resource resource;
>  	int32_t width, height;
>  	uint32_t busy_count;
> -};
> +} WL_DEPRECATED;
> +
> +uint32_t
> +wl_client_add_resource(struct wl_client *client,
> +		       struct wl_resource *resource) WL_DEPRECATED;
> +
> +#endif
>  
>  /*
>   * Post an event to the client's object referred to by 'resource'.
> @@ -247,10 +239,6 @@ void wl_resource_post_no_memory(struct wl_resource *resource);
>  
>  #include "wayland-server-protocol.h"
>  
> -uint32_t
> -wl_client_add_resource(struct wl_client *client,
> -		       struct wl_resource *resource) WL_DEPRECATED;
> -
>  struct wl_display *
>  wl_client_get_display(struct wl_client *client);
>  
> diff --git a/src/wayland-shm.c b/src/wayland-shm.c
> index c2e1df0..8a10253 100644
> --- a/src/wayland-shm.c
> +++ b/src/wayland-shm.c
> @@ -283,6 +283,9 @@ wl_shm_buffer_create(struct wl_client *client,
>  WL_EXPORT struct wl_shm_buffer *
>  wl_shm_buffer_get(struct wl_resource *resource)
>  {
> +	if (resource == NULL)
> +		return NULL;
> +
>  	if (wl_resource_instance_of(resource, &wl_buffer_interface,
>  				    &shm_buffer_interface))
>  		return wl_resource_get_user_data(resource);
> diff --git a/src/wayland-util.h b/src/wayland-util.h
> index 119fa33..53d3282 100644
> --- a/src/wayland-util.h
> +++ b/src/wayland-util.h
> @@ -61,12 +61,6 @@ struct wl_interface {
>  	const struct wl_message *events;
>  };
>  
> -struct wl_object {
> -	const struct wl_interface *interface;
> -	const void *implementation;
> -	uint32_t id;
> -};
> -
>  /**
>   * wl_list - linked list
>   *
> -- 
> 1.8.2.1
> 


More information about the wayland-devel mailing list