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_level
;
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 pipe_mutex_lock(dev
->mutex
);
87 /* XXX: Current limits */
89 max_2d_texture_level
= pscreen
->get_param(pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
90 pipe_mutex_unlock(dev
->mutex
);
91 if (!max_2d_texture_level
)
92 return VDP_STATUS_RESOURCES
;
94 /* I am not quite sure if it is max_2d_texture_level-1 or just max_2d_texture_level */
95 *max_width
= *max_height
= pow(2,max_2d_texture_level
-1);
101 * Query the implementation's VdpVideoSurface GetBits/PutBits capabilities.
104 vlVdpVideoSurfaceQueryGetPutBitsYCbCrCapabilities(VdpDevice device
, VdpChromaType surface_chroma_type
,
105 VdpYCbCrFormat bits_ycbcr_format
,
106 VdpBool
*is_supported
)
109 struct pipe_screen
*pscreen
;
112 return VDP_STATUS_INVALID_POINTER
;
114 dev
= vlGetDataHTAB(device
);
116 return VDP_STATUS_INVALID_HANDLE
;
118 pscreen
= dev
->vscreen
->pscreen
;
120 return VDP_STATUS_RESOURCES
;
122 pipe_mutex_lock(dev
->mutex
);
124 switch(bits_ycbcr_format
) {
125 case VDP_YCBCR_FORMAT_NV12
:
126 case VDP_YCBCR_FORMAT_YV12
:
127 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_420
;
130 case VDP_YCBCR_FORMAT_UYVY
:
131 case VDP_YCBCR_FORMAT_YUYV
:
132 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_422
;
135 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
136 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
137 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_444
;
141 *is_supported
= false;
145 *is_supported
&= pscreen
->is_video_format_supported
148 FormatYCBCRToPipe(bits_ycbcr_format
),
149 PIPE_VIDEO_PROFILE_UNKNOWN
,
150 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
152 pipe_mutex_unlock(dev
->mutex
);
154 return VDP_STATUS_OK
;
158 * Query the implementation's VdpDecoder capabilities.
161 vlVdpDecoderQueryCapabilities(VdpDevice device
, VdpDecoderProfile profile
,
162 VdpBool
*is_supported
, uint32_t *max_level
, uint32_t *max_macroblocks
,
163 uint32_t *max_width
, uint32_t *max_height
)
166 struct pipe_screen
*pscreen
;
167 enum pipe_video_profile p_profile
;
169 if (!(is_supported
&& max_level
&& max_macroblocks
&& max_width
&& max_height
))
170 return VDP_STATUS_INVALID_POINTER
;
172 dev
= vlGetDataHTAB(device
);
174 return VDP_STATUS_INVALID_HANDLE
;
176 pscreen
= dev
->vscreen
->pscreen
;
178 return VDP_STATUS_RESOURCES
;
180 p_profile
= ProfileToPipe(profile
);
181 if (p_profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
182 *is_supported
= false;
183 return VDP_STATUS_OK
;
186 pipe_mutex_lock(dev
->mutex
);
187 *is_supported
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
188 PIPE_VIDEO_CAP_SUPPORTED
);
190 *max_width
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
191 PIPE_VIDEO_CAP_MAX_WIDTH
);
192 *max_height
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
193 PIPE_VIDEO_CAP_MAX_HEIGHT
);
194 *max_level
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
195 PIPE_VIDEO_CAP_MAX_LEVEL
);
196 *max_macroblocks
= (*max_width
/16)*(*max_height
/16);
201 *max_macroblocks
= 0;
203 pipe_mutex_unlock(dev
->mutex
);
205 return VDP_STATUS_OK
;
209 * Query the implementation's VdpOutputSurface capabilities.
212 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
213 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
216 struct pipe_screen
*pscreen
;
217 enum pipe_format format
;
219 dev
= vlGetDataHTAB(device
);
221 return VDP_STATUS_INVALID_HANDLE
;
223 pscreen
= dev
->vscreen
->pscreen
;
225 return VDP_STATUS_RESOURCES
;
227 format
= FormatRGBAToPipe(surface_rgba_format
);
228 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
229 return VDP_STATUS_INVALID_RGBA_FORMAT
;
231 if (!(is_supported
&& max_width
&& max_height
))
232 return VDP_STATUS_INVALID_POINTER
;
234 pipe_mutex_lock(dev
->mutex
);
235 *is_supported
= pscreen
->is_format_supported
237 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
238 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
241 uint32_t max_2d_texture_level
= pscreen
->get_param(
242 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
244 if (!max_2d_texture_level
) {
245 pipe_mutex_unlock(dev
->mutex
);
246 return VDP_STATUS_ERROR
;
249 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
254 pipe_mutex_unlock(dev
->mutex
);
256 return VDP_STATUS_OK
;
260 * Query the implementation's capability to perform a PutBits operation using
261 * application data matching the surface's format.
264 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
265 VdpBool
*is_supported
)
268 struct pipe_screen
*pscreen
;
269 enum pipe_format format
;
271 dev
= vlGetDataHTAB(device
);
273 return VDP_STATUS_INVALID_HANDLE
;
275 pscreen
= dev
->vscreen
->pscreen
;
277 return VDP_STATUS_ERROR
;
279 format
= FormatRGBAToPipe(surface_rgba_format
);
280 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
281 return VDP_STATUS_INVALID_RGBA_FORMAT
;
284 return VDP_STATUS_INVALID_POINTER
;
286 pipe_mutex_lock(dev
->mutex
);
287 *is_supported
= pscreen
->is_format_supported
289 pscreen
, format
, PIPE_TEXTURE_2D
, 1,
290 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
292 pipe_mutex_unlock(dev
->mutex
);
294 return VDP_STATUS_OK
;
298 * Query the implementation's capability to perform a PutBits operation using
299 * application data in a specific indexed format.
302 vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device
,
303 VdpRGBAFormat surface_rgba_format
,
304 VdpIndexedFormat bits_indexed_format
,
305 VdpColorTableFormat color_table_format
,
306 VdpBool
*is_supported
)
309 struct pipe_screen
*pscreen
;
310 enum pipe_format rgba_format
, index_format
, colortbl_format
;
312 dev
= vlGetDataHTAB(device
);
314 return VDP_STATUS_INVALID_HANDLE
;
316 pscreen
= dev
->vscreen
->pscreen
;
318 return VDP_STATUS_ERROR
;
320 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
321 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
322 return VDP_STATUS_INVALID_RGBA_FORMAT
;
324 index_format
= FormatIndexedToPipe(bits_indexed_format
);
325 if (index_format
== PIPE_FORMAT_NONE
)
326 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
328 colortbl_format
= FormatColorTableToPipe(color_table_format
);
329 if (colortbl_format
== PIPE_FORMAT_NONE
)
330 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
333 return VDP_STATUS_INVALID_POINTER
;
335 pipe_mutex_lock(dev
->mutex
);
336 *is_supported
= pscreen
->is_format_supported
338 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
339 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
342 *is_supported
&= pscreen
->is_format_supported
344 pscreen
, index_format
, PIPE_TEXTURE_2D
, 1,
345 PIPE_BIND_SAMPLER_VIEW
348 *is_supported
&= pscreen
->is_format_supported
350 pscreen
, colortbl_format
, PIPE_TEXTURE_1D
, 1,
351 PIPE_BIND_SAMPLER_VIEW
353 pipe_mutex_unlock(dev
->mutex
);
355 return VDP_STATUS_OK
;
359 * Query the implementation's capability to perform a PutBits operation using
360 * application data in a specific YCbCr/YUB format.
363 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
364 VdpYCbCrFormat bits_ycbcr_format
,
365 VdpBool
*is_supported
)
368 struct pipe_screen
*pscreen
;
369 enum pipe_format rgba_format
, ycbcr_format
;
371 dev
= vlGetDataHTAB(device
);
373 return VDP_STATUS_INVALID_HANDLE
;
375 pscreen
= dev
->vscreen
->pscreen
;
377 return VDP_STATUS_ERROR
;
379 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
380 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
381 return VDP_STATUS_INVALID_RGBA_FORMAT
;
383 ycbcr_format
= FormatYCBCRToPipe(bits_ycbcr_format
);
384 if (ycbcr_format
== PIPE_FORMAT_NONE
)
385 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
388 return VDP_STATUS_INVALID_POINTER
;
390 pipe_mutex_lock(dev
->mutex
);
391 *is_supported
= pscreen
->is_format_supported
393 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
394 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
397 *is_supported
&= pscreen
->is_video_format_supported
399 pscreen
, ycbcr_format
,
400 PIPE_VIDEO_PROFILE_UNKNOWN
,
401 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
403 pipe_mutex_unlock(dev
->mutex
);
405 return VDP_STATUS_OK
;
409 * Query the implementation's VdpBitmapSurface capabilities.
412 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
413 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
416 struct pipe_screen
*pscreen
;
417 enum pipe_format format
;
419 dev
= vlGetDataHTAB(device
);
421 return VDP_STATUS_INVALID_HANDLE
;
423 pscreen
= dev
->vscreen
->pscreen
;
425 return VDP_STATUS_RESOURCES
;
427 format
= FormatRGBAToPipe(surface_rgba_format
);
428 if (format
== PIPE_FORMAT_NONE
)
429 return VDP_STATUS_INVALID_RGBA_FORMAT
;
431 if (!(is_supported
&& max_width
&& max_height
))
432 return VDP_STATUS_INVALID_POINTER
;
434 pipe_mutex_lock(dev
->mutex
);
435 *is_supported
= pscreen
->is_format_supported
437 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
438 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
441 uint32_t max_2d_texture_level
= pscreen
->get_param(
442 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
444 if (!max_2d_texture_level
) {
445 pipe_mutex_unlock(dev
->mutex
);
446 return VDP_STATUS_ERROR
;
449 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
454 pipe_mutex_unlock(dev
->mutex
);
456 return VDP_STATUS_OK
;
460 * Query the implementation's support for a specific feature.
463 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device
, VdpVideoMixerFeature feature
,
464 VdpBool
*is_supported
)
467 return VDP_STATUS_INVALID_POINTER
;
470 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
471 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
472 *is_supported
= VDP_TRUE
;
475 *is_supported
= VDP_FALSE
;
478 return VDP_STATUS_OK
;
482 * Query the implementation's support for a specific parameter.
485 vlVdpVideoMixerQueryParameterSupport(VdpDevice device
, VdpVideoMixerParameter parameter
,
486 VdpBool
*is_supported
)
489 return VDP_STATUS_INVALID_POINTER
;
492 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
493 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
494 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
495 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
496 *is_supported
= VDP_TRUE
;
499 *is_supported
= VDP_FALSE
;
502 return VDP_STATUS_OK
;
506 * Query the implementation's supported for a specific parameter.
509 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device
, VdpVideoMixerParameter parameter
,
510 void *min_value
, void *max_value
)
512 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
513 struct pipe_screen
*screen
;
516 return VDP_STATUS_INVALID_HANDLE
;
517 if (!(min_value
&& max_value
))
518 return VDP_STATUS_INVALID_POINTER
;
520 pipe_mutex_lock(dev
->mutex
);
521 screen
= dev
->vscreen
->pscreen
;
523 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
524 *(uint32_t*)min_value
= 48;
525 *(uint32_t*)max_value
= screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
526 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
527 PIPE_VIDEO_CAP_MAX_WIDTH
);
529 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
530 *(uint32_t*)min_value
= 48;
531 *(uint32_t*)max_value
= screen
->get_video_param(screen
, PIPE_VIDEO_PROFILE_UNKNOWN
,
532 PIPE_VIDEO_ENTRYPOINT_BITSTREAM
,
533 PIPE_VIDEO_CAP_MAX_HEIGHT
);
536 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
537 *(uint32_t*)min_value
= 0;
538 *(uint32_t*)max_value
= 4;
541 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
543 pipe_mutex_unlock(dev
->mutex
);
544 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
546 pipe_mutex_unlock(dev
->mutex
);
547 return VDP_STATUS_OK
;
551 * Query the implementation's support for a specific attribute.
554 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device
, VdpVideoMixerAttribute attribute
,
555 VdpBool
*is_supported
)
558 return VDP_STATUS_INVALID_POINTER
;
561 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
562 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
563 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
564 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
565 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
566 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
567 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
568 *is_supported
= VDP_TRUE
;
571 *is_supported
= VDP_FALSE
;
573 return VDP_STATUS_OK
;
577 * Query the implementation's supported for a specific attribute.
580 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device
, VdpVideoMixerAttribute attribute
,
581 void *min_value
, void *max_value
)
583 if (!(min_value
&& max_value
))
584 return VDP_STATUS_INVALID_POINTER
;
587 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
588 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
589 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
590 *(float*)min_value
= 0.f
;
591 *(float*)max_value
= 1.f
;
593 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
594 *(float*)min_value
= -1.f
;
595 *(float*)max_value
= 1.f
;
597 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
598 *(uint8_t*)min_value
= 0;
599 *(uint8_t*)max_value
= 1;
601 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
602 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
604 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
606 return VDP_STATUS_OK
;