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 "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_UYVY
:
126 case VDP_YCBCR_FORMAT_YUYV
:
127 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_422
;
130 case VDP_YCBCR_FORMAT_Y8U8V8A8
:
131 case VDP_YCBCR_FORMAT_V8U8Y8A8
:
132 *is_supported
= surface_chroma_type
== VDP_CHROMA_TYPE_444
;
136 *is_supported
= true;
140 *is_supported
&= pscreen
->is_video_format_supported
143 FormatYCBCRToPipe(bits_ycbcr_format
),
144 PIPE_VIDEO_PROFILE_UNKNOWN
146 pipe_mutex_unlock(dev
->mutex
);
148 return VDP_STATUS_OK
;
152 * Query the implementation's VdpDecoder capabilities.
155 vlVdpDecoderQueryCapabilities(VdpDevice device
, VdpDecoderProfile profile
,
156 VdpBool
*is_supported
, uint32_t *max_level
, uint32_t *max_macroblocks
,
157 uint32_t *max_width
, uint32_t *max_height
)
160 struct pipe_screen
*pscreen
;
161 enum pipe_video_profile p_profile
;
163 if (!(is_supported
&& max_level
&& max_macroblocks
&& max_width
&& max_height
))
164 return VDP_STATUS_INVALID_POINTER
;
166 dev
= vlGetDataHTAB(device
);
168 return VDP_STATUS_INVALID_HANDLE
;
170 pscreen
= dev
->vscreen
->pscreen
;
172 return VDP_STATUS_RESOURCES
;
174 p_profile
= ProfileToPipe(profile
);
175 if (p_profile
== PIPE_VIDEO_PROFILE_UNKNOWN
) {
176 *is_supported
= false;
177 return VDP_STATUS_OK
;
180 pipe_mutex_lock(dev
->mutex
);
181 *is_supported
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_SUPPORTED
);
183 *max_width
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_MAX_WIDTH
);
184 *max_height
= pscreen
->get_video_param(pscreen
, p_profile
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
186 *max_macroblocks
= (*max_width
/16)*(*max_height
/16);
191 *max_macroblocks
= 0;
193 pipe_mutex_unlock(dev
->mutex
);
195 return VDP_STATUS_OK
;
199 * Query the implementation's VdpOutputSurface capabilities.
202 vlVdpOutputSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
203 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
206 struct pipe_screen
*pscreen
;
207 enum pipe_format format
;
209 dev
= vlGetDataHTAB(device
);
211 return VDP_STATUS_INVALID_HANDLE
;
213 pscreen
= dev
->vscreen
->pscreen
;
215 return VDP_STATUS_RESOURCES
;
217 format
= FormatRGBAToPipe(surface_rgba_format
);
218 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
219 return VDP_STATUS_INVALID_RGBA_FORMAT
;
221 if (!(is_supported
&& max_width
&& max_height
))
222 return VDP_STATUS_INVALID_POINTER
;
224 pipe_mutex_lock(dev
->mutex
);
225 *is_supported
= pscreen
->is_format_supported
227 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
228 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
231 uint32_t max_2d_texture_level
= pscreen
->get_param(
232 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
234 if (!max_2d_texture_level
) {
235 pipe_mutex_unlock(dev
->mutex
);
236 return VDP_STATUS_ERROR
;
239 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
244 pipe_mutex_unlock(dev
->mutex
);
246 return VDP_STATUS_OK
;
250 * Query the implementation's capability to perform a PutBits operation using
251 * application data matching the surface's format.
254 vlVdpOutputSurfaceQueryGetPutBitsNativeCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
255 VdpBool
*is_supported
)
258 struct pipe_screen
*pscreen
;
259 enum pipe_format format
;
261 dev
= vlGetDataHTAB(device
);
263 return VDP_STATUS_INVALID_HANDLE
;
265 pscreen
= dev
->vscreen
->pscreen
;
267 return VDP_STATUS_ERROR
;
269 format
= FormatRGBAToPipe(surface_rgba_format
);
270 if (format
== PIPE_FORMAT_NONE
|| format
== PIPE_FORMAT_A8_UNORM
)
271 return VDP_STATUS_INVALID_RGBA_FORMAT
;
274 return VDP_STATUS_INVALID_POINTER
;
276 pipe_mutex_lock(dev
->mutex
);
277 *is_supported
= pscreen
->is_format_supported
279 pscreen
, format
, PIPE_TEXTURE_2D
, 1,
280 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
282 pipe_mutex_unlock(dev
->mutex
);
284 return VDP_STATUS_OK
;
288 * Query the implementation's capability to perform a PutBits operation using
289 * application data in a specific indexed format.
292 vlVdpOutputSurfaceQueryPutBitsIndexedCapabilities(VdpDevice device
,
293 VdpRGBAFormat surface_rgba_format
,
294 VdpIndexedFormat bits_indexed_format
,
295 VdpColorTableFormat color_table_format
,
296 VdpBool
*is_supported
)
299 struct pipe_screen
*pscreen
;
300 enum pipe_format rgba_format
, index_format
, colortbl_format
;
302 dev
= vlGetDataHTAB(device
);
304 return VDP_STATUS_INVALID_HANDLE
;
306 pscreen
= dev
->vscreen
->pscreen
;
308 return VDP_STATUS_ERROR
;
310 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
311 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
312 return VDP_STATUS_INVALID_RGBA_FORMAT
;
314 index_format
= FormatIndexedToPipe(bits_indexed_format
);
315 if (index_format
== PIPE_FORMAT_NONE
)
316 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
318 colortbl_format
= FormatColorTableToPipe(color_table_format
);
319 if (colortbl_format
== PIPE_FORMAT_NONE
)
320 return VDP_STATUS_INVALID_COLOR_TABLE_FORMAT
;
323 return VDP_STATUS_INVALID_POINTER
;
325 pipe_mutex_lock(dev
->mutex
);
326 *is_supported
= pscreen
->is_format_supported
328 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
329 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
332 *is_supported
&= pscreen
->is_format_supported
334 pscreen
, index_format
, PIPE_TEXTURE_2D
, 1,
335 PIPE_BIND_SAMPLER_VIEW
338 *is_supported
&= pscreen
->is_format_supported
340 pscreen
, colortbl_format
, PIPE_TEXTURE_1D
, 1,
341 PIPE_BIND_SAMPLER_VIEW
343 pipe_mutex_unlock(dev
->mutex
);
345 return VDP_STATUS_OK
;
349 * Query the implementation's capability to perform a PutBits operation using
350 * application data in a specific YCbCr/YUB format.
353 vlVdpOutputSurfaceQueryPutBitsYCbCrCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
354 VdpYCbCrFormat bits_ycbcr_format
,
355 VdpBool
*is_supported
)
358 struct pipe_screen
*pscreen
;
359 enum pipe_format rgba_format
, ycbcr_format
;
361 dev
= vlGetDataHTAB(device
);
363 return VDP_STATUS_INVALID_HANDLE
;
365 pscreen
= dev
->vscreen
->pscreen
;
367 return VDP_STATUS_ERROR
;
369 rgba_format
= FormatRGBAToPipe(surface_rgba_format
);
370 if (rgba_format
== PIPE_FORMAT_NONE
|| rgba_format
== PIPE_FORMAT_A8_UNORM
)
371 return VDP_STATUS_INVALID_RGBA_FORMAT
;
373 ycbcr_format
= FormatYCBCRToPipe(bits_ycbcr_format
);
374 if (ycbcr_format
== PIPE_FORMAT_NONE
)
375 return VDP_STATUS_INVALID_INDEXED_FORMAT
;
378 return VDP_STATUS_INVALID_POINTER
;
380 pipe_mutex_lock(dev
->mutex
);
381 *is_supported
= pscreen
->is_format_supported
383 pscreen
, rgba_format
, PIPE_TEXTURE_2D
, 1,
384 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
387 *is_supported
&= pscreen
->is_video_format_supported
389 pscreen
, ycbcr_format
,
390 PIPE_VIDEO_PROFILE_UNKNOWN
392 pipe_mutex_unlock(dev
->mutex
);
394 return VDP_STATUS_OK
;
398 * Query the implementation's VdpBitmapSurface capabilities.
401 vlVdpBitmapSurfaceQueryCapabilities(VdpDevice device
, VdpRGBAFormat surface_rgba_format
,
402 VdpBool
*is_supported
, uint32_t *max_width
, uint32_t *max_height
)
405 struct pipe_screen
*pscreen
;
406 enum pipe_format format
;
408 dev
= vlGetDataHTAB(device
);
410 return VDP_STATUS_INVALID_HANDLE
;
412 pscreen
= dev
->vscreen
->pscreen
;
414 return VDP_STATUS_RESOURCES
;
416 format
= FormatRGBAToPipe(surface_rgba_format
);
417 if (format
== PIPE_FORMAT_NONE
)
418 return VDP_STATUS_INVALID_RGBA_FORMAT
;
420 if (!(is_supported
&& max_width
&& max_height
))
421 return VDP_STATUS_INVALID_POINTER
;
423 pipe_mutex_lock(dev
->mutex
);
424 *is_supported
= pscreen
->is_format_supported
426 pscreen
, format
, PIPE_TEXTURE_3D
, 1,
427 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_RENDER_TARGET
430 uint32_t max_2d_texture_level
= pscreen
->get_param(
431 pscreen
, PIPE_CAP_MAX_TEXTURE_2D_LEVELS
);
433 if (!max_2d_texture_level
) {
434 pipe_mutex_unlock(dev
->mutex
);
435 return VDP_STATUS_ERROR
;
438 *max_width
= *max_height
= pow(2, max_2d_texture_level
- 1);
443 pipe_mutex_unlock(dev
->mutex
);
445 return VDP_STATUS_OK
;
449 * Query the implementation's support for a specific feature.
452 vlVdpVideoMixerQueryFeatureSupport(VdpDevice device
, VdpVideoMixerFeature feature
,
453 VdpBool
*is_supported
)
456 return VDP_STATUS_INVALID_POINTER
;
459 case VDP_VIDEO_MIXER_FEATURE_SHARPNESS
:
460 case VDP_VIDEO_MIXER_FEATURE_NOISE_REDUCTION
:
461 *is_supported
= VDP_TRUE
;
464 *is_supported
= VDP_FALSE
;
467 return VDP_STATUS_OK
;
471 * Query the implementation's support for a specific parameter.
474 vlVdpVideoMixerQueryParameterSupport(VdpDevice device
, VdpVideoMixerParameter parameter
,
475 VdpBool
*is_supported
)
478 return VDP_STATUS_INVALID_POINTER
;
481 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
482 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
483 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
484 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
485 *is_supported
= VDP_TRUE
;
488 *is_supported
= VDP_FALSE
;
491 return VDP_STATUS_OK
;
495 * Query the implementation's supported for a specific parameter.
498 vlVdpVideoMixerQueryParameterValueRange(VdpDevice device
, VdpVideoMixerParameter parameter
,
499 void *min_value
, void *max_value
)
501 vlVdpDevice
*dev
= vlGetDataHTAB(device
);
502 struct pipe_screen
*screen
;
503 enum pipe_video_profile prof
= PIPE_VIDEO_PROFILE_UNKNOWN
;
506 return VDP_STATUS_INVALID_HANDLE
;
507 if (!(min_value
&& max_value
))
508 return VDP_STATUS_INVALID_POINTER
;
510 pipe_mutex_lock(dev
->mutex
);
511 screen
= dev
->vscreen
->pscreen
;
513 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_WIDTH
:
514 *(uint32_t*)min_value
= 48;
515 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_WIDTH
);
517 case VDP_VIDEO_MIXER_PARAMETER_VIDEO_SURFACE_HEIGHT
:
518 *(uint32_t*)min_value
= 48;
519 *(uint32_t*)max_value
= screen
->get_video_param(screen
, prof
, PIPE_VIDEO_CAP_MAX_HEIGHT
);
522 case VDP_VIDEO_MIXER_PARAMETER_LAYERS
:
523 *(uint32_t*)min_value
= 0;
524 *(uint32_t*)max_value
= 4;
527 case VDP_VIDEO_MIXER_PARAMETER_CHROMA_TYPE
:
529 pipe_mutex_unlock(dev
->mutex
);
530 return VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER
;
532 pipe_mutex_unlock(dev
->mutex
);
533 return VDP_STATUS_OK
;
537 * Query the implementation's support for a specific attribute.
540 vlVdpVideoMixerQueryAttributeSupport(VdpDevice device
, VdpVideoMixerAttribute attribute
,
541 VdpBool
*is_supported
)
544 return VDP_STATUS_INVALID_POINTER
;
547 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
548 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
549 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
550 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
551 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
552 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
553 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
554 *is_supported
= VDP_TRUE
;
557 *is_supported
= VDP_FALSE
;
559 return VDP_STATUS_OK
;
563 * Query the implementation's supported for a specific attribute.
566 vlVdpVideoMixerQueryAttributeValueRange(VdpDevice device
, VdpVideoMixerAttribute attribute
,
567 void *min_value
, void *max_value
)
569 if (!(min_value
&& max_value
))
570 return VDP_STATUS_INVALID_POINTER
;
573 case VDP_VIDEO_MIXER_ATTRIBUTE_NOISE_REDUCTION_LEVEL
:
574 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MIN_LUMA
:
575 case VDP_VIDEO_MIXER_ATTRIBUTE_LUMA_KEY_MAX_LUMA
:
576 *(float*)min_value
= 0.f
;
577 *(float*)max_value
= 1.f
;
579 case VDP_VIDEO_MIXER_ATTRIBUTE_SHARPNESS_LEVEL
:
580 *(float*)min_value
= -1.f
;
581 *(float*)max_value
= 1.f
;
583 case VDP_VIDEO_MIXER_ATTRIBUTE_SKIP_CHROMA_DEINTERLACE
:
584 *(uint8_t*)min_value
= 0;
585 *(uint8_t*)max_value
= 1;
587 case VDP_VIDEO_MIXER_ATTRIBUTE_BACKGROUND_COLOR
:
588 case VDP_VIDEO_MIXER_ATTRIBUTE_CSC_MATRIX
:
590 return VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE
;
592 return VDP_STATUS_OK
;