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 VMWARE 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 "pipe/p_screen.h"
33 #include "pipe/p_defines.h"
34 #include "util/u_debug.h"
37 * Retrieve the VDPAU version implemented by the backend.
40 vlVdpGetApiVersion(uint32_t *api_version
)
43 return VDP_STATUS_INVALID_POINTER
;
50 * Retrieve an implementation-specific string description of the implementation.
51 * This typically includes detailed version information.
54 vlVdpGetInformationString(char const **information_string
)
56 if (!information_string
)
57 return VDP_STATUS_INVALID_POINTER
;
59 *information_string
= INFORMATION_STRING
;
64 * Query the implementation's VdpVideoSurface capabilities.
67 vlVdpVideoSurfaceQueryCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
68 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
71 struct pipe_screen
*pscreen
;
72 uint32_t max_2d_texture_size
;
74 if (!(is_supported
&& max_width
&& max_height
))
75 return VDP_STATUS_INVALID_POINTER
;
77 dev
= vlGetDataHTAB(device
);
79 return VDP_STATUS_INVALID_HANDLE
;
81 pscreen
= dev
->vscreen
->pscreen
;
83 return VDP_STATUS_RESOURCES
;
85 mtx_lock(&dev
->mutex
);
87 /* XXX: Current limits */
89 max_2d_texture_size
= pscreen
->get_param(pscreen
, PIPE_CAP_MAX_TEXTURE_2D_SIZE
);
90 mtx_unlock(&dev
->mutex
);
91 if (!max_2d_texture_size
)
92 return VDP_STATUS_RESOURCES
;
94 *max_width
= *max_height
= max_2d_texture_size
;
100 * Query the implementation's VdpVideoSurface GetBits/PutBits capabilities.
103 vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
104 VdpYCbCrFormat bits_ycbcr_format
,
105 VdpBool
*is_supported
)
108 struct pipe_screen
*pscreen
;
111 return VDP_STATUS_INVALID_POINTER
;
113 dev
= vlGetDataHTAB(device
);
115 return VDP_STATUS_INVALID_HANDLE
;
117 pscreen
= dev
->vscreen
->pscreen
;
119 return VDP_STATUS_RESOURCES
;
121 mtx_lock(&dev
->mutex
);
123 switch(bits_ycbcr_format
) {
124 case VDP_YCBCR_FORMAT_NV12
:
125 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_420
;
128 case VDP_YCBCR_FORMAT_YV12
:
129 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_420
;
131 /* We can convert YV12 to NV12 on the fly! */
133 pscreen
->is_video_format_supported(pscreen
,
135 PIPE_VIDEO_PROFILE_UNKNOWN
,
136 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
)) {
137 mtx_unlock(&dev
->mutex
);
138 return VDP_STATUS_OK
;
142 case VDP_YCBCR_FORMAT_UYVY
:
143 case VDP_YCBCR_FORMAT_YUYV
:
144 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_422
;
147 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
148 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
149 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_444
;
153 *is_supported
= false;
158 !pscreen
->is_video_format_supported(pscreen
,
159 FormatYCBCRToPipe(bits_ycbcr_format
),
160 PIPE_VIDEO_PROFILE_UNKNOWN
,
161 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
)) {
162 *is_supported
= false;
164 mtx_unlock(&dev
->mutex
);
166 return VDP_STATUS_OK
;
170 * Query the implementation's VdpDecoder capabilities.
173 vlVdpDecoderQueryCapabilities(VdpDevice device
, VdpDecoderProfile profile
,
174 VdpBool
*is_supported
, uint32_t *max_level
, uint32_t *max_macroblocks
,
175 uint32_t *max_width
, uint32_t *max_height
)
178 struct pipe_screen
*pscreen
;
179 enum pipe_video_profile p_profile
;
181 if (!(is_supported
&& max_level
&& max_macroblocks
&& max_width
&& max_height
))
182 return VDP_STATUS_INVALID_POINTER
;
184 dev
= vlGetDataHTAB(device
);
186 return VDP_STATUS_INVALID_HANDLE
;
188 pscreen
= dev
->vscreen
->pscreen
;
190 return VDP_STATUS_RESOURCES
;
192 p_profile
= ProfileToPipe(profile
);
193 if (p_profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
194 *is_supported
= false;
195 return VDP_STATUS_OK
;
198 mtx_lock(&dev
->mutex
);
199 *is_supported
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
200 PIPE_VIDEO_CAP_SUPPORTED
);
202 *max_width
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
203 PIPE_VIDEO_CAP_MAX_WIDTH
);
204 *max_height
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
205 PIPE_VIDEO_CAP_MAX_HEIGHT
);
206 *max_level
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
207 PIPE_VIDEO_CAP_MAX_LEVEL
);
208 *max_macroblocks
= (*max_width
/16)*(*max_height
/16);
213 *max_macroblocks
= 0;
215 mtx_unlock(&dev
->mutex
);
217 return VDP_STATUS_OK
;
221 * Query the implementation's VdpOutputSurface capabilities.
224 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
225 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
228 struct pipe_screen
*pscreen
;
229 enum pipe_format format
;
231 dev
= vlGetDataHTAB(device
);
233 return VDP_STATUS_INVALID_HANDLE
;
235 pscreen
= dev
->vscreen
->pscreen
;
237 return VDP_STATUS_RESOURCES
;
239 format
= VdpFormatRGBAToPipe(surface_rgba_format
);
240 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
241 return VDP_STATUS_INVALID_RGBA_FORMAT
;
243 if (!(is_supported
&& max_width
&& max_height
))
244 return VDP_STATUS_INVALID_POINTER
;
246 mtx_lock(&dev
->mutex
);
247 *is_supported
= pscreen
->is_format_supported
249 pscreen
, format
, PIPE_TEXTURE_2D
, 1, 1,
250 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
253 uint32_t max_2d_texture_size
= pscreen
->get_param(
254 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_SIZE
);
256 if (!max_2d_texture_size
) {
257 mtx_unlock(&dev
->mutex
);
258 return VDP_STATUS_ERROR
;
261 *max_width
= *max_height
= max_2d_texture_size
;
266 mtx_unlock(&dev
->mutex
);
268 return VDP_STATUS_OK
;
272 * Query the implementation's capability to perform a PutBits operation using
273 * application data matching the surface's format.
276 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
277 VdpBool
*is_supported
)
280 struct pipe_screen
*pscreen
;
281 enum pipe_format format
;
283 dev
= vlGetDataHTAB(device
);
285 return VDP_STATUS_INVALID_HANDLE
;
287 pscreen
= dev
->vscreen
->pscreen
;
289 return VDP_STATUS_ERROR
;
291 format
= VdpFormatRGBAToPipe(surface_rgba_format
);
292 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
293 return VDP_STATUS_INVALID_RGBA_FORMAT
;
296 return VDP_STATUS_INVALID_POINTER
;
298 mtx_lock(&dev
->mutex
);
299 *is_supported
= pscreen
->is_format_supported
301 pscreen
, format
, PIPE_TEXTURE_2D
, 1, 1,
302 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
304 mtx_unlock(&dev
->mutex
);
306 return VDP_STATUS_OK
;
310 * Query the implementation's capability to perform a PutBits operation using
311 * application data in a specific indexed format.
314 vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device
,
315 VdpRGBAFormat surface_rgba_format
,
316 VdpIndexedFormat bits_indexed_format
,
317 VdpColorTableFormat color_table_format
,
318 VdpBool
*is_supported
)
321 struct pipe_screen
*pscreen
;
322 enum pipe_format rgba_format
, index_format
, colortbl_format
;
324 dev
= vlGetDataHTAB(device
);
326 return VDP_STATUS_INVALID_HANDLE
;
328 pscreen
= dev
->vscreen
->pscreen
;
330 return VDP_STATUS_ERROR
;
332 rgba_format
= VdpFormatRGBAToPipe(surface_rgba_format
);
333 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
334 return VDP_STATUS_INVALID_RGBA_FORMAT
;
336 index_format
= FormatIndexedToPipe(bits_indexed_format
);
337 if (index_format
== PIPE_FORMAT_NONE
)
338 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
340 colortbl_format
= FormatColorTableToPipe(color_table_format
);
341 if (colortbl_format
== PIPE_FORMAT_NONE
)
342 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
345 return VDP_STATUS_INVALID_POINTER
;
347 mtx_lock(&dev
->mutex
);
348 *is_supported
= pscreen
->is_format_supported
350 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1, 1,
351 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
354 *is_supported
&= pscreen
->is_format_supported
356 pscreen
, index_format
, PIPE_TEXTURE_2D
, 1, 1,
357 PIPE_BIND_SAMPLER_VIEW
360 *is_supported
&= pscreen
->is_format_supported
362 pscreen
, colortbl_format
, PIPE_TEXTURE_1D
, 1, 1,
363 PIPE_BIND_SAMPLER_VIEW
365 mtx_unlock(&dev
->mutex
);
367 return VDP_STATUS_OK
;
371 * Query the implementation's capability to perform a PutBits operation using
372 * application data in a specific YCbCr/YUB format.
375 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
376 VdpYCbCrFormat bits_ycbcr_format
,
377 VdpBool
*is_supported
)
380 struct pipe_screen
*pscreen
;
381 enum pipe_format rgba_format
, ycbcr_format
;
383 dev
= vlGetDataHTAB(device
);
385 return VDP_STATUS_INVALID_HANDLE
;
387 pscreen
= dev
->vscreen
->pscreen
;
389 return VDP_STATUS_ERROR
;
391 rgba_format
= VdpFormatRGBAToPipe(surface_rgba_format
);
392 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
393 return VDP_STATUS_INVALID_RGBA_FORMAT
;
395 ycbcr_format
= FormatYCBCRToPipe(bits_ycbcr_format
);
396 if (ycbcr_format
== PIPE_FORMAT_NONE
)
397 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
400 return VDP_STATUS_INVALID_POINTER
;
402 mtx_lock(&dev
->mutex
);
403 *is_supported
= pscreen
->is_format_supported
405 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1, 1,
406 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
409 *is_supported
&= pscreen
->is_video_format_supported
411 pscreen
, ycbcr_format
,
412 PIPE_VIDEO_PROFILE_UNKNOWN
,
413 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
415 mtx_unlock(&dev
->mutex
);
417 return VDP_STATUS_OK
;
421 * Query the implementation's VdpBitmapSurface capabilities.
424 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
425 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
428 struct pipe_screen
*pscreen
;
429 enum pipe_format format
;
431 dev
= vlGetDataHTAB(device
);
433 return VDP_STATUS_INVALID_HANDLE
;
435 pscreen
= dev
->vscreen
->pscreen
;
437 return VDP_STATUS_RESOURCES
;
439 format
= VdpFormatRGBAToPipe(surface_rgba_format
);
440 if (format
== PIPE_FORMAT_NONE
)
441 return VDP_STATUS_INVALID_RGBA_FORMAT
;
443 if (!(is_supported
&& max_width
&& max_height
))
444 return VDP_STATUS_INVALID_POINTER
;
446 mtx_lock(&dev
->mutex
);
447 *is_supported
= pscreen
->is_format_supported
449 pscreen
, format
, PIPE_TEXTURE_2D
, 1, 1,
450 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
453 uint32_t max_2d_texture_size
= pscreen
->get_param(
454 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_SIZE
);
456 if (!max_2d_texture_size
) {
457 mtx_unlock(&dev
->mutex
);
458 return VDP_STATUS_ERROR
;
461 *max_width
= *max_height
= max_2d_texture_size
;
466 mtx_unlock(&dev
->mutex
);
468 return VDP_STATUS_OK
;
472 * Query the implementation's support for a specific feature.
475 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device
, VdpVideoMixerFeature feature
,
476 VdpBool
*is_supported
)
479 return VDP_STATUS_INVALID_POINTER
;
482 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
483 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
484 case VDP_VIDEO_MIXER_FEATURE_DEINTERLACE_TEMPORAL
:
485 case VDP_VIDEO_MIXER_FEATURE_LUMA_KEY
:
486 case VDP_VIDEO_MIXER_FEATURE_HIGH_QUALITY_SCALING_L1
:
487 *is_supported
= VDP_TRUE
;
490 *is_supported
= VDP_FALSE
;
493 return VDP_STATUS_OK
;
497 * Query the implementation's support for a specific parameter.
500 vlVdpVideoMixerQueryParameterSupport(VdpDevice device
, VdpVideoMixerParameter parameter
,
501 VdpBool
*is_supported
)
504 return VDP_STATUS_INVALID_POINTER
;
507 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
508 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
509 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
510 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
511 *is_supported
= VDP_TRUE
;
514 *is_supported
= VDP_FALSE
;
517 return VDP_STATUS_OK
;
521 * Query the implementation's supported for a specific parameter.
524 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device
, VdpVideoMixerParameter parameter
,
525 void *min_value
, void *max_value
)
527 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
528 struct pipe_screen
*screen
;
531 return VDP_STATUS_INVALID_HANDLE
;
532 if (!(min_value
&& max_value
))
533 return VDP_STATUS_INVALID_POINTER
;
535 mtx_lock(&dev
->mutex
);
536 screen
= dev
->vscreen
->pscreen
;
538 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
539 *(uint32_t*)min_value
= 48;
540 *(uint32_t*)max_value
= screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
541 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
542 PIPE_VIDEO_CAP_MAX_WIDTH
);
544 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
545 *(uint32_t*)min_value
= 48;
546 *(uint32_t*)max_value
= screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
547 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
548 PIPE_VIDEO_CAP_MAX_HEIGHT
);
551 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
552 *(uint32_t*)min_value
= 0;
553 *(uint32_t*)max_value
= 4;
556 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
558 mtx_unlock(&dev
->mutex
);
559 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
561 mtx_unlock(&dev
->mutex
);
562 return VDP_STATUS_OK
;
566 * Query the implementation's support for a specific attribute.
569 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device
, VdpVideoMixerAttribute attribute
,
570 VdpBool
*is_supported
)
573 return VDP_STATUS_INVALID_POINTER
;
576 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
577 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
578 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
579 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
580 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
581 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
582 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
583 *is_supported
= VDP_TRUE
;
586 *is_supported
= VDP_FALSE
;
588 return VDP_STATUS_OK
;
592 * Query the implementation's supported for a specific attribute.
595 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device
, VdpVideoMixerAttribute attribute
,
596 void *min_value
, void *max_value
)
598 if (!(min_value
&& max_value
))
599 return VDP_STATUS_INVALID_POINTER
;
602 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
603 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
604 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
605 *(float*)min_value
= 0.0f
;
606 *(float*)max_value
= 1.0f
;
608 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
609 *(float*)min_value
= -1.0f
;
610 *(float*)max_value
= 1.0f
;
612 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
613 *(uint8_t*)min_value
= 0;
614 *(uint8_t*)max_value
= 1;
616 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
617 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
619 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
621 return VDP_STATUS_OK
;