compositor: redesign how resources are managed

All public resource creators now take a new ID for the resource
and an optional list where the resource link is added. When the
resource is destroyed it is its own responsibility to remove
itself from the list. This removes the need for the caller to add
a destroy listener.

This commit fixes a few segfaults with resources not removed from
the list when destroyed.
This commit is contained in:
emersion 2018-04-26 17:51:06 +01:00
parent 979b1b22d5
commit 43012f3740
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
5 changed files with 90 additions and 76 deletions

View file

@ -6,9 +6,11 @@
struct wl_resource;
/*
* Implements the given resource as region.
* Creates a new region resource with the provided new ID. If `resource_list` is
* non-NULL, adds the region's resource to the list.
*/
struct wl_resource *wlr_region_create(struct wl_client *client, uint32_t id);
struct wl_resource *wlr_region_create(struct wl_client *client,
uint32_t version, uint32_t id, struct wl_list *resource_list);
pixman_region32_t *wlr_region_from_resource(struct wl_resource *resource);

View file

@ -80,10 +80,6 @@ struct wlr_surface {
struct wl_signal destroy;
} events;
// destroy listener used by compositor
struct wl_listener compositor_listener;
void *compositor_data;
// surface commit callback for the role that runs before all others
void (*role_committed)(struct wlr_surface *surface, void *role_data);
void *role_data;
@ -102,8 +98,14 @@ typedef void (*wlr_surface_iterator_func_t)(struct wlr_surface *surface,
int sx, int sy, void *data);
struct wlr_renderer;
struct wlr_surface *wlr_surface_create(struct wl_resource *res,
struct wlr_renderer *renderer);
/**
* Create a new surface resource with the provided new ID. If `resource_list`
* is non-NULL, adds the surface's resource to the list.
*/
struct wlr_surface *wlr_surface_create(struct wl_client *client,
uint32_t version, uint32_t id, struct wlr_renderer *renderer,
struct wl_list *resource_list);
/**
* Set the lifetime role for this surface. Returns 0 on success or -1 if the
@ -121,10 +123,12 @@ int wlr_surface_set_role(struct wlr_surface *surface, const char *role,
bool wlr_surface_has_buffer(struct wlr_surface *surface);
/**
* Create the subsurface implementation for this surface.
* Create a new subsurface resource with the provided new ID. If `resource_list`
* is non-NULL, adds the subsurface's resource to the list.
*/
struct wlr_subsurface *wlr_surface_make_subsurface(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t id);
struct wlr_subsurface *wlr_subsurface_create(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t version, uint32_t id,
struct wl_list *resource_list);
/**
* Get the root of the subsurface tree for this surface.