From 8a0d0ce98704442c16fa4ecc20a85dd80c67f1d3 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Wed, 21 Nov 2018 14:21:20 +0200 Subject: [PATCH] crtc/kms: Add fallback primary plane formats This avoids having to hardcode the same fallbacks elsewhere multiple times when determining what formats might be suitable for a set of CRTCs. The formats_modifiers hash table is now guaranteed to be populated with at least something, so future code will not need to handle it being empty. The hardcoded fallback formats are a minimal set probably supported by most hardware. XRGB8888 is the format that, according to ancient lore, all DRM devices should support, especially if they don't have the capability to advertise otherwise. Mutter also hardcodes XRGB8888 as the GBM surface format, so it is already required on primary GPUs. XBGR8888 matches the most common OpenGL format, sans alpha channel since scanout hardware has not traditionally supported alpha. XBGR8888 is here also because Mutter hardcodes that format for secondary GPU outputs when using the CPU copy path. https://gitlab.gnome.org/GNOME/mutter/merge_requests/341 --- src/backends/native/meta-crtc-kms.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c index 3f423f966..f4962bece 100644 --- a/src/backends/native/meta-crtc-kms.c +++ b/src/backends/native/meta-crtc-kms.c @@ -211,6 +211,19 @@ free_modifier_array (GArray *array) g_array_free (array, TRUE); } +/* + * In case the DRM driver does not expose a format list for the + * primary plane (does not support universal planes nor + * IN_FORMATS property), hardcode something that is probably supported. + */ +static const uint32_t drm_default_formats[] = + { + DRM_FORMAT_XRGB8888 /* The format everything should always support by convention */, +#if G_BYTE_ORDER == G_LITTLE_ENDIAN + DRM_FORMAT_XBGR8888 /* OpenGL GL_RGBA, GL_UNSIGNED_BYTE format, hopefully supported */ +#endif + }; + static void set_formats_from_array (MetaCrtc *crtc, const uint32_t *formats, @@ -407,6 +420,14 @@ init_crtc_rotations (MetaCrtc *crtc, crtc->all_transforms |= crtc_kms->all_hw_transforms; drmModeFreePlaneResources (planes); + + /* final formats fallback to something hardcoded */ + if (g_hash_table_size (crtc_kms->formats_modifiers) == 0) + { + set_formats_from_array (crtc, + drm_default_formats, + G_N_ELEMENTS (drm_default_formats)); + } } static void