mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-25 22:25:58 +01:00
render/gles2: make wlr_gles2_texture a wlr_buffer addon
This commit is contained in:
parent
ee1156b62b
commit
ad7651a370
2 changed files with 24 additions and 20 deletions
|
@ -108,8 +108,7 @@ struct wlr_gles2_texture {
|
|||
uint32_t drm_format; // used to interpret upload data
|
||||
// If imported from a wlr_buffer
|
||||
struct wlr_buffer *buffer;
|
||||
|
||||
struct wl_listener buffer_destroy;
|
||||
struct wlr_addon buffer_addon;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -129,7 +129,9 @@ static bool gles2_texture_invalidate(struct wlr_gles2_texture *texture) {
|
|||
|
||||
void gles2_texture_destroy(struct wlr_gles2_texture *texture) {
|
||||
wl_list_remove(&texture->link);
|
||||
wl_list_remove(&texture->buffer_destroy.link);
|
||||
if (texture->buffer != NULL) {
|
||||
wlr_addon_finish(&texture->buffer_addon);
|
||||
}
|
||||
|
||||
struct wlr_egl_context prev_ctx;
|
||||
wlr_egl_save_context(&prev_ctx);
|
||||
|
@ -175,7 +177,6 @@ static struct wlr_gles2_texture *gles2_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;
|
||||
}
|
||||
|
||||
|
@ -294,19 +295,25 @@ static struct wlr_texture *gles2_texture_from_dmabuf(
|
|||
return &texture->wlr_texture;
|
||||
}
|
||||
|
||||
static void texture_handle_buffer_destroy(struct wl_listener *listener,
|
||||
void *data) {
|
||||
static void texture_handle_buffer_destroy(struct wlr_addon *addon) {
|
||||
struct wlr_gles2_texture *texture =
|
||||
wl_container_of(listener, texture, buffer_destroy);
|
||||
wl_container_of(addon, texture, buffer_addon);
|
||||
gles2_texture_destroy(texture);
|
||||
}
|
||||
|
||||
static const struct wlr_addon_interface texture_addon_impl = {
|
||||
.name = "wlr_gles2_texture",
|
||||
.destroy = texture_handle_buffer_destroy,
|
||||
};
|
||||
|
||||
static struct wlr_texture *gles2_texture_from_dmabuf_buffer(
|
||||
struct wlr_gles2_renderer *renderer, struct wlr_buffer *buffer,
|
||||
struct wlr_dmabuf_attributes *dmabuf) {
|
||||
struct wlr_gles2_texture *texture;
|
||||
wl_list_for_each(texture, &renderer->textures, link) {
|
||||
if (texture->buffer == buffer) {
|
||||
struct wlr_addon *addon =
|
||||
wlr_addon_find(&buffer->addons, renderer, &texture_addon_impl);
|
||||
if (addon != NULL) {
|
||||
struct wlr_gles2_texture *texture =
|
||||
wl_container_of(addon, texture, buffer_addon);
|
||||
if (!gles2_texture_invalidate(texture)) {
|
||||
wlr_log(WLR_ERROR, "Failed to invalidate texture");
|
||||
return false;
|
||||
|
@ -314,7 +321,6 @@ static struct wlr_texture *gles2_texture_from_dmabuf_buffer(
|
|||
wlr_buffer_lock(texture->buffer);
|
||||
return &texture->wlr_texture;
|
||||
}
|
||||
}
|
||||
|
||||
struct wlr_texture *wlr_texture =
|
||||
gles2_texture_from_dmabuf(&renderer->wlr_renderer, dmabuf);
|
||||
|
@ -322,11 +328,10 @@ static struct wlr_texture *gles2_texture_from_dmabuf_buffer(
|
|||
return false;
|
||||
}
|
||||
|
||||
texture = gles2_get_texture(wlr_texture);
|
||||
struct wlr_gles2_texture *texture = gles2_get_texture(wlr_texture);
|
||||
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, &texture_addon_impl);
|
||||
|
||||
return &texture->wlr_texture;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue