render/vulkan: use addon for wlr_vk_texture
Avoids having to walk the list of all textures.
This commit is contained in:
parent
7899b97d20
commit
e4efb6b601
|
@ -246,7 +246,7 @@ struct wlr_vk_texture {
|
||||||
|
|
||||||
// If imported from a wlr_buffer
|
// If imported from a wlr_buffer
|
||||||
struct wlr_buffer *buffer;
|
struct wlr_buffer *buffer;
|
||||||
struct wl_listener buffer_destroy;
|
struct wlr_addon buffer_addon;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture);
|
struct wlr_vk_texture *vulkan_get_texture(struct wlr_texture *wlr_texture);
|
||||||
|
|
|
@ -194,7 +194,10 @@ void vulkan_texture_destroy(struct wlr_vk_texture *texture) {
|
||||||
}
|
}
|
||||||
|
|
||||||
wl_list_remove(&texture->link);
|
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;
|
VkDevice dev = texture->renderer->dev->dev;
|
||||||
if (texture->ds && texture->ds_pool) {
|
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);
|
wlr_texture_init(&texture->wlr_texture, &texture_impl, width, height);
|
||||||
texture->renderer = renderer;
|
texture->renderer = renderer;
|
||||||
wl_list_insert(&renderer->textures, &texture->link);
|
wl_list_insert(&renderer->textures, &texture->link);
|
||||||
wl_list_init(&texture->buffer_destroy.link);
|
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -688,33 +690,37 @@ error:
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void texture_handle_buffer_destroy(struct wl_listener *listener,
|
static void texture_handle_buffer_destroy(struct wlr_addon *addon) {
|
||||||
void *data) {
|
|
||||||
struct wlr_vk_texture *texture =
|
struct wlr_vk_texture *texture =
|
||||||
wl_container_of(listener, texture, buffer_destroy);
|
wl_container_of(addon, texture, buffer_addon);
|
||||||
vulkan_texture_destroy(texture);
|
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(
|
static struct wlr_texture *vulkan_texture_from_dmabuf_buffer(
|
||||||
struct wlr_vk_renderer *renderer, struct wlr_buffer *buffer,
|
struct wlr_vk_renderer *renderer, struct wlr_buffer *buffer,
|
||||||
struct wlr_dmabuf_attributes *dmabuf) {
|
struct wlr_dmabuf_attributes *dmabuf) {
|
||||||
struct wlr_vk_texture *texture;
|
struct wlr_addon *addon =
|
||||||
wl_list_for_each(texture, &renderer->textures, link) {
|
wlr_addon_find(&buffer->addons, renderer, &buffer_addon_impl);
|
||||||
if (texture->buffer == buffer) {
|
if (addon != NULL) {
|
||||||
|
struct wlr_vk_texture *texture =
|
||||||
|
wl_container_of(addon, texture, buffer_addon);
|
||||||
wlr_buffer_lock(texture->buffer);
|
wlr_buffer_lock(texture->buffer);
|
||||||
return &texture->wlr_texture;
|
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) {
|
if (texture == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
texture->buffer = wlr_buffer_lock(buffer);
|
texture->buffer = wlr_buffer_lock(buffer);
|
||||||
|
wlr_addon_init(&texture->buffer_addon, &buffer->addons, renderer,
|
||||||
texture->buffer_destroy.notify = texture_handle_buffer_destroy;
|
&buffer_addon_impl);
|
||||||
wl_signal_add(&buffer->events.destroy, &texture->buffer_destroy);
|
|
||||||
|
|
||||||
return &texture->wlr_texture;
|
return &texture->wlr_texture;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue