diff --git a/backend/drm/fb.c b/backend/drm/fb.c index 575f32d91..76086ef65 100644 --- a/backend/drm/fb.c +++ b/backend/drm/fb.c @@ -163,11 +163,10 @@ static struct wlr_drm_fb *drm_fb_create(struct wlr_drm_backend *drm, attribs.modifier)) { // The format isn't supported by the plane. Try stripping the alpha // channel, if any. - const struct wlr_pixel_format_info *info = - drm_get_pixel_format_info(attribs.format); - if (info != NULL && info->opaque_substitute != DRM_FORMAT_INVALID && - wlr_drm_format_set_has(formats, info->opaque_substitute, attribs.modifier)) { - attribs.format = info->opaque_substitute; + uint32_t opaque_substitute = pixel_format_get_opaque_substitute(attribs.format); + if (opaque_substitute != DRM_FORMAT_INVALID && + wlr_drm_format_set_has(formats, opaque_substitute, attribs.modifier)) { + attribs.format = opaque_substitute; } else { wlr_log(WLR_DEBUG, "Buffer format 0x%"PRIX32" with modifier " "0x%"PRIX64" cannot be scanned out", diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index af9908e91..0d3aac501 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -157,11 +157,8 @@ bool drm_plane_pick_render_format(struct wlr_drm_plane *plane, uint32_t format = DRM_FORMAT_ARGB8888; if (!wlr_drm_format_set_get(&plane->formats, format)) { - const struct wlr_pixel_format_info *format_info = - drm_get_pixel_format_info(format); - assert(format_info != NULL && - format_info->opaque_substitute != DRM_FORMAT_INVALID); - format = format_info->opaque_substitute; + format = pixel_format_get_opaque_substitute(format); + assert(format != DRM_FORMAT_INVALID); } const struct wlr_drm_format *render_format = diff --git a/include/render/pixel_format.h b/include/render/pixel_format.h index b5f2b2411..c49567759 100644 --- a/include/render/pixel_format.h +++ b/include/render/pixel_format.h @@ -68,4 +68,10 @@ bool pixel_format_has_alpha(uint32_t fmt); */ bool pixel_format_is_ycbcr(uint32_t fmt); +/** + * Get the equivalent opaque variant of a format if it has an alpha channel, + * DRM_FORMAT_INVALID otherwise. + */ +uint32_t pixel_format_get_opaque_substitute(uint32_t fmt); + #endif diff --git a/render/pixel_format.c b/render/pixel_format.c index c60dd9d2a..3a9b92105 100644 --- a/render/pixel_format.c +++ b/render/pixel_format.c @@ -372,3 +372,11 @@ bool pixel_format_is_ycbcr(uint32_t format) { } return false; } + +uint32_t pixel_format_get_opaque_substitute(uint32_t fmt) { + const struct wlr_pixel_format_info *info = drm_get_pixel_format_info(fmt); + if (info == NULL) { + return DRM_FORMAT_INVALID; + } + return info->opaque_substitute; +}