[Mesa-dev] [PATCH 8/8] gbm: Add entry points for mapping and unmapping bos
Ander Conselvan de Oliveira
conselvan2 at gmail.com
Thu Mar 13 07:02:54 PDT 2014
From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira at intel.com>
Add gbm_bo_map() and gbm_bo_unmap(). This lets a user access the
contents of a bo using the CPU.
---
src/gbm/backends/dri/gbm_dri.c | 3 +++
src/gbm/backends/intel/gbm_intel.c | 24 ++++++++++++++++++++++++
src/gbm/backends/intel/gbm_intel.h | 2 ++
src/gbm/main/gbm.c | 25 +++++++++++++++++++++++++
src/gbm/main/gbm.h | 10 ++++++++++
src/gbm/main/gbmint.h | 2 ++
6 files changed, 66 insertions(+)
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index acf6b24..45d3614 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -345,6 +345,9 @@ gbm_dri_is_format_supported(struct gbm_device *gbm,
usage & GBM_BO_USE_RENDERING)
return 0;
+ if (usage & GBM_BO_USE_MAP)
+ return 0;
+
return 1;
}
diff --git a/src/gbm/backends/intel/gbm_intel.c b/src/gbm/backends/intel/gbm_intel.c
index 2429457..7573cd5 100644
--- a/src/gbm/backends/intel/gbm_intel.c
+++ b/src/gbm/backends/intel/gbm_intel.c
@@ -73,6 +73,24 @@ gbm_intel_bo_write(struct gbm_bo *bo, const void *buf, size_t count)
return drm_intel_bo_unmap(ibo->bo);
}
+static void *
+gbm_intel_bo_map(struct gbm_bo *bo)
+{
+ struct gbm_intel_bo *ibo = gbm_intel_bo(bo);
+
+ drm_intel_bo_map(ibo->bo, 1);
+
+ return ibo->bo->virtual;
+}
+
+static void
+gbm_intel_bo_unmap(struct gbm_bo *bo)
+{
+ struct gbm_intel_bo *ibo = gbm_intel_bo(bo);
+
+ drm_intel_bo_unmap(ibo->bo);
+}
+
static void
gbm_intel_bo_destroy(struct gbm_bo *_bo)
{
@@ -102,6 +120,7 @@ gbm_intel_bo_create_with_bo(struct gbm_device *gbm,
return NULL;
ibo->bo = bo;
+ ibo->usage = usage;
ibo->base.base.gbm = gbm;
ibo->base.base.width = width;
@@ -144,6 +163,9 @@ gbm_intel_bo_create(struct gbm_device *gbm,
tiling = I915_TILING_NONE;
}
+ if (usage & GBM_BO_USE_MAP)
+ tiling = I915_TILING_NONE;
+
if (usage & GBM_BO_USE_RENDERING)
flags |= BO_ALLOC_FOR_RENDER;
@@ -220,6 +242,8 @@ gbm_intel_device_create(int fd)
igbm->base.base.bo_import = gbm_intel_bo_import;
igbm->base.base.is_format_supported = gbm_intel_is_format_supported;
igbm->base.base.bo_write = gbm_intel_bo_write;
+ igbm->base.base.bo_map = gbm_intel_bo_map;
+ igbm->base.base.bo_unmap = gbm_intel_bo_unmap;
igbm->base.base.bo_destroy = gbm_intel_bo_destroy;
igbm->base.base.destroy = gbm_intel_destroy;
igbm->base.base.surface_create = gbm_intel_surface_create;
diff --git a/src/gbm/backends/intel/gbm_intel.h b/src/gbm/backends/intel/gbm_intel.h
index af0689b..1958355 100644
--- a/src/gbm/backends/intel/gbm_intel.h
+++ b/src/gbm/backends/intel/gbm_intel.h
@@ -46,6 +46,8 @@ struct gbm_intel_device {
struct gbm_intel_bo {
struct gbm_drm_bo base;
+ uint32_t usage;
+
drm_intel_bo *bo;
};
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 30785a6..b4532f4 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -249,6 +249,31 @@ gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count)
return bo->gbm->bo_write(bo, buf, count);
}
+/** Map a buffer object in CPU accesible memory
+ *
+ * \param bo The buffer object to be mapped
+ * \return Pointer to the mapped buffer object or NULL on failure
+ */
+GBM_EXPORT void *
+gbm_bo_map(struct gbm_bo *bo)
+{
+ if (bo->gbm->bo_map)
+ return bo->gbm->bo_map(bo);
+ else
+ return NULL;
+}
+
+/** Unmap a preivously mapped buffer object
+ *
+ * \param The buffer object to be unmapped
+ */
+GBM_EXPORT void
+gbm_bo_unmap(struct gbm_bo *bo)
+{
+ if (bo->gbm->bo_unmap)
+ bo->gbm->bo_unmap(bo);
+}
+
/** Get the gbm device used to create the buffer object
*
* \param bo The buffer object
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 9d2a030..63ba624 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -207,6 +207,10 @@ enum gbm_bo_flags {
* combinations.
*/
GBM_BO_USE_WRITE = (1 << 3),
+ /**
+ * Buffer can be mapped with gbm_bo_map().
+ */
+ GBM_BO_USE_MAP = (1 << 4),
};
int
@@ -258,6 +262,12 @@ gbm_bo_get_handle(struct gbm_bo *bo);
int
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
+void *
+gbm_bo_map(struct gbm_bo *bo);
+
+void
+gbm_bo_unmap(struct gbm_bo *bo);
+
void
gbm_bo_set_user_data(struct gbm_bo *bo, void *data,
void (*destroy_user_data)(struct gbm_bo *, void *));
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index 549fa3e..83eb426 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -69,6 +69,8 @@ struct gbm_device {
struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type,
void *buffer, uint32_t usage);
int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);
+ void *(*bo_map)(struct gbm_bo *bo);
+ void (*bo_unmap)(struct gbm_bo *bo);
void (*bo_destroy)(struct gbm_bo *bo);
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
--
1.8.3.2
More information about the mesa-dev
mailing list