buffer: stop sending wl_buffer.release events from wlr_client_buffer

The specialized client buffer implementations take care of this.
This commit is contained in:
Simon Ser 2021-06-08 19:45:56 +02:00 committed by Simon Zeni
parent d3d1c69aca
commit 9a8097682b
3 changed files with 1 additions and 40 deletions

View File

@ -122,10 +122,6 @@ struct wlr_client_buffer {
* The buffer resource, if any. Will be NULL if the client destroys it.
*/
struct wl_resource *resource;
/**
* Whether a release event has been sent to the resource.
*/
bool resource_released;
/**
* The buffer's texture, if any. A buffer will not have a texture if the
* client destroys the buffer before it has been released.
@ -133,7 +129,6 @@ struct wlr_client_buffer {
struct wlr_texture *texture;
struct wl_listener resource_destroy;
struct wl_listener release;
};
struct wlr_renderer;

View File

@ -148,11 +148,6 @@ static struct wlr_client_buffer *client_buffer_from_buffer(
static void client_buffer_destroy(struct wlr_buffer *_buffer) {
struct wlr_client_buffer *buffer = client_buffer_from_buffer(_buffer);
if (!buffer->resource_released && buffer->resource != NULL) {
wl_buffer_send_release(buffer->resource);
}
wl_list_remove(&buffer->resource_destroy.link);
wlr_texture_destroy(buffer->texture);
free(buffer);
@ -199,23 +194,11 @@ static void client_buffer_resource_handle_destroy(struct wl_listener *listener,
// which case we'll read garbage. We decide to accept this risk.
}
static void client_buffer_handle_release(struct wl_listener *listener,
void *data) {
struct wlr_client_buffer *buffer =
wl_container_of(listener, buffer, release);
if (!buffer->resource_released && buffer->resource != NULL) {
wl_buffer_send_release(buffer->resource);
buffer->resource_released = true;
}
}
struct wlr_client_buffer *wlr_client_buffer_import(
struct wlr_renderer *renderer, struct wl_resource *resource) {
assert(wlr_resource_is_buffer(resource));
struct wlr_texture *texture = NULL;
bool resource_released = false;
if (wl_shm_buffer_get(resource) != NULL) {
struct wlr_shm_client_buffer *shm_client_buffer =
shm_client_buffer_create(resource);
@ -232,26 +215,14 @@ struct wlr_client_buffer *wlr_client_buffer_import(
// The renderer should've locked the buffer by now if necessary
wlr_buffer_unlock(&shm_client_buffer->base);
// The renderer is responsible for releasing the buffer when
// appropriate
resource_released = true;
} else if (wlr_dmabuf_v1_resource_is_buffer(resource)) {
struct wlr_dmabuf_v1_buffer *dmabuf =
wlr_dmabuf_v1_buffer_from_buffer_resource(resource);
texture = wlr_texture_from_buffer(renderer, &dmabuf->base);
// The renderer is responsible for releasing the buffer when
// appropriate
resource_released = true;
} else if (wlr_drm_buffer_is_resource(resource)) {
struct wlr_drm_buffer *drm_buffer =
wlr_drm_buffer_from_resource(resource);
texture = wlr_texture_from_buffer(renderer, &drm_buffer->base);
// The renderer is responsible for releasing the buffer when
// appropriate
resource_released = true;
} else {
wlr_log(WLR_ERROR, "Cannot upload texture: unknown buffer type");
@ -278,14 +249,10 @@ struct wlr_client_buffer *wlr_client_buffer_import(
texture->width, texture->height);
buffer->resource = resource;
buffer->texture = texture;
buffer->resource_released = resource_released;
wl_resource_add_destroy_listener(resource, &buffer->resource_destroy);
buffer->resource_destroy.notify = client_buffer_resource_handle_destroy;
buffer->release.notify = client_buffer_handle_release;
wl_signal_add(&buffer->base.events.release, &buffer->release);
// Ensure the buffer will be released before being destroyed
wlr_buffer_lock(&buffer->base);
wlr_buffer_drop(&buffer->base);
@ -353,7 +320,6 @@ struct wlr_client_buffer *wlr_client_buffer_apply_damage(
buffer->resource_destroy.notify = client_buffer_resource_handle_destroy;
buffer->resource = resource;
buffer->resource_released = true;
return buffer;
}

View File

@ -355,7 +355,7 @@ static void surface_apply_damage(struct wlr_surface *surface) {
return;
}
if (surface->buffer != NULL && surface->buffer->resource_released) {
if (surface->buffer != NULL) {
struct wlr_client_buffer *updated_buffer =
wlr_client_buffer_apply_damage(surface->buffer, resource,
&surface->buffer_damage);