diff options
author | Simon Ser <contact@emersion.fr> | 2021-08-17 09:34:49 +0200 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2021-08-17 11:08:45 +0200 |
commit | 7544b7abf9997ac9b53777afb4396f92ecc867ba (patch) | |
tree | 3b4592d9112e9e354a9cb67a59d52c79b35e5247 /backend/drm | |
parent | cae7b981369a7670a0fc15bfdd2c65592e199ad8 (diff) |
backend/drm: use addon for wlr_drm_fb
Diffstat (limited to 'backend/drm')
-rw-r--r-- | backend/drm/renderer.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 7531ec32..adda8fd5 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -232,12 +232,16 @@ static struct gbm_bo *get_bo_for_dmabuf(struct gbm_device *gbm, } } -static void drm_fb_handle_wlr_buf_destroy(struct wl_listener *listener, - void *data) { - struct wlr_drm_fb *fb = wl_container_of(listener, fb, wlr_buf_destroy); +static void drm_fb_handle_destroy(struct wlr_addon *addon) { + struct wlr_drm_fb *fb = wl_container_of(addon, fb, addon); drm_fb_destroy(fb); } +static const struct wlr_addon_interface fb_addon_impl = { + .name = "wlr_drm_fb", + .destroy = drm_fb_handle_destroy, +}; + static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm, struct wlr_buffer *buf, const struct wlr_drm_format_set *formats) { struct wlr_drm_fb *fb = calloc(1, sizeof(*fb)); @@ -289,9 +293,7 @@ static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm, fb->wlr_buf = buf; - fb->wlr_buf_destroy.notify = drm_fb_handle_wlr_buf_destroy; - wl_signal_add(&buf->events.destroy, &fb->wlr_buf_destroy); - + wlr_addon_init(&fb->addon, &buf->addons, drm, &fb_addon_impl); wl_list_insert(&drm->fbs, &fb->link); return fb; @@ -305,7 +307,7 @@ error_get_dmabuf: void drm_fb_destroy(struct wlr_drm_fb *fb) { wl_list_remove(&fb->link); - wl_list_remove(&fb->wlr_buf_destroy.link); + wlr_addon_finish(&fb->addon); struct gbm_device *gbm = gbm_bo_get_device(fb->bo); if (drmModeRmFB(gbm_device_get_fd(gbm), fb->id) != 0) { @@ -316,21 +318,13 @@ void drm_fb_destroy(struct wlr_drm_fb *fb) { free(fb); } -static struct wlr_drm_fb *drm_fb_get(struct wlr_drm_backend *drm, - struct wlr_buffer *local_buf) { - struct wlr_drm_fb *fb; - wl_list_for_each(fb, &drm->fbs, link) { - if (fb->wlr_buf == local_buf) { - return fb; - } - } - return NULL; -} - bool drm_fb_import(struct wlr_drm_fb **fb_ptr, struct wlr_drm_backend *drm, struct wlr_buffer *buf, const struct wlr_drm_format_set *formats) { - struct wlr_drm_fb *fb = drm_fb_get(drm, buf); - if (!fb) { + struct wlr_drm_fb *fb; + struct wlr_addon *addon = wlr_addon_find(&buf->addons, drm, &fb_addon_impl); + if (addon != NULL) { + fb = wl_container_of(addon, fb, addon); + } else { fb = drm_fb_create(drm, buf, formats); if (!fb) { return false; |