mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-22 09:59:48 +01:00
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:
parent
651c876e79
commit
7899b97d20
2 changed files with 24 additions and 19 deletions
|
@ -9,6 +9,7 @@
|
|||
#include <wlr/render/wlr_texture.h>
|
||||
#include <wlr/render/drm_format_set.h>
|
||||
#include <wlr/render/interface.h>
|
||||
#include <wlr/util/addon.h>
|
||||
|
||||
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.
|
||||
struct wlr_vk_render_buffer {
|
||||
struct wlr_buffer *wlr_buffer;
|
||||
struct wlr_addon addon;
|
||||
struct wlr_vk_renderer *renderer;
|
||||
struct wlr_vk_render_format_setup *render_setup;
|
||||
struct wl_list link; // wlr_vk_renderer.buffers
|
||||
|
@ -142,8 +144,6 @@ struct wlr_vk_render_buffer {
|
|||
uint32_t mem_count;
|
||||
VkDeviceMemory memories[WLR_DMABUF_MAX_PLANES];
|
||||
bool transitioned;
|
||||
|
||||
struct wl_listener buffer_destroy;
|
||||
};
|
||||
|
||||
// Vulkan wlr_renderer implementation on top of a wlr_vk_device.
|
||||
|
|
|
@ -386,7 +386,7 @@ struct wlr_vk_format_props *vulkan_format_props_from_drm(
|
|||
// buffer import
|
||||
static void destroy_render_buffer(struct wlr_vk_render_buffer *buffer) {
|
||||
wl_list_remove(&buffer->link);
|
||||
wl_list_remove(&buffer->buffer_destroy.link);
|
||||
wlr_addon_finish(&buffer->addon);
|
||||
|
||||
assert(buffer->renderer->current_render_buffer != buffer);
|
||||
|
||||
|
@ -403,23 +403,16 @@ static void destroy_render_buffer(struct wlr_vk_render_buffer *buffer) {
|
|||
free(buffer);
|
||||
}
|
||||
|
||||
static struct wlr_vk_render_buffer *get_render_buffer(
|
||||
struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) {
|
||||
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);
|
||||
static void handle_render_buffer_destroy(struct wlr_addon *addon) {
|
||||
struct wlr_vk_render_buffer *buffer = wl_container_of(addon, buffer, addon);
|
||||
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(
|
||||
struct wlr_vk_renderer *renderer, struct wlr_buffer *wlr_buffer) {
|
||||
VkResult res;
|
||||
|
@ -496,8 +489,8 @@ static struct wlr_vk_render_buffer *create_render_buffer(
|
|||
goto error_view;
|
||||
}
|
||||
|
||||
buffer->buffer_destroy.notify = handle_render_buffer_destroy;
|
||||
wl_signal_add(&wlr_buffer->events.destroy, &buffer->buffer_destroy);
|
||||
wlr_addon_init(&buffer->addon, &wlr_buffer->addons, renderer,
|
||||
&render_buffer_addon_impl);
|
||||
wl_list_insert(&renderer->render_buffers, &buffer->link);
|
||||
|
||||
return buffer;
|
||||
|
@ -515,6 +508,18 @@ error_buffer:
|
|||
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
|
||||
static bool vulkan_bind_buffer(struct wlr_renderer *wlr_renderer,
|
||||
struct wlr_buffer *wlr_buffer) {
|
||||
|
|
Loading…
Reference in a new issue