gbm: Export a plane getter function
authorBen Widawsky <ben@bwidawsk.net>
Wed, 30 Nov 2016 05:53:52 +0000 (21:53 -0800)
committerBen Widawsky <ben@bwidawsk.net>
Thu, 9 Mar 2017 23:35:44 +0000 (15:35 -0800)
This will be used by clients that need to know the number of planes
allocated for them on behalf of the GL or other API. The best current
example of this is when an extra "plane" is allocated to store
compression data for the primary plane.

v2: Return 1 for cases where there is no image, ie. dumb bo (Daniel)

Signed-off-by: Ben Widawsky <ben@bwidawsk.net>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Acked-by: Daniel Stone <daniels@collabora.com>
src/gbm/backends/dri/gbm_dri.c
src/gbm/gbm-symbols-check
src/gbm/main/gbm.c
src/gbm/main/gbm.h
src/gbm/main/gbmint.h

index 3faa19e3f19312bb7536dd54766000c0757a3b16..9bd647fa19f9b91c4f6ad53d6b2f4071ab32bfc8 100644 (file)
@@ -599,6 +599,32 @@ gbm_dri_bo_get_fd(struct gbm_bo *_bo)
    return fd;
 }
 
+static int
+get_number_planes(struct gbm_dri_device *dri, __DRIimage *image)
+{
+   int num_planes = 0;
+
+   /* Dumb buffers are single-plane only. */
+   if (!image)
+      return 1;
+
+   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes);
+
+   if (num_planes <= 0)
+      num_planes = 1;
+
+   return num_planes;
+}
+
+static int
+gbm_dri_bo_get_planes(struct gbm_bo *_bo)
+{
+   struct gbm_dri_device *dri = gbm_dri_device(_bo->gbm);
+   struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
+
+   return get_number_planes(dri, bo->image);
+}
+
 static void
 gbm_dri_bo_destroy(struct gbm_bo *_bo)
 {
@@ -1091,6 +1117,7 @@ dri_device_create(int fd)
    dri->base.base.is_format_supported = gbm_dri_is_format_supported;
    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_destroy = gbm_dri_bo_destroy;
    dri->base.base.destroy = dri_destroy;
    dri->base.base.surface_create = gbm_dri_surface_create;
index 5a333ffcda04a146aed9f069b3740161bf00cae5..8c4da1b7ea2e7b8ceb801f372833474534e8f8ea 100755 (executable)
@@ -18,6 +18,7 @@ gbm_bo_get_format
 gbm_bo_get_device
 gbm_bo_get_handle
 gbm_bo_get_fd
+gbm_bo_get_plane_count
 gbm_bo_write
 gbm_bo_set_user_data
 gbm_bo_get_user_data
index e96297ec52e0914c02b2434e3a3b6d0db44268d1..377951756443c107ee6a5e40fe689806e9fc2a46 100644 (file)
@@ -223,6 +223,16 @@ gbm_bo_get_fd(struct gbm_bo *bo)
    return bo->gbm->bo_get_fd(bo);
 }
 
+/** Get the number of planes for the given bo.
+ *
+ * \param bo The buffer object
+ * \return The number of planes
+ */
+GBM_EXPORT int
+gbm_bo_get_plane_count(struct gbm_bo *bo)
+{
+   return bo->gbm->bo_get_planes(bo);
+}
 
 /** Write data into the buffer object
  *
index 59daaa164d1be5bb27b0f6526fc8c395367c5b7b..203a23635791d14d9fade133c648502629050d6e 100644 (file)
@@ -315,6 +315,9 @@ gbm_bo_get_handle(struct gbm_bo *bo);
 int
 gbm_bo_get_fd(struct gbm_bo *bo);
 
+int
+gbm_bo_get_plane_count(struct gbm_bo *bo);
+
 int
 gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count);
 
index cfef5eea291fb2261a4c67e532c15c73dada85e5..c6a6701464a4aeb32ddd0d22512204aa8b3f4409 100644 (file)
@@ -76,6 +76,7 @@ struct gbm_device {
    void (*bo_unmap)(struct gbm_bo *bo, void *map_data);
    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);
    void (*bo_destroy)(struct gbm_bo *bo);
 
    struct gbm_surface *(*surface_create)(struct gbm_device *gbm,