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 max_2d_texture_level
= pscreen
->get_param(pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
91 pipe_mutex_unlock(dev
->mutex
);
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 pipe_mutex_lock(dev
->mutex
);
125 switch(bits_ycbcr_format
) {
126 case VDP_YCBCR_FORMAT_UYVY
:
127 case VDP_YCBCR_FORMAT_YUYV
:
128 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_422
;
131 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
132 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
133 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_444
;
137 *is_supported
= true;
141 *is_supported
&= pscreen
->is_video_format_supported
144 FormatYCBCRToPipe(bits_ycbcr_format
),
145 PIPE_VIDEO_PROFILE_UNKNOWN
147 pipe_mutex_unlock(dev
->mutex
);
149 return VDP_STATUS_OK
;
153 * Query the implementation's VdpDecoder capabilities.
156 vlVdpDecoderQueryCapabilities(VdpDevice device
, VdpDecoderProfile profile
,
157 VdpBool
*is_supported
, uint32_t *max_level
, uint32_t *max_macroblocks
,
158 uint32_t *max_width
, uint32_t *max_height
)
161 struct pipe_screen
*pscreen
;
162 enum pipe_video_profile p_profile
;
164 if (!(is_supported
&& max_level
&& max_macroblocks
&& max_width
&& max_height
))
165 return VDP_STATUS_INVALID_POINTER
;
167 dev
= vlGetDataHTAB(device
);
169 return VDP_STATUS_INVALID_HANDLE
;
171 pscreen
= dev
->vscreen
->pscreen
;
173 return VDP_STATUS_RESOURCES
;
175 p_profile
= ProfileToPipe(profile
);
176 if (p_profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
177 *is_supported
= false;
178 return VDP_STATUS_OK
;
181 pipe_mutex_lock(dev
->mutex
);
182 *is_supported
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_SUPPORTED
);
184 *max_width
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_MAX_WIDTH
);
185 *max_height
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
187 *max_macroblocks
= (*max_width
/16)*(*max_height
/16);
192 *max_macroblocks
= 0;
194 pipe_mutex_unlock(dev
->mutex
);
196 return VDP_STATUS_OK
;
200 * Query the implementation's VdpOutputSurface capabilities.
203 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
204 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
207 struct pipe_screen
*pscreen
;
208 enum pipe_format format
;
210 dev
= vlGetDataHTAB(device
);
212 return VDP_STATUS_INVALID_HANDLE
;
214 pscreen
= dev
->vscreen
->pscreen
;
216 return VDP_STATUS_RESOURCES
;
218 format
= FormatRGBAToPipe(surface_rgba_format
);
219 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
220 return VDP_STATUS_INVALID_RGBA_FORMAT
;
222 if (!(is_supported
&& max_width
&& max_height
))
223 return VDP_STATUS_INVALID_POINTER
;
225 pipe_mutex_lock(dev
->mutex
);
226 *is_supported
= pscreen
->is_format_supported
228 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
229 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
232 uint32_t max_2d_texture_level
= pscreen
->get_param(
233 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
235 if (!max_2d_texture_level
) {
236 pipe_mutex_unlock(dev
->mutex
);
237 return VDP_STATUS_ERROR
;
240 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
245 pipe_mutex_unlock(dev
->mutex
);
247 return VDP_STATUS_OK
;
251 * Query the implementation's capability to perform a PutBits operation using
252 * application data matching the surface's format.
255 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
256 VdpBool
*is_supported
)
259 struct pipe_screen
*pscreen
;
260 enum pipe_format format
;
262 dev
= vlGetDataHTAB(device
);
264 return VDP_STATUS_INVALID_HANDLE
;
266 pscreen
= dev
->vscreen
->pscreen
;
268 return VDP_STATUS_ERROR
;
270 format
= FormatRGBAToPipe(surface_rgba_format
);
271 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
272 return VDP_STATUS_INVALID_RGBA_FORMAT
;
275 return VDP_STATUS_INVALID_POINTER
;
277 pipe_mutex_lock(dev
->mutex
);
278 *is_supported
= pscreen
->is_format_supported
280 pscreen
, format
, PIPE_TEXTURE_2D
, 1,
281 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
283 pipe_mutex_unlock(dev
->mutex
);
285 return VDP_STATUS_OK
;
289 * Query the implementation's capability to perform a PutBits operation using
290 * application data in a specific indexed format.
293 vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device
,
294 VdpRGBAFormat surface_rgba_format
,
295 VdpIndexedFormat bits_indexed_format
,
296 VdpColorTableFormat color_table_format
,
297 VdpBool
*is_supported
)
300 struct pipe_screen
*pscreen
;
301 enum pipe_format rgba_format
, index_format
, colortbl_format
;
303 dev
= vlGetDataHTAB(device
);
305 return VDP_STATUS_INVALID_HANDLE
;
307 pscreen
= dev
->vscreen
->pscreen
;
309 return VDP_STATUS_ERROR
;
311 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
312 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
313 return VDP_STATUS_INVALID_RGBA_FORMAT
;
315 index_format
= FormatIndexedToPipe(bits_indexed_format
);
316 if (index_format
== PIPE_FORMAT_NONE
)
317 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
319 colortbl_format
= FormatColorTableToPipe(color_table_format
);
320 if (colortbl_format
== PIPE_FORMAT_NONE
)
321 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
324 return VDP_STATUS_INVALID_POINTER
;
326 pipe_mutex_lock(dev
->mutex
);
327 *is_supported
= pscreen
->is_format_supported
329 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
330 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
333 *is_supported
&= pscreen
->is_format_supported
335 pscreen
, index_format
, PIPE_TEXTURE_2D
, 1,
336 PIPE_BIND_SAMPLER_VIEW
339 *is_supported
&= pscreen
->is_format_supported
341 pscreen
, colortbl_format
, PIPE_TEXTURE_1D
, 1,
342 PIPE_BIND_SAMPLER_VIEW
344 pipe_mutex_unlock(dev
->mutex
);
346 return VDP_STATUS_OK
;
350 * Query the implementation's capability to perform a PutBits operation using
351 * application data in a specific YCbCr/YUB format.
354 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
355 VdpYCbCrFormat bits_ycbcr_format
,
356 VdpBool
*is_supported
)
359 struct pipe_screen
*pscreen
;
360 enum pipe_format rgba_format
, ycbcr_format
;
362 dev
= vlGetDataHTAB(device
);
364 return VDP_STATUS_INVALID_HANDLE
;
366 pscreen
= dev
->vscreen
->pscreen
;
368 return VDP_STATUS_ERROR
;
370 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
371 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
372 return VDP_STATUS_INVALID_RGBA_FORMAT
;
374 ycbcr_format
= FormatYCBCRToPipe(bits_ycbcr_format
);
375 if (ycbcr_format
== PIPE_FORMAT_NONE
)
376 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
379 return VDP_STATUS_INVALID_POINTER
;
381 pipe_mutex_lock(dev
->mutex
);
382 *is_supported
= pscreen
->is_format_supported
384 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
385 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
388 *is_supported
&= pscreen
->is_video_format_supported
390 pscreen
, ycbcr_format
,
391 PIPE_VIDEO_PROFILE_UNKNOWN
393 pipe_mutex_unlock(dev
->mutex
);
395 return VDP_STATUS_OK
;
399 * Query the implementation's VdpBitmapSurface capabilities.
402 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
403 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
406 struct pipe_screen
*pscreen
;
407 enum pipe_format format
;
409 dev
= vlGetDataHTAB(device
);
411 return VDP_STATUS_INVALID_HANDLE
;
413 pscreen
= dev
->vscreen
->pscreen
;
415 return VDP_STATUS_RESOURCES
;
417 format
= FormatRGBAToPipe(surface_rgba_format
);
418 if (format
== PIPE_FORMAT_NONE
)
419 return VDP_STATUS_INVALID_RGBA_FORMAT
;
421 if (!(is_supported
&& max_width
&& max_height
))
422 return VDP_STATUS_INVALID_POINTER
;
424 pipe_mutex_lock(dev
->mutex
);
425 *is_supported
= pscreen
->is_format_supported
427 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
428 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
431 uint32_t max_2d_texture_level
= pscreen
->get_param(
432 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
434 if (!max_2d_texture_level
) {
435 pipe_mutex_unlock(dev
->mutex
);
436 return VDP_STATUS_ERROR
;
439 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
444 pipe_mutex_unlock(dev
->mutex
);
446 return VDP_STATUS_OK
;
450 * Query the implementation's support for a specific feature.
453 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device
, VdpVideoMixerFeature feature
,
454 VdpBool
*is_supported
)
457 return VDP_STATUS_INVALID_POINTER
;
460 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
461 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
462 *is_supported
= VDP_TRUE
;
465 *is_supported
= VDP_FALSE
;
468 return VDP_STATUS_OK
;
472 * Query the implementation's support for a specific parameter.
475 vlVdpVideoMixerQueryParameterSupport(VdpDevice device
, VdpVideoMixerParameter parameter
,
476 VdpBool
*is_supported
)
479 return VDP_STATUS_INVALID_POINTER
;
482 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
483 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
484 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
485 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
486 *is_supported
= VDP_TRUE
;
489 *is_supported
= VDP_FALSE
;
492 return VDP_STATUS_OK
;
496 * Query the implementation's supported for a specific parameter.
499 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device
, VdpVideoMixerParameter parameter
,
500 void *min_value
, void *max_value
)
502 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
503 struct pipe_screen
*screen
;
504 enum pipe_video_profile prof
= PIPE_VIDEO_PROFILE_UNKNOWN
;
507 return VDP_STATUS_INVALID_HANDLE
;
508 if (!(min_value
&& max_value
))
509 return VDP_STATUS_INVALID_POINTER
;
511 pipe_mutex_lock(dev
->mutex
);
512 screen
= dev
->vscreen
->pscreen
;
514 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
515 *(uint32_t*)min_value
= 48;
516 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_WIDTH
);
518 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
519 *(uint32_t*)min_value
= 48;
520 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
523 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
524 *(uint32_t*)min_value
= 0;
525 *(uint32_t*)max_value
= 4;
528 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
530 pipe_mutex_unlock(dev
->mutex
);
531 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
533 pipe_mutex_unlock(dev
->mutex
);
534 return VDP_STATUS_OK
;
538 * Query the implementation's support for a specific attribute.
541 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device
, VdpVideoMixerAttribute attribute
,
542 VdpBool
*is_supported
)
545 return VDP_STATUS_INVALID_POINTER
;
548 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
549 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
550 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
551 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
552 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
553 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
554 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
555 *is_supported
= VDP_TRUE
;
558 *is_supported
= VDP_FALSE
;
560 return VDP_STATUS_OK
;
564 * Query the implementation's supported for a specific attribute.
567 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device
, VdpVideoMixerAttribute attribute
,
568 void *min_value
, void *max_value
)
570 if (!(min_value
&& max_value
))
571 return VDP_STATUS_INVALID_POINTER
;
574 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
575 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
576 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
577 *(float*)min_value
= 0.f
;
578 *(float*)max_value
= 1.f
;
580 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
581 *(float*)min_value
= -1.f
;
582 *(float*)max_value
= 1.f
;
584 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
585 *(uint8_t*)min_value
= 0;
586 *(uint8_t*)max_value
= 1;
588 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
589 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
591 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
593 return VDP_STATUS_OK
;