mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2026-04-17 06:46:39 -04:00
swapchain: Introduce new helper for damage rings
This is advantageous over rolling your own logic because this will choose the ideal buffer (the youngest buffer - the one with the least damage)
This commit is contained in:
parent
3b3ed21e61
commit
551340a39e
2 changed files with 56 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#include <wlr/util/log.h>
|
||||
#include <wlr/render/swapchain.h>
|
||||
#include <wlr/types/wlr_buffer.h>
|
||||
#include <wlr/types/wlr_damage_ring.h>
|
||||
#include "render/allocator/allocator.h"
|
||||
#include "render/drm_format_set.h"
|
||||
|
||||
|
|
@ -108,6 +109,40 @@ struct wlr_buffer *wlr_swapchain_acquire(struct wlr_swapchain *swapchain) {
|
|||
return slot_acquire(swapchain, free_slot);
|
||||
}
|
||||
|
||||
struct wlr_buffer *wlr_swapchain_acquire_from_damage_ring(struct wlr_swapchain *swapchain,
|
||||
struct wlr_damage_ring *ring, pixman_region32_t *damage) {
|
||||
struct wlr_buffer *buffer = NULL;
|
||||
|
||||
struct wlr_damage_ring_buffer *entry;
|
||||
wl_list_for_each(entry, &ring->buffers, link) {
|
||||
for (size_t i = 0; i < WLR_SWAPCHAIN_CAP; i++) {
|
||||
struct wlr_swapchain_slot *slot = &swapchain->slots[i];
|
||||
if (slot->acquired) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (slot->buffer == entry->buffer) {
|
||||
buffer = slot_acquire(swapchain, slot);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (buffer) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!buffer) {
|
||||
buffer = wlr_swapchain_acquire(swapchain);
|
||||
if (!buffer) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
wlr_damage_ring_rotate_buffer(ring, buffer, damage);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
bool wlr_swapchain_has_buffer(struct wlr_swapchain *swapchain,
|
||||
struct wlr_buffer *buffer) {
|
||||
for (size_t i = 0; i < WLR_SWAPCHAIN_CAP; i++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue