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 <basni@chromium.org>
Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Commit-Queue: Bas Nieuwenhuizen <basni@chromium.org>
This commit is contained in:
Bas Nieuwenhuizen 2021-11-10 13:47:16 +01:00 committed by Commit Bot
parent 5809891959
commit 631d9e4d65
2 changed files with 6 additions and 0 deletions

3
drv.c
View file

@ -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)) {

View file

@ -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);