render/gles2: make wlr_gles2_buffer an addon

Saves us from walking a list.
master
Simon Ser 3 years ago
parent 93964012e6
commit ee1156b62b

@ -12,6 +12,7 @@
#include <wlr/render/interface.h> #include <wlr/render/interface.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/render/wlr_texture.h> #include <wlr/render/wlr_texture.h>
#include <wlr/util/addon.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
struct wlr_gles2_pixel_format { struct wlr_gles2_pixel_format {
@ -84,7 +85,7 @@ struct wlr_gles2_buffer {
GLuint rbo; GLuint rbo;
GLuint fbo; GLuint fbo;
struct wl_listener buffer_destroy; struct wlr_addon addon;
}; };
struct wlr_gles2_texture { struct wlr_gles2_texture {

@ -48,7 +48,7 @@ static struct wlr_gles2_renderer *gles2_get_renderer_in_context(
static void destroy_buffer(struct wlr_gles2_buffer *buffer) { static void destroy_buffer(struct wlr_gles2_buffer *buffer) {
wl_list_remove(&buffer->link); wl_list_remove(&buffer->link);
wl_list_remove(&buffer->buffer_destroy.link); wlr_addon_finish(&buffer->addon);
struct wlr_egl_context prev_ctx; struct wlr_egl_context prev_ctx;
wlr_egl_save_context(&prev_ctx); wlr_egl_save_context(&prev_ctx);
@ -68,21 +68,26 @@ static void destroy_buffer(struct wlr_gles2_buffer *buffer) {
free(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, static struct wlr_gles2_buffer *get_buffer(struct wlr_gles2_renderer *renderer,
struct wlr_buffer *wlr_buffer) { struct wlr_buffer *wlr_buffer) {
struct wlr_gles2_buffer *buffer; struct wlr_addon *addon =
wl_list_for_each(buffer, &renderer->buffers, link) { wlr_addon_find(&wlr_buffer->addons, renderer, &buffer_addon_impl);
if (buffer->buffer == wlr_buffer) { if (addon == NULL) {
return buffer;
}
}
return NULL; return NULL;
} }
struct wlr_gles2_buffer *buffer = wl_container_of(addon, buffer, addon);
static void handle_buffer_destroy(struct wl_listener *listener, void *data) { return buffer;
struct wlr_gles2_buffer *buffer =
wl_container_of(listener, buffer, buffer_destroy);
destroy_buffer(buffer);
} }
static struct wlr_gles2_buffer *create_buffer(struct wlr_gles2_renderer *renderer, 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; goto error_image;
} }
buffer->buffer_destroy.notify = handle_buffer_destroy; wlr_addon_init(&buffer->addon, &wlr_buffer->addons, renderer,
wl_signal_add(&wlr_buffer->events.destroy, &buffer->buffer_destroy); &buffer_addon_impl);
wl_list_insert(&renderer->buffers, &buffer->link); wl_list_insert(&renderer->buffers, &buffer->link);

Loading…
Cancel
Save