[Mesa-dev] [PATCH 04/34] gbm: Export a getter for per plane handles
Ben Widawsky
ben at bwidawsk.net
Tue Jan 24 06:19:03 UTC 2017
v2: Make the error return be -1 instead of 0 because I think 0 is
actually valid.
v3: Set errno to EINVAL when the specified plane is above the total
planes. (Jason Ekstrand)
Return the bo's handle if there is no image ie. for dumb images like cursor (Daniel)
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
Acked-by: Daniel Stone <daniels at collabora.com>
---
src/gbm/backends/dri/gbm_dri.c | 35 +++++++++++++++++++++++++++++++++++
src/gbm/gbm-symbols-check | 1 +
src/gbm/main/gbm.c | 18 ++++++++++++++++++
src/gbm/main/gbm.h | 3 +++
src/gbm/main/gbmint.h | 1 +
5 files changed, 58 insertions(+)
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 8a47e932ef..e01b8f3a8c 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -624,6 +624,40 @@ gbm_dri_bo_get_planes(struct gbm_bo *_bo)
return get_number_planes(dri, bo->image);
}
+static union gbm_bo_handle
+gbm_dri_bo_get_handle_for_plane(struct gbm_bo *_bo, int plane)
+{
+ struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+ struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+ union gbm_bo_handle ret;
+ ret.s32 = -1;
+
+ if (!dri->image || dri->image->base.version < 13 || !dri->image->fromPlanar) {
+ errno = ENOSYS;
+ return ret;
+ }
+
+ if (plane >= get_number_planes(dri, bo->image)) {
+ errno = EINVAL;
+ return ret;
+ }
+
+ if (!bo->image) {
+ ret.s32 = bo->handle;
+ return ret;
+ }
+
+ __DRIimage *image = dri->image->fromPlanar(bo->image, plane, NULL);
+ if (!image) {
+ /* Use the parent's handle */
+ image = bo->image;
+ }
+
+ dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HANDLE, &ret.s32);
+
+ return ret;
+}
+
static void
gbm_dri_bo_destroy(struct gbm_bo *_bo)
{
@@ -1082,6 +1116,7 @@ dri_device_create(int fd)
dri->base.base.bo_write = gbm_dri_bo_write;
dri->base.base.bo_get_fd = gbm_dri_bo_get_fd;
dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
+ dri->base.base.bo_get_handle = gbm_dri_bo_get_handle_for_plane;
dri->base.base.bo_destroy = gbm_dri_bo_destroy;
dri->base.base.destroy = dri_destroy;
dri->base.base.surface_create = gbm_dri_surface_create;
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check
index 8c4da1b7ea..1e6dd4d3ec 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -19,6 +19,7 @@ gbm_bo_get_device
gbm_bo_get_handle
gbm_bo_get_fd
gbm_bo_get_plane_count
+gbm_bo_get_handle_for_plane
gbm_bo_write
gbm_bo_set_user_data
gbm_bo_get_user_data
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 3779517564..066ceffc0a 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -234,6 +234,24 @@ gbm_bo_get_plane_count(struct gbm_bo *bo)
return bo->gbm->bo_get_planes(bo);
}
+/** Get the handle for the specified plane of the buffer object
+ *
+ * This function gets the handle for any plane associated with the BO. When
+ * dealing with multi-planar formats, or formats which might have implicit
+ * planes based on different underlying hardware it is necessary for the client
+ * to be able to get this information to pass to the DRM.
+ *
+ * \param bo The buffer object
+ * \param plane the plane to get a handle for
+ *
+ * \sa gbm_bo_get_handle()
+ */
+GBM_EXPORT union gbm_bo_handle
+gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane)
+{
+ return bo->gbm->bo_get_handle(bo, plane);
+}
+
/** Write data into the buffer object
*
* If the buffer object was created with the GBM_BO_USE_WRITE flag,
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index 203a236357..67548206c4 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -318,6 +318,9 @@ gbm_bo_get_fd(struct gbm_bo *bo);
int
gbm_bo_get_plane_count(struct gbm_bo *bo);
+union gbm_bo_handle
+gbm_bo_get_handle_for_plane(struct gbm_bo *bo, int plane);
+
int
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index c6a6701464..0ec531d099 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -77,6 +77,7 @@ struct gbm_device {
int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);
int (*bo_get_fd)(struct gbm_bo *bo);
int (*bo_get_planes)(struct gbm_bo *bo);
+ union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);
void (*bo_destroy)(struct gbm_bo *bo);
struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
--
2.11.0
More information about the mesa-dev
mailing list