backend-drm: use format db for fallback too
authorPekka Paalanen <pekka.paalanen@collabora.com>
Fri, 13 Sep 2019 11:44:24 +0000 (14:44 +0300)
committerPekka Paalanen <pq@iki.fi>
Tue, 1 Oct 2019 09:26:33 +0000 (09:26 +0000)
Replace one more open-coded pixel format translation map with a call to our
central pixel format database, reducing duplication of format information.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
libweston/backend-drm/drm.c
libweston/pixel-formats.c
libweston/pixel-formats.h

index dc092e61184a1c174a410ba18f4406b15aaf98a6..e6db80c937854b721eb3b291589c6ca17b358a7f 100644 (file)
@@ -723,14 +723,13 @@ create_gbm_device(int fd)
 static int
 fallback_format_for(uint32_t format)
 {
-       switch (format) {
-       case GBM_FORMAT_XRGB8888:
-               return GBM_FORMAT_ARGB8888;
-       case GBM_FORMAT_XRGB2101010:
-               return GBM_FORMAT_ARGB2101010;
-       default:
+       const struct pixel_format_info *pf;
+
+       pf = pixel_format_get_info_by_opaque_substitute(format);
+       if (!pf)
                return 0;
-       }
+
+       return pf->format;
 }
 
 static int
index b96f3b21bdf86ccd07e4595f5779ad40564bda91..23d7d5b9f769b60b062d56576b4c2619ffccdc42 100644 (file)
@@ -436,6 +436,19 @@ pixel_format_get_opaque_substitute(const struct pixel_format_info *info)
                return pixel_format_get_info(info->opaque_substitute);
 }
 
+WL_EXPORT const struct pixel_format_info *
+pixel_format_get_info_by_opaque_substitute(uint32_t format)
+{
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_LENGTH(pixel_format_table); i++) {
+               if (pixel_format_table[i].opaque_substitute == format)
+                       return &pixel_format_table[i];
+       }
+
+       return NULL;
+}
+
 WL_EXPORT unsigned int
 pixel_format_width_for_plane(const struct pixel_format_info *info,
                             unsigned int plane,
index 4e651bbbb54508e16b933d43e10faf8f500f4f7e..48395725e885bcb24fd69087de36bc4ef395bffe 100644 (file)
@@ -191,6 +191,23 @@ pixel_format_is_opaque(const struct pixel_format_info *format);
 const struct pixel_format_info *
 pixel_format_get_opaque_substitute(const struct pixel_format_info *format);
 
+/**
+ * For an opaque format, get the equivalent format with alpha instead of an
+ * ignored channel
+ *
+ * This is the opposite lookup from pixel_format_get_opaque_substitute().
+ * Finds the format whose opaque substitute is the given format.
+ *
+ * If the input format is not opaque or does not have ignored (X) bits, then
+ * the search cannot find a match.
+ *
+ * @param format DRM format code to search for
+ * @returns A pixel format info structure for the pixel format whose opaque
+ * substitute is the argument, or NULL if no match.
+ */
+const struct pixel_format_info *
+pixel_format_get_info_by_opaque_substitute(uint32_t format);
+
 /**
  * Return the effective sampling width for a given plane
  *