[Mesa-dev] [PATCH 2/4] gbm: add gbm_bo_get/set_user_data()
Ander Conselvan de Oliveira
ander.conselvan.de.oliveira at intel.com
Mon Apr 30 03:27:51 PDT 2012
This allows the user to associate some data to a gbm_bo and get a
callback when the bo is destroyed.
---
src/gbm/main/gbm.c | 32 ++++++++++++++++++++++++++++++++
src/gbm/main/gbm.h | 7 +++++++
src/gbm/main/gbmint.h | 2 ++
3 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 79ba650..0871905 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -231,6 +231,35 @@ gbm_bo_get_handle(struct gbm_bo *bo)
return bo->handle;
}
+/** Set the user data associated with a buffer object
+ *
+ * \param bo The buffer object
+ * \param data The data to associate to the buffer object
+ * \param destroy_user_data A callback (which may be %NULL) that will be
+ * called prior to the buffer destruction
+ */
+GBM_EXPORT void
+gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
+ void (*destroy_user_data)(struct gbm_bo *, void *))
+{
+ bo->user_data = data;
+ bo->destroy_user_data = destroy_user_data;
+}
+
+/** Get the user data associated with a buffer object
+ *
+ * \param bo The buffer object
+ * \return Returns the user data associated with the buffer object or %NULL
+ * if no data was associated with it
+ *
+ * \sa gbm_bo_set_user_data()
+ */
+GBM_EXPORT void *
+gbm_bo_get_user_data(struct gbm_bo *bo)
+{
+ return bo->user_data;
+}
+
/**
* Destroys the given buffer object and frees all resources associated with
* it.
@@ -240,6 +269,9 @@ gbm_bo_get_handle(struct gbm_bo *bo)
GBM_EXPORT void
gbm_bo_destroy(struct gbm_bo *bo)
{
+ if (bo->destroy_user_data)
+ bo->destroy_user_data(bo, bo->user_data);
+
bo->gbm->bo_destroy(bo);
}
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 6748752..16489f3 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -246,6 +246,13 @@ union gbm_bo_handle
gbm_bo_get_handle(struct gbm_bo *bo);
void
+gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
+ void (*destroy_user_data)(struct gbm_bo *, void *));
+
+void *
+gbm_bo_get_user_data(struct gbm_bo *bo);
+
+void
gbm_bo_destroy(struct gbm_bo *bo);
struct gbm_surface *
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index 53d73f4..0e98bdf 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -94,6 +94,8 @@ struct gbm_bo {
uint32_t pitch;
uint32_t format;
union gbm_bo_handle handle;
+ void *user_data;
+ void (*destroy_user_data)(struct gbm_bo *, void *);
};
struct gbm_surface {
--
1.7.4.1
More information about the mesa-dev
mailing list