Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752488AbeAIM3b (ORCPT + 1 other); Tue, 9 Jan 2018 07:29:31 -0500 Received: from galahad.ideasonboard.com ([185.26.127.97]:56159 "EHLO galahad.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755518AbeAIM32 (ORCPT ); Tue, 9 Jan 2018 07:29:28 -0500 From: Laurent Pinchart To: dri-devel@lists.freedesktop.org Cc: Maxime Ripard , Chen-Yu Tsai , Daniel Vetter , Jani Nikula , Sean Paul , Thomas Petazzoni , Boris Brezillon , Seung-Woo Kim , linux-kernel@vger.kernel.org, Kyungmin Park , Mark Yao , linux-arm-kernel@lists.infradead.org, thomas@vitsch.nl Subject: Re: [PATCH 01/19] drm/fourcc: Add a function to tell if the format embeds alpha Date: Tue, 09 Jan 2018 14:29:58 +0200 Message-ID: <1796930.sWoKI78acY@avalon> Organization: Ideas on Board Oy In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Hi Maxime, Thank you for the patch. On Tuesday, 9 January 2018 12:56:20 EET Maxime Ripard wrote: > There's a bunch of drivers that duplicate the same function to know if a > particular format embeds an alpha component or not. > > Let's create a helper to avoid duplicating that logic. > > Cc: Boris Brezillon > Cc: Eric Anholt > Cc: Inki Dae > Cc: Joonyoung Shim > Cc: Kyungmin Park > Cc: Laurent Pinchart > Cc: Mark Yao > Cc: Seung-Woo Kim > Signed-off-by: Maxime Ripard > --- > drivers/gpu/drm/drm_fourcc.c | 43 +++++++++++++++++++++++++++++++++++++- > include/drm/drm_fourcc.h | 1 +- > 2 files changed, 44 insertions(+) > > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c > index 9c0152df45ad..6e6227d6a46b 100644 > --- a/drivers/gpu/drm/drm_fourcc.c > +++ b/drivers/gpu/drm/drm_fourcc.c > @@ -348,3 +348,46 @@ int drm_format_plane_height(int height, uint32_t > format, int plane) return height / info->vsub; > } > EXPORT_SYMBOL(drm_format_plane_height); > + > +/** > + * drm_format_has_alpha - get whether the format embeds an alpha component > + * @format: pixel format (DRM_FORMAT_*) > + * > + * Returns: > + * true if the format embeds an alpha component, false otherwise. > + */ > +bool drm_format_has_alpha(uint32_t format) > +{ > + switch (format) { > + case DRM_FORMAT_ARGB4444: > + case DRM_FORMAT_ABGR4444: > + case DRM_FORMAT_RGBA4444: > + case DRM_FORMAT_BGRA4444: > + case DRM_FORMAT_ARGB1555: > + case DRM_FORMAT_ABGR1555: > + case DRM_FORMAT_RGBA5551: > + case DRM_FORMAT_BGRA5551: > + case DRM_FORMAT_ARGB8888: > + case DRM_FORMAT_ABGR8888: > + case DRM_FORMAT_RGBA8888: > + case DRM_FORMAT_BGRA8888: > + case DRM_FORMAT_ARGB2101010: > + case DRM_FORMAT_ABGR2101010: > + case DRM_FORMAT_RGBA1010102: > + case DRM_FORMAT_BGRA1010102: > + case DRM_FORMAT_AYUV: > + case DRM_FORMAT_XRGB8888_A8: > + case DRM_FORMAT_XBGR8888_A8: > + case DRM_FORMAT_RGBX8888_A8: > + case DRM_FORMAT_BGRX8888_A8: > + case DRM_FORMAT_RGB888_A8: > + case DRM_FORMAT_BGR888_A8: > + case DRM_FORMAT_RGB565_A8: > + case DRM_FORMAT_BGR565_A8: > + return true; > + > + default: > + return false; > + } > +} > +EXPORT_SYMBOL(drm_format_has_alpha); How about adding the information to struct drm_format_info instead ? drm_format_has_alpha() could then be implemented as bool drm_format_has_alpha(uint32_t format) { const struct drm_format_info *info; info = drm_format_info(format); return info ? info->has_alpha : false; } although drivers should really use the drm_framebuffer::format field directly in most cases, so the helper might not be needed at all. > diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h > index 6942e84b6edd..e08fc22c5f78 100644 > --- a/include/drm/drm_fourcc.h > +++ b/include/drm/drm_fourcc.h > @@ -69,5 +69,6 @@ int drm_format_vert_chroma_subsampling(uint32_t format); > int drm_format_plane_width(int width, uint32_t format, int plane); > int drm_format_plane_height(int height, uint32_t format, int plane); > const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf > *buf); > +bool drm_format_has_alpha(uint32_t format); > > #endif /* __DRM_FOURCC_H__ */ -- Regards, Laurent Pinchart