^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Permission to use, copy, modify, distribute, and sell this software and its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * documentation for any purpose is hereby granted without fee, provided that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * the above copyright notice appear in all copies and that both that copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * notice and this permission notice appear in supporting documentation, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * that the name of the copyright holders not be used in advertising or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * publicity pertaining to distribution of the software without specific,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * written prior permission. The copyright holders make no representations
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * about the suitability of this software for any purpose. It is provided "as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * is" without express or implied warranty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * OF THIS SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #ifndef __DRM_FOURCC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define __DRM_FOURCC_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <uapi/drm/drm_fourcc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * DRM formats are little endian. Define host endian variants for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * most common formats here, to reduce the #ifdefs needed in drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * Note that the DRM_FORMAT_BIG_ENDIAN flag should only be used in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * case the format can't be specified otherwise, so we don't end up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * with two values describing the same format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #ifdef __BIG_ENDIAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) # define DRM_FORMAT_HOST_XRGB1555 (DRM_FORMAT_XRGB1555 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) DRM_FORMAT_BIG_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) # define DRM_FORMAT_HOST_RGB565 (DRM_FORMAT_RGB565 | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) DRM_FORMAT_BIG_ENDIAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) # define DRM_FORMAT_HOST_XRGB8888 DRM_FORMAT_BGRX8888
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) # define DRM_FORMAT_HOST_ARGB8888 DRM_FORMAT_BGRA8888
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) # define DRM_FORMAT_HOST_XRGB1555 DRM_FORMAT_XRGB1555
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) # define DRM_FORMAT_HOST_RGB565 DRM_FORMAT_RGB565
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) # define DRM_FORMAT_HOST_XRGB8888 DRM_FORMAT_XRGB8888
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) # define DRM_FORMAT_HOST_ARGB8888 DRM_FORMAT_ARGB8888
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct drm_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct drm_mode_fb_cmd2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * struct drm_format_info - information about a DRM format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct drm_format_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /** @format: 4CC format identifier (DRM_FORMAT_*) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) u32 format;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * @depth:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Color depth (number of bits per pixel excluding padding bits),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * valid for a subset of RGB formats only. This is a legacy field, do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * not use in new code and set to 0 for new formats.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u8 depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /** @num_planes: Number of color planes (1 to 3) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 num_planes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @cpp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Number of bytes per pixel (per plane), this is aliased with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * @char_per_block. It is deprecated in favour of using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * triplet @char_per_block, @block_w, @block_h for better
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * describing the pixel format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u8 cpp[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * @char_per_block:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Number of bytes per block (per plane), where blocks are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * defined as a rectangle of pixels which are stored next to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * each other in a byte aligned memory region. Together with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * @block_w and @block_h this is used to properly describe tiles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * in tiled formats or to describe groups of pixels in packed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * formats for which the memory needed for a single pixel is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * byte aligned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * @cpp has been kept for historical reasons because there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * a lot of places in drivers where it's used. In drm core for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * generic code paths the preferred way is to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * @char_per_block, drm_format_info_block_width() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * drm_format_info_block_height() which allows handling both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * block and non-block formats in the same way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * For formats that are intended to be used only with non-linear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * modifiers both @cpp and @char_per_block must be 0 in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * generic format table. Drivers could supply accurate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * information from their drm_mode_config.get_format_info hook
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * if they want the core to be validating the pitch.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) u8 char_per_block[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * @block_w:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * Block width in pixels, this is intended to be accessed through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * drm_format_info_block_width()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) u8 block_w[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * @block_h:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * Block height in pixels, this is intended to be accessed through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * drm_format_info_block_height()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) u8 block_h[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /** @hsub: Horizontal chroma subsampling factor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) u8 hsub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /** @vsub: Vertical chroma subsampling factor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u8 vsub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /** @has_alpha: Does the format embeds an alpha component? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) bool has_alpha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /** @is_yuv: Is it a YUV format? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) bool is_yuv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * struct drm_format_name_buf - name of a DRM format
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * @str: string buffer containing the format name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct drm_format_name_buf {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) char str[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * drm_format_info_is_yuv_packed - check that the format info matches a YUV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * format with data laid in a single plane
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * A boolean indicating whether the format info matches a packed YUV format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) drm_format_info_is_yuv_packed(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return info->is_yuv && info->num_planes == 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * drm_format_info_is_yuv_semiplanar - check that the format info matches a YUV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * format with data laid in two planes (luminance and chrominance)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * A boolean indicating whether the format info matches a semiplanar YUV format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) drm_format_info_is_yuv_semiplanar(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return info->is_yuv && info->num_planes == 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * drm_format_info_is_yuv_planar - check that the format info matches a YUV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * format with data laid in three planes (one for each YUV component)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * A boolean indicating whether the format info matches a planar YUV format.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) drm_format_info_is_yuv_planar(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return info->is_yuv && info->num_planes == 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * drm_format_info_is_yuv_sampling_410 - check that the format info matches a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * YUV format with 4:1:0 sub-sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * A boolean indicating whether the format info matches a YUV format with 4:1:0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * sub-sampling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) drm_format_info_is_yuv_sampling_410(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) return info->is_yuv && info->hsub == 4 && info->vsub == 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * drm_format_info_is_yuv_sampling_411 - check that the format info matches a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * YUV format with 4:1:1 sub-sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * A boolean indicating whether the format info matches a YUV format with 4:1:1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * sub-sampling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) drm_format_info_is_yuv_sampling_411(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) return info->is_yuv && info->hsub == 4 && info->vsub == 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * drm_format_info_is_yuv_sampling_420 - check that the format info matches a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * YUV format with 4:2:0 sub-sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * A boolean indicating whether the format info matches a YUV format with 4:2:0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * sub-sampling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) drm_format_info_is_yuv_sampling_420(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return info->is_yuv && info->hsub == 2 && info->vsub == 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * drm_format_info_is_yuv_sampling_422 - check that the format info matches a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * YUV format with 4:2:2 sub-sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * A boolean indicating whether the format info matches a YUV format with 4:2:2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * sub-sampling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) drm_format_info_is_yuv_sampling_422(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return info->is_yuv && info->hsub == 2 && info->vsub == 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * drm_format_info_is_yuv_sampling_444 - check that the format info matches a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * YUV format with 4:4:4 sub-sampling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * @info: format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * A boolean indicating whether the format info matches a YUV format with 4:4:4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * sub-sampling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) drm_format_info_is_yuv_sampling_444(const struct drm_format_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return info->is_yuv && info->hsub == 1 && info->vsub == 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * drm_format_info_plane_width - width of the plane given the first plane
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * @info: pixel format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * @width: width of the first plane
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * @plane: plane index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * The width of @plane, given that the width of the first plane is @width.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int drm_format_info_plane_width(const struct drm_format_info *info, int width,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int plane)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (!info || plane >= info->num_planes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (plane == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return width / info->hsub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * drm_format_info_plane_height - height of the plane given the first plane
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * @info: pixel format info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) * @height: height of the first plane
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * @plane: plane index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * The height of @plane, given that the height of the first plane is @height.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int drm_format_info_plane_height(const struct drm_format_info *info, int height,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int plane)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (!info || plane >= info->num_planes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (plane == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) return height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return height / info->vsub;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) const struct drm_format_info *__drm_format_info(u32 format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) const struct drm_format_info *drm_format_info(u32 format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) const struct drm_format_info *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) drm_get_format_info(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) const struct drm_mode_fb_cmd2 *mode_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) uint32_t drm_driver_legacy_fb_format(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) uint32_t bpp, uint32_t depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) unsigned int drm_format_info_block_width(const struct drm_format_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int plane);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) unsigned int drm_format_info_block_height(const struct drm_format_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int plane);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int plane, unsigned int buffer_width);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #endif /* __DRM_FOURCC_H__ */