![]() |
|
|||
0001 /* 0002 * Copyright (c) 2016 Laurent Pinchart <laurent.pinchart@ideasonboard.com> 0003 * 0004 * Permission to use, copy, modify, distribute, and sell this software and its 0005 * documentation for any purpose is hereby granted without fee, provided that 0006 * the above copyright notice appear in all copies and that both that copyright 0007 * notice and this permission notice appear in supporting documentation, and 0008 * that the name of the copyright holders not be used in advertising or 0009 * publicity pertaining to distribution of the software without specific, 0010 * written prior permission. The copyright holders make no representations 0011 * about the suitability of this software for any purpose. It is provided "as 0012 * is" without express or implied warranty. 0013 * 0014 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 0015 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 0016 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR 0017 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 0018 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 0019 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 0020 * OF THIS SOFTWARE. 0021 */ 0022 #ifndef __DRM_FOURCC_H__ 0023 #define __DRM_FOURCC_H__ 0024 0025 #include <linux/types.h> 0026 #include <uapi/drm/drm_fourcc.h> 0027 0028 /** 0029 * DRM_FORMAT_MAX_PLANES - maximum number of planes a DRM format can have 0030 */ 0031 #define DRM_FORMAT_MAX_PLANES 4u 0032 0033 /* 0034 * DRM formats are little endian. Define host endian variants for the 0035 * most common formats here, to reduce the #ifdefs needed in drivers. 0036 * 0037 * Note that the DRM_FORMAT_BIG_ENDIAN flag should only be used in 0038 * case the format can't be specified otherwise, so we don't end up 0039 * with two values describing the same format. 0040 */ 0041 #ifdef __BIG_ENDIAN 0042 # define DRM_FORMAT_HOST_XRGB1555 (DRM_FORMAT_XRGB1555 | \ 0043 DRM_FORMAT_BIG_ENDIAN) 0044 # define DRM_FORMAT_HOST_RGB565 (DRM_FORMAT_RGB565 | \ 0045 DRM_FORMAT_BIG_ENDIAN) 0046 # define DRM_FORMAT_HOST_XRGB8888 DRM_FORMAT_BGRX8888 0047 # define DRM_FORMAT_HOST_ARGB8888 DRM_FORMAT_BGRA8888 0048 #else 0049 # define DRM_FORMAT_HOST_XRGB1555 DRM_FORMAT_XRGB1555 0050 # define DRM_FORMAT_HOST_RGB565 DRM_FORMAT_RGB565 0051 # define DRM_FORMAT_HOST_XRGB8888 DRM_FORMAT_XRGB8888 0052 # define DRM_FORMAT_HOST_ARGB8888 DRM_FORMAT_ARGB8888 0053 #endif 0054 0055 struct drm_device; 0056 struct drm_mode_fb_cmd2; 0057 0058 /** 0059 * struct drm_format_info - information about a DRM format 0060 */ 0061 struct drm_format_info { 0062 /** @format: 4CC format identifier (DRM_FORMAT_*) */ 0063 u32 format; 0064 0065 /** 0066 * @depth: 0067 * 0068 * Color depth (number of bits per pixel excluding padding bits), 0069 * valid for a subset of RGB formats only. This is a legacy field, do 0070 * not use in new code and set to 0 for new formats. 0071 */ 0072 u8 depth; 0073 0074 /** @num_planes: Number of color planes (1 to 3) */ 0075 u8 num_planes; 0076 0077 union { 0078 /** 0079 * @cpp: 0080 * 0081 * Number of bytes per pixel (per plane), this is aliased with 0082 * @char_per_block. It is deprecated in favour of using the 0083 * triplet @char_per_block, @block_w, @block_h for better 0084 * describing the pixel format. 0085 */ 0086 u8 cpp[DRM_FORMAT_MAX_PLANES]; 0087 0088 /** 0089 * @char_per_block: 0090 * 0091 * Number of bytes per block (per plane), where blocks are 0092 * defined as a rectangle of pixels which are stored next to 0093 * each other in a byte aligned memory region. Together with 0094 * @block_w and @block_h this is used to properly describe tiles 0095 * in tiled formats or to describe groups of pixels in packed 0096 * formats for which the memory needed for a single pixel is not 0097 * byte aligned. 0098 * 0099 * @cpp has been kept for historical reasons because there are 0100 * a lot of places in drivers where it's used. In drm core for 0101 * generic code paths the preferred way is to use 0102 * @char_per_block, drm_format_info_block_width() and 0103 * drm_format_info_block_height() which allows handling both 0104 * block and non-block formats in the same way. 0105 * 0106 * For formats that are intended to be used only with non-linear 0107 * modifiers both @cpp and @char_per_block must be 0 in the 0108 * generic format table. Drivers could supply accurate 0109 * information from their drm_mode_config.get_format_info hook 0110 * if they want the core to be validating the pitch. 0111 */ 0112 u8 char_per_block[DRM_FORMAT_MAX_PLANES]; 0113 }; 0114 0115 /** 0116 * @block_w: 0117 * 0118 * Block width in pixels, this is intended to be accessed through 0119 * drm_format_info_block_width() 0120 */ 0121 u8 block_w[DRM_FORMAT_MAX_PLANES]; 0122 0123 /** 0124 * @block_h: 0125 * 0126 * Block height in pixels, this is intended to be accessed through 0127 * drm_format_info_block_height() 0128 */ 0129 u8 block_h[DRM_FORMAT_MAX_PLANES]; 0130 0131 /** @hsub: Horizontal chroma subsampling factor */ 0132 u8 hsub; 0133 /** @vsub: Vertical chroma subsampling factor */ 0134 u8 vsub; 0135 0136 /** @has_alpha: Does the format embeds an alpha component? */ 0137 bool has_alpha; 0138 0139 /** @is_yuv: Is it a YUV format? */ 0140 bool is_yuv; 0141 }; 0142 0143 /** 0144 * drm_format_info_is_yuv_packed - check that the format info matches a YUV 0145 * format with data laid in a single plane 0146 * @info: format info 0147 * 0148 * Returns: 0149 * A boolean indicating whether the format info matches a packed YUV format. 0150 */ 0151 static inline bool 0152 drm_format_info_is_yuv_packed(const struct drm_format_info *info) 0153 { 0154 return info->is_yuv && info->num_planes == 1; 0155 } 0156 0157 /** 0158 * drm_format_info_is_yuv_semiplanar - check that the format info matches a YUV 0159 * format with data laid in two planes (luminance and chrominance) 0160 * @info: format info 0161 * 0162 * Returns: 0163 * A boolean indicating whether the format info matches a semiplanar YUV format. 0164 */ 0165 static inline bool 0166 drm_format_info_is_yuv_semiplanar(const struct drm_format_info *info) 0167 { 0168 return info->is_yuv && info->num_planes == 2; 0169 } 0170 0171 /** 0172 * drm_format_info_is_yuv_planar - check that the format info matches a YUV 0173 * format with data laid in three planes (one for each YUV component) 0174 * @info: format info 0175 * 0176 * Returns: 0177 * A boolean indicating whether the format info matches a planar YUV format. 0178 */ 0179 static inline bool 0180 drm_format_info_is_yuv_planar(const struct drm_format_info *info) 0181 { 0182 return info->is_yuv && info->num_planes == 3; 0183 } 0184 0185 /** 0186 * drm_format_info_is_yuv_sampling_410 - check that the format info matches a 0187 * YUV format with 4:1:0 sub-sampling 0188 * @info: format info 0189 * 0190 * Returns: 0191 * A boolean indicating whether the format info matches a YUV format with 4:1:0 0192 * sub-sampling. 0193 */ 0194 static inline bool 0195 drm_format_info_is_yuv_sampling_410(const struct drm_format_info *info) 0196 { 0197 return info->is_yuv && info->hsub == 4 && info->vsub == 4; 0198 } 0199 0200 /** 0201 * drm_format_info_is_yuv_sampling_411 - check that the format info matches a 0202 * YUV format with 4:1:1 sub-sampling 0203 * @info: format info 0204 * 0205 * Returns: 0206 * A boolean indicating whether the format info matches a YUV format with 4:1:1 0207 * sub-sampling. 0208 */ 0209 static inline bool 0210 drm_format_info_is_yuv_sampling_411(const struct drm_format_info *info) 0211 { 0212 return info->is_yuv && info->hsub == 4 && info->vsub == 1; 0213 } 0214 0215 /** 0216 * drm_format_info_is_yuv_sampling_420 - check that the format info matches a 0217 * YUV format with 4:2:0 sub-sampling 0218 * @info: format info 0219 * 0220 * Returns: 0221 * A boolean indicating whether the format info matches a YUV format with 4:2:0 0222 * sub-sampling. 0223 */ 0224 static inline bool 0225 drm_format_info_is_yuv_sampling_420(const struct drm_format_info *info) 0226 { 0227 return info->is_yuv && info->hsub == 2 && info->vsub == 2; 0228 } 0229 0230 /** 0231 * drm_format_info_is_yuv_sampling_422 - check that the format info matches a 0232 * YUV format with 4:2:2 sub-sampling 0233 * @info: format info 0234 * 0235 * Returns: 0236 * A boolean indicating whether the format info matches a YUV format with 4:2:2 0237 * sub-sampling. 0238 */ 0239 static inline bool 0240 drm_format_info_is_yuv_sampling_422(const struct drm_format_info *info) 0241 { 0242 return info->is_yuv && info->hsub == 2 && info->vsub == 1; 0243 } 0244 0245 /** 0246 * drm_format_info_is_yuv_sampling_444 - check that the format info matches a 0247 * YUV format with 4:4:4 sub-sampling 0248 * @info: format info 0249 * 0250 * Returns: 0251 * A boolean indicating whether the format info matches a YUV format with 4:4:4 0252 * sub-sampling. 0253 */ 0254 static inline bool 0255 drm_format_info_is_yuv_sampling_444(const struct drm_format_info *info) 0256 { 0257 return info->is_yuv && info->hsub == 1 && info->vsub == 1; 0258 } 0259 0260 /** 0261 * drm_format_info_plane_width - width of the plane given the first plane 0262 * @info: pixel format info 0263 * @width: width of the first plane 0264 * @plane: plane index 0265 * 0266 * Returns: 0267 * The width of @plane, given that the width of the first plane is @width. 0268 */ 0269 static inline 0270 int drm_format_info_plane_width(const struct drm_format_info *info, int width, 0271 int plane) 0272 { 0273 if (!info || plane >= info->num_planes) 0274 return 0; 0275 0276 if (plane == 0) 0277 return width; 0278 0279 return width / info->hsub; 0280 } 0281 0282 /** 0283 * drm_format_info_plane_height - height of the plane given the first plane 0284 * @info: pixel format info 0285 * @height: height of the first plane 0286 * @plane: plane index 0287 * 0288 * Returns: 0289 * The height of @plane, given that the height of the first plane is @height. 0290 */ 0291 static inline 0292 int drm_format_info_plane_height(const struct drm_format_info *info, int height, 0293 int plane) 0294 { 0295 if (!info || plane >= info->num_planes) 0296 return 0; 0297 0298 if (plane == 0) 0299 return height; 0300 0301 return height / info->vsub; 0302 } 0303 0304 const struct drm_format_info *__drm_format_info(u32 format); 0305 const struct drm_format_info *drm_format_info(u32 format); 0306 const struct drm_format_info * 0307 drm_get_format_info(struct drm_device *dev, 0308 const struct drm_mode_fb_cmd2 *mode_cmd); 0309 uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); 0310 uint32_t drm_driver_legacy_fb_format(struct drm_device *dev, 0311 uint32_t bpp, uint32_t depth); 0312 unsigned int drm_format_info_block_width(const struct drm_format_info *info, 0313 int plane); 0314 unsigned int drm_format_info_block_height(const struct drm_format_info *info, 0315 int plane); 0316 uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, 0317 int plane, unsigned int buffer_width); 0318 0319 #endif /* __DRM_FOURCC_H__ */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |