mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-24 13:45:58 +01:00
compositor: use compositor to get renderer
This allows us to remove the renderer destroy listener. The listener was buggy: compositors can't destroy surface resources on their own. The wlr_compositor will always outlive the wlr_surface, so no need for a destroy listener.
This commit is contained in:
parent
508d8c9a01
commit
3075e6a6f9
2 changed files with 6 additions and 22 deletions
|
@ -121,7 +121,7 @@ struct wlr_surface_output {
|
||||||
|
|
||||||
struct wlr_surface {
|
struct wlr_surface {
|
||||||
struct wl_resource *resource;
|
struct wl_resource *resource;
|
||||||
struct wlr_renderer *renderer; // may be NULL
|
struct wlr_compositor *compositor;
|
||||||
/**
|
/**
|
||||||
* The surface's buffer, if any. A surface has an attached buffer when it
|
* The surface's buffer, if any. A surface has an attached buffer when it
|
||||||
* commits with a non-null buffer in its pending state. A surface will not
|
* commits with a non-null buffer in its pending state. A surface will not
|
||||||
|
@ -212,7 +212,6 @@ struct wlr_surface {
|
||||||
|
|
||||||
// private state
|
// private state
|
||||||
|
|
||||||
struct wl_listener renderer_destroy;
|
|
||||||
struct wl_listener role_resource_destroy;
|
struct wl_listener role_resource_destroy;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -426,12 +426,12 @@ static void surface_apply_damage(struct wlr_surface *surface) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (surface->renderer == NULL) {
|
if (surface->compositor->renderer == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_client_buffer *buffer = wlr_client_buffer_create(
|
struct wlr_client_buffer *buffer = wlr_client_buffer_create(
|
||||||
surface->current.buffer, surface->renderer);
|
surface->current.buffer, surface->compositor->renderer);
|
||||||
|
|
||||||
if (buffer == NULL) {
|
if (buffer == NULL) {
|
||||||
wlr_log(WLR_ERROR, "Failed to upload buffer");
|
wlr_log(WLR_ERROR, "Failed to upload buffer");
|
||||||
|
@ -736,7 +736,6 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
||||||
surface_state_destroy_cached(cached, surface);
|
surface_state_destroy_cached(cached, surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_remove(&surface->renderer_destroy.link);
|
|
||||||
wl_list_remove(&surface->role_resource_destroy.link);
|
wl_list_remove(&surface->role_resource_destroy.link);
|
||||||
|
|
||||||
wl_list_remove(&surface->pending_buffer_resource_destroy.link);
|
wl_list_remove(&surface->pending_buffer_resource_destroy.link);
|
||||||
|
@ -752,15 +751,8 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) {
|
||||||
free(surface);
|
free(surface);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void surface_handle_renderer_destroy(struct wl_listener *listener,
|
|
||||||
void *data) {
|
|
||||||
struct wlr_surface *surface =
|
|
||||||
wl_container_of(listener, surface, renderer_destroy);
|
|
||||||
wl_resource_destroy(surface->resource);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wlr_surface *surface_create(struct wl_client *client,
|
static struct wlr_surface *surface_create(struct wl_client *client,
|
||||||
uint32_t version, uint32_t id, struct wlr_renderer *renderer) {
|
uint32_t version, uint32_t id, struct wlr_compositor *compositor) {
|
||||||
struct wlr_surface *surface = calloc(1, sizeof(*surface));
|
struct wlr_surface *surface = calloc(1, sizeof(*surface));
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
|
@ -778,7 +770,7 @@ static struct wlr_surface *surface_create(struct wl_client *client,
|
||||||
|
|
||||||
wlr_log(WLR_DEBUG, "New wlr_surface %p (res %p)", surface, surface->resource);
|
wlr_log(WLR_DEBUG, "New wlr_surface %p (res %p)", surface, surface->resource);
|
||||||
|
|
||||||
surface->renderer = renderer;
|
surface->compositor = compositor;
|
||||||
|
|
||||||
surface_state_init(&surface->current, surface);
|
surface_state_init(&surface->current, surface);
|
||||||
surface_state_init(&surface->pending, surface);
|
surface_state_init(&surface->pending, surface);
|
||||||
|
@ -798,13 +790,6 @@ static struct wlr_surface *surface_create(struct wl_client *client,
|
||||||
wlr_addon_set_init(&surface->addons);
|
wlr_addon_set_init(&surface->addons);
|
||||||
wl_list_init(&surface->synced);
|
wl_list_init(&surface->synced);
|
||||||
|
|
||||||
if (renderer != NULL) {
|
|
||||||
wl_signal_add(&renderer->events.destroy, &surface->renderer_destroy);
|
|
||||||
surface->renderer_destroy.notify = surface_handle_renderer_destroy;
|
|
||||||
} else {
|
|
||||||
wl_list_init(&surface->renderer_destroy.link);
|
|
||||||
}
|
|
||||||
|
|
||||||
wl_list_init(&surface->role_resource_destroy.link);
|
wl_list_init(&surface->role_resource_destroy.link);
|
||||||
|
|
||||||
surface->pending_buffer_resource_destroy.notify = pending_buffer_resource_handle_destroy;
|
surface->pending_buffer_resource_destroy.notify = pending_buffer_resource_handle_destroy;
|
||||||
|
@ -1310,7 +1295,7 @@ static void compositor_create_surface(struct wl_client *client,
|
||||||
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
struct wlr_compositor *compositor = compositor_from_resource(resource);
|
||||||
|
|
||||||
struct wlr_surface *surface = surface_create(client,
|
struct wlr_surface *surface = surface_create(client,
|
||||||
wl_resource_get_version(resource), id, compositor->renderer);
|
wl_resource_get_version(resource), id, compositor);
|
||||||
if (surface == NULL) {
|
if (surface == NULL) {
|
||||||
wl_client_post_no_memory(client);
|
wl_client_post_no_memory(client);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue