Mesa (main): gbm: Add gbm_core struct to export code to backends

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jul 6 17:27:20 UTC 2021


Module: Mesa
Branch: main
Commit: f98bcd2f5b1501e51053e2abfbde4fce1a6e51a5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f98bcd2f5b1501e51053e2abfbde4fce1a6e51a5

Author: James Jones <jajones at nvidia.com>
Date:   Thu Jun  3 15:24:43 2021 -0700

gbm: Add gbm_core struct to export code to backends

The GBM core/loader code defines one helper
function used by both itself and the built-in DRI
backend. Presumably, external backend authors
would want to use such functions as well, so
package them into a single struct that will be
passed explicitly to externally loaded backends in
subsequent changes.

Another option considered was to simply export
the gbm_format_canonicalize() function directly,
optionally renaming it to better indicate it is
intended only for "internal" use first. However,
even with a rename, this would expose it to
potential use by applications as well, which is
not ideal, as it is not intended to be part of
the application-facing GBM ABI.

Signed-off-by: James Jones <jajones at nvidia.com>
Reviewed-by: Michel Dänzer <mdaenzer at redhat.com>
Reviewed-by: Emil Velikov <emil.l.velikov at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9902>

---

 src/gbm/backends/dri/gbm_dri.c | 14 +++++++-------
 src/gbm/main/gbm.c             | 14 +++++++++++---
 src/gbm/main/gbmint.h          |  7 +++++--
 3 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index e1ec561a117..baac0909025 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -576,7 +576,7 @@ static const struct gbm_dri_visual gbm_dri_visuals_table[] = {
 static int
 gbm_format_to_dri_format(uint32_t gbm_format)
 {
-   gbm_format = gbm_format_canonicalize(gbm_format);
+   gbm_format = gbm_core.format_canonicalize(gbm_format);
    for (size_t i = 0; i < ARRAY_SIZE(gbm_dri_visuals_table); i++) {
       if (gbm_dri_visuals_table[i].gbm_format == gbm_format)
          return gbm_dri_visuals_table[i].dri_image_format;
@@ -607,7 +607,7 @@ gbm_dri_is_format_supported(struct gbm_device *gbm,
    if ((usage & GBM_BO_USE_CURSOR) && (usage & GBM_BO_USE_RENDERING))
       return 0;
 
-   format = gbm_format_canonicalize(format);
+   format = gbm_core.format_canonicalize(format);
    if (gbm_format_to_dri_format(format) == 0)
       return 0;
 
@@ -644,7 +644,7 @@ gbm_dri_get_format_modifier_plane_count(struct gbm_device *gbm,
        !dri->image->queryDmaBufFormatModifierAttribs)
       return -1;
 
-   format = gbm_format_canonicalize(format);
+   format = gbm_core.format_canonicalize(format);
    if (gbm_format_to_dri_format(format) == 0)
       return -1;
 
@@ -992,7 +992,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
       /* GBM's GBM_FORMAT_* tokens are a strict superset of the DRI FourCC
        * tokens accepted by createImageFromFds, except for not supporting
        * the sARGB format. */
-      fourcc = gbm_format_canonicalize(fd_data->format);
+      fourcc = gbm_core.format_canonicalize(fd_data->format);
 
       image = dri->image->createImageFromFds(dri->screen,
                                              fd_data->width,
@@ -1025,7 +1025,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
       /* GBM's GBM_FORMAT_* tokens are a strict superset of the DRI FourCC
        * tokens accepted by createImageFromDmaBufs2, except for not supporting
        * the sARGB format. */
-      fourcc = gbm_format_canonicalize(fd_data->format);
+      fourcc = gbm_core.format_canonicalize(fd_data->format);
 
       image = dri->image->createImageFromDmaBufs2(dri->screen, fd_data->width,
                                                   fd_data->height, fourcc,
@@ -1161,7 +1161,7 @@ gbm_dri_bo_create(struct gbm_device *gbm,
     */
    assert(!(usage && count));
 
-   format = gbm_format_canonicalize(format);
+   format = gbm_core.format_canonicalize(format);
 
    if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
       return create_dumb(gbm, width, height, format, usage);
@@ -1322,7 +1322,7 @@ gbm_dri_surface_create(struct gbm_device *gbm,
    surf->base.gbm = gbm;
    surf->base.width = width;
    surf->base.height = height;
-   surf->base.format = gbm_format_canonicalize(format);
+   surf->base.format = gbm_core.format_canonicalize(format);
    surf->base.flags = flags;
    if (!modifiers) {
       assert(!count);
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index d53620a8943..8831350257c 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -725,8 +725,8 @@ gbm_surface_has_free_buffers(struct gbm_surface *surf)
 /* The two GBM_BO_FORMAT_[XA]RGB8888 formats alias the GBM_FORMAT_*
  * formats of the same name. We want to accept them whenever someone
  * has a GBM format, but never return them to the user. */
-uint32_t
-gbm_format_canonicalize(uint32_t gbm_format)
+static uint32_t
+format_canonicalize(uint32_t gbm_format)
 {
    switch (gbm_format) {
    case GBM_BO_FORMAT_XRGB8888:
@@ -747,7 +747,7 @@ gbm_format_canonicalize(uint32_t gbm_format)
 GBM_EXPORT char *
 gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
 {
-   gbm_format = gbm_format_canonicalize(gbm_format);
+   gbm_format = format_canonicalize(gbm_format);
 
    desc->name[0] = gbm_format;
    desc->name[1] = gbm_format >> 8;
@@ -757,3 +757,11 @@ gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
 
    return desc->name;
 }
+
+/**
+ * A global table of functions and global variables defined in the core GBM
+ * code that need to be accessed directly by GBM backends.
+ */
+struct gbm_core gbm_core = {
+   .format_canonicalize = format_canonicalize,
+};
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h
index 82c989960e5..81cdab59f9d 100644
--- a/src/gbm/main/gbmint.h
+++ b/src/gbm/main/gbmint.h
@@ -135,7 +135,10 @@ struct gbm_backend {
    struct gbm_device *(*create_device)(int fd);
 };
 
-uint32_t
-gbm_format_canonicalize(uint32_t gbm_format);
+struct gbm_core {
+   uint32_t (*format_canonicalize)(uint32_t gbm_format);
+};
+
+extern struct gbm_core gbm_core;
 
 #endif



More information about the mesa-commit mailing list