diff options
author | Simon Ser <contact@emersion.fr> | 2021-08-11 10:00:50 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-08-12 10:22:19 +0200 |
commit | ee1156b62b74303b47eb86d71379d57a98e29035 (patch) | |
tree | c688ce9fcc0fbe37e66e7bdc0fd4e9aa1c9ef508 /render | |
parent | 93964012e66116e66a2efb2ef4d395f1141b9f13 (diff) |
render/gles2: make wlr_gles2_buffer an addon
Saves us from walking a list.
Diffstat (limited to 'render')
-rw-r--r-- | render/gles2/renderer.c | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index 9ae6e2bb..01efaf1d 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -48,7 +48,7 @@ static struct wlr_gles2_renderer *gles2_get_renderer_in_context( static void destroy_buffer(struct wlr_gles2_buffer *buffer) { wl_list_remove(&buffer->link); - wl_list_remove(&buffer->buffer_destroy.link); + wlr_addon_finish(&buffer->addon); struct wlr_egl_context prev_ctx; wlr_egl_save_context(&prev_ctx); @@ -68,21 +68,26 @@ static void destroy_buffer(struct wlr_gles2_buffer *buffer) { free(buffer); } +static void handle_buffer_destroy(struct wlr_addon *addon) { + struct wlr_gles2_buffer *buffer = + wl_container_of(addon, buffer, addon); + destroy_buffer(buffer); +} + +static const struct wlr_addon_interface buffer_addon_impl = { + .name = "wlr_gles2_buffer", + .destroy = handle_buffer_destroy, +}; + static struct wlr_gles2_buffer *get_buffer(struct wlr_gles2_renderer *renderer, struct wlr_buffer *wlr_buffer) { - struct wlr_gles2_buffer *buffer; - wl_list_for_each(buffer, &renderer->buffers, link) { - if (buffer->buffer == wlr_buffer) { - return buffer; - } + struct wlr_addon *addon = + wlr_addon_find(&wlr_buffer->addons, renderer, &buffer_addon_impl); + if (addon == NULL) { + return NULL; } - return NULL; -} - -static void handle_buffer_destroy(struct wl_listener *listener, void *data) { - struct wlr_gles2_buffer *buffer = - wl_container_of(listener, buffer, buffer_destroy); - destroy_buffer(buffer); + struct wlr_gles2_buffer *buffer = wl_container_of(addon, buffer, addon); + return buffer; } static struct wlr_gles2_buffer *create_buffer(struct wlr_gles2_renderer *renderer, @@ -129,8 +134,8 @@ static struct wlr_gles2_buffer *create_buffer(struct wlr_gles2_renderer *rendere goto error_image; } - buffer->buffer_destroy.notify = handle_buffer_destroy; - wl_signal_add(&wlr_buffer->events.destroy, &buffer->buffer_destroy); + wlr_addon_init(&buffer->addon, &wlr_buffer->addons, renderer, + &buffer_addon_impl); wl_list_insert(&renderer->buffers, &buffer->link); |