aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Orzechowski <alex@ozal.ski>2022-11-08 11:55:05 -0500
committerSimon Ser <contact@emersion.fr>2022-11-11 00:08:04 +0000
commitea40ba4f6abd6623ff40eef7e443ca2e389ca3b1 (patch)
treef93d9e3dda9dcefdeace391e93f667421d2202b3
parenteec95e3d5e1a4f2e13b1f6b34cc287475ca57daf (diff)
wlr_scene: Fix texture reuse
Add private interface to ignore a buffer that's locking a client_buffer for damage tracking. This should eventually be replaced by wlr_raster.
-rw-r--r--include/wlr/types/wlr_buffer.h2
-rw-r--r--types/buffer/client.c2
-rw-r--r--types/scene/surface.c29
3 files changed, 32 insertions, 1 deletions
diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h
index b24c0ccd..bb0444bf 100644
--- a/include/wlr/types/wlr_buffer.h
+++ b/include/wlr/types/wlr_buffer.h
@@ -151,6 +151,8 @@ struct wlr_client_buffer {
// private state
struct wl_listener source_destroy;
+
+ size_t n_ignore_locks;
};
/**
diff --git a/types/buffer/client.c b/types/buffer/client.c
index 50c19691..6bcda941 100644
--- a/types/buffer/client.c
+++ b/types/buffer/client.c
@@ -84,7 +84,7 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *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) {
+ if (client_buffer->base.n_locks - client_buffer->n_ignore_locks > 1) {
// Someone else still has a reference to the buffer
return false;
}
diff --git a/types/scene/surface.c b/types/scene/surface.c
index f8bb5538..553cc421 100644
--- a/types/scene/surface.c
+++ b/types/scene/surface.c
@@ -1,3 +1,4 @@
+#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_presentation_time.h>
@@ -55,6 +56,28 @@ static void scene_surface_handle_surface_destroy(
wlr_scene_node_destroy(&surface->buffer->node);
}
+// This is used for wlr_scene where it unconditionally locks buffers preventing
+// reuse of the existing texture for shm clients. With the usage pattern of
+// wlr_scene surface handling, we can mark its locked buffer as safe
+// for mutation.
+static void client_buffer_mark_next_can_damage(struct wlr_client_buffer *buffer) {
+ buffer->n_ignore_locks++;
+}
+
+static void scene_buffer_unmark_client_buffer(struct wlr_scene_buffer *scene_buffer) {
+ if (!scene_buffer->buffer) {
+ return;
+ }
+
+ struct wlr_client_buffer *buffer = wlr_client_buffer_get(scene_buffer->buffer);
+ if (!buffer) {
+ return;
+ }
+
+ assert(buffer->n_ignore_locks > 0);
+ buffer->n_ignore_locks--;
+}
+
static void set_buffer_with_surface_state(struct wlr_scene_buffer *scene_buffer,
struct wlr_surface *surface) {
struct wlr_surface_state *state = &surface->current;
@@ -68,7 +91,11 @@ 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);
+ scene_buffer_unmark_client_buffer(scene_buffer);
+
if (surface->buffer) {
+ client_buffer_mark_next_can_damage(surface->buffer);
+
wlr_scene_buffer_set_buffer_with_damage(scene_buffer,
&surface->buffer->base, &surface->buffer_damage);
} else {
@@ -109,6 +136,8 @@ static bool scene_buffer_point_accepts_input(struct wlr_scene_buffer *scene_buff
static void surface_addon_destroy(struct wlr_addon *addon) {
struct wlr_scene_surface *surface = wl_container_of(addon, surface, addon);
+ scene_buffer_unmark_client_buffer(surface->buffer);
+
wlr_addon_finish(&surface->addon);
wl_list_remove(&surface->output_enter.link);