query.c revision 36cd50152c76d5a5b34202887af68aab09854d5d
1/************************************************************************** 2 * 3 * Copyright 2010 Younes Manton. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#include <assert.h> 29#include <math.h> 30 31#include "vdpau_private.h" 32#include "vl_winsys.h" 33#include "pipe/p_screen.h" 34#include "pipe/p_defines.h" 35#include "util/u_debug.h" 36 37/** 38 * Retrieve the VDPAU version implemented by the backend. 39 */ 40VdpStatus 41vlVdpGetApiVersion(uint32_t *api_version) 42{ 43 if (!api_version) 44 return VDP_STATUS_INVALID_POINTER; 45 46 *api_version = 1; 47 return VDP_STATUS_OK; 48} 49 50/** 51 * Retrieve an implementation-specific string description of the implementation. 52 * This typically includes detailed version information. 53 */ 54VdpStatus 55vlVdpGetInformationString(char const **information_string) 56{ 57 if (!information_string) 58 return VDP_STATUS_INVALID_POINTER; 59 60 *information_string = INFORMATION_STRING; 61 return VDP_STATUS_OK; 62} 63 64/** 65 * Query the implementation's VdpVideoSurface capabilities. 66 */ 67VdpStatus 68vlVdpVideoSurfaceQueryCapabilities(VdpDevice device, VdpChromaType surface_chroma_type, 69 VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height) 70{ 71 vlVdpDevice *dev; 72 struct pipe_screen *pscreen; 73 uint32_t max_2d_texture_level; 74 75 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpVideoSurface capabilities\n"); 76 77 if (!(is_supported && max_width && max_height)) 78 return VDP_STATUS_INVALID_POINTER; 79 80 dev = vlGetDataHTAB(device); 81 if (!dev) 82 return VDP_STATUS_INVALID_HANDLE; 83 84 pscreen = dev->vscreen->pscreen; 85 if (!pscreen) 86 return VDP_STATUS_RESOURCES; 87 88 /* XXX: Current limits */ 89 *is_supported = true; 90 if (surface_chroma_type != VDP_CHROMA_TYPE_420) 91 *is_supported = false; 92 93 max_2d_texture_level = pscreen->get_param(pscreen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); 94 if (!max_2d_texture_level) 95 return VDP_STATUS_RESOURCES; 96 97 /* I am not quite sure if it is max_2d_texture_level-1 or just max_2d_texture_level */ 98 *max_width = *max_height = pow(2,max_2d_texture_level-1); 99 100 return VDP_STATUS_OK; 101} 102 103/** 104 * Query the implementation's VdpVideoSurface GetBits/PutBits capabilities. 105 */ 106VdpStatus 107vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device, VdpChromaType surface_chroma_type, 108 VdpYCbCrFormat bits_ycbcr_format, 109 VdpBool *is_supported) 110{ 111 vlVdpDevice *dev; 112 struct pipe_screen *pscreen; 113 114 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpVideoSurface get/put bits YCbCr capabilities\n"); 115 116 if (!is_supported) 117 return VDP_STATUS_INVALID_POINTER; 118 119 dev = vlGetDataHTAB(device); 120 if (!dev) 121 return VDP_STATUS_INVALID_HANDLE; 122 123 pscreen = dev->vscreen->pscreen; 124 if (!pscreen) 125 return VDP_STATUS_RESOURCES; 126 127 *is_supported = pscreen->is_video_format_supported 128 ( 129 pscreen, 130 FormatYCBCRToPipe(bits_ycbcr_format), 131 PIPE_VIDEO_PROFILE_UNKNOWN 132 ); 133 134 return VDP_STATUS_OK; 135} 136 137/** 138 * Query the implementation's VdpDecoder capabilities. 139 */ 140VdpStatus 141vlVdpDecoderQueryCapabilities(VdpDevice device, VdpDecoderProfile profile, 142 VdpBool *is_supported, uint32_t *max_level, uint32_t *max_macroblocks, 143 uint32_t *max_width, uint32_t *max_height) 144{ 145 vlVdpDevice *dev; 146 struct pipe_screen *pscreen; 147 enum pipe_video_profile p_profile; 148 149 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpDecoder capabilities\n"); 150 151 if (!(is_supported && max_level && max_macroblocks && max_width && max_height)) 152 return VDP_STATUS_INVALID_POINTER; 153 154 dev = vlGetDataHTAB(device); 155 if (!dev) 156 return VDP_STATUS_INVALID_HANDLE; 157 158 pscreen = dev->vscreen->pscreen; 159 if (!pscreen) 160 return VDP_STATUS_RESOURCES; 161 162 p_profile = ProfileToPipe(profile); 163 if (p_profile == PIPE_VIDEO_PROFILE_UNKNOWN) { 164 *is_supported = false; 165 return VDP_STATUS_OK; 166 } 167 168 *is_supported = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_CAP_SUPPORTED); 169 if (*is_supported) { 170 *max_width = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_CAP_MAX_WIDTH); 171 *max_height = pscreen->get_video_param(pscreen, p_profile, PIPE_VIDEO_CAP_MAX_HEIGHT); 172 *max_level = 16; 173 *max_macroblocks = (*max_width/16)*(*max_height/16); 174 } else { 175 *max_width = 0; 176 *max_height = 0; 177 *max_level = 0; 178 *max_macroblocks = 0; 179 } 180 181 return VDP_STATUS_OK; 182} 183 184/** 185 * Query the implementation's VdpOutputSurface capabilities. 186 */ 187VdpStatus 188vlVdpOutputSurfaceQueryCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format, 189 VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height) 190{ 191 vlVdpDevice *dev; 192 struct pipe_screen *pscreen; 193 enum pipe_format format; 194 195 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpOutputSurface capabilities\n"); 196 197 dev = vlGetDataHTAB(device); 198 if (!dev) 199 return VDP_STATUS_INVALID_HANDLE; 200 201 pscreen = dev->vscreen->pscreen; 202 if (!pscreen) 203 return VDP_STATUS_RESOURCES; 204 205 format = FormatRGBAToPipe(surface_rgba_format); 206 if (format == PIPE_FORMAT_NONE || format == PIPE_FORMAT_A8_UNORM) 207 return VDP_STATUS_INVALID_RGBA_FORMAT; 208 209 if (!(is_supported && max_width && max_height)) 210 return VDP_STATUS_INVALID_POINTER; 211 212 *is_supported = pscreen->is_format_supported 213 ( 214 pscreen, format, PIPE_TEXTURE_3D, 1, 215 PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET 216 ); 217 if (*is_supported) { 218 uint32_t max_2d_texture_level = pscreen->get_param( 219 pscreen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS); 220 221 if (!max_2d_texture_level) 222 return VDP_STATUS_ERROR; 223 224 *max_width = *max_height = pow(2, max_2d_texture_level - 1); 225 } else { 226 *max_width = 0; 227 *max_height = 0; 228 } 229 230 return VDP_STATUS_OK; 231} 232 233/** 234 * Query the implementation's capability to perform a PutBits operation using 235 * application data matching the surface's format. 236 */ 237VdpStatus 238vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format, 239 VdpBool *is_supported) 240{ 241 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpOutputSurface get/put bits native capabilities\n"); 242 243 if (!is_supported) 244 return VDP_STATUS_INVALID_POINTER; 245 246 return VDP_STATUS_NO_IMPLEMENTATION; 247} 248 249/** 250 * Query the implementation's capability to perform a PutBits operation using 251 * application data in a specific indexed format. 252 */ 253VdpStatus 254vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device, 255 VdpRGBAFormat surface_rgba_format, 256 VdpIndexedFormat bits_indexed_format, 257 VdpColorTableFormat color_table_format, 258 VdpBool *is_supported) 259{ 260 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpOutputSurface put bits indexed capabilities\n"); 261 262 if (!is_supported) 263 return VDP_STATUS_INVALID_POINTER; 264 265 return VDP_STATUS_NO_IMPLEMENTATION; 266} 267 268/** 269 * Query the implementation's capability to perform a PutBits operation using 270 * application data in a specific YCbCr/YUB format. 271 */ 272VdpStatus 273vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format, 274 VdpYCbCrFormat bits_ycbcr_format, 275 VdpBool *is_supported) 276{ 277 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpOutputSurface put bits YCbCr capabilities\n"); 278 279 if (!is_supported) 280 return VDP_STATUS_INVALID_POINTER; 281 282 return VDP_STATUS_NO_IMPLEMENTATION; 283} 284 285/** 286 * Query the implementation's VdpBitmapSurface capabilities. 287 */ 288VdpStatus 289vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device, VdpRGBAFormat surface_rgba_format, 290 VdpBool *is_supported, uint32_t *max_width, uint32_t *max_height) 291{ 292 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Querying VdpBitmapSurface capabilities\n"); 293 294 if (!(is_supported && max_width && max_height)) 295 return VDP_STATUS_INVALID_POINTER; 296 297 return VDP_STATUS_NO_IMPLEMENTATION; 298} 299 300/** 301 * Query the implementation's support for a specific feature. 302 */ 303VdpStatus 304vlVdpVideoMixerQueryFeatureSupport(VdpDevice device, VdpVideoMixerFeature feature, 305 VdpBool *is_supported) 306{ 307 if (!is_supported) 308 return VDP_STATUS_INVALID_POINTER; 309 310 switch (feature) { 311 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS: 312 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION: 313 *is_supported = VDP_TRUE; 314 break; 315 default: 316 *is_supported = VDP_FALSE; 317 break; 318 } 319 return VDP_STATUS_OK; 320} 321 322/** 323 * Query the implementation's support for a specific parameter. 324 */ 325VdpStatus 326vlVdpVideoMixerQueryParameterSupport(VdpDevice device, VdpVideoMixerParameter parameter, 327 VdpBool *is_supported) 328{ 329 if (!is_supported) 330 return VDP_STATUS_INVALID_POINTER; 331 332 switch (parameter) { 333 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH: 334 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT: 335 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE: 336 case VDP_VIDEO_MIXER_PARAMETER_LAYERS: 337 *is_supported = VDP_TRUE; 338 break; 339 default: 340 *is_supported = VDP_FALSE; 341 break; 342 } 343 return VDP_STATUS_OK; 344} 345 346/** 347 * Query the implementation's supported for a specific parameter. 348 */ 349VdpStatus 350vlVdpVideoMixerQueryParameterValueRange(VdpDevice device, VdpVideoMixerParameter parameter, 351 void *min_value, void *max_value) 352{ 353 vlVdpDevice *dev = vlGetDataHTAB(device); 354 struct pipe_screen *screen; 355 enum pipe_video_profile prof = PIPE_VIDEO_PROFILE_UNKNOWN; 356 if (!dev) 357 return VDP_STATUS_INVALID_HANDLE; 358 if (!(min_value && max_value)) 359 return VDP_STATUS_INVALID_POINTER; 360 screen = dev->vscreen->pscreen; 361 switch (parameter) { 362 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH: 363 *(uint32_t*)min_value = 48; 364 *(uint32_t*)max_value = screen->get_video_param(screen, prof, PIPE_VIDEO_CAP_MAX_WIDTH); 365 break; 366 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT: 367 *(uint32_t*)min_value = 48; 368 *(uint32_t*)max_value = screen->get_video_param(screen, prof, PIPE_VIDEO_CAP_MAX_HEIGHT); 369 break; 370 371 case VDP_VIDEO_MIXER_PARAMETER_LAYERS: 372 *(uint32_t*)min_value = 0; 373 *(uint32_t*)max_value = 4; 374 break; 375 376 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE: 377 default: 378 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER; 379 } 380 return VDP_STATUS_OK; 381} 382 383/** 384 * Query the implementation's support for a specific attribute. 385 */ 386VdpStatus 387vlVdpVideoMixerQueryAttributeSupport(VdpDevice device, VdpVideoMixerAttribute attribute, 388 VdpBool *is_supported) 389{ 390 if (!is_supported) 391 return VDP_STATUS_INVALID_POINTER; 392 393 switch (attribute) { 394 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR: 395 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX: 396 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL: 397 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL: 398 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA: 399 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA: 400 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE: 401 *is_supported = VDP_TRUE; 402 break; 403 default: 404 *is_supported = VDP_FALSE; 405 } 406 return VDP_STATUS_OK; 407} 408 409/** 410 * Query the implementation's supported for a specific attribute. 411 */ 412VdpStatus 413vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device, VdpVideoMixerAttribute attribute, 414 void *min_value, void *max_value) 415{ 416 if (!(min_value && max_value)) 417 return VDP_STATUS_INVALID_POINTER; 418 419 switch (attribute) { 420 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL: 421 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA: 422 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA: 423 *(float*)min_value = 0.f; 424 *(float*)max_value = 1.f; 425 break; 426 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL: 427 *(float*)min_value = -1.f; 428 *(float*)max_value = 1.f; 429 break; 430 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE: 431 *(uint8_t*)min_value = 0; 432 *(uint8_t*)max_value = 1; 433 break; 434 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR: 435 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX: 436 default: 437 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE; 438 } 439 return VDP_STATUS_OK; 440} 441