Merge pull request #197 from versusvoid/buffer-reset

Reset buffer resource pointer on destroy signal.
This commit is contained in:
Drew DeVault 2017-10-03 15:28:48 -04:00 committed by GitHub
commit 836242b0c4
2 changed files with 41 additions and 9 deletions

View File

@ -24,6 +24,7 @@ struct wlr_frame_callback {
struct wlr_surface_state { struct wlr_surface_state {
uint32_t invalid; uint32_t invalid;
struct wl_resource *buffer; struct wl_resource *buffer;
struct wl_listener buffer_destroy_listener;
int32_t sx, sy; int32_t sx, sy;
pixman_region32_t surface_damage, buffer_damage; pixman_region32_t surface_damage, buffer_damage;
pixman_region32_t opaque, input; pixman_region32_t opaque, input;

View File

@ -7,6 +7,39 @@
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
#include <wlr/render/matrix.h> #include <wlr/render/matrix.h>
static void wlr_surface_state_reset_buffer(struct wlr_surface_state *state) {
if (state->buffer) {
wl_list_remove(&state->buffer_destroy_listener.link);
state->buffer = NULL;
}
}
static void buffer_destroy(struct wl_listener *listener, void *data) {
struct wlr_surface_state *state =
wl_container_of(listener, state, buffer_destroy_listener);
wl_list_remove(&state->buffer_destroy_listener.link);
state->buffer = NULL;
}
static void wlr_surface_state_release_buffer(struct wlr_surface_state *state) {
if (state->buffer) {
wl_resource_post_event(state->buffer, WL_BUFFER_RELEASE);
wl_list_remove(&state->buffer_destroy_listener.link);
state->buffer = NULL;
}
}
static void wlr_surface_state_set_buffer(struct wlr_surface_state *state,
struct wl_resource *buffer) {
state->buffer = buffer;
if (buffer) {
wl_resource_add_destroy_listener(buffer,
&state->buffer_destroy_listener);
state->buffer_destroy_listener.notify = buffer_destroy;
}
}
static void surface_destroy(struct wl_client *client, static void surface_destroy(struct wl_client *client,
struct wl_resource *resource) { struct wl_resource *resource) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
@ -18,7 +51,8 @@ static void surface_attach(struct wl_client *client,
struct wlr_surface *surface = wl_resource_get_user_data(resource); struct wlr_surface *surface = wl_resource_get_user_data(resource);
surface->pending->invalid |= WLR_SURFACE_INVALID_BUFFER; surface->pending->invalid |= WLR_SURFACE_INVALID_BUFFER;
surface->pending->buffer = buffer; wlr_surface_state_reset_buffer(surface->pending);
wlr_surface_state_set_buffer(surface->pending, buffer);
} }
static void surface_damage(struct wl_client *client, static void surface_damage(struct wl_client *client,
@ -223,12 +257,9 @@ static void wlr_surface_move_state(struct wlr_surface *surface, struct wlr_surfa
update_size = true; update_size = true;
} }
if ((next->invalid & WLR_SURFACE_INVALID_BUFFER)) { if ((next->invalid & WLR_SURFACE_INVALID_BUFFER)) {
if (state->buffer) { wlr_surface_state_release_buffer(state);
wl_resource_post_event(state->buffer, WL_BUFFER_RELEASE); wlr_surface_state_set_buffer(state, next->buffer);
} wlr_surface_state_reset_buffer(next);
state->buffer = next->buffer;
next->buffer = NULL;
update_size = true; update_size = true;
} }
if (update_size) { if (update_size) {
@ -460,8 +491,7 @@ release:
pixman_region32_clear(&surface->current->surface_damage); pixman_region32_clear(&surface->current->surface_damage);
pixman_region32_clear(&surface->current->buffer_damage); pixman_region32_clear(&surface->current->buffer_damage);
wl_resource_post_event(surface->current->buffer, WL_BUFFER_RELEASE); wlr_surface_state_release_buffer(surface->current);
surface->current->buffer = NULL;
} }
static void surface_set_buffer_transform(struct wl_client *client, static void surface_set_buffer_transform(struct wl_client *client,
@ -522,6 +552,7 @@ static struct wlr_surface_state *wlr_surface_state_create() {
} }
static void wlr_surface_state_destroy(struct wlr_surface_state *state) { static void wlr_surface_state_destroy(struct wlr_surface_state *state) {
wlr_surface_state_reset_buffer(state);
struct wlr_frame_callback *cb, *tmp; struct wlr_frame_callback *cb, *tmp;
wl_list_for_each_safe(cb, tmp, &state->frame_callback_list, link) { wl_list_for_each_safe(cb, tmp, &state->frame_callback_list, link) {
wl_resource_destroy(cb->resource); wl_resource_destroy(cb->resource);