render/vulkan: use addon for wlr_vk_render_buffer

Avoids having to walk the list containing all of the render buffers.
This commit is contained in:
Simon Ser 2022-09-30 15:50:18 +02:00 committed by Simon Zeni
parent 651c876e79
commit 7899b97d20
2 changed files with 24 additions and 19 deletions

View file

@ -9,6 +9,7 @@
#include <wlr/render/wlr_texture.h> #include <wlr/render/wlr_texture.h>
#include <wlr/render/drm_format_set.h> #include <wlr/render/drm_format_set.h>
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/util/addon.h>
struct wlr_vk_descriptor_pool; struct wlr_vk_descriptor_pool;
@ -132,6 +133,7 @@ struct wlr_vk_render_format_setup {
// Renderer-internal represenation of an wlr_buffer imported for rendering. // Renderer-internal represenation of an wlr_buffer imported for rendering.
struct wlr_vk_render_buffer { struct wlr_vk_render_buffer {
struct wlr_buffer *wlr_buffer; struct wlr_buffer *wlr_buffer;
struct wlr_addon addon;
struct wlr_vk_renderer *renderer; struct wlr_vk_renderer *renderer;
struct wlr_vk_render_format_setup *render_setup; struct wlr_vk_render_format_setup *render_setup;
struct wl_list link; // wlr_vk_renderer.buffers struct wl_list link; // wlr_vk_renderer.buffers
@ -142,8 +144,6 @@ struct wlr_vk_render_buffer {
uint32_t mem_count; uint32_t mem_count;
VkDeviceMemory memories[WLR_DMABUF_MAX_PLANES]; VkDeviceMemory memories[WLR_DMABUF_MAX_PLANES];
bool transitioned; bool transitioned;
struct wl_listener buffer_destroy;
}; };
// Vulkan wlr_renderer implementation on top of a wlr_vk_device. // Vulkan wlr_renderer implementation on top of a wlr_vk_device.

View file

@ -386,7 +386,7 @@ struct wlr_vk_format_props *vulkan_format_props_from_drm(
// buffer import // buffer import
static void destroy_render_buffer(struct wlr_vk_render_buffer *buffer) { static void destroy_render_buffer(struct wlr_vk_render_buffer *buffer) {
wl_list_remove(&buffer->link); wl_list_remove(&buffer->link);
wl_list_remove(&buffer->buffer_destroy.link); wlr_addon_finish(&buffer->addon);
assert(buffer->renderer->current_render_buffer != buffer); assert(buffer->renderer->current_render_buffer != buffer);
@ -403,23 +403,16 @@ static void destroy_render_buffer(struct wlr_vk_render_buffer *buffer) {
free(buffer); free(buffer);
} }
static struct wlr_vk_render_buffer *get_render_buffer( static void handle_render_buffer_destroy(struct wlr_addon *addon) {
struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) { struct wlr_vk_render_buffer *buffer = wl_container_of(addon, buffer, addon);
struct wlr_vk_render_buffer *buffer;
wl_list_for_each(buffer, &renderer->render_buffers, link) {
if (buffer->wlr_buffer == wlr_buffer) {
return buffer;
}
}
return NULL;
}
static void handle_render_buffer_destroy(struct wl_listener *listener, void *data) {
struct wlr_vk_render_buffer *buffer =
wl_container_of(listener, buffer, buffer_destroy);
destroy_render_buffer(buffer); destroy_render_buffer(buffer);
} }
static struct wlr_addon_interface render_buffer_addon_impl = {
.name = "wlr_vk_render_buffer",
.destroy = handle_render_buffer_destroy,
};
static struct wlr_vk_render_buffer *create_render_buffer( static struct wlr_vk_render_buffer *create_render_buffer(
struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) { struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) {
VkResult res; VkResult res;
@ -496,8 +489,8 @@ static struct wlr_vk_render_buffer *create_render_buffer(
goto error_view; goto error_view;
} }
buffer->buffer_destroy.notify = handle_render_buffer_destroy; wlr_addon_init(&buffer->addon, &wlr_buffer->addons, renderer,
wl_signal_add(&wlr_buffer->events.destroy, &buffer->buffer_destroy); &render_buffer_addon_impl);
wl_list_insert(&renderer->render_buffers, &buffer->link); wl_list_insert(&renderer->render_buffers, &buffer->link);
return buffer; return buffer;
@ -515,6 +508,18 @@ error_buffer:
return NULL; return NULL;
} }
static struct wlr_vk_render_buffer *get_render_buffer(
struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) {
struct wlr_addon *addon =
wlr_addon_find(&wlr_buffer->addons, renderer, &render_buffer_addon_impl);
if (addon == NULL) {
return NULL;
}
struct wlr_vk_render_buffer *buffer = wl_container_of(addon, buffer, addon);
return buffer;
}
// interface implementation // interface implementation
static bool vulkan_bind_buffer(struct wlr_renderer *wlr_renderer, static bool vulkan_bind_buffer(struct wlr_renderer *wlr_renderer,
struct wlr_buffer *wlr_buffer) { struct wlr_buffer *wlr_buffer) {