mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-18 06:47:31 -04:00
wlr_damage_ring: Rework to use list instead of fixed length ring
When we add buffer support this model of keeping a fixed size list simply won't be compatible.
This commit is contained in:
parent
a6d3eee63a
commit
600d995e94
2 changed files with 49 additions and 32 deletions
|
|
@ -13,14 +13,14 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <pixman.h>
|
#include <pixman.h>
|
||||||
|
#include <wayland-server-core.h>
|
||||||
/* For triple buffering, a history of two frames is required. */
|
|
||||||
#define WLR_DAMAGE_RING_PREVIOUS_LEN 2
|
|
||||||
|
|
||||||
struct wlr_box;
|
struct wlr_box;
|
||||||
|
|
||||||
struct wlr_damage_ring_entry {
|
struct wlr_damage_ring_entry {
|
||||||
pixman_region32_t damage;
|
pixman_region32_t damage;
|
||||||
|
|
||||||
|
struct wl_list link; // struct wlr_damage_ring.previous
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_damage_ring {
|
struct wlr_damage_ring {
|
||||||
|
|
@ -31,8 +31,7 @@ struct wlr_damage_ring {
|
||||||
|
|
||||||
// private state
|
// private state
|
||||||
|
|
||||||
struct wlr_damage_ring_entry previous[WLR_DAMAGE_RING_PREVIOUS_LEN];
|
struct wl_list previous; // struct wlr_damage_ring_entry.link
|
||||||
size_t previous_idx;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void wlr_damage_ring_init(struct wlr_damage_ring *ring);
|
void wlr_damage_ring_init(struct wlr_damage_ring *ring);
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,21 @@ void wlr_damage_ring_init(struct wlr_damage_ring *ring) {
|
||||||
};
|
};
|
||||||
|
|
||||||
pixman_region32_init(&ring->current);
|
pixman_region32_init(&ring->current);
|
||||||
for (size_t i = 0; i < WLR_DAMAGE_RING_PREVIOUS_LEN; ++i) {
|
wl_list_init(&ring->previous);
|
||||||
pixman_region32_init(&ring->previous[i].damage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void entry_destroy(struct wlr_damage_ring_entry *entry) {
|
||||||
|
wl_list_remove(&entry->link);
|
||||||
|
pixman_region32_fini(&entry->damage);
|
||||||
|
free(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_damage_ring_finish(struct wlr_damage_ring *ring) {
|
void wlr_damage_ring_finish(struct wlr_damage_ring *ring) {
|
||||||
pixman_region32_fini(&ring->current);
|
pixman_region32_fini(&ring->current);
|
||||||
for (size_t i = 0; i < WLR_DAMAGE_RING_PREVIOUS_LEN; ++i) {
|
|
||||||
pixman_region32_fini(&ring->previous[i].damage);
|
struct wlr_damage_ring_entry *entry, *tmp_entry;
|
||||||
|
wl_list_for_each_safe(entry, tmp_entry, &ring->previous, link) {
|
||||||
|
entry_destroy(entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,28 +85,41 @@ void wlr_damage_ring_add_whole(struct wlr_damage_ring *ring) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_damage_ring_rotate(struct wlr_damage_ring *ring) {
|
void wlr_damage_ring_rotate(struct wlr_damage_ring *ring) {
|
||||||
// modular decrement
|
struct wlr_damage_ring_entry *last =
|
||||||
ring->previous_idx = ring->previous_idx +
|
wl_container_of(ring->previous.prev, last, link);
|
||||||
WLR_DAMAGE_RING_PREVIOUS_LEN - 1;
|
wl_list_remove(&last->link);
|
||||||
ring->previous_idx %= WLR_DAMAGE_RING_PREVIOUS_LEN;
|
wl_list_insert(&ring->previous, &last->link);
|
||||||
|
|
||||||
pixman_region32_copy(&ring->previous[ring->previous_idx].damage, &ring->current);
|
pixman_region32_copy(&last->damage, &ring->current);
|
||||||
pixman_region32_clear(&ring->current);
|
pixman_region32_clear(&ring->current);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wlr_damage_ring_get_buffer_damage(struct wlr_damage_ring *ring,
|
void wlr_damage_ring_get_buffer_damage(struct wlr_damage_ring *ring,
|
||||||
int buffer_age, pixman_region32_t *damage) {
|
int buffer_age, pixman_region32_t *damage) {
|
||||||
if (buffer_age <= 0 || buffer_age - 1 > WLR_DAMAGE_RING_PREVIOUS_LEN) {
|
|
||||||
pixman_region32_clear(damage);
|
|
||||||
pixman_region32_union_rect(damage, damage,
|
|
||||||
0, 0, ring->width, ring->height);
|
|
||||||
} else {
|
|
||||||
pixman_region32_copy(damage, &ring->current);
|
pixman_region32_copy(damage, &ring->current);
|
||||||
|
|
||||||
// Accumulate damage from old buffers
|
// Accumulate damage from old buffers
|
||||||
for (int i = 0; i < buffer_age - 1; ++i) {
|
struct wlr_damage_ring_entry *entry;
|
||||||
int j = (ring->previous_idx + i) % WLR_DAMAGE_RING_PREVIOUS_LEN;
|
wl_list_for_each(entry, &ring->previous, link) {
|
||||||
pixman_region32_union(damage, damage, &ring->previous[j].damage);
|
if (--buffer_age <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixman_region32_union(damage, damage, &entry->damage);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if our buffer age is older than anything we are keeping track of, increase
|
||||||
|
// the size
|
||||||
|
if (buffer_age > 0) {
|
||||||
|
pixman_region32_clear(damage);
|
||||||
|
pixman_region32_union_rect(damage, damage,
|
||||||
|
0, 0, ring->width, ring->height);
|
||||||
|
|
||||||
|
struct wlr_damage_ring_entry *entry = calloc(1, sizeof(*entry));
|
||||||
|
if (entry) {
|
||||||
|
pixman_region32_init(&entry->damage);
|
||||||
|
wl_list_insert(ring->previous.prev, &entry->link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check the number of rectangles
|
// Check the number of rectangles
|
||||||
|
|
@ -113,4 +132,3 @@ void wlr_damage_ring_get_buffer_damage(struct wlr_damage_ring *ring,
|
||||||
extents->y2 - extents->y1);
|
extents->y2 - extents->y1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue