[Mesa-dev] [PATCH 11/27] gbm: Get modifiers from DRI

Ben Widawsky benjamin.widawsky at intel.com
Thu Dec 1 22:09:52 UTC 2016


From: Ben Widawsky <ben at bwidawsk.net>

v2: Use stored modifiers from create instead of queryImage

Discussion with Kristian yielded that there is no need for per plane
modifiers.

Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 src/gbm/backends/dri/gbm_dri.c           | 32 ++++++++++++++++++++++++--------
 src/gbm/gbm-symbols-check                |  1 +
 src/gbm/main/gbm.c                       | 22 ++++++++++++++++++++++
 src/gbm/main/gbm.h                       |  3 +++
 src/gbm/main/gbmint.h                    |  5 +----
 src/mesa/drivers/dri/i965/intel_screen.c |  6 ++++++
 6 files changed, 57 insertions(+), 12 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index b1bbbd1..355f9e1 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -38,6 +38,7 @@
 #include <unistd.h>
 #include <dlfcn.h>
 #include <xf86drm.h>
+#include <drm_fourcc.h>
 
 #include <GL/gl.h> /* dri_interface needs GL types */
 #include <GL/internal/dri_interface.h>
@@ -678,6 +679,28 @@ gbm_dri_bo_get_offset(struct gbm_bo *_bo, int plane)
    return (uint32_t)offset;
 }
 
+static uint64_t
+gbm_dri_bo_get_modifier(struct gbm_bo *_bo)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+
+   if (!dri->image || dri->image->base.version < 14) {
+      errno = ENOSYS;
+      return 0;
+   }
+
+   uint64_t ret = 0;
+   int mod;
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_MODIFIER_UPPER, &mod);
+   ret = (uint64_t)mod << 32;
+
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_MODIFIER_LOWER, &mod);
+   ret |= mod;
+
+   return ret;
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1005,14 +1028,6 @@ gbm_dri_bo_create(struct gbm_device *gbm,
    if (bo->image == NULL)
       goto failed;
 
-   bo->base.base.modifiers = calloc(count, sizeof(*modifiers));
-   if (!bo->base.base.modifiers) {
-      dri->image->destroyImage(bo->image);
-      goto failed;
-   }
-   bo->base.base.count = count;
-   memcpy(bo->base.base.modifiers, modifiers, count * sizeof(*modifiers));
-
    dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
                           &bo->base.base.handle.s32);
    dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
@@ -1159,6 +1174,7 @@ dri_device_create(int fd)
    dri->base.base.bo_get_planes = gbm_dri_bo_get_planes;
    dri->base.base.bo_get_stride = gbm_dri_bo_get_stride;
    dri->base.base.bo_get_offset = gbm_dri_bo_get_offset;
+   dri->base.base.bo_get_modifier = gbm_dri_bo_get_modifier;
    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 ba6186c..4c977d4 100755
--- a/src/gbm/gbm-symbols-check
+++ b/src/gbm/gbm-symbols-check
@@ -22,6 +22,7 @@ gbm_bo_get_device
 gbm_bo_get_handle
 gbm_bo_get_fd
 gbm_bo_get_plane_count
+gbm_bo_get_modifier
 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 81408ad..e792c0f 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -262,6 +262,28 @@ gbm_bo_get_plane_count(struct gbm_bo *bo)
    return bo->gbm->bo_get_planes(bo);
 }
 
+/**
+ * Get the chosen modifier for the buffer object
+ *
+ * This function returns the modifier that was chosen for the object. These
+ * properties may be generic, or platform/implementation
+ * dependent.
+ *
+ * \param bo The buffer object
+ * \return Returns count of modifiers, and modifiers \param is set to point to
+ * the array of modifiers
+ * \sa gbm_bo_create_with_modifiers() where possible modifiers are set
+ * \sa gbm_surface_create_with_modifiers() where possible modifiers are set
+ * \sa define DRM_FORMAT_MOD_* in drm_fourcc.h for possible modifiers
+ */
+
+GBM_EXPORT uint64_t
+gbm_bo_get_modifier(struct gbm_bo *bo)
+{
+
+   return bo->gbm->bo_get_modifier(bo);
+}
+
 /** 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 c573093..7c1c6ae 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -327,6 +327,9 @@ gbm_bo_get_handle(struct gbm_bo *bo);
 int
 gbm_bo_get_fd(struct gbm_bo *bo);
 
+uint64_t
+gbm_bo_get_modifier(struct gbm_bo *bo);
+
 int
 gbm_bo_get_plane_count(struct gbm_bo *bo);
 
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index 75b57e7..682984d 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -81,6 +81,7 @@ struct gbm_device {
    int (*bo_get_planes)(struct gbm_bo *bo);
    uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);
    uint32_t (*bo_get_offset)(struct gbm_bo *bo, int plane);
+   uint64_t (*bo_get_modifier)(struct gbm_bo *bo);
    void (*bo_destroy)(struct gbm_bo *bo);
 
    struct gbm_surface *(*surface_create)(struct gbm_device *gbm,
@@ -106,10 +107,6 @@ struct gbm_bo {
    uint32_t height;
    uint32_t stride;
    uint32_t format;
-   struct {
-      uint64_t *modifiers;
-      unsigned int count;
-   };
    union gbm_bo_handle  handle;
    void *user_data;
    void (*destroy_user_data)(struct gbm_bo *, void *);
diff --git a/src/mesa/drivers/dri/i965/intel_screen.c b/src/mesa/drivers/dri/i965/intel_screen.c
index e54332f..afe3189 100644
--- a/src/mesa/drivers/dri/i965/intel_screen.c
+++ b/src/mesa/drivers/dri/i965/intel_screen.c
@@ -657,6 +657,12 @@ intel_query_image(__DRIimage *image, int attrib, int *value)
    case __DRI_IMAGE_ATTRIB_OFFSET:
       *value = image->offset;
       return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_LOWER:
+      *value = (image->modifier & 0xffffffff);
+      return true;
+   case __DRI_IMAGE_ATTRIB_MODIFIER_UPPER:
+      *value = ((image->modifier >> 32) & 0xffffffff);
+      return true;
 
   default:
       return false;
-- 
2.10.2



More information about the mesa-dev mailing list