[PATCH v3.1 01/15] drm: Move format-related helpers to drm_fourcc.c

Daniel Vetter daniel at ffwll.ch
Thu Jun 9 10:03:22 UTC 2016


On Thu, Jun 09, 2016 at 12:54:08PM +0300, Laurent Pinchart wrote:
> The drm_crtc.c file is a mess, making the ABI documentation confusing
> since all functions are in the same bag. Split the format-related
> helpers to a new drm_fourcc.c file.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>

Applied to drm-misc, thanks.

> ---
>  Documentation/DocBook/gpu.tmpl |   5 +
>  drivers/gpu/drm/Makefile       |   2 +-
>  drivers/gpu/drm/drm_crtc.c     | 289 -------------------------------------
>  drivers/gpu/drm/drm_fourcc.c   | 320 +++++++++++++++++++++++++++++++++++++++++
>  include/drm/drmP.h             |   1 +
>  include/drm/drm_crtc.h         |   9 --
>  include/drm/drm_fourcc.h       |  37 +++++
>  7 files changed, 364 insertions(+), 299 deletions(-)
>  create mode 100644 drivers/gpu/drm/drm_fourcc.c
>  create mode 100644 include/drm/drm_fourcc.h
> 
> Changes since v3:
> 
> - Moved the documentation to a new subsection of the modesetting chapter

Bikeshed: I know it's against kernel standards, but I like to include the
per-patch changelog with the merged commit. I think that's a better
tradeoff on the clean history vs. full history tradeoff scale. Some links
for why and all that:

http://jamey.thesharps.us/2016/05/perspectives-on-commit-history.html

with links to more in there. tl;dr; Also including the messy way needed to
get to a clean final patch is valuable. Same reasons why we add links to
bugzilla and other auxiliary information.

Cheers, Daniel
> 
> diff --git a/Documentation/DocBook/gpu.tmpl b/Documentation/DocBook/gpu.tmpl
> index 7586bf75f62e..7043b270cf54 100644
> --- a/Documentation/DocBook/gpu.tmpl
> +++ b/Documentation/DocBook/gpu.tmpl
> @@ -1018,6 +1018,11 @@ int max_width, max_height;</synopsis>
>        </para>
>      </sect2>
>      <sect2>
> +      <title>DRM Format Handling</title>
> +!Iinclude/drm/drm_fourcc.h
> +!Edrivers/gpu/drm/drm_fourcc.c
> +    </sect2>
> +    <sect2>
>        <title>Dumb Buffer Objects</title>
>        <para>
>  	The KMS API doesn't standardize backing storage object creation and
> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile
> index be43afb08c69..aa24af35c068 100644
> --- a/drivers/gpu/drm/Makefile
> +++ b/drivers/gpu/drm/Makefile
> @@ -8,7 +8,7 @@ drm-y       :=	drm_auth.o drm_bufs.o drm_cache.o \
>  		drm_lock.o drm_memory.o drm_drv.o drm_vm.o \
>  		drm_scatter.o drm_pci.o \
>  		drm_platform.o drm_sysfs.o drm_hashtab.o drm_mm.o \
> -		drm_crtc.o drm_modes.o drm_edid.o \
> +		drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
>  		drm_info.o drm_debugfs.o drm_encoder_slave.o \
>  		drm_trace_points.o drm_global.o drm_prime.o \
>  		drm_rect.o drm_vma_manager.o drm_flip_work.o \
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index 0e3cc66aa8b7..e5369529af06 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -239,37 +239,6 @@ const char *drm_get_subpixel_order_name(enum subpixel_order order)
>  }
>  EXPORT_SYMBOL(drm_get_subpixel_order_name);
>  
> -static char printable_char(int c)
> -{
> -	return isascii(c) && isprint(c) ? c : '?';
> -}
> -
> -/**
> - * drm_get_format_name - return a string for drm fourcc format
> - * @format: format to compute name of
> - *
> - * Note that the buffer used by this function is globally shared and owned by
> - * the function itself.
> - *
> - * FIXME: This isn't really multithreading safe.
> - */
> -const char *drm_get_format_name(uint32_t format)
> -{
> -	static char buf[32];
> -
> -	snprintf(buf, sizeof(buf),
> -		 "%c%c%c%c %s-endian (0x%08x)",
> -		 printable_char(format & 0xff),
> -		 printable_char((format >> 8) & 0xff),
> -		 printable_char((format >> 16) & 0xff),
> -		 printable_char((format >> 24) & 0x7f),
> -		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
> -		 format);
> -
> -	return buf;
> -}
> -EXPORT_SYMBOL(drm_get_format_name);
> -
>  /*
>   * Internal function to assign a slot in the object idr and optionally
>   * register the object into the idr.
> @@ -5544,264 +5513,6 @@ int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
>  }
>  
>  /**
> - * drm_fb_get_bpp_depth - get the bpp/depth values for format
> - * @format: pixel format (DRM_FORMAT_*)
> - * @depth: storage for the depth value
> - * @bpp: storage for the bpp value
> - *
> - * This only supports RGB formats here for compat with code that doesn't use
> - * pixel formats directly yet.
> - */
> -void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> -			  int *bpp)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_C8:
> -	case DRM_FORMAT_RGB332:
> -	case DRM_FORMAT_BGR233:
> -		*depth = 8;
> -		*bpp = 8;
> -		break;
> -	case DRM_FORMAT_XRGB1555:
> -	case DRM_FORMAT_XBGR1555:
> -	case DRM_FORMAT_RGBX5551:
> -	case DRM_FORMAT_BGRX5551:
> -	case DRM_FORMAT_ARGB1555:
> -	case DRM_FORMAT_ABGR1555:
> -	case DRM_FORMAT_RGBA5551:
> -	case DRM_FORMAT_BGRA5551:
> -		*depth = 15;
> -		*bpp = 16;
> -		break;
> -	case DRM_FORMAT_RGB565:
> -	case DRM_FORMAT_BGR565:
> -		*depth = 16;
> -		*bpp = 16;
> -		break;
> -	case DRM_FORMAT_RGB888:
> -	case DRM_FORMAT_BGR888:
> -		*depth = 24;
> -		*bpp = 24;
> -		break;
> -	case DRM_FORMAT_XRGB8888:
> -	case DRM_FORMAT_XBGR8888:
> -	case DRM_FORMAT_RGBX8888:
> -	case DRM_FORMAT_BGRX8888:
> -		*depth = 24;
> -		*bpp = 32;
> -		break;
> -	case DRM_FORMAT_XRGB2101010:
> -	case DRM_FORMAT_XBGR2101010:
> -	case DRM_FORMAT_RGBX1010102:
> -	case DRM_FORMAT_BGRX1010102:
> -	case DRM_FORMAT_ARGB2101010:
> -	case DRM_FORMAT_ABGR2101010:
> -	case DRM_FORMAT_RGBA1010102:
> -	case DRM_FORMAT_BGRA1010102:
> -		*depth = 30;
> -		*bpp = 32;
> -		break;
> -	case DRM_FORMAT_ARGB8888:
> -	case DRM_FORMAT_ABGR8888:
> -	case DRM_FORMAT_RGBA8888:
> -	case DRM_FORMAT_BGRA8888:
> -		*depth = 32;
> -		*bpp = 32;
> -		break;
> -	default:
> -		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> -			      drm_get_format_name(format));
> -		*depth = 0;
> -		*bpp = 0;
> -		break;
> -	}
> -}
> -EXPORT_SYMBOL(drm_fb_get_bpp_depth);
> -
> -/**
> - * drm_format_num_planes - get the number of planes for format
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The number of planes used by the specified pixel format.
> - */
> -int drm_format_num_planes(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV444:
> -	case DRM_FORMAT_YVU444:
> -		return 3;
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_NV24:
> -	case DRM_FORMAT_NV42:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_num_planes);
> -
> -/**
> - * drm_format_plane_cpp - determine the bytes per pixel value
> - * @format: pixel format (DRM_FORMAT_*)
> - * @plane: plane index
> - *
> - * Returns:
> - * The bytes per pixel value for the specified plane.
> - */
> -int drm_format_plane_cpp(uint32_t format, int plane)
> -{
> -	unsigned int depth;
> -	int bpp;
> -
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	switch (format) {
> -	case DRM_FORMAT_YUYV:
> -	case DRM_FORMAT_YVYU:
> -	case DRM_FORMAT_UYVY:
> -	case DRM_FORMAT_VYUY:
> -		return 2;
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_NV24:
> -	case DRM_FORMAT_NV42:
> -		return plane ? 2 : 1;
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV444:
> -	case DRM_FORMAT_YVU444:
> -		return 1;
> -	default:
> -		drm_fb_get_bpp_depth(format, &depth, &bpp);
> -		return bpp >> 3;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_plane_cpp);
> -
> -/**
> - * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The horizontal chroma subsampling factor for the
> - * specified pixel format.
> - */
> -int drm_format_horz_chroma_subsampling(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV411:
> -	case DRM_FORMAT_YVU411:
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -		return 4;
> -	case DRM_FORMAT_YUYV:
> -	case DRM_FORMAT_YVYU:
> -	case DRM_FORMAT_UYVY:
> -	case DRM_FORMAT_VYUY:
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -	case DRM_FORMAT_NV16:
> -	case DRM_FORMAT_NV61:
> -	case DRM_FORMAT_YUV422:
> -	case DRM_FORMAT_YVU422:
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
> -
> -/**
> - * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
> - * @format: pixel format (DRM_FORMAT_*)
> - *
> - * Returns:
> - * The vertical chroma subsampling factor for the
> - * specified pixel format.
> - */
> -int drm_format_vert_chroma_subsampling(uint32_t format)
> -{
> -	switch (format) {
> -	case DRM_FORMAT_YUV410:
> -	case DRM_FORMAT_YVU410:
> -		return 4;
> -	case DRM_FORMAT_YUV420:
> -	case DRM_FORMAT_YVU420:
> -	case DRM_FORMAT_NV12:
> -	case DRM_FORMAT_NV21:
> -		return 2;
> -	default:
> -		return 1;
> -	}
> -}
> -EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
> -
> -/**
> - * drm_format_plane_width - width of the plane given the first plane
> - * @width: width of the first plane
> - * @format: pixel format
> - * @plane: plane index
> - *
> - * Returns:
> - * The width of @plane, given that the width of the first plane is @width.
> - */
> -int drm_format_plane_width(int width, uint32_t format, int plane)
> -{
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	if (plane == 0)
> -		return width;
> -
> -	return width / drm_format_horz_chroma_subsampling(format);
> -}
> -EXPORT_SYMBOL(drm_format_plane_width);
> -
> -/**
> - * drm_format_plane_height - height of the plane given the first plane
> - * @height: height of the first plane
> - * @format: pixel format
> - * @plane: plane index
> - *
> - * Returns:
> - * The height of @plane, given that the height of the first plane is @height.
> - */
> -int drm_format_plane_height(int height, uint32_t format, int plane)
> -{
> -	if (plane >= drm_format_num_planes(format))
> -		return 0;
> -
> -	if (plane == 0)
> -		return height;
> -
> -	return height / drm_format_vert_chroma_subsampling(format);
> -}
> -EXPORT_SYMBOL(drm_format_plane_height);
> -
> -/**
>   * drm_rotation_simplify() - Try to simplify the rotation
>   * @rotation: Rotation to be simplified
>   * @supported_rotations: Supported rotations
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> new file mode 100644
> index 000000000000..0645c85d5f95
> --- /dev/null
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -0,0 +1,320 @@
> +/*
> + * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> + *
> + * DRM core format related functions
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +
> +#include <linux/bug.h>
> +#include <linux/ctype.h>
> +#include <linux/export.h>
> +#include <linux/kernel.h>
> +
> +#include <drm/drmP.h>
> +#include <drm/drm_fourcc.h>
> +
> +static char printable_char(int c)
> +{
> +	return isascii(c) && isprint(c) ? c : '?';
> +}
> +
> +/**
> + * drm_get_format_name - return a string for drm fourcc format
> + * @format: format to compute name of
> + *
> + * Note that the buffer used by this function is globally shared and owned by
> + * the function itself.
> + *
> + * FIXME: This isn't really multithreading safe.
> + */
> +const char *drm_get_format_name(uint32_t format)
> +{
> +	static char buf[32];
> +
> +	snprintf(buf, sizeof(buf),
> +		 "%c%c%c%c %s-endian (0x%08x)",
> +		 printable_char(format & 0xff),
> +		 printable_char((format >> 8) & 0xff),
> +		 printable_char((format >> 16) & 0xff),
> +		 printable_char((format >> 24) & 0x7f),
> +		 format & DRM_FORMAT_BIG_ENDIAN ? "big" : "little",
> +		 format);
> +
> +	return buf;
> +}
> +EXPORT_SYMBOL(drm_get_format_name);
> +
> +/**
> + * drm_fb_get_bpp_depth - get the bpp/depth values for format
> + * @format: pixel format (DRM_FORMAT_*)
> + * @depth: storage for the depth value
> + * @bpp: storage for the bpp value
> + *
> + * This only supports RGB formats here for compat with code that doesn't use
> + * pixel formats directly yet.
> + */
> +void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> +			  int *bpp)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_C8:
> +	case DRM_FORMAT_RGB332:
> +	case DRM_FORMAT_BGR233:
> +		*depth = 8;
> +		*bpp = 8;
> +		break;
> +	case DRM_FORMAT_XRGB1555:
> +	case DRM_FORMAT_XBGR1555:
> +	case DRM_FORMAT_RGBX5551:
> +	case DRM_FORMAT_BGRX5551:
> +	case DRM_FORMAT_ARGB1555:
> +	case DRM_FORMAT_ABGR1555:
> +	case DRM_FORMAT_RGBA5551:
> +	case DRM_FORMAT_BGRA5551:
> +		*depth = 15;
> +		*bpp = 16;
> +		break;
> +	case DRM_FORMAT_RGB565:
> +	case DRM_FORMAT_BGR565:
> +		*depth = 16;
> +		*bpp = 16;
> +		break;
> +	case DRM_FORMAT_RGB888:
> +	case DRM_FORMAT_BGR888:
> +		*depth = 24;
> +		*bpp = 24;
> +		break;
> +	case DRM_FORMAT_XRGB8888:
> +	case DRM_FORMAT_XBGR8888:
> +	case DRM_FORMAT_RGBX8888:
> +	case DRM_FORMAT_BGRX8888:
> +		*depth = 24;
> +		*bpp = 32;
> +		break;
> +	case DRM_FORMAT_XRGB2101010:
> +	case DRM_FORMAT_XBGR2101010:
> +	case DRM_FORMAT_RGBX1010102:
> +	case DRM_FORMAT_BGRX1010102:
> +	case DRM_FORMAT_ARGB2101010:
> +	case DRM_FORMAT_ABGR2101010:
> +	case DRM_FORMAT_RGBA1010102:
> +	case DRM_FORMAT_BGRA1010102:
> +		*depth = 30;
> +		*bpp = 32;
> +		break;
> +	case DRM_FORMAT_ARGB8888:
> +	case DRM_FORMAT_ABGR8888:
> +	case DRM_FORMAT_RGBA8888:
> +	case DRM_FORMAT_BGRA8888:
> +		*depth = 32;
> +		*bpp = 32;
> +		break;
> +	default:
> +		DRM_DEBUG_KMS("unsupported pixel format %s\n",
> +			      drm_get_format_name(format));
> +		*depth = 0;
> +		*bpp = 0;
> +		break;
> +	}
> +}
> +EXPORT_SYMBOL(drm_fb_get_bpp_depth);
> +
> +/**
> + * drm_format_num_planes - get the number of planes for format
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The number of planes used by the specified pixel format.
> + */
> +int drm_format_num_planes(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV444:
> +	case DRM_FORMAT_YVU444:
> +		return 3;
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_NV24:
> +	case DRM_FORMAT_NV42:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_num_planes);
> +
> +/**
> + * drm_format_plane_cpp - determine the bytes per pixel value
> + * @format: pixel format (DRM_FORMAT_*)
> + * @plane: plane index
> + *
> + * Returns:
> + * The bytes per pixel value for the specified plane.
> + */
> +int drm_format_plane_cpp(uint32_t format, int plane)
> +{
> +	unsigned int depth;
> +	int bpp;
> +
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	switch (format) {
> +	case DRM_FORMAT_YUYV:
> +	case DRM_FORMAT_YVYU:
> +	case DRM_FORMAT_UYVY:
> +	case DRM_FORMAT_VYUY:
> +		return 2;
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_NV24:
> +	case DRM_FORMAT_NV42:
> +		return plane ? 2 : 1;
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV444:
> +	case DRM_FORMAT_YVU444:
> +		return 1;
> +	default:
> +		drm_fb_get_bpp_depth(format, &depth, &bpp);
> +		return bpp >> 3;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_plane_cpp);
> +
> +/**
> + * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The horizontal chroma subsampling factor for the
> + * specified pixel format.
> + */
> +int drm_format_horz_chroma_subsampling(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV411:
> +	case DRM_FORMAT_YVU411:
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +		return 4;
> +	case DRM_FORMAT_YUYV:
> +	case DRM_FORMAT_YVYU:
> +	case DRM_FORMAT_UYVY:
> +	case DRM_FORMAT_VYUY:
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +	case DRM_FORMAT_NV16:
> +	case DRM_FORMAT_NV61:
> +	case DRM_FORMAT_YUV422:
> +	case DRM_FORMAT_YVU422:
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_horz_chroma_subsampling);
> +
> +/**
> + * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor
> + * @format: pixel format (DRM_FORMAT_*)
> + *
> + * Returns:
> + * The vertical chroma subsampling factor for the
> + * specified pixel format.
> + */
> +int drm_format_vert_chroma_subsampling(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_YUV410:
> +	case DRM_FORMAT_YVU410:
> +		return 4;
> +	case DRM_FORMAT_YUV420:
> +	case DRM_FORMAT_YVU420:
> +	case DRM_FORMAT_NV12:
> +	case DRM_FORMAT_NV21:
> +		return 2;
> +	default:
> +		return 1;
> +	}
> +}
> +EXPORT_SYMBOL(drm_format_vert_chroma_subsampling);
> +
> +/**
> + * drm_format_plane_width - width of the plane given the first plane
> + * @width: width of the first plane
> + * @format: pixel format
> + * @plane: plane index
> + *
> + * Returns:
> + * The width of @plane, given that the width of the first plane is @width.
> + */
> +int drm_format_plane_width(int width, uint32_t format, int plane)
> +{
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	if (plane == 0)
> +		return width;
> +
> +	return width / drm_format_horz_chroma_subsampling(format);
> +}
> +EXPORT_SYMBOL(drm_format_plane_width);
> +
> +/**
> + * drm_format_plane_height - height of the plane given the first plane
> + * @height: height of the first plane
> + * @format: pixel format
> + * @plane: plane index
> + *
> + * Returns:
> + * The height of @plane, given that the height of the first plane is @height.
> + */
> +int drm_format_plane_height(int height, uint32_t format, int plane)
> +{
> +	if (plane >= drm_format_num_planes(format))
> +		return 0;
> +
> +	if (plane == 0)
> +		return height;
> +
> +	return height / drm_format_vert_chroma_subsampling(format);
> +}
> +EXPORT_SYMBOL(drm_format_plane_height);
> diff --git a/include/drm/drmP.h b/include/drm/drmP.h
> index 84f1a8eefbdb..c8879057084e 100644
> --- a/include/drm/drmP.h
> +++ b/include/drm/drmP.h
> @@ -66,6 +66,7 @@
>  
>  #include <drm/drm_agpsupport.h>
>  #include <drm/drm_crtc.h>
> +#include <drm/drm_fourcc.h>
>  #include <drm/drm_global.h>
>  #include <drm/drm_hashtab.h>
>  #include <drm/drm_mem_util.h>
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index d1559cd04e3d..1b80c0268d8f 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -2540,15 +2540,6 @@ extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
>  extern int drm_mode_atomic_ioctl(struct drm_device *dev,
>  				 void *data, struct drm_file *file_priv);
>  
> -extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
> -				 int *bpp);
> -extern int drm_format_num_planes(uint32_t format);
> -extern int drm_format_plane_cpp(uint32_t format, int plane);
> -extern int drm_format_horz_chroma_subsampling(uint32_t format);
> -extern int drm_format_vert_chroma_subsampling(uint32_t format);
> -extern int drm_format_plane_width(int width, uint32_t format, int plane);
> -extern int drm_format_plane_height(int height, uint32_t format, int plane);
> -extern const char *drm_get_format_name(uint32_t format);
>  extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
>  							      unsigned int supported_rotations);
>  extern unsigned int drm_rotation_simplify(unsigned int rotation,
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> new file mode 100644
> index 000000000000..7f90a396cf2b
> --- /dev/null
> +++ b/include/drm/drm_fourcc.h
> @@ -0,0 +1,37 @@
> +/*
> + * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart at ideasonboard.com>
> + *
> + * Permission to use, copy, modify, distribute, and sell this software and its
> + * documentation for any purpose is hereby granted without fee, provided that
> + * the above copyright notice appear in all copies and that both that copyright
> + * notice and this permission notice appear in supporting documentation, and
> + * that the name of the copyright holders not be used in advertising or
> + * publicity pertaining to distribution of the software without specific,
> + * written prior permission.  The copyright holders make no representations
> + * about the suitability of this software for any purpose.  It is provided "as
> + * is" without express or implied warranty.
> + *
> + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
> + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
> + * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
> + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
> + * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
> + * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
> + * OF THIS SOFTWARE.
> + */
> +#ifndef __DRM_FOURCC_H__
> +#define __DRM_FOURCC_H__
> +
> +#include <linux/types.h>
> +#include <uapi/drm/drm_fourcc.h>
> +
> +void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, int *bpp);
> +int drm_format_num_planes(uint32_t format);
> +int drm_format_plane_cpp(uint32_t format, int plane);
> +int drm_format_horz_chroma_subsampling(uint32_t format);
> +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);
> +
> +#endif /* __DRM_FOURCC_H__ */
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the dri-devel mailing list