From 631d9e4d653567eba0dfc846ec849be5e490f574 Mon Sep 17 00:00:00 2001 From: Bas Nieuwenhuizen Date: Wed, 10 Nov 2021 13:47:16 +0100 Subject: drv: Add new bo_release driver callback. The current bo_destroy callback only gets called if the bo has the last references to the GEM BOs, and otherwise plain free gets called. However, this is an issue if bo->priv contains something per bo that needs to be cleaned up. To solve this we introduce a new callback to clean up things per bo instance. BUG=b:185869479 TEST=none for this patch. See follow-on patch making use of this. Change-Id: I9d48b3b5a70264adbc4de55a5c7b18e1a2209553 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3270683 Tested-by: Bas Nieuwenhuizen Reviewed-by: Yiwei Zhang Commit-Queue: Bas Nieuwenhuizen --- drv.c | 3 +++ drv_priv.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/drv.c b/drv.c index 31a5ee5..ada02ba 100644 --- a/drv.c +++ b/drv.c @@ -300,6 +300,9 @@ static bool drv_bo_release(struct bo *bo) struct driver *drv = bo->drv; uintptr_t num; + if (drv->backend->bo_release) + drv->backend->bo_release(bo); + pthread_mutex_lock(&drv->buffer_table_lock); for (size_t plane = 0; plane < bo->meta.num_planes; plane++) { if (!drmHashLookup(drv->buffer_table, bo->handles[plane].u32, (void **)&num)) { diff --git a/drv_priv.h b/drv_priv.h index 63f7804..d2da440 100644 --- a/drv_priv.h +++ b/drv_priv.h @@ -85,6 +85,9 @@ struct backend { int (*bo_compute_metadata)(struct bo *bo, uint32_t width, uint32_t height, uint32_t format, uint64_t use_flags, const uint64_t *modifiers, uint32_t count); int (*bo_create_from_metadata)(struct bo *bo); + /* Called for every non-test-buffer BO on free */ + int (*bo_release)(struct bo *bo); + /* Called on free if this bo is the last object referencing the contained GEM BOs */ int (*bo_destroy)(struct bo *bo); int (*bo_import)(struct bo *bo, struct drv_import_fd_data *data); void *(*bo_map)(struct bo *bo, struct vma *vma, size_t plane, uint32_t map_flags); -- cgit v1.2.3