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@nvidia.com>
Reviewed-by: Michel Dänzer <mdaenzer@redhat.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9902>
This commit is contained in:
James Jones 2021-06-03 15:24:43 -07:00 committed by Marge Bot
parent 45bd17610c
commit f98bcd2f5b
3 changed files with 23 additions and 12 deletions

View file

@ -576,7 +576,7 @@ static const struct gbm_dri_visual gbm_dri_visuals_table[] = {
static int static int
gbm_format_to_dri_format(uint32_t gbm_format) 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++) { for (size_t i = 0; i < ARRAY_SIZE(gbm_dri_visuals_table); i++) {
if (gbm_dri_visuals_table[i].gbm_format == gbm_format) if (gbm_dri_visuals_table[i].gbm_format == gbm_format)
return gbm_dri_visuals_table[i].dri_image_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)) if ((usage & GBM_BO_USE_CURSOR) && (usage & GBM_BO_USE_RENDERING))
return 0; return 0;
format = gbm_format_canonicalize(format); format = gbm_core.format_canonicalize(format);
if (gbm_format_to_dri_format(format) == 0) if (gbm_format_to_dri_format(format) == 0)
return 0; return 0;
@ -644,7 +644,7 @@ gbm_dri_get_format_modifier_plane_count(struct gbm_device *gbm,
!dri->image->queryDmaBufFormatModifierAttribs) !dri->image->queryDmaBufFormatModifierAttribs)
return -1; return -1;
format = gbm_format_canonicalize(format); format = gbm_core.format_canonicalize(format);
if (gbm_format_to_dri_format(format) == 0) if (gbm_format_to_dri_format(format) == 0)
return -1; 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 /* GBM's GBM_FORMAT_* tokens are a strict superset of the DRI FourCC
* tokens accepted by createImageFromFds, except for not supporting * tokens accepted by createImageFromFds, except for not supporting
* the sARGB format. */ * the sARGB format. */
fourcc = gbm_format_canonicalize(fd_data->format); fourcc = gbm_core.format_canonicalize(fd_data->format);
image = dri->image->createImageFromFds(dri->screen, image = dri->image->createImageFromFds(dri->screen,
fd_data->width, 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 /* GBM's GBM_FORMAT_* tokens are a strict superset of the DRI FourCC
* tokens accepted by createImageFromDmaBufs2, except for not supporting * tokens accepted by createImageFromDmaBufs2, except for not supporting
* the sARGB format. */ * 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, image = dri->image->createImageFromDmaBufs2(dri->screen, fd_data->width,
fd_data->height, fourcc, fd_data->height, fourcc,
@ -1161,7 +1161,7 @@ gbm_dri_bo_create(struct gbm_device *gbm,
*/ */
assert(!(usage && count)); assert(!(usage && count));
format = gbm_format_canonicalize(format); format = gbm_core.format_canonicalize(format);
if (usage & GBM_BO_USE_WRITE || dri->image == NULL) if (usage & GBM_BO_USE_WRITE || dri->image == NULL)
return create_dumb(gbm, width, height, format, usage); 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.gbm = gbm;
surf->base.width = width; surf->base.width = width;
surf->base.height = height; surf->base.height = height;
surf->base.format = gbm_format_canonicalize(format); surf->base.format = gbm_core.format_canonicalize(format);
surf->base.flags = flags; surf->base.flags = flags;
if (!modifiers) { if (!modifiers) {
assert(!count); assert(!count);

View file

@ -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_* /* The two GBM_BO_FORMAT_[XA]RGB8888 formats alias the GBM_FORMAT_*
* formats of the same name. We want to accept them whenever someone * formats of the same name. We want to accept them whenever someone
* has a GBM format, but never return them to the user. */ * has a GBM format, but never return them to the user. */
uint32_t static uint32_t
gbm_format_canonicalize(uint32_t gbm_format) format_canonicalize(uint32_t gbm_format)
{ {
switch (gbm_format) { switch (gbm_format) {
case GBM_BO_FORMAT_XRGB8888: case GBM_BO_FORMAT_XRGB8888:
@ -747,7 +747,7 @@ gbm_format_canonicalize(uint32_t gbm_format)
GBM_EXPORT char * GBM_EXPORT char *
gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc) 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[0] = gbm_format;
desc->name[1] = gbm_format >> 8; 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; 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,
};

View file

@ -135,7 +135,10 @@ struct gbm_backend {
struct gbm_device *(*create_device)(int fd); struct gbm_device *(*create_device)(int fd);
}; };
uint32_t struct gbm_core {
gbm_format_canonicalize(uint32_t gbm_format); uint32_t (*format_canonicalize)(uint32_t gbm_format);
};
extern struct gbm_core gbm_core;
#endif #endif