mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-19 06:47:02 -04:00
Merge branch 'surface-texture-v2' into 'master'
Replace wlr_client_buffer with wlr_surface_texture, take 2 See merge request wlroots/wlroots!4437
This commit is contained in:
commit
8fa5b78f66
13 changed files with 209 additions and 225 deletions
|
|
@ -72,28 +72,6 @@ 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 int min(int a, int b) {
|
||||
return a < b ? a : b;
|
||||
}
|
||||
|
|
@ -148,13 +126,10 @@ static void surface_reconfigure(struct wlr_scene_surface *scene_surface) {
|
|||
wlr_scene_buffer_set_dest_size(scene_buffer, width, 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);
|
||||
if (surface->texture) {
|
||||
scene_buffer_set_buffer_and_texture(scene_buffer,
|
||||
surface->texture->buffer, surface->texture->texture,
|
||||
&surface->buffer_damage);
|
||||
} else {
|
||||
wlr_scene_buffer_set_buffer(scene_buffer, NULL);
|
||||
}
|
||||
|
|
@ -198,7 +173,7 @@ 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_scene_buffer_set_buffer(surface->buffer, NULL);
|
||||
|
||||
wlr_addon_finish(&surface->addon);
|
||||
|
||||
|
|
|
|||
|
|
@ -112,7 +112,9 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node) {
|
|||
}
|
||||
}
|
||||
|
||||
wlr_texture_destroy(scene_buffer->texture);
|
||||
if (scene_buffer->own_texture) {
|
||||
wlr_texture_destroy(scene_buffer->texture);
|
||||
}
|
||||
scene_buffer_set_buffer(scene_buffer, NULL);
|
||||
pixman_region32_fini(&scene_buffer->opaque_region);
|
||||
} else if (node->type == WLR_SCENE_NODE_TREE) {
|
||||
|
|
@ -635,6 +637,37 @@ static void scene_buffer_set_buffer(struct wlr_scene_buffer *scene_buffer,
|
|||
wl_signal_add(&buffer->events.release, &scene_buffer->buffer_release);
|
||||
}
|
||||
|
||||
static void scene_buffer_set_texture(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_texture *texture, bool own_texture);
|
||||
|
||||
static void scene_buffer_handle_texture_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
struct wlr_scene_buffer *scene_buffer =
|
||||
wl_container_of(listener, scene_buffer, texture_destroy);
|
||||
scene_buffer_set_texture(scene_buffer, NULL, false);
|
||||
}
|
||||
|
||||
static void scene_buffer_set_texture(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_texture *texture, bool own_texture) {
|
||||
wl_list_remove(&scene_buffer->texture_destroy.link);
|
||||
wl_list_init(&scene_buffer->texture_destroy.link);
|
||||
if (scene_buffer->own_texture) {
|
||||
wlr_texture_destroy(scene_buffer->texture);
|
||||
}
|
||||
scene_buffer->texture = NULL;
|
||||
scene_buffer->own_texture = false;
|
||||
|
||||
if (!texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
scene_buffer->own_texture = own_texture;
|
||||
scene_buffer->texture = texture;
|
||||
|
||||
scene_buffer->texture_destroy.notify = scene_buffer_handle_texture_destroy;
|
||||
wl_signal_add(&texture->events.destroy, &scene_buffer->texture_destroy);
|
||||
}
|
||||
|
||||
struct wlr_scene_buffer *wlr_scene_buffer_create(struct wlr_scene_tree *parent,
|
||||
struct wlr_buffer *buffer) {
|
||||
struct wlr_scene_buffer *scene_buffer = calloc(1, sizeof(*scene_buffer));
|
||||
|
|
@ -659,14 +692,28 @@ struct wlr_scene_buffer *wlr_scene_buffer_create(struct wlr_scene_tree *parent,
|
|||
return scene_buffer;
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_buffer *buffer, const pixman_region32_t *damage) {
|
||||
void scene_buffer_set_buffer_and_texture(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_buffer *buffer, struct wlr_texture *texture,
|
||||
const pixman_region32_t *damage) {
|
||||
// specifying a region for a NULL buffer doesn't make sense. We need to know
|
||||
// about the buffer to scale the buffer local coordinates down to scene
|
||||
// coordinates.
|
||||
assert(buffer || !damage);
|
||||
assert(buffer || texture || !damage);
|
||||
|
||||
bool mapped = buffer != NULL;
|
||||
int buffer_width = 0, buffer_height = 0;
|
||||
if (buffer != NULL && texture != NULL) {
|
||||
assert(buffer->width == (int)texture->width &&
|
||||
buffer->height == (int)texture->height);
|
||||
}
|
||||
if (buffer != NULL) {
|
||||
buffer_width = buffer->width;
|
||||
buffer_height = buffer->height;
|
||||
} else if (texture != NULL) {
|
||||
buffer_width = texture->width;
|
||||
buffer_height = texture->height;
|
||||
}
|
||||
|
||||
bool mapped = buffer != NULL || texture != NULL;
|
||||
bool prev_mapped = scene_buffer->buffer != NULL || scene_buffer->texture != NULL;
|
||||
|
||||
if (!mapped && !prev_mapped) {
|
||||
|
|
@ -678,15 +725,15 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
|
|||
// buffer region will be different from what the new buffer would
|
||||
// produce we need to update the node.
|
||||
bool update = mapped != prev_mapped;
|
||||
if (buffer != NULL && scene_buffer->dst_width == 0 && scene_buffer->dst_height == 0) {
|
||||
update = update || scene_buffer->buffer_width != buffer->width ||
|
||||
scene_buffer->buffer_height != buffer->height;
|
||||
if (scene_buffer->dst_width == 0 && scene_buffer->dst_height == 0) {
|
||||
update = update || scene_buffer->buffer_width != buffer_width ||
|
||||
scene_buffer->buffer_height != buffer_height;
|
||||
}
|
||||
|
||||
wlr_texture_destroy(scene_buffer->texture);
|
||||
scene_buffer->texture = NULL;
|
||||
|
||||
scene_buffer_set_buffer(scene_buffer, buffer);
|
||||
scene_buffer_set_texture(scene_buffer, texture, false);
|
||||
scene_buffer->buffer_width = buffer_width;
|
||||
scene_buffer->buffer_height = buffer_height;
|
||||
|
||||
if (update) {
|
||||
scene_node_update(&scene_buffer->node, NULL);
|
||||
|
|
@ -701,7 +748,7 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
|
|||
}
|
||||
|
||||
pixman_region32_t fallback_damage;
|
||||
pixman_region32_init_rect(&fallback_damage, 0, 0, buffer->width, buffer->height);
|
||||
pixman_region32_init_rect(&fallback_damage, 0, 0, buffer_width, buffer_height);
|
||||
if (!damage) {
|
||||
damage = &fallback_damage;
|
||||
}
|
||||
|
|
@ -710,26 +757,26 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
|
|||
if (wlr_fbox_empty(&box)) {
|
||||
box.x = 0;
|
||||
box.y = 0;
|
||||
box.width = buffer->width;
|
||||
box.height = buffer->height;
|
||||
box.width = buffer_width;
|
||||
box.height = buffer_height;
|
||||
}
|
||||
|
||||
wlr_fbox_transform(&box, &box, scene_buffer->transform,
|
||||
buffer->width, buffer->height);
|
||||
buffer_width, buffer_height);
|
||||
|
||||
float scale_x, scale_y;
|
||||
if (scene_buffer->dst_width || scene_buffer->dst_height) {
|
||||
scale_x = scene_buffer->dst_width / box.width;
|
||||
scale_y = scene_buffer->dst_height / box.height;
|
||||
} else {
|
||||
scale_x = buffer->width / box.width;
|
||||
scale_y = buffer->height / box.height;
|
||||
scale_x = buffer_width / box.width;
|
||||
scale_y = buffer_height / box.height;
|
||||
}
|
||||
|
||||
pixman_region32_t trans_damage;
|
||||
pixman_region32_init(&trans_damage);
|
||||
wlr_region_transform(&trans_damage, damage,
|
||||
scene_buffer->transform, buffer->width, buffer->height);
|
||||
scene_buffer->transform, buffer_width, buffer_height);
|
||||
pixman_region32_intersect_rect(&trans_damage, &trans_damage,
|
||||
box.x, box.y, box.width, box.height);
|
||||
pixman_region32_translate(&trans_damage, -box.x, -box.y);
|
||||
|
|
@ -785,11 +832,21 @@ void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buff
|
|||
pixman_region32_fini(&fallback_damage);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_buffer_with_damage(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_buffer *buffer, const pixman_region32_t *damage) {
|
||||
scene_buffer_set_buffer_and_texture(scene_buffer, buffer, NULL, damage);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_buffer(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_buffer *buffer) {
|
||||
wlr_scene_buffer_set_buffer_with_damage(scene_buffer, buffer, NULL);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_texture(struct wlr_scene_buffer *scene_buffer,
|
||||
struct wlr_texture *texture) {
|
||||
scene_buffer_set_buffer_and_texture(scene_buffer, NULL, texture, NULL);
|
||||
}
|
||||
|
||||
void wlr_scene_buffer_set_opaque_region(struct wlr_scene_buffer *scene_buffer,
|
||||
const pixman_region32_t *region) {
|
||||
if (pixman_region32_equal(&scene_buffer->opaque_region, region)) {
|
||||
|
|
@ -879,15 +936,10 @@ static struct wlr_texture *scene_buffer_get_texture(
|
|||
return scene_buffer->texture;
|
||||
}
|
||||
|
||||
struct wlr_client_buffer *client_buffer =
|
||||
wlr_client_buffer_get(scene_buffer->buffer);
|
||||
if (client_buffer != NULL) {
|
||||
return client_buffer->texture;
|
||||
}
|
||||
|
||||
scene_buffer->texture =
|
||||
struct wlr_texture *texture =
|
||||
wlr_texture_from_buffer(renderer, scene_buffer->buffer);
|
||||
if (scene_buffer->texture != NULL && scene_buffer->own_buffer) {
|
||||
scene_buffer_set_texture(scene_buffer, texture, true);
|
||||
if (texture != NULL && scene_buffer->own_buffer) {
|
||||
scene_buffer->own_buffer = false;
|
||||
wlr_buffer_unlock(scene_buffer->buffer);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue