[Mesa-dev] [PATCH 2/5] gbm: Add a gbm_device_get_format_modifier_plane_count function
Jason Ekstrand
jason at jlekstrand.net
Wed Aug 16 19:30:56 UTC 2017
This allows the user to query the number of planes required by a given
format+modifier combination without having to create a bo or surface.
---
src/gbm/backends/dri/gbm_dri.c | 26 ++++++++++++++++++++++++++
src/gbm/main/gbm.c | 14 ++++++++++++++
src/gbm/main/gbm.h | 5 +++++
src/gbm/main/gbmint.h | 3 +++
4 files changed, 48 insertions(+)
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 1b2cc4c..1361645 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -639,6 +639,30 @@ gbm_dri_is_format_supported(struct gbm_device *gbm,
}
static int
+gbm_dri_get_format_modifier_plane_count(struct gbm_device *gbm,
+ uint32_t format,
+ uint64_t modifier)
+{
+ struct gbm_dri_device *dri = gbm_dri_device(gbm);
+ uint64_t plane_count;
+
+ if (dri->image->base.version < 16 ||
+ !dri->image->queryDmaBufFormatModifierAttribs)
+ return -1;
+
+ format = gbm_format_canonicalize(format);
+ if (gbm_format_to_dri_format(format) == 0)
+ return -1;
+
+ if (!dri->image->queryDmaBufFormatModifierAttribs(
+ dri->screen, format, modifier,
+ __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT, &plane_count))
+ return -1;
+
+ return plane_count;
+}
+
+static int
gbm_dri_bo_write(struct gbm_bo *_bo, const void *buf, size_t count)
{
struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
@@ -1348,6 +1372,8 @@ dri_device_create(int fd)
dri->base.bo_map = gbm_dri_bo_map;
dri->base.bo_unmap = gbm_dri_bo_unmap;
dri->base.is_format_supported = gbm_dri_is_format_supported;
+ dri->base.get_format_modifier_plane_count =
+ gbm_dri_get_format_modifier_plane_count;
dri->base.bo_write = gbm_dri_bo_write;
dri->base.bo_get_fd = gbm_dri_bo_get_fd;
dri->base.bo_get_planes = gbm_dri_bo_get_planes;
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index df61ff6..2a1cb2e 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -85,6 +85,20 @@ gbm_device_is_format_supported(struct gbm_device *gbm,
return gbm->is_format_supported(gbm, format, usage);
}
+/** Get the number of planes that are required for a given format+modifier
+ *
+ * \param gbm The gbm device returned from gbm_create_device()
+ * \param format The format to query
+ * \param modifier The modifier to query
+ */
+int
+gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
+ uint32_t format,
+ uint64_t modifier)
+{
+ return gbm->get_format_modifier_plane_count(gbm, modifier, format);
+}
+
/** Destroy the gbm device and free all resources associated with it.
*
* \param gbm The device created using gbm_create_device()
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index aed26a0..7710e61b 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -238,6 +238,11 @@ int
gbm_device_is_format_supported(struct gbm_device *gbm,
uint32_t format, uint32_t usage);
+int
+gbm_device_get_format_modifier_plane_count(struct gbm_device *gbm,
+ uint32_t format,
+ uint64_t modifier);
+
void
gbm_device_destroy(struct gbm_device *gbm);
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index c27a7a5..9220a4a 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -61,6 +61,9 @@ struct gbm_device {
int (*is_format_supported)(struct gbm_device *gbm,
uint32_t format,
uint32_t usage);
+ int (*get_format_modifier_plane_count)(struct gbm_device *device,
+ uint32_t format,
+ uint64_t modifier);
struct gbm_bo *(*bo_create)(struct gbm_device *gbm,
uint32_t width, uint32_t height,
--
2.5.0.400.gff86faf
More information about the mesa-dev
mailing list