1 /* 2 * Copyright (c) 2009-2022, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file vphal_common.h 24 //! \brief clarify common utilities for vphal 25 //! \details clarify common utilities for vphal including: 26 //! some marcro, enum, union, structure, function 27 //! 28 #ifndef __VPHAL_COMMON_H__ 29 #define __VPHAL_COMMON_H__ 30 31 #if EMUL || VPHAL_LIB 32 33 #include "support.h" 34 35 #endif // EMUL || VPHAL_LIB 36 37 #include "mos_os.h" 38 #include "vp_common_hdr.h" 39 #include "media_common_defs.h" 40 #include "vp_common.h" 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 //! 47 //! \def DBG_TEXT(txt) 48 //! Allow certain \a txt fields to be present only on DEBUG builds. 49 //! 50 #if _DEBUG 51 #define DBG_TEXT(txt) txt 52 #else 53 #define DBG_TEXT(txt) "" 54 #endif 55 56 #ifndef ABS 57 //! 58 //! \def ABS( x ) 59 //! Calcualte absolute value of \a x. 60 //! 61 #define ABS(a) (((a) < 0) ? (-(a)) : (a)) 62 #endif 63 64 //! 65 //! \def VPHAL_ABS(x) 66 //! Calcualte the Abslute value of \a x. 67 //! 68 #define VPHAL_ABS(x) (((x) > 0) ? (x) : -(x)) 69 70 #define VPHAL_PI 3.14159265358979324f //!< Definition the const pi 71 72 //! 73 //! \def RECT1_EQUALS_RECT2(rect1, rect2) 74 //! Compare if two rectangles has the same coordinate 75 //! 76 #define RECT1_EQUALS_RECT2(rect1, rect2) \ 77 (((rect1).left == (rect2).left) && ((rect1).top == (rect2).top) && \ 78 ((rect1).right == (rect2).right) && ((rect1).bottom == (rect2).bottom)) 79 80 //! 81 //! \def RECT1_OUTSIDE_RECT2(rect1, rect2) 82 //! Compare if the rectangle \a rect1 is outside the rectangle \a rect2 at least partly in coordinate 83 //! 84 #define RECT1_OUTSIDE_RECT2(rect1, rect2) \ 85 (((rect1).left >= (rect2).right) || ((rect1).top >= (rect2).bottom) || \ 86 ((rect1).right <= (rect2).left) || ((rect1).bottom <= (rect2).top)) 87 88 //! 89 // \def DEGREE_TO_RADIAN(degree) 90 // Convert a degree value \a degree to radian. 91 //! 92 #define DEGREE_TO_RADIAN(degree) (degree) * (VPHAL_PI) / 180 93 #define AVS_TBL_COEF_PREC 6 //!< Table coef precision (after decimal point 94 #define SAME_SAMPLE_THRESHOLD 1000 //!< When checking whether 2 timestamps are the same, leave room for some error 95 96 // Compositing Block size 97 #define VPHAL_COMP_BLOCK_WIDTH 16 98 #define VPHAL_COMP_BLOCK_HEIGHT 16 99 100 // NLAS Default Values 101 #define NLAS_VERTICALCROP_MIN 0.0F 102 #define NLAS_VERTICALCROP_MAX 1.0F 103 #define NLAS_VERTICALCROP_DEFAULT 0.0F 104 #define NLAS_VERTICALCROP_STEP 0.001F 105 #define NLAS_HLINEARREGION_MIN 0.0F 106 #define NLAS_HLINEARREGION_MAX 1.0F 107 #define NLAS_HLINEARREGION_DEFAULT 1.0F 108 #define NLAS_HLINEARREGION_STEP 0.001F 109 #define NLAS_NONLINEARCROP_MIN 0.0F 110 #define NLAS_NONLINEARCROP_MAX 1.0F 111 #define NLAS_NONLINEARCROP_DEFAULT 0.0F 112 #define NLAS_NONLINEARCROP_STEP 0.001F 113 114 #define VPHAL_MAX_CHANNELS 2 115 #define VPHAL_MAX_FUTURE_FRAMES 18 //!< maximum future frames supported in VPHAL 116 117 typedef enum _VPHAL_DP_ROTATION_MODE 118 { 119 VPHAL_DP_ROTATION_NV12_AVG = 0, //!< nv12 -> yuy2 by chroma average 120 VPHAL_DP_ROTATION_NV12_NV12 , //!< nv12 -> nv12 121 VPHAL_DP_ROTATION_NV12_REP , //!< nv12 -> yuy2 by chroma repeat 122 VPHAL_DP_ROTATION_NV12_YUY2_NOT_SET //!< nv12 -> yuy2 by chroma average or repeat, decided by scaling mode 123 } VPHAL_DP_ROTATION_MODE; 124 125 //! 126 //! \def IS_RGB_LIMITED_RANGE(_a) 127 //! Check if RGB limited range 128 //! 129 #define IS_RGB_LIMITED_RANGE(_a) (_a == CSpace_stRGB || \ 130 _a == CSpace_BT2020_stRGB) 131 132 //! 133 //! \def IS_RGB_FULL_RANGE(_a) 134 //! Check if RGB full range 135 //! 136 #define IS_RGB_FULL_RANGE(_a) (_a == CSpace_sRGB || \ 137 _a == CSpace_BT2020_sRGB) 138 139 //! 140 //! \def IS_YUV_LIMITED_RANGE(_a) 141 //! Check if YUV limited range 142 //! 143 #define IS_YUV_LIMITED_RANGE(_a) (_a == CSpace_BT601 || \ 144 _a == CSpace_BT709 || \ 145 _a == CSpace_BT601Gray || \ 146 _a == CSpace_BT2020) 147 148 //! 149 //! \def SET_VPHAL_OUTPUT_PIPE(_a, _Pipe) 150 //! Set the output pipe 151 //! 152 #define SET_VPHAL_OUTPUT_PIPE(_a, _Pipe) \ 153 { \ 154 (_a->OutputPipe = _Pipe); \ 155 VPHAL_RENDER_NORMALMESSAGE("VPHAL_OUTPUT_PIPE %d", _Pipe); \ 156 } 157 158 //! 159 //! \def IS_VPHAL_OUTPUT_PIPE_INVALID(_a) 160 //! Sheck if the output pipe is invalid 161 //! 162 #define IS_VPHAL_OUTPUT_PIPE_INVALID(_a) (_a->OutputPipe == VPHAL_OUTPUT_PIPE_MODE_INVALID) 163 164 //! 165 //! \def IS_VPHAL_OUTPUT_PIPE_COMP(_a) 166 //! Check if the output pipe is Composition 167 //! 168 #define IS_VPHAL_OUTPUT_PIPE_COMP(_a) (_a->OutputPipe == VPHAL_OUTPUT_PIPE_MODE_COMP) 169 170 //! 171 //! \def IS_VPHAL_OUTPUT_PIPE_SFC(_a) 172 //! Check if the output pipe is SFC 173 //! 174 #define IS_VPHAL_OUTPUT_PIPE_SFC(_a) (_a->OutputPipe == VPHAL_OUTPUT_PIPE_MODE_SFC) 175 176 //! 177 //! \def IS_VPHAL_OUTPUT_PIPE_VEBOX(_a) 178 //! Check if the output pipe is Vebox 179 //! 180 #define IS_VPHAL_OUTPUT_PIPE_VEBOX(_a) (_a->OutputPipe == VPHAL_OUTPUT_PIPE_MODE_VEBOX) 181 182 //! 183 //! \def SET_VPHAL_COMPONENT(_a, _Component) 184 //! Set the Component 185 //! 186 #define SET_VPHAL_COMPONENT(_a, _Component) (_a->Component = _Component) // Set the Component 187 188 //! 189 //! \def SET_VPHAL_MMC_STATE(_a, _bEnableMMC) 190 //! Set the Component 191 //! 192 #define SET_VPHAL_MMC_STATE(_a, _bEnableMMC) (_a->bEnableMMC = _bEnableMMC) // Set the Component 193 194 //! 195 //! \brief Vphal 3DLUT Channel Mapping enum 196 //! 197 typedef enum _VPHAL_3DLUT_CHANNEL_MAPPING 198 { 199 CHANNEL_MAPPING_RGB_RGB = 0, 200 CHANNEL_MAPPING_YUV_RGB = 1 << 0, 201 CHANNEL_MAPPING_VUY_RGB = 1 << 1, 202 } VPHAL_3DLUT_CHANNEL_MAPPING; 203 204 //! 205 //! Structure VPHAL_CONSTRICTION_PARAMS 206 //! \brief Constriction parameters 207 //! 208 typedef struct _VPHAL_CONSTRICTION_PARAMS 209 { 210 RECT rcConstriction; 211 } VPHAL_CONSTRICTION_PARAMS, *PVPHAL_CONSTRICTION_PARAMS; 212 213 //! 214 //! \brief sinc 215 //! \details Calculate sinc(x) 216 //! \param [in] x 217 //! float 218 //! \return float 219 //! sinc(x) 220 //! 221 float VpHal_Sinc(float x); 222 223 //! 224 //! \brief Lanczos 225 //! \details Calculate lanczos(x) 226 //! Basic formula is: lanczos(x)= VpHal_Sinc(x) * VpHal_Sinc(x / fLanczosT) 227 //! \param [in] x 228 //! float 229 //! \param [in] dwNumEntries 230 //! dword 231 //! \param [in] fLanczosT 232 //! 233 //! \return float 234 //! lanczos(x) 235 //! 236 float VpHal_Lanczos( 237 float x, 238 uint32_t dwNumEntries, 239 float fLanczosT); 240 241 //! 242 //! \brief Allocates the Surface 243 //! \details Allocates the Surface 244 //! - if the surface is not already allocated OR 245 //! - resource dimenisions OR format changed 246 //! \param [in] pOsInterface 247 //! Pointer to MOS_INTERFACE 248 //! \param [in,out] pSurface 249 //! Pointer to VPHAL_SURFACE 250 //! \param [in] pSurfaceName 251 //! Pointer to surface name 252 //! \param [in] Format 253 //! Expected MOS_FORMAT 254 //! \param [in] DefaultResType 255 //! Expected Resource Type 256 //! \param [in] DefaultTileType 257 //! Expected Surface Tile Type 258 //! \param [in] dwWidth 259 //! Expected Surface Width 260 //! \param [in] dwHeight 261 //! Expected Surface Height 262 //! \param [in] bCompressible 263 //! Surface being compressible or not 264 //! \param [in] CompressionMode 265 //! Compression Mode 266 //! \param [out] pbAllocated 267 //! true if allocated, false for not 268 //! \param [in] resUsageType 269 //! resource usage type for caching 270 //! \param [in] tileModeByForce 271 //! Forced tile mode 272 //! \param [in] memType 273 //! vidoe memory location 274 //! \return MOS_STATUS 275 //! MOS_STATUS_SUCCESS if success. Error code otherwise 276 //! 277 MOS_STATUS VpHal_ReAllocateSurface( 278 PMOS_INTERFACE pOsInterface, // [in] Pointer to OS Interface 279 PVPHAL_SURFACE pSurface, // [in/out]Pointer to surface 280 PCCHAR pSurfaceName, // [in] Pointer to surface name 281 MOS_FORMAT Format, // [in] Surface Format 282 MOS_GFXRES_TYPE DefaultResType, // [in] Default Resource Type to use if resource has not be allocated yet 283 MOS_TILE_TYPE DefaultTileType, // [in] Default Resource Tile Type to use if resource has not be allocated yet 284 uint32_t dwWidth, // [in] Resource Width 285 uint32_t dwHeight, // [in] Resource Height 286 bool bCompressible, // [in] Flag indaicated reource is compressible or not 287 MOS_RESOURCE_MMC_MODE CompressionMode, // [in] Compression mode 288 bool* pbAllocated, // [out] Flag indicating new allocation 289 MOS_HW_RESOURCE_DEF resUsageType = MOS_HW_RESOURCE_DEF_MAX, // [in] resource usage type 290 MOS_TILE_MODE_GMM tileModeByForce = MOS_TILE_UNSET_GMM, // [in] Flag to indicate if GMM flag tile64 need set 291 Mos_MemPool memType = MOS_MEMPOOL_VIDEOMEMORY, // [in] Flag to indicate the memType 292 bool isNotLockable = false); // [in] Flag to indicate whether resource being not lockable 293 294 //! 295 //! \brief Reads the Surface contents and copy to the Dst Buffer 296 //! \details Reads the Surface contents and copy to the Dst Buffer 297 //! - 1 lock surface 298 //! - 2 copy surface data to pDst 299 //! - 3 unlock surface 300 //! \param [in] pOsInterface 301 //! Pointer to MOS_INTERFACE 302 //! \param [in] pSurface 303 //! Pointer to VPHAL_SURFACE 304 //! \param [in] uBpp 305 //! bit per pixel of surface contents 306 //! \param [out] pDst 307 //! output buffer to store Surface contents 308 //! \return MOS_STATUS 309 //! MOS_STATUS_SUCCESS if success. Error code otherwise 310 //! 311 MOS_STATUS VpHal_ReadSurface ( 312 PMOS_INTERFACE pOsInterface, 313 PVPHAL_SURFACE pSurface, 314 uint32_t uBpp, 315 uint8_t* pDst); 316 317 //! 318 //! \brief Copy Data from input Buffer to the Surface contents 319 //! \details Copy Data from input Buffer to the Surface contents 320 //! - 1 lock surface 321 //! - 2 copy data from pSrc to Surface 322 //! - 3 unlock surface 323 //! \param [in] pOsInterface 324 //! Pointer to MOS_INTERFACE 325 //! \param [out] pSurface 326 //! Pointer to VPHAL_SURFACE 327 //! \param [in] uBpp 328 //! bit per pixel of input buffer 329 //! \param [in] pSrc 330 //! Input buffer to store Surface contents 331 //! \return MOS_STATUS 332 //! MOS_STATUS_SUCCESS if success. Error code otherwise 333 //! 334 MOS_STATUS VpHal_WriteSurface ( 335 PMOS_INTERFACE pOsInterface, 336 PVPHAL_SURFACE pSurface, 337 uint32_t uBpp, 338 const uint8_t* pSrc); 339 340 //! 341 //! \brief Decide whether Chroma up sampling is needed 342 //! \param [in] pSource 343 //! Pointer to Source Surface 344 //! \param [in] pTarget 345 //! Pointer to Target Surface 346 //! \return bool 347 //! Return true if Chroma up sampling is needed, otherwise false 348 //! 349 bool VpHal_IsChromaUpSamplingNeeded( 350 PVPHAL_SURFACE pSource, 351 PVPHAL_SURFACE pTarget); 352 353 //! 354 //! \brief Decide whether Chroma down sampling is needed 355 //! \param [in] pSource 356 //! Pointer to Source Surface 357 //! \param [in] pTarget 358 //! Pointer to Target Surface 359 //! \return bool 360 //! Return true if Chroma down sampling is needed, otherwise false 361 //! 362 bool VpHal_IsChromaDownSamplingNeeded( 363 PVPHAL_SURFACE pSource, 364 PVPHAL_SURFACE pTarget); 365 366 //! 367 //! \brief Get the scale ratio 368 //! \details Get the scale ratio from input surface to output surface 369 //! \param [in] pSource 370 //! Pointer to input Surface 371 //! \param [in] pTarget 372 //! Pointer to output Surface 373 //! \param [out] pfScaleX 374 //! Pointer to scaling ratio x 375 //! \param [out] pfScaleY 376 //! Pointer to scaling ratio y 377 //! \return void 378 //! 379 void VpHal_GetScalingRatio( 380 PVPHAL_SURFACE pSource, 381 PVPHAL_SURFACE pTarget, 382 float* pfScaleX, 383 float* pfScaleY); 384 385 //! \brief Transfer float type to half precision float type 386 //! \details Transfer float type to half precision float (16bit) type 387 //! \param [in] fInput 388 //! input FP32 number 389 //! \return uint16_t 390 //! half precision float value in bit 391 //! 392 uint16_t VpHal_FloatToHalfFloatA( 393 float fInputA); 394 395 bool IsSyncFreeNeededForMMCSurface(PVPHAL_SURFACE pSurface, PMOS_INTERFACE pOsInterface); 396 397 #ifdef __cplusplus 398 } 399 #endif 400 401 #endif // __VPHAL_COMMON_H__ 402