diff options
author | Simon Ser <contact@emersion.fr> | 2022-09-30 15:50:54 +0200 |
---|---|---|
committer | Simon Zeni <simon@bl4ckb0ne.ca> | 2022-09-30 14:02:51 +0000 |
commit | e4efb6b6015adc8b4e5a35b3bb93efcdecb6798d (patch) | |
tree | a772007e3f169e6a025a7ed98277a5728b5f7702 /render/vulkan | |
parent | 7899b97d20073d4bd59072b26a1ef940229ba382 (diff) |
render/vulkan: use addon for wlr_vk_texture
Avoids having to walk the list of all textures.
Diffstat (limited to 'render/vulkan')
-rw-r--r-- | render/vulkan/texture.c | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/render/vulkan/texture.c b/render/vulkan/texture.c index 69ed3391..2566d1eb 100644 --- a/render/vulkan/texture.c +++ b/render/vulkan/texture.c @@ -194,7 +194,10 @@ void vulkan_texture_destroy(struct wlr_vk_texture *texture) { } wl_list_remove(&texture->link); - wl_list_remove(&texture->buffer_destroy.link); + + if (texture->buffer != NULL) { + wlr_addon_finish(&texture->buffer_addon); + } VkDevice dev = texture->renderer->dev->dev; if (texture->ds && texture->ds_pool) { @@ -238,7 +241,6 @@ static struct wlr_vk_texture *vulkan_texture_create( wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height); texture->renderer = renderer; wl_list_insert(&renderer->textures, &texture->link); - wl_list_init(&texture->buffer_destroy.link); return texture; } @@ -688,33 +690,37 @@ error: return NULL; } -static void texture_handle_buffer_destroy(struct wl_listener *listener, - void *data) { +static void texture_handle_buffer_destroy(struct wlr_addon *addon) { struct wlr_vk_texture *texture = - wl_container_of(listener, texture, buffer_destroy); + wl_container_of(addon, texture, buffer_addon); vulkan_texture_destroy(texture); } +static const struct wlr_addon_interface buffer_addon_impl = { + .name = "wlr_vk_texture", + .destroy = texture_handle_buffer_destroy, +}; + static struct wlr_texture *vulkan_texture_from_dmabuf_buffer( struct wlr_vk_renderer *renderer, struct wlr_buffer *buffer, struct wlr_dmabuf_attributes *dmabuf) { - struct wlr_vk_texture *texture; - wl_list_for_each(texture, &renderer->textures, link) { - if (texture->buffer == buffer) { - wlr_buffer_lock(texture->buffer); - return &texture->wlr_texture; - } + struct wlr_addon *addon = + wlr_addon_find(&buffer->addons, renderer, &buffer_addon_impl); + if (addon != NULL) { + struct wlr_vk_texture *texture = + wl_container_of(addon, texture, buffer_addon); + wlr_buffer_lock(texture->buffer); + return &texture->wlr_texture; } - texture = vulkan_texture_from_dmabuf(renderer, dmabuf); + struct wlr_vk_texture *texture = vulkan_texture_from_dmabuf(renderer, dmabuf); if (texture == NULL) { return false; } texture->buffer = wlr_buffer_lock(buffer); - - texture->buffer_destroy.notify = texture_handle_buffer_destroy; - wl_signal_add(&buffer->events.destroy, &texture->buffer_destroy); + wlr_addon_init(&texture->buffer_addon, &buffer->addons, renderer, + &buffer_addon_impl); return &texture->wlr_texture; } |