Add wl_resource_init and use it in libwayland implementations of data sharing and SHM
This commit adds a wl_resource_init function for initializing wl_resource structures similar to wl_client_add_object. From this commit forward, wl_resource structures should not be initialized manually, but should use wl_resource_init. In the event of a change to the wl_resource structure, this allows us to protect against regressions by filling in added fields with reasonable defaults. In this way, while changing wl_object or wl_resource still constitutes an ABI break, compositors following this rule will only need to be recompiled in order to properly link against the new version. Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
parent
ca5b1946cb
commit
bedc3432ff
|
@ -98,13 +98,9 @@ wl_data_source_send_offer(struct wl_data_source *source,
|
|||
if (offer == NULL)
|
||||
return NULL;
|
||||
|
||||
wl_resource_init(&offer->resource, &wl_data_offer_interface,
|
||||
&data_offer_interface, 0, offer);
|
||||
offer->resource.destroy = destroy_data_offer;
|
||||
offer->resource.object.id = 0;
|
||||
offer->resource.object.interface = &wl_data_offer_interface;
|
||||
offer->resource.object.implementation =
|
||||
(void (**)(void)) &data_offer_interface;
|
||||
offer->resource.data = offer;
|
||||
wl_signal_init(&offer->resource.destroy_signal);
|
||||
|
||||
offer->source = source;
|
||||
offer->source_destroy_listener.notify = destroy_offer_data_source;
|
||||
|
@ -459,13 +455,9 @@ create_data_source(struct wl_client *client,
|
|||
return;
|
||||
}
|
||||
|
||||
wl_resource_init(&source->resource, &wl_data_source_interface,
|
||||
&data_source_interface, id, source);
|
||||
source->resource.destroy = destroy_data_source;
|
||||
source->resource.object.id = id;
|
||||
source->resource.object.interface = &wl_data_source_interface;
|
||||
source->resource.object.implementation =
|
||||
(void (**)(void)) &data_source_interface;
|
||||
source->resource.data = source;
|
||||
wl_signal_init(&source->resource.destroy_signal);
|
||||
|
||||
source->accept = client_source_accept;
|
||||
source->send = client_source_send;
|
||||
|
|
|
@ -1396,13 +1396,9 @@ wl_client_add_object(struct wl_client *client,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
resource->object.interface = interface;
|
||||
resource->object.implementation = implementation;
|
||||
resource->object.id = id;
|
||||
wl_resource_init(resource, interface, implementation, id, data);
|
||||
resource->client = client;
|
||||
resource->data = data;
|
||||
resource->destroy = (void *) free;
|
||||
wl_signal_init(&resource->destroy_signal);
|
||||
|
||||
if (wl_map_insert_at(&client->objects, resource->object.id, resource) < 0) {
|
||||
wl_resource_post_error(client->display_resource,
|
||||
|
|
|
@ -190,6 +190,22 @@ 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;
|
||||
|
|
|
@ -128,12 +128,8 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
|
|||
buffer->pool = pool;
|
||||
pool->refcount++;
|
||||
|
||||
buffer->buffer.resource.object.id = id;
|
||||
buffer->buffer.resource.object.interface = &wl_buffer_interface;
|
||||
buffer->buffer.resource.object.implementation = (void (**)(void))
|
||||
&shm_buffer_interface;
|
||||
|
||||
buffer->buffer.resource.data = buffer;
|
||||
wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface,
|
||||
&shm_buffer_interface, id, buffer);
|
||||
buffer->buffer.resource.client = resource->client;
|
||||
buffer->buffer.resource.destroy = destroy_buffer;
|
||||
|
||||
|
@ -211,12 +207,8 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
|
|||
}
|
||||
close(fd);
|
||||
|
||||
pool->resource.object.id = id;
|
||||
pool->resource.object.interface = &wl_shm_pool_interface;
|
||||
pool->resource.object.implementation =
|
||||
(void (**)(void)) &shm_pool_interface;
|
||||
|
||||
pool->resource.data = pool;
|
||||
wl_resource_init(&pool->resource, &wl_shm_pool_interface,
|
||||
&shm_pool_interface, id, pool);
|
||||
pool->resource.client = client;
|
||||
pool->resource.destroy = destroy_pool;
|
||||
|
||||
|
@ -283,12 +275,8 @@ wl_shm_buffer_create(struct wl_client *client,
|
|||
buffer->offset = 0;
|
||||
buffer->pool = NULL;
|
||||
|
||||
buffer->buffer.resource.object.id = id;
|
||||
buffer->buffer.resource.object.interface = &wl_buffer_interface;
|
||||
buffer->buffer.resource.object.implementation = (void (**)(void))
|
||||
&shm_buffer_interface;
|
||||
|
||||
buffer->buffer.resource.data = buffer;
|
||||
wl_resource_init(&buffer->buffer.resource, &wl_buffer_interface,
|
||||
&shm_buffer_interface, id, buffer);
|
||||
buffer->buffer.resource.client = client;
|
||||
buffer->buffer.resource.destroy = destroy_buffer;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user