From 567cc92797846081506ccb36e6af99884a8b6cf2 Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Wed, 21 Apr 2021 11:44:53 -0300 Subject: [PATCH] backend-drm: add DRM_FORMAT_MOD_INVALID to modifier sets when no modifiers are supported From now on, when we can't know the modifiers supported for a certain format, we add DRM_FORMAT_MOD_INVALID to its modifier set. There is some parts where nothing is being added an others where DRM_FORMAT_MOD_LINEAR is being added, so fix them. Signed-off-by: Leandro Ribeiro --- libweston/backend-drm/drm-gbm.c | 4 ++-- libweston/backend-drm/drm-virtual.c | 17 +++++++++++------ libweston/backend-drm/drm.c | 10 +++++++++- libweston/backend-drm/kms.c | 4 ++-- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/libweston/backend-drm/drm-gbm.c b/libweston/backend-drm/drm-gbm.c index b9f29a8c..3db14624 100644 --- a/libweston/backend-drm/drm-gbm.c +++ b/libweston/backend-drm/drm-gbm.c @@ -195,8 +195,8 @@ create_gbm_surface(struct gbm_device *gbm, struct drm_output *output) } #ifdef HAVE_GBM_MODIFIERS - modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers); - if (num_modifiers > 0) { + if (!weston_drm_format_has_modifier(fmt, DRM_FORMAT_MOD_INVALID)) { + modifiers = weston_drm_format_get_modifiers(fmt, &num_modifiers); output->gbm_surface = gbm_surface_create_with_modifiers(gbm, mode->width, mode->height, diff --git a/libweston/backend-drm/drm-virtual.c b/libweston/backend-drm/drm-virtual.c index d016d6ba..6ca32c6f 100644 --- a/libweston/backend-drm/drm-virtual.c +++ b/libweston/backend-drm/drm-virtual.c @@ -94,7 +94,7 @@ drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output) { struct drm_plane *plane; struct weston_drm_format *fmt; - int ret; + uint64_t mod; plane = zalloc(sizeof(*plane)); if (!plane) { @@ -112,11 +112,16 @@ drm_virtual_plane_create(struct drm_backend *b, struct drm_output *output) if (!fmt) goto err; - if ((output->gbm_bo_flags & GBM_BO_USE_LINEAR) && b->fb_modifiers) { - ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_LINEAR); - if (ret < 0) - goto err; - } + /* If output supports linear modifier, we add it to the plane. + * Otherwise we add DRM_FORMAT_MOD_INVALID, as explicit modifiers + * are not supported. */ + if ((output->gbm_bo_flags & GBM_BO_USE_LINEAR) && b->fb_modifiers) + mod = DRM_FORMAT_MOD_LINEAR; + else + mod = DRM_FORMAT_MOD_INVALID; + + if (weston_drm_format_add_modifier(fmt, mod) < 0) + goto err; weston_plane_init(&plane->base, b->compositor, 0, 0); wl_list_insert(&b->plane_list, &plane->link); diff --git a/libweston/backend-drm/drm.c b/libweston/backend-drm/drm.c index d3c178bf..9eb3b138 100644 --- a/libweston/backend-drm/drm.c +++ b/libweston/backend-drm/drm.c @@ -760,6 +760,7 @@ drm_plane_create(struct drm_backend *b, const drmModePlane *kplane, struct drm_plane *plane; drmModeObjectProperties *props; uint64_t *zpos_range_values; + struct weston_drm_format *fmt; plane = zalloc(sizeof(*plane)); if (!plane) { @@ -816,7 +817,14 @@ drm_plane_create(struct drm_backend *b, const drmModePlane *kplane, plane->type = type; plane->zpos_max = DRM_PLANE_ZPOS_INVALID_PLANE; plane->zpos_min = DRM_PLANE_ZPOS_INVALID_PLANE; - if (!weston_drm_format_array_add_format(&plane->formats, format)) + + /* Without universal planes support we can't tell the formats + * and modifiers that the plane support, as we don't know + * anything about the planes. So modifiers are not supported. */ + fmt = weston_drm_format_array_add_format(&plane->formats, format); + if (!fmt) + goto err; + if (!weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_INVALID)) goto err; } diff --git a/libweston/backend-drm/kms.c b/libweston/backend-drm/kms.c index 75730ffe..b82c2189 100644 --- a/libweston/backend-drm/kms.c +++ b/libweston/backend-drm/kms.c @@ -483,7 +483,7 @@ drm_plane_populate_formats(struct drm_plane *plane, const drmModePlane *kplane, } if (fmt->modifiers.size == 0) { - ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_LINEAR); + ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_INVALID); if (ret < 0) goto out; } @@ -500,7 +500,7 @@ fallback: kplane->formats[i]); if (!fmt) return -1; - ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_LINEAR); + ret = weston_drm_format_add_modifier(fmt, DRM_FORMAT_MOD_INVALID); if (ret < 0) return -1; }