diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 262a533e6..723beee24 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -1508,8 +1508,7 @@ static void handle_page_flip(int fd, unsigned seq, * data between the GPUs, even if we were using the direct scanout * interface. */ - if (!drm->parent && plane->current_fb && - wlr_client_buffer_get(plane->current_fb->wlr_buf)) { + if (!drm->parent && plane->current_fb && false) { present_flags |= WLR_OUTPUT_PRESENT_ZERO_COPY; } diff --git a/examples/fullscreen-shell.c b/examples/fullscreen-shell.c index bc4bb7a86..de4ba4dc8 100644 --- a/examples/fullscreen-shell.c +++ b/examples/fullscreen-shell.c @@ -56,7 +56,8 @@ static void render_surface(struct wlr_surface *surface, struct render_data *rdata = data; struct wlr_output *output = rdata->output; - struct wlr_texture *texture = wlr_surface_get_texture(surface); + struct wlr_texture *texture = wlr_texture_from_buffer(output->renderer, + surface->current.buffer); if (texture == NULL) { return; } @@ -77,6 +78,8 @@ static void render_surface(struct wlr_surface *surface, wlr_render_texture_with_matrix(rdata->renderer, texture, matrix, 1); wlr_surface_send_frame_done(surface, rdata->when); + + wlr_texture_destroy(texture); } static void output_handle_frame(struct wl_listener *listener, void *data) { diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index b24c0ccd1..46a9198bc 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -132,50 +132,9 @@ bool wlr_buffer_begin_data_ptr_access(struct wlr_buffer *buffer, uint32_t flags, void **data, uint32_t *format, size_t *stride); void wlr_buffer_end_data_ptr_access(struct wlr_buffer *buffer); -/** - * A client buffer. - */ -struct wlr_client_buffer { - struct wlr_buffer base; - - /** - * The buffer's texture, if any. A buffer will not have a texture if the - * client destroys the buffer before it has been released. - */ - struct wlr_texture *texture; - /** - * The buffer this client buffer was created from. NULL if destroyed. - */ - struct wlr_buffer *source; - - // private state - - struct wl_listener source_destroy; -}; - -/** - * Creates a struct wlr_client_buffer from a given struct wlr_buffer by creating - * a texture from it, and copying its struct wl_resource. - */ -struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, - struct wlr_renderer *renderer); - -/** - * Get a client buffer from a generic buffer. If the buffer isn't a client - * buffer, returns NULL. - */ -struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer); /** * Check if a resource is a wl_buffer resource. */ bool wlr_resource_is_buffer(struct wl_resource *resource); -/** - * Try to update the buffer's content. - * - * Fails if there's more than one reference to the buffer or if the texture - * isn't mutable. - */ -bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer, - struct wlr_buffer *next, pixman_region32_t *damage); #endif diff --git a/include/wlr/types/wlr_compositor.h b/include/wlr/types/wlr_compositor.h index 034b075b1..a8577087d 100644 --- a/include/wlr/types/wlr_compositor.h +++ b/include/wlr/types/wlr_compositor.h @@ -89,13 +89,6 @@ struct wlr_surface_output { struct wlr_surface { struct wl_resource *resource; struct wlr_renderer *renderer; - /** - * 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 - * have a buffer if it has never committed one, has committed a null buffer, - * or something went wrong with uploading the buffer. - */ - struct wlr_client_buffer *buffer; /** * The buffer position, in surface-local units. */ @@ -199,13 +192,6 @@ bool wlr_surface_set_role(struct wlr_surface *surface, */ bool wlr_surface_has_buffer(struct wlr_surface *surface); -/** - * Get the texture of the buffer currently attached to this surface. Returns - * NULL if no buffer is currently attached or if something went wrong with - * uploading the buffer. - */ -struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface); - /** * Get the root of the subsurface tree for this surface. Can return NULL if * a surface in the tree has been destroyed. diff --git a/types/output/cursor.c b/types/output/cursor.c index 85973ce93..995af5c8a 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -94,9 +94,6 @@ static void output_cursor_render(struct wlr_output_cursor *cursor, assert(renderer); struct wlr_texture *texture = cursor->texture; - if (cursor->surface != NULL) { - texture = wlr_surface_get_texture(cursor->surface); - } if (texture == NULL) { return; } @@ -236,7 +233,6 @@ static struct wlr_buffer *render_cursor_buffer(struct wlr_output_cursor *cursor) enum wl_output_transform transform = WL_OUTPUT_TRANSFORM_NORMAL; struct wlr_texture *texture = cursor->texture; if (cursor->surface != NULL) { - texture = wlr_surface_get_texture(cursor->surface); scale = cursor->surface->current.scale; transform = cursor->surface->current.transform; } @@ -337,11 +333,8 @@ static bool output_cursor_attempt_hardware(struct wlr_output_cursor *cursor) { return false; } + // TODO: try using the surface buffer directly struct wlr_texture *texture = cursor->texture; - if (cursor->surface != NULL) { - // TODO: try using the surface buffer directly - texture = wlr_surface_get_texture(cursor->surface); - } // If the cursor was hidden or was a software cursor, the hardware // cursor position is outdated @@ -445,6 +438,17 @@ static void output_cursor_commit(struct wlr_output_cursor *cursor, struct wlr_surface *surface = cursor->surface; assert(surface != NULL); + wlr_texture_destroy(cursor->texture); + cursor->texture = NULL; + + if (surface->current.buffer) { + cursor->texture = wlr_texture_from_buffer(cursor->output->renderer, + surface->current.buffer); + if (cursor->texture == NULL) { + return; + } + } + // Some clients commit a cursor surface with a NULL buffer to hide it. cursor->enabled = wlr_surface_has_buffer(surface); cursor->width = surface->current.width * cursor->output->scale; diff --git a/types/scene/surface.c b/types/scene/surface.c index d3a0b035f..e06e77312 100644 --- a/types/scene/surface.c +++ b/types/scene/surface.c @@ -66,9 +66,9 @@ static void set_buffer_with_surface_state(struct wlr_scene_buffer *scene_buffer, wlr_scene_buffer_set_dest_size(scene_buffer, state->width, state->height); wlr_scene_buffer_set_transform(scene_buffer, state->transform); - if (surface->buffer) { + if (surface->current.buffer) { wlr_scene_buffer_set_buffer_with_damage(scene_buffer, - &surface->buffer->base, &surface->buffer_damage); + surface->current.buffer, &surface->buffer_damage); } else { wlr_scene_buffer_set_buffer(scene_buffer, NULL); } diff --git a/types/scene/wlr_scene.c b/types/scene/wlr_scene.c index 68b05b7c8..4306410b4 100644 --- a/types/scene/wlr_scene.c +++ b/types/scene/wlr_scene.c @@ -477,12 +477,6 @@ void wlr_scene_buffer_send_frame_done(struct wlr_scene_buffer *scene_buffer, static struct wlr_texture *scene_buffer_get_texture( struct wlr_scene_buffer *scene_buffer, struct wlr_renderer *renderer) { - struct wlr_client_buffer *client_buffer = - wlr_client_buffer_get(scene_buffer->buffer); - if (client_buffer != NULL) { - return client_buffer->texture; - } - if (scene_buffer->texture != NULL) { return scene_buffer->texture; } diff --git a/types/wlr_buffer.c b/types/wlr_buffer.c index b63ce88ad..800a3f992 100644 --- a/types/wlr_buffer.c +++ b/types/wlr_buffer.c @@ -109,54 +109,6 @@ bool wlr_resource_is_buffer(struct wl_resource *resource) { return strcmp(wl_resource_get_class(resource), wl_buffer_interface.name) == 0; } -static const struct wlr_buffer_impl client_buffer_impl; - -struct wlr_client_buffer *wlr_client_buffer_get(struct wlr_buffer *buffer) { - if (buffer->impl != &client_buffer_impl) { - return NULL; - } - return (struct wlr_client_buffer *)buffer; -} - -static struct wlr_client_buffer *client_buffer_from_buffer( - struct wlr_buffer *buffer) { - struct wlr_client_buffer *client_buffer = wlr_client_buffer_get(buffer); - assert(client_buffer != NULL); - return client_buffer; -} - -static void client_buffer_destroy(struct wlr_buffer *buffer) { - struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer); - wl_list_remove(&client_buffer->source_destroy.link); - wlr_texture_destroy(client_buffer->texture); - free(client_buffer); -} - -static bool client_buffer_get_dmabuf(struct wlr_buffer *buffer, - struct wlr_dmabuf_attributes *attribs) { - struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer); - - if (client_buffer->source == NULL) { - return false; - } - - return wlr_buffer_get_dmabuf(client_buffer->source, attribs); -} - -static const struct wlr_buffer_impl client_buffer_impl = { - .destroy = client_buffer_destroy, - .get_dmabuf = client_buffer_get_dmabuf, -}; - -static void client_buffer_handle_source_destroy(struct wl_listener *listener, - void *data) { - struct wlr_client_buffer *client_buffer = - wl_container_of(listener, client_buffer, source_destroy); - wl_list_remove(&client_buffer->source_destroy.link); - wl_list_init(&client_buffer->source_destroy.link); - client_buffer->source = NULL; -} - static struct wlr_shm_client_buffer *shm_client_buffer_get_or_create( struct wl_resource *resource); static bool buffer_is_shm_client_buffer(struct wlr_buffer *buffer); @@ -263,45 +215,6 @@ bool buffer_is_opaque(struct wlr_buffer *buffer) { return !format_info->has_alpha; } -struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, - struct wlr_renderer *renderer) { - struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer); - if (texture == NULL) { - wlr_log(WLR_ERROR, "Failed to create texture"); - return NULL; - } - - struct wlr_client_buffer *client_buffer = - calloc(1, sizeof(struct wlr_client_buffer)); - if (client_buffer == NULL) { - wlr_texture_destroy(texture); - return NULL; - } - wlr_buffer_init(&client_buffer->base, &client_buffer_impl, - texture->width, texture->height); - client_buffer->source = buffer; - client_buffer->texture = texture; - - wl_signal_add(&buffer->events.destroy, &client_buffer->source_destroy); - client_buffer->source_destroy.notify = client_buffer_handle_source_destroy; - - // Ensure the buffer will be released before being destroyed - wlr_buffer_lock(&client_buffer->base); - wlr_buffer_drop(&client_buffer->base); - - return client_buffer; -} - -bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer, - struct wlr_buffer *next, pixman_region32_t *damage) { - if (client_buffer->base.n_locks > 1) { - // Someone else still has a reference to the buffer - return false; - } - - return wlr_texture_update_from_buffer(client_buffer->texture, next, damage); -} - static const struct wlr_buffer_impl shm_client_buffer_impl; static bool buffer_is_shm_client_buffer(struct wlr_buffer *buffer) { diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index c1cdc3b05..fc00abb2f 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -333,45 +333,15 @@ static void surface_state_move(struct wlr_surface_state *state, static void surface_apply_damage(struct wlr_surface *surface) { if (surface->current.buffer == NULL) { // NULL commit - if (surface->buffer != NULL) { - wlr_buffer_unlock(&surface->buffer->base); - } - surface->buffer = NULL; surface->opaque = false; return; } surface->opaque = buffer_is_opaque(surface->current.buffer); - - if (surface->buffer != NULL) { - if (wlr_client_buffer_apply_damage(surface->buffer, - surface->current.buffer, &surface->buffer_damage)) { - wlr_buffer_unlock(surface->current.buffer); - surface->current.buffer = NULL; - return; - } - } - - struct wlr_client_buffer *buffer = wlr_client_buffer_create( - surface->current.buffer, surface->renderer); - - wlr_buffer_unlock(surface->current.buffer); - surface->current.buffer = NULL; - - if (buffer == NULL) { - wlr_log(WLR_ERROR, "Failed to upload buffer"); - return; - } - - if (surface->buffer != NULL) { - wlr_buffer_unlock(&surface->buffer->base); - } - surface->buffer = buffer; } static void surface_update_opaque_region(struct wlr_surface *surface) { - struct wlr_texture *texture = wlr_surface_get_texture(surface); - if (texture == NULL) { + if (!wlr_surface_has_buffer(surface)) { pixman_region32_clear(&surface->opaque_region); return; } @@ -660,9 +630,6 @@ static void surface_handle_resource_destroy(struct wl_resource *resource) { pixman_region32_fini(&surface->external_damage); pixman_region32_fini(&surface->opaque_region); pixman_region32_fini(&surface->input_region); - if (surface->buffer != NULL) { - wlr_buffer_unlock(&surface->buffer->base); - } free(surface); } @@ -716,15 +683,8 @@ static struct wlr_surface *surface_create(struct wl_client *client, return surface; } -struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface) { - if (surface->buffer == NULL) { - return NULL; - } - return surface->buffer->texture; -} - bool wlr_surface_has_buffer(struct wlr_surface *surface) { - return wlr_surface_get_texture(surface) != NULL; + return surface->current.buffer != NULL; } bool wlr_surface_set_role(struct wlr_surface *surface,