1 /**************************************************************************
3 * Copyright 2010 Younes Manton.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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"
38 * Retrieve the VDPAU version implemented by the backend.
41 vlVdpGetApiVersion(uint32_t *api_version
)
44 return VDP_STATUS_INVALID_POINTER
;
51 * Retrieve an implementation-specific string description of the implementation.
52 * This typically includes detailed version information.
55 vlVdpGetInformationString(char const **information_string
)
57 if (!information_string
)
58 return VDP_STATUS_INVALID_POINTER
;
60 *information_string
= INFORMATION_STRING
;
65 * Query the implementation's VdpVideoSurface capabilities.
68 vlVdpVideoSurfaceQueryCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
69 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
72 struct pipe_screen
*pscreen
;
73 uint32_t max_2d_texture_level
;
75 if (!(is_supported
&& max_width
&& max_height
))
76 return VDP_STATUS_INVALID_POINTER
;
78 dev
= vlGetDataHTAB(device
);
80 return VDP_STATUS_INVALID_HANDLE
;
82 pscreen
= dev
->vscreen
->pscreen
;
84 return VDP_STATUS_RESOURCES
;
86 /* XXX: Current limits */
88 if (surface_chroma_type
!= VDP_CHROMA_TYPE_420
)
89 *is_supported
= false;
91 max_2d_texture_level
= pscreen
->get_param(pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
92 if (!max_2d_texture_level
)
93 return VDP_STATUS_RESOURCES
;
95 /* I am not quite sure if it is max_2d_texture_level-1 or just max_2d_texture_level */
96 *max_width
= *max_height
= pow(2,max_2d_texture_level
-1);
102 * Query the implementation's VdpVideoSurface GetBits/PutBits capabilities.
105 vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
106 VdpYCbCrFormat bits_ycbcr_format
,
107 VdpBool
*is_supported
)
110 struct pipe_screen
*pscreen
;
113 return VDP_STATUS_INVALID_POINTER
;
115 dev
= vlGetDataHTAB(device
);
117 return VDP_STATUS_INVALID_HANDLE
;
119 pscreen
= dev
->vscreen
->pscreen
;
121 return VDP_STATUS_RESOURCES
;
123 *is_supported
= pscreen
->is_video_format_supported
126 FormatYCBCRToPipe(bits_ycbcr_format
),
127 PIPE_VIDEO_PROFILE_UNKNOWN
130 return VDP_STATUS_OK
;
134 * Query the implementation's VdpDecoder capabilities.
137 vlVdpDecoderQueryCapabilities(VdpDevice device
, VdpDecoderProfile profile
,
138 VdpBool
*is_supported
, uint32_t *max_level
, uint32_t *max_macroblocks
,
139 uint32_t *max_width
, uint32_t *max_height
)
142 struct pipe_screen
*pscreen
;
143 enum pipe_video_profile p_profile
;
145 if (!(is_supported
&& max_level
&& max_macroblocks
&& max_width
&& max_height
))
146 return VDP_STATUS_INVALID_POINTER
;
148 dev
= vlGetDataHTAB(device
);
150 return VDP_STATUS_INVALID_HANDLE
;
152 pscreen
= dev
->vscreen
->pscreen
;
154 return VDP_STATUS_RESOURCES
;
156 p_profile
= ProfileToPipe(profile
);
157 if (p_profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
158 *is_supported
= false;
159 return VDP_STATUS_OK
;
162 *is_supported
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_SUPPORTED
);
164 *max_width
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_MAX_WIDTH
);
165 *max_height
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
167 *max_macroblocks
= (*max_width
/16)*(*max_height
/16);
172 *max_macroblocks
= 0;
175 return VDP_STATUS_OK
;
179 * Query the implementation's VdpOutputSurface capabilities.
182 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
183 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
186 struct pipe_screen
*pscreen
;
187 enum pipe_format format
;
189 dev
= vlGetDataHTAB(device
);
191 return VDP_STATUS_INVALID_HANDLE
;
193 pscreen
= dev
->vscreen
->pscreen
;
195 return VDP_STATUS_RESOURCES
;
197 format
= FormatRGBAToPipe(surface_rgba_format
);
198 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
199 return VDP_STATUS_INVALID_RGBA_FORMAT
;
201 if (!(is_supported
&& max_width
&& max_height
))
202 return VDP_STATUS_INVALID_POINTER
;
204 *is_supported
= pscreen
->is_format_supported
206 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
207 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
210 uint32_t max_2d_texture_level
= pscreen
->get_param(
211 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
213 if (!max_2d_texture_level
)
214 return VDP_STATUS_ERROR
;
216 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
222 return VDP_STATUS_OK
;
226 * Query the implementation's capability to perform a PutBits operation using
227 * application data matching the surface's format.
230 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
231 VdpBool
*is_supported
)
234 struct pipe_screen
*pscreen
;
235 enum pipe_format format
;
237 dev
= vlGetDataHTAB(device
);
239 return VDP_STATUS_INVALID_HANDLE
;
241 pscreen
= dev
->vscreen
->pscreen
;
243 return VDP_STATUS_ERROR
;
245 format
= FormatRGBAToPipe(surface_rgba_format
);
246 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
247 return VDP_STATUS_INVALID_RGBA_FORMAT
;
250 return VDP_STATUS_INVALID_POINTER
;
252 *is_supported
= pscreen
->is_format_supported
254 pscreen
, format
, PIPE_TEXTURE_2D
, 1,
255 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
258 return VDP_STATUS_OK
;
262 * Query the implementation's capability to perform a PutBits operation using
263 * application data in a specific indexed format.
266 vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device
,
267 VdpRGBAFormat surface_rgba_format
,
268 VdpIndexedFormat bits_indexed_format
,
269 VdpColorTableFormat color_table_format
,
270 VdpBool
*is_supported
)
273 struct pipe_screen
*pscreen
;
274 enum pipe_format rgba_format
, index_format
, colortbl_format
;
276 dev
= vlGetDataHTAB(device
);
278 return VDP_STATUS_INVALID_HANDLE
;
280 pscreen
= dev
->vscreen
->pscreen
;
282 return VDP_STATUS_ERROR
;
284 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
285 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
286 return VDP_STATUS_INVALID_RGBA_FORMAT
;
288 index_format
= FormatIndexedToPipe(bits_indexed_format
);
289 if (index_format
== PIPE_FORMAT_NONE
)
290 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
292 colortbl_format
= FormatColorTableToPipe(color_table_format
);
293 if (colortbl_format
== PIPE_FORMAT_NONE
)
294 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
297 return VDP_STATUS_INVALID_POINTER
;
299 *is_supported
= pscreen
->is_format_supported
301 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
302 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
305 *is_supported
&= pscreen
->is_format_supported
307 pscreen
, index_format
, PIPE_TEXTURE_2D
, 1,
308 PIPE_BIND_SAMPLER_VIEW
311 *is_supported
&= pscreen
->is_format_supported
313 pscreen
, colortbl_format
, PIPE_TEXTURE_1D
, 1,
314 PIPE_BIND_SAMPLER_VIEW
317 return VDP_STATUS_OK
;
321 * Query the implementation's capability to perform a PutBits operation using
322 * application data in a specific YCbCr/YUB format.
325 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
326 VdpYCbCrFormat bits_ycbcr_format
,
327 VdpBool
*is_supported
)
330 return VDP_STATUS_INVALID_POINTER
;
332 return VDP_STATUS_NO_IMPLEMENTATION
;
336 * Query the implementation's VdpBitmapSurface capabilities.
339 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
340 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
343 struct pipe_screen
*pscreen
;
344 enum pipe_format format
;
346 dev
= vlGetDataHTAB(device
);
348 return VDP_STATUS_INVALID_HANDLE
;
350 pscreen
= dev
->vscreen
->pscreen
;
352 return VDP_STATUS_RESOURCES
;
354 format
= FormatRGBAToPipe(surface_rgba_format
);
355 if (format
== PIPE_FORMAT_NONE
)
356 return VDP_STATUS_INVALID_RGBA_FORMAT
;
358 if (!(is_supported
&& max_width
&& max_height
))
359 return VDP_STATUS_INVALID_POINTER
;
361 *is_supported
= pscreen
->is_format_supported
363 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
364 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
367 uint32_t max_2d_texture_level
= pscreen
->get_param(
368 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
370 if (!max_2d_texture_level
)
371 return VDP_STATUS_ERROR
;
373 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
379 return VDP_STATUS_OK
;
383 * Query the implementation's support for a specific feature.
386 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device
, VdpVideoMixerFeature feature
,
387 VdpBool
*is_supported
)
390 return VDP_STATUS_INVALID_POINTER
;
393 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
394 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
395 *is_supported
= VDP_TRUE
;
398 *is_supported
= VDP_FALSE
;
401 return VDP_STATUS_OK
;
405 * Query the implementation's support for a specific parameter.
408 vlVdpVideoMixerQueryParameterSupport(VdpDevice device
, VdpVideoMixerParameter parameter
,
409 VdpBool
*is_supported
)
412 return VDP_STATUS_INVALID_POINTER
;
415 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
416 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
417 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
418 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
419 *is_supported
= VDP_TRUE
;
422 *is_supported
= VDP_FALSE
;
425 return VDP_STATUS_OK
;
429 * Query the implementation's supported for a specific parameter.
432 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device
, VdpVideoMixerParameter parameter
,
433 void *min_value
, void *max_value
)
435 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
436 struct pipe_screen
*screen
;
437 enum pipe_video_profile prof
= PIPE_VIDEO_PROFILE_UNKNOWN
;
439 return VDP_STATUS_INVALID_HANDLE
;
440 if (!(min_value
&& max_value
))
441 return VDP_STATUS_INVALID_POINTER
;
442 screen
= dev
->vscreen
->pscreen
;
444 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
445 *(uint32_t*)min_value
= 48;
446 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_WIDTH
);
448 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
449 *(uint32_t*)min_value
= 48;
450 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
453 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
454 *(uint32_t*)min_value
= 0;
455 *(uint32_t*)max_value
= 4;
458 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
460 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
462 return VDP_STATUS_OK
;
466 * Query the implementation's support for a specific attribute.
469 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device
, VdpVideoMixerAttribute attribute
,
470 VdpBool
*is_supported
)
473 return VDP_STATUS_INVALID_POINTER
;
476 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
477 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
478 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
479 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
480 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
481 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
482 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
483 *is_supported
= VDP_TRUE
;
486 *is_supported
= VDP_FALSE
;
488 return VDP_STATUS_OK
;
492 * Query the implementation's supported for a specific attribute.
495 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device
, VdpVideoMixerAttribute attribute
,
496 void *min_value
, void *max_value
)
498 if (!(min_value
&& max_value
))
499 return VDP_STATUS_INVALID_POINTER
;
502 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
503 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
504 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
505 *(float*)min_value
= 0.f
;
506 *(float*)max_value
= 1.f
;
508 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
509 *(float*)min_value
= -1.f
;
510 *(float*)max_value
= 1.f
;
512 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
513 *(uint8_t*)min_value
= 0;
514 *(uint8_t*)max_value
= 1;
516 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
517 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
519 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
521 return VDP_STATUS_OK
;