gbm: Give gbm_device a reference to its backend

This will be used for looking up the backend
again at destruction time to perform any backend-
agnostic cleanup.  To facilitate that, also
dispatch device destruction to the backend manager
code.

Signed-off-by: James Jones <jajones@nvidia.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9902>
This commit is contained in:
James Jones 2019-12-13 16:32:57 -08:00 committed by Marge Bot
parent ceb6c44fe4
commit 45bd17610c
4 changed files with 22 additions and 4 deletions

View File

@ -37,12 +37,12 @@
extern const struct gbm_backend gbm_dri_backend;
struct backend_desc {
struct gbm_backend_desc {
const char *name;
const struct gbm_backend *backend;
};
static const struct backend_desc backends[] = {
static const struct gbm_backend_desc backends[] = {
{ "gbm_dri.so", &gbm_dri_backend },
};
@ -52,11 +52,16 @@ find_backend(const char *name, int fd)
struct gbm_device *dev = NULL;
unsigned i;
for (i = 0; i < ARRAY_SIZE(backends) && dev == NULL; ++i) {
for (i = 0; i < ARRAY_SIZE(backends); ++i) {
if (name && strcmp(backends[i].name, name))
continue;
dev = backends[i].backend->create_device(fd);
if (dev) {
dev->backend_desc = &backends[i];
break;
}
}
return dev;
@ -87,3 +92,9 @@ _gbm_create_device(int fd)
return dev;
}
void
_gbm_device_destroy(struct gbm_device *gbm)
{
gbm->destroy(gbm);
}

View File

@ -33,4 +33,7 @@
struct gbm_device *
_gbm_create_device(int fd);
void
_gbm_device_destroy(struct gbm_device *gbm);
#endif

View File

@ -106,7 +106,7 @@ gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
GBM_EXPORT void
gbm_device_destroy(struct gbm_device *gbm)
{
gbm->destroy(gbm);
_gbm_device_destroy(gbm);
}
/** Create a gbm device for allocating buffers

View File

@ -42,6 +42,8 @@
* \brief Internal implementation details of gbm
*/
struct gbm_backend_desc;
/**
* The device used for the memory allocation.
*
@ -51,6 +53,8 @@ struct gbm_device {
/* Hack to make a gbm_device detectable by its first element. */
struct gbm_device *(*dummy)(int);
const struct gbm_backend_desc *backend_desc;
int fd;
const char *name;