surface: drop wlr_surface_state.buffer_resource

Instead, use wlr_surface_state.buffer only.
This commit is contained in:
Simon Ser 2021-08-11 17:34:34 +02:00 committed by Simon Zeni
parent 0978a702d7
commit ba0525c5c0
5 changed files with 16 additions and 50 deletions

View File

@ -36,7 +36,6 @@ struct wlr_surface_state {
uint32_t seq; uint32_t seq;
struct wlr_buffer *buffer; struct wlr_buffer *buffer;
struct wl_resource *buffer_resource;
int32_t dx, dy; // relative to previous position int32_t dx, dy; // relative to previous position
pixman_region32_t surface_damage, buffer_damage; // clipped to bounds pixman_region32_t surface_damage, buffer_damage; // clipped to bounds
pixman_region32_t opaque, input; pixman_region32_t opaque, input;
@ -65,8 +64,6 @@ struct wlr_surface_state {
int dst_width, dst_height; // in surface-local coordinates int dst_width, dst_height; // in surface-local coordinates
} viewport; } viewport;
struct wl_listener buffer_destroy;
// Number of locks that prevent this surface state from being committed. // Number of locks that prevent this surface state from being committed.
size_t cached_state_locks; size_t cached_state_locks;
struct wl_list cached_state_link; // wlr_surface.cached struct wl_list cached_state_link; // wlr_surface.cached

View File

@ -32,32 +32,6 @@ static int max(int fst, int snd) {
} }
} }
static void surface_state_reset_buffer(struct wlr_surface_state *state) {
if (state->buffer_resource) {
wl_list_remove(&state->buffer_destroy.link);
state->buffer_resource = NULL;
}
}
static void surface_handle_buffer_destroy(struct wl_listener *listener,
void *data) {
struct wlr_surface_state *state =
wl_container_of(listener, state, buffer_destroy);
surface_state_reset_buffer(state);
}
static void surface_state_set_buffer(struct wlr_surface_state *state,
struct wl_resource *buffer_resource) {
surface_state_reset_buffer(state);
state->buffer_resource = buffer_resource;
if (buffer_resource != NULL) {
wl_resource_add_destroy_listener(buffer_resource,
&state->buffer_destroy);
state->buffer_destroy.notify = surface_handle_buffer_destroy;
}
}
static void surface_handle_destroy(struct wl_client *client, static void surface_handle_destroy(struct wl_client *client,
struct wl_resource *resource) { struct wl_resource *resource) {
wl_resource_destroy(resource); wl_resource_destroy(resource);
@ -65,13 +39,21 @@ static void surface_handle_destroy(struct wl_client *client,
static void surface_handle_attach(struct wl_client *client, static void surface_handle_attach(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
struct wl_resource *buffer, int32_t dx, int32_t dy) { struct wl_resource *buffer_resource, int32_t dx, int32_t dy) {
struct wlr_surface *surface = wlr_surface_from_resource(resource); struct wlr_surface *surface = wlr_surface_from_resource(resource);
struct wlr_buffer *buffer = wlr_buffer_from_resource(buffer_resource);
if (buffer == NULL) {
wl_resource_post_error(buffer_resource, 0, "unknown buffer type");
return;
}
surface->pending.committed |= WLR_SURFACE_STATE_BUFFER; surface->pending.committed |= WLR_SURFACE_STATE_BUFFER;
surface->pending.dx = dx; surface->pending.dx = dx;
surface->pending.dy = dy; surface->pending.dy = dy;
surface_state_set_buffer(&surface->pending, buffer);
wlr_buffer_unlock(surface->pending.buffer);
surface->pending.buffer = buffer;
} }
static void surface_handle_damage(struct wl_client *client, static void surface_handle_damage(struct wl_client *client,
@ -171,15 +153,7 @@ static void surface_finalize_pending(struct wlr_surface *surface) {
struct wlr_surface_state *pending = &surface->pending; struct wlr_surface_state *pending = &surface->pending;
if ((pending->committed & WLR_SURFACE_STATE_BUFFER)) { if ((pending->committed & WLR_SURFACE_STATE_BUFFER)) {
if (pending->buffer_resource) { if (pending->buffer != NULL) {
wlr_buffer_unlock(pending->buffer);
pending->buffer = wlr_buffer_from_resource(pending->buffer_resource);
if (!pending->buffer) {
wl_resource_post_error(pending->buffer_resource, 0,
"unknown buffer type");
return;
}
pending->buffer_width = pending->buffer->width; pending->buffer_width = pending->buffer->width;
pending->buffer_height = pending->buffer->height; pending->buffer_height = pending->buffer->height;
} else { } else {
@ -281,9 +255,6 @@ static void surface_state_move(struct wlr_surface_state *state,
state->dy = next->dy; state->dy = next->dy;
next->dx = next->dy = 0; next->dx = next->dy = 0;
surface_state_set_buffer(state, next->buffer_resource);
surface_state_reset_buffer(next);
wlr_buffer_unlock(state->buffer); wlr_buffer_unlock(state->buffer);
state->buffer = NULL; state->buffer = NULL;
if (next->buffer) { if (next->buffer) {
@ -354,8 +325,7 @@ static void surface_damage_subsurfaces(struct wlr_subsurface *subsurface) {
} }
static void surface_apply_damage(struct wlr_surface *surface) { static void surface_apply_damage(struct wlr_surface *surface) {
struct wl_resource *resource = surface->current.buffer_resource; if (surface->current.buffer == NULL) {
if (resource == NULL) {
// NULL commit // NULL commit
if (surface->buffer != NULL) { if (surface->buffer != NULL) {
wlr_buffer_unlock(&surface->buffer->base); wlr_buffer_unlock(&surface->buffer->base);
@ -657,7 +627,6 @@ static void surface_state_init(struct wlr_surface_state *state) {
} }
static void surface_state_finish(struct wlr_surface_state *state) { static void surface_state_finish(struct wlr_surface_state *state) {
surface_state_reset_buffer(state);
wlr_buffer_unlock(state->buffer); wlr_buffer_unlock(state->buffer);
struct wl_resource *resource, *tmp; struct wl_resource *resource, *tmp;
@ -1127,7 +1096,7 @@ static void subsurface_role_precommit(struct wlr_surface *surface) {
} }
if (surface->pending.committed & WLR_SURFACE_STATE_BUFFER && if (surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
surface->pending.buffer_resource == NULL) { surface->pending.buffer == NULL) {
// This is a NULL commit // This is a NULL commit
subsurface_unmap(subsurface); subsurface_unmap(subsurface);
} }

View File

@ -143,7 +143,7 @@ static void viewport_handle_surface_commit(struct wl_listener *listener,
return; return;
} }
if (current->viewport.has_src && current->buffer_resource != NULL && if (current->viewport.has_src && current->buffer != NULL &&
(current->viewport.src.x + current->viewport.src.width > (current->viewport.src.x + current->viewport.src.width >
current->buffer_width || current->buffer_width ||
current->viewport.src.y + current->viewport.src.height > current->viewport.src.y + current->viewport.src.height >

View File

@ -398,7 +398,7 @@ void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface) {
} }
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER && if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer_resource == NULL) { wlr_surface->pending.buffer == NULL) {
// This is a NULL commit // This is a NULL commit
if (surface->configured && surface->mapped) { if (surface->configured && surface->mapped) {
unmap_xdg_surface(surface); unmap_xdg_surface(surface);

View File

@ -850,7 +850,7 @@ static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface) {
} }
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER && if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer_resource == NULL) { wlr_surface->pending.buffer == NULL) {
// This is a NULL commit // This is a NULL commit
if (surface->mapped) { if (surface->mapped) {
wlr_signal_emit_safe(&surface->events.unmap, surface); wlr_signal_emit_safe(&surface->events.unmap, surface);