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 pipe_mutex_lock(dev
->mutex
);
88 /* XXX: Current limits */
90 if (surface_chroma_type
!= VDP_CHROMA_TYPE_420
)
91 *is_supported
= false;
93 max_2d_texture_level
= pscreen
->get_param(pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
94 pipe_mutex_unlock(dev
->mutex
);
95 if (!max_2d_texture_level
)
96 return VDP_STATUS_RESOURCES
;
98 /* I am not quite sure if it is max_2d_texture_level-1 or just max_2d_texture_level */
99 *max_width
= *max_height
= pow(2,max_2d_texture_level
-1);
101 return VDP_STATUS_OK
;
105 * Query the implementation's VdpVideoSurface GetBits/PutBits capabilities.
108 vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
109 VdpYCbCrFormat bits_ycbcr_format
,
110 VdpBool
*is_supported
)
113 struct pipe_screen
*pscreen
;
116 return VDP_STATUS_INVALID_POINTER
;
118 dev
= vlGetDataHTAB(device
);
120 return VDP_STATUS_INVALID_HANDLE
;
122 pscreen
= dev
->vscreen
->pscreen
;
124 return VDP_STATUS_RESOURCES
;
126 pipe_mutex_lock(dev
->mutex
);
127 *is_supported
= pscreen
->is_video_format_supported
130 FormatYCBCRToPipe(bits_ycbcr_format
),
131 PIPE_VIDEO_PROFILE_UNKNOWN
133 pipe_mutex_unlock(dev
->mutex
);
135 return VDP_STATUS_OK
;
139 * Query the implementation's VdpDecoder capabilities.
142 vlVdpDecoderQueryCapabilities(VdpDevice device
, VdpDecoderProfile profile
,
143 VdpBool
*is_supported
, uint32_t *max_level
, uint32_t *max_macroblocks
,
144 uint32_t *max_width
, uint32_t *max_height
)
147 struct pipe_screen
*pscreen
;
148 enum pipe_video_profile p_profile
;
150 if (!(is_supported
&& max_level
&& max_macroblocks
&& max_width
&& max_height
))
151 return VDP_STATUS_INVALID_POINTER
;
153 dev
= vlGetDataHTAB(device
);
155 return VDP_STATUS_INVALID_HANDLE
;
157 pscreen
= dev
->vscreen
->pscreen
;
159 return VDP_STATUS_RESOURCES
;
161 p_profile
= ProfileToPipe(profile
);
162 if (p_profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
163 *is_supported
= false;
164 return VDP_STATUS_OK
;
167 pipe_mutex_lock(dev
->mutex
);
168 *is_supported
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_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
);
173 *max_macroblocks
= (*max_width
/16)*(*max_height
/16);
178 *max_macroblocks
= 0;
180 pipe_mutex_unlock(dev
->mutex
);
182 return VDP_STATUS_OK
;
186 * Query the implementation's VdpOutputSurface capabilities.
189 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
190 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
193 struct pipe_screen
*pscreen
;
194 enum pipe_format format
;
196 dev
= vlGetDataHTAB(device
);
198 return VDP_STATUS_INVALID_HANDLE
;
200 pscreen
= dev
->vscreen
->pscreen
;
202 return VDP_STATUS_RESOURCES
;
204 format
= FormatRGBAToPipe(surface_rgba_format
);
205 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
206 return VDP_STATUS_INVALID_RGBA_FORMAT
;
208 if (!(is_supported
&& max_width
&& max_height
))
209 return VDP_STATUS_INVALID_POINTER
;
211 pipe_mutex_lock(dev
->mutex
);
212 *is_supported
= pscreen
->is_format_supported
214 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
215 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
218 uint32_t max_2d_texture_level
= pscreen
->get_param(
219 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
221 if (!max_2d_texture_level
) {
222 pipe_mutex_unlock(dev
->mutex
);
223 return VDP_STATUS_ERROR
;
226 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
231 pipe_mutex_unlock(dev
->mutex
);
233 return VDP_STATUS_OK
;
237 * Query the implementation's capability to perform a PutBits operation using
238 * application data matching the surface's format.
241 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
242 VdpBool
*is_supported
)
245 struct pipe_screen
*pscreen
;
246 enum pipe_format format
;
248 dev
= vlGetDataHTAB(device
);
250 return VDP_STATUS_INVALID_HANDLE
;
252 pscreen
= dev
->vscreen
->pscreen
;
254 return VDP_STATUS_ERROR
;
256 format
= FormatRGBAToPipe(surface_rgba_format
);
257 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
258 return VDP_STATUS_INVALID_RGBA_FORMAT
;
261 return VDP_STATUS_INVALID_POINTER
;
263 pipe_mutex_lock(dev
->mutex
);
264 *is_supported
= pscreen
->is_format_supported
266 pscreen
, format
, PIPE_TEXTURE_2D
, 1,
267 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
269 pipe_mutex_unlock(dev
->mutex
);
271 return VDP_STATUS_OK
;
275 * Query the implementation's capability to perform a PutBits operation using
276 * application data in a specific indexed format.
279 vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device
,
280 VdpRGBAFormat surface_rgba_format
,
281 VdpIndexedFormat bits_indexed_format
,
282 VdpColorTableFormat color_table_format
,
283 VdpBool
*is_supported
)
286 struct pipe_screen
*pscreen
;
287 enum pipe_format rgba_format
, index_format
, colortbl_format
;
289 dev
= vlGetDataHTAB(device
);
291 return VDP_STATUS_INVALID_HANDLE
;
293 pscreen
= dev
->vscreen
->pscreen
;
295 return VDP_STATUS_ERROR
;
297 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
298 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
299 return VDP_STATUS_INVALID_RGBA_FORMAT
;
301 index_format
= FormatIndexedToPipe(bits_indexed_format
);
302 if (index_format
== PIPE_FORMAT_NONE
)
303 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
305 colortbl_format
= FormatColorTableToPipe(color_table_format
);
306 if (colortbl_format
== PIPE_FORMAT_NONE
)
307 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
310 return VDP_STATUS_INVALID_POINTER
;
312 pipe_mutex_lock(dev
->mutex
);
313 *is_supported
= pscreen
->is_format_supported
315 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
316 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
319 *is_supported
&= pscreen
->is_format_supported
321 pscreen
, index_format
, PIPE_TEXTURE_2D
, 1,
322 PIPE_BIND_SAMPLER_VIEW
325 *is_supported
&= pscreen
->is_format_supported
327 pscreen
, colortbl_format
, PIPE_TEXTURE_1D
, 1,
328 PIPE_BIND_SAMPLER_VIEW
330 pipe_mutex_unlock(dev
->mutex
);
332 return VDP_STATUS_OK
;
336 * Query the implementation's capability to perform a PutBits operation using
337 * application data in a specific YCbCr/YUB format.
340 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
341 VdpYCbCrFormat bits_ycbcr_format
,
342 VdpBool
*is_supported
)
345 struct pipe_screen
*pscreen
;
346 enum pipe_format rgba_format
, ycbcr_format
;
348 dev
= vlGetDataHTAB(device
);
350 return VDP_STATUS_INVALID_HANDLE
;
352 pscreen
= dev
->vscreen
->pscreen
;
354 return VDP_STATUS_ERROR
;
356 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
357 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
358 return VDP_STATUS_INVALID_RGBA_FORMAT
;
360 ycbcr_format
= FormatYCBCRToPipe(bits_ycbcr_format
);
361 if (ycbcr_format
== PIPE_FORMAT_NONE
)
362 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
365 return VDP_STATUS_INVALID_POINTER
;
367 pipe_mutex_lock(dev
->mutex
);
368 *is_supported
= pscreen
->is_format_supported
370 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
371 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
374 *is_supported
&= pscreen
->is_video_format_supported
376 pscreen
, ycbcr_format
,
377 PIPE_VIDEO_PROFILE_UNKNOWN
379 pipe_mutex_unlock(dev
->mutex
);
381 return VDP_STATUS_OK
;
385 * Query the implementation's VdpBitmapSurface capabilities.
388 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
389 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
392 struct pipe_screen
*pscreen
;
393 enum pipe_format format
;
395 dev
= vlGetDataHTAB(device
);
397 return VDP_STATUS_INVALID_HANDLE
;
399 pscreen
= dev
->vscreen
->pscreen
;
401 return VDP_STATUS_RESOURCES
;
403 format
= FormatRGBAToPipe(surface_rgba_format
);
404 if (format
== PIPE_FORMAT_NONE
)
405 return VDP_STATUS_INVALID_RGBA_FORMAT
;
407 if (!(is_supported
&& max_width
&& max_height
))
408 return VDP_STATUS_INVALID_POINTER
;
410 pipe_mutex_lock(dev
->mutex
);
411 *is_supported
= pscreen
->is_format_supported
413 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
414 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
417 uint32_t max_2d_texture_level
= pscreen
->get_param(
418 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
420 if (!max_2d_texture_level
) {
421 pipe_mutex_unlock(dev
->mutex
);
422 return VDP_STATUS_ERROR
;
425 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
430 pipe_mutex_unlock(dev
->mutex
);
432 return VDP_STATUS_OK
;
436 * Query the implementation's support for a specific feature.
439 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device
, VdpVideoMixerFeature feature
,
440 VdpBool
*is_supported
)
443 return VDP_STATUS_INVALID_POINTER
;
446 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
447 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
448 *is_supported
= VDP_TRUE
;
451 *is_supported
= VDP_FALSE
;
454 return VDP_STATUS_OK
;
458 * Query the implementation's support for a specific parameter.
461 vlVdpVideoMixerQueryParameterSupport(VdpDevice device
, VdpVideoMixerParameter parameter
,
462 VdpBool
*is_supported
)
465 return VDP_STATUS_INVALID_POINTER
;
468 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
469 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
470 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
471 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
472 *is_supported
= VDP_TRUE
;
475 *is_supported
= VDP_FALSE
;
478 return VDP_STATUS_OK
;
482 * Query the implementation's supported for a specific parameter.
485 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device
, VdpVideoMixerParameter parameter
,
486 void *min_value
, void *max_value
)
488 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
489 struct pipe_screen
*screen
;
490 enum pipe_video_profile prof
= PIPE_VIDEO_PROFILE_UNKNOWN
;
493 return VDP_STATUS_INVALID_HANDLE
;
494 if (!(min_value
&& max_value
))
495 return VDP_STATUS_INVALID_POINTER
;
497 pipe_mutex_lock(dev
->mutex
);
498 screen
= dev
->vscreen
->pscreen
;
500 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
501 *(uint32_t*)min_value
= 48;
502 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_WIDTH
);
504 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
505 *(uint32_t*)min_value
= 48;
506 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
509 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
510 *(uint32_t*)min_value
= 0;
511 *(uint32_t*)max_value
= 4;
514 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
516 pipe_mutex_unlock(dev
->mutex
);
517 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
519 pipe_mutex_unlock(dev
->mutex
);
520 return VDP_STATUS_OK
;
524 * Query the implementation's support for a specific attribute.
527 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device
, VdpVideoMixerAttribute attribute
,
528 VdpBool
*is_supported
)
531 return VDP_STATUS_INVALID_POINTER
;
534 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
535 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
536 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
537 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
538 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
539 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
540 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
541 *is_supported
= VDP_TRUE
;
544 *is_supported
= VDP_FALSE
;
546 return VDP_STATUS_OK
;
550 * Query the implementation's supported for a specific attribute.
553 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device
, VdpVideoMixerAttribute attribute
,
554 void *min_value
, void *max_value
)
556 if (!(min_value
&& max_value
))
557 return VDP_STATUS_INVALID_POINTER
;
560 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
561 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
562 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
563 *(float*)min_value
= 0.f
;
564 *(float*)max_value
= 1.f
;
566 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
567 *(float*)min_value
= -1.f
;
568 *(float*)max_value
= 1.f
;
570 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
571 *(uint8_t*)min_value
= 0;
572 *(uint8_t*)max_value
= 1;
574 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
575 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
577 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
579 return VDP_STATUS_OK
;